theokit 0.20.0 → 0.22.0

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 (57) hide show
  1. package/dist/{agent-76WK2CZJ.js → agent-GXPTQTCU.js} +2 -2
  2. package/dist/{build-6UDZJIHD.js → build-2JDQBBWN.js} +3 -3
  3. package/dist/{chunk-DXF64KS5.js → chunk-4QXVTX3X.js} +30 -12
  4. package/dist/chunk-4QXVTX3X.js.map +1 -0
  5. package/dist/{chunk-WLKFWVOM.js → chunk-5PY3QPVM.js} +32 -47
  6. package/dist/chunk-5PY3QPVM.js.map +1 -0
  7. package/dist/{chunk-3WOODHXK.js → chunk-D7D6V6FN.js} +12 -6
  8. package/dist/chunk-D7D6V6FN.js.map +1 -0
  9. package/dist/{chunk-W4YO6S4I.js → chunk-FO2KMFAE.js} +101 -67
  10. package/dist/chunk-FO2KMFAE.js.map +1 -0
  11. package/dist/{chunk-23T4CO4M.js → chunk-JRYP7KNS.js} +2 -2
  12. package/dist/{chunk-7PFHQ56Q.js → chunk-RQCZTDCX.js} +39 -15
  13. package/dist/chunk-RQCZTDCX.js.map +1 -0
  14. package/dist/{chunk-DMC6HYUR.js → chunk-VS6LJM2V.js} +69 -47
  15. package/dist/chunk-VS6LJM2V.js.map +1 -0
  16. package/dist/cli/index.js +6 -6
  17. package/dist/{define-websocket-CdK94O-D.d.ts → define-websocket-CPQcQK9h.d.ts} +1 -19
  18. package/dist/{dev-NHHTXOA4.js → dev-7AW7FBNH.js} +4 -4
  19. package/dist/{generate-OMKHQ7OM.js → generate-373DALPY.js} +62 -70
  20. package/dist/generate-373DALPY.js.map +1 -0
  21. package/dist/{index-B40qUSrQ.d.ts → index-C3ged4mn.d.ts} +2 -2
  22. package/dist/index.d.ts +1 -8
  23. package/dist/index.js +2 -3
  24. package/dist/{mcp-HP5RVOOZ.js → mcp-MOKIIMJ6.js} +4 -4
  25. package/dist/{mcp-HP5RVOOZ.js.map → mcp-MOKIIMJ6.js.map} +1 -1
  26. package/dist/{plugin-runner-BGBkzgi0.d.ts → plugin-runner-CMprWWHZ.d.ts} +1 -1
  27. package/dist/{plugin-types-DNJGxr4Z.d.ts → plugin-types-L49QYMb5.d.ts} +1 -19
  28. package/dist/{registry-XSRSTH33.js → registry-3NB7KOUI.js} +2 -2
  29. package/dist/server/define/index.d.ts +169 -221
  30. package/dist/server/define/index.js +1 -15
  31. package/dist/server/http/index.d.ts +3 -3
  32. package/dist/server/index.d.ts +168 -7
  33. package/dist/server/index.js +61 -19
  34. package/dist/server/index.js.map +1 -1
  35. package/dist/server/plugins/index.d.ts +3 -3
  36. package/dist/server/realtime/index.d.ts +1 -1
  37. package/dist/{start-ILT6E25Q.js → start-4VHDT4TN.js} +6 -4
  38. package/dist/{start-ILT6E25Q.js.map → start-4VHDT4TN.js.map} +1 -1
  39. package/dist/{static-CYG2WGYP.js → static-MB2CD5Y3.js} +1 -1
  40. package/dist/static-MB2CD5Y3.js.map +1 -0
  41. package/dist/vite-plugin/index.js +2 -2
  42. package/dist/{vite-plugin-3UDOJGO5.js → vite-plugin-5WTU62ZH.js} +4 -4
  43. package/package.json +2 -2
  44. package/dist/chunk-3WOODHXK.js.map +0 -1
  45. package/dist/chunk-7PFHQ56Q.js.map +0 -1
  46. package/dist/chunk-DMC6HYUR.js.map +0 -1
  47. package/dist/chunk-DXF64KS5.js.map +0 -1
  48. package/dist/chunk-W4YO6S4I.js.map +0 -1
  49. package/dist/chunk-WLKFWVOM.js.map +0 -1
  50. package/dist/generate-OMKHQ7OM.js.map +0 -1
  51. package/dist/static-CYG2WGYP.js.map +0 -1
  52. /package/dist/{agent-76WK2CZJ.js.map → agent-GXPTQTCU.js.map} +0 -0
  53. /package/dist/{build-6UDZJIHD.js.map → build-2JDQBBWN.js.map} +0 -0
  54. /package/dist/{chunk-23T4CO4M.js.map → chunk-JRYP7KNS.js.map} +0 -0
  55. /package/dist/{dev-NHHTXOA4.js.map → dev-7AW7FBNH.js.map} +0 -0
  56. /package/dist/{registry-XSRSTH33.js.map → registry-3NB7KOUI.js.map} +0 -0
  57. /package/dist/{vite-plugin-3UDOJGO5.js.map → vite-plugin-5WTU62ZH.js.map} +0 -0
@@ -2,11 +2,11 @@
2
2
  import "tsx/esm";
3
3
  import {
4
4
  createAgentSsrLoader
5
- } from "./chunk-23T4CO4M.js";
5
+ } from "./chunk-JRYP7KNS.js";
6
6
  import {
7
7
  extractAppResources,
8
8
  handleMcpJsonRpc
9
- } from "./chunk-DMC6HYUR.js";
9
+ } from "./chunk-VS6LJM2V.js";
10
10
  import "./chunk-M6NMS5LR.js";
11
11
  import "./chunk-GDN3PXFH.js";
12
12
  import {
@@ -31,7 +31,7 @@ async function handleMcpStdioLine(line, mod, name, appResources = []) {
31
31
  error: { code: -32700, message: "Parse error" }
32
32
  });
33
33
  }
34
- const response = handleMcpJsonRpc(mod, name, body, appResources);
34
+ const response = await handleMcpJsonRpc(mod, name, body, appResources);
35
35
  const payload = await response.json();
36
36
  return JSON.stringify(payload);
37
37
  }
@@ -75,4 +75,4 @@ async function mcpCommand(name, deps = {}) {
75
75
  export {
76
76
  mcpCommand
77
77
  };
78
- //# sourceMappingURL=mcp-HP5RVOOZ.js.map
78
+ //# sourceMappingURL=mcp-MOKIIMJ6.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/cli/commands/mcp.ts","../src/server/agent/mcp-stdio.ts"],"sourcesContent":["/**\n * `theokit mcp <agent>` — expose a scanned agent as an MCP server over stdio.\n *\n * The stdio sibling of the M16 HTTP route (`POST /api/agents/<name>/mcp`): a desktop MCP client\n * (e.g. Claude Desktop) spawns this command and speaks newline-delimited JSON-RPC over the pipe.\n * It reuses the framework's OWN `serveMcpStdio` / `handleMcpJsonRpc` (no LLM call, no runtime — a\n * TRANSPORT, like the HTTP route). `deps` is injectable so the routing is tested without Vite/stdin.\n */\nimport { createInterface } from 'node:readline'\n\nimport { extractAppResources } from '../../server/agent/mcp-app-resources.js'\nimport { type StdioStreams, serveMcpStdio } from '../../server/agent/mcp-stdio.js'\nimport { scanAgents } from '../../server/scan/agent-scan.js'\n\nimport { createAgentSsrLoader } from './agent.js'\n\nexport interface McpCommandDeps {\n projectRoot?: string\n /** Load a TS agent module; defaults to the framework's Vite SSR loader (same transpile as dev). */\n loadModule?: (filePath: string) => Promise<Record<string, unknown>>\n /** stdio streams; defaults to `readline(process.stdin)` + `process.stdout`. Injected in tests. */\n streams?: StdioStreams\n /** Agents dir name (config `agentsDir`); defaults to the loaded config's value (\"agents\"). Tests inject it. */\n agentsDir?: string\n}\n\nexport async function mcpCommand(name: string, deps: McpCommandDeps = {}): Promise<void> {\n const projectRoot = deps.projectRoot ?? process.cwd()\n // #95 follow-up — resolve agents dir from config (default \"agents\") so `agentsDir` is honored here too.\n const agentsDir =\n deps.agentsDir ??\n (await (await import('../../config/load-config.js')).loadConfig(projectRoot)).agentsDir\n const agent = scanAgents(projectRoot, agentsDir).find((a) => a.name === name)\n if (!agent) {\n const names = scanAgents(projectRoot, agentsDir)\n .map((a) => a.name)\n .join(', ')\n throw new Error(\n `theokit mcp: agent '${name}' not found. Available: ${names || '(none in agents/)'}`,\n )\n }\n\n let loadModule = deps.loadModule\n let dispose: (() => Promise<void>) | undefined\n if (!loadModule) {\n const loader = await createAgentSsrLoader(projectRoot)\n loadModule = loader.load\n dispose = loader.dispose\n }\n\n const streams =\n deps.streams ??\n ({\n lines: createInterface({ input: process.stdin }),\n write: (line: string) => process.stdout.write(line),\n } satisfies StdioStreams)\n\n try {\n const mod = await loadModule(agent.filePath)\n await serveMcpStdio(mod, agent.name, extractAppResources(mod), streams)\n } finally {\n if (dispose) await dispose()\n }\n}\n","/**\n * MCP stdio transport (M16 follow-up) — expose a TheoKit agent as an MCP server over stdin/stdout,\n * the sibling of the M16 HTTP route (`POST /api/agents/<name>/mcp`). A desktop MCP client (e.g.\n * Claude Desktop) spawns `theokit mcp <agent>` and speaks newline-delimited JSON-RPC over the pipe.\n *\n * This is a TRANSPORT over the framework's OWN {@link handleMcpJsonRpc} — it reuses the exact handler\n * the HTTP route uses; it calls no LLM, spawns no MCP client, and reimplements no runtime (G2 /\n * sdk-runtime.md). Distinct from the SDK's MCP CLIENT stdio (which spawns external MCP servers via\n * `mcpServers` command/args) — that stays SDK-side. Here TheoKit is the SERVER. The framework-side\n * placement of this server-exposure transport is recorded in ADR-0042 (refining ADR-0040's M16 note).\n */\nimport type { AppResource } from './mcp-app-resources.js'\nimport { handleMcpJsonRpc } from './mcp-handler.js'\n\n/**\n * Handle one newline-delimited JSON-RPC line. Returns the response line to write to stdout, or\n * `null` for a blank line (nothing to emit). A malformed JSON line yields a `-32700` (Parse error)\n * envelope — never throws, so the stdio loop never dies on bad input.\n */\nexport async function handleMcpStdioLine(\n line: string,\n mod: unknown,\n name: string,\n appResources: readonly AppResource[] = [],\n): Promise<string | null> {\n const trimmed = line.trim()\n if (trimmed.length === 0) return null\n let body: unknown\n try {\n body = JSON.parse(trimmed)\n } catch {\n return JSON.stringify({\n jsonrpc: '2.0',\n id: null,\n error: { code: -32700, message: 'Parse error' },\n })\n }\n const response = handleMcpJsonRpc(mod, name, body, appResources)\n const payload: unknown = await response.json()\n return JSON.stringify(payload)\n}\n\n/** A minimal readable line source (an async iterable of lines) + a writable sink. */\nexport interface StdioStreams {\n /** Async iterable of newline-delimited input lines (e.g. `readline.createInterface({ input })`). */\n lines: AsyncIterable<string>\n /** Write a response line (the caller appends no newline). */\n write: (line: string) => void\n}\n\n/**\n * Drive the MCP stdio server loop: for each input line, dispatch via {@link handleMcpStdioLine} and\n * write the response line (with a trailing `\\n`). Returns when the input stream ends (EOF).\n */\nexport async function serveMcpStdio(\n mod: unknown,\n name: string,\n appResources: readonly AppResource[],\n streams: StdioStreams,\n): Promise<void> {\n for await (const line of streams.lines) {\n const out = await handleMcpStdioLine(line, mod, name, appResources)\n if (out !== null) streams.write(`${out}\\n`)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAQA,SAAS,uBAAuB;;;ACWhC,eAAsB,mBACpB,MACA,KACA,MACA,eAAuC,CAAC,GAChB;AACxB,QAAM,UAAU,KAAK,KAAK;AAC1B,MAAI,QAAQ,WAAW,EAAG,QAAO;AACjC,MAAI;AACJ,MAAI;AACF,WAAO,KAAK,MAAM,OAAO;AAAA,EAC3B,QAAQ;AACN,WAAO,KAAK,UAAU;AAAA,MACpB,SAAS;AAAA,MACT,IAAI;AAAA,MACJ,OAAO,EAAE,MAAM,QAAQ,SAAS,cAAc;AAAA,IAChD,CAAC;AAAA,EACH;AACA,QAAM,WAAW,iBAAiB,KAAK,MAAM,MAAM,YAAY;AAC/D,QAAM,UAAmB,MAAM,SAAS,KAAK;AAC7C,SAAO,KAAK,UAAU,OAAO;AAC/B;AAcA,eAAsB,cACpB,KACA,MACA,cACA,SACe;AACf,mBAAiB,QAAQ,QAAQ,OAAO;AACtC,UAAM,MAAM,MAAM,mBAAmB,MAAM,KAAK,MAAM,YAAY;AAClE,QAAI,QAAQ,KAAM,SAAQ,MAAM,GAAG,GAAG;AAAA,CAAI;AAAA,EAC5C;AACF;;;ADtCA,eAAsB,WAAW,MAAc,OAAuB,CAAC,GAAkB;AACvF,QAAM,cAAc,KAAK,eAAe,QAAQ,IAAI;AAEpD,QAAM,YACJ,KAAK,cACJ,OAAO,MAAM,OAAO,2BAA6B,GAAG,WAAW,WAAW,GAAG;AAChF,QAAM,QAAQ,WAAW,aAAa,SAAS,EAAE,KAAK,CAAC,MAAM,EAAE,SAAS,IAAI;AAC5E,MAAI,CAAC,OAAO;AACV,UAAM,QAAQ,WAAW,aAAa,SAAS,EAC5C,IAAI,CAAC,MAAM,EAAE,IAAI,EACjB,KAAK,IAAI;AACZ,UAAM,IAAI;AAAA,MACR,uBAAuB,IAAI,2BAA2B,SAAS,mBAAmB;AAAA,IACpF;AAAA,EACF;AAEA,MAAI,aAAa,KAAK;AACtB,MAAI;AACJ,MAAI,CAAC,YAAY;AACf,UAAM,SAAS,MAAM,qBAAqB,WAAW;AACrD,iBAAa,OAAO;AACpB,cAAU,OAAO;AAAA,EACnB;AAEA,QAAM,UACJ,KAAK,WACJ;AAAA,IACC,OAAO,gBAAgB,EAAE,OAAO,QAAQ,MAAM,CAAC;AAAA,IAC/C,OAAO,CAAC,SAAiB,QAAQ,OAAO,MAAM,IAAI;AAAA,EACpD;AAEF,MAAI;AACF,UAAM,MAAM,MAAM,WAAW,MAAM,QAAQ;AAC3C,UAAM,cAAc,KAAK,MAAM,MAAM,oBAAoB,GAAG,GAAG,OAAO;AAAA,EACxE,UAAE;AACA,QAAI,QAAS,OAAM,QAAQ;AAAA,EAC7B;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/cli/commands/mcp.ts","../src/server/agent/mcp-stdio.ts"],"sourcesContent":["/**\n * `theokit mcp <agent>` — expose a scanned agent as an MCP server over stdio.\n *\n * The stdio sibling of the M16 HTTP route (`POST /api/agents/<name>/mcp`): a desktop MCP client\n * (e.g. Claude Desktop) spawns this command and speaks newline-delimited JSON-RPC over the pipe.\n * It reuses the framework's OWN `serveMcpStdio` / `handleMcpJsonRpc` (no LLM call, no runtime — a\n * TRANSPORT, like the HTTP route). `deps` is injectable so the routing is tested without Vite/stdin.\n */\nimport { createInterface } from 'node:readline'\n\nimport { extractAppResources } from '../../server/agent/mcp-app-resources.js'\nimport { type StdioStreams, serveMcpStdio } from '../../server/agent/mcp-stdio.js'\nimport { scanAgents } from '../../server/scan/agent-scan.js'\n\nimport { createAgentSsrLoader } from './agent.js'\n\nexport interface McpCommandDeps {\n projectRoot?: string\n /** Load a TS agent module; defaults to the framework's Vite SSR loader (same transpile as dev). */\n loadModule?: (filePath: string) => Promise<Record<string, unknown>>\n /** stdio streams; defaults to `readline(process.stdin)` + `process.stdout`. Injected in tests. */\n streams?: StdioStreams\n /** Agents dir name (config `agentsDir`); defaults to the loaded config's value (\"agents\"). Tests inject it. */\n agentsDir?: string\n}\n\nexport async function mcpCommand(name: string, deps: McpCommandDeps = {}): Promise<void> {\n const projectRoot = deps.projectRoot ?? process.cwd()\n // #95 follow-up — resolve agents dir from config (default \"agents\") so `agentsDir` is honored here too.\n const agentsDir =\n deps.agentsDir ??\n (await (await import('../../config/load-config.js')).loadConfig(projectRoot)).agentsDir\n const agent = scanAgents(projectRoot, agentsDir).find((a) => a.name === name)\n if (!agent) {\n const names = scanAgents(projectRoot, agentsDir)\n .map((a) => a.name)\n .join(', ')\n throw new Error(\n `theokit mcp: agent '${name}' not found. Available: ${names || '(none in agents/)'}`,\n )\n }\n\n let loadModule = deps.loadModule\n let dispose: (() => Promise<void>) | undefined\n if (!loadModule) {\n const loader = await createAgentSsrLoader(projectRoot)\n loadModule = loader.load\n dispose = loader.dispose\n }\n\n const streams =\n deps.streams ??\n ({\n lines: createInterface({ input: process.stdin }),\n write: (line: string) => process.stdout.write(line),\n } satisfies StdioStreams)\n\n try {\n const mod = await loadModule(agent.filePath)\n await serveMcpStdio(mod, agent.name, extractAppResources(mod), streams)\n } finally {\n if (dispose) await dispose()\n }\n}\n","/**\n * MCP stdio transport (M16 follow-up) — expose a TheoKit agent as an MCP server over stdin/stdout,\n * the sibling of the M16 HTTP route (`POST /api/agents/<name>/mcp`). A desktop MCP client (e.g.\n * Claude Desktop) spawns `theokit mcp <agent>` and speaks newline-delimited JSON-RPC over the pipe.\n *\n * This is a TRANSPORT over the framework's OWN {@link handleMcpJsonRpc} — it reuses the exact handler\n * the HTTP route uses; it calls no LLM, spawns no MCP client, and reimplements no runtime (G2 /\n * sdk-runtime.md). Distinct from the SDK's MCP CLIENT stdio (which spawns external MCP servers via\n * `mcpServers` command/args) — that stays SDK-side. Here TheoKit is the SERVER. The framework-side\n * placement of this server-exposure transport is recorded in ADR-0042 (refining ADR-0040's M16 note).\n */\nimport type { AppResource } from './mcp-app-resources.js'\nimport { handleMcpJsonRpc } from './mcp-handler.js'\n\n/**\n * Handle one newline-delimited JSON-RPC line. Returns the response line to write to stdout, or\n * `null` for a blank line (nothing to emit). A malformed JSON line yields a `-32700` (Parse error)\n * envelope — never throws, so the stdio loop never dies on bad input.\n */\nexport async function handleMcpStdioLine(\n line: string,\n mod: unknown,\n name: string,\n appResources: readonly AppResource[] = [],\n): Promise<string | null> {\n const trimmed = line.trim()\n if (trimmed.length === 0) return null\n let body: unknown\n try {\n body = JSON.parse(trimmed)\n } catch {\n return JSON.stringify({\n jsonrpc: '2.0',\n id: null,\n error: { code: -32700, message: 'Parse error' },\n })\n }\n const response = await handleMcpJsonRpc(mod, name, body, appResources)\n const payload: unknown = await response.json()\n return JSON.stringify(payload)\n}\n\n/** A minimal readable line source (an async iterable of lines) + a writable sink. */\nexport interface StdioStreams {\n /** Async iterable of newline-delimited input lines (e.g. `readline.createInterface({ input })`). */\n lines: AsyncIterable<string>\n /** Write a response line (the caller appends no newline). */\n write: (line: string) => void\n}\n\n/**\n * Drive the MCP stdio server loop: for each input line, dispatch via {@link handleMcpStdioLine} and\n * write the response line (with a trailing `\\n`). Returns when the input stream ends (EOF).\n */\nexport async function serveMcpStdio(\n mod: unknown,\n name: string,\n appResources: readonly AppResource[],\n streams: StdioStreams,\n): Promise<void> {\n for await (const line of streams.lines) {\n const out = await handleMcpStdioLine(line, mod, name, appResources)\n if (out !== null) streams.write(`${out}\\n`)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAQA,SAAS,uBAAuB;;;ACWhC,eAAsB,mBACpB,MACA,KACA,MACA,eAAuC,CAAC,GAChB;AACxB,QAAM,UAAU,KAAK,KAAK;AAC1B,MAAI,QAAQ,WAAW,EAAG,QAAO;AACjC,MAAI;AACJ,MAAI;AACF,WAAO,KAAK,MAAM,OAAO;AAAA,EAC3B,QAAQ;AACN,WAAO,KAAK,UAAU;AAAA,MACpB,SAAS;AAAA,MACT,IAAI;AAAA,MACJ,OAAO,EAAE,MAAM,QAAQ,SAAS,cAAc;AAAA,IAChD,CAAC;AAAA,EACH;AACA,QAAM,WAAW,MAAM,iBAAiB,KAAK,MAAM,MAAM,YAAY;AACrE,QAAM,UAAmB,MAAM,SAAS,KAAK;AAC7C,SAAO,KAAK,UAAU,OAAO;AAC/B;AAcA,eAAsB,cACpB,KACA,MACA,cACA,SACe;AACf,mBAAiB,QAAQ,QAAQ,OAAO;AACtC,UAAM,MAAM,MAAM,mBAAmB,MAAM,KAAK,MAAM,YAAY;AAClE,QAAI,QAAQ,KAAM,SAAQ,MAAM,GAAG,GAAG;AAAA,CAAI;AAAA,EAC5C;AACF;;;ADtCA,eAAsB,WAAW,MAAc,OAAuB,CAAC,GAAkB;AACvF,QAAM,cAAc,KAAK,eAAe,QAAQ,IAAI;AAEpD,QAAM,YACJ,KAAK,cACJ,OAAO,MAAM,OAAO,2BAA6B,GAAG,WAAW,WAAW,GAAG;AAChF,QAAM,QAAQ,WAAW,aAAa,SAAS,EAAE,KAAK,CAAC,MAAM,EAAE,SAAS,IAAI;AAC5E,MAAI,CAAC,OAAO;AACV,UAAM,QAAQ,WAAW,aAAa,SAAS,EAC5C,IAAI,CAAC,MAAM,EAAE,IAAI,EACjB,KAAK,IAAI;AACZ,UAAM,IAAI;AAAA,MACR,uBAAuB,IAAI,2BAA2B,SAAS,mBAAmB;AAAA,IACpF;AAAA,EACF;AAEA,MAAI,aAAa,KAAK;AACtB,MAAI;AACJ,MAAI,CAAC,YAAY;AACf,UAAM,SAAS,MAAM,qBAAqB,WAAW;AACrD,iBAAa,OAAO;AACpB,cAAU,OAAO;AAAA,EACnB;AAEA,QAAM,UACJ,KAAK,WACJ;AAAA,IACC,OAAO,gBAAgB,EAAE,OAAO,QAAQ,MAAM,CAAC;AAAA,IAC/C,OAAO,CAAC,SAAiB,QAAQ,OAAO,MAAM,IAAI;AAAA,EACpD;AAEF,MAAI;AACF,UAAM,MAAM,MAAM,WAAW,MAAM,QAAQ;AAC3C,UAAM,cAAc,KAAK,MAAM,MAAM,oBAAoB,GAAG,GAAG,OAAO;AAAA,EACxE,UAAE;AACA,QAAI,QAAS,OAAM,QAAQ;AAAA,EAC7B;AACF;","names":[]}
@@ -1,4 +1,4 @@
1
- import { T as TheoPlugin, a as TheoApp, P as PluginContext, H as HookResult, R as RunHookOptions } from './plugin-types-DNJGxr4Z.js';
1
+ import { T as TheoPlugin, a as TheoApp, P as PluginContext, H as HookResult, R as RunHookOptions } from './plugin-types-L49QYMb5.js';
2
2
 
3
3
  declare class DuplicatePluginError extends Error {
4
4
  constructor(name: string);
@@ -29,24 +29,6 @@ interface TheoPlugin {
29
29
  name: string;
30
30
  register(app: TheoApp): void | Promise<void>;
31
31
  }
32
- /**
33
- * Identity function for plugin authors. Provides auto-completion + type
34
- * inference at the call site (TanStack/Vite/Astro pattern). Pure runtime
35
- * no-op — returns the input unchanged.
36
- *
37
- * @example
38
- * import { definePlugin } from 'theokit/server'
39
- * export default definePlugin({
40
- * name: 'my-plugin',
41
- * register(app) {
42
- * app.addHook('onRequest', (req) => { ... })
43
- * },
44
- * })
45
- *
46
- * Equivalent to `const p: TheoPlugin = {...}` but more ergonomic. See
47
- * ADR-0008 (D1 + D6) for the rationale.
48
- */
49
- declare function definePlugin(plugin: TheoPlugin): TheoPlugin;
50
32
  /**
51
33
  * Web-Standards plugin context. Available during all 4 hook lifecycle
52
34
  * stages (onRequest, preHandler, onResponse, onError).
@@ -76,4 +58,4 @@ type WebPreHandlerHook = (ctx: WebPluginContext) => void | Promise<void>;
76
58
  type WebOnResponseHook = (ctx: WebPluginContext) => void | Promise<void>;
77
59
  type WebOnErrorHook = (ctx: WebPluginErrorContext) => void | Promise<void>;
78
60
 
79
- export { type HookResult as H, type OnErrorHook as O, type PluginContext as P, type RunHookOptions as R, type TheoPlugin as T, type WebOnRequestHook as W, type TheoApp as a, type WebPreHandlerHook as b, type WebOnResponseHook as c, type WebOnErrorHook as d, type HookName as e, type OnRequestHook as f, type OnResponseHook as g, type PluginErrorContext as h, type PreHandlerHook as i, definePlugin as j };
61
+ export type { HookResult as H, OnErrorHook as O, PluginContext as P, RunHookOptions as R, TheoPlugin as T, WebOnRequestHook as W, TheoApp as a, WebPreHandlerHook as b, WebOnResponseHook as c, WebOnErrorHook as d, HookName as e, OnRequestHook as f, OnResponseHook as g, PluginErrorContext as h, PreHandlerHook as i };
@@ -6,7 +6,7 @@ var adapterRegistry = {
6
6
  node: async () => (await import("./node-BPJ3Z4DT.js")).nodeAdapter,
7
7
  vercel: async () => (await import("./vercel-J6G7ZHYQ.js")).vercelAdapter,
8
8
  cloudflare: async () => (await import("./cloudflare-C6E5SPAE.js")).cloudflareAdapter,
9
- static: async () => (await import("./static-CYG2WGYP.js")).staticAdapter,
9
+ static: async () => (await import("./static-MB2CD5Y3.js")).staticAdapter,
10
10
  bun: async () => (await import("./bun-KP2KES6S.js")).bunAdapter,
11
11
  "deno-deploy": async () => (await import("./deno-deploy-RFZN56X4.js")).denoDeployAdapter,
12
12
  netlify: async () => (await import("./netlify-PMLHVPN4.js")).netlifyAdapter,
@@ -21,4 +21,4 @@ export {
21
21
  adapterRegistry,
22
22
  resolveAdapter
23
23
  };
24
- //# sourceMappingURL=registry-XSRSTH33.js.map
24
+ //# sourceMappingURL=registry-3NB7KOUI.js.map
@@ -1,9 +1,9 @@
1
1
  import { z } from 'zod';
2
+ import { W as WebSocketHandler, b as WebSocketLike } from '../../define-websocket-CPQcQK9h.js';
3
+ export { a as WebSocketHandlerWeb } from '../../define-websocket-CPQcQK9h.js';
4
+ import { f as OnRequestHook, i as PreHandlerHook, g as OnResponseHook, O as OnErrorHook, T as TheoPlugin } from '../../plugin-types-L49QYMb5.js';
2
5
  import { UIMessageChunk } from 'ai';
3
- import { W as WebSocketHandler, b as WebSocketLike } from '../../define-websocket-CdK94O-D.js';
4
- export { a as WebSocketHandlerWeb, d as defineWebSocket, c as defineWebSocketWeb } from '../../define-websocket-CdK94O-D.js';
5
6
  import { IncomingMessage } from 'node:http';
6
- import { T as TheoPlugin, f as OnRequestHook, i as PreHandlerHook, g as OnResponseHook, O as OnErrorHook } from '../../plugin-types-DNJGxr4Z.js';
7
7
  export { H as HEALTH_PATH, a as HealthRouteConfig, b as READY_PATH, c as ReadyRouteConfig, d as ReservedResponse, R as ReservedRoutes, e as defineHealthRoute, f as defineReadyRoute, s as serveReservedRoute } from '../../health-route-C0hk64_U.js';
8
8
 
9
9
  /**
@@ -59,10 +59,126 @@ interface RouteConfig<TQuery extends z.ZodType = z.ZodUndefined, TBody extends z
59
59
  }
60
60
 
61
61
  /**
62
- * Define a typed HTTP route.
63
- * Identity function — provides type inference for route handlers.
62
+ * Action wire-protocol accept mode per plan g3-server-actions-and-useaction
63
+ * v1.2 ADR D1. Default behavior (when omitted) is `'json'`. `'form'` opts the
64
+ * action into FormData multipart parsing for progressive-enhancement forms;
65
+ * the runtime in `server/http/action-execute.ts` will coerce FormData entries
66
+ * against the `input` schema via `formDataToObject` (Astro pattern).
67
+ */
68
+ type ActionAccept = 'form' | 'json';
69
+ interface ActionConfig<TInput extends z.ZodType, TCtx = unknown> {
70
+ /**
71
+ * Zod input schema. Required: every action declares its input contract via
72
+ * Zod (architecture rule: zod-is-SSOT). The shape becomes the handler's
73
+ * typed `input` parameter via `z.infer<TInput>`.
74
+ */
75
+ input: TInput;
76
+ /**
77
+ * Wire-protocol accept mode. Defaults to `'json'` when omitted. Setting
78
+ * `'form'` switches the runtime to FormData multipart parsing — the input
79
+ * schema MUST be `z.object(...)` so field-by-field coercion can drive
80
+ * boolean string / number / array coercion (Astro pattern).
81
+ */
82
+ accept?: ActionAccept;
83
+ /**
84
+ * Opt OUT of CSRF enforcement for this action. Default (omitted) keeps the
85
+ * multi-header CSRF gate active. Set `false` for endpoints intentionally
86
+ * callable without the `X-Theo-Action` header (e.g. public webhooks). The
87
+ * runtime in `server/http/action-execute.ts` reads this flag.
88
+ */
89
+ csrf?: false;
90
+ handler: (ctx: {
91
+ input: z.infer<TInput>;
92
+ ctx: TCtx;
93
+ }) => unknown;
94
+ }
95
+
96
+ type MiddlewareHandler = (request: Request, next: (request: Request) => Promise<Response>) => Response | Promise<Response>;
97
+
98
+ /**
99
+ * Item #4 — `defineAgentTool`
100
+ *
101
+ * Sugar over the `@theokit/sdk` `CustomTool` contract. Takes a Zod schema +
102
+ * handler and produces a structurally-compatible `CustomTool` that
103
+ * `Agent.create({ tools: [...] })` accepts.
104
+ *
105
+ * Uses Zod v4's native `z.toJSONSchema()` to convert the input schema to
106
+ * JSON Schema for LLM providers.
107
+ *
108
+ * Handler error propagation:
109
+ * `defineAgentTool` parses the input via the Zod schema BEFORE calling the
110
+ * user handler. Invalid input throws a `ZodError`, which the SDK's tool-
111
+ * dispatcher treats as a tool failure and surfaces to the model as a tool
112
+ * error (the SDK owns the wire; ADR D3).
113
+ */
114
+ /**
115
+ * Local mirror of the SDK's `CustomTool` interface. We don't `import type`
116
+ * from `@theokit/sdk` because the SDK is an optional peer (consumers who
117
+ * never call `defineAgentTool` shouldn't need it installed). The shape is
118
+ * the wire contract; any structurally-matching object is accepted by
119
+ * `Agent.create({ tools })`.
120
+ *
121
+ * @public
122
+ */
123
+ interface CustomTool {
124
+ name: string;
125
+ description: string;
126
+ inputSchema: Record<string, unknown>;
127
+ handler: (input: Record<string, unknown>, ctx?: {
128
+ signal?: AbortSignal;
129
+ context?: unknown;
130
+ }) => string | Promise<string>;
131
+ /** M18 — optional per-target formatters for the app's UI/transcript (ignored by the SDK wire). */
132
+ transform?: ToolTransform;
133
+ }
134
+ /**
135
+ * M18 — per-target formatters. `display` shapes the rich handler result for the UI; `transcript`
136
+ * shapes it for a saved transcript. Applied by {@link applyTransform}, never by the model wire.
137
+ */
138
+ interface ToolTransform<R = unknown> {
139
+ display?: (result: R) => unknown;
140
+ transcript?: (result: R) => unknown;
141
+ }
142
+ /**
143
+ * Spec accepted by {@link defineAgentTool}. `inputSchema` is a Zod 3 schema
144
+ * rooted in `z.object(...)`. The `handler` argument type is inferred via
145
+ * `z.infer<T>`.
146
+ *
147
+ * @public
148
+ */
149
+ interface DefineAgentToolSpec<T extends z.ZodType, R = string> {
150
+ /** Tool name surfaced to the LLM. Must match `^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`. */
151
+ name: string;
152
+ /** Description surfaced to the LLM. Required — drives tool-selection accuracy. */
153
+ description: string;
154
+ /** Zod schema describing the input. Must be `z.object(...)` at the root. */
155
+ inputSchema: T;
156
+ /**
157
+ * Handler invoked with the parsed input and, optionally, the run `ctx` (M7). `ctx.context`
158
+ * is the object supplied once at the agent level (`defineAgent({ context })`) or per-run —
159
+ * read it for shared config like `projectRoot` instead of baking it into the factory.
160
+ * `ctx.signal` is the abort signal. Optional so existing one-arg handlers keep working.
161
+ *
162
+ * M18 — the handler may return RICH data `R` (not just a string) when `toModelOutput` is
163
+ * provided to map it to the model-visible string.
164
+ */
165
+ handler: (input: z.infer<T>, ctx?: {
166
+ signal?: AbortSignal;
167
+ context?: unknown;
168
+ }) => R | Promise<R>;
169
+ /**
170
+ * M18 — map the rich handler result `R` to the string the model sees. Required (in practice)
171
+ * when `handler` returns a non-string; absent ⇒ the handler must return a string.
172
+ */
173
+ toModelOutput?: (result: R) => string;
174
+ /** M18 — per-target formatters (`display` / `transcript`) for the app, applied by {@link applyTransform}. */
175
+ transform?: ToolTransform<R>;
176
+ }
177
+ /**
178
+ * M18 — apply a tool's `transform` for a target (`display` / `transcript`). Returns the formatted
179
+ * value, or the raw `result` when the tool declares no transform for that target.
64
180
  */
65
- declare function defineRoute<TQuery extends z.ZodType = z.ZodUndefined, TBody extends z.ZodType = z.ZodUndefined, TParams extends z.ZodType = z.ZodUndefined, TCtx = unknown, TResponse = unknown>(config: RouteConfig<TQuery, TBody, TParams, TCtx, TResponse>): RouteConfig<TQuery, TBody, TParams, TCtx, TResponse>;
181
+ declare function applyTransform(tool: CustomTool, result: unknown, target: 'display' | 'transcript'): unknown;
66
182
 
67
183
  /**
68
184
  * M31 Phase 3 — `route()`, the fluent builder that replaces `defineRoute({...})`.
@@ -123,54 +239,6 @@ interface RouteBuilder<TQuery extends z.ZodType = z.ZodUndefined, TBody extends
123
239
  */
124
240
  declare function route(): RouteBuilder;
125
241
 
126
- /**
127
- * Action wire-protocol accept mode per plan g3-server-actions-and-useaction
128
- * v1.2 ADR D1. Default behavior (when omitted) is `'json'`. `'form'` opts the
129
- * action into FormData multipart parsing for progressive-enhancement forms;
130
- * the runtime in `server/http/action-execute.ts` will coerce FormData entries
131
- * against the `input` schema via `formDataToObject` (Astro pattern).
132
- */
133
- type ActionAccept = 'form' | 'json';
134
- interface ActionConfig<TInput extends z.ZodType, TCtx = unknown> {
135
- /**
136
- * Zod input schema. Required: every action declares its input contract via
137
- * Zod (architecture rule: zod-is-SSOT). The shape becomes the handler's
138
- * typed `input` parameter via `z.infer<TInput>`.
139
- */
140
- input: TInput;
141
- /**
142
- * Wire-protocol accept mode. Defaults to `'json'` when omitted. Setting
143
- * `'form'` switches the runtime to FormData multipart parsing — the input
144
- * schema MUST be `z.object(...)` so field-by-field coercion can drive
145
- * boolean string / number / array coercion (Astro pattern).
146
- */
147
- accept?: ActionAccept;
148
- /**
149
- * Opt OUT of CSRF enforcement for this action. Default (omitted) keeps the
150
- * multi-header CSRF gate active. Set `false` for endpoints intentionally
151
- * callable without the `X-Theo-Action` header (e.g. public webhooks). The
152
- * runtime in `server/http/action-execute.ts` reads this flag.
153
- */
154
- csrf?: false;
155
- handler: (ctx: {
156
- input: z.infer<TInput>;
157
- ctx: TCtx;
158
- }) => unknown;
159
- }
160
- /**
161
- * Define a typed server action.
162
- *
163
- * Identity function — provides type inference for action handlers. The
164
- * runtime that consumes the config (validation + invocation + serialization)
165
- * lives in `server/http/action-execute.ts`.
166
- *
167
- * Per plan g3-server-actions-and-useaction v1.2 § Phase 1 / T1.2: the new
168
- * `accept?: 'form' | 'json'` field is the only contract change vs the
169
- * pre-G3 identity. Existing callsites (`defineAction({input, handler})`)
170
- * continue to compile — `accept` is opt-in.
171
- */
172
- declare function defineAction<TInput extends z.ZodType, TCtx = unknown>(config: ActionConfig<TInput, TCtx>): ActionConfig<TInput, TCtx>;
173
-
174
242
  /**
175
243
  * M31 Phase 3 — `action()`, the fluent builder that replaces `defineAction({...})`.
176
244
  *
@@ -227,12 +295,29 @@ interface ActionBuilder<TInput extends z.ZodType | UnsetMarker$1 = UnsetMarker$1
227
295
  */
228
296
  declare function action(): ActionBuilder;
229
297
 
230
- type MiddlewareHandler = (request: Request, next: (request: Request) => Promise<Response>) => Response | Promise<Response>;
231
298
  /**
232
- * Define a middleware handler.
233
- * Identity function — provides type annotation for middleware.
299
+ * M31 Phase 3 — `websocket()`, the fluent builder that replaces `defineWebSocket({...})`.
300
+ *
301
+ * Lifecycle setters (`onOpen/onMessage/onClose/onError`), all optional; `.build()` delegates to the
302
+ * internal {@link defineWebSocket} (identity) — the ws handler loading path is UNCHANGED.
303
+ *
304
+ * export default websocket()
305
+ * .onOpen((ws) => ws.send('hi'))
306
+ * .onMessage((ws, data) => ws.send(`echo:${data}`))
307
+ * .build()
234
308
  */
235
- declare function defineMiddleware(handler: MiddlewareHandler): MiddlewareHandler;
309
+
310
+ /** The fluent WebSocket builder. Each lifecycle hook is optional; `.build()` returns the handler. */
311
+ interface WebSocketBuilder {
312
+ onOpen(fn: NonNullable<WebSocketHandler['onOpen']>): WebSocketBuilder;
313
+ onMessage(fn: NonNullable<WebSocketHandler['onMessage']>): WebSocketBuilder;
314
+ onClose(fn: NonNullable<WebSocketHandler['onClose']>): WebSocketBuilder;
315
+ onError(fn: NonNullable<WebSocketHandler['onError']>): WebSocketBuilder;
316
+ /** Resolve to the `WebSocketHandler` — the SAME value `defineWebSocket({...})` returns. */
317
+ build(): WebSocketHandler;
318
+ }
319
+ /** Start a fluent WebSocket definition. Chain any of the lifecycle hooks, then `.build()`. */
320
+ declare function websocket(): WebSocketBuilder;
236
321
 
237
322
  /**
238
323
  * M31 Phase 3 — `middleware()`, the fluent builder that replaces `defineMiddleware(fn)`.
@@ -264,112 +349,6 @@ interface MiddlewareBuilder<THandleSet extends boolean = false> {
264
349
  /** Start a fluent middleware definition. Chain `.handle()` (required), then `.build()`. */
265
350
  declare function middleware(): MiddlewareBuilder;
266
351
 
267
- declare function uiMessageStreamResponse(chunks: AsyncIterable<UIMessageChunk>): Response;
268
-
269
- /**
270
- * Item #4 — `defineAgentTool`
271
- *
272
- * Sugar over the `@theokit/sdk` `CustomTool` contract. Takes a Zod schema +
273
- * handler and produces a structurally-compatible `CustomTool` that
274
- * `Agent.create({ tools: [...] })` accepts.
275
- *
276
- * Uses Zod v4's native `z.toJSONSchema()` to convert the input schema to
277
- * JSON Schema for LLM providers.
278
- *
279
- * Handler error propagation:
280
- * `defineAgentTool` parses the input via the Zod schema BEFORE calling the
281
- * user handler. Invalid input throws a `ZodError`, which the SDK's tool-
282
- * dispatcher treats as a tool failure and surfaces to the model as a tool
283
- * error (the SDK owns the wire; ADR D3).
284
- */
285
- /**
286
- * Local mirror of the SDK's `CustomTool` interface. We don't `import type`
287
- * from `@theokit/sdk` because the SDK is an optional peer (consumers who
288
- * never call `defineAgentTool` shouldn't need it installed). The shape is
289
- * the wire contract; any structurally-matching object is accepted by
290
- * `Agent.create({ tools })`.
291
- *
292
- * @public
293
- */
294
- interface CustomTool {
295
- name: string;
296
- description: string;
297
- inputSchema: Record<string, unknown>;
298
- handler: (input: Record<string, unknown>, ctx?: {
299
- signal?: AbortSignal;
300
- context?: unknown;
301
- }) => string | Promise<string>;
302
- /** M18 — optional per-target formatters for the app's UI/transcript (ignored by the SDK wire). */
303
- transform?: ToolTransform;
304
- }
305
- /**
306
- * M18 — per-target formatters. `display` shapes the rich handler result for the UI; `transcript`
307
- * shapes it for a saved transcript. Applied by {@link applyTransform}, never by the model wire.
308
- */
309
- interface ToolTransform<R = unknown> {
310
- display?: (result: R) => unknown;
311
- transcript?: (result: R) => unknown;
312
- }
313
- /**
314
- * Spec accepted by {@link defineAgentTool}. `inputSchema` is a Zod 3 schema
315
- * rooted in `z.object(...)`. The `handler` argument type is inferred via
316
- * `z.infer<T>`.
317
- *
318
- * @public
319
- */
320
- interface DefineAgentToolSpec<T extends z.ZodType, R = string> {
321
- /** Tool name surfaced to the LLM. Must match `^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`. */
322
- name: string;
323
- /** Description surfaced to the LLM. Required — drives tool-selection accuracy. */
324
- description: string;
325
- /** Zod schema describing the input. Must be `z.object(...)` at the root. */
326
- inputSchema: T;
327
- /**
328
- * Handler invoked with the parsed input and, optionally, the run `ctx` (M7). `ctx.context`
329
- * is the object supplied once at the agent level (`defineAgent({ context })`) or per-run —
330
- * read it for shared config like `projectRoot` instead of baking it into the factory.
331
- * `ctx.signal` is the abort signal. Optional so existing one-arg handlers keep working.
332
- *
333
- * M18 — the handler may return RICH data `R` (not just a string) when `toModelOutput` is
334
- * provided to map it to the model-visible string.
335
- */
336
- handler: (input: z.infer<T>, ctx?: {
337
- signal?: AbortSignal;
338
- context?: unknown;
339
- }) => R | Promise<R>;
340
- /**
341
- * M18 — map the rich handler result `R` to the string the model sees. Required (in practice)
342
- * when `handler` returns a non-string; absent ⇒ the handler must return a string.
343
- */
344
- toModelOutput?: (result: R) => string;
345
- /** M18 — per-target formatters (`display` / `transcript`) for the app, applied by {@link applyTransform}. */
346
- transform?: ToolTransform<R>;
347
- }
348
- /**
349
- * Build a {@link CustomTool} from a Zod 3 schema + handler.
350
- *
351
- * Behavior:
352
- * - Validates `name` matches the LLM tool-name regex.
353
- * - Requires `inputSchema` to be a `ZodObject` (Anthropic + SDK contract).
354
- * - Warns (not throws) if `description` is empty — empty descriptions
355
- * degrade LLM tool selection.
356
- * - Converts the Zod schema to JSON Schema 7 inline (no `$ref`s — LLMs handle
357
- * inline schemas more reliably).
358
- * - Strips the top-level `$schema` field (Anthropic rejects schemas with
359
- * `$schema` at root in some provider modes).
360
- * - Wraps the handler to parse the input via the Zod schema BEFORE invoking
361
- * the user code — bad LLM-supplied input throws `ZodError`, which the SDK
362
- * converts to `tool_result(isError)`.
363
- *
364
- * @public
365
- */
366
- declare function defineAgentTool<T extends z.ZodType, R = string>(spec: DefineAgentToolSpec<T, R>): CustomTool;
367
- /**
368
- * M18 — apply a tool's `transform` for a target (`display` / `transcript`). Returns the formatted
369
- * value, or the raw `result` when the tool declares no transform for that target.
370
- */
371
- declare function applyTransform(tool: CustomTool, result: unknown, target: 'display' | 'transcript'): unknown;
372
-
373
352
  /**
374
353
  * M31 Phase 1 — `tool()`, the fluent builder that replaces `defineAgentTool({...})`.
375
354
  *
@@ -436,28 +415,37 @@ interface ToolBuilder<TName extends string = string, TInput extends z.ZodType |
436
415
  declare function tool<TName extends string>(name: TName): ToolBuilder<TName>;
437
416
 
438
417
  /**
439
- * M31 Phase 3 — `websocket()`, the fluent builder that replaces `defineWebSocket({...})`.
418
+ * M31 Phase 3 — `plugin()`, the fluent builder that replaces `definePlugin({...})`.
440
419
  *
441
- * Lifecycle setters (`onOpen/onMessage/onClose/onError`), all optional; `.build()` delegates to the
442
- * internal {@link defineWebSocket} (identity) — the ws handler loading path is UNCHANGED.
420
+ * Collects lifecycle hooks + request decorations and SYNTHESIZES the `register(app)` function, so
421
+ * authors never write the imperative `register` body. `.build()` returns a `TheoPlugin` the plugin
422
+ * runner consumes UNCHANGED.
443
423
  *
444
- * export default websocket()
445
- * .onOpen((ws) => ws.send('hi'))
446
- * .onMessage((ws, data) => ws.send(`echo:${data}`))
424
+ * export default plugin('request-id')
425
+ * .onRequest((ctx) => { ctx.ctx.requestId = crypto.randomUUID() })
426
+ * .onResponse((ctx) => { ctx.response.setHeader('x-request-id', String(ctx.ctx.requestId)) })
447
427
  * .build()
448
428
  */
449
429
 
450
- /** The fluent WebSocket builder. Each lifecycle hook is optional; `.build()` returns the handler. */
451
- interface WebSocketBuilder {
452
- onOpen(fn: NonNullable<WebSocketHandler['onOpen']>): WebSocketBuilder;
453
- onMessage(fn: NonNullable<WebSocketHandler['onMessage']>): WebSocketBuilder;
454
- onClose(fn: NonNullable<WebSocketHandler['onClose']>): WebSocketBuilder;
455
- onError(fn: NonNullable<WebSocketHandler['onError']>): WebSocketBuilder;
456
- /** Resolve to the `WebSocketHandler` — the SAME value `defineWebSocket({...})` returns. */
457
- build(): WebSocketHandler;
430
+ /** The fluent plugin builder. `name` is set at entry; every hook is optional and may repeat. */
431
+ interface PluginBuilder {
432
+ /** Register an `onRequest` hook (runs before the CSRF gate). May be called multiple times. */
433
+ onRequest(fn: OnRequestHook): PluginBuilder;
434
+ /** Register a `preHandler` hook (after CSRF, before the route handler). */
435
+ preHandler(fn: PreHandlerHook): PluginBuilder;
436
+ /** Register an `onResponse` hook (after the handler returns). */
437
+ onResponse(fn: OnResponseHook): PluginBuilder;
438
+ /** Register an `onError` hook (error path). */
439
+ onError(fn: OnErrorHook): PluginBuilder;
440
+ /** Decorate every request with a key/value pair (available on `ctx.ctx[key]`). */
441
+ decorateRequest<T>(key: string, value: T): PluginBuilder;
442
+ /** Resolve to the `TheoPlugin` — a synthesized `{ name, register }` the runner consumes. */
443
+ build(): TheoPlugin;
458
444
  }
459
- /** Start a fluent WebSocket definition. Chain any of the lifecycle hooks, then `.build()`. */
460
- declare function websocket(): WebSocketBuilder;
445
+ /** Start a fluent plugin definition. `name` is required; chain hooks/decorations, then `.build()`. */
446
+ declare function plugin(name: string): PluginBuilder;
447
+
448
+ declare function uiMessageStreamResponse(chunks: AsyncIterable<UIMessageChunk>): Response;
461
449
 
462
450
  interface ChannelHandler<TMessage = unknown> {
463
451
  onSubscribe?: (ws: WebSocketLike, room: string, req: IncomingMessage) => void;
@@ -504,44 +492,4 @@ interface WebChannelHandler<TMessage = unknown> {
504
492
  */
505
493
  declare function defineWebChannel<TMessage = unknown>(handler: WebChannelHandler<TMessage>): WebChannelHandler<TMessage>;
506
494
 
507
- /**
508
- * Identity function for defining a Theo plugin.
509
- *
510
- * **Note:** Prefer `definePlugin` (shorter, canonical name per ADR-0008 D6).
511
- * Both functions are identical — `defineTheoPlugin` is kept as an alias for
512
- * existing in-tree consumers without forcing a migration sweep.
513
- */
514
- declare function defineTheoPlugin(plugin: TheoPlugin): TheoPlugin;
515
-
516
- /**
517
- * M31 Phase 3 — `plugin()`, the fluent builder that replaces `definePlugin({...})`.
518
- *
519
- * Collects lifecycle hooks + request decorations and SYNTHESIZES the `register(app)` function, so
520
- * authors never write the imperative `register` body. `.build()` returns a `TheoPlugin` the plugin
521
- * runner consumes UNCHANGED.
522
- *
523
- * export default plugin('request-id')
524
- * .onRequest((ctx) => { ctx.ctx.requestId = crypto.randomUUID() })
525
- * .onResponse((ctx) => { ctx.response.setHeader('x-request-id', String(ctx.ctx.requestId)) })
526
- * .build()
527
- */
528
-
529
- /** The fluent plugin builder. `name` is set at entry; every hook is optional and may repeat. */
530
- interface PluginBuilder {
531
- /** Register an `onRequest` hook (runs before the CSRF gate). May be called multiple times. */
532
- onRequest(fn: OnRequestHook): PluginBuilder;
533
- /** Register a `preHandler` hook (after CSRF, before the route handler). */
534
- preHandler(fn: PreHandlerHook): PluginBuilder;
535
- /** Register an `onResponse` hook (after the handler returns). */
536
- onResponse(fn: OnResponseHook): PluginBuilder;
537
- /** Register an `onError` hook (error path). */
538
- onError(fn: OnErrorHook): PluginBuilder;
539
- /** Decorate every request with a key/value pair (available on `ctx.ctx[key]`). */
540
- decorateRequest<T>(key: string, value: T): PluginBuilder;
541
- /** Resolve to the `TheoPlugin` — a synthesized `{ name, register }` the runner consumes. */
542
- build(): TheoPlugin;
543
- }
544
- /** Start a fluent plugin definition. `name` is required; chain hooks/decorations, then `.build()`. */
545
- declare function plugin(name: string): PluginBuilder;
546
-
547
- export { type ActionAccept, type ActionBuilder, type ActionConfig, type ChannelHandler, type CustomTool, type DefineAgentToolSpec, type MiddlewareBuilder, type MiddlewareHandler, type PluginBuilder, type RouteBuilder, type RouteConfig, type ToolBuilder, type ToolTransform, type WebChannelHandler, type WebSocketBuilder, WebSocketHandler, WebSocketLike, action, applyTransform, defineAction, defineAgentTool, defineChannel, defineMiddleware, defineRoute, defineTheoPlugin, defineWebChannel, middleware, plugin, route, tool, uiMessageStreamResponse, websocket };
495
+ export { type ActionAccept, type ActionBuilder, type ActionConfig, type ChannelHandler, type CustomTool, type DefineAgentToolSpec, type MiddlewareBuilder, type MiddlewareHandler, type PluginBuilder, type RouteBuilder, type RouteConfig, type ToolBuilder, type ToolTransform, type WebChannelHandler, type WebSocketBuilder, WebSocketHandler, WebSocketLike, action, applyTransform, defineChannel, defineWebChannel, middleware, plugin, route, tool, uiMessageStreamResponse, websocket };
@@ -1,21 +1,14 @@
1
1
  import {
2
2
  action,
3
3
  applyTransform,
4
- defineAction,
5
- defineAgentTool,
6
4
  defineChannel,
7
- defineMiddleware,
8
- defineRoute,
9
- defineTheoPlugin,
10
5
  defineWebChannel,
11
- defineWebSocket,
12
- defineWebSocketWeb,
13
6
  middleware,
14
7
  plugin,
15
8
  route,
16
9
  tool,
17
10
  websocket
18
- } from "../../chunk-WLKFWVOM.js";
11
+ } from "../../chunk-5PY3QPVM.js";
19
12
  import {
20
13
  uiMessageStreamResponse
21
14
  } from "../../chunk-JZHT3LW7.js";
@@ -32,17 +25,10 @@ export {
32
25
  READY_PATH,
33
26
  action,
34
27
  applyTransform,
35
- defineAction,
36
- defineAgentTool,
37
28
  defineChannel,
38
29
  defineHealthRoute,
39
- defineMiddleware,
40
30
  defineReadyRoute,
41
- defineRoute,
42
- defineTheoPlugin,
43
31
  defineWebChannel,
44
- defineWebSocket,
45
- defineWebSocketWeb,
46
32
  middleware,
47
33
  plugin,
48
34
  route,
@@ -1,8 +1,8 @@
1
- export { B as BATCH_PATH, a as BatchExecuteFn, b as BatchPathConflictError, c as BatchPayload, d as BatchRequestItem, e as BatchResponse, f as BatchResultItem, C as CookieOptions, g as CorsConfig, h as CorsHandler, i as CorsOrigin, j as CorsWebHandler, k as CustomErrorPages, E as ExecuteActionOptions, l as ExecuteRouteContext, H as HandleBatchOptions, M as MAX_ERROR_HTML_BYTES, m as MiddlewareResult, N as NotFoundError, S as STRIPPED_HEADERS, n as SendErrorInput, o as SendErrorOptions, T as TRACE_HEADER, p as TRACE_PARENT_HEADER, q as TheoError, _ as _resetMiddlewareCacheForTests, s as appendCookieToHeaders, t as appendDeleteCookieToHeaders, u as createCorsHandler, v as createCorsWebHandler, w as deleteCookie, x as envelopeCodeToStatus, y as executeAction, z as executeRoute, A as extractTraceId, D as extractTraceIdFromRequest, F as fromUnknown, G as getCookie, I as getCookieFromRequest, J as handleBatchRequest, K as handleRequestError, L as handleWebRequestError, P as loadCustomErrorPages, Q as matchesOrigin, R as parseCookieHeader, U as parseTraceparent, W as runMiddlewareAndContext, X as sendError, Y as sendJson, Z as serializeCookie, $ as serveStaticFile, a0 as serverErrorToEnvelope, a1 as setCookie } from '../../index-B40qUSrQ.js';
1
+ export { B as BATCH_PATH, a as BatchExecuteFn, b as BatchPathConflictError, c as BatchPayload, d as BatchRequestItem, e as BatchResponse, f as BatchResultItem, C as CookieOptions, g as CorsConfig, h as CorsHandler, i as CorsOrigin, j as CorsWebHandler, k as CustomErrorPages, E as ExecuteActionOptions, l as ExecuteRouteContext, H as HandleBatchOptions, M as MAX_ERROR_HTML_BYTES, m as MiddlewareResult, N as NotFoundError, S as STRIPPED_HEADERS, n as SendErrorInput, o as SendErrorOptions, T as TRACE_HEADER, p as TRACE_PARENT_HEADER, q as TheoError, _ as _resetMiddlewareCacheForTests, s as appendCookieToHeaders, t as appendDeleteCookieToHeaders, u as createCorsHandler, v as createCorsWebHandler, w as deleteCookie, x as envelopeCodeToStatus, y as executeAction, z as executeRoute, A as extractTraceId, D as extractTraceIdFromRequest, F as fromUnknown, G as getCookie, I as getCookieFromRequest, J as handleBatchRequest, K as handleRequestError, L as handleWebRequestError, P as loadCustomErrorPages, Q as matchesOrigin, R as parseCookieHeader, U as parseTraceparent, W as runMiddlewareAndContext, X as sendError, Y as sendJson, Z as serializeCookie, $ as serveStaticFile, a0 as serverErrorToEnvelope, a1 as setCookie } from '../../index-C3ged4mn.js';
2
2
  import '../../error-envelope-BsNzzAV5.js';
3
3
  import 'node:http';
4
- import '../../plugin-types-DNJGxr4Z.js';
5
- import '../../plugin-runner-BGBkzgi0.js';
4
+ import '../../plugin-types-L49QYMb5.js';
5
+ import '../../plugin-runner-CMprWWHZ.js';
6
6
  import '../../job-backend-CgC8Xf33.js';
7
7
  import '../../match-CfbEFRG4.js';
8
8
  import 'vite';