@rivet-dev/agentos 0.0.0-integrate-dylib-into-main.815fcda → 0.0.0-main.29b0797
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/badge-NKTqivIc.js +1 -0
- package/assets/inspector-tabs-app/assets/filesystem-CyIvO-1j.js +1 -0
- package/assets/inspector-tabs-app/assets/index-DcBRn-yP.js +125 -0
- package/assets/inspector-tabs-app/assets/index-Dt5XhJ9h.css +1 -0
- package/assets/inspector-tabs-app/assets/mounts-DWpTN-N6.js +1 -0
- package/assets/inspector-tabs-app/assets/processes-CUocx7Ya.js +1 -0
- package/assets/inspector-tabs-app/assets/scroll-area-C07uoUZ4.js +1 -0
- package/assets/inspector-tabs-app/assets/software-ftDfKuwh.js +1 -0
- package/assets/inspector-tabs-app/assets/transcript-7Ao7EjSb.js +1 -0
- package/assets/inspector-tabs-app/assets/useSuspenseQuery-DBzwnHO3.js +1 -0
- package/assets/inspector-tabs-app/index.html +13 -0
- package/dist/client.d.ts +2 -0
- package/dist/client.js +3 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +159 -4
- package/dist/index.js +831 -10
- package/dist/index.js.map +1 -0
- package/dist/react.d.ts +1 -0
- package/dist/react.js +3 -0
- package/dist/react.js.map +1 -0
- package/package.json +79 -26
- package/dist/actor.d.ts +0 -52
- package/dist/actor.js +0 -252
- package/dist/config.d.ts +0 -23
- package/dist/config.js +0 -18
- package/dist/plugin-binary.d.ts +0 -5
- package/dist/plugin-binary.js +0 -84
- package/dist/types.d.ts +0 -102
- package/dist/types.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/actor.ts"],"sourcesContent":["import { setup as rivetkitSetup } from \"rivetkit\";\n\nconst AGENTOS_REGISTRY_MESSAGE_SIZE_DEFAULT = 512 * 1024 * 1024;\n\n/**\n * RivetKit setup with the direct actor SQLite UDS enabled. The UDS is consumed\n * by the AgentOS sidecar; filesystem SQL never crosses the JavaScript layer.\n */\nexport const setup: typeof rivetkitSetup = ((\n\tinput: Parameters<typeof rivetkitSetup>[0],\n) =>\n\trivetkitSetup({\n\t\t...input,\n\t\tmaxIncomingMessageSize: AGENTOS_REGISTRY_MESSAGE_SIZE_DEFAULT,\n\t\tmaxOutgoingMessageSize: AGENTOS_REGISTRY_MESSAGE_SIZE_DEFAULT,\n\t\texperimentalActorUds: true,\n\t} as Parameters<typeof rivetkitSetup>[0])) as typeof rivetkitSetup;\n\nexport type {\n\tAgentOsOptions,\n\tDirEntry,\n\tDynamicMountDescriptor,\n\tExportRootFilesystemOptions,\n\tHttpRequest,\n\tHttpResponse,\n\tMountInfo,\n\tNodeModulesMountConfig,\n\tPackageDescriptor,\n\tProcessExit,\n\tProcessOutput,\n\tPromptResult,\n\tReaddirEntry,\n\tRootSnapshotExport,\n\tSessionInfo,\n\tShellData,\n\tShellExit,\n} from \"@rivet-dev/agentos-core\";\nexport { defineSoftware, nodeModulesMount } from \"@rivet-dev/agentos-core\";\nexport type {\n\tAgentOsActorConfigInput as AgentOSActorConfigInput,\n\tAgentOsActorConfigInput as AgentOSConfigInput,\n} from \"./actor.js\";\nexport {\n\ttype AgentOsActions,\n\ttype AgentOsActorConfigInput,\n\ttype AgentOsActorExtras,\n\ttype AgentOsEventHooks,\n\tcreateAgentOS,\n\tcreateAgentOS as agentOS,\n\tcreateAgentOsActions,\n} from \"./actor.js\";\nexport type {\n\tAgentOsEvents,\n\tProcessExitPayload,\n\tProcessOutputPayload,\n\tSerializableCronAction,\n\tSerializableCronEvent,\n\tSerializableCronJobInfo,\n\tSerializableCronJobOptions,\n\tShellDataPayload,\n\tShellExitPayload,\n\tVmBootedPayload,\n\tVmShutdownPayload,\n} from \"./types.js\";\n","import crypto from \"node:crypto\";\nimport {\n\tAgentOs,\n\ttype AgentExitEvent,\n\ttype AgentOsOptions,\n\ttype CronEvent,\n\ttype DynamicMountDescriptor,\n\ttype OpenSessionInput,\n\ttype PackageDescriptor,\n\ttype PromptInput,\n\ttype SessionStreamEntry,\n} from \"@rivet-dev/agentos-core\";\nimport {\n\ttype Actions,\n\ttype ActorConfigInput,\n\ttype ActorContext,\n\ttype ActorDefinition,\n\tactor,\n\tevent,\n\ttype Type,\n\tUserError,\n} from \"rivetkit\";\nimport { type DatabaseProvider, db, type RawAccess } from \"rivetkit/db\";\nimport type {\n\tAgentOsEvents,\n\tProcessExitPayload,\n\tProcessOutputPayload,\n\tSerializableCronJobOptions,\n\tShellDataPayload,\n\tShellExitPayload,\n\tVmBootedPayload,\n\tVmShutdownPayload,\n} from \"./types.js\";\n\n// Prompts may remain paused at a permission request for a long human review.\n// RivetKit currently exposes only one actor-wide action timeout, so use the\n// largest value Node timers can represent safely (~24.8 days). Callers may\n// still opt into a shorter timeout through actor options.\nconst DEFAULT_ACTION_TIMEOUT_MS = 2_147_483_647;\nconst DEFAULT_SLEEP_GRACE_PERIOD_MS = 15 * 60_000;\nconst DEFAULT_PREVIEW_TTL_SECONDS = 3_600;\nconst MAX_PREVIEW_TTL_SECONDS = 86_400;\nconst DEFAULT_MAX_ACTIVE_PREVIEW_TOKENS = 1_024;\nconst DEFAULT_MAX_SESSION_SUBSCRIPTIONS = 10_000;\nconst DEFAULT_MAX_DYNAMIC_MOUNTS = 10_000;\nconst DEFAULT_MAX_LINKED_SOFTWARE = 10_000;\nconst ACTOR_SQLITE_CHUNK_SIZE = 512 * 1024;\nconst ACTOR_SQLITE_INLINE_THRESHOLD = 64 * 1024;\nconst ROOT_NAMESPACE = \"agentos-root\";\nconst PREVIEW_PATH_PATTERN = /^\\/fetch\\/([a-f0-9]{48})(\\/.*)?$/;\nconst MAX_SQLITE_SAFE_INTEGER = Number.MAX_SAFE_INTEGER;\n\ninterface ActorSqliteMigration {\n\treadonly version: number;\n\treadonly sql: string;\n}\n\nconst ACTOR_SQLITE_MIGRATIONS = [\n\t{\n\t\tversion: 1,\n\t\tsql: `\n\t\t\tCREATE TABLE agentos_actor_preview_tokens (\n\t\t\t\ttoken TEXT PRIMARY KEY CHECK (length(token) = 48 AND token NOT GLOB '*[^0-9a-f]*'),\n\t\t\t\tport INTEGER NOT NULL CHECK (port BETWEEN 1 AND 65535),\n\t\t\t\tcreated_at_ms INTEGER NOT NULL CHECK (created_at_ms BETWEEN 0 AND ${MAX_SQLITE_SAFE_INTEGER}),\n\t\t\t\texpires_at_ms INTEGER NOT NULL CHECK (expires_at_ms > created_at_ms AND expires_at_ms <= ${MAX_SQLITE_SAFE_INTEGER})\n\t\t\t) STRICT;\n\t\t\tCREATE INDEX agentos_actor_preview_tokens_by_expiry\n\t\t\t\tON agentos_actor_preview_tokens(expires_at_ms);\n\t\t\tCREATE TABLE agentos_actor_dynamic_mounts (\n\t\t\t\tpath TEXT PRIMARY KEY CHECK (substr(path, 1, 1) = '/' AND instr(path, char(0)) = 0),\n\t\t\t\tdescriptor_json TEXT NOT NULL CHECK (json_valid(descriptor_json) AND json_type(descriptor_json) = 'object')\n\t\t\t) STRICT;\n\t\t\tCREATE TABLE agentos_actor_linked_software (\n\t\t\t\tpath TEXT PRIMARY KEY CHECK (length(path) > 0 AND instr(path, char(0)) = 0),\n\t\t\t\tdescriptor_json TEXT NOT NULL CHECK (json_valid(descriptor_json) AND json_type(descriptor_json) = 'object')\n\t\t\t) STRICT;\n\t\t`,\n\t},\n] as const satisfies readonly ActorSqliteMigration[];\n\ntype BuiltInEvents = {\n\t[K in keyof AgentOsEvents]: Type<AgentOsEvents[K]>;\n};\n\nconst builtInEvents: BuiltInEvents = {\n\tsessionEvent: event<SessionStreamEntry>(),\n\tvmBooted: event<VmBootedPayload>(),\n\tvmShutdown: event<VmShutdownPayload>(),\n\tprocessOutput: event<ProcessOutputPayload>(),\n\tprocessExit: event<ProcessExitPayload>(),\n\tshellData: event<ShellDataPayload>(),\n\tcronEvent: event<CronEvent>(),\n\tagentExit: event<AgentExitEvent>(),\n\tshellStderr: event<ShellDataPayload>(),\n\tshellExit: event<ShellExitPayload>(),\n};\ntype ActorDb = DatabaseProvider<RawAccess>;\ntype EventSchemaConfig = Record<string, any>;\ntype QueueSchemaConfig = Record<string, any>;\ntype AnyContext = ActorContext<any, any, any, any, any, ActorDb, any, any>;\n\ninterface RuntimeState {\n\tvm: Promise<AgentOs> | null;\n\tsubscribedSessions: Map<string, readonly (() => void)[]>;\n}\n\nconst runtimes = new Map<string, RuntimeState>();\n\nfunction runtimeFor(c: AnyContext): RuntimeState {\n\tlet runtime = runtimes.get(c.actorId);\n\tif (!runtime) {\n\t\truntime = { vm: null, subscribedSessions: new Map() };\n\t\truntimes.set(c.actorId, runtime);\n\t}\n\treturn runtime;\n}\n\nasync function ensureVm(\n\tc: AnyContext,\n\toptions?: AgentOsOptions,\n): Promise<AgentOs> {\n\tconst runtime = runtimeFor(c);\n\tif (runtime.vm !== null) return runtime.vm;\n\n\tconst startedAt = Date.now();\n\truntime.vm = (async () => {\n\t\tconst actorUds = (\n\t\t\tc as AnyContext & {\n\t\t\t\tactorUds(): Promise<{ path: string; token: string }>;\n\t\t\t}\n\t\t).actorUds;\n\t\tif (typeof actorUds !== \"function\") {\n\t\t\tthrow new Error(\n\t\t\t\t\"AgentOS actors require a RivetKit runtime with experimental actor UDS support\",\n\t\t\t);\n\t\t}\n\t\tconst { path, token } = await actorUds.call(c);\n\t\tconst mountRows = await c.db.execute<{ descriptor_json: string }>(\n\t\t\t\"SELECT descriptor_json FROM agentos_actor_dynamic_mounts ORDER BY path\",\n\t\t);\n\t\tconst softwareRows = await c.db.execute<{ descriptor_json: string }>(\n\t\t\t\"SELECT descriptor_json FROM agentos_actor_linked_software ORDER BY path\",\n\t\t);\n\t\tconst vm = await AgentOs.create({\n\t\t\t...options,\n\t\t\tdatabase: { type: \"actor_uds\", path, token },\n\t\t\tonAgentExit: (event) => {\n\t\t\t\tc.log.error({\n\t\t\t\t\tmsg: \"agent-os agent adapter exited unexpectedly\",\n\t\t\t\t\t...event,\n\t\t\t\t});\n\t\t\t\tc.broadcast(\"agentExit\", event);\n\t\t\t\ttry {\n\t\t\t\t\toptions?.onAgentExit?.(event);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tc.log.error({\n\t\t\t\t\t\tmsg: \"agent-os onAgentExit hook failed\",\n\t\t\t\t\t\tsessionId: event.sessionId,\n\t\t\t\t\t\terror,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t},\n\t\t\trootFilesystem: {\n\t\t\t\ttype: \"native\",\n\t\t\t\tplugin: {\n\t\t\t\t\tid: \"chunked_actor_sqlite\",\n\t\t\t\t\tconfig: {\n\t\t\t\t\t\tnamespace: ROOT_NAMESPACE,\n\t\t\t\t\t\tchunkSize: ACTOR_SQLITE_CHUNK_SIZE,\n\t\t\t\t\t\tinlineThreshold: ACTOR_SQLITE_INLINE_THRESHOLD,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\t\ttry {\n\t\t\tfor (const row of mountRows) {\n\t\t\t\tawait vm.mountFs(\n\t\t\t\t\tJSON.parse(row.descriptor_json) as DynamicMountDescriptor,\n\t\t\t\t);\n\t\t\t}\n\t\t\tfor (const row of softwareRows) {\n\t\t\t\tawait vm.linkSoftware(\n\t\t\t\t\tJSON.parse(row.descriptor_json) as PackageDescriptor,\n\t\t\t\t);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tawait vm.dispose();\n\t\t\tthrow error;\n\t\t}\n\t\tvm.onCronEvent((cronEvent) => c.broadcast(\"cronEvent\", cronEvent));\n\t\tc.broadcast(\"vmBooted\", {});\n\t\tc.log.info({\n\t\t\tmsg: \"agent-os vm booted\",\n\t\t\tbootDurationMs: Date.now() - startedAt,\n\t\t});\n\t\treturn vm;\n\t})();\n\n\ttry {\n\t\treturn await runtime.vm;\n\t} catch (error) {\n\t\truntime.vm = null;\n\t\tthrow error;\n\t}\n}\n\nasync function disposeVm(c: AnyContext, reason: \"sleep\" | \"destroy\" | \"error\") {\n\tconst runtime = runtimes.get(c.actorId);\n\tif (!runtime) return;\n\tconst vm = runtime.vm;\n\truntimes.delete(c.actorId);\n\tfor (const unsubscribers of runtime.subscribedSessions.values()) {\n\t\tfor (const unsubscribe of unsubscribers) unsubscribe();\n\t}\n\truntime.subscribedSessions.clear();\n\tif (vm) await (await vm).dispose();\n\tc.broadcast(\"vmShutdown\", { reason });\n}\n\nfunction matchPreviewPath(pathname: string): RegExpMatchArray | null {\n\treturn pathname.match(PREVIEW_PATH_PATTERN);\n}\n\n/** @internal Exported only for focused migration-ladder tests. */\nexport function validateAgentOsActorMigrationLadder(\n\tmigrations: readonly ActorSqliteMigration[],\n): void {\n\tif (migrations.length === 0) {\n\t\tthrow new Error(\"AgentOS actor SQLite migration ladder must not be empty\");\n\t}\n\tfor (const [index, migration] of migrations.entries()) {\n\t\tconst expectedVersion = index + 1;\n\t\tif (migration.version !== expectedVersion) {\n\t\t\tthrow new Error(\n\t\t\t\t`invalid AgentOS actor SQLite migration ladder: expected version ${expectedVersion}, received ${migration.version}`,\n\t\t\t);\n\t\t}\n\t\tif (migration.sql.trim().length === 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`invalid AgentOS actor SQLite migration ${migration.version}: SQL is empty`,\n\t\t\t);\n\t\t}\n\t\tif (\n\t\t\t/(?:^|;)\\s*(?:BEGIN|COMMIT|ROLLBACK|SAVEPOINT|RELEASE)\\b/im.test(\n\t\t\t\tmigration.sql,\n\t\t\t)\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t`invalid AgentOS actor SQLite migration ${migration.version}: transaction control belongs to the migration provider`,\n\t\t\t);\n\t\t}\n\t\tif (/\\b(?:FOREIGN\\s+KEY|REFERENCES)\\b/i.test(migration.sql)) {\n\t\t\tthrow new Error(\n\t\t\t\t`invalid AgentOS actor SQLite migration ${migration.version}: foreign keys are not used in the actor-owned schema`,\n\t\t\t);\n\t\t}\n\t\tfor (const statement of migration.sql.split(\";\")) {\n\t\t\tif (\n\t\t\t\t/^\\s*CREATE\\s+TABLE\\b/i.test(statement) &&\n\t\t\t\t!/[)]\\s*STRICT\\s*$/i.test(statement)\n\t\t\t) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`invalid AgentOS actor SQLite migration ${migration.version}: every actor-owned table must be STRICT`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tconst ownedIdentifiers = migration.sql.match(/\\bagentos_[a-z0-9_]+\\b/gi);\n\t\tif (\n\t\t\t!ownedIdentifiers ||\n\t\t\townedIdentifiers.some(\n\t\t\t\t(identifier) => !identifier.startsWith(\"agentos_actor_\"),\n\t\t\t)\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t`invalid AgentOS actor SQLite migration ${migration.version}: migrations may reference only agentos_actor_* tables and indexes`,\n\t\t\t);\n\t\t}\n\t}\n}\n\n/** @internal Exported only for focused migration tests. */\nexport async function migrateAgentOsActorTables(\n\tdatabase: RawAccess,\n): Promise<void> {\n\tvalidateAgentOsActorMigrationLadder(ACTOR_SQLITE_MIGRATIONS);\n\tawait database.execute(`\n\t\tCREATE TABLE IF NOT EXISTS agentos_actor_schema_version (\n\t\t\tsingleton INTEGER PRIMARY KEY CHECK (singleton = 1),\n\t\t\tschema_version INTEGER NOT NULL CHECK (schema_version BETWEEN 0 AND ${MAX_SQLITE_SAFE_INTEGER})\n\t\t) STRICT;\n\t`);\n\tconst rows = await database.execute<{ schema_version: unknown }>(\n\t\t\"SELECT schema_version FROM agentos_actor_schema_version WHERE singleton = 1\",\n\t);\n\tif (rows.length > 1) {\n\t\tthrow new Error(\n\t\t\t`invalid AgentOS actor SQLite schema version table: expected at most one row, received ${rows.length}`,\n\t\t);\n\t}\n\tconst rawCurrent = rows[0]?.schema_version;\n\tconst current = rows.length === 0 ? 0 : rawCurrent;\n\tif (\n\t\ttypeof current !== \"number\" ||\n\t\t!Number.isSafeInteger(current) ||\n\t\tcurrent < 0\n\t) {\n\t\tthrow new Error(\n\t\t\t`invalid AgentOS actor SQLite schema version ${String(rawCurrent)}`,\n\t\t);\n\t}\n\tif (current > ACTOR_SQLITE_MIGRATIONS.length) {\n\t\tthrow new Error(\n\t\t\t`AgentOS actor SQLite schema version ${current} is newer than supported version ${ACTOR_SQLITE_MIGRATIONS.length}`,\n\t\t);\n\t}\n\tfor (const migration of ACTOR_SQLITE_MIGRATIONS.slice(current)) {\n\t\tawait database.execute(migration.sql);\n\t\tawait database.execute(\n\t\t\t`INSERT INTO agentos_actor_schema_version (singleton, schema_version)\n\t\t\t VALUES (1, ?)\n\t\t\t ON CONFLICT(singleton) DO UPDATE SET schema_version = excluded.schema_version`,\n\t\t\tmigration.version,\n\t\t);\n\t}\n}\n\nasync function assertActorCollectionCapacity(\n\tc: AnyContext,\n\ttable: \"agentos_actor_dynamic_mounts\" | \"agentos_actor_linked_software\",\n\tkey: string,\n\tlimit: number,\n\tlabel: \"dynamic mounts\" | \"linked software packages\",\n\tconfigKey: \"maxDynamicMounts\" | \"maxLinkedSoftware\",\n): Promise<void> {\n\tconst existing = await c.db.execute<{ present: number }>(\n\t\t`SELECT 1 AS present FROM ${table} WHERE path = ? LIMIT 1`,\n\t\tkey,\n\t);\n\tif (existing.length > 0) return;\n\tconst rows = await c.db.execute<{ count: number }>(\n\t\t`SELECT COUNT(*) AS count FROM ${table}`,\n\t);\n\tconst count = Number(rows[0]?.count ?? 0);\n\tif (count >= limit) {\n\t\tthrow new UserError(\n\t\t\t`${label} limit ${limit} reached; raise ${configKey} to persist more`,\n\t\t\t{\n\t\t\t\tcode: `agentos_${configKey === \"maxDynamicMounts\" ? \"dynamic_mount\" : \"linked_software\"}_limit`,\n\t\t\t\tmetadata: { limit },\n\t\t\t},\n\t\t);\n\t}\n\tif (count + 1 === Math.ceil(limit * 0.8)) {\n\t\tc.log.warn({\n\t\t\tmsg: `${label} are near the limit of ${limit}; raise ${configKey} to persist more`,\n\t\t\tcount: count + 1,\n\t\t\tlimit,\n\t\t});\n\t}\n}\n\nexport interface AgentOsEventHooks<TContext = AnyContext> {\n\tonSessionEvent?: (\n\t\tc: TContext,\n\t\tsessionId: string,\n\t\tevent: SessionStreamEntry,\n\t) => void | Promise<void>;\n}\n\nfunction trackSessionEvents(\n\tc: AnyContext,\n\tvm: AgentOs,\n\tsessionId: string,\n\thooks: AgentOsEventHooks,\n\tmaxSessionSubscriptions: number,\n): void {\n\tconst runtime = runtimeFor(c);\n\tif (runtime.subscribedSessions.has(sessionId)) return;\n\tif (runtime.subscribedSessions.size >= maxSessionSubscriptions) {\n\t\tthrow new UserError(\n\t\t\t`session subscription limit ${maxSessionSubscriptions} reached; raise maxSessionSubscriptions to observe more sessions`,\n\t\t\t{\n\t\t\t\tcode: \"agentos_session_subscription_limit\",\n\t\t\t\tmetadata: { limit: maxSessionSubscriptions },\n\t\t\t},\n\t\t);\n\t}\n\tconst nextCount = runtime.subscribedSessions.size + 1;\n\tif (nextCount === Math.ceil(maxSessionSubscriptions * 0.8)) {\n\t\tc.log.warn({\n\t\t\tmsg: `session subscriptions are near the limit of ${maxSessionSubscriptions}; raise maxSessionSubscriptions to observe more sessions`,\n\t\t\tsubscriptionCount: nextCount,\n\t\t\tlimit: maxSessionSubscriptions,\n\t\t});\n\t}\n\tconst unsubscribeSession = vm.onSessionEvent(\n\t\tsessionId,\n\t\t(notification: SessionStreamEntry) => {\n\t\t\tconst serialized = JSON.parse(\n\t\t\t\tJSON.stringify(notification),\n\t\t\t) as SessionStreamEntry;\n\t\t\tc.broadcast(\"sessionEvent\", serialized);\n\t\t\tif (hooks.onSessionEvent) {\n\t\t\t\tc.waitUntil(\n\t\t\t\t\tPromise.resolve()\n\t\t\t\t\t\t.then(() => hooks.onSessionEvent?.(c, sessionId, serialized))\n\t\t\t\t\t\t.catch((error) =>\n\t\t\t\t\t\t\tc.log.error({\n\t\t\t\t\t\t\t\tmsg: \"agent-os session event hook failed\",\n\t\t\t\t\t\t\t\tsessionId,\n\t\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t);\n\truntime.subscribedSessions.set(sessionId, [unsubscribeSession]);\n}\n\nfunction untrackSessionEvents(c: AnyContext, sessionId: string): void {\n\tconst unsubscribers = runtimeFor(c).subscribedSessions.get(sessionId);\n\tif (!unsubscribers) return;\n\tfor (const unsubscribe of unsubscribers) unsubscribe();\n\truntimeFor(c).subscribedSessions.delete(sessionId);\n}\n\nexport function createAgentOsActions(\n\toptions?: AgentOsOptions,\n\thooks: AgentOsEventHooks = {},\n\tpreview: AgentOsActorExtras[\"preview\"] = {},\n\tmaxSessionSubscriptions = DEFAULT_MAX_SESSION_SUBSCRIPTIONS,\n\tmaxDynamicMounts = DEFAULT_MAX_DYNAMIC_MOUNTS,\n\tmaxLinkedSoftware = DEFAULT_MAX_LINKED_SOFTWARE,\n) {\n\tconst defaultPreviewTtlSeconds =\n\t\tpreview.defaultExpiresInSeconds ?? DEFAULT_PREVIEW_TTL_SECONDS;\n\tconst maxPreviewTtlSeconds =\n\t\tpreview.maxExpiresInSeconds ?? MAX_PREVIEW_TTL_SECONDS;\n\tconst maxActivePreviewTokens =\n\t\tpreview.maxActiveTokens ?? DEFAULT_MAX_ACTIVE_PREVIEW_TOKENS;\n\tif (\n\t\t!Number.isFinite(defaultPreviewTtlSeconds) ||\n\t\tdefaultPreviewTtlSeconds <= 0 ||\n\t\t!Number.isFinite(maxPreviewTtlSeconds) ||\n\t\tmaxPreviewTtlSeconds <= 0 ||\n\t\tdefaultPreviewTtlSeconds > maxPreviewTtlSeconds\n\t) {\n\t\tthrow new UserError(\n\t\t\t\"preview expiry bounds must be positive and the default cannot exceed the maximum\",\n\t\t\t{ code: \"agentos_preview_invalid_config\" },\n\t\t);\n\t}\n\tif (!Number.isInteger(maxActivePreviewTokens) || maxActivePreviewTokens < 1) {\n\t\tthrow new UserError(\"preview.maxActiveTokens must be a positive integer\", {\n\t\t\tcode: \"agentos_preview_invalid_config\",\n\t\t});\n\t}\n\tif (\n\t\t!Number.isInteger(maxSessionSubscriptions) ||\n\t\tmaxSessionSubscriptions < 1\n\t) {\n\t\tthrow new UserError(\"maxSessionSubscriptions must be a positive integer\", {\n\t\t\tcode: \"agentos_session_subscription_invalid_config\",\n\t\t});\n\t}\n\tif (!Number.isInteger(maxDynamicMounts) || maxDynamicMounts < 1) {\n\t\tthrow new UserError(\"maxDynamicMounts must be a positive integer\", {\n\t\t\tcode: \"agentos_dynamic_mount_invalid_config\",\n\t\t});\n\t}\n\tif (!Number.isInteger(maxLinkedSoftware) || maxLinkedSoftware < 1) {\n\t\tthrow new UserError(\"maxLinkedSoftware must be a positive integer\", {\n\t\t\tcode: \"agentos_linked_software_invalid_config\",\n\t\t});\n\t}\n\treturn {\n\t\treadFile: async (c: AnyContext, ...args: Parameters<AgentOs[\"readFile\"]>) =>\n\t\t\t(await ensureVm(c, options)).readFile(...args),\n\t\twriteFile: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"writeFile\"]>\n\t\t) => (await ensureVm(c, options)).writeFile(...args),\n\t\treadFiles: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"readFiles\"]>\n\t\t) => (await ensureVm(c, options)).readFiles(...args),\n\t\twriteFiles: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"writeFiles\"]>\n\t\t) => (await ensureVm(c, options)).writeFiles(...args),\n\t\tstat: async (c: AnyContext, ...args: Parameters<AgentOs[\"stat\"]>) =>\n\t\t\t(await ensureVm(c, options)).stat(...args),\n\t\tmkdir: async (c: AnyContext, ...args: Parameters<AgentOs[\"mkdir\"]>) =>\n\t\t\t(await ensureVm(c, options)).mkdir(...args),\n\t\treaddir: async (c: AnyContext, ...args: Parameters<AgentOs[\"readdir\"]>) =>\n\t\t\t(await ensureVm(c, options)).readdir(...args),\n\t\treaddirEntries: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"readdirEntries\"]>\n\t\t) => (await ensureVm(c, options)).readdirEntries(...args),\n\t\treaddirRecursive: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"readdirRecursive\"]>\n\t\t) => (await ensureVm(c, options)).readdirRecursive(...args),\n\t\texists: async (c: AnyContext, ...args: Parameters<AgentOs[\"exists\"]>) =>\n\t\t\t(await ensureVm(c, options)).exists(...args),\n\t\tmove: async (c: AnyContext, ...args: Parameters<AgentOs[\"move\"]>) =>\n\t\t\t(await ensureVm(c, options)).move(...args),\n\t\tremove: async (c: AnyContext, ...args: Parameters<AgentOs[\"remove\"]>) =>\n\t\t\t(await ensureVm(c, options)).remove(...args),\n\t\texec: async (c: AnyContext, ...args: Parameters<AgentOs[\"exec\"]>) =>\n\t\t\t(await ensureVm(c, options)).exec(...args),\n\t\texecArgv: async (c: AnyContext, ...args: Parameters<AgentOs[\"execArgv\"]>) =>\n\t\t\t(await ensureVm(c, options)).execArgv(...args),\n\t\tspawn: async (c: AnyContext, ...args: Parameters<AgentOs[\"spawn\"]>) => {\n\t\t\tconst vm = await ensureVm(c, options);\n\t\t\tconst process = vm.spawn(...args);\n\t\t\tconst unsubscribeOutput = vm.onProcessOutput(process.pid, (event) =>\n\t\t\t\tc.broadcast(\"processOutput\", event),\n\t\t\t);\n\t\t\tconst unsubscribeExit = vm.onProcessExit(process.pid, (event) =>\n\t\t\t\tc.broadcast(\"processExit\", event),\n\t\t\t);\n\t\t\tvoid c\n\t\t\t\t.keepAwake(\n\t\t\t\t\tvm.waitProcess(process.pid).finally(() => {\n\t\t\t\t\t\tunsubscribeOutput();\n\t\t\t\t\t\tunsubscribeExit();\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\t.catch((error) =>\n\t\t\t\t\tc.log.error({\n\t\t\t\t\t\tmsg: \"agent-os process wait failed\",\n\t\t\t\t\t\tpid: process.pid,\n\t\t\t\t\t\terror,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\treturn process;\n\t\t},\n\t\twaitProcess: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"waitProcess\"]>\n\t\t) => (await ensureVm(c, options)).waitProcess(...args),\n\t\tkillProcess: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"killProcess\"]>\n\t\t) => (await ensureVm(c, options)).killProcess(...args),\n\t\tstopProcess: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"stopProcess\"]>\n\t\t) => (await ensureVm(c, options)).stopProcess(...args),\n\t\tlistProcesses: async (c: AnyContext) =>\n\t\t\t(await ensureVm(c, options)).listProcesses(),\n\t\tallProcesses: async (c: AnyContext) =>\n\t\t\t(await ensureVm(c, options)).allProcesses(),\n\t\tprocessTree: async (c: AnyContext) =>\n\t\t\t(await ensureVm(c, options)).processTree(),\n\t\tgetProcess: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"getProcess\"]>\n\t\t) => (await ensureVm(c, options)).getProcess(...args),\n\t\twriteProcessStdin: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"writeProcessStdin\"]>\n\t\t) => (await ensureVm(c, options)).writeProcessStdin(...args),\n\t\tcloseProcessStdin: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"closeProcessStdin\"]>\n\t\t) => (await ensureVm(c, options)).closeProcessStdin(...args),\n\t\topenShell: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"openShell\"]>\n\t\t) => {\n\t\t\tconst vm = await ensureVm(c, options);\n\t\t\tconst shell = vm.openShell(...args);\n\t\t\tconst unsubscribeData = vm.onShellData(shell.shellId, (event) =>\n\t\t\t\tc.broadcast(\"shellData\", event),\n\t\t\t);\n\t\t\tconst unsubscribeStderr = vm.onShellStderr(shell.shellId, (event) =>\n\t\t\t\tc.broadcast(\"shellStderr\", event),\n\t\t\t);\n\t\t\tconst unsubscribeExit = vm.onShellExit(shell.shellId, (event) =>\n\t\t\t\tc.broadcast(\"shellExit\", event),\n\t\t\t);\n\t\t\tvoid c\n\t\t\t\t.keepAwake(\n\t\t\t\t\tvm.waitShell(shell.shellId).finally(() => {\n\t\t\t\t\t\tunsubscribeData();\n\t\t\t\t\t\tunsubscribeStderr();\n\t\t\t\t\t\tunsubscribeExit();\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\t.catch((error) =>\n\t\t\t\t\tc.log.error({\n\t\t\t\t\t\tmsg: \"agent-os shell wait failed\",\n\t\t\t\t\t\tshellId: shell.shellId,\n\t\t\t\t\t\terror,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\treturn shell;\n\t\t},\n\t\twriteShell: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"writeShell\"]>\n\t\t) => (await ensureVm(c, options)).writeShell(...args),\n\t\tresizeShell: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"resizeShell\"]>\n\t\t) => (await ensureVm(c, options)).resizeShell(...args),\n\t\tcloseShell: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"closeShell\"]>\n\t\t) => (await ensureVm(c, options)).closeShell(...args),\n\t\twaitShell: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"waitShell\"]>\n\t\t) => (await ensureVm(c, options)).waitShell(...args),\n\t\thttpRequest: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"httpRequest\"]>\n\t\t) => (await ensureVm(c, options)).httpRequest(...args),\n\t\tscheduleCron: async (\n\t\t\tc: AnyContext,\n\t\t\tcronOptions: SerializableCronJobOptions,\n\t\t) => {\n\t\t\tconst job = (await ensureVm(c, options)).scheduleCron(\n\t\t\t\tcronOptions as Parameters<AgentOs[\"scheduleCron\"]>[0],\n\t\t\t);\n\t\t\treturn { id: job.id };\n\t\t},\n\t\tlistCronJobs: async (c: AnyContext) =>\n\t\t\t(await ensureVm(c, options)).listCronJobs(),\n\t\tcancelCronJob: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"cancelCronJob\"]>\n\t\t) => (await ensureVm(c, options)).cancelCronJob(...args),\n\t\tlistAgents: async (c: AnyContext) =>\n\t\t\t(await ensureVm(c, options)).listAgents(),\n\t\topenSession: async (c: AnyContext, input: OpenSessionInput) => {\n\t\t\tconst vm = await ensureVm(c, options);\n\t\t\tawait vm.openSession(input);\n\t\t\ttrackSessionEvents(\n\t\t\t\tc,\n\t\t\t\tvm,\n\t\t\t\tinput.sessionId ?? \"main\",\n\t\t\t\thooks,\n\t\t\t\tmaxSessionSubscriptions,\n\t\t\t);\n\t\t},\n\t\tgetSession: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"getSession\"]>\n\t\t) => (await ensureVm(c, options)).getSession(...args),\n\t\tlistSessions: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"listSessions\"]>\n\t\t) => (await ensureVm(c, options)).listSessions(...args),\n\t\tdeleteSession: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"deleteSession\"]>\n\t\t) => {\n\t\t\tconst result = await (await ensureVm(c, options)).deleteSession(...args);\n\t\t\tuntrackSessionEvents(c, args[0]?.sessionId ?? \"main\");\n\t\t\treturn result;\n\t\t},\n\t\tunloadSession: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"unloadSession\"]>\n\t\t) => {\n\t\t\tconst result = await (await ensureVm(c, options)).unloadSession(...args);\n\t\t\tuntrackSessionEvents(c, args[0]?.sessionId ?? \"main\");\n\t\t\treturn result;\n\t\t},\n\t\tprompt: async (c: AnyContext, input: PromptInput) => {\n\t\t\tconst vm = await ensureVm(c, options);\n\t\t\tconst sessionId = input.sessionId ?? \"main\";\n\t\t\ttrackSessionEvents(c, vm, sessionId, hooks, maxSessionSubscriptions);\n\t\t\t// The actor is held only through the terminal SQLite commit for this\n\t\t\t// active turn. Merely having an idle durable session holds nothing.\n\t\t\treturn c.keepAwake(vm.prompt(input));\n\t\t},\n\t\tcancelPrompt: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"cancelPrompt\"]>\n\t\t) => (await ensureVm(c, options)).cancelPrompt(...args),\n\t\trespondPermission: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"respondPermission\"]>\n\t\t) => (await ensureVm(c, options)).respondPermission(...args),\n\t\treadHistory: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"readHistory\"]>\n\t\t) => (await ensureVm(c, options)).readHistory(...args),\n\t\tgetSessionConfig: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"getSessionConfig\"]>\n\t\t) => (await ensureVm(c, options)).getSessionConfig(...args),\n\t\tsetSessionConfigOption: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"setSessionConfigOption\"]>\n\t\t) => (await ensureVm(c, options)).setSessionConfigOption(...args),\n\t\tgetSessionCapabilities: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"getSessionCapabilities\"]>\n\t\t) => (await ensureVm(c, options)).getSessionCapabilities(...args),\n\t\tgetSessionAgentInfo: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"getSessionAgentInfo\"]>\n\t\t) => (await ensureVm(c, options)).getSessionAgentInfo(...args),\n\t\tcreatePreviewUrl: async (\n\t\t\tc: AnyContext,\n\t\t\tport: number,\n\t\t\tttlSeconds = defaultPreviewTtlSeconds,\n\t\t) => {\n\t\t\tif (!Number.isInteger(port) || port < 1 || port > 65_535)\n\t\t\t\tthrow new UserError(\n\t\t\t\t\t\"port must be an integer between 1 and 65535; pass a valid VM listener port\",\n\t\t\t\t\t{ code: \"agentos_preview_invalid_port\" },\n\t\t\t\t);\n\t\t\tif (\n\t\t\t\t!Number.isFinite(ttlSeconds) ||\n\t\t\t\tttlSeconds <= 0 ||\n\t\t\t\tttlSeconds > maxPreviewTtlSeconds\n\t\t\t)\n\t\t\t\tthrow new UserError(\n\t\t\t\t\t`ttlSeconds must be greater than 0 and at most ${maxPreviewTtlSeconds}; raise preview.maxExpiresInSeconds to allow a longer lifetime`,\n\t\t\t\t\t{ code: \"agentos_preview_invalid_ttl\" },\n\t\t\t\t);\n\t\t\tconst token = crypto.randomBytes(24).toString(\"hex\");\n\t\t\tconst createdAt = Date.now();\n\t\t\tconst expiresAt = createdAt + ttlSeconds * 1_000;\n\t\t\tawait c.db.execute(\n\t\t\t\t\"DELETE FROM agentos_actor_preview_tokens WHERE expires_at_ms <= ?\",\n\t\t\t\tcreatedAt,\n\t\t\t);\n\t\t\tconst counts = await c.db.execute<{ count: number }>(\n\t\t\t\t\"SELECT COUNT(*) AS count FROM agentos_actor_preview_tokens\",\n\t\t\t);\n\t\t\tconst activeTokenCount = Number(counts[0]?.count ?? 0);\n\t\t\tif (activeTokenCount >= maxActivePreviewTokens) {\n\t\t\t\tthrow new UserError(\n\t\t\t\t\t`preview token limit ${maxActivePreviewTokens} reached; raise preview.maxActiveTokens to allow more`,\n\t\t\t\t\t{\n\t\t\t\t\t\tcode: \"agentos_preview_token_limit\",\n\t\t\t\t\t\tmetadata: { limit: maxActivePreviewTokens },\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst nextActiveTokenCount = activeTokenCount + 1;\n\t\t\tconst warningThreshold = Math.ceil(maxActivePreviewTokens * 0.8);\n\t\t\tif (nextActiveTokenCount === warningThreshold) {\n\t\t\t\tc.log.warn({\n\t\t\t\t\tmsg: `preview tokens are near the limit of ${maxActivePreviewTokens}; raise preview.maxActiveTokens to allow more`,\n\t\t\t\t\tactiveTokenCount: nextActiveTokenCount,\n\t\t\t\t\tlimit: maxActivePreviewTokens,\n\t\t\t\t});\n\t\t\t}\n\t\t\tawait c.db.execute(\n\t\t\t\t\"INSERT INTO agentos_actor_preview_tokens (token, port, created_at_ms, expires_at_ms) VALUES (?, ?, ?, ?)\",\n\t\t\t\ttoken,\n\t\t\t\tport,\n\t\t\t\tcreatedAt,\n\t\t\t\texpiresAt,\n\t\t\t);\n\t\t\treturn { path: `/fetch/${token}`, token, port, expiresAt };\n\t\t},\n\t\texpirePreviewUrl: async (c: AnyContext, token: string) => {\n\t\t\tawait c.db.execute(\n\t\t\t\t\"DELETE FROM agentos_actor_preview_tokens WHERE token = ?\",\n\t\t\t\ttoken,\n\t\t\t);\n\t\t},\n\t\texportRootFilesystem: async (\n\t\t\tc: AnyContext,\n\t\t\t...args: Parameters<AgentOs[\"exportRootFilesystem\"]>\n\t\t) => (await ensureVm(c, options)).exportRootFilesystem(...args),\n\t\tmountFs: async (c: AnyContext, descriptor: DynamicMountDescriptor) => {\n\t\t\tawait assertActorCollectionCapacity(\n\t\t\t\tc,\n\t\t\t\t\"agentos_actor_dynamic_mounts\",\n\t\t\t\tdescriptor.path,\n\t\t\t\tmaxDynamicMounts,\n\t\t\t\t\"dynamic mounts\",\n\t\t\t\t\"maxDynamicMounts\",\n\t\t\t);\n\t\t\tconst vm = await ensureVm(c, options);\n\t\t\tawait vm.mountFs(descriptor);\n\t\t\ttry {\n\t\t\t\tawait c.db.execute(\n\t\t\t\t\t\"INSERT INTO agentos_actor_dynamic_mounts (path, descriptor_json) VALUES (?, ?) ON CONFLICT(path) DO UPDATE SET descriptor_json = excluded.descriptor_json\",\n\t\t\t\t\tdescriptor.path,\n\t\t\t\t\tJSON.stringify(descriptor),\n\t\t\t\t);\n\t\t\t} catch (error) {\n\t\t\t\ttry {\n\t\t\t\t\tawait vm.unmountFs(descriptor.path);\n\t\t\t\t} catch (rollbackError) {\n\t\t\t\t\tc.log.error({\n\t\t\t\t\t\tmsg: \"agent-os dynamic mount rollback failed\",\n\t\t\t\t\t\tpath: descriptor.path,\n\t\t\t\t\t\terror: rollbackError,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t\tunmountFs: async (c: AnyContext, path: string) => {\n\t\t\tconst rows = await c.db.execute<{ descriptor_json: string }>(\n\t\t\t\t\"SELECT descriptor_json FROM agentos_actor_dynamic_mounts WHERE path = ?\",\n\t\t\t\tpath,\n\t\t\t);\n\t\t\tconst vm = await ensureVm(c, options);\n\t\t\tawait vm.unmountFs(path);\n\t\t\ttry {\n\t\t\t\tawait c.db.execute(\n\t\t\t\t\t\"DELETE FROM agentos_actor_dynamic_mounts WHERE path = ?\",\n\t\t\t\t\tpath,\n\t\t\t\t);\n\t\t\t} catch (error) {\n\t\t\t\tif (rows[0]) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait vm.mountFs(\n\t\t\t\t\t\t\tJSON.parse(rows[0].descriptor_json) as DynamicMountDescriptor,\n\t\t\t\t\t\t);\n\t\t\t\t\t} catch (rollbackError) {\n\t\t\t\t\t\tc.log.error({\n\t\t\t\t\t\t\tmsg: \"agent-os dynamic unmount rollback failed\",\n\t\t\t\t\t\t\tpath,\n\t\t\t\t\t\t\terror: rollbackError,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t\tlistMounts: async (c: AnyContext) =>\n\t\t\t(await ensureVm(c, options)).listMounts(),\n\t\tlistSoftware: async (c: AnyContext) =>\n\t\t\t(await ensureVm(c, options)).listSoftware(),\n\t\tlinkSoftware: async (c: AnyContext, descriptor: PackageDescriptor) => {\n\t\t\tawait assertActorCollectionCapacity(\n\t\t\t\tc,\n\t\t\t\t\"agentos_actor_linked_software\",\n\t\t\t\tdescriptor.path,\n\t\t\t\tmaxLinkedSoftware,\n\t\t\t\t\"linked software packages\",\n\t\t\t\t\"maxLinkedSoftware\",\n\t\t\t);\n\t\t\tawait c.db.execute(\n\t\t\t\t\"INSERT INTO agentos_actor_linked_software (path, descriptor_json) VALUES (?, ?) ON CONFLICT(path) DO UPDATE SET descriptor_json = excluded.descriptor_json\",\n\t\t\t\tdescriptor.path,\n\t\t\t\tJSON.stringify(descriptor),\n\t\t\t);\n\t\t\ttry {\n\t\t\t\tawait (await ensureVm(c, options)).linkSoftware(descriptor);\n\t\t\t} catch (error) {\n\t\t\t\ttry {\n\t\t\t\t\tawait c.db.execute(\n\t\t\t\t\t\t\"DELETE FROM agentos_actor_linked_software WHERE path = ?\",\n\t\t\t\t\t\tdescriptor.path,\n\t\t\t\t\t);\n\t\t\t\t} catch (rollbackError) {\n\t\t\t\t\tc.log.error({\n\t\t\t\t\t\tmsg: \"agent-os linked software rollback failed\",\n\t\t\t\t\t\tpath: descriptor.path,\n\t\t\t\t\t\terror: rollbackError,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t};\n}\n\nexport type AgentOsActions = ReturnType<typeof createAgentOsActions>;\nexport type AgentOsActorDefinition<TConnParams = undefined> = ActorDefinition<\n\tundefined,\n\tTConnParams,\n\tundefined,\n\tundefined,\n\tundefined,\n\tActorDb,\n\tBuiltInEvents,\n\tRecord<never, never>,\n\tAgentOsActions\n>;\n\nexport interface AgentOsActorExtras extends AgentOsOptions {\n\t/** Maximum live session event subscriptions per actor VM. Default: 10,000. */\n\tmaxSessionSubscriptions?: number;\n\t/** Maximum durable dynamic mount descriptors per actor. Default: 10,000. */\n\tmaxDynamicMounts?: number;\n\t/** Maximum durable linked software descriptors per actor. Default: 10,000. */\n\tmaxLinkedSoftware?: number;\n\tpreview?: {\n\t\tdefaultExpiresInSeconds?: number;\n\t\tmaxExpiresInSeconds?: number;\n\t\tmaxActiveTokens?: number;\n\t};\n}\n\nexport type AgentOsActorConfigInput<\n\tTState = undefined,\n\tTConnParams = undefined,\n\tTConnState = undefined,\n\tTVars = undefined,\n\tTInput = undefined,\n\tTEvents extends EventSchemaConfig = Record<never, never>,\n\tTQueues extends QueueSchemaConfig = Record<never, never>,\n\tTUserActions extends Actions<\n\t\tTState,\n\t\tTConnParams,\n\t\tTConnState,\n\t\tTVars,\n\t\tTInput,\n\t\tActorDb,\n\t\tTEvents,\n\t\tTQueues\n\t> = Record<never, never>,\n> = Omit<\n\tActorConfigInput<\n\t\tTState,\n\t\tTConnParams,\n\t\tTConnState,\n\t\tTVars,\n\t\tTInput,\n\t\tActorDb,\n\t\tTEvents,\n\t\tTQueues,\n\t\tTUserActions\n\t>,\n\t\"db\"\n> &\n\tAgentOsActorExtras &\n\tAgentOsEventHooks<\n\t\tActorContext<\n\t\t\tTState,\n\t\t\tTConnParams,\n\t\t\tTConnState,\n\t\t\tTVars,\n\t\t\tTInput,\n\t\t\tActorDb,\n\t\t\tTEvents,\n\t\t\tTQueues\n\t\t>\n\t>;\n\nconst agentOsOptionKeys = [\n\t\"software\",\n\t\"defaultSoftware\",\n\t\"loopbackExemptPorts\",\n\t\"allowedNodeBuiltins\",\n\t\"highResolutionTime\",\n\t\"database\",\n\t\"rootFilesystem\",\n\t\"mounts\",\n\t\"scheduleDriver\",\n\t\"bindings\",\n\t\"permissions\",\n\t\"sidecar\",\n\t\"limits\",\n\t\"onAgentStderr\",\n\t\"onAgentExit\",\n\t\"onLimitWarning\",\n] as const satisfies readonly (keyof AgentOsOptions)[];\n\nfunction splitConfig(\n\tconfig: AgentOsActorConfigInput<any, any, any, any, any, any, any, any>,\n) {\n\tconst actorConfig = { ...config } as Record<string, unknown>;\n\tconst agentOsOptions: AgentOsOptions = {};\n\tfor (const key of agentOsOptionKeys) {\n\t\tif (key in actorConfig) {\n\t\t\t(agentOsOptions as Record<string, unknown>)[key] = actorConfig[key];\n\t\t\tdelete actorConfig[key];\n\t\t}\n\t}\n\tconst onSessionEvent =\n\t\tactorConfig.onSessionEvent as AgentOsEventHooks<AnyContext>[\"onSessionEvent\"];\n\tconst preview = actorConfig.preview as AgentOsActorExtras[\"preview\"];\n\tconst maxSessionSubscriptions = actorConfig.maxSessionSubscriptions as\n\t\t| number\n\t\t| undefined;\n\tconst maxDynamicMounts = actorConfig.maxDynamicMounts as number | undefined;\n\tconst maxLinkedSoftware = actorConfig.maxLinkedSoftware as number | undefined;\n\tdelete actorConfig.onSessionEvent;\n\tdelete actorConfig.preview;\n\tdelete actorConfig.maxSessionSubscriptions;\n\tdelete actorConfig.maxDynamicMounts;\n\tdelete actorConfig.maxLinkedSoftware;\n\treturn {\n\t\tactorConfig,\n\t\tagentOsOptions,\n\t\thooks: { onSessionEvent },\n\t\tpreview,\n\t\tmaxSessionSubscriptions,\n\t\tmaxDynamicMounts,\n\t\tmaxLinkedSoftware,\n\t};\n}\n\nfunction assertNoReservedKeys(\n\tkind: string,\n\tcustom: object | undefined,\n\tbuiltIns: object,\n) {\n\tfor (const key of Object.keys(custom ?? {})) {\n\t\tif (key in builtIns)\n\t\t\tthrow new Error(`agentOS() ${kind} name is reserved: ${key}`);\n\t}\n}\n\nexport function createAgentOS<\n\tTState = undefined,\n\tTConnParams = undefined,\n\tTConnState = undefined,\n\tTVars = undefined,\n\tTInput = undefined,\n\tTEvents extends EventSchemaConfig = Record<never, never>,\n\tTQueues extends QueueSchemaConfig = Record<never, never>,\n\tTUserActions extends Actions<\n\t\tTState,\n\t\tTConnParams,\n\t\tTConnState,\n\t\tTVars,\n\t\tTInput,\n\t\tActorDb,\n\t\tTEvents,\n\t\tTQueues\n\t> = Record<never, never>,\n>(\n\tconfig: AgentOsActorConfigInput<\n\t\tTState,\n\t\tTConnParams,\n\t\tTConnState,\n\t\tTVars,\n\t\tTInput,\n\t\tTEvents,\n\t\tTQueues,\n\t\tTUserActions\n\t> = {} as AgentOsActorConfigInput<\n\t\tTState,\n\t\tTConnParams,\n\t\tTConnState,\n\t\tTVars,\n\t\tTInput,\n\t\tTEvents,\n\t\tTQueues,\n\t\tTUserActions\n\t>,\n): ActorDefinition<\n\tTState,\n\tTConnParams,\n\tTConnState,\n\tTVars,\n\tTInput,\n\tActorDb,\n\tTEvents & BuiltInEvents,\n\tTQueues,\n\tTUserActions & AgentOsActions\n> {\n\tconst split = splitConfig(config);\n\tconst actorConfig = split.actorConfig as Omit<\n\t\ttypeof config,\n\t\tkeyof AgentOsActorExtras\n\t>;\n\tconst {\n\t\tagentOsOptions,\n\t\thooks,\n\t\tpreview,\n\t\tmaxSessionSubscriptions,\n\t\tmaxDynamicMounts,\n\t\tmaxLinkedSoftware,\n\t} = split;\n\tif (agentOsOptions.rootFilesystem) {\n\t\tthrow new Error(\n\t\t\t\"agentOS() owns rootFilesystem so it can persist directly through the actor SQLite UDS; use mounts for additional filesystems\",\n\t\t);\n\t}\n\tif (agentOsOptions.database) {\n\t\tthrow new Error(\n\t\t\t\"agentOS() owns database and injects the actor SQLite UDS descriptor; standalone AgentOs clients may choose a SQLite file\",\n\t\t);\n\t}\n\tconst actions = createAgentOsActions(\n\t\tagentOsOptions,\n\t\thooks,\n\t\tpreview,\n\t\tmaxSessionSubscriptions,\n\t\tmaxDynamicMounts,\n\t\tmaxLinkedSoftware,\n\t);\n\tassertNoReservedKeys(\"action\", actorConfig.actions, actions);\n\tassertNoReservedKeys(\"event\", actorConfig.events, builtInEvents);\n\n\tconst userOnWake = actorConfig.onWake;\n\tconst userOnSleep = actorConfig.onSleep;\n\tconst userOnDestroy = actorConfig.onDestroy;\n\tconst userOnRequest = actorConfig.onRequest;\n\tconst userOnBeforeConnect = actorConfig.onBeforeConnect;\n\n\treturn actor({\n\t\t...actorConfig,\n\t\toptions: {\n\t\t\tactionTimeout: DEFAULT_ACTION_TIMEOUT_MS,\n\t\t\tsleepGracePeriod: DEFAULT_SLEEP_GRACE_PERIOD_MS,\n\t\t\t...actorConfig.options,\n\t\t},\n\t\tdb: db({ onMigrate: migrateAgentOsActorTables }),\n\t\tevents: { ...(actorConfig.events ?? {}), ...builtInEvents },\n\t\tactions: { ...(actorConfig.actions ?? {}), ...actions },\n\t\tonBeforeConnect: async (\n\t\t\tc: Parameters<NonNullable<typeof userOnBeforeConnect>>[0],\n\t\t\tparams: Parameters<NonNullable<typeof userOnBeforeConnect>>[1],\n\t\t) => {\n\t\t\tif (\n\t\t\t\tc.request &&\n\t\t\t\tmatchPreviewPath(new URL(c.request.url).pathname) !== null\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tawait userOnBeforeConnect?.(c, params);\n\t\t},\n\t\tonWake: async (c: AnyContext) => {\n\t\t\ttry {\n\t\t\t\tawait userOnWake?.(c);\n\t\t\t} catch (error) {\n\t\t\t\tawait disposeVm(c as AnyContext, \"error\");\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t\tonSleep: async (c: AnyContext) => {\n\t\t\ttry {\n\t\t\t\tawait userOnSleep?.(c);\n\t\t\t} finally {\n\t\t\t\tawait disposeVm(c as AnyContext, \"sleep\");\n\t\t\t}\n\t\t},\n\t\tonDestroy: async (c: AnyContext) => {\n\t\t\ttry {\n\t\t\t\tawait userOnDestroy?.(c);\n\t\t\t} finally {\n\t\t\t\tawait disposeVm(c as AnyContext, \"destroy\");\n\t\t\t}\n\t\t},\n\t\tonRequest: async (c: AnyContext, request: Request) => {\n\t\t\tconst url = new URL(request.url);\n\t\t\tconst match = matchPreviewPath(url.pathname);\n\t\t\tif (!match) {\n\t\t\t\tconst response = await userOnRequest?.(c as never, request);\n\t\t\t\treturn response ?? new Response(\"Not Found\", { status: 404 });\n\t\t\t}\n\t\t\tif (request.method === \"OPTIONS\")\n\t\t\t\treturn new Response(null, {\n\t\t\t\t\tstatus: 204,\n\t\t\t\t\theaders: {\n\t\t\t\t\t\t\"access-control-allow-origin\": \"*\",\n\t\t\t\t\t\t\"access-control-allow-methods\":\n\t\t\t\t\t\t\t\"GET, POST, PUT, PATCH, DELETE, OPTIONS\",\n\t\t\t\t\t\t\"access-control-allow-headers\": \"*\",\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\tconst now = Date.now();\n\t\t\tawait c.db.execute(\n\t\t\t\t\"DELETE FROM agentos_actor_preview_tokens WHERE expires_at_ms <= ?\",\n\t\t\t\tnow,\n\t\t\t);\n\t\t\tconst rows = await c.db.execute<{ port: number }>(\n\t\t\t\t\"SELECT port FROM agentos_actor_preview_tokens WHERE token = ? AND expires_at_ms > ?\",\n\t\t\t\tmatch[1],\n\t\t\t\tnow,\n\t\t\t);\n\t\t\tif (!rows[0])\n\t\t\t\treturn new Response(\"Preview URL expired or invalid\", { status: 403 });\n\t\t\tconst target = new URL(request.url);\n\t\t\ttarget.pathname = match[2] ?? \"/\";\n\t\t\tconst vm = await ensureVm(c as AnyContext, agentOsOptions);\n\t\t\tconst requestHeaders: Record<string, string> = {};\n\t\t\trequest.headers.forEach((value, key) => {\n\t\t\t\trequestHeaders[key] = value;\n\t\t\t});\n\t\t\tconst response = await vm.httpRequest({\n\t\t\t\tport: rows[0].port,\n\t\t\t\tpath: `${target.pathname}${target.search}`,\n\t\t\t\tmethod: request.method,\n\t\t\t\theaders: requestHeaders,\n\t\t\t\t...(request.method === \"GET\" || request.method === \"HEAD\"\n\t\t\t\t\t? {}\n\t\t\t\t\t: { body: new Uint8Array(await request.arrayBuffer()) }),\n\t\t\t});\n\t\t\tconst headers = new Headers(response.headers);\n\t\t\theaders.set(\"access-control-allow-origin\", \"*\");\n\t\t\treturn new Response(Buffer.from(response.body), {\n\t\t\t\tstatus: response.status,\n\t\t\t\tstatusText: response.statusText,\n\t\t\t\theaders,\n\t\t\t});\n\t\t},\n\t} as any) as ActorDefinition<\n\t\tTState,\n\t\tTConnParams,\n\t\tTConnState,\n\t\tTVars,\n\t\tTInput,\n\t\tActorDb,\n\t\tTEvents & BuiltInEvents,\n\t\tTQueues,\n\t\tTUserActions & AgentOsActions\n\t>;\n}\n"],"mappings":";AAAA,SAAS,SAAS,qBAAqB;AAqCvC,SAAS,gBAAgB,wBAAwB;;;ACrCjD,OAAO,YAAY;AACnB;AAAA,EACC;AAAA,OASM;AACP;AAAA,EAKC;AAAA,EACA;AAAA,EAEA;AAAA,OACM;AACP,SAAgC,UAA0B;AAgB1D,IAAM,4BAA4B;AAClC,IAAM,gCAAgC,KAAK;AAC3C,IAAM,8BAA8B;AACpC,IAAM,0BAA0B;AAChC,IAAM,oCAAoC;AAC1C,IAAM,oCAAoC;AAC1C,IAAM,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AAQ,IAAI,CAAC;AACtE,YAAM,SAAS,IAAI,IAAI,QAAQ,GAAG;AAClC,aAAO,WAAW,MAAM,CAAC,KAAK;AAC9B,YAAM,KAAK,MAAM,SAAS,GAAiB,cAAc;AACzD,YAAM,iBAAyC,CAAC;AAChD,cAAQ,QAAQ,QAAQ,CAAC,OAAO,QAAQ;AACvC,uBAAe,GAAG,IAAI;AAAA,MACvB,CAAC;AACD,YAAM,WAAW,MAAM,GAAG,YAAY;AAAA,QACrC,MAAM,KAAK,CAAC,EAAE;AAAA,QACd,MAAM,GAAG,OAAO,QAAQ,GAAG,OAAO,MAAM;AAAA,QACxC,QAAQ,QAAQ;AAAA,QAChB,SAAS;AAAA,QACT,GAAI,QAAQ,WAAW,SAAS,QAAQ,WAAW,SAChD,CAAC,IACD,EAAE,MAAM,IAAI,WAAW,MAAM,QAAQ,YAAY,CAAC,EAAE;AAAA,MACxD,CAAC;AACD,YAAM,UAAU,IAAI,QAAQ,SAAS,OAAO;AAC5C,cAAQ,IAAI,+BAA+B,GAAG;AAC9C,aAAO,IAAI,SAAS,OAAO,KAAK,SAAS,IAAI,GAAG;AAAA,QAC/C,QAAQ,SAAS;AAAA,QACjB,YAAY,SAAS;AAAA,QACrB;AAAA,MACD,CAAC;AAAA,IACF;AAAA,EACD,CAAQ;AAWT;;;ADzrCA,IAAM,wCAAwC,MAAM,OAAO;AAMpD,IAAM,SAA+B,CAC3C,UAEA,cAAc;AAAA,EACb,GAAG;AAAA,EACH,wBAAwB;AAAA,EACxB,wBAAwB;AAAA,EACxB,sBAAsB;AACvB,CAAwC;","names":["event","response"]}
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@rivetkit/react';
|
package/dist/react.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/react.ts"],"sourcesContent":["/**\n * `@rivet-dev/agentos/react` — Agent OS React bindings.\n *\n * Re-exports `@rivetkit/react` (`createRivetKit`, `createRivetKitWithClient`,\n * and the hooks). Kept on its own subpath so neither React nor the client\n * bundle is pulled into server code that imports the root module.\n */\n\nexport * from \"@rivetkit/react\";\n"],"mappings":";AAQA,cAAc;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,50 +1,103 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rivet-dev/agentos",
|
|
3
|
-
"version": "0.0.0-
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.0-main.29b0797",
|
|
4
|
+
"description": "A native TypeScript RivetKit actor backed by the AgentOS core SDK and sidecar.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
"keywords": [
|
|
7
|
+
"rivetkit",
|
|
8
|
+
"agent-os",
|
|
9
|
+
"agentos",
|
|
10
|
+
"agents",
|
|
11
|
+
"actors",
|
|
12
|
+
"ai"
|
|
13
|
+
],
|
|
14
|
+
"sideEffects": false,
|
|
14
15
|
"files": [
|
|
15
16
|
"dist",
|
|
17
|
+
"assets",
|
|
18
|
+
"package.json",
|
|
16
19
|
"README.md"
|
|
17
20
|
],
|
|
21
|
+
"type": "module",
|
|
18
22
|
"exports": {
|
|
19
23
|
".": {
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
"import": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"default": "./dist/index.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"./client": {
|
|
30
|
+
"import": {
|
|
31
|
+
"browser": {
|
|
32
|
+
"types": "./dist/client.d.ts",
|
|
33
|
+
"default": "./dist/client.js"
|
|
34
|
+
},
|
|
35
|
+
"types": "./dist/client.d.ts",
|
|
36
|
+
"default": "./dist/client.js"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"./react": {
|
|
40
|
+
"import": {
|
|
41
|
+
"types": "./dist/react.d.ts",
|
|
42
|
+
"default": "./dist/react.js"
|
|
43
|
+
}
|
|
23
44
|
}
|
|
24
45
|
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=22.0.0"
|
|
48
|
+
},
|
|
25
49
|
"scripts": {
|
|
50
|
+
"build": "pnpm build:actor && pnpm build:tabs",
|
|
51
|
+
"build:actor": "tsup src/index.ts src/client.ts src/react.ts",
|
|
52
|
+
"build:tabs": "vite build --config vite.tabs.config.ts",
|
|
26
53
|
"check-types": "tsc --noEmit",
|
|
27
|
-
"
|
|
28
|
-
"test": "vitest run"
|
|
54
|
+
"test": "vitest run --exclude '**/*.nightly.test.ts'",
|
|
55
|
+
"test:pr": "AGENTOS_ACTOR_E2E=1 vitest run tests/agent-os-conformance.e2e.test.ts --fileParallelism=false",
|
|
56
|
+
"test:nightly": "AGENTOS_ACTOR_E2E=1 vitest run tests/*.nightly.test.ts tests/agent-os-conformance.e2e.test.ts --fileParallelism=false --passWithNoTests",
|
|
57
|
+
"test:e2e": "cargo build --manifest-path ../../Cargo.toml -p agentos-sidecar && pnpm --filter @rivet-dev/agentos-runtime-core build && pnpm --filter @agentos-software/manifest build && pnpm --filter @agentos-software/common... build && pnpm --filter @agentos-software/coreutils build:runtime && pnpm --filter @rivet-dev/agentos-test-harness build && pnpm --filter @rivet-dev/agentos-core build && pnpm build && pnpm test:e2e:run",
|
|
58
|
+
"test:e2e:run": "AGENTOS_ACTOR_E2E=1 vitest run tests/actor-lifecycle.nightly.test.ts tests/agent-os-conformance.e2e.test.ts --fileParallelism=false"
|
|
29
59
|
},
|
|
30
60
|
"dependencies": {
|
|
31
|
-
"@
|
|
32
|
-
"@
|
|
33
|
-
"@rivet-dev/agentos-
|
|
61
|
+
"@agentclientprotocol/sdk": "0.16.1",
|
|
62
|
+
"@agentos-software/common": "0.0.0-main.29b0797",
|
|
63
|
+
"@rivet-dev/agentos-core": "0.0.0-main.29b0797",
|
|
64
|
+
"@rivetkit/react": "0.0.0-sqlite-uds.4e59a38",
|
|
65
|
+
"rivetkit": "0.0.0-sqlite-uds.4e59a38",
|
|
34
66
|
"zod": "^4.1.11"
|
|
35
67
|
},
|
|
36
68
|
"peerDependencies": {
|
|
37
|
-
"
|
|
69
|
+
"react": "^18 || ^19",
|
|
70
|
+
"react-dom": "^18 || ^19"
|
|
71
|
+
},
|
|
72
|
+
"peerDependenciesMeta": {
|
|
73
|
+
"react": {
|
|
74
|
+
"optional": true
|
|
75
|
+
},
|
|
76
|
+
"react-dom": {
|
|
77
|
+
"optional": true
|
|
78
|
+
}
|
|
38
79
|
},
|
|
39
80
|
"devDependencies": {
|
|
81
|
+
"@agentos-software/coreutils": "0.3.3",
|
|
82
|
+
"@rivet-dev/agentos-test-harness": "0.0.0-main.29b0797",
|
|
83
|
+
"@radix-ui/react-collapsible": "^1.1.2",
|
|
84
|
+
"@radix-ui/react-scroll-area": "^1.2.2",
|
|
85
|
+
"@tanstack/react-query": "^5.87.1",
|
|
40
86
|
"@types/node": "^22.19.15",
|
|
41
|
-
"
|
|
87
|
+
"@types/react": "^19.0.0",
|
|
88
|
+
"@types/react-dom": "^19.0.0",
|
|
89
|
+
"@vitejs/plugin-react": "^4.3.4",
|
|
90
|
+
"autoprefixer": "^10.4.20",
|
|
91
|
+
"class-variance-authority": "^0.7.1",
|
|
92
|
+
"clsx": "^2.1.1",
|
|
93
|
+
"postcss": "^8.4.49",
|
|
94
|
+
"react": "^19.0.0",
|
|
95
|
+
"react-dom": "^19.0.0",
|
|
96
|
+
"tailwind-merge": "^2.6.0",
|
|
97
|
+
"tailwindcss": "^3.4.17",
|
|
98
|
+
"tsup": "^8.4.0",
|
|
99
|
+
"typescript": "^5.7.3",
|
|
100
|
+
"vite": "^5.4.20",
|
|
42
101
|
"vitest": "^2.1.8"
|
|
43
|
-
},
|
|
44
|
-
"engines": {
|
|
45
|
-
"node": ">=20"
|
|
46
|
-
},
|
|
47
|
-
"optionalDependencies": {
|
|
48
|
-
"@rivet-dev/agentos-plugin-linux-x64-gnu": "0.0.0-integrate-dylib-into-main.815fcda"
|
|
49
102
|
}
|
|
50
103
|
}
|
package/dist/actor.d.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Rust-backed `agentOs(...)` definition.
|
|
3
|
-
*
|
|
4
|
-
* Produces an `ActorDefinition` whose `nativeFactoryBuilder` constructs a
|
|
5
|
-
* native-actor-plugin factory through `runtime.createNativePluginFactory(...)`
|
|
6
|
-
* (NAPI → `dlopen` of the agent-os actor plugin cdylib, the inverse of the
|
|
7
|
-
* generic host loader). All lifecycle, state, and action dispatch live in the
|
|
8
|
-
* Rust plugin (`crates/agentos-actor-plugin`). This JS shim only validates
|
|
9
|
-
* configuration, resolves the plugin + sidecar binaries, and hands the opaque
|
|
10
|
-
* config envelope across the bridge — it owns no agent-os runtime logic.
|
|
11
|
-
*/
|
|
12
|
-
import { type ActorDefinition, type DatabaseProvider, type RawAccess } from "rivetkit";
|
|
13
|
-
import { type AgentOsActorConfig, type AgentOsActorConfigInput } from "./config.js";
|
|
14
|
-
import type { AgentOsActorState, AgentOsActorVars } from "./types.js";
|
|
15
|
-
/**
|
|
16
|
-
* A native `host_dir` mount of a host `node_modules` directory at
|
|
17
|
-
* `/root/node_modules`, the serializable form `agentOs({ options: { mounts } })`
|
|
18
|
-
* accepts across the NAPI boundary.
|
|
19
|
-
*/
|
|
20
|
-
export interface NodeModulesMountConfig {
|
|
21
|
-
path: "/root/node_modules";
|
|
22
|
-
plugin: {
|
|
23
|
-
id: "host_dir";
|
|
24
|
-
config: {
|
|
25
|
-
hostPath: string;
|
|
26
|
-
readOnly: boolean;
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
readOnly: boolean;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Mount a host `node_modules` directory into the VM at `/root/node_modules`.
|
|
33
|
-
*
|
|
34
|
-
* This is the explicit, mount-based replacement for the removed `moduleAccessCwd`
|
|
35
|
-
* mechanism: the VM module resolver reads the mounted tree through the kernel
|
|
36
|
-
* VFS, so the caller supplies exactly the `node_modules` directory whose
|
|
37
|
-
* packages should resolve in the guest.
|
|
38
|
-
*
|
|
39
|
-
* @param hostNodeModulesDir Absolute host path to a `node_modules` directory.
|
|
40
|
-
* @param opts.readOnly Defaults to `true`; the mount is read-only.
|
|
41
|
-
*/
|
|
42
|
-
export declare function nodeModulesMount(hostNodeModulesDir: string, opts?: {
|
|
43
|
-
readOnly?: boolean;
|
|
44
|
-
}): NodeModulesMountConfig;
|
|
45
|
-
export declare function buildConfigJson<TConnParams>(parsed: AgentOsActorConfig<TConnParams>): string;
|
|
46
|
-
/**
|
|
47
|
-
* Type alias for the `agentOs(...)` return type. Events are not typed at the
|
|
48
|
-
* TS surface because the Rust plugin owns the broadcast set and the
|
|
49
|
-
* test/client surface uses `any` for actions.
|
|
50
|
-
*/
|
|
51
|
-
export type AgentOsActorDefinition<TConnParams> = ActorDefinition<AgentOsActorState, TConnParams, undefined, AgentOsActorVars, undefined, DatabaseProvider<RawAccess>, Record<never, never>, Record<never, never>, any>;
|
|
52
|
-
export declare function agentOs<TConnParams = undefined>(config: AgentOsActorConfigInput<TConnParams>): AgentOsActorDefinition<TConnParams>;
|
package/dist/actor.js
DELETED
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Rust-backed `agentOs(...)` definition.
|
|
3
|
-
*
|
|
4
|
-
* Produces an `ActorDefinition` whose `nativeFactoryBuilder` constructs a
|
|
5
|
-
* native-actor-plugin factory through `runtime.createNativePluginFactory(...)`
|
|
6
|
-
* (NAPI → `dlopen` of the agent-os actor plugin cdylib, the inverse of the
|
|
7
|
-
* generic host loader). All lifecycle, state, and action dispatch live in the
|
|
8
|
-
* Rust plugin (`crates/agentos-actor-plugin`). This JS shim only validates
|
|
9
|
-
* configuration, resolves the plugin + sidecar binaries, and hands the opaque
|
|
10
|
-
* config envelope across the bridge — it owns no agent-os runtime logic.
|
|
11
|
-
*/
|
|
12
|
-
import { sep } from "node:path";
|
|
13
|
-
import common from "@agentos-software/common";
|
|
14
|
-
import { getSidecarPath } from "@rivet-dev/agentos-sidecar";
|
|
15
|
-
import { actor, } from "rivetkit";
|
|
16
|
-
import { agentOsActorConfigSchema, } from "./config.js";
|
|
17
|
-
import { getPluginPath } from "./plugin-binary.js";
|
|
18
|
-
/**
|
|
19
|
-
* Mount a host `node_modules` directory into the VM at `/root/node_modules`.
|
|
20
|
-
*
|
|
21
|
-
* This is the explicit, mount-based replacement for the removed `moduleAccessCwd`
|
|
22
|
-
* mechanism: the VM module resolver reads the mounted tree through the kernel
|
|
23
|
-
* VFS, so the caller supplies exactly the `node_modules` directory whose
|
|
24
|
-
* packages should resolve in the guest.
|
|
25
|
-
*
|
|
26
|
-
* @param hostNodeModulesDir Absolute host path to a `node_modules` directory.
|
|
27
|
-
* @param opts.readOnly Defaults to `true`; the mount is read-only.
|
|
28
|
-
*/
|
|
29
|
-
export function nodeModulesMount(hostNodeModulesDir, opts) {
|
|
30
|
-
const readOnly = opts?.readOnly ?? true;
|
|
31
|
-
return {
|
|
32
|
-
path: "/root/node_modules",
|
|
33
|
-
plugin: {
|
|
34
|
-
id: "host_dir",
|
|
35
|
-
config: { hostPath: hostNodeModulesDir, readOnly },
|
|
36
|
-
},
|
|
37
|
-
readOnly,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Derive the `node_modules` root that contains an installed package directory.
|
|
42
|
-
* For an agent descriptor whose `packageDir` is `<root>/node_modules/@scope/pkg`,
|
|
43
|
-
* this returns `<root>/node_modules` — the hoist root that also holds the agent's
|
|
44
|
-
* `requires` (the ACP adapter + agent SDK) and their transitive deps under a
|
|
45
|
-
* flat (npm) install. Returns `undefined` when `packageDir` is not inside a
|
|
46
|
-
* `node_modules` tree (e.g. a linked monorepo checkout), where the caller must
|
|
47
|
-
* supply an explicit `nodeModulesMount(...)`.
|
|
48
|
-
*/
|
|
49
|
-
function nodeModulesRootOf(packageDir) {
|
|
50
|
-
const parts = packageDir.split(sep);
|
|
51
|
-
const idx = parts.lastIndexOf("node_modules");
|
|
52
|
-
if (idx === -1)
|
|
53
|
-
return undefined;
|
|
54
|
-
return parts.slice(0, idx + 1).join(sep);
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Agents run their ACP adapter + SDK inside the VM from `/root/node_modules`.
|
|
58
|
-
* Rather than make the caller hand-write `nodeModulesMount(...)`, auto-derive a
|
|
59
|
-
* read-only `host_dir` mount of the `node_modules` root that holds the agent
|
|
60
|
-
* packages (`requires`) from each agent descriptor's installed `packageDir`.
|
|
61
|
-
*
|
|
62
|
-
* An explicit `/root/node_modules` mount in `options.mounts` always wins. If
|
|
63
|
-
* agents resolve to more than one distinct `node_modules` root the derivation is
|
|
64
|
-
* ambiguous and the caller must mount explicitly.
|
|
65
|
-
*/
|
|
66
|
-
function withAutoAgentNodeModulesMount(mounts, descriptors) {
|
|
67
|
-
if (mounts?.some((mount) => mount.path === "/root/node_modules")) {
|
|
68
|
-
return mounts;
|
|
69
|
-
}
|
|
70
|
-
const roots = new Set();
|
|
71
|
-
for (const d of descriptors) {
|
|
72
|
-
if (!d.agent || typeof d.packageDir !== "string")
|
|
73
|
-
continue;
|
|
74
|
-
const root = nodeModulesRootOf(d.packageDir);
|
|
75
|
-
if (root)
|
|
76
|
-
roots.add(root);
|
|
77
|
-
}
|
|
78
|
-
if (roots.size === 0)
|
|
79
|
-
return mounts;
|
|
80
|
-
if (roots.size > 1) {
|
|
81
|
-
throw new Error("agentOs() could not auto-mount agent node_modules: agents resolved to " +
|
|
82
|
-
`multiple node_modules roots (${[...roots].join(", ")}). Pass an ` +
|
|
83
|
-
"explicit nodeModulesMount(...) in options.mounts.");
|
|
84
|
-
}
|
|
85
|
-
const [hostNodeModulesDir] = [...roots];
|
|
86
|
-
return [...(mounts ?? []), nodeModulesMount(hostNodeModulesDir)];
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Stable identity for a software descriptor, used to de-duplicate the
|
|
90
|
-
* auto-injected default bundle against software the caller passed explicitly.
|
|
91
|
-
* Resolved `commandDir`/`packageDir` paths are the most reliable key; `name`
|
|
92
|
-
* is the fallback for descriptors without a directory.
|
|
93
|
-
*/
|
|
94
|
-
function softwareIdentity(d) {
|
|
95
|
-
if (typeof d.commandDir === "string")
|
|
96
|
-
return `dir:${d.commandDir}`;
|
|
97
|
-
if (typeof d.packageDir === "string")
|
|
98
|
-
return `dir:${d.packageDir}`;
|
|
99
|
-
const name = d.name;
|
|
100
|
-
if (typeof name === "string")
|
|
101
|
-
return `name:${name}`;
|
|
102
|
-
return JSON.stringify(d);
|
|
103
|
-
}
|
|
104
|
-
function flattenSoftware(input, out) {
|
|
105
|
-
if (input == null)
|
|
106
|
-
return;
|
|
107
|
-
if (Array.isArray(input)) {
|
|
108
|
-
for (const item of input)
|
|
109
|
-
flattenSoftware(item, out);
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
if (typeof input === "object")
|
|
113
|
-
out.push(input);
|
|
114
|
-
}
|
|
115
|
-
export function buildConfigJson(parsed) {
|
|
116
|
-
const descriptors = [];
|
|
117
|
-
flattenSoftware(parsed.options?.software, descriptors);
|
|
118
|
-
// Auto-include the default software bundle (`@agentos-software/common`: `sh` +
|
|
119
|
-
// coreutils + the standard CLI tools agents rely on) unless the caller opted
|
|
120
|
-
// out with `defaultSoftware: false`. Anything already listed in `software`
|
|
121
|
-
// (e.g. an explicit `common`) is not duplicated. Prepended so the baseline
|
|
122
|
-
// tools come first, matching the previous explicit `[common, ...]` ordering.
|
|
123
|
-
const defaultSoftwareEnabled = parsed.options?.defaultSoftware !== false;
|
|
124
|
-
if (defaultSoftwareEnabled) {
|
|
125
|
-
const defaults = [];
|
|
126
|
-
flattenSoftware(common, defaults);
|
|
127
|
-
const seen = new Set(descriptors.map(softwareIdentity));
|
|
128
|
-
const toPrepend = defaults.filter((d) => !seen.has(softwareIdentity(d)));
|
|
129
|
-
descriptors.unshift(...toPrepend);
|
|
130
|
-
}
|
|
131
|
-
const software = [];
|
|
132
|
-
for (const d of descriptors) {
|
|
133
|
-
if (typeof d.commandDir === "string") {
|
|
134
|
-
// Wasm command directory (kind defaults to WasmCommands on the Rust side).
|
|
135
|
-
software.push({ package: d.commandDir });
|
|
136
|
-
}
|
|
137
|
-
else if (typeof d.packageDir === "string") {
|
|
138
|
-
// Agent SDK / host-tool package: forwarded but not mounted as commands.
|
|
139
|
-
// `kind` matches the kebab-case serde tags of the Rust `SoftwareKind`
|
|
140
|
-
// enum (`wasm-commands` / `agent` / `tool`).
|
|
141
|
-
software.push({
|
|
142
|
-
package: d.packageDir,
|
|
143
|
-
kind: d.hostTool || d.toolkit ? "tool" : "agent",
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
// `/root/node_modules` (agent ACP adapter + SDK + transitive dep resolution)
|
|
148
|
-
// is auto-derived from the agent descriptors so the standard quickstart needs
|
|
149
|
-
// no manual `nodeModulesMount(...)`: see `withAutoAgentNodeModulesMount`. An
|
|
150
|
-
// explicit `/root/node_modules` mount in `options.mounts` always wins. The VM
|
|
151
|
-
// module resolver reads the mounted tree through the kernel VFS.
|
|
152
|
-
const options = (parsed.options ?? {});
|
|
153
|
-
const mounts = withAutoAgentNodeModulesMount(serializeNativeMounts(options.mounts), descriptors);
|
|
154
|
-
const sidecar = serializeSidecar(options.sidecar);
|
|
155
|
-
return JSON.stringify({
|
|
156
|
-
software,
|
|
157
|
-
additionalInstructions: options.additionalInstructions,
|
|
158
|
-
loopbackExemptPorts: options.loopbackExemptPorts,
|
|
159
|
-
allowedNodeBuiltins: options.allowedNodeBuiltins,
|
|
160
|
-
permissions: options.permissions,
|
|
161
|
-
rootFilesystem: options.rootFilesystem,
|
|
162
|
-
mounts,
|
|
163
|
-
limits: options.limits,
|
|
164
|
-
sidecar,
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
function serializeNativeMounts(input) {
|
|
168
|
-
if (input == null)
|
|
169
|
-
return undefined;
|
|
170
|
-
if (!Array.isArray(input)) {
|
|
171
|
-
throw new Error("agentOs() options.mounts must be an array");
|
|
172
|
-
}
|
|
173
|
-
return input.map((mount, index) => {
|
|
174
|
-
if (!mount || typeof mount !== "object") {
|
|
175
|
-
throw new Error(`agentOs() options.mounts[${index}] must be an object`);
|
|
176
|
-
}
|
|
177
|
-
const record = mount;
|
|
178
|
-
if (record.driver !== undefined) {
|
|
179
|
-
throw new Error("agentOs() only supports Native mounts across the NAPI boundary; Plain mounts with driver callbacks are not serializable");
|
|
180
|
-
}
|
|
181
|
-
if (record.filesystem !== undefined) {
|
|
182
|
-
throw new Error("agentOs() only supports Native mounts across the NAPI boundary; Overlay mounts are not serializable");
|
|
183
|
-
}
|
|
184
|
-
const plugin = record.plugin;
|
|
185
|
-
if (typeof record.path !== "string" ||
|
|
186
|
-
!plugin ||
|
|
187
|
-
typeof plugin !== "object" ||
|
|
188
|
-
typeof plugin.id !== "string") {
|
|
189
|
-
throw new Error(`agentOs() options.mounts[${index}] must be a Native mount with { path, plugin: { id, config? } }`);
|
|
190
|
-
}
|
|
191
|
-
return {
|
|
192
|
-
path: record.path,
|
|
193
|
-
plugin: {
|
|
194
|
-
id: plugin.id,
|
|
195
|
-
config: plugin.config,
|
|
196
|
-
},
|
|
197
|
-
readOnly: typeof record.readOnly === "boolean" ? record.readOnly : undefined,
|
|
198
|
-
};
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
function serializeSidecar(input) {
|
|
202
|
-
if (input == null)
|
|
203
|
-
return undefined;
|
|
204
|
-
if (!input || typeof input !== "object") {
|
|
205
|
-
throw new Error("agentOs() options.sidecar must be an object");
|
|
206
|
-
}
|
|
207
|
-
const record = input;
|
|
208
|
-
if (record.kind === "explicit" || record.handle !== undefined) {
|
|
209
|
-
throw new Error("agentOs() only supports sidecar shared pool configuration across the NAPI boundary; explicit sidecar handles are not serializable");
|
|
210
|
-
}
|
|
211
|
-
if (record.kind !== undefined && record.kind !== "shared") {
|
|
212
|
-
throw new Error('agentOs() options.sidecar.kind must be "shared"');
|
|
213
|
-
}
|
|
214
|
-
return typeof record.pool === "string" ? { pool: record.pool } : {};
|
|
215
|
-
}
|
|
216
|
-
function buildNativeFactoryBuilder(parsed) {
|
|
217
|
-
return (runtime) => {
|
|
218
|
-
if (runtime.kind !== "napi") {
|
|
219
|
-
throw new Error(`agentOs() is only supported on the native NAPI runtime (current runtime kind: ${runtime.kind})`);
|
|
220
|
-
}
|
|
221
|
-
if (!runtime.createNativePluginFactory) {
|
|
222
|
-
throw new Error("runtime.createNativePluginFactory is not implemented on the active CoreRuntime");
|
|
223
|
-
}
|
|
224
|
-
const options = {
|
|
225
|
-
// Resolve the prebuilt agent-os actor plugin cdylib; RivetKit `dlopen`s
|
|
226
|
-
// it through the generic native-plugin ABI.
|
|
227
|
-
pluginPath: getPluginPath(),
|
|
228
|
-
// Opaque config envelope the plugin parses (config.rs::AgentOsConfigJson).
|
|
229
|
-
configJson: buildConfigJson(parsed),
|
|
230
|
-
// Resolve the prebuilt sidecar binary from the npm package so the plugin
|
|
231
|
-
// spawns the bundled binary rather than relying on `agentos-sidecar`
|
|
232
|
-
// being on PATH.
|
|
233
|
-
sidecarPath: getSidecarPath(),
|
|
234
|
-
};
|
|
235
|
-
return runtime.createNativePluginFactory(options);
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
export function agentOs(config) {
|
|
239
|
-
const parsed = agentOsActorConfigSchema.parse(config);
|
|
240
|
-
// Construct a minimal definition through the existing actor() helper, then
|
|
241
|
-
// attach the Rust factory builder marker. The actions block stays empty
|
|
242
|
-
// because no JS-side action ever runs: the engine driver branches on
|
|
243
|
-
// `nativeFactoryBuilder` before reaching the JS dispatch path.
|
|
244
|
-
const actorOptions = parsed
|
|
245
|
-
.actorOptions;
|
|
246
|
-
const definition = actor({
|
|
247
|
-
actions: {},
|
|
248
|
-
...(actorOptions ? { options: actorOptions } : {}),
|
|
249
|
-
});
|
|
250
|
-
definition.nativeFactoryBuilder = buildNativeFactoryBuilder(parsed);
|
|
251
|
-
return definition;
|
|
252
|
-
}
|
package/dist/config.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { AgentOsOptions, JsonRpcNotification, PermissionRequest } from "@rivet-dev/agentos-core";
|
|
2
|
-
import type { ActorContext, BeforeConnectContext } from "rivetkit";
|
|
3
|
-
import { z } from "zod/v4";
|
|
4
|
-
import type { AgentOsActorState, AgentOsActorVars } from "./types.js";
|
|
5
|
-
export declare const agentOsActorConfigSchema: z.ZodObject<{
|
|
6
|
-
options: z.ZodOptional<z.ZodCustom<AgentOsOptions, AgentOsOptions>>;
|
|
7
|
-
preview: z.ZodPrefault<z.ZodObject<{
|
|
8
|
-
defaultExpiresInSeconds: z.ZodDefault<z.ZodNumber>;
|
|
9
|
-
maxExpiresInSeconds: z.ZodDefault<z.ZodNumber>;
|
|
10
|
-
}, z.core.$strict>>;
|
|
11
|
-
onBeforeConnect: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
12
|
-
onSessionEvent: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
13
|
-
onPermissionRequest: z.ZodOptional<z.ZodCustom<(...args: unknown[]) => unknown, (...args: unknown[]) => unknown>>;
|
|
14
|
-
}, z.core.$strict>;
|
|
15
|
-
type AgentOsActorContext<TConnParams> = ActorContext<AgentOsActorState, TConnParams, undefined, AgentOsActorVars, undefined, any>;
|
|
16
|
-
interface AgentOsActorConfigCallbacks<TConnParams> {
|
|
17
|
-
onBeforeConnect?: (c: BeforeConnectContext<AgentOsActorState, AgentOsActorVars, undefined, any>, params: TConnParams) => void | Promise<void>;
|
|
18
|
-
onSessionEvent?: (c: AgentOsActorContext<TConnParams>, sessionId: string, event: JsonRpcNotification) => void | Promise<void>;
|
|
19
|
-
onPermissionRequest?: (c: AgentOsActorContext<TConnParams>, sessionId: string, request: PermissionRequest) => void | Promise<void>;
|
|
20
|
-
}
|
|
21
|
-
export type AgentOsActorConfig<TConnParams = undefined> = Omit<z.infer<typeof agentOsActorConfigSchema>, "onBeforeConnect" | "onSessionEvent" | "onPermissionRequest"> & AgentOsActorConfigCallbacks<TConnParams>;
|
|
22
|
-
export type AgentOsActorConfigInput<TConnParams = undefined> = Omit<z.input<typeof agentOsActorConfigSchema>, "onBeforeConnect" | "onSessionEvent" | "onPermissionRequest"> & AgentOsActorConfigCallbacks<TConnParams>;
|
|
23
|
-
export {};
|
package/dist/config.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { z } from "zod/v4";
|
|
2
|
-
const zFunction = () => z.custom((val) => typeof val === "function");
|
|
3
|
-
const AgentOsOptionsSchema = z.custom((val) => typeof val === "object" && val !== null);
|
|
4
|
-
export const agentOsActorConfigSchema = z
|
|
5
|
-
.object({
|
|
6
|
-
options: AgentOsOptionsSchema.optional(),
|
|
7
|
-
preview: z
|
|
8
|
-
.object({
|
|
9
|
-
defaultExpiresInSeconds: z.number().positive().default(3600),
|
|
10
|
-
maxExpiresInSeconds: z.number().positive().default(86400),
|
|
11
|
-
})
|
|
12
|
-
.strict()
|
|
13
|
-
.prefault(() => ({})),
|
|
14
|
-
onBeforeConnect: zFunction().optional(),
|
|
15
|
-
onSessionEvent: zFunction().optional(),
|
|
16
|
-
onPermissionRequest: zFunction().optional(),
|
|
17
|
-
})
|
|
18
|
-
.strict();
|