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
@@ -6,9 +6,11 @@ import {
6
6
  broadcastToDevtools
7
7
  } from "./chunk-7BIM27LV.js";
8
8
  import {
9
+ buildResourceDescriptors,
9
10
  loadEnv,
11
+ readAppResource,
10
12
  resolveTransformer
11
- } from "./chunk-5UUOGAJH.js";
13
+ } from "./chunk-3FNZG6Q3.js";
12
14
  import {
13
15
  findSuggestion
14
16
  } from "./chunk-5QW7IQQU.js";
@@ -984,6 +986,50 @@ function createActionMiddleware(vite, serverDir, options) {
984
986
  // src/vite-plugin/agent-middleware.ts
985
987
  import { randomUUID as randomUUID2 } from "crypto";
986
988
 
989
+ // src/server/agent/agent-card-handler.ts
990
+ import {
991
+ buildAgentCard,
992
+ compileAgentModule
993
+ } from "@theokit/agents";
994
+ var WELL_KNOWN = /^\/\.well-known\/([^/]+)\/agent-card\.json$/;
995
+ function isAgentCardPath(urlPath) {
996
+ const match = WELL_KNOWN.exec(urlPath);
997
+ return match ? decodeURIComponent(match[1]) : null;
998
+ }
999
+ function toManifestEntry(name, route, mod) {
1000
+ const compiled = compileAgentModule(mod, `agent card for "${name}"`);
1001
+ return {
1002
+ name,
1003
+ route,
1004
+ stream: compiled.stream,
1005
+ mainLoop: { method: "", strategy: "" },
1006
+ guards: [],
1007
+ interceptors: [],
1008
+ tools: compiled.tools.map((t) => ({
1009
+ name: t.name,
1010
+ description: t.description,
1011
+ approval: false,
1012
+ trace: false,
1013
+ audit: false
1014
+ })),
1015
+ subAgents: []
1016
+ };
1017
+ }
1018
+ function handleAgentCard(mod, name, route, baseUrl) {
1019
+ try {
1020
+ const card = buildAgentCard(toManifestEntry(name, route, mod), { baseUrl });
1021
+ return new Response(JSON.stringify(card), {
1022
+ status: 200,
1023
+ headers: { "content-type": "application/json; charset=utf-8" }
1024
+ });
1025
+ } catch (err) {
1026
+ return new Response(
1027
+ JSON.stringify({ error: { code: "AGENT_CARD_FAILED", message: err instanceof Error ? err.message : "card build failed" } }),
1028
+ { status: 500, headers: { "content-type": "application/json; charset=utf-8" } }
1029
+ );
1030
+ }
1031
+ }
1032
+
987
1033
  // src/server/agent/approval-registry.ts
988
1034
  var serverRegistry;
989
1035
  function getApprovalRegistry() {
@@ -995,24 +1041,34 @@ function createInProcessApprovalRegistry() {
995
1041
  return {
996
1042
  register(approvalId, opts) {
997
1043
  return new Promise((resolve10) => {
998
- const settle = (approved) => {
1044
+ const settle = (decision) => {
999
1045
  const entry = pending.get(approvalId);
1000
1046
  if (!entry) return;
1001
1047
  clearTimeout(entry.timer);
1002
1048
  pending.delete(approvalId);
1003
- resolve10(approved);
1049
+ resolve10(decision);
1004
1050
  };
1005
1051
  const timer = setTimeout(() => {
1006
- settle(opts.onTimeout === "proceed");
1052
+ settle({ approved: opts.onTimeout === "proceed" });
1007
1053
  }, opts.timeoutMs);
1008
- pending.set(approvalId, { settle, timer });
1054
+ const info = {
1055
+ approvalId,
1056
+ toolName: opts.toolName,
1057
+ question: opts.question,
1058
+ expiresAt: Date.now() + opts.timeoutMs,
1059
+ ...opts.payloadSchema !== void 0 ? { payloadSchema: opts.payloadSchema } : {}
1060
+ };
1061
+ pending.set(approvalId, { settle, timer, info });
1009
1062
  });
1010
1063
  },
1011
- resolve(approvalId, approved) {
1064
+ resolve(approvalId, decision) {
1012
1065
  const entry = pending.get(approvalId);
1013
1066
  if (!entry) return false;
1014
- entry.settle(approved);
1067
+ entry.settle(typeof decision === "boolean" ? { approved: decision } : decision);
1015
1068
  return true;
1069
+ },
1070
+ list() {
1071
+ return [...pending.values()].map((p) => p.info);
1016
1072
  }
1017
1073
  };
1018
1074
  }
@@ -1034,10 +1090,22 @@ function jsonError(status, code, message) {
1034
1090
  headers: { "content-type": "application/json" }
1035
1091
  });
1036
1092
  }
1093
+ var MAX_PAYLOAD_BYTES = 16 * 1024;
1037
1094
  function parseApprovalBody(body) {
1038
1095
  if (typeof body !== "object" || body === null) return null;
1039
1096
  const b = body;
1040
- return typeof b.approved === "boolean" ? { approved: b.approved } : null;
1097
+ if (typeof b.approved !== "boolean") return null;
1098
+ const decision = { approved: b.approved };
1099
+ if (b.reason !== void 0) {
1100
+ if (typeof b.reason !== "string") return null;
1101
+ decision.reason = b.reason;
1102
+ }
1103
+ if (b.payload !== void 0) {
1104
+ if (typeof b.payload !== "object" || b.payload === null || Array.isArray(b.payload)) return null;
1105
+ if (JSON.stringify(b.payload).length > MAX_PAYLOAD_BYTES) return null;
1106
+ decision.payload = b.payload;
1107
+ }
1108
+ return decision;
1041
1109
  }
1042
1110
  async function handleAgentApproval(request, urlPath, registry2, csrfMode = "strict") {
1043
1111
  if (csrfMode !== "off") {
@@ -1059,7 +1127,7 @@ async function handleAgentApproval(request, urlPath, registry2, csrfMode = "stri
1059
1127
  if (parsed === null) {
1060
1128
  return jsonError(400, "BAD_REQUEST", "Request body must contain a boolean `approved`.");
1061
1129
  }
1062
- const resolved = registry2.resolve(approvalId, parsed.approved);
1130
+ const resolved = registry2.resolve(approvalId, parsed);
1063
1131
  if (!resolved) {
1064
1132
  return jsonError(404, "NOT_PENDING", `No pending approval for id '${approvalId}'.`);
1065
1133
  }
@@ -1069,9 +1137,130 @@ async function handleAgentApproval(request, urlPath, registry2, csrfMode = "stri
1069
1137
  });
1070
1138
  }
1071
1139
 
1140
+ // src/server/agent/list-approvals-handler.ts
1141
+ var LIST_PATH = /^\/api\/agents\/([^/]+)\/approvals$/;
1142
+ function isListApprovalsPath(urlPath) {
1143
+ const match = LIST_PATH.exec(urlPath);
1144
+ return match ? decodeURIComponent(match[1]) : null;
1145
+ }
1146
+ function handleListApprovals(registry2) {
1147
+ return new Response(JSON.stringify({ approvals: registry2.list() }), {
1148
+ status: 200,
1149
+ headers: { "content-type": "application/json; charset=utf-8" }
1150
+ });
1151
+ }
1152
+
1153
+ // src/server/agent/mcp-handler.ts
1154
+ import {
1155
+ buildMcpToolDescriptors,
1156
+ compileAgentModule as compileAgentModule2,
1157
+ mcpServerInfo
1158
+ } from "@theokit/agents";
1159
+ var MCP_PATH = /^\/api\/agents\/([^/]+)\/mcp$/;
1160
+ function isMcpPath(urlPath) {
1161
+ const match = MCP_PATH.exec(urlPath);
1162
+ return match ? decodeURIComponent(match[1]) : null;
1163
+ }
1164
+ function isJsonRpcRequest(body) {
1165
+ return typeof body === "object" && body !== null && body.jsonrpc === "2.0" && typeof body.method === "string";
1166
+ }
1167
+ function jsonResponse(payload) {
1168
+ return new Response(JSON.stringify(payload), {
1169
+ status: 200,
1170
+ headers: { "content-type": "application/json; charset=utf-8" }
1171
+ });
1172
+ }
1173
+ function toEntry(name, mod) {
1174
+ const compiled = compileAgentModule2(mod, `mcp server for "${name}"`);
1175
+ return {
1176
+ name,
1177
+ route: `/api/agents/${name}`,
1178
+ stream: compiled.stream,
1179
+ mainLoop: { method: "", strategy: "" },
1180
+ guards: [],
1181
+ interceptors: [],
1182
+ tools: compiled.tools.map((t) => ({
1183
+ name: t.name,
1184
+ description: t.description,
1185
+ approval: false,
1186
+ trace: false,
1187
+ audit: false
1188
+ })),
1189
+ subAgents: []
1190
+ };
1191
+ }
1192
+ function handleMcpJsonRpc(mod, name, body, appResources = []) {
1193
+ if (!isJsonRpcRequest(body)) {
1194
+ return jsonResponse({
1195
+ jsonrpc: "2.0",
1196
+ id: null,
1197
+ error: { code: -32600, message: "Invalid Request" }
1198
+ });
1199
+ }
1200
+ const { id, method, params } = body;
1201
+ try {
1202
+ const entry = toEntry(name, mod);
1203
+ if (method === "initialize") {
1204
+ const info = mcpServerInfo(entry);
1205
+ const capabilities = { tools: {} };
1206
+ if (appResources.length > 0) capabilities.resources = {};
1207
+ return jsonResponse({
1208
+ jsonrpc: "2.0",
1209
+ id,
1210
+ result: {
1211
+ protocolVersion: info.protocolVersion,
1212
+ capabilities,
1213
+ serverInfo: { name: info.name, version: info.version }
1214
+ }
1215
+ });
1216
+ }
1217
+ if (method === "tools/list") {
1218
+ return jsonResponse({ jsonrpc: "2.0", id, result: { tools: buildMcpToolDescriptors(entry) } });
1219
+ }
1220
+ if (method === "resources/list") {
1221
+ return jsonResponse({
1222
+ jsonrpc: "2.0",
1223
+ id,
1224
+ result: { resources: buildResourceDescriptors(appResources) }
1225
+ });
1226
+ }
1227
+ if (method === "resources/read") {
1228
+ const uri = params?.uri;
1229
+ if (typeof uri !== "string") {
1230
+ return jsonResponse({
1231
+ jsonrpc: "2.0",
1232
+ id,
1233
+ error: { code: -32602, message: "resources/read requires a string `uri` param." }
1234
+ });
1235
+ }
1236
+ const contents = readAppResource(appResources, uri);
1237
+ if (contents === null) {
1238
+ return jsonResponse({
1239
+ jsonrpc: "2.0",
1240
+ id,
1241
+ error: { code: -32602, message: `Resource not found: ${uri}` }
1242
+ });
1243
+ }
1244
+ return jsonResponse({ jsonrpc: "2.0", id, result: contents });
1245
+ }
1246
+ return jsonResponse({
1247
+ jsonrpc: "2.0",
1248
+ id,
1249
+ error: { code: -32601, message: `Method not found: ${method}` }
1250
+ });
1251
+ } catch (err) {
1252
+ return jsonResponse({
1253
+ jsonrpc: "2.0",
1254
+ id,
1255
+ error: { code: -32603, message: err instanceof Error ? err.message : "Internal error" }
1256
+ });
1257
+ }
1258
+ }
1259
+
1072
1260
  // src/server/agent/mount-agent.ts
1073
1261
  import {
1074
- compileAgentModule,
1262
+ compileAgentModule as compileAgentModule3,
1263
+ resolveEnabledSkills,
1075
1264
  streamAgentUIMessages
1076
1265
  } from "@theokit/agents";
1077
1266
  function partText(part) {
@@ -1109,7 +1298,11 @@ async function mountAgent(mod, request, apiKey, source = "agent module", csrfMod
1109
1298
  return jsonError2(403, "CSRF_FAILED", `CSRF check failed: ${csrf.reason}`);
1110
1299
  }
1111
1300
  }
1112
- const compiled = compileAgentModule(mod, source);
1301
+ const compiled = compileAgentModule3(mod, source);
1302
+ if (compiled.skillsResolver) {
1303
+ const enabled = await resolveEnabledSkills(compiled.skillsResolver, compiled.runContext ?? {});
1304
+ if (enabled !== void 0) compiled.skills = { enabled, autoInject: true };
1305
+ }
1113
1306
  let body = null;
1114
1307
  try {
1115
1308
  body = await request.json();
@@ -1123,9 +1316,14 @@ async function mountAgent(mod, request, apiKey, source = "agent module", csrfMod
1123
1316
  const registry2 = getApprovalRegistry();
1124
1317
  const hitl = gated && gated.size > 0 ? {
1125
1318
  gated,
1126
- awaitApproval: (approvalId, opts) => registry2.register(approvalId, {
1319
+ awaitApproval: (approvalId, opts, toolName) => registry2.register(approvalId, {
1127
1320
  timeoutMs: opts.timeout ?? 3e5,
1128
- onTimeout: opts.onTimeout ?? "abort"
1321
+ onTimeout: opts.onTimeout ?? "abort",
1322
+ // M14 — surface toolName + question in GET /approvals (the plugin forwards c.name).
1323
+ toolName,
1324
+ question: opts.question,
1325
+ // M20 — carry the declared custom-payload schema into GET /approvals.
1326
+ ...opts.payloadSchema !== void 0 ? { payloadSchema: opts.payloadSchema } : {}
1129
1327
  })
1130
1328
  } : void 0;
1131
1329
  return uiMessageStreamResponse(
@@ -1239,11 +1437,84 @@ function pickHeaderString(value) {
1239
1437
 
1240
1438
  // src/vite-plugin/agent-middleware.ts
1241
1439
  var PREFIX2 = "/api/agents/";
1440
+ async function serveApprove(req, res, urlPath, csrfMode, log) {
1441
+ const method = (req.method ?? "POST").toUpperCase();
1442
+ 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 });
1445
+ return;
1446
+ }
1447
+ try {
1448
+ const response = await handleAgentApproval(incomingMessageToWebRequest(req), urlPath, getApprovalRegistry(), csrfMode);
1449
+ await writeWebResponseToServerResponse(response, res);
1450
+ } 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;
1479
+ }
1480
+ await writeWebResponseToServerResponse(handleListApprovals(getApprovalRegistry()), res);
1481
+ logRequest({
1482
+ method,
1483
+ url: req.url ?? "",
1484
+ status: res.statusCode,
1485
+ duration: Date.now() - log.start,
1486
+ requestId: log.requestId
1487
+ });
1488
+ }
1489
+ async function serveAgentCard(req, res, next, cardAgentName, deps) {
1490
+ const requestId = randomUUID2();
1491
+ 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
+ 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);
1503
+ } catch (err) {
1504
+ sendError(res, "INTERNAL", err instanceof Error ? err.message : "Agent card failed", 500, void 0, requestId);
1505
+ }
1506
+ logRequest({ method, url: req.url ?? "", status: res.statusCode, duration: Date.now() - start, requestId });
1507
+ }
1242
1508
  function createAgentMiddleware(vite, projectRoot, csrfMode = "strict") {
1243
1509
  const loadModule = createViteLoader(vite);
1244
1510
  return (req, res, next) => {
1245
1511
  void (async () => {
1246
1512
  const url = req.url ?? "";
1513
+ const cardAgentName = isAgentCardPath(url.split("?")[0]);
1514
+ if (cardAgentName) {
1515
+ await serveAgentCard(req, res, next, cardAgentName, { projectRoot, loadModule });
1516
+ return;
1517
+ }
1247
1518
  if (!url.startsWith(PREFIX2)) {
1248
1519
  next();
1249
1520
  return;
@@ -1253,39 +1524,16 @@ function createAgentMiddleware(vite, projectRoot, csrfMode = "strict") {
1253
1524
  res.setHeader("x-request-id", requestId);
1254
1525
  const urlPath = url.split("?")[0];
1255
1526
  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 });
1527
+ await serveApprove(req, res, urlPath, csrfMode, { requestId, start });
1528
+ return;
1529
+ }
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 });
1289
1537
  return;
1290
1538
  }
1291
1539
  const agent = scanAgents(projectRoot).find((a) => a.agentPath === urlPath);
@@ -2699,7 +2947,7 @@ async function theoPluginAsync(rootOrOptions) {
2699
2947
  serverDir: resolve9(projectRoot, "server"),
2700
2948
  distDir: resolve9(projectRoot, ".theokit")
2701
2949
  });
2702
- const { agentsTypedClientPlugin } = await import("./agents-typed-client-SAWAAH7K.js");
2950
+ const { agentsTypedClientPlugin } = await import("./agents-typed-client-D3LXWGCF.js");
2703
2951
  const { generateManifest } = await import("./internal-api-5BDI6N5U.js");
2704
2952
  const agentsClientPlugin = agentsTypedClientPlugin({
2705
2953
  projectRoot,
@@ -2878,4 +3126,4 @@ export {
2878
3126
  theoPluginAsync,
2879
3127
  theoPlugin
2880
3128
  };
2881
- //# sourceMappingURL=chunk-UOR6JTCI.js.map
3129
+ //# sourceMappingURL=chunk-X6COGWHN.js.map