@rivet-dev/agentos 0.0.0-main.29b0797 → 0.0.0-main.5ac5a14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/inspector-tabs-app/assets/__vite-browser-external-2447137e-BIHI7g3E.js +1 -0
- package/assets/inspector-tabs-app/assets/agentos-hero-logo-E3fapwXM.svg +74 -0
- package/assets/inspector-tabs-app/assets/filesystem-C-x0K5sy.js +1 -0
- package/assets/inspector-tabs-app/assets/hooks-DU8a-cwM.js +1 -0
- package/assets/inspector-tabs-app/assets/index-7G_DbdZ6.js +110 -0
- package/assets/inspector-tabs-app/assets/index-DG_s1YoH.css +1 -0
- package/assets/inspector-tabs-app/assets/scroll-area-kPbv4IGy.js +1 -0
- package/assets/inspector-tabs-app/assets/sed-BwsOyU9v.svg +1 -0
- package/assets/inspector-tabs-app/assets/system-D98yBhMj.js +2 -0
- package/assets/inspector-tabs-app/assets/terminal-Bv9GKv4q.js +13 -0
- package/assets/inspector-tabs-app/assets/transcript-kMbm_tF8.js +1 -0
- package/assets/inspector-tabs-app/assets/useSuspenseQuery-ChN8rnBd.js +1 -0
- package/assets/inspector-tabs-app/assets/vm-boot-gate-rpuO0b5W.js +1 -0
- package/assets/inspector-tabs-app/assets/vm-status-badges-09qyfN_A.js +5 -0
- package/assets/inspector-tabs-app/index.html +2 -2
- package/dist/chunk-V6TY7KAL.js +8 -0
- package/dist/chunk-V6TY7KAL.js.map +1 -0
- package/dist/index.d.ts +328 -22
- package/dist/index.js +1238 -138
- package/dist/index.js.map +1 -1
- package/dist/node.d.ts +67 -0
- package/dist/node.js +275 -0
- package/dist/node.js.map +1 -0
- package/package.json +22 -10
- package/assets/inspector-tabs-app/assets/badge-NKTqivIc.js +0 -1
- package/assets/inspector-tabs-app/assets/filesystem-CyIvO-1j.js +0 -1
- package/assets/inspector-tabs-app/assets/index-DcBRn-yP.js +0 -125
- package/assets/inspector-tabs-app/assets/index-Dt5XhJ9h.css +0 -1
- package/assets/inspector-tabs-app/assets/mounts-DWpTN-N6.js +0 -1
- package/assets/inspector-tabs-app/assets/processes-CUocx7Ya.js +0 -1
- package/assets/inspector-tabs-app/assets/scroll-area-C07uoUZ4.js +0 -1
- package/assets/inspector-tabs-app/assets/software-ftDfKuwh.js +0 -1
- package/assets/inspector-tabs-app/assets/transcript-7Ao7EjSb.js +0 -1
- package/assets/inspector-tabs-app/assets/useSuspenseQuery-DBzwnHO3.js +0 -1
package/dist/index.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__publicField
|
|
3
|
+
} from "./chunk-V6TY7KAL.js";
|
|
4
|
+
|
|
1
5
|
// src/index.ts
|
|
2
6
|
import { setup as rivetkitSetup } from "rivetkit";
|
|
3
|
-
|
|
7
|
+
export * from "@rivet-dev/agentos-core";
|
|
4
8
|
|
|
5
9
|
// src/actor.ts
|
|
6
10
|
import crypto from "crypto";
|
|
11
|
+
import { dirname, join } from "path";
|
|
12
|
+
import { fileURLToPath } from "url";
|
|
7
13
|
import {
|
|
8
14
|
AgentOs
|
|
9
15
|
} from "@rivet-dev/agentos-core";
|
|
@@ -13,6 +19,276 @@ import {
|
|
|
13
19
|
UserError
|
|
14
20
|
} from "rivetkit";
|
|
15
21
|
import { db } from "rivetkit/db";
|
|
22
|
+
import { migrations } from "rivetkit/unstable/migrations";
|
|
23
|
+
|
|
24
|
+
// src/shell-replay.ts
|
|
25
|
+
import { readFile } from "fs/promises";
|
|
26
|
+
import { createRequire } from "module";
|
|
27
|
+
var MAX_REPLAY_SHELLS = 32;
|
|
28
|
+
var MAX_SCROLLBACK_LINES = 1e3;
|
|
29
|
+
var MAX_COLS = 1e3;
|
|
30
|
+
var MAX_ROWS = 1e3;
|
|
31
|
+
var DEFAULT_COLS = 80;
|
|
32
|
+
var DEFAULT_ROWS = 24;
|
|
33
|
+
var ghosttyPromise;
|
|
34
|
+
async function loadGhostty() {
|
|
35
|
+
ghosttyPromise ?? (ghosttyPromise = (async () => {
|
|
36
|
+
const require2 = createRequire(import.meta.url);
|
|
37
|
+
const { Ghostty } = await import("ghostty-web");
|
|
38
|
+
const bytes = await readFile(
|
|
39
|
+
require2.resolve("ghostty-web/ghostty-vt.wasm")
|
|
40
|
+
);
|
|
41
|
+
const webAssembly = Reflect.get(globalThis, "WebAssembly");
|
|
42
|
+
if (!webAssembly) {
|
|
43
|
+
throw new Error("WebAssembly is unavailable in this runtime");
|
|
44
|
+
}
|
|
45
|
+
const { instance } = await webAssembly.instantiate(bytes, {
|
|
46
|
+
env: { log: () => {
|
|
47
|
+
} }
|
|
48
|
+
});
|
|
49
|
+
const GhosttyConstructor = Ghostty;
|
|
50
|
+
return new GhosttyConstructor(instance);
|
|
51
|
+
})());
|
|
52
|
+
return ghosttyPromise;
|
|
53
|
+
}
|
|
54
|
+
var CELL_BOLD = 1;
|
|
55
|
+
var CELL_ITALIC = 2;
|
|
56
|
+
var CELL_UNDERLINE = 4;
|
|
57
|
+
var CELL_STRIKETHROUGH = 8;
|
|
58
|
+
var CELL_INVERSE = 16;
|
|
59
|
+
var CELL_INVISIBLE = 32;
|
|
60
|
+
var CELL_BLINK = 64;
|
|
61
|
+
var CELL_FAINT = 128;
|
|
62
|
+
var RESTORED_DEC_MODES = [
|
|
63
|
+
1,
|
|
64
|
+
// DECCKM — application cursor keys
|
|
65
|
+
7,
|
|
66
|
+
// DECAWM — autowrap
|
|
67
|
+
1e3,
|
|
68
|
+
// mouse: click tracking
|
|
69
|
+
1002,
|
|
70
|
+
// mouse: button-event tracking
|
|
71
|
+
1003,
|
|
72
|
+
// mouse: any-event tracking
|
|
73
|
+
1004,
|
|
74
|
+
// focus in/out reporting
|
|
75
|
+
1005,
|
|
76
|
+
// mouse: UTF-8 coordinates
|
|
77
|
+
1006,
|
|
78
|
+
// mouse: SGR coordinates
|
|
79
|
+
1015,
|
|
80
|
+
// mouse: urxvt coordinates
|
|
81
|
+
2004
|
|
82
|
+
// bracketed paste
|
|
83
|
+
];
|
|
84
|
+
var DEFAULT_STYLE = { fg: null, bg: null, flags: 0 };
|
|
85
|
+
function rgb(r, g, b) {
|
|
86
|
+
return r << 16 | g << 8 | b;
|
|
87
|
+
}
|
|
88
|
+
function styleOf(cell, defaultFg, defaultBg) {
|
|
89
|
+
const fg = rgb(cell.fg_r, cell.fg_g, cell.fg_b);
|
|
90
|
+
const bg = rgb(cell.bg_r, cell.bg_g, cell.bg_b);
|
|
91
|
+
return {
|
|
92
|
+
fg: fg === defaultFg ? null : fg,
|
|
93
|
+
bg: bg === defaultBg ? null : bg,
|
|
94
|
+
flags: cell.flags
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function sameStyle(a, b) {
|
|
98
|
+
return a.fg === b.fg && a.bg === b.bg && a.flags === b.flags;
|
|
99
|
+
}
|
|
100
|
+
function sgr(style) {
|
|
101
|
+
const params = [0];
|
|
102
|
+
if (style.flags & CELL_BOLD) params.push(1);
|
|
103
|
+
if (style.flags & CELL_FAINT) params.push(2);
|
|
104
|
+
if (style.flags & CELL_ITALIC) params.push(3);
|
|
105
|
+
if (style.flags & CELL_UNDERLINE) params.push(4);
|
|
106
|
+
if (style.flags & CELL_BLINK) params.push(5);
|
|
107
|
+
if (style.flags & CELL_INVERSE) params.push(7);
|
|
108
|
+
if (style.flags & CELL_INVISIBLE) params.push(8);
|
|
109
|
+
if (style.flags & CELL_STRIKETHROUGH) params.push(9);
|
|
110
|
+
if (style.fg !== null) {
|
|
111
|
+
params.push(
|
|
112
|
+
38,
|
|
113
|
+
2,
|
|
114
|
+
style.fg >> 16 & 255,
|
|
115
|
+
style.fg >> 8 & 255,
|
|
116
|
+
style.fg & 255
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
if (style.bg !== null) {
|
|
120
|
+
params.push(
|
|
121
|
+
48,
|
|
122
|
+
2,
|
|
123
|
+
style.bg >> 16 & 255,
|
|
124
|
+
style.bg >> 8 & 255,
|
|
125
|
+
style.bg & 255
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
return `\x1B[${params.join(";")}m`;
|
|
129
|
+
}
|
|
130
|
+
function serializeRow(cells, cols, defaultFg, defaultBg, graphemeAt) {
|
|
131
|
+
let lastMeaningful = -1;
|
|
132
|
+
for (let x = 0; x < cols; x++) {
|
|
133
|
+
const cell = cells[x];
|
|
134
|
+
if (!cell) continue;
|
|
135
|
+
const blank = cell.codepoint === 0 || cell.codepoint === 32;
|
|
136
|
+
if (!blank || !sameStyle(styleOf(cell, defaultFg, defaultBg), DEFAULT_STYLE)) {
|
|
137
|
+
lastMeaningful = x;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (lastMeaningful < 0) return "\x1B[0m\x1B[K";
|
|
141
|
+
let out = "";
|
|
142
|
+
let current = DEFAULT_STYLE;
|
|
143
|
+
out += sgr(current);
|
|
144
|
+
for (let x = 0; x <= lastMeaningful; x++) {
|
|
145
|
+
const cell = cells[x];
|
|
146
|
+
if (!cell) {
|
|
147
|
+
out += " ";
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (cell.width === 0) continue;
|
|
151
|
+
const style = styleOf(cell, defaultFg, defaultBg);
|
|
152
|
+
if (!sameStyle(style, current)) {
|
|
153
|
+
out += sgr(style);
|
|
154
|
+
current = style;
|
|
155
|
+
}
|
|
156
|
+
if (cell.grapheme_len > 0) {
|
|
157
|
+
out += graphemeAt(x);
|
|
158
|
+
} else if (cell.codepoint === 0) {
|
|
159
|
+
out += " ";
|
|
160
|
+
} else {
|
|
161
|
+
out += String.fromCodePoint(cell.codepoint);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return `${out}\x1B[0m\x1B[K`;
|
|
165
|
+
}
|
|
166
|
+
function clamp(value, fallback, max) {
|
|
167
|
+
if (!Number.isFinite(value) || value === void 0 || value <= 0)
|
|
168
|
+
return fallback;
|
|
169
|
+
return Math.min(Math.floor(value), max);
|
|
170
|
+
}
|
|
171
|
+
var ShellReplayStore = class {
|
|
172
|
+
constructor() {
|
|
173
|
+
__publicField(this, "entries", /* @__PURE__ */ new Map());
|
|
174
|
+
__publicField(this, "ghostty", null);
|
|
175
|
+
}
|
|
176
|
+
/** Instantiates the WASM module. Callers must await this before opening a
|
|
177
|
+
* shell so that `open` itself can be synchronous: a PTY starts producing
|
|
178
|
+
* output the moment it exists, and any await between opening it and
|
|
179
|
+
* subscribing is a window where output is lost to every consumer. */
|
|
180
|
+
async warm() {
|
|
181
|
+
this.ghostty ?? (this.ghostty = await loadGhostty());
|
|
182
|
+
}
|
|
183
|
+
open(shellId, cols, rows) {
|
|
184
|
+
if (this.entries.has(shellId)) return;
|
|
185
|
+
if (this.entries.size >= MAX_REPLAY_SHELLS) {
|
|
186
|
+
throw new Error(
|
|
187
|
+
`agent-os shell replay limit reached (${MAX_REPLAY_SHELLS} emulators); close a shell or raise MAX_REPLAY_SHELLS in shell-replay.ts`
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
if (!this.ghostty) {
|
|
191
|
+
throw new Error("agent-os shell replay used before warm() resolved");
|
|
192
|
+
}
|
|
193
|
+
const width = clamp(cols, DEFAULT_COLS, MAX_COLS);
|
|
194
|
+
const height = clamp(rows, DEFAULT_ROWS, MAX_ROWS);
|
|
195
|
+
const term = this.ghostty.createTerminal(width, height, {
|
|
196
|
+
scrollbackLimit: MAX_SCROLLBACK_LINES
|
|
197
|
+
});
|
|
198
|
+
term.write("\x1Bc");
|
|
199
|
+
this.entries.set(shellId, { term, cols: width, rows: height, seq: 0 });
|
|
200
|
+
}
|
|
201
|
+
/** Feeds one broadcast chunk and returns its sequence number. Clients use
|
|
202
|
+
* it to drop chunks a snapshot already contains. Returns 0 when this shell
|
|
203
|
+
* has no emulator, which clients read as "no replay available". */
|
|
204
|
+
feed(shellId, data) {
|
|
205
|
+
const entry = this.entries.get(shellId);
|
|
206
|
+
if (!entry) return 0;
|
|
207
|
+
entry.term.write(data);
|
|
208
|
+
return ++entry.seq;
|
|
209
|
+
}
|
|
210
|
+
resize(shellId, cols, rows) {
|
|
211
|
+
const entry = this.entries.get(shellId);
|
|
212
|
+
if (!entry) return;
|
|
213
|
+
entry.cols = clamp(cols, entry.cols, MAX_COLS);
|
|
214
|
+
entry.rows = clamp(rows, entry.rows, MAX_ROWS);
|
|
215
|
+
entry.term.resize(entry.cols, entry.rows);
|
|
216
|
+
}
|
|
217
|
+
close(shellId) {
|
|
218
|
+
const entry = this.entries.get(shellId);
|
|
219
|
+
if (!entry) return;
|
|
220
|
+
this.entries.delete(shellId);
|
|
221
|
+
entry.term.free();
|
|
222
|
+
}
|
|
223
|
+
has(shellId) {
|
|
224
|
+
return this.entries.has(shellId);
|
|
225
|
+
}
|
|
226
|
+
snapshot(shellId, mode) {
|
|
227
|
+
const entry = this.entries.get(shellId);
|
|
228
|
+
if (!entry) return null;
|
|
229
|
+
const { term, cols, rows, seq } = entry;
|
|
230
|
+
const base = { shellId, seq, cols, rows };
|
|
231
|
+
if (mode === "none") return { ...base, mode, data: "" };
|
|
232
|
+
term.update();
|
|
233
|
+
const colors = term.getColors();
|
|
234
|
+
const defaultFg = rgb(
|
|
235
|
+
colors.foreground.r,
|
|
236
|
+
colors.foreground.g,
|
|
237
|
+
colors.foreground.b
|
|
238
|
+
);
|
|
239
|
+
const defaultBg = rgb(
|
|
240
|
+
colors.background.r,
|
|
241
|
+
colors.background.g,
|
|
242
|
+
colors.background.b
|
|
243
|
+
);
|
|
244
|
+
const alternate = term.isAlternateScreen();
|
|
245
|
+
let out = "\x1Bc";
|
|
246
|
+
if (mode === "scrollback" && !alternate) {
|
|
247
|
+
const available = Math.min(
|
|
248
|
+
term.getScrollbackLength(),
|
|
249
|
+
MAX_SCROLLBACK_LINES
|
|
250
|
+
);
|
|
251
|
+
for (let i = available; i > 0; i--) {
|
|
252
|
+
const offset = i - 1;
|
|
253
|
+
const line = term.getScrollbackLine(offset);
|
|
254
|
+
if (!line) continue;
|
|
255
|
+
out += serializeRow(
|
|
256
|
+
line,
|
|
257
|
+
cols,
|
|
258
|
+
defaultFg,
|
|
259
|
+
defaultBg,
|
|
260
|
+
(col) => term.getScrollbackGraphemeString(offset, col)
|
|
261
|
+
);
|
|
262
|
+
out += "\r\n";
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
if (alternate) out += "\x1B[?1049h";
|
|
266
|
+
for (const decMode of RESTORED_DEC_MODES) {
|
|
267
|
+
out += term.getMode(decMode) ? `\x1B[?${decMode}h` : `\x1B[?${decMode}l`;
|
|
268
|
+
}
|
|
269
|
+
const viewport = term.getViewport();
|
|
270
|
+
out += "\x1B[H";
|
|
271
|
+
for (let y = 0; y < rows; y++) {
|
|
272
|
+
if (y > 0) out += "\r\n";
|
|
273
|
+
const row = viewport.slice(y * cols, (y + 1) * cols);
|
|
274
|
+
out += serializeRow(
|
|
275
|
+
row,
|
|
276
|
+
cols,
|
|
277
|
+
defaultFg,
|
|
278
|
+
defaultBg,
|
|
279
|
+
(col) => term.getGraphemeString(y, col)
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
const cursor = term.getCursor();
|
|
283
|
+
const cy = Math.min(Math.max(cursor.viewportY, 0), rows - 1) + 1;
|
|
284
|
+
const cx = Math.min(Math.max(cursor.viewportX, 0), cols - 1) + 1;
|
|
285
|
+
out += `\x1B[0m\x1B[${cy};${cx}H`;
|
|
286
|
+
out += cursor.visible ? "\x1B[?25h" : "\x1B[?25l";
|
|
287
|
+
return { ...base, mode, data: out };
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
// src/actor.ts
|
|
16
292
|
var DEFAULT_ACTION_TIMEOUT_MS = 2147483647;
|
|
17
293
|
var DEFAULT_SLEEP_GRACE_PERIOD_MS = 15 * 6e4;
|
|
18
294
|
var DEFAULT_PREVIEW_TTL_SECONDS = 3600;
|
|
@@ -26,6 +302,7 @@ var ACTOR_SQLITE_INLINE_THRESHOLD = 64 * 1024;
|
|
|
26
302
|
var ROOT_NAMESPACE = "agentos-root";
|
|
27
303
|
var PREVIEW_PATH_PATTERN = /^\/fetch\/([a-f0-9]{48})(\/.*)?$/;
|
|
28
304
|
var MAX_SQLITE_SAFE_INTEGER = Number.MAX_SAFE_INTEGER;
|
|
305
|
+
var MAX_OPEN_SHELLS = 32;
|
|
29
306
|
var ACTOR_SQLITE_MIGRATIONS = [
|
|
30
307
|
{
|
|
31
308
|
version: 1,
|
|
@@ -62,26 +339,80 @@ var builtInEvents = {
|
|
|
62
339
|
shellExit: event()
|
|
63
340
|
};
|
|
64
341
|
var runtimes = /* @__PURE__ */ new Map();
|
|
342
|
+
var optionResolvers = /* @__PURE__ */ new WeakMap();
|
|
343
|
+
var vmStartResolvers = /* @__PURE__ */ new WeakMap();
|
|
344
|
+
var vmStopResolvers = /* @__PURE__ */ new WeakMap();
|
|
345
|
+
var vmDisposedResolvers = /* @__PURE__ */ new WeakMap();
|
|
346
|
+
var HEALTH_WARNINGS_CAP = 50;
|
|
347
|
+
var HEALTH_AGENT_EXITS_CAP = 50;
|
|
348
|
+
var healthBuffers = /* @__PURE__ */ new Map();
|
|
349
|
+
function healthBuffersFor(actorId) {
|
|
350
|
+
let buffers = healthBuffers.get(actorId);
|
|
351
|
+
if (!buffers) {
|
|
352
|
+
buffers = { warnings: [], agentExits: [] };
|
|
353
|
+
healthBuffers.set(actorId, buffers);
|
|
354
|
+
}
|
|
355
|
+
return buffers;
|
|
356
|
+
}
|
|
357
|
+
function pushCapped(buffer, item, cap) {
|
|
358
|
+
buffer.push(item);
|
|
359
|
+
while (buffer.length > cap) buffer.shift();
|
|
360
|
+
}
|
|
65
361
|
function runtimeFor(c) {
|
|
66
362
|
let runtime = runtimes.get(c.actorId);
|
|
67
363
|
if (!runtime) {
|
|
68
|
-
runtime = {
|
|
364
|
+
runtime = {
|
|
365
|
+
vm: null,
|
|
366
|
+
bootedVm: null,
|
|
367
|
+
openShells: /* @__PURE__ */ new Map(),
|
|
368
|
+
shellReplay: new ShellReplayStore(),
|
|
369
|
+
subscribedSessions: /* @__PURE__ */ new Map(),
|
|
370
|
+
vmCleanupRan: false,
|
|
371
|
+
fetchStreamHolds: /* @__PURE__ */ new Map()
|
|
372
|
+
};
|
|
69
373
|
runtimes.set(c.actorId, runtime);
|
|
70
374
|
}
|
|
71
375
|
return runtime;
|
|
72
376
|
}
|
|
377
|
+
async function runVmDisposedHook(runtime, c, reason) {
|
|
378
|
+
if (runtime.vmCleanupRan) return;
|
|
379
|
+
runtime.vmCleanupRan = true;
|
|
380
|
+
await runtime.onVmDisposed?.(c, reason);
|
|
381
|
+
}
|
|
73
382
|
async function ensureVm(c, options) {
|
|
74
383
|
const runtime = runtimeFor(c);
|
|
75
384
|
if (runtime.vm !== null) return runtime.vm;
|
|
76
385
|
const startedAt = Date.now();
|
|
386
|
+
runtime.vmCleanupRan = false;
|
|
77
387
|
runtime.vm = (async () => {
|
|
78
|
-
|
|
79
|
-
|
|
388
|
+
runtime.onVmStop = options ? vmStopResolvers.get(options) : void 0;
|
|
389
|
+
runtime.onVmDisposed = options ? vmDisposedResolvers.get(options) : void 0;
|
|
390
|
+
const resolvedOptions = {
|
|
391
|
+
...options,
|
|
392
|
+
...options && optionResolvers.has(options) ? await optionResolvers.get(options)?.(c) : void 0
|
|
393
|
+
};
|
|
394
|
+
if (resolvedOptions.rootFilesystem) {
|
|
80
395
|
throw new Error(
|
|
81
|
-
"
|
|
396
|
+
"agentOS() owns rootFilesystem so it can persist directly through the actor SQLite UDS; resolveOptions may configure mounts but not rootFilesystem"
|
|
82
397
|
);
|
|
83
398
|
}
|
|
84
|
-
|
|
399
|
+
if (resolvedOptions.database) {
|
|
400
|
+
throw new Error(
|
|
401
|
+
"agentOS() owns database and injects the actor SQLite UDS descriptor; resolveOptions cannot replace it"
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
if (resolvedOptions.sandbox && "client" in resolvedOptions.sandbox) {
|
|
405
|
+
throw new Error(
|
|
406
|
+
"agentOS() cannot share sandbox: { client } across actor instances; resolveOptions must use sandbox: { provider }"
|
|
407
|
+
);
|
|
408
|
+
}
|
|
409
|
+
const actorRuntimeSocket = c.actorRuntimeSocket;
|
|
410
|
+
if (typeof actorRuntimeSocket !== "function") {
|
|
411
|
+
throw new Error(
|
|
412
|
+
"AgentOS actors require a RivetKit runtime with Actor Runtime Socket support"
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
const { path } = await actorRuntimeSocket.call(c);
|
|
85
416
|
const mountRows = await c.db.execute(
|
|
86
417
|
"SELECT descriptor_json FROM agentos_actor_dynamic_mounts ORDER BY path"
|
|
87
418
|
);
|
|
@@ -89,16 +420,28 @@ async function ensureVm(c, options) {
|
|
|
89
420
|
"SELECT descriptor_json FROM agentos_actor_linked_software ORDER BY path"
|
|
90
421
|
);
|
|
91
422
|
const vm = await AgentOs.create({
|
|
92
|
-
...
|
|
93
|
-
database: { type: "actor_uds", path
|
|
423
|
+
...resolvedOptions,
|
|
424
|
+
database: { type: "actor_uds", path },
|
|
94
425
|
onAgentExit: (event2) => {
|
|
95
426
|
c.log.error({
|
|
96
427
|
msg: "agent-os agent adapter exited unexpectedly",
|
|
97
428
|
...event2
|
|
98
429
|
});
|
|
430
|
+
pushCapped(
|
|
431
|
+
healthBuffersFor(c.actorId).agentExits,
|
|
432
|
+
{
|
|
433
|
+
ts: Date.now(),
|
|
434
|
+
sessionId: event2.sessionId,
|
|
435
|
+
agentType: event2.agentType,
|
|
436
|
+
exitCode: event2.exitCode,
|
|
437
|
+
restart: event2.restart,
|
|
438
|
+
restartCount: event2.restartCount
|
|
439
|
+
},
|
|
440
|
+
HEALTH_AGENT_EXITS_CAP
|
|
441
|
+
);
|
|
99
442
|
c.broadcast("agentExit", event2);
|
|
100
443
|
try {
|
|
101
|
-
|
|
444
|
+
resolvedOptions.onAgentExit?.(event2);
|
|
102
445
|
} catch (error) {
|
|
103
446
|
c.log.error({
|
|
104
447
|
msg: "agent-os onAgentExit hook failed",
|
|
@@ -107,6 +450,26 @@ async function ensureVm(c, options) {
|
|
|
107
450
|
});
|
|
108
451
|
}
|
|
109
452
|
},
|
|
453
|
+
onLimitWarning: (warning) => {
|
|
454
|
+
c.log.warn({
|
|
455
|
+
msg: "agent-os runtime limit is near capacity",
|
|
456
|
+
...warning
|
|
457
|
+
});
|
|
458
|
+
pushCapped(
|
|
459
|
+
healthBuffersFor(c.actorId).warnings,
|
|
460
|
+
{ ts: Date.now(), ...warning },
|
|
461
|
+
HEALTH_WARNINGS_CAP
|
|
462
|
+
);
|
|
463
|
+
try {
|
|
464
|
+
options?.onLimitWarning?.(warning);
|
|
465
|
+
} catch (error) {
|
|
466
|
+
c.log.error({
|
|
467
|
+
msg: "agent-os onLimitWarning hook failed",
|
|
468
|
+
limit: warning.limit,
|
|
469
|
+
error
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
},
|
|
110
473
|
rootFilesystem: {
|
|
111
474
|
type: "native",
|
|
112
475
|
plugin: {
|
|
@@ -114,19 +477,21 @@ async function ensureVm(c, options) {
|
|
|
114
477
|
config: {
|
|
115
478
|
namespace: ROOT_NAMESPACE,
|
|
116
479
|
chunkSize: ACTOR_SQLITE_CHUNK_SIZE,
|
|
117
|
-
inlineThreshold: ACTOR_SQLITE_INLINE_THRESHOLD
|
|
480
|
+
inlineThreshold: ACTOR_SQLITE_INLINE_THRESHOLD,
|
|
481
|
+
uid: resolvedOptions.user?.euid ?? resolvedOptions.user?.uid ?? 1e3,
|
|
482
|
+
gid: resolvedOptions.user?.egid ?? resolvedOptions.user?.gid ?? 1e3
|
|
118
483
|
}
|
|
119
484
|
}
|
|
120
485
|
}
|
|
121
486
|
});
|
|
122
487
|
try {
|
|
123
488
|
for (const row of mountRows) {
|
|
124
|
-
await vm.
|
|
489
|
+
await vm.filesystem.mount(
|
|
125
490
|
JSON.parse(row.descriptor_json)
|
|
126
491
|
);
|
|
127
492
|
}
|
|
128
493
|
for (const row of softwareRows) {
|
|
129
|
-
await vm.
|
|
494
|
+
await vm.software.link(
|
|
130
495
|
JSON.parse(row.descriptor_json)
|
|
131
496
|
);
|
|
132
497
|
}
|
|
@@ -134,7 +499,26 @@ async function ensureVm(c, options) {
|
|
|
134
499
|
await vm.dispose();
|
|
135
500
|
throw error;
|
|
136
501
|
}
|
|
502
|
+
const onVmStart = options ? vmStartResolvers.get(options) : void 0;
|
|
503
|
+
if (onVmStart) {
|
|
504
|
+
try {
|
|
505
|
+
await onVmStart(c, vm);
|
|
506
|
+
} catch (error) {
|
|
507
|
+
try {
|
|
508
|
+
await vm.dispose();
|
|
509
|
+
} catch (disposeError) {
|
|
510
|
+
c.log.error({
|
|
511
|
+
msg: "failed to dispose AgentOS VM after start hook failure",
|
|
512
|
+
disposeError
|
|
513
|
+
});
|
|
514
|
+
} finally {
|
|
515
|
+
await runVmDisposedHook(runtime, c, "error");
|
|
516
|
+
}
|
|
517
|
+
throw error;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
137
520
|
vm.onCronEvent((cronEvent) => c.broadcast("cronEvent", cronEvent));
|
|
521
|
+
runtime.bootedVm = vm;
|
|
138
522
|
c.broadcast("vmBooted", {});
|
|
139
523
|
c.log.info({
|
|
140
524
|
msg: "agent-os vm booted",
|
|
@@ -146,29 +530,70 @@ async function ensureVm(c, options) {
|
|
|
146
530
|
return await runtime.vm;
|
|
147
531
|
} catch (error) {
|
|
148
532
|
runtime.vm = null;
|
|
533
|
+
runtime.bootedVm = null;
|
|
534
|
+
c.log.error({
|
|
535
|
+
msg: "agent-os vm bootstrap failed",
|
|
536
|
+
actorId: c.actorId,
|
|
537
|
+
error
|
|
538
|
+
});
|
|
539
|
+
await runVmDisposedHook(runtime, c, "error");
|
|
149
540
|
throw error;
|
|
150
541
|
}
|
|
151
542
|
}
|
|
152
543
|
async function disposeVm(c, reason) {
|
|
544
|
+
if (reason === "destroy") healthBuffers.delete(c.actorId);
|
|
153
545
|
const runtime = runtimes.get(c.actorId);
|
|
154
546
|
if (!runtime) return;
|
|
155
547
|
const vm = runtime.vm;
|
|
548
|
+
runtime.bootedVm = null;
|
|
156
549
|
runtimes.delete(c.actorId);
|
|
157
550
|
for (const unsubscribers of runtime.subscribedSessions.values()) {
|
|
158
551
|
for (const unsubscribe of unsubscribers) unsubscribe();
|
|
159
552
|
}
|
|
160
553
|
runtime.subscribedSessions.clear();
|
|
161
|
-
|
|
554
|
+
for (const release of runtime.fetchStreamHolds.values()) release();
|
|
555
|
+
runtime.fetchStreamHolds.clear();
|
|
556
|
+
if (vm) {
|
|
557
|
+
const failures = [];
|
|
558
|
+
try {
|
|
559
|
+
const resolvedVm = await vm;
|
|
560
|
+
try {
|
|
561
|
+
await runtime.onVmStop?.(c, resolvedVm, reason);
|
|
562
|
+
} catch (error) {
|
|
563
|
+
failures.push(error);
|
|
564
|
+
}
|
|
565
|
+
try {
|
|
566
|
+
await resolvedVm.dispose();
|
|
567
|
+
} catch (error) {
|
|
568
|
+
failures.push(error);
|
|
569
|
+
}
|
|
570
|
+
} catch (error) {
|
|
571
|
+
failures.push(error);
|
|
572
|
+
}
|
|
573
|
+
try {
|
|
574
|
+
await runVmDisposedHook(runtime, c, reason);
|
|
575
|
+
} catch (error) {
|
|
576
|
+
failures.push(error);
|
|
577
|
+
}
|
|
578
|
+
if (failures.length === 1) throw failures[0];
|
|
579
|
+
if (failures.length > 1) {
|
|
580
|
+
const aggregate = new Error(
|
|
581
|
+
"failed to stop, dispose, or clean up AgentOS VM"
|
|
582
|
+
);
|
|
583
|
+
aggregate.errors = failures;
|
|
584
|
+
throw aggregate;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
162
587
|
c.broadcast("vmShutdown", { reason });
|
|
163
588
|
}
|
|
164
589
|
function matchPreviewPath(pathname) {
|
|
165
590
|
return pathname.match(PREVIEW_PATH_PATTERN);
|
|
166
591
|
}
|
|
167
|
-
function validateAgentOsActorMigrationLadder(
|
|
168
|
-
if (
|
|
592
|
+
function validateAgentOsActorMigrationLadder(migrations2) {
|
|
593
|
+
if (migrations2.length === 0) {
|
|
169
594
|
throw new Error("AgentOS actor SQLite migration ladder must not be empty");
|
|
170
595
|
}
|
|
171
|
-
for (const [index, migration] of
|
|
596
|
+
for (const [index, migration] of migrations2.entries()) {
|
|
172
597
|
const expectedVersion = index + 1;
|
|
173
598
|
if (migration.version !== expectedVersion) {
|
|
174
599
|
throw new Error(
|
|
@@ -211,42 +636,12 @@ function validateAgentOsActorMigrationLadder(migrations) {
|
|
|
211
636
|
}
|
|
212
637
|
async function migrateAgentOsActorTables(database) {
|
|
213
638
|
validateAgentOsActorMigrationLadder(ACTOR_SQLITE_MIGRATIONS);
|
|
214
|
-
await database
|
|
215
|
-
CREATE TABLE IF NOT EXISTS agentos_actor_schema_version (
|
|
216
|
-
singleton INTEGER PRIMARY KEY CHECK (singleton = 1),
|
|
217
|
-
schema_version INTEGER NOT NULL CHECK (schema_version BETWEEN 0 AND ${MAX_SQLITE_SAFE_INTEGER})
|
|
218
|
-
) STRICT;
|
|
219
|
-
`);
|
|
220
|
-
const rows = await database.execute(
|
|
221
|
-
"SELECT schema_version FROM agentos_actor_schema_version WHERE singleton = 1"
|
|
222
|
-
);
|
|
223
|
-
if (rows.length > 1) {
|
|
224
|
-
throw new Error(
|
|
225
|
-
`invalid AgentOS actor SQLite schema version table: expected at most one row, received ${rows.length}`
|
|
226
|
-
);
|
|
227
|
-
}
|
|
228
|
-
const rawCurrent = rows[0]?.schema_version;
|
|
229
|
-
const current = rows.length === 0 ? 0 : rawCurrent;
|
|
230
|
-
if (typeof current !== "number" || !Number.isSafeInteger(current) || current < 0) {
|
|
231
|
-
throw new Error(
|
|
232
|
-
`invalid AgentOS actor SQLite schema version ${String(rawCurrent)}`
|
|
233
|
-
);
|
|
234
|
-
}
|
|
235
|
-
if (current > ACTOR_SQLITE_MIGRATIONS.length) {
|
|
236
|
-
throw new Error(
|
|
237
|
-
`AgentOS actor SQLite schema version ${current} is newer than supported version ${ACTOR_SQLITE_MIGRATIONS.length}`
|
|
238
|
-
);
|
|
239
|
-
}
|
|
240
|
-
for (const migration of ACTOR_SQLITE_MIGRATIONS.slice(current)) {
|
|
241
|
-
await database.execute(migration.sql);
|
|
242
|
-
await database.execute(
|
|
243
|
-
`INSERT INTO agentos_actor_schema_version (singleton, schema_version)
|
|
244
|
-
VALUES (1, ?)
|
|
245
|
-
ON CONFLICT(singleton) DO UPDATE SET schema_version = excluded.schema_version`,
|
|
246
|
-
migration.version
|
|
247
|
-
);
|
|
248
|
-
}
|
|
639
|
+
await runAgentOsActorMigrations(database);
|
|
249
640
|
}
|
|
641
|
+
var runAgentOsActorMigrations = migrations({
|
|
642
|
+
tableName: "agentos_actor_schema_version",
|
|
643
|
+
migrations: ACTOR_SQLITE_MIGRATIONS
|
|
644
|
+
});
|
|
250
645
|
async function assertActorCollectionCapacity(c, table, key, limit, label, configKey) {
|
|
251
646
|
const existing = await c.db.execute(
|
|
252
647
|
`SELECT 1 AS present FROM ${table} WHERE path = ? LIMIT 1`,
|
|
@@ -302,7 +697,7 @@ function trackSessionEvents(c, vm, sessionId, hooks, maxSessionSubscriptions) {
|
|
|
302
697
|
);
|
|
303
698
|
c.broadcast("sessionEvent", serialized);
|
|
304
699
|
if (hooks.onSessionEvent) {
|
|
305
|
-
c.
|
|
700
|
+
void c.keepAwake(
|
|
306
701
|
Promise.resolve().then(() => hooks.onSessionEvent?.(c, sessionId, serialized)).catch(
|
|
307
702
|
(error) => c.log.error({
|
|
308
703
|
msg: "agent-os session event hook failed",
|
|
@@ -322,6 +717,95 @@ function untrackSessionEvents(c, sessionId) {
|
|
|
322
717
|
for (const unsubscribe of unsubscribers) unsubscribe();
|
|
323
718
|
runtimeFor(c).subscribedSessions.delete(sessionId);
|
|
324
719
|
}
|
|
720
|
+
function trackFetchStream(c, streamId) {
|
|
721
|
+
const runtime = runtimeFor(c);
|
|
722
|
+
if (runtime.fetchStreamHolds.has(streamId)) return;
|
|
723
|
+
const hold = new Promise((resolve) => {
|
|
724
|
+
runtime.fetchStreamHolds.set(streamId, resolve);
|
|
725
|
+
});
|
|
726
|
+
void c.keepAwake(hold).catch(
|
|
727
|
+
(error) => c.log.error({
|
|
728
|
+
msg: "agent-os fetch stream hold failed",
|
|
729
|
+
streamId,
|
|
730
|
+
error
|
|
731
|
+
})
|
|
732
|
+
);
|
|
733
|
+
}
|
|
734
|
+
function releaseFetchStream(c, streamId) {
|
|
735
|
+
const runtime = runtimeFor(c);
|
|
736
|
+
runtime.fetchStreamHolds.get(streamId)?.();
|
|
737
|
+
runtime.fetchStreamHolds.delete(streamId);
|
|
738
|
+
}
|
|
739
|
+
function decodeActorData(value) {
|
|
740
|
+
if (value === void 0) return void 0;
|
|
741
|
+
if (typeof value !== "object" || value === null || !("encoding" in value) || !("data" in value)) {
|
|
742
|
+
throw new UserError("stdin must be tagged UTF-8 or base64 actor data", {
|
|
743
|
+
code: "agentos_execution_invalid_actor_data"
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
const input = value;
|
|
747
|
+
if (typeof input.data !== "string") {
|
|
748
|
+
throw new UserError("actor data must contain a string", {
|
|
749
|
+
code: "agentos_execution_invalid_actor_data"
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
if (input.encoding === "utf8") return input.data;
|
|
753
|
+
if (input.encoding === "base64")
|
|
754
|
+
return new Uint8Array(Buffer.from(input.data, "base64"));
|
|
755
|
+
throw new UserError("actor data encoding must be utf8 or base64", {
|
|
756
|
+
code: "agentos_execution_invalid_actor_data"
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
function actorExecutionArgs(args) {
|
|
760
|
+
return args.map((arg) => {
|
|
761
|
+
if (typeof arg !== "object" || arg === null || Array.isArray(arg))
|
|
762
|
+
return arg;
|
|
763
|
+
const options = arg;
|
|
764
|
+
for (const field of ["signal", "onStdout", "onStderr"]) {
|
|
765
|
+
if (options[field] !== void 0) {
|
|
766
|
+
throw new UserError(`${field} is not available on actor actions`, {
|
|
767
|
+
code: "agentos_execution_non_serializable_option"
|
|
768
|
+
});
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
const normalized = { ...options };
|
|
772
|
+
if ("stdin" in normalized)
|
|
773
|
+
normalized.stdin = decodeActorData(normalized.stdin);
|
|
774
|
+
return normalized;
|
|
775
|
+
});
|
|
776
|
+
}
|
|
777
|
+
function actorSpawnArgs(options) {
|
|
778
|
+
return options === void 0 ? [] : actorExecutionArgs([options]);
|
|
779
|
+
}
|
|
780
|
+
async function runActorExecution(c, operation, options) {
|
|
781
|
+
const vm = await ensureVm(c, options);
|
|
782
|
+
return c.keepAwake(operation(vm));
|
|
783
|
+
}
|
|
784
|
+
async function runActorSpawn(c, operation, options) {
|
|
785
|
+
const vm = await ensureVm(c, options);
|
|
786
|
+
const process = await operation(vm);
|
|
787
|
+
const unsubscribeOutput = vm.onProcessOutput(
|
|
788
|
+
process.pid,
|
|
789
|
+
(event2) => c.broadcast("processOutput", event2)
|
|
790
|
+
);
|
|
791
|
+
const unsubscribeExit = vm.onProcessExit(
|
|
792
|
+
process.pid,
|
|
793
|
+
(event2) => c.broadcast("processExit", event2)
|
|
794
|
+
);
|
|
795
|
+
void c.keepAwake(
|
|
796
|
+
vm.process.wait(process.pid).finally(() => {
|
|
797
|
+
unsubscribeOutput();
|
|
798
|
+
unsubscribeExit();
|
|
799
|
+
})
|
|
800
|
+
).catch(
|
|
801
|
+
(error) => c.log.error({
|
|
802
|
+
msg: "agent-os process wait failed",
|
|
803
|
+
pid: process.pid,
|
|
804
|
+
error
|
|
805
|
+
})
|
|
806
|
+
);
|
|
807
|
+
return process;
|
|
808
|
+
}
|
|
325
809
|
function createAgentOsActions(options, hooks = {}, preview = {}, maxSessionSubscriptions = DEFAULT_MAX_SESSION_SUBSCRIPTIONS, maxDynamicMounts = DEFAULT_MAX_DYNAMIC_MOUNTS, maxLinkedSoftware = DEFAULT_MAX_LINKED_SOFTWARE) {
|
|
326
810
|
const defaultPreviewTtlSeconds = preview.defaultExpiresInSeconds ?? DEFAULT_PREVIEW_TTL_SECONDS;
|
|
327
811
|
const maxPreviewTtlSeconds = preview.maxExpiresInSeconds ?? MAX_PREVIEW_TTL_SECONDS;
|
|
@@ -352,72 +836,294 @@ function createAgentOsActions(options, hooks = {}, preview = {}, maxSessionSubsc
|
|
|
352
836
|
code: "agentos_linked_software_invalid_config"
|
|
353
837
|
});
|
|
354
838
|
}
|
|
355
|
-
|
|
356
|
-
readFile: async (c, ...args) =>
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
readdirEntries: async (c, ...args) => (await ensureVm(c, options)).readdirEntries(...args),
|
|
364
|
-
readdirRecursive: async (c, ...args) => (await ensureVm(c, options)).readdirRecursive(...args),
|
|
365
|
-
exists: async (c, ...args) => (await ensureVm(c, options)).exists(...args),
|
|
366
|
-
move: async (c, ...args) => (await ensureVm(c, options)).move(...args),
|
|
367
|
-
remove: async (c, ...args) => (await ensureVm(c, options)).remove(...args),
|
|
368
|
-
exec: async (c, ...args) => (await ensureVm(c, options)).exec(...args),
|
|
369
|
-
execArgv: async (c, ...args) => (await ensureVm(c, options)).execArgv(...args),
|
|
370
|
-
spawn: async (c, ...args) => {
|
|
371
|
-
const vm = await ensureVm(c, options);
|
|
372
|
-
const process = vm.spawn(...args);
|
|
373
|
-
const unsubscribeOutput = vm.onProcessOutput(
|
|
374
|
-
process.pid,
|
|
375
|
-
(event2) => c.broadcast("processOutput", event2)
|
|
376
|
-
);
|
|
377
|
-
const unsubscribeExit = vm.onProcessExit(
|
|
378
|
-
process.pid,
|
|
379
|
-
(event2) => c.broadcast("processExit", event2)
|
|
380
|
-
);
|
|
381
|
-
void c.keepAwake(
|
|
382
|
-
vm.waitProcess(process.pid).finally(() => {
|
|
383
|
-
unsubscribeOutput();
|
|
384
|
-
unsubscribeExit();
|
|
385
|
-
})
|
|
386
|
-
).catch(
|
|
387
|
-
(error) => c.log.error({
|
|
388
|
-
msg: "agent-os process wait failed",
|
|
389
|
-
pid: process.pid,
|
|
839
|
+
const flat = {
|
|
840
|
+
readFile: async (c, ...args) => {
|
|
841
|
+
try {
|
|
842
|
+
return await (await ensureVm(c, options)).filesystem.readFile(...args);
|
|
843
|
+
} catch (error) {
|
|
844
|
+
c.log.error({
|
|
845
|
+
msg: "agent-os readFile action failed",
|
|
846
|
+
path: args[0],
|
|
390
847
|
error
|
|
391
|
-
})
|
|
848
|
+
});
|
|
849
|
+
throw error;
|
|
850
|
+
}
|
|
851
|
+
},
|
|
852
|
+
writeFile: async (c, ...args) => (await ensureVm(c, options)).filesystem.writeFile(...args),
|
|
853
|
+
readFiles: async (c, ...args) => (await ensureVm(c, options)).filesystem.readFiles(...args),
|
|
854
|
+
writeFiles: async (c, ...args) => (await ensureVm(c, options)).filesystem.writeFiles(...args),
|
|
855
|
+
stat: async (c, ...args) => (await ensureVm(c, options)).filesystem.stat(...args),
|
|
856
|
+
mkdir: async (c, ...args) => (await ensureVm(c, options)).filesystem.mkdir(...args),
|
|
857
|
+
readdir: async (c, ...args) => (await ensureVm(c, options)).filesystem.readdir(...args),
|
|
858
|
+
readdirEntries: async (c, ...args) => (await ensureVm(c, options)).filesystem.readdirEntries(...args),
|
|
859
|
+
readdirRecursive: async (c, ...args) => (await ensureVm(c, options)).filesystem.readdirRecursive(...args),
|
|
860
|
+
exists: async (c, ...args) => (await ensureVm(c, options)).filesystem.exists(...args),
|
|
861
|
+
move: async (c, ...args) => (await ensureVm(c, options)).filesystem.move(...args),
|
|
862
|
+
remove: async (c, ...args) => (await ensureVm(c, options)).filesystem.remove(...args),
|
|
863
|
+
exec: async (c, command, actorOptions) => runActorExecution(
|
|
864
|
+
c,
|
|
865
|
+
(vm) => vm.process.exec(
|
|
866
|
+
command,
|
|
867
|
+
...actorExecutionArgs([actorOptions])
|
|
868
|
+
),
|
|
869
|
+
options
|
|
870
|
+
),
|
|
871
|
+
execArgv: async (c, command, args = [], actorOptions) => runActorExecution(
|
|
872
|
+
c,
|
|
873
|
+
(vm) => vm.process.execFile(
|
|
874
|
+
command,
|
|
875
|
+
args,
|
|
876
|
+
...actorExecutionArgs([actorOptions])
|
|
877
|
+
),
|
|
878
|
+
options
|
|
879
|
+
),
|
|
880
|
+
spawn: async (c, command, args = [], actorOptions) => runActorSpawn(
|
|
881
|
+
c,
|
|
882
|
+
(vm) => vm.process.spawn(
|
|
883
|
+
command,
|
|
884
|
+
args,
|
|
885
|
+
...actorSpawnArgs(actorOptions)
|
|
886
|
+
),
|
|
887
|
+
options
|
|
888
|
+
),
|
|
889
|
+
createContext: async (c, contextId) => (await ensureVm(c, options)).createContext(contextId),
|
|
890
|
+
executeJavaScript: async (c, source, actorOptions) => runActorExecution(
|
|
891
|
+
c,
|
|
892
|
+
(vm) => vm.javascript.execute(
|
|
893
|
+
source,
|
|
894
|
+
...actorExecutionArgs([actorOptions])
|
|
895
|
+
),
|
|
896
|
+
options
|
|
897
|
+
),
|
|
898
|
+
evaluateJavaScript: async (c, expression, actorOptions) => runActorExecution(
|
|
899
|
+
c,
|
|
900
|
+
(vm) => vm.javascript.evaluate(
|
|
901
|
+
expression,
|
|
902
|
+
...actorExecutionArgs([actorOptions])
|
|
903
|
+
),
|
|
904
|
+
options
|
|
905
|
+
),
|
|
906
|
+
executeJavaScriptFile: async (c, path, actorOptions) => runActorExecution(
|
|
907
|
+
c,
|
|
908
|
+
(vm) => vm.javascript.executeFile(
|
|
909
|
+
path,
|
|
910
|
+
...actorExecutionArgs([actorOptions])
|
|
911
|
+
),
|
|
912
|
+
options
|
|
913
|
+
),
|
|
914
|
+
spawnJavaScript: async (c, source, actorOptions) => runActorSpawn(
|
|
915
|
+
c,
|
|
916
|
+
(vm) => vm.javascript.spawn(
|
|
917
|
+
source,
|
|
918
|
+
...actorSpawnArgs(actorOptions)
|
|
919
|
+
),
|
|
920
|
+
options
|
|
921
|
+
),
|
|
922
|
+
spawnJavaScriptFile: async (c, path, actorOptions) => runActorSpawn(
|
|
923
|
+
c,
|
|
924
|
+
(vm) => vm.javascript.spawnFile(
|
|
925
|
+
path,
|
|
926
|
+
...actorSpawnArgs(actorOptions)
|
|
927
|
+
),
|
|
928
|
+
options
|
|
929
|
+
),
|
|
930
|
+
executeTypeScript: async (c, source, actorOptions) => runActorExecution(
|
|
931
|
+
c,
|
|
932
|
+
(vm) => vm.typescript.execute(
|
|
933
|
+
source,
|
|
934
|
+
...actorExecutionArgs([actorOptions])
|
|
935
|
+
),
|
|
936
|
+
options
|
|
937
|
+
),
|
|
938
|
+
evaluateTypeScript: async (c, expression, actorOptions) => runActorExecution(
|
|
939
|
+
c,
|
|
940
|
+
(vm) => vm.typescript.evaluate(
|
|
941
|
+
expression,
|
|
942
|
+
...actorExecutionArgs([actorOptions])
|
|
943
|
+
),
|
|
944
|
+
options
|
|
945
|
+
),
|
|
946
|
+
executeTypeScriptFile: async (c, path, actorOptions) => runActorExecution(
|
|
947
|
+
c,
|
|
948
|
+
(vm) => vm.typescript.executeFile(
|
|
949
|
+
path,
|
|
950
|
+
...actorExecutionArgs([actorOptions])
|
|
951
|
+
),
|
|
952
|
+
options
|
|
953
|
+
),
|
|
954
|
+
spawnTypeScript: async (c, source, actorOptions) => runActorSpawn(
|
|
955
|
+
c,
|
|
956
|
+
(vm) => vm.typescript.spawn(
|
|
957
|
+
source,
|
|
958
|
+
...actorSpawnArgs(actorOptions)
|
|
959
|
+
),
|
|
960
|
+
options
|
|
961
|
+
),
|
|
962
|
+
spawnTypeScriptFile: async (c, path, actorOptions) => runActorSpawn(
|
|
963
|
+
c,
|
|
964
|
+
(vm) => vm.typescript.spawnFile(
|
|
965
|
+
path,
|
|
966
|
+
...actorSpawnArgs(actorOptions)
|
|
967
|
+
),
|
|
968
|
+
options
|
|
969
|
+
),
|
|
970
|
+
checkTypeScript: async (c, source, actorOptions) => runActorExecution(
|
|
971
|
+
c,
|
|
972
|
+
(vm) => vm.typescript.check(
|
|
973
|
+
source,
|
|
974
|
+
...actorExecutionArgs([actorOptions])
|
|
975
|
+
),
|
|
976
|
+
options
|
|
977
|
+
),
|
|
978
|
+
checkTypeScriptProject: async (c, actorOptions) => runActorExecution(
|
|
979
|
+
c,
|
|
980
|
+
(vm) => vm.typescript.checkProject(
|
|
981
|
+
...actorExecutionArgs([actorOptions])
|
|
982
|
+
),
|
|
983
|
+
options
|
|
984
|
+
),
|
|
985
|
+
installNpmPackages: async (c, ...args) => runActorExecution(
|
|
986
|
+
c,
|
|
987
|
+
(vm) => vm.javascript.npm.install(...actorExecutionArgs(args)),
|
|
988
|
+
options
|
|
989
|
+
),
|
|
990
|
+
executeNpmScript: async (c, script, actorOptions) => runActorExecution(
|
|
991
|
+
c,
|
|
992
|
+
(vm) => vm.javascript.npm.runScript(
|
|
993
|
+
script,
|
|
994
|
+
...actorExecutionArgs([actorOptions])
|
|
995
|
+
),
|
|
996
|
+
options
|
|
997
|
+
),
|
|
998
|
+
executeNpmPackage: async (c, packageSpec, actorOptions) => runActorExecution(
|
|
999
|
+
c,
|
|
1000
|
+
(vm) => vm.javascript.npm.runPackage(
|
|
1001
|
+
packageSpec,
|
|
1002
|
+
...actorExecutionArgs([actorOptions])
|
|
1003
|
+
),
|
|
1004
|
+
options
|
|
1005
|
+
),
|
|
1006
|
+
executePython: async (c, source, actorOptions) => runActorExecution(
|
|
1007
|
+
c,
|
|
1008
|
+
(vm) => vm.python.execute(
|
|
1009
|
+
source,
|
|
1010
|
+
...actorExecutionArgs([actorOptions])
|
|
1011
|
+
),
|
|
1012
|
+
options
|
|
1013
|
+
),
|
|
1014
|
+
evaluatePython: async (c, expression, actorOptions) => runActorExecution(
|
|
1015
|
+
c,
|
|
1016
|
+
(vm) => vm.python.evaluate(
|
|
1017
|
+
expression,
|
|
1018
|
+
...actorExecutionArgs([actorOptions])
|
|
1019
|
+
),
|
|
1020
|
+
options
|
|
1021
|
+
),
|
|
1022
|
+
executePythonFile: async (c, path, actorOptions) => runActorExecution(
|
|
1023
|
+
c,
|
|
1024
|
+
(vm) => vm.python.executeFile(
|
|
1025
|
+
path,
|
|
1026
|
+
...actorExecutionArgs([actorOptions])
|
|
1027
|
+
),
|
|
1028
|
+
options
|
|
1029
|
+
),
|
|
1030
|
+
executePythonModule: async (c, module, actorOptions) => runActorExecution(
|
|
1031
|
+
c,
|
|
1032
|
+
(vm) => vm.python.executeModule(
|
|
1033
|
+
module,
|
|
1034
|
+
...actorExecutionArgs([actorOptions])
|
|
1035
|
+
),
|
|
1036
|
+
options
|
|
1037
|
+
),
|
|
1038
|
+
spawnPython: async (c, source, actorOptions) => runActorSpawn(
|
|
1039
|
+
c,
|
|
1040
|
+
(vm) => vm.python.spawn(source, ...actorSpawnArgs(actorOptions)),
|
|
1041
|
+
options
|
|
1042
|
+
),
|
|
1043
|
+
spawnPythonFile: async (c, path, actorOptions) => runActorSpawn(
|
|
1044
|
+
c,
|
|
1045
|
+
(vm) => vm.python.spawnFile(
|
|
1046
|
+
path,
|
|
1047
|
+
...actorSpawnArgs(actorOptions)
|
|
1048
|
+
),
|
|
1049
|
+
options
|
|
1050
|
+
),
|
|
1051
|
+
spawnPythonModule: async (c, module, actorOptions) => runActorSpawn(
|
|
1052
|
+
c,
|
|
1053
|
+
(vm) => vm.python.spawnModule(
|
|
1054
|
+
module,
|
|
1055
|
+
...actorSpawnArgs(actorOptions)
|
|
1056
|
+
),
|
|
1057
|
+
options
|
|
1058
|
+
),
|
|
1059
|
+
installPythonPackages: async (c, ...args) => runActorExecution(
|
|
1060
|
+
c,
|
|
1061
|
+
(vm) => vm.python.install(...actorExecutionArgs(args)),
|
|
1062
|
+
options
|
|
1063
|
+
),
|
|
1064
|
+
getContext: async (c, ...args) => (await ensureVm(c, options)).contexts.get(...args),
|
|
1065
|
+
listContexts: async (c) => (await ensureVm(c, options)).contexts.list(),
|
|
1066
|
+
resetContext: async (c, ...args) => (await ensureVm(c, options)).contexts.reset(...args),
|
|
1067
|
+
deleteContext: async (c, ...args) => (await ensureVm(c, options)).contexts.delete(...args),
|
|
1068
|
+
waitProcess: async (c, ...args) => (await ensureVm(c, options)).process.wait(...args),
|
|
1069
|
+
killProcess: async (c, ...args) => (await ensureVm(c, options)).process.kill(...args),
|
|
1070
|
+
signalProcess: async (c, ...args) => (await ensureVm(c, options)).process.signal(...args),
|
|
1071
|
+
listProcesses: async (c) => (await ensureVm(c, options)).process.list(),
|
|
1072
|
+
processTree: async (c) => (await ensureVm(c, options)).process.tree(),
|
|
1073
|
+
getProcess: async (c, ...args) => (await ensureVm(c, options)).process.get(...args),
|
|
1074
|
+
writeProcessStdin: async (c, ...args) => (await ensureVm(c, options)).process.writeStdin(...args),
|
|
1075
|
+
closeProcessStdin: async (c, ...args) => (await ensureVm(c, options)).process.closeStdin(...args),
|
|
1076
|
+
resizeProcessPty: async (c, ...args) => (await ensureVm(c, options)).process.resizePty(...args),
|
|
1077
|
+
readProcessOutput: async (c, ...args) => {
|
|
1078
|
+
const replay = await (await ensureVm(c, options)).process.readOutput(
|
|
1079
|
+
...args
|
|
392
1080
|
);
|
|
393
|
-
return
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
1081
|
+
return {
|
|
1082
|
+
...replay,
|
|
1083
|
+
events: replay.events.map((event2) => ({
|
|
1084
|
+
...event2,
|
|
1085
|
+
chunk: {
|
|
1086
|
+
encoding: "base64",
|
|
1087
|
+
data: Buffer.from(event2.chunk).toString("base64")
|
|
1088
|
+
}
|
|
1089
|
+
}))
|
|
1090
|
+
};
|
|
1091
|
+
},
|
|
404
1092
|
openShell: async (c, ...args) => {
|
|
405
1093
|
const vm = await ensureVm(c, options);
|
|
406
|
-
const
|
|
1094
|
+
const runtime = runtimeFor(c);
|
|
1095
|
+
if (runtime.openShells.size >= MAX_OPEN_SHELLS) {
|
|
1096
|
+
throw new Error(
|
|
1097
|
+
`agent-os shell limit reached (${MAX_OPEN_SHELLS} open); close a shell or raise MAX_OPEN_SHELLS`
|
|
1098
|
+
);
|
|
1099
|
+
}
|
|
1100
|
+
await runtime.shellReplay.warm();
|
|
1101
|
+
const shell = vm.terminal.open(...args);
|
|
1102
|
+
runtime.openShells.set(shell.shellId, { openedAt: Date.now() });
|
|
1103
|
+
runtime.shellReplay.open(shell.shellId, args[0]?.cols, args[0]?.rows);
|
|
407
1104
|
const unsubscribeData = vm.onShellData(
|
|
408
1105
|
shell.shellId,
|
|
409
|
-
(event2) => c.broadcast("shellData",
|
|
1106
|
+
(event2) => c.broadcast("shellData", {
|
|
1107
|
+
...event2,
|
|
1108
|
+
seq: runtime.shellReplay.feed(event2.shellId, event2.data)
|
|
1109
|
+
})
|
|
410
1110
|
);
|
|
411
1111
|
const unsubscribeStderr = vm.onShellStderr(
|
|
412
1112
|
shell.shellId,
|
|
413
|
-
(event2) =>
|
|
1113
|
+
(event2) => (
|
|
1114
|
+
// A diagnostic tap carrying bytes `shellData` already delivered, so
|
|
1115
|
+
// it is never folded into replay and carries no sequence.
|
|
1116
|
+
c.broadcast("shellStderr", { ...event2, seq: 0 })
|
|
1117
|
+
)
|
|
414
1118
|
);
|
|
415
1119
|
const unsubscribeExit = vm.onShellExit(
|
|
416
1120
|
shell.shellId,
|
|
417
1121
|
(event2) => c.broadcast("shellExit", event2)
|
|
418
1122
|
);
|
|
419
1123
|
void c.keepAwake(
|
|
420
|
-
vm.
|
|
1124
|
+
vm.terminal.wait(shell.shellId).finally(() => {
|
|
1125
|
+
runtime.openShells.delete(shell.shellId);
|
|
1126
|
+
runtime.shellReplay.close(shell.shellId);
|
|
421
1127
|
unsubscribeData();
|
|
422
1128
|
unsubscribeStderr();
|
|
423
1129
|
unsubscribeExit();
|
|
@@ -431,23 +1137,151 @@ function createAgentOsActions(options, hooks = {}, preview = {}, maxSessionSubsc
|
|
|
431
1137
|
);
|
|
432
1138
|
return shell;
|
|
433
1139
|
},
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
1140
|
+
// Observe-only: enumerates shells this actor opened without booting a
|
|
1141
|
+
// sleeping VM (a sleeping VM has none). Clients must not track shell ids
|
|
1142
|
+
// themselves — a shell outlives the page that opened it and keeps the VM
|
|
1143
|
+
// awake, so it has to stay discoverable.
|
|
1144
|
+
listShells: async (c) => {
|
|
1145
|
+
const runtime = runtimes.get(c.actorId);
|
|
1146
|
+
if (!runtime?.bootedVm) return [];
|
|
1147
|
+
return [...runtime.openShells.entries()].map(([shellId, entry]) => ({ shellId, openedAt: entry.openedAt })).sort((a, b) => a.openedAt - b.openedAt);
|
|
1148
|
+
},
|
|
1149
|
+
writeShell: async (c, ...args) => (await ensureVm(c, options)).terminal.write(...args),
|
|
1150
|
+
resizeShell: async (c, ...args) => {
|
|
1151
|
+
const result = (await ensureVm(c, options)).terminal.resize(...args);
|
|
1152
|
+
runtimeFor(c).shellReplay.resize(args[0], args[1], args[2]);
|
|
1153
|
+
return result;
|
|
1154
|
+
},
|
|
1155
|
+
// Observe-only, like `listShells`: repainting a shell must never boot a
|
|
1156
|
+
// VM, and a sleeping VM has no live shells to repaint. Returns `null`
|
|
1157
|
+
// for an unknown shell so a client falls back to no replay.
|
|
1158
|
+
shellSnapshot: async (c, shellId, mode = "screen") => {
|
|
1159
|
+
const runtime = runtimes.get(c.actorId);
|
|
1160
|
+
if (!runtime?.bootedVm) return null;
|
|
1161
|
+
return runtime.shellReplay.snapshot(shellId, mode);
|
|
1162
|
+
},
|
|
1163
|
+
closeShell: async (c, ...args) => (await ensureVm(c, options)).terminal.close(...args),
|
|
1164
|
+
waitShell: async (c, ...args) => (await ensureVm(c, options)).terminal.wait(...args),
|
|
1165
|
+
httpRequest: async (c, ...args) => (await ensureVm(c, options)).network.httpRequest(...args),
|
|
1166
|
+
vmFetch: async (c, port, url, requestOptions) => {
|
|
1167
|
+
const vm = await ensureVm(c, options);
|
|
1168
|
+
const body = requestOptions?.body instanceof Uint8Array ? Buffer.from(requestOptions.body) : requestOptions?.body;
|
|
1169
|
+
const response = await vm.fetch(
|
|
1170
|
+
port,
|
|
1171
|
+
new Request(url, {
|
|
1172
|
+
method: requestOptions?.method ?? "GET",
|
|
1173
|
+
headers: requestOptions?.headers,
|
|
1174
|
+
body
|
|
1175
|
+
})
|
|
1176
|
+
);
|
|
1177
|
+
const headers = {};
|
|
1178
|
+
const rawHeaders = [];
|
|
1179
|
+
response.headers.forEach((value, key) => {
|
|
1180
|
+
headers[key] = value;
|
|
1181
|
+
if (key !== "set-cookie") rawHeaders.push([key, value]);
|
|
1182
|
+
});
|
|
1183
|
+
for (const value of response.headers.getSetCookie?.() ?? []) {
|
|
1184
|
+
rawHeaders.push(["set-cookie", value]);
|
|
1185
|
+
}
|
|
1186
|
+
return {
|
|
1187
|
+
status: response.status,
|
|
1188
|
+
statusText: response.statusText,
|
|
1189
|
+
headers,
|
|
1190
|
+
rawHeaders,
|
|
1191
|
+
body: new Uint8Array(await response.arrayBuffer())
|
|
1192
|
+
};
|
|
1193
|
+
},
|
|
1194
|
+
vmFetchStreamStart: async (c, port, url, requestOptions) => {
|
|
1195
|
+
const vm = await ensureVm(c, options);
|
|
1196
|
+
const body = requestOptions?.body instanceof Uint8Array ? Buffer.from(requestOptions.body) : requestOptions?.body;
|
|
1197
|
+
const head = await vm.fetchStreamStart(
|
|
1198
|
+
port,
|
|
1199
|
+
new Request(url, {
|
|
1200
|
+
method: requestOptions?.method ?? "GET",
|
|
1201
|
+
headers: requestOptions?.headers,
|
|
1202
|
+
body
|
|
1203
|
+
})
|
|
1204
|
+
);
|
|
1205
|
+
trackFetchStream(c, head.streamId);
|
|
1206
|
+
const headers = {};
|
|
1207
|
+
for (const [name, value] of head.headers) headers[name] = value;
|
|
1208
|
+
return { ...head, headers, rawHeaders: head.headers };
|
|
1209
|
+
},
|
|
1210
|
+
vmFetchStreamRead: async (c, streamId, maxBytes) => {
|
|
1211
|
+
try {
|
|
1212
|
+
const chunk = await (await ensureVm(c, options)).fetchStreamRead(
|
|
1213
|
+
streamId,
|
|
1214
|
+
maxBytes
|
|
1215
|
+
);
|
|
1216
|
+
if (chunk.done) releaseFetchStream(c, streamId);
|
|
1217
|
+
return chunk;
|
|
1218
|
+
} catch (error) {
|
|
1219
|
+
releaseFetchStream(c, streamId);
|
|
1220
|
+
throw error;
|
|
1221
|
+
}
|
|
1222
|
+
},
|
|
1223
|
+
vmFetchStreamCancel: async (c, streamId) => {
|
|
1224
|
+
try {
|
|
1225
|
+
await (await ensureVm(c, options)).fetchStreamCancel(streamId);
|
|
1226
|
+
} finally {
|
|
1227
|
+
releaseFetchStream(c, streamId);
|
|
1228
|
+
}
|
|
1229
|
+
},
|
|
439
1230
|
scheduleCron: async (c, cronOptions) => {
|
|
440
|
-
const job = (await ensureVm(c, options)).
|
|
1231
|
+
const job = (await ensureVm(c, options)).cron.schedule(
|
|
441
1232
|
cronOptions
|
|
442
1233
|
);
|
|
443
1234
|
return { id: job.id };
|
|
444
1235
|
},
|
|
445
|
-
listCronJobs: async (c) => (await ensureVm(c, options)).
|
|
446
|
-
cancelCronJob: async (c, ...args) => (await ensureVm(c, options)).
|
|
447
|
-
listAgents: async (c) => (await ensureVm(c, options)).
|
|
1236
|
+
listCronJobs: async (c) => (await ensureVm(c, options)).cron.list(),
|
|
1237
|
+
cancelCronJob: async (c, ...args) => (await ensureVm(c, options)).cron.cancel(...args),
|
|
1238
|
+
listAgents: async (c) => (await ensureVm(c, options)).agents.list(),
|
|
1239
|
+
// Observe-only: reports VM liveness and the post-mortem buffers without
|
|
1240
|
+
// ever booting the VM (deliberately no ensureVm).
|
|
1241
|
+
health: async (c) => {
|
|
1242
|
+
const runtime = runtimes.get(c.actorId);
|
|
1243
|
+
const buffers = healthBuffersFor(c.actorId);
|
|
1244
|
+
let booted = false;
|
|
1245
|
+
let sessions = null;
|
|
1246
|
+
let sidecar = null;
|
|
1247
|
+
const vm = runtime?.bootedVm;
|
|
1248
|
+
if (runtime && vm) {
|
|
1249
|
+
booted = true;
|
|
1250
|
+
sessions = runtime.subscribedSessions.size;
|
|
1251
|
+
const description = vm.sidecar.describe();
|
|
1252
|
+
sidecar = {
|
|
1253
|
+
state: description.state,
|
|
1254
|
+
activeVmCount: description.activeVmCount
|
|
1255
|
+
};
|
|
1256
|
+
}
|
|
1257
|
+
return {
|
|
1258
|
+
booted,
|
|
1259
|
+
sessions,
|
|
1260
|
+
sidecar,
|
|
1261
|
+
warnings: [...buffers.warnings],
|
|
1262
|
+
agentExits: [...buffers.agentExits],
|
|
1263
|
+
stderrTail: []
|
|
1264
|
+
};
|
|
1265
|
+
},
|
|
448
1266
|
openSession: async (c, input) => {
|
|
449
1267
|
const vm = await ensureVm(c, options);
|
|
450
|
-
|
|
1268
|
+
try {
|
|
1269
|
+
await vm.sessions.open(input);
|
|
1270
|
+
} catch (error) {
|
|
1271
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1272
|
+
const causeCode = typeof error?.code === "string" ? error.code : void 0;
|
|
1273
|
+
c.log.error({
|
|
1274
|
+
msg: "agent-os openSession action failed",
|
|
1275
|
+
sessionId: input.sessionId ?? "main",
|
|
1276
|
+
agent: input.agent,
|
|
1277
|
+
causeCode,
|
|
1278
|
+
error
|
|
1279
|
+
});
|
|
1280
|
+
throw new UserError(`AgentOS openSession failed: ${message}`, {
|
|
1281
|
+
code: "agentos_session_open_failed",
|
|
1282
|
+
metadata: causeCode ? { causeCode } : void 0
|
|
1283
|
+
});
|
|
1284
|
+
}
|
|
451
1285
|
trackSessionEvents(
|
|
452
1286
|
c,
|
|
453
1287
|
vm,
|
|
@@ -456,15 +1290,19 @@ function createAgentOsActions(options, hooks = {}, preview = {}, maxSessionSubsc
|
|
|
456
1290
|
maxSessionSubscriptions
|
|
457
1291
|
);
|
|
458
1292
|
},
|
|
459
|
-
getSession: async (c, ...args) => (await ensureVm(c, options)).
|
|
460
|
-
listSessions: async (c, ...args) => (await ensureVm(c, options)).
|
|
1293
|
+
getSession: async (c, ...args) => (await ensureVm(c, options)).sessions.get(...args),
|
|
1294
|
+
listSessions: async (c, ...args) => (await ensureVm(c, options)).sessions.list(...args),
|
|
461
1295
|
deleteSession: async (c, ...args) => {
|
|
462
|
-
const result = await (await ensureVm(c, options)).
|
|
1296
|
+
const result = await (await ensureVm(c, options)).sessions.delete(
|
|
1297
|
+
...args
|
|
1298
|
+
);
|
|
463
1299
|
untrackSessionEvents(c, args[0]?.sessionId ?? "main");
|
|
464
1300
|
return result;
|
|
465
1301
|
},
|
|
466
1302
|
unloadSession: async (c, ...args) => {
|
|
467
|
-
const result = await (await ensureVm(c, options)).
|
|
1303
|
+
const result = await (await ensureVm(c, options)).sessions.unload(
|
|
1304
|
+
...args
|
|
1305
|
+
);
|
|
468
1306
|
untrackSessionEvents(c, args[0]?.sessionId ?? "main");
|
|
469
1307
|
return result;
|
|
470
1308
|
},
|
|
@@ -472,15 +1310,30 @@ function createAgentOsActions(options, hooks = {}, preview = {}, maxSessionSubsc
|
|
|
472
1310
|
const vm = await ensureVm(c, options);
|
|
473
1311
|
const sessionId = input.sessionId ?? "main";
|
|
474
1312
|
trackSessionEvents(c, vm, sessionId, hooks, maxSessionSubscriptions);
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
1313
|
+
try {
|
|
1314
|
+
return await c.keepAwake(vm.sessions.prompt(input));
|
|
1315
|
+
} catch (error) {
|
|
1316
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1317
|
+
const causeCode = typeof error?.code === "string" ? error.code : void 0;
|
|
1318
|
+
c.log.error({
|
|
1319
|
+
msg: "agent-os prompt action failed",
|
|
1320
|
+
sessionId,
|
|
1321
|
+
causeCode,
|
|
1322
|
+
error
|
|
1323
|
+
});
|
|
1324
|
+
throw new UserError(`AgentOS prompt failed: ${message}`, {
|
|
1325
|
+
code: "agentos_prompt_failed",
|
|
1326
|
+
metadata: causeCode ? { causeCode } : void 0
|
|
1327
|
+
});
|
|
1328
|
+
}
|
|
1329
|
+
},
|
|
1330
|
+
cancelPrompt: async (c, ...args) => (await ensureVm(c, options)).sessions.cancelPrompt(...args),
|
|
1331
|
+
respondPermission: async (c, ...args) => (await ensureVm(c, options)).sessions.respondPermission(...args),
|
|
1332
|
+
readHistory: async (c, ...args) => (await ensureVm(c, options)).sessions.readHistory(...args),
|
|
1333
|
+
getSessionConfig: async (c, ...args) => (await ensureVm(c, options)).sessions.getConfig(...args),
|
|
1334
|
+
setSessionConfigOption: async (c, ...args) => (await ensureVm(c, options)).sessions.setConfigOption(...args),
|
|
1335
|
+
getSessionCapabilities: async (c, ...args) => (await ensureVm(c, options)).sessions.getCapabilities(...args),
|
|
1336
|
+
getSessionAgentInfo: async (c, ...args) => (await ensureVm(c, options)).sessions.getAgentInfo(...args),
|
|
484
1337
|
createPreviewUrl: async (c, port, ttlSeconds = defaultPreviewTtlSeconds) => {
|
|
485
1338
|
if (!Number.isInteger(port) || port < 1 || port > 65535)
|
|
486
1339
|
throw new UserError(
|
|
@@ -536,7 +1389,7 @@ function createAgentOsActions(options, hooks = {}, preview = {}, maxSessionSubsc
|
|
|
536
1389
|
token
|
|
537
1390
|
);
|
|
538
1391
|
},
|
|
539
|
-
exportRootFilesystem: async (c, ...args) => (await ensureVm(c, options)).
|
|
1392
|
+
exportRootFilesystem: async (c, ...args) => (await ensureVm(c, options)).filesystem.export(...args),
|
|
540
1393
|
mountFs: async (c, descriptor) => {
|
|
541
1394
|
await assertActorCollectionCapacity(
|
|
542
1395
|
c,
|
|
@@ -547,7 +1400,7 @@ function createAgentOsActions(options, hooks = {}, preview = {}, maxSessionSubsc
|
|
|
547
1400
|
"maxDynamicMounts"
|
|
548
1401
|
);
|
|
549
1402
|
const vm = await ensureVm(c, options);
|
|
550
|
-
await vm.
|
|
1403
|
+
await vm.filesystem.mount(descriptor);
|
|
551
1404
|
try {
|
|
552
1405
|
await c.db.execute(
|
|
553
1406
|
"INSERT INTO agentos_actor_dynamic_mounts (path, descriptor_json) VALUES (?, ?) ON CONFLICT(path) DO UPDATE SET descriptor_json = excluded.descriptor_json",
|
|
@@ -556,7 +1409,7 @@ function createAgentOsActions(options, hooks = {}, preview = {}, maxSessionSubsc
|
|
|
556
1409
|
);
|
|
557
1410
|
} catch (error) {
|
|
558
1411
|
try {
|
|
559
|
-
await vm.
|
|
1412
|
+
await vm.filesystem.unmount(descriptor.path);
|
|
560
1413
|
} catch (rollbackError) {
|
|
561
1414
|
c.log.error({
|
|
562
1415
|
msg: "agent-os dynamic mount rollback failed",
|
|
@@ -573,7 +1426,7 @@ function createAgentOsActions(options, hooks = {}, preview = {}, maxSessionSubsc
|
|
|
573
1426
|
path
|
|
574
1427
|
);
|
|
575
1428
|
const vm = await ensureVm(c, options);
|
|
576
|
-
await vm.
|
|
1429
|
+
await vm.filesystem.unmount(path);
|
|
577
1430
|
try {
|
|
578
1431
|
await c.db.execute(
|
|
579
1432
|
"DELETE FROM agentos_actor_dynamic_mounts WHERE path = ?",
|
|
@@ -582,7 +1435,7 @@ function createAgentOsActions(options, hooks = {}, preview = {}, maxSessionSubsc
|
|
|
582
1435
|
} catch (error) {
|
|
583
1436
|
if (rows[0]) {
|
|
584
1437
|
try {
|
|
585
|
-
await vm.
|
|
1438
|
+
await vm.filesystem.mount(
|
|
586
1439
|
JSON.parse(rows[0].descriptor_json)
|
|
587
1440
|
);
|
|
588
1441
|
} catch (rollbackError) {
|
|
@@ -596,8 +1449,8 @@ function createAgentOsActions(options, hooks = {}, preview = {}, maxSessionSubsc
|
|
|
596
1449
|
throw error;
|
|
597
1450
|
}
|
|
598
1451
|
},
|
|
599
|
-
listMounts: async (c) => (await ensureVm(c, options)).listMounts(),
|
|
600
|
-
listSoftware: async (c) => (await ensureVm(c, options)).
|
|
1452
|
+
listMounts: async (c) => (await ensureVm(c, options)).filesystem.listMounts(),
|
|
1453
|
+
listSoftware: async (c) => (await ensureVm(c, options)).software.list(),
|
|
601
1454
|
linkSoftware: async (c, descriptor) => {
|
|
602
1455
|
await assertActorCollectionCapacity(
|
|
603
1456
|
c,
|
|
@@ -613,7 +1466,7 @@ function createAgentOsActions(options, hooks = {}, preview = {}, maxSessionSubsc
|
|
|
613
1466
|
JSON.stringify(descriptor)
|
|
614
1467
|
);
|
|
615
1468
|
try {
|
|
616
|
-
await (await ensureVm(c, options)).
|
|
1469
|
+
await (await ensureVm(c, options)).software.link(descriptor);
|
|
617
1470
|
} catch (error) {
|
|
618
1471
|
try {
|
|
619
1472
|
await c.db.execute(
|
|
@@ -631,6 +1484,185 @@ function createAgentOsActions(options, hooks = {}, preview = {}, maxSessionSubsc
|
|
|
631
1484
|
}
|
|
632
1485
|
}
|
|
633
1486
|
};
|
|
1487
|
+
const nested = {
|
|
1488
|
+
createContext: flat.createContext,
|
|
1489
|
+
process: {
|
|
1490
|
+
exec: flat.exec,
|
|
1491
|
+
execFile: flat.execArgv,
|
|
1492
|
+
spawn: flat.spawn,
|
|
1493
|
+
get: flat.getProcess,
|
|
1494
|
+
list: flat.listProcesses,
|
|
1495
|
+
tree: flat.processTree,
|
|
1496
|
+
wait: flat.waitProcess,
|
|
1497
|
+
signal: flat.signalProcess,
|
|
1498
|
+
kill: flat.killProcess,
|
|
1499
|
+
writeStdin: flat.writeProcessStdin,
|
|
1500
|
+
closeStdin: flat.closeProcessStdin,
|
|
1501
|
+
resizePty: flat.resizeProcessPty,
|
|
1502
|
+
readOutput: flat.readProcessOutput
|
|
1503
|
+
},
|
|
1504
|
+
javascript: {
|
|
1505
|
+
execute: flat.executeJavaScript,
|
|
1506
|
+
evaluate: flat.evaluateJavaScript,
|
|
1507
|
+
executeFile: flat.executeJavaScriptFile,
|
|
1508
|
+
spawn: flat.spawnJavaScript,
|
|
1509
|
+
spawnFile: flat.spawnJavaScriptFile,
|
|
1510
|
+
npm: {
|
|
1511
|
+
install: flat.installNpmPackages,
|
|
1512
|
+
runScript: flat.executeNpmScript,
|
|
1513
|
+
runPackage: flat.executeNpmPackage
|
|
1514
|
+
}
|
|
1515
|
+
},
|
|
1516
|
+
typescript: {
|
|
1517
|
+
execute: flat.executeTypeScript,
|
|
1518
|
+
evaluate: flat.evaluateTypeScript,
|
|
1519
|
+
executeFile: flat.executeTypeScriptFile,
|
|
1520
|
+
spawn: flat.spawnTypeScript,
|
|
1521
|
+
spawnFile: flat.spawnTypeScriptFile,
|
|
1522
|
+
check: flat.checkTypeScript,
|
|
1523
|
+
checkProject: flat.checkTypeScriptProject
|
|
1524
|
+
},
|
|
1525
|
+
python: {
|
|
1526
|
+
execute: flat.executePython,
|
|
1527
|
+
evaluate: flat.evaluatePython,
|
|
1528
|
+
executeFile: flat.executePythonFile,
|
|
1529
|
+
executeModule: flat.executePythonModule,
|
|
1530
|
+
spawn: flat.spawnPython,
|
|
1531
|
+
spawnFile: flat.spawnPythonFile,
|
|
1532
|
+
spawnModule: flat.spawnPythonModule,
|
|
1533
|
+
install: flat.installPythonPackages
|
|
1534
|
+
},
|
|
1535
|
+
contexts: {
|
|
1536
|
+
get: flat.getContext,
|
|
1537
|
+
list: flat.listContexts,
|
|
1538
|
+
reset: flat.resetContext,
|
|
1539
|
+
delete: flat.deleteContext
|
|
1540
|
+
},
|
|
1541
|
+
terminal: {
|
|
1542
|
+
open: flat.openShell,
|
|
1543
|
+
list: flat.listShells,
|
|
1544
|
+
snapshot: flat.shellSnapshot,
|
|
1545
|
+
write: flat.writeShell,
|
|
1546
|
+
resize: flat.resizeShell,
|
|
1547
|
+
wait: flat.waitShell,
|
|
1548
|
+
close: flat.closeShell
|
|
1549
|
+
},
|
|
1550
|
+
filesystem: {
|
|
1551
|
+
readFile: flat.readFile,
|
|
1552
|
+
writeFile: flat.writeFile,
|
|
1553
|
+
readFiles: flat.readFiles,
|
|
1554
|
+
writeFiles: flat.writeFiles,
|
|
1555
|
+
stat: flat.stat,
|
|
1556
|
+
mkdir: flat.mkdir,
|
|
1557
|
+
readdir: flat.readdir,
|
|
1558
|
+
readdirEntries: flat.readdirEntries,
|
|
1559
|
+
readdirRecursive: flat.readdirRecursive,
|
|
1560
|
+
exists: flat.exists,
|
|
1561
|
+
move: flat.move,
|
|
1562
|
+
remove: flat.remove,
|
|
1563
|
+
export: flat.exportRootFilesystem,
|
|
1564
|
+
mount: flat.mountFs,
|
|
1565
|
+
unmount: flat.unmountFs,
|
|
1566
|
+
listMounts: flat.listMounts
|
|
1567
|
+
},
|
|
1568
|
+
network: {
|
|
1569
|
+
httpRequest: flat.httpRequest
|
|
1570
|
+
},
|
|
1571
|
+
software: {
|
|
1572
|
+
list: flat.listSoftware,
|
|
1573
|
+
link: flat.linkSoftware
|
|
1574
|
+
},
|
|
1575
|
+
agents: {
|
|
1576
|
+
list: flat.listAgents
|
|
1577
|
+
},
|
|
1578
|
+
sessions: {
|
|
1579
|
+
open: flat.openSession,
|
|
1580
|
+
get: flat.getSession,
|
|
1581
|
+
list: flat.listSessions,
|
|
1582
|
+
delete: flat.deleteSession,
|
|
1583
|
+
unload: flat.unloadSession,
|
|
1584
|
+
prompt: flat.prompt,
|
|
1585
|
+
cancelPrompt: flat.cancelPrompt,
|
|
1586
|
+
respondPermission: flat.respondPermission,
|
|
1587
|
+
readHistory: flat.readHistory,
|
|
1588
|
+
getConfig: flat.getSessionConfig,
|
|
1589
|
+
setConfigOption: flat.setSessionConfigOption,
|
|
1590
|
+
getCapabilities: flat.getSessionCapabilities,
|
|
1591
|
+
getAgentInfo: flat.getSessionAgentInfo
|
|
1592
|
+
},
|
|
1593
|
+
cron: {
|
|
1594
|
+
schedule: flat.scheduleCron,
|
|
1595
|
+
list: flat.listCronJobs,
|
|
1596
|
+
cancel: flat.cancelCronJob
|
|
1597
|
+
}
|
|
1598
|
+
};
|
|
1599
|
+
return {
|
|
1600
|
+
...nested,
|
|
1601
|
+
// Legacy flat actions from the pre-language-execution API. Keep these
|
|
1602
|
+
// as aliases to the canonical nested handlers.
|
|
1603
|
+
readFile: nested.filesystem.readFile,
|
|
1604
|
+
writeFile: nested.filesystem.writeFile,
|
|
1605
|
+
readFiles: nested.filesystem.readFiles,
|
|
1606
|
+
writeFiles: nested.filesystem.writeFiles,
|
|
1607
|
+
stat: nested.filesystem.stat,
|
|
1608
|
+
mkdir: nested.filesystem.mkdir,
|
|
1609
|
+
readdir: nested.filesystem.readdir,
|
|
1610
|
+
readdirEntries: nested.filesystem.readdirEntries,
|
|
1611
|
+
readdirRecursive: nested.filesystem.readdirRecursive,
|
|
1612
|
+
exists: nested.filesystem.exists,
|
|
1613
|
+
move: nested.filesystem.move,
|
|
1614
|
+
remove: nested.filesystem.remove,
|
|
1615
|
+
exportRootFilesystem: nested.filesystem.export,
|
|
1616
|
+
mountFs: nested.filesystem.mount,
|
|
1617
|
+
unmountFs: nested.filesystem.unmount,
|
|
1618
|
+
listMounts: nested.filesystem.listMounts,
|
|
1619
|
+
exec: async (c, ...args) => (await ensureVm(c, options)).exec(...args),
|
|
1620
|
+
execArgv: async (c, ...args) => (await ensureVm(c, options)).execArgv(...args),
|
|
1621
|
+
spawn: nested.process.spawn,
|
|
1622
|
+
waitProcess: nested.process.wait,
|
|
1623
|
+
killProcess: nested.process.kill,
|
|
1624
|
+
listProcesses: nested.process.list,
|
|
1625
|
+
processTree: nested.process.tree,
|
|
1626
|
+
getProcess: nested.process.get,
|
|
1627
|
+
writeProcessStdin: nested.process.writeStdin,
|
|
1628
|
+
closeProcessStdin: nested.process.closeStdin,
|
|
1629
|
+
openShell: nested.terminal.open,
|
|
1630
|
+
listShells: nested.terminal.list,
|
|
1631
|
+
shellSnapshot: nested.terminal.snapshot,
|
|
1632
|
+
writeShell: nested.terminal.write,
|
|
1633
|
+
resizeShell: nested.terminal.resize,
|
|
1634
|
+
closeShell: nested.terminal.close,
|
|
1635
|
+
waitShell: nested.terminal.wait,
|
|
1636
|
+
httpRequest: nested.network.httpRequest,
|
|
1637
|
+
vmFetch: flat.vmFetch,
|
|
1638
|
+
vmFetchStreamStart: flat.vmFetchStreamStart,
|
|
1639
|
+
vmFetchStreamRead: flat.vmFetchStreamRead,
|
|
1640
|
+
vmFetchStreamCancel: flat.vmFetchStreamCancel,
|
|
1641
|
+
scheduleCron: nested.cron.schedule,
|
|
1642
|
+
listCronJobs: nested.cron.list,
|
|
1643
|
+
cancelCronJob: nested.cron.cancel,
|
|
1644
|
+
listAgents: nested.agents.list,
|
|
1645
|
+
openSession: nested.sessions.open,
|
|
1646
|
+
getSession: nested.sessions.get,
|
|
1647
|
+
listSessions: nested.sessions.list,
|
|
1648
|
+
deleteSession: nested.sessions.delete,
|
|
1649
|
+
unloadSession: nested.sessions.unload,
|
|
1650
|
+
prompt: nested.sessions.prompt,
|
|
1651
|
+
cancelPrompt: nested.sessions.cancelPrompt,
|
|
1652
|
+
respondPermission: nested.sessions.respondPermission,
|
|
1653
|
+
readHistory: nested.sessions.readHistory,
|
|
1654
|
+
getSessionConfig: nested.sessions.getConfig,
|
|
1655
|
+
setSessionConfigOption: nested.sessions.setConfigOption,
|
|
1656
|
+
getSessionCapabilities: nested.sessions.getCapabilities,
|
|
1657
|
+
getSessionAgentInfo: nested.sessions.getAgentInfo,
|
|
1658
|
+
listSoftware: nested.software.list,
|
|
1659
|
+
linkSoftware: nested.software.link,
|
|
1660
|
+
// Preview URLs are RivetKit-specific and intentionally stay flat.
|
|
1661
|
+
createPreviewUrl: flat.createPreviewUrl,
|
|
1662
|
+
expirePreviewUrl: flat.expirePreviewUrl,
|
|
1663
|
+
// Observe-only runtime health, also RivetKit-specific.
|
|
1664
|
+
health: flat.health
|
|
1665
|
+
};
|
|
634
1666
|
}
|
|
635
1667
|
var agentOsOptionKeys = [
|
|
636
1668
|
"software",
|
|
@@ -641,6 +1673,7 @@ var agentOsOptionKeys = [
|
|
|
641
1673
|
"database",
|
|
642
1674
|
"rootFilesystem",
|
|
643
1675
|
"mounts",
|
|
1676
|
+
"sandbox",
|
|
644
1677
|
"scheduleDriver",
|
|
645
1678
|
"bindings",
|
|
646
1679
|
"permissions",
|
|
@@ -661,11 +1694,19 @@ function splitConfig(config) {
|
|
|
661
1694
|
}
|
|
662
1695
|
const onSessionEvent = actorConfig.onSessionEvent;
|
|
663
1696
|
const preview = actorConfig.preview;
|
|
1697
|
+
const resolveOptions = actorConfig.resolveOptions;
|
|
1698
|
+
const onVmStart = actorConfig.onVmStart;
|
|
1699
|
+
const onVmStop = actorConfig.onVmStop;
|
|
1700
|
+
const onVmDisposed = actorConfig.onVmDisposed;
|
|
664
1701
|
const maxSessionSubscriptions = actorConfig.maxSessionSubscriptions;
|
|
665
1702
|
const maxDynamicMounts = actorConfig.maxDynamicMounts;
|
|
666
1703
|
const maxLinkedSoftware = actorConfig.maxLinkedSoftware;
|
|
667
1704
|
delete actorConfig.onSessionEvent;
|
|
668
1705
|
delete actorConfig.preview;
|
|
1706
|
+
delete actorConfig.resolveOptions;
|
|
1707
|
+
delete actorConfig.onVmStart;
|
|
1708
|
+
delete actorConfig.onVmStop;
|
|
1709
|
+
delete actorConfig.onVmDisposed;
|
|
669
1710
|
delete actorConfig.maxSessionSubscriptions;
|
|
670
1711
|
delete actorConfig.maxDynamicMounts;
|
|
671
1712
|
delete actorConfig.maxLinkedSoftware;
|
|
@@ -674,6 +1715,10 @@ function splitConfig(config) {
|
|
|
674
1715
|
agentOsOptions,
|
|
675
1716
|
hooks: { onSessionEvent },
|
|
676
1717
|
preview,
|
|
1718
|
+
resolveOptions,
|
|
1719
|
+
onVmStart,
|
|
1720
|
+
onVmStop,
|
|
1721
|
+
onVmDisposed,
|
|
677
1722
|
maxSessionSubscriptions,
|
|
678
1723
|
maxDynamicMounts,
|
|
679
1724
|
maxLinkedSoftware
|
|
@@ -685,6 +1730,46 @@ function assertNoReservedKeys(kind, custom, builtIns) {
|
|
|
685
1730
|
throw new Error(`agentOS() ${kind} name is reserved: ${key}`);
|
|
686
1731
|
}
|
|
687
1732
|
}
|
|
1733
|
+
var INSPECTOR_TABS_ASSET_DIR = join(
|
|
1734
|
+
dirname(fileURLToPath(import.meta.url)),
|
|
1735
|
+
"..",
|
|
1736
|
+
"assets",
|
|
1737
|
+
"inspector-tabs-app"
|
|
1738
|
+
);
|
|
1739
|
+
var AGENTOS_INSPECTOR_CONFIG = {
|
|
1740
|
+
tabs: [
|
|
1741
|
+
{
|
|
1742
|
+
id: "transcript",
|
|
1743
|
+
label: "Transcript",
|
|
1744
|
+
source: INSPECTOR_TABS_ASSET_DIR,
|
|
1745
|
+
icon: "comments"
|
|
1746
|
+
},
|
|
1747
|
+
{
|
|
1748
|
+
id: "filesystem",
|
|
1749
|
+
label: "Filesystem",
|
|
1750
|
+
source: INSPECTOR_TABS_ASSET_DIR,
|
|
1751
|
+
icon: "folder-tree"
|
|
1752
|
+
},
|
|
1753
|
+
{
|
|
1754
|
+
id: "terminal",
|
|
1755
|
+
label: "Terminal",
|
|
1756
|
+
source: INSPECTOR_TABS_ASSET_DIR,
|
|
1757
|
+
icon: "terminal"
|
|
1758
|
+
},
|
|
1759
|
+
{
|
|
1760
|
+
id: "system",
|
|
1761
|
+
label: "System",
|
|
1762
|
+
source: INSPECTOR_TABS_ASSET_DIR,
|
|
1763
|
+
icon: "layer-group"
|
|
1764
|
+
},
|
|
1765
|
+
// Processes/software/mounts live as sections inside the System tab.
|
|
1766
|
+
// `metadata` is dashboard-owned and not hideable (the schema only
|
|
1767
|
+
// accepts the six built-in ids below), so it stays.
|
|
1768
|
+
...["workflow", "database", "state", "queue", "connections", "console"].map(
|
|
1769
|
+
(id) => ({ id, hidden: true })
|
|
1770
|
+
)
|
|
1771
|
+
]
|
|
1772
|
+
};
|
|
688
1773
|
function createAgentOS(config = {}) {
|
|
689
1774
|
const split = splitConfig(config);
|
|
690
1775
|
const actorConfig = split.actorConfig;
|
|
@@ -696,6 +1781,17 @@ function createAgentOS(config = {}) {
|
|
|
696
1781
|
maxDynamicMounts,
|
|
697
1782
|
maxLinkedSoftware
|
|
698
1783
|
} = split;
|
|
1784
|
+
if (split.resolveOptions)
|
|
1785
|
+
optionResolvers.set(agentOsOptions, split.resolveOptions);
|
|
1786
|
+
if (split.onVmStart) vmStartResolvers.set(agentOsOptions, split.onVmStart);
|
|
1787
|
+
if (split.onVmStop) vmStopResolvers.set(agentOsOptions, split.onVmStop);
|
|
1788
|
+
if (split.onVmDisposed)
|
|
1789
|
+
vmDisposedResolvers.set(agentOsOptions, split.onVmDisposed);
|
|
1790
|
+
if (agentOsOptions.sandbox && "client" in agentOsOptions.sandbox) {
|
|
1791
|
+
throw new Error(
|
|
1792
|
+
"agentOS() cannot share sandbox: { client } across actor instances; use sandbox: { provider } so each actor VM starts its own client"
|
|
1793
|
+
);
|
|
1794
|
+
}
|
|
699
1795
|
if (agentOsOptions.rootFilesystem) {
|
|
700
1796
|
throw new Error(
|
|
701
1797
|
"agentOS() owns rootFilesystem so it can persist directly through the actor SQLite UDS; use mounts for additional filesystems"
|
|
@@ -726,8 +1822,14 @@ function createAgentOS(config = {}) {
|
|
|
726
1822
|
options: {
|
|
727
1823
|
actionTimeout: DEFAULT_ACTION_TIMEOUT_MS,
|
|
728
1824
|
sleepGracePeriod: DEFAULT_SLEEP_GRACE_PERIOD_MS,
|
|
729
|
-
...actorConfig.options
|
|
1825
|
+
...actorConfig.options,
|
|
1826
|
+
enableActorRuntimeSocket: true
|
|
730
1827
|
},
|
|
1828
|
+
// Register the custom agent-os inspector tabs (and hide the built-in
|
|
1829
|
+
// rivetkit tabs) so the dashboard renders the agent-os UI. Without
|
|
1830
|
+
// this the shipped tab assets are never surfaced. A caller-supplied
|
|
1831
|
+
// inspector config wins.
|
|
1832
|
+
inspector: actorConfig.inspector ?? AGENTOS_INSPECTOR_CONFIG,
|
|
731
1833
|
db: db({ onMigrate: migrateAgentOsActorTables }),
|
|
732
1834
|
events: { ...actorConfig.events ?? {}, ...builtInEvents },
|
|
733
1835
|
actions: { ...actorConfig.actions ?? {}, ...actions },
|
|
@@ -794,7 +1896,7 @@ function createAgentOS(config = {}) {
|
|
|
794
1896
|
request.headers.forEach((value, key) => {
|
|
795
1897
|
requestHeaders[key] = value;
|
|
796
1898
|
});
|
|
797
|
-
const response = await vm.httpRequest({
|
|
1899
|
+
const response = await vm.network.httpRequest({
|
|
798
1900
|
port: rows[0].port,
|
|
799
1901
|
path: `${target.pathname}${target.search}`,
|
|
800
1902
|
method: request.method,
|
|
@@ -824,8 +1926,6 @@ export {
|
|
|
824
1926
|
createAgentOS as agentOS,
|
|
825
1927
|
createAgentOS,
|
|
826
1928
|
createAgentOsActions,
|
|
827
|
-
defineSoftware,
|
|
828
|
-
nodeModulesMount,
|
|
829
1929
|
setup
|
|
830
1930
|
};
|
|
831
1931
|
//# sourceMappingURL=index.js.map
|