@opengeni/worker-bundle 2.0.1 → 2.0.2-canary.38686408778001
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/activities/agent-run-admission.d.ts +1 -12
- package/dist/activities/agent-turn/admission.d.ts +88 -10
- package/dist/activities/agent-turn/agent-build.d.ts +14 -3
- package/dist/activities/agent-turn/claim.d.ts +4 -1
- package/dist/activities/agent-turn/claude-core.d.ts +195 -0
- package/dist/activities/agent-turn/code-search.d.ts +60 -0
- package/dist/activities/agent-turn/codex-capacity.d.ts +3 -0
- package/dist/activities/agent-turn/codex-core-capacity.d.ts +37 -0
- package/dist/activities/agent-turn/codex-core-claim.d.ts +40 -0
- package/dist/activities/agent-turn/codex-core-errors.d.ts +102 -0
- package/dist/activities/agent-turn/codex-core-failover.d.ts +15 -0
- package/dist/activities/agent-turn/codex-core-requests.d.ts +28 -0
- package/dist/activities/agent-turn/codex-core-settlement.d.ts +77 -0
- package/dist/activities/agent-turn/codex-credit-policy.d.ts +30 -0
- package/dist/activities/agent-turn/codex-plan-entitlement.d.ts +105 -0
- package/dist/activities/agent-turn/codex-usage-policy.d.ts +2 -0
- package/dist/activities/agent-turn/codex.d.ts +2 -19
- package/dist/activities/agent-turn/compaction-interruption.d.ts +32 -0
- package/dist/activities/agent-turn/compaction-prep.d.ts +30 -1
- package/dist/activities/agent-turn/credential-leases.d.ts +64 -37
- package/dist/activities/agent-turn/credential-restriction.d.ts +3 -0
- package/dist/activities/agent-turn/errors.d.ts +172 -28
- package/dist/activities/agent-turn/failure-settlement.d.ts +10 -43
- package/dist/activities/agent-turn/final-reply.d.ts +18 -0
- package/dist/activities/agent-turn/finalization-monitor.d.ts +7 -2
- package/dist/activities/agent-turn/finalization.d.ts +2 -0
- package/dist/activities/agent-turn/github-repository-bindings.d.ts +2 -0
- package/dist/activities/agent-turn/governance-model.d.ts +13 -1
- package/dist/activities/agent-turn/history-sink.d.ts +3 -1
- package/dist/activities/agent-turn/history.d.ts +2 -0
- package/dist/activities/agent-turn/input-wait-reply.d.ts +76 -0
- package/dist/activities/agent-turn/meaningful-output.d.ts +9 -0
- package/dist/activities/agent-turn/media-artifacts.d.ts +5 -3
- package/dist/activities/agent-turn/model-call-admission.d.ts +15 -0
- package/dist/activities/agent-turn/model-usage.d.ts +56 -14
- package/dist/activities/agent-turn/model-wire-dispatch.d.ts +15 -0
- package/dist/activities/agent-turn/optional-repositories.d.ts +59 -0
- package/dist/activities/agent-turn/prompt-tool-availability.d.ts +17 -0
- package/dist/activities/agent-turn/provider-dispatch-barrier.d.ts +12 -1
- package/dist/activities/agent-turn/provider-recovery-copy.d.ts +24 -0
- package/dist/activities/agent-turn/provider-recovery-metrics.d.ts +18 -0
- package/dist/activities/agent-turn/provider-recovery-policy.d.ts +6 -0
- package/dist/activities/agent-turn/quiescence.d.ts +6 -7
- package/dist/activities/agent-turn/recovery-warning.d.ts +6 -5
- package/dist/activities/agent-turn/refresh-credentials.d.ts +6 -0
- package/dist/activities/agent-turn/run-credentials.d.ts +9 -5
- package/dist/activities/agent-turn/run.d.ts +27 -2
- package/dist/activities/agent-turn/sandbox-establish.d.ts +1 -0
- package/dist/activities/agent-turn/sandbox-provision.d.ts +25 -1
- package/dist/activities/agent-turn/sandbox-route.d.ts +3 -0
- package/dist/activities/agent-turn/sandbox-runtime.d.ts +1 -1
- package/dist/activities/agent-turn/secret-resolver.d.ts +64 -0
- package/dist/activities/agent-turn/session-title.d.ts +60 -3
- package/dist/activities/agent-turn/session-usage-custody.d.ts +66 -0
- package/dist/activities/agent-turn/skill-checkout.d.ts +25 -6
- package/dist/activities/agent-turn/skill-read.d.ts +70 -2
- package/dist/activities/agent-turn/skill-search.d.ts +2 -0
- package/dist/activities/agent-turn/skill-tools.d.ts +41 -4
- package/dist/activities/agent-turn/skill-transfer.d.ts +18 -6
- package/dist/activities/agent-turn/stream-attempt.d.ts +6 -3
- package/dist/activities/agent-turn/subscription-capacity-arming.d.ts +41 -0
- package/dist/activities/agent-turn/subscription-core-capacity.d.ts +86 -0
- package/dist/activities/agent-turn/subscription-core-failover.d.ts +69 -0
- package/dist/activities/agent-turn/subscription-core-placed.d.ts +14 -0
- package/dist/activities/agent-turn/subscription-core-requests.d.ts +109 -0
- package/dist/activities/agent-turn/subscription-core-settlement.d.ts +112 -0
- package/dist/activities/agent-turn/subscription-lease.d.ts +44 -0
- package/dist/activities/agent-turn/subscription-serving-capacity.d.ts +6 -0
- package/dist/activities/agent-turn/subscription-serving-catalog.d.ts +13 -0
- package/dist/activities/agent-turn/subscription-serving-claim.d.ts +30 -0
- package/dist/activities/agent-turn/subscription-serving-providers.d.ts +2 -0
- package/dist/activities/agent-turn/tool-environment.d.ts +30 -6
- package/dist/activities/agent-turn/tool-policy.d.ts +55 -3
- package/dist/activities/agent-turn/turn-context.d.ts +104 -5
- package/dist/activities/agent-turn/web-search.d.ts +57 -0
- package/dist/activities/agent-turn/xai-core.d.ts +96 -0
- package/dist/activities/automations.d.ts +3 -1
- package/dist/activities/browser-deadline-checkpoint.d.ts +34 -0
- package/dist/activities/capabilities.d.ts +8 -20
- package/dist/activities/codemode-dispatcher.d.ts +20 -3
- package/dist/activities/codex-capacity.d.ts +1 -56
- package/dist/activities/codex-image-generation.d.ts +49 -3
- package/dist/activities/common.d.ts +3 -1
- package/dist/activities/context-compaction.d.ts +41 -2
- package/dist/activities/environment.d.ts +1 -19
- package/dist/activities/gmail-files.d.ts +50 -0
- package/dist/activities/goals.d.ts +1 -9
- package/dist/activities/incident-telemetry-authority.d.ts +5 -2
- package/dist/activities/incident-telemetry-preflight.d.ts +10 -3
- package/dist/activities/knowledge-indexing.d.ts +19 -0
- package/dist/activities/mcp-account-routes.d.ts +2 -21
- package/dist/activities/model-call-fact-reconciler.d.ts +34 -0
- package/dist/activities/open-suffix-resume.d.ts +15 -0
- package/dist/activities/parent-wake.d.ts +17 -12
- package/dist/activities/programmatic-approvals.d.ts +10 -0
- package/dist/activities/requester-unavailable-receipt.d.ts +8 -0
- package/dist/activities/retained-screenshots.d.ts +7 -2
- package/dist/activities/run-credential-renewal.d.ts +1 -0
- package/dist/activities/run-credentials.d.ts +16 -4
- package/dist/activities/run-input.d.ts +17 -0
- package/dist/activities/sandbox-lease.d.ts +132 -12
- package/dist/activities/scheduled-tasks.d.ts +4 -35
- package/dist/activities/session-archive.d.ts +58 -0
- package/dist/activities/session-state.d.ts +15 -3
- package/dist/activities/session-storage.d.ts +44 -0
- package/dist/activities/subscription-core-claude-waits.d.ts +2 -0
- package/dist/activities/subscription-core-codex-quota.d.ts +25 -0
- package/dist/activities/subscription-core-codex-waits.d.ts +153 -0
- package/dist/activities/subscription-core-image-operation.d.ts +29 -0
- package/dist/activities/subscription-core-usage-recheck.d.ts +49 -0
- package/dist/activities/subscription-core-wait-bindings.d.ts +3 -0
- package/dist/activities/subscription-core-xai-quota.d.ts +30 -0
- package/dist/activities/subscription-core-xai-waits.d.ts +2 -0
- package/dist/activities/types.d.ts +68 -5
- package/dist/activities/video-generation-admission.d.ts +2 -8
- package/dist/activities/video-generation-credential.d.ts +15 -12
- package/dist/activities/video-generation-subscription-core.d.ts +70 -0
- package/dist/activities/workspace-capture.d.ts +2 -0
- package/dist/activities/workspace-credential-provider.d.ts +47 -0
- package/dist/activities/xai-auth.d.ts +6 -18
- package/dist/activities/xai-image-generation.d.ts +22 -6
- package/dist/{activities-control-QA6OLRQY.js → activities-control-NTXZHYET.js} +1552 -2876
- package/dist/activities-control-NTXZHYET.js.map +1 -0
- package/dist/activities-control.d.ts +64 -4
- package/dist/{activities-turn-YVVKCGAK.js → activities-turn-RKRI5GY4.js} +9238 -4392
- package/dist/activities-turn-RKRI5GY4.js.map +1 -0
- package/dist/activities.d.ts +64 -4
- package/dist/artifact-materializer-entry.js +104 -35
- package/dist/artifact-materializer-entry.js.map +1 -1
- package/dist/artifact-outbox-entry.js +132 -61
- package/dist/artifact-outbox-entry.js.map +1 -1
- package/dist/browser-deadline-checkpoint-contract.d.ts +2 -0
- package/dist/{chunk-GDCLDKSH.js → chunk-24GP3BX5.js} +79 -72
- package/dist/chunk-24GP3BX5.js.map +1 -0
- package/dist/{chunk-RAMNYSAW.js → chunk-4ER3YXOT.js} +22 -4
- package/dist/chunk-4ER3YXOT.js.map +1 -0
- package/dist/{chunk-I7HKKMUJ.js → chunk-5NNS4327.js} +734 -58
- package/dist/chunk-5NNS4327.js.map +1 -0
- package/dist/{chunk-M3NVMF2V.js → chunk-7BIHFUGB.js} +2293 -3956
- package/dist/chunk-7BIHFUGB.js.map +1 -0
- package/dist/chunk-MVESOYFC.js +3746 -0
- package/dist/chunk-MVESOYFC.js.map +1 -0
- package/dist/chunk-NQDVJ6RI.js +2823 -0
- package/dist/chunk-NQDVJ6RI.js.map +1 -0
- package/dist/chunk-O7UPBWXK.js +79 -0
- package/dist/chunk-O7UPBWXK.js.map +1 -0
- package/dist/chunk-W2QSM5HR.js +414 -0
- package/dist/chunk-W2QSM5HR.js.map +1 -0
- package/dist/chunk-ZN3XJR33.js +227 -0
- package/dist/chunk-ZN3XJR33.js.map +1 -0
- package/dist/editable-artifact-outbox-dispatcher.d.ts +12 -1
- package/dist/editable-artifact-outbox-service.d.ts +3 -1
- package/dist/host-export-pump.d.ts +3 -1
- package/dist/host-export.d.ts +2 -2
- package/dist/host-export.js +1 -1
- package/dist/http.d.ts +1 -1
- package/dist/index.d.ts +49 -48
- package/dist/index.js +835 -256
- package/dist/index.js.map +1 -1
- package/dist/internal-maintenance.d.ts +63 -0
- package/dist/maintenance-cadence.d.ts +43 -0
- package/dist/observability-metrics.d.ts +293 -24
- package/dist/onepassword-vault-provider.d.ts +7 -0
- package/dist/parent-wake-PCLH7A3Y.js +24 -0
- package/dist/parent-wake-PCLH7A3Y.js.map +1 -0
- package/dist/personal-github-git-credentials.d.ts +1 -1
- package/dist/readiness-checks.d.ts +39 -0
- package/dist/retained-process-retry.d.ts +7 -0
- package/dist/sandbox-lease-BJYU72N3.js +84 -0
- package/dist/sandbox-lease-BJYU72N3.js.map +1 -0
- package/dist/sandbox-reaper-contract.d.ts +25 -0
- package/dist/sandbox-resume.d.ts +72 -4
- package/dist/sandbox-routing.d.ts +4 -2
- package/dist/session-event-fanout.d.ts +6 -0
- package/dist/site-auth-maintenance-WK3MR2PV.js +12 -0
- package/dist/site-auth-maintenance-WK3MR2PV.js.map +1 -0
- package/dist/telemetry-scheduler.d.ts +14 -0
- package/dist/temporal-runtime-logger.d.ts +22 -0
- package/dist/turn-task-queue-reader.d.ts +18 -0
- package/dist/turn-worker-activity-telemetry.d.ts +47 -0
- package/dist/worker-service-lifecycle.d.ts +12 -0
- package/dist/workflow-bundle.js +468 -71
- package/dist/workflows/activities.d.ts +1 -1
- package/dist/workflows/browser-deadline-checkpoint.d.ts +10 -0
- package/dist/workflows/sandbox-reaper.d.ts +10 -1
- package/dist/workflows/scheduled-tasks.d.ts +4 -0
- package/dist/workflows/session-storage.d.ts +2 -0
- package/dist/workflows/session.d.ts +36 -0
- package/dist/workflows/site-auth-maintenance.d.ts +2 -1
- package/dist/workflows/workflow-wake.d.ts +14 -3
- package/dist/workflows.d.ts +3 -1
- package/package.json +26 -20
- package/src/activities/agent-run-admission.ts +1 -82
- package/src/activities/agent-turn/admission.ts +175 -24
- package/src/activities/agent-turn/agent-build.ts +226 -145
- package/src/activities/agent-turn/claim.ts +363 -64
- package/src/activities/agent-turn/claude-core.ts +587 -0
- package/src/activities/agent-turn/code-search.ts +275 -0
- package/src/activities/agent-turn/codex-capacity.ts +30 -757
- package/src/activities/agent-turn/codex-core-capacity.ts +190 -0
- package/src/activities/agent-turn/codex-core-claim.ts +83 -0
- package/src/activities/agent-turn/codex-core-errors.ts +308 -0
- package/src/activities/agent-turn/codex-core-failover.ts +73 -0
- package/src/activities/agent-turn/codex-core-requests.ts +86 -0
- package/src/activities/agent-turn/codex-core-settlement.ts +263 -0
- package/src/activities/agent-turn/codex-credit-policy.ts +247 -0
- package/src/activities/agent-turn/codex-plan-entitlement.ts +254 -0
- package/src/activities/agent-turn/codex-usage-policy.ts +2 -0
- package/src/activities/agent-turn/codex.ts +8 -76
- package/src/activities/agent-turn/compaction-interruption.ts +56 -0
- package/src/activities/agent-turn/compaction-prep.ts +249 -36
- package/src/activities/agent-turn/credential-leases.ts +269 -214
- package/src/activities/agent-turn/credential-restriction.ts +14 -0
- package/src/activities/agent-turn/errors.ts +1134 -82
- package/src/activities/agent-turn/failure-settlement.ts +879 -886
- package/src/activities/agent-turn/final-reply.ts +46 -0
- package/src/activities/agent-turn/finalization-monitor.ts +17 -5
- package/src/activities/agent-turn/finalization.ts +107 -88
- package/src/activities/agent-turn/github-repository-bindings.ts +3 -1
- package/src/activities/agent-turn/governance-model.ts +90 -22
- package/src/activities/agent-turn/history-sink.ts +26 -4
- package/src/activities/agent-turn/history.ts +25 -5
- package/src/activities/agent-turn/input-wait-reply.ts +139 -0
- package/src/activities/agent-turn/knowledge-source-tools.ts +2 -0
- package/src/activities/agent-turn/meaningful-output.ts +44 -0
- package/src/activities/agent-turn/media-artifacts.ts +3 -1
- package/src/activities/agent-turn/model-call-admission.ts +94 -0
- package/src/activities/agent-turn/model-usage.ts +299 -233
- package/src/activities/agent-turn/model-wire-dispatch.ts +27 -0
- package/src/activities/agent-turn/optional-repositories.ts +224 -0
- package/src/activities/agent-turn/prompt-tool-availability.ts +27 -0
- package/src/activities/agent-turn/provider-dispatch-barrier.ts +22 -0
- package/src/activities/agent-turn/provider-recovery-copy.ts +76 -0
- package/src/activities/agent-turn/provider-recovery-metrics.ts +64 -0
- package/src/activities/agent-turn/provider-recovery-policy.ts +25 -0
- package/src/activities/agent-turn/quiescence.ts +7 -7
- package/src/activities/agent-turn/recovery-warning.ts +6 -8
- package/src/activities/agent-turn/refresh-credentials.ts +44 -0
- package/src/activities/agent-turn/run-credentials.ts +124 -76
- package/src/activities/agent-turn/run.ts +501 -112
- package/src/activities/agent-turn/sandbox-establish.ts +152 -75
- package/src/activities/agent-turn/sandbox-provision.ts +54 -1
- package/src/activities/agent-turn/sandbox-route.ts +4 -1
- package/src/activities/agent-turn/sandbox-runtime.ts +319 -11
- package/src/activities/agent-turn/secret-resolver.ts +155 -0
- package/src/activities/agent-turn/session-title.ts +177 -12
- package/src/activities/agent-turn/session-usage-custody.ts +170 -0
- package/src/activities/agent-turn/skill-checkout.ts +111 -24
- package/src/activities/agent-turn/skill-install.ts +1 -1
- package/src/activities/agent-turn/skill-read.ts +374 -28
- package/src/activities/agent-turn/skill-save.ts +35 -7
- package/src/activities/agent-turn/skill-search.ts +9 -0
- package/src/activities/agent-turn/skill-selection.ts +4 -0
- package/src/activities/agent-turn/skill-tools.ts +208 -21
- package/src/activities/agent-turn/skill-transfer.ts +68 -23
- package/src/activities/agent-turn/stream-attempt.ts +599 -110
- package/src/activities/agent-turn/subscription-capacity-arming.ts +81 -0
- package/src/activities/agent-turn/subscription-core-capacity.ts +439 -0
- package/src/activities/agent-turn/subscription-core-failover.ts +229 -0
- package/src/activities/agent-turn/subscription-core-placed.ts +37 -0
- package/src/activities/agent-turn/subscription-core-requests.ts +271 -0
- package/src/activities/agent-turn/subscription-core-settlement.ts +234 -0
- package/src/activities/agent-turn/subscription-lease.ts +140 -0
- package/src/activities/agent-turn/subscription-serving-capacity.ts +195 -0
- package/src/activities/agent-turn/subscription-serving-catalog.ts +71 -0
- package/src/activities/agent-turn/subscription-serving-claim.ts +178 -0
- package/src/activities/agent-turn/subscription-serving-providers.ts +15 -0
- package/src/activities/agent-turn/tool-environment.ts +384 -292
- package/src/activities/agent-turn/tool-policy.ts +104 -4
- package/src/activities/agent-turn/tool-result-spill.ts +1 -0
- package/src/activities/agent-turn/turn-context.ts +124 -8
- package/src/activities/agent-turn/web-search.ts +431 -0
- package/src/activities/agent-turn/xai-core.ts +301 -0
- package/src/activities/automations.ts +81 -6
- package/src/activities/browser-deadline-checkpoint.ts +297 -0
- package/src/activities/capabilities.ts +53 -213
- package/src/activities/codemode-dispatcher.ts +236 -14
- package/src/activities/codex-capacity.ts +27 -380
- package/src/activities/codex-image-generation.ts +252 -42
- package/src/activities/common.ts +12 -0
- package/src/activities/connector-attachments.ts +3 -1
- package/src/activities/context-compaction.ts +162 -21
- package/src/activities/environment.ts +18 -106
- package/src/activities/gmail-files.ts +108 -0
- package/src/activities/goals.ts +120 -204
- package/src/activities/image-generation-operation.ts +1 -1
- package/src/activities/incident-telemetry-authority.ts +80 -50
- package/src/activities/incident-telemetry-preflight.ts +27 -15
- package/src/activities/knowledge-indexing.ts +287 -17
- package/src/activities/knowledge-source-sync.ts +10 -0
- package/src/activities/mcp-account-routes.ts +2 -124
- package/src/activities/model-call-fact-reconciler.ts +112 -0
- package/src/activities/open-suffix-resume.ts +122 -88
- package/src/activities/parent-wake.ts +89 -21
- package/src/activities/programmatic-approvals.ts +26 -0
- package/src/activities/requester-unavailable-receipt.ts +14 -0
- package/src/activities/retained-screenshots.ts +135 -24
- package/src/activities/run-credential-renewal.ts +13 -1
- package/src/activities/run-credentials.ts +61 -19
- package/src/activities/run-input.ts +116 -9
- package/src/activities/sandbox-lease.ts +1615 -73
- package/src/activities/scheduled-tasks.ts +758 -141
- package/src/activities/session-archive.ts +382 -0
- package/src/activities/session-state.ts +219 -10
- package/src/activities/session-storage.ts +124 -0
- package/src/activities/site-auth-maintenance.ts +5 -2
- package/src/activities/subscription-core-claude-waits.ts +49 -0
- package/src/activities/subscription-core-codex-quota.ts +46 -0
- package/src/activities/subscription-core-codex-waits.ts +488 -0
- package/src/activities/subscription-core-image-operation.ts +126 -0
- package/src/activities/subscription-core-usage-recheck.ts +146 -0
- package/src/activities/subscription-core-wait-bindings.ts +12 -0
- package/src/activities/subscription-core-xai-quota.ts +85 -0
- package/src/activities/subscription-core-xai-waits.ts +48 -0
- package/src/activities/types.ts +85 -9
- package/src/activities/video-generation-admission.ts +1 -36
- package/src/activities/video-generation-credential.ts +38 -56
- package/src/activities/video-generation-reconciliation.ts +150 -131
- package/src/activities/video-generation-subscription-core.ts +180 -0
- package/src/activities/workspace-capture.ts +13 -2
- package/src/activities/workspace-credential-provider.ts +302 -0
- package/src/activities/xai-auth.ts +34 -112
- package/src/activities/xai-image-generation.ts +84 -36
- package/src/activities-control.ts +8 -0
- package/src/activities-turn.ts +5 -0
- package/src/activities.ts +17 -0
- package/src/activity-services.ts +29 -4
- package/src/browser-deadline-checkpoint-contract.ts +5 -0
- package/src/editable-artifact-hint-broker.ts +3 -0
- package/src/editable-artifact-materializer-service.ts +79 -38
- package/src/editable-artifact-materializer-subprocess.ts +47 -2
- package/src/editable-artifact-outbox-dispatcher.ts +107 -46
- package/src/editable-artifact-outbox-service.ts +55 -25
- package/src/github-rest-mcp.ts +1 -1
- package/src/host-export-pump.ts +26 -4
- package/src/host-export.ts +4 -1
- package/src/http.ts +4 -2
- package/src/index.ts +222 -282
- package/src/internal-maintenance.ts +347 -0
- package/src/maintenance-cadence.ts +156 -0
- package/src/observability-metrics.ts +1173 -73
- package/src/onepassword-vault-provider.ts +11 -0
- package/src/personal-github-git-credentials.ts +3 -1
- package/src/pr-review-credentials.ts +1 -1
- package/src/readiness-checks.ts +113 -0
- package/src/retained-process-retry.ts +36 -0
- package/src/sandbox-reaper-contract.ts +33 -0
- package/src/sandbox-resume.ts +444 -73
- package/src/sandbox-routing.ts +230 -75
- package/src/session-event-fanout.ts +23 -0
- package/src/telemetry-scheduler.ts +53 -0
- package/src/temporal-runtime-logger.ts +44 -0
- package/src/turn-task-queue-reader.ts +110 -0
- package/src/turn-worker-activity-telemetry.ts +209 -0
- package/src/worker-service-lifecycle.ts +54 -1
- package/src/workflows/activities.ts +16 -1
- package/src/workflows/browser-deadline-checkpoint.ts +55 -0
- package/src/workflows/file-upload-reaper.ts +2 -0
- package/src/workflows/sandbox-reaper.ts +88 -0
- package/src/workflows/scheduled-tasks.ts +26 -13
- package/src/workflows/session-storage.ts +19 -0
- package/src/workflows/session.ts +238 -33
- package/src/workflows/site-auth-maintenance.ts +2 -1
- package/src/workflows/workflow-wake.ts +26 -4
- package/src/workflows.ts +7 -0
- package/dist/activities/agent-turn/xai-capacity.d.ts +0 -2
- package/dist/activities/codex-fleet-shadow.d.ts +0 -74
- package/dist/activities/codex-rotation.d.ts +0 -200
- package/dist/activities/xai-quota.d.ts +0 -3
- package/dist/activities-control-QA6OLRQY.js.map +0 -1
- package/dist/activities-turn-YVVKCGAK.js.map +0 -1
- package/dist/chunk-GDCLDKSH.js.map +0 -1
- package/dist/chunk-I7HKKMUJ.js.map +0 -1
- package/dist/chunk-M3NVMF2V.js.map +0 -1
- package/dist/chunk-RAMNYSAW.js.map +0 -1
- package/src/activities/agent-turn/xai-capacity.ts +0 -257
- package/src/activities/codex-fleet-shadow.ts +0 -306
- package/src/activities/codex-rotation.ts +0 -685
- package/src/activities/xai-quota.ts +0 -35
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { appendSessionHistoryItems, upsertSandboxSessionEnvelope } from "@opengeni/db";
|
|
2
2
|
import { sandboxStateEntryFromRunState, type OpenGeniRuntime } from "@opengeni/runtime";
|
|
3
|
-
import type
|
|
3
|
+
import { sandboxManifestEnvironmentNamePredicate, type Settings } from "@opengeni/config";
|
|
4
4
|
import { TurnAttemptFencedError } from "../turn-attempt-fenced";
|
|
5
5
|
import type { SharedActivityServices } from "../types";
|
|
6
6
|
import { compactGeneratedImageHistory } from "../generated-images";
|
|
@@ -50,6 +50,7 @@ export type TurnHistorySinkDeps = {
|
|
|
50
50
|
*/
|
|
51
51
|
export class TurnHistorySink {
|
|
52
52
|
private readonly prefix = new HistoryPrefixGuard();
|
|
53
|
+
private checkpointTail: Promise<void> = Promise.resolve();
|
|
53
54
|
|
|
54
55
|
seedHistory(input: string | readonly unknown[] | { readonly history: unknown[] }, count: number) {
|
|
55
56
|
const items =
|
|
@@ -76,9 +77,22 @@ export class TurnHistorySink {
|
|
|
76
77
|
|
|
77
78
|
constructor(private readonly deps: TurnHistorySinkDeps) {}
|
|
78
79
|
|
|
79
|
-
reconcileConversationTruth =
|
|
80
|
+
reconcileConversationTruth = (
|
|
80
81
|
options: { skipInputOnlyRows?: boolean; requireDurable?: boolean } = {},
|
|
81
|
-
) => {
|
|
82
|
+
): Promise<void> => {
|
|
83
|
+
// The provider loop and the stream consumer checkpoint independently.
|
|
84
|
+
// Serialize the complete read/write/acknowledgment boundary, not just the
|
|
85
|
+
// database write: each caller must read history against the latest durable
|
|
86
|
+
// watermark. Keep each caller's durability policy and rejection intact.
|
|
87
|
+
const checkpoint = this.checkpointTail.then(() => this.reconcile(options));
|
|
88
|
+
this.checkpointTail = checkpoint.catch(() => {});
|
|
89
|
+
return checkpoint;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
private reconcile = async (options: {
|
|
93
|
+
skipInputOnlyRows?: boolean;
|
|
94
|
+
requireDurable?: boolean;
|
|
95
|
+
}) => {
|
|
82
96
|
const { media } = this.deps;
|
|
83
97
|
const stream = this.deps.getStream();
|
|
84
98
|
const turnId = this.deps.getTurnId();
|
|
@@ -140,7 +154,15 @@ export class TurnHistorySink {
|
|
|
140
154
|
"SDK conversation history is unavailable at a mandatory persistence boundary",
|
|
141
155
|
);
|
|
142
156
|
}
|
|
143
|
-
|
|
157
|
+
// W1 defensive strip: persist deployment-constant env names only. Built
|
|
158
|
+
// lazily: only an envelope that carries env needs the settings lookup.
|
|
159
|
+
let keepEnvironmentName: ((name: string) => boolean) | undefined;
|
|
160
|
+
const envelope = sandboxStateEntryFromRunState(stream.state, {
|
|
161
|
+
keepEnvironmentName: (name) =>
|
|
162
|
+
(keepEnvironmentName ??= sandboxManifestEnvironmentNamePredicate(
|
|
163
|
+
this.deps.getModelRunSettings(),
|
|
164
|
+
))(name),
|
|
165
|
+
});
|
|
144
166
|
if (envelope) {
|
|
145
167
|
await runMandatoryHistoryPersistenceStep("sandbox_envelope", () =>
|
|
146
168
|
upsertSandboxSessionEnvelope(this.deps.db, {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isCuaDesktopModelTool } from "@opengeni/contracts";
|
|
1
2
|
import {
|
|
2
3
|
normalizeProtocolJsonValue,
|
|
3
4
|
TURN_OPERATIONAL_NOTICE_PREFIX,
|
|
@@ -156,15 +157,20 @@ export function pendingToolCallFromSdkEvent(event: unknown): {
|
|
|
156
157
|
}
|
|
157
158
|
const raw = item.rawItem as Record<string, unknown>;
|
|
158
159
|
// Provider-executed search/image calls carry their outcome in this item,
|
|
159
|
-
// not a later function result
|
|
160
|
-
//
|
|
161
|
-
// approval requests are different:
|
|
160
|
+
// not a later function result, whether they succeeded or failed.
|
|
161
|
+
// Registering them as pending leaves an impossible receipt behind even
|
|
162
|
+
// after the turn completes. Hosted MCP approval requests are different:
|
|
163
|
+
// they still require a response.
|
|
162
164
|
const providerData = raw.providerData as Record<string, unknown> | undefined;
|
|
163
165
|
if (
|
|
164
166
|
raw.type === "hosted_tool_call" &&
|
|
165
167
|
raw.name !== "mcp_approval_request" &&
|
|
166
168
|
providerData?.type !== "mcp_approval_request" &&
|
|
167
|
-
(raw.status === "completed" ||
|
|
169
|
+
(raw.status === "completed" ||
|
|
170
|
+
raw.status === "failed" ||
|
|
171
|
+
raw.name === "image_generation_call" ||
|
|
172
|
+
raw.name === "web_search_call" ||
|
|
173
|
+
providerData?.type === "web_search_call")
|
|
168
174
|
)
|
|
169
175
|
return null;
|
|
170
176
|
const callId = toolCallIdFromSdkItem(raw) ?? raw.id;
|
|
@@ -186,7 +192,21 @@ export function toolCallProducesRetainableSessionImage(name: string | null): boo
|
|
|
186
192
|
return (
|
|
187
193
|
name === "computer_screenshot" ||
|
|
188
194
|
name === "view_image" ||
|
|
189
|
-
name === "interaction__computer_observe"
|
|
195
|
+
name === "interaction__computer_observe" ||
|
|
196
|
+
isCuaDesktopModelTool(name) ||
|
|
197
|
+
retainableBrowserScreenshotToolCall(name)
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** Browser interactions can carry an image block, including opt-in observe frames. */
|
|
202
|
+
export function retainableBrowserScreenshotToolCall(name: string | null): boolean {
|
|
203
|
+
return (
|
|
204
|
+
name === "browser_screenshot" ||
|
|
205
|
+
name === "interaction__browser_screenshot" ||
|
|
206
|
+
name === "browser_observe" ||
|
|
207
|
+
name === "interaction__browser_observe" ||
|
|
208
|
+
name === "browser_act" ||
|
|
209
|
+
name === "interaction__browser_act"
|
|
190
210
|
);
|
|
191
211
|
}
|
|
192
212
|
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { listSessionEvents, type Database } from "@opengeni/db";
|
|
2
|
+
import type { TurnInitiator, TurnInitiatorContext } from "@opengeni/contracts";
|
|
3
|
+
|
|
4
|
+
type ReplyTurn = {
|
|
5
|
+
source?: string | undefined;
|
|
6
|
+
initiator: TurnInitiator;
|
|
7
|
+
initiatorContext: TurnInitiatorContext;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Provenance an agent adds when it creates a session or calls the API
|
|
12
|
+
* (`via`, `viaTruncated`), plus internal-update and legacy markers: the prompt
|
|
13
|
+
* came from an agent or a migration, not from a person.
|
|
14
|
+
*/
|
|
15
|
+
const DERIVED_PROVENANCE_KEYS = ["via", "viaTruncated", "provenanceError", "backfill"] as const;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Worker-owned producers that create a session whose first turn (`source`
|
|
19
|
+
* `user`) is their task prompt: scheduled runs, automations and site-auth
|
|
20
|
+
* maintenance. An embedding host that asserts one of these service names only
|
|
21
|
+
* gives up the recorded reply; it grants nothing.
|
|
22
|
+
*/
|
|
23
|
+
function isWorkerTaskProducer(initiator: TurnInitiator): boolean {
|
|
24
|
+
if (initiator.kind !== "service") return false;
|
|
25
|
+
const subjectId = initiator.subjectId;
|
|
26
|
+
return (
|
|
27
|
+
subjectId === "scheduler" ||
|
|
28
|
+
subjectId === "site-auth-maintenance" ||
|
|
29
|
+
subjectId.startsWith("automation:")
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Whether a turn answers a message a person sent, directly or through an API
|
|
35
|
+
* caller that relays one (an embedding host, a realtime delegation). The
|
|
36
|
+
* source alone is not enough: every session's first turn is `user`, including
|
|
37
|
+
* a child an agent spawned and a session a scheduled task created.
|
|
38
|
+
*/
|
|
39
|
+
export function turnAnswersMessage(turn: ReplyTurn): boolean {
|
|
40
|
+
if (turn.source !== "user" && turn.source !== "api") return false;
|
|
41
|
+
if (
|
|
42
|
+
DERIVED_PROVENANCE_KEYS.some((key) =>
|
|
43
|
+
Object.prototype.hasOwnProperty.call(turn.initiatorContext, key),
|
|
44
|
+
)
|
|
45
|
+
) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
return !isWorkerTaskProducer(turn.initiator);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The reply `turn.completed` records when a turn ends through `wait_for_input`
|
|
53
|
+
* (read back with `turnCompletedReply` in `@opengeni/contracts`).
|
|
54
|
+
*
|
|
55
|
+
* Such a turn settles with an empty `output`: the wait, not an answer, ended
|
|
56
|
+
* it. When the turn answers a person's message, its latest assistant message
|
|
57
|
+
* is still that message's answer, for example a status reply given before
|
|
58
|
+
* waiting again on work in flight. That message shares its model response with
|
|
59
|
+
* the wait call, so it streams as commentary, which is activity everywhere
|
|
60
|
+
* else. Recording it lets unread attention and Slack treat it as the answer
|
|
61
|
+
* without relabelling the provider's phase in stored history. Turns that
|
|
62
|
+
* machine input, an agent or a worker-owned producer started only narrate
|
|
63
|
+
* progress and record nothing.
|
|
64
|
+
*
|
|
65
|
+
* The message this activity completed last is the newest. An activity that
|
|
66
|
+
* resumed the turn (after an approval, a human-input answer or a recovery) and
|
|
67
|
+
* completed none reads the turn's latest durable message instead.
|
|
68
|
+
*/
|
|
69
|
+
export async function inputWaitReply(input: {
|
|
70
|
+
inputWaitYielded: boolean;
|
|
71
|
+
turn: ReplyTurn;
|
|
72
|
+
latestAssistantMessageText: string | null;
|
|
73
|
+
readLatestDurableTurnMessage: () => Promise<string | null>;
|
|
74
|
+
}): Promise<string | null> {
|
|
75
|
+
if (!input.inputWaitYielded || !turnAnswersMessage(input.turn)) return null;
|
|
76
|
+
const text = input.latestAssistantMessageText ?? (await input.readLatestDurableTurnMessage());
|
|
77
|
+
return text !== null && text.trim().length > 0 ? text : null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** How far back to look past rejected-late or duplicate completions. */
|
|
81
|
+
const DURABLE_MESSAGE_LOOKBACK = 16;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Text of the newest current `agent.message.completed` this turn persisted,
|
|
85
|
+
* or null when the session's newest completion belongs to another turn.
|
|
86
|
+
*/
|
|
87
|
+
export async function latestDurableTurnMessageText(
|
|
88
|
+
db: Database,
|
|
89
|
+
input: { workspaceId: string; sessionId: string; turnId: string },
|
|
90
|
+
): Promise<string | null> {
|
|
91
|
+
const events = await listSessionEvents(db, input.workspaceId, input.sessionId, {
|
|
92
|
+
direction: "before",
|
|
93
|
+
includeTypes: ["agent.message.completed"],
|
|
94
|
+
limit: DURABLE_MESSAGE_LOOKBACK,
|
|
95
|
+
});
|
|
96
|
+
for (const event of events.reverse()) {
|
|
97
|
+
if (event.duplicateOfEventId || (event.turnAssociation ?? "current") !== "current") continue;
|
|
98
|
+
if (event.turnId !== input.turnId) return null;
|
|
99
|
+
const text = (event.payload as { text?: unknown } | null)?.text;
|
|
100
|
+
return typeof text === "string" ? text : null;
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Tool error the model receives when it waits before answering a person.
|
|
107
|
+
*
|
|
108
|
+
* Models with extended thinking often draft the reply inside their thinking
|
|
109
|
+
* and believe it was sent, then retry the wait unchanged and conclude that a
|
|
110
|
+
* wait cannot be armed at all. The text therefore names thinking explicitly and
|
|
111
|
+
* says the reply may share the wait call's response.
|
|
112
|
+
*/
|
|
113
|
+
export const INPUT_WAIT_REPLY_REFUSAL =
|
|
114
|
+
"wait_for_input was not registered: this turn answers a person's message and you have not written a visible reply yet. Your reasoning is not shown to them: text inside a thinking or reasoning block does not count, even when it is written as an answer. Write your answer to their message as a normal assistant text block (it may be in the same response, before the wait_for_input call), then call wait_for_input again. If an earlier wait is still armed, pass the time remaining on its deadline rather than a fresh timeout.";
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Refusals per turn attempt (one worker activity); a resumed or retried
|
|
118
|
+
* attempt starts again. After that the wait proceeds rather than looping.
|
|
119
|
+
*/
|
|
120
|
+
export const MAX_INPUT_WAIT_REPLY_REFUSALS = 2;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Why `wait_for_input` must not end this turn yet, or null.
|
|
124
|
+
*
|
|
125
|
+
* A wait ends the turn at the tool boundary, so no message can follow it. When
|
|
126
|
+
* the turn answers a person's message and has no visible assistant text, the
|
|
127
|
+
* person would get no answer at all (the model may have drafted one only in its
|
|
128
|
+
* reasoning). Refusing the wait as a tool error gives the model one more step
|
|
129
|
+
* to write the reply; the wait is registered on its next call.
|
|
130
|
+
*/
|
|
131
|
+
export async function inputWaitReplyRefusal(input: {
|
|
132
|
+
turn: ReplyTurn;
|
|
133
|
+
refusalsSoFar: number;
|
|
134
|
+
hasVisibleReply: () => Promise<boolean>;
|
|
135
|
+
}): Promise<string | null> {
|
|
136
|
+
if (input.refusalsSoFar >= MAX_INPUT_WAIT_REPLY_REFUSALS) return null;
|
|
137
|
+
if (!turnAnswersMessage(input.turn)) return null;
|
|
138
|
+
return (await input.hasVisibleReply()) ? null : INPUT_WAIT_REPLY_REFUSAL;
|
|
139
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isRetiredNativeAtlassianSource } from "@opengeni/contracts/atlassian-native-retirement";
|
|
1
2
|
import type { AttemptToolDefinition } from "@opengeni/codemode";
|
|
2
3
|
import {
|
|
3
4
|
freezeAgentLearningPolicy,
|
|
@@ -24,6 +25,7 @@ export async function createKnowledgeSourceAttemptTools(input: {
|
|
|
24
25
|
});
|
|
25
26
|
const source = accepted?.task.agentConfig.knowledgeSource;
|
|
26
27
|
if (!accepted || !source || accepted.task.action.kind !== "agent_turn") return [];
|
|
28
|
+
if (isRetiredNativeAtlassianSource(source)) return [];
|
|
27
29
|
const actor = input.context.actor;
|
|
28
30
|
const authorize = async () => {
|
|
29
31
|
const current = await freezeAgentLearningPolicy(input.db, input.context);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conservative progress evidence for a model response that reaches the worker
|
|
3
|
+
* as an SDK `response_done` event (providers without their own request
|
|
4
|
+
* events): completed assistant text or a complete function call. Reasoning,
|
|
5
|
+
* usage, an incomplete message and empty bookkeeping are not work. The shared
|
|
6
|
+
* false-resumption breaker of core waiters reads this through
|
|
7
|
+
* `agent.model.request` `meaningfulOutput`.
|
|
8
|
+
*/
|
|
9
|
+
export function sdkResponseHasMeaningfulOutput(event: unknown): boolean {
|
|
10
|
+
const output = responseDoneOutput(event);
|
|
11
|
+
if (!output) return false;
|
|
12
|
+
return output.some((value) => {
|
|
13
|
+
if (!isRecord(value)) return false;
|
|
14
|
+
if (value.status !== undefined && value.status !== "completed") return false;
|
|
15
|
+
if (value.type === "message" && value.role === "assistant" && Array.isArray(value.content))
|
|
16
|
+
return value.content.some(
|
|
17
|
+
(part) =>
|
|
18
|
+
isRecord(part) &&
|
|
19
|
+
part.type === "output_text" &&
|
|
20
|
+
typeof part.text === "string" &&
|
|
21
|
+
part.text.trim().length > 0,
|
|
22
|
+
);
|
|
23
|
+
return (
|
|
24
|
+
value.type === "function_call" &&
|
|
25
|
+
typeof value.name === "string" &&
|
|
26
|
+
value.name.trim().length > 0 &&
|
|
27
|
+
typeof value.callId === "string" &&
|
|
28
|
+
value.callId.length > 0 &&
|
|
29
|
+
typeof value.arguments === "string" &&
|
|
30
|
+
value.arguments.trim().length > 0
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function responseDoneOutput(event: unknown): unknown[] | null {
|
|
36
|
+
if (!isRecord(event) || event.type !== "raw_model_stream_event") return null;
|
|
37
|
+
const data = event.data;
|
|
38
|
+
if (!isRecord(data) || data.type !== "response_done" || !isRecord(data.response)) return null;
|
|
39
|
+
return Array.isArray(data.response.output) ? data.response.output : null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
43
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
44
|
+
}
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
type TurnToolCancellationFence,
|
|
13
13
|
} from "@opengeni/runtime";
|
|
14
14
|
import type { Settings } from "@opengeni/config";
|
|
15
|
-
import type { RetainedArtifactMetadata } from "@opengeni/contracts";
|
|
15
|
+
import type { RetainedArtifactMetadata, RetainedSessionScreenshotKind } from "@opengeni/contracts";
|
|
16
16
|
import type { ResumedTurnSandbox } from "../../sandbox-resume";
|
|
17
17
|
import type { SharedActivityServices } from "../types";
|
|
18
18
|
import {
|
|
@@ -79,6 +79,7 @@ export class TurnMediaArtifacts {
|
|
|
79
79
|
sandboxFileDownloadBackend: Settings["sandboxBackend"];
|
|
80
80
|
nativeImageGenerationRetention: NativeImageGenerationRetention | null = null;
|
|
81
81
|
readonly retainedSessionImageCallIds = new Set<string>();
|
|
82
|
+
readonly retainedSessionImageKindsByCallId = new Map<string, RetainedSessionScreenshotKind>();
|
|
82
83
|
|
|
83
84
|
constructor(private readonly deps: TurnMediaArtifactDeps) {
|
|
84
85
|
this.sandboxFileDownloadBackend = deps.getModelRunSettings().sandboxBackend;
|
|
@@ -124,6 +125,7 @@ export class TurnMediaArtifacts {
|
|
|
124
125
|
const publish = this.deps.getPublish();
|
|
125
126
|
const fence = this.deps.toolCancellationFenceRef.current;
|
|
126
127
|
const materialized = await materializeSandboxFileDownloads(sessionForDownload, [download], {
|
|
128
|
+
sandboxBackend: this.sandboxFileDownloadBackend,
|
|
127
129
|
onRuntimeEvent: async (event) => {
|
|
128
130
|
await publish?.([{ type: event.type, payload: event.payload }], true);
|
|
129
131
|
},
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { StreamEvent } from "@openai/agents";
|
|
2
|
+
|
|
3
|
+
/** SDK producer/consumer rendezvous. Usage stays on the sole consumer writer. */
|
|
4
|
+
export function createModelCallAdmission(input: {
|
|
5
|
+
signal: AbortSignal;
|
|
6
|
+
admit: () => Promise<void>;
|
|
7
|
+
}) {
|
|
8
|
+
type Receipt = {
|
|
9
|
+
promise: Promise<void>;
|
|
10
|
+
resolve: () => void;
|
|
11
|
+
reject: (error: unknown) => void;
|
|
12
|
+
};
|
|
13
|
+
const receipts = new WeakMap<object, Receipt>();
|
|
14
|
+
const responseReceipts = new Map<string, Receipt>();
|
|
15
|
+
const pending = new Set<Receipt>();
|
|
16
|
+
const responseId = (event: unknown): string | null => {
|
|
17
|
+
const id = (event as { response?: { id?: unknown } } | null)?.response?.id;
|
|
18
|
+
return typeof id === "string" && id.length > 0 ? id : null;
|
|
19
|
+
};
|
|
20
|
+
let latest: Promise<void> = Promise.resolve();
|
|
21
|
+
let failure: unknown;
|
|
22
|
+
let failed = false;
|
|
23
|
+
let rejectHalted!: (error: unknown) => void;
|
|
24
|
+
const halted = new Promise<never>((_, reject) => {
|
|
25
|
+
rejectHalted = reject;
|
|
26
|
+
});
|
|
27
|
+
void halted.catch(() => undefined);
|
|
28
|
+
const fail = (error: unknown) => {
|
|
29
|
+
if (failed) return;
|
|
30
|
+
failed = true;
|
|
31
|
+
failure = error;
|
|
32
|
+
rejectHalted(error);
|
|
33
|
+
for (const receipt of pending) receipt.reject(error);
|
|
34
|
+
pending.clear();
|
|
35
|
+
responseReceipts.clear();
|
|
36
|
+
};
|
|
37
|
+
const abort = () => fail(input.signal.reason ?? new Error("Model stream cancelled"));
|
|
38
|
+
input.signal.addEventListener("abort", abort, { once: true });
|
|
39
|
+
if (input.signal.aborted) abort();
|
|
40
|
+
return {
|
|
41
|
+
beforeModelRequest: async () => {
|
|
42
|
+
await Promise.race([latest, halted]);
|
|
43
|
+
if (failed) throw failure;
|
|
44
|
+
// Even a settled predecessor does not grant admission to the next call.
|
|
45
|
+
await Promise.race([input.admit(), halted]);
|
|
46
|
+
if (failed) throw failure;
|
|
47
|
+
},
|
|
48
|
+
onModelResponse: (event: StreamEvent): Promise<void> => {
|
|
49
|
+
if (failed) return Promise.reject(failure);
|
|
50
|
+
const id = responseId(event);
|
|
51
|
+
const existing =
|
|
52
|
+
receipts.get(event) ??
|
|
53
|
+
(id ? responseReceipts.get(id) : undefined) ??
|
|
54
|
+
(!id && pending.size === 1 ? pending.values().next().value : undefined);
|
|
55
|
+
if (existing) return existing.promise;
|
|
56
|
+
let resolve!: () => void;
|
|
57
|
+
let reject!: (error: unknown) => void;
|
|
58
|
+
const promise = new Promise<void>((yes, no) => {
|
|
59
|
+
resolve = yes;
|
|
60
|
+
reject = no;
|
|
61
|
+
});
|
|
62
|
+
// The next model entry awaits this receipt; rejection can happen sooner.
|
|
63
|
+
void promise.catch(() => undefined);
|
|
64
|
+
const receipt = { promise, resolve, reject };
|
|
65
|
+
receipts.set(event, receipt);
|
|
66
|
+
if (id) responseReceipts.set(id, receipt);
|
|
67
|
+
pending.add(receipt);
|
|
68
|
+
latest = promise;
|
|
69
|
+
return promise;
|
|
70
|
+
},
|
|
71
|
+
settle: (event: { type: string; data?: unknown }) => {
|
|
72
|
+
if (event.type !== "raw_model_stream_event" || !event.data || typeof event.data !== "object")
|
|
73
|
+
return;
|
|
74
|
+
if ((event.data as { type?: unknown }).type !== "response_done") return;
|
|
75
|
+
const id = responseId(event.data);
|
|
76
|
+
// Runner retry normalization copies response_done. It cannot create a
|
|
77
|
+
// second response before this receipt permits the next model entry.
|
|
78
|
+
const receipt =
|
|
79
|
+
receipts.get(event.data) ??
|
|
80
|
+
(id ? responseReceipts.get(id) : undefined) ??
|
|
81
|
+
(pending.size === 1 ? pending.values().next().value : undefined);
|
|
82
|
+
if (!receipt) return;
|
|
83
|
+
pending.delete(receipt);
|
|
84
|
+
if (id) responseReceipts.delete(id);
|
|
85
|
+
receipt.resolve();
|
|
86
|
+
},
|
|
87
|
+
fail,
|
|
88
|
+
close: () => {
|
|
89
|
+
input.signal.removeEventListener("abort", abort);
|
|
90
|
+
if (pending.size > 0) fail(new Error("Model stream closed before response settlement"));
|
|
91
|
+
responseReceipts.clear();
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}
|