theokit 0.13.0 → 0.15.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 (102) hide show
  1. package/dist/{actions-virtual-module-3CDQTWOC.js → actions-virtual-module-G4BANOLW.js} +5 -3
  2. package/dist/{actions-virtual-module-3CDQTWOC.js.map → actions-virtual-module-G4BANOLW.js.map} +1 -1
  3. package/dist/{actions-virtual-module-EIPXX4ZB.js → actions-virtual-module-RM7JRY5N.js} +7 -7
  4. package/dist/agent-MN7XGJR3.js +209 -0
  5. package/dist/agent-MN7XGJR3.js.map +1 -0
  6. package/dist/{app-typed-client-7PBFWZUE.js → app-typed-client-5VQE6DNF.js} +7 -7
  7. package/dist/{app-typed-client-CSOK7NPC.js → app-typed-client-Z6BHD4MF.js} +5 -3
  8. package/dist/{app-typed-client-CSOK7NPC.js.map → app-typed-client-Z6BHD4MF.js.map} +1 -1
  9. package/dist/boot/index.js +3 -3
  10. package/dist/{build-HXND27XG.js → build-QDAFSKKW.js} +11 -7
  11. package/dist/{build-HXND27XG.js.map → build-QDAFSKKW.js.map} +1 -1
  12. package/dist/chunk-34YQOXGM.js +37 -0
  13. package/dist/chunk-34YQOXGM.js.map +1 -0
  14. package/dist/{chunk-7YZHAQU7.js → chunk-567NA7Y6.js} +8 -99
  15. package/dist/chunk-567NA7Y6.js.map +1 -0
  16. package/dist/{chunk-3S3BNW5K.js → chunk-5UUOGAJH.js} +2 -2
  17. package/dist/{chunk-BQDGES7C.js → chunk-GBXLKYIA.js} +19 -43
  18. package/dist/chunk-GBXLKYIA.js.map +1 -0
  19. package/dist/chunk-GDN3PXFH.js +101 -0
  20. package/dist/chunk-GDN3PXFH.js.map +1 -0
  21. package/dist/{chunk-TGTNRUH3.js → chunk-H243MR3F.js} +2 -2
  22. package/dist/{chunk-NHJMZCAS.js → chunk-JZHT3LW7.js} +1 -1
  23. package/dist/chunk-JZHT3LW7.js.map +1 -0
  24. package/dist/chunk-KGFNWIMS.js +94 -0
  25. package/dist/chunk-KGFNWIMS.js.map +1 -0
  26. package/dist/{chunk-EXP56GFQ.js → chunk-NBWB4S46.js} +38 -9
  27. package/dist/chunk-NBWB4S46.js.map +1 -0
  28. package/dist/{chunk-F4YUPDJ2.js → chunk-NXTF5PPW.js} +15 -41
  29. package/dist/chunk-NXTF5PPW.js.map +1 -0
  30. package/dist/{chunk-UNLA45FY.js → chunk-OTFIRP6S.js} +76 -46
  31. package/dist/chunk-OTFIRP6S.js.map +1 -0
  32. package/dist/chunk-P37RZRFV.js +31 -0
  33. package/dist/chunk-P37RZRFV.js.map +1 -0
  34. package/dist/{chunk-RYTZYFSD.js → chunk-UOR6JTCI.js} +205 -33
  35. package/dist/chunk-UOR6JTCI.js.map +1 -0
  36. package/dist/{chunk-WFNLNIJX.js → chunk-Z5IGLBWE.js} +1 -1
  37. package/dist/{chunk-O62MW4MT.js → chunk-ZJDKAD3L.js} +55 -14
  38. package/dist/chunk-ZJDKAD3L.js.map +1 -0
  39. package/dist/cli/index.js +22 -6
  40. package/dist/cli/index.js.map +1 -1
  41. package/dist/client/index.d.ts +3 -152
  42. package/dist/client/index.js +13 -236
  43. package/dist/client/index.js.map +1 -1
  44. package/dist/{dev-OWW4XVIH.js → dev-TEE4T6ZB.js} +13 -8
  45. package/dist/{dev-OWW4XVIH.js.map → dev-TEE4T6ZB.js.map} +1 -1
  46. package/dist/{dev-emit-5MDSBP5D.js → dev-emit-VJ5CFMPY.js} +5 -3
  47. package/dist/{dev-emit-5MDSBP5D.js.map → dev-emit-VJ5CFMPY.js.map} +1 -1
  48. package/dist/index.js +12 -13
  49. package/dist/index.js.map +1 -1
  50. package/dist/{info-OUEUZOT7.js → info-7PE2PZJI.js} +6 -5
  51. package/dist/{info-OUEUZOT7.js.map → info-7PE2PZJI.js.map} +1 -1
  52. package/dist/{internal-api-4YTJDITC.js → internal-api-5BDI6N5U.js} +20 -20
  53. package/dist/{internal-api-EFKZWIYZ.js → internal-api-J27TYE2I.js} +7 -4
  54. package/dist/load-config-JKYO5RFK.js +14 -0
  55. package/dist/{openapi-FHY6HC6I.js → openapi-MXMLZCXC.js} +7 -4
  56. package/dist/{openapi-FHY6HC6I.js.map → openapi-MXMLZCXC.js.map} +1 -1
  57. package/dist/{registry-34LL7NF4.js → registry-XJUYD2OU.js} +2 -2
  58. package/dist/{routes-EW7TP7NJ.js → routes-NNBEZSGN.js} +5 -3
  59. package/dist/{routes-EW7TP7NJ.js.map → routes-NNBEZSGN.js.map} +1 -1
  60. package/dist/server/auth/index.js +1 -1
  61. package/dist/server/define/index.d.ts +3 -70
  62. package/dist/server/define/index.js +2 -4
  63. package/dist/server/http/index.js +2 -2
  64. package/dist/server/index.d.ts +1 -3
  65. package/dist/server/index.js +90 -105
  66. package/dist/server/index.js.map +1 -1
  67. package/dist/server/jobs/index.js +4 -4
  68. package/dist/server/observability/index.js +1 -1
  69. package/dist/server/scan/index.js +1 -1
  70. package/dist/{start-KIQ5TTLR.js → start-7MQEEQH4.js} +68 -8
  71. package/dist/start-7MQEEQH4.js.map +1 -0
  72. package/dist/{static-55G3LX2I.js → static-7ARBVDJF.js} +4 -4
  73. package/dist/vite-plugin/index.js +12 -13
  74. package/dist/{vite-plugin-RK66K26Z.js → vite-plugin-GC6WCU4P.js} +11 -7
  75. package/package.json +2 -6
  76. package/dist/agent-events-DosDXkSV.d.ts +0 -94
  77. package/dist/chunk-2KZQPDYR.js +0 -226
  78. package/dist/chunk-2KZQPDYR.js.map +0 -1
  79. package/dist/chunk-7YZHAQU7.js.map +0 -1
  80. package/dist/chunk-BQDGES7C.js.map +0 -1
  81. package/dist/chunk-EXP56GFQ.js.map +0 -1
  82. package/dist/chunk-F4YUPDJ2.js.map +0 -1
  83. package/dist/chunk-NHJMZCAS.js.map +0 -1
  84. package/dist/chunk-O62MW4MT.js.map +0 -1
  85. package/dist/chunk-RYTZYFSD.js.map +0 -1
  86. package/dist/chunk-UNLA45FY.js.map +0 -1
  87. package/dist/chunk-ZSTZXR2D.js +0 -208
  88. package/dist/chunk-ZSTZXR2D.js.map +0 -1
  89. package/dist/server/agent/index.d.ts +0 -229
  90. package/dist/server/agent/index.js +0 -17
  91. package/dist/start-KIQ5TTLR.js.map +0 -1
  92. /package/dist/{actions-virtual-module-EIPXX4ZB.js.map → actions-virtual-module-RM7JRY5N.js.map} +0 -0
  93. /package/dist/{app-typed-client-7PBFWZUE.js.map → app-typed-client-5VQE6DNF.js.map} +0 -0
  94. /package/dist/{chunk-3S3BNW5K.js.map → chunk-5UUOGAJH.js.map} +0 -0
  95. /package/dist/{chunk-TGTNRUH3.js.map → chunk-H243MR3F.js.map} +0 -0
  96. /package/dist/{chunk-WFNLNIJX.js.map → chunk-Z5IGLBWE.js.map} +0 -0
  97. /package/dist/{internal-api-4YTJDITC.js.map → internal-api-5BDI6N5U.js.map} +0 -0
  98. /package/dist/{internal-api-EFKZWIYZ.js.map → internal-api-J27TYE2I.js.map} +0 -0
  99. /package/dist/{server/agent/index.js.map → load-config-JKYO5RFK.js.map} +0 -0
  100. /package/dist/{registry-34LL7NF4.js.map → registry-XJUYD2OU.js.map} +0 -0
  101. /package/dist/{static-55G3LX2I.js.map → static-7ARBVDJF.js.map} +0 -0
  102. /package/dist/{vite-plugin-RK66K26Z.js.map → vite-plugin-GC6WCU4P.js.map} +0 -0
@@ -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-3S3BNW5K.js";
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-NHJMZCAS.js";
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";
@@ -987,14 +984,102 @@ function createActionMiddleware(vite, serverDir, options) {
987
984
  // src/vite-plugin/agent-middleware.ts
988
985
  import { randomUUID as randomUUID2 } from "crypto";
989
986
 
987
+ // src/server/agent/approval-registry.ts
988
+ var serverRegistry;
989
+ function getApprovalRegistry() {
990
+ serverRegistry ??= createInProcessApprovalRegistry();
991
+ return serverRegistry;
992
+ }
993
+ function createInProcessApprovalRegistry() {
994
+ const pending = /* @__PURE__ */ new Map();
995
+ return {
996
+ register(approvalId, opts) {
997
+ return new Promise((resolve10) => {
998
+ const settle = (approved) => {
999
+ const entry = pending.get(approvalId);
1000
+ if (!entry) return;
1001
+ clearTimeout(entry.timer);
1002
+ pending.delete(approvalId);
1003
+ resolve10(approved);
1004
+ };
1005
+ const timer = setTimeout(() => {
1006
+ settle(opts.onTimeout === "proceed");
1007
+ }, opts.timeoutMs);
1008
+ pending.set(approvalId, { settle, timer });
1009
+ });
1010
+ },
1011
+ resolve(approvalId, approved) {
1012
+ const entry = pending.get(approvalId);
1013
+ if (!entry) return false;
1014
+ entry.settle(approved);
1015
+ return true;
1016
+ }
1017
+ };
1018
+ }
1019
+
1020
+ // src/server/agent/approve-agent.ts
1021
+ var APPROVE_SEGMENT = "/approve/";
1022
+ function parseApprovalId(urlPath) {
1023
+ const at = urlPath.indexOf(APPROVE_SEGMENT);
1024
+ if (at === -1) return null;
1025
+ const id = urlPath.slice(at + APPROVE_SEGMENT.length);
1026
+ return id.length > 0 && !id.includes("/") ? id : null;
1027
+ }
1028
+ function isApprovalPath(urlPath) {
1029
+ return urlPath.includes(APPROVE_SEGMENT);
1030
+ }
1031
+ function jsonError(status, code, message) {
1032
+ return new Response(JSON.stringify({ error: { code, message } }), {
1033
+ status,
1034
+ headers: { "content-type": "application/json" }
1035
+ });
1036
+ }
1037
+ function parseApprovalBody(body) {
1038
+ if (typeof body !== "object" || body === null) return null;
1039
+ const b = body;
1040
+ return typeof b.approved === "boolean" ? { approved: b.approved } : null;
1041
+ }
1042
+ async function handleAgentApproval(request, urlPath, registry2, csrfMode = "strict") {
1043
+ if (csrfMode !== "off") {
1044
+ const csrf = validateCsrfRequest(request);
1045
+ if (!csrf.valid && csrfMode === "strict") {
1046
+ return jsonError(403, "CSRF_FAILED", `CSRF check failed: ${csrf.reason}`);
1047
+ }
1048
+ }
1049
+ const approvalId = parseApprovalId(urlPath);
1050
+ if (approvalId === null) {
1051
+ return jsonError(400, "BAD_REQUEST", "Approval path must be /api/agents/<name>/approve/<id>.");
1052
+ }
1053
+ let body = null;
1054
+ try {
1055
+ body = await request.json();
1056
+ } catch {
1057
+ }
1058
+ const parsed = parseApprovalBody(body);
1059
+ if (parsed === null) {
1060
+ return jsonError(400, "BAD_REQUEST", "Request body must contain a boolean `approved`.");
1061
+ }
1062
+ const resolved = registry2.resolve(approvalId, parsed.approved);
1063
+ if (!resolved) {
1064
+ return jsonError(404, "NOT_PENDING", `No pending approval for id '${approvalId}'.`);
1065
+ }
1066
+ return new Response(JSON.stringify({ resolved: true }), {
1067
+ status: 200,
1068
+ headers: { "content-type": "application/json" }
1069
+ });
1070
+ }
1071
+
990
1072
  // src/server/agent/mount-agent.ts
991
- import { compileAgentModule, streamAgentUIMessages } from "@theokit/agents";
1073
+ import {
1074
+ compileAgentModule,
1075
+ streamAgentUIMessages
1076
+ } from "@theokit/agents";
992
1077
  function partText(part) {
993
1078
  if (typeof part !== "object" || part === null) return "";
994
1079
  const p = part;
995
1080
  return p.type === "text" && typeof p.text === "string" ? p.text : "";
996
1081
  }
997
- function jsonError(status, code, message) {
1082
+ function jsonError2(status, code, message) {
998
1083
  return new Response(JSON.stringify({ error: { code, message } }), {
999
1084
  status,
1000
1085
  headers: { "content-type": "application/json" }
@@ -1021,7 +1106,7 @@ async function mountAgent(mod, request, apiKey, source = "agent module", csrfMod
1021
1106
  if (csrfMode !== "off") {
1022
1107
  const csrf = validateCsrfRequest(request);
1023
1108
  if (!csrf.valid && csrfMode === "strict") {
1024
- return jsonError(403, "CSRF_FAILED", `CSRF check failed: ${csrf.reason}`);
1109
+ return jsonError2(403, "CSRF_FAILED", `CSRF check failed: ${csrf.reason}`);
1025
1110
  }
1026
1111
  }
1027
1112
  const compiled = compileAgentModule(mod, source);
@@ -1032,9 +1117,60 @@ async function mountAgent(mod, request, apiKey, source = "agent module", csrfMod
1032
1117
  }
1033
1118
  const input = parseAgentRequestBody(body);
1034
1119
  if (input === null) {
1035
- return jsonError(400, "BAD_REQUEST", "Request must contain a non-empty message or messages[].");
1120
+ return jsonError2(400, "BAD_REQUEST", "Request must contain a non-empty message or messages[].");
1121
+ }
1122
+ const gated = compiled.hitl;
1123
+ const registry2 = getApprovalRegistry();
1124
+ const hitl = gated && gated.size > 0 ? {
1125
+ gated,
1126
+ awaitApproval: (approvalId, opts) => registry2.register(approvalId, {
1127
+ timeoutMs: opts.timeout ?? 3e5,
1128
+ onTimeout: opts.onTimeout ?? "abort"
1129
+ })
1130
+ } : void 0;
1131
+ return uiMessageStreamResponse(
1132
+ streamAgentUIMessages(compiled, apiKey, { ...input, hitl, signal: request.signal })
1133
+ );
1134
+ }
1135
+
1136
+ // src/server/agent/provider-resolver.ts
1137
+ var DEFAULT_REGISTRY = [
1138
+ {
1139
+ name: "openrouter",
1140
+ envKey: "OPENROUTER_API_KEY",
1141
+ baseUrl: "https://openrouter.ai/api/v1",
1142
+ priority: 1
1143
+ },
1144
+ {
1145
+ name: "openai",
1146
+ envKey: "OPENAI_API_KEY",
1147
+ baseUrl: "https://api.openai.com/v1",
1148
+ priority: 2
1149
+ },
1150
+ {
1151
+ name: "anthropic",
1152
+ envKey: "ANTHROPIC_API_KEY",
1153
+ baseUrl: "https://api.anthropic.com",
1154
+ priority: 3
1155
+ }
1156
+ ];
1157
+ var registry = [...DEFAULT_REGISTRY];
1158
+ function resolveProvider() {
1159
+ const sorted = [...registry].sort((a, b) => a.priority - b.priority);
1160
+ for (const desc of sorted) {
1161
+ const apiKey = process.env[desc.envKey];
1162
+ if (apiKey && apiKey.length > 0) {
1163
+ return {
1164
+ name: desc.name,
1165
+ apiKey,
1166
+ baseUrl: desc.baseUrl
1167
+ };
1168
+ }
1036
1169
  }
1037
- return uiMessageStreamResponse(streamAgentUIMessages(compiled, apiKey, input));
1170
+ const envKeys = sorted.map((p) => p.envKey).join(" OR ");
1171
+ throw new Error(
1172
+ `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).`
1173
+ );
1038
1174
  }
1039
1175
 
1040
1176
  // src/server/http/node-web-adapter.ts
@@ -1116,6 +1252,42 @@ function createAgentMiddleware(vite, projectRoot, csrfMode = "strict") {
1116
1252
  const start = Date.now();
1117
1253
  res.setHeader("x-request-id", requestId);
1118
1254
  const urlPath = url.split("?")[0];
1255
+ if (isApprovalPath(urlPath)) {
1256
+ const method2 = (req.method ?? "POST").toUpperCase();
1257
+ if (method2 !== "POST") {
1258
+ sendError(
1259
+ res,
1260
+ "METHOD_NOT_ALLOWED",
1261
+ "Approve endpoints accept POST",
1262
+ 405,
1263
+ void 0,
1264
+ requestId
1265
+ );
1266
+ logRequest({ method: method2, url, status: 405, duration: Date.now() - start, requestId });
1267
+ return;
1268
+ }
1269
+ try {
1270
+ const request = incomingMessageToWebRequest(req);
1271
+ const response = await handleAgentApproval(
1272
+ request,
1273
+ urlPath,
1274
+ getApprovalRegistry(),
1275
+ csrfMode
1276
+ );
1277
+ await writeWebResponseToServerResponse(response, res);
1278
+ } catch (err) {
1279
+ sendError(
1280
+ res,
1281
+ "INTERNAL",
1282
+ err instanceof Error ? err.message : "Approve handler failed",
1283
+ 500,
1284
+ void 0,
1285
+ requestId
1286
+ );
1287
+ }
1288
+ logRequest({ method: method2, url, status: res.statusCode, duration: Date.now() - start, requestId });
1289
+ return;
1290
+ }
1119
1291
  const agent = scanAgents(projectRoot).find((a) => a.agentPath === urlPath);
1120
1292
  if (!agent) {
1121
1293
  next();
@@ -2516,19 +2688,19 @@ async function theoPluginAsync(rootOrOptions) {
2516
2688
  })
2517
2689
  );
2518
2690
  }
2519
- const { appTypedClientPlugin } = await import("./app-typed-client-7PBFWZUE.js");
2691
+ const { appTypedClientPlugin } = await import("./app-typed-client-5VQE6DNF.js");
2520
2692
  const appClientPlugin = appTypedClientPlugin({
2521
2693
  cwd: projectRoot,
2522
2694
  serverDir: resolve9(projectRoot, "server"),
2523
2695
  distDir: resolve9(projectRoot, ".theokit")
2524
2696
  });
2525
- const { actionsVirtualModule } = await import("./actions-virtual-module-EIPXX4ZB.js");
2697
+ const { actionsVirtualModule } = await import("./actions-virtual-module-RM7JRY5N.js");
2526
2698
  const actionsPlugin = actionsVirtualModule({
2527
2699
  serverDir: resolve9(projectRoot, "server"),
2528
2700
  distDir: resolve9(projectRoot, ".theokit")
2529
2701
  });
2530
2702
  const { agentsTypedClientPlugin } = await import("./agents-typed-client-SAWAAH7K.js");
2531
- const { generateManifest } = await import("./internal-api-4YTJDITC.js");
2703
+ const { generateManifest } = await import("./internal-api-5BDI6N5U.js");
2532
2704
  const agentsClientPlugin = agentsTypedClientPlugin({
2533
2705
  projectRoot,
2534
2706
  distDir: resolve9(projectRoot, ".theokit"),
@@ -2706,4 +2878,4 @@ export {
2706
2878
  theoPluginAsync,
2707
2879
  theoPlugin
2708
2880
  };
2709
- //# sourceMappingURL=chunk-RYTZYFSD.js.map
2881
+ //# sourceMappingURL=chunk-UOR6JTCI.js.map