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
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import "tsx/esm";
|
|
3
|
+
import {
|
|
4
|
+
agentCommand,
|
|
5
|
+
createAgentSsrLoader
|
|
6
|
+
} from "./chunk-ZYMFKYLM.js";
|
|
7
|
+
import "./chunk-M6NMS5LR.js";
|
|
8
|
+
import "./chunk-GDN3PXFH.js";
|
|
9
|
+
import "./chunk-34YQOXGM.js";
|
|
10
|
+
import "./chunk-P37RZRFV.js";
|
|
11
|
+
export {
|
|
12
|
+
agentCommand,
|
|
13
|
+
createAgentSsrLoader
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=agent-Y4W4X46A.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-
|
|
534
|
+
const { theoPluginAsync } = await import("./vite-plugin-GXRWNESN.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-
|
|
609
|
+
//# sourceMappingURL=build-ESXLJKYY.js.map
|
|
@@ -6,11 +6,12 @@ import {
|
|
|
6
6
|
broadcastToDevtools
|
|
7
7
|
} from "./chunk-7BIM27LV.js";
|
|
8
8
|
import {
|
|
9
|
-
|
|
9
|
+
extractAppResources,
|
|
10
|
+
handleMcpJsonRpc,
|
|
11
|
+
isMcpPath,
|
|
10
12
|
loadEnv,
|
|
11
|
-
readAppResource,
|
|
12
13
|
resolveTransformer
|
|
13
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-W4YO6S4I.js";
|
|
14
15
|
import {
|
|
15
16
|
findSuggestion
|
|
16
17
|
} from "./chunk-5QW7IQQU.js";
|
|
@@ -1150,116 +1151,9 @@ function handleListApprovals(registry2) {
|
|
|
1150
1151
|
});
|
|
1151
1152
|
}
|
|
1152
1153
|
|
|
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
|
-
|
|
1260
1154
|
// src/server/agent/mount-agent.ts
|
|
1261
1155
|
import {
|
|
1262
|
-
compileAgentModule as
|
|
1156
|
+
compileAgentModule as compileAgentModule2,
|
|
1263
1157
|
resolveEnabledSkills,
|
|
1264
1158
|
streamAgentUIMessages
|
|
1265
1159
|
} from "@theokit/agents";
|
|
@@ -1298,7 +1192,7 @@ async function mountAgent(mod, request, apiKey, source = "agent module", csrfMod
|
|
|
1298
1192
|
return jsonError2(403, "CSRF_FAILED", `CSRF check failed: ${csrf.reason}`);
|
|
1299
1193
|
}
|
|
1300
1194
|
}
|
|
1301
|
-
const compiled =
|
|
1195
|
+
const compiled = compileAgentModule2(mod, source);
|
|
1302
1196
|
if (compiled.skillsResolver) {
|
|
1303
1197
|
const enabled = await resolveEnabledSkills(compiled.skillsResolver, compiled.runContext ?? {});
|
|
1304
1198
|
if (enabled !== void 0) compiled.skills = { enabled, autoInject: true };
|
|
@@ -1371,6 +1265,37 @@ function resolveProvider() {
|
|
|
1371
1265
|
);
|
|
1372
1266
|
}
|
|
1373
1267
|
|
|
1268
|
+
// src/server/agent/serve-aux-routes.ts
|
|
1269
|
+
async function serveAgentAuxRoute(request, urlPath, deps) {
|
|
1270
|
+
const method = request.method.toUpperCase();
|
|
1271
|
+
const cardName = isAgentCardPath(urlPath);
|
|
1272
|
+
if (cardName !== null) {
|
|
1273
|
+
if (method !== "GET") return null;
|
|
1274
|
+
const agent = deps.agents.find((a) => a.name === cardName);
|
|
1275
|
+
if (!agent) return null;
|
|
1276
|
+
const mod = await deps.loadModule(agent.filePath);
|
|
1277
|
+
return handleAgentCard(mod, agent.name, agent.agentPath, deps.baseUrl);
|
|
1278
|
+
}
|
|
1279
|
+
if (isListApprovalsPath(urlPath)) {
|
|
1280
|
+
if (method !== "GET") return null;
|
|
1281
|
+
return handleListApprovals(getApprovalRegistry());
|
|
1282
|
+
}
|
|
1283
|
+
const mcpName = isMcpPath(urlPath);
|
|
1284
|
+
if (mcpName !== null) {
|
|
1285
|
+
if (method !== "POST") return null;
|
|
1286
|
+
const agent = deps.agents.find((a) => a.name === mcpName);
|
|
1287
|
+
if (!agent) return null;
|
|
1288
|
+
let body = null;
|
|
1289
|
+
try {
|
|
1290
|
+
body = await request.json();
|
|
1291
|
+
} catch {
|
|
1292
|
+
}
|
|
1293
|
+
const mod = await deps.loadModule(agent.filePath);
|
|
1294
|
+
return handleMcpJsonRpc(mod, agent.name, body, extractAppResources(mod));
|
|
1295
|
+
}
|
|
1296
|
+
return null;
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1374
1299
|
// src/server/http/node-web-adapter.ts
|
|
1375
1300
|
import { Readable } from "stream";
|
|
1376
1301
|
function incomingMessageToWebRequest(req) {
|
|
@@ -1440,44 +1365,41 @@ var PREFIX2 = "/api/agents/";
|
|
|
1440
1365
|
async function serveApprove(req, res, urlPath, csrfMode, log) {
|
|
1441
1366
|
const method = (req.method ?? "POST").toUpperCase();
|
|
1442
1367
|
if (method !== "POST") {
|
|
1443
|
-
sendError(
|
|
1444
|
-
|
|
1368
|
+
sendError(
|
|
1369
|
+
res,
|
|
1370
|
+
"METHOD_NOT_ALLOWED",
|
|
1371
|
+
"Approve endpoints accept POST",
|
|
1372
|
+
405,
|
|
1373
|
+
void 0,
|
|
1374
|
+
log.requestId
|
|
1375
|
+
);
|
|
1376
|
+
logRequest({
|
|
1377
|
+
method,
|
|
1378
|
+
url: req.url ?? "",
|
|
1379
|
+
status: 405,
|
|
1380
|
+
duration: Date.now() - log.start,
|
|
1381
|
+
requestId: log.requestId
|
|
1382
|
+
});
|
|
1445
1383
|
return;
|
|
1446
1384
|
}
|
|
1447
1385
|
try {
|
|
1448
|
-
const response = await handleAgentApproval(
|
|
1386
|
+
const response = await handleAgentApproval(
|
|
1387
|
+
incomingMessageToWebRequest(req),
|
|
1388
|
+
urlPath,
|
|
1389
|
+
getApprovalRegistry(),
|
|
1390
|
+
csrfMode
|
|
1391
|
+
);
|
|
1449
1392
|
await writeWebResponseToServerResponse(response, res);
|
|
1450
1393
|
} catch (err) {
|
|
1451
|
-
sendError(
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
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;
|
|
1394
|
+
sendError(
|
|
1395
|
+
res,
|
|
1396
|
+
"INTERNAL",
|
|
1397
|
+
err instanceof Error ? err.message : "Approve handler failed",
|
|
1398
|
+
500,
|
|
1399
|
+
void 0,
|
|
1400
|
+
log.requestId
|
|
1401
|
+
);
|
|
1479
1402
|
}
|
|
1480
|
-
await writeWebResponseToServerResponse(handleListApprovals(getApprovalRegistry()), res);
|
|
1481
1403
|
logRequest({
|
|
1482
1404
|
method,
|
|
1483
1405
|
url: req.url ?? "",
|
|
@@ -1486,33 +1408,48 @@ async function serveListApprovals(req, res, next, log) {
|
|
|
1486
1408
|
requestId: log.requestId
|
|
1487
1409
|
});
|
|
1488
1410
|
}
|
|
1489
|
-
async function
|
|
1411
|
+
async function serveAux(req, res, next, urlPath, deps) {
|
|
1490
1412
|
const requestId = randomUUID2();
|
|
1491
1413
|
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
1414
|
try {
|
|
1500
|
-
const
|
|
1501
|
-
const
|
|
1502
|
-
|
|
1415
|
+
const request = incomingMessageToWebRequest(req);
|
|
1416
|
+
const response = await serveAgentAuxRoute(request, urlPath, {
|
|
1417
|
+
agents: scanAgents(deps.projectRoot),
|
|
1418
|
+
loadModule: deps.loadModule,
|
|
1419
|
+
baseUrl: `http://${req.headers.host ?? "localhost"}`
|
|
1420
|
+
});
|
|
1421
|
+
if (response === null) {
|
|
1422
|
+
next();
|
|
1423
|
+
return;
|
|
1424
|
+
}
|
|
1425
|
+
res.setHeader("x-request-id", requestId);
|
|
1426
|
+
await writeWebResponseToServerResponse(response, res);
|
|
1503
1427
|
} catch (err) {
|
|
1504
|
-
|
|
1428
|
+
res.setHeader("x-request-id", requestId);
|
|
1429
|
+
sendError(
|
|
1430
|
+
res,
|
|
1431
|
+
"INTERNAL",
|
|
1432
|
+
err instanceof Error ? err.message : "Agent aux handler failed",
|
|
1433
|
+
500,
|
|
1434
|
+
void 0,
|
|
1435
|
+
requestId
|
|
1436
|
+
);
|
|
1505
1437
|
}
|
|
1506
|
-
logRequest({
|
|
1438
|
+
logRequest({
|
|
1439
|
+
method: (req.method ?? "GET").toUpperCase(),
|
|
1440
|
+
url: req.url ?? "",
|
|
1441
|
+
status: res.statusCode,
|
|
1442
|
+
duration: Date.now() - start,
|
|
1443
|
+
requestId
|
|
1444
|
+
});
|
|
1507
1445
|
}
|
|
1508
1446
|
function createAgentMiddleware(vite, projectRoot, csrfMode = "strict") {
|
|
1509
1447
|
const loadModule = createViteLoader(vite);
|
|
1510
1448
|
return (req, res, next) => {
|
|
1511
1449
|
void (async () => {
|
|
1512
1450
|
const url = req.url ?? "";
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
await serveAgentCard(req, res, next, cardAgentName, { projectRoot, loadModule });
|
|
1451
|
+
if (isAgentCardPath(url.split("?")[0]) !== null) {
|
|
1452
|
+
await serveAux(req, res, next, url.split("?")[0], { projectRoot, loadModule });
|
|
1516
1453
|
return;
|
|
1517
1454
|
}
|
|
1518
1455
|
if (!url.startsWith(PREFIX2)) {
|
|
@@ -1527,13 +1464,8 @@ function createAgentMiddleware(vite, projectRoot, csrfMode = "strict") {
|
|
|
1527
1464
|
await serveApprove(req, res, urlPath, csrfMode, { requestId, start });
|
|
1528
1465
|
return;
|
|
1529
1466
|
}
|
|
1530
|
-
if (isListApprovalsPath(urlPath)) {
|
|
1531
|
-
await
|
|
1532
|
-
return;
|
|
1533
|
-
}
|
|
1534
|
-
const mcpAgentName = isMcpPath(urlPath);
|
|
1535
|
-
if (mcpAgentName) {
|
|
1536
|
-
await serveMcp(req, res, next, mcpAgentName, { projectRoot, loadModule });
|
|
1467
|
+
if (isListApprovalsPath(urlPath) !== null || isMcpPath(urlPath) !== null) {
|
|
1468
|
+
await serveAux(req, res, next, urlPath, { projectRoot, loadModule });
|
|
1537
1469
|
return;
|
|
1538
1470
|
}
|
|
1539
1471
|
const agent = scanAgents(projectRoot).find((a) => a.agentPath === urlPath);
|
|
@@ -3126,4 +3058,4 @@ export {
|
|
|
3126
3058
|
theoPluginAsync,
|
|
3127
3059
|
theoPlugin
|
|
3128
3060
|
};
|
|
3129
|
-
//# sourceMappingURL=chunk-
|
|
3061
|
+
//# sourceMappingURL=chunk-7NTXG7SI.js.map
|