@parcha/agentrun-kernel 0.1.0-beta.37 → 0.1.0-beta.39
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/CHANGELOG.md +136 -0
- package/NOTICE +2 -0
- package/dist/booking.d.ts +25 -6
- package/dist/booking.js +15 -4
- package/dist/host/index.d.ts +4 -5
- package/dist/host/index.js +3 -3
- package/dist/host/o200k.d.ts +11 -0
- package/dist/host/o200k.js +185 -0
- package/dist/host/overhead.d.ts +105 -3
- package/dist/host/overhead.js +276 -20
- package/dist/host/proxy.d.ts +97 -16
- package/dist/host/proxy.js +420 -108
- package/dist/index.d.ts +6 -5
- package/dist/index.js +4 -3
- package/dist/kernel/cap/admit.d.ts +5 -8
- package/dist/kernel/cap/admit.js +13 -19
- package/dist/kernel/cap/free.d.ts +43 -0
- package/dist/kernel/cap/free.js +71 -0
- package/dist/kernel/cap/index.d.ts +7 -6
- package/dist/kernel/cap/index.js +6 -5
- package/dist/kernel/cap/marks.d.ts +2 -3
- package/dist/kernel/cap/park.d.ts +3 -4
- package/dist/kernel/cap/park.js +4 -5
- package/dist/kernel/cap/port.d.ts +11 -5
- package/dist/kernel/cap/port.js +26 -24
- package/dist/kernel/cap/price.d.ts +10 -30
- package/dist/kernel/cap/price.js +15 -48
- package/dist/kernel/cap/recover.d.ts +1 -2
- package/dist/kernel/cap/recover.js +2 -4
- package/dist/kernel/cap/rule.d.ts +11 -17
- package/dist/kernel/cap/rule.js +37 -19
- package/dist/kernel/cap/run-cap.d.ts +25 -10
- package/dist/kernel/cap/run-cap.js +78 -35
- package/dist/kernel/cap/types.d.ts +11 -27
- package/dist/kernel/cap/words.d.ts +13 -8
- package/dist/kernel/cap/words.js +23 -14
- package/dist/kernel/cap/wrap-up.d.ts +4 -0
- package/dist/kernel/cap/wrap-up.js +5 -1
- package/dist/kernel/registry/computer-surface.generated.d.ts +1 -1
- package/dist/kernel/registry/computer-surface.generated.js +18 -27
- package/dist/kernel/registry/computer.d.ts +14 -7
- package/dist/kernel/registry/computer.js +64 -16
- package/dist/kernel/registry/gate.d.ts +2 -2
- package/dist/kernel/registry/gate.js +4 -7
- package/dist/kernel/registry/hands.d.ts +4 -5
- package/dist/kernel/registry/index.d.ts +1 -1
- package/dist/kernel/registry/index.js +1 -1
- package/dist/kernel/registry/registry.js +6 -9
- package/dist/kernel/types.d.ts +8 -1
- package/dist/process/recovery.d.ts +4 -1
- package/dist/process/recovery.js +15 -3
- package/dist/process/resume.d.ts +5 -2
- package/dist/process/resume.js +15 -3
- package/dist/process/tools.d.ts +28 -1
- package/dist/process/tools.js +102 -5
- package/dist/run-booking.d.ts +21 -2
- package/dist/run-booking.js +215 -18
- package/dist/runner.d.ts +82 -21
- package/dist/runner.js +271 -56
- package/dist/testing.d.ts +10 -4
- package/dist/testing.js +7 -5
- package/dist/tool-deferral.d.ts +12 -0
- package/dist/tool-deferral.js +17 -0
- package/dist/types.d.ts +133 -48
- package/dist/types.js +8 -0
- package/package.json +5 -3
- package/vendor/o200k/LICENSE +61 -0
- package/vendor/o200k/o200k_base.tiktoken +199998 -0
- package/dist/host/mcp-route.d.ts +0 -14
- package/dist/host/mcp-route.js +0 -125
package/dist/host/mcp-route.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
-
import type { SessionMcp } from "../types.js";
|
|
3
|
-
/** The protocol revisions answered, newest first: a client asking for another gets the newest. */
|
|
4
|
-
export declare const MCP_ROUTE_VERSIONS: readonly string[];
|
|
5
|
-
export interface McpRouteOptions {
|
|
6
|
-
/** How often a call in flight sends a keepalive. Default 15 s. */
|
|
7
|
-
keepaliveMs?: number;
|
|
8
|
-
/** The `_meta` key of a `tools/call` that carries the harness's own id for the call (McpClient.callIdMeta); none, the
|
|
9
|
-
* call has no id. */
|
|
10
|
-
callIdMeta?: string;
|
|
11
|
-
}
|
|
12
|
-
/** The handler a model proxy mounts at `/mcp/<server>` (ModelProxyOptions.mcp). */
|
|
13
|
-
export type McpHandler = (server: string, req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
|
14
|
-
export declare function mcpRoute(mcp: SessionMcp, options?: McpRouteOptions): McpHandler;
|
package/dist/host/mcp-route.js
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { parseStrict } from "./proxy.js";
|
|
2
|
-
/** The protocol revisions answered, newest first: a client asking for another gets the newest. */
|
|
3
|
-
export const MCP_ROUTE_VERSIONS = ["2025-11-25", "2025-06-18", "2025-03-26"];
|
|
4
|
-
const MAX_BODY = 4 * 1024 * 1024;
|
|
5
|
-
const KEEPALIVE_MS = 15_000;
|
|
6
|
-
const isPlain = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
7
|
-
const isId = (v) => typeof v === "string" || (typeof v === "number" && Number.isSafeInteger(v));
|
|
8
|
-
export function mcpRoute(mcp, options = {}) {
|
|
9
|
-
const keepaliveMs = options.keepaliveMs ?? KEEPALIVE_MS;
|
|
10
|
-
const servers = new Map(mcp.servers.map((server) => [server.name, server]));
|
|
11
|
-
/** Calls in flight, by server and JSON-RPC id. */
|
|
12
|
-
const running = new Map();
|
|
13
|
-
const keyOf = (server, id) => `${server}\0${typeof id}:${id}`;
|
|
14
|
-
const json = (res, status, body) => {
|
|
15
|
-
res.writeHead(status, body === undefined ? { "content-length": "0" } : { "content-type": "application/json" });
|
|
16
|
-
res.end(body === undefined ? undefined : JSON.stringify(body));
|
|
17
|
-
};
|
|
18
|
-
const failure = (id, code, message) => ({ jsonrpc: "2.0", id, error: { code, message } });
|
|
19
|
-
return async (server, req, res) => {
|
|
20
|
-
const served = servers.get(server);
|
|
21
|
-
if (!served)
|
|
22
|
-
return json(res, 404, failure(null, -32601, `this session has no MCP server ${server}`));
|
|
23
|
-
if (req.method !== "POST") {
|
|
24
|
-
res.writeHead(405, { allow: "POST", "content-length": "0" });
|
|
25
|
-
return void res.end();
|
|
26
|
-
}
|
|
27
|
-
const chunks = [];
|
|
28
|
-
let size = 0;
|
|
29
|
-
for await (const chunk of req) {
|
|
30
|
-
size += chunk.length;
|
|
31
|
-
if (size > MAX_BODY)
|
|
32
|
-
return json(res, 413, failure(null, -32600, "the request is too large"));
|
|
33
|
-
chunks.push(chunk);
|
|
34
|
-
}
|
|
35
|
-
let message;
|
|
36
|
-
try {
|
|
37
|
-
const parsed = parseStrict(Buffer.concat(chunks).toString("utf8"));
|
|
38
|
-
if (!isPlain(parsed))
|
|
39
|
-
return json(res, 400, failure(null, -32600, "one JSON-RPC message per request; no batches"));
|
|
40
|
-
message = parsed;
|
|
41
|
-
}
|
|
42
|
-
catch {
|
|
43
|
-
return json(res, 400, failure(null, -32700, "the body is not JSON"));
|
|
44
|
-
}
|
|
45
|
-
const params = isPlain(message.params) ? message.params : {};
|
|
46
|
-
// A notification, or the client's answer to a request: nothing to say back.
|
|
47
|
-
if (typeof message.method !== "string" || message.id === undefined) {
|
|
48
|
-
if (message.method === "notifications/cancelled" && isId(params.requestId))
|
|
49
|
-
running.get(keyOf(server, params.requestId))?.abort();
|
|
50
|
-
return json(res, 202);
|
|
51
|
-
}
|
|
52
|
-
if (!isId(message.id))
|
|
53
|
-
return json(res, 400, failure(null, -32600, "the request's id must be a string or an integer"));
|
|
54
|
-
const id = message.id;
|
|
55
|
-
const answer = (result) => json(res, 200, { jsonrpc: "2.0", id, result });
|
|
56
|
-
switch (message.method) {
|
|
57
|
-
case "initialize": {
|
|
58
|
-
const asked = params.protocolVersion;
|
|
59
|
-
const protocolVersion = typeof asked === "string" && MCP_ROUTE_VERSIONS.includes(asked) ? asked : MCP_ROUTE_VERSIONS[0];
|
|
60
|
-
return answer({ protocolVersion, capabilities: { tools: {} }, serverInfo: { name: `agentrun-${server}`, version: "1.0.0" } });
|
|
61
|
-
}
|
|
62
|
-
case "ping":
|
|
63
|
-
return answer({});
|
|
64
|
-
case "tools/list":
|
|
65
|
-
return answer({ tools: served.tools.map((tool) => ({ name: tool.name, ...(tool.title ? { title: tool.title } : {}), description: tool.description ?? "", inputSchema: tool.inputSchema, ...(tool.annotations ? { annotations: tool.annotations } : {}) })) });
|
|
66
|
-
case "tools/call":
|
|
67
|
-
return call(server, id, params, req, res);
|
|
68
|
-
default:
|
|
69
|
-
return json(res, 200, failure(id, -32601, `${String(message.method).slice(0, 64)} is not a method this server answers`));
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
async function call(server, id, params, req, res) {
|
|
73
|
-
const meta = isPlain(params._meta) ? params._meta : {};
|
|
74
|
-
const progressToken = isId(meta.progressToken) ? meta.progressToken : undefined;
|
|
75
|
-
// The harness's own id for the call, under the key its adapter declared (McpClient.callIdMeta), and no other.
|
|
76
|
-
const own = options.callIdMeta !== undefined && Object.hasOwn(meta, options.callIdMeta) ? meta[options.callIdMeta] : undefined;
|
|
77
|
-
const callId = typeof own === "string" ? own : undefined;
|
|
78
|
-
const stream = String(req.headers.accept ?? "").includes("text/event-stream");
|
|
79
|
-
const controller = new AbortController();
|
|
80
|
-
const key = keyOf(server, id);
|
|
81
|
-
running.set(key, controller);
|
|
82
|
-
// A client gone before the answer: its call is aborted, upstream too.
|
|
83
|
-
res.once("close", () => { if (!res.writableFinished)
|
|
84
|
-
controller.abort(); });
|
|
85
|
-
const send = (body) => res.write(`event: message\ndata: ${JSON.stringify(body)}\n\n`);
|
|
86
|
-
let timer;
|
|
87
|
-
if (stream) {
|
|
88
|
-
res.writeHead(200, { "content-type": "text/event-stream", "cache-control": "no-cache" });
|
|
89
|
-
res.flushHeaders();
|
|
90
|
-
let beat = 0;
|
|
91
|
-
timer = setInterval(() => {
|
|
92
|
-
beat += 1;
|
|
93
|
-
if (progressToken === undefined)
|
|
94
|
-
res.write(": keepalive\n\n");
|
|
95
|
-
else
|
|
96
|
-
send({ jsonrpc: "2.0", method: "notifications/progress", params: { progressToken, progress: beat } });
|
|
97
|
-
}, keepaliveMs);
|
|
98
|
-
}
|
|
99
|
-
let result;
|
|
100
|
-
try {
|
|
101
|
-
const name = params.name;
|
|
102
|
-
const args = isPlain(params.arguments) ? params.arguments : {};
|
|
103
|
-
const granted = typeof name === "string" && servers.get(server).tools.some((tool) => tool.name === name);
|
|
104
|
-
result = granted
|
|
105
|
-
// The door calls the session's MCP (serve's gateway.call); its target is the tool plane's one invoke() (fix 2).
|
|
106
|
-
? await mcp.call(server, name, args, { signal: controller.signal, ...(callId ? { callId } : {}) })
|
|
107
|
-
: { content: [{ type: "text", text: `${String(name).slice(0, 64)} is not a tool of the MCP server ${server} in this session.` }], isError: true };
|
|
108
|
-
}
|
|
109
|
-
catch (error) {
|
|
110
|
-
result = { content: [{ type: "text", text: `The MCP server ${server}'s call failed: ${String(error?.message ?? error).slice(0, 300)}` }], isError: true };
|
|
111
|
-
}
|
|
112
|
-
finally {
|
|
113
|
-
clearInterval(timer);
|
|
114
|
-
running.delete(key);
|
|
115
|
-
}
|
|
116
|
-
if (res.destroyed)
|
|
117
|
-
return;
|
|
118
|
-
// What the client reads of the answer: its content, and whether it failed (never the host's `parked`).
|
|
119
|
-
const body = { jsonrpc: "2.0", id, result: { content: result.content, ...(result.isError ? { isError: true } : {}) } };
|
|
120
|
-
if (!stream)
|
|
121
|
-
return json(res, 200, body);
|
|
122
|
-
send(body);
|
|
123
|
-
res.end();
|
|
124
|
-
}
|
|
125
|
-
}
|