@opengeni/db 3.7.4 → 4.0.0-canary.0

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 (113) hide show
  1. package/dist/automations.d.ts +4 -0
  2. package/dist/canonical-human-identities.js +3 -3
  3. package/dist/capability-integrations.d.ts +2 -0
  4. package/dist/{chunk-6DPJA36C.js → chunk-2XEZK4LF.js} +7 -1
  5. package/dist/chunk-2XEZK4LF.js.map +1 -0
  6. package/dist/{chunk-4NAR7FBA.js → chunk-3RI33YQN.js} +67 -1
  7. package/dist/chunk-3RI33YQN.js.map +1 -0
  8. package/dist/{chunk-SZAWDXQC.js → chunk-CJROYHSC.js} +3 -3
  9. package/dist/{chunk-DZCYW2WT.js → chunk-MX6V5F65.js} +2 -2
  10. package/dist/{chunk-S3TDDCS2.js → chunk-N5VXJ4I2.js} +151 -78
  11. package/dist/chunk-N5VXJ4I2.js.map +1 -0
  12. package/dist/{chunk-U4WPPEBH.js → chunk-NLFHMPUB.js} +2 -2
  13. package/dist/{chunk-5NNCGFQY.js → chunk-P6NSEG2S.js} +2 -2
  14. package/dist/{chunk-O56DM5GZ.js → chunk-QM6YOWHZ.js} +624 -57
  15. package/dist/chunk-QM6YOWHZ.js.map +1 -0
  16. package/dist/{chunk-US4IS6IV.js → chunk-RZNOSEMC.js} +2 -2
  17. package/dist/{chunk-F6PBS6WE.js → chunk-UFAMOUWL.js} +2 -2
  18. package/dist/codemode-operations.d.ts +5 -0
  19. package/dist/codex-token-resolver.d.ts +6 -2
  20. package/dist/connection-token-resolver.d.ts +8 -0
  21. package/dist/editable-artifact-durable-export.js +2 -2
  22. package/dist/editable-artifacts.js +3 -3
  23. package/dist/generated-images.d.ts +15 -0
  24. package/dist/index.d.ts +393 -91
  25. package/dist/index.js +9992 -6069
  26. package/dist/index.js.map +1 -1
  27. package/dist/insights.d.ts +9 -0
  28. package/dist/managed-auth-session-sets.js +3 -3
  29. package/dist/managed-user-setup.d.ts +3 -0
  30. package/dist/mcp-oauth.d.ts +80 -0
  31. package/dist/migrate.d.ts +1 -0
  32. package/dist/migrate.js +3 -1
  33. package/dist/model-catalog.d.ts +153 -0
  34. package/dist/model-context-snapshots.d.ts +20 -0
  35. package/dist/new-session-drafts.d.ts +12 -0
  36. package/dist/organization-membership-lifecycle.d.ts +8 -1
  37. package/dist/organization-model-providers.d.ts +101 -0
  38. package/dist/pack-components.d.ts +1 -0
  39. package/dist/pr-review.d.ts +9 -0
  40. package/dist/provision-roles.js +1 -1
  41. package/dist/runtime-posture.d.ts +8 -8
  42. package/dist/schema.d.ts +7708 -5050
  43. package/dist/schema.js +25 -1
  44. package/dist/session-background-commands.d.ts +18 -6
  45. package/dist/session-background-commands.js +15 -9
  46. package/dist/session-control.d.ts +37 -2
  47. package/dist/session-goal-pacing.d.ts +3 -6
  48. package/dist/session-queue-commands.d.ts +17 -0
  49. package/dist/session-tenancy.js +3 -3
  50. package/dist/tool-gateway-approvals.d.ts +31 -0
  51. package/dist/video-generation.js +3 -3
  52. package/dist/workspace-artifacts.d.ts +17 -3
  53. package/dist/xai-subscription.d.ts +8 -0
  54. package/drizzle/0387_bound_host_export_session_payloads.sql +165 -0
  55. package/drizzle/0388_sandbox_provider_deadline_interactions.sql +491 -0
  56. package/drizzle/0389_model_catalog_and_gateway_custom_models.sql +241 -0
  57. package/drizzle/0390_organization_model_provider_connections.sql +197 -0
  58. package/drizzle/0391_sandbox_provider_deadline_interaction_followup.sql +295 -0
  59. package/drizzle/0392_context_compaction_pending_observability.sql +198 -0
  60. package/drizzle/0393_workspace_memory_and_learning_defaults.sql +102 -0
  61. package/drizzle/0394_session_selected_skill_activation.sql +20 -0
  62. package/drizzle/0395_scheduled_task_unclaimed_occurrence_invalidation.sql +154 -0
  63. package/drizzle/0396_model_call_equivalent_credit_cost.sql +28 -0
  64. package/drizzle/0397_sandbox_deadline_rotation_preemption.sql +113 -0
  65. package/drizzle/0398_organization_workspace_management_entry.sql +206 -0
  66. package/drizzle/0399_additional_managed_organization_creation.sql +691 -0
  67. package/drizzle/0400_session_attempt_model_context_snapshots.sql +65 -0
  68. package/drizzle/0401_organization_user_setup_token_transport.sql +178 -0
  69. package/drizzle/0402_session_input_wait_and_background_command_results.sql +1023 -0
  70. package/drizzle/0403_codex_unconditional_credential_leasing.sql +181 -0
  71. package/drizzle/0404_mcp_oauth_authorization_server.sql +471 -0
  72. package/drizzle/0405_tool_gateway_approval_capabilities.sql +184 -0
  73. package/drizzle/0406_workspace_html_site_sources.sql +71 -0
  74. package/package.json +6 -6
  75. package/src/automations.ts +9 -1
  76. package/src/capability-integrations.ts +8 -0
  77. package/src/codemode-operations.ts +31 -21
  78. package/src/codex-token-resolver.ts +16 -6
  79. package/src/connection-token-resolver.ts +52 -3
  80. package/src/generated-images.ts +70 -6
  81. package/src/index.ts +3894 -994
  82. package/src/insights-model-bundle.ts +54 -5
  83. package/src/insights.ts +53 -7
  84. package/src/managed-user-setup.ts +14 -3
  85. package/src/mcp-oauth.ts +488 -0
  86. package/src/migrate.ts +9 -1
  87. package/src/model-catalog.ts +682 -0
  88. package/src/model-context-snapshots.ts +151 -0
  89. package/src/new-session-drafts.ts +66 -21
  90. package/src/organization-membership-lifecycle.ts +47 -5
  91. package/src/organization-model-providers.ts +614 -0
  92. package/src/pack-components.ts +15 -2
  93. package/src/pr-review.ts +19 -0
  94. package/src/provision-roles.ts +4 -0
  95. package/src/runtime-posture.ts +64 -0
  96. package/src/schema.ts +666 -61
  97. package/src/session-background-commands.ts +180 -78
  98. package/src/session-control.ts +181 -12
  99. package/src/session-goal-pacing.ts +4 -8
  100. package/src/session-queue-commands.ts +157 -82
  101. package/src/tool-gateway-approvals.ts +168 -0
  102. package/src/workspace-artifacts.ts +633 -178
  103. package/src/xai-subscription.ts +66 -14
  104. package/dist/chunk-4NAR7FBA.js.map +0 -1
  105. package/dist/chunk-6DPJA36C.js.map +0 -1
  106. package/dist/chunk-O56DM5GZ.js.map +0 -1
  107. package/dist/chunk-S3TDDCS2.js.map +0 -1
  108. /package/dist/{chunk-SZAWDXQC.js.map → chunk-CJROYHSC.js.map} +0 -0
  109. /package/dist/{chunk-DZCYW2WT.js.map → chunk-MX6V5F65.js.map} +0 -0
  110. /package/dist/{chunk-U4WPPEBH.js.map → chunk-NLFHMPUB.js.map} +0 -0
  111. /package/dist/{chunk-5NNCGFQY.js.map → chunk-P6NSEG2S.js.map} +0 -0
  112. /package/dist/{chunk-US4IS6IV.js.map → chunk-RZNOSEMC.js.map} +0 -0
  113. /package/dist/{chunk-F6PBS6WE.js.map → chunk-UFAMOUWL.js.map} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/session-background-commands.ts"],"sourcesContent":["import type {\n SessionBackgroundCommand,\n SessionBackgroundCommandActivity,\n} from \"@opengeni/contracts\";\nimport { and, desc, eq, inArray, sql } from \"drizzle-orm\";\n\nimport type { Database } from \"./database\";\nimport { withRlsContext } from \"./database\";\nimport * as schema from \"./schema\";\n\nexport type ConnectedMachineBackgroundCommandProof = {\n outcome: \"exited\" | \"lost\";\n exitCode: number | null;\n reason: string;\n observedAt: Date;\n};\n\nexport type ConnectedMachineBackgroundCommandClaim = {\n commandId: string;\n accountId: string;\n workspaceId: string;\n sessionId: string;\n claimId: string;\n state: \"running\" | \"stopping\";\n controlWorkspaceId: string;\n enrollmentId: string;\n connectionInstanceId: string;\n opId: string;\n reconcileAttempts: number;\n proof: ConnectedMachineBackgroundCommandProof | null;\n};\n\ntype ConnectedMachineBackgroundCommandClaimRow = {\n accountId: string;\n workspaceId: string;\n sessionId: string;\n commandId: string;\n claimId: string;\n commandState: string;\n controlWorkspaceId: string;\n enrollmentId: string;\n connectionInstanceId: string;\n opId: string;\n reconcileAttempts: number | string;\n reconcileProofOutcome: string | null;\n reconcileProofExitCode: number | string | null;\n reconcileProofReason: string | null;\n reconcileProofObservedAt: Date | string | null;\n};\n\nfunction commandPreview(value: string): string {\n const normalized = value.replace(/\\s+/g, \" \").trim();\n return Array.from(normalized).slice(0, 512).join(\"\");\n}\n\nfunction mapCommand(\n row: typeof schema.sessionBackgroundCommands.$inferSelect,\n): SessionBackgroundCommand {\n return {\n id: row.id,\n workspaceId: row.workspaceId,\n sessionId: row.sessionId,\n provider: row.provider,\n state: row.state,\n commandPreview: row.commandPreview,\n cancelRequestedAt: row.cancelRequestedAt?.toISOString() ?? null,\n exitCode: row.exitCode ?? null,\n settlementReason: row.settlementReason ?? null,\n startedAt: row.startedAt.toISOString(),\n settledAt: row.settledAt?.toISOString() ?? null,\n updatedAt: row.updatedAt.toISOString(),\n };\n}\n\nexport async function backgroundCommandActivityForSessions(\n db: Database,\n input: { accountId: string; workspaceId: string; sessionIds: string[] },\n): Promise<Map<string, SessionBackgroundCommandActivity>> {\n if (input.sessionIds.length === 0) return new Map();\n return await withRlsContext(\n db,\n { accountId: input.accountId, workspaceId: input.workspaceId },\n async (scopedDb) => {\n const rows = await scopedDb\n .select({\n sessionId: schema.sessionBackgroundCommands.sessionId,\n count: sql<number>`count(*)::int`,\n stoppingCount: sql<number>`count(*) filter (where ${schema.sessionBackgroundCommands.state} = 'stopping')::int`,\n })\n .from(schema.sessionBackgroundCommands)\n .where(\n and(\n eq(schema.sessionBackgroundCommands.workspaceId, input.workspaceId),\n inArray(schema.sessionBackgroundCommands.sessionId, input.sessionIds),\n inArray(schema.sessionBackgroundCommands.state, [\"running\", \"stopping\"]),\n ),\n )\n .groupBy(schema.sessionBackgroundCommands.sessionId);\n return new Map(\n rows.map((row) => [\n row.sessionId,\n {\n state: Number(row.stoppingCount) > 0 ? (\"stopping\" as const) : (\"running\" as const),\n count: Number(row.count),\n },\n ]),\n );\n },\n );\n}\n\nexport async function listSessionBackgroundCommands(\n db: Database,\n input: { accountId: string; workspaceId: string; sessionId: string },\n): Promise<SessionBackgroundCommand[]> {\n return await withRlsContext(\n db,\n { accountId: input.accountId, workspaceId: input.workspaceId },\n async (scopedDb) => {\n const rows = await scopedDb\n .select()\n .from(schema.sessionBackgroundCommands)\n .where(\n and(\n eq(schema.sessionBackgroundCommands.workspaceId, input.workspaceId),\n eq(schema.sessionBackgroundCommands.sessionId, input.sessionId),\n ),\n )\n .orderBy(\n desc(schema.sessionBackgroundCommands.startedAt),\n desc(schema.sessionBackgroundCommands.id),\n )\n .limit(1000);\n return rows.map(mapCommand);\n },\n );\n}\n\n/** @internal Caller must already hold the canonical session/control fence. */\nexport async function insertManagedSessionBackgroundCommandInTransaction(\n db: Database,\n input: {\n accountId: string;\n workspaceId: string;\n sessionId: string;\n commandId: string;\n retainedProcessId: string;\n command: string;\n },\n): Promise<SessionBackgroundCommand> {\n const [process] = await db\n .select({\n accountId: schema.sandboxRetainedProcesses.accountId,\n workspaceId: schema.sandboxRetainedProcesses.workspaceId,\n sessionId: schema.sandboxRetainedProcesses.sessionId,\n state: schema.sandboxRetainedProcesses.state,\n })\n .from(schema.sandboxRetainedProcesses)\n .where(eq(schema.sandboxRetainedProcesses.id, input.retainedProcessId))\n .for(\"update\")\n .limit(1);\n if (\n !process ||\n process.accountId !== input.accountId ||\n process.workspaceId !== input.workspaceId ||\n process.sessionId !== input.sessionId ||\n process.state !== \"active\"\n ) {\n throw new Error(\"Managed background command requires its exact active retained process\");\n }\n const [row] = await db\n .insert(schema.sessionBackgroundCommands)\n .values({\n id: input.commandId,\n accountId: input.accountId,\n workspaceId: input.workspaceId,\n sessionId: input.sessionId,\n provider: \"managed\",\n state: \"running\",\n retainedProcessId: input.retainedProcessId,\n commandPreview: commandPreview(input.command),\n })\n .onConflictDoUpdate({\n target: schema.sessionBackgroundCommands.retainedProcessId,\n targetWhere: sql`${schema.sessionBackgroundCommands.retainedProcessId} is not null`,\n set: { updatedAt: new Date() },\n })\n .returning();\n if (!row) throw new Error(\"Managed background command adoption returned no row\");\n if (\n row.accountId !== input.accountId ||\n row.workspaceId !== input.workspaceId ||\n row.sessionId !== input.sessionId ||\n row.provider !== \"managed\" ||\n row.retainedProcessId !== input.retainedProcessId\n ) {\n throw new Error(\"Managed background command adoption conflicted with another identity\");\n }\n return mapCommand(row);\n}\n\n/** @internal Caller must already hold the canonical exact-attempt fence. */\nexport async function insertConnectedMachineSessionBackgroundCommandInTransaction(\n db: Database,\n input: {\n accountId: string;\n workspaceId: string;\n sessionId: string;\n commandId: string;\n controlWorkspaceId: string;\n enrollmentId: string;\n connectionInstanceId: string;\n opId: string;\n command: string;\n },\n): Promise<SessionBackgroundCommand> {\n const [row] = await db\n .insert(schema.sessionBackgroundCommands)\n .values({\n id: input.commandId,\n accountId: input.accountId,\n workspaceId: input.workspaceId,\n sessionId: input.sessionId,\n provider: \"connected_machine\",\n state: \"running\",\n controlWorkspaceId: input.controlWorkspaceId,\n enrollmentId: input.enrollmentId,\n connectionInstanceId: input.connectionInstanceId,\n opId: input.opId,\n commandPreview: commandPreview(input.command),\n })\n .onConflictDoUpdate({\n target: [\n schema.sessionBackgroundCommands.controlWorkspaceId,\n schema.sessionBackgroundCommands.enrollmentId,\n schema.sessionBackgroundCommands.connectionInstanceId,\n schema.sessionBackgroundCommands.opId,\n ],\n targetWhere: sql`${schema.sessionBackgroundCommands.provider} = 'connected_machine'`,\n set: { updatedAt: new Date() },\n })\n .returning();\n if (!row) throw new Error(\"Connected Machine background command adoption returned no row\");\n if (\n row.accountId !== input.accountId ||\n row.workspaceId !== input.workspaceId ||\n row.sessionId !== input.sessionId ||\n row.provider !== \"connected_machine\" ||\n row.controlWorkspaceId !== input.controlWorkspaceId ||\n row.enrollmentId !== input.enrollmentId ||\n row.connectionInstanceId !== input.connectionInstanceId ||\n row.opId !== input.opId\n ) {\n throw new Error(\n \"Connected Machine background command adoption conflicted with another identity\",\n );\n }\n return mapCommand(row);\n}\n\n/** Claim exact Connected Machine locators globally for provider reconciliation.\n * The SECURITY DEFINER SQL function owns the bounded SKIP LOCKED inventory;\n * claim expiry is coordination recovery only and never implies command loss. */\nexport async function claimConnectedMachineSessionBackgroundCommands(\n db: Database,\n input: { claimId: string; limit: number; claimTtlMs: number },\n): Promise<ConnectedMachineBackgroundCommandClaim[]> {\n if (!Number.isSafeInteger(input.limit) || input.limit < 1 || input.limit > 100) {\n throw new Error(\"Connected command reconciliation limit must be between 1 and 100\");\n }\n if (\n !Number.isSafeInteger(input.claimTtlMs) ||\n input.claimTtlMs < 0 ||\n input.claimTtlMs > 3_600_000\n ) {\n throw new Error(\"Connected command reconciliation claim TTL is invalid\");\n }\n const rows = await db.execute<ConnectedMachineBackgroundCommandClaimRow>(sql`\n select account_id as \"accountId\",\n workspace_id as \"workspaceId\",\n session_id as \"sessionId\",\n command_id as \"commandId\",\n claim_id as \"claimId\",\n command_state as \"commandState\",\n control_workspace_id as \"controlWorkspaceId\",\n enrollment_id as \"enrollmentId\",\n connection_instance_id as \"connectionInstanceId\",\n op_id as \"opId\",\n reconcile_attempts as \"reconcileAttempts\",\n reconcile_proof_outcome as \"reconcileProofOutcome\",\n reconcile_proof_exit_code as \"reconcileProofExitCode\",\n reconcile_proof_reason as \"reconcileProofReason\",\n reconcile_proof_observed_at as \"reconcileProofObservedAt\"\n from opengeni_private.claim_connected_machine_background_commands(\n ${input.claimId}::uuid, ${input.limit}::integer, ${input.claimTtlMs}::bigint\n )\n `);\n return rows.map((row: ConnectedMachineBackgroundCommandClaimRow) => {\n if (row.commandState !== \"running\" && row.commandState !== \"stopping\") {\n throw new Error(`Connected command claim returned invalid state ${row.commandState}`);\n }\n const proof =\n row.reconcileProofOutcome === null\n ? null\n : row.reconcileProofOutcome === \"exited\" || row.reconcileProofOutcome === \"lost\"\n ? {\n outcome: row.reconcileProofOutcome,\n exitCode:\n row.reconcileProofExitCode === null ? null : Number(row.reconcileProofExitCode),\n reason: row.reconcileProofReason!,\n observedAt:\n row.reconcileProofObservedAt instanceof Date\n ? row.reconcileProofObservedAt\n : new Date(row.reconcileProofObservedAt!),\n }\n : (() => {\n throw new Error(\n `Connected command claim returned invalid proof ${row.reconcileProofOutcome}`,\n );\n })();\n return {\n commandId: row.commandId,\n accountId: row.accountId,\n workspaceId: row.workspaceId,\n sessionId: row.sessionId,\n claimId: row.claimId,\n state: row.commandState,\n controlWorkspaceId: row.controlWorkspaceId,\n enrollmentId: row.enrollmentId,\n connectionInstanceId: row.connectionInstanceId,\n opId: row.opId,\n reconcileAttempts: Number(row.reconcileAttempts),\n proof,\n };\n });\n}\n\nfunction connectedClaimIdentityWhere(claim: ConnectedMachineBackgroundCommandClaim) {\n return and(\n eq(schema.sessionBackgroundCommands.id, claim.commandId),\n eq(schema.sessionBackgroundCommands.accountId, claim.accountId),\n eq(schema.sessionBackgroundCommands.workspaceId, claim.workspaceId),\n eq(schema.sessionBackgroundCommands.sessionId, claim.sessionId),\n eq(schema.sessionBackgroundCommands.provider, \"connected_machine\"),\n eq(schema.sessionBackgroundCommands.controlWorkspaceId, claim.controlWorkspaceId),\n eq(schema.sessionBackgroundCommands.enrollmentId, claim.enrollmentId),\n eq(schema.sessionBackgroundCommands.connectionInstanceId, claim.connectionInstanceId),\n eq(schema.sessionBackgroundCommands.opId, claim.opId),\n eq(schema.sessionBackgroundCommands.reconcileClaimId, claim.claimId),\n inArray(schema.sessionBackgroundCommands.state, [\"running\", \"stopping\"]),\n );\n}\n\n/** Checkpoint one exact terminal provider observation before lifecycle settlement.\n * A retry may reuse an identical proof; a divergent proof is a hard identity fault. */\nexport async function recordConnectedMachineBackgroundCommandProof(\n db: Database,\n input: {\n claim: ConnectedMachineBackgroundCommandClaim;\n proof: ConnectedMachineBackgroundCommandProof;\n },\n): Promise<void> {\n const reason = input.proof.reason.trim().slice(0, 512);\n if (!reason) throw new Error(\"Connected command proof reason must not be empty\");\n if (input.proof.outcome === \"exited\" && input.proof.exitCode === null) {\n throw new Error(\"Connected command exit proof requires an exit code\");\n }\n if (input.proof.outcome === \"lost\" && input.proof.exitCode !== null) {\n throw new Error(\"Connected command loss proof cannot carry an exit code\");\n }\n await withRlsContext(\n db,\n { accountId: input.claim.accountId, workspaceId: input.claim.workspaceId },\n async (scopedDb) => {\n const [current] = await scopedDb\n .select()\n .from(schema.sessionBackgroundCommands)\n .where(connectedClaimIdentityWhere(input.claim))\n .for(\"update\")\n .limit(1);\n if (!current) throw new Error(\"Connected command proof was fenced by newer lifecycle state\");\n if (current.reconcileProofOutcome !== null) {\n const observedAt = current.reconcileProofObservedAt?.getTime() ?? null;\n if (\n current.reconcileProofOutcome !== input.proof.outcome ||\n current.reconcileProofExitCode !== input.proof.exitCode ||\n current.reconcileProofReason !== reason ||\n observedAt !== input.proof.observedAt.getTime()\n ) {\n throw new Error(\"Connected command reconciliation proof conflicts with durable proof\");\n }\n return;\n }\n const rows = await scopedDb\n .update(schema.sessionBackgroundCommands)\n .set({\n reconcileProofOutcome: input.proof.outcome,\n reconcileProofExitCode: input.proof.exitCode,\n reconcileProofReason: reason,\n reconcileProofObservedAt: input.proof.observedAt,\n lastReconcileOutcome: `proof_${input.proof.outcome}`,\n updatedAt: new Date(),\n })\n .where(connectedClaimIdentityWhere(input.claim))\n .returning({ id: schema.sessionBackgroundCommands.id });\n if (rows.length !== 1) {\n throw new Error(\"Connected command proof lost its exact claim during checkpoint\");\n }\n },\n );\n}\n\nexport async function deferConnectedMachineBackgroundCommandReconciliation(\n db: Database,\n input: {\n claim: ConnectedMachineBackgroundCommandClaim;\n outcome: string;\n retryAfterMs: number;\n },\n): Promise<boolean> {\n if (!Number.isSafeInteger(input.retryAfterMs) || input.retryAfterMs < 0) {\n throw new Error(\"Connected command reconciliation retry delay is invalid\");\n }\n const outcome = input.outcome.trim().slice(0, 64);\n if (!outcome) throw new Error(\"Connected command reconciliation outcome must not be empty\");\n return await withRlsContext(\n db,\n { accountId: input.claim.accountId, workspaceId: input.claim.workspaceId },\n async (scopedDb) => {\n const rows = await scopedDb\n .update(schema.sessionBackgroundCommands)\n .set({\n reconcileAfter: new Date(Date.now() + input.retryAfterMs),\n reconcileClaimId: null,\n reconcileClaimedAt: null,\n lastReconcileOutcome: outcome,\n updatedAt: new Date(),\n })\n .where(connectedClaimIdentityWhere(input.claim))\n .returning({ id: schema.sessionBackgroundCommands.id });\n return rows.length === 1;\n },\n );\n}\n\n/** Settle only from the proof already checkpointed under this exact claim. */\nexport async function settleClaimedConnectedMachineBackgroundCommand(\n db: Database,\n input: { claim: ConnectedMachineBackgroundCommandClaim },\n): Promise<boolean> {\n return await withRlsContext(\n db,\n { accountId: input.claim.accountId, workspaceId: input.claim.workspaceId },\n async (scopedDb) => {\n const rows = await scopedDb.execute<{ id: string }>(sql`\n update ${schema.sessionBackgroundCommands} command set\n state = command.reconcile_proof_outcome,\n exit_code = case\n when command.reconcile_proof_outcome = 'exited'\n then command.reconcile_proof_exit_code\n else null\n end,\n settlement_reason = command.reconcile_proof_reason,\n settled_at = command.reconcile_proof_observed_at,\n reconcile_claim_id = null,\n reconcile_claimed_at = null,\n last_reconcile_outcome = 'settled_' || command.reconcile_proof_outcome,\n updated_at = clock_timestamp()\n where command.id = ${input.claim.commandId}\n and command.account_id = ${input.claim.accountId}\n and command.workspace_id = ${input.claim.workspaceId}\n and command.session_id = ${input.claim.sessionId}\n and command.provider = 'connected_machine'\n and command.control_workspace_id = ${input.claim.controlWorkspaceId}\n and command.enrollment_id = ${input.claim.enrollmentId}\n and command.connection_instance_id = ${input.claim.connectionInstanceId}\n and command.op_id = ${input.claim.opId}\n and command.reconcile_claim_id = ${input.claim.claimId}\n and command.state in ('running', 'stopping')\n and command.reconcile_proof_outcome in ('exited', 'lost')\n and command.reconcile_proof_observed_at is not null\n returning command.id\n `);\n return rows.length === 1;\n },\n );\n}\n\nexport async function requestSessionBackgroundCommandCancellation(\n db: Database,\n input: {\n accountId: string;\n workspaceId: string;\n sessionId: string;\n commandId: string;\n subjectId: string;\n },\n): Promise<{ command: SessionBackgroundCommand | null; accepted: boolean }> {\n return await withRlsContext(\n db,\n { accountId: input.accountId, workspaceId: input.workspaceId },\n async (scopedDb) =>\n await scopedDb.transaction(async (tx) => {\n const [current] = await tx\n .select()\n .from(schema.sessionBackgroundCommands)\n .where(\n and(\n eq(schema.sessionBackgroundCommands.workspaceId, input.workspaceId),\n eq(schema.sessionBackgroundCommands.sessionId, input.sessionId),\n eq(schema.sessionBackgroundCommands.id, input.commandId),\n ),\n )\n .for(\"update\")\n .limit(1);\n if (!current) return { command: null, accepted: false };\n if (current.state !== \"running\") {\n return { command: mapCommand(current), accepted: false };\n }\n const [updated] = await tx\n .update(schema.sessionBackgroundCommands)\n .set({\n state: \"stopping\",\n cancelRequestedAt: new Date(),\n cancelRequestedBy: input.subjectId.slice(0, 1024),\n reconcileAfter: new Date(),\n reconcileClaimId: null,\n reconcileClaimedAt: null,\n updatedAt: new Date(),\n })\n .where(eq(schema.sessionBackgroundCommands.id, current.id))\n .returning();\n if (current.retainedProcessId) {\n await tx\n .update(schema.sandboxRetainedProcesses)\n .set({ reconcileAfter: new Date(), lastReconcileOutcome: \"cancel_requested\" })\n .where(\n and(\n eq(schema.sandboxRetainedProcesses.id, current.retainedProcessId),\n eq(schema.sandboxRetainedProcesses.state, \"active\"),\n sql`${schema.sandboxRetainedProcesses.reconcileClaimId} is null`,\n ),\n );\n }\n return { command: mapCommand(updated!), accepted: true };\n }),\n );\n}\n\n/**\n * Transfer every active command in one or more session subtrees to the\n * provider-neutral stopping state inside the caller's existing control\n * transaction. The workspace-control mutation already excludes concurrent\n * session-tree changes, so the recursive walk and state transition are one\n * atomic Pause/Cancel effect. Steer deliberately never calls this seam.\n */\nexport async function requestSessionBackgroundCommandCancellationsInTransaction(\n db: Database,\n input: {\n workspaceId: string;\n rootSessionIds: string[];\n subjectId: string;\n },\n): Promise<number> {\n const rootSessionIds = [...new Set(input.rootSessionIds)];\n if (rootSessionIds.length === 0) return 0;\n const rows = await db.execute<{ commandCount: number | string }>(sql`\n with recursive roots(id) as (\n values ${sql.join(\n rootSessionIds.map((sessionId) => sql`(${sessionId}::uuid)`),\n sql`, `,\n )}\n ), subtree(id, path, cycle) as (\n select session.id, array[session.id]::uuid[], false\n from roots root\n join ${schema.sessions} session\n on session.workspace_id = ${input.workspaceId}\n and session.id = root.id\n union all\n select child.id, parent.path || child.id, child.id = any(parent.path)\n from subtree parent\n join ${schema.sessions} child\n on child.workspace_id = ${input.workspaceId}\n and child.parent_session_id = parent.id\n where not parent.cycle\n ), stopped as (\n update ${schema.sessionBackgroundCommands} command set\n state = 'stopping',\n cancel_requested_at = clock_timestamp(),\n cancel_requested_by = left(${input.subjectId}, 1024),\n reconcile_after = clock_timestamp(),\n reconcile_claim_id = null,\n reconcile_claimed_at = null,\n updated_at = clock_timestamp()\n where command.workspace_id = ${input.workspaceId}\n and command.session_id in (select id from subtree where not cycle)\n and command.state = 'running'\n returning command.retained_process_id\n ), nudged as (\n update ${schema.sandboxRetainedProcesses} process set\n reconcile_after = clock_timestamp(),\n reconcile_claim_id = null,\n reconcile_claimed_at = null,\n last_reconcile_outcome = 'cancel_requested'\n where process.id in (\n select stopped.retained_process_id\n from stopped\n where stopped.retained_process_id is not null\n )\n and process.state = 'active'\n returning process.id\n )\n select count(*)::integer as \"commandCount\" from stopped\n `);\n return Number(rows[0]?.commandCount ?? 0);\n}\n\n/** Workspace Pause owns every active command in that workspace. */\nexport async function requestWorkspaceBackgroundCommandCancellationsInTransaction(\n db: Database,\n input: { workspaceId: string; subjectId: string },\n): Promise<number> {\n const rows = await db.execute<{ commandCount: number | string }>(sql`\n with stopped as (\n update ${schema.sessionBackgroundCommands} command set\n state = 'stopping',\n cancel_requested_at = clock_timestamp(),\n cancel_requested_by = left(${input.subjectId}, 1024),\n reconcile_after = clock_timestamp(),\n reconcile_claim_id = null,\n reconcile_claimed_at = null,\n updated_at = clock_timestamp()\n where command.workspace_id = ${input.workspaceId}\n and command.state = 'running'\n returning command.retained_process_id\n ), nudged as (\n update ${schema.sandboxRetainedProcesses} process set\n reconcile_after = clock_timestamp(),\n reconcile_claim_id = null,\n reconcile_claimed_at = null,\n last_reconcile_outcome = 'cancel_requested'\n where process.id in (\n select stopped.retained_process_id\n from stopped\n where stopped.retained_process_id is not null\n )\n and process.state = 'active'\n returning process.id\n )\n select count(*)::integer as \"commandCount\" from stopped\n `);\n return Number(rows[0]?.commandCount ?? 0);\n}\n\nexport async function settleSessionBackgroundCommandForRetainedProcess(\n db: Database,\n input: {\n accountId: string;\n workspaceId: string;\n sessionId: string;\n retainedProcessId: string;\n outcome: \"exited\" | \"lost\";\n exitCode: number | null;\n reason: string;\n },\n): Promise<SessionBackgroundCommand | null> {\n return await withRlsContext(\n db,\n { accountId: input.accountId, workspaceId: input.workspaceId },\n async (scopedDb) => {\n const [row] = await scopedDb\n .update(schema.sessionBackgroundCommands)\n .set({\n state: input.outcome,\n exitCode: input.outcome === \"exited\" ? input.exitCode : null,\n settlementReason: input.reason.slice(0, 512),\n settledAt: new Date(),\n reconcileClaimId: null,\n reconcileClaimedAt: null,\n lastReconcileOutcome: `settled_${input.outcome}`,\n updatedAt: new Date(),\n })\n .where(\n and(\n eq(schema.sessionBackgroundCommands.workspaceId, input.workspaceId),\n eq(schema.sessionBackgroundCommands.sessionId, input.sessionId),\n eq(schema.sessionBackgroundCommands.retainedProcessId, input.retainedProcessId),\n inArray(schema.sessionBackgroundCommands.state, [\"running\", \"stopping\"]),\n ),\n )\n .returning();\n return row ? mapCommand(row) : null;\n },\n );\n}\n\nexport async function settleConnectedMachineSessionBackgroundCommand(\n db: Database,\n input: {\n accountId: string;\n workspaceId: string;\n sessionId: string;\n commandId: string;\n controlWorkspaceId: string;\n enrollmentId: string;\n connectionInstanceId: string;\n opId: string;\n outcome: \"exited\" | \"lost\";\n exitCode: number | null;\n reason: string;\n },\n): Promise<SessionBackgroundCommand | null> {\n return await withRlsContext(\n db,\n { accountId: input.accountId, workspaceId: input.workspaceId },\n async (scopedDb) => {\n const settledAt = new Date();\n const reason = input.reason.trim().slice(0, 512);\n if (!reason) throw new Error(\"Connected command settlement reason must not be empty\");\n if (input.outcome === \"exited\" && input.exitCode === null) {\n throw new Error(\"Connected command exit settlement requires an exit code\");\n }\n if (input.outcome === \"lost\" && input.exitCode !== null) {\n throw new Error(\"Connected command loss settlement cannot carry an exit code\");\n }\n const [row] = await scopedDb\n .update(schema.sessionBackgroundCommands)\n .set({\n state: input.outcome,\n exitCode: input.outcome === \"exited\" ? input.exitCode : null,\n settlementReason: reason,\n settledAt,\n reconcileClaimId: null,\n reconcileClaimedAt: null,\n reconcileProofOutcome: input.outcome,\n reconcileProofExitCode: input.outcome === \"exited\" ? input.exitCode : null,\n reconcileProofReason: reason,\n reconcileProofObservedAt: settledAt,\n lastReconcileOutcome: `settled_${input.outcome}`,\n updatedAt: new Date(),\n })\n .where(\n and(\n eq(schema.sessionBackgroundCommands.workspaceId, input.workspaceId),\n eq(schema.sessionBackgroundCommands.sessionId, input.sessionId),\n eq(schema.sessionBackgroundCommands.id, input.commandId),\n eq(schema.sessionBackgroundCommands.provider, \"connected_machine\"),\n eq(schema.sessionBackgroundCommands.controlWorkspaceId, input.controlWorkspaceId),\n eq(schema.sessionBackgroundCommands.enrollmentId, input.enrollmentId),\n eq(schema.sessionBackgroundCommands.connectionInstanceId, input.connectionInstanceId),\n eq(schema.sessionBackgroundCommands.opId, input.opId),\n inArray(schema.sessionBackgroundCommands.state, [\"running\", \"stopping\"]),\n ),\n )\n .returning();\n return row ? mapCommand(row) : null;\n },\n );\n}\n"],"mappings":";;;;;;;;;;AAIA,SAAS,KAAK,MAAM,IAAI,SAAS,WAAW;AA8C5C,SAAS,eAAe,OAAuB;AAC7C,QAAM,aAAa,MAAM,QAAQ,QAAQ,GAAG,EAAE,KAAK;AACnD,SAAO,MAAM,KAAK,UAAU,EAAE,MAAM,GAAG,GAAG,EAAE,KAAK,EAAE;AACrD;AAEA,SAAS,WACP,KAC0B;AAC1B,SAAO;AAAA,IACL,IAAI,IAAI;AAAA,IACR,aAAa,IAAI;AAAA,IACjB,WAAW,IAAI;AAAA,IACf,UAAU,IAAI;AAAA,IACd,OAAO,IAAI;AAAA,IACX,gBAAgB,IAAI;AAAA,IACpB,mBAAmB,IAAI,mBAAmB,YAAY,KAAK;AAAA,IAC3D,UAAU,IAAI,YAAY;AAAA,IAC1B,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