@nylorun/runtime 0.9.0-beta → 0.10.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 (129) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +96 -25
  3. package/dist/adapters/media.d.ts +2 -2
  4. package/dist/adapters/media.js +2 -2
  5. package/dist/adapters/observe.d.ts +2 -1
  6. package/dist/adapters/observe.js +2 -3
  7. package/dist/assets.d.ts +2 -2
  8. package/dist/assets.js +5 -3
  9. package/dist/core/executors.d.ts +11 -2
  10. package/dist/core/executors.js +20 -4
  11. package/dist/core/flow-host.d.ts +264 -0
  12. package/dist/core/flow-host.js +783 -0
  13. package/dist/core/limits.d.ts +40 -0
  14. package/dist/core/limits.js +76 -0
  15. package/dist/core/runtime.d.ts +5 -90
  16. package/dist/core/runtime.js +3 -1447
  17. package/dist/core/sandbox-routes.d.ts +35 -0
  18. package/dist/core/sandbox-routes.js +106 -0
  19. package/dist/core/store.d.ts +3 -1
  20. package/dist/core/store.js +14 -73
  21. package/dist/core/turn-manifest.d.ts +50 -0
  22. package/dist/core/turn-manifest.js +66 -0
  23. package/dist/host/config-for.d.ts +16 -0
  24. package/dist/host/config-for.js +45 -0
  25. package/dist/host/config.d.ts +24 -0
  26. package/dist/host/create-host.d.ts +21 -0
  27. package/dist/host/create-host.js +396 -0
  28. package/dist/host/environment.d.ts +13 -0
  29. package/dist/host/environment.js +53 -0
  30. package/dist/host/http.d.ts +35 -0
  31. package/dist/host/http.js +136 -0
  32. package/dist/host/index.d.ts +6 -0
  33. package/dist/host/index.js +5 -0
  34. package/dist/host/logger.d.ts +3 -0
  35. package/dist/host/logger.js +18 -0
  36. package/dist/host/main.d.ts +3 -0
  37. package/dist/host/main.js +142 -0
  38. package/dist/index.d.ts +7 -2
  39. package/dist/index.js +4 -2
  40. package/dist/launcher/commands.d.ts +24 -0
  41. package/dist/launcher/commands.js +260 -0
  42. package/dist/launcher/ensure-config.d.ts +16 -0
  43. package/dist/launcher/ensure-config.js +79 -0
  44. package/dist/launcher/errors.d.ts +12 -0
  45. package/dist/launcher/errors.js +22 -0
  46. package/dist/launcher/host-config.d.ts +17 -0
  47. package/dist/launcher/host-config.js +64 -0
  48. package/dist/launcher/host-state.d.ts +17 -0
  49. package/dist/launcher/host-state.js +61 -0
  50. package/dist/launcher/lifecycle.d.ts +66 -0
  51. package/dist/launcher/lifecycle.js +407 -0
  52. package/dist/launcher/locks.d.ts +26 -0
  53. package/dist/launcher/locks.js +117 -0
  54. package/dist/launcher/logs.d.ts +18 -0
  55. package/dist/launcher/logs.js +117 -0
  56. package/dist/launcher/main.d.ts +2 -0
  57. package/dist/launcher/main.js +66 -0
  58. package/dist/launcher/output.d.ts +11 -0
  59. package/dist/launcher/output.js +68 -0
  60. package/dist/launcher/paths.d.ts +20 -0
  61. package/dist/launcher/paths.js +36 -0
  62. package/dist/launcher/probe.d.ts +23 -0
  63. package/dist/launcher/probe.js +72 -0
  64. package/dist/launcher/protocol.d.ts +62 -0
  65. package/dist/launcher/protocol.js +1 -0
  66. package/dist/launcher/schema-guard.d.ts +6 -0
  67. package/dist/launcher/schema-guard.js +36 -0
  68. package/dist/launcher/spawn.d.ts +22 -0
  69. package/dist/launcher/spawn.js +85 -0
  70. package/dist/launcher/status.d.ts +6 -0
  71. package/dist/launcher/status.js +65 -0
  72. package/dist/mcp/connect.d.ts +1 -0
  73. package/dist/mcp/connect.js +2 -0
  74. package/dist/mcp/pool.d.ts +3 -1
  75. package/dist/mcp/pool.js +2 -1
  76. package/dist/mcp/stdio.d.ts +2 -0
  77. package/dist/mcp/stdio.js +3 -1
  78. package/dist/model/auth-store.d.ts +1 -1
  79. package/dist/model/auth-store.js +2 -2
  80. package/dist/model/models.d.ts +4 -0
  81. package/dist/model/models.js +22 -26
  82. package/dist/model/pi-model.js +1 -1
  83. package/dist/model/settings.d.ts +5 -1
  84. package/dist/model/settings.js +6 -2
  85. package/dist/sandbox/select.d.ts +4 -3
  86. package/dist/sandbox/select.js +15 -9
  87. package/dist/sandbox/share.d.ts +23 -0
  88. package/dist/sandbox/share.js +58 -0
  89. package/dist/tenant/envelope.d.ts +10 -0
  90. package/dist/tenant/envelope.js +54 -0
  91. package/dist/tenant/ephemeral.d.ts +31 -0
  92. package/dist/tenant/ephemeral.js +156 -0
  93. package/dist/tenant/logger.d.ts +9 -0
  94. package/dist/tenant/logger.js +25 -0
  95. package/dist/tenant/migration.d.ts +16 -0
  96. package/dist/tenant/migration.js +116 -0
  97. package/dist/tenant/module.d.ts +17 -0
  98. package/dist/tenant/module.js +315 -0
  99. package/dist/tenant/paths.d.ts +24 -0
  100. package/dist/tenant/paths.js +65 -0
  101. package/dist/tenant/pool.d.ts +10 -0
  102. package/dist/tenant/pool.js +54 -0
  103. package/dist/tenant/principals.d.ts +17 -0
  104. package/dist/tenant/principals.js +44 -0
  105. package/dist/tenant/quarantine-error.d.ts +6 -0
  106. package/dist/tenant/quarantine-error.js +15 -0
  107. package/dist/tenant/quarantine.d.ts +35 -0
  108. package/dist/tenant/quarantine.js +94 -0
  109. package/dist/tenant/reset.d.ts +21 -0
  110. package/dist/tenant/reset.js +125 -0
  111. package/dist/tenant/runtime.d.ts +80 -0
  112. package/dist/tenant/runtime.js +2256 -0
  113. package/dist/tenant/schema.d.ts +23 -0
  114. package/dist/tenant/schema.js +151 -0
  115. package/dist/tenant/status.d.ts +28 -0
  116. package/dist/tenant/status.js +95 -0
  117. package/dist/tenant/store-fs.d.ts +16 -0
  118. package/dist/tenant/store-fs.js +205 -0
  119. package/dist/tenant/store-memory.d.ts +19 -0
  120. package/dist/tenant/store-memory.js +100 -0
  121. package/dist/tenant/types.d.ts +125 -0
  122. package/dist/tenant/types.js +1 -0
  123. package/dist/vault/kek.d.ts +5 -2
  124. package/dist/vault/kek.js +7 -10
  125. package/dist/version.d.ts +1 -1
  126. package/dist/version.js +1 -1
  127. package/package.json +9 -6
  128. package/dist/core/main.js +0 -35
  129. /package/dist/{core/main.d.ts → host/config.js} +0 -0
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Operator flow limits (`workflows.md` §13).
3
+ * Host configuration only — never workflow API settings.
4
+ */
5
+ export type FlowLimits = {
6
+ readonly maxConcurrency: number;
7
+ readonly maxMapItems: number;
8
+ readonly maxLoopIterations: number;
9
+ };
10
+ export declare const FLOW_LIMIT_DEFAULTS: FlowLimits;
11
+ export declare const FLOW_LIMIT_ENV: {
12
+ readonly maxConcurrency: "NYLORUN_FLOW_MAX_CONCURRENCY";
13
+ readonly maxMapItems: "NYLORUN_FLOW_MAX_MAP_ITEMS";
14
+ readonly maxLoopIterations: "NYLORUN_FLOW_MAX_LOOP_ITERATIONS";
15
+ };
16
+ export type FlowLimitErrorCode = "map.too-many-items" | "loop.too-many-iterations";
17
+ export declare class FlowLimitError extends Error {
18
+ readonly code: FlowLimitErrorCode;
19
+ readonly path?: string;
20
+ constructor(code: FlowLimitErrorCode, message: string, path?: string);
21
+ }
22
+ /**
23
+ * Resolve limits from `RuntimeOptions.flow` overrides and optional env snapshot.
24
+ * Does not read ambient process environment — callers pass an explicit env map.
25
+ */
26
+ export declare function resolveFlowLimits(input?: {
27
+ readonly flow?: Partial<FlowLimits> | null;
28
+ readonly env?: Readonly<Record<string, string | undefined>>;
29
+ }): FlowLimits;
30
+ /** Further ready work waits when active >= maxConcurrency (not an error). */
31
+ export declare function mayDispatchMore(activeCount: number, limits: Pick<FlowLimits, "maxConcurrency">): boolean;
32
+ /**
33
+ * Map item ceiling. Exceeding raises `map.too-many-items` and nothing should start.
34
+ */
35
+ export declare function assertMapItemCount(count: number, limits: Pick<FlowLimits, "maxMapItems">, path?: string): void;
36
+ /**
37
+ * Loop operator ceiling. Exceeding raises `loop.too-many-iterations`.
38
+ * `n` is the 1-based iteration about to run.
39
+ */
40
+ export declare function assertLoopIteration(n: number, limits: Pick<FlowLimits, "maxLoopIterations">, path?: string): void;
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Operator flow limits (`workflows.md` §13).
3
+ * Host configuration only — never workflow API settings.
4
+ */
5
+ export const FLOW_LIMIT_DEFAULTS = {
6
+ maxConcurrency: 8,
7
+ maxMapItems: 1000,
8
+ maxLoopIterations: 100,
9
+ };
10
+ export const FLOW_LIMIT_ENV = {
11
+ maxConcurrency: "NYLORUN_FLOW_MAX_CONCURRENCY",
12
+ maxMapItems: "NYLORUN_FLOW_MAX_MAP_ITEMS",
13
+ maxLoopIterations: "NYLORUN_FLOW_MAX_LOOP_ITERATIONS",
14
+ };
15
+ export class FlowLimitError extends Error {
16
+ code;
17
+ path;
18
+ constructor(code, message, path) {
19
+ super(message);
20
+ this.name = "FlowLimitError";
21
+ this.code = code;
22
+ if (path !== undefined)
23
+ this.path = path;
24
+ }
25
+ }
26
+ function parsePositiveInt(raw, field) {
27
+ if (raw === undefined || raw === "")
28
+ return undefined;
29
+ const n = Number(raw);
30
+ if (!Number.isFinite(n) || !Number.isInteger(n) || n <= 0)
31
+ throw new Error(`${field} must be a positive integer`);
32
+ return n;
33
+ }
34
+ /**
35
+ * Resolve limits from `RuntimeOptions.flow` overrides and optional env snapshot.
36
+ * Does not read ambient process environment — callers pass an explicit env map.
37
+ */
38
+ export function resolveFlowLimits(input) {
39
+ const env = input?.env ?? {};
40
+ const flow = input?.flow ?? {};
41
+ const fromEnv = {
42
+ maxConcurrency: parsePositiveInt(env[FLOW_LIMIT_ENV.maxConcurrency], FLOW_LIMIT_ENV.maxConcurrency),
43
+ maxMapItems: parsePositiveInt(env[FLOW_LIMIT_ENV.maxMapItems], FLOW_LIMIT_ENV.maxMapItems),
44
+ maxLoopIterations: parsePositiveInt(env[FLOW_LIMIT_ENV.maxLoopIterations], FLOW_LIMIT_ENV.maxLoopIterations),
45
+ };
46
+ const pick = (field, override, envValue) => {
47
+ const value = override ?? envValue ?? FLOW_LIMIT_DEFAULTS[field];
48
+ if (!Number.isFinite(value) || !Number.isInteger(value) || value <= 0)
49
+ throw new Error(`flow.${field} must be a positive integer`);
50
+ return value;
51
+ };
52
+ return {
53
+ maxConcurrency: pick("maxConcurrency", flow.maxConcurrency, fromEnv.maxConcurrency),
54
+ maxMapItems: pick("maxMapItems", flow.maxMapItems, fromEnv.maxMapItems),
55
+ maxLoopIterations: pick("maxLoopIterations", flow.maxLoopIterations, fromEnv.maxLoopIterations),
56
+ };
57
+ }
58
+ /** Further ready work waits when active >= maxConcurrency (not an error). */
59
+ export function mayDispatchMore(activeCount, limits) {
60
+ return activeCount < limits.maxConcurrency;
61
+ }
62
+ /**
63
+ * Map item ceiling. Exceeding raises `map.too-many-items` and nothing should start.
64
+ */
65
+ export function assertMapItemCount(count, limits, path) {
66
+ if (count > limits.maxMapItems)
67
+ throw new FlowLimitError("map.too-many-items", `Map produced ${count} items; maxMapItems is ${limits.maxMapItems}`, path);
68
+ }
69
+ /**
70
+ * Loop operator ceiling. Exceeding raises `loop.too-many-iterations`.
71
+ * `n` is the 1-based iteration about to run.
72
+ */
73
+ export function assertLoopIteration(n, limits, path) {
74
+ if (n > limits.maxLoopIterations)
75
+ throw new FlowLimitError("loop.too-many-iterations", `Loop iteration ${n} exceeds maxLoopIterations ${limits.maxLoopIterations}`, path);
76
+ }
@@ -1,90 +1,5 @@
1
- import { type ExecutorScope } from "@nylorun/core/contracts";
2
- import { type ModelProvider } from "./provider.js";
3
- import { type AuthorizeResult } from "../vault/service.js";
4
- import type { SandboxBackend } from "../sandbox/types.js";
5
- export interface RuntimeOptions {
6
- sqlitePath: string;
7
- serverToken: string;
8
- executors: readonly (ExecutorScope & {
9
- token: string;
10
- })[];
11
- model?: ModelProvider;
12
- /** Read the model provider credential from the host vault at call time. */
13
- useHostModel?: boolean;
14
- leaseMs?: number;
15
- /** 32-byte key, or base64 of that key. `null` disables env and file lookup. */
16
- vaultKek?: Buffer | string | null;
17
- vaultKekPath?: string;
18
- vaultFetch?: typeof fetch;
19
- sandbox?: {
20
- /** `auto` (default), `microsandbox` or `virtual`. Defaults to NYLORUN_SANDBOX. */
21
- backend?: string;
22
- /** Host directory for virtual-backend workspaces. Defaults beside the SQLite file. */
23
- root?: string;
24
- /** Replace the backend list. Tests only. */
25
- backends?: readonly SandboxBackend[];
26
- };
27
- }
28
- export declare class CoreRuntime {
29
- private readonly options;
30
- private readonly store;
31
- private readonly vault;
32
- private kek;
33
- private readonly kekPath;
34
- private readonly running;
35
- private readonly pending;
36
- private readonly observers;
37
- private readonly executorStreams;
38
- private readonly registry;
39
- private readonly scopeId;
40
- private readonly mcp;
41
- private readonly sandbox;
42
- private server?;
43
- private closing;
44
- private closed;
45
- private readonly lockPath?;
46
- private readonly timer;
47
- constructor(options: RuntimeOptions);
48
- private session;
49
- private publish;
50
- private send;
51
- private notify;
52
- /**
53
- * Manifest v4 replaced beforeModelCall/afterModelCall with scoped hooks. Turns started under
54
- * an older manifest cannot continue, and their hook actions no longer parse, so end them.
55
- */
56
- private retireLegacyHooks;
57
- private expireClaims;
58
- private schedule;
59
- private execute;
60
- private invokeModel;
61
- private resolveEffect;
62
- private scope;
63
- private scoped;
64
- private body;
65
- private command;
66
- private sse;
67
- private handle;
68
- private view;
69
- private prepareMcp;
70
- private callMcpTool;
71
- private callSandboxTool;
72
- authorize(sessionId: string, request: {
73
- url: string;
74
- serverName?: string;
75
- }): Promise<AuthorizeResult>;
76
- private ensureKek;
77
- private dispatchHost;
78
- private dispatchVault;
79
- listen(port?: number, hostname?: string): Promise<{
80
- url: string;
81
- }>;
82
- close(): Promise<void>;
83
- }
84
- export declare function createRuntime(options: RuntimeOptions): CoreRuntime;
85
- export declare function startRuntime(options: RuntimeOptions & {
86
- port?: number;
87
- hostname?: string;
88
- }): Promise<CoreRuntime & {
89
- url: string;
90
- }>;
1
+ export { openTenantRuntime, TenantRuntime, type TenantOpenHooks, } from "../tenant/runtime.js";
2
+ export { startEphemeralRuntime, type StartEphemeralRuntimeOptions, type EphemeralRuntime, } from "../tenant/ephemeral.js";
3
+ export { scriptedModel, gatewayModel, type ModelProvider } from "./provider.js";
4
+ /** @deprecated Use TenantHandle. */
5
+ export type { TenantHandle as CoreRuntime } from "../tenant/types.js";