theokit 0.15.2 → 0.16.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.
- package/dist/{agent-MN7XGJR3.js → agent-BBK42EPJ.js} +3 -3
- package/dist/{agents-typed-client-SAWAAH7K.js → agents-typed-client-D3LXWGCF.js} +6 -4
- package/dist/agents-typed-client-D3LXWGCF.js.map +1 -0
- package/dist/{agents-typed-client-UTEQUA63.js → agents-typed-client-LQ36PCHL.js} +6 -4
- package/dist/agents-typed-client-LQ36PCHL.js.map +1 -0
- package/dist/{build-QDAFSKKW.js → build-LZ4QSZ63.js} +2 -2
- package/dist/{chunk-UOR6JTCI.js → chunk-3HLO7KAK.js} +235 -40
- package/dist/chunk-3HLO7KAK.js.map +1 -0
- package/dist/{chunk-ZJDKAD3L.js → chunk-7HBLJ5BU.js} +217 -37
- package/dist/chunk-7HBLJ5BU.js.map +1 -0
- package/dist/{chunk-KGFNWIMS.js → chunk-AXVP326H.js} +3 -3
- package/dist/chunk-AXVP326H.js.map +1 -0
- package/dist/{chunk-NBWB4S46.js → chunk-FIZXWL73.js} +11 -2
- package/dist/{chunk-NBWB4S46.js.map → chunk-FIZXWL73.js.map} +1 -1
- package/dist/{chunk-OTFIRP6S.js → chunk-Q6KPASBB.js} +12 -4
- package/dist/chunk-Q6KPASBB.js.map +1 -0
- package/dist/cli/index.js +4 -4
- package/dist/client/index.d.ts +8 -1
- package/dist/client/index.js.map +1 -1
- package/dist/{dev-TEE4T6ZB.js → dev-P4GENSZK.js} +4 -4
- package/dist/index.js +1 -1
- package/dist/server/define/index.d.ts +14 -3
- package/dist/server/define/index.js +1 -1
- package/dist/server/index.js +1 -1
- package/dist/{start-7MQEEQH4.js → start-4VPYN2OS.js} +3 -3
- package/dist/vite-plugin/index.js +1 -1
- package/dist/{vite-plugin-GC6WCU4P.js → vite-plugin-23BBKL3F.js} +4 -4
- package/package.json +3 -2
- package/dist/agents-typed-client-SAWAAH7K.js.map +0 -1
- package/dist/agents-typed-client-UTEQUA63.js.map +0 -1
- package/dist/chunk-KGFNWIMS.js.map +0 -1
- package/dist/chunk-OTFIRP6S.js.map +0 -1
- package/dist/chunk-UOR6JTCI.js.map +0 -1
- package/dist/chunk-ZJDKAD3L.js.map +0 -1
- /package/dist/{agent-MN7XGJR3.js.map → agent-BBK42EPJ.js.map} +0 -0
- /package/dist/{build-QDAFSKKW.js.map → build-LZ4QSZ63.js.map} +0 -0
- /package/dist/{dev-TEE4T6ZB.js.map → dev-P4GENSZK.js.map} +0 -0
- /package/dist/{start-7MQEEQH4.js.map → start-4VPYN2OS.js.map} +0 -0
- /package/dist/{vite-plugin-GC6WCU4P.js.map → vite-plugin-23BBKL3F.js.map} +0 -0
|
@@ -7,11 +7,11 @@ import {
|
|
|
7
7
|
mountAgent,
|
|
8
8
|
resolveTransformer,
|
|
9
9
|
writeWebResponseToServerResponse
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-Q6KPASBB.js";
|
|
11
11
|
import {
|
|
12
12
|
getApprovalRegistry,
|
|
13
13
|
resolveProvider
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-FIZXWL73.js";
|
|
15
15
|
import {
|
|
16
16
|
isRouteFile,
|
|
17
17
|
scanRoutes
|
|
@@ -392,12 +392,215 @@ 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
|
+
var MCP_PATH = /^\/api\/agents\/([^/]+)\/mcp$/;
|
|
460
|
+
function isMcpPath(urlPath) {
|
|
461
|
+
const match = MCP_PATH.exec(urlPath);
|
|
462
|
+
return match ? decodeURIComponent(match[1]) : null;
|
|
463
|
+
}
|
|
464
|
+
function isJsonRpcRequest(body) {
|
|
465
|
+
return typeof body === "object" && body !== null && body.jsonrpc === "2.0" && typeof body.method === "string";
|
|
466
|
+
}
|
|
467
|
+
function jsonResponse(payload) {
|
|
468
|
+
return new Response(JSON.stringify(payload), {
|
|
469
|
+
status: 200,
|
|
470
|
+
headers: { "content-type": "application/json; charset=utf-8" }
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
function toEntry(name, mod) {
|
|
474
|
+
const compiled = compileAgentModule2(mod, `mcp server for "${name}"`);
|
|
475
|
+
return {
|
|
476
|
+
name,
|
|
477
|
+
route: `/api/agents/${name}`,
|
|
478
|
+
stream: compiled.stream,
|
|
479
|
+
mainLoop: { method: "", strategy: "" },
|
|
480
|
+
guards: [],
|
|
481
|
+
interceptors: [],
|
|
482
|
+
tools: compiled.tools.map((t) => ({
|
|
483
|
+
name: t.name,
|
|
484
|
+
description: t.description,
|
|
485
|
+
approval: false,
|
|
486
|
+
trace: false,
|
|
487
|
+
audit: false
|
|
488
|
+
})),
|
|
489
|
+
subAgents: []
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
function handleMcpJsonRpc(mod, name, body) {
|
|
493
|
+
if (!isJsonRpcRequest(body)) {
|
|
494
|
+
return jsonResponse({ jsonrpc: "2.0", id: null, error: { code: -32600, message: "Invalid Request" } });
|
|
495
|
+
}
|
|
496
|
+
const { id, method } = body;
|
|
497
|
+
try {
|
|
498
|
+
const entry = toEntry(name, mod);
|
|
499
|
+
if (method === "initialize") {
|
|
500
|
+
const info = mcpServerInfo(entry);
|
|
501
|
+
return jsonResponse({
|
|
502
|
+
jsonrpc: "2.0",
|
|
503
|
+
id,
|
|
504
|
+
result: {
|
|
505
|
+
protocolVersion: info.protocolVersion,
|
|
506
|
+
capabilities: { tools: {} },
|
|
507
|
+
serverInfo: { name: info.name, version: info.version }
|
|
508
|
+
}
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
if (method === "tools/list") {
|
|
512
|
+
return jsonResponse({ jsonrpc: "2.0", id, result: { tools: buildMcpToolDescriptors(entry) } });
|
|
513
|
+
}
|
|
514
|
+
return jsonResponse({ jsonrpc: "2.0", id, error: { code: -32601, message: `Method not found: ${method}` } });
|
|
515
|
+
} catch (err) {
|
|
516
|
+
return jsonResponse({
|
|
517
|
+
jsonrpc: "2.0",
|
|
518
|
+
id,
|
|
519
|
+
error: { code: -32603, message: err instanceof Error ? err.message : "Internal error" }
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
// src/vite-plugin/agent-middleware.ts
|
|
395
525
|
var PREFIX2 = "/api/agents/";
|
|
526
|
+
async function serveApprove(req, res, urlPath, csrfMode, log) {
|
|
527
|
+
const method = (req.method ?? "POST").toUpperCase();
|
|
528
|
+
if (method !== "POST") {
|
|
529
|
+
sendError(res, "METHOD_NOT_ALLOWED", "Approve endpoints accept POST", 405, void 0, log.requestId);
|
|
530
|
+
logRequest({ method, url: req.url ?? "", status: 405, duration: Date.now() - log.start, requestId: log.requestId });
|
|
531
|
+
return;
|
|
532
|
+
}
|
|
533
|
+
try {
|
|
534
|
+
const response = await handleAgentApproval(incomingMessageToWebRequest(req), urlPath, getApprovalRegistry(), csrfMode);
|
|
535
|
+
await writeWebResponseToServerResponse(response, res);
|
|
536
|
+
} catch (err) {
|
|
537
|
+
sendError(res, "INTERNAL", err instanceof Error ? err.message : "Approve handler failed", 500, void 0, log.requestId);
|
|
538
|
+
}
|
|
539
|
+
logRequest({ method, url: req.url ?? "", status: res.statusCode, duration: Date.now() - log.start, requestId: log.requestId });
|
|
540
|
+
}
|
|
541
|
+
async function serveMcp(req, res, next, mcpAgentName, deps) {
|
|
542
|
+
const requestId = randomUUID2();
|
|
543
|
+
const start = Date.now();
|
|
544
|
+
res.setHeader("x-request-id", requestId);
|
|
545
|
+
const method = (req.method ?? "POST").toUpperCase();
|
|
546
|
+
const agent = scanAgents(deps.projectRoot).find((a) => a.name === mcpAgentName);
|
|
547
|
+
if (method !== "POST" || !agent) {
|
|
548
|
+
next();
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
try {
|
|
552
|
+
const body = await incomingMessageToWebRequest(req).json();
|
|
553
|
+
const mod = await deps.loadModule(agent.filePath);
|
|
554
|
+
await writeWebResponseToServerResponse(handleMcpJsonRpc(mod, agent.name, body), res);
|
|
555
|
+
} catch (err) {
|
|
556
|
+
sendError(res, "INTERNAL", err instanceof Error ? err.message : "MCP handler failed", 500, void 0, requestId);
|
|
557
|
+
}
|
|
558
|
+
logRequest({ method, url: req.url ?? "", status: res.statusCode, duration: Date.now() - start, requestId });
|
|
559
|
+
}
|
|
560
|
+
async function serveListApprovals(req, res, next, log) {
|
|
561
|
+
const method = (req.method ?? "GET").toUpperCase();
|
|
562
|
+
if (method !== "GET") {
|
|
563
|
+
next();
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
await writeWebResponseToServerResponse(handleListApprovals(getApprovalRegistry()), res);
|
|
567
|
+
logRequest({
|
|
568
|
+
method,
|
|
569
|
+
url: req.url ?? "",
|
|
570
|
+
status: res.statusCode,
|
|
571
|
+
duration: Date.now() - log.start,
|
|
572
|
+
requestId: log.requestId
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
async function serveAgentCard(req, res, next, cardAgentName, deps) {
|
|
576
|
+
const requestId = randomUUID2();
|
|
577
|
+
const start = Date.now();
|
|
578
|
+
res.setHeader("x-request-id", requestId);
|
|
579
|
+
const method = (req.method ?? "GET").toUpperCase();
|
|
580
|
+
const agent = scanAgents(deps.projectRoot).find((a) => a.name === cardAgentName);
|
|
581
|
+
if (method !== "GET" || !agent) {
|
|
582
|
+
next();
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
try {
|
|
586
|
+
const mod = await deps.loadModule(agent.filePath);
|
|
587
|
+
const baseUrl = `http://${req.headers.host ?? "localhost"}`;
|
|
588
|
+
await writeWebResponseToServerResponse(handleAgentCard(mod, agent.name, agent.agentPath, baseUrl), res);
|
|
589
|
+
} catch (err) {
|
|
590
|
+
sendError(res, "INTERNAL", err instanceof Error ? err.message : "Agent card failed", 500, void 0, requestId);
|
|
591
|
+
}
|
|
592
|
+
logRequest({ method, url: req.url ?? "", status: res.statusCode, duration: Date.now() - start, requestId });
|
|
593
|
+
}
|
|
396
594
|
function createAgentMiddleware(vite, projectRoot, csrfMode = "strict") {
|
|
397
595
|
const loadModule = createViteLoader(vite);
|
|
398
596
|
return (req, res, next) => {
|
|
399
597
|
void (async () => {
|
|
400
598
|
const url = req.url ?? "";
|
|
599
|
+
const cardAgentName = isAgentCardPath(url.split("?")[0]);
|
|
600
|
+
if (cardAgentName) {
|
|
601
|
+
await serveAgentCard(req, res, next, cardAgentName, { projectRoot, loadModule });
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
401
604
|
if (!url.startsWith(PREFIX2)) {
|
|
402
605
|
next();
|
|
403
606
|
return;
|
|
@@ -407,39 +610,16 @@ function createAgentMiddleware(vite, projectRoot, csrfMode = "strict") {
|
|
|
407
610
|
res.setHeader("x-request-id", requestId);
|
|
408
611
|
const urlPath = url.split("?")[0];
|
|
409
612
|
if (isApprovalPath(urlPath)) {
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
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 });
|
|
613
|
+
await serveApprove(req, res, urlPath, csrfMode, { requestId, start });
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
if (isListApprovalsPath(urlPath)) {
|
|
617
|
+
await serveListApprovals(req, res, next, { requestId, start });
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
const mcpAgentName = isMcpPath(urlPath);
|
|
621
|
+
if (mcpAgentName) {
|
|
622
|
+
await serveMcp(req, res, next, mcpAgentName, { projectRoot, loadModule });
|
|
443
623
|
return;
|
|
444
624
|
}
|
|
445
625
|
const agent = scanAgents(projectRoot).find((a) => a.agentPath === urlPath);
|
|
@@ -1853,7 +2033,7 @@ async function theoPluginAsync(rootOrOptions) {
|
|
|
1853
2033
|
serverDir: resolve7(projectRoot, "server"),
|
|
1854
2034
|
distDir: resolve7(projectRoot, ".theokit")
|
|
1855
2035
|
});
|
|
1856
|
-
const { agentsTypedClientPlugin } = await import("./agents-typed-client-
|
|
2036
|
+
const { agentsTypedClientPlugin } = await import("./agents-typed-client-LQ36PCHL.js");
|
|
1857
2037
|
const { generateManifest } = await import("./internal-api-J27TYE2I.js");
|
|
1858
2038
|
const agentsClientPlugin = agentsTypedClientPlugin({
|
|
1859
2039
|
projectRoot,
|
|
@@ -2024,4 +2204,4 @@ export {
|
|
|
2024
2204
|
theoPluginAsync,
|
|
2025
2205
|
theoPlugin
|
|
2026
2206
|
};
|
|
2027
|
-
//# sourceMappingURL=chunk-
|
|
2207
|
+
//# sourceMappingURL=chunk-7HBLJ5BU.js.map
|