@orion-agents/orion-code 0.1.4 → 0.1.5
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/README.md +52 -21
- package/README.zh-CN.md +14 -7
- package/dist/agents/coder.d.ts.map +1 -1
- package/dist/agents/coder.js.map +1 -1
- package/dist/agents/fork.d.ts +12 -4
- package/dist/agents/fork.d.ts.map +1 -1
- package/dist/agents/fork.js +28 -32
- package/dist/agents/fork.js.map +1 -1
- package/dist/agents/leader.d.ts.map +1 -1
- package/dist/agents/leader.js.map +1 -1
- package/dist/agents/worker-pool.d.ts.map +1 -1
- package/dist/agents/worker-pool.js +38 -29
- package/dist/agents/worker-pool.js.map +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +4 -1
- package/dist/cli.js.map +1 -1
- package/dist/commands/context-commands.d.ts +4 -0
- package/dist/commands/context-commands.d.ts.map +1 -0
- package/dist/commands/context-commands.js +74 -0
- package/dist/commands/context-commands.js.map +1 -0
- package/dist/commands/context-tool-command-handlers.d.ts +13 -0
- package/dist/commands/context-tool-command-handlers.d.ts.map +1 -0
- package/dist/commands/context-tool-command-handlers.js +580 -0
- package/dist/commands/context-tool-command-handlers.js.map +1 -0
- package/dist/commands/core-command-handlers.d.ts +12 -0
- package/dist/commands/core-command-handlers.d.ts.map +1 -0
- package/dist/commands/core-command-handlers.js +805 -0
- package/dist/commands/core-command-handlers.js.map +1 -0
- package/dist/commands/diagnostic-command-handlers.d.ts +14 -0
- package/dist/commands/diagnostic-command-handlers.d.ts.map +1 -0
- package/dist/commands/diagnostic-command-handlers.js +1043 -0
- package/dist/commands/diagnostic-command-handlers.js.map +1 -0
- package/dist/commands/diagnostic-commands.d.ts +4 -0
- package/dist/commands/diagnostic-commands.d.ts.map +1 -0
- package/dist/commands/diagnostic-commands.js +175 -0
- package/dist/commands/diagnostic-commands.js.map +1 -0
- package/dist/commands/index.d.ts +9 -10
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +42 -3563
- package/dist/commands/index.js.map +1 -1
- package/dist/commands/legacy-commands.d.ts +4 -0
- package/dist/commands/legacy-commands.d.ts.map +1 -0
- package/dist/commands/legacy-commands.js +44 -0
- package/dist/commands/legacy-commands.js.map +1 -0
- package/dist/commands/model-command-handlers.d.ts +15 -0
- package/dist/commands/model-command-handlers.d.ts.map +1 -0
- package/dist/commands/model-command-handlers.js +526 -0
- package/dist/commands/model-command-handlers.js.map +1 -0
- package/dist/commands/model-commands.d.ts +4 -0
- package/dist/commands/model-commands.d.ts.map +1 -0
- package/dist/commands/model-commands.js +85 -0
- package/dist/commands/model-commands.js.map +1 -0
- package/dist/commands/parser.d.ts +12 -0
- package/dist/commands/parser.d.ts.map +1 -1
- package/dist/commands/parser.js +48 -7
- package/dist/commands/parser.js.map +1 -1
- package/dist/commands/registry.d.ts +4 -0
- package/dist/commands/registry.d.ts.map +1 -0
- package/dist/commands/registry.js +566 -0
- package/dist/commands/registry.js.map +1 -0
- package/dist/commands/session-command-handlers.d.ts +10 -0
- package/dist/commands/session-command-handlers.d.ts.map +1 -0
- package/dist/commands/session-command-handlers.js +626 -0
- package/dist/commands/session-command-handlers.js.map +1 -0
- package/dist/commands/session-commands.d.ts +4 -0
- package/dist/commands/session-commands.d.ts.map +1 -0
- package/dist/commands/session-commands.js +102 -0
- package/dist/commands/session-commands.js.map +1 -0
- package/dist/commands/system-commands.d.ts +4 -0
- package/dist/commands/system-commands.d.ts.map +1 -0
- package/dist/commands/system-commands.js +80 -0
- package/dist/commands/system-commands.js.map +1 -0
- package/dist/commands/target-command.d.ts.map +1 -1
- package/dist/commands/target-command.js +29 -2
- package/dist/commands/target-command.js.map +1 -1
- package/dist/commands/tool-commands.d.ts +4 -0
- package/dist/commands/tool-commands.d.ts.map +1 -0
- package/dist/commands/tool-commands.js +49 -0
- package/dist/commands/tool-commands.js.map +1 -0
- package/dist/commands/types.d.ts +69 -5
- package/dist/commands/types.d.ts.map +1 -1
- package/dist/commands/types.js +3 -4
- package/dist/commands/types.js.map +1 -1
- package/dist/commands/workflow-command-handlers.d.ts +7 -0
- package/dist/commands/workflow-command-handlers.d.ts.map +1 -0
- package/dist/commands/workflow-command-handlers.js +32 -0
- package/dist/commands/workflow-command-handlers.js.map +1 -0
- package/dist/commands/workflow-commands.d.ts +4 -0
- package/dist/commands/workflow-commands.d.ts.map +1 -0
- package/dist/commands/workflow-commands.js +124 -0
- package/dist/commands/workflow-commands.js.map +1 -0
- package/dist/core/checkpoint.d.ts +12 -4
- package/dist/core/checkpoint.d.ts.map +1 -1
- package/dist/core/checkpoint.js +114 -28
- package/dist/core/checkpoint.js.map +1 -1
- package/dist/core/cost-tracker.d.ts +17 -1
- package/dist/core/cost-tracker.d.ts.map +1 -1
- package/dist/core/cost-tracker.js +24 -8
- package/dist/core/cost-tracker.js.map +1 -1
- package/dist/core/warn-dedup.d.ts +3 -0
- package/dist/core/warn-dedup.d.ts.map +1 -1
- package/dist/core/warn-dedup.js +6 -6
- package/dist/core/warn-dedup.js.map +1 -1
- package/dist/framework/index.d.ts +1 -1
- package/dist/framework/index.d.ts.map +1 -1
- package/dist/framework/index.js.map +1 -1
- package/dist/framework/prompt.d.ts +2 -2
- package/dist/framework/query.d.ts +2 -2
- package/dist/framework/query.d.ts.map +1 -1
- package/dist/framework/query.js +57 -10
- package/dist/framework/query.js.map +1 -1
- package/dist/framework/store.d.ts +15 -6
- package/dist/framework/store.d.ts.map +1 -1
- package/dist/framework/store.js +18 -0
- package/dist/framework/store.js.map +1 -1
- package/dist/framework/tool-scheduler.d.ts +16 -13
- package/dist/framework/tool-scheduler.d.ts.map +1 -1
- package/dist/framework/tool-scheduler.js +155 -38
- package/dist/framework/tool-scheduler.js.map +1 -1
- package/dist/framework/tool.d.ts +39 -2
- package/dist/framework/tool.d.ts.map +1 -1
- package/dist/framework/tool.js +27 -1
- package/dist/framework/tool.js.map +1 -1
- package/dist/harness/assembler.d.ts.map +1 -1
- package/dist/harness/assembler.js +4 -2
- package/dist/harness/assembler.js.map +1 -1
- package/dist/harness/evidence.d.ts.map +1 -1
- package/dist/harness/evidence.js +3 -2
- package/dist/harness/evidence.js.map +1 -1
- package/dist/harness/safety.d.ts +11 -1
- package/dist/harness/safety.d.ts.map +1 -1
- package/dist/harness/safety.js +112 -16
- package/dist/harness/safety.js.map +1 -1
- package/dist/index.d.ts +1 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +4 -8
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +4 -4
- package/dist/init.js.map +1 -1
- package/dist/ink-ui/App.d.ts +2 -2
- package/dist/ink-ui/components/Markdown.d.ts.map +1 -1
- package/dist/ink-ui/components/Markdown.js.map +1 -1
- package/dist/ink-ui/components/PixelHorseBanner.d.ts +2 -2
- package/dist/ink-ui/components/StatusLine.d.ts +2 -2
- package/dist/ink-ui/launch.d.ts +2 -2
- package/dist/ink-ui/screens/ReplScreen.d.ts +4 -3
- package/dist/ink-ui/screens/ReplScreen.d.ts.map +1 -1
- package/dist/ink-ui/screens/ReplScreen.js +103 -31
- package/dist/ink-ui/screens/ReplScreen.js.map +1 -1
- package/dist/memory/relevant-finder.d.ts +2 -1
- package/dist/memory/relevant-finder.d.ts.map +1 -1
- package/dist/memory/relevant-finder.js +17 -8
- package/dist/memory/relevant-finder.js.map +1 -1
- package/dist/memory/semantic-config.d.ts +9 -0
- package/dist/memory/semantic-config.d.ts.map +1 -0
- package/dist/memory/semantic-config.js +16 -0
- package/dist/memory/semantic-config.js.map +1 -0
- package/dist/memory/semantic-search.d.ts +1 -6
- package/dist/memory/semantic-search.d.ts.map +1 -1
- package/dist/memory/semantic-search.js +3 -15
- package/dist/memory/semantic-search.js.map +1 -1
- package/dist/memory/storage.d.ts +23 -0
- package/dist/memory/storage.d.ts.map +1 -1
- package/dist/memory/storage.js +116 -9
- package/dist/memory/storage.js.map +1 -1
- package/dist/memory/vector-store.d.ts +30 -0
- package/dist/memory/vector-store.d.ts.map +1 -1
- package/dist/memory/vector-store.js +160 -21
- package/dist/memory/vector-store.js.map +1 -1
- package/dist/migration/command.d.ts.map +1 -1
- package/dist/migration/command.js +0 -1
- package/dist/migration/command.js.map +1 -1
- package/dist/migration/migrate.d.ts.map +1 -1
- package/dist/migration/migrate.js +47 -103
- package/dist/migration/migrate.js.map +1 -1
- package/dist/migration/types.d.ts +0 -1
- package/dist/migration/types.d.ts.map +1 -1
- package/dist/print-ui/launch.d.ts +13 -3
- package/dist/print-ui/launch.d.ts.map +1 -1
- package/dist/print-ui/launch.js +28 -3
- package/dist/print-ui/launch.js.map +1 -1
- package/dist/product/environment.d.ts +3 -5
- package/dist/product/environment.d.ts.map +1 -1
- package/dist/product/environment.js +4 -32
- package/dist/product/environment.js.map +1 -1
- package/dist/product/index.d.ts +1 -1
- package/dist/product/index.d.ts.map +1 -1
- package/dist/product/index.js +1 -3
- package/dist/product/index.js.map +1 -1
- package/dist/product/paths.d.ts.map +1 -1
- package/dist/product/paths.js +16 -11
- package/dist/product/paths.js.map +1 -1
- package/dist/runtime/agent-runtime-controller.d.ts +4 -2
- package/dist/runtime/agent-runtime-controller.d.ts.map +1 -1
- package/dist/runtime/agent-runtime-controller.js +127 -14
- package/dist/runtime/agent-runtime-controller.js.map +1 -1
- package/dist/runtime/agent-runtime-protocol.d.ts +15 -0
- package/dist/runtime/agent-runtime-protocol.d.ts.map +1 -1
- package/dist/runtime/agent-runtime-protocol.js +6 -0
- package/dist/runtime/agent-runtime-protocol.js.map +1 -1
- package/dist/runtime/chat-checkpoint.d.ts +17 -0
- package/dist/runtime/chat-checkpoint.d.ts.map +1 -0
- package/dist/runtime/chat-checkpoint.js +108 -0
- package/dist/runtime/chat-checkpoint.js.map +1 -0
- package/dist/runtime/chat-controller.d.ts +10 -51
- package/dist/runtime/chat-controller.d.ts.map +1 -1
- package/dist/runtime/chat-controller.js +256 -1070
- package/dist/runtime/chat-controller.js.map +1 -1
- package/dist/runtime/chat-effort.d.ts +5 -0
- package/dist/runtime/chat-effort.d.ts.map +1 -0
- package/dist/runtime/chat-effort.js +47 -0
- package/dist/runtime/chat-effort.js.map +1 -0
- package/dist/runtime/chat-presentation.d.ts +60 -0
- package/dist/runtime/chat-presentation.d.ts.map +1 -0
- package/dist/runtime/chat-presentation.js +537 -0
- package/dist/runtime/chat-presentation.js.map +1 -0
- package/dist/runtime/chat-trace.d.ts +52 -0
- package/dist/runtime/chat-trace.d.ts.map +1 -0
- package/dist/runtime/chat-trace.js +234 -0
- package/dist/runtime/chat-trace.js.map +1 -0
- package/dist/runtime/chat-workspace.d.ts +22 -0
- package/dist/runtime/chat-workspace.d.ts.map +1 -0
- package/dist/runtime/chat-workspace.js +154 -0
- package/dist/runtime/chat-workspace.js.map +1 -0
- package/dist/runtime/goals/accounting.js +1 -1
- package/dist/runtime/goals/accounting.js.map +1 -1
- package/dist/runtime/goals/completion-audit.d.ts.map +1 -1
- package/dist/runtime/goals/completion-audit.js +5 -4
- package/dist/runtime/goals/completion-audit.js.map +1 -1
- package/dist/runtime/goals/coordinator.d.ts +3 -0
- package/dist/runtime/goals/coordinator.d.ts.map +1 -1
- package/dist/runtime/goals/coordinator.js +30 -2
- package/dist/runtime/goals/coordinator.js.map +1 -1
- package/dist/runtime/goals/prompt.d.ts +1 -1
- package/dist/runtime/goals/prompt.d.ts.map +1 -1
- package/dist/runtime/goals/prompt.js +4 -3
- package/dist/runtime/goals/prompt.js.map +1 -1
- package/dist/runtime/goals/tools.d.ts +21 -8
- package/dist/runtime/goals/tools.d.ts.map +1 -1
- package/dist/runtime/goals/tools.js +141 -10
- package/dist/runtime/goals/tools.js.map +1 -1
- package/dist/runtime/loop-budget.d.ts +2 -2
- package/dist/runtime/rich-text/markdown-parser.d.ts +2 -0
- package/dist/runtime/rich-text/markdown-parser.d.ts.map +1 -1
- package/dist/runtime/rich-text/markdown-parser.js +50 -10
- package/dist/runtime/rich-text/markdown-parser.js.map +1 -1
- package/dist/runtime/subagents/index.d.ts +2 -2
- package/dist/runtime/subagents/index.d.ts.map +1 -1
- package/dist/runtime/subagents/index.js +2 -1
- package/dist/runtime/subagents/index.js.map +1 -1
- package/dist/runtime/subagents/policy.d.ts +1 -1
- package/dist/runtime/subagents/policy.d.ts.map +1 -1
- package/dist/runtime/subagents/policy.js.map +1 -1
- package/dist/runtime/subagents/presets.d.ts +2 -2
- package/dist/runtime/subagents/research-artifact.d.ts +7 -0
- package/dist/runtime/subagents/research-artifact.d.ts.map +1 -1
- package/dist/runtime/subagents/research-artifact.js +73 -27
- package/dist/runtime/subagents/research-artifact.js.map +1 -1
- package/dist/runtime/subagents/research-contract.d.ts +18 -4
- package/dist/runtime/subagents/research-contract.d.ts.map +1 -1
- package/dist/runtime/subagents/research-contract.js +122 -17
- package/dist/runtime/subagents/research-contract.js.map +1 -1
- package/dist/runtime/subagents/research-renderer.d.ts +27 -11
- package/dist/runtime/subagents/research-renderer.d.ts.map +1 -1
- package/dist/runtime/subagents/research-renderer.js +34 -2
- package/dist/runtime/subagents/research-renderer.js.map +1 -1
- package/dist/runtime/subagents/result-parser.d.ts +1 -5
- package/dist/runtime/subagents/result-parser.d.ts.map +1 -1
- package/dist/runtime/subagents/result-parser.js +5 -72
- package/dist/runtime/subagents/result-parser.js.map +1 -1
- package/dist/runtime/subagents/runtime-integration.d.ts +13 -7
- package/dist/runtime/subagents/runtime-integration.d.ts.map +1 -1
- package/dist/runtime/subagents/runtime-integration.js +112 -2
- package/dist/runtime/subagents/runtime-integration.js.map +1 -1
- package/dist/runtime/subagents/supervisor.d.ts +15 -1
- package/dist/runtime/subagents/supervisor.d.ts.map +1 -1
- package/dist/runtime/subagents/supervisor.js +58 -3
- package/dist/runtime/subagents/supervisor.js.map +1 -1
- package/dist/runtime/subagents/tool.d.ts +2 -2
- package/dist/runtime/subagents/tool.d.ts.map +1 -1
- package/dist/runtime/subagents/tool.js +129 -9
- package/dist/runtime/subagents/tool.js.map +1 -1
- package/dist/runtime/subagents/types.d.ts +20 -0
- package/dist/runtime/subagents/types.d.ts.map +1 -1
- package/dist/runtime/subagents/types.js.map +1 -1
- package/dist/runtime/subagents/web-research-adapter.d.ts +4 -2
- package/dist/runtime/subagents/web-research-adapter.d.ts.map +1 -1
- package/dist/runtime/subagents/web-research-adapter.js +81 -15
- package/dist/runtime/subagents/web-research-adapter.js.map +1 -1
- package/dist/runtime/ui-events.d.ts +36 -8
- package/dist/runtime/ui-events.d.ts.map +1 -1
- package/dist/runtime/ui-events.js.map +1 -1
- package/dist/runtime/ui-view-model.d.ts +53 -4
- package/dist/runtime/ui-view-model.d.ts.map +1 -1
- package/dist/runtime/ui-view-model.js +190 -10
- package/dist/runtime/ui-view-model.js.map +1 -1
- package/dist/services/agent-runner.d.ts +5 -2
- package/dist/services/agent-runner.d.ts.map +1 -1
- package/dist/services/agent-runner.js +18 -18
- package/dist/services/agent-runner.js.map +1 -1
- package/dist/services/atomic-write.d.ts +9 -1
- package/dist/services/atomic-write.d.ts.map +1 -1
- package/dist/services/atomic-write.js +55 -2
- package/dist/services/atomic-write.js.map +1 -1
- package/dist/services/auth/auth.d.ts +11 -7
- package/dist/services/auth/auth.d.ts.map +1 -1
- package/dist/services/auth/auth.js +117 -31
- package/dist/services/auth/auth.js.map +1 -1
- package/dist/services/auth/aws.d.ts +2 -0
- package/dist/services/auth/aws.d.ts.map +1 -1
- package/dist/services/auth/aws.js +126 -12
- package/dist/services/auth/aws.js.map +1 -1
- package/dist/services/auth/index.d.ts +1 -1
- package/dist/services/auth/index.d.ts.map +1 -1
- package/dist/services/auth/index.js +2 -1
- package/dist/services/auth/index.js.map +1 -1
- package/dist/services/auto-fix/autoFixConfig.d.ts +0 -3
- package/dist/services/auto-fix/autoFixConfig.d.ts.map +1 -1
- package/dist/services/auto-fix/autoFixConfig.js +25 -8
- package/dist/services/auto-fix/autoFixConfig.js.map +1 -1
- package/dist/services/auto-fix/autoFixHook.d.ts +7 -0
- package/dist/services/auto-fix/autoFixHook.d.ts.map +1 -1
- package/dist/services/auto-fix/autoFixHook.js +10 -1
- package/dist/services/auto-fix/autoFixHook.js.map +1 -1
- package/dist/services/compact/auto-compact.d.ts +2 -0
- package/dist/services/compact/auto-compact.d.ts.map +1 -1
- package/dist/services/compact/auto-compact.js +15 -1
- package/dist/services/compact/auto-compact.js.map +1 -1
- package/dist/services/compact/compact.d.ts.map +1 -1
- package/dist/services/compact/compact.js +9 -11
- package/dist/services/compact/compact.js.map +1 -1
- package/dist/services/compact/summary-generator.d.ts.map +1 -1
- package/dist/services/compact/summary-generator.js +28 -4
- package/dist/services/compact/summary-generator.js.map +1 -1
- package/dist/services/compact/tool-call-groups.d.ts +19 -0
- package/dist/services/compact/tool-call-groups.d.ts.map +1 -0
- package/dist/services/compact/tool-call-groups.js +105 -0
- package/dist/services/compact/tool-call-groups.js.map +1 -0
- package/dist/services/concurrent-sessions.d.ts +4 -0
- package/dist/services/concurrent-sessions.d.ts.map +1 -1
- package/dist/services/concurrent-sessions.js +59 -12
- package/dist/services/concurrent-sessions.js.map +1 -1
- package/dist/services/config.d.ts +8 -4
- package/dist/services/config.d.ts.map +1 -1
- package/dist/services/config.js +15 -71
- package/dist/services/config.js.map +1 -1
- package/dist/services/doctor.d.ts +2 -2
- package/dist/services/doctor.js.map +1 -1
- package/dist/services/effort.d.ts +40 -0
- package/dist/services/effort.d.ts.map +1 -0
- package/dist/services/effort.js +88 -0
- package/dist/services/effort.js.map +1 -0
- package/dist/services/file-glob.d.ts.map +1 -1
- package/dist/services/file-glob.js +22 -2
- package/dist/services/file-glob.js.map +1 -1
- package/dist/services/file-lock.d.ts +7 -0
- package/dist/services/file-lock.d.ts.map +1 -0
- package/dist/services/file-lock.js +193 -0
- package/dist/services/file-lock.js.map +1 -0
- package/dist/services/global-config.d.ts +9 -0
- package/dist/services/global-config.d.ts.map +1 -1
- package/dist/services/global-config.js +79 -4
- package/dist/services/global-config.js.map +1 -1
- package/dist/services/goal-storage.d.ts.map +1 -1
- package/dist/services/goal-storage.js +30 -11
- package/dist/services/goal-storage.js.map +1 -1
- package/dist/services/llm.d.ts +35 -17
- package/dist/services/llm.d.ts.map +1 -1
- package/dist/services/llm.js +249 -113
- package/dist/services/llm.js.map +1 -1
- package/dist/services/mcp/transports.d.ts +0 -1
- package/dist/services/mcp/transports.d.ts.map +1 -1
- package/dist/services/mcp/transports.js +12 -13
- package/dist/services/mcp/transports.js.map +1 -1
- package/dist/services/model-context.d.ts +8 -0
- package/dist/services/model-context.d.ts.map +1 -1
- package/dist/services/model-context.js +111 -7
- package/dist/services/model-context.js.map +1 -1
- package/dist/services/model-registry.d.ts +3 -0
- package/dist/services/model-registry.d.ts.map +1 -1
- package/dist/services/model-registry.js +59 -2
- package/dist/services/model-registry.js.map +1 -1
- package/dist/services/provider-diagnostics.d.ts +1 -1
- package/dist/services/provider-diagnostics.d.ts.map +1 -1
- package/dist/services/provider-diagnostics.js +30 -16
- package/dist/services/provider-diagnostics.js.map +1 -1
- package/dist/services/provider-resilience/coordinator.d.ts +8 -3
- package/dist/services/provider-resilience/coordinator.d.ts.map +1 -1
- package/dist/services/provider-resilience/coordinator.js +86 -19
- package/dist/services/provider-resilience/coordinator.js.map +1 -1
- package/dist/services/provider-resilience/error-classifier.d.ts +1 -0
- package/dist/services/provider-resilience/error-classifier.d.ts.map +1 -1
- package/dist/services/provider-resilience/error-classifier.js +50 -26
- package/dist/services/provider-resilience/error-classifier.js.map +1 -1
- package/dist/services/provider-resilience/index.d.ts +3 -3
- package/dist/services/provider-resilience/index.d.ts.map +1 -1
- package/dist/services/provider-resilience/index.js +3 -1
- package/dist/services/provider-resilience/index.js.map +1 -1
- package/dist/services/provider-resilience/request-gate.d.ts +6 -0
- package/dist/services/provider-resilience/request-gate.d.ts.map +1 -1
- package/dist/services/provider-resilience/request-gate.js +24 -9
- package/dist/services/provider-resilience/request-gate.js.map +1 -1
- package/dist/services/provider-resilience/types.d.ts +10 -1
- package/dist/services/provider-resilience/types.d.ts.map +1 -1
- package/dist/services/provider-resilience/types.js.map +1 -1
- package/dist/services/redaction.d.ts.map +1 -1
- package/dist/services/redaction.js +29 -1
- package/dist/services/redaction.js.map +1 -1
- package/dist/services/session-index.d.ts.map +1 -1
- package/dist/services/session-index.js +75 -44
- package/dist/services/session-index.js.map +1 -1
- package/dist/services/session-memory/sessionMemory.d.ts.map +1 -1
- package/dist/services/session-memory/sessionMemory.js +6 -3
- package/dist/services/session-memory/sessionMemory.js.map +1 -1
- package/dist/services/session-storage.d.ts +12 -0
- package/dist/services/session-storage.d.ts.map +1 -1
- package/dist/services/session-storage.js +301 -230
- package/dist/services/session-storage.js.map +1 -1
- package/dist/services/storage-maintenance.d.ts.map +1 -1
- package/dist/services/storage-maintenance.js +25 -7
- package/dist/services/storage-maintenance.js.map +1 -1
- package/dist/services/task-manager.d.ts +6 -1
- package/dist/services/task-manager.d.ts.map +1 -1
- package/dist/services/task-manager.js +18 -4
- package/dist/services/task-manager.js.map +1 -1
- package/dist/services/tool-allowlist.d.ts +20 -10
- package/dist/services/tool-allowlist.d.ts.map +1 -1
- package/dist/services/tool-allowlist.js +64 -15
- package/dist/services/tool-allowlist.js.map +1 -1
- package/dist/services/usage-state.d.ts +10 -0
- package/dist/services/usage-state.d.ts.map +1 -1
- package/dist/services/usage-state.js +116 -45
- package/dist/services/usage-state.js.map +1 -1
- package/dist/services/verification-profile.d.ts.map +1 -1
- package/dist/services/verification-profile.js +23 -3
- package/dist/services/verification-profile.js.map +1 -1
- package/dist/services/workspace-diff.d.ts +14 -0
- package/dist/services/workspace-diff.d.ts.map +1 -1
- package/dist/services/workspace-diff.js +60 -11
- package/dist/services/workspace-diff.js.map +1 -1
- package/dist/skills/loader.d.ts.map +1 -1
- package/dist/skills/loader.js +23 -9
- package/dist/skills/loader.js.map +1 -1
- package/dist/skills/runtime.d.ts +3 -3
- package/dist/skills/runtime.d.ts.map +1 -1
- package/dist/skills/runtime.js +37 -4
- package/dist/skills/runtime.js.map +1 -1
- package/dist/skills/types.d.ts +1 -1
- package/dist/skills/types.d.ts.map +1 -1
- package/dist/terminal-ui/launch.d.ts +26 -8
- package/dist/terminal-ui/launch.d.ts.map +1 -1
- package/dist/terminal-ui/launch.js +79 -37
- package/dist/terminal-ui/launch.js.map +1 -1
- package/dist/tools/bash_security.d.ts +17 -0
- package/dist/tools/bash_security.d.ts.map +1 -1
- package/dist/tools/bash_security.js +233 -27
- package/dist/tools/bash_security.js.map +1 -1
- package/dist/tools/git.d.ts +8 -8
- package/dist/tools/git.d.ts.map +1 -1
- package/dist/tools/git.js +248 -55
- package/dist/tools/git.js.map +1 -1
- package/dist/tools/index.d.ts +13 -3
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +245 -25
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/lsp.d.ts +74 -6
- package/dist/tools/lsp.d.ts.map +1 -1
- package/dist/tools/lsp.js +24 -5
- package/dist/tools/lsp.js.map +1 -1
- package/dist/tools/mcp.d.ts +11 -4
- package/dist/tools/mcp.d.ts.map +1 -1
- package/dist/tools/mcp.js +99 -3
- package/dist/tools/mcp.js.map +1 -1
- package/dist/tools/plan.d.ts +4 -4
- package/dist/tools/sandbox.d.ts +3 -1
- package/dist/tools/sandbox.d.ts.map +1 -1
- package/dist/tools/sandbox.js +28 -13
- package/dist/tools/sandbox.js.map +1 -1
- package/dist/tools/todo.d.ts +3 -3
- package/dist/tools/web.d.ts +15 -4
- package/dist/tools/web.d.ts.map +1 -1
- package/dist/tools/web.js +240 -26
- package/dist/tools/web.js.map +1 -1
- package/dist/tui-ui/launch.d.ts +3 -3
- package/dist/tui-ui/launch.d.ts.map +1 -1
- package/dist/tui-ui/launch.js +3 -3
- package/dist/tui-ui/launch.js.map +1 -1
- package/dist/tui-ui/layout.d.ts.map +1 -1
- package/dist/tui-ui/layout.js +9 -3
- package/dist/tui-ui/layout.js.map +1 -1
- package/dist/tui-ui/pickers.d.ts.map +1 -1
- package/dist/tui-ui/pickers.js +1 -0
- package/dist/tui-ui/pickers.js.map +1 -1
- package/dist/tui-ui/runner.d.ts +2 -1
- package/dist/tui-ui/runner.d.ts.map +1 -1
- package/dist/tui-ui/runner.js +18 -29
- package/dist/tui-ui/runner.js.map +1 -1
- package/dist/tui-ui/state.d.ts +13 -1
- package/dist/tui-ui/state.d.ts.map +1 -1
- package/dist/tui-ui/state.js +28 -1
- package/dist/tui-ui/state.js.map +1 -1
- package/dist/ui/markdown.js.map +1 -1
- package/dist/utils/debug-log.d.ts +3 -3
- package/dist/utils/debug-log.d.ts.map +1 -1
- package/dist/utils/debug-log.js +7 -4
- package/dist/utils/debug-log.js.map +1 -1
- package/dist/utils/json.d.ts +6 -0
- package/dist/utils/json.d.ts.map +1 -0
- package/dist/utils/json.js +66 -0
- package/dist/utils/json.js.map +1 -0
- package/dist/utils/mask.d.ts +8 -1
- package/dist/utils/mask.d.ts.map +1 -1
- package/dist/utils/mask.js +10 -12
- package/dist/utils/mask.js.map +1 -1
- package/dist/utils/observability.d.ts +22 -0
- package/dist/utils/observability.d.ts.map +1 -0
- package/dist/utils/observability.js +80 -0
- package/dist/utils/observability.js.map +1 -0
- package/dist/utils/token-estimate.d.ts +8 -0
- package/dist/utils/token-estimate.d.ts.map +1 -1
- package/dist/utils/token-estimate.js +30 -17
- package/dist/utils/token-estimate.js.map +1 -1
- package/package.json +9 -8
package/dist/services/llm.js
CHANGED
|
@@ -12,11 +12,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
exports.LLMService = exports.ProviderRequestPreflightError = exports.FallbackTriggeredError = exports.LLMProviderError = void 0;
|
|
15
|
+
exports.normalizeFinishReason = normalizeFinishReason;
|
|
15
16
|
const openai_1 = __importDefault(require("openai"));
|
|
16
17
|
const crypto_1 = require("crypto");
|
|
17
18
|
const provider_diagnostics_1 = require("./provider-diagnostics");
|
|
18
19
|
const provider_resilience_1 = require("./provider-resilience");
|
|
20
|
+
const tool_call_groups_1 = require("./compact/tool-call-groups");
|
|
19
21
|
const token_estimate_1 = require("../utils/token-estimate");
|
|
22
|
+
const effort_1 = require("./effort");
|
|
20
23
|
var provider_diagnostics_2 = require("./provider-diagnostics");
|
|
21
24
|
Object.defineProperty(exports, "LLMProviderError", { enumerable: true, get: function () { return provider_diagnostics_2.LLMProviderError; } });
|
|
22
25
|
/** Fallback 触发错误 */
|
|
@@ -29,6 +32,29 @@ class FallbackTriggeredError extends Error {
|
|
|
29
32
|
}
|
|
30
33
|
}
|
|
31
34
|
exports.FallbackTriggeredError = FallbackTriggeredError;
|
|
35
|
+
function normalizeFinishReason(value) {
|
|
36
|
+
if (typeof value !== 'string')
|
|
37
|
+
return undefined;
|
|
38
|
+
const reason = value.trim().toLowerCase();
|
|
39
|
+
if (!reason)
|
|
40
|
+
return undefined;
|
|
41
|
+
if (['stop', 'end', 'end_turn', 'completed', 'complete', 'success'].includes(reason)) {
|
|
42
|
+
return 'stop';
|
|
43
|
+
}
|
|
44
|
+
if (['length', 'max_tokens', 'max_output_tokens', 'token_limit'].includes(reason)) {
|
|
45
|
+
return 'length';
|
|
46
|
+
}
|
|
47
|
+
if (['tool_calls', 'tool_call', 'tool_use', 'function_call'].includes(reason)) {
|
|
48
|
+
return 'tool_calls';
|
|
49
|
+
}
|
|
50
|
+
if (['content_filter', 'content_filtered', 'safety', 'blocked'].includes(reason)) {
|
|
51
|
+
return 'content_filter';
|
|
52
|
+
}
|
|
53
|
+
return 'unknown';
|
|
54
|
+
}
|
|
55
|
+
function rawFinishReason(value) {
|
|
56
|
+
return typeof value === 'string' && value.trim() ? value.trim() : undefined;
|
|
57
|
+
}
|
|
32
58
|
class ProviderRequestPreflightError extends Error {
|
|
33
59
|
constructor(message) {
|
|
34
60
|
super(message);
|
|
@@ -55,6 +81,8 @@ function providerErrorTypeForFailureKind(kind) {
|
|
|
55
81
|
case 'provider_overloaded':
|
|
56
82
|
case 'server_error':
|
|
57
83
|
return 'provider_busy';
|
|
84
|
+
case 'unsupported_effort':
|
|
85
|
+
return 'unsupported_effort';
|
|
58
86
|
default:
|
|
59
87
|
return 'unknown_provider_error';
|
|
60
88
|
}
|
|
@@ -67,6 +95,7 @@ const DEFAULT_RETRY_CONFIG = {
|
|
|
67
95
|
maxRetries: 3,
|
|
68
96
|
baseDelayMs: 500,
|
|
69
97
|
maxDelayMs: 10000,
|
|
98
|
+
maxRetryAfterMs: 60000,
|
|
70
99
|
};
|
|
71
100
|
/** 529 错误最大重试次数(触发 fallback) */
|
|
72
101
|
const MAX_529_RETRIES = 3;
|
|
@@ -90,28 +119,6 @@ function throwIfAborted(signal) {
|
|
|
90
119
|
function isAbortError(error) {
|
|
91
120
|
return error instanceof Error && error.name === 'AbortError';
|
|
92
121
|
}
|
|
93
|
-
/** 从错误中提取 retry-after 时间 */
|
|
94
|
-
function getRetryAfterMs(error) {
|
|
95
|
-
if (error instanceof openai_1.default.APIError && error.headers) {
|
|
96
|
-
const headers = error.headers;
|
|
97
|
-
let retryAfter = null;
|
|
98
|
-
// headers may be Headers object or plain object
|
|
99
|
-
if (headers && typeof headers === 'object') {
|
|
100
|
-
if ('get' in headers && typeof headers.get === 'function') {
|
|
101
|
-
retryAfter = headers.get('retry-after');
|
|
102
|
-
}
|
|
103
|
-
else if ('retry-after' in headers) {
|
|
104
|
-
retryAfter = headers['retry-after'];
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
if (retryAfter) {
|
|
108
|
-
const seconds = parseInt(retryAfter, 10);
|
|
109
|
-
if (!isNaN(seconds))
|
|
110
|
-
return seconds * 1000;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return null;
|
|
114
|
-
}
|
|
115
122
|
/** 指数退避计算 */
|
|
116
123
|
function exponentialBackoff(attempt, baseDelayMs, maxDelayMs) {
|
|
117
124
|
const delay = baseDelayMs * Math.pow(2, attempt - 1);
|
|
@@ -155,9 +162,9 @@ async function withRetry(operation, config) {
|
|
|
155
162
|
throw lastError;
|
|
156
163
|
}
|
|
157
164
|
let delayMs = exponentialBackoff(attempt, config.baseDelayMs, config.maxDelayMs);
|
|
158
|
-
const retryAfter =
|
|
159
|
-
if (retryAfter !==
|
|
160
|
-
delayMs = retryAfter;
|
|
165
|
+
const retryAfter = (0, provider_resilience_1.extractRetryAfterMs)(error);
|
|
166
|
+
if (retryAfter !== undefined) {
|
|
167
|
+
delayMs = Math.min(retryAfter, config.maxRetryAfterMs ?? 60000);
|
|
161
168
|
}
|
|
162
169
|
else if (isRateLimitError(error)) {
|
|
163
170
|
delayMs = Math.max(delayMs, Math.min(2000, config.baseDelayMs * 4));
|
|
@@ -216,10 +223,13 @@ function extractProviderCost(usage, response) {
|
|
|
216
223
|
function extractLLMUsage(usage, response, requestId) {
|
|
217
224
|
const cachedPromptTokens = toNonNegativeFiniteNumber(readField(readField(usage, 'prompt_tokens_details'), 'cached_tokens') ??
|
|
218
225
|
readField(readField(usage, 'input_tokens_details'), 'cached_tokens'));
|
|
226
|
+
const reasoningTokens = toNonNegativeFiniteNumber(readField(readField(usage, 'completion_tokens_details'), 'reasoning_tokens') ??
|
|
227
|
+
readField(readField(usage, 'output_tokens_details'), 'reasoning_tokens'));
|
|
219
228
|
return {
|
|
220
229
|
promptTokens: toNonNegativeFiniteNumber(readField(usage, 'prompt_tokens') ?? readField(usage, 'input_tokens')) ?? 0,
|
|
221
230
|
completionTokens: toNonNegativeFiniteNumber(readField(usage, 'completion_tokens') ?? readField(usage, 'output_tokens')) ?? 0,
|
|
222
231
|
...(cachedPromptTokens !== undefined ? { cachedPromptTokens } : {}),
|
|
232
|
+
...(reasoningTokens !== undefined ? { reasoningTokens } : {}),
|
|
223
233
|
...(extractProviderCost(usage, response) !== undefined
|
|
224
234
|
? { costUsd: extractProviderCost(usage, response) }
|
|
225
235
|
: {}),
|
|
@@ -249,6 +259,14 @@ class LLMService {
|
|
|
249
259
|
maxRetries: DEFAULT_MAX_RETRIES,
|
|
250
260
|
retryBaseDelay: DEFAULT_RETRY_DELAY,
|
|
251
261
|
};
|
|
262
|
+
this.effortContext = {
|
|
263
|
+
preference: config.effortPreference ?? 'auto',
|
|
264
|
+
protocol: config.providerProtocol ?? 'openai-completions',
|
|
265
|
+
...(config.reasoningCapability ? { capability: config.reasoningCapability } : {}),
|
|
266
|
+
...(config.fallbackReasoningCapability
|
|
267
|
+
? { fallbackCapability: config.fallbackReasoningCapability }
|
|
268
|
+
: {}),
|
|
269
|
+
};
|
|
252
270
|
this.lastRequestDiagnostics = this.createRequestDiagnostics();
|
|
253
271
|
}
|
|
254
272
|
/** 是否正在使用 fallback model */
|
|
@@ -275,13 +293,13 @@ class LLMService {
|
|
|
275
293
|
this.providerRequestPreflight = previous;
|
|
276
294
|
};
|
|
277
295
|
}
|
|
278
|
-
async assertProviderRequestAllowed(operation, attempt, messages) {
|
|
296
|
+
async assertProviderRequestAllowed(operation, attempt, messages, model = this.config.model) {
|
|
279
297
|
if (!this.providerRequestPreflight)
|
|
280
298
|
return;
|
|
281
299
|
const decision = await this.providerRequestPreflight({
|
|
282
300
|
operation,
|
|
283
301
|
attempt,
|
|
284
|
-
model
|
|
302
|
+
model,
|
|
285
303
|
estimatedPromptTokens: (0, token_estimate_1.estimateMessagesTokens)(messages),
|
|
286
304
|
});
|
|
287
305
|
if (!decision.available) {
|
|
@@ -301,59 +319,13 @@ class LLMService {
|
|
|
301
319
|
this.usingFallback = false;
|
|
302
320
|
this.consecutive529Errors = 0;
|
|
303
321
|
}
|
|
304
|
-
/**
|
|
305
|
-
* Switch to the configured fallback model before a retry, and record it.
|
|
306
|
-
*
|
|
307
|
-
* The resilience coordinator only retries errors it has already classified as
|
|
308
|
-
* retryable -- rate limiting, provider overload, transient transport faults --
|
|
309
|
-
* which is exactly the situation a fallback model exists for. So the first
|
|
310
|
-
* retry is the right moment to switch.
|
|
311
|
-
*
|
|
312
|
-
* The previous gate (`consecutive529Errors >= MAX_529_RETRIES`, i.e. 3) was
|
|
313
|
-
* unreachable in practice: that threshold is at least the coordinator's whole
|
|
314
|
-
* attempt budget, so the request was exhausted before the gate could open. It
|
|
315
|
-
* also only ever ran from the legacy `retryConfig.onRetry` path, which is
|
|
316
|
-
* skipped entirely whenever the coordinator is active.
|
|
317
|
-
*
|
|
318
|
-
* @returns true when the active model changed.
|
|
319
|
-
*/
|
|
320
|
-
applyFallbackForRetry(diagnostics) {
|
|
321
|
-
if (!this.config.fallbackModel || this.usingFallback) {
|
|
322
|
-
return false;
|
|
323
|
-
}
|
|
324
|
-
const originalModel = this.config.model;
|
|
325
|
-
this.triggerFallback();
|
|
326
|
-
if (this.config.model === originalModel) {
|
|
327
|
-
return false;
|
|
328
|
-
}
|
|
329
|
-
diagnostics.fallbackTriggered = true;
|
|
330
|
-
diagnostics.fallbackFromModel = originalModel;
|
|
331
|
-
diagnostics.fallbackToModel = this.config.model;
|
|
332
|
-
diagnostics.finalModel = this.config.model;
|
|
333
|
-
diagnostics.usingFallback = this.usingFallback;
|
|
334
|
-
return true;
|
|
335
|
-
}
|
|
336
322
|
/**
|
|
337
323
|
* 非流式对话
|
|
338
324
|
*/
|
|
339
325
|
async chat(messages, tools) {
|
|
340
326
|
const requestDiagnostics = this.createRequestDiagnostics();
|
|
341
327
|
this.lastRequestDiagnostics = requestDiagnostics;
|
|
342
|
-
|
|
343
|
-
// whatever was configured before the first request, so a fallback switch
|
|
344
|
-
// (which mutates this.config.model) would never reach the wire.
|
|
345
|
-
const buildParams = () => {
|
|
346
|
-
const params = {
|
|
347
|
-
model: this.config.model,
|
|
348
|
-
messages: this.toOpenAIMessages(messages),
|
|
349
|
-
max_tokens: this.config.maxTokens,
|
|
350
|
-
temperature: this.config.temperature,
|
|
351
|
-
};
|
|
352
|
-
if (tools && tools.length > 0) {
|
|
353
|
-
params.tools = tools;
|
|
354
|
-
}
|
|
355
|
-
return params;
|
|
356
|
-
};
|
|
328
|
+
const effortSnapshot = this.createEffortRequestSnapshot();
|
|
357
329
|
// v0.2.25: Use resilience coordinator when available.
|
|
358
330
|
let response;
|
|
359
331
|
try {
|
|
@@ -363,16 +335,20 @@ class LLMService {
|
|
|
363
335
|
operation: 'root_chat',
|
|
364
336
|
providerKey: 'default',
|
|
365
337
|
requestedModel: this.config.model,
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
this.
|
|
373
|
-
|
|
338
|
+
fallbackModel: this.config.fallbackModel || undefined,
|
|
339
|
+
}, async (attempt, signal, model = this.config.model) => {
|
|
340
|
+
await this.assertProviderRequestAllowed('chat', attempt, messages, model);
|
|
341
|
+
const params = {
|
|
342
|
+
model,
|
|
343
|
+
messages: this.toOpenAIMessages(messages),
|
|
344
|
+
max_tokens: this.config.maxTokens,
|
|
345
|
+
temperature: this.config.temperature,
|
|
346
|
+
...(0, effort_1.buildProviderEffortParams)(this.effortSnapshotForModel(effortSnapshot, model)),
|
|
347
|
+
};
|
|
348
|
+
if (tools && tools.length > 0)
|
|
349
|
+
params.tools = tools;
|
|
374
350
|
return {
|
|
375
|
-
response:
|
|
351
|
+
response: await this.client.chat.completions.create(params, signal ? { signal } : undefined),
|
|
376
352
|
};
|
|
377
353
|
});
|
|
378
354
|
response = result.result;
|
|
@@ -380,7 +356,16 @@ class LLMService {
|
|
|
380
356
|
}
|
|
381
357
|
else {
|
|
382
358
|
await this.assertProviderRequestAllowed('chat', 1, messages);
|
|
383
|
-
|
|
359
|
+
const params = {
|
|
360
|
+
model: this.config.model,
|
|
361
|
+
messages: this.toOpenAIMessages(messages),
|
|
362
|
+
max_tokens: this.config.maxTokens,
|
|
363
|
+
temperature: this.config.temperature,
|
|
364
|
+
...(0, effort_1.buildProviderEffortParams)(this.effortSnapshotForModel(effortSnapshot, this.config.model)),
|
|
365
|
+
};
|
|
366
|
+
if (tools && tools.length > 0)
|
|
367
|
+
params.tools = tools;
|
|
368
|
+
response = (await this.client.chat.completions.create(params));
|
|
384
369
|
}
|
|
385
370
|
}
|
|
386
371
|
catch (error) {
|
|
@@ -400,7 +385,8 @@ class LLMService {
|
|
|
400
385
|
throw error;
|
|
401
386
|
throw (0, provider_diagnostics_1.toLLMProviderError)(error);
|
|
402
387
|
}
|
|
403
|
-
const
|
|
388
|
+
const choice = response.choices?.[0];
|
|
389
|
+
const message = choice?.message;
|
|
404
390
|
const content = message?.content ?? '';
|
|
405
391
|
const toolCalls = message?.tool_calls?.map(tc => ({
|
|
406
392
|
id: tc.id,
|
|
@@ -410,8 +396,11 @@ class LLMService {
|
|
|
410
396
|
arguments: tc.function.arguments,
|
|
411
397
|
},
|
|
412
398
|
}));
|
|
399
|
+
const providerFinishReason = rawFinishReason(choice?.finish_reason);
|
|
400
|
+
const finishReason = normalizeFinishReason(providerFinishReason) ??
|
|
401
|
+
(toolCalls && toolCalls.length > 0 ? 'tool_calls' : undefined);
|
|
413
402
|
const usage = response.usage
|
|
414
|
-
? extractLLMUsage(response.usage, response, response.id)
|
|
403
|
+
? this.annotateEffortUsage(extractLLMUsage(response.usage, response, response.id), this.effortSnapshotForModel(effortSnapshot, response.model ?? this.config.model))
|
|
415
404
|
: undefined;
|
|
416
405
|
requestDiagnostics.finalModel = response.model ?? this.config.model;
|
|
417
406
|
requestDiagnostics.usingFallback = this.usingFallback;
|
|
@@ -425,6 +414,8 @@ class LLMService {
|
|
|
425
414
|
content,
|
|
426
415
|
usage,
|
|
427
416
|
model: response.model ?? this.config.model,
|
|
417
|
+
finishReason,
|
|
418
|
+
rawFinishReason: providerFinishReason,
|
|
428
419
|
toolCalls,
|
|
429
420
|
};
|
|
430
421
|
}
|
|
@@ -436,10 +427,34 @@ class LLMService {
|
|
|
436
427
|
const onThinking = typeof callbacks === 'object' ? callbacks?.onThinking : undefined;
|
|
437
428
|
const requestDiagnostics = this.createRequestDiagnostics();
|
|
438
429
|
this.lastRequestDiagnostics = requestDiagnostics;
|
|
430
|
+
const effortSnapshot = this.createEffortRequestSnapshot();
|
|
431
|
+
let visibleStreamText = '';
|
|
432
|
+
const emitStreamText = (text, bufferForRecovery, reporter) => {
|
|
433
|
+
if (!text)
|
|
434
|
+
return;
|
|
435
|
+
reporter?.onTextDelta(text);
|
|
436
|
+
if (bufferForRecovery)
|
|
437
|
+
return;
|
|
438
|
+
visibleStreamText += text;
|
|
439
|
+
onChunk?.(text);
|
|
440
|
+
};
|
|
441
|
+
const finalizeStreamText = (attemptText, bufferForRecovery) => {
|
|
442
|
+
if (!bufferForRecovery)
|
|
443
|
+
return attemptText;
|
|
444
|
+
const suffix = attemptText.startsWith(visibleStreamText)
|
|
445
|
+
? attemptText.slice(visibleStreamText.length)
|
|
446
|
+
: (0, provider_resilience_1.reconcileStreamOverlap)(visibleStreamText, attemptText).suffix;
|
|
447
|
+
if (suffix) {
|
|
448
|
+
visibleStreamText += suffix;
|
|
449
|
+
onChunk?.(suffix);
|
|
450
|
+
}
|
|
451
|
+
return visibleStreamText;
|
|
452
|
+
};
|
|
439
453
|
const retryConfig = {
|
|
440
454
|
maxRetries: this.config.maxRetries,
|
|
441
455
|
baseDelayMs: this.config.retryBaseDelay,
|
|
442
456
|
maxDelayMs: 10000,
|
|
457
|
+
maxRetryAfterMs: 60000,
|
|
443
458
|
abortSignal: options?.abortSignal,
|
|
444
459
|
onRetry: (_attempt, error, delayMs) => {
|
|
445
460
|
const diagnostic = (0, provider_diagnostics_1.diagnoseProviderError)(error);
|
|
@@ -453,8 +468,16 @@ class LLMService {
|
|
|
453
468
|
diagnostic.type === 'provider_busy' ||
|
|
454
469
|
diagnostic.type === 'rate_limit') {
|
|
455
470
|
this.consecutive529Errors++;
|
|
456
|
-
if (this.consecutive529Errors >= MAX_529_RETRIES
|
|
457
|
-
this.
|
|
471
|
+
if (this.consecutive529Errors >= MAX_529_RETRIES &&
|
|
472
|
+
this.config.fallbackModel &&
|
|
473
|
+
!this.usingFallback) {
|
|
474
|
+
const originalModel = this.config.model;
|
|
475
|
+
this.triggerFallback();
|
|
476
|
+
if (this.config.model !== originalModel) {
|
|
477
|
+
requestDiagnostics.fallbackTriggered = true;
|
|
478
|
+
requestDiagnostics.fallbackFromModel = originalModel;
|
|
479
|
+
requestDiagnostics.fallbackToModel = this.config.model;
|
|
480
|
+
}
|
|
458
481
|
}
|
|
459
482
|
}
|
|
460
483
|
requestDiagnostics.finalModel = this.config.model;
|
|
@@ -469,23 +492,19 @@ class LLMService {
|
|
|
469
492
|
operation: 'root_chat_stream',
|
|
470
493
|
providerKey: 'default',
|
|
471
494
|
requestedModel: this.config.model,
|
|
495
|
+
fallbackModel: this.config.fallbackModel || undefined,
|
|
472
496
|
abortSignal: options?.abortSignal,
|
|
473
|
-
}, async (attempt, signal) => {
|
|
497
|
+
}, async (attempt, signal, model = this.config.model, reporter) => {
|
|
474
498
|
throwIfAborted(signal);
|
|
475
|
-
await this.assertProviderRequestAllowed('chat_stream', attempt, messages);
|
|
476
|
-
// Same contract as chat(): the coordinator only re-enters this
|
|
477
|
-
// callback after a retryable failure, so switch models here rather
|
|
478
|
-
// than in retryConfig.onRetry, which the coordinator never calls.
|
|
479
|
-
if (attempt > 1) {
|
|
480
|
-
this.applyFallbackForRetry(requestDiagnostics);
|
|
481
|
-
}
|
|
499
|
+
await this.assertProviderRequestAllowed('chat_stream', attempt, messages, model);
|
|
482
500
|
const params = {
|
|
483
|
-
model
|
|
501
|
+
model,
|
|
484
502
|
messages: this.toOpenAIMessages(messages),
|
|
485
503
|
max_tokens: this.config.maxTokens,
|
|
486
504
|
temperature: this.config.temperature,
|
|
487
505
|
stream: true,
|
|
488
506
|
stream_options: { include_usage: true },
|
|
507
|
+
...(0, effort_1.buildProviderEffortParams)(this.effortSnapshotForModel(effortSnapshot, model)),
|
|
489
508
|
};
|
|
490
509
|
if (tools && tools.length > 0) {
|
|
491
510
|
params.tools = tools;
|
|
@@ -494,9 +513,12 @@ class LLMService {
|
|
|
494
513
|
const requestOptions = signal ? { signal } : undefined;
|
|
495
514
|
const stream = (await this.client.chat.completions.create(params, requestOptions));
|
|
496
515
|
let content = '';
|
|
497
|
-
let usedModel =
|
|
516
|
+
let usedModel = model;
|
|
498
517
|
let usage;
|
|
499
518
|
let providerRequestId;
|
|
519
|
+
let providerFinishReason;
|
|
520
|
+
let finishReason;
|
|
521
|
+
const bufferForRecovery = visibleStreamText.length > 0;
|
|
500
522
|
const toolCallsMap = new Map();
|
|
501
523
|
for await (const chunk of stream) {
|
|
502
524
|
throwIfAborted(signal);
|
|
@@ -507,11 +529,16 @@ class LLMService {
|
|
|
507
529
|
console.log('[DEBUG] Raw chunk:', JSON.stringify(chunk, null, 2));
|
|
508
530
|
}
|
|
509
531
|
}
|
|
510
|
-
const
|
|
511
|
-
const
|
|
532
|
+
const choice = chunk.choices?.[0];
|
|
533
|
+
const delta = choice?.delta;
|
|
534
|
+
const msg = choice?.message;
|
|
535
|
+
const text = delta?.content ?? (content ? '' : (msg?.content ?? ''));
|
|
512
536
|
if (text) {
|
|
513
537
|
content += text;
|
|
514
|
-
|
|
538
|
+
emitStreamText(text, bufferForRecovery, reporter);
|
|
539
|
+
}
|
|
540
|
+
if ((delta?.tool_calls?.length ?? 0) > 0 || (msg?.tool_calls?.length ?? 0) > 0) {
|
|
541
|
+
reporter?.onToolCallDelta();
|
|
515
542
|
}
|
|
516
543
|
for (const tc of delta?.tool_calls ?? []) {
|
|
517
544
|
const idx = tc.index ?? 0;
|
|
@@ -535,7 +562,6 @@ class LLMService {
|
|
|
535
562
|
existing.function.arguments += tc.function.arguments;
|
|
536
563
|
}
|
|
537
564
|
}
|
|
538
|
-
const msg = chunk.choices?.[0]?.message;
|
|
539
565
|
if (msg?.tool_calls && !delta?.tool_calls) {
|
|
540
566
|
for (const msgTc of msg.tool_calls) {
|
|
541
567
|
const existing = toolCallsMap.get(msgTc.index ?? 0);
|
|
@@ -555,13 +581,19 @@ class LLMService {
|
|
|
555
581
|
}
|
|
556
582
|
}
|
|
557
583
|
if (chunk.usage) {
|
|
558
|
-
usage = extractLLMUsage(chunk.usage, chunk, chunk.id ?? providerRequestId);
|
|
584
|
+
usage = this.annotateEffortUsage(extractLLMUsage(chunk.usage, chunk, chunk.id ?? providerRequestId), this.effortSnapshotForModel(effortSnapshot, usedModel));
|
|
559
585
|
}
|
|
560
586
|
if (chunk.id)
|
|
561
587
|
providerRequestId = chunk.id;
|
|
562
588
|
if (chunk.model) {
|
|
563
589
|
usedModel = chunk.model;
|
|
564
590
|
}
|
|
591
|
+
const chunkFinishReason = rawFinishReason(choice?.finish_reason);
|
|
592
|
+
if (chunkFinishReason) {
|
|
593
|
+
providerFinishReason = chunkFinishReason;
|
|
594
|
+
finishReason = normalizeFinishReason(chunkFinishReason);
|
|
595
|
+
reporter?.onFinishReason(chunkFinishReason);
|
|
596
|
+
}
|
|
565
597
|
}
|
|
566
598
|
const toolCalls = Array.from(toolCallsMap.entries())
|
|
567
599
|
.sort(([a], [b]) => Number(a) - Number(b))
|
|
@@ -580,13 +612,17 @@ class LLMService {
|
|
|
580
612
|
}
|
|
581
613
|
}
|
|
582
614
|
}
|
|
615
|
+
finishReason ?? (finishReason = toolCalls.length > 0 ? 'tool_calls' : undefined);
|
|
616
|
+
const finalContent = finalizeStreamText(content, bufferForRecovery);
|
|
583
617
|
if (usage)
|
|
584
618
|
this.publishUsage(usage, usedModel, 'chat_stream');
|
|
585
619
|
return {
|
|
586
620
|
response: {
|
|
587
|
-
content,
|
|
621
|
+
content: finalContent,
|
|
588
622
|
model: usedModel,
|
|
589
623
|
usage,
|
|
624
|
+
finishReason,
|
|
625
|
+
rawFinishReason: providerFinishReason,
|
|
590
626
|
toolCalls: toolCalls.length > 0 ? toolCalls : undefined,
|
|
591
627
|
},
|
|
592
628
|
usage: usage
|
|
@@ -623,6 +659,7 @@ class LLMService {
|
|
|
623
659
|
temperature: this.config.temperature,
|
|
624
660
|
stream: true,
|
|
625
661
|
stream_options: { include_usage: true },
|
|
662
|
+
...(0, effort_1.buildProviderEffortParams)(this.effortSnapshotForModel(effortSnapshot, this.config.model)),
|
|
626
663
|
};
|
|
627
664
|
if (tools && tools.length > 0) {
|
|
628
665
|
params.tools = tools;
|
|
@@ -634,6 +671,9 @@ class LLMService {
|
|
|
634
671
|
let usedModel = this.config.model;
|
|
635
672
|
let usage;
|
|
636
673
|
let providerRequestId;
|
|
674
|
+
let providerFinishReason;
|
|
675
|
+
let finishReason;
|
|
676
|
+
const bufferForRecovery = visibleStreamText.length > 0;
|
|
637
677
|
const toolCallsMap = new Map();
|
|
638
678
|
for await (const chunk of stream) {
|
|
639
679
|
throwIfAborted(options?.abortSignal);
|
|
@@ -644,11 +684,13 @@ class LLMService {
|
|
|
644
684
|
console.log('[DEBUG] Raw chunk:', JSON.stringify(chunk, null, 2));
|
|
645
685
|
}
|
|
646
686
|
}
|
|
647
|
-
const
|
|
648
|
-
const
|
|
687
|
+
const choice = chunk.choices?.[0];
|
|
688
|
+
const delta = choice?.delta;
|
|
689
|
+
const msg = choice?.message;
|
|
690
|
+
const text = delta?.content ?? (content ? '' : (msg?.content ?? ''));
|
|
649
691
|
if (text) {
|
|
650
692
|
content += text;
|
|
651
|
-
|
|
693
|
+
emitStreamText(text, bufferForRecovery);
|
|
652
694
|
}
|
|
653
695
|
// Handle tool_calls from delta (OpenAI standard streaming format).
|
|
654
696
|
// A single stream chunk may contain multiple tool call deltas.
|
|
@@ -675,7 +717,6 @@ class LLMService {
|
|
|
675
717
|
}
|
|
676
718
|
}
|
|
677
719
|
// Handle tool_calls from message (some APIs like DashScope may use this format)
|
|
678
|
-
const msg = chunk.choices?.[0]?.message;
|
|
679
720
|
if (msg?.tool_calls && !delta?.tool_calls) {
|
|
680
721
|
for (const msgTc of msg.tool_calls) {
|
|
681
722
|
const existing = toolCallsMap.get(msgTc.index ?? 0);
|
|
@@ -695,13 +736,18 @@ class LLMService {
|
|
|
695
736
|
}
|
|
696
737
|
}
|
|
697
738
|
if (chunk.usage) {
|
|
698
|
-
usage = extractLLMUsage(chunk.usage, chunk, chunk.id ?? providerRequestId);
|
|
739
|
+
usage = this.annotateEffortUsage(extractLLMUsage(chunk.usage, chunk, chunk.id ?? providerRequestId), this.effortSnapshotForModel(effortSnapshot, usedModel));
|
|
699
740
|
}
|
|
700
741
|
if (chunk.id)
|
|
701
742
|
providerRequestId = chunk.id;
|
|
702
743
|
if (chunk.model) {
|
|
703
744
|
usedModel = chunk.model;
|
|
704
745
|
}
|
|
746
|
+
const chunkFinishReason = rawFinishReason(choice?.finish_reason);
|
|
747
|
+
if (chunkFinishReason) {
|
|
748
|
+
providerFinishReason = chunkFinishReason;
|
|
749
|
+
finishReason = normalizeFinishReason(chunkFinishReason);
|
|
750
|
+
}
|
|
705
751
|
}
|
|
706
752
|
const toolCalls = Array.from(toolCallsMap.entries())
|
|
707
753
|
.sort(([a], [b]) => Number(a) - Number(b))
|
|
@@ -720,6 +766,8 @@ class LLMService {
|
|
|
720
766
|
}
|
|
721
767
|
}
|
|
722
768
|
}
|
|
769
|
+
finishReason ?? (finishReason = toolCalls.length > 0 ? 'tool_calls' : undefined);
|
|
770
|
+
const finalContent = finalizeStreamText(content, bufferForRecovery);
|
|
723
771
|
if (usage)
|
|
724
772
|
this.publishUsage(usage, usedModel, 'chat_stream');
|
|
725
773
|
this.consecutive529Errors = 0;
|
|
@@ -730,9 +778,11 @@ class LLMService {
|
|
|
730
778
|
retryErrorTypes: [...requestDiagnostics.retryErrorTypes],
|
|
731
779
|
};
|
|
732
780
|
return {
|
|
733
|
-
content,
|
|
781
|
+
content: finalContent,
|
|
734
782
|
model: usedModel,
|
|
735
783
|
usage,
|
|
784
|
+
finishReason,
|
|
785
|
+
rawFinishReason: providerFinishReason,
|
|
736
786
|
toolCalls: toolCalls.length > 0 ? toolCalls : undefined,
|
|
737
787
|
};
|
|
738
788
|
}, retryConfig);
|
|
@@ -827,6 +877,39 @@ class LLMService {
|
|
|
827
877
|
setModel(model) {
|
|
828
878
|
this.config.model = model;
|
|
829
879
|
}
|
|
880
|
+
setEffortContext(input) {
|
|
881
|
+
const resolved = (0, effort_1.resolveEffort)({ session: input.preference, capability: input.capability });
|
|
882
|
+
if (input.preference !== 'auto' && !resolved.supported) {
|
|
883
|
+
throw new Error(resolved.warning ?? 'Effort is not supported by the active profile.');
|
|
884
|
+
}
|
|
885
|
+
this.effortContext = {
|
|
886
|
+
preference: input.preference,
|
|
887
|
+
protocol: input.protocol,
|
|
888
|
+
...(input.capability
|
|
889
|
+
? {
|
|
890
|
+
capability: {
|
|
891
|
+
...input.capability,
|
|
892
|
+
supportedLevels: [...input.capability.supportedLevels],
|
|
893
|
+
},
|
|
894
|
+
}
|
|
895
|
+
: {}),
|
|
896
|
+
...(input.fallbackCapability
|
|
897
|
+
? {
|
|
898
|
+
fallbackCapability: {
|
|
899
|
+
...input.fallbackCapability,
|
|
900
|
+
supportedLevels: [...input.fallbackCapability.supportedLevels],
|
|
901
|
+
},
|
|
902
|
+
}
|
|
903
|
+
: {}),
|
|
904
|
+
};
|
|
905
|
+
return resolved;
|
|
906
|
+
}
|
|
907
|
+
getResolvedEffort() {
|
|
908
|
+
return (0, effort_1.resolveEffort)({
|
|
909
|
+
session: this.effortContext.preference,
|
|
910
|
+
capability: this.effortContext.capability,
|
|
911
|
+
});
|
|
912
|
+
}
|
|
830
913
|
/**
|
|
831
914
|
* 获取当前模型
|
|
832
915
|
*/
|
|
@@ -851,6 +934,49 @@ class LLMService {
|
|
|
851
934
|
};
|
|
852
935
|
}
|
|
853
936
|
// ---- Internal ----
|
|
937
|
+
createEffortRequestSnapshot() {
|
|
938
|
+
const preference = this.effortContext.preference;
|
|
939
|
+
const primaryCapability = this.effortContext.capability
|
|
940
|
+
? {
|
|
941
|
+
...this.effortContext.capability,
|
|
942
|
+
supportedLevels: [...this.effortContext.capability.supportedLevels],
|
|
943
|
+
}
|
|
944
|
+
: undefined;
|
|
945
|
+
const fallbackCapability = this.effortContext.fallbackCapability
|
|
946
|
+
? {
|
|
947
|
+
...this.effortContext.fallbackCapability,
|
|
948
|
+
supportedLevels: [...this.effortContext.fallbackCapability.supportedLevels],
|
|
949
|
+
}
|
|
950
|
+
: undefined;
|
|
951
|
+
return {
|
|
952
|
+
primaryModel: this.config.model,
|
|
953
|
+
...(this.config.fallbackModel ? { fallbackModel: this.config.fallbackModel } : {}),
|
|
954
|
+
primary: {
|
|
955
|
+
protocol: this.effortContext.protocol,
|
|
956
|
+
capability: primaryCapability,
|
|
957
|
+
resolved: (0, effort_1.resolveEffort)({ session: preference, capability: primaryCapability }),
|
|
958
|
+
},
|
|
959
|
+
fallback: {
|
|
960
|
+
protocol: this.effortContext.protocol,
|
|
961
|
+
capability: fallbackCapability,
|
|
962
|
+
resolved: (0, effort_1.resolveEffort)({ session: preference, capability: fallbackCapability }),
|
|
963
|
+
},
|
|
964
|
+
};
|
|
965
|
+
}
|
|
966
|
+
effortSnapshotForModel(snapshot, model) {
|
|
967
|
+
return snapshot.fallbackModel && model === snapshot.fallbackModel
|
|
968
|
+
? snapshot.fallback
|
|
969
|
+
: snapshot.primary;
|
|
970
|
+
}
|
|
971
|
+
annotateEffortUsage(usage, snapshot) {
|
|
972
|
+
return {
|
|
973
|
+
...usage,
|
|
974
|
+
effortRequested: snapshot.resolved.requested,
|
|
975
|
+
...(snapshot.resolved.effective ? { effortEffective: snapshot.resolved.effective } : {}),
|
|
976
|
+
effortSource: snapshot.resolved.source,
|
|
977
|
+
providerProtocol: snapshot.protocol,
|
|
978
|
+
};
|
|
979
|
+
}
|
|
854
980
|
createRequestDiagnostics() {
|
|
855
981
|
return {
|
|
856
982
|
retryCount: 0,
|
|
@@ -859,12 +985,23 @@ class LLMService {
|
|
|
859
985
|
fallbackTriggered: false,
|
|
860
986
|
finalModel: this.config.model,
|
|
861
987
|
usingFallback: this.usingFallback,
|
|
988
|
+
recoveryCount: 0,
|
|
989
|
+
unknownBilledAttemptCount: 0,
|
|
990
|
+
usageConfidence: 'unknown',
|
|
862
991
|
};
|
|
863
992
|
}
|
|
864
993
|
applyResilienceDiagnostics(target, diagnostics) {
|
|
865
994
|
const retriedAttempts = diagnostics.attempts.filter(attempt => attempt.backoffMs !== undefined);
|
|
866
995
|
const lastRetriedAttempt = retriedAttempts[retriedAttempts.length - 1];
|
|
867
996
|
target.retryCount += diagnostics.retryCount;
|
|
997
|
+
target.recoveryCount += diagnostics.recoveryCount;
|
|
998
|
+
target.unknownBilledAttemptCount += diagnostics.unknownBilledAttemptCount;
|
|
999
|
+
if (diagnostics.usageConfidence === 'partial' || target.usageConfidence === 'partial') {
|
|
1000
|
+
target.usageConfidence = 'partial';
|
|
1001
|
+
}
|
|
1002
|
+
else if (diagnostics.usageConfidence === 'exact') {
|
|
1003
|
+
target.usageConfidence = 'exact';
|
|
1004
|
+
}
|
|
868
1005
|
target.retryDelayMs += diagnostics.totalBackoffMs;
|
|
869
1006
|
target.retryErrorTypes.push(...retriedAttempts.map(attempt => providerErrorTypeForFailureKind(attempt.failureKind)));
|
|
870
1007
|
if (lastRetriedAttempt) {
|
|
@@ -872,13 +1009,11 @@ class LLMService {
|
|
|
872
1009
|
target.lastRetryStatus = lastRetriedAttempt.status;
|
|
873
1010
|
}
|
|
874
1011
|
if (diagnostics.fallbackCount > 0) {
|
|
875
|
-
// The current coordinator records fallback dispositions but does not yet
|
|
876
|
-
// switch models. Surface the count through the legacy diagnostics contract
|
|
877
|
-
// so Goal accounting fails closed without claiming that a switch occurred.
|
|
878
1012
|
target.fallbackTriggered = true;
|
|
879
1013
|
target.fallbackFromModel = diagnostics.requestedModel;
|
|
880
1014
|
if (diagnostics.finalModel && diagnostics.finalModel !== diagnostics.requestedModel) {
|
|
881
1015
|
target.fallbackToModel = diagnostics.finalModel;
|
|
1016
|
+
this.usingFallback = true;
|
|
882
1017
|
}
|
|
883
1018
|
}
|
|
884
1019
|
target.finalModel = diagnostics.finalModel ?? target.finalModel;
|
|
@@ -886,6 +1021,7 @@ class LLMService {
|
|
|
886
1021
|
}
|
|
887
1022
|
/** 转换为 OpenAI SDK 消息格式 */
|
|
888
1023
|
toOpenAIMessages(messages) {
|
|
1024
|
+
(0, tool_call_groups_1.assertToolCallGroups)(messages);
|
|
889
1025
|
return messages.map(msg => {
|
|
890
1026
|
if (msg.role === 'tool') {
|
|
891
1027
|
return {
|