@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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as activities from "../activities.js";
|
|
2
|
-
type WorkflowControlActivities = Pick<typeof activities, "enqueueGoalRetryWake" | "expireSessionHumanInput" | "expireSessionInteractionIntervention" | "failSessionAttempt" | "getCodexCapacityWait" | "markSessionIdle" | "peekSessionWork" | "persistSessionAttemptQuiescence" | "reconcileSessionAttemptQuiescence" | "reconcileCodexCapacityWait" | "recoverDispatch" | "recoverEscapedMcpTimeout" | "settleSessionInterruptions" | "settleSessionInputWait">;
|
|
2
|
+
type WorkflowControlActivities = Pick<typeof activities, "enqueueGoalRetryWake" | "expireSessionHumanInput" | "expireSessionInteractionIntervention" | "expireScheduledRunHumanWait" | "failSessionAttempt" | "getCodexCapacityWait" | "markSessionIdle" | "peekSessionWork" | "persistSessionAttemptQuiescence" | "reconcileSessionAttemptQuiescence" | "reconcileSettledSessionAttempt" | "reconcileCodexCapacityWait" | "recoverDispatch" | "recoverEscapedMcpTimeout" | "settleSessionInterruptions" | "settleSessionInputWait">;
|
|
3
3
|
/**
|
|
4
4
|
* Session/schedule workflow control activities are bounded, idempotent database
|
|
5
5
|
* and provider-metadata operations. They must not inherit the agent turn's
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { BrowserDeadlineCheckpointTarget } from "@opengeni/db";
|
|
2
|
+
export declare function browserDeadlineCheckpointWorkflow(target: BrowserDeadlineCheckpointTarget): Promise<{
|
|
3
|
+
status: "skipped";
|
|
4
|
+
} | {
|
|
5
|
+
status: "suspended";
|
|
6
|
+
}>;
|
|
7
|
+
/** Runs from the existing lease-sweep dispatch. Inventory never performs provider
|
|
8
|
+
* I/O; each exact browser has an independent durable capture/cleanup child.
|
|
9
|
+
* Provider-deadline saves and idle saves (prepared by the lease reaper) share it. */
|
|
10
|
+
export declare function browserDeadlineCheckpointSweepWorkflow(): Promise<void>;
|
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
import { type SandboxDrainWorkflowInput, type SandboxLeaseSweepMaintenanceInput } from "../sandbox-reaper-contract.js";
|
|
1
|
+
import { type SandboxDrainWorkflowInput, type SandboxIdleCheckpointWorkflowInput, type SandboxLeaseSweepMaintenanceInput } from "../sandbox-reaper-contract.js";
|
|
2
2
|
export declare function sandboxDrainWorkflow(input: SandboxDrainWorkflowInput): Promise<void>;
|
|
3
|
+
/** Checkpoint one warm box between turns (see checkpointIdleSandboxLease).
|
|
4
|
+
* Failure is not fatal: the next sweep lists the box again when it is due. */
|
|
5
|
+
export declare function sandboxIdleCheckpointWorkflow(input: SandboxIdleCheckpointWorkflowInput): Promise<void>;
|
|
6
|
+
/** Idle checkpoint sweep, started from the same tick as the drain inventory
|
|
7
|
+
* but as its own workflow type, so the V2 drain workflow's command history is
|
|
8
|
+
* unchanged across a rolling deploy. Inventory is DB only; each exact box gets
|
|
9
|
+
* one durable child per lease epoch, and a still-running child for that epoch
|
|
10
|
+
* is the coalesced capture. */
|
|
11
|
+
export declare function sandboxIdleCheckpointSweepWorkflow(): Promise<void>;
|
|
3
12
|
/** Ancillary billing/reconciliation/GC is durable but never allowed to hold the
|
|
4
13
|
* fixed-ID inventory workflow open behind a provider backlog. One singleton
|
|
5
14
|
* maintenance child may queue on the lifecycle workers while every schedule
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { TurnInitiator } from "@opengeni/contracts";
|
|
2
|
+
import type { DispatchScheduledTaskRunInput } from "../activities/types.js";
|
|
2
3
|
type ScheduledTaskFireWorkflowBase = {
|
|
3
4
|
accountId: string;
|
|
4
5
|
workspaceId: string;
|
|
@@ -8,10 +9,13 @@ export type ScheduledTaskFireWorkflowInput = ScheduledTaskFireWorkflowBase & ({
|
|
|
8
9
|
triggerType: "scheduled";
|
|
9
10
|
agentRunUsageIdempotencyKey?: never;
|
|
10
11
|
initiator?: never;
|
|
12
|
+
credentialRestriction?: never;
|
|
11
13
|
} | {
|
|
12
14
|
triggerType: "manual" | "initial" | "provider_event" | "retry" | "repair";
|
|
13
15
|
agentRunUsageIdempotencyKey: string;
|
|
14
16
|
initiator: TurnInitiator;
|
|
17
|
+
credentialRestriction?: "developer_setup";
|
|
15
18
|
});
|
|
19
|
+
export declare function scheduledTaskDispatchInput(input: ScheduledTaskFireWorkflowInput, producerKey: string): DispatchScheduledTaskRunInput;
|
|
16
20
|
export declare function scheduledTaskFireWorkflow(input: ScheduledTaskFireWorkflowInput): Promise<void>;
|
|
17
21
|
export {};
|
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
import type * as activities from "../activities.js";
|
|
2
2
|
import { type EscapedMcpTimeoutRecoveryDetail, type PostClaimDatabaseRecoveryDetail, type PreClaimFailureDetail, type PreClaimFailureDisposition } from "../activities/types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Provider capacity waits are shared: every waiter of one exhausted pool learns
|
|
5
|
+
* the same authoritative reset time, and one capacity mutation (for example the
|
|
6
|
+
* bounded refresh that verifies a quota reset) wakes every waiter at once, both
|
|
7
|
+
* as the typed capacity signal and as the generic durable workflow wake. Without
|
|
8
|
+
* spread, a reset resumes the whole backlog in the same few seconds and its
|
|
9
|
+
* turns stampede sandbox creation and the provider. Each workflow therefore
|
|
10
|
+
* delays its reconciliation by a bounded, replay-deterministic (Temporal-seeded
|
|
11
|
+
* `Math.random`) jitter: up to one minute past a scheduled reset timer and up to
|
|
12
|
+
* 30 seconds after a capacity or queue wake or an already-due waiter. A wake
|
|
13
|
+
* that lands inside a waiter's timer spread does not shorten it. The Postgres
|
|
14
|
+
* waiter stays authoritative; jitter only delays the same reconciliation
|
|
15
|
+
* activity and never creates queue rows, input, or inference. Interruptions are
|
|
16
|
+
* never delayed.
|
|
17
|
+
*
|
|
18
|
+
* The patch marker is not understood by workers built before it: rolling the
|
|
19
|
+
* worker image back past this change while a session has recorded the marker
|
|
20
|
+
* (it waited on capacity in its current run) fails that workflow's tasks as
|
|
21
|
+
* nondeterministic until a patched worker returns.
|
|
22
|
+
*/
|
|
23
|
+
export declare const CAPACITY_WAKE_JITTER_PATCH = "session-capacity-wake-jitter-v1";
|
|
24
|
+
/**
|
|
25
|
+
* A scheduled run's approval timeout sleeps on a durable Temporal timer. A
|
|
26
|
+
* history recorded by a worker that ignored the deadline has no timer command
|
|
27
|
+
* there, so replay only arms it behind this marker.
|
|
28
|
+
*/
|
|
29
|
+
export declare const SCHEDULED_HUMAN_WAIT_TIMEOUT_PATCH = "session-scheduled-human-wait-timeout-v1";
|
|
30
|
+
export declare const CAPACITY_TIMER_WAKE_JITTER_MAX_MS = 60000;
|
|
31
|
+
export declare const CAPACITY_WAKE_JITTER_MAX_MS = 30000;
|
|
32
|
+
/**
|
|
33
|
+
* Pure + exported so the bound is unit-testable without a workflow environment.
|
|
34
|
+
* `overrideMaxMs` is the test-only SessionWorkflowInput ceiling; it can only
|
|
35
|
+
* narrow the production bound.
|
|
36
|
+
*/
|
|
37
|
+
export declare function capacityWakeJitterMs(kind: "timer" | "wake", sample: number, overrideMaxMs?: number): number;
|
|
3
38
|
/**
|
|
4
39
|
* How long the continuation loop must hold before re-admitting the next turn. 0 ⇒ no
|
|
5
40
|
* hold (re-dispatch immediately — a rotation candidate is ready, or no idle delay was
|
|
@@ -76,5 +111,6 @@ export type SessionWorkflowInput = {
|
|
|
76
111
|
initialEventId?: string;
|
|
77
112
|
maxTurnsPerRun?: number;
|
|
78
113
|
maxCapacityChecksPerRun?: number;
|
|
114
|
+
capacityWakeJitterMaxMs?: number;
|
|
79
115
|
};
|
|
80
116
|
export declare function sessionWorkflow(input: SessionWorkflowInput): Promise<void>;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
/** One bounded durable claim/dispatch sweep
|
|
1
|
+
/** One bounded durable claim/dispatch sweep over provider-managed (external_provider)
|
|
2
|
+
* site-auth connections; the Temporal Schedule owns cadence. */
|
|
2
3
|
export declare function siteAuthMaintenanceWorkflow(): Promise<void>;
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
export declare
|
|
1
|
+
/** Must equal SESSION_WORKFLOW_WAKE_DISPATCH_REQUESTED_SIGNAL in @opengeni/core;
|
|
2
|
+
* workflow code cannot import that package. */
|
|
3
|
+
export declare const sessionWorkflowWakeDispatchRequestedSignal: import("@temporalio/client").SignalDefinition<[], "dispatchRequested">;
|
|
4
|
+
/** Bounds one execution's history. A request still pending at the cap is
|
|
5
|
+
* picked up by the control worker's next repair tick. */
|
|
6
|
+
export declare const SESSION_WORKFLOW_WAKE_DISPATCHER_MAX_SWEEPS = 50;
|
|
7
|
+
/**
|
|
8
|
+
* Bounded delivery sweeps. Producers and the control worker's repair cadence
|
|
9
|
+
* signal-with-start one fixed execution; a request that arrives during a sweep
|
|
10
|
+
* runs one more sweep afterwards, so no committed wake waits for a later tick.
|
|
11
|
+
*/
|
|
12
|
+
export declare function sessionWorkflowWakeDispatcherWorkflow(): Promise<import("../activities/parent-wake.js").WorkflowWakeReconciliationResult & {
|
|
13
|
+
exhaustedBatchLimit: boolean;
|
|
14
|
+
}>;
|
package/dist/workflows.d.ts
CHANGED
|
@@ -4,8 +4,10 @@ export { approvalDecision, codexCapacityChanged, sessionControl, sessionAttemptQ
|
|
|
4
4
|
export { scheduledTaskFireWorkflow, type ScheduledTaskFireWorkflowInput, } from "./workflows/scheduled-tasks.js";
|
|
5
5
|
export { automationRunWorkflow, type AutomationRunWorkflowInput } from "./workflows/automations.js";
|
|
6
6
|
export { knowledgeSourceSyncWake, knowledgeSourceSyncWorkflow, knowledgeSourceSyncWorkflowId, type KnowledgeSourceSyncWorkflowInput, } from "./workflows/knowledge-source-sync.js";
|
|
7
|
-
export { sandboxDrainWorkflow, sandboxReaperMaintenanceWorkflow, sandboxReaperWorkflow, sandboxReaperWorkflowV2, } from "./workflows/sandbox-reaper.js";
|
|
7
|
+
export { sandboxDrainWorkflow, sandboxIdleCheckpointSweepWorkflow, sandboxIdleCheckpointWorkflow, sandboxReaperMaintenanceWorkflow, sandboxReaperWorkflow, sandboxReaperWorkflowV2, } from "./workflows/sandbox-reaper.js";
|
|
8
8
|
export { fileUploadReaperWorkflow } from "./workflows/file-upload-reaper.js";
|
|
9
|
+
export { sessionStorageMaintenanceWorkflow } from "./workflows/session-storage.js";
|
|
10
|
+
export { browserDeadlineCheckpointWorkflow, browserDeadlineCheckpointSweepWorkflow, } from "./workflows/browser-deadline-checkpoint.js";
|
|
9
11
|
export { siteAuthMaintenanceWorkflow } from "./workflows/site-auth-maintenance.js";
|
|
10
12
|
export { videoGenerationWorkflow, videoGenerationWorkflowId, type VideoGenerationWorkflowInput, } from "./workflows/video-generation.js";
|
|
11
13
|
export { sessionWorkflowWakeDispatcherWorkflow } from "./workflows/workflow-wake.js";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengeni/worker-bundle",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.0.2-canary.38789554071001",
|
|
4
|
+
"description": "Opengeni worker entry and reusable embedded lifecycle, shipped with a release-coherent pre-bundled Temporal workflow artifact.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -53,25 +53,31 @@
|
|
|
53
53
|
"prepublishOnly": "bash ../../scripts/prepublish-guard"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
+
"@1password/sdk": "0.5.0",
|
|
56
57
|
"@llamaindex/liteparse": "2.14.2",
|
|
57
|
-
"@opengeni/agent-proto": "
|
|
58
|
-
"@opengeni/capabilities": "
|
|
59
|
-
"@opengeni/codemode": "
|
|
60
|
-
"@opengeni/codex": "
|
|
61
|
-
"@opengeni/config": "
|
|
62
|
-
"@opengeni/contracts": "
|
|
63
|
-
"@opengeni/core": "
|
|
64
|
-
"@opengeni/db": "
|
|
65
|
-
"@opengeni/documents": "
|
|
66
|
-
"@opengeni/events": "
|
|
67
|
-
"@opengeni/github": "
|
|
68
|
-
"@opengeni/
|
|
69
|
-
"@opengeni/
|
|
70
|
-
"@opengeni/
|
|
71
|
-
"@opengeni/
|
|
72
|
-
"@opengeni/
|
|
73
|
-
"@opengeni/
|
|
74
|
-
"@opengeni/
|
|
58
|
+
"@opengeni/agent-proto": "2.0.2-canary.38789554071001",
|
|
59
|
+
"@opengeni/capabilities": "2.0.2-canary.38789554071001",
|
|
60
|
+
"@opengeni/codemode": "2.0.2-canary.38789554071001",
|
|
61
|
+
"@opengeni/codex": "2.0.2-canary.38789554071001",
|
|
62
|
+
"@opengeni/config": "2.0.2-canary.38789554071001",
|
|
63
|
+
"@opengeni/contracts": "2.0.2-canary.38789554071001",
|
|
64
|
+
"@opengeni/core": "2.0.2-canary.38789554071001",
|
|
65
|
+
"@opengeni/db": "2.0.2-canary.38789554071001",
|
|
66
|
+
"@opengeni/documents": "2.0.2-canary.38789554071001",
|
|
67
|
+
"@opengeni/events": "2.0.2-canary.38789554071001",
|
|
68
|
+
"@opengeni/github": "2.0.2-canary.38789554071001",
|
|
69
|
+
"@opengeni/interaction": "2.0.2-canary.38789554071001",
|
|
70
|
+
"@opengeni/jev": "2.0.2-canary.38789554071001",
|
|
71
|
+
"@opengeni/network": "2.0.2-canary.38789554071001",
|
|
72
|
+
"@opengeni/observability": "2.0.2-canary.38789554071001",
|
|
73
|
+
"@opengeni/runtime": "2.0.2-canary.38789554071001",
|
|
74
|
+
"@opengeni/sdk": "2.0.2-canary.38789554071001",
|
|
75
|
+
"@opengeni/storage": "2.0.2-canary.38789554071001",
|
|
76
|
+
"@opengeni/subscriptions": "2.0.2-canary.38789554071001",
|
|
77
|
+
"@opengeni/tool-gateway": "2.0.2-canary.38789554071001",
|
|
78
|
+
"@opengeni/vaults": "2.0.2-canary.38789554071001",
|
|
79
|
+
"@opengeni/vaults-onepassword": "2.0.2-canary.38789554071001",
|
|
80
|
+
"@opengeni/xai-subscription": "2.0.2-canary.38789554071001",
|
|
75
81
|
"@temporalio/activity": "^1.17.0",
|
|
76
82
|
"@temporalio/client": "^1.17.0",
|
|
77
83
|
"@temporalio/worker": "^1.17.0",
|
|
@@ -1,82 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { modelFundingForAdmission } from "@opengeni/core";
|
|
3
|
-
import { getBillingBalance, isCodexBilledTurn, sumUsageQuantity } from "@opengeni/db";
|
|
4
|
-
import type { ControlActivityServices } from "./types";
|
|
5
|
-
|
|
6
|
-
export type AgentRunAdmissionDenial =
|
|
7
|
-
| "insufficient_credits"
|
|
8
|
-
| "monthly_model_cost_limit"
|
|
9
|
-
| "monthly_agent_run_limit";
|
|
10
|
-
|
|
11
|
-
/** One worker-side admission boundary for service-authored agent runs. */
|
|
12
|
-
export async function agentRunAdmissionDenial(
|
|
13
|
-
services: Pick<ControlActivityServices, "db" | "entitlements"> & { settings: Settings },
|
|
14
|
-
input: {
|
|
15
|
-
accountId: string;
|
|
16
|
-
workspaceId: string;
|
|
17
|
-
model: string;
|
|
18
|
-
requestedAgentRuns: number;
|
|
19
|
-
},
|
|
20
|
-
): Promise<AgentRunAdmissionDenial | null> {
|
|
21
|
-
const codexBilled = await isCodexBilledTurn({
|
|
22
|
-
db: services.db,
|
|
23
|
-
settings: services.settings,
|
|
24
|
-
workspaceId: input.workspaceId,
|
|
25
|
-
model: input.model,
|
|
26
|
-
});
|
|
27
|
-
const externallyBilled = modelFundingForAdmission(
|
|
28
|
-
services.settings,
|
|
29
|
-
input.model,
|
|
30
|
-
codexBilled,
|
|
31
|
-
).fundedWithoutCredits;
|
|
32
|
-
if (
|
|
33
|
-
!externallyBilled &&
|
|
34
|
-
(services.settings.billingMode === "stripe" || services.settings.usageLimitsMode === "managed")
|
|
35
|
-
) {
|
|
36
|
-
if (services.entitlements) {
|
|
37
|
-
const decision = await services.entitlements.admitRun({
|
|
38
|
-
accountId: input.accountId,
|
|
39
|
-
workspaceId: input.workspaceId,
|
|
40
|
-
action: "agent_run:create",
|
|
41
|
-
quantity: input.requestedAgentRuns,
|
|
42
|
-
});
|
|
43
|
-
if (!decision.allowed) return "insufficient_credits";
|
|
44
|
-
} else {
|
|
45
|
-
const balance = await getBillingBalance(services.db, input.accountId);
|
|
46
|
-
if (balance.balanceMicros <= 0) return "insufficient_credits";
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
if (
|
|
50
|
-
services.settings.usageLimitsMode !== "static" &&
|
|
51
|
-
services.settings.usageLimitsMode !== "managed"
|
|
52
|
-
) {
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
const limits = configuredStaticUsageLimits(services.settings);
|
|
56
|
-
if (!externallyBilled && limits.maxMonthlyCostMicrosPerAccount) {
|
|
57
|
-
const used = await sumUsageQuantity(services.db, {
|
|
58
|
-
accountId: input.accountId,
|
|
59
|
-
eventType: "model.cost",
|
|
60
|
-
since: startOfUtcMonth(),
|
|
61
|
-
});
|
|
62
|
-
if (used >= limits.maxMonthlyCostMicrosPerAccount) {
|
|
63
|
-
return "monthly_model_cost_limit";
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if (limits.maxMonthlyAgentRunsPerWorkspace) {
|
|
67
|
-
const used = await sumUsageQuantity(services.db, {
|
|
68
|
-
workspaceId: input.workspaceId,
|
|
69
|
-
eventType: "agent_run.created",
|
|
70
|
-
since: startOfUtcMonth(),
|
|
71
|
-
});
|
|
72
|
-
if (used + input.requestedAgentRuns > limits.maxMonthlyAgentRunsPerWorkspace) {
|
|
73
|
-
return "monthly_agent_run_limit";
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function startOfUtcMonth(): Date {
|
|
80
|
-
const now = new Date();
|
|
81
|
-
return new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), 1));
|
|
82
|
-
}
|
|
1
|
+
export { agentRunAdmissionDenial, type AgentRunAdmissionDenial } from "@opengeni/core";
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
checkSessionUsageLimitAdmission,
|
|
3
|
+
checkWorkspaceAllowance,
|
|
4
|
+
getSpendableCreditBalance,
|
|
5
|
+
SessionUsageLimitUnavailableError,
|
|
6
|
+
sumUsageQuantity,
|
|
7
|
+
} from "@opengeni/db";
|
|
2
8
|
import {
|
|
3
9
|
configuredStaticUsageLimits,
|
|
4
10
|
resolveTurnExecutionPolicyV1,
|
|
@@ -8,14 +14,17 @@ import { selectCodexCredentialId } from "@opengeni/codex";
|
|
|
8
14
|
import { directPersonalConnectionSubjectId } from "@opengeni/core";
|
|
9
15
|
import type { TurnActivityServices as ActivityServices } from "../types";
|
|
10
16
|
import {
|
|
17
|
+
type AllowanceExhaustedRefusal,
|
|
11
18
|
type SessionEvent,
|
|
19
|
+
type SessionUsageLimitReachedRefusal,
|
|
12
20
|
type SessionTurn,
|
|
13
21
|
type ToolAuthNeededPayload,
|
|
14
22
|
type TurnExecutionPolicyV1,
|
|
15
|
-
type XaiProviderAccountAuthoritySnapshotV1,
|
|
16
23
|
} from "@opengeni/contracts";
|
|
24
|
+
import { SESSION_USAGE_LIMIT_SEGMENT } from "@opengeni/contracts/session-usage-limit-refusal";
|
|
17
25
|
import { createHash } from "node:crypto";
|
|
18
26
|
import { startOfUtcMonth } from "./model-usage";
|
|
27
|
+
import { flushHeldSessionUsageReceipts } from "./session-usage-custody";
|
|
19
28
|
|
|
20
29
|
export class WorkspaceHumanInputDisabledError extends Error {
|
|
21
30
|
constructor(kind: "resume" | "interruption") {
|
|
@@ -39,22 +48,6 @@ export function credentialSubjectIdForTurnInitiator(
|
|
|
39
48
|
return directPersonalConnectionSubjectId(turn);
|
|
40
49
|
}
|
|
41
50
|
|
|
42
|
-
export function xaiCatalogReadinessAuthority(
|
|
43
|
-
turn: {
|
|
44
|
-
initiatingHumanSubjectId: string | null;
|
|
45
|
-
xaiProviderAccountAuthoritySnapshot: XaiProviderAccountAuthoritySnapshotV1;
|
|
46
|
-
},
|
|
47
|
-
directCredentialSubjectId: string | undefined,
|
|
48
|
-
): {
|
|
49
|
-
subjectId: string;
|
|
50
|
-
authoritySnapshot: XaiProviderAccountAuthoritySnapshotV1;
|
|
51
|
-
} | null {
|
|
52
|
-
const subjectId = turn.initiatingHumanSubjectId ?? directCredentialSubjectId;
|
|
53
|
-
return subjectId
|
|
54
|
-
? { subjectId, authoritySnapshot: turn.xaiProviderAccountAuthoritySnapshot }
|
|
55
|
-
: null;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
51
|
/**
|
|
59
52
|
* Direct authenticated-human work is the persisted human source with subject
|
|
60
53
|
* authority and no inherited agent or legacy provenance. Use this complete
|
|
@@ -243,16 +236,158 @@ export class BudgetExhaustedError extends Error {
|
|
|
243
236
|
constructor(
|
|
244
237
|
message: string,
|
|
245
238
|
readonly serializedRunState: string | null,
|
|
239
|
+
readonly allowance: AllowanceRefusal | null = null,
|
|
240
|
+
/** A reached per-task usage limit: its own stop marker, never credits. */
|
|
241
|
+
readonly sessionUsageLimit: SessionUsageLimitReachedRefusal | null = null,
|
|
246
242
|
) {
|
|
247
243
|
super(message);
|
|
248
244
|
this.name = "BudgetExhaustedError";
|
|
249
245
|
}
|
|
250
246
|
}
|
|
251
247
|
|
|
248
|
+
/** The task's root usage limit is reached: a recoverable non-failure stop. */
|
|
249
|
+
export class SessionUsageLimitReachedError extends Error {
|
|
250
|
+
readonly code = "session_usage_limit_reached";
|
|
251
|
+
|
|
252
|
+
constructor(readonly refusal: SessionUsageLimitReachedRefusal) {
|
|
253
|
+
super(refusal.message);
|
|
254
|
+
this.name = "SessionUsageLimitReachedError";
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* The terminal events of a usage-limit stop: a completed (non-failed) turn
|
|
260
|
+
* with its own `segmentLimit` and the typed refusal, then an idle session.
|
|
261
|
+
* Deliberately no `usage.exhausted` (an allowance/webhook contract) and no
|
|
262
|
+
* `budget_exhausted` marker, so no client offers "Add credits".
|
|
263
|
+
*/
|
|
264
|
+
export function sessionUsageLimitStopEvents(
|
|
265
|
+
refusal: SessionUsageLimitReachedRefusal,
|
|
266
|
+
extra: { detail?: string } = {},
|
|
267
|
+
) {
|
|
268
|
+
return [
|
|
269
|
+
{
|
|
270
|
+
type: "turn.completed" as const,
|
|
271
|
+
payload: {
|
|
272
|
+
output: "",
|
|
273
|
+
segmentLimit: SESSION_USAGE_LIMIT_SEGMENT,
|
|
274
|
+
...(extra.detail ? { detail: extra.detail } : {}),
|
|
275
|
+
sessionUsageLimit: refusal,
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
{ type: "session.status.changed" as const, payload: { status: "idle" } },
|
|
279
|
+
];
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Refuse a new model request once the task's root usage limit is reached.
|
|
284
|
+
* Reads the latest durable counter; a read failure throws
|
|
285
|
+
* `SessionUsageLimitUnavailableError` (never treated as unlimited).
|
|
286
|
+
*/
|
|
287
|
+
export async function ensureSessionUsageLimitAllows(
|
|
288
|
+
db: ActivityServices["db"],
|
|
289
|
+
input: { accountId: string; workspaceId: string; sessionId: string },
|
|
290
|
+
): Promise<void> {
|
|
291
|
+
// Receipts this process holds (a settlement write failed) are made durable
|
|
292
|
+
// before the next request is admitted; a still-failing write throws a
|
|
293
|
+
// database error and blocks the request without replaying provider work.
|
|
294
|
+
// It is an unreadable usage state (never a credit or limit stop); the
|
|
295
|
+
// database cause keeps it in the attempt's DB-only recovery lane.
|
|
296
|
+
try {
|
|
297
|
+
await flushHeldSessionUsageReceipts(db, input.sessionId);
|
|
298
|
+
} catch (error) {
|
|
299
|
+
throw new SessionUsageLimitUnavailableError(
|
|
300
|
+
"Recorded task usage could not be saved before the next model request",
|
|
301
|
+
{ cause: error },
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
const admission = await checkSessionUsageLimitAdmission(db, { ...input, runtime: true });
|
|
305
|
+
if (!admission.allowed) throw new SessionUsageLimitReachedError(admission.refusal);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* The task usage limit alone, for a paid request that has no allowance
|
|
310
|
+
* boundary of its own (the Codex remote compaction request). A reached limit
|
|
311
|
+
* becomes the same typed between-request stop as any other call; an
|
|
312
|
+
* unreadable state still throws `SessionUsageLimitUnavailableError`.
|
|
313
|
+
*/
|
|
314
|
+
export async function ensureSessionUsageLimitAllowsBetweenModelCalls(
|
|
315
|
+
db: ActivityServices["db"],
|
|
316
|
+
input: { accountId: string; workspaceId: string; sessionId: string },
|
|
317
|
+
): Promise<void> {
|
|
318
|
+
try {
|
|
319
|
+
await ensureSessionUsageLimitAllows(db, input);
|
|
320
|
+
} catch (error) {
|
|
321
|
+
if (!(error instanceof SessionUsageLimitReachedError)) throw error;
|
|
322
|
+
throw new BudgetExhaustedError(error.message, null, null, error.refusal);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export type AllowanceRefusal = AllowanceExhaustedRefusal;
|
|
327
|
+
|
|
328
|
+
/** Account allowance exhaustion is recoverable state, never a provider failure. */
|
|
329
|
+
export class AllowanceExhaustedError extends Error {
|
|
330
|
+
readonly code = "allowance_exhausted";
|
|
331
|
+
|
|
332
|
+
constructor(readonly refusal: AllowanceRefusal) {
|
|
333
|
+
super(refusal.message);
|
|
334
|
+
this.name = "AllowanceExhaustedError";
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/** Revalidate between paid calls without replaying provider work or reserving credits. */
|
|
339
|
+
export async function ensureRunAllowedBetweenModelCalls(input: {
|
|
340
|
+
settings: Settings;
|
|
341
|
+
db: ActivityServices["db"];
|
|
342
|
+
accountId: string;
|
|
343
|
+
workspaceId: string;
|
|
344
|
+
isExternallyBilledTurn: boolean;
|
|
345
|
+
entitlements?: ActivityServices["entitlements"];
|
|
346
|
+
chargesOpenGeniCredits: boolean;
|
|
347
|
+
countsTowardTokenCap: boolean;
|
|
348
|
+
initiatingHumanSubjectId: string | null;
|
|
349
|
+
modelId?: string;
|
|
350
|
+
/** The session whose task root usage limit gates this request. */
|
|
351
|
+
sessionId?: string;
|
|
352
|
+
serializedRunState?: () => string | null;
|
|
353
|
+
}): Promise<number | undefined> {
|
|
354
|
+
try {
|
|
355
|
+
return await ensureRunAllowed(
|
|
356
|
+
input.settings,
|
|
357
|
+
input.db,
|
|
358
|
+
input.accountId,
|
|
359
|
+
input.workspaceId,
|
|
360
|
+
input.isExternallyBilledTurn,
|
|
361
|
+
input.entitlements,
|
|
362
|
+
input.chargesOpenGeniCredits,
|
|
363
|
+
input.countsTowardTokenCap,
|
|
364
|
+
input.initiatingHumanSubjectId,
|
|
365
|
+
input.modelId,
|
|
366
|
+
input.sessionId,
|
|
367
|
+
);
|
|
368
|
+
} catch (limitError) {
|
|
369
|
+
// An unreadable usage state blocks the request as an infrastructure
|
|
370
|
+
// failure; it is never presented as a credit or usage-limit stop.
|
|
371
|
+
if (limitError instanceof SessionUsageLimitUnavailableError) throw limitError;
|
|
372
|
+
let serializedRunState: string | null = null;
|
|
373
|
+
try {
|
|
374
|
+
serializedRunState = input.serializedRunState?.() ?? null;
|
|
375
|
+
} catch {
|
|
376
|
+
// Durable history remains authoritative when the SDK state cannot serialize.
|
|
377
|
+
}
|
|
378
|
+
throw new BudgetExhaustedError(
|
|
379
|
+
limitError instanceof Error ? limitError.message : String(limitError),
|
|
380
|
+
serializedRunState,
|
|
381
|
+
limitError instanceof AllowanceExhaustedError ? limitError.refusal : null,
|
|
382
|
+
limitError instanceof SessionUsageLimitReachedError ? limitError.refusal : null,
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
252
387
|
// Exported for unit testing the external-billing bypass (codex-billing.test.ts); not
|
|
253
388
|
// part of the activity surface. Takes the accepted policy's billing attribution and
|
|
254
389
|
// the optional §7.5 P3 host `entitlements` port (when bound, its `admitRun` REPLACES
|
|
255
|
-
// the local credit read for an
|
|
390
|
+
// the local credit read for an Opengeni-metered turn; unset → local ledger).
|
|
256
391
|
export async function ensureRunAllowed(
|
|
257
392
|
settings: Settings,
|
|
258
393
|
db: ActivityServices["db"],
|
|
@@ -262,10 +397,17 @@ export async function ensureRunAllowed(
|
|
|
262
397
|
entitlements?: ActivityServices["entitlements"],
|
|
263
398
|
chargesOpenGeniCredits = !isExternallyBilledTurn,
|
|
264
399
|
countsTowardTokenCap = !isExternallyBilledTurn,
|
|
265
|
-
|
|
400
|
+
initiatingHumanSubjectId: string | null = null,
|
|
401
|
+
modelId?: string,
|
|
402
|
+
sessionId?: string,
|
|
403
|
+
): Promise<number | undefined> {
|
|
404
|
+
let creditPolicyRevision: number | undefined;
|
|
405
|
+
// Per-task usage limit: independent of funding, so it applies to
|
|
406
|
+
// credit, subscription, workspace-key and free paths alike.
|
|
407
|
+
if (sessionId) await ensureSessionUsageLimitAllows(db, { accountId, workspaceId, sessionId });
|
|
266
408
|
// Upstream settlement and workspace-facing cost are independent. External
|
|
267
409
|
// metering skips the token cap; free/subscription/workspace cost skips the
|
|
268
|
-
//
|
|
410
|
+
// Opengeni credit gate. The agent-run COUNT cap below is a volume/fairness
|
|
269
411
|
// quota and is intentionally kept for every funding path.
|
|
270
412
|
//
|
|
271
413
|
// §7.5 P3 — host-entitlements DELEGATION (the worker half of the same seam the
|
|
@@ -291,17 +433,25 @@ export async function ensureRunAllowed(
|
|
|
291
433
|
quantity: 1,
|
|
292
434
|
});
|
|
293
435
|
if (!decision.allowed) {
|
|
294
|
-
throw new Error(decision.reason || "insufficient
|
|
436
|
+
throw new Error(decision.reason || "insufficient Opengeni credits");
|
|
295
437
|
}
|
|
296
438
|
} else if (
|
|
297
439
|
chargesOpenGeniCredits &&
|
|
298
440
|
(settings.billingMode === "stripe" || settings.usageLimitsMode === "managed")
|
|
299
441
|
) {
|
|
300
|
-
const balance = await
|
|
442
|
+
const balance = await getSpendableCreditBalance(db, accountId, modelId);
|
|
443
|
+
creditPolicyRevision = balance.creditPolicyRevision;
|
|
301
444
|
if (balance.balanceMicros <= 0) {
|
|
302
|
-
throw new Error("insufficient
|
|
445
|
+
throw new Error("insufficient Opengeni credits");
|
|
303
446
|
}
|
|
304
447
|
}
|
|
448
|
+
const refusal = await checkWorkspaceAllowance(db, {
|
|
449
|
+
accountId,
|
|
450
|
+
workspaceId,
|
|
451
|
+
subjectId: initiatingHumanSubjectId,
|
|
452
|
+
...(chargesOpenGeniCredits ? {} : { fundedWithoutCredits: true }),
|
|
453
|
+
});
|
|
454
|
+
if (refusal) throw new AllowanceExhaustedError(refusal);
|
|
305
455
|
if (settings.usageLimitsMode === "static" || settings.usageLimitsMode === "managed") {
|
|
306
456
|
const limits = configuredStaticUsageLimits(settings);
|
|
307
457
|
if (limits.maxMonthlyAgentRunsPerWorkspace) {
|
|
@@ -330,4 +480,5 @@ export async function ensureRunAllowed(
|
|
|
330
480
|
}
|
|
331
481
|
}
|
|
332
482
|
}
|
|
483
|
+
return creditPolicyRevision;
|
|
333
484
|
}
|