@rivet-dev/agentos-core 0.0.0-main.2f99c77 → 0.0.0-main.5ac5a14
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/README.md +10 -196
- package/dist/agent-os.d.ts +508 -271
- package/dist/agent-os.js +2277 -1243
- package/dist/agentos-package.d.ts +6 -4
- package/dist/agentos-package.js +6 -3
- package/dist/base-filesystem.js +2 -2
- package/dist/{host-tools-zod.d.ts → bindings-zod.d.ts} +1 -1
- package/dist/{host-tools-zod.js → bindings-zod.js} +27 -20
- package/dist/bindings.d.ts +43 -0
- package/dist/bindings.js +34 -0
- package/dist/code-execution.d.ts +70 -0
- package/dist/code-execution.js +115 -0
- package/dist/cron/cron-manager.js +43 -10
- package/dist/cron/index.d.ts +1 -1
- package/dist/cron/types.d.ts +25 -9
- package/dist/filesystem-snapshot.d.ts +1 -2
- package/dist/filesystem-snapshot.js +0 -43
- package/dist/generated/AcpLimitsConfig.d.ts +16 -0
- package/dist/generated/BindingLimitsConfig.d.ts +10 -0
- package/dist/generated/CreateVmConfig.d.ts +2 -0
- package/dist/generated/ProcessLimitsConfig.d.ts +7 -0
- package/dist/generated/ProcessLimitsConfig.js +2 -0
- package/dist/generated/VmGroupConfig.d.ts +5 -0
- package/dist/generated/VmGroupConfig.js +2 -0
- package/dist/generated/VmLimitsConfig.d.ts +4 -2
- package/dist/generated/VmUserAccountConfig.d.ts +9 -0
- package/dist/generated/VmUserAccountConfig.js +2 -0
- package/dist/generated/VmUserConfig.d.ts +19 -0
- package/dist/generated/WasmLimitsConfig.d.ts +1 -0
- package/dist/index.d.ts +7 -5
- package/dist/index.js +5 -5
- package/dist/language-execution.d.ts +170 -0
- package/dist/language-execution.js +1 -0
- package/dist/layers.d.ts +5 -2
- package/dist/layers.js +0 -185
- package/dist/options-schema.d.ts +150 -31
- package/dist/options-schema.js +159 -26
- package/dist/packages.d.ts +1 -1
- package/dist/runtime-compat.d.ts +6 -35
- package/dist/runtime-compat.js +85 -373
- package/dist/runtime.d.ts +5 -1
- package/dist/sandbox.d.ts +4 -4
- package/dist/sandbox.js +34 -21
- package/dist/session-api.d.ts +180 -0
- package/dist/session-api.js +1 -0
- package/dist/sidecar/agentos-protocol.d.ts +434 -32
- package/dist/sidecar/agentos-protocol.js +693 -93
- package/dist/sidecar/rpc-client.d.ts +18 -6
- package/dist/sidecar/rpc-client.js +88 -39
- package/dist/test/runtime.d.ts +2 -1
- package/dist/test/runtime.js +2 -1
- package/dist/test/terminal-harness.js +0 -3
- package/dist/types.d.ts +7 -6
- package/package.json +38 -28
- package/dist/agent-session-types.d.ts +0 -67
- package/dist/generated/ToolLimitsConfig.d.ts +0 -10
- package/dist/host-tools.d.ts +0 -45
- package/dist/host-tools.js +0 -35
- package/dist/overlay-filesystem.d.ts +0 -19
- package/dist/overlay-filesystem.js +0 -645
- /package/dist/generated/{ToolLimitsConfig.js → BindingLimitsConfig.js} +0 -0
- /package/dist/{agent-session-types.js → generated/VmUserConfig.js} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { VirtualFileSystem } from "./runtime-compat.js";
|
|
2
2
|
export interface FilesystemEntry {
|
|
3
3
|
path: string;
|
|
4
4
|
type: "directory" | "file" | "symlink";
|
|
@@ -10,5 +10,4 @@ export interface FilesystemEntry {
|
|
|
10
10
|
target?: string;
|
|
11
11
|
}
|
|
12
12
|
export declare function sortFilesystemEntries(entries: FilesystemEntry[]): FilesystemEntry[];
|
|
13
|
-
export declare function createFilesystemFromEntries(entries: FilesystemEntry[]): Promise<VirtualFileSystem>;
|
|
14
13
|
export declare function snapshotVirtualFilesystem(filesystem: VirtualFileSystem, rootPath?: string): Promise<FilesystemEntry[]>;
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
import * as posixPath from "node:path/posix";
|
|
2
|
-
import { createInMemoryFileSystem, } from "./runtime-compat.js";
|
|
3
|
-
function parseMode(mode) {
|
|
4
|
-
return Number.parseInt(mode, 8);
|
|
5
|
-
}
|
|
6
2
|
export function sortFilesystemEntries(entries) {
|
|
7
3
|
return [...entries].sort((a, b) => {
|
|
8
4
|
const depthA = a.path === "/" ? 0 : a.path.split("/").filter(Boolean).length;
|
|
@@ -13,45 +9,6 @@ export function sortFilesystemEntries(entries) {
|
|
|
13
9
|
return a.path.localeCompare(b.path);
|
|
14
10
|
});
|
|
15
11
|
}
|
|
16
|
-
async function applyDirectory(filesystem, entry) {
|
|
17
|
-
if (entry.path !== "/") {
|
|
18
|
-
await filesystem.mkdir(entry.path, { recursive: true });
|
|
19
|
-
}
|
|
20
|
-
await filesystem.chmod(entry.path, parseMode(entry.mode));
|
|
21
|
-
await filesystem.chown(entry.path, entry.uid, entry.gid);
|
|
22
|
-
}
|
|
23
|
-
async function applyFile(filesystem, entry) {
|
|
24
|
-
const content = entry.content ?? "";
|
|
25
|
-
await filesystem.writeFile(entry.path, entry.encoding === "base64" ? Buffer.from(content, "base64") : content);
|
|
26
|
-
await filesystem.chmod(entry.path, parseMode(entry.mode));
|
|
27
|
-
await filesystem.chown(entry.path, entry.uid, entry.gid);
|
|
28
|
-
}
|
|
29
|
-
async function applySymlink(filesystem, entry) {
|
|
30
|
-
if (!entry.target) {
|
|
31
|
-
throw new Error(`Missing symlink target for ${entry.path}`);
|
|
32
|
-
}
|
|
33
|
-
await filesystem.symlink(entry.target, entry.path);
|
|
34
|
-
}
|
|
35
|
-
export async function createFilesystemFromEntries(entries) {
|
|
36
|
-
const filesystem = createInMemoryFileSystem();
|
|
37
|
-
const sortedEntries = sortFilesystemEntries(entries);
|
|
38
|
-
for (const entry of sortedEntries) {
|
|
39
|
-
if (entry.type === "directory") {
|
|
40
|
-
await applyDirectory(filesystem, entry);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
for (const entry of sortedEntries) {
|
|
44
|
-
if (entry.type === "file") {
|
|
45
|
-
await applyFile(filesystem, entry);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
for (const entry of sortedEntries) {
|
|
49
|
-
if (entry.type === "symlink") {
|
|
50
|
-
await applySymlink(filesystem, entry);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return filesystem;
|
|
54
|
-
}
|
|
55
12
|
function toModeString(mode) {
|
|
56
13
|
return `0${(mode & 0o7777).toString(8)}`;
|
|
57
14
|
}
|
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
export type AcpLimitsConfig = {
|
|
2
2
|
maxReadLineBytes?: number;
|
|
3
3
|
stdoutBufferByteLimit?: number;
|
|
4
|
+
maxCompletedMessageBytes?: number;
|
|
5
|
+
maxTurnOutputBytes?: number;
|
|
6
|
+
maxPromptBytes?: number;
|
|
7
|
+
maxPromptBlocks?: number;
|
|
8
|
+
maxFallbackContinuationBytes?: number;
|
|
9
|
+
maxSessionHistoryBytes?: number;
|
|
10
|
+
maxSessionHistoryEvents?: number;
|
|
11
|
+
maxHistoryPageEntries?: number;
|
|
12
|
+
maxSessionListEntries?: number;
|
|
13
|
+
maxSessionsPerVm?: number;
|
|
14
|
+
maxPromptsPerSession?: number;
|
|
15
|
+
maxPromptsPerVm?: number;
|
|
16
|
+
maxPendingPermissionsPerSession?: number;
|
|
17
|
+
maxPendingPermissionsPerVm?: number;
|
|
18
|
+
maxPermissionOutcomesPerSession?: number;
|
|
19
|
+
maxPermissionOutcomesPerVm?: number;
|
|
4
20
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type BindingLimitsConfig = {
|
|
2
|
+
defaultBindingTimeoutMs?: number;
|
|
3
|
+
maxBindingTimeoutMs?: number;
|
|
4
|
+
maxRegisteredCollections?: number;
|
|
5
|
+
maxRegisteredBindingsPerVm?: number;
|
|
6
|
+
maxBindingsPerCollection?: number;
|
|
7
|
+
maxBindingSchemaBytes?: number;
|
|
8
|
+
maxExamplesPerBinding?: number;
|
|
9
|
+
maxBindingExampleInputBytes?: number;
|
|
10
|
+
};
|
|
@@ -5,6 +5,7 @@ import type { RootFilesystemConfig } from "./RootFilesystemConfig.js";
|
|
|
5
5
|
import type { VmDnsConfig } from "./VmDnsConfig.js";
|
|
6
6
|
import type { VmLimitsConfig } from "./VmLimitsConfig.js";
|
|
7
7
|
import type { VmListenPolicyConfig } from "./VmListenPolicyConfig.js";
|
|
8
|
+
import type { VmUserConfig } from "./VmUserConfig.js";
|
|
8
9
|
/**
|
|
9
10
|
* Canonical Rust-side VM config. Unknown fields must stay rejected here and in
|
|
10
11
|
* the TS preflight schema at
|
|
@@ -14,6 +15,7 @@ import type { VmListenPolicyConfig } from "./VmListenPolicyConfig.js";
|
|
|
14
15
|
export type CreateVmConfig = {
|
|
15
16
|
cwd?: string;
|
|
16
17
|
env: Record<string, string>;
|
|
18
|
+
user?: VmUserConfig;
|
|
17
19
|
rootFilesystem: RootFilesystemConfig;
|
|
18
20
|
permissions?: PermissionsPolicy;
|
|
19
21
|
limits?: VmLimitsConfig;
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import type { AcpLimitsConfig } from "./AcpLimitsConfig.js";
|
|
2
|
+
import type { BindingLimitsConfig } from "./BindingLimitsConfig.js";
|
|
2
3
|
import type { HttpLimitsConfig } from "./HttpLimitsConfig.js";
|
|
3
4
|
import type { JsRuntimeLimitsConfig } from "./JsRuntimeLimitsConfig.js";
|
|
4
5
|
import type { PluginLimitsConfig } from "./PluginLimitsConfig.js";
|
|
6
|
+
import type { ProcessLimitsConfig } from "./ProcessLimitsConfig.js";
|
|
5
7
|
import type { PythonLimitsConfig } from "./PythonLimitsConfig.js";
|
|
6
8
|
import type { ResourceLimitsConfig } from "./ResourceLimitsConfig.js";
|
|
7
|
-
import type { ToolLimitsConfig } from "./ToolLimitsConfig.js";
|
|
8
9
|
import type { WasmLimitsConfig } from "./WasmLimitsConfig.js";
|
|
9
10
|
export type VmLimitsConfig = {
|
|
10
11
|
resources?: ResourceLimitsConfig;
|
|
11
12
|
http?: HttpLimitsConfig;
|
|
12
|
-
|
|
13
|
+
bindings?: BindingLimitsConfig;
|
|
13
14
|
plugins?: PluginLimitsConfig;
|
|
14
15
|
acp?: AcpLimitsConfig;
|
|
15
16
|
jsRuntime?: JsRuntimeLimitsConfig;
|
|
16
17
|
python?: PythonLimitsConfig;
|
|
17
18
|
wasm?: WasmLimitsConfig;
|
|
19
|
+
process?: ProcessLimitsConfig;
|
|
18
20
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { VmGroupConfig } from "./VmGroupConfig.js";
|
|
2
|
+
import type { VmUserAccountConfig } from "./VmUserAccountConfig.js";
|
|
3
|
+
/**
|
|
4
|
+
* Initial Linux-style credentials and account record for processes in a VM.
|
|
5
|
+
*/
|
|
6
|
+
export type VmUserConfig = {
|
|
7
|
+
uid?: number;
|
|
8
|
+
gid?: number;
|
|
9
|
+
euid?: number;
|
|
10
|
+
egid?: number;
|
|
11
|
+
username?: string;
|
|
12
|
+
homedir?: string;
|
|
13
|
+
shell?: string;
|
|
14
|
+
gecos?: string;
|
|
15
|
+
groupName?: string;
|
|
16
|
+
supplementaryGids?: Array<number>;
|
|
17
|
+
accounts?: Array<VmUserAccountConfig>;
|
|
18
|
+
groups?: Array<VmGroupConfig>;
|
|
19
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
export { AgentOs, AgentOsSidecar } from "./agent-os.js";
|
|
2
|
+
export type * from "./language-execution.js";
|
|
2
3
|
export { CronManager, InvalidScheduleError, PastScheduleError, TimerScheduleDriver, } from "./cron/index.js";
|
|
3
4
|
export { createHostDirBackend, nodeModulesMount } from "./host-dir-mount.js";
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
5
|
+
export { binding, MAX_BINDING_DESCRIPTION_LENGTH, bindings, validateBindings, } from "./bindings.js";
|
|
6
|
+
export type { Binding, BindingExample, Bindings } from "./bindings.js";
|
|
7
|
+
export { agentOsLimitsSchema, agentOsOptionFieldSchemas, agentOsOptionsSchema, bindingSchema, mountConfigSchema, nativeMountConfigSchema, parseAgentOsOptions, permissionsSchema, rootFilesystemConfigSchema, sharedSidecarConfigSchema, sidecarConfigSchema, bindingsSchema, } from "./options-schema.js";
|
|
8
|
+
export { createSnapshotExport } from "./layers.js";
|
|
7
9
|
export { defineSoftware } from "./packages.js";
|
|
8
10
|
export { isPackageDescriptor, OPT_AGENTOS_BIN, OPT_AGENTOS_ROOT, tryReadAgentosPackageManifest, } from "./agentos-package.js";
|
|
9
|
-
export {
|
|
10
|
-
export { createInMemoryFileSystem, KernelError } from "./runtime-compat.js";
|
|
11
|
+
export { KernelError } from "./runtime-compat.js";
|
|
11
12
|
export type { ExecOptions, ExecResult, ManagedProcess, ProcessInfo, ShellHandle, VirtualDirEntry, VirtualStat, } from "./runtime.js";
|
|
13
|
+
export { createSandboxBindings, createSandboxFs, getSandboxDisposeHooks, resolveSandboxOptions, } from "./sandbox.js";
|
|
12
14
|
export type * from "./types.js";
|
package/dist/index.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
export { AgentOs, AgentOsSidecar } from "./agent-os.js";
|
|
3
3
|
export { CronManager, InvalidScheduleError, PastScheduleError, TimerScheduleDriver, } from "./cron/index.js";
|
|
4
4
|
export { createHostDirBackend, nodeModulesMount } from "./host-dir-mount.js";
|
|
5
|
-
export {
|
|
6
|
-
export { agentOsLimitsSchema, agentOsOptionFieldSchemas, agentOsOptionsSchema,
|
|
7
|
-
export {
|
|
5
|
+
export { binding, MAX_BINDING_DESCRIPTION_LENGTH, bindings, validateBindings, } from "./bindings.js";
|
|
6
|
+
export { agentOsLimitsSchema, agentOsOptionFieldSchemas, agentOsOptionsSchema, bindingSchema, mountConfigSchema, nativeMountConfigSchema, parseAgentOsOptions, permissionsSchema, rootFilesystemConfigSchema, sharedSidecarConfigSchema, sidecarConfigSchema, bindingsSchema, } from "./options-schema.js";
|
|
7
|
+
export { createSnapshotExport } from "./layers.js";
|
|
8
8
|
export { defineSoftware } from "./packages.js";
|
|
9
9
|
export { isPackageDescriptor, OPT_AGENTOS_BIN, OPT_AGENTOS_ROOT, tryReadAgentosPackageManifest, } from "./agentos-package.js";
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
10
|
+
export { KernelError } from "./runtime-compat.js";
|
|
11
|
+
export { createSandboxBindings, createSandboxFs, getSandboxDisposeHooks, resolveSandboxOptions, } from "./sandbox.js";
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import type { JsonValue } from "./session-api.js";
|
|
2
|
+
export type ExecutionSignal = "SIGHUP" | "SIGINT" | "SIGQUIT" | "SIGTERM" | "SIGKILL" | "SIGSTOP" | "SIGCONT" | "SIGUSR1" | "SIGUSR2";
|
|
3
|
+
export interface LanguageExecutionOptions {
|
|
4
|
+
contextId?: string;
|
|
5
|
+
cwd?: string;
|
|
6
|
+
env?: Record<string, string>;
|
|
7
|
+
args?: string[];
|
|
8
|
+
stdin?: string | Uint8Array;
|
|
9
|
+
timeoutMs?: number;
|
|
10
|
+
pty?: {
|
|
11
|
+
cols?: number;
|
|
12
|
+
rows?: number;
|
|
13
|
+
};
|
|
14
|
+
signal?: AbortSignal;
|
|
15
|
+
onStdout?: (chunk: Uint8Array) => void;
|
|
16
|
+
onStderr?: (chunk: Uint8Array) => void;
|
|
17
|
+
output?: ExecutionOutputOptions;
|
|
18
|
+
}
|
|
19
|
+
export type OutputCapture = "none" | "stderr" | "all";
|
|
20
|
+
export interface ExecutionOutputOptions {
|
|
21
|
+
capture?: OutputCapture;
|
|
22
|
+
retainEvents?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export interface InlineExecutionOptions extends LanguageExecutionOptions {
|
|
25
|
+
inputs?: Record<string, JsonValue>;
|
|
26
|
+
}
|
|
27
|
+
export interface JavaScriptExecutionOptions extends InlineExecutionOptions {
|
|
28
|
+
format?: "module" | "commonjs";
|
|
29
|
+
filePath?: string;
|
|
30
|
+
}
|
|
31
|
+
export type JavaScriptEvaluationOptions = JavaScriptExecutionOptions;
|
|
32
|
+
export interface TypeScriptExecutionOptions extends InlineExecutionOptions {
|
|
33
|
+
filePath?: string;
|
|
34
|
+
tsconfigPath?: string;
|
|
35
|
+
compilerOptions?: Record<string, JsonValue>;
|
|
36
|
+
}
|
|
37
|
+
export type TypeScriptEvaluationOptions = TypeScriptExecutionOptions;
|
|
38
|
+
export interface TypeScriptFileExecutionOptions extends LanguageExecutionOptions {
|
|
39
|
+
tsconfigPath?: string;
|
|
40
|
+
compilerOptions?: Record<string, JsonValue>;
|
|
41
|
+
}
|
|
42
|
+
export interface TypeScriptCheckOptions {
|
|
43
|
+
contextId?: string;
|
|
44
|
+
cwd?: string;
|
|
45
|
+
filePath?: string;
|
|
46
|
+
tsconfigPath?: string;
|
|
47
|
+
compilerOptions?: Record<string, JsonValue>;
|
|
48
|
+
timeoutMs?: number;
|
|
49
|
+
signal?: AbortSignal;
|
|
50
|
+
output?: ExecutionOutputOptions;
|
|
51
|
+
}
|
|
52
|
+
export interface NpmProjectInstallOptions extends Omit<LanguageExecutionOptions, "args" | "stdin"> {
|
|
53
|
+
frozen?: boolean;
|
|
54
|
+
}
|
|
55
|
+
export interface NpmPackageInstallOptions extends Omit<LanguageExecutionOptions, "args" | "stdin"> {
|
|
56
|
+
dev?: boolean;
|
|
57
|
+
global?: boolean;
|
|
58
|
+
}
|
|
59
|
+
export interface PythonInstallOptions extends Omit<LanguageExecutionOptions, "args" | "stdin"> {
|
|
60
|
+
upgrade?: boolean;
|
|
61
|
+
requirementsFile?: string;
|
|
62
|
+
indexUrl?: string;
|
|
63
|
+
extraIndexUrls?: string[];
|
|
64
|
+
}
|
|
65
|
+
export type ContextState = "idle" | "running" | "resetting" | "deleting" | "failed";
|
|
66
|
+
export type ExecutionOutcome = "succeeded" | "failed" | "cancelled" | "timed_out";
|
|
67
|
+
export interface ContextDescriptor {
|
|
68
|
+
contextId: string;
|
|
69
|
+
state: ContextState;
|
|
70
|
+
language?: "javascript" | "python";
|
|
71
|
+
createdAtMs: number;
|
|
72
|
+
lastStartedAtMs?: number;
|
|
73
|
+
lastCompletedAtMs?: number;
|
|
74
|
+
}
|
|
75
|
+
export interface ProcessDescriptor {
|
|
76
|
+
pid: number;
|
|
77
|
+
state: "running" | "exited";
|
|
78
|
+
language?: "javascript" | "python";
|
|
79
|
+
command?: string;
|
|
80
|
+
startedAtMs: number;
|
|
81
|
+
}
|
|
82
|
+
export interface ProcessExit {
|
|
83
|
+
pid: number;
|
|
84
|
+
outcome: "exited" | "signalled" | "timed_out";
|
|
85
|
+
exitCode?: number;
|
|
86
|
+
signal?: ExecutionSignal;
|
|
87
|
+
}
|
|
88
|
+
export interface SpawnOptions {
|
|
89
|
+
cwd?: string;
|
|
90
|
+
env?: Record<string, string>;
|
|
91
|
+
args?: string[];
|
|
92
|
+
stdin?: string | Uint8Array;
|
|
93
|
+
timeoutMs?: number;
|
|
94
|
+
pty?: {
|
|
95
|
+
cols?: number;
|
|
96
|
+
rows?: number;
|
|
97
|
+
};
|
|
98
|
+
signal?: AbortSignal;
|
|
99
|
+
onStdout?: (chunk: Uint8Array) => void;
|
|
100
|
+
onStderr?: (chunk: Uint8Array) => void;
|
|
101
|
+
output?: {
|
|
102
|
+
retainEvents?: boolean;
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
export type LanguageSpawnOptions = SpawnOptions;
|
|
106
|
+
export interface ExecutionErrorData {
|
|
107
|
+
code: string;
|
|
108
|
+
name: string;
|
|
109
|
+
message: string;
|
|
110
|
+
stack?: string;
|
|
111
|
+
details?: JsonValue;
|
|
112
|
+
}
|
|
113
|
+
interface CodeExecutionResultBase {
|
|
114
|
+
exitCode?: number;
|
|
115
|
+
stdout?: string;
|
|
116
|
+
stderr?: string;
|
|
117
|
+
stdoutTruncated?: boolean;
|
|
118
|
+
stderrTruncated?: boolean;
|
|
119
|
+
}
|
|
120
|
+
type ExecutionResultOutcome<TIdentity> = (CodeExecutionResultBase & {
|
|
121
|
+
outcome: "succeeded";
|
|
122
|
+
error?: never;
|
|
123
|
+
} & TIdentity) | (CodeExecutionResultBase & {
|
|
124
|
+
outcome: Exclude<ExecutionOutcome, "succeeded">;
|
|
125
|
+
error: ExecutionErrorData;
|
|
126
|
+
} & TIdentity);
|
|
127
|
+
export type CodeExecutionResult = ExecutionResultOutcome<Record<never, never>>;
|
|
128
|
+
export type CodeEvaluationResult<T = JsonValue> = (CodeExecutionResultBase & {
|
|
129
|
+
outcome: "succeeded";
|
|
130
|
+
error?: never;
|
|
131
|
+
value: T;
|
|
132
|
+
}) | (CodeExecutionResultBase & {
|
|
133
|
+
outcome: Exclude<ExecutionOutcome, "succeeded">;
|
|
134
|
+
error: ExecutionErrorData;
|
|
135
|
+
value?: never;
|
|
136
|
+
});
|
|
137
|
+
export interface TypeScriptDiagnostic {
|
|
138
|
+
code: number;
|
|
139
|
+
category: "error" | "warning" | "suggestion" | "message";
|
|
140
|
+
message: string;
|
|
141
|
+
filePath?: string;
|
|
142
|
+
line?: number;
|
|
143
|
+
column?: number;
|
|
144
|
+
}
|
|
145
|
+
export type TypeScriptCheckResult = (CodeExecutionResultBase & {
|
|
146
|
+
outcome: "succeeded";
|
|
147
|
+
error?: never;
|
|
148
|
+
hasErrors: boolean;
|
|
149
|
+
diagnostics: TypeScriptDiagnostic[];
|
|
150
|
+
}) | (CodeExecutionResultBase & {
|
|
151
|
+
outcome: Exclude<ExecutionOutcome, "succeeded">;
|
|
152
|
+
error: ExecutionErrorData;
|
|
153
|
+
hasErrors?: never;
|
|
154
|
+
diagnostics: TypeScriptDiagnostic[];
|
|
155
|
+
});
|
|
156
|
+
export interface ProcessOutputEvent<TChunk = Uint8Array> {
|
|
157
|
+
pid: number;
|
|
158
|
+
sequence: number;
|
|
159
|
+
channel: "stdout" | "stderr" | "pty";
|
|
160
|
+
chunk: TChunk;
|
|
161
|
+
timestampMs: number;
|
|
162
|
+
}
|
|
163
|
+
export interface OutputReplay<TChunk = Uint8Array> {
|
|
164
|
+
pid: number;
|
|
165
|
+
events: ProcessOutputEvent<TChunk>[];
|
|
166
|
+
nextCursor: string;
|
|
167
|
+
hasMore: boolean;
|
|
168
|
+
truncated: boolean;
|
|
169
|
+
}
|
|
170
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/layers.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BaseFilesystemSnapshot } from "./base-filesystem.js";
|
|
2
|
-
import {
|
|
2
|
+
import type { FilesystemEntry } from "./filesystem-snapshot.js";
|
|
3
3
|
import type { VirtualFileSystem } from "./runtime-compat.js";
|
|
4
4
|
export type OverlayFilesystemMode = "ephemeral" | "read-only";
|
|
5
5
|
export interface FilesystemSnapshotExport {
|
|
@@ -31,6 +31,10 @@ export type SnapshotImportSource = {
|
|
|
31
31
|
kind: "snapshot-export";
|
|
32
32
|
source: FilesystemSnapshotExport | unknown;
|
|
33
33
|
};
|
|
34
|
+
/**
|
|
35
|
+
* Caller-provided durable layer store. AgentOS forwards these explicit handles
|
|
36
|
+
* but does not provide a second client-side filesystem or overlay engine.
|
|
37
|
+
*/
|
|
34
38
|
export interface LayerStore {
|
|
35
39
|
readonly storeId: string;
|
|
36
40
|
createWritableLayer(): Promise<WritableLayerHandle>;
|
|
@@ -48,4 +52,3 @@ export interface LayerStore {
|
|
|
48
52
|
dispose(): void;
|
|
49
53
|
}
|
|
50
54
|
export declare function createSnapshotExport(entries: FilesystemEntry[]): RootSnapshotExport;
|
|
51
|
-
export declare function createInMemoryLayerStore(): LayerStore;
|
package/dist/layers.js
CHANGED
|
@@ -1,52 +1,3 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { createFilesystemFromEntries, snapshotVirtualFilesystem, } from "./filesystem-snapshot.js";
|
|
3
|
-
import { createOverlayBackend } from "./overlay-filesystem.js";
|
|
4
|
-
function cloneSnapshotHandle(storeId, layerId) {
|
|
5
|
-
return { kind: "snapshot", storeId, layerId };
|
|
6
|
-
}
|
|
7
|
-
function cloneWritableHandle(storeId, layerId, leaseId) {
|
|
8
|
-
return { kind: "writable", storeId, layerId, leaseId };
|
|
9
|
-
}
|
|
10
|
-
function isBaseFilesystemSnapshot(value) {
|
|
11
|
-
if (!value || typeof value !== "object") {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
const filesystem = value.filesystem;
|
|
15
|
-
if (!filesystem || typeof filesystem !== "object") {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
return Array.isArray(filesystem.entries);
|
|
19
|
-
}
|
|
20
|
-
function isFilesystemSnapshotExport(value) {
|
|
21
|
-
if (!value || typeof value !== "object") {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
if (value.format !== "agentos-filesystem-snapshot-v1") {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
const filesystem = value.filesystem;
|
|
28
|
-
if (!filesystem || typeof filesystem !== "object") {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
return Array.isArray(filesystem.entries);
|
|
32
|
-
}
|
|
33
|
-
function normalizeSnapshotExport(source) {
|
|
34
|
-
if (source.kind === "base-filesystem-artifact") {
|
|
35
|
-
if (!isBaseFilesystemSnapshot(source.source)) {
|
|
36
|
-
throw new Error("Invalid base filesystem artifact");
|
|
37
|
-
}
|
|
38
|
-
return {
|
|
39
|
-
format: "agentos-filesystem-snapshot-v1",
|
|
40
|
-
filesystem: {
|
|
41
|
-
entries: source.source.filesystem.entries,
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
if (!isFilesystemSnapshotExport(source.source)) {
|
|
46
|
-
throw new Error("Invalid snapshot export");
|
|
47
|
-
}
|
|
48
|
-
return source.source;
|
|
49
|
-
}
|
|
50
1
|
export function createSnapshotExport(entries) {
|
|
51
2
|
return {
|
|
52
3
|
kind: "snapshot-export",
|
|
@@ -56,139 +7,3 @@ export function createSnapshotExport(entries) {
|
|
|
56
7
|
},
|
|
57
8
|
};
|
|
58
9
|
}
|
|
59
|
-
export function createInMemoryLayerStore() {
|
|
60
|
-
const storeId = `memory-layer-store:${randomUUID()}`;
|
|
61
|
-
const layers = new Map();
|
|
62
|
-
function getLayerState(handle) {
|
|
63
|
-
if (handle.storeId !== storeId) {
|
|
64
|
-
throw new Error(`Layer ${handle.layerId} belongs to store ${handle.storeId}, not ${storeId}`);
|
|
65
|
-
}
|
|
66
|
-
const state = layers.get(handle.layerId);
|
|
67
|
-
if (!state) {
|
|
68
|
-
throw new Error(`Unknown layer: ${handle.layerId}`);
|
|
69
|
-
}
|
|
70
|
-
if (state.kind !== handle.kind) {
|
|
71
|
-
throw new Error(`Layer kind mismatch for ${handle.layerId}`);
|
|
72
|
-
}
|
|
73
|
-
return state;
|
|
74
|
-
}
|
|
75
|
-
const store = {
|
|
76
|
-
storeId,
|
|
77
|
-
get retainedLayerCount() {
|
|
78
|
-
return layers.size;
|
|
79
|
-
},
|
|
80
|
-
async createWritableLayer() {
|
|
81
|
-
const layerId = randomUUID();
|
|
82
|
-
const leaseId = randomUUID();
|
|
83
|
-
layers.set(layerId, {
|
|
84
|
-
kind: "writable",
|
|
85
|
-
fs: await createFilesystemFromEntries([
|
|
86
|
-
{
|
|
87
|
-
path: "/",
|
|
88
|
-
type: "directory",
|
|
89
|
-
mode: "0755",
|
|
90
|
-
uid: 0,
|
|
91
|
-
gid: 0,
|
|
92
|
-
},
|
|
93
|
-
]),
|
|
94
|
-
leaseId,
|
|
95
|
-
valid: true,
|
|
96
|
-
activeOverlay: null,
|
|
97
|
-
});
|
|
98
|
-
return cloneWritableHandle(storeId, layerId, leaseId);
|
|
99
|
-
},
|
|
100
|
-
async importSnapshot(source) {
|
|
101
|
-
const snapshot = normalizeSnapshotExport(source);
|
|
102
|
-
const layerId = randomUUID();
|
|
103
|
-
layers.set(layerId, {
|
|
104
|
-
kind: "snapshot",
|
|
105
|
-
snapshot,
|
|
106
|
-
fs: await createFilesystemFromEntries(snapshot.filesystem.entries),
|
|
107
|
-
});
|
|
108
|
-
return cloneSnapshotHandle(storeId, layerId);
|
|
109
|
-
},
|
|
110
|
-
async openSnapshotLayer(layerId) {
|
|
111
|
-
const state = layers.get(layerId);
|
|
112
|
-
if (!state || state.kind !== "snapshot") {
|
|
113
|
-
throw new Error(`Unknown snapshot layer: ${layerId}`);
|
|
114
|
-
}
|
|
115
|
-
return cloneSnapshotHandle(storeId, layerId);
|
|
116
|
-
},
|
|
117
|
-
async sealLayer(layer) {
|
|
118
|
-
const state = getLayerState(layer);
|
|
119
|
-
if (state.kind !== "writable") {
|
|
120
|
-
throw new Error(`Layer ${layer.layerId} is not writable`);
|
|
121
|
-
}
|
|
122
|
-
const baseFs = state.activeOverlay ?? state.fs;
|
|
123
|
-
if (!state.valid || state.leaseId !== layer.leaseId || !baseFs) {
|
|
124
|
-
throw new Error(`Writable layer ${layer.layerId} is no longer valid`);
|
|
125
|
-
}
|
|
126
|
-
const entries = await snapshotVirtualFilesystem(baseFs);
|
|
127
|
-
const snapshot = createSnapshotExport(entries).source;
|
|
128
|
-
const layerId = randomUUID();
|
|
129
|
-
layers.set(layerId, {
|
|
130
|
-
kind: "snapshot",
|
|
131
|
-
snapshot,
|
|
132
|
-
fs: await createFilesystemFromEntries(snapshot.filesystem.entries),
|
|
133
|
-
});
|
|
134
|
-
// Release the writable layer's filesystem payload now that it is sealed;
|
|
135
|
-
// the invalid tombstone is retained so stale handles still report cleanly.
|
|
136
|
-
state.valid = false;
|
|
137
|
-
state.activeOverlay = null;
|
|
138
|
-
state.fs = null;
|
|
139
|
-
return cloneSnapshotHandle(storeId, layerId);
|
|
140
|
-
},
|
|
141
|
-
createOverlayFilesystem(options) {
|
|
142
|
-
const lowers = options.lowers.map((lower) => {
|
|
143
|
-
const state = getLayerState(lower);
|
|
144
|
-
if (state.kind !== "snapshot") {
|
|
145
|
-
throw new Error(`Layer ${lower.layerId} is not a snapshot`);
|
|
146
|
-
}
|
|
147
|
-
return lower;
|
|
148
|
-
});
|
|
149
|
-
if (options.mode === "read-only") {
|
|
150
|
-
return createOverlayBackend({
|
|
151
|
-
mode: "read-only",
|
|
152
|
-
lowers: lowers.map((lower) => {
|
|
153
|
-
const state = getLayerState(lower);
|
|
154
|
-
if (state.kind !== "snapshot") {
|
|
155
|
-
throw new Error(`Layer ${lower.layerId} is not a snapshot`);
|
|
156
|
-
}
|
|
157
|
-
return state.fs;
|
|
158
|
-
}),
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
const upperState = getLayerState(options.upper);
|
|
162
|
-
if (upperState.kind !== "writable") {
|
|
163
|
-
throw new Error(`Layer ${options.upper.layerId} is not writable`);
|
|
164
|
-
}
|
|
165
|
-
if (!upperState.valid || upperState.leaseId !== options.upper.leaseId) {
|
|
166
|
-
throw new Error(`Writable layer ${options.upper.layerId} is no longer valid`);
|
|
167
|
-
}
|
|
168
|
-
if (upperState.activeOverlay) {
|
|
169
|
-
throw new Error(`Writable layer ${options.upper.layerId} is already attached to an overlay`);
|
|
170
|
-
}
|
|
171
|
-
if (!upperState.fs) {
|
|
172
|
-
throw new Error(`Writable layer ${options.upper.layerId} is no longer valid`);
|
|
173
|
-
}
|
|
174
|
-
const overlay = createOverlayBackend({
|
|
175
|
-
upper: upperState.fs,
|
|
176
|
-
lowers: lowers.map((lower) => {
|
|
177
|
-
const state = getLayerState(lower);
|
|
178
|
-
if (state.kind !== "snapshot") {
|
|
179
|
-
throw new Error(`Layer ${lower.layerId} is not a snapshot`);
|
|
180
|
-
}
|
|
181
|
-
return state.fs;
|
|
182
|
-
}),
|
|
183
|
-
});
|
|
184
|
-
upperState.activeOverlay = overlay;
|
|
185
|
-
return overlay;
|
|
186
|
-
},
|
|
187
|
-
dispose() {
|
|
188
|
-
// Release every retained layer's filesystem payload so the store does
|
|
189
|
-
// not accumulate snapshots/writable layers for the process lifetime.
|
|
190
|
-
layers.clear();
|
|
191
|
-
},
|
|
192
|
-
};
|
|
193
|
-
return store;
|
|
194
|
-
}
|