@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
|
@@ -2,6 +2,7 @@ import { readReasoningConfiguration } from "@opengeni/codex";
|
|
|
2
2
|
import {
|
|
3
3
|
applyContextCompaction,
|
|
4
4
|
getActiveSessionHistoryItemsPaged,
|
|
5
|
+
getFiles,
|
|
5
6
|
recordSkippedContextCompaction,
|
|
6
7
|
recordStartedContextCompaction,
|
|
7
8
|
type Database,
|
|
@@ -9,9 +10,17 @@ import {
|
|
|
9
10
|
import {
|
|
10
11
|
EmptyCompactionSummaryError,
|
|
11
12
|
REMOTE_COMPACTION_V2_IMPLEMENTATION,
|
|
12
|
-
|
|
13
|
+
compactionSummaryOutputTokens,
|
|
14
|
+
buildSummaryItem,
|
|
15
|
+
buildCompactionPromptInput,
|
|
16
|
+
fitCompactionPrefix,
|
|
17
|
+
ANTHROPIC_REQUEST_MAX_BYTES,
|
|
18
|
+
AnthropicSizeRecoveryExhaustedError,
|
|
19
|
+
type AnthropicRequestSize,
|
|
20
|
+
omitOpaqueArtifactsFromPortableCompactionHistory,
|
|
13
21
|
buildCompactionReplacementHistory,
|
|
14
22
|
buildRemoteV2ReplacementHistory,
|
|
23
|
+
compactionAttachmentFileIds,
|
|
15
24
|
compactionThresholdTokens,
|
|
16
25
|
compactionReplacementFingerprint,
|
|
17
26
|
decideCompaction,
|
|
@@ -21,6 +30,7 @@ import {
|
|
|
21
30
|
projectRemoteCompactionOverflowRetryInput,
|
|
22
31
|
sanitizeHistoryItemsForModel,
|
|
23
32
|
summarizeForCompaction,
|
|
33
|
+
type AttachmentUploadTimes,
|
|
24
34
|
type CompactionItem,
|
|
25
35
|
type CompactionProviderRejection,
|
|
26
36
|
} from "@opengeni/runtime";
|
|
@@ -58,7 +68,15 @@ export type MaybeCompactResult =
|
|
|
58
68
|
* Codex, call Codex `/codex/responses` with `compaction_trigger` and persist the
|
|
59
69
|
* opaque compaction item. Fail closed — never silently fall back to portable.
|
|
60
70
|
*/
|
|
61
|
-
export type CompactionSummarizer = (
|
|
71
|
+
export type CompactionSummarizer = ((
|
|
72
|
+
settings: Settings,
|
|
73
|
+
input: CompactionItem[],
|
|
74
|
+
) => Promise<string>) & {
|
|
75
|
+
/** Model-visible instructions and tool schemas outside the history estimate. */
|
|
76
|
+
estimatePrefixTokens?: () => number;
|
|
77
|
+
/** Exact provider wire size, with the same projection as the checkpoint call. */
|
|
78
|
+
measureInputBytes?: (settings: Settings, input: CompactionItem[]) => Promise<number>;
|
|
79
|
+
};
|
|
62
80
|
|
|
63
81
|
/** Returns the opaque Codex remote compaction v2 item. */
|
|
64
82
|
export type RemoteCompactionV2Requester = (
|
|
@@ -81,7 +99,7 @@ export async function maybeCompactContext(
|
|
|
81
99
|
// Injectable for tests; defaults to the real provider-aware model call.
|
|
82
100
|
summarize: CompactionSummarizer = (s, m) =>
|
|
83
101
|
summarizeForCompaction(s, m, {
|
|
84
|
-
maxOutputTokens:
|
|
102
|
+
maxOutputTokens: compactionSummaryOutputTokens(s.contextWindowTokens),
|
|
85
103
|
}),
|
|
86
104
|
// Operator-forced (the /compact command): bypass the budget trigger and
|
|
87
105
|
// compact now if there is anything to summarize. Structural guards still hold.
|
|
@@ -107,6 +125,8 @@ export async function maybeCompactContext(
|
|
|
107
125
|
materializeHistory?: (items: CompactionItem[]) => Promise<CompactionItem[]>;
|
|
108
126
|
/** Turn-scoped attachment/modality view; canonical persisted rows stay untouched. */
|
|
109
127
|
projectModelInput?: (items: CompactionItem[]) => Promise<CompactionItem[]>;
|
|
128
|
+
/** A typed pre-dispatch size rejection parks the newest complete work unit. */
|
|
129
|
+
requestSizeRecovery?: { maxBytes: number; size: AnthropicRequestSize };
|
|
110
130
|
} = {},
|
|
111
131
|
): Promise<MaybeCompactResult> {
|
|
112
132
|
if (options.codexCompactionMode === "remote_v2" && options.isCodexSubscriptionTurn !== true) {
|
|
@@ -205,9 +225,14 @@ export async function maybeCompactContext(
|
|
|
205
225
|
expectedAttemptId: scope.attemptId,
|
|
206
226
|
trigger,
|
|
207
227
|
estimatedTokensBefore,
|
|
228
|
+
...(options.requestSizeRecovery
|
|
229
|
+
? { requestSizeRecovery: options.requestSizeRecovery.size }
|
|
230
|
+
: {}),
|
|
208
231
|
...(useRemoteV2 ? { implementation: REMOTE_COMPACTION_V2_IMPLEMENTATION } : {}),
|
|
209
232
|
});
|
|
210
233
|
if (!started.recorded) {
|
|
234
|
+
if (started.reason === "request_size_recovery_exhausted")
|
|
235
|
+
throw new AnthropicSizeRecoveryExhaustedError();
|
|
211
236
|
throw new TurnAttemptFencedError(
|
|
212
237
|
`turn attempt was fenced while recording context compaction start: ${started.reason}`,
|
|
213
238
|
);
|
|
@@ -275,6 +300,44 @@ export async function settleFailedContextCompactionLandmark(
|
|
|
275
300
|
return settled;
|
|
276
301
|
}
|
|
277
302
|
|
|
303
|
+
/**
|
|
304
|
+
* After `compaction.started`, record that the checkpoint request was cut short
|
|
305
|
+
* by the attempt's own cancellation (graceful worker shutdown, or any other
|
|
306
|
+
* activity cancellation) rather than by a provider or summarizer failure.
|
|
307
|
+
*
|
|
308
|
+
* Unlike {@link settleFailedContextCompactionLandmark}, this never consumes an
|
|
309
|
+
* operator `/compact` request: the recovered attempt of the same turn
|
|
310
|
+
* re-evaluates, exactly as when a Pause has already fenced the attempt. A
|
|
311
|
+
* fence rejection is not an error here: the control that closed the attempt
|
|
312
|
+
* owns the outcome, so the caller's cancellation must keep propagating.
|
|
313
|
+
*/
|
|
314
|
+
export async function settleInterruptedContextCompactionLandmark(
|
|
315
|
+
db: Database,
|
|
316
|
+
scope: {
|
|
317
|
+
accountId: string;
|
|
318
|
+
workspaceId: string;
|
|
319
|
+
sessionId: string;
|
|
320
|
+
turnId: string;
|
|
321
|
+
executionGeneration: number;
|
|
322
|
+
attemptId: string;
|
|
323
|
+
},
|
|
324
|
+
options: {
|
|
325
|
+
publishLiveEvents?: (events: SessionEvent[]) => Promise<void>;
|
|
326
|
+
} = {},
|
|
327
|
+
): Promise<{ recorded: boolean; events: SessionEvent[] }> {
|
|
328
|
+
const skipped = await recordSkippedContextCompaction(db, {
|
|
329
|
+
...scope,
|
|
330
|
+
expectedExecutionGeneration: scope.executionGeneration,
|
|
331
|
+
expectedAttemptId: scope.attemptId,
|
|
332
|
+
reason: "interrupted",
|
|
333
|
+
requirePendingRequest: false,
|
|
334
|
+
clearRequestedCompaction: false,
|
|
335
|
+
});
|
|
336
|
+
if (!skipped.recorded) return { recorded: false, events: [] };
|
|
337
|
+
await options.publishLiveEvents?.(skipped.events);
|
|
338
|
+
return { recorded: true, events: skipped.events };
|
|
339
|
+
}
|
|
340
|
+
|
|
278
341
|
function prependCompactionEvents(
|
|
279
342
|
prefix: SessionEvent[],
|
|
280
343
|
outcome: MaybeCompactResult,
|
|
@@ -300,6 +363,7 @@ async function settleSkippedAfterStart(
|
|
|
300
363
|
reason:
|
|
301
364
|
| "no_history"
|
|
302
365
|
| "replacement_not_smaller"
|
|
366
|
+
| "replacement_exceeds_model_budget"
|
|
303
367
|
| "replacement_unchanged"
|
|
304
368
|
| "summarization_failed",
|
|
305
369
|
): Promise<Extract<MaybeCompactResult, { compacted: false }>> {
|
|
@@ -377,6 +441,7 @@ async function compactContextRemoteV2(
|
|
|
377
441
|
canonicalItems,
|
|
378
442
|
compactionItem,
|
|
379
443
|
(item) => retainedTokens.get(item) ?? estimateTokens([item]),
|
|
444
|
+
await attachmentUploadTimes(db, scope.workspaceId, canonicalItems),
|
|
380
445
|
);
|
|
381
446
|
const estimatedTokensAfter = estimateTokens(await projectForWire(replacementHistory));
|
|
382
447
|
const replacementFingerprint = compactionReplacementFingerprint(replacementHistory);
|
|
@@ -448,21 +513,83 @@ async function compactContextPortable(
|
|
|
448
513
|
options: {
|
|
449
514
|
clearRequestedCompaction?: boolean;
|
|
450
515
|
trigger?: "auto" | "operator" | "proactive" | "overflow";
|
|
516
|
+
requestSizeRecovery?: { maxBytes: number };
|
|
451
517
|
},
|
|
452
518
|
projectForWire: (items: CompactionItem[]) => Promise<CompactionItem[]>,
|
|
453
519
|
): Promise<MaybeCompactResult> {
|
|
454
520
|
const estimatedTokensBefore = estimateTokens(items);
|
|
455
|
-
const
|
|
521
|
+
const prefixTokens = Math.max(0, Math.ceil(summarize.estimatePrefixTokens?.() ?? 0));
|
|
522
|
+
const outputReserve = compactionSummaryOutputTokens(settings.contextWindowTokens);
|
|
523
|
+
const structuralBudget = Math.min(
|
|
524
|
+
contextInputBudgetTokens(settings) || settings.contextWindowTokens - outputReserve,
|
|
525
|
+
settings.contextWindowTokens - outputReserve,
|
|
526
|
+
);
|
|
527
|
+
let summarizedItems = canonicalItems;
|
|
528
|
+
let deferredItems: CompactionItem[] = [];
|
|
529
|
+
let summarized: Awaited<ReturnType<typeof summarizeWithCodexOverflowTrimming>>;
|
|
530
|
+
if (summarize.measureInputBytes) {
|
|
531
|
+
const budget = Math.max(0, structuralBudget - prefixTokens);
|
|
532
|
+
const maxBytes = Math.min(
|
|
533
|
+
ANTHROPIC_REQUEST_MAX_BYTES,
|
|
534
|
+
options.requestSizeRecovery?.maxBytes ?? ANTHROPIC_REQUEST_MAX_BYTES,
|
|
535
|
+
);
|
|
536
|
+
const prepare = async (prefix: CompactionItem[]) =>
|
|
537
|
+
buildCompactionPromptInput(
|
|
538
|
+
omitOpaqueArtifactsFromPortableCompactionHistory(await projectForWire(prefix)),
|
|
539
|
+
);
|
|
540
|
+
const cut = await fitCompactionPrefix(
|
|
541
|
+
canonicalItems,
|
|
542
|
+
async (prefix) => {
|
|
543
|
+
const projected = await prepare(prefix);
|
|
544
|
+
return (
|
|
545
|
+
estimateTokens(projected) <= budget &&
|
|
546
|
+
(await summarize.measureInputBytes!(settings, projected)) <= maxBytes
|
|
547
|
+
);
|
|
548
|
+
},
|
|
549
|
+
Boolean(options.requestSizeRecovery),
|
|
550
|
+
);
|
|
551
|
+
if (cut === null)
|
|
552
|
+
throw new EmptyCompactionSummaryError({
|
|
553
|
+
stage: "portable_byte_budget",
|
|
554
|
+
reason: "no_complete_prefix_fit",
|
|
555
|
+
});
|
|
556
|
+
summarizedItems = canonicalItems.slice(0, cut);
|
|
557
|
+
deferredItems = canonicalItems.slice(cut);
|
|
558
|
+
const projected = await prepare(summarizedItems);
|
|
559
|
+
summarized = {
|
|
560
|
+
summaryBody: await summarize(settings, projected),
|
|
561
|
+
preparation: {
|
|
562
|
+
input: projected,
|
|
563
|
+
estimatedInputTokens: estimateTokens(projected),
|
|
564
|
+
rewrittenToolOutputs: 0,
|
|
565
|
+
droppedHistoryItems: 0,
|
|
566
|
+
},
|
|
567
|
+
providerCalls: 1,
|
|
568
|
+
};
|
|
569
|
+
} else summarized = await summarizeWithCodexOverflowTrimming(summarize, settings, items);
|
|
456
570
|
const summaryBody = summarized.summaryBody;
|
|
457
571
|
const retainedTokens = await retentionTokenCounts(canonicalItems, projectForWire);
|
|
572
|
+
const summaryTokens = estimateTokens([buildSummaryItem(summaryBody)]);
|
|
458
573
|
const replacementHistory = buildCompactionReplacementHistory(
|
|
459
|
-
|
|
574
|
+
summarizedItems,
|
|
460
575
|
summaryBody,
|
|
461
576
|
(item) => retainedTokens.get(item) ?? estimateTokens([item]),
|
|
577
|
+
Math.min(outputReserve, Math.max(0, structuralBudget - prefixTokens - summaryTokens)),
|
|
578
|
+
await attachmentUploadTimes(db, scope.workspaceId, summarizedItems),
|
|
462
579
|
);
|
|
463
|
-
const estimatedTokensAfter = estimateTokens(
|
|
464
|
-
|
|
465
|
-
|
|
580
|
+
const estimatedTokensAfter = estimateTokens(
|
|
581
|
+
await projectForWire([...replacementHistory, ...deferredItems]),
|
|
582
|
+
);
|
|
583
|
+
if (estimatedTokensAfter + prefixTokens > structuralBudget) {
|
|
584
|
+
return await settleSkippedAfterStart(db, scope, options, "replacement_exceeds_model_budget");
|
|
585
|
+
}
|
|
586
|
+
const replacementFingerprint = compactionReplacementFingerprint([
|
|
587
|
+
...replacementHistory,
|
|
588
|
+
...deferredItems,
|
|
589
|
+
]);
|
|
590
|
+
const previousReplacementFingerprint = deferredItems.length
|
|
591
|
+
? compactionReplacementFingerprint(canonicalItems)
|
|
592
|
+
: latestCompactionReplacementFingerprint(canonicalItems);
|
|
466
593
|
const summaryIndex =
|
|
467
594
|
replacementHistory.length -
|
|
468
595
|
(readReasoningConfiguration(replacementHistory.at(-1) ?? {}) ? 2 : 1);
|
|
@@ -486,8 +613,8 @@ async function compactContextPortable(
|
|
|
486
613
|
expectedExecutionGeneration: scope.executionGeneration,
|
|
487
614
|
expectedAttemptId: scope.attemptId,
|
|
488
615
|
replacementItems: replacementHistory.slice(0, summaryIndex),
|
|
489
|
-
...(replacementHistory.length > summaryIndex + 1
|
|
490
|
-
? { trailingItems: replacementHistory.slice(summaryIndex + 1) }
|
|
616
|
+
...(replacementHistory.length > summaryIndex + 1 || deferredItems.length > 0
|
|
617
|
+
? { trailingItems: [...replacementHistory.slice(summaryIndex + 1), ...deferredItems] }
|
|
491
618
|
: {}),
|
|
492
619
|
summaryItem: summaryItem as Record<string, unknown>,
|
|
493
620
|
...(options.clearRequestedCompaction ? { clearRequestedCompaction: true } : {}),
|
|
@@ -499,6 +626,9 @@ async function compactContextPortable(
|
|
|
499
626
|
compactionInputToolOutputsRewritten: summarized.preparation.rewrittenToolOutputs,
|
|
500
627
|
compactionInputHistoryItemsDropped: summarized.preparation.droppedHistoryItems,
|
|
501
628
|
compactionInputProviderCalls: summarized.providerCalls,
|
|
629
|
+
...(summarize.measureInputBytes
|
|
630
|
+
? { compactionDeferredHistoryItems: deferredItems.length }
|
|
631
|
+
: {}),
|
|
502
632
|
},
|
|
503
633
|
});
|
|
504
634
|
if (!applied.applied) {
|
|
@@ -520,7 +650,7 @@ async function compactContextPortable(
|
|
|
520
650
|
};
|
|
521
651
|
}
|
|
522
652
|
|
|
523
|
-
async function summarizeWithCodexOverflowTrimming(
|
|
653
|
+
export async function summarizeWithCodexOverflowTrimming(
|
|
524
654
|
summarize: CompactionSummarizer,
|
|
525
655
|
settings: Settings,
|
|
526
656
|
activeHistory: CompactionItem[],
|
|
@@ -531,17 +661,32 @@ async function summarizeWithCodexOverflowTrimming(
|
|
|
531
661
|
}> {
|
|
532
662
|
// Codex's estimator is intentionally coarse. Keep the explicit checkpoint
|
|
533
663
|
// request below both the effective input window and the raw window minus the
|
|
534
|
-
// requested summary
|
|
535
|
-
//
|
|
536
|
-
//
|
|
537
|
-
const summaryAwareBudget = Math.max(
|
|
664
|
+
// requested summary. Preserve the full portable history copy on the first
|
|
665
|
+
// call whenever it fits; only trim further after an actual provider overflow.
|
|
666
|
+
// Durable active history remains untouched until applyContextCompaction.
|
|
667
|
+
const summaryAwareBudget = Math.max(
|
|
668
|
+
0,
|
|
669
|
+
settings.contextWindowTokens - compactionSummaryOutputTokens(settings.contextWindowTokens),
|
|
670
|
+
);
|
|
538
671
|
const configuredInputBudget = contextInputBudgetTokens(settings);
|
|
539
672
|
const structuralBudget = Math.min(
|
|
540
673
|
configuredInputBudget > 0 ? configuredInputBudget : summaryAwareBudget,
|
|
541
674
|
summaryAwareBudget,
|
|
542
675
|
);
|
|
543
|
-
const
|
|
676
|
+
const prefixTokens = Math.max(0, Math.ceil(summarize.estimatePrefixTokens?.() ?? 0));
|
|
677
|
+
const initialBudget = Math.max(0, structuralBudget - prefixTokens);
|
|
544
678
|
let preparation = prepareCompactionPromptInput(activeHistory, initialBudget);
|
|
679
|
+
// A checkpoint prompt without source history cannot summarize that history.
|
|
680
|
+
// Do not let a plausible-sounding reply replace durable active context.
|
|
681
|
+
const requireHistory = () => {
|
|
682
|
+
if (activeHistory.length > 0 && preparation.input.length === 1) {
|
|
683
|
+
throw new EmptyCompactionSummaryError({
|
|
684
|
+
stage: "portable_input_budget",
|
|
685
|
+
reason: "no_history_fit",
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
};
|
|
689
|
+
requireHistory();
|
|
545
690
|
try {
|
|
546
691
|
return {
|
|
547
692
|
summaryBody: await summarize(settings, preparation.input),
|
|
@@ -551,15 +696,16 @@ async function summarizeWithCodexOverflowTrimming(
|
|
|
551
696
|
} catch (error) {
|
|
552
697
|
if (!isContextWindowExceeded(error)) throw error;
|
|
553
698
|
// The provider is more authoritative than the byte/4 estimate. Refit once
|
|
554
|
-
// to
|
|
699
|
+
// to 40% of both the available target and the actual prepared estimate;
|
|
555
700
|
// then fail terminally with prior history intact. Never issue one failing
|
|
556
|
-
// request per oldest item. The
|
|
557
|
-
// provider can count slightly more than twice the byte/4 estimate
|
|
558
|
-
//
|
|
701
|
+
// request per oldest item. The retry is bounded, not a guarantee: the
|
|
702
|
+
// provider can count slightly more than twice the byte/4 estimate. The
|
|
703
|
+
// prepared prefix has already been reserved from the available budget.
|
|
559
704
|
const retryBudget = Math.floor(
|
|
560
|
-
Math.min(initialBudget * 0.
|
|
705
|
+
Math.min(initialBudget * 0.4, preparation.estimatedInputTokens * 0.4),
|
|
561
706
|
);
|
|
562
707
|
preparation = prepareCompactionPromptInput(activeHistory, retryBudget);
|
|
708
|
+
requireHistory();
|
|
563
709
|
return {
|
|
564
710
|
summaryBody: await summarize(settings, preparation.input),
|
|
565
711
|
preparation,
|
|
@@ -612,6 +758,21 @@ export function isExactContextLengthExceeded(
|
|
|
612
758
|
);
|
|
613
759
|
}
|
|
614
760
|
|
|
761
|
+
/**
|
|
762
|
+
* Upload times for the files a new attachment catalog may list. They are
|
|
763
|
+
* immutable file facts, frozen into the catalog text when it is created.
|
|
764
|
+
*/
|
|
765
|
+
async function attachmentUploadTimes(
|
|
766
|
+
db: Database,
|
|
767
|
+
workspaceId: string,
|
|
768
|
+
items: readonly CompactionItem[],
|
|
769
|
+
): Promise<AttachmentUploadTimes> {
|
|
770
|
+
const fileIds = compactionAttachmentFileIds(items);
|
|
771
|
+
if (fileIds.length === 0) return new Map();
|
|
772
|
+
const files = await getFiles(db, workspaceId, fileIds);
|
|
773
|
+
return new Map(files.map((file) => [file.id, file.createdAt]));
|
|
774
|
+
}
|
|
775
|
+
|
|
615
776
|
/** Charge retained uploads by their projected image context, not reference text. */
|
|
616
777
|
async function retentionTokenCounts(
|
|
617
778
|
items: CompactionItem[],
|
|
@@ -14,29 +14,14 @@ import {
|
|
|
14
14
|
type GitCredentialTransport,
|
|
15
15
|
type GitCredentials,
|
|
16
16
|
type ResourceRef,
|
|
17
|
-
type SandboxSecrets,
|
|
18
17
|
type SessionTurn,
|
|
19
18
|
type TurnInitiator,
|
|
20
19
|
type TurnInitiatorContext,
|
|
21
20
|
} from "@opengeni/contracts";
|
|
22
21
|
import { personalGitHubRepositoryResources } from "@opengeni/core";
|
|
23
22
|
import { mintSandboxCodemodeToken, type SandboxCodemodeAuthority } from "@opengeni/runtime/sandbox";
|
|
24
|
-
import {
|
|
25
|
-
loadVariableSetForRun as loadWorkspaceEnvironmentForRunFromDb,
|
|
26
|
-
type Database,
|
|
27
|
-
type VariableSetForRun as WorkspaceEnvironmentForRun,
|
|
28
|
-
} from "@opengeni/db";
|
|
29
23
|
import { createGitHubAppInstallationTokenWithExpiry, githubAppBotIdentity } from "@opengeni/github";
|
|
30
24
|
|
|
31
|
-
// Re-exported from the shared @opengeni/db leaf (moved there so the API-direct
|
|
32
|
-
// attach paths can load the SAME decrypted workspace environment the turn
|
|
33
|
-
// declares — keeping the box-manifest env and agent-manifest env identical).
|
|
34
|
-
// Existing worker import sites (agent-turn) continue importing from here.
|
|
35
|
-
export {
|
|
36
|
-
loadWorkspaceEnvironmentForRunFromDb as loadWorkspaceEnvironmentForRun,
|
|
37
|
-
type WorkspaceEnvironmentForRun,
|
|
38
|
-
};
|
|
39
|
-
|
|
40
25
|
// §7.6 connection-credential provider — the run's workspace identity, threaded so the connection-credential
|
|
41
26
|
// provider can be called with the run's tenant context AND so the workspace-scope cross-check
|
|
42
27
|
// cross-check has the run's workspace to assert the provider's echo against.
|
|
@@ -45,15 +30,6 @@ export type ConnectionScope = {
|
|
|
45
30
|
workspaceId: string;
|
|
46
31
|
};
|
|
47
32
|
|
|
48
|
-
export type VariableSetCredentialAuthority = {
|
|
49
|
-
sessionId: string;
|
|
50
|
-
turnId: string;
|
|
51
|
-
attemptId: string;
|
|
52
|
-
executionGeneration: number;
|
|
53
|
-
initiator: TurnInitiator;
|
|
54
|
-
initiatingHumanSubjectId: string | null;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
33
|
export type GitTokenSeeds = Partial<Record<GitCredentialProvider, string>>;
|
|
58
34
|
export type GitTokenExpiries = Partial<Record<GitCredentialProvider, string>>;
|
|
59
35
|
export type GitCredentialBindingSeed = {
|
|
@@ -122,80 +98,10 @@ type RunGitCredentialOptions = {
|
|
|
122
98
|
authorizeGitHubTokenMint?: GitHubTokenMintAuthorization;
|
|
123
99
|
};
|
|
124
100
|
|
|
125
|
-
//
|
|
126
|
-
//
|
|
127
|
-
//
|
|
128
|
-
//
|
|
129
|
-
//
|
|
130
|
-
// Unattached runs (environmentId === null) short-circuit identically in BOTH
|
|
131
|
-
// modes: zero DB/provider work, returns null. When a provider IS bound it owns
|
|
132
|
-
// the decrypt end-to-end (it reads the host's own store), so the local DB read
|
|
133
|
-
// is skipped — the provider is the sole source of truth for that leg.
|
|
134
|
-
export async function loadWorkspaceEnvironmentForRunWithCredentials(
|
|
135
|
-
db: Database,
|
|
136
|
-
settings: Settings,
|
|
137
|
-
scope: ConnectionScope,
|
|
138
|
-
environmentId: string | null,
|
|
139
|
-
authority: VariableSetCredentialAuthority,
|
|
140
|
-
sandboxSecrets?: ConnectionCredentialsPort["sandboxSecrets"],
|
|
141
|
-
options: {
|
|
142
|
-
/**
|
|
143
|
-
* Exact accepted scheduled-occurrence generation for this Variable Set,
|
|
144
|
-
* resolved by the caller from the immutable run snapshot; null/omitted for
|
|
145
|
-
* ordinary live turns.
|
|
146
|
-
*/
|
|
147
|
-
expectedGeneration?: number | null;
|
|
148
|
-
} = {},
|
|
149
|
-
): Promise<WorkspaceEnvironmentForRun | null> {
|
|
150
|
-
if (!sandboxSecrets) {
|
|
151
|
-
return loadWorkspaceEnvironmentForRunFromDb(db, settings, {
|
|
152
|
-
...scope,
|
|
153
|
-
variableSetId: environmentId,
|
|
154
|
-
authority: {
|
|
155
|
-
kind: "agent_attempt",
|
|
156
|
-
subjectId: authority.initiatingHumanSubjectId ?? authority.initiator.subjectId,
|
|
157
|
-
...authority,
|
|
158
|
-
},
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
if (!environmentId) {
|
|
162
|
-
return null;
|
|
163
|
-
}
|
|
164
|
-
const expectedGeneration = options.expectedGeneration ?? null;
|
|
165
|
-
const secrets: SandboxSecrets = await sandboxSecrets({
|
|
166
|
-
accountId: scope.accountId,
|
|
167
|
-
workspaceId: scope.workspaceId,
|
|
168
|
-
...authority,
|
|
169
|
-
variableSetId: environmentId,
|
|
170
|
-
...(expectedGeneration === null ? {} : { expectedGeneration }),
|
|
171
|
-
});
|
|
172
|
-
// workspace-scope cross-check: the provider must echo THIS run's workspace before we apply its
|
|
173
|
-
// decrypted values into the sandbox.
|
|
174
|
-
assertWorkspaceEcho("sandboxSecrets", scope, secrets.workspaceId);
|
|
175
|
-
if (
|
|
176
|
-
secrets.accountId !== scope.accountId ||
|
|
177
|
-
secrets.sessionId !== authority.sessionId ||
|
|
178
|
-
secrets.turnId !== authority.turnId ||
|
|
179
|
-
secrets.attemptId !== authority.attemptId ||
|
|
180
|
-
secrets.executionGeneration !== authority.executionGeneration ||
|
|
181
|
-
secrets.variableSetId !== environmentId ||
|
|
182
|
-
// A scheduled attempt materializes only the exact accepted generation:
|
|
183
|
-
// the host must echo it and return that generation's values.
|
|
184
|
-
(expectedGeneration !== null &&
|
|
185
|
-
(secrets.expectedGeneration !== expectedGeneration ||
|
|
186
|
-
secrets.generation !== expectedGeneration))
|
|
187
|
-
) {
|
|
188
|
-
throw new Error("connection-credential provider (sandboxSecrets) returned stale authority");
|
|
189
|
-
}
|
|
190
|
-
return {
|
|
191
|
-
id: secrets.id ?? environmentId,
|
|
192
|
-
name: secrets.name ?? environmentId,
|
|
193
|
-
description: secrets.description ?? null,
|
|
194
|
-
scope: secrets.scope,
|
|
195
|
-
generation: secrets.generation,
|
|
196
|
-
values: secrets.values,
|
|
197
|
-
};
|
|
198
|
-
}
|
|
101
|
+
// W1 (secrets delivery): the worker no longer loads or decrypts Variable Sets
|
|
102
|
+
// for a turn, and the `sandboxSecrets` leg is gone. User secrets reach a
|
|
103
|
+
// command only through `{{secret:…}}` references resolved at the exec
|
|
104
|
+
// boundary; the manifest carries deployment constants only.
|
|
199
105
|
|
|
200
106
|
// Workspace-scope cross-check. A credential provider echoes the workspace it scoped
|
|
201
107
|
// the credential to; we ASSERT it equals the run's workspace BEFORE the caller
|
|
@@ -217,7 +123,6 @@ function assertWorkspaceEcho(
|
|
|
217
123
|
export async function sandboxEnvironmentForRun(
|
|
218
124
|
settings: Settings,
|
|
219
125
|
resources: ResourceRef[],
|
|
220
|
-
workspaceEnvironment: Record<string, string> = {},
|
|
221
126
|
// §7.6 connection-credential provider - optional host git-credential provider + the run scope it needs
|
|
222
127
|
// (unset, the standalone default → self-mint from `settings` byte-for-byte).
|
|
223
128
|
// `skipGitHubToken` (Stage D): a connected-machine turn skips the inert platform
|
|
@@ -245,11 +150,10 @@ export async function sandboxEnvironmentForRun(
|
|
|
245
150
|
codemodeToken?: string;
|
|
246
151
|
codemodeTokenExpiresAt?: Date;
|
|
247
152
|
}> {
|
|
248
|
-
// Precedence: deployment allowlist < git identity <
|
|
249
|
-
//
|
|
250
|
-
//
|
|
251
|
-
//
|
|
252
|
-
// workspace values from colliding with the platform-managed entries.
|
|
153
|
+
// Precedence: deployment allowlist < git identity < backend-aware HOME (the
|
|
154
|
+
// STABLE base, shared with the API-direct attach paths via
|
|
155
|
+
// stableSandboxEnvironmentForRun) < platform run-scoped git auth (applied
|
|
156
|
+
// below, always last). No user values: secrets are delivered per command (W1).
|
|
253
157
|
//
|
|
254
158
|
// TOKEN-BROKER (B1): run-scoped git provider tokens are NO LONGER layered into
|
|
255
159
|
// the box/agent MANIFEST env (no GH_TOKEN/GITHUB_TOKEN/GITLAB_TOKEN/
|
|
@@ -263,7 +167,7 @@ export async function sandboxEnvironmentForRun(
|
|
|
263
167
|
// GitHub keeps the legacy `gitToken`/OPENGENI_GIT_TOKEN_FILE alias. The worker
|
|
264
168
|
// proactively renews every selected provider behind these stable pointers.
|
|
265
169
|
const stableOptions = options.scope ? { workspaceId: options.scope.workspaceId } : {};
|
|
266
|
-
const environment = stableSandboxEnvironmentForRun(settings,
|
|
170
|
+
const environment = stableSandboxEnvironmentForRun(settings, stableOptions);
|
|
267
171
|
const codemodeDelivery = options.codemodeDelivery ?? "managed_file";
|
|
268
172
|
// Connected Machines keep their machine-wide environment untouched. Their
|
|
269
173
|
// URL, package hint, and direct bearer are projected only onto an exact child
|
|
@@ -880,7 +784,15 @@ function gitCredentialSelections(resources: ResourceRef[]): GitCredentialSelecti
|
|
|
880
784
|
);
|
|
881
785
|
}
|
|
882
786
|
entry.installationId = installationId;
|
|
883
|
-
|
|
787
|
+
// The same repository may legitimately be attached more than once
|
|
788
|
+
// (another ref or mount path), and sessions persisted before the
|
|
789
|
+
// web picker reconciled manual and catalog rows can hold an exact
|
|
790
|
+
// duplicate. One binding's token allowlist is the unique repository
|
|
791
|
+
// set; every resource keeps its own ref and mount above, and the
|
|
792
|
+
// GitHub token boundary still rejects duplicates from other callers.
|
|
793
|
+
if (!entry.repositoryIds.includes(repositoryId)) {
|
|
794
|
+
entry.repositoryIds.push(repositoryId);
|
|
795
|
+
}
|
|
884
796
|
}
|
|
885
797
|
}
|
|
886
798
|
byBinding.set(bindingKey, entry);
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import type { ObjectStorage } from "@opengeni/storage";
|
|
3
|
+
import type { GmailFileMaterializationRequest } from "@opengeni/runtime/gmail-rest-mcp";
|
|
4
|
+
import type {
|
|
5
|
+
ConnectorAttachmentMaterializer,
|
|
6
|
+
ConnectorFileMaterializationRequest,
|
|
7
|
+
} from "@opengeni/runtime";
|
|
8
|
+
import type { SandboxChannelAService } from "@opengeni/runtime/sandbox";
|
|
9
|
+
|
|
10
|
+
/** Use the selected filesystem namespace, retaining descriptor confinement and
|
|
11
|
+
* one extra byte to distinguish a complete exact-limit input from truncation. */
|
|
12
|
+
export async function readGmailFileFromChannel(
|
|
13
|
+
channel: Pick<SandboxChannelAService, "fsRead">,
|
|
14
|
+
request: { path: string; maxBytes: number },
|
|
15
|
+
): Promise<Uint8Array> {
|
|
16
|
+
const file = await channel.fsRead({
|
|
17
|
+
path: request.path,
|
|
18
|
+
maxBytes: request.maxBytes + 1,
|
|
19
|
+
encoding: "base64",
|
|
20
|
+
workspaceOnly: true,
|
|
21
|
+
});
|
|
22
|
+
const bytes = Buffer.from(file.content, "base64");
|
|
23
|
+
if (file.truncated || bytes.byteLength > request.maxBytes)
|
|
24
|
+
throw new Error("Gmail file input exceeds the maximum size");
|
|
25
|
+
return bytes;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type ConnectorFileMaterializationOptions = {
|
|
29
|
+
workspaceId: string;
|
|
30
|
+
storage: ObjectStorage;
|
|
31
|
+
downloadStorage: ObjectStorage;
|
|
32
|
+
materialize: ConnectorAttachmentMaterializer;
|
|
33
|
+
onCleanupFailure?: (key: string) => void;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/** Gmail returns base64url JSON, while the exact filesystem importer consumes
|
|
37
|
+
* byte streams. Stage only inside the worker; no URL or bytes reach a tool result. */
|
|
38
|
+
export async function materializeGmailFile(
|
|
39
|
+
request: GmailFileMaterializationRequest,
|
|
40
|
+
options: ConnectorFileMaterializationOptions,
|
|
41
|
+
) {
|
|
42
|
+
return await materializeConnectorFile(
|
|
43
|
+
{
|
|
44
|
+
...request,
|
|
45
|
+
toolName: request.providerAttachmentId.value.endsWith(":raw")
|
|
46
|
+
? "download_message"
|
|
47
|
+
: "download_attachment",
|
|
48
|
+
},
|
|
49
|
+
options,
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Connectors that buffer provider bytes stage them privately in object
|
|
54
|
+
* storage, then import them as exact connector attachments in the sandbox. */
|
|
55
|
+
export async function materializeConnectorFile(
|
|
56
|
+
request: ConnectorFileMaterializationRequest,
|
|
57
|
+
options: ConnectorFileMaterializationOptions,
|
|
58
|
+
) {
|
|
59
|
+
if (!(await request.authorizeProviderRequest()))
|
|
60
|
+
throw new Error("Connector file authority is unavailable");
|
|
61
|
+
const hash = createHash("sha256").update(request.bytes).digest("hex");
|
|
62
|
+
const key = `workspaces/${options.workspaceId}/private-connector-transfers/${crypto.randomUUID()}`;
|
|
63
|
+
try {
|
|
64
|
+
await options.storage.putObject({
|
|
65
|
+
key,
|
|
66
|
+
body: request.bytes,
|
|
67
|
+
contentType: request.mediaType,
|
|
68
|
+
sha256: hash,
|
|
69
|
+
});
|
|
70
|
+
const source = await options.downloadStorage.createGetUrl({ key, expiresInSeconds: 300 });
|
|
71
|
+
const envelope = await options.materialize({
|
|
72
|
+
serverId: request.serverId,
|
|
73
|
+
toolName: request.toolName,
|
|
74
|
+
operationId: request.operationId,
|
|
75
|
+
connectionId: request.connectionId,
|
|
76
|
+
authorizeProviderRequest: request.authorizeProviderRequest,
|
|
77
|
+
attachments: [
|
|
78
|
+
{
|
|
79
|
+
providerAttachmentId: request.providerAttachmentId,
|
|
80
|
+
fileName: request.fileName,
|
|
81
|
+
mediaType: request.mediaType,
|
|
82
|
+
byteSize: request.bytes.byteLength,
|
|
83
|
+
contentSha256: hash,
|
|
84
|
+
source: { url: source.url, expiresAt: source.expiresAt.toISOString() },
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
});
|
|
88
|
+
return { attachments: envelope.attachments };
|
|
89
|
+
} finally {
|
|
90
|
+
// The transfer object is never a retained workspace File or Knowledge entry.
|
|
91
|
+
let cleaned = false;
|
|
92
|
+
for (let attempt = 0; attempt < 3 && !cleaned; attempt++) {
|
|
93
|
+
try {
|
|
94
|
+
await options.storage.deleteObject(key);
|
|
95
|
+
cleaned = true;
|
|
96
|
+
} catch {
|
|
97
|
+
/* Idempotent storage cleanup must not erase delivery or uncertainty. */
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (!cleaned) {
|
|
101
|
+
try {
|
|
102
|
+
options.onCleanupFailure?.(key);
|
|
103
|
+
} catch {
|
|
104
|
+
/* Observability cannot replace a file result. */
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|