@opengeni/worker-bundle 2.0.1 → 2.0.2-canary.38789554071001
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/activities/agent-run-admission.d.ts +1 -12
- package/dist/activities/agent-turn/admission.d.ts +88 -10
- package/dist/activities/agent-turn/agent-build.d.ts +14 -3
- package/dist/activities/agent-turn/claim.d.ts +4 -1
- package/dist/activities/agent-turn/claude-core.d.ts +195 -0
- package/dist/activities/agent-turn/code-search.d.ts +60 -0
- package/dist/activities/agent-turn/codex-capacity.d.ts +3 -0
- package/dist/activities/agent-turn/codex-core-capacity.d.ts +37 -0
- package/dist/activities/agent-turn/codex-core-claim.d.ts +40 -0
- package/dist/activities/agent-turn/codex-core-errors.d.ts +102 -0
- package/dist/activities/agent-turn/codex-core-failover.d.ts +15 -0
- package/dist/activities/agent-turn/codex-core-requests.d.ts +28 -0
- package/dist/activities/agent-turn/codex-core-settlement.d.ts +77 -0
- package/dist/activities/agent-turn/codex-credit-policy.d.ts +30 -0
- package/dist/activities/agent-turn/codex-plan-entitlement.d.ts +105 -0
- package/dist/activities/agent-turn/codex-usage-policy.d.ts +2 -0
- package/dist/activities/agent-turn/codex.d.ts +2 -19
- package/dist/activities/agent-turn/compaction-interruption.d.ts +32 -0
- package/dist/activities/agent-turn/compaction-prep.d.ts +30 -1
- package/dist/activities/agent-turn/credential-leases.d.ts +64 -37
- package/dist/activities/agent-turn/credential-restriction.d.ts +3 -0
- package/dist/activities/agent-turn/errors.d.ts +185 -26
- package/dist/activities/agent-turn/failure-settlement.d.ts +10 -43
- package/dist/activities/agent-turn/final-reply.d.ts +18 -0
- package/dist/activities/agent-turn/finalization-monitor.d.ts +7 -2
- package/dist/activities/agent-turn/finalization.d.ts +2 -0
- package/dist/activities/agent-turn/github-repository-bindings.d.ts +2 -0
- package/dist/activities/agent-turn/governance-model.d.ts +13 -1
- package/dist/activities/agent-turn/history-sink.d.ts +4 -1
- package/dist/activities/agent-turn/history.d.ts +2 -0
- package/dist/activities/agent-turn/input-wait-reply.d.ts +76 -0
- package/dist/activities/agent-turn/meaningful-output.d.ts +9 -0
- package/dist/activities/agent-turn/media-artifacts.d.ts +5 -3
- package/dist/activities/agent-turn/model-call-admission.d.ts +15 -0
- package/dist/activities/agent-turn/model-usage.d.ts +56 -14
- package/dist/activities/agent-turn/model-wire-dispatch.d.ts +15 -0
- package/dist/activities/agent-turn/optional-repositories.d.ts +59 -0
- package/dist/activities/agent-turn/prompt-tool-availability.d.ts +17 -0
- package/dist/activities/agent-turn/provider-dispatch-barrier.d.ts +12 -1
- package/dist/activities/agent-turn/provider-recovery-copy.d.ts +24 -0
- package/dist/activities/agent-turn/provider-recovery-metrics.d.ts +18 -0
- package/dist/activities/agent-turn/provider-recovery-policy.d.ts +6 -0
- package/dist/activities/agent-turn/quiescence.d.ts +6 -7
- package/dist/activities/agent-turn/recovery-warning.d.ts +6 -5
- package/dist/activities/agent-turn/refresh-credentials.d.ts +6 -0
- package/dist/activities/agent-turn/run-credentials.d.ts +9 -5
- package/dist/activities/agent-turn/run.d.ts +27 -2
- package/dist/activities/agent-turn/sandbox-establish.d.ts +1 -0
- package/dist/activities/agent-turn/sandbox-provision.d.ts +25 -1
- package/dist/activities/agent-turn/sandbox-route.d.ts +3 -0
- package/dist/activities/agent-turn/sandbox-runtime.d.ts +1 -1
- package/dist/activities/agent-turn/secret-resolver.d.ts +64 -0
- package/dist/activities/agent-turn/session-title.d.ts +60 -3
- package/dist/activities/agent-turn/session-usage-custody.d.ts +66 -0
- package/dist/activities/agent-turn/skill-checkout.d.ts +25 -6
- package/dist/activities/agent-turn/skill-read.d.ts +70 -2
- package/dist/activities/agent-turn/skill-search.d.ts +2 -0
- package/dist/activities/agent-turn/skill-tools.d.ts +41 -4
- package/dist/activities/agent-turn/skill-transfer.d.ts +18 -6
- package/dist/activities/agent-turn/stream-attempt.d.ts +6 -3
- package/dist/activities/agent-turn/subscription-capacity-arming.d.ts +41 -0
- package/dist/activities/agent-turn/subscription-core-capacity.d.ts +86 -0
- package/dist/activities/agent-turn/subscription-core-failover.d.ts +69 -0
- package/dist/activities/agent-turn/subscription-core-placed.d.ts +14 -0
- package/dist/activities/agent-turn/subscription-core-requests.d.ts +109 -0
- package/dist/activities/agent-turn/subscription-core-settlement.d.ts +112 -0
- package/dist/activities/agent-turn/subscription-lease.d.ts +44 -0
- package/dist/activities/agent-turn/subscription-serving-capacity.d.ts +6 -0
- package/dist/activities/agent-turn/subscription-serving-catalog.d.ts +13 -0
- package/dist/activities/agent-turn/subscription-serving-claim.d.ts +30 -0
- package/dist/activities/agent-turn/subscription-serving-providers.d.ts +2 -0
- package/dist/activities/agent-turn/tool-environment.d.ts +31 -6
- package/dist/activities/agent-turn/tool-policy.d.ts +55 -3
- package/dist/activities/agent-turn/turn-context.d.ts +104 -5
- package/dist/activities/agent-turn/web-search.d.ts +57 -0
- package/dist/activities/agent-turn/xai-core.d.ts +96 -0
- package/dist/activities/automations.d.ts +3 -1
- package/dist/activities/browser-deadline-checkpoint.d.ts +34 -0
- package/dist/activities/capabilities.d.ts +8 -20
- package/dist/activities/codemode-dispatcher.d.ts +20 -3
- package/dist/activities/codex-capacity.d.ts +1 -56
- package/dist/activities/codex-image-generation.d.ts +49 -3
- package/dist/activities/common.d.ts +3 -1
- package/dist/activities/context-compaction.d.ts +41 -2
- package/dist/activities/environment.d.ts +1 -19
- package/dist/activities/gmail-files.d.ts +50 -0
- package/dist/activities/goals.d.ts +1 -9
- package/dist/activities/incident-telemetry-authority.d.ts +5 -2
- package/dist/activities/incident-telemetry-preflight.d.ts +10 -3
- package/dist/activities/knowledge-indexing.d.ts +19 -0
- package/dist/activities/mcp-account-routes.d.ts +2 -21
- package/dist/activities/model-call-fact-reconciler.d.ts +34 -0
- package/dist/activities/open-suffix-resume.d.ts +15 -0
- package/dist/activities/parent-wake.d.ts +17 -12
- package/dist/activities/programmatic-approvals.d.ts +10 -0
- package/dist/activities/requester-unavailable-receipt.d.ts +8 -0
- package/dist/activities/retained-screenshots.d.ts +7 -2
- package/dist/activities/run-credential-renewal.d.ts +1 -0
- package/dist/activities/run-credentials.d.ts +16 -4
- package/dist/activities/run-input.d.ts +17 -0
- package/dist/activities/sandbox-lease.d.ts +132 -12
- package/dist/activities/scheduled-tasks.d.ts +4 -35
- package/dist/activities/session-archive.d.ts +58 -0
- package/dist/activities/session-state.d.ts +15 -3
- package/dist/activities/session-storage.d.ts +44 -0
- package/dist/activities/subscription-core-claude-waits.d.ts +2 -0
- package/dist/activities/subscription-core-codex-quota.d.ts +25 -0
- package/dist/activities/subscription-core-codex-waits.d.ts +153 -0
- package/dist/activities/subscription-core-image-operation.d.ts +29 -0
- package/dist/activities/subscription-core-usage-recheck.d.ts +49 -0
- package/dist/activities/subscription-core-wait-bindings.d.ts +3 -0
- package/dist/activities/subscription-core-xai-quota.d.ts +30 -0
- package/dist/activities/subscription-core-xai-waits.d.ts +2 -0
- package/dist/activities/types.d.ts +68 -5
- package/dist/activities/video-generation-admission.d.ts +2 -8
- package/dist/activities/video-generation-credential.d.ts +15 -12
- package/dist/activities/video-generation-subscription-core.d.ts +70 -0
- package/dist/activities/workspace-capture.d.ts +2 -0
- package/dist/activities/workspace-credential-provider.d.ts +47 -0
- package/dist/activities/xai-auth.d.ts +6 -18
- package/dist/activities/xai-image-generation.d.ts +22 -6
- package/dist/{activities-control-QA6OLRQY.js → activities-control-5IIVRXLA.js} +1569 -2883
- package/dist/activities-control-5IIVRXLA.js.map +1 -0
- package/dist/activities-control.d.ts +64 -4
- package/dist/{activities-turn-YVVKCGAK.js → activities-turn-FLYJOM54.js} +9300 -4403
- package/dist/activities-turn-FLYJOM54.js.map +1 -0
- package/dist/activities.d.ts +64 -4
- package/dist/artifact-materializer-entry.js +107 -36
- package/dist/artifact-materializer-entry.js.map +1 -1
- package/dist/artifact-outbox-entry.js +132 -61
- package/dist/artifact-outbox-entry.js.map +1 -1
- package/dist/browser-deadline-checkpoint-contract.d.ts +2 -0
- package/dist/{chunk-GDCLDKSH.js → chunk-24GP3BX5.js} +79 -72
- package/dist/chunk-24GP3BX5.js.map +1 -0
- package/dist/{chunk-RAMNYSAW.js → chunk-4ER3YXOT.js} +22 -4
- package/dist/chunk-4ER3YXOT.js.map +1 -0
- package/dist/{chunk-I7HKKMUJ.js → chunk-5NNS4327.js} +734 -58
- package/dist/chunk-5NNS4327.js.map +1 -0
- package/dist/chunk-MVESOYFC.js +3746 -0
- package/dist/chunk-MVESOYFC.js.map +1 -0
- package/dist/{chunk-M3NVMF2V.js → chunk-N57B3PJ5.js} +2307 -3951
- package/dist/chunk-N57B3PJ5.js.map +1 -0
- package/dist/chunk-NQDVJ6RI.js +2823 -0
- package/dist/chunk-NQDVJ6RI.js.map +1 -0
- package/dist/chunk-O7UPBWXK.js +79 -0
- package/dist/chunk-O7UPBWXK.js.map +1 -0
- package/dist/chunk-W2QSM5HR.js +414 -0
- package/dist/chunk-W2QSM5HR.js.map +1 -0
- package/dist/chunk-ZN3XJR33.js +227 -0
- package/dist/chunk-ZN3XJR33.js.map +1 -0
- package/dist/editable-artifact-outbox-dispatcher.d.ts +12 -1
- package/dist/editable-artifact-outbox-service.d.ts +3 -1
- package/dist/host-export-pump.d.ts +3 -1
- package/dist/host-export.d.ts +2 -2
- package/dist/host-export.js +1 -1
- package/dist/http.d.ts +1 -1
- package/dist/index.d.ts +49 -48
- package/dist/index.js +835 -256
- package/dist/index.js.map +1 -1
- package/dist/internal-maintenance.d.ts +63 -0
- package/dist/maintenance-cadence.d.ts +43 -0
- package/dist/observability-metrics.d.ts +293 -24
- package/dist/onepassword-vault-provider.d.ts +7 -0
- package/dist/parent-wake-PCLH7A3Y.js +24 -0
- package/dist/parent-wake-PCLH7A3Y.js.map +1 -0
- package/dist/personal-github-git-credentials.d.ts +1 -1
- package/dist/readiness-checks.d.ts +39 -0
- package/dist/retained-process-retry.d.ts +7 -0
- package/dist/sandbox-lease-BJYU72N3.js +84 -0
- package/dist/sandbox-lease-BJYU72N3.js.map +1 -0
- package/dist/sandbox-reaper-contract.d.ts +25 -0
- package/dist/sandbox-resume.d.ts +72 -4
- package/dist/sandbox-routing.d.ts +4 -2
- package/dist/session-event-fanout.d.ts +6 -0
- package/dist/site-auth-maintenance-WK3MR2PV.js +12 -0
- package/dist/site-auth-maintenance-WK3MR2PV.js.map +1 -0
- package/dist/telemetry-scheduler.d.ts +14 -0
- package/dist/temporal-runtime-logger.d.ts +22 -0
- package/dist/turn-task-queue-reader.d.ts +18 -0
- package/dist/turn-worker-activity-telemetry.d.ts +47 -0
- package/dist/worker-service-lifecycle.d.ts +12 -0
- package/dist/workflow-bundle.js +468 -71
- package/dist/workflows/activities.d.ts +1 -1
- package/dist/workflows/browser-deadline-checkpoint.d.ts +10 -0
- package/dist/workflows/sandbox-reaper.d.ts +10 -1
- package/dist/workflows/scheduled-tasks.d.ts +4 -0
- package/dist/workflows/session-storage.d.ts +2 -0
- package/dist/workflows/session.d.ts +36 -0
- package/dist/workflows/site-auth-maintenance.d.ts +2 -1
- package/dist/workflows/workflow-wake.d.ts +14 -3
- package/dist/workflows.d.ts +3 -1
- package/package.json +26 -20
- package/src/activities/agent-run-admission.ts +1 -82
- package/src/activities/agent-turn/admission.ts +175 -24
- package/src/activities/agent-turn/agent-build.ts +226 -145
- package/src/activities/agent-turn/claim.ts +363 -64
- package/src/activities/agent-turn/claude-core.ts +587 -0
- package/src/activities/agent-turn/code-search.ts +275 -0
- package/src/activities/agent-turn/codex-capacity.ts +30 -757
- package/src/activities/agent-turn/codex-core-capacity.ts +190 -0
- package/src/activities/agent-turn/codex-core-claim.ts +83 -0
- package/src/activities/agent-turn/codex-core-errors.ts +308 -0
- package/src/activities/agent-turn/codex-core-failover.ts +73 -0
- package/src/activities/agent-turn/codex-core-requests.ts +86 -0
- package/src/activities/agent-turn/codex-core-settlement.ts +263 -0
- package/src/activities/agent-turn/codex-credit-policy.ts +247 -0
- package/src/activities/agent-turn/codex-plan-entitlement.ts +254 -0
- package/src/activities/agent-turn/codex-usage-policy.ts +2 -0
- package/src/activities/agent-turn/codex.ts +8 -76
- package/src/activities/agent-turn/compaction-interruption.ts +56 -0
- package/src/activities/agent-turn/compaction-prep.ts +249 -36
- package/src/activities/agent-turn/credential-leases.ts +269 -214
- package/src/activities/agent-turn/credential-restriction.ts +14 -0
- package/src/activities/agent-turn/errors.ts +1152 -82
- package/src/activities/agent-turn/failure-settlement.ts +879 -886
- package/src/activities/agent-turn/final-reply.ts +46 -0
- package/src/activities/agent-turn/finalization-monitor.ts +17 -5
- package/src/activities/agent-turn/finalization.ts +107 -88
- package/src/activities/agent-turn/github-repository-bindings.ts +3 -1
- package/src/activities/agent-turn/governance-model.ts +90 -22
- package/src/activities/agent-turn/history-sink.ts +42 -12
- package/src/activities/agent-turn/history.ts +25 -5
- package/src/activities/agent-turn/input-wait-reply.ts +139 -0
- package/src/activities/agent-turn/knowledge-source-tools.ts +2 -0
- package/src/activities/agent-turn/meaningful-output.ts +44 -0
- package/src/activities/agent-turn/media-artifacts.ts +3 -1
- package/src/activities/agent-turn/model-call-admission.ts +114 -0
- package/src/activities/agent-turn/model-usage.ts +299 -233
- package/src/activities/agent-turn/model-wire-dispatch.ts +27 -0
- package/src/activities/agent-turn/optional-repositories.ts +224 -0
- package/src/activities/agent-turn/prompt-tool-availability.ts +27 -0
- package/src/activities/agent-turn/provider-dispatch-barrier.ts +22 -0
- package/src/activities/agent-turn/provider-recovery-copy.ts +76 -0
- package/src/activities/agent-turn/provider-recovery-metrics.ts +64 -0
- package/src/activities/agent-turn/provider-recovery-policy.ts +25 -0
- package/src/activities/agent-turn/quiescence.ts +7 -7
- package/src/activities/agent-turn/recovery-warning.ts +6 -8
- package/src/activities/agent-turn/refresh-credentials.ts +44 -0
- package/src/activities/agent-turn/run-credentials.ts +124 -76
- package/src/activities/agent-turn/run.ts +501 -112
- package/src/activities/agent-turn/sandbox-establish.ts +152 -75
- package/src/activities/agent-turn/sandbox-provision.ts +54 -1
- package/src/activities/agent-turn/sandbox-route.ts +4 -1
- package/src/activities/agent-turn/sandbox-runtime.ts +319 -11
- package/src/activities/agent-turn/secret-resolver.ts +155 -0
- package/src/activities/agent-turn/session-title.ts +177 -12
- package/src/activities/agent-turn/session-usage-custody.ts +170 -0
- package/src/activities/agent-turn/skill-checkout.ts +111 -24
- package/src/activities/agent-turn/skill-install.ts +1 -1
- package/src/activities/agent-turn/skill-read.ts +374 -28
- package/src/activities/agent-turn/skill-save.ts +35 -7
- package/src/activities/agent-turn/skill-search.ts +9 -0
- package/src/activities/agent-turn/skill-selection.ts +4 -0
- package/src/activities/agent-turn/skill-tools.ts +208 -21
- package/src/activities/agent-turn/skill-transfer.ts +68 -23
- package/src/activities/agent-turn/stream-attempt.ts +634 -111
- package/src/activities/agent-turn/subscription-capacity-arming.ts +81 -0
- package/src/activities/agent-turn/subscription-core-capacity.ts +439 -0
- package/src/activities/agent-turn/subscription-core-failover.ts +229 -0
- package/src/activities/agent-turn/subscription-core-placed.ts +37 -0
- package/src/activities/agent-turn/subscription-core-requests.ts +271 -0
- package/src/activities/agent-turn/subscription-core-settlement.ts +234 -0
- package/src/activities/agent-turn/subscription-lease.ts +140 -0
- package/src/activities/agent-turn/subscription-serving-capacity.ts +195 -0
- package/src/activities/agent-turn/subscription-serving-catalog.ts +71 -0
- package/src/activities/agent-turn/subscription-serving-claim.ts +178 -0
- package/src/activities/agent-turn/subscription-serving-providers.ts +15 -0
- package/src/activities/agent-turn/tool-environment.ts +384 -292
- package/src/activities/agent-turn/tool-policy.ts +104 -4
- package/src/activities/agent-turn/tool-result-spill.ts +1 -0
- package/src/activities/agent-turn/turn-context.ts +124 -8
- package/src/activities/agent-turn/web-search.ts +431 -0
- package/src/activities/agent-turn/xai-core.ts +301 -0
- package/src/activities/automations.ts +81 -6
- package/src/activities/browser-deadline-checkpoint.ts +297 -0
- package/src/activities/capabilities.ts +53 -213
- package/src/activities/codemode-dispatcher.ts +236 -14
- package/src/activities/codex-capacity.ts +27 -380
- package/src/activities/codex-image-generation.ts +252 -42
- package/src/activities/common.ts +12 -0
- package/src/activities/connector-attachments.ts +3 -1
- package/src/activities/context-compaction.ts +182 -21
- package/src/activities/environment.ts +18 -106
- package/src/activities/gmail-files.ts +108 -0
- package/src/activities/goals.ts +120 -204
- package/src/activities/image-generation-operation.ts +1 -1
- package/src/activities/incident-telemetry-authority.ts +80 -50
- package/src/activities/incident-telemetry-preflight.ts +27 -15
- package/src/activities/knowledge-indexing.ts +287 -17
- package/src/activities/knowledge-source-sync.ts +10 -0
- package/src/activities/mcp-account-routes.ts +2 -124
- package/src/activities/model-call-fact-reconciler.ts +112 -0
- package/src/activities/open-suffix-resume.ts +122 -88
- package/src/activities/parent-wake.ts +89 -21
- package/src/activities/programmatic-approvals.ts +26 -0
- package/src/activities/requester-unavailable-receipt.ts +14 -0
- package/src/activities/retained-screenshots.ts +135 -24
- package/src/activities/run-credential-renewal.ts +13 -1
- package/src/activities/run-credentials.ts +61 -19
- package/src/activities/run-input.ts +124 -9
- package/src/activities/sandbox-lease.ts +1615 -73
- package/src/activities/scheduled-tasks.ts +780 -147
- package/src/activities/session-archive.ts +382 -0
- package/src/activities/session-state.ts +219 -10
- package/src/activities/session-storage.ts +124 -0
- package/src/activities/site-auth-maintenance.ts +5 -2
- package/src/activities/subscription-core-claude-waits.ts +49 -0
- package/src/activities/subscription-core-codex-quota.ts +46 -0
- package/src/activities/subscription-core-codex-waits.ts +488 -0
- package/src/activities/subscription-core-image-operation.ts +126 -0
- package/src/activities/subscription-core-usage-recheck.ts +146 -0
- package/src/activities/subscription-core-wait-bindings.ts +12 -0
- package/src/activities/subscription-core-xai-quota.ts +85 -0
- package/src/activities/subscription-core-xai-waits.ts +48 -0
- package/src/activities/types.ts +85 -9
- package/src/activities/video-generation-admission.ts +1 -36
- package/src/activities/video-generation-credential.ts +38 -56
- package/src/activities/video-generation-reconciliation.ts +150 -131
- package/src/activities/video-generation-subscription-core.ts +180 -0
- package/src/activities/workspace-capture.ts +13 -2
- package/src/activities/workspace-credential-provider.ts +302 -0
- package/src/activities/xai-auth.ts +34 -112
- package/src/activities/xai-image-generation.ts +84 -36
- package/src/activities-control.ts +8 -0
- package/src/activities-turn.ts +5 -0
- package/src/activities.ts +17 -0
- package/src/activity-services.ts +29 -4
- package/src/browser-deadline-checkpoint-contract.ts +5 -0
- package/src/editable-artifact-hint-broker.ts +3 -0
- package/src/editable-artifact-materializer-service.ts +85 -39
- package/src/editable-artifact-materializer-subprocess.ts +47 -2
- package/src/editable-artifact-outbox-dispatcher.ts +107 -46
- package/src/editable-artifact-outbox-service.ts +55 -25
- package/src/github-rest-mcp.ts +1 -1
- package/src/host-export-pump.ts +26 -4
- package/src/host-export.ts +4 -1
- package/src/http.ts +4 -2
- package/src/index.ts +222 -282
- package/src/internal-maintenance.ts +347 -0
- package/src/maintenance-cadence.ts +156 -0
- package/src/observability-metrics.ts +1173 -73
- package/src/onepassword-vault-provider.ts +11 -0
- package/src/personal-github-git-credentials.ts +3 -1
- package/src/pr-review-credentials.ts +1 -1
- package/src/readiness-checks.ts +113 -0
- package/src/retained-process-retry.ts +36 -0
- package/src/sandbox-reaper-contract.ts +33 -0
- package/src/sandbox-resume.ts +444 -73
- package/src/sandbox-routing.ts +230 -75
- package/src/session-event-fanout.ts +23 -0
- package/src/telemetry-scheduler.ts +53 -0
- package/src/temporal-runtime-logger.ts +44 -0
- package/src/turn-task-queue-reader.ts +110 -0
- package/src/turn-worker-activity-telemetry.ts +209 -0
- package/src/worker-service-lifecycle.ts +54 -1
- package/src/workflows/activities.ts +16 -1
- package/src/workflows/browser-deadline-checkpoint.ts +55 -0
- package/src/workflows/file-upload-reaper.ts +2 -0
- package/src/workflows/sandbox-reaper.ts +88 -0
- package/src/workflows/scheduled-tasks.ts +26 -13
- package/src/workflows/session-storage.ts +19 -0
- package/src/workflows/session.ts +238 -33
- package/src/workflows/site-auth-maintenance.ts +2 -1
- package/src/workflows/workflow-wake.ts +26 -4
- package/src/workflows.ts +7 -0
- package/dist/activities/agent-turn/xai-capacity.d.ts +0 -2
- package/dist/activities/codex-fleet-shadow.d.ts +0 -74
- package/dist/activities/codex-rotation.d.ts +0 -200
- package/dist/activities/xai-quota.d.ts +0 -3
- package/dist/activities-control-QA6OLRQY.js.map +0 -1
- package/dist/activities-turn-YVVKCGAK.js.map +0 -1
- package/dist/chunk-GDCLDKSH.js.map +0 -1
- package/dist/chunk-I7HKKMUJ.js.map +0 -1
- package/dist/chunk-M3NVMF2V.js.map +0 -1
- package/dist/chunk-RAMNYSAW.js.map +0 -1
- package/src/activities/agent-turn/xai-capacity.ts +0 -257
- package/src/activities/codex-fleet-shadow.ts +0 -306
- package/src/activities/codex-rotation.ts +0 -685
- package/src/activities/xai-quota.ts +0 -35
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
import { hasPermission } from "@opengeni/core";
|
|
2
2
|
import type { AttemptToolDefinition } from "@opengeni/codemode";
|
|
3
|
-
import
|
|
3
|
+
import {
|
|
4
|
+
claudeNativeModelProfile,
|
|
5
|
+
isManagedOpenRouterFreeRoute,
|
|
6
|
+
type ModelCapabilitiesV1,
|
|
7
|
+
} from "@opengeni/config";
|
|
8
|
+
import type {
|
|
9
|
+
GeneratedSessionTitle,
|
|
10
|
+
GenerateSessionTitleOptions,
|
|
11
|
+
OpenGeniRuntime,
|
|
12
|
+
} from "@opengeni/runtime";
|
|
4
13
|
import {
|
|
5
14
|
AUTOMATIC_SESSION_TITLE_FALLBACK,
|
|
6
15
|
DEFAULT_FIRST_PARTY_MCP_PERMISSIONS,
|
|
16
|
+
ReasoningEffort,
|
|
7
17
|
type FirstPartyMcpToolName,
|
|
8
18
|
type Permission,
|
|
19
|
+
type ResolvedAgentConfig,
|
|
9
20
|
type ToolRef,
|
|
10
21
|
} from "@opengeni/contracts";
|
|
11
22
|
|
|
@@ -17,6 +28,7 @@ const SESSION_TITLE_DESCRIPTION =
|
|
|
17
28
|
export function shouldRequestMissingSessionTitle(input: {
|
|
18
29
|
title: string | null;
|
|
19
30
|
titleSource: "user" | "agent" | null;
|
|
31
|
+
agentConfig?: ResolvedAgentConfig | null;
|
|
20
32
|
firstPartyMcpTools: readonly FirstPartyMcpToolName[];
|
|
21
33
|
firstPartyMcpPermissions: readonly Permission[] | null;
|
|
22
34
|
}): boolean {
|
|
@@ -24,16 +36,34 @@ export function shouldRequestMissingSessionTitle(input: {
|
|
|
24
36
|
const needsSemanticTitle =
|
|
25
37
|
input.titleSource !== "user" && (!title || title === AUTOMATIC_SESSION_TITLE_FALLBACK);
|
|
26
38
|
if (!needsSemanticTitle) return false;
|
|
27
|
-
|
|
39
|
+
// Configured sessions title through the runtime, not an opted-in capability.
|
|
40
|
+
// Legacy sessions keep their exact selected-tool and permission admission.
|
|
41
|
+
if (!input.agentConfig && !input.firstPartyMcpTools.includes("set_session_title")) return false;
|
|
28
42
|
const permissions = input.firstPartyMcpPermissions ?? DEFAULT_FIRST_PARTY_MCP_PERMISSIONS;
|
|
29
43
|
return hasPermission([...permissions], "sessions:control");
|
|
30
44
|
}
|
|
31
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Whether the turn's route can afford a model request spent only on a title.
|
|
48
|
+
* The managed OpenRouter free route draws on one deployment-wide per-minute
|
|
49
|
+
* and per-day request quota that users' turns need, so an untitled session on
|
|
50
|
+
* it gets no title sidecar and no title tool (whose call would cost a
|
|
51
|
+
* follow-up request). Clients keep showing the prompt preview, and a later
|
|
52
|
+
* turn on another route titles the session.
|
|
53
|
+
*/
|
|
54
|
+
export function routeAllowsSessionTitleRequests(
|
|
55
|
+
resolvedModel: ReturnType<OpenGeniRuntime["resolveTurnModel"]>,
|
|
56
|
+
): boolean {
|
|
57
|
+
return !resolvedModel || !isManagedOpenRouterFreeRoute(resolvedModel);
|
|
58
|
+
}
|
|
59
|
+
|
|
32
60
|
export function sessionTitleToolPlan(input: {
|
|
33
61
|
tools: readonly ToolRef[];
|
|
62
|
+
agentConfig?: ResolvedAgentConfig | null;
|
|
34
63
|
selectedFirstPartyMcpTools: readonly FirstPartyMcpToolName[];
|
|
35
64
|
shouldRequestTitle: boolean;
|
|
36
65
|
parallelGenerationAvailable: boolean;
|
|
66
|
+
routeAllowsTitleRequests: boolean;
|
|
37
67
|
}): {
|
|
38
68
|
promoteTitleTool: boolean;
|
|
39
69
|
generateTitleInParallel: boolean;
|
|
@@ -42,9 +72,11 @@ export function sessionTitleToolPlan(input: {
|
|
|
42
72
|
} {
|
|
43
73
|
const titleToolAvailable =
|
|
44
74
|
input.shouldRequestTitle &&
|
|
45
|
-
input.
|
|
46
|
-
|
|
47
|
-
const
|
|
75
|
+
(input.agentConfig != null ||
|
|
76
|
+
input.tools.some((tool) => tool.kind === "mcp" && tool.id === "opengeni"));
|
|
77
|
+
const titleRequestAllowed = titleToolAvailable && input.routeAllowsTitleRequests;
|
|
78
|
+
const generateTitleInParallel = titleRequestAllowed && input.parallelGenerationAvailable;
|
|
79
|
+
const promoteTitleTool = titleRequestAllowed && !generateTitleInParallel;
|
|
48
80
|
return {
|
|
49
81
|
promoteTitleTool,
|
|
50
82
|
generateTitleInParallel,
|
|
@@ -57,6 +89,130 @@ export function sessionTitleToolPlan(input: {
|
|
|
57
89
|
|
|
58
90
|
export const PARALLEL_SESSION_TITLE_TIMEOUT_MS = 15_000;
|
|
59
91
|
|
|
92
|
+
/** Codex subscription turns title on this fast model of the same account. */
|
|
93
|
+
export const CODEX_SESSION_TITLE_MODEL_ID = "codex/gpt-6-luna";
|
|
94
|
+
/** Claude subscription turns title on this fast model of the same account. */
|
|
95
|
+
export const CLAUDE_SESSION_TITLE_UPSTREAM_MODEL_ID = "claude-haiku-5-5";
|
|
96
|
+
|
|
97
|
+
type ResolvedTitleModel = NonNullable<ReturnType<OpenGeniRuntime["resolveTurnModel"]>>;
|
|
98
|
+
|
|
99
|
+
export type SessionTitleRoute = {
|
|
100
|
+
resolvedModel: ReturnType<OpenGeniRuntime["resolveTurnModel"]>;
|
|
101
|
+
/** Upstream model name sent to the provider. */
|
|
102
|
+
modelName: string;
|
|
103
|
+
/** Product model id the title usage is recorded under, when it differs from the turn's. */
|
|
104
|
+
usageModelId: string | null;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The model for the auxiliary title request. A subscription turn titles on a
|
|
109
|
+
* fast model of the same subscription account and request context, so the
|
|
110
|
+
* title costs the subscription little and never another rail: Codex turns use
|
|
111
|
+
* Luna and Claude subscription turns use Haiku. Other turns, and a
|
|
112
|
+
* subscription whose catalog lacks the title model, title on the turn's model.
|
|
113
|
+
*/
|
|
114
|
+
export function sessionTitleRoute(input: {
|
|
115
|
+
resolvedModel: ReturnType<OpenGeniRuntime["resolveTurnModel"]>;
|
|
116
|
+
modelName: string;
|
|
117
|
+
resolveTurnModel: (modelId: string) => ReturnType<OpenGeniRuntime["resolveTurnModel"]>;
|
|
118
|
+
}): SessionTitleRoute {
|
|
119
|
+
const turnRoute = {
|
|
120
|
+
resolvedModel: input.resolvedModel,
|
|
121
|
+
modelName: input.modelName,
|
|
122
|
+
usageModelId: null,
|
|
123
|
+
};
|
|
124
|
+
const turn = input.resolvedModel;
|
|
125
|
+
if (!turn) return turnRoute;
|
|
126
|
+
const sameAccount = (title: ResolvedTitleModel): SessionTitleRoute => ({
|
|
127
|
+
// The turn's client and provider carry its account and credential binding.
|
|
128
|
+
resolvedModel: { ...title, client: turn.client, provider: turn.provider },
|
|
129
|
+
modelName: title.configured.upstreamModelId,
|
|
130
|
+
usageModelId: title.configured.id,
|
|
131
|
+
});
|
|
132
|
+
if (turn.provider.kind === "codex-subscription") {
|
|
133
|
+
if (turn.configured.id === CODEX_SESSION_TITLE_MODEL_ID) return turnRoute;
|
|
134
|
+
const title = input.resolveTurnModel(CODEX_SESSION_TITLE_MODEL_ID);
|
|
135
|
+
return title && title.provider.id === turn.provider.id ? sameAccount(title) : turnRoute;
|
|
136
|
+
}
|
|
137
|
+
if (turn.provider.kind?.startsWith("claude-subscription-")) {
|
|
138
|
+
if (turn.configured.upstreamModelId === CLAUDE_SESSION_TITLE_UPSTREAM_MODEL_ID)
|
|
139
|
+
return turnRoute;
|
|
140
|
+
const titleModelId = `${turn.provider.id}/${CLAUDE_SESSION_TITLE_UPSTREAM_MODEL_ID}`;
|
|
141
|
+
const listed = input.resolveTurnModel(titleModelId);
|
|
142
|
+
if (listed && listed.provider.id === turn.provider.id) return sameAccount(listed);
|
|
143
|
+
// Every Claude subscription can serve Haiku even when the connection's
|
|
144
|
+
// picker list omits it; the native profile supplies its reasoning range.
|
|
145
|
+
const profile = claudeNativeModelProfile(CLAUDE_SESSION_TITLE_UPSTREAM_MODEL_ID);
|
|
146
|
+
if (!profile) return turnRoute;
|
|
147
|
+
return sameAccount({
|
|
148
|
+
...turn,
|
|
149
|
+
configured: {
|
|
150
|
+
...turn.configured,
|
|
151
|
+
id: titleModelId,
|
|
152
|
+
upstreamModelId: CLAUDE_SESSION_TITLE_UPSTREAM_MODEL_ID,
|
|
153
|
+
capabilities: {
|
|
154
|
+
...turn.configured.capabilities,
|
|
155
|
+
reasoning: {
|
|
156
|
+
...turn.configured.capabilities.reasoning,
|
|
157
|
+
runnable: profile.efforts.length > 0,
|
|
158
|
+
efforts: [...profile.efforts],
|
|
159
|
+
defaultEffort: profile.defaultEffort,
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
return turnRoute;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* The lowest reasoning effort the resolved model can run, for the auxiliary
|
|
170
|
+
* title request only. A title needs no deliberation, and a provider default
|
|
171
|
+
* effort can use most of the output budget before any visible text. Returns
|
|
172
|
+
* undefined when the model declares no runnable reasoning control, so the
|
|
173
|
+
* request carries no reasoning parameter.
|
|
174
|
+
*/
|
|
175
|
+
export function sessionTitleReasoningEffort(
|
|
176
|
+
capabilities: Pick<ModelCapabilitiesV1, "reasoning"> | undefined,
|
|
177
|
+
): ReasoningEffort | undefined {
|
|
178
|
+
const reasoning = capabilities?.reasoning;
|
|
179
|
+
if (!reasoning?.runnable) return undefined;
|
|
180
|
+
const order = ReasoningEffort.options;
|
|
181
|
+
let lowest: ReasoningEffort | undefined;
|
|
182
|
+
for (const effort of reasoning.efforts) {
|
|
183
|
+
if (!lowest || order.indexOf(effort) < order.indexOf(lowest)) lowest = effort;
|
|
184
|
+
}
|
|
185
|
+
return lowest;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Options for the parallel title request. It uses the turn's resolved
|
|
190
|
+
* provider and credential authority, but its own lowest runnable reasoning
|
|
191
|
+
* effort rather than the turn's effort.
|
|
192
|
+
*/
|
|
193
|
+
export function sessionTitleGenerationOptions(input: {
|
|
194
|
+
resolvedModel: ReturnType<OpenGeniRuntime["resolveTurnModel"]>;
|
|
195
|
+
modelName: string;
|
|
196
|
+
serviceTier: GenerateSessionTitleOptions["serviceTier"] | null | undefined;
|
|
197
|
+
signal: AbortSignal;
|
|
198
|
+
}): GenerateSessionTitleOptions {
|
|
199
|
+
const { resolvedModel, serviceTier } = input;
|
|
200
|
+
const reasoningEffort = sessionTitleReasoningEffort(resolvedModel?.configured.capabilities);
|
|
201
|
+
return {
|
|
202
|
+
...(resolvedModel
|
|
203
|
+
? {
|
|
204
|
+
client: resolvedModel.client,
|
|
205
|
+
provider: resolvedModel.provider,
|
|
206
|
+
model: resolvedModel.model,
|
|
207
|
+
}
|
|
208
|
+
: {}),
|
|
209
|
+
modelName: input.modelName,
|
|
210
|
+
...(serviceTier ? { serviceTier } : {}),
|
|
211
|
+
...(reasoningEffort ? { reasoningEffort } : {}),
|
|
212
|
+
signal: input.signal,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
60
216
|
export type ParallelSessionTitleGeneration = {
|
|
61
217
|
finish: () => Promise<GeneratedSessionTitle | null>;
|
|
62
218
|
cancel: () => Promise<void>;
|
|
@@ -67,13 +223,15 @@ export type ParallelSessionTitleGeneration = {
|
|
|
67
223
|
* stream. finish() waits for the already-running bounded request, so a quick
|
|
68
224
|
* main response does not discard a valid title merely because it completed
|
|
69
225
|
* first. cancel() aborts and joins exceptional/cancelled exits so no provider
|
|
70
|
-
* work escapes the owning runAgentTurn activity.
|
|
226
|
+
* work escapes the owning runAgentTurn activity. Both exits settle an already
|
|
227
|
+
* completed result before returning, including its separate request custody.
|
|
71
228
|
*/
|
|
72
229
|
export function startParallelSessionTitleGeneration(input: {
|
|
73
230
|
generate: (signal: AbortSignal) => Promise<GeneratedSessionTitle>;
|
|
74
231
|
signal?: AbortSignal;
|
|
75
232
|
timeoutMs?: number;
|
|
76
233
|
onError?: (error: unknown) => void;
|
|
234
|
+
onFinish?: (result: GeneratedSessionTitle | null) => Promise<void>;
|
|
77
235
|
}): ParallelSessionTitleGeneration {
|
|
78
236
|
const cancellationController = new AbortController();
|
|
79
237
|
const timeoutSignal = AbortSignal.timeout(input.timeoutMs ?? PARALLEL_SESSION_TITLE_TIMEOUT_MS);
|
|
@@ -89,15 +247,22 @@ export function startParallelSessionTitleGeneration(input: {
|
|
|
89
247
|
});
|
|
90
248
|
let finished: Promise<GeneratedSessionTitle | null> | null = null;
|
|
91
249
|
|
|
250
|
+
const finish = (): Promise<GeneratedSessionTitle | null> => {
|
|
251
|
+
finished ??= generation.then(async (result) => {
|
|
252
|
+
await input.onFinish?.(result);
|
|
253
|
+
return result;
|
|
254
|
+
});
|
|
255
|
+
return finished;
|
|
256
|
+
};
|
|
257
|
+
|
|
92
258
|
return {
|
|
93
|
-
finish
|
|
94
|
-
if (finished) return finished;
|
|
95
|
-
finished = generation;
|
|
96
|
-
return finished;
|
|
97
|
-
},
|
|
259
|
+
finish,
|
|
98
260
|
cancel: async () => {
|
|
261
|
+
// Let an already-resolved generation deliver its queued result before
|
|
262
|
+
// aborting. A request still pending at this boundary remains cancelled.
|
|
263
|
+
await Promise.resolve();
|
|
99
264
|
cancellationController.abort();
|
|
100
|
-
await
|
|
265
|
+
await finish();
|
|
101
266
|
},
|
|
102
267
|
};
|
|
103
268
|
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import type { HeldSessionUsageReceipt } from "@opengeni/core";
|
|
2
|
+
import { settleSessionUsageReceipt, SessionUsageLimitUnavailableError } from "@opengeni/db";
|
|
3
|
+
import type { TurnActivityServices as ActivityServices } from "../types";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Attempt-scoped custody for per-task usage receipts whose write failed after
|
|
7
|
+
* the provider response was received.
|
|
8
|
+
*
|
|
9
|
+
* The response is never lost or re-requested because of an accounting
|
|
10
|
+
* failure: settlement hands the content-free receipt here (original source
|
|
11
|
+
* identity, amount, pricing source) and the turn keeps the response. Before
|
|
12
|
+
* the next model request (every admission check) and before the turn
|
|
13
|
+
* completes, held receipts are written; if that still fails, the attempt
|
|
14
|
+
* stops for the workflow's DB-only recovery lane and carries the held
|
|
15
|
+
* receipts in its typed failure detail (durable in workflow history), which
|
|
16
|
+
* the lane writes before any replacement attempt. Writes are idempotent per
|
|
17
|
+
* source identity, so overlapping writers (the `agent.model.usage` event
|
|
18
|
+
* meter, a later flush and the recovery lane) record the call once.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
type Scope = { accountId: string; workspaceId: string };
|
|
22
|
+
type Entry = Scope & { receipts: Map<string, HeldSessionUsageReceipt> };
|
|
23
|
+
|
|
24
|
+
/** Bound on receipts carried through one recovery failure detail. */
|
|
25
|
+
export const MAX_RECOVERY_SESSION_USAGE_RECEIPTS = 64;
|
|
26
|
+
const MAX_HELD_SESSIONS = 4096;
|
|
27
|
+
const FLUSH_DELAYS_MS = [0, 250, 1_000];
|
|
28
|
+
|
|
29
|
+
const held = new Map<string, Entry>();
|
|
30
|
+
|
|
31
|
+
/** Recovery reason and detail code for a task whose earlier single-call receipt is still owed. */
|
|
32
|
+
export const SESSION_USAGE_CUSTODY_PENDING = "session_usage_custody_pending";
|
|
33
|
+
/**
|
|
34
|
+
* How long a parked turn waits before its replacement attempt re-checks
|
|
35
|
+
* admission (database reads only). An owner fills its receipt within
|
|
36
|
+
* seconds; a dead owner's marker is disclosed by maintenance after 30
|
|
37
|
+
* minutes, so a task waits at most about 60 rechecks.
|
|
38
|
+
*/
|
|
39
|
+
export const SESSION_USAGE_CUSTODY_RECHECK_MS = 30_000;
|
|
40
|
+
|
|
41
|
+
/** A fenced or overdue custody marker (not a database outage) refused the next model request. */
|
|
42
|
+
export function sessionUsageCustodyPending(error: unknown): boolean {
|
|
43
|
+
let current = error;
|
|
44
|
+
for (let depth = 0; depth < 6 && current && typeof current === "object"; depth += 1) {
|
|
45
|
+
if (current instanceof SessionUsageLimitUnavailableError) {
|
|
46
|
+
return current.reason === "custody_pending";
|
|
47
|
+
}
|
|
48
|
+
current = (current as { cause?: unknown }).cause;
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function holdSessionUsageReceipt(scope: Scope, receipt: HeldSessionUsageReceipt): void {
|
|
54
|
+
let entry = held.get(receipt.sessionId);
|
|
55
|
+
if (!entry) {
|
|
56
|
+
if (held.size >= MAX_HELD_SESSIONS) {
|
|
57
|
+
// Oldest sessions only: their receipts already travelled with a
|
|
58
|
+
// recovery failure or will be re-imported from durable usage events.
|
|
59
|
+
const oldest = held.keys().next().value;
|
|
60
|
+
if (oldest !== undefined) held.delete(oldest);
|
|
61
|
+
}
|
|
62
|
+
entry = { accountId: scope.accountId, workspaceId: scope.workspaceId, receipts: new Map() };
|
|
63
|
+
held.set(receipt.sessionId, entry);
|
|
64
|
+
}
|
|
65
|
+
entry.receipts.set(receipt.sourceId, receipt);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Held receipts for one turn, bounded, for a post-claim recovery failure detail. */
|
|
69
|
+
export function heldSessionUsageReceiptsForTurn(turnId: string): HeldSessionUsageReceipt[] {
|
|
70
|
+
const receipts: HeldSessionUsageReceipt[] = [];
|
|
71
|
+
for (const entry of held.values()) {
|
|
72
|
+
for (const receipt of entry.receipts.values()) {
|
|
73
|
+
if (receipt.turnId === turnId) receipts.push(receipt);
|
|
74
|
+
if (receipts.length >= MAX_RECOVERY_SESSION_USAGE_RECEIPTS) return receipts;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return receipts;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function heldSessionUsageReceiptCount(sessionId?: string): number {
|
|
81
|
+
if (sessionId !== undefined) return held.get(sessionId)?.receipts.size ?? 0;
|
|
82
|
+
let count = 0;
|
|
83
|
+
for (const entry of held.values()) count += entry.receipts.size;
|
|
84
|
+
return count;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The `agent.model.usage` event for a held receipt committed. Its appending
|
|
89
|
+
* transaction meters the same source identity through the database trigger
|
|
90
|
+
* (or, for a root still preparing, leaves the event for the bounded import),
|
|
91
|
+
* and a trigger failure would have rolled the event back. When the event
|
|
92
|
+
* carries exactly the held amount, the receipt is therefore durable and the
|
|
93
|
+
* hold is dropped, so completion does not stop for a write that is already
|
|
94
|
+
* done. A different or unknown event amount keeps the hold: only the direct
|
|
95
|
+
* write can record (or fill) that value.
|
|
96
|
+
*/
|
|
97
|
+
export function releaseHeldSessionUsageReceiptMeteredByEvent(input: {
|
|
98
|
+
sessionId: string;
|
|
99
|
+
sourceId: string;
|
|
100
|
+
amountMicros: number | null;
|
|
101
|
+
pricingSource: string | null;
|
|
102
|
+
}): boolean {
|
|
103
|
+
const entry = held.get(input.sessionId);
|
|
104
|
+
const receipt = entry?.receipts.get(input.sourceId);
|
|
105
|
+
if (!entry || !receipt) return false;
|
|
106
|
+
if (receipt.amountMicros !== input.amountMicros) return false;
|
|
107
|
+
if (receipt.amountMicros !== null && receipt.pricingSource !== input.pricingSource) return false;
|
|
108
|
+
entry.receipts.delete(input.sourceId);
|
|
109
|
+
if (entry.receipts.size === 0 && held.get(input.sessionId) === entry) {
|
|
110
|
+
held.delete(input.sessionId);
|
|
111
|
+
}
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Write receipts with their original identities; throws the last database error. */
|
|
116
|
+
export async function writeSessionUsageReceipts(
|
|
117
|
+
db: ActivityServices["db"],
|
|
118
|
+
scope: Scope,
|
|
119
|
+
receipts: readonly HeldSessionUsageReceipt[],
|
|
120
|
+
): Promise<void> {
|
|
121
|
+
for (const receipt of receipts) {
|
|
122
|
+
await settleSessionUsageReceipt(db, {
|
|
123
|
+
accountId: scope.accountId,
|
|
124
|
+
workspaceId: scope.workspaceId,
|
|
125
|
+
sessionId: receipt.sessionId,
|
|
126
|
+
sourceId: receipt.sourceId,
|
|
127
|
+
turnId: receipt.turnId,
|
|
128
|
+
amountMicros: receipt.amountMicros,
|
|
129
|
+
pricingSource: receipt.amountMicros === null ? null : receipt.pricingSource,
|
|
130
|
+
model: receipt.model,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Write every receipt held for this session before another model request or
|
|
137
|
+
* turn completion. Retries briefly; a persistent failure rethrows the
|
|
138
|
+
* database error so the attempt enters post-claim DB recovery with the
|
|
139
|
+
* receipts still held for its failure detail.
|
|
140
|
+
*/
|
|
141
|
+
export async function flushHeldSessionUsageReceipts(
|
|
142
|
+
db: ActivityServices["db"],
|
|
143
|
+
sessionId: string,
|
|
144
|
+
): Promise<void> {
|
|
145
|
+
const entry = held.get(sessionId);
|
|
146
|
+
if (!entry || entry.receipts.size === 0) return;
|
|
147
|
+
let lastError: unknown;
|
|
148
|
+
for (const delay of FLUSH_DELAYS_MS) {
|
|
149
|
+
if (delay > 0) await new Promise((resolve) => setTimeout(resolve, delay));
|
|
150
|
+
try {
|
|
151
|
+
// A parallel call (session title) may hold another receipt meanwhile.
|
|
152
|
+
while (entry.receipts.size > 0) {
|
|
153
|
+
for (const [sourceId, receipt] of [...entry.receipts]) {
|
|
154
|
+
await writeSessionUsageReceipts(db, entry, [receipt]);
|
|
155
|
+
entry.receipts.delete(sourceId);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (entry.receipts.size === 0 && held.get(sessionId) === entry) held.delete(sessionId);
|
|
159
|
+
return;
|
|
160
|
+
} catch (error) {
|
|
161
|
+
lastError = error;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
throw lastError;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Test-only reset of process custody. */
|
|
168
|
+
export function resetSessionUsageReceiptCustodyForTests(): void {
|
|
169
|
+
held.clear();
|
|
170
|
+
}
|
|
@@ -1,10 +1,28 @@
|
|
|
1
1
|
import type { AttemptToolDefinition } from "@opengeni/codemode";
|
|
2
|
-
import type
|
|
3
|
-
import type
|
|
4
|
-
import { checkoutSkillDirectory, readSkillDirectory } from "./skill-transfer";
|
|
2
|
+
import { SKILL_READ_MAX_PATHS, type SkillTextFile } from "@opengeni/runtime/skill-library";
|
|
3
|
+
import { checkoutSkillDirectory, readSkillDirectory, type SkillFileSystem } from "./skill-transfer";
|
|
5
4
|
import type { SkillSaveReceipt, SkillSaveRequest } from "./skill-save";
|
|
6
5
|
|
|
7
|
-
type
|
|
6
|
+
export type SkillCheckoutOutcome = "written" | "unchanged" | "refused" | "failed";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Content-free timing of one skill_checkout call. `resolve` covers authority
|
|
10
|
+
* and the Skill read, `sandbox` acquiring the turn's filesystem handle, and
|
|
11
|
+
* `write` the batched filesystem write. On a lazily provisioned turn whose
|
|
12
|
+
* first sandbox use is this checkout, acquiring the handle starts the box, so
|
|
13
|
+
* box start is inside `sandbox`. A phase that did not run is null.
|
|
14
|
+
*/
|
|
15
|
+
export type SkillCheckoutObservation = Readonly<{
|
|
16
|
+
outcome: SkillCheckoutOutcome;
|
|
17
|
+
selection: "all" | "paths";
|
|
18
|
+
files: number;
|
|
19
|
+
written: number;
|
|
20
|
+
unchanged: number;
|
|
21
|
+
resolveSeconds: number | null;
|
|
22
|
+
sandboxSeconds: number | null;
|
|
23
|
+
writeSeconds: number | null;
|
|
24
|
+
totalSeconds: number;
|
|
25
|
+
}>;
|
|
8
26
|
|
|
9
27
|
export function createSkillCheckoutAttemptToolDefinition(input: {
|
|
10
28
|
authorize: () => Promise<void>;
|
|
@@ -14,7 +32,9 @@ export function createSkillCheckoutAttemptToolDefinition(input: {
|
|
|
14
32
|
scopeVersion: number | null;
|
|
15
33
|
files: readonly SkillTextFile[];
|
|
16
34
|
}>;
|
|
17
|
-
filesystem: () => Promise<SkillFileSystem
|
|
35
|
+
filesystem: () => Promise<Pick<SkillFileSystem, "fsWriteFiles">>;
|
|
36
|
+
/** Telemetry only; a failure here never changes the result. */
|
|
37
|
+
observe?: (observation: SkillCheckoutObservation) => void;
|
|
18
38
|
}): AttemptToolDefinition {
|
|
19
39
|
return {
|
|
20
40
|
identity: { serverId: "opengeni", toolName: "skill_checkout" },
|
|
@@ -22,12 +42,19 @@ export function createSkillCheckoutAttemptToolDefinition(input: {
|
|
|
22
42
|
codemodePath: ["opengeni", "skill_checkout"],
|
|
23
43
|
title: "Check out Skill files",
|
|
24
44
|
description:
|
|
25
|
-
"Copy
|
|
45
|
+
"Copy Skill files into a sandbox-relative directory to run scripts or make larger edits. Starts the sandbox if needed. Writes all missing files in one step and never overwrites: files that already hold the same content are kept, and a different existing file fails the call, so repeating a checkout into the same directory is fast. Pass paths to copy only those files, for example one script to run. Only a complete copy that creates a new directory returns revisionId and scopeVersion for skill_publish. Does not publish changes. Use skill_read for reading without a sandbox.",
|
|
26
46
|
inputSchema: {
|
|
27
47
|
type: "object",
|
|
28
48
|
properties: {
|
|
29
49
|
skill: { type: "string", minLength: 1, maxLength: 512 },
|
|
30
50
|
directory: { type: "string", minLength: 1, maxLength: 1024 },
|
|
51
|
+
paths: {
|
|
52
|
+
type: "array",
|
|
53
|
+
minItems: 1,
|
|
54
|
+
maxItems: SKILL_READ_MAX_PATHS,
|
|
55
|
+
uniqueItems: true,
|
|
56
|
+
items: { type: "string", minLength: 1, maxLength: 1024 },
|
|
57
|
+
},
|
|
31
58
|
},
|
|
32
59
|
required: ["skill", "directory"],
|
|
33
60
|
additionalProperties: false,
|
|
@@ -35,37 +62,97 @@ export function createSkillCheckoutAttemptToolDefinition(input: {
|
|
|
35
62
|
annotations: {
|
|
36
63
|
readOnlyHint: false,
|
|
37
64
|
destructiveHint: false,
|
|
38
|
-
idempotentHint:
|
|
65
|
+
idempotentHint: true,
|
|
39
66
|
openWorldHint: false,
|
|
40
67
|
},
|
|
41
68
|
source: "opengeni",
|
|
42
69
|
approval: "none",
|
|
43
70
|
execute: async (args) => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
71
|
+
if (
|
|
72
|
+
typeof args.skill !== "string" ||
|
|
73
|
+
typeof args.directory !== "string" ||
|
|
74
|
+
(args.paths !== undefined &&
|
|
75
|
+
(!Array.isArray(args.paths) || args.paths.some((path) => typeof path !== "string")))
|
|
76
|
+
) {
|
|
77
|
+
throw new Error(
|
|
78
|
+
"skill_checkout requires a Skill, a directory, and optional relative paths.",
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
const paths = args.paths as string[] | undefined;
|
|
82
|
+
const started = performance.now();
|
|
83
|
+
const phases: { resolve: number | null; sandbox: number | null; write: number | null } = {
|
|
84
|
+
resolve: null,
|
|
85
|
+
sandbox: null,
|
|
86
|
+
write: null,
|
|
56
87
|
};
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
88
|
+
const timed = async <T>(phase: keyof typeof phases, run: () => Promise<T>): Promise<T> => {
|
|
89
|
+
const phaseStarted = performance.now();
|
|
90
|
+
try {
|
|
91
|
+
return await run();
|
|
92
|
+
} finally {
|
|
93
|
+
phases[phase] = (performance.now() - phaseStarted) / 1_000;
|
|
94
|
+
}
|
|
61
95
|
};
|
|
96
|
+
let copied: Awaited<ReturnType<typeof checkoutSkillDirectory>> | undefined;
|
|
97
|
+
let outcome: SkillCheckoutOutcome = "refused";
|
|
98
|
+
try {
|
|
99
|
+
const skill = await timed("resolve", async () => {
|
|
100
|
+
await input.authorize();
|
|
101
|
+
return input.load(args.skill as string);
|
|
102
|
+
});
|
|
103
|
+
outcome = "failed";
|
|
104
|
+
const filesystem = await timed("sandbox", input.filesystem);
|
|
105
|
+
copied = await timed("write", () =>
|
|
106
|
+
checkoutSkillDirectory(
|
|
107
|
+
filesystem,
|
|
108
|
+
args.directory as string,
|
|
109
|
+
skill.files,
|
|
110
|
+
paths ? { paths } : {},
|
|
111
|
+
),
|
|
112
|
+
);
|
|
113
|
+
outcome = copied.written > 0 ? "written" : "unchanged";
|
|
114
|
+
// Only a complete copy into a directory this call created mirrors the
|
|
115
|
+
// revision exactly, so only it may serve as a skill_publish base.
|
|
116
|
+
const publishable = !paths && copied.createdDirectory;
|
|
117
|
+
const output = {
|
|
118
|
+
directory: copied.directory,
|
|
119
|
+
fileCount: copied.fileCount,
|
|
120
|
+
written: copied.written,
|
|
121
|
+
unchanged: copied.unchanged,
|
|
122
|
+
skillId: skill.skillId,
|
|
123
|
+
...(publishable
|
|
124
|
+
? { revisionId: skill.revisionId, scopeVersion: skill.scopeVersion }
|
|
125
|
+
: { publishable: false }),
|
|
126
|
+
};
|
|
127
|
+
return {
|
|
128
|
+
isError: false,
|
|
129
|
+
content: [{ type: "text", text: JSON.stringify(output) }],
|
|
130
|
+
structuredContent: output,
|
|
131
|
+
};
|
|
132
|
+
} finally {
|
|
133
|
+
try {
|
|
134
|
+
input.observe?.({
|
|
135
|
+
outcome,
|
|
136
|
+
selection: paths ? "paths" : "all",
|
|
137
|
+
files: copied?.fileCount ?? 0,
|
|
138
|
+
written: copied?.written ?? 0,
|
|
139
|
+
unchanged: copied?.unchanged ?? 0,
|
|
140
|
+
resolveSeconds: phases.resolve,
|
|
141
|
+
sandboxSeconds: phases.sandbox,
|
|
142
|
+
writeSeconds: phases.write,
|
|
143
|
+
totalSeconds: (performance.now() - started) / 1_000,
|
|
144
|
+
});
|
|
145
|
+
} catch {
|
|
146
|
+
// Telemetry is best effort.
|
|
147
|
+
}
|
|
148
|
+
}
|
|
62
149
|
},
|
|
63
150
|
};
|
|
64
151
|
}
|
|
65
152
|
|
|
66
153
|
export function createSkillPublishAttemptToolDefinition(input: {
|
|
67
154
|
authorize: () => Promise<void>;
|
|
68
|
-
filesystem: () => Promise<SkillFileSystem
|
|
155
|
+
filesystem: () => Promise<Pick<SkillFileSystem, "fsList" | "fsRead">>;
|
|
69
156
|
save: (request: SkillSaveRequest) => Promise<SkillSaveReceipt>;
|
|
70
157
|
}): AttemptToolDefinition {
|
|
71
158
|
return {
|
|
@@ -17,7 +17,7 @@ export function createSkillInstallAttemptToolDefinition(input: {
|
|
|
17
17
|
codemodePath: ["opengeni", "skill_install"],
|
|
18
18
|
title: "Install a Skill",
|
|
19
19
|
description:
|
|
20
|
-
"Install a Skill from a public skills.sh or GitHub URL, or library
|
|
20
|
+
"Install a Skill from a public skills.sh or GitHub URL, such as a public skill_search result, or a curated Opengeni library entry as library:<id>. The server resolves and pins the source; no prior preview or invented hash is required. The effective Skills setting governs agent installation: Automatic publishes, Review first leaves a pending change in Knowledge > Needs review while the task continues, and Off prevents agent installation. Human installation from the UI remains available. Do not ask an approval question for a pending receipt. Replacing an existing installation requires its current installation version, and preserves workspace customizations.",
|
|
21
21
|
inputSchema: {
|
|
22
22
|
type: "object",
|
|
23
23
|
properties: {
|