mirror of
https://github.com/Ku6epXBOCTuK/easy-png-tools.git
synced 2026-11-13 17:08:20 +00:00
feat: add source aware resolver, update reset, update generator
This commit is contained in:
@@ -20,7 +20,9 @@ export async function execute(
|
||||
tool: ToolEntry,
|
||||
ctx: ExecuteContext,
|
||||
): Promise<ToolResult> {
|
||||
const params = sanitizeSchemaParams(tool.schema, ctx.params);
|
||||
const params = sanitizeSchemaParams(tool.schema, ctx.params, {
|
||||
source: ctx.source,
|
||||
});
|
||||
if (tool.input === "image" && !ctx.source) {
|
||||
throw new ToolError("errors.sourceRequired");
|
||||
}
|
||||
@@ -129,13 +131,17 @@ function ensureWorker(): Worker | null {
|
||||
} else if (payload.errorKey) {
|
||||
entry.reject(new ToolError(payload.errorKey, payload.errorVars));
|
||||
} else {
|
||||
entry.reject(new Error(payload.error ?? "errors.workerFailed"));
|
||||
entry.reject(
|
||||
payload.error
|
||||
? new Error(payload.error)
|
||||
: new ToolError("errors.workerFailed"),
|
||||
);
|
||||
}
|
||||
};
|
||||
candidate.onerror = () => {
|
||||
worker = null;
|
||||
for (const entry of pending.values()) {
|
||||
entry.reject(new Error("errors.workerUnavailable"));
|
||||
entry.reject(new ToolError("errors.workerUnavailable"));
|
||||
}
|
||||
pending.clear();
|
||||
};
|
||||
|
||||
@@ -46,7 +46,7 @@ async function handle(request: WorkerRequest): Promise<void> {
|
||||
try {
|
||||
const tool = getTool(request.toolId);
|
||||
if (!tool?.run) {
|
||||
throw new Error("errors.noImageRun");
|
||||
throw new ToolError("errors.noImageRun");
|
||||
}
|
||||
const source: PixelImage | undefined = request.source
|
||||
? {
|
||||
@@ -56,7 +56,7 @@ async function handle(request: WorkerRequest): Promise<void> {
|
||||
}
|
||||
: undefined;
|
||||
const output = await tool.run({
|
||||
params: sanitizeSchemaParams(tool.schema, request.params),
|
||||
params: sanitizeSchemaParams(tool.schema, request.params, { source }),
|
||||
source,
|
||||
text: request.text,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user