@nylorun/runtime 0.7.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.
Files changed (69) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +7 -5
  3. package/dist/adapters/sandbox/microsandbox.d.ts +2 -0
  4. package/dist/adapters/sandbox/microsandbox.js +238 -0
  5. package/dist/adapters/sandbox/virtual.d.ts +4 -0
  6. package/dist/adapters/sandbox/virtual.js +125 -0
  7. package/dist/configuration.d.ts +1 -1
  8. package/dist/configuration.js +1 -1
  9. package/dist/core/executors.d.ts +32 -0
  10. package/dist/core/executors.js +60 -0
  11. package/dist/core/main.js +7 -12
  12. package/dist/core/runtime.d.ts +24 -1
  13. package/dist/core/runtime.js +322 -30
  14. package/dist/core/store.d.ts +12 -0
  15. package/dist/core/store.js +50 -1
  16. package/dist/index.d.ts +0 -1
  17. package/dist/index.js +0 -1
  18. package/dist/model/catalog.d.ts +12 -0
  19. package/dist/model/catalog.js +29 -0
  20. package/dist/model/models.d.ts +3 -1
  21. package/dist/model/models.js +4 -2
  22. package/dist/model/pi-model.d.ts +9 -3
  23. package/dist/model/pi-model.js +47 -11
  24. package/dist/model/settings.d.ts +0 -2
  25. package/dist/model/settings.js +0 -47
  26. package/dist/node/index.d.ts +1 -1
  27. package/dist/node/index.js +1 -1
  28. package/dist/sandbox/manager.d.ts +61 -0
  29. package/dist/sandbox/manager.js +239 -0
  30. package/dist/sandbox/policy.d.ts +13 -0
  31. package/dist/sandbox/policy.js +67 -0
  32. package/dist/sandbox/select.d.ts +35 -0
  33. package/dist/sandbox/select.js +76 -0
  34. package/dist/sandbox/tools.d.ts +25 -0
  35. package/dist/sandbox/tools.js +165 -0
  36. package/dist/sandbox/types.d.ts +66 -0
  37. package/dist/vault/service.d.ts +41 -1
  38. package/dist/vault/service.js +291 -4
  39. package/dist/version.d.ts +1 -0
  40. package/dist/version.js +3 -0
  41. package/package.json +9 -4
  42. package/dist/config.d.ts +0 -20
  43. package/dist/model/defaults.d.ts +0 -17
  44. package/dist/model/defaults.js +0 -21
  45. package/dist/model/http-model.d.ts +0 -12
  46. package/dist/model/http-model.js +0 -299
  47. package/dist/node/local-sessions.d.ts +0 -5
  48. package/dist/node/local-sessions.js +0 -174
  49. package/dist/server/ag-ui.d.ts +0 -8
  50. package/dist/server/ag-ui.js +0 -76
  51. package/dist/server/delivery.d.ts +0 -24
  52. package/dist/server/delivery.js +0 -107
  53. package/dist/server/digests.d.ts +0 -13
  54. package/dist/server/digests.js +0 -39
  55. package/dist/server/host.d.ts +0 -70
  56. package/dist/server/host.js +0 -647
  57. package/dist/session/api.d.ts +0 -10
  58. package/dist/session/api.js +0 -15
  59. package/dist/session/default.d.ts +0 -5
  60. package/dist/session/default.js +0 -30
  61. package/dist/session/handle.d.ts +0 -27
  62. package/dist/session/handle.js +0 -199
  63. package/dist/session/index.d.ts +0 -2
  64. package/dist/session/index.js +0 -2
  65. package/dist/sessions/host.d.ts +0 -39
  66. package/dist/sessions/host.js +0 -359
  67. package/dist/sessions/store.d.ts +0 -41
  68. package/dist/sessions/store.js +0 -33
  69. /package/dist/{config.js → sandbox/types.js} +0 -0
@@ -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
- }
@@ -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
- };
@@ -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
- }
@@ -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 {};