@opengeni/worker-bundle 2.0.1 → 2.0.2-canary.38789554071001
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 +185 -26
- 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 +4 -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 +31 -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-5IIVRXLA.js} +1569 -2883
- package/dist/activities-control-5IIVRXLA.js.map +1 -0
- package/dist/activities-control.d.ts +64 -4
- package/dist/{activities-turn-YVVKCGAK.js → activities-turn-FLYJOM54.js} +9300 -4403
- package/dist/activities-turn-FLYJOM54.js.map +1 -0
- package/dist/activities.d.ts +64 -4
- package/dist/artifact-materializer-entry.js +107 -36
- 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-MVESOYFC.js +3746 -0
- package/dist/chunk-MVESOYFC.js.map +1 -0
- package/dist/{chunk-M3NVMF2V.js → chunk-N57B3PJ5.js} +2307 -3951
- package/dist/chunk-N57B3PJ5.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 +1152 -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 +42 -12
- 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 +114 -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 +634 -111
- 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 +182 -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 +124 -9
- package/src/activities/sandbox-lease.ts +1615 -73
- package/src/activities/scheduled-tasks.ts +780 -147
- 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 +85 -39
- 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
|
@@ -11,9 +11,6 @@ import {
|
|
|
11
11
|
markVideoGenerationRetaining,
|
|
12
12
|
markVideoGenerationSubmissionIntent,
|
|
13
13
|
markVideoGenerationSubmissionUncertain,
|
|
14
|
-
materializeXaiCredentialForRun,
|
|
15
|
-
refreshXaiSubscriptionCredentialSerialized,
|
|
16
|
-
rotateVideoGenerationCredential,
|
|
17
14
|
markVideoGenerationTerminalUpdate,
|
|
18
15
|
markVideoGenerationTerminalUpdateInTransaction,
|
|
19
16
|
mediaGenerationResultForStoredOperation,
|
|
@@ -21,8 +18,12 @@ import {
|
|
|
21
18
|
rescheduleVideoGenerationOperation,
|
|
22
19
|
settleVideoGenerationFailure,
|
|
23
20
|
settleVideoGenerationReady,
|
|
24
|
-
type XaiCredentialForRun,
|
|
25
21
|
type VideoGenerationOperationWithReferences,
|
|
22
|
+
cancelVideoGenerationBeforeSubmit,
|
|
23
|
+
SUBSCRIPTION_CORE_XAI,
|
|
24
|
+
SUBSCRIPTION_CORE_XAI_PROVIDER,
|
|
25
|
+
subscriptionCoreXaiBearer,
|
|
26
|
+
subscriptionCoreXaiFetch,
|
|
26
27
|
} from "@opengeni/db";
|
|
27
28
|
import { publishDurableSessionEvents } from "@opengeni/events";
|
|
28
29
|
import type { ObjectStorage } from "@opengeni/storage";
|
|
@@ -37,17 +38,16 @@ import {
|
|
|
37
38
|
downloadGeneratedVideoToVerifiedTemp,
|
|
38
39
|
retainVerifiedGeneratedVideo,
|
|
39
40
|
} from "./video-output-retention";
|
|
41
|
+
import { decryptVideoGenerationCredential } from "./video-generation-credential";
|
|
40
42
|
import {
|
|
41
|
-
decryptVideoGenerationCredential,
|
|
42
|
-
encryptVideoGenerationXaiCredential,
|
|
43
|
-
type VideoGenerationProviderCredential,
|
|
44
|
-
} from "./video-generation-credential";
|
|
45
|
-
import {
|
|
46
|
-
refreshXaiToken,
|
|
47
43
|
XaiSubscriptionError,
|
|
48
|
-
|
|
44
|
+
type XaiFetch,
|
|
49
45
|
type XaiSubscriptionRequestContext,
|
|
50
46
|
} from "@opengeni/xai-subscription";
|
|
47
|
+
import {
|
|
48
|
+
SubscriptionCoreVideoDispatchRejected,
|
|
49
|
+
withSubscriptionCoreVideoConnection,
|
|
50
|
+
} from "./video-generation-subscription-core";
|
|
51
51
|
import {
|
|
52
52
|
buildXaiVideoStartBody,
|
|
53
53
|
getXaiVideoGenerationStatus,
|
|
@@ -92,16 +92,124 @@ export async function reconcileVideoGenerationOperation(
|
|
|
92
92
|
if (!operation.credentialEncrypted) {
|
|
93
93
|
throw new Error("Video provider credential lease was erased too early");
|
|
94
94
|
}
|
|
95
|
-
const providerCredential = decryptVideoGenerationCredential(key, operation.credentialEncrypted);
|
|
96
95
|
const usesSuperGrok = operation.fundingSource === "supergrok_subscription";
|
|
97
|
-
|
|
96
|
+
let providerCredential: ReturnType<typeof decryptVideoGenerationCredential>;
|
|
97
|
+
try {
|
|
98
|
+
providerCredential = decryptVideoGenerationCredential(key, operation.credentialEncrypted);
|
|
99
|
+
} catch (error) {
|
|
100
|
+
// A SuperGrok envelope the cutover did not convert (a legacy token
|
|
101
|
+
// envelope or a restored row) is never decoded: like an unavailable
|
|
102
|
+
// connection it waits until the recovery deadline, then ends.
|
|
103
|
+
if (usesSuperGrok) return await subscriptionConnectionUnavailable(service, input, operation);
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
if (
|
|
107
|
+
usesSuperGrok &&
|
|
108
|
+
(providerCredential.kind !== "subscription-connection" ||
|
|
109
|
+
providerCredential.provider !== SUBSCRIPTION_CORE_XAI_PROVIDER)
|
|
110
|
+
) {
|
|
111
|
+
return await subscriptionConnectionUnavailable(service, input, operation);
|
|
112
|
+
}
|
|
113
|
+
if (usesSuperGrok !== (providerCredential.kind !== "api-key")) {
|
|
98
114
|
throw new Error("Video provider credential does not match its funding source");
|
|
99
115
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
116
|
+
if (providerCredential.kind === "subscription-connection") {
|
|
117
|
+
// After the SuperGrok cutover: the canonical connection under a `video`
|
|
118
|
+
// operation lease, refreshed only under the core lock (EP-N13/EP-N14).
|
|
119
|
+
const ran = await withSubscriptionCoreVideoConnection(
|
|
120
|
+
service.db,
|
|
121
|
+
service.settings,
|
|
122
|
+
SUBSCRIPTION_CORE_XAI,
|
|
123
|
+
operation,
|
|
124
|
+
providerCredential.connectionId,
|
|
125
|
+
subscriptionCoreXaiBearer,
|
|
126
|
+
async ({ auth, fetch }) =>
|
|
127
|
+
await reconcileWithProviderCredential(service, input, storage, key, operation, {
|
|
128
|
+
apiKey: null,
|
|
129
|
+
xai: {
|
|
130
|
+
auth,
|
|
131
|
+
fetch: subscriptionCoreXaiFetch(fetch) as XaiFetch,
|
|
132
|
+
},
|
|
133
|
+
}),
|
|
134
|
+
);
|
|
135
|
+
if (ran.kind === "ran") return ran.value;
|
|
136
|
+
return await subscriptionConnectionUnavailable(service, input, operation);
|
|
137
|
+
}
|
|
138
|
+
return await reconcileWithProviderCredential(service, input, storage, key, operation, {
|
|
139
|
+
apiKey: providerCredential.apiKey,
|
|
140
|
+
xai: null,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
type XaiVideoAuth = {
|
|
145
|
+
auth: Pick<XaiSubscriptionRequestContext, "getToken" | "refresh">;
|
|
146
|
+
fetch?: XaiFetch;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* The operation's subscription connection cannot serve it now (the session
|
|
151
|
+
* or its owner context is gone, the lease was refused, the connection needs
|
|
152
|
+
* a new sign-in or left the pool): wait until the recovery deadline, then
|
|
153
|
+
* end it (decision 6). Nothing reached the provider in this run.
|
|
154
|
+
*/
|
|
155
|
+
async function subscriptionConnectionUnavailable(
|
|
156
|
+
service: TurnActivityServices,
|
|
157
|
+
input: { accountId: string; workspaceId: string; operationId: string },
|
|
158
|
+
start: VideoGenerationOperationWithReferences,
|
|
159
|
+
): Promise<VideoGenerationReconcileResult> {
|
|
160
|
+
let operation = start;
|
|
161
|
+
const mutation = {
|
|
162
|
+
accountId: input.accountId,
|
|
163
|
+
workspaceId: input.workspaceId,
|
|
164
|
+
operationId: operation.id,
|
|
165
|
+
requestDigest: operation.requestDigest,
|
|
166
|
+
};
|
|
167
|
+
const reason = "The connected subscription funding this video is not available";
|
|
168
|
+
if (Date.now() < operation.recoveryDeadlineAt.getTime()) {
|
|
169
|
+
await rescheduleVideoGenerationOperation(service.db, {
|
|
170
|
+
...mutation,
|
|
171
|
+
nextReconcileAt: nextPoll(service),
|
|
172
|
+
error: reason,
|
|
173
|
+
});
|
|
174
|
+
return waitResult(service);
|
|
175
|
+
}
|
|
176
|
+
operation = retainReferences(
|
|
177
|
+
operation,
|
|
178
|
+
operation.status === "retaining"
|
|
179
|
+
? await settleVideoGenerationFailure(service.db, {
|
|
180
|
+
...mutation,
|
|
181
|
+
status: "retention_failed",
|
|
182
|
+
publicReason: "The generated video could not be retained.",
|
|
183
|
+
privateError: reason,
|
|
184
|
+
})
|
|
185
|
+
: operation.status === "submission_uncertain" || operation.status === "provider_started"
|
|
186
|
+
? await settleVideoGenerationFailure(service.db, {
|
|
187
|
+
...mutation,
|
|
188
|
+
status: "outcome_unknown",
|
|
189
|
+
publicReason:
|
|
190
|
+
"The connected subscription that started this video is no longer available.",
|
|
191
|
+
privateError: reason,
|
|
192
|
+
})
|
|
193
|
+
: await cancelVideoGenerationBeforeSubmit(service.db, {
|
|
194
|
+
...mutation,
|
|
195
|
+
reason: "The connected subscription funding this video is no longer available.",
|
|
196
|
+
}),
|
|
197
|
+
);
|
|
198
|
+
await deliverTerminalResult(service, operation);
|
|
199
|
+
return { action: "terminal", status: terminalStatus(operation.status) };
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
async function reconcileWithProviderCredential(
|
|
203
|
+
service: TurnActivityServices,
|
|
204
|
+
input: { accountId: string; workspaceId: string; operationId: string },
|
|
205
|
+
storage: ObjectStorage,
|
|
206
|
+
key: Uint8Array,
|
|
207
|
+
start: VideoGenerationOperationWithReferences,
|
|
208
|
+
credential: { apiKey: string | null; xai: XaiVideoAuth | null },
|
|
209
|
+
): Promise<VideoGenerationReconcileResult> {
|
|
210
|
+
let operation = start;
|
|
211
|
+
const usesSuperGrok = operation.fundingSource === "supergrok_subscription";
|
|
212
|
+
const { apiKey, xai: xaiAuth } = credential;
|
|
105
213
|
let preparedSubmissionThisRun = false;
|
|
106
214
|
|
|
107
215
|
if (operation.status === "accepted") {
|
|
@@ -187,7 +295,7 @@ export async function reconcileVideoGenerationOperation(
|
|
|
187
295
|
? await startXaiVideoGeneration({
|
|
188
296
|
body,
|
|
189
297
|
sessionId: operation.sessionId,
|
|
190
|
-
|
|
298
|
+
...requireXaiAuth(xaiAuth),
|
|
191
299
|
})
|
|
192
300
|
: await startGatewayVideoGenerationWithBody({
|
|
193
301
|
apiKey: requireApiKey(apiKey),
|
|
@@ -208,6 +316,27 @@ export async function reconcileVideoGenerationOperation(
|
|
|
208
316
|
);
|
|
209
317
|
return waitResult(service);
|
|
210
318
|
} catch (error) {
|
|
319
|
+
if (error instanceof SubscriptionCoreVideoDispatchRejected) {
|
|
320
|
+
// Verified: the start never reached the provider (the operation
|
|
321
|
+
// lease's fence failed, or the bearer was refused and could not be
|
|
322
|
+
// renewed). The frozen request cannot be replayed on the core path,
|
|
323
|
+
// so the operation ends as a known failure, never outcome-unknown.
|
|
324
|
+
operation = retainReferences(
|
|
325
|
+
operation,
|
|
326
|
+
await settleVideoGenerationFailure(service.db, {
|
|
327
|
+
accountId: input.accountId,
|
|
328
|
+
workspaceId: input.workspaceId,
|
|
329
|
+
operationId: operation.id,
|
|
330
|
+
requestDigest: operation.requestDigest,
|
|
331
|
+
status: "provider_failed",
|
|
332
|
+
publicReason:
|
|
333
|
+
"The connected subscription funding this video could not start it. Nothing was generated.",
|
|
334
|
+
privateError: privateError(error),
|
|
335
|
+
}),
|
|
336
|
+
);
|
|
337
|
+
await deliverTerminalResult(service, operation);
|
|
338
|
+
return { action: "terminal", status: terminalStatus(operation.status) };
|
|
339
|
+
}
|
|
211
340
|
if (isPermanentProviderFailure(error)) {
|
|
212
341
|
operation = retainReferences(
|
|
213
342
|
operation,
|
|
@@ -246,7 +375,7 @@ export async function reconcileVideoGenerationOperation(
|
|
|
246
375
|
? await getXaiVideoGenerationStatus({
|
|
247
376
|
providerJobId: operation.providerJobId,
|
|
248
377
|
sessionId: operation.sessionId,
|
|
249
|
-
|
|
378
|
+
...requireXaiAuth(xaiAuth),
|
|
250
379
|
})
|
|
251
380
|
: await getGatewayVideoGenerationStatus({
|
|
252
381
|
apiKey: requireApiKey(apiKey),
|
|
@@ -614,121 +743,11 @@ function requireApiKey(value: string | null): string {
|
|
|
614
743
|
return value;
|
|
615
744
|
}
|
|
616
745
|
|
|
617
|
-
function requireXaiAuth(
|
|
618
|
-
value: Pick<XaiSubscriptionRequestContext, "getToken" | "refresh"> | null,
|
|
619
|
-
): Pick<XaiSubscriptionRequestContext, "getToken" | "refresh"> {
|
|
746
|
+
function requireXaiAuth(value: XaiVideoAuth | null): XaiVideoAuth {
|
|
620
747
|
if (!value) throw new Error("SuperGrok video authorization is unavailable");
|
|
621
748
|
return value;
|
|
622
749
|
}
|
|
623
750
|
|
|
624
|
-
/**
|
|
625
|
-
* A paid video job outlives the connected-account row. Keep its frozen OAuth
|
|
626
|
-
* lease usable after disconnect, and durably replace rotated refresh tokens
|
|
627
|
-
* before exposing them to another provider call. The shared account row is a
|
|
628
|
-
* best-effort mirror only; it is never the operation's recovery authority.
|
|
629
|
-
*/
|
|
630
|
-
async function durableXaiVideoAuth(
|
|
631
|
-
service: TurnActivityServices,
|
|
632
|
-
operation: VideoGenerationOperationWithReferences,
|
|
633
|
-
key: Uint8Array,
|
|
634
|
-
credential: Extract<VideoGenerationProviderCredential, { kind: "xai-subscription" }>,
|
|
635
|
-
): Promise<Pick<XaiSubscriptionRequestContext, "getToken" | "refresh">> {
|
|
636
|
-
let current = credential;
|
|
637
|
-
const frozenEncrypted = operation.credentialEncrypted;
|
|
638
|
-
if (!frozenEncrypted) throw new Error("SuperGrok video credential lease is unavailable");
|
|
639
|
-
let currentEncrypted: string = frozenEncrypted;
|
|
640
|
-
|
|
641
|
-
let connectedAccount: XaiCredentialForRun | null = null;
|
|
642
|
-
try {
|
|
643
|
-
connectedAccount = await materializeXaiCredentialForRun(service.db, {
|
|
644
|
-
workspaceId: operation.workspaceId,
|
|
645
|
-
subjectId: current.subjectId,
|
|
646
|
-
credentialId: current.credentialId,
|
|
647
|
-
authoritySnapshot: current.authoritySnapshot,
|
|
648
|
-
encryptionKey: key,
|
|
649
|
-
});
|
|
650
|
-
} catch {
|
|
651
|
-
// Disconnect/revocation must not cancel a previously accepted paid job.
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
return {
|
|
655
|
-
getToken: async () => ({
|
|
656
|
-
accessToken: current.accessToken,
|
|
657
|
-
userId: current.userId,
|
|
658
|
-
}),
|
|
659
|
-
refresh: async () => {
|
|
660
|
-
let next: typeof current | null = null;
|
|
661
|
-
if (connectedAccount) {
|
|
662
|
-
try {
|
|
663
|
-
const result = await refreshXaiSubscriptionCredentialSerialized(service.db, {
|
|
664
|
-
accountId: operation.accountId,
|
|
665
|
-
workspaceId: operation.workspaceId,
|
|
666
|
-
subjectId: current.subjectId,
|
|
667
|
-
credentialId: current.credentialId,
|
|
668
|
-
authoritySnapshot: current.authoritySnapshot,
|
|
669
|
-
encryptionKey: key,
|
|
670
|
-
observedAccessToken: current.accessToken,
|
|
671
|
-
observedRefreshToken: current.refreshToken,
|
|
672
|
-
refresh: async (shared) => {
|
|
673
|
-
const refreshToken = shared.secret.refreshToken;
|
|
674
|
-
if (!refreshToken) {
|
|
675
|
-
throw new Error("The connected SuperGrok account cannot be refreshed");
|
|
676
|
-
}
|
|
677
|
-
const tokens = await refreshXaiToken(refreshToken);
|
|
678
|
-
return {
|
|
679
|
-
secret: {
|
|
680
|
-
version: 1,
|
|
681
|
-
accessToken: tokens.accessToken,
|
|
682
|
-
refreshToken: tokens.refreshToken,
|
|
683
|
-
},
|
|
684
|
-
expiresAt:
|
|
685
|
-
xaiAccessTokenExpiry(tokens.accessToken) ??
|
|
686
|
-
new Date(Date.now() + tokens.expiresInSeconds * 1_000),
|
|
687
|
-
};
|
|
688
|
-
},
|
|
689
|
-
});
|
|
690
|
-
connectedAccount = result.credential;
|
|
691
|
-
if (
|
|
692
|
-
connectedAccount.secret.accessToken &&
|
|
693
|
-
connectedAccount.secret.refreshToken &&
|
|
694
|
-
connectedAccount.providerAccountId
|
|
695
|
-
) {
|
|
696
|
-
next = Object.freeze({
|
|
697
|
-
...current,
|
|
698
|
-
accessToken: connectedAccount.secret.accessToken,
|
|
699
|
-
refreshToken: connectedAccount.secret.refreshToken,
|
|
700
|
-
userId: connectedAccount.providerAccountId,
|
|
701
|
-
});
|
|
702
|
-
}
|
|
703
|
-
} catch {
|
|
704
|
-
// Disconnect/revocation must not cancel a previously accepted paid job.
|
|
705
|
-
connectedAccount = null;
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
if (!next) {
|
|
709
|
-
const tokens = await refreshXaiToken(current.refreshToken);
|
|
710
|
-
next = Object.freeze({
|
|
711
|
-
...current,
|
|
712
|
-
accessToken: tokens.accessToken,
|
|
713
|
-
refreshToken: tokens.refreshToken,
|
|
714
|
-
});
|
|
715
|
-
}
|
|
716
|
-
const nextEncrypted = encryptVideoGenerationXaiCredential(key, next);
|
|
717
|
-
await rotateVideoGenerationCredential(service.db, {
|
|
718
|
-
accountId: operation.accountId,
|
|
719
|
-
workspaceId: operation.workspaceId,
|
|
720
|
-
operationId: operation.id,
|
|
721
|
-
requestDigest: operation.requestDigest,
|
|
722
|
-
expectedCredentialEncrypted: currentEncrypted,
|
|
723
|
-
credentialEncrypted: nextEncrypted,
|
|
724
|
-
});
|
|
725
|
-
current = next;
|
|
726
|
-
currentEncrypted = nextEncrypted;
|
|
727
|
-
return { accessToken: current.accessToken, userId: current.userId };
|
|
728
|
-
},
|
|
729
|
-
};
|
|
730
|
-
}
|
|
731
|
-
|
|
732
751
|
function isPermanentProviderFailure(error: unknown): boolean {
|
|
733
752
|
if (error instanceof GatewayVideoApiError) return !error.retryable;
|
|
734
753
|
if (!(error instanceof XaiSubscriptionError)) return false;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Subscription-funded video on the shared subscription core (design 5.3,
|
|
3
|
+
* EP-T17/EP-N12 funding and selection, EP-N13/EP-N14 admission and
|
|
4
|
+
* reconciliation), for any provider whose adapter funds media.
|
|
5
|
+
*
|
|
6
|
+
* - Selection: the first shared organization- or workspace-scoped candidate
|
|
7
|
+
* for the session's recorded owner (the session's explicit choice, then
|
|
8
|
+
* the effective primary, then pool order) whose stored quota is not
|
|
9
|
+
* exhausted now; none when every candidate is exhausted. Never a personal
|
|
10
|
+
* connection: a video job outlives its turn, and reconciliation has no
|
|
11
|
+
* turn authority.
|
|
12
|
+
* - Admission records a reference to that canonical connection, never token
|
|
13
|
+
* material, so no organization-scope envelope can be refused (EP-N13).
|
|
14
|
+
* - Reconciliation reads the credential through the core connection seam
|
|
15
|
+
* under a `video` operation lease on exactly that connection and refreshes
|
|
16
|
+
* only under the core lock (EP-N14). Without a usable connection the
|
|
17
|
+
* operation waits until its recovery deadline (decision 6).
|
|
18
|
+
* - Anything that stops a run before its first request reached the provider
|
|
19
|
+
* (the operation lease's fence, a refused bearer after a 401, a bearer
|
|
20
|
+
* the provider cannot use) is a `SubscriptionCoreVideoDispatchRejected`:
|
|
21
|
+
* verified, nothing reached the provider.
|
|
22
|
+
* - Nothing here reads or writes the chat session binding beyond the
|
|
23
|
+
* candidate order's explicit choice.
|
|
24
|
+
*/
|
|
25
|
+
import { environmentsEncryptionKeyBytes, type Settings } from "@opengeni/config";
|
|
26
|
+
import {
|
|
27
|
+
readSubscriptionCoreSessionOwner,
|
|
28
|
+
subscriptionCoreOperationConnections,
|
|
29
|
+
type Database,
|
|
30
|
+
type SubscriptionCoreConnectionToken,
|
|
31
|
+
type SubscriptionCoreFetch,
|
|
32
|
+
type SubscriptionCoreProvider,
|
|
33
|
+
} from "@opengeni/db";
|
|
34
|
+
import type { VideoGenerationCredentialLease } from "./video-generation-admission";
|
|
35
|
+
import { encryptVideoGenerationConnectionReference } from "./video-generation-credential";
|
|
36
|
+
|
|
37
|
+
type SessionContext = { accountId: string; workspaceId: string; sessionId: string };
|
|
38
|
+
|
|
39
|
+
/** Verified: nothing reached the provider in this run. */
|
|
40
|
+
export class SubscriptionCoreVideoDispatchRejected extends Error {
|
|
41
|
+
constructor() {
|
|
42
|
+
super("The video operation could not reach the provider on its subscription connection");
|
|
43
|
+
this.name = "SubscriptionCoreVideoDispatchRejected";
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function sessionScope(db: Database, context: SessionContext) {
|
|
48
|
+
const owner = await readSubscriptionCoreSessionOwner(db, context);
|
|
49
|
+
if (!owner) return null;
|
|
50
|
+
return {
|
|
51
|
+
kind: "session" as const,
|
|
52
|
+
...context,
|
|
53
|
+
sessionOwnerSubjectId: owner.ownerSubjectId,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The video funding lease for this session, or null when no shared
|
|
59
|
+
* connection can fund it (none assigned, or every one's stored quota is
|
|
60
|
+
* exhausted now: the provider would refuse the start).
|
|
61
|
+
*/
|
|
62
|
+
export async function subscriptionCoreVideoGenerationCredentialLease(
|
|
63
|
+
db: Database,
|
|
64
|
+
settings: Settings,
|
|
65
|
+
provider: SubscriptionCoreProvider,
|
|
66
|
+
fundingSource: VideoGenerationCredentialLease["fundingSource"],
|
|
67
|
+
context: SessionContext,
|
|
68
|
+
): Promise<VideoGenerationCredentialLease | null> {
|
|
69
|
+
const encryptionKey = environmentsEncryptionKeyBytes(settings);
|
|
70
|
+
if (!encryptionKey) return null;
|
|
71
|
+
const scope = await sessionScope(db, context);
|
|
72
|
+
if (!scope) return null;
|
|
73
|
+
const connections = subscriptionCoreOperationConnections(provider);
|
|
74
|
+
const candidates = await connections.listSubscriptionCoreOperationCandidates(db, scope);
|
|
75
|
+
if (candidates.length === 0) return null;
|
|
76
|
+
const exhausted = await connections.readSubscriptionCoreExhaustedConnectionIds(
|
|
77
|
+
db,
|
|
78
|
+
scope,
|
|
79
|
+
candidates.map((candidate) => candidate.connectionId),
|
|
80
|
+
);
|
|
81
|
+
const selected = candidates.find((candidate) => !exhausted.has(candidate.connectionId));
|
|
82
|
+
if (!selected) return null;
|
|
83
|
+
return Object.freeze({
|
|
84
|
+
fundingSource,
|
|
85
|
+
connectionId: null,
|
|
86
|
+
version: 1,
|
|
87
|
+
credentialEncrypted: encryptVideoGenerationConnectionReference(encryptionKey, {
|
|
88
|
+
provider: provider.adapter.provider,
|
|
89
|
+
connectionId: selected.connectionId,
|
|
90
|
+
}),
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Run one reconciliation step on the operation's recorded connection under
|
|
96
|
+
* a `video` operation lease. `unavailable` when the session (or its owner
|
|
97
|
+
* context) is gone, the lease is refused, or the connection's first bearer
|
|
98
|
+
* cannot be read or used (a relogin, a revoked or unassigned connection):
|
|
99
|
+
* nothing reached the provider. `bearer` maps the core token to the
|
|
100
|
+
* provider client's bearer inside the pre-dispatch guard.
|
|
101
|
+
*/
|
|
102
|
+
export async function withSubscriptionCoreVideoConnection<T, Bearer>(
|
|
103
|
+
db: Database,
|
|
104
|
+
settings: Settings,
|
|
105
|
+
provider: SubscriptionCoreProvider,
|
|
106
|
+
operation: { id: string; accountId: string; workspaceId: string; sessionId: string | null },
|
|
107
|
+
connectionId: string,
|
|
108
|
+
bearer: (token: SubscriptionCoreConnectionToken) => Bearer,
|
|
109
|
+
run: (connection: {
|
|
110
|
+
auth: { getToken: () => Promise<Bearer>; refresh: () => Promise<Bearer> };
|
|
111
|
+
fetch: SubscriptionCoreFetch;
|
|
112
|
+
}) => Promise<T>,
|
|
113
|
+
deps: { fetchImpl?: SubscriptionCoreFetch } = {},
|
|
114
|
+
): Promise<{ kind: "ran"; value: T } | { kind: "unavailable" }> {
|
|
115
|
+
if (!operation.sessionId) return { kind: "unavailable" };
|
|
116
|
+
const scope = await sessionScope(db, {
|
|
117
|
+
accountId: operation.accountId,
|
|
118
|
+
workspaceId: operation.workspaceId,
|
|
119
|
+
sessionId: operation.sessionId,
|
|
120
|
+
});
|
|
121
|
+
if (!scope) return { kind: "unavailable" };
|
|
122
|
+
const unreadable = Symbol("unreadable");
|
|
123
|
+
// Requests that reached the transport, after the core's custody reservation
|
|
124
|
+
// committed (a 401 generated nothing).
|
|
125
|
+
let dispatched = 0;
|
|
126
|
+
const transport = deps.fetchImpl ?? fetch;
|
|
127
|
+
const countedTransport: SubscriptionCoreFetch = async (input, init) => {
|
|
128
|
+
dispatched += 1;
|
|
129
|
+
const response = await transport(input, init);
|
|
130
|
+
if (response.status === 401) dispatched -= 1;
|
|
131
|
+
return response;
|
|
132
|
+
};
|
|
133
|
+
const ran = await subscriptionCoreOperationConnections(provider).runSubscriptionCoreOperation(
|
|
134
|
+
db,
|
|
135
|
+
settings,
|
|
136
|
+
scope,
|
|
137
|
+
{
|
|
138
|
+
candidates: [connectionId],
|
|
139
|
+
operationKind: "video",
|
|
140
|
+
holderId: `video:${operation.id}`,
|
|
141
|
+
fetchImpl: countedTransport,
|
|
142
|
+
},
|
|
143
|
+
async ({ resolver, fetch: custody, fence }) => {
|
|
144
|
+
try {
|
|
145
|
+
bearer(await resolver.getToken());
|
|
146
|
+
} catch {
|
|
147
|
+
return unreadable;
|
|
148
|
+
}
|
|
149
|
+
const beforeDispatch = async <R>(step: () => Promise<R>): Promise<R> => {
|
|
150
|
+
try {
|
|
151
|
+
return await step();
|
|
152
|
+
} catch (error) {
|
|
153
|
+
if (dispatched === 0) throw new SubscriptionCoreVideoDispatchRejected();
|
|
154
|
+
throw error;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
const fenced: SubscriptionCoreFetch = async (input, init) => {
|
|
158
|
+
// Pre-dispatch fence on the exact operation lease.
|
|
159
|
+
const held = await beforeDispatch(fence);
|
|
160
|
+
if (!held) {
|
|
161
|
+
if (dispatched === 0) throw new SubscriptionCoreVideoDispatchRejected();
|
|
162
|
+
throw new Error("The video operation lease was lost");
|
|
163
|
+
}
|
|
164
|
+
// A refused custody reservation never reached the transport.
|
|
165
|
+
return await beforeDispatch(() => custody(input, init));
|
|
166
|
+
};
|
|
167
|
+
return {
|
|
168
|
+
value: await run({
|
|
169
|
+
auth: {
|
|
170
|
+
getToken: () => beforeDispatch(async () => bearer(await resolver.getToken())),
|
|
171
|
+
refresh: () => beforeDispatch(async () => bearer(await resolver.refresh())),
|
|
172
|
+
},
|
|
173
|
+
fetch: fenced,
|
|
174
|
+
}),
|
|
175
|
+
};
|
|
176
|
+
},
|
|
177
|
+
);
|
|
178
|
+
if (ran.kind === "unavailable" || ran.value === unreadable) return { kind: "unavailable" };
|
|
179
|
+
return { kind: "ran", value: ran.value.value };
|
|
180
|
+
}
|
|
@@ -947,13 +947,24 @@ async function runCapture(
|
|
|
947
947
|
}
|
|
948
948
|
|
|
949
949
|
// ── 10. observe completion ────────────────────────────────────────────────
|
|
950
|
-
|
|
950
|
+
recordWorkspaceCaptureCompleted(observability, Date.now() - startedAt);
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
/** Count one committed logical capture and observe its end-to-end duration. */
|
|
954
|
+
export function recordWorkspaceCaptureCompleted(
|
|
955
|
+
observability: Pick<Observability, "incrementCounter" | "observeHistogram">,
|
|
956
|
+
durationMs: number,
|
|
957
|
+
): void {
|
|
951
958
|
observability.incrementCounter({
|
|
952
959
|
name: "opengeni_workspace_capture_total",
|
|
953
960
|
labels: { result: "ok" },
|
|
954
961
|
});
|
|
962
|
+
// Distinct from the physical `opengeni_workspace_capture_duration_seconds`
|
|
963
|
+
// {backend,outcome} histogram the runtime hook records in this same
|
|
964
|
+
// registry: one name cannot carry two label sets.
|
|
955
965
|
observability.observeHistogram({
|
|
956
|
-
name: "
|
|
966
|
+
name: "opengeni_workspace_capture_revision_duration_seconds",
|
|
967
|
+
help: "Turn-end logical workspace revision capture duration for committed revisions.",
|
|
957
968
|
value: durationMs / 1000,
|
|
958
969
|
});
|
|
959
970
|
}
|