@nyte-ai/ai 0.0.0-stage → 0.0.19

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 (314) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +170 -2
  3. package/THIRD-PARTY-NOTICES.md +866 -0
  4. package/dist/chunks/account-limits-cache-031vfpt3.js +37 -0
  5. package/dist/chunks/account-limits-cache-09vs98g6.js +41 -0
  6. package/dist/chunks/account-limits-cache-0af5gqeg.js +15 -0
  7. package/dist/chunks/account-limits-cache-0yd6bde8.js +103 -0
  8. package/dist/chunks/account-limits-cache-1jv43fhh.js +22 -0
  9. package/dist/chunks/account-limits-cache-3ykqmnj5.js +88 -0
  10. package/dist/chunks/account-limits-cache-4b8ckwqw.js +293 -0
  11. package/dist/chunks/account-limits-cache-4fn5w63p.js +295 -0
  12. package/dist/chunks/account-limits-cache-4hptgd2h.js +49 -0
  13. package/dist/chunks/account-limits-cache-53e64mhx.js +417 -0
  14. package/dist/chunks/account-limits-cache-5jdhn0e1.js +562 -0
  15. package/dist/chunks/account-limits-cache-5rx2pfm5.js +8 -0
  16. package/dist/chunks/account-limits-cache-5ygxyyss.js +19 -0
  17. package/dist/chunks/account-limits-cache-6250ykn6.js +21 -0
  18. package/dist/chunks/account-limits-cache-6x05n06z.js +49 -0
  19. package/dist/chunks/account-limits-cache-736tdyme.js +6 -0
  20. package/dist/chunks/account-limits-cache-75smws02.js +213 -0
  21. package/dist/chunks/account-limits-cache-7z9s8j16.js +139 -0
  22. package/dist/chunks/account-limits-cache-8137j3zp.js +37 -0
  23. package/dist/chunks/account-limits-cache-8qzk56vj.js +160 -0
  24. package/dist/chunks/account-limits-cache-8s8bz4dr.js +36 -0
  25. package/dist/chunks/account-limits-cache-8vzx8k6r.js +166 -0
  26. package/dist/chunks/account-limits-cache-8wfqg73s.js +135 -0
  27. package/dist/chunks/account-limits-cache-90c9c2eb.js +50 -0
  28. package/dist/chunks/account-limits-cache-9wqk28n5.js +25 -0
  29. package/dist/chunks/account-limits-cache-a1jyaq00.js +56 -0
  30. package/dist/chunks/account-limits-cache-a558rjbg.js +138 -0
  31. package/dist/chunks/account-limits-cache-a55e14fr.js +70 -0
  32. package/dist/chunks/account-limits-cache-a6cgeagz.js +77 -0
  33. package/dist/chunks/account-limits-cache-ag5b8dja.js +38 -0
  34. package/dist/chunks/account-limits-cache-b0x2sfya.js +45 -0
  35. package/dist/chunks/account-limits-cache-b23sbrke.js +26 -0
  36. package/dist/chunks/account-limits-cache-b4edaybk.js +8 -0
  37. package/dist/chunks/account-limits-cache-bsknrh6t.js +74 -0
  38. package/dist/chunks/account-limits-cache-csbxvam7.js +12 -0
  39. package/dist/chunks/account-limits-cache-cw7q7vfy.js +293 -0
  40. package/dist/chunks/account-limits-cache-d1ypzqzp.js +27 -0
  41. package/dist/chunks/account-limits-cache-d2a51dka.js +17 -0
  42. package/dist/chunks/account-limits-cache-dejeygdt.js +114 -0
  43. package/dist/chunks/account-limits-cache-eejm0vth.js +11 -0
  44. package/dist/chunks/account-limits-cache-ehy0ze2b.js +33 -0
  45. package/dist/chunks/account-limits-cache-emg5b4hj.js +53 -0
  46. package/dist/chunks/account-limits-cache-eqwweapz.js +6 -0
  47. package/dist/chunks/account-limits-cache-eyx1jcxc.js +8 -0
  48. package/dist/chunks/account-limits-cache-f9z00x8c.js +36 -0
  49. package/dist/chunks/account-limits-cache-fbkaq46e.js +113 -0
  50. package/dist/chunks/account-limits-cache-fdwad56n.js +399 -0
  51. package/dist/chunks/account-limits-cache-fht68jp2.js +22 -0
  52. package/dist/chunks/account-limits-cache-fp03ztsw.js +17 -0
  53. package/dist/chunks/account-limits-cache-fsktnetm.js +69 -0
  54. package/dist/chunks/account-limits-cache-fvadc36m.js +110 -0
  55. package/dist/chunks/account-limits-cache-gknnm1kv.js +13 -0
  56. package/dist/chunks/account-limits-cache-gqsrbky9.js +40 -0
  57. package/dist/chunks/account-limits-cache-gr671dr2.js +0 -0
  58. package/dist/chunks/account-limits-cache-gs8a3fhw.js +32 -0
  59. package/dist/chunks/account-limits-cache-gsa5tzck.js +37 -0
  60. package/dist/chunks/account-limits-cache-h92bzz1j.js +235 -0
  61. package/dist/chunks/account-limits-cache-hemxtapd.js +142 -0
  62. package/dist/chunks/account-limits-cache-hj1h48sc.js +92 -0
  63. package/dist/chunks/account-limits-cache-hj3ek3ty.js +128 -0
  64. package/dist/chunks/account-limits-cache-hwehc67r.js +509 -0
  65. package/dist/chunks/account-limits-cache-hyzn1jmk.js +46 -0
  66. package/dist/chunks/account-limits-cache-j2bt392s.js +63 -0
  67. package/dist/chunks/account-limits-cache-k0pkzhbx.js +74 -0
  68. package/dist/chunks/account-limits-cache-kjx405q0.js +277 -0
  69. package/dist/chunks/account-limits-cache-ks1sjym9.js +37 -0
  70. package/dist/chunks/account-limits-cache-me1x57bs.js +89 -0
  71. package/dist/chunks/account-limits-cache-n3yk6g5c.js +314 -0
  72. package/dist/chunks/account-limits-cache-nbhht7xz.js +72 -0
  73. package/dist/chunks/account-limits-cache-nbkyhs6v.js +42 -0
  74. package/dist/chunks/account-limits-cache-nn9jebsj.js +26 -0
  75. package/dist/chunks/account-limits-cache-nxkprk3g.js +13 -0
  76. package/dist/chunks/account-limits-cache-nyy770yd.js +38 -0
  77. package/dist/chunks/account-limits-cache-pfa86y8e.js +45 -0
  78. package/dist/chunks/account-limits-cache-pfr14mcn.js +59 -0
  79. package/dist/chunks/account-limits-cache-q1ebtvet.js +8 -0
  80. package/dist/chunks/account-limits-cache-q63mc41j.js +51 -0
  81. package/dist/chunks/account-limits-cache-re8hpzwn.js +104 -0
  82. package/dist/chunks/account-limits-cache-rz8p1g5y.js +9 -0
  83. package/dist/chunks/account-limits-cache-skbfmzqe.js +7 -0
  84. package/dist/chunks/account-limits-cache-tc38g0ca.js +20 -0
  85. package/dist/chunks/account-limits-cache-v4n30az2.js +24 -0
  86. package/dist/chunks/account-limits-cache-vwgfz727.js +281 -0
  87. package/dist/chunks/account-limits-cache-wtg64ez7.js +69 -0
  88. package/dist/chunks/account-limits-cache-x9fvb3s5.js +8 -0
  89. package/dist/chunks/account-limits-cache-xds88kxd.js +209 -0
  90. package/dist/chunks/account-limits-cache-xz65wyd1.js +428 -0
  91. package/dist/chunks/account-limits-cache-ydq8p8qp.js +39 -0
  92. package/dist/chunks/account-limits-cache-ykbqsvv6.js +134 -0
  93. package/dist/chunks/account-limits-cache-yzyp0c2h.js +251 -0
  94. package/dist/chunks/account-limits-cache-za42x8a3.js +25 -0
  95. package/dist/chunks/account-limits-cache-zcbkmrvy.js +79 -0
  96. package/dist/chunks/account-limits-cache-zgzptd0z.js +62 -0
  97. package/dist/chunks/account-limits-cache-zn01kscn.js +252 -0
  98. package/dist/chunks/account-limits-cache-zpjmeyt0.js +113 -0
  99. package/dist/chunks/account-limits-cache-zqdb4yh4.js +8 -0
  100. package/dist/src/account-limits-cache.d.ts +16 -0
  101. package/dist/src/account-limits-cache.js +7 -0
  102. package/dist/src/api/anthropic-client.d.ts +25 -0
  103. package/dist/src/api/anthropic-client.js +30 -0
  104. package/dist/src/api/anthropic-convert.d.ts +17 -0
  105. package/dist/src/api/anthropic-convert.js +14 -0
  106. package/dist/src/api/anthropic-events.d.ts +101 -0
  107. package/dist/src/api/anthropic-events.js +11 -0
  108. package/dist/src/api/anthropic-messages.d.ts +88 -0
  109. package/dist/src/api/anthropic-messages.js +578 -0
  110. package/dist/src/api/anthropic-messages.lazy.d.ts +2 -0
  111. package/dist/src/api/anthropic-messages.lazy.js +11 -0
  112. package/dist/src/api/assistant-stream.d.ts +23 -0
  113. package/dist/src/api/assistant-stream.js +15 -0
  114. package/dist/src/api/claude-code.d.ts +12 -0
  115. package/dist/src/api/claude-code.js +12 -0
  116. package/dist/src/api/cloudflare.d.ts +8 -0
  117. package/dist/src/api/cloudflare.js +11 -0
  118. package/dist/src/api/constrained-sampling.d.ts +24 -0
  119. package/dist/src/api/constrained-sampling.js +16 -0
  120. package/dist/src/api/deferred.d.ts +7 -0
  121. package/dist/src/api/deferred.js +10 -0
  122. package/dist/src/api/github-copilot-headers.d.ts +15 -0
  123. package/dist/src/api/github-copilot-headers.js +12 -0
  124. package/dist/src/api/google-generative-ai.d.ts +22 -0
  125. package/dist/src/api/google-generative-ai.js +583 -0
  126. package/dist/src/api/google-generative-ai.lazy.d.ts +2 -0
  127. package/dist/src/api/google-generative-ai.lazy.js +11 -0
  128. package/dist/src/api/lazy.d.ts +18 -0
  129. package/dist/src/api/lazy.js +12 -0
  130. package/dist/src/api/openai-codex-compact.d.ts +14 -0
  131. package/dist/src/api/openai-codex-compact.js +389 -0
  132. package/dist/src/api/openai-codex-compaction-error.d.ts +7 -0
  133. package/dist/src/api/openai-codex-compaction-error.js +6 -0
  134. package/dist/src/api/openai-codex-protocol.d.ts +125 -0
  135. package/dist/src/api/openai-codex-protocol.js +48 -0
  136. package/dist/src/api/openai-codex-responses.d.ts +4 -0
  137. package/dist/src/api/openai-codex-responses.js +175 -0
  138. package/dist/src/api/openai-codex-responses.lazy.d.ts +2 -0
  139. package/dist/src/api/openai-codex-responses.lazy.js +11 -0
  140. package/dist/src/api/openai-codex-websocket.d.ts +13 -0
  141. package/dist/src/api/openai-codex-websocket.js +37 -0
  142. package/dist/src/api/openai-codex-wire.d.ts +44 -0
  143. package/dist/src/api/openai-codex-wire.js +34 -0
  144. package/dist/src/api/openai-compact.d.ts +9 -0
  145. package/dist/src/api/openai-compact.js +12 -0
  146. package/dist/src/api/openai-completions-convert.d.ts +58 -0
  147. package/dist/src/api/openai-completions-convert.js +21 -0
  148. package/dist/src/api/openai-completions-params.d.ts +29 -0
  149. package/dist/src/api/openai-completions-params.js +20 -0
  150. package/dist/src/api/openai-completions-reasoning.d.ts +54 -0
  151. package/dist/src/api/openai-completions-reasoning.js +22 -0
  152. package/dist/src/api/openai-completions.d.ts +22 -0
  153. package/dist/src/api/openai-completions.js +484 -0
  154. package/dist/src/api/openai-completions.lazy.d.ts +5 -0
  155. package/dist/src/api/openai-completions.lazy.js +11 -0
  156. package/dist/src/api/openai-prompt-cache.d.ts +1 -0
  157. package/dist/src/api/openai-prompt-cache.js +6 -0
  158. package/dist/src/api/openai-responses-convert.d.ts +58 -0
  159. package/dist/src/api/openai-responses-convert.js +16 -0
  160. package/dist/src/api/openai-responses-events.d.ts +379 -0
  161. package/dist/src/api/openai-responses-events.js +12 -0
  162. package/dist/src/api/openai-responses-stream.d.ts +36 -0
  163. package/dist/src/api/openai-responses-stream.js +25 -0
  164. package/dist/src/api/openai-responses.d.ts +18 -0
  165. package/dist/src/api/openai-responses.js +276 -0
  166. package/dist/src/api/openai-responses.lazy.d.ts +2 -0
  167. package/dist/src/api/openai-responses.lazy.js +11 -0
  168. package/dist/src/api/simple-options.d.ts +17 -0
  169. package/dist/src/api/simple-options.js +18 -0
  170. package/dist/src/api/token-count.d.ts +5 -0
  171. package/dist/src/api/token-count.js +8 -0
  172. package/dist/src/api/transform-messages.d.ts +9 -0
  173. package/dist/src/api/transform-messages.js +6 -0
  174. package/dist/src/api-options.d.ts +27 -0
  175. package/dist/src/api-options.js +0 -0
  176. package/dist/src/auth/context.d.ts +11 -0
  177. package/dist/src/auth/context.js +6 -0
  178. package/dist/src/auth/credential-store.d.ts +17 -0
  179. package/dist/src/auth/credential-store.js +7 -0
  180. package/dist/src/auth/helpers.d.ts +24 -0
  181. package/dist/src/auth/helpers.js +8 -0
  182. package/dist/src/auth/oauth/anthropic.d.ts +7 -0
  183. package/dist/src/auth/oauth/anthropic.js +12 -0
  184. package/dist/src/auth/oauth/authorization-input.d.ts +14 -0
  185. package/dist/src/auth/oauth/authorization-input.js +6 -0
  186. package/dist/src/auth/oauth/device-code.d.ts +29 -0
  187. package/dist/src/auth/oauth/device-code.js +9 -0
  188. package/dist/src/auth/oauth/github-copilot.d.ts +23 -0
  189. package/dist/src/auth/oauth/github-copilot.js +12 -0
  190. package/dist/src/auth/oauth/load.d.ts +14 -0
  191. package/dist/src/auth/oauth/load.js +10 -0
  192. package/dist/src/auth/oauth/oauth-page.d.ts +13 -0
  193. package/dist/src/auth/oauth/oauth-page.js +8 -0
  194. package/dist/src/auth/oauth/openai-codex.d.ts +10 -0
  195. package/dist/src/auth/oauth/openai-codex.js +18 -0
  196. package/dist/src/auth/oauth/pkce.d.ts +12 -0
  197. package/dist/src/auth/oauth/pkce.js +6 -0
  198. package/dist/src/auth/resolve.d.ts +38 -0
  199. package/dist/src/auth/resolve.js +12 -0
  200. package/dist/src/auth/store.d.ts +29 -0
  201. package/dist/src/auth/store.js +10 -0
  202. package/dist/src/auth/types.d.ts +291 -0
  203. package/dist/src/auth/types.js +8 -0
  204. package/dist/src/auth/verify.d.ts +13 -0
  205. package/dist/src/auth/verify.js +7 -0
  206. package/dist/src/bun-oauth.d.ts +2 -0
  207. package/dist/src/bun-oauth.js +25 -0
  208. package/dist/src/env-api-keys.d.ts +32 -0
  209. package/dist/src/env-api-keys.js +27 -0
  210. package/dist/src/file-models-store.d.ts +18 -0
  211. package/dist/src/file-models-store.js +9 -0
  212. package/dist/src/index.d.ts +62 -0
  213. package/dist/src/index.js +372 -0
  214. package/dist/src/model-capabilities.d.ts +21 -0
  215. package/dist/src/model-capabilities.js +14 -0
  216. package/dist/src/model-pricing.d.ts +6 -0
  217. package/dist/src/model-pricing.js +10 -0
  218. package/dist/src/model-variants.d.ts +21 -0
  219. package/dist/src/model-variants.js +19 -0
  220. package/dist/src/models-refresh.d.ts +27 -0
  221. package/dist/src/models-refresh.js +9 -0
  222. package/dist/src/models-store.d.ts +31 -0
  223. package/dist/src/models-store.js +6 -0
  224. package/dist/src/models-types.d.ts +206 -0
  225. package/dist/src/models-types.js +0 -0
  226. package/dist/src/models.d.ts +7 -0
  227. package/dist/src/models.js +44 -0
  228. package/dist/src/prompt-cache.d.ts +5 -0
  229. package/dist/src/prompt-cache.js +9 -0
  230. package/dist/src/provider.d.ts +23 -0
  231. package/dist/src/provider.js +14 -0
  232. package/dist/src/providers/account-limits.d.ts +13 -0
  233. package/dist/src/providers/account-limits.js +8 -0
  234. package/dist/src/providers/anthropic-limits.d.ts +9 -0
  235. package/dist/src/providers/anthropic-limits.js +10 -0
  236. package/dist/src/providers/anthropic.d.ts +2 -0
  237. package/dist/src/providers/anthropic.js +25 -0
  238. package/dist/src/providers/github-copilot-catalog.d.ts +5 -0
  239. package/dist/src/providers/github-copilot-catalog.js +7 -0
  240. package/dist/src/providers/github-copilot.d.ts +2 -0
  241. package/dist/src/providers/github-copilot.js +23 -0
  242. package/dist/src/providers/nyte-catalog.d.ts +15 -0
  243. package/dist/src/providers/nyte-catalog.js +63 -0
  244. package/dist/src/providers/openai-codex-limits.d.ts +8 -0
  245. package/dist/src/providers/openai-codex-limits.js +14 -0
  246. package/dist/src/providers/openai-codex.d.ts +2 -0
  247. package/dist/src/providers/openai-codex.js +23 -0
  248. package/dist/src/providers/openai.d.ts +2 -0
  249. package/dist/src/providers/openai.js +19 -0
  250. package/dist/src/providers/opencode-go.d.ts +5 -0
  251. package/dist/src/providers/opencode-go.js +22 -0
  252. package/dist/src/providers/opencode-headers.d.ts +5 -0
  253. package/dist/src/providers/opencode-headers.js +6 -0
  254. package/dist/src/providers/opencode.d.ts +14 -0
  255. package/dist/src/providers/opencode.js +23 -0
  256. package/dist/src/providers/openrouter.d.ts +2 -0
  257. package/dist/src/providers/openrouter.js +19 -0
  258. package/dist/src/providers/vercel-ai-gateway.d.ts +3 -0
  259. package/dist/src/providers/vercel-ai-gateway.js +19 -0
  260. package/dist/src/session-resources.d.ts +9 -0
  261. package/dist/src/session-resources.js +10 -0
  262. package/dist/src/types.d.ts +210 -0
  263. package/dist/src/types.js +1 -0
  264. package/dist/src/utils/abort.d.ts +12 -0
  265. package/dist/src/utils/abort.js +10 -0
  266. package/dist/src/utils/deferred-tools.d.ts +11 -0
  267. package/dist/src/utils/deferred-tools.js +6 -0
  268. package/dist/src/utils/diagnostics.d.ts +11 -0
  269. package/dist/src/utils/diagnostics.js +12 -0
  270. package/dist/src/utils/error-body.d.ts +26 -0
  271. package/dist/src/utils/error-body.js +10 -0
  272. package/dist/src/utils/estimate.d.ts +20 -0
  273. package/dist/src/utils/estimate.js +14 -0
  274. package/dist/src/utils/event-stream.d.ts +22 -0
  275. package/dist/src/utils/event-stream.js +11 -0
  276. package/dist/src/utils/failure.d.ts +49 -0
  277. package/dist/src/utils/failure.js +10 -0
  278. package/dist/src/utils/fifo-queue.d.ts +11 -0
  279. package/dist/src/utils/fifo-queue.js +6 -0
  280. package/dist/src/utils/hash.d.ts +5 -0
  281. package/dist/src/utils/hash.js +6 -0
  282. package/dist/src/utils/headers.d.ts +12 -0
  283. package/dist/src/utils/headers.js +14 -0
  284. package/dist/src/utils/json-parse.d.ts +33 -0
  285. package/dist/src/utils/json-parse.js +12 -0
  286. package/dist/src/utils/node-http-proxy.d.ts +6 -0
  287. package/dist/src/utils/node-http-proxy.js +9 -0
  288. package/dist/src/utils/nyte-home.d.ts +2 -0
  289. package/dist/src/utils/nyte-home.js +6 -0
  290. package/dist/src/utils/nyte-user-agent.d.ts +1 -0
  291. package/dist/src/utils/nyte-user-agent.js +6 -0
  292. package/dist/src/utils/overflow.d.ts +18 -0
  293. package/dist/src/utils/overflow.js +9 -0
  294. package/dist/src/utils/provider-env.d.ts +9 -0
  295. package/dist/src/utils/provider-env.js +6 -0
  296. package/dist/src/utils/provider-retry.d.ts +22 -0
  297. package/dist/src/utils/provider-retry.js +9 -0
  298. package/dist/src/utils/retry.d.ts +66 -0
  299. package/dist/src/utils/retry.js +18 -0
  300. package/dist/src/utils/sanitize-unicode.d.ts +24 -0
  301. package/dist/src/utils/sanitize-unicode.js +6 -0
  302. package/dist/src/utils/sse.d.ts +21 -0
  303. package/dist/src/utils/sse.js +6 -0
  304. package/dist/src/utils/text.d.ts +5 -0
  305. package/dist/src/utils/text.js +10 -0
  306. package/dist/src/utils/transcript.d.ts +5 -0
  307. package/dist/src/utils/transcript.js +36 -0
  308. package/dist/src/utils/typebox-helpers.d.ts +19 -0
  309. package/dist/src/utils/typebox-helpers.js +6 -0
  310. package/dist/src/utils/uuid.d.ts +2 -0
  311. package/dist/src/utils/uuid.js +6 -0
  312. package/dist/src/utils/validation.d.ts +13 -0
  313. package/dist/src/utils/validation.js +8 -0
  314. package/package.json +152 -3
@@ -0,0 +1,213 @@
1
+ import {
2
+ getProviderEnvValue2
3
+ } from "./account-limits-cache-b23sbrke.js";
4
+ import {
5
+ ANTHROPIC_FEDERATION_RULE_ID_ENV2,
6
+ ANTHROPIC_ORGANIZATION_ID_ENV2,
7
+ ANTHROPIC_SERVICE_ACCOUNT_ID_ENV2,
8
+ ANTHROPIC_IDENTITY_TOKEN_FILE_ENV2,
9
+ ANTHROPIC_WORKSPACE_ID_ENV2
10
+ } from "./account-limits-cache-hyzn1jmk.js";
11
+ import {
12
+ mergeProviderHeaders2,
13
+ hasHeader2
14
+ } from "./account-limits-cache-ag5b8dja.js";
15
+ import {
16
+ getNyteUserAgent2
17
+ } from "./account-limits-cache-gknnm1kv.js";
18
+ import {
19
+ getCurrentTools2
20
+ } from "./account-limits-cache-6250ykn6.js";
21
+ import {
22
+ claudeCodeVersion2,
23
+ usesClaudeSubscription2
24
+ } from "./account-limits-cache-ks1sjym9.js";
25
+
26
+ // src/api/anthropic-client.ts
27
+ import Anthropic from "@anthropic-ai/sdk";
28
+ var FINE_GRAINED_TOOL_STREAMING_BETA = "fine-grained-tool-streaming-2025-05-14";
29
+ var FAST_MODE_BETA2 = "fast-mode-2026-02-01";
30
+ var INTERLEAVED_THINKING_BETA = "interleaved-thinking-2025-05-14";
31
+ var SERVER_SIDE_FALLBACK_BETA = "server-side-fallback-2026-07-01";
32
+ var MID_CONVERSATION_TOOL_CHANGES_BETA2 = "mid-conversation-tool-changes-2026-07-01";
33
+ function shouldUseServerSideFallbackBeta2(model) {
34
+ return (model.compat?.allowedFallbackModels?.length ?? 0) > 0;
35
+ }
36
+ function getAnthropicCompat2(model) {
37
+ return {
38
+ supportsEagerToolInputStreaming: model.compat?.supportsEagerToolInputStreaming ?? true,
39
+ supportsLongCacheRetention: model.compat?.supportsLongCacheRetention ?? true,
40
+ sendSessionAffinityHeaders: model.compat?.sendSessionAffinityHeaders ?? false,
41
+ supportsCacheControlOnTools: model.compat?.supportsCacheControlOnTools ?? true,
42
+ supportsTemperature: model.compat?.supportsTemperature ?? true,
43
+ allowEmptySignature: model.compat?.allowEmptySignature ?? false,
44
+ supportsStrictTools: model.compat?.supportsStrictTools ?? false,
45
+ supportsMidConvoSystemMessages: model.compat?.supportsMidConvoSystemMessages ?? false,
46
+ supportsMidConvoToolChanges: model.compat?.supportsMidConvoToolChanges ?? false,
47
+ supportsToolReferences: model.compat?.supportsToolReferences ?? defaultSupportsToolReferences(model)
48
+ };
49
+ }
50
+ function defaultSupportsToolReferences(model) {
51
+ if (model.provider !== "anthropic" || model.id.includes("haiku"))
52
+ return false;
53
+ const version = model.id.match(/^claude-(?:opus|sonnet|fable)-(\d+)(?:-(\d+))?(?:-|$)/);
54
+ if (!version)
55
+ return false;
56
+ const major = Number(version[1]);
57
+ const minor = version[2] && version[2].length < 8 ? Number(version[2]) : 0;
58
+ return major > 4 || major === 4 && minor >= 5;
59
+ }
60
+ function mergeAnthropicHeaders2(...headerSources) {
61
+ const merged = mergeProviderHeaders2(...headerSources);
62
+ for (const name of Object.keys(merged)) {
63
+ if (name.toLowerCase() === "anthropic-beta")
64
+ delete merged[name];
65
+ }
66
+ for (const headers of headerSources) {
67
+ for (const [name, value] of Object.entries(headers ?? {})) {
68
+ if (name.toLowerCase() === "anthropic-beta")
69
+ merged[name] = value;
70
+ }
71
+ }
72
+ return merged;
73
+ }
74
+ function appendAnthropicBeta2(headers, beta) {
75
+ if (!beta)
76
+ return headers;
77
+ const values = [];
78
+ for (const [name, value] of Object.entries(headers)) {
79
+ if (name.toLowerCase() !== "anthropic-beta")
80
+ continue;
81
+ delete headers[name];
82
+ if (value === null)
83
+ continue;
84
+ for (const entry of value.split(",")) {
85
+ const normalized = entry.trim();
86
+ if (normalized && !values.includes(normalized))
87
+ values.push(normalized);
88
+ }
89
+ }
90
+ if (!values.includes(beta))
91
+ values.push(beta);
92
+ headers["anthropic-beta"] = values.join(",");
93
+ return headers;
94
+ }
95
+ function mergeClientHeaders(...headerSources) {
96
+ return mergeAnthropicHeaders2({ "User-Agent": getNyteUserAgent2() }, ...headerSources);
97
+ }
98
+ function hasRequestAuth(apiKey, headers) {
99
+ return !!apiKey || hasHeader2(headers, "authorization") || hasHeader2(headers, "x-api-key") || hasHeader2(headers, "cf-aig-authorization");
100
+ }
101
+ function assertRequestAuth2(provider, apiKey, headers) {
102
+ if (!hasRequestAuth(apiKey, headers))
103
+ throw new Error(`No API key for provider: ${provider}`);
104
+ }
105
+
106
+ class PiAnthropic extends Anthropic {
107
+ _shouldResolveDefaultCredentials() {
108
+ return false;
109
+ }
110
+ }
111
+ function getAnthropicFederation2(model, apiKey, headers, env) {
112
+ if (model.provider !== "anthropic" || hasRequestAuth(apiKey, headers))
113
+ return;
114
+ const federationRuleId = getProviderEnvValue2(ANTHROPIC_FEDERATION_RULE_ID_ENV2, env);
115
+ const organizationId = getProviderEnvValue2(ANTHROPIC_ORGANIZATION_ID_ENV2, env);
116
+ const identityTokenFile = getProviderEnvValue2(ANTHROPIC_IDENTITY_TOKEN_FILE_ENV2, env);
117
+ if (!federationRuleId || !organizationId || !identityTokenFile)
118
+ return;
119
+ return {
120
+ organization_id: organizationId,
121
+ workspace_id: getProviderEnvValue2(ANTHROPIC_WORKSPACE_ID_ENV2, env),
122
+ authentication: {
123
+ type: "oidc_federation",
124
+ federation_rule_id: federationRuleId,
125
+ service_account_id: getProviderEnvValue2(ANTHROPIC_SERVICE_ACCOUNT_ID_ENV2, env),
126
+ identity_token: { source: "file", path: identityTokenFile }
127
+ }
128
+ };
129
+ }
130
+ var federationClient;
131
+ function createClient2(model, apiKey, interleavedThinking, useFineGrainedToolStreamingBeta, useServerSideFallbackBeta, useFastModeBeta, useMidConversationToolChangesBeta, optionsHeaders, fetch, dynamicHeaders, sessionId, federation) {
132
+ const needsInterleavedBeta = interleavedThinking && model.compat?.forceAdaptiveThinking !== true;
133
+ const betaFeatures = [];
134
+ if (useFineGrainedToolStreamingBeta) {
135
+ betaFeatures.push(FINE_GRAINED_TOOL_STREAMING_BETA);
136
+ }
137
+ if (needsInterleavedBeta) {
138
+ betaFeatures.push(INTERLEAVED_THINKING_BETA);
139
+ }
140
+ if (useServerSideFallbackBeta) {
141
+ betaFeatures.push(SERVER_SIDE_FALLBACK_BETA);
142
+ }
143
+ if (useMidConversationToolChangesBeta) {
144
+ betaFeatures.push(MID_CONVERSATION_TOOL_CHANGES_BETA2);
145
+ }
146
+ const browserHeaders = {
147
+ accept: "application/json",
148
+ "anthropic-dangerous-direct-browser-access": "true"
149
+ };
150
+ if (betaFeatures.length > 0)
151
+ browserHeaders["anthropic-beta"] = betaFeatures.join(",");
152
+ if (model.provider === "github-copilot") {
153
+ const client = new PiAnthropic({
154
+ apiKey: null,
155
+ authToken: apiKey ?? null,
156
+ baseURL: model.baseUrl,
157
+ dangerouslyAllowBrowser: true,
158
+ fetch,
159
+ defaultHeaders: appendAnthropicBeta2(mergeClientHeaders(browserHeaders, model.headers, dynamicHeaders, optionsHeaders), useFastModeBeta ? FAST_MODE_BETA2 : undefined)
160
+ });
161
+ return { client, isOAuthToken: false };
162
+ }
163
+ if (apiKey && usesClaudeSubscription2(apiKey)) {
164
+ const client = new PiAnthropic({
165
+ apiKey: null,
166
+ authToken: apiKey,
167
+ baseURL: model.baseUrl,
168
+ dangerouslyAllowBrowser: true,
169
+ fetch,
170
+ defaultHeaders: appendAnthropicBeta2(mergeClientHeaders({
171
+ accept: "application/json",
172
+ "anthropic-dangerous-direct-browser-access": "true",
173
+ "anthropic-beta": ["claude-code-20250219", "oauth-2025-04-20", ...betaFeatures].join(","),
174
+ "user-agent": `claude-cli/${claudeCodeVersion2}`,
175
+ "x-app": "cli"
176
+ }, model.headers, optionsHeaders), useFastModeBeta ? FAST_MODE_BETA2 : undefined)
177
+ });
178
+ return { client, isOAuthToken: true };
179
+ }
180
+ const sessionAffinityHeaders = sessionId && getAnthropicCompat2(model).sendSessionAffinityHeaders ? { "x-session-affinity": sessionId } : {};
181
+ const defaultHeaders = mergeClientHeaders(browserHeaders, sessionAffinityHeaders, model.headers, optionsHeaders);
182
+ if (useFastModeBeta)
183
+ appendAnthropicBeta2(defaultHeaders, FAST_MODE_BETA2);
184
+ if (federation) {
185
+ const key = JSON.stringify([model.baseUrl, federation]);
186
+ if (federationClient?.key !== key || federationClient.fetch !== fetch) {
187
+ const client = new PiAnthropic({
188
+ apiKey: null,
189
+ authToken: null,
190
+ config: federation,
191
+ baseURL: model.baseUrl,
192
+ dangerouslyAllowBrowser: true,
193
+ fetch
194
+ });
195
+ federationClient = { key, fetch, client };
196
+ }
197
+ return { client: federationClient.client.withOptions({ defaultHeaders }), isOAuthToken: false };
198
+ }
199
+ const client = new PiAnthropic({
200
+ apiKey: apiKey ?? null,
201
+ authToken: null,
202
+ baseURL: model.baseUrl,
203
+ dangerouslyAllowBrowser: true,
204
+ fetch,
205
+ defaultHeaders
206
+ });
207
+ return { client, isOAuthToken: false };
208
+ }
209
+ function shouldUseFineGrainedToolStreamingBeta2(model, context) {
210
+ return getCurrentTools2(context.messages).length > 0 && !getAnthropicCompat2(model).supportsEagerToolInputStreaming;
211
+ }
212
+
213
+ export { FAST_MODE_BETA2, MID_CONVERSATION_TOOL_CHANGES_BETA2, shouldUseServerSideFallbackBeta2, getAnthropicCompat2, mergeAnthropicHeaders2, appendAnthropicBeta2, assertRequestAuth2, getAnthropicFederation2, createClient2, shouldUseFineGrainedToolStreamingBeta2 };
@@ -0,0 +1,139 @@
1
+ import {
2
+ operationSignal2,
3
+ raceWithAbortSignal2
4
+ } from "./account-limits-cache-j2bt392s.js";
5
+ import {
6
+ formatThrownValue2
7
+ } from "./account-limits-cache-9wqk28n5.js";
8
+
9
+ // src/auth/resolve.ts
10
+ class ModelsError2 extends Error {
11
+ code;
12
+ constructor(code, message, options) {
13
+ super(withCauseDetail(message, options?.cause), options);
14
+ this.name = "ModelsError";
15
+ this.code = code;
16
+ }
17
+ }
18
+ function withCauseDetail(message, cause) {
19
+ if (cause === undefined || cause === null)
20
+ return message;
21
+ const detail = formatThrownValue2(cause).trim();
22
+ if (!detail || message.includes(detail))
23
+ return message;
24
+ return `${message}: ${detail}`;
25
+ }
26
+ function resolveProviderAuth2(provider, credentials, authContext, overrides) {
27
+ const signal = operationSignal2(overrides?.signal);
28
+ return raceWithAbortSignal2(resolveProviderAuthWithSignal(provider, credentials, authContext, overrides, signal), signal);
29
+ }
30
+ async function resolveProviderAuthWithSignal(provider, credentials, authContext, overrides, signal) {
31
+ signal.throwIfAborted();
32
+ const requestAuthContext = overrides?.env ? overlayEnvAuthContext(authContext, overrides.env) : authContext;
33
+ if (overrides?.apiKey !== undefined && provider.auth.apiKey) {
34
+ return resolveApiKey(requestAuthContext, provider.auth.apiKey, provider.id, {
35
+ type: "api_key",
36
+ key: overrides.apiKey,
37
+ env: overrides.env
38
+ }, signal);
39
+ }
40
+ const stored = await readCredential(credentials, provider.id, signal);
41
+ const account = stored?.accounts.find((entry) => entry.id === stored.active);
42
+ if (stored) {
43
+ if (!account)
44
+ return;
45
+ const credential = account.credential;
46
+ if (credential.type === "oauth" && provider.auth.oauth) {
47
+ return resolveStoredOAuth(credentials, provider.id, account.id, provider.auth.oauth, credential, signal, overrides?.minOAuthValidityMs);
48
+ }
49
+ if (credential.type === "api_key" && provider.auth.apiKey) {
50
+ const effective = overrides?.env ? { ...credential, env: { ...credential.env, ...overrides.env } } : credential;
51
+ const result = await resolveApiKey(requestAuthContext, provider.auth.apiKey, provider.id, effective, signal);
52
+ return result ? { ...result, accountId: account.id } : undefined;
53
+ }
54
+ return;
55
+ }
56
+ return provider.auth.apiKey ? resolveApiKey(requestAuthContext, provider.auth.apiKey, provider.id, undefined, signal) : undefined;
57
+ }
58
+ function overlayEnvAuthContext(base, env) {
59
+ return {
60
+ env: async (name) => env[name] || await base.env(name),
61
+ fileExists: (path) => base.fileExists(path)
62
+ };
63
+ }
64
+ var DEFAULT_OAUTH_MINIMUM_VALIDITY_MS = 5 * 60 * 1000;
65
+ var DEFAULT_OAUTH_REFRESH_TIMEOUT_MS2 = 15000;
66
+ async function resolveStoredOAuth(credentials, providerId, accountId, oauth, stored, signal, minOAuthValidityMs) {
67
+ const minimumValidityMs = Math.max(DEFAULT_OAUTH_MINIMUM_VALIDITY_MS, minOAuthValidityMs ?? 0);
68
+ const expiresSoon = (credential) => Date.now() + minimumValidityMs >= credential.expires;
69
+ let credential = stored;
70
+ let refreshed;
71
+ if (expiresSoon(credential)) {
72
+ let post;
73
+ try {
74
+ post = await credentials.modify(providerId, async (current) => {
75
+ const account = current?.accounts.find((entry) => entry.id === accountId);
76
+ if (!current || account?.credential.type !== "oauth")
77
+ return;
78
+ const previous = account.credential;
79
+ if (!expiresSoon(previous))
80
+ return;
81
+ try {
82
+ if (refreshed?.token !== previous.refresh) {
83
+ const next = await oauth.refresh(previous, AbortSignal.any([signal, AbortSignal.timeout(DEFAULT_OAUTH_REFRESH_TIMEOUT_MS2)]));
84
+ refreshed = { token: previous.refresh, credential: next };
85
+ }
86
+ const next = refreshed.credential;
87
+ return {
88
+ ...current,
89
+ accounts: current.accounts.map((entry) => entry.id === accountId ? { ...entry, credential: next } : entry)
90
+ };
91
+ } catch (error) {
92
+ throw new ModelsError2("oauth", `OAuth refresh failed for ${providerId}`, {
93
+ cause: error
94
+ });
95
+ }
96
+ }, { signal });
97
+ } catch (error) {
98
+ if (error instanceof ModelsError2)
99
+ throw error;
100
+ throw new ModelsError2("auth", `Credential store modify failed for ${providerId}`, {
101
+ cause: error
102
+ });
103
+ }
104
+ const account = post?.accounts.find((entry) => entry.id === accountId);
105
+ if (account?.credential.type !== "oauth")
106
+ return;
107
+ credential = account.credential;
108
+ if (minOAuthValidityMs !== undefined && expiresSoon(credential)) {
109
+ throw new ModelsError2("oauth", `OAuth refresh returned a token that expires too soon for ${providerId}`);
110
+ }
111
+ }
112
+ try {
113
+ return { auth: await oauth.toAuth(credential), source: "OAuth", accountId };
114
+ } catch (error) {
115
+ throw new ModelsError2("oauth", `OAuth auth derivation failed for ${providerId}`, {
116
+ cause: error
117
+ });
118
+ }
119
+ }
120
+ async function resolveApiKey(authContext, apiKey, providerId, credential, signal) {
121
+ try {
122
+ return await apiKey.resolve({ ctx: authContext, credential, signal });
123
+ } catch (error) {
124
+ throw new ModelsError2("auth", `API key auth failed for provider ${providerId}`, {
125
+ cause: error
126
+ });
127
+ }
128
+ }
129
+ async function readCredential(credentials, providerId, signal) {
130
+ try {
131
+ return await credentials.read(providerId, { signal });
132
+ } catch (error) {
133
+ throw new ModelsError2("auth", `Credential store read failed for ${providerId}`, {
134
+ cause: error
135
+ });
136
+ }
137
+ }
138
+
139
+ export { ModelsError2, resolveProviderAuth2, DEFAULT_OAUTH_REFRESH_TIMEOUT_MS2 };
@@ -0,0 +1,37 @@
1
+ // src/utils/uuid.ts
2
+ var MAX_UUID_V7_TIMESTAMP = 281474976710655;
3
+ var MAX_SEQUENCE = (1n << 41n) - 1n;
4
+ var lastOrdinaryTimestamp = -1;
5
+ var sequence;
6
+ function uuidv72(timestampMs) {
7
+ const requestedTimestamp = timestampMs ?? Date.now();
8
+ if (!Number.isInteger(requestedTimestamp) || requestedTimestamp < 0 || requestedTimestamp > MAX_UUID_V7_TIMESTAMP) {
9
+ throw new RangeError(`UUIDv7 timestamp must be an integer between 0 and ${MAX_UUID_V7_TIMESTAMP}`);
10
+ }
11
+ const effectiveTimestamp = timestampMs === undefined ? Math.max(requestedTimestamp, lastOrdinaryTimestamp) : timestampMs;
12
+ if (timestampMs === undefined)
13
+ lastOrdinaryTimestamp = effectiveTimestamp;
14
+ const bytes = new Uint8Array(16);
15
+ globalThis.crypto.getRandomValues(bytes);
16
+ if (sequence === undefined) {
17
+ sequence = BigInt(bytes[1]) << 32n | BigInt(bytes[2]) << 24n | BigInt(bytes[3]) << 16n | BigInt(bytes[4]) << 8n | BigInt(bytes[5]);
18
+ } else {
19
+ if (sequence === MAX_SEQUENCE)
20
+ throw new RangeError("UUIDv7 generator sequence exhausted");
21
+ sequence++;
22
+ }
23
+ const timestamp = BigInt(effectiveTimestamp);
24
+ for (let index = 5;index >= 0; index--) {
25
+ bytes[index] = Number(timestamp >> BigInt((5 - index) * 8)) & 255;
26
+ }
27
+ bytes[6] = 112 | Number(sequence >> 37n & 0x0fn);
28
+ bytes[7] = Number(sequence >> 29n & 0xffn);
29
+ bytes[8] = 128 | Number(sequence >> 23n & 0x3fn);
30
+ bytes[9] = Number(sequence >> 15n & 0xffn);
31
+ bytes[10] = Number(sequence >> 7n & 0xffn);
32
+ bytes[11] = Number((sequence & 0x7fn) << 1n) | bytes[11] & 1;
33
+ const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0"));
34
+ return `${hex.slice(0, 4).join("")}-${hex.slice(4, 6).join("")}-${hex.slice(6, 8).join("")}-${hex.slice(8, 10).join("")}-${hex.slice(10).join("")}`;
35
+ }
36
+
37
+ export { uuidv72 };
@@ -0,0 +1,160 @@
1
+ // src/api/transform-messages.ts
2
+ var NON_VISION_USER_IMAGE_PLACEHOLDER = "(image omitted: model does not support images)";
3
+ var NON_VISION_TOOL_IMAGE_PLACEHOLDER = "(tool image omitted: model does not support images)";
4
+ function replaceImagesWithPlaceholder(content, placeholder) {
5
+ const result = [];
6
+ let previousWasPlaceholder = false;
7
+ for (const block of content) {
8
+ if (block.type === "image") {
9
+ if (!previousWasPlaceholder) {
10
+ result.push({ type: "text", text: placeholder });
11
+ }
12
+ previousWasPlaceholder = true;
13
+ continue;
14
+ }
15
+ result.push(block);
16
+ previousWasPlaceholder = block.text === placeholder;
17
+ }
18
+ return result;
19
+ }
20
+ function downgradeUnsupportedImages(messages, model) {
21
+ if (model.input.includes("image")) {
22
+ return messages;
23
+ }
24
+ return messages.map((msg) => {
25
+ if (msg.role === "user" && Array.isArray(msg.content)) {
26
+ return {
27
+ ...msg,
28
+ content: replaceImagesWithPlaceholder(msg.content, NON_VISION_USER_IMAGE_PLACEHOLDER)
29
+ };
30
+ }
31
+ if (msg.role === "toolResult") {
32
+ return {
33
+ ...msg,
34
+ content: replaceImagesWithPlaceholder(msg.content, NON_VISION_TOOL_IMAGE_PLACEHOLDER)
35
+ };
36
+ }
37
+ return msg;
38
+ });
39
+ }
40
+ function transformMessages2(messages, model, normalizeToolCallId) {
41
+ const toolCallIdMap = new Map;
42
+ const normalizedMessages = messages.map((msg) => msg.content == null ? { ...msg, content: [] } : msg);
43
+ const imageAwareMessages = downgradeUnsupportedImages(normalizedMessages, model);
44
+ const transformed = imageAwareMessages.map((msg) => {
45
+ if (msg.role === "system" || msg.role === "user") {
46
+ return msg;
47
+ }
48
+ if (msg.role === "toolResult") {
49
+ const normalizedId = toolCallIdMap.get(msg.toolCallId);
50
+ if (normalizedId && normalizedId !== msg.toolCallId) {
51
+ return { ...msg, toolCallId: normalizedId };
52
+ }
53
+ return msg;
54
+ }
55
+ if (msg.role === "assistant") {
56
+ const isSameModel = msg.provider === model.provider && msg.api === model.api && msg.model === model.id;
57
+ const transformedContent = msg.content.flatMap((block) => {
58
+ if (block.type === "thinking") {
59
+ if (block.redacted) {
60
+ return isSameModel ? block : [];
61
+ }
62
+ if (isSameModel && block.thinkingSignature)
63
+ return block;
64
+ if (!block.thinking || block.thinking.trim() === "")
65
+ return [];
66
+ if (isSameModel)
67
+ return block;
68
+ return {
69
+ type: "text",
70
+ text: block.thinking
71
+ };
72
+ }
73
+ if (block.type === "text") {
74
+ if (isSameModel)
75
+ return block;
76
+ return {
77
+ type: "text",
78
+ text: block.text
79
+ };
80
+ }
81
+ if (block.type === "toolCall") {
82
+ let normalizedToolCall = block;
83
+ if (!isSameModel && block.thoughtSignature) {
84
+ normalizedToolCall = { ...block };
85
+ delete normalizedToolCall.thoughtSignature;
86
+ }
87
+ if (!isSameModel && normalizeToolCallId) {
88
+ const normalizedId = normalizeToolCallId(block.id, model, msg);
89
+ if (normalizedId !== block.id) {
90
+ toolCallIdMap.set(block.id, normalizedId);
91
+ normalizedToolCall = { ...normalizedToolCall, id: normalizedId };
92
+ }
93
+ }
94
+ return normalizedToolCall;
95
+ }
96
+ return block;
97
+ });
98
+ return {
99
+ ...msg,
100
+ content: transformedContent
101
+ };
102
+ }
103
+ return msg;
104
+ });
105
+ const result = [];
106
+ let pendingToolCalls = [];
107
+ let existingToolResultIds = new Set;
108
+ const heldSystemMessages = [];
109
+ const closePendingToolCalls = () => {
110
+ if (pendingToolCalls.length > 0) {
111
+ for (const tc of pendingToolCalls) {
112
+ if (!existingToolResultIds.has(tc.id)) {
113
+ result.push({
114
+ role: "toolResult",
115
+ toolCallId: tc.id,
116
+ toolName: tc.name,
117
+ content: [{ type: "text", text: "No result provided" }],
118
+ isError: true,
119
+ timestamp: Date.now()
120
+ });
121
+ }
122
+ }
123
+ pendingToolCalls = [];
124
+ existingToolResultIds = new Set;
125
+ }
126
+ result.push(...heldSystemMessages);
127
+ heldSystemMessages.length = 0;
128
+ };
129
+ for (let i = 0;i < transformed.length; i++) {
130
+ const msg = transformed[i];
131
+ if (msg.role === "assistant") {
132
+ closePendingToolCalls();
133
+ if (msg.stopReason === "error" || msg.stopReason === "aborted") {
134
+ continue;
135
+ }
136
+ const toolCalls = msg.content.filter((b) => b.type === "toolCall");
137
+ if (toolCalls.length > 0) {
138
+ pendingToolCalls = toolCalls;
139
+ existingToolResultIds = new Set;
140
+ }
141
+ result.push(msg);
142
+ } else if (msg.role === "toolResult") {
143
+ existingToolResultIds.add(msg.toolCallId);
144
+ result.push(msg);
145
+ } else if (msg.role === "system") {
146
+ if (pendingToolCalls.length > 0) {
147
+ heldSystemMessages.push(msg);
148
+ } else {
149
+ result.push(msg);
150
+ }
151
+ } else {
152
+ closePendingToolCalls();
153
+ result.push(msg);
154
+ }
155
+ }
156
+ closePendingToolCalls();
157
+ return result;
158
+ }
159
+
160
+ export { transformMessages2 };
@@ -0,0 +1,36 @@
1
+ // src/utils/deferred-tools.ts
2
+ var identityToolName = (name) => name;
3
+ function splitDeferredTools2(context, enabled, normalizeName = identityToolName) {
4
+ const uniqueTools = new Map;
5
+ for (const tool of context.tools ?? [])
6
+ uniqueTools.set(normalizeName(tool.name), tool);
7
+ if (!enabled)
8
+ return { immediate: [...uniqueTools.values()], deferred: new Map };
9
+ const deferredNames = new Set;
10
+ const usedNames = new Set;
11
+ for (const message of context.messages) {
12
+ if (message.role === "assistant") {
13
+ for (const block of message.content) {
14
+ if (block.type === "toolCall")
15
+ usedNames.add(normalizeName(block.name));
16
+ }
17
+ } else if (message.role === "toolResult") {
18
+ for (const name of message.addedToolNames ?? []) {
19
+ const normalizedName = normalizeName(name);
20
+ if (!usedNames.has(normalizedName))
21
+ deferredNames.add(normalizedName);
22
+ }
23
+ }
24
+ }
25
+ const immediate = [];
26
+ const deferred = new Map;
27
+ for (const [name, tool] of uniqueTools) {
28
+ if (deferredNames.has(name))
29
+ deferred.set(name, tool);
30
+ else
31
+ immediate.push(tool);
32
+ }
33
+ return { immediate, deferred };
34
+ }
35
+
36
+ export { splitDeferredTools2 };