theokit 0.17.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 (30) hide show
  1. package/dist/{agent-7DBAK65H.js → agent-TZ5JZUJ7.js} +2 -2
  2. package/dist/{build-MTI4RAI3.js → build-5PSDDMFB.js} +2 -2
  3. package/dist/{chunk-4FOPDXKT.js → chunk-CC5WOQUV.js} +68 -240
  4. package/dist/chunk-CC5WOQUV.js.map +1 -0
  5. package/dist/{chunk-X6COGWHN.js → chunk-DEO2VAJE.js} +96 -57
  6. package/dist/chunk-DEO2VAJE.js.map +1 -0
  7. package/dist/{chunk-4JDYVNSY.js → chunk-XVFMSNDE.js} +229 -3
  8. package/dist/chunk-XVFMSNDE.js.map +1 -0
  9. package/dist/{chunk-3FNZG6Q3.js → chunk-XWS4RZCE.js} +12 -1
  10. package/dist/chunk-XWS4RZCE.js.map +1 -0
  11. package/dist/cli/index.js +4 -4
  12. package/dist/{dev-SVHKR2VR.js → dev-A7NESJ7S.js} +3 -3
  13. package/dist/index.js +2 -2
  14. package/dist/server/index.d.ts +9 -1
  15. package/dist/server/index.js +3 -1
  16. package/dist/server/index.js.map +1 -1
  17. package/dist/{start-SDZTFJNQ.js → start-WGOKQEUW.js} +30 -6
  18. package/dist/start-WGOKQEUW.js.map +1 -0
  19. package/dist/vite-plugin/index.js +2 -2
  20. package/dist/{vite-plugin-ZZYTMWZY.js → vite-plugin-DBS2USI4.js} +3 -3
  21. package/package.json +1 -1
  22. package/dist/chunk-3FNZG6Q3.js.map +0 -1
  23. package/dist/chunk-4FOPDXKT.js.map +0 -1
  24. package/dist/chunk-4JDYVNSY.js.map +0 -1
  25. package/dist/chunk-X6COGWHN.js.map +0 -1
  26. package/dist/start-SDZTFJNQ.js.map +0 -1
  27. /package/dist/{agent-7DBAK65H.js.map → agent-TZ5JZUJ7.js.map} +0 -0
  28. /package/dist/{build-MTI4RAI3.js.map → build-5PSDDMFB.js.map} +0 -0
  29. /package/dist/{dev-SVHKR2VR.js.map → dev-A7NESJ7S.js.map} +0 -0
  30. /package/dist/{vite-plugin-ZZYTMWZY.js.map → vite-plugin-DBS2USI4.js.map} +0 -0
@@ -7,10 +7,11 @@ import {
7
7
  } from "./chunk-7BIM27LV.js";
8
8
  import {
9
9
  buildResourceDescriptors,
10
+ extractAppResources,
10
11
  loadEnv,
11
12
  readAppResource,
12
13
  resolveTransformer
13
- } from "./chunk-3FNZG6Q3.js";
14
+ } from "./chunk-XWS4RZCE.js";
14
15
  import {
15
16
  findSuggestion
16
17
  } from "./chunk-5QW7IQQU.js";
@@ -1371,6 +1372,37 @@ function resolveProvider() {
1371
1372
  );
1372
1373
  }
1373
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
+
1374
1406
  // src/server/http/node-web-adapter.ts
1375
1407
  import { Readable } from "stream";
1376
1408
  function incomingMessageToWebRequest(req) {
@@ -1440,44 +1472,41 @@ var PREFIX2 = "/api/agents/";
1440
1472
  async function serveApprove(req, res, urlPath, csrfMode, log) {
1441
1473
  const method = (req.method ?? "POST").toUpperCase();
1442
1474
  if (method !== "POST") {
1443
- sendError(res, "METHOD_NOT_ALLOWED", "Approve endpoints accept POST", 405, void 0, log.requestId);
1444
- 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
+ });
1445
1490
  return;
1446
1491
  }
1447
1492
  try {
1448
- const response = await handleAgentApproval(incomingMessageToWebRequest(req), urlPath, getApprovalRegistry(), csrfMode);
1493
+ const response = await handleAgentApproval(
1494
+ incomingMessageToWebRequest(req),
1495
+ urlPath,
1496
+ getApprovalRegistry(),
1497
+ csrfMode
1498
+ );
1449
1499
  await writeWebResponseToServerResponse(response, res);
1450
1500
  } catch (err) {
1451
- sendError(res, "INTERNAL", err instanceof Error ? err.message : "Approve handler failed", 500, void 0, log.requestId);
1452
- }
1453
- logRequest({ method, url: req.url ?? "", status: res.statusCode, duration: Date.now() - log.start, requestId: log.requestId });
1454
- }
1455
- async function serveMcp(req, res, next, mcpAgentName, deps) {
1456
- const requestId = randomUUID2();
1457
- const start = Date.now();
1458
- res.setHeader("x-request-id", requestId);
1459
- const method = (req.method ?? "POST").toUpperCase();
1460
- const agent = scanAgents(deps.projectRoot).find((a) => a.name === mcpAgentName);
1461
- if (method !== "POST" || !agent) {
1462
- next();
1463
- return;
1464
- }
1465
- try {
1466
- const body = await incomingMessageToWebRequest(req).json();
1467
- const mod = await deps.loadModule(agent.filePath);
1468
- await writeWebResponseToServerResponse(handleMcpJsonRpc(mod, agent.name, body), res);
1469
- } catch (err) {
1470
- sendError(res, "INTERNAL", err instanceof Error ? err.message : "MCP handler failed", 500, void 0, requestId);
1471
- }
1472
- logRequest({ method, url: req.url ?? "", status: res.statusCode, duration: Date.now() - start, requestId });
1473
- }
1474
- async function serveListApprovals(req, res, next, log) {
1475
- const method = (req.method ?? "GET").toUpperCase();
1476
- if (method !== "GET") {
1477
- next();
1478
- 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
+ );
1479
1509
  }
1480
- await writeWebResponseToServerResponse(handleListApprovals(getApprovalRegistry()), res);
1481
1510
  logRequest({
1482
1511
  method,
1483
1512
  url: req.url ?? "",
@@ -1486,33 +1515,48 @@ async function serveListApprovals(req, res, next, log) {
1486
1515
  requestId: log.requestId
1487
1516
  });
1488
1517
  }
1489
- async function serveAgentCard(req, res, next, cardAgentName, deps) {
1518
+ async function serveAux(req, res, next, urlPath, deps) {
1490
1519
  const requestId = randomUUID2();
1491
1520
  const start = Date.now();
1492
- res.setHeader("x-request-id", requestId);
1493
- const method = (req.method ?? "GET").toUpperCase();
1494
- const agent = scanAgents(deps.projectRoot).find((a) => a.name === cardAgentName);
1495
- if (method !== "GET" || !agent) {
1496
- next();
1497
- return;
1498
- }
1499
1521
  try {
1500
- const mod = await deps.loadModule(agent.filePath);
1501
- const baseUrl = `http://${req.headers.host ?? "localhost"}`;
1502
- 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);
1503
1534
  } catch (err) {
1504
- 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
+ );
1505
1544
  }
1506
- 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
+ });
1507
1552
  }
1508
1553
  function createAgentMiddleware(vite, projectRoot, csrfMode = "strict") {
1509
1554
  const loadModule = createViteLoader(vite);
1510
1555
  return (req, res, next) => {
1511
1556
  void (async () => {
1512
1557
  const url = req.url ?? "";
1513
- const cardAgentName = isAgentCardPath(url.split("?")[0]);
1514
- if (cardAgentName) {
1515
- 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 });
1516
1560
  return;
1517
1561
  }
1518
1562
  if (!url.startsWith(PREFIX2)) {
@@ -1527,13 +1571,8 @@ function createAgentMiddleware(vite, projectRoot, csrfMode = "strict") {
1527
1571
  await serveApprove(req, res, urlPath, csrfMode, { requestId, start });
1528
1572
  return;
1529
1573
  }
1530
- if (isListApprovalsPath(urlPath)) {
1531
- await serveListApprovals(req, res, next, { requestId, start });
1532
- return;
1533
- }
1534
- const mcpAgentName = isMcpPath(urlPath);
1535
- if (mcpAgentName) {
1536
- 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 });
1537
1576
  return;
1538
1577
  }
1539
1578
  const agent = scanAgents(projectRoot).find((a) => a.agentPath === urlPath);
@@ -3126,4 +3165,4 @@ export {
3126
3165
  theoPluginAsync,
3127
3166
  theoPlugin
3128
3167
  };
3129
- //# sourceMappingURL=chunk-X6COGWHN.js.map
3168
+ //# sourceMappingURL=chunk-DEO2VAJE.js.map