@code-yeongyu/senpi 2026.5.20-4 → 2026.5.21

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 (794) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cli.d.ts.map +1 -1
  3. package/dist/cli.js +4 -10
  4. package/dist/cli.js.map +1 -1
  5. package/dist/config.d.ts.map +1 -1
  6. package/dist/config.js +10 -4
  7. package/dist/config.js.map +1 -1
  8. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  9. package/dist/core/agent-session-runtime.js +2 -3
  10. package/dist/core/agent-session-runtime.js.map +1 -1
  11. package/dist/core/http-dispatcher.d.ts +21 -0
  12. package/dist/core/http-dispatcher.d.ts.map +1 -0
  13. package/dist/core/http-dispatcher.js +48 -0
  14. package/dist/core/http-dispatcher.js.map +1 -0
  15. package/dist/core/package-manager.d.ts.map +1 -1
  16. package/dist/core/package-manager.js +2 -1
  17. package/dist/core/package-manager.js.map +1 -1
  18. package/dist/core/settings-manager.d.ts +3 -0
  19. package/dist/core/settings-manager.d.ts.map +1 -1
  20. package/dist/core/settings-manager.js +20 -0
  21. package/dist/core/settings-manager.js.map +1 -1
  22. package/dist/main.d.ts.map +1 -1
  23. package/dist/main.js +2 -0
  24. package/dist/main.js.map +1 -1
  25. package/dist/modes/interactive/components/settings-selector.d.ts +2 -0
  26. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  27. package/dist/modes/interactive/components/settings-selector.js +15 -0
  28. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  29. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  30. package/dist/modes/interactive/interactive-mode.js +10 -1
  31. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  32. package/dist/senpi +4 -10
  33. package/dist/utils/paths.d.ts +1 -0
  34. package/dist/utils/paths.d.ts.map +1 -1
  35. package/dist/utils/paths.js +16 -0
  36. package/dist/utils/paths.js.map +1 -1
  37. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  38. package/examples/extensions/custom-provider-anthropic/package.json +2 -2
  39. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  40. package/examples/extensions/sandbox/package-lock.json +2 -2
  41. package/examples/extensions/sandbox/package.json +2 -2
  42. package/examples/extensions/with-deps/package-lock.json +2 -2
  43. package/examples/extensions/with-deps/package.json +3 -3
  44. package/node_modules/@earendil-works/pi-agent-core/README.md +488 -0
  45. package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.d.ts +24 -0
  46. package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.d.ts.map +1 -0
  47. package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js +610 -0
  48. package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js.map +1 -0
  49. package/node_modules/@earendil-works/pi-agent-core/dist/agent.d.ts +120 -0
  50. package/node_modules/@earendil-works/pi-agent-core/dist/agent.d.ts.map +1 -0
  51. package/node_modules/@earendil-works/pi-agent-core/dist/agent.js +405 -0
  52. package/node_modules/@earendil-works/pi-agent-core/dist/agent.js.map +1 -0
  53. package/node_modules/@earendil-works/pi-agent-core/dist/harness/agent-harness.d.ts +92 -0
  54. package/node_modules/@earendil-works/pi-agent-core/dist/harness/agent-harness.d.ts.map +1 -0
  55. package/node_modules/@earendil-works/pi-agent-core/dist/harness/agent-harness.js +904 -0
  56. package/node_modules/@earendil-works/pi-agent-core/dist/harness/agent-harness.js.map +1 -0
  57. package/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/branch-summarization.d.ts +53 -0
  58. package/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/branch-summarization.d.ts.map +1 -0
  59. package/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/branch-summarization.js +174 -0
  60. package/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/branch-summarization.js.map +1 -0
  61. package/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/compaction.d.ts +95 -0
  62. package/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/compaction.d.ts.map +1 -0
  63. package/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/compaction.js +533 -0
  64. package/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/compaction.js.map +1 -0
  65. package/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/utils.d.ts +25 -0
  66. package/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/utils.d.ts.map +1 -0
  67. package/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/utils.js +131 -0
  68. package/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/utils.js.map +1 -0
  69. package/node_modules/@earendil-works/pi-agent-core/dist/harness/env/nodejs.d.ts +51 -0
  70. package/node_modules/@earendil-works/pi-agent-core/dist/harness/env/nodejs.d.ts.map +1 -0
  71. package/node_modules/@earendil-works/pi-agent-core/dist/harness/env/nodejs.js +486 -0
  72. package/node_modules/@earendil-works/pi-agent-core/dist/harness/env/nodejs.js.map +1 -0
  73. package/node_modules/@earendil-works/pi-agent-core/dist/harness/messages.d.ts +52 -0
  74. package/node_modules/@earendil-works/pi-agent-core/dist/harness/messages.d.ts.map +1 -0
  75. package/node_modules/@earendil-works/pi-agent-core/dist/harness/messages.js +102 -0
  76. package/node_modules/@earendil-works/pi-agent-core/dist/harness/messages.js.map +1 -0
  77. package/node_modules/@earendil-works/pi-agent-core/dist/harness/prompt-templates.d.ts +48 -0
  78. package/node_modules/@earendil-works/pi-agent-core/dist/harness/prompt-templates.d.ts.map +1 -0
  79. package/node_modules/@earendil-works/pi-agent-core/dist/harness/prompt-templates.js +230 -0
  80. package/node_modules/@earendil-works/pi-agent-core/dist/harness/prompt-templates.js.map +1 -0
  81. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-repo.d.ts +26 -0
  82. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-repo.d.ts.map +1 -0
  83. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-repo.js +101 -0
  84. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-repo.js.map +1 -0
  85. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-storage.d.ts +33 -0
  86. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-storage.d.ts.map +1 -0
  87. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-storage.js +231 -0
  88. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-storage.js.map +1 -0
  89. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-repo.d.ts +18 -0
  90. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-repo.d.ts.map +1 -0
  91. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-repo.js +42 -0
  92. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-repo.js.map +1 -0
  93. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-storage.d.ts +25 -0
  94. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-storage.d.ts.map +1 -0
  95. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-storage.js +114 -0
  96. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-storage.js.map +1 -0
  97. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo-utils.d.ts +11 -0
  98. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo-utils.d.ts.map +1 -0
  99. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo-utils.js +39 -0
  100. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo-utils.js.map +1 -0
  101. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/session.d.ts +32 -0
  102. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/session.d.ts.map +1 -0
  103. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/session.js +197 -0
  104. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/session.js.map +1 -0
  105. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/uuid.d.ts +2 -0
  106. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/uuid.d.ts.map +1 -0
  107. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/uuid.js +50 -0
  108. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/uuid.js.map +1 -0
  109. package/node_modules/@earendil-works/pi-agent-core/dist/harness/skills.d.ts +44 -0
  110. package/node_modules/@earendil-works/pi-agent-core/dist/harness/skills.d.ts.map +1 -0
  111. package/node_modules/@earendil-works/pi-agent-core/dist/harness/skills.js +311 -0
  112. package/node_modules/@earendil-works/pi-agent-core/dist/harness/skills.js.map +1 -0
  113. package/node_modules/@earendil-works/pi-agent-core/dist/harness/system-prompt.d.ts +3 -0
  114. package/node_modules/@earendil-works/pi-agent-core/dist/harness/system-prompt.d.ts.map +1 -0
  115. package/node_modules/@earendil-works/pi-agent-core/dist/harness/system-prompt.js +30 -0
  116. package/node_modules/@earendil-works/pi-agent-core/dist/harness/system-prompt.js.map +1 -0
  117. package/node_modules/@earendil-works/pi-agent-core/dist/harness/types.d.ts +604 -0
  118. package/node_modules/@earendil-works/pi-agent-core/dist/harness/types.d.ts.map +1 -0
  119. package/node_modules/@earendil-works/pi-agent-core/dist/harness/types.js +103 -0
  120. package/node_modules/@earendil-works/pi-agent-core/dist/harness/types.js.map +1 -0
  121. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/shell-output.d.ts +14 -0
  122. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/shell-output.d.ts.map +1 -0
  123. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/shell-output.js +126 -0
  124. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/shell-output.js.map +1 -0
  125. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/truncate.d.ts +70 -0
  126. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/truncate.d.ts.map +1 -0
  127. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/truncate.js +290 -0
  128. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/truncate.js.map +1 -0
  129. package/node_modules/@earendil-works/pi-agent-core/dist/index.d.ts +20 -0
  130. package/node_modules/@earendil-works/pi-agent-core/dist/index.d.ts.map +1 -0
  131. package/node_modules/@earendil-works/pi-agent-core/dist/index.js +25 -0
  132. package/node_modules/@earendil-works/pi-agent-core/dist/index.js.map +1 -0
  133. package/node_modules/@earendil-works/pi-agent-core/dist/node.d.ts +3 -0
  134. package/node_modules/@earendil-works/pi-agent-core/dist/node.d.ts.map +1 -0
  135. package/node_modules/@earendil-works/pi-agent-core/dist/node.js +3 -0
  136. package/node_modules/@earendil-works/pi-agent-core/dist/node.js.map +1 -0
  137. package/node_modules/@earendil-works/pi-agent-core/dist/proxy.d.ts +69 -0
  138. package/node_modules/@earendil-works/pi-agent-core/dist/proxy.d.ts.map +1 -0
  139. package/node_modules/@earendil-works/pi-agent-core/dist/proxy.js +278 -0
  140. package/node_modules/@earendil-works/pi-agent-core/dist/proxy.js.map +1 -0
  141. package/node_modules/@earendil-works/pi-agent-core/dist/types.d.ts +394 -0
  142. package/node_modules/@earendil-works/pi-agent-core/dist/types.d.ts.map +1 -0
  143. package/node_modules/@earendil-works/pi-agent-core/dist/types.js +2 -0
  144. package/node_modules/@earendil-works/pi-agent-core/dist/types.js.map +1 -0
  145. package/node_modules/@earendil-works/pi-agent-core/package.json +61 -0
  146. package/node_modules/@earendil-works/pi-ai/README.md +1386 -0
  147. package/node_modules/@earendil-works/pi-ai/dist/api-registry.d.ts +20 -0
  148. package/node_modules/@earendil-works/pi-ai/dist/api-registry.d.ts.map +1 -0
  149. package/node_modules/@earendil-works/pi-ai/dist/api-registry.js +44 -0
  150. package/node_modules/@earendil-works/pi-ai/dist/api-registry.js.map +1 -0
  151. package/node_modules/@earendil-works/pi-ai/dist/bedrock-provider.d.ts +5 -0
  152. package/node_modules/@earendil-works/pi-ai/dist/bedrock-provider.d.ts.map +1 -0
  153. package/node_modules/@earendil-works/pi-ai/dist/bedrock-provider.js +6 -0
  154. package/node_modules/@earendil-works/pi-ai/dist/bedrock-provider.js.map +1 -0
  155. package/node_modules/@earendil-works/pi-ai/dist/cli.d.ts +3 -0
  156. package/node_modules/@earendil-works/pi-ai/dist/cli.d.ts.map +1 -0
  157. package/node_modules/@earendil-works/pi-ai/dist/cli.js +116 -0
  158. package/node_modules/@earendil-works/pi-ai/dist/cli.js.map +1 -0
  159. package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.d.ts +18 -0
  160. package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.d.ts.map +1 -0
  161. package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.js +178 -0
  162. package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.js.map +1 -0
  163. package/node_modules/@earendil-works/pi-ai/dist/image-models.d.ts +10 -0
  164. package/node_modules/@earendil-works/pi-ai/dist/image-models.d.ts.map +1 -0
  165. package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.d.ts +440 -0
  166. package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.d.ts.map +1 -0
  167. package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js +442 -0
  168. package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js.map +1 -0
  169. package/node_modules/@earendil-works/pi-ai/dist/image-models.js +23 -0
  170. package/node_modules/@earendil-works/pi-ai/dist/image-models.js.map +1 -0
  171. package/node_modules/@earendil-works/pi-ai/dist/images-api-registry.d.ts +14 -0
  172. package/node_modules/@earendil-works/pi-ai/dist/images-api-registry.d.ts.map +1 -0
  173. package/node_modules/@earendil-works/pi-ai/dist/images-api-registry.js +22 -0
  174. package/node_modules/@earendil-works/pi-ai/dist/images-api-registry.js.map +1 -0
  175. package/node_modules/@earendil-works/pi-ai/dist/images.d.ts +4 -0
  176. package/node_modules/@earendil-works/pi-ai/dist/images.d.ts.map +1 -0
  177. package/node_modules/@earendil-works/pi-ai/dist/images.js +14 -0
  178. package/node_modules/@earendil-works/pi-ai/dist/images.js.map +1 -0
  179. package/node_modules/@earendil-works/pi-ai/dist/index.d.ts +33 -0
  180. package/node_modules/@earendil-works/pi-ai/dist/index.d.ts.map +1 -0
  181. package/node_modules/@earendil-works/pi-ai/dist/index.js +21 -0
  182. package/node_modules/@earendil-works/pi-ai/dist/index.js.map +1 -0
  183. package/node_modules/@earendil-works/pi-ai/dist/models.d.ts +37 -0
  184. package/node_modules/@earendil-works/pi-ai/dist/models.d.ts.map +1 -0
  185. package/node_modules/@earendil-works/pi-ai/dist/models.generated.d.ts +17658 -0
  186. package/node_modules/@earendil-works/pi-ai/dist/models.generated.d.ts.map +1 -0
  187. package/node_modules/@earendil-works/pi-ai/dist/models.generated.js +16510 -0
  188. package/node_modules/@earendil-works/pi-ai/dist/models.generated.js.map +1 -0
  189. package/node_modules/@earendil-works/pi-ai/dist/models.js +114 -0
  190. package/node_modules/@earendil-works/pi-ai/dist/models.js.map +1 -0
  191. package/node_modules/@earendil-works/pi-ai/dist/oauth.d.ts +2 -0
  192. package/node_modules/@earendil-works/pi-ai/dist/oauth.d.ts.map +1 -0
  193. package/node_modules/@earendil-works/pi-ai/dist/oauth.js +2 -0
  194. package/node_modules/@earendil-works/pi-ai/dist/oauth.js.map +1 -0
  195. package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.d.ts +38 -0
  196. package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.d.ts.map +1 -0
  197. package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.js +787 -0
  198. package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.js.map +1 -0
  199. package/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.d.ts +52 -0
  200. package/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.d.ts.map +1 -0
  201. package/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.js +1127 -0
  202. package/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.js.map +1 -0
  203. package/node_modules/@earendil-works/pi-ai/dist/providers/azure-openai-responses.d.ts +15 -0
  204. package/node_modules/@earendil-works/pi-ai/dist/providers/azure-openai-responses.d.ts.map +1 -0
  205. package/node_modules/@earendil-works/pi-ai/dist/providers/azure-openai-responses.js +229 -0
  206. package/node_modules/@earendil-works/pi-ai/dist/providers/azure-openai-responses.js.map +1 -0
  207. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare.d.ts +13 -0
  208. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare.d.ts.map +1 -0
  209. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare.js +26 -0
  210. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare.js.map +1 -0
  211. package/node_modules/@earendil-works/pi-ai/dist/providers/faux.d.ts +66 -0
  212. package/node_modules/@earendil-works/pi-ai/dist/providers/faux.d.ts.map +1 -0
  213. package/node_modules/@earendil-works/pi-ai/dist/providers/faux.js +401 -0
  214. package/node_modules/@earendil-works/pi-ai/dist/providers/faux.js.map +1 -0
  215. package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot-headers.d.ts +8 -0
  216. package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot-headers.d.ts.map +1 -0
  217. package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot-headers.js +29 -0
  218. package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot-headers.js.map +1 -0
  219. package/node_modules/@earendil-works/pi-ai/dist/providers/google-shared.d.ts +73 -0
  220. package/node_modules/@earendil-works/pi-ai/dist/providers/google-shared.d.ts.map +1 -0
  221. package/node_modules/@earendil-works/pi-ai/dist/providers/google-shared.js +359 -0
  222. package/node_modules/@earendil-works/pi-ai/dist/providers/google-shared.js.map +1 -0
  223. package/node_modules/@earendil-works/pi-ai/dist/providers/google-vertex.d.ts +15 -0
  224. package/node_modules/@earendil-works/pi-ai/dist/providers/google-vertex.d.ts.map +1 -0
  225. package/node_modules/@earendil-works/pi-ai/dist/providers/google-vertex.js +465 -0
  226. package/node_modules/@earendil-works/pi-ai/dist/providers/google-vertex.js.map +1 -0
  227. package/node_modules/@earendil-works/pi-ai/dist/providers/google.d.ts +13 -0
  228. package/node_modules/@earendil-works/pi-ai/dist/providers/google.d.ts.map +1 -0
  229. package/node_modules/@earendil-works/pi-ai/dist/providers/google.js +431 -0
  230. package/node_modules/@earendil-works/pi-ai/dist/providers/google.js.map +1 -0
  231. package/node_modules/@earendil-works/pi-ai/dist/providers/images/openrouter.d.ts +3 -0
  232. package/node_modules/@earendil-works/pi-ai/dist/providers/images/openrouter.d.ts.map +1 -0
  233. package/node_modules/@earendil-works/pi-ai/dist/providers/images/openrouter.js +129 -0
  234. package/node_modules/@earendil-works/pi-ai/dist/providers/images/openrouter.js.map +1 -0
  235. package/node_modules/@earendil-works/pi-ai/dist/providers/images/register-builtins.d.ts +4 -0
  236. package/node_modules/@earendil-works/pi-ai/dist/providers/images/register-builtins.d.ts.map +1 -0
  237. package/node_modules/@earendil-works/pi-ai/dist/providers/images/register-builtins.js +34 -0
  238. package/node_modules/@earendil-works/pi-ai/dist/providers/images/register-builtins.js.map +1 -0
  239. package/node_modules/@earendil-works/pi-ai/dist/providers/mistral.d.ts +25 -0
  240. package/node_modules/@earendil-works/pi-ai/dist/providers/mistral.d.ts.map +1 -0
  241. package/node_modules/@earendil-works/pi-ai/dist/providers/mistral.js +542 -0
  242. package/node_modules/@earendil-works/pi-ai/dist/providers/mistral.js.map +1 -0
  243. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex-responses.d.ts +30 -0
  244. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex-responses.d.ts.map +1 -0
  245. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex-responses.js +1112 -0
  246. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex-responses.js.map +1 -0
  247. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-completions.d.ts +22 -0
  248. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-completions.d.ts.map +1 -0
  249. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-completions.js +977 -0
  250. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-completions.js.map +1 -0
  251. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-prompt-cache.d.ts +3 -0
  252. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-prompt-cache.d.ts.map +1 -0
  253. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-prompt-cache.js +10 -0
  254. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-prompt-cache.js.map +1 -0
  255. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-responses-shared.d.ts +19 -0
  256. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-responses-shared.d.ts.map +1 -0
  257. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-responses-shared.js +579 -0
  258. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-responses-shared.js.map +1 -0
  259. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-responses.d.ts +13 -0
  260. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-responses.d.ts.map +1 -0
  261. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-responses.js +651 -0
  262. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-responses.js.map +1 -0
  263. package/node_modules/@earendil-works/pi-ai/dist/providers/register-builtins.d.ts +35 -0
  264. package/node_modules/@earendil-works/pi-ai/dist/providers/register-builtins.d.ts.map +1 -0
  265. package/node_modules/@earendil-works/pi-ai/dist/providers/register-builtins.js +254 -0
  266. package/node_modules/@earendil-works/pi-ai/dist/providers/register-builtins.js.map +1 -0
  267. package/node_modules/@earendil-works/pi-ai/dist/providers/simple-options.d.ts +38 -0
  268. package/node_modules/@earendil-works/pi-ai/dist/providers/simple-options.d.ts.map +1 -0
  269. package/node_modules/@earendil-works/pi-ai/dist/providers/simple-options.js +174 -0
  270. package/node_modules/@earendil-works/pi-ai/dist/providers/simple-options.js.map +1 -0
  271. package/node_modules/@earendil-works/pi-ai/dist/providers/transform-messages.d.ts +16 -0
  272. package/node_modules/@earendil-works/pi-ai/dist/providers/transform-messages.d.ts.map +1 -0
  273. package/node_modules/@earendil-works/pi-ai/dist/providers/transform-messages.js +186 -0
  274. package/node_modules/@earendil-works/pi-ai/dist/providers/transform-messages.js.map +1 -0
  275. package/node_modules/@earendil-works/pi-ai/dist/session-resources.d.ts +4 -0
  276. package/node_modules/@earendil-works/pi-ai/dist/session-resources.d.ts.map +1 -0
  277. package/node_modules/@earendil-works/pi-ai/dist/session-resources.js +22 -0
  278. package/node_modules/@earendil-works/pi-ai/dist/session-resources.js.map +1 -0
  279. package/node_modules/@earendil-works/pi-ai/dist/stream.d.ts +8 -0
  280. package/node_modules/@earendil-works/pi-ai/dist/stream.d.ts.map +1 -0
  281. package/node_modules/@earendil-works/pi-ai/dist/stream.js +42 -0
  282. package/node_modules/@earendil-works/pi-ai/dist/stream.js.map +1 -0
  283. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/context-transformer.d.ts +22 -0
  284. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/context-transformer.d.ts.map +1 -0
  285. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/context-transformer.js +161 -0
  286. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/context-transformer.js.map +1 -0
  287. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/index.d.ts +13 -0
  288. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/index.d.ts.map +1 -0
  289. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/index.js +23 -0
  290. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/index.js.map +1 -0
  291. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/gemma4.d.ts +21 -0
  292. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/gemma4.d.ts.map +1 -0
  293. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/gemma4.js +559 -0
  294. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/gemma4.js.map +1 -0
  295. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/hermes.d.ts +21 -0
  296. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/hermes.d.ts.map +1 -0
  297. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/hermes.js +69 -0
  298. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/hermes.js.map +1 -0
  299. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/json-mix.d.ts +12 -0
  300. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/json-mix.d.ts.map +1 -0
  301. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/json-mix.js +570 -0
  302. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/json-mix.js.map +1 -0
  303. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/morph-xml.d.ts +15 -0
  304. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/morph-xml.d.ts.map +1 -0
  305. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/morph-xml.js +935 -0
  306. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/morph-xml.js.map +1 -0
  307. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/xml-tool-tag-scanner.d.ts +14 -0
  308. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/xml-tool-tag-scanner.d.ts.map +1 -0
  309. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/xml-tool-tag-scanner.js +54 -0
  310. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/xml-tool-tag-scanner.js.map +1 -0
  311. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/yaml-xml.d.ts +8 -0
  312. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/yaml-xml.d.ts.map +1 -0
  313. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/yaml-xml.js +295 -0
  314. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/yaml-xml.js.map +1 -0
  315. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/stream-wrapper.d.ts +4 -0
  316. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/stream-wrapper.d.ts.map +1 -0
  317. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/stream-wrapper.js +336 -0
  318. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/stream-wrapper.js.map +1 -0
  319. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/types.d.ts +103 -0
  320. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/types.d.ts.map +1 -0
  321. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/types.js +2 -0
  322. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/types.js.map +1 -0
  323. package/node_modules/@earendil-works/pi-ai/dist/types.d.ts +543 -0
  324. package/node_modules/@earendil-works/pi-ai/dist/types.d.ts.map +1 -0
  325. package/node_modules/@earendil-works/pi-ai/dist/types.js +2 -0
  326. package/node_modules/@earendil-works/pi-ai/dist/types.js.map +1 -0
  327. package/node_modules/@earendil-works/pi-ai/dist/utils/diagnostics.d.ts +19 -0
  328. package/node_modules/@earendil-works/pi-ai/dist/utils/diagnostics.d.ts.map +1 -0
  329. package/node_modules/@earendil-works/pi-ai/dist/utils/diagnostics.js +25 -0
  330. package/node_modules/@earendil-works/pi-ai/dist/utils/diagnostics.js.map +1 -0
  331. package/node_modules/@earendil-works/pi-ai/dist/utils/event-stream.d.ts +21 -0
  332. package/node_modules/@earendil-works/pi-ai/dist/utils/event-stream.d.ts.map +1 -0
  333. package/node_modules/@earendil-works/pi-ai/dist/utils/event-stream.js +81 -0
  334. package/node_modules/@earendil-works/pi-ai/dist/utils/event-stream.js.map +1 -0
  335. package/node_modules/@earendil-works/pi-ai/dist/utils/hash.d.ts +3 -0
  336. package/node_modules/@earendil-works/pi-ai/dist/utils/hash.d.ts.map +1 -0
  337. package/node_modules/@earendil-works/pi-ai/dist/utils/hash.js +14 -0
  338. package/node_modules/@earendil-works/pi-ai/dist/utils/hash.js.map +1 -0
  339. package/node_modules/@earendil-works/pi-ai/dist/utils/headers.d.ts +2 -0
  340. package/node_modules/@earendil-works/pi-ai/dist/utils/headers.d.ts.map +1 -0
  341. package/node_modules/@earendil-works/pi-ai/dist/utils/headers.js +8 -0
  342. package/node_modules/@earendil-works/pi-ai/dist/utils/headers.js.map +1 -0
  343. package/node_modules/@earendil-works/pi-ai/dist/utils/json-parse.d.ts +16 -0
  344. package/node_modules/@earendil-works/pi-ai/dist/utils/json-parse.d.ts.map +1 -0
  345. package/node_modules/@earendil-works/pi-ai/dist/utils/json-parse.js +113 -0
  346. package/node_modules/@earendil-works/pi-ai/dist/utils/json-parse.js.map +1 -0
  347. package/node_modules/@earendil-works/pi-ai/dist/utils/node-http-proxy.d.ts +10 -0
  348. package/node_modules/@earendil-works/pi-ai/dist/utils/node-http-proxy.d.ts.map +1 -0
  349. package/node_modules/@earendil-works/pi-ai/dist/utils/node-http-proxy.js +97 -0
  350. package/node_modules/@earendil-works/pi-ai/dist/utils/node-http-proxy.js.map +1 -0
  351. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/anthropic.d.ts +25 -0
  352. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/anthropic.d.ts.map +1 -0
  353. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/anthropic.js +335 -0
  354. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/anthropic.js.map +1 -0
  355. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/github-copilot.d.ts +30 -0
  356. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/github-copilot.d.ts.map +1 -0
  357. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/github-copilot.js +292 -0
  358. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/github-copilot.js.map +1 -0
  359. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/index.d.ts +57 -0
  360. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/index.d.ts.map +1 -0
  361. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/index.js +121 -0
  362. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/index.js.map +1 -0
  363. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/oauth-page.d.ts +3 -0
  364. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/oauth-page.d.ts.map +1 -0
  365. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/oauth-page.js +105 -0
  366. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/oauth-page.js.map +1 -0
  367. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/openai-codex.d.ts +34 -0
  368. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/openai-codex.d.ts.map +1 -0
  369. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/openai-codex.js +385 -0
  370. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/openai-codex.js.map +1 -0
  371. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/pkce.d.ts +13 -0
  372. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/pkce.d.ts.map +1 -0
  373. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/pkce.js +31 -0
  374. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/pkce.js.map +1 -0
  375. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/types.d.ts +57 -0
  376. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/types.d.ts.map +1 -0
  377. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/types.js +2 -0
  378. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/types.js.map +1 -0
  379. package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.d.ts +56 -0
  380. package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.d.ts.map +1 -0
  381. package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js +151 -0
  382. package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js.map +1 -0
  383. package/node_modules/@earendil-works/pi-ai/dist/utils/sanitize-unicode.d.ts +22 -0
  384. package/node_modules/@earendil-works/pi-ai/dist/utils/sanitize-unicode.d.ts.map +1 -0
  385. package/node_modules/@earendil-works/pi-ai/dist/utils/sanitize-unicode.js +26 -0
  386. package/node_modules/@earendil-works/pi-ai/dist/utils/sanitize-unicode.js.map +1 -0
  387. package/node_modules/@earendil-works/pi-ai/dist/utils/tool-pair-repair.d.ts +5 -0
  388. package/node_modules/@earendil-works/pi-ai/dist/utils/tool-pair-repair.d.ts.map +1 -0
  389. package/node_modules/@earendil-works/pi-ai/dist/utils/tool-pair-repair.js +49 -0
  390. package/node_modules/@earendil-works/pi-ai/dist/utils/tool-pair-repair.js.map +1 -0
  391. package/node_modules/@earendil-works/pi-ai/dist/utils/typebox-helpers.d.ts +17 -0
  392. package/node_modules/@earendil-works/pi-ai/dist/utils/typebox-helpers.d.ts.map +1 -0
  393. package/node_modules/@earendil-works/pi-ai/dist/utils/typebox-helpers.js +21 -0
  394. package/node_modules/@earendil-works/pi-ai/dist/utils/typebox-helpers.js.map +1 -0
  395. package/node_modules/@earendil-works/pi-ai/dist/utils/validation.d.ts +18 -0
  396. package/node_modules/@earendil-works/pi-ai/dist/utils/validation.d.ts.map +1 -0
  397. package/node_modules/@earendil-works/pi-ai/dist/utils/validation.js +281 -0
  398. package/node_modules/@earendil-works/pi-ai/dist/utils/validation.js.map +1 -0
  399. package/node_modules/@earendil-works/pi-ai/package.json +113 -0
  400. package/node_modules/@earendil-works/pi-tui/README.md +779 -0
  401. package/node_modules/@earendil-works/pi-tui/dist/autocomplete.d.ts +54 -0
  402. package/node_modules/@earendil-works/pi-tui/dist/autocomplete.d.ts.map +1 -0
  403. package/node_modules/@earendil-works/pi-tui/dist/autocomplete.js +632 -0
  404. package/node_modules/@earendil-works/pi-tui/dist/autocomplete.js.map +1 -0
  405. package/node_modules/@earendil-works/pi-tui/dist/components/box.d.ts +22 -0
  406. package/node_modules/@earendil-works/pi-tui/dist/components/box.d.ts.map +1 -0
  407. package/node_modules/@earendil-works/pi-tui/dist/components/box.js +104 -0
  408. package/node_modules/@earendil-works/pi-tui/dist/components/box.js.map +1 -0
  409. package/node_modules/@earendil-works/pi-tui/dist/components/cancellable-loader.d.ts +22 -0
  410. package/node_modules/@earendil-works/pi-tui/dist/components/cancellable-loader.d.ts.map +1 -0
  411. package/node_modules/@earendil-works/pi-tui/dist/components/cancellable-loader.js +35 -0
  412. package/node_modules/@earendil-works/pi-tui/dist/components/cancellable-loader.js.map +1 -0
  413. package/node_modules/@earendil-works/pi-tui/dist/components/editor.d.ts +249 -0
  414. package/node_modules/@earendil-works/pi-tui/dist/components/editor.d.ts.map +1 -0
  415. package/node_modules/@earendil-works/pi-tui/dist/components/editor.js +1916 -0
  416. package/node_modules/@earendil-works/pi-tui/dist/components/editor.js.map +1 -0
  417. package/node_modules/@earendil-works/pi-tui/dist/components/image.d.ts +28 -0
  418. package/node_modules/@earendil-works/pi-tui/dist/components/image.d.ts.map +1 -0
  419. package/node_modules/@earendil-works/pi-tui/dist/components/image.js +89 -0
  420. package/node_modules/@earendil-works/pi-tui/dist/components/image.js.map +1 -0
  421. package/node_modules/@earendil-works/pi-tui/dist/components/input.d.ts +37 -0
  422. package/node_modules/@earendil-works/pi-tui/dist/components/input.d.ts.map +1 -0
  423. package/node_modules/@earendil-works/pi-tui/dist/components/input.js +426 -0
  424. package/node_modules/@earendil-works/pi-tui/dist/components/input.js.map +1 -0
  425. package/node_modules/@earendil-works/pi-tui/dist/components/loader.d.ts +40 -0
  426. package/node_modules/@earendil-works/pi-tui/dist/components/loader.d.ts.map +1 -0
  427. package/node_modules/@earendil-works/pi-tui/dist/components/loader.js +95 -0
  428. package/node_modules/@earendil-works/pi-tui/dist/components/loader.js.map +1 -0
  429. package/node_modules/@earendil-works/pi-tui/dist/components/markdown.d.ts +90 -0
  430. package/node_modules/@earendil-works/pi-tui/dist/components/markdown.d.ts.map +1 -0
  431. package/node_modules/@earendil-works/pi-tui/dist/components/markdown.js +634 -0
  432. package/node_modules/@earendil-works/pi-tui/dist/components/markdown.js.map +1 -0
  433. package/node_modules/@earendil-works/pi-tui/dist/components/select-list.d.ts +50 -0
  434. package/node_modules/@earendil-works/pi-tui/dist/components/select-list.d.ts.map +1 -0
  435. package/node_modules/@earendil-works/pi-tui/dist/components/select-list.js +159 -0
  436. package/node_modules/@earendil-works/pi-tui/dist/components/select-list.js.map +1 -0
  437. package/node_modules/@earendil-works/pi-tui/dist/components/settings-list.d.ts +50 -0
  438. package/node_modules/@earendil-works/pi-tui/dist/components/settings-list.d.ts.map +1 -0
  439. package/node_modules/@earendil-works/pi-tui/dist/components/settings-list.js +185 -0
  440. package/node_modules/@earendil-works/pi-tui/dist/components/settings-list.js.map +1 -0
  441. package/node_modules/@earendil-works/pi-tui/dist/components/spacer.d.ts +12 -0
  442. package/node_modules/@earendil-works/pi-tui/dist/components/spacer.d.ts.map +1 -0
  443. package/node_modules/@earendil-works/pi-tui/dist/components/spacer.js +23 -0
  444. package/node_modules/@earendil-works/pi-tui/dist/components/spacer.js.map +1 -0
  445. package/node_modules/@earendil-works/pi-tui/dist/components/text.d.ts +19 -0
  446. package/node_modules/@earendil-works/pi-tui/dist/components/text.d.ts.map +1 -0
  447. package/node_modules/@earendil-works/pi-tui/dist/components/text.js +89 -0
  448. package/node_modules/@earendil-works/pi-tui/dist/components/text.js.map +1 -0
  449. package/node_modules/@earendil-works/pi-tui/dist/components/truncated-text.d.ts +13 -0
  450. package/node_modules/@earendil-works/pi-tui/dist/components/truncated-text.d.ts.map +1 -0
  451. package/node_modules/@earendil-works/pi-tui/dist/components/truncated-text.js +51 -0
  452. package/node_modules/@earendil-works/pi-tui/dist/components/truncated-text.js.map +1 -0
  453. package/node_modules/@earendil-works/pi-tui/dist/editor-component.d.ts +39 -0
  454. package/node_modules/@earendil-works/pi-tui/dist/editor-component.d.ts.map +1 -0
  455. package/node_modules/@earendil-works/pi-tui/dist/editor-component.js +2 -0
  456. package/node_modules/@earendil-works/pi-tui/dist/editor-component.js.map +1 -0
  457. package/node_modules/@earendil-works/pi-tui/dist/fuzzy.d.ts +16 -0
  458. package/node_modules/@earendil-works/pi-tui/dist/fuzzy.d.ts.map +1 -0
  459. package/node_modules/@earendil-works/pi-tui/dist/fuzzy.js +110 -0
  460. package/node_modules/@earendil-works/pi-tui/dist/fuzzy.js.map +1 -0
  461. package/node_modules/@earendil-works/pi-tui/dist/index.d.ts +23 -0
  462. package/node_modules/@earendil-works/pi-tui/dist/index.d.ts.map +1 -0
  463. package/node_modules/@earendil-works/pi-tui/dist/index.js +32 -0
  464. package/node_modules/@earendil-works/pi-tui/dist/index.js.map +1 -0
  465. package/node_modules/@earendil-works/pi-tui/dist/keybindings.d.ts +193 -0
  466. package/node_modules/@earendil-works/pi-tui/dist/keybindings.d.ts.map +1 -0
  467. package/node_modules/@earendil-works/pi-tui/dist/keybindings.js +174 -0
  468. package/node_modules/@earendil-works/pi-tui/dist/keybindings.js.map +1 -0
  469. package/node_modules/@earendil-works/pi-tui/dist/keys.d.ts +184 -0
  470. package/node_modules/@earendil-works/pi-tui/dist/keys.d.ts.map +1 -0
  471. package/node_modules/@earendil-works/pi-tui/dist/keys.js +1173 -0
  472. package/node_modules/@earendil-works/pi-tui/dist/keys.js.map +1 -0
  473. package/node_modules/@earendil-works/pi-tui/dist/kill-ring.d.ts +28 -0
  474. package/node_modules/@earendil-works/pi-tui/dist/kill-ring.d.ts.map +1 -0
  475. package/node_modules/@earendil-works/pi-tui/dist/kill-ring.js +44 -0
  476. package/node_modules/@earendil-works/pi-tui/dist/kill-ring.js.map +1 -0
  477. package/node_modules/@earendil-works/pi-tui/dist/stdin-buffer.d.ts +50 -0
  478. package/node_modules/@earendil-works/pi-tui/dist/stdin-buffer.d.ts.map +1 -0
  479. package/node_modules/@earendil-works/pi-tui/dist/stdin-buffer.js +361 -0
  480. package/node_modules/@earendil-works/pi-tui/dist/stdin-buffer.js.map +1 -0
  481. package/node_modules/@earendil-works/pi-tui/dist/terminal-image.d.ts +90 -0
  482. package/node_modules/@earendil-works/pi-tui/dist/terminal-image.d.ts.map +1 -0
  483. package/node_modules/@earendil-works/pi-tui/dist/terminal-image.js +336 -0
  484. package/node_modules/@earendil-works/pi-tui/dist/terminal-image.js.map +1 -0
  485. package/node_modules/@earendil-works/pi-tui/dist/terminal.d.ts +88 -0
  486. package/node_modules/@earendil-works/pi-tui/dist/terminal.d.ts.map +1 -0
  487. package/node_modules/@earendil-works/pi-tui/dist/terminal.js +329 -0
  488. package/node_modules/@earendil-works/pi-tui/dist/terminal.js.map +1 -0
  489. package/node_modules/@earendil-works/pi-tui/dist/tui.d.ts +231 -0
  490. package/node_modules/@earendil-works/pi-tui/dist/tui.d.ts.map +1 -0
  491. package/node_modules/@earendil-works/pi-tui/dist/tui.js +1230 -0
  492. package/node_modules/@earendil-works/pi-tui/dist/tui.js.map +1 -0
  493. package/node_modules/@earendil-works/pi-tui/dist/undo-stack.d.ts +17 -0
  494. package/node_modules/@earendil-works/pi-tui/dist/undo-stack.d.ts.map +1 -0
  495. package/node_modules/@earendil-works/pi-tui/dist/undo-stack.js +25 -0
  496. package/node_modules/@earendil-works/pi-tui/dist/undo-stack.js.map +1 -0
  497. package/node_modules/@earendil-works/pi-tui/dist/utils.d.ts +79 -0
  498. package/node_modules/@earendil-works/pi-tui/dist/utils.d.ts.map +1 -0
  499. package/node_modules/@earendil-works/pi-tui/dist/utils.js +1031 -0
  500. package/node_modules/@earendil-works/pi-tui/dist/utils.js.map +1 -0
  501. package/node_modules/@earendil-works/pi-tui/package.json +48 -0
  502. package/node_modules/@smithy/node-http-handler/LICENSE +201 -0
  503. package/node_modules/@smithy/node-http-handler/README.md +9 -0
  504. package/node_modules/@smithy/node-http-handler/dist-cjs/index.js +724 -0
  505. package/node_modules/@smithy/node-http-handler/dist-es/constants.js +1 -0
  506. package/node_modules/@smithy/node-http-handler/dist-es/get-transformed-headers.js +9 -0
  507. package/node_modules/@smithy/node-http-handler/dist-es/index.js +3 -0
  508. package/node_modules/@smithy/node-http-handler/dist-es/node-http-handler.js +216 -0
  509. package/node_modules/@smithy/node-http-handler/dist-es/node-http2-connection-manager.js +87 -0
  510. package/node_modules/@smithy/node-http-handler/dist-es/node-http2-connection-pool.js +32 -0
  511. package/node_modules/@smithy/node-http-handler/dist-es/node-http2-handler.js +170 -0
  512. package/node_modules/@smithy/node-http-handler/dist-es/readable.mock.js +21 -0
  513. package/node_modules/@smithy/node-http-handler/dist-es/server.mock.js +88 -0
  514. package/node_modules/@smithy/node-http-handler/dist-es/set-connection-timeout.js +36 -0
  515. package/node_modules/@smithy/node-http-handler/dist-es/set-request-timeout.js +21 -0
  516. package/node_modules/@smithy/node-http-handler/dist-es/set-socket-keep-alive.js +22 -0
  517. package/node_modules/@smithy/node-http-handler/dist-es/set-socket-timeout.js +23 -0
  518. package/node_modules/@smithy/node-http-handler/dist-es/stream-collector/collector.js +8 -0
  519. package/node_modules/@smithy/node-http-handler/dist-es/stream-collector/index.js +41 -0
  520. package/node_modules/@smithy/node-http-handler/dist-es/stream-collector/readable.mock.js +21 -0
  521. package/node_modules/@smithy/node-http-handler/dist-es/timing.js +4 -0
  522. package/node_modules/@smithy/node-http-handler/dist-es/write-request-body.js +56 -0
  523. package/node_modules/@smithy/node-http-handler/dist-types/constants.d.ts +5 -0
  524. package/node_modules/@smithy/node-http-handler/dist-types/get-transformed-headers.d.ts +4 -0
  525. package/node_modules/@smithy/node-http-handler/dist-types/index.d.ts +3 -0
  526. package/node_modules/@smithy/node-http-handler/dist-types/node-http-handler.d.ts +46 -0
  527. package/node_modules/@smithy/node-http-handler/dist-types/node-http2-connection-manager.d.ts +24 -0
  528. package/node_modules/@smithy/node-http-handler/dist-types/node-http2-connection-pool.d.ts +12 -0
  529. package/node_modules/@smithy/node-http-handler/dist-types/node-http2-handler.d.ts +63 -0
  530. package/node_modules/@smithy/node-http-handler/dist-types/readable.mock.d.ts +13 -0
  531. package/node_modules/@smithy/node-http-handler/dist-types/server.mock.d.ts +12 -0
  532. package/node_modules/@smithy/node-http-handler/dist-types/set-connection-timeout.d.ts +2 -0
  533. package/node_modules/@smithy/node-http-handler/dist-types/set-request-timeout.d.ts +6 -0
  534. package/node_modules/@smithy/node-http-handler/dist-types/set-socket-keep-alive.d.ts +6 -0
  535. package/node_modules/@smithy/node-http-handler/dist-types/set-socket-timeout.d.ts +2 -0
  536. package/node_modules/@smithy/node-http-handler/dist-types/stream-collector/collector.d.ts +5 -0
  537. package/node_modules/@smithy/node-http-handler/dist-types/stream-collector/index.d.ts +6 -0
  538. package/node_modules/@smithy/node-http-handler/dist-types/stream-collector/readable.mock.d.ts +13 -0
  539. package/node_modules/@smithy/node-http-handler/dist-types/timing.d.ts +8 -0
  540. package/node_modules/@smithy/node-http-handler/dist-types/ts3.4/constants.d.ts +5 -0
  541. package/node_modules/@smithy/node-http-handler/dist-types/ts3.4/get-transformed-headers.d.ts +4 -0
  542. package/node_modules/@smithy/node-http-handler/dist-types/ts3.4/index.d.ts +3 -0
  543. package/node_modules/@smithy/node-http-handler/dist-types/ts3.4/node-http-handler.d.ts +46 -0
  544. package/node_modules/@smithy/node-http-handler/dist-types/ts3.4/node-http2-connection-manager.d.ts +24 -0
  545. package/node_modules/@smithy/node-http-handler/dist-types/ts3.4/node-http2-connection-pool.d.ts +12 -0
  546. package/node_modules/@smithy/node-http-handler/dist-types/ts3.4/node-http2-handler.d.ts +63 -0
  547. package/node_modules/@smithy/node-http-handler/dist-types/ts3.4/readable.mock.d.ts +13 -0
  548. package/node_modules/@smithy/node-http-handler/dist-types/ts3.4/server.mock.d.ts +12 -0
  549. package/node_modules/@smithy/node-http-handler/dist-types/ts3.4/set-connection-timeout.d.ts +2 -0
  550. package/node_modules/@smithy/node-http-handler/dist-types/ts3.4/set-request-timeout.d.ts +6 -0
  551. package/node_modules/@smithy/node-http-handler/dist-types/ts3.4/set-socket-keep-alive.d.ts +6 -0
  552. package/node_modules/@smithy/node-http-handler/dist-types/ts3.4/set-socket-timeout.d.ts +2 -0
  553. package/node_modules/@smithy/node-http-handler/dist-types/ts3.4/stream-collector/collector.d.ts +5 -0
  554. package/node_modules/@smithy/node-http-handler/dist-types/ts3.4/stream-collector/index.d.ts +6 -0
  555. package/node_modules/@smithy/node-http-handler/dist-types/ts3.4/stream-collector/readable.mock.d.ts +13 -0
  556. package/node_modules/@smithy/node-http-handler/dist-types/ts3.4/timing.d.ts +8 -0
  557. package/node_modules/@smithy/node-http-handler/dist-types/ts3.4/write-request-body.d.ts +11 -0
  558. package/node_modules/@smithy/node-http-handler/dist-types/write-request-body.d.ts +11 -0
  559. package/node_modules/@smithy/node-http-handler/package.json +68 -0
  560. package/node_modules/@smithy/types/LICENSE +201 -0
  561. package/node_modules/@smithy/types/README.md +115 -0
  562. package/node_modules/@smithy/types/dist-cjs/index.js +91 -0
  563. package/node_modules/@smithy/types/dist-es/abort-handler.js +1 -0
  564. package/node_modules/@smithy/types/dist-es/abort.js +1 -0
  565. package/node_modules/@smithy/types/dist-es/auth/HttpApiKeyAuth.js +5 -0
  566. package/node_modules/@smithy/types/dist-es/auth/HttpAuthScheme.js +1 -0
  567. package/node_modules/@smithy/types/dist-es/auth/HttpAuthSchemeProvider.js +1 -0
  568. package/node_modules/@smithy/types/dist-es/auth/HttpSigner.js +1 -0
  569. package/node_modules/@smithy/types/dist-es/auth/IdentityProviderConfig.js +1 -0
  570. package/node_modules/@smithy/types/dist-es/auth/auth.js +5 -0
  571. package/node_modules/@smithy/types/dist-es/auth/index.js +6 -0
  572. package/node_modules/@smithy/types/dist-es/blob/blob-payload-input-types.js +1 -0
  573. package/node_modules/@smithy/types/dist-es/checksum.js +1 -0
  574. package/node_modules/@smithy/types/dist-es/client.js +1 -0
  575. package/node_modules/@smithy/types/dist-es/command.js +1 -0
  576. package/node_modules/@smithy/types/dist-es/connection/config.js +1 -0
  577. package/node_modules/@smithy/types/dist-es/connection/index.js +3 -0
  578. package/node_modules/@smithy/types/dist-es/connection/manager.js +1 -0
  579. package/node_modules/@smithy/types/dist-es/connection/pool.js +1 -0
  580. package/node_modules/@smithy/types/dist-es/crypto.js +1 -0
  581. package/node_modules/@smithy/types/dist-es/downlevel-ts3.4/transform/type-transform.js +1 -0
  582. package/node_modules/@smithy/types/dist-es/encode.js +1 -0
  583. package/node_modules/@smithy/types/dist-es/endpoint.js +5 -0
  584. package/node_modules/@smithy/types/dist-es/endpoints/EndpointRuleObject.js +1 -0
  585. package/node_modules/@smithy/types/dist-es/endpoints/ErrorRuleObject.js +1 -0
  586. package/node_modules/@smithy/types/dist-es/endpoints/RuleSetObject.js +1 -0
  587. package/node_modules/@smithy/types/dist-es/endpoints/TreeRuleObject.js +1 -0
  588. package/node_modules/@smithy/types/dist-es/endpoints/index.js +5 -0
  589. package/node_modules/@smithy/types/dist-es/endpoints/shared.js +1 -0
  590. package/node_modules/@smithy/types/dist-es/eventStream.js +1 -0
  591. package/node_modules/@smithy/types/dist-es/extensions/checksum.js +38 -0
  592. package/node_modules/@smithy/types/dist-es/extensions/defaultClientConfiguration.js +7 -0
  593. package/node_modules/@smithy/types/dist-es/extensions/defaultExtensionConfiguration.js +1 -0
  594. package/node_modules/@smithy/types/dist-es/extensions/index.js +3 -0
  595. package/node_modules/@smithy/types/dist-es/extensions/retry.js +1 -0
  596. package/node_modules/@smithy/types/dist-es/externals-check/browser-externals-check.js +1 -0
  597. package/node_modules/@smithy/types/dist-es/feature-ids.js +1 -0
  598. package/node_modules/@smithy/types/dist-es/http/httpHandlerInitialization.js +1 -0
  599. package/node_modules/@smithy/types/dist-es/http.js +5 -0
  600. package/node_modules/@smithy/types/dist-es/identity/apiKeyIdentity.js +1 -0
  601. package/node_modules/@smithy/types/dist-es/identity/awsCredentialIdentity.js +1 -0
  602. package/node_modules/@smithy/types/dist-es/identity/identity.js +1 -0
  603. package/node_modules/@smithy/types/dist-es/identity/index.js +4 -0
  604. package/node_modules/@smithy/types/dist-es/identity/tokenIdentity.js +1 -0
  605. package/node_modules/@smithy/types/dist-es/index.js +42 -0
  606. package/node_modules/@smithy/types/dist-es/logger.js +1 -0
  607. package/node_modules/@smithy/types/dist-es/middleware.js +1 -0
  608. package/node_modules/@smithy/types/dist-es/pagination.js +1 -0
  609. package/node_modules/@smithy/types/dist-es/profile.js +6 -0
  610. package/node_modules/@smithy/types/dist-es/response.js +1 -0
  611. package/node_modules/@smithy/types/dist-es/retry.js +1 -0
  612. package/node_modules/@smithy/types/dist-es/schema/schema-deprecated.js +1 -0
  613. package/node_modules/@smithy/types/dist-es/schema/schema.js +1 -0
  614. package/node_modules/@smithy/types/dist-es/schema/sentinels.js +1 -0
  615. package/node_modules/@smithy/types/dist-es/schema/static-schemas.js +1 -0
  616. package/node_modules/@smithy/types/dist-es/schema/traits.js +1 -0
  617. package/node_modules/@smithy/types/dist-es/serde.js +1 -0
  618. package/node_modules/@smithy/types/dist-es/shapes.js +1 -0
  619. package/node_modules/@smithy/types/dist-es/signature.js +1 -0
  620. package/node_modules/@smithy/types/dist-es/stream.js +1 -0
  621. package/node_modules/@smithy/types/dist-es/streaming-payload/streaming-blob-common-types.js +1 -0
  622. package/node_modules/@smithy/types/dist-es/streaming-payload/streaming-blob-payload-input-types.js +1 -0
  623. package/node_modules/@smithy/types/dist-es/streaming-payload/streaming-blob-payload-output-types.js +1 -0
  624. package/node_modules/@smithy/types/dist-es/transfer.js +6 -0
  625. package/node_modules/@smithy/types/dist-es/transform/client-method-transforms.js +1 -0
  626. package/node_modules/@smithy/types/dist-es/transform/client-payload-blob-type-narrow.js +1 -0
  627. package/node_modules/@smithy/types/dist-es/transform/exact.js +1 -0
  628. package/node_modules/@smithy/types/dist-es/transform/mutable.js +1 -0
  629. package/node_modules/@smithy/types/dist-es/transform/no-undefined.js +1 -0
  630. package/node_modules/@smithy/types/dist-es/transform/type-transform.js +1 -0
  631. package/node_modules/@smithy/types/dist-es/uri.js +1 -0
  632. package/node_modules/@smithy/types/dist-es/util.js +1 -0
  633. package/node_modules/@smithy/types/dist-es/waiter.js +1 -0
  634. package/node_modules/@smithy/types/dist-types/abort-handler.d.ts +7 -0
  635. package/node_modules/@smithy/types/dist-types/abort.d.ts +50 -0
  636. package/node_modules/@smithy/types/dist-types/auth/HttpApiKeyAuth.d.ts +7 -0
  637. package/node_modules/@smithy/types/dist-types/auth/HttpAuthScheme.d.ts +49 -0
  638. package/node_modules/@smithy/types/dist-types/auth/HttpAuthSchemeProvider.d.ts +20 -0
  639. package/node_modules/@smithy/types/dist-types/auth/HttpSigner.d.ts +41 -0
  640. package/node_modules/@smithy/types/dist-types/auth/IdentityProviderConfig.d.ts +14 -0
  641. package/node_modules/@smithy/types/dist-types/auth/auth.d.ts +57 -0
  642. package/node_modules/@smithy/types/dist-types/auth/index.d.ts +6 -0
  643. package/node_modules/@smithy/types/dist-types/blob/blob-payload-input-types.d.ts +40 -0
  644. package/node_modules/@smithy/types/dist-types/checksum.d.ts +63 -0
  645. package/node_modules/@smithy/types/dist-types/client.d.ts +57 -0
  646. package/node_modules/@smithy/types/dist-types/command.d.ts +28 -0
  647. package/node_modules/@smithy/types/dist-types/connection/config.d.ts +10 -0
  648. package/node_modules/@smithy/types/dist-types/connection/index.d.ts +3 -0
  649. package/node_modules/@smithy/types/dist-types/connection/manager.d.ts +34 -0
  650. package/node_modules/@smithy/types/dist-types/connection/pool.d.ts +32 -0
  651. package/node_modules/@smithy/types/dist-types/crypto.d.ts +60 -0
  652. package/node_modules/@smithy/types/dist-types/downlevel-ts3.4/transform/type-transform.d.ts +25 -0
  653. package/node_modules/@smithy/types/dist-types/encode.d.ts +31 -0
  654. package/node_modules/@smithy/types/dist-types/endpoint.d.ts +77 -0
  655. package/node_modules/@smithy/types/dist-types/endpoints/EndpointRuleObject.d.ts +27 -0
  656. package/node_modules/@smithy/types/dist-types/endpoints/ErrorRuleObject.d.ts +10 -0
  657. package/node_modules/@smithy/types/dist-types/endpoints/RuleSetObject.d.ts +28 -0
  658. package/node_modules/@smithy/types/dist-types/endpoints/TreeRuleObject.d.ts +16 -0
  659. package/node_modules/@smithy/types/dist-types/endpoints/index.d.ts +5 -0
  660. package/node_modules/@smithy/types/dist-types/endpoints/shared.d.ts +55 -0
  661. package/node_modules/@smithy/types/dist-types/eventStream.d.ts +137 -0
  662. package/node_modules/@smithy/types/dist-types/extensions/checksum.d.ts +58 -0
  663. package/node_modules/@smithy/types/dist-types/extensions/defaultClientConfiguration.d.ts +33 -0
  664. package/node_modules/@smithy/types/dist-types/extensions/defaultExtensionConfiguration.d.ts +9 -0
  665. package/node_modules/@smithy/types/dist-types/extensions/index.d.ts +4 -0
  666. package/node_modules/@smithy/types/dist-types/extensions/retry.d.ts +18 -0
  667. package/node_modules/@smithy/types/dist-types/externals-check/browser-externals-check.d.ts +35 -0
  668. package/node_modules/@smithy/types/dist-types/feature-ids.d.ts +16 -0
  669. package/node_modules/@smithy/types/dist-types/http/httpHandlerInitialization.d.ts +128 -0
  670. package/node_modules/@smithy/types/dist-types/http.d.ts +112 -0
  671. package/node_modules/@smithy/types/dist-types/identity/apiKeyIdentity.d.ts +14 -0
  672. package/node_modules/@smithy/types/dist-types/identity/awsCredentialIdentity.d.ts +31 -0
  673. package/node_modules/@smithy/types/dist-types/identity/identity.d.ts +15 -0
  674. package/node_modules/@smithy/types/dist-types/identity/index.d.ts +4 -0
  675. package/node_modules/@smithy/types/dist-types/identity/tokenIdentity.d.ts +14 -0
  676. package/node_modules/@smithy/types/dist-types/index.d.ts +42 -0
  677. package/node_modules/@smithy/types/dist-types/logger.d.ts +13 -0
  678. package/node_modules/@smithy/types/dist-types/middleware.d.ts +534 -0
  679. package/node_modules/@smithy/types/dist-types/pagination.d.ts +33 -0
  680. package/node_modules/@smithy/types/dist-types/profile.d.ts +30 -0
  681. package/node_modules/@smithy/types/dist-types/response.d.ts +40 -0
  682. package/node_modules/@smithy/types/dist-types/retry.d.ts +133 -0
  683. package/node_modules/@smithy/types/dist-types/schema/schema-deprecated.d.ts +136 -0
  684. package/node_modules/@smithy/types/dist-types/schema/schema.d.ts +230 -0
  685. package/node_modules/@smithy/types/dist-types/schema/sentinels.d.ts +65 -0
  686. package/node_modules/@smithy/types/dist-types/schema/static-schemas.d.ts +82 -0
  687. package/node_modules/@smithy/types/dist-types/schema/traits.d.ts +46 -0
  688. package/node_modules/@smithy/types/dist-types/serde.d.ts +114 -0
  689. package/node_modules/@smithy/types/dist-types/shapes.d.ts +82 -0
  690. package/node_modules/@smithy/types/dist-types/signature.d.ts +155 -0
  691. package/node_modules/@smithy/types/dist-types/stream.d.ts +22 -0
  692. package/node_modules/@smithy/types/dist-types/streaming-payload/streaming-blob-common-types.d.ts +32 -0
  693. package/node_modules/@smithy/types/dist-types/streaming-payload/streaming-blob-payload-input-types.d.ts +60 -0
  694. package/node_modules/@smithy/types/dist-types/streaming-payload/streaming-blob-payload-output-types.d.ts +51 -0
  695. package/node_modules/@smithy/types/dist-types/transfer.d.ts +41 -0
  696. package/node_modules/@smithy/types/dist-types/transform/client-method-transforms.d.ts +26 -0
  697. package/node_modules/@smithy/types/dist-types/transform/client-payload-blob-type-narrow.d.ts +77 -0
  698. package/node_modules/@smithy/types/dist-types/transform/exact.d.ts +6 -0
  699. package/node_modules/@smithy/types/dist-types/transform/mutable.d.ts +6 -0
  700. package/node_modules/@smithy/types/dist-types/transform/no-undefined.d.ts +68 -0
  701. package/node_modules/@smithy/types/dist-types/transform/type-transform.d.ts +34 -0
  702. package/node_modules/@smithy/types/dist-types/ts3.4/abort-handler.d.ts +7 -0
  703. package/node_modules/@smithy/types/dist-types/ts3.4/abort.d.ts +50 -0
  704. package/node_modules/@smithy/types/dist-types/ts3.4/auth/HttpApiKeyAuth.d.ts +7 -0
  705. package/node_modules/@smithy/types/dist-types/ts3.4/auth/HttpAuthScheme.d.ts +49 -0
  706. package/node_modules/@smithy/types/dist-types/ts3.4/auth/HttpAuthSchemeProvider.d.ts +20 -0
  707. package/node_modules/@smithy/types/dist-types/ts3.4/auth/HttpSigner.d.ts +41 -0
  708. package/node_modules/@smithy/types/dist-types/ts3.4/auth/IdentityProviderConfig.d.ts +14 -0
  709. package/node_modules/@smithy/types/dist-types/ts3.4/auth/auth.d.ts +57 -0
  710. package/node_modules/@smithy/types/dist-types/ts3.4/auth/index.d.ts +6 -0
  711. package/node_modules/@smithy/types/dist-types/ts3.4/blob/blob-payload-input-types.d.ts +40 -0
  712. package/node_modules/@smithy/types/dist-types/ts3.4/checksum.d.ts +63 -0
  713. package/node_modules/@smithy/types/dist-types/ts3.4/client.d.ts +57 -0
  714. package/node_modules/@smithy/types/dist-types/ts3.4/command.d.ts +28 -0
  715. package/node_modules/@smithy/types/dist-types/ts3.4/connection/config.d.ts +10 -0
  716. package/node_modules/@smithy/types/dist-types/ts3.4/connection/index.d.ts +3 -0
  717. package/node_modules/@smithy/types/dist-types/ts3.4/connection/manager.d.ts +34 -0
  718. package/node_modules/@smithy/types/dist-types/ts3.4/connection/pool.d.ts +32 -0
  719. package/node_modules/@smithy/types/dist-types/ts3.4/crypto.d.ts +60 -0
  720. package/node_modules/@smithy/types/dist-types/ts3.4/downlevel-ts3.4/transform/type-transform.d.ts +41 -0
  721. package/node_modules/@smithy/types/dist-types/ts3.4/encode.d.ts +31 -0
  722. package/node_modules/@smithy/types/dist-types/ts3.4/endpoint.d.ts +77 -0
  723. package/node_modules/@smithy/types/dist-types/ts3.4/endpoints/EndpointRuleObject.d.ts +27 -0
  724. package/node_modules/@smithy/types/dist-types/ts3.4/endpoints/ErrorRuleObject.d.ts +10 -0
  725. package/node_modules/@smithy/types/dist-types/ts3.4/endpoints/RuleSetObject.d.ts +28 -0
  726. package/node_modules/@smithy/types/dist-types/ts3.4/endpoints/TreeRuleObject.d.ts +16 -0
  727. package/node_modules/@smithy/types/dist-types/ts3.4/endpoints/index.d.ts +5 -0
  728. package/node_modules/@smithy/types/dist-types/ts3.4/endpoints/shared.d.ts +55 -0
  729. package/node_modules/@smithy/types/dist-types/ts3.4/eventStream.d.ts +137 -0
  730. package/node_modules/@smithy/types/dist-types/ts3.4/extensions/checksum.d.ts +58 -0
  731. package/node_modules/@smithy/types/dist-types/ts3.4/extensions/defaultClientConfiguration.d.ts +33 -0
  732. package/node_modules/@smithy/types/dist-types/ts3.4/extensions/defaultExtensionConfiguration.d.ts +9 -0
  733. package/node_modules/@smithy/types/dist-types/ts3.4/extensions/index.d.ts +4 -0
  734. package/node_modules/@smithy/types/dist-types/ts3.4/extensions/retry.d.ts +18 -0
  735. package/node_modules/@smithy/types/dist-types/ts3.4/externals-check/browser-externals-check.d.ts +35 -0
  736. package/node_modules/@smithy/types/dist-types/ts3.4/feature-ids.d.ts +16 -0
  737. package/node_modules/@smithy/types/dist-types/ts3.4/http/httpHandlerInitialization.d.ts +128 -0
  738. package/node_modules/@smithy/types/dist-types/ts3.4/http.d.ts +112 -0
  739. package/node_modules/@smithy/types/dist-types/ts3.4/identity/apiKeyIdentity.d.ts +14 -0
  740. package/node_modules/@smithy/types/dist-types/ts3.4/identity/awsCredentialIdentity.d.ts +31 -0
  741. package/node_modules/@smithy/types/dist-types/ts3.4/identity/identity.d.ts +15 -0
  742. package/node_modules/@smithy/types/dist-types/ts3.4/identity/index.d.ts +4 -0
  743. package/node_modules/@smithy/types/dist-types/ts3.4/identity/tokenIdentity.d.ts +14 -0
  744. package/node_modules/@smithy/types/dist-types/ts3.4/index.d.ts +42 -0
  745. package/node_modules/@smithy/types/dist-types/ts3.4/logger.d.ts +13 -0
  746. package/node_modules/@smithy/types/dist-types/ts3.4/middleware.d.ts +534 -0
  747. package/node_modules/@smithy/types/dist-types/ts3.4/pagination.d.ts +33 -0
  748. package/node_modules/@smithy/types/dist-types/ts3.4/profile.d.ts +30 -0
  749. package/node_modules/@smithy/types/dist-types/ts3.4/response.d.ts +40 -0
  750. package/node_modules/@smithy/types/dist-types/ts3.4/retry.d.ts +133 -0
  751. package/node_modules/@smithy/types/dist-types/ts3.4/schema/schema-deprecated.d.ts +142 -0
  752. package/node_modules/@smithy/types/dist-types/ts3.4/schema/schema.d.ts +245 -0
  753. package/node_modules/@smithy/types/dist-types/ts3.4/schema/sentinels.d.ts +65 -0
  754. package/node_modules/@smithy/types/dist-types/ts3.4/schema/static-schemas.d.ts +101 -0
  755. package/node_modules/@smithy/types/dist-types/ts3.4/schema/traits.d.ts +46 -0
  756. package/node_modules/@smithy/types/dist-types/ts3.4/serde.d.ts +114 -0
  757. package/node_modules/@smithy/types/dist-types/ts3.4/shapes.d.ts +82 -0
  758. package/node_modules/@smithy/types/dist-types/ts3.4/signature.d.ts +155 -0
  759. package/node_modules/@smithy/types/dist-types/ts3.4/stream.d.ts +22 -0
  760. package/node_modules/@smithy/types/dist-types/ts3.4/streaming-payload/streaming-blob-common-types.d.ts +32 -0
  761. package/node_modules/@smithy/types/dist-types/ts3.4/streaming-payload/streaming-blob-payload-input-types.d.ts +60 -0
  762. package/node_modules/@smithy/types/dist-types/ts3.4/streaming-payload/streaming-blob-payload-output-types.d.ts +51 -0
  763. package/node_modules/@smithy/types/dist-types/ts3.4/transfer.d.ts +41 -0
  764. package/node_modules/@smithy/types/dist-types/ts3.4/transform/client-method-transforms.d.ts +26 -0
  765. package/node_modules/@smithy/types/dist-types/ts3.4/transform/client-payload-blob-type-narrow.d.ts +81 -0
  766. package/node_modules/@smithy/types/dist-types/ts3.4/transform/exact.d.ts +14 -0
  767. package/node_modules/@smithy/types/dist-types/ts3.4/transform/mutable.d.ts +6 -0
  768. package/node_modules/@smithy/types/dist-types/ts3.4/transform/no-undefined.d.ts +88 -0
  769. package/node_modules/@smithy/types/dist-types/ts3.4/transform/type-transform.d.ts +41 -0
  770. package/node_modules/@smithy/types/dist-types/ts3.4/uri.d.ts +17 -0
  771. package/node_modules/@smithy/types/dist-types/ts3.4/util.d.ts +192 -0
  772. package/node_modules/@smithy/types/dist-types/ts3.4/waiter.d.ts +35 -0
  773. package/node_modules/@smithy/types/dist-types/uri.d.ts +17 -0
  774. package/node_modules/@smithy/types/dist-types/util.d.ts +176 -0
  775. package/node_modules/@smithy/types/dist-types/waiter.d.ts +35 -0
  776. package/node_modules/@smithy/types/package.json +61 -0
  777. package/node_modules/marked/LICENSE.md +44 -0
  778. package/node_modules/marked/README.md +106 -0
  779. package/node_modules/marked/bin/main.js +282 -0
  780. package/node_modules/marked/bin/marked.js +15 -0
  781. package/node_modules/marked/lib/marked.cjs +2211 -0
  782. package/node_modules/marked/lib/marked.cjs.map +7 -0
  783. package/node_modules/marked/lib/marked.d.cts +728 -0
  784. package/node_modules/marked/lib/marked.d.ts +728 -0
  785. package/node_modules/marked/lib/marked.esm.js +2189 -0
  786. package/node_modules/marked/lib/marked.esm.js.map +7 -0
  787. package/node_modules/marked/lib/marked.umd.js +2213 -0
  788. package/node_modules/marked/lib/marked.umd.js.map +7 -0
  789. package/node_modules/marked/man/marked.1 +111 -0
  790. package/node_modules/marked/man/marked.1.md +92 -0
  791. package/node_modules/marked/marked.min.js +69 -0
  792. package/node_modules/marked/package.json +111 -0
  793. package/npm-shrinkwrap.json +1841 -0
  794. package/package.json +49 -31
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yaml-xml.js","sourceRoot":"","sources":["../../../src/tool-call-middleware/protocols/yaml-xml.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEzF,SAAS,YAAY,CAAC,IAAY,EAAU;IAC3C,OAAO,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AAAA,CACnD;AAED,SAAS,oBAAoB,CAAC,WAAmB,EAAU;IAC1D,MAAM,qBAAqB,GAAG,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC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AAE,OAAO,EAAE,CAAC,4DAA4D,EAAE;wBAChF,QAAQ,EAAE,WAAW;qBACrB,CAAC,CAAC;oBACH,IAAI,gCAAgC,CAAC,OAAO,CAAC,EAAE,CAAC;wBAC/C,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC;oBAClD,CAAC;gBACF,CAAC;gBACD,MAAM,GAAG,EAAE,CAAC;gBACZ,gBAAgB,GAAG,IAAI,CAAC;YACzB,CAAC;YACD,OAAO,MAAM,CAAC;QAAA,CACd;KACD,CAAC;AAAA,CACF","sourcesContent":["import YAML from \"yaml\";\nimport type { TextContent, Tool } from \"../../types.ts\";\nimport type { ParsedToolCall, ParserOptions, StreamParser, StreamParserEvent } from \"../types.ts\";\nimport { findEarliestXmlToolTag, getSafeXmlTextLength } from \"./xml-tool-tag-scanner.ts\";\n\nfunction escapeRegExp(text: string): string {\n\treturn text.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n\nfunction normalizeYamlContent(yamlContent: string): string {\n\tconst trimmedLeadingNewline = yamlContent.startsWith(\"\\n\") ? yamlContent.slice(1) : yamlContent;\n\tconst lines = trimmedLeadingNewline.split(\"\\n\");\n\tconst nonEmptyLines = lines.filter((line) => line.trim().length > 0);\n\tif (nonEmptyLines.length === 0) {\n\t\treturn \"\";\n\t}\n\n\tconst minIndent = Math.min(\n\t\t...nonEmptyLines.map((line) => {\n\t\t\tconst match = line.match(/^(\\s*)/);\n\t\t\treturn match?.[1].length ?? 0;\n\t\t}),\n\t);\n\treturn minIndent > 0 ? lines.map((line) => line.slice(minIndent)).join(\"\\n\") : trimmedLeadingNewline;\n}\n\nfunction parseYamlMapping(yamlContent: string): Record<string, unknown> | null {\n\tconst normalized = normalizeYamlContent(yamlContent);\n\tif (normalized.trim().length === 0) {\n\t\treturn {};\n\t}\n\n\ttry {\n\t\tconst parsed = YAML.parse(normalized) as unknown;\n\t\tif (parsed === null) {\n\t\t\treturn {};\n\t\t}\n\t\tif (typeof parsed !== \"object\" || Array.isArray(parsed)) {\n\t\t\treturn null;\n\t\t}\n\t\treturn parsed as Record<string, unknown>;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nfunction findClosingTagEnd(text: string, contentStart: number, toolName: string): number {\n\tconst closingPattern = new RegExp(`</\\\\s*${escapeRegExp(toolName)}\\\\s*>`, \"g\");\n\tclosingPattern.lastIndex = contentStart;\n\tconst match = closingPattern.exec(text);\n\treturn match?.index === undefined ? -1 : match.index + match[0].length;\n}\n\nfunction shouldEmitRawToolCallTextOnError(options?: ParserOptions): boolean {\n\treturn options?.emitRawToolCallTextOnError === true;\n}\n\nexport function yamlXmlFormatToolsSystemPrompt(tools: Tool[]): string {\n\tif (tools.length === 0) {\n\t\treturn \"\";\n\t}\n\n\tconst toolsRendered = JSON.stringify(\n\t\ttools.map((tool) => ({\n\t\t\tname: tool.name,\n\t\t\tdescription: tool.description,\n\t\t\tparameters: tool.parameters,\n\t\t})),\n\t);\n\n\treturn `# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>${toolsRendered}</tools>\n\n# Format\n\nUse exactly one XML element whose tag name is the function name.\nInside the XML element, specify parameters using YAML syntax (key: value pairs).\n\n# Example\n<get_weather>\ncity: Seoul\nunit: celsius\n</get_weather>`;\n}\n\nexport function yamlXmlFormatToolCall(name: string, args: Record<string, unknown>): string {\n\tconst yamlBody = YAML.stringify(args).trimEnd();\n\treturn `<${name}>\\n${yamlBody.length > 0 ? yamlBody : \"null\"}\\n</${name}>`;\n}\n\nexport function yamlXmlFormatToolResponse(toolName: string, _toolCallId: string, content: TextContent[]): string {\n\tconst textContent = content\n\t\t.filter((entry): entry is TextContent => entry.type === \"text\")\n\t\t.map((entry) => entry.text)\n\t\t.join(\"\\n\");\n\n\treturn [\n\t\t`<tool_response>`,\n\t\t`tool_name: ${toolName}`,\n\t\t`result: |-`,\n\t\t...textContent.split(\"\\n\").map((line) => ` ${line}`),\n\t\t`</tool_response>`,\n\t].join(\"\\n\");\n}\n\nexport function parseYamlXmlGeneratedText(text: string, tools: Tool[], options?: ParserOptions): ParsedToolCall[] {\n\tif (tools.length === 0 || text.length === 0) {\n\t\treturn [];\n\t}\n\n\tconst parsedToolCalls: ParsedToolCall[] = [];\n\tconst toolNames = tools.map((tool) => tool.name);\n\tlet cursor = 0;\n\n\twhile (cursor < text.length) {\n\t\tconst openingTag = findEarliestXmlToolTag(text.slice(cursor), toolNames);\n\t\tif (!openingTag) {\n\t\t\tbreak;\n\t\t}\n\n\t\tconst absoluteIndex = cursor + openingTag.index;\n\t\tif (openingTag.selfClosing) {\n\t\t\tparsedToolCalls.push({ name: openingTag.name, arguments: {} });\n\t\t\tcursor = absoluteIndex + openingTag.tag.length;\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst contentStart = absoluteIndex + openingTag.tag.length;\n\t\tconst closingTagEnd = findClosingTagEnd(text, contentStart, openingTag.name);\n\t\tif (closingTagEnd === -1) {\n\t\t\tbreak;\n\t\t}\n\n\t\tconst closingTagText = text.slice(contentStart, closingTagEnd);\n\t\tconst closingTagMatch = new RegExp(`</\\\\s*${escapeRegExp(openingTag.name)}\\\\s*>`).exec(closingTagText);\n\t\tconst closingTagIndex = closingTagMatch?.index;\n\t\tif (closingTagIndex === undefined) {\n\t\t\tcursor = closingTagEnd;\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst yamlContent = closingTagText.slice(0, closingTagIndex);\n\t\tconst parsedArguments = parseYamlMapping(yamlContent);\n\t\tif (parsedArguments !== null) {\n\t\t\tparsedToolCalls.push({\n\t\t\t\tname: openingTag.name,\n\t\t\t\targuments: parsedArguments,\n\t\t\t});\n\t\t} else {\n\t\t\toptions?.onError?.(\"Could not process YAML XML tool call, keeping original text.\", {\n\t\t\t\ttoolCall: text.slice(absoluteIndex, closingTagEnd),\n\t\t\t});\n\t\t}\n\n\t\tcursor = closingTagEnd;\n\t}\n\n\treturn parsedToolCalls;\n}\n\nexport function createYamlXmlStreamParser(tools: Tool[], options?: ParserOptions): StreamParser {\n\tconst toolNames = tools.map((tool) => tool.name);\n\tlet buffer = \"\";\n\tlet currentToolState: {\n\t\tid: string;\n\t\tindex: number;\n\t\tname: string;\n\t\tlastArgumentsSnapshot: string | null;\n\t} | null = null;\n\tlet nextToolCallIndex = 0;\n\n\tfunction emitSnapshot(events: StreamParserEvent[], yamlContent: string): void {\n\t\tif (!currentToolState) {\n\t\t\treturn;\n\t\t}\n\t\tconst parsedArguments = parseYamlMapping(yamlContent);\n\t\tif (parsedArguments === null) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst snapshot = JSON.stringify(parsedArguments);\n\t\tif (snapshot === \"{}\" || snapshot === currentToolState.lastArgumentsSnapshot) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (currentToolState.lastArgumentsSnapshot === null) {\n\t\t\tevents.push({\n\t\t\t\ttype: \"toolcall_start\",\n\t\t\t\tindex: currentToolState.index,\n\t\t\t\tname: currentToolState.name,\n\t\t\t\tid: currentToolState.id,\n\t\t\t});\n\t\t}\n\n\t\tcurrentToolState.lastArgumentsSnapshot = snapshot;\n\t\tevents.push({\n\t\t\ttype: \"toolcall_delta\",\n\t\t\tindex: currentToolState.index,\n\t\t\targumentsDelta: snapshot,\n\t\t});\n\t}\n\n\tfunction processBuffer(): StreamParserEvent[] {\n\t\tconst events: StreamParserEvent[] = [];\n\n\t\twhile (buffer.length > 0) {\n\t\t\tif (currentToolState) {\n\t\t\t\tconst closingTagRegex = new RegExp(`</\\\\s*${escapeRegExp(currentToolState.name)}\\\\s*>`);\n\t\t\t\tconst closingTagMatch = closingTagRegex.exec(buffer);\n\t\t\t\tif (!closingTagMatch || closingTagMatch.index === undefined) {\n\t\t\t\t\temitSnapshot(events, buffer);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tconst yamlContent = buffer.slice(0, closingTagMatch.index);\n\t\t\t\tconst originalCallText = `<${currentToolState.name}>${yamlContent}${closingTagMatch[0]}`;\n\t\t\t\tconst parsedArguments = parseYamlMapping(yamlContent);\n\t\t\t\tbuffer = buffer.slice(closingTagMatch.index + closingTagMatch[0].length);\n\t\t\t\tif (parsedArguments === null) {\n\t\t\t\t\toptions?.onError?.(\"Could not process YAML XML tool call, keeping original text.\", {\n\t\t\t\t\t\ttoolCall: originalCallText,\n\t\t\t\t\t});\n\t\t\t\t\tif (shouldEmitRawToolCallTextOnError(options)) {\n\t\t\t\t\t\tevents.push({ type: \"text\", text: originalCallText });\n\t\t\t\t\t}\n\t\t\t\t\tcurrentToolState = null;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\temitSnapshot(events, yamlContent);\n\t\t\t\tif (currentToolState.lastArgumentsSnapshot === null) {\n\t\t\t\t\tevents.push({\n\t\t\t\t\t\ttype: \"toolcall_start\",\n\t\t\t\t\t\tindex: currentToolState.index,\n\t\t\t\t\t\tname: currentToolState.name,\n\t\t\t\t\t\tid: currentToolState.id,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tevents.push({\n\t\t\t\t\ttype: \"toolcall_end\",\n\t\t\t\t\tindex: currentToolState.index,\n\t\t\t\t\tname: currentToolState.name,\n\t\t\t\t\tid: currentToolState.id,\n\t\t\t\t\targuments: parsedArguments,\n\t\t\t\t});\n\t\t\t\tcurrentToolState = null;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst openingTag = findEarliestXmlToolTag(buffer, toolNames);\n\t\t\tif (!openingTag) {\n\t\t\t\tconst textLength = getSafeXmlTextLength(buffer, toolNames);\n\t\t\t\tif (textLength === 0) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tevents.push({ type: \"text\", text: buffer.slice(0, textLength) });\n\t\t\t\tbuffer = buffer.slice(textLength);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (openingTag.index > 0) {\n\t\t\t\tevents.push({ type: \"text\", text: buffer.slice(0, openingTag.index) });\n\t\t\t}\n\n\t\t\tbuffer = buffer.slice(openingTag.index + openingTag.tag.length);\n\t\t\tif (openingTag.selfClosing) {\n\t\t\t\tconst id = `yaml-xml-tool-${nextToolCallIndex}`;\n\t\t\t\tconst index = nextToolCallIndex;\n\t\t\t\tnextToolCallIndex += 1;\n\t\t\t\tevents.push({ type: \"toolcall_start\", index, name: openingTag.name, id });\n\t\t\t\tevents.push({ type: \"toolcall_end\", index, name: openingTag.name, id, arguments: {} });\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tcurrentToolState = {\n\t\t\t\tid: `yaml-xml-tool-${nextToolCallIndex}`,\n\t\t\t\tindex: nextToolCallIndex,\n\t\t\t\tname: openingTag.name,\n\t\t\t\tlastArgumentsSnapshot: null,\n\t\t\t};\n\t\t\tnextToolCallIndex += 1;\n\t\t}\n\n\t\treturn events;\n\t}\n\n\treturn {\n\t\tfeed(textDelta: string): StreamParserEvent[] {\n\t\t\tif (textDelta.length === 0) {\n\t\t\t\treturn [];\n\t\t\t}\n\t\t\tbuffer += textDelta;\n\t\t\treturn processBuffer();\n\t\t},\n\t\tfinish(): StreamParserEvent[] {\n\t\t\tconst events = processBuffer();\n\t\t\tif (!currentToolState && buffer.length > 0) {\n\t\t\t\tevents.push({ type: \"text\", text: buffer });\n\t\t\t\tbuffer = \"\";\n\t\t\t}\n\t\t\tif (currentToolState && buffer.length > 0) {\n\t\t\t\tconst parsedArguments = parseYamlMapping(buffer);\n\t\t\t\tif (parsedArguments !== null) {\n\t\t\t\t\temitSnapshot(events, buffer);\n\t\t\t\t\tif (currentToolState.lastArgumentsSnapshot === null) {\n\t\t\t\t\t\tevents.push({\n\t\t\t\t\t\t\ttype: \"toolcall_start\",\n\t\t\t\t\t\t\tindex: currentToolState.index,\n\t\t\t\t\t\t\tname: currentToolState.name,\n\t\t\t\t\t\t\tid: currentToolState.id,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\tevents.push({\n\t\t\t\t\t\ttype: \"toolcall_end\",\n\t\t\t\t\t\tindex: currentToolState.index,\n\t\t\t\t\t\tname: currentToolState.name,\n\t\t\t\t\t\tid: currentToolState.id,\n\t\t\t\t\t\targuments: parsedArguments,\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tconst rawToolCall = `<${currentToolState.name}>${buffer}`;\n\t\t\t\t\toptions?.onError?.(\"Could not complete streaming YAML XML tool call at finish.\", {\n\t\t\t\t\t\ttoolCall: rawToolCall,\n\t\t\t\t\t});\n\t\t\t\t\tif (shouldEmitRawToolCallTextOnError(options)) {\n\t\t\t\t\t\tevents.push({ type: \"text\", text: rawToolCall });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbuffer = \"\";\n\t\t\t\tcurrentToolState = null;\n\t\t\t}\n\t\t\treturn events;\n\t\t},\n\t};\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { AssistantMessageEventStream, Tool } from "../types.ts";
2
+ import type { ToolCallProtocol } from "./types.ts";
3
+ export declare function wrapStreamWithToolCallMiddleware(innerStream: AssistantMessageEventStream, protocol: ToolCallProtocol, tools: Tool[]): AssistantMessageEventStream;
4
+ //# sourceMappingURL=stream-wrapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream-wrapper.d.ts","sourceRoot":"","sources":["../../src/tool-call-middleware/stream-wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEX,2BAA2B,EAE3B,IAAI,EAGJ,MAAM,aAAa,CAAC;AAGrB,OAAO,KAAK,EAAqB,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAwPtE,wBAAgB,gCAAgC,CAC/C,WAAW,EAAE,2BAA2B,EACxC,QAAQ,EAAE,gBAAgB,EAC1B,KAAK,EAAE,IAAI,EAAE,GACX,2BAA2B,CAqL7B","sourcesContent":["import type {\n\tAssistantMessage,\n\tAssistantMessageEventStream,\n\tThinkingContent,\n\tTool,\n\tToolCall,\n\tUsage,\n} from \"../types.ts\";\nimport { AssistantMessageEventStream as AssistantMessageEventStreamImpl } from \"../utils/event-stream.ts\";\nimport { parseStreamingJson } from \"../utils/json-parse.ts\";\nimport type { StreamParserEvent, ToolCallProtocol } from \"./types.ts\";\n\ntype PartialToolCall = ToolCall & {\n\tpartialJson: string;\n};\n\nfunction isPartialToolCall(block: AssistantMessage[\"content\"][number] | undefined): block is PartialToolCall {\n\treturn block?.type === \"toolCall\" && typeof (block as PartialToolCall).partialJson === \"string\";\n}\n\nfunction cloneUsage(usage: Usage): Usage {\n\treturn {\n\t\tinput: usage.input,\n\t\toutput: usage.output,\n\t\tcacheRead: usage.cacheRead,\n\t\tcacheWrite: usage.cacheWrite,\n\t\ttotalTokens: usage.totalTokens,\n\t\tcost: {\n\t\t\tinput: usage.cost.input,\n\t\t\toutput: usage.cost.output,\n\t\t\tcacheRead: usage.cost.cacheRead,\n\t\t\tcacheWrite: usage.cost.cacheWrite,\n\t\t\ttotal: usage.cost.total,\n\t\t},\n\t};\n}\n\nfunction createOuterMessage(message: AssistantMessage): AssistantMessage {\n\treturn {\n\t\trole: \"assistant\",\n\t\tapi: message.api,\n\t\tprovider: message.provider,\n\t\tmodel: message.model,\n\t\tresponseId: message.responseId,\n\t\tcontent: [],\n\t\tusage: cloneUsage(message.usage),\n\t\tstopReason: message.stopReason,\n\t\terrorMessage: message.errorMessage,\n\t\ttimestamp: message.timestamp,\n\t};\n}\n\nfunction syncOuterMetadata(target: AssistantMessage, source: AssistantMessage): void {\n\ttarget.api = source.api;\n\ttarget.provider = source.provider;\n\ttarget.model = source.model;\n\ttarget.responseId = source.responseId;\n\ttarget.usage = cloneUsage(source.usage);\n\ttarget.stopReason = source.stopReason;\n\ttarget.errorMessage = source.errorMessage;\n\ttarget.timestamp = source.timestamp;\n}\n\nfunction pushParserEvent(\n\tparserEvent: StreamParserEvent,\n\touterStream: AssistantMessageEventStream,\n\touterMessage: AssistantMessage,\n\ttextBlockIndexByInnerIndex: Map<number, number | null>,\n\ttoolCallIndexByParserIndex: Map<number, number>,\n\tcurrentInnerTextIndex: number | null,\n): void {\n\tswitch (parserEvent.type) {\n\t\tcase \"text\": {\n\t\t\tif (currentInnerTextIndex == null) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet textBlockIndex = textBlockIndexByInnerIndex.get(currentInnerTextIndex) ?? null;\n\t\t\tif (textBlockIndex == null) {\n\t\t\t\ttextBlockIndex = outerMessage.content.length;\n\t\t\t\touterMessage.content.push({ type: \"text\", text: parserEvent.text });\n\t\t\t\ttextBlockIndexByInnerIndex.set(currentInnerTextIndex, textBlockIndex);\n\t\t\t} else {\n\t\t\t\tconst block = outerMessage.content[textBlockIndex];\n\t\t\t\tif (block?.type !== \"text\") {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tblock.text += parserEvent.text;\n\t\t\t}\n\n\t\t\touterStream.push({\n\t\t\t\ttype: \"text_delta\",\n\t\t\t\tcontentIndex: textBlockIndex,\n\t\t\t\tdelta: parserEvent.text,\n\t\t\t\tpartial: outerMessage,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tcase \"toolcall_start\": {\n\t\t\tconst contentIndex = outerMessage.content.length;\n\t\t\tconst toolCall: PartialToolCall = {\n\t\t\t\ttype: \"toolCall\",\n\t\t\t\tid: parserEvent.id,\n\t\t\t\tname: parserEvent.name,\n\t\t\t\targuments: {},\n\t\t\t\tpartialJson: \"\",\n\t\t\t};\n\t\t\touterMessage.content.push(toolCall);\n\t\t\ttoolCallIndexByParserIndex.set(parserEvent.index, contentIndex);\n\t\t\tif (currentInnerTextIndex != null) {\n\t\t\t\ttextBlockIndexByInnerIndex.set(currentInnerTextIndex, null);\n\t\t\t}\n\t\t\touterStream.push({\n\t\t\t\ttype: \"toolcall_start\",\n\t\t\t\tcontentIndex,\n\t\t\t\tpartial: outerMessage,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tcase \"toolcall_delta\": {\n\t\t\tconst contentIndex = toolCallIndexByParserIndex.get(parserEvent.index);\n\t\t\tif (contentIndex == null) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst block = outerMessage.content[contentIndex];\n\t\t\tif (!isPartialToolCall(block)) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tblock.partialJson += parserEvent.argumentsDelta;\n\t\t\tblock.arguments = parseStreamingJson<Record<string, unknown>>(block.partialJson);\n\t\t\touterStream.push({\n\t\t\t\ttype: \"toolcall_delta\",\n\t\t\t\tcontentIndex,\n\t\t\t\tdelta: parserEvent.argumentsDelta,\n\t\t\t\tpartial: outerMessage,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tcase \"toolcall_end\": {\n\t\t\tconst contentIndex = toolCallIndexByParserIndex.get(parserEvent.index);\n\t\t\tif (contentIndex == null) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst block = outerMessage.content[contentIndex];\n\t\t\tif (block?.type !== \"toolCall\") {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst finalToolCall: ToolCall = {\n\t\t\t\ttype: \"toolCall\",\n\t\t\t\tid: parserEvent.id,\n\t\t\t\tname: parserEvent.name,\n\t\t\t\targuments: parserEvent.arguments,\n\t\t\t};\n\t\t\touterMessage.content[contentIndex] = finalToolCall;\n\t\t\touterStream.push({\n\t\t\t\ttype: \"toolcall_end\",\n\t\t\t\tcontentIndex,\n\t\t\t\ttoolCall: finalToolCall,\n\t\t\t\tpartial: outerMessage,\n\t\t\t});\n\t\t}\n\t}\n}\n\nfunction processParserEvents(\n\tparserEvents: StreamParserEvent[],\n\touterStream: AssistantMessageEventStream,\n\touterMessage: AssistantMessage,\n\ttextBlockIndexByInnerIndex: Map<number, number | null>,\n\ttoolCallIndexByParserIndex: Map<number, number>,\n\tcurrentInnerTextIndex: number | null,\n): boolean {\n\tlet emittedToolCall = false;\n\tfor (const parserEvent of parserEvents) {\n\t\tif (\n\t\t\tparserEvent.type === \"toolcall_start\" ||\n\t\t\tparserEvent.type === \"toolcall_delta\" ||\n\t\t\tparserEvent.type === \"toolcall_end\"\n\t\t) {\n\t\t\temittedToolCall = true;\n\t\t}\n\n\t\tpushParserEvent(\n\t\t\tparserEvent,\n\t\t\touterStream,\n\t\t\touterMessage,\n\t\t\ttextBlockIndexByInnerIndex,\n\t\t\ttoolCallIndexByParserIndex,\n\t\t\tcurrentInnerTextIndex,\n\t\t);\n\t}\n\treturn emittedToolCall;\n}\n\nfunction finalizeMessage(\n\touterMessage: AssistantMessage,\n\tdoneMessage: AssistantMessage,\n\tsawToolCall: boolean,\n): AssistantMessage {\n\tconst finalMessage: AssistantMessage = {\n\t\t...createOuterMessage(doneMessage),\n\t\tcontent: outerMessage.content,\n\t};\n\n\tif (sawToolCall && finalMessage.stopReason === \"stop\") {\n\t\tfinalMessage.stopReason = \"toolUse\";\n\t}\n\n\treturn finalMessage;\n}\n\nfunction hasCompletedToolCallContent(message: AssistantMessage): boolean {\n\treturn message.content.some((block) => block.type === \"toolCall\");\n}\n\nfunction finalizePendingTextBlock(\n\touterStream: AssistantMessageEventStream,\n\touterMessage: AssistantMessage,\n\tparser: ReturnType<ToolCallProtocol[\"createStreamParser\"]>,\n\ttextBlockIndexByInnerIndex: Map<number, number | null>,\n\ttoolCallIndexByParserIndex: Map<number, number>,\n\tcurrentInnerTextIndex: number | null,\n\tsawToolCall: boolean,\n): { currentInnerTextIndex: null; sawToolCall: boolean } {\n\tconst nextSawToolCall =\n\t\tprocessParserEvents(\n\t\t\tparser.finish(),\n\t\t\touterStream,\n\t\t\touterMessage,\n\t\t\ttextBlockIndexByInnerIndex,\n\t\t\ttoolCallIndexByParserIndex,\n\t\t\tcurrentInnerTextIndex,\n\t\t) || sawToolCall;\n\n\tconst outerContentIndex =\n\t\tcurrentInnerTextIndex == null ? null : (textBlockIndexByInnerIndex.get(currentInnerTextIndex) ?? null);\n\tif (outerContentIndex != null) {\n\t\tconst outerBlock = outerMessage.content[outerContentIndex];\n\t\tif (outerBlock?.type === \"text\") {\n\t\t\touterStream.push({\n\t\t\t\ttype: \"text_end\",\n\t\t\t\tcontentIndex: outerContentIndex,\n\t\t\t\tcontent: outerBlock.text,\n\t\t\t\tpartial: outerMessage,\n\t\t\t});\n\t\t}\n\t}\n\n\treturn {\n\t\tcurrentInnerTextIndex: null,\n\t\tsawToolCall: nextSawToolCall,\n\t};\n}\n\nexport function wrapStreamWithToolCallMiddleware(\n\tinnerStream: AssistantMessageEventStream,\n\tprotocol: ToolCallProtocol,\n\ttools: Tool[],\n): AssistantMessageEventStream {\n\tconst outerStream = new AssistantMessageEventStreamImpl();\n\tconst parser = protocol.createStreamParser(tools);\n\n\tvoid (async (): Promise<void> => {\n\t\tlet outerMessage: AssistantMessage | null = null;\n\t\tlet currentInnerTextIndex: number | null = null;\n\t\tlet sawToolCall = false;\n\t\tconst textBlockIndexByInnerIndex = new Map<number, number | null>();\n\t\tconst thinkingBlockIndexByInnerIndex = new Map<number, number>();\n\t\tconst toolCallIndexByParserIndex = new Map<number, number>();\n\n\t\ttry {\n\t\t\tfor await (const event of innerStream) {\n\t\t\t\tswitch (event.type) {\n\t\t\t\t\tcase \"start\": {\n\t\t\t\t\t\touterMessage = createOuterMessage(event.partial);\n\t\t\t\t\t\touterStream.push({ type: \"start\", partial: outerMessage });\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"text_start\": {\n\t\t\t\t\t\tif (outerMessage) {\n\t\t\t\t\t\t\tsyncOuterMetadata(outerMessage, event.partial);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcurrentInnerTextIndex = event.contentIndex;\n\t\t\t\t\t\ttextBlockIndexByInnerIndex.set(event.contentIndex, null);\n\t\t\t\t\t\tif (outerMessage) {\n\t\t\t\t\t\t\touterStream.push({ ...event, partial: outerMessage });\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"text_delta\": {\n\t\t\t\t\t\tif (!outerMessage) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsyncOuterMetadata(outerMessage, event.partial);\n\t\t\t\t\t\tsawToolCall =\n\t\t\t\t\t\t\tprocessParserEvents(\n\t\t\t\t\t\t\t\tparser.feed(event.delta),\n\t\t\t\t\t\t\t\touterStream,\n\t\t\t\t\t\t\t\touterMessage,\n\t\t\t\t\t\t\t\ttextBlockIndexByInnerIndex,\n\t\t\t\t\t\t\t\ttoolCallIndexByParserIndex,\n\t\t\t\t\t\t\t\tcurrentInnerTextIndex,\n\t\t\t\t\t\t\t) || sawToolCall;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"text_end\": {\n\t\t\t\t\t\tif (!outerMessage) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsyncOuterMetadata(outerMessage, event.partial);\n\t\t\t\t\t\t({ currentInnerTextIndex, sawToolCall } = finalizePendingTextBlock(\n\t\t\t\t\t\t\touterStream,\n\t\t\t\t\t\t\touterMessage,\n\t\t\t\t\t\t\tparser,\n\t\t\t\t\t\t\ttextBlockIndexByInnerIndex,\n\t\t\t\t\t\t\ttoolCallIndexByParserIndex,\n\t\t\t\t\t\t\tcurrentInnerTextIndex,\n\t\t\t\t\t\t\tsawToolCall,\n\t\t\t\t\t\t));\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"thinking_start\": {\n\t\t\t\t\t\tif (!outerMessage) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsyncOuterMetadata(outerMessage, event.partial);\n\t\t\t\t\t\tconst contentIndex = outerMessage.content.length;\n\t\t\t\t\t\tconst thinkingBlock: ThinkingContent = { type: \"thinking\", thinking: \"\" };\n\t\t\t\t\t\touterMessage.content.push(thinkingBlock);\n\t\t\t\t\t\tthinkingBlockIndexByInnerIndex.set(event.contentIndex, contentIndex);\n\t\t\t\t\t\touterStream.push({ type: \"thinking_start\", contentIndex, partial: outerMessage });\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"thinking_delta\": {\n\t\t\t\t\t\tif (!outerMessage) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsyncOuterMetadata(outerMessage, event.partial);\n\t\t\t\t\t\tconst contentIndex = thinkingBlockIndexByInnerIndex.get(event.contentIndex);\n\t\t\t\t\t\tif (contentIndex == null) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst block = outerMessage.content[contentIndex];\n\t\t\t\t\t\tif (block?.type !== \"thinking\") {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tblock.thinking += event.delta;\n\t\t\t\t\t\touterStream.push({\n\t\t\t\t\t\t\ttype: \"thinking_delta\",\n\t\t\t\t\t\t\tcontentIndex,\n\t\t\t\t\t\t\tdelta: event.delta,\n\t\t\t\t\t\t\tpartial: outerMessage,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"thinking_end\": {\n\t\t\t\t\t\tif (!outerMessage) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsyncOuterMetadata(outerMessage, event.partial);\n\t\t\t\t\t\tconst contentIndex = thinkingBlockIndexByInnerIndex.get(event.contentIndex);\n\t\t\t\t\t\tif (contentIndex == null) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst block = outerMessage.content[contentIndex];\n\t\t\t\t\t\tif (block?.type !== \"thinking\") {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tblock.thinking = event.content;\n\t\t\t\t\t\touterStream.push({\n\t\t\t\t\t\t\ttype: \"thinking_end\",\n\t\t\t\t\t\t\tcontentIndex,\n\t\t\t\t\t\t\tcontent: event.content,\n\t\t\t\t\t\t\tpartial: outerMessage,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"done\": {\n\t\t\t\t\t\tif (!outerMessage) {\n\t\t\t\t\t\t\touterMessage = createOuterMessage(event.message);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst finalMessage = finalizeMessage(outerMessage, event.message, sawToolCall);\n\t\t\t\t\t\tconst finalReason = sawToolCall && event.reason === \"stop\" ? \"toolUse\" : event.reason;\n\t\t\t\t\t\touterStream.push({ type: \"done\", reason: finalReason, message: finalMessage });\n\t\t\t\t\t\touterStream.end();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"error\": {\n\t\t\t\t\t\tif (!outerMessage) {\n\t\t\t\t\t\t\touterStream.push(event);\n\t\t\t\t\t\t\touterStream.end(event.error);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tsyncOuterMetadata(outerMessage, event.error);\n\t\t\t\t\t\tif (currentInnerTextIndex != null) {\n\t\t\t\t\t\t\t({ currentInnerTextIndex, sawToolCall } = finalizePendingTextBlock(\n\t\t\t\t\t\t\t\touterStream,\n\t\t\t\t\t\t\t\touterMessage,\n\t\t\t\t\t\t\t\tparser,\n\t\t\t\t\t\t\t\ttextBlockIndexByInnerIndex,\n\t\t\t\t\t\t\t\ttoolCallIndexByParserIndex,\n\t\t\t\t\t\t\t\tcurrentInnerTextIndex,\n\t\t\t\t\t\t\t\tsawToolCall,\n\t\t\t\t\t\t\t));\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst finalErrorMessage = finalizeMessage(outerMessage, event.error, sawToolCall);\n\t\t\t\t\t\tif (sawToolCall && hasCompletedToolCallContent(finalErrorMessage)) {\n\t\t\t\t\t\t\tconst recoveredMessage: AssistantMessage = {\n\t\t\t\t\t\t\t\t...finalErrorMessage,\n\t\t\t\t\t\t\t\tstopReason: \"toolUse\",\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\touterStream.push({ type: \"done\", reason: \"toolUse\", message: recoveredMessage });\n\t\t\t\t\t\t\touterStream.end(recoveredMessage);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\touterStream.push({ type: \"error\", reason: event.reason, error: finalErrorMessage });\n\t\t\t\t\t\touterStream.end(finalErrorMessage);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst finalInnerMessage = await innerStream.result();\n\t\t\tif (!outerMessage) {\n\t\t\t\touterMessage = createOuterMessage(finalInnerMessage);\n\t\t\t}\n\t\t\touterStream.end(finalizeMessage(outerMessage, finalInnerMessage, sawToolCall));\n\t\t} catch (error) {\n\t\t\tconst fallbackMessage = outerMessage ?? createOuterMessage(await innerStream.result());\n\t\t\tfallbackMessage.stopReason = \"error\";\n\t\t\tfallbackMessage.errorMessage = error instanceof Error ? error.message : JSON.stringify(error);\n\t\t\touterStream.push({ type: \"error\", reason: \"error\", error: fallbackMessage });\n\t\t\touterStream.end();\n\t\t}\n\t})();\n\n\treturn outerStream;\n}\n"]}
@@ -0,0 +1,336 @@
1
+ import { AssistantMessageEventStream as AssistantMessageEventStreamImpl } from "../utils/event-stream.js";
2
+ import { parseStreamingJson } from "../utils/json-parse.js";
3
+ function isPartialToolCall(block) {
4
+ return block?.type === "toolCall" && typeof block.partialJson === "string";
5
+ }
6
+ function cloneUsage(usage) {
7
+ return {
8
+ input: usage.input,
9
+ output: usage.output,
10
+ cacheRead: usage.cacheRead,
11
+ cacheWrite: usage.cacheWrite,
12
+ totalTokens: usage.totalTokens,
13
+ cost: {
14
+ input: usage.cost.input,
15
+ output: usage.cost.output,
16
+ cacheRead: usage.cost.cacheRead,
17
+ cacheWrite: usage.cost.cacheWrite,
18
+ total: usage.cost.total,
19
+ },
20
+ };
21
+ }
22
+ function createOuterMessage(message) {
23
+ return {
24
+ role: "assistant",
25
+ api: message.api,
26
+ provider: message.provider,
27
+ model: message.model,
28
+ responseId: message.responseId,
29
+ content: [],
30
+ usage: cloneUsage(message.usage),
31
+ stopReason: message.stopReason,
32
+ errorMessage: message.errorMessage,
33
+ timestamp: message.timestamp,
34
+ };
35
+ }
36
+ function syncOuterMetadata(target, source) {
37
+ target.api = source.api;
38
+ target.provider = source.provider;
39
+ target.model = source.model;
40
+ target.responseId = source.responseId;
41
+ target.usage = cloneUsage(source.usage);
42
+ target.stopReason = source.stopReason;
43
+ target.errorMessage = source.errorMessage;
44
+ target.timestamp = source.timestamp;
45
+ }
46
+ function pushParserEvent(parserEvent, outerStream, outerMessage, textBlockIndexByInnerIndex, toolCallIndexByParserIndex, currentInnerTextIndex) {
47
+ switch (parserEvent.type) {
48
+ case "text": {
49
+ if (currentInnerTextIndex == null) {
50
+ return;
51
+ }
52
+ let textBlockIndex = textBlockIndexByInnerIndex.get(currentInnerTextIndex) ?? null;
53
+ if (textBlockIndex == null) {
54
+ textBlockIndex = outerMessage.content.length;
55
+ outerMessage.content.push({ type: "text", text: parserEvent.text });
56
+ textBlockIndexByInnerIndex.set(currentInnerTextIndex, textBlockIndex);
57
+ }
58
+ else {
59
+ const block = outerMessage.content[textBlockIndex];
60
+ if (block?.type !== "text") {
61
+ return;
62
+ }
63
+ block.text += parserEvent.text;
64
+ }
65
+ outerStream.push({
66
+ type: "text_delta",
67
+ contentIndex: textBlockIndex,
68
+ delta: parserEvent.text,
69
+ partial: outerMessage,
70
+ });
71
+ return;
72
+ }
73
+ case "toolcall_start": {
74
+ const contentIndex = outerMessage.content.length;
75
+ const toolCall = {
76
+ type: "toolCall",
77
+ id: parserEvent.id,
78
+ name: parserEvent.name,
79
+ arguments: {},
80
+ partialJson: "",
81
+ };
82
+ outerMessage.content.push(toolCall);
83
+ toolCallIndexByParserIndex.set(parserEvent.index, contentIndex);
84
+ if (currentInnerTextIndex != null) {
85
+ textBlockIndexByInnerIndex.set(currentInnerTextIndex, null);
86
+ }
87
+ outerStream.push({
88
+ type: "toolcall_start",
89
+ contentIndex,
90
+ partial: outerMessage,
91
+ });
92
+ return;
93
+ }
94
+ case "toolcall_delta": {
95
+ const contentIndex = toolCallIndexByParserIndex.get(parserEvent.index);
96
+ if (contentIndex == null) {
97
+ return;
98
+ }
99
+ const block = outerMessage.content[contentIndex];
100
+ if (!isPartialToolCall(block)) {
101
+ return;
102
+ }
103
+ block.partialJson += parserEvent.argumentsDelta;
104
+ block.arguments = parseStreamingJson(block.partialJson);
105
+ outerStream.push({
106
+ type: "toolcall_delta",
107
+ contentIndex,
108
+ delta: parserEvent.argumentsDelta,
109
+ partial: outerMessage,
110
+ });
111
+ return;
112
+ }
113
+ case "toolcall_end": {
114
+ const contentIndex = toolCallIndexByParserIndex.get(parserEvent.index);
115
+ if (contentIndex == null) {
116
+ return;
117
+ }
118
+ const block = outerMessage.content[contentIndex];
119
+ if (block?.type !== "toolCall") {
120
+ return;
121
+ }
122
+ const finalToolCall = {
123
+ type: "toolCall",
124
+ id: parserEvent.id,
125
+ name: parserEvent.name,
126
+ arguments: parserEvent.arguments,
127
+ };
128
+ outerMessage.content[contentIndex] = finalToolCall;
129
+ outerStream.push({
130
+ type: "toolcall_end",
131
+ contentIndex,
132
+ toolCall: finalToolCall,
133
+ partial: outerMessage,
134
+ });
135
+ }
136
+ }
137
+ }
138
+ function processParserEvents(parserEvents, outerStream, outerMessage, textBlockIndexByInnerIndex, toolCallIndexByParserIndex, currentInnerTextIndex) {
139
+ let emittedToolCall = false;
140
+ for (const parserEvent of parserEvents) {
141
+ if (parserEvent.type === "toolcall_start" ||
142
+ parserEvent.type === "toolcall_delta" ||
143
+ parserEvent.type === "toolcall_end") {
144
+ emittedToolCall = true;
145
+ }
146
+ pushParserEvent(parserEvent, outerStream, outerMessage, textBlockIndexByInnerIndex, toolCallIndexByParserIndex, currentInnerTextIndex);
147
+ }
148
+ return emittedToolCall;
149
+ }
150
+ function finalizeMessage(outerMessage, doneMessage, sawToolCall) {
151
+ const finalMessage = {
152
+ ...createOuterMessage(doneMessage),
153
+ content: outerMessage.content,
154
+ };
155
+ if (sawToolCall && finalMessage.stopReason === "stop") {
156
+ finalMessage.stopReason = "toolUse";
157
+ }
158
+ return finalMessage;
159
+ }
160
+ function hasCompletedToolCallContent(message) {
161
+ return message.content.some((block) => block.type === "toolCall");
162
+ }
163
+ function finalizePendingTextBlock(outerStream, outerMessage, parser, textBlockIndexByInnerIndex, toolCallIndexByParserIndex, currentInnerTextIndex, sawToolCall) {
164
+ const nextSawToolCall = processParserEvents(parser.finish(), outerStream, outerMessage, textBlockIndexByInnerIndex, toolCallIndexByParserIndex, currentInnerTextIndex) || sawToolCall;
165
+ const outerContentIndex = currentInnerTextIndex == null ? null : (textBlockIndexByInnerIndex.get(currentInnerTextIndex) ?? null);
166
+ if (outerContentIndex != null) {
167
+ const outerBlock = outerMessage.content[outerContentIndex];
168
+ if (outerBlock?.type === "text") {
169
+ outerStream.push({
170
+ type: "text_end",
171
+ contentIndex: outerContentIndex,
172
+ content: outerBlock.text,
173
+ partial: outerMessage,
174
+ });
175
+ }
176
+ }
177
+ return {
178
+ currentInnerTextIndex: null,
179
+ sawToolCall: nextSawToolCall,
180
+ };
181
+ }
182
+ export function wrapStreamWithToolCallMiddleware(innerStream, protocol, tools) {
183
+ const outerStream = new AssistantMessageEventStreamImpl();
184
+ const parser = protocol.createStreamParser(tools);
185
+ void (async () => {
186
+ let outerMessage = null;
187
+ let currentInnerTextIndex = null;
188
+ let sawToolCall = false;
189
+ const textBlockIndexByInnerIndex = new Map();
190
+ const thinkingBlockIndexByInnerIndex = new Map();
191
+ const toolCallIndexByParserIndex = new Map();
192
+ try {
193
+ for await (const event of innerStream) {
194
+ switch (event.type) {
195
+ case "start": {
196
+ outerMessage = createOuterMessage(event.partial);
197
+ outerStream.push({ type: "start", partial: outerMessage });
198
+ break;
199
+ }
200
+ case "text_start": {
201
+ if (outerMessage) {
202
+ syncOuterMetadata(outerMessage, event.partial);
203
+ }
204
+ currentInnerTextIndex = event.contentIndex;
205
+ textBlockIndexByInnerIndex.set(event.contentIndex, null);
206
+ if (outerMessage) {
207
+ outerStream.push({ ...event, partial: outerMessage });
208
+ }
209
+ break;
210
+ }
211
+ case "text_delta": {
212
+ if (!outerMessage) {
213
+ break;
214
+ }
215
+ syncOuterMetadata(outerMessage, event.partial);
216
+ sawToolCall =
217
+ processParserEvents(parser.feed(event.delta), outerStream, outerMessage, textBlockIndexByInnerIndex, toolCallIndexByParserIndex, currentInnerTextIndex) || sawToolCall;
218
+ break;
219
+ }
220
+ case "text_end": {
221
+ if (!outerMessage) {
222
+ break;
223
+ }
224
+ syncOuterMetadata(outerMessage, event.partial);
225
+ ({ currentInnerTextIndex, sawToolCall } = finalizePendingTextBlock(outerStream, outerMessage, parser, textBlockIndexByInnerIndex, toolCallIndexByParserIndex, currentInnerTextIndex, sawToolCall));
226
+ break;
227
+ }
228
+ case "thinking_start": {
229
+ if (!outerMessage) {
230
+ break;
231
+ }
232
+ syncOuterMetadata(outerMessage, event.partial);
233
+ const contentIndex = outerMessage.content.length;
234
+ const thinkingBlock = { type: "thinking", thinking: "" };
235
+ outerMessage.content.push(thinkingBlock);
236
+ thinkingBlockIndexByInnerIndex.set(event.contentIndex, contentIndex);
237
+ outerStream.push({ type: "thinking_start", contentIndex, partial: outerMessage });
238
+ break;
239
+ }
240
+ case "thinking_delta": {
241
+ if (!outerMessage) {
242
+ break;
243
+ }
244
+ syncOuterMetadata(outerMessage, event.partial);
245
+ const contentIndex = thinkingBlockIndexByInnerIndex.get(event.contentIndex);
246
+ if (contentIndex == null) {
247
+ break;
248
+ }
249
+ const block = outerMessage.content[contentIndex];
250
+ if (block?.type !== "thinking") {
251
+ break;
252
+ }
253
+ block.thinking += event.delta;
254
+ outerStream.push({
255
+ type: "thinking_delta",
256
+ contentIndex,
257
+ delta: event.delta,
258
+ partial: outerMessage,
259
+ });
260
+ break;
261
+ }
262
+ case "thinking_end": {
263
+ if (!outerMessage) {
264
+ break;
265
+ }
266
+ syncOuterMetadata(outerMessage, event.partial);
267
+ const contentIndex = thinkingBlockIndexByInnerIndex.get(event.contentIndex);
268
+ if (contentIndex == null) {
269
+ break;
270
+ }
271
+ const block = outerMessage.content[contentIndex];
272
+ if (block?.type !== "thinking") {
273
+ break;
274
+ }
275
+ block.thinking = event.content;
276
+ outerStream.push({
277
+ type: "thinking_end",
278
+ contentIndex,
279
+ content: event.content,
280
+ partial: outerMessage,
281
+ });
282
+ break;
283
+ }
284
+ case "done": {
285
+ if (!outerMessage) {
286
+ outerMessage = createOuterMessage(event.message);
287
+ }
288
+ const finalMessage = finalizeMessage(outerMessage, event.message, sawToolCall);
289
+ const finalReason = sawToolCall && event.reason === "stop" ? "toolUse" : event.reason;
290
+ outerStream.push({ type: "done", reason: finalReason, message: finalMessage });
291
+ outerStream.end();
292
+ return;
293
+ }
294
+ case "error": {
295
+ if (!outerMessage) {
296
+ outerStream.push(event);
297
+ outerStream.end(event.error);
298
+ return;
299
+ }
300
+ syncOuterMetadata(outerMessage, event.error);
301
+ if (currentInnerTextIndex != null) {
302
+ ({ currentInnerTextIndex, sawToolCall } = finalizePendingTextBlock(outerStream, outerMessage, parser, textBlockIndexByInnerIndex, toolCallIndexByParserIndex, currentInnerTextIndex, sawToolCall));
303
+ }
304
+ const finalErrorMessage = finalizeMessage(outerMessage, event.error, sawToolCall);
305
+ if (sawToolCall && hasCompletedToolCallContent(finalErrorMessage)) {
306
+ const recoveredMessage = {
307
+ ...finalErrorMessage,
308
+ stopReason: "toolUse",
309
+ };
310
+ outerStream.push({ type: "done", reason: "toolUse", message: recoveredMessage });
311
+ outerStream.end(recoveredMessage);
312
+ return;
313
+ }
314
+ outerStream.push({ type: "error", reason: event.reason, error: finalErrorMessage });
315
+ outerStream.end(finalErrorMessage);
316
+ return;
317
+ }
318
+ }
319
+ }
320
+ const finalInnerMessage = await innerStream.result();
321
+ if (!outerMessage) {
322
+ outerMessage = createOuterMessage(finalInnerMessage);
323
+ }
324
+ outerStream.end(finalizeMessage(outerMessage, finalInnerMessage, sawToolCall));
325
+ }
326
+ catch (error) {
327
+ const fallbackMessage = outerMessage ?? createOuterMessage(await innerStream.result());
328
+ fallbackMessage.stopReason = "error";
329
+ fallbackMessage.errorMessage = error instanceof Error ? error.message : JSON.stringify(error);
330
+ outerStream.push({ type: "error", reason: "error", error: fallbackMessage });
331
+ outerStream.end();
332
+ }
333
+ })();
334
+ return outerStream;
335
+ }
336
+ //# sourceMappingURL=stream-wrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream-wrapper.js","sourceRoot":"","sources":["../../src/tool-call-middleware/stream-wrapper.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,2BAA2B,IAAI,+BAA+B,EAAE,MAAM,0BAA0B,CAAC;AAC1G,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAO5D,SAAS,iBAAiB,CAAC,KAAsD,EAA4B;IAC5G,OAAO,KAAK,EAAE,IAAI,KAAK,UAAU,IAAI,OAAQ,KAAyB,CAAC,WAAW,KAAK,QAAQ,CAAC;AAAA,CAChG;AAED,SAAS,UAAU,CAAC,KAAY,EAAS;IACxC,OAAO;QACN,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,IAAI,EAAE;YACL,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK;YACvB,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM;YACzB,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,SAAS;YAC/B,UAAU,EAAE,KAAK,CAAC,IAAI,CAAC,UAAU;YACjC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK;SACvB;KACD,CAAC;AAAA,CACF;AAED,SAAS,kBAAkB,CAAC,OAAyB,EAAoB;IACxE,OAAO;QACN,IAAI,EAAE,WA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AAAA,CACnB","sourcesContent":["import type {\n\tAssistantMessage,\n\tAssistantMessageEventStream,\n\tThinkingContent,\n\tTool,\n\tToolCall,\n\tUsage,\n} from \"../types.ts\";\nimport { AssistantMessageEventStream as AssistantMessageEventStreamImpl } from \"../utils/event-stream.ts\";\nimport { parseStreamingJson } from \"../utils/json-parse.ts\";\nimport type { StreamParserEvent, ToolCallProtocol } from \"./types.ts\";\n\ntype PartialToolCall = ToolCall & {\n\tpartialJson: string;\n};\n\nfunction isPartialToolCall(block: AssistantMessage[\"content\"][number] | undefined): block is PartialToolCall {\n\treturn block?.type === \"toolCall\" && typeof (block as PartialToolCall).partialJson === \"string\";\n}\n\nfunction cloneUsage(usage: Usage): Usage {\n\treturn {\n\t\tinput: usage.input,\n\t\toutput: usage.output,\n\t\tcacheRead: usage.cacheRead,\n\t\tcacheWrite: usage.cacheWrite,\n\t\ttotalTokens: usage.totalTokens,\n\t\tcost: {\n\t\t\tinput: usage.cost.input,\n\t\t\toutput: usage.cost.output,\n\t\t\tcacheRead: usage.cost.cacheRead,\n\t\t\tcacheWrite: usage.cost.cacheWrite,\n\t\t\ttotal: usage.cost.total,\n\t\t},\n\t};\n}\n\nfunction createOuterMessage(message: AssistantMessage): AssistantMessage {\n\treturn {\n\t\trole: \"assistant\",\n\t\tapi: message.api,\n\t\tprovider: message.provider,\n\t\tmodel: message.model,\n\t\tresponseId: message.responseId,\n\t\tcontent: [],\n\t\tusage: cloneUsage(message.usage),\n\t\tstopReason: message.stopReason,\n\t\terrorMessage: message.errorMessage,\n\t\ttimestamp: message.timestamp,\n\t};\n}\n\nfunction syncOuterMetadata(target: AssistantMessage, source: AssistantMessage): void {\n\ttarget.api = source.api;\n\ttarget.provider = source.provider;\n\ttarget.model = source.model;\n\ttarget.responseId = source.responseId;\n\ttarget.usage = cloneUsage(source.usage);\n\ttarget.stopReason = source.stopReason;\n\ttarget.errorMessage = source.errorMessage;\n\ttarget.timestamp = source.timestamp;\n}\n\nfunction pushParserEvent(\n\tparserEvent: StreamParserEvent,\n\touterStream: AssistantMessageEventStream,\n\touterMessage: AssistantMessage,\n\ttextBlockIndexByInnerIndex: Map<number, number | null>,\n\ttoolCallIndexByParserIndex: Map<number, number>,\n\tcurrentInnerTextIndex: number | null,\n): void {\n\tswitch (parserEvent.type) {\n\t\tcase \"text\": {\n\t\t\tif (currentInnerTextIndex == null) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet textBlockIndex = textBlockIndexByInnerIndex.get(currentInnerTextIndex) ?? null;\n\t\t\tif (textBlockIndex == null) {\n\t\t\t\ttextBlockIndex = outerMessage.content.length;\n\t\t\t\touterMessage.content.push({ type: \"text\", text: parserEvent.text });\n\t\t\t\ttextBlockIndexByInnerIndex.set(currentInnerTextIndex, textBlockIndex);\n\t\t\t} else {\n\t\t\t\tconst block = outerMessage.content[textBlockIndex];\n\t\t\t\tif (block?.type !== \"text\") {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tblock.text += parserEvent.text;\n\t\t\t}\n\n\t\t\touterStream.push({\n\t\t\t\ttype: \"text_delta\",\n\t\t\t\tcontentIndex: textBlockIndex,\n\t\t\t\tdelta: parserEvent.text,\n\t\t\t\tpartial: outerMessage,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tcase \"toolcall_start\": {\n\t\t\tconst contentIndex = outerMessage.content.length;\n\t\t\tconst toolCall: PartialToolCall = {\n\t\t\t\ttype: \"toolCall\",\n\t\t\t\tid: parserEvent.id,\n\t\t\t\tname: parserEvent.name,\n\t\t\t\targuments: {},\n\t\t\t\tpartialJson: \"\",\n\t\t\t};\n\t\t\touterMessage.content.push(toolCall);\n\t\t\ttoolCallIndexByParserIndex.set(parserEvent.index, contentIndex);\n\t\t\tif (currentInnerTextIndex != null) {\n\t\t\t\ttextBlockIndexByInnerIndex.set(currentInnerTextIndex, null);\n\t\t\t}\n\t\t\touterStream.push({\n\t\t\t\ttype: \"toolcall_start\",\n\t\t\t\tcontentIndex,\n\t\t\t\tpartial: outerMessage,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tcase \"toolcall_delta\": {\n\t\t\tconst contentIndex = toolCallIndexByParserIndex.get(parserEvent.index);\n\t\t\tif (contentIndex == null) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst block = outerMessage.content[contentIndex];\n\t\t\tif (!isPartialToolCall(block)) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tblock.partialJson += parserEvent.argumentsDelta;\n\t\t\tblock.arguments = parseStreamingJson<Record<string, unknown>>(block.partialJson);\n\t\t\touterStream.push({\n\t\t\t\ttype: \"toolcall_delta\",\n\t\t\t\tcontentIndex,\n\t\t\t\tdelta: parserEvent.argumentsDelta,\n\t\t\t\tpartial: outerMessage,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tcase \"toolcall_end\": {\n\t\t\tconst contentIndex = toolCallIndexByParserIndex.get(parserEvent.index);\n\t\t\tif (contentIndex == null) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst block = outerMessage.content[contentIndex];\n\t\t\tif (block?.type !== \"toolCall\") {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst finalToolCall: ToolCall = {\n\t\t\t\ttype: \"toolCall\",\n\t\t\t\tid: parserEvent.id,\n\t\t\t\tname: parserEvent.name,\n\t\t\t\targuments: parserEvent.arguments,\n\t\t\t};\n\t\t\touterMessage.content[contentIndex] = finalToolCall;\n\t\t\touterStream.push({\n\t\t\t\ttype: \"toolcall_end\",\n\t\t\t\tcontentIndex,\n\t\t\t\ttoolCall: finalToolCall,\n\t\t\t\tpartial: outerMessage,\n\t\t\t});\n\t\t}\n\t}\n}\n\nfunction processParserEvents(\n\tparserEvents: StreamParserEvent[],\n\touterStream: AssistantMessageEventStream,\n\touterMessage: AssistantMessage,\n\ttextBlockIndexByInnerIndex: Map<number, number | null>,\n\ttoolCallIndexByParserIndex: Map<number, number>,\n\tcurrentInnerTextIndex: number | null,\n): boolean {\n\tlet emittedToolCall = false;\n\tfor (const parserEvent of parserEvents) {\n\t\tif (\n\t\t\tparserEvent.type === \"toolcall_start\" ||\n\t\t\tparserEvent.type === \"toolcall_delta\" ||\n\t\t\tparserEvent.type === \"toolcall_end\"\n\t\t) {\n\t\t\temittedToolCall = true;\n\t\t}\n\n\t\tpushParserEvent(\n\t\t\tparserEvent,\n\t\t\touterStream,\n\t\t\touterMessage,\n\t\t\ttextBlockIndexByInnerIndex,\n\t\t\ttoolCallIndexByParserIndex,\n\t\t\tcurrentInnerTextIndex,\n\t\t);\n\t}\n\treturn emittedToolCall;\n}\n\nfunction finalizeMessage(\n\touterMessage: AssistantMessage,\n\tdoneMessage: AssistantMessage,\n\tsawToolCall: boolean,\n): AssistantMessage {\n\tconst finalMessage: AssistantMessage = {\n\t\t...createOuterMessage(doneMessage),\n\t\tcontent: outerMessage.content,\n\t};\n\n\tif (sawToolCall && finalMessage.stopReason === \"stop\") {\n\t\tfinalMessage.stopReason = \"toolUse\";\n\t}\n\n\treturn finalMessage;\n}\n\nfunction hasCompletedToolCallContent(message: AssistantMessage): boolean {\n\treturn message.content.some((block) => block.type === \"toolCall\");\n}\n\nfunction finalizePendingTextBlock(\n\touterStream: AssistantMessageEventStream,\n\touterMessage: AssistantMessage,\n\tparser: ReturnType<ToolCallProtocol[\"createStreamParser\"]>,\n\ttextBlockIndexByInnerIndex: Map<number, number | null>,\n\ttoolCallIndexByParserIndex: Map<number, number>,\n\tcurrentInnerTextIndex: number | null,\n\tsawToolCall: boolean,\n): { currentInnerTextIndex: null; sawToolCall: boolean } {\n\tconst nextSawToolCall =\n\t\tprocessParserEvents(\n\t\t\tparser.finish(),\n\t\t\touterStream,\n\t\t\touterMessage,\n\t\t\ttextBlockIndexByInnerIndex,\n\t\t\ttoolCallIndexByParserIndex,\n\t\t\tcurrentInnerTextIndex,\n\t\t) || sawToolCall;\n\n\tconst outerContentIndex =\n\t\tcurrentInnerTextIndex == null ? null : (textBlockIndexByInnerIndex.get(currentInnerTextIndex) ?? null);\n\tif (outerContentIndex != null) {\n\t\tconst outerBlock = outerMessage.content[outerContentIndex];\n\t\tif (outerBlock?.type === \"text\") {\n\t\t\touterStream.push({\n\t\t\t\ttype: \"text_end\",\n\t\t\t\tcontentIndex: outerContentIndex,\n\t\t\t\tcontent: outerBlock.text,\n\t\t\t\tpartial: outerMessage,\n\t\t\t});\n\t\t}\n\t}\n\n\treturn {\n\t\tcurrentInnerTextIndex: null,\n\t\tsawToolCall: nextSawToolCall,\n\t};\n}\n\nexport function wrapStreamWithToolCallMiddleware(\n\tinnerStream: AssistantMessageEventStream,\n\tprotocol: ToolCallProtocol,\n\ttools: Tool[],\n): AssistantMessageEventStream {\n\tconst outerStream = new AssistantMessageEventStreamImpl();\n\tconst parser = protocol.createStreamParser(tools);\n\n\tvoid (async (): Promise<void> => {\n\t\tlet outerMessage: AssistantMessage | null = null;\n\t\tlet currentInnerTextIndex: number | null = null;\n\t\tlet sawToolCall = false;\n\t\tconst textBlockIndexByInnerIndex = new Map<number, number | null>();\n\t\tconst thinkingBlockIndexByInnerIndex = new Map<number, number>();\n\t\tconst toolCallIndexByParserIndex = new Map<number, number>();\n\n\t\ttry {\n\t\t\tfor await (const event of innerStream) {\n\t\t\t\tswitch (event.type) {\n\t\t\t\t\tcase \"start\": {\n\t\t\t\t\t\touterMessage = createOuterMessage(event.partial);\n\t\t\t\t\t\touterStream.push({ type: \"start\", partial: outerMessage });\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"text_start\": {\n\t\t\t\t\t\tif (outerMessage) {\n\t\t\t\t\t\t\tsyncOuterMetadata(outerMessage, event.partial);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcurrentInnerTextIndex = event.contentIndex;\n\t\t\t\t\t\ttextBlockIndexByInnerIndex.set(event.contentIndex, null);\n\t\t\t\t\t\tif (outerMessage) {\n\t\t\t\t\t\t\touterStream.push({ ...event, partial: outerMessage });\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"text_delta\": {\n\t\t\t\t\t\tif (!outerMessage) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsyncOuterMetadata(outerMessage, event.partial);\n\t\t\t\t\t\tsawToolCall =\n\t\t\t\t\t\t\tprocessParserEvents(\n\t\t\t\t\t\t\t\tparser.feed(event.delta),\n\t\t\t\t\t\t\t\touterStream,\n\t\t\t\t\t\t\t\touterMessage,\n\t\t\t\t\t\t\t\ttextBlockIndexByInnerIndex,\n\t\t\t\t\t\t\t\ttoolCallIndexByParserIndex,\n\t\t\t\t\t\t\t\tcurrentInnerTextIndex,\n\t\t\t\t\t\t\t) || sawToolCall;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"text_end\": {\n\t\t\t\t\t\tif (!outerMessage) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsyncOuterMetadata(outerMessage, event.partial);\n\t\t\t\t\t\t({ currentInnerTextIndex, sawToolCall } = finalizePendingTextBlock(\n\t\t\t\t\t\t\touterStream,\n\t\t\t\t\t\t\touterMessage,\n\t\t\t\t\t\t\tparser,\n\t\t\t\t\t\t\ttextBlockIndexByInnerIndex,\n\t\t\t\t\t\t\ttoolCallIndexByParserIndex,\n\t\t\t\t\t\t\tcurrentInnerTextIndex,\n\t\t\t\t\t\t\tsawToolCall,\n\t\t\t\t\t\t));\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"thinking_start\": {\n\t\t\t\t\t\tif (!outerMessage) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsyncOuterMetadata(outerMessage, event.partial);\n\t\t\t\t\t\tconst contentIndex = outerMessage.content.length;\n\t\t\t\t\t\tconst thinkingBlock: ThinkingContent = { type: \"thinking\", thinking: \"\" };\n\t\t\t\t\t\touterMessage.content.push(thinkingBlock);\n\t\t\t\t\t\tthinkingBlockIndexByInnerIndex.set(event.contentIndex, contentIndex);\n\t\t\t\t\t\touterStream.push({ type: \"thinking_start\", contentIndex, partial: outerMessage });\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"thinking_delta\": {\n\t\t\t\t\t\tif (!outerMessage) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsyncOuterMetadata(outerMessage, event.partial);\n\t\t\t\t\t\tconst contentIndex = thinkingBlockIndexByInnerIndex.get(event.contentIndex);\n\t\t\t\t\t\tif (contentIndex == null) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst block = outerMessage.content[contentIndex];\n\t\t\t\t\t\tif (block?.type !== \"thinking\") {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tblock.thinking += event.delta;\n\t\t\t\t\t\touterStream.push({\n\t\t\t\t\t\t\ttype: \"thinking_delta\",\n\t\t\t\t\t\t\tcontentIndex,\n\t\t\t\t\t\t\tdelta: event.delta,\n\t\t\t\t\t\t\tpartial: outerMessage,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"thinking_end\": {\n\t\t\t\t\t\tif (!outerMessage) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsyncOuterMetadata(outerMessage, event.partial);\n\t\t\t\t\t\tconst contentIndex = thinkingBlockIndexByInnerIndex.get(event.contentIndex);\n\t\t\t\t\t\tif (contentIndex == null) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst block = outerMessage.content[contentIndex];\n\t\t\t\t\t\tif (block?.type !== \"thinking\") {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tblock.thinking = event.content;\n\t\t\t\t\t\touterStream.push({\n\t\t\t\t\t\t\ttype: \"thinking_end\",\n\t\t\t\t\t\t\tcontentIndex,\n\t\t\t\t\t\t\tcontent: event.content,\n\t\t\t\t\t\t\tpartial: outerMessage,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"done\": {\n\t\t\t\t\t\tif (!outerMessage) {\n\t\t\t\t\t\t\touterMessage = createOuterMessage(event.message);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst finalMessage = finalizeMessage(outerMessage, event.message, sawToolCall);\n\t\t\t\t\t\tconst finalReason = sawToolCall && event.reason === \"stop\" ? \"toolUse\" : event.reason;\n\t\t\t\t\t\touterStream.push({ type: \"done\", reason: finalReason, message: finalMessage });\n\t\t\t\t\t\touterStream.end();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"error\": {\n\t\t\t\t\t\tif (!outerMessage) {\n\t\t\t\t\t\t\touterStream.push(event);\n\t\t\t\t\t\t\touterStream.end(event.error);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tsyncOuterMetadata(outerMessage, event.error);\n\t\t\t\t\t\tif (currentInnerTextIndex != null) {\n\t\t\t\t\t\t\t({ currentInnerTextIndex, sawToolCall } = finalizePendingTextBlock(\n\t\t\t\t\t\t\t\touterStream,\n\t\t\t\t\t\t\t\touterMessage,\n\t\t\t\t\t\t\t\tparser,\n\t\t\t\t\t\t\t\ttextBlockIndexByInnerIndex,\n\t\t\t\t\t\t\t\ttoolCallIndexByParserIndex,\n\t\t\t\t\t\t\t\tcurrentInnerTextIndex,\n\t\t\t\t\t\t\t\tsawToolCall,\n\t\t\t\t\t\t\t));\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst finalErrorMessage = finalizeMessage(outerMessage, event.error, sawToolCall);\n\t\t\t\t\t\tif (sawToolCall && hasCompletedToolCallContent(finalErrorMessage)) {\n\t\t\t\t\t\t\tconst recoveredMessage: AssistantMessage = {\n\t\t\t\t\t\t\t\t...finalErrorMessage,\n\t\t\t\t\t\t\t\tstopReason: \"toolUse\",\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\touterStream.push({ type: \"done\", reason: \"toolUse\", message: recoveredMessage });\n\t\t\t\t\t\t\touterStream.end(recoveredMessage);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\touterStream.push({ type: \"error\", reason: event.reason, error: finalErrorMessage });\n\t\t\t\t\t\touterStream.end(finalErrorMessage);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst finalInnerMessage = await innerStream.result();\n\t\t\tif (!outerMessage) {\n\t\t\t\touterMessage = createOuterMessage(finalInnerMessage);\n\t\t\t}\n\t\t\touterStream.end(finalizeMessage(outerMessage, finalInnerMessage, sawToolCall));\n\t\t} catch (error) {\n\t\t\tconst fallbackMessage = outerMessage ?? createOuterMessage(await innerStream.result());\n\t\t\tfallbackMessage.stopReason = \"error\";\n\t\t\tfallbackMessage.errorMessage = error instanceof Error ? error.message : JSON.stringify(error);\n\t\t\touterStream.push({ type: \"error\", reason: \"error\", error: fallbackMessage });\n\t\t\touterStream.end();\n\t\t}\n\t})();\n\n\treturn outerStream;\n}\n"]}
@@ -0,0 +1,103 @@
1
+ import type { ImageContent, TextContent, Tool } from "../types.ts";
2
+ /**
3
+ * Supported tool call formats for models that don't natively support tool calling.
4
+ * - "hermes": Hermes 2/3 format with special delimiters
5
+ * - "xml": XML-based tool call format
6
+ * - "gemma4-delimiter": Gemma 4 specific delimiter format
7
+ */
8
+ export type ToolCallFormat = "hermes" | "xml" | "yaml-xml" | "gemma4-delimiter";
9
+ /**
10
+ * Content type for tool results (text or image)
11
+ */
12
+ export type ToolResultContent = TextContent | ImageContent;
13
+ export interface ParserOptions {
14
+ emitRawToolCallTextOnError?: boolean;
15
+ onError?: (message: string, metadata?: Record<string, unknown>) => void;
16
+ }
17
+ /**
18
+ * A parsed tool call extracted from generated text
19
+ */
20
+ export interface ParsedToolCall {
21
+ name: string;
22
+ arguments: Record<string, unknown>;
23
+ }
24
+ /**
25
+ * Events emitted by the stream parser during text processing.
26
+ * Maps 1:1 to AssistantMessageEventStream events for seamless integration.
27
+ */
28
+ export type StreamParserEvent = {
29
+ type: "text";
30
+ text: string;
31
+ } | {
32
+ type: "toolcall_start";
33
+ index: number;
34
+ name: string;
35
+ id: string;
36
+ } | {
37
+ type: "toolcall_delta";
38
+ index: number;
39
+ argumentsDelta: string;
40
+ } | {
41
+ type: "toolcall_end";
42
+ index: number;
43
+ name: string;
44
+ id: string;
45
+ arguments: Record<string, unknown>;
46
+ };
47
+ /**
48
+ * Stream parser for incremental tool call parsing during streaming.
49
+ */
50
+ export interface StreamParser {
51
+ /**
52
+ * Feed a text delta into the parser and receive any events generated.
53
+ * @param textDelta - The next chunk of text to parse
54
+ * @returns Array of parser events (text or tool call events)
55
+ */
56
+ feed(textDelta: string): StreamParserEvent[];
57
+ /**
58
+ * Signal that the stream has ended and receive any final events.
59
+ * @returns Array of final parser events
60
+ */
61
+ finish(): StreamParserEvent[];
62
+ }
63
+ /**
64
+ * Protocol interface for formatting and parsing tool calls in different formats.
65
+ * Implementations handle the specifics of each tool call format (Hermes, XML, etc.)
66
+ */
67
+ export interface ToolCallProtocol {
68
+ /**
69
+ * Format tools into a system prompt that instructs the model how to use tools.
70
+ * @param tools - Array of available tools
71
+ * @returns Formatted system prompt string
72
+ */
73
+ formatToolsSystemPrompt(tools: Tool[]): string;
74
+ /**
75
+ * Format a tool response for inclusion in the conversation context.
76
+ * @param toolName - Name of the tool that was called
77
+ * @param toolCallId - Unique identifier for this tool call
78
+ * @param content - Array of content blocks (text or images) representing the result
79
+ * @returns Formatted tool response string
80
+ */
81
+ formatToolResponse(toolName: string, toolCallId: string, content: ToolResultContent[]): string;
82
+ /**
83
+ * Format a tool call for sending to the model.
84
+ * @param name - Name of the tool to call
85
+ * @param args - Arguments for the tool call
86
+ * @returns Formatted tool call string
87
+ */
88
+ formatToolCall(name: string, args: Record<string, unknown>): string;
89
+ /**
90
+ * Parse generated text to extract tool calls.
91
+ * @param text - The generated text to parse
92
+ * @param tools - Available tools for validation
93
+ * @returns Array of parsed tool calls
94
+ */
95
+ parseGeneratedText(text: string, tools: Tool[], options?: ParserOptions): ParsedToolCall[];
96
+ /**
97
+ * Create a stream parser for incremental parsing during streaming.
98
+ * @param tools - Available tools for the parser to recognize
99
+ * @returns A new StreamParser instance
100
+ */
101
+ createStreamParser(tools: Tool[], options?: ParserOptions): StreamParser;
102
+ }
103
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/tool-call-middleware/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEnE;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,KAAK,GAAG,UAAU,GAAG,kBAAkB,CAAC;AAEhF;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,WAAW,GAAG,YAAY,CAAC;AAE3D,MAAM,WAAW,aAAa;IAC7B,0BAA0B,CAAC,EAAE,OAAO,CAAC;IACrC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;CACxE;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAC1B;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,gBAAgB,CAAC;I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.ts\";\n\n/**\n * Supported tool call formats for models that don't natively support tool calling.\n * - \"hermes\": Hermes 2/3 format with special delimiters\n * - \"xml\": XML-based tool call format\n * - \"gemma4-delimiter\": Gemma 4 specific delimiter format\n */\nexport type ToolCallFormat = \"hermes\" | \"xml\" | \"yaml-xml\" | \"gemma4-delimiter\";\n\n/**\n * Content type for tool results (text or image)\n */\nexport type ToolResultContent = TextContent | ImageContent;\n\nexport interface ParserOptions {\n\temitRawToolCallTextOnError?: boolean;\n\tonError?: (message: string, metadata?: Record<string, unknown>) => void;\n}\n\n/**\n * A parsed tool call extracted from generated text\n */\nexport interface ParsedToolCall {\n\tname: string;\n\targuments: Record<string, unknown>;\n}\n\n/**\n * Events emitted by the stream parser during text processing.\n * Maps 1:1 to AssistantMessageEventStream events for seamless integration.\n */\nexport type StreamParserEvent =\n\t| { type: \"text\"; text: string }\n\t| { type: \"toolcall_start\"; index: number; name: string; id: string }\n\t| { type: \"toolcall_delta\"; index: number; argumentsDelta: string }\n\t| {\n\t\t\ttype: \"toolcall_end\";\n\t\t\tindex: number;\n\t\t\tname: string;\n\t\t\tid: string;\n\t\t\targuments: Record<string, unknown>;\n\t };\n\n/**\n * Stream parser for incremental tool call parsing during streaming.\n */\nexport interface StreamParser {\n\t/**\n\t * Feed a text delta into the parser and receive any events generated.\n\t * @param textDelta - The next chunk of text to parse\n\t * @returns Array of parser events (text or tool call events)\n\t */\n\tfeed(textDelta: string): StreamParserEvent[];\n\n\t/**\n\t * Signal that the stream has ended and receive any final events.\n\t * @returns Array of final parser events\n\t */\n\tfinish(): StreamParserEvent[];\n}\n\n/**\n * Protocol interface for formatting and parsing tool calls in different formats.\n * Implementations handle the specifics of each tool call format (Hermes, XML, etc.)\n */\nexport interface ToolCallProtocol {\n\t/**\n\t * Format tools into a system prompt that instructs the model how to use tools.\n\t * @param tools - Array of available tools\n\t * @returns Formatted system prompt string\n\t */\n\tformatToolsSystemPrompt(tools: Tool[]): string;\n\n\t/**\n\t * Format a tool response for inclusion in the conversation context.\n\t * @param toolName - Name of the tool that was called\n\t * @param toolCallId - Unique identifier for this tool call\n\t * @param content - Array of content blocks (text or images) representing the result\n\t * @returns Formatted tool response string\n\t */\n\tformatToolResponse(toolName: string, toolCallId: string, content: ToolResultContent[]): string;\n\n\t/**\n\t * Format a tool call for sending to the model.\n\t * @param name - Name of the tool to call\n\t * @param args - Arguments for the tool call\n\t * @returns Formatted tool call string\n\t */\n\tformatToolCall(name: string, args: Record<string, unknown>): string;\n\n\t/**\n\t * Parse generated text to extract tool calls.\n\t * @param text - The generated text to parse\n\t * @param tools - Available tools for validation\n\t * @returns Array of parsed tool calls\n\t */\n\tparseGeneratedText(text: string, tools: Tool[], options?: ParserOptions): ParsedToolCall[];\n\n\t/**\n\t * Create a stream parser for incremental parsing during streaming.\n\t * @param tools - Available tools for the parser to recognize\n\t * @returns A new StreamParser instance\n\t */\n\tcreateStreamParser(tools: Tool[], options?: ParserOptions): StreamParser;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/tool-call-middleware/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ImageContent, TextContent, Tool } from \"../types.ts\";\n\n/**\n * Supported tool call formats for models that don't natively support tool calling.\n * - \"hermes\": Hermes 2/3 format with special delimiters\n * - \"xml\": XML-based tool call format\n * - \"gemma4-delimiter\": Gemma 4 specific delimiter format\n */\nexport type ToolCallFormat = \"hermes\" | \"xml\" | \"yaml-xml\" | \"gemma4-delimiter\";\n\n/**\n * Content type for tool results (text or image)\n */\nexport type ToolResultContent = TextContent | ImageContent;\n\nexport interface ParserOptions {\n\temitRawToolCallTextOnError?: boolean;\n\tonError?: (message: string, metadata?: Record<string, unknown>) => void;\n}\n\n/**\n * A parsed tool call extracted from generated text\n */\nexport interface ParsedToolCall {\n\tname: string;\n\targuments: Record<string, unknown>;\n}\n\n/**\n * Events emitted by the stream parser during text processing.\n * Maps 1:1 to AssistantMessageEventStream events for seamless integration.\n */\nexport type StreamParserEvent =\n\t| { type: \"text\"; text: string }\n\t| { type: \"toolcall_start\"; index: number; name: string; id: string }\n\t| { type: \"toolcall_delta\"; index: number; argumentsDelta: string }\n\t| {\n\t\t\ttype: \"toolcall_end\";\n\t\t\tindex: number;\n\t\t\tname: string;\n\t\t\tid: string;\n\t\t\targuments: Record<string, unknown>;\n\t };\n\n/**\n * Stream parser for incremental tool call parsing during streaming.\n */\nexport interface StreamParser {\n\t/**\n\t * Feed a text delta into the parser and receive any events generated.\n\t * @param textDelta - The next chunk of text to parse\n\t * @returns Array of parser events (text or tool call events)\n\t */\n\tfeed(textDelta: string): StreamParserEvent[];\n\n\t/**\n\t * Signal that the stream has ended and receive any final events.\n\t * @returns Array of final parser events\n\t */\n\tfinish(): StreamParserEvent[];\n}\n\n/**\n * Protocol interface for formatting and parsing tool calls in different formats.\n * Implementations handle the specifics of each tool call format (Hermes, XML, etc.)\n */\nexport interface ToolCallProtocol {\n\t/**\n\t * Format tools into a system prompt that instructs the model how to use tools.\n\t * @param tools - Array of available tools\n\t * @returns Formatted system prompt string\n\t */\n\tformatToolsSystemPrompt(tools: Tool[]): string;\n\n\t/**\n\t * Format a tool response for inclusion in the conversation context.\n\t * @param toolName - Name of the tool that was called\n\t * @param toolCallId - Unique identifier for this tool call\n\t * @param content - Array of content blocks (text or images) representing the result\n\t * @returns Formatted tool response string\n\t */\n\tformatToolResponse(toolName: string, toolCallId: string, content: ToolResultContent[]): string;\n\n\t/**\n\t * Format a tool call for sending to the model.\n\t * @param name - Name of the tool to call\n\t * @param args - Arguments for the tool call\n\t * @returns Formatted tool call string\n\t */\n\tformatToolCall(name: string, args: Record<string, unknown>): string;\n\n\t/**\n\t * Parse generated text to extract tool calls.\n\t * @param text - The generated text to parse\n\t * @param tools - Available tools for validation\n\t * @returns Array of parsed tool calls\n\t */\n\tparseGeneratedText(text: string, tools: Tool[], options?: ParserOptions): ParsedToolCall[];\n\n\t/**\n\t * Create a stream parser for incremental parsing during streaming.\n\t * @param tools - Available tools for the parser to recognize\n\t * @returns A new StreamParser instance\n\t */\n\tcreateStreamParser(tools: Tool[], options?: ParserOptions): StreamParser;\n}\n"]}