The Coline App SDK: apps, tools, file types and surfaces that run inside Coline workspaces, and public websites with Coline Sites. TypeScript, with an in-memory test workspace. MIT.
| 4 |
| 5 | /** |
| 6 | * Wire payloads for tool invocation (plan §10.3), carried inside the |
| 7 | * protocol v2 envelope with `kind: "tool.invoke"`. |
| 8 | * |
| 9 | * The payload is self-describing: it carries the capability endpoint and a |
| 10 | * short-lived invocation token minted by Coline for THIS invocation. The |
| 11 | * token binds install, workspace, actor, tool, and effect ceiling — the |
| 12 | * capability endpoint derives every guard input from the token, never |
| 13 | * from caller claims. One mechanism for both execution paths (hosted |
| 14 | * Dynamic Worker and external backend). |
| 15 | */ |
| 16 |
| 17 | export const TOOL_INVOKE_KIND = "tool.invoke" as const; |
| 18 |
| 19 | export const toolInvokeCapabilitiesSchema = z.strictObject({ |
| 20 | /** Absolute URL of the capability endpoint for this invocation. */ |
| 21 | url: z.url().max(2000), |
| 22 | /** Opaque short-lived invocation token (bearer). */ |
| 23 | token: z.string().min(16).max(4096), |
| 24 | }); |
| 25 | export type ToolInvokeCapabilities = z.infer<typeof toolInvokeCapabilitiesSchema>; |
| 26 |
| 27 | export const toolInvokePayloadSchema = z.strictObject({ |
| 28 | tool: toolNameSchema, |
| 29 | input: z.unknown(), |
| 30 | capabilities: toolInvokeCapabilitiesSchema, |
| 31 | }); |
| 32 | export type ToolInvokePayload = z.infer<typeof toolInvokePayloadSchema>; |
| 33 |
| 34 | /** What a tool execution returns over the wire. */ |
| 35 | export const toolInvokeResultSchema = z.strictObject({ |
| 36 | output: z.unknown().optional(), |
| 37 | card: colineUiNodeSchema.optional(), |
| 38 | }); |
| 39 | export type ToolInvokeResult = z.infer<typeof toolInvokeResultSchema>; |
| 40 |
| 41 | export const toolInvokeResponseSchema = z.union([ |
| 42 | z.strictObject({ result: toolInvokeResultSchema }), |
| 43 | z.strictObject({ |
| 44 | error: z.strictObject({ |
| 45 | code: z.string().min(1).max(120), |
| 46 | message: z.string().min(1).max(2000), |
| 47 | }), |
| 48 | }), |
| 49 | ]); |
| 50 | export type ToolInvokeResponse = z.infer<typeof toolInvokeResponseSchema>; |
| 51 |
| 52 | /** |
| 53 | * The capability endpoint wire contract: one POST per operation. |
| 54 | * `args` are the positional arguments of the capability method. |
| 55 | */ |
| 56 | export const capabilityCallRequestSchema = z.strictObject({ |
| 57 | operation: z.string().min(1).max(120), |
| 58 | args: z.array(z.unknown()).max(4).default([]), |
| 59 | }); |
| 60 | export type CapabilityCallRequest = z.infer<typeof capabilityCallRequestSchema>; |
| 61 |
| 62 | export const capabilityCallResponseSchema = z.union([ |
| 63 | z.strictObject({ data: z.unknown() }), |
| 64 | z.strictObject({ |
| 65 | error: z.strictObject({ |
| 66 | code: z.string().min(1).max(120), |
| 67 | message: z.string().min(1).max(2000), |
| 68 | }), |
| 69 | }), |
| 70 | ]); |
| 71 | export type CapabilityCallResponse = z.infer<typeof capabilityCallResponseSchema>; |
| 72 |