@rivet-dev/agentos 0.2.12 → 0.2.13
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/dist/index.d.ts +43 -3
- package/dist/index.js +194 -6
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Actions, ActorConfigInput, ActorContext, ActorDefinition, Type, setup as setup$1 } from 'rivetkit';
|
|
2
2
|
export { Registry } from 'rivetkit';
|
|
3
3
|
import * as _rivet_dev_agentos_core from '@rivet-dev/agentos-core';
|
|
4
|
-
import { SessionStreamEntry, AgentExitEvent, ProcessOutput, ProcessExit, ShellData, ShellExit, CronEvent, CronJobInfo, AgentOsOptions, OpenSessionInput, PromptInput, DynamicMountDescriptor, PackageDescriptor } from '@rivet-dev/agentos-core';
|
|
4
|
+
import { SessionStreamEntry, AgentExitEvent, ProcessOutput, ProcessExit, ShellData, ShellExit, CronEvent, CronJobInfo, AgentOsOptions, AgentOs, OpenSessionInput, PromptInput, DynamicMountDescriptor, PackageDescriptor } from '@rivet-dev/agentos-core';
|
|
5
5
|
export { AgentOsOptions, DirEntry, DynamicMountDescriptor, ExportRootFilesystemOptions, HttpRequest, HttpResponse, MountInfo, NodeModulesMountConfig, PackageDescriptor, ProcessExit, ProcessOutput, PromptResult, ReaddirEntry, RootSnapshotExport, SessionInfo, ShellData, ShellExit, defineSoftware, nodeModulesMount } from '@rivet-dev/agentos-core';
|
|
6
6
|
import * as _agentclientprotocol_sdk from '@agentclientprotocol/sdk';
|
|
7
7
|
import * as _rivet_dev_agentos_core_internal_runtime_compat from '@rivet-dev/agentos-core/internal/runtime-compat';
|
|
@@ -56,6 +56,29 @@ type ActorDb = DatabaseProvider<RawAccess>;
|
|
|
56
56
|
type EventSchemaConfig = Record<string, any>;
|
|
57
57
|
type QueueSchemaConfig = Record<string, any>;
|
|
58
58
|
type AnyContext = ActorContext<any, any, any, any, any, ActorDb, any, any>;
|
|
59
|
+
interface VmFetchOptions {
|
|
60
|
+
method?: string;
|
|
61
|
+
headers?: Record<string, string>;
|
|
62
|
+
body?: string | Uint8Array;
|
|
63
|
+
}
|
|
64
|
+
interface VmFetchResponse {
|
|
65
|
+
status: number;
|
|
66
|
+
statusText: string;
|
|
67
|
+
headers: Record<string, string>;
|
|
68
|
+
rawHeaders?: Array<[string, string]>;
|
|
69
|
+
body: Uint8Array;
|
|
70
|
+
}
|
|
71
|
+
interface VmFetchStreamHead {
|
|
72
|
+
streamId: string;
|
|
73
|
+
status: number;
|
|
74
|
+
statusText: string;
|
|
75
|
+
headers: Record<string, string>;
|
|
76
|
+
rawHeaders?: Array<[string, string]>;
|
|
77
|
+
}
|
|
78
|
+
interface VmFetchStreamChunk {
|
|
79
|
+
body: Uint8Array;
|
|
80
|
+
done: boolean;
|
|
81
|
+
}
|
|
59
82
|
interface AgentOsEventHooks<TContext = AnyContext> {
|
|
60
83
|
onSessionEvent?: (c: TContext, sessionId: string, event: SessionStreamEntry) => void | Promise<void>;
|
|
61
84
|
}
|
|
@@ -98,6 +121,10 @@ declare function createAgentOsActions(options?: AgentOsOptions, hooks?: AgentOsE
|
|
|
98
121
|
closeShell: (c: AnyContext, shellId: string) => Promise<void>;
|
|
99
122
|
waitShell: (c: AnyContext, shellId: string) => Promise<number>;
|
|
100
123
|
httpRequest: (c: AnyContext, request: _rivet_dev_agentos_core.HttpRequest) => Promise<_rivet_dev_agentos_core.HttpResponse>;
|
|
124
|
+
vmFetch: (c: AnyContext, port: number, url: string, requestOptions?: VmFetchOptions) => Promise<VmFetchResponse>;
|
|
125
|
+
vmFetchStreamStart: (c: AnyContext, port: number, url: string, requestOptions?: VmFetchOptions) => Promise<VmFetchStreamHead>;
|
|
126
|
+
vmFetchStreamRead: (c: AnyContext, streamId: string, maxBytes?: number) => Promise<VmFetchStreamChunk>;
|
|
127
|
+
vmFetchStreamCancel: (c: AnyContext, streamId: string) => Promise<void>;
|
|
101
128
|
scheduleCron: (c: AnyContext, cronOptions: SerializableCronJobOptions) => Promise<{
|
|
102
129
|
id: string;
|
|
103
130
|
}>;
|
|
@@ -136,6 +163,18 @@ declare function createAgentOsActions(options?: AgentOsOptions, hooks?: AgentOsE
|
|
|
136
163
|
};
|
|
137
164
|
type AgentOsActions = ReturnType<typeof createAgentOsActions>;
|
|
138
165
|
interface AgentOsActorExtras extends AgentOsOptions {
|
|
166
|
+
/**
|
|
167
|
+
* Resolve trusted VM options from actor state immediately before the VM's
|
|
168
|
+
* first boot. Evaluated once per wake. The actor-owned root filesystem and
|
|
169
|
+
* database cannot be replaced.
|
|
170
|
+
*/
|
|
171
|
+
resolveOptions?: (c: AnyContext) => AgentOsOptions | Promise<AgentOsOptions>;
|
|
172
|
+
/** Start long-lived processes after each VM boot. Trusted host code only. */
|
|
173
|
+
onVmStart?: (c: AnyContext, vm: AgentOs) => void | Promise<void>;
|
|
174
|
+
/** Gracefully stop long-lived processes before the VM is disposed. */
|
|
175
|
+
onVmStop?: (c: AnyContext, vm: AgentOs, reason: "sleep" | "destroy" | "error") => void | Promise<void>;
|
|
176
|
+
/** Clean up host resources after the VM and lazy mount readers close. */
|
|
177
|
+
onVmDisposed?: (c: AnyContext, reason: "sleep" | "destroy" | "error") => void | Promise<void>;
|
|
139
178
|
/** Maximum live session event subscriptions per actor VM. Default: 10,000. */
|
|
140
179
|
maxSessionSubscriptions?: number;
|
|
141
180
|
/** Maximum durable dynamic mount descriptors per actor. Default: 10,000. */
|
|
@@ -148,7 +187,8 @@ interface AgentOsActorExtras extends AgentOsOptions {
|
|
|
148
187
|
maxActiveTokens?: number;
|
|
149
188
|
};
|
|
150
189
|
}
|
|
151
|
-
type
|
|
190
|
+
type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
|
|
191
|
+
type AgentOsActorConfigInput<TState = undefined, TConnParams = undefined, TConnState = undefined, TVars = undefined, TInput = undefined, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>, TUserActions extends Actions<TState, TConnParams, TConnState, TVars, TInput, ActorDb, TEvents, TQueues> = Record<never, never>> = DistributiveOmit<ActorConfigInput<TState, TConnParams, TConnState, TVars, TInput, ActorDb, TEvents, TQueues, TUserActions>, "db"> & AgentOsActorExtras & AgentOsEventHooks<ActorContext<TState, TConnParams, TConnState, TVars, TInput, ActorDb, TEvents, TQueues>>;
|
|
152
192
|
declare function createAgentOS<TState = undefined, TConnParams = undefined, TConnState = undefined, TVars = undefined, TInput = undefined, TEvents extends EventSchemaConfig = Record<never, never>, TQueues extends QueueSchemaConfig = Record<never, never>, TUserActions extends Actions<TState, TConnParams, TConnState, TVars, TInput, ActorDb, TEvents, TQueues> = Record<never, never>>(config?: AgentOsActorConfigInput<TState, TConnParams, TConnState, TVars, TInput, TEvents, TQueues, TUserActions>): ActorDefinition<TState, TConnParams, TConnState, TVars, TInput, ActorDb, TEvents & BuiltInEvents, TQueues, TUserActions & AgentOsActions>;
|
|
153
193
|
|
|
154
194
|
/**
|
|
@@ -157,4 +197,4 @@ declare function createAgentOS<TState = undefined, TConnParams = undefined, TCon
|
|
|
157
197
|
*/
|
|
158
198
|
declare const setup: typeof setup$1;
|
|
159
199
|
|
|
160
|
-
export { type AgentOsActorConfigInput as AgentOSActorConfigInput, type AgentOsActorConfigInput as AgentOSConfigInput, type AgentOsActions, type AgentOsActorConfigInput, type AgentOsActorExtras, type AgentOsEventHooks, type AgentOsEvents, type ProcessExitPayload, type ProcessOutputPayload, type SerializableCronAction, type SerializableCronEvent, type SerializableCronJobInfo, type SerializableCronJobOptions, type ShellDataPayload, type ShellExitPayload, type VmBootedPayload, type VmShutdownPayload, createAgentOS as agentOS, createAgentOS, createAgentOsActions, setup };
|
|
200
|
+
export { type AgentOsActorConfigInput as AgentOSActorConfigInput, type AgentOsActorConfigInput as AgentOSConfigInput, type AgentOsActions, type AgentOsActorConfigInput, type AgentOsActorExtras, type AgentOsEventHooks, type AgentOsEvents, type ProcessExitPayload, type ProcessOutputPayload, type SerializableCronAction, type SerializableCronEvent, type SerializableCronJobInfo, type SerializableCronJobOptions, type ShellDataPayload, type ShellExitPayload, type VmBootedPayload, type VmFetchOptions, type VmFetchResponse, type VmFetchStreamChunk, type VmFetchStreamHead, type VmShutdownPayload, createAgentOS as agentOS, createAgentOS, createAgentOsActions, setup };
|
package/dist/index.js
CHANGED
|
@@ -65,19 +65,55 @@ var builtInEvents = {
|
|
|
65
65
|
shellExit: event()
|
|
66
66
|
};
|
|
67
67
|
var runtimes = /* @__PURE__ */ new Map();
|
|
68
|
+
var optionResolvers = /* @__PURE__ */ new WeakMap();
|
|
69
|
+
var vmStartResolvers = /* @__PURE__ */ new WeakMap();
|
|
70
|
+
var vmStopResolvers = /* @__PURE__ */ new WeakMap();
|
|
71
|
+
var vmDisposedResolvers = /* @__PURE__ */ new WeakMap();
|
|
68
72
|
function runtimeFor(c) {
|
|
69
73
|
let runtime = runtimes.get(c.actorId);
|
|
70
74
|
if (!runtime) {
|
|
71
|
-
runtime = {
|
|
75
|
+
runtime = {
|
|
76
|
+
vm: null,
|
|
77
|
+
subscribedSessions: /* @__PURE__ */ new Map(),
|
|
78
|
+
vmCleanupRan: false,
|
|
79
|
+
fetchStreamHolds: /* @__PURE__ */ new Map()
|
|
80
|
+
};
|
|
72
81
|
runtimes.set(c.actorId, runtime);
|
|
73
82
|
}
|
|
74
83
|
return runtime;
|
|
75
84
|
}
|
|
85
|
+
async function runVmDisposedHook(runtime, c, reason) {
|
|
86
|
+
if (runtime.vmCleanupRan) return;
|
|
87
|
+
runtime.vmCleanupRan = true;
|
|
88
|
+
await runtime.onVmDisposed?.(c, reason);
|
|
89
|
+
}
|
|
76
90
|
async function ensureVm(c, options) {
|
|
77
91
|
const runtime = runtimeFor(c);
|
|
78
92
|
if (runtime.vm !== null) return runtime.vm;
|
|
79
93
|
const startedAt = Date.now();
|
|
94
|
+
runtime.vmCleanupRan = false;
|
|
80
95
|
runtime.vm = (async () => {
|
|
96
|
+
runtime.onVmStop = options ? vmStopResolvers.get(options) : void 0;
|
|
97
|
+
runtime.onVmDisposed = options ? vmDisposedResolvers.get(options) : void 0;
|
|
98
|
+
const resolvedOptions = {
|
|
99
|
+
...options,
|
|
100
|
+
...options && optionResolvers.has(options) ? await optionResolvers.get(options)?.(c) : void 0
|
|
101
|
+
};
|
|
102
|
+
if (resolvedOptions.rootFilesystem) {
|
|
103
|
+
throw new Error(
|
|
104
|
+
"agentOS() owns rootFilesystem so it can persist directly through the actor SQLite UDS; resolveOptions may configure mounts but not rootFilesystem"
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
if (resolvedOptions.database) {
|
|
108
|
+
throw new Error(
|
|
109
|
+
"agentOS() owns database and injects the actor SQLite UDS descriptor; resolveOptions cannot replace it"
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
if (resolvedOptions.sandbox && "client" in resolvedOptions.sandbox) {
|
|
113
|
+
throw new Error(
|
|
114
|
+
"agentOS() cannot share sandbox: { client } across actor instances; resolveOptions must use sandbox: { provider }"
|
|
115
|
+
);
|
|
116
|
+
}
|
|
81
117
|
const actorRuntimeSocket = c.actorRuntimeSocket;
|
|
82
118
|
if (typeof actorRuntimeSocket !== "function") {
|
|
83
119
|
throw new Error(
|
|
@@ -92,7 +128,7 @@ async function ensureVm(c, options) {
|
|
|
92
128
|
"SELECT descriptor_json FROM agentos_actor_linked_software ORDER BY path"
|
|
93
129
|
);
|
|
94
130
|
const vm = await AgentOs.create({
|
|
95
|
-
...
|
|
131
|
+
...resolvedOptions,
|
|
96
132
|
database: { type: "actor_uds", path },
|
|
97
133
|
onAgentExit: (event2) => {
|
|
98
134
|
c.log.error({
|
|
@@ -101,7 +137,7 @@ async function ensureVm(c, options) {
|
|
|
101
137
|
});
|
|
102
138
|
c.broadcast("agentExit", event2);
|
|
103
139
|
try {
|
|
104
|
-
|
|
140
|
+
resolvedOptions.onAgentExit?.(event2);
|
|
105
141
|
} catch (error) {
|
|
106
142
|
c.log.error({
|
|
107
143
|
msg: "agent-os onAgentExit hook failed",
|
|
@@ -118,8 +154,8 @@ async function ensureVm(c, options) {
|
|
|
118
154
|
namespace: ROOT_NAMESPACE,
|
|
119
155
|
chunkSize: ACTOR_SQLITE_CHUNK_SIZE,
|
|
120
156
|
inlineThreshold: ACTOR_SQLITE_INLINE_THRESHOLD,
|
|
121
|
-
uid:
|
|
122
|
-
gid:
|
|
157
|
+
uid: resolvedOptions.user?.euid ?? resolvedOptions.user?.uid ?? 1e3,
|
|
158
|
+
gid: resolvedOptions.user?.egid ?? resolvedOptions.user?.gid ?? 1e3
|
|
123
159
|
}
|
|
124
160
|
}
|
|
125
161
|
}
|
|
@@ -139,6 +175,24 @@ async function ensureVm(c, options) {
|
|
|
139
175
|
await vm.dispose();
|
|
140
176
|
throw error;
|
|
141
177
|
}
|
|
178
|
+
const onVmStart = options ? vmStartResolvers.get(options) : void 0;
|
|
179
|
+
if (onVmStart) {
|
|
180
|
+
try {
|
|
181
|
+
await onVmStart(c, vm);
|
|
182
|
+
} catch (error) {
|
|
183
|
+
try {
|
|
184
|
+
await vm.dispose();
|
|
185
|
+
} catch (disposeError) {
|
|
186
|
+
c.log.error({
|
|
187
|
+
msg: "failed to dispose AgentOS VM after start hook failure",
|
|
188
|
+
disposeError
|
|
189
|
+
});
|
|
190
|
+
} finally {
|
|
191
|
+
await runVmDisposedHook(runtime, c, "error");
|
|
192
|
+
}
|
|
193
|
+
throw error;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
142
196
|
vm.onCronEvent((cronEvent) => c.broadcast("cronEvent", cronEvent));
|
|
143
197
|
c.broadcast("vmBooted", {});
|
|
144
198
|
c.log.info({
|
|
@@ -156,6 +210,7 @@ async function ensureVm(c, options) {
|
|
|
156
210
|
actorId: c.actorId,
|
|
157
211
|
error
|
|
158
212
|
});
|
|
213
|
+
await runVmDisposedHook(runtime, c, "error");
|
|
159
214
|
throw error;
|
|
160
215
|
}
|
|
161
216
|
}
|
|
@@ -168,7 +223,39 @@ async function disposeVm(c, reason) {
|
|
|
168
223
|
for (const unsubscribe of unsubscribers) unsubscribe();
|
|
169
224
|
}
|
|
170
225
|
runtime.subscribedSessions.clear();
|
|
171
|
-
|
|
226
|
+
for (const release of runtime.fetchStreamHolds.values()) release();
|
|
227
|
+
runtime.fetchStreamHolds.clear();
|
|
228
|
+
if (vm) {
|
|
229
|
+
const failures = [];
|
|
230
|
+
try {
|
|
231
|
+
const resolvedVm = await vm;
|
|
232
|
+
try {
|
|
233
|
+
await runtime.onVmStop?.(c, resolvedVm, reason);
|
|
234
|
+
} catch (error) {
|
|
235
|
+
failures.push(error);
|
|
236
|
+
}
|
|
237
|
+
try {
|
|
238
|
+
await resolvedVm.dispose();
|
|
239
|
+
} catch (error) {
|
|
240
|
+
failures.push(error);
|
|
241
|
+
}
|
|
242
|
+
} catch (error) {
|
|
243
|
+
failures.push(error);
|
|
244
|
+
}
|
|
245
|
+
try {
|
|
246
|
+
await runVmDisposedHook(runtime, c, reason);
|
|
247
|
+
} catch (error) {
|
|
248
|
+
failures.push(error);
|
|
249
|
+
}
|
|
250
|
+
if (failures.length === 1) throw failures[0];
|
|
251
|
+
if (failures.length > 1) {
|
|
252
|
+
const aggregate = new Error(
|
|
253
|
+
"failed to stop, dispose, or clean up AgentOS VM"
|
|
254
|
+
);
|
|
255
|
+
aggregate.errors = failures;
|
|
256
|
+
throw aggregate;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
172
259
|
c.broadcast("vmShutdown", { reason });
|
|
173
260
|
}
|
|
174
261
|
function matchPreviewPath(pathname) {
|
|
@@ -302,6 +389,25 @@ function untrackSessionEvents(c, sessionId) {
|
|
|
302
389
|
for (const unsubscribe of unsubscribers) unsubscribe();
|
|
303
390
|
runtimeFor(c).subscribedSessions.delete(sessionId);
|
|
304
391
|
}
|
|
392
|
+
function trackFetchStream(c, streamId) {
|
|
393
|
+
const runtime = runtimeFor(c);
|
|
394
|
+
if (runtime.fetchStreamHolds.has(streamId)) return;
|
|
395
|
+
const hold = new Promise((resolve) => {
|
|
396
|
+
runtime.fetchStreamHolds.set(streamId, resolve);
|
|
397
|
+
});
|
|
398
|
+
void c.keepAwake(hold).catch(
|
|
399
|
+
(error) => c.log.error({
|
|
400
|
+
msg: "agent-os fetch stream hold failed",
|
|
401
|
+
streamId,
|
|
402
|
+
error
|
|
403
|
+
})
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
function releaseFetchStream(c, streamId) {
|
|
407
|
+
const runtime = runtimeFor(c);
|
|
408
|
+
runtime.fetchStreamHolds.get(streamId)?.();
|
|
409
|
+
runtime.fetchStreamHolds.delete(streamId);
|
|
410
|
+
}
|
|
305
411
|
function createAgentOsActions(options, hooks = {}, preview = {}, maxSessionSubscriptions = DEFAULT_MAX_SESSION_SUBSCRIPTIONS, maxDynamicMounts = DEFAULT_MAX_DYNAMIC_MOUNTS, maxLinkedSoftware = DEFAULT_MAX_LINKED_SOFTWARE) {
|
|
306
412
|
const defaultPreviewTtlSeconds = preview.defaultExpiresInSeconds ?? DEFAULT_PREVIEW_TTL_SECONDS;
|
|
307
413
|
const maxPreviewTtlSeconds = preview.maxExpiresInSeconds ?? MAX_PREVIEW_TTL_SECONDS;
|
|
@@ -427,6 +533,70 @@ function createAgentOsActions(options, hooks = {}, preview = {}, maxSessionSubsc
|
|
|
427
533
|
closeShell: async (c, ...args) => (await ensureVm(c, options)).closeShell(...args),
|
|
428
534
|
waitShell: async (c, ...args) => (await ensureVm(c, options)).waitShell(...args),
|
|
429
535
|
httpRequest: async (c, ...args) => (await ensureVm(c, options)).httpRequest(...args),
|
|
536
|
+
vmFetch: async (c, port, url, requestOptions) => {
|
|
537
|
+
const vm = await ensureVm(c, options);
|
|
538
|
+
const body = requestOptions?.body instanceof Uint8Array ? Buffer.from(requestOptions.body) : requestOptions?.body;
|
|
539
|
+
const response = await vm.fetch(
|
|
540
|
+
port,
|
|
541
|
+
new Request(url, {
|
|
542
|
+
method: requestOptions?.method ?? "GET",
|
|
543
|
+
headers: requestOptions?.headers,
|
|
544
|
+
body
|
|
545
|
+
})
|
|
546
|
+
);
|
|
547
|
+
const headers = {};
|
|
548
|
+
const rawHeaders = [];
|
|
549
|
+
response.headers.forEach((value, key) => {
|
|
550
|
+
headers[key] = value;
|
|
551
|
+
if (key !== "set-cookie") rawHeaders.push([key, value]);
|
|
552
|
+
});
|
|
553
|
+
for (const value of response.headers.getSetCookie?.() ?? []) {
|
|
554
|
+
rawHeaders.push(["set-cookie", value]);
|
|
555
|
+
}
|
|
556
|
+
return {
|
|
557
|
+
status: response.status,
|
|
558
|
+
statusText: response.statusText,
|
|
559
|
+
headers,
|
|
560
|
+
rawHeaders,
|
|
561
|
+
body: new Uint8Array(await response.arrayBuffer())
|
|
562
|
+
};
|
|
563
|
+
},
|
|
564
|
+
vmFetchStreamStart: async (c, port, url, requestOptions) => {
|
|
565
|
+
const vm = await ensureVm(c, options);
|
|
566
|
+
const body = requestOptions?.body instanceof Uint8Array ? Buffer.from(requestOptions.body) : requestOptions?.body;
|
|
567
|
+
const head = await vm.fetchStreamStart(
|
|
568
|
+
port,
|
|
569
|
+
new Request(url, {
|
|
570
|
+
method: requestOptions?.method ?? "GET",
|
|
571
|
+
headers: requestOptions?.headers,
|
|
572
|
+
body
|
|
573
|
+
})
|
|
574
|
+
);
|
|
575
|
+
trackFetchStream(c, head.streamId);
|
|
576
|
+
const headers = {};
|
|
577
|
+
for (const [name, value] of head.headers) headers[name] = value;
|
|
578
|
+
return { ...head, headers, rawHeaders: head.headers };
|
|
579
|
+
},
|
|
580
|
+
vmFetchStreamRead: async (c, streamId, maxBytes) => {
|
|
581
|
+
try {
|
|
582
|
+
const chunk = await (await ensureVm(c, options)).fetchStreamRead(
|
|
583
|
+
streamId,
|
|
584
|
+
maxBytes
|
|
585
|
+
);
|
|
586
|
+
if (chunk.done) releaseFetchStream(c, streamId);
|
|
587
|
+
return chunk;
|
|
588
|
+
} catch (error) {
|
|
589
|
+
releaseFetchStream(c, streamId);
|
|
590
|
+
throw error;
|
|
591
|
+
}
|
|
592
|
+
},
|
|
593
|
+
vmFetchStreamCancel: async (c, streamId) => {
|
|
594
|
+
try {
|
|
595
|
+
await (await ensureVm(c, options)).fetchStreamCancel(streamId);
|
|
596
|
+
} finally {
|
|
597
|
+
releaseFetchStream(c, streamId);
|
|
598
|
+
}
|
|
599
|
+
},
|
|
430
600
|
scheduleCron: async (c, cronOptions) => {
|
|
431
601
|
const job = (await ensureVm(c, options)).scheduleCron(
|
|
432
602
|
cronOptions
|
|
@@ -684,11 +854,19 @@ function splitConfig(config) {
|
|
|
684
854
|
}
|
|
685
855
|
const onSessionEvent = actorConfig.onSessionEvent;
|
|
686
856
|
const preview = actorConfig.preview;
|
|
857
|
+
const resolveOptions = actorConfig.resolveOptions;
|
|
858
|
+
const onVmStart = actorConfig.onVmStart;
|
|
859
|
+
const onVmStop = actorConfig.onVmStop;
|
|
860
|
+
const onVmDisposed = actorConfig.onVmDisposed;
|
|
687
861
|
const maxSessionSubscriptions = actorConfig.maxSessionSubscriptions;
|
|
688
862
|
const maxDynamicMounts = actorConfig.maxDynamicMounts;
|
|
689
863
|
const maxLinkedSoftware = actorConfig.maxLinkedSoftware;
|
|
690
864
|
delete actorConfig.onSessionEvent;
|
|
691
865
|
delete actorConfig.preview;
|
|
866
|
+
delete actorConfig.resolveOptions;
|
|
867
|
+
delete actorConfig.onVmStart;
|
|
868
|
+
delete actorConfig.onVmStop;
|
|
869
|
+
delete actorConfig.onVmDisposed;
|
|
692
870
|
delete actorConfig.maxSessionSubscriptions;
|
|
693
871
|
delete actorConfig.maxDynamicMounts;
|
|
694
872
|
delete actorConfig.maxLinkedSoftware;
|
|
@@ -697,6 +875,10 @@ function splitConfig(config) {
|
|
|
697
875
|
agentOsOptions,
|
|
698
876
|
hooks: { onSessionEvent },
|
|
699
877
|
preview,
|
|
878
|
+
resolveOptions,
|
|
879
|
+
onVmStart,
|
|
880
|
+
onVmStop,
|
|
881
|
+
onVmDisposed,
|
|
700
882
|
maxSessionSubscriptions,
|
|
701
883
|
maxDynamicMounts,
|
|
702
884
|
maxLinkedSoftware
|
|
@@ -719,6 +901,12 @@ function createAgentOS(config = {}) {
|
|
|
719
901
|
maxDynamicMounts,
|
|
720
902
|
maxLinkedSoftware
|
|
721
903
|
} = split;
|
|
904
|
+
if (split.resolveOptions)
|
|
905
|
+
optionResolvers.set(agentOsOptions, split.resolveOptions);
|
|
906
|
+
if (split.onVmStart) vmStartResolvers.set(agentOsOptions, split.onVmStart);
|
|
907
|
+
if (split.onVmStop) vmStopResolvers.set(agentOsOptions, split.onVmStop);
|
|
908
|
+
if (split.onVmDisposed)
|
|
909
|
+
vmDisposedResolvers.set(agentOsOptions, split.onVmDisposed);
|
|
722
910
|
if (agentOsOptions.sandbox && "client" in agentOsOptions.sandbox) {
|
|
723
911
|
throw new Error(
|
|
724
912
|
"agentOS() cannot share sandbox: { client } across actor instances; use sandbox: { provider } so each actor VM starts its own client"
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/actor.ts"],"sourcesContent":["import { setup as rivetkitSetup } from \"rivetkit\";\n\nexport type { Registry } from \"rivetkit\";\n\nconst AGENTOS_REGISTRY_MESSAGE_SIZE_DEFAULT = 512 * 1024 * 1024;\n\n/**\n * RivetKit setup with the direct actor SQLite UDS enabled. The UDS is consumed\n * by the AgentOS sidecar; filesystem SQL never crosses the JavaScript layer.\n */\nexport const setup: typeof rivetkitSetup = ((\n\tinput: Parameters<typeof rivetkitSetup>[0],\n) =>\n\trivetkitSetup({\n\t\t...input,\n\t\tmaxIncomingMessageSize: AGENTOS_REGISTRY_MESSAGE_SIZE_DEFAULT,\n\t\tmaxOutgoingMessageSize: AGENTOS_REGISTRY_MESSAGE_SIZE_DEFAULT,\n\t\texperimentalActorUds: true,\n\t} as Parameters<typeof rivetkitSetup>[0])) as typeof rivetkitSetup;\n\nexport type {\n\tAgentOsOptions,\n\tDirEntry,\n\tDynamicMountDescriptor,\n\tExportRootFilesystemOptions,\n\tHttpRequest,\n\tHttpResponse,\n\tMountInfo,\n\tNodeModulesMountConfig,\n\tPackageDescriptor,\n\tProcessExit,\n\tProcessOutput,\n\tPromptResult,\n\tReaddirEntry,\n\tRootSnapshotExport,\n\tSessionInfo,\n\tShellData,\n\tShellExit,\n} from \"@rivet-dev/agentos-core\";\nexport { defineSoftware, nodeModulesMount } from \"@rivet-dev/agentos-core\";\nexport type {\n\tAgentOsActorConfigInput as AgentOSActorConfigInput,\n\tAgentOsActorConfigInput as AgentOSConfigInput,\n} from \"./actor.js\";\nexport {\n\ttype AgentOsActions,\n\ttype AgentOsActorConfigInput,\n\ttype AgentOsActorExtras,\n\ttype AgentOsEventHooks,\n\tcreateAgentOS,\n\tcreateAgentOS as agentOS,\n\tcreateAgentOsActions,\n} from \"./actor.js\";\nexport type {\n\tAgentOsEvents,\n\tProcessExitPayload,\n\tProcessOutputPayload,\n\tSerializableCronAction,\n\tSerializableCronEvent,\n\tSerializableCronJobInfo,\n\tSerializableCronJobOptions,\n\tShellDataPayload,\n\tShellExitPayload,\n\tVmBootedPayload,\n\tVmShutdownPayload,\n} from \"./types.js\";\n","import crypto from \"node:crypto\";\nimport {\n\ttype AgentExitEvent,\n\tAgentOs,\n\ttype AgentOsOptions,\n\ttype CronEvent,\n\ttype DynamicMountDescriptor,\n\ttype OpenSessionInput,\n\ttype PackageDescriptor,\n\ttype PromptInput,\n\ttype SessionStreamEntry,\n} from \"@rivet-dev/agentos-core\";\nimport {\n\ttype Actions,\n\ttype ActorConfigInput,\n\ttype ActorContext,\n\ttype ActorDefinition,\n\tactor,\n\tevent,\n\ttype Type,\n\tUserError,\n} from \"rivetkit\";\nimport { type DatabaseProvider, db, type RawAccess } from \"rivetkit/db\";\nimport { migrations } from \"rivetkit/unstable/migrations\";\nimport type {\n\tAgentOsEvents,\n\tProcessExitPayload,\n\tProcessOutputPayload,\n\tSerializableCronJobOptions,\n\tShellDataPayload,\n\tShellExitPayload,\n\tVmBootedPayload,\n\tVmShutdownPayload,\n} from \"./types.js\";\n\n// Prompts may remain paused at a permission request for a long human review.\n// RivetKit currently exposes only one actor-wide action timeout, so use the\n// largest value Node timers can represent safely (~24.8 days). Callers may\n// still opt into a shorter timeout through actor options.\nconst DEFAULT_ACTION_TIMEOUT_MS = 2_147_483_647;\nconst DEFAULT_SLEEP_GRACE_PERIOD_MS = 15 * 60_000;\nconst DEFAULT_PREVIEW_TTL_SECONDS = 3_600;\nconst MAX_PREVIEW_TTL_SECONDS = 86_400;\nconst DEFAULT_MAX_ACTIVE_PREVIEW_TOKENS = 1_024;\nconst DEFAULT_MAX_SESSION_SUBSCRIPTIONS = 10_000;\nconst DEFAULT_MAX_DYNAMIC_MOUNTS = 10_000;\nconst DEFAULT_MAX_LINKED_SOFTWARE = 10_000;\nconst ACTOR_SQLITE_CHUNK_SIZE = 512 * 1024;\nconst ACTOR_SQLITE_INLINE_THRESHOLD = 64 * 1024;\nconst ROOT_NAMESPACE = \"agentos-root\";\nconst PREVIEW_PATH_PATTERN = /^\\/fetch\\/([a-f0-9]{48})(\\/.*)?$/;\nconst MAX_SQLITE_SAFE_INTEGER = Number.MAX_SAFE_INTEGER;\n\ninterface ActorSqliteMigration {\n\treadonly version: number;\n\treadonly sql: string;\n}\n\nconst ACTOR_SQLITE_MIGRATIONS = [\n\t{\n\t\tversion: 1,\n\t\tsql: `\n\t\t\tCREATE TABLE agentos_actor_preview_tokens (\n\t\t\t\ttoken TEXT PRIMARY KEY CHECK (length(token) = 48 AND token NOT GLOB '*[^0-9a-f]*'),\n\t\t\t\tport INTEGER NOT NULL CHECK (port BETWEEN 1 AND 65535),\n\t\t\t\tcreated_at_ms INTEGER NOT NULL CHECK (created_at_ms BETWEEN 0 AND ${MAX_SQLITE_SAFE_INTEGER}),\n\t\t\t\texpires_at_ms INTEGER NOT NULL CHECK (expires_at_ms > created_at_ms AND expires_at_ms <= ${MAX_SQLITE_SAFE_INTEGER})\n\t\t\t) STRICT;\n\t\t\tCREATE INDEX agentos_actor_preview_tokens_by_expiry\n\t\t\t\tON agentos_actor_preview_tokens(expires_at_ms);\n\t\t\tCREATE TABLE agentos_actor_dynamic_mounts (\n\t\t\t\tpath TEXT PRIMARY KEY CHECK (substr(path, 1, 1) = '/' AND instr(path, char(0)) = 0),\n\t\t\t\tdescriptor_json TEXT NOT NULL CHECK (json_valid(descriptor_json) AND json_type(descriptor_json) = 'object')\n\t\t\t) STRICT;\n\t\t\tCREATE TABLE agentos_actor_linked_software (\n\t\t\t\tpath TEXT PRIMARY KEY CHECK (length(path) > 0 AND instr(path, char(0)) = 0),\n\t\t\t\tdescriptor_json TEXT NOT NULL CHECK (json_valid(descriptor_json) AND json_type(descriptor_json) = 'object')\n\t\t\t) STRICT;\n\t\t`,\n\t},\n] as const satisfies readonly ActorSqliteMigration[];\n\ntype BuiltInEvents = {\n\t[K in keyof AgentOsEvents]: Type<AgentOsEvents[K]>;\n};\n\nconst builtInEvents: BuiltInEvents = {\n\tsessionEvent: event<SessionStreamEntry>(),\n\tvmBooted: event<VmBootedPayload>(),\n\tvmShutdown: event<VmShutdownPayload>(),\n\tprocessOutput: event<ProcessOutputPayload>(),\n\tprocessExit: event<ProcessExitPayload>(),\n\tshellData: event<ShellDataPayload>(),\n\tcronEvent: event<CronEvent>(),\n\tagentExit: event<AgentExitEvent>(),\n\tshellStderr: event<ShellDataPayload>(),\n\tshellExit: event<ShellExitPayload>(),\n};\ntype ActorDb = DatabaseProvider<RawAccess>;\ntype EventSchemaConfig = Record<string, any>;\ntype QueueSchemaConfig = Record<string, any>;\ntype AnyContext = ActorContext<any, any, any, any, any, ActorDb, any, any>;\n\ninterface RuntimeState {\n\tvm: Promise<AgentOs> | null;\n\tsubscribedSessions: Map<string, readonly (() => void)[]>;\n}\n\nconst runtimes = new Map<string, RuntimeState>();\n\nfunction runtimeFor(c: AnyContext): RuntimeState {\n\tlet runtime = runtimes.get(c.actorId);\n\tif (!runtime) {\n\t\truntime = { vm: null, subscribedSessions: new Map() };\n\t\truntimes.set(c.actorId, runtime);\n\t}\n\treturn runtime;\n}\n\nasync function ensureVm(\n\tc: AnyContext,\n\toptions?: AgentOsOptions,\n): Promise<AgentOs> {\n\tconst runtime = runtimeFor(c);\n\tif (runtime.vm !== null) return runtime.vm;\n\n\tconst startedAt = Date.now();\n\truntime.vm = (async () => {\n\t\tconst actorRuntimeSocket = (\n\t\t\tc as AnyContext & {\n\t\t\t\tactorRuntimeSocket(): Promise<{ path: string }>;\n\t\t\t}\n\t\t).actorRuntimeSocket;\n\t\tif (typeof actorRuntimeSocket !== \"function\") {\n\t\t\tthrow new Error(\n\t\t\t\t\"AgentOS actors require a RivetKit runtime with Actor Runtime Socket support\",\n\t\t\t);\n\t\t}\n\t\tconst { path } = await actorRuntimeSocket.call(c);\n\t\tconst mountRows = await c.db.execute<{ descriptor_json: string }>(\n\t\t\t\"SELECT descriptor_json FROM agentos_actor_dynamic_mounts ORDER BY path\",\n\t\t);\n\t\tconst softwareRows = await c.db.execute<{ descriptor_json: string }>(\n\t\t\t\"SELECT descriptor_json FROM agentos_actor_linked_software ORDER BY path\",\n\t\t);\n\t\tconst vm = await AgentOs.create({\n\t\t\t...options,\n\t\t\tdatabase: { type: \"actor_uds\", path },\n\t\t\tonAgentExit: (event) => {\n\t\t\t\tc.log.error({\n\t\t\t\t\tmsg: \"agent-os agent adapter exited unexpectedly\",\n\t\t\t\t\t...event,\n\t\t\t\t});\n\t\t\t\tc.broadcast(\"agentExit\", event);\n\t\t\t\ttry {\n\t\t\t\t\toptions?.onAgentExit?.(event);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tc.log.error({\n\t\t\t\t\t\tmsg: \"agent-os onAgentExit hook failed\",\n\t\t\t\t\t\tsessionId: event.sessionId,\n\t\t\t\t\t\terror,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t},\n\t\t\trootFilesystem: {\n\t\t\t\ttype: \"native\",\n\t\t\t\tplugin: {\n\t\t\t\t\tid: \"chunked_actor_sqlite\",\n\t\t\t\t\tconfig: {\n\t\t\t\t\t\tnamespace: ROOT_NAMESPACE,\n\t\t\t\t\t\tchunkSize: ACTOR_SQLITE_CHUNK_SIZE,\n\t\t\t\t\t\tinlineThreshold: ACTOR_SQLITE_INLINE_THRESHOLD,\n\t\t\t\t\t\tuid: options?.user?.euid ?? options?.user?.uid ?? 1000,\n\t\t\t\t\t\tgid: options?.user?.egid ?? options?.user?.gid ?? 1000,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\t\ttry {\n\t\t\tfor (const row of mountRows) {\n\t\t\t\tawait vm.mountFs(\n\t\t\t\t\tJSON.parse(row.descriptor_json) as DynamicMountDescriptor,\n\t\t\t\t);\n\t\t\t}\n\t\t\tfor (const row of softwareRows) {\n\t\t\t\tawait vm.linkSoftware(\n\t\t\t\t\tJSON.parse(row.descriptor_json) as PackageDescriptor,\n\t\t\t\t);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tawait vm.dispose();\n\t\t\tthrow error;\n\t\t}\n\t\tvm.onCronEvent((cronEvent) => c.broadcast(\"cronEvent\", cronEvent));\n\t\tc.broadcast(\"vmBooted\", {});\n\t\tc.log.info({\n\t\t\tmsg: \"agent-os vm booted\",\n\t\t\tbootDurationMs: Date.now() - startedAt,\n\t\t});\n\t\treturn vm;\n\t})();\n\n\ttry {\n\t\treturn await runtime.vm;\n\t} catch (error) {\n\t\truntime.vm = null;\n\t\tc.log.error({\n\t\t\tmsg: \"agent-os vm bootstrap failed\",\n\t\t\tactorId: c.actorId,\n\t\t\terror,\n\t\t});\n\t\tthrow error;\n\t}\n}\n\nasync function disposeVm(c: AnyContext, reason: \"sleep\" | \"destroy\" | \"error\") {\n\tconst runtime = runtimes.get(c.actorId);\n\tif (!runtime) return;\n\tconst vm = runtime.vm;\n\truntimes.delete(c.actorId);\n\tfor (const unsubscribers of runtime.subscribedSessions.values()) {\n\t\tfor (const unsubscribe of unsubscribers) unsubscribe();\n\t}\n\truntime.subscribedSessions.clear();\n\tif (vm) await (await vm).dispose();\n\tc.broadcast(\"vmShutdown\", { reason });\n}\n\nfunction matchPreviewPath(pathname: string): RegExpMatchArray | null {\n\treturn pathname.match(PREVIEW_PATH_PATTERN);\n}\n\n/** @internal Exported only for focused migration-ladder tests. */\nexport function validateAgentOsActorMigrationLadder(\n\tmigrations: readonly ActorSqliteMigration[],\n): void {\n\tif (migrations.length === 0) {\n\t\tthrow new Error(\"AgentOS actor SQLite migration ladder must not be empty\");\n\t}\n\tfor (const [index, migration] of migrations.entries()) {\n\t\tconst expectedVersion = index + 1;\n\t\tif (migration.version !== expectedVersion) {\n\t\t\tthrow new Error(\n\t\t\t\t`invalid AgentOS actor SQLite migration ladder: expected version ${expectedVersion}, received ${migration.version}`,\n\t\t\t);\n\t\t}\n\t\tif (migration.sql.trim().length === 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`invalid AgentOS actor SQLite migration ${migration.version}: SQL is empty`,\n\t\t\t);\n\t\t}\n\t\tif (\n\t\t\t/(?:^|;)\\s*(?:BEGIN|COMMIT|ROLLBACK|SAVEPOINT|RELEASE)\\b/im.test(\n\t\t\t\tmigration.sql,\n\t\t\t)\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t`invalid AgentOS actor SQLite migration ${migration.version}: transaction control belongs to the migration provider`,\n\t\t\t);\n\t\t}\n\t\tif (/\\b(?:FOREIGN\\s+KEY|REFERENCES)\\b/i.test(migration.sql)) {\n\t\t\tthrow new Error(\n\t\t\t\t`invalid AgentOS actor SQLite migration ${migration.version}: foreign keys are not used in the actor-owned schema`,\n\t\t\t);\n\t\t}\n\t\tfor (const statement of migration.sql.split(\";\")) {\n\t\t\tif (\n\t\t\t\t/^\\s*CREATE\\s+TABLE\\b/i.test(statement) &&\n\t\t\t\t!/[)]\\s*STRICT\\s*$/i.test(statement)\n\t\t\t) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`invalid AgentOS actor SQLite migration ${migration.version}: every actor-owned table must be STRICT`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tconst ownedIdentifiers = migration.sql.match(/\\bagentos_[a-z0-9_]+\\b/gi);\n\t\tif (\n\t\t\t!ownedIdentifiers ||\n\t\t\townedIdentifiers.some(\n\t\t\t\t(identifier) => !identifier.startsWith(\"agentos_actor_\"),\n\t\t\t)\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t`invalid AgentOS actor SQLite migration ${migration.version}: migrations may reference only agentos_actor_* tables and indexes`,\n\t\t\t);\n\t\t}\n\t}\n}\n\n/** @internal Exported only for focused migration tests. */\nexport async function migrateAgentOsActorTables(\n\tdatabase: RawAccess,\n): Promise<void> {\n\tvalidateAgentOsActorMigrationLadder(ACTOR_SQLITE_MIGRATIONS);\n\tawait runAgentOsActorMigrations(database);\n}\n\nconst runAgentOsActorMigrations = migrations({\n\ttableName: \"agentos_actor_schema_version\",\n\tmigrations: ACTOR_SQLITE_MIGRATIONS,\n});\n\nasync function assertActorCollectionCapacity(\n\tc: AnyContext,\n\ttable: \"agentos_actor_dynamic_mounts\" | \"agentos_actor_linked_software\",\n\tkey: string,\n\tlimit: number,\n\tlabel: \"dynamic mounts\" | \"linked software packages\",\n\tconfigKey: \"maxDynamicMounts\" | \"maxLinkedSoftware\",\n): Promise<void> {\n\tconst existing = await c.db.execute<{ present: number }>(\n\t\t`SELECT 1 AS present FROM ${table} WHERE path = ? LIMIT 1`,\n\t\tkey,\n\t);\n\tif (existing.length > 0) return;\n\tconst rows = await c.db.execute<{ count: number }>(\n\t\t`SELECT COUNT(*) AS count FROM ${table}`,\n\t);\n\tconst count = Number(rows[0]?.count ?? 0);\n\tif (count >= limit) {\n\t\tthrow new UserError(\n\t\t\t`${label} limit ${limit} reached; raise ${configKey} to persist more`,\n\t\t\t{\n\t\t\t\tcode: `agentos_${configKey === \"maxDynamicMounts\" ? \"dynamic_mount\" : \"linked_software\"}_limit`,\n\t\t\t\tmetadata: { limit },\n\t\t\t},\n\t\t);\n\t}\n\tif (count + 1 === Math.ceil(limit * 0.8)) {\n\t\tc.log.warn({\n\t\t\tmsg: `${label} are near the limit of ${limit}; raise ${configKey} to persist more`,\n\t\t\tcount: count + 1,\n\t\t\tlimit,\n\t\t});\n\t}\n}\n\nexport interface AgentOsEventHooks<TContext = AnyContext> {\n\tonSessionEvent?: (\n\t\tc: TContext,\n\t\tsessionId: string,\n\t\tevent: SessionStreamEntry,\n\t) => void | Promise<void>;\n}\n\nfunction trackSessionEvents(\n\tc: AnyContext,\n\tvm: AgentOs,\n\tsessionId: string,\n\thooks: AgentOsEventHooks,\n\tmaxSessionSubscriptions: number,\n): void {\n\tconst runtime = runtimeFor(c);\n\tif (runtime.subscribedSessions.has(sessionId)) return;\n\tif (runtime.subscribedSessions.size >= maxSessionSubscriptions) {\n\t\tthrow new UserError(\n\t\t\t`session subscription limit ${maxSessionSubscriptions} reached; raise maxSessionSubscriptions to observe more sessions`,\n\t\t\t{\n\t\t\t\tcode: \"agentos_session_subscription_limit\",\n\t\t\t\tmetadata: { limit: maxSessionSubscriptions },\n\t\t\t},\n\t\t);\n\t}\n\tconst nextCount = runtime.subscribedSessions.size + 1;\n\tif (nextCount === Math.ceil(maxSessionSubscriptions * 0.8)) {\n\t\tc.log.warn({\n\t\t\tmsg: `session subscriptions are near the limit of ${maxSessionSubscriptions}; raise maxSessionSubscriptions to observe more sessions`,\n\t\t\tsubscriptionCount: nextCount,\n\t\t\tlimit: maxSessionSubscriptions,\n\t\t});\n\t}\n\tconst unsubscribeSession = vm.onSessionEvent(\n\t\tsessionId,\n\t\t(notification: SessionStreamEntry) => {\n\t\t\tconst serialized = JSON.parse(\n\t\t\t\tJSON.stringify(notification),\n\t\t\t) as SessionStreamEntry;\n\t\t\tc.broadcast(\"sessionEvent\", serialized);\n\t\t\tif (hooks.onSessionEvent) {\n\t\t\t\tvoid c.keepAwake(\n\t\t\t\t\tPromise.resolve()\n\t\t\t\t\t\t.then(() => hooks.onSessionEvent?.(c, sessionId, serialized))\n\t\t\t\t\t\t.catch((error) =>\n\t\t\t\t\t\t\tc.log.error({\n\t\t\t\t\t\t\t\tmsg: \"agent-os session event hook failed\",\n\t\t\t\t\t\t\t\tsessionId,\n\t\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t);\n\truntime.subscribedSessions.set(sessionId, [unsubscribeSession]);\n}\n\nfunction untrackSessionEvents(c: AnyContext, sessionId: string): void {\n\tconst unsubscribers = runtimeFor(c).subscribedSessions.get(sessionId);\n\tif (!unsubscribers) return;\n\tfor (const unsubscribe of unsubscribers) unsubscribe();\n\truntimeFor(c).subscribedSessions.delete(sessionId);\n}\n\nexport function createAgentOsActions(\n\toptions?: AgentOsOptions,\n\thooks: AgentOsEventHooks = {},\n\tpreview: AgentOsActorExtras[\"preview\"] = {},\n\tmaxSessionSubscriptions = DEFAULT_MAX_SESSION_SUBSCRIPTIONS,\n\tmaxDynamicMounts = DEFAULT_MAX_DYNAMIC_MOUNTS,\n\tmaxLinkedSoftware = DEFAULT_MAX_LINKED_SOFTWARE,\n) {\n\tconst defaultPreviewTtlSeconds =\n\t\tpreview.defaultExpiresInSeconds ?? DEFAULT_PREVIEW_TTL_SECONDS;\n\tconst maxPreviewTtlSeconds =\n\t\tpreview.maxExpiresInSeconds ?? MAX_PREVIEW_TTL_SECONDS;\n\tconst maxActivePreviewTokens =\n\t\tpreview.maxActiveTokens ?? DEFAULT_MAX_ACTIVE_PREVIEW_TOKENS;\n\tif (\n\t\t!Number.isFinite(defaultPreviewTtlSeconds) ||\n\t\tdefaultPreviewTtlSeconds <= 0 ||\n\t\t!Number.isFinite(maxPreviewTtlSeconds) ||\n\t\tmaxPreviewTtlSeconds <= 0 ||\n\t\tdefaultPreviewTtlSeconds > maxPreviewTtlSeconds\n\t) {\n\t\tthrow new UserError(\n\t\t\t\"preview expiry bounds must be positive and the default cannot exceed the maximum\",\n\t\t\t{ code: \"agentos_preview_invalid_config\" },\n\t\t);\n\t}\n\tif (!Number.isInteger(maxActivePreviewTokens) || maxActivePreviewTokens < 1) {\n\t\tthrow new UserError(\"preview.maxActiveTokens must be a positive integer\", {\n\t\t\tcode: \"agentos_preview_invalid_config\",\n\t\t});\n\t}\n\tif (\n\t\t!Number.isInteger(maxSessionSubscriptions) ||\n\t\tmaxSessionSubscriptions < 1\n\t) {\n\t\tthrow new UserError(\"maxSessionSubscriptions must be a positive integer\", {\n\t\t\tcode: \"agentos_session_subscription_invalid_config\",\n\t\t});\n\t}\n\tif (!Number.isInteger(maxDynamicMounts) || maxDynamicMounts < 1) {\n\t\tthrow new UserError(\"maxDynamicMounts must be a positive integer\", {\n\t\t\tcode: \"agentos_dynamic_mount_invalid_config\",\n\t\t});\n\t}\n\tif (!Number.isInteger(maxLinkedSoftware) || maxLinkedSoftware < 1) {\n\t\tthrow new UserError(\"maxLinkedSoftware must be a positive integer\", {\n\t\t\tcode: \"agentos_linked_software_invalid_config\",\n\t\t});\n\t}\n\treturn {\n\t\treadFile: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"readFile\"]>\n\t\t) => {\n\t\t\ttry {\n\t\t\t\treturn await (await ensureVm(c, options)).readFile(...args);\n\t\t\t} catch (error) {\n\t\t\t\tc.log.error({\n\t\t\t\t\tmsg: \"agent-os readFile action failed\",\n\t\t\t\t\tpath: args[0],\n\t\t\t\t\terror,\n\t\t\t\t});\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t\twriteFile: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"writeFile\"]>\n\t\t) => (await ensureVm(c, options)).writeFile(...args),\n\t\treadFiles: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"readFiles\"]>\n\t\t) => (await ensureVm(c, options)).readFiles(...args),\n\t\twriteFiles: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"writeFiles\"]>\n\t\t) => (await ensureVm(c, options)).writeFiles(...args),\n\t\tstat: async (c: AnyContext, ...args: Parameters<AgentOs[\"stat\"]>) =>\n\t\t\t(await ensureVm(c, options)).stat(...args),\n\t\tmkdir: async (c: AnyContext, ...args: Parameters<AgentOs[\"mkdir\"]>) =>\n\t\t\t(await ensureVm(c, options)).mkdir(...args),\n\t\treaddir: async (c: AnyContext, ...args: Parameters<AgentOs[\"readdir\"]>) =>\n\t\t\t(await ensureVm(c, options)).readdir(...args),\n\t\treaddirEntries: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"readdirEntries\"]>\n\t\t) => (await ensureVm(c, options)).readdirEntries(...args),\n\t\treaddirRecursive: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"readdirRecursive\"]>\n\t\t) => (await ensureVm(c, options)).readdirRecursive(...args),\n\t\texists: async (c: AnyContext, ...args: Parameters<AgentOs[\"exists\"]>) =>\n\t\t\t(await ensureVm(c, options)).exists(...args),\n\t\tmove: async (c: AnyContext, ...args: Parameters<AgentOs[\"move\"]>) =>\n\t\t\t(await ensureVm(c, options)).move(...args),\n\t\tremove: async (c: AnyContext, ...args: Parameters<AgentOs[\"remove\"]>) =>\n\t\t\t(await ensureVm(c, options)).remove(...args),\n\t\texec: async (c: AnyContext, ...args: Parameters<AgentOs[\"exec\"]>) =>\n\t\t\t(await ensureVm(c, options)).exec(...args),\n\t\texecArgv: async (c: AnyContext, ...args: Parameters<AgentOs[\"execArgv\"]>) =>\n\t\t\t(await ensureVm(c, options)).execArgv(...args),\n\t\tspawn: async (c: AnyContext, ...args: Parameters<AgentOs[\"spawn\"]>) => {\n\t\t\tconst vm = await ensureVm(c, options);\n\t\t\tconst process = vm.spawn(...args);\n\t\t\tconst unsubscribeOutput = vm.onProcessOutput(process.pid, (event) =>\n\t\t\t\tc.broadcast(\"processOutput\", event),\n\t\t\t);\n\t\t\tconst unsubscribeExit = vm.onProcessExit(process.pid, (event) =>\n\t\t\t\tc.broadcast(\"processExit\", event),\n\t\t\t);\n\t\t\tvoid c\n\t\t\t\t.keepAwake(\n\t\t\t\t\tvm.waitProcess(process.pid).finally(() => {\n\t\t\t\t\t\tunsubscribeOutput();\n\t\t\t\t\t\tunsubscribeExit();\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\t.catch((error) =>\n\t\t\t\t\tc.log.error({\n\t\t\t\t\t\tmsg: \"agent-os process wait failed\",\n\t\t\t\t\t\tpid: process.pid,\n\t\t\t\t\t\terror,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\treturn process;\n\t\t},\n\t\twaitProcess: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"waitProcess\"]>\n\t\t) => (await ensureVm(c, options)).waitProcess(...args),\n\t\tkillProcess: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"killProcess\"]>\n\t\t) => (await ensureVm(c, options)).killProcess(...args),\n\t\tstopProcess: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"stopProcess\"]>\n\t\t) => (await ensureVm(c, options)).stopProcess(...args),\n\t\tlistProcesses: async (c: AnyContext) =>\n\t\t\t(await ensureVm(c, options)).listProcesses(),\n\t\tallProcesses: async (c: AnyContext) =>\n\t\t\t(await ensureVm(c, options)).allProcesses(),\n\t\tprocessTree: async (c: AnyContext) =>\n\t\t\t(await ensureVm(c, options)).processTree(),\n\t\tgetProcess: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"getProcess\"]>\n\t\t) => (await ensureVm(c, options)).getProcess(...args),\n\t\twriteProcessStdin: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"writeProcessStdin\"]>\n\t\t) => (await ensureVm(c, options)).writeProcessStdin(...args),\n\t\tcloseProcessStdin: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"closeProcessStdin\"]>\n\t\t) => (await ensureVm(c, options)).closeProcessStdin(...args),\n\t\topenShell: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"openShell\"]>\n\t\t) => {\n\t\t\tconst vm = await ensureVm(c, options);\n\t\t\tconst shell = vm.openShell(...args);\n\t\t\tconst unsubscribeData = vm.onShellData(shell.shellId, (event) =>\n\t\t\t\tc.broadcast(\"shellData\", event),\n\t\t\t);\n\t\t\tconst unsubscribeStderr = vm.onShellStderr(shell.shellId, (event) =>\n\t\t\t\tc.broadcast(\"shellStderr\", event),\n\t\t\t);\n\t\t\tconst unsubscribeExit = vm.onShellExit(shell.shellId, (event) =>\n\t\t\t\tc.broadcast(\"shellExit\", event),\n\t\t\t);\n\t\t\tvoid c\n\t\t\t\t.keepAwake(\n\t\t\t\t\tvm.waitShell(shell.shellId).finally(() => {\n\t\t\t\t\t\tunsubscribeData();\n\t\t\t\t\t\tunsubscribeStderr();\n\t\t\t\t\t\tunsubscribeExit();\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\t.catch((error) =>\n\t\t\t\t\tc.log.error({\n\t\t\t\t\t\tmsg: \"agent-os shell wait failed\",\n\t\t\t\t\t\tshellId: shell.shellId,\n\t\t\t\t\t\terror,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\treturn shell;\n\t\t},\n\t\twriteShell: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"writeShell\"]>\n\t\t) => (await ensureVm(c, options)).writeShell(...args),\n\t\tresizeShell: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"resizeShell\"]>\n\t\t) => (await ensureVm(c, options)).resizeShell(...args),\n\t\tcloseShell: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"closeShell\"]>\n\t\t) => (await ensureVm(c, options)).closeShell(...args),\n\t\twaitShell: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"waitShell\"]>\n\t\t) => (await ensureVm(c, options)).waitShell(...args),\n\t\thttpRequest: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"httpRequest\"]>\n\t\t) => (await ensureVm(c, options)).httpRequest(...args),\n\t\tscheduleCron: async (\n\t\t\tc: AnyContext,\n\t\t\tcronOptions: SerializableCronJobOptions,\n\t\t) => {\n\t\t\tconst job = (await ensureVm(c, options)).scheduleCron(\n\t\t\t\tcronOptions as Parameters<AgentOs[\"scheduleCron\"]>[0],\n\t\t\t);\n\t\t\treturn { id: job.id };\n\t\t},\n\t\tlistCronJobs: async (c: AnyContext) =>\n\t\t\t(await ensureVm(c, options)).listCronJobs(),\n\t\tcancelCronJob: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"cancelCronJob\"]>\n\t\t) => (await ensureVm(c, options)).cancelCronJob(...args),\n\t\tlistAgents: async (c: AnyContext) =>\n\t\t\t(await ensureVm(c, options)).listAgents(),\n\t\topenSession: async (c: AnyContext, input: OpenSessionInput) => {\n\t\t\tconst vm = await ensureVm(c, options);\n\t\t\ttry {\n\t\t\t\tawait vm.openSession(input);\n\t\t\t} catch (error) {\n\t\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\t\tconst causeCode =\n\t\t\t\t\ttypeof (error as { code?: unknown })?.code === \"string\"\n\t\t\t\t\t\t? (error as { code: string }).code\n\t\t\t\t\t\t: undefined;\n\t\t\t\tc.log.error({\n\t\t\t\t\tmsg: \"agent-os openSession action failed\",\n\t\t\t\t\tsessionId: input.sessionId ?? \"main\",\n\t\t\t\t\tagent: input.agent,\n\t\t\t\t\tcauseCode,\n\t\t\t\t\terror,\n\t\t\t\t});\n\t\t\t\tthrow new UserError(`AgentOS openSession failed: ${message}`, {\n\t\t\t\t\tcode: \"agentos_session_open_failed\",\n\t\t\t\t\tmetadata: causeCode ? { causeCode } : undefined,\n\t\t\t\t});\n\t\t\t}\n\t\t\ttrackSessionEvents(\n\t\t\t\tc,\n\t\t\t\tvm,\n\t\t\t\tinput.sessionId ?? \"main\",\n\t\t\t\thooks,\n\t\t\t\tmaxSessionSubscriptions,\n\t\t\t);\n\t\t},\n\t\tgetSession: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"getSession\"]>\n\t\t) => (await ensureVm(c, options)).getSession(...args),\n\t\tlistSessions: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"listSessions\"]>\n\t\t) => (await ensureVm(c, options)).listSessions(...args),\n\t\tdeleteSession: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"deleteSession\"]>\n\t\t) => {\n\t\t\tconst result = await (await ensureVm(c, options)).deleteSession(...args);\n\t\t\tuntrackSessionEvents(c, args[0]?.sessionId ?? \"main\");\n\t\t\treturn result;\n\t\t},\n\t\tunloadSession: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"unloadSession\"]>\n\t\t) => {\n\t\t\tconst result = await (await ensureVm(c, options)).unloadSession(...args);\n\t\t\tuntrackSessionEvents(c, args[0]?.sessionId ?? \"main\");\n\t\t\treturn result;\n\t\t},\n\t\tprompt: async (c: AnyContext, input: PromptInput) => {\n\t\t\tconst vm = await ensureVm(c, options);\n\t\t\tconst sessionId = input.sessionId ?? \"main\";\n\t\t\ttrackSessionEvents(c, vm, sessionId, hooks, maxSessionSubscriptions);\n\t\t\t// The actor is held only through the terminal SQLite commit for this\n\t\t\t// active turn. Merely having an idle durable session holds nothing.\n\t\t\ttry {\n\t\t\t\treturn await c.keepAwake(vm.prompt(input));\n\t\t\t} catch (error) {\n\t\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\t\tconst causeCode =\n\t\t\t\t\ttypeof (error as { code?: unknown })?.code === \"string\"\n\t\t\t\t\t\t? (error as { code: string }).code\n\t\t\t\t\t\t: undefined;\n\t\t\t\tc.log.error({\n\t\t\t\t\tmsg: \"agent-os prompt action failed\",\n\t\t\t\t\tsessionId,\n\t\t\t\t\tcauseCode,\n\t\t\t\t\terror,\n\t\t\t\t});\n\t\t\t\tthrow new UserError(`AgentOS prompt failed: ${message}`, {\n\t\t\t\t\tcode: \"agentos_prompt_failed\",\n\t\t\t\t\tmetadata: causeCode ? { causeCode } : undefined,\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\tcancelPrompt: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"cancelPrompt\"]>\n\t\t) => (await ensureVm(c, options)).cancelPrompt(...args),\n\t\trespondPermission: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"respondPermission\"]>\n\t\t) => (await ensureVm(c, options)).respondPermission(...args),\n\t\treadHistory: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"readHistory\"]>\n\t\t) => (await ensureVm(c, options)).readHistory(...args),\n\t\tgetSessionConfig: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"getSessionConfig\"]>\n\t\t) => (await ensureVm(c, options)).getSessionConfig(...args),\n\t\tsetSessionConfigOption: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"setSessionConfigOption\"]>\n\t\t) => (await ensureVm(c, options)).setSessionConfigOption(...args),\n\t\tgetSessionCapabilities: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"getSessionCapabilities\"]>\n\t\t) => (await ensureVm(c, options)).getSessionCapabilities(...args),\n\t\tgetSessionAgentInfo: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"getSessionAgentInfo\"]>\n\t\t) => (await ensureVm(c, options)).getSessionAgentInfo(...args),\n\t\tcreatePreviewUrl: async (\n\t\t\tc: AnyContext,\n\t\t\tport: number,\n\t\t\tttlSeconds = defaultPreviewTtlSeconds,\n\t\t) => {\n\t\t\tif (!Number.isInteger(port) || port < 1 || port > 65_535)\n\t\t\t\tthrow new UserError(\n\t\t\t\t\t\"port must be an integer between 1 and 65535; pass a valid VM listener port\",\n\t\t\t\t\t{ code: \"agentos_preview_invalid_port\" },\n\t\t\t\t);\n\t\t\tif (\n\t\t\t\t!Number.isFinite(ttlSeconds) ||\n\t\t\t\tttlSeconds <= 0 ||\n\t\t\t\tttlSeconds > maxPreviewTtlSeconds\n\t\t\t)\n\t\t\t\tthrow new UserError(\n\t\t\t\t\t`ttlSeconds must be greater than 0 and at most ${maxPreviewTtlSeconds}; raise preview.maxExpiresInSeconds to allow a longer lifetime`,\n\t\t\t\t\t{ code: \"agentos_preview_invalid_ttl\" },\n\t\t\t\t);\n\t\t\tconst token = crypto.randomBytes(24).toString(\"hex\");\n\t\t\tconst createdAt = Date.now();\n\t\t\tconst expiresAt = createdAt + ttlSeconds * 1_000;\n\t\t\tawait c.db.execute(\n\t\t\t\t\"DELETE FROM agentos_actor_preview_tokens WHERE expires_at_ms <= ?\",\n\t\t\t\tcreatedAt,\n\t\t\t);\n\t\t\tconst counts = await c.db.execute<{ count: number }>(\n\t\t\t\t\"SELECT COUNT(*) AS count FROM agentos_actor_preview_tokens\",\n\t\t\t);\n\t\t\tconst activeTokenCount = Number(counts[0]?.count ?? 0);\n\t\t\tif (activeTokenCount >= maxActivePreviewTokens) {\n\t\t\t\tthrow new UserError(\n\t\t\t\t\t`preview token limit ${maxActivePreviewTokens} reached; raise preview.maxActiveTokens to allow more`,\n\t\t\t\t\t{\n\t\t\t\t\t\tcode: \"agentos_preview_token_limit\",\n\t\t\t\t\t\tmetadata: { limit: maxActivePreviewTokens },\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst nextActiveTokenCount = activeTokenCount + 1;\n\t\t\tconst warningThreshold = Math.ceil(maxActivePreviewTokens * 0.8);\n\t\t\tif (nextActiveTokenCount === warningThreshold) {\n\t\t\t\tc.log.warn({\n\t\t\t\t\tmsg: `preview tokens are near the limit of ${maxActivePreviewTokens}; raise preview.maxActiveTokens to allow more`,\n\t\t\t\t\tactiveTokenCount: nextActiveTokenCount,\n\t\t\t\t\tlimit: maxActivePreviewTokens,\n\t\t\t\t});\n\t\t\t}\n\t\t\tawait c.db.execute(\n\t\t\t\t\"INSERT INTO agentos_actor_preview_tokens (token, port, created_at_ms, expires_at_ms) VALUES (?, ?, ?, ?)\",\n\t\t\t\ttoken,\n\t\t\t\tport,\n\t\t\t\tcreatedAt,\n\t\t\t\texpiresAt,\n\t\t\t);\n\t\t\treturn { path: `/fetch/${token}`, token, port, expiresAt };\n\t\t},\n\t\texpirePreviewUrl: async (c: AnyContext, token: string) => {\n\t\t\tawait c.db.execute(\n\t\t\t\t\"DELETE FROM agentos_actor_preview_tokens WHERE token = ?\",\n\t\t\t\ttoken,\n\t\t\t);\n\t\t},\n\t\texportRootFilesystem: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"exportRootFilesystem\"]>\n\t\t) => (await ensureVm(c, options)).exportRootFilesystem(...args),\n\t\tmountFs: async (c: AnyContext, descriptor: DynamicMountDescriptor) => {\n\t\t\tawait assertActorCollectionCapacity(\n\t\t\t\tc,\n\t\t\t\t\"agentos_actor_dynamic_mounts\",\n\t\t\t\tdescriptor.path,\n\t\t\t\tmaxDynamicMounts,\n\t\t\t\t\"dynamic mounts\",\n\t\t\t\t\"maxDynamicMounts\",\n\t\t\t);\n\t\t\tconst vm = await ensureVm(c, options);\n\t\t\tawait vm.mountFs(descriptor);\n\t\t\ttry {\n\t\t\t\tawait c.db.execute(\n\t\t\t\t\t\"INSERT INTO agentos_actor_dynamic_mounts (path, descriptor_json) VALUES (?, ?) ON CONFLICT(path) DO UPDATE SET descriptor_json = excluded.descriptor_json\",\n\t\t\t\t\tdescriptor.path,\n\t\t\t\t\tJSON.stringify(descriptor),\n\t\t\t\t);\n\t\t\t} catch (error) {\n\t\t\t\ttry {\n\t\t\t\t\tawait vm.unmountFs(descriptor.path);\n\t\t\t\t} catch (rollbackError) {\n\t\t\t\t\tc.log.error({\n\t\t\t\t\t\tmsg: \"agent-os dynamic mount rollback failed\",\n\t\t\t\t\t\tpath: descriptor.path,\n\t\t\t\t\t\terror: rollbackError,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t\tunmountFs: async (c: AnyContext, path: string) => {\n\t\t\tconst rows = await c.db.execute<{ descriptor_json: string }>(\n\t\t\t\t\"SELECT descriptor_json FROM agentos_actor_dynamic_mounts WHERE path = ?\",\n\t\t\t\tpath,\n\t\t\t);\n\t\t\tconst vm = await ensureVm(c, options);\n\t\t\tawait vm.unmountFs(path);\n\t\t\ttry {\n\t\t\t\tawait c.db.execute(\n\t\t\t\t\t\"DELETE FROM agentos_actor_dynamic_mounts WHERE path = ?\",\n\t\t\t\t\tpath,\n\t\t\t\t);\n\t\t\t} catch (error) {\n\t\t\t\tif (rows[0]) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait vm.mountFs(\n\t\t\t\t\t\t\tJSON.parse(rows[0].descriptor_json) as DynamicMountDescriptor,\n\t\t\t\t\t\t);\n\t\t\t\t\t} catch (rollbackError) {\n\t\t\t\t\t\tc.log.error({\n\t\t\t\t\t\t\tmsg: \"agent-os dynamic unmount rollback failed\",\n\t\t\t\t\t\t\tpath,\n\t\t\t\t\t\t\terror: rollbackError,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t\tlistMounts: async (c: AnyContext) =>\n\t\t\t(await ensureVm(c, options)).listMounts(),\n\t\tlistSoftware: async (c: AnyContext) =>\n\t\t\t(await ensureVm(c, options)).listSoftware(),\n\t\tlinkSoftware: async (c: AnyContext, descriptor: PackageDescriptor) => {\n\t\t\tawait assertActorCollectionCapacity(\n\t\t\t\tc,\n\t\t\t\t\"agentos_actor_linked_software\",\n\t\t\t\tdescriptor.path,\n\t\t\t\tmaxLinkedSoftware,\n\t\t\t\t\"linked software packages\",\n\t\t\t\t\"maxLinkedSoftware\",\n\t\t\t);\n\t\t\tawait c.db.execute(\n\t\t\t\t\"INSERT INTO agentos_actor_linked_software (path, descriptor_json) VALUES (?, ?) ON CONFLICT(path) DO UPDATE SET descriptor_json = excluded.descriptor_json\",\n\t\t\t\tdescriptor.path,\n\t\t\t\tJSON.stringify(descriptor),\n\t\t\t);\n\t\t\ttry {\n\t\t\t\tawait (await ensureVm(c, options)).linkSoftware(descriptor);\n\t\t\t} catch (error) {\n\t\t\t\ttry {\n\t\t\t\t\tawait c.db.execute(\n\t\t\t\t\t\t\"DELETE FROM agentos_actor_linked_software WHERE path = ?\",\n\t\t\t\t\t\tdescriptor.path,\n\t\t\t\t\t);\n\t\t\t\t} catch (rollbackError) {\n\t\t\t\t\tc.log.error({\n\t\t\t\t\t\tmsg: \"agent-os linked software rollback failed\",\n\t\t\t\t\t\tpath: descriptor.path,\n\t\t\t\t\t\terror: rollbackError,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t};\n}\n\nexport type AgentOsActions = ReturnType<typeof createAgentOsActions>;\nexport type AgentOsActorDefinition<TConnParams = undefined> = ActorDefinition<\n\tundefined,\n\tTConnParams,\n\tundefined,\n\tundefined,\n\tundefined,\n\tActorDb,\n\tBuiltInEvents,\n\tRecord<never, never>,\n\tAgentOsActions\n>;\n\nexport interface AgentOsActorExtras extends AgentOsOptions {\n\t/** Maximum live session event subscriptions per actor VM. Default: 10,000. */\n\tmaxSessionSubscriptions?: number;\n\t/** Maximum durable dynamic mount descriptors per actor. Default: 10,000. */\n\tmaxDynamicMounts?: number;\n\t/** Maximum durable linked software descriptors per actor. Default: 10,000. */\n\tmaxLinkedSoftware?: number;\n\tpreview?: {\n\t\tdefaultExpiresInSeconds?: number;\n\t\tmaxExpiresInSeconds?: number;\n\t\tmaxActiveTokens?: number;\n\t};\n}\n\nexport type AgentOsActorConfigInput<\n\tTState = undefined,\n\tTConnParams = undefined,\n\tTConnState = undefined,\n\tTVars = undefined,\n\tTInput = undefined,\n\tTEvents extends EventSchemaConfig = Record<never, never>,\n\tTQueues extends QueueSchemaConfig = Record<never, never>,\n\tTUserActions extends Actions<\n\t\tTState,\n\t\tTConnParams,\n\t\tTConnState,\n\t\tTVars,\n\t\tTInput,\n\t\tActorDb,\n\t\tTEvents,\n\t\tTQueues\n\t> = Record<never, never>,\n> = Omit<\n\tActorConfigInput<\n\t\tTState,\n\t\tTConnParams,\n\t\tTConnState,\n\t\tTVars,\n\t\tTInput,\n\t\tActorDb,\n\t\tTEvents,\n\t\tTQueues,\n\t\tTUserActions\n\t>,\n\t\"db\"\n> &\n\tAgentOsActorExtras &\n\tAgentOsEventHooks<\n\t\tActorContext<\n\t\t\tTState,\n\t\t\tTConnParams,\n\t\t\tTConnState,\n\t\t\tTVars,\n\t\t\tTInput,\n\t\t\tActorDb,\n\t\t\tTEvents,\n\t\t\tTQueues\n\t\t>\n\t>;\n\nconst agentOsOptionKeys = [\n\t\"software\",\n\t\"defaultSoftware\",\n\t\"loopbackExemptPorts\",\n\t\"allowedNodeBuiltins\",\n\t\"highResolutionTime\",\n\t\"database\",\n\t\"rootFilesystem\",\n\t\"mounts\",\n\t\"sandbox\",\n\t\"scheduleDriver\",\n\t\"bindings\",\n\t\"permissions\",\n\t\"sidecar\",\n\t\"limits\",\n\t\"onAgentStderr\",\n\t\"onAgentExit\",\n\t\"onLimitWarning\",\n] as const satisfies readonly (keyof AgentOsOptions)[];\n\nfunction splitConfig(\n\tconfig: AgentOsActorConfigInput<any, any, any, any, any, any, any, any>,\n) {\n\tconst actorConfig = { ...config } as Record<string, unknown>;\n\tconst agentOsOptions: AgentOsOptions = {};\n\tfor (const key of agentOsOptionKeys) {\n\t\tif (key in actorConfig) {\n\t\t\t(agentOsOptions as Record<string, unknown>)[key] = actorConfig[key];\n\t\t\tdelete actorConfig[key];\n\t\t}\n\t}\n\tconst onSessionEvent =\n\t\tactorConfig.onSessionEvent as AgentOsEventHooks<AnyContext>[\"onSessionEvent\"];\n\tconst preview = actorConfig.preview as AgentOsActorExtras[\"preview\"];\n\tconst maxSessionSubscriptions = actorConfig.maxSessionSubscriptions as\n\t\t| number\n\t\t| undefined;\n\tconst maxDynamicMounts = actorConfig.maxDynamicMounts as number | undefined;\n\tconst maxLinkedSoftware = actorConfig.maxLinkedSoftware as number | undefined;\n\tdelete actorConfig.onSessionEvent;\n\tdelete actorConfig.preview;\n\tdelete actorConfig.maxSessionSubscriptions;\n\tdelete actorConfig.maxDynamicMounts;\n\tdelete actorConfig.maxLinkedSoftware;\n\treturn {\n\t\tactorConfig,\n\t\tagentOsOptions,\n\t\thooks: { onSessionEvent },\n\t\tpreview,\n\t\tmaxSessionSubscriptions,\n\t\tmaxDynamicMounts,\n\t\tmaxLinkedSoftware,\n\t};\n}\n\nfunction assertNoReservedKeys(\n\tkind: string,\n\tcustom: object | undefined,\n\tbuiltIns: object,\n) {\n\tfor (const key of Object.keys(custom ?? {})) {\n\t\tif (key in builtIns)\n\t\t\tthrow new Error(`agentOS() ${kind} name is reserved: ${key}`);\n\t}\n}\n\nexport function createAgentOS<\n\tTState = undefined,\n\tTConnParams = undefined,\n\tTConnState = undefined,\n\tTVars = undefined,\n\tTInput = undefined,\n\tTEvents extends EventSchemaConfig = Record<never, never>,\n\tTQueues extends QueueSchemaConfig = Record<never, never>,\n\tTUserActions extends Actions<\n\t\tTState,\n\t\tTConnParams,\n\t\tTConnState,\n\t\tTVars,\n\t\tTInput,\n\t\tActorDb,\n\t\tTEvents,\n\t\tTQueues\n\t> = Record<never, never>,\n>(\n\tconfig: AgentOsActorConfigInput<\n\t\tTState,\n\t\tTConnParams,\n\t\tTConnState,\n\t\tTVars,\n\t\tTInput,\n\t\tTEvents,\n\t\tTQueues,\n\t\tTUserActions\n\t> = {} as AgentOsActorConfigInput<\n\t\tTState,\n\t\tTConnParams,\n\t\tTConnState,\n\t\tTVars,\n\t\tTInput,\n\t\tTEvents,\n\t\tTQueues,\n\t\tTUserActions\n\t>,\n): ActorDefinition<\n\tTState,\n\tTConnParams,\n\tTConnState,\n\tTVars,\n\tTInput,\n\tActorDb,\n\tTEvents & BuiltInEvents,\n\tTQueues,\n\tTUserActions & AgentOsActions\n> {\n\tconst split = splitConfig(config);\n\tconst actorConfig = split.actorConfig as Omit<\n\t\ttypeof config,\n\t\tkeyof AgentOsActorExtras\n\t>;\n\tconst {\n\t\tagentOsOptions,\n\t\thooks,\n\t\tpreview,\n\t\tmaxSessionSubscriptions,\n\t\tmaxDynamicMounts,\n\t\tmaxLinkedSoftware,\n\t} = split;\n\tif (agentOsOptions.sandbox && \"client\" in agentOsOptions.sandbox) {\n\t\tthrow new Error(\n\t\t\t\"agentOS() cannot share sandbox: { client } across actor instances; use sandbox: { provider } so each actor VM starts its own client\",\n\t\t);\n\t}\n\tif (agentOsOptions.rootFilesystem) {\n\t\tthrow new Error(\n\t\t\t\"agentOS() owns rootFilesystem so it can persist directly through the actor SQLite UDS; use mounts for additional filesystems\",\n\t\t);\n\t}\n\tif (agentOsOptions.database) {\n\t\tthrow new Error(\n\t\t\t\"agentOS() owns database and injects the actor SQLite UDS descriptor; standalone AgentOs clients may choose a SQLite file\",\n\t\t);\n\t}\n\tconst actions = createAgentOsActions(\n\t\tagentOsOptions,\n\t\thooks,\n\t\tpreview,\n\t\tmaxSessionSubscriptions,\n\t\tmaxDynamicMounts,\n\t\tmaxLinkedSoftware,\n\t);\n\tassertNoReservedKeys(\"action\", actorConfig.actions, actions);\n\tassertNoReservedKeys(\"event\", actorConfig.events, builtInEvents);\n\n\tconst userOnWake = actorConfig.onWake;\n\tconst userOnSleep = actorConfig.onSleep;\n\tconst userOnDestroy = actorConfig.onDestroy;\n\tconst userOnRequest = actorConfig.onRequest;\n\tconst userOnBeforeConnect = actorConfig.onBeforeConnect;\n\n\treturn actor({\n\t\t...actorConfig,\n\t\toptions: {\n\t\t\tactionTimeout: DEFAULT_ACTION_TIMEOUT_MS,\n\t\t\tsleepGracePeriod: DEFAULT_SLEEP_GRACE_PERIOD_MS,\n\t\t\t...actorConfig.options,\n\t\t\tenableActorRuntimeSocket: true,\n\t\t},\n\t\tdb: db({ onMigrate: migrateAgentOsActorTables }),\n\t\tevents: { ...(actorConfig.events ?? {}), ...builtInEvents },\n\t\tactions: { ...(actorConfig.actions ?? {}), ...actions },\n\t\tonBeforeConnect: async (\n\t\t\tc: Parameters<NonNullable<typeof userOnBeforeConnect>>[0],\n\t\t\tparams: Parameters<NonNullable<typeof userOnBeforeConnect>>[1],\n\t\t) => {\n\t\t\tif (\n\t\t\t\tc.request &&\n\t\t\t\tmatchPreviewPath(new URL(c.request.url).pathname) !== null\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tawait userOnBeforeConnect?.(c, params);\n\t\t},\n\t\tonWake: async (c: AnyContext) => {\n\t\t\ttry {\n\t\t\t\tawait userOnWake?.(c);\n\t\t\t} catch (error) {\n\t\t\t\tawait disposeVm(c as AnyContext, \"error\");\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t\tonSleep: async (c: AnyContext) => {\n\t\t\ttry {\n\t\t\t\tawait userOnSleep?.(c);\n\t\t\t} finally {\n\t\t\t\tawait disposeVm(c as AnyContext, \"sleep\");\n\t\t\t}\n\t\t},\n\t\tonDestroy: async (c: AnyContext) => {\n\t\t\ttry {\n\t\t\t\tawait userOnDestroy?.(c);\n\t\t\t} finally {\n\t\t\t\tawait disposeVm(c as AnyContext, \"destroy\");\n\t\t\t}\n\t\t},\n\t\tonRequest: async (c: AnyContext, request: Request) => {\n\t\t\tconst url = new URL(request.url);\n\t\t\tconst match = matchPreviewPath(url.pathname);\n\t\t\tif (!match) {\n\t\t\t\tconst response = await userOnRequest?.(c as never, request);\n\t\t\t\treturn response ?? new Response(\"Not Found\", { status: 404 });\n\t\t\t}\n\t\t\tif (request.method === \"OPTIONS\")\n\t\t\t\treturn new Response(null, {\n\t\t\t\t\tstatus: 204,\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"access-control-allow-origin\": \"*\",\n\t\t\t\t\t\t\"access-control-allow-methods\":\n\t\t\t\t\t\t\t\"GET, POST, PUT, PATCH, DELETE, OPTIONS\",\n\t\t\t\t\t\t\"access-control-allow-headers\": \"*\",\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\tconst now = Date.now();\n\t\t\tawait c.db.execute(\n\t\t\t\t\"DELETE FROM agentos_actor_preview_tokens WHERE expires_at_ms <= ?\",\n\t\t\t\tnow,\n\t\t\t);\n\t\t\tconst rows = await c.db.execute<{ port: number }>(\n\t\t\t\t\"SELECT port FROM agentos_actor_preview_tokens WHERE token = ? AND expires_at_ms > ?\",\n\t\t\t\tmatch[1],\n\t\t\t\tnow,\n\t\t\t);\n\t\t\tif (!rows[0])\n\t\t\t\treturn new Response(\"Preview URL expired or invalid\", { status: 403 });\n\t\t\tconst target = new URL(request.url);\n\t\t\ttarget.pathname = match[2] ?? \"/\";\n\t\t\tconst vm = await ensureVm(c as AnyContext, agentOsOptions);\n\t\t\tconst requestHeaders: Record<string, string> = {};\n\t\t\trequest.headers.forEach((value, key) => {\n\t\t\t\trequestHeaders[key] = value;\n\t\t\t});\n\t\t\tconst response = await vm.httpRequest({\n\t\t\t\tport: rows[0].port,\n\t\t\t\tpath: `${target.pathname}${target.search}`,\n\t\t\t\tmethod: request.method,\n\t\t\t\theaders: requestHeaders,\n\t\t\t\t...(request.method === \"GET\" || request.method === \"HEAD\"\n\t\t\t\t\t? {}\n\t\t\t\t\t: { body: new Uint8Array(await request.arrayBuffer()) }),\n\t\t\t});\n\t\t\tconst headers = new Headers(response.headers);\n\t\t\theaders.set(\"access-control-allow-origin\", \"*\");\n\t\t\treturn new Response(Buffer.from(response.body), {\n\t\t\t\tstatus: response.status,\n\t\t\t\tstatusText: response.statusText,\n\t\t\t\theaders,\n\t\t\t});\n\t\t},\n\t} as any) as ActorDefinition<\n\t\tTState,\n\t\tTConnParams,\n\t\tTConnState,\n\t\tTVars,\n\t\tTInput,\n\t\tActorDb,\n\t\tTEvents & BuiltInEvents,\n\t\tTQ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,QAAQ,QAAQ,CAAC,OAAO,QAAQ;AACvC,uBAAe,GAAG,IAAI;AAAA,MACvB,CAAC;AACD,YAAM,WAAW,MAAM,GAAG,YAAY;AAAA,QACrC,MAAM,KAAK,CAAC,EAAE;AAAA,QACd,MAAM,GAAG,OAAO,QAAQ,GAAG,OAAO,MAAM;AAAA,QACxC,QAAQ,QAAQ;AAAA,QAChB,SAAS;AAAA,QACT,GAAI,QAAQ,WAAW,SAAS,QAAQ,WAAW,SAChD,CAAC,IACD,EAAE,MAAM,IAAI,WAAW,MAAM,QAAQ,YAAY,CAAC,EAAE;AAAA,MACxD,CAAC;AACD,YAAM,UAAU,IAAI,QAAQ,SAAS,OAAO;AAC5C,cAAQ,IAAI,+BAA+B,GAAG;AAC9C,aAAO,IAAI,SAAS,OAAO,KAAK,SAAS,IAAI,GAAG;AAAA,QAC/C,QAAQ,SAAS;AAAA,QACjB,YAAY,SAAS;AAAA,QACrB;AAAA,MACD,CAAC;AAAA,IACF;AAAA,EACD,CAAQ;AAWT;;;ADvtCA,IAAM,wCAAwC,MAAM,OAAO;AAMpD,IAAM,SAA+B,CAC3C,UAEA,cAAc;AAAA,EACb,GAAG;AAAA,EACH,wBAAwB;AAAA,EACxB,wBAAwB;AAAA,EACxB,sBAAsB;AACvB,CAAwC;","names":["event","migrations","response"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/actor.ts"],"sourcesContent":["import { setup as rivetkitSetup } from \"rivetkit\";\n\nexport type { Registry } from \"rivetkit\";\n\nconst AGENTOS_REGISTRY_MESSAGE_SIZE_DEFAULT = 512 * 1024 * 1024;\n\n/**\n * RivetKit setup with the direct actor SQLite UDS enabled. The UDS is consumed\n * by the AgentOS sidecar; filesystem SQL never crosses the JavaScript layer.\n */\nexport const setup: typeof rivetkitSetup = ((\n\tinput: Parameters<typeof rivetkitSetup>[0],\n) =>\n\trivetkitSetup({\n\t\t...input,\n\t\tmaxIncomingMessageSize: AGENTOS_REGISTRY_MESSAGE_SIZE_DEFAULT,\n\t\tmaxOutgoingMessageSize: AGENTOS_REGISTRY_MESSAGE_SIZE_DEFAULT,\n\t\texperimentalActorUds: true,\n\t} as Parameters<typeof rivetkitSetup>[0])) as typeof rivetkitSetup;\n\nexport type {\n\tAgentOsOptions,\n\tDirEntry,\n\tDynamicMountDescriptor,\n\tExportRootFilesystemOptions,\n\tHttpRequest,\n\tHttpResponse,\n\tMountInfo,\n\tNodeModulesMountConfig,\n\tPackageDescriptor,\n\tProcessExit,\n\tProcessOutput,\n\tPromptResult,\n\tReaddirEntry,\n\tRootSnapshotExport,\n\tSessionInfo,\n\tShellData,\n\tShellExit,\n} from \"@rivet-dev/agentos-core\";\nexport { defineSoftware, nodeModulesMount } from \"@rivet-dev/agentos-core\";\nexport type {\n\tAgentOsActorConfigInput as AgentOSActorConfigInput,\n\tAgentOsActorConfigInput as AgentOSConfigInput,\n} from \"./actor.js\";\nexport {\n\ttype AgentOsActions,\n\ttype AgentOsActorConfigInput,\n\ttype AgentOsActorExtras,\n\ttype AgentOsEventHooks,\n\tcreateAgentOS,\n\tcreateAgentOS as agentOS,\n\tcreateAgentOsActions,\n\ttype VmFetchOptions,\n\ttype VmFetchResponse,\n\ttype VmFetchStreamChunk,\n\ttype VmFetchStreamHead,\n} from \"./actor.js\";\nexport type {\n\tAgentOsEvents,\n\tProcessExitPayload,\n\tProcessOutputPayload,\n\tSerializableCronAction,\n\tSerializableCronEvent,\n\tSerializableCronJobInfo,\n\tSerializableCronJobOptions,\n\tShellDataPayload,\n\tShellExitPayload,\n\tVmBootedPayload,\n\tVmShutdownPayload,\n} from \"./types.js\";\n","import crypto from \"node:crypto\";\nimport {\n\ttype AgentExitEvent,\n\tAgentOs,\n\ttype AgentOsOptions,\n\ttype CronEvent,\n\ttype DynamicMountDescriptor,\n\ttype OpenSessionInput,\n\ttype PackageDescriptor,\n\ttype PromptInput,\n\ttype SessionStreamEntry,\n} from \"@rivet-dev/agentos-core\";\nimport {\n\ttype Actions,\n\ttype ActorConfigInput,\n\ttype ActorContext,\n\ttype ActorDefinition,\n\tactor,\n\tevent,\n\ttype Type,\n\tUserError,\n} from \"rivetkit\";\nimport { type DatabaseProvider, db, type RawAccess } from \"rivetkit/db\";\nimport { migrations } from \"rivetkit/unstable/migrations\";\nimport type {\n\tAgentOsEvents,\n\tProcessExitPayload,\n\tProcessOutputPayload,\n\tSerializableCronJobOptions,\n\tShellDataPayload,\n\tShellExitPayload,\n\tVmBootedPayload,\n\tVmShutdownPayload,\n} from \"./types.js\";\n\n// Prompts may remain paused at a permission request for a long human review.\n// RivetKit currently exposes only one actor-wide action timeout, so use the\n// largest value Node timers can represent safely (~24.8 days). Callers may\n// still opt into a shorter timeout through actor options.\nconst DEFAULT_ACTION_TIMEOUT_MS = 2_147_483_647;\nconst DEFAULT_SLEEP_GRACE_PERIOD_MS = 15 * 60_000;\nconst DEFAULT_PREVIEW_TTL_SECONDS = 3_600;\nconst MAX_PREVIEW_TTL_SECONDS = 86_400;\nconst DEFAULT_MAX_ACTIVE_PREVIEW_TOKENS = 1_024;\nconst DEFAULT_MAX_SESSION_SUBSCRIPTIONS = 10_000;\nconst DEFAULT_MAX_DYNAMIC_MOUNTS = 10_000;\nconst DEFAULT_MAX_LINKED_SOFTWARE = 10_000;\nconst ACTOR_SQLITE_CHUNK_SIZE = 512 * 1024;\nconst ACTOR_SQLITE_INLINE_THRESHOLD = 64 * 1024;\nconst ROOT_NAMESPACE = \"agentos-root\";\nconst PREVIEW_PATH_PATTERN = /^\\/fetch\\/([a-f0-9]{48})(\\/.*)?$/;\nconst MAX_SQLITE_SAFE_INTEGER = Number.MAX_SAFE_INTEGER;\n\ninterface ActorSqliteMigration {\n\treadonly version: number;\n\treadonly sql: string;\n}\n\nconst ACTOR_SQLITE_MIGRATIONS = [\n\t{\n\t\tversion: 1,\n\t\tsql: `\n\t\t\tCREATE TABLE agentos_actor_preview_tokens (\n\t\t\t\ttoken TEXT PRIMARY KEY CHECK (length(token) = 48 AND token NOT GLOB '*[^0-9a-f]*'),\n\t\t\t\tport INTEGER NOT NULL CHECK (port BETWEEN 1 AND 65535),\n\t\t\t\tcreated_at_ms INTEGER NOT NULL CHECK (created_at_ms BETWEEN 0 AND ${MAX_SQLITE_SAFE_INTEGER}),\n\t\t\t\texpires_at_ms INTEGER NOT NULL CHECK (expires_at_ms > created_at_ms AND expires_at_ms <= ${MAX_SQLITE_SAFE_INTEGER})\n\t\t\t) STRICT;\n\t\t\tCREATE INDEX agentos_actor_preview_tokens_by_expiry\n\t\t\t\tON agentos_actor_preview_tokens(expires_at_ms);\n\t\t\tCREATE TABLE agentos_actor_dynamic_mounts (\n\t\t\t\tpath TEXT PRIMARY KEY CHECK (substr(path, 1, 1) = '/' AND instr(path, char(0)) = 0),\n\t\t\t\tdescriptor_json TEXT NOT NULL CHECK (json_valid(descriptor_json) AND json_type(descriptor_json) = 'object')\n\t\t\t) STRICT;\n\t\t\tCREATE TABLE agentos_actor_linked_software (\n\t\t\t\tpath TEXT PRIMARY KEY CHECK (length(path) > 0 AND instr(path, char(0)) = 0),\n\t\t\t\tdescriptor_json TEXT NOT NULL CHECK (json_valid(descriptor_json) AND json_type(descriptor_json) = 'object')\n\t\t\t) STRICT;\n\t\t`,\n\t},\n] as const satisfies readonly ActorSqliteMigration[];\n\ntype BuiltInEvents = {\n\t[K in keyof AgentOsEvents]: Type<AgentOsEvents[K]>;\n};\n\nconst builtInEvents: BuiltInEvents = {\n\tsessionEvent: event<SessionStreamEntry>(),\n\tvmBooted: event<VmBootedPayload>(),\n\tvmShutdown: event<VmShutdownPayload>(),\n\tprocessOutput: event<ProcessOutputPayload>(),\n\tprocessExit: event<ProcessExitPayload>(),\n\tshellData: event<ShellDataPayload>(),\n\tcronEvent: event<CronEvent>(),\n\tagentExit: event<AgentExitEvent>(),\n\tshellStderr: event<ShellDataPayload>(),\n\tshellExit: event<ShellExitPayload>(),\n};\ntype ActorDb = DatabaseProvider<RawAccess>;\ntype EventSchemaConfig = Record<string, any>;\ntype QueueSchemaConfig = Record<string, any>;\ntype AnyContext = ActorContext<any, any, any, any, any, ActorDb, any, any>;\n\ninterface RuntimeState {\n\tvm: Promise<AgentOs> | null;\n\tsubscribedSessions: Map<string, readonly (() => void)[]>;\n\tonVmStop?: (\n\t\tc: AnyContext,\n\t\tvm: AgentOs,\n\t\treason: \"sleep\" | \"destroy\" | \"error\",\n\t) => void | Promise<void>;\n\tonVmDisposed?: (\n\t\tc: AnyContext,\n\t\treason: \"sleep\" | \"destroy\" | \"error\",\n\t) => void | Promise<void>;\n\tvmCleanupRan: boolean;\n\tfetchStreamHolds: Map<string, () => void>;\n}\n\nconst runtimes = new Map<string, RuntimeState>();\nconst optionResolvers = new WeakMap<\n\tAgentOsOptions,\n\t(c: AnyContext) => AgentOsOptions | Promise<AgentOsOptions>\n>();\nconst vmStartResolvers = new WeakMap<\n\tAgentOsOptions,\n\t(c: AnyContext, vm: AgentOs) => void | Promise<void>\n>();\nconst vmStopResolvers = new WeakMap<\n\tAgentOsOptions,\n\t(\n\t\tc: AnyContext,\n\t\tvm: AgentOs,\n\t\treason: \"sleep\" | \"destroy\" | \"error\",\n\t) => void | Promise<void>\n>();\nconst vmDisposedResolvers = new WeakMap<\n\tAgentOsOptions,\n\t(c: AnyContext, reason: \"sleep\" | \"destroy\" | \"error\") => void | Promise<void>\n>();\n\nfunction runtimeFor(c: AnyContext): RuntimeState {\n\tlet runtime = runtimes.get(c.actorId);\n\tif (!runtime) {\n\t\truntime = {\n\t\t\tvm: null,\n\t\t\tsubscribedSessions: new Map(),\n\t\t\tvmCleanupRan: false,\n\t\t\tfetchStreamHolds: new Map(),\n\t\t};\n\t\truntimes.set(c.actorId, runtime);\n\t}\n\treturn runtime;\n}\n\nasync function runVmDisposedHook(\n\truntime: RuntimeState,\n\tc: AnyContext,\n\treason: \"sleep\" | \"destroy\" | \"error\",\n): Promise<void> {\n\tif (runtime.vmCleanupRan) return;\n\truntime.vmCleanupRan = true;\n\tawait runtime.onVmDisposed?.(c, reason);\n}\n\nasync function ensureVm(\n\tc: AnyContext,\n\toptions?: AgentOsOptions,\n): Promise<AgentOs> {\n\tconst runtime = runtimeFor(c);\n\tif (runtime.vm !== null) return runtime.vm;\n\n\tconst startedAt = Date.now();\n\truntime.vmCleanupRan = false;\n\truntime.vm = (async () => {\n\t\truntime.onVmStop = options ? vmStopResolvers.get(options) : undefined;\n\t\truntime.onVmDisposed = options\n\t\t\t? vmDisposedResolvers.get(options)\n\t\t\t: undefined;\n\t\tconst resolvedOptions = {\n\t\t\t...options,\n\t\t\t...(options && optionResolvers.has(options)\n\t\t\t\t? await optionResolvers.get(options)?.(c)\n\t\t\t\t: undefined),\n\t\t};\n\t\tif (resolvedOptions.rootFilesystem) {\n\t\t\tthrow new Error(\n\t\t\t\t\"agentOS() owns rootFilesystem so it can persist directly through the actor SQLite UDS; resolveOptions may configure mounts but not rootFilesystem\",\n\t\t\t);\n\t\t}\n\t\tif (resolvedOptions.database) {\n\t\t\tthrow new Error(\n\t\t\t\t\"agentOS() owns database and injects the actor SQLite UDS descriptor; resolveOptions cannot replace it\",\n\t\t\t);\n\t\t}\n\t\tif (resolvedOptions.sandbox && \"client\" in resolvedOptions.sandbox) {\n\t\t\tthrow new Error(\n\t\t\t\t\"agentOS() cannot share sandbox: { client } across actor instances; resolveOptions must use sandbox: { provider }\",\n\t\t\t);\n\t\t}\n\t\tconst actorRuntimeSocket = (\n\t\t\tc as AnyContext & {\n\t\t\t\tactorRuntimeSocket(): Promise<{ path: string }>;\n\t\t\t}\n\t\t).actorRuntimeSocket;\n\t\tif (typeof actorRuntimeSocket !== \"function\") {\n\t\t\tthrow new Error(\n\t\t\t\t\"AgentOS actors require a RivetKit runtime with Actor Runtime Socket support\",\n\t\t\t);\n\t\t}\n\t\tconst { path } = await actorRuntimeSocket.call(c);\n\t\tconst mountRows = await c.db.execute<{ descriptor_json: string }>(\n\t\t\t\"SELECT descriptor_json FROM agentos_actor_dynamic_mounts ORDER BY path\",\n\t\t);\n\t\tconst softwareRows = await c.db.execute<{ descriptor_json: string }>(\n\t\t\t\"SELECT descriptor_json FROM agentos_actor_linked_software ORDER BY path\",\n\t\t);\n\t\tconst vm = await AgentOs.create({\n\t\t\t...resolvedOptions,\n\t\t\tdatabase: { type: \"actor_uds\", path },\n\t\t\tonAgentExit: (event) => {\n\t\t\t\tc.log.error({\n\t\t\t\t\tmsg: \"agent-os agent adapter exited unexpectedly\",\n\t\t\t\t\t...event,\n\t\t\t\t});\n\t\t\t\tc.broadcast(\"agentExit\", event);\n\t\t\t\ttry {\n\t\t\t\t\tresolvedOptions.onAgentExit?.(event);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tc.log.error({\n\t\t\t\t\t\tmsg: \"agent-os onAgentExit hook failed\",\n\t\t\t\t\t\tsessionId: event.sessionId,\n\t\t\t\t\t\terror,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t},\n\t\t\trootFilesystem: {\n\t\t\t\ttype: \"native\",\n\t\t\t\tplugin: {\n\t\t\t\t\tid: \"chunked_actor_sqlite\",\n\t\t\t\t\tconfig: {\n\t\t\t\t\t\tnamespace: ROOT_NAMESPACE,\n\t\t\t\t\t\tchunkSize: ACTOR_SQLITE_CHUNK_SIZE,\n\t\t\t\t\t\tinlineThreshold: ACTOR_SQLITE_INLINE_THRESHOLD,\n\t\t\t\t\t\tuid:\n\t\t\t\t\t\t\tresolvedOptions.user?.euid ?? resolvedOptions.user?.uid ?? 1000,\n\t\t\t\t\t\tgid:\n\t\t\t\t\t\t\tresolvedOptions.user?.egid ?? resolvedOptions.user?.gid ?? 1000,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\t\ttry {\n\t\t\tfor (const row of mountRows) {\n\t\t\t\tawait vm.mountFs(\n\t\t\t\t\tJSON.parse(row.descriptor_json) as DynamicMountDescriptor,\n\t\t\t\t);\n\t\t\t}\n\t\t\tfor (const row of softwareRows) {\n\t\t\t\tawait vm.linkSoftware(\n\t\t\t\t\tJSON.parse(row.descriptor_json) as PackageDescriptor,\n\t\t\t\t);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tawait vm.dispose();\n\t\t\tthrow error;\n\t\t}\n\t\tconst onVmStart = options ? vmStartResolvers.get(options) : undefined;\n\t\tif (onVmStart) {\n\t\t\ttry {\n\t\t\t\tawait onVmStart(c, vm);\n\t\t\t} catch (error) {\n\t\t\t\ttry {\n\t\t\t\t\tawait vm.dispose();\n\t\t\t\t} catch (disposeError) {\n\t\t\t\t\tc.log.error({\n\t\t\t\t\t\tmsg: \"failed to dispose AgentOS VM after start hook failure\",\n\t\t\t\t\t\tdisposeError,\n\t\t\t\t\t});\n\t\t\t\t} finally {\n\t\t\t\t\tawait runVmDisposedHook(runtime, c, \"error\");\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\tvm.onCronEvent((cronEvent) => c.broadcast(\"cronEvent\", cronEvent));\n\t\tc.broadcast(\"vmBooted\", {});\n\t\tc.log.info({\n\t\t\tmsg: \"agent-os vm booted\",\n\t\t\tbootDurationMs: Date.now() - startedAt,\n\t\t});\n\t\treturn vm;\n\t})();\n\n\ttry {\n\t\treturn await runtime.vm;\n\t} catch (error) {\n\t\truntime.vm = null;\n\t\tc.log.error({\n\t\t\tmsg: \"agent-os vm bootstrap failed\",\n\t\t\tactorId: c.actorId,\n\t\t\terror,\n\t\t});\n\t\tawait runVmDisposedHook(runtime, c, \"error\");\n\t\tthrow error;\n\t}\n}\n\nasync function disposeVm(c: AnyContext, reason: \"sleep\" | \"destroy\" | \"error\") {\n\tconst runtime = runtimes.get(c.actorId);\n\tif (!runtime) return;\n\tconst vm = runtime.vm;\n\truntimes.delete(c.actorId);\n\tfor (const unsubscribers of runtime.subscribedSessions.values()) {\n\t\tfor (const unsubscribe of unsubscribers) unsubscribe();\n\t}\n\truntime.subscribedSessions.clear();\n\tfor (const release of runtime.fetchStreamHolds.values()) release();\n\truntime.fetchStreamHolds.clear();\n\tif (vm) {\n\t\tconst failures: unknown[] = [];\n\t\ttry {\n\t\t\tconst resolvedVm = await vm;\n\t\t\ttry {\n\t\t\t\tawait runtime.onVmStop?.(c, resolvedVm, reason);\n\t\t\t} catch (error) {\n\t\t\t\tfailures.push(error);\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tawait resolvedVm.dispose();\n\t\t\t} catch (error) {\n\t\t\t\tfailures.push(error);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tfailures.push(error);\n\t\t}\n\t\ttry {\n\t\t\tawait runVmDisposedHook(runtime, c, reason);\n\t\t} catch (error) {\n\t\t\tfailures.push(error);\n\t\t}\n\t\tif (failures.length === 1) throw failures[0];\n\t\tif (failures.length > 1) {\n\t\t\tconst aggregate = new Error(\n\t\t\t\t\"failed to stop, dispose, or clean up AgentOS VM\",\n\t\t\t);\n\t\t\t(aggregate as Error & { errors: unknown[] }).errors = failures;\n\t\t\tthrow aggregate;\n\t\t}\n\t}\n\tc.broadcast(\"vmShutdown\", { reason });\n}\n\nfunction matchPreviewPath(pathname: string): RegExpMatchArray | null {\n\treturn pathname.match(PREVIEW_PATH_PATTERN);\n}\n\n/** @internal Exported only for focused migration-ladder tests. */\nexport function validateAgentOsActorMigrationLadder(\n\tmigrations: readonly ActorSqliteMigration[],\n): void {\n\tif (migrations.length === 0) {\n\t\tthrow new Error(\"AgentOS actor SQLite migration ladder must not be empty\");\n\t}\n\tfor (const [index, migration] of migrations.entries()) {\n\t\tconst expectedVersion = index + 1;\n\t\tif (migration.version !== expectedVersion) {\n\t\t\tthrow new Error(\n\t\t\t\t`invalid AgentOS actor SQLite migration ladder: expected version ${expectedVersion}, received ${migration.version}`,\n\t\t\t);\n\t\t}\n\t\tif (migration.sql.trim().length === 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`invalid AgentOS actor SQLite migration ${migration.version}: SQL is empty`,\n\t\t\t);\n\t\t}\n\t\tif (\n\t\t\t/(?:^|;)\\s*(?:BEGIN|COMMIT|ROLLBACK|SAVEPOINT|RELEASE)\\b/im.test(\n\t\t\t\tmigration.sql,\n\t\t\t)\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t`invalid AgentOS actor SQLite migration ${migration.version}: transaction control belongs to the migration provider`,\n\t\t\t);\n\t\t}\n\t\tif (/\\b(?:FOREIGN\\s+KEY|REFERENCES)\\b/i.test(migration.sql)) {\n\t\t\tthrow new Error(\n\t\t\t\t`invalid AgentOS actor SQLite migration ${migration.version}: foreign keys are not used in the actor-owned schema`,\n\t\t\t);\n\t\t}\n\t\tfor (const statement of migration.sql.split(\";\")) {\n\t\t\tif (\n\t\t\t\t/^\\s*CREATE\\s+TABLE\\b/i.test(statement) &&\n\t\t\t\t!/[)]\\s*STRICT\\s*$/i.test(statement)\n\t\t\t) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`invalid AgentOS actor SQLite migration ${migration.version}: every actor-owned table must be STRICT`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tconst ownedIdentifiers = migration.sql.match(/\\bagentos_[a-z0-9_]+\\b/gi);\n\t\tif (\n\t\t\t!ownedIdentifiers ||\n\t\t\townedIdentifiers.some(\n\t\t\t\t(identifier) => !identifier.startsWith(\"agentos_actor_\"),\n\t\t\t)\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t`invalid AgentOS actor SQLite migration ${migration.version}: migrations may reference only agentos_actor_* tables and indexes`,\n\t\t\t);\n\t\t}\n\t}\n}\n\n/** @internal Exported only for focused migration tests. */\nexport async function migrateAgentOsActorTables(\n\tdatabase: RawAccess,\n): Promise<void> {\n\tvalidateAgentOsActorMigrationLadder(ACTOR_SQLITE_MIGRATIONS);\n\tawait runAgentOsActorMigrations(database);\n}\n\nconst runAgentOsActorMigrations = migrations({\n\ttableName: \"agentos_actor_schema_version\",\n\tmigrations: ACTOR_SQLITE_MIGRATIONS,\n});\n\nasync function assertActorCollectionCapacity(\n\tc: AnyContext,\n\ttable: \"agentos_actor_dynamic_mounts\" | \"agentos_actor_linked_software\",\n\tkey: string,\n\tlimit: number,\n\tlabel: \"dynamic mounts\" | \"linked software packages\",\n\tconfigKey: \"maxDynamicMounts\" | \"maxLinkedSoftware\",\n): Promise<void> {\n\tconst existing = await c.db.execute<{ present: number }>(\n\t\t`SELECT 1 AS present FROM ${table} WHERE path = ? LIMIT 1`,\n\t\tkey,\n\t);\n\tif (existing.length > 0) return;\n\tconst rows = await c.db.execute<{ count: number }>(\n\t\t`SELECT COUNT(*) AS count FROM ${table}`,\n\t);\n\tconst count = Number(rows[0]?.count ?? 0);\n\tif (count >= limit) {\n\t\tthrow new UserError(\n\t\t\t`${label} limit ${limit} reached; raise ${configKey} to persist more`,\n\t\t\t{\n\t\t\t\tcode: `agentos_${configKey === \"maxDynamicMounts\" ? \"dynamic_mount\" : \"linked_software\"}_limit`,\n\t\t\t\tmetadata: { limit },\n\t\t\t},\n\t\t);\n\t}\n\tif (count + 1 === Math.ceil(limit * 0.8)) {\n\t\tc.log.warn({\n\t\t\tmsg: `${label} are near the limit of ${limit}; raise ${configKey} to persist more`,\n\t\t\tcount: count + 1,\n\t\t\tlimit,\n\t\t});\n\t}\n}\n\nexport interface VmFetchOptions {\n\tmethod?: string;\n\theaders?: Record<string, string>;\n\tbody?: string | Uint8Array;\n}\n\nexport interface VmFetchResponse {\n\tstatus: number;\n\tstatusText: string;\n\theaders: Record<string, string>;\n\trawHeaders?: Array<[string, string]>;\n\tbody: Uint8Array;\n}\n\nexport interface VmFetchStreamHead {\n\tstreamId: string;\n\tstatus: number;\n\tstatusText: string;\n\theaders: Record<string, string>;\n\trawHeaders?: Array<[string, string]>;\n}\n\nexport interface VmFetchStreamChunk {\n\tbody: Uint8Array;\n\tdone: boolean;\n}\n\nexport interface AgentOsEventHooks<TContext = AnyContext> {\n\tonSessionEvent?: (\n\t\tc: TContext,\n\t\tsessionId: string,\n\t\tevent: SessionStreamEntry,\n\t) => void | Promise<void>;\n}\n\nfunction trackSessionEvents(\n\tc: AnyContext,\n\tvm: AgentOs,\n\tsessionId: string,\n\thooks: AgentOsEventHooks,\n\tmaxSessionSubscriptions: number,\n): void {\n\tconst runtime = runtimeFor(c);\n\tif (runtime.subscribedSessions.has(sessionId)) return;\n\tif (runtime.subscribedSessions.size >= maxSessionSubscriptions) {\n\t\tthrow new UserError(\n\t\t\t`session subscription limit ${maxSessionSubscriptions} reached; raise maxSessionSubscriptions to observe more sessions`,\n\t\t\t{\n\t\t\t\tcode: \"agentos_session_subscription_limit\",\n\t\t\t\tmetadata: { limit: maxSessionSubscriptions },\n\t\t\t},\n\t\t);\n\t}\n\tconst nextCount = runtime.subscribedSessions.size + 1;\n\tif (nextCount === Math.ceil(maxSessionSubscriptions * 0.8)) {\n\t\tc.log.warn({\n\t\t\tmsg: `session subscriptions are near the limit of ${maxSessionSubscriptions}; raise maxSessionSubscriptions to observe more sessions`,\n\t\t\tsubscriptionCount: nextCount,\n\t\t\tlimit: maxSessionSubscriptions,\n\t\t});\n\t}\n\tconst unsubscribeSession = vm.onSessionEvent(\n\t\tsessionId,\n\t\t(notification: SessionStreamEntry) => {\n\t\t\tconst serialized = JSON.parse(\n\t\t\t\tJSON.stringify(notification),\n\t\t\t) as SessionStreamEntry;\n\t\t\tc.broadcast(\"sessionEvent\", serialized);\n\t\t\tif (hooks.onSessionEvent) {\n\t\t\t\tvoid c.keepAwake(\n\t\t\t\t\tPromise.resolve()\n\t\t\t\t\t\t.then(() => hooks.onSessionEvent?.(c, sessionId, serialized))\n\t\t\t\t\t\t.catch((error) =>\n\t\t\t\t\t\t\tc.log.error({\n\t\t\t\t\t\t\t\tmsg: \"agent-os session event hook failed\",\n\t\t\t\t\t\t\t\tsessionId,\n\t\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t);\n\truntime.subscribedSessions.set(sessionId, [unsubscribeSession]);\n}\n\nfunction untrackSessionEvents(c: AnyContext, sessionId: string): void {\n\tconst unsubscribers = runtimeFor(c).subscribedSessions.get(sessionId);\n\tif (!unsubscribers) return;\n\tfor (const unsubscribe of unsubscribers) unsubscribe();\n\truntimeFor(c).subscribedSessions.delete(sessionId);\n}\n\nfunction trackFetchStream(c: AnyContext, streamId: string): void {\n\tconst runtime = runtimeFor(c);\n\tif (runtime.fetchStreamHolds.has(streamId)) return;\n\tconst hold = new Promise<void>((resolve) => {\n\t\truntime.fetchStreamHolds.set(streamId, resolve);\n\t});\n\tvoid c.keepAwake(hold).catch((error) =>\n\t\tc.log.error({\n\t\t\tmsg: \"agent-os fetch stream hold failed\",\n\t\t\tstreamId,\n\t\t\terror,\n\t\t}),\n\t);\n}\n\nfunction releaseFetchStream(c: AnyContext, streamId: string): void {\n\tconst runtime = runtimeFor(c);\n\truntime.fetchStreamHolds.get(streamId)?.();\n\truntime.fetchStreamHolds.delete(streamId);\n}\n\nexport function createAgentOsActions(\n\toptions?: AgentOsOptions,\n\thooks: AgentOsEventHooks = {},\n\tpreview: AgentOsActorExtras[\"preview\"] = {},\n\tmaxSessionSubscriptions = DEFAULT_MAX_SESSION_SUBSCRIPTIONS,\n\tmaxDynamicMounts = DEFAULT_MAX_DYNAMIC_MOUNTS,\n\tmaxLinkedSoftware = DEFAULT_MAX_LINKED_SOFTWARE,\n) {\n\tconst defaultPreviewTtlSeconds =\n\t\tpreview.defaultExpiresInSeconds ?? DEFAULT_PREVIEW_TTL_SECONDS;\n\tconst maxPreviewTtlSeconds =\n\t\tpreview.maxExpiresInSeconds ?? MAX_PREVIEW_TTL_SECONDS;\n\tconst maxActivePreviewTokens =\n\t\tpreview.maxActiveTokens ?? DEFAULT_MAX_ACTIVE_PREVIEW_TOKENS;\n\tif (\n\t\t!Number.isFinite(defaultPreviewTtlSeconds) ||\n\t\tdefaultPreviewTtlSeconds <= 0 ||\n\t\t!Number.isFinite(maxPreviewTtlSeconds) ||\n\t\tmaxPreviewTtlSeconds <= 0 ||\n\t\tdefaultPreviewTtlSeconds > maxPreviewTtlSeconds\n\t) {\n\t\tthrow new UserError(\n\t\t\t\"preview expiry bounds must be positive and the default cannot exceed the maximum\",\n\t\t\t{ code: \"agentos_preview_invalid_config\" },\n\t\t);\n\t}\n\tif (!Number.isInteger(maxActivePreviewTokens) || maxActivePreviewTokens < 1) {\n\t\tthrow new UserError(\"preview.maxActiveTokens must be a positive integer\", {\n\t\t\tcode: \"agentos_preview_invalid_config\",\n\t\t});\n\t}\n\tif (\n\t\t!Number.isInteger(maxSessionSubscriptions) ||\n\t\tmaxSessionSubscriptions < 1\n\t) {\n\t\tthrow new UserError(\"maxSessionSubscriptions must be a positive integer\", {\n\t\t\tcode: \"agentos_session_subscription_invalid_config\",\n\t\t});\n\t}\n\tif (!Number.isInteger(maxDynamicMounts) || maxDynamicMounts < 1) {\n\t\tthrow new UserError(\"maxDynamicMounts must be a positive integer\", {\n\t\t\tcode: \"agentos_dynamic_mount_invalid_config\",\n\t\t});\n\t}\n\tif (!Number.isInteger(maxLinkedSoftware) || maxLinkedSoftware < 1) {\n\t\tthrow new UserError(\"maxLinkedSoftware must be a positive integer\", {\n\t\t\tcode: \"agentos_linked_software_invalid_config\",\n\t\t});\n\t}\n\treturn {\n\t\treadFile: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"readFile\"]>\n\t\t) => {\n\t\t\ttry {\n\t\t\t\treturn await (await ensureVm(c, options)).readFile(...args);\n\t\t\t} catch (error) {\n\t\t\t\tc.log.error({\n\t\t\t\t\tmsg: \"agent-os readFile action failed\",\n\t\t\t\t\tpath: args[0],\n\t\t\t\t\terror,\n\t\t\t\t});\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t\twriteFile: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"writeFile\"]>\n\t\t) => (await ensureVm(c, options)).writeFile(...args),\n\t\treadFiles: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"readFiles\"]>\n\t\t) => (await ensureVm(c, options)).readFiles(...args),\n\t\twriteFiles: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"writeFiles\"]>\n\t\t) => (await ensureVm(c, options)).writeFiles(...args),\n\t\tstat: async (c: AnyContext, ...args: Parameters<AgentOs[\"stat\"]>) =>\n\t\t\t(await ensureVm(c, options)).stat(...args),\n\t\tmkdir: async (c: AnyContext, ...args: Parameters<AgentOs[\"mkdir\"]>) =>\n\t\t\t(await ensureVm(c, options)).mkdir(...args),\n\t\treaddir: async (c: AnyContext, ...args: Parameters<AgentOs[\"readdir\"]>) =>\n\t\t\t(await ensureVm(c, options)).readdir(...args),\n\t\treaddirEntries: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"readdirEntries\"]>\n\t\t) => (await ensureVm(c, options)).readdirEntries(...args),\n\t\treaddirRecursive: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"readdirRecursive\"]>\n\t\t) => (await ensureVm(c, options)).readdirRecursive(...args),\n\t\texists: async (c: AnyContext, ...args: Parameters<AgentOs[\"exists\"]>) =>\n\t\t\t(await ensureVm(c, options)).exists(...args),\n\t\tmove: async (c: AnyContext, ...args: Parameters<AgentOs[\"move\"]>) =>\n\t\t\t(await ensureVm(c, options)).move(...args),\n\t\tremove: async (c: AnyContext, ...args: Parameters<AgentOs[\"remove\"]>) =>\n\t\t\t(await ensureVm(c, options)).remove(...args),\n\t\texec: async (c: AnyContext, ...args: Parameters<AgentOs[\"exec\"]>) =>\n\t\t\t(await ensureVm(c, options)).exec(...args),\n\t\texecArgv: async (c: AnyContext, ...args: Parameters<AgentOs[\"execArgv\"]>) =>\n\t\t\t(await ensureVm(c, options)).execArgv(...args),\n\t\tspawn: async (c: AnyContext, ...args: Parameters<AgentOs[\"spawn\"]>) => {\n\t\t\tconst vm = await ensureVm(c, options);\n\t\t\tconst process = vm.spawn(...args);\n\t\t\tconst unsubscribeOutput = vm.onProcessOutput(process.pid, (event) =>\n\t\t\t\tc.broadcast(\"processOutput\", event),\n\t\t\t);\n\t\t\tconst unsubscribeExit = vm.onProcessExit(process.pid, (event) =>\n\t\t\t\tc.broadcast(\"processExit\", event),\n\t\t\t);\n\t\t\tvoid c\n\t\t\t\t.keepAwake(\n\t\t\t\t\tvm.waitProcess(process.pid).finally(() => {\n\t\t\t\t\t\tunsubscribeOutput();\n\t\t\t\t\t\tunsubscribeExit();\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\t.catch((error) =>\n\t\t\t\t\tc.log.error({\n\t\t\t\t\t\tmsg: \"agent-os process wait failed\",\n\t\t\t\t\t\tpid: process.pid,\n\t\t\t\t\t\terror,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\treturn process;\n\t\t},\n\t\twaitProcess: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"waitProcess\"]>\n\t\t) => (await ensureVm(c, options)).waitProcess(...args),\n\t\tkillProcess: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"killProcess\"]>\n\t\t) => (await ensureVm(c, options)).killProcess(...args),\n\t\tstopProcess: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"stopProcess\"]>\n\t\t) => (await ensureVm(c, options)).stopProcess(...args),\n\t\tlistProcesses: async (c: AnyContext) =>\n\t\t\t(await ensureVm(c, options)).listProcesses(),\n\t\tallProcesses: async (c: AnyContext) =>\n\t\t\t(await ensureVm(c, options)).allProcesses(),\n\t\tprocessTree: async (c: AnyContext) =>\n\t\t\t(await ensureVm(c, options)).processTree(),\n\t\tgetProcess: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"getProcess\"]>\n\t\t) => (await ensureVm(c, options)).getProcess(...args),\n\t\twriteProcessStdin: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"writeProcessStdin\"]>\n\t\t) => (await ensureVm(c, options)).writeProcessStdin(...args),\n\t\tcloseProcessStdin: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"closeProcessStdin\"]>\n\t\t) => (await ensureVm(c, options)).closeProcessStdin(...args),\n\t\topenShell: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"openShell\"]>\n\t\t) => {\n\t\t\tconst vm = await ensureVm(c, options);\n\t\t\tconst shell = vm.openShell(...args);\n\t\t\tconst unsubscribeData = vm.onShellData(shell.shellId, (event) =>\n\t\t\t\tc.broadcast(\"shellData\", event),\n\t\t\t);\n\t\t\tconst unsubscribeStderr = vm.onShellStderr(shell.shellId, (event) =>\n\t\t\t\tc.broadcast(\"shellStderr\", event),\n\t\t\t);\n\t\t\tconst unsubscribeExit = vm.onShellExit(shell.shellId, (event) =>\n\t\t\t\tc.broadcast(\"shellExit\", event),\n\t\t\t);\n\t\t\tvoid c\n\t\t\t\t.keepAwake(\n\t\t\t\t\tvm.waitShell(shell.shellId).finally(() => {\n\t\t\t\t\t\tunsubscribeData();\n\t\t\t\t\t\tunsubscribeStderr();\n\t\t\t\t\t\tunsubscribeExit();\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\t.catch((error) =>\n\t\t\t\t\tc.log.error({\n\t\t\t\t\t\tmsg: \"agent-os shell wait failed\",\n\t\t\t\t\t\tshellId: shell.shellId,\n\t\t\t\t\t\terror,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\treturn shell;\n\t\t},\n\t\twriteShell: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"writeShell\"]>\n\t\t) => (await ensureVm(c, options)).writeShell(...args),\n\t\tresizeShell: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"resizeShell\"]>\n\t\t) => (await ensureVm(c, options)).resizeShell(...args),\n\t\tcloseShell: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"closeShell\"]>\n\t\t) => (await ensureVm(c, options)).closeShell(...args),\n\t\twaitShell: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"waitShell\"]>\n\t\t) => (await ensureVm(c, options)).waitShell(...args),\n\t\thttpRequest: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"httpRequest\"]>\n\t\t) => (await ensureVm(c, options)).httpRequest(...args),\n\t\tvmFetch: async (\n\t\t\tc: AnyContext,\n\t\t\tport: number,\n\t\t\turl: string,\n\t\t\trequestOptions?: VmFetchOptions,\n\t\t): Promise<VmFetchResponse> => {\n\t\t\tconst vm = await ensureVm(c, options);\n\t\t\tconst body =\n\t\t\t\trequestOptions?.body instanceof Uint8Array\n\t\t\t\t\t? Buffer.from(requestOptions.body)\n\t\t\t\t\t: requestOptions?.body;\n\t\t\tconst response = await vm.fetch(\n\t\t\t\tport,\n\t\t\t\tnew Request(url, {\n\t\t\t\t\tmethod: requestOptions?.method ?? \"GET\",\n\t\t\t\t\theaders: requestOptions?.headers,\n\t\t\t\t\tbody,\n\t\t\t\t}),\n\t\t\t);\n\t\t\tconst headers: Record<string, string> = {};\n\t\t\tconst rawHeaders: Array<[string, string]> = [];\n\t\t\tresponse.headers.forEach((value, key) => {\n\t\t\t\theaders[key] = value;\n\t\t\t\tif (key !== \"set-cookie\") rawHeaders.push([key, value]);\n\t\t\t});\n\t\t\tfor (const value of response.headers.getSetCookie?.() ?? []) {\n\t\t\t\trawHeaders.push([\"set-cookie\", value]);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tstatus: response.status,\n\t\t\t\tstatusText: response.statusText,\n\t\t\t\theaders,\n\t\t\t\trawHeaders,\n\t\t\t\tbody: new Uint8Array(await response.arrayBuffer()),\n\t\t\t};\n\t\t},\n\t\tvmFetchStreamStart: async (\n\t\t\tc: AnyContext,\n\t\t\tport: number,\n\t\t\turl: string,\n\t\t\trequestOptions?: VmFetchOptions,\n\t\t): Promise<VmFetchStreamHead> => {\n\t\t\tconst vm = await ensureVm(c, options);\n\t\t\tconst body =\n\t\t\t\trequestOptions?.body instanceof Uint8Array\n\t\t\t\t\t? Buffer.from(requestOptions.body)\n\t\t\t\t\t: requestOptions?.body;\n\t\t\tconst head = await vm.fetchStreamStart(\n\t\t\t\tport,\n\t\t\t\tnew Request(url, {\n\t\t\t\t\tmethod: requestOptions?.method ?? \"GET\",\n\t\t\t\t\theaders: requestOptions?.headers,\n\t\t\t\t\tbody,\n\t\t\t\t}),\n\t\t\t);\n\t\t\ttrackFetchStream(c, head.streamId);\n\t\t\tconst headers: Record<string, string> = {};\n\t\t\tfor (const [name, value] of head.headers) headers[name] = value;\n\t\t\treturn { ...head, headers, rawHeaders: head.headers };\n\t\t},\n\t\tvmFetchStreamRead: async (\n\t\t\tc: AnyContext,\n\t\t\tstreamId: string,\n\t\t\tmaxBytes?: number,\n\t\t): Promise<VmFetchStreamChunk> => {\n\t\t\ttry {\n\t\t\t\tconst chunk = await (await ensureVm(c, options)).fetchStreamRead(\n\t\t\t\t\tstreamId,\n\t\t\t\t\tmaxBytes,\n\t\t\t\t);\n\t\t\t\tif (chunk.done) releaseFetchStream(c, streamId);\n\t\t\t\treturn chunk;\n\t\t\t} catch (error) {\n\t\t\t\treleaseFetchStream(c, streamId);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t\tvmFetchStreamCancel: async (c: AnyContext, streamId: string) => {\n\t\t\ttry {\n\t\t\t\tawait (await ensureVm(c, options)).fetchStreamCancel(streamId);\n\t\t\t} finally {\n\t\t\t\treleaseFetchStream(c, streamId);\n\t\t\t}\n\t\t},\n\t\tscheduleCron: async (\n\t\t\tc: AnyContext,\n\t\t\tcronOptions: SerializableCronJobOptions,\n\t\t) => {\n\t\t\tconst job = (await ensureVm(c, options)).scheduleCron(\n\t\t\t\tcronOptions as Parameters<AgentOs[\"scheduleCron\"]>[0],\n\t\t\t);\n\t\t\treturn { id: job.id };\n\t\t},\n\t\tlistCronJobs: async (c: AnyContext) =>\n\t\t\t(await ensureVm(c, options)).listCronJobs(),\n\t\tcancelCronJob: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"cancelCronJob\"]>\n\t\t) => (await ensureVm(c, options)).cancelCronJob(...args),\n\t\tlistAgents: async (c: AnyContext) =>\n\t\t\t(await ensureVm(c, options)).listAgents(),\n\t\topenSession: async (c: AnyContext, input: OpenSessionInput) => {\n\t\t\tconst vm = await ensureVm(c, options);\n\t\t\ttry {\n\t\t\t\tawait vm.openSession(input);\n\t\t\t} catch (error) {\n\t\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\t\tconst causeCode =\n\t\t\t\t\ttypeof (error as { code?: unknown })?.code === \"string\"\n\t\t\t\t\t\t? (error as { code: string }).code\n\t\t\t\t\t\t: undefined;\n\t\t\t\tc.log.error({\n\t\t\t\t\tmsg: \"agent-os openSession action failed\",\n\t\t\t\t\tsessionId: input.sessionId ?? \"main\",\n\t\t\t\t\tagent: input.agent,\n\t\t\t\t\tcauseCode,\n\t\t\t\t\terror,\n\t\t\t\t});\n\t\t\t\tthrow new UserError(`AgentOS openSession failed: ${message}`, {\n\t\t\t\t\tcode: \"agentos_session_open_failed\",\n\t\t\t\t\tmetadata: causeCode ? { causeCode } : undefined,\n\t\t\t\t});\n\t\t\t}\n\t\t\ttrackSessionEvents(\n\t\t\t\tc,\n\t\t\t\tvm,\n\t\t\t\tinput.sessionId ?? \"main\",\n\t\t\t\thooks,\n\t\t\t\tmaxSessionSubscriptions,\n\t\t\t);\n\t\t},\n\t\tgetSession: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"getSession\"]>\n\t\t) => (await ensureVm(c, options)).getSession(...args),\n\t\tlistSessions: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"listSessions\"]>\n\t\t) => (await ensureVm(c, options)).listSessions(...args),\n\t\tdeleteSession: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"deleteSession\"]>\n\t\t) => {\n\t\t\tconst result = await (await ensureVm(c, options)).deleteSession(...args);\n\t\t\tuntrackSessionEvents(c, args[0]?.sessionId ?? \"main\");\n\t\t\treturn result;\n\t\t},\n\t\tunloadSession: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"unloadSession\"]>\n\t\t) => {\n\t\t\tconst result = await (await ensureVm(c, options)).unloadSession(...args);\n\t\t\tuntrackSessionEvents(c, args[0]?.sessionId ?? \"main\");\n\t\t\treturn result;\n\t\t},\n\t\tprompt: async (c: AnyContext, input: PromptInput) => {\n\t\t\tconst vm = await ensureVm(c, options);\n\t\t\tconst sessionId = input.sessionId ?? \"main\";\n\t\t\ttrackSessionEvents(c, vm, sessionId, hooks, maxSessionSubscriptions);\n\t\t\t// The actor is held only through the terminal SQLite commit for this\n\t\t\t// active turn. Merely having an idle durable session holds nothing.\n\t\t\ttry {\n\t\t\t\treturn await c.keepAwake(vm.prompt(input));\n\t\t\t} catch (error) {\n\t\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\t\tconst causeCode =\n\t\t\t\t\ttypeof (error as { code?: unknown })?.code === \"string\"\n\t\t\t\t\t\t? (error as { code: string }).code\n\t\t\t\t\t\t: undefined;\n\t\t\t\tc.log.error({\n\t\t\t\t\tmsg: \"agent-os prompt action failed\",\n\t\t\t\t\tsessionId,\n\t\t\t\t\tcauseCode,\n\t\t\t\t\terror,\n\t\t\t\t});\n\t\t\t\tthrow new UserError(`AgentOS prompt failed: ${message}`, {\n\t\t\t\t\tcode: \"agentos_prompt_failed\",\n\t\t\t\t\tmetadata: causeCode ? { causeCode } : undefined,\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\tcancelPrompt: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"cancelPrompt\"]>\n\t\t) => (await ensureVm(c, options)).cancelPrompt(...args),\n\t\trespondPermission: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"respondPermission\"]>\n\t\t) => (await ensureVm(c, options)).respondPermission(...args),\n\t\treadHistory: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"readHistory\"]>\n\t\t) => (await ensureVm(c, options)).readHistory(...args),\n\t\tgetSessionConfig: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"getSessionConfig\"]>\n\t\t) => (await ensureVm(c, options)).getSessionConfig(...args),\n\t\tsetSessionConfigOption: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"setSessionConfigOption\"]>\n\t\t) => (await ensureVm(c, options)).setSessionConfigOption(...args),\n\t\tgetSessionCapabilities: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"getSessionCapabilities\"]>\n\t\t) => (await ensureVm(c, options)).getSessionCapabilities(...args),\n\t\tgetSessionAgentInfo: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"getSessionAgentInfo\"]>\n\t\t) => (await ensureVm(c, options)).getSessionAgentInfo(...args),\n\t\tcreatePreviewUrl: async (\n\t\t\tc: AnyContext,\n\t\t\tport: number,\n\t\t\tttlSeconds = defaultPreviewTtlSeconds,\n\t\t) => {\n\t\t\tif (!Number.isInteger(port) || port < 1 || port > 65_535)\n\t\t\t\tthrow new UserError(\n\t\t\t\t\t\"port must be an integer between 1 and 65535; pass a valid VM listener port\",\n\t\t\t\t\t{ code: \"agentos_preview_invalid_port\" },\n\t\t\t\t);\n\t\t\tif (\n\t\t\t\t!Number.isFinite(ttlSeconds) ||\n\t\t\t\tttlSeconds <= 0 ||\n\t\t\t\tttlSeconds > maxPreviewTtlSeconds\n\t\t\t)\n\t\t\t\tthrow new UserError(\n\t\t\t\t\t`ttlSeconds must be greater than 0 and at most ${maxPreviewTtlSeconds}; raise preview.maxExpiresInSeconds to allow a longer lifetime`,\n\t\t\t\t\t{ code: \"agentos_preview_invalid_ttl\" },\n\t\t\t\t);\n\t\t\tconst token = crypto.randomBytes(24).toString(\"hex\");\n\t\t\tconst createdAt = Date.now();\n\t\t\tconst expiresAt = createdAt + ttlSeconds * 1_000;\n\t\t\tawait c.db.execute(\n\t\t\t\t\"DELETE FROM agentos_actor_preview_tokens WHERE expires_at_ms <= ?\",\n\t\t\t\tcreatedAt,\n\t\t\t);\n\t\t\tconst counts = await c.db.execute<{ count: number }>(\n\t\t\t\t\"SELECT COUNT(*) AS count FROM agentos_actor_preview_tokens\",\n\t\t\t);\n\t\t\tconst activeTokenCount = Number(counts[0]?.count ?? 0);\n\t\t\tif (activeTokenCount >= maxActivePreviewTokens) {\n\t\t\t\tthrow new UserError(\n\t\t\t\t\t`preview token limit ${maxActivePreviewTokens} reached; raise preview.maxActiveTokens to allow more`,\n\t\t\t\t\t{\n\t\t\t\t\t\tcode: \"agentos_preview_token_limit\",\n\t\t\t\t\t\tmetadata: { limit: maxActivePreviewTokens },\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst nextActiveTokenCount = activeTokenCount + 1;\n\t\t\tconst warningThreshold = Math.ceil(maxActivePreviewTokens * 0.8);\n\t\t\tif (nextActiveTokenCount === warningThreshold) {\n\t\t\t\tc.log.warn({\n\t\t\t\t\tmsg: `preview tokens are near the limit of ${maxActivePreviewTokens}; raise preview.maxActiveTokens to allow more`,\n\t\t\t\t\tactiveTokenCount: nextActiveTokenCount,\n\t\t\t\t\tlimit: maxActivePreviewTokens,\n\t\t\t\t});\n\t\t\t}\n\t\t\tawait c.db.execute(\n\t\t\t\t\"INSERT INTO agentos_actor_preview_tokens (token, port, created_at_ms, expires_at_ms) VALUES (?, ?, ?, ?)\",\n\t\t\t\ttoken,\n\t\t\t\tport,\n\t\t\t\tcreatedAt,\n\t\t\t\texpiresAt,\n\t\t\t);\n\t\t\treturn { path: `/fetch/${token}`, token, port, expiresAt };\n\t\t},\n\t\texpirePreviewUrl: async (c: AnyContext, token: string) => {\n\t\t\tawait c.db.execute(\n\t\t\t\t\"DELETE FROM agentos_actor_preview_tokens WHERE token = ?\",\n\t\t\t\ttoken,\n\t\t\t);\n\t\t},\n\t\texportRootFilesystem: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"exportRootFilesystem\"]>\n\t\t) => (await ensureVm(c, options)).exportRootFilesystem(...args),\n\t\tmountFs: async (c: AnyContext, descriptor: DynamicMountDescriptor) => {\n\t\t\tawait assertActorCollectionCapacity(\n\t\t\t\tc,\n\t\t\t\t\"agentos_actor_dynamic_mounts\",\n\t\t\t\tdescriptor.path,\n\t\t\t\tmaxDynamicMounts,\n\t\t\t\t\"dynamic mounts\",\n\t\t\t\t\"maxDynamicMounts\",\n\t\t\t);\n\t\t\tconst vm = await ensureVm(c, options);\n\t\t\tawait vm.mountFs(descriptor);\n\t\t\ttry {\n\t\t\t\tawait c.db.execute(\n\t\t\t\t\t\"INSERT INTO agentos_actor_dynamic_mounts (path, descriptor_json) VALUES (?, ?) ON CONFLICT(path) DO UPDATE SET descriptor_json = excluded.descriptor_json\",\n\t\t\t\t\tdescriptor.path,\n\t\t\t\t\tJSON.stringify(descriptor),\n\t\t\t\t);\n\t\t\t} catch (error) {\n\t\t\t\ttry {\n\t\t\t\t\tawait vm.unmountFs(descriptor.path);\n\t\t\t\t} catch (rollbackError) {\n\t\t\t\t\tc.log.error({\n\t\t\t\t\t\tmsg: \"agent-os dynamic mount rollback failed\",\n\t\t\t\t\t\tpath: descriptor.path,\n\t\t\t\t\t\terror: rollbackError,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t\tunmountFs: async (c: AnyContext, path: string) => {\n\t\t\tconst rows = await c.db.execute<{ descriptor_json: string }>(\n\t\t\t\t\"SELECT descriptor_json FROM agentos_actor_dynamic_mounts WHERE path = ?\",\n\t\t\t\tpath,\n\t\t\t);\n\t\t\tconst vm = await ensureVm(c, options);\n\t\t\tawait vm.unmountFs(path);\n\t\t\ttry {\n\t\t\t\tawait c.db.execute(\n\t\t\t\t\t\"DELETE FROM agentos_actor_dynamic_mounts WHERE path = ?\",\n\t\t\t\t\tpath,\n\t\t\t\t);\n\t\t\t} catch (error) {\n\t\t\t\tif (rows[0]) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait vm.mountFs(\n\t\t\t\t\t\t\tJSON.parse(rows[0].descriptor_json) as DynamicMountDescriptor,\n\t\t\t\t\t\t);\n\t\t\t\t\t} catch (rollbackError) {\n\t\t\t\t\t\tc.log.error({\n\t\t\t\t\t\t\tmsg: \"agent-os dynamic unmount rollback failed\",\n\t\t\t\t\t\t\tpath,\n\t\t\t\t\t\t\terror: rollbackError,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t\tlistMounts: async (c: AnyContext) =>\n\t\t\t(await ensureVm(c, options)).listMounts(),\n\t\tlistSoftware: async (c: AnyContext) =>\n\t\t\t(await ensureVm(c, options)).listSoftware(),\n\t\tlinkSoftware: async (c: AnyContext, descriptor: PackageDescriptor) => {\n\t\t\tawait assertActorCollectionCapacity(\n\t\t\t\tc,\n\t\t\t\t\"agentos_actor_linked_software\",\n\t\t\t\tdescriptor.path,\n\t\t\t\tmaxLinkedSoftware,\n\t\t\t\t\"linked software packages\",\n\t\t\t\t\"maxLinkedSoftware\",\n\t\t\t);\n\t\t\tawait c.db.execute(\n\t\t\t\t\"INSERT INTO agentos_actor_linked_software (path, descriptor_json) VALUES (?, ?) ON CONFLICT(path) DO UPDATE SET descriptor_json = excluded.descriptor_json\",\n\t\t\t\tdescriptor.path,\n\t\t\t\tJSON.stringify(descriptor),\n\t\t\t);\n\t\t\ttry {\n\t\t\t\tawait (await ensureVm(c, options)).linkSoftware(descriptor);\n\t\t\t} catch (error) {\n\t\t\t\ttry {\n\t\t\t\t\tawait c.db.execute(\n\t\t\t\t\t\t\"DELETE FROM agentos_actor_linked_software WHERE path = ?\",\n\t\t\t\t\t\tdescriptor.path,\n\t\t\t\t\t);\n\t\t\t\t} catch (rollbackError) {\n\t\t\t\t\tc.log.error({\n\t\t\t\t\t\tmsg: \"agent-os linked software rollback failed\",\n\t\t\t\t\t\tpath: descriptor.path,\n\t\t\t\t\t\terror: rollbackError,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t};\n}\n\nexport type AgentOsActions = ReturnType<typeof createAgentOsActions>;\nexport type AgentOsActorDefinition<TConnParams = undefined> = ActorDefinition<\n\tundefined,\n\tTConnParams,\n\tundefined,\n\tundefined,\n\tundefined,\n\tActorDb,\n\tBuiltInEvents,\n\tRecord<never, never>,\n\tAgentOsActions\n>;\n\nexport interface AgentOsActorExtras extends AgentOsOptions {\n\t/**\n\t * Resolve trusted VM options from actor state immediately before the VM's\n\t * first boot. Evaluated once per wake. The actor-owned root filesystem and\n\t * database cannot be replaced.\n\t */\n\tresolveOptions?: (c: AnyContext) => AgentOsOptions | Promise<AgentOsOptions>;\n\t/** Start long-lived processes after each VM boot. Trusted host code only. */\n\tonVmStart?: (c: AnyContext, vm: AgentOs) => void | Promise<void>;\n\t/** Gracefully stop long-lived processes before the VM is disposed. */\n\tonVmStop?: (\n\t\tc: AnyContext,\n\t\tvm: AgentOs,\n\t\treason: \"sleep\" | \"destroy\" | \"error\",\n\t) => void | Promise<void>;\n\t/** Clean up host resources after the VM and lazy mount readers close. */\n\tonVmDisposed?: (\n\t\tc: AnyContext,\n\t\treason: \"sleep\" | \"destroy\" | \"error\",\n\t) => void | Promise<void>;\n\t/** Maximum live session event subscriptions per actor VM. Default: 10,000. */\n\tmaxSessionSubscriptions?: number;\n\t/** Maximum durable dynamic mount descriptors per actor. Default: 10,000. */\n\tmaxDynamicMounts?: number;\n\t/** Maximum durable linked software descriptors per actor. Default: 10,000. */\n\tmaxLinkedSoftware?: number;\n\tpreview?: {\n\t\tdefaultExpiresInSeconds?: number;\n\t\tmaxExpiresInSeconds?: number;\n\t\tmaxActiveTokens?: number;\n\t};\n}\n\ntype DistributiveOmit<T, K extends PropertyKey> = T extends unknown\n\t? Omit<T, K>\n\t: never;\n\nexport type AgentOsActorConfigInput<\n\tTState = undefined,\n\tTConnParams = undefined,\n\tTConnState = undefined,\n\tTVars = undefined,\n\tTInput = undefined,\n\tTEvents extends EventSchemaConfig = Record<never, never>,\n\tTQueues extends QueueSchemaConfig = Record<never, never>,\n\tTUserActions extends Actions<\n\t\tTState,\n\t\tTConnParams,\n\t\tTConnState,\n\t\tTVars,\n\t\tTInput,\n\t\tActorDb,\n\t\tTEvents,\n\t\tTQueues\n\t> = Record<never, never>,\n> = DistributiveOmit<\n\tActorConfigInput<\n\t\tTState,\n\t\tTConnParams,\n\t\tTConnState,\n\t\tTVars,\n\t\tTInput,\n\t\tActorDb,\n\t\tTEvents,\n\t\tTQueues,\n\t\tTUserActions\n\t>,\n\t\"db\"\n> &\n\tAgentOsActorExtras &\n\tAgentOsEventHooks<\n\t\tActorContext<\n\t\t\tTState,\n\t\t\tTConnParams,\n\t\t\tTConnState,\n\t\t\tTVars,\n\t\t\tTInput,\n\t\t\tActorDb,\n\t\t\tTEvents,\n\t\t\tTQueues\n\t\t>\n\t>;\n\nconst agentOsOptionKeys = [\n\t\"software\",\n\t\"defaultSoftware\",\n\t\"loopbackExemptPorts\",\n\t\"allowedNodeBuiltins\",\n\t\"highResolutionTime\",\n\t\"database\",\n\t\"rootFilesystem\",\n\t\"mounts\",\n\t\"sandbox\",\n\t\"scheduleDriver\",\n\t\"bindings\",\n\t\"permissions\",\n\t\"sidecar\",\n\t\"limits\",\n\t\"onAgentStderr\",\n\t\"onAgentExit\",\n\t\"onLimitWarning\",\n] as const satisfies readonly (keyof AgentOsOptions)[];\n\nfunction splitConfig(\n\tconfig: AgentOsActorConfigInput<any, any, any, any, any, any, any, any>,\n) {\n\tconst actorConfig = { ...config } as Record<string, unknown>;\n\tconst agentOsOptions: AgentOsOptions = {};\n\tfor (const key of agentOsOptionKeys) {\n\t\tif (key in actorConfig) {\n\t\t\t(agentOsOptions as Record<string, unknown>)[key] = actorConfig[key];\n\t\t\tdelete actorConfig[key];\n\t\t}\n\t}\n\tconst onSessionEvent =\n\t\tactorConfig.onSessionEvent as AgentOsEventHooks<AnyContext>[\"onSessionEvent\"];\n\tconst preview = actorConfig.preview as AgentOsActorExtras[\"preview\"];\n\tconst resolveOptions = actorConfig.resolveOptions as\n\t\t| AgentOsActorExtras[\"resolveOptions\"]\n\t\t| undefined;\n\tconst onVmStart = actorConfig.onVmStart as AgentOsActorExtras[\"onVmStart\"];\n\tconst onVmStop = actorConfig.onVmStop as AgentOsActorExtras[\"onVmStop\"];\n\tconst onVmDisposed =\n\t\tactorConfig.onVmDisposed as AgentOsActorExtras[\"onVmDisposed\"];\n\tconst maxSessionSubscriptions = actorConfig.maxSessionSubscriptions as\n\t\t| number\n\t\t| undefined;\n\tconst maxDynamicMounts = actorConfig.maxDynamicMounts as number | undefined;\n\tconst maxLinkedSoftware = actorConfig.maxLinkedSoftware as number | undefined;\n\tdelete actorConfig.onSessionEvent;\n\tdelete actorConfig.preview;\n\tdelete actorConfig.resolveOptions;\n\tdelete actorConfig.onVmStart;\n\tdelete actorConfig.onVmStop;\n\tdelete actorConfig.onVmDisposed;\n\tdelete actorConfig.maxSessionSubscriptions;\n\tdelete actorConfig.maxDynamicMounts;\n\tdelete actorConfig.maxLinkedSoftware;\n\treturn {\n\t\tactorConfig,\n\t\tagentOsOptions,\n\t\thooks: { onSessionEvent },\n\t\tpreview,\n\t\tresolveOptions,\n\t\tonVmStart,\n\t\tonVmStop,\n\t\tonVmDisposed,\n\t\tmaxSessionSubscriptions,\n\t\tmaxDynamicMounts,\n\t\tmaxLinkedSoftware,\n\t};\n}\n\nfunction assertNoReservedKeys(\n\tkind: string,\n\tcustom: object | undefined,\n\tbuiltIns: object,\n) {\n\tfor (const key of Object.keys(custom ?? {})) {\n\t\tif (key in builtIns)\n\t\t\tthrow new Error(`agentOS() ${kind} name is reserved: ${key}`);\n\t}\n}\n\nexport function createAgentOS<\n\tTState = undefined,\n\tTConnParams = undefined,\n\tTConnState = undefined,\n\tTVars = undefined,\n\tTInput = undefined,\n\tTEvents extends EventSchemaConfig = Record<never, never>,\n\tTQueues extends QueueSchemaConfig = Record<never, never>,\n\tTUserActions extends Actions<\n\t\tTState,\n\t\tTConnParams,\n\t\tTConnState,\n\t\tTVars,\n\t\tTInput,\n\t\tActorDb,\n\t\tTEvents,\n\t\tTQueues\n\t> = Record<never, never>,\n>(\n\tconfig: AgentOsActorConfigInput<\n\t\tTState,\n\t\tTConnParams,\n\t\tTConnState,\n\t\tTVars,\n\t\tTInput,\n\t\tTEvents,\n\t\tTQueues,\n\t\tTUserActions\n\t> = {} as AgentOsActorConfigInput<\n\t\tTState,\n\t\tTConnParams,\n\t\tTConnState,\n\t\tTVars,\n\t\tTInput,\n\t\tTEvents,\n\t\tTQueues,\n\t\tTUserActions\n\t>,\n): ActorDefinition<\n\tTState,\n\tTConnParams,\n\tTConnState,\n\tTVars,\n\tTInput,\n\tActorDb,\n\tTEvents & BuiltInEvents,\n\tTQueues,\n\tTUserActions & AgentOsActions\n> {\n\tconst split = splitConfig(config);\n\tconst actorConfig = split.actorConfig as Omit<\n\t\ttypeof config,\n\t\tkeyof AgentOsActorExtras\n\t>;\n\tconst {\n\t\tagentOsOptions,\n\t\thooks,\n\t\tpreview,\n\t\tmaxSessionSubscriptions,\n\t\tmaxDynamicMounts,\n\t\tmaxLinkedSoftware,\n\t} = split;\n\tif (split.resolveOptions)\n\t\toptionResolvers.set(agentOsOptions, split.resolveOptions);\n\tif (split.onVmStart) vmStartResolvers.set(agentOsOptions, split.onVmStart);\n\tif (split.onVmStop) vmStopResolvers.set(agentOsOptions, split.onVmStop);\n\tif (split.onVmDisposed)\n\t\tvmDisposedResolvers.set(agentOsOptions, split.onVmDisposed);\n\tif (agentOsOptions.sandbox && \"client\" in agentOsOptions.sandbox) {\n\t\tthrow new Error(\n\t\t\t\"agentOS() cannot share sandbox: { client } across actor instances; use sandbox: { provider } so each actor VM starts its own client\",\n\t\t);\n\t}\n\tif (agentOsOptions.rootFilesystem) {\n\t\tthrow new Error(\n\t\t\t\"agentOS() owns rootFilesystem so it can persist directly through the actor SQLite UDS; use mounts for additional filesystems\",\n\t\t);\n\t}\n\tif (agentOsOptions.database) {\n\t\tthrow new Error(\n\t\t\t\"agentOS() owns database and injects the actor SQLite UDS descriptor; standalone AgentOs clients may choose a SQLite file\",\n\t\t);\n\t}\n\tconst actions = createAgentOsActions(\n\t\tagentOsOptions,\n\t\thooks,\n\t\tpreview,\n\t\tmaxSessionSubscriptions,\n\t\tmaxDynamicMounts,\n\t\tmaxLinkedSoftware,\n\t);\n\tassertNoReservedKeys(\"action\", actorConfig.actions, actions);\n\tassertNoReservedKeys(\"event\", actorConfig.events, builtInEvents);\n\n\tconst userOnWake = actorConfig.onWake;\n\tconst userOnSleep = actorConfig.onSleep;\n\tconst userOnDestroy = actorConfig.onDestroy;\n\tconst userOnRequest = actorConfig.onRequest;\n\tconst userOnBeforeConnect = actorConfig.onBeforeConnect;\n\n\treturn actor({\n\t\t...actorConfig,\n\t\toptions: {\n\t\t\tactionTimeout: DEFAULT_ACTION_TIMEOUT_MS,\n\t\t\tsleepGracePeriod: DEFAULT_SLEEP_GRACE_PERIOD_MS,\n\t\t\t...actorConfig.options,\n\t\t\tenableActorRuntimeSocket: true,\n\t\t},\n\t\tdb: db({ onMigrate: migrateAgentOsActorTables }),\n\t\tevents: { ...(actorConfig.events ?? {}), ...builtInEvents },\n\t\tactions: { ...(actorConfig.actions ?? {}), ...actions },\n\t\tonBeforeConnect: async (\n\t\t\tc: Parameters<NonNullable<typeof userOnBeforeConnect>>[0],\n\t\t\tparams: Parameters<NonNullable<typeof userOnBeforeConnect>>[1],\n\t\t) => {\n\t\t\tif (\n\t\t\t\tc.request &&\n\t\t\t\tmatchPreviewPath(new URL(c.request.url).pathname) !== null\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tawait userOnBeforeConnect?.(c, params);\n\t\t},\n\t\tonWake: async (c: AnyContext) => {\n\t\t\ttry {\n\t\t\t\tawait userOnWake?.(c);\n\t\t\t} catch (error) {\n\t\t\t\tawait disposeVm(c as AnyContext, \"error\");\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t\tonSleep: async (c: AnyContext) => {\n\t\t\ttry {\n\t\t\t\tawait userOnSleep?.(c);\n\t\t\t} finally {\n\t\t\t\tawait disposeVm(c as AnyContext, \"sleep\");\n\t\t\t}\n\t\t},\n\t\tonDestroy: async (c: AnyContext) => {\n\t\t\ttry {\n\t\t\t\tawait userOnDestroy?.(c);\n\t\t\t} finally {\n\t\t\t\tawait disposeVm(c as AnyContext, \"destroy\");\n\t\t\t}\n\t\t},\n\t\tonRequest: async (c: AnyContext, request: Request) => {\n\t\t\tconst url = new URL(request.url);\n\t\t\tconst match = matchPreviewPath(url.pathname);\n\t\t\tif (!match) {\n\t\t\t\tconst response = await userOnRequest?.(c as never, request);\n\t\t\t\treturn response ?? new Response(\"Not Found\", { status: 404 });\n\t\t\t}\n\t\t\tif (request.method === \"OPTIONS\")\n\t\t\t\treturn new Response(null, {\n\t\t\t\t\tstatus: 204,\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"access-control-allow-origin\": \"*\",\n\t\t\t\t\t\t\"access-control-allow-methods\":\n\t\t\t\t\t\t\t\"GET, POST, PUT, PATCH, DELETE, OPTIONS\",\n\t\t\t\t\t\t\"access-control-allow-headers\": \"*\",\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\tconst now = Date.now();\n\t\t\tawait c.db.execute(\n\t\t\t\t\"DELETE FROM agentos_actor_preview_tokens WHERE expires_at_ms <= ?\",\n\t\t\t\tnow,\n\t\t\t);\n\t\t\tconst rows = await c.db.execute<{ port: number }>(\n\t\t\t\t\"SELECT port FROM agentos_actor_preview_tokens WHERE token = ? AND expires_at_ms > ?\",\n\t\t\t\tmatch[1],\n\t\t\t\tnow,\n\t\t\t);\n\t\t\tif (!rows[0])\n\t\t\t\treturn new Response(\"Preview URL expired or invalid\", { status: 403 });\n\t\t\tconst target = new URL(request.url);\n\t\t\ttarget.pathname = match[2] ?? \"/\";\n\t\t\tconst vm = await ensureVm(c as AnyContext, agentOsOptions);\n\t\t\tconst requestHeaders: Record<string, string> = {};\n\t\t\trequest.headers.forEach((value, key) => {\n\t\t\t\trequestHeaders[key] = value;\n\t\t\t});\n\t\t\tconst response = await vm.httpRequest({\n\t\t\t\tport: rows[0].port,\n\t\t\t\tpath: `${target.pathname}${target.search}`,\n\t\t\t\tmethod: request.method,\n\t\t\t\theaders: requestHeaders,\n\t\t\t\t...(request.method === \"GET\" || request.method === \"HEAD\"\n\t\t\t\t\t? {}\n\t\t\t\t\t: { body: new Uint8Array(await request.arrayBuffer()) }),\n\t\t\t});\n\t\t\tconst headers = new Headers(response.headers);\n\t\t\theaders.set(\"access-control-allow-origin\", \"*\");\n\t\t\treturn new Response(Buffer.from(response.body), {\n\t\t\t\tstatus: response.status,\n\t\t\t\tstatusText: response.statusText,\n\t\t\t\theaders,\n\t\t\t});\n\t\t},\n\t} as any) as ActorDefinition<\n\t\tTState,\n\t\tTConnParams,\n\t\tTConnState,\n\t\tTVars,\n\t\tTInput,\n\t\tActorDb,\n\t\tTEvents & BuiltInEvents,\n\t\tTQueues,\n\t\tTUserActions & AgentOsActions\n\t>;\n}\n"],"mappings":";;;AAAA,SAAS,SAAS,qBAAqB;AAuCvC,SAAS,gBAAgB,wBAAwB;;;ACvCjD,OAAO,YAAY;AACnB;AAAA,EAEC;AAAA,OAQM;AACP;AAAA,EAKC;AAAA,EACA;AAAA,EAEA;AAAA,OACM;AACP,SAAgC,UAA0B;AAC1D,SAAS,kBAAkB;AAgB3B,IAAM,4BAA4B;AAClC,IAAM,gCAAgC,KAAK;AAC3C,IAAM,8BAA8B;AACpC,IAAM,0BAA0B;AAChC,IAAM,oCAAoC;AAC1C,IAAM,oCAAoC;AAC1C,IAAM,6BAA6B;AACnC,IAAM,8BAA8B;AACpC,IAAM,0BAA0B,MAAM;AACtC,IAAM,gCAAgC,KAA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EA,cAAc;AAAA,EACb,GAAG;AAAA,EACH,wBAAwB;AAAA,EACxB,wBAAwB;AAAA,EACxB,sBAAsB;AACvB,CAAwC;","names":["event","migrations","response"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rivet-dev/agentos",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.13",
|
|
4
4
|
"description": "A native TypeScript RivetKit actor backed by the AgentOS core SDK and sidecar.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"keywords": [
|
|
@@ -65,8 +65,8 @@
|
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"@agentclientprotocol/sdk": "0.16.1",
|
|
68
|
-
"@agentos-software/common": "0.2.
|
|
69
|
-
"@rivet-dev/agentos-core": "0.2.
|
|
68
|
+
"@agentos-software/common": "0.2.13",
|
|
69
|
+
"@rivet-dev/agentos-core": "0.2.13",
|
|
70
70
|
"@rivetkit/react": "2.3.9",
|
|
71
71
|
"rivetkit": "2.3.9",
|
|
72
72
|
"zod": "^4.1.11"
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
87
|
"@agentos-software/coreutils": "0.3.4",
|
|
88
|
-
"@rivet-dev/agentos-test-harness": "0.2.
|
|
88
|
+
"@rivet-dev/agentos-test-harness": "0.2.13",
|
|
89
89
|
"@radix-ui/react-collapsible": "^1.1.2",
|
|
90
90
|
"@radix-ui/react-scroll-area": "^1.2.2",
|
|
91
91
|
"@tanstack/react-query": "^5.87.1",
|