operon-agents-core 0.1.0-alpha.0

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 (511) hide show
  1. package/LICENSE +55 -0
  2. package/README.md +7 -0
  3. package/dist/agent/agent.d.ts +65 -0
  4. package/dist/agent/agent.js +39 -0
  5. package/dist/agent/compose-hooks.d.ts +13 -0
  6. package/dist/agent/compose-hooks.js +197 -0
  7. package/dist/agent/concurrency.d.ts +22 -0
  8. package/dist/agent/concurrency.js +70 -0
  9. package/dist/agent/context-report.d.ts +60 -0
  10. package/dist/agent/context-report.js +45 -0
  11. package/dist/agent/graph.d.ts +48 -0
  12. package/dist/agent/graph.js +129 -0
  13. package/dist/agent/guardrail.d.ts +105 -0
  14. package/dist/agent/guardrail.js +314 -0
  15. package/dist/agent/handoff-executor.d.ts +21 -0
  16. package/dist/agent/handoff-executor.js +95 -0
  17. package/dist/agent/handoff.d.ts +42 -0
  18. package/dist/agent/handoff.js +70 -0
  19. package/dist/agent/index.d.ts +25 -0
  20. package/dist/agent/index.js +19 -0
  21. package/dist/agent/instruction-context.d.ts +33 -0
  22. package/dist/agent/instruction-context.js +100 -0
  23. package/dist/agent/pause.d.ts +12 -0
  24. package/dist/agent/pause.js +82 -0
  25. package/dist/agent/profile-builtins.d.ts +8 -0
  26. package/dist/agent/profile-builtins.js +130 -0
  27. package/dist/agent/profiles.d.ts +94 -0
  28. package/dist/agent/profiles.js +264 -0
  29. package/dist/agent/recovery.d.ts +10 -0
  30. package/dist/agent/recovery.js +151 -0
  31. package/dist/agent/run-support.d.ts +79 -0
  32. package/dist/agent/run-support.js +211 -0
  33. package/dist/agent/runner.d.ts +246 -0
  34. package/dist/agent/runner.js +786 -0
  35. package/dist/agent/session.d.ts +363 -0
  36. package/dist/agent/session.js +937 -0
  37. package/dist/agent/subagent-tools.d.ts +18 -0
  38. package/dist/agent/subagent-tools.js +650 -0
  39. package/dist/agent/subagent.d.ts +56 -0
  40. package/dist/agent/subagent.js +50 -0
  41. package/dist/agent/toolset.d.ts +24 -0
  42. package/dist/agent/toolset.js +112 -0
  43. package/dist/agent/workflow/index.d.ts +9 -0
  44. package/dist/agent/workflow/index.js +8 -0
  45. package/dist/agent/workflow/journal.d.ts +180 -0
  46. package/dist/agent/workflow/journal.js +224 -0
  47. package/dist/agent/workflow/manager.d.ts +27 -0
  48. package/dist/agent/workflow/manager.js +33 -0
  49. package/dist/agent/workflow/parse.d.ts +17 -0
  50. package/dist/agent/workflow/parse.js +174 -0
  51. package/dist/agent/workflow/prompt.d.ts +8 -0
  52. package/dist/agent/workflow/prompt.js +84 -0
  53. package/dist/agent/workflow/runtime.d.ts +64 -0
  54. package/dist/agent/workflow/runtime.js +380 -0
  55. package/dist/agent/workflow/sandbox.d.ts +35 -0
  56. package/dist/agent/workflow/sandbox.js +90 -0
  57. package/dist/agent/workflow/snapshot.d.ts +36 -0
  58. package/dist/agent/workflow/snapshot.js +9 -0
  59. package/dist/agent/workflow/structured.d.ts +35 -0
  60. package/dist/agent/workflow/structured.js +79 -0
  61. package/dist/agent/workflow/tool.d.ts +14 -0
  62. package/dist/agent/workflow/tool.js +569 -0
  63. package/dist/agent/workflow/types.d.ts +100 -0
  64. package/dist/agent/workflow/types.js +17 -0
  65. package/dist/agent/worktree.d.ts +38 -0
  66. package/dist/agent/worktree.js +56 -0
  67. package/dist/capabilities/assembler.d.ts +39 -0
  68. package/dist/capabilities/assembler.js +171 -0
  69. package/dist/capabilities/background/agent-task.d.ts +51 -0
  70. package/dist/capabilities/background/agent-task.js +101 -0
  71. package/dist/capabilities/background/command-task.d.ts +43 -0
  72. package/dist/capabilities/background/command-task.js +86 -0
  73. package/dist/capabilities/background/index.d.ts +20 -0
  74. package/dist/capabilities/background/index.js +57 -0
  75. package/dist/capabilities/background/manager.d.ts +194 -0
  76. package/dist/capabilities/background/manager.js +1131 -0
  77. package/dist/capabilities/background/persist-disk.d.ts +17 -0
  78. package/dist/capabilities/background/persist-disk.js +66 -0
  79. package/dist/capabilities/background/persist.d.ts +61 -0
  80. package/dist/capabilities/background/persist.js +117 -0
  81. package/dist/capabilities/background/question-task.d.ts +32 -0
  82. package/dist/capabilities/background/question-task.js +56 -0
  83. package/dist/capabilities/background/registrar.d.ts +12 -0
  84. package/dist/capabilities/background/registrar.js +9 -0
  85. package/dist/capabilities/background/swappable-sink.d.ts +20 -0
  86. package/dist/capabilities/background/swappable-sink.js +20 -0
  87. package/dist/capabilities/background/task.d.ts +114 -0
  88. package/dist/capabilities/background/task.js +20 -0
  89. package/dist/capabilities/background/tools.d.ts +6 -0
  90. package/dist/capabilities/background/tools.js +190 -0
  91. package/dist/capabilities/background/workflow-task.d.ts +48 -0
  92. package/dist/capabilities/background/workflow-task.js +91 -0
  93. package/dist/capabilities/capability-state.d.ts +13 -0
  94. package/dist/capabilities/capability-state.js +37 -0
  95. package/dist/capabilities/capability.d.ts +145 -0
  96. package/dist/capabilities/capability.js +2 -0
  97. package/dist/capabilities/compaction/full.d.ts +27 -0
  98. package/dist/capabilities/compaction/full.js +155 -0
  99. package/dist/capabilities/compaction/index.d.ts +17 -0
  100. package/dist/capabilities/compaction/index.js +145 -0
  101. package/dist/capabilities/compaction/instruction.d.ts +2 -0
  102. package/dist/capabilities/compaction/instruction.js +31 -0
  103. package/dist/capabilities/compaction/micro.d.ts +17 -0
  104. package/dist/capabilities/compaction/micro.js +57 -0
  105. package/dist/capabilities/compaction/service.d.ts +28 -0
  106. package/dist/capabilities/compaction/service.js +52 -0
  107. package/dist/capabilities/compaction/strategy.d.ts +43 -0
  108. package/dist/capabilities/compaction/strategy.js +116 -0
  109. package/dist/capabilities/compaction/tokens.d.ts +5 -0
  110. package/dist/capabilities/compaction/tokens.js +28 -0
  111. package/dist/capabilities/goal/goal-store.d.ts +69 -0
  112. package/dist/capabilities/goal/goal-store.js +172 -0
  113. package/dist/capabilities/goal/index.d.ts +6 -0
  114. package/dist/capabilities/goal/index.js +31 -0
  115. package/dist/capabilities/goal/injector.d.ts +9 -0
  116. package/dist/capabilities/goal/injector.js +79 -0
  117. package/dist/capabilities/goal/tools.d.ts +6 -0
  118. package/dist/capabilities/goal/tools.js +86 -0
  119. package/dist/capabilities/index.d.ts +25 -0
  120. package/dist/capabilities/index.js +22 -0
  121. package/dist/capabilities/injection.d.ts +44 -0
  122. package/dist/capabilities/injection.js +112 -0
  123. package/dist/capabilities/plan/index.d.ts +6 -0
  124. package/dist/capabilities/plan/index.js +25 -0
  125. package/dist/capabilities/plan/injector.d.ts +13 -0
  126. package/dist/capabilities/plan/injector.js +83 -0
  127. package/dist/capabilities/plan/plan-mode.d.ts +38 -0
  128. package/dist/capabilities/plan/plan-mode.js +113 -0
  129. package/dist/capabilities/plan/policies.d.ts +6 -0
  130. package/dist/capabilities/plan/policies.js +89 -0
  131. package/dist/capabilities/plan/tools.d.ts +15 -0
  132. package/dist/capabilities/plan/tools.js +87 -0
  133. package/dist/capabilities/skills/flow-provider.d.ts +6 -0
  134. package/dist/capabilities/skills/flow-provider.js +50 -0
  135. package/dist/capabilities/skills/index.d.ts +43 -0
  136. package/dist/capabilities/skills/index.js +48 -0
  137. package/dist/capabilities/skills/injector.d.ts +11 -0
  138. package/dist/capabilities/skills/injector.js +27 -0
  139. package/dist/capabilities/skills/parser.d.ts +36 -0
  140. package/dist/capabilities/skills/parser.js +334 -0
  141. package/dist/capabilities/skills/registry.d.ts +33 -0
  142. package/dist/capabilities/skills/registry.js +118 -0
  143. package/dist/capabilities/skills/scanner.d.ts +26 -0
  144. package/dist/capabilities/skills/scanner.js +154 -0
  145. package/dist/capabilities/skills/service.d.ts +39 -0
  146. package/dist/capabilities/skills/service.js +68 -0
  147. package/dist/capabilities/skills/skill-tool.d.ts +13 -0
  148. package/dist/capabilities/skills/skill-tool.js +72 -0
  149. package/dist/capabilities/skills/types.d.ts +62 -0
  150. package/dist/capabilities/skills/types.js +26 -0
  151. package/dist/capabilities/task/index.d.ts +23 -0
  152. package/dist/capabilities/task/index.js +38 -0
  153. package/dist/capabilities/task/injector.d.ts +9 -0
  154. package/dist/capabilities/task/injector.js +62 -0
  155. package/dist/capabilities/task/persist-disk.d.ts +19 -0
  156. package/dist/capabilities/task/persist-disk.js +84 -0
  157. package/dist/capabilities/task/persist.d.ts +52 -0
  158. package/dist/capabilities/task/persist.js +84 -0
  159. package/dist/capabilities/task/task-store.d.ts +44 -0
  160. package/dist/capabilities/task/task-store.js +106 -0
  161. package/dist/capabilities/task/tools.d.ts +12 -0
  162. package/dist/capabilities/task/tools.js +164 -0
  163. package/dist/capabilities/todo/index.d.ts +8 -0
  164. package/dist/capabilities/todo/index.js +21 -0
  165. package/dist/capabilities/todo/injector.d.ts +9 -0
  166. package/dist/capabilities/todo/injector.js +68 -0
  167. package/dist/capabilities/todo/todo-store.d.ts +19 -0
  168. package/dist/capabilities/todo/todo-store.js +36 -0
  169. package/dist/capabilities/todo/tools.d.ts +6 -0
  170. package/dist/capabilities/todo/tools.js +70 -0
  171. package/dist/capabilities/tool-provider.d.ts +12 -0
  172. package/dist/capabilities/tool-provider.js +20 -0
  173. package/dist/capabilities/user-hooks/engine.d.ts +22 -0
  174. package/dist/capabilities/user-hooks/engine.js +105 -0
  175. package/dist/capabilities/user-hooks/index.d.ts +13 -0
  176. package/dist/capabilities/user-hooks/index.js +126 -0
  177. package/dist/capabilities/user-hooks/types.d.ts +26 -0
  178. package/dist/capabilities/user-hooks/types.js +19 -0
  179. package/dist/capabilities/workflow/index.d.ts +16 -0
  180. package/dist/capabilities/workflow/index.js +15 -0
  181. package/dist/commands/index.d.ts +31 -0
  182. package/dist/commands/index.js +318 -0
  183. package/dist/config/config-store.d.ts +29 -0
  184. package/dist/config/config-store.js +103 -0
  185. package/dist/config/file-source.d.ts +40 -0
  186. package/dist/config/file-source.js +78 -0
  187. package/dist/config/flags.d.ts +13 -0
  188. package/dist/config/flags.js +25 -0
  189. package/dist/config/index.d.ts +17 -0
  190. package/dist/config/index.js +10 -0
  191. package/dist/config/merge.d.ts +5 -0
  192. package/dist/config/merge.js +57 -0
  193. package/dist/config/model-catalog.d.ts +17 -0
  194. package/dist/config/model-catalog.js +37 -0
  195. package/dist/config/paths.d.ts +31 -0
  196. package/dist/config/paths.js +28 -0
  197. package/dist/config/provider-manager.d.ts +57 -0
  198. package/dist/config/provider-manager.js +344 -0
  199. package/dist/config/resolver.d.ts +40 -0
  200. package/dist/config/resolver.js +52 -0
  201. package/dist/config/schema.d.ts +389 -0
  202. package/dist/config/schema.js +132 -0
  203. package/dist/events/events.d.ts +348 -0
  204. package/dist/events/events.js +146 -0
  205. package/dist/events/index.d.ts +10 -0
  206. package/dist/events/index.js +5 -0
  207. package/dist/events/projection.d.ts +207 -0
  208. package/dist/events/projection.js +438 -0
  209. package/dist/events/publisher.d.ts +48 -0
  210. package/dist/events/publisher.js +404 -0
  211. package/dist/events/redacting-sink.d.ts +11 -0
  212. package/dist/events/redacting-sink.js +31 -0
  213. package/dist/home.d.ts +16 -0
  214. package/dist/home.js +20 -0
  215. package/dist/index.d.ts +22 -0
  216. package/dist/index.js +22 -0
  217. package/dist/internal.d.ts +33 -0
  218. package/dist/internal.js +29 -0
  219. package/dist/llm/auth.d.ts +22 -0
  220. package/dist/llm/auth.js +112 -0
  221. package/dist/llm/capability.d.ts +13 -0
  222. package/dist/llm/capability.js +45 -0
  223. package/dist/llm/define-model.d.ts +110 -0
  224. package/dist/llm/define-model.js +252 -0
  225. package/dist/llm/errors.d.ts +33 -0
  226. package/dist/llm/errors.js +154 -0
  227. package/dist/llm/index.d.ts +14 -0
  228. package/dist/llm/index.js +8 -0
  229. package/dist/llm/model.d.ts +43 -0
  230. package/dist/llm/model.js +9 -0
  231. package/dist/llm/retry.d.ts +35 -0
  232. package/dist/llm/retry.js +160 -0
  233. package/dist/llm/runtime.d.ts +25 -0
  234. package/dist/llm/runtime.js +38 -0
  235. package/dist/logging/diagnostics.d.ts +21 -0
  236. package/dist/logging/diagnostics.js +46 -0
  237. package/dist/logging/index.d.ts +11 -0
  238. package/dist/logging/index.js +7 -0
  239. package/dist/logging/logger.d.ts +25 -0
  240. package/dist/logging/logger.js +54 -0
  241. package/dist/logging/paths.d.ts +11 -0
  242. package/dist/logging/paths.js +20 -0
  243. package/dist/logging/policy.d.ts +5 -0
  244. package/dist/logging/policy.js +19 -0
  245. package/dist/logging/redact.d.ts +10 -0
  246. package/dist/logging/redact.js +95 -0
  247. package/dist/logging/sinks.d.ts +67 -0
  248. package/dist/logging/sinks.js +117 -0
  249. package/dist/loop/context.d.ts +69 -0
  250. package/dist/loop/context.js +129 -0
  251. package/dist/loop/errors.d.ts +8 -0
  252. package/dist/loop/errors.js +27 -0
  253. package/dist/loop/events.d.ts +14 -0
  254. package/dist/loop/events.js +2 -0
  255. package/dist/loop/index.d.ts +10 -0
  256. package/dist/loop/index.js +7 -0
  257. package/dist/loop/interruption.d.ts +118 -0
  258. package/dist/loop/interruption.js +191 -0
  259. package/dist/loop/run-turn.d.ts +54 -0
  260. package/dist/loop/run-turn.js +203 -0
  261. package/dist/loop/scheduler.d.ts +18 -0
  262. package/dist/loop/scheduler.js +71 -0
  263. package/dist/loop/steer.d.ts +122 -0
  264. package/dist/loop/steer.js +209 -0
  265. package/dist/loop/tool-call.d.ts +41 -0
  266. package/dist/loop/tool-call.js +326 -0
  267. package/dist/loop/turn-step.d.ts +57 -0
  268. package/dist/loop/turn-step.js +298 -0
  269. package/dist/loop/types.d.ts +217 -0
  270. package/dist/loop/types.js +2 -0
  271. package/dist/loop/usage.d.ts +6 -0
  272. package/dist/loop/usage.js +44 -0
  273. package/dist/mcp/auth-tool.d.ts +12 -0
  274. package/dist/mcp/auth-tool.js +92 -0
  275. package/dist/mcp/capability.d.ts +7 -0
  276. package/dist/mcp/capability.js +91 -0
  277. package/dist/mcp/config-loader.d.ts +28 -0
  278. package/dist/mcp/config-loader.js +115 -0
  279. package/dist/mcp/filter.d.ts +18 -0
  280. package/dist/mcp/filter.js +35 -0
  281. package/dist/mcp/index.d.ts +23 -0
  282. package/dist/mcp/index.js +13 -0
  283. package/dist/mcp/manager.d.ts +51 -0
  284. package/dist/mcp/manager.js +412 -0
  285. package/dist/mcp/mock-transport.d.ts +40 -0
  286. package/dist/mcp/mock-transport.js +68 -0
  287. package/dist/mcp/oauth/callback-server.d.ts +14 -0
  288. package/dist/mcp/oauth/callback-server.js +122 -0
  289. package/dist/mcp/oauth/index.d.ts +9 -0
  290. package/dist/mcp/oauth/index.js +5 -0
  291. package/dist/mcp/oauth/provider.d.ts +39 -0
  292. package/dist/mcp/oauth/provider.js +121 -0
  293. package/dist/mcp/oauth/service.d.ts +34 -0
  294. package/dist/mcp/oauth/service.js +130 -0
  295. package/dist/mcp/oauth/store.d.ts +40 -0
  296. package/dist/mcp/oauth/store.js +134 -0
  297. package/dist/mcp/output.d.ts +12 -0
  298. package/dist/mcp/output.js +110 -0
  299. package/dist/mcp/provider.d.ts +7 -0
  300. package/dist/mcp/provider.js +56 -0
  301. package/dist/mcp/sdk-transport.d.ts +25 -0
  302. package/dist/mcp/sdk-transport.js +228 -0
  303. package/dist/mcp/server.d.ts +77 -0
  304. package/dist/mcp/server.js +120 -0
  305. package/dist/mcp/tool-naming.d.ts +4 -0
  306. package/dist/mcp/tool-naming.js +26 -0
  307. package/dist/mcp/types.d.ts +75 -0
  308. package/dist/mcp/types.js +2 -0
  309. package/dist/net/index.d.ts +3 -0
  310. package/dist/net/index.js +2 -0
  311. package/dist/net/proxy.d.ts +16 -0
  312. package/dist/net/proxy.js +42 -0
  313. package/dist/permission/auto-approver/index.d.ts +3 -0
  314. package/dist/permission/auto-approver/index.js +3 -0
  315. package/dist/permission/auto-approver/llm-auto-approver.d.ts +53 -0
  316. package/dist/permission/auto-approver/llm-auto-approver.js +122 -0
  317. package/dist/permission/auto-approver/prompts-data.d.ts +9 -0
  318. package/dist/permission/auto-approver/prompts-data.js +155 -0
  319. package/dist/permission/auto-approver/prompts.d.ts +18 -0
  320. package/dist/permission/auto-approver/prompts.js +40 -0
  321. package/dist/permission/auto-approver/transcript.d.ts +22 -0
  322. package/dist/permission/auto-approver/transcript.js +75 -0
  323. package/dist/permission/auto-approver/xml.d.ts +5 -0
  324. package/dist/permission/auto-approver/xml.js +25 -0
  325. package/dist/permission/index.d.ts +7 -0
  326. package/dist/permission/index.js +5 -0
  327. package/dist/permission/manager.d.ts +74 -0
  328. package/dist/permission/manager.js +162 -0
  329. package/dist/permission/matches-rule.d.ts +27 -0
  330. package/dist/permission/matches-rule.js +54 -0
  331. package/dist/permission/policies.d.ts +14 -0
  332. package/dist/permission/policies.js +233 -0
  333. package/dist/permission/types.d.ts +84 -0
  334. package/dist/permission/types.js +2 -0
  335. package/dist/plugins/archive.d.ts +3 -0
  336. package/dist/plugins/archive.js +58 -0
  337. package/dist/plugins/github-resolver.d.ts +13 -0
  338. package/dist/plugins/github-resolver.js +20 -0
  339. package/dist/plugins/hooks.d.ts +28 -0
  340. package/dist/plugins/hooks.js +296 -0
  341. package/dist/plugins/index.d.ts +23 -0
  342. package/dist/plugins/index.js +23 -0
  343. package/dist/plugins/injector.d.ts +11 -0
  344. package/dist/plugins/injector.js +32 -0
  345. package/dist/plugins/manager.d.ts +37 -0
  346. package/dist/plugins/manager.js +330 -0
  347. package/dist/plugins/manifest.d.ts +9 -0
  348. package/dist/plugins/manifest.js +234 -0
  349. package/dist/plugins/marketplace.d.ts +85 -0
  350. package/dist/plugins/marketplace.js +205 -0
  351. package/dist/plugins/source.d.ts +23 -0
  352. package/dist/plugins/source.js +87 -0
  353. package/dist/plugins/store.d.ts +20 -0
  354. package/dist/plugins/store.js +30 -0
  355. package/dist/plugins/types.d.ts +118 -0
  356. package/dist/plugins/types.js +5 -0
  357. package/dist/protocol/index.d.ts +4 -0
  358. package/dist/protocol/index.js +2 -0
  359. package/dist/protocol/tool-schema.d.ts +6 -0
  360. package/dist/protocol/tool-schema.js +2 -0
  361. package/dist/store/blob-store.d.ts +45 -0
  362. package/dist/store/blob-store.js +120 -0
  363. package/dist/store/catalog-store.d.ts +32 -0
  364. package/dist/store/catalog-store.js +73 -0
  365. package/dist/store/disk-store.d.ts +58 -0
  366. package/dist/store/disk-store.js +369 -0
  367. package/dist/store/index.d.ts +23 -0
  368. package/dist/store/index.js +15 -0
  369. package/dist/store/lock.d.ts +86 -0
  370. package/dist/store/lock.js +104 -0
  371. package/dist/store/log-store.d.ts +89 -0
  372. package/dist/store/log-store.js +296 -0
  373. package/dist/store/migrate.d.ts +26 -0
  374. package/dist/store/migrate.js +32 -0
  375. package/dist/store/origin.d.ts +89 -0
  376. package/dist/store/origin.js +16 -0
  377. package/dist/store/pg.d.ts +90 -0
  378. package/dist/store/pg.js +344 -0
  379. package/dist/store/redacting-store.d.ts +21 -0
  380. package/dist/store/redacting-store.js +46 -0
  381. package/dist/store/redis.d.ts +89 -0
  382. package/dist/store/redis.js +370 -0
  383. package/dist/store/repository.d.ts +150 -0
  384. package/dist/store/repository.js +508 -0
  385. package/dist/store/session-catalog.d.ts +32 -0
  386. package/dist/store/session-catalog.js +117 -0
  387. package/dist/store/storage.d.ts +27 -0
  388. package/dist/store/storage.js +54 -0
  389. package/dist/store/store.d.ts +262 -0
  390. package/dist/store/store.js +129 -0
  391. package/dist/store/workdir-key.d.ts +4 -0
  392. package/dist/store/workdir-key.js +28 -0
  393. package/dist/tool/access.d.ts +37 -0
  394. package/dist/tool/access.js +79 -0
  395. package/dist/tool/ask.d.ts +22 -0
  396. package/dist/tool/ask.js +38 -0
  397. package/dist/tool/background.d.ts +109 -0
  398. package/dist/tool/background.js +39 -0
  399. package/dist/tool/builtin/ask-user-question.d.ts +2 -0
  400. package/dist/tool/builtin/ask-user-question.js +175 -0
  401. package/dist/tool/builtin/bash.d.ts +2 -0
  402. package/dist/tool/builtin/bash.js +407 -0
  403. package/dist/tool/builtin/edit.d.ts +2 -0
  404. package/dist/tool/builtin/edit.js +202 -0
  405. package/dist/tool/builtin/glob.d.ts +3 -0
  406. package/dist/tool/builtin/glob.js +260 -0
  407. package/dist/tool/builtin/grep.d.ts +2 -0
  408. package/dist/tool/builtin/grep.js +574 -0
  409. package/dist/tool/builtin/line-endings.d.ts +10 -0
  410. package/dist/tool/builtin/line-endings.js +41 -0
  411. package/dist/tool/builtin/read.d.ts +28 -0
  412. package/dist/tool/builtin/read.js +498 -0
  413. package/dist/tool/builtin/write.d.ts +2 -0
  414. package/dist/tool/builtin/write.js +179 -0
  415. package/dist/tool/define.d.ts +46 -0
  416. package/dist/tool/define.js +45 -0
  417. package/dist/tool/file-freshness.d.ts +81 -0
  418. package/dist/tool/file-freshness.js +67 -0
  419. package/dist/tool/filesystem-tools.d.ts +16 -0
  420. package/dist/tool/filesystem-tools.js +19 -0
  421. package/dist/tool/git-context.d.ts +20 -0
  422. package/dist/tool/git-context.js +114 -0
  423. package/dist/tool/index.d.ts +37 -0
  424. package/dist/tool/index.js +34 -0
  425. package/dist/tool/machine-base.d.ts +138 -0
  426. package/dist/tool/machine-base.js +388 -0
  427. package/dist/tool/machine-local.d.ts +35 -0
  428. package/dist/tool/machine-local.js +316 -0
  429. package/dist/tool/machine-null.d.ts +36 -0
  430. package/dist/tool/machine-null.js +64 -0
  431. package/dist/tool/machine-ssh.d.ts +86 -0
  432. package/dist/tool/machine-ssh.js +576 -0
  433. package/dist/tool/machine.d.ts +333 -0
  434. package/dist/tool/machine.js +15 -0
  435. package/dist/tool/policies/path-access.d.ts +48 -0
  436. package/dist/tool/policies/path-access.js +186 -0
  437. package/dist/tool/policies/sensitive.d.ts +3 -0
  438. package/dist/tool/policies/sensitive.js +60 -0
  439. package/dist/tool/questions.d.ts +40 -0
  440. package/dist/tool/questions.js +8 -0
  441. package/dist/tool/search/activation.d.ts +13 -0
  442. package/dist/tool/search/activation.js +31 -0
  443. package/dist/tool/search/deferral.d.ts +37 -0
  444. package/dist/tool/search/deferral.js +128 -0
  445. package/dist/tool/search/search-tool.d.ts +9 -0
  446. package/dist/tool/search/search-tool.js +62 -0
  447. package/dist/tool/shell-env.d.ts +9 -0
  448. package/dist/tool/shell-env.js +34 -0
  449. package/dist/tool/support/bash-destructive.d.ts +24 -0
  450. package/dist/tool/support/bash-destructive.js +63 -0
  451. package/dist/tool/support/bash-paths.d.ts +7 -0
  452. package/dist/tool/support/bash-paths.js +247 -0
  453. package/dist/tool/support/bash-read-only.d.ts +8 -0
  454. package/dist/tool/support/bash-read-only.js +165 -0
  455. package/dist/tool/support/bash-rule-match.d.ts +20 -0
  456. package/dist/tool/support/bash-rule-match.js +191 -0
  457. package/dist/tool/support/file-type.d.ts +10 -0
  458. package/dist/tool/support/file-type.js +149 -0
  459. package/dist/tool/support/git-worktree.d.ts +10 -0
  460. package/dist/tool/support/git-worktree.js +63 -0
  461. package/dist/tool/support/image-compress.d.ts +69 -0
  462. package/dist/tool/support/image-compress.js +265 -0
  463. package/dist/tool/support/machine-ops.d.ts +34 -0
  464. package/dist/tool/support/machine-ops.js +34 -0
  465. package/dist/tool/support/path-glob-match.d.ts +12 -0
  466. package/dist/tool/support/path-glob-match.js +84 -0
  467. package/dist/tool/support/result-builder.d.ts +27 -0
  468. package/dist/tool/support/result-builder.js +108 -0
  469. package/dist/tool/support/rg-locator.d.ts +20 -0
  470. package/dist/tool/support/rg-locator.js +42 -0
  471. package/dist/tool/support/ripgrep-run.d.ts +65 -0
  472. package/dist/tool/support/ripgrep-run.js +40 -0
  473. package/dist/tool/support/rule-match.d.ts +6 -0
  474. package/dist/tool/support/rule-match.js +23 -0
  475. package/dist/tool/support/tool-path.d.ts +8 -0
  476. package/dist/tool/support/tool-path.js +28 -0
  477. package/dist/tool/support/workspace.d.ts +5 -0
  478. package/dist/tool/support/workspace.js +2 -0
  479. package/dist/tool/types.d.ts +131 -0
  480. package/dist/tool/types.js +2 -0
  481. package/dist/tool/web/fetch-url.d.ts +4 -0
  482. package/dist/tool/web/fetch-url.js +61 -0
  483. package/dist/tool/web/index.d.ts +11 -0
  484. package/dist/tool/web/index.js +7 -0
  485. package/dist/tool/web/providers/direct-fetch.d.ts +33 -0
  486. package/dist/tool/web/providers/direct-fetch.js +198 -0
  487. package/dist/tool/web/providers/firecrawl.d.ts +16 -0
  488. package/dist/tool/web/providers/firecrawl.js +59 -0
  489. package/dist/tool/web/providers/tavily.d.ts +14 -0
  490. package/dist/tool/web/providers/tavily.js +43 -0
  491. package/dist/tool/web/types.d.ts +41 -0
  492. package/dist/tool/web/types.js +7 -0
  493. package/dist/tool/web/web-search.d.ts +4 -0
  494. package/dist/tool/web/web-search.js +68 -0
  495. package/dist/tool/workspace-spec.d.ts +74 -0
  496. package/dist/tool/workspace-spec.js +177 -0
  497. package/dist/tracing/bridge.d.ts +7 -0
  498. package/dist/tracing/bridge.js +171 -0
  499. package/dist/tracing/index.d.ts +9 -0
  500. package/dist/tracing/index.js +5 -0
  501. package/dist/tracing/otel.d.ts +38 -0
  502. package/dist/tracing/otel.js +221 -0
  503. package/dist/tracing/processor.d.ts +47 -0
  504. package/dist/tracing/processor.js +94 -0
  505. package/dist/tracing/spans.d.ts +94 -0
  506. package/dist/tracing/spans.js +56 -0
  507. package/dist/ui/ai-sdk.d.ts +114 -0
  508. package/dist/ui/ai-sdk.js +175 -0
  509. package/dist/ui/index.d.ts +2 -0
  510. package/dist/ui/index.js +2 -0
  511. package/package.json +101 -0
@@ -0,0 +1,110 @@
1
+ export const MCP_MAX_OUTPUT_CHARS = 100_000;
2
+ const MCP_OUTPUT_TRUNCATED_TEXT = `\n\n[Output truncated: exceeded ${MCP_MAX_OUTPUT_CHARS} character limit. Use pagination or more specific queries to get remaining content.]`;
3
+ export const MCP_MAX_IMAGE_PART_BYTES = 10 * 1024 * 1024;
4
+ const MCP_MAX_IMAGE_PART_CHARS = Math.ceil((MCP_MAX_IMAGE_PART_BYTES * 4) / 3);
5
+ function imageTooLargeNotice(urlLength) {
6
+ const approxMb = ((urlLength * 3) / 4 / (1024 * 1024)).toFixed(1);
7
+ const capMb = String(MCP_MAX_IMAGE_PART_BYTES / (1024 * 1024));
8
+ return { type: "text", text: `[image dropped: ~${approxMb} MB exceeds ${capMb} MB per-part limit. Try a smaller resource.]` };
9
+ }
10
+ function mediaNote(kind) {
11
+ return { type: "text", text: `[${kind} content omitted: not representable in this tool-result content model.]` };
12
+ }
13
+ export function convertMcpContentBlock(block) {
14
+ if (block.type === "text" && typeof block.text === "string") {
15
+ return { type: "text", text: block.text };
16
+ }
17
+ if (block.type === "image" && typeof block.data === "string") {
18
+ return { type: "image", data: block.data, mimeType: block.mimeType ?? "image/png" };
19
+ }
20
+ if (block.type === "audio")
21
+ return mediaNote("audio");
22
+ // EmbeddedResource: payload nested under `resource` (text or blob).
23
+ if (block.type === "resource" && block.resource) {
24
+ const res = block.resource;
25
+ if (typeof res.text === "string")
26
+ return { type: "text", text: res.text };
27
+ if (typeof res.blob === "string") {
28
+ const mimeType = res.mimeType ?? "application/octet-stream";
29
+ if (mimeType.startsWith("image/"))
30
+ return { type: "image", data: res.blob, mimeType };
31
+ if (mimeType.startsWith("audio/"))
32
+ return mediaNote("audio");
33
+ if (mimeType.startsWith("video/"))
34
+ return mediaNote("video");
35
+ return null;
36
+ }
37
+ return null;
38
+ }
39
+ // ResourceLink: a URL reference (our ImageContent needs inline base64, not a URL).
40
+ if (block.type === "resource_link" && typeof block.uri === "string") {
41
+ return { type: "text", text: `[resource: ${block.uri}${block.mimeType ? ` (${block.mimeType})` : ""}]` };
42
+ }
43
+ return null;
44
+ }
45
+ export function mcpResultToContent(result, qualifiedToolName) {
46
+ const converted = [];
47
+ for (const block of result.content) {
48
+ const part = convertMcpContentBlock(block);
49
+ if (part !== null)
50
+ converted.push(part);
51
+ }
52
+ const wrapped = wrapMediaOnly(converted, qualifiedToolName);
53
+ const limited = applyOutputLimits(wrapped);
54
+ const content = limited.length > 0 ? limited : [{ type: "text", text: "" }];
55
+ return { content, isError: result.isError === true };
56
+ }
57
+ function wrapMediaOnly(parts, qualifiedToolName) {
58
+ const hasMedia = parts.some((p) => p.type === "image");
59
+ const hasNonEmptyText = parts.some((p) => p.type === "text" && p.text.length > 0);
60
+ if (!hasMedia || hasNonEmptyText)
61
+ return [...parts];
62
+ return [
63
+ { type: "text", text: `<mcp_tool_result name="${qualifiedToolName}">` },
64
+ ...parts,
65
+ { type: "text", text: "</mcp_tool_result>" },
66
+ ];
67
+ }
68
+ function applyOutputLimits(parts) {
69
+ let remaining = MCP_MAX_OUTPUT_CHARS;
70
+ let textTruncated = false;
71
+ const out = [];
72
+ for (const part of parts) {
73
+ if (part.type === "text") {
74
+ if (remaining <= 0) {
75
+ textTruncated = true;
76
+ continue;
77
+ }
78
+ if (part.text.length > remaining) {
79
+ out.push({ type: "text", text: part.text.slice(0, remaining) });
80
+ remaining = 0;
81
+ textTruncated = true;
82
+ }
83
+ else {
84
+ out.push(part);
85
+ remaining -= part.text.length;
86
+ }
87
+ continue;
88
+ }
89
+ // image: per-part byte cap, independent of the text budget.
90
+ if (part.data.length > MCP_MAX_IMAGE_PART_CHARS) {
91
+ out.push(imageTooLargeNotice(part.data.length));
92
+ continue;
93
+ }
94
+ out.push(part);
95
+ }
96
+ if (textTruncated)
97
+ appendTruncationNotice(out);
98
+ return out;
99
+ }
100
+ function appendTruncationNotice(out) {
101
+ for (let i = out.length - 1; i >= 0; i--) {
102
+ const candidate = out[i];
103
+ if (candidate?.type === "text") {
104
+ out[i] = { type: "text", text: candidate.text + MCP_OUTPUT_TRUNCATED_TEXT };
105
+ return;
106
+ }
107
+ }
108
+ out.push({ type: "text", text: MCP_OUTPUT_TRUNCATED_TEXT });
109
+ }
110
+ //# sourceMappingURL=output.js.map
@@ -0,0 +1,7 @@
1
+ import { type Tool } from "../index.ts";
2
+ import type { MCPServer } from "./server.ts";
3
+ import type { ToolProvider } from "../index.ts";
4
+ import type { MCPTool } from "./types.ts";
5
+ export declare function wrapMcpTool(server: MCPServer, def: MCPTool): Tool;
6
+ export declare function mcpToolProvider(server: MCPServer): ToolProvider;
7
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1,56 @@
1
+ import { ToolAccesses } from "../index.js";
2
+ import { applyMcpToolFilter } from "./filter.js";
3
+ import { qualifyMcpToolName } from "./tool-naming.js";
4
+ import { mcpResultToContent } from "./output.js";
5
+ function asArgs(raw) {
6
+ return raw !== null && typeof raw === "object" ? raw : null;
7
+ }
8
+ async function defaultErrorText(server, toolName, error) {
9
+ if (server.errorFunction === null)
10
+ throw error;
11
+ if (server.errorFunction)
12
+ return server.errorFunction({ error, toolName, serverName: server.name });
13
+ return `MCP tool "${toolName}" on server "${server.name}" failed: ${error instanceof Error ? error.message : String(error)}`;
14
+ }
15
+ export function wrapMcpTool(server, def) {
16
+ const qualifiedName = qualifyMcpToolName(server.name, def.name);
17
+ const rawName = def.name;
18
+ return {
19
+ schema: {
20
+ name: qualifiedName,
21
+ description: def.description ?? `MCP tool "${rawName}" from server "${server.name}".`,
22
+ parameters: def.inputSchema ?? { type: "object", properties: {} },
23
+ },
24
+ resolve: (rawArgs) => {
25
+ const args = asArgs(rawArgs);
26
+ return {
27
+ approvalRule: qualifiedName,
28
+ // MCP side effects are opaque → serialize against everything (conservative).
29
+ accesses: ToolAccesses.all(),
30
+ display: { kind: "mcp_call", title: qualifiedName, detail: def.description },
31
+ run: async (ctx) => {
32
+ try {
33
+ const result = await server.callTool(rawName, args, { signal: ctx.signal });
34
+ const { content, isError } = mcpResultToContent(result, qualifiedName);
35
+ return { content, isError };
36
+ }
37
+ catch (error) {
38
+ const text = await defaultErrorText(server, rawName, error);
39
+ return { content: [{ type: "text", text }], isError: true };
40
+ }
41
+ },
42
+ };
43
+ },
44
+ };
45
+ }
46
+ export function mcpToolProvider(server) {
47
+ return {
48
+ id: `mcp:${server.name}`,
49
+ listTools: async (ctx) => {
50
+ const raw = await server.listTools();
51
+ const filtered = await applyMcpToolFilter(server.toolFilter, raw, { serverName: server.name, ctx });
52
+ return filtered.map((def) => wrapMcpTool(server, def));
53
+ },
54
+ };
55
+ }
56
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1,25 @@
1
+ import type { OAuthClientProvider } from "@modelcontextprotocol/sdk/client/auth.js";
2
+ import type { MCPTransport } from "./types.ts";
3
+ export interface MCPStdioConfig {
4
+ readonly name: string;
5
+ readonly command: string;
6
+ readonly args?: readonly string[];
7
+ readonly env?: Record<string, string>;
8
+ readonly cwd?: string;
9
+ readonly toolTimeoutMs?: number;
10
+ }
11
+ export declare function mcpStdioTransport(config: MCPStdioConfig): MCPTransport;
12
+ export declare function mergeStdioEnv(configEnv?: Record<string, string>): Record<string, string>;
13
+ export interface MCPHttpConfig {
14
+ readonly name: string;
15
+ readonly url: string;
16
+ readonly headers?: Record<string, string>;
17
+ readonly bearerTokenEnvVar?: string;
18
+ readonly toolTimeoutMs?: number;
19
+ readonly oauthProvider?: OAuthClientProvider;
20
+ readonly envLookup?: (name: string) => string | undefined;
21
+ }
22
+ export declare function mcpStreamableHttpTransport(config: MCPHttpConfig): MCPTransport;
23
+ export declare function isTerminalTransportError(error: Error): boolean;
24
+ export declare function buildMcpHttpHeaders(config: MCPHttpConfig, envLookup: (name: string) => string | undefined): Record<string, string> | undefined;
25
+ //# sourceMappingURL=sdk-transport.d.ts.map
@@ -0,0 +1,228 @@
1
+ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
2
+ import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
3
+ import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
4
+ const CLIENT_INFO = { name: "agent-framework-mcp", version: "0.0.0" };
5
+ const STDERR_BUFFER_CAPACITY = 4 * 1024;
6
+ class SdkMcpTransport {
7
+ name;
8
+ cfg;
9
+ client;
10
+ stderrBuffer = new BoundedTail(STDERR_BUFFER_CAPACITY);
11
+ started = false;
12
+ closed = false;
13
+ // Flips true only after `connect()` resolves AND the caller has not torn down mid-startup;
14
+ // the hooks gate on it so a handshake-phase death rides `connect()` rejecting instead.
15
+ ready = false;
16
+ hooksInstalled = false;
17
+ listener;
18
+ lastError;
19
+ // Buffered when the transport drops before a listener registers; replayed on registration.
20
+ pending;
21
+ // Latch so `onerror` + `onclose` for the same failure don't double-fire the listener.
22
+ fired = false;
23
+ constructor(cfg) {
24
+ this.name = cfg.name;
25
+ this.cfg = cfg;
26
+ }
27
+ async connect() {
28
+ if (this.closed)
29
+ throw new Error(`MCP transport "${this.name}" is closed.`);
30
+ if (this.started)
31
+ return;
32
+ this.started = true;
33
+ const sdkTransport = this.cfg.makeSdkTransport();
34
+ if (this.cfg.captureStderr)
35
+ this.attachStderr(sdkTransport);
36
+ const client = new Client(CLIENT_INFO, { capabilities: {} });
37
+ this.client = client;
38
+ // Hooks BEFORE the handshake so an onclose firing between handshake completion and our
39
+ // wiring is never lost; the hooks themselves gate on `ready`.
40
+ this.installHooks(client);
41
+ try {
42
+ await client.connect(sdkTransport);
43
+ }
44
+ catch (error) {
45
+ await this.closeStarted();
46
+ throw error;
47
+ }
48
+ if (this.closed) {
49
+ await this.closeStarted();
50
+ throw new Error(`MCP transport "${this.name}" was closed during startup.`);
51
+ }
52
+ this.ready = true;
53
+ }
54
+ async close() {
55
+ if (this.closed)
56
+ return;
57
+ this.closed = true;
58
+ await this.closeStarted();
59
+ }
60
+ async listTools() {
61
+ const res = await this.requireClient().listTools();
62
+ return res.tools;
63
+ }
64
+ async ping(options) {
65
+ await this.requireClient().ping(buildRequestOptions(options?.timeoutMs, options?.signal));
66
+ }
67
+ async callTool(toolName, args, options) {
68
+ return this.requireClient().callTool({ name: toolName, arguments: args, _meta: options?.meta ?? null }, undefined, buildRequestOptions(this.cfg.toolTimeoutMs, options?.signal));
69
+ }
70
+ async listResources(params) {
71
+ return this.requireClient().listResources(params);
72
+ }
73
+ async readResource(uri) {
74
+ return this.requireClient().readResource({ uri });
75
+ }
76
+ onUnexpectedClose(listener) {
77
+ this.listener = listener;
78
+ const pending = this.pending;
79
+ if (pending !== undefined) {
80
+ this.pending = undefined;
81
+ listener(pending);
82
+ }
83
+ }
84
+ stderrSnapshot() {
85
+ return this.stderrBuffer.snapshot();
86
+ }
87
+ requireClient() {
88
+ if (!this.client)
89
+ throw new Error(`MCP transport "${this.name}" is not connected.`);
90
+ return this.client;
91
+ }
92
+ async closeStarted() {
93
+ if (!this.started)
94
+ return;
95
+ this.started = false;
96
+ const c = this.client;
97
+ this.client = undefined;
98
+ await c?.close();
99
+ }
100
+ attachStderr(sdkTransport) {
101
+ // `stderr:'pipe'` returns a PassThrough immediately (SDK), so this drain is wired before
102
+ // the child spawns. We MUST drain it — an undrained full pipe can block the child.
103
+ const stderr = sdkTransport.stderr;
104
+ stderr?.on("data", (chunk) => {
105
+ this.stderrBuffer.push(typeof chunk === "string" ? chunk : chunk.toString("utf8"));
106
+ });
107
+ }
108
+ installHooks(client) {
109
+ if (this.hooksInstalled)
110
+ return;
111
+ this.hooksInstalled = true;
112
+ client.onclose = () => {
113
+ if (this.closed)
114
+ return; // intentional close
115
+ if (!this.ready)
116
+ return; // handshake-phase death → connect() rejects
117
+ const stderr = this.stderrBuffer.snapshot();
118
+ this.fireUnexpectedClose({ error: this.lastError, stderr: stderr.length > 0 ? stderr : undefined });
119
+ };
120
+ client.onerror = (error) => {
121
+ // Errors are informational on their own; `onclose` is what says the transport is gone.
122
+ // For http there is no onclose for remote drops, so a terminal error stands in.
123
+ this.lastError = error;
124
+ if (this.closed)
125
+ return;
126
+ if (!this.ready)
127
+ return;
128
+ if (this.cfg.isTerminalError?.(error))
129
+ this.fireUnexpectedClose({ error });
130
+ };
131
+ }
132
+ fireUnexpectedClose(reason) {
133
+ if (this.fired)
134
+ return;
135
+ this.fired = true;
136
+ if (this.listener !== undefined)
137
+ this.listener(reason);
138
+ else
139
+ this.pending = reason;
140
+ }
141
+ }
142
+ class BoundedTail {
143
+ buffer = "";
144
+ capacity;
145
+ constructor(capacity) {
146
+ this.capacity = capacity;
147
+ }
148
+ push(chunk) {
149
+ this.buffer += chunk;
150
+ if (this.buffer.length > this.capacity) {
151
+ this.buffer = this.buffer.slice(this.buffer.length - this.capacity);
152
+ }
153
+ }
154
+ snapshot() {
155
+ return this.buffer;
156
+ }
157
+ }
158
+ function buildRequestOptions(toolTimeoutMs, signal) {
159
+ if (toolTimeoutMs === undefined && signal === undefined)
160
+ return undefined;
161
+ const out = {};
162
+ if (toolTimeoutMs !== undefined)
163
+ out.timeout = toolTimeoutMs;
164
+ if (signal !== undefined)
165
+ out.signal = signal;
166
+ return out;
167
+ }
168
+ export function mcpStdioTransport(config) {
169
+ return new SdkMcpTransport({
170
+ name: config.name,
171
+ captureStderr: true,
172
+ ...(config.toolTimeoutMs !== undefined ? { toolTimeoutMs: config.toolTimeoutMs } : {}),
173
+ makeSdkTransport: () => new StdioClientTransport({
174
+ command: config.command,
175
+ ...(config.args !== undefined ? { args: [...config.args] } : {}),
176
+ env: mergeStdioEnv(config.env),
177
+ ...(config.cwd !== undefined ? { cwd: config.cwd } : {}),
178
+ stderr: "pipe",
179
+ }),
180
+ });
181
+ }
182
+ export function mergeStdioEnv(configEnv) {
183
+ const merged = {};
184
+ for (const [key, value] of Object.entries(process.env)) {
185
+ if (value !== undefined)
186
+ merged[key] = value;
187
+ }
188
+ if (configEnv !== undefined)
189
+ Object.assign(merged, configEnv);
190
+ return merged;
191
+ }
192
+ export function mcpStreamableHttpTransport(config) {
193
+ const envLookup = config.envLookup ?? ((name) => process.env[name]);
194
+ const headers = buildMcpHttpHeaders(config, envLookup);
195
+ return new SdkMcpTransport({
196
+ name: config.name,
197
+ captureStderr: false,
198
+ isTerminalError: isTerminalTransportError,
199
+ ...(config.toolTimeoutMs !== undefined ? { toolTimeoutMs: config.toolTimeoutMs } : {}),
200
+ makeSdkTransport: () => new StreamableHTTPClientTransport(new URL(config.url), {
201
+ ...(headers !== undefined ? { requestInit: { headers } } : {}),
202
+ ...(config.oauthProvider !== undefined ? { authProvider: config.oauthProvider } : {}),
203
+ }),
204
+ });
205
+ }
206
+ export function isTerminalTransportError(error) {
207
+ if (error.name === "UnauthorizedError")
208
+ return true;
209
+ if (/Maximum reconnection attempts/i.test(error.message))
210
+ return true;
211
+ return false;
212
+ }
213
+ export function buildMcpHttpHeaders(config, envLookup) {
214
+ const headers = { ...config.headers };
215
+ if (config.bearerTokenEnvVar !== undefined) {
216
+ const token = envLookup(config.bearerTokenEnvVar);
217
+ if (token === undefined || token.length === 0) {
218
+ throw new Error(`MCP HTTP bearer token env var "${config.bearerTokenEnvVar}" is not set or is empty.`);
219
+ }
220
+ for (const key of Object.keys(headers)) {
221
+ if (key.toLowerCase() === "authorization")
222
+ delete headers[key];
223
+ }
224
+ headers["Authorization"] = `Bearer ${token}`;
225
+ }
226
+ return Object.keys(headers).length > 0 ? headers : undefined;
227
+ }
228
+ //# sourceMappingURL=sdk-transport.js.map
@@ -0,0 +1,77 @@
1
+ import type { MCPListResourcesResult, MCPReadResourceResult, MCPTool, MCPToolResult, MCPTransport, MCPCallToolOptions, MCPPingOptions, UnexpectedCloseListener } from "./types.ts";
2
+ import type { MCPToolFilter } from "./filter.ts";
3
+ export type MCPToolErrorFunction = (args: {
4
+ error: unknown;
5
+ toolName: string;
6
+ serverName: string;
7
+ }) => string | Promise<string>;
8
+ export interface MCPServer {
9
+ readonly name: string;
10
+ cacheToolsList: boolean;
11
+ toolFilter?: MCPToolFilter;
12
+ errorFunction?: MCPToolErrorFunction | null;
13
+ connect(): Promise<void>;
14
+ close(): Promise<void>;
15
+ ping(options?: MCPPingOptions): Promise<void>;
16
+ listTools(): Promise<readonly MCPTool[]>;
17
+ callTool(toolName: string, args: Record<string, unknown> | null, options?: MCPCallToolOptions): Promise<MCPToolResult>;
18
+ invalidateToolsCache(): Promise<void>;
19
+ readonly connected: boolean;
20
+ onUnexpectedClose?(listener: UnexpectedCloseListener): void;
21
+ stderrSnapshot?(): string;
22
+ }
23
+ export interface MCPServerWithResources extends MCPServer {
24
+ listResources(params?: {
25
+ cursor?: string;
26
+ }): Promise<MCPListResourcesResult>;
27
+ readResource(uri: string): Promise<MCPReadResourceResult>;
28
+ }
29
+ export interface MCPServerOptions {
30
+ readonly name: string;
31
+ readonly transport: MCPTransport;
32
+ /**
33
+ * Cache the tool list instead of re-listing on every use. Default true, matching
34
+ * `serverFromConfig`/`mcpServersCapability` (the path real deployments load servers
35
+ * through): the toolset is rebuilt once per turn, so an uncached server pays a round trip
36
+ * per turn in the critical path ahead of the model request.
37
+ *
38
+ * Refresh is manual — `invalidateToolsCache()`. Nothing listens for
39
+ * `notifications/tools/list_changed` yet, so a server that adds tools mid-session needs
40
+ * that call (or `cacheToolsList: false`) to be noticed.
41
+ */
42
+ readonly cacheToolsList?: boolean;
43
+ readonly toolFilter?: MCPToolFilter;
44
+ readonly errorFunction?: MCPToolErrorFunction | null;
45
+ readonly startupTimeoutMs?: number;
46
+ }
47
+ export declare const DEFAULT_MCP_STARTUP_TIMEOUT_MS = 30000;
48
+ export declare function hasResources(server: MCPServer): server is MCPServerWithResources;
49
+ export declare class TransportMCPServer implements MCPServerWithResources {
50
+ readonly name: string;
51
+ cacheToolsList: boolean;
52
+ toolFilter?: MCPToolFilter;
53
+ errorFunction?: MCPToolErrorFunction | null;
54
+ private readonly transport;
55
+ private readonly startupTimeoutMs;
56
+ private cachedTools;
57
+ private isConnected;
58
+ private readonly closeListeners;
59
+ private transportWatchInstalled;
60
+ constructor(options: MCPServerOptions);
61
+ get connected(): boolean;
62
+ connect(): Promise<void>;
63
+ private onTransportDrop;
64
+ onUnexpectedClose(listener: UnexpectedCloseListener): void;
65
+ stderrSnapshot(): string;
66
+ close(): Promise<void>;
67
+ ping(options?: MCPPingOptions): Promise<void>;
68
+ listTools(): Promise<readonly MCPTool[]>;
69
+ callTool(toolName: string, args: Record<string, unknown> | null, options?: MCPCallToolOptions): Promise<MCPToolResult>;
70
+ invalidateToolsCache(): Promise<void>;
71
+ listResources(params?: {
72
+ cursor?: string;
73
+ }): Promise<MCPListResourcesResult>;
74
+ readResource(uri: string): Promise<MCPReadResourceResult>;
75
+ }
76
+ export declare function withTimeout<T>(promise: Promise<T>, timeoutMs: number, label: string, onTimeout?: () => void): Promise<T>;
77
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1,120 @@
1
+ export const DEFAULT_MCP_STARTUP_TIMEOUT_MS = 30_000;
2
+ export function hasResources(server) {
3
+ const t = server;
4
+ return typeof t.listResources === "function" && typeof t.readResource === "function";
5
+ }
6
+ export class TransportMCPServer {
7
+ name;
8
+ cacheToolsList;
9
+ toolFilter;
10
+ errorFunction;
11
+ transport;
12
+ startupTimeoutMs;
13
+ cachedTools;
14
+ isConnected = false;
15
+ closeListeners = new Set();
16
+ transportWatchInstalled = false;
17
+ constructor(options) {
18
+ this.name = options.name;
19
+ this.transport = options.transport;
20
+ this.cacheToolsList = options.cacheToolsList ?? true;
21
+ this.toolFilter = options.toolFilter;
22
+ this.errorFunction = options.errorFunction;
23
+ this.startupTimeoutMs = options.startupTimeoutMs ?? DEFAULT_MCP_STARTUP_TIMEOUT_MS;
24
+ }
25
+ get connected() {
26
+ return this.isConnected;
27
+ }
28
+ async connect() {
29
+ if (this.isConnected)
30
+ return;
31
+ // Own the transport's single close listener and re-broadcast: a self-drop flips us to
32
+ // disconnected (so `listTools` throws → tools absent) AND notifies the capability.
33
+ if (!this.transportWatchInstalled && this.transport.onUnexpectedClose) {
34
+ this.transportWatchInstalled = true;
35
+ this.transport.onUnexpectedClose((reason) => this.onTransportDrop(reason));
36
+ }
37
+ // Bound the handshake: a hung connect must machine as a failure, not stall the session.
38
+ await withTimeout(this.transport.connect(), this.startupTimeoutMs, this.name, () => {
39
+ void this.transport.close().catch(() => undefined);
40
+ });
41
+ this.isConnected = true;
42
+ }
43
+ onTransportDrop(reason) {
44
+ this.isConnected = false;
45
+ this.cachedTools = undefined;
46
+ for (const listener of this.closeListeners) {
47
+ try {
48
+ listener(reason);
49
+ }
50
+ catch {
51
+ // a subscriber fault must not break the drop fan-out
52
+ }
53
+ }
54
+ }
55
+ onUnexpectedClose(listener) {
56
+ this.closeListeners.add(listener);
57
+ }
58
+ stderrSnapshot() {
59
+ return this.transport.stderrSnapshot?.() ?? "";
60
+ }
61
+ async close() {
62
+ if (!this.isConnected)
63
+ return;
64
+ this.isConnected = false;
65
+ this.cachedTools = undefined;
66
+ await this.transport.close();
67
+ }
68
+ async ping(options) {
69
+ if (!this.isConnected)
70
+ throw new Error(`MCP server "${this.name}" is not connected.`);
71
+ if (!this.transport.ping)
72
+ return;
73
+ await this.transport.ping(options);
74
+ }
75
+ async listTools() {
76
+ if (!this.isConnected)
77
+ throw new Error(`MCP server "${this.name}" is not connected.`);
78
+ if (this.cacheToolsList && this.cachedTools !== undefined)
79
+ return this.cachedTools;
80
+ const tools = await this.transport.listTools();
81
+ if (this.cacheToolsList)
82
+ this.cachedTools = tools;
83
+ return tools;
84
+ }
85
+ async callTool(toolName, args, options) {
86
+ if (!this.isConnected)
87
+ throw new Error(`MCP server "${this.name}" is not connected.`);
88
+ return this.transport.callTool(toolName, args, options);
89
+ }
90
+ async invalidateToolsCache() {
91
+ this.cachedTools = undefined;
92
+ }
93
+ async listResources(params) {
94
+ if (!this.transport.listResources)
95
+ throw new Error(`MCP server "${this.name}" does not expose resources.`);
96
+ return this.transport.listResources(params);
97
+ }
98
+ async readResource(uri) {
99
+ if (!this.transport.readResource)
100
+ throw new Error(`MCP server "${this.name}" does not expose resources.`);
101
+ return this.transport.readResource(uri);
102
+ }
103
+ }
104
+ export async function withTimeout(promise, timeoutMs, label, onTimeout) {
105
+ let timer;
106
+ try {
107
+ return await new Promise((resolve, reject) => {
108
+ timer = setTimeout(() => {
109
+ onTimeout?.();
110
+ reject(new Error(`MCP server "${label}" timed out after ${timeoutMs}ms.`));
111
+ }, timeoutMs);
112
+ promise.then(resolve, reject);
113
+ });
114
+ }
115
+ finally {
116
+ if (timer !== undefined)
117
+ clearTimeout(timer);
118
+ }
119
+ }
120
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1,4 @@
1
+ export declare function sanitizeMcpNamePart(part: string): string;
2
+ export declare function isMcpToolName(name: string): boolean;
3
+ export declare function qualifyMcpToolName(serverName: string, toolName: string): string;
4
+ //# sourceMappingURL=tool-naming.d.ts.map
@@ -0,0 +1,26 @@
1
+ const MCP_NAME_PREFIX = "mcp__";
2
+ const MCP_NAME_SEPARATOR = "__";
3
+ const MAX_QUALIFIED_LENGTH = 64;
4
+ export function sanitizeMcpNamePart(part) {
5
+ return part.replaceAll(/[^a-zA-Z0-9_-]/g, "_").replaceAll(/_+/g, "_");
6
+ }
7
+ export function isMcpToolName(name) {
8
+ return name.startsWith(MCP_NAME_PREFIX);
9
+ }
10
+ export function qualifyMcpToolName(serverName, toolName) {
11
+ const full = `${MCP_NAME_PREFIX}${sanitizeMcpNamePart(serverName)}${MCP_NAME_SEPARATOR}${sanitizeMcpNamePart(toolName)}`;
12
+ if (full.length <= MAX_QUALIFIED_LENGTH)
13
+ return full;
14
+ const hash = stableHash8(full);
15
+ const head = full.slice(0, MAX_QUALIFIED_LENGTH - hash.length - 1);
16
+ return `${head}_${hash}`;
17
+ }
18
+ function stableHash8(input) {
19
+ let hash = 0x811c9dc5;
20
+ for (let i = 0; i < input.length; i++) {
21
+ hash ^= input.codePointAt(i);
22
+ hash = Math.trunc(Math.imul(hash, 0x01000193));
23
+ }
24
+ return (hash >>> 0).toString(16).padStart(8, "0");
25
+ }
26
+ //# sourceMappingURL=tool-naming.js.map