@strands-agents/sdk 0.5.0 → 0.7.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 (486) hide show
  1. package/README.md +64 -0
  2. package/dist/src/__fixtures__/agent-helpers.d.ts +37 -4
  3. package/dist/src/__fixtures__/agent-helpers.d.ts.map +1 -1
  4. package/dist/src/__fixtures__/agent-helpers.js +31 -4
  5. package/dist/src/__fixtures__/agent-helpers.js.map +1 -1
  6. package/dist/src/__fixtures__/metrics-helpers.d.ts +55 -0
  7. package/dist/src/__fixtures__/metrics-helpers.d.ts.map +1 -0
  8. package/dist/src/__fixtures__/metrics-helpers.js +57 -0
  9. package/dist/src/__fixtures__/metrics-helpers.js.map +1 -0
  10. package/dist/src/__fixtures__/mock-message-model.d.ts +8 -4
  11. package/dist/src/__fixtures__/mock-message-model.d.ts.map +1 -1
  12. package/dist/src/__fixtures__/mock-message-model.js +25 -7
  13. package/dist/src/__fixtures__/mock-message-model.js.map +1 -1
  14. package/dist/src/__fixtures__/mock-meter.d.ts +32 -0
  15. package/dist/src/__fixtures__/mock-meter.d.ts.map +1 -0
  16. package/dist/src/__fixtures__/mock-meter.js +47 -0
  17. package/dist/src/__fixtures__/mock-meter.js.map +1 -0
  18. package/dist/src/__fixtures__/mock-plugin.d.ts +13 -0
  19. package/dist/src/__fixtures__/mock-plugin.d.ts.map +1 -0
  20. package/dist/src/__fixtures__/{mock-hook-provider.js → mock-plugin.js} +8 -5
  21. package/dist/src/__fixtures__/mock-plugin.js.map +1 -0
  22. package/dist/src/__fixtures__/mock-storage-provider.d.ts +5 -0
  23. package/dist/src/__fixtures__/mock-storage-provider.d.ts.map +1 -1
  24. package/dist/src/__fixtures__/mock-storage-provider.js +23 -6
  25. package/dist/src/__fixtures__/mock-storage-provider.js.map +1 -1
  26. package/dist/src/__fixtures__/slim-types.d.ts +2 -1
  27. package/dist/src/__fixtures__/slim-types.d.ts.map +1 -1
  28. package/dist/src/__fixtures__/tool-helpers.d.ts.map +1 -1
  29. package/dist/src/__fixtures__/tool-helpers.js +5 -2
  30. package/dist/src/__fixtures__/tool-helpers.js.map +1 -1
  31. package/dist/src/__tests__/index.test.js +21 -0
  32. package/dist/src/__tests__/index.test.js.map +1 -1
  33. package/dist/src/__tests__/mcp.test.js +45 -15
  34. package/dist/src/__tests__/mcp.test.js.map +1 -1
  35. package/dist/src/__tests__/mime.test.d.ts +2 -0
  36. package/dist/src/__tests__/mime.test.d.ts.map +1 -0
  37. package/dist/src/__tests__/mime.test.js +83 -0
  38. package/dist/src/__tests__/mime.test.js.map +1 -0
  39. package/dist/src/__tests__/state-store.test.d.ts +2 -0
  40. package/dist/src/__tests__/state-store.test.d.ts.map +1 -0
  41. package/dist/src/__tests__/{app-state.test.js → state-store.test.js} +86 -51
  42. package/dist/src/__tests__/state-store.test.js.map +1 -0
  43. package/dist/src/a2a/__tests__/a2a-agent.test.d.ts +2 -0
  44. package/dist/src/a2a/__tests__/a2a-agent.test.d.ts.map +1 -0
  45. package/dist/src/a2a/__tests__/a2a-agent.test.js +364 -0
  46. package/dist/src/a2a/__tests__/a2a-agent.test.js.map +1 -0
  47. package/dist/src/a2a/__tests__/adapters.test.d.ts +2 -0
  48. package/dist/src/a2a/__tests__/adapters.test.d.ts.map +1 -0
  49. package/dist/src/a2a/__tests__/adapters.test.js +151 -0
  50. package/dist/src/a2a/__tests__/adapters.test.js.map +1 -0
  51. package/dist/src/a2a/__tests__/executor.test.d.ts +2 -0
  52. package/dist/src/a2a/__tests__/executor.test.d.ts.map +1 -0
  53. package/dist/src/a2a/__tests__/executor.test.js +196 -0
  54. package/dist/src/a2a/__tests__/executor.test.js.map +1 -0
  55. package/dist/src/a2a/__tests__/server.test.d.ts +2 -0
  56. package/dist/src/a2a/__tests__/server.test.d.ts.map +1 -0
  57. package/dist/src/a2a/__tests__/server.test.js +51 -0
  58. package/dist/src/a2a/__tests__/server.test.js.map +1 -0
  59. package/dist/src/a2a/__tests__/server.test.node.d.ts +2 -0
  60. package/dist/src/a2a/__tests__/server.test.node.d.ts.map +1 -0
  61. package/dist/src/a2a/__tests__/server.test.node.js +110 -0
  62. package/dist/src/a2a/__tests__/server.test.node.js.map +1 -0
  63. package/dist/src/a2a/a2a-agent.d.ts +132 -0
  64. package/dist/src/a2a/a2a-agent.d.ts.map +1 -0
  65. package/dist/src/a2a/a2a-agent.js +255 -0
  66. package/dist/src/a2a/a2a-agent.js.map +1 -0
  67. package/dist/src/a2a/adapters.d.ts +27 -0
  68. package/dist/src/a2a/adapters.d.ts.map +1 -0
  69. package/dist/src/a2a/adapters.js +175 -0
  70. package/dist/src/a2a/adapters.js.map +1 -0
  71. package/dist/src/a2a/events.d.ts +42 -0
  72. package/dist/src/a2a/events.d.ts.map +1 -0
  73. package/dist/src/a2a/events.js +35 -0
  74. package/dist/src/a2a/events.js.map +1 -0
  75. package/dist/src/a2a/executor.d.ts +57 -0
  76. package/dist/src/a2a/executor.d.ts.map +1 -0
  77. package/dist/src/a2a/executor.js +130 -0
  78. package/dist/src/a2a/executor.js.map +1 -0
  79. package/dist/src/a2a/express-server.d.ts +67 -0
  80. package/dist/src/a2a/express-server.d.ts.map +1 -0
  81. package/dist/src/a2a/express-server.js +95 -0
  82. package/dist/src/a2a/express-server.js.map +1 -0
  83. package/dist/src/a2a/index.d.ts +16 -0
  84. package/dist/src/a2a/index.d.ts.map +1 -0
  85. package/dist/src/a2a/index.js +16 -0
  86. package/dist/src/a2a/index.js.map +1 -0
  87. package/dist/src/a2a/logging.d.ts +8 -0
  88. package/dist/src/a2a/logging.d.ts.map +1 -0
  89. package/dist/src/a2a/logging.js +15 -0
  90. package/dist/src/a2a/logging.js.map +1 -0
  91. package/dist/src/a2a/server.d.ts +67 -0
  92. package/dist/src/a2a/server.d.ts.map +1 -0
  93. package/dist/src/a2a/server.js +67 -0
  94. package/dist/src/a2a/server.js.map +1 -0
  95. package/dist/src/agent/__tests__/agent.hook.test.js +87 -51
  96. package/dist/src/agent/__tests__/agent.hook.test.js.map +1 -1
  97. package/dist/src/agent/__tests__/agent.test.js +176 -101
  98. package/dist/src/agent/__tests__/agent.test.js.map +1 -1
  99. package/dist/src/agent/__tests__/agent.tracer.test.js +10 -10
  100. package/dist/src/agent/__tests__/agent.tracer.test.js.map +1 -1
  101. package/dist/src/agent/__tests__/snapshot.test.js +11 -11
  102. package/dist/src/agent/__tests__/snapshot.test.js.map +1 -1
  103. package/dist/src/agent/agent.d.ts +71 -58
  104. package/dist/src/agent/agent.d.ts.map +1 -1
  105. package/dist/src/agent/agent.js +177 -93
  106. package/dist/src/agent/agent.js.map +1 -1
  107. package/dist/src/agent/snapshot.d.ts.map +1 -1
  108. package/dist/src/agent/snapshot.js +3 -2
  109. package/dist/src/agent/snapshot.js.map +1 -1
  110. package/dist/src/conversation-manager/__tests__/conversation-manager.test.d.ts +2 -0
  111. package/dist/src/conversation-manager/__tests__/conversation-manager.test.d.ts.map +1 -0
  112. package/dist/src/conversation-manager/__tests__/conversation-manager.test.js +100 -0
  113. package/dist/src/conversation-manager/__tests__/conversation-manager.test.js.map +1 -0
  114. package/dist/src/conversation-manager/__tests__/null-conversation-manager.test.js +26 -10
  115. package/dist/src/conversation-manager/__tests__/null-conversation-manager.test.js.map +1 -1
  116. package/dist/src/conversation-manager/__tests__/sliding-window-conversation-manager.test.js +84 -21
  117. package/dist/src/conversation-manager/__tests__/sliding-window-conversation-manager.test.js.map +1 -1
  118. package/dist/src/conversation-manager/conversation-manager.d.ts +87 -0
  119. package/dist/src/conversation-manager/conversation-manager.d.ts.map +1 -0
  120. package/dist/src/conversation-manager/conversation-manager.js +59 -0
  121. package/dist/src/conversation-manager/conversation-manager.js.map +1 -0
  122. package/dist/src/conversation-manager/index.d.ts +1 -0
  123. package/dist/src/conversation-manager/index.d.ts.map +1 -1
  124. package/dist/src/conversation-manager/index.js +1 -0
  125. package/dist/src/conversation-manager/index.js.map +1 -1
  126. package/dist/src/conversation-manager/null-conversation-manager.d.ts +12 -8
  127. package/dist/src/conversation-manager/null-conversation-manager.d.ts.map +1 -1
  128. package/dist/src/conversation-manager/null-conversation-manager.js +13 -7
  129. package/dist/src/conversation-manager/null-conversation-manager.js.map +1 -1
  130. package/dist/src/conversation-manager/sliding-window-conversation-manager.d.ts +28 -19
  131. package/dist/src/conversation-manager/sliding-window-conversation-manager.d.ts.map +1 -1
  132. package/dist/src/conversation-manager/sliding-window-conversation-manager.js +44 -36
  133. package/dist/src/conversation-manager/sliding-window-conversation-manager.js.map +1 -1
  134. package/dist/src/errors.d.ts +6 -0
  135. package/dist/src/errors.d.ts.map +1 -1
  136. package/dist/src/errors.js +9 -0
  137. package/dist/src/errors.js.map +1 -1
  138. package/dist/src/hooks/__tests__/events.test.js +2 -0
  139. package/dist/src/hooks/__tests__/events.test.js.map +1 -1
  140. package/dist/src/hooks/__tests__/registry.test.js +10 -154
  141. package/dist/src/hooks/__tests__/registry.test.js.map +1 -1
  142. package/dist/src/hooks/events.d.ts +60 -44
  143. package/dist/src/hooks/events.d.ts.map +1 -1
  144. package/dist/src/hooks/events.js +11 -11
  145. package/dist/src/hooks/events.js.map +1 -1
  146. package/dist/src/hooks/index.d.ts +4 -4
  147. package/dist/src/hooks/index.d.ts.map +1 -1
  148. package/dist/src/hooks/index.js +2 -2
  149. package/dist/src/hooks/registry.d.ts +1 -32
  150. package/dist/src/hooks/registry.d.ts.map +1 -1
  151. package/dist/src/hooks/registry.js +1 -47
  152. package/dist/src/hooks/registry.js.map +1 -1
  153. package/dist/src/hooks/types.d.ts +0 -31
  154. package/dist/src/hooks/types.d.ts.map +1 -1
  155. package/dist/src/index.d.ts +30 -15
  156. package/dist/src/index.d.ts.map +1 -1
  157. package/dist/src/index.js +21 -8
  158. package/dist/src/index.js.map +1 -1
  159. package/dist/src/mcp.d.ts +38 -0
  160. package/dist/src/mcp.d.ts.map +1 -1
  161. package/dist/src/mcp.js +23 -6
  162. package/dist/src/mcp.js.map +1 -1
  163. package/dist/src/mime.d.ts +24 -0
  164. package/dist/src/mime.d.ts.map +1 -0
  165. package/dist/src/mime.js +82 -0
  166. package/dist/src/mime.js.map +1 -0
  167. package/dist/src/models/__tests__/anthropic.test.js +78 -1
  168. package/dist/src/models/__tests__/anthropic.test.js.map +1 -1
  169. package/dist/src/models/__tests__/bedrock.test.js +2050 -131
  170. package/dist/src/models/__tests__/bedrock.test.js.map +1 -1
  171. package/dist/src/models/__tests__/gemini.test.js +100 -1
  172. package/dist/src/models/__tests__/gemini.test.js.map +1 -1
  173. package/dist/src/models/__tests__/model.test.js +131 -0
  174. package/dist/src/models/__tests__/model.test.js.map +1 -1
  175. package/dist/src/models/__tests__/openai.test.js +184 -32
  176. package/dist/src/models/__tests__/openai.test.js.map +1 -1
  177. package/dist/src/models/__tests__/streaming.test.d.ts +2 -0
  178. package/dist/src/models/__tests__/streaming.test.d.ts.map +1 -0
  179. package/dist/src/models/__tests__/streaming.test.js +50 -0
  180. package/dist/src/models/__tests__/streaming.test.js.map +1 -0
  181. package/dist/src/models/anthropic.d.ts.map +1 -1
  182. package/dist/src/models/anthropic.js +6 -7
  183. package/dist/src/models/anthropic.js.map +1 -1
  184. package/dist/src/models/bedrock.d.ts +144 -11
  185. package/dist/src/models/bedrock.d.ts.map +1 -1
  186. package/dist/src/models/bedrock.js +416 -28
  187. package/dist/src/models/bedrock.js.map +1 -1
  188. package/dist/src/models/gemini/adapters.d.ts.map +1 -1
  189. package/dist/src/models/gemini/adapters.js +65 -14
  190. package/dist/src/models/gemini/adapters.js.map +1 -1
  191. package/dist/src/models/model.d.ts +18 -0
  192. package/dist/src/models/model.d.ts.map +1 -1
  193. package/dist/src/models/model.js +57 -11
  194. package/dist/src/models/model.js.map +1 -1
  195. package/dist/src/models/openai.d.ts +15 -0
  196. package/dist/src/models/openai.d.ts.map +1 -1
  197. package/dist/src/models/openai.js +108 -64
  198. package/dist/src/models/openai.js.map +1 -1
  199. package/dist/src/models/streaming.d.ts +88 -2
  200. package/dist/src/models/streaming.d.ts.map +1 -1
  201. package/dist/src/models/streaming.js +26 -0
  202. package/dist/src/models/streaming.js.map +1 -1
  203. package/dist/src/multiagent/__tests__/events.test.js +41 -8
  204. package/dist/src/multiagent/__tests__/events.test.js.map +1 -1
  205. package/dist/src/multiagent/__tests__/graph.test.d.ts +2 -0
  206. package/dist/src/multiagent/__tests__/graph.test.d.ts.map +1 -0
  207. package/dist/src/multiagent/__tests__/graph.test.js +453 -0
  208. package/dist/src/multiagent/__tests__/graph.test.js.map +1 -0
  209. package/dist/src/multiagent/__tests__/nodes.test.js +34 -16
  210. package/dist/src/multiagent/__tests__/nodes.test.js.map +1 -1
  211. package/dist/src/multiagent/__tests__/queue.test.js +22 -0
  212. package/dist/src/multiagent/__tests__/queue.test.js.map +1 -1
  213. package/dist/src/multiagent/__tests__/swarm.test.d.ts +2 -0
  214. package/dist/src/multiagent/__tests__/swarm.test.d.ts.map +1 -0
  215. package/dist/src/multiagent/__tests__/swarm.test.js +264 -0
  216. package/dist/src/multiagent/__tests__/swarm.test.js.map +1 -0
  217. package/dist/src/multiagent/edge.d.ts +9 -2
  218. package/dist/src/multiagent/edge.d.ts.map +1 -1
  219. package/dist/src/multiagent/events.d.ts +63 -15
  220. package/dist/src/multiagent/events.d.ts.map +1 -1
  221. package/dist/src/multiagent/events.js +28 -3
  222. package/dist/src/multiagent/events.js.map +1 -1
  223. package/dist/src/multiagent/graph.d.ts +135 -0
  224. package/dist/src/multiagent/graph.d.ts.map +1 -0
  225. package/dist/src/multiagent/graph.js +400 -0
  226. package/dist/src/multiagent/graph.js.map +1 -0
  227. package/dist/src/multiagent/index.d.ts +8 -3
  228. package/dist/src/multiagent/index.d.ts.map +1 -1
  229. package/dist/src/multiagent/index.js +3 -1
  230. package/dist/src/multiagent/index.js.map +1 -1
  231. package/dist/src/multiagent/multiagent.d.ts +41 -0
  232. package/dist/src/multiagent/multiagent.d.ts.map +1 -0
  233. package/dist/src/multiagent/multiagent.js +2 -0
  234. package/dist/src/multiagent/multiagent.js.map +1 -0
  235. package/dist/src/multiagent/nodes.d.ts +24 -25
  236. package/dist/src/multiagent/nodes.d.ts.map +1 -1
  237. package/dist/src/multiagent/nodes.js +42 -15
  238. package/dist/src/multiagent/nodes.js.map +1 -1
  239. package/dist/src/multiagent/plugins.d.ts +70 -0
  240. package/dist/src/multiagent/plugins.d.ts.map +1 -0
  241. package/dist/src/multiagent/plugins.js +70 -0
  242. package/dist/src/multiagent/plugins.js.map +1 -0
  243. package/dist/src/multiagent/queue.d.ts +6 -0
  244. package/dist/src/multiagent/queue.d.ts.map +1 -1
  245. package/dist/src/multiagent/queue.js +13 -0
  246. package/dist/src/multiagent/queue.js.map +1 -1
  247. package/dist/src/multiagent/state.d.ts +4 -2
  248. package/dist/src/multiagent/state.d.ts.map +1 -1
  249. package/dist/src/multiagent/state.js +5 -2
  250. package/dist/src/multiagent/state.js.map +1 -1
  251. package/dist/src/multiagent/swarm.d.ts +112 -0
  252. package/dist/src/multiagent/swarm.d.ts.map +1 -0
  253. package/dist/src/multiagent/swarm.js +256 -0
  254. package/dist/src/multiagent/swarm.js.map +1 -0
  255. package/dist/src/plugins/__tests__/plugin.test.d.ts +2 -0
  256. package/dist/src/plugins/__tests__/plugin.test.d.ts.map +1 -0
  257. package/dist/src/plugins/__tests__/plugin.test.js +114 -0
  258. package/dist/src/plugins/__tests__/plugin.test.js.map +1 -0
  259. package/dist/src/plugins/__tests__/registry.test.d.ts +2 -0
  260. package/dist/src/plugins/__tests__/registry.test.d.ts.map +1 -0
  261. package/dist/src/plugins/__tests__/registry.test.js +147 -0
  262. package/dist/src/plugins/__tests__/registry.test.js.map +1 -0
  263. package/dist/src/plugins/index.d.ts +30 -0
  264. package/dist/src/plugins/index.d.ts.map +1 -0
  265. package/dist/src/plugins/index.js +30 -0
  266. package/dist/src/plugins/index.js.map +1 -0
  267. package/dist/src/plugins/plugin.d.ts +74 -0
  268. package/dist/src/plugins/plugin.d.ts.map +1 -0
  269. package/dist/src/plugins/plugin.js +8 -0
  270. package/dist/src/plugins/plugin.js.map +1 -0
  271. package/dist/src/plugins/registry.d.ts +25 -0
  272. package/dist/src/plugins/registry.d.ts.map +1 -0
  273. package/dist/src/plugins/registry.js +41 -0
  274. package/dist/src/plugins/registry.js.map +1 -0
  275. package/dist/src/registry/__tests__/tool-registry.test.d.ts +2 -0
  276. package/dist/src/registry/__tests__/tool-registry.test.d.ts.map +1 -0
  277. package/dist/src/registry/__tests__/tool-registry.test.js +124 -0
  278. package/dist/src/registry/__tests__/tool-registry.test.js.map +1 -0
  279. package/dist/src/registry/tool-registry.d.ts +32 -20
  280. package/dist/src/registry/tool-registry.d.ts.map +1 -1
  281. package/dist/src/registry/tool-registry.js +60 -158
  282. package/dist/src/registry/tool-registry.js.map +1 -1
  283. package/dist/src/session/__tests__/file-storage.test.node.js +75 -15
  284. package/dist/src/session/__tests__/file-storage.test.node.js.map +1 -1
  285. package/dist/src/session/__tests__/s3-storage.test.d.ts +2 -0
  286. package/dist/src/session/__tests__/s3-storage.test.d.ts.map +1 -0
  287. package/dist/src/session/__tests__/{s3-storage.test.node.js → s3-storage.test.js} +161 -75
  288. package/dist/src/session/__tests__/s3-storage.test.js.map +1 -0
  289. package/dist/src/session/__tests__/session-manager.test.d.ts +2 -0
  290. package/dist/src/session/__tests__/session-manager.test.d.ts.map +1 -0
  291. package/dist/src/session/__tests__/session-manager.test.js +443 -0
  292. package/dist/src/session/__tests__/session-manager.test.js.map +1 -0
  293. package/dist/src/session/__tests__/validation.test.js +28 -1
  294. package/dist/src/session/__tests__/validation.test.js.map +1 -1
  295. package/dist/src/session/file-storage.d.ts +53 -27
  296. package/dist/src/session/file-storage.d.ts.map +1 -1
  297. package/dist/src/session/file-storage.js +103 -52
  298. package/dist/src/session/file-storage.js.map +1 -1
  299. package/dist/src/session/index.d.ts +6 -14
  300. package/dist/src/session/index.d.ts.map +1 -1
  301. package/dist/src/session/index.js +4 -13
  302. package/dist/src/session/index.js.map +1 -1
  303. package/dist/src/session/s3-storage.d.ts +49 -20
  304. package/dist/src/session/s3-storage.d.ts.map +1 -1
  305. package/dist/src/session/s3-storage.js +120 -35
  306. package/dist/src/session/s3-storage.js.map +1 -1
  307. package/dist/src/session/session-manager.d.ts +87 -0
  308. package/dist/src/session/session-manager.d.ts.map +1 -0
  309. package/dist/src/session/session-manager.js +128 -0
  310. package/dist/src/session/session-manager.js.map +1 -0
  311. package/dist/src/session/storage.d.ts +20 -12
  312. package/dist/src/session/storage.d.ts.map +1 -1
  313. package/dist/src/session/types.d.ts +8 -20
  314. package/dist/src/session/types.d.ts.map +1 -1
  315. package/dist/src/session/validation.d.ts +7 -0
  316. package/dist/src/session/validation.d.ts.map +1 -1
  317. package/dist/src/session/validation.js +12 -0
  318. package/dist/src/session/validation.js.map +1 -1
  319. package/dist/src/{app-state.d.ts → state-store.d.ts} +11 -11
  320. package/dist/src/state-store.d.ts.map +1 -0
  321. package/dist/src/{app-state.js → state-store.js} +8 -7
  322. package/dist/src/state-store.js.map +1 -0
  323. package/dist/src/structured-output/__tests__/context.test.js +13 -13
  324. package/dist/src/structured-output/__tests__/context.test.js.map +1 -1
  325. package/dist/src/structured-output/context.js +1 -1
  326. package/dist/src/structured-output/context.js.map +1 -1
  327. package/dist/src/telemetry/__tests__/config.test.d.ts +2 -0
  328. package/dist/src/telemetry/__tests__/config.test.d.ts.map +1 -0
  329. package/dist/src/telemetry/__tests__/config.test.js +64 -0
  330. package/dist/src/telemetry/__tests__/config.test.js.map +1 -0
  331. package/dist/src/telemetry/__tests__/config.test.node.js +66 -36
  332. package/dist/src/telemetry/__tests__/config.test.node.js.map +1 -1
  333. package/dist/src/telemetry/__tests__/meter.test.d.ts +2 -0
  334. package/dist/src/telemetry/__tests__/meter.test.d.ts.map +1 -0
  335. package/dist/src/telemetry/__tests__/meter.test.js +624 -0
  336. package/dist/src/telemetry/__tests__/meter.test.js.map +1 -0
  337. package/dist/src/telemetry/__tests__/tracer.test.node.js +123 -2
  338. package/dist/src/telemetry/__tests__/tracer.test.node.js.map +1 -1
  339. package/dist/src/telemetry/config.d.ts +104 -23
  340. package/dist/src/telemetry/config.d.ts.map +1 -1
  341. package/dist/src/telemetry/config.js +152 -43
  342. package/dist/src/telemetry/config.js.map +1 -1
  343. package/dist/src/telemetry/index.d.ts +10 -7
  344. package/dist/src/telemetry/index.d.ts.map +1 -1
  345. package/dist/src/telemetry/index.js +9 -6
  346. package/dist/src/telemetry/index.js.map +1 -1
  347. package/dist/src/telemetry/meter.d.ts +296 -0
  348. package/dist/src/telemetry/meter.d.ts.map +1 -0
  349. package/dist/src/telemetry/meter.js +365 -0
  350. package/dist/src/telemetry/meter.js.map +1 -0
  351. package/dist/src/telemetry/tracer.d.ts +27 -0
  352. package/dist/src/telemetry/tracer.d.ts.map +1 -1
  353. package/dist/src/telemetry/tracer.js +79 -4
  354. package/dist/src/telemetry/tracer.js.map +1 -1
  355. package/dist/src/telemetry/types.d.ts +2 -0
  356. package/dist/src/telemetry/types.d.ts.map +1 -1
  357. package/dist/src/telemetry/utils.d.ts +10 -0
  358. package/dist/src/telemetry/utils.d.ts.map +1 -0
  359. package/dist/src/telemetry/utils.js +13 -0
  360. package/dist/src/telemetry/utils.js.map +1 -0
  361. package/dist/src/tools/__tests__/tool-factory.test.d.ts +2 -0
  362. package/dist/src/tools/__tests__/tool-factory.test.d.ts.map +1 -0
  363. package/dist/src/tools/__tests__/tool-factory.test.js +98 -0
  364. package/dist/src/tools/__tests__/tool-factory.test.js.map +1 -0
  365. package/dist/src/tools/__tests__/tool.test.js +22 -1
  366. package/dist/src/tools/__tests__/tool.test.js.map +1 -1
  367. package/dist/src/tools/__tests__/zod-tool.test-d.js +1 -1
  368. package/dist/src/tools/__tests__/zod-tool.test-d.js.map +1 -1
  369. package/dist/src/tools/__tests__/zod-tool.test.js +3 -4
  370. package/dist/src/tools/__tests__/zod-tool.test.js.map +1 -1
  371. package/dist/src/tools/function-tool.d.ts +26 -3
  372. package/dist/src/tools/function-tool.d.ts.map +1 -1
  373. package/dist/src/tools/function-tool.js +88 -3
  374. package/dist/src/tools/function-tool.js.map +1 -1
  375. package/dist/src/tools/tool-factory.d.ts +22 -0
  376. package/dist/src/tools/tool-factory.d.ts.map +1 -0
  377. package/dist/src/tools/tool-factory.js +55 -0
  378. package/dist/src/tools/tool-factory.js.map +1 -0
  379. package/dist/src/tools/tool.d.ts +2 -2
  380. package/dist/src/tools/tool.d.ts.map +1 -1
  381. package/dist/src/tools/zod-tool.d.ts +55 -52
  382. package/dist/src/tools/zod-tool.d.ts.map +1 -1
  383. package/dist/src/tools/zod-tool.js +7 -61
  384. package/dist/src/tools/zod-tool.js.map +1 -1
  385. package/dist/src/tsconfig.tsbuildinfo +1 -1
  386. package/dist/src/types/__tests__/agent.test.js +11 -0
  387. package/dist/src/types/__tests__/agent.test.js.map +1 -1
  388. package/dist/src/types/__tests__/citations.test.d.ts +2 -0
  389. package/dist/src/types/__tests__/citations.test.d.ts.map +1 -0
  390. package/dist/src/types/__tests__/citations.test.js +104 -0
  391. package/dist/src/types/__tests__/citations.test.js.map +1 -0
  392. package/dist/src/types/__tests__/media.test.js +22 -16
  393. package/dist/src/types/__tests__/media.test.js.map +1 -1
  394. package/dist/src/types/__tests__/messages.test.js +26 -0
  395. package/dist/src/types/__tests__/messages.test.js.map +1 -1
  396. package/dist/src/types/agent.d.ts +82 -7
  397. package/dist/src/types/agent.d.ts.map +1 -1
  398. package/dist/src/types/agent.js +9 -0
  399. package/dist/src/types/agent.js.map +1 -1
  400. package/dist/src/types/citations.d.ts +180 -0
  401. package/dist/src/types/citations.d.ts.map +1 -0
  402. package/dist/src/types/citations.js +45 -0
  403. package/dist/src/types/citations.js.map +1 -0
  404. package/dist/src/types/media.d.ts +27 -30
  405. package/dist/src/types/media.d.ts.map +1 -1
  406. package/dist/src/types/media.js +15 -56
  407. package/dist/src/types/media.js.map +1 -1
  408. package/dist/src/types/messages.d.ts +23 -5
  409. package/dist/src/types/messages.d.ts.map +1 -1
  410. package/dist/src/types/messages.js +26 -26
  411. package/dist/src/types/messages.js.map +1 -1
  412. package/dist/src/types/serializable.d.ts +34 -4
  413. package/dist/src/types/serializable.d.ts.map +1 -1
  414. package/dist/src/types/serializable.js +31 -2
  415. package/dist/src/types/serializable.js.map +1 -1
  416. package/dist/src/vended-tools/bash/__tests__/bash.test.node.js +5 -4
  417. package/dist/src/vended-tools/bash/__tests__/bash.test.node.js.map +1 -1
  418. package/dist/src/vended-tools/bash/bash.d.ts.map +1 -1
  419. package/dist/src/vended-tools/bash/bash.js +1 -2
  420. package/dist/src/vended-tools/bash/bash.js.map +1 -1
  421. package/dist/src/vended-tools/file-editor/__tests__/file-editor.test.node.d.ts.map +1 -0
  422. package/dist/src/vended-tools/{file_editor → file-editor}/__tests__/file-editor.test.node.js +11 -4
  423. package/dist/src/vended-tools/file-editor/__tests__/file-editor.test.node.js.map +1 -0
  424. package/dist/src/vended-tools/{file_editor → file-editor}/file-editor.d.ts +1 -1
  425. package/dist/src/vended-tools/{file_editor → file-editor}/file-editor.d.ts.map +1 -1
  426. package/dist/src/vended-tools/{file_editor → file-editor}/file-editor.js +3 -3
  427. package/dist/src/vended-tools/{file_editor → file-editor}/file-editor.js.map +1 -1
  428. package/dist/src/vended-tools/{file_editor → file-editor}/index.d.ts.map +1 -1
  429. package/dist/src/vended-tools/file-editor/index.js.map +1 -0
  430. package/dist/src/vended-tools/{file_editor → file-editor}/types.d.ts.map +1 -1
  431. package/dist/src/vended-tools/file-editor/types.js.map +1 -0
  432. package/dist/src/vended-tools/http-request/__tests__/http-request.test.d.ts.map +1 -0
  433. package/dist/src/vended-tools/{http_request → http-request}/__tests__/http-request.test.js.map +1 -1
  434. package/dist/src/vended-tools/http-request/http-request.d.ts.map +1 -0
  435. package/dist/src/vended-tools/{http_request → http-request}/http-request.js +1 -2
  436. package/dist/src/vended-tools/http-request/http-request.js.map +1 -0
  437. package/dist/src/vended-tools/{http_request → http-request}/index.d.ts.map +1 -1
  438. package/dist/src/vended-tools/http-request/index.js.map +1 -0
  439. package/dist/src/vended-tools/{http_request → http-request}/types.d.ts.map +1 -1
  440. package/dist/src/vended-tools/http-request/types.js.map +1 -0
  441. package/dist/src/vended-tools/notebook/__tests__/notebook.test.js +5 -4
  442. package/dist/src/vended-tools/notebook/__tests__/notebook.test.js.map +1 -1
  443. package/dist/src/vended-tools/notebook/notebook.d.ts +1 -1
  444. package/dist/src/vended-tools/notebook/notebook.js +2 -2
  445. package/dist/src/vended-tools/notebook/notebook.js.map +1 -1
  446. package/package.json +66 -12
  447. package/dist/src/__fixtures__/mock-hook-provider.d.ts +0 -10
  448. package/dist/src/__fixtures__/mock-hook-provider.d.ts.map +0 -1
  449. package/dist/src/__fixtures__/mock-hook-provider.js.map +0 -1
  450. package/dist/src/__tests__/app-state.test.d.ts +0 -2
  451. package/dist/src/__tests__/app-state.test.d.ts.map +0 -1
  452. package/dist/src/__tests__/app-state.test.js.map +0 -1
  453. package/dist/src/app-state.d.ts.map +0 -1
  454. package/dist/src/app-state.js.map +0 -1
  455. package/dist/src/multiagent/base.d.ts +0 -25
  456. package/dist/src/multiagent/base.d.ts.map +0 -1
  457. package/dist/src/multiagent/base.js +0 -2
  458. package/dist/src/multiagent/base.js.map +0 -1
  459. package/dist/src/registry/registry.d.ts +0 -117
  460. package/dist/src/registry/registry.d.ts.map +0 -1
  461. package/dist/src/registry/registry.js +0 -298
  462. package/dist/src/registry/registry.js.map +0 -1
  463. package/dist/src/session/__tests__/s3-storage.test.node.d.ts +0 -2
  464. package/dist/src/session/__tests__/s3-storage.test.node.d.ts.map +0 -1
  465. package/dist/src/session/__tests__/s3-storage.test.node.js.map +0 -1
  466. package/dist/src/vended-tools/file_editor/__tests__/file-editor.test.node.d.ts.map +0 -1
  467. package/dist/src/vended-tools/file_editor/__tests__/file-editor.test.node.js.map +0 -1
  468. package/dist/src/vended-tools/file_editor/index.js.map +0 -1
  469. package/dist/src/vended-tools/file_editor/types.js.map +0 -1
  470. package/dist/src/vended-tools/http_request/__tests__/http-request.test.d.ts.map +0 -1
  471. package/dist/src/vended-tools/http_request/http-request.d.ts.map +0 -1
  472. package/dist/src/vended-tools/http_request/http-request.js.map +0 -1
  473. package/dist/src/vended-tools/http_request/index.js.map +0 -1
  474. package/dist/src/vended-tools/http_request/types.js.map +0 -1
  475. /package/dist/src/vended-tools/{file_editor → file-editor}/__tests__/file-editor.test.node.d.ts +0 -0
  476. /package/dist/src/vended-tools/{file_editor → file-editor}/index.d.ts +0 -0
  477. /package/dist/src/vended-tools/{file_editor → file-editor}/index.js +0 -0
  478. /package/dist/src/vended-tools/{file_editor → file-editor}/types.d.ts +0 -0
  479. /package/dist/src/vended-tools/{file_editor → file-editor}/types.js +0 -0
  480. /package/dist/src/vended-tools/{http_request → http-request}/__tests__/http-request.test.d.ts +0 -0
  481. /package/dist/src/vended-tools/{http_request → http-request}/__tests__/http-request.test.js +0 -0
  482. /package/dist/src/vended-tools/{http_request → http-request}/http-request.d.ts +0 -0
  483. /package/dist/src/vended-tools/{http_request → http-request}/index.d.ts +0 -0
  484. /package/dist/src/vended-tools/{http_request → http-request}/index.js +0 -0
  485. /package/dist/src/vended-tools/{http_request → http-request}/types.d.ts +0 -0
  486. /package/dist/src/vended-tools/{http_request → http-request}/types.js +0 -0
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Plugin interface for extending agent functionality.
3
+ *
4
+ * This module defines the Plugin interface, which provides a composable way to
5
+ * add behavior changes to agents through hook registration and custom initialization.
6
+ */
7
+ import type { Tool } from '../tools/tool.js';
8
+ import type { LocalAgent } from '../types/agent.js';
9
+ /**
10
+ * Interface for objects that extend agent functionality.
11
+ *
12
+ * Plugins provide a composable way to add behavior changes to agents by registering
13
+ * hook callbacks in their `initAgent` method. Each plugin must have a unique name
14
+ * for identification, logging, and duplicate prevention.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * class LoggingPlugin implements Plugin {
19
+ * get name(): string {
20
+ * return 'logging-plugin'
21
+ * }
22
+ *
23
+ * initAgent(agent: LocalAgent): void {
24
+ * agent.addHook(BeforeInvocationEvent, (event) => {
25
+ * console.log('Agent invocation started')
26
+ * })
27
+ * }
28
+ * }
29
+ *
30
+ * const agent = new Agent({
31
+ * model,
32
+ * plugins: [new LoggingPlugin()],
33
+ * })
34
+ * ```
35
+ *
36
+ * @example With tools
37
+ * ```typescript
38
+ * class MyToolPlugin implements Plugin {
39
+ * get name(): string {
40
+ * return 'my-tool-plugin'
41
+ * }
42
+ *
43
+ * getTools(): Tool[] {
44
+ * return [myTool]
45
+ * }
46
+ * }
47
+ * ```
48
+ */
49
+ export interface Plugin {
50
+ /**
51
+ * A stable string identifier for the plugin.
52
+ * Used for logging, duplicate detection, and plugin management.
53
+ *
54
+ * For strands-vended plugins, names should be prefixed with `strands:`.
55
+ */
56
+ readonly name: string;
57
+ /**
58
+ * Initialize the plugin with the agent instance.
59
+ *
60
+ * Implement this method to register hooks and perform custom initialization.
61
+ * Tool registration from {@link getTools} is handled automatically by the PluginRegistry.
62
+ *
63
+ * @param agent - The agent instance this plugin is being attached to
64
+ */
65
+ initAgent(agent: LocalAgent): void | Promise<void>;
66
+ /**
67
+ * Returns tools provided by this plugin for auto-registration.
68
+ * Implement to provide plugin-specific tools.
69
+ *
70
+ * @returns Array of tools to register with the agent
71
+ */
72
+ getTools?(): Tool[];
73
+ }
74
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/plugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,WAAW,MAAM;IACrB;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IAErB;;;;;;;OAOG;IACH,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAElD;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,IAAI,EAAE,CAAA;CACpB"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Plugin interface for extending agent functionality.
3
+ *
4
+ * This module defines the Plugin interface, which provides a composable way to
5
+ * add behavior changes to agents through hook registration and custom initialization.
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../src/plugins/plugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Plugin registry for managing plugins attached to an agent.
3
+ */
4
+ import type { Plugin } from './plugin.js';
5
+ import type { LocalAgent } from '../types/agent.js';
6
+ /**
7
+ * Registry for managing plugins attached to an agent.
8
+ *
9
+ * Holds pending plugins and initializes them on first use.
10
+ * Handles duplicate detection, tool registration, and calls each plugin's initAgent method.
11
+ */
12
+ export declare class PluginRegistry {
13
+ private readonly _plugins;
14
+ private readonly _pending;
15
+ constructor(plugins?: Plugin[]);
16
+ /**
17
+ * Initialize all pending plugins with the agent.
18
+ * Safe to call multiple times — only runs once per pending batch.
19
+ *
20
+ * @param agent - The agent instance to initialize plugins with
21
+ */
22
+ initialize(agent: LocalAgent): Promise<void>;
23
+ private _addAndInit;
24
+ }
25
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/plugins/registry.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAEnD;;;;;GAKG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqB;IAC9C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAU;gBAEvB,OAAO,GAAE,MAAM,EAAO;IAKlC;;;;;OAKG;IACG,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;YAOpC,WAAW;CAa1B"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Plugin registry for managing plugins attached to an agent.
3
+ */
4
+ /**
5
+ * Registry for managing plugins attached to an agent.
6
+ *
7
+ * Holds pending plugins and initializes them on first use.
8
+ * Handles duplicate detection, tool registration, and calls each plugin's initAgent method.
9
+ */
10
+ export class PluginRegistry {
11
+ _plugins;
12
+ _pending;
13
+ constructor(plugins = []) {
14
+ this._plugins = new Map();
15
+ this._pending = [...plugins];
16
+ }
17
+ /**
18
+ * Initialize all pending plugins with the agent.
19
+ * Safe to call multiple times — only runs once per pending batch.
20
+ *
21
+ * @param agent - The agent instance to initialize plugins with
22
+ */
23
+ async initialize(agent) {
24
+ while (this._pending.length > 0) {
25
+ const plugin = this._pending.shift();
26
+ await this._addAndInit(plugin, agent);
27
+ }
28
+ }
29
+ async _addAndInit(plugin, agent) {
30
+ if (this._plugins.has(plugin.name)) {
31
+ throw new Error(`plugin_name=<${plugin.name}> | plugin already registered`);
32
+ }
33
+ this._plugins.set(plugin.name, plugin);
34
+ const tools = plugin.getTools?.() ?? [];
35
+ if (tools.length > 0) {
36
+ agent.toolRegistry.add(tools);
37
+ }
38
+ await plugin.initAgent(agent);
39
+ }
40
+ }
41
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../src/plugins/registry.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH;;;;;GAKG;AACH,MAAM,OAAO,cAAc;IACR,QAAQ,CAAqB;IAC7B,QAAQ,CAAU;IAEnC,YAAY,UAAoB,EAAE;QAChC,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,EAAE,CAAA;QACzB,IAAI,CAAC,QAAQ,GAAG,CAAC,GAAG,OAAO,CAAC,CAAA;IAC9B,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,UAAU,CAAC,KAAiB;QAChC,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChC,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAG,CAAA;YACrC,MAAM,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;QACvC,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,WAAW,CAAC,MAAc,EAAE,KAAiB;QACzD,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CAAC,gBAAgB,MAAM,CAAC,IAAI,+BAA+B,CAAC,CAAA;QAC7E,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;QAEtC,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,CAAA;QACvC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACrB,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QAC/B,CAAC;QAED,MAAM,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;IAC/B,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=tool-registry.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-registry.test.d.ts","sourceRoot":"","sources":["../../../../src/registry/__tests__/tool-registry.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,124 @@
1
+ import { describe, it, expect, beforeEach } from 'vitest';
2
+ import { ToolRegistry } from '../tool-registry.js';
3
+ import { ToolValidationError } from '../../errors.js';
4
+ import { ToolStreamEvent } from '../../tools/tool.js';
5
+ import { ToolResultBlock } from '../../types/messages.js';
6
+ const createMockTool = (overrides = {}) => ({
7
+ name: 'valid-tool',
8
+ description: 'A valid tool description.',
9
+ toolSpec: {
10
+ name: 'valid-tool',
11
+ description: 'A valid tool description.',
12
+ inputSchema: { type: 'object', properties: {} },
13
+ },
14
+ stream: async function* () {
15
+ yield new ToolStreamEvent({ data: 'mock data' });
16
+ return new ToolResultBlock({ toolUseId: '', status: 'success', content: [] });
17
+ },
18
+ ...overrides,
19
+ });
20
+ describe('ToolRegistry', () => {
21
+ let registry;
22
+ beforeEach(() => {
23
+ registry = new ToolRegistry();
24
+ });
25
+ describe('add', () => {
26
+ it('registers a single tool', () => {
27
+ const tool = createMockTool();
28
+ registry.add(tool);
29
+ expect(registry.list()).toStrictEqual([tool]);
30
+ });
31
+ it('registers an array of tools', () => {
32
+ const tool1 = createMockTool({ name: 'tool-1' });
33
+ const tool2 = createMockTool({ name: 'tool-2' });
34
+ registry.add([tool1, tool2]);
35
+ expect(registry.list()).toStrictEqual([tool1, tool2]);
36
+ });
37
+ it('throws ToolValidationError for a duplicate tool name', () => {
38
+ registry.add(createMockTool({ name: 'duplicate' }));
39
+ expect(() => registry.add(createMockTool({ name: 'duplicate' }))).toThrow(ToolValidationError);
40
+ expect(() => registry.add(createMockTool({ name: 'duplicate' }))).toThrow("Tool with name 'duplicate' already registered");
41
+ });
42
+ it('throws ToolValidationError for an invalid tool name pattern', () => {
43
+ expect(() => registry.add(createMockTool({ name: 'invalid name!' }))).toThrow(ToolValidationError);
44
+ expect(() => registry.add(createMockTool({ name: 'invalid name!' }))).toThrow('Tool name must contain only alphanumeric characters, hyphens, and underscores');
45
+ });
46
+ it('throws ToolValidationError for a tool name that is too long', () => {
47
+ expect(() => registry.add(createMockTool({ name: 'a'.repeat(65) }))).toThrow(ToolValidationError);
48
+ expect(() => registry.add(createMockTool({ name: 'a'.repeat(65) }))).toThrow('Tool name must be between 1 and 64 characters');
49
+ });
50
+ it('throws ToolValidationError for a tool name that is too short', () => {
51
+ expect(() => registry.add(createMockTool({ name: '' }))).toThrow(ToolValidationError);
52
+ expect(() => registry.add(createMockTool({ name: '' }))).toThrow('Tool name must be between 1 and 64 characters');
53
+ });
54
+ it('throws ToolValidationError for a non-string tool name', () => {
55
+ // @ts-expect-error - Testing invalid type for name
56
+ expect(() => registry.add(createMockTool({ name: 123 }))).toThrow(ToolValidationError);
57
+ // @ts-expect-error - Testing invalid type for name
58
+ expect(() => registry.add(createMockTool({ name: 123 }))).toThrow('Tool name must be a string');
59
+ });
60
+ it('throws ToolValidationError for an invalid description', () => {
61
+ // @ts-expect-error - Testing invalid type for description
62
+ expect(() => registry.add(createMockTool({ description: 123 }))).toThrow(ToolValidationError);
63
+ // @ts-expect-error - Testing invalid type for description
64
+ expect(() => registry.add(createMockTool({ description: 123 }))).toThrow('Tool description must be a non-empty string');
65
+ });
66
+ it('throws ToolValidationError for an empty string description', () => {
67
+ expect(() => registry.add(createMockTool({ description: '' }))).toThrow(ToolValidationError);
68
+ expect(() => registry.add(createMockTool({ description: '' }))).toThrow('Tool description must be a non-empty string');
69
+ });
70
+ it('allows a tool with a null or undefined description', () => {
71
+ const tool1 = createMockTool({ name: 'tool-1' });
72
+ // @ts-expect-error - Testing explicit undefined description
73
+ tool1.description = undefined;
74
+ const tool2 = createMockTool({ name: 'tool-2' });
75
+ // @ts-expect-error - Testing explicit null description
76
+ tool2.description = null;
77
+ registry.add([tool1, tool2]);
78
+ expect(registry.list()).toHaveLength(2);
79
+ });
80
+ it('registers a tool with a name at the maximum length', () => {
81
+ const tool = createMockTool({ name: 'a'.repeat(64) });
82
+ expect(() => registry.add(tool)).not.toThrow();
83
+ });
84
+ });
85
+ describe('get', () => {
86
+ it('retrieves a tool by name', () => {
87
+ const tool = createMockTool({ name: 'find-me' });
88
+ registry.add(tool);
89
+ expect(registry.get('find-me')).toBe(tool);
90
+ });
91
+ it('returns undefined for a non-existent tool', () => {
92
+ expect(registry.get('non-existent')).toBeUndefined();
93
+ });
94
+ });
95
+ describe('remove', () => {
96
+ it('removes a tool by name', () => {
97
+ registry.add(createMockTool({ name: 'remove-me' }));
98
+ registry.remove('remove-me');
99
+ expect(registry.get('remove-me')).toBeUndefined();
100
+ });
101
+ it('does not throw when removing a non-existent tool', () => {
102
+ expect(() => registry.remove('non-existent')).not.toThrow();
103
+ });
104
+ });
105
+ describe('list', () => {
106
+ it('returns an empty array when no tools are registered', () => {
107
+ expect(registry.list()).toStrictEqual([]);
108
+ });
109
+ it('returns all registered tools', () => {
110
+ const tool1 = createMockTool({ name: 'tool-1' });
111
+ const tool2 = createMockTool({ name: 'tool-2' });
112
+ registry.add([tool1, tool2]);
113
+ expect(registry.list()).toStrictEqual([tool1, tool2]);
114
+ });
115
+ });
116
+ describe('constructor', () => {
117
+ it('accepts initial tools', () => {
118
+ const tool = createMockTool();
119
+ const reg = new ToolRegistry([tool]);
120
+ expect(reg.list()).toStrictEqual([tool]);
121
+ });
122
+ });
123
+ });
124
+ //# sourceMappingURL=tool-registry.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-registry.test.js","sourceRoot":"","sources":["../../../../src/registry/__tests__/tool-registry.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAErD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAEzD,MAAM,cAAc,GAAG,CAAC,YAA2B,EAAE,EAAQ,EAAE,CAAC,CAAC;IAC/D,IAAI,EAAE,YAAY;IAClB,WAAW,EAAE,2BAA2B;IACxC,QAAQ,EAAE;QACR,IAAI,EAAE,YAAY;QAClB,WAAW,EAAE,2BAA2B;QACxC,WAAW,EAAE,EAAE,IAAI,EAAE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,CAAC,CAAC,aAAa,CAAC,EAAE,CAAC,CAAA;QAC3C,CAAC,CAAC,CAAA;QAEF,EAAE,CAAC,8BAA8B,EAAE,GAAG,EAAE;YACtC,MAAM,KAAK,GAAG,cAAc,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAA;YAChD,MAAM,KAAK,GAAG,cAAc,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAA;YAChD,QAAQ,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAA;YAC5B,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,aAAa,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAA;QACvD,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;QAC3B,EAAE,CAAC,uBAAuB,EAAE,GAAG,EAAE;YAC/B,MAAM,IAAI,GAAG,cAAc,EAAE,CAAA;YAC7B,MAAM,GAAG,GAAG,IAAI,YAAY,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;YACpC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;QAC1C,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -1,35 +1,47 @@
1
- import { Registry } from './registry.js';
2
1
  import type { Tool } from '../tools/tool.js';
3
2
  /**
4
- * A concrete implementation of the Registry for managing Tool instances.
5
- * It adds validation for tool properties and ensures unique tool names.
3
+ * Registry for managing Tool instances with name-based CRUDL operations.
6
4
  */
7
- export declare class ToolRegistry extends Registry<Tool, Tool> {
5
+ export declare class ToolRegistry {
6
+ private _tools;
8
7
  /**
9
- * Generates a unique identifier for a Tool.
10
- * @override
11
- * @returns The tool itself as the identifier.
8
+ * Creates a new ToolRegistry, optionally pre-populated with tools.
9
+ *
10
+ * @param tools - Optional initial tools to register
11
+ */
12
+ constructor(tools?: Tool[]);
13
+ /**
14
+ * Registers one or more tools.
15
+ *
16
+ * @param tool - A single tool or array of tools to register
17
+ * @throws ToolValidationError If a tool's properties are invalid or its name is already registered
12
18
  */
13
- protected generateId(tool: Tool): Tool;
19
+ add(tool: Tool | Tool[]): void;
14
20
  /**
15
- * Validates a tool before it is registered.
16
- * @override
17
- * @param tool - The tool to be validated.
18
- * @throws ValidationError If the tool's properties are invalid or its name is already registered.
21
+ * Retrieves a tool by name.
22
+ *
23
+ * @param name - The name of the tool to retrieve
24
+ * @returns The tool if found, otherwise undefined
25
+ */
26
+ get(name: string): Tool | undefined;
27
+ /**
28
+ * Removes a tool by name. No-op if the tool does not exist.
29
+ *
30
+ * @param name - The name of the tool to remove
19
31
  */
20
- protected validate(tool: Tool): void;
32
+ remove(name: string): void;
21
33
  /**
22
- * Retrieves the first tool that matches the given name.
34
+ * Returns all registered tools.
23
35
  *
24
- * @param name - The name of the tool to retrieve.
25
- * @returns The tool if found, otherwise undefined.
36
+ * @returns Array of all registered tools
26
37
  */
27
- getByName(name: string): Tool | undefined;
38
+ list(): Tool[];
28
39
  /**
29
- * Finds and removes the first tool that matches the given name.
40
+ * Validates a tool before registration.
30
41
  *
31
- * @param name - The name of the tool to remove.
42
+ * @param tool - The tool to validate
43
+ * @throws ToolValidationError If the tool's properties are invalid or its name is already registered
32
44
  */
33
- removeByName(name: string): void;
45
+ private _validate;
34
46
  }
35
47
  //# sourceMappingURL=tool-registry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tool-registry.d.ts","sourceRoot":"","sources":["../../../src/registry/tool-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAmB,MAAM,eAAe,CAAA;AACzD,OAAO,KAAK,EAAE,IAAI,EAAuB,MAAM,kBAAkB,CAAA;AAIjE;;;GAGG;AACH,qBAAa,YAAa,SAAQ,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpD;;;;OAIG;IACH,SAAS,CAAC,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAItC;;;;;OAKG;IACH,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IA+BpC;;;;;OAKG;IACI,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;IAIhD;;;;OAIG;IACI,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;CAGxC"}
1
+ {"version":3,"file":"tool-registry.d.ts","sourceRoot":"","sources":["../../../src/registry/tool-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAG5C;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAA+B;IAE7C;;;;OAIG;gBACS,KAAK,CAAC,EAAE,IAAI,EAAE;IAM1B;;;;;OAKG;IACH,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,GAAG,IAAI;IAQ9B;;;;;OAKG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;IAInC;;;;OAIG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAI1B;;;;OAIG;IACH,IAAI,IAAI,IAAI,EAAE;IAId;;;;;OAKG;IACH,OAAO,CAAC,SAAS;CAwBlB"}
@@ -1,180 +1,82 @@
1
- import { Registry, ValidationError } from './registry.js';
2
- import { ToolStreamEvent } from '../tools/tool.js';
3
- import { ToolResultBlock } from '../types/messages.js';
1
+ import { ToolValidationError } from '../errors.js';
4
2
  /**
5
- * A concrete implementation of the Registry for managing Tool instances.
6
- * It adds validation for tool properties and ensures unique tool names.
3
+ * Registry for managing Tool instances with name-based CRUDL operations.
7
4
  */
8
- export class ToolRegistry extends Registry {
5
+ export class ToolRegistry {
6
+ _tools = new Map();
9
7
  /**
10
- * Generates a unique identifier for a Tool.
11
- * @override
12
- * @returns The tool itself as the identifier.
8
+ * Creates a new ToolRegistry, optionally pre-populated with tools.
9
+ *
10
+ * @param tools - Optional initial tools to register
11
+ */
12
+ constructor(tools) {
13
+ if (tools) {
14
+ this.add(tools);
15
+ }
16
+ }
17
+ /**
18
+ * Registers one or more tools.
19
+ *
20
+ * @param tool - A single tool or array of tools to register
21
+ * @throws ToolValidationError If a tool's properties are invalid or its name is already registered
13
22
  */
14
- generateId(tool) {
15
- return tool;
23
+ add(tool) {
24
+ const tools = Array.isArray(tool) ? tool : [tool];
25
+ for (const t of tools) {
26
+ this._validate(t);
27
+ this._tools.set(t.name, t);
28
+ }
16
29
  }
17
30
  /**
18
- * Validates a tool before it is registered.
19
- * @override
20
- * @param tool - The tool to be validated.
21
- * @throws ValidationError If the tool's properties are invalid or its name is already registered.
31
+ * Retrieves a tool by name.
32
+ *
33
+ * @param name - The name of the tool to retrieve
34
+ * @returns The tool if found, otherwise undefined
22
35
  */
23
- validate(tool) {
24
- // Validate tool name is a string
36
+ get(name) {
37
+ return this._tools.get(name);
38
+ }
39
+ /**
40
+ * Removes a tool by name. No-op if the tool does not exist.
41
+ *
42
+ * @param name - The name of the tool to remove
43
+ */
44
+ remove(name) {
45
+ this._tools.delete(name);
46
+ }
47
+ /**
48
+ * Returns all registered tools.
49
+ *
50
+ * @returns Array of all registered tools
51
+ */
52
+ list() {
53
+ return Array.from(this._tools.values());
54
+ }
55
+ /**
56
+ * Validates a tool before registration.
57
+ *
58
+ * @param tool - The tool to validate
59
+ * @throws ToolValidationError If the tool's properties are invalid or its name is already registered
60
+ */
61
+ _validate(tool) {
25
62
  if (typeof tool.name !== 'string') {
26
- throw new ValidationError('Tool name must be a string');
63
+ throw new ToolValidationError('Tool name must be a string');
27
64
  }
28
- // Validate tool name length (1-64 characters)
29
65
  if (tool.name.length < 1 || tool.name.length > 64) {
30
- throw new ValidationError('Tool name must be between 1 and 64 characters');
66
+ throw new ToolValidationError('Tool name must be between 1 and 64 characters');
31
67
  }
32
- // Validate tool name pattern
33
68
  const validNamePattern = /^[a-zA-Z0-9_-]+$/;
34
69
  if (!validNamePattern.test(tool.name)) {
35
- throw new ValidationError('Tool name must contain only alphanumeric characters, hyphens, and underscores');
70
+ throw new ToolValidationError('Tool name must contain only alphanumeric characters, hyphens, and underscores');
36
71
  }
37
- // Validate tool description if present
38
72
  if (tool.description !== undefined && tool.description !== null) {
39
73
  if (typeof tool.description !== 'string' || tool.description.length < 1) {
40
- throw new ValidationError('Tool description must be a non-empty string');
74
+ throw new ToolValidationError('Tool description must be a non-empty string');
41
75
  }
42
76
  }
43
- // Check for duplicate names
44
- const hasDuplicate = this.values().some((t) => t.name === tool.name);
45
- if (hasDuplicate) {
46
- throw new ValidationError(`Tool with name '${tool.name}' already registered`);
77
+ if (this._tools.has(tool.name)) {
78
+ throw new ToolValidationError(`Tool with name '${tool.name}' already registered`);
47
79
  }
48
80
  }
49
- /**
50
- * Retrieves the first tool that matches the given name.
51
- *
52
- * @param name - The name of the tool to retrieve.
53
- * @returns The tool if found, otherwise undefined.
54
- */
55
- getByName(name) {
56
- return this.values().find((tool) => tool.name === name);
57
- }
58
- /**
59
- * Finds and removes the first tool that matches the given name.
60
- *
61
- * @param name - The name of the tool to remove.
62
- */
63
- removeByName(name) {
64
- this.findRemove((tool) => tool.name === name);
65
- }
66
- }
67
- // Unit tests
68
- if (import.meta.vitest) {
69
- const { describe, it, expect, beforeEach } = import.meta.vitest;
70
- // Mock Tool definition for testing purposes
71
- const createMockTool = (overrides = {}) => ({
72
- name: 'valid-tool',
73
- description: 'A valid tool description.',
74
- toolSpec: {
75
- name: 'valid-tool',
76
- description: 'A valid tool description.',
77
- inputSchema: { type: 'object', properties: {} },
78
- },
79
- stream: async function* () {
80
- // Mock stream implementation
81
- yield new ToolStreamEvent({ data: 'mock data' });
82
- return new ToolResultBlock({ toolUseId: '', status: 'success', content: [] });
83
- },
84
- ...overrides,
85
- });
86
- describe('ToolRegistry', () => {
87
- let registry;
88
- beforeEach(() => {
89
- registry = new ToolRegistry();
90
- });
91
- it('should register a valid tool successfully', () => {
92
- const tool = createMockTool();
93
- expect(() => registry.add(tool)).not.toThrow();
94
- expect(registry.values()).toHaveLength(1);
95
- expect(registry.values()[0]?.name).toBe('valid-tool');
96
- });
97
- it('should throw ValidationError for a duplicate tool name', () => {
98
- const tool1 = createMockTool({ name: 'duplicate-name' });
99
- const tool2 = createMockTool({ name: 'duplicate-name' });
100
- registry.add(tool1);
101
- expect(() => registry.add(tool2)).toThrow(ValidationError);
102
- expect(() => registry.add(tool2)).toThrow("Tool with name 'duplicate-name' already registered");
103
- });
104
- it('should throw ValidationError for an invalid tool name pattern', () => {
105
- const tool = createMockTool({ name: 'invalid name!' });
106
- expect(() => registry.add(tool)).toThrow(ValidationError);
107
- expect(() => registry.add(tool)).toThrow('Tool name must contain only alphanumeric characters, hyphens, and underscores');
108
- });
109
- it('should throw ValidationError for a tool name that is too long', () => {
110
- const longName = 'a'.repeat(65);
111
- const tool = createMockTool({ name: longName });
112
- expect(() => registry.add(tool)).toThrow(ValidationError);
113
- expect(() => registry.add(tool)).toThrow('Tool name must be between 1 and 64 characters');
114
- });
115
- it('should throw ValidationError for a tool name that is too short', () => {
116
- const tool = createMockTool({ name: '' });
117
- expect(() => registry.add(tool)).toThrow(ValidationError);
118
- expect(() => registry.add(tool)).toThrow('Tool name must be between 1 and 64 characters');
119
- });
120
- it('should throw ValidationError for an invalid description', () => {
121
- // @ts-expect-error - Testing invalid type for description
122
- const tool = createMockTool({ description: 123 });
123
- expect(() => registry.add(tool)).toThrow(ValidationError);
124
- expect(() => registry.add(tool)).toThrow('Tool description must be a non-empty string');
125
- });
126
- it('should throw ValidationError for an empty string description', () => {
127
- const tool = createMockTool({ description: '' });
128
- expect(() => registry.add(tool)).toThrow(ValidationError);
129
- expect(() => registry.add(tool)).toThrow('Tool description must be a non-empty string');
130
- });
131
- it('should allow a tool with a null or undefined description', () => {
132
- const tool1 = createMockTool();
133
- // @ts-expect-error - Testing explicit undefined description
134
- tool1.description = undefined;
135
- const tool2 = createMockTool();
136
- tool2.name = 'another-valid-tool';
137
- // @ts-expect-error - Testing explicit null description
138
- tool2.description = null;
139
- expect(() => registry.add(tool1)).not.toThrow();
140
- expect(() => registry.add(tool2)).not.toThrow();
141
- });
142
- it('should retrieve a tool by its name', () => {
143
- const tool = createMockTool({ name: 'find-me' });
144
- registry.add(tool);
145
- const foundTool = registry.getByName('find-me');
146
- expect(foundTool).toBe(tool);
147
- });
148
- it('should return undefined when getting a tool by a name that does not exist', () => {
149
- const foundTool = registry.getByName('non-existent');
150
- expect(foundTool).toBeUndefined();
151
- });
152
- it('should remove a tool by its name', () => {
153
- const tool = createMockTool({ name: 'remove-me' });
154
- registry.add(tool);
155
- expect(registry.getByName('remove-me')).toBeDefined();
156
- registry.removeByName('remove-me');
157
- expect(registry.getByName('remove-me')).toBeUndefined();
158
- });
159
- it('should not throw when removing a tool by a name that does not exist', () => {
160
- expect(() => registry.removeByName('non-existent')).not.toThrow();
161
- });
162
- it('should generate a valid ToolIdentifier', () => {
163
- const tool = createMockTool();
164
- const id = registry['generateId'](tool);
165
- expect(id).toBe(tool);
166
- });
167
- it('should register a tool with a name at the maximum length', () => {
168
- const longName = 'a'.repeat(64);
169
- const tool = createMockTool({ name: longName });
170
- expect(() => registry.add(tool)).not.toThrow();
171
- });
172
- it('should throw ValidationError for a non-string tool name', () => {
173
- // @ts-expect-error - Testing invalid type for name
174
- const tool = createMockTool({ name: 123 });
175
- expect(() => registry.add(tool)).toThrow(ValidationError);
176
- expect(() => registry.add(tool)).toThrow('Tool name must be a string');
177
- });
178
- });
179
81
  }
180
82
  //# sourceMappingURL=tool-registry.js.map