@strands-agents/sdk 0.0.1

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 (423) hide show
  1. package/LICENSE +175 -0
  2. package/README.md +185 -0
  3. package/dist/__fixtures__/model-test-helpers.d.ts +56 -0
  4. package/dist/__fixtures__/model-test-helpers.d.ts.map +1 -0
  5. package/dist/__fixtures__/model-test-helpers.js +85 -0
  6. package/dist/__fixtures__/model-test-helpers.js.map +1 -0
  7. package/dist/__fixtures__/tool-helpers.d.ts +15 -0
  8. package/dist/__fixtures__/tool-helpers.d.ts.map +1 -0
  9. package/dist/__fixtures__/tool-helpers.js +22 -0
  10. package/dist/__fixtures__/tool-helpers.js.map +1 -0
  11. package/dist/__tests__/errors.test.d.ts +2 -0
  12. package/dist/__tests__/errors.test.d.ts.map +1 -0
  13. package/dist/__tests__/errors.test.js +20 -0
  14. package/dist/__tests__/errors.test.js.map +1 -0
  15. package/dist/__tests__/index.test.d.ts +2 -0
  16. package/dist/__tests__/index.test.d.ts.map +1 -0
  17. package/dist/__tests__/index.test.js +27 -0
  18. package/dist/__tests__/index.test.js.map +1 -0
  19. package/dist/errors.d.ts +22 -0
  20. package/dist/errors.d.ts.map +1 -0
  21. package/dist/errors.js +25 -0
  22. package/dist/errors.js.map +1 -0
  23. package/dist/index.d.ts +19 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +17 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/models/__tests__/bedrock.test.d.ts +2 -0
  28. package/dist/models/__tests__/bedrock.test.d.ts.map +1 -0
  29. package/dist/models/__tests__/bedrock.test.js +1161 -0
  30. package/dist/models/__tests__/bedrock.test.js.map +1 -0
  31. package/dist/models/__tests__/model.test.d.ts +2 -0
  32. package/dist/models/__tests__/model.test.d.ts.map +1 -0
  33. package/dist/models/__tests__/model.test.js +297 -0
  34. package/dist/models/__tests__/model.test.js.map +1 -0
  35. package/dist/models/__tests__/openai.test.d.ts +2 -0
  36. package/dist/models/__tests__/openai.test.d.ts.map +1 -0
  37. package/dist/models/__tests__/openai.test.js +1016 -0
  38. package/dist/models/__tests__/openai.test.js.map +1 -0
  39. package/dist/models/__tests__/test-utils.d.ts +10 -0
  40. package/dist/models/__tests__/test-utils.d.ts.map +1 -0
  41. package/dist/models/__tests__/test-utils.js +17 -0
  42. package/dist/models/__tests__/test-utils.js.map +1 -0
  43. package/dist/models/bedrock.d.ts +272 -0
  44. package/dist/models/bedrock.d.ts.map +1 -0
  45. package/dist/models/bedrock.js +679 -0
  46. package/dist/models/bedrock.js.map +1 -0
  47. package/dist/models/model.d.ts +89 -0
  48. package/dist/models/model.d.ts.map +1 -0
  49. package/dist/models/model.js +122 -0
  50. package/dist/models/model.js.map +1 -0
  51. package/dist/models/openai.d.ts +262 -0
  52. package/dist/models/openai.d.ts.map +1 -0
  53. package/dist/models/openai.js +625 -0
  54. package/dist/models/openai.js.map +1 -0
  55. package/dist/models/streaming.d.ts +226 -0
  56. package/dist/models/streaming.d.ts.map +1 -0
  57. package/dist/models/streaming.js +2 -0
  58. package/dist/models/streaming.js.map +1 -0
  59. package/dist/src/__fixtures__/agent-helpers.d.ts +29 -0
  60. package/dist/src/__fixtures__/agent-helpers.d.ts.map +1 -0
  61. package/dist/src/__fixtures__/agent-helpers.js +19 -0
  62. package/dist/src/__fixtures__/agent-helpers.js.map +1 -0
  63. package/dist/src/__fixtures__/environment.d.ts +12 -0
  64. package/dist/src/__fixtures__/environment.d.ts.map +1 -0
  65. package/dist/src/__fixtures__/environment.js +12 -0
  66. package/dist/src/__fixtures__/environment.js.map +1 -0
  67. package/dist/src/__fixtures__/mock-hook-provider.d.ts +14 -0
  68. package/dist/src/__fixtures__/mock-hook-provider.d.ts.map +1 -0
  69. package/dist/src/__fixtures__/mock-hook-provider.js +33 -0
  70. package/dist/src/__fixtures__/mock-hook-provider.js.map +1 -0
  71. package/dist/src/__fixtures__/mock-message-model.d.ts +93 -0
  72. package/dist/src/__fixtures__/mock-message-model.d.ts.map +1 -0
  73. package/dist/src/__fixtures__/mock-message-model.js +226 -0
  74. package/dist/src/__fixtures__/mock-message-model.js.map +1 -0
  75. package/dist/src/__fixtures__/model-test-helpers.d.ts +56 -0
  76. package/dist/src/__fixtures__/model-test-helpers.d.ts.map +1 -0
  77. package/dist/src/__fixtures__/model-test-helpers.js +85 -0
  78. package/dist/src/__fixtures__/model-test-helpers.js.map +1 -0
  79. package/dist/src/__fixtures__/tool-helpers.d.ts +37 -0
  80. package/dist/src/__fixtures__/tool-helpers.d.ts.map +1 -0
  81. package/dist/src/__fixtures__/tool-helpers.js +78 -0
  82. package/dist/src/__fixtures__/tool-helpers.js.map +1 -0
  83. package/dist/src/__tests__/errors.test.d.ts +2 -0
  84. package/dist/src/__tests__/errors.test.d.ts.map +1 -0
  85. package/dist/src/__tests__/errors.test.js +64 -0
  86. package/dist/src/__tests__/errors.test.js.map +1 -0
  87. package/dist/src/__tests__/index.test.d.ts +2 -0
  88. package/dist/src/__tests__/index.test.d.ts.map +1 -0
  89. package/dist/src/__tests__/index.test.js +27 -0
  90. package/dist/src/__tests__/index.test.js.map +1 -0
  91. package/dist/src/__tests__/mcp.test.d.ts +2 -0
  92. package/dist/src/__tests__/mcp.test.d.ts.map +1 -0
  93. package/dist/src/__tests__/mcp.test.js +166 -0
  94. package/dist/src/__tests__/mcp.test.js.map +1 -0
  95. package/dist/src/agent/__tests__/agent.hook.test.d.ts +2 -0
  96. package/dist/src/agent/__tests__/agent.hook.test.d.ts.map +1 -0
  97. package/dist/src/agent/__tests__/agent.hook.test.js +250 -0
  98. package/dist/src/agent/__tests__/agent.hook.test.js.map +1 -0
  99. package/dist/src/agent/__tests__/agent.test.d.ts +2 -0
  100. package/dist/src/agent/__tests__/agent.test.d.ts.map +1 -0
  101. package/dist/src/agent/__tests__/agent.test.js +414 -0
  102. package/dist/src/agent/__tests__/agent.test.js.map +1 -0
  103. package/dist/src/agent/__tests__/printer.test.d.ts +2 -0
  104. package/dist/src/agent/__tests__/printer.test.d.ts.map +1 -0
  105. package/dist/src/agent/__tests__/printer.test.js +152 -0
  106. package/dist/src/agent/__tests__/printer.test.js.map +1 -0
  107. package/dist/src/agent/__tests__/state.test.d.ts +2 -0
  108. package/dist/src/agent/__tests__/state.test.d.ts.map +1 -0
  109. package/dist/src/agent/__tests__/state.test.js +231 -0
  110. package/dist/src/agent/__tests__/state.test.js.map +1 -0
  111. package/dist/src/agent/agent.d.ts +207 -0
  112. package/dist/src/agent/agent.d.ts.map +1 -0
  113. package/dist/src/agent/agent.js +481 -0
  114. package/dist/src/agent/agent.js.map +1 -0
  115. package/dist/src/agent/printer.d.ts +73 -0
  116. package/dist/src/agent/printer.d.ts.map +1 -0
  117. package/dist/src/agent/printer.js +145 -0
  118. package/dist/src/agent/printer.js.map +1 -0
  119. package/dist/src/agent/state.d.ts +102 -0
  120. package/dist/src/agent/state.d.ts.map +1 -0
  121. package/dist/src/agent/state.js +73 -0
  122. package/dist/src/agent/state.js.map +1 -0
  123. package/dist/src/agent/streaming.d.ts +91 -0
  124. package/dist/src/agent/streaming.d.ts.map +1 -0
  125. package/dist/src/agent/streaming.js +2 -0
  126. package/dist/src/agent/streaming.js.map +1 -0
  127. package/dist/src/conversation-manager/__tests__/conversation-manager.test.d.ts +2 -0
  128. package/dist/src/conversation-manager/__tests__/conversation-manager.test.d.ts.map +1 -0
  129. package/dist/src/conversation-manager/__tests__/conversation-manager.test.js +10 -0
  130. package/dist/src/conversation-manager/__tests__/conversation-manager.test.js.map +1 -0
  131. package/dist/src/conversation-manager/__tests__/null-conversation-manager.test.d.ts +2 -0
  132. package/dist/src/conversation-manager/__tests__/null-conversation-manager.test.d.ts.map +1 -0
  133. package/dist/src/conversation-manager/__tests__/null-conversation-manager.test.js +35 -0
  134. package/dist/src/conversation-manager/__tests__/null-conversation-manager.test.js.map +1 -0
  135. package/dist/src/conversation-manager/__tests__/sliding-window-conversation-manager.test.d.ts +2 -0
  136. package/dist/src/conversation-manager/__tests__/sliding-window-conversation-manager.test.d.ts.map +1 -0
  137. package/dist/src/conversation-manager/__tests__/sliding-window-conversation-manager.test.js +553 -0
  138. package/dist/src/conversation-manager/__tests__/sliding-window-conversation-manager.test.js.map +1 -0
  139. package/dist/src/conversation-manager/conversation-manager.d.ts +73 -0
  140. package/dist/src/conversation-manager/conversation-manager.d.ts.map +1 -0
  141. package/dist/src/conversation-manager/conversation-manager.js +24 -0
  142. package/dist/src/conversation-manager/conversation-manager.js.map +1 -0
  143. package/dist/src/conversation-manager/index.d.ts +8 -0
  144. package/dist/src/conversation-manager/index.d.ts.map +1 -0
  145. package/dist/src/conversation-manager/index.js +8 -0
  146. package/dist/src/conversation-manager/index.js.map +1 -0
  147. package/dist/src/conversation-manager/null-conversation-manager.d.ts +23 -0
  148. package/dist/src/conversation-manager/null-conversation-manager.d.ts.map +1 -0
  149. package/dist/src/conversation-manager/null-conversation-manager.js +23 -0
  150. package/dist/src/conversation-manager/null-conversation-manager.js.map +1 -0
  151. package/dist/src/conversation-manager/sliding-window-conversation-manager.d.ts +105 -0
  152. package/dist/src/conversation-manager/sliding-window-conversation-manager.d.ts.map +1 -0
  153. package/dist/src/conversation-manager/sliding-window-conversation-manager.js +212 -0
  154. package/dist/src/conversation-manager/sliding-window-conversation-manager.js.map +1 -0
  155. package/dist/src/errors.d.ts +83 -0
  156. package/dist/src/errors.d.ts.map +1 -0
  157. package/dist/src/errors.js +97 -0
  158. package/dist/src/errors.js.map +1 -0
  159. package/dist/src/hooks/__tests__/events.test.d.ts +2 -0
  160. package/dist/src/hooks/__tests__/events.test.d.ts.map +1 -0
  161. package/dist/src/hooks/__tests__/events.test.js +347 -0
  162. package/dist/src/hooks/__tests__/events.test.js.map +1 -0
  163. package/dist/src/hooks/__tests__/registry.test.d.ts +2 -0
  164. package/dist/src/hooks/__tests__/registry.test.d.ts.map +1 -0
  165. package/dist/src/hooks/__tests__/registry.test.js +154 -0
  166. package/dist/src/hooks/__tests__/registry.test.js.map +1 -0
  167. package/dist/src/hooks/events.d.ts +199 -0
  168. package/dist/src/hooks/events.d.ts.map +1 -0
  169. package/dist/src/hooks/events.js +191 -0
  170. package/dist/src/hooks/events.js.map +1 -0
  171. package/dist/src/hooks/index.d.ts +11 -0
  172. package/dist/src/hooks/index.d.ts.map +1 -0
  173. package/dist/src/hooks/index.js +11 -0
  174. package/dist/src/hooks/index.js.map +1 -0
  175. package/dist/src/hooks/registry.d.ts +65 -0
  176. package/dist/src/hooks/registry.d.ts.map +1 -0
  177. package/dist/src/hooks/registry.js +65 -0
  178. package/dist/src/hooks/registry.js.map +1 -0
  179. package/dist/src/hooks/types.d.ts +49 -0
  180. package/dist/src/hooks/types.d.ts.map +1 -0
  181. package/dist/src/hooks/types.js +2 -0
  182. package/dist/src/hooks/types.js.map +1 -0
  183. package/dist/src/index.d.ts +32 -0
  184. package/dist/src/index.d.ts.map +1 -0
  185. package/dist/src/index.js +29 -0
  186. package/dist/src/index.js.map +1 -0
  187. package/dist/src/mcp.d.ts +51 -0
  188. package/dist/src/mcp.d.ts.map +1 -0
  189. package/dist/src/mcp.js +91 -0
  190. package/dist/src/mcp.js.map +1 -0
  191. package/dist/src/models/__tests__/bedrock.test.d.ts +2 -0
  192. package/dist/src/models/__tests__/bedrock.test.d.ts.map +1 -0
  193. package/dist/src/models/__tests__/bedrock.test.js +1388 -0
  194. package/dist/src/models/__tests__/bedrock.test.js.map +1 -0
  195. package/dist/src/models/__tests__/model.test.d.ts +2 -0
  196. package/dist/src/models/__tests__/model.test.d.ts.map +1 -0
  197. package/dist/src/models/__tests__/model.test.js +342 -0
  198. package/dist/src/models/__tests__/model.test.js.map +1 -0
  199. package/dist/src/models/__tests__/openai.test.d.ts +2 -0
  200. package/dist/src/models/__tests__/openai.test.d.ts.map +1 -0
  201. package/dist/src/models/__tests__/openai.test.js +1189 -0
  202. package/dist/src/models/__tests__/openai.test.js.map +1 -0
  203. package/dist/src/models/__tests__/test-utils.d.ts +10 -0
  204. package/dist/src/models/__tests__/test-utils.d.ts.map +1 -0
  205. package/dist/src/models/__tests__/test-utils.js +17 -0
  206. package/dist/src/models/__tests__/test-utils.js.map +1 -0
  207. package/dist/src/models/bedrock.d.ts +289 -0
  208. package/dist/src/models/bedrock.d.ts.map +1 -0
  209. package/dist/src/models/bedrock.js +804 -0
  210. package/dist/src/models/bedrock.js.map +1 -0
  211. package/dist/src/models/model.d.ts +99 -0
  212. package/dist/src/models/model.d.ts.map +1 -0
  213. package/dist/src/models/model.js +169 -0
  214. package/dist/src/models/model.js.map +1 -0
  215. package/dist/src/models/openai.d.ts +262 -0
  216. package/dist/src/models/openai.d.ts.map +1 -0
  217. package/dist/src/models/openai.js +752 -0
  218. package/dist/src/models/openai.js.map +1 -0
  219. package/dist/src/models/streaming.d.ts +318 -0
  220. package/dist/src/models/streaming.d.ts.map +1 -0
  221. package/dist/src/models/streaming.js +122 -0
  222. package/dist/src/models/streaming.js.map +1 -0
  223. package/dist/src/registry/registry.d.ts +117 -0
  224. package/dist/src/registry/registry.d.ts.map +1 -0
  225. package/dist/src/registry/registry.js +298 -0
  226. package/dist/src/registry/registry.js.map +1 -0
  227. package/dist/src/registry/tool-registry.d.ts +34 -0
  228. package/dist/src/registry/tool-registry.d.ts.map +1 -0
  229. package/dist/src/registry/tool-registry.js +178 -0
  230. package/dist/src/registry/tool-registry.js.map +1 -0
  231. package/dist/src/tools/__tests__/tool.test.d.ts +2 -0
  232. package/dist/src/tools/__tests__/tool.test.d.ts.map +1 -0
  233. package/dist/src/tools/__tests__/tool.test.js +877 -0
  234. package/dist/src/tools/__tests__/tool.test.js.map +1 -0
  235. package/dist/src/tools/__tests__/zod-tool.test-d.d.ts +2 -0
  236. package/dist/src/tools/__tests__/zod-tool.test-d.d.ts.map +1 -0
  237. package/dist/src/tools/__tests__/zod-tool.test-d.js +227 -0
  238. package/dist/src/tools/__tests__/zod-tool.test-d.js.map +1 -0
  239. package/dist/src/tools/__tests__/zod-tool.test.d.ts +2 -0
  240. package/dist/src/tools/__tests__/zod-tool.test.d.ts.map +1 -0
  241. package/dist/src/tools/__tests__/zod-tool.test.js +372 -0
  242. package/dist/src/tools/__tests__/zod-tool.test.js.map +1 -0
  243. package/dist/src/tools/function-tool.d.ts +146 -0
  244. package/dist/src/tools/function-tool.d.ts.map +1 -0
  245. package/dist/src/tools/function-tool.js +188 -0
  246. package/dist/src/tools/function-tool.js.map +1 -0
  247. package/dist/src/tools/mcp-tool.d.ts +36 -0
  248. package/dist/src/tools/mcp-tool.d.ts.map +1 -0
  249. package/dist/src/tools/mcp-tool.js +78 -0
  250. package/dist/src/tools/mcp-tool.js.map +1 -0
  251. package/dist/src/tools/tool.d.ts +167 -0
  252. package/dist/src/tools/tool.d.ts.map +1 -0
  253. package/dist/src/tools/tool.js +68 -0
  254. package/dist/src/tools/tool.js.map +1 -0
  255. package/dist/src/tools/types.d.ts +62 -0
  256. package/dist/src/tools/types.d.ts.map +1 -0
  257. package/dist/src/tools/types.js +2 -0
  258. package/dist/src/tools/types.js.map +1 -0
  259. package/dist/src/tools/zod-tool.d.ts +70 -0
  260. package/dist/src/tools/zod-tool.d.ts.map +1 -0
  261. package/dist/src/tools/zod-tool.js +149 -0
  262. package/dist/src/tools/zod-tool.js.map +1 -0
  263. package/dist/src/types/__tests__/agent.test.d.ts +2 -0
  264. package/dist/src/types/__tests__/agent.test.d.ts.map +1 -0
  265. package/dist/src/types/__tests__/agent.test.js +155 -0
  266. package/dist/src/types/__tests__/agent.test.js.map +1 -0
  267. package/dist/src/types/__tests__/json.test.d.ts +2 -0
  268. package/dist/src/types/__tests__/json.test.d.ts.map +1 -0
  269. package/dist/src/types/__tests__/json.test.js +298 -0
  270. package/dist/src/types/__tests__/json.test.js.map +1 -0
  271. package/dist/src/types/__tests__/media.test.d.ts +2 -0
  272. package/dist/src/types/__tests__/media.test.d.ts.map +1 -0
  273. package/dist/src/types/__tests__/media.test.js +257 -0
  274. package/dist/src/types/__tests__/media.test.js.map +1 -0
  275. package/dist/src/types/__tests__/messages.test.d.ts +2 -0
  276. package/dist/src/types/__tests__/messages.test.d.ts.map +1 -0
  277. package/dist/src/types/__tests__/messages.test.js +364 -0
  278. package/dist/src/types/__tests__/messages.test.js.map +1 -0
  279. package/dist/src/types/__tests__/validation.test.d.ts +2 -0
  280. package/dist/src/types/__tests__/validation.test.d.ts.map +1 -0
  281. package/dist/src/types/__tests__/validation.test.js +30 -0
  282. package/dist/src/types/__tests__/validation.test.js.map +1 -0
  283. package/dist/src/types/agent.d.ts +57 -0
  284. package/dist/src/types/agent.d.ts.map +1 -0
  285. package/dist/src/types/agent.js +47 -0
  286. package/dist/src/types/agent.js.map +1 -0
  287. package/dist/src/types/json.d.ts +55 -0
  288. package/dist/src/types/json.d.ts.map +1 -0
  289. package/dist/src/types/json.js +72 -0
  290. package/dist/src/types/json.js.map +1 -0
  291. package/dist/src/types/media.d.ts +249 -0
  292. package/dist/src/types/media.d.ts.map +1 -0
  293. package/dist/src/types/media.js +173 -0
  294. package/dist/src/types/media.js.map +1 -0
  295. package/dist/src/types/messages.d.ts +438 -0
  296. package/dist/src/types/messages.d.ts.map +1 -0
  297. package/dist/src/types/messages.js +286 -0
  298. package/dist/src/types/messages.js.map +1 -0
  299. package/dist/src/types/validation.d.ts +10 -0
  300. package/dist/src/types/validation.d.ts.map +1 -0
  301. package/dist/src/types/validation.js +15 -0
  302. package/dist/src/types/validation.js.map +1 -0
  303. package/dist/tools/__tests__/registry.test.d.ts +2 -0
  304. package/dist/tools/__tests__/registry.test.d.ts.map +1 -0
  305. package/dist/tools/__tests__/registry.test.js +253 -0
  306. package/dist/tools/__tests__/registry.test.js.map +1 -0
  307. package/dist/tools/__tests__/tool.test.d.ts +2 -0
  308. package/dist/tools/__tests__/tool.test.d.ts.map +1 -0
  309. package/dist/tools/__tests__/tool.test.js +761 -0
  310. package/dist/tools/__tests__/tool.test.js.map +1 -0
  311. package/dist/tools/__tests__/zod-tool.test-d.d.ts +2 -0
  312. package/dist/tools/__tests__/zod-tool.test-d.d.ts.map +1 -0
  313. package/dist/tools/__tests__/zod-tool.test-d.js +227 -0
  314. package/dist/tools/__tests__/zod-tool.test-d.js.map +1 -0
  315. package/dist/tools/__tests__/zod-tool.test.d.ts +2 -0
  316. package/dist/tools/__tests__/zod-tool.test.d.ts.map +1 -0
  317. package/dist/tools/__tests__/zod-tool.test.js +342 -0
  318. package/dist/tools/__tests__/zod-tool.test.js.map +1 -0
  319. package/dist/tools/function-tool.d.ts +156 -0
  320. package/dist/tools/function-tool.d.ts.map +1 -0
  321. package/dist/tools/function-tool.js +237 -0
  322. package/dist/tools/function-tool.js.map +1 -0
  323. package/dist/tools/registry.d.ts +43 -0
  324. package/dist/tools/registry.d.ts.map +1 -0
  325. package/dist/tools/registry.js +82 -0
  326. package/dist/tools/registry.js.map +1 -0
  327. package/dist/tools/tool.d.ts +157 -0
  328. package/dist/tools/tool.d.ts.map +1 -0
  329. package/dist/tools/tool.js +2 -0
  330. package/dist/tools/tool.js.map +1 -0
  331. package/dist/tools/types.d.ts +119 -0
  332. package/dist/tools/types.d.ts.map +1 -0
  333. package/dist/tools/types.js +2 -0
  334. package/dist/tools/types.js.map +1 -0
  335. package/dist/tools/zod-tool.d.ts +70 -0
  336. package/dist/tools/zod-tool.d.ts.map +1 -0
  337. package/dist/tools/zod-tool.js +96 -0
  338. package/dist/tools/zod-tool.js.map +1 -0
  339. package/dist/types/__tests__/json.test.d.ts +2 -0
  340. package/dist/types/__tests__/json.test.d.ts.map +1 -0
  341. package/dist/types/__tests__/json.test.js +129 -0
  342. package/dist/types/__tests__/json.test.js.map +1 -0
  343. package/dist/types/__tests__/validation.test.d.ts +2 -0
  344. package/dist/types/__tests__/validation.test.d.ts.map +1 -0
  345. package/dist/types/__tests__/validation.test.js +30 -0
  346. package/dist/types/__tests__/validation.test.js.map +1 -0
  347. package/dist/types/json.d.ts +45 -0
  348. package/dist/types/json.d.ts.map +1 -0
  349. package/dist/types/json.js +17 -0
  350. package/dist/types/json.js.map +1 -0
  351. package/dist/types/messages.d.ts +160 -0
  352. package/dist/types/messages.d.ts.map +1 -0
  353. package/dist/types/messages.js +2 -0
  354. package/dist/types/messages.js.map +1 -0
  355. package/dist/types/validation.d.ts +10 -0
  356. package/dist/types/validation.d.ts.map +1 -0
  357. package/dist/types/validation.js +15 -0
  358. package/dist/types/validation.js.map +1 -0
  359. package/dist/vended_tools/bash/__tests__/bash.test.d.ts +2 -0
  360. package/dist/vended_tools/bash/__tests__/bash.test.d.ts.map +1 -0
  361. package/dist/vended_tools/bash/__tests__/bash.test.js +333 -0
  362. package/dist/vended_tools/bash/__tests__/bash.test.js.map +1 -0
  363. package/dist/vended_tools/bash/bash.d.ts +33 -0
  364. package/dist/vended_tools/bash/bash.d.ts.map +1 -0
  365. package/dist/vended_tools/bash/bash.js +264 -0
  366. package/dist/vended_tools/bash/bash.js.map +1 -0
  367. package/dist/vended_tools/bash/index.d.ts +7 -0
  368. package/dist/vended_tools/bash/index.d.ts.map +1 -0
  369. package/dist/vended_tools/bash/index.js +6 -0
  370. package/dist/vended_tools/bash/index.js.map +1 -0
  371. package/dist/vended_tools/bash/types.d.ts +65 -0
  372. package/dist/vended_tools/bash/types.d.ts.map +1 -0
  373. package/dist/vended_tools/bash/types.js +22 -0
  374. package/dist/vended_tools/bash/types.js.map +1 -0
  375. package/dist/vended_tools/file_editor/__tests__/file-editor.test.d.ts +2 -0
  376. package/dist/vended_tools/file_editor/__tests__/file-editor.test.d.ts.map +1 -0
  377. package/dist/vended_tools/file_editor/__tests__/file-editor.test.js +359 -0
  378. package/dist/vended_tools/file_editor/__tests__/file-editor.test.js.map +1 -0
  379. package/dist/vended_tools/file_editor/file-editor.d.ts +31 -0
  380. package/dist/vended_tools/file_editor/file-editor.d.ts.map +1 -0
  381. package/dist/vended_tools/file_editor/file-editor.js +353 -0
  382. package/dist/vended_tools/file_editor/file-editor.js.map +1 -0
  383. package/dist/vended_tools/file_editor/index.d.ts +6 -0
  384. package/dist/vended_tools/file_editor/index.d.ts.map +1 -0
  385. package/dist/vended_tools/file_editor/index.js +5 -0
  386. package/dist/vended_tools/file_editor/index.js.map +1 -0
  387. package/dist/vended_tools/file_editor/types.d.ts +61 -0
  388. package/dist/vended_tools/file_editor/types.d.ts.map +1 -0
  389. package/dist/vended_tools/file_editor/types.js +2 -0
  390. package/dist/vended_tools/file_editor/types.js.map +1 -0
  391. package/dist/vended_tools/http_request/__tests__/http-request.test.d.ts +2 -0
  392. package/dist/vended_tools/http_request/__tests__/http-request.test.d.ts.map +1 -0
  393. package/dist/vended_tools/http_request/__tests__/http-request.test.js +189 -0
  394. package/dist/vended_tools/http_request/__tests__/http-request.test.js.map +1 -0
  395. package/dist/vended_tools/http_request/http-request.d.ts +35 -0
  396. package/dist/vended_tools/http_request/http-request.d.ts.map +1 -0
  397. package/dist/vended_tools/http_request/http-request.js +95 -0
  398. package/dist/vended_tools/http_request/http-request.js.map +1 -0
  399. package/dist/vended_tools/http_request/index.d.ts +6 -0
  400. package/dist/vended_tools/http_request/index.d.ts.map +1 -0
  401. package/dist/vended_tools/http_request/index.js +5 -0
  402. package/dist/vended_tools/http_request/index.js.map +1 -0
  403. package/dist/vended_tools/http_request/types.d.ts +47 -0
  404. package/dist/vended_tools/http_request/types.d.ts.map +1 -0
  405. package/dist/vended_tools/http_request/types.js +2 -0
  406. package/dist/vended_tools/http_request/types.js.map +1 -0
  407. package/dist/vended_tools/notebook/__tests__/notebook.test.d.ts +2 -0
  408. package/dist/vended_tools/notebook/__tests__/notebook.test.d.ts.map +1 -0
  409. package/dist/vended_tools/notebook/__tests__/notebook.test.js +371 -0
  410. package/dist/vended_tools/notebook/__tests__/notebook.test.js.map +1 -0
  411. package/dist/vended_tools/notebook/index.d.ts +6 -0
  412. package/dist/vended_tools/notebook/index.d.ts.map +1 -0
  413. package/dist/vended_tools/notebook/index.js +5 -0
  414. package/dist/vended_tools/notebook/index.js.map +1 -0
  415. package/dist/vended_tools/notebook/notebook.d.ts +29 -0
  416. package/dist/vended_tools/notebook/notebook.d.ts.map +1 -0
  417. package/dist/vended_tools/notebook/notebook.js +215 -0
  418. package/dist/vended_tools/notebook/notebook.js.map +1 -0
  419. package/dist/vended_tools/notebook/types.d.ts +79 -0
  420. package/dist/vended_tools/notebook/types.d.ts.map +1 -0
  421. package/dist/vended_tools/notebook/types.js +2 -0
  422. package/dist/vended_tools/notebook/types.js.map +1 -0
  423. package/package.json +112 -0
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Abstract interface for conversation history management.
3
+ *
4
+ * This module provides the base class for implementing conversation management strategies
5
+ * to control the size of message arrays, helping to manage memory usage, control context
6
+ * length, and maintain relevant conversation state.
7
+ */
8
+ import type { Message } from '../types/messages.js';
9
+ /**
10
+ * Interface for conversation context that can be managed.
11
+ *
12
+ * This interface defines the minimal set of properties required by conversation managers
13
+ * to perform their operations. Using an interface allows for backwards-compatible
14
+ * API evolution and better decoupling from specific implementations.
15
+ */
16
+ export interface ConversationContext {
17
+ /**
18
+ * The conversation history of messages that will be managed.
19
+ * This array is modified in-place by conversation management operations.
20
+ */
21
+ messages: Message[];
22
+ }
23
+ /**
24
+ * Abstract base class for managing conversation history.
25
+ *
26
+ * This class provides an interface for implementing conversation management strategies
27
+ * to control the size of message arrays/conversation histories, helping to:
28
+ *
29
+ * - Manage memory usage
30
+ * - Control context length
31
+ * - Maintain relevant conversation state
32
+ */
33
+ export declare abstract class ConversationManager {
34
+ /**
35
+ * Creates a new ConversationManager instance.
36
+ */
37
+ constructor();
38
+ /**
39
+ * Applies management strategy to the provided conversation context.
40
+ *
41
+ * Processes the conversation history to maintain appropriate size by modifying
42
+ * the messages list in-place. Implementations should handle message pruning,
43
+ * summarization, or other size management techniques to keep the conversation
44
+ * context within desired bounds.
45
+ *
46
+ * @param context - The conversation context whose message history will be managed.
47
+ * The messages array is modified in-place.
48
+ */
49
+ abstract applyManagement(context: ConversationContext): void;
50
+ /**
51
+ * Called when the model's context window is exceeded.
52
+ *
53
+ * This method should implement the specific strategy for reducing the window size
54
+ * when a context overflow occurs. It is typically called after a ContextWindowOverflowError
55
+ * is caught during model invocation.
56
+ *
57
+ * Implementations might use strategies such as:
58
+ * - Removing the N oldest messages
59
+ * - Summarizing older context
60
+ * - Applying importance-based filtering
61
+ * - Maintaining critical conversation markers
62
+ *
63
+ * @param context - The conversation context whose message history will be reduced.
64
+ * The messages array is modified in-place.
65
+ * @param error - The error that triggered the context reduction, if any.
66
+ *
67
+ * @throws ContextWindowOverflowError If the context cannot be reduced further,
68
+ * such as when the conversation is already minimal or when tool result
69
+ * messages cannot be properly converted.
70
+ */
71
+ abstract reduceContext(context: ConversationContext, error?: Error): void;
72
+ }
73
+ //# sourceMappingURL=conversation-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conversation-manager.d.ts","sourceRoot":"","sources":["../../../src/conversation-manager/conversation-manager.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAEnD;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,QAAQ,EAAE,OAAO,EAAE,CAAA;CACpB;AAED;;;;;;;;;GASG;AACH,8BAAsB,mBAAmB;IACvC;;OAEG;;IAGH;;;;;;;;;;OAUG;aACa,eAAe,CAAC,OAAO,EAAE,mBAAmB,GAAG,IAAI;IAEnE;;;;;;;;;;;;;;;;;;;;OAoBG;aACa,aAAa,CAAC,OAAO,EAAE,mBAAmB,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI;CACjF"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Abstract interface for conversation history management.
3
+ *
4
+ * This module provides the base class for implementing conversation management strategies
5
+ * to control the size of message arrays, helping to manage memory usage, control context
6
+ * length, and maintain relevant conversation state.
7
+ */
8
+ /**
9
+ * Abstract base class for managing conversation history.
10
+ *
11
+ * This class provides an interface for implementing conversation management strategies
12
+ * to control the size of message arrays/conversation histories, helping to:
13
+ *
14
+ * - Manage memory usage
15
+ * - Control context length
16
+ * - Maintain relevant conversation state
17
+ */
18
+ export class ConversationManager {
19
+ /**
20
+ * Creates a new ConversationManager instance.
21
+ */
22
+ constructor() { }
23
+ }
24
+ //# sourceMappingURL=conversation-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conversation-manager.js","sourceRoot":"","sources":["../../../src/conversation-manager/conversation-manager.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAmBH;;;;;;;;;GASG;AACH,MAAM,OAAgB,mBAAmB;IACvC;;OAEG;IACH,gBAAe,CAAC;CAqCjB"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Conversation Manager exports.
3
+ *
4
+ * This module exports conversation manager implementations.
5
+ */
6
+ export { NullConversationManager } from './null-conversation-manager.js';
7
+ export { SlidingWindowConversationManager, type SlidingWindowConversationManagerConfig, } from './sliding-window-conversation-manager.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/conversation-manager/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAA;AACxE,OAAO,EACL,gCAAgC,EAChC,KAAK,sCAAsC,GAC5C,MAAM,0CAA0C,CAAA"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Conversation Manager exports.
3
+ *
4
+ * This module exports conversation manager implementations.
5
+ */
6
+ export { NullConversationManager } from './null-conversation-manager.js';
7
+ export { SlidingWindowConversationManager, } from './sliding-window-conversation-manager.js';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/conversation-manager/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAA;AACxE,OAAO,EACL,gCAAgC,GAEjC,MAAM,0CAA0C,CAAA"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Null implementation of conversation management.
3
+ *
4
+ * This module provides a no-op conversation manager that does not modify
5
+ * the conversation history. Useful for testing and scenarios where conversation
6
+ * management is handled externally.
7
+ */
8
+ import type { HookProvider } from '../hooks/types.js';
9
+ import type { HookRegistry } from '../hooks/registry.js';
10
+ /**
11
+ * A no-op conversation manager that does not modify the conversation history.
12
+ * Implements HookProvider but registers zero hooks.
13
+ */
14
+ export declare class NullConversationManager implements HookProvider {
15
+ /**
16
+ * Registers callbacks with the hook registry.
17
+ * This implementation registers no hooks, providing a complete no-op behavior.
18
+ *
19
+ * @param _registry - The hook registry to register callbacks with (unused)
20
+ */
21
+ registerCallbacks(_registry: HookRegistry): void;
22
+ }
23
+ //# sourceMappingURL=null-conversation-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"null-conversation-manager.d.ts","sourceRoot":"","sources":["../../../src/conversation-manager/null-conversation-manager.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAExD;;;GAGG;AACH,qBAAa,uBAAwB,YAAW,YAAY;IAC1D;;;;;OAKG;IACI,iBAAiB,CAAC,SAAS,EAAE,YAAY,GAAG,IAAI;CAGxD"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Null implementation of conversation management.
3
+ *
4
+ * This module provides a no-op conversation manager that does not modify
5
+ * the conversation history. Useful for testing and scenarios where conversation
6
+ * management is handled externally.
7
+ */
8
+ /**
9
+ * A no-op conversation manager that does not modify the conversation history.
10
+ * Implements HookProvider but registers zero hooks.
11
+ */
12
+ export class NullConversationManager {
13
+ /**
14
+ * Registers callbacks with the hook registry.
15
+ * This implementation registers no hooks, providing a complete no-op behavior.
16
+ *
17
+ * @param _registry - The hook registry to register callbacks with (unused)
18
+ */
19
+ registerCallbacks(_registry) {
20
+ // No-op - register zero hooks
21
+ }
22
+ }
23
+ //# sourceMappingURL=null-conversation-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"null-conversation-manager.js","sourceRoot":"","sources":["../../../src/conversation-manager/null-conversation-manager.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH;;;GAGG;AACH,MAAM,OAAO,uBAAuB;IAClC;;;;;OAKG;IACI,iBAAiB,CAAC,SAAuB;QAC9C,8BAA8B;IAChC,CAAC;CACF"}
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Sliding window conversation history management.
3
+ *
4
+ * This module provides a sliding window strategy for managing conversation history
5
+ * that preserves tool usage pairs and avoids invalid window states.
6
+ */
7
+ import type { HookProvider } from '../hooks/types.js';
8
+ import type { HookRegistry } from '../hooks/registry.js';
9
+ /**
10
+ * Configuration for the sliding window conversation manager.
11
+ */
12
+ export type SlidingWindowConversationManagerConfig = {
13
+ /**
14
+ * Maximum number of messages to keep in the conversation history.
15
+ * Defaults to 40 messages.
16
+ */
17
+ windowSize?: number;
18
+ /**
19
+ * Whether to truncate tool results when a message is too large for the model's context window.
20
+ * Defaults to true.
21
+ */
22
+ shouldTruncateResults?: boolean;
23
+ };
24
+ /**
25
+ * Implements a sliding window strategy for managing conversation history.
26
+ *
27
+ * This class handles the logic of maintaining a conversation window that preserves
28
+ * tool usage pairs and avoids invalid window states. When the message count exceeds
29
+ * the window size, it will either truncate large tool results or remove the oldest
30
+ * messages while ensuring tool use/result pairs remain valid.
31
+ *
32
+ * As a HookProvider, it registers callbacks for:
33
+ * - AfterInvocationEvent: Applies sliding window management after each invocation
34
+ * - AfterModelCallEvent: Reduces context on overflow errors and requests retry
35
+ */
36
+ export declare class SlidingWindowConversationManager implements HookProvider {
37
+ private readonly _windowSize;
38
+ private readonly _shouldTruncateResults;
39
+ /**
40
+ * Initialize the sliding window conversation manager.
41
+ *
42
+ * @param config - Configuration options for the sliding window manager.
43
+ */
44
+ constructor(config?: SlidingWindowConversationManagerConfig);
45
+ /**
46
+ * Registers callbacks with the hook registry.
47
+ *
48
+ * Registers:
49
+ * - AfterInvocationEvent callback to apply sliding window management
50
+ * - AfterModelCallEvent callback to handle context overflow and request retry
51
+ *
52
+ * @param registry - The hook registry to register callbacks with
53
+ */
54
+ registerCallbacks(registry: HookRegistry): void;
55
+ /**
56
+ * Apply the sliding window to the messages array to maintain a manageable history size.
57
+ *
58
+ * This method is called after every event loop cycle to apply a sliding window if the message
59
+ * count exceeds the window size. If the number of messages is within the window size, no action
60
+ * is taken.
61
+ *
62
+ * @param messages - The message array to manage. Modified in-place.
63
+ */
64
+ private applyManagement;
65
+ /**
66
+ * Trim the oldest messages to reduce the conversation context size.
67
+ *
68
+ * The method handles special cases where trimming the messages leads to:
69
+ * - toolResult with no corresponding toolUse
70
+ * - toolUse with no corresponding toolResult
71
+ *
72
+ * The strategy is:
73
+ * 1. First, attempt to truncate large tool results if shouldTruncateResults is true
74
+ * 2. If truncation is not possible or doesn't help, trim oldest messages
75
+ * 3. When trimming, skip invalid trim points (toolResult at start, or toolUse without following toolResult)
76
+ *
77
+ * @param messages - The message array to reduce. Modified in-place.
78
+ * @param _error - The error that triggered the context reduction, if any.
79
+ *
80
+ * @throws ContextWindowOverflowError If the context cannot be reduced further,
81
+ * such as when the conversation is already minimal or when no valid trim point exists.
82
+ */
83
+ private reduceContext;
84
+ /**
85
+ * Truncate tool results in a message to reduce context size.
86
+ *
87
+ * When a message contains tool results that are too large for the model's context window,
88
+ * this function replaces the content of those tool results with a simple error message.
89
+ *
90
+ * @param messages - The conversation message history.
91
+ * @param msgIdx - Index of the message containing tool results to truncate.
92
+ * @returns True if any changes were made to the message, false otherwise.
93
+ */
94
+ private truncateToolResults;
95
+ /**
96
+ * Find the index of the last message containing tool results.
97
+ *
98
+ * This is useful for identifying messages that might need to be truncated to reduce context size.
99
+ *
100
+ * @param messages - The conversation message history.
101
+ * @returns Index of the last message with tool results, or undefined if no such message exists.
102
+ */
103
+ private findLastMessageWithToolResults;
104
+ }
105
+ //# sourceMappingURL=sliding-window-conversation-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sliding-window-conversation-manager.d.ts","sourceRoot":"","sources":["../../../src/conversation-manager/sliding-window-conversation-manager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAGxD;;GAEG;AACH,MAAM,MAAM,sCAAsC,GAAG;IACnD;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IAEnB;;;OAGG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAChC,CAAA;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,gCAAiC,YAAW,YAAY;IACnE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAQ;IACpC,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAS;IAEhD;;;;OAIG;gBACS,MAAM,CAAC,EAAE,sCAAsC;IAK3D;;;;;;;;OAQG;IACI,iBAAiB,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI;IAetD;;;;;;;;OAQG;IACH,OAAO,CAAC,eAAe;IAQvB;;;;;;;;;;;;;;;;;OAiBG;IACH,OAAO,CAAC,aAAa;IAuDrB;;;;;;;;;OASG;IACH,OAAO,CAAC,mBAAmB;IA0D3B;;;;;;;OAOG;IACH,OAAO,CAAC,8BAA8B;CAcvC"}
@@ -0,0 +1,212 @@
1
+ /**
2
+ * Sliding window conversation history management.
3
+ *
4
+ * This module provides a sliding window strategy for managing conversation history
5
+ * that preserves tool usage pairs and avoids invalid window states.
6
+ */
7
+ import { ContextWindowOverflowError } from '../errors.js';
8
+ import { Message, TextBlock, ToolResultBlock } from '../types/messages.js';
9
+ import { AfterInvocationEvent, AfterModelCallEvent } from '../hooks/events.js';
10
+ /**
11
+ * Implements a sliding window strategy for managing conversation history.
12
+ *
13
+ * This class handles the logic of maintaining a conversation window that preserves
14
+ * tool usage pairs and avoids invalid window states. When the message count exceeds
15
+ * the window size, it will either truncate large tool results or remove the oldest
16
+ * messages while ensuring tool use/result pairs remain valid.
17
+ *
18
+ * As a HookProvider, it registers callbacks for:
19
+ * - AfterInvocationEvent: Applies sliding window management after each invocation
20
+ * - AfterModelCallEvent: Reduces context on overflow errors and requests retry
21
+ */
22
+ export class SlidingWindowConversationManager {
23
+ _windowSize;
24
+ _shouldTruncateResults;
25
+ /**
26
+ * Initialize the sliding window conversation manager.
27
+ *
28
+ * @param config - Configuration options for the sliding window manager.
29
+ */
30
+ constructor(config) {
31
+ this._windowSize = config?.windowSize ?? 40;
32
+ this._shouldTruncateResults = config?.shouldTruncateResults ?? true;
33
+ }
34
+ /**
35
+ * Registers callbacks with the hook registry.
36
+ *
37
+ * Registers:
38
+ * - AfterInvocationEvent callback to apply sliding window management
39
+ * - AfterModelCallEvent callback to handle context overflow and request retry
40
+ *
41
+ * @param registry - The hook registry to register callbacks with
42
+ */
43
+ registerCallbacks(registry) {
44
+ // Apply sliding window management after each invocation
45
+ registry.addCallback(AfterInvocationEvent, (event) => {
46
+ this.applyManagement(event.agent.messages);
47
+ });
48
+ // Handle context overflow errors
49
+ registry.addCallback(AfterModelCallEvent, (event) => {
50
+ if (event.error instanceof ContextWindowOverflowError) {
51
+ this.reduceContext(event.agent.messages, event.error);
52
+ event.retryModelCall = true;
53
+ }
54
+ });
55
+ }
56
+ /**
57
+ * Apply the sliding window to the messages array to maintain a manageable history size.
58
+ *
59
+ * This method is called after every event loop cycle to apply a sliding window if the message
60
+ * count exceeds the window size. If the number of messages is within the window size, no action
61
+ * is taken.
62
+ *
63
+ * @param messages - The message array to manage. Modified in-place.
64
+ */
65
+ applyManagement(messages) {
66
+ if (messages.length <= this._windowSize) {
67
+ return;
68
+ }
69
+ this.reduceContext(messages);
70
+ }
71
+ /**
72
+ * Trim the oldest messages to reduce the conversation context size.
73
+ *
74
+ * The method handles special cases where trimming the messages leads to:
75
+ * - toolResult with no corresponding toolUse
76
+ * - toolUse with no corresponding toolResult
77
+ *
78
+ * The strategy is:
79
+ * 1. First, attempt to truncate large tool results if shouldTruncateResults is true
80
+ * 2. If truncation is not possible or doesn't help, trim oldest messages
81
+ * 3. When trimming, skip invalid trim points (toolResult at start, or toolUse without following toolResult)
82
+ *
83
+ * @param messages - The message array to reduce. Modified in-place.
84
+ * @param _error - The error that triggered the context reduction, if any.
85
+ *
86
+ * @throws ContextWindowOverflowError If the context cannot be reduced further,
87
+ * such as when the conversation is already minimal or when no valid trim point exists.
88
+ */
89
+ reduceContext(messages, _error) {
90
+ // Only truncate tool results when handling a context overflow error, not for window size enforcement
91
+ const lastMessageIdxWithToolResults = this.findLastMessageWithToolResults(messages);
92
+ if (_error && lastMessageIdxWithToolResults !== undefined && this._shouldTruncateResults) {
93
+ const resultsTruncated = this.truncateToolResults(messages, lastMessageIdxWithToolResults);
94
+ if (resultsTruncated) {
95
+ return;
96
+ }
97
+ }
98
+ // Try to trim messages when tool result cannot be truncated anymore
99
+ // If the number of messages is less than the window_size, then we default to 2, otherwise, trim to window size
100
+ let trimIndex = messages.length <= this._windowSize ? 2 : messages.length - this._windowSize;
101
+ // Find the next valid trim_index
102
+ while (trimIndex < messages.length) {
103
+ const oldestMessage = messages[trimIndex];
104
+ if (!oldestMessage) {
105
+ break;
106
+ }
107
+ // Check if oldest message would be a toolResult (invalid - needs preceding toolUse)
108
+ const hasToolResult = oldestMessage.content.some((block) => block.type === 'toolResultBlock');
109
+ if (hasToolResult) {
110
+ trimIndex++;
111
+ continue;
112
+ }
113
+ // Check if oldest message would be a toolUse without immediately following toolResult
114
+ const hasToolUse = oldestMessage.content.some((block) => block.type === 'toolUseBlock');
115
+ if (hasToolUse) {
116
+ // Check if next message has toolResult
117
+ const nextMessage = messages[trimIndex + 1];
118
+ const nextHasToolResult = nextMessage && nextMessage.content.some((block) => block.type === 'toolResultBlock');
119
+ if (!nextHasToolResult) {
120
+ // toolUse without following toolResult - invalid trim point
121
+ trimIndex++;
122
+ continue;
123
+ }
124
+ }
125
+ // Valid trim point found
126
+ break;
127
+ }
128
+ // If we didn't find a valid trim_index, then we throw
129
+ if (trimIndex >= messages.length) {
130
+ throw new ContextWindowOverflowError('Unable to trim conversation context!');
131
+ }
132
+ // Overwrite message history
133
+ messages.splice(0, trimIndex);
134
+ }
135
+ /**
136
+ * Truncate tool results in a message to reduce context size.
137
+ *
138
+ * When a message contains tool results that are too large for the model's context window,
139
+ * this function replaces the content of those tool results with a simple error message.
140
+ *
141
+ * @param messages - The conversation message history.
142
+ * @param msgIdx - Index of the message containing tool results to truncate.
143
+ * @returns True if any changes were made to the message, false otherwise.
144
+ */
145
+ truncateToolResults(messages, msgIdx) {
146
+ if (msgIdx >= messages.length || msgIdx < 0) {
147
+ return false;
148
+ }
149
+ const message = messages[msgIdx];
150
+ if (!message) {
151
+ return false;
152
+ }
153
+ const toolResultTooLargeMessage = 'The tool result was too large!';
154
+ let foundToolResultToTruncate = false;
155
+ // First, check if there's a tool result that needs truncation
156
+ for (const block of message.content) {
157
+ if (block.type === 'toolResultBlock') {
158
+ const toolResultBlock = block;
159
+ // Check if already truncated
160
+ const firstContent = toolResultBlock.content[0];
161
+ const contentText = firstContent && firstContent.type === 'textBlock' ? firstContent.text : '';
162
+ if (toolResultBlock.status === 'error' && contentText === toolResultTooLargeMessage) {
163
+ return false;
164
+ }
165
+ foundToolResultToTruncate = true;
166
+ break;
167
+ }
168
+ }
169
+ if (!foundToolResultToTruncate) {
170
+ return false;
171
+ }
172
+ // Create new content array with truncated tool results
173
+ const newContent = message.content.map((block) => {
174
+ if (block.type === 'toolResultBlock') {
175
+ const toolResultBlock = block;
176
+ // Create new ToolResultBlock with truncated content
177
+ return new ToolResultBlock({
178
+ toolUseId: toolResultBlock.toolUseId,
179
+ status: 'error',
180
+ content: [new TextBlock(toolResultTooLargeMessage)],
181
+ });
182
+ }
183
+ return block;
184
+ });
185
+ // Replace the message in the array with a new message containing the modified content
186
+ messages[msgIdx] = new Message({
187
+ role: message.role,
188
+ content: newContent,
189
+ });
190
+ return true;
191
+ }
192
+ /**
193
+ * Find the index of the last message containing tool results.
194
+ *
195
+ * This is useful for identifying messages that might need to be truncated to reduce context size.
196
+ *
197
+ * @param messages - The conversation message history.
198
+ * @returns Index of the last message with tool results, or undefined if no such message exists.
199
+ */
200
+ findLastMessageWithToolResults(messages) {
201
+ // Iterate backwards through all messages (from newest to oldest)
202
+ for (let idx = messages.length - 1; idx >= 0; idx--) {
203
+ const currentMessage = messages[idx];
204
+ const hasToolResult = currentMessage.content.some((block) => block.type === 'toolResultBlock');
205
+ if (hasToolResult) {
206
+ return idx;
207
+ }
208
+ }
209
+ return undefined;
210
+ }
211
+ }
212
+ //# sourceMappingURL=sliding-window-conversation-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sliding-window-conversation-manager.js","sourceRoot":"","sources":["../../../src/conversation-manager/sliding-window-conversation-manager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAA;AACzD,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAG1E,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAmB9E;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,gCAAgC;IAC1B,WAAW,CAAQ;IACnB,sBAAsB,CAAS;IAEhD;;;;OAIG;IACH,YAAY,MAA+C;QACzD,IAAI,CAAC,WAAW,GAAG,MAAM,EAAE,UAAU,IAAI,EAAE,CAAA;QAC3C,IAAI,CAAC,sBAAsB,GAAG,MAAM,EAAE,qBAAqB,IAAI,IAAI,CAAA;IACrE,CAAC;IAED;;;;;;;;OAQG;IACI,iBAAiB,CAAC,QAAsB;QAC7C,wDAAwD;QACxD,QAAQ,CAAC,WAAW,CAAC,oBAAoB,EAAE,CAAC,KAAK,EAAE,EAAE;YACnD,IAAI,CAAC,eAAe,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C,MAAM,EAAE,OAAO;oBACf,OAAO,EAAE,CAAC,IAAI,SAAS,CAAC,yBAAyB,CAAC,CAAC;iBACpD,CAAC,CAAA;YACJ,CAAC;YACD,OAAO,KAAK,CAAA;QACd,CAAC,CAAC,CAAA;QAEF,sFAAsF;QACtF,QAAQ,CAAC,MAAM,CAAC,GAAG,IAAI,OAAO,CAAC;YAC7B,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,OAAO,EAAE,UAAU;SACpB,CAAC,CAAA;QAEF,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;;;;;;OAOG;IACK,8BAA8B,CAAC,QAAmB;QACxD,iEAAiE;QACjE,KAAK,IAAI,GAAG,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC;YACpD,MAAM,cAAc,GAAG,QAAQ,CAAC,GAAG,CAAE,CAAA;YAErC,MAAM,aAAa,GAAG,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,iBAAiB,CAAC,CAAA;YAE9F,IAAI,aAAa,EAAE,CAAC;gBAClB,OAAO,GAAG,CAAA;YACZ,CAAC;QACH,CAAC;QAED,OAAO,SAAS,CAAA;IAClB,CAAC;CACF"}
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Error types for the Strands Agents TypeScript SDK.
3
+ *
4
+ * These error classes represent specific error conditions that can occur
5
+ * during agent execution and model provider interactions.
6
+ */
7
+ import type { Message } from './types/messages.js';
8
+ /**
9
+ * Error thrown when input exceeds the model's context window.
10
+ *
11
+ * This error indicates that the combined length of the input (prompt, messages,
12
+ * system prompt, and tool definitions) exceeds the maximum context window size
13
+ * supported by the model.
14
+ */
15
+ export declare class ContextWindowOverflowError extends Error {
16
+ /**
17
+ * Creates a new ContextWindowOverflowError.
18
+ *
19
+ * @param message - Error message describing the context overflow
20
+ */
21
+ constructor(message: string);
22
+ }
23
+ /**
24
+ * Error thrown when the model reaches its maximum token limit during generation.
25
+ *
26
+ * This error indicates that the model stopped generating content because it reached
27
+ * the maximum number of tokens allowed for the response. This is an unrecoverable
28
+ * state that requires intervention, such as reducing the input size or adjusting
29
+ * the max tokens parameter.
30
+ */
31
+ export declare class MaxTokensError extends Error {
32
+ /**
33
+ * The partial assistant message that was generated before hitting the token limit.
34
+ * This can be useful for understanding what the model was trying to generate.
35
+ */
36
+ readonly partialMessage: Message;
37
+ /**
38
+ * Creates a new MaxTokensError.
39
+ *
40
+ * @param message - Error message describing the max tokens condition
41
+ * @param partialMessage - The partial assistant message generated before the limit
42
+ */
43
+ constructor(message: string, partialMessage: Message);
44
+ }
45
+ /**
46
+ * Error thrown when attempting to serialize a value that is not JSON-serializable.
47
+ *
48
+ * This error indicates that a value contains non-serializable types such as functions,
49
+ * symbols, or undefined values that cannot be converted to JSON.
50
+ */
51
+ export declare class JsonValidationError extends Error {
52
+ /**
53
+ * Creates a new JsonValidationError.
54
+ *
55
+ * @param message - Error message describing the validation failure
56
+ */
57
+ constructor(message: string);
58
+ }
59
+ /**
60
+ * Error thrown when attempting to invoke an agent that is already processing an invocation.
61
+ *
62
+ * This error indicates that invoke() or stream() was called while the agent is already
63
+ * executing. Agents can only process one invocation at a time to prevent state corruption.
64
+ */
65
+ export declare class ConcurrentInvocationError extends Error {
66
+ /**
67
+ * Creates a new ConcurrentInvocationError.
68
+ *
69
+ * @param message - Error message describing the concurrent invocation attempt
70
+ */
71
+ constructor(message: string);
72
+ }
73
+ /**
74
+ * Normalizes an unknown error value to an Error instance.
75
+ *
76
+ * This helper ensures that any thrown value (Error, string, number, etc.)
77
+ * is converted to a proper Error object for consistent error handling.
78
+ *
79
+ * @param error - The error value to normalize
80
+ * @returns An Error instance
81
+ */
82
+ export declare function normalizeError(error: unknown): Error;
83
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAElD;;;;;;GAMG;AACH,qBAAa,0BAA2B,SAAQ,KAAK;IACnD;;;;OAIG;gBACS,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;;;GAOG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACvC;;;OAGG;IACH,SAAgB,cAAc,EAAE,OAAO,CAAA;IAEvC;;;;;OAKG;gBACS,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO;CAKrD;AAED;;;;;GAKG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C;;;;OAIG;gBACS,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;GAKG;AACH,qBAAa,yBAA0B,SAAQ,KAAK;IAClD;;;;OAIG;gBACS,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CAEpD"}