feat: separate slug pages from tools

This commit is contained in:
2026-09-27 16:10:28 +05:00
parent 931ee27b05
commit 7a3498c173
35 changed files with 1436 additions and 993 deletions
+4 -8
View File
@@ -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,
+5 -8
View File
@@ -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);