open-multi-agent-kit 0.98.4 → 0.99.0
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/CHANGELOG.md +36 -0
- package/README.md +4 -2
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +1 -0
- package/dist/cli/help.js.map +1 -1
- package/dist/commands/run-command.d.ts +2 -1
- package/dist/commands/run-command.d.ts.map +1 -1
- package/dist/commands/run-command.js +9 -1
- package/dist/commands/run-command.js.map +1 -1
- package/dist/commands/verified-run-cli.d.ts +6 -0
- package/dist/commands/verified-run-cli.d.ts.map +1 -0
- package/dist/commands/verified-run-cli.js +190 -0
- package/dist/commands/verified-run-cli.js.map +1 -0
- package/dist/core/agent-session-services.d.ts +8 -1
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +41 -0
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +7 -8
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +80 -43
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/devin-harness-dispatch.d.ts +12 -0
- package/dist/core/devin-harness-dispatch.d.ts.map +1 -0
- package/dist/core/devin-harness-dispatch.js +12 -0
- package/dist/core/devin-harness-dispatch.js.map +1 -0
- package/dist/core/devin-harness.d.ts +53 -0
- package/dist/core/devin-harness.d.ts.map +1 -0
- package/dist/core/devin-harness.js +112 -0
- package/dist/core/devin-harness.js.map +1 -0
- package/dist/core/domain-dispatch.d.ts +4 -1
- package/dist/core/domain-dispatch.d.ts.map +1 -1
- package/dist/core/domain-dispatch.js +5 -0
- package/dist/core/domain-dispatch.js.map +1 -1
- package/dist/core/domain-loadouts-provider-harness.d.ts +12 -0
- package/dist/core/domain-loadouts-provider-harness.d.ts.map +1 -0
- package/dist/core/domain-loadouts-provider-harness.js +122 -0
- package/dist/core/domain-loadouts-provider-harness.js.map +1 -0
- package/dist/core/domain-loadouts.d.ts +2 -33
- package/dist/core/domain-loadouts.d.ts.map +1 -1
- package/dist/core/domain-loadouts.js +3 -56
- package/dist/core/domain-loadouts.js.map +1 -1
- package/dist/core/domain-profile.d.ts +40 -0
- package/dist/core/domain-profile.d.ts.map +1 -0
- package/dist/core/domain-profile.js +7 -0
- package/dist/core/domain-profile.js.map +1 -0
- package/dist/core/grok-harness-dispatch.d.ts +6 -20
- package/dist/core/grok-harness-dispatch.d.ts.map +1 -1
- package/dist/core/grok-harness-dispatch.js +6 -55
- package/dist/core/grok-harness-dispatch.js.map +1 -1
- package/dist/core/grok-harness.d.ts +7 -9
- package/dist/core/grok-harness.d.ts.map +1 -1
- package/dist/core/grok-harness.js +9 -23
- package/dist/core/grok-harness.js.map +1 -1
- package/dist/core/harness-skills.d.ts +20 -0
- package/dist/core/harness-skills.d.ts.map +1 -0
- package/dist/core/harness-skills.js +36 -0
- package/dist/core/harness-skills.js.map +1 -0
- package/dist/core/loadout-runtime-state.d.ts +25 -0
- package/dist/core/loadout-runtime-state.d.ts.map +1 -0
- package/dist/core/loadout-runtime-state.js +39 -0
- package/dist/core/loadout-runtime-state.js.map +1 -0
- package/dist/core/loadout-runtime.d.ts +2 -12
- package/dist/core/loadout-runtime.d.ts.map +1 -1
- package/dist/core/loadout-runtime.js +6 -13
- package/dist/core/loadout-runtime.js.map +1 -1
- package/dist/core/model-resolver.d.ts +1 -41
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +2 -49
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/prompt-settlement.d.ts +4 -3
- package/dist/core/prompt-settlement.d.ts.map +1 -1
- package/dist/core/prompt-settlement.js.map +1 -1
- package/dist/core/provider-default-models.d.ts +42 -0
- package/dist/core/provider-default-models.d.ts.map +1 -0
- package/dist/core/provider-default-models.js +50 -0
- package/dist/core/provider-default-models.js.map +1 -0
- package/dist/core/provider-display-names.d.ts.map +1 -1
- package/dist/core/provider-display-names.js +1 -0
- package/dist/core/provider-display-names.js.map +1 -1
- package/dist/core/provider-harness-dispatch.d.ts +63 -0
- package/dist/core/provider-harness-dispatch.d.ts.map +1 -0
- package/dist/core/provider-harness-dispatch.js +60 -0
- package/dist/core/provider-harness-dispatch.js.map +1 -0
- package/dist/core/provider-usage-devin.d.ts +16 -0
- package/dist/core/provider-usage-devin.d.ts.map +1 -0
- package/dist/core/provider-usage-devin.js +61 -0
- package/dist/core/provider-usage-devin.js.map +1 -0
- package/dist/core/provider-usage-text.d.ts +5 -0
- package/dist/core/provider-usage-text.d.ts.map +1 -0
- package/dist/core/provider-usage-text.js +15 -0
- package/dist/core/provider-usage-text.js.map +1 -0
- package/dist/core/provider-usage-types.d.ts +2 -1
- package/dist/core/provider-usage-types.d.ts.map +1 -1
- package/dist/core/provider-usage-types.js.map +1 -1
- package/dist/core/provider-usage.d.ts +1 -2
- package/dist/core/provider-usage.d.ts.map +1 -1
- package/dist/core/provider-usage.js +12 -7
- package/dist/core/provider-usage.js.map +1 -1
- package/dist/core/run-budget-policy.d.ts +18 -0
- package/dist/core/run-budget-policy.d.ts.map +1 -0
- package/dist/core/run-budget-policy.js +52 -0
- package/dist/core/run-budget-policy.js.map +1 -0
- package/dist/core/run-budget.d.ts +33 -0
- package/dist/core/run-budget.d.ts.map +1 -0
- package/dist/core/run-budget.js +89 -0
- package/dist/core/run-budget.js.map +1 -0
- package/dist/core/run-execution-api.d.ts +15 -0
- package/dist/core/run-execution-api.d.ts.map +1 -0
- package/dist/core/run-execution-api.js +7 -0
- package/dist/core/run-execution-api.js.map +1 -0
- package/dist/core/run-journal.d.ts.map +1 -1
- package/dist/core/run-journal.js +30 -208
- package/dist/core/run-journal.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +23 -18
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-bash-service.d.ts +2 -2
- package/dist/core/session-bash-service.d.ts.map +1 -1
- package/dist/core/session-bash-service.js +21 -9
- package/dist/core/session-bash-service.js.map +1 -1
- package/dist/core/session-failure-cause.d.ts.map +1 -1
- package/dist/core/session-failure-cause.js +5 -0
- package/dist/core/session-failure-cause.js.map +1 -1
- package/dist/core/session-prompt-lifecycle.d.ts +25 -0
- package/dist/core/session-prompt-lifecycle.d.ts.map +1 -0
- package/dist/core/session-prompt-lifecycle.js +87 -0
- package/dist/core/session-prompt-lifecycle.js.map +1 -0
- package/dist/core/session-run-budget.d.ts +28 -0
- package/dist/core/session-run-budget.d.ts.map +1 -0
- package/dist/core/session-run-budget.js +127 -0
- package/dist/core/session-run-budget.js.map +1 -0
- package/dist/core/session-run-termination.d.ts.map +1 -1
- package/dist/core/session-run-termination.js +14 -3
- package/dist/core/session-run-termination.js.map +1 -1
- package/dist/core/session-termination-types.d.ts +97 -0
- package/dist/core/session-termination-types.d.ts.map +1 -0
- package/dist/core/session-termination-types.js +26 -0
- package/dist/core/session-termination-types.js.map +1 -0
- package/dist/core/session-termination.d.ts +3 -97
- package/dist/core/session-termination.d.ts.map +1 -1
- package/dist/core/session-termination.js +24 -28
- package/dist/core/session-termination.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +1 -0
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/subagent-lane-launcher.d.ts +3 -2
- package/dist/core/subagent-lane-launcher.d.ts.map +1 -1
- package/dist/core/subagent-lane-launcher.js +24 -13
- package/dist/core/subagent-lane-launcher.js.map +1 -1
- package/dist/core/verified-run/broker.d.ts +26 -0
- package/dist/core/verified-run/broker.d.ts.map +1 -0
- package/dist/core/verified-run/broker.js +210 -0
- package/dist/core/verified-run/broker.js.map +1 -0
- package/dist/core/verified-run/candidate.d.ts +24 -0
- package/dist/core/verified-run/candidate.d.ts.map +1 -0
- package/dist/core/verified-run/candidate.js +167 -0
- package/dist/core/verified-run/candidate.js.map +1 -0
- package/dist/core/verified-run/check-receipt.d.ts +18 -0
- package/dist/core/verified-run/check-receipt.d.ts.map +1 -0
- package/dist/core/verified-run/check-receipt.js +92 -0
- package/dist/core/verified-run/check-receipt.js.map +1 -0
- package/dist/core/verified-run/coordinator.d.ts +39 -0
- package/dist/core/verified-run/coordinator.d.ts.map +1 -0
- package/dist/core/verified-run/coordinator.js +190 -0
- package/dist/core/verified-run/coordinator.js.map +1 -0
- package/dist/core/verified-run/dag-candidates.d.ts +8 -0
- package/dist/core/verified-run/dag-candidates.d.ts.map +1 -0
- package/dist/core/verified-run/dag-candidates.js +65 -0
- package/dist/core/verified-run/dag-candidates.js.map +1 -0
- package/dist/core/verified-run/dag-phase.d.ts +7 -0
- package/dist/core/verified-run/dag-phase.d.ts.map +1 -0
- package/dist/core/verified-run/dag-phase.js +130 -0
- package/dist/core/verified-run/dag-phase.js.map +1 -0
- package/dist/core/verified-run/dag-projection.d.ts +7 -0
- package/dist/core/verified-run/dag-projection.d.ts.map +1 -0
- package/dist/core/verified-run/dag-projection.js +103 -0
- package/dist/core/verified-run/dag-projection.js.map +1 -0
- package/dist/core/verified-run/dag-recovery.d.ts +13 -0
- package/dist/core/verified-run/dag-recovery.d.ts.map +1 -0
- package/dist/core/verified-run/dag-recovery.js +98 -0
- package/dist/core/verified-run/dag-recovery.js.map +1 -0
- package/dist/core/verified-run/dag-retry-projection.d.ts +9 -0
- package/dist/core/verified-run/dag-retry-projection.d.ts.map +1 -0
- package/dist/core/verified-run/dag-retry-projection.js +43 -0
- package/dist/core/verified-run/dag-retry-projection.js.map +1 -0
- package/dist/core/verified-run/dag-types.d.ts +58 -0
- package/dist/core/verified-run/dag-types.d.ts.map +1 -0
- package/dist/core/verified-run/dag-types.js +2 -0
- package/dist/core/verified-run/dag-types.js.map +1 -0
- package/dist/core/verified-run/event-parser.d.ts +3 -0
- package/dist/core/verified-run/event-parser.d.ts.map +1 -0
- package/dist/core/verified-run/event-parser.js +154 -0
- package/dist/core/verified-run/event-parser.js.map +1 -0
- package/dist/core/verified-run/events.d.ts +4 -0
- package/dist/core/verified-run/events.d.ts.map +1 -0
- package/dist/core/verified-run/events.js +3 -0
- package/dist/core/verified-run/events.js.map +1 -0
- package/dist/core/verified-run/evidence-binding.d.ts +18 -0
- package/dist/core/verified-run/evidence-binding.d.ts.map +1 -0
- package/dist/core/verified-run/evidence-binding.js +81 -0
- package/dist/core/verified-run/evidence-binding.js.map +1 -0
- package/dist/core/verified-run/evidence.d.ts +27 -0
- package/dist/core/verified-run/evidence.d.ts.map +1 -0
- package/dist/core/verified-run/evidence.js +100 -0
- package/dist/core/verified-run/evidence.js.map +1 -0
- package/dist/core/verified-run/journal.d.ts +32 -0
- package/dist/core/verified-run/journal.d.ts.map +1 -0
- package/dist/core/verified-run/journal.js +103 -0
- package/dist/core/verified-run/journal.js.map +1 -0
- package/dist/core/verified-run/namespace-identity.d.ts +11 -0
- package/dist/core/verified-run/namespace-identity.d.ts.map +1 -0
- package/dist/core/verified-run/namespace-identity.js +77 -0
- package/dist/core/verified-run/namespace-identity.js.map +1 -0
- package/dist/core/verified-run/owned-execution.d.ts +22 -0
- package/dist/core/verified-run/owned-execution.d.ts.map +1 -0
- package/dist/core/verified-run/owned-execution.js +49 -0
- package/dist/core/verified-run/owned-execution.js.map +1 -0
- package/dist/core/verified-run/phase-context.d.ts +9 -0
- package/dist/core/verified-run/phase-context.d.ts.map +1 -0
- package/dist/core/verified-run/phase-context.js +2 -0
- package/dist/core/verified-run/phase-context.js.map +1 -0
- package/dist/core/verified-run/process-gate.d.ts +5 -0
- package/dist/core/verified-run/process-gate.d.ts.map +1 -0
- package/dist/core/verified-run/process-gate.js +31 -0
- package/dist/core/verified-run/process-gate.js.map +1 -0
- package/dist/core/verified-run/process-projection.d.ts +13 -0
- package/dist/core/verified-run/process-projection.d.ts.map +1 -0
- package/dist/core/verified-run/process-projection.js +82 -0
- package/dist/core/verified-run/process-projection.js.map +1 -0
- package/dist/core/verified-run/projection.d.ts +4 -0
- package/dist/core/verified-run/projection.d.ts.map +1 -0
- package/dist/core/verified-run/projection.js +175 -0
- package/dist/core/verified-run/projection.js.map +1 -0
- package/dist/core/verified-run/recovery-clock.d.ts +19 -0
- package/dist/core/verified-run/recovery-clock.d.ts.map +1 -0
- package/dist/core/verified-run/recovery-clock.js +69 -0
- package/dist/core/verified-run/recovery-clock.js.map +1 -0
- package/dist/core/verified-run/recovery-command.d.ts +11 -0
- package/dist/core/verified-run/recovery-command.d.ts.map +1 -0
- package/dist/core/verified-run/recovery-command.js +73 -0
- package/dist/core/verified-run/recovery-command.js.map +1 -0
- package/dist/core/verified-run/recovery-projection.d.ts +12 -0
- package/dist/core/verified-run/recovery-projection.d.ts.map +1 -0
- package/dist/core/verified-run/recovery-projection.js +88 -0
- package/dist/core/verified-run/recovery-projection.js.map +1 -0
- package/dist/core/verified-run/recovery.d.ts +12 -0
- package/dist/core/verified-run/recovery.d.ts.map +1 -0
- package/dist/core/verified-run/recovery.js +115 -0
- package/dist/core/verified-run/recovery.js.map +1 -0
- package/dist/core/verified-run/run-types.d.ts +104 -0
- package/dist/core/verified-run/run-types.d.ts.map +1 -0
- package/dist/core/verified-run/run-types.js +2 -0
- package/dist/core/verified-run/run-types.js.map +1 -0
- package/dist/core/verified-run/scripted-writer.d.ts +15 -0
- package/dist/core/verified-run/scripted-writer.d.ts.map +1 -0
- package/dist/core/verified-run/scripted-writer.js +94 -0
- package/dist/core/verified-run/scripted-writer.js.map +1 -0
- package/dist/core/verified-run/session-port.d.ts +27 -0
- package/dist/core/verified-run/session-port.d.ts.map +1 -0
- package/dist/core/verified-run/session-port.js +2 -0
- package/dist/core/verified-run/session-port.js.map +1 -0
- package/dist/core/verified-run/storage.d.ts +15 -0
- package/dist/core/verified-run/storage.d.ts.map +1 -0
- package/dist/core/verified-run/storage.js +96 -0
- package/dist/core/verified-run/storage.js.map +1 -0
- package/dist/core/verified-run/task-execution.d.ts +9 -0
- package/dist/core/verified-run/task-execution.d.ts.map +1 -0
- package/dist/core/verified-run/task-execution.js +29 -0
- package/dist/core/verified-run/task-execution.js.map +1 -0
- package/dist/core/verified-run/verification-phase.d.ts +5 -0
- package/dist/core/verified-run/verification-phase.d.ts.map +1 -0
- package/dist/core/verified-run/verification-phase.js +56 -0
- package/dist/core/verified-run/verification-phase.js.map +1 -0
- package/dist/core/verified-run/work-recovery.d.ts +8 -0
- package/dist/core/verified-run/work-recovery.d.ts.map +1 -0
- package/dist/core/verified-run/work-recovery.js +44 -0
- package/dist/core/verified-run/work-recovery.js.map +1 -0
- package/dist/core/verified-run/writer-completion.d.ts +4 -0
- package/dist/core/verified-run/writer-completion.d.ts.map +1 -0
- package/dist/core/verified-run/writer-completion.js +27 -0
- package/dist/core/verified-run/writer-completion.js.map +1 -0
- package/dist/core/verified-run/writer-phase.d.ts +8 -0
- package/dist/core/verified-run/writer-phase.d.ts.map +1 -0
- package/dist/core/verified-run/writer-phase.js +76 -0
- package/dist/core/verified-run/writer-phase.js.map +1 -0
- package/dist/core/verified-run/writer-projection.d.ts +11 -0
- package/dist/core/verified-run/writer-projection.d.ts.map +1 -0
- package/dist/core/verified-run/writer-projection.js +71 -0
- package/dist/core/verified-run/writer-projection.js.map +1 -0
- package/dist/core/verified-run/writer-recovery.d.ts +16 -0
- package/dist/core/verified-run/writer-recovery.d.ts.map +1 -0
- package/dist/core/verified-run/writer-recovery.js +107 -0
- package/dist/core/verified-run/writer-recovery.js.map +1 -0
- package/dist/core/workload-permit-pool.d.ts +1 -3
- package/dist/core/workload-permit-pool.d.ts.map +1 -1
- package/dist/core/workload-permit-pool.js +11 -11
- package/dist/core/workload-permit-pool.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +2 -8
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/session-failure.d.ts +13 -0
- package/dist/modes/interactive/components/session-failure.d.ts.map +1 -0
- package/dist/modes/interactive/components/session-failure.js +81 -0
- package/dist/modes/interactive/components/session-failure.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +47 -36
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/resource-description.d.ts +3 -0
- package/dist/modes/interactive/resource-description.d.ts.map +1 -0
- package/dist/modes/interactive/resource-description.js +15 -0
- package/dist/modes/interactive/resource-description.js.map +1 -0
- package/dist/modes/interactive/tui-diagnostics.d.ts +36 -0
- package/dist/modes/interactive/tui-diagnostics.d.ts.map +1 -0
- package/dist/modes/interactive/tui-diagnostics.js +105 -0
- package/dist/modes/interactive/tui-diagnostics.js.map +1 -0
- package/dist/modes/interactive/tui-runtime-info.d.ts +20 -0
- package/dist/modes/interactive/tui-runtime-info.d.ts.map +1 -0
- package/dist/modes/interactive/tui-runtime-info.js +76 -0
- package/dist/modes/interactive/tui-runtime-info.js.map +1 -0
- package/docs/development.md +10 -0
- package/docs/devin-harness.md +121 -0
- package/docs/docs.json +4 -0
- package/docs/environment-variables.md +2 -1
- package/docs/index.md +1 -0
- package/docs/keybindings.md +1 -1
- package/docs/loadout-domains/README.md +2 -1
- package/docs/loadout-domains/devin-harness.md +72 -0
- package/docs/metrics.md +57 -16
- package/docs/providers.md +76 -0
- package/docs/release-audit-0.98.5.md +101 -0
- package/docs/release-audit-0.99.0.md +68 -0
- package/docs/run-protocol.md +34 -1
- package/docs/runtime-algorithms.md +30 -1
- package/docs/sdk.md +198 -1
- package/docs/settings.md +1 -1
- package/docs/startup-resource-labels-testing.md +47 -0
- package/docs/tb21-audit.md +18 -4
- package/docs/usage.md +59 -0
- package/docs/verified-run-remaining-design.md +881 -0
- package/docs/verified-run-testing.md +508 -0
- package/docs/verified-run.md +409 -0
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +18 -18
- package/package.json +6 -6
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { createPromptSettlementState, reducePromptSettlement, settlePromptIfReady, } from "./prompt-settlement.js";
|
|
2
|
+
export class PromptExecutionBusyError extends Error {
|
|
3
|
+
constructor() {
|
|
4
|
+
super("Agent is already processing or has unsettled tool execution. Wait for actual termination.");
|
|
5
|
+
this.name = "PromptExecutionBusyError";
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
/** Session-local ownership, not a durable journal or a detached-process sandbox. */
|
|
9
|
+
export class SessionPromptLifecycle {
|
|
10
|
+
owner;
|
|
11
|
+
disposed = false;
|
|
12
|
+
canSettle;
|
|
13
|
+
auditsLateSettlement;
|
|
14
|
+
constructor(options = {}) {
|
|
15
|
+
this.canSettle = options.canSettle ?? (() => true);
|
|
16
|
+
this.auditsLateSettlement = options.auditsLateSettlement ?? (() => true);
|
|
17
|
+
}
|
|
18
|
+
assertIdle() {
|
|
19
|
+
if (this.owner !== undefined || this.disposed)
|
|
20
|
+
throw new PromptExecutionBusyError();
|
|
21
|
+
}
|
|
22
|
+
begin(promptRunId) {
|
|
23
|
+
this.assertIdle();
|
|
24
|
+
const owner = { promptRunId, startedAt: performance.now(), executions: new Set() };
|
|
25
|
+
this.owner = owner;
|
|
26
|
+
return {
|
|
27
|
+
finish: (outcome, notify) => {
|
|
28
|
+
if (owner.terminal !== undefined)
|
|
29
|
+
return;
|
|
30
|
+
owner.terminal = { outcome, notify };
|
|
31
|
+
this.flush();
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
wrapTool(tool) {
|
|
36
|
+
return {
|
|
37
|
+
name: tool.name,
|
|
38
|
+
label: tool.label,
|
|
39
|
+
description: tool.description,
|
|
40
|
+
parameters: tool.parameters,
|
|
41
|
+
prepareArguments: tool.prepareArguments,
|
|
42
|
+
executionMode: tool.executionMode,
|
|
43
|
+
resourceClaims: tool.resourceClaims,
|
|
44
|
+
// A spread would evaluate and freeze the context-sensitive timeout too early.
|
|
45
|
+
get timeoutMs() {
|
|
46
|
+
return tool.timeoutMs;
|
|
47
|
+
},
|
|
48
|
+
execute: async (...args) => {
|
|
49
|
+
const owner = this.owner;
|
|
50
|
+
if (this.disposed || owner?.terminal !== undefined)
|
|
51
|
+
throw new PromptExecutionBusyError();
|
|
52
|
+
// Runtime-owned identities cannot collide with reused model toolCallIds.
|
|
53
|
+
const execution = Symbol();
|
|
54
|
+
const requiresAudit = this.auditsLateSettlement();
|
|
55
|
+
owner?.executions.add(execution);
|
|
56
|
+
try {
|
|
57
|
+
return await tool.execute(...args);
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
owner?.executions.delete(execution);
|
|
61
|
+
// Audit mode flushes only after the late event has been delivered.
|
|
62
|
+
if (!requiresAudit)
|
|
63
|
+
this.flush();
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/** Called after the root producer drains, or after late-settlement event delivery. */
|
|
69
|
+
flush() {
|
|
70
|
+
const owner = this.owner;
|
|
71
|
+
if (!owner?.terminal || owner.executions.size > 0 || this.disposed || !this.canSettle())
|
|
72
|
+
return;
|
|
73
|
+
const state = reducePromptSettlement(createPromptSettlementState(owner.promptRunId, owner.startedAt), {
|
|
74
|
+
kind: "terminal",
|
|
75
|
+
outcome: owner.terminal.outcome,
|
|
76
|
+
});
|
|
77
|
+
const { event } = settlePromptIfReady(state, performance.now());
|
|
78
|
+
this.owner = undefined;
|
|
79
|
+
if (event !== null)
|
|
80
|
+
owner.terminal.notify(event);
|
|
81
|
+
}
|
|
82
|
+
dispose() {
|
|
83
|
+
this.disposed = true;
|
|
84
|
+
this.owner = undefined;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=session-prompt-lifecycle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-prompt-lifecycle.js","sourceRoot":"","sources":["../../src/core/session-prompt-lifecycle.ts"],"names":[],"mappings":"AACA,OAAO,EACN,2BAA2B,EAG3B,sBAAsB,EACtB,mBAAmB,GACnB,MAAM,wBAAwB,CAAC;AAShC,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IAClD,cAAc;QACb,KAAK,CAAC,2FAA2F,CAAC,CAAC;QACnG,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IAAA,CACvC;CACD;AAED,oFAAoF;AACpF,MAAM,OAAO,sBAAsB;IAC1B,KAAK,CAA0B;IAC/B,QAAQ,GAAG,KAAK,CAAC;IACR,SAAS,CAAgB;IACzB,oBAAoB,CAAgB;IAErD,YAAY,OAAO,GAAwE,EAAE,EAAE;QAC9F,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;QACnD,IAAI,CAAC,oBAAoB,GAAG,OAAO,CAAC,oBAAoB,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;IAAA,CACzE;IAED,UAAU,GAAS;QAClB,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,IAAI,IAAI,CAAC,QAAQ;YAAE,MAAM,IAAI,wBAAwB,EAAE,CAAC;IAAA,CACpF;IAED,KAAK,CAAC,WAAmB,EAEvB;QACD,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,MAAM,KAAK,GAAgB,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,CAAC,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,GAAG,EAAE,EAAE,CAAC;QAChG,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,OAAO;YACN,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC;gBA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BAClC,CAAC;YAAA,CACD;SACD,CAAC;IAAA,CACF;IAED,sFAAsF;IACtF,KAAK,GAAS;QACb,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACzB,IAAI,CAAC,KAAK,EAAE,QAAQ,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YAAE,OAAO;QAChG,MAAM,KAAK,GAAG,sBAAsB,CAAC,2BAA2B,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,SAAS,CAAC,EAAE;YACrG,IAAI,EAAE,UAAU;YAChB,OAAO,EAAE,KAAK,CAAC,QAAQ,CAAC,OAAO;SAC/B,CAAC,CAAC;QACH,MAAM,EAAE,KAAK,EAAE,GAAG,mBAAmB,CAAC,KAAK,EAAE,WAAW,CAAC,GAAG,EAAE,CAAC,CAAC;QAChE,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;QACvB,IAAI,KAAK,KAAK,IAAI;YAAE,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAAA,CACjD;IAED,OAAO,GAAS;QACf,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;IAAA,CACvB;CACD","sourcesContent":["import type { AgentTool } from \"omk-agent-core\";\nimport {\n\tcreatePromptSettlementState,\n\ttype PromptSettledEvent,\n\ttype PromptSettlementOutcome,\n\treducePromptSettlement,\n\tsettlePromptIfReady,\n} from \"./prompt-settlement.ts\";\n\ninterface PromptOwner {\n\treadonly promptRunId: string;\n\treadonly startedAt: number;\n\treadonly executions: Set<symbol>;\n\tterminal?: { readonly outcome: PromptSettlementOutcome; readonly notify: (event: PromptSettledEvent) => void };\n}\n\nexport class PromptExecutionBusyError extends Error {\n\tconstructor() {\n\t\tsuper(\"Agent is already processing or has unsettled tool execution. Wait for actual termination.\");\n\t\tthis.name = \"PromptExecutionBusyError\";\n\t}\n}\n\n/** Session-local ownership, not a durable journal or a detached-process sandbox. */\nexport class SessionPromptLifecycle {\n\tprivate owner: PromptOwner | undefined;\n\tprivate disposed = false;\n\tprivate readonly canSettle: () => boolean;\n\tprivate readonly auditsLateSettlement: () => boolean;\n\n\tconstructor(options: { canSettle?: () => boolean; auditsLateSettlement?: () => boolean } = {}) {\n\t\tthis.canSettle = options.canSettle ?? (() => true);\n\t\tthis.auditsLateSettlement = options.auditsLateSettlement ?? (() => true);\n\t}\n\n\tassertIdle(): void {\n\t\tif (this.owner !== undefined || this.disposed) throw new PromptExecutionBusyError();\n\t}\n\n\tbegin(promptRunId: string): {\n\t\tfinish: (outcome: PromptSettlementOutcome, notify: (event: PromptSettledEvent) => void) => void;\n\t} {\n\t\tthis.assertIdle();\n\t\tconst owner: PromptOwner = { promptRunId, startedAt: performance.now(), executions: new Set() };\n\t\tthis.owner = owner;\n\t\treturn {\n\t\t\tfinish: (outcome, notify) => {\n\t\t\t\tif (owner.terminal !== undefined) return;\n\t\t\t\towner.terminal = { outcome, notify };\n\t\t\t\tthis.flush();\n\t\t\t},\n\t\t};\n\t}\n\n\twrapTool(tool: AgentTool): AgentTool {\n\t\treturn {\n\t\t\tname: tool.name,\n\t\t\tlabel: tool.label,\n\t\t\tdescription: tool.description,\n\t\t\tparameters: tool.parameters,\n\t\t\tprepareArguments: tool.prepareArguments,\n\t\t\texecutionMode: tool.executionMode,\n\t\t\tresourceClaims: tool.resourceClaims,\n\t\t\t// A spread would evaluate and freeze the context-sensitive timeout too early.\n\t\t\tget timeoutMs() {\n\t\t\t\treturn tool.timeoutMs;\n\t\t\t},\n\t\t\texecute: async (...args) => {\n\t\t\t\tconst owner = this.owner;\n\t\t\t\tif (this.disposed || owner?.terminal !== undefined) throw new PromptExecutionBusyError();\n\t\t\t\t// Runtime-owned identities cannot collide with reused model toolCallIds.\n\t\t\t\tconst execution = Symbol();\n\t\t\t\tconst requiresAudit = this.auditsLateSettlement();\n\t\t\t\towner?.executions.add(execution);\n\t\t\t\ttry {\n\t\t\t\t\treturn await tool.execute(...args);\n\t\t\t\t} finally {\n\t\t\t\t\towner?.executions.delete(execution);\n\t\t\t\t\t// Audit mode flushes only after the late event has been delivered.\n\t\t\t\t\tif (!requiresAudit) this.flush();\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t}\n\n\t/** Called after the root producer drains, or after late-settlement event delivery. */\n\tflush(): void {\n\t\tconst owner = this.owner;\n\t\tif (!owner?.terminal || owner.executions.size > 0 || this.disposed || !this.canSettle()) return;\n\t\tconst state = reducePromptSettlement(createPromptSettlementState(owner.promptRunId, owner.startedAt), {\n\t\t\tkind: \"terminal\",\n\t\t\toutcome: owner.terminal.outcome,\n\t\t});\n\t\tconst { event } = settlePromptIfReady(state, performance.now());\n\t\tthis.owner = undefined;\n\t\tif (event !== null) owner.terminal.notify(event);\n\t}\n\n\tdispose(): void {\n\t\tthis.disposed = true;\n\t\tthis.owner = undefined;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Agent, StreamFn } from "omk-agent-core";
|
|
2
|
+
import { RunBudget, type RunBudgetSnapshot } from "./run-budget.ts";
|
|
3
|
+
import { RunBudgetExceededError, type RunBudgetLimits, RunBudgetPolicyError } from "./run-budget-policy.ts";
|
|
4
|
+
interface RunBudgetLifecycle {
|
|
5
|
+
readonly assertIdle: () => void;
|
|
6
|
+
readonly stop: (error: RunBudgetExceededError) => void;
|
|
7
|
+
readonly reject: (error: RunBudgetExceededError | RunBudgetPolicyError) => void;
|
|
8
|
+
}
|
|
9
|
+
/** Installs one scoped stream boundary; restores it without overwriting a later owner. */
|
|
10
|
+
export declare class SessionRunBudget {
|
|
11
|
+
private readonly agent;
|
|
12
|
+
private readonly lifecycle;
|
|
13
|
+
private current;
|
|
14
|
+
private previous;
|
|
15
|
+
private executing;
|
|
16
|
+
private disposed;
|
|
17
|
+
constructor(agent: Agent, lifecycle: RunBudgetLifecycle);
|
|
18
|
+
get failure(): RunBudgetExceededError | undefined;
|
|
19
|
+
get remainingMs(): number | undefined;
|
|
20
|
+
snapshot(): RunBudgetSnapshot | undefined;
|
|
21
|
+
assertActive(): void;
|
|
22
|
+
assertAdmission(): void;
|
|
23
|
+
close(): void;
|
|
24
|
+
execute(limits: RunBudgetLimits | undefined, operation: () => Promise<void>, preflightResult?: (accepted: boolean) => void): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
export declare function wrapBudgetStream(source: StreamFn, budget: RunBudget): StreamFn;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=session-run-budget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-run-budget.d.ts","sourceRoot":"","sources":["../../src/core/session-run-budget.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,KAAK,eAAe,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAG5G,UAAU,kBAAkB;IAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,IAAI,CAAC;IAChC,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,sBAAsB,KAAK,IAAI,CAAC;IACvD,QAAQ,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,sBAAsB,GAAG,oBAAoB,KAAK,IAAI,CAAC;CAChF;AAED,0FAA0F;AAC1F,qBAAa,gBAAgB;IAC5B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAQ;IAC9B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAqB;IAC/C,OAAO,CAAC,OAAO,CAAwB;IACvC,OAAO,CAAC,QAAQ,CAAwB;IACxC,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,QAAQ,CAAS;IAEzB,YAAY,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,kBAAkB,EAGtD;IAED,IAAI,OAAO,IAAI,sBAAsB,GAAG,SAAS,CAEhD;IACD,IAAI,WAAW,IAAI,MAAM,GAAG,SAAS,CAEpC;IACD,QAAQ,IAAI,iBAAiB,GAAG,SAAS,CAExC;IACD,YAAY,IAAI,IAAI,CAEnB;IACD,eAAe,IAAI,IAAI,CAEtB;IACD,KAAK,IAAI,IAAI,CAGZ;IAEK,OAAO,CACZ,MAAM,EAAE,eAAe,GAAG,SAAS,EACnC,SAAS,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EAC9B,eAAe,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,GAC3C,OAAO,CAAC,IAAI,CAAC,CAmDf;CACD;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,GAAG,QAAQ,CA6B9E","sourcesContent":["import type { Agent, StreamFn } from \"omk-agent-core\";\nimport { RunBudget, type RunBudgetSnapshot } from \"./run-budget.ts\";\nimport { RunBudgetExceededError, type RunBudgetLimits, RunBudgetPolicyError } from \"./run-budget-policy.ts\";\nimport { PromptExecutionBusyError } from \"./session-prompt-lifecycle.ts\";\n\ninterface RunBudgetLifecycle {\n\treadonly assertIdle: () => void;\n\treadonly stop: (error: RunBudgetExceededError) => void;\n\treadonly reject: (error: RunBudgetExceededError | RunBudgetPolicyError) => void;\n}\n\n/** Installs one scoped stream boundary; restores it without overwriting a later owner. */\nexport class SessionRunBudget {\n\tprivate readonly agent: Agent;\n\tprivate readonly lifecycle: RunBudgetLifecycle;\n\tprivate current: RunBudget | undefined;\n\tprivate previous: RunBudget | undefined;\n\tprivate executing = false;\n\tprivate disposed = false;\n\n\tconstructor(agent: Agent, lifecycle: RunBudgetLifecycle) {\n\t\tthis.agent = agent;\n\t\tthis.lifecycle = lifecycle;\n\t}\n\n\tget failure(): RunBudgetExceededError | undefined {\n\t\treturn this.current?.failure;\n\t}\n\tget remainingMs(): number | undefined {\n\t\treturn this.current?.remainingMs;\n\t}\n\tsnapshot(): RunBudgetSnapshot | undefined {\n\t\treturn (this.current ?? this.previous)?.snapshot();\n\t}\n\tassertActive(): void {\n\t\tthis.current?.assertActive();\n\t}\n\tassertAdmission(): void {\n\t\tthis.current?.assertAdmission();\n\t}\n\tclose(): void {\n\t\tthis.disposed = true;\n\t\tthis.current?.close();\n\t}\n\n\tasync execute(\n\t\tlimits: RunBudgetLimits | undefined,\n\t\toperation: () => Promise<void>,\n\t\tpreflightResult?: (accepted: boolean) => void,\n\t): Promise<void> {\n\t\tlet ownsScope = false;\n\t\tlet entered = false;\n\t\tlet budget: RunBudget | undefined;\n\t\tconst source = this.agent.streamFn;\n\t\tconst sourceAuth = this.agent.getApiKey;\n\t\tlet wrapped: StreamFn | undefined;\n\t\tlet wrappedAuth: Agent[\"getApiKey\"];\n\t\ttry {\n\t\t\tif (this.executing || this.disposed || (this.previous?.snapshot().activeRequests ?? 0) > 0) {\n\t\t\t\tthrow new PromptExecutionBusyError();\n\t\t\t}\n\t\t\tthis.executing = true;\n\t\t\townsScope = true;\n\t\t\tif (limits !== undefined) {\n\t\t\t\tif (this.agent.state.isStreaming) throw new PromptExecutionBusyError();\n\t\t\t\tthis.lifecycle.assertIdle();\n\t\t\t\tconst scopedBudget = new RunBudget(limits, this.lifecycle.stop);\n\t\t\t\tbudget = scopedBudget;\n\t\t\t\tthis.current = scopedBudget;\n\t\t\t\twrapped = wrapBudgetStream(source, scopedBudget);\n\t\t\t\twrappedAuth = async (provider) => {\n\t\t\t\t\tscopedBudget.assertAdmission();\n\t\t\t\t\tconst key = await sourceAuth?.(provider);\n\t\t\t\t\tscopedBudget.assertActive();\n\t\t\t\t\treturn key;\n\t\t\t\t};\n\t\t\t\tthis.agent.streamFn = wrapped;\n\t\t\t\tthis.agent.getApiKey = wrappedAuth;\n\t\t\t\tscopedBudget.assertAdmission();\n\t\t\t}\n\t\t\tentered = true;\n\t\t\tawait operation();\n\t\t\tbudget?.assertActive();\n\t\t} catch (error) {\n\t\t\tif (!entered) {\n\t\t\t\tpreflightResult?.(false);\n\t\t\t\tif (error instanceof RunBudgetExceededError || error instanceof RunBudgetPolicyError)\n\t\t\t\t\tthis.lifecycle.reject(error);\n\t\t\t}\n\t\t\tthrow budget?.failure ?? error;\n\t\t} finally {\n\t\t\tif (budget) {\n\t\t\t\tbudget.close();\n\t\t\t\tthis.previous = budget;\n\t\t\t\tif (this.current === budget) this.current = undefined;\n\t\t\t}\n\t\t\tif (wrapped !== undefined && this.agent.streamFn === wrapped) this.agent.streamFn = source;\n\t\t\tif (wrappedAuth !== undefined && this.agent.getApiKey === wrappedAuth) this.agent.getApiKey = sourceAuth;\n\t\t\tif (ownsScope) this.executing = false;\n\t\t}\n\t}\n}\n\nexport function wrapBudgetStream(source: StreamFn, budget: RunBudget): StreamFn {\n\tconst wrapped: StreamFn = async (model, context, options) => {\n\t\toptions?.signal?.throwIfAborted();\n\t\tconst release = budget.admit();\n\t\tconst remainingMs = budget.remainingMs;\n\t\ttry {\n\t\t\tconst stream = await source(model, context, {\n\t\t\t\t...options,\n\t\t\t\tsignal: options?.signal ? AbortSignal.any([options.signal, budget.signal]) : budget.signal,\n\t\t\t\tmaxRetries: 0,\n\t\t\t\t...(remainingMs === undefined\n\t\t\t\t\t? {}\n\t\t\t\t\t: { timeoutMs: Math.min(options?.timeoutMs ?? remainingMs, remainingMs) }),\n\t\t\t});\n\t\t\t// A returned stream is not yet a completed request. Missing terminal metadata\n\t\t\t// retains the reservation; abort alone never refunds it.\n\t\t\tvoid stream.result().then(release, release);\n\t\t\treturn stream;\n\t\t} catch (error) {\n\t\t\trelease();\n\t\t\tthrow error;\n\t\t}\n\t};\n\t// Preserve source-owned identity brands used by mandatory credential checks.\n\tfor (const key of Object.getOwnPropertySymbols(source)) {\n\t\tconst descriptor = Object.getOwnPropertyDescriptor(source, key);\n\t\tif (descriptor) Object.defineProperty(wrapped, key, descriptor);\n\t}\n\treturn wrapped;\n}\n"]}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { RunBudget } from "./run-budget.js";
|
|
2
|
+
import { RunBudgetExceededError, RunBudgetPolicyError } from "./run-budget-policy.js";
|
|
3
|
+
import { PromptExecutionBusyError } from "./session-prompt-lifecycle.js";
|
|
4
|
+
/** Installs one scoped stream boundary; restores it without overwriting a later owner. */
|
|
5
|
+
export class SessionRunBudget {
|
|
6
|
+
agent;
|
|
7
|
+
lifecycle;
|
|
8
|
+
current;
|
|
9
|
+
previous;
|
|
10
|
+
executing = false;
|
|
11
|
+
disposed = false;
|
|
12
|
+
constructor(agent, lifecycle) {
|
|
13
|
+
this.agent = agent;
|
|
14
|
+
this.lifecycle = lifecycle;
|
|
15
|
+
}
|
|
16
|
+
get failure() {
|
|
17
|
+
return this.current?.failure;
|
|
18
|
+
}
|
|
19
|
+
get remainingMs() {
|
|
20
|
+
return this.current?.remainingMs;
|
|
21
|
+
}
|
|
22
|
+
snapshot() {
|
|
23
|
+
return (this.current ?? this.previous)?.snapshot();
|
|
24
|
+
}
|
|
25
|
+
assertActive() {
|
|
26
|
+
this.current?.assertActive();
|
|
27
|
+
}
|
|
28
|
+
assertAdmission() {
|
|
29
|
+
this.current?.assertAdmission();
|
|
30
|
+
}
|
|
31
|
+
close() {
|
|
32
|
+
this.disposed = true;
|
|
33
|
+
this.current?.close();
|
|
34
|
+
}
|
|
35
|
+
async execute(limits, operation, preflightResult) {
|
|
36
|
+
let ownsScope = false;
|
|
37
|
+
let entered = false;
|
|
38
|
+
let budget;
|
|
39
|
+
const source = this.agent.streamFn;
|
|
40
|
+
const sourceAuth = this.agent.getApiKey;
|
|
41
|
+
let wrapped;
|
|
42
|
+
let wrappedAuth;
|
|
43
|
+
try {
|
|
44
|
+
if (this.executing || this.disposed || (this.previous?.snapshot().activeRequests ?? 0) > 0) {
|
|
45
|
+
throw new PromptExecutionBusyError();
|
|
46
|
+
}
|
|
47
|
+
this.executing = true;
|
|
48
|
+
ownsScope = true;
|
|
49
|
+
if (limits !== undefined) {
|
|
50
|
+
if (this.agent.state.isStreaming)
|
|
51
|
+
throw new PromptExecutionBusyError();
|
|
52
|
+
this.lifecycle.assertIdle();
|
|
53
|
+
const scopedBudget = new RunBudget(limits, this.lifecycle.stop);
|
|
54
|
+
budget = scopedBudget;
|
|
55
|
+
this.current = scopedBudget;
|
|
56
|
+
wrapped = wrapBudgetStream(source, scopedBudget);
|
|
57
|
+
wrappedAuth = async (provider) => {
|
|
58
|
+
scopedBudget.assertAdmission();
|
|
59
|
+
const key = await sourceAuth?.(provider);
|
|
60
|
+
scopedBudget.assertActive();
|
|
61
|
+
return key;
|
|
62
|
+
};
|
|
63
|
+
this.agent.streamFn = wrapped;
|
|
64
|
+
this.agent.getApiKey = wrappedAuth;
|
|
65
|
+
scopedBudget.assertAdmission();
|
|
66
|
+
}
|
|
67
|
+
entered = true;
|
|
68
|
+
await operation();
|
|
69
|
+
budget?.assertActive();
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
if (!entered) {
|
|
73
|
+
preflightResult?.(false);
|
|
74
|
+
if (error instanceof RunBudgetExceededError || error instanceof RunBudgetPolicyError)
|
|
75
|
+
this.lifecycle.reject(error);
|
|
76
|
+
}
|
|
77
|
+
throw budget?.failure ?? error;
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
if (budget) {
|
|
81
|
+
budget.close();
|
|
82
|
+
this.previous = budget;
|
|
83
|
+
if (this.current === budget)
|
|
84
|
+
this.current = undefined;
|
|
85
|
+
}
|
|
86
|
+
if (wrapped !== undefined && this.agent.streamFn === wrapped)
|
|
87
|
+
this.agent.streamFn = source;
|
|
88
|
+
if (wrappedAuth !== undefined && this.agent.getApiKey === wrappedAuth)
|
|
89
|
+
this.agent.getApiKey = sourceAuth;
|
|
90
|
+
if (ownsScope)
|
|
91
|
+
this.executing = false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
export function wrapBudgetStream(source, budget) {
|
|
96
|
+
const wrapped = async (model, context, options) => {
|
|
97
|
+
options?.signal?.throwIfAborted();
|
|
98
|
+
const release = budget.admit();
|
|
99
|
+
const remainingMs = budget.remainingMs;
|
|
100
|
+
try {
|
|
101
|
+
const stream = await source(model, context, {
|
|
102
|
+
...options,
|
|
103
|
+
signal: options?.signal ? AbortSignal.any([options.signal, budget.signal]) : budget.signal,
|
|
104
|
+
maxRetries: 0,
|
|
105
|
+
...(remainingMs === undefined
|
|
106
|
+
? {}
|
|
107
|
+
: { timeoutMs: Math.min(options?.timeoutMs ?? remainingMs, remainingMs) }),
|
|
108
|
+
});
|
|
109
|
+
// A returned stream is not yet a completed request. Missing terminal metadata
|
|
110
|
+
// retains the reservation; abort alone never refunds it.
|
|
111
|
+
void stream.result().then(release, release);
|
|
112
|
+
return stream;
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
release();
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
// Preserve source-owned identity brands used by mandatory credential checks.
|
|
120
|
+
for (const key of Object.getOwnPropertySymbols(source)) {
|
|
121
|
+
const descriptor = Object.getOwnPropertyDescriptor(source, key);
|
|
122
|
+
if (descriptor)
|
|
123
|
+
Object.defineProperty(wrapped, key, descriptor);
|
|
124
|
+
}
|
|
125
|
+
return wrapped;
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=session-run-budget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-run-budget.js","sourceRoot":"","sources":["../../src/core/session-run-budget.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAA0B,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAwB,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC5G,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAQzE,0FAA0F;AAC1F,MAAM,OAAO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BAC3C,GAAG,OAAO;gBACV,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM;gBAC1F,UAAU,EAAE,CAAC;gBACb,GAAG,CAAC,WAAW,KAAK,SAAS;oBAC5B,CAAC,CAAC,EAAE;oBACJ,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,SAAS,IAAI,WAAW,EAAE,WAAW,CAAC,EAAE,CAAC;aAC3E,CAAC,CAAC;YACH,8EAA8E;YAC9E,yDAAyD;YACzD,KAAK,MAAM,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC5C,OAAO,MAAM,CAAC;QACf,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,OAAO,EAAE,CAAC;YACV,MAAM,KAAK,CAAC;QACb,CAAC;IAAA,CACD,CAAC;IACF,6EAA6E;IAC7E,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,qBAAqB,CAAC,MAAM,CAAC,EAAE,CAAC;QACxD,MAAM,UAAU,GAAG,MAAM,CAAC,wBAAwB,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAChE,IAAI,UAAU;YAAE,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC;IACjE,CAAC;IACD,OAAO,OAAO,CAAC;AAAA,CACf","sourcesContent":["import type { Agent, StreamFn } from \"omk-agent-core\";\nimport { RunBudget, type RunBudgetSnapshot } from \"./run-budget.ts\";\nimport { RunBudgetExceededError, type RunBudgetLimits, RunBudgetPolicyError } from \"./run-budget-policy.ts\";\nimport { PromptExecutionBusyError } from \"./session-prompt-lifecycle.ts\";\n\ninterface RunBudgetLifecycle {\n\treadonly assertIdle: () => void;\n\treadonly stop: (error: RunBudgetExceededError) => void;\n\treadonly reject: (error: RunBudgetExceededError | RunBudgetPolicyError) => void;\n}\n\n/** Installs one scoped stream boundary; restores it without overwriting a later owner. */\nexport class SessionRunBudget {\n\tprivate readonly agent: Agent;\n\tprivate readonly lifecycle: RunBudgetLifecycle;\n\tprivate current: RunBudget | undefined;\n\tprivate previous: RunBudget | undefined;\n\tprivate executing = false;\n\tprivate disposed = false;\n\n\tconstructor(agent: Agent, lifecycle: RunBudgetLifecycle) {\n\t\tthis.agent = agent;\n\t\tthis.lifecycle = lifecycle;\n\t}\n\n\tget failure(): RunBudgetExceededError | undefined {\n\t\treturn this.current?.failure;\n\t}\n\tget remainingMs(): number | undefined {\n\t\treturn this.current?.remainingMs;\n\t}\n\tsnapshot(): RunBudgetSnapshot | undefined {\n\t\treturn (this.current ?? this.previous)?.snapshot();\n\t}\n\tassertActive(): void {\n\t\tthis.current?.assertActive();\n\t}\n\tassertAdmission(): void {\n\t\tthis.current?.assertAdmission();\n\t}\n\tclose(): void {\n\t\tthis.disposed = true;\n\t\tthis.current?.close();\n\t}\n\n\tasync execute(\n\t\tlimits: RunBudgetLimits | undefined,\n\t\toperation: () => Promise<void>,\n\t\tpreflightResult?: (accepted: boolean) => void,\n\t): Promise<void> {\n\t\tlet ownsScope = false;\n\t\tlet entered = false;\n\t\tlet budget: RunBudget | undefined;\n\t\tconst source = this.agent.streamFn;\n\t\tconst sourceAuth = this.agent.getApiKey;\n\t\tlet wrapped: StreamFn | undefined;\n\t\tlet wrappedAuth: Agent[\"getApiKey\"];\n\t\ttry {\n\t\t\tif (this.executing || this.disposed || (this.previous?.snapshot().activeRequests ?? 0) > 0) {\n\t\t\t\tthrow new PromptExecutionBusyError();\n\t\t\t}\n\t\t\tthis.executing = true;\n\t\t\townsScope = true;\n\t\t\tif (limits !== undefined) {\n\t\t\t\tif (this.agent.state.isStreaming) throw new PromptExecutionBusyError();\n\t\t\t\tthis.lifecycle.assertIdle();\n\t\t\t\tconst scopedBudget = new RunBudget(limits, this.lifecycle.stop);\n\t\t\t\tbudget = scopedBudget;\n\t\t\t\tthis.current = scopedBudget;\n\t\t\t\twrapped = wrapBudgetStream(source, scopedBudget);\n\t\t\t\twrappedAuth = async (provider) => {\n\t\t\t\t\tscopedBudget.assertAdmission();\n\t\t\t\t\tconst key = await sourceAuth?.(provider);\n\t\t\t\t\tscopedBudget.assertActive();\n\t\t\t\t\treturn key;\n\t\t\t\t};\n\t\t\t\tthis.agent.streamFn = wrapped;\n\t\t\t\tthis.agent.getApiKey = wrappedAuth;\n\t\t\t\tscopedBudget.assertAdmission();\n\t\t\t}\n\t\t\tentered = true;\n\t\t\tawait operation();\n\t\t\tbudget?.assertActive();\n\t\t} catch (error) {\n\t\t\tif (!entered) {\n\t\t\t\tpreflightResult?.(false);\n\t\t\t\tif (error instanceof RunBudgetExceededError || error instanceof RunBudgetPolicyError)\n\t\t\t\t\tthis.lifecycle.reject(error);\n\t\t\t}\n\t\t\tthrow budget?.failure ?? error;\n\t\t} finally {\n\t\t\tif (budget) {\n\t\t\t\tbudget.close();\n\t\t\t\tthis.previous = budget;\n\t\t\t\tif (this.current === budget) this.current = undefined;\n\t\t\t}\n\t\t\tif (wrapped !== undefined && this.agent.streamFn === wrapped) this.agent.streamFn = source;\n\t\t\tif (wrappedAuth !== undefined && this.agent.getApiKey === wrappedAuth) this.agent.getApiKey = sourceAuth;\n\t\t\tif (ownsScope) this.executing = false;\n\t\t}\n\t}\n}\n\nexport function wrapBudgetStream(source: StreamFn, budget: RunBudget): StreamFn {\n\tconst wrapped: StreamFn = async (model, context, options) => {\n\t\toptions?.signal?.throwIfAborted();\n\t\tconst release = budget.admit();\n\t\tconst remainingMs = budget.remainingMs;\n\t\ttry {\n\t\t\tconst stream = await source(model, context, {\n\t\t\t\t...options,\n\t\t\t\tsignal: options?.signal ? AbortSignal.any([options.signal, budget.signal]) : budget.signal,\n\t\t\t\tmaxRetries: 0,\n\t\t\t\t...(remainingMs === undefined\n\t\t\t\t\t? {}\n\t\t\t\t\t: { timeoutMs: Math.min(options?.timeoutMs ?? remainingMs, remainingMs) }),\n\t\t\t});\n\t\t\t// A returned stream is not yet a completed request. Missing terminal metadata\n\t\t\t// retains the reservation; abort alone never refunds it.\n\t\t\tvoid stream.result().then(release, release);\n\t\t\treturn stream;\n\t\t} catch (error) {\n\t\t\trelease();\n\t\t\tthrow error;\n\t\t}\n\t};\n\t// Preserve source-owned identity brands used by mandatory credential checks.\n\tfor (const key of Object.getOwnPropertySymbols(source)) {\n\t\tconst descriptor = Object.getOwnPropertyDescriptor(source, key);\n\t\tif (descriptor) Object.defineProperty(wrapped, key, descriptor);\n\t}\n\treturn wrapped;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-run-termination.d.ts","sourceRoot":"","sources":["../../src/core/session-run-termination.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,EAAE,GAAG,EAAoB,KAAK,EAAE,MAAM,QAAQ,CAAC;AAE3D,OAAO,EACN,KAAK,+BAA+B,EAEpC,KAAK,kBAAkB,EACvB,KAAK,uBAAuB,EAC5B,MAAM,0BAA0B,CAAC;AAElC,UAAU,qBAAsB,SAAQ,IAAI,CAAC,+BAA+B,EAAE,WAAW,GAAG,OAAO,GAAG,WAAW,CAAC;IACjH,QAAQ,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,UAAU,GAAG,IAAI,GAAG,eAAe,CAAC,CAAC;IACvE,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAC/B,QAAQ,CAAC,kBAAkB,EAAE,OAAO,CAAC;IACrC,QAAQ,CAAC,YAAY,CAAC,EAAE,uBAAuB,CAAC;IAChD,QAAQ,CAAC,WAAW,CAAC,EAAE;QACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;QAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAC1B,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;KACnC,CAAC;CACF;AAED,kGAAkG;AAClG,wBAAgB,sBAAsB,CACrC,QAAQ,EAAE,SAAS,YAAY,EAAE,EACjC,OAAO,EAAE,qBAAqB,GAC5B,kBAAkB,
|
|
1
|
+
{"version":3,"file":"session-run-termination.d.ts","sourceRoot":"","sources":["../../src/core/session-run-termination.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,EAAE,GAAG,EAAoB,KAAK,EAAE,MAAM,QAAQ,CAAC;AAE3D,OAAO,EACN,KAAK,+BAA+B,EAEpC,KAAK,kBAAkB,EACvB,KAAK,uBAAuB,EAC5B,MAAM,0BAA0B,CAAC;AAElC,UAAU,qBAAsB,SAAQ,IAAI,CAAC,+BAA+B,EAAE,WAAW,GAAG,OAAO,GAAG,WAAW,CAAC;IACjH,QAAQ,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,UAAU,GAAG,IAAI,GAAG,eAAe,CAAC,CAAC;IACvE,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAC/B,QAAQ,CAAC,kBAAkB,EAAE,OAAO,CAAC;IACrC,QAAQ,CAAC,YAAY,CAAC,EAAE,uBAAuB,CAAC;IAChD,QAAQ,CAAC,WAAW,CAAC,EAAE;QACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;QAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAC1B,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;KACnC,CAAC;CACF;AAED,kGAAkG;AAClG,wBAAgB,sBAAsB,CACrC,QAAQ,EAAE,SAAS,YAAY,EAAE,EACjC,OAAO,EAAE,qBAAqB,GAC5B,kBAAkB,CA4DpB","sourcesContent":["import type { AgentMessage } from \"omk-agent-core\";\nimport type { Api, AssistantMessage, Model } from \"omk-ai\";\nimport { providerFailureCause, terminationMessage } from \"./session-failure-cause.ts\";\nimport {\n\ttype ClassifySessionTerminationInput,\n\tclassifySessionTermination,\n\ttype SessionTermination,\n\ttype SessionTerminationCause,\n} from \"./session-termination.ts\";\n\ninterface RunTerminationContext extends Pick<ClassifySessionTerminationInput, \"sessionId\" | \"runId\" | \"timestamp\"> {\n\treadonly model?: Pick<Model<Api>, \"provider\" | \"id\" | \"contextWindow\">;\n\treadonly elevatedRisk: boolean;\n\treadonly userAbortRequested: boolean;\n\treadonly pendingCause?: SessionTerminationCause;\n\treadonly toolTimeout?: {\n\t\treadonly toolCallId: string;\n\t\treadonly toolName: string;\n\t\treadonly executionStarted: boolean;\n\t};\n}\n\n/** Translate one settled core run into a cause; lifecycle persistence stays with AgentSession. */\nexport function classifyRunTermination(\n\tmessages: readonly AgentMessage[],\n\tcontext: RunTerminationContext,\n): SessionTermination {\n\tlet assistant: AssistantMessage | undefined;\n\tfor (let index = messages.length - 1; index >= 0; index--) {\n\t\tconst candidate = messages[index];\n\t\tif (candidate?.role === \"assistant\") {\n\t\t\tassistant = candidate;\n\t\t\tbreak;\n\t\t}\n\t}\n\tlet cause: SessionTerminationCause;\n\tlet message: string;\n\tlet sideEffects: \"none\" | \"possible\" = context.elevatedRisk ? \"possible\" : \"none\";\n\tlet toolCallId: string | undefined;\n\tlet toolName: string | undefined;\n\n\tif (context.pendingCause?.area === \"budget\") {\n\t\tcause = context.pendingCause;\n\t\tmessage = `Run budget exhausted: ${context.pendingCause.code}`;\n\t\tsideEffects = \"possible\";\n\t} else if (context.toolTimeout) {\n\t\tcause = { area: \"tool\", code: \"timeout\" };\n\t\tmessage = `Tool ${context.toolTimeout.toolName} timed out.`;\n\t\ttoolCallId = context.toolTimeout.toolCallId;\n\t\ttoolName = context.toolTimeout.toolName;\n\t\tsideEffects = context.toolTimeout.executionStarted ? \"possible\" : sideEffects;\n\t} else if (context.pendingCause?.area === \"configuration\") {\n\t\tcause = context.pendingCause;\n\t\tmessage = \"Model dispatch was rejected by the configured model contract.\";\n\t} else if (context.userAbortRequested) {\n\t\tcause = { area: \"user\", code: \"abort\" };\n\t\tmessage = \"The user aborted the run.\";\n\t\tif (messages.some((entry) => entry.role === \"toolResult\")) sideEffects = \"possible\";\n\t} else if (!assistant) {\n\t\tcause = { area: \"internal\", code: \"unclassified\" };\n\t\tmessage = \"Agent run ended without an assistant result.\";\n\t} else if (assistant.stopReason === \"aborted\") {\n\t\tcause = { area: \"provider\", code: \"abort\" };\n\t\tmessage = terminationMessage(assistant.errorMessage, \"The provider aborted the run.\");\n\t} else if (assistant.stopReason === \"error\") {\n\t\tcause = providerFailureCause(assistant, context.model?.contextWindow ?? 0);\n\t\tmessage = terminationMessage(assistant.errorMessage, \"The provider request failed.\");\n\t} else {\n\t\tcause = { area: \"completed\" };\n\t\tmessage = \"Run completed.\";\n\t}\n\tconst provider = assistant?.provider || context.model?.provider;\n\tconst model = assistant?.model || context.model?.id;\n\treturn classifySessionTermination({\n\t\tsessionId: context.sessionId,\n\t\trunId: context.runId,\n\t\ttimestamp: context.timestamp,\n\t\tsource: \"observed\",\n\t\tmessage,\n\t\tcause,\n\t\tsideEffects,\n\t\t...(provider ? { provider } : {}),\n\t\t...(model ? { model } : {}),\n\t\t...(toolCallId ? { toolCallId } : {}),\n\t\t...(toolName ? { toolName } : {}),\n\t});\n}\n"]}
|
|
@@ -15,7 +15,12 @@ export function classifyRunTermination(messages, context) {
|
|
|
15
15
|
let sideEffects = context.elevatedRisk ? "possible" : "none";
|
|
16
16
|
let toolCallId;
|
|
17
17
|
let toolName;
|
|
18
|
-
if (context.
|
|
18
|
+
if (context.pendingCause?.area === "budget") {
|
|
19
|
+
cause = context.pendingCause;
|
|
20
|
+
message = `Run budget exhausted: ${context.pendingCause.code}`;
|
|
21
|
+
sideEffects = "possible";
|
|
22
|
+
}
|
|
23
|
+
else if (context.toolTimeout) {
|
|
19
24
|
cause = { area: "tool", code: "timeout" };
|
|
20
25
|
message = `Tool ${context.toolTimeout.toolName} timed out.`;
|
|
21
26
|
toolCallId = context.toolTimeout.toolCallId;
|
|
@@ -26,13 +31,19 @@ export function classifyRunTermination(messages, context) {
|
|
|
26
31
|
cause = context.pendingCause;
|
|
27
32
|
message = "Model dispatch was rejected by the configured model contract.";
|
|
28
33
|
}
|
|
34
|
+
else if (context.userAbortRequested) {
|
|
35
|
+
cause = { area: "user", code: "abort" };
|
|
36
|
+
message = "The user aborted the run.";
|
|
37
|
+
if (messages.some((entry) => entry.role === "toolResult"))
|
|
38
|
+
sideEffects = "possible";
|
|
39
|
+
}
|
|
29
40
|
else if (!assistant) {
|
|
30
41
|
cause = { area: "internal", code: "unclassified" };
|
|
31
42
|
message = "Agent run ended without an assistant result.";
|
|
32
43
|
}
|
|
33
44
|
else if (assistant.stopReason === "aborted") {
|
|
34
|
-
cause =
|
|
35
|
-
message = terminationMessage(assistant.errorMessage,
|
|
45
|
+
cause = { area: "provider", code: "abort" };
|
|
46
|
+
message = terminationMessage(assistant.errorMessage, "The provider aborted the run.");
|
|
36
47
|
}
|
|
37
48
|
else if (assistant.stopReason === "error") {
|
|
38
49
|
cause = providerFailureCause(assistant, context.model?.contextWindow ?? 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-run-termination.js","sourceRoot":"","sources":["../../src/core/session-run-termination.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AACtF,OAAO,EAEN,0BAA0B,GAG1B,MAAM,0BAA0B,CAAC;AAclC,kGAAkG;AAClG,MAAM,UAAU,sBAAsB,CACrC,QAAiC,EACjC,OAA8B,EACT;IACrB,IAAI,SAAuC,CAAC;IAC5C,KAAK,IAAI,KAAK,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;QAC3D,MAAM,SAAS,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;QAClC,IAAI,SAAS,EAAE,IAAI,KAAK,WAAW,EAAE,CAAC;YACrC,SAAS,GAAG,SAAS,CAAC;YACtB,MAAM;QACP,CAAC;IACF,CAAC;IACD,IAAI,KAA8B,CAAC;IACnC,IAAI,OAAe,CAAC;IACpB,IAAI,WAAW,GAAwB,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC;IAClF,IAAI,UAA8B,CAAC;IACnC,IAAI,QAA4B,CAAC;IAEjC,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"session-run-termination.js","sourceRoot":"","sources":["../../src/core/session-run-termination.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AACtF,OAAO,EAEN,0BAA0B,GAG1B,MAAM,0BAA0B,CAAC;AAclC,kGAAkG;AAClG,MAAM,UAAU,sBAAsB,CACrC,QAAiC,EACjC,OAA8B,EACT;IACrB,IAAI,SAAuC,CAAC;IAC5C,KAAK,IAAI,KAAK,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;QAC3D,MAAM,SAAS,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;QAClC,IAAI,SAAS,EAAE,IAAI,KAAK,WAAW,EAAE,CAAC;YACrC,SAAS,GAAG,SAAS,CAAC;YACtB,MAAM;QACP,CAAC;IACF,CAAC;IACD,IAAI,KAA8B,CAAC;IACnC,IAAI,OAAe,CAAC;IACpB,IAAI,WAAW,GAAwB,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC;IAClF,IAAI,UAA8B,CAAC;IACnC,IAAI,QAA4B,CAAC;IAEjC,IAAI,OAAO,CAAC,YAAY,EAAE,IAAI,KAAK,QAAQ,EAAE,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EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACjC,CAAC,CAAC;AAAA,CACH","sourcesContent":["import type { AgentMessage } from \"omk-agent-core\";\nimport type { Api, AssistantMessage, Model } from \"omk-ai\";\nimport { providerFailureCause, terminationMessage } from \"./session-failure-cause.ts\";\nimport {\n\ttype ClassifySessionTerminationInput,\n\tclassifySessionTermination,\n\ttype SessionTermination,\n\ttype SessionTerminationCause,\n} from \"./session-termination.ts\";\n\ninterface RunTerminationContext extends Pick<ClassifySessionTerminationInput, \"sessionId\" | \"runId\" | \"timestamp\"> {\n\treadonly model?: Pick<Model<Api>, \"provider\" | \"id\" | \"contextWindow\">;\n\treadonly elevatedRisk: boolean;\n\treadonly userAbortRequested: boolean;\n\treadonly pendingCause?: SessionTerminationCause;\n\treadonly toolTimeout?: {\n\t\treadonly toolCallId: string;\n\t\treadonly toolName: string;\n\t\treadonly executionStarted: boolean;\n\t};\n}\n\n/** Translate one settled core run into a cause; lifecycle persistence stays with AgentSession. */\nexport function classifyRunTermination(\n\tmessages: readonly AgentMessage[],\n\tcontext: RunTerminationContext,\n): SessionTermination {\n\tlet assistant: AssistantMessage | undefined;\n\tfor (let index = messages.length - 1; index >= 0; index--) {\n\t\tconst candidate = messages[index];\n\t\tif (candidate?.role === \"assistant\") {\n\t\t\tassistant = candidate;\n\t\t\tbreak;\n\t\t}\n\t}\n\tlet cause: SessionTerminationCause;\n\tlet message: string;\n\tlet sideEffects: \"none\" | \"possible\" = context.elevatedRisk ? \"possible\" : \"none\";\n\tlet toolCallId: string | undefined;\n\tlet toolName: string | undefined;\n\n\tif (context.pendingCause?.area === \"budget\") {\n\t\tcause = context.pendingCause;\n\t\tmessage = `Run budget exhausted: ${context.pendingCause.code}`;\n\t\tsideEffects = \"possible\";\n\t} else if (context.toolTimeout) {\n\t\tcause = { area: \"tool\", code: \"timeout\" };\n\t\tmessage = `Tool ${context.toolTimeout.toolName} timed out.`;\n\t\ttoolCallId = context.toolTimeout.toolCallId;\n\t\ttoolName = context.toolTimeout.toolName;\n\t\tsideEffects = context.toolTimeout.executionStarted ? \"possible\" : sideEffects;\n\t} else if (context.pendingCause?.area === \"configuration\") {\n\t\tcause = context.pendingCause;\n\t\tmessage = \"Model dispatch was rejected by the configured model contract.\";\n\t} else if (context.userAbortRequested) {\n\t\tcause = { area: \"user\", code: \"abort\" };\n\t\tmessage = \"The user aborted the run.\";\n\t\tif (messages.some((entry) => entry.role === \"toolResult\")) sideEffects = \"possible\";\n\t} else if (!assistant) {\n\t\tcause = { area: \"internal\", code: \"unclassified\" };\n\t\tmessage = \"Agent run ended without an assistant result.\";\n\t} else if (assistant.stopReason === \"aborted\") {\n\t\tcause = { area: \"provider\", code: \"abort\" };\n\t\tmessage = terminationMessage(assistant.errorMessage, \"The provider aborted the run.\");\n\t} else if (assistant.stopReason === \"error\") {\n\t\tcause = providerFailureCause(assistant, context.model?.contextWindow ?? 0);\n\t\tmessage = terminationMessage(assistant.errorMessage, \"The provider request failed.\");\n\t} else {\n\t\tcause = { area: \"completed\" };\n\t\tmessage = \"Run completed.\";\n\t}\n\tconst provider = assistant?.provider || context.model?.provider;\n\tconst model = assistant?.model || context.model?.id;\n\treturn classifySessionTermination({\n\t\tsessionId: context.sessionId,\n\t\trunId: context.runId,\n\t\ttimestamp: context.timestamp,\n\t\tsource: \"observed\",\n\t\tmessage,\n\t\tcause,\n\t\tsideEffects,\n\t\t...(provider ? { provider } : {}),\n\t\t...(model ? { model } : {}),\n\t\t...(toolCallId ? { toolCallId } : {}),\n\t\t...(toolName ? { toolName } : {}),\n\t});\n}\n"]}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { RunBudgetStopCode } from "./run-budget-policy.ts";
|
|
2
|
+
export declare const SESSION_TERMINATION_SCHEMA_VERSION: 1;
|
|
3
|
+
export declare const MAX_SESSION_TERMINATION_MESSAGE_LENGTH = 512;
|
|
4
|
+
/** The journal validator derives its accepted kinds from this tuple. */
|
|
5
|
+
export declare const SESSION_TERMINATION_KIND_VALUES: readonly ["completed", "user_abort", "provider_abort", "provider_auth", "provider_rate_limit", "provider_network", "provider_protocol", "provider_refusal", "context_overflow", "transcript_invalid", "tool_timeout", "tool_fatal", "compaction", "persistence", "process_signal", "process_crash", "configuration", "internal_error", "resource_pressure", "budget_exhausted"];
|
|
6
|
+
export type SessionTerminationKind = (typeof SESSION_TERMINATION_KIND_VALUES)[number];
|
|
7
|
+
export type SessionTerminationPhase = "completed" | "control" | "preflight" | "provider" | "tool" | "compaction" | "persistence" | "process" | "resume";
|
|
8
|
+
export type SessionTerminationSource = "observed" | "inferred_on_resume";
|
|
9
|
+
export type SessionSideEffects = "none" | "possible" | "confirmed";
|
|
10
|
+
export type SessionProcessSignal = "SIGINT" | "SIGTERM" | "SIGHUP" | "SIGQUIT";
|
|
11
|
+
export type ProviderTerminationCauseCode = "abort" | "auth" | "rate_limit" | "network" | "protocol" | "refusal" | "context_overflow";
|
|
12
|
+
export type ToolTerminationCauseCode = "timeout" | "fatal";
|
|
13
|
+
export type ResourceTerminationCauseCode = "memory" | "disk" | "cpu" | "heap" | "probe_unavailable" | "queue_overflow";
|
|
14
|
+
export type CompactionTerminationCauseCode = "aborted" | "failed" | "stale" | "quota_exhausted";
|
|
15
|
+
export type PersistenceTerminationCauseCode = "read_failed" | "append_failed" | "replace_failed" | "fsync_failed" | "lock_failed";
|
|
16
|
+
export type TranscriptTerminationCauseCode = "missing_result" | "duplicate_result" | "orphan_result" | "duplicate_call_id" | "interleaved_non_result" | "invalid_jsonl" | "invalid_tree" | "unsupported_version" | "trailing_fragment";
|
|
17
|
+
export type SessionTerminationCauseCode = "session.completed" | "session.user_abort" | `provider.${ProviderTerminationCauseCode}` | `tool.${ToolTerminationCauseCode}` | `compaction.${CompactionTerminationCauseCode}` | `persistence.${PersistenceTerminationCauseCode}` | "process.signal" | "process.crash" | `transcript.${TranscriptTerminationCauseCode}` | "configuration.invalid" | "internal.unclassified" | `resource.${ResourceTerminationCauseCode}` | `budget.${RunBudgetStopCode}`;
|
|
18
|
+
export type SessionTerminationCause = {
|
|
19
|
+
readonly area: "completed";
|
|
20
|
+
} | {
|
|
21
|
+
readonly area: "user";
|
|
22
|
+
readonly code: "abort";
|
|
23
|
+
} | {
|
|
24
|
+
readonly area: "provider";
|
|
25
|
+
readonly code: ProviderTerminationCauseCode;
|
|
26
|
+
} | {
|
|
27
|
+
readonly area: "tool";
|
|
28
|
+
readonly code: ToolTerminationCauseCode;
|
|
29
|
+
} | {
|
|
30
|
+
readonly area: "compaction";
|
|
31
|
+
readonly code: CompactionTerminationCauseCode;
|
|
32
|
+
} | {
|
|
33
|
+
readonly area: "persistence";
|
|
34
|
+
readonly code: PersistenceTerminationCauseCode;
|
|
35
|
+
} | {
|
|
36
|
+
readonly area: "process";
|
|
37
|
+
readonly code: "signal";
|
|
38
|
+
readonly signal: SessionProcessSignal;
|
|
39
|
+
} | {
|
|
40
|
+
readonly area: "process";
|
|
41
|
+
readonly code: "crash";
|
|
42
|
+
} | {
|
|
43
|
+
readonly area: "transcript";
|
|
44
|
+
readonly code: TranscriptTerminationCauseCode;
|
|
45
|
+
} | {
|
|
46
|
+
readonly area: "configuration";
|
|
47
|
+
readonly code: "invalid";
|
|
48
|
+
} | {
|
|
49
|
+
readonly area: "internal";
|
|
50
|
+
readonly code: "unclassified";
|
|
51
|
+
} | {
|
|
52
|
+
readonly area: "resource";
|
|
53
|
+
readonly code: ResourceTerminationCauseCode;
|
|
54
|
+
} | {
|
|
55
|
+
readonly area: "budget";
|
|
56
|
+
readonly code: RunBudgetStopCode;
|
|
57
|
+
};
|
|
58
|
+
export interface ClassifySessionTerminationInput {
|
|
59
|
+
readonly sessionId: string;
|
|
60
|
+
readonly runId: string;
|
|
61
|
+
/** Deterministic caller-provided ISO-8601 timestamp. */
|
|
62
|
+
readonly timestamp: string;
|
|
63
|
+
readonly source: SessionTerminationSource;
|
|
64
|
+
/** Caller-supplied, pre-redacted diagnostic text. */
|
|
65
|
+
readonly message: string;
|
|
66
|
+
readonly cause: SessionTerminationCause;
|
|
67
|
+
readonly sideEffects: SessionSideEffects;
|
|
68
|
+
readonly retryAfterMs?: number;
|
|
69
|
+
readonly provider?: string;
|
|
70
|
+
readonly model?: string;
|
|
71
|
+
readonly toolCallId?: string;
|
|
72
|
+
readonly toolName?: string;
|
|
73
|
+
}
|
|
74
|
+
export interface SessionTermination {
|
|
75
|
+
readonly schemaVersion: typeof SESSION_TERMINATION_SCHEMA_VERSION;
|
|
76
|
+
readonly sessionId: string;
|
|
77
|
+
readonly runId: string;
|
|
78
|
+
readonly kind: SessionTerminationKind;
|
|
79
|
+
readonly phase: SessionTerminationPhase;
|
|
80
|
+
readonly source: SessionTerminationSource;
|
|
81
|
+
readonly message: string;
|
|
82
|
+
readonly causeCode: SessionTerminationCauseCode;
|
|
83
|
+
/** Stable operator guidance suitable for print, JSON, RPC, and TUI surfaces. */
|
|
84
|
+
readonly nextAction: string;
|
|
85
|
+
readonly retryable: boolean;
|
|
86
|
+
readonly safeToAutoRetry: boolean;
|
|
87
|
+
readonly sideEffects: SessionSideEffects;
|
|
88
|
+
readonly timestamp: string;
|
|
89
|
+
readonly retryAfterMs?: number;
|
|
90
|
+
readonly provider?: string;
|
|
91
|
+
readonly model?: string;
|
|
92
|
+
readonly toolCallId?: string;
|
|
93
|
+
readonly toolName?: string;
|
|
94
|
+
readonly processSignal?: SessionProcessSignal;
|
|
95
|
+
readonly transcriptIssue?: TranscriptTerminationCauseCode;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=session-termination-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-termination-types.d.ts","sourceRoot":"","sources":["../../src/core/session-termination-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhE,eAAO,MAAM,kCAAkC,GAAa,CAAC;AAC7D,eAAO,MAAM,sCAAsC,MAAM,CAAC;AAE1D,wEAA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EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,2BAA2B,CAAC;IAChD,gFAAgF;IAChF,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC;IAClC,QAAQ,CAAC,WAAW,EAAE,kBAAkB,CAAC;IACzC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,aAAa,CAAC,EAAE,oBAAoB,CAAC;IAC9C,QAAQ,CAAC,eAAe,CAAC,EAAE,8BAA8B,CAAC;CAC1D","sourcesContent":["import type { RunBudgetStopCode } from \"./run-budget-policy.ts\";\n\nexport const SESSION_TERMINATION_SCHEMA_VERSION = 1 as const;\nexport const MAX_SESSION_TERMINATION_MESSAGE_LENGTH = 512;\n\n/** The journal validator derives its accepted kinds from this tuple. */\nexport const SESSION_TERMINATION_KIND_VALUES = [\n\t\"completed\",\n\t\"user_abort\",\n\t\"provider_abort\",\n\t\"provider_auth\",\n\t\"provider_rate_limit\",\n\t\"provider_network\",\n\t\"provider_protocol\",\n\t\"provider_refusal\",\n\t\"context_overflow\",\n\t\"transcript_invalid\",\n\t\"tool_timeout\",\n\t\"tool_fatal\",\n\t\"compaction\",\n\t\"persistence\",\n\t\"process_signal\",\n\t\"process_crash\",\n\t\"configuration\",\n\t\"internal_error\",\n\t\"resource_pressure\",\n\t\"budget_exhausted\",\n] as const;\nexport type SessionTerminationKind = (typeof SESSION_TERMINATION_KIND_VALUES)[number];\nexport type SessionTerminationPhase =\n\t| \"completed\"\n\t| \"control\"\n\t| \"preflight\"\n\t| \"provider\"\n\t| \"tool\"\n\t| \"compaction\"\n\t| \"persistence\"\n\t| \"process\"\n\t| \"resume\";\nexport type SessionTerminationSource = \"observed\" | \"inferred_on_resume\";\nexport type SessionSideEffects = \"none\" | \"possible\" | \"confirmed\";\nexport type SessionProcessSignal = \"SIGINT\" | \"SIGTERM\" | \"SIGHUP\" | \"SIGQUIT\";\nexport type ProviderTerminationCauseCode =\n\t| \"abort\"\n\t| \"auth\"\n\t| \"rate_limit\"\n\t| \"network\"\n\t| \"protocol\"\n\t| \"refusal\"\n\t| \"context_overflow\";\nexport type ToolTerminationCauseCode = \"timeout\" | \"fatal\";\nexport type ResourceTerminationCauseCode = \"memory\" | \"disk\" | \"cpu\" | \"heap\" | \"probe_unavailable\" | \"queue_overflow\";\nexport type CompactionTerminationCauseCode = \"aborted\" | \"failed\" | \"stale\" | \"quota_exhausted\";\nexport type PersistenceTerminationCauseCode =\n\t| \"read_failed\"\n\t| \"append_failed\"\n\t| \"replace_failed\"\n\t| \"fsync_failed\"\n\t| \"lock_failed\";\nexport type TranscriptTerminationCauseCode =\n\t| \"missing_result\"\n\t| \"duplicate_result\"\n\t| \"orphan_result\"\n\t| \"duplicate_call_id\"\n\t| \"interleaved_non_result\"\n\t| \"invalid_jsonl\"\n\t| \"invalid_tree\"\n\t| \"unsupported_version\"\n\t| \"trailing_fragment\";\nexport type SessionTerminationCauseCode =\n\t| \"session.completed\"\n\t| \"session.user_abort\"\n\t| `provider.${ProviderTerminationCauseCode}`\n\t| `tool.${ToolTerminationCauseCode}`\n\t| `compaction.${CompactionTerminationCauseCode}`\n\t| `persistence.${PersistenceTerminationCauseCode}`\n\t| \"process.signal\"\n\t| \"process.crash\"\n\t| `transcript.${TranscriptTerminationCauseCode}`\n\t| \"configuration.invalid\"\n\t| \"internal.unclassified\"\n\t| `resource.${ResourceTerminationCauseCode}`\n\t| `budget.${RunBudgetStopCode}`;\n\nexport type SessionTerminationCause =\n\t| { readonly area: \"completed\" }\n\t| { readonly area: \"user\"; readonly code: \"abort\" }\n\t| { readonly area: \"provider\"; readonly code: ProviderTerminationCauseCode }\n\t| { readonly area: \"tool\"; readonly code: ToolTerminationCauseCode }\n\t| { readonly area: \"compaction\"; readonly code: CompactionTerminationCauseCode }\n\t| { readonly area: \"persistence\"; readonly code: PersistenceTerminationCauseCode }\n\t| { readonly area: \"process\"; readonly code: \"signal\"; readonly signal: SessionProcessSignal }\n\t| { readonly area: \"process\"; readonly code: \"crash\" }\n\t| { readonly area: \"transcript\"; readonly code: TranscriptTerminationCauseCode }\n\t| { readonly area: \"configuration\"; readonly code: \"invalid\" }\n\t| { readonly area: \"internal\"; readonly code: \"unclassified\" }\n\t| { readonly area: \"resource\"; readonly code: ResourceTerminationCauseCode }\n\t| { readonly area: \"budget\"; readonly code: RunBudgetStopCode };\n\nexport interface ClassifySessionTerminationInput {\n\treadonly sessionId: string;\n\treadonly runId: string;\n\t/** Deterministic caller-provided ISO-8601 timestamp. */\n\treadonly timestamp: string;\n\treadonly source: SessionTerminationSource;\n\t/** Caller-supplied, pre-redacted diagnostic text. */\n\treadonly message: string;\n\treadonly cause: SessionTerminationCause;\n\treadonly sideEffects: SessionSideEffects;\n\treadonly retryAfterMs?: number;\n\treadonly provider?: string;\n\treadonly model?: string;\n\treadonly toolCallId?: string;\n\treadonly toolName?: string;\n}\n\nexport interface SessionTermination {\n\treadonly schemaVersion: typeof SESSION_TERMINATION_SCHEMA_VERSION;\n\treadonly sessionId: string;\n\treadonly runId: string;\n\treadonly kind: SessionTerminationKind;\n\treadonly phase: SessionTerminationPhase;\n\treadonly source: SessionTerminationSource;\n\treadonly message: string;\n\treadonly causeCode: SessionTerminationCauseCode;\n\t/** Stable operator guidance suitable for print, JSON, RPC, and TUI surfaces. */\n\treadonly nextAction: string;\n\treadonly retryable: boolean;\n\treadonly safeToAutoRetry: boolean;\n\treadonly sideEffects: SessionSideEffects;\n\treadonly timestamp: string;\n\treadonly retryAfterMs?: number;\n\treadonly provider?: string;\n\treadonly model?: string;\n\treadonly toolCallId?: string;\n\treadonly toolName?: string;\n\treadonly processSignal?: SessionProcessSignal;\n\treadonly transcriptIssue?: TranscriptTerminationCauseCode;\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export const SESSION_TERMINATION_SCHEMA_VERSION = 1;
|
|
2
|
+
export const MAX_SESSION_TERMINATION_MESSAGE_LENGTH = 512;
|
|
3
|
+
/** The journal validator derives its accepted kinds from this tuple. */
|
|
4
|
+
export const SESSION_TERMINATION_KIND_VALUES = [
|
|
5
|
+
"completed",
|
|
6
|
+
"user_abort",
|
|
7
|
+
"provider_abort",
|
|
8
|
+
"provider_auth",
|
|
9
|
+
"provider_rate_limit",
|
|
10
|
+
"provider_network",
|
|
11
|
+
"provider_protocol",
|
|
12
|
+
"provider_refusal",
|
|
13
|
+
"context_overflow",
|
|
14
|
+
"transcript_invalid",
|
|
15
|
+
"tool_timeout",
|
|
16
|
+
"tool_fatal",
|
|
17
|
+
"compaction",
|
|
18
|
+
"persistence",
|
|
19
|
+
"process_signal",
|
|
20
|
+
"process_crash",
|
|
21
|
+
"configuration",
|
|
22
|
+
"internal_error",
|
|
23
|
+
"resource_pressure",
|
|
24
|
+
"budget_exhausted",
|
|
25
|
+
];
|
|
26
|
+
//# sourceMappingURL=session-termination-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-termination-types.js","sourceRoot":"","sources":["../../src/core/session-termination-types.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAAU,CAAC;AAC7D,MAAM,CAAC,MAAM,sCAAsC,GAAG,GAAG,CAAC;AAE1D,wEAAwE;AACxE,MAAM,CAAC,MAAM,+BAA+B,GAAG;IAC9C,WAAW;IACX,YAAY;IACZ,gBAAgB;IAChB,eAAe;IACf,qBAAqB;IACrB,kBAAkB;IAClB,mBAAmB;IACnB,kBAAkB;IAClB,kBAAkB;IAClB,oBAAoB;IACpB,cAAc;IACd,YAAY;IACZ,YAAY;IACZ,aAAa;IACb,gBAAgB;IAChB,eAAe;IACf,eAAe;IACf,gBAAgB;IAChB,mBAAmB;IACnB,kBAAkB;CACT,CAAC","sourcesContent":["import type { RunBudgetStopCode } from \"./run-budget-policy.ts\";\n\nexport const SESSION_TERMINATION_SCHEMA_VERSION = 1 as const;\nexport const MAX_SESSION_TERMINATION_MESSAGE_LENGTH = 512;\n\n/** The journal validator derives its accepted kinds from this tuple. */\nexport const SESSION_TERMINATION_KIND_VALUES = [\n\t\"completed\",\n\t\"user_abort\",\n\t\"provider_abort\",\n\t\"provider_auth\",\n\t\"provider_rate_limit\",\n\t\"provider_network\",\n\t\"provider_protocol\",\n\t\"provider_refusal\",\n\t\"context_overflow\",\n\t\"transcript_invalid\",\n\t\"tool_timeout\",\n\t\"tool_fatal\",\n\t\"compaction\",\n\t\"persistence\",\n\t\"process_signal\",\n\t\"process_crash\",\n\t\"configuration\",\n\t\"internal_error\",\n\t\"resource_pressure\",\n\t\"budget_exhausted\",\n] as const;\nexport type SessionTerminationKind = (typeof SESSION_TERMINATION_KIND_VALUES)[number];\nexport type SessionTerminationPhase =\n\t| \"completed\"\n\t| \"control\"\n\t| \"preflight\"\n\t| \"provider\"\n\t| \"tool\"\n\t| \"compaction\"\n\t| \"persistence\"\n\t| \"process\"\n\t| \"resume\";\nexport type SessionTerminationSource = \"observed\" | \"inferred_on_resume\";\nexport type SessionSideEffects = \"none\" | \"possible\" | \"confirmed\";\nexport type SessionProcessSignal = \"SIGINT\" | \"SIGTERM\" | \"SIGHUP\" | \"SIGQUIT\";\nexport type ProviderTerminationCauseCode =\n\t| \"abort\"\n\t| \"auth\"\n\t| \"rate_limit\"\n\t| \"network\"\n\t| \"protocol\"\n\t| \"refusal\"\n\t| \"context_overflow\";\nexport type ToolTerminationCauseCode = \"timeout\" | \"fatal\";\nexport type ResourceTerminationCauseCode = \"memory\" | \"disk\" | \"cpu\" | \"heap\" | \"probe_unavailable\" | \"queue_overflow\";\nexport type CompactionTerminationCauseCode = \"aborted\" | \"failed\" | \"stale\" | \"quota_exhausted\";\nexport type PersistenceTerminationCauseCode =\n\t| \"read_failed\"\n\t| \"append_failed\"\n\t| \"replace_failed\"\n\t| \"fsync_failed\"\n\t| \"lock_failed\";\nexport type TranscriptTerminationCauseCode =\n\t| \"missing_result\"\n\t| \"duplicate_result\"\n\t| \"orphan_result\"\n\t| \"duplicate_call_id\"\n\t| \"interleaved_non_result\"\n\t| \"invalid_jsonl\"\n\t| \"invalid_tree\"\n\t| \"unsupported_version\"\n\t| \"trailing_fragment\";\nexport type SessionTerminationCauseCode =\n\t| \"session.completed\"\n\t| \"session.user_abort\"\n\t| `provider.${ProviderTerminationCauseCode}`\n\t| `tool.${ToolTerminationCauseCode}`\n\t| `compaction.${CompactionTerminationCauseCode}`\n\t| `persistence.${PersistenceTerminationCauseCode}`\n\t| \"process.signal\"\n\t| \"process.crash\"\n\t| `transcript.${TranscriptTerminationCauseCode}`\n\t| \"configuration.invalid\"\n\t| \"internal.unclassified\"\n\t| `resource.${ResourceTerminationCauseCode}`\n\t| `budget.${RunBudgetStopCode}`;\n\nexport type SessionTerminationCause =\n\t| { readonly area: \"completed\" }\n\t| { readonly area: \"user\"; readonly code: \"abort\" }\n\t| { readonly area: \"provider\"; readonly code: ProviderTerminationCauseCode }\n\t| { readonly area: \"tool\"; readonly code: ToolTerminationCauseCode }\n\t| { readonly area: \"compaction\"; readonly code: CompactionTerminationCauseCode }\n\t| { readonly area: \"persistence\"; readonly code: PersistenceTerminationCauseCode }\n\t| { readonly area: \"process\"; readonly code: \"signal\"; readonly signal: SessionProcessSignal }\n\t| { readonly area: \"process\"; readonly code: \"crash\" }\n\t| { readonly area: \"transcript\"; readonly code: TranscriptTerminationCauseCode }\n\t| { readonly area: \"configuration\"; readonly code: \"invalid\" }\n\t| { readonly area: \"internal\"; readonly code: \"unclassified\" }\n\t| { readonly area: \"resource\"; readonly code: ResourceTerminationCauseCode }\n\t| { readonly area: \"budget\"; readonly code: RunBudgetStopCode };\n\nexport interface ClassifySessionTerminationInput {\n\treadonly sessionId: string;\n\treadonly runId: string;\n\t/** Deterministic caller-provided ISO-8601 timestamp. */\n\treadonly timestamp: string;\n\treadonly source: SessionTerminationSource;\n\t/** Caller-supplied, pre-redacted diagnostic text. */\n\treadonly message: string;\n\treadonly cause: SessionTerminationCause;\n\treadonly sideEffects: SessionSideEffects;\n\treadonly retryAfterMs?: number;\n\treadonly provider?: string;\n\treadonly model?: string;\n\treadonly toolCallId?: string;\n\treadonly toolName?: string;\n}\n\nexport interface SessionTermination {\n\treadonly schemaVersion: typeof SESSION_TERMINATION_SCHEMA_VERSION;\n\treadonly sessionId: string;\n\treadonly runId: string;\n\treadonly kind: SessionTerminationKind;\n\treadonly phase: SessionTerminationPhase;\n\treadonly source: SessionTerminationSource;\n\treadonly message: string;\n\treadonly causeCode: SessionTerminationCauseCode;\n\t/** Stable operator guidance suitable for print, JSON, RPC, and TUI surfaces. */\n\treadonly nextAction: string;\n\treadonly retryable: boolean;\n\treadonly safeToAutoRetry: boolean;\n\treadonly sideEffects: SessionSideEffects;\n\treadonly timestamp: string;\n\treadonly retryAfterMs?: number;\n\treadonly provider?: string;\n\treadonly model?: string;\n\treadonly toolCallId?: string;\n\treadonly toolName?: string;\n\treadonly processSignal?: SessionProcessSignal;\n\treadonly transcriptIssue?: TranscriptTerminationCauseCode;\n}\n"]}
|