theokit 0.16.0 → 0.18.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 (95) hide show
  1. package/dist/actions-virtual-module-G4BANOLW.js +0 -0
  2. package/dist/add-W6FNTAFS.js +0 -0
  3. package/dist/{agent-BBK42EPJ.js → agent-TZ5JZUJ7.js} +3 -3
  4. package/dist/agents-typed-client-LQ36PCHL.js +0 -0
  5. package/dist/app-typed-client-Z6BHD4MF.js +0 -0
  6. package/dist/aws-lambda-7GSCNLPY.js +0 -0
  7. package/dist/body-parser-web-FV5HWCY3.js +0 -0
  8. package/dist/broadcast-LUMOJIJT.js +0 -0
  9. package/dist/{build-LZ4QSZ63.js → build-5PSDDMFB.js} +2 -2
  10. package/dist/build-request-body-preview-QMWD2IXK.js +0 -0
  11. package/dist/bun-KP2KES6S.js +0 -0
  12. package/dist/check-PD2FTKMM.js +0 -0
  13. package/dist/chunk-34YQOXGM.js +0 -0
  14. package/dist/chunk-45C3WUQ7.js +0 -0
  15. package/dist/chunk-567NA7Y6.js +0 -0
  16. package/dist/chunk-5ODOE6EF.js +0 -0
  17. package/dist/{chunk-7HBLJ5BU.js → chunk-CC5WOQUV.js} +69 -188
  18. package/dist/chunk-CC5WOQUV.js.map +1 -0
  19. package/dist/{chunk-AXVP326H.js → chunk-CWVBDUDC.js} +17 -3
  20. package/dist/chunk-CWVBDUDC.js.map +1 -0
  21. package/dist/{chunk-3HLO7KAK.js → chunk-DEO2VAJE.js} +163 -71
  22. package/dist/chunk-DEO2VAJE.js.map +1 -0
  23. package/dist/chunk-FOZIR3TG.js +0 -0
  24. package/dist/chunk-GBXLKYIA.js +0 -0
  25. package/dist/chunk-GDN3PXFH.js +0 -0
  26. package/dist/chunk-HGZL5EOI.js +0 -0
  27. package/dist/chunk-HNBWZKIQ.js +0 -0
  28. package/dist/chunk-IEES3CHD.js +0 -0
  29. package/dist/chunk-JAIKGP3Q.js +0 -0
  30. package/dist/chunk-JQSFBJR5.js +0 -0
  31. package/dist/chunk-KXA37ONC.js +0 -0
  32. package/dist/{chunk-FIZXWL73.js → chunk-M6NMS5LR.js} +8 -7
  33. package/dist/{chunk-FIZXWL73.js.map → chunk-M6NMS5LR.js.map} +1 -1
  34. package/dist/chunk-NXTF5PPW.js +0 -0
  35. package/dist/chunk-P37RZRFV.js +0 -0
  36. package/dist/chunk-WR4F4EEZ.js +0 -0
  37. package/dist/{chunk-Q6KPASBB.js → chunk-XVFMSNDE.js} +247 -7
  38. package/dist/chunk-XVFMSNDE.js.map +1 -0
  39. package/dist/{chunk-5UUOGAJH.js → chunk-XWS4RZCE.js} +47 -1
  40. package/dist/{chunk-5UUOGAJH.js.map → chunk-XWS4RZCE.js.map} +1 -1
  41. package/dist/chunk-YJAUJXZS.js +0 -0
  42. package/dist/cli/index.js +4 -4
  43. package/dist/client/index.d.ts +51 -1
  44. package/dist/client/index.js +43 -0
  45. package/dist/client/index.js.map +1 -1
  46. package/dist/cloudflare-C6E5SPAE.js +0 -0
  47. package/dist/configure-agent-registry-ZOBVU3MV.js +0 -0
  48. package/dist/db-3UNAMSFK.js +0 -0
  49. package/dist/deno-deploy-RFZN56X4.js +0 -0
  50. package/dist/{dev-P4GENSZK.js → dev-A7NESJ7S.js} +4 -4
  51. package/dist/dev-emit-VJ5CFMPY.js +0 -0
  52. package/dist/dispatcher-EJHL6JMJ.js +0 -0
  53. package/dist/docker-LZZB4D5E.js +0 -0
  54. package/dist/generate-OMKHQ7OM.js +0 -0
  55. package/dist/index.js +2 -2
  56. package/dist/info-7PE2PZJI.js +0 -0
  57. package/dist/internal-api-J27TYE2I.js +0 -0
  58. package/dist/load-config-JKYO5RFK.js +0 -0
  59. package/dist/netlify-PMLHVPN4.js +0 -0
  60. package/dist/node-BPJ3Z4DT.js +0 -0
  61. package/dist/openapi-MXMLZCXC.js +0 -0
  62. package/dist/registry-XJUYD2OU.js +0 -0
  63. package/dist/router-TLEAOFID.js +0 -0
  64. package/dist/routes-NNBEZSGN.js +0 -0
  65. package/dist/scan-7MJC6PYU.js +0 -0
  66. package/dist/schema-7CAY6IZR.js +0 -0
  67. package/dist/server/define/index.d.ts +29 -4
  68. package/dist/server/define/index.js +3 -1
  69. package/dist/server/index.d.ts +286 -4
  70. package/dist/server/index.js +234 -2
  71. package/dist/server/index.js.map +1 -1
  72. package/dist/server-error-to-envelope-UUXDSLAZ.js +0 -0
  73. package/dist/server-routes-hmr-VZXOP5YT.js +0 -0
  74. package/dist/services-json-Y3XODNB5.js +0 -0
  75. package/dist/services-typed-client-32KMTTXR.js +0 -0
  76. package/dist/{start-4VPYN2OS.js → start-WGOKQEUW.js} +31 -7
  77. package/dist/start-WGOKQEUW.js.map +1 -0
  78. package/dist/static-7ARBVDJF.js +0 -0
  79. package/dist/storage-manager-ZSQFLEYT.js +0 -0
  80. package/dist/theo-cloud-DQRP6S6M.js +0 -0
  81. package/dist/upgrade-readiness-ACGW44JC.js +0 -0
  82. package/dist/vercel-J6G7ZHYQ.js +0 -0
  83. package/dist/vite-plugin/index.js +2 -2
  84. package/dist/{vite-plugin-23BBKL3F.js → vite-plugin-DBS2USI4.js} +4 -4
  85. package/package.json +11 -11
  86. package/LICENSE +0 -201
  87. package/dist/chunk-3HLO7KAK.js.map +0 -1
  88. package/dist/chunk-7HBLJ5BU.js.map +0 -1
  89. package/dist/chunk-AXVP326H.js.map +0 -1
  90. package/dist/chunk-Q6KPASBB.js.map +0 -1
  91. package/dist/start-4VPYN2OS.js.map +0 -1
  92. /package/dist/{agent-BBK42EPJ.js.map → agent-TZ5JZUJ7.js.map} +0 -0
  93. /package/dist/{build-LZ4QSZ63.js.map → build-5PSDDMFB.js.map} +0 -0
  94. /package/dist/{dev-P4GENSZK.js.map → dev-A7NESJ7S.js.map} +0 -0
  95. /package/dist/{vite-plugin-23BBKL3F.js.map → vite-plugin-DBS2USI4.js.map} +0 -0
@@ -6,9 +6,12 @@ import {
6
6
  broadcastToDevtools
7
7
  } from "./chunk-7BIM27LV.js";
8
8
  import {
9
+ buildResourceDescriptors,
10
+ extractAppResources,
9
11
  loadEnv,
12
+ readAppResource,
10
13
  resolveTransformer
11
- } from "./chunk-5UUOGAJH.js";
14
+ } from "./chunk-XWS4RZCE.js";
12
15
  import {
13
16
  findSuggestion
14
17
  } from "./chunk-5QW7IQQU.js";
@@ -1039,29 +1042,30 @@ function createInProcessApprovalRegistry() {
1039
1042
  return {
1040
1043
  register(approvalId, opts) {
1041
1044
  return new Promise((resolve10) => {
1042
- const settle = (approved) => {
1045
+ const settle = (decision) => {
1043
1046
  const entry = pending.get(approvalId);
1044
1047
  if (!entry) return;
1045
1048
  clearTimeout(entry.timer);
1046
1049
  pending.delete(approvalId);
1047
- resolve10(approved);
1050
+ resolve10(decision);
1048
1051
  };
1049
1052
  const timer = setTimeout(() => {
1050
- settle(opts.onTimeout === "proceed");
1053
+ settle({ approved: opts.onTimeout === "proceed" });
1051
1054
  }, opts.timeoutMs);
1052
1055
  const info = {
1053
1056
  approvalId,
1054
1057
  toolName: opts.toolName,
1055
1058
  question: opts.question,
1056
- expiresAt: Date.now() + opts.timeoutMs
1059
+ expiresAt: Date.now() + opts.timeoutMs,
1060
+ ...opts.payloadSchema !== void 0 ? { payloadSchema: opts.payloadSchema } : {}
1057
1061
  };
1058
1062
  pending.set(approvalId, { settle, timer, info });
1059
1063
  });
1060
1064
  },
1061
- resolve(approvalId, approved) {
1065
+ resolve(approvalId, decision) {
1062
1066
  const entry = pending.get(approvalId);
1063
1067
  if (!entry) return false;
1064
- entry.settle(approved);
1068
+ entry.settle(typeof decision === "boolean" ? { approved: decision } : decision);
1065
1069
  return true;
1066
1070
  },
1067
1071
  list() {
@@ -1087,10 +1091,22 @@ function jsonError(status, code, message) {
1087
1091
  headers: { "content-type": "application/json" }
1088
1092
  });
1089
1093
  }
1094
+ var MAX_PAYLOAD_BYTES = 16 * 1024;
1090
1095
  function parseApprovalBody(body) {
1091
1096
  if (typeof body !== "object" || body === null) return null;
1092
1097
  const b = body;
1093
- return typeof b.approved === "boolean" ? { approved: b.approved } : null;
1098
+ if (typeof b.approved !== "boolean") return null;
1099
+ const decision = { approved: b.approved };
1100
+ if (b.reason !== void 0) {
1101
+ if (typeof b.reason !== "string") return null;
1102
+ decision.reason = b.reason;
1103
+ }
1104
+ if (b.payload !== void 0) {
1105
+ if (typeof b.payload !== "object" || b.payload === null || Array.isArray(b.payload)) return null;
1106
+ if (JSON.stringify(b.payload).length > MAX_PAYLOAD_BYTES) return null;
1107
+ decision.payload = b.payload;
1108
+ }
1109
+ return decision;
1094
1110
  }
1095
1111
  async function handleAgentApproval(request, urlPath, registry2, csrfMode = "strict") {
1096
1112
  if (csrfMode !== "off") {
@@ -1112,7 +1128,7 @@ async function handleAgentApproval(request, urlPath, registry2, csrfMode = "stri
1112
1128
  if (parsed === null) {
1113
1129
  return jsonError(400, "BAD_REQUEST", "Request body must contain a boolean `approved`.");
1114
1130
  }
1115
- const resolved = registry2.resolve(approvalId, parsed.approved);
1131
+ const resolved = registry2.resolve(approvalId, parsed);
1116
1132
  if (!resolved) {
1117
1133
  return jsonError(404, "NOT_PENDING", `No pending approval for id '${approvalId}'.`);
1118
1134
  }
@@ -1174,21 +1190,27 @@ function toEntry(name, mod) {
1174
1190
  subAgents: []
1175
1191
  };
1176
1192
  }
1177
- function handleMcpJsonRpc(mod, name, body) {
1193
+ function handleMcpJsonRpc(mod, name, body, appResources = []) {
1178
1194
  if (!isJsonRpcRequest(body)) {
1179
- return jsonResponse({ jsonrpc: "2.0", id: null, error: { code: -32600, message: "Invalid Request" } });
1195
+ return jsonResponse({
1196
+ jsonrpc: "2.0",
1197
+ id: null,
1198
+ error: { code: -32600, message: "Invalid Request" }
1199
+ });
1180
1200
  }
1181
- const { id, method } = body;
1201
+ const { id, method, params } = body;
1182
1202
  try {
1183
1203
  const entry = toEntry(name, mod);
1184
1204
  if (method === "initialize") {
1185
1205
  const info = mcpServerInfo(entry);
1206
+ const capabilities = { tools: {} };
1207
+ if (appResources.length > 0) capabilities.resources = {};
1186
1208
  return jsonResponse({
1187
1209
  jsonrpc: "2.0",
1188
1210
  id,
1189
1211
  result: {
1190
1212
  protocolVersion: info.protocolVersion,
1191
- capabilities: { tools: {} },
1213
+ capabilities,
1192
1214
  serverInfo: { name: info.name, version: info.version }
1193
1215
  }
1194
1216
  });
@@ -1196,7 +1218,37 @@ function handleMcpJsonRpc(mod, name, body) {
1196
1218
  if (method === "tools/list") {
1197
1219
  return jsonResponse({ jsonrpc: "2.0", id, result: { tools: buildMcpToolDescriptors(entry) } });
1198
1220
  }
1199
- return jsonResponse({ jsonrpc: "2.0", id, error: { code: -32601, message: `Method not found: ${method}` } });
1221
+ if (method === "resources/list") {
1222
+ return jsonResponse({
1223
+ jsonrpc: "2.0",
1224
+ id,
1225
+ result: { resources: buildResourceDescriptors(appResources) }
1226
+ });
1227
+ }
1228
+ if (method === "resources/read") {
1229
+ const uri = params?.uri;
1230
+ if (typeof uri !== "string") {
1231
+ return jsonResponse({
1232
+ jsonrpc: "2.0",
1233
+ id,
1234
+ error: { code: -32602, message: "resources/read requires a string `uri` param." }
1235
+ });
1236
+ }
1237
+ const contents = readAppResource(appResources, uri);
1238
+ if (contents === null) {
1239
+ return jsonResponse({
1240
+ jsonrpc: "2.0",
1241
+ id,
1242
+ error: { code: -32602, message: `Resource not found: ${uri}` }
1243
+ });
1244
+ }
1245
+ return jsonResponse({ jsonrpc: "2.0", id, result: contents });
1246
+ }
1247
+ return jsonResponse({
1248
+ jsonrpc: "2.0",
1249
+ id,
1250
+ error: { code: -32601, message: `Method not found: ${method}` }
1251
+ });
1200
1252
  } catch (err) {
1201
1253
  return jsonResponse({
1202
1254
  jsonrpc: "2.0",
@@ -1270,7 +1322,9 @@ async function mountAgent(mod, request, apiKey, source = "agent module", csrfMod
1270
1322
  onTimeout: opts.onTimeout ?? "abort",
1271
1323
  // M14 — surface toolName + question in GET /approvals (the plugin forwards c.name).
1272
1324
  toolName,
1273
- question: opts.question
1325
+ question: opts.question,
1326
+ // M20 — carry the declared custom-payload schema into GET /approvals.
1327
+ ...opts.payloadSchema !== void 0 ? { payloadSchema: opts.payloadSchema } : {}
1274
1328
  })
1275
1329
  } : void 0;
1276
1330
  return uiMessageStreamResponse(
@@ -1318,6 +1372,37 @@ function resolveProvider() {
1318
1372
  );
1319
1373
  }
1320
1374
 
1375
+ // src/server/agent/serve-aux-routes.ts
1376
+ async function serveAgentAuxRoute(request, urlPath, deps) {
1377
+ const method = request.method.toUpperCase();
1378
+ const cardName = isAgentCardPath(urlPath);
1379
+ if (cardName !== null) {
1380
+ if (method !== "GET") return null;
1381
+ const agent = deps.agents.find((a) => a.name === cardName);
1382
+ if (!agent) return null;
1383
+ const mod = await deps.loadModule(agent.filePath);
1384
+ return handleAgentCard(mod, agent.name, agent.agentPath, deps.baseUrl);
1385
+ }
1386
+ if (isListApprovalsPath(urlPath)) {
1387
+ if (method !== "GET") return null;
1388
+ return handleListApprovals(getApprovalRegistry());
1389
+ }
1390
+ const mcpName = isMcpPath(urlPath);
1391
+ if (mcpName !== null) {
1392
+ if (method !== "POST") return null;
1393
+ const agent = deps.agents.find((a) => a.name === mcpName);
1394
+ if (!agent) return null;
1395
+ let body = null;
1396
+ try {
1397
+ body = await request.json();
1398
+ } catch {
1399
+ }
1400
+ const mod = await deps.loadModule(agent.filePath);
1401
+ return handleMcpJsonRpc(mod, agent.name, body, extractAppResources(mod));
1402
+ }
1403
+ return null;
1404
+ }
1405
+
1321
1406
  // src/server/http/node-web-adapter.ts
1322
1407
  import { Readable } from "stream";
1323
1408
  function incomingMessageToWebRequest(req) {
@@ -1387,44 +1472,41 @@ var PREFIX2 = "/api/agents/";
1387
1472
  async function serveApprove(req, res, urlPath, csrfMode, log) {
1388
1473
  const method = (req.method ?? "POST").toUpperCase();
1389
1474
  if (method !== "POST") {
1390
- sendError(res, "METHOD_NOT_ALLOWED", "Approve endpoints accept POST", 405, void 0, log.requestId);
1391
- logRequest({ method, url: req.url ?? "", status: 405, duration: Date.now() - log.start, requestId: log.requestId });
1475
+ sendError(
1476
+ res,
1477
+ "METHOD_NOT_ALLOWED",
1478
+ "Approve endpoints accept POST",
1479
+ 405,
1480
+ void 0,
1481
+ log.requestId
1482
+ );
1483
+ logRequest({
1484
+ method,
1485
+ url: req.url ?? "",
1486
+ status: 405,
1487
+ duration: Date.now() - log.start,
1488
+ requestId: log.requestId
1489
+ });
1392
1490
  return;
1393
1491
  }
1394
1492
  try {
1395
- const response = await handleAgentApproval(incomingMessageToWebRequest(req), urlPath, getApprovalRegistry(), csrfMode);
1493
+ const response = await handleAgentApproval(
1494
+ incomingMessageToWebRequest(req),
1495
+ urlPath,
1496
+ getApprovalRegistry(),
1497
+ csrfMode
1498
+ );
1396
1499
  await writeWebResponseToServerResponse(response, res);
1397
1500
  } catch (err) {
1398
- sendError(res, "INTERNAL", err instanceof Error ? err.message : "Approve handler failed", 500, void 0, log.requestId);
1399
- }
1400
- logRequest({ method, url: req.url ?? "", status: res.statusCode, duration: Date.now() - log.start, requestId: log.requestId });
1401
- }
1402
- async function serveMcp(req, res, next, mcpAgentName, deps) {
1403
- const requestId = randomUUID2();
1404
- const start = Date.now();
1405
- res.setHeader("x-request-id", requestId);
1406
- const method = (req.method ?? "POST").toUpperCase();
1407
- const agent = scanAgents(deps.projectRoot).find((a) => a.name === mcpAgentName);
1408
- if (method !== "POST" || !agent) {
1409
- next();
1410
- return;
1411
- }
1412
- try {
1413
- const body = await incomingMessageToWebRequest(req).json();
1414
- const mod = await deps.loadModule(agent.filePath);
1415
- await writeWebResponseToServerResponse(handleMcpJsonRpc(mod, agent.name, body), res);
1416
- } catch (err) {
1417
- sendError(res, "INTERNAL", err instanceof Error ? err.message : "MCP handler failed", 500, void 0, requestId);
1418
- }
1419
- logRequest({ method, url: req.url ?? "", status: res.statusCode, duration: Date.now() - start, requestId });
1420
- }
1421
- async function serveListApprovals(req, res, next, log) {
1422
- const method = (req.method ?? "GET").toUpperCase();
1423
- if (method !== "GET") {
1424
- next();
1425
- return;
1501
+ sendError(
1502
+ res,
1503
+ "INTERNAL",
1504
+ err instanceof Error ? err.message : "Approve handler failed",
1505
+ 500,
1506
+ void 0,
1507
+ log.requestId
1508
+ );
1426
1509
  }
1427
- await writeWebResponseToServerResponse(handleListApprovals(getApprovalRegistry()), res);
1428
1510
  logRequest({
1429
1511
  method,
1430
1512
  url: req.url ?? "",
@@ -1433,33 +1515,48 @@ async function serveListApprovals(req, res, next, log) {
1433
1515
  requestId: log.requestId
1434
1516
  });
1435
1517
  }
1436
- async function serveAgentCard(req, res, next, cardAgentName, deps) {
1518
+ async function serveAux(req, res, next, urlPath, deps) {
1437
1519
  const requestId = randomUUID2();
1438
1520
  const start = Date.now();
1439
- res.setHeader("x-request-id", requestId);
1440
- const method = (req.method ?? "GET").toUpperCase();
1441
- const agent = scanAgents(deps.projectRoot).find((a) => a.name === cardAgentName);
1442
- if (method !== "GET" || !agent) {
1443
- next();
1444
- return;
1445
- }
1446
1521
  try {
1447
- const mod = await deps.loadModule(agent.filePath);
1448
- const baseUrl = `http://${req.headers.host ?? "localhost"}`;
1449
- await writeWebResponseToServerResponse(handleAgentCard(mod, agent.name, agent.agentPath, baseUrl), res);
1522
+ const request = incomingMessageToWebRequest(req);
1523
+ const response = await serveAgentAuxRoute(request, urlPath, {
1524
+ agents: scanAgents(deps.projectRoot),
1525
+ loadModule: deps.loadModule,
1526
+ baseUrl: `http://${req.headers.host ?? "localhost"}`
1527
+ });
1528
+ if (response === null) {
1529
+ next();
1530
+ return;
1531
+ }
1532
+ res.setHeader("x-request-id", requestId);
1533
+ await writeWebResponseToServerResponse(response, res);
1450
1534
  } catch (err) {
1451
- sendError(res, "INTERNAL", err instanceof Error ? err.message : "Agent card failed", 500, void 0, requestId);
1535
+ res.setHeader("x-request-id", requestId);
1536
+ sendError(
1537
+ res,
1538
+ "INTERNAL",
1539
+ err instanceof Error ? err.message : "Agent aux handler failed",
1540
+ 500,
1541
+ void 0,
1542
+ requestId
1543
+ );
1452
1544
  }
1453
- logRequest({ method, url: req.url ?? "", status: res.statusCode, duration: Date.now() - start, requestId });
1545
+ logRequest({
1546
+ method: (req.method ?? "GET").toUpperCase(),
1547
+ url: req.url ?? "",
1548
+ status: res.statusCode,
1549
+ duration: Date.now() - start,
1550
+ requestId
1551
+ });
1454
1552
  }
1455
1553
  function createAgentMiddleware(vite, projectRoot, csrfMode = "strict") {
1456
1554
  const loadModule = createViteLoader(vite);
1457
1555
  return (req, res, next) => {
1458
1556
  void (async () => {
1459
1557
  const url = req.url ?? "";
1460
- const cardAgentName = isAgentCardPath(url.split("?")[0]);
1461
- if (cardAgentName) {
1462
- await serveAgentCard(req, res, next, cardAgentName, { projectRoot, loadModule });
1558
+ if (isAgentCardPath(url.split("?")[0]) !== null) {
1559
+ await serveAux(req, res, next, url.split("?")[0], { projectRoot, loadModule });
1463
1560
  return;
1464
1561
  }
1465
1562
  if (!url.startsWith(PREFIX2)) {
@@ -1474,13 +1571,8 @@ function createAgentMiddleware(vite, projectRoot, csrfMode = "strict") {
1474
1571
  await serveApprove(req, res, urlPath, csrfMode, { requestId, start });
1475
1572
  return;
1476
1573
  }
1477
- if (isListApprovalsPath(urlPath)) {
1478
- await serveListApprovals(req, res, next, { requestId, start });
1479
- return;
1480
- }
1481
- const mcpAgentName = isMcpPath(urlPath);
1482
- if (mcpAgentName) {
1483
- await serveMcp(req, res, next, mcpAgentName, { projectRoot, loadModule });
1574
+ if (isListApprovalsPath(urlPath) !== null || isMcpPath(urlPath) !== null) {
1575
+ await serveAux(req, res, next, urlPath, { projectRoot, loadModule });
1484
1576
  return;
1485
1577
  }
1486
1578
  const agent = scanAgents(projectRoot).find((a) => a.agentPath === urlPath);
@@ -3073,4 +3165,4 @@ export {
3073
3165
  theoPluginAsync,
3074
3166
  theoPlugin
3075
3167
  };
3076
- //# sourceMappingURL=chunk-3HLO7KAK.js.map
3168
+ //# sourceMappingURL=chunk-DEO2VAJE.js.map