@opengeni/worker-bundle 2.0.1 → 2.0.2-canary.38686408778001
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/activities/agent-run-admission.d.ts +1 -12
- package/dist/activities/agent-turn/admission.d.ts +88 -10
- package/dist/activities/agent-turn/agent-build.d.ts +14 -3
- package/dist/activities/agent-turn/claim.d.ts +4 -1
- package/dist/activities/agent-turn/claude-core.d.ts +195 -0
- package/dist/activities/agent-turn/code-search.d.ts +60 -0
- package/dist/activities/agent-turn/codex-capacity.d.ts +3 -0
- package/dist/activities/agent-turn/codex-core-capacity.d.ts +37 -0
- package/dist/activities/agent-turn/codex-core-claim.d.ts +40 -0
- package/dist/activities/agent-turn/codex-core-errors.d.ts +102 -0
- package/dist/activities/agent-turn/codex-core-failover.d.ts +15 -0
- package/dist/activities/agent-turn/codex-core-requests.d.ts +28 -0
- package/dist/activities/agent-turn/codex-core-settlement.d.ts +77 -0
- package/dist/activities/agent-turn/codex-credit-policy.d.ts +30 -0
- package/dist/activities/agent-turn/codex-plan-entitlement.d.ts +105 -0
- package/dist/activities/agent-turn/codex-usage-policy.d.ts +2 -0
- package/dist/activities/agent-turn/codex.d.ts +2 -19
- package/dist/activities/agent-turn/compaction-interruption.d.ts +32 -0
- package/dist/activities/agent-turn/compaction-prep.d.ts +30 -1
- package/dist/activities/agent-turn/credential-leases.d.ts +64 -37
- package/dist/activities/agent-turn/credential-restriction.d.ts +3 -0
- package/dist/activities/agent-turn/errors.d.ts +172 -28
- package/dist/activities/agent-turn/failure-settlement.d.ts +10 -43
- package/dist/activities/agent-turn/final-reply.d.ts +18 -0
- package/dist/activities/agent-turn/finalization-monitor.d.ts +7 -2
- package/dist/activities/agent-turn/finalization.d.ts +2 -0
- package/dist/activities/agent-turn/github-repository-bindings.d.ts +2 -0
- package/dist/activities/agent-turn/governance-model.d.ts +13 -1
- package/dist/activities/agent-turn/history-sink.d.ts +3 -1
- package/dist/activities/agent-turn/history.d.ts +2 -0
- package/dist/activities/agent-turn/input-wait-reply.d.ts +76 -0
- package/dist/activities/agent-turn/meaningful-output.d.ts +9 -0
- package/dist/activities/agent-turn/media-artifacts.d.ts +5 -3
- package/dist/activities/agent-turn/model-call-admission.d.ts +15 -0
- package/dist/activities/agent-turn/model-usage.d.ts +56 -14
- package/dist/activities/agent-turn/model-wire-dispatch.d.ts +15 -0
- package/dist/activities/agent-turn/optional-repositories.d.ts +59 -0
- package/dist/activities/agent-turn/prompt-tool-availability.d.ts +17 -0
- package/dist/activities/agent-turn/provider-dispatch-barrier.d.ts +12 -1
- package/dist/activities/agent-turn/provider-recovery-copy.d.ts +24 -0
- package/dist/activities/agent-turn/provider-recovery-metrics.d.ts +18 -0
- package/dist/activities/agent-turn/provider-recovery-policy.d.ts +6 -0
- package/dist/activities/agent-turn/quiescence.d.ts +6 -7
- package/dist/activities/agent-turn/recovery-warning.d.ts +6 -5
- package/dist/activities/agent-turn/refresh-credentials.d.ts +6 -0
- package/dist/activities/agent-turn/run-credentials.d.ts +9 -5
- package/dist/activities/agent-turn/run.d.ts +27 -2
- package/dist/activities/agent-turn/sandbox-establish.d.ts +1 -0
- package/dist/activities/agent-turn/sandbox-provision.d.ts +25 -1
- package/dist/activities/agent-turn/sandbox-route.d.ts +3 -0
- package/dist/activities/agent-turn/sandbox-runtime.d.ts +1 -1
- package/dist/activities/agent-turn/secret-resolver.d.ts +64 -0
- package/dist/activities/agent-turn/session-title.d.ts +60 -3
- package/dist/activities/agent-turn/session-usage-custody.d.ts +66 -0
- package/dist/activities/agent-turn/skill-checkout.d.ts +25 -6
- package/dist/activities/agent-turn/skill-read.d.ts +70 -2
- package/dist/activities/agent-turn/skill-search.d.ts +2 -0
- package/dist/activities/agent-turn/skill-tools.d.ts +41 -4
- package/dist/activities/agent-turn/skill-transfer.d.ts +18 -6
- package/dist/activities/agent-turn/stream-attempt.d.ts +6 -3
- package/dist/activities/agent-turn/subscription-capacity-arming.d.ts +41 -0
- package/dist/activities/agent-turn/subscription-core-capacity.d.ts +86 -0
- package/dist/activities/agent-turn/subscription-core-failover.d.ts +69 -0
- package/dist/activities/agent-turn/subscription-core-placed.d.ts +14 -0
- package/dist/activities/agent-turn/subscription-core-requests.d.ts +109 -0
- package/dist/activities/agent-turn/subscription-core-settlement.d.ts +112 -0
- package/dist/activities/agent-turn/subscription-lease.d.ts +44 -0
- package/dist/activities/agent-turn/subscription-serving-capacity.d.ts +6 -0
- package/dist/activities/agent-turn/subscription-serving-catalog.d.ts +13 -0
- package/dist/activities/agent-turn/subscription-serving-claim.d.ts +30 -0
- package/dist/activities/agent-turn/subscription-serving-providers.d.ts +2 -0
- package/dist/activities/agent-turn/tool-environment.d.ts +30 -6
- package/dist/activities/agent-turn/tool-policy.d.ts +55 -3
- package/dist/activities/agent-turn/turn-context.d.ts +104 -5
- package/dist/activities/agent-turn/web-search.d.ts +57 -0
- package/dist/activities/agent-turn/xai-core.d.ts +96 -0
- package/dist/activities/automations.d.ts +3 -1
- package/dist/activities/browser-deadline-checkpoint.d.ts +34 -0
- package/dist/activities/capabilities.d.ts +8 -20
- package/dist/activities/codemode-dispatcher.d.ts +20 -3
- package/dist/activities/codex-capacity.d.ts +1 -56
- package/dist/activities/codex-image-generation.d.ts +49 -3
- package/dist/activities/common.d.ts +3 -1
- package/dist/activities/context-compaction.d.ts +41 -2
- package/dist/activities/environment.d.ts +1 -19
- package/dist/activities/gmail-files.d.ts +50 -0
- package/dist/activities/goals.d.ts +1 -9
- package/dist/activities/incident-telemetry-authority.d.ts +5 -2
- package/dist/activities/incident-telemetry-preflight.d.ts +10 -3
- package/dist/activities/knowledge-indexing.d.ts +19 -0
- package/dist/activities/mcp-account-routes.d.ts +2 -21
- package/dist/activities/model-call-fact-reconciler.d.ts +34 -0
- package/dist/activities/open-suffix-resume.d.ts +15 -0
- package/dist/activities/parent-wake.d.ts +17 -12
- package/dist/activities/programmatic-approvals.d.ts +10 -0
- package/dist/activities/requester-unavailable-receipt.d.ts +8 -0
- package/dist/activities/retained-screenshots.d.ts +7 -2
- package/dist/activities/run-credential-renewal.d.ts +1 -0
- package/dist/activities/run-credentials.d.ts +16 -4
- package/dist/activities/run-input.d.ts +17 -0
- package/dist/activities/sandbox-lease.d.ts +132 -12
- package/dist/activities/scheduled-tasks.d.ts +4 -35
- package/dist/activities/session-archive.d.ts +58 -0
- package/dist/activities/session-state.d.ts +15 -3
- package/dist/activities/session-storage.d.ts +44 -0
- package/dist/activities/subscription-core-claude-waits.d.ts +2 -0
- package/dist/activities/subscription-core-codex-quota.d.ts +25 -0
- package/dist/activities/subscription-core-codex-waits.d.ts +153 -0
- package/dist/activities/subscription-core-image-operation.d.ts +29 -0
- package/dist/activities/subscription-core-usage-recheck.d.ts +49 -0
- package/dist/activities/subscription-core-wait-bindings.d.ts +3 -0
- package/dist/activities/subscription-core-xai-quota.d.ts +30 -0
- package/dist/activities/subscription-core-xai-waits.d.ts +2 -0
- package/dist/activities/types.d.ts +68 -5
- package/dist/activities/video-generation-admission.d.ts +2 -8
- package/dist/activities/video-generation-credential.d.ts +15 -12
- package/dist/activities/video-generation-subscription-core.d.ts +70 -0
- package/dist/activities/workspace-capture.d.ts +2 -0
- package/dist/activities/workspace-credential-provider.d.ts +47 -0
- package/dist/activities/xai-auth.d.ts +6 -18
- package/dist/activities/xai-image-generation.d.ts +22 -6
- package/dist/{activities-control-QA6OLRQY.js → activities-control-NTXZHYET.js} +1552 -2876
- package/dist/activities-control-NTXZHYET.js.map +1 -0
- package/dist/activities-control.d.ts +64 -4
- package/dist/{activities-turn-YVVKCGAK.js → activities-turn-RKRI5GY4.js} +9238 -4392
- package/dist/activities-turn-RKRI5GY4.js.map +1 -0
- package/dist/activities.d.ts +64 -4
- package/dist/artifact-materializer-entry.js +104 -35
- package/dist/artifact-materializer-entry.js.map +1 -1
- package/dist/artifact-outbox-entry.js +132 -61
- package/dist/artifact-outbox-entry.js.map +1 -1
- package/dist/browser-deadline-checkpoint-contract.d.ts +2 -0
- package/dist/{chunk-GDCLDKSH.js → chunk-24GP3BX5.js} +79 -72
- package/dist/chunk-24GP3BX5.js.map +1 -0
- package/dist/{chunk-RAMNYSAW.js → chunk-4ER3YXOT.js} +22 -4
- package/dist/chunk-4ER3YXOT.js.map +1 -0
- package/dist/{chunk-I7HKKMUJ.js → chunk-5NNS4327.js} +734 -58
- package/dist/chunk-5NNS4327.js.map +1 -0
- package/dist/{chunk-M3NVMF2V.js → chunk-7BIHFUGB.js} +2293 -3956
- package/dist/chunk-7BIHFUGB.js.map +1 -0
- package/dist/chunk-MVESOYFC.js +3746 -0
- package/dist/chunk-MVESOYFC.js.map +1 -0
- package/dist/chunk-NQDVJ6RI.js +2823 -0
- package/dist/chunk-NQDVJ6RI.js.map +1 -0
- package/dist/chunk-O7UPBWXK.js +79 -0
- package/dist/chunk-O7UPBWXK.js.map +1 -0
- package/dist/chunk-W2QSM5HR.js +414 -0
- package/dist/chunk-W2QSM5HR.js.map +1 -0
- package/dist/chunk-ZN3XJR33.js +227 -0
- package/dist/chunk-ZN3XJR33.js.map +1 -0
- package/dist/editable-artifact-outbox-dispatcher.d.ts +12 -1
- package/dist/editable-artifact-outbox-service.d.ts +3 -1
- package/dist/host-export-pump.d.ts +3 -1
- package/dist/host-export.d.ts +2 -2
- package/dist/host-export.js +1 -1
- package/dist/http.d.ts +1 -1
- package/dist/index.d.ts +49 -48
- package/dist/index.js +835 -256
- package/dist/index.js.map +1 -1
- package/dist/internal-maintenance.d.ts +63 -0
- package/dist/maintenance-cadence.d.ts +43 -0
- package/dist/observability-metrics.d.ts +293 -24
- package/dist/onepassword-vault-provider.d.ts +7 -0
- package/dist/parent-wake-PCLH7A3Y.js +24 -0
- package/dist/parent-wake-PCLH7A3Y.js.map +1 -0
- package/dist/personal-github-git-credentials.d.ts +1 -1
- package/dist/readiness-checks.d.ts +39 -0
- package/dist/retained-process-retry.d.ts +7 -0
- package/dist/sandbox-lease-BJYU72N3.js +84 -0
- package/dist/sandbox-lease-BJYU72N3.js.map +1 -0
- package/dist/sandbox-reaper-contract.d.ts +25 -0
- package/dist/sandbox-resume.d.ts +72 -4
- package/dist/sandbox-routing.d.ts +4 -2
- package/dist/session-event-fanout.d.ts +6 -0
- package/dist/site-auth-maintenance-WK3MR2PV.js +12 -0
- package/dist/site-auth-maintenance-WK3MR2PV.js.map +1 -0
- package/dist/telemetry-scheduler.d.ts +14 -0
- package/dist/temporal-runtime-logger.d.ts +22 -0
- package/dist/turn-task-queue-reader.d.ts +18 -0
- package/dist/turn-worker-activity-telemetry.d.ts +47 -0
- package/dist/worker-service-lifecycle.d.ts +12 -0
- package/dist/workflow-bundle.js +468 -71
- package/dist/workflows/activities.d.ts +1 -1
- package/dist/workflows/browser-deadline-checkpoint.d.ts +10 -0
- package/dist/workflows/sandbox-reaper.d.ts +10 -1
- package/dist/workflows/scheduled-tasks.d.ts +4 -0
- package/dist/workflows/session-storage.d.ts +2 -0
- package/dist/workflows/session.d.ts +36 -0
- package/dist/workflows/site-auth-maintenance.d.ts +2 -1
- package/dist/workflows/workflow-wake.d.ts +14 -3
- package/dist/workflows.d.ts +3 -1
- package/package.json +26 -20
- package/src/activities/agent-run-admission.ts +1 -82
- package/src/activities/agent-turn/admission.ts +175 -24
- package/src/activities/agent-turn/agent-build.ts +226 -145
- package/src/activities/agent-turn/claim.ts +363 -64
- package/src/activities/agent-turn/claude-core.ts +587 -0
- package/src/activities/agent-turn/code-search.ts +275 -0
- package/src/activities/agent-turn/codex-capacity.ts +30 -757
- package/src/activities/agent-turn/codex-core-capacity.ts +190 -0
- package/src/activities/agent-turn/codex-core-claim.ts +83 -0
- package/src/activities/agent-turn/codex-core-errors.ts +308 -0
- package/src/activities/agent-turn/codex-core-failover.ts +73 -0
- package/src/activities/agent-turn/codex-core-requests.ts +86 -0
- package/src/activities/agent-turn/codex-core-settlement.ts +263 -0
- package/src/activities/agent-turn/codex-credit-policy.ts +247 -0
- package/src/activities/agent-turn/codex-plan-entitlement.ts +254 -0
- package/src/activities/agent-turn/codex-usage-policy.ts +2 -0
- package/src/activities/agent-turn/codex.ts +8 -76
- package/src/activities/agent-turn/compaction-interruption.ts +56 -0
- package/src/activities/agent-turn/compaction-prep.ts +249 -36
- package/src/activities/agent-turn/credential-leases.ts +269 -214
- package/src/activities/agent-turn/credential-restriction.ts +14 -0
- package/src/activities/agent-turn/errors.ts +1134 -82
- package/src/activities/agent-turn/failure-settlement.ts +879 -886
- package/src/activities/agent-turn/final-reply.ts +46 -0
- package/src/activities/agent-turn/finalization-monitor.ts +17 -5
- package/src/activities/agent-turn/finalization.ts +107 -88
- package/src/activities/agent-turn/github-repository-bindings.ts +3 -1
- package/src/activities/agent-turn/governance-model.ts +90 -22
- package/src/activities/agent-turn/history-sink.ts +26 -4
- package/src/activities/agent-turn/history.ts +25 -5
- package/src/activities/agent-turn/input-wait-reply.ts +139 -0
- package/src/activities/agent-turn/knowledge-source-tools.ts +2 -0
- package/src/activities/agent-turn/meaningful-output.ts +44 -0
- package/src/activities/agent-turn/media-artifacts.ts +3 -1
- package/src/activities/agent-turn/model-call-admission.ts +94 -0
- package/src/activities/agent-turn/model-usage.ts +299 -233
- package/src/activities/agent-turn/model-wire-dispatch.ts +27 -0
- package/src/activities/agent-turn/optional-repositories.ts +224 -0
- package/src/activities/agent-turn/prompt-tool-availability.ts +27 -0
- package/src/activities/agent-turn/provider-dispatch-barrier.ts +22 -0
- package/src/activities/agent-turn/provider-recovery-copy.ts +76 -0
- package/src/activities/agent-turn/provider-recovery-metrics.ts +64 -0
- package/src/activities/agent-turn/provider-recovery-policy.ts +25 -0
- package/src/activities/agent-turn/quiescence.ts +7 -7
- package/src/activities/agent-turn/recovery-warning.ts +6 -8
- package/src/activities/agent-turn/refresh-credentials.ts +44 -0
- package/src/activities/agent-turn/run-credentials.ts +124 -76
- package/src/activities/agent-turn/run.ts +501 -112
- package/src/activities/agent-turn/sandbox-establish.ts +152 -75
- package/src/activities/agent-turn/sandbox-provision.ts +54 -1
- package/src/activities/agent-turn/sandbox-route.ts +4 -1
- package/src/activities/agent-turn/sandbox-runtime.ts +319 -11
- package/src/activities/agent-turn/secret-resolver.ts +155 -0
- package/src/activities/agent-turn/session-title.ts +177 -12
- package/src/activities/agent-turn/session-usage-custody.ts +170 -0
- package/src/activities/agent-turn/skill-checkout.ts +111 -24
- package/src/activities/agent-turn/skill-install.ts +1 -1
- package/src/activities/agent-turn/skill-read.ts +374 -28
- package/src/activities/agent-turn/skill-save.ts +35 -7
- package/src/activities/agent-turn/skill-search.ts +9 -0
- package/src/activities/agent-turn/skill-selection.ts +4 -0
- package/src/activities/agent-turn/skill-tools.ts +208 -21
- package/src/activities/agent-turn/skill-transfer.ts +68 -23
- package/src/activities/agent-turn/stream-attempt.ts +599 -110
- package/src/activities/agent-turn/subscription-capacity-arming.ts +81 -0
- package/src/activities/agent-turn/subscription-core-capacity.ts +439 -0
- package/src/activities/agent-turn/subscription-core-failover.ts +229 -0
- package/src/activities/agent-turn/subscription-core-placed.ts +37 -0
- package/src/activities/agent-turn/subscription-core-requests.ts +271 -0
- package/src/activities/agent-turn/subscription-core-settlement.ts +234 -0
- package/src/activities/agent-turn/subscription-lease.ts +140 -0
- package/src/activities/agent-turn/subscription-serving-capacity.ts +195 -0
- package/src/activities/agent-turn/subscription-serving-catalog.ts +71 -0
- package/src/activities/agent-turn/subscription-serving-claim.ts +178 -0
- package/src/activities/agent-turn/subscription-serving-providers.ts +15 -0
- package/src/activities/agent-turn/tool-environment.ts +384 -292
- package/src/activities/agent-turn/tool-policy.ts +104 -4
- package/src/activities/agent-turn/tool-result-spill.ts +1 -0
- package/src/activities/agent-turn/turn-context.ts +124 -8
- package/src/activities/agent-turn/web-search.ts +431 -0
- package/src/activities/agent-turn/xai-core.ts +301 -0
- package/src/activities/automations.ts +81 -6
- package/src/activities/browser-deadline-checkpoint.ts +297 -0
- package/src/activities/capabilities.ts +53 -213
- package/src/activities/codemode-dispatcher.ts +236 -14
- package/src/activities/codex-capacity.ts +27 -380
- package/src/activities/codex-image-generation.ts +252 -42
- package/src/activities/common.ts +12 -0
- package/src/activities/connector-attachments.ts +3 -1
- package/src/activities/context-compaction.ts +162 -21
- package/src/activities/environment.ts +18 -106
- package/src/activities/gmail-files.ts +108 -0
- package/src/activities/goals.ts +120 -204
- package/src/activities/image-generation-operation.ts +1 -1
- package/src/activities/incident-telemetry-authority.ts +80 -50
- package/src/activities/incident-telemetry-preflight.ts +27 -15
- package/src/activities/knowledge-indexing.ts +287 -17
- package/src/activities/knowledge-source-sync.ts +10 -0
- package/src/activities/mcp-account-routes.ts +2 -124
- package/src/activities/model-call-fact-reconciler.ts +112 -0
- package/src/activities/open-suffix-resume.ts +122 -88
- package/src/activities/parent-wake.ts +89 -21
- package/src/activities/programmatic-approvals.ts +26 -0
- package/src/activities/requester-unavailable-receipt.ts +14 -0
- package/src/activities/retained-screenshots.ts +135 -24
- package/src/activities/run-credential-renewal.ts +13 -1
- package/src/activities/run-credentials.ts +61 -19
- package/src/activities/run-input.ts +116 -9
- package/src/activities/sandbox-lease.ts +1615 -73
- package/src/activities/scheduled-tasks.ts +758 -141
- package/src/activities/session-archive.ts +382 -0
- package/src/activities/session-state.ts +219 -10
- package/src/activities/session-storage.ts +124 -0
- package/src/activities/site-auth-maintenance.ts +5 -2
- package/src/activities/subscription-core-claude-waits.ts +49 -0
- package/src/activities/subscription-core-codex-quota.ts +46 -0
- package/src/activities/subscription-core-codex-waits.ts +488 -0
- package/src/activities/subscription-core-image-operation.ts +126 -0
- package/src/activities/subscription-core-usage-recheck.ts +146 -0
- package/src/activities/subscription-core-wait-bindings.ts +12 -0
- package/src/activities/subscription-core-xai-quota.ts +85 -0
- package/src/activities/subscription-core-xai-waits.ts +48 -0
- package/src/activities/types.ts +85 -9
- package/src/activities/video-generation-admission.ts +1 -36
- package/src/activities/video-generation-credential.ts +38 -56
- package/src/activities/video-generation-reconciliation.ts +150 -131
- package/src/activities/video-generation-subscription-core.ts +180 -0
- package/src/activities/workspace-capture.ts +13 -2
- package/src/activities/workspace-credential-provider.ts +302 -0
- package/src/activities/xai-auth.ts +34 -112
- package/src/activities/xai-image-generation.ts +84 -36
- package/src/activities-control.ts +8 -0
- package/src/activities-turn.ts +5 -0
- package/src/activities.ts +17 -0
- package/src/activity-services.ts +29 -4
- package/src/browser-deadline-checkpoint-contract.ts +5 -0
- package/src/editable-artifact-hint-broker.ts +3 -0
- package/src/editable-artifact-materializer-service.ts +79 -38
- package/src/editable-artifact-materializer-subprocess.ts +47 -2
- package/src/editable-artifact-outbox-dispatcher.ts +107 -46
- package/src/editable-artifact-outbox-service.ts +55 -25
- package/src/github-rest-mcp.ts +1 -1
- package/src/host-export-pump.ts +26 -4
- package/src/host-export.ts +4 -1
- package/src/http.ts +4 -2
- package/src/index.ts +222 -282
- package/src/internal-maintenance.ts +347 -0
- package/src/maintenance-cadence.ts +156 -0
- package/src/observability-metrics.ts +1173 -73
- package/src/onepassword-vault-provider.ts +11 -0
- package/src/personal-github-git-credentials.ts +3 -1
- package/src/pr-review-credentials.ts +1 -1
- package/src/readiness-checks.ts +113 -0
- package/src/retained-process-retry.ts +36 -0
- package/src/sandbox-reaper-contract.ts +33 -0
- package/src/sandbox-resume.ts +444 -73
- package/src/sandbox-routing.ts +230 -75
- package/src/session-event-fanout.ts +23 -0
- package/src/telemetry-scheduler.ts +53 -0
- package/src/temporal-runtime-logger.ts +44 -0
- package/src/turn-task-queue-reader.ts +110 -0
- package/src/turn-worker-activity-telemetry.ts +209 -0
- package/src/worker-service-lifecycle.ts +54 -1
- package/src/workflows/activities.ts +16 -1
- package/src/workflows/browser-deadline-checkpoint.ts +55 -0
- package/src/workflows/file-upload-reaper.ts +2 -0
- package/src/workflows/sandbox-reaper.ts +88 -0
- package/src/workflows/scheduled-tasks.ts +26 -13
- package/src/workflows/session-storage.ts +19 -0
- package/src/workflows/session.ts +238 -33
- package/src/workflows/site-auth-maintenance.ts +2 -1
- package/src/workflows/workflow-wake.ts +26 -4
- package/src/workflows.ts +7 -0
- package/dist/activities/agent-turn/xai-capacity.d.ts +0 -2
- package/dist/activities/codex-fleet-shadow.d.ts +0 -74
- package/dist/activities/codex-rotation.d.ts +0 -200
- package/dist/activities/xai-quota.d.ts +0 -3
- package/dist/activities-control-QA6OLRQY.js.map +0 -1
- package/dist/activities-turn-YVVKCGAK.js.map +0 -1
- package/dist/chunk-GDCLDKSH.js.map +0 -1
- package/dist/chunk-I7HKKMUJ.js.map +0 -1
- package/dist/chunk-M3NVMF2V.js.map +0 -1
- package/dist/chunk-RAMNYSAW.js.map +0 -1
- package/src/activities/agent-turn/xai-capacity.ts +0 -257
- package/src/activities/codex-fleet-shadow.ts +0 -306
- package/src/activities/codex-rotation.ts +0 -685
- package/src/activities/xai-quota.ts +0 -35
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { Context } from "@temporalio/activity";
|
|
2
|
+
import {
|
|
3
|
+
environmentsEncryptionKeyBytes,
|
|
4
|
+
resolveFirstPartyDelegationSecret,
|
|
5
|
+
type Settings,
|
|
6
|
+
} from "@opengeni/config";
|
|
7
|
+
import { BROWSER_STATE_ARTIFACT_CONTENT_TYPE } from "@opengeni/contracts";
|
|
8
|
+
import {
|
|
9
|
+
browserDeadlineCheckpoint,
|
|
10
|
+
clearSuspendedBrowserSessionController,
|
|
11
|
+
commitBrowserSessionSuspension,
|
|
12
|
+
dispatchBrowserSessionOperation,
|
|
13
|
+
failBrowserSessionSuspension,
|
|
14
|
+
listBrowserDeadlineCheckpoints,
|
|
15
|
+
readLease,
|
|
16
|
+
releaseLeaseHolder,
|
|
17
|
+
withRlsContext,
|
|
18
|
+
type BrowserDeadlineCheckpointTarget,
|
|
19
|
+
} from "@opengeni/db";
|
|
20
|
+
import { deriveBrowserControllerAdminToken } from "@opengeni/interaction/browser-controller-authority";
|
|
21
|
+
import {
|
|
22
|
+
browserStateArtifactAad,
|
|
23
|
+
browserStateManifestDigest,
|
|
24
|
+
browserStateObjectKey,
|
|
25
|
+
deriveBrowserStateDataKey,
|
|
26
|
+
wrapBrowserStateDataKey,
|
|
27
|
+
} from "@opengeni/interaction/browser-state-authority";
|
|
28
|
+
import {
|
|
29
|
+
BrowserControlClient,
|
|
30
|
+
BrowserControlRequestError,
|
|
31
|
+
createSandboxClientForBackend,
|
|
32
|
+
deserializeSandboxSessionStateEnvelope,
|
|
33
|
+
resumeExactSandboxSession,
|
|
34
|
+
type BrowserControlPlacementSession,
|
|
35
|
+
} from "@opengeni/runtime";
|
|
36
|
+
import type { ControlActivityServices } from "./types";
|
|
37
|
+
|
|
38
|
+
const UPLOAD_CLEANUP_GRACE_MS = 24 * 60 * 60_000;
|
|
39
|
+
|
|
40
|
+
function heartbeat(): void {
|
|
41
|
+
try {
|
|
42
|
+
Context.current().heartbeat();
|
|
43
|
+
} catch {
|
|
44
|
+
// Direct embedded calls have no Temporal context. In-flight controller
|
|
45
|
+
// operations still settle under their exact durable database claim.
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function withActivityHeartbeat<T>(run: () => Promise<T>): Promise<T> {
|
|
50
|
+
heartbeat();
|
|
51
|
+
const timer = setInterval(heartbeat, 5_000);
|
|
52
|
+
try {
|
|
53
|
+
return await run();
|
|
54
|
+
} finally {
|
|
55
|
+
clearInterval(timer);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
type CheckpointController = Pick<BrowserControlClient, "captureState" | "endSession">;
|
|
60
|
+
type CheckpointPlacement = {
|
|
61
|
+
target: BrowserDeadlineCheckpointTarget;
|
|
62
|
+
lease: NonNullable<Awaited<ReturnType<typeof readLease>>>;
|
|
63
|
+
settings: Settings;
|
|
64
|
+
controllerRoot: string;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
async function resumeCheckpointController({
|
|
68
|
+
target,
|
|
69
|
+
lease,
|
|
70
|
+
settings,
|
|
71
|
+
controllerRoot,
|
|
72
|
+
}: CheckpointPlacement): Promise<CheckpointController> {
|
|
73
|
+
// This edge cannot create a box or route through a user's current machine.
|
|
74
|
+
const provider = createSandboxClientForBackend("modal", settings) as Parameters<
|
|
75
|
+
typeof deserializeSandboxSessionStateEnvelope
|
|
76
|
+
>[0];
|
|
77
|
+
const envelope = lease.resumeState as { sessionState?: unknown };
|
|
78
|
+
const state = await deserializeSandboxSessionStateEnvelope(
|
|
79
|
+
provider,
|
|
80
|
+
envelope.sessionState ?? lease.resumeState,
|
|
81
|
+
target.instanceId,
|
|
82
|
+
);
|
|
83
|
+
const resumed = await resumeExactSandboxSession(provider, "modal", state, target.instanceId);
|
|
84
|
+
return new BrowserControlClient(resumed.session as BrowserControlPlacementSession, {
|
|
85
|
+
adminToken: deriveBrowserControllerAdminToken({
|
|
86
|
+
rootSecret: controllerRoot,
|
|
87
|
+
accountId: target.accountId,
|
|
88
|
+
workspaceId: target.workspaceId,
|
|
89
|
+
placement: { kind: "sandbox_group", sandboxGroupId: target.sandboxGroupId },
|
|
90
|
+
placementInstanceId: target.instanceId,
|
|
91
|
+
}),
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Whether this worker can save browser profiles: ownership, object storage,
|
|
96
|
+
* the controller delegation secret and the environments encryption key. */
|
|
97
|
+
export function browserCheckpointPrerequisites(
|
|
98
|
+
settings: Settings,
|
|
99
|
+
objectStorage: ControlActivityServices["objectStorage"],
|
|
100
|
+
): boolean {
|
|
101
|
+
if (
|
|
102
|
+
!settings.sandboxOwnershipEnabled ||
|
|
103
|
+
!objectStorage ||
|
|
104
|
+
!resolveFirstPartyDelegationSecret(settings)
|
|
105
|
+
)
|
|
106
|
+
return false;
|
|
107
|
+
const root = environmentsEncryptionKeyBytes(settings);
|
|
108
|
+
if (!root) return false;
|
|
109
|
+
root.fill(0);
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function createBrowserDeadlineCheckpointActivities(
|
|
114
|
+
services: () => Promise<ControlActivityServices>,
|
|
115
|
+
connectController: (
|
|
116
|
+
placement: CheckpointPlacement,
|
|
117
|
+
) => Promise<CheckpointController> = resumeCheckpointController,
|
|
118
|
+
) {
|
|
119
|
+
return {
|
|
120
|
+
async listDueBrowserCheckpoints() {
|
|
121
|
+
return await withActivityHeartbeat(async () => {
|
|
122
|
+
const { db, settings, objectStorage } = await services();
|
|
123
|
+
if (!browserCheckpointPrerequisites(settings, objectStorage)) return [];
|
|
124
|
+
return await listBrowserDeadlineCheckpoints(db);
|
|
125
|
+
});
|
|
126
|
+
},
|
|
127
|
+
async checkpointBrowserBeforeDeadline(target: BrowserDeadlineCheckpointTarget) {
|
|
128
|
+
return await withActivityHeartbeat(async () => {
|
|
129
|
+
const { db, settings, objectStorage } = await services();
|
|
130
|
+
const rootKey = environmentsEncryptionKeyBytes(settings);
|
|
131
|
+
const controllerRoot = resolveFirstPartyDelegationSecret(settings);
|
|
132
|
+
if (!rootKey || !objectStorage || !controllerRoot) {
|
|
133
|
+
rootKey?.fill(0);
|
|
134
|
+
throw new Error("browser deadline checkpoint storage or encryption is unavailable");
|
|
135
|
+
}
|
|
136
|
+
let dataKey: Buffer | null = null;
|
|
137
|
+
let aad: Buffer | null = null;
|
|
138
|
+
let timer: ReturnType<typeof setInterval> | null = null;
|
|
139
|
+
try {
|
|
140
|
+
// Only the reaper's locked idle decision prepares an idle save; this
|
|
141
|
+
// activity continues it. A deadline save prepares here.
|
|
142
|
+
const claim = await browserDeadlineCheckpoint(db, target, {
|
|
143
|
+
prepare: target.reason !== "idle",
|
|
144
|
+
touch: true,
|
|
145
|
+
});
|
|
146
|
+
if (!claim) return { status: "skipped" as const };
|
|
147
|
+
let pulseRunning = false;
|
|
148
|
+
let authorityLost = false;
|
|
149
|
+
const pulse = async () => {
|
|
150
|
+
if (pulseRunning) return;
|
|
151
|
+
pulseRunning = true;
|
|
152
|
+
try {
|
|
153
|
+
if (!(await browserDeadlineCheckpoint(db, target, { touch: true })))
|
|
154
|
+
authorityLost = true;
|
|
155
|
+
} finally {
|
|
156
|
+
pulseRunning = false;
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
timer = setInterval(() => {
|
|
160
|
+
void pulse().catch(() => undefined);
|
|
161
|
+
}, 5_000);
|
|
162
|
+
const lease = await readLease(db, target.workspaceId, target.sandboxGroupId);
|
|
163
|
+
if (
|
|
164
|
+
!lease ||
|
|
165
|
+
lease.instanceId !== target.instanceId ||
|
|
166
|
+
lease.leaseEpoch !== target.leaseEpoch ||
|
|
167
|
+
!lease.resumeState
|
|
168
|
+
) {
|
|
169
|
+
throw new Error("browser deadline checkpoint placement changed");
|
|
170
|
+
}
|
|
171
|
+
const placement = {
|
|
172
|
+
kind: "sandbox_group" as const,
|
|
173
|
+
sandboxGroupId: target.sandboxGroupId,
|
|
174
|
+
};
|
|
175
|
+
const client = await connectController({ target, lease, settings, controllerRoot });
|
|
176
|
+
if (authorityLost || !(await browserDeadlineCheckpoint(db, target, { touch: true }))) {
|
|
177
|
+
throw new Error("browser deadline checkpoint authority changed");
|
|
178
|
+
}
|
|
179
|
+
if (claim.state !== "completed") {
|
|
180
|
+
const scope = { ...target, operationId: claim.operationId };
|
|
181
|
+
const objectKey = browserStateObjectKey(target.workspaceId, claim.operationId);
|
|
182
|
+
dataKey = deriveBrowserStateDataKey(rootKey, { ...scope, objectKey });
|
|
183
|
+
aad = browserStateArtifactAad({ ...scope, objectKey });
|
|
184
|
+
await dispatchBrowserSessionOperation(db, {
|
|
185
|
+
...scope,
|
|
186
|
+
deadlineTarget: target,
|
|
187
|
+
stateUpload: {
|
|
188
|
+
objectKey,
|
|
189
|
+
cleanupAfter: new Date(Date.now() + UPLOAD_CLEANUP_GRACE_MS),
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
const signed = await objectStorage.createPutUrl({
|
|
193
|
+
key: objectKey,
|
|
194
|
+
contentType: BROWSER_STATE_ARTIFACT_CONTENT_TYPE,
|
|
195
|
+
audience: "sandbox",
|
|
196
|
+
});
|
|
197
|
+
const receipt = await client
|
|
198
|
+
.captureState({
|
|
199
|
+
...scope,
|
|
200
|
+
objectKey,
|
|
201
|
+
afterCapture: "stop",
|
|
202
|
+
dataKey,
|
|
203
|
+
aad,
|
|
204
|
+
upload: {
|
|
205
|
+
url: signed.url,
|
|
206
|
+
requiredHeaders: signed.requiredHeaders,
|
|
207
|
+
expiresAt: signed.expiresAt.toISOString(),
|
|
208
|
+
},
|
|
209
|
+
})
|
|
210
|
+
.catch(async (error: unknown) => {
|
|
211
|
+
if (
|
|
212
|
+
error instanceof BrowserControlRequestError &&
|
|
213
|
+
(error.error.code === "outcome_unknown" || !error.error.retryable)
|
|
214
|
+
) {
|
|
215
|
+
await failBrowserSessionSuspension(db, { ...scope, error: error.error });
|
|
216
|
+
}
|
|
217
|
+
throw error;
|
|
218
|
+
});
|
|
219
|
+
if (authorityLost) throw new Error("browser deadline checkpoint authority changed");
|
|
220
|
+
const portable = receipt.manifest.profileCrypto !== "platform_bound";
|
|
221
|
+
await commitBrowserSessionSuspension(db, {
|
|
222
|
+
...scope,
|
|
223
|
+
deadlineTarget: target,
|
|
224
|
+
artifact: {
|
|
225
|
+
kind: "chromium_profile",
|
|
226
|
+
format: receipt.format,
|
|
227
|
+
objectKey,
|
|
228
|
+
artifactDigest: receipt.artifactDigest,
|
|
229
|
+
contentDigest: receipt.contentDigest,
|
|
230
|
+
manifestDigest: browserStateManifestDigest(receipt.manifest),
|
|
231
|
+
sizeBytes: receipt.sizeBytes,
|
|
232
|
+
encryptedDataKey: wrapBrowserStateDataKey(rootKey, dataKey, {
|
|
233
|
+
...scope,
|
|
234
|
+
objectKey,
|
|
235
|
+
artifactDigest: receipt.artifactDigest,
|
|
236
|
+
contentDigest: receipt.contentDigest,
|
|
237
|
+
}),
|
|
238
|
+
materialization: {
|
|
239
|
+
portability: portable ? "portable" : "placement_bound",
|
|
240
|
+
reason: portable
|
|
241
|
+
? null
|
|
242
|
+
: "Profile encryption depends on the source operating-system credential store.",
|
|
243
|
+
platform: receipt.manifest.platform,
|
|
244
|
+
architecture: receipt.manifest.architecture,
|
|
245
|
+
engine: receipt.manifest.engine,
|
|
246
|
+
engineVersion: receipt.manifest.engineVersion,
|
|
247
|
+
driverId: receipt.manifest.driverId,
|
|
248
|
+
driverSchemaVersion: receipt.manifest.driverSchemaVersion,
|
|
249
|
+
profileCrypto: receipt.manifest.profileCrypto,
|
|
250
|
+
providerId: null,
|
|
251
|
+
placement: portable ? null : placement,
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
// Only remove the local profile after the encrypted artifact and its
|
|
257
|
+
// authority committed. A crash resumes this cleanup, never capture.
|
|
258
|
+
await client.endSession(target, { removeState: true }).catch((error: unknown) => {
|
|
259
|
+
if (!(error instanceof BrowserControlRequestError && error.status === 404)) throw error;
|
|
260
|
+
});
|
|
261
|
+
await withRlsContext(
|
|
262
|
+
db,
|
|
263
|
+
target,
|
|
264
|
+
async (tx) => {
|
|
265
|
+
if ((await browserDeadlineCheckpoint(tx, target))?.state !== "completed") {
|
|
266
|
+
throw new Error("browser deadline checkpoint cleanup authority changed");
|
|
267
|
+
}
|
|
268
|
+
await clearSuspendedBrowserSessionController(tx, {
|
|
269
|
+
...target,
|
|
270
|
+
expectedControllerGeneration: target.controllerGeneration,
|
|
271
|
+
});
|
|
272
|
+
// One transaction prevents a human resume from acquiring a new
|
|
273
|
+
// same-browser holder between clearing and releasing the old one.
|
|
274
|
+
await releaseLeaseHolder(tx, {
|
|
275
|
+
...target,
|
|
276
|
+
kind: "interaction",
|
|
277
|
+
holderId: `browser-session:${target.browserSessionId}`,
|
|
278
|
+
// The idle window already elapsed before this save began, so
|
|
279
|
+
// a box the saved browser was last to hold drains now.
|
|
280
|
+
idleGraceMs: target.reason === "idle" ? 0 : settings.sandboxIdleGraceMs,
|
|
281
|
+
preserveHoldersChangedAt: target.reason === "idle",
|
|
282
|
+
});
|
|
283
|
+
},
|
|
284
|
+
undefined,
|
|
285
|
+
"none",
|
|
286
|
+
);
|
|
287
|
+
return { status: "suspended" as const };
|
|
288
|
+
} finally {
|
|
289
|
+
if (timer) clearInterval(timer);
|
|
290
|
+
dataKey?.fill(0);
|
|
291
|
+
aad?.fill(0);
|
|
292
|
+
rootKey.fill(0);
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
},
|
|
296
|
+
};
|
|
297
|
+
}
|
|
@@ -1,36 +1,18 @@
|
|
|
1
|
+
import { environmentsEncryptionKeyBytes, type Settings } from "@opengeni/config";
|
|
1
2
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
withOrganizationGatewayCatalogProvider,
|
|
12
|
-
withOrganizationGatewayCredential,
|
|
13
|
-
withOrganizationOpenRouterCatalogProvider,
|
|
14
|
-
withOrganizationOpenRouterCredential,
|
|
15
|
-
ORGANIZATION_GATEWAY_MODEL_ID_PREFIX,
|
|
16
|
-
ORGANIZATION_OPENROUTER_MODEL_ID_PREFIX,
|
|
17
|
-
withXaiSubscriptionCatalogProvider,
|
|
18
|
-
} from "@opengeni/config";
|
|
19
|
-
import { settingsWithEnabledCapabilityMcpServers } from "@opengeni/core";
|
|
3
|
+
settingsWithCodexCredential as coreSettingsWithCodexCredential,
|
|
4
|
+
settingsWithEnabledCapabilityMcpServers,
|
|
5
|
+
settingsWithOrganizationProviderCredentials as coreSettingsWithOrganizationProviderCredentials,
|
|
6
|
+
settingsWithWorkspaceGatewayCredential as coreSettingsWithWorkspaceGatewayCredential,
|
|
7
|
+
settingsWithWorkspaceOpenRouterCredential as coreSettingsWithWorkspaceOpenRouterCredential,
|
|
8
|
+
settingsWithWorkspaceOpperCredential as coreSettingsWithWorkspaceOpperCredential,
|
|
9
|
+
withCodexProvider as coreWithCodexProvider,
|
|
10
|
+
withXaiSubscriptionProvider as coreWithXaiSubscriptionProvider,
|
|
11
|
+
} from "@opengeni/core";
|
|
20
12
|
import {
|
|
21
|
-
getWorkspaceGatewayCustomModelForExecution,
|
|
22
|
-
getWorkspaceOpenRouterCustomModelForExecution,
|
|
23
13
|
listSessionMcpServerMetadata,
|
|
24
14
|
listSessionMcpServersForRun,
|
|
25
15
|
getSessionAttemptMcpApprovalPolicies,
|
|
26
|
-
listWorkspaceGatewayCustomModels,
|
|
27
|
-
listWorkspaceOpenRouterCustomModels,
|
|
28
|
-
workspaceCodexSubscriptionActive,
|
|
29
|
-
loadWorkspaceVercelAiGatewayApiKey,
|
|
30
|
-
loadWorkspaceOpenRouterApiKey,
|
|
31
|
-
listOrganizationModelProviderCustomModelsForWorkspace,
|
|
32
|
-
getOrganizationModelProviderCustomModelForExecution,
|
|
33
|
-
loadOrganizationModelProviderApiKey,
|
|
34
16
|
type Database,
|
|
35
17
|
type SessionMcpServerForRun,
|
|
36
18
|
} from "@opengeni/db";
|
|
@@ -48,12 +30,28 @@ export async function settingsWithSessionMcpServersForRun(
|
|
|
48
30
|
},
|
|
49
31
|
): Promise<Settings> {
|
|
50
32
|
const encryptionKey = environmentsEncryptionKeyBytes(settings);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
33
|
+
let policies: Awaited<ReturnType<typeof getSessionAttemptMcpApprovalPolicies>>;
|
|
34
|
+
let resolvedServers: SessionMcpServerForRun[] | undefined;
|
|
35
|
+
if (encryptionKey && typeof (db as Database & { rollback?: unknown }).rollback !== "function") {
|
|
36
|
+
// Both readers independently fence this exact active attempt. The server
|
|
37
|
+
// read must remain fresh for credential renewal; it does not consume the
|
|
38
|
+
// policy read's result. Root-pool RLS transactions may overlap, whereas
|
|
39
|
+
// nested scopes on a transaction handle must retain serial savepoints.
|
|
40
|
+
const [policyResult, serverResult] = await Promise.allSettled([
|
|
41
|
+
(async () =>
|
|
42
|
+
await getSessionAttemptMcpApprovalPolicies(db, workspaceId, sessionId, attemptId))(),
|
|
43
|
+
(async () =>
|
|
44
|
+
await listSessionMcpServersForRun(db, workspaceId, sessionId, attemptId, encryptionKey))(),
|
|
45
|
+
]);
|
|
46
|
+
// Observe both reads before returning or propagating an error. Preserve the
|
|
47
|
+
// previous policy-first diagnostic priority, including synchronous ports.
|
|
48
|
+
if (policyResult.status === "rejected") throw policyResult.reason;
|
|
49
|
+
if (serverResult.status === "rejected") throw serverResult.reason;
|
|
50
|
+
policies = policyResult.value;
|
|
51
|
+
resolvedServers = serverResult.value;
|
|
52
|
+
} else {
|
|
53
|
+
policies = await getSessionAttemptMcpApprovalPolicies(db, workspaceId, sessionId, attemptId);
|
|
54
|
+
}
|
|
57
55
|
const policySettings = {
|
|
58
56
|
...settings,
|
|
59
57
|
mcpServers: settings.mcpServers.map((server) =>
|
|
@@ -73,13 +71,15 @@ export async function settingsWithSessionMcpServersForRun(
|
|
|
73
71
|
);
|
|
74
72
|
}
|
|
75
73
|
}
|
|
76
|
-
const servers =
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
74
|
+
const servers =
|
|
75
|
+
resolvedServers ??
|
|
76
|
+
(await listSessionMcpServersForRun(
|
|
77
|
+
db,
|
|
78
|
+
workspaceId,
|
|
79
|
+
sessionId,
|
|
80
|
+
attemptId,
|
|
81
|
+
encryptionKey ?? null,
|
|
82
|
+
));
|
|
83
83
|
// Keep credential provenance coupled to the exact decrypted rows that are
|
|
84
84
|
// overlaid into settings. A session projection read earlier in the turn can
|
|
85
85
|
// be stale after a concurrent mcpCredentialUpdates renewal.
|
|
@@ -116,175 +116,15 @@ export function settingsWithSessionMcpServers(
|
|
|
116
116
|
};
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
export
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
): Promise<Settings> {
|
|
132
|
-
// Same active-credential predicate the billing bypass uses, so provider
|
|
133
|
-
// injection and billing can never disagree on what an "active codex" turn is.
|
|
134
|
-
// The caller may pass `activeOverride` (a single, shared read; P2-b) so routing
|
|
135
|
-
// and billing decide from the exact same observation, immune to a concurrent
|
|
136
|
-
// disconnect/reconnect landing between two independent reads.
|
|
137
|
-
const active =
|
|
138
|
-
activeOverride ?? (await workspaceCodexSubscriptionActive(db, settings, workspaceId));
|
|
139
|
-
if (!active) {
|
|
140
|
-
return settings; // disabled / not connected / needs_relogin / error -> leave settings unchanged
|
|
141
|
-
}
|
|
142
|
-
const withProvider = withCodexProvider(settings);
|
|
143
|
-
return withProvider;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/** Pure: append the synthetic codex-subscription provider, idempotently. */
|
|
147
|
-
export function withCodexProvider(settings: Settings): Settings {
|
|
148
|
-
return withCodexCatalogProvider(settings);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Pure: append the synthetic SuperGrok/xAI subscription provider,
|
|
153
|
-
* idempotently. The overlay is catalogue metadata only; the exact account,
|
|
154
|
-
* authority snapshot, and bearer remain frozen later at turn admission.
|
|
155
|
-
*/
|
|
156
|
-
export function withXaiSubscriptionProvider(settings: Settings): Settings {
|
|
157
|
-
return withXaiSubscriptionCatalogProvider(settings);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export async function settingsWithWorkspaceGatewayCredential(
|
|
161
|
-
db: Database,
|
|
162
|
-
accountId: string,
|
|
163
|
-
workspaceId: string,
|
|
164
|
-
settings: Settings,
|
|
165
|
-
retainedProductModelId?: string | null,
|
|
166
|
-
): Promise<Settings> {
|
|
167
|
-
const activeCustomModels = await listWorkspaceGatewayCustomModels(db, {
|
|
168
|
-
accountId,
|
|
169
|
-
workspaceId,
|
|
170
|
-
});
|
|
171
|
-
const retainedUpstreamModelId = retainedProductModelId?.startsWith(
|
|
172
|
-
WORKSPACE_GATEWAY_MODEL_ID_PREFIX,
|
|
173
|
-
)
|
|
174
|
-
? retainedProductModelId.slice(WORKSPACE_GATEWAY_MODEL_ID_PREFIX.length)
|
|
175
|
-
: null;
|
|
176
|
-
const retainedCustomModel = retainedUpstreamModelId
|
|
177
|
-
? await getWorkspaceGatewayCustomModelForExecution(db, {
|
|
178
|
-
accountId,
|
|
179
|
-
workspaceId,
|
|
180
|
-
upstreamModelId: retainedUpstreamModelId,
|
|
181
|
-
})
|
|
182
|
-
: null;
|
|
183
|
-
const customModels =
|
|
184
|
-
retainedCustomModel &&
|
|
185
|
-
!activeCustomModels.some(
|
|
186
|
-
(model) => model.upstreamModelId === retainedCustomModel.upstreamModelId,
|
|
187
|
-
)
|
|
188
|
-
? [...activeCustomModels, retainedCustomModel]
|
|
189
|
-
: activeCustomModels;
|
|
190
|
-
const catalogSettings = withWorkspaceGatewayCatalogProvider(settings, customModels);
|
|
191
|
-
const apiKey = await loadWorkspaceVercelAiGatewayApiKey(
|
|
192
|
-
db,
|
|
193
|
-
settings,
|
|
194
|
-
workspaceId,
|
|
195
|
-
retainedProductModelId,
|
|
196
|
-
);
|
|
197
|
-
return apiKey
|
|
198
|
-
? withWorkspaceGatewayCredential(catalogSettings, apiKey, customModels)
|
|
199
|
-
: catalogSettings;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
export async function settingsWithWorkspaceOpenRouterCredential(
|
|
203
|
-
db: Database,
|
|
204
|
-
accountId: string,
|
|
205
|
-
workspaceId: string,
|
|
206
|
-
settings: Settings,
|
|
207
|
-
retainedProductModelId?: string | null,
|
|
208
|
-
): Promise<Settings> {
|
|
209
|
-
const activeCustomModels = await listWorkspaceOpenRouterCustomModels(db, {
|
|
210
|
-
accountId,
|
|
211
|
-
workspaceId,
|
|
212
|
-
});
|
|
213
|
-
const retainedUpstreamModelId = retainedProductModelId?.startsWith(
|
|
214
|
-
WORKSPACE_OPENROUTER_MODEL_ID_PREFIX,
|
|
215
|
-
)
|
|
216
|
-
? retainedProductModelId.slice(WORKSPACE_OPENROUTER_MODEL_ID_PREFIX.length)
|
|
217
|
-
: null;
|
|
218
|
-
const retainedCustomModel = retainedUpstreamModelId
|
|
219
|
-
? await getWorkspaceOpenRouterCustomModelForExecution(db, {
|
|
220
|
-
accountId,
|
|
221
|
-
workspaceId,
|
|
222
|
-
upstreamModelId: retainedUpstreamModelId,
|
|
223
|
-
})
|
|
224
|
-
: null;
|
|
225
|
-
const customModels =
|
|
226
|
-
retainedCustomModel &&
|
|
227
|
-
!activeCustomModels.some(
|
|
228
|
-
(model) => model.upstreamModelId === retainedCustomModel.upstreamModelId,
|
|
229
|
-
)
|
|
230
|
-
? [...activeCustomModels, retainedCustomModel]
|
|
231
|
-
: activeCustomModels;
|
|
232
|
-
const catalogSettings = withWorkspaceOpenRouterCatalogProvider(settings, customModels);
|
|
233
|
-
const apiKey = await loadWorkspaceOpenRouterApiKey(
|
|
234
|
-
db,
|
|
235
|
-
settings,
|
|
236
|
-
workspaceId,
|
|
237
|
-
retainedProductModelId,
|
|
238
|
-
);
|
|
239
|
-
return apiKey
|
|
240
|
-
? withWorkspaceOpenRouterCredential(catalogSettings, apiKey, customModels)
|
|
241
|
-
: catalogSettings;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
export async function settingsWithOrganizationProviderCredentials(
|
|
245
|
-
db: Database,
|
|
246
|
-
accountId: string,
|
|
247
|
-
workspaceId: string,
|
|
248
|
-
settings: Settings,
|
|
249
|
-
retainedProductModelId?: string | null,
|
|
250
|
-
): Promise<Settings> {
|
|
251
|
-
const buildModels = async (providerKind: "vercel_gateway" | "openrouter", prefix: string) => {
|
|
252
|
-
const active = await listOrganizationModelProviderCustomModelsForWorkspace(db, {
|
|
253
|
-
accountId,
|
|
254
|
-
workspaceId,
|
|
255
|
-
providerKind,
|
|
256
|
-
});
|
|
257
|
-
const upstreamModelId = retainedProductModelId?.startsWith(prefix)
|
|
258
|
-
? retainedProductModelId.slice(prefix.length)
|
|
259
|
-
: null;
|
|
260
|
-
const retained = upstreamModelId
|
|
261
|
-
? await getOrganizationModelProviderCustomModelForExecution(db, {
|
|
262
|
-
accountId,
|
|
263
|
-
workspaceId,
|
|
264
|
-
providerKind,
|
|
265
|
-
upstreamModelId,
|
|
266
|
-
})
|
|
267
|
-
: null;
|
|
268
|
-
return retained && !active.some((model) => model.id === retained.id)
|
|
269
|
-
? [...active, retained]
|
|
270
|
-
: active;
|
|
271
|
-
};
|
|
272
|
-
const gatewayModels = await buildModels("vercel_gateway", ORGANIZATION_GATEWAY_MODEL_ID_PREFIX);
|
|
273
|
-
const openRouterModels = await buildModels("openrouter", ORGANIZATION_OPENROUTER_MODEL_ID_PREFIX);
|
|
274
|
-
const gatewayKey = await loadOrganizationModelProviderApiKey(db, settings, {
|
|
275
|
-
accountId,
|
|
276
|
-
workspaceId,
|
|
277
|
-
providerKind: "vercel_gateway",
|
|
278
|
-
});
|
|
279
|
-
const gatewaySettings = gatewayKey
|
|
280
|
-
? withOrganizationGatewayCredential(settings, gatewayKey, gatewayModels)
|
|
281
|
-
: withOrganizationGatewayCatalogProvider(settings, gatewayModels);
|
|
282
|
-
const openRouterKey = await loadOrganizationModelProviderApiKey(db, settings, {
|
|
283
|
-
accountId,
|
|
284
|
-
workspaceId,
|
|
285
|
-
providerKind: "openrouter",
|
|
286
|
-
});
|
|
287
|
-
return openRouterKey
|
|
288
|
-
? withOrganizationOpenRouterCredential(gatewaySettings, openRouterKey, openRouterModels)
|
|
289
|
-
: withOrganizationOpenRouterCatalogProvider(gatewaySettings, openRouterModels);
|
|
290
|
-
}
|
|
119
|
+
// Provider credential overlays live in core so stateless single model calls
|
|
120
|
+
// resolve providers exactly like agent turns. These module-local bindings keep
|
|
121
|
+
// the claim's call sites (and their test seams) unchanged.
|
|
122
|
+
export const settingsWithCodexCredential = coreSettingsWithCodexCredential;
|
|
123
|
+
export const withCodexProvider = coreWithCodexProvider;
|
|
124
|
+
export const withXaiSubscriptionProvider = coreWithXaiSubscriptionProvider;
|
|
125
|
+
export const settingsWithWorkspaceGatewayCredential = coreSettingsWithWorkspaceGatewayCredential;
|
|
126
|
+
export const settingsWithWorkspaceOpenRouterCredential =
|
|
127
|
+
coreSettingsWithWorkspaceOpenRouterCredential;
|
|
128
|
+
export const settingsWithWorkspaceOpperCredential = coreSettingsWithWorkspaceOpperCredential;
|
|
129
|
+
export const settingsWithOrganizationProviderCredentials =
|
|
130
|
+
coreSettingsWithOrganizationProviderCredentials;
|