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
@@ -178,7 +178,7 @@ async function agentCommand(name, message, deps = {}) {
178
178
  async function createAgentSsrLoader(projectRoot) {
179
179
  const { createServer } = await import("vite");
180
180
  const react = (await import("@vitejs/plugin-react")).default;
181
- const { theoPluginAsync } = await import("./vite-plugin-ZZYTMWZY.js");
181
+ const { theoPluginAsync } = await import("./vite-plugin-DBS2USI4.js");
182
182
  const { loadConfig } = await import("./load-config-JKYO5RFK.js");
183
183
  const config = await loadConfig(projectRoot);
184
184
  const theoPlugins = await theoPluginAsync({
@@ -206,4 +206,4 @@ async function createAgentSsrLoader(projectRoot) {
206
206
  export {
207
207
  agentCommand
208
208
  };
209
- //# sourceMappingURL=agent-7DBAK65H.js.map
209
+ //# sourceMappingURL=agent-TZ5JZUJ7.js.map
@@ -531,7 +531,7 @@ async function buildCommand(options) {
531
531
  `);
532
532
  }
533
533
  async function runAdapterBuild(target, config, cwd) {
534
- const { theoPluginAsync } = await import("./vite-plugin-ZZYTMWZY.js");
534
+ const { theoPluginAsync } = await import("./vite-plugin-DBS2USI4.js");
535
535
  const { default: react } = await import("@vitejs/plugin-react");
536
536
  const ctx = {
537
537
  // `react()` may return Plugin or Plugin[] depending on version; spread the
@@ -606,4 +606,4 @@ function relativize3(absPath, root) {
606
606
  export {
607
607
  buildCommand
608
608
  };
609
- //# sourceMappingURL=build-MTI4RAI3.js.map
609
+ //# sourceMappingURL=build-5PSDDMFB.js.map
@@ -3,11 +3,15 @@ import "tsx/esm";
3
3
  import {
4
4
  handleAgentApproval,
5
5
  incomingMessageToWebRequest,
6
+ isAgentCardPath,
6
7
  isApprovalPath,
8
+ isListApprovalsPath,
9
+ isMcpPath,
7
10
  mountAgent,
8
11
  resolveTransformer,
12
+ serveAgentAuxRoute,
9
13
  writeWebResponseToServerResponse
10
- } from "./chunk-4JDYVNSY.js";
14
+ } from "./chunk-XVFMSNDE.js";
11
15
  import {
12
16
  getApprovalRegistry,
13
17
  resolveProvider
@@ -392,231 +396,45 @@ function createActionMiddleware(vite, serverDir, options) {
392
396
 
393
397
  // src/vite-plugin/agent-middleware.ts
394
398
  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
578
399
  var PREFIX2 = "/api/agents/";
579
400
  async function serveApprove(req, res, urlPath, csrfMode, log) {
580
401
  const method = (req.method ?? "POST").toUpperCase();
581
402
  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 });
403
+ sendError(
404
+ res,
405
+ "METHOD_NOT_ALLOWED",
406
+ "Approve endpoints accept POST",
407
+ 405,
408
+ void 0,
409
+ log.requestId
410
+ );
411
+ logRequest({
412
+ method,
413
+ url: req.url ?? "",
414
+ status: 405,
415
+ duration: Date.now() - log.start,
416
+ requestId: log.requestId
417
+ });
584
418
  return;
585
419
  }
586
420
  try {
587
- const response = await handleAgentApproval(incomingMessageToWebRequest(req), urlPath, getApprovalRegistry(), csrfMode);
421
+ const response = await handleAgentApproval(
422
+ incomingMessageToWebRequest(req),
423
+ urlPath,
424
+ getApprovalRegistry(),
425
+ csrfMode
426
+ );
588
427
  await writeWebResponseToServerResponse(response, res);
589
428
  } 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;
429
+ sendError(
430
+ res,
431
+ "INTERNAL",
432
+ err instanceof Error ? err.message : "Approve handler failed",
433
+ 500,
434
+ void 0,
435
+ log.requestId
436
+ );
618
437
  }
619
- await writeWebResponseToServerResponse(handleListApprovals(getApprovalRegistry()), res);
620
438
  logRequest({
621
439
  method,
622
440
  url: req.url ?? "",
@@ -625,33 +443,48 @@ async function serveListApprovals(req, res, next, log) {
625
443
  requestId: log.requestId
626
444
  });
627
445
  }
628
- async function serveAgentCard(req, res, next, cardAgentName, deps) {
446
+ async function serveAux(req, res, next, urlPath, deps) {
629
447
  const requestId = randomUUID2();
630
448
  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
449
  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);
450
+ const request = incomingMessageToWebRequest(req);
451
+ const response = await serveAgentAuxRoute(request, urlPath, {
452
+ agents: scanAgents(deps.projectRoot),
453
+ loadModule: deps.loadModule,
454
+ baseUrl: `http://${req.headers.host ?? "localhost"}`
455
+ });
456
+ if (response === null) {
457
+ next();
458
+ return;
459
+ }
460
+ res.setHeader("x-request-id", requestId);
461
+ await writeWebResponseToServerResponse(response, res);
642
462
  } catch (err) {
643
- sendError(res, "INTERNAL", err instanceof Error ? err.message : "Agent card failed", 500, void 0, requestId);
463
+ res.setHeader("x-request-id", requestId);
464
+ sendError(
465
+ res,
466
+ "INTERNAL",
467
+ err instanceof Error ? err.message : "Agent aux handler failed",
468
+ 500,
469
+ void 0,
470
+ requestId
471
+ );
644
472
  }
645
- logRequest({ method, url: req.url ?? "", status: res.statusCode, duration: Date.now() - start, requestId });
473
+ logRequest({
474
+ method: (req.method ?? "GET").toUpperCase(),
475
+ url: req.url ?? "",
476
+ status: res.statusCode,
477
+ duration: Date.now() - start,
478
+ requestId
479
+ });
646
480
  }
647
481
  function createAgentMiddleware(vite, projectRoot, csrfMode = "strict") {
648
482
  const loadModule = createViteLoader(vite);
649
483
  return (req, res, next) => {
650
484
  void (async () => {
651
485
  const url = req.url ?? "";
652
- const cardAgentName = isAgentCardPath(url.split("?")[0]);
653
- if (cardAgentName) {
654
- await serveAgentCard(req, res, next, cardAgentName, { projectRoot, loadModule });
486
+ if (isAgentCardPath(url.split("?")[0]) !== null) {
487
+ await serveAux(req, res, next, url.split("?")[0], { projectRoot, loadModule });
655
488
  return;
656
489
  }
657
490
  if (!url.startsWith(PREFIX2)) {
@@ -666,13 +499,8 @@ function createAgentMiddleware(vite, projectRoot, csrfMode = "strict") {
666
499
  await serveApprove(req, res, urlPath, csrfMode, { requestId, start });
667
500
  return;
668
501
  }
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 });
502
+ if (isListApprovalsPath(urlPath) !== null || isMcpPath(urlPath) !== null) {
503
+ await serveAux(req, res, next, urlPath, { projectRoot, loadModule });
676
504
  return;
677
505
  }
678
506
  const agent = scanAgents(projectRoot).find((a) => a.agentPath === urlPath);
@@ -2257,4 +2085,4 @@ export {
2257
2085
  theoPluginAsync,
2258
2086
  theoPlugin
2259
2087
  };
2260
- //# sourceMappingURL=chunk-4FOPDXKT.js.map
2088
+ //# sourceMappingURL=chunk-CC5WOQUV.js.map