@ai-agent-forge/agent-forge 0.88.5 → 0.88.6

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.
Files changed (198) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/bundled-plugins/agent-loop-policy/agent-forge.json +1 -1
  3. package/bundled-plugins/agent-loop-policy/plugin.json +1 -1
  4. package/bundled-plugins/alignment/agent-forge.json +19 -0
  5. package/bundled-plugins/alignment/dist/baseline.d.ts +12 -0
  6. package/bundled-plugins/alignment/dist/baseline.d.ts.map +1 -0
  7. package/bundled-plugins/alignment/dist/baseline.js +68 -0
  8. package/bundled-plugins/alignment/dist/baseline.js.map +1 -0
  9. package/bundled-plugins/alignment/dist/engine.d.ts +102 -0
  10. package/bundled-plugins/alignment/dist/engine.d.ts.map +1 -0
  11. package/bundled-plugins/alignment/dist/engine.js +654 -0
  12. package/bundled-plugins/alignment/dist/engine.js.map +1 -0
  13. package/bundled-plugins/alignment/dist/entry.d.ts +14 -0
  14. package/bundled-plugins/alignment/dist/entry.d.ts.map +1 -0
  15. package/bundled-plugins/alignment/dist/entry.js +23 -0
  16. package/bundled-plugins/alignment/dist/entry.js.map +1 -0
  17. package/bundled-plugins/alignment/dist/export.d.ts +15 -0
  18. package/bundled-plugins/alignment/dist/export.d.ts.map +1 -0
  19. package/bundled-plugins/alignment/dist/export.js +122 -0
  20. package/bundled-plugins/alignment/dist/export.js.map +1 -0
  21. package/bundled-plugins/alignment/dist/http-server.d.ts +33 -0
  22. package/bundled-plugins/alignment/dist/http-server.d.ts.map +1 -0
  23. package/bundled-plugins/alignment/dist/http-server.js +119 -0
  24. package/bundled-plugins/alignment/dist/http-server.js.map +1 -0
  25. package/bundled-plugins/alignment/dist/index.d.ts +24 -0
  26. package/bundled-plugins/alignment/dist/index.d.ts.map +1 -0
  27. package/bundled-plugins/alignment/dist/index.js +719 -0
  28. package/bundled-plugins/alignment/dist/index.js.map +1 -0
  29. package/bundled-plugins/alignment/dist/page.d.ts +15 -0
  30. package/bundled-plugins/alignment/dist/page.d.ts.map +1 -0
  31. package/bundled-plugins/alignment/dist/page.js +832 -0
  32. package/bundled-plugins/alignment/dist/page.js.map +1 -0
  33. package/bundled-plugins/alignment/dist/render.d.ts +40 -0
  34. package/bundled-plugins/alignment/dist/render.d.ts.map +1 -0
  35. package/bundled-plugins/alignment/dist/render.js +194 -0
  36. package/bundled-plugins/alignment/dist/render.js.map +1 -0
  37. package/bundled-plugins/alignment/dist/types.d.ts +217 -0
  38. package/bundled-plugins/alignment/dist/types.d.ts.map +1 -0
  39. package/bundled-plugins/alignment/dist/types.js +30 -0
  40. package/bundled-plugins/alignment/dist/types.js.map +1 -0
  41. package/bundled-plugins/alignment/plugin.json +12 -0
  42. package/bundled-plugins/browser-playwright/MANUAL.md +60 -0
  43. package/bundled-plugins/browser-playwright/agent-forge.json +25 -0
  44. package/bundled-plugins/browser-playwright/dist/capability.d.ts +25 -0
  45. package/bundled-plugins/browser-playwright/dist/capability.d.ts.map +1 -0
  46. package/bundled-plugins/browser-playwright/dist/capability.js +612 -0
  47. package/bundled-plugins/browser-playwright/dist/capability.js.map +1 -0
  48. package/bundled-plugins/browser-playwright/dist/entry.d.ts +13 -0
  49. package/bundled-plugins/browser-playwright/dist/entry.d.ts.map +1 -0
  50. package/bundled-plugins/browser-playwright/dist/entry.js +14 -0
  51. package/bundled-plugins/browser-playwright/dist/entry.js.map +1 -0
  52. package/bundled-plugins/browser-playwright/dist/index.d.ts +7 -0
  53. package/bundled-plugins/browser-playwright/dist/index.d.ts.map +1 -0
  54. package/bundled-plugins/browser-playwright/dist/index.js +5 -0
  55. package/bundled-plugins/browser-playwright/dist/index.js.map +1 -0
  56. package/bundled-plugins/browser-playwright/dist/operations.d.ts +69 -0
  57. package/bundled-plugins/browser-playwright/dist/operations.d.ts.map +1 -0
  58. package/bundled-plugins/browser-playwright/dist/operations.js +149 -0
  59. package/bundled-plugins/browser-playwright/dist/operations.js.map +1 -0
  60. package/bundled-plugins/browser-playwright/dist/playwright-driver.d.ts +275 -0
  61. package/bundled-plugins/browser-playwright/dist/playwright-driver.d.ts.map +1 -0
  62. package/bundled-plugins/browser-playwright/dist/playwright-driver.js +953 -0
  63. package/bundled-plugins/browser-playwright/dist/playwright-driver.js.map +1 -0
  64. package/bundled-plugins/browser-playwright/dist/setup.d.ts +88 -0
  65. package/bundled-plugins/browser-playwright/dist/setup.d.ts.map +1 -0
  66. package/bundled-plugins/browser-playwright/dist/setup.js +252 -0
  67. package/bundled-plugins/browser-playwright/dist/setup.js.map +1 -0
  68. package/bundled-plugins/browser-playwright/dist/types.d.ts +270 -0
  69. package/bundled-plugins/browser-playwright/dist/types.d.ts.map +1 -0
  70. package/bundled-plugins/browser-playwright/dist/types.js +2 -0
  71. package/bundled-plugins/browser-playwright/dist/types.js.map +1 -0
  72. package/bundled-plugins/browser-playwright/plugin.json +20 -0
  73. package/bundled-plugins/coding-tools/agent-forge.json +1 -1
  74. package/bundled-plugins/coding-tools/dist/bash.d.ts +2 -7
  75. package/bundled-plugins/coding-tools/dist/bash.d.ts.map +1 -1
  76. package/bundled-plugins/coding-tools/dist/bash.js +2 -34
  77. package/bundled-plugins/coding-tools/dist/bash.js.map +1 -1
  78. package/bundled-plugins/coding-tools/plugin.json +1 -1
  79. package/bundled-plugins/compaction-policy/agent-forge.json +1 -1
  80. package/bundled-plugins/compaction-policy/plugin.json +1 -1
  81. package/bundled-plugins/mcp-http/dist/mcp-http.d.ts.map +1 -1
  82. package/bundled-plugins/mcp-http/dist/mcp-http.js +84 -31
  83. package/bundled-plugins/mcp-http/dist/mcp-http.js.map +1 -1
  84. package/bundled-plugins/overflow-policy/agent-forge.json +1 -1
  85. package/bundled-plugins/overflow-policy/plugin.json +1 -1
  86. package/bundled-plugins/provider-failover/agent-forge.json +1 -1
  87. package/bundled-plugins/provider-failover/plugin.json +1 -1
  88. package/bundled-plugins/retry-policy/agent-forge.json +1 -1
  89. package/bundled-plugins/retry-policy/plugin.json +1 -1
  90. package/dist/bundle/.build-manifest.json +60 -58
  91. package/dist/bundle/chunks/{anthropic-messages-3FJHRAJL.js → anthropic-messages-NL4Y6WPB.js} +1 -1
  92. package/dist/bundle/chunks/{azure-openai-responses-GCL47IDS.js → azure-openai-responses-CPXC42HO.js} +1 -1
  93. package/dist/bundle/chunks/bedrock-converse-stream.js +1 -1
  94. package/dist/bundle/chunks/chunk-5LRQFZFE.js +2 -0
  95. package/dist/bundle/chunks/{chunk-HTEVUY7F.js → chunk-7HSJPQKN.js} +1 -1
  96. package/dist/bundle/chunks/{chunk-AC2FIS4G.js → chunk-EDO7Q6XR.js} +1 -1
  97. package/dist/bundle/chunks/{chunk-755VNWIF.js → chunk-ISLHFRER.js} +6 -6
  98. package/dist/bundle/chunks/{chunk-HV64ASMT.js → chunk-K3S6GTL7.js} +1 -1
  99. package/dist/bundle/chunks/{chunk-HEL6TAWE.js → chunk-POLDAUYA.js} +37 -36
  100. package/dist/bundle/chunks/{chunk-V3ACW7VD.js → chunk-WJSKB3FC.js} +1 -1
  101. package/dist/bundle/chunks/{chunk-32YDZI4J.js → chunk-ZS5JEI76.js} +1 -1
  102. package/dist/bundle/chunks/{google-generative-ai-6BMXWA44.js → google-generative-ai-UMZ53EFA.js} +1 -1
  103. package/dist/bundle/chunks/{google-vertex-6H7NLRTK.js → google-vertex-ZNR5NS6H.js} +1 -1
  104. package/dist/bundle/chunks/image-resize-worker.js +1 -1
  105. package/dist/bundle/chunks/{mistral-conversations-IXUHSFSJ.js → mistral-conversations-IT66WUNN.js} +1 -1
  106. package/dist/bundle/chunks/{openai-codex-responses-YHUAEVCM.js → openai-codex-responses-FOVCVG6I.js} +1 -1
  107. package/dist/bundle/chunks/{openai-completions-ULQCFC72.js → openai-completions-FLQ7CBOL.js} +1 -1
  108. package/dist/bundle/chunks/{openai-responses-NLLAJDPS.js → openai-responses-ABGYHS2T.js} +1 -1
  109. package/dist/bundle/chunks/{pi-messages-EJTI2EJ3.js → pi-messages-6K5W6LUN.js} +1 -1
  110. package/dist/bundle/chunks/{virtual-modules-TQWEGNNZ.js → virtual-modules-2QGILFV7.js} +1 -1
  111. package/dist/bundle/cli.js +1 -1
  112. package/dist/bundle/client.js +1 -1
  113. package/dist/bundle/index.js +1 -1
  114. package/dist/bundle/rpc-entry.js +1 -1
  115. package/dist/client/remote-session.d.ts.map +1 -1
  116. package/dist/client/remote-session.js +65 -6
  117. package/dist/client/remote-session.js.map +1 -1
  118. package/dist/core/agent-session-store.d.ts.map +1 -1
  119. package/dist/core/agent-session-store.js +20 -3
  120. package/dist/core/agent-session-store.js.map +1 -1
  121. package/dist/core/extensions/agent-composition.d.ts.map +1 -1
  122. package/dist/core/extensions/agent-composition.js +20 -1
  123. package/dist/core/extensions/agent-composition.js.map +1 -1
  124. package/dist/core/i18n/locales/zh-cn/core-errors.d.ts.map +1 -1
  125. package/dist/core/i18n/locales/zh-cn/core-errors.js +1 -0
  126. package/dist/core/i18n/locales/zh-cn/core-errors.js.map +1 -1
  127. package/dist/core/i18n/locales/zh-cn/interactive-mode.d.ts.map +1 -1
  128. package/dist/core/i18n/locales/zh-cn/interactive-mode.js +10 -3
  129. package/dist/core/i18n/locales/zh-cn/interactive-mode.js.map +1 -1
  130. package/dist/core/keybindings.d.ts +35 -0
  131. package/dist/core/keybindings.d.ts.map +1 -1
  132. package/dist/core/keybindings.js +34 -0
  133. package/dist/core/keybindings.js.map +1 -1
  134. package/dist/core/sdk.d.ts.map +1 -1
  135. package/dist/core/sdk.js +62 -15
  136. package/dist/core/sdk.js.map +1 -1
  137. package/dist/core/session-manager.d.ts.map +1 -1
  138. package/dist/core/session-manager.js +11 -3
  139. package/dist/core/session-manager.js.map +1 -1
  140. package/dist/core/system-prompt.d.ts.map +1 -1
  141. package/dist/core/system-prompt.js +2 -2
  142. package/dist/core/system-prompt.js.map +1 -1
  143. package/dist/core/tools/capability-mount.d.ts.map +1 -1
  144. package/dist/core/tools/capability-mount.js +4 -21
  145. package/dist/core/tools/capability-mount.js.map +1 -1
  146. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  147. package/dist/modes/interactive/components/assistant-message.js +2 -2
  148. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  149. package/dist/modes/interactive/components/bash-execution.d.ts +2 -0
  150. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
  151. package/dist/modes/interactive/components/bash-execution.js +25 -0
  152. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  153. package/dist/modes/interactive/components/changelog-pager.d.ts +53 -0
  154. package/dist/modes/interactive/components/changelog-pager.d.ts.map +1 -0
  155. package/dist/modes/interactive/components/changelog-pager.js +239 -0
  156. package/dist/modes/interactive/components/changelog-pager.js.map +1 -0
  157. package/dist/modes/interactive/components/tool-execution.d.ts +6 -0
  158. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  159. package/dist/modes/interactive/components/tool-execution.js +12 -0
  160. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  161. package/dist/modes/interactive/components/tool-run-group.d.ts +41 -11
  162. package/dist/modes/interactive/components/tool-run-group.d.ts.map +1 -1
  163. package/dist/modes/interactive/components/tool-run-group.js +126 -14
  164. package/dist/modes/interactive/components/tool-run-group.js.map +1 -1
  165. package/dist/modes/interactive/interactive-commands.d.ts.map +1 -1
  166. package/dist/modes/interactive/interactive-commands.js +23 -13
  167. package/dist/modes/interactive/interactive-commands.js.map +1 -1
  168. package/dist/modes/interactive/interactive-events.d.ts +14 -4
  169. package/dist/modes/interactive/interactive-events.d.ts.map +1 -1
  170. package/dist/modes/interactive/interactive-events.js +94 -12
  171. package/dist/modes/interactive/interactive-events.js.map +1 -1
  172. package/dist/modes/interactive/interactive-mode.d.ts +6 -1
  173. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  174. package/dist/modes/interactive/interactive-mode.js +21 -5
  175. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  176. package/dist/plugins/ecosystem/node-local-package-source.d.ts +2 -1
  177. package/dist/plugins/ecosystem/node-local-package-source.d.ts.map +1 -1
  178. package/dist/plugins/ecosystem/node-local-package-source.js +110 -4
  179. package/dist/plugins/ecosystem/node-local-package-source.js.map +1 -1
  180. package/dist/plugins/ecosystem/node-package-install-host.d.ts.map +1 -1
  181. package/dist/plugins/ecosystem/node-package-install-host.js +106 -39
  182. package/dist/plugins/ecosystem/node-package-install-host.js.map +1 -1
  183. package/dist/plugins/ecosystem/node-plugin-bootstrap.d.ts.map +1 -1
  184. package/dist/plugins/ecosystem/node-plugin-bootstrap.js +59 -2
  185. package/dist/plugins/ecosystem/node-plugin-bootstrap.js.map +1 -1
  186. package/dist/suites/builtin-suites.d.ts.map +1 -1
  187. package/dist/suites/builtin-suites.js +2 -2
  188. package/dist/suites/builtin-suites.js.map +1 -1
  189. package/dist/utils/changelog.d.ts +27 -0
  190. package/dist/utils/changelog.d.ts.map +1 -1
  191. package/dist/utils/changelog.js +110 -0
  192. package/dist/utils/changelog.js.map +1 -1
  193. package/docs/keybindings.md +14 -0
  194. package/examples/extensions/with-deps/package-lock.json +2 -2
  195. package/examples/extensions/with-deps/package.json +1 -1
  196. package/examples/extensions/with-deps/plugin.json +1 -1
  197. package/package.json +1 -1
  198. package/dist/bundle/chunks/chunk-A3JYRWB6.js +0 -2
@@ -1 +1 @@
1
- {"version":3,"file":"bash.js","sourceRoot":"","sources":["../src/bash.ts"],"names":[],"mappings":"AAAA,yFAAyF;AACzF,uEAAuE;AAEvE,OAAO,EAIN,yBAAyB,EACzB,0BAA0B,GAC1B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,CAAC,EAAE,MAAM,wBAAwB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,oCAAoC,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,gCAAgC,CAAC;AACpF,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAy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M,cAAc,GAAoB;IACvC,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,MAAM;IACb,SAAS,EAAE,MAAM;IACjB,MAAM,EAAE,GAAG;IACX,aAAa,EAAE,gCAAgC,CAAC,OAAO;IACvD,gBAAgB,EAAE,gCAAgC,CAAC,UAAU;IAC7D,cAAc,EAAE,kBAAkB;CAClC,CAAC;AAEF,MAAM,UAAU,wBAAwB,CACvC,GAAW,EACX,OAAyB,EACyD;IAClF,OAAO,yBAAyB,CAAC,GAAG,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC;AAAA,CAC/D;AAED,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,OAAyB,EAAgC;IACpG,MAAM,UAAU,GAAG,wBAAwB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC1D,MAAM,IAAI,GAAG,kBAAkB,CAAC,UAAU,CAAC,CAAC;IAC5C,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE;QACnB,aAAa,EAAE,UAAU,CAAC,aAAa;QACvC,gBAAgB,EAAE,UAAU,CAAC,gBAAgB;KAC7C,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AAAA,CACZ","sourcesContent":["// Migrated from packages/agent-forge/src/core/tools/bash.ts (batch 1, copy-then-delete);\n// host modules are imported through supply keys (@agent-forge/host/*).\n\nimport {\n\ttype BashOperations,\n\ttype BashSpawnContext,\n\ttype BashSpawnHook,\n\tcreateLocalBashOperations,\n\tcreateLocalShellOperations,\n} from \"@agent-forge/host/bash-operations\";\nimport { t } from \"@agent-forge/host/i18n\";\nimport { keyHint } from \"@agent-forge/host/keybinding-hints\";\nimport { OutputAccumulator } from \"@agent-forge/host/output-accumulator\";\nimport { getTextOutput, invalidArgText, str } from \"@agent-forge/host/render-utils\";\nimport { getShellEnv } from \"@agent-forge/host/shell\";\nimport { theme } from \"@agent-forge/host/theme\";\nimport type { ToolDefinition, ToolExecuteContext, ToolRenderResultOptions } from \"@agent-forge/host/tool-definition\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, type TruncationResult } from \"@agent-forge/host/truncate\";\nimport { truncateToVisualLines } from \"@agent-forge/host/visual-truncate\";\nimport { Container, Text, truncateToWidth } from \"@agent-forge/tui\";\nimport { type Static, Type } from \"typebox\";\nimport { type AgentTool, wrapToolDefinition } from \"./types.ts\";\n\n// Operations layer shared with plugins via the \"@agent-forge/host/bash-operations\"\n// virtual module; re-exported so the existing host import surface keeps resolving.\nexport {\n\ttype BashOperations,\n\ttype BashSpawnContext,\n\ttype BashSpawnHook,\n\tcreateLocalBashOperations,\n\tcreateLocalShellOperations,\n};\n\nconst bashSchema = Type.Object({\n\tcommand: Type.String({ description: \"Shell command to execute\" }),\n\ttimeout: Type.Optional(Type.Number({ description: \"Timeout in seconds (optional, no default timeout)\" })),\n});\n\nexport const bashToolSystemPromptContribution = {\n\tsnippet: \"Execute bash commands (ls, grep, find, etc.)\",\n\tguidelines: [\"You can inspect AGENT_FORGE_* environment variables for current model and session details.\"],\n} as const;\n\nexport type BashToolInput = Static<typeof bashSchema>;\n\nexport interface BashToolDetails {\n\ttruncation?: TruncationResult;\n\tfullOutputPath?: string;\n}\n\nfunction resolveSpawnContext(\n\tcommand: string,\n\tcwd: string,\n\tspawnHook: BashSpawnHook | undefined,\n\texposeSessionEnvironment: boolean,\n\tctx: ToolExecuteContext | undefined,\n): BashSpawnContext {\n\tconst env = { ...getShellEnv() };\n\tdelete env.AGENT_FORGE_SESSION_ID;\n\tdelete env.AGENT_FORGE_SESSION_FILE;\n\tdelete env.AGENT_FORGE_PROVIDER;\n\tdelete env.AGENT_FORGE_MODEL;\n\tdelete env.AGENT_FORGE_REASONING_LEVEL;\n\tif (exposeSessionEnvironment && ctx) {\n\t\tconst model = ctx.model;\n\t\tenv.AGENT_FORGE_SESSION_ID = ctx.sessionManager.getSessionId();\n\t\tconst sessionFile = ctx.sessionManager.getSessionFile();\n\t\tif (sessionFile) env.AGENT_FORGE_SESSION_FILE = sessionFile;\n\t\tif (model) {\n\t\t\tenv.AGENT_FORGE_PROVIDER = model.provider;\n\t\t\tenv.AGENT_FORGE_MODEL = model.id;\n\t\t}\n\t\tif (ctx.thinkingLevel) env.AGENT_FORGE_REASONING_LEVEL = ctx.thinkingLevel;\n\t}\n\tconst baseContext: BashSpawnContext = { command, cwd, env };\n\treturn spawnHook ? spawnHook(baseContext) : baseContext;\n}\n\nexport interface BashToolOptions {\n\t/** Custom operations for command execution. Default: local shell */\n\toperations?: BashOperations;\n\t/** Command prefix prepended to every command (for example shell setup commands) */\n\tcommandPrefix?: string;\n\t/** Optional explicit shell path from settings */\n\tshellPath?: string;\n\t/** Expose current Agent Forge session metadata as AGENT_FORGE_* environment variables. Default: true */\n\texposeSessionEnvironment?: boolean;\n\t/** Hook to adjust command, cwd, or env before execution */\n\tspawnHook?: BashSpawnHook;\n}\n\nconst BASH_PREVIEW_LINES = 5;\nconst BASH_UPDATE_THROTTLE_MS = 100;\n\nexport type BashRenderState = {\n\tstartedAt: number | undefined;\n\tendedAt: number | undefined;\n\tinterval: NodeJS.Timeout | undefined;\n};\n\ntype BashResultRenderState = {\n\tcachedWidth: number | undefined;\n\tcachedLines: string[] | undefined;\n};\n\nclass BashResultRenderComponent extends Container {\n\tstate: BashResultRenderState = {\n\t\tcachedWidth: undefined,\n\t\tcachedLines: undefined,\n\t};\n}\n\nfunction formatDuration(ms: number): string {\n\tconst seconds = ms / 1000;\n\tif (seconds < 60) return `${seconds.toFixed(1)}s`;\n\n\tconst totalSeconds = Math.floor(seconds);\n\tconst minutes = Math.floor(totalSeconds / 60);\n\tconst remainder = totalSeconds % 60;\n\tif (minutes < 60) return `${minutes}m ${remainder}s`;\n\n\treturn `${Math.floor(minutes / 60)}h ${minutes % 60}m ${remainder}s`;\n}\n\nfunction formatShellCall(args: { command?: string; timeout?: number } | undefined, prompt: string): string {\n\tconst command = str(args?.command);\n\tconst timeout = args?.timeout as number | undefined;\n\tconst timeoutSuffix = timeout ? theme.fg(\"muted\", ` (timeout ${timeout}s)`) : \"\";\n\tconst commandDisplay = command === null ? invalidArgText(theme) : command ? command : theme.fg(\"toolOutput\", \"...\");\n\treturn theme.fg(\"toolTitle\", theme.bold(`${prompt} ${commandDisplay}`)) + timeoutSuffix;\n}\n\nfunction rebuildBashResultRenderComponent(\n\tcomponent: BashResultRenderComponent,\n\tresult: {\n\t\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\t\tdetails?: BashToolDetails;\n\t},\n\toptions: ToolRenderResultOptions,\n\tshowImages: boolean,\n\tstartedAt: number | undefined,\n\tendedAt: number | undefined,\n): void {\n\tconst state = component.state;\n\tcomponent.clear();\n\n\tlet output = getTextOutput(result, showImages).trim();\n\tconst truncation = result.details?.truncation;\n\tconst fullOutputPath = result.details?.fullOutputPath;\n\tif (!options.isPartial && truncation?.truncated && fullOutputPath && output.endsWith(\"]\")) {\n\t\tconst footerStart = output.lastIndexOf(\"\\n\\n[\");\n\t\tif (footerStart !== -1 && output.slice(footerStart).includes(fullOutputPath)) {\n\t\t\toutput = output.slice(0, footerStart).trimEnd();\n\t\t}\n\t}\n\n\tif (output) {\n\t\tconst styledOutput = output\n\t\t\t.split(\"\\n\")\n\t\t\t.map((line) => theme.fg(\"toolOutput\", line))\n\t\t\t.join(\"\\n\");\n\n\t\tif (options.expanded) {\n\t\t\tcomponent.addChild(new Text(`\\n${styledOutput}`, 0, 0));\n\t\t} else {\n\t\t\tcomponent.addChild({\n\t\t\t\trender: (width: number) => {\n\t\t\t\t\t// Cache the complete output: this renders on every frame for every bash result in the transcript.\n\t\t\t\t\tif (state.cachedLines === undefined || state.cachedWidth !== width) {\n\t\t\t\t\t\tconst preview = truncateToVisualLines(styledOutput, BASH_PREVIEW_LINES, width);\n\t\t\t\t\t\tconst hintLines: string[] = [];\n\t\t\t\t\t\tif (preview.skippedCount > 0) {\n\t\t\t\t\t\t\tconst hint =\n\t\t\t\t\t\t\t\ttheme.fg(\"muted\", `... (${preview.skippedCount} earlier lines,`) +\n\t\t\t\t\t\t\t\t` ${keyHint(\"app.tools.expand\", \"to expand\")}${theme.fg(\"muted\", \")\")}`;\n\t\t\t\t\t\t\thintLines.push(truncateToWidth(hint, width, \"...\"));\n\t\t\t\t\t\t}\n\t\t\t\t\t\tstate.cachedLines = [\"\", ...hintLines, ...preview.visualLines];\n\t\t\t\t\t\tstate.cachedWidth = width;\n\t\t\t\t\t}\n\t\t\t\t\treturn state.cachedLines;\n\t\t\t\t},\n\t\t\t\tinvalidate: () => {\n\t\t\t\t\tstate.cachedWidth = undefined;\n\t\t\t\t\tstate.cachedLines = undefined;\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t}\n\n\tif (truncation?.truncated || fullOutputPath) {\n\t\tconst warnings: string[] = [];\n\t\tif (fullOutputPath) {\n\t\t\twarnings.push(`Full output: ${fullOutputPath}`);\n\t\t}\n\t\tif (truncation?.truncated) {\n\t\t\tif (truncation.truncatedBy === \"lines\") {\n\t\t\t\twarnings.push(`Truncated: showing ${truncation.outputLines} of ${truncation.totalLines} lines`);\n\t\t\t} else {\n\t\t\t\twarnings.push(\n\t\t\t\t\t`Truncated: ${truncation.outputLines} lines shown (${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit)`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tcomponent.addChild(new Text(`\\n${theme.fg(\"warning\", `[${warnings.join(\". \")}]`)}`, 0, 0));\n\t}\n\n\tif (startedAt !== undefined) {\n\t\tconst label = options.isPartial ? \"Elapsed\" : \"Took\";\n\t\tconst endTime = endedAt ?? Date.now();\n\t\tcomponent.addChild(new Text(`\\n${theme.fg(\"muted\", `${label} ${formatDuration(endTime - startedAt)}`)}`, 0, 0));\n\t}\n}\n\nexport interface ShellToolConfig {\n\tname: string;\n\tlabel: string;\n\tshellName: string;\n\tprompt: string;\n\tpromptSnippet: string;\n\tpromptGuidelines?: readonly string[];\n\ttempFilePrefix: string;\n}\n\nexport function createShellToolDefinition(\n\tcwd: string,\n\tconfig: ShellToolConfig,\n\toptions?: BashToolOptions,\n): ToolDefinition<typeof bashSchema, BashToolDetails | undefined, BashRenderState> {\n\tconst ops = options?.operations ?? createLocalBashOperations({ shellPath: options?.shellPath });\n\tconst commandPrefix = options?.commandPrefix;\n\tconst exposeSessionEnvironment = options?.exposeSessionEnvironment ?? true;\n\tconst spawnHook = options?.spawnHook;\n\treturn {\n\t\tname: config.name,\n\t\tlabel: config.label,\n\t\tdescription: `Execute a ${config.shellName} command in the current working directory. Returns stdout and stderr. Output is truncated to last ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). If truncated, full output is saved to a temp file. Optionally provide a timeout in seconds.`,\n\t\tpromptSnippet: config.promptSnippet,\n\t\tpromptGuidelines: exposeSessionEnvironment && config.promptGuidelines ? [...config.promptGuidelines] : undefined,\n\t\tparameters: bashSchema,\n\t\tconstrainedSampling: { type: \"json_schema\", strict: \"prefer\" },\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{ command, timeout }: { command: string; timeout?: number },\n\t\t\tsignal?: AbortSignal,\n\t\t\tonUpdate?,\n\t\t\tctx?: ToolExecuteContext,\n\t\t) {\n\t\t\tconst resolvedCommand = commandPrefix ? `${commandPrefix}\\n${command}` : command;\n\t\t\tconst spawnContext = resolveSpawnContext(\n\t\t\t\tresolvedCommand,\n\t\t\t\tctx?.cwd || cwd,\n\t\t\t\tspawnHook,\n\t\t\t\texposeSessionEnvironment,\n\t\t\t\tctx,\n\t\t\t);\n\t\t\tconst output = new OutputAccumulator({ tempFilePrefix: config.tempFilePrefix });\n\t\t\tlet acceptingOutput = true;\n\t\t\tlet updateTimer: NodeJS.Timeout | undefined;\n\t\t\tlet updateDirty = false;\n\t\t\tlet lastUpdateAt = 0;\n\n\t\t\tconst emitOutputUpdate = () => {\n\t\t\t\tif (!onUpdate || !updateDirty) return;\n\t\t\t\tupdateDirty = false;\n\t\t\t\tlastUpdateAt = Date.now();\n\t\t\t\tconst snapshot = output.snapshot({ persistIfTruncated: true });\n\t\t\t\tonUpdate({\n\t\t\t\t\tcontent: [{ type: \"text\", text: snapshot.content || \"\" }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\ttruncation: snapshot.truncation.truncated ? snapshot.truncation : undefined,\n\t\t\t\t\t\tfullOutputPath: snapshot.fullOutputPath,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t};\n\n\t\t\tconst clearUpdateTimer = () => {\n\t\t\t\tif (updateTimer) {\n\t\t\t\t\tclearTimeout(updateTimer);\n\t\t\t\t\tupdateTimer = undefined;\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconst scheduleOutputUpdate = () => {\n\t\t\t\tif (!onUpdate) return;\n\t\t\t\tupdateDirty = true;\n\t\t\t\tconst delay = BASH_UPDATE_THROTTLE_MS - (Date.now() - lastUpdateAt);\n\t\t\t\tif (delay <= 0) {\n\t\t\t\t\tclearUpdateTimer();\n\t\t\t\t\temitOutputUpdate();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tupdateTimer ??= setTimeout(() => {\n\t\t\t\t\tupdateTimer = undefined;\n\t\t\t\t\temitOutputUpdate();\n\t\t\t\t}, delay);\n\t\t\t};\n\n\t\t\tif (onUpdate) {\n\t\t\t\tonUpdate({ content: [], details: undefined });\n\t\t\t}\n\n\t\t\tconst handleData = (data: Buffer) => {\n\t\t\t\tif (!acceptingOutput) return;\n\t\t\t\toutput.append(data);\n\t\t\t\tscheduleOutputUpdate();\n\t\t\t};\n\n\t\t\tconst finishOutput = async () => {\n\t\t\t\tacceptingOutput = false;\n\t\t\t\toutput.finish();\n\t\t\t\tclearUpdateTimer();\n\t\t\t\temitOutputUpdate();\n\t\t\t\tconst snapshot = output.snapshot({ persistIfTruncated: true });\n\t\t\t\tawait output.closeTempFile();\n\t\t\t\treturn snapshot;\n\t\t\t};\n\n\t\t\tconst formatOutput = (snapshot: Awaited<ReturnType<typeof finishOutput>>, emptyText = \"(no output)\") => {\n\t\t\t\tconst truncation = snapshot.truncation;\n\t\t\t\tlet text = snapshot.content || emptyText;\n\t\t\t\tlet details: BashToolDetails | undefined;\n\t\t\t\tif (truncation.truncated) {\n\t\t\t\t\tdetails = { truncation, fullOutputPath: snapshot.fullOutputPath };\n\t\t\t\t\tconst startLine = truncation.totalLines - truncation.outputLines + 1;\n\t\t\t\t\tconst endLine = truncation.totalLines;\n\t\t\t\t\tif (truncation.lastLinePartial) {\n\t\t\t\t\t\tconst lastLineSize = formatSize(output.getLastLineBytes());\n\t\t\t\t\t\ttext += `\\n\\n[Showing last ${formatSize(truncation.outputBytes)} of line ${endLine} (line is ${lastLineSize}). Full output: ${snapshot.fullOutputPath}]`;\n\t\t\t\t\t} else if (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\ttext += `\\n\\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines}. Full output: ${snapshot.fullOutputPath}]`;\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttext += `\\n\\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines} (${formatSize(DEFAULT_MAX_BYTES)} limit). Full output: ${snapshot.fullOutputPath}]`;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn { text, details };\n\t\t\t};\n\n\t\t\tconst appendStatus = (text: string, status: string) => `${text ? `${text}\\n\\n` : \"\"}${status}`;\n\n\t\t\ttry {\n\t\t\t\tlet exitCode: number | null;\n\t\t\t\ttry {\n\t\t\t\t\tconst result = await ops.exec(spawnContext.command, spawnContext.cwd, {\n\t\t\t\t\t\tonData: handleData,\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t\ttimeout,\n\t\t\t\t\t\tenv: spawnContext.env,\n\t\t\t\t\t});\n\t\t\t\t\texitCode = result.exitCode;\n\t\t\t\t} catch (err) {\n\t\t\t\t\tconst snapshot = await finishOutput();\n\t\t\t\t\tconst { text } = formatOutput(snapshot, \"\");\n\t\t\t\t\tif (err instanceof Error && err.message === \"aborted\") {\n\t\t\t\t\t\tthrow new Error(appendStatus(text, t(\"Command aborted\")));\n\t\t\t\t\t}\n\t\t\t\t\tif (err instanceof Error && err.message.startsWith(\"timeout:\")) {\n\t\t\t\t\t\tconst timeoutSecs = err.message.split(\":\")[1];\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\tappendStatus(text, t(\"Command timed out after {seconds} seconds\", { seconds: timeoutSecs })),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\n\t\t\t\tconst snapshot = await finishOutput();\n\t\t\t\tconst { text: outputText, details } = formatOutput(snapshot);\n\t\t\t\tif (exitCode === null) {\n\t\t\t\t\tthrow new Error(appendStatus(outputText, t(\"Command terminated without an exit code\")));\n\t\t\t\t}\n\t\t\t\tif (exitCode !== 0) {\n\t\t\t\t\tthrow new Error(appendStatus(outputText, t(\"Command exited with code {exitCode}\", { exitCode })));\n\t\t\t\t}\n\t\t\t\treturn { content: [{ type: \"text\", text: outputText }], details };\n\t\t\t} finally {\n\t\t\t\tclearUpdateTimer();\n\t\t\t}\n\t\t},\n\t\trenderCall(args, _theme, context) {\n\t\t\tconst state = context.state;\n\t\t\tif (context.executionStarted && state.startedAt === undefined) {\n\t\t\t\tstate.startedAt = Date.now();\n\t\t\t\tstate.endedAt = undefined;\n\t\t\t}\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(formatShellCall(args, config.prompt));\n\t\t\treturn text;\n\t\t},\n\t\trenderResult(result, options, _theme, context) {\n\t\t\tconst state = context.state;\n\t\t\tif (state.startedAt !== undefined && options.isPartial && !state.interval) {\n\t\t\t\tstate.interval = setInterval(() => context.invalidate(), 1000);\n\t\t\t}\n\t\t\tif (!options.isPartial || context.isError) {\n\t\t\t\tstate.endedAt ??= Date.now();\n\t\t\t\tif (state.interval) {\n\t\t\t\t\tclearInterval(state.interval);\n\t\t\t\t\tstate.interval = undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst component =\n\t\t\t\t(context.lastComponent as BashResultRenderComponent | undefined) ?? new BashResultRenderComponent();\n\t\t\trebuildBashResultRenderComponent(\n\t\t\t\tcomponent,\n\t\t\t\tresult,\n\t\t\t\toptions,\n\t\t\t\tcontext.showImages,\n\t\t\t\tstate.startedAt,\n\t\t\t\tstate.endedAt,\n\t\t\t);\n\t\t\tcomponent.invalidate();\n\t\t\treturn component;\n\t\t},\n\t};\n}\n\nconst bashToolConfig: ShellToolConfig = {\n\tname: \"bash\",\n\tlabel: \"bash\",\n\tshellName: \"bash\",\n\tprompt: \"$\",\n\tpromptSnippet: bashToolSystemPromptContribution.snippet,\n\tpromptGuidelines: bashToolSystemPromptContribution.guidelines,\n\ttempFilePrefix: \"agent-forge-bash\",\n};\n\nexport function createBashToolDefinition(\n\tcwd: string,\n\toptions?: BashToolOptions,\n): ToolDefinition<typeof bashSchema, BashToolDetails | undefined, BashRenderState> {\n\treturn createShellToolDefinition(cwd, bashToolConfig, options);\n}\n\nexport function createBashTool(cwd: string, options?: BashToolOptions): AgentTool<typeof bashSchema> {\n\tconst definition = createBashToolDefinition(cwd, options);\n\tconst tool = wrapToolDefinition(definition);\n\tObject.assign(tool, {\n\t\tpromptSnippet: definition.promptSnippet,\n\t\tpromptGuidelines: definition.promptGuidelines,\n\t});\n\treturn tool;\n}\n"]}
1
+ {"version":3,"file":"bash.js","sourceRoot":"","sources":["../src/bash.ts"],"names":[],"mappings":"AAAA,yFAAyF;AACzF,uEAAuE;AAEvE,OAAO,EAIN,yBAAyB,EACzB,0BAA0B,GAC1B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,CAAC,EAAE,MAAM,wBAAwB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,oCAAoC,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,gCAAgC,CAAC;AACpF,OA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AAgB,EAAE,UAAU,CAAC,gBAAgB;KAC7C,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AAAA,CACZ","sourcesContent":["// Migrated from packages/agent-forge/src/core/tools/bash.ts (batch 1, copy-then-delete);\n// host modules are imported through supply keys (@agent-forge/host/*).\n\nimport {\n\ttype BashOperations,\n\ttype BashSpawnContext,\n\ttype BashSpawnHook,\n\tcreateLocalBashOperations,\n\tcreateLocalShellOperations,\n} from \"@agent-forge/host/bash-operations\";\nimport { t } from \"@agent-forge/host/i18n\";\nimport { keyHint } from \"@agent-forge/host/keybinding-hints\";\nimport { OutputAccumulator } from \"@agent-forge/host/output-accumulator\";\nimport { getTextOutput, invalidArgText, str } from \"@agent-forge/host/render-utils\";\nimport { getShellEnv } from \"@agent-forge/host/shell\";\nimport { theme } from \"@agent-forge/host/theme\";\nimport type { ToolDefinition, ToolExecuteContext, ToolRenderResultOptions } from \"@agent-forge/host/tool-definition\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, type TruncationResult } from \"@agent-forge/host/truncate\";\nimport { truncateToVisualLines } from \"@agent-forge/host/visual-truncate\";\nimport { Container, Text, truncateToWidth } from \"@agent-forge/tui\";\nimport { type Static, Type } from \"typebox\";\nimport { type AgentTool, wrapToolDefinition } from \"./types.ts\";\n\n// Operations layer shared with plugins via the \"@agent-forge/host/bash-operations\"\n// virtual module; re-exported so the existing host import surface keeps resolving.\nexport {\n\ttype BashOperations,\n\ttype BashSpawnContext,\n\ttype BashSpawnHook,\n\tcreateLocalBashOperations,\n\tcreateLocalShellOperations,\n};\n\nconst bashSchema = Type.Object({\n\tcommand: Type.String({ description: \"Shell command to execute\" }),\n\ttimeout: Type.Optional(Type.Number({ description: \"Timeout in seconds (optional, no default timeout)\" })),\n});\n\nexport const bashToolSystemPromptContribution = {\n\tsnippet: \"Execute bash commands (ls, grep, find, etc.)\",\n\tguidelines: [\"You can inspect AGENT_FORGE_* environment variables for current model and session details.\"],\n} as const;\n\nexport type BashToolInput = Static<typeof bashSchema>;\n\nexport interface BashToolDetails {\n\ttruncation?: TruncationResult;\n\tfullOutputPath?: string;\n}\n\nfunction resolveSpawnContext(\n\tcommand: string,\n\tcwd: string,\n\tspawnHook: BashSpawnHook | undefined,\n\texposeSessionEnvironment: boolean,\n\tctx: ToolExecuteContext | undefined,\n): BashSpawnContext {\n\tconst env = { ...getShellEnv() };\n\tdelete env.AGENT_FORGE_SESSION_ID;\n\tdelete env.AGENT_FORGE_SESSION_FILE;\n\tdelete env.AGENT_FORGE_PROVIDER;\n\tdelete env.AGENT_FORGE_MODEL;\n\tdelete env.AGENT_FORGE_REASONING_LEVEL;\n\tif (exposeSessionEnvironment && ctx) {\n\t\tconst model = ctx.model;\n\t\tenv.AGENT_FORGE_SESSION_ID = ctx.sessionManager.getSessionId();\n\t\tconst sessionFile = ctx.sessionManager.getSessionFile();\n\t\tif (sessionFile) env.AGENT_FORGE_SESSION_FILE = sessionFile;\n\t\tif (model) {\n\t\t\tenv.AGENT_FORGE_PROVIDER = model.provider;\n\t\t\tenv.AGENT_FORGE_MODEL = model.id;\n\t\t}\n\t\tif (ctx.thinkingLevel) env.AGENT_FORGE_REASONING_LEVEL = ctx.thinkingLevel;\n\t}\n\tconst baseContext: BashSpawnContext = { command, cwd, env };\n\treturn spawnHook ? spawnHook(baseContext) : baseContext;\n}\n\nexport interface BashToolOptions {\n\t/** Custom operations for command execution. Default: local shell */\n\toperations?: BashOperations;\n\t/** Command prefix prepended to every command (for example shell setup commands) */\n\tcommandPrefix?: string;\n\t/** Optional explicit shell path from settings */\n\tshellPath?: string;\n\t/** Expose current Agent Forge session metadata as AGENT_FORGE_* environment variables. Default: true */\n\texposeSessionEnvironment?: boolean;\n\t/** Hook to adjust command, cwd, or env before execution */\n\tspawnHook?: BashSpawnHook;\n}\n\nconst BASH_PREVIEW_LINES = 5;\nconst BASH_UPDATE_THROTTLE_MS = 100;\n\ntype BashResultRenderState = {\n\tcachedWidth: number | undefined;\n\tcachedLines: string[] | undefined;\n};\n\nclass BashResultRenderComponent extends Container {\n\tstate: BashResultRenderState = {\n\t\tcachedWidth: undefined,\n\t\tcachedLines: undefined,\n\t};\n}\n\nfunction formatShellCall(args: { command?: string; timeout?: number } | undefined, prompt: string): string {\n\tconst command = str(args?.command);\n\tconst timeout = args?.timeout as number | undefined;\n\tconst timeoutSuffix = timeout ? theme.fg(\"muted\", ` (timeout ${timeout}s)`) : \"\";\n\tconst commandDisplay = command === null ? invalidArgText(theme) : command ? command : theme.fg(\"toolOutput\", \"...\");\n\treturn theme.fg(\"toolTitle\", theme.bold(`${prompt} ${commandDisplay}`)) + timeoutSuffix;\n}\n\nfunction rebuildBashResultRenderComponent(\n\tcomponent: BashResultRenderComponent,\n\tresult: {\n\t\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\t\tdetails?: BashToolDetails;\n\t},\n\toptions: ToolRenderResultOptions,\n\tshowImages: boolean,\n): void {\n\tconst state = component.state;\n\tcomponent.clear();\n\n\tlet output = getTextOutput(result, showImages).trim();\n\tconst truncation = result.details?.truncation;\n\tconst fullOutputPath = result.details?.fullOutputPath;\n\tif (!options.isPartial && truncation?.truncated && fullOutputPath && output.endsWith(\"]\")) {\n\t\tconst footerStart = output.lastIndexOf(\"\\n\\n[\");\n\t\tif (footerStart !== -1 && output.slice(footerStart).includes(fullOutputPath)) {\n\t\t\toutput = output.slice(0, footerStart).trimEnd();\n\t\t}\n\t}\n\n\tif (output) {\n\t\tconst styledOutput = output\n\t\t\t.split(\"\\n\")\n\t\t\t.map((line) => theme.fg(\"toolOutput\", line))\n\t\t\t.join(\"\\n\");\n\n\t\tif (options.expanded) {\n\t\t\tcomponent.addChild(new Text(`\\n${styledOutput}`, 0, 0));\n\t\t} else {\n\t\t\tcomponent.addChild({\n\t\t\t\trender: (width: number) => {\n\t\t\t\t\t// Cache the complete output: this renders on every frame for every bash result in the transcript.\n\t\t\t\t\tif (state.cachedLines === undefined || state.cachedWidth !== width) {\n\t\t\t\t\t\tconst preview = truncateToVisualLines(styledOutput, BASH_PREVIEW_LINES, width);\n\t\t\t\t\t\tconst hintLines: string[] = [];\n\t\t\t\t\t\tif (preview.skippedCount > 0) {\n\t\t\t\t\t\t\tconst hint =\n\t\t\t\t\t\t\t\ttheme.fg(\"muted\", `... (${preview.skippedCount} earlier lines,`) +\n\t\t\t\t\t\t\t\t` ${keyHint(\"app.tools.expand\", \"to expand\")}${theme.fg(\"muted\", \")\")}`;\n\t\t\t\t\t\t\thintLines.push(truncateToWidth(hint, width, \"...\"));\n\t\t\t\t\t\t}\n\t\t\t\t\t\tstate.cachedLines = [\"\", ...hintLines, ...preview.visualLines];\n\t\t\t\t\t\tstate.cachedWidth = width;\n\t\t\t\t\t}\n\t\t\t\t\treturn state.cachedLines;\n\t\t\t\t},\n\t\t\t\tinvalidate: () => {\n\t\t\t\t\tstate.cachedWidth = undefined;\n\t\t\t\t\tstate.cachedLines = undefined;\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t}\n\n\tif (truncation?.truncated || fullOutputPath) {\n\t\tconst warnings: string[] = [];\n\t\tif (fullOutputPath) {\n\t\t\twarnings.push(`Full output: ${fullOutputPath}`);\n\t\t}\n\t\tif (truncation?.truncated) {\n\t\t\tif (truncation.truncatedBy === \"lines\") {\n\t\t\t\twarnings.push(`Truncated: showing ${truncation.outputLines} of ${truncation.totalLines} lines`);\n\t\t\t} else {\n\t\t\t\twarnings.push(\n\t\t\t\t\t`Truncated: ${truncation.outputLines} lines shown (${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit)`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tcomponent.addChild(new Text(`\\n${theme.fg(\"warning\", `[${warnings.join(\". \")}]`)}`, 0, 0));\n\t}\n}\n\nexport interface ShellToolConfig {\n\tname: string;\n\tlabel: string;\n\tshellName: string;\n\tprompt: string;\n\tpromptSnippet: string;\n\tpromptGuidelines?: readonly string[];\n\ttempFilePrefix: string;\n}\n\nexport function createShellToolDefinition(\n\tcwd: string,\n\tconfig: ShellToolConfig,\n\toptions?: BashToolOptions,\n): ToolDefinition<typeof bashSchema, BashToolDetails | undefined> {\n\tconst ops = options?.operations ?? createLocalBashOperations({ shellPath: options?.shellPath });\n\tconst commandPrefix = options?.commandPrefix;\n\tconst exposeSessionEnvironment = options?.exposeSessionEnvironment ?? true;\n\tconst spawnHook = options?.spawnHook;\n\treturn {\n\t\tname: config.name,\n\t\tlabel: config.label,\n\t\tdescription: `Execute a ${config.shellName} command in the current working directory. Returns stdout and stderr. Output is truncated to last ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). If truncated, full output is saved to a temp file. Optionally provide a timeout in seconds.`,\n\t\tpromptSnippet: config.promptSnippet,\n\t\tpromptGuidelines: exposeSessionEnvironment && config.promptGuidelines ? [...config.promptGuidelines] : undefined,\n\t\tparameters: bashSchema,\n\t\tconstrainedSampling: { type: \"json_schema\", strict: \"prefer\" },\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{ command, timeout }: { command: string; timeout?: number },\n\t\t\tsignal?: AbortSignal,\n\t\t\tonUpdate?,\n\t\t\tctx?: ToolExecuteContext,\n\t\t) {\n\t\t\tconst resolvedCommand = commandPrefix ? `${commandPrefix}\\n${command}` : command;\n\t\t\tconst spawnContext = resolveSpawnContext(\n\t\t\t\tresolvedCommand,\n\t\t\t\tctx?.cwd || cwd,\n\t\t\t\tspawnHook,\n\t\t\t\texposeSessionEnvironment,\n\t\t\t\tctx,\n\t\t\t);\n\t\t\tconst output = new OutputAccumulator({ tempFilePrefix: config.tempFilePrefix });\n\t\t\tlet acceptingOutput = true;\n\t\t\tlet updateTimer: NodeJS.Timeout | undefined;\n\t\t\tlet updateDirty = false;\n\t\t\tlet lastUpdateAt = 0;\n\n\t\t\tconst emitOutputUpdate = () => {\n\t\t\t\tif (!onUpdate || !updateDirty) return;\n\t\t\t\tupdateDirty = false;\n\t\t\t\tlastUpdateAt = Date.now();\n\t\t\t\tconst snapshot = output.snapshot({ persistIfTruncated: true });\n\t\t\t\tonUpdate({\n\t\t\t\t\tcontent: [{ type: \"text\", text: snapshot.content || \"\" }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\ttruncation: snapshot.truncation.truncated ? snapshot.truncation : undefined,\n\t\t\t\t\t\tfullOutputPath: snapshot.fullOutputPath,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t};\n\n\t\t\tconst clearUpdateTimer = () => {\n\t\t\t\tif (updateTimer) {\n\t\t\t\t\tclearTimeout(updateTimer);\n\t\t\t\t\tupdateTimer = undefined;\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconst scheduleOutputUpdate = () => {\n\t\t\t\tif (!onUpdate) return;\n\t\t\t\tupdateDirty = true;\n\t\t\t\tconst delay = BASH_UPDATE_THROTTLE_MS - (Date.now() - lastUpdateAt);\n\t\t\t\tif (delay <= 0) {\n\t\t\t\t\tclearUpdateTimer();\n\t\t\t\t\temitOutputUpdate();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tupdateTimer ??= setTimeout(() => {\n\t\t\t\t\tupdateTimer = undefined;\n\t\t\t\t\temitOutputUpdate();\n\t\t\t\t}, delay);\n\t\t\t};\n\n\t\t\tif (onUpdate) {\n\t\t\t\tonUpdate({ content: [], details: undefined });\n\t\t\t}\n\n\t\t\tconst handleData = (data: Buffer) => {\n\t\t\t\tif (!acceptingOutput) return;\n\t\t\t\toutput.append(data);\n\t\t\t\tscheduleOutputUpdate();\n\t\t\t};\n\n\t\t\tconst finishOutput = async () => {\n\t\t\t\tacceptingOutput = false;\n\t\t\t\toutput.finish();\n\t\t\t\tclearUpdateTimer();\n\t\t\t\temitOutputUpdate();\n\t\t\t\tconst snapshot = output.snapshot({ persistIfTruncated: true });\n\t\t\t\tawait output.closeTempFile();\n\t\t\t\treturn snapshot;\n\t\t\t};\n\n\t\t\tconst formatOutput = (snapshot: Awaited<ReturnType<typeof finishOutput>>, emptyText = \"(no output)\") => {\n\t\t\t\tconst truncation = snapshot.truncation;\n\t\t\t\tlet text = snapshot.content || emptyText;\n\t\t\t\tlet details: BashToolDetails | undefined;\n\t\t\t\tif (truncation.truncated) {\n\t\t\t\t\tdetails = { truncation, fullOutputPath: snapshot.fullOutputPath };\n\t\t\t\t\tconst startLine = truncation.totalLines - truncation.outputLines + 1;\n\t\t\t\t\tconst endLine = truncation.totalLines;\n\t\t\t\t\tif (truncation.lastLinePartial) {\n\t\t\t\t\t\tconst lastLineSize = formatSize(output.getLastLineBytes());\n\t\t\t\t\t\ttext += `\\n\\n[Showing last ${formatSize(truncation.outputBytes)} of line ${endLine} (line is ${lastLineSize}). Full output: ${snapshot.fullOutputPath}]`;\n\t\t\t\t\t} else if (truncation.truncatedBy === \"lines\") {\n\t\t\t\t\t\ttext += `\\n\\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines}. Full output: ${snapshot.fullOutputPath}]`;\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttext += `\\n\\n[Showing lines ${startLine}-${endLine} of ${truncation.totalLines} (${formatSize(DEFAULT_MAX_BYTES)} limit). Full output: ${snapshot.fullOutputPath}]`;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn { text, details };\n\t\t\t};\n\n\t\t\tconst appendStatus = (text: string, status: string) => `${text ? `${text}\\n\\n` : \"\"}${status}`;\n\n\t\t\ttry {\n\t\t\t\tlet exitCode: number | null;\n\t\t\t\ttry {\n\t\t\t\t\tconst result = await ops.exec(spawnContext.command, spawnContext.cwd, {\n\t\t\t\t\t\tonData: handleData,\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t\ttimeout,\n\t\t\t\t\t\tenv: spawnContext.env,\n\t\t\t\t\t});\n\t\t\t\t\texitCode = result.exitCode;\n\t\t\t\t} catch (err) {\n\t\t\t\t\tconst snapshot = await finishOutput();\n\t\t\t\t\tconst { text } = formatOutput(snapshot, \"\");\n\t\t\t\t\tif (err instanceof Error && err.message === \"aborted\") {\n\t\t\t\t\t\tthrow new Error(appendStatus(text, t(\"Command aborted\")));\n\t\t\t\t\t}\n\t\t\t\t\tif (err instanceof Error && err.message.startsWith(\"timeout:\")) {\n\t\t\t\t\t\tconst timeoutSecs = err.message.split(\":\")[1];\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\tappendStatus(text, t(\"Command timed out after {seconds} seconds\", { seconds: timeoutSecs })),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tthrow err;\n\t\t\t\t}\n\n\t\t\t\tconst snapshot = await finishOutput();\n\t\t\t\tconst { text: outputText, details } = formatOutput(snapshot);\n\t\t\t\tif (exitCode === null) {\n\t\t\t\t\tthrow new Error(appendStatus(outputText, t(\"Command terminated without an exit code\")));\n\t\t\t\t}\n\t\t\t\tif (exitCode !== 0) {\n\t\t\t\t\tthrow new Error(appendStatus(outputText, t(\"Command exited with code {exitCode}\", { exitCode })));\n\t\t\t\t}\n\t\t\t\treturn { content: [{ type: \"text\", text: outputText }], details };\n\t\t\t} finally {\n\t\t\t\tclearUpdateTimer();\n\t\t\t}\n\t\t},\n\t\trenderCall(args, _theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(formatShellCall(args, config.prompt));\n\t\t\treturn text;\n\t\t},\n\t\trenderResult(result, options, _theme, context) {\n\t\t\tconst component =\n\t\t\t\t(context.lastComponent as BashResultRenderComponent | undefined) ?? new BashResultRenderComponent();\n\t\t\trebuildBashResultRenderComponent(component, result, options, context.showImages);\n\t\t\tcomponent.invalidate();\n\t\t\treturn component;\n\t\t},\n\t};\n}\n\nconst bashToolConfig: ShellToolConfig = {\n\tname: \"bash\",\n\tlabel: \"bash\",\n\tshellName: \"bash\",\n\tprompt: \"$\",\n\tpromptSnippet: bashToolSystemPromptContribution.snippet,\n\tpromptGuidelines: bashToolSystemPromptContribution.guidelines,\n\ttempFilePrefix: \"agent-forge-bash\",\n};\n\nexport function createBashToolDefinition(\n\tcwd: string,\n\toptions?: BashToolOptions,\n): ToolDefinition<typeof bashSchema, BashToolDetails | undefined> {\n\treturn createShellToolDefinition(cwd, bashToolConfig, options);\n}\n\nexport function createBashTool(cwd: string, options?: BashToolOptions): AgentTool<typeof bashSchema> {\n\tconst definition = createBashToolDefinition(cwd, options);\n\tconst tool = wrapToolDefinition(definition);\n\tObject.assign(tool, {\n\t\tpromptSnippet: definition.promptSnippet,\n\t\tpromptGuidelines: definition.promptGuidelines,\n\t});\n\treturn tool;\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "agent-forge.plugin.coding-tools",
3
- "version": "0.88.5",
3
+ "version": "0.88.6",
4
4
  "apiVersion": "1-draft",
5
5
  "entry": "./dist/entry.js",
6
6
  "hostVersion": ">=0.88.0",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "packageFormatVersion": 1,
3
3
  "id": "agent-forge.plugin.compaction-policy",
4
- "pluginVersion": "0.88.5",
4
+ "pluginVersion": "0.88.6",
5
5
  "apiVersion": "1",
6
6
  "minHostVersion": "0.88.0",
7
7
  "platform": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "agent-forge.plugin.compaction-policy",
3
- "version": "0.88.5",
3
+ "version": "0.88.6",
4
4
  "apiVersion": "1-draft",
5
5
  "entry": "./dist/entry.js",
6
6
  "hostVersion": ">=0.88.0",
@@ -1 +1 @@
1
- {"version":3,"file":"mcp-http.d.ts","sourceRoot":"","sources":["../src/mcp-http.ts"],"names":[],"mappings":"AAmBA,MAAM,WAAW,iBAAiB;IACjC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,uBAAuB;IACvC,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,iBAAiB,GAAG,OAAO,GAAG,WAAW,GAAG,UAAU,CAAC;IAClF,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CA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WAAW,wBAAwB;IACxC,YAAY,CAAC,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC;CAC3C;AAWD;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE;IACjD,GAAG,EAAE,MAAM,CAAC;IACZ,0GAA0G;IAC1G,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAC3C,GAAG,CAAC,GAAG,EAAE,wBAAwB,KAAK,OAAO,CAAC;IAAE,OAAO,IAAI,IAAI,CAAA;CAAE,CAAC,CAqDlE","sourcesContent":["/**\n * MCP HTTP transport (4.3) — a streamable-HTTP MCP transport implementing the\n * same transport interface as the stdio plugin, plus observable retry.\n *\n * Retries apply ONLY to requests the server could not have started (connect\n * errors, 5xx, 429) — a completed response (any JSON-RPC reply) is never\n * re-sent, keeping calls idempotent from the caller's perspective. Every\n * transport error, retry attempt, and reconnect is reported through the\n * `onEvent` callback so callers can observe what happened. CLI\n * productization is out of scope.\n */\n/**\n * Per-request options for MCP transports. Defined here rather than imported\n * from the mcp-stdio example so production src never depends on examples/\n * (统一修复轮 C reverse-dependency fix); structurally identical to the\n * example's own declaration, which stays self-contained.\n */\nimport { t } from \"@agent-forge/host/i18n\";\n\nexport interface McpRequestOptions {\n\tsignal?: AbortSignal;\n\ttimeoutMs?: number;\n}\n\nexport interface McpHttpTransportEventV1 {\n\treadonly kind: \"connect\" | \"transport_error\" | \"retry\" | \"reconnect\" | \"response\";\n\treadonly at: number;\n\treadonly detail: string;\n\treadonly attempt?: number;\n}\n\nexport interface McpHttpTransportOptionsV1 {\n\treadonly url: string;\n\treadonly timeoutMs?: number;\n\treadonly retryLimit?: number;\n\treadonly baseRetryMs?: number;\n\treadonly maxRetryMs?: number;\n\treadonly now?: () => number;\n\treadonly sleep?: (ms: number) => Promise<void> | void;\n\treadonly onEvent?: (event: McpHttpTransportEventV1) => void;\n\t/**\n\t * Extra request headers merged after the transport defaults on every\n\t * outbound request (initialize / notifications/initialized / tools/list /\n\t * tools/call), so user values can override the defaults — the\n\t * `Authorization: Bearer ...` case for hosted remote MCP servers. Values\n\t * are sent verbatim (never case-normalized). They may carry credentials:\n\t * the suite MCP pool materializes them into the generated plugin entry\n\t * below `<agentDir>/mcp/pool/`, which sits inside the same local-machine\n\t * data boundary as `auth.json` (docs/design/产品价值度量与数据边界登记.md\n\t * §2.1 本机数据).\n\t */\n\treadonly headers?: Readonly<Record<string, string>>;\n}\n\n/** Structurally compatible with the stdio plugin's transport interface. */\nexport interface McpHttpTransportV1 {\n\trequest(method: string, params?: unknown, options?: McpRequestOptions): Promise<unknown>;\n\tnotify(method: string, params?: unknown): Promise<void> | void;\n\tclose(): Promise<void> | void;\n\tevents(): readonly McpHttpTransportEventV1[];\n}\n\ninterface JsonRpcResponse {\n\tid?: number | string | null;\n\tresult?: unknown;\n\terror?: { code?: number; message?: string };\n}\n\nexport function createMcpHttpTransport(options: McpHttpTransportOptionsV1): McpHttpTransportV1 {\n\tconst timeoutMs = options.timeoutMs ?? 10_000;\n\tconst retryLimit = options.retryLimit ?? 2;\n\tconst baseRetryMs = options.baseRetryMs ?? 100;\n\tconst maxRetryMs = options.maxRetryMs ?? 1_600;\n\tconst now = options.now ?? (() => Date.now());\n\tconst sleep = options.sleep ?? (() => undefined);\n\tconst events: McpHttpTransportEventV1[] = [];\n\tlet nextId = 1;\n\tlet closed = false;\n\n\tconst record = (event: McpHttpTransportEventV1): void => {\n\t\tevents.push(event);\n\t\toptions.onEvent?.(event);\n\t};\n\n\tconst postOnce = async (\n\t\tbody: string,\n\t\trequestOptions: McpRequestOptions | undefined,\n\t): Promise<{ status: number; text: string } | { status: \"connect_error\"; reason: string }> => {\n\t\tconst controller = new AbortController();\n\t\tconst timer = setTimeout(() => controller.abort(), requestOptions?.timeoutMs ?? timeoutMs);\n\t\ttry {\n\t\t\tconst response = await fetch(options.url, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\theaders: {\n\t\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t\t\taccept: \"application/json, text/event-stream\",\n\t\t\t\t\t...(options.headers ?? {}),\n\t\t\t\t},\n\t\t\t\tbody,\n\t\t\t\tsignal: controller.signal,\n\t\t\t});\n\t\t\tconst text = await response.text();\n\t\t\treturn { status: response.status, text };\n\t\t} catch (error) {\n\t\t\tconst reason = error instanceof Error ? `${error.name}: ${error.message}` : String(error);\n\t\t\treturn { status: \"connect_error\", reason };\n\t\t} finally {\n\t\t\tclearTimeout(timer);\n\t\t}\n\t};\n\n\tconst postWithRetry = async (\n\t\tbody: string,\n\t\trequestOptions?: McpRequestOptions,\n\t): Promise<{ status: number; text: string }> => {\n\t\tfor (let attempt = 1; ; attempt += 1) {\n\t\t\tconst response = await postOnce(body, requestOptions);\n\t\t\tif (response.status !== \"connect_error\" && response.status < 500 && response.status !== 429) {\n\t\t\t\trecord({ kind: \"response\", at: now(), detail: `HTTP ${response.status}`, attempt });\n\t\t\t\treturn response;\n\t\t\t}\n\t\t\tconst reason = response.status === \"connect_error\" ? response.reason : `HTTP ${response.status}`;\n\t\t\tif (attempt > retryLimit) {\n\t\t\t\trecord({\n\t\t\t\t\tkind: \"transport_error\",\n\t\t\t\t\tat: now(),\n\t\t\t\t\tdetail: `giving up after ${attempt - 1} retries: ${reason}`,\n\t\t\t\t\tattempt,\n\t\t\t\t});\n\t\t\t\tthrow new Error(t(\"MCP HTTP transport error: {reason}\", { reason }));\n\t\t\t}\n\t\t\tconst waitedMs = Math.min(baseRetryMs * 2 ** (attempt - 1), maxRetryMs);\n\t\t\trecord({\n\t\t\t\tkind: \"retry\",\n\t\t\t\tat: now(),\n\t\t\t\tdetail: `attempt ${attempt} failed (${reason}); waiting ${waitedMs}ms`,\n\t\t\t\tattempt,\n\t\t\t});\n\t\t\tawait sleep(waitedMs);\n\t\t\tif (attempt === 1 && response.status === \"connect_error\") {\n\t\t\t\trecord({ kind: \"reconnect\", at: now(), detail: \"re-establishing HTTP connection\", attempt });\n\t\t\t}\n\t\t}\n\t};\n\n\tconst rpc = async (method: string, params?: unknown, requestOptions?: McpRequestOptions): Promise<unknown> => {\n\t\tif (closed) throw new Error(t(\"MCP HTTP transport is closed\"));\n\t\tconst id = nextId;\n\t\tnextId += 1;\n\t\tconst body = JSON.stringify({ jsonrpc: \"2.0\", id, method, ...(params === undefined ? {} : { params }) });\n\t\tconst response = await postWithRetry(body, requestOptions);\n\t\tif (response.status !== 200) {\n\t\t\tthrow new Error(t(\"MCP HTTP transport returned HTTP {status}\", { status: response.status }));\n\t\t}\n\t\tlet parsed: JsonRpcResponse;\n\t\ttry {\n\t\t\tparsed = JSON.parse(response.text) as JsonRpcResponse;\n\t\t} catch (error) {\n\t\t\tthrow new Error(\n\t\t\t\t// v8 ignore next -- JSON.parse 只会抛出 Error 对象\n\t\t\t\tt(\"MCP HTTP transport returned non-JSON body: {reason}\", {\n\t\t\t\t\treason: error instanceof Error ? error.message : String(error),\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t\tif (parsed.error !== undefined) {\n\t\t\tthrow new Error(\n\t\t\t\tt(\"MCP error {code}: {message}\", {\n\t\t\t\t\tcode: parsed.error.code ?? \"\",\n\t\t\t\t\tmessage: parsed.error.message ?? t(\"unknown error\"),\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t\treturn parsed.result;\n\t};\n\n\treturn {\n\t\tasync request(method, params, requestOptions) {\n\t\t\treturn rpc(method, params, requestOptions);\n\t\t},\n\t\tasync notify(method, params) {\n\t\t\tawait postWithRetry(\n\t\t\t\tJSON.stringify({ jsonrpc: \"2.0\", method, ...(params === undefined ? {} : { params }) }),\n\t\t\t\tundefined,\n\t\t\t);\n\t\t},\n\t\tasync close() {\n\t\t\tclosed = true;\n\t\t},\n\t\tevents() {\n\t\t\treturn Object.freeze([...events]);\n\t\t},\n\t};\n}\n\n/** Minimal api surface the HTTP server plugin relies on (capability registerTool). */\nexport interface McpHttpServerPluginApiV1 {\n\tregisterTool(definition: unknown): unknown;\n}\n\nfunction normalizeToolResult(result: unknown): { content: unknown[]; details?: unknown } {\n\tif (result && typeof result === \"object\" && Array.isArray((result as { content?: unknown }).content)) {\n\t\tconst { content, details } = result as { content: unknown[]; details?: unknown };\n\t\treturn { content, details };\n\t}\n\tif (result === undefined) return { content: [{ type: \"text\", text: \"\" }] };\n\treturn { content: [{ type: \"text\", text: JSON.stringify(result) }] };\n}\n\n/**\n * Configuration-driven entry for remote MCP servers: wires\n * createMcpHttpTransport into the same plugin shape as the generated stdio\n * bridge (initialize/tools/list handshake, one registerTool per remote tool,\n * dual call convention). Tool call policy stays host-owned; the plugin only\n * forwards requests and maps results. The suite MCP registration pool\n * materializes url-configured servers through this entry; optional `headers`\n * are forwarded verbatim to the transport (credential note there).\n */\nexport function createMcpHttpServerPlugin(config: {\n\turl: string;\n\t/** Forwarded to the transport verbatim; see McpHttpTransportOptionsV1.headers for the credential note. */\n\theaders?: Readonly<Record<string, string>>;\n}): (api: McpHttpServerPluginApiV1) => Promise<{ dispose(): void }> {\n\treturn async (api) => {\n\t\tconst transport = createMcpHttpTransport({ url: config.url, headers: config.headers });\n\t\ttry {\n\t\t\tawait transport.request(\"initialize\", {\n\t\t\t\tprotocolVersion: \"2024-11-05\",\n\t\t\t\tcapabilities: {},\n\t\t\t\tclientInfo: { name: \"agent-forge-mcp-pool\", version: \"0.1.0\" },\n\t\t\t});\n\t\t\tawait transport.notify(\"notifications/initialized\");\n\t\t\tconst listing = (await transport.request(\"tools/list\")) as { tools?: unknown };\n\t\t\tif (!listing || !Array.isArray(listing.tools)) {\n\t\t\t\tthrow new Error(t(\"MCP tools/list result must contain tools[]\"));\n\t\t\t}\n\t\t\tfor (const tool of listing.tools) {\n\t\t\t\tconst candidate = tool as { name?: unknown; description?: unknown; inputSchema?: unknown };\n\t\t\t\tif (!candidate || typeof candidate.name !== \"string\" || !candidate.name) {\n\t\t\t\t\tthrow new Error(t(\"MCP tool requires a non-empty name\"));\n\t\t\t\t}\n\t\t\t\tapi.registerTool({\n\t\t\t\t\tname: candidate.name,\n\t\t\t\t\tlabel: candidate.name,\n\t\t\t\t\tdescription:\n\t\t\t\t\t\ttypeof candidate.description === \"string\" ? candidate.description : `MCP tool: ${candidate.name}`,\n\t\t\t\t\tparameters:\n\t\t\t\t\t\tcandidate.inputSchema && typeof candidate.inputSchema === \"object\"\n\t\t\t\t\t\t\t? candidate.inputSchema\n\t\t\t\t\t\t\t: { type: \"object\", properties: {} },\n\t\t\t\t\texecute: async (toolCallId: string, params: unknown, signal?: AbortSignal) => {\n\t\t\t\t\t\t// Dual call convention: the session passes (toolCallId, params,\n\t\t\t\t\t\t// signal); the runtime's invokeTool passes the input as the\n\t\t\t\t\t\t// single first argument.\n\t\t\t\t\t\tconst singleArgCall = params === undefined && typeof toolCallId !== \"string\";\n\t\t\t\t\t\tconst input = singleArgCall ? toolCallId : params;\n\t\t\t\t\t\tconst result = await transport.request(\n\t\t\t\t\t\t\t\"tools/call\",\n\t\t\t\t\t\t\t{ name: candidate.name as string, arguments: input || {} },\n\t\t\t\t\t\t\tsingleArgCall ? undefined : { signal },\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn normalizeToolResult(result);\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tdispose() {\n\t\t\t\t\ttransport.close();\n\t\t\t\t},\n\t\t\t};\n\t\t} catch (error) {\n\t\t\ttransport.close();\n\t\t\tthrow error;\n\t\t}\n\t};\n}\n"]}
1
+ {"version":3,"file":"mcp-http.d.ts","sourceRoot":"","sources":["../src/mcp-http.ts"],"names":[],"mappings":"AAuBA,MAAM,WAAW,iBAAiB;IACjC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,uBAAuB;IACvC,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,iBAAiB,GAAG,OAAO,GAAG,WAAW,GAAG,UAAU,CAAC;IAClF,QAAQ,CAAC,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BAAkB,CA2K7F;AAED,sFAAsF;AACtF,MAAM,WAAW,wBAAwB;IACxC,YAAY,CAAC,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC;CAC3C;AAWD;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE;IACjD,GAAG,EAAE,MAAM,CAAC;IACZ,0GAA0G;IAC1G,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAC3C,GAAG,CAAC,GAAG,EAAE,wBAAwB,KAAK,OAAO,CAAC;IAAE,OAAO,IAAI,IAAI,CAAA;CAAE,CAAC,CAqDlE","sourcesContent":["/**\n * MCP HTTP transport (4.3) — a streamable-HTTP MCP transport implementing the\n * same transport interface as the stdio plugin, plus observable retry.\n *\n * Retries apply ONLY to requests the server could not have started (connect\n * errors, 5xx, 429) — a completed response (any JSON-RPC reply) is never\n * re-sent, keeping calls idempotent from the caller's perspective. The same\n * idempotency rule makes post-send failures terminal: a response-body read\n * error, a per-request timeout, or a caller abort all mean the request\n * already reached the server, so they are reported once and never re-sent.\n * close() rejects every in-flight request and fails new ones immediately.\n * Every transport error, retry attempt, and reconnect is reported through the\n * `onEvent` callback so callers can observe what happened. CLI\n * productization is out of scope.\n */\n/**\n * Per-request options for MCP transports. Defined here rather than imported\n * from the mcp-stdio example so production src never depends on examples/\n * (统一修复轮 C reverse-dependency fix); structurally identical to the\n * example's own declaration, which stays self-contained.\n */\nimport { t } from \"@agent-forge/host/i18n\";\n\nexport interface McpRequestOptions {\n\tsignal?: AbortSignal;\n\ttimeoutMs?: number;\n}\n\nexport interface McpHttpTransportEventV1 {\n\treadonly kind: \"connect\" | \"transport_error\" | \"retry\" | \"reconnect\" | \"response\";\n\treadonly at: number;\n\treadonly detail: string;\n\treadonly attempt?: number;\n}\n\nexport interface McpHttpTransportOptionsV1 {\n\treadonly url: string;\n\treadonly timeoutMs?: number;\n\treadonly retryLimit?: number;\n\treadonly baseRetryMs?: number;\n\treadonly maxRetryMs?: number;\n\treadonly now?: () => number;\n\treadonly sleep?: (ms: number) => Promise<void> | void;\n\treadonly onEvent?: (event: McpHttpTransportEventV1) => void;\n\t/**\n\t * Extra request headers merged after the transport defaults on every\n\t * outbound request (initialize / notifications/initialized / tools/list /\n\t * tools/call), so user values can override the defaults — the\n\t * `Authorization: Bearer ...` case for hosted remote MCP servers. Values\n\t * are sent verbatim (never case-normalized). They may carry credentials:\n\t * the suite MCP pool materializes them into the generated plugin entry\n\t * below `<agentDir>/mcp/pool/`, which sits inside the same local-machine\n\t * data boundary as `auth.json` (docs/design/产品价值度量与数据边界登记.md\n\t * §2.1 本机数据).\n\t */\n\treadonly headers?: Readonly<Record<string, string>>;\n}\n\n/** Structurally compatible with the stdio plugin's transport interface. */\nexport interface McpHttpTransportV1 {\n\trequest(method: string, params?: unknown, options?: McpRequestOptions): Promise<unknown>;\n\tnotify(method: string, params?: unknown): Promise<void> | void;\n\tclose(): Promise<void> | void;\n\tevents(): readonly McpHttpTransportEventV1[];\n}\n\ninterface JsonRpcResponse {\n\tid?: number | string | null;\n\tresult?: unknown;\n\terror?: { code?: number; message?: string };\n}\n\n/**\n * One postOnce outcome. `connect_error` means the fetch call itself failed\n * before a response arrived (the server could not have started) and stays\n * retryable; `read_error` and `aborted` mean the request already reached the\n * server, so both are terminal and never re-sent.\n */\ntype PostOnceResult =\n\t| { status: number; text: string }\n\t| { status: \"connect_error\"; reason: string }\n\t| { status: \"read_error\"; reason: string }\n\t| { status: \"aborted\"; reason: string };\n\nconst formatError = (error: unknown): string =>\n\terror instanceof Error ? `${error.name}: ${error.message}` : String(error);\n\nexport function createMcpHttpTransport(options: McpHttpTransportOptionsV1): McpHttpTransportV1 {\n\tconst timeoutMs = options.timeoutMs ?? 10_000;\n\tconst retryLimit = options.retryLimit ?? 2;\n\tconst baseRetryMs = options.baseRetryMs ?? 100;\n\tconst maxRetryMs = options.maxRetryMs ?? 1_600;\n\tconst now = options.now ?? (() => Date.now());\n\tconst sleep = options.sleep ?? ((ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms)));\n\tconst events: McpHttpTransportEventV1[] = [];\n\tlet nextId = 1;\n\tlet closed = false;\n\n\tconst record = (event: McpHttpTransportEventV1): void => {\n\t\tevents.push(event);\n\t\toptions.onEvent?.(event);\n\t};\n\n\t/** Abort controllers for in-flight postWithRetry runs; close() aborts them all. */\n\tconst inFlight = new Set<AbortController>();\n\n\tconst closedError = (): Error => new Error(t(\"MCP HTTP transport is closed\"));\n\n\tconst postOnce = async (\n\t\tbody: string,\n\t\trequestOptions: McpRequestOptions | undefined,\n\t\tcloseSignal: AbortSignal,\n\t): Promise<PostOnceResult> => {\n\t\tif (requestOptions?.signal?.aborted) {\n\t\t\treturn { status: \"aborted\", reason: t(\"request aborted before it was sent\") };\n\t\t}\n\t\tconst controller = new AbortController();\n\t\tconst timer = setTimeout(() => controller.abort(), requestOptions?.timeoutMs ?? timeoutMs);\n\t\tconst signals: AbortSignal[] = [controller.signal, closeSignal];\n\t\tif (requestOptions?.signal) signals.push(requestOptions.signal);\n\t\ttry {\n\t\t\tconst response = await fetch(options.url, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\theaders: {\n\t\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t\t\taccept: \"application/json, text/event-stream\",\n\t\t\t\t\t...(options.headers ?? {}),\n\t\t\t\t},\n\t\t\t\tbody,\n\t\t\t\tsignal: AbortSignal.any(signals),\n\t\t\t});\n\t\t\tlet text: string;\n\t\t\ttry {\n\t\t\t\ttext = await response.text();\n\t\t\t} catch (error) {\n\t\t\t\t// Response headers already arrived: the server may have started\n\t\t\t\t// executing, so a re-send could duplicate side effects.\n\t\t\t\treturn { status: \"read_error\", reason: formatError(error) };\n\t\t\t}\n\t\t\treturn { status: response.status, text };\n\t\t} catch (error) {\n\t\t\t// An abort means the request was already sent (per-request timeout,\n\t\t\t// caller signal, or close), so it must never be re-sent. Only a fetch\n\t\t\t// failure before any response stays classified as connect_error.\n\t\t\tif (controller.signal.aborted || requestOptions?.signal?.aborted) {\n\t\t\t\treturn { status: \"aborted\", reason: formatError(error) };\n\t\t\t}\n\t\t\treturn { status: \"connect_error\", reason: formatError(error) };\n\t\t} finally {\n\t\t\tclearTimeout(timer);\n\t\t}\n\t};\n\n\tconst postWithRetry = async (\n\t\tbody: string,\n\t\trequestOptions?: McpRequestOptions,\n\t): Promise<{ status: number; text: string }> => {\n\t\tconst closeController = new AbortController();\n\t\tinFlight.add(closeController);\n\t\ttry {\n\t\t\tfor (let attempt = 1; ; attempt += 1) {\n\t\t\t\tif (closed) throw closedError();\n\t\t\t\tconst response = await postOnce(body, requestOptions, closeController.signal);\n\t\t\t\tif (closed) throw closedError();\n\t\t\t\tif (response.status === \"read_error\" || response.status === \"aborted\") {\n\t\t\t\t\trecord({\n\t\t\t\t\t\tkind: \"transport_error\",\n\t\t\t\t\t\tat: now(),\n\t\t\t\t\t\tdetail: `${response.status}: ${response.reason}`,\n\t\t\t\t\t\tattempt,\n\t\t\t\t\t});\n\t\t\t\t\tthrow new Error(t(\"MCP HTTP transport error: {reason}\", { reason: response.reason }));\n\t\t\t\t}\n\t\t\t\tif (response.status !== \"connect_error\" && response.status < 500 && response.status !== 429) {\n\t\t\t\t\trecord({ kind: \"response\", at: now(), detail: `HTTP ${response.status}`, attempt });\n\t\t\t\t\treturn response;\n\t\t\t\t}\n\t\t\t\tconst reason = response.status === \"connect_error\" ? response.reason : `HTTP ${response.status}`;\n\t\t\t\tif (attempt > retryLimit) {\n\t\t\t\t\trecord({\n\t\t\t\t\t\tkind: \"transport_error\",\n\t\t\t\t\t\tat: now(),\n\t\t\t\t\t\tdetail: `giving up after ${attempt - 1} retries: ${reason}`,\n\t\t\t\t\t\tattempt,\n\t\t\t\t\t});\n\t\t\t\t\tthrow new Error(t(\"MCP HTTP transport error: {reason}\", { reason }));\n\t\t\t\t}\n\t\t\t\tconst waitedMs = Math.min(baseRetryMs * 2 ** (attempt - 1), maxRetryMs);\n\t\t\t\trecord({\n\t\t\t\t\tkind: \"retry\",\n\t\t\t\t\tat: now(),\n\t\t\t\t\tdetail: `attempt ${attempt} failed (${reason}); waiting ${waitedMs}ms`,\n\t\t\t\t\tattempt,\n\t\t\t\t});\n\t\t\t\tawait sleep(waitedMs);\n\t\t\t\tif (attempt === 1 && response.status === \"connect_error\") {\n\t\t\t\t\trecord({ kind: \"reconnect\", at: now(), detail: \"re-establishing HTTP connection\", attempt });\n\t\t\t\t}\n\t\t\t}\n\t\t} finally {\n\t\t\tinFlight.delete(closeController);\n\t\t}\n\t};\n\n\tconst rpc = async (method: string, params?: unknown, requestOptions?: McpRequestOptions): Promise<unknown> => {\n\t\tif (closed) throw closedError();\n\t\tconst id = nextId;\n\t\tnextId += 1;\n\t\tconst body = JSON.stringify({ jsonrpc: \"2.0\", id, method, ...(params === undefined ? {} : { params }) });\n\t\tconst response = await postWithRetry(body, requestOptions);\n\t\tif (response.status !== 200) {\n\t\t\tthrow new Error(t(\"MCP HTTP transport returned HTTP {status}\", { status: response.status }));\n\t\t}\n\t\tlet parsed: JsonRpcResponse;\n\t\ttry {\n\t\t\tparsed = JSON.parse(response.text) as JsonRpcResponse;\n\t\t} catch (error) {\n\t\t\tthrow new Error(\n\t\t\t\t// v8 ignore next -- JSON.parse 只会抛出 Error 对象\n\t\t\t\tt(\"MCP HTTP transport returned non-JSON body: {reason}\", {\n\t\t\t\t\treason: error instanceof Error ? error.message : String(error),\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t\tif (parsed.error !== undefined) {\n\t\t\tthrow new Error(\n\t\t\t\tt(\"MCP error {code}: {message}\", {\n\t\t\t\t\tcode: parsed.error.code ?? \"\",\n\t\t\t\t\tmessage: parsed.error.message ?? t(\"unknown error\"),\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t\treturn parsed.result;\n\t};\n\n\treturn {\n\t\tasync request(method, params, requestOptions) {\n\t\t\treturn rpc(method, params, requestOptions);\n\t\t},\n\t\tasync notify(method, params) {\n\t\t\tawait postWithRetry(\n\t\t\t\tJSON.stringify({ jsonrpc: \"2.0\", method, ...(params === undefined ? {} : { params }) }),\n\t\t\t\tundefined,\n\t\t\t);\n\t\t},\n\t\tasync close() {\n\t\t\tclosed = true;\n\t\t\t// Reject every in-flight request promptly: aborting its run makes the\n\t\t\t// pending fetch fail and the loop throw the closed error instead of\n\t\t\t// returning a late success or retrying after close.\n\t\t\tfor (const controller of inFlight) {\n\t\t\t\tcontroller.abort(closedError());\n\t\t\t}\n\t\t},\n\t\tevents() {\n\t\t\treturn Object.freeze([...events]);\n\t\t},\n\t};\n}\n\n/** Minimal api surface the HTTP server plugin relies on (capability registerTool). */\nexport interface McpHttpServerPluginApiV1 {\n\tregisterTool(definition: unknown): unknown;\n}\n\nfunction normalizeToolResult(result: unknown): { content: unknown[]; details?: unknown } {\n\tif (result && typeof result === \"object\" && Array.isArray((result as { content?: unknown }).content)) {\n\t\tconst { content, details } = result as { content: unknown[]; details?: unknown };\n\t\treturn { content, details };\n\t}\n\tif (result === undefined) return { content: [{ type: \"text\", text: \"\" }] };\n\treturn { content: [{ type: \"text\", text: JSON.stringify(result) }] };\n}\n\n/**\n * Configuration-driven entry for remote MCP servers: wires\n * createMcpHttpTransport into the same plugin shape as the generated stdio\n * bridge (initialize/tools/list handshake, one registerTool per remote tool,\n * dual call convention). Tool call policy stays host-owned; the plugin only\n * forwards requests and maps results. The suite MCP registration pool\n * materializes url-configured servers through this entry; optional `headers`\n * are forwarded verbatim to the transport (credential note there).\n */\nexport function createMcpHttpServerPlugin(config: {\n\turl: string;\n\t/** Forwarded to the transport verbatim; see McpHttpTransportOptionsV1.headers for the credential note. */\n\theaders?: Readonly<Record<string, string>>;\n}): (api: McpHttpServerPluginApiV1) => Promise<{ dispose(): void }> {\n\treturn async (api) => {\n\t\tconst transport = createMcpHttpTransport({ url: config.url, headers: config.headers });\n\t\ttry {\n\t\t\tawait transport.request(\"initialize\", {\n\t\t\t\tprotocolVersion: \"2024-11-05\",\n\t\t\t\tcapabilities: {},\n\t\t\t\tclientInfo: { name: \"agent-forge-mcp-pool\", version: \"0.1.0\" },\n\t\t\t});\n\t\t\tawait transport.notify(\"notifications/initialized\");\n\t\t\tconst listing = (await transport.request(\"tools/list\")) as { tools?: unknown };\n\t\t\tif (!listing || !Array.isArray(listing.tools)) {\n\t\t\t\tthrow new Error(t(\"MCP tools/list result must contain tools[]\"));\n\t\t\t}\n\t\t\tfor (const tool of listing.tools) {\n\t\t\t\tconst candidate = tool as { name?: unknown; description?: unknown; inputSchema?: unknown };\n\t\t\t\tif (!candidate || typeof candidate.name !== \"string\" || !candidate.name) {\n\t\t\t\t\tthrow new Error(t(\"MCP tool requires a non-empty name\"));\n\t\t\t\t}\n\t\t\t\tapi.registerTool({\n\t\t\t\t\tname: candidate.name,\n\t\t\t\t\tlabel: candidate.name,\n\t\t\t\t\tdescription:\n\t\t\t\t\t\ttypeof candidate.description === \"string\" ? candidate.description : `MCP tool: ${candidate.name}`,\n\t\t\t\t\tparameters:\n\t\t\t\t\t\tcandidate.inputSchema && typeof candidate.inputSchema === \"object\"\n\t\t\t\t\t\t\t? candidate.inputSchema\n\t\t\t\t\t\t\t: { type: \"object\", properties: {} },\n\t\t\t\t\texecute: async (toolCallId: string, params: unknown, signal?: AbortSignal) => {\n\t\t\t\t\t\t// Dual call convention: the session passes (toolCallId, params,\n\t\t\t\t\t\t// signal); the runtime's invokeTool passes the input as the\n\t\t\t\t\t\t// single first argument.\n\t\t\t\t\t\tconst singleArgCall = params === undefined && typeof toolCallId !== \"string\";\n\t\t\t\t\t\tconst input = singleArgCall ? toolCallId : params;\n\t\t\t\t\t\tconst result = await transport.request(\n\t\t\t\t\t\t\t\"tools/call\",\n\t\t\t\t\t\t\t{ name: candidate.name as string, arguments: input || {} },\n\t\t\t\t\t\t\tsingleArgCall ? undefined : { signal },\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn normalizeToolResult(result);\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tdispose() {\n\t\t\t\t\ttransport.close();\n\t\t\t\t},\n\t\t\t};\n\t\t} catch (error) {\n\t\t\ttransport.close();\n\t\t\tthrow error;\n\t\t}\n\t};\n}\n"]}
@@ -4,8 +4,12 @@
4
4
  *
5
5
  * Retries apply ONLY to requests the server could not have started (connect
6
6
  * errors, 5xx, 429) — a completed response (any JSON-RPC reply) is never
7
- * re-sent, keeping calls idempotent from the caller's perspective. Every
8
- * transport error, retry attempt, and reconnect is reported through the
7
+ * re-sent, keeping calls idempotent from the caller's perspective. The same
8
+ * idempotency rule makes post-send failures terminal: a response-body read
9
+ * error, a per-request timeout, or a caller abort all mean the request
10
+ * already reached the server, so they are reported once and never re-sent.
11
+ * close() rejects every in-flight request and fails new ones immediately.
12
+ * Every transport error, retry attempt, and reconnect is reported through the
9
13
  * `onEvent` callback so callers can observe what happened. CLI
10
14
  * productization is out of scope.
11
15
  */
@@ -16,13 +20,14 @@
16
20
  * example's own declaration, which stays self-contained.
17
21
  */
18
22
  import { t } from "@agent-forge/host/i18n";
23
+ const formatError = (error) => error instanceof Error ? `${error.name}: ${error.message}` : String(error);
19
24
  export function createMcpHttpTransport(options) {
20
25
  const timeoutMs = options.timeoutMs ?? 10_000;
21
26
  const retryLimit = options.retryLimit ?? 2;
22
27
  const baseRetryMs = options.baseRetryMs ?? 100;
23
28
  const maxRetryMs = options.maxRetryMs ?? 1_600;
24
29
  const now = options.now ?? (() => Date.now());
25
- const sleep = options.sleep ?? (() => undefined);
30
+ const sleep = options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
26
31
  const events = [];
27
32
  let nextId = 1;
28
33
  let closed = false;
@@ -30,9 +35,18 @@ export function createMcpHttpTransport(options) {
30
35
  events.push(event);
31
36
  options.onEvent?.(event);
32
37
  };
33
- const postOnce = async (body, requestOptions) => {
38
+ /** Abort controllers for in-flight postWithRetry runs; close() aborts them all. */
39
+ const inFlight = new Set();
40
+ const closedError = () => new Error(t("MCP HTTP transport is closed"));
41
+ const postOnce = async (body, requestOptions, closeSignal) => {
42
+ if (requestOptions?.signal?.aborted) {
43
+ return { status: "aborted", reason: t("request aborted before it was sent") };
44
+ }
34
45
  const controller = new AbortController();
35
46
  const timer = setTimeout(() => controller.abort(), requestOptions?.timeoutMs ?? timeoutMs);
47
+ const signals = [controller.signal, closeSignal];
48
+ if (requestOptions?.signal)
49
+ signals.push(requestOptions.signal);
36
50
  try {
37
51
  const response = await fetch(options.url, {
38
52
  method: "POST",
@@ -42,52 +56,85 @@ export function createMcpHttpTransport(options) {
42
56
  ...(options.headers ?? {}),
43
57
  },
44
58
  body,
45
- signal: controller.signal,
59
+ signal: AbortSignal.any(signals),
46
60
  });
47
- const text = await response.text();
61
+ let text;
62
+ try {
63
+ text = await response.text();
64
+ }
65
+ catch (error) {
66
+ // Response headers already arrived: the server may have started
67
+ // executing, so a re-send could duplicate side effects.
68
+ return { status: "read_error", reason: formatError(error) };
69
+ }
48
70
  return { status: response.status, text };
49
71
  }
50
72
  catch (error) {
51
- const reason = error instanceof Error ? `${error.name}: ${error.message}` : String(error);
52
- return { status: "connect_error", reason };
73
+ // An abort means the request was already sent (per-request timeout,
74
+ // caller signal, or close), so it must never be re-sent. Only a fetch
75
+ // failure before any response stays classified as connect_error.
76
+ if (controller.signal.aborted || requestOptions?.signal?.aborted) {
77
+ return { status: "aborted", reason: formatError(error) };
78
+ }
79
+ return { status: "connect_error", reason: formatError(error) };
53
80
  }
54
81
  finally {
55
82
  clearTimeout(timer);
56
83
  }
57
84
  };
58
85
  const postWithRetry = async (body, requestOptions) => {
59
- for (let attempt = 1;; attempt += 1) {
60
- const response = await postOnce(body, requestOptions);
61
- if (response.status !== "connect_error" && response.status < 500 && response.status !== 429) {
62
- record({ kind: "response", at: now(), detail: `HTTP ${response.status}`, attempt });
63
- return response;
64
- }
65
- const reason = response.status === "connect_error" ? response.reason : `HTTP ${response.status}`;
66
- if (attempt > retryLimit) {
86
+ const closeController = new AbortController();
87
+ inFlight.add(closeController);
88
+ try {
89
+ for (let attempt = 1;; attempt += 1) {
90
+ if (closed)
91
+ throw closedError();
92
+ const response = await postOnce(body, requestOptions, closeController.signal);
93
+ if (closed)
94
+ throw closedError();
95
+ if (response.status === "read_error" || response.status === "aborted") {
96
+ record({
97
+ kind: "transport_error",
98
+ at: now(),
99
+ detail: `${response.status}: ${response.reason}`,
100
+ attempt,
101
+ });
102
+ throw new Error(t("MCP HTTP transport error: {reason}", { reason: response.reason }));
103
+ }
104
+ if (response.status !== "connect_error" && response.status < 500 && response.status !== 429) {
105
+ record({ kind: "response", at: now(), detail: `HTTP ${response.status}`, attempt });
106
+ return response;
107
+ }
108
+ const reason = response.status === "connect_error" ? response.reason : `HTTP ${response.status}`;
109
+ if (attempt > retryLimit) {
110
+ record({
111
+ kind: "transport_error",
112
+ at: now(),
113
+ detail: `giving up after ${attempt - 1} retries: ${reason}`,
114
+ attempt,
115
+ });
116
+ throw new Error(t("MCP HTTP transport error: {reason}", { reason }));
117
+ }
118
+ const waitedMs = Math.min(baseRetryMs * 2 ** (attempt - 1), maxRetryMs);
67
119
  record({
68
- kind: "transport_error",
120
+ kind: "retry",
69
121
  at: now(),
70
- detail: `giving up after ${attempt - 1} retries: ${reason}`,
122
+ detail: `attempt ${attempt} failed (${reason}); waiting ${waitedMs}ms`,
71
123
  attempt,
72
124
  });
73
- throw new Error(t("MCP HTTP transport error: {reason}", { reason }));
74
- }
75
- const waitedMs = Math.min(baseRetryMs * 2 ** (attempt - 1), maxRetryMs);
76
- record({
77
- kind: "retry",
78
- at: now(),
79
- detail: `attempt ${attempt} failed (${reason}); waiting ${waitedMs}ms`,
80
- attempt,
81
- });
82
- await sleep(waitedMs);
83
- if (attempt === 1 && response.status === "connect_error") {
84
- record({ kind: "reconnect", at: now(), detail: "re-establishing HTTP connection", attempt });
125
+ await sleep(waitedMs);
126
+ if (attempt === 1 && response.status === "connect_error") {
127
+ record({ kind: "reconnect", at: now(), detail: "re-establishing HTTP connection", attempt });
128
+ }
85
129
  }
86
130
  }
131
+ finally {
132
+ inFlight.delete(closeController);
133
+ }
87
134
  };
88
135
  const rpc = async (method, params, requestOptions) => {
89
136
  if (closed)
90
- throw new Error(t("MCP HTTP transport is closed"));
137
+ throw closedError();
91
138
  const id = nextId;
92
139
  nextId += 1;
93
140
  const body = JSON.stringify({ jsonrpc: "2.0", id, method, ...(params === undefined ? {} : { params }) });
@@ -123,6 +170,12 @@ export function createMcpHttpTransport(options) {
123
170
  },
124
171
  async close() {
125
172
  closed = true;
173
+ // Reject every in-flight request promptly: aborting its run makes the
174
+ // pending fetch fail and the loop throw the closed error instead of
175
+ // returning a late success or retrying after close.
176
+ for (const controller of inFlight) {
177
+ controller.abort(closedError());
178
+ }
126
179
  },
127
180
  events() {
128
181
  return Object.freeze([...events]);
@@ -1 +1 @@
1
- {"version":3,"file":"mcp-http.js","sourceRoot":"","sources":["../src/mcp-http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH;;;;;GAKG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,wBAAwB,CAAC;AAmD3C,MAAM,UAAU,sBAAsB,CAAC,OAAkC,EAAsB;IAC9F,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,MAAM,CAAC;IAC9C,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,CAAC,CAAC;IAC3C,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,GAAG,CAAC;IAC/C,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,KAAK,CAAC;IAC/C,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IAC9C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IACjD,MAAM,MAAM,GAA8B,EAAE,CAAC;IAC7C,IAA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rC,YAAY,EACZ,EAAE,IAAI,EAAE,SAAS,CAAC,IAAc,EAAE,SAAS,EAAE,KAAK,IAAI,EAAE,EAAE,EAC1D,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CACtC,CAAC;wBACF,OAAO,mBAAmB,CAAC,MAAM,CAAC,CAAC;oBAAA,CACnC;iBACD,CAAC,CAAC;YACJ,CAAC;YACD,OAAO;gBACN,OAAO,GAAG;oBACT,SAAS,CAAC,KAAK,EAAE,CAAC;gBAAA,CAClB;aACD,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,SAAS,CAAC,KAAK,EAAE,CAAC;YAClB,MAAM,KAAK,CAAC;QACb,CAAC;IAAA,CACD,CAAC;AAAA,CACF","sourcesContent":["/**\n * MCP HTTP transport (4.3) — a streamable-HTTP MCP transport implementing the\n * same transport interface as the stdio plugin, plus observable retry.\n *\n * Retries apply ONLY to requests the server could not have started (connect\n * errors, 5xx, 429) — a completed response (any JSON-RPC reply) is never\n * re-sent, keeping calls idempotent from the caller's perspective. Every\n * transport error, retry attempt, and reconnect is reported through the\n * `onEvent` callback so callers can observe what happened. CLI\n * productization is out of scope.\n */\n/**\n * Per-request options for MCP transports. Defined here rather than imported\n * from the mcp-stdio example so production src never depends on examples/\n * (统一修复轮 C reverse-dependency fix); structurally identical to the\n * example's own declaration, which stays self-contained.\n */\nimport { t } from \"@agent-forge/host/i18n\";\n\nexport interface McpRequestOptions {\n\tsignal?: AbortSignal;\n\ttimeoutMs?: number;\n}\n\nexport interface McpHttpTransportEventV1 {\n\treadonly kind: \"connect\" | \"transport_error\" | \"retry\" | \"reconnect\" | \"response\";\n\treadonly at: number;\n\treadonly detail: string;\n\treadonly attempt?: number;\n}\n\nexport interface McpHttpTransportOptionsV1 {\n\treadonly url: string;\n\treadonly timeoutMs?: number;\n\treadonly retryLimit?: number;\n\treadonly baseRetryMs?: number;\n\treadonly maxRetryMs?: number;\n\treadonly now?: () => number;\n\treadonly sleep?: (ms: number) => Promise<void> | void;\n\treadonly onEvent?: (event: McpHttpTransportEventV1) => void;\n\t/**\n\t * Extra request headers merged after the transport defaults on every\n\t * outbound request (initialize / notifications/initialized / tools/list /\n\t * tools/call), so user values can override the defaults — the\n\t * `Authorization: Bearer ...` case for hosted remote MCP servers. Values\n\t * are sent verbatim (never case-normalized). They may carry credentials:\n\t * the suite MCP pool materializes them into the generated plugin entry\n\t * below `<agentDir>/mcp/pool/`, which sits inside the same local-machine\n\t * data boundary as `auth.json` (docs/design/产品价值度量与数据边界登记.md\n\t * §2.1 本机数据).\n\t */\n\treadonly headers?: Readonly<Record<string, string>>;\n}\n\n/** Structurally compatible with the stdio plugin's transport interface. */\nexport interface McpHttpTransportV1 {\n\trequest(method: string, params?: unknown, options?: McpRequestOptions): Promise<unknown>;\n\tnotify(method: string, params?: unknown): Promise<void> | void;\n\tclose(): Promise<void> | void;\n\tevents(): readonly McpHttpTransportEventV1[];\n}\n\ninterface JsonRpcResponse {\n\tid?: number | string | null;\n\tresult?: unknown;\n\terror?: { code?: number; message?: string };\n}\n\nexport function createMcpHttpTransport(options: McpHttpTransportOptionsV1): McpHttpTransportV1 {\n\tconst timeoutMs = options.timeoutMs ?? 10_000;\n\tconst retryLimit = options.retryLimit ?? 2;\n\tconst baseRetryMs = options.baseRetryMs ?? 100;\n\tconst maxRetryMs = options.maxRetryMs ?? 1_600;\n\tconst now = options.now ?? (() => Date.now());\n\tconst sleep = options.sleep ?? (() => undefined);\n\tconst events: McpHttpTransportEventV1[] = [];\n\tlet nextId = 1;\n\tlet closed = false;\n\n\tconst record = (event: McpHttpTransportEventV1): void => {\n\t\tevents.push(event);\n\t\toptions.onEvent?.(event);\n\t};\n\n\tconst postOnce = async (\n\t\tbody: string,\n\t\trequestOptions: McpRequestOptions | undefined,\n\t): Promise<{ status: number; text: string } | { status: \"connect_error\"; reason: string }> => {\n\t\tconst controller = new AbortController();\n\t\tconst timer = setTimeout(() => controller.abort(), requestOptions?.timeoutMs ?? timeoutMs);\n\t\ttry {\n\t\t\tconst response = await fetch(options.url, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\theaders: {\n\t\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t\t\taccept: \"application/json, text/event-stream\",\n\t\t\t\t\t...(options.headers ?? {}),\n\t\t\t\t},\n\t\t\t\tbody,\n\t\t\t\tsignal: controller.signal,\n\t\t\t});\n\t\t\tconst text = await response.text();\n\t\t\treturn { status: response.status, text };\n\t\t} catch (error) {\n\t\t\tconst reason = error instanceof Error ? `${error.name}: ${error.message}` : String(error);\n\t\t\treturn { status: \"connect_error\", reason };\n\t\t} finally {\n\t\t\tclearTimeout(timer);\n\t\t}\n\t};\n\n\tconst postWithRetry = async (\n\t\tbody: string,\n\t\trequestOptions?: McpRequestOptions,\n\t): Promise<{ status: number; text: string }> => {\n\t\tfor (let attempt = 1; ; attempt += 1) {\n\t\t\tconst response = await postOnce(body, requestOptions);\n\t\t\tif (response.status !== \"connect_error\" && response.status < 500 && response.status !== 429) {\n\t\t\t\trecord({ kind: \"response\", at: now(), detail: `HTTP ${response.status}`, attempt });\n\t\t\t\treturn response;\n\t\t\t}\n\t\t\tconst reason = response.status === \"connect_error\" ? response.reason : `HTTP ${response.status}`;\n\t\t\tif (attempt > retryLimit) {\n\t\t\t\trecord({\n\t\t\t\t\tkind: \"transport_error\",\n\t\t\t\t\tat: now(),\n\t\t\t\t\tdetail: `giving up after ${attempt - 1} retries: ${reason}`,\n\t\t\t\t\tattempt,\n\t\t\t\t});\n\t\t\t\tthrow new Error(t(\"MCP HTTP transport error: {reason}\", { reason }));\n\t\t\t}\n\t\t\tconst waitedMs = Math.min(baseRetryMs * 2 ** (attempt - 1), maxRetryMs);\n\t\t\trecord({\n\t\t\t\tkind: \"retry\",\n\t\t\t\tat: now(),\n\t\t\t\tdetail: `attempt ${attempt} failed (${reason}); waiting ${waitedMs}ms`,\n\t\t\t\tattempt,\n\t\t\t});\n\t\t\tawait sleep(waitedMs);\n\t\t\tif (attempt === 1 && response.status === \"connect_error\") {\n\t\t\t\trecord({ kind: \"reconnect\", at: now(), detail: \"re-establishing HTTP connection\", attempt });\n\t\t\t}\n\t\t}\n\t};\n\n\tconst rpc = async (method: string, params?: unknown, requestOptions?: McpRequestOptions): Promise<unknown> => {\n\t\tif (closed) throw new Error(t(\"MCP HTTP transport is closed\"));\n\t\tconst id = nextId;\n\t\tnextId += 1;\n\t\tconst body = JSON.stringify({ jsonrpc: \"2.0\", id, method, ...(params === undefined ? {} : { params }) });\n\t\tconst response = await postWithRetry(body, requestOptions);\n\t\tif (response.status !== 200) {\n\t\t\tthrow new Error(t(\"MCP HTTP transport returned HTTP {status}\", { status: response.status }));\n\t\t}\n\t\tlet parsed: JsonRpcResponse;\n\t\ttry {\n\t\t\tparsed = JSON.parse(response.text) as JsonRpcResponse;\n\t\t} catch (error) {\n\t\t\tthrow new Error(\n\t\t\t\t// v8 ignore next -- JSON.parse 只会抛出 Error 对象\n\t\t\t\tt(\"MCP HTTP transport returned non-JSON body: {reason}\", {\n\t\t\t\t\treason: error instanceof Error ? error.message : String(error),\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t\tif (parsed.error !== undefined) {\n\t\t\tthrow new Error(\n\t\t\t\tt(\"MCP error {code}: {message}\", {\n\t\t\t\t\tcode: parsed.error.code ?? \"\",\n\t\t\t\t\tmessage: parsed.error.message ?? t(\"unknown error\"),\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t\treturn parsed.result;\n\t};\n\n\treturn {\n\t\tasync request(method, params, requestOptions) {\n\t\t\treturn rpc(method, params, requestOptions);\n\t\t},\n\t\tasync notify(method, params) {\n\t\t\tawait postWithRetry(\n\t\t\t\tJSON.stringify({ jsonrpc: \"2.0\", method, ...(params === undefined ? {} : { params }) }),\n\t\t\t\tundefined,\n\t\t\t);\n\t\t},\n\t\tasync close() {\n\t\t\tclosed = true;\n\t\t},\n\t\tevents() {\n\t\t\treturn Object.freeze([...events]);\n\t\t},\n\t};\n}\n\n/** Minimal api surface the HTTP server plugin relies on (capability registerTool). */\nexport interface McpHttpServerPluginApiV1 {\n\tregisterTool(definition: unknown): unknown;\n}\n\nfunction normalizeToolResult(result: unknown): { content: unknown[]; details?: unknown } {\n\tif (result && typeof result === \"object\" && Array.isArray((result as { content?: unknown }).content)) {\n\t\tconst { content, details } = result as { content: unknown[]; details?: unknown };\n\t\treturn { content, details };\n\t}\n\tif (result === undefined) return { content: [{ type: \"text\", text: \"\" }] };\n\treturn { content: [{ type: \"text\", text: JSON.stringify(result) }] };\n}\n\n/**\n * Configuration-driven entry for remote MCP servers: wires\n * createMcpHttpTransport into the same plugin shape as the generated stdio\n * bridge (initialize/tools/list handshake, one registerTool per remote tool,\n * dual call convention). Tool call policy stays host-owned; the plugin only\n * forwards requests and maps results. The suite MCP registration pool\n * materializes url-configured servers through this entry; optional `headers`\n * are forwarded verbatim to the transport (credential note there).\n */\nexport function createMcpHttpServerPlugin(config: {\n\turl: string;\n\t/** Forwarded to the transport verbatim; see McpHttpTransportOptionsV1.headers for the credential note. */\n\theaders?: Readonly<Record<string, string>>;\n}): (api: McpHttpServerPluginApiV1) => Promise<{ dispose(): void }> {\n\treturn async (api) => {\n\t\tconst transport = createMcpHttpTransport({ url: config.url, headers: config.headers });\n\t\ttry {\n\t\t\tawait transport.request(\"initialize\", {\n\t\t\t\tprotocolVersion: \"2024-11-05\",\n\t\t\t\tcapabilities: {},\n\t\t\t\tclientInfo: { name: \"agent-forge-mcp-pool\", version: \"0.1.0\" },\n\t\t\t});\n\t\t\tawait transport.notify(\"notifications/initialized\");\n\t\t\tconst listing = (await transport.request(\"tools/list\")) as { tools?: unknown };\n\t\t\tif (!listing || !Array.isArray(listing.tools)) {\n\t\t\t\tthrow new Error(t(\"MCP tools/list result must contain tools[]\"));\n\t\t\t}\n\t\t\tfor (const tool of listing.tools) {\n\t\t\t\tconst candidate = tool as { name?: unknown; description?: unknown; inputSchema?: unknown };\n\t\t\t\tif (!candidate || typeof candidate.name !== \"string\" || !candidate.name) {\n\t\t\t\t\tthrow new Error(t(\"MCP tool requires a non-empty name\"));\n\t\t\t\t}\n\t\t\t\tapi.registerTool({\n\t\t\t\t\tname: candidate.name,\n\t\t\t\t\tlabel: candidate.name,\n\t\t\t\t\tdescription:\n\t\t\t\t\t\ttypeof candidate.description === \"string\" ? candidate.description : `MCP tool: ${candidate.name}`,\n\t\t\t\t\tparameters:\n\t\t\t\t\t\tcandidate.inputSchema && typeof candidate.inputSchema === \"object\"\n\t\t\t\t\t\t\t? candidate.inputSchema\n\t\t\t\t\t\t\t: { type: \"object\", properties: {} },\n\t\t\t\t\texecute: async (toolCallId: string, params: unknown, signal?: AbortSignal) => {\n\t\t\t\t\t\t// Dual call convention: the session passes (toolCallId, params,\n\t\t\t\t\t\t// signal); the runtime's invokeTool passes the input as the\n\t\t\t\t\t\t// single first argument.\n\t\t\t\t\t\tconst singleArgCall = params === undefined && typeof toolCallId !== \"string\";\n\t\t\t\t\t\tconst input = singleArgCall ? toolCallId : params;\n\t\t\t\t\t\tconst result = await transport.request(\n\t\t\t\t\t\t\t\"tools/call\",\n\t\t\t\t\t\t\t{ name: candidate.name as string, arguments: input || {} },\n\t\t\t\t\t\t\tsingleArgCall ? undefined : { signal },\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn normalizeToolResult(result);\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tdispose() {\n\t\t\t\t\ttransport.close();\n\t\t\t\t},\n\t\t\t};\n\t\t} catch (error) {\n\t\t\ttransport.close();\n\t\t\tthrow error;\n\t\t}\n\t};\n}\n"]}
1
+ {"version":3,"file":"mcp-http.js","sourceRoot":"","sources":["../src/mcp-http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH;;;;;GAKG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,wBAAwB,CAAC;AA+D3C,MAAM,WAAW,GAAG,CAAC,KA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M,MAAM,GAAG,MAAM,SAAS,CAAC,OAAO,CACrC,YAAY,EACZ,EAAE,IAAI,EAAE,SAAS,CAAC,IAAc,EAAE,SAAS,EAAE,KAAK,IAAI,EAAE,EAAE,EAC1D,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CACtC,CAAC;wBACF,OAAO,mBAAmB,CAAC,MAAM,CAAC,CAAC;oBAAA,CACnC;iBACD,CAAC,CAAC;YACJ,CAAC;YACD,OAAO;gBACN,OAAO,GAAG;oBACT,SAAS,CAAC,KAAK,EAAE,CAAC;gBAAA,CAClB;aACD,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,SAAS,CAAC,KAAK,EAAE,CAAC;YAClB,MAAM,KAAK,CAAC;QACb,CAAC;IAAA,CACD,CAAC;AAAA,CACF","sourcesContent":["/**\n * MCP HTTP transport (4.3) — a streamable-HTTP MCP transport implementing the\n * same transport interface as the stdio plugin, plus observable retry.\n *\n * Retries apply ONLY to requests the server could not have started (connect\n * errors, 5xx, 429) — a completed response (any JSON-RPC reply) is never\n * re-sent, keeping calls idempotent from the caller's perspective. The same\n * idempotency rule makes post-send failures terminal: a response-body read\n * error, a per-request timeout, or a caller abort all mean the request\n * already reached the server, so they are reported once and never re-sent.\n * close() rejects every in-flight request and fails new ones immediately.\n * Every transport error, retry attempt, and reconnect is reported through the\n * `onEvent` callback so callers can observe what happened. CLI\n * productization is out of scope.\n */\n/**\n * Per-request options for MCP transports. Defined here rather than imported\n * from the mcp-stdio example so production src never depends on examples/\n * (统一修复轮 C reverse-dependency fix); structurally identical to the\n * example's own declaration, which stays self-contained.\n */\nimport { t } from \"@agent-forge/host/i18n\";\n\nexport interface McpRequestOptions {\n\tsignal?: AbortSignal;\n\ttimeoutMs?: number;\n}\n\nexport interface McpHttpTransportEventV1 {\n\treadonly kind: \"connect\" | \"transport_error\" | \"retry\" | \"reconnect\" | \"response\";\n\treadonly at: number;\n\treadonly detail: string;\n\treadonly attempt?: number;\n}\n\nexport interface McpHttpTransportOptionsV1 {\n\treadonly url: string;\n\treadonly timeoutMs?: number;\n\treadonly retryLimit?: number;\n\treadonly baseRetryMs?: number;\n\treadonly maxRetryMs?: number;\n\treadonly now?: () => number;\n\treadonly sleep?: (ms: number) => Promise<void> | void;\n\treadonly onEvent?: (event: McpHttpTransportEventV1) => void;\n\t/**\n\t * Extra request headers merged after the transport defaults on every\n\t * outbound request (initialize / notifications/initialized / tools/list /\n\t * tools/call), so user values can override the defaults — the\n\t * `Authorization: Bearer ...` case for hosted remote MCP servers. Values\n\t * are sent verbatim (never case-normalized). They may carry credentials:\n\t * the suite MCP pool materializes them into the generated plugin entry\n\t * below `<agentDir>/mcp/pool/`, which sits inside the same local-machine\n\t * data boundary as `auth.json` (docs/design/产品价值度量与数据边界登记.md\n\t * §2.1 本机数据).\n\t */\n\treadonly headers?: Readonly<Record<string, string>>;\n}\n\n/** Structurally compatible with the stdio plugin's transport interface. */\nexport interface McpHttpTransportV1 {\n\trequest(method: string, params?: unknown, options?: McpRequestOptions): Promise<unknown>;\n\tnotify(method: string, params?: unknown): Promise<void> | void;\n\tclose(): Promise<void> | void;\n\tevents(): readonly McpHttpTransportEventV1[];\n}\n\ninterface JsonRpcResponse {\n\tid?: number | string | null;\n\tresult?: unknown;\n\terror?: { code?: number; message?: string };\n}\n\n/**\n * One postOnce outcome. `connect_error` means the fetch call itself failed\n * before a response arrived (the server could not have started) and stays\n * retryable; `read_error` and `aborted` mean the request already reached the\n * server, so both are terminal and never re-sent.\n */\ntype PostOnceResult =\n\t| { status: number; text: string }\n\t| { status: \"connect_error\"; reason: string }\n\t| { status: \"read_error\"; reason: string }\n\t| { status: \"aborted\"; reason: string };\n\nconst formatError = (error: unknown): string =>\n\terror instanceof Error ? `${error.name}: ${error.message}` : String(error);\n\nexport function createMcpHttpTransport(options: McpHttpTransportOptionsV1): McpHttpTransportV1 {\n\tconst timeoutMs = options.timeoutMs ?? 10_000;\n\tconst retryLimit = options.retryLimit ?? 2;\n\tconst baseRetryMs = options.baseRetryMs ?? 100;\n\tconst maxRetryMs = options.maxRetryMs ?? 1_600;\n\tconst now = options.now ?? (() => Date.now());\n\tconst sleep = options.sleep ?? ((ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms)));\n\tconst events: McpHttpTransportEventV1[] = [];\n\tlet nextId = 1;\n\tlet closed = false;\n\n\tconst record = (event: McpHttpTransportEventV1): void => {\n\t\tevents.push(event);\n\t\toptions.onEvent?.(event);\n\t};\n\n\t/** Abort controllers for in-flight postWithRetry runs; close() aborts them all. */\n\tconst inFlight = new Set<AbortController>();\n\n\tconst closedError = (): Error => new Error(t(\"MCP HTTP transport is closed\"));\n\n\tconst postOnce = async (\n\t\tbody: string,\n\t\trequestOptions: McpRequestOptions | undefined,\n\t\tcloseSignal: AbortSignal,\n\t): Promise<PostOnceResult> => {\n\t\tif (requestOptions?.signal?.aborted) {\n\t\t\treturn { status: \"aborted\", reason: t(\"request aborted before it was sent\") };\n\t\t}\n\t\tconst controller = new AbortController();\n\t\tconst timer = setTimeout(() => controller.abort(), requestOptions?.timeoutMs ?? timeoutMs);\n\t\tconst signals: AbortSignal[] = [controller.signal, closeSignal];\n\t\tif (requestOptions?.signal) signals.push(requestOptions.signal);\n\t\ttry {\n\t\t\tconst response = await fetch(options.url, {\n\t\t\t\tmethod: \"POST\",\n\t\t\t\theaders: {\n\t\t\t\t\t\"content-type\": \"application/json\",\n\t\t\t\t\taccept: \"application/json, text/event-stream\",\n\t\t\t\t\t...(options.headers ?? {}),\n\t\t\t\t},\n\t\t\t\tbody,\n\t\t\t\tsignal: AbortSignal.any(signals),\n\t\t\t});\n\t\t\tlet text: string;\n\t\t\ttry {\n\t\t\t\ttext = await response.text();\n\t\t\t} catch (error) {\n\t\t\t\t// Response headers already arrived: the server may have started\n\t\t\t\t// executing, so a re-send could duplicate side effects.\n\t\t\t\treturn { status: \"read_error\", reason: formatError(error) };\n\t\t\t}\n\t\t\treturn { status: response.status, text };\n\t\t} catch (error) {\n\t\t\t// An abort means the request was already sent (per-request timeout,\n\t\t\t// caller signal, or close), so it must never be re-sent. Only a fetch\n\t\t\t// failure before any response stays classified as connect_error.\n\t\t\tif (controller.signal.aborted || requestOptions?.signal?.aborted) {\n\t\t\t\treturn { status: \"aborted\", reason: formatError(error) };\n\t\t\t}\n\t\t\treturn { status: \"connect_error\", reason: formatError(error) };\n\t\t} finally {\n\t\t\tclearTimeout(timer);\n\t\t}\n\t};\n\n\tconst postWithRetry = async (\n\t\tbody: string,\n\t\trequestOptions?: McpRequestOptions,\n\t): Promise<{ status: number; text: string }> => {\n\t\tconst closeController = new AbortController();\n\t\tinFlight.add(closeController);\n\t\ttry {\n\t\t\tfor (let attempt = 1; ; attempt += 1) {\n\t\t\t\tif (closed) throw closedError();\n\t\t\t\tconst response = await postOnce(body, requestOptions, closeController.signal);\n\t\t\t\tif (closed) throw closedError();\n\t\t\t\tif (response.status === \"read_error\" || response.status === \"aborted\") {\n\t\t\t\t\trecord({\n\t\t\t\t\t\tkind: \"transport_error\",\n\t\t\t\t\t\tat: now(),\n\t\t\t\t\t\tdetail: `${response.status}: ${response.reason}`,\n\t\t\t\t\t\tattempt,\n\t\t\t\t\t});\n\t\t\t\t\tthrow new Error(t(\"MCP HTTP transport error: {reason}\", { reason: response.reason }));\n\t\t\t\t}\n\t\t\t\tif (response.status !== \"connect_error\" && response.status < 500 && response.status !== 429) {\n\t\t\t\t\trecord({ kind: \"response\", at: now(), detail: `HTTP ${response.status}`, attempt });\n\t\t\t\t\treturn response;\n\t\t\t\t}\n\t\t\t\tconst reason = response.status === \"connect_error\" ? response.reason : `HTTP ${response.status}`;\n\t\t\t\tif (attempt > retryLimit) {\n\t\t\t\t\trecord({\n\t\t\t\t\t\tkind: \"transport_error\",\n\t\t\t\t\t\tat: now(),\n\t\t\t\t\t\tdetail: `giving up after ${attempt - 1} retries: ${reason}`,\n\t\t\t\t\t\tattempt,\n\t\t\t\t\t});\n\t\t\t\t\tthrow new Error(t(\"MCP HTTP transport error: {reason}\", { reason }));\n\t\t\t\t}\n\t\t\t\tconst waitedMs = Math.min(baseRetryMs * 2 ** (attempt - 1), maxRetryMs);\n\t\t\t\trecord({\n\t\t\t\t\tkind: \"retry\",\n\t\t\t\t\tat: now(),\n\t\t\t\t\tdetail: `attempt ${attempt} failed (${reason}); waiting ${waitedMs}ms`,\n\t\t\t\t\tattempt,\n\t\t\t\t});\n\t\t\t\tawait sleep(waitedMs);\n\t\t\t\tif (attempt === 1 && response.status === \"connect_error\") {\n\t\t\t\t\trecord({ kind: \"reconnect\", at: now(), detail: \"re-establishing HTTP connection\", attempt });\n\t\t\t\t}\n\t\t\t}\n\t\t} finally {\n\t\t\tinFlight.delete(closeController);\n\t\t}\n\t};\n\n\tconst rpc = async (method: string, params?: unknown, requestOptions?: McpRequestOptions): Promise<unknown> => {\n\t\tif (closed) throw closedError();\n\t\tconst id = nextId;\n\t\tnextId += 1;\n\t\tconst body = JSON.stringify({ jsonrpc: \"2.0\", id, method, ...(params === undefined ? {} : { params }) });\n\t\tconst response = await postWithRetry(body, requestOptions);\n\t\tif (response.status !== 200) {\n\t\t\tthrow new Error(t(\"MCP HTTP transport returned HTTP {status}\", { status: response.status }));\n\t\t}\n\t\tlet parsed: JsonRpcResponse;\n\t\ttry {\n\t\t\tparsed = JSON.parse(response.text) as JsonRpcResponse;\n\t\t} catch (error) {\n\t\t\tthrow new Error(\n\t\t\t\t// v8 ignore next -- JSON.parse 只会抛出 Error 对象\n\t\t\t\tt(\"MCP HTTP transport returned non-JSON body: {reason}\", {\n\t\t\t\t\treason: error instanceof Error ? error.message : String(error),\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t\tif (parsed.error !== undefined) {\n\t\t\tthrow new Error(\n\t\t\t\tt(\"MCP error {code}: {message}\", {\n\t\t\t\t\tcode: parsed.error.code ?? \"\",\n\t\t\t\t\tmessage: parsed.error.message ?? t(\"unknown error\"),\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t\treturn parsed.result;\n\t};\n\n\treturn {\n\t\tasync request(method, params, requestOptions) {\n\t\t\treturn rpc(method, params, requestOptions);\n\t\t},\n\t\tasync notify(method, params) {\n\t\t\tawait postWithRetry(\n\t\t\t\tJSON.stringify({ jsonrpc: \"2.0\", method, ...(params === undefined ? {} : { params }) }),\n\t\t\t\tundefined,\n\t\t\t);\n\t\t},\n\t\tasync close() {\n\t\t\tclosed = true;\n\t\t\t// Reject every in-flight request promptly: aborting its run makes the\n\t\t\t// pending fetch fail and the loop throw the closed error instead of\n\t\t\t// returning a late success or retrying after close.\n\t\t\tfor (const controller of inFlight) {\n\t\t\t\tcontroller.abort(closedError());\n\t\t\t}\n\t\t},\n\t\tevents() {\n\t\t\treturn Object.freeze([...events]);\n\t\t},\n\t};\n}\n\n/** Minimal api surface the HTTP server plugin relies on (capability registerTool). */\nexport interface McpHttpServerPluginApiV1 {\n\tregisterTool(definition: unknown): unknown;\n}\n\nfunction normalizeToolResult(result: unknown): { content: unknown[]; details?: unknown } {\n\tif (result && typeof result === \"object\" && Array.isArray((result as { content?: unknown }).content)) {\n\t\tconst { content, details } = result as { content: unknown[]; details?: unknown };\n\t\treturn { content, details };\n\t}\n\tif (result === undefined) return { content: [{ type: \"text\", text: \"\" }] };\n\treturn { content: [{ type: \"text\", text: JSON.stringify(result) }] };\n}\n\n/**\n * Configuration-driven entry for remote MCP servers: wires\n * createMcpHttpTransport into the same plugin shape as the generated stdio\n * bridge (initialize/tools/list handshake, one registerTool per remote tool,\n * dual call convention). Tool call policy stays host-owned; the plugin only\n * forwards requests and maps results. The suite MCP registration pool\n * materializes url-configured servers through this entry; optional `headers`\n * are forwarded verbatim to the transport (credential note there).\n */\nexport function createMcpHttpServerPlugin(config: {\n\turl: string;\n\t/** Forwarded to the transport verbatim; see McpHttpTransportOptionsV1.headers for the credential note. */\n\theaders?: Readonly<Record<string, string>>;\n}): (api: McpHttpServerPluginApiV1) => Promise<{ dispose(): void }> {\n\treturn async (api) => {\n\t\tconst transport = createMcpHttpTransport({ url: config.url, headers: config.headers });\n\t\ttry {\n\t\t\tawait transport.request(\"initialize\", {\n\t\t\t\tprotocolVersion: \"2024-11-05\",\n\t\t\t\tcapabilities: {},\n\t\t\t\tclientInfo: { name: \"agent-forge-mcp-pool\", version: \"0.1.0\" },\n\t\t\t});\n\t\t\tawait transport.notify(\"notifications/initialized\");\n\t\t\tconst listing = (await transport.request(\"tools/list\")) as { tools?: unknown };\n\t\t\tif (!listing || !Array.isArray(listing.tools)) {\n\t\t\t\tthrow new Error(t(\"MCP tools/list result must contain tools[]\"));\n\t\t\t}\n\t\t\tfor (const tool of listing.tools) {\n\t\t\t\tconst candidate = tool as { name?: unknown; description?: unknown; inputSchema?: unknown };\n\t\t\t\tif (!candidate || typeof candidate.name !== \"string\" || !candidate.name) {\n\t\t\t\t\tthrow new Error(t(\"MCP tool requires a non-empty name\"));\n\t\t\t\t}\n\t\t\t\tapi.registerTool({\n\t\t\t\t\tname: candidate.name,\n\t\t\t\t\tlabel: candidate.name,\n\t\t\t\t\tdescription:\n\t\t\t\t\t\ttypeof candidate.description === \"string\" ? candidate.description : `MCP tool: ${candidate.name}`,\n\t\t\t\t\tparameters:\n\t\t\t\t\t\tcandidate.inputSchema && typeof candidate.inputSchema === \"object\"\n\t\t\t\t\t\t\t? candidate.inputSchema\n\t\t\t\t\t\t\t: { type: \"object\", properties: {} },\n\t\t\t\t\texecute: async (toolCallId: string, params: unknown, signal?: AbortSignal) => {\n\t\t\t\t\t\t// Dual call convention: the session passes (toolCallId, params,\n\t\t\t\t\t\t// signal); the runtime's invokeTool passes the input as the\n\t\t\t\t\t\t// single first argument.\n\t\t\t\t\t\tconst singleArgCall = params === undefined && typeof toolCallId !== \"string\";\n\t\t\t\t\t\tconst input = singleArgCall ? toolCallId : params;\n\t\t\t\t\t\tconst result = await transport.request(\n\t\t\t\t\t\t\t\"tools/call\",\n\t\t\t\t\t\t\t{ name: candidate.name as string, arguments: input || {} },\n\t\t\t\t\t\t\tsingleArgCall ? undefined : { signal },\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn normalizeToolResult(result);\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tdispose() {\n\t\t\t\t\ttransport.close();\n\t\t\t\t},\n\t\t\t};\n\t\t} catch (error) {\n\t\t\ttransport.close();\n\t\t\tthrow error;\n\t\t}\n\t};\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "packageFormatVersion": 1,
3
3
  "id": "agent-forge.plugin.overflow-policy",
4
- "pluginVersion": "0.88.5",
4
+ "pluginVersion": "0.88.6",
5
5
  "apiVersion": "1",
6
6
  "minHostVersion": "0.88.0",
7
7
  "platform": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "agent-forge.plugin.overflow-policy",
3
- "version": "0.88.5",
3
+ "version": "0.88.6",
4
4
  "apiVersion": "1-draft",
5
5
  "entry": "./dist/entry.js",
6
6
  "hostVersion": ">=0.88.0",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "packageFormatVersion": 1,
3
3
  "id": "agent-forge.plugin.provider-failover",
4
- "pluginVersion": "0.88.5",
4
+ "pluginVersion": "0.88.6",
5
5
  "apiVersion": "1",
6
6
  "minHostVersion": "0.88.0",
7
7
  "platform": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "agent-forge.plugin.provider-failover",
3
- "version": "0.88.5",
3
+ "version": "0.88.6",
4
4
  "apiVersion": "1-draft",
5
5
  "entry": "./dist/entry.js",
6
6
  "hostVersion": ">=0.88.0"
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "packageFormatVersion": 1,
3
3
  "id": "agent-forge.plugin.retry-policy",
4
- "pluginVersion": "0.88.5",
4
+ "pluginVersion": "0.88.6",
5
5
  "apiVersion": "1",
6
6
  "minHostVersion": "0.88.0",
7
7
  "platform": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "id": "agent-forge.plugin.retry-policy",
3
- "version": "0.88.5",
3
+ "version": "0.88.6",
4
4
  "apiVersion": "1-draft",
5
5
  "entry": "./dist/entry.js",
6
6
  "hostVersion": ">=0.88.0",