theokit 0.17.0 → 0.19.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-Y4W4X46A.js +15 -0
- package/dist/{build-MTI4RAI3.js → build-ESXLJKYY.js} +2 -2
- package/dist/{chunk-X6COGWHN.js → chunk-7NTXG7SI.js} +100 -168
- package/dist/chunk-7NTXG7SI.js.map +1 -0
- package/dist/chunk-DMC6HYUR.js +141 -0
- package/dist/chunk-DMC6HYUR.js.map +1 -0
- package/dist/{chunk-4JDYVNSY.js → chunk-DXF64KS5.js} +99 -3
- package/dist/chunk-DXF64KS5.js.map +1 -0
- package/dist/{chunk-4FOPDXKT.js → chunk-ULFNEG27.js} +70 -240
- package/dist/chunk-ULFNEG27.js.map +1 -0
- package/dist/{chunk-3FNZG6Q3.js → chunk-W4YO6S4I.js} +121 -1
- package/dist/chunk-W4YO6S4I.js.map +1 -0
- package/dist/{agent-7DBAK65H.js → chunk-ZYMFKYLM.js} +5 -4
- package/dist/{agent-7DBAK65H.js.map → chunk-ZYMFKYLM.js.map} +1 -1
- package/dist/cli/index.js +16 -4
- package/dist/cli/index.js.map +1 -1
- package/dist/{dev-SVHKR2VR.js → dev-D7PKQUL2.js} +4 -3
- package/dist/{dev-SVHKR2VR.js.map → dev-D7PKQUL2.js.map} +1 -1
- package/dist/index.js +2 -2
- package/dist/mcp-3C4CMHP4.js +77 -0
- package/dist/mcp-3C4CMHP4.js.map +1 -0
- package/dist/server/index.d.ts +39 -1
- package/dist/server/index.js +32 -1
- package/dist/server/index.js.map +1 -1
- package/dist/{start-SDZTFJNQ.js → start-5UDUXYKC.js} +31 -6
- package/dist/start-5UDUXYKC.js.map +1 -0
- package/dist/vite-plugin/index.js +2 -2
- package/dist/{vite-plugin-ZZYTMWZY.js → vite-plugin-GXRWNESN.js} +4 -3
- package/dist/vite-plugin-GXRWNESN.js.map +1 -0
- package/package.json +1 -1
- package/dist/chunk-3FNZG6Q3.js.map +0 -1
- package/dist/chunk-4FOPDXKT.js.map +0 -1
- package/dist/chunk-4JDYVNSY.js.map +0 -1
- package/dist/chunk-X6COGWHN.js.map +0 -1
- package/dist/start-SDZTFJNQ.js.map +0 -1
- /package/dist/{vite-plugin-ZZYTMWZY.js.map → agent-Y4W4X46A.js.map} +0 -0
- /package/dist/{build-MTI4RAI3.js.map → build-ESXLJKYY.js.map} +0 -0
|
@@ -3,11 +3,17 @@ import "tsx/esm";
|
|
|
3
3
|
import {
|
|
4
4
|
handleAgentApproval,
|
|
5
5
|
incomingMessageToWebRequest,
|
|
6
|
+
isAgentCardPath,
|
|
6
7
|
isApprovalPath,
|
|
8
|
+
isListApprovalsPath,
|
|
7
9
|
mountAgent,
|
|
8
10
|
resolveTransformer,
|
|
11
|
+
serveAgentAuxRoute,
|
|
9
12
|
writeWebResponseToServerResponse
|
|
10
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-DXF64KS5.js";
|
|
14
|
+
import {
|
|
15
|
+
isMcpPath
|
|
16
|
+
} from "./chunk-DMC6HYUR.js";
|
|
11
17
|
import {
|
|
12
18
|
getApprovalRegistry,
|
|
13
19
|
resolveProvider
|
|
@@ -392,231 +398,45 @@ function createActionMiddleware(vite, serverDir, options) {
|
|
|
392
398
|
|
|
393
399
|
// src/vite-plugin/agent-middleware.ts
|
|
394
400
|
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
401
|
var PREFIX2 = "/api/agents/";
|
|
579
402
|
async function serveApprove(req, res, urlPath, csrfMode, log) {
|
|
580
403
|
const method = (req.method ?? "POST").toUpperCase();
|
|
581
404
|
if (method !== "POST") {
|
|
582
|
-
sendError(
|
|
583
|
-
|
|
405
|
+
sendError(
|
|
406
|
+
res,
|
|
407
|
+
"METHOD_NOT_ALLOWED",
|
|
408
|
+
"Approve endpoints accept POST",
|
|
409
|
+
405,
|
|
410
|
+
void 0,
|
|
411
|
+
log.requestId
|
|
412
|
+
);
|
|
413
|
+
logRequest({
|
|
414
|
+
method,
|
|
415
|
+
url: req.url ?? "",
|
|
416
|
+
status: 405,
|
|
417
|
+
duration: Date.now() - log.start,
|
|
418
|
+
requestId: log.requestId
|
|
419
|
+
});
|
|
584
420
|
return;
|
|
585
421
|
}
|
|
586
422
|
try {
|
|
587
|
-
const response = await handleAgentApproval(
|
|
423
|
+
const response = await handleAgentApproval(
|
|
424
|
+
incomingMessageToWebRequest(req),
|
|
425
|
+
urlPath,
|
|
426
|
+
getApprovalRegistry(),
|
|
427
|
+
csrfMode
|
|
428
|
+
);
|
|
588
429
|
await writeWebResponseToServerResponse(response, res);
|
|
589
430
|
} catch (err) {
|
|
590
|
-
sendError(
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
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;
|
|
431
|
+
sendError(
|
|
432
|
+
res,
|
|
433
|
+
"INTERNAL",
|
|
434
|
+
err instanceof Error ? err.message : "Approve handler failed",
|
|
435
|
+
500,
|
|
436
|
+
void 0,
|
|
437
|
+
log.requestId
|
|
438
|
+
);
|
|
618
439
|
}
|
|
619
|
-
await writeWebResponseToServerResponse(handleListApprovals(getApprovalRegistry()), res);
|
|
620
440
|
logRequest({
|
|
621
441
|
method,
|
|
622
442
|
url: req.url ?? "",
|
|
@@ -625,33 +445,48 @@ async function serveListApprovals(req, res, next, log) {
|
|
|
625
445
|
requestId: log.requestId
|
|
626
446
|
});
|
|
627
447
|
}
|
|
628
|
-
async function
|
|
448
|
+
async function serveAux(req, res, next, urlPath, deps) {
|
|
629
449
|
const requestId = randomUUID2();
|
|
630
450
|
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
451
|
try {
|
|
639
|
-
const
|
|
640
|
-
const
|
|
641
|
-
|
|
452
|
+
const request = incomingMessageToWebRequest(req);
|
|
453
|
+
const response = await serveAgentAuxRoute(request, urlPath, {
|
|
454
|
+
agents: scanAgents(deps.projectRoot),
|
|
455
|
+
loadModule: deps.loadModule,
|
|
456
|
+
baseUrl: `http://${req.headers.host ?? "localhost"}`
|
|
457
|
+
});
|
|
458
|
+
if (response === null) {
|
|
459
|
+
next();
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
res.setHeader("x-request-id", requestId);
|
|
463
|
+
await writeWebResponseToServerResponse(response, res);
|
|
642
464
|
} catch (err) {
|
|
643
|
-
|
|
465
|
+
res.setHeader("x-request-id", requestId);
|
|
466
|
+
sendError(
|
|
467
|
+
res,
|
|
468
|
+
"INTERNAL",
|
|
469
|
+
err instanceof Error ? err.message : "Agent aux handler failed",
|
|
470
|
+
500,
|
|
471
|
+
void 0,
|
|
472
|
+
requestId
|
|
473
|
+
);
|
|
644
474
|
}
|
|
645
|
-
logRequest({
|
|
475
|
+
logRequest({
|
|
476
|
+
method: (req.method ?? "GET").toUpperCase(),
|
|
477
|
+
url: req.url ?? "",
|
|
478
|
+
status: res.statusCode,
|
|
479
|
+
duration: Date.now() - start,
|
|
480
|
+
requestId
|
|
481
|
+
});
|
|
646
482
|
}
|
|
647
483
|
function createAgentMiddleware(vite, projectRoot, csrfMode = "strict") {
|
|
648
484
|
const loadModule = createViteLoader(vite);
|
|
649
485
|
return (req, res, next) => {
|
|
650
486
|
void (async () => {
|
|
651
487
|
const url = req.url ?? "";
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
await serveAgentCard(req, res, next, cardAgentName, { projectRoot, loadModule });
|
|
488
|
+
if (isAgentCardPath(url.split("?")[0]) !== null) {
|
|
489
|
+
await serveAux(req, res, next, url.split("?")[0], { projectRoot, loadModule });
|
|
655
490
|
return;
|
|
656
491
|
}
|
|
657
492
|
if (!url.startsWith(PREFIX2)) {
|
|
@@ -666,13 +501,8 @@ function createAgentMiddleware(vite, projectRoot, csrfMode = "strict") {
|
|
|
666
501
|
await serveApprove(req, res, urlPath, csrfMode, { requestId, start });
|
|
667
502
|
return;
|
|
668
503
|
}
|
|
669
|
-
if (isListApprovalsPath(urlPath)) {
|
|
670
|
-
await
|
|
671
|
-
return;
|
|
672
|
-
}
|
|
673
|
-
const mcpAgentName = isMcpPath(urlPath);
|
|
674
|
-
if (mcpAgentName) {
|
|
675
|
-
await serveMcp(req, res, next, mcpAgentName, { projectRoot, loadModule });
|
|
504
|
+
if (isListApprovalsPath(urlPath) !== null || isMcpPath(urlPath) !== null) {
|
|
505
|
+
await serveAux(req, res, next, urlPath, { projectRoot, loadModule });
|
|
676
506
|
return;
|
|
677
507
|
}
|
|
678
508
|
const agent = scanAgents(projectRoot).find((a) => a.agentPath === urlPath);
|
|
@@ -2257,4 +2087,4 @@ export {
|
|
|
2257
2087
|
theoPluginAsync,
|
|
2258
2088
|
theoPlugin
|
|
2259
2089
|
};
|
|
2260
|
-
//# sourceMappingURL=chunk-
|
|
2090
|
+
//# sourceMappingURL=chunk-ULFNEG27.js.map
|