theokit 0.30.0 → 0.30.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/LICENSE +201 -0
  2. package/dist/{actions-virtual-module-PBLLMJY4.js → actions-virtual-module-XHVLBFNN.js} +7 -7
  3. package/dist/actions-virtual-module-Z2IXNF72.js +0 -0
  4. package/dist/add-W6FNTAFS.js +0 -0
  5. package/dist/agent-I5QEOMCN.js +0 -0
  6. package/dist/agents-typed-client-5DCGDWFZ.js +0 -0
  7. package/dist/{app-typed-client-EXHUWPOI.js → app-typed-client-4PAUHTO6.js} +7 -7
  8. package/dist/app-typed-client-YCQC3MZ7.js +0 -0
  9. package/dist/aws-lambda-7GSCNLPY.js +0 -0
  10. package/dist/body-parser-web-FV5HWCY3.js +0 -0
  11. package/dist/boot/index.js +3 -3
  12. package/dist/broadcast-LUMOJIJT.js +0 -0
  13. package/dist/build-V2QEBE7I.js +0 -0
  14. package/dist/build-request-body-preview-QMWD2IXK.js +0 -0
  15. package/dist/bun-KP2KES6S.js +0 -0
  16. package/dist/check-PD2FTKMM.js +0 -0
  17. package/dist/chunk-2CVV6CNN.js +0 -0
  18. package/dist/chunk-45C3WUQ7.js +0 -0
  19. package/dist/{chunk-UYFZ6DDW.js → chunk-4MTCKE5I.js} +1 -189
  20. package/dist/chunk-4MTCKE5I.js.map +1 -0
  21. package/dist/chunk-5ODOE6EF.js +0 -0
  22. package/dist/chunk-63BUBV5L.js +64 -0
  23. package/dist/chunk-63BUBV5L.js.map +1 -0
  24. package/dist/chunk-AFVTEAES.js +0 -0
  25. package/dist/chunk-FOZIR3TG.js +0 -0
  26. package/dist/chunk-FRUEDJFX.js +0 -0
  27. package/dist/chunk-GDN3PXFH.js +0 -0
  28. package/dist/chunk-GEQJAFSV.js +0 -0
  29. package/dist/chunk-GSO77FSM.js +0 -0
  30. package/dist/{chunk-EHUT4FMG.js → chunk-HAOPVC47.js} +29 -27
  31. package/dist/{chunk-EHUT4FMG.js.map → chunk-HAOPVC47.js.map} +1 -1
  32. package/dist/chunk-HGZL5EOI.js +0 -0
  33. package/dist/chunk-HNBWZKIQ.js +0 -0
  34. package/dist/chunk-HZ6USUHC.js +191 -0
  35. package/dist/chunk-HZ6USUHC.js.map +1 -0
  36. package/dist/chunk-IEES3CHD.js +0 -0
  37. package/dist/chunk-JAIKGP3Q.js +0 -0
  38. package/dist/chunk-KXA37ONC.js +0 -0
  39. package/dist/chunk-M6NMS5LR.js +0 -0
  40. package/dist/chunk-P37RZRFV.js +0 -0
  41. package/dist/chunk-S7L6H3KP.js +0 -0
  42. package/dist/chunk-SPFMJAFW.js +326 -0
  43. package/dist/chunk-SPFMJAFW.js.map +1 -0
  44. package/dist/chunk-TERFLG67.js +0 -0
  45. package/dist/{chunk-DMGVH3VG.js → chunk-V3X5FWJA.js} +5 -62
  46. package/dist/chunk-V3X5FWJA.js.map +1 -0
  47. package/dist/chunk-VRVNM3QL.js +0 -0
  48. package/dist/chunk-WR4F4EEZ.js +0 -0
  49. package/dist/chunk-Y4TOVMNC.js +0 -0
  50. package/dist/chunk-YJWEADAW.js +0 -0
  51. package/dist/cloudflare-C6E5SPAE.js +0 -0
  52. package/dist/configure-agent-registry-ZOBVU3MV.js +0 -0
  53. package/dist/db-3UNAMSFK.js +0 -0
  54. package/dist/define-agent-tool-ChaGymol.d.ts +88 -0
  55. package/dist/deno-deploy-RFZN56X4.js +0 -0
  56. package/dist/dev-5ZQMWVFC.js +0 -0
  57. package/dist/dev-emit-EFQRBVYS.js +0 -0
  58. package/dist/dispatcher-EJHL6JMJ.js +0 -0
  59. package/dist/docker-LZZB4D5E.js +0 -0
  60. package/dist/generate-373DALPY.js +0 -0
  61. package/dist/index.js +11 -10
  62. package/dist/index.js.map +1 -1
  63. package/dist/info-2OOXFTJX.js +0 -0
  64. package/dist/{internal-api-JIR3HRKF.js → internal-api-QSP2HCUU.js} +20 -20
  65. package/dist/internal-api-Y5REPVUS.js +0 -0
  66. package/dist/load-config-3EAQTXPH.js +0 -0
  67. package/dist/mcp-VMKWB2BY.js +0 -0
  68. package/dist/netlify-PMLHVPN4.js +0 -0
  69. package/dist/node-BPJ3Z4DT.js +0 -0
  70. package/dist/openapi-ERYWAT3A.js +0 -0
  71. package/dist/registry-3NB7KOUI.js +0 -0
  72. package/dist/router-TLEAOFID.js +0 -0
  73. package/dist/routes-XNS3UM3B.js +0 -0
  74. package/dist/scan-7MJC6PYU.js +0 -0
  75. package/dist/schema-LYOLNHZ7.js +0 -0
  76. package/dist/server/agent/index.d.ts +387 -0
  77. package/dist/server/agent/index.js +43 -0
  78. package/dist/server/agent/index.js.map +1 -0
  79. package/dist/server/auth/index.js +1 -1
  80. package/dist/server/define/index.d.ts +3 -86
  81. package/dist/server/define/index.js +4 -2
  82. package/dist/server/index.d.ts +10 -387
  83. package/dist/server/index.js +112 -398
  84. package/dist/server/index.js.map +1 -1
  85. package/dist/server/jobs/index.js +4 -4
  86. package/dist/server/scan/index.js +1 -1
  87. package/dist/server/webhook/index.d.ts +4 -45
  88. package/dist/server-error-to-envelope-UUXDSLAZ.js +0 -0
  89. package/dist/server-routes-hmr-VZXOP5YT.js +0 -0
  90. package/dist/services-json-Y3XODNB5.js +0 -0
  91. package/dist/services-typed-client-32KMTTXR.js +0 -0
  92. package/dist/start-IFTLTEPZ.js +0 -0
  93. package/dist/static-MB2CD5Y3.js +0 -0
  94. package/dist/storage-manager-ZSQFLEYT.js +0 -0
  95. package/dist/theo-cloud-DQRP6S6M.js +0 -0
  96. package/dist/upgrade-readiness-ACGW44JC.js +0 -0
  97. package/dist/vercel-J6G7ZHYQ.js +0 -0
  98. package/dist/vite-plugin/index.js +11 -10
  99. package/dist/vite-plugin-BNI7YLCD.js +0 -0
  100. package/dist/webhook-types-CNUZY7o1.d.ts +45 -0
  101. package/package.json +14 -10
  102. package/dist/chunk-DMGVH3VG.js.map +0 -1
  103. package/dist/chunk-UYFZ6DDW.js.map +0 -1
  104. /package/dist/{actions-virtual-module-PBLLMJY4.js.map → actions-virtual-module-XHVLBFNN.js.map} +0 -0
  105. /package/dist/{app-typed-client-EXHUWPOI.js.map → app-typed-client-4PAUHTO6.js.map} +0 -0
  106. /package/dist/{internal-api-JIR3HRKF.js.map → internal-api-QSP2HCUU.js.map} +0 -0
File without changes
File without changes
@@ -0,0 +1,191 @@
1
+ // src/server/agent/mcp-app-resources.ts
2
+ function defineAppResource(input) {
3
+ if (!input.uri.startsWith("ui://")) {
4
+ throw new Error(
5
+ `defineAppResource: uri must use the ui:// scheme (an app UI resource). Got: ${JSON.stringify(input.uri)}`
6
+ );
7
+ }
8
+ if (input.html.length === 0) {
9
+ throw new Error(`defineAppResource(${JSON.stringify(input.uri)}): html must be non-empty.`);
10
+ }
11
+ return {
12
+ uri: input.uri,
13
+ name: input.name,
14
+ mimeType: "text/html",
15
+ html: input.html,
16
+ ...input.description !== void 0 ? { description: input.description } : {}
17
+ };
18
+ }
19
+ function buildResourceDescriptors(resources) {
20
+ return resources.map((r) => ({
21
+ uri: r.uri,
22
+ name: r.name,
23
+ mimeType: r.mimeType,
24
+ ...r.description !== void 0 ? { description: r.description } : {}
25
+ }));
26
+ }
27
+ function readAppResource(resources, uri) {
28
+ const found = resources.find((r) => r.uri === uri);
29
+ if (!found) return null;
30
+ return { contents: [{ uri: found.uri, mimeType: "text/html", text: found.html }] };
31
+ }
32
+ function isAppResource(v) {
33
+ if (typeof v !== "object" || v === null) return false;
34
+ const r = v;
35
+ return typeof r.uri === "string" && r.uri.startsWith("ui://") && r.mimeType === "text/html" && typeof r.html === "string";
36
+ }
37
+ function extractAppResources(mod) {
38
+ const raw = mod?.appResources;
39
+ if (!Array.isArray(raw)) return [];
40
+ return raw.filter(isAppResource);
41
+ }
42
+
43
+ // src/server/agent/mcp-handler.ts
44
+ import { compileAgentModule } from "@theokit/agents";
45
+ var MCP_PATH = /^\/api\/agents\/([^/]+)\/mcp$/;
46
+ var MCP_PROTOCOL_VERSION = "2025-06-18";
47
+ function toolDescriptors(tools) {
48
+ return tools.map((t) => ({
49
+ name: t.name,
50
+ description: t.description,
51
+ // The compiled tool already carries a JSON Schema (via `z.toJSONSchema()` in defineAgentTool).
52
+ // Fall back to a permissive object only when a tool genuinely declared no schema.
53
+ inputSchema: t.inputSchema && typeof t.inputSchema === "object" ? t.inputSchema : { type: "object", properties: {} }
54
+ }));
55
+ }
56
+ function isMcpPath(urlPath) {
57
+ const match = MCP_PATH.exec(urlPath);
58
+ return match ? decodeURIComponent(match[1]) : null;
59
+ }
60
+ function isJsonRpcRequest(body) {
61
+ return typeof body === "object" && body !== null && body.jsonrpc === "2.0" && typeof body.method === "string";
62
+ }
63
+ function jsonResponse(payload) {
64
+ return new Response(JSON.stringify(payload), {
65
+ status: 200,
66
+ headers: { "content-type": "application/json; charset=utf-8" }
67
+ });
68
+ }
69
+ async function callTool(tools, toolName, args, hitl) {
70
+ if (typeof toolName !== "string") {
71
+ return {
72
+ content: [{ type: "text", text: "tools/call requires a string `name`." }],
73
+ isError: true
74
+ };
75
+ }
76
+ const tool = tools.find((t) => t.name === toolName);
77
+ if (!tool) {
78
+ return { content: [{ type: "text", text: `Unknown tool: ${toolName}` }], isError: true };
79
+ }
80
+ if (hitl?.has(toolName)) {
81
+ return {
82
+ content: [
83
+ {
84
+ type: "text",
85
+ text: `Tool "${toolName}" requires human approval, which is not available over MCP. Refused.`
86
+ }
87
+ ],
88
+ isError: true
89
+ };
90
+ }
91
+ try {
92
+ const result = await tool.handler(args);
93
+ const text = typeof result === "string" ? result : JSON.stringify(result);
94
+ return { content: [{ type: "text", text }] };
95
+ } catch (err) {
96
+ return {
97
+ content: [
98
+ { type: "text", text: err instanceof Error ? err.message : "Tool execution failed" }
99
+ ],
100
+ isError: true
101
+ };
102
+ }
103
+ }
104
+ function handleResourcesRead(id, params, appResources) {
105
+ const uri = params?.uri;
106
+ if (typeof uri !== "string") {
107
+ return jsonResponse({
108
+ jsonrpc: "2.0",
109
+ id,
110
+ error: { code: -32602, message: "resources/read requires a string `uri` param." }
111
+ });
112
+ }
113
+ const contents = readAppResource(appResources, uri);
114
+ if (contents === null) {
115
+ return jsonResponse({
116
+ jsonrpc: "2.0",
117
+ id,
118
+ error: { code: -32602, message: `Resource not found: ${uri}` }
119
+ });
120
+ }
121
+ return jsonResponse({ jsonrpc: "2.0", id, result: contents });
122
+ }
123
+ async function handleMcpJsonRpc(mod, name, body, appResources = []) {
124
+ if (!isJsonRpcRequest(body)) {
125
+ return jsonResponse({
126
+ jsonrpc: "2.0",
127
+ id: null,
128
+ error: { code: -32600, message: "Invalid Request" }
129
+ });
130
+ }
131
+ const { id, method, params } = body;
132
+ try {
133
+ const compiled = compileAgentModule(mod, `mcp server for "${name}"`);
134
+ if (method === "initialize") {
135
+ const capabilities = { tools: {} };
136
+ if (appResources.length > 0) capabilities.resources = {};
137
+ return jsonResponse({
138
+ jsonrpc: "2.0",
139
+ id,
140
+ result: {
141
+ protocolVersion: MCP_PROTOCOL_VERSION,
142
+ capabilities,
143
+ serverInfo: { name, version: "1.0" }
144
+ }
145
+ });
146
+ }
147
+ if (method === "tools/list") {
148
+ return jsonResponse({
149
+ jsonrpc: "2.0",
150
+ id,
151
+ result: { tools: toolDescriptors(compiled.tools) }
152
+ });
153
+ }
154
+ if (method === "tools/call") {
155
+ const p = params;
156
+ const result = await callTool(compiled.tools, p?.name, p?.arguments ?? {}, compiled.hitl);
157
+ return jsonResponse({ jsonrpc: "2.0", id, result });
158
+ }
159
+ if (method === "resources/list") {
160
+ return jsonResponse({
161
+ jsonrpc: "2.0",
162
+ id,
163
+ result: { resources: buildResourceDescriptors(appResources) }
164
+ });
165
+ }
166
+ if (method === "resources/read") {
167
+ return handleResourcesRead(id, params, appResources);
168
+ }
169
+ return jsonResponse({
170
+ jsonrpc: "2.0",
171
+ id,
172
+ error: { code: -32601, message: `Method not found: ${method}` }
173
+ });
174
+ } catch (err) {
175
+ return jsonResponse({
176
+ jsonrpc: "2.0",
177
+ id,
178
+ error: { code: -32603, message: err instanceof Error ? err.message : "Internal error" }
179
+ });
180
+ }
181
+ }
182
+
183
+ export {
184
+ defineAppResource,
185
+ buildResourceDescriptors,
186
+ readAppResource,
187
+ extractAppResources,
188
+ isMcpPath,
189
+ handleMcpJsonRpc
190
+ };
191
+ //# sourceMappingURL=chunk-HZ6USUHC.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/server/agent/mcp-app-resources.ts","../src/server/agent/mcp-handler.ts"],"sourcesContent":["/**\n * M30 (ADR-0041) — MCP Apps: `ui://` HTML resources for the MCP server (M16).\n *\n * A tool can declare a `ui://` HTML resource; the MCP server advertises it via `resources/list` and\n * serves the HTML via `resources/read`. The client renders it in a SANDBOXED iframe (see\n * `mcp-app-host.ts`). Pure data transforms here — no LLM, no runtime (ADR-0040 § D2 home concern).\n *\n * Security: only the `ui://` scheme is accepted (an app UI resource), never `http(s)://` — the HTML\n * is rendered sandboxed on the client, and the scheme gate keeps a tool from smuggling a remote URL\n * into the app surface.\n */\n\n/** A declared `ui://` app resource. */\nexport interface AppResource {\n uri: string\n name: string\n mimeType: 'text/html'\n html: string\n description?: string\n}\n\n/** Input to {@link defineAppResource}. */\nexport interface AppResourceInput {\n /** MUST start with `ui://`. */\n uri: string\n name: string\n html: string\n description?: string\n}\n\n/** An MCP `resources/list` descriptor (no HTML body — that comes from `resources/read`). */\nexport interface McpResourceDescriptor {\n uri: string\n name: string\n mimeType: 'text/html'\n description?: string\n}\n\n/** An MCP `resources/read` result. */\nexport interface McpResourceContents {\n contents: { uri: string; mimeType: 'text/html'; text: string }[]\n}\n\n/**\n * Declare a `ui://` HTML app resource. Fails fast if the uri is not a `ui://` scheme or the HTML is\n * empty (error-handling.md) — a misconfigured resource is caught at definition time.\n */\nexport function defineAppResource(input: AppResourceInput): AppResource {\n if (!input.uri.startsWith('ui://')) {\n throw new Error(\n `defineAppResource: uri must use the ui:// scheme (an app UI resource). Got: ${JSON.stringify(input.uri)}`,\n )\n }\n if (input.html.length === 0) {\n throw new Error(`defineAppResource(${JSON.stringify(input.uri)}): html must be non-empty.`)\n }\n return {\n uri: input.uri,\n name: input.name,\n mimeType: 'text/html',\n html: input.html,\n ...(input.description !== undefined ? { description: input.description } : {}),\n }\n}\n\n/** Map app resources to MCP `resources/list` descriptors (the HTML body is omitted from the list). */\nexport function buildResourceDescriptors(\n resources: readonly AppResource[],\n): McpResourceDescriptor[] {\n return resources.map((r) => ({\n uri: r.uri,\n name: r.name,\n mimeType: r.mimeType,\n ...(r.description !== undefined ? { description: r.description } : {}),\n }))\n}\n\n/** Serve the HTML for `uri` as an MCP `resources/read` result, or `null` when unknown. */\nexport function readAppResource(\n resources: readonly AppResource[],\n uri: string,\n): McpResourceContents | null {\n const found = resources.find((r) => r.uri === uri)\n if (!found) return null\n return { contents: [{ uri: found.uri, mimeType: 'text/html', text: found.html }] }\n}\n\n/** True when `v` is a well-formed {@link AppResource} (from `defineAppResource`). */\nfunction isAppResource(v: unknown): v is AppResource {\n if (typeof v !== 'object' || v === null) return false\n const r = v as Record<string, unknown>\n return (\n typeof r.uri === 'string' &&\n r.uri.startsWith('ui://') &&\n r.mimeType === 'text/html' &&\n typeof r.html === 'string'\n )\n}\n\n/**\n * M30 wiring — extract the App resources an agent module declares via a named `appResources` export\n * (`export const appResources = [defineAppResource(...)]`). Returns only the well-formed entries; a\n * module without the export (or with a malformed one) yields `[]`. This is how per-agent `ui://`\n * resources reach the MCP server's `resources/list` + `resources/read` without a runtime dependency\n * from `@theokit/agents` on this theo-side type (the module exports them; the serving path reads them).\n */\nexport function extractAppResources(mod: unknown): AppResource[] {\n const raw = (mod as { appResources?: unknown } | null | undefined)?.appResources\n if (!Array.isArray(raw)) return []\n return raw.filter(isAppResource)\n}\n","/**\n * M16 (theokit-ai-first) — serve an agent as an MCP server over HTTP at `/api/agents/<name>/mcp`.\n *\n * Answers the two core MCP methods over JSON-RPC 2.0: `initialize` (server info + capabilities) and\n * `tools/list` (the agent's tools as MCP descriptors, via `buildMcpToolDescriptors`). M30 adds\n * `resources/list` + `resources/read` for `ui://` App resources. Unknown methods return `-32601`\n * (method not found). Web Standards Response (G8). The stdio transport + full method set stay\n * SDK-side (sdk-runtime.md); this exposes the agent over the app's own HTTP route.\n */\nimport { type CompiledTool, compileAgentModule } from '@theokit/agents'\n\nimport { type AppResource, buildResourceDescriptors, readAppResource } from './mcp-app-resources.js'\n\nconst MCP_PATH = /^\\/api\\/agents\\/([^/]+)\\/mcp$/\n\n/**\n * The MCP protocol revision THIS server transport implements (M34). The protocol version is a\n * property of the server that speaks it (this handler), not of the manifest data generator — so the\n * handler owns it. Current MCP revision (`2025-06-18`); replaces the stale `2024-11-05` the manifest\n * generator carried.\n */\nconst MCP_PROTOCOL_VERSION = '2025-06-18'\n\n/** An MCP `tools/list` descriptor with the tool's REAL input schema retained (M34 — no longer dropped). */\ninterface McpToolDescriptor {\n name: string\n description: string\n inputSchema: Record<string, unknown>\n}\n\n/** Build tool descriptors from the compiled tools, retaining each tool's real JSON-Schema input (M34). */\nfunction toolDescriptors(tools: readonly CompiledTool[]): McpToolDescriptor[] {\n return tools.map((t) => ({\n name: t.name,\n description: t.description,\n // The compiled tool already carries a JSON Schema (via `z.toJSONSchema()` in defineAgentTool).\n // Fall back to a permissive object only when a tool genuinely declared no schema.\n inputSchema:\n t.inputSchema && typeof t.inputSchema === 'object'\n ? (t.inputSchema as Record<string, unknown>)\n : { type: 'object', properties: {} },\n }))\n}\n\n/** An MCP `CallToolResult` — `content[]` + `isError` (the shape MCP clients expect). */\ninterface CallToolResult {\n content: { type: 'text'; text: string }[]\n isError?: boolean\n}\n\n/** Return the agent name when `urlPath` is the MCP endpoint, else `null`. */\nexport function isMcpPath(urlPath: string): string | null {\n const match = MCP_PATH.exec(urlPath)\n return match ? decodeURIComponent(match[1]) : null\n}\n\ninterface JsonRpcRequest {\n jsonrpc: '2.0'\n id: number | string | null\n method: string\n params?: unknown\n}\n\nfunction isJsonRpcRequest(body: unknown): body is JsonRpcRequest {\n return (\n typeof body === 'object' &&\n body !== null &&\n (body as { jsonrpc?: unknown }).jsonrpc === '2.0' &&\n typeof (body as { method?: unknown }).method === 'string'\n )\n}\n\nfunction jsonResponse(payload: unknown): Response {\n return new Response(JSON.stringify(payload), {\n status: 200,\n headers: { 'content-type': 'application/json; charset=utf-8' },\n })\n}\n\n/**\n * Execute an MCP `tools/call` against the compiled tools (M34). Finds the tool by name, runs its\n * handler with the supplied `arguments`, and shapes the result into a `CallToolResult`. An unknown\n * tool or a throwing handler yields `{ isError: true }` (MCP convention — the model sees the failure)\n * rather than a JSON-RPC crash.\n */\nasync function callTool(\n tools: readonly CompiledTool[],\n toolName: unknown,\n args: unknown,\n hitl?: ReadonlyMap<string, unknown>,\n): Promise<CallToolResult> {\n if (typeof toolName !== 'string') {\n return {\n content: [{ type: 'text', text: 'tools/call requires a string `name`.' }],\n isError: true,\n }\n }\n const tool = tools.find((t) => t.name === toolName)\n if (!tool) {\n return { content: [{ type: 'text', text: `Unknown tool: ${toolName}` }], isError: true }\n }\n // #99 — REFUSE a HITL-gated tool. The approval gate (`compiled.hitl`) lives in the SDK run-loop,\n // not in the raw tool handler; executing the handler here would BYPASS the human approval the web/\n // TUI surfaces enforce. Over MCP there is no approval mechanism, so a gated tool is not callable —\n // return an error result instead of running it unguarded (fail-closed, Rule 8).\n if (hitl?.has(toolName)) {\n return {\n content: [\n {\n type: 'text',\n text: `Tool \"${toolName}\" requires human approval, which is not available over MCP. Refused.`,\n },\n ],\n isError: true,\n }\n }\n try {\n const result = await tool.handler(args)\n const text = typeof result === 'string' ? result : JSON.stringify(result)\n return { content: [{ type: 'text', text }] }\n } catch (err) {\n return {\n content: [\n { type: 'text', text: err instanceof Error ? err.message : 'Tool execution failed' },\n ],\n isError: true,\n }\n }\n}\n\n/** `resources/read` (M30) — extracted to keep `handleMcpJsonRpc` within the complexity budget. */\nfunction handleResourcesRead(\n id: number | string | null,\n params: unknown,\n appResources: readonly AppResource[],\n): Response {\n const uri = (params as { uri?: unknown } | undefined)?.uri\n if (typeof uri !== 'string') {\n return jsonResponse({\n jsonrpc: '2.0',\n id,\n error: { code: -32602, message: 'resources/read requires a string `uri` param.' },\n })\n }\n const contents = readAppResource(appResources, uri)\n if (contents === null) {\n return jsonResponse({\n jsonrpc: '2.0',\n id,\n error: { code: -32602, message: `Resource not found: ${uri}` },\n })\n }\n return jsonResponse({ jsonrpc: '2.0', id, result: contents })\n}\n\n/**\n * Handle one MCP JSON-RPC request for an agent module. Always returns a 200 JSON-RPC envelope.\n *\n * M30 — `appResources` (optional) are the agent's declared `ui://` App resources; when present the\n * server advertises `capabilities.resources` and answers `resources/list` + `resources/read`.\n */\nexport async function handleMcpJsonRpc(\n mod: unknown,\n name: string,\n body: unknown,\n appResources: readonly AppResource[] = [],\n): Promise<Response> {\n if (!isJsonRpcRequest(body)) {\n return jsonResponse({\n jsonrpc: '2.0',\n id: null,\n error: { code: -32600, message: 'Invalid Request' },\n })\n }\n const { id, method, params } = body\n try {\n const compiled = compileAgentModule(mod, `mcp server for \"${name}\"`)\n if (method === 'initialize') {\n const capabilities: Record<string, unknown> = { tools: {} }\n if (appResources.length > 0) capabilities.resources = {}\n return jsonResponse({\n jsonrpc: '2.0',\n id,\n result: {\n protocolVersion: MCP_PROTOCOL_VERSION,\n capabilities,\n serverInfo: { name, version: '1.0' },\n },\n })\n }\n if (method === 'tools/list') {\n return jsonResponse({\n jsonrpc: '2.0',\n id,\n result: { tools: toolDescriptors(compiled.tools) },\n })\n }\n if (method === 'tools/call') {\n const p = params as { name?: unknown; arguments?: unknown } | undefined\n const result = await callTool(compiled.tools, p?.name, p?.arguments ?? {}, compiled.hitl)\n return jsonResponse({ jsonrpc: '2.0', id, result })\n }\n if (method === 'resources/list') {\n return jsonResponse({\n jsonrpc: '2.0',\n id,\n result: { resources: buildResourceDescriptors(appResources) },\n })\n }\n if (method === 'resources/read') {\n return handleResourcesRead(id, params, appResources)\n }\n return jsonResponse({\n jsonrpc: '2.0',\n id,\n error: { code: -32601, message: `Method not found: ${method}` },\n })\n } catch (err) {\n return jsonResponse({\n jsonrpc: '2.0',\n id,\n error: { code: -32603, message: err instanceof Error ? err.message : 'Internal error' },\n })\n }\n}\n"],"mappings":";AA+CO,SAAS,kBAAkB,OAAsC;AACtE,MAAI,CAAC,MAAM,IAAI,WAAW,OAAO,GAAG;AAClC,UAAM,IAAI;AAAA,MACR,+EAA+E,KAAK,UAAU,MAAM,GAAG,CAAC;AAAA,IAC1G;AAAA,EACF;AACA,MAAI,MAAM,KAAK,WAAW,GAAG;AAC3B,UAAM,IAAI,MAAM,qBAAqB,KAAK,UAAU,MAAM,GAAG,CAAC,4BAA4B;AAAA,EAC5F;AACA,SAAO;AAAA,IACL,KAAK,MAAM;AAAA,IACX,MAAM,MAAM;AAAA,IACZ,UAAU;AAAA,IACV,MAAM,MAAM;AAAA,IACZ,GAAI,MAAM,gBAAgB,SAAY,EAAE,aAAa,MAAM,YAAY,IAAI,CAAC;AAAA,EAC9E;AACF;AAGO,SAAS,yBACd,WACyB;AACzB,SAAO,UAAU,IAAI,CAAC,OAAO;AAAA,IAC3B,KAAK,EAAE;AAAA,IACP,MAAM,EAAE;AAAA,IACR,UAAU,EAAE;AAAA,IACZ,GAAI,EAAE,gBAAgB,SAAY,EAAE,aAAa,EAAE,YAAY,IAAI,CAAC;AAAA,EACtE,EAAE;AACJ;AAGO,SAAS,gBACd,WACA,KAC4B;AAC5B,QAAM,QAAQ,UAAU,KAAK,CAAC,MAAM,EAAE,QAAQ,GAAG;AACjD,MAAI,CAAC,MAAO,QAAO;AACnB,SAAO,EAAE,UAAU,CAAC,EAAE,KAAK,MAAM,KAAK,UAAU,aAAa,MAAM,MAAM,KAAK,CAAC,EAAE;AACnF;AAGA,SAAS,cAAc,GAA8B;AACnD,MAAI,OAAO,MAAM,YAAY,MAAM,KAAM,QAAO;AAChD,QAAM,IAAI;AACV,SACE,OAAO,EAAE,QAAQ,YACjB,EAAE,IAAI,WAAW,OAAO,KACxB,EAAE,aAAa,eACf,OA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A,MACA,OAAO,EAAE,MAAM,QAAQ,SAAS,eAAe,QAAQ,IAAI,UAAU,iBAAiB;AAAA,IACxF,CAAC;AAAA,EACH;AACF;","names":[]}
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,326 @@
1
+ import {
2
+ handleMcpJsonRpc
3
+ } from "./chunk-HZ6USUHC.js";
4
+ import {
5
+ defineAgentTool
6
+ } from "./chunk-63BUBV5L.js";
7
+
8
+ // src/server/agent/workflow-tool.ts
9
+ import { z } from "zod";
10
+ var FAILURE_STATUSES = /* @__PURE__ */ new Set(["failed", "error", "cancelled", "canceled"]);
11
+ function createWorkflowTool(workflow, config) {
12
+ const runFn = workflow?.run;
13
+ if (typeof runFn !== "function") {
14
+ throw new Error(
15
+ "createWorkflowTool: the SDK does not expose a Workflow (expected an object with a run() method). Pass a `Workflow.create(...).\u2026build()` instance from @theokit/sdk."
16
+ );
17
+ }
18
+ const inputSchema = config.inputSchema ?? z.looseObject({});
19
+ return defineAgentTool({
20
+ name: config.name,
21
+ description: config.description,
22
+ inputSchema,
23
+ handler: async (input) => {
24
+ const run = await workflow.run(input);
25
+ if (FAILURE_STATUSES.has(run.status)) {
26
+ throw new Error(
27
+ `createWorkflowTool(${JSON.stringify(config.name)}): workflow run ${run.runId ? `'${run.runId}' ` : ""}failed with status '${run.status}'.`
28
+ );
29
+ }
30
+ return typeof run.output === "string" ? run.output : JSON.stringify(run.output);
31
+ }
32
+ });
33
+ }
34
+
35
+ // src/server/agent/acp-tool.ts
36
+ import { spawn } from "child_process";
37
+ import { AcpClient } from "@theokit/agents";
38
+ import { encodeAcpMessage } from "@theokit/agents";
39
+ var NodeAcpTransport = class {
40
+ // stdin=pipe, stdout=pipe, stderr=inherit → the third stream is null.
41
+ proc;
42
+ constructor(command, args = [], cwd) {
43
+ this.proc = spawn(command, args, { cwd, stdio: ["pipe", "pipe", "inherit"] });
44
+ }
45
+ send(line) {
46
+ this.proc.stdin.write(line);
47
+ }
48
+ subscribe(onData) {
49
+ this.proc.stdout.on("data", (buf) => {
50
+ onData(buf.toString("utf8"));
51
+ });
52
+ }
53
+ close() {
54
+ this.proc.kill();
55
+ }
56
+ };
57
+ function defaultTransport(config) {
58
+ return new NodeAcpTransport(config.command, config.args, config.cwd);
59
+ }
60
+ function createACPTool(config) {
61
+ if (typeof config.onPermissionRequest !== "function") {
62
+ throw new Error("[theokit] createACPTool requires onPermissionRequest (security by default \u2014 no default-allow)");
63
+ }
64
+ const makeTransport = config.transportFactory ?? defaultTransport;
65
+ return {
66
+ name: config.name,
67
+ description: config.description,
68
+ inputSchema: {
69
+ type: "object",
70
+ properties: { message: { type: "string", description: "The task/prompt for the coding agent." } },
71
+ required: ["message"]
72
+ },
73
+ handler: async (input) => {
74
+ const message = typeof input.message === "string" ? input.message : "";
75
+ const client = new AcpClient(makeTransport(config));
76
+ client.onRequest("session/request_permission", (params) => config.onPermissionRequest(params));
77
+ const result = await client.request("session/prompt", { message });
78
+ return result.text ?? "";
79
+ }
80
+ };
81
+ }
82
+
83
+ // src/server/agent/vendor-agent-tool.ts
84
+ function createVendorAgentTool(config) {
85
+ if (!config.vendor || config.vendor.length === 0) {
86
+ throw new Error('createVendorAgentTool: `vendor` is required (e.g. "claude", "openai").');
87
+ }
88
+ const queryFn = config.client?.query;
89
+ if (typeof queryFn !== "function") {
90
+ throw new Error(
91
+ `createVendorAgentTool(${JSON.stringify(config.vendor)}): the vendor client does not expose a query() method. Pass the vendor SDK client (or a @theokit/agent-* wrapper).`
92
+ );
93
+ }
94
+ const name = config.name ?? `${config.vendor}_agent`;
95
+ const description = config.description ?? `Delegate a task to the ${config.vendor} agent and return its answer.`;
96
+ return {
97
+ name,
98
+ description,
99
+ inputSchema: {
100
+ type: "object",
101
+ properties: {
102
+ prompt: { type: "string", description: "The task/prompt for the vendor agent." },
103
+ resumeSessionId: {
104
+ type: "string",
105
+ description: "Optional vendor session id to resume a prior conversation."
106
+ }
107
+ },
108
+ required: ["prompt"]
109
+ },
110
+ handler: async (input) => {
111
+ const prompt = typeof input.prompt === "string" ? input.prompt : "";
112
+ const resumeSessionId = typeof input.resumeSessionId === "string" ? input.resumeSessionId : void 0;
113
+ const result = await config.client.query(
114
+ prompt,
115
+ resumeSessionId !== void 0 ? { resumeSessionId } : void 0
116
+ );
117
+ if (result.sessionId !== void 0 && config.onSession) config.onSession(result.sessionId);
118
+ return result.text;
119
+ }
120
+ };
121
+ }
122
+
123
+ // src/server/agent/code-mode.ts
124
+ var CodeModePermissionDeniedError = class extends Error {
125
+ constructor(tool, reason) {
126
+ const suffix = reason ? `: ${reason}` : "";
127
+ super(`code-mode: tool '${tool}' denied by permission gate${suffix}`);
128
+ this.name = "CodeModePermissionDeniedError";
129
+ }
130
+ };
131
+ function describeToolInput(inputSchema) {
132
+ const props = inputSchema.properties ?? {};
133
+ const required = new Set(inputSchema.required ?? []);
134
+ const entries = Object.entries(props).map(([key, spec]) => {
135
+ const type = typeof spec.type === "string" ? spec.type : "unknown";
136
+ return `${key}${required.has(key) ? "" : "?"}: ${type}`;
137
+ });
138
+ return entries.length > 0 ? `{ ${entries.join(", ")} }` : "{}";
139
+ }
140
+ function generateCodeModeInstructions(tools, toolName) {
141
+ const calls = tools.map((t) => `- \`await api.${t.name}(${describeToolInput(t.inputSchema)})\` \u2014 ${t.description}`).join("\n");
142
+ return [
143
+ `The \`${toolName}\` tool runs your code in a sandbox. Your code may call ONLY these functions (each bridges to a real, validated tool on the host):`,
144
+ calls,
145
+ "Write an async function body that composes these calls and return exactly ONE structured result. Prefer `Promise.all` for independent calls; do arithmetic and aggregation in code, not in prose."
146
+ ].join("\n\n");
147
+ }
148
+ function createCodeMode(config) {
149
+ if (typeof config.onPermissionRequest !== "function") {
150
+ throw new Error(
151
+ "createCodeMode requires onPermissionRequest (security by default \u2014 no default-allow for any tool)."
152
+ );
153
+ }
154
+ const sandboxRun = config.sandbox?.run;
155
+ if (typeof sandboxRun !== "function") {
156
+ throw new Error(
157
+ "createCodeMode requires an injected `sandbox` with a run() method (a vetted isolation boundary \u2014 never node:vm)."
158
+ );
159
+ }
160
+ if (config.tools.length === 0) {
161
+ throw new Error(
162
+ "createCodeMode requires a non-empty tools[] \u2014 the restricted API would be empty."
163
+ );
164
+ }
165
+ const api = {};
166
+ for (const tool2 of config.tools) {
167
+ api[tool2.name] = async (args) => {
168
+ const decision = await config.onPermissionRequest({ tool: tool2.name, args });
169
+ if (!decision.granted) throw new CodeModePermissionDeniedError(tool2.name, decision.reason);
170
+ return tool2.handler(args);
171
+ };
172
+ }
173
+ const name = config.name ?? "run_code";
174
+ const tool = {
175
+ name,
176
+ description: config.description ?? "Run code that composes the available tools. Only the declared tools are callable.",
177
+ inputSchema: {
178
+ type: "object",
179
+ properties: { code: { type: "string", description: "The code to run in the sandbox." } },
180
+ required: ["code"]
181
+ },
182
+ handler: async (input) => {
183
+ const code = typeof input.code === "string" ? input.code : "";
184
+ const result = await config.sandbox.run(code, api);
185
+ return typeof result === "string" ? result : JSON.stringify(result);
186
+ }
187
+ };
188
+ return { tool, instructions: generateCodeModeInstructions(config.tools, name) };
189
+ }
190
+
191
+ // src/server/agent/channel-webhook.ts
192
+ var CHANNEL_PATH = /^\/api\/agents\/([^/]+)\/channels\/([^/]+)\/webhook$/;
193
+ function parseChannelPath(urlPath) {
194
+ const match = CHANNEL_PATH.exec(urlPath);
195
+ if (!match) return null;
196
+ return { agent: decodeURIComponent(match[1]), platform: decodeURIComponent(match[2]) };
197
+ }
198
+ function isChannelPath(urlPath) {
199
+ return CHANNEL_PATH.test(urlPath);
200
+ }
201
+ function jsonError(status, code, message) {
202
+ return new Response(JSON.stringify({ error: { code, message } }), {
203
+ status,
204
+ headers: { "content-type": "application/json" }
205
+ });
206
+ }
207
+ async function handleChannelWebhook(request, urlPath, config) {
208
+ const parsed = parseChannelPath(urlPath);
209
+ if (parsed === null) {
210
+ return jsonError(
211
+ 400,
212
+ "BAD_REQUEST",
213
+ "Path must be /api/agents/<name>/channels/<platform>/webhook."
214
+ );
215
+ }
216
+ if (!Object.hasOwn(config.validators, parsed.platform)) {
217
+ return jsonError(
218
+ 404,
219
+ "UNKNOWN_PLATFORM",
220
+ `No validator configured for platform '${parsed.platform}'.`
221
+ );
222
+ }
223
+ const verify = config.validators[parsed.platform];
224
+ const verifyResult = await verify(request.clone());
225
+ if (!verifyResult.ok) {
226
+ return jsonError(
227
+ 401,
228
+ "INVALID_SIGNATURE",
229
+ `Signature validation failed: ${verifyResult.reason}`
230
+ );
231
+ }
232
+ let payload;
233
+ try {
234
+ payload = await request.json();
235
+ } catch {
236
+ return jsonError(400, "BAD_REQUEST", "Request body must be JSON.");
237
+ }
238
+ await config.onMessage({ agent: parsed.agent, platform: parsed.platform, payload });
239
+ return new Response(JSON.stringify({ ok: true }), {
240
+ status: 200,
241
+ headers: { "content-type": "application/json" }
242
+ });
243
+ }
244
+
245
+ // src/server/agent/stream-agent-turn-in-process.ts
246
+ import {
247
+ compileAgentModule,
248
+ resolveEnabledSkills,
249
+ streamAgentUIMessages
250
+ } from "@theokit/agents";
251
+ var InProcessApprovalRequiredError = class extends Error {
252
+ constructor(toolNames) {
253
+ super(
254
+ `Agent has HITL-gated tool(s) [${toolNames.join(", ")}] but no \`awaitApproval\` resolver was supplied to streamAgentTurnInProcess. In-process runs must resolve approvals inline \u2014 pass awaitApproval, or remove the gate. Refused (fail-closed).`
255
+ );
256
+ this.name = "InProcessApprovalRequiredError";
257
+ }
258
+ };
259
+ function streamAgentTurnInProcess(mod, apiKey, input, deps = { stream: streamAgentUIMessages }) {
260
+ const compiled = compileAgentModule(mod, input.source);
261
+ const gated = compiled.hitl;
262
+ if (gated && gated.size > 0 && !input.awaitApproval) {
263
+ throw new InProcessApprovalRequiredError([...gated.keys()]);
264
+ }
265
+ const resolve = input.awaitApproval;
266
+ const hitl = gated && gated.size > 0 && resolve ? {
267
+ gated,
268
+ awaitApproval: (approvalId, opts, toolName) => resolve({ approvalId, toolName, opts })
269
+ } : void 0;
270
+ const sessionId = input.sessionId ?? crypto.randomUUID();
271
+ return (async function* () {
272
+ if (compiled.skillsResolver) {
273
+ const enabled = await resolveEnabledSkills(compiled.skillsResolver, compiled.runContext ?? {});
274
+ if (enabled !== void 0) compiled.skills = { enabled, autoInject: true };
275
+ }
276
+ yield* deps.stream(compiled, apiKey, {
277
+ message: input.message,
278
+ sessionId,
279
+ hitl,
280
+ signal: input.signal
281
+ });
282
+ })();
283
+ }
284
+
285
+ // src/server/agent/mcp-stdio.ts
286
+ async function handleMcpStdioLine(line, mod, name, appResources = []) {
287
+ const trimmed = line.trim();
288
+ if (trimmed.length === 0) return null;
289
+ let body;
290
+ try {
291
+ body = JSON.parse(trimmed);
292
+ } catch {
293
+ return JSON.stringify({
294
+ jsonrpc: "2.0",
295
+ id: null,
296
+ error: { code: -32700, message: "Parse error" }
297
+ });
298
+ }
299
+ const response = await handleMcpJsonRpc(mod, name, body, appResources);
300
+ const payload = await response.json();
301
+ return JSON.stringify(payload);
302
+ }
303
+ async function serveMcpStdio(mod, name, appResources, streams) {
304
+ for await (const line of streams.lines) {
305
+ const out = await handleMcpStdioLine(line, mod, name, appResources);
306
+ if (out !== null) streams.write(`${out}
307
+ `);
308
+ }
309
+ }
310
+
311
+ export {
312
+ createWorkflowTool,
313
+ NodeAcpTransport,
314
+ createACPTool,
315
+ createVendorAgentTool,
316
+ CodeModePermissionDeniedError,
317
+ createCodeMode,
318
+ parseChannelPath,
319
+ isChannelPath,
320
+ handleChannelWebhook,
321
+ InProcessApprovalRequiredError,
322
+ streamAgentTurnInProcess,
323
+ handleMcpStdioLine,
324
+ serveMcpStdio
325
+ };
326
+ //# sourceMappingURL=chunk-SPFMJAFW.js.map