theokit 0.15.2 → 0.17.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 (100) hide show
  1. package/dist/actions-virtual-module-G4BANOLW.js +0 -0
  2. package/dist/add-W6FNTAFS.js +0 -0
  3. package/dist/{agent-MN7XGJR3.js → agent-7DBAK65H.js} +3 -3
  4. package/dist/{agents-typed-client-SAWAAH7K.js → agents-typed-client-D3LXWGCF.js} +6 -4
  5. package/dist/agents-typed-client-D3LXWGCF.js.map +1 -0
  6. package/dist/{agents-typed-client-UTEQUA63.js → agents-typed-client-LQ36PCHL.js} +6 -4
  7. package/dist/agents-typed-client-LQ36PCHL.js.map +1 -0
  8. package/dist/app-typed-client-Z6BHD4MF.js +0 -0
  9. package/dist/aws-lambda-7GSCNLPY.js +0 -0
  10. package/dist/body-parser-web-FV5HWCY3.js +0 -0
  11. package/dist/broadcast-LUMOJIJT.js +0 -0
  12. package/dist/{build-QDAFSKKW.js → build-MTI4RAI3.js} +2 -2
  13. package/dist/build-request-body-preview-QMWD2IXK.js +0 -0
  14. package/dist/bun-KP2KES6S.js +0 -0
  15. package/dist/check-PD2FTKMM.js +0 -0
  16. package/dist/chunk-34YQOXGM.js +0 -0
  17. package/dist/{chunk-5UUOGAJH.js → chunk-3FNZG6Q3.js} +36 -1
  18. package/dist/chunk-3FNZG6Q3.js.map +1 -0
  19. package/dist/chunk-45C3WUQ7.js +0 -0
  20. package/dist/{chunk-ZJDKAD3L.js → chunk-4FOPDXKT.js} +270 -37
  21. package/dist/chunk-4FOPDXKT.js.map +1 -0
  22. package/dist/{chunk-OTFIRP6S.js → chunk-4JDYVNSY.js} +28 -6
  23. package/dist/chunk-4JDYVNSY.js.map +1 -0
  24. package/dist/chunk-567NA7Y6.js +0 -0
  25. package/dist/chunk-5ODOE6EF.js +0 -0
  26. package/dist/{chunk-KGFNWIMS.js → chunk-CWVBDUDC.js} +18 -4
  27. package/dist/chunk-CWVBDUDC.js.map +1 -0
  28. package/dist/chunk-FOZIR3TG.js +0 -0
  29. package/dist/chunk-GBXLKYIA.js +0 -0
  30. package/dist/chunk-GDN3PXFH.js +0 -0
  31. package/dist/chunk-HGZL5EOI.js +0 -0
  32. package/dist/chunk-HNBWZKIQ.js +0 -0
  33. package/dist/chunk-IEES3CHD.js +0 -0
  34. package/dist/chunk-JAIKGP3Q.js +0 -0
  35. package/dist/chunk-JQSFBJR5.js +0 -0
  36. package/dist/chunk-KXA37ONC.js +0 -0
  37. package/dist/{chunk-NBWB4S46.js → chunk-M6NMS5LR.js} +17 -7
  38. package/dist/{chunk-NBWB4S46.js.map → chunk-M6NMS5LR.js.map} +1 -1
  39. package/dist/chunk-NXTF5PPW.js +0 -0
  40. package/dist/chunk-P37RZRFV.js +0 -0
  41. package/dist/chunk-WR4F4EEZ.js +0 -0
  42. package/dist/{chunk-UOR6JTCI.js → chunk-X6COGWHN.js} +296 -48
  43. package/dist/chunk-X6COGWHN.js.map +1 -0
  44. package/dist/chunk-YJAUJXZS.js +0 -0
  45. package/dist/cli/index.js +4 -4
  46. package/dist/client/index.d.ts +59 -2
  47. package/dist/client/index.js +43 -0
  48. package/dist/client/index.js.map +1 -1
  49. package/dist/cloudflare-C6E5SPAE.js +0 -0
  50. package/dist/configure-agent-registry-ZOBVU3MV.js +0 -0
  51. package/dist/db-3UNAMSFK.js +0 -0
  52. package/dist/deno-deploy-RFZN56X4.js +0 -0
  53. package/dist/{dev-TEE4T6ZB.js → dev-SVHKR2VR.js} +4 -4
  54. package/dist/dev-emit-VJ5CFMPY.js +0 -0
  55. package/dist/dispatcher-EJHL6JMJ.js +0 -0
  56. package/dist/docker-LZZB4D5E.js +0 -0
  57. package/dist/generate-OMKHQ7OM.js +0 -0
  58. package/dist/index.js +2 -2
  59. package/dist/info-7PE2PZJI.js +0 -0
  60. package/dist/internal-api-J27TYE2I.js +0 -0
  61. package/dist/load-config-JKYO5RFK.js +0 -0
  62. package/dist/netlify-PMLHVPN4.js +0 -0
  63. package/dist/node-BPJ3Z4DT.js +0 -0
  64. package/dist/openapi-MXMLZCXC.js +0 -0
  65. package/dist/registry-XJUYD2OU.js +0 -0
  66. package/dist/router-TLEAOFID.js +0 -0
  67. package/dist/routes-NNBEZSGN.js +0 -0
  68. package/dist/scan-7MJC6PYU.js +0 -0
  69. package/dist/schema-7CAY6IZR.js +0 -0
  70. package/dist/server/define/index.d.ts +42 -6
  71. package/dist/server/define/index.js +3 -1
  72. package/dist/server/index.d.ts +278 -4
  73. package/dist/server/index.js +232 -2
  74. package/dist/server/index.js.map +1 -1
  75. package/dist/server-error-to-envelope-UUXDSLAZ.js +0 -0
  76. package/dist/server-routes-hmr-VZXOP5YT.js +0 -0
  77. package/dist/services-json-Y3XODNB5.js +0 -0
  78. package/dist/services-typed-client-32KMTTXR.js +0 -0
  79. package/dist/{start-7MQEEQH4.js → start-SDZTFJNQ.js} +3 -3
  80. package/dist/static-7ARBVDJF.js +0 -0
  81. package/dist/storage-manager-ZSQFLEYT.js +0 -0
  82. package/dist/theo-cloud-DQRP6S6M.js +0 -0
  83. package/dist/upgrade-readiness-ACGW44JC.js +0 -0
  84. package/dist/vercel-J6G7ZHYQ.js +0 -0
  85. package/dist/vite-plugin/index.js +2 -2
  86. package/dist/{vite-plugin-GC6WCU4P.js → vite-plugin-ZZYTMWZY.js} +4 -4
  87. package/package.json +12 -11
  88. package/LICENSE +0 -201
  89. package/dist/agents-typed-client-SAWAAH7K.js.map +0 -1
  90. package/dist/agents-typed-client-UTEQUA63.js.map +0 -1
  91. package/dist/chunk-5UUOGAJH.js.map +0 -1
  92. package/dist/chunk-KGFNWIMS.js.map +0 -1
  93. package/dist/chunk-OTFIRP6S.js.map +0 -1
  94. package/dist/chunk-UOR6JTCI.js.map +0 -1
  95. package/dist/chunk-ZJDKAD3L.js.map +0 -1
  96. /package/dist/{agent-MN7XGJR3.js.map → agent-7DBAK65H.js.map} +0 -0
  97. /package/dist/{build-QDAFSKKW.js.map → build-MTI4RAI3.js.map} +0 -0
  98. /package/dist/{dev-TEE4T6ZB.js.map → dev-SVHKR2VR.js.map} +0 -0
  99. /package/dist/{start-7MQEEQH4.js.map → start-SDZTFJNQ.js.map} +0 -0
  100. /package/dist/{vite-plugin-GC6WCU4P.js.map → vite-plugin-ZZYTMWZY.js.map} +0 -0
@@ -7,11 +7,11 @@ import {
7
7
  mountAgent,
8
8
  resolveTransformer,
9
9
  writeWebResponseToServerResponse
10
- } from "./chunk-OTFIRP6S.js";
10
+ } from "./chunk-4JDYVNSY.js";
11
11
  import {
12
12
  getApprovalRegistry,
13
13
  resolveProvider
14
- } from "./chunk-NBWB4S46.js";
14
+ } from "./chunk-M6NMS5LR.js";
15
15
  import {
16
16
  isRouteFile,
17
17
  scanRoutes
@@ -392,12 +392,268 @@ function createActionMiddleware(vite, serverDir, options) {
392
392
 
393
393
  // src/vite-plugin/agent-middleware.ts
394
394
  import { randomUUID as randomUUID2 } from "crypto";
395
+
396
+ // src/server/agent/agent-card-handler.ts
397
+ import {
398
+ buildAgentCard,
399
+ compileAgentModule
400
+ } from "@theokit/agents";
401
+ var WELL_KNOWN = /^\/\.well-known\/([^/]+)\/agent-card\.json$/;
402
+ function isAgentCardPath(urlPath) {
403
+ const match = WELL_KNOWN.exec(urlPath);
404
+ return match ? decodeURIComponent(match[1]) : null;
405
+ }
406
+ function toManifestEntry(name, route, mod) {
407
+ const compiled = compileAgentModule(mod, `agent card for "${name}"`);
408
+ return {
409
+ name,
410
+ route,
411
+ stream: compiled.stream,
412
+ mainLoop: { method: "", strategy: "" },
413
+ guards: [],
414
+ interceptors: [],
415
+ tools: compiled.tools.map((t) => ({
416
+ name: t.name,
417
+ description: t.description,
418
+ approval: false,
419
+ trace: false,
420
+ audit: false
421
+ })),
422
+ subAgents: []
423
+ };
424
+ }
425
+ function handleAgentCard(mod, name, route, baseUrl) {
426
+ try {
427
+ const card = buildAgentCard(toManifestEntry(name, route, mod), { baseUrl });
428
+ return new Response(JSON.stringify(card), {
429
+ status: 200,
430
+ headers: { "content-type": "application/json; charset=utf-8" }
431
+ });
432
+ } catch (err) {
433
+ return new Response(
434
+ JSON.stringify({ error: { code: "AGENT_CARD_FAILED", message: err instanceof Error ? err.message : "card build failed" } }),
435
+ { status: 500, headers: { "content-type": "application/json; charset=utf-8" } }
436
+ );
437
+ }
438
+ }
439
+
440
+ // src/server/agent/list-approvals-handler.ts
441
+ var LIST_PATH = /^\/api\/agents\/([^/]+)\/approvals$/;
442
+ function isListApprovalsPath(urlPath) {
443
+ const match = LIST_PATH.exec(urlPath);
444
+ return match ? decodeURIComponent(match[1]) : null;
445
+ }
446
+ function handleListApprovals(registry) {
447
+ return new Response(JSON.stringify({ approvals: registry.list() }), {
448
+ status: 200,
449
+ headers: { "content-type": "application/json; charset=utf-8" }
450
+ });
451
+ }
452
+
453
+ // src/server/agent/mcp-handler.ts
454
+ import {
455
+ buildMcpToolDescriptors,
456
+ compileAgentModule as compileAgentModule2,
457
+ mcpServerInfo
458
+ } from "@theokit/agents";
459
+
460
+ // src/server/agent/mcp-app-resources.ts
461
+ function buildResourceDescriptors(resources) {
462
+ return resources.map((r) => ({
463
+ uri: r.uri,
464
+ name: r.name,
465
+ mimeType: r.mimeType,
466
+ ...r.description !== void 0 ? { description: r.description } : {}
467
+ }));
468
+ }
469
+ function readAppResource(resources, uri) {
470
+ const found = resources.find((r) => r.uri === uri);
471
+ if (!found) return null;
472
+ return { contents: [{ uri: found.uri, mimeType: "text/html", text: found.html }] };
473
+ }
474
+
475
+ // src/server/agent/mcp-handler.ts
476
+ var MCP_PATH = /^\/api\/agents\/([^/]+)\/mcp$/;
477
+ function isMcpPath(urlPath) {
478
+ const match = MCP_PATH.exec(urlPath);
479
+ return match ? decodeURIComponent(match[1]) : null;
480
+ }
481
+ function isJsonRpcRequest(body) {
482
+ return typeof body === "object" && body !== null && body.jsonrpc === "2.0" && typeof body.method === "string";
483
+ }
484
+ function jsonResponse(payload) {
485
+ return new Response(JSON.stringify(payload), {
486
+ status: 200,
487
+ headers: { "content-type": "application/json; charset=utf-8" }
488
+ });
489
+ }
490
+ function toEntry(name, mod) {
491
+ const compiled = compileAgentModule2(mod, `mcp server for "${name}"`);
492
+ return {
493
+ name,
494
+ route: `/api/agents/${name}`,
495
+ stream: compiled.stream,
496
+ mainLoop: { method: "", strategy: "" },
497
+ guards: [],
498
+ interceptors: [],
499
+ tools: compiled.tools.map((t) => ({
500
+ name: t.name,
501
+ description: t.description,
502
+ approval: false,
503
+ trace: false,
504
+ audit: false
505
+ })),
506
+ subAgents: []
507
+ };
508
+ }
509
+ function handleMcpJsonRpc(mod, name, body, appResources = []) {
510
+ if (!isJsonRpcRequest(body)) {
511
+ return jsonResponse({
512
+ jsonrpc: "2.0",
513
+ id: null,
514
+ error: { code: -32600, message: "Invalid Request" }
515
+ });
516
+ }
517
+ const { id, method, params } = body;
518
+ try {
519
+ const entry = toEntry(name, mod);
520
+ if (method === "initialize") {
521
+ const info = mcpServerInfo(entry);
522
+ const capabilities = { tools: {} };
523
+ if (appResources.length > 0) capabilities.resources = {};
524
+ return jsonResponse({
525
+ jsonrpc: "2.0",
526
+ id,
527
+ result: {
528
+ protocolVersion: info.protocolVersion,
529
+ capabilities,
530
+ serverInfo: { name: info.name, version: info.version }
531
+ }
532
+ });
533
+ }
534
+ if (method === "tools/list") {
535
+ return jsonResponse({ jsonrpc: "2.0", id, result: { tools: buildMcpToolDescriptors(entry) } });
536
+ }
537
+ if (method === "resources/list") {
538
+ return jsonResponse({
539
+ jsonrpc: "2.0",
540
+ id,
541
+ result: { resources: buildResourceDescriptors(appResources) }
542
+ });
543
+ }
544
+ if (method === "resources/read") {
545
+ const uri = params?.uri;
546
+ if (typeof uri !== "string") {
547
+ return jsonResponse({
548
+ jsonrpc: "2.0",
549
+ id,
550
+ error: { code: -32602, message: "resources/read requires a string `uri` param." }
551
+ });
552
+ }
553
+ const contents = readAppResource(appResources, uri);
554
+ if (contents === null) {
555
+ return jsonResponse({
556
+ jsonrpc: "2.0",
557
+ id,
558
+ error: { code: -32602, message: `Resource not found: ${uri}` }
559
+ });
560
+ }
561
+ return jsonResponse({ jsonrpc: "2.0", id, result: contents });
562
+ }
563
+ return jsonResponse({
564
+ jsonrpc: "2.0",
565
+ id,
566
+ error: { code: -32601, message: `Method not found: ${method}` }
567
+ });
568
+ } catch (err) {
569
+ return jsonResponse({
570
+ jsonrpc: "2.0",
571
+ id,
572
+ error: { code: -32603, message: err instanceof Error ? err.message : "Internal error" }
573
+ });
574
+ }
575
+ }
576
+
577
+ // src/vite-plugin/agent-middleware.ts
395
578
  var PREFIX2 = "/api/agents/";
579
+ async function serveApprove(req, res, urlPath, csrfMode, log) {
580
+ const method = (req.method ?? "POST").toUpperCase();
581
+ if (method !== "POST") {
582
+ sendError(res, "METHOD_NOT_ALLOWED", "Approve endpoints accept POST", 405, void 0, log.requestId);
583
+ logRequest({ method, url: req.url ?? "", status: 405, duration: Date.now() - log.start, requestId: log.requestId });
584
+ return;
585
+ }
586
+ try {
587
+ const response = await handleAgentApproval(incomingMessageToWebRequest(req), urlPath, getApprovalRegistry(), csrfMode);
588
+ await writeWebResponseToServerResponse(response, res);
589
+ } catch (err) {
590
+ sendError(res, "INTERNAL", err instanceof Error ? err.message : "Approve handler failed", 500, void 0, log.requestId);
591
+ }
592
+ logRequest({ method, url: req.url ?? "", status: res.statusCode, duration: Date.now() - log.start, requestId: log.requestId });
593
+ }
594
+ async function serveMcp(req, res, next, mcpAgentName, deps) {
595
+ const requestId = randomUUID2();
596
+ const start = Date.now();
597
+ res.setHeader("x-request-id", requestId);
598
+ const method = (req.method ?? "POST").toUpperCase();
599
+ const agent = scanAgents(deps.projectRoot).find((a) => a.name === mcpAgentName);
600
+ if (method !== "POST" || !agent) {
601
+ next();
602
+ return;
603
+ }
604
+ try {
605
+ const body = await incomingMessageToWebRequest(req).json();
606
+ const mod = await deps.loadModule(agent.filePath);
607
+ await writeWebResponseToServerResponse(handleMcpJsonRpc(mod, agent.name, body), res);
608
+ } catch (err) {
609
+ sendError(res, "INTERNAL", err instanceof Error ? err.message : "MCP handler failed", 500, void 0, requestId);
610
+ }
611
+ logRequest({ method, url: req.url ?? "", status: res.statusCode, duration: Date.now() - start, requestId });
612
+ }
613
+ async function serveListApprovals(req, res, next, log) {
614
+ const method = (req.method ?? "GET").toUpperCase();
615
+ if (method !== "GET") {
616
+ next();
617
+ return;
618
+ }
619
+ await writeWebResponseToServerResponse(handleListApprovals(getApprovalRegistry()), res);
620
+ logRequest({
621
+ method,
622
+ url: req.url ?? "",
623
+ status: res.statusCode,
624
+ duration: Date.now() - log.start,
625
+ requestId: log.requestId
626
+ });
627
+ }
628
+ async function serveAgentCard(req, res, next, cardAgentName, deps) {
629
+ const requestId = randomUUID2();
630
+ const start = Date.now();
631
+ res.setHeader("x-request-id", requestId);
632
+ const method = (req.method ?? "GET").toUpperCase();
633
+ const agent = scanAgents(deps.projectRoot).find((a) => a.name === cardAgentName);
634
+ if (method !== "GET" || !agent) {
635
+ next();
636
+ return;
637
+ }
638
+ try {
639
+ const mod = await deps.loadModule(agent.filePath);
640
+ const baseUrl = `http://${req.headers.host ?? "localhost"}`;
641
+ await writeWebResponseToServerResponse(handleAgentCard(mod, agent.name, agent.agentPath, baseUrl), res);
642
+ } catch (err) {
643
+ sendError(res, "INTERNAL", err instanceof Error ? err.message : "Agent card failed", 500, void 0, requestId);
644
+ }
645
+ logRequest({ method, url: req.url ?? "", status: res.statusCode, duration: Date.now() - start, requestId });
646
+ }
396
647
  function createAgentMiddleware(vite, projectRoot, csrfMode = "strict") {
397
648
  const loadModule = createViteLoader(vite);
398
649
  return (req, res, next) => {
399
650
  void (async () => {
400
651
  const url = req.url ?? "";
652
+ const cardAgentName = isAgentCardPath(url.split("?")[0]);
653
+ if (cardAgentName) {
654
+ await serveAgentCard(req, res, next, cardAgentName, { projectRoot, loadModule });
655
+ return;
656
+ }
401
657
  if (!url.startsWith(PREFIX2)) {
402
658
  next();
403
659
  return;
@@ -407,39 +663,16 @@ function createAgentMiddleware(vite, projectRoot, csrfMode = "strict") {
407
663
  res.setHeader("x-request-id", requestId);
408
664
  const urlPath = url.split("?")[0];
409
665
  if (isApprovalPath(urlPath)) {
410
- const method2 = (req.method ?? "POST").toUpperCase();
411
- if (method2 !== "POST") {
412
- sendError(
413
- res,
414
- "METHOD_NOT_ALLOWED",
415
- "Approve endpoints accept POST",
416
- 405,
417
- void 0,
418
- requestId
419
- );
420
- logRequest({ method: method2, url, status: 405, duration: Date.now() - start, requestId });
421
- return;
422
- }
423
- try {
424
- const request = incomingMessageToWebRequest(req);
425
- const response = await handleAgentApproval(
426
- request,
427
- urlPath,
428
- getApprovalRegistry(),
429
- csrfMode
430
- );
431
- await writeWebResponseToServerResponse(response, res);
432
- } catch (err) {
433
- sendError(
434
- res,
435
- "INTERNAL",
436
- err instanceof Error ? err.message : "Approve handler failed",
437
- 500,
438
- void 0,
439
- requestId
440
- );
441
- }
442
- logRequest({ method: method2, url, status: res.statusCode, duration: Date.now() - start, requestId });
666
+ await serveApprove(req, res, urlPath, csrfMode, { requestId, start });
667
+ return;
668
+ }
669
+ if (isListApprovalsPath(urlPath)) {
670
+ await serveListApprovals(req, res, next, { requestId, start });
671
+ return;
672
+ }
673
+ const mcpAgentName = isMcpPath(urlPath);
674
+ if (mcpAgentName) {
675
+ await serveMcp(req, res, next, mcpAgentName, { projectRoot, loadModule });
443
676
  return;
444
677
  }
445
678
  const agent = scanAgents(projectRoot).find((a) => a.agentPath === urlPath);
@@ -1853,7 +2086,7 @@ async function theoPluginAsync(rootOrOptions) {
1853
2086
  serverDir: resolve7(projectRoot, "server"),
1854
2087
  distDir: resolve7(projectRoot, ".theokit")
1855
2088
  });
1856
- const { agentsTypedClientPlugin } = await import("./agents-typed-client-UTEQUA63.js");
2089
+ const { agentsTypedClientPlugin } = await import("./agents-typed-client-LQ36PCHL.js");
1857
2090
  const { generateManifest } = await import("./internal-api-J27TYE2I.js");
1858
2091
  const agentsClientPlugin = agentsTypedClientPlugin({
1859
2092
  projectRoot,
@@ -2024,4 +2257,4 @@ export {
2024
2257
  theoPluginAsync,
2025
2258
  theoPlugin
2026
2259
  };
2027
- //# sourceMappingURL=chunk-ZJDKAD3L.js.map
2260
+ //# sourceMappingURL=chunk-4FOPDXKT.js.map