@ai-agent-forge/agent-forge 0.88.0 → 0.88.2
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 +73 -0
- package/bundled-plugins/agent-loop-policy/agent-forge.json +19 -0
- package/bundled-plugins/agent-loop-policy/dist/entry.d.ts +28 -0
- package/bundled-plugins/agent-loop-policy/dist/entry.d.ts.map +1 -0
- package/bundled-plugins/agent-loop-policy/dist/entry.js +69 -0
- package/bundled-plugins/agent-loop-policy/dist/entry.js.map +1 -0
- package/bundled-plugins/agent-loop-policy/dist/loop-guard.d.ts +199 -0
- package/bundled-plugins/agent-loop-policy/dist/loop-guard.d.ts.map +1 -0
- package/bundled-plugins/agent-loop-policy/dist/loop-guard.js +208 -0
- package/bundled-plugins/agent-loop-policy/dist/loop-guard.js.map +1 -0
- package/bundled-plugins/agent-loop-policy/dist/run-loop-strategy.d.ts +17 -0
- package/bundled-plugins/agent-loop-policy/dist/run-loop-strategy.d.ts.map +1 -0
- package/bundled-plugins/agent-loop-policy/dist/run-loop-strategy.js +18 -0
- package/bundled-plugins/agent-loop-policy/dist/run-loop-strategy.js.map +1 -0
- package/bundled-plugins/agent-loop-policy/plugin.json +7 -0
- package/bundled-plugins/coding-tools/agent-forge.json +19 -0
- package/{dist/core/tools → bundled-plugins/coding-tools/dist}/bash.d.ts +5 -44
- package/bundled-plugins/coding-tools/dist/bash.d.ts.map +1 -0
- package/{dist/core/tools → bundled-plugins/coding-tools/dist}/bash.js +15 -119
- package/bundled-plugins/coding-tools/dist/bash.js.map +1 -0
- package/bundled-plugins/coding-tools/dist/capability.d.ts +25 -0
- package/bundled-plugins/coding-tools/dist/capability.d.ts.map +1 -0
- package/bundled-plugins/coding-tools/dist/capability.js +98 -0
- package/bundled-plugins/coding-tools/dist/capability.js.map +1 -0
- package/bundled-plugins/coding-tools/dist/config.d.ts +8 -0
- package/bundled-plugins/coding-tools/dist/config.d.ts.map +1 -0
- package/bundled-plugins/coding-tools/dist/config.js +8 -0
- package/bundled-plugins/coding-tools/dist/config.js.map +1 -0
- package/{dist/core/tools → bundled-plugins/coding-tools/dist}/edit.d.ts +3 -3
- package/bundled-plugins/coding-tools/dist/edit.d.ts.map +1 -0
- package/{dist/core/tools → bundled-plugins/coding-tools/dist}/edit.js +12 -10
- package/bundled-plugins/coding-tools/dist/edit.js.map +1 -0
- package/bundled-plugins/coding-tools/dist/entry.d.ts +14 -0
- package/bundled-plugins/coding-tools/dist/entry.d.ts.map +1 -0
- package/bundled-plugins/coding-tools/dist/entry.js +23 -0
- package/bundled-plugins/coding-tools/dist/entry.js.map +1 -0
- package/{dist/core/tools → bundled-plugins/coding-tools/dist}/find.d.ts +4 -4
- package/bundled-plugins/coding-tools/dist/find.d.ts.map +1 -0
- package/{dist/core/tools → bundled-plugins/coding-tools/dist}/find.js +10 -8
- package/bundled-plugins/coding-tools/dist/find.js.map +1 -0
- package/{dist/core/tools → bundled-plugins/coding-tools/dist}/grep.d.ts +3 -3
- package/bundled-plugins/coding-tools/dist/grep.d.ts.map +1 -0
- package/{dist/core/tools → bundled-plugins/coding-tools/dist}/grep.js +10 -8
- package/bundled-plugins/coding-tools/dist/grep.js.map +1 -0
- package/bundled-plugins/coding-tools/dist/index.d.ts +17 -0
- package/bundled-plugins/coding-tools/dist/index.d.ts.map +1 -0
- package/bundled-plugins/coding-tools/dist/index.js +17 -0
- package/bundled-plugins/coding-tools/dist/index.js.map +1 -0
- package/{dist/core/tools → bundled-plugins/coding-tools/dist}/ls.d.ts +3 -3
- package/bundled-plugins/coding-tools/dist/ls.d.ts.map +1 -0
- package/{dist/core/tools → bundled-plugins/coding-tools/dist}/ls.js +8 -6
- package/{dist/core/tools → bundled-plugins/coding-tools/dist}/ls.js.map +1 -1
- package/{dist/core/tools → bundled-plugins/coding-tools/dist}/powershell.d.ts +2 -1
- package/bundled-plugins/coding-tools/dist/powershell.d.ts.map +1 -0
- package/{dist/core/tools → bundled-plugins/coding-tools/dist}/powershell.js +6 -3
- package/bundled-plugins/coding-tools/dist/powershell.js.map +1 -0
- package/{dist/core/tools → bundled-plugins/coding-tools/dist}/read.d.ts +3 -3
- package/bundled-plugins/coding-tools/dist/read.d.ts.map +1 -0
- package/{dist/core/tools → bundled-plugins/coding-tools/dist}/read.js +15 -13
- package/bundled-plugins/coding-tools/dist/read.js.map +1 -0
- package/bundled-plugins/coding-tools/dist/types.d.ts +74 -0
- package/bundled-plugins/coding-tools/dist/types.d.ts.map +1 -0
- package/bundled-plugins/coding-tools/dist/types.js +28 -0
- package/bundled-plugins/coding-tools/dist/types.js.map +1 -0
- package/{dist/core/tools → bundled-plugins/coding-tools/dist}/write.d.ts +2 -2
- package/bundled-plugins/coding-tools/dist/write.d.ts.map +1 -0
- package/{dist/core/tools → bundled-plugins/coding-tools/dist}/write.js +11 -9
- package/bundled-plugins/coding-tools/dist/write.js.map +1 -0
- package/bundled-plugins/coding-tools/plugin.json +10 -0
- package/bundled-plugins/compaction-policy/agent-forge.json +19 -0
- package/bundled-plugins/compaction-policy/dist/branch-summary-policy.d.ts +6 -0
- package/bundled-plugins/compaction-policy/dist/branch-summary-policy.d.ts.map +1 -0
- package/bundled-plugins/compaction-policy/dist/branch-summary-policy.js +19 -0
- package/bundled-plugins/compaction-policy/dist/branch-summary-policy.js.map +1 -0
- package/bundled-plugins/compaction-policy/dist/compaction-policy.d.ts +6 -0
- package/bundled-plugins/compaction-policy/dist/compaction-policy.d.ts.map +1 -0
- package/bundled-plugins/compaction-policy/dist/compaction-policy.js +38 -0
- package/bundled-plugins/compaction-policy/dist/compaction-policy.js.map +1 -0
- package/bundled-plugins/compaction-policy/dist/entry.d.ts +13 -0
- package/bundled-plugins/compaction-policy/dist/entry.d.ts.map +1 -0
- package/bundled-plugins/compaction-policy/dist/entry.js +23 -0
- package/bundled-plugins/compaction-policy/dist/entry.js.map +1 -0
- package/bundled-plugins/compaction-policy/plugin.json +10 -0
- package/bundled-plugins/mcp-http/dist/index.d.ts +8 -0
- package/bundled-plugins/mcp-http/dist/index.d.ts.map +1 -0
- package/bundled-plugins/mcp-http/dist/index.js +8 -0
- package/bundled-plugins/mcp-http/dist/index.js.map +1 -0
- package/bundled-plugins/mcp-http/dist/mcp-http.d.ts.map +1 -0
- package/{dist/plugins → bundled-plugins/mcp-http/dist}/mcp-http.js +1 -1
- package/bundled-plugins/mcp-http/dist/mcp-http.js.map +1 -0
- package/bundled-plugins/overflow-policy/agent-forge.json +19 -0
- package/bundled-plugins/overflow-policy/dist/entry.d.ts +16 -0
- package/bundled-plugins/overflow-policy/dist/entry.d.ts.map +1 -0
- package/bundled-plugins/overflow-policy/dist/entry.js +35 -0
- package/bundled-plugins/overflow-policy/dist/entry.js.map +1 -0
- package/bundled-plugins/overflow-policy/plugin.json +10 -0
- package/bundled-plugins/provider-failover/agent-forge.json +19 -0
- package/bundled-plugins/provider-failover/dist/entry.d.ts +8 -0
- package/bundled-plugins/provider-failover/dist/entry.d.ts.map +1 -0
- package/bundled-plugins/provider-failover/dist/entry.js +8 -0
- package/bundled-plugins/provider-failover/dist/entry.js.map +1 -0
- package/bundled-plugins/provider-failover/dist/provider-failover.d.ts +122 -0
- package/bundled-plugins/provider-failover/dist/provider-failover.d.ts.map +1 -0
- package/{dist/core/extensions → bundled-plugins/provider-failover/dist}/provider-failover.js +143 -56
- package/bundled-plugins/provider-failover/dist/provider-failover.js.map +1 -0
- package/bundled-plugins/provider-failover/plugin.json +7 -0
- package/bundled-plugins/retry-policy/agent-forge.json +19 -0
- package/bundled-plugins/retry-policy/dist/entry.d.ts +16 -0
- package/bundled-plugins/retry-policy/dist/entry.d.ts.map +1 -0
- package/bundled-plugins/retry-policy/dist/entry.js +34 -0
- package/bundled-plugins/retry-policy/dist/entry.js.map +1 -0
- package/bundled-plugins/retry-policy/plugin.json +10 -0
- package/dist/bundle/.build-manifest.json +109 -155
- package/dist/bundle/chunks/{anthropic-messages-ALDZBUKI.js → anthropic-messages-PLAKXR73.js} +1 -1
- package/dist/bundle/chunks/{azure-openai-responses-A2WJWZFB.js → azure-openai-responses-OUWQ2AZD.js} +1 -1
- package/dist/bundle/chunks/chunk-44I47ACN.js +13 -0
- package/dist/bundle/chunks/chunk-6F5JWGKE.js +4 -0
- package/dist/bundle/chunks/{chunk-CIX3FSBK.js → chunk-A3JYRWB6.js} +1 -1
- package/dist/bundle/chunks/{chunk-SQFG22WN.js → chunk-AC2FIS4G.js} +1 -1
- package/dist/bundle/chunks/chunk-HTC5K5SM.js +866 -0
- package/dist/bundle/chunks/{chunk-YJCQVXW5.js → chunk-HTEVUY7F.js} +1 -1
- package/dist/bundle/chunks/{chunk-Y7HXTASS.js → chunk-HV64ASMT.js} +1 -1
- package/dist/bundle/chunks/chunk-LSP24WNH.js +665 -0
- package/dist/bundle/chunks/{chunk-7ZY7IXZD.js → chunk-TRDNDS6A.js} +1 -1
- package/dist/bundle/chunks/{google-generative-ai-NIB4WONV.js → google-generative-ai-DLII6DAT.js} +1 -1
- package/dist/bundle/chunks/{google-vertex-DCPYUEUO.js → google-vertex-G7BZL7GM.js} +1 -1
- package/dist/bundle/chunks/image-resize-worker.js +4 -4
- package/dist/bundle/chunks/{mistral-conversations-OC6LA5XL.js → mistral-conversations-JXUK24ID.js} +1 -1
- package/dist/bundle/chunks/{openai-codex-responses-IO2X4Y7L.js → openai-codex-responses-5GSGFIPG.js} +1 -1
- package/dist/bundle/chunks/{openai-completions-XYQQHETU.js → openai-completions-EI2I6DTG.js} +1 -1
- package/dist/bundle/chunks/{openai-responses-DLIRN3CI.js → openai-responses-AUJQ3NWT.js} +1 -1
- package/dist/bundle/chunks/{pi-messages-E6RRYBO7.js → pi-messages-PWU2VJMR.js} +1 -1
- package/dist/bundle/chunks/virtual-modules-MRXD3RWG.js +5 -0
- package/dist/bundle/cli.js +1 -1
- package/dist/bundle/client.js +1 -1
- package/dist/bundle/index.js +3 -3
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/capabilities/builtin.d.ts +1 -1
- package/dist/capabilities/builtin.d.ts.map +1 -1
- package/dist/capabilities/builtin.js +5 -0
- package/dist/capabilities/builtin.js.map +1 -1
- package/dist/cli/plugin-command.d.ts.map +1 -1
- package/dist/cli/plugin-command.js +25 -3
- package/dist/cli/plugin-command.js.map +1 -1
- package/dist/config.d.ts +2 -3
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +2 -4
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-bash.d.ts +1 -1
- package/dist/core/agent-session-bash.d.ts.map +1 -1
- package/dist/core/agent-session-bash.js +1 -1
- package/dist/core/agent-session-bash.js.map +1 -1
- package/dist/core/agent-session-compaction.d.ts.map +1 -1
- package/dist/core/agent-session-compaction.js +14 -1
- package/dist/core/agent-session-compaction.js.map +1 -1
- package/dist/core/agent-session-internal.d.ts +3 -1
- package/dist/core/agent-session-internal.d.ts.map +1 -1
- package/dist/core/agent-session-internal.js.map +1 -1
- package/dist/core/agent-session-loop.d.ts +4 -3
- package/dist/core/agent-session-loop.d.ts.map +1 -1
- package/dist/core/agent-session-loop.js +9 -6
- package/dist/core/agent-session-loop.js.map +1 -1
- package/dist/core/agent-session-retry.d.ts +1 -1
- package/dist/core/agent-session-retry.d.ts.map +1 -1
- package/dist/core/agent-session-retry.js +32 -3
- package/dist/core/agent-session-retry.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +2 -0
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +31 -9
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session-store.d.ts.map +1 -1
- package/dist/core/agent-session-store.js +6 -1
- package/dist/core/agent-session-store.js.map +1 -1
- package/dist/core/agent-session-tools.d.ts.map +1 -1
- package/dist/core/agent-session-tools.js +18 -1
- package/dist/core/agent-session-tools.js.map +1 -1
- package/dist/core/agent-session.d.ts +34 -11
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +114 -38
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/bash-executor.d.ts +1 -1
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/extensions/bootstrap-agent-loop.d.ts +23 -151
- package/dist/core/extensions/bootstrap-agent-loop.d.ts.map +1 -1
- package/dist/core/extensions/bootstrap-agent-loop.js +28 -290
- package/dist/core/extensions/bootstrap-agent-loop.js.map +1 -1
- package/dist/core/extensions/capability-runtime-types.d.ts +5 -3
- package/dist/core/extensions/capability-runtime-types.d.ts.map +1 -1
- package/dist/core/extensions/capability-runtime-types.js.map +1 -1
- package/dist/core/extensions/capability-runtime.d.ts.map +1 -1
- package/dist/core/extensions/capability-runtime.js +42 -6
- package/dist/core/extensions/capability-runtime.js.map +1 -1
- package/dist/core/extensions/index.d.ts +12 -5
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js +12 -5
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/virtual-modules.d.ts.map +1 -1
- package/dist/core/extensions/virtual-modules.js +65 -0
- package/dist/core/extensions/virtual-modules.js.map +1 -1
- package/dist/core/facade/coding-agent-facade.d.ts +1 -1
- package/dist/core/facade/coding-agent-facade.d.ts.map +1 -1
- package/dist/core/facade/coding-agent-facade.js.map +1 -1
- package/dist/core/i18n/locales/zh-cn/cli.d.ts.map +1 -1
- package/dist/core/i18n/locales/zh-cn/cli.js +2 -0
- package/dist/core/i18n/locales/zh-cn/cli.js.map +1 -1
- package/dist/core/i18n/locales/zh-cn/core-contract-core.d.ts +1 -1
- package/dist/core/i18n/locales/zh-cn/core-contract-core.d.ts.map +1 -1
- package/dist/core/i18n/locales/zh-cn/core-contract-core.js +1 -1
- package/dist/core/i18n/locales/zh-cn/core-contract-core.js.map +1 -1
- package/dist/core/i18n/locales/zh-cn/core-contract-extensions.d.ts.map +1 -1
- package/dist/core/i18n/locales/zh-cn/core-contract-extensions.js +2 -4
- package/dist/core/i18n/locales/zh-cn/core-contract-extensions.js.map +1 -1
- package/dist/core/i18n/locales/zh-cn/core-errors.d.ts.map +1 -1
- package/dist/core/i18n/locales/zh-cn/core-errors.js +3 -1
- package/dist/core/i18n/locales/zh-cn/core-errors.js.map +1 -1
- package/dist/core/i18n/locales/zh-cn/index.d.ts.map +1 -1
- package/dist/core/i18n/locales/zh-cn/index.js +2 -0
- package/dist/core/i18n/locales/zh-cn/index.js.map +1 -1
- package/dist/core/i18n/locales/zh-cn/interactive-mode.d.ts.map +1 -1
- package/dist/core/i18n/locales/zh-cn/interactive-mode.js +5 -0
- package/dist/core/i18n/locales/zh-cn/interactive-mode.js.map +1 -1
- package/dist/core/i18n/locales/zh-cn/session-cleanup.d.ts +7 -0
- package/dist/core/i18n/locales/zh-cn/session-cleanup.d.ts.map +1 -0
- package/dist/core/i18n/locales/zh-cn/session-cleanup.js +15 -0
- package/dist/core/i18n/locales/zh-cn/session-cleanup.js.map +1 -0
- package/dist/core/i18n/locales/zh-cn/slash-commands.d.ts.map +1 -1
- package/dist/core/i18n/locales/zh-cn/slash-commands.js +1 -0
- package/dist/core/i18n/locales/zh-cn/slash-commands.js.map +1 -1
- package/dist/core/sdk.d.ts +10 -3
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +287 -78
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-cleanup.d.ts +49 -0
- package/dist/core/session-cleanup.d.ts.map +1 -0
- package/dist/core/session-cleanup.js +159 -0
- package/dist/core/session-cleanup.js.map +1 -0
- package/dist/core/session-index.d.ts +75 -0
- package/dist/core/session-index.d.ts.map +1 -0
- package/dist/core/session-index.js +455 -0
- package/dist/core/session-index.js.map +1 -0
- package/dist/core/session-manager.d.ts +9 -0
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +202 -47
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +5 -0
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +12 -1
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/bash-operations.d.ts +41 -0
- package/dist/core/tools/bash-operations.d.ts.map +1 -0
- package/dist/core/tools/bash-operations.js +113 -0
- package/dist/core/tools/bash-operations.js.map +1 -0
- package/dist/core/tools/capability-mount.d.ts +40 -0
- package/dist/core/tools/capability-mount.d.ts.map +1 -0
- package/dist/core/tools/capability-mount.js +112 -0
- package/dist/core/tools/capability-mount.js.map +1 -0
- package/dist/core/tools/index.d.ts +12 -36
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +1 -117
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/readme-path.d.ts +3 -0
- package/dist/core/tools/readme-path.d.ts.map +1 -0
- package/dist/core/tools/readme-path.js +15 -0
- package/dist/core/tools/readme-path.js.map +1 -0
- package/dist/index.d.ts +3 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -39
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +1 -0
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +3 -0
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +27 -5
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector-search.js +5 -1
- package/dist/modes/interactive/components/session-selector-search.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +9 -0
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +17 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +52 -25
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tool-run-group.d.ts +44 -0
- package/dist/modes/interactive/components/tool-run-group.d.ts.map +1 -0
- package/dist/modes/interactive/components/tool-run-group.js +121 -0
- package/dist/modes/interactive/components/tool-run-group.js.map +1 -0
- package/dist/modes/interactive/interactive-commands.d.ts +2 -0
- package/dist/modes/interactive/interactive-commands.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-commands.js +7 -0
- package/dist/modes/interactive/interactive-commands.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +18 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +85 -3
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/plugins/ecosystem/cli.d.ts.map +1 -1
- package/dist/plugins/ecosystem/cli.js +20 -5
- package/dist/plugins/ecosystem/cli.js.map +1 -1
- package/dist/plugins/ecosystem/node-npm-registry-source.d.ts +7 -2
- package/dist/plugins/ecosystem/node-npm-registry-source.d.ts.map +1 -1
- package/dist/plugins/ecosystem/node-npm-registry-source.js +64 -9
- package/dist/plugins/ecosystem/node-npm-registry-source.js.map +1 -1
- package/dist/plugins/ecosystem/node-plugin-acquisition-host.d.ts.map +1 -1
- package/dist/plugins/ecosystem/node-plugin-acquisition-host.js +6 -0
- package/dist/plugins/ecosystem/node-plugin-acquisition-host.js.map +1 -1
- package/dist/plugins/ecosystem/node-plugin-bootstrap.d.ts +7 -1
- package/dist/plugins/ecosystem/node-plugin-bootstrap.d.ts.map +1 -1
- package/dist/plugins/ecosystem/node-plugin-bootstrap.js +50 -3
- package/dist/plugins/ecosystem/node-plugin-bootstrap.js.map +1 -1
- package/dist/plugins/ecosystem/plugin-bootstrap.d.ts +28 -16
- package/dist/plugins/ecosystem/plugin-bootstrap.d.ts.map +1 -1
- package/dist/plugins/ecosystem/plugin-bootstrap.js +35 -33
- package/dist/plugins/ecosystem/plugin-bootstrap.js.map +1 -1
- package/dist/profile/plugin-profiles.d.ts +1 -1
- package/dist/profile/plugin-profiles.d.ts.map +1 -1
- package/dist/profile/plugin-profiles.js +18 -0
- package/dist/profile/plugin-profiles.js.map +1 -1
- package/dist/profiles/builtin-suites.d.ts +19 -5
- package/dist/profiles/builtin-suites.d.ts.map +1 -1
- package/dist/profiles/builtin-suites.js +26 -6
- package/dist/profiles/builtin-suites.js.map +1 -1
- package/docs/settings.md +354 -354
- package/docs/usage.md +292 -292
- package/examples/extensions/bash-spawn-hook/index.ts +7 -2
- package/examples/extensions/built-in-tool-renderer/index.ts +4 -2
- package/examples/extensions/minimal-mode/index.ts +2 -2
- package/examples/extensions/truncated-tool/index.ts +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/extensions/with-deps/plugin.json +1 -1
- package/package.json +3 -2
- package/dist/bundle/chunks/chunk-6ZKDNZHA.js +0 -145
- package/dist/bundle/chunks/chunk-HLJEVRWP.js +0 -13
- package/dist/bundle/chunks/chunk-YGHQME4V.js +0 -1456
- package/dist/bundle/chunks/virtual-modules-KZ5DRH7Q.js +0 -2
- package/dist/core/extensions/bootstrap-branch-summary-policy.d.ts +0 -7
- package/dist/core/extensions/bootstrap-branch-summary-policy.d.ts.map +0 -1
- package/dist/core/extensions/bootstrap-branch-summary-policy.js +0 -28
- package/dist/core/extensions/bootstrap-branch-summary-policy.js.map +0 -1
- package/dist/core/extensions/bootstrap-compaction-policy.d.ts +0 -7
- package/dist/core/extensions/bootstrap-compaction-policy.d.ts.map +0 -1
- package/dist/core/extensions/bootstrap-compaction-policy.js +0 -48
- package/dist/core/extensions/bootstrap-compaction-policy.js.map +0 -1
- package/dist/core/extensions/bootstrap-overflow-policy.d.ts +0 -7
- package/dist/core/extensions/bootstrap-overflow-policy.d.ts.map +0 -1
- package/dist/core/extensions/bootstrap-overflow-policy.js +0 -30
- package/dist/core/extensions/bootstrap-overflow-policy.js.map +0 -1
- package/dist/core/extensions/bootstrap-retry-policy.d.ts +0 -7
- package/dist/core/extensions/bootstrap-retry-policy.d.ts.map +0 -1
- package/dist/core/extensions/bootstrap-retry-policy.js +0 -29
- package/dist/core/extensions/bootstrap-retry-policy.js.map +0 -1
- package/dist/core/extensions/bootstrap-tools.d.ts +0 -20
- package/dist/core/extensions/bootstrap-tools.d.ts.map +0 -1
- package/dist/core/extensions/bootstrap-tools.js +0 -36
- package/dist/core/extensions/bootstrap-tools.js.map +0 -1
- package/dist/core/extensions/provider-failover.d.ts +0 -110
- package/dist/core/extensions/provider-failover.d.ts.map +0 -1
- package/dist/core/extensions/provider-failover.js.map +0 -1
- package/dist/core/tools/bash.d.ts.map +0 -1
- package/dist/core/tools/bash.js.map +0 -1
- package/dist/core/tools/edit.d.ts.map +0 -1
- package/dist/core/tools/edit.js.map +0 -1
- package/dist/core/tools/find.d.ts.map +0 -1
- package/dist/core/tools/find.js.map +0 -1
- package/dist/core/tools/grep.d.ts.map +0 -1
- package/dist/core/tools/grep.js.map +0 -1
- package/dist/core/tools/ls.d.ts.map +0 -1
- package/dist/core/tools/powershell.d.ts.map +0 -1
- package/dist/core/tools/powershell.js.map +0 -1
- package/dist/core/tools/read.d.ts.map +0 -1
- package/dist/core/tools/read.js.map +0 -1
- package/dist/core/tools/write.d.ts.map +0 -1
- package/dist/core/tools/write.js.map +0 -1
- package/dist/plugins/mcp-http.d.ts.map +0 -1
- package/dist/plugins/mcp-http.js.map +0 -1
- package/dist/profile/child-facade.d.ts +0 -44
- package/dist/profile/child-facade.d.ts.map +0 -1
- package/dist/profile/child-facade.js +0 -56
- package/dist/profile/child-facade.js.map +0 -1
- package/dist/profile/dependency-wiring.d.ts +0 -48
- package/dist/profile/dependency-wiring.d.ts.map +0 -1
- package/dist/profile/dependency-wiring.js +0 -56
- package/dist/profile/dependency-wiring.js.map +0 -1
- package/dist/profile/domain-recovery.d.ts +0 -60
- package/dist/profile/domain-recovery.d.ts.map +0 -1
- package/dist/profile/domain-recovery.js +0 -94
- package/dist/profile/domain-recovery.js.map +0 -1
- package/dist/profile/first-roles.d.ts +0 -30
- package/dist/profile/first-roles.d.ts.map +0 -1
- package/dist/profile/first-roles.js +0 -83
- package/dist/profile/first-roles.js.map +0 -1
- package/dist/profile/goal-plugin.d.ts +0 -38
- package/dist/profile/goal-plugin.d.ts.map +0 -1
- package/dist/profile/goal-plugin.js +0 -132
- package/dist/profile/goal-plugin.js.map +0 -1
- package/dist/profile/plan-plugin.d.ts +0 -44
- package/dist/profile/plan-plugin.d.ts.map +0 -1
- package/dist/profile/plan-plugin.js +0 -157
- package/dist/profile/plan-plugin.js.map +0 -1
- package/dist/profile/policy-manifest.d.ts +0 -53
- package/dist/profile/policy-manifest.d.ts.map +0 -1
- package/dist/profile/policy-manifest.js +0 -53
- package/dist/profile/policy-manifest.js.map +0 -1
- package/dist/profile/role-assembly.d.ts +0 -47
- package/dist/profile/role-assembly.d.ts.map +0 -1
- package/dist/profile/role-assembly.js +0 -31
- package/dist/profile/role-assembly.js.map +0 -1
- package/dist/profile/role-catalog.d.ts +0 -43
- package/dist/profile/role-catalog.d.ts.map +0 -1
- package/dist/profile/role-catalog.js +0 -132
- package/dist/profile/role-catalog.js.map +0 -1
- package/dist/profile/role-orchestrator.d.ts +0 -123
- package/dist/profile/role-orchestrator.d.ts.map +0 -1
- package/dist/profile/role-orchestrator.js +0 -195
- package/dist/profile/role-orchestrator.js.map +0 -1
- package/dist/profile/role-runner.d.ts +0 -99
- package/dist/profile/role-runner.d.ts.map +0 -1
- package/dist/profile/role-runner.js +0 -79
- package/dist/profile/role-runner.js.map +0 -1
- package/dist/profile/root-facade.d.ts +0 -36
- package/dist/profile/root-facade.d.ts.map +0 -1
- package/dist/profile/root-facade.js +0 -49
- package/dist/profile/root-facade.js.map +0 -1
- package/dist/profile/skill-discovery-wiring.d.ts +0 -58
- package/dist/profile/skill-discovery-wiring.d.ts.map +0 -1
- package/dist/profile/skill-discovery-wiring.js +0 -80
- package/dist/profile/skill-discovery-wiring.js.map +0 -1
- package/dist/profile/state-store.d.ts +0 -62
- package/dist/profile/state-store.d.ts.map +0 -1
- package/dist/profile/state-store.js +0 -144
- package/dist/profile/state-store.js.map +0 -1
- package/dist/profile/todo-plugin.d.ts +0 -37
- package/dist/profile/todo-plugin.d.ts.map +0 -1
- package/dist/profile/todo-plugin.js +0 -137
- package/dist/profile/todo-plugin.js.map +0 -1
- package/examples/extensions/mcp-stdio/index.d.ts +0 -64
- package/examples/extensions/mcp-stdio/index.d.ts.map +0 -1
- package/examples/extensions/mcp-stdio/index.js +0 -292
- package/examples/extensions/mcp-stdio/index.js.map +0 -1
- /package/{dist/plugins → bundled-plugins/mcp-http/dist}/mcp-http.d.ts +0 -0
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { createRequire as __piCreateRequire } from "node:module"; const require = __piCreateRequire(import.meta.url);
|
|
2
|
-
import{build_exports,dist_exports,require_undici,session_lineage_exports,subagent_exports,value_exports2 as value_exports}from"./chunk-6ZKDNZHA.js";import{__toESM}from"./chunk-4L3WN2XY.js";var undici=__toESM(require_undici(),1),VIRTUAL_MODULES={"@agent-forge/plugin-sdk":dist_exports,"@agent-forge/plugin-sdk/session-lineage":session_lineage_exports,"@agent-forge/protocol/subagent":subagent_exports,typebox:build_exports,"typebox/value":value_exports,undici};export{VIRTUAL_MODULES};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { type CapabilityPluginHandle } from "./capability-plugin.ts";
|
|
2
|
-
import type { CapabilityRuntime } from "./capability-runtime.ts";
|
|
3
|
-
export declare const BOOTSTRAP_BRANCH_SUMMARY_PLUGIN_ID = "agent-forge.bootstrap-branch-summary";
|
|
4
|
-
export declare const DEFAULT_BRANCH_SUMMARY_POLICY_NAME = "default";
|
|
5
|
-
/** First-party adapter that keeps the legacy branch summarizer replaceable. */
|
|
6
|
-
export declare function installBootstrapBranchSummaryPolicy(runtime: CapabilityRuntime): CapabilityPluginHandle;
|
|
7
|
-
//# sourceMappingURL=bootstrap-branch-summary-policy.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap-branch-summary-policy.d.ts","sourceRoot":"","sources":["../../../src/core/extensions/bootstrap-branch-summary-policy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,sBAAsB,EAA4B,MAAM,wBAAwB,CAAC;AAC/F,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAGjE,eAAO,MAAM,kCAAkC,yCAAyC,CAAC;AACzF,eAAO,MAAM,kCAAkC,YAAY,CAAC;AAE5D,+EAA+E;AAC/E,wBAAgB,mCAAmC,CAAC,OAAO,EAAE,iBAAiB,GAAG,sBAAsB,CAwBtG","sourcesContent":["import { generateBranchSummary } from \"../compaction/branch-summarization.ts\";\nimport { type CapabilityPluginHandle, loadCapabilityPluginSync } from \"./capability-plugin.ts\";\nimport type { CapabilityRuntime } from \"./capability-runtime.ts\";\nimport { type BranchSummaryRequest, EXPERIMENTAL_PUBLIC_API_VERSION } from \"./public-api.ts\";\n\nexport const BOOTSTRAP_BRANCH_SUMMARY_PLUGIN_ID = \"agent-forge.bootstrap-branch-summary\";\nexport const DEFAULT_BRANCH_SUMMARY_POLICY_NAME = \"default\";\n\n/** First-party adapter that keeps the legacy branch summarizer replaceable. */\nexport function installBootstrapBranchSummaryPolicy(runtime: CapabilityRuntime): CapabilityPluginHandle {\n\treturn loadCapabilityPluginSync(\n\t\truntime,\n\t\t{\n\t\t\tid: BOOTSTRAP_BRANCH_SUMMARY_PLUGIN_ID,\n\t\t\tversion: \"1.0.0\",\n\t\t\tapiVersion: EXPERIMENTAL_PUBLIC_API_VERSION,\n\t\t\tentry: \"<bootstrap>\",\n\t\t},\n\t\t(api) => {\n\t\t\tapi.registerBranchSummaryPolicy(DEFAULT_BRANCH_SUMMARY_POLICY_NAME, {\n\t\t\t\tasync summarize(request: BranchSummaryRequest) {\n\t\t\t\t\treturn generateBranchSummary(request.entries as Parameters<typeof generateBranchSummary>[0], {\n\t\t\t\t\t\tinvocation: request.invocation,\n\t\t\t\t\t\tmodel: request.model,\n\t\t\t\t\t\tsignal: request.signal,\n\t\t\t\t\t\tcustomInstructions: request.customInstructions,\n\t\t\t\t\t\treplaceInstructions: request.replaceInstructions,\n\t\t\t\t\t\treserveTokens: request.reserveTokens,\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t);\n}\n"]}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { generateBranchSummary } from "../compaction/branch-summarization.js";
|
|
2
|
-
import { loadCapabilityPluginSync } from "./capability-plugin.js";
|
|
3
|
-
import { EXPERIMENTAL_PUBLIC_API_VERSION } from "./public-api.js";
|
|
4
|
-
export const BOOTSTRAP_BRANCH_SUMMARY_PLUGIN_ID = "agent-forge.bootstrap-branch-summary";
|
|
5
|
-
export const DEFAULT_BRANCH_SUMMARY_POLICY_NAME = "default";
|
|
6
|
-
/** First-party adapter that keeps the legacy branch summarizer replaceable. */
|
|
7
|
-
export function installBootstrapBranchSummaryPolicy(runtime) {
|
|
8
|
-
return loadCapabilityPluginSync(runtime, {
|
|
9
|
-
id: BOOTSTRAP_BRANCH_SUMMARY_PLUGIN_ID,
|
|
10
|
-
version: "1.0.0",
|
|
11
|
-
apiVersion: EXPERIMENTAL_PUBLIC_API_VERSION,
|
|
12
|
-
entry: "<bootstrap>",
|
|
13
|
-
}, (api) => {
|
|
14
|
-
api.registerBranchSummaryPolicy(DEFAULT_BRANCH_SUMMARY_POLICY_NAME, {
|
|
15
|
-
async summarize(request) {
|
|
16
|
-
return generateBranchSummary(request.entries, {
|
|
17
|
-
invocation: request.invocation,
|
|
18
|
-
model: request.model,
|
|
19
|
-
signal: request.signal,
|
|
20
|
-
customInstructions: request.customInstructions,
|
|
21
|
-
replaceInstructions: request.replaceInstructions,
|
|
22
|
-
reserveTokens: request.reserveTokens,
|
|
23
|
-
});
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
//# sourceMappingURL=bootstrap-branch-summary-policy.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap-branch-summary-policy.js","sourceRoot":"","sources":["../../../src/core/extensions/bootstrap-branch-summary-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EAA+B,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAE/F,OAAO,EAA6B,+BAA+B,EAAE,MAAM,iBAAiB,CAAC;AAE7F,MAAM,CAAC,MAAM,kCAAkC,GAAG,sCAAsC,CAAC;AACzF,MAAM,CAAC,MAAM,kCAAkC,GAAG,SAAS,CAAC;AAE5D,+EAA+E;AAC/E,MAAM,UAAU,mCAAmC,CAAC,OAA0B,EAA0B;IACvG,OAAO,wBAAwB,CAC9B,OAAO,EACP;QACC,EAAE,EAAE,kCAAkC;QACtC,OAAO,EAAE,OAAO;QAChB,UAAU,EAAE,+BAA+B;QAC3C,KAAK,EAAE,aAAa;KACpB,EACD,CAAC,GAAG,EAAE,EAAE,CAAC;QACR,GAAG,CAAC,2BAA2B,CAAC,kCAAkC,EAAE;YACnE,KAAK,CAAC,SAAS,CAAC,OAA6B,EAAE;gBAC9C,OAAO,qBAAqB,CAAC,OAAO,CAAC,OAAsD,EAAE;oBAC5F,UAAU,EAAE,OAAO,CAAC,UAAU;oBAC9B,KAAK,EAAE,OAAO,CAAC,KAAK;oBACpB,MAAM,EAAE,OAAO,CAAC,MAAM;oBACtB,kBAAkB,EAAE,OAAO,CAAC,kBAAkB;oBAC9C,mBAAmB,EAAE,OAAO,CAAC,mBAAmB;oBAChD,aAAa,EAAE,OAAO,CAAC,aAAa;iBACpC,CAAC,CAAC;YAAA,CACH;SACD,CAAC,CAAC;IAAA,CACH,CACD,CAAC;AAAA,CACF","sourcesContent":["import { generateBranchSummary } from \"../compaction/branch-summarization.ts\";\nimport { type CapabilityPluginHandle, loadCapabilityPluginSync } from \"./capability-plugin.ts\";\nimport type { CapabilityRuntime } from \"./capability-runtime.ts\";\nimport { type BranchSummaryRequest, EXPERIMENTAL_PUBLIC_API_VERSION } from \"./public-api.ts\";\n\nexport const BOOTSTRAP_BRANCH_SUMMARY_PLUGIN_ID = \"agent-forge.bootstrap-branch-summary\";\nexport const DEFAULT_BRANCH_SUMMARY_POLICY_NAME = \"default\";\n\n/** First-party adapter that keeps the legacy branch summarizer replaceable. */\nexport function installBootstrapBranchSummaryPolicy(runtime: CapabilityRuntime): CapabilityPluginHandle {\n\treturn loadCapabilityPluginSync(\n\t\truntime,\n\t\t{\n\t\t\tid: BOOTSTRAP_BRANCH_SUMMARY_PLUGIN_ID,\n\t\t\tversion: \"1.0.0\",\n\t\t\tapiVersion: EXPERIMENTAL_PUBLIC_API_VERSION,\n\t\t\tentry: \"<bootstrap>\",\n\t\t},\n\t\t(api) => {\n\t\t\tapi.registerBranchSummaryPolicy(DEFAULT_BRANCH_SUMMARY_POLICY_NAME, {\n\t\t\t\tasync summarize(request: BranchSummaryRequest) {\n\t\t\t\t\treturn generateBranchSummary(request.entries as Parameters<typeof generateBranchSummary>[0], {\n\t\t\t\t\t\tinvocation: request.invocation,\n\t\t\t\t\t\tmodel: request.model,\n\t\t\t\t\t\tsignal: request.signal,\n\t\t\t\t\t\tcustomInstructions: request.customInstructions,\n\t\t\t\t\t\treplaceInstructions: request.replaceInstructions,\n\t\t\t\t\t\treserveTokens: request.reserveTokens,\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t);\n}\n"]}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { type CapabilityPluginHandle } from "./capability-plugin.ts";
|
|
2
|
-
import type { CapabilityRuntime } from "./capability-runtime.ts";
|
|
3
|
-
export declare const BOOTSTRAP_COMPACTION_PLUGIN_ID = "agent-forge.bootstrap-compaction";
|
|
4
|
-
export declare const DEFAULT_COMPACTION_POLICY_NAME = "default";
|
|
5
|
-
/** Register the current automatic-compaction decision as a replaceable first-party policy. */
|
|
6
|
-
export declare function installBootstrapCompactionPolicy(runtime: CapabilityRuntime): CapabilityPluginHandle;
|
|
7
|
-
//# sourceMappingURL=bootstrap-compaction-policy.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap-compaction-policy.d.ts","sourceRoot":"","sources":["../../../src/core/extensions/bootstrap-compaction-policy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,sBAAsB,EAA4B,MAAM,wBAAwB,CAAC;AAC/F,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAIjE,eAAO,MAAM,8BAA8B,qCAAqC,CAAC;AACjF,eAAO,MAAM,8BAA8B,YAAY,CAAC;AAExD,8FAA8F;AAC9F,wBAAgB,gCAAgC,CAAC,OAAO,EAAE,iBAAiB,GAAG,sBAAsB,CAkDnG","sourcesContent":["import { type CompactionPreparation, compact, prepareCompaction } from \"../compaction/index.ts\";\nimport { type CapabilityPluginHandle, loadCapabilityPluginSync } from \"./capability-plugin.ts\";\nimport type { CapabilityRuntime } from \"./capability-runtime.ts\";\nimport type { CompactionSummaryRequest } from \"./public-api.ts\";\nimport { EXPERIMENTAL_PUBLIC_API_VERSION } from \"./public-api.ts\";\n\nexport const BOOTSTRAP_COMPACTION_PLUGIN_ID = \"agent-forge.bootstrap-compaction\";\nexport const DEFAULT_COMPACTION_POLICY_NAME = \"default\";\n\n/** Register the current automatic-compaction decision as a replaceable first-party policy. */\nexport function installBootstrapCompactionPolicy(runtime: CapabilityRuntime): CapabilityPluginHandle {\n\treturn loadCapabilityPluginSync(\n\t\truntime,\n\t\t{\n\t\t\tid: BOOTSTRAP_COMPACTION_PLUGIN_ID,\n\t\t\tversion: \"0.0.0\",\n\t\t\tapiVersion: EXPERIMENTAL_PUBLIC_API_VERSION,\n\t\t\tentry: \"<embedded:bootstrap-compaction>\",\n\t\t\trequiredCapabilities: [\"compaction-policy\"],\n\t\t},\n\t\t(api) => {\n\t\t\tapi.registerCompactionPolicy(DEFAULT_COMPACTION_POLICY_NAME, {\n\t\t\t\tprepare: (request) =>\n\t\t\t\t\tprepareCompaction(\n\t\t\t\t\t\trequest.entries as Parameters<typeof prepareCompaction>[0],\n\t\t\t\t\t\trequest.settings as Parameters<typeof prepareCompaction>[1],\n\t\t\t\t\t),\n\t\t\t\tdecide: (request) => {\n\t\t\t\t\tif (request.reason === \"threshold\") {\n\t\t\t\t\t\tconst usage = request.contextUsage;\n\t\t\t\t\t\tconst overBudget =\n\t\t\t\t\t\t\tusage !== undefined &&\n\t\t\t\t\t\t\tusage.contextWindow > 0 &&\n\t\t\t\t\t\t\tusage.contextTokens > usage.contextWindow - usage.reserveTokens;\n\t\t\t\t\t\treturn { compact: overBudget, retry: false };\n\t\t\t\t\t}\n\t\t\t\t\tif (request.recoveryAttempted) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcompact: false,\n\t\t\t\t\t\t\tfailureMessage: request.contextOverflow\n\t\t\t\t\t\t\t\t? \"Context overflow recovery failed after one compact-and-retry attempt. Try reducing context or switching to a larger-context model.\"\n\t\t\t\t\t\t\t\t: \"Truncated response recovery failed after one compact-and-retry attempt.\",\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcompact: request.contextOverflow || request.recoverableLength,\n\t\t\t\t\t\tretry: request.canContinue,\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\tsummarize: async (request: CompactionSummaryRequest) =>\n\t\t\t\t\tcompact(request.preparation as CompactionPreparation, {\n\t\t\t\t\t\tinvocation: request.invocation,\n\t\t\t\t\t\tmodel: request.model,\n\t\t\t\t\t\tcustomInstructions: request.customInstructions,\n\t\t\t\t\t\tthinkingLevel: request.thinkingLevel,\n\t\t\t\t\t\tsignal: request.signal,\n\t\t\t\t\t}),\n\t\t\t});\n\t\t},\n\t);\n}\n"]}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { compact, prepareCompaction } from "../compaction/index.js";
|
|
2
|
-
import { loadCapabilityPluginSync } from "./capability-plugin.js";
|
|
3
|
-
import { EXPERIMENTAL_PUBLIC_API_VERSION } from "./public-api.js";
|
|
4
|
-
export const BOOTSTRAP_COMPACTION_PLUGIN_ID = "agent-forge.bootstrap-compaction";
|
|
5
|
-
export const DEFAULT_COMPACTION_POLICY_NAME = "default";
|
|
6
|
-
/** Register the current automatic-compaction decision as a replaceable first-party policy. */
|
|
7
|
-
export function installBootstrapCompactionPolicy(runtime) {
|
|
8
|
-
return loadCapabilityPluginSync(runtime, {
|
|
9
|
-
id: BOOTSTRAP_COMPACTION_PLUGIN_ID,
|
|
10
|
-
version: "0.0.0",
|
|
11
|
-
apiVersion: EXPERIMENTAL_PUBLIC_API_VERSION,
|
|
12
|
-
entry: "<embedded:bootstrap-compaction>",
|
|
13
|
-
requiredCapabilities: ["compaction-policy"],
|
|
14
|
-
}, (api) => {
|
|
15
|
-
api.registerCompactionPolicy(DEFAULT_COMPACTION_POLICY_NAME, {
|
|
16
|
-
prepare: (request) => prepareCompaction(request.entries, request.settings),
|
|
17
|
-
decide: (request) => {
|
|
18
|
-
if (request.reason === "threshold") {
|
|
19
|
-
const usage = request.contextUsage;
|
|
20
|
-
const overBudget = usage !== undefined &&
|
|
21
|
-
usage.contextWindow > 0 &&
|
|
22
|
-
usage.contextTokens > usage.contextWindow - usage.reserveTokens;
|
|
23
|
-
return { compact: overBudget, retry: false };
|
|
24
|
-
}
|
|
25
|
-
if (request.recoveryAttempted) {
|
|
26
|
-
return {
|
|
27
|
-
compact: false,
|
|
28
|
-
failureMessage: request.contextOverflow
|
|
29
|
-
? "Context overflow recovery failed after one compact-and-retry attempt. Try reducing context or switching to a larger-context model."
|
|
30
|
-
: "Truncated response recovery failed after one compact-and-retry attempt.",
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
return {
|
|
34
|
-
compact: request.contextOverflow || request.recoverableLength,
|
|
35
|
-
retry: request.canContinue,
|
|
36
|
-
};
|
|
37
|
-
},
|
|
38
|
-
summarize: async (request) => compact(request.preparation, {
|
|
39
|
-
invocation: request.invocation,
|
|
40
|
-
model: request.model,
|
|
41
|
-
customInstructions: request.customInstructions,
|
|
42
|
-
thinkingLevel: request.thinkingLevel,
|
|
43
|
-
signal: request.signal,
|
|
44
|
-
}),
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
//# sourceMappingURL=bootstrap-compaction-policy.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap-compaction-policy.js","sourceRoot":"","sources":["../../../src/core/extensions/bootstrap-compaction-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAChG,OAAO,EAA+B,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAG/F,OAAO,EAAE,+BAA+B,EAAE,MAAM,iBAAiB,CAAC;AAElE,MAAM,CAAC,MAAM,8BAA8B,GAAG,kCAAkC,CAAC;AACjF,MAAM,CAAC,MAAM,8BAA8B,GAAG,SAAS,CAAC;AAExD,8FAA8F;AAC9F,MAAM,UAAU,gCAAgC,CAAC,OAA0B,EAA0B;IACpG,OAAO,wBAAwB,CAC9B,OAAO,EACP;QACC,EAAE,EAAE,8BAA8B;QAClC,OAAO,EAAE,OAAO;QAChB,UAAU,EAAE,+BAA+B;QAC3C,KAAK,EAAE,iCAAiC;QACxC,oBAAoB,EAAE,CAAC,mBAAmB,CAAC;KAC3C,EACD,CAAC,GAAG,EAAE,EAAE,CAAC;QACR,GAAG,CAAC,wBAAwB,CAAC,8BAA8B,EAAE;YAC5D,OAAO,EAAE,CAAC,OAAO,EAAE,EAAE,CACpB,iBAAiB,CAChB,OAAO,CAAC,OAAkD,EAC1D,OAAO,CAAC,QAAmD,CAC3D;YACF,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC;gBACpB,IAAI,OAAO,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;oBACpC,MAAM,KAAK,GAAG,OAAO,CAAC,YAAY,CAAC;oBACnC,MAAM,UAAU,GACf,KAAK,KAAK,SAAS;wBACnB,KAAK,CAAC,aAAa,GAAG,CAAC;wBACvB,KAAK,CAAC,aAAa,GAAG,KAAK,CAAC,aAAa,GAAG,KAAK,CAAC,aAAa,CAAC;oBACjE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;gBAC9C,CAAC;gBACD,IAAI,OAAO,CAAC,iBAAiB,EAAE,CAAC;oBAC/B,OAAO;wBACN,OAAO,EAAE,KAAK;wBACd,cAAc,EAAE,OAAO,CAAC,eAAe;4BACtC,CAAC,CAAC,oIAAoI;4BACtI,CAAC,CAAC,yEAAyE;qBAC5E,CAAC;gBACH,CAAC;gBACD,OAAO;oBACN,OAAO,EAAE,OAAO,CAAC,eAAe,IAAI,OAAO,CAAC,iBAAiB;oBAC7D,KAAK,EAAE,OAAO,CAAC,WAAW;iBAC1B,CAAC;YAAA,CACF;YACD,SAAS,EAAE,KAAK,EAAE,OAAiC,EAAE,EAAE,CACtD,OAAO,CAAC,OAAO,CAAC,WAAoC,EAAE;gBACrD,UAAU,EAAE,OAAO,CAAC,UAAU;gBAC9B,KAAK,EAAE,OAAO,CAAC,KAAK;gBACpB,kBAAkB,EAAE,OAAO,CAAC,kBAAkB;gBAC9C,aAAa,EAAE,OAAO,CAAC,aAAa;gBACpC,MAAM,EAAE,OAAO,CAAC,MAAM;aACtB,CAAC;SACH,CAAC,CAAC;IAAA,CACH,CACD,CAAC;AAAA,CACF","sourcesContent":["import { type CompactionPreparation, compact, prepareCompaction } from \"../compaction/index.ts\";\nimport { type CapabilityPluginHandle, loadCapabilityPluginSync } from \"./capability-plugin.ts\";\nimport type { CapabilityRuntime } from \"./capability-runtime.ts\";\nimport type { CompactionSummaryRequest } from \"./public-api.ts\";\nimport { EXPERIMENTAL_PUBLIC_API_VERSION } from \"./public-api.ts\";\n\nexport const BOOTSTRAP_COMPACTION_PLUGIN_ID = \"agent-forge.bootstrap-compaction\";\nexport const DEFAULT_COMPACTION_POLICY_NAME = \"default\";\n\n/** Register the current automatic-compaction decision as a replaceable first-party policy. */\nexport function installBootstrapCompactionPolicy(runtime: CapabilityRuntime): CapabilityPluginHandle {\n\treturn loadCapabilityPluginSync(\n\t\truntime,\n\t\t{\n\t\t\tid: BOOTSTRAP_COMPACTION_PLUGIN_ID,\n\t\t\tversion: \"0.0.0\",\n\t\t\tapiVersion: EXPERIMENTAL_PUBLIC_API_VERSION,\n\t\t\tentry: \"<embedded:bootstrap-compaction>\",\n\t\t\trequiredCapabilities: [\"compaction-policy\"],\n\t\t},\n\t\t(api) => {\n\t\t\tapi.registerCompactionPolicy(DEFAULT_COMPACTION_POLICY_NAME, {\n\t\t\t\tprepare: (request) =>\n\t\t\t\t\tprepareCompaction(\n\t\t\t\t\t\trequest.entries as Parameters<typeof prepareCompaction>[0],\n\t\t\t\t\t\trequest.settings as Parameters<typeof prepareCompaction>[1],\n\t\t\t\t\t),\n\t\t\t\tdecide: (request) => {\n\t\t\t\t\tif (request.reason === \"threshold\") {\n\t\t\t\t\t\tconst usage = request.contextUsage;\n\t\t\t\t\t\tconst overBudget =\n\t\t\t\t\t\t\tusage !== undefined &&\n\t\t\t\t\t\t\tusage.contextWindow > 0 &&\n\t\t\t\t\t\t\tusage.contextTokens > usage.contextWindow - usage.reserveTokens;\n\t\t\t\t\t\treturn { compact: overBudget, retry: false };\n\t\t\t\t\t}\n\t\t\t\t\tif (request.recoveryAttempted) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcompact: false,\n\t\t\t\t\t\t\tfailureMessage: request.contextOverflow\n\t\t\t\t\t\t\t\t? \"Context overflow recovery failed after one compact-and-retry attempt. Try reducing context or switching to a larger-context model.\"\n\t\t\t\t\t\t\t\t: \"Truncated response recovery failed after one compact-and-retry attempt.\",\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcompact: request.contextOverflow || request.recoverableLength,\n\t\t\t\t\t\tretry: request.canContinue,\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\tsummarize: async (request: CompactionSummaryRequest) =>\n\t\t\t\t\tcompact(request.preparation as CompactionPreparation, {\n\t\t\t\t\t\tinvocation: request.invocation,\n\t\t\t\t\t\tmodel: request.model,\n\t\t\t\t\t\tcustomInstructions: request.customInstructions,\n\t\t\t\t\t\tthinkingLevel: request.thinkingLevel,\n\t\t\t\t\t\tsignal: request.signal,\n\t\t\t\t\t}),\n\t\t\t});\n\t\t},\n\t);\n}\n"]}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { type CapabilityPluginHandle } from "./capability-plugin.ts";
|
|
2
|
-
import type { CapabilityRuntime } from "./capability-runtime.ts";
|
|
3
|
-
export declare const BOOTSTRAP_OVERFLOW_PLUGIN_ID = "agent-forge.bootstrap-overflow";
|
|
4
|
-
export declare const DEFAULT_OVERFLOW_POLICY_NAME = "default";
|
|
5
|
-
/** Register the current provider classification as a replaceable first-party policy. */
|
|
6
|
-
export declare function installBootstrapOverflowPolicy(runtime: CapabilityRuntime): CapabilityPluginHandle;
|
|
7
|
-
//# sourceMappingURL=bootstrap-overflow-policy.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap-overflow-policy.d.ts","sourceRoot":"","sources":["../../../src/core/extensions/bootstrap-overflow-policy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,sBAAsB,EAA4B,MAAM,wBAAwB,CAAC;AAC/F,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAIjE,eAAO,MAAM,4BAA4B,mCAAmC,CAAC;AAC7E,eAAO,MAAM,4BAA4B,YAAY,CAAC;AAEtD,wFAAwF;AACxF,wBAAgB,8BAA8B,CAAC,OAAO,EAAE,iBAAiB,GAAG,sBAAsB,CAyBjG","sourcesContent":["import { type AssistantMessage, isContextOverflow, isRecoverableLength } from \"@agent-forge/ai/compat\";\nimport { t } from \"../i18n/index.ts\";\nimport { type CapabilityPluginHandle, loadCapabilityPluginSync } from \"./capability-plugin.ts\";\nimport type { CapabilityRuntime } from \"./capability-runtime.ts\";\nimport type { OverflowPolicyRequest } from \"./public-api.ts\";\nimport { EXPERIMENTAL_PUBLIC_API_VERSION } from \"./public-api.ts\";\n\nexport const BOOTSTRAP_OVERFLOW_PLUGIN_ID = \"agent-forge.bootstrap-overflow\";\nexport const DEFAULT_OVERFLOW_POLICY_NAME = \"default\";\n\n/** Register the current provider classification as a replaceable first-party policy. */\nexport function installBootstrapOverflowPolicy(runtime: CapabilityRuntime): CapabilityPluginHandle {\n\treturn loadCapabilityPluginSync(\n\t\truntime,\n\t\t{\n\t\t\tid: BOOTSTRAP_OVERFLOW_PLUGIN_ID,\n\t\t\tversion: \"0.0.0\",\n\t\t\tapiVersion: EXPERIMENTAL_PUBLIC_API_VERSION,\n\t\t\tentry: \"<embedded:bootstrap-overflow>\",\n\t\t\trequiredCapabilities: [\"overflow-policy\"],\n\t\t},\n\t\t(api) => {\n\t\t\tapi.registerOverflowPolicy(DEFAULT_OVERFLOW_POLICY_NAME, {\n\t\t\t\tdecide: (request: OverflowPolicyRequest) => {\n\t\t\t\t\tif (!request.message || typeof request.message !== \"object\") {\n\t\t\t\t\t\tthrow new Error(t(\"Overflow policy requires an assistant message object\"));\n\t\t\t\t\t}\n\t\t\t\t\tconst message = request.message as AssistantMessage;\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontextOverflow: isContextOverflow(message, request.contextWindow),\n\t\t\t\t\t\trecoverableLength: isRecoverableLength(message, request.desiredMaxOutput),\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t);\n}\n"]}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { isContextOverflow, isRecoverableLength } from "@agent-forge/ai/compat";
|
|
2
|
-
import { t } from "../i18n/index.js";
|
|
3
|
-
import { loadCapabilityPluginSync } from "./capability-plugin.js";
|
|
4
|
-
import { EXPERIMENTAL_PUBLIC_API_VERSION } from "./public-api.js";
|
|
5
|
-
export const BOOTSTRAP_OVERFLOW_PLUGIN_ID = "agent-forge.bootstrap-overflow";
|
|
6
|
-
export const DEFAULT_OVERFLOW_POLICY_NAME = "default";
|
|
7
|
-
/** Register the current provider classification as a replaceable first-party policy. */
|
|
8
|
-
export function installBootstrapOverflowPolicy(runtime) {
|
|
9
|
-
return loadCapabilityPluginSync(runtime, {
|
|
10
|
-
id: BOOTSTRAP_OVERFLOW_PLUGIN_ID,
|
|
11
|
-
version: "0.0.0",
|
|
12
|
-
apiVersion: EXPERIMENTAL_PUBLIC_API_VERSION,
|
|
13
|
-
entry: "<embedded:bootstrap-overflow>",
|
|
14
|
-
requiredCapabilities: ["overflow-policy"],
|
|
15
|
-
}, (api) => {
|
|
16
|
-
api.registerOverflowPolicy(DEFAULT_OVERFLOW_POLICY_NAME, {
|
|
17
|
-
decide: (request) => {
|
|
18
|
-
if (!request.message || typeof request.message !== "object") {
|
|
19
|
-
throw new Error(t("Overflow policy requires an assistant message object"));
|
|
20
|
-
}
|
|
21
|
-
const message = request.message;
|
|
22
|
-
return {
|
|
23
|
-
contextOverflow: isContextOverflow(message, request.contextWindow),
|
|
24
|
-
recoverableLength: isRecoverableLength(message, request.desiredMaxOutput),
|
|
25
|
-
};
|
|
26
|
-
},
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
//# sourceMappingURL=bootstrap-overflow-policy.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap-overflow-policy.js","sourceRoot":"","sources":["../../../src/core/extensions/bootstrap-overflow-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AACvG,OAAO,EAAE,CAAC,EAAE,MAAM,kBAAkB,CAAC;AACrC,OAAO,EAA+B,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAG/F,OAAO,EAAE,+BAA+B,EAAE,MAAM,iBAAiB,CAAC;AAElE,MAAM,CAAC,MAAM,4BAA4B,GAAG,gCAAgC,CAAC;AAC7E,MAAM,CAAC,MAAM,4BAA4B,GAAG,SAAS,CAAC;AAEtD,wFAAwF;AACxF,MAAM,UAAU,8BAA8B,CAAC,OAA0B,EAA0B;IAClG,OAAO,wBAAwB,CAC9B,OAAO,EACP;QACC,EAAE,EAAE,4BAA4B;QAChC,OAAO,EAAE,OAAO;QAChB,UAAU,EAAE,+BAA+B;QAC3C,KAAK,EAAE,+BAA+B;QACtC,oBAAoB,EAAE,CAAC,iBAAiB,CAAC;KACzC,EACD,CAAC,GAAG,EAAE,EAAE,CAAC;QACR,GAAG,CAAC,sBAAsB,CAAC,4BAA4B,EAAE;YACxD,MAAM,EAAE,CAAC,OAA8B,EAAE,EAAE,CAAC;gBAC3C,IAAI,CAAC,OAAO,CAAC,OAAO,IAAI,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;oBAC7D,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,sDAAsD,CAAC,CAAC,CAAC;gBAC5E,CAAC;gBACD,MAAM,OAAO,GAAG,OAAO,CAAC,OAA2B,CAAC;gBACpD,OAAO;oBACN,eAAe,EAAE,iBAAiB,CAAC,OAAO,EAAE,OAAO,CAAC,aAAa,CAAC;oBAClE,iBAAiB,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,gBAAgB,CAAC;iBACzE,CAAC;YAAA,CACF;SACD,CAAC,CAAC;IAAA,CACH,CACD,CAAC;AAAA,CACF","sourcesContent":["import { type AssistantMessage, isContextOverflow, isRecoverableLength } from \"@agent-forge/ai/compat\";\nimport { t } from \"../i18n/index.ts\";\nimport { type CapabilityPluginHandle, loadCapabilityPluginSync } from \"./capability-plugin.ts\";\nimport type { CapabilityRuntime } from \"./capability-runtime.ts\";\nimport type { OverflowPolicyRequest } from \"./public-api.ts\";\nimport { EXPERIMENTAL_PUBLIC_API_VERSION } from \"./public-api.ts\";\n\nexport const BOOTSTRAP_OVERFLOW_PLUGIN_ID = \"agent-forge.bootstrap-overflow\";\nexport const DEFAULT_OVERFLOW_POLICY_NAME = \"default\";\n\n/** Register the current provider classification as a replaceable first-party policy. */\nexport function installBootstrapOverflowPolicy(runtime: CapabilityRuntime): CapabilityPluginHandle {\n\treturn loadCapabilityPluginSync(\n\t\truntime,\n\t\t{\n\t\t\tid: BOOTSTRAP_OVERFLOW_PLUGIN_ID,\n\t\t\tversion: \"0.0.0\",\n\t\t\tapiVersion: EXPERIMENTAL_PUBLIC_API_VERSION,\n\t\t\tentry: \"<embedded:bootstrap-overflow>\",\n\t\t\trequiredCapabilities: [\"overflow-policy\"],\n\t\t},\n\t\t(api) => {\n\t\t\tapi.registerOverflowPolicy(DEFAULT_OVERFLOW_POLICY_NAME, {\n\t\t\t\tdecide: (request: OverflowPolicyRequest) => {\n\t\t\t\t\tif (!request.message || typeof request.message !== \"object\") {\n\t\t\t\t\t\tthrow new Error(t(\"Overflow policy requires an assistant message object\"));\n\t\t\t\t\t}\n\t\t\t\t\tconst message = request.message as AssistantMessage;\n\t\t\t\t\treturn {\n\t\t\t\t\t\tcontextOverflow: isContextOverflow(message, request.contextWindow),\n\t\t\t\t\t\trecoverableLength: isRecoverableLength(message, request.desiredMaxOutput),\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t);\n}\n"]}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { type CapabilityPluginHandle } from "./capability-plugin.ts";
|
|
2
|
-
import type { CapabilityRuntime } from "./capability-runtime.ts";
|
|
3
|
-
export declare const BOOTSTRAP_RETRY_PLUGIN_ID = "agent-forge.bootstrap-retry";
|
|
4
|
-
export declare const DEFAULT_RETRY_POLICY_NAME = "default";
|
|
5
|
-
/** Register the built-in retry decision as a replaceable first-party policy. */
|
|
6
|
-
export declare function installBootstrapRetryPolicy(runtime: CapabilityRuntime): CapabilityPluginHandle;
|
|
7
|
-
//# sourceMappingURL=bootstrap-retry-policy.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap-retry-policy.d.ts","sourceRoot":"","sources":["../../../src/core/extensions/bootstrap-retry-policy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,sBAAsB,EAA4B,MAAM,wBAAwB,CAAC;AAC/F,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAGjE,eAAO,MAAM,yBAAyB,gCAAgC,CAAC;AACvE,eAAO,MAAM,yBAAyB,YAAY,CAAC;AAEnD,gFAAgF;AAChF,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,iBAAiB,GAAG,sBAAsB,CAwB9F","sourcesContent":["import { isRetryableAssistantError } from \"@agent-forge/ai/compat\";\nimport { t } from \"../i18n/index.ts\";\nimport { type CapabilityPluginHandle, loadCapabilityPluginSync } from \"./capability-plugin.ts\";\nimport type { CapabilityRuntime } from \"./capability-runtime.ts\";\nimport { EXPERIMENTAL_PUBLIC_API_VERSION } from \"./public-api.ts\";\n\nexport const BOOTSTRAP_RETRY_PLUGIN_ID = \"agent-forge.bootstrap-retry\";\nexport const DEFAULT_RETRY_POLICY_NAME = \"default\";\n\n/** Register the built-in retry decision as a replaceable first-party policy. */\nexport function installBootstrapRetryPolicy(runtime: CapabilityRuntime): CapabilityPluginHandle {\n\treturn loadCapabilityPluginSync(\n\t\truntime,\n\t\t{\n\t\t\tid: BOOTSTRAP_RETRY_PLUGIN_ID,\n\t\t\tversion: \"0.0.0\",\n\t\t\tapiVersion: EXPERIMENTAL_PUBLIC_API_VERSION,\n\t\t\tentry: \"<embedded:bootstrap-retry>\",\n\t\t\trequiredCapabilities: [\"retry-policy\"],\n\t\t},\n\t\t(api) => {\n\t\t\tapi.registerRetryPolicy(DEFAULT_RETRY_POLICY_NAME, {\n\t\t\t\tclassify: ({ message }) => {\n\t\t\t\t\tif (!message || typeof message !== \"object\")\n\t\t\t\t\t\tthrow new Error(t(\"Retry classification requires an assistant message object\"));\n\t\t\t\t\treturn isRetryableAssistantError(message as Parameters<typeof isRetryableAssistantError>[0]);\n\t\t\t\t},\n\t\t\t\tdecide: ({ retryable, attempt, maxAttempts, baseDelayMs }) => ({\n\t\t\t\t\tretry: retryable && attempt <= maxAttempts,\n\t\t\t\t\tdelayMs: baseDelayMs * 2 ** Math.max(0, attempt - 1),\n\t\t\t\t}),\n\t\t\t});\n\t\t},\n\t);\n}\n"]}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { isRetryableAssistantError } from "@agent-forge/ai/compat";
|
|
2
|
-
import { t } from "../i18n/index.js";
|
|
3
|
-
import { loadCapabilityPluginSync } from "./capability-plugin.js";
|
|
4
|
-
import { EXPERIMENTAL_PUBLIC_API_VERSION } from "./public-api.js";
|
|
5
|
-
export const BOOTSTRAP_RETRY_PLUGIN_ID = "agent-forge.bootstrap-retry";
|
|
6
|
-
export const DEFAULT_RETRY_POLICY_NAME = "default";
|
|
7
|
-
/** Register the built-in retry decision as a replaceable first-party policy. */
|
|
8
|
-
export function installBootstrapRetryPolicy(runtime) {
|
|
9
|
-
return loadCapabilityPluginSync(runtime, {
|
|
10
|
-
id: BOOTSTRAP_RETRY_PLUGIN_ID,
|
|
11
|
-
version: "0.0.0",
|
|
12
|
-
apiVersion: EXPERIMENTAL_PUBLIC_API_VERSION,
|
|
13
|
-
entry: "<embedded:bootstrap-retry>",
|
|
14
|
-
requiredCapabilities: ["retry-policy"],
|
|
15
|
-
}, (api) => {
|
|
16
|
-
api.registerRetryPolicy(DEFAULT_RETRY_POLICY_NAME, {
|
|
17
|
-
classify: ({ message }) => {
|
|
18
|
-
if (!message || typeof message !== "object")
|
|
19
|
-
throw new Error(t("Retry classification requires an assistant message object"));
|
|
20
|
-
return isRetryableAssistantError(message);
|
|
21
|
-
},
|
|
22
|
-
decide: ({ retryable, attempt, maxAttempts, baseDelayMs }) => ({
|
|
23
|
-
retry: retryable && attempt <= maxAttempts,
|
|
24
|
-
delayMs: baseDelayMs * 2 ** Math.max(0, attempt - 1),
|
|
25
|
-
}),
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
//# sourceMappingURL=bootstrap-retry-policy.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap-retry-policy.js","sourceRoot":"","sources":["../../../src/core/extensions/bootstrap-retry-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EAAE,CAAC,EAAE,MAAM,kBAAkB,CAAC;AACrC,OAAO,EAA+B,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAE/F,OAAO,EAAE,+BAA+B,EAAE,MAAM,iBAAiB,CAAC;AAElE,MAAM,CAAC,MAAM,yBAAyB,GAAG,6BAA6B,CAAC;AACvE,MAAM,CAAC,MAAM,yBAAyB,GAAG,SAAS,CAAC;AAEnD,gFAAgF;AAChF,MAAM,UAAU,2BAA2B,CAAC,OAA0B,EAA0B;IAC/F,OAAO,wBAAwB,CAC9B,OAAO,EACP;QACC,EAAE,EAAE,yBAAyB;QAC7B,OAAO,EAAE,OAAO;QAChB,UAAU,EAAE,+BAA+B;QAC3C,KAAK,EAAE,4BAA4B;QACnC,oBAAoB,EAAE,CAAC,cAAc,CAAC;KACtC,EACD,CAAC,GAAG,EAAE,EAAE,CAAC;QACR,GAAG,CAAC,mBAAmB,CAAC,yBAAyB,EAAE;YAClD,QAAQ,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;gBAC1B,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ;oBAC1C,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,2DAA2D,CAAC,CAAC,CAAC;gBACjF,OAAO,yBAAyB,CAAC,OAA0D,CAAC,CAAC;YAAA,CAC7F;YACD,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,CAAC;gBAC9D,KAAK,EAAE,SAAS,IAAI,OAAO,IAAI,WAAW;gBAC1C,OAAO,EAAE,WAAW,GAAG,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC;aACpD,CAAC;SACF,CAAC,CAAC;IAAA,CACH,CACD,CAAC;AAAA,CACF","sourcesContent":["import { isRetryableAssistantError } from \"@agent-forge/ai/compat\";\nimport { t } from \"../i18n/index.ts\";\nimport { type CapabilityPluginHandle, loadCapabilityPluginSync } from \"./capability-plugin.ts\";\nimport type { CapabilityRuntime } from \"./capability-runtime.ts\";\nimport { EXPERIMENTAL_PUBLIC_API_VERSION } from \"./public-api.ts\";\n\nexport const BOOTSTRAP_RETRY_PLUGIN_ID = \"agent-forge.bootstrap-retry\";\nexport const DEFAULT_RETRY_POLICY_NAME = \"default\";\n\n/** Register the built-in retry decision as a replaceable first-party policy. */\nexport function installBootstrapRetryPolicy(runtime: CapabilityRuntime): CapabilityPluginHandle {\n\treturn loadCapabilityPluginSync(\n\t\truntime,\n\t\t{\n\t\t\tid: BOOTSTRAP_RETRY_PLUGIN_ID,\n\t\t\tversion: \"0.0.0\",\n\t\t\tapiVersion: EXPERIMENTAL_PUBLIC_API_VERSION,\n\t\t\tentry: \"<embedded:bootstrap-retry>\",\n\t\t\trequiredCapabilities: [\"retry-policy\"],\n\t\t},\n\t\t(api) => {\n\t\t\tapi.registerRetryPolicy(DEFAULT_RETRY_POLICY_NAME, {\n\t\t\t\tclassify: ({ message }) => {\n\t\t\t\t\tif (!message || typeof message !== \"object\")\n\t\t\t\t\t\tthrow new Error(t(\"Retry classification requires an assistant message object\"));\n\t\t\t\t\treturn isRetryableAssistantError(message as Parameters<typeof isRetryableAssistantError>[0]);\n\t\t\t\t},\n\t\t\t\tdecide: ({ retryable, attempt, maxAttempts, baseDelayMs }) => ({\n\t\t\t\t\tretry: retryable && attempt <= maxAttempts,\n\t\t\t\t\tdelayMs: baseDelayMs * 2 ** Math.max(0, attempt - 1),\n\t\t\t\t}),\n\t\t\t});\n\t\t},\n\t);\n}\n"]}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { AgentTool } from "@agent-forge/agent-core";
|
|
2
|
-
import { type ToolsOptions } from "../tools/index.ts";
|
|
3
|
-
import type { ToolDefinition } from "../tools/tool-definition.ts";
|
|
4
|
-
import { type CapabilityPluginHandle } from "./capability-plugin.ts";
|
|
5
|
-
import type { CapabilityRuntime } from "./capability-runtime.ts";
|
|
6
|
-
import { type HostMode } from "./public-api.ts";
|
|
7
|
-
export declare const BOOTSTRAP_TOOLS_PLUGIN_ID = "agent-forge.bootstrap-tools";
|
|
8
|
-
export interface BootstrapToolsOptions {
|
|
9
|
-
version?: string;
|
|
10
|
-
}
|
|
11
|
-
export interface SessionBootstrapToolsOptions extends BootstrapToolsOptions {
|
|
12
|
-
read?: ToolsOptions["read"];
|
|
13
|
-
bash?: ToolsOptions["bash"];
|
|
14
|
-
mode?: HostMode;
|
|
15
|
-
}
|
|
16
|
-
/** Install the default coding tools through the same facade available to users. */
|
|
17
|
-
export declare function installBootstrapTools(runtime: CapabilityRuntime, definitions: readonly ToolDefinition[], options?: BootstrapToolsOptions): CapabilityPluginHandle;
|
|
18
|
-
/** Build and install the standard coding tools without exposing their construction to AgentSession. */
|
|
19
|
-
export declare function installSessionBootstrapTools(runtime: CapabilityRuntime, cwd: string, options?: SessionBootstrapToolsOptions, baseToolsOverride?: Record<string, AgentTool>): CapabilityPluginHandle;
|
|
20
|
-
//# sourceMappingURL=bootstrap-tools.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap-tools.d.ts","sourceRoot":"","sources":["../../../src/core/extensions/bootstrap-tools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,EAA2D,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC/G,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAElE,OAAO,EAAE,KAAK,sBAAsB,EAA4B,MAAM,wBAAwB,CAAC;AAC/F,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAmC,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEjF,eAAO,MAAM,yBAAyB,gCAAgC,CAAC;AAEvE,MAAM,WAAW,qBAAqB;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,4BAA6B,SAAQ,qBAAqB;IAC1E,IAAI,CAAC,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC;IAC5B,IAAI,CAAC,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC;IAC5B,IAAI,CAAC,EAAE,QAAQ,CAAC;CAChB;AAkBD,mFAAmF;AACnF,wBAAgB,qBAAqB,CACpC,OAAO,EAAE,iBAAiB,EAC1B,WAAW,EAAE,SAAS,cAAc,EAAE,EACtC,OAAO,GAAE,qBAA0B,GACjC,sBAAsB,CAcxB;AAED,uGAAuG;AACvG,wBAAgB,4BAA4B,CAC3C,OAAO,EAAE,iBAAiB,EAC1B,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,4BAAiC,EAC1C,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAC3C,sBAAsB,CAGxB","sourcesContent":["import type { AgentTool } from \"@agent-forge/agent-core\";\nimport { t } from \"../i18n/index.ts\";\nimport { createAllToolDefinitions, createReadOnlyToolDefinitions, type ToolsOptions } from \"../tools/index.ts\";\nimport type { ToolDefinition } from \"../tools/tool-definition.ts\";\nimport { createToolDefinitionFromAgentTool } from \"../tools/tool-definition-wrapper.ts\";\nimport { type CapabilityPluginHandle, loadCapabilityPluginSync } from \"./capability-plugin.ts\";\nimport type { CapabilityRuntime } from \"./capability-runtime.ts\";\nimport { EXPERIMENTAL_PUBLIC_API_VERSION, type HostMode } from \"./public-api.ts\";\n\nexport const BOOTSTRAP_TOOLS_PLUGIN_ID = \"agent-forge.bootstrap-tools\";\n\nexport interface BootstrapToolsOptions {\n\tversion?: string;\n}\n\nexport interface SessionBootstrapToolsOptions extends BootstrapToolsOptions {\n\tread?: ToolsOptions[\"read\"];\n\tbash?: ToolsOptions[\"bash\"];\n\tmode?: HostMode;\n}\n\nfunction resolveSessionToolDefinitions(\n\tcwd: string,\n\toptions: SessionBootstrapToolsOptions,\n\tbaseToolsOverride?: Record<string, AgentTool>,\n): readonly ToolDefinition[] {\n\tif (!baseToolsOverride) {\n\t\treturn options.mode === \"readonly\"\n\t\t\t? createReadOnlyToolDefinitions(cwd, { read: options.read })\n\t\t\t: Object.values(createAllToolDefinitions(cwd, { read: options.read, bash: options.bash }));\n\t}\n\tif (options.mode === \"readonly\") {\n\t\tthrow new Error(t(\"Readonly mode does not allow base tool overrides\"));\n\t}\n\treturn Object.values(baseToolsOverride).map((tool) => createToolDefinitionFromAgentTool(tool));\n}\n\n/** Install the default coding tools through the same facade available to users. */\nexport function installBootstrapTools(\n\truntime: CapabilityRuntime,\n\tdefinitions: readonly ToolDefinition[],\n\toptions: BootstrapToolsOptions = {},\n): CapabilityPluginHandle {\n\treturn loadCapabilityPluginSync(\n\t\truntime,\n\t\t{\n\t\t\tid: BOOTSTRAP_TOOLS_PLUGIN_ID,\n\t\t\tversion: options.version ?? \"0.0.0\",\n\t\t\tapiVersion: EXPERIMENTAL_PUBLIC_API_VERSION,\n\t\t\tentry: \"<embedded:bootstrap-tools>\",\n\t\t\trequiredCapabilities: [\"tools\"],\n\t\t},\n\t\t(api) => {\n\t\t\tfor (const definition of definitions) api.registerTool(definition);\n\t\t},\n\t);\n}\n\n/** Build and install the standard coding tools without exposing their construction to AgentSession. */\nexport function installSessionBootstrapTools(\n\truntime: CapabilityRuntime,\n\tcwd: string,\n\toptions: SessionBootstrapToolsOptions = {},\n\tbaseToolsOverride?: Record<string, AgentTool>,\n): CapabilityPluginHandle {\n\tconst definitions = resolveSessionToolDefinitions(cwd, options, baseToolsOverride);\n\treturn installBootstrapTools(runtime, definitions, options);\n}\n"]}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { t } from "../i18n/index.js";
|
|
2
|
-
import { createAllToolDefinitions, createReadOnlyToolDefinitions } from "../tools/index.js";
|
|
3
|
-
import { createToolDefinitionFromAgentTool } from "../tools/tool-definition-wrapper.js";
|
|
4
|
-
import { loadCapabilityPluginSync } from "./capability-plugin.js";
|
|
5
|
-
import { EXPERIMENTAL_PUBLIC_API_VERSION } from "./public-api.js";
|
|
6
|
-
export const BOOTSTRAP_TOOLS_PLUGIN_ID = "agent-forge.bootstrap-tools";
|
|
7
|
-
function resolveSessionToolDefinitions(cwd, options, baseToolsOverride) {
|
|
8
|
-
if (!baseToolsOverride) {
|
|
9
|
-
return options.mode === "readonly"
|
|
10
|
-
? createReadOnlyToolDefinitions(cwd, { read: options.read })
|
|
11
|
-
: Object.values(createAllToolDefinitions(cwd, { read: options.read, bash: options.bash }));
|
|
12
|
-
}
|
|
13
|
-
if (options.mode === "readonly") {
|
|
14
|
-
throw new Error(t("Readonly mode does not allow base tool overrides"));
|
|
15
|
-
}
|
|
16
|
-
return Object.values(baseToolsOverride).map((tool) => createToolDefinitionFromAgentTool(tool));
|
|
17
|
-
}
|
|
18
|
-
/** Install the default coding tools through the same facade available to users. */
|
|
19
|
-
export function installBootstrapTools(runtime, definitions, options = {}) {
|
|
20
|
-
return loadCapabilityPluginSync(runtime, {
|
|
21
|
-
id: BOOTSTRAP_TOOLS_PLUGIN_ID,
|
|
22
|
-
version: options.version ?? "0.0.0",
|
|
23
|
-
apiVersion: EXPERIMENTAL_PUBLIC_API_VERSION,
|
|
24
|
-
entry: "<embedded:bootstrap-tools>",
|
|
25
|
-
requiredCapabilities: ["tools"],
|
|
26
|
-
}, (api) => {
|
|
27
|
-
for (const definition of definitions)
|
|
28
|
-
api.registerTool(definition);
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
/** Build and install the standard coding tools without exposing their construction to AgentSession. */
|
|
32
|
-
export function installSessionBootstrapTools(runtime, cwd, options = {}, baseToolsOverride) {
|
|
33
|
-
const definitions = resolveSessionToolDefinitions(cwd, options, baseToolsOverride);
|
|
34
|
-
return installBootstrapTools(runtime, definitions, options);
|
|
35
|
-
}
|
|
36
|
-
//# sourceMappingURL=bootstrap-tools.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap-tools.js","sourceRoot":"","sources":["../../../src/core/extensions/bootstrap-tools.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,kBAAkB,CAAC;AACrC,OAAO,EAAE,wBAAwB,EAAE,6BAA6B,EAAqB,MAAM,mBAAmB,CAAC;AAE/G,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AACxF,OAAO,EAA+B,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAE/F,OAAO,EAAE,+BAA+B,EAAiB,MAAM,iBAAiB,CAAC;AAEjF,MAAM,CAAC,MAAM,yBAAyB,GAAG,6BAA6B,CAAC;AAYvE,SAAS,6BAA6B,CACrC,GAAW,EACX,OAAqC,EACrC,iBAA6C,EACjB;IAC5B,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACxB,OAAO,OAAO,CAAC,IAAI,KAAK,UAAU;YACjC,CAAC,CAAC,6BAA6B,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC;YAC5D,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,wBAAwB,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAC7F,CAAC;IACD,IAAI,OAAO,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;QACjC,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,kDAAkD,CAAC,CAAC,CAAC;IACxE,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,iCAAiC,CAAC,IAAI,CAAC,CAAC,CAAC;AAAA,CAC/F;AAED,mFAAmF;AACnF,MAAM,UAAU,qBAAqB,CACpC,OAA0B,EAC1B,WAAsC,EACtC,OAAO,GAA0B,EAAE,EACV;IACzB,OAAO,wBAAwB,CAC9B,OAAO,EACP;QACC,EAAE,EAAE,yBAAyB;QAC7B,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,OAAO;QACnC,UAAU,EAAE,+BAA+B;QAC3C,KAAK,EAAE,4BAA4B;QACnC,oBAAoB,EAAE,CAAC,OAAO,CAAC;KAC/B,EACD,CAAC,GAAG,EAAE,EAAE,CAAC;QACR,KAAK,MAAM,UAAU,IAAI,WAAW;YAAE,GAAG,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;IAAA,CACnE,CACD,CAAC;AAAA,CACF;AAED,uGAAuG;AACvG,MAAM,UAAU,4BAA4B,CAC3C,OAA0B,EAC1B,GAAW,EACX,OAAO,GAAiC,EAAE,EAC1C,iBAA6C,EACpB;IACzB,MAAM,WAAW,GAAG,6BAA6B,CAAC,GAAG,EAAE,OAAO,EAAE,iBAAiB,CAAC,CAAC;IACnF,OAAO,qBAAqB,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;AAAA,CAC5D","sourcesContent":["import type { AgentTool } from \"@agent-forge/agent-core\";\nimport { t } from \"../i18n/index.ts\";\nimport { createAllToolDefinitions, createReadOnlyToolDefinitions, type ToolsOptions } from \"../tools/index.ts\";\nimport type { ToolDefinition } from \"../tools/tool-definition.ts\";\nimport { createToolDefinitionFromAgentTool } from \"../tools/tool-definition-wrapper.ts\";\nimport { type CapabilityPluginHandle, loadCapabilityPluginSync } from \"./capability-plugin.ts\";\nimport type { CapabilityRuntime } from \"./capability-runtime.ts\";\nimport { EXPERIMENTAL_PUBLIC_API_VERSION, type HostMode } from \"./public-api.ts\";\n\nexport const BOOTSTRAP_TOOLS_PLUGIN_ID = \"agent-forge.bootstrap-tools\";\n\nexport interface BootstrapToolsOptions {\n\tversion?: string;\n}\n\nexport interface SessionBootstrapToolsOptions extends BootstrapToolsOptions {\n\tread?: ToolsOptions[\"read\"];\n\tbash?: ToolsOptions[\"bash\"];\n\tmode?: HostMode;\n}\n\nfunction resolveSessionToolDefinitions(\n\tcwd: string,\n\toptions: SessionBootstrapToolsOptions,\n\tbaseToolsOverride?: Record<string, AgentTool>,\n): readonly ToolDefinition[] {\n\tif (!baseToolsOverride) {\n\t\treturn options.mode === \"readonly\"\n\t\t\t? createReadOnlyToolDefinitions(cwd, { read: options.read })\n\t\t\t: Object.values(createAllToolDefinitions(cwd, { read: options.read, bash: options.bash }));\n\t}\n\tif (options.mode === \"readonly\") {\n\t\tthrow new Error(t(\"Readonly mode does not allow base tool overrides\"));\n\t}\n\treturn Object.values(baseToolsOverride).map((tool) => createToolDefinitionFromAgentTool(tool));\n}\n\n/** Install the default coding tools through the same facade available to users. */\nexport function installBootstrapTools(\n\truntime: CapabilityRuntime,\n\tdefinitions: readonly ToolDefinition[],\n\toptions: BootstrapToolsOptions = {},\n): CapabilityPluginHandle {\n\treturn loadCapabilityPluginSync(\n\t\truntime,\n\t\t{\n\t\t\tid: BOOTSTRAP_TOOLS_PLUGIN_ID,\n\t\t\tversion: options.version ?? \"0.0.0\",\n\t\t\tapiVersion: EXPERIMENTAL_PUBLIC_API_VERSION,\n\t\t\tentry: \"<embedded:bootstrap-tools>\",\n\t\t\trequiredCapabilities: [\"tools\"],\n\t\t},\n\t\t(api) => {\n\t\t\tfor (const definition of definitions) api.registerTool(definition);\n\t\t},\n\t);\n}\n\n/** Build and install the standard coding tools without exposing their construction to AgentSession. */\nexport function installSessionBootstrapTools(\n\truntime: CapabilityRuntime,\n\tcwd: string,\n\toptions: SessionBootstrapToolsOptions = {},\n\tbaseToolsOverride?: Record<string, AgentTool>,\n): CapabilityPluginHandle {\n\tconst definitions = resolveSessionToolDefinitions(cwd, options, baseToolsOverride);\n\treturn installBootstrapTools(runtime, definitions, options);\n}\n"]}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 第一方 provider 主备切换插件(设计:docs/design/供应商能力槽位与主备切换设计.md §4)。
|
|
3
|
-
*
|
|
4
|
-
* 形态与 bootstrap-retry 同族——嵌入式第一方插件,策略经公共
|
|
5
|
-
* `api.registerStreamFnWrapper` 注册面挂进宿主默认 stream 装配——但熔断状态是
|
|
6
|
-
* **宿主模块级单例**(设计 §4.2):进程内所有会话与 subagent 共享同一份,不随
|
|
7
|
-
* 会话 dispose,不持久化(重启后全部 CLOSED)。
|
|
8
|
-
*
|
|
9
|
-
* 判定哲学(设计 §2):只看流终态 done/error/aborted 与"是否已向上层释放内容
|
|
10
|
-
* 增量"两个本地事实,不解读错误类型/错误码语义;原始 errorMessage 照透传保留,
|
|
11
|
-
* 只用于事件归因与 diagnostics,不参与机器判定分支。aborted 不计数、不换道、
|
|
12
|
-
* 状态不变。换道从第一次失败即发生;`failureThreshold` 只控制"是否继续先撞主"
|
|
13
|
-
* (连续 N 次后熔断打开,请求直接落备用,冷却期满后以真实请求试探回主)。
|
|
14
|
-
*/
|
|
15
|
-
import type { Api, Model } from "@agent-forge/ai/compat";
|
|
16
|
-
import type { HostLogger } from "../logger.ts";
|
|
17
|
-
import { type CapabilityPluginHandle } from "./capability-plugin.ts";
|
|
18
|
-
import type { CapabilityRuntime } from "./capability-runtime.ts";
|
|
19
|
-
export declare const PROVIDER_FAILOVER_PLUGIN_ID = "agent-forge.provider-failover";
|
|
20
|
-
export declare const PROVIDER_FAILOVER_WRAPPER_NAME = "provider-failover";
|
|
21
|
-
/**
|
|
22
|
-
* 会话日志快照通道的 customType(设计 §4.7 Phase 3):插件经公共
|
|
23
|
-
* `api.session.appendEntry` 在状态转移点写入快照,footer 每帧取最后一条渲染
|
|
24
|
-
* 摘要行——与 goal.state / todo.state / workflow.state 同构,零新公共面。
|
|
25
|
-
*/
|
|
26
|
-
export declare const PROVIDER_FAILOVER_STATE_ENTRY_TYPE = "provider.failover.state";
|
|
27
|
-
/** `provider.failover.state` 快照负载(footer 按最后一条渲染)。 */
|
|
28
|
-
export interface ProviderFailoverStateSnapshot {
|
|
29
|
-
readonly version: 1;
|
|
30
|
-
/** 主链引用 `provider/modelId`;装配期初始快照无链上下文,为空串。 */
|
|
31
|
-
readonly chainId: string;
|
|
32
|
-
readonly status: "closed" | "open" | "half-open";
|
|
33
|
-
/** 当前换道目标引用 `provider/modelId`(OPEN 期请求从链头重走);closed 省略。 */
|
|
34
|
-
readonly backupProvider?: string;
|
|
35
|
-
/** 下次试探时间戳 = open 时刻 + 当前冷却;closed 为 0。 */
|
|
36
|
-
readonly probeAtMs: number;
|
|
37
|
-
/** 快照写入时刻(注入时钟友好)。 */
|
|
38
|
-
readonly now: number;
|
|
39
|
-
}
|
|
40
|
-
interface FailoverChainDeclaration {
|
|
41
|
-
readonly primary: string;
|
|
42
|
-
readonly backups: readonly string[];
|
|
43
|
-
}
|
|
44
|
-
interface ResolvedFailoverConfig {
|
|
45
|
-
/** 试探失败冷却起点(也是回 CLOSED 后的重置值)。 */
|
|
46
|
-
readonly cooldownInitialMs: number;
|
|
47
|
-
readonly cooldownMaxMs: number;
|
|
48
|
-
readonly failureThreshold: number;
|
|
49
|
-
readonly backupProviders: readonly string[];
|
|
50
|
-
readonly chains: readonly FailoverChainDeclaration[];
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* 解析 settings `failover` 节。返回 undefined = 无 failover(未配置 / 无有效
|
|
54
|
-
* backupProviders 与 chains / 配置错误拒绝加载——后者附带一条警告,设计 §4.1
|
|
55
|
-
* "重复 primary 拒绝加载并警告")。`failover.enabled` 开关已移除(2026-10-03
|
|
56
|
-
* D-079):节点存在即装配,残留 `enabled` 键只警告并忽略,按其余字段正常解析。
|
|
57
|
-
*/
|
|
58
|
-
export declare function parseProviderFailoverConfig(raw: unknown, warn: (message: string) => void): ResolvedFailoverConfig | undefined;
|
|
59
|
-
/**
|
|
60
|
-
* 从 SettingsManager 现有读面取合并后的 `failover` 原始节点(设计 §4.1 配置面):
|
|
61
|
-
* `getFailoverSettings()`(Phase 1 落地)原样透传合并层对象,本层不做结构收窄
|
|
62
|
-
* ——解析与校验全部收在本模块(见 parseProviderFailoverConfig)。
|
|
63
|
-
*/
|
|
64
|
-
export declare function readProviderFailoverSettingsNode(settingsManager: Pick<SettingsManagerFailoverReader, "getFailoverSettings">): unknown;
|
|
65
|
-
interface SettingsManagerFailoverReader {
|
|
66
|
-
getFailoverSettings(): unknown;
|
|
67
|
-
}
|
|
68
|
-
/** 测试隔离钩子:清空模块级熔断单例与预检警告去重集(仅测试使用)。 */
|
|
69
|
-
export declare function resetProviderFailoverStateForTests(): void;
|
|
70
|
-
/**
|
|
71
|
-
* 装载预检的宿主静态检查面(设计 §4.6)。全部为目录/凭据快照读取:不发网络
|
|
72
|
-
* 请求、不触发 OAuth 刷新(凭据检查与 ModelRuntime.hasConfiguredAuth 同构——
|
|
73
|
-
* 只读"该 provider 是否有凭据条目",不做可用性探测)。
|
|
74
|
-
*/
|
|
75
|
-
export interface ProviderFailoverPreflightChecks {
|
|
76
|
-
/** 目录解析,与运行时换道候选解析同一面。 */
|
|
77
|
-
readonly resolveModel: (provider: string, modelId: string) => Model<Api> | undefined;
|
|
78
|
-
/** provider 在组合目录(builtin + models.json + 扩展)中存在(backupProviders 层预检)。 */
|
|
79
|
-
readonly hasProvider: (providerId: string) => boolean;
|
|
80
|
-
/** provider 有凭据条目(静态;不触发 OAuth 刷新)。 */
|
|
81
|
-
readonly hasConfiguredAuth: (providerId: string) => boolean;
|
|
82
|
-
}
|
|
83
|
-
export interface ProviderFailoverInstallOptions {
|
|
84
|
-
/** settings `failover` 节的原始合并值(经 readProviderFailoverSettingsNode 读取)。 */
|
|
85
|
-
readonly failoverSettings: unknown;
|
|
86
|
-
/**
|
|
87
|
-
* 装载预检宿主检查面(设计 §4.6):全部静态读取,零网络、零 OAuth 刷新。
|
|
88
|
-
* 必传——预检是安装契约的一部分,宿主缺失检查面时不应静默退化为无预检。
|
|
89
|
-
*/
|
|
90
|
-
readonly preflight: ProviderFailoverPreflightChecks;
|
|
91
|
-
/** 注入时钟(测试用确定性时间);缺省 Date.now。 */
|
|
92
|
-
readonly now?: () => number;
|
|
93
|
-
/** 宿主进程日志;缺省时配置警告静默丢弃。 */
|
|
94
|
-
readonly hostLogger?: HostLogger;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* 装配嵌入式 provider-failover 插件(设计 §4.8)。
|
|
98
|
-
*
|
|
99
|
-
* - 未配置 / 无有效 backupProviders 与 chains / 配置错误(已警告)→ 返回
|
|
100
|
-
* undefined,不注册任何面;残留 `failover.enabled` 键只警告并忽略(已移除,
|
|
101
|
-
* 2026-10-03 D-079),节点按其余字段正常解析装配。
|
|
102
|
-
* - 配置解析完成后同步执行装载预检(设计 §4.6):失败条目从候选源剔除并警告,
|
|
103
|
-
* 警告经模块级去重每进程至多一次;预检不阻断其余条目与主 provider 的正常使用。
|
|
104
|
-
* - 宿主侧装配失败由调用方兜底(failover 是可靠性能力,装载失败不得阻断会话)。
|
|
105
|
-
* - 熔断状态是模块级单例:本函数跨会话重复调用注册的是新包装器实例,但共享
|
|
106
|
-
* 同一份状态(设计 §4.2)。
|
|
107
|
-
*/
|
|
108
|
-
export declare function installProviderFailoverPlugin(runtime: CapabilityRuntime, options: ProviderFailoverInstallOptions): CapabilityPluginHandle | undefined;
|
|
109
|
-
export {};
|
|
110
|
-
//# sourceMappingURL=provider-failover.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"provider-failover.d.ts","sourceRoot":"","sources":["../../../src/core/extensions/provider-failover.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EACX,GAAG,EAMH,KAAK,EAEL,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,KAAK,sBAAsB,EAA4B,MAAM,wBAAwB,CAAC;AAC/F,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAYjE,eAAO,MAAM,2BAA2B,kCAAkC,CAAC;AAC3E,eAAO,MAAM,8BAA8B,sBAAsB,CAAC;AAElE;;;;GAIG;AACH,eAAO,MAAM,kCAAkC,4BAA4B,CAAC;AAE5E,kFAAsD;AACtD,MAAM,WAAW,6BAA6B;IAC7C,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IACpB,4FAAgD;IAChD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAC;IACjD,wGAA4D;IAC5D,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,2EAA2C;IAC3C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,oDAAsB;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACrB;AAcD,UAAU,wBAAwB;IACjC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;CACpC;AAED,UAAU,sBAAsB;IAC/B,wEAAkC;IAClC,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,eAAe,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5C,QAAQ,CAAC,MAAM,EAAE,SAAS,wBAAwB,EAAE,CAAC;CACrD;AA8CD;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAC1C,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GAC7B,sBAAsB,GAAG,SAAS,CAyFpC;AAED;;;;GAIG;AACH,wBAAgB,gCAAgC,CAC/C,eAAe,EAAE,IAAI,CAAC,6BAA6B,EAAE,qBAAqB,CAAC,GACzE,OAAO,CAET;AAED,UAAU,6BAA6B;IACtC,mBAAmB,IAAI,OAAO,CAAC;CAC/B;AAsBD,uGAAuC;AACvC,wBAAgB,kCAAkC,IAAI,IAAI,CAGzD;AA0cD;;;;GAIG;AACH,MAAM,WAAW,+BAA+B;IAC/C,gEAA0B;IAC1B,QAAQ,CAAC,YAAY,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,KAAK,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;IACrF,8GAA0E;IAC1E,QAAQ,CAAC,WAAW,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC;IACtD,uEAAuC;IACvC,QAAQ,CAAC,iBAAiB,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC;CAC5D;AA+HD,MAAM,WAAW,8BAA8B;IAC9C,oGAA0E;IAC1E,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;IACnC;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,+BAA+B,CAAC;IACpD,sEAAkC;IAClC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IAC5B,gEAA0B;IAC1B,QAAQ,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC;CACjC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,6BAA6B,CAC5C,OAAO,EAAE,iBAAiB,EAC1B,OAAO,EAAE,8BAA8B,GACrC,sBAAsB,GAAG,SAAS,CAyCpC","sourcesContent":["/**\n * 第一方 provider 主备切换插件(设计:docs/design/供应商能力槽位与主备切换设计.md §4)。\n *\n * 形态与 bootstrap-retry 同族——嵌入式第一方插件,策略经公共\n * `api.registerStreamFnWrapper` 注册面挂进宿主默认 stream 装配——但熔断状态是\n * **宿主模块级单例**(设计 §4.2):进程内所有会话与 subagent 共享同一份,不随\n * 会话 dispose,不持久化(重启后全部 CLOSED)。\n *\n * 判定哲学(设计 §2):只看流终态 done/error/aborted 与\"是否已向上层释放内容\n * 增量\"两个本地事实,不解读错误类型/错误码语义;原始 errorMessage 照透传保留,\n * 只用于事件归因与 diagnostics,不参与机器判定分支。aborted 不计数、不换道、\n * 状态不变。换道从第一次失败即发生;`failureThreshold` 只控制\"是否继续先撞主\"\n * (连续 N 次后熔断打开,请求直接落备用,冷却期满后以真实请求试探回主)。\n */\n\nimport type {\n\tApi,\n\tAssistantMessage,\n\tAssistantMessageDiagnostic,\n\tAssistantMessageEvent,\n\tAssistantMessageEventStream,\n\tContext,\n\tModel,\n\tSimpleStreamOptions,\n} from \"@agent-forge/ai/compat\";\nimport { createAssistantMessageEventStream } from \"@agent-forge/ai/compat\";\nimport type { HostLogger } from \"../logger.ts\";\nimport { type CapabilityPluginHandle, loadCapabilityPluginSync } from \"./capability-plugin.ts\";\nimport type { CapabilityRuntime } from \"./capability-runtime.ts\";\nimport {\n\tPROVIDER_FAILOVER_PROBE_FAILED_EVENT_ID,\n\tPROVIDER_FAILOVER_PROBE_FAILED_EVENT_VERSION,\n\tPROVIDER_FAILOVER_RECOVERED_EVENT_ID,\n\tPROVIDER_FAILOVER_RECOVERED_EVENT_VERSION,\n\tPROVIDER_FAILOVER_SWITCHED_EVENT_ID,\n\tPROVIDER_FAILOVER_SWITCHED_EVENT_VERSION,\n} from \"./lifecycle-catalog.ts\";\nimport type { LifecycleDispatchRequest, SessionAPI, StreamFnWrapper } from \"./public-api.ts\";\nimport { EXPERIMENTAL_PUBLIC_API_VERSION } from \"./public-api.ts\";\n\nexport const PROVIDER_FAILOVER_PLUGIN_ID = \"agent-forge.provider-failover\";\nexport const PROVIDER_FAILOVER_WRAPPER_NAME = \"provider-failover\";\n\n/**\n * 会话日志快照通道的 customType(设计 §4.7 Phase 3):插件经公共\n * `api.session.appendEntry` 在状态转移点写入快照,footer 每帧取最后一条渲染\n * 摘要行——与 goal.state / todo.state / workflow.state 同构,零新公共面。\n */\nexport const PROVIDER_FAILOVER_STATE_ENTRY_TYPE = \"provider.failover.state\";\n\n/** `provider.failover.state` 快照负载(footer 按最后一条渲染)。 */\nexport interface ProviderFailoverStateSnapshot {\n\treadonly version: 1;\n\t/** 主链引用 `provider/modelId`;装配期初始快照无链上下文,为空串。 */\n\treadonly chainId: string;\n\treadonly status: \"closed\" | \"open\" | \"half-open\";\n\t/** 当前换道目标引用 `provider/modelId`(OPEN 期请求从链头重走);closed 省略。 */\n\treadonly backupProvider?: string;\n\t/** 下次试探时间戳 = open 时刻 + 当前冷却;closed 为 0。 */\n\treadonly probeAtMs: number;\n\t/** 快照写入时刻(注入时钟友好)。 */\n\treadonly now: number;\n}\n\n/** 链默认阈值/冷却(设计 §4.1:默认值全部可省)。 */\nconst DEFAULT_FAILURE_THRESHOLD = 2;\nconst DEFAULT_COOLDOWN_INITIAL_MS = 60_000;\nconst DEFAULT_COOLDOWN_MAX_MS = 15 * 60_000;\n/** 事件负载与 diagnostics 里的原始错误文本截断上限(只影响展示,不影响判定)。 */\nconst RAW_ERROR_MAX_LENGTH = 500;\n\n// ---------------------------------------------------------------------------\n// 配置解析(局部类型声明:settings `failover` 节不是 settings-manager 的已知面,\n// 解析与校验全部收在本模块内,宿主只递交原始节点)\n// ---------------------------------------------------------------------------\n\ninterface FailoverChainDeclaration {\n\treadonly primary: string;\n\treadonly backups: readonly string[];\n}\n\ninterface ResolvedFailoverConfig {\n\t/** 试探失败冷却起点(也是回 CLOSED 后的重置值)。 */\n\treadonly cooldownInitialMs: number;\n\treadonly cooldownMaxMs: number;\n\treadonly failureThreshold: number;\n\treadonly backupProviders: readonly string[];\n\treadonly chains: readonly FailoverChainDeclaration[];\n}\n\nconst isPlainObject = (value: unknown): value is Record<string, unknown> =>\n\ttypeof value === \"object\" && value !== null && !Array.isArray(value);\n\nfunction parseModelReference(reference: string): { provider: string; modelId: string } | undefined {\n\tconst separator = reference.indexOf(\"/\");\n\tif (separator <= 0 || separator === reference.length - 1) return undefined;\n\treturn { provider: reference.slice(0, separator), modelId: reference.slice(separator + 1) };\n}\n\nfunction parseModelReferenceList(value: unknown, label: string, warn: (message: string) => void): string[] | undefined {\n\tif (value === undefined) return undefined;\n\tif (!Array.isArray(value)) {\n\t\twarn(`failover ${label} must be an array of \"provider/modelId\" strings; ignoring it`);\n\t\treturn undefined;\n\t}\n\tconst references: string[] = [];\n\tfor (const entry of value) {\n\t\tif (typeof entry !== \"string\" || parseModelReference(entry) === undefined) {\n\t\t\twarn(`failover ${label} contains a non-\"provider/modelId\" entry; skipping it`);\n\t\t\tcontinue;\n\t\t}\n\t\treferences.push(entry);\n\t}\n\treturn references;\n}\n\n/** `backupProviders` 是纯 provider id 列表(设计 §4.1:`[\"proxy-a\", \"proxy-b\"]`),匹配运行时做。 */\nfunction parseProviderIdList(value: unknown, warn: (message: string) => void): string[] | undefined {\n\tif (value === undefined) return undefined;\n\tif (!Array.isArray(value)) {\n\t\twarn(\"failover.backupProviders must be an array of provider id strings; ignoring it\");\n\t\treturn undefined;\n\t}\n\tconst providerIds: string[] = [];\n\tfor (const entry of value) {\n\t\tif (typeof entry !== \"string\" || entry.trim() === \"\") {\n\t\t\twarn(\"failover.backupProviders contains a non-string entry; skipping it\");\n\t\t\tcontinue;\n\t\t}\n\t\tproviderIds.push(entry);\n\t}\n\treturn providerIds;\n}\n\n/**\n * 解析 settings `failover` 节。返回 undefined = 无 failover(未配置 / 无有效\n * backupProviders 与 chains / 配置错误拒绝加载——后者附带一条警告,设计 §4.1\n * \"重复 primary 拒绝加载并警告\")。`failover.enabled` 开关已移除(2026-10-03\n * D-079):节点存在即装配,残留 `enabled` 键只警告并忽略,按其余字段正常解析。\n */\nexport function parseProviderFailoverConfig(\n\traw: unknown,\n\twarn: (message: string) => void,\n): ResolvedFailoverConfig | undefined {\n\tif (raw === undefined || raw === null) return undefined;\n\tif (!isPlainObject(raw)) {\n\t\twarn(\"failover settings must be an object; provider failover stays disabled\");\n\t\treturn undefined;\n\t}\n\tif (raw.enabled !== undefined) {\n\t\twarn(\"failover.enabled was removed (2026-10-03): the failover node installs whenever configured; remove the key\");\n\t}\n\n\tlet failureThreshold = DEFAULT_FAILURE_THRESHOLD;\n\tif (raw.failureThreshold !== undefined) {\n\t\tif (\n\t\t\ttypeof raw.failureThreshold !== \"number\" ||\n\t\t\t!Number.isSafeInteger(raw.failureThreshold) ||\n\t\t\traw.failureThreshold < 1\n\t\t) {\n\t\t\twarn(\"failover.failureThreshold must be a positive integer; using the default (2)\");\n\t\t} else {\n\t\t\tfailureThreshold = raw.failureThreshold;\n\t\t}\n\t}\n\n\tlet cooldownInitialMs = DEFAULT_COOLDOWN_INITIAL_MS;\n\tlet cooldownMaxMs = DEFAULT_COOLDOWN_MAX_MS;\n\tif (raw.cooldown !== undefined) {\n\t\tif (!isPlainObject(raw.cooldown)) {\n\t\t\twarn(\"failover.cooldown must be an object { initialMs?, maxMs? }; using the defaults\");\n\t\t} else {\n\t\t\tconst initialMs = raw.cooldown.initialMs;\n\t\t\tconst maxMs = raw.cooldown.maxMs;\n\t\t\tif (\n\t\t\t\tinitialMs !== undefined &&\n\t\t\t\t(typeof initialMs !== \"number\" || !Number.isSafeInteger(initialMs) || initialMs < 1)\n\t\t\t) {\n\t\t\t\twarn(\"failover.cooldown.initialMs must be a positive integer; using the default (60000)\");\n\t\t\t} else if (initialMs !== undefined) {\n\t\t\t\tcooldownInitialMs = initialMs;\n\t\t\t}\n\t\t\tif (maxMs !== undefined && (typeof maxMs !== \"number\" || !Number.isSafeInteger(maxMs) || maxMs < 1)) {\n\t\t\t\twarn(\"failover.cooldown.maxMs must be a positive integer; using the default (900000)\");\n\t\t\t} else if (maxMs !== undefined) {\n\t\t\t\tcooldownMaxMs = maxMs;\n\t\t\t}\n\t\t}\n\t}\n\tif (cooldownMaxMs < cooldownInitialMs) {\n\t\twarn(\"failover.cooldown.maxMs is below initialMs; clamping maxMs to initialMs\");\n\t\tcooldownMaxMs = cooldownInitialMs;\n\t}\n\n\tconst backupProviders = parseProviderIdList(raw.backupProviders, warn) ?? [];\n\n\tconst chains: FailoverChainDeclaration[] = [];\n\tif (raw.chains !== undefined) {\n\t\tif (!Array.isArray(raw.chains)) {\n\t\t\twarn(\"failover.chains must be an array; ignoring explicit chains\");\n\t\t} else {\n\t\t\tconst seenPrimaries = new Set<string>();\n\t\t\tfor (const entry of raw.chains) {\n\t\t\t\tif (!isPlainObject(entry)) {\n\t\t\t\t\twarn(\"failover.chains entries must be objects; skipping one\");\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (typeof entry.primary !== \"string\" || parseModelReference(entry.primary) === undefined) {\n\t\t\t\t\twarn('failover.chains entry is missing a valid \"provider/modelId\" primary; skipping it');\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst backups = parseModelReferenceList(entry.backups, `chains[${entry.primary}].backups`, warn) ?? [];\n\t\t\t\tif (seenPrimaries.has(entry.primary)) {\n\t\t\t\t\t// 设计 §4.1:同一 primary 出现在多条显式链 → 配置错误拒绝加载。\n\t\t\t\t\twarn(\n\t\t\t\t\t\t`failover.chains declares primary \"${entry.primary}\" more than once; provider failover stays disabled`,\n\t\t\t\t\t);\n\t\t\t\t\treturn undefined;\n\t\t\t\t}\n\t\t\t\tseenPrimaries.add(entry.primary);\n\t\t\t\tif (backups.length > 2) {\n\t\t\t\t\twarn(\n\t\t\t\t\t\t`failover chain \"${entry.primary}\" declares ${backups.length} backups; the worst-case retry budget grows with chain length (recommended: at most 2)`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tchains.push({ primary: entry.primary, backups });\n\t\t\t}\n\t\t}\n\t}\n\n\tif (backupProviders.length === 0 && chains.length === 0) return undefined;\n\treturn { cooldownInitialMs, cooldownMaxMs, failureThreshold, backupProviders, chains };\n}\n\n/**\n * 从 SettingsManager 现有读面取合并后的 `failover` 原始节点(设计 §4.1 配置面):\n * `getFailoverSettings()`(Phase 1 落地)原样透传合并层对象,本层不做结构收窄\n * ——解析与校验全部收在本模块(见 parseProviderFailoverConfig)。\n */\nexport function readProviderFailoverSettingsNode(\n\tsettingsManager: Pick<SettingsManagerFailoverReader, \"getFailoverSettings\">,\n): unknown {\n\treturn settingsManager.getFailoverSettings();\n}\n\ninterface SettingsManagerFailoverReader {\n\tgetFailoverSettings(): unknown;\n}\n\n// ---------------------------------------------------------------------------\n// 熔断状态机(模块级单例,设计 §4.2:进程内所有会话共享,不持久化)\n// ---------------------------------------------------------------------------\n\ntype ProviderBreakerStatus = \"closed\" | \"open\" | \"half-open\";\n\ninterface ProviderBreakerState {\n\tstatus: ProviderBreakerStatus;\n\t/** CLOSED 期主连续失败计数;任一主 done 清零(设计 §4.2)。 */\n\tconsecutiveFailures: number;\n\t/** 当前冷却时长:打开时取 initialMs,每次试探失败 ×2 封顶 maxMs。 */\n\tcooldownMs: number;\n\topenedAtMs: number;\n}\n\nconst providerBreakerRegistry = new Map<string, ProviderBreakerState>();\n\n/** 预检警告去重集(设计 §4.6:每进程至多一次,与会话重复装载解耦)。 */\nconst preflightWarnedMessages = new Set<string>();\n\n/** 测试隔离钩子:清空模块级熔断单例与预检警告去重集(仅测试使用)。 */\nexport function resetProviderFailoverStateForTests(): void {\n\tproviderBreakerRegistry.clear();\n\tpreflightWarnedMessages.clear();\n}\n\nfunction getBreaker(chainId: string, config: ResolvedFailoverConfig): ProviderBreakerState {\n\tlet breaker = providerBreakerRegistry.get(chainId);\n\tif (breaker === undefined) {\n\t\tbreaker = {\n\t\t\tstatus: \"closed\",\n\t\t\tconsecutiveFailures: 0,\n\t\t\tcooldownMs: config.cooldownInitialMs,\n\t\t\topenedAtMs: 0,\n\t\t};\n\t\tproviderBreakerRegistry.set(chainId, breaker);\n\t}\n\treturn breaker;\n}\n\n// ---------------------------------------------------------------------------\n// 换道主体\n// ---------------------------------------------------------------------------\n\ninterface FailoverAttempt {\n\treadonly model: Model<Api>;\n\treadonly role: \"primary\" | \"backup\";\n}\n\ninterface AttemptFailure {\n\treadonly model: Model<Api>;\n\t/** 失败尝试的原始错误消息(照透传;诊断与事件只做展示截断)。 */\n\treadonly message: AssistantMessage;\n}\n\ntype AttemptOutcome =\n\t| { readonly outcome: \"done\"; readonly message: AssistantMessage }\n\t| { readonly outcome: \"aborted\"; readonly message: AssistantMessage }\n\t/** 已过提交边界(内容增量已释放)的 error:终态已转发,不可换道。 */\n\t| { readonly outcome: \"failed-forwarded\"; readonly message: AssistantMessage }\n\t/** 未过提交边界的 error:上层尚未看到任何事件,可安全重放。 */\n\t| { readonly outcome: \"failed-switchable\"; readonly failure: AttemptFailure };\n\nconst isCommittedDelta = (event: { type: string }): boolean =>\n\tevent.type === \"text_delta\" || event.type === \"thinking_delta\" || event.type === \"toolcall_delta\";\n\nfunction truncateRawError(text: string | undefined): string {\n\tconst value = text === undefined || text === \"\" ? \"unknown error\" : text;\n\treturn value.length > RAW_ERROR_MAX_LENGTH ? `${value.slice(0, RAW_ERROR_MAX_LENGTH)}…[truncated]` : value;\n}\n\nfunction createThrownErrorMessage(model: Model<Api>, error: unknown, nowMs: number): AssistantMessage {\n\treturn {\n\t\trole: \"assistant\",\n\t\tcontent: [],\n\t\tapi: model.api,\n\t\tprovider: model.provider,\n\t\tmodel: model.id,\n\t\tusage: {\n\t\t\tinput: 0,\n\t\t\toutput: 0,\n\t\t\tcacheRead: 0,\n\t\t\tcacheWrite: 0,\n\t\t\ttotalTokens: 0,\n\t\t\tcost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },\n\t\t},\n\t\tstopReason: \"error\",\n\t\terrorMessage: error instanceof Error ? error.message : String(error),\n\t\ttimestamp: nowMs,\n\t};\n}\n\n/**\n * 换道重放的凭据剔除(设计 §4.4):apiKey/headers/env 是主 provider 的预解析\n * 凭据,照抄重放会把主的 key 发给备用 provider——剔除后由目标 provider 经\n * 宿主 auth 解析重新注入。其余 options(signal、预算、缓存策略等)原样保留。\n */\nfunction stripCredentialOptions(options: SimpleStreamOptions | undefined): SimpleStreamOptions | undefined {\n\tif (options === undefined) return undefined;\n\tconst { apiKey: _apiKey, headers: _headers, env: _env, ...rest } = options;\n\treturn rest;\n}\n\n/** 候选序列解析(设计 §4.1):显式链优先,否则 backupProviders 按声明顺序同 id 匹配。 */\nfunction resolveFailoverCandidates(\n\tmodel: Model<Api>,\n\tconfig: ResolvedFailoverConfig,\n\tresolveModel: (provider: string, modelId: string) => Model<Api> | undefined,\n): Model<Api>[] {\n\tconst reference = `${model.provider}/${model.id}`;\n\tconst chain = config.chains.find((entry) => entry.primary === reference);\n\tif (chain !== undefined) {\n\t\tconst candidates: Model<Api>[] = [];\n\t\tfor (const backup of chain.backups) {\n\t\t\tconst parsed = parseModelReference(backup);\n\t\t\tconst resolved = parsed === undefined ? undefined : resolveModel(parsed.provider, parsed.modelId);\n\t\t\tif (resolved === undefined) continue;\n\t\t\tif (resolved.provider === model.provider && resolved.id === model.id) continue;\n\t\t\tcandidates.push(resolved);\n\t\t}\n\t\treturn candidates;\n\t}\n\tconst candidates: Model<Api>[] = [];\n\tfor (const providerId of config.backupProviders) {\n\t\t// 含主 provider 自身 → 忽略该项(设计 §4.1)。\n\t\tif (providerId === model.provider) continue;\n\t\tconst resolved = resolveModel(providerId, model.id);\n\t\tif (resolved !== undefined) candidates.push(resolved);\n\t}\n\treturn candidates;\n}\n\ninterface ProviderFailoverRuntimeDeps {\n\treadonly runtime: CapabilityRuntime;\n\treadonly config: ResolvedFailoverConfig;\n\treadonly now: () => number;\n\t/**\n\t * 会话日志快照通道(宿主声明 `session` feature 时在场;最小宿主可缺席)。\n\t * 缺席只损失 footer 可见性,不影响换道判定。\n\t */\n\treadonly session?: Pick<SessionAPI, \"appendEntry\">;\n\t/** 快照写入失败的警告通道;缺省静默(与 lifecycle 事件通道同级)。 */\n\treadonly hostLogger?: HostLogger;\n}\n\n/**\n * 写一条熔断状态快照进会话日志(设计 §4.7 Phase 3)。尽力通道:失败不打断\n * 换道判定,但经进程日志警告保持失败可见。\n */\nfunction writeStateSnapshot(deps: ProviderFailoverRuntimeDeps, snapshot: ProviderFailoverStateSnapshot): void {\n\tif (deps.session === undefined) return;\n\ttry {\n\t\tdeps.session.appendEntry(PROVIDER_FAILOVER_STATE_ENTRY_TYPE, snapshot);\n\t} catch (error) {\n\t\tdeps.hostLogger?.warn(\"provider-failover\", \"failover state snapshot append failed\", { cause: error });\n\t}\n}\n\n/** OPEN 转移点(阈值打开 / 试探失败重开)共用的 open 快照。 */\nfunction writeOpenStateSnapshot(\n\tdeps: ProviderFailoverRuntimeDeps,\n\tchainId: string,\n\tbreaker: ProviderBreakerState,\n\tbackupReference: string | undefined,\n): void {\n\twriteStateSnapshot(deps, {\n\t\tversion: 1,\n\t\tchainId,\n\t\tstatus: \"open\",\n\t\t...(backupReference === undefined ? {} : { backupProvider: backupReference }),\n\t\tprobeAtMs: breaker.openedAtMs + breaker.cooldownMs,\n\t\tnow: breaker.openedAtMs,\n\t});\n}\n\nfunction dispatchFailoverEvent(deps: ProviderFailoverRuntimeDeps, request: LifecycleDispatchRequest): void {\n\ttry {\n\t\tif (!deps.runtime.hasLifecycleEvent(request.type, request.version)) return;\n\t\tvoid deps.runtime.dispatchLifecycle(request).catch(() => {\n\t\t\t// 可见性事件失败不打断换道判定(宪法 §8 的尽力通道)。\n\t\t});\n\t} catch {\n\t\t// 同上:派发入口同步抛错也不影响请求路径。\n\t}\n}\n\nfunction createFailoverWrapper(deps: ProviderFailoverRuntimeDeps): StreamFnWrapper {\n\treturn (modelArgument, contextArgument, optionsArgument, next, host) => {\n\t\tconst model = modelArgument as Model<Api>;\n\t\tconst context = contextArgument as Context;\n\t\tconst options = optionsArgument as SimpleStreamOptions | undefined;\n\t\tconst outer = createAssistantMessageEventStream();\n\t\tconst resolveModel = (provider: string, modelId: string): Model<Api> | undefined =>\n\t\t\thost.resolveModel(provider, modelId) as Model<Api> | undefined;\n\t\tvoid driveFailoverStream(deps, outer, model, context, options, next, resolveModel);\n\t\treturn outer;\n\t};\n}\n\nasync function driveFailoverStream(\n\tdeps: ProviderFailoverRuntimeDeps,\n\touter: AssistantMessageEventStream,\n\tmodel: Model<Api>,\n\tcontext: Context,\n\toptions: SimpleStreamOptions | undefined,\n\tnext: (model: unknown, context: unknown, options: unknown) => unknown,\n\tresolveModel: (provider: string, modelId: string) => Model<Api> | undefined,\n): Promise<void> {\n\tconst { config } = deps;\n\tconst nowMs = deps.now();\n\tconst chainId = `${model.provider}/${model.id}`;\n\tconst breaker = getBreaker(chainId, config);\n\n\t// 入场判定(设计 §4.3 判定表):CLOSED/HALF_OPEN 撞主,OPEN 且冷却未满落备用。\n\tlet attemptPrimary = true;\n\tlet isProbe = false;\n\tif (breaker.status === \"open\") {\n\t\tif (nowMs - breaker.openedAtMs >= breaker.cooldownMs) {\n\t\t\t// 冷却期满:下一个真实请求改道回主作试探(HALF_OPEN 并发放行)。\n\t\t\tbreaker.status = \"half-open\";\n\t\t\tisProbe = true;\n\t\t} else {\n\t\t\tattemptPrimary = false;\n\t\t}\n\t} else if (breaker.status === \"half-open\") {\n\t\tisProbe = true;\n\t}\n\n\tconst candidates = resolveFailoverCandidates(model, config, resolveModel);\n\t// OPEN 期请求从链头重走(设计 §4.3),快照披露的换道目标 = 链头候选。\n\tconst backupReference = candidates[0] === undefined ? undefined : `${candidates[0].provider}/${candidates[0].id}`;\n\n\tconst attempts: FailoverAttempt[] = [];\n\tif (attemptPrimary) attempts.push({ model, role: \"primary\" });\n\tfor (const candidate of candidates) attempts.push({ model: candidate, role: \"backup\" });\n\tif (attempts.length === 0) {\n\t\t// OPEN 且候选为空:无别处可去,直发主(按普通主请求计账,不作试探)。\n\t\tattempts.push({ model, role: \"primary\" });\n\t}\n\n\tconst failures: AttemptFailure[] = [];\n\tlet switchOrdinal = 0;\n\tfor (let index = 0; index < attempts.length; index++) {\n\t\tconst attempt = attempts[index];\n\t\tconst attemptOptions = attempt.role === \"backup\" ? stripCredentialOptions(options) : options;\n\t\tconst result = await runFailoverAttempt(outer, next, attempt.model, context, attemptOptions, deps.now);\n\n\t\tif (result.outcome === \"done\") {\n\t\t\tif (attempt.role === \"primary\") {\n\t\t\t\tbreaker.status = \"closed\";\n\t\t\t\tbreaker.consecutiveFailures = 0;\n\t\t\t\tbreaker.cooldownMs = config.cooldownInitialMs;\n\t\t\t\tif (isProbe) {\n\t\t\t\t\tdispatchFailoverEvent(deps, {\n\t\t\t\t\t\ttype: PROVIDER_FAILOVER_RECOVERED_EVENT_ID,\n\t\t\t\t\t\tversion: PROVIDER_FAILOVER_RECOVERED_EVENT_VERSION,\n\t\t\t\t\t\tphase: \"committed\",\n\t\t\t\t\t\tsource: PROVIDER_FAILOVER_PLUGIN_ID,\n\t\t\t\t\t\tdata: { version: 1, chainId, provider: model.provider },\n\t\t\t\t\t});\n\t\t\t\t\t// HALF_OPEN → CLOSED 转移点:footer 摘要行随最后一条 closed 快照消失。\n\t\t\t\t\twriteStateSnapshot(deps, {\n\t\t\t\t\t\tversion: 1,\n\t\t\t\t\t\tchainId,\n\t\t\t\t\t\tstatus: \"closed\",\n\t\t\t\t\t\tprobeAtMs: 0,\n\t\t\t\t\t\tnow: deps.now(),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t\t// 备用成败不影响 primary 熔断状态(设计 §4.2)。\n\t\t\treturn;\n\t\t}\n\n\t\tif (result.outcome === \"aborted\") {\n\t\t\t// 用户本地取消:不计数、不换道、状态不变(设计 §2/§4.3)。\n\t\t\treturn;\n\t\t}\n\n\t\tif (result.outcome === \"failed-forwarded\") {\n\t\t\t// 已过提交边界:不可重放,交回合级重试;主失败照常计数。\n\t\t\tif (attempt.role === \"primary\") {\n\t\t\t\trecordPrimaryFailure(deps, breaker, config, chainId, result.message, isProbe, backupReference);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// failed-switchable:无可见内容,可换道重放。\n\t\tfailures.push(result.failure);\n\t\tif (attempt.role === \"primary\") {\n\t\t\trecordPrimaryFailure(deps, breaker, config, chainId, result.failure.message, isProbe, backupReference);\n\t\t}\n\n\t\tif (index + 1 < attempts.length) {\n\t\t\tswitchOrdinal += 1;\n\t\t\tconst target = attempts[index + 1];\n\t\t\tdispatchFailoverEvent(deps, {\n\t\t\t\ttype: PROVIDER_FAILOVER_SWITCHED_EVENT_ID,\n\t\t\t\tversion: PROVIDER_FAILOVER_SWITCHED_EVENT_VERSION,\n\t\t\t\tphase: \"committed\",\n\t\t\t\tsource: PROVIDER_FAILOVER_PLUGIN_ID,\n\t\t\t\tdata: {\n\t\t\t\t\tversion: 1,\n\t\t\t\t\tchainId,\n\t\t\t\t\tfrom: `${attempt.model.provider}/${attempt.model.id}`,\n\t\t\t\t\tto: `${target.model.provider}/${target.model.id}`,\n\t\t\t\t\tattempt: switchOrdinal,\n\t\t\t\t\trawError: truncateRawError(result.failure.message.errorMessage),\n\t\t\t\t},\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\t\tbreak;\n\t}\n\n\t// 全链尽:报链内最后一次实际失败的原始错误 + 整链摘要进 diagnostics(设计 §4.3)。\n\tconst lastFailure = failures[failures.length - 1];\n\tif (lastFailure === undefined) {\n\t\t// 不可达(至少一次 failed-switchable 才会走到这里);保守以合成错误收尾。\n\t\tconst message = createThrownErrorMessage(model, new Error(\"provider failover exhausted the chain\"), deps.now());\n\t\touter.push({ type: \"error\", reason: \"error\", error: message });\n\t\touter.end();\n\t\treturn;\n\t}\n\tconst diagnostic: AssistantMessageDiagnostic = {\n\t\ttype: \"provider-failover\",\n\t\ttimestamp: deps.now(),\n\t\tdetails: {\n\t\t\tchainId,\n\t\t\tattempts: failures.map((failure) => ({\n\t\t\t\tprovider: failure.model.provider,\n\t\t\t\tmodel: failure.model.id,\n\t\t\t\terror: truncateRawError(failure.message.errorMessage),\n\t\t\t})),\n\t\t},\n\t};\n\tconst finalMessage: AssistantMessage = {\n\t\t...lastFailure.message,\n\t\tdiagnostics: [...(lastFailure.message.diagnostics ?? []), diagnostic],\n\t};\n\touter.push({ type: \"error\", reason: \"error\", error: finalMessage });\n\touter.end();\n}\n\n/**\n * 主失败计账(设计 §4.2/§4.3):CLOSED 期连续 N 次达到阈值 → OPEN(冷却取\n * initialMs);HALF_OPEN 试探失败 → OPEN 且冷却 ×2 封顶 maxMs(经 probe.failed\n * 事件可见)。backup 的成败永远不进这里。\n */\nfunction recordPrimaryFailure(\n\tdeps: ProviderFailoverRuntimeDeps,\n\tbreaker: ProviderBreakerState,\n\tconfig: ResolvedFailoverConfig,\n\tchainId: string,\n\tmessage: AssistantMessage,\n\tisProbe: boolean,\n\tbackupReference: string | undefined,\n): void {\n\tif (isProbe) {\n\t\topenAfterFailedProbe(deps, breaker, config, chainId, message, backupReference);\n\t\treturn;\n\t}\n\tbreaker.consecutiveFailures += 1;\n\tif (breaker.consecutiveFailures >= config.failureThreshold) {\n\t\tbreaker.status = \"open\";\n\t\tbreaker.cooldownMs = config.cooldownInitialMs;\n\t\tbreaker.openedAtMs = deps.now();\n\t\twriteOpenStateSnapshot(deps, chainId, breaker, backupReference);\n\t}\n}\n\n/** HALF_OPEN 试探失败:回 OPEN,冷却 ×2 封顶 maxMs,并派发 probe.failed(设计 §4.2)。 */\nfunction openAfterFailedProbe(\n\tdeps: ProviderFailoverRuntimeDeps,\n\tbreaker: ProviderBreakerState,\n\tconfig: ResolvedFailoverConfig,\n\tchainId: string,\n\tmessage: AssistantMessage,\n\tbackupReference: string | undefined,\n): void {\n\tbreaker.status = \"open\";\n\tbreaker.cooldownMs = Math.min(breaker.cooldownMs * 2, config.cooldownMaxMs);\n\tbreaker.openedAtMs = deps.now();\n\tdispatchFailoverEvent(deps, {\n\t\ttype: PROVIDER_FAILOVER_PROBE_FAILED_EVENT_ID,\n\t\tversion: PROVIDER_FAILOVER_PROBE_FAILED_EVENT_VERSION,\n\t\tphase: \"committed\",\n\t\tsource: PROVIDER_FAILOVER_PLUGIN_ID,\n\t\tdata: {\n\t\t\tversion: 1,\n\t\t\tchainId,\n\t\t\tprovider: message.provider,\n\t\t\trawError: truncateRawError(message.errorMessage),\n\t\t\tnextCooldownMs: breaker.cooldownMs,\n\t\t},\n\t});\n\twriteOpenStateSnapshot(deps, chainId, breaker, backupReference);\n}\n\nasync function runFailoverAttempt(\n\touter: AssistantMessageEventStream,\n\tnext: (model: unknown, context: unknown, options: unknown) => unknown,\n\tattemptModel: Model<Api>,\n\tcontext: Context,\n\toptions: SimpleStreamOptions | undefined,\n\tnow: () => number,\n): Promise<AttemptOutcome> {\n\tlet inner: AssistantMessageEventStream;\n\ttry {\n\t\tinner = (await next(attemptModel, context, options)) as AssistantMessageEventStream;\n\t} catch (error) {\n\t\tconst message = createThrownErrorMessage(attemptModel, error, now());\n\t\treturn { outcome: \"failed-switchable\", failure: { model: attemptModel, message } };\n\t}\n\n\t// 前奏事件缓冲(设计 §4.4):提交边界(首个内容增量)或正常完成前不释放,\n\t// 使\"无可见内容\"的失败可以整段丢弃后无感重放。非增量、非终态事件(start、\n\t// *_start、*_end 及未知扩展事件)一律入缓冲——保守归入前奏,重放安全性优先。\n\tconst buffered: AssistantMessageEvent[] = [];\n\tlet committed = false;\n\tconst flushBuffer = (): void => {\n\t\tfor (const event of buffered) outer.push(event);\n\t\tbuffered.length = 0;\n\t};\n\ttry {\n\t\tfor await (const event of inner) {\n\t\t\tif (event.type === \"done\") {\n\t\t\t\tflushBuffer();\n\t\t\t\touter.push(event);\n\t\t\t\touter.end();\n\t\t\t\treturn { outcome: \"done\", message: event.message };\n\t\t\t}\n\t\t\tif (event.type === \"error\") {\n\t\t\t\tif (event.reason === \"aborted\") {\n\t\t\t\t\t// 不重放的终态:丢弃缓冲只发终态,避免上层收到孤立 start。\n\t\t\t\t\touter.push(event);\n\t\t\t\t\touter.end();\n\t\t\t\t\treturn { outcome: \"aborted\", message: event.error };\n\t\t\t\t}\n\t\t\t\tif (committed) {\n\t\t\t\t\touter.push(event);\n\t\t\t\t\touter.end();\n\t\t\t\t\treturn { outcome: \"failed-forwarded\", message: event.error };\n\t\t\t\t}\n\t\t\t\treturn { outcome: \"failed-switchable\", failure: { model: attemptModel, message: event.error } };\n\t\t\t}\n\t\t\tif (isCommittedDelta(event)) {\n\t\t\t\tif (!committed) {\n\t\t\t\t\tcommitted = true;\n\t\t\t\t\tflushBuffer();\n\t\t\t\t}\n\t\t\t\touter.push(event);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (committed) outer.push(event);\n\t\t\telse buffered.push(event);\n\t\t}\n\t} catch (error) {\n\t\tconst message = createThrownErrorMessage(attemptModel, error, now());\n\t\tif (committed) {\n\t\t\tconst errorEvent = { type: \"error\" as const, reason: \"error\" as const, error: message };\n\t\t\touter.push(errorEvent);\n\t\t\touter.end();\n\t\t\treturn { outcome: \"failed-forwarded\", message };\n\t\t}\n\t\treturn { outcome: \"failed-switchable\", failure: { model: attemptModel, message } };\n\t}\n\n\t// 流自然结束但没有终止信号:按设计 §2 的归一哲学视作 error 终态。\n\tconst message = createThrownErrorMessage(attemptModel, new Error(\"stream ended without a terminal event\"), now());\n\tif (committed) {\n\t\touter.push({ type: \"error\", reason: \"error\", error: message });\n\t\touter.end();\n\t\treturn { outcome: \"failed-forwarded\", message };\n\t}\n\treturn { outcome: \"failed-switchable\", failure: { model: attemptModel, message } };\n}\n\n// ---------------------------------------------------------------------------\n// 装载预检(设计 §4.6:插件安装时同步执行的静态检查,零网络请求)\n// ---------------------------------------------------------------------------\n\n/**\n * 装载预检的宿主静态检查面(设计 §4.6)。全部为目录/凭据快照读取:不发网络\n * 请求、不触发 OAuth 刷新(凭据检查与 ModelRuntime.hasConfiguredAuth 同构——\n * 只读\"该 provider 是否有凭据条目\",不做可用性探测)。\n */\nexport interface ProviderFailoverPreflightChecks {\n\t/** 目录解析,与运行时换道候选解析同一面。 */\n\treadonly resolveModel: (provider: string, modelId: string) => Model<Api> | undefined;\n\t/** provider 在组合目录(builtin + models.json + 扩展)中存在(backupProviders 层预检)。 */\n\treadonly hasProvider: (providerId: string) => boolean;\n\t/** provider 有凭据条目(静态;不触发 OAuth 刷新)。 */\n\treadonly hasConfiguredAuth: (providerId: string) => boolean;\n}\n\n/**\n * 稳定序列化(键排序、剔除 undefined):compat/thinkingLevelMap 的派生差异按\n * 值比较,不依赖对象键序。\n */\nfunction stableStringify(value: unknown): string {\n\tif (value === undefined) return \"∅\";\n\tif (value === null || typeof value !== \"object\") return JSON.stringify(value) ?? String(value);\n\tif (Array.isArray(value)) return `[${value.map(stableStringify).join(\",\")}]`;\n\tconst entries = Object.entries(value as Record<string, unknown>)\n\t\t.filter(([, entryValue]) => entryValue !== undefined)\n\t\t.sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0));\n\treturn `{${entries.map(([key, entryValue]) => `${JSON.stringify(key)}:${stableStringify(entryValue)}`).join(\",\")}}`;\n}\n\n/**\n * 显式链全量预检(设计 §4.6):每个 backup 逐一检查,失败条目从链中剔除并\n * 警告;主不可解析 → 整链跳过。contextWindow/compat/thinkingLevelMap/maxTokens\n * 差异只进警告清单、不硬拦——实施裁量:contextWindow 低于主的备用对小上下文\n * 请求仍可成功,剔除条目会静默损失兜底;只有上下文逼近主窗口的请求才必失败,\n * 该情形运行时走链内下一候选,有界。\n */\nfunction preflightExplicitChain(\n\tchain: FailoverChainDeclaration,\n\tchecks: ProviderFailoverPreflightChecks,\n\twarn: (message: string) => void,\n): FailoverChainDeclaration | undefined {\n\tconst parsedPrimary = parseModelReference(chain.primary);\n\tconst primaryModel =\n\t\tparsedPrimary === undefined ? undefined : checks.resolveModel(parsedPrimary.provider, parsedPrimary.modelId);\n\tif (parsedPrimary === undefined || primaryModel === undefined) {\n\t\twarn(`failover chain \"${chain.primary}\" primary does not resolve in the model catalog; skipping the chain`);\n\t\treturn undefined;\n\t}\n\tconst backups: string[] = [];\n\tfor (const backup of chain.backups) {\n\t\tconst parsed = parseModelReference(backup);\n\t\tconst backupModel = parsed === undefined ? undefined : checks.resolveModel(parsed.provider, parsed.modelId);\n\t\tif (parsed === undefined || backupModel === undefined) {\n\t\t\twarn(\n\t\t\t\t`failover chain \"${chain.primary}\" backup \"${backup}\" does not resolve in the model catalog; skipping it`,\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\t\tif (!checks.hasConfiguredAuth(backupModel.provider)) {\n\t\t\twarn(\n\t\t\t\t`failover chain \"${chain.primary}\" backup provider \"${backupModel.provider}\" has no configured credentials; skipping \"${backup}\"`,\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\t\tif (backupModel.contextWindow < primaryModel.contextWindow) {\n\t\t\twarn(\n\t\t\t\t`failover chain \"${chain.primary}\" backup \"${backup}\" context window (${backupModel.contextWindow}) is below the primary's (${primaryModel.contextWindow}); contexts sized for the primary may fail on this backup (entry kept)`,\n\t\t\t);\n\t\t}\n\t\tif (backupModel.maxTokens !== primaryModel.maxTokens) {\n\t\t\twarn(\n\t\t\t\t`failover chain \"${chain.primary}\" backup \"${backup}\" maxTokens (${backupModel.maxTokens}) differs from the primary's (${primaryModel.maxTokens}); output budget may change after switching`,\n\t\t\t);\n\t\t}\n\t\tif (stableStringify(backupModel.compat) !== stableStringify(primaryModel.compat)) {\n\t\t\twarn(\n\t\t\t\t`failover chain \"${chain.primary}\" backup \"${backup}\" compat differs from the primary's; request derivation may change after switching`,\n\t\t\t);\n\t\t}\n\t\tif (stableStringify(backupModel.thinkingLevelMap) !== stableStringify(primaryModel.thinkingLevelMap)) {\n\t\t\twarn(\n\t\t\t\t`failover chain \"${chain.primary}\" backup \"${backup}\" thinkingLevelMap differs from the primary's; reasoning level mapping may change after switching`,\n\t\t\t);\n\t\t}\n\t\tbackups.push(backup);\n\t}\n\tif (backups.length === 0 && chain.backups.length > 0) {\n\t\twarn(\n\t\t\t`failover chain \"${chain.primary}\" has no usable backups left after preflight; the primary keeps no failover candidates from this chain`,\n\t\t);\n\t}\n\treturn { primary: chain.primary, backups };\n}\n\n/**\n * backupProviders 层预检(设计 §4.6):仅检 provider 存在 + 凭据条目;模型匹配\n * 留运行时(目录同 id 匹配不到时静默跳过,不算失败)。\n */\nfunction preflightBackupProviders(\n\tproviderIds: readonly string[],\n\tchecks: ProviderFailoverPreflightChecks,\n\twarn: (message: string) => void,\n): string[] {\n\tconst retained: string[] = [];\n\tfor (const providerId of providerIds) {\n\t\tif (!checks.hasProvider(providerId)) {\n\t\t\twarn(`failover.backupProviders entry \"${providerId}\" is not a known provider; skipping it`);\n\t\t\tcontinue;\n\t\t}\n\t\tif (!checks.hasConfiguredAuth(providerId)) {\n\t\t\twarn(`failover.backupProviders entry \"${providerId}\" has no configured credentials; skipping it`);\n\t\t\tcontinue;\n\t\t}\n\t\tretained.push(providerId);\n\t}\n\treturn retained;\n}\n\n/**\n * 装载预检主体:返回过滤后的派生配置(预检失败条目已从候选源剔除)。不改变\n * 运行时换道判定——过滤只发生在装载期,运行时候选解析逻辑不变。\n */\nfunction runProviderFailoverPreflight(\n\tconfig: ResolvedFailoverConfig,\n\tchecks: ProviderFailoverPreflightChecks,\n\twarn: (message: string) => void,\n): ResolvedFailoverConfig {\n\tconst backupProviders = preflightBackupProviders(config.backupProviders, checks, warn);\n\tconst chains: FailoverChainDeclaration[] = [];\n\tfor (const chain of config.chains) {\n\t\tconst preflighted = preflightExplicitChain(chain, checks, warn);\n\t\tif (preflighted !== undefined) chains.push(preflighted);\n\t}\n\treturn { ...config, backupProviders, chains };\n}\n\n// ---------------------------------------------------------------------------\n// 装配\n// ---------------------------------------------------------------------------\n\nexport interface ProviderFailoverInstallOptions {\n\t/** settings `failover` 节的原始合并值(经 readProviderFailoverSettingsNode 读取)。 */\n\treadonly failoverSettings: unknown;\n\t/**\n\t * 装载预检宿主检查面(设计 §4.6):全部静态读取,零网络、零 OAuth 刷新。\n\t * 必传——预检是安装契约的一部分,宿主缺失检查面时不应静默退化为无预检。\n\t */\n\treadonly preflight: ProviderFailoverPreflightChecks;\n\t/** 注入时钟(测试用确定性时间);缺省 Date.now。 */\n\treadonly now?: () => number;\n\t/** 宿主进程日志;缺省时配置警告静默丢弃。 */\n\treadonly hostLogger?: HostLogger;\n}\n\n/**\n * 装配嵌入式 provider-failover 插件(设计 §4.8)。\n *\n * - 未配置 / 无有效 backupProviders 与 chains / 配置错误(已警告)→ 返回\n * undefined,不注册任何面;残留 `failover.enabled` 键只警告并忽略(已移除,\n * 2026-10-03 D-079),节点按其余字段正常解析装配。\n * - 配置解析完成后同步执行装载预检(设计 §4.6):失败条目从候选源剔除并警告,\n * 警告经模块级去重每进程至多一次;预检不阻断其余条目与主 provider 的正常使用。\n * - 宿主侧装配失败由调用方兜底(failover 是可靠性能力,装载失败不得阻断会话)。\n * - 熔断状态是模块级单例:本函数跨会话重复调用注册的是新包装器实例,但共享\n * 同一份状态(设计 §4.2)。\n */\nexport function installProviderFailoverPlugin(\n\truntime: CapabilityRuntime,\n\toptions: ProviderFailoverInstallOptions,\n): CapabilityPluginHandle | undefined {\n\tconst warn =\n\t\toptions.hostLogger === undefined\n\t\t\t? (_message: string) => {}\n\t\t\t: (message: string) => {\n\t\t\t\t\toptions.hostLogger?.warn(\"provider-failover\", message);\n\t\t\t\t};\n\tconst config = parseProviderFailoverConfig(options.failoverSettings, warn);\n\tif (config === undefined) return undefined;\n\tconst warnPreflightOnce = (message: string): void => {\n\t\tif (preflightWarnedMessages.has(message)) return;\n\t\tpreflightWarnedMessages.add(message);\n\t\twarn(message);\n\t};\n\tconst preflighted = runProviderFailoverPreflight(config, options.preflight, warnPreflightOnce);\n\tconst now = options.now ?? (() => Date.now());\n\treturn loadCapabilityPluginSync(\n\t\truntime,\n\t\t{\n\t\t\tid: PROVIDER_FAILOVER_PLUGIN_ID,\n\t\t\tversion: \"0.0.0\",\n\t\t\tapiVersion: EXPERIMENTAL_PUBLIC_API_VERSION,\n\t\t\tentry: \"<embedded:provider-failover>\",\n\t\t},\n\t\t(api) => {\n\t\t\t// 快照通道绑定本会话的公共 session 面(宿主声明 session feature 时在场):\n\t\t\t// 会话 A 触发的熔断只写进 A 的日志,footer 可见性是会话局部的(设计 §4.7\n\t\t\t// 保真度限制)。deps 须在此构建——api 只在工厂内可得。\n\t\t\tconst deps: ProviderFailoverRuntimeDeps = {\n\t\t\t\truntime,\n\t\t\t\tconfig: preflighted,\n\t\t\t\tnow,\n\t\t\t\tsession: api.session,\n\t\t\t\t...(options.hostLogger === undefined ? {} : { hostLogger: options.hostLogger }),\n\t\t\t};\n\t\t\tapi.registerStreamFnWrapper(PROVIDER_FAILOVER_WRAPPER_NAME, createFailoverWrapper(deps));\n\t\t\t// 装配期初始快照(status closed)覆盖恢复会话里的陈旧 open 残留:熔断\n\t\t\t// 状态不持久化,新进程恒 CLOSED(设计 §4.2/§4.7)。无链上下文 → chainId 空。\n\t\t\twriteStateSnapshot(deps, { version: 1, chainId: \"\", status: \"closed\", probeAtMs: 0, now: deps.now() });\n\t\t},\n\t);\n}\n"]}
|