@code-yeongyu/senpi 2026.9.7 → 2026.9.8
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 +79 -0
- package/dist/core/agent-session.d.ts +40 -3
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +159 -40
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +2 -1
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/dynamic-prompt/working-task.js +1 -1
- package/dist/core/dynamic-prompt/working-task.js.map +1 -1
- package/dist/core/extensions/builtin/cache-keepalive/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/cache-keepalive/index.js +4 -21
- package/dist/core/extensions/builtin/cache-keepalive/index.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/account-command.d.ts +2 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/account-command.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/account-command.js +10 -25
- package/dist/core/extensions/builtin/claude-sdk-oauth/account-command.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-binding.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-binding.js +36 -19
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-binding.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-commit-boundary.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-commit-boundary.js +21 -10
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-commit-boundary.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-continuity.d.ts +4 -17
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-continuity.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-continuity.js +23 -33
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-continuity.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-stream.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-stream.js +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-stream.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-sync.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-sync.js +5 -3
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-sync.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-turn-attempt.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-turn-attempt.js +8 -3
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-turn-attempt.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/tools.d.ts +6 -5
- package/dist/core/extensions/builtin/claude-sdk-oauth/tools.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/tools.js +6 -5
- package/dist/core/extensions/builtin/claude-sdk-oauth/tools.js.map +1 -1
- package/dist/core/extensions/builtin/compaction/circuit-breaker.d.ts +8 -0
- package/dist/core/extensions/builtin/compaction/circuit-breaker.d.ts.map +1 -1
- package/dist/core/extensions/builtin/compaction/circuit-breaker.js +8 -0
- package/dist/core/extensions/builtin/compaction/circuit-breaker.js.map +1 -1
- package/dist/core/extensions/builtin/compaction/deterministic-fallback.d.ts +8 -0
- package/dist/core/extensions/builtin/compaction/deterministic-fallback.d.ts.map +1 -1
- package/dist/core/extensions/builtin/compaction/deterministic-fallback.js +125 -20
- package/dist/core/extensions/builtin/compaction/deterministic-fallback.js.map +1 -1
- package/dist/core/extensions/builtin/compaction/fallback-failed-turn-normalization.d.ts +18 -0
- package/dist/core/extensions/builtin/compaction/fallback-failed-turn-normalization.d.ts.map +1 -0
- package/dist/core/extensions/builtin/compaction/fallback-failed-turn-normalization.js +20 -0
- package/dist/core/extensions/builtin/compaction/fallback-failed-turn-normalization.js.map +1 -0
- package/dist/core/extensions/builtin/compaction/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/compaction/index.js +54 -11
- package/dist/core/extensions/builtin/compaction/index.js.map +1 -1
- package/dist/core/extensions/builtin/compaction/lane-policy.d.ts +3 -0
- package/dist/core/extensions/builtin/compaction/lane-policy.d.ts.map +1 -1
- package/dist/core/extensions/builtin/compaction/lane-policy.js +47 -23
- package/dist/core/extensions/builtin/compaction/lane-policy.js.map +1 -1
- package/dist/core/extensions/builtin/goal/agent-end-continuation.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/agent-end-continuation.js +11 -0
- package/dist/core/extensions/builtin/goal/agent-end-continuation.js.map +1 -1
- package/dist/core/extensions/builtin/goal/cache-warm-renderer.js +6 -4
- package/dist/core/extensions/builtin/goal/cache-warm-renderer.js.map +1 -1
- package/dist/core/extensions/builtin/goal/cache-warm.d.ts +25 -1
- package/dist/core/extensions/builtin/goal/cache-warm.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/cache-warm.js +29 -10
- package/dist/core/extensions/builtin/goal/cache-warm.js.map +1 -1
- package/dist/core/extensions/builtin/goal/continuation.d.ts +3 -1
- package/dist/core/extensions/builtin/goal/continuation.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/continuation.js +17 -2
- package/dist/core/extensions/builtin/goal/continuation.js.map +1 -1
- package/dist/core/extensions/builtin/goal/lifecycle-helpers.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/lifecycle-helpers.js +1 -0
- package/dist/core/extensions/builtin/goal/lifecycle-helpers.js.map +1 -1
- package/dist/core/extensions/builtin/goal/monitor-continuation.d.ts +1 -1
- package/dist/core/extensions/builtin/goal/monitor-continuation.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/monitor-continuation.js +8 -3
- package/dist/core/extensions/builtin/goal/monitor-continuation.js.map +1 -1
- package/dist/core/extensions/builtin/gpt-account.d.ts +5 -1
- package/dist/core/extensions/builtin/gpt-account.d.ts.map +1 -1
- package/dist/core/extensions/builtin/gpt-account.js +9 -26
- package/dist/core/extensions/builtin/gpt-account.js.map +1 -1
- package/dist/core/extensions/builtin/hooks/plugin-manifest.js +2 -2
- package/dist/core/extensions/builtin/hooks/plugin-manifest.js.map +1 -1
- package/dist/core/extensions/builtin/hooks/safety.js +2 -2
- package/dist/core/extensions/builtin/hooks/safety.js.map +1 -1
- package/dist/core/extensions/builtin/monitor-state-event.d.ts +18 -0
- package/dist/core/extensions/builtin/monitor-state-event.d.ts.map +1 -1
- package/dist/core/extensions/builtin/monitor-state-event.js +23 -0
- package/dist/core/extensions/builtin/monitor-state-event.js.map +1 -1
- package/dist/core/extensions/builtin/oauth-login-interaction.d.ts +24 -0
- package/dist/core/extensions/builtin/oauth-login-interaction.d.ts.map +1 -0
- package/dist/core/extensions/builtin/oauth-login-interaction.js +77 -0
- package/dist/core/extensions/builtin/oauth-login-interaction.js.map +1 -0
- package/dist/core/extensions/builtin/permission-system/external-dir.d.ts.map +1 -1
- package/dist/core/extensions/builtin/permission-system/external-dir.js +5 -51
- package/dist/core/extensions/builtin/permission-system/external-dir.js.map +1 -1
- package/dist/core/extensions/builtin/permission-system/parsers.d.ts.map +1 -1
- package/dist/core/extensions/builtin/permission-system/parsers.js +5 -7
- package/dist/core/extensions/builtin/permission-system/parsers.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-fable-5-1.js +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-fable-5-1.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-fable-5.js +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-fable-5.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/execution-tooling.d.ts +14 -7
- package/dist/core/extensions/builtin/prompt-preset/execution-tooling.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/execution-tooling.js +34 -13
- package/dist/core/extensions/builtin/prompt-preset/execution-tooling.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.d.ts +6 -10
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.js +14 -9
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-6-astra.d.ts +15 -15
- package/dist/core/extensions/builtin/prompt-preset/gpt-6-astra.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-6-astra.js +49 -21
- package/dist/core/extensions/builtin/prompt-preset/gpt-6-astra.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k3.js +1 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k3.js.map +1 -1
- package/dist/core/extensions/builtin/service-tier.d.ts +2 -0
- package/dist/core/extensions/builtin/service-tier.d.ts.map +1 -1
- package/dist/core/extensions/builtin/service-tier.js +17 -1
- package/dist/core/extensions/builtin/service-tier.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/durable-command.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/durable-command.js +3 -0
- package/dist/core/extensions/builtin/terminal/durable-command.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/durable-file.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/durable-file.js +2 -0
- package/dist/core/extensions/builtin/terminal/durable-file.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/extension.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/extension.js +14 -2
- package/dist/core/extensions/builtin/terminal/extension.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/monitor-notify.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/monitor-notify.js +27 -5
- package/dist/core/extensions/builtin/terminal/monitor-notify.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/monitor-registry.d.ts +17 -0
- package/dist/core/extensions/builtin/terminal/monitor-registry.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/monitor-registry.js +76 -14
- package/dist/core/extensions/builtin/terminal/monitor-registry.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/notify.d.ts +2 -0
- package/dist/core/extensions/builtin/terminal/notify.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/notify.js +6 -1
- package/dist/core/extensions/builtin/terminal/notify.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/session-bundle.d.ts +3 -1
- package/dist/core/extensions/builtin/terminal/session-bundle.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/session-bundle.js +13 -0
- package/dist/core/extensions/builtin/terminal/session-bundle.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/shared.d.ts +13 -2
- package/dist/core/extensions/builtin/terminal/shared.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/shared.js +15 -2
- package/dist/core/extensions/builtin/terminal/shared.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/monitor.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/monitor.js +8 -1
- package/dist/core/extensions/builtin/terminal/tools/monitor.js.map +1 -1
- package/dist/core/extensions/builtin/tool-search/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/tool-search/index.js +1 -0
- package/dist/core/extensions/builtin/tool-search/index.js.map +1 -1
- package/dist/core/extensions/builtin/tool-search/service.d.ts +4 -0
- package/dist/core/extensions/builtin/tool-search/service.d.ts.map +1 -1
- package/dist/core/extensions/builtin/tool-search/service.js +11 -0
- package/dist/core/extensions/builtin/tool-search/service.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +1 -0
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +8 -1
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +9 -0
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/high-reasoning-warning.d.ts.map +1 -1
- package/dist/core/high-reasoning-warning.js +4 -6
- package/dist/core/high-reasoning-warning.js.map +1 -1
- package/dist/core/sdk.d.ts +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +25 -6
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/settings-manager.js +1 -1
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/settings-shapes.js.map +1 -1
- package/dist/core/tools/bounded-realpath.d.ts +28 -0
- package/dist/core/tools/bounded-realpath.d.ts.map +1 -0
- package/dist/core/tools/bounded-realpath.js +53 -0
- package/dist/core/tools/bounded-realpath.js.map +1 -0
- package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
- package/dist/core/tools/file-mutation-queue.js +15 -13
- package/dist/core/tools/file-mutation-queue.js.map +1 -1
- package/dist/core/tools/filesystem-policy.d.ts +7 -0
- package/dist/core/tools/filesystem-policy.d.ts.map +1 -1
- package/dist/core/tools/filesystem-policy.js +25 -15
- package/dist/core/tools/filesystem-policy.js.map +1 -1
- package/dist/core/trust-manager.d.ts.map +1 -1
- package/dist/core/trust-manager.js +13 -2
- package/dist/core/trust-manager.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +1 -0
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/tips/catalog/memory-tips.d.ts.map +1 -1
- package/dist/modes/interactive/tips/catalog/memory-tips.js +6 -0
- package/dist/modes/interactive/tips/catalog/memory-tips.js.map +1 -1
- package/dist/modes/interactive/tips/catalog/subagent-tips.d.ts.map +1 -1
- package/dist/modes/interactive/tips/catalog/subagent-tips.js +6 -0
- package/dist/modes/interactive/tips/catalog/subagent-tips.js.map +1 -1
- package/dist/modes/rpc/host-lifecycle.d.ts.map +1 -1
- package/dist/modes/rpc/host-lifecycle.js +31 -5
- package/dist/modes/rpc/host-lifecycle.js.map +1 -1
- package/dist/modes/rpc/host-watchdog.d.ts +11 -0
- package/dist/modes/rpc/host-watchdog.d.ts.map +1 -1
- package/dist/modes/rpc/host-watchdog.js +16 -2
- package/dist/modes/rpc/host-watchdog.js.map +1 -1
- package/dist/modes/rpc/multi-session-host.d.ts.map +1 -1
- package/dist/modes/rpc/multi-session-host.js +54 -16
- package/dist/modes/rpc/multi-session-host.js.map +1 -1
- package/dist/modes/rpc/socket-ownership.d.ts +46 -0
- package/dist/modes/rpc/socket-ownership.d.ts.map +1 -0
- package/dist/modes/rpc/socket-ownership.js +178 -0
- package/dist/modes/rpc/socket-ownership.js.map +1 -0
- package/dist/utils/fs-watch.d.ts +17 -0
- package/dist/utils/fs-watch.d.ts.map +1 -1
- package/dist/utils/fs-watch.js +38 -10
- package/dist/utils/fs-watch.js.map +1 -1
- package/dist/utils/paths.d.ts +33 -0
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +109 -3
- package/dist/utils/paths.js.map +1 -1
- package/docs/development.md +3 -2
- package/docs/providers.md +5 -1
- package/docs/settings.md +1 -0
- package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +31 -0
- package/node_modules/@code-yeongyu/senpi-codemode/README.md +14 -1
- package/node_modules/@code-yeongyu/senpi-codemode/package.json +4 -4
- package/node_modules/@code-yeongyu/senpi-codemode/src/bridge/protocol.ts +1 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/extension/runtime-factory.ts +3 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/extension/session-manager.ts +7 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/AGENTS.md +7 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/jl/kernel.ts +4 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-contract.ts +3 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-core.js +29 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-indirect-eval.js +10 -6
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-shell-capture.d.ts +16 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-shell-capture.js +44 -8
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-startup.ts +1 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/py/kernel-contract.ts +3 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/py/transport.ts +9 -1
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/rb/kernel.ts +4 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/session-env.ts +56 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/shared/subprocess-contract.ts +3 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/shared/subprocess-kernel.ts +9 -1
- package/node_modules/@code-yeongyu/senpi-codemode/src/output/output-meta.ts +26 -2
- package/node_modules/@code-yeongyu/senpi-codemode/src/prompt/eval-prompt.ts +17 -24
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/image.ts +12 -3
- package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js +2 -2
- package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/assistant-terminal-state.d.ts +7 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/assistant-terminal-state.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/assistant-terminal-state.js +19 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/assistant-terminal-state.js.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/empty-assistant-recovery.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/empty-assistant-recovery.js +24 -16
- package/node_modules/@earendil-works/pi-agent-core/dist/empty-assistant-recovery.js.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/index.d.ts +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/index.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/index.js +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/index.js.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +47 -178
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-tool-references.d.ts +3 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-tool-references.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-tool-references.js +260 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-tool-references.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/anthropic-callback-listener.d.ts +40 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/anthropic-callback-listener.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/anthropic-callback-listener.js +138 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/anthropic-callback-listener.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/anthropic.d.ts +2 -3
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/anthropic.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/anthropic.js +42 -139
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/anthropic.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/authorization-input.d.ts +6 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/authorization-input.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/authorization-input.js +29 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/authorization-input.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/error-details.d.ts +3 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/error-details.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/error-details.js +20 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/error-details.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/azure-openai-responses.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/github-copilot.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/openai-codex.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/openai.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/opengateway.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/recovery-stream-terminal.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/recovery-stream-terminal.js +16 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/recovery-stream-terminal.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/types.d.ts +7 -0
- package/node_modules/@earendil-works/pi-ai/dist/types.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/types.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.d.ts +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js +14 -3
- package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/server-fallback-receipt.d.ts +2 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/server-fallback-receipt.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/server-fallback-receipt.js +16 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/server-fallback-receipt.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/package.json +2 -2
- package/node_modules/@earendil-works/pi-pty/package.json +1 -1
- package/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
- package/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/package.json +7 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overflow.js","sourceRoot":"","sources":["../../src/utils/overflow.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,iBAAiB,GAAG;IACzB,6BAA6B,EAAE,qEAAqE;IACpG,qBAAqB,EAAE,2BAA2B;IAClD,oBAAoB,EAAE,kDAAkD;IACxE,wCAAwC,EAAE,iBAAiB;IAC3D,6BAA6B,EAAE,uCAAuC;IACtE,4FAA4F,EAAE,sCAAsC;IACpI,yCAAyC,EAAE,kBAAkB;IAC7D,+BAA+B,EAAE,aAAa;IAC9C,oCAAoC,EAAE,OAAO;IAC7C,uCAAuC,EAAE,6BAA6B;IACtE,kEAAkE,EAAE,sBAAsB;IAC1F,iFAAiF,EAAE,cAAc;IACjG,2BAA2B,EAAE,iBAAiB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B,CAAC;AACH,CAAC;AAED,MAAM,UAAU,kCAAkC,CAAC,OAIlD;IACA,IAAI,OAAO,CAAC,UAAU,KAAK,OAAO,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,IAAI,EAAE,CAAC,EAAE,CAAC;QAChG,OAAO,KAAK,CAAC;IACd,CAAC;IACD,OAAO,CAAC,CAAC,oBAAoB,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,yCAAyC,CAAC,OAAkD;IAC3G,OAAO,OAAO,EAAE,eAAe,KAAK,IAAI,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,iCAAiC,CAAC,SAAkB,EAAE,YAAoB;IACzF,IAAI,SAAS;QAAE,OAAO,KAAK,CAAC;IAC5B,OAAO,qBAAqB,CAAC,IAAI,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;AACvD,CAAC;AAED,MAAM,UAAU,gCAAgC,CAC/C,QAAW,EACX,QAA4B,EAC5B,MAA0B;IAE1B,IAAI,MAAM,KAAK,UAAU;QAAE,OAAO,QAAQ,CAAC;IAC3C,IAAI,QAAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,kBAAkB;QAAE,OAAO,QAAQ,CAAC;IAC9E,OAAO,EAAE,GAAG,QAAQ,EAAE,gBAAgB,EAAE,CAAC,EAAE,kBAAkB,EAAE,KAAK,EAAE,CAAC;AACxE,CAAC","sourcesContent":["import type { AssistantMessage } from \"../types.ts\";\n\n/**\n * Regex patterns to detect context overflow errors from different providers.\n *\n * These patterns match error messages returned when the input exceeds\n * the model's context window.\n *\n * Provider-specific patterns (with example error messages):\n *\n * - Anthropic: \"prompt is too long: 213462 tokens > 200000 maximum\"\n * - Anthropic: \"413 {\\\"error\\\":{\\\"type\\\":\\\"request_too_large\\\",\\\"message\\\":\\\"Request exceeds the maximum size\\\"}}\"\n * - OpenAI: \"Your input exceeds the context window of this model\"\n * - OpenAI/LiteLLM: \"Requested token count exceeds the model's maximum context length of 131072 tokens\"\n * - OpenAI-compatible: \"Input length (265330) exceeds model's maximum context length (262144).\"\n * - Google: \"The input token count (1196265) exceeds the maximum number of tokens allowed (1048575)\"\n * - xAI: \"This model's maximum prompt length is 131072 but the request contains 537812 tokens\"\n * - Groq: \"Please reduce the length of the messages or completion\"\n * - OpenRouter: \"This endpoint's maximum context length is X tokens. However, you requested about Y tokens\"\n * - OpenRouter/Poolside: \"Input length X exceeds the maximum allowed input length of Y tokens.\"\n * - Together AI: \"The input (X tokens) is longer than the model's context length (Y tokens).\"\n * - llama.cpp: \"the request exceeds the available context size, try increasing it\"\n * - LM Studio: \"tokens to keep from the initial prompt is greater than the context length\"\n * - GitHub Copilot: \"prompt token count of X exceeds the limit of Y\"\n * - MiniMax: \"invalid params, context window exceeds limit\"\n * - Kimi For Coding: \"Your request exceeded model token limit: X (requested: Y)\"\n * - DS4: \"Prompt has X tokens, but the configured context size is Y tokens\"\n * - Cerebras: \"400/413 status code (no body)\"\n * - Gateways: \"413 Request body too large\" / \"Request Entity Too Large\" / \"Payload Too Large\" (byte-size overflow)\n * - kiro-lb gateways: \"Request payload is 1095225 bytes, over the 1085435 byte limit Kiro accepts.\" / \"Request payload is N tokens, over the M token limit Kiro accepts.\" (HTTP 400 local payload guard)\n * - Kiro upstream via kiro-lb: \"Model context limit reached. Conversation size exceeds model capacity.\" (CONTENT_LENGTH_EXCEEDS_THRESHOLD token overflow)\n * - Mistral: \"Prompt contains X tokens ... too large for model with Y maximum context length\"\n * - z.ai: Does NOT error, accepts overflow silently - handled via usage.input > contextWindow\n * - Xiaomi MiMo: Truncates input to fill contextWindow exactly, then returns finish_reason \"length\"\n * with output=0 (no room left to generate). Detected via stopReason \"length\" + zero output +\n * input filling the context window.\n * - DashScope/Qwen: \"Range of input length should be [1, X]\" (HTTP 400 invalid_parameter_error)\n * - Ollama: Some deployments truncate silently, others return errors like \"prompt too long; exceeded max context length by X tokens\"\n * - pi-ai pre-flight guard (api/context-room.ts): \"Context window exhausted: the conversation is estimated at X of Y tokens, ...\" - raised before any provider call\n */\nconst OVERFLOW_PATTERNS = [\n\t/^Context window exhausted: /, // pi-ai pre-flight guard: no answer room left, provider never called\n\t/prompt is too long/i, // Anthropic token overflow\n\t/request_too_large/i, // Anthropic request byte-size overflow (HTTP 413)\n\t/input is too long for requested model/i, // Amazon Bedrock\n\t/exceeds the context window/i, // OpenAI (Completions & Responses API)\n\t/exceeds (?:the )?(?:model'?s )?maximum context length(?: of [\\d,]+ tokens?|\\s*\\([\\d,]+\\))/i, // OpenAI-compatible proxies (LiteLLM)\n\t/input token count.*exceeds the maximum/i, // Google (Gemini)\n\t/maximum prompt length is \\d+/i, // xAI (Grok)\n\t/reduce the length of the messages/i, // Groq\n\t/maximum context length is \\d+ tokens/i, // OpenRouter (most backends)\n\t/exceeds (?:the )?maximum allowed input length of [\\d,]+ tokens?/i, // OpenRouter/Poolside\n\t/input \\(\\d+ tokens\\) is longer than the model'?s context length \\(\\d+ tokens\\)/i, // Together AI\n\t/exceeds the limit of \\d+/i, // GitHub Copilot\n\t/exceeds the available context size/i, // llama.cpp server\n\t/greater than the context length/i, // LM Studio\n\t/context window exceeds limit/i, // MiniMax\n\t/exceeded model token limit/i, // Kimi For Coding\n\t/too large for model with \\d+ maximum context length/i, // Mistral\n\t/prompt has [\\d,]+ tokens?, but the configured context size is [\\d,]+ tokens?/i, // DS4 server\n\t/model_context_window_exceeded/i, // z.ai non-standard finish_reason surfaced as error text\n\t/prompt too long; exceeded (?:max )?context length/i, // Ollama explicit overflow error\n\t/range of input length should be/i, // DashScope / Qwen Token Plan\n\t/context[_ ]length[_ ]exceeded/i, // Generic fallback\n\t/too many tokens/i, // Generic fallback\n\t/token limit exceeded/i, // Generic fallback\n\t/^4(?:00|13)\\s*(?:status code)?\\s*\\(no body\\)/i, // Cerebras: 400/413 with no body\n\t/(?:request[ _])?(?:body|entity|payload)[_ ]too[_ ]large/i, // Gateway HTTP 413 byte-size rejections (\"Request body too large\", \"Request Entity Too Large\", \"body_too_large\", \"Payload Too Large\"). Substring-anchored by design (JSON bodies lack an adjacent status code); a non-context size rejection (e.g. an oversized image) can over-match, which costs one bounded shrink-retry, never a wedge.\n\t/Request payload is \\d+ (?:bytes, over the \\d+ byte|tokens, over the \\d+ token) limit Kiro accepts\\./, // kiro-lb local byte/token payload guard (HTTP 400; Anthropic uses invalid_request_error, OpenAI uses detail).\n\t/Model context limit reached\\. Conversation size exceeds model capacity\\./, // kiro-lb enhancement of Kiro CONTENT_LENGTH_EXCEEDS_THRESHOLD\n];\n\n/**\n * Patterns that indicate non-overflow errors (e.g. rate limiting, server errors).\n * Error messages matching any of these are excluded from overflow detection\n * even if they also match an OVERFLOW_PATTERN.\n *\n * Example: Bedrock formats throttling errors as \"ThrottlingException: Too many tokens,\n * please wait before trying again.\" which would match the /too many tokens/i overflow\n * pattern without this exclusion.\n */\nconst NON_OVERFLOW_PATTERNS = [\n\t/^(Throttling error|Service unavailable):/i, // AWS Bedrock non-overflow errors (human-readable prefixes from formatBedrockError)\n\t/rate limit/i, // Generic rate limiting\n\t/too many requests/i, // Generic HTTP 429 style\n];\n\n/**\n * Cursor's api2.cursor.sh surfaces a context overflow as a bare gRPC\n * `resource_exhausted` end-stream — the same wording its backend uses for\n * quota and poisoned-conversation rejections. Token evidence disambiguates:\n * a request that already streamed or billed tokens overflowed mid-flight,\n * while a zero-token rejection is a quota/conversation failure that must stay\n * on the rate-limit path (the cursor client rotates the conversation id for\n * those and retry handling supplies the backoff).\n */\nconst RESOURCE_EXHAUSTED_PATTERN = /resource.?exhausted/i;\n\n/**\n * Check if an assistant message represents a context overflow error.\n *\n * This handles three cases:\n * 1. Error-based overflow: Most providers return stopReason \"error\" with a\n * specific error message pattern.\n * 2. Silent overflow: Some providers accept overflow requests and return\n * successfully. For these, we check if usage.input exceeds the context window.\n * 3. Length-stop overflow: Xiaomi MiMo can return \"length\" with zero output when\n * the input fills the context window.\n *\n * ## Reliability by Provider\n *\n * **Reliable detection (returns error with detectable message):**\n * - Anthropic: \"prompt is too long: X tokens > Y maximum\" or \"request_too_large\"\n * - OpenAI (Completions & Responses): \"exceeds the context window\", \"exceeds the model's maximum context length of X tokens\", or \"exceeds model's maximum context length (X)\"\n * - Google Gemini: \"input token count exceeds the maximum\"\n * - xAI (Grok): \"maximum prompt length is X but request contains Y\"\n * - Groq: \"reduce the length of the messages\"\n * - Cerebras: 400/413 status code (no body)\n * - Mistral: \"Prompt contains X tokens ... too large for model with Y maximum context length\"\n * - OpenRouter (most backends): \"maximum context length is X tokens\"\n * - OpenRouter/Poolside: \"Input length X exceeds the maximum allowed input length of Y tokens.\"\n * - Together AI: \"The input (X tokens) is longer than the model's context length (Y tokens).\"\n * - llama.cpp: \"exceeds the available context size\"\n * - LM Studio: \"greater than the context length\"\n * - Kimi For Coding: \"exceeded model token limit: X (requested: Y)\"\n * - DS4: \"Prompt has X tokens, but the configured context size is Y tokens\"\n * - DashScope/Qwen: \"Range of input length should be [1, X]\"\n *\n * **Unreliable detection:**\n * - z.ai: Sometimes accepts overflow silently (detectable via usage.input > contextWindow),\n * sometimes returns rate limit errors. Pass contextWindow param to detect silent overflow.\n * - Xiaomi MiMo: Truncates input to fit contextWindow then returns stopReason \"length\" with\n * output=0. Pass contextWindow param to detect via the \"filled context + zero output\" signal.\n * - Ollama: May truncate input silently for some setups, but may also return explicit\n * overflow errors that match the patterns above. Silent truncation still cannot be\n * detected here because we do not know the expected token count.\n *\n * ## Custom Providers\n *\n * If you've added custom models via settings.json, this function may not detect\n * overflow errors from those providers. To add support:\n *\n * 1. Send a request that exceeds the model's context window\n * 2. Check the errorMessage in the response\n * 3. Create a regex pattern that matches the error\n * 4. The pattern should be added to OVERFLOW_PATTERNS in this file, or\n * check the errorMessage yourself before calling this function\n *\n * @param message - The assistant message to check\n * @param contextWindow - Optional context window size for detecting silent overflow (z.ai)\n * @returns true if the message indicates a context overflow\n */\nexport function isContextOverflow(message: AssistantMessage, contextWindow?: number): boolean {\n\t// Case 1: Check error message patterns\n\tif (message.stopReason === \"error\" && message.errorMessage) {\n\t\t// Skip messages matching known non-overflow patterns (e.g. throttling / rate-limit)\n\t\tconst isNonOverflow = NON_OVERFLOW_PATTERNS.some((p) => p.test(message.errorMessage!));\n\t\tif (!isNonOverflow && OVERFLOW_PATTERNS.some((p) => p.test(message.errorMessage!))) {\n\t\t\treturn true;\n\t\t}\n\t\tconst usage = message.usage;\n\t\tconst hasTokenEvidence =\n\t\t\t(usage.totalTokens || usage.input + usage.output + usage.cacheRead + usage.cacheWrite) > 0;\n\t\tif (\n\t\t\t!isNonOverflow &&\n\t\t\thasTokenEvidence &&\n\t\t\tRESOURCE_EXHAUSTED_PATTERN.test(message.errorMessage) &&\n\t\t\t(contextWindow === undefined || contextWindow <= 0 || cursorZeroTokenCount(message) >= contextWindow * 0.5)\n\t\t) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\t// Case 2: Silent overflow (z.ai style) - successful but usage exceeds context\n\tif (contextWindow && message.stopReason === \"stop\") {\n\t\tconst inputTokens = message.usage.input + message.usage.cacheRead;\n\t\tif (inputTokens > contextWindow) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\t// Case 3: Length-stop overflow (Xiaomi MiMo style) - server truncates oversized input\n\t// to fit the context window, leaving no room for output. Returns stopReason \"length\"\n\t// with output=0 and input+cacheRead filling the context window.\n\tif (contextWindow && message.stopReason === \"length\" && message.usage.output === 0) {\n\t\tconst inputTokens = message.usage.input + message.usage.cacheRead;\n\t\tif (inputTokens >= contextWindow * 0.99) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n/**\n * Check whether a length stop ended below the caller or model's intended output limit.\n * Such responses may be caused by context pressure or provider-side truncation, so callers\n * can make one bounded compact-and-retry attempt. `desiredMaxOutput` must be the original\n * limit before any context-based clamping.\n */\nexport function isRecoverableLength(message: AssistantMessage, desiredMaxOutput: number): boolean {\n\treturn message.stopReason === \"length\" && desiredMaxOutput > 0 && message.usage.output < desiredMaxOutput;\n}\n\n/**\n * Get the overflow patterns for testing purposes.\n */\nexport function getOverflowPatterns(): RegExp[] {\n\treturn [...OVERFLOW_PATTERNS];\n}\n\nfunction cursorZeroTokenCount(message: {\n\tusage?: { input?: number; output?: number; cacheRead?: number; cacheWrite?: number; totalTokens?: number };\n}): number {\n\tconst usage = message.usage;\n\tif (!usage) return 0;\n\treturn (\n\t\tusage.totalTokens || (usage.input ?? 0) + (usage.output ?? 0) + (usage.cacheRead ?? 0) + (usage.cacheWrite ?? 0)\n\t);\n}\n\nexport function isCursorPayloadResourceExhausted(\n\tmessage: {\n\t\tstopReason?: string;\n\t\terrorMessage?: string;\n\t\tusage?: { input?: number; output?: number; cacheRead?: number; cacheWrite?: number; totalTokens?: number };\n\t},\n\t_estimateTokens: number,\n): boolean {\n\tif (message.stopReason !== \"error\" || !/resource.?exhausted/i.test(message.errorMessage || \"\")) {\n\t\treturn false;\n\t}\n\treturn !(cursorZeroTokenCount(message) > 0);\n}\n\n/**\n * Detects Cursor's verified usage-pool exhaustion signature: a token-bearing\n * `resource_exhausted` error while the conversation is well below the model\n * context window.\n */\nexport function isCursorQuotaResourceExhausted(\n\tmessage: {\n\t\tstopReason?: string;\n\t\terrorMessage?: string;\n\t\tusage?: { input?: number; output?: number; cacheRead?: number; cacheWrite?: number; totalTokens?: number };\n\t},\n\tcontextWindow: number,\n): boolean {\n\tconst tokens = cursorZeroTokenCount(message);\n\treturn (\n\t\tmessage.stopReason === \"error\" &&\n\t\tRESOURCE_EXHAUSTED_PATTERN.test(message.errorMessage || \"\") &&\n\t\tcontextWindow > 0 &&\n\t\ttokens > 0 &&\n\t\ttokens < contextWindow * 0.5\n\t);\n}\n\nexport function isCursorZeroTokenResourceExhausted(message: {\n\tstopReason?: string;\n\terrorMessage?: string;\n\tusage?: { input?: number; output?: number; cacheRead?: number; cacheWrite?: number; totalTokens?: number };\n}): boolean {\n\tif (message.stopReason !== \"error\" || !/resource.?exhausted/i.test(message.errorMessage || \"\")) {\n\t\treturn false;\n\t}\n\treturn !(cursorZeroTokenCount(message) > 0);\n}\n\nexport function shouldSkipProviderFallbackForCursorZeroRe(options: { sameModelRemint?: boolean } | undefined): boolean {\n\treturn options?.sameModelRemint === true;\n}\n\nexport function shouldRetryOverflowWithoutCompact(compacted: boolean, errorMessage: string): boolean {\n\tif (compacted) return false;\n\treturn /Nothing to compact/i.test(errorMessage || \"\");\n}\n\nexport function cursorOverflowCompactionSettings<T extends { keepRecentTokens?: number; restorationEnabled?: boolean }>(\n\tsettings: T,\n\tprovider: string | undefined,\n\treason: string | undefined,\n): T {\n\tif (reason !== \"overflow\") return settings;\n\tif (provider !== \"cursor\" && provider !== \"cursor-cli-oauth\") return settings;\n\treturn { ...settings, keepRecentTokens: 0, restorationEnabled: false };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"overflow.js","sourceRoot":"","sources":["../../src/utils/overflow.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,MAAM,iBAAiB,GAAG;IACzB,6BAA6B,EAAE,qEAAqE;IACpG,qBAAqB,EAAE,2BAA2B;IAClD,oBAAoB,EAAE,kDAAkD;IACxE,wCAAwC,EAAE,iBAAiB;IAC3D,yDAAyD,EAAE,uCAAuC;IAClG,4FAA4F,EAAE,sCAAsC;IACpI,yCAAyC,EAAE,kBAAkB;IAC7D,+BAA+B,EAAE,aAAa;IAC9C,oCAAoC,EAAE,OAAO;IAC7C,uCAAuC,EAAE,6BAA6B;IACtE,kEAAkE,EAAE,sBAAsB;IAC1F,iFAAiF,EAAE,cAAc;IACjG,2BAA2B,EAAE,iBAAiB;IAC9C,qCAAqC,EAAE,mBAAmB;IAC1D,kCAAkC,EAAE,YAAY;IAChD,+BAA+B,EAAE,UAAU;IAC3C,6BAA6B,EAAE,kBAAkB;IACjD,sDAAsD,EAAE,UAAU;IAClE,+EAA+E,EAAE,aAAa;IAC9F,gCAAgC,EAAE,yDAAyD;IAC3F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AG,aAAa,GAAG,GAAG,CAC5B,CAAC;AACH,CAAC;AAED,MAAM,UAAU,kCAAkC,CAAC,OAIlD;IACA,IAAI,OAAO,CAAC,UAAU,KAAK,OAAO,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,IAAI,EAAE,CAAC,EAAE,CAAC;QAChG,OAAO,KAAK,CAAC;IACd,CAAC;IACD,OAAO,CAAC,CAAC,oBAAoB,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,yCAAyC,CAAC,OAAkD;IAC3G,OAAO,OAAO,EAAE,eAAe,KAAK,IAAI,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,iCAAiC,CAAC,SAAkB,EAAE,YAAoB;IACzF,IAAI,SAAS;QAAE,OAAO,KAAK,CAAC;IAC5B,OAAO,qBAAqB,CAAC,IAAI,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;AACvD,CAAC;AAED,MAAM,UAAU,gCAAgC,CAC/C,QAAW,EACX,QAA4B,EAC5B,MAA0B;IAE1B,IAAI,MAAM,KAAK,UAAU;QAAE,OAAO,QAAQ,CAAC;IAC3C,IAAI,QAAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,kBAAkB;QAAE,OAAO,QAAQ,CAAC;IAC9E,OAAO,EAAE,GAAG,QAAQ,EAAE,gBAAgB,EAAE,CAAC,EAAE,kBAAkB,EAAE,KAAK,EAAE,CAAC;AACxE,CAAC","sourcesContent":["import type { AssistantMessage } from \"../types.ts\";\n\n/**\n * Regex patterns to detect context overflow errors from different providers.\n *\n * These patterns match error messages returned when the input exceeds\n * the model's context window.\n *\n * Provider-specific patterns (with example error messages):\n *\n * - Anthropic: \"prompt is too long: 213462 tokens > 200000 maximum\"\n * - Anthropic: \"413 {\\\"error\\\":{\\\"type\\\":\\\"request_too_large\\\",\\\"message\\\":\\\"Request exceeds the maximum size\\\"}}\"\n * - OpenAI: \"Your input exceeds the context window of this model\"\n * - OpenAI: \"Your input exceeds the model's context window\" / \"exceeds this model's context window\"\n * - OpenAI/LiteLLM: \"Requested token count exceeds the model's maximum context length of 131072 tokens\"\n * - OpenAI-compatible: \"Input length (265330) exceeds model's maximum context length (262144).\"\n * - Google: \"The input token count (1196265) exceeds the maximum number of tokens allowed (1048575)\"\n * - xAI: \"This model's maximum prompt length is 131072 but the request contains 537812 tokens\"\n * - Groq: \"Please reduce the length of the messages or completion\"\n * - OpenRouter: \"This endpoint's maximum context length is X tokens. However, you requested about Y tokens\"\n * - OpenRouter/Poolside: \"Input length X exceeds the maximum allowed input length of Y tokens.\"\n * - Together AI: \"The input (X tokens) is longer than the model's context length (Y tokens).\"\n * - llama.cpp: \"the request exceeds the available context size, try increasing it\"\n * - LM Studio: \"tokens to keep from the initial prompt is greater than the context length\"\n * - GitHub Copilot: \"prompt token count of X exceeds the limit of Y\"\n * - MiniMax: \"invalid params, context window exceeds limit\"\n * - Kimi For Coding: \"Your request exceeded model token limit: X (requested: Y)\"\n * - DS4: \"Prompt has X tokens, but the configured context size is Y tokens\"\n * - Cerebras: \"400/413 status code (no body)\"\n * - Gateways: \"413 Request body too large\" / \"Request Entity Too Large\" / \"Payload Too Large\" (byte-size overflow)\n * - kiro-lb gateways: \"Request payload is 1095225 bytes, over the 1085435 byte limit Kiro accepts.\" / \"Request payload is N tokens, over the M token limit Kiro accepts.\" (HTTP 400 local payload guard)\n * - Kiro upstream via kiro-lb: \"Model context limit reached. Conversation size exceeds model capacity.\" (CONTENT_LENGTH_EXCEEDS_THRESHOLD token overflow)\n * - Mistral: \"Prompt contains X tokens ... too large for model with Y maximum context length\"\n * - z.ai: Does NOT error, accepts overflow silently - handled via usage.input > contextWindow\n * - Xiaomi MiMo: Truncates input to fill contextWindow exactly, then returns finish_reason \"length\"\n * with output=0 (no room left to generate). Detected via stopReason \"length\" + zero output +\n * input filling the context window.\n * - DashScope/Qwen: \"Range of input length should be [1, X]\" (HTTP 400 invalid_parameter_error)\n * - Ollama: Some deployments truncate silently, others return errors like \"prompt too long; exceeded max context length by X tokens\"\n * - pi-ai pre-flight guard (api/context-room.ts): \"Context window exhausted: the conversation is estimated at X of Y tokens, ...\" - raised before any provider call\n */\nconst OVERFLOW_PATTERNS = [\n\t/^Context window exhausted: /, // pi-ai pre-flight guard: no answer room left, provider never called\n\t/prompt is too long/i, // Anthropic token overflow\n\t/request_too_large/i, // Anthropic request byte-size overflow (HTTP 413)\n\t/input is too long for requested model/i, // Amazon Bedrock\n\t/exceeds (?:(?:the|this) )?(?:model'?s )?context window/i, // OpenAI (Completions & Responses API)\n\t/exceeds (?:the )?(?:model'?s )?maximum context length(?: of [\\d,]+ tokens?|\\s*\\([\\d,]+\\))/i, // OpenAI-compatible proxies (LiteLLM)\n\t/input token count.*exceeds the maximum/i, // Google (Gemini)\n\t/maximum prompt length is \\d+/i, // xAI (Grok)\n\t/reduce the length of the messages/i, // Groq\n\t/maximum context length is \\d+ tokens/i, // OpenRouter (most backends)\n\t/exceeds (?:the )?maximum allowed input length of [\\d,]+ tokens?/i, // OpenRouter/Poolside\n\t/input \\(\\d+ tokens\\) is longer than the model'?s context length \\(\\d+ tokens\\)/i, // Together AI\n\t/exceeds the limit of \\d+/i, // GitHub Copilot\n\t/exceeds the available context size/i, // llama.cpp server\n\t/greater than the context length/i, // LM Studio\n\t/context window exceeds limit/i, // MiniMax\n\t/exceeded model token limit/i, // Kimi For Coding\n\t/too large for model with \\d+ maximum context length/i, // Mistral\n\t/prompt has [\\d,]+ tokens?, but the configured context size is [\\d,]+ tokens?/i, // DS4 server\n\t/model_context_window_exceeded/i, // z.ai non-standard finish_reason surfaced as error text\n\t/prompt too long; exceeded (?:max )?context length/i, // Ollama explicit overflow error\n\t/range of input length should be/i, // DashScope / Qwen Token Plan\n\t/context[_ ]length[_ ]exceeded/i, // Generic fallback\n\t/too many tokens/i, // Generic fallback\n\t/token limit exceeded/i, // Generic fallback\n\t/^4(?:00|13)\\s*(?:status code)?\\s*\\(no body\\)/i, // Cerebras: 400/413 with no body\n\t/(?:request[ _])?(?:body|entity|payload)[_ ]too[_ ]large/i, // Gateway HTTP 413 byte-size rejections (\"Request body too large\", \"Request Entity Too Large\", \"body_too_large\", \"Payload Too Large\"). Substring-anchored by design (JSON bodies lack an adjacent status code); a non-context size rejection (e.g. an oversized image) can over-match, which costs one bounded shrink-retry, never a wedge.\n\t/Request payload is \\d+ (?:bytes, over the \\d+ byte|tokens, over the \\d+ token) limit Kiro accepts\\./, // kiro-lb local byte/token payload guard (HTTP 400; Anthropic uses invalid_request_error, OpenAI uses detail).\n\t/Model context limit reached\\. Conversation size exceeds model capacity\\./, // kiro-lb enhancement of Kiro CONTENT_LENGTH_EXCEEDS_THRESHOLD\n];\n\n/**\n * Patterns that indicate non-overflow errors (e.g. rate limiting, server errors).\n * Error messages matching any of these are excluded from overflow detection\n * even if they also match an OVERFLOW_PATTERN.\n *\n * Example: Bedrock formats throttling errors as \"ThrottlingException: Too many tokens,\n * please wait before trying again.\" which would match the /too many tokens/i overflow\n * pattern without this exclusion. Token-quota / TPM messages such as \"Too many tokens\n * per minute\" or \"This request exceeds the limit of 30000 tokens per minute\" similarly\n * match generic overflow fallbacks and must stay on the rate-limit path.\n */\nconst NON_OVERFLOW_PATTERNS = [\n\t/^(Throttling error|Service unavailable):/i, // AWS Bedrock non-overflow errors (human-readable prefixes from formatBedrockError)\n\t/rate limit/i, // Generic rate limiting\n\t/too many requests/i, // Generic HTTP 429 style\n\t/tokens per (?:min|minute|hour|day)/i, // Token-quota windows (TPM/TPH/TPD), not context size\n\t/\\bTPM\\b/i, // Tokens-per-minute abbreviation\n\t/\\bRPM\\b/i, // Requests-per-minute abbreviation\n\t/quota exceeded/i, // Provider quota, not context window\n\t/retry (?:after|in) \\d/i, // Retry-after rate-limit wording\n\t/^429\\b/, // HTTP 429 prefix\n\t/status code 429/i, // HTTP 429 mentioned mid-message\n\t/overloaded/i, // Provider capacity, not context size\n];\n\n/**\n * Cursor's api2.cursor.sh surfaces a context overflow as a bare gRPC\n * `resource_exhausted` end-stream — the same wording its backend uses for\n * quota and poisoned-conversation rejections. Token evidence disambiguates:\n * a request that already streamed or billed tokens overflowed mid-flight,\n * while a zero-token rejection is a quota/conversation failure that must stay\n * on the rate-limit path (the cursor client rotates the conversation id for\n * those and retry handling supplies the backoff).\n */\nconst RESOURCE_EXHAUSTED_PATTERN = /resource.?exhausted/i;\n\n/**\n * Check if an assistant message represents a context overflow error.\n *\n * This handles three cases:\n * 1. Error-based overflow: Most providers return stopReason \"error\" with a\n * specific error message pattern.\n * 2. Silent overflow: Some providers accept overflow requests and return\n * successfully. For these, we check if usage.input exceeds the context window.\n * 3. Length-stop overflow: Xiaomi MiMo can return \"length\" with zero output when\n * the input fills the context window.\n *\n * ## Reliability by Provider\n *\n * **Reliable detection (returns error with detectable message):**\n * - Anthropic: \"prompt is too long: X tokens > Y maximum\" or \"request_too_large\"\n * - OpenAI (Completions & Responses): \"exceeds the context window\", \"exceeds the model's context window\", \"exceeds this model's context window\", \"exceeds the model's maximum context length of X tokens\", or \"exceeds model's maximum context length (X)\"\n * - Google Gemini: \"input token count exceeds the maximum\"\n * - xAI (Grok): \"maximum prompt length is X but request contains Y\"\n * - Groq: \"reduce the length of the messages\"\n * - Cerebras: 400/413 status code (no body)\n * - Mistral: \"Prompt contains X tokens ... too large for model with Y maximum context length\"\n * - OpenRouter (most backends): \"maximum context length is X tokens\"\n * - OpenRouter/Poolside: \"Input length X exceeds the maximum allowed input length of Y tokens.\"\n * - Together AI: \"The input (X tokens) is longer than the model's context length (Y tokens).\"\n * - llama.cpp: \"exceeds the available context size\"\n * - LM Studio: \"greater than the context length\"\n * - Kimi For Coding: \"exceeded model token limit: X (requested: Y)\"\n * - DS4: \"Prompt has X tokens, but the configured context size is Y tokens\"\n * - DashScope/Qwen: \"Range of input length should be [1, X]\"\n *\n * **Unreliable detection:**\n * - z.ai: Sometimes accepts overflow silently (detectable via usage.input > contextWindow),\n * sometimes returns rate limit errors. Pass contextWindow param to detect silent overflow.\n * - Xiaomi MiMo: Truncates input to fit contextWindow then returns stopReason \"length\" with\n * output=0. Pass contextWindow param to detect via the \"filled context + zero output\" signal.\n * - Ollama: May truncate input silently for some setups, but may also return explicit\n * overflow errors that match the patterns above. Silent truncation still cannot be\n * detected here because we do not know the expected token count.\n *\n * ## Custom Providers\n *\n * If you've added custom models via settings.json, this function may not detect\n * overflow errors from those providers. To add support:\n *\n * 1. Send a request that exceeds the model's context window\n * 2. Check the errorMessage in the response\n * 3. Create a regex pattern that matches the error\n * 4. The pattern should be added to OVERFLOW_PATTERNS in this file, or\n * check the errorMessage yourself before calling this function\n *\n * @param message - The assistant message to check\n * @param contextWindow - Optional context window size for detecting silent overflow (z.ai)\n * @returns true if the message indicates a context overflow\n */\nexport function isContextOverflow(message: AssistantMessage, contextWindow?: number): boolean {\n\t// Case 1: Check error message patterns\n\tif (message.stopReason === \"error\" && message.errorMessage) {\n\t\t// Skip messages matching known non-overflow patterns (e.g. throttling / rate-limit)\n\t\tconst isNonOverflow = NON_OVERFLOW_PATTERNS.some((p) => p.test(message.errorMessage!));\n\t\tif (!isNonOverflow && OVERFLOW_PATTERNS.some((p) => p.test(message.errorMessage!))) {\n\t\t\treturn true;\n\t\t}\n\t\tconst usage = message.usage;\n\t\tconst hasTokenEvidence =\n\t\t\t(usage.totalTokens || usage.input + usage.output + usage.cacheRead + usage.cacheWrite) > 0;\n\t\tif (\n\t\t\t!isNonOverflow &&\n\t\t\thasTokenEvidence &&\n\t\t\tRESOURCE_EXHAUSTED_PATTERN.test(message.errorMessage) &&\n\t\t\t(contextWindow === undefined || contextWindow <= 0 || cursorZeroTokenCount(message) >= contextWindow * 0.5)\n\t\t) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\t// Case 2: Silent overflow (z.ai style) - successful but usage exceeds context\n\tif (contextWindow && message.stopReason === \"stop\") {\n\t\tconst inputTokens = message.usage.input + message.usage.cacheRead;\n\t\tif (inputTokens > contextWindow) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\t// Case 3: Length-stop overflow (Xiaomi MiMo style) - server truncates oversized input\n\t// to fit the context window, leaving no room for output. Returns stopReason \"length\"\n\t// with output=0 and input+cacheRead filling the context window.\n\tif (contextWindow && message.stopReason === \"length\" && message.usage.output === 0) {\n\t\tconst inputTokens = message.usage.input + message.usage.cacheRead;\n\t\tif (inputTokens >= contextWindow * 0.99) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n/**\n * Check whether a length stop ended below the caller or model's intended output limit.\n * Such responses may be caused by context pressure or provider-side truncation, so callers\n * can make one bounded compact-and-retry attempt. `desiredMaxOutput` must be the original\n * limit before any context-based clamping.\n */\nexport function isRecoverableLength(message: AssistantMessage, desiredMaxOutput: number): boolean {\n\treturn message.stopReason === \"length\" && desiredMaxOutput > 0 && message.usage.output < desiredMaxOutput;\n}\n\n/**\n * Get the overflow patterns for testing purposes.\n */\nexport function getOverflowPatterns(): RegExp[] {\n\treturn [...OVERFLOW_PATTERNS];\n}\n\nfunction cursorZeroTokenCount(message: {\n\tusage?: { input?: number; output?: number; cacheRead?: number; cacheWrite?: number; totalTokens?: number };\n}): number {\n\tconst usage = message.usage;\n\tif (!usage) return 0;\n\treturn (\n\t\tusage.totalTokens || (usage.input ?? 0) + (usage.output ?? 0) + (usage.cacheRead ?? 0) + (usage.cacheWrite ?? 0)\n\t);\n}\n\nexport function isCursorPayloadResourceExhausted(\n\tmessage: {\n\t\tstopReason?: string;\n\t\terrorMessage?: string;\n\t\tusage?: { input?: number; output?: number; cacheRead?: number; cacheWrite?: number; totalTokens?: number };\n\t},\n\t_estimateTokens: number,\n): boolean {\n\tif (message.stopReason !== \"error\" || !/resource.?exhausted/i.test(message.errorMessage || \"\")) {\n\t\treturn false;\n\t}\n\treturn !(cursorZeroTokenCount(message) > 0);\n}\n\n/**\n * Detects Cursor's verified usage-pool exhaustion signature: a token-bearing\n * `resource_exhausted` error while the conversation is well below the model\n * context window.\n */\nexport function isCursorQuotaResourceExhausted(\n\tmessage: {\n\t\tstopReason?: string;\n\t\terrorMessage?: string;\n\t\tusage?: { input?: number; output?: number; cacheRead?: number; cacheWrite?: number; totalTokens?: number };\n\t},\n\tcontextWindow: number,\n): boolean {\n\tconst tokens = cursorZeroTokenCount(message);\n\treturn (\n\t\tmessage.stopReason === \"error\" &&\n\t\tRESOURCE_EXHAUSTED_PATTERN.test(message.errorMessage || \"\") &&\n\t\tcontextWindow > 0 &&\n\t\ttokens > 0 &&\n\t\ttokens < contextWindow * 0.5\n\t);\n}\n\nexport function isCursorZeroTokenResourceExhausted(message: {\n\tstopReason?: string;\n\terrorMessage?: string;\n\tusage?: { input?: number; output?: number; cacheRead?: number; cacheWrite?: number; totalTokens?: number };\n}): boolean {\n\tif (message.stopReason !== \"error\" || !/resource.?exhausted/i.test(message.errorMessage || \"\")) {\n\t\treturn false;\n\t}\n\treturn !(cursorZeroTokenCount(message) > 0);\n}\n\nexport function shouldSkipProviderFallbackForCursorZeroRe(options: { sameModelRemint?: boolean } | undefined): boolean {\n\treturn options?.sameModelRemint === true;\n}\n\nexport function shouldRetryOverflowWithoutCompact(compacted: boolean, errorMessage: string): boolean {\n\tif (compacted) return false;\n\treturn /Nothing to compact/i.test(errorMessage || \"\");\n}\n\nexport function cursorOverflowCompactionSettings<T extends { keepRecentTokens?: number; restorationEnabled?: boolean }>(\n\tsettings: T,\n\tprovider: string | undefined,\n\treason: string | undefined,\n): T {\n\tif (reason !== \"overflow\") return settings;\n\tif (provider !== \"cursor\" && provider !== \"cursor-cli-oauth\") return settings;\n\treturn { ...settings, keepRecentTokens: 0, restorationEnabled: false };\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AssistantMessage } from "../types.ts";
|
|
1
|
+
import type { AssistantMessage, Model } from "../types.ts";
|
|
2
2
|
export declare const SERVER_FALLBACK_ABORTED_DIAGNOSTIC = "server_fallback_aborted";
|
|
3
3
|
export declare const BILLING_INCOMPLETE_DIAGNOSTIC = "billing_incomplete_after_client_abort";
|
|
4
4
|
export interface ServerFallbackReceipt {
|
|
@@ -20,6 +20,7 @@ export declare function parseServerFallbackReceipt(block: unknown): ServerFallba
|
|
|
20
20
|
*/
|
|
21
21
|
export declare function parseStickyFallbackReceipt(usage: unknown, requestedModel: string, servedModel?: string): ServerFallbackReceipt | undefined;
|
|
22
22
|
export declare function serverFallbackRefusalExplanation(receipt: ServerFallbackReceipt): string;
|
|
23
|
+
export declare function applyServerFallbackContinuation(message: AssistantMessage, model: Model<"anthropic-messages">, receipt: ServerFallbackReceipt): Model<"anthropic-messages">;
|
|
23
24
|
/**
|
|
24
25
|
* Rewrites an aborted turn into the same shape a pre-output classifier refusal
|
|
25
26
|
* has, so `isClassifierRefusal()` routes it through the caller's fallback chain.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-fallback-receipt.d.ts","sourceRoot":"","sources":["../../src/utils/server-fallback-receipt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"server-fallback-receipt.d.ts","sourceRoot":"","sources":["../../src/utils/server-fallback-receipt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAG3D,eAAO,MAAM,kCAAkC,4BAA4B,CAAC;AAC5E,eAAO,MAAM,6BAA6B,0CAA0C,CAAC;AAErF,MAAM,WAAW,qBAAqB;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACpB;AAWD;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,OAAO,GAAG,qBAAqB,GAAG,SAAS,CAK5F;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CACzC,KAAK,EAAE,OAAO,EACd,cAAc,EAAE,MAAM,EACtB,WAAW,CAAC,EAAE,MAAM,GAClB,qBAAqB,GAAG,SAAS,CAUnC;AAED,wBAAgB,gCAAgC,CAAC,OAAO,EAAE,qBAAqB,GAAG,MAAM,CAEvF;AAED,wBAAgB,+BAA+B,CAC9C,OAAO,EAAE,gBAAgB,EACzB,KAAK,EAAE,KAAK,CAAC,oBAAoB,CAAC,EAClC,OAAO,EAAE,qBAAqB,GAC5B,KAAK,CAAC,oBAAoB,CAAC,CAkB7B;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,qBAAqB,GAAG,IAAI,CAgBxG"}
|
|
@@ -44,6 +44,22 @@ export function parseStickyFallbackReceipt(usage, requestedModel, servedModel) {
|
|
|
44
44
|
export function serverFallbackRefusalExplanation(receipt) {
|
|
45
45
|
return `Server-side fallback (${receipt.from} -> ${receipt.to}) aborted by client policy`;
|
|
46
46
|
}
|
|
47
|
+
export function applyServerFallbackContinuation(message, model, receipt) {
|
|
48
|
+
// Keep source indices stable for stream projections while making abandoned
|
|
49
|
+
// client calls audit-only before the agent can execute the completed message.
|
|
50
|
+
for (const [index, block] of message.content.entries()) {
|
|
51
|
+
if (block.type === "toolCall") {
|
|
52
|
+
message.content[index] = { type: "providerNative", subtype: "discarded_tool_call", raw: block };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
message.model = receipt.to;
|
|
56
|
+
const fallback = model.compat?.allowedFallbackModels?.find((candidate) => typeof candidate !== "string" && candidate.provider === model.provider && candidate.model === receipt.to);
|
|
57
|
+
return {
|
|
58
|
+
...model,
|
|
59
|
+
id: receipt.to,
|
|
60
|
+
cost: fallback && typeof fallback !== "string" ? fallback.cost : model.cost,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
47
63
|
/**
|
|
48
64
|
* Rewrites an aborted turn into the same shape a pre-output classifier refusal
|
|
49
65
|
* has, so `isClassifierRefusal()` routes it through the caller's fallback chain.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server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C,OAAO,EAAE;QACzC,IAAI,EAAE,kCAAkC;QACxC,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;QACrB,OAAO,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE,EAAE;KAC/C,CAAC,CAAC;IACH,gCAAgC,CAAC,OAAO,EAAE;QACzC,IAAI,EAAE,6BAA6B;QACnC,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;QACrB,OAAO,EAAE,EAAE,MAAM,EAAE,wDAAwD,EAAE;KAC7E,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { AssistantMessage } from \"../types.ts\";\nimport { appendAssistantMessageDiagnostic } from \"./diagnostics.ts\";\n\nexport const SERVER_FALLBACK_ABORTED_DIAGNOSTIC = \"server_fallback_aborted\";\nexport const BILLING_INCOMPLETE_DIAGNOSTIC = \"billing_incomplete_after_client_abort\";\n\nexport interface ServerFallbackReceipt {\n\treadonly from: string;\n\treadonly to: string;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction readModel(value: unknown): string | undefined {\n\tif (!isRecord(value)) return undefined;\n\treturn typeof value.model === \"string\" && value.model.length > 0 ? value.model : undefined;\n}\n\n/**\n * Anthropic marks a classifier handoff with `{type:\"fallback\", from:{model}, to:{model}}`\n * (`server-side-fallback-*` betas). Returns undefined for anything else, so an\n * unrelated or malformed provider-native block falls through to normal handling.\n */\nexport function parseServerFallbackReceipt(block: unknown): ServerFallbackReceipt | undefined {\n\tif (!isRecord(block) || block.type !== \"fallback\") return undefined;\n\tconst from = readModel(block.from);\n\tconst to = readModel(block.to);\n\treturn from !== undefined && to !== undefined ? { from, to } : undefined;\n}\n\n/**\n * Sticky routing serves later turns of a fallen-back conversation from the\n * substitute model with no `fallback` block at all; a `fallback_message` entry\n * in `usage.iterations` is the documented signal. A served-model string\n * comparison is deliberately NOT used: gateways and Bedrock-style endpoints\n * rewrite model ids, so a mismatch is not evidence of a fallback.\n */\nexport function parseStickyFallbackReceipt(\n\tusage: unknown,\n\trequestedModel: string,\n\tservedModel?: string,\n): ServerFallbackReceipt | undefined {\n\tif (!isRecord(usage) || !Array.isArray(usage.iterations)) return undefined;\n\tfor (let index = usage.iterations.length - 1; index >= 0; index--) {\n\t\tconst entry: unknown = usage.iterations[index];\n\t\tif (!isRecord(entry) || entry.type !== \"fallback_message\") continue;\n\t\tconst entryModel = typeof entry.model === \"string\" && entry.model.length > 0 ? entry.model : undefined;\n\t\tconst to = entryModel ?? servedModel;\n\t\treturn to !== undefined ? { from: requestedModel, to } : undefined;\n\t}\n\treturn undefined;\n}\n\nexport function serverFallbackRefusalExplanation(receipt: ServerFallbackReceipt): string {\n\treturn `Server-side fallback (${receipt.from} -> ${receipt.to}) aborted by client policy`;\n}\n\n/**\n * Rewrites an aborted turn into the same shape a pre-output classifier refusal\n * has, so `isClassifierRefusal()` routes it through the caller's fallback chain.\n * Content is dropped: the substitute model's partial output was never requested,\n * and replaying a half-turn containing a fallback marker breaks Anthropic replay.\n */\nexport function applyServerFallbackAbort(message: AssistantMessage, receipt: ServerFallbackReceipt): void {\n\tconst explanation = serverFallbackRefusalExplanation(receipt);\n\tmessage.content = [];\n\tmessage.stopReason = \"error\";\n\tmessage.stopDetails = { type: \"refusal\", explanation };\n\tmessage.errorMessage = explanation;\n\tappendAssistantMessageDiagnostic(message, {\n\t\ttype: SERVER_FALLBACK_ABORTED_DIAGNOSTIC,\n\t\ttimestamp: Date.now(),\n\t\tdetails: { from: receipt.from, to: receipt.to },\n\t});\n\tappendAssistantMessageDiagnostic(message, {\n\t\ttype: BILLING_INCOMPLETE_DIAGNOSTIC,\n\t\ttimestamp: Date.now(),\n\t\tdetails: { reason: \"per-attempt usage does not arrive after a client abort\" },\n\t});\n}\n"]}
|
|
1
|
+
{"version":3,"file":"server-fallback-receipt.js","sourceRoot":"","sources":["../../src/utils/server-fallback-receipt.ts"],"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C,CAAC;AACJ,CAAC","sourcesContent":["import type { AssistantMessage, Model } from \"../types.ts\";\nimport { appendAssistantMessageDiagnostic } from \"./diagnostics.ts\";\n\nexport const SERVER_FALLBACK_ABORTED_DIAGNOSTIC = \"server_fallback_aborted\";\nexport const BILLING_INCOMPLETE_DIAGNOSTIC = \"billing_incomplete_after_client_abort\";\n\nexport interface ServerFallbackReceipt {\n\treadonly from: string;\n\treadonly to: string;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction readModel(value: unknown): string | undefined {\n\tif (!isRecord(value)) return undefined;\n\treturn typeof value.model === \"string\" && value.model.length > 0 ? value.model : undefined;\n}\n\n/**\n * Anthropic marks a classifier handoff with `{type:\"fallback\", from:{model}, to:{model}}`\n * (`server-side-fallback-*` betas). Returns undefined for anything else, so an\n * unrelated or malformed provider-native block falls through to normal handling.\n */\nexport function parseServerFallbackReceipt(block: unknown): ServerFallbackReceipt | undefined {\n\tif (!isRecord(block) || block.type !== \"fallback\") return undefined;\n\tconst from = readModel(block.from);\n\tconst to = readModel(block.to);\n\treturn from !== undefined && to !== undefined ? { from, to } : undefined;\n}\n\n/**\n * Sticky routing serves later turns of a fallen-back conversation from the\n * substitute model with no `fallback` block at all; a `fallback_message` entry\n * in `usage.iterations` is the documented signal. A served-model string\n * comparison is deliberately NOT used: gateways and Bedrock-style endpoints\n * rewrite model ids, so a mismatch is not evidence of a fallback.\n */\nexport function parseStickyFallbackReceipt(\n\tusage: unknown,\n\trequestedModel: string,\n\tservedModel?: string,\n): ServerFallbackReceipt | undefined {\n\tif (!isRecord(usage) || !Array.isArray(usage.iterations)) return undefined;\n\tfor (let index = usage.iterations.length - 1; index >= 0; index--) {\n\t\tconst entry: unknown = usage.iterations[index];\n\t\tif (!isRecord(entry) || entry.type !== \"fallback_message\") continue;\n\t\tconst entryModel = typeof entry.model === \"string\" && entry.model.length > 0 ? entry.model : undefined;\n\t\tconst to = entryModel ?? servedModel;\n\t\treturn to !== undefined ? { from: requestedModel, to } : undefined;\n\t}\n\treturn undefined;\n}\n\nexport function serverFallbackRefusalExplanation(receipt: ServerFallbackReceipt): string {\n\treturn `Server-side fallback (${receipt.from} -> ${receipt.to}) aborted by client policy`;\n}\n\nexport function applyServerFallbackContinuation(\n\tmessage: AssistantMessage,\n\tmodel: Model<\"anthropic-messages\">,\n\treceipt: ServerFallbackReceipt,\n): Model<\"anthropic-messages\"> {\n\t// Keep source indices stable for stream projections while making abandoned\n\t// client calls audit-only before the agent can execute the completed message.\n\tfor (const [index, block] of message.content.entries()) {\n\t\tif (block.type === \"toolCall\") {\n\t\t\tmessage.content[index] = { type: \"providerNative\", subtype: \"discarded_tool_call\", raw: block };\n\t\t}\n\t}\n\tmessage.model = receipt.to;\n\tconst fallback = model.compat?.allowedFallbackModels?.find(\n\t\t(candidate) =>\n\t\t\ttypeof candidate !== \"string\" && candidate.provider === model.provider && candidate.model === receipt.to,\n\t);\n\treturn {\n\t\t...model,\n\t\tid: receipt.to,\n\t\tcost: fallback && typeof fallback !== \"string\" ? fallback.cost : model.cost,\n\t};\n}\n\n/**\n * Rewrites an aborted turn into the same shape a pre-output classifier refusal\n * has, so `isClassifierRefusal()` routes it through the caller's fallback chain.\n * Content is dropped: the substitute model's partial output was never requested,\n * and replaying a half-turn containing a fallback marker breaks Anthropic replay.\n */\nexport function applyServerFallbackAbort(message: AssistantMessage, receipt: ServerFallbackReceipt): void {\n\tconst explanation = serverFallbackRefusalExplanation(receipt);\n\tmessage.content = [];\n\tmessage.stopReason = \"error\";\n\tmessage.stopDetails = { type: \"refusal\", explanation };\n\tmessage.errorMessage = explanation;\n\tappendAssistantMessageDiagnostic(message, {\n\t\ttype: SERVER_FALLBACK_ABORTED_DIAGNOSTIC,\n\t\ttimestamp: Date.now(),\n\t\tdetails: { from: receipt.from, to: receipt.to },\n\t});\n\tappendAssistantMessageDiagnostic(message, {\n\t\ttype: BILLING_INCOMPLETE_DIAGNOSTIC,\n\t\ttimestamp: Date.now(),\n\t\tdetails: { reason: \"per-attempt usage does not arrive after a client abort\" },\n\t});\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@earendil-works/pi-ai",
|
|
3
|
-
"version": "2026.9.
|
|
3
|
+
"version": "2026.9.8",
|
|
4
4
|
"description": "Unified LLM API with automatic model discovery and provider configuration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"dependencies": {
|
|
77
77
|
"@anthropic-ai/sdk": "0.123.0",
|
|
78
78
|
"@aws-sdk/client-bedrock-runtime": "3.1116.0",
|
|
79
|
-
"@earendil-works/pi-telemetry": "npm:@code-yeongyu/senpi-telemetry@2026.9.
|
|
79
|
+
"@earendil-works/pi-telemetry": "npm:@code-yeongyu/senpi-telemetry@2026.9.8",
|
|
80
80
|
"@google/genai": "2.18.0",
|
|
81
81
|
"@smithy/node-http-handler": "4.11.3",
|
|
82
82
|
"http-proxy-agent": "9.1.0",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@code-yeongyu/senpi",
|
|
3
|
-
"version": "2026.9.
|
|
3
|
+
"version": "2026.9.8",
|
|
4
4
|
"description": "Coding agent CLI with read, bash, edit, write tools and session management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"piConfig": {
|
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
"qa:app-server": "node scripts/qa-app-server/run-all.mjs"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@earendil-works/pi-agent-core": "npm:@code-yeongyu/senpi-agent-core@2026.9.
|
|
52
|
-
"@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.9.
|
|
53
|
-
"@earendil-works/pi-tui": "npm:@code-yeongyu/senpi-tui@2026.9.
|
|
51
|
+
"@earendil-works/pi-agent-core": "npm:@code-yeongyu/senpi-agent-core@2026.9.8",
|
|
52
|
+
"@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.9.8",
|
|
53
|
+
"@earendil-works/pi-tui": "npm:@code-yeongyu/senpi-tui@2026.9.8",
|
|
54
54
|
"@silvia-odwyer/photon-node": "0.3.4",
|
|
55
55
|
"chalk": "6.0.0",
|
|
56
56
|
"cross-spawn": "7.0.6",
|
|
@@ -70,8 +70,8 @@
|
|
|
70
70
|
"@anthropic-ai/sdk": "0.123.0",
|
|
71
71
|
"@aws-sdk/client-bedrock-runtime": "3.1116.0",
|
|
72
72
|
"@bufbuild/protobuf": "2.14.0",
|
|
73
|
-
"@code-yeongyu/senpi-codemode": "2026.9.
|
|
74
|
-
"@earendil-works/pi-pty": "npm:@code-yeongyu/senpi-pty@2026.9.
|
|
73
|
+
"@code-yeongyu/senpi-codemode": "2026.9.8",
|
|
74
|
+
"@earendil-works/pi-pty": "npm:@code-yeongyu/senpi-pty@2026.9.8",
|
|
75
75
|
"@modelcontextprotocol/sdk": "1.30.0",
|
|
76
76
|
"@mozilla/readability": "0.6.0",
|
|
77
77
|
"@opentelemetry/api": "1.9.1",
|
|
@@ -119,7 +119,7 @@
|
|
|
119
119
|
"@csstools/css-parser-algorithms": "4.0.0",
|
|
120
120
|
"@csstools/css-syntax-patches-for-csstree": "1.1.8",
|
|
121
121
|
"@csstools/css-tokenizer": "4.0.0",
|
|
122
|
-
"@earendil-works/pi-telemetry": "npm:@code-yeongyu/senpi-telemetry@2026.9.
|
|
122
|
+
"@earendil-works/pi-telemetry": "npm:@code-yeongyu/senpi-telemetry@2026.9.8",
|
|
123
123
|
"@exodus/bytes": "1.15.1",
|
|
124
124
|
"@google/genai": "2.18.0",
|
|
125
125
|
"@hono/node-server": "2.1.1",
|