theokit 0.13.0 → 0.14.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.
- package/dist/{actions-virtual-module-EIPXX4ZB.js → actions-virtual-module-RM7JRY5N.js} +7 -7
- package/dist/{app-typed-client-7PBFWZUE.js → app-typed-client-5VQE6DNF.js} +7 -7
- package/dist/boot/index.js +3 -3
- package/dist/{build-HXND27XG.js → build-5K7LK77K.js} +2 -2
- package/dist/{chunk-3S3BNW5K.js → chunk-5UUOGAJH.js} +2 -2
- package/dist/{chunk-O62MW4MT.js → chunk-637WJB7Z.js} +2 -2
- package/dist/{chunk-TGTNRUH3.js → chunk-H243MR3F.js} +2 -2
- package/dist/{chunk-NHJMZCAS.js → chunk-JZHT3LW7.js} +1 -1
- package/dist/chunk-JZHT3LW7.js.map +1 -0
- package/dist/chunk-KGFNWIMS.js +94 -0
- package/dist/chunk-KGFNWIMS.js.map +1 -0
- package/dist/{chunk-RYTZYFSD.js → chunk-RBHCJHRR.js} +65 -28
- package/dist/chunk-RBHCJHRR.js.map +1 -0
- package/dist/{chunk-UNLA45FY.js → chunk-S7Y5WLZY.js} +1 -1
- package/dist/chunk-S7Y5WLZY.js.map +1 -0
- package/dist/{chunk-WFNLNIJX.js → chunk-Z5IGLBWE.js} +1 -1
- package/dist/cli/index.js +3 -3
- package/dist/client/index.d.ts +3 -152
- package/dist/client/index.js +13 -236
- package/dist/client/index.js.map +1 -1
- package/dist/{dev-OWW4XVIH.js → dev-QOEVYNBG.js} +3 -3
- package/dist/index.js +12 -13
- package/dist/index.js.map +1 -1
- package/dist/{internal-api-4YTJDITC.js → internal-api-5BDI6N5U.js} +20 -20
- package/dist/server/auth/index.js +1 -1
- package/dist/server/define/index.d.ts +3 -70
- package/dist/server/define/index.js +2 -4
- package/dist/server/http/index.js +2 -2
- package/dist/server/index.d.ts +1 -3
- package/dist/server/index.js +90 -105
- package/dist/server/index.js.map +1 -1
- package/dist/server/jobs/index.js +4 -4
- package/dist/server/observability/index.js +1 -1
- package/dist/server/scan/index.js +1 -1
- package/dist/{start-KIQ5TTLR.js → start-2KG4JSXM.js} +2 -2
- package/dist/vite-plugin/index.js +12 -13
- package/dist/{vite-plugin-RK66K26Z.js → vite-plugin-TDIDZ5U7.js} +3 -3
- package/package.json +1 -5
- package/dist/agent-events-DosDXkSV.d.ts +0 -94
- package/dist/chunk-2KZQPDYR.js +0 -226
- package/dist/chunk-2KZQPDYR.js.map +0 -1
- package/dist/chunk-EXP56GFQ.js +0 -52
- package/dist/chunk-EXP56GFQ.js.map +0 -1
- package/dist/chunk-NHJMZCAS.js.map +0 -1
- package/dist/chunk-RYTZYFSD.js.map +0 -1
- package/dist/chunk-UNLA45FY.js.map +0 -1
- package/dist/chunk-ZSTZXR2D.js +0 -208
- package/dist/chunk-ZSTZXR2D.js.map +0 -1
- package/dist/server/agent/index.d.ts +0 -229
- package/dist/server/agent/index.js +0 -17
- package/dist/vite-plugin-RK66K26Z.js.map +0 -1
- /package/dist/{actions-virtual-module-EIPXX4ZB.js.map → actions-virtual-module-RM7JRY5N.js.map} +0 -0
- /package/dist/{app-typed-client-7PBFWZUE.js.map → app-typed-client-5VQE6DNF.js.map} +0 -0
- /package/dist/{build-HXND27XG.js.map → build-5K7LK77K.js.map} +0 -0
- /package/dist/{chunk-3S3BNW5K.js.map → chunk-5UUOGAJH.js.map} +0 -0
- /package/dist/{chunk-O62MW4MT.js.map → chunk-637WJB7Z.js.map} +0 -0
- /package/dist/{chunk-TGTNRUH3.js.map → chunk-H243MR3F.js.map} +0 -0
- /package/dist/{chunk-WFNLNIJX.js.map → chunk-Z5IGLBWE.js.map} +0 -0
- /package/dist/{dev-OWW4XVIH.js.map → dev-QOEVYNBG.js.map} +0 -0
- /package/dist/{internal-api-4YTJDITC.js.map → internal-api-5BDI6N5U.js.map} +0 -0
- /package/dist/{start-KIQ5TTLR.js.map → start-2KG4JSXM.js.map} +0 -0
- /package/dist/{server/agent/index.js.map → vite-plugin-TDIDZ5U7.js.map} +0 -0
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import "./chunk-RSVN727G.js";
|
|
2
|
-
import "./chunk-TGTNRUH3.js";
|
|
3
|
-
import "./chunk-GY5Q27BJ.js";
|
|
4
2
|
import "./chunk-5QW7IQQU.js";
|
|
5
|
-
import "./chunk-WFNLNIJX.js";
|
|
6
3
|
import "./chunk-IAJ2JVEH.js";
|
|
7
4
|
import "./chunk-VMEWD57H.js";
|
|
8
5
|
import "./chunk-JQSKBMXP.js";
|
|
@@ -10,14 +7,17 @@ import {
|
|
|
10
7
|
scanServerActionsEnriched
|
|
11
8
|
} from "./chunk-2J7XU3PW.js";
|
|
12
9
|
import "./chunk-WSJKACWB.js";
|
|
13
|
-
import "./chunk-ZEGYW52B.js";
|
|
14
10
|
import "./chunk-JBCHWRKF.js";
|
|
11
|
+
import "./chunk-C3ZZ56YZ.js";
|
|
12
|
+
import "./chunk-X2VVCJ4V.js";
|
|
13
|
+
import "./chunk-H243MR3F.js";
|
|
14
|
+
import "./chunk-GY5Q27BJ.js";
|
|
15
|
+
import "./chunk-Z5IGLBWE.js";
|
|
16
|
+
import "./chunk-ZEGYW52B.js";
|
|
15
17
|
import "./chunk-TSLSIRBR.js";
|
|
16
18
|
import "./chunk-UD3LFGDL.js";
|
|
17
19
|
import "./chunk-X32XEJXR.js";
|
|
18
20
|
import "./chunk-UVXB2ER7.js";
|
|
19
|
-
import "./chunk-C3ZZ56YZ.js";
|
|
20
|
-
import "./chunk-X2VVCJ4V.js";
|
|
21
21
|
import "./chunk-DGUM43GV.js";
|
|
22
22
|
|
|
23
23
|
// src/vite-plugin/actions-virtual-module.ts
|
|
@@ -221,4 +221,4 @@ export const actions = manifest
|
|
|
221
221
|
export {
|
|
222
222
|
actionsVirtualModule
|
|
223
223
|
};
|
|
224
|
-
//# sourceMappingURL=actions-virtual-module-
|
|
224
|
+
//# sourceMappingURL=actions-virtual-module-RM7JRY5N.js.map
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import "./chunk-RSVN727G.js";
|
|
2
|
-
import "./chunk-TGTNRUH3.js";
|
|
3
|
-
import "./chunk-GY5Q27BJ.js";
|
|
4
2
|
import "./chunk-5QW7IQQU.js";
|
|
5
|
-
import "./chunk-WFNLNIJX.js";
|
|
6
3
|
import "./chunk-IAJ2JVEH.js";
|
|
7
4
|
import "./chunk-VMEWD57H.js";
|
|
8
5
|
import "./chunk-JQSKBMXP.js";
|
|
@@ -12,14 +9,17 @@ import {
|
|
|
12
9
|
import {
|
|
13
10
|
HTTP_METHODS
|
|
14
11
|
} from "./chunk-WSJKACWB.js";
|
|
15
|
-
import "./chunk-ZEGYW52B.js";
|
|
16
12
|
import "./chunk-JBCHWRKF.js";
|
|
13
|
+
import "./chunk-C3ZZ56YZ.js";
|
|
14
|
+
import "./chunk-X2VVCJ4V.js";
|
|
15
|
+
import "./chunk-H243MR3F.js";
|
|
16
|
+
import "./chunk-GY5Q27BJ.js";
|
|
17
|
+
import "./chunk-Z5IGLBWE.js";
|
|
18
|
+
import "./chunk-ZEGYW52B.js";
|
|
17
19
|
import "./chunk-TSLSIRBR.js";
|
|
18
20
|
import "./chunk-UD3LFGDL.js";
|
|
19
21
|
import "./chunk-X32XEJXR.js";
|
|
20
22
|
import "./chunk-UVXB2ER7.js";
|
|
21
|
-
import "./chunk-C3ZZ56YZ.js";
|
|
22
|
-
import "./chunk-X2VVCJ4V.js";
|
|
23
23
|
import "./chunk-DGUM43GV.js";
|
|
24
24
|
|
|
25
25
|
// src/vite-plugin/app-typed-client.ts
|
|
@@ -296,4 +296,4 @@ export {
|
|
|
296
296
|
emitClientDts,
|
|
297
297
|
generateClientDts
|
|
298
298
|
};
|
|
299
|
-
//# sourceMappingURL=app-typed-client-
|
|
299
|
+
//# sourceMappingURL=app-typed-client-5VQE6DNF.js.map
|
package/dist/boot/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
serveReservedRoute
|
|
3
|
+
} from "../chunk-V3LJN2GS.js";
|
|
1
4
|
import {
|
|
2
5
|
envelopeCodeToStatus
|
|
3
6
|
} from "../chunk-X32XEJXR.js";
|
|
@@ -5,9 +8,6 @@ import {
|
|
|
5
8
|
NotFoundError,
|
|
6
9
|
serverErrorToEnvelope
|
|
7
10
|
} from "../chunk-UVXB2ER7.js";
|
|
8
|
-
import {
|
|
9
|
-
serveReservedRoute
|
|
10
|
-
} from "../chunk-V3LJN2GS.js";
|
|
11
11
|
import "../chunk-DGUM43GV.js";
|
|
12
12
|
|
|
13
13
|
// src/server/boot.ts
|
|
@@ -527,7 +527,7 @@ async function buildCommand(options) {
|
|
|
527
527
|
`);
|
|
528
528
|
}
|
|
529
529
|
async function runAdapterBuild(target, config, cwd) {
|
|
530
|
-
const { theoPluginAsync } = await import("./vite-plugin-
|
|
530
|
+
const { theoPluginAsync } = await import("./vite-plugin-TDIDZ5U7.js");
|
|
531
531
|
const { default: react } = await import("@vitejs/plugin-react");
|
|
532
532
|
const ctx = {
|
|
533
533
|
// `react()` may return Plugin or Plugin[] depending on version; spread the
|
|
@@ -602,4 +602,4 @@ function relativize3(absPath, root) {
|
|
|
602
602
|
export {
|
|
603
603
|
buildCommand
|
|
604
604
|
};
|
|
605
|
-
//# sourceMappingURL=build-
|
|
605
|
+
//# sourceMappingURL=build-5K7LK77K.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isZodLike
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-H243MR3F.js";
|
|
4
4
|
import {
|
|
5
5
|
validateCsrfRequest
|
|
6
6
|
} from "./chunk-TSLSIRBR.js";
|
|
@@ -442,4 +442,4 @@ export {
|
|
|
442
442
|
resolveTransformer,
|
|
443
443
|
executeWebRequest
|
|
444
444
|
};
|
|
445
|
-
//# sourceMappingURL=chunk-
|
|
445
|
+
//# sourceMappingURL=chunk-5UUOGAJH.js.map
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
resolveProvider,
|
|
7
7
|
resolveTransformer,
|
|
8
8
|
writeWebResponseToServerResponse
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-S7Y5WLZY.js";
|
|
10
10
|
import {
|
|
11
11
|
loadConfig
|
|
12
12
|
} from "./chunk-7YZHAQU7.js";
|
|
@@ -1983,4 +1983,4 @@ export {
|
|
|
1983
1983
|
theoPluginAsync,
|
|
1984
1984
|
theoPlugin
|
|
1985
1985
|
};
|
|
1986
|
-
//# sourceMappingURL=chunk-
|
|
1986
|
+
//# sourceMappingURL=chunk-637WJB7Z.js.map
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
import {
|
|
8
8
|
parseRequestBody,
|
|
9
9
|
warnOnce
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-Z5IGLBWE.js";
|
|
11
11
|
import {
|
|
12
12
|
scanMiddlewares
|
|
13
13
|
} from "./chunk-ZEGYW52B.js";
|
|
@@ -1393,4 +1393,4 @@ export {
|
|
|
1393
1393
|
extractTraceId,
|
|
1394
1394
|
extractTraceIdFromRequest
|
|
1395
1395
|
};
|
|
1396
|
-
//# sourceMappingURL=chunk-
|
|
1396
|
+
//# sourceMappingURL=chunk-H243MR3F.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server/define/ui-message-stream-response.ts"],"sourcesContent":["import type { UIMessageChunk } from 'ai'\n\n/**\n * M0 (theokit-ai-first) — serialize a stream of ai-sdk `UIMessageChunk`s into a\n * Web-Standards `Response` on the UIMessageStream wire so `@ai-sdk/react`'s\n * `useChat` consumes it WITHOUT a custom adapter.\n *\n * Wire contract (must match ai-sdk's consumer transport exactly):\n * - `content-type: text/event-stream`\n * - `x-vercel-ai-ui-message-stream: v1` — the version marker `useChat` checks\n * - each chunk framed as `data: ${JSON.stringify(chunk)}\\n\\n`\n * - a terminal `data: [DONE]\\n\\n` after the last chunk (ignored by the parser)\n *\n * Web Standards only — `Response` + `ReadableStream` (G8, no node:http). The\n * headers commit before the stream starts.\n *\n * Fail-clear (error-handling.md): if the source iterable throws mid-stream, the\n * `[DONE]` terminal is still flushed and the stream is closed — never left\n * hanging. (The translator upstream already closes gracefully; this is defense\n * in depth for any other chunk source.)\n */\nconst UI_MESSAGE_STREAM_HEADERS = {\n 'content-type': 'text/event-stream',\n 'x-vercel-ai-ui-message-stream': 'v1',\n} as const\n\nconst DONE_FRAME = 'data: [DONE]\\n\\n'\n\nfunction encode(text: string): Uint8Array {\n return new TextEncoder().encode(text)\n}\n\nexport function uiMessageStreamResponse(chunks: AsyncIterable<UIMessageChunk>): Response {\n const stream = new ReadableStream<Uint8Array>({\n async start(controller) {\n try {\n for await (const chunk of chunks) {\n controller.enqueue(encode(`data: ${JSON.stringify(chunk)}\\n\\n`))\n }\n } catch {\n // The source iterable aborted mid-stream. The upstream translator owns\n // error semantics (it surfaces failures as chunks + closes gracefully);\n // this transport's sole guarantee is a terminated stream — fall through\n // to the DONE terminal rather than re-throw and error an open stream.\n } finally {\n controller.enqueue(encode(DONE_FRAME))\n controller.close()\n }\n },\n })\n return new Response(stream, { headers: UI_MESSAGE_STREAM_HEADERS })\n}\n"],"mappings":";AAqBA,IAAM,4BAA4B;AAAA,EAChC,gBAAgB;AAAA,EAChB,iCAAiC;AACnC;AAEA,IAAM,aAAa;AAEnB,SAAS,OAAO,MAA0B;AACxC,SAAO,IAAI,YAAY,EAAE,OAAO,IAAI;AACtC;AAEO,SAAS,wBAAwB,QAAiD;AACvF,QAAM,SAAS,IAAI,eAA2B;AAAA,IAC5C,MAAM,MAAM,YAAY;AACtB,UAAI;AACF,yBAAiB,SAAS,QAAQ;AAChC,qBAAW,QAAQ,OAAO,SAAS,KAAK,UAAU,KAAK,CAAC;AAAA;AAAA,CAAM,CAAC;AAAA,QACjE;AAAA,MACF,QAAQ;AAAA,MAKR,UAAE;AACA,mBAAW,QAAQ,OAAO,UAAU,CAAC;AACrC,mBAAW,MAAM;AAAA,MACnB;AAAA,IACF;AAAA,EACF,CAAC;AACD,SAAO,IAAI,SAAS,QAAQ,EAAE,SAAS,0BAA0B,CAAC;AACpE;","names":[]}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// src/server/define/define-route.ts
|
|
2
|
+
function defineRoute(config) {
|
|
3
|
+
return config;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
// src/server/define/define-action.ts
|
|
7
|
+
function defineAction(config) {
|
|
8
|
+
return config;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// src/server/define/define-middleware.ts
|
|
12
|
+
function defineMiddleware(handler) {
|
|
13
|
+
return handler;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// src/server/define/define-agent-tool.ts
|
|
17
|
+
import { z } from "zod";
|
|
18
|
+
var TOOL_NAME_REGEX = /^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/;
|
|
19
|
+
function isZodObject(schema) {
|
|
20
|
+
let current = schema;
|
|
21
|
+
for (let depth = 0; depth < 10; depth++) {
|
|
22
|
+
if (current instanceof z.ZodObject) return true;
|
|
23
|
+
const z4 = current.def;
|
|
24
|
+
if (z4?.type === "object") return true;
|
|
25
|
+
const z3 = current._def;
|
|
26
|
+
if (z3?.typeName === "ZodObject") return true;
|
|
27
|
+
const next = z4?.innerType ?? z4?.in ?? z3?.schema ?? z3?.innerType;
|
|
28
|
+
if (next !== void 0) {
|
|
29
|
+
current = next;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
function defineAgentTool(spec) {
|
|
37
|
+
if (!TOOL_NAME_REGEX.test(spec.name)) {
|
|
38
|
+
throw new Error(
|
|
39
|
+
`defineAgentTool: name must match ${TOOL_NAME_REGEX.source}. Got: ${JSON.stringify(spec.name)}`
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
if (!isZodObject(spec.inputSchema)) {
|
|
43
|
+
throw new Error("defineAgentTool: inputSchema must be a ZodObject (z.object({...}))");
|
|
44
|
+
}
|
|
45
|
+
if (spec.description.length === 0) {
|
|
46
|
+
console.warn(
|
|
47
|
+
`defineAgentTool(${JSON.stringify(spec.name)}): empty description degrades LLM tool selection \u2014 provide a one-sentence summary.`
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
const { $schema: _$schema, ...inputSchema } = z.toJSONSchema(spec.inputSchema);
|
|
51
|
+
return {
|
|
52
|
+
name: spec.name,
|
|
53
|
+
description: spec.description,
|
|
54
|
+
inputSchema,
|
|
55
|
+
handler: async (input) => {
|
|
56
|
+
const parsed = spec.inputSchema.parse(input);
|
|
57
|
+
return await spec.handler(parsed);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/server/define/define-websocket.ts
|
|
63
|
+
function defineWebSocket(handler) {
|
|
64
|
+
return handler;
|
|
65
|
+
}
|
|
66
|
+
function defineWebSocketWeb(handler) {
|
|
67
|
+
return handler;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// src/server/define/define-channel.ts
|
|
71
|
+
function defineChannel(handler) {
|
|
72
|
+
return handler;
|
|
73
|
+
}
|
|
74
|
+
function defineWebChannel(handler) {
|
|
75
|
+
return handler;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// src/server/define/define-plugin.ts
|
|
79
|
+
function defineTheoPlugin(plugin) {
|
|
80
|
+
return plugin;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export {
|
|
84
|
+
defineRoute,
|
|
85
|
+
defineAction,
|
|
86
|
+
defineMiddleware,
|
|
87
|
+
defineAgentTool,
|
|
88
|
+
defineWebSocket,
|
|
89
|
+
defineWebSocketWeb,
|
|
90
|
+
defineChannel,
|
|
91
|
+
defineWebChannel,
|
|
92
|
+
defineTheoPlugin
|
|
93
|
+
};
|
|
94
|
+
//# sourceMappingURL=chunk-KGFNWIMS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/server/define/define-route.ts","../src/server/define/define-action.ts","../src/server/define/define-middleware.ts","../src/server/define/define-agent-tool.ts","../src/server/define/define-websocket.ts","../src/server/define/define-channel.ts","../src/server/define/define-plugin.ts"],"sourcesContent":["import type { z } from 'zod'\n\n// T2.2 (architecture-cleanup) — RouteConfig type moved to core/contracts/\n// (canonical home per ADR-0001 v3). Re-export preserves the public path\n// `import { type RouteConfig } from 'theokit/server'`.\nexport type { RouteConfig } from '../../core/contracts/route-config.js'\n\nimport type { RouteConfig } from '../../core/contracts/route-config.js'\n\n/**\n * Define a typed HTTP route.\n * Identity function — provides type inference for route handlers.\n */\nexport function defineRoute<\n TQuery extends z.ZodType = z.ZodUndefined,\n TBody extends z.ZodType = z.ZodUndefined,\n TParams extends z.ZodType = z.ZodUndefined,\n TCtx = unknown,\n TResponse = unknown,\n>(\n config: RouteConfig<TQuery, TBody, TParams, TCtx, TResponse>,\n): RouteConfig<TQuery, TBody, TParams, TCtx, TResponse> {\n return config\n}\n","import type { z } from 'zod'\n\n/**\n * Action wire-protocol accept mode per plan g3-server-actions-and-useaction\n * v1.2 ADR D1. Default behavior (when omitted) is `'json'`. `'form'` opts the\n * action into FormData multipart parsing for progressive-enhancement forms;\n * the runtime in `server/http/action-execute.ts` will coerce FormData entries\n * against the `input` schema via `formDataToObject` (Astro pattern).\n */\nexport type ActionAccept = 'form' | 'json'\n\nexport interface ActionConfig<TInput extends z.ZodType, TCtx = unknown> {\n /**\n * Zod input schema. Required: every action declares its input contract via\n * Zod (architecture rule: zod-is-SSOT). The shape becomes the handler's\n * typed `input` parameter via `z.infer<TInput>`.\n */\n input: TInput\n /**\n * Wire-protocol accept mode. Defaults to `'json'` when omitted. Setting\n * `'form'` switches the runtime to FormData multipart parsing — the input\n * schema MUST be `z.object(...)` so field-by-field coercion can drive\n * boolean string / number / array coercion (Astro pattern).\n */\n accept?: ActionAccept\n /**\n * Opt OUT of CSRF enforcement for this action. Default (omitted) keeps the\n * multi-header CSRF gate active. Set `false` for endpoints intentionally\n * callable without the `X-Theo-Action` header (e.g. public webhooks). The\n * runtime in `server/http/action-execute.ts` reads this flag.\n */\n csrf?: false\n handler: (ctx: { input: z.infer<TInput>; ctx: TCtx }) => unknown\n}\n\n/**\n * Define a typed server action.\n *\n * Identity function — provides type inference for action handlers. The\n * runtime that consumes the config (validation + invocation + serialization)\n * lives in `server/http/action-execute.ts`.\n *\n * Per plan g3-server-actions-and-useaction v1.2 § Phase 1 / T1.2: the new\n * `accept?: 'form' | 'json'` field is the only contract change vs the\n * pre-G3 identity. Existing callsites (`defineAction({input, handler})`)\n * continue to compile — `accept` is opt-in.\n */\nexport function defineAction<TInput extends z.ZodType, TCtx = unknown>(\n config: ActionConfig<TInput, TCtx>,\n): ActionConfig<TInput, TCtx> {\n return config\n}\n","export type MiddlewareHandler = (\n request: Request,\n next: (request: Request) => Promise<Response>,\n) => Response | Promise<Response>\n\n/**\n * Define a middleware handler.\n * Identity function — provides type annotation for middleware.\n */\nexport function defineMiddleware(handler: MiddlewareHandler): MiddlewareHandler {\n return handler\n}\n","import { z } from 'zod'\n\n/**\n * Item #4 — `defineAgentTool`\n *\n * Sugar over the `@theokit/sdk` `CustomTool` contract. Takes a Zod schema +\n * handler and produces a structurally-compatible `CustomTool` that\n * `Agent.create({ tools: [...] })` accepts.\n *\n * Uses Zod v4's native `z.toJSONSchema()` to convert the input schema to\n * JSON Schema for LLM providers.\n *\n * Handler error propagation:\n * `defineAgentTool` parses the input via the Zod schema BEFORE calling the\n * user handler. Invalid input throws a `ZodError`, which the SDK's tool-\n * dispatcher treats as a tool failure and surfaces to the model as a tool\n * error (the SDK owns the wire; ADR D3).\n */\n\n/**\n * Local mirror of the SDK's `CustomTool` interface. We don't `import type`\n * from `@theokit/sdk` because the SDK is an optional peer (consumers who\n * never call `defineAgentTool` shouldn't need it installed). The shape is\n * the wire contract; any structurally-matching object is accepted by\n * `Agent.create({ tools })`.\n *\n * @public\n */\nexport interface CustomTool {\n name: string\n description: string\n inputSchema: Record<string, unknown>\n handler: (input: Record<string, unknown>) => string | Promise<string>\n}\n\n/**\n * Spec accepted by {@link defineAgentTool}. `inputSchema` is a Zod 3 schema\n * rooted in `z.object(...)`. The `handler` argument type is inferred via\n * `z.infer<T>`.\n *\n * @public\n */\nexport interface DefineAgentToolSpec<T extends z.ZodType> {\n /** Tool name surfaced to the LLM. Must match `^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`. */\n name: string\n /** Description surfaced to the LLM. Required — drives tool-selection accuracy. */\n description: string\n /** Zod schema describing the input. Must be `z.object(...)` at the root. */\n inputSchema: T\n /** Handler invoked with the parsed input. */\n handler: (input: z.infer<T>) => string | Promise<string>\n}\n\nconst TOOL_NAME_REGEX = /^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/\n\nfunction isZodObject(schema: z.ZodType): boolean {\n // Refinements (`.refine`), transforms (`.transform`), and defaults wrap the\n // underlying schema — walk the chain until we hit a ZodObject (or give up).\n // Supports both zod 4 (`instanceof z.ZodObject`, `def.type === 'object'`,\n // wrappers via `def.innerType` / pipe via `def.in`) and zod 3\n // (`_def.typeName === 'ZodObject'`, wrappers via `_def.schema`/`_def.innerType`).\n let current: unknown = schema\n for (let depth = 0; depth < 10; depth++) {\n if (current instanceof z.ZodObject) return true\n const z4 = (current as { def?: { type?: string; innerType?: unknown; in?: unknown } }).def\n if (z4?.type === 'object') return true\n const z3 = (current as { _def?: { typeName?: string; schema?: unknown; innerType?: unknown } })\n ._def\n if (z3?.typeName === 'ZodObject') return true\n const next = z4?.innerType ?? z4?.in ?? z3?.schema ?? z3?.innerType\n if (next !== undefined) {\n current = next\n continue\n }\n return false\n }\n return false\n}\n\n/**\n * Build a {@link CustomTool} from a Zod 3 schema + handler.\n *\n * Behavior:\n * - Validates `name` matches the LLM tool-name regex.\n * - Requires `inputSchema` to be a `ZodObject` (Anthropic + SDK contract).\n * - Warns (not throws) if `description` is empty — empty descriptions\n * degrade LLM tool selection.\n * - Converts the Zod schema to JSON Schema 7 inline (no `$ref`s — LLMs handle\n * inline schemas more reliably).\n * - Strips the top-level `$schema` field (Anthropic rejects schemas with\n * `$schema` at root in some provider modes).\n * - Wraps the handler to parse the input via the Zod schema BEFORE invoking\n * the user code — bad LLM-supplied input throws `ZodError`, which the SDK\n * converts to `tool_result(isError)`.\n *\n * @public\n */\nexport function defineAgentTool<T extends z.ZodType>(spec: DefineAgentToolSpec<T>): CustomTool {\n if (!TOOL_NAME_REGEX.test(spec.name)) {\n throw new Error(\n `defineAgentTool: name must match ${TOOL_NAME_REGEX.source}. Got: ${JSON.stringify(spec.name)}`,\n )\n }\n if (!isZodObject(spec.inputSchema)) {\n throw new Error('defineAgentTool: inputSchema must be a ZodObject (z.object({...}))')\n }\n if (spec.description.length === 0) {\n console.warn(\n `defineAgentTool(${JSON.stringify(spec.name)}): empty description degrades LLM tool selection — provide a one-sentence summary.`,\n )\n }\n\n // Zod v4 native JSON Schema conversion — replaces zod-to-json-schema dep.\n // Strip $schema (Anthropic + some providers reject it).\n const { $schema: _$schema, ...inputSchema } = z.toJSONSchema(spec.inputSchema) as Record<\n string,\n unknown\n > & {\n $schema?: unknown\n }\n\n return {\n name: spec.name,\n description: spec.description,\n inputSchema,\n handler: async (input: Record<string, unknown>): Promise<string> => {\n const parsed = spec.inputSchema.parse(input)\n return await spec.handler(parsed)\n },\n }\n}\n","import type { IncomingMessage } from 'node:http'\n\nexport interface WebSocketLike {\n send(data: string | Buffer): void\n close(code?: number, reason?: string): void\n}\n\nexport interface WebSocketHandler {\n onOpen?: (ws: WebSocketLike, req: IncomingMessage) => void\n onMessage?: (ws: WebSocketLike, data: string | Buffer) => void\n onClose?: (ws: WebSocketLike, code: number, reason: Buffer) => void\n onError?: (ws: WebSocketLike, error: Error) => void\n}\n\n/**\n * Define a WebSocket endpoint handler.\n * Identity function — provides type inference for WebSocket handlers.\n */\nexport function defineWebSocket(handler: WebSocketHandler): WebSocketHandler {\n return handler\n}\n\n/**\n * T5a.2 Phase F slice 3/3 — Web-Standards WebSocket endpoint handler.\n *\n * Mirror of `WebSocketHandler` for the Web `Request` shape. `onOpen`\n * receives `request: Request` instead of `req: IncomingMessage`. The\n * rest of the lifecycle (onMessage, onClose, onError) is shape-agnostic\n * (`WebSocketLike` is already Web-standards-compatible per the existing\n * design — `send(string | Buffer)` works on both Node `ws` and Web\n * `WebSocket` instances; CF Workers / Bun / Deno coerce as needed at\n * the adapter boundary).\n *\n * Per `docs/plans/t5a2-incoming-message-to-request-shape-refactor-plan.md`\n * v1.0 § Phase F (closes Phase F).\n *\n * **Architectural note — WebSocket upgrade semantics differ across runtimes:**\n * - Node + `ws`: `WebSocketServer.handleUpgrade(req, socket, head, cb)` —\n * `req` is `IncomingMessage`. Use `WebSocketHandler`.\n * - CF Workers: `new WebSocketPair()` + `request.headers` (the upgrade\n * handshake IS a Web Request). Use `WebSocketHandlerWeb`.\n * - Bun: `server.upgrade(request, { data })` — same Web Request shape.\n * - Deno: `Deno.upgradeWebSocket(request)` — same Web Request shape.\n *\n * Cross-runtime WebSocket endpoints ship BOTH `WebSocketHandler` +\n * `WebSocketHandlerWeb` exports; the runtime adapter picks the matching\n * one. This is the canonical Hono / Nitric pattern.\n */\nexport interface WebSocketHandlerWeb {\n onOpen?: (ws: WebSocketLike, request: Request) => void\n onMessage?: (ws: WebSocketLike, data: string | Uint8Array) => void\n onClose?: (ws: WebSocketLike, code: number, reason: string) => void\n onError?: (ws: WebSocketLike, error: Error) => void\n}\n\n/**\n * Web-Standards `defineWebSocket` sibling. Identity function — provides\n * type inference for Web WebSocket handlers.\n *\n * **Type difference note vs Node path:**\n * - `onMessage` data is `string | Uint8Array` instead of `string | Buffer`\n * (Web standards have no `Buffer`; Node's Buffer is a Uint8Array\n * subclass so the Node path's Buffer values flow through unchanged\n * when adapters wrap them).\n * - `onClose` reason is `string` instead of `Buffer` (Web `CloseEvent`\n * exposes the reason as a UTF-8 string natively).\n */\nexport function defineWebSocketWeb(handler: WebSocketHandlerWeb): WebSocketHandlerWeb {\n return handler\n}\n","import type { IncomingMessage } from 'node:http'\n\nimport type { WebSocketLike } from './define-websocket.js'\n\nexport interface ChannelHandler<TMessage = unknown> {\n onSubscribe?: (ws: WebSocketLike, room: string, req: IncomingMessage) => void\n onMessage?: (ws: WebSocketLike, room: string, data: TMessage) => void\n onUnsubscribe?: (ws: WebSocketLike, room: string) => void\n}\n\n/**\n * Define a channel handler for WebSocket rooms.\n * Identity function — provides type inference for channel handlers.\n */\nexport function defineChannel<TMessage = unknown>(\n handler: ChannelHandler<TMessage>,\n): ChannelHandler<TMessage> {\n return handler\n}\n\n/**\n * T5a.2 Phase F slice 2/3 — Web-Standards channel handler.\n *\n * Mirror of `ChannelHandler<TMessage>` for the Web `Request` shape.\n * `onSubscribe` receives `request: Request` instead of `req: IncomingMessage`\n * — the rest of the surface (onMessage, onUnsubscribe) is shape-agnostic\n * (WebSocketLike is already Web-standards-compatible per `define-websocket.ts`).\n *\n * Per `docs/plans/t5a2-incoming-message-to-request-shape-refactor-plan.md`\n * v1.0 § Phase F.\n *\n * **Architectural note:** WebSocket upgrade semantics differ across\n * runtimes:\n * - Node: `WebSocketServer.handleUpgrade(req, socket, head, cb)` —\n * hands you `req: IncomingMessage` at the upgrade handshake.\n * - CF Workers: `new WebSocketPair()` + `request.headers` (the upgrade\n * handshake IS a Web Request) — hands you `request: Request`.\n * - Bun: `server.upgrade(request, { data })` — same Web Request shape.\n * - Deno: `Deno.upgradeWebSocket(request)` — same Web Request shape.\n *\n * Channel handlers targeting CF/Bun/Deno use `WebChannelHandler`; legacy\n * Node consumers stay on `ChannelHandler`. Cross-runtime channels ship\n * both shapes.\n */\nexport interface WebChannelHandler<TMessage = unknown> {\n onSubscribe?: (ws: WebSocketLike, room: string, request: Request) => void\n onMessage?: (ws: WebSocketLike, room: string, data: TMessage) => void\n onUnsubscribe?: (ws: WebSocketLike, room: string) => void\n}\n\n/**\n * Web-Standards `defineChannel` sibling. Identity function — provides\n * type inference for Web channel handlers.\n */\nexport function defineWebChannel<TMessage = unknown>(\n handler: WebChannelHandler<TMessage>,\n): WebChannelHandler<TMessage> {\n return handler\n}\n","import type { TheoPlugin } from '../plugin-types.js'\n\n/**\n * Identity function for defining a Theo plugin.\n *\n * **Note:** Prefer `definePlugin` (shorter, canonical name per ADR-0008 D6).\n * Both functions are identical — `defineTheoPlugin` is kept as an alias for\n * existing in-tree consumers without forcing a migration sweep.\n */\nexport function defineTheoPlugin(plugin: TheoPlugin): TheoPlugin {\n return plugin\n}\n"],"mappings":";AAaO,SAAS,YAOd,QACsD;AACtD,SAAO;AACT;;;ACwBO,SAAS,aACd,QAC4B;AAC5B,SAAO;AACT;;;AC1CO,SAAS,iBAAiB,SAA+C;AAC9E,SAAO;AACT;;;ACXA,SAAS,SAAS;AAqDlB,IAAM,kBAAkB;AAExB,SAAS,YAAY,QAA4B;AAM/C,MAAI,UAAmB;AACvB,WAAS,QAAQ,GAAG,QAAQ,IAAI,SAAS;AACvC,QAAI,mBAAmB,EAAE,UAAW,QAAO;AAC3C,UAAM,KAAM,QAA2E;AACvF,QAAI,IAAI,SAAS,SAAU,QAAO;AAClC,UAAM,KAAM,QACT;AACH,QAAI,IAAI,aAAa,YAAa,QAAO;AACzC,UAAM,OAAO,IAAI,aAAa,IAAI,MAAM,IAAI,UAAU,IAAI;AAC1D,QAAI,SAAS,QAAW;AACtB,gBAAU;AACV;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAoBO,SAAS,gBAAqC,MAA0C;AAC7F,MAAI,CAAC,gBAAgB,KAAK,KAAK,IAAI,GAAG;AACpC,UAAM,IAAI;AAAA,MACR,oCAAoC,gBAAgB,MAAM,UAAU,KAAK,UAAU,KAAK,IAAI,CAAC;AAAA,IAC/F;AAAA,EACF;AACA,MAAI,CAAC,YAAY,KAAK,WAAW,GAAG;AAClC,UAAM,IAAI,MAAM,oEAAoE;AAAA,EACtF;AACA,MAAI,KAAK,YAAY,WAAW,GAAG;AACjC,YAAQ;AAAA,MACN,mBAAmB,KAAK,UAAU,KAAK,IAAI,CAAC;AAAA,IAC9C;AAAA,EACF;AAIA,QAAM,EAAE,SAAS,UAAU,GAAG,YAAY,IAAI,EAAE,aAAa,KAAK,WAAW;AAO7E,SAAO;AAAA,IACL,MAAM,KAAK;AAAA,IACX,aAAa,KAAK;AAAA,IAClB;AAAA,IACA,SAAS,OAAO,UAAoD;AAClE,YAAM,SAAS,KAAK,YAAY,MAAM,KAAK;AAC3C,aAAO,MAAM,KAAK,QAAQ,MAAM;AAAA,IAClC;AAAA,EACF;AACF;;;AChHO,SAAS,gBAAgB,SAA6C;AAC3E,SAAO;AACT;AA+CO,SAAS,mBAAmB,SAAmD;AACpF,SAAO;AACT;;;ACvDO,SAAS,cACd,SAC0B;AAC1B,SAAO;AACT;AAoCO,SAAS,iBACd,SAC6B;AAC7B,SAAO;AACT;;;ACjDO,SAAS,iBAAiB,QAAgC;AAC/D,SAAO;AACT;","names":[]}
|
|
@@ -1,30 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
broadcastToDevtools
|
|
3
|
-
} from "./chunk-7BIM27LV.js";
|
|
4
1
|
import {
|
|
5
2
|
buildServicesProxyConfig,
|
|
6
3
|
servicesConfigSchema
|
|
7
4
|
} from "./chunk-D7ZH7DTG.js";
|
|
5
|
+
import {
|
|
6
|
+
broadcastToDevtools
|
|
7
|
+
} from "./chunk-7BIM27LV.js";
|
|
8
8
|
import {
|
|
9
9
|
loadEnv,
|
|
10
10
|
resolveTransformer
|
|
11
|
-
} from "./chunk-
|
|
12
|
-
import {
|
|
13
|
-
BATCH_PATH,
|
|
14
|
-
TRACE_HEADER,
|
|
15
|
-
createCorsHandler,
|
|
16
|
-
executeAction,
|
|
17
|
-
executeRoute,
|
|
18
|
-
extractTraceId,
|
|
19
|
-
handleBatchRequest,
|
|
20
|
-
sendError
|
|
21
|
-
} from "./chunk-TGTNRUH3.js";
|
|
11
|
+
} from "./chunk-5UUOGAJH.js";
|
|
22
12
|
import {
|
|
23
13
|
findSuggestion
|
|
24
14
|
} from "./chunk-5QW7IQQU.js";
|
|
25
|
-
import {
|
|
26
|
-
logRequest
|
|
27
|
-
} from "./chunk-WFNLNIJX.js";
|
|
28
15
|
import {
|
|
29
16
|
createPluginRunnerFromConfig
|
|
30
17
|
} from "./chunk-IAJ2JVEH.js";
|
|
@@ -48,12 +35,6 @@ import {
|
|
|
48
35
|
handleCspReport,
|
|
49
36
|
handleCsrfReadiness
|
|
50
37
|
} from "./chunk-JBCHWRKF.js";
|
|
51
|
-
import {
|
|
52
|
-
validateCsrfRequest
|
|
53
|
-
} from "./chunk-TSLSIRBR.js";
|
|
54
|
-
import {
|
|
55
|
-
resolveProvider
|
|
56
|
-
} from "./chunk-EXP56GFQ.js";
|
|
57
38
|
import {
|
|
58
39
|
generateNonce
|
|
59
40
|
} from "./chunk-C3ZZ56YZ.js";
|
|
@@ -62,7 +43,23 @@ import {
|
|
|
62
43
|
} from "./chunk-7MQOHNHE.js";
|
|
63
44
|
import {
|
|
64
45
|
uiMessageStreamResponse
|
|
65
|
-
} from "./chunk-
|
|
46
|
+
} from "./chunk-JZHT3LW7.js";
|
|
47
|
+
import {
|
|
48
|
+
BATCH_PATH,
|
|
49
|
+
TRACE_HEADER,
|
|
50
|
+
createCorsHandler,
|
|
51
|
+
executeAction,
|
|
52
|
+
executeRoute,
|
|
53
|
+
extractTraceId,
|
|
54
|
+
handleBatchRequest,
|
|
55
|
+
sendError
|
|
56
|
+
} from "./chunk-H243MR3F.js";
|
|
57
|
+
import {
|
|
58
|
+
logRequest
|
|
59
|
+
} from "./chunk-Z5IGLBWE.js";
|
|
60
|
+
import {
|
|
61
|
+
validateCsrfRequest
|
|
62
|
+
} from "./chunk-TSLSIRBR.js";
|
|
66
63
|
|
|
67
64
|
// src/vite-plugin/index.ts
|
|
68
65
|
import { existsSync as existsSync9 } from "fs";
|
|
@@ -1037,6 +1034,46 @@ async function mountAgent(mod, request, apiKey, source = "agent module", csrfMod
|
|
|
1037
1034
|
return uiMessageStreamResponse(streamAgentUIMessages(compiled, apiKey, input));
|
|
1038
1035
|
}
|
|
1039
1036
|
|
|
1037
|
+
// src/server/agent/provider-resolver.ts
|
|
1038
|
+
var DEFAULT_REGISTRY = [
|
|
1039
|
+
{
|
|
1040
|
+
name: "openrouter",
|
|
1041
|
+
envKey: "OPENROUTER_API_KEY",
|
|
1042
|
+
baseUrl: "https://openrouter.ai/api/v1",
|
|
1043
|
+
priority: 1
|
|
1044
|
+
},
|
|
1045
|
+
{
|
|
1046
|
+
name: "openai",
|
|
1047
|
+
envKey: "OPENAI_API_KEY",
|
|
1048
|
+
baseUrl: "https://api.openai.com/v1",
|
|
1049
|
+
priority: 2
|
|
1050
|
+
},
|
|
1051
|
+
{
|
|
1052
|
+
name: "anthropic",
|
|
1053
|
+
envKey: "ANTHROPIC_API_KEY",
|
|
1054
|
+
baseUrl: "https://api.anthropic.com",
|
|
1055
|
+
priority: 3
|
|
1056
|
+
}
|
|
1057
|
+
];
|
|
1058
|
+
var registry = [...DEFAULT_REGISTRY];
|
|
1059
|
+
function resolveProvider() {
|
|
1060
|
+
const sorted = [...registry].sort((a, b) => a.priority - b.priority);
|
|
1061
|
+
for (const desc of sorted) {
|
|
1062
|
+
const apiKey = process.env[desc.envKey];
|
|
1063
|
+
if (apiKey && apiKey.length > 0) {
|
|
1064
|
+
return {
|
|
1065
|
+
name: desc.name,
|
|
1066
|
+
apiKey,
|
|
1067
|
+
baseUrl: desc.baseUrl
|
|
1068
|
+
};
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
const envKeys = sorted.map((p) => p.envKey).join(" OR ");
|
|
1072
|
+
throw new Error(
|
|
1073
|
+
`No LLM provider API key found in environment. Set one of: ${envKeys}. Get a free OpenRouter key at https://openrouter.ai/keys (recommended \u2014 one key, many models).`
|
|
1074
|
+
);
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1040
1077
|
// src/server/http/node-web-adapter.ts
|
|
1041
1078
|
import { Readable } from "stream";
|
|
1042
1079
|
function incomingMessageToWebRequest(req) {
|
|
@@ -2516,19 +2553,19 @@ async function theoPluginAsync(rootOrOptions) {
|
|
|
2516
2553
|
})
|
|
2517
2554
|
);
|
|
2518
2555
|
}
|
|
2519
|
-
const { appTypedClientPlugin } = await import("./app-typed-client-
|
|
2556
|
+
const { appTypedClientPlugin } = await import("./app-typed-client-5VQE6DNF.js");
|
|
2520
2557
|
const appClientPlugin = appTypedClientPlugin({
|
|
2521
2558
|
cwd: projectRoot,
|
|
2522
2559
|
serverDir: resolve9(projectRoot, "server"),
|
|
2523
2560
|
distDir: resolve9(projectRoot, ".theokit")
|
|
2524
2561
|
});
|
|
2525
|
-
const { actionsVirtualModule } = await import("./actions-virtual-module-
|
|
2562
|
+
const { actionsVirtualModule } = await import("./actions-virtual-module-RM7JRY5N.js");
|
|
2526
2563
|
const actionsPlugin = actionsVirtualModule({
|
|
2527
2564
|
serverDir: resolve9(projectRoot, "server"),
|
|
2528
2565
|
distDir: resolve9(projectRoot, ".theokit")
|
|
2529
2566
|
});
|
|
2530
2567
|
const { agentsTypedClientPlugin } = await import("./agents-typed-client-SAWAAH7K.js");
|
|
2531
|
-
const { generateManifest } = await import("./internal-api-
|
|
2568
|
+
const { generateManifest } = await import("./internal-api-5BDI6N5U.js");
|
|
2532
2569
|
const agentsClientPlugin = agentsTypedClientPlugin({
|
|
2533
2570
|
projectRoot,
|
|
2534
2571
|
distDir: resolve9(projectRoot, ".theokit"),
|
|
@@ -2706,4 +2743,4 @@ export {
|
|
|
2706
2743
|
theoPluginAsync,
|
|
2707
2744
|
theoPlugin
|
|
2708
2745
|
};
|
|
2709
|
-
//# sourceMappingURL=chunk-
|
|
2746
|
+
//# sourceMappingURL=chunk-RBHCJHRR.js.map
|