rivetkit 2.3.26 → 2.3.28
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/browser/client.js +2 -5
- package/dist/browser/client.js.map +1 -1
- package/dist/browser/inspector/client.js +2 -5
- package/dist/browser/inspector/client.js.map +1 -1
- package/dist/tsup/agent-os/index.cjs +3 -2652
- package/dist/tsup/agent-os/index.cjs.map +1 -1
- package/dist/tsup/agent-os/index.d.cts +1 -2717
- package/dist/tsup/agent-os/index.d.ts +1 -2717
- package/dist/tsup/agent-os/index.js +3 -2652
- package/dist/tsup/agent-os/index.js.map +1 -1
- package/dist/tsup/{chunk-LEXBAJ2Q.js → chunk-3EYXDC64.js} +3 -3
- package/dist/tsup/chunk-3EYXDC64.js.map +1 -0
- package/dist/tsup/{chunk-4SGTACEH.cjs → chunk-3X3QZVH6.cjs} +140 -140
- package/dist/tsup/chunk-3X3QZVH6.cjs.map +1 -0
- package/dist/tsup/{chunk-A27ATZJ4.cjs → chunk-4LMR7FES.cjs} +7 -7
- package/dist/tsup/{chunk-A27ATZJ4.cjs.map → chunk-4LMR7FES.cjs.map} +1 -1
- package/dist/tsup/{chunk-ZRCMI2TE.cjs → chunk-67PPGBOA.cjs} +3 -3
- package/dist/tsup/{chunk-ZRCMI2TE.cjs.map → chunk-67PPGBOA.cjs.map} +1 -1
- package/dist/tsup/{chunk-W5ADMRWL.cjs → chunk-DRG3YQ42.cjs} +3 -3
- package/dist/tsup/{chunk-W5ADMRWL.cjs.map → chunk-DRG3YQ42.cjs.map} +1 -1
- package/dist/tsup/{chunk-EQODJ4G7.cjs → chunk-FHZZ6PLK.cjs} +3 -6
- package/dist/tsup/chunk-FHZZ6PLK.cjs.map +1 -0
- package/dist/tsup/{chunk-NHXI4GVK.js → chunk-IKMLO5KS.js} +4 -4
- package/dist/tsup/{chunk-YXVLQDDK.js → chunk-KJBV7M2J.js} +3 -3
- package/dist/tsup/{chunk-7HU3OZCW.js → chunk-QLIVFNLT.js} +2 -2
- package/dist/tsup/{chunk-ORMO5OOW.cjs → chunk-S5EZP52Q.cjs} +3 -3
- package/dist/tsup/{chunk-ORMO5OOW.cjs.map → chunk-S5EZP52Q.cjs.map} +1 -1
- package/dist/tsup/{chunk-WI2Q7NT3.cjs → chunk-SRRUW63T.cjs} +4 -4
- package/dist/tsup/{chunk-WI2Q7NT3.cjs.map → chunk-SRRUW63T.cjs.map} +1 -1
- package/dist/tsup/{chunk-BKUZYZRZ.js → chunk-SWESH3VP.js} +2 -2
- package/dist/tsup/{chunk-XKVT36WN.js → chunk-UEQ5NN24.js} +2 -2
- package/dist/tsup/{chunk-3CZAZIO5.js → chunk-WB3BJJWJ.js} +3 -6
- package/dist/tsup/chunk-WB3BJJWJ.js.map +1 -0
- package/dist/tsup/{chunk-6AU5SM6I.cjs → chunk-XQIPFU3I.cjs} +10 -10
- package/dist/tsup/{chunk-6AU5SM6I.cjs.map → chunk-XQIPFU3I.cjs.map} +1 -1
- package/dist/tsup/{chunk-YQ7QHMPY.js → chunk-XQVCT3CM.js} +2 -2
- package/dist/tsup/client/mod.cjs +5 -5
- package/dist/tsup/client/mod.js +4 -4
- package/dist/tsup/common/log.cjs +2 -2
- package/dist/tsup/common/log.js +1 -1
- package/dist/tsup/common/websocket.cjs +3 -3
- package/dist/tsup/common/websocket.js +2 -2
- package/dist/tsup/db/drizzle.cjs +2 -2
- package/dist/tsup/db/drizzle.js +1 -1
- package/dist/tsup/db/mod.cjs +3 -3
- package/dist/tsup/db/mod.js +2 -2
- package/dist/tsup/inspector/mod.cjs +5 -5
- package/dist/tsup/inspector/mod.js +4 -4
- package/dist/tsup/inspector/workflow.cjs +4 -4
- package/dist/tsup/inspector/workflow.js +3 -3
- package/dist/tsup/mod.cjs +84 -84
- package/dist/tsup/mod.js +5 -5
- package/dist/tsup/test/mod.cjs +6 -6
- package/dist/tsup/test/mod.js +4 -4
- package/dist/tsup/utils.cjs +2 -2
- package/dist/tsup/utils.js +1 -1
- package/dist/tsup/workflow/mod.cjs +7 -7
- package/dist/tsup/workflow/mod.js +4 -4
- package/package.json +10 -13
- package/src/agent-os/index.ts +5 -65
- package/src/client/actor-handle.ts +3 -1
- package/src/client/client.ts +8 -4
- package/dist/tsup/chunk-3CZAZIO5.js.map +0 -1
- package/dist/tsup/chunk-4SGTACEH.cjs.map +0 -1
- package/dist/tsup/chunk-EQODJ4G7.cjs.map +0 -1
- package/dist/tsup/chunk-LEXBAJ2Q.js.map +0 -1
- package/src/agent-os/actor/cron.ts +0 -84
- package/src/agent-os/actor/db.ts +0 -54
- package/src/agent-os/actor/filesystem.ts +0 -131
- package/src/agent-os/actor/index.ts +0 -285
- package/src/agent-os/actor/network.ts +0 -58
- package/src/agent-os/actor/preview.ts +0 -190
- package/src/agent-os/actor/process.ts +0 -177
- package/src/agent-os/actor/session.ts +0 -518
- package/src/agent-os/actor/shell.ts +0 -60
- package/src/agent-os/config.ts +0 -79
- package/src/agent-os/fs/database-vfs.ts +0 -624
- package/src/agent-os/types.ts +0 -148
- /package/dist/tsup/{chunk-NHXI4GVK.js.map → chunk-IKMLO5KS.js.map} +0 -0
- /package/dist/tsup/{chunk-YXVLQDDK.js.map → chunk-KJBV7M2J.js.map} +0 -0
- /package/dist/tsup/{chunk-7HU3OZCW.js.map → chunk-QLIVFNLT.js.map} +0 -0
- /package/dist/tsup/{chunk-BKUZYZRZ.js.map → chunk-SWESH3VP.js.map} +0 -0
- /package/dist/tsup/{chunk-XKVT36WN.js.map → chunk-UEQ5NN24.js.map} +0 -0
- /package/dist/tsup/{chunk-YQ7QHMPY.js.map → chunk-XQVCT3CM.js.map} +0 -0
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import type { CronAction, CronJobInfo } from "@rivet-dev/agent-os-core";
|
|
2
|
-
import type { AgentOsActorConfig } from "../config";
|
|
3
|
-
import type {
|
|
4
|
-
AgentOsActionContext,
|
|
5
|
-
SerializableCronAction,
|
|
6
|
-
SerializableCronJobInfo,
|
|
7
|
-
SerializableCronJobOptions,
|
|
8
|
-
} from "../types";
|
|
9
|
-
import { ensureVm } from "./index";
|
|
10
|
-
|
|
11
|
-
function serializeCronAction(action: CronAction): SerializableCronAction {
|
|
12
|
-
switch (action.type) {
|
|
13
|
-
case "session":
|
|
14
|
-
return {
|
|
15
|
-
type: "session",
|
|
16
|
-
agentType: action.agentType,
|
|
17
|
-
prompt: action.prompt,
|
|
18
|
-
cwd: action.options?.cwd,
|
|
19
|
-
};
|
|
20
|
-
case "exec":
|
|
21
|
-
return {
|
|
22
|
-
type: "exec",
|
|
23
|
-
command: action.command,
|
|
24
|
-
args: action.args,
|
|
25
|
-
};
|
|
26
|
-
case "callback":
|
|
27
|
-
throw new TypeError("callback cron actions are not serializable");
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function serializeCronJob(job: CronJobInfo): SerializableCronJobInfo {
|
|
32
|
-
return {
|
|
33
|
-
id: job.id,
|
|
34
|
-
schedule: job.schedule,
|
|
35
|
-
action: serializeCronAction(job.action),
|
|
36
|
-
overlap: job.overlap,
|
|
37
|
-
lastRun: job.lastRun?.toISOString(),
|
|
38
|
-
nextRun: job.nextRun?.toISOString(),
|
|
39
|
-
runCount: job.runCount,
|
|
40
|
-
running: job.running,
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Build cron scheduling actions for the actor factory.
|
|
45
|
-
export function buildCronActions<TConnParams>(
|
|
46
|
-
config: AgentOsActorConfig<TConnParams>,
|
|
47
|
-
) {
|
|
48
|
-
return {
|
|
49
|
-
scheduleCron: async (
|
|
50
|
-
c: AgentOsActionContext<TConnParams>,
|
|
51
|
-
options: SerializableCronJobOptions,
|
|
52
|
-
): Promise<{ id: string }> => {
|
|
53
|
-
const agentOs = await ensureVm(c, config);
|
|
54
|
-
const job = agentOs.scheduleCron({
|
|
55
|
-
id: options.id,
|
|
56
|
-
schedule: options.schedule,
|
|
57
|
-
action: options.action as CronAction,
|
|
58
|
-
overlap: options.overlap,
|
|
59
|
-
});
|
|
60
|
-
c.log.info({
|
|
61
|
-
msg: "agent-os cron job scheduled",
|
|
62
|
-
jobId: job.id,
|
|
63
|
-
schedule: options.schedule,
|
|
64
|
-
});
|
|
65
|
-
return { id: job.id };
|
|
66
|
-
},
|
|
67
|
-
|
|
68
|
-
listCronJobs: async (
|
|
69
|
-
c: AgentOsActionContext<TConnParams>,
|
|
70
|
-
): Promise<SerializableCronJobInfo[]> => {
|
|
71
|
-
const agentOs = await ensureVm(c, config);
|
|
72
|
-
return agentOs.listCronJobs().map(serializeCronJob);
|
|
73
|
-
},
|
|
74
|
-
|
|
75
|
-
cancelCronJob: async (
|
|
76
|
-
c: AgentOsActionContext<TConnParams>,
|
|
77
|
-
id: string,
|
|
78
|
-
): Promise<void> => {
|
|
79
|
-
const agentOs = await ensureVm(c, config);
|
|
80
|
-
agentOs.cancelCronJob(id);
|
|
81
|
-
c.log.info({ msg: "agent-os cron job cancelled", jobId: id });
|
|
82
|
-
},
|
|
83
|
-
};
|
|
84
|
-
}
|
package/src/agent-os/actor/db.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type { RawAccess } from "@/common/database/config";
|
|
2
|
-
|
|
3
|
-
export async function migrateAgentOsTables(db: RawAccess): Promise<void> {
|
|
4
|
-
await db.execute(`
|
|
5
|
-
CREATE TABLE IF NOT EXISTS agent_os_preview_tokens (
|
|
6
|
-
token TEXT PRIMARY KEY,
|
|
7
|
-
port INTEGER NOT NULL,
|
|
8
|
-
created_at INTEGER NOT NULL,
|
|
9
|
-
expires_at INTEGER NOT NULL
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
CREATE INDEX IF NOT EXISTS idx_preview_tokens_expires_at
|
|
13
|
-
ON agent_os_preview_tokens(expires_at);
|
|
14
|
-
|
|
15
|
-
CREATE TABLE IF NOT EXISTS agent_os_fs_entries (
|
|
16
|
-
path TEXT PRIMARY KEY,
|
|
17
|
-
is_directory INTEGER NOT NULL DEFAULT 0,
|
|
18
|
-
content BLOB,
|
|
19
|
-
mode INTEGER NOT NULL DEFAULT 33188,
|
|
20
|
-
uid INTEGER NOT NULL DEFAULT 0,
|
|
21
|
-
gid INTEGER NOT NULL DEFAULT 0,
|
|
22
|
-
size INTEGER NOT NULL DEFAULT 0,
|
|
23
|
-
atime_ms INTEGER NOT NULL,
|
|
24
|
-
mtime_ms INTEGER NOT NULL,
|
|
25
|
-
ctime_ms INTEGER NOT NULL,
|
|
26
|
-
birthtime_ms INTEGER NOT NULL,
|
|
27
|
-
symlink_target TEXT,
|
|
28
|
-
nlink INTEGER NOT NULL DEFAULT 1
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
CREATE INDEX IF NOT EXISTS idx_fs_entries_parent
|
|
32
|
-
ON agent_os_fs_entries(path);
|
|
33
|
-
|
|
34
|
-
CREATE TABLE IF NOT EXISTS agent_os_sessions (
|
|
35
|
-
session_id TEXT PRIMARY KEY,
|
|
36
|
-
agent_type TEXT NOT NULL,
|
|
37
|
-
capabilities TEXT NOT NULL,
|
|
38
|
-
agent_info TEXT,
|
|
39
|
-
created_at INTEGER NOT NULL
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
CREATE TABLE IF NOT EXISTS agent_os_session_events (
|
|
43
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
44
|
-
session_id TEXT NOT NULL,
|
|
45
|
-
seq INTEGER NOT NULL,
|
|
46
|
-
event TEXT NOT NULL,
|
|
47
|
-
created_at INTEGER NOT NULL,
|
|
48
|
-
FOREIGN KEY (session_id) REFERENCES agent_os_sessions(session_id) ON DELETE CASCADE
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
CREATE INDEX IF NOT EXISTS idx_session_events_session_seq
|
|
52
|
-
ON agent_os_session_events(session_id, seq);
|
|
53
|
-
`);
|
|
54
|
-
}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AgentRegistryEntry,
|
|
3
|
-
BatchReadResult,
|
|
4
|
-
BatchWriteEntry,
|
|
5
|
-
BatchWriteResult,
|
|
6
|
-
DirEntry,
|
|
7
|
-
ReaddirRecursiveOptions,
|
|
8
|
-
} from "@rivet-dev/agent-os-core";
|
|
9
|
-
import type { AgentOsActorConfig } from "../config";
|
|
10
|
-
import type { AgentOsActionContext } from "../types";
|
|
11
|
-
import { ensureVm } from "./index";
|
|
12
|
-
|
|
13
|
-
// Infer types from AgentOs methods since @secure-exec/core is not a direct dep.
|
|
14
|
-
type VirtualStat = Awaited<
|
|
15
|
-
ReturnType<import("@rivet-dev/agent-os-core").AgentOs["stat"]>
|
|
16
|
-
>;
|
|
17
|
-
type DeleteOptions = Parameters<
|
|
18
|
-
import("@rivet-dev/agent-os-core").AgentOs["delete"]
|
|
19
|
-
>[1];
|
|
20
|
-
|
|
21
|
-
// Build filesystem and agent registry actions for the actor factory.
|
|
22
|
-
export function buildFilesystemActions<TConnParams>(
|
|
23
|
-
config: AgentOsActorConfig<TConnParams>,
|
|
24
|
-
) {
|
|
25
|
-
return {
|
|
26
|
-
readFile: async (
|
|
27
|
-
c: AgentOsActionContext<TConnParams>,
|
|
28
|
-
path: string,
|
|
29
|
-
): Promise<Uint8Array> => {
|
|
30
|
-
const agentOs = await ensureVm(c, config);
|
|
31
|
-
return agentOs.readFile(path);
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
writeFile: async (
|
|
35
|
-
c: AgentOsActionContext<TConnParams>,
|
|
36
|
-
path: string,
|
|
37
|
-
content: string | Uint8Array,
|
|
38
|
-
): Promise<void> => {
|
|
39
|
-
const agentOs = await ensureVm(c, config);
|
|
40
|
-
await agentOs.writeFile(path, content);
|
|
41
|
-
},
|
|
42
|
-
|
|
43
|
-
readFiles: async (
|
|
44
|
-
c: AgentOsActionContext<TConnParams>,
|
|
45
|
-
paths: string[],
|
|
46
|
-
): Promise<BatchReadResult[]> => {
|
|
47
|
-
const agentOs = await ensureVm(c, config);
|
|
48
|
-
return agentOs.readFiles(paths);
|
|
49
|
-
},
|
|
50
|
-
|
|
51
|
-
writeFiles: async (
|
|
52
|
-
c: AgentOsActionContext<TConnParams>,
|
|
53
|
-
entries: BatchWriteEntry[],
|
|
54
|
-
): Promise<BatchWriteResult[]> => {
|
|
55
|
-
const agentOs = await ensureVm(c, config);
|
|
56
|
-
return agentOs.writeFiles(entries);
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
mkdir: async (
|
|
60
|
-
c: AgentOsActionContext<TConnParams>,
|
|
61
|
-
path: string,
|
|
62
|
-
options?: { recursive?: boolean },
|
|
63
|
-
): Promise<void> => {
|
|
64
|
-
const agentOs = await ensureVm(c, config);
|
|
65
|
-
await agentOs.mkdir(path, options);
|
|
66
|
-
},
|
|
67
|
-
|
|
68
|
-
readdir: async (
|
|
69
|
-
c: AgentOsActionContext<TConnParams>,
|
|
70
|
-
path: string,
|
|
71
|
-
): Promise<string[]> => {
|
|
72
|
-
const agentOs = await ensureVm(c, config);
|
|
73
|
-
return agentOs.readdir(path);
|
|
74
|
-
},
|
|
75
|
-
|
|
76
|
-
readdirRecursive: async (
|
|
77
|
-
c: AgentOsActionContext<TConnParams>,
|
|
78
|
-
path: string,
|
|
79
|
-
options?: ReaddirRecursiveOptions,
|
|
80
|
-
): Promise<DirEntry[]> => {
|
|
81
|
-
const agentOs = await ensureVm(c, config);
|
|
82
|
-
return agentOs.readdirRecursive(path, options);
|
|
83
|
-
},
|
|
84
|
-
|
|
85
|
-
stat: async (
|
|
86
|
-
c: AgentOsActionContext<TConnParams>,
|
|
87
|
-
path: string,
|
|
88
|
-
): Promise<VirtualStat> => {
|
|
89
|
-
const agentOs = await ensureVm(c, config);
|
|
90
|
-
return agentOs.stat(path);
|
|
91
|
-
},
|
|
92
|
-
|
|
93
|
-
exists: async (
|
|
94
|
-
c: AgentOsActionContext<TConnParams>,
|
|
95
|
-
path: string,
|
|
96
|
-
): Promise<boolean> => {
|
|
97
|
-
const agentOs = await ensureVm(c, config);
|
|
98
|
-
return agentOs.exists(path);
|
|
99
|
-
},
|
|
100
|
-
|
|
101
|
-
move: async (
|
|
102
|
-
c: AgentOsActionContext<TConnParams>,
|
|
103
|
-
from: string,
|
|
104
|
-
to: string,
|
|
105
|
-
): Promise<void> => {
|
|
106
|
-
const agentOs = await ensureVm(c, config);
|
|
107
|
-
await agentOs.move(from, to);
|
|
108
|
-
},
|
|
109
|
-
|
|
110
|
-
deleteFile: async (
|
|
111
|
-
c: AgentOsActionContext<TConnParams>,
|
|
112
|
-
path: string,
|
|
113
|
-
options?: DeleteOptions,
|
|
114
|
-
): Promise<void> => {
|
|
115
|
-
const agentOs = await ensureVm(c, config);
|
|
116
|
-
await agentOs.delete(path, options);
|
|
117
|
-
},
|
|
118
|
-
|
|
119
|
-
// TODO: mountFs and unmountFs are not exposed as actor actions because
|
|
120
|
-
// filesystem drivers (VirtualFileSystem) are not serializable over the
|
|
121
|
-
// network. Mount filesystems via the `options.mounts` config in agentOs()
|
|
122
|
-
// instead. See: https://github.com/rivet-dev/rivet/issues/XXXX
|
|
123
|
-
|
|
124
|
-
listAgents: async (
|
|
125
|
-
c: AgentOsActionContext<TConnParams>,
|
|
126
|
-
): Promise<AgentRegistryEntry[]> => {
|
|
127
|
-
const agentOs = await ensureVm(c, config);
|
|
128
|
-
return agentOs.listAgents();
|
|
129
|
-
},
|
|
130
|
-
};
|
|
131
|
-
}
|
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
import type { AgentOsOptions, MountConfig } from "@rivet-dev/agent-os-core";
|
|
2
|
-
import { AgentOs, createInMemoryFileSystem } from "@rivet-dev/agent-os-core";
|
|
3
|
-
import { type ActorDefinition, actor, event } from "@/actor/mod";
|
|
4
|
-
import type { DatabaseProvider, RawAccess } from "@/common/database/config";
|
|
5
|
-
import { db } from "@/common/database/mod";
|
|
6
|
-
import {
|
|
7
|
-
type AgentOsActorConfig,
|
|
8
|
-
type AgentOsActorConfigInput,
|
|
9
|
-
agentOsActorConfigSchema,
|
|
10
|
-
} from "../config";
|
|
11
|
-
import type {
|
|
12
|
-
AgentOsActionContext,
|
|
13
|
-
AgentOsActorState,
|
|
14
|
-
AgentOsActorVars,
|
|
15
|
-
CronEventPayload,
|
|
16
|
-
PermissionRequestPayload,
|
|
17
|
-
ProcessExitPayload,
|
|
18
|
-
ProcessOutputPayload,
|
|
19
|
-
SessionEventPayload,
|
|
20
|
-
ShellDataPayload,
|
|
21
|
-
VmBootedPayload,
|
|
22
|
-
VmShutdownPayload,
|
|
23
|
-
} from "../types";
|
|
24
|
-
import { buildCronActions } from "./cron";
|
|
25
|
-
import { migrateAgentOsTables } from "./db";
|
|
26
|
-
import { buildFilesystemActions } from "./filesystem";
|
|
27
|
-
import { buildNetworkActions } from "./network";
|
|
28
|
-
import { buildOnRequestHandler, buildPreviewActions } from "./preview";
|
|
29
|
-
import { buildProcessActions } from "./process";
|
|
30
|
-
import {
|
|
31
|
-
buildConfigActions,
|
|
32
|
-
buildPromptActions,
|
|
33
|
-
buildSessionActions,
|
|
34
|
-
buildSessionPersistenceActions,
|
|
35
|
-
} from "./session";
|
|
36
|
-
import { buildShellActions } from "./shell";
|
|
37
|
-
|
|
38
|
-
// --- VM lifecycle helpers ---
|
|
39
|
-
|
|
40
|
-
async function ensureVm<TConnParams>(
|
|
41
|
-
c: AgentOsActionContext<TConnParams>,
|
|
42
|
-
config: AgentOsActorConfig<TConnParams>,
|
|
43
|
-
): Promise<AgentOs> {
|
|
44
|
-
if (c.vars.agentOs) {
|
|
45
|
-
return c.vars.agentOs;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const start = Date.now();
|
|
49
|
-
|
|
50
|
-
// Build options with in-memory VFS as default working directory mount.
|
|
51
|
-
const options = buildVmOptions(config.options);
|
|
52
|
-
|
|
53
|
-
const agentOs = await AgentOs.create(options);
|
|
54
|
-
c.vars.agentOs = agentOs;
|
|
55
|
-
|
|
56
|
-
// Wire cron events to actor events.
|
|
57
|
-
agentOs.onCronEvent((cronEvent) => {
|
|
58
|
-
c.broadcast("cronEvent", { event: cronEvent });
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
c.broadcast("vmBooted", {});
|
|
62
|
-
c.log.info({
|
|
63
|
-
msg: "agent-os vm booted",
|
|
64
|
-
bootDurationMs: Date.now() - start,
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
return agentOs;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function buildVmOptions(userOptions?: AgentOsOptions): AgentOsOptions {
|
|
71
|
-
const userMounts = userOptions?.mounts ?? [];
|
|
72
|
-
|
|
73
|
-
// Check if the user already provided a mount at /home/user. If so, respect
|
|
74
|
-
// their override and skip the default in-memory VFS mount.
|
|
75
|
-
const hasWorkdirMount = userMounts.some(
|
|
76
|
-
(m: MountConfig) => m.path === "/home/user",
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
if (hasWorkdirMount) {
|
|
80
|
-
return userOptions ?? {};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// TODO: Reimplement with persistent backend (SQLite-backed metadata and
|
|
84
|
-
// actor storage-backed blocks) so VM filesystem state survives sleep/wake.
|
|
85
|
-
const memMount: MountConfig = {
|
|
86
|
-
path: "/home/user",
|
|
87
|
-
driver: createInMemoryFileSystem(),
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
return {
|
|
91
|
-
...userOptions,
|
|
92
|
-
mounts: [memMount, ...userMounts],
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// --- Prevent-sleep coordination ---
|
|
97
|
-
|
|
98
|
-
function syncPreventSleep<TConnParams>(
|
|
99
|
-
c: AgentOsActionContext<TConnParams>,
|
|
100
|
-
): void {
|
|
101
|
-
const shouldPrevent =
|
|
102
|
-
c.vars.activeSessionIds.size > 0 ||
|
|
103
|
-
c.vars.activeProcesses.size > 0 ||
|
|
104
|
-
c.vars.activeHooks.size > 0 ||
|
|
105
|
-
c.vars.activeShells.size > 0;
|
|
106
|
-
|
|
107
|
-
c.setPreventSleep(shouldPrevent);
|
|
108
|
-
|
|
109
|
-
c.log.info({
|
|
110
|
-
msg: "agent-os prevent sleep sync",
|
|
111
|
-
preventSleep: shouldPrevent,
|
|
112
|
-
activeSessions: c.vars.activeSessionIds.size,
|
|
113
|
-
activeProcesses: c.vars.activeProcesses.size,
|
|
114
|
-
activeHooks: c.vars.activeHooks.size,
|
|
115
|
-
activeShells: c.vars.activeShells.size,
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// --- Hook tracking ---
|
|
120
|
-
|
|
121
|
-
function runHook<TConnParams>(
|
|
122
|
-
c: AgentOsActionContext<TConnParams>,
|
|
123
|
-
name: string,
|
|
124
|
-
callback: () => void | Promise<void>,
|
|
125
|
-
): void {
|
|
126
|
-
const promise = Promise.resolve(callback())
|
|
127
|
-
.catch((error) =>
|
|
128
|
-
c.log.error({ msg: "agent-os hook failed", hookName: name, error }),
|
|
129
|
-
)
|
|
130
|
-
.finally(() => {
|
|
131
|
-
c.vars.activeHooks.delete(promise);
|
|
132
|
-
syncPreventSleep(c);
|
|
133
|
-
});
|
|
134
|
-
c.vars.activeHooks.add(promise);
|
|
135
|
-
syncPreventSleep(c);
|
|
136
|
-
c.waitUntil(promise);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// --- Public API ---
|
|
140
|
-
|
|
141
|
-
export function agentOs<TConnParams = undefined>(
|
|
142
|
-
config: AgentOsActorConfigInput<TConnParams>,
|
|
143
|
-
): ActorDefinition<
|
|
144
|
-
AgentOsActorState,
|
|
145
|
-
TConnParams,
|
|
146
|
-
undefined,
|
|
147
|
-
AgentOsActorVars,
|
|
148
|
-
undefined,
|
|
149
|
-
DatabaseProvider<RawAccess>,
|
|
150
|
-
{
|
|
151
|
-
sessionEvent: typeof sessionEventToken;
|
|
152
|
-
permissionRequest: typeof permissionRequestToken;
|
|
153
|
-
vmBooted: typeof vmBootedToken;
|
|
154
|
-
vmShutdown: typeof vmShutdownToken;
|
|
155
|
-
processOutput: typeof processOutputToken;
|
|
156
|
-
processExit: typeof processExitToken;
|
|
157
|
-
shellData: typeof shellDataToken;
|
|
158
|
-
cronEvent: typeof cronEventToken;
|
|
159
|
-
},
|
|
160
|
-
Record<never, never>,
|
|
161
|
-
any
|
|
162
|
-
> {
|
|
163
|
-
const parsedConfig = agentOsActorConfigSchema.parse(
|
|
164
|
-
config,
|
|
165
|
-
) as AgentOsActorConfig<TConnParams>;
|
|
166
|
-
const actions = {
|
|
167
|
-
...buildSessionActions(parsedConfig),
|
|
168
|
-
...buildPromptActions(parsedConfig),
|
|
169
|
-
...buildConfigActions(parsedConfig),
|
|
170
|
-
...buildSessionPersistenceActions(parsedConfig),
|
|
171
|
-
...buildProcessActions(parsedConfig),
|
|
172
|
-
...buildFilesystemActions(parsedConfig),
|
|
173
|
-
...buildPreviewActions(parsedConfig),
|
|
174
|
-
...buildShellActions(parsedConfig),
|
|
175
|
-
...buildCronActions(parsedConfig),
|
|
176
|
-
...buildNetworkActions(parsedConfig),
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
return actor<
|
|
180
|
-
AgentOsActorState,
|
|
181
|
-
TConnParams,
|
|
182
|
-
undefined,
|
|
183
|
-
AgentOsActorVars,
|
|
184
|
-
undefined,
|
|
185
|
-
DatabaseProvider<RawAccess>,
|
|
186
|
-
{
|
|
187
|
-
sessionEvent: typeof sessionEventToken;
|
|
188
|
-
permissionRequest: typeof permissionRequestToken;
|
|
189
|
-
vmBooted: typeof vmBootedToken;
|
|
190
|
-
vmShutdown: typeof vmShutdownToken;
|
|
191
|
-
processOutput: typeof processOutputToken;
|
|
192
|
-
processExit: typeof processExitToken;
|
|
193
|
-
shellData: typeof shellDataToken;
|
|
194
|
-
cronEvent: typeof cronEventToken;
|
|
195
|
-
},
|
|
196
|
-
Record<never, never>,
|
|
197
|
-
typeof actions
|
|
198
|
-
>({
|
|
199
|
-
options: {
|
|
200
|
-
sleepGracePeriod: 900_000,
|
|
201
|
-
actionTimeout: 900_000,
|
|
202
|
-
},
|
|
203
|
-
createState: async () => ({}),
|
|
204
|
-
createVars: () => ({
|
|
205
|
-
agentOs: null,
|
|
206
|
-
activeSessionIds: new Set<string>(),
|
|
207
|
-
activeProcesses: new Set<number>(),
|
|
208
|
-
activeHooks: new Set<Promise<void>>(),
|
|
209
|
-
activeShells: new Set<string>(),
|
|
210
|
-
sessions: new Set(),
|
|
211
|
-
}),
|
|
212
|
-
db: db({
|
|
213
|
-
onMigrate: migrateAgentOsTables,
|
|
214
|
-
}),
|
|
215
|
-
events: {
|
|
216
|
-
sessionEvent: sessionEventToken,
|
|
217
|
-
permissionRequest: permissionRequestToken,
|
|
218
|
-
vmBooted: vmBootedToken,
|
|
219
|
-
vmShutdown: vmShutdownToken,
|
|
220
|
-
processOutput: processOutputToken,
|
|
221
|
-
processExit: processExitToken,
|
|
222
|
-
shellData: shellDataToken,
|
|
223
|
-
cronEvent: cronEventToken,
|
|
224
|
-
},
|
|
225
|
-
onBeforeConnect: parsedConfig.onBeforeConnect
|
|
226
|
-
? async (ctx, params) => {
|
|
227
|
-
// Skip user auth for preview URL requests. The signed token
|
|
228
|
-
// in onRequest is the credential; browsers navigating preview
|
|
229
|
-
// URLs cannot supply actor connection params.
|
|
230
|
-
if (ctx.request) {
|
|
231
|
-
const url = new URL(ctx.request.url);
|
|
232
|
-
if (url.pathname.startsWith("/fetch/")) {
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
await parsedConfig.onBeforeConnect?.(ctx, params);
|
|
237
|
-
}
|
|
238
|
-
: undefined,
|
|
239
|
-
onRequest: buildOnRequestHandler(parsedConfig),
|
|
240
|
-
onSleep: async (c) => {
|
|
241
|
-
c.log.info({
|
|
242
|
-
msg: "agent-os vm shutdown for sleep",
|
|
243
|
-
activeSessions: c.vars.sessions.size,
|
|
244
|
-
activeProcesses: c.vars.activeProcesses.size,
|
|
245
|
-
activeShells: c.vars.activeShells.size,
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
if (c.vars.agentOs) {
|
|
249
|
-
await c.vars.agentOs.dispose();
|
|
250
|
-
c.vars.agentOs = null;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
c.broadcast("vmShutdown", { reason: "sleep" as const });
|
|
254
|
-
},
|
|
255
|
-
onDestroy: async (c) => {
|
|
256
|
-
c.log.info({
|
|
257
|
-
msg: "agent-os vm shutdown for destroy",
|
|
258
|
-
activeSessions: c.vars.sessions.size,
|
|
259
|
-
activeProcesses: c.vars.activeProcesses.size,
|
|
260
|
-
activeShells: c.vars.activeShells.size,
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
if (c.vars.agentOs) {
|
|
264
|
-
await c.vars.agentOs.dispose();
|
|
265
|
-
c.vars.agentOs = null;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
c.broadcast("vmShutdown", { reason: "destroy" as const });
|
|
269
|
-
},
|
|
270
|
-
actions,
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
// Event type tokens. Declared at module level so they can be referenced in
|
|
275
|
-
// the actor generic type parameters.
|
|
276
|
-
const sessionEventToken = event<SessionEventPayload>();
|
|
277
|
-
const permissionRequestToken = event<PermissionRequestPayload>();
|
|
278
|
-
const vmBootedToken = event<VmBootedPayload>();
|
|
279
|
-
const vmShutdownToken = event<VmShutdownPayload>();
|
|
280
|
-
const processOutputToken = event<ProcessOutputPayload>();
|
|
281
|
-
const processExitToken = event<ProcessExitPayload>();
|
|
282
|
-
const shellDataToken = event<ShellDataPayload>();
|
|
283
|
-
const cronEventToken = event<CronEventPayload>();
|
|
284
|
-
|
|
285
|
-
export { ensureVm, syncPreventSleep, runHook };
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import type { AgentOsActorConfig } from "../config";
|
|
2
|
-
import type { AgentOsActionContext } from "../types";
|
|
3
|
-
import { ensureVm } from "./index";
|
|
4
|
-
|
|
5
|
-
// Serializable fetch options for the actor action boundary.
|
|
6
|
-
export interface VmFetchOptions {
|
|
7
|
-
method?: string;
|
|
8
|
-
headers?: Record<string, string>;
|
|
9
|
-
body?: string | Uint8Array;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// Serializable fetch result returned by the actor action.
|
|
13
|
-
export interface VmFetchResult {
|
|
14
|
-
status: number;
|
|
15
|
-
statusText: string;
|
|
16
|
-
headers: Record<string, string>;
|
|
17
|
-
body: Uint8Array;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Build network actions for the actor factory.
|
|
21
|
-
export function buildNetworkActions<TConnParams>(
|
|
22
|
-
config: AgentOsActorConfig<TConnParams>,
|
|
23
|
-
) {
|
|
24
|
-
return {
|
|
25
|
-
vmFetch: async (
|
|
26
|
-
c: AgentOsActionContext<TConnParams>,
|
|
27
|
-
port: number,
|
|
28
|
-
url: string,
|
|
29
|
-
options?: VmFetchOptions,
|
|
30
|
-
): Promise<VmFetchResult> => {
|
|
31
|
-
const agentOs = await ensureVm(c, config);
|
|
32
|
-
|
|
33
|
-
const headers = new Headers(options?.headers);
|
|
34
|
-
const request = new Request(url, {
|
|
35
|
-
method: options?.method ?? "GET",
|
|
36
|
-
headers,
|
|
37
|
-
body: options?.body ?? null,
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
const response = await agentOs.fetch(port, request);
|
|
41
|
-
|
|
42
|
-
// Serialize response headers to a plain object.
|
|
43
|
-
const responseHeaders: Record<string, string> = {};
|
|
44
|
-
response.headers.forEach((value, key) => {
|
|
45
|
-
responseHeaders[key] = value;
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
const body = new Uint8Array(await response.arrayBuffer());
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
status: response.status,
|
|
52
|
-
statusText: response.statusText,
|
|
53
|
-
headers: responseHeaders,
|
|
54
|
-
body,
|
|
55
|
-
};
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
}
|