@nylorun/runtime 0.8.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.
- package/CHANGELOG.md +52 -0
- package/README.md +96 -25
- package/dist/adapters/media.d.ts +2 -2
- package/dist/adapters/media.js +2 -2
- package/dist/adapters/observe.d.ts +2 -1
- package/dist/adapters/observe.js +2 -3
- package/dist/assets.d.ts +2 -2
- package/dist/assets.js +5 -3
- package/dist/core/executors.d.ts +11 -2
- package/dist/core/executors.js +20 -4
- package/dist/core/flow-host.d.ts +264 -0
- package/dist/core/flow-host.js +783 -0
- package/dist/core/limits.d.ts +40 -0
- package/dist/core/limits.js +76 -0
- package/dist/core/runtime.d.ts +5 -90
- package/dist/core/runtime.js +3 -1418
- package/dist/core/sandbox-routes.d.ts +35 -0
- package/dist/core/sandbox-routes.js +106 -0
- package/dist/core/store.d.ts +5 -2
- package/dist/core/store.js +20 -72
- package/dist/core/turn-manifest.d.ts +50 -0
- package/dist/core/turn-manifest.js +66 -0
- package/dist/host/config-for.d.ts +16 -0
- package/dist/host/config-for.js +45 -0
- package/dist/host/config.d.ts +24 -0
- package/dist/host/create-host.d.ts +21 -0
- package/dist/host/create-host.js +396 -0
- package/dist/host/environment.d.ts +13 -0
- package/dist/host/environment.js +53 -0
- package/dist/host/http.d.ts +35 -0
- package/dist/host/http.js +136 -0
- package/dist/host/index.d.ts +6 -0
- package/dist/host/index.js +5 -0
- package/dist/host/logger.d.ts +3 -0
- package/dist/host/logger.js +18 -0
- package/dist/host/main.d.ts +3 -0
- package/dist/host/main.js +142 -0
- package/dist/index.d.ts +7 -2
- package/dist/index.js +4 -2
- package/dist/launcher/commands.d.ts +24 -0
- package/dist/launcher/commands.js +260 -0
- package/dist/launcher/ensure-config.d.ts +16 -0
- package/dist/launcher/ensure-config.js +79 -0
- package/dist/launcher/errors.d.ts +12 -0
- package/dist/launcher/errors.js +22 -0
- package/dist/launcher/host-config.d.ts +17 -0
- package/dist/launcher/host-config.js +64 -0
- package/dist/launcher/host-state.d.ts +17 -0
- package/dist/launcher/host-state.js +61 -0
- package/dist/launcher/lifecycle.d.ts +66 -0
- package/dist/launcher/lifecycle.js +407 -0
- package/dist/launcher/locks.d.ts +26 -0
- package/dist/launcher/locks.js +117 -0
- package/dist/launcher/logs.d.ts +18 -0
- package/dist/launcher/logs.js +117 -0
- package/dist/launcher/main.d.ts +2 -0
- package/dist/launcher/main.js +66 -0
- package/dist/launcher/output.d.ts +11 -0
- package/dist/launcher/output.js +68 -0
- package/dist/launcher/paths.d.ts +20 -0
- package/dist/launcher/paths.js +36 -0
- package/dist/launcher/probe.d.ts +23 -0
- package/dist/launcher/probe.js +72 -0
- package/dist/launcher/protocol.d.ts +62 -0
- package/dist/launcher/protocol.js +1 -0
- package/dist/launcher/schema-guard.d.ts +6 -0
- package/dist/launcher/schema-guard.js +36 -0
- package/dist/launcher/spawn.d.ts +22 -0
- package/dist/launcher/spawn.js +85 -0
- package/dist/launcher/status.d.ts +6 -0
- package/dist/launcher/status.js +65 -0
- package/dist/mcp/connect.d.ts +1 -0
- package/dist/mcp/connect.js +2 -0
- package/dist/mcp/pool.d.ts +16 -2
- package/dist/mcp/pool.js +54 -19
- package/dist/mcp/snapshot.d.ts +4 -0
- package/dist/mcp/stdio.d.ts +2 -0
- package/dist/mcp/stdio.js +3 -1
- package/dist/model/auth-store.d.ts +1 -1
- package/dist/model/auth-store.js +2 -2
- package/dist/model/models.d.ts +4 -0
- package/dist/model/models.js +22 -26
- package/dist/model/pi-model.js +1 -1
- package/dist/model/settings.d.ts +5 -1
- package/dist/model/settings.js +6 -2
- package/dist/sandbox/select.d.ts +4 -3
- package/dist/sandbox/select.js +15 -9
- package/dist/sandbox/share.d.ts +23 -0
- package/dist/sandbox/share.js +58 -0
- package/dist/tenant/envelope.d.ts +10 -0
- package/dist/tenant/envelope.js +54 -0
- package/dist/tenant/ephemeral.d.ts +31 -0
- package/dist/tenant/ephemeral.js +156 -0
- package/dist/tenant/logger.d.ts +9 -0
- package/dist/tenant/logger.js +25 -0
- package/dist/tenant/migration.d.ts +16 -0
- package/dist/tenant/migration.js +116 -0
- package/dist/tenant/module.d.ts +17 -0
- package/dist/tenant/module.js +315 -0
- package/dist/tenant/paths.d.ts +24 -0
- package/dist/tenant/paths.js +65 -0
- package/dist/tenant/pool.d.ts +10 -0
- package/dist/tenant/pool.js +54 -0
- package/dist/tenant/principals.d.ts +17 -0
- package/dist/tenant/principals.js +44 -0
- package/dist/tenant/quarantine-error.d.ts +6 -0
- package/dist/tenant/quarantine-error.js +15 -0
- package/dist/tenant/quarantine.d.ts +35 -0
- package/dist/tenant/quarantine.js +94 -0
- package/dist/tenant/reset.d.ts +21 -0
- package/dist/tenant/reset.js +125 -0
- package/dist/tenant/runtime.d.ts +80 -0
- package/dist/tenant/runtime.js +2256 -0
- package/dist/tenant/schema.d.ts +23 -0
- package/dist/tenant/schema.js +151 -0
- package/dist/tenant/status.d.ts +28 -0
- package/dist/tenant/status.js +95 -0
- package/dist/tenant/store-fs.d.ts +16 -0
- package/dist/tenant/store-fs.js +205 -0
- package/dist/tenant/store-memory.d.ts +19 -0
- package/dist/tenant/store-memory.js +100 -0
- package/dist/tenant/types.d.ts +125 -0
- package/dist/tenant/types.js +1 -0
- package/dist/vault/kek.d.ts +5 -2
- package/dist/vault/kek.js +7 -10
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +9 -6
- package/dist/core/main.js +0 -35
- /package/dist/{core/main.d.ts → host/config.js} +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Store } from "../core/store.js";
|
|
2
|
+
import type { ExecutorRegistry } from "../core/executors.js";
|
|
3
|
+
import type { SandboxManager } from "../sandbox/manager.js";
|
|
4
|
+
import type { TenantPaths } from "./types.js";
|
|
5
|
+
export type ResetScope = "sessions" | "sandboxes" | "all";
|
|
6
|
+
export interface ResetTenantContext {
|
|
7
|
+
store: Store;
|
|
8
|
+
registry: ExecutorRegistry;
|
|
9
|
+
sandbox: SandboxManager;
|
|
10
|
+
paths: TenantPaths;
|
|
11
|
+
/** Clear in-memory session observers after DB wipe. */
|
|
12
|
+
clearSessionState: () => void;
|
|
13
|
+
/** Clear executor SSE streams when registrations are removed. */
|
|
14
|
+
clearExecutorStreams: () => void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Reset Tenant durable state for `scope` (A17).
|
|
18
|
+
* Caller must have already drained (`activeWork`). Runs SQLite work in one
|
|
19
|
+
* transaction, then filesystem rename+delete for sandboxes / log as needed.
|
|
20
|
+
*/
|
|
21
|
+
export declare function resetTenant(ctx: ResetTenantContext, scope: ResetScope): Promise<void>;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, renameSync, rmSync, writeFileSync, } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
const SESSION_TABLES = [
|
|
4
|
+
"sessions",
|
|
5
|
+
"commands",
|
|
6
|
+
"checkpoints",
|
|
7
|
+
"effects",
|
|
8
|
+
"actions",
|
|
9
|
+
];
|
|
10
|
+
/**
|
|
11
|
+
* Rename `dir` to a sibling, delete the sibling, recreate an empty `dir`.
|
|
12
|
+
* Failure before rename leaves the original intact; after rename the empty
|
|
13
|
+
* target is restored so the Tenant layout stays valid (A17).
|
|
14
|
+
*/
|
|
15
|
+
function replaceDirectory(dir) {
|
|
16
|
+
mkdirSync(dir, { recursive: true });
|
|
17
|
+
const sibling = `${dir}.resetting`;
|
|
18
|
+
if (existsSync(sibling))
|
|
19
|
+
rmSync(sibling, { recursive: true, force: true });
|
|
20
|
+
renameSync(dir, sibling);
|
|
21
|
+
try {
|
|
22
|
+
mkdirSync(dir, { recursive: true });
|
|
23
|
+
rmSync(sibling, { recursive: true, force: true });
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
// Best-effort restore if recreation failed.
|
|
27
|
+
if (!existsSync(dir) && existsSync(sibling)) {
|
|
28
|
+
try {
|
|
29
|
+
renameSync(sibling, dir);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
/* leave sibling for operator inspection */
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function clearSessionTables(store) {
|
|
39
|
+
for (const table of SESSION_TABLES) {
|
|
40
|
+
store.db.prepare(`DELETE FROM ${table}`).run();
|
|
41
|
+
}
|
|
42
|
+
store.db.prepare("DELETE FROM events").run();
|
|
43
|
+
}
|
|
44
|
+
function clearSandboxRows(store) {
|
|
45
|
+
store.db.prepare("DELETE FROM sandboxes").run();
|
|
46
|
+
}
|
|
47
|
+
function clearDefinitions(store) {
|
|
48
|
+
store.db.prepare("DELETE FROM definitions").run();
|
|
49
|
+
}
|
|
50
|
+
function clearExecutors(store, registry) {
|
|
51
|
+
for (const row of registry.list())
|
|
52
|
+
registry.remove(row.agentId);
|
|
53
|
+
store.db.prepare("DELETE FROM executors").run();
|
|
54
|
+
}
|
|
55
|
+
/** Delete user-scoped vaults; keep the host vault (model credentials). */
|
|
56
|
+
function clearUserVaults(store) {
|
|
57
|
+
const userVaults = store.db
|
|
58
|
+
.prepare(`SELECT id FROM vaults WHERE scope != 'host'`)
|
|
59
|
+
.all();
|
|
60
|
+
for (const vault of userVaults) {
|
|
61
|
+
store.db
|
|
62
|
+
.prepare(`DELETE FROM vault_credentials WHERE vault_id=?`)
|
|
63
|
+
.run(vault.id);
|
|
64
|
+
store.db.prepare(`DELETE FROM vaults WHERE id=?`).run(vault.id);
|
|
65
|
+
}
|
|
66
|
+
// Drop audit / idempotency rows that referenced user vaults only when all.
|
|
67
|
+
// Keep host-model idempotency so seed replay stays stable.
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Reset Tenant durable state for `scope` (A17).
|
|
71
|
+
* Caller must have already drained (`activeWork`). Runs SQLite work in one
|
|
72
|
+
* transaction, then filesystem rename+delete for sandboxes / log as needed.
|
|
73
|
+
*/
|
|
74
|
+
export async function resetTenant(ctx, scope) {
|
|
75
|
+
const clearSessions = scope === "sessions" || scope === "all";
|
|
76
|
+
const clearSandboxes = scope === "sandboxes" || scope === "all";
|
|
77
|
+
const clearAll = scope === "all";
|
|
78
|
+
if (clearSandboxes) {
|
|
79
|
+
await ctx.sandbox.reconcile(() => false);
|
|
80
|
+
}
|
|
81
|
+
ctx.store.tx(() => {
|
|
82
|
+
if (clearSessions)
|
|
83
|
+
clearSessionTables(ctx.store);
|
|
84
|
+
if (clearSandboxes)
|
|
85
|
+
clearSandboxRows(ctx.store);
|
|
86
|
+
if (clearAll) {
|
|
87
|
+
clearDefinitions(ctx.store);
|
|
88
|
+
clearExecutors(ctx.store, ctx.registry);
|
|
89
|
+
clearUserVaults(ctx.store);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
if (clearSessions)
|
|
93
|
+
ctx.clearSessionState();
|
|
94
|
+
if (clearAll)
|
|
95
|
+
ctx.clearExecutorStreams();
|
|
96
|
+
if (clearSandboxes)
|
|
97
|
+
replaceDirectory(ctx.paths.sandboxes);
|
|
98
|
+
if (clearAll) {
|
|
99
|
+
mkdirSync(ctx.paths.logs, { recursive: true });
|
|
100
|
+
const logSibling = join(ctx.paths.logs, "tenant.log.resetting");
|
|
101
|
+
if (existsSync(ctx.paths.log)) {
|
|
102
|
+
if (existsSync(logSibling))
|
|
103
|
+
rmSync(logSibling, { force: true });
|
|
104
|
+
renameSync(ctx.paths.log, logSibling);
|
|
105
|
+
try {
|
|
106
|
+
writeFileSync(ctx.paths.log, "");
|
|
107
|
+
rmSync(logSibling, { force: true });
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
if (!existsSync(ctx.paths.log) && existsSync(logSibling)) {
|
|
111
|
+
try {
|
|
112
|
+
renameSync(logSibling, ctx.paths.log);
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
/* leave sibling */
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
writeFileSync(ctx.paths.log, "");
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { type ServerResponse, type IncomingMessage } from "node:http";
|
|
2
|
+
import { type ModelProvider } from "../core/provider.js";
|
|
3
|
+
import type { TenantConfig, TenantHandle, TenantSummary } from "./types.js";
|
|
4
|
+
import type { TenantEnvelope } from "@nylorun/core/contracts";
|
|
5
|
+
import { type AuthorizeResult } from "../vault/service.js";
|
|
6
|
+
/** TENANTS-CCR: test/injection hooks until TenantConfig gains them. */
|
|
7
|
+
export type TenantOpenHooks = {
|
|
8
|
+
modelProvider?: ModelProvider;
|
|
9
|
+
vaultKek?: Buffer | string | null;
|
|
10
|
+
/** When true, create the KEK file on first vault write (tests / new Tenants). */
|
|
11
|
+
createKekIfMissing?: boolean;
|
|
12
|
+
};
|
|
13
|
+
export declare class TenantRuntime implements TenantHandle {
|
|
14
|
+
private readonly config;
|
|
15
|
+
private readonly store;
|
|
16
|
+
private readonly vault;
|
|
17
|
+
private kek;
|
|
18
|
+
private readonly kekPath;
|
|
19
|
+
private readonly running;
|
|
20
|
+
private readonly pending;
|
|
21
|
+
private readonly observers;
|
|
22
|
+
private readonly executorStreams;
|
|
23
|
+
private readonly registry;
|
|
24
|
+
private readonly mcp;
|
|
25
|
+
private readonly sandbox;
|
|
26
|
+
private closing;
|
|
27
|
+
private closed;
|
|
28
|
+
private readonly lockPath?;
|
|
29
|
+
private readonly timer;
|
|
30
|
+
private readonly modelProvider;
|
|
31
|
+
private readonly useVaultModel;
|
|
32
|
+
private readonly createKekIfMissing;
|
|
33
|
+
private readonly flowLimits;
|
|
34
|
+
readonly envelope: TenantEnvelope;
|
|
35
|
+
private constructor();
|
|
36
|
+
static open(config: TenantConfig, hooks?: TenantOpenHooks): Promise<TenantRuntime>;
|
|
37
|
+
private session;
|
|
38
|
+
private publish;
|
|
39
|
+
private send;
|
|
40
|
+
private notify;
|
|
41
|
+
/**
|
|
42
|
+
* Manifest v4 replaced beforeModelCall/afterModelCall with scoped hooks. Turns started under
|
|
43
|
+
* an older manifest cannot continue, and their hook actions no longer parse, so end them.
|
|
44
|
+
*/
|
|
45
|
+
private retireLegacyHooks;
|
|
46
|
+
private expireClaims;
|
|
47
|
+
private schedule;
|
|
48
|
+
private execute;
|
|
49
|
+
private invokeModel;
|
|
50
|
+
private resolveEffect;
|
|
51
|
+
/** Journal and dispatch a new flow effect (agent / tool node / fn / verify). */
|
|
52
|
+
private resolveNewFlowEffect;
|
|
53
|
+
private scope;
|
|
54
|
+
private scoped;
|
|
55
|
+
private requireApplication;
|
|
56
|
+
private sandboxRouteDeps;
|
|
57
|
+
private body;
|
|
58
|
+
private command;
|
|
59
|
+
private sse;
|
|
60
|
+
handle(request: IncomingMessage, response: ServerResponse, _url?: URL): Promise<void>;
|
|
61
|
+
private view;
|
|
62
|
+
private prepareMcp;
|
|
63
|
+
private callMcpTool;
|
|
64
|
+
private callSandboxTool;
|
|
65
|
+
authorize(sessionId: string, request: {
|
|
66
|
+
url: string;
|
|
67
|
+
serverName?: string;
|
|
68
|
+
}): Promise<AuthorizeResult>;
|
|
69
|
+
private ensureKek;
|
|
70
|
+
private dispatchTenant;
|
|
71
|
+
private dispatchVault;
|
|
72
|
+
summary(): TenantSummary;
|
|
73
|
+
drain(activeWork: "drain" | "cancel", timeoutMs?: number): Promise<void>;
|
|
74
|
+
close(): Promise<void>;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Open a Tenant Runtime from an explicit `TenantConfig`. No listen() (A1).
|
|
78
|
+
* Implements `OpenTenantRuntime`.
|
|
79
|
+
*/
|
|
80
|
+
export declare function openTenantRuntime(config: TenantConfig, hooks?: TenantOpenHooks): Promise<TenantHandle>;
|