/** * Small shared helpers for the authoring tools (see tools.ts). Kept separate so * the per-tool files (find.ts, propose.ts, replay.ts) and the inline tools in * tools.ts share one copy without a circular import. */ import type { JSONSchema } from 'zod/v4/core' import type { CapturedRequest } from '../provider/schema.ts' import type { AuthoringBackend } from './backend.ts' /** * Resolves the session backend for a tool call. The MCP keys it by * `args.captureId` (multi-session); the cloud loop returns its one run backend. * Each authoring tool closes over this so the same tool works for both hosts. */ export type ResolveBackend = (args: Record) => AuthoringBackend /** Build an `object` JSON Schema for a tool input — a small literal shortener, * not a tool abstraction. */ export function objectSchema( properties: Record, required?: string[], ): JSONSchema.ObjectSchema { // `properties` is an untyped Record here (this is a literal shortener, not a // schema validator), so it doesn't structurally match ObjectSchema's strict // per-property schema type — assert the shape. return { type: 'object', properties, ...(required?.length ? { required } : {}), } as unknown as JSONSchema.ObjectSchema } /** Secret-free projection of a captured request for tool output. */ export function publicRequest(r: CapturedRequest) { return { requestId: r.requestId, method: r.method, url: r.url, status: r.status, contentType: r.contentType, size: r.size, ...(r.graphqlOp ? { graphqlOp: r.graphqlOp } : {}), } }