@code-yeongyu/senpi 2026.9.3 → 2026.9.4
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 +75 -0
- package/dist/core/agent-session.d.ts +2 -5
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +32 -29
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/dynamic-prompt/style.js +1 -1
- package/dist/core/dynamic-prompt/style.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/bash-timeout/index.d.ts +1 -1
- package/dist/core/extensions/builtin/bash-timeout/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/bash-timeout/index.js +7 -1
- package/dist/core/extensions/builtin/bash-timeout/index.js.map +1 -1
- package/dist/core/extensions/builtin/bash-timeout/timeout.d.ts +11 -7
- package/dist/core/extensions/builtin/bash-timeout/timeout.d.ts.map +1 -1
- package/dist/core/extensions/builtin/bash-timeout/timeout.js +4 -8
- package/dist/core/extensions/builtin/bash-timeout/timeout.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/auth-lane.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/auth-lane.js +15 -18
- package/dist/core/extensions/builtin/claude-sdk-oauth/auth-lane.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/content-blocks.d.ts +3 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/content-blocks.d.ts.map +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/content-blocks.js +80 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/content-blocks.js.map +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/errors.d.ts +18 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/errors.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/errors.js +57 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/errors.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/guidance.d.ts +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/guidance.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/guidance.js +13 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/guidance.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/oauth-login.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/oauth-login.js +6 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/oauth-login.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/prompt-bridge.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/prompt-bridge.js +2 -23
- package/dist/core/extensions/builtin/claude-sdk-oauth/prompt-bridge.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-binding.d.ts +2 -2
- 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 +30 -24
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-binding.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-continuity.d.ts +2 -0
- 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 +15 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-continuity.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-observability.d.ts +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-observability.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-observability.js +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-observability.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-reattach.d.ts +6 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-reattach.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-reattach.js +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-reattach.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry-pump.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry-pump.js +19 -3
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry-pump.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry-wiring.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry-wiring.js +31 -13
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry-wiring.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry.d.ts +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry.js +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-registry.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 +8 -14
- 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 +23 -6
- package/dist/core/extensions/builtin/claude-sdk-oauth/session-turn-attempt.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream-guidance.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream-guidance.js +4 -2
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream-guidance.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream-protocol.d.ts +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream-protocol.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream.js +13 -6
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/tools.d.ts +11 -3
- package/dist/core/extensions/builtin/claude-sdk-oauth/tools.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/tools.js +12 -3
- package/dist/core/extensions/builtin/claude-sdk-oauth/tools.js.map +1 -1
- package/dist/core/extensions/builtin/eval-only-routing.d.ts +10 -0
- package/dist/core/extensions/builtin/eval-only-routing.d.ts.map +1 -0
- package/dist/core/extensions/builtin/eval-only-routing.js +16 -0
- package/dist/core/extensions/builtin/eval-only-routing.js.map +1 -0
- package/dist/core/extensions/builtin/gpt-account.d.ts +3 -0
- package/dist/core/extensions/builtin/gpt-account.d.ts.map +1 -0
- package/dist/core/extensions/builtin/gpt-account.js +115 -0
- package/dist/core/extensions/builtin/gpt-account.js.map +1 -0
- package/dist/core/extensions/builtin/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/index.js +2 -0
- package/dist/core/extensions/builtin/index.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-5.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-5.js +1 -3
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-5.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-6.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-6.js +1 -11
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-6.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-7.js +2 -2
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-7.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-8.js +3 -3
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-8.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-5.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-5.js +56 -43
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-5.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/execution-tooling.d.ts +4 -15
- package/dist/core/extensions/builtin/prompt-preset/execution-tooling.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/execution-tooling.js +12 -21
- package/dist/core/extensions/builtin/prompt-preset/execution-tooling.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/glm-5-2.d.ts +1 -1
- package/dist/core/extensions/builtin/prompt-preset/glm-5-2.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/glm-5-2.js +2 -11
- package/dist/core/extensions/builtin/prompt-preset/glm-5-2.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/glm-5-3.d.ts +1 -1
- package/dist/core/extensions/builtin/prompt-preset/glm-5-3.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/glm-5-3.js +2 -11
- package/dist/core/extensions/builtin/prompt-preset/glm-5-3.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/glm-5.d.ts +4 -0
- package/dist/core/extensions/builtin/prompt-preset/glm-5.d.ts.map +1 -0
- package/dist/core/extensions/builtin/prompt-preset/glm-5.js +16 -0
- package/dist/core/extensions/builtin/prompt-preset/glm-5.js.map +1 -0
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.d.ts +1 -5
- 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 +1 -6
- 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 +123 -0
- package/dist/core/extensions/builtin/prompt-preset/gpt-6-astra.d.ts.map +1 -0
- package/dist/core/extensions/builtin/prompt-preset/gpt-6-astra.js +202 -0
- package/dist/core/extensions/builtin/prompt-preset/gpt-6-astra.js.map +1 -0
- package/dist/core/extensions/builtin/prompt-preset/gpt-eval-routing.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-eval-routing.js +1 -2
- package/dist/core/extensions/builtin/prompt-preset/gpt-eval-routing.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k3.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k3.js +60 -76
- package/dist/core/extensions/builtin/prompt-preset/kimi-k3.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/presets.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/presets.js +17 -0
- package/dist/core/extensions/builtin/prompt-preset/presets.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/settings.d.ts +1 -1
- package/dist/core/extensions/builtin/prompt-preset/settings.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/settings.js +1 -0
- package/dist/core/extensions/builtin/prompt-preset/settings.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/extension.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/extension.js +5 -2
- package/dist/core/extensions/builtin/terminal/extension.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/prompt.d.ts +13 -2
- package/dist/core/extensions/builtin/terminal/prompt.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/prompt.js +18 -7
- package/dist/core/extensions/builtin/terminal/prompt.js.map +1 -1
- package/dist/core/extensions/builtin/tool-search/native-search.d.ts +1 -1
- package/dist/core/extensions/builtin/tool-search/native-search.d.ts.map +1 -1
- package/dist/core/extensions/builtin/tool-search/native-search.js +1 -1
- package/dist/core/extensions/builtin/tool-search/native-search.js.map +1 -1
- package/dist/core/extensions/builtin/ttsr/detectors/collapse-paragraphs.d.ts +34 -0
- package/dist/core/extensions/builtin/ttsr/detectors/collapse-paragraphs.d.ts.map +1 -0
- package/dist/core/extensions/builtin/ttsr/detectors/collapse-paragraphs.js +121 -0
- package/dist/core/extensions/builtin/ttsr/detectors/collapse-paragraphs.js.map +1 -0
- package/dist/core/extensions/builtin/ttsr/detectors/collapse.d.ts +2 -0
- package/dist/core/extensions/builtin/ttsr/detectors/collapse.d.ts.map +1 -1
- package/dist/core/extensions/builtin/ttsr/detectors/collapse.js +6 -2
- package/dist/core/extensions/builtin/ttsr/detectors/collapse.js.map +1 -1
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +18 -1
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts +0 -4
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +0 -6
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +9 -0
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/connection-handler.d.ts +2 -0
- package/dist/modes/rpc/connection-handler.d.ts.map +1 -1
- package/dist/modes/rpc/connection-handler.js +71 -12
- package/dist/modes/rpc/connection-handler.js.map +1 -1
- package/dist/modes/rpc/custom-capability.d.ts +5 -0
- package/dist/modes/rpc/custom-capability.d.ts.map +1 -1
- package/dist/modes/rpc/custom-capability.js +5 -0
- package/dist/modes/rpc/custom-capability.js.map +1 -1
- package/dist/modes/rpc/login-prompts.d.ts +24 -0
- package/dist/modes/rpc/login-prompts.d.ts.map +1 -0
- package/dist/modes/rpc/login-prompts.js +44 -0
- package/dist/modes/rpc/login-prompts.js.map +1 -0
- package/dist/modes/rpc/media-placeholders.d.ts +49 -0
- package/dist/modes/rpc/media-placeholders.d.ts.map +1 -0
- package/dist/modes/rpc/media-placeholders.js +151 -0
- package/dist/modes/rpc/media-placeholders.js.map +1 -0
- package/dist/modes/rpc/multi-session-host.js +3 -0
- package/dist/modes/rpc/multi-session-host.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +8 -0
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +11 -0
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +23 -1
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js +1 -0
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/modes/rpc/session-command-router.d.ts.map +1 -1
- package/dist/modes/rpc/session-command-router.js +2 -1
- package/dist/modes/rpc/session-command-router.js.map +1 -1
- package/dist/modes/rpc/session-event-fanout.d.ts +13 -2
- package/dist/modes/rpc/session-event-fanout.d.ts.map +1 -1
- package/dist/modes/rpc/session-event-fanout.js +36 -12
- package/dist/modes/rpc/session-event-fanout.js.map +1 -1
- package/dist/modes/rpc/session-event-writer.d.ts +3 -1
- package/dist/modes/rpc/session-event-writer.d.ts.map +1 -1
- package/dist/modes/rpc/session-event-writer.js +23 -13
- package/dist/modes/rpc/session-event-writer.js.map +1 -1
- package/dist/modes/rpc/socket-event-fanout.d.ts +8 -1
- package/dist/modes/rpc/socket-event-fanout.d.ts.map +1 -1
- package/dist/modes/rpc/socket-event-fanout.js +32 -9
- package/dist/modes/rpc/socket-event-fanout.js.map +1 -1
- package/docs/rpc.md +104 -0
- package/docs/settings.md +5 -27
- package/docs/windows.md +1 -1
- package/node_modules/@anthropic-ai/claude-agent-sdk/bridge.d.ts +18 -1
- package/node_modules/@anthropic-ai/claude-agent-sdk/bridge.mjs +155 -106
- package/node_modules/@anthropic-ai/claude-agent-sdk/browser-sdk.js +144 -83
- package/node_modules/@anthropic-ai/claude-agent-sdk/manifest.json +21 -32
- package/node_modules/@anthropic-ai/claude-agent-sdk/manifest.zst.json +25 -36
- package/node_modules/@anthropic-ai/claude-agent-sdk/package.json +2 -2
- package/node_modules/@anthropic-ai/claude-agent-sdk/sdk-tools.d.ts +93 -31
- package/node_modules/@anthropic-ai/claude-agent-sdk/sdk.d.ts +473 -31
- package/node_modules/@anthropic-ai/claude-agent-sdk/sdk.mjs +140 -93
- package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +38 -0
- package/node_modules/@code-yeongyu/senpi-codemode/package.json +4 -4
- package/node_modules/@code-yeongyu/senpi-codemode/src/index.ts +17 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-runtime.js +6 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-shell-capture.d.ts +10 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-shell-capture.js +126 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/prompt/eval-prompt.ts +14 -6
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/eval-tool-options.ts +2 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/eval-tool.ts +1 -0
- package/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
- package/node_modules/@earendil-works/pi-ai/dist/api/context-room.d.ts +20 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/context-room.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/context-room.js +40 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/context-room.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/simple-options.d.ts +1 -3
- package/node_modules/@earendil-works/pi-ai/dist/api/simple-options.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/simple-options.js +2 -16
- package/node_modules/@earendil-works/pi-ai/dist/api/simple-options.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.d.ts +16 -3
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.js +40 -6
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/compat/extension-oauth-types.d.ts +8 -0
- package/node_modules/@earendil-works/pi-ai/dist/compat/extension-oauth-types.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/compat/extension-oauth-types.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/models.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/models.js +3 -2
- package/node_modules/@earendil-works/pi-ai/dist/models.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.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/huggingface.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/nvidia.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/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/utils/overflow.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js +2 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.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 +16 -16
|
@@ -12,6 +12,44 @@
|
|
|
12
12
|
|
|
13
13
|
### Removed
|
|
14
14
|
|
|
15
|
+
## [2026.9.4] - 2026-09-04
|
|
16
|
+
|
|
17
|
+
### Breaking Changes
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
### Removed
|
|
26
|
+
|
|
27
|
+
## [2026.9.3-3] - 2026-09-03
|
|
28
|
+
|
|
29
|
+
### Breaking Changes
|
|
30
|
+
|
|
31
|
+
### Added
|
|
32
|
+
|
|
33
|
+
### Changed
|
|
34
|
+
|
|
35
|
+
### Fixed
|
|
36
|
+
|
|
37
|
+
### Removed
|
|
38
|
+
|
|
39
|
+
## [2026.9.3-2] - 2026-09-03
|
|
40
|
+
|
|
41
|
+
### Breaking Changes
|
|
42
|
+
|
|
43
|
+
### Added
|
|
44
|
+
|
|
45
|
+
### Changed
|
|
46
|
+
|
|
47
|
+
### Fixed
|
|
48
|
+
|
|
49
|
+
- JavaScript eval cells no longer leak child-process output onto the host terminal under Bun: `Bun.$` commands awaited without `.quiet()`/`.text()` and `Bun.spawn` children with the default stderr now route their output into the cell's stdout/stderr streams instead of the inherited fd 1/2 that the interactive TUI owns.
|
|
50
|
+
|
|
51
|
+
### Removed
|
|
52
|
+
|
|
15
53
|
## [2026.9.3] - 2026-09-03
|
|
16
54
|
|
|
17
55
|
### Breaking Changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@code-yeongyu/senpi-codemode",
|
|
3
|
-
"version": "2026.9.
|
|
3
|
+
"version": "2026.9.4",
|
|
4
4
|
"private": true,
|
|
5
5
|
"description": "Source-only senpi extension package for codemode evaluation tools",
|
|
6
6
|
"type": "module",
|
|
@@ -31,14 +31,14 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@babel/parser": "8.0.4",
|
|
34
|
-
"@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.9.
|
|
34
|
+
"@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.9.4",
|
|
35
35
|
"typebox": "1.3.18"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@code-yeongyu/senpi": "2026.9.
|
|
38
|
+
"@code-yeongyu/senpi": "2026.9.4"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@code-yeongyu/senpi": "2026.9.
|
|
41
|
+
"@code-yeongyu/senpi": "2026.9.4"
|
|
42
42
|
},
|
|
43
43
|
"keywords": [
|
|
44
44
|
"senpi",
|
|
@@ -64,6 +64,15 @@ export interface SenpiCodemodeOptions {
|
|
|
64
64
|
readonly now?: () => number;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
/** Whether the session registry holds `monitor`; false when the runtime cannot be read yet. */
|
|
68
|
+
function monitorIsRegistered(pi: CodemodeExtensionAPI): boolean {
|
|
69
|
+
try {
|
|
70
|
+
return pi.getAllTools().some((tool) => tool.name === "monitor");
|
|
71
|
+
} catch {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
67
76
|
export default function senpiCodemode(pi: CodemodeExtensionAPI, options: SenpiCodemodeOptions = {}): void {
|
|
68
77
|
const manager = new SessionManagerProxy();
|
|
69
78
|
const complete = options.complete ?? ((request, ctx) => createCompletionHandler()(ctx)(request));
|
|
@@ -108,6 +117,11 @@ export default function senpiCodemode(pi: CodemodeExtensionAPI, options: SenpiCo
|
|
|
108
117
|
pi.rpc?.emit(EVAL_EXECUTION_EVENT, toEvalExecutionRpcPayload(payload));
|
|
109
118
|
pi.events?.emit(EVAL_EXECUTION_EVENT, payload);
|
|
110
119
|
};
|
|
120
|
+
// `listTools` below survives because it is lazy; this read is eager, and the loader's
|
|
121
|
+
// action methods throw while extensions are still loading (the bundled codemode path
|
|
122
|
+
// reaches this before the runtime is bound). An unreadable registry means "do not teach
|
|
123
|
+
// a tool we cannot confirm"; session_start / model_select re-register once it is live.
|
|
124
|
+
const monitor = monitorIsRegistered(pi);
|
|
111
125
|
pi.registerTool(
|
|
112
126
|
createEvalTool({
|
|
113
127
|
enabledLanguages: runtime.enabledLanguages,
|
|
@@ -122,6 +136,7 @@ export default function senpiCodemode(pi: CodemodeExtensionAPI, options: SenpiCo
|
|
|
122
136
|
executionTracker: manager,
|
|
123
137
|
onCellSettled,
|
|
124
138
|
renderers,
|
|
139
|
+
monitor,
|
|
125
140
|
spawns: runtime.spawns,
|
|
126
141
|
spawnDefaultAgent: runtime.settings.taskTools.task,
|
|
127
142
|
hostLine: hostLine(),
|
|
@@ -159,6 +174,8 @@ export default function senpiCodemode(pi: CodemodeExtensionAPI, options: SenpiCo
|
|
|
159
174
|
}),
|
|
160
175
|
executionTracker: manager,
|
|
161
176
|
renderers,
|
|
177
|
+
// The baseline tool is registered before extensions such as monitor load.
|
|
178
|
+
monitor: false,
|
|
162
179
|
hostLine: hostLine(),
|
|
163
180
|
runtimes: { js: jsRuntimeInfo() },
|
|
164
181
|
...(bunSkillPath === undefined ? {} : { bunSkillPath }),
|
|
@@ -3,6 +3,7 @@ import { mkdir, readFile, stat, writeFile } from "node:fs/promises";
|
|
|
3
3
|
import { dirname, isAbsolute, join, normalize, resolve, sep } from "node:path";
|
|
4
4
|
import { inspect } from "node:util";
|
|
5
5
|
import { awaitMaybePromise, indirectEval, wrapUserCode } from "./worker-indirect-eval.js";
|
|
6
|
+
import { installShellCapture } from "./worker-shell-capture.js";
|
|
6
7
|
|
|
7
8
|
const PREPARED_CELL_PREFIX = "/*senpi:prepared-cell*/";
|
|
8
9
|
const INTERNAL_URL = /^([a-z][a-z0-9+.-]*):\/\/(.*)$/iu;
|
|
@@ -84,11 +85,16 @@ export class JsWorkerRuntime {
|
|
|
84
85
|
process.stderr.write = routeWrite(process.stderr, originalStderrWrite, "stderr");
|
|
85
86
|
console.log = (...values) => this.#emitText("stdout", `${values.map(formatValue).join(" ")}\n`);
|
|
86
87
|
console.error = (...values) => this.#emitText("stderr", `${values.map(formatValue).join(" ")}\n`);
|
|
88
|
+
const restoreShellCapture = installShellCapture({
|
|
89
|
+
isActive: () => this.#hooks !== null,
|
|
90
|
+
emitText: (stream, data) => this.#emitText(stream, data),
|
|
91
|
+
});
|
|
87
92
|
globalThis.__senpi_restore_console__ = () => {
|
|
88
93
|
console.log = originalLog;
|
|
89
94
|
console.error = originalError;
|
|
90
95
|
process.stdout.write = originalStdoutWrite;
|
|
91
96
|
process.stderr.write = originalStderrWrite;
|
|
97
|
+
restoreShellCapture();
|
|
92
98
|
};
|
|
93
99
|
}
|
|
94
100
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type ShellCaptureStream = "stdout" | "stderr";
|
|
2
|
+
|
|
3
|
+
export type ShellCaptureRestore = () => void;
|
|
4
|
+
|
|
5
|
+
export interface ShellCaptureOptions {
|
|
6
|
+
readonly isActive: () => boolean;
|
|
7
|
+
readonly emitText: (stream: ShellCaptureStream, data: string) => void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function installShellCapture(options: ShellCaptureOptions): ShellCaptureRestore;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
const SHELL_CONFIG_METHODS = ["env", "cwd", "nothrow", "throws"];
|
|
2
|
+
const SHELL_READ_METHODS = ["text", "json", "lines", "arrayBuffer", "bytes", "blob"];
|
|
3
|
+
|
|
4
|
+
export function installShellCapture(options) {
|
|
5
|
+
const bun = globalThis.Bun;
|
|
6
|
+
if (!isBunRuntime(bun)) return () => {};
|
|
7
|
+
const originalShell = bun.$;
|
|
8
|
+
const originalSpawn = bun.spawn;
|
|
9
|
+
bun.$ = capturedShell(originalShell, options);
|
|
10
|
+
bun.spawn = capturedSpawn(originalSpawn, options);
|
|
11
|
+
return () => {
|
|
12
|
+
bun.$ = originalShell;
|
|
13
|
+
bun.spawn = originalSpawn;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function isBunRuntime(bun) {
|
|
18
|
+
return bun !== null && typeof bun === "object" && typeof bun.$ === "function" && typeof bun.spawn === "function";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function capturedShell(originalShell, options) {
|
|
22
|
+
const shell = (strings, ...expressions) => {
|
|
23
|
+
const promise = originalShell(strings, ...expressions);
|
|
24
|
+
return options.isActive() ? captureShellPromise(promise, options.emitText) : promise;
|
|
25
|
+
};
|
|
26
|
+
for (const key of Object.keys(originalShell)) shell[key] = originalShell[key];
|
|
27
|
+
for (const method of SHELL_CONFIG_METHODS) {
|
|
28
|
+
shell[method] = (...args) => {
|
|
29
|
+
originalShell[method](...args);
|
|
30
|
+
return shell;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return shell;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function captureShellPromise(promise, emitText) {
|
|
37
|
+
const prototype = Object.getPrototypeOf(promise);
|
|
38
|
+
let echo = true;
|
|
39
|
+
const echoOnce = (output) => {
|
|
40
|
+
if (!echo) return;
|
|
41
|
+
echo = false;
|
|
42
|
+
emitShellOutput(output, emitText);
|
|
43
|
+
};
|
|
44
|
+
prototype.quiet.call(promise);
|
|
45
|
+
promise.quiet = function quiet() {
|
|
46
|
+
echo = false;
|
|
47
|
+
return prototype.quiet.call(this);
|
|
48
|
+
};
|
|
49
|
+
for (const method of SHELL_READ_METHODS) {
|
|
50
|
+
if (typeof prototype[method] !== "function") continue;
|
|
51
|
+
promise[method] = function read(...args) {
|
|
52
|
+
echo = false;
|
|
53
|
+
return prototype[method].apply(this, args);
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
promise.then = function then(onFulfilled, onRejected) {
|
|
57
|
+
return prototype.then.call(
|
|
58
|
+
this,
|
|
59
|
+
(output) => {
|
|
60
|
+
echoOnce(output);
|
|
61
|
+
return onFulfilled ? onFulfilled(output) : output;
|
|
62
|
+
},
|
|
63
|
+
(error) => {
|
|
64
|
+
echoOnce(error);
|
|
65
|
+
if (onRejected) return onRejected(error);
|
|
66
|
+
throw error;
|
|
67
|
+
},
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
return promise;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function emitShellOutput(output, emitText) {
|
|
74
|
+
if (output === null || typeof output !== "object") return;
|
|
75
|
+
const stdout = outputText(output.stdout);
|
|
76
|
+
if (stdout) emitText("stdout", stdout);
|
|
77
|
+
const stderr = outputText(output.stderr);
|
|
78
|
+
if (stderr) emitText("stderr", stderr);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function outputText(value) {
|
|
82
|
+
if (value instanceof Uint8Array) return new TextDecoder().decode(value);
|
|
83
|
+
return typeof value === "string" ? value : "";
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function capturedSpawn(originalSpawn, options) {
|
|
87
|
+
return (...args) => {
|
|
88
|
+
if (!options.isActive()) return originalSpawn(...args);
|
|
89
|
+
const [first, second] = args;
|
|
90
|
+
if (Array.isArray(first)) {
|
|
91
|
+
const spawnOptions = second === undefined ? {} : second;
|
|
92
|
+
if (!needsStderrCapture(spawnOptions)) return originalSpawn(...args);
|
|
93
|
+
return drainStderr(originalSpawn(first, { ...spawnOptions, stderr: "pipe" }), options.emitText);
|
|
94
|
+
}
|
|
95
|
+
if (!needsStderrCapture(first)) return originalSpawn(...args);
|
|
96
|
+
return drainStderr(originalSpawn({ ...first, stderr: "pipe" }), options.emitText);
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function needsStderrCapture(spawnOptions) {
|
|
101
|
+
return (
|
|
102
|
+
spawnOptions !== null &&
|
|
103
|
+
typeof spawnOptions === "object" &&
|
|
104
|
+
spawnOptions.stdio === undefined &&
|
|
105
|
+
spawnOptions.stderr === undefined
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function drainStderr(child, emitText) {
|
|
110
|
+
const stream = child?.stderr;
|
|
111
|
+
if (!(stream instanceof ReadableStream)) return child;
|
|
112
|
+
void readStream(stream, emitText).catch((error) => {
|
|
113
|
+
emitText("stderr", `[spawn stderr capture failed: ${String(error)}]\n`);
|
|
114
|
+
});
|
|
115
|
+
return child;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async function readStream(stream, emitText) {
|
|
119
|
+
const decoder = new TextDecoder();
|
|
120
|
+
for await (const chunk of stream) {
|
|
121
|
+
const text = decoder.decode(chunk, { stream: true });
|
|
122
|
+
if (text) emitText("stderr", text);
|
|
123
|
+
}
|
|
124
|
+
const tail = decoder.decode();
|
|
125
|
+
if (tail) emitText("stderr", tail);
|
|
126
|
+
}
|
|
@@ -15,6 +15,8 @@ export interface EvalPromptParts {
|
|
|
15
15
|
|
|
16
16
|
export interface EvalPromptOptions {
|
|
17
17
|
readonly spawns: boolean;
|
|
18
|
+
/** Whether the session registry exposes the monitor tool through eval. */
|
|
19
|
+
readonly monitor?: boolean;
|
|
18
20
|
readonly spawnDefaultAgent?: string;
|
|
19
21
|
/** Active model id; selects the emphasis dialect of the batching guidance. */
|
|
20
22
|
readonly modelId?: string;
|
|
@@ -105,21 +107,26 @@ Work incrementally: imports in one call, define in the next, test, then use —
|
|
|
105
107
|
\`eval\` is your default execution surface: if a step needs more than one tool call, write ONE cell that performs the whole step — never issue the calls one at a time.
|
|
106
108
|
- Enumerate every lookup the step needs, then run all independent ones simultaneously with \`parallel(thunks)\` inside the cell; keep calls sequential only when one result feeds the next.
|
|
107
109
|
- Write real code around the calls: loop or comprehend over file sets with \`read()\`/stdlib, branch per case, and wrap risky calls in try/except so one failure degrades only its item — recover or retry inside the cell, keep the batch alive.
|
|
108
|
-
- Post-process \`tool.<name>()\` results programmatically and return distilled facts, not raw dumps.
|
|
110
|
+
- Post-process \`tool.<name>()\` results programmatically — filter, join, aggregate — and return distilled facts, not raw dumps.
|
|
111
|
+
{{#if monitor}}- Start long-running work (build, test run, deploy, or watch) through \`tool.monitor({ command, filter })\`, putting the decisive-line filter inside the same cell, then keep working until its event wakes the turn; sleeping, timed retries, and repeated status reads are not waiting.{{/if}}
|
|
109
112
|
</eval_first_batching>{{/if}}{{#if styleGpt}}<gpt_eval_dialect>
|
|
110
113
|
GPT eval: compose multi-tool work inside one cell with \`tool.<name>(args)\` and \`parallel(thunks)\`; do not split a planned step into serial tool calls.
|
|
111
114
|
- Long pure-compute cells detach on timeout and notify on completion. Do not poll or re-run them; use \`eval({ action: "peek"|"stop", cell_id })\` only to inspect or stop a detached cell.
|
|
112
|
-
-
|
|
115
|
+
- Filter, join, and aggregate tool results in the cell; return only decision-relevant facts.
|
|
116
|
+
{{#if monitor}}- For long-running build, test run, deploy, or watch work, start \`tool.monitor({ command, filter })\` with the decisive-line filter in the same cell; keep working while its event wakes the turn; sleeping, timed retries, and repeated status reads are not waiting.{{/if}}
|
|
113
117
|
</gpt_eval_dialect>{{/if}}{{#if styleCodex}}Route multi-call steps through eval: one cell per step, independent lookups dispatched together via \`parallel(thunks)\`; keep work sequential only when one result determines the next action.
|
|
114
|
-
- Loop or comprehend over file sets with \`read()\`/stdlib instead of reading files one call at a time; post-process \`tool.<name>()\` results programmatically.
|
|
118
|
+
- Loop or comprehend over file sets with \`read()\`/stdlib instead of reading files one call at a time; post-process \`tool.<name>()\` results programmatically — filter, join, aggregate.
|
|
115
119
|
- Wrap failable calls in try/except inside the cell; a failed item degrades only itself. After two distinct failed strategies for the same fact, fall back to direct tool calls.
|
|
116
|
-
- Reduce large results in-kernel to the facts the task needs before returning.
|
|
120
|
+
- Reduce large results in-kernel to the facts the task needs before returning.
|
|
121
|
+
{{#if monitor}}- Long-running build/test/deploy/watch work: start \`tool.monitor({ command, filter })\` with the decisive-line filter inside the same cell, then continue working; its event wakes the turn — sleeping, timed retries, and repeated status reads are not waiting.{{/if}}{{/if}}{{#if styleKimi}}**EVAL IS YOUR SUPERPOWER — MAKE IT YOUR DEFAULT WAY TO ACT.** Before any step, think: "how do I execute this WHOLE step in ONE parallelized cell?" — then write that ONE cell.
|
|
117
122
|
- **BATCH EVERYTHING AT ONCE:** enumerate EVERY independent lookup the step needs and dispatch them ALL simultaneously with \`parallel(thunks)\` in that cell; keep calls sequential only when one result feeds the next.
|
|
118
123
|
- **WRITE REAL CODE, NOT CALL CHAINS:** loop or comprehend over file sets with \`read()\`/stdlib, post-process \`tool.<name>()\` results programmatically, and put try/except around each risky call so the rest of the batch completes.
|
|
119
|
-
- **DISTILL IN-KERNEL:** filter and aggregate results in code, then return ONLY the distilled facts.
|
|
124
|
+
- **DISTILL IN-KERNEL:** filter, join, and aggregate \`tool.<name>()\` results in code, then return ONLY the distilled facts.
|
|
125
|
+
{{#if monitor}}- **DO start long-running build, test run, deploy, or watch work with \`tool.monitor({ command, filter })\`, put the decisive-line filter INSIDE THE SAME CELL, and KEEP WORKING until its event wakes the turn; sleeping, timed retries, and repeated status reads are not waiting.**{{/if}}{{/if}}{{#if styleDefault}}**EVAL IS YOUR PRIMARY EXECUTION SURFACE.** Any step that needs MORE THAN ONE tool call MUST be written as ONE cell — NEVER as a chain of single tool calls.
|
|
120
126
|
- **PLAN THE WHOLE STEP, THEN BATCH IT.** Enumerate every read/search/lookup the step needs and dispatch ALL independent ones through \`parallel(thunks)\` in one cell.
|
|
121
127
|
- **WRITE REAL CODE, NOT CALL LISTS.** Loop or comprehend over file sets with \`read()\`/stdlib, branch \`if\`/\`else\` per case, post-process \`tool.<name>()\` results programmatically, and wrap EVERY risky call in try/except so ONE failure NEVER kills the batch.
|
|
122
|
-
- **DISTILL IN-KERNEL.** Filter, diff, and aggregate in code before returning; return facts, NOT dumps.
|
|
128
|
+
- **DISTILL IN-KERNEL.** Filter, join, diff, and aggregate in code before returning; return facts, NOT dumps.
|
|
129
|
+
{{#if monitor}}- **LONG-RUNNING build, test run, deploy, or watch work MUST start with \`tool.monitor({ command, filter })\`, with the decisive-line filter INSIDE THE SAME CELL; KEEP WORKING until its event wakes the turn — SLEEPING, TIMED RETRIES, AND REPEATED STATUS READS ARE NOT WAITING.**{{/if}}{{/if}}
|
|
123
130
|
{{#if hostLine}}
|
|
124
131
|
Host: {{hostLine}} — cells execute here. Size \`parallel(thunks)\` pools to its cores; \`tool.<name>()\` shell commands must fit this platform, even when the code you are writing targets another machine.
|
|
125
132
|
{{/if}}
|
|
@@ -211,6 +218,7 @@ export function buildEvalPrompt(
|
|
|
211
218
|
rb: enabled.rb,
|
|
212
219
|
jl: enabled.jl,
|
|
213
220
|
spawns: options.spawns,
|
|
221
|
+
monitor: options.monitor === true,
|
|
214
222
|
spawnDefaultAgent,
|
|
215
223
|
styleClaude: style === "claude",
|
|
216
224
|
styleCodex: style === "codex",
|
|
@@ -36,6 +36,8 @@ export interface CreateEvalToolOptions {
|
|
|
36
36
|
readonly proxyExecutor?: (params: EvalToolInput, signal?: AbortSignal) => Promise<AgentToolResult<EvalToolDetails>>;
|
|
37
37
|
readonly renderers?: Pick<ToolDefinition<EvalInputSchema, EvalToolDetails>, "renderCall" | "renderResult">;
|
|
38
38
|
readonly spawns?: boolean;
|
|
39
|
+
/** Whether the session registry exposes the monitor tool through eval. */
|
|
40
|
+
readonly monitor?: boolean;
|
|
39
41
|
readonly spawnDefaultAgent?: string;
|
|
40
42
|
readonly modelId?: string;
|
|
41
43
|
readonly hostLine?: string;
|
|
@@ -28,6 +28,7 @@ export function createEvalTool(options: CreateEvalToolOptions): ToolDefinition<E
|
|
|
28
28
|
const parameters = createEvalInputSchema(options.enabledLanguages);
|
|
29
29
|
const prompt = buildEvalPrompt(options.enabledLanguages, {
|
|
30
30
|
spawns: options.spawns ?? false,
|
|
31
|
+
monitor: options.monitor,
|
|
31
32
|
...(options.spawnDefaultAgent === undefined ? {} : { spawnDefaultAgent: options.spawnDefaultAgent }),
|
|
32
33
|
...(options.modelId === undefined ? {} : { modelId: options.modelId }),
|
|
33
34
|
...(options.hostLine === undefined ? {} : { hostLine: options.hostLine }),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@earendil-works/pi-agent-core",
|
|
3
|
-
"version": "2026.9.
|
|
3
|
+
"version": "2026.9.4",
|
|
4
4
|
"description": "General-purpose agent with transport abstraction, state management, and attachment support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"prepublishOnly": "npm run build"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.9.
|
|
39
|
-
"@earendil-works/pi-telemetry": "npm:@code-yeongyu/senpi-telemetry@2026.9.
|
|
38
|
+
"@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.9.4",
|
|
39
|
+
"@earendil-works/pi-telemetry": "npm:@code-yeongyu/senpi-telemetry@2026.9.4",
|
|
40
40
|
"diff": "9.0.0",
|
|
41
41
|
"ignore": "7.0.6",
|
|
42
42
|
"typebox": "1.3.18",
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Api, Context, Model } from "../types.ts";
|
|
2
|
+
export declare const CONTEXT_SAFETY_TOKENS = 4096;
|
|
3
|
+
/** Tokens always left for the answer when a thinking budget shares the response ceiling. */
|
|
4
|
+
export declare const MIN_ANSWER_TOKENS = 1024;
|
|
5
|
+
/** Windows too small to hold the safety margin plus one answer keep the legacy one-token floor. */
|
|
6
|
+
export declare const CONTEXT_GUARD_MIN_WINDOW: number;
|
|
7
|
+
export declare class ContextWindowExhaustedError extends Error {
|
|
8
|
+
readonly estimatedTokens: number;
|
|
9
|
+
readonly contextWindow: number;
|
|
10
|
+
constructor(estimatedTokens: number, contextWindow: number);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Fit the requested output budget into the room the context leaves in the model window.
|
|
14
|
+
* For windows of at least {@link CONTEXT_GUARD_MIN_WINDOW} tokens this throws
|
|
15
|
+
* {@link ContextWindowExhaustedError} instead of shrinking the budget below
|
|
16
|
+
* {@link MIN_ANSWER_TOKENS}: such a request can only return a truncated tool call or an
|
|
17
|
+
* empty "length" stop while still billing the whole prompt.
|
|
18
|
+
*/
|
|
19
|
+
export declare function clampMaxTokensToContext(model: Model<Api>, context: Context, maxTokens: number): number;
|
|
20
|
+
//# sourceMappingURL=context-room.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-room.d.ts","sourceRoot":"","sources":["../../src/api/context-room.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGvD,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAC1C,4FAA4F;AAC5F,eAAO,MAAM,iBAAiB,OAAO,CAAC;AAEtC,mGAAmG;AACnG,eAAO,MAAM,wBAAwB,QAA4C,CAAC;AAElF,qBAAa,2BAA4B,SAAQ,KAAK;IACrD,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;gBAEnB,eAAe,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM;CAU1D;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CActG"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { estimateContextTokens } from "../utils/estimate.js";
|
|
2
|
+
export const CONTEXT_SAFETY_TOKENS = 4096;
|
|
3
|
+
/** Tokens always left for the answer when a thinking budget shares the response ceiling. */
|
|
4
|
+
export const MIN_ANSWER_TOKENS = 1024;
|
|
5
|
+
const MIN_MAX_TOKENS = 1;
|
|
6
|
+
/** Windows too small to hold the safety margin plus one answer keep the legacy one-token floor. */
|
|
7
|
+
export const CONTEXT_GUARD_MIN_WINDOW = CONTEXT_SAFETY_TOKENS + MIN_ANSWER_TOKENS;
|
|
8
|
+
export class ContextWindowExhaustedError extends Error {
|
|
9
|
+
constructor(estimatedTokens, contextWindow) {
|
|
10
|
+
super(`Context window exhausted: the conversation is estimated at ${estimatedTokens} of ${contextWindow} tokens, ` +
|
|
11
|
+
`leaving fewer than ${MIN_ANSWER_TOKENS} tokens for a response. ` +
|
|
12
|
+
"Compact the conversation, enable auto-compaction, or start a new session before retrying.");
|
|
13
|
+
this.name = "ContextWindowExhaustedError";
|
|
14
|
+
this.estimatedTokens = estimatedTokens;
|
|
15
|
+
this.contextWindow = contextWindow;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Fit the requested output budget into the room the context leaves in the model window.
|
|
20
|
+
* For windows of at least {@link CONTEXT_GUARD_MIN_WINDOW} tokens this throws
|
|
21
|
+
* {@link ContextWindowExhaustedError} instead of shrinking the budget below
|
|
22
|
+
* {@link MIN_ANSWER_TOKENS}: such a request can only return a truncated tool call or an
|
|
23
|
+
* empty "length" stop while still billing the whole prompt.
|
|
24
|
+
*/
|
|
25
|
+
export function clampMaxTokensToContext(model, context, maxTokens) {
|
|
26
|
+
if (model.contextWindow <= 0) {
|
|
27
|
+
return Number.isFinite(maxTokens) && maxTokens > 0
|
|
28
|
+
? Math.max(MIN_MAX_TOKENS, Math.floor(maxTokens))
|
|
29
|
+
: MIN_MAX_TOKENS;
|
|
30
|
+
}
|
|
31
|
+
const estimatedTokens = estimateContextTokens(context).tokens;
|
|
32
|
+
const available = model.contextWindow - estimatedTokens - CONTEXT_SAFETY_TOKENS;
|
|
33
|
+
if (model.contextWindow >= CONTEXT_GUARD_MIN_WINDOW && available < MIN_ANSWER_TOKENS) {
|
|
34
|
+
throw new ContextWindowExhaustedError(estimatedTokens, model.contextWindow);
|
|
35
|
+
}
|
|
36
|
+
const safeAvailable = Math.max(MIN_MAX_TOKENS, available);
|
|
37
|
+
const requested = Number.isFinite(maxTokens) && maxTokens > 0 ? Math.floor(maxTokens) : safeAvailable;
|
|
38
|
+
return Math.min(requested, safeAvailable);
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=context-room.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-room.js","sourceRoot":"","sources":["../../src/api/context-room.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,CAAC;AAC1C,4FAA4F;AAC5F,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAC;AACtC,M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SAAS,CAAC,IAAI,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC;IACtG,OAAO,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["import type { Api, Context, Model } from \"../types.ts\";\nimport { estimateContextTokens } from \"../utils/estimate.ts\";\n\nexport const CONTEXT_SAFETY_TOKENS = 4096;\n/** Tokens always left for the answer when a thinking budget shares the response ceiling. */\nexport const MIN_ANSWER_TOKENS = 1024;\nconst MIN_MAX_TOKENS = 1;\n/** Windows too small to hold the safety margin plus one answer keep the legacy one-token floor. */\nexport const CONTEXT_GUARD_MIN_WINDOW = CONTEXT_SAFETY_TOKENS + MIN_ANSWER_TOKENS;\n\nexport class ContextWindowExhaustedError extends Error {\n\treadonly estimatedTokens: number;\n\treadonly contextWindow: number;\n\n\tconstructor(estimatedTokens: number, contextWindow: number) {\n\t\tsuper(\n\t\t\t`Context window exhausted: the conversation is estimated at ${estimatedTokens} of ${contextWindow} tokens, ` +\n\t\t\t\t`leaving fewer than ${MIN_ANSWER_TOKENS} tokens for a response. ` +\n\t\t\t\t\"Compact the conversation, enable auto-compaction, or start a new session before retrying.\",\n\t\t);\n\t\tthis.name = \"ContextWindowExhaustedError\";\n\t\tthis.estimatedTokens = estimatedTokens;\n\t\tthis.contextWindow = contextWindow;\n\t}\n}\n\n/**\n * Fit the requested output budget into the room the context leaves in the model window.\n * For windows of at least {@link CONTEXT_GUARD_MIN_WINDOW} tokens this throws\n * {@link ContextWindowExhaustedError} instead of shrinking the budget below\n * {@link MIN_ANSWER_TOKENS}: such a request can only return a truncated tool call or an\n * empty \"length\" stop while still billing the whole prompt.\n */\nexport function clampMaxTokensToContext(model: Model<Api>, context: Context, maxTokens: number): number {\n\tif (model.contextWindow <= 0) {\n\t\treturn Number.isFinite(maxTokens) && maxTokens > 0\n\t\t\t? Math.max(MIN_MAX_TOKENS, Math.floor(maxTokens))\n\t\t\t: MIN_MAX_TOKENS;\n\t}\n\tconst estimatedTokens = estimateContextTokens(context).tokens;\n\tconst available = model.contextWindow - estimatedTokens - CONTEXT_SAFETY_TOKENS;\n\tif (model.contextWindow >= CONTEXT_GUARD_MIN_WINDOW && available < MIN_ANSWER_TOKENS) {\n\t\tthrow new ContextWindowExhaustedError(estimatedTokens, model.contextWindow);\n\t}\n\tconst safeAvailable = Math.max(MIN_MAX_TOKENS, available);\n\tconst requested = Number.isFinite(maxTokens) && maxTokens > 0 ? Math.floor(maxTokens) : safeAvailable;\n\treturn Math.min(requested, safeAvailable);\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Api, Context, Model, SimpleStreamOptions, StreamOptions, ThinkingBudgets, ThinkingLevel } from "../types.ts";
|
|
2
|
+
export { CONTEXT_GUARD_MIN_WINDOW, CONTEXT_SAFETY_TOKENS, ContextWindowExhaustedError, clampMaxTokensToContext, MIN_ANSWER_TOKENS, } from "./context-room.ts";
|
|
2
3
|
/**
|
|
3
4
|
* Merge user-supplied extraBody fields into a provider request payload, skipping
|
|
4
5
|
* any key the provider manages itself (model id, messages, stream flag, etc.).
|
|
@@ -16,10 +17,7 @@ export declare const GOOGLE_RESERVED_BODY_KEYS: ReadonlySet<string>;
|
|
|
16
17
|
export declare const ANTHROPIC_RESERVED_BODY_KEYS: ReadonlySet<string>;
|
|
17
18
|
export declare const MISTRAL_RESERVED_BODY_KEYS: ReadonlySet<string>;
|
|
18
19
|
export declare const BEDROCK_RESERVED_BODY_KEYS: ReadonlySet<string>;
|
|
19
|
-
export declare function clampMaxTokensToContext(model: Model<Api>, context: Context, maxTokens: number): number;
|
|
20
20
|
export declare function buildBaseOptions(model: Model<Api>, context: Context, options?: SimpleStreamOptions, apiKey?: string): StreamOptions;
|
|
21
|
-
/** Tokens always left for the answer when a thinking budget shares the response ceiling. */
|
|
22
|
-
export declare const MIN_ANSWER_TOKENS = 1024;
|
|
23
21
|
export declare const DEFAULT_THINKING_BUDGETS: ThinkingBudgets;
|
|
24
22
|
export declare function clampReasoning(effort: ThinkingLevel | undefined): Exclude<ThinkingLevel, "xhigh" | "max"> | undefined;
|
|
25
23
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simple-options.d.ts","sourceRoot":"","sources":["../../src/api/simple-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,GAAG,EACH,OAAO,EACP,KAAK,EACL,mBAAmB,EACnB,aAAa,EACb,eAAe,EACf,aAAa,EACb,MAAM,aAAa,CAAC;AAGrB;;;;GAIG;AACH,wBAAgB,cAAc,CAC7B,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAC9C,YAAY,EAAE,WAAW,CAAC,MAAM,CAAC,GAC/B,IAAI,CAMN;AAED,eAAO,MAAM,qCAAqC,EAAE,WAAW,CAAC,MAAM,CAmBpE,CAAC;AAEH,eAAO,MAAM,mCAAmC,EAAE,WAAW,CAAC,MAAM,CAiBlE,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,EAAE,WAAW,CAAC,MAAM,CAYxD,CAAC;AAEH,eAAO,MAAM,4BAA4B,EAAE,WAAW,CAAC,MAAM,CAY3D,CAAC;AAEH,eAAO,MAAM,0BAA0B,EAAE,WAAW,CAAC,MAAM,CASzD,CAAC;AAEH,eAAO,MAAM,0BAA0B,EAAE,WAAW,CAAC,MAAM,CAQzD,CAAC;
|
|
1
|
+
{"version":3,"file":"simple-options.d.ts","sourceRoot":"","sources":["../../src/api/simple-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,GAAG,EACH,OAAO,EACP,KAAK,EACL,mBAAmB,EACnB,aAAa,EACb,eAAe,EACf,aAAa,EACb,MAAM,aAAa,CAAC;AAGrB,OAAO,EACN,wBAAwB,EACxB,qBAAqB,EACrB,2BAA2B,EAC3B,uB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G;AAED,kGAAkG;AAClG,wBAAgB,+BAA+B,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAE/F;AAED,wBAAgB,0BAA0B,CAEzC,aAAa,EAAE,MAAM,GAAG,SAAS,EACjC,cAAc,EAAE,MAAM,EACtB,cAAc,EAAE,aAAa,EAC7B,aAAa,CAAC,EAAE,eAAe,GAC7B;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE,CAe/C"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { clampMaxTokensToContext, MIN_ANSWER_TOKENS } from "./context-room.js";
|
|
2
|
+
export { CONTEXT_GUARD_MIN_WINDOW, CONTEXT_SAFETY_TOKENS, ContextWindowExhaustedError, clampMaxTokensToContext, MIN_ANSWER_TOKENS, } from "./context-room.js";
|
|
2
3
|
/**
|
|
3
4
|
* Merge user-supplied extraBody fields into a provider request payload, skipping
|
|
4
5
|
* any key the provider manages itself (model id, messages, stream flag, etc.).
|
|
@@ -101,19 +102,6 @@ export const BEDROCK_RESERVED_BODY_KEYS = new Set([
|
|
|
101
102
|
"inferenceConfig",
|
|
102
103
|
"requestMetadata",
|
|
103
104
|
]);
|
|
104
|
-
const CONTEXT_SAFETY_TOKENS = 4096;
|
|
105
|
-
const MIN_MAX_TOKENS = 1;
|
|
106
|
-
export function clampMaxTokensToContext(model, context, maxTokens) {
|
|
107
|
-
if (model.contextWindow <= 0) {
|
|
108
|
-
return Number.isFinite(maxTokens) && maxTokens > 0
|
|
109
|
-
? Math.max(MIN_MAX_TOKENS, Math.floor(maxTokens))
|
|
110
|
-
: MIN_MAX_TOKENS;
|
|
111
|
-
}
|
|
112
|
-
const available = model.contextWindow - estimateContextTokens(context).tokens - CONTEXT_SAFETY_TOKENS;
|
|
113
|
-
const safeAvailable = Math.max(MIN_MAX_TOKENS, available);
|
|
114
|
-
const requested = Number.isFinite(maxTokens) && maxTokens > 0 ? Math.floor(maxTokens) : safeAvailable;
|
|
115
|
-
return Math.min(requested, safeAvailable);
|
|
116
|
-
}
|
|
117
105
|
export function buildBaseOptions(model, context, options, apiKey) {
|
|
118
106
|
const samplingParams = model.samplingParams || options?.samplingParams
|
|
119
107
|
? { ...model.samplingParams, ...options?.samplingParams }
|
|
@@ -142,8 +130,6 @@ export function buildBaseOptions(model, context, options, apiKey) {
|
|
|
142
130
|
env: options?.env,
|
|
143
131
|
};
|
|
144
132
|
}
|
|
145
|
-
/** Tokens always left for the answer when a thinking budget shares the response ceiling. */
|
|
146
|
-
export const MIN_ANSWER_TOKENS = 1024;
|
|
147
133
|
export const DEFAULT_THINKING_BUDGETS = {
|
|
148
134
|
minimal: 1024,
|
|
149
135
|
low: 2048,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simple-options.js","sourceRoot":"","sources":["../../src/api/simple-options.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAE7D;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAC7B,MAAc,EACd,SAA8C,EAC9C,YAAiC;IAEjC,IAAI,CAAC,SAAS;QAAE,OAAO;IACvB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QACtD,IAAI,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,SAAS;QACpC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;IACjC,CAAC;AACF,CAAC;AAED,MAAM,CAAC,MAAM,qCAAqC,GAAwB,IAAI,GAAG,CAAC;IACjF,OAAO;IACP,UAAU;IACV,QAAQ;IACR,gBAAgB;IAChB,OAAO;IACP,aAAa;IACb,OAAO;IACP,aAAa;IACb,YAAY;IACZ,uBAAuB;IACvB,kBAAkB;IAClB,WAAW;IACX,UAAU;IACV,iBAAiB;I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AC,cAA6B,EAAE,aAA+B;IACpG,MAAM,OAAO,GAAG,EAAE,GAAG,wBAAwB,EAAE,GAAG,aAAa,EAAE,CAAC;IAClE,MAAM,KAAK,GAAG,cAAc,CAAC,cAAc,CAAE,CAAC;IAC9C,OAAO,OAAO,CAAC,KAAK,CAAE,CAAC;AACxB,CAAC;AAED,kGAAkG;AAClG,MAAM,UAAU,+BAA+B,CAAC,cAAsB,EAAE,OAAe;IACtF,OAAO,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,GAAG,iBAAiB,CAAC,CAAC,CAAC;AAC3E,CAAC;AAED,MAAM,UAAU,0BAA0B;AACzC,wFAAwF;AACxF,aAAiC,EACjC,cAAsB,EACtB,cAA6B,EAC7B,aAA+B;IAE/B,4EAA4E;IAC5E,MAAM,KAAK,GAAG,cAAc,CAAC,cAAc,CAAC,CAAC;IAC7C,IAAI,CAAC,KAAK,EAAE,CAAC;QACZ,OAAO,EAAE,SAAS,EAAE,aAAa,IAAI,cAAc,EAAE,cAAc,EAAE,CAAC,EAAE,CAAC;IAC1E,CAAC;IACD,IAAI,cAAc,GAAG,sBAAsB,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IAClE,MAAM,SAAS,GACd,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,aAAa,GAAG,cAAc,EAAE,cAAc,CAAC,CAAC;IAEzG,IAAI,SAAS,IAAI,cAAc,EAAE,CAAC;QACjC,cAAc,GAAG,+BAA+B,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;IAC7E,CAAC;IAED,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC;AACtC,CAAC","sourcesContent":["import type {\n\tApi,\n\tContext,\n\tModel,\n\tSimpleStreamOptions,\n\tStreamOptions,\n\tThinkingBudgets,\n\tThinkingLevel,\n} from \"../types.ts\";\nimport { estimateContextTokens } from \"../utils/estimate.ts\";\n\n/**\n * Merge user-supplied extraBody fields into a provider request payload, skipping\n * any key the provider manages itself (model id, messages, stream flag, etc.).\n * Mutates `target` in place for zero-copy integration into per-provider builders.\n */\nexport function applyExtraBody(\n\ttarget: object,\n\textraBody: Record<string, unknown> | undefined,\n\treservedKeys: ReadonlySet<string>,\n): void {\n\tif (!extraBody) return;\n\tfor (const [key, value] of Object.entries(extraBody)) {\n\t\tif (reservedKeys.has(key)) continue;\n\t\tReflect.set(target, key, value);\n\t}\n}\n\nexport const OPENAI_COMPLETIONS_RESERVED_BODY_KEYS: ReadonlySet<string> = new Set([\n\t\"model\",\n\t\"messages\",\n\t\"stream\",\n\t\"stream_options\",\n\t\"tools\",\n\t\"tool_choice\",\n\t\"store\",\n\t\"temperature\",\n\t\"max_tokens\",\n\t\"max_completion_tokens\",\n\t\"reasoning_effort\",\n\t\"reasoning\",\n\t\"thinking\",\n\t\"enable_thinking\",\n\t\"chat_template_kwargs\",\n\t\"tool_stream\",\n\t\"provider\",\n\t\"providerOptions\",\n]);\n\nexport const OPENAI_RESPONSES_RESERVED_BODY_KEYS: ReadonlySet<string> = new Set([\n\t\"model\",\n\t\"input\",\n\t\"instructions\",\n\t\"stream\",\n\t\"tools\",\n\t\"tool_choice\",\n\t\"parallel_tool_calls\",\n\t\"reasoning\",\n\t\"max_output_tokens\",\n\t\"temperature\",\n\t\"text\",\n\t\"store\",\n\t\"include\",\n\t\"prompt_cache_key\",\n\t\"prompt_cache_retention\",\n\t\"service_tier\",\n]);\n\n/**\n * Reserved keys for the inner Google `config` object (which is serialized as the\n * request body's generationConfig/tools/systemInstruction by the @google/genai SDK).\n * extraBody is merged into `config`, not the top-level GenerateContentParameters.\n */\nexport const GOOGLE_RESERVED_BODY_KEYS: ReadonlySet<string> = new Set([\n\t\"systemInstruction\",\n\t\"tools\",\n\t\"toolConfig\",\n\t\"temperature\",\n\t\"maxOutputTokens\",\n\t\"thinkingConfig\",\n\t\"responseMimeType\",\n\t\"responseSchema\",\n\t\"cachedContent\",\n\t\"abortSignal\",\n\t\"httpOptions\",\n]);\n\nexport const ANTHROPIC_RESERVED_BODY_KEYS: ReadonlySet<string> = new Set([\n\t\"model\",\n\t\"messages\",\n\t\"system\",\n\t\"stream\",\n\t\"tools\",\n\t\"tool_choice\",\n\t\"temperature\",\n\t\"max_tokens\",\n\t\"thinking\",\n\t\"output_config\",\n\t\"metadata\",\n]);\n\nexport const MISTRAL_RESERVED_BODY_KEYS: ReadonlySet<string> = new Set([\n\t\"model\",\n\t\"messages\",\n\t\"stream\",\n\t\"tools\",\n\t\"toolChoice\",\n\t\"temperature\",\n\t\"maxTokens\",\n\t\"promptMode\",\n]);\n\nexport const BEDROCK_RESERVED_BODY_KEYS: ReadonlySet<string> = new Set([\n\t\"modelId\",\n\t\"messages\",\n\t\"system\",\n\t\"toolConfig\",\n\t\"additionalModelRequestFields\",\n\t\"inferenceConfig\",\n\t\"requestMetadata\",\n]);\n\nconst CONTEXT_SAFETY_TOKENS = 4096;\nconst MIN_MAX_TOKENS = 1;\n\nexport function clampMaxTokensToContext(model: Model<Api>, context: Context, maxTokens: number): number {\n\tif (model.contextWindow <= 0) {\n\t\treturn Number.isFinite(maxTokens) && maxTokens > 0\n\t\t\t? Math.max(MIN_MAX_TOKENS, Math.floor(maxTokens))\n\t\t\t: MIN_MAX_TOKENS;\n\t}\n\tconst available = model.contextWindow - estimateContextTokens(context).tokens - CONTEXT_SAFETY_TOKENS;\n\tconst safeAvailable = Math.max(MIN_MAX_TOKENS, available);\n\tconst requested = Number.isFinite(maxTokens) && maxTokens > 0 ? Math.floor(maxTokens) : safeAvailable;\n\treturn Math.min(requested, safeAvailable);\n}\n\nexport function buildBaseOptions(\n\tmodel: Model<Api>,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n\tapiKey?: string,\n): StreamOptions {\n\tconst samplingParams =\n\t\tmodel.samplingParams || options?.samplingParams\n\t\t\t? { ...model.samplingParams, ...options?.samplingParams }\n\t\t\t: undefined;\n\treturn {\n\t\ttemperature: options?.temperature,\n\t\tsamplingParams,\n\t\tmaxTokens: clampMaxTokensToContext(model, context, options?.maxTokens ?? model.maxTokens),\n\t\tsignal: options?.signal,\n\t\tabortServerSideFallback: options?.abortServerSideFallback,\n\t\ttelemetryContext: options?.telemetryContext,\n\t\tapiKey: apiKey || options?.apiKey,\n\t\tfetch: options?.fetch,\n\t\ttransport: options?.transport,\n\t\tcacheRetention: options?.cacheRetention ?? model.cacheRetention,\n\t\tsessionId: options?.sessionId,\n\t\theaders: options?.headers,\n\t\textraBody: options?.extraBody,\n\t\tonPayload: options?.onPayload,\n\t\tonResponse: options?.onResponse,\n\t\ttimeoutMs: options?.timeoutMs,\n\t\twebsocketConnectTimeoutMs: options?.websocketConnectTimeoutMs,\n\t\tmaxRetries: options?.maxRetries,\n\t\tmaxRetryDelayMs: options?.maxRetryDelayMs,\n\t\tmetadata: options?.metadata,\n\t\tenv: options?.env,\n\t};\n}\n\n/** Tokens always left for the answer when a thinking budget shares the response ceiling. */\nexport const MIN_ANSWER_TOKENS = 1024;\n\nexport const DEFAULT_THINKING_BUDGETS: ThinkingBudgets = {\n\tminimal: 1024,\n\tlow: 2048,\n\tmedium: 8192,\n\thigh: 16384,\n};\n\nexport function clampReasoning(effort: ThinkingLevel | undefined): Exclude<ThinkingLevel, \"xhigh\" | \"max\"> | undefined {\n\tif (effort === \"xhigh\" || effort === \"max\") return \"high\";\n\treturn effort;\n}\n\n/**\n * Clamp \"max\" to an OpenAI-compatible effort. OpenAI-style reasoning APIs accept\n * low|medium|high|xhigh but not \"max\". Callers that know the model supports xhigh\n * should pass through xhigh; \"max\" downgrades to \"xhigh\" on xhigh-capable models\n * and to \"high\" otherwise.\n */\nexport function clampMaxForOpenAI(\n\teffort: ThinkingLevel | undefined,\n\txhighSupported: boolean,\n): Exclude<ThinkingLevel, \"max\"> | undefined {\n\tif (effort === \"max\") return xhighSupported ? \"xhigh\" : \"high\";\n\treturn effort;\n}\n\nexport function thinkingBudgetForLevel(reasoningLevel: ThinkingLevel, customBudgets?: ThinkingBudgets): number {\n\tconst budgets = { ...DEFAULT_THINKING_BUDGETS, ...customBudgets };\n\tconst level = clampReasoning(reasoningLevel)!;\n\treturn budgets[level]!;\n}\n\n/** Cap a thinking budget so at least MIN_ANSWER_TOKENS remain under a shared response ceiling. */\nexport function clampThinkingBudgetToAnswerRoom(thinkingBudget: number, ceiling: number): number {\n\treturn Math.min(thinkingBudget, Math.max(0, ceiling - MIN_ANSWER_TOKENS));\n}\n\nexport function adjustMaxTokensForThinking(\n\t// Undefined means no explicit caller cap. Use the model cap and fit thinking inside it.\n\tbaseMaxTokens: number | undefined,\n\tmodelMaxTokens: number,\n\treasoningLevel: ThinkingLevel,\n\tcustomBudgets?: ThinkingBudgets,\n): { maxTokens: number; thinkingBudget: number } {\n\t// Fork: an absent/unresolvable level means \"no thinking\", not a NaN budget.\n\tconst level = clampReasoning(reasoningLevel);\n\tif (!level) {\n\t\treturn { maxTokens: baseMaxTokens ?? modelMaxTokens, thinkingBudget: 0 };\n\t}\n\tlet thinkingBudget = thinkingBudgetForLevel(level, customBudgets);\n\tconst maxTokens =\n\t\tbaseMaxTokens === undefined ? modelMaxTokens : Math.min(baseMaxTokens + thinkingBudget, modelMaxTokens);\n\n\tif (maxTokens <= thinkingBudget) {\n\t\tthinkingBudget = clampThinkingBudgetToAnswerRoom(thinkingBudget, maxTokens);\n\t}\n\n\treturn { maxTokens, thinkingBudget };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"simple-options.js","sourceRoot":"","sources":["../../src/api/simple-options.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAE/E,OAAO,EACN,wBAAwB,EACxB,qBAAqB,EACrB,2BAA2B,EAC3B,uBAAuB,EACvB,iBAAiB,GACjB,MAAM,mBAAmB,CAAC;AAE3B;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAC7B,MAA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O,GAAG,iBAAiB,CAAC,CAAC,CAAC;AAC3E,CAAC;AAED,MAAM,UAAU,0BAA0B;AACzC,wFAAwF;AACxF,aAAiC,EACjC,cAAsB,EACtB,cAA6B,EAC7B,aAA+B;IAE/B,4EAA4E;IAC5E,MAAM,KAAK,GAAG,cAAc,CAAC,cAAc,CAAC,CAAC;IAC7C,IAAI,CAAC,KAAK,EAAE,CAAC;QACZ,OAAO,EAAE,SAAS,EAAE,aAAa,IAAI,cAAc,EAAE,cAAc,EAAE,CAAC,EAAE,CAAC;IAC1E,CAAC;IACD,IAAI,cAAc,GAAG,sBAAsB,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IAClE,MAAM,SAAS,GACd,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,aAAa,GAAG,cAAc,EAAE,cAAc,CAAC,CAAC;IAEzG,IAAI,SAAS,IAAI,cAAc,EAAE,CAAC;QACjC,cAAc,GAAG,+BAA+B,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;IAC7E,CAAC;IAED,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC;AACtC,CAAC","sourcesContent":["import type {\n\tApi,\n\tContext,\n\tModel,\n\tSimpleStreamOptions,\n\tStreamOptions,\n\tThinkingBudgets,\n\tThinkingLevel,\n} from \"../types.ts\";\nimport { clampMaxTokensToContext, MIN_ANSWER_TOKENS } from \"./context-room.ts\";\n\nexport {\n\tCONTEXT_GUARD_MIN_WINDOW,\n\tCONTEXT_SAFETY_TOKENS,\n\tContextWindowExhaustedError,\n\tclampMaxTokensToContext,\n\tMIN_ANSWER_TOKENS,\n} from \"./context-room.ts\";\n\n/**\n * Merge user-supplied extraBody fields into a provider request payload, skipping\n * any key the provider manages itself (model id, messages, stream flag, etc.).\n * Mutates `target` in place for zero-copy integration into per-provider builders.\n */\nexport function applyExtraBody(\n\ttarget: object,\n\textraBody: Record<string, unknown> | undefined,\n\treservedKeys: ReadonlySet<string>,\n): void {\n\tif (!extraBody) return;\n\tfor (const [key, value] of Object.entries(extraBody)) {\n\t\tif (reservedKeys.has(key)) continue;\n\t\tReflect.set(target, key, value);\n\t}\n}\n\nexport const OPENAI_COMPLETIONS_RESERVED_BODY_KEYS: ReadonlySet<string> = new Set([\n\t\"model\",\n\t\"messages\",\n\t\"stream\",\n\t\"stream_options\",\n\t\"tools\",\n\t\"tool_choice\",\n\t\"store\",\n\t\"temperature\",\n\t\"max_tokens\",\n\t\"max_completion_tokens\",\n\t\"reasoning_effort\",\n\t\"reasoning\",\n\t\"thinking\",\n\t\"enable_thinking\",\n\t\"chat_template_kwargs\",\n\t\"tool_stream\",\n\t\"provider\",\n\t\"providerOptions\",\n]);\n\nexport const OPENAI_RESPONSES_RESERVED_BODY_KEYS: ReadonlySet<string> = new Set([\n\t\"model\",\n\t\"input\",\n\t\"instructions\",\n\t\"stream\",\n\t\"tools\",\n\t\"tool_choice\",\n\t\"parallel_tool_calls\",\n\t\"reasoning\",\n\t\"max_output_tokens\",\n\t\"temperature\",\n\t\"text\",\n\t\"store\",\n\t\"include\",\n\t\"prompt_cache_key\",\n\t\"prompt_cache_retention\",\n\t\"service_tier\",\n]);\n\n/**\n * Reserved keys for the inner Google `config` object (which is serialized as the\n * request body's generationConfig/tools/systemInstruction by the @google/genai SDK).\n * extraBody is merged into `config`, not the top-level GenerateContentParameters.\n */\nexport const GOOGLE_RESERVED_BODY_KEYS: ReadonlySet<string> = new Set([\n\t\"systemInstruction\",\n\t\"tools\",\n\t\"toolConfig\",\n\t\"temperature\",\n\t\"maxOutputTokens\",\n\t\"thinkingConfig\",\n\t\"responseMimeType\",\n\t\"responseSchema\",\n\t\"cachedContent\",\n\t\"abortSignal\",\n\t\"httpOptions\",\n]);\n\nexport const ANTHROPIC_RESERVED_BODY_KEYS: ReadonlySet<string> = new Set([\n\t\"model\",\n\t\"messages\",\n\t\"system\",\n\t\"stream\",\n\t\"tools\",\n\t\"tool_choice\",\n\t\"temperature\",\n\t\"max_tokens\",\n\t\"thinking\",\n\t\"output_config\",\n\t\"metadata\",\n]);\n\nexport const MISTRAL_RESERVED_BODY_KEYS: ReadonlySet<string> = new Set([\n\t\"model\",\n\t\"messages\",\n\t\"stream\",\n\t\"tools\",\n\t\"toolChoice\",\n\t\"temperature\",\n\t\"maxTokens\",\n\t\"promptMode\",\n]);\n\nexport const BEDROCK_RESERVED_BODY_KEYS: ReadonlySet<string> = new Set([\n\t\"modelId\",\n\t\"messages\",\n\t\"system\",\n\t\"toolConfig\",\n\t\"additionalModelRequestFields\",\n\t\"inferenceConfig\",\n\t\"requestMetadata\",\n]);\n\nexport function buildBaseOptions(\n\tmodel: Model<Api>,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n\tapiKey?: string,\n): StreamOptions {\n\tconst samplingParams =\n\t\tmodel.samplingParams || options?.samplingParams\n\t\t\t? { ...model.samplingParams, ...options?.samplingParams }\n\t\t\t: undefined;\n\treturn {\n\t\ttemperature: options?.temperature,\n\t\tsamplingParams,\n\t\tmaxTokens: clampMaxTokensToContext(model, context, options?.maxTokens ?? model.maxTokens),\n\t\tsignal: options?.signal,\n\t\tabortServerSideFallback: options?.abortServerSideFallback,\n\t\ttelemetryContext: options?.telemetryContext,\n\t\tapiKey: apiKey || options?.apiKey,\n\t\tfetch: options?.fetch,\n\t\ttransport: options?.transport,\n\t\tcacheRetention: options?.cacheRetention ?? model.cacheRetention,\n\t\tsessionId: options?.sessionId,\n\t\theaders: options?.headers,\n\t\textraBody: options?.extraBody,\n\t\tonPayload: options?.onPayload,\n\t\tonResponse: options?.onResponse,\n\t\ttimeoutMs: options?.timeoutMs,\n\t\twebsocketConnectTimeoutMs: options?.websocketConnectTimeoutMs,\n\t\tmaxRetries: options?.maxRetries,\n\t\tmaxRetryDelayMs: options?.maxRetryDelayMs,\n\t\tmetadata: options?.metadata,\n\t\tenv: options?.env,\n\t};\n}\n\nexport const DEFAULT_THINKING_BUDGETS: ThinkingBudgets = {\n\tminimal: 1024,\n\tlow: 2048,\n\tmedium: 8192,\n\thigh: 16384,\n};\n\nexport function clampReasoning(effort: ThinkingLevel | undefined): Exclude<ThinkingLevel, \"xhigh\" | \"max\"> | undefined {\n\tif (effort === \"xhigh\" || effort === \"max\") return \"high\";\n\treturn effort;\n}\n\n/**\n * Clamp \"max\" to an OpenAI-compatible effort. OpenAI-style reasoning APIs accept\n * low|medium|high|xhigh but not \"max\". Callers that know the model supports xhigh\n * should pass through xhigh; \"max\" downgrades to \"xhigh\" on xhigh-capable models\n * and to \"high\" otherwise.\n */\nexport function clampMaxForOpenAI(\n\teffort: ThinkingLevel | undefined,\n\txhighSupported: boolean,\n): Exclude<ThinkingLevel, \"max\"> | undefined {\n\tif (effort === \"max\") return xhighSupported ? \"xhigh\" : \"high\";\n\treturn effort;\n}\n\nexport function thinkingBudgetForLevel(reasoningLevel: ThinkingLevel, customBudgets?: ThinkingBudgets): number {\n\tconst budgets = { ...DEFAULT_THINKING_BUDGETS, ...customBudgets };\n\tconst level = clampReasoning(reasoningLevel)!;\n\treturn budgets[level]!;\n}\n\n/** Cap a thinking budget so at least MIN_ANSWER_TOKENS remain under a shared response ceiling. */\nexport function clampThinkingBudgetToAnswerRoom(thinkingBudget: number, ceiling: number): number {\n\treturn Math.min(thinkingBudget, Math.max(0, ceiling - MIN_ANSWER_TOKENS));\n}\n\nexport function adjustMaxTokensForThinking(\n\t// Undefined means no explicit caller cap. Use the model cap and fit thinking inside it.\n\tbaseMaxTokens: number | undefined,\n\tmodelMaxTokens: number,\n\treasoningLevel: ThinkingLevel,\n\tcustomBudgets?: ThinkingBudgets,\n): { maxTokens: number; thinkingBudget: number } {\n\t// Fork: an absent/unresolvable level means \"no thinking\", not a NaN budget.\n\tconst level = clampReasoning(reasoningLevel);\n\tif (!level) {\n\t\treturn { maxTokens: baseMaxTokens ?? modelMaxTokens, thinkingBudget: 0 };\n\t}\n\tlet thinkingBudget = thinkingBudgetForLevel(level, customBudgets);\n\tconst maxTokens =\n\t\tbaseMaxTokens === undefined ? modelMaxTokens : Math.min(baseMaxTokens + thinkingBudget, modelMaxTokens);\n\n\tif (maxTokens <= thinkingBudget) {\n\t\tthinkingBudget = clampThinkingBudgetToAnswerRoom(thinkingBudget, maxTokens);\n\t}\n\n\treturn { maxTokens, thinkingBudget };\n}\n"]}
|
|
@@ -31,6 +31,13 @@ export declare function upsertSlot(credential: PooledCredential | undefined, slo
|
|
|
31
31
|
* Removes one slot. The credential is dropped entirely once its last slot is gone,
|
|
32
32
|
* and a pin naming the removed slot is cleared so selection never points at a slot
|
|
33
33
|
* that no longer exists.
|
|
34
|
+
*
|
|
35
|
+
* When the removed slot was the one the flat top-level fields projected, those
|
|
36
|
+
* fields are re-projected from the first survivor. Without that the pool keeps
|
|
37
|
+
* authenticating with the deleted account's material: a credential with a single
|
|
38
|
+
* remaining slot does not enter the rotation path, so ordinary requests resolve
|
|
39
|
+
* the flat projection and would keep using exactly the account the user removed.
|
|
40
|
+
* `accounts` is preserved either way, so the entry stays a pool.
|
|
34
41
|
*/
|
|
35
42
|
export declare function removeSlot(credential: PooledCredential | undefined, name: string): PooledCredential | undefined;
|
|
36
43
|
export declare function pinSlot(credential: PooledCredential, name: string): PooledCredential;
|
|
@@ -41,9 +48,15 @@ export declare function pinSlot(credential: PooledCredential, name: string): Poo
|
|
|
41
48
|
*/
|
|
42
49
|
export declare function projectSlot(credential: PooledCredential | undefined, name: string): Credential | undefined;
|
|
43
50
|
/**
|
|
44
|
-
* Appends an unnamed flat credential to a pool as a generated `login-N` slot.
|
|
45
|
-
*
|
|
46
|
-
*
|
|
51
|
+
* Appends an unnamed flat credential to a pool as a generated `login-N` slot.
|
|
52
|
+
* An absent current entry keeps today's whole-write shape; a flat current entry
|
|
53
|
+
* is promoted to a pool so the legacy credential stays reachable as `default`
|
|
54
|
+
* instead of being overwritten by the second login.
|
|
55
|
+
*
|
|
56
|
+
* A login result that already carries its own populated `accounts` array is a
|
|
57
|
+
* provider-owned pool: it IS the complete post-login credential, so it is
|
|
58
|
+
* written through untouched. Reading its top-level fields as a flat credential
|
|
59
|
+
* would append the provider's placeholder material as a second slot.
|
|
47
60
|
*/
|
|
48
61
|
export declare function appendLoginSlot(current: PooledCredential | undefined, flat: Credential): Credential;
|
|
49
62
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slots.d.ts","sourceRoot":"","sources":["../../../src/auth/pool/slots.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,YAAY,EAAE,UAAU,EAAE,CAAC;AAE3B,eAAO,MAAM,iBAAiB,YAAY,CAAC;AAE3C,MAAM,MAAM,oBAAoB,GAAG,OAAO,GAAG,QAAQ,GAAG,KAAK,CAAC;AAE9D,MAAM,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,oBAAoB,CAAC;IAC9B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG;IAC3C,QAAQ,CAAC,EAAE,cAAc,EAAE,CAAC;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAIF,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAMtD;AAmBD;;;GAGG;AACH,wBAAgB,SAAS,CAAC,UAAU,EAAE,gBAAgB,GAAG,SAAS,GAAG,cAAc,EAAE,CAIpF;AAED,wBAAgB,QAAQ,CAAC,UAAU,EAAE,gBAAgB,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAE3G;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,UAAU,EAAE,gBAAgB,GAAG,SA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