mirror of
https://github.com/Ku6epXBOCTuK/easy-png-tools.git
synced 2026-11-13 17:08:20 +00:00
feat: separate slug pages from tools
This commit is contained in:
@@ -15,7 +15,7 @@ import {
|
||||
} from "./protocol";
|
||||
import { handleWorkerRequest } from "./worker-handler";
|
||||
import { field, toolSchema, type Dimension } from "../registry-schema";
|
||||
import type { ToolEntry } from "../registry";
|
||||
import type { Tool } from "../registry";
|
||||
|
||||
class FakeWorker implements WorkerLike {
|
||||
onmessage: ((event: MessageEvent<WorkerResponse>) => void) | null = null;
|
||||
@@ -61,15 +61,11 @@ function createFactory(throwOnPost = false): {
|
||||
const emptySchema = toolSchema<Record<string, never>>({});
|
||||
|
||||
function makeTool(
|
||||
run: ToolEntry["run"] = () => "direct",
|
||||
overrides: Partial<ToolEntry> = {},
|
||||
): ToolEntry {
|
||||
run: Tool["run"] = () => "direct",
|
||||
overrides: Partial<Tool> = {},
|
||||
): Tool {
|
||||
return {
|
||||
id: "test-tool",
|
||||
slug: "test-tool",
|
||||
title: "Test tool",
|
||||
description: "Test tool",
|
||||
category: "analyze",
|
||||
schema: emptySchema,
|
||||
input: "none",
|
||||
run,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ToolError } from "../core/errors";
|
||||
import type { PixelImage } from "../core/types";
|
||||
import type { ToolContext, ToolEntry, ToolResult } from "../registry";
|
||||
import type { ToolContext, Tool, ToolResult } from "../registry";
|
||||
import { sanitizeSchemaParams } from "../registry-schema";
|
||||
import {
|
||||
decodeWorkerResponse,
|
||||
@@ -37,7 +37,7 @@ function defaultWorkerFactory(): WorkerLike {
|
||||
|
||||
export function createExecutor(
|
||||
options: { workerFactory?: WorkerFactory } = {},
|
||||
): (tool: ToolEntry, ctx: ExecuteContext) => Promise<ToolResult> {
|
||||
): (tool: Tool, ctx: ExecuteContext) => Promise<ToolResult> {
|
||||
const workerFactory = options.workerFactory ?? defaultWorkerFactory;
|
||||
let worker: WorkerLike | null = null;
|
||||
let workerTried = false;
|
||||
@@ -102,7 +102,7 @@ export function createExecutor(
|
||||
}
|
||||
|
||||
async function runDirect(
|
||||
tool: ToolEntry,
|
||||
tool: Tool,
|
||||
ctx: ExecuteContext,
|
||||
): Promise<ToolResult> {
|
||||
return await tool.run(ctx as ToolContext<Record<string, unknown>>);
|
||||
@@ -110,7 +110,7 @@ export function createExecutor(
|
||||
|
||||
function runInWorker(
|
||||
candidate: WorkerLike,
|
||||
tool: ToolEntry,
|
||||
tool: Tool,
|
||||
ctx: ExecuteContext,
|
||||
): Promise<ToolResult> {
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -136,10 +136,7 @@ export function createExecutor(
|
||||
});
|
||||
}
|
||||
|
||||
async function route(
|
||||
tool: ToolEntry,
|
||||
ctx: ExecuteContext,
|
||||
): Promise<ToolResult> {
|
||||
async function route(tool: Tool, ctx: ExecuteContext): Promise<ToolResult> {
|
||||
if (tool.domOnly) return await runDirect(tool, ctx);
|
||||
const candidate = ensureWorker();
|
||||
if (candidate === null) return await runDirect(tool, ctx);
|
||||
|
||||
Reference in New Issue
Block a user