import { z } from "zod/v4"; import { toolNameSchema } from "../manifest/tool"; import { colineUiNodeSchema } from "../tree/tree"; /** * Wire payloads for tool invocation (plan §10.3), carried inside the * protocol v2 envelope with `kind: "tool.invoke"`. * * The payload is self-describing: it carries the capability endpoint and a * short-lived invocation token minted by Coline for THIS invocation. The * token binds install, workspace, actor, tool, and effect ceiling — the * capability endpoint derives every guard input from the token, never * from caller claims. One mechanism for both execution paths (hosted * Dynamic Worker and external backend). */ export const TOOL_INVOKE_KIND = "tool.invoke" as const; export const toolInvokeCapabilitiesSchema = z.strictObject({ /** Absolute URL of the capability endpoint for this invocation. */ url: z.url().max(2000), /** Opaque short-lived invocation token (bearer). */ token: z.string().min(16).max(4096), }); export type ToolInvokeCapabilities = z.infer; export const toolInvokePayloadSchema = z.strictObject({ tool: toolNameSchema, input: z.unknown(), capabilities: toolInvokeCapabilitiesSchema, }); export type ToolInvokePayload = z.infer; /** What a tool execution returns over the wire. */ export const toolInvokeResultSchema = z.strictObject({ output: z.unknown().optional(), card: colineUiNodeSchema.optional(), }); export type ToolInvokeResult = z.infer; export const toolInvokeResponseSchema = z.union([ z.strictObject({ result: toolInvokeResultSchema }), z.strictObject({ error: z.strictObject({ code: z.string().min(1).max(120), message: z.string().min(1).max(2000), }), }), ]); export type ToolInvokeResponse = z.infer; /** * The capability endpoint wire contract: one POST per operation. * `args` are the positional arguments of the capability method. */ export const capabilityCallRequestSchema = z.strictObject({ operation: z.string().min(1).max(120), args: z.array(z.unknown()).max(4).default([]), }); export type CapabilityCallRequest = z.infer; export const capabilityCallResponseSchema = z.union([ z.strictObject({ data: z.unknown() }), z.strictObject({ error: z.strictObject({ code: z.string().min(1).max(120), message: z.string().min(1).max(2000), }), }), ]); export type CapabilityCallResponse = z.infer;