@code-yeongyu/senpi 2026.7.14 → 2026.7.16-2

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 (455) hide show
  1. package/CHANGELOG.md +143 -0
  2. package/README.md +6 -6
  3. package/dist/bun/cli.js +2 -0
  4. package/dist/bun/cli.js.map +1 -1
  5. package/dist/cli/args.js +1 -1
  6. package/dist/cli/args.js.map +1 -1
  7. package/dist/cli/list-models.d.ts +2 -2
  8. package/dist/cli/list-models.d.ts.map +1 -1
  9. package/dist/cli/list-models.js +3 -3
  10. package/dist/cli/list-models.js.map +1 -1
  11. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  12. package/dist/core/agent-session-runtime.js +3 -0
  13. package/dist/core/agent-session-runtime.js.map +1 -1
  14. package/dist/core/agent-session-services.d.ts +4 -3
  15. package/dist/core/agent-session-services.d.ts.map +1 -1
  16. package/dist/core/agent-session-services.js +14 -5
  17. package/dist/core/agent-session-services.js.map +1 -1
  18. package/dist/core/agent-session.d.ts +8 -4
  19. package/dist/core/agent-session.d.ts.map +1 -1
  20. package/dist/core/agent-session.js +81 -30
  21. package/dist/core/agent-session.js.map +1 -1
  22. package/dist/core/auth-providers.js +1 -1
  23. package/dist/core/auth-providers.js.map +1 -1
  24. package/dist/core/auth-storage.d.ts +32 -87
  25. package/dist/core/auth-storage.d.ts.map +1 -1
  26. package/dist/core/auth-storage.js +158 -221
  27. package/dist/core/auth-storage.js.map +1 -1
  28. package/dist/core/cache-stats.d.ts +2 -2
  29. package/dist/core/cache-stats.d.ts.map +1 -1
  30. package/dist/core/cache-stats.js +1 -1
  31. package/dist/core/cache-stats.js.map +1 -1
  32. package/dist/core/compaction/branch-summarization.d.ts +1 -1
  33. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  34. package/dist/core/compaction/branch-summarization.js.map +1 -1
  35. package/dist/core/dynamic-prompt/build.d.ts.map +1 -1
  36. package/dist/core/dynamic-prompt/build.js +6 -1
  37. package/dist/core/dynamic-prompt/build.js.map +1 -1
  38. package/dist/core/extensions/builtin/bash-timeout/timeout.js +2 -2
  39. package/dist/core/extensions/builtin/bash-timeout/timeout.js.map +1 -1
  40. package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.d.ts.map +1 -1
  41. package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.js +22 -13
  42. package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.js.map +1 -1
  43. package/dist/core/extensions/builtin/terminal/runtime-session.d.ts +1 -1
  44. package/dist/core/extensions/builtin/terminal/runtime-session.d.ts.map +1 -1
  45. package/dist/core/extensions/builtin/terminal/runtime-session.js +3 -2
  46. package/dist/core/extensions/builtin/terminal/runtime-session.js.map +1 -1
  47. package/dist/core/extensions/loader.d.ts.map +1 -1
  48. package/dist/core/extensions/loader.js +8 -2
  49. package/dist/core/extensions/loader.js.map +1 -1
  50. package/dist/core/extensions/runner.d.ts +1 -0
  51. package/dist/core/extensions/runner.d.ts.map +1 -1
  52. package/dist/core/extensions/runner.js +3 -0
  53. package/dist/core/extensions/runner.js.map +1 -1
  54. package/dist/core/extensions/types.d.ts +15 -2
  55. package/dist/core/extensions/types.d.ts.map +1 -1
  56. package/dist/core/extensions/types.js.map +1 -1
  57. package/dist/core/model-config.d.ts +589 -0
  58. package/dist/core/model-config.d.ts.map +1 -0
  59. package/dist/core/model-config.js +288 -0
  60. package/dist/core/model-config.js.map +1 -0
  61. package/dist/core/model-registry.d.ts +17 -146
  62. package/dist/core/model-registry.d.ts.map +1 -1
  63. package/dist/core/model-registry.js +69 -943
  64. package/dist/core/model-registry.js.map +1 -1
  65. package/dist/core/model-resolver.d.ts +8 -5
  66. package/dist/core/model-resolver.d.ts.map +1 -1
  67. package/dist/core/model-resolver.js +19 -18
  68. package/dist/core/model-resolver.js.map +1 -1
  69. package/dist/core/model-runtime.d.ts +81 -0
  70. package/dist/core/model-runtime.d.ts.map +1 -0
  71. package/dist/core/model-runtime.js +442 -0
  72. package/dist/core/model-runtime.js.map +1 -0
  73. package/dist/core/models-store.d.ts +17 -0
  74. package/dist/core/models-store.d.ts.map +1 -0
  75. package/dist/core/models-store.js +46 -0
  76. package/dist/core/models-store.js.map +1 -0
  77. package/dist/core/package-manager.d.ts.map +1 -1
  78. package/dist/core/package-manager.js +7 -2
  79. package/dist/core/package-manager.js.map +1 -1
  80. package/dist/core/provider-composer.d.ts +64 -0
  81. package/dist/core/provider-composer.d.ts.map +1 -0
  82. package/dist/core/provider-composer.js +406 -0
  83. package/dist/core/provider-composer.js.map +1 -0
  84. package/dist/core/provider-display-names.d.ts.map +1 -1
  85. package/dist/core/provider-display-names.js +2 -1
  86. package/dist/core/provider-display-names.js.map +1 -1
  87. package/dist/core/radius.d.ts +2 -0
  88. package/dist/core/radius.d.ts.map +1 -0
  89. package/dist/core/radius.js +2 -0
  90. package/dist/core/radius.js.map +1 -0
  91. package/dist/core/remote-catalog-provider.d.ts +5 -0
  92. package/dist/core/remote-catalog-provider.d.ts.map +1 -0
  93. package/dist/core/remote-catalog-provider.js +83 -0
  94. package/dist/core/remote-catalog-provider.js.map +1 -0
  95. package/dist/core/runtime-credentials.d.ts +15 -0
  96. package/dist/core/runtime-credentials.d.ts.map +1 -0
  97. package/dist/core/runtime-credentials.js +35 -0
  98. package/dist/core/runtime-credentials.js.map +1 -0
  99. package/dist/core/sdk.d.ts +11 -20
  100. package/dist/core/sdk.d.ts.map +1 -1
  101. package/dist/core/sdk.js +61 -89
  102. package/dist/core/sdk.js.map +1 -1
  103. package/dist/core/skills.js +1 -1
  104. package/dist/core/skills.js.map +1 -1
  105. package/dist/core/system-prompt.d.ts.map +1 -1
  106. package/dist/core/system-prompt.js +1 -11
  107. package/dist/core/system-prompt.js.map +1 -1
  108. package/dist/index.d.ts +2 -1
  109. package/dist/index.d.ts.map +1 -1
  110. package/dist/index.js +2 -2
  111. package/dist/index.js.map +1 -1
  112. package/dist/main.d.ts.map +1 -1
  113. package/dist/main.js +10 -13
  114. package/dist/main.js.map +1 -1
  115. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  116. package/dist/modes/interactive/components/assistant-message.js +22 -10
  117. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  118. package/dist/modes/interactive/components/footer.js +1 -1
  119. package/dist/modes/interactive/components/footer.js.map +1 -1
  120. package/dist/modes/interactive/components/login-dialog.d.ts +4 -8
  121. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  122. package/dist/modes/interactive/components/login-dialog.js +14 -12
  123. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  124. package/dist/modes/interactive/components/model-selector.d.ts +13 -4
  125. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  126. package/dist/modes/interactive/components/model-selector.js +84 -41
  127. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  128. package/dist/modes/interactive/components/oauth-selector.d.ts +4 -4
  129. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  130. package/dist/modes/interactive/components/oauth-selector.js +14 -25
  131. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  132. package/dist/modes/interactive/interactive-mode.d.ts +5 -1
  133. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  134. package/dist/modes/interactive/interactive-mode.js +155 -129
  135. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  136. package/dist/package-manager-cli.d.ts.map +1 -1
  137. package/dist/package-manager-cli.js +70 -8
  138. package/dist/package-manager-cli.js.map +1 -1
  139. package/docs/custom-provider.md +8 -11
  140. package/docs/extensions.md +78 -555
  141. package/docs/models.md +4 -0
  142. package/docs/packages.md +1 -0
  143. package/docs/providers.md +23 -11
  144. package/docs/sdk.md +79 -105
  145. package/docs/usage.md +1 -0
  146. package/examples/AGENTS.md +34 -0
  147. package/examples/extensions/README.md +1 -0
  148. package/examples/extensions/custom-provider-anthropic/index.ts +1 -1
  149. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  150. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  151. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  152. package/examples/extensions/gondolin/package-lock.json +2 -2
  153. package/examples/extensions/gondolin/package.json +1 -1
  154. package/examples/extensions/kimi-deferred-tools.ts +61 -0
  155. package/examples/extensions/sandbox/package-lock.json +2 -2
  156. package/examples/extensions/sandbox/package.json +1 -1
  157. package/examples/extensions/with-deps/package-lock.json +2 -2
  158. package/examples/extensions/with-deps/package.json +1 -1
  159. package/examples/sdk/02-custom-model.ts +5 -8
  160. package/examples/sdk/09-api-keys-and-oauth.ts +13 -31
  161. package/examples/sdk/12-full-control.ts +8 -13
  162. package/examples/sdk/README.md +14 -18
  163. package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +32 -0
  164. package/node_modules/@code-yeongyu/senpi-codemode/package.json +3 -3
  165. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/local-module-loader.ts +2 -2
  166. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/rewrite-imports.ts +4 -4
  167. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/render.ts +32 -32
  168. package/node_modules/@earendil-works/pi-agent-core/package.json +4 -4
  169. package/node_modules/@earendil-works/pi-ai/README.md +80 -25
  170. package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.d.ts.map +1 -1
  171. package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +23 -42
  172. package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js.map +1 -1
  173. package/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.d.ts.map +1 -1
  174. package/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.js +10 -6
  175. package/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.js.map +1 -1
  176. package/node_modules/@earendil-works/pi-ai/dist/api/lazy.d.ts.map +1 -1
  177. package/node_modules/@earendil-works/pi-ai/dist/api/lazy.js +9 -10
  178. package/node_modules/@earendil-works/pi-ai/dist/api/lazy.js.map +1 -1
  179. package/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.d.ts +1 -0
  180. package/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.d.ts.map +1 -1
  181. package/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js +4 -3
  182. package/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js.map +1 -1
  183. package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.d.ts +2 -1
  184. package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.d.ts.map +1 -1
  185. package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js +54 -5
  186. package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js.map +1 -1
  187. package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses-shared.d.ts.map +1 -1
  188. package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses-shared.js +23 -0
  189. package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses-shared.js.map +1 -1
  190. package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.d.ts +1 -0
  191. package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.d.ts.map +1 -1
  192. package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js +24 -6
  193. package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js.map +1 -1
  194. package/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.d.ts +97 -0
  195. package/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.d.ts.map +1 -0
  196. package/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.js +307 -0
  197. package/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.js.map +1 -0
  198. package/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.lazy.d.ts +3 -0
  199. package/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.lazy.d.ts.map +1 -0
  200. package/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.lazy.js +3 -0
  201. package/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.lazy.js.map +1 -0
  202. package/node_modules/@earendil-works/pi-ai/dist/auth/credential-store.d.ts +2 -1
  203. package/node_modules/@earendil-works/pi-ai/dist/auth/credential-store.d.ts.map +1 -1
  204. package/node_modules/@earendil-works/pi-ai/dist/auth/credential-store.js +3 -0
  205. package/node_modules/@earendil-works/pi-ai/dist/auth/credential-store.js.map +1 -1
  206. package/node_modules/@earendil-works/pi-ai/dist/auth/helpers.d.ts +1 -0
  207. package/node_modules/@earendil-works/pi-ai/dist/auth/helpers.d.ts.map +1 -1
  208. package/node_modules/@earendil-works/pi-ai/dist/auth/helpers.js +4 -3
  209. package/node_modules/@earendil-works/pi-ai/dist/auth/helpers.js.map +1 -1
  210. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/anthropic.d.ts +9 -0
  211. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/anthropic.d.ts.map +1 -0
  212. package/node_modules/@earendil-works/pi-ai/dist/{utils → auth}/oauth/anthropic.js +51 -116
  213. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/anthropic.js.map +1 -0
  214. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/device-code.d.ts.map +1 -0
  215. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/device-code.js.map +1 -0
  216. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/github-copilot.d.ts +6 -0
  217. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/github-copilot.d.ts.map +1 -0
  218. package/node_modules/@earendil-works/pi-ai/dist/{utils → auth}/oauth/github-copilot.js +18 -77
  219. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/github-copilot.js.map +1 -0
  220. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/load.d.ts +23 -0
  221. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/load.d.ts.map +1 -0
  222. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/load.js +49 -0
  223. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/load.js.map +1 -0
  224. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/oauth-page.d.ts.map +1 -0
  225. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/oauth-page.js.map +1 -0
  226. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/openai-codex.d.ts +9 -0
  227. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/openai-codex.d.ts.map +1 -0
  228. package/node_modules/@earendil-works/pi-ai/dist/{utils → auth}/oauth/openai-codex.js +61 -155
  229. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/openai-codex.js.map +1 -0
  230. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/pkce.d.ts.map +1 -0
  231. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/pkce.js.map +1 -0
  232. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/radius.d.ts +16 -0
  233. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/radius.d.ts.map +1 -0
  234. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/radius.js +316 -0
  235. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/radius.js.map +1 -0
  236. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/xai.d.ts +6 -0
  237. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/xai.d.ts.map +1 -0
  238. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/xai.js +189 -0
  239. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/xai.js.map +1 -0
  240. package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.d.ts +2 -4
  241. package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.d.ts.map +1 -1
  242. package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.js +9 -7
  243. package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.js.map +1 -1
  244. package/node_modules/@earendil-works/pi-ai/dist/auth/types.d.ts +49 -10
  245. package/node_modules/@earendil-works/pi-ai/dist/auth/types.d.ts.map +1 -1
  246. package/node_modules/@earendil-works/pi-ai/dist/auth/types.js.map +1 -1
  247. package/node_modules/@earendil-works/pi-ai/dist/bun-oauth.d.ts +3 -0
  248. package/node_modules/@earendil-works/pi-ai/dist/bun-oauth.d.ts.map +1 -0
  249. package/node_modules/@earendil-works/pi-ai/dist/bun-oauth.js +17 -0
  250. package/node_modules/@earendil-works/pi-ai/dist/bun-oauth.js.map +1 -0
  251. package/node_modules/@earendil-works/pi-ai/dist/cli.js +58 -76
  252. package/node_modules/@earendil-works/pi-ai/dist/cli.js.map +1 -1
  253. package/node_modules/@earendil-works/pi-ai/dist/compat/extension-oauth-types.d.ts +42 -0
  254. package/node_modules/@earendil-works/pi-ai/dist/compat/extension-oauth-types.d.ts.map +1 -0
  255. package/node_modules/@earendil-works/pi-ai/dist/compat/extension-oauth-types.js +2 -0
  256. package/node_modules/@earendil-works/pi-ai/dist/compat/extension-oauth-types.js.map +1 -0
  257. package/node_modules/@earendil-works/pi-ai/dist/compat.d.ts +2 -0
  258. package/node_modules/@earendil-works/pi-ai/dist/compat.d.ts.map +1 -1
  259. package/node_modules/@earendil-works/pi-ai/dist/compat.js +49 -22
  260. package/node_modules/@earendil-works/pi-ai/dist/compat.js.map +1 -1
  261. package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.d.ts.map +1 -1
  262. package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.js +1 -0
  263. package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.js.map +1 -1
  264. package/node_modules/@earendil-works/pi-ai/dist/images-models.d.ts +4 -2
  265. package/node_modules/@earendil-works/pi-ai/dist/images-models.d.ts.map +1 -1
  266. package/node_modules/@earendil-works/pi-ai/dist/images-models.js +5 -4
  267. package/node_modules/@earendil-works/pi-ai/dist/images-models.js.map +1 -1
  268. package/node_modules/@earendil-works/pi-ai/dist/index.d.ts +3 -1
  269. package/node_modules/@earendil-works/pi-ai/dist/index.d.ts.map +1 -1
  270. package/node_modules/@earendil-works/pi-ai/dist/index.js +1 -0
  271. package/node_modules/@earendil-works/pi-ai/dist/index.js.map +1 -1
  272. package/node_modules/@earendil-works/pi-ai/dist/models-store.d.ts +25 -0
  273. package/node_modules/@earendil-works/pi-ai/dist/models-store.d.ts.map +1 -0
  274. package/node_modules/@earendil-works/pi-ai/dist/models-store.js +16 -0
  275. package/node_modules/@earendil-works/pi-ai/dist/models-store.js.map +1 -0
  276. package/node_modules/@earendil-works/pi-ai/dist/models.d.ts +69 -30
  277. package/node_modules/@earendil-works/pi-ai/dist/models.d.ts.map +1 -1
  278. package/node_modules/@earendil-works/pi-ai/dist/models.generated.d.ts +328 -120
  279. package/node_modules/@earendil-works/pi-ai/dist/models.generated.d.ts.map +1 -1
  280. package/node_modules/@earendil-works/pi-ai/dist/models.js +217 -31
  281. package/node_modules/@earendil-works/pi-ai/dist/models.js.map +1 -1
  282. package/node_modules/@earendil-works/pi-ai/dist/oauth.d.ts +2 -1
  283. package/node_modules/@earendil-works/pi-ai/dist/oauth.d.ts.map +1 -1
  284. package/node_modules/@earendil-works/pi-ai/dist/oauth.js +1 -1
  285. package/node_modules/@earendil-works/pi-ai/dist/oauth.js.map +1 -1
  286. package/node_modules/@earendil-works/pi-ai/dist/providers/all.d.ts +11 -6
  287. package/node_modules/@earendil-works/pi-ai/dist/providers/all.d.ts.map +1 -1
  288. package/node_modules/@earendil-works/pi-ai/dist/providers/all.js +3 -0
  289. package/node_modules/@earendil-works/pi-ai/dist/providers/all.js.map +1 -1
  290. package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.d.ts.map +1 -1
  291. package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.js +51 -10
  292. package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.js.map +1 -1
  293. package/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.d.ts.map +1 -1
  294. package/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.js +1 -1
  295. package/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.js.map +1 -1
  296. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-ai-gateway.d.ts.map +1 -1
  297. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-ai-gateway.js +4 -3
  298. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-ai-gateway.js.map +1 -1
  299. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-auth.d.ts.map +1 -1
  300. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-auth.js +13 -20
  301. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-auth.js.map +1 -1
  302. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-stream.d.ts +8 -0
  303. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-stream.d.ts.map +1 -0
  304. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-stream.js +21 -0
  305. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-stream.js.map +1 -0
  306. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-workers-ai.d.ts.map +1 -1
  307. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-workers-ai.js +2 -1
  308. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-workers-ai.js.map +1 -1
  309. package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot.d.ts.map +1 -1
  310. package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot.js +11 -1
  311. package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot.js.map +1 -1
  312. package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot.models.d.ts +1 -6
  313. package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot.models.d.ts.map +1 -1
  314. package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot.models.js +1 -2
  315. package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot.models.js.map +1 -1
  316. package/node_modules/@earendil-works/pi-ai/dist/providers/google-vertex.d.ts.map +1 -1
  317. package/node_modules/@earendil-works/pi-ai/dist/providers/google-vertex.js +56 -5
  318. package/node_modules/@earendil-works/pi-ai/dist/providers/google-vertex.js.map +1 -1
  319. package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.models.d.ts +66 -0
  320. package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.models.d.ts.map +1 -1
  321. package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.models.js +42 -0
  322. package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.models.js.map +1 -1
  323. package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai-cn.models.d.ts +36 -0
  324. package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai-cn.models.d.ts.map +1 -1
  325. package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai-cn.models.js +19 -0
  326. package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai-cn.models.js.map +1 -1
  327. package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai.models.d.ts +36 -0
  328. package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai.models.d.ts.map +1 -1
  329. package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai.models.js +19 -0
  330. package/node_modules/@earendil-works/pi-ai/dist/providers/moonshotai.models.js.map +1 -1
  331. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex.d.ts.map +1 -1
  332. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex.js +1 -1
  333. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex.js.map +1 -1
  334. package/node_modules/@earendil-works/pi-ai/dist/providers/opencode.models.d.ts +57 -0
  335. package/node_modules/@earendil-works/pi-ai/dist/providers/opencode.models.d.ts.map +1 -1
  336. package/node_modules/@earendil-works/pi-ai/dist/providers/opencode.models.js +19 -0
  337. package/node_modules/@earendil-works/pi-ai/dist/providers/opencode.models.js.map +1 -1
  338. package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.models.d.ts +42 -0
  339. package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.models.d.ts.map +1 -1
  340. package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.models.js +175 -139
  341. package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.models.js.map +1 -1
  342. package/node_modules/@earendil-works/pi-ai/dist/providers/radius-config.d.ts +26 -0
  343. package/node_modules/@earendil-works/pi-ai/dist/providers/radius-config.d.ts.map +1 -0
  344. package/node_modules/@earendil-works/pi-ai/dist/providers/radius-config.js +59 -0
  345. package/node_modules/@earendil-works/pi-ai/dist/providers/radius-config.js.map +1 -0
  346. package/node_modules/@earendil-works/pi-ai/dist/providers/radius.d.ts +9 -0
  347. package/node_modules/@earendil-works/pi-ai/dist/providers/radius.d.ts.map +1 -0
  348. package/node_modules/@earendil-works/pi-ai/dist/providers/radius.js +54 -0
  349. package/node_modules/@earendil-works/pi-ai/dist/providers/radius.js.map +1 -0
  350. package/node_modules/@earendil-works/pi-ai/dist/providers/vercel-ai-gateway.models.d.ts +84 -0
  351. package/node_modules/@earendil-works/pi-ai/dist/providers/vercel-ai-gateway.models.d.ts.map +1 -1
  352. package/node_modules/@earendil-works/pi-ai/dist/providers/vercel-ai-gateway.models.js +74 -2
  353. package/node_modules/@earendil-works/pi-ai/dist/providers/vercel-ai-gateway.models.js.map +1 -1
  354. package/node_modules/@earendil-works/pi-ai/dist/providers/xai.d.ts +1 -1
  355. package/node_modules/@earendil-works/pi-ai/dist/providers/xai.d.ts.map +1 -1
  356. package/node_modules/@earendil-works/pi-ai/dist/providers/xai.js +15 -3
  357. package/node_modules/@earendil-works/pi-ai/dist/providers/xai.js.map +1 -1
  358. package/node_modules/@earendil-works/pi-ai/dist/providers/xai.models.d.ts +6 -114
  359. package/node_modules/@earendil-works/pi-ai/dist/providers/xai.models.d.ts.map +1 -1
  360. package/node_modules/@earendil-works/pi-ai/dist/providers/xai.models.js +3 -92
  361. package/node_modules/@earendil-works/pi-ai/dist/providers/xai.models.js.map +1 -1
  362. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/context-transformer.d.ts.map +1 -1
  363. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/context-transformer.js +9 -0
  364. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/context-transformer.js.map +1 -1
  365. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/index.d.ts +1 -1
  366. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/index.d.ts.map +1 -1
  367. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/index.js +6 -2
  368. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/index.js.map +1 -1
  369. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/coerce-parameters.d.ts +8 -0
  370. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/coerce-parameters.d.ts.map +1 -0
  371. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/coerce-parameters.js +92 -0
  372. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/coerce-parameters.js.map +1 -0
  373. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/format.d.ts +6 -0
  374. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/format.d.ts.map +1 -0
  375. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/format.js +54 -0
  376. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/format.js.map +1 -0
  377. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/index.d.ts +4 -0
  378. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/index.d.ts.map +1 -0
  379. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/index.js +4 -0
  380. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/index.js.map +1 -0
  381. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-match.d.ts +7 -0
  382. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-match.d.ts.map +1 -0
  383. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-match.js +16 -0
  384. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-match.js.map +1 -0
  385. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-tag-scanner.d.ts +19 -0
  386. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-tag-scanner.d.ts.map +1 -0
  387. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-tag-scanner.js +217 -0
  388. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-tag-scanner.js.map +1 -0
  389. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/parse.d.ts +4 -0
  390. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/parse.d.ts.map +1 -0
  391. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/parse.js +46 -0
  392. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/parse.js.map +1 -0
  393. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream-boundary.d.ts +13 -0
  394. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream-boundary.d.ts.map +1 -0
  395. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream-boundary.js +144 -0
  396. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream-boundary.js.map +1 -0
  397. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream.d.ts +5 -0
  398. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream.d.ts.map +1 -0
  399. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream.js +208 -0
  400. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream.js.map +1 -0
  401. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/tool-resolver.d.ts +4 -0
  402. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/tool-resolver.d.ts.map +1 -0
  403. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/tool-resolver.js +17 -0
  404. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/tool-resolver.js.map +1 -0
  405. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/xml-entities.d.ts +5 -0
  406. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/xml-entities.d.ts.map +1 -0
  407. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/xml-entities.js +34 -0
  408. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/xml-entities.js.map +1 -0
  409. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/types.d.ts +3 -1
  410. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/types.d.ts.map +1 -1
  411. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/types.js.map +1 -1
  412. package/node_modules/@earendil-works/pi-ai/dist/types.d.ts +12 -5
  413. package/node_modules/@earendil-works/pi-ai/dist/types.d.ts.map +1 -1
  414. package/node_modules/@earendil-works/pi-ai/dist/types.js.map +1 -1
  415. package/node_modules/@earendil-works/pi-ai/package.json +6 -1
  416. package/node_modules/@earendil-works/pi-pty/native/prebuilds/darwin-arm64/senpi_pty.darwin-arm64.node +0 -0
  417. package/node_modules/@earendil-works/pi-pty/package.json +1 -1
  418. package/node_modules/@earendil-works/pi-tui/dist/utils.d.ts.map +1 -1
  419. package/node_modules/@earendil-works/pi-tui/dist/utils.js +22 -4
  420. package/node_modules/@earendil-works/pi-tui/dist/utils.js.map +1 -1
  421. package/node_modules/@earendil-works/pi-tui/package.json +1 -1
  422. package/package.json +6 -6
  423. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/anthropic.d.ts +0 -27
  424. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/anthropic.d.ts.map +0 -1
  425. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/anthropic.js.map +0 -1
  426. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/device-code.d.ts.map +0 -1
  427. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/device-code.js.map +0 -1
  428. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/github-copilot.d.ts +0 -32
  429. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/github-copilot.d.ts.map +0 -1
  430. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/github-copilot.js.map +0 -1
  431. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/index.d.ts +0 -58
  432. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/index.d.ts.map +0 -1
  433. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/index.js +0 -122
  434. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/index.js.map +0 -1
  435. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/load.d.ts +0 -5
  436. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/load.d.ts.map +0 -1
  437. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/load.js +0 -22
  438. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/load.js.map +0 -1
  439. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/oauth-page.d.ts.map +0 -1
  440. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/oauth-page.js.map +0 -1
  441. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/openai-codex.d.ts +0 -45
  442. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/openai-codex.d.ts.map +0 -1
  443. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/openai-codex.js.map +0 -1
  444. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/pkce.d.ts.map +0 -1
  445. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/pkce.js.map +0 -1
  446. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/types.d.ts +0 -64
  447. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/types.d.ts.map +0 -1
  448. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/types.js +0 -2
  449. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/types.js.map +0 -1
  450. /package/node_modules/@earendil-works/pi-ai/dist/{utils → auth}/oauth/device-code.d.ts +0 -0
  451. /package/node_modules/@earendil-works/pi-ai/dist/{utils → auth}/oauth/device-code.js +0 -0
  452. /package/node_modules/@earendil-works/pi-ai/dist/{utils → auth}/oauth/oauth-page.d.ts +0 -0
  453. /package/node_modules/@earendil-works/pi-ai/dist/{utils → auth}/oauth/oauth-page.js +0 -0
  454. /package/node_modules/@earendil-works/pi-ai/dist/{utils → auth}/oauth/pkce.d.ts +0 -0
  455. /package/node_modules/@earendil-works/pi-ai/dist/{utils → auth}/oauth/pkce.js +0 -0
@@ -0,0 +1,54 @@
1
+ import { encodeXmlAttribute, encodeXmlParameterText, encodeXmlText } from "./xml-entities.js";
2
+ function serializeToolValue(value) {
3
+ if (typeof value === "object" && value !== null) {
4
+ return JSON.stringify(value) ?? "null";
5
+ }
6
+ return String(value);
7
+ }
8
+ function renderToolDefinitions(tools) {
9
+ const json = JSON.stringify(tools.map((tool) => ({
10
+ name: tool.name,
11
+ description: tool.description,
12
+ parameters: tool.parameters,
13
+ })));
14
+ return json.replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026");
15
+ }
16
+ export function anthropicXmlFormatToolsSystemPrompt(tools) {
17
+ if (tools.length === 0) {
18
+ return "";
19
+ }
20
+ return `# Tools
21
+
22
+ You may call one or more functions to assist with the user query.
23
+
24
+ You are provided with function signatures as JSON within <tools></tools> XML tags:
25
+ <tools>${renderToolDefinitions(tools)}</tools>
26
+
27
+ # Format
28
+
29
+ For each function call, emit exactly one bare <invoke> element with the tool name in its name attribute.
30
+ Put each argument in one <parameter> element with its name in the name attribute.
31
+ Do not wrap the invoke element in another XML element.
32
+
33
+ # Example
34
+ <invoke name="get_weather"><parameter name="city">Seoul</parameter></invoke>`;
35
+ }
36
+ export function anthropicXmlFormatToolCall(name, args) {
37
+ const parameters = Object.entries(args).map(([parameterName, value]) => `<parameter name="${encodeXmlAttribute(parameterName)}">${encodeXmlParameterText(serializeToolValue(value))}</parameter>`);
38
+ return [`<invoke name="${encodeXmlAttribute(name)}">`, ...parameters, "</invoke>"].join("\n");
39
+ }
40
+ export function anthropicXmlFormatToolResponse(toolName, _toolCallId, content) {
41
+ const textContent = content
42
+ .filter((entry) => entry.type === "text")
43
+ .map((entry) => entry.text)
44
+ .join("\n");
45
+ return [
46
+ "<function_results>",
47
+ "<result>",
48
+ `<tool_name>${encodeXmlText(toolName)}</tool_name>`,
49
+ `<stdout>${encodeXmlText(textContent)}</stdout>`,
50
+ "</result>",
51
+ "</function_results>",
52
+ ].join("\n");
53
+ }
54
+ //# sourceMappingURL=format.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.js","sourceRoot":"","sources":["../../../../src/tool-call-middleware/protocols/anthropic-xml/format.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAE9F,SAAS,kBAAkB,CAAC,KAAc;IACzC,IAAI,OAAO,KAAK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I,CAAC,IAAI,CAAC,CAAC;AAC/F,CAAC;AAED,MAAM,UAAU,8BAA8B,CAC7C,QAAgB,EAChB,WAAmB,EACnB,OAA4B;IAE5B,MAAM,WAAW,GAAG,OAAO;SACzB,MAAM,CAAC,CAAC,KAAK,EAAyD,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,MAAM,CAAC;SAC/F,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC;SAC1B,IAAI,CAAC,IAAI,CAAC,CAAC;IAEb,OAAO;QACN,oBAAoB;QACpB,UAAU;QACV,cAAc,aAAa,CAAC,QAAQ,CAAC,cAAc;QACnD,WAAW,aAAa,CAAC,WAAW,CAAC,WAAW;QAChD,WAAW;QACX,qBAAqB;KACrB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACd,CAAC","sourcesContent":["import type { Tool } from \"../../../types.ts\";\nimport type { ToolResultContent } from \"../../types.ts\";\nimport { encodeXmlAttribute, encodeXmlParameterText, encodeXmlText } from \"./xml-entities.ts\";\n\nfunction serializeToolValue(value: unknown): string {\n\tif (typeof value === \"object\" && value !== null) {\n\t\treturn JSON.stringify(value) ?? \"null\";\n\t}\n\n\treturn String(value);\n}\n\nfunction renderToolDefinitions(tools: Tool[]): string {\n\tconst json = 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 json.replace(/</g, \"\\\\u003c\").replace(/>/g, \"\\\\u003e\").replace(/&/g, \"\\\\u0026\");\n}\n\nexport function anthropicXmlFormatToolsSystemPrompt(tools: Tool[]): string {\n\tif (tools.length === 0) {\n\t\treturn \"\";\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 as JSON within <tools></tools> XML tags:\n<tools>${renderToolDefinitions(tools)}</tools>\n\n# Format\n\nFor each function call, emit exactly one bare <invoke> element with the tool name in its name attribute.\nPut each argument in one <parameter> element with its name in the name attribute.\nDo not wrap the invoke element in another XML element.\n\n# Example\n<invoke name=\"get_weather\"><parameter name=\"city\">Seoul</parameter></invoke>`;\n}\n\nexport function anthropicXmlFormatToolCall(name: string, args: Record<string, unknown>): string {\n\tconst parameters = Object.entries(args).map(\n\t\t([parameterName, value]) =>\n\t\t\t`<parameter name=\"${encodeXmlAttribute(parameterName)}\">${encodeXmlParameterText(serializeToolValue(value))}</parameter>`,\n\t);\n\n\treturn [`<invoke name=\"${encodeXmlAttribute(name)}\">`, ...parameters, \"</invoke>\"].join(\"\\n\");\n}\n\nexport function anthropicXmlFormatToolResponse(\n\ttoolName: string,\n\t_toolCallId: string,\n\tcontent: ToolResultContent[],\n): string {\n\tconst textContent = content\n\t\t.filter((entry): entry is Extract<ToolResultContent, { type: \"text\" }> => entry.type === \"text\")\n\t\t.map((entry) => entry.text)\n\t\t.join(\"\\n\");\n\n\treturn [\n\t\t\"<function_results>\",\n\t\t\"<result>\",\n\t\t`<tool_name>${encodeXmlText(toolName)}</tool_name>`,\n\t\t`<stdout>${encodeXmlText(textContent)}</stdout>`,\n\t\t\"</result>\",\n\t\t\"</function_results>\",\n\t].join(\"\\n\");\n}\n"]}
@@ -0,0 +1,4 @@
1
+ export { anthropicXmlFormatToolCall, anthropicXmlFormatToolResponse, anthropicXmlFormatToolsSystemPrompt, } from "./format.ts";
2
+ export { parseAnthropicXmlGeneratedText } from "./parse.ts";
3
+ export { createAnthropicXmlStreamParser } from "./stream.ts";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/tool-call-middleware/protocols/anthropic-xml/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,0BAA0B,EAC1B,8BAA8B,EAC9B,mCAAmC,GACnC,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,8BAA8B,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { anthropicXmlFormatToolCall, anthropicXmlFormatToolResponse, anthropicXmlFormatToolsSystemPrompt, } from "./format.js";
2
+ export { parseAnthropicXmlGeneratedText } from "./parse.js";
3
+ export { createAnthropicXmlStreamParser } from "./stream.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/tool-call-middleware/protocols/anthropic-xml/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,0BAA0B,EAC1B,8BAA8B,EAC9B,mCAAmC,GACnC,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,8BAA8B,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC","sourcesContent":["export {\n\tanthropicXmlFormatToolCall,\n\tanthropicXmlFormatToolResponse,\n\tanthropicXmlFormatToolsSystemPrompt,\n} from \"./format.ts\";\nexport { parseAnthropicXmlGeneratedText } from \"./parse.ts\";\nexport { createAnthropicXmlStreamParser } from \"./stream.ts\";\n"]}
@@ -0,0 +1,7 @@
1
+ import type { InvokeBlockMatch, InvokeOpenTagMatch } from "./invoke-tag-scanner.ts";
2
+ export type InvokeMatch = {
3
+ readonly openingTag: InvokeOpenTagMatch;
4
+ readonly block: InvokeBlockMatch | null;
5
+ };
6
+ export declare function findNextInvokeMatch(text: string, fromIndex: number, matchesToolName: (toolName: string) => boolean): InvokeMatch | null;
7
+ //# sourceMappingURL=invoke-match.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invoke-match.d.ts","sourceRoot":"","sources":["../../../../src/tool-call-middleware/protocols/anthropic-xml/invoke-match.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAGpF,MAAM,MAAM,WAAW,GAAG;IACzB,QAAQ,CAAC,UAAU,EAAE,kBAAkB,CAAC;IACxC,QAAQ,CAAC,KAAK,EAAE,gBAAgB,GAAG,IAAI,CAAC;CACxC,CAAC;AAEF,wBAAgB,mBAAmB,CAClC,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,GAC5C,WAAW,GAAG,IAAI,CAapB"}
@@ -0,0 +1,16 @@
1
+ import { findInvokeOpenTag, scanInvokeBlock } from "./invoke-tag-scanner.js";
2
+ export function findNextInvokeMatch(text, fromIndex, matchesToolName) {
3
+ let cursor = Math.max(0, fromIndex);
4
+ while (cursor < text.length) {
5
+ const openingTag = findInvokeOpenTag(text, cursor);
6
+ if (!openingTag) {
7
+ return null;
8
+ }
9
+ if (matchesToolName(openingTag.toolName)) {
10
+ return { openingTag, block: scanInvokeBlock(text, openingTag) };
11
+ }
12
+ cursor = openingTag.index + openingTag.length;
13
+ }
14
+ return null;
15
+ }
16
+ //# sourceMappingURL=invoke-match.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invoke-match.js","sourceRoot":"","sources":["../../../../src/tool-call-middleware/protocols/anthropic-xml/invoke-match.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAO7E,MAAM,UAAU,mBAAmB,CAClC,IAAY,EACZ,SAAiB,EACjB,eAA8C;IAE9C,IAAI,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;IACpC,OAAO,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAC7B,MAAM,UAAU,GAAG,iBAAiB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACnD,IAAI,CAAC,UAAU,EAAE,CAAC;YACjB,OAAO,IAAI,CAAC;QACb,CAAC;QACD,IAAI,eAAe,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC1C,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,eAAe,CAAC,IAAI,EAAE,UAAU,CAAC,EAAE,CAAC;QACjE,CAAC;QACD,MAAM,GAAG,UAAU,CAAC,KAAK,GAAG,UAAU,CAAC,MAAM,CAAC;IAC/C,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC","sourcesContent":["import type { InvokeBlockMatch, InvokeOpenTagMatch } from \"./invoke-tag-scanner.ts\";\nimport { findInvokeOpenTag, scanInvokeBlock } from \"./invoke-tag-scanner.ts\";\n\nexport type InvokeMatch = {\n\treadonly openingTag: InvokeOpenTagMatch;\n\treadonly block: InvokeBlockMatch | null;\n};\n\nexport function findNextInvokeMatch(\n\ttext: string,\n\tfromIndex: number,\n\tmatchesToolName: (toolName: string) => boolean,\n): InvokeMatch | null {\n\tlet cursor = Math.max(0, fromIndex);\n\twhile (cursor < text.length) {\n\t\tconst openingTag = findInvokeOpenTag(text, cursor);\n\t\tif (!openingTag) {\n\t\t\treturn null;\n\t\t}\n\t\tif (matchesToolName(openingTag.toolName)) {\n\t\t\treturn { openingTag, block: scanInvokeBlock(text, openingTag) };\n\t\t}\n\t\tcursor = openingTag.index + openingTag.length;\n\t}\n\treturn null;\n}\n"]}
@@ -0,0 +1,19 @@
1
+ export type InvokeOpenTagMatch = {
2
+ readonly index: number;
3
+ readonly length: number;
4
+ readonly toolName: string;
5
+ };
6
+ export type InvokeParameter = {
7
+ readonly name: string;
8
+ readonly rawValue: string;
9
+ };
10
+ export type InvokeBlockMatch = {
11
+ readonly contentEnd: number;
12
+ readonly end: number;
13
+ readonly parameters: InvokeParameter[] | null;
14
+ };
15
+ export declare function findInvokeOpenTag(text: string, fromIndex: number): InvokeOpenTagMatch | null;
16
+ export declare function findIncompleteInvokeOpenTag(text: string, fromIndex: number): InvokeOpenTagMatch | null;
17
+ export declare function scanInvokeBlock(text: string, openingTag: InvokeOpenTagMatch): InvokeBlockMatch | null;
18
+ export declare function getSafeInvokeTextLength(text: string): number;
19
+ //# sourceMappingURL=invoke-tag-scanner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invoke-tag-scanner.d.ts","sourceRoot":"","sources":["../../../../src/tool-call-middleware/protocols/anthropic-xml/invoke-tag-scanner.ts"],"names":[],"mappings":"AAyBA,MAAM,MAAM,kBAAkB,GAAG;IAChC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC9B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,UAAU,EAAE,eAAe,EAAE,GAAG,IAAI,CAAC;CAC9C,CAAC;AAwEF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,kBAAkB,GAAG,IAAI,CAS5F;AAED,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,kBAAkB,GAAG,IAAI,CA2BtG;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,kBAAkB,GAAG,gBAAgB,GAAG,IAAI,CA4DrG;AAqED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAO5D"}
@@ -0,0 +1,217 @@
1
+ import { decodeXmlEntities } from "./xml-entities.js";
2
+ const PROTOCOL_TAG_NAMES = ["invoke", "parameter", "function_calls"];
3
+ const INVOKE_OPEN_TAG_BODY = String.raw `<\s*invoke\b\s+name\s*=\s*(?:"([^"]+)"|'([^']+)')`;
4
+ const INVOKE_OPEN_TAG = new RegExp(`${INVOKE_OPEN_TAG_BODY}\\s*>`, "g");
5
+ const INVOKE_CLOSE_TAG = /<\s*\/\s*invoke\s*>/g;
6
+ const NESTED_INVOKE_OPEN_TAG = /<\s*invoke\b[^>]*>/g;
7
+ const PARAMETER_MARKUP = /<\s*\/?\s*parameter\b/g;
8
+ const PARAMETER_OPEN_TAG = /<\s*parameter\b\s+name\s*=\s*(?:"([^"]+)"|'([^']+)')\s*>/g;
9
+ const PARAMETER_CLOSE_TAG = /<\s*\/\s*parameter\s*>/g;
10
+ function findTag(pattern, text, fromIndex) {
11
+ pattern.lastIndex = Math.max(0, fromIndex);
12
+ const match = pattern.exec(text);
13
+ return match ? { index: match.index, length: match[0].length } : null;
14
+ }
15
+ function findParameterOpenTagAt(text, index) {
16
+ PARAMETER_OPEN_TAG.lastIndex = index;
17
+ const match = PARAMETER_OPEN_TAG.exec(text);
18
+ if (!match || match.index !== index) {
19
+ return null;
20
+ }
21
+ const name = match[1] ?? match[2];
22
+ return name ? { index, length: match[0].length, name: decodeXmlEntities(name) } : null;
23
+ }
24
+ function findParameterBoundary(text, fromIndex) {
25
+ let cursor = fromIndex;
26
+ let nestedInvokeDepth = 0;
27
+ while (cursor < text.length) {
28
+ const parameterClose = findTag(PARAMETER_CLOSE_TAG, text, cursor);
29
+ const invokeOpen = findTag(NESTED_INVOKE_OPEN_TAG, text, cursor);
30
+ const invokeClose = findTag(INVOKE_CLOSE_TAG, text, cursor);
31
+ const nextIndex = Math.min(parameterClose?.index ?? Number.POSITIVE_INFINITY, invokeOpen?.index ?? Number.POSITIVE_INFINITY, invokeClose?.index ?? Number.POSITIVE_INFINITY);
32
+ if (!Number.isFinite(nextIndex)) {
33
+ return null;
34
+ }
35
+ if (invokeOpen && invokeOpen.index === nextIndex) {
36
+ const nextParameterClose = findTag(PARAMETER_CLOSE_TAG, text, invokeOpen.index + invokeOpen.length);
37
+ const nestedParameterOpen = findTag(PARAMETER_OPEN_TAG, text, invokeOpen.index + invokeOpen.length);
38
+ const nestedInvokeClose = findTag(INVOKE_CLOSE_TAG, text, invokeOpen.index + invokeOpen.length);
39
+ if (nestedInvokeClose === null ||
40
+ ((nestedParameterOpen === null || nestedParameterOpen.index > nestedInvokeClose.index) &&
41
+ nextParameterClose !== null &&
42
+ nestedInvokeClose.index > nextParameterClose.index)) {
43
+ cursor = invokeOpen.index + invokeOpen.length;
44
+ continue;
45
+ }
46
+ nestedInvokeDepth += 1;
47
+ cursor = invokeOpen.index + invokeOpen.length;
48
+ continue;
49
+ }
50
+ if (invokeClose && invokeClose.index === nextIndex) {
51
+ if (nestedInvokeDepth === 0) {
52
+ return { kind: "invoke-close", match: invokeClose };
53
+ }
54
+ nestedInvokeDepth -= 1;
55
+ cursor = invokeClose.index + invokeClose.length;
56
+ continue;
57
+ }
58
+ if (parameterClose) {
59
+ if (nestedInvokeDepth === 0) {
60
+ return { kind: "parameter-close", match: parameterClose };
61
+ }
62
+ cursor = parameterClose.index + parameterClose.length;
63
+ }
64
+ }
65
+ return null;
66
+ }
67
+ export function findInvokeOpenTag(text, fromIndex) {
68
+ INVOKE_OPEN_TAG.lastIndex = Math.max(0, fromIndex);
69
+ const match = INVOKE_OPEN_TAG.exec(text);
70
+ if (!match || match.index === undefined) {
71
+ return null;
72
+ }
73
+ const toolName = match[1] ?? match[2];
74
+ return toolName ? { index: match.index, length: match[0].length, toolName: decodeXmlEntities(toolName) } : null;
75
+ }
76
+ export function findIncompleteInvokeOpenTag(text, fromIndex) {
77
+ const index = Math.max(0, fromIndex);
78
+ const candidate = text.slice(index);
79
+ const match = /^<\s*invoke\b\s+name\s*=\s*/.exec(candidate);
80
+ if (!match) {
81
+ return null;
82
+ }
83
+ const quoteIndex = match[0].length;
84
+ const quote = candidate[quoteIndex];
85
+ if (quote !== '"' && quote !== "'") {
86
+ return null;
87
+ }
88
+ const toolNameStart = quoteIndex + 1;
89
+ const closingQuoteIndex = candidate.indexOf(quote, toolNameStart);
90
+ if (closingQuoteIndex === -1) {
91
+ const toolName = decodeXmlEntities(candidate.slice(toolNameStart));
92
+ return toolName.length > 0 ? { index, length: candidate.length, toolName } : null;
93
+ }
94
+ const toolName = decodeXmlEntities(candidate.slice(toolNameStart, closingQuoteIndex));
95
+ if (toolName.length === 0 || candidate.slice(closingQuoteIndex + 1).trim().length > 0) {
96
+ return null;
97
+ }
98
+ return { index, length: candidate.length, toolName };
99
+ }
100
+ export function scanInvokeBlock(text, openingTag) {
101
+ const parameters = [];
102
+ let cursor = Math.max(0, openingTag.index + openingTag.length);
103
+ while (cursor <= text.length) {
104
+ const invokeClose = findTag(INVOKE_CLOSE_TAG, text, cursor);
105
+ if (!invokeClose) {
106
+ return null;
107
+ }
108
+ const parameterMarkup = findTag(PARAMETER_MARKUP, text, cursor);
109
+ const nestedInvokeOpen = findTag(NESTED_INVOKE_OPEN_TAG, text, cursor);
110
+ if (nestedInvokeOpen &&
111
+ nestedInvokeOpen.index < invokeClose.index &&
112
+ (!parameterMarkup || nestedInvokeOpen.index < parameterMarkup.index)) {
113
+ return null;
114
+ }
115
+ if (!parameterMarkup || invokeClose.index < parameterMarkup.index) {
116
+ return {
117
+ contentEnd: invokeClose.index,
118
+ end: invokeClose.index + invokeClose.length,
119
+ parameters,
120
+ };
121
+ }
122
+ const parameterOpen = findParameterOpenTagAt(text, parameterMarkup.index);
123
+ if (!parameterOpen) {
124
+ return {
125
+ contentEnd: invokeClose.index,
126
+ end: invokeClose.index + invokeClose.length,
127
+ parameters: null,
128
+ };
129
+ }
130
+ const valueStart = parameterOpen.index + parameterOpen.length;
131
+ const boundary = findParameterBoundary(text, valueStart);
132
+ if (!boundary) {
133
+ return null;
134
+ }
135
+ switch (boundary.kind) {
136
+ case "invoke-close":
137
+ return {
138
+ contentEnd: boundary.match.index,
139
+ end: boundary.match.index + boundary.match.length,
140
+ parameters: null,
141
+ };
142
+ case "parameter-close":
143
+ parameters.push({
144
+ name: parameterOpen.name,
145
+ rawValue: text.slice(valueStart, boundary.match.index),
146
+ });
147
+ cursor = boundary.match.index + boundary.match.length;
148
+ break;
149
+ }
150
+ }
151
+ return null;
152
+ }
153
+ function isAttributePrefix(remainder) {
154
+ const attributeMatch = /^(\s*)([A-Za-z]*)/.exec(remainder);
155
+ if (!attributeMatch) {
156
+ return false;
157
+ }
158
+ const attributeName = attributeMatch[2] ?? "";
159
+ const afterAttributeName = remainder.slice(attributeMatch[0].length);
160
+ if (attributeName.length < "name".length) {
161
+ return "name".startsWith(attributeName) && afterAttributeName.trim().length === 0;
162
+ }
163
+ if (attributeName !== "name") {
164
+ return false;
165
+ }
166
+ if (afterAttributeName.trim().length === 0) {
167
+ return true;
168
+ }
169
+ const equalsMatch = /^\s*=\s*(.*)$/.exec(afterAttributeName);
170
+ if (!equalsMatch) {
171
+ return false;
172
+ }
173
+ const valuePrefix = equalsMatch[1] ?? "";
174
+ if (valuePrefix.length === 0) {
175
+ return true;
176
+ }
177
+ const quote = valuePrefix[0];
178
+ if (quote !== '"' && quote !== "'") {
179
+ return false;
180
+ }
181
+ const closingQuoteIndex = valuePrefix.indexOf(quote, 1);
182
+ return closingQuoteIndex === -1 || valuePrefix.slice(closingQuoteIndex + 1).trim().length === 0;
183
+ }
184
+ function isPotentialProtocolStart(candidate) {
185
+ if (!candidate.startsWith("<")) {
186
+ return false;
187
+ }
188
+ const body = candidate.slice(1);
189
+ const leadingWhitespace = /^\s*/.exec(body)?.[0] ?? "";
190
+ const namePart = body.slice(leadingWhitespace.length);
191
+ if (namePart.length === 0) {
192
+ return true;
193
+ }
194
+ const tagName = PROTOCOL_TAG_NAMES.find((name) => name.startsWith(namePart) || namePart.startsWith(name));
195
+ if (!tagName) {
196
+ return false;
197
+ }
198
+ if (namePart.length < tagName.length) {
199
+ return true;
200
+ }
201
+ const remainder = namePart.slice(tagName.length);
202
+ if (remainder.includes(">")) {
203
+ return false;
204
+ }
205
+ if (tagName === "function_calls") {
206
+ return /^\s*$/.test(remainder);
207
+ }
208
+ return isAttributePrefix(remainder);
209
+ }
210
+ export function getSafeInvokeTextLength(text) {
211
+ const lastTagIndex = text.lastIndexOf("<");
212
+ if (lastTagIndex === -1) {
213
+ return text.length;
214
+ }
215
+ return isPotentialProtocolStart(text.slice(lastTagIndex)) ? lastTagIndex : text.length;
216
+ }
217
+ //# sourceMappingURL=invoke-tag-scanner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invoke-tag-scanner.js","sourceRoot":"","sources":["../../../../src/tool-call-middleware/protocols/anthropic-xml/invoke-tag-scanner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD,MAAM,kBAAkB,GAAG,CAAC,QAAQ,EAAE,WAAW,EAAE,gBAAgB,CAAU,CAAC;AAE9E,MAAM,oBAAoB,GAAG,MAAM,CAAC,GAAG,CAAA,mDAAmD,CAAC;AAC3F,MAAM,eAAe,GAAG,IAAI,MAAM,CAAC,GAAG,oBAAoB,OAAO,EAAE,GAAG,CAAC,CAAC;AACxE,MAAM,gBAAgB,GAAG,sBAAsB,CAAC;AAChD,MAAM,sBAAsB,GAAG,qBAAqB,CAAC;AACrD,MAAM,gBAAgB,GAAG,wBAAwB,CAAC;AAClD,MAAM,kBAAkB,GAAG,2DAA2D,CAAC;AACvF,MAAM,mBAAmB,GAAG,yBAAyB,CAAC;AAgCtD,SAAS,OAAO,CAAC,OAAe,EAAE,IAAY,EAAE,SAAiB;IAChE,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;IAC3C,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjC,OAAO,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AACvE,CAAC;AAED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KE_OPEN_TAG_BODY = String.raw`<\\s*invoke\\b\\s+name\\s*=\\s*(?:\"([^\"]+)\"|'([^']+)')`;\nconst INVOKE_OPEN_TAG = new RegExp(`${INVOKE_OPEN_TAG_BODY}\\\\s*>`, \"g\");\nconst INVOKE_CLOSE_TAG = /<\\s*\\/\\s*invoke\\s*>/g;\nconst NESTED_INVOKE_OPEN_TAG = /<\\s*invoke\\b[^>]*>/g;\nconst PARAMETER_MARKUP = /<\\s*\\/?\\s*parameter\\b/g;\nconst PARAMETER_OPEN_TAG = /<\\s*parameter\\b\\s+name\\s*=\\s*(?:\"([^\"]+)\"|'([^']+)')\\s*>/g;\nconst PARAMETER_CLOSE_TAG = /<\\s*\\/\\s*parameter\\s*>/g;\n\ntype TagMatch = {\n\treadonly index: number;\n\treadonly length: number;\n};\n\ntype ParameterOpenTagMatch = TagMatch & {\n\treadonly name: string;\n};\n\ntype ParameterBoundary =\n\t| { readonly kind: \"parameter-close\"; readonly match: TagMatch }\n\t| { readonly kind: \"invoke-close\"; readonly match: TagMatch };\n\nexport type InvokeOpenTagMatch = {\n\treadonly index: number;\n\treadonly length: number;\n\treadonly toolName: string;\n};\n\nexport type InvokeParameter = {\n\treadonly name: string;\n\treadonly rawValue: string;\n};\n\nexport type InvokeBlockMatch = {\n\treadonly contentEnd: number;\n\treadonly end: number;\n\treadonly parameters: InvokeParameter[] | null;\n};\n\nfunction findTag(pattern: RegExp, text: string, fromIndex: number): TagMatch | null {\n\tpattern.lastIndex = Math.max(0, fromIndex);\n\tconst match = pattern.exec(text);\n\treturn match ? { index: match.index, length: match[0].length } : null;\n}\n\nfunction findParameterOpenTagAt(text: string, index: number): ParameterOpenTagMatch | null {\n\tPARAMETER_OPEN_TAG.lastIndex = index;\n\tconst match = PARAMETER_OPEN_TAG.exec(text);\n\tif (!match || match.index !== index) {\n\t\treturn null;\n\t}\n\n\tconst name = match[1] ?? match[2];\n\treturn name ? { index, length: match[0].length, name: decodeXmlEntities(name) } : null;\n}\n\nfunction findParameterBoundary(text: string, fromIndex: number): ParameterBoundary | null {\n\tlet cursor = fromIndex;\n\tlet nestedInvokeDepth = 0;\n\n\twhile (cursor < text.length) {\n\t\tconst parameterClose = findTag(PARAMETER_CLOSE_TAG, text, cursor);\n\t\tconst invokeOpen = findTag(NESTED_INVOKE_OPEN_TAG, text, cursor);\n\t\tconst invokeClose = findTag(INVOKE_CLOSE_TAG, text, cursor);\n\t\tconst nextIndex = Math.min(\n\t\t\tparameterClose?.index ?? Number.POSITIVE_INFINITY,\n\t\t\tinvokeOpen?.index ?? Number.POSITIVE_INFINITY,\n\t\t\tinvokeClose?.index ?? Number.POSITIVE_INFINITY,\n\t\t);\n\n\t\tif (!Number.isFinite(nextIndex)) {\n\t\t\treturn null;\n\t\t}\n\t\tif (invokeOpen && invokeOpen.index === nextIndex) {\n\t\t\tconst nextParameterClose = findTag(PARAMETER_CLOSE_TAG, text, invokeOpen.index + invokeOpen.length);\n\t\t\tconst nestedParameterOpen = findTag(PARAMETER_OPEN_TAG, text, invokeOpen.index + invokeOpen.length);\n\t\t\tconst nestedInvokeClose = findTag(INVOKE_CLOSE_TAG, text, invokeOpen.index + invokeOpen.length);\n\t\t\tif (\n\t\t\t\tnestedInvokeClose === null ||\n\t\t\t\t((nestedParameterOpen === null || nestedParameterOpen.index > nestedInvokeClose.index) &&\n\t\t\t\t\tnextParameterClose !== null &&\n\t\t\t\t\tnestedInvokeClose.index > nextParameterClose.index)\n\t\t\t) {\n\t\t\t\tcursor = invokeOpen.index + invokeOpen.length;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tnestedInvokeDepth += 1;\n\t\t\tcursor = invokeOpen.index + invokeOpen.length;\n\t\t\tcontinue;\n\t\t}\n\t\tif (invokeClose && invokeClose.index === nextIndex) {\n\t\t\tif (nestedInvokeDepth === 0) {\n\t\t\t\treturn { kind: \"invoke-close\", match: invokeClose };\n\t\t\t}\n\t\t\tnestedInvokeDepth -= 1;\n\t\t\tcursor = invokeClose.index + invokeClose.length;\n\t\t\tcontinue;\n\t\t}\n\t\tif (parameterClose) {\n\t\t\tif (nestedInvokeDepth === 0) {\n\t\t\t\treturn { kind: \"parameter-close\", match: parameterClose };\n\t\t\t}\n\t\t\tcursor = parameterClose.index + parameterClose.length;\n\t\t}\n\t}\n\n\treturn null;\n}\n\nexport function findInvokeOpenTag(text: string, fromIndex: number): InvokeOpenTagMatch | null {\n\tINVOKE_OPEN_TAG.lastIndex = Math.max(0, fromIndex);\n\tconst match = INVOKE_OPEN_TAG.exec(text);\n\tif (!match || match.index === undefined) {\n\t\treturn null;\n\t}\n\n\tconst toolName = match[1] ?? match[2];\n\treturn toolName ? { index: match.index, length: match[0].length, toolName: decodeXmlEntities(toolName) } : null;\n}\n\nexport function findIncompleteInvokeOpenTag(text: string, fromIndex: number): InvokeOpenTagMatch | null {\n\tconst index = Math.max(0, fromIndex);\n\tconst candidate = text.slice(index);\n\tconst match = /^<\\s*invoke\\b\\s+name\\s*=\\s*/.exec(candidate);\n\tif (!match) {\n\t\treturn null;\n\t}\n\n\tconst quoteIndex = match[0].length;\n\tconst quote = candidate[quoteIndex];\n\tif (quote !== '\"' && quote !== \"'\") {\n\t\treturn null;\n\t}\n\n\tconst toolNameStart = quoteIndex + 1;\n\tconst closingQuoteIndex = candidate.indexOf(quote, toolNameStart);\n\tif (closingQuoteIndex === -1) {\n\t\tconst toolName = decodeXmlEntities(candidate.slice(toolNameStart));\n\t\treturn toolName.length > 0 ? { index, length: candidate.length, toolName } : null;\n\t}\n\n\tconst toolName = decodeXmlEntities(candidate.slice(toolNameStart, closingQuoteIndex));\n\tif (toolName.length === 0 || candidate.slice(closingQuoteIndex + 1).trim().length > 0) {\n\t\treturn null;\n\t}\n\n\treturn { index, length: candidate.length, toolName };\n}\n\nexport function scanInvokeBlock(text: string, openingTag: InvokeOpenTagMatch): InvokeBlockMatch | null {\n\tconst parameters: InvokeParameter[] = [];\n\tlet cursor = Math.max(0, openingTag.index + openingTag.length);\n\n\twhile (cursor <= text.length) {\n\t\tconst invokeClose = findTag(INVOKE_CLOSE_TAG, text, cursor);\n\t\tif (!invokeClose) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst parameterMarkup = findTag(PARAMETER_MARKUP, text, cursor);\n\t\tconst nestedInvokeOpen = findTag(NESTED_INVOKE_OPEN_TAG, text, cursor);\n\t\tif (\n\t\t\tnestedInvokeOpen &&\n\t\t\tnestedInvokeOpen.index < invokeClose.index &&\n\t\t\t(!parameterMarkup || nestedInvokeOpen.index < parameterMarkup.index)\n\t\t) {\n\t\t\treturn null;\n\t\t}\n\t\tif (!parameterMarkup || invokeClose.index < parameterMarkup.index) {\n\t\t\treturn {\n\t\t\t\tcontentEnd: invokeClose.index,\n\t\t\t\tend: invokeClose.index + invokeClose.length,\n\t\t\t\tparameters,\n\t\t\t};\n\t\t}\n\n\t\tconst parameterOpen = findParameterOpenTagAt(text, parameterMarkup.index);\n\t\tif (!parameterOpen) {\n\t\t\treturn {\n\t\t\t\tcontentEnd: invokeClose.index,\n\t\t\t\tend: invokeClose.index + invokeClose.length,\n\t\t\t\tparameters: null,\n\t\t\t};\n\t\t}\n\n\t\tconst valueStart = parameterOpen.index + parameterOpen.length;\n\t\tconst boundary = findParameterBoundary(text, valueStart);\n\t\tif (!boundary) {\n\t\t\treturn null;\n\t\t}\n\n\t\tswitch (boundary.kind) {\n\t\t\tcase \"invoke-close\":\n\t\t\t\treturn {\n\t\t\t\t\tcontentEnd: boundary.match.index,\n\t\t\t\t\tend: boundary.match.index + boundary.match.length,\n\t\t\t\t\tparameters: null,\n\t\t\t\t};\n\t\t\tcase \"parameter-close\":\n\t\t\t\tparameters.push({\n\t\t\t\t\tname: parameterOpen.name,\n\t\t\t\t\trawValue: text.slice(valueStart, boundary.match.index),\n\t\t\t\t});\n\t\t\t\tcursor = boundary.match.index + boundary.match.length;\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn null;\n}\n\nfunction isAttributePrefix(remainder: string): boolean {\n\tconst attributeMatch = /^(\\s*)([A-Za-z]*)/.exec(remainder);\n\tif (!attributeMatch) {\n\t\treturn false;\n\t}\n\n\tconst attributeName = attributeMatch[2] ?? \"\";\n\tconst afterAttributeName = remainder.slice(attributeMatch[0].length);\n\tif (attributeName.length < \"name\".length) {\n\t\treturn \"name\".startsWith(attributeName) && afterAttributeName.trim().length === 0;\n\t}\n\tif (attributeName !== \"name\") {\n\t\treturn false;\n\t}\n\tif (afterAttributeName.trim().length === 0) {\n\t\treturn true;\n\t}\n\n\tconst equalsMatch = /^\\s*=\\s*(.*)$/.exec(afterAttributeName);\n\tif (!equalsMatch) {\n\t\treturn false;\n\t}\n\n\tconst valuePrefix = equalsMatch[1] ?? \"\";\n\tif (valuePrefix.length === 0) {\n\t\treturn true;\n\t}\n\n\tconst quote = valuePrefix[0];\n\tif (quote !== '\"' && quote !== \"'\") {\n\t\treturn false;\n\t}\n\n\tconst closingQuoteIndex = valuePrefix.indexOf(quote, 1);\n\treturn closingQuoteIndex === -1 || valuePrefix.slice(closingQuoteIndex + 1).trim().length === 0;\n}\n\nfunction isPotentialProtocolStart(candidate: string): boolean {\n\tif (!candidate.startsWith(\"<\")) {\n\t\treturn false;\n\t}\n\n\tconst body = candidate.slice(1);\n\tconst leadingWhitespace = /^\\s*/.exec(body)?.[0] ?? \"\";\n\tconst namePart = body.slice(leadingWhitespace.length);\n\tif (namePart.length === 0) {\n\t\treturn true;\n\t}\n\n\tconst tagName = PROTOCOL_TAG_NAMES.find((name) => name.startsWith(namePart) || namePart.startsWith(name));\n\tif (!tagName) {\n\t\treturn false;\n\t}\n\tif (namePart.length < tagName.length) {\n\t\treturn true;\n\t}\n\n\tconst remainder = namePart.slice(tagName.length);\n\tif (remainder.includes(\">\")) {\n\t\treturn false;\n\t}\n\tif (tagName === \"function_calls\") {\n\t\treturn /^\\s*$/.test(remainder);\n\t}\n\treturn isAttributePrefix(remainder);\n}\n\nexport function getSafeInvokeTextLength(text: string): number {\n\tconst lastTagIndex = text.lastIndexOf(\"<\");\n\tif (lastTagIndex === -1) {\n\t\treturn text.length;\n\t}\n\n\treturn isPotentialProtocolStart(text.slice(lastTagIndex)) ? lastTagIndex : text.length;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { Tool } from "../../../types.ts";
2
+ import type { ParsedToolCall, ParserOptions } from "../../types.ts";
3
+ export declare function parseAnthropicXmlGeneratedText(text: string, tools: Tool[], options?: ParserOptions): ParsedToolCall[];
4
+ //# sourceMappingURL=parse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../../../src/tool-call-middleware/protocols/anthropic-xml/parse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAMpE,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,cAAc,EAAE,CAsDrH"}
@@ -0,0 +1,46 @@
1
+ import { coerceParameters } from "./coerce-parameters.js";
2
+ import { findNextInvokeMatch } from "./invoke-match.js";
3
+ import { findInvokeOpenTag, scanInvokeBlock } from "./invoke-tag-scanner.js";
4
+ import { createToolResolver } from "./tool-resolver.js";
5
+ export function parseAnthropicXmlGeneratedText(text, tools, options) {
6
+ if (text.length === 0 || tools.length === 0) {
7
+ return [];
8
+ }
9
+ const resolveTool = createToolResolver(tools);
10
+ const parsedToolCalls = [];
11
+ let cursor = 0;
12
+ while (cursor < text.length) {
13
+ const openingTag = findInvokeOpenTag(text, cursor);
14
+ if (!openingTag) {
15
+ break;
16
+ }
17
+ const tool = resolveTool(openingTag.toolName);
18
+ const block = scanInvokeBlock(text, openingTag);
19
+ if (!tool) {
20
+ const nextKnownInvoke = findNextInvokeMatch(text, openingTag.index + openingTag.length, (toolName) => resolveTool(toolName) !== undefined);
21
+ if (nextKnownInvoke &&
22
+ (block === null || (nextKnownInvoke.block !== null && nextKnownInvoke.block.end === block.end))) {
23
+ cursor = nextKnownInvoke.openingTag.index;
24
+ continue;
25
+ }
26
+ }
27
+ if (!block) {
28
+ break;
29
+ }
30
+ const originalCallText = text.slice(openingTag.index, block.end);
31
+ cursor = block.end;
32
+ if (!tool) {
33
+ continue;
34
+ }
35
+ const argumentsRecord = block.parameters ? coerceParameters(block.parameters, tool) : null;
36
+ if (!argumentsRecord) {
37
+ options?.onError?.("Could not process anthropic-xml tool call, keeping original text.", {
38
+ toolCall: originalCallText,
39
+ });
40
+ continue;
41
+ }
42
+ parsedToolCalls.push({ name: tool.name, arguments: argumentsRecord });
43
+ }
44
+ return parsedToolCalls;
45
+ }
46
+ //# sourceMappingURL=parse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.js","sourceRoot":"","sources":["../../../../src/tool-call-middleware/protocols/anthropic-xml/parse.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExD,MAAM,UAAU,8BAA8B,CAAC,IAAY,EAAE,KAAa,EAAE,OAAuB;IAClG,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC7C,OAAO,EAAE,CAAC;IACX,CAAC;IAED,MAAM,WAAW,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;IAC9C,MAAM,eAAe,GAAqB,EAAE,CAAC;IAC7C,IAAI,MAAM,GAAG,CAAC,CAAC;IAEf,OAAO,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAC7B,MAAM,UAAU,G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BAAgB;aAC1B,CAAC,CAAC;YACH,SAAS;QACV,CAAC;QAED,eAAe,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,eAAe,EAAE,CAAC,CAAC;IACvE,CAAC;IAED,OAAO,eAAe,CAAC;AACxB,CAAC","sourcesContent":["import type { Tool } from \"../../../types.ts\";\nimport type { ParsedToolCall, ParserOptions } from \"../../types.ts\";\nimport { coerceParameters } from \"./coerce-parameters.ts\";\nimport { findNextInvokeMatch } from \"./invoke-match.ts\";\nimport { findInvokeOpenTag, scanInvokeBlock } from \"./invoke-tag-scanner.ts\";\nimport { createToolResolver } from \"./tool-resolver.ts\";\n\nexport function parseAnthropicXmlGeneratedText(text: string, tools: Tool[], options?: ParserOptions): ParsedToolCall[] {\n\tif (text.length === 0 || tools.length === 0) {\n\t\treturn [];\n\t}\n\n\tconst resolveTool = createToolResolver(tools);\n\tconst parsedToolCalls: ParsedToolCall[] = [];\n\tlet cursor = 0;\n\n\twhile (cursor < text.length) {\n\t\tconst openingTag = findInvokeOpenTag(text, cursor);\n\t\tif (!openingTag) {\n\t\t\tbreak;\n\t\t}\n\n\t\tconst tool = resolveTool(openingTag.toolName);\n\t\tconst block = scanInvokeBlock(text, openingTag);\n\t\tif (!tool) {\n\t\t\tconst nextKnownInvoke = findNextInvokeMatch(\n\t\t\t\ttext,\n\t\t\t\topeningTag.index + openingTag.length,\n\t\t\t\t(toolName) => resolveTool(toolName) !== undefined,\n\t\t\t);\n\t\t\tif (\n\t\t\t\tnextKnownInvoke &&\n\t\t\t\t(block === null || (nextKnownInvoke.block !== null && nextKnownInvoke.block.end === block.end))\n\t\t\t) {\n\t\t\t\tcursor = nextKnownInvoke.openingTag.index;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\tif (!block) {\n\t\t\tbreak;\n\t\t}\n\n\t\tconst originalCallText = text.slice(openingTag.index, block.end);\n\t\tcursor = block.end;\n\n\t\tif (!tool) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst argumentsRecord = block.parameters ? coerceParameters(block.parameters, tool) : null;\n\t\tif (!argumentsRecord) {\n\t\t\toptions?.onError?.(\"Could not process anthropic-xml tool call, keeping original text.\", {\n\t\t\t\ttoolCall: originalCallText,\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\n\t\tparsedToolCalls.push({ name: tool.name, arguments: argumentsRecord });\n\t}\n\n\treturn parsedToolCalls;\n}\n"]}
@@ -0,0 +1,13 @@
1
+ /** Incomplete protocol fragments are rejected before retained input can exceed this many UTF-16 code units. */
2
+ export declare const ANTHROPIC_XML_MAX_RETAINED_FRAGMENT_LENGTH: number;
3
+ export type StreamBoundaryMatcher = {
4
+ feed(text: string): boolean;
5
+ };
6
+ export type PendingFragment = {
7
+ readonly kind: "invoke" | "function-calls" | "open-tag";
8
+ readonly matcher: StreamBoundaryMatcher;
9
+ };
10
+ export declare function createClosingTagMatcher(tagName: "invoke" | "function_calls"): StreamBoundaryMatcher;
11
+ export declare function createTagEndMatcher(): StreamBoundaryMatcher;
12
+ export declare function createPendingFragment(kind: PendingFragment["kind"], text: string): PendingFragment;
13
+ //# sourceMappingURL=stream-boundary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream-boundary.d.ts","sourceRoot":"","sources":["../../../../src/tool-call-middleware/protocols/anthropic-xml/stream-boundary.ts"],"names":[],"mappings":"AAMA,+GAA+G;AAC/G,eAAO,MAAM,0CAA0C,QAAY,CAAC;AAEpE,MAAM,MAAM,qBAAqB,GAAG;IACnC,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC7B,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,gBAAgB,GAAG,UAAU,CAAC;IACxD,QAAQ,CAAC,OAAO,EAAE,qBAAqB,CAAC;CACxC,CAAC;AAsEF,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,QAAQ,GAAG,gBAAgB,GAAG,qBAAqB,CA0DnG;AAED,wBAAgB,mBAAmB,IAAI,qBAAqB,CAM3D;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,eAAe,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,eAAe,CASlG"}
@@ -0,0 +1,144 @@
1
+ const WHITESPACE = /\s/;
2
+ const INVOKE_OPEN_TAG = /^<\s*invoke\b[^>]*>$/;
3
+ const INVOKE_CLOSE_TAG = /^<\s*\/\s*invoke\s*>$/;
4
+ const PARAMETER_OPEN_TAG = /^<\s*parameter\b[^>]*>$/;
5
+ const PARAMETER_CLOSE_TAG = /^<\s*\/\s*parameter\s*>$/;
6
+ /** Incomplete protocol fragments are rejected before retained input can exceed this many UTF-16 code units. */
7
+ export const ANTHROPIC_XML_MAX_RETAINED_FRAGMENT_LENGTH = 64 * 1024;
8
+ function isWhitespace(character) {
9
+ return WHITESPACE.test(character);
10
+ }
11
+ function createInvokeBoundaryMatcher() {
12
+ let invokeDepth = 0;
13
+ const parameterInvokeDepths = [];
14
+ let tagCharacters = null;
15
+ return {
16
+ feed(text) {
17
+ for (const character of text) {
18
+ if (tagCharacters === null) {
19
+ if (character === "<") {
20
+ tagCharacters = [character];
21
+ }
22
+ continue;
23
+ }
24
+ if (character === "<") {
25
+ tagCharacters = [character];
26
+ continue;
27
+ }
28
+ tagCharacters.push(character);
29
+ if (character !== ">") {
30
+ continue;
31
+ }
32
+ const tag = tagCharacters.join("");
33
+ tagCharacters = null;
34
+ if (INVOKE_OPEN_TAG.test(tag)) {
35
+ invokeDepth += 1;
36
+ continue;
37
+ }
38
+ if (PARAMETER_OPEN_TAG.test(tag)) {
39
+ parameterInvokeDepths.push(invokeDepth);
40
+ continue;
41
+ }
42
+ if (PARAMETER_CLOSE_TAG.test(tag)) {
43
+ const parameterInvokeDepth = parameterInvokeDepths.pop();
44
+ if (parameterInvokeDepth !== undefined && invokeDepth > parameterInvokeDepth) {
45
+ invokeDepth = parameterInvokeDepth;
46
+ }
47
+ continue;
48
+ }
49
+ if (!INVOKE_CLOSE_TAG.test(tag) || invokeDepth === 0) {
50
+ continue;
51
+ }
52
+ invokeDepth -= 1;
53
+ while (parameterInvokeDepths.length > 0) {
54
+ const parameterInvokeDepth = parameterInvokeDepths[parameterInvokeDepths.length - 1];
55
+ if (parameterInvokeDepth === undefined || parameterInvokeDepth <= invokeDepth) {
56
+ break;
57
+ }
58
+ parameterInvokeDepths.pop();
59
+ }
60
+ if (invokeDepth === 0) {
61
+ return true;
62
+ }
63
+ }
64
+ return false;
65
+ },
66
+ };
67
+ }
68
+ export function createClosingTagMatcher(tagName) {
69
+ let state = "seek";
70
+ let nameIndex = 0;
71
+ function restart(character) {
72
+ state = character === "<" ? "after-open" : "seek";
73
+ nameIndex = 0;
74
+ }
75
+ return {
76
+ feed(text) {
77
+ let matched = false;
78
+ for (const character of text) {
79
+ switch (state) {
80
+ case "seek":
81
+ if (character === "<") {
82
+ state = "after-open";
83
+ }
84
+ break;
85
+ case "after-open":
86
+ if (character === "/") {
87
+ state = "after-slash";
88
+ }
89
+ else if (!isWhitespace(character)) {
90
+ restart(character);
91
+ }
92
+ break;
93
+ case "after-slash":
94
+ if (character === tagName[0]) {
95
+ nameIndex = 1;
96
+ state = "name";
97
+ }
98
+ else if (!isWhitespace(character)) {
99
+ restart(character);
100
+ }
101
+ break;
102
+ case "name":
103
+ if (character !== tagName[nameIndex]) {
104
+ restart(character);
105
+ break;
106
+ }
107
+ nameIndex += 1;
108
+ if (nameIndex === tagName.length) {
109
+ state = "after-name";
110
+ }
111
+ break;
112
+ case "after-name":
113
+ if (character === ">") {
114
+ matched = true;
115
+ state = "seek";
116
+ nameIndex = 0;
117
+ }
118
+ else if (!isWhitespace(character)) {
119
+ restart(character);
120
+ }
121
+ break;
122
+ }
123
+ }
124
+ return matched;
125
+ },
126
+ };
127
+ }
128
+ export function createTagEndMatcher() {
129
+ return {
130
+ feed(text) {
131
+ return text.includes(">");
132
+ },
133
+ };
134
+ }
135
+ export function createPendingFragment(kind, text) {
136
+ const matcher = kind === "invoke"
137
+ ? createInvokeBoundaryMatcher()
138
+ : kind === "function-calls"
139
+ ? createClosingTagMatcher("function_calls")
140
+ : createTagEndMatcher();
141
+ matcher.feed(text);
142
+ return { kind, matcher };
143
+ }
144
+ //# sourceMappingURL=stream-boundary.js.map