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.
Files changed (84) hide show
  1. package/dist/browser/client.js +2 -5
  2. package/dist/browser/client.js.map +1 -1
  3. package/dist/browser/inspector/client.js +2 -5
  4. package/dist/browser/inspector/client.js.map +1 -1
  5. package/dist/tsup/agent-os/index.cjs +3 -2652
  6. package/dist/tsup/agent-os/index.cjs.map +1 -1
  7. package/dist/tsup/agent-os/index.d.cts +1 -2717
  8. package/dist/tsup/agent-os/index.d.ts +1 -2717
  9. package/dist/tsup/agent-os/index.js +3 -2652
  10. package/dist/tsup/agent-os/index.js.map +1 -1
  11. package/dist/tsup/{chunk-LEXBAJ2Q.js → chunk-3EYXDC64.js} +3 -3
  12. package/dist/tsup/chunk-3EYXDC64.js.map +1 -0
  13. package/dist/tsup/{chunk-4SGTACEH.cjs → chunk-3X3QZVH6.cjs} +140 -140
  14. package/dist/tsup/chunk-3X3QZVH6.cjs.map +1 -0
  15. package/dist/tsup/{chunk-A27ATZJ4.cjs → chunk-4LMR7FES.cjs} +7 -7
  16. package/dist/tsup/{chunk-A27ATZJ4.cjs.map → chunk-4LMR7FES.cjs.map} +1 -1
  17. package/dist/tsup/{chunk-ZRCMI2TE.cjs → chunk-67PPGBOA.cjs} +3 -3
  18. package/dist/tsup/{chunk-ZRCMI2TE.cjs.map → chunk-67PPGBOA.cjs.map} +1 -1
  19. package/dist/tsup/{chunk-W5ADMRWL.cjs → chunk-DRG3YQ42.cjs} +3 -3
  20. package/dist/tsup/{chunk-W5ADMRWL.cjs.map → chunk-DRG3YQ42.cjs.map} +1 -1
  21. package/dist/tsup/{chunk-EQODJ4G7.cjs → chunk-FHZZ6PLK.cjs} +3 -6
  22. package/dist/tsup/chunk-FHZZ6PLK.cjs.map +1 -0
  23. package/dist/tsup/{chunk-NHXI4GVK.js → chunk-IKMLO5KS.js} +4 -4
  24. package/dist/tsup/{chunk-YXVLQDDK.js → chunk-KJBV7M2J.js} +3 -3
  25. package/dist/tsup/{chunk-7HU3OZCW.js → chunk-QLIVFNLT.js} +2 -2
  26. package/dist/tsup/{chunk-ORMO5OOW.cjs → chunk-S5EZP52Q.cjs} +3 -3
  27. package/dist/tsup/{chunk-ORMO5OOW.cjs.map → chunk-S5EZP52Q.cjs.map} +1 -1
  28. package/dist/tsup/{chunk-WI2Q7NT3.cjs → chunk-SRRUW63T.cjs} +4 -4
  29. package/dist/tsup/{chunk-WI2Q7NT3.cjs.map → chunk-SRRUW63T.cjs.map} +1 -1
  30. package/dist/tsup/{chunk-BKUZYZRZ.js → chunk-SWESH3VP.js} +2 -2
  31. package/dist/tsup/{chunk-XKVT36WN.js → chunk-UEQ5NN24.js} +2 -2
  32. package/dist/tsup/{chunk-3CZAZIO5.js → chunk-WB3BJJWJ.js} +3 -6
  33. package/dist/tsup/chunk-WB3BJJWJ.js.map +1 -0
  34. package/dist/tsup/{chunk-6AU5SM6I.cjs → chunk-XQIPFU3I.cjs} +10 -10
  35. package/dist/tsup/{chunk-6AU5SM6I.cjs.map → chunk-XQIPFU3I.cjs.map} +1 -1
  36. package/dist/tsup/{chunk-YQ7QHMPY.js → chunk-XQVCT3CM.js} +2 -2
  37. package/dist/tsup/client/mod.cjs +5 -5
  38. package/dist/tsup/client/mod.js +4 -4
  39. package/dist/tsup/common/log.cjs +2 -2
  40. package/dist/tsup/common/log.js +1 -1
  41. package/dist/tsup/common/websocket.cjs +3 -3
  42. package/dist/tsup/common/websocket.js +2 -2
  43. package/dist/tsup/db/drizzle.cjs +2 -2
  44. package/dist/tsup/db/drizzle.js +1 -1
  45. package/dist/tsup/db/mod.cjs +3 -3
  46. package/dist/tsup/db/mod.js +2 -2
  47. package/dist/tsup/inspector/mod.cjs +5 -5
  48. package/dist/tsup/inspector/mod.js +4 -4
  49. package/dist/tsup/inspector/workflow.cjs +4 -4
  50. package/dist/tsup/inspector/workflow.js +3 -3
  51. package/dist/tsup/mod.cjs +84 -84
  52. package/dist/tsup/mod.js +5 -5
  53. package/dist/tsup/test/mod.cjs +6 -6
  54. package/dist/tsup/test/mod.js +4 -4
  55. package/dist/tsup/utils.cjs +2 -2
  56. package/dist/tsup/utils.js +1 -1
  57. package/dist/tsup/workflow/mod.cjs +7 -7
  58. package/dist/tsup/workflow/mod.js +4 -4
  59. package/package.json +10 -13
  60. package/src/agent-os/index.ts +5 -65
  61. package/src/client/actor-handle.ts +3 -1
  62. package/src/client/client.ts +8 -4
  63. package/dist/tsup/chunk-3CZAZIO5.js.map +0 -1
  64. package/dist/tsup/chunk-4SGTACEH.cjs.map +0 -1
  65. package/dist/tsup/chunk-EQODJ4G7.cjs.map +0 -1
  66. package/dist/tsup/chunk-LEXBAJ2Q.js.map +0 -1
  67. package/src/agent-os/actor/cron.ts +0 -84
  68. package/src/agent-os/actor/db.ts +0 -54
  69. package/src/agent-os/actor/filesystem.ts +0 -131
  70. package/src/agent-os/actor/index.ts +0 -285
  71. package/src/agent-os/actor/network.ts +0 -58
  72. package/src/agent-os/actor/preview.ts +0 -190
  73. package/src/agent-os/actor/process.ts +0 -177
  74. package/src/agent-os/actor/session.ts +0 -518
  75. package/src/agent-os/actor/shell.ts +0 -60
  76. package/src/agent-os/config.ts +0 -79
  77. package/src/agent-os/fs/database-vfs.ts +0 -624
  78. package/src/agent-os/types.ts +0 -148
  79. /package/dist/tsup/{chunk-NHXI4GVK.js.map → chunk-IKMLO5KS.js.map} +0 -0
  80. /package/dist/tsup/{chunk-YXVLQDDK.js.map → chunk-KJBV7M2J.js.map} +0 -0
  81. /package/dist/tsup/{chunk-7HU3OZCW.js.map → chunk-QLIVFNLT.js.map} +0 -0
  82. /package/dist/tsup/{chunk-BKUZYZRZ.js.map → chunk-SWESH3VP.js.map} +0 -0
  83. /package/dist/tsup/{chunk-XKVT36WN.js.map → chunk-UEQ5NN24.js.map} +0 -0
  84. /package/dist/tsup/{chunk-YQ7QHMPY.js.map → chunk-XQVCT3CM.js.map} +0 -0
@@ -1,190 +0,0 @@
1
- import crypto from "node:crypto";
2
- import type { RequestContext } from "@/actor/config";
3
- import type { DatabaseProvider, RawAccess } from "@/common/database/config";
4
- import type { AgentOsActorConfig } from "../config";
5
- import type {
6
- AgentOsActionContext,
7
- AgentOsActorState,
8
- AgentOsActorVars,
9
- } from "../types";
10
- import { ensureVm } from "./index";
11
-
12
- // Generate a 32-character lowercase alphanumeric token (a-z0-9).
13
- // 36^32 ~= 1.6e49 possible tokens, brute-force infeasible.
14
- export function generateToken(): string {
15
- const bytes = crypto.randomBytes(32);
16
- const alphabet = "abcdefghijklmnopqrstuvwxyz0123456789";
17
- let token = "";
18
- for (let i = 0; i < 32; i++) {
19
- token += alphabet[bytes[i]! % alphabet.length];
20
- }
21
- return token;
22
- }
23
-
24
- // CORS headers added to all preview proxy responses.
25
- const CORS_HEADERS: Record<string, string> = {
26
- "Access-Control-Allow-Origin": "*",
27
- "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
28
- "Access-Control-Allow-Headers": "*",
29
- };
30
-
31
- function addCorsHeaders(response: Response): Response {
32
- const headers = new Headers(response.headers);
33
- for (const [key, value] of Object.entries(CORS_HEADERS)) {
34
- headers.set(key, value);
35
- }
36
- return new Response(response.body, {
37
- status: response.status,
38
- statusText: response.statusText,
39
- headers,
40
- });
41
- }
42
-
43
- type AgentOsRequestContext<TConnParams> = RequestContext<
44
- AgentOsActorState,
45
- TConnParams,
46
- undefined,
47
- AgentOsActorVars,
48
- undefined,
49
- DatabaseProvider<RawAccess>
50
- >;
51
-
52
- export function buildOnRequestHandler<TConnParams>(
53
- config: AgentOsActorConfig<TConnParams>,
54
- ) {
55
- return async (
56
- c: AgentOsRequestContext<TConnParams>,
57
- request: Request,
58
- ): Promise<Response> => {
59
- const url = new URL(request.url);
60
- const pathname = url.pathname;
61
-
62
- // Expect paths like /fetch/{token} or /fetch/{token}/remaining/path.
63
- const match = pathname.match(/^\/fetch\/([a-z0-9]+)(\/.*)?$/);
64
- if (!match) {
65
- return new Response("Not Found", { status: 404 });
66
- }
67
-
68
- // Handle OPTIONS preflight before token validation.
69
- if (request.method === "OPTIONS") {
70
- return new Response(null, { status: 204, headers: CORS_HEADERS });
71
- }
72
-
73
- const token = match[1]!;
74
- const remainingPath = match[2] ?? "/";
75
-
76
- // Validate token from SQLite.
77
- const now = Date.now();
78
- const rows: { port: number }[] = await c.db.execute(
79
- `SELECT port FROM agent_os_preview_tokens WHERE token = ? AND expires_at > ?`,
80
- token,
81
- now,
82
- );
83
-
84
- if (rows.length === 0) {
85
- c.log.warn({ msg: "agent-os preview auth failed", token });
86
- return addCorsHeaders(new Response("Forbidden", { status: 403 }));
87
- }
88
-
89
- const port = rows[0]?.port;
90
-
91
- // Boot the VM if needed.
92
- const agentOs = await ensureVm(
93
- c as AgentOsActionContext<TConnParams>,
94
- config,
95
- );
96
-
97
- // Build the request to proxy through the VM's virtual network.
98
- const vmUrl = `http://localhost:${port}${remainingPath}${url.search}`;
99
- const vmRequest = new Request(vmUrl, {
100
- method: request.method,
101
- headers: request.headers,
102
- body: request.body,
103
- duplex: "half",
104
- } as RequestInit);
105
-
106
- const vmResponse = await agentOs.fetch(port, vmRequest);
107
-
108
- c.log.info({
109
- msg: "agent-os preview request proxied",
110
- port,
111
- method: request.method,
112
- path: remainingPath,
113
- status: vmResponse.status,
114
- });
115
-
116
- return addCorsHeaders(vmResponse);
117
- };
118
- }
119
-
120
- export function buildPreviewActions<TConnParams>(
121
- config: AgentOsActorConfig<TConnParams>,
122
- ) {
123
- return {
124
- createSignedPreviewUrl: async (
125
- c: AgentOsActionContext<TConnParams>,
126
- port: number,
127
- expiresInSeconds?: number,
128
- ): Promise<{
129
- path: string;
130
- token: string;
131
- port: number;
132
- expiresAt: number;
133
- }> => {
134
- await ensureVm(c, config);
135
-
136
- const effectiveExpires =
137
- expiresInSeconds ?? config.preview.defaultExpiresInSeconds;
138
- const maxExpires = config.preview.maxExpiresInSeconds;
139
-
140
- if (effectiveExpires < 1 || effectiveExpires > maxExpires) {
141
- throw new Error(
142
- `expiresInSeconds must be between 1 and ${maxExpires}`,
143
- );
144
- }
145
-
146
- const token = generateToken();
147
- const now = Date.now();
148
- const expiresAt = now + effectiveExpires * 1000;
149
-
150
- // Insert token and lazy-delete expired tokens.
151
- await c.db.execute(
152
- `INSERT INTO agent_os_preview_tokens (token, port, created_at, expires_at)
153
- VALUES (?, ?, ?, ?)`,
154
- token,
155
- port,
156
- now,
157
- expiresAt,
158
- );
159
- await c.db.execute(
160
- `DELETE FROM agent_os_preview_tokens WHERE expires_at <= ?`,
161
- now,
162
- );
163
-
164
- // Path relative to the actor's gateway URL. Full URL is
165
- // `${gatewayUrl}/request/fetch/${token}` where gatewayUrl
166
- // comes from the client's getGatewayUrl().
167
- const path = `/request/fetch/${token}`;
168
-
169
- c.log.info({
170
- msg: "agent-os preview token created",
171
- port,
172
- expiresInSeconds: effectiveExpires,
173
- });
174
-
175
- return { path, token, port, expiresAt };
176
- },
177
-
178
- expireSignedPreviewUrl: async (
179
- c: AgentOsActionContext<TConnParams>,
180
- token: string,
181
- ): Promise<void> => {
182
- await c.db.execute(
183
- `DELETE FROM agent_os_preview_tokens WHERE token = ?`,
184
- token,
185
- );
186
-
187
- c.log.info({ msg: "agent-os preview token expired", token });
188
- },
189
- };
190
- }
@@ -1,177 +0,0 @@
1
- import type {
2
- ProcessInfo,
3
- ProcessTreeNode,
4
- SpawnedProcessInfo,
5
- } from "@rivet-dev/agent-os-core";
6
- import { isRivetErrorCode } from "@/actor/errors";
7
- import type { AgentOsActorConfig } from "../config";
8
- import type { AgentOsActionContext } from "../types";
9
- import { ensureVm, syncPreventSleep } from "./index";
10
-
11
- // Infer types from AgentOs methods since @secure-exec/core is not a direct dep.
12
- type ExecResult = Awaited<
13
- ReturnType<import("@rivet-dev/agent-os-core").AgentOs["exec"]>
14
- >;
15
- type ExecOptions = Parameters<
16
- import("@rivet-dev/agent-os-core").AgentOs["exec"]
17
- >[1];
18
- type SpawnOptions = Parameters<
19
- import("@rivet-dev/agent-os-core").AgentOs["spawn"]
20
- >[2];
21
-
22
- function broadcastProcessEvent<TConnParams>(
23
- c: AgentOsActionContext<TConnParams>,
24
- name: "processOutput" | "processExit",
25
- payload: unknown,
26
- ) {
27
- try {
28
- c.broadcast(name, payload);
29
- } catch (error) {
30
- if (isRivetErrorCode(error, "actor", "stopping")) {
31
- return;
32
- }
33
- throw error;
34
- }
35
- }
36
-
37
- // Build process execution actions for the actor factory.
38
- export function buildProcessActions<TConnParams>(
39
- config: AgentOsActorConfig<TConnParams>,
40
- ) {
41
- return {
42
- exec: async (
43
- c: AgentOsActionContext<TConnParams>,
44
- command: string,
45
- options?: ExecOptions,
46
- ): Promise<ExecResult> => {
47
- const agentOs = await ensureVm(c, config);
48
- return agentOs.exec(command, options);
49
- },
50
-
51
- spawn: async (
52
- c: AgentOsActionContext<TConnParams>,
53
- command: string,
54
- args: string[],
55
- options?: SpawnOptions,
56
- ): Promise<{ pid: number }> => {
57
- const agentOs = await ensureVm(c, config);
58
- const { pid } = agentOs.spawn(command, args, {
59
- ...options,
60
- onStdout: (data: Uint8Array) => {
61
- broadcastProcessEvent(c, "processOutput", {
62
- pid,
63
- stream: "stdout" as const,
64
- data,
65
- });
66
- options?.onStdout?.(data);
67
- },
68
- onStderr: (data: Uint8Array) => {
69
- broadcastProcessEvent(c, "processOutput", {
70
- pid,
71
- stream: "stderr" as const,
72
- data,
73
- });
74
- options?.onStderr?.(data);
75
- },
76
- });
77
-
78
- c.vars.activeProcesses.add(pid);
79
- syncPreventSleep(c);
80
- c.log.info({
81
- msg: "agent-os process spawned",
82
- pid,
83
- command,
84
- });
85
-
86
- agentOs
87
- .waitProcess(pid)
88
- .then((exitCode) => {
89
- broadcastProcessEvent(c, "processExit", { pid, exitCode });
90
- c.log.info({
91
- msg: "agent-os process exited",
92
- pid,
93
- exitCode,
94
- });
95
- })
96
- .catch(() => {
97
- // Process killed during dispose. Silently clean up.
98
- })
99
- .finally(() => {
100
- c.vars.activeProcesses.delete(pid);
101
- syncPreventSleep(c);
102
- });
103
-
104
- return { pid };
105
- },
106
-
107
- writeProcessStdin: async (
108
- c: AgentOsActionContext<TConnParams>,
109
- pid: number,
110
- data: string | Uint8Array,
111
- ): Promise<void> => {
112
- const agentOs = await ensureVm(c, config);
113
- agentOs.writeProcessStdin(pid, data);
114
- },
115
-
116
- closeProcessStdin: async (
117
- c: AgentOsActionContext<TConnParams>,
118
- pid: number,
119
- ): Promise<void> => {
120
- const agentOs = await ensureVm(c, config);
121
- agentOs.closeProcessStdin(pid);
122
- },
123
-
124
- waitProcess: async (
125
- c: AgentOsActionContext<TConnParams>,
126
- pid: number,
127
- ): Promise<number> => {
128
- const agentOs = await ensureVm(c, config);
129
- return agentOs.waitProcess(pid);
130
- },
131
-
132
- listProcesses: async (
133
- c: AgentOsActionContext<TConnParams>,
134
- ): Promise<SpawnedProcessInfo[]> => {
135
- const agentOs = await ensureVm(c, config);
136
- return agentOs.listProcesses();
137
- },
138
-
139
- allProcesses: async (
140
- c: AgentOsActionContext<TConnParams>,
141
- ): Promise<ProcessInfo[]> => {
142
- const agentOs = await ensureVm(c, config);
143
- return agentOs.allProcesses();
144
- },
145
-
146
- processTree: async (
147
- c: AgentOsActionContext<TConnParams>,
148
- ): Promise<ProcessTreeNode[]> => {
149
- const agentOs = await ensureVm(c, config);
150
- return agentOs.processTree();
151
- },
152
-
153
- getProcess: async (
154
- c: AgentOsActionContext<TConnParams>,
155
- pid: number,
156
- ): Promise<SpawnedProcessInfo> => {
157
- const agentOs = await ensureVm(c, config);
158
- return agentOs.getProcess(pid);
159
- },
160
-
161
- stopProcess: async (
162
- c: AgentOsActionContext<TConnParams>,
163
- pid: number,
164
- ): Promise<void> => {
165
- const agentOs = await ensureVm(c, config);
166
- agentOs.stopProcess(pid);
167
- },
168
-
169
- killProcess: async (
170
- c: AgentOsActionContext<TConnParams>,
171
- pid: number,
172
- ): Promise<void> => {
173
- const agentOs = await ensureVm(c, config);
174
- agentOs.killProcess(pid);
175
- },
176
- };
177
- }