@nylorun/runtime 0.6.0-beta → 0.8.0-beta
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 +48 -0
- package/README.md +9 -5
- package/dist/adapters/sandbox/microsandbox.d.ts +2 -0
- package/dist/adapters/sandbox/microsandbox.js +238 -0
- package/dist/adapters/sandbox/virtual.d.ts +4 -0
- package/dist/adapters/sandbox/virtual.js +125 -0
- package/dist/configuration.d.ts +1 -1
- package/dist/configuration.js +1 -1
- package/dist/core/executors.d.ts +32 -0
- package/dist/core/executors.js +60 -0
- package/dist/core/main.js +7 -12
- package/dist/core/runtime.d.ts +41 -1
- package/dist/core/runtime.js +594 -53
- package/dist/core/store.d.ts +13 -0
- package/dist/core/store.js +95 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/mcp/connect.d.ts +31 -0
- package/dist/mcp/connect.js +190 -0
- package/dist/mcp/pool.d.ts +45 -0
- package/dist/mcp/pool.js +143 -0
- package/dist/mcp/snapshot.d.ts +25 -0
- package/dist/mcp/snapshot.js +10 -0
- package/dist/mcp/stdio.d.ts +15 -0
- package/dist/mcp/stdio.js +80 -0
- package/dist/model/catalog.d.ts +12 -0
- package/dist/model/catalog.js +29 -0
- package/dist/model/models.d.ts +3 -1
- package/dist/model/models.js +4 -2
- package/dist/model/pi-model.d.ts +9 -3
- package/dist/model/pi-model.js +47 -11
- package/dist/model/settings.d.ts +0 -2
- package/dist/model/settings.js +0 -47
- package/dist/node/index.d.ts +1 -1
- package/dist/node/index.js +1 -1
- package/dist/sandbox/manager.d.ts +61 -0
- package/dist/sandbox/manager.js +239 -0
- package/dist/sandbox/policy.d.ts +13 -0
- package/dist/sandbox/policy.js +67 -0
- package/dist/sandbox/select.d.ts +35 -0
- package/dist/sandbox/select.js +76 -0
- package/dist/sandbox/tools.d.ts +25 -0
- package/dist/sandbox/tools.js +165 -0
- package/dist/sandbox/types.d.ts +66 -0
- package/dist/vault/crypto.d.ts +12 -0
- package/dist/vault/crypto.js +80 -0
- package/dist/vault/error.d.ts +4 -0
- package/dist/vault/error.js +7 -0
- package/dist/vault/kek.d.ts +6 -0
- package/dist/vault/kek.js +26 -0
- package/dist/vault/service.d.ts +99 -0
- package/dist/vault/service.js +825 -0
- package/dist/vault/url.d.ts +3 -0
- package/dist/vault/url.js +27 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +3 -0
- package/package.json +12 -6
- package/dist/config.d.ts +0 -20
- package/dist/model/defaults.d.ts +0 -17
- package/dist/model/defaults.js +0 -21
- package/dist/model/http-model.d.ts +0 -12
- package/dist/model/http-model.js +0 -299
- package/dist/node/local-sessions.d.ts +0 -5
- package/dist/node/local-sessions.js +0 -174
- package/dist/server/ag-ui.d.ts +0 -8
- package/dist/server/ag-ui.js +0 -76
- package/dist/server/delivery.d.ts +0 -24
- package/dist/server/delivery.js +0 -107
- package/dist/server/digests.d.ts +0 -13
- package/dist/server/digests.js +0 -39
- package/dist/server/host.d.ts +0 -70
- package/dist/server/host.js +0 -647
- package/dist/session/api.d.ts +0 -10
- package/dist/session/api.js +0 -15
- package/dist/session/default.d.ts +0 -5
- package/dist/session/default.js +0 -30
- package/dist/session/handle.d.ts +0 -27
- package/dist/session/handle.js +0 -199
- package/dist/session/index.d.ts +0 -2
- package/dist/session/index.js +0 -2
- package/dist/sessions/host.d.ts +0 -39
- package/dist/sessions/host.js +0 -359
- package/dist/sessions/store.d.ts +0 -41
- package/dist/sessions/store.js +0 -33
- /package/dist/{config.js → sandbox/types.js} +0 -0
package/dist/server/ag-ui.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/** Minimal truthful AG-UI projection from the same canonical events Studio displays. */
|
|
2
|
-
export function agUiEvents(events, threadId, runId) {
|
|
3
|
-
const output = [
|
|
4
|
-
{ type: "RUN_STARTED", threadId, runId },
|
|
5
|
-
];
|
|
6
|
-
for (const event of events) {
|
|
7
|
-
if (event.type === "tool.sealed") {
|
|
8
|
-
const calls = Array.isArray(event.payload.attributes
|
|
9
|
-
?.executable)
|
|
10
|
-
? event.payload.attributes
|
|
11
|
-
.executable
|
|
12
|
-
: [];
|
|
13
|
-
for (const call of calls) {
|
|
14
|
-
const id = typeof call.callId === "string" ? call.callId : undefined;
|
|
15
|
-
const name = typeof call.toolName === "string" ? call.toolName : undefined;
|
|
16
|
-
if (!id || !name)
|
|
17
|
-
continue;
|
|
18
|
-
output.push({ type: "TOOL_CALL_START", toolCallId: id, toolCallName: name }, {
|
|
19
|
-
type: "TOOL_CALL_ARGS",
|
|
20
|
-
toolCallId: id,
|
|
21
|
-
delta: JSON.stringify(call.args ?? {}),
|
|
22
|
-
}, { type: "TOOL_CALL_END", toolCallId: id });
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
else if (event.type === "tool.completed" &&
|
|
26
|
-
typeof event.payload.callId === "string") {
|
|
27
|
-
output.push({
|
|
28
|
-
type: "TOOL_CALL_RESULT",
|
|
29
|
-
messageId: `nylorun-${threadId}-${event.seq}`,
|
|
30
|
-
toolCallId: event.payload.callId,
|
|
31
|
-
content: JSON.stringify(event.payload.attributes ?? {
|
|
32
|
-
outcome: event.payload.outcome ?? "completed",
|
|
33
|
-
}),
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
else if (event.type === "final" && event.payload.output !== undefined) {
|
|
37
|
-
const messageId = `nylorun-${threadId}-${event.seq}`;
|
|
38
|
-
const text = typeof event.payload.output === "string"
|
|
39
|
-
? event.payload.output
|
|
40
|
-
: JSON.stringify(event.payload.output);
|
|
41
|
-
output.push({ type: "TEXT_MESSAGE_START", messageId, role: "assistant" }, { type: "TEXT_MESSAGE_CONTENT", messageId, delta: text }, { type: "TEXT_MESSAGE_END", messageId });
|
|
42
|
-
}
|
|
43
|
-
else if (event.type === "error" || event.type === "tripwire") {
|
|
44
|
-
const tripwire = event.payload.tripwire;
|
|
45
|
-
const payload = tripwire && typeof tripwire === "object"
|
|
46
|
-
? { ...event.payload, ...tripwire }
|
|
47
|
-
: event.payload;
|
|
48
|
-
const attributes = payload.attributes;
|
|
49
|
-
const message = payload.message ??
|
|
50
|
-
(attributes && typeof attributes === "object" && "message" in attributes
|
|
51
|
-
? attributes.message
|
|
52
|
-
: undefined);
|
|
53
|
-
output.push({
|
|
54
|
-
type: "RUN_ERROR",
|
|
55
|
-
message: typeof message === "string" ? message : "Agent run failed.",
|
|
56
|
-
...(typeof payload.code === "string" ? { code: payload.code } : {}),
|
|
57
|
-
});
|
|
58
|
-
return Object.freeze(output);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
output.push({ type: "RUN_FINISHED", threadId, runId });
|
|
62
|
-
return Object.freeze(output);
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Preserve headers installed by the Hono host (notably loopback CORS) when a
|
|
66
|
-
* route returns a raw streaming Response instead of `context.json()`.
|
|
67
|
-
*/
|
|
68
|
-
export function sse(events, inherited) {
|
|
69
|
-
const headers = new Headers(inherited);
|
|
70
|
-
headers.set("content-type", "text/event-stream; charset=utf-8");
|
|
71
|
-
headers.set("cache-control", "no-cache");
|
|
72
|
-
headers.set("connection", "keep-alive");
|
|
73
|
-
return new Response(events.map((event) => `data: ${JSON.stringify(event)}\n\n`).join(""), {
|
|
74
|
-
headers,
|
|
75
|
-
});
|
|
76
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/** Bounded per-request delivery. Generation never waits for a subscriber. */
|
|
2
|
-
export declare class EventDelivery {
|
|
3
|
-
private readonly abort;
|
|
4
|
-
private readonly limits;
|
|
5
|
-
readonly response: Response;
|
|
6
|
-
private controller;
|
|
7
|
-
private readonly queue;
|
|
8
|
-
private readonly suppressed;
|
|
9
|
-
private previewBytes;
|
|
10
|
-
private readonly previewTotals;
|
|
11
|
-
private eventBytes;
|
|
12
|
-
private eventCount;
|
|
13
|
-
private ended;
|
|
14
|
-
private closed;
|
|
15
|
-
constructor(abort: () => void, limits?: {
|
|
16
|
-
previewBytes?: number;
|
|
17
|
-
eventBytes?: number;
|
|
18
|
-
eventCount?: number;
|
|
19
|
-
}, inherited?: HeadersInit);
|
|
20
|
-
private waiting;
|
|
21
|
-
private flush;
|
|
22
|
-
push(event: Record<string, unknown>, preview?: string): void;
|
|
23
|
-
end(): void;
|
|
24
|
-
}
|
package/dist/server/delivery.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
/** Bounded per-request delivery. Generation never waits for a subscriber. */
|
|
2
|
-
export class EventDelivery {
|
|
3
|
-
abort;
|
|
4
|
-
limits;
|
|
5
|
-
response;
|
|
6
|
-
controller;
|
|
7
|
-
queue = [];
|
|
8
|
-
suppressed = new Set();
|
|
9
|
-
previewBytes = 0;
|
|
10
|
-
previewTotals = new Map();
|
|
11
|
-
eventBytes = 0;
|
|
12
|
-
eventCount = 0;
|
|
13
|
-
ended = false;
|
|
14
|
-
closed = false;
|
|
15
|
-
constructor(abort, limits = {}, inherited) {
|
|
16
|
-
this.abort = abort;
|
|
17
|
-
this.limits = limits;
|
|
18
|
-
for (const value of Object.values(limits))
|
|
19
|
-
if (!Number.isSafeInteger(value) || value <= 0)
|
|
20
|
-
throw new Error("Delivery limits must be positive integers");
|
|
21
|
-
const stream = new ReadableStream({
|
|
22
|
-
start: (controller) => {
|
|
23
|
-
this.controller = controller;
|
|
24
|
-
},
|
|
25
|
-
pull: () => this.flush(),
|
|
26
|
-
cancel: () => {
|
|
27
|
-
this.closed = true;
|
|
28
|
-
this.queue.length = 0;
|
|
29
|
-
abort();
|
|
30
|
-
},
|
|
31
|
-
}, { highWaterMark: 0 });
|
|
32
|
-
const headers = new Headers(inherited);
|
|
33
|
-
headers.set("content-type", "text/event-stream; charset=utf-8");
|
|
34
|
-
headers.set("cache-control", "no-cache");
|
|
35
|
-
this.response = new Response(stream, { headers });
|
|
36
|
-
}
|
|
37
|
-
waiting = false;
|
|
38
|
-
flush() {
|
|
39
|
-
if (this.closed)
|
|
40
|
-
return;
|
|
41
|
-
const item = this.queue.shift();
|
|
42
|
-
if (item) {
|
|
43
|
-
this.waiting = false;
|
|
44
|
-
if (item.preview)
|
|
45
|
-
this.previewBytes -= item.bytes.byteLength;
|
|
46
|
-
else {
|
|
47
|
-
this.eventBytes -= item.bytes.byteLength;
|
|
48
|
-
this.eventCount--;
|
|
49
|
-
}
|
|
50
|
-
this.controller.enqueue(item.bytes);
|
|
51
|
-
}
|
|
52
|
-
else if (this.ended) {
|
|
53
|
-
this.closed = true;
|
|
54
|
-
this.controller.close();
|
|
55
|
-
}
|
|
56
|
-
else
|
|
57
|
-
this.waiting = true;
|
|
58
|
-
}
|
|
59
|
-
push(event, preview) {
|
|
60
|
-
if (this.closed || this.ended || (preview && this.suppressed.has(preview)))
|
|
61
|
-
return;
|
|
62
|
-
const bytes = new TextEncoder().encode(`data: ${JSON.stringify(event)}\n\n`);
|
|
63
|
-
if (preview &&
|
|
64
|
-
Math.max(this.previewBytes, this.previewTotals.get(preview) ?? 0) +
|
|
65
|
-
bytes.byteLength >
|
|
66
|
-
(this.limits.previewBytes ?? 64 * 1024)) {
|
|
67
|
-
this.suppressed.add(preview);
|
|
68
|
-
for (let i = this.queue.length - 1; i >= 0; i--)
|
|
69
|
-
if (this.queue[i].preview === preview) {
|
|
70
|
-
this.previewBytes -= this.queue[i].bytes.byteLength;
|
|
71
|
-
this.queue.splice(i, 1);
|
|
72
|
-
}
|
|
73
|
-
this.push({
|
|
74
|
-
type: "CUSTOM",
|
|
75
|
-
name: "nylorun.preview.incomplete",
|
|
76
|
-
value: { invocationId: preview },
|
|
77
|
-
});
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
if (!preview &&
|
|
81
|
-
(this.eventCount + 1 > (this.limits.eventCount ?? 256) ||
|
|
82
|
-
this.eventBytes + bytes.byteLength >
|
|
83
|
-
(this.limits.eventBytes ?? 1024 * 1024))) {
|
|
84
|
-
this.closed = true;
|
|
85
|
-
this.queue.length = 0;
|
|
86
|
-
this.controller.error(new Error("Subscriber exceeded execution-event delivery limits"));
|
|
87
|
-
this.abort();
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
this.queue.push({ bytes, ...(preview ? { preview } : {}) });
|
|
91
|
-
if (preview) {
|
|
92
|
-
this.previewBytes += bytes.byteLength;
|
|
93
|
-
this.previewTotals.set(preview, (this.previewTotals.get(preview) ?? 0) + bytes.byteLength);
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
this.eventBytes += bytes.byteLength;
|
|
97
|
-
this.eventCount++;
|
|
98
|
-
}
|
|
99
|
-
if (this.waiting)
|
|
100
|
-
this.flush();
|
|
101
|
-
}
|
|
102
|
-
end() {
|
|
103
|
-
this.ended = true;
|
|
104
|
-
if (this.waiting)
|
|
105
|
-
this.flush();
|
|
106
|
-
}
|
|
107
|
-
}
|
package/dist/server/digests.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/** Optional diagnostic enrichment; engines need not emit model diagnostics. */
|
|
2
|
-
export declare function observedPayload(event: {
|
|
3
|
-
readonly type: string;
|
|
4
|
-
readonly attributes?: unknown;
|
|
5
|
-
}): Record<string, unknown>;
|
|
6
|
-
export declare function modelRequestDigests(value: unknown): {
|
|
7
|
-
prompt: string;
|
|
8
|
-
tools: string;
|
|
9
|
-
model: string;
|
|
10
|
-
output: string;
|
|
11
|
-
configuration: string;
|
|
12
|
-
context: string;
|
|
13
|
-
};
|
package/dist/server/digests.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
/** Optional diagnostic enrichment; engines need not emit model diagnostics. */
|
|
3
|
-
export function observedPayload(event) {
|
|
4
|
-
const attributes = record(event.attributes);
|
|
5
|
-
if (event.type !== "model.requested" || !record(attributes?.call))
|
|
6
|
-
return { ...event };
|
|
7
|
-
return { ...event, digests: modelRequestDigests(attributes) };
|
|
8
|
-
}
|
|
9
|
-
export function modelRequestDigests(value) {
|
|
10
|
-
const attributes = record(value) ?? {};
|
|
11
|
-
const call = record(attributes.call) ?? {};
|
|
12
|
-
const configuration = record(attributes.configuration) ?? {};
|
|
13
|
-
return {
|
|
14
|
-
prompt: digest(call.prompt),
|
|
15
|
-
tools: digest({ call: call.tools, contracts: configuration.toolContracts }),
|
|
16
|
-
model: digest(call.model ?? null),
|
|
17
|
-
output: digest(call.outputSchema ?? null),
|
|
18
|
-
configuration: digest(attributes.configuration),
|
|
19
|
-
context: digest(attributes.context),
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
function record(value) {
|
|
23
|
-
return value !== null && typeof value === "object" && !Array.isArray(value)
|
|
24
|
-
? value
|
|
25
|
-
: undefined;
|
|
26
|
-
}
|
|
27
|
-
function digest(value) {
|
|
28
|
-
return createHash("sha256").update(canonical(value)).digest("hex");
|
|
29
|
-
}
|
|
30
|
-
function canonical(value) {
|
|
31
|
-
if (Array.isArray(value))
|
|
32
|
-
return `[${value.map(canonical).join(",")}]`;
|
|
33
|
-
if (value && typeof value === "object")
|
|
34
|
-
return `{${Object.entries(value)
|
|
35
|
-
.sort(([a], [b]) => a.localeCompare(b))
|
|
36
|
-
.map(([k, v]) => `${JSON.stringify(k)}:${canonical(v)}`)
|
|
37
|
-
.join(",")}}`;
|
|
38
|
-
return JSON.stringify(value) ?? "null";
|
|
39
|
-
}
|
package/dist/server/host.d.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { Hono, type Context } from "hono";
|
|
2
|
-
import type { JsonValue, RuntimeAgent } from "../contracts.js";
|
|
3
|
-
import type { BuiltAgent, ModelAdapter } from "@nylorun/core/define";
|
|
4
|
-
import { SessionHost } from "../sessions/host.js";
|
|
5
|
-
import type { RuntimeConfig } from "../config.js";
|
|
6
|
-
import type { ModelEnvironment } from "../model/http-model.js";
|
|
7
|
-
import { type OpenSessionOptions, type SessionHandle } from "../session/handle.js";
|
|
8
|
-
export type RuntimeActor = Readonly<{
|
|
9
|
-
id: string;
|
|
10
|
-
context?: Record<string, JsonValue>;
|
|
11
|
-
}>;
|
|
12
|
-
export type AgentRouterOptions = Readonly<{
|
|
13
|
-
basePath?: string;
|
|
14
|
-
getActor?: (context: Context) => RuntimeActor | undefined | Promise<RuntimeActor | undefined>;
|
|
15
|
-
getInfo?: (context: Context) => unknown | Promise<unknown>;
|
|
16
|
-
getEnvironment?: (context: Context) => ModelEnvironment | Promise<ModelEnvironment>;
|
|
17
|
-
getRequestMetadata?: (context: Context) => Record<string, JsonValue> | undefined | Promise<Record<string, JsonValue> | undefined>;
|
|
18
|
-
}>;
|
|
19
|
-
/** 1.0 compatibility: requires an explicit Runtime and returns a Hono app. */
|
|
20
|
-
export type ServeAgentsCompatOptions = AgentRouterOptions & {
|
|
21
|
-
readonly agents: readonly RuntimeAgent[];
|
|
22
|
-
readonly runtime: Runtime;
|
|
23
|
-
};
|
|
24
|
-
/** DX v5.6 local: optional Runtime; returns `{ fetch }`. */
|
|
25
|
-
export type ServeAgentsFetchOptions = AgentRouterOptions & {
|
|
26
|
-
readonly agents?: readonly RuntimeAgent[];
|
|
27
|
-
readonly runtime?: Runtime;
|
|
28
|
-
/** Alias for `getInfo` — keep the name `info` (never `user`). */
|
|
29
|
-
readonly info?: AgentRouterOptions["getInfo"];
|
|
30
|
-
readonly on?: {
|
|
31
|
-
readonly session?: {
|
|
32
|
-
readonly created?: (session: {
|
|
33
|
-
readonly id: string;
|
|
34
|
-
readonly agentId: string;
|
|
35
|
-
}) => void;
|
|
36
|
-
readonly idle?: (session: {
|
|
37
|
-
readonly id: string;
|
|
38
|
-
readonly agentId: string;
|
|
39
|
-
}) => void;
|
|
40
|
-
readonly failed?: (session: {
|
|
41
|
-
readonly id: string;
|
|
42
|
-
readonly agentId: string;
|
|
43
|
-
}) => void;
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
export type ServeAgentsOptions = ServeAgentsCompatOptions;
|
|
48
|
-
export type ServeAgentsFetch = {
|
|
49
|
-
readonly fetch: (request: Request) => Response | Promise<Response>;
|
|
50
|
-
};
|
|
51
|
-
declare const kServe: unique symbol;
|
|
52
|
-
export declare class Runtime {
|
|
53
|
-
readonly config: RuntimeConfig;
|
|
54
|
-
readonly host: SessionHost;
|
|
55
|
-
private served;
|
|
56
|
-
private closing?;
|
|
57
|
-
constructor(config?: RuntimeConfig);
|
|
58
|
-
close: () => Promise<void>;
|
|
59
|
-
resolveModel(onPreview?: (preview: import("../model/defaults.js").ModelPreview) => void): ModelAdapter;
|
|
60
|
-
openSession(agent: BuiltAgent<any, any>, options?: OpenSessionOptions): SessionHandle;
|
|
61
|
-
listSessions(agentId: string): Promise<readonly import("../sessions/store.js").SessionSummary[]>;
|
|
62
|
-
getSession(agentId: string, sessionId: string): Promise<import("../sessions/store.js").StoredSession | undefined>;
|
|
63
|
-
deleteSession(agentId: string, sessionId: string): Promise<boolean>;
|
|
64
|
-
[kServe](options: Omit<ServeAgentsCompatOptions, "runtime"> & {
|
|
65
|
-
readonly agents: readonly RuntimeAgent[];
|
|
66
|
-
}): Hono<any>;
|
|
67
|
-
}
|
|
68
|
-
export declare function serveAgents(options: ServeAgentsCompatOptions): Hono<any>;
|
|
69
|
-
export declare function serveAgents(options: ServeAgentsFetchOptions): ServeAgentsFetch;
|
|
70
|
-
export {};
|