@rivet-dev/agentos-core 0.0.0-agentos-dylib-plugin.473700e
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 +204 -0
- package/dist/agent-os.d.ts +560 -0
- package/dist/agent-os.js +3624 -0
- package/dist/agent-session-types.d.ts +67 -0
- package/dist/agent-session-types.js +1 -0
- package/dist/agents.d.ts +63 -0
- package/dist/agents.js +42 -0
- package/dist/base-filesystem.d.ts +34 -0
- package/dist/base-filesystem.js +173 -0
- package/dist/cron/cron-manager.d.ts +22 -0
- package/dist/cron/cron-manager.js +160 -0
- package/dist/cron/index.d.ts +5 -0
- package/dist/cron/index.js +3 -0
- package/dist/cron/parse-schedule.d.ts +25 -0
- package/dist/cron/parse-schedule.js +66 -0
- package/dist/cron/schedule-driver.d.ts +19 -0
- package/dist/cron/schedule-driver.js +1 -0
- package/dist/cron/timer-driver.d.ts +17 -0
- package/dist/cron/timer-driver.js +61 -0
- package/dist/cron/types.d.ts +55 -0
- package/dist/cron/types.js +1 -0
- package/dist/filesystem-snapshot.d.ts +14 -0
- package/dist/filesystem-snapshot.js +105 -0
- package/dist/host-dir-mount.d.ts +38 -0
- package/dist/host-dir-mount.js +34 -0
- package/dist/host-tools-zod.d.ts +7 -0
- package/dist/host-tools-zod.js +243 -0
- package/dist/host-tools.d.ts +45 -0
- package/dist/host-tools.js +26 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -0
- package/dist/js-bridge.d.ts +3 -0
- package/dist/js-bridge.js +2 -0
- package/dist/json-rpc.d.ts +50 -0
- package/dist/json-rpc.js +22 -0
- package/dist/layers.d.ts +51 -0
- package/dist/layers.js +185 -0
- package/dist/overlay-filesystem.d.ts +19 -0
- package/dist/overlay-filesystem.js +645 -0
- package/dist/packages.d.ts +127 -0
- package/dist/packages.js +335 -0
- package/dist/runtime-compat.d.ts +471 -0
- package/dist/runtime-compat.js +2009 -0
- package/dist/runtime.d.ts +336 -0
- package/dist/runtime.js +1 -0
- package/dist/sidecar/agent-os-protocol.d.ts +219 -0
- package/dist/sidecar/agent-os-protocol.js +594 -0
- package/dist/sidecar/binary.d.ts +9 -0
- package/dist/sidecar/binary.js +30 -0
- package/dist/sidecar/cargo.d.ts +2 -0
- package/dist/sidecar/cargo.js +142 -0
- package/dist/sidecar/native-process-client.d.ts +2 -0
- package/dist/sidecar/native-process-client.js +1 -0
- package/dist/sidecar/permissions.d.ts +3 -0
- package/dist/sidecar/permissions.js +54 -0
- package/dist/sidecar/process.d.ts +6 -0
- package/dist/sidecar/process.js +8 -0
- package/dist/sidecar/rpc-client.d.ts +244 -0
- package/dist/sidecar/rpc-client.js +2028 -0
- package/dist/test/docker.d.ts +133 -0
- package/dist/test/docker.js +336 -0
- package/dist/test/file-system.d.ts +39 -0
- package/dist/test/file-system.js +562 -0
- package/dist/test/mock-s3.d.ts +42 -0
- package/dist/test/mock-s3.js +292 -0
- package/dist/test/runtime.d.ts +11 -0
- package/dist/test/runtime.js +9 -0
- package/dist/test/sandbox-agent.d.ts +9 -0
- package/dist/test/sandbox-agent.js +395 -0
- package/dist/test/terminal-harness.d.ts +27 -0
- package/dist/test/terminal-harness.js +122 -0
- package/dist/types.d.ts +10 -0
- package/dist/types.js +1 -0
- package/fixtures/AGENTOS_SYSTEM_PROMPT.md +21 -0
- package/package.json +111 -0
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
import type { NativeMountPluginDescriptor } from "@secure-exec/core/descriptors";
|
|
2
|
+
import type { AgentCapabilities, AgentInfo, PermissionReply, PermissionRequestHandler, SessionConfigOption, SessionEventHandler, SessionModeState } from "./agent-session-types.js";
|
|
3
|
+
import { type ToolKit } from "./host-tools.js";
|
|
4
|
+
import type { JsonRpcResponse } from "./json-rpc.js";
|
|
5
|
+
import type { ConnectTerminalOptions, Kernel, KernelExecOptions, KernelExecResult, ProcessInfo as KernelProcessInfo, KernelSpawnOptions, OpenShellOptions, Permissions, VirtualFileSystem, VirtualStat } from "./runtime-compat.js";
|
|
6
|
+
export type { MountConfigJsonObject, MountConfigJsonPrimitive, MountConfigJsonValue, NativeMountPluginDescriptor, } from "@secure-exec/core/descriptors";
|
|
7
|
+
export type { AgentCapabilities, AgentInfo, PermissionReply, PermissionRequest, PermissionRequestHandler, SessionConfigOption, SessionEventHandler, SessionInitData, SessionMode, SessionModeState, } from "./agent-session-types.js";
|
|
8
|
+
export type { AcpTimeoutErrorData, JsonRpcError, JsonRpcErrorData, JsonRpcNotification, JsonRpcRequest, JsonRpcResponse, } from "./json-rpc.js";
|
|
9
|
+
export { isAcpTimeoutErrorData } from "./json-rpc.js";
|
|
10
|
+
export type { ConnectTerminalOptions } from "./runtime-compat.js";
|
|
11
|
+
/** Process tree node: extends kernel ProcessInfo with child references. */
|
|
12
|
+
export interface ProcessTreeNode extends KernelProcessInfo {
|
|
13
|
+
children: ProcessTreeNode[];
|
|
14
|
+
}
|
|
15
|
+
/** A directory entry with metadata. */
|
|
16
|
+
export interface DirEntry {
|
|
17
|
+
/** Absolute path to the entry. */
|
|
18
|
+
path: string;
|
|
19
|
+
type: "file" | "directory" | "symlink";
|
|
20
|
+
size: number;
|
|
21
|
+
}
|
|
22
|
+
/** Options for readdirRecursive(). */
|
|
23
|
+
export interface ReaddirRecursiveOptions {
|
|
24
|
+
/** Maximum depth to recurse (0 = only immediate children). */
|
|
25
|
+
maxDepth?: number;
|
|
26
|
+
/** Directory names to skip. */
|
|
27
|
+
exclude?: string[];
|
|
28
|
+
}
|
|
29
|
+
/** Entry for batch write operations. */
|
|
30
|
+
export interface BatchWriteEntry {
|
|
31
|
+
path: string;
|
|
32
|
+
content: string | Uint8Array;
|
|
33
|
+
}
|
|
34
|
+
/** Result of a single file in a batch write. */
|
|
35
|
+
export interface BatchWriteResult {
|
|
36
|
+
path: string;
|
|
37
|
+
success: boolean;
|
|
38
|
+
error?: string;
|
|
39
|
+
}
|
|
40
|
+
/** Result of a single file in a batch read. */
|
|
41
|
+
export interface BatchReadResult {
|
|
42
|
+
path: string;
|
|
43
|
+
content: Uint8Array | null;
|
|
44
|
+
error?: string;
|
|
45
|
+
}
|
|
46
|
+
/** Entry in the agent registry, describing an available agent type. */
|
|
47
|
+
export interface AgentRegistryEntry {
|
|
48
|
+
id: string;
|
|
49
|
+
acpAdapter: string;
|
|
50
|
+
agentPackage: string;
|
|
51
|
+
installed: boolean;
|
|
52
|
+
}
|
|
53
|
+
import { type AgentType } from "./agents.js";
|
|
54
|
+
import type { ScheduleDriver } from "./cron/schedule-driver.js";
|
|
55
|
+
import type { CronEventHandler, CronJob, CronJobInfo, CronJobOptions } from "./cron/types.js";
|
|
56
|
+
import { type LayerStore, type OverlayFilesystemMode, type RootSnapshotExport, type SnapshotLayerHandle } from "./layers.js";
|
|
57
|
+
import { type SoftwareInput } from "./packages.js";
|
|
58
|
+
import { type AgentOsSidecarPlacement } from "./sidecar/rpc-client.js";
|
|
59
|
+
export interface AgentOsSharedSidecarOptions {
|
|
60
|
+
pool?: string;
|
|
61
|
+
}
|
|
62
|
+
export interface AgentOsCreateSidecarOptions {
|
|
63
|
+
sidecarId?: string;
|
|
64
|
+
}
|
|
65
|
+
export type AgentOsSidecarConfig = {
|
|
66
|
+
kind: "shared";
|
|
67
|
+
pool?: string;
|
|
68
|
+
} | {
|
|
69
|
+
kind: "explicit";
|
|
70
|
+
handle: AgentOsSidecar;
|
|
71
|
+
};
|
|
72
|
+
export interface AgentOsSidecarDescription {
|
|
73
|
+
sidecarId: string;
|
|
74
|
+
placement: AgentOsSidecarPlacement;
|
|
75
|
+
state: "ready" | "disposing" | "disposed";
|
|
76
|
+
activeVmCount: number;
|
|
77
|
+
}
|
|
78
|
+
export type RootLowerInput = {
|
|
79
|
+
kind: "bundled-base-filesystem";
|
|
80
|
+
} | RootSnapshotExport;
|
|
81
|
+
export interface RootFilesystemConfig {
|
|
82
|
+
type?: "overlay";
|
|
83
|
+
mode?: OverlayFilesystemMode;
|
|
84
|
+
disableDefaultBaseLayer?: boolean;
|
|
85
|
+
lowers?: RootLowerInput[];
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Compatibility path for arbitrary caller-supplied filesystems.
|
|
89
|
+
* This maps to the sidecar `js_bridge` plugin during the migration.
|
|
90
|
+
*/
|
|
91
|
+
export interface PlainMountConfig {
|
|
92
|
+
/** Path inside the VM to mount at. */
|
|
93
|
+
path: string;
|
|
94
|
+
/** The filesystem driver to mount. */
|
|
95
|
+
driver: VirtualFileSystem;
|
|
96
|
+
/** If true, write operations throw EROFS. */
|
|
97
|
+
readOnly?: boolean;
|
|
98
|
+
}
|
|
99
|
+
/** Declarative native mount configuration that the sidecar can serialize. */
|
|
100
|
+
export interface NativeMountConfig {
|
|
101
|
+
path: string;
|
|
102
|
+
plugin: NativeMountPluginDescriptor;
|
|
103
|
+
readOnly?: boolean;
|
|
104
|
+
}
|
|
105
|
+
export interface OverlayMountConfig {
|
|
106
|
+
path: string;
|
|
107
|
+
filesystem: {
|
|
108
|
+
type: "overlay";
|
|
109
|
+
store: LayerStore;
|
|
110
|
+
mode?: OverlayFilesystemMode;
|
|
111
|
+
lowers: SnapshotLayerHandle[];
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
export type MountConfig = PlainMountConfig | NativeMountConfig | OverlayMountConfig;
|
|
115
|
+
/**
|
|
116
|
+
* Operator-tunable runtime limits for a VM. Every field is optional; unset fields fall back to
|
|
117
|
+
* built-in defaults that match the runtime's historical hardcoded constants, so behavior is
|
|
118
|
+
* unchanged unless a value is overridden. All values are JSON-serializable integers and are
|
|
119
|
+
* forwarded to the native sidecar in the typed create-VM JSON config. Unknown, negative, or
|
|
120
|
+
* non-integer values are rejected by the sidecar before VM construction.
|
|
121
|
+
*/
|
|
122
|
+
export interface AgentOsLimits {
|
|
123
|
+
/** Kernel resource limits (processes, FDs, sockets, filesystem bytes, WASM caps, etc.). */
|
|
124
|
+
resources?: {
|
|
125
|
+
cpuCount?: number;
|
|
126
|
+
maxProcesses?: number;
|
|
127
|
+
maxOpenFds?: number;
|
|
128
|
+
maxPipes?: number;
|
|
129
|
+
maxPtys?: number;
|
|
130
|
+
maxSockets?: number;
|
|
131
|
+
maxConnections?: number;
|
|
132
|
+
maxSocketBufferedBytes?: number;
|
|
133
|
+
maxSocketDatagramQueueLen?: number;
|
|
134
|
+
maxFilesystemBytes?: number;
|
|
135
|
+
maxInodeCount?: number;
|
|
136
|
+
maxBlockingReadMs?: number;
|
|
137
|
+
maxPreadBytes?: number;
|
|
138
|
+
maxFdWriteBytes?: number;
|
|
139
|
+
maxProcessArgvBytes?: number;
|
|
140
|
+
maxProcessEnvBytes?: number;
|
|
141
|
+
maxReaddirEntries?: number;
|
|
142
|
+
maxWasmFuel?: number;
|
|
143
|
+
maxWasmMemoryBytes?: number;
|
|
144
|
+
maxWasmStackBytes?: number;
|
|
145
|
+
};
|
|
146
|
+
/** HTTP body buffering limits. */
|
|
147
|
+
http?: {
|
|
148
|
+
/** Cap on `vm.fetch()` buffered response bodies. Must be <= the sidecar wire frame cap. */
|
|
149
|
+
maxFetchResponseBytes?: number;
|
|
150
|
+
};
|
|
151
|
+
/** Host-tool registration and invocation limits. */
|
|
152
|
+
tools?: {
|
|
153
|
+
defaultToolTimeoutMs?: number;
|
|
154
|
+
maxToolTimeoutMs?: number;
|
|
155
|
+
maxRegisteredToolkits?: number;
|
|
156
|
+
maxRegisteredToolsPerVm?: number;
|
|
157
|
+
maxToolsPerToolkit?: number;
|
|
158
|
+
maxToolSchemaBytes?: number;
|
|
159
|
+
maxToolExamplesPerTool?: number;
|
|
160
|
+
maxToolExampleInputBytes?: number;
|
|
161
|
+
};
|
|
162
|
+
/** Mount plugin manifest size limits. */
|
|
163
|
+
plugins?: {
|
|
164
|
+
maxPersistedManifestBytes?: number;
|
|
165
|
+
maxPersistedManifestFileBytes?: number;
|
|
166
|
+
};
|
|
167
|
+
/** ACP adapter buffering limits. */
|
|
168
|
+
acp?: {
|
|
169
|
+
maxReadLineBytes?: number;
|
|
170
|
+
stdoutBufferByteLimit?: number;
|
|
171
|
+
};
|
|
172
|
+
/** Guest JavaScript runtime buffering limits. */
|
|
173
|
+
jsRuntime?: {
|
|
174
|
+
v8HeapLimitMb?: number;
|
|
175
|
+
capturedOutputLimitBytes?: number;
|
|
176
|
+
stdinBufferLimitBytes?: number;
|
|
177
|
+
eventPayloadLimitBytes?: number;
|
|
178
|
+
v8IpcMaxFrameBytes?: number;
|
|
179
|
+
};
|
|
180
|
+
/** Guest Python runtime limits. */
|
|
181
|
+
python?: {
|
|
182
|
+
outputBufferMaxBytes?: number;
|
|
183
|
+
executionTimeoutMs?: number;
|
|
184
|
+
vfsRpcTimeoutMs?: number;
|
|
185
|
+
};
|
|
186
|
+
/** Guest WASM runtime limits. */
|
|
187
|
+
wasm?: {
|
|
188
|
+
maxModuleFileBytes?: number;
|
|
189
|
+
capturedOutputLimitBytes?: number;
|
|
190
|
+
syncReadLimitBytes?: number;
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
export interface AgentOsOptions {
|
|
194
|
+
/**
|
|
195
|
+
* Software to install in the VM. Each entry provides agents, tools,
|
|
196
|
+
* or WASM commands. Any object with a `commandDir` property (e.g.,
|
|
197
|
+
* registry packages like @agent-os-pkgs/coreutils) is treated
|
|
198
|
+
* as a WASM command source automatically. Arrays are flattened, so
|
|
199
|
+
* meta-packages that export arrays of sub-packages work directly.
|
|
200
|
+
*/
|
|
201
|
+
software?: SoftwareInput[];
|
|
202
|
+
/** Loopback ports to exempt from SSRF checks (for testing with host-side mock servers). */
|
|
203
|
+
loopbackExemptPorts?: number[];
|
|
204
|
+
/**
|
|
205
|
+
* Allowed Node.js builtins for guest Node processes.
|
|
206
|
+
* Defaults to the hardened builtin set used by the native sidecar bridge.
|
|
207
|
+
*/
|
|
208
|
+
allowedNodeBuiltins?: string[];
|
|
209
|
+
/** Root filesystem configuration. Defaults to an overlay with the bundled base snapshot as its deepest lower. */
|
|
210
|
+
rootFilesystem?: RootFilesystemConfig;
|
|
211
|
+
/** Filesystems to mount at boot time. */
|
|
212
|
+
mounts?: MountConfig[];
|
|
213
|
+
/** Additional instructions appended to the base OS system prompt injected at session start. */
|
|
214
|
+
additionalInstructions?: string;
|
|
215
|
+
/** Custom schedule driver for cron jobs. Defaults to TimerScheduleDriver. */
|
|
216
|
+
scheduleDriver?: ScheduleDriver;
|
|
217
|
+
/** Host-side toolkits available to agents inside the VM. */
|
|
218
|
+
toolKits?: ToolKit[];
|
|
219
|
+
/**
|
|
220
|
+
* Custom permission policy for the kernel. Controls access to filesystem,
|
|
221
|
+
* network, child process, and environment operations. Defaults to allowAll.
|
|
222
|
+
*/
|
|
223
|
+
permissions?: Permissions;
|
|
224
|
+
/**
|
|
225
|
+
* Sidecar placement for the VM. Defaults to the shared `default` pool.
|
|
226
|
+
* Pass an explicit sidecar handle to pin the VM to a caller-managed sidecar.
|
|
227
|
+
*/
|
|
228
|
+
sidecar?: AgentOsSidecarConfig;
|
|
229
|
+
/**
|
|
230
|
+
* Operator-tunable runtime limits. Unset fields use built-in defaults that match the
|
|
231
|
+
* runtime's historical constants, so omitting this leaves behavior unchanged.
|
|
232
|
+
*/
|
|
233
|
+
limits?: AgentOsLimits;
|
|
234
|
+
}
|
|
235
|
+
/** Configuration for a local MCP server (spawned as a child process). */
|
|
236
|
+
export interface McpServerConfigLocal {
|
|
237
|
+
type: "local";
|
|
238
|
+
/** Command to launch the MCP server. */
|
|
239
|
+
command: string;
|
|
240
|
+
/** Arguments for the command. */
|
|
241
|
+
args?: string[];
|
|
242
|
+
/** Environment variables for the server process. */
|
|
243
|
+
env?: Record<string, string>;
|
|
244
|
+
}
|
|
245
|
+
/** Configuration for a remote MCP server (connected via URL). */
|
|
246
|
+
export interface McpServerConfigRemote {
|
|
247
|
+
type: "remote";
|
|
248
|
+
/** URL of the remote MCP server. */
|
|
249
|
+
url: string;
|
|
250
|
+
/** HTTP headers to include in requests to the server. */
|
|
251
|
+
headers?: Record<string, string>;
|
|
252
|
+
}
|
|
253
|
+
export type McpServerConfig = McpServerConfigLocal | McpServerConfigRemote;
|
|
254
|
+
export interface AgentOsRuntimeAdmin {
|
|
255
|
+
kernel: Kernel;
|
|
256
|
+
rootView: VirtualFileSystem;
|
|
257
|
+
env: Record<string, string>;
|
|
258
|
+
sidecar: AgentOsSidecar;
|
|
259
|
+
}
|
|
260
|
+
export interface CreateSessionOptions {
|
|
261
|
+
/** Working directory for the agent session inside the VM. */
|
|
262
|
+
cwd?: string;
|
|
263
|
+
/** Environment variables to pass to the agent process. */
|
|
264
|
+
env?: Record<string, string>;
|
|
265
|
+
/** MCP servers to make available to the agent during the session. */
|
|
266
|
+
mcpServers?: McpServerConfig[];
|
|
267
|
+
/** Skip OS instructions injection entirely (default false). */
|
|
268
|
+
skipOsInstructions?: boolean;
|
|
269
|
+
/** Additional instructions appended to the base OS instructions. */
|
|
270
|
+
additionalInstructions?: string;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Options for {@link AgentOs.resumeSession}.
|
|
274
|
+
*
|
|
275
|
+
* Resume depends on a durable root: after a Rivet actor sleeps (VM destroyed) and
|
|
276
|
+
* wakes (fresh VM, actor SQLite intact) the caller can keep prompting an existing
|
|
277
|
+
* session. On a non-durable (default in-memory) root there is no surviving store,
|
|
278
|
+
* so the sidecar's universal fallback tier always runs and the transcript pointer
|
|
279
|
+
* is the only continuity mechanism.
|
|
280
|
+
*/
|
|
281
|
+
export interface ResumeSessionOptions {
|
|
282
|
+
/**
|
|
283
|
+
* Guest-readable path to the reconstructed transcript. When present, the
|
|
284
|
+
* fallback tier arms a continuation preamble pointing the agent at it.
|
|
285
|
+
*/
|
|
286
|
+
transcriptPath?: string;
|
|
287
|
+
/** Working directory for the resumed agent session (default `/home/user`). */
|
|
288
|
+
cwd?: string;
|
|
289
|
+
/** Environment variables to pass to the resumed agent process. */
|
|
290
|
+
env?: Record<string, string>;
|
|
291
|
+
}
|
|
292
|
+
/** Result from {@link AgentOs.resumeSession}. */
|
|
293
|
+
export interface ResumeSessionResult {
|
|
294
|
+
/**
|
|
295
|
+
* The live ACP session id in the fresh VM: equal to the requested id for
|
|
296
|
+
* native loads, or a freshly assigned id for the fallback tier — the caller
|
|
297
|
+
* remaps `external -> live`.
|
|
298
|
+
*/
|
|
299
|
+
sessionId: string;
|
|
300
|
+
/** `"native"` (session/load|resume) or `"fallback"` (session/new + preamble). */
|
|
301
|
+
mode: string;
|
|
302
|
+
}
|
|
303
|
+
export interface SessionInfo {
|
|
304
|
+
sessionId: string;
|
|
305
|
+
agentType: string;
|
|
306
|
+
}
|
|
307
|
+
/** Result from AgentOs.prompt(). */
|
|
308
|
+
export interface PromptResult {
|
|
309
|
+
/** Raw JSON-RPC response from the ACP adapter. */
|
|
310
|
+
response: JsonRpcResponse;
|
|
311
|
+
/** Accumulated agent text output from streamed message chunks. */
|
|
312
|
+
text: string;
|
|
313
|
+
}
|
|
314
|
+
/** Information about a process spawned via AgentOs.spawn(). */
|
|
315
|
+
export interface SpawnedProcessInfo {
|
|
316
|
+
pid: number;
|
|
317
|
+
command: string;
|
|
318
|
+
args: string[];
|
|
319
|
+
running: boolean;
|
|
320
|
+
exitCode: number | null;
|
|
321
|
+
}
|
|
322
|
+
export declare class AgentOs {
|
|
323
|
+
#private;
|
|
324
|
+
readonly sidecar: AgentOsSidecar;
|
|
325
|
+
private _sessions;
|
|
326
|
+
private _closedSessionIds;
|
|
327
|
+
private _sessionClosePromises;
|
|
328
|
+
private _pendingSessionRequestResolvers;
|
|
329
|
+
private _processes;
|
|
330
|
+
private _shells;
|
|
331
|
+
private _closedShellIds;
|
|
332
|
+
private _pendingShellExitPromises;
|
|
333
|
+
private _shellCounter;
|
|
334
|
+
private _acpTerminals;
|
|
335
|
+
private _acpTerminalCounter;
|
|
336
|
+
private _softwareRoots;
|
|
337
|
+
private _softwareAgentConfigs;
|
|
338
|
+
private _cronManager;
|
|
339
|
+
private _toolKits;
|
|
340
|
+
private _toolReference;
|
|
341
|
+
private _permissions;
|
|
342
|
+
private _hostMounts;
|
|
343
|
+
private _env;
|
|
344
|
+
private _rootFilesystem;
|
|
345
|
+
private _sidecarLease;
|
|
346
|
+
private readonly _sidecarClient;
|
|
347
|
+
private readonly _sidecarSession;
|
|
348
|
+
private readonly _sidecarVm;
|
|
349
|
+
private readonly _disposeSidecarEventListener;
|
|
350
|
+
private constructor();
|
|
351
|
+
static createSidecar(options?: AgentOsCreateSidecarOptions): Promise<AgentOsSidecar>;
|
|
352
|
+
static getSharedSidecar(options?: AgentOsSharedSidecarOptions): Promise<AgentOsSidecar>;
|
|
353
|
+
static create(options?: AgentOsOptions): Promise<AgentOs>;
|
|
354
|
+
exec(command: string, options?: KernelExecOptions): Promise<KernelExecResult>;
|
|
355
|
+
private _trackProcess;
|
|
356
|
+
spawn(command: string, args: string[], options?: KernelSpawnOptions): {
|
|
357
|
+
pid: number;
|
|
358
|
+
};
|
|
359
|
+
/** Write data to a process's stdin. */
|
|
360
|
+
writeProcessStdin(pid: number, data: string | Uint8Array): void;
|
|
361
|
+
/** Close a process's stdin stream. */
|
|
362
|
+
closeProcessStdin(pid: number): void;
|
|
363
|
+
/** Subscribe to stdout data from a process. Returns an unsubscribe function. */
|
|
364
|
+
onProcessStdout(pid: number, handler: (data: Uint8Array) => void): () => void;
|
|
365
|
+
/** Subscribe to stderr data from a process. Returns an unsubscribe function. */
|
|
366
|
+
onProcessStderr(pid: number, handler: (data: Uint8Array) => void): () => void;
|
|
367
|
+
/** Subscribe to process exit. Returns an unsubscribe function. */
|
|
368
|
+
onProcessExit(pid: number, handler: (exitCode: number) => void): () => void;
|
|
369
|
+
/** Wait for a process to exit. Returns the exit code. */
|
|
370
|
+
waitProcess(pid: number): Promise<number>;
|
|
371
|
+
private _assertSafeAbsolutePath;
|
|
372
|
+
private _assertWritableAbsolutePath;
|
|
373
|
+
private _vfs;
|
|
374
|
+
private _copyPath;
|
|
375
|
+
readFile(path: string): Promise<Uint8Array>;
|
|
376
|
+
writeFile(path: string, content: string | Uint8Array): Promise<void>;
|
|
377
|
+
writeFiles(entries: BatchWriteEntry[]): Promise<BatchWriteResult[]>;
|
|
378
|
+
readFiles(paths: string[]): Promise<BatchReadResult[]>;
|
|
379
|
+
/** Recursively create directories (mkdir -p). */
|
|
380
|
+
private _mkdirp;
|
|
381
|
+
mkdir(path: string, options?: {
|
|
382
|
+
recursive?: boolean;
|
|
383
|
+
}): Promise<void>;
|
|
384
|
+
readdir(path: string): Promise<string[]>;
|
|
385
|
+
readdirRecursive(path: string, options?: ReaddirRecursiveOptions): Promise<DirEntry[]>;
|
|
386
|
+
stat(path: string): Promise<VirtualStat>;
|
|
387
|
+
exists(path: string): Promise<boolean>;
|
|
388
|
+
snapshotRootFilesystem(): Promise<RootSnapshotExport>;
|
|
389
|
+
mountFs(path: string, driver: VirtualFileSystem, options?: {
|
|
390
|
+
readOnly?: boolean;
|
|
391
|
+
}): void;
|
|
392
|
+
unmountFs(path: string): void;
|
|
393
|
+
move(from: string, to: string): Promise<void>;
|
|
394
|
+
delete(path: string, options?: {
|
|
395
|
+
recursive?: boolean;
|
|
396
|
+
}): Promise<void>;
|
|
397
|
+
fetch(port: number, request: Request): Promise<Response>;
|
|
398
|
+
openShell(options?: OpenShellOptions): {
|
|
399
|
+
shellId: string;
|
|
400
|
+
};
|
|
401
|
+
connectTerminal(options?: ConnectTerminalOptions): Promise<number>;
|
|
402
|
+
/** Write data to a shell's PTY input. */
|
|
403
|
+
writeShell(shellId: string, data: string | Uint8Array): void;
|
|
404
|
+
/** Subscribe to data output from a shell. Returns an unsubscribe function. */
|
|
405
|
+
onShellData(shellId: string, handler: (data: Uint8Array) => void): () => void;
|
|
406
|
+
/** Notify a shell of terminal resize. */
|
|
407
|
+
resizeShell(shellId: string, cols: number, rows: number): void;
|
|
408
|
+
/** Kill a shell process and remove it from tracking. */
|
|
409
|
+
closeShell(shellId: string): void;
|
|
410
|
+
private _resolveVmPathToHostPath;
|
|
411
|
+
/** Returns info about all processes spawned via spawn(). */
|
|
412
|
+
listProcesses(): SpawnedProcessInfo[];
|
|
413
|
+
/** Returns all kernel processes across all active runtimes (WASM and Node). */
|
|
414
|
+
allProcesses(): KernelProcessInfo[];
|
|
415
|
+
/** Returns processes organized as a tree using ppid relationships. */
|
|
416
|
+
processTree(): ProcessTreeNode[];
|
|
417
|
+
/** Returns info about a specific process by PID. Throws if not found. */
|
|
418
|
+
getProcess(pid: number): SpawnedProcessInfo;
|
|
419
|
+
/** Send SIGTERM to gracefully stop a process. No-op if already exited. */
|
|
420
|
+
stopProcess(pid: number): void;
|
|
421
|
+
/** Send SIGKILL to force-kill a process. No-op if already exited. */
|
|
422
|
+
killProcess(pid: number): void;
|
|
423
|
+
/** Returns all active sessions with their IDs and agent types. */
|
|
424
|
+
listSessions(): SessionInfo[];
|
|
425
|
+
/** Internal helper: retrieve a session or throw. */
|
|
426
|
+
private _requireSession;
|
|
427
|
+
/** Returns all registered agents with their installation status. */
|
|
428
|
+
listAgents(): AgentRegistryEntry[];
|
|
429
|
+
private _syncSessionState;
|
|
430
|
+
private _applySessionUpdate;
|
|
431
|
+
private _recordSessionNotification;
|
|
432
|
+
private _dispatchSessionEvent;
|
|
433
|
+
private _subscribeSessionEvents;
|
|
434
|
+
private _applySyntheticConfigOverrides;
|
|
435
|
+
private _handleSidecarEvent;
|
|
436
|
+
private _handleAcpExtEvent;
|
|
437
|
+
private _unsupportedConfigResponse;
|
|
438
|
+
private _sendAcpRequest;
|
|
439
|
+
private _sendSessionRequest;
|
|
440
|
+
private _setSessionConfigByCategory;
|
|
441
|
+
private _removeSession;
|
|
442
|
+
private _abortPendingSessionRequests;
|
|
443
|
+
private _cancelPendingPromptRequests;
|
|
444
|
+
private _rejectPendingPermissionReplies;
|
|
445
|
+
private _rejectPendingPermissionRepliesFromSession;
|
|
446
|
+
private _closeSessionInternal;
|
|
447
|
+
private _hydrateSessionState;
|
|
448
|
+
createSession(agentType: AgentType | string, options?: CreateSessionOptions): Promise<{
|
|
449
|
+
sessionId: string;
|
|
450
|
+
}>;
|
|
451
|
+
/**
|
|
452
|
+
* Resume a session that exists in durable storage but is not live in this VM
|
|
453
|
+
* (e.g. after a Rivet actor slept and woke with a fresh VM). Thin forwarder:
|
|
454
|
+
* resolves the agent config + adapter entrypoint exactly as {@link createSession}
|
|
455
|
+
* does, then forwards a single `AcpResumeSessionRequest` to the sidecar, which
|
|
456
|
+
* owns the resume state machine (native `session/load` when the agent supports
|
|
457
|
+
* it, else `session/new` + a transcript-continuation preamble). The returned
|
|
458
|
+
* `sessionId` is the live id in this VM (equal to the requested id for native
|
|
459
|
+
* loads, freshly assigned for the fallback); the caller remaps `external -> live`.
|
|
460
|
+
* The new live session is registered + hydrated locally so subsequent prompts
|
|
461
|
+
* route to it.
|
|
462
|
+
*
|
|
463
|
+
* Resume depends on a durable root; on a non-durable (default in-memory) root
|
|
464
|
+
* there is no surviving store and the fallback tier always runs.
|
|
465
|
+
*/
|
|
466
|
+
resumeSession(sessionId: string, agentType: AgentType | string, options?: ResumeSessionOptions): Promise<ResumeSessionResult>;
|
|
467
|
+
/**
|
|
468
|
+
* Resolve the VM bin entry point of an ACP adapter package.
|
|
469
|
+
* Reads from the host filesystem since kernel.readFile() resolves through
|
|
470
|
+
* mounts; adapter package.json is read directly off the host dir backing
|
|
471
|
+
* the relevant mount.
|
|
472
|
+
*/
|
|
473
|
+
private _resolveAdapterBin;
|
|
474
|
+
/**
|
|
475
|
+
* Parent of the host directory backing the `/root/node_modules` mount, if
|
|
476
|
+
* the caller supplied one (e.g. via `nodeModulesMount(...)`). Used as the
|
|
477
|
+
* `resolvePackageDir` start dir for adapter/agent package resolution when no
|
|
478
|
+
* software root matches. `nodeModulesMount` mounts `<dir>/node_modules`, so
|
|
479
|
+
* the start dir is `<dir>` (one level above the node_modules tree).
|
|
480
|
+
*/
|
|
481
|
+
private _nodeModulesHostRoot;
|
|
482
|
+
private _resolvePackageBin;
|
|
483
|
+
private _installSidecarRequestHandler;
|
|
484
|
+
private _handleAcpExtSidecarRequest;
|
|
485
|
+
private _dispatchAcpSidecarRequest;
|
|
486
|
+
private _handleSupportedAcpSidecarRequest;
|
|
487
|
+
private _normalizeAcpPermissionOptionId;
|
|
488
|
+
private _buildAcpPermissionResult;
|
|
489
|
+
private _handleAcpPermissionRequest;
|
|
490
|
+
private _acpParams;
|
|
491
|
+
private _requireAcpStringParam;
|
|
492
|
+
private _optionalAcpStringParam;
|
|
493
|
+
private _optionalAcpNumberParam;
|
|
494
|
+
private _optionalAcpStringArrayParam;
|
|
495
|
+
private _optionalAcpEnvParam;
|
|
496
|
+
private _requireAcpTerminal;
|
|
497
|
+
private _appendAcpTerminalOutput;
|
|
498
|
+
private _handleAcpReadFile;
|
|
499
|
+
private _handleAcpWriteFile;
|
|
500
|
+
private _handleAcpReadDir;
|
|
501
|
+
private _handleAcpCreateTerminal;
|
|
502
|
+
private _handleAcpWriteTerminal;
|
|
503
|
+
private _handleAcpReadTerminal;
|
|
504
|
+
private _handleAcpWaitForTerminalExit;
|
|
505
|
+
private _handleAcpKillTerminal;
|
|
506
|
+
private _handleAcpReleaseTerminal;
|
|
507
|
+
private _handleAcpResizeTerminal;
|
|
508
|
+
private _handleAcpPermissionCallback;
|
|
509
|
+
/**
|
|
510
|
+
* Resolve an agent config by ID. Package-provided configs take
|
|
511
|
+
* precedence over the hardcoded AGENT_CONFIGS.
|
|
512
|
+
*/
|
|
513
|
+
private _resolveAgentConfig;
|
|
514
|
+
/**
|
|
515
|
+
* Gracefully destroy a session: cancel any pending work, close the client,
|
|
516
|
+
* and remove from tracking. Unlike close() which is abrupt, this attempts
|
|
517
|
+
* a graceful shutdown sequence.
|
|
518
|
+
*/
|
|
519
|
+
destroySession(sessionId: string): Promise<void>;
|
|
520
|
+
prompt(sessionId: string, text: string): Promise<PromptResult>;
|
|
521
|
+
/** Cancel ongoing agent work for a session. */
|
|
522
|
+
cancelSession(sessionId: string): Promise<JsonRpcResponse>;
|
|
523
|
+
closeSession(sessionId: string): void;
|
|
524
|
+
respondPermission(sessionId: string, permissionId: string, reply: PermissionReply): Promise<JsonRpcResponse>;
|
|
525
|
+
setSessionMode(sessionId: string, modeId: string): Promise<JsonRpcResponse>;
|
|
526
|
+
getSessionModes(sessionId: string): SessionModeState | null;
|
|
527
|
+
setSessionModel(sessionId: string, model: string): Promise<JsonRpcResponse>;
|
|
528
|
+
setSessionThoughtLevel(sessionId: string, level: string): Promise<JsonRpcResponse>;
|
|
529
|
+
getSessionConfigOptions(sessionId: string): SessionConfigOption[];
|
|
530
|
+
getSessionCapabilities(sessionId: string): AgentCapabilities | null;
|
|
531
|
+
getSessionAgentInfo(sessionId: string): AgentInfo | null;
|
|
532
|
+
rawSessionSend(sessionId: string, method: string, params?: Record<string, unknown>): Promise<JsonRpcResponse>;
|
|
533
|
+
rawSend(sessionId: string, method: string, params?: Record<string, unknown>): Promise<JsonRpcResponse>;
|
|
534
|
+
onSessionEvent(sessionId: string, handler: SessionEventHandler): () => void;
|
|
535
|
+
onPermissionRequest(sessionId: string, handler: PermissionRequestHandler): () => void;
|
|
536
|
+
/** Schedule a cron job. Returns a handle with the job ID and a cancel method. */
|
|
537
|
+
scheduleCron(options: CronJobOptions): CronJob;
|
|
538
|
+
/** List all registered cron jobs. */
|
|
539
|
+
listCronJobs(): CronJobInfo[];
|
|
540
|
+
/** Cancel a cron job by ID. */
|
|
541
|
+
cancelCronJob(id: string): void;
|
|
542
|
+
/** Subscribe to cron lifecycle events (fire, complete, error). */
|
|
543
|
+
onCronEvent(handler: CronEventHandler): void;
|
|
544
|
+
dispose(): Promise<void>;
|
|
545
|
+
}
|
|
546
|
+
export declare function getAgentOsRuntimeAdmin(vm: AgentOs): AgentOsRuntimeAdmin;
|
|
547
|
+
export declare function getAgentOsKernel(vm: AgentOs): Kernel;
|
|
548
|
+
export declare class AgentOsSidecar {
|
|
549
|
+
constructor(sidecarId: string, placement: AgentOsSidecarPlacement, sharedPool?: string);
|
|
550
|
+
describe(): AgentOsSidecarDescription;
|
|
551
|
+
dispose(): Promise<void>;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Test-only escape hatch: dispose every cached shared sidecar so vitest
|
|
555
|
+
* workers can exit cleanly. The shared sidecar is normally process-global and
|
|
556
|
+
* keeps its native subprocess alive across `AgentOs.create()` calls; without
|
|
557
|
+
* this hook the vitest worker can hold open piped stdio handles after the
|
|
558
|
+
* test suite finishes and stall `pnpm test` indefinitely.
|
|
559
|
+
*/
|
|
560
|
+
export declare function __disposeAllSharedSidecarsForTesting(): Promise<void>;
|