gemi 0.224.1 → 0.225.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (258) hide show
  1. package/dist/ai/Agent.d.ts +2 -0
  2. package/dist/ai/Agent.d.ts.map +1 -1
  3. package/dist/ai/index.js +2 -2
  4. package/dist/ai/index.js.map +1 -1
  5. package/dist/ai/providers/anthropicStream.d.ts +6 -0
  6. package/dist/ai/providers/anthropicStream.d.ts.map +1 -1
  7. package/dist/ai/providers/call.d.ts +15 -0
  8. package/dist/ai/providers/call.d.ts.map +1 -1
  9. package/dist/ai/providers/endpoints.d.ts +25 -0
  10. package/dist/ai/providers/endpoints.d.ts.map +1 -1
  11. package/dist/ai/providers/errors.d.ts +12 -0
  12. package/dist/ai/providers/errors.d.ts.map +1 -1
  13. package/dist/ai/providers/stream.d.ts +3 -0
  14. package/dist/ai/providers/stream.d.ts.map +1 -1
  15. package/dist/ai/testing/index.js +2 -2
  16. package/dist/ai/testing/index.js.map +2 -2
  17. package/dist/ai/types.d.ts +6 -0
  18. package/dist/ai/types.d.ts.map +1 -1
  19. package/dist/app/index.js +1 -1
  20. package/dist/bun/plugin.js +1 -1
  21. package/dist/bun/preload.js +1 -1
  22. package/dist/{chunk-p1ern8r4.js → chunk-1jyzg1ex.js} +3 -3
  23. package/dist/{chunk-p1ern8r4.js.map → chunk-1jyzg1ex.js.map} +1 -1
  24. package/dist/{chunk-97tj0d7v.js → chunk-21hhvphe.js} +2 -2
  25. package/dist/{chunk-97tj0d7v.js.map → chunk-21hhvphe.js.map} +1 -1
  26. package/dist/{chunk-zmt5kdpb.js → chunk-2450kxym.js} +2 -2
  27. package/dist/{chunk-zmt5kdpb.js.map → chunk-2450kxym.js.map} +1 -1
  28. package/dist/{chunk-vmmjq9fn.js → chunk-3dkaz47e.js} +2 -2
  29. package/dist/{chunk-vmmjq9fn.js.map → chunk-3dkaz47e.js.map} +1 -1
  30. package/dist/{chunk-bqm79ar0.js → chunk-3e55yw7v.js} +3 -3
  31. package/dist/{chunk-bqm79ar0.js.map → chunk-3e55yw7v.js.map} +1 -1
  32. package/dist/chunk-3vgjrn2r.js +12 -0
  33. package/dist/{chunk-dpmvvwts.js.map → chunk-3vgjrn2r.js.map} +6 -6
  34. package/dist/{chunk-snmyjq03.js → chunk-40yd1n60.js} +2 -2
  35. package/dist/{chunk-snmyjq03.js.map → chunk-40yd1n60.js.map} +1 -1
  36. package/dist/{chunk-6ttbhhnn.js → chunk-421hq1rw.js} +1 -1
  37. package/dist/{chunk-99216y02.js → chunk-444g812v.js} +2 -2
  38. package/dist/{chunk-99216y02.js.map → chunk-444g812v.js.map} +1 -1
  39. package/dist/{chunk-k16phdjv.js → chunk-4qyp7w89.js} +1 -1
  40. package/dist/{chunk-j9abwrkv.js → chunk-5kgqfczk.js} +3 -3
  41. package/dist/{chunk-j9abwrkv.js.map → chunk-5kgqfczk.js.map} +1 -1
  42. package/dist/{chunk-wy82t7mz.js → chunk-64yf0shq.js} +2 -2
  43. package/dist/{chunk-wy82t7mz.js.map → chunk-64yf0shq.js.map} +1 -1
  44. package/dist/{chunk-8a3fqcf0.js → chunk-6et7jwp8.js} +2 -2
  45. package/dist/{chunk-8a3fqcf0.js.map → chunk-6et7jwp8.js.map} +1 -1
  46. package/dist/{chunk-0k2r6bep.js → chunk-6h1hjzj7.js} +2 -2
  47. package/dist/{chunk-0k2r6bep.js.map → chunk-6h1hjzj7.js.map} +1 -1
  48. package/dist/{chunk-nzd7z4s6.js → chunk-70jhw0ft.js} +1 -1
  49. package/dist/{chunk-b87wvmsz.js → chunk-7901z26g.js} +2 -2
  50. package/dist/{chunk-b87wvmsz.js.map → chunk-7901z26g.js.map} +1 -1
  51. package/dist/{chunk-sfrjkysf.js → chunk-7d1f5gyv.js} +2 -2
  52. package/dist/{chunk-sfrjkysf.js.map → chunk-7d1f5gyv.js.map} +1 -1
  53. package/dist/{chunk-50791bmz.js → chunk-7mvfk0q9.js} +2 -2
  54. package/dist/{chunk-50791bmz.js.map → chunk-7mvfk0q9.js.map} +1 -1
  55. package/dist/{chunk-4wh4dfgf.js → chunk-81y96dax.js} +1 -1
  56. package/dist/{chunk-2vv04thj.js → chunk-8pdke84p.js} +2 -2
  57. package/dist/{chunk-2vv04thj.js.map → chunk-8pdke84p.js.map} +1 -1
  58. package/dist/{chunk-h9nt7hm6.js → chunk-8szsd6vy.js} +2 -2
  59. package/dist/{chunk-h9nt7hm6.js.map → chunk-8szsd6vy.js.map} +1 -1
  60. package/dist/{chunk-79v94sa6.js → chunk-8yxjq6cm.js} +2 -2
  61. package/dist/{chunk-79v94sa6.js.map → chunk-8yxjq6cm.js.map} +1 -1
  62. package/dist/{chunk-t8ygf6zj.js → chunk-9xxgj5zk.js} +3 -3
  63. package/dist/{chunk-t8ygf6zj.js.map → chunk-9xxgj5zk.js.map} +1 -1
  64. package/dist/{chunk-8pz8yzax.js → chunk-9znec0we.js} +4 -4
  65. package/dist/{chunk-8pz8yzax.js.map → chunk-9znec0we.js.map} +3 -3
  66. package/dist/{chunk-3dkv4989.js → chunk-ads3c8m0.js} +2 -2
  67. package/dist/{chunk-3dkv4989.js.map → chunk-ads3c8m0.js.map} +1 -1
  68. package/dist/{chunk-fqhkkpq3.js → chunk-awryyak8.js} +2 -2
  69. package/dist/{chunk-fqhkkpq3.js.map → chunk-awryyak8.js.map} +1 -1
  70. package/dist/{chunk-5jvbr0e5.js → chunk-bch7xbsr.js} +2 -2
  71. package/dist/{chunk-5jvbr0e5.js.map → chunk-bch7xbsr.js.map} +1 -1
  72. package/dist/{chunk-3y91vexx.js → chunk-bwjaq694.js} +3 -3
  73. package/dist/{chunk-3y91vexx.js.map → chunk-bwjaq694.js.map} +1 -1
  74. package/dist/chunk-bzrta2sw.js +10 -0
  75. package/dist/{chunk-qs2xvc8g.js.map → chunk-bzrta2sw.js.map} +9 -4
  76. package/dist/{chunk-4v5nwqw6.js → chunk-crk4ddqa.js} +3 -3
  77. package/dist/{chunk-4v5nwqw6.js.map → chunk-crk4ddqa.js.map} +1 -1
  78. package/dist/{chunk-37209psn.js → chunk-d3a29hyg.js} +3 -3
  79. package/dist/{chunk-37209psn.js.map → chunk-d3a29hyg.js.map} +1 -1
  80. package/dist/{chunk-jyyrgb6j.js → chunk-dxesf8bt.js} +2 -2
  81. package/dist/{chunk-jyyrgb6j.js.map → chunk-dxesf8bt.js.map} +1 -1
  82. package/dist/{chunk-yj7pbbnm.js → chunk-enqrjcdk.js} +2 -2
  83. package/dist/{chunk-yj7pbbnm.js.map → chunk-enqrjcdk.js.map} +1 -1
  84. package/dist/{chunk-adw279ge.js → chunk-eydww2nn.js} +2 -2
  85. package/dist/{chunk-adw279ge.js.map → chunk-eydww2nn.js.map} +1 -1
  86. package/dist/{chunk-fxa72ppw.js → chunk-fjnhqbtx.js} +1 -1
  87. package/dist/{chunk-726gd69z.js → chunk-ftc9292d.js} +2 -2
  88. package/dist/{chunk-726gd69z.js.map → chunk-ftc9292d.js.map} +1 -1
  89. package/dist/{chunk-pxjptskr.js → chunk-gj0bwm41.js} +2 -2
  90. package/dist/{chunk-pxjptskr.js.map → chunk-gj0bwm41.js.map} +1 -1
  91. package/dist/{chunk-5mrtgr7q.js → chunk-hvyzp9p6.js} +2 -2
  92. package/dist/{chunk-5mrtgr7q.js.map → chunk-hvyzp9p6.js.map} +1 -1
  93. package/dist/{chunk-8vpe54ek.js → chunk-j0rhz378.js} +2 -2
  94. package/dist/{chunk-8vpe54ek.js.map → chunk-j0rhz378.js.map} +1 -1
  95. package/dist/{chunk-swmf6w3z.js → chunk-j13jmjkr.js} +2 -2
  96. package/dist/{chunk-swmf6w3z.js.map → chunk-j13jmjkr.js.map} +1 -1
  97. package/dist/{chunk-anc5v266.js → chunk-j7pzdvxr.js} +2 -2
  98. package/dist/{chunk-anc5v266.js.map → chunk-j7pzdvxr.js.map} +1 -1
  99. package/dist/{chunk-h1wmpa03.js → chunk-ja3n968b.js} +2 -2
  100. package/dist/{chunk-h1wmpa03.js.map → chunk-ja3n968b.js.map} +1 -1
  101. package/dist/{chunk-vcw98sp6.js → chunk-k657v3ed.js} +3 -3
  102. package/dist/{chunk-vcw98sp6.js.map → chunk-k657v3ed.js.map} +1 -1
  103. package/dist/{chunk-t586p2g2.js → chunk-kxc2mzzr.js} +2 -2
  104. package/dist/{chunk-t586p2g2.js.map → chunk-kxc2mzzr.js.map} +1 -1
  105. package/dist/{chunk-nqqyn3cx.js → chunk-kzz2nfzf.js} +2 -2
  106. package/dist/{chunk-nqqyn3cx.js.map → chunk-kzz2nfzf.js.map} +1 -1
  107. package/dist/{chunk-k6af7qek.js → chunk-m7v4erdg.js} +2 -2
  108. package/dist/{chunk-k6af7qek.js.map → chunk-m7v4erdg.js.map} +1 -1
  109. package/dist/{chunk-p4v71qfx.js → chunk-mca5s0bf.js} +3 -3
  110. package/dist/{chunk-p4v71qfx.js.map → chunk-mca5s0bf.js.map} +1 -1
  111. package/dist/{chunk-79wjkaa4.js → chunk-me70vszk.js} +2 -2
  112. package/dist/{chunk-79wjkaa4.js.map → chunk-me70vszk.js.map} +1 -1
  113. package/dist/{chunk-qy0k2s5f.js → chunk-mvb8m247.js} +2 -2
  114. package/dist/{chunk-qy0k2s5f.js.map → chunk-mvb8m247.js.map} +1 -1
  115. package/dist/{chunk-0av1gyns.js → chunk-mvp6fkg2.js} +3 -3
  116. package/dist/{chunk-0av1gyns.js.map → chunk-mvp6fkg2.js.map} +1 -1
  117. package/dist/{chunk-e4zxacxd.js → chunk-n2c748aw.js} +2 -2
  118. package/dist/{chunk-e4zxacxd.js.map → chunk-n2c748aw.js.map} +1 -1
  119. package/dist/{chunk-nqgeny8m.js → chunk-ng6pbd7f.js} +4 -4
  120. package/dist/{chunk-nqgeny8m.js.map → chunk-ng6pbd7f.js.map} +1 -1
  121. package/dist/{chunk-7xe5vd4w.js → chunk-pdymdjpq.js} +2 -2
  122. package/dist/{chunk-7xe5vd4w.js.map → chunk-pdymdjpq.js.map} +1 -1
  123. package/dist/{chunk-dj0nvj66.js → chunk-pn3egz75.js} +1 -1
  124. package/dist/chunk-qjn6a2ed.js +5 -0
  125. package/dist/{chunk-89egc0h3.js.map → chunk-qjn6a2ed.js.map} +1 -1
  126. package/dist/chunk-qrc2r0ce.js +5 -0
  127. package/dist/{chunk-kp7wcpx7.js.map → chunk-qrc2r0ce.js.map} +3 -3
  128. package/dist/{chunk-gyszenps.js → chunk-qtz4g4kv.js} +3 -3
  129. package/dist/{chunk-gyszenps.js.map → chunk-qtz4g4kv.js.map} +1 -1
  130. package/dist/{chunk-55btq9c7.js → chunk-qx9p15em.js} +2 -2
  131. package/dist/{chunk-55btq9c7.js.map → chunk-qx9p15em.js.map} +1 -1
  132. package/dist/{chunk-fp9yn4k8.js → chunk-rq0dpv7r.js} +2 -2
  133. package/dist/{chunk-fp9yn4k8.js.map → chunk-rq0dpv7r.js.map} +1 -1
  134. package/dist/{chunk-ps5rpy9n.js → chunk-ryh6rfts.js} +2 -2
  135. package/dist/{chunk-ps5rpy9n.js.map → chunk-ryh6rfts.js.map} +1 -1
  136. package/dist/{chunk-7etvj6w2.js → chunk-svrvb47q.js} +2 -2
  137. package/dist/{chunk-7etvj6w2.js.map → chunk-svrvb47q.js.map} +1 -1
  138. package/dist/{chunk-3k4p9agd.js → chunk-t5aft2ra.js} +22 -22
  139. package/dist/{chunk-3k4p9agd.js.map → chunk-t5aft2ra.js.map} +8 -7
  140. package/dist/{chunk-ncnygh0s.js → chunk-t9fh0ptd.js} +2 -2
  141. package/dist/{chunk-ncnygh0s.js.map → chunk-t9fh0ptd.js.map} +1 -1
  142. package/dist/{chunk-jf2dr481.js → chunk-tbvrv4h2.js} +2 -2
  143. package/dist/{chunk-jf2dr481.js.map → chunk-tbvrv4h2.js.map} +1 -1
  144. package/dist/{chunk-6r7956dh.js → chunk-tgy75n24.js} +2 -2
  145. package/dist/{chunk-6r7956dh.js.map → chunk-tgy75n24.js.map} +1 -1
  146. package/dist/{chunk-pxjkxhf9.js → chunk-tp1gxcke.js} +3 -3
  147. package/dist/{chunk-pxjkxhf9.js.map → chunk-tp1gxcke.js.map} +1 -1
  148. package/dist/{chunk-y8cj5cap.js → chunk-v0fqq5z7.js} +2 -2
  149. package/dist/{chunk-y8cj5cap.js.map → chunk-v0fqq5z7.js.map} +1 -1
  150. package/dist/{chunk-cf8bztwq.js → chunk-v4ecxbgd.js} +2 -2
  151. package/dist/{chunk-cf8bztwq.js.map → chunk-v4ecxbgd.js.map} +1 -1
  152. package/dist/{chunk-rat2827k.js → chunk-v5sg62xm.js} +2 -2
  153. package/dist/{chunk-rat2827k.js.map → chunk-v5sg62xm.js.map} +1 -1
  154. package/dist/chunk-v979k0be.js +5 -0
  155. package/dist/{chunk-zcmz311y.js.map → chunk-v979k0be.js.map} +3 -8
  156. package/dist/{chunk-rw45xz3f.js → chunk-we65r9fh.js} +3 -3
  157. package/dist/{chunk-rw45xz3f.js.map → chunk-we65r9fh.js.map} +1 -1
  158. package/dist/{chunk-2y0nr525.js → chunk-wnmpwb4s.js} +3 -3
  159. package/dist/{chunk-2y0nr525.js.map → chunk-wnmpwb4s.js.map} +1 -1
  160. package/dist/{chunk-s3gn68dy.js → chunk-wzr8tzv0.js} +2 -2
  161. package/dist/{chunk-s3gn68dy.js.map → chunk-wzr8tzv0.js.map} +1 -1
  162. package/dist/{chunk-wt4ekzp9.js → chunk-x47kwv2x.js} +2 -2
  163. package/dist/{chunk-wt4ekzp9.js.map → chunk-x47kwv2x.js.map} +1 -1
  164. package/dist/{chunk-8ddt5fa2.js → chunk-x93dpv6e.js} +2 -2
  165. package/dist/{chunk-8ddt5fa2.js.map → chunk-x93dpv6e.js.map} +1 -1
  166. package/dist/{chunk-tac25cnj.js → chunk-xpzdwhjg.js} +3 -3
  167. package/dist/{chunk-tac25cnj.js.map → chunk-xpzdwhjg.js.map} +1 -1
  168. package/dist/{chunk-ax042w6k.js → chunk-z4fhhtjh.js} +2 -2
  169. package/dist/{chunk-ax042w6k.js.map → chunk-z4fhhtjh.js.map} +1 -1
  170. package/dist/{chunk-5h2xj3cx.js → chunk-z6x78wb3.js} +2 -2
  171. package/dist/{chunk-5h2xj3cx.js.map → chunk-z6x78wb3.js.map} +1 -1
  172. package/dist/{chunk-q5xcjm5z.js → chunk-zvg2qsa5.js} +2 -2
  173. package/dist/{chunk-q5xcjm5z.js.map → chunk-zvg2qsa5.js.map} +1 -1
  174. package/dist/{chunk-mt82209n.js → chunk-zy56kaws.js} +2 -2
  175. package/dist/{chunk-mt82209n.js.map → chunk-zy56kaws.js.map} +1 -1
  176. package/dist/chunks/{RealtimeClient-CuTFz0v1.js → RealtimeClient-C5Zh3fD6.js} +2 -2
  177. package/dist/chunks/{RealtimeClient-CuTFz0v1.js.map → RealtimeClient-C5Zh3fD6.js.map} +1 -1
  178. package/dist/chunks/{ThemeProvider-BO3sQkWl.js → ThemeProvider-bbbE-N3t.js} +5 -3
  179. package/dist/chunks/ThemeProvider-bbbE-N3t.js.map +1 -0
  180. package/dist/chunks/{fetchFileRequest-CrKd0rD5.js → fetchFileRequest-JXhnEi-R.js} +2 -2
  181. package/dist/chunks/{fetchFileRequest-CrKd0rD5.js.map → fetchFileRequest-JXhnEi-R.js.map} +1 -1
  182. package/dist/chunks/{live-BCCfTb28.js → live-CApTRvmK.js} +3 -3
  183. package/dist/chunks/{live-BCCfTb28.js.map → live-CApTRvmK.js.map} +1 -1
  184. package/dist/chunks/{mutationExtras-cPXZS6Hf.js → mutationExtras-C2qSSZ2Q.js} +34 -3
  185. package/dist/chunks/mutationExtras-C2qSSZ2Q.js.map +1 -0
  186. package/dist/chunks/{subscriptionStream-CRrAISl8.js → subscriptionStream-DQLW7dTW.js} +2 -2
  187. package/dist/chunks/{subscriptionStream-CRrAISl8.js.map → subscriptionStream-DQLW7dTW.js.map} +1 -1
  188. package/dist/client/QueryManagerContext.d.ts +2 -0
  189. package/dist/client/QueryManagerContext.d.ts.map +1 -1
  190. package/dist/client/index.d.ts +2 -1
  191. package/dist/client/index.d.ts.map +1 -1
  192. package/dist/client/index.js +63 -8
  193. package/dist/client/index.js.map +1 -1
  194. package/dist/client/islands.d.ts.map +1 -1
  195. package/dist/client/mutationExtras.d.ts +1 -1
  196. package/dist/client/mutationExtras.d.ts.map +1 -1
  197. package/dist/client/queryUpdates.d.ts +8 -0
  198. package/dist/client/queryUpdates.d.ts.map +1 -1
  199. package/dist/client/useInvalidate.d.ts +13 -0
  200. package/dist/client/useInvalidate.d.ts.map +1 -0
  201. package/dist/client/useMutation.d.ts +17 -0
  202. package/dist/client/useMutation.d.ts.map +1 -1
  203. package/dist/config/index.js +1 -1
  204. package/dist/console/run.js +2 -2
  205. package/dist/console/run.js.map +1 -1
  206. package/dist/container/index.js +2 -2
  207. package/dist/container/index.js.map +1 -1
  208. package/dist/database/index.js +2 -2
  209. package/dist/database/index.js.map +1 -1
  210. package/dist/email/index.js +2 -2
  211. package/dist/email/index.js.map +1 -1
  212. package/dist/facades/Prefetch.d.ts +22 -0
  213. package/dist/facades/Prefetch.d.ts.map +1 -1
  214. package/dist/facades/index.js +2 -2
  215. package/dist/facades/index.js.map +1 -1
  216. package/dist/foundation/index.js +2 -2
  217. package/dist/foundation/index.js.map +1 -1
  218. package/dist/http/index.js +2 -2
  219. package/dist/http/index.js.map +1 -1
  220. package/dist/i18n/dictionaryRuntime.js +2 -2
  221. package/dist/i18n/dictionaryRuntime.js.map +1 -1
  222. package/dist/i18n/index.js +2 -2
  223. package/dist/i18n/index.js.map +1 -1
  224. package/dist/kernel/index.js +2 -2
  225. package/dist/kernel/index.js.map +1 -1
  226. package/dist/orm/index.js +2 -2
  227. package/dist/orm/index.js.map +1 -1
  228. package/dist/probe/index.js +2 -2
  229. package/dist/probe/index.js.map +1 -1
  230. package/dist/server/index.js +2 -2
  231. package/dist/server/index.js.map +1 -1
  232. package/dist/services/index.js +2 -2
  233. package/dist/services/index.js.map +2 -2
  234. package/dist/services/queue/work.js +2 -2
  235. package/dist/services/queue/work.js.map +1 -1
  236. package/dist/services/router/ServerQueryStore.d.ts +8 -0
  237. package/dist/services/router/ServerQueryStore.d.ts.map +1 -1
  238. package/dist/stats/route-table.js +1 -1
  239. package/dist/support/index.js +2 -2
  240. package/dist/support/index.js.map +1 -1
  241. package/dist/testing/index.js +2 -2
  242. package/dist/utils/invalidation.d.ts +16 -0
  243. package/dist/utils/invalidation.d.ts.map +1 -0
  244. package/dist/vitest/index.js +1 -1
  245. package/package.json +1 -1
  246. package/dist/chunk-89egc0h3.js +0 -5
  247. package/dist/chunk-dpmvvwts.js +0 -11
  248. package/dist/chunk-kp7wcpx7.js +0 -5
  249. package/dist/chunk-qs2xvc8g.js +0 -7
  250. package/dist/chunk-zcmz311y.js +0 -8
  251. package/dist/chunks/ThemeProvider-BO3sQkWl.js.map +0 -1
  252. package/dist/chunks/mutationExtras-cPXZS6Hf.js.map +0 -1
  253. /package/dist/{chunk-6ttbhhnn.js.map → chunk-421hq1rw.js.map} +0 -0
  254. /package/dist/{chunk-k16phdjv.js.map → chunk-4qyp7w89.js.map} +0 -0
  255. /package/dist/{chunk-nzd7z4s6.js.map → chunk-70jhw0ft.js.map} +0 -0
  256. /package/dist/{chunk-4wh4dfgf.js.map → chunk-81y96dax.js.map} +0 -0
  257. /package/dist/{chunk-fxa72ppw.js.map → chunk-fjnhqbtx.js.map} +0 -0
  258. /package/dist/{chunk-dj0nvj66.js.map → chunk-pn3egz75.js.map} +0 -0
@@ -0,0 +1,12 @@
1
+ // @bun
2
+ import{$d as h,Nd as OQ,Vd as I,Wd as o,Xd as X5,Yd as H5,Zd as xQ,_d as j5,ae as QQ,be as M,xd as JQ,zd as $Q}from"./chunk-qrc2r0ce.js";import{Bj as oQ,Jj as W5}from"./chunk-bzrta2sw.js";function XQ(Q,$,J){let Z=Q.on;if(Z===void 0)return!0;if(typeof Z!=="function")return Z.includes($.code);try{return Z($,J)===!0}catch{return!1}}var v5=4000,b5=60000;function pQ(Q){if(Q===void 0)return;let $=(J,Z)=>typeof J==="number"&&Number.isFinite(J)&&J>=Z;if(!Q||!$(Q.patienceMs,0)||Q.initialWaitMs!==void 0&&!$(Q.initialWaitMs,1)||Q.maxWaitMs!==void 0&&!$(Q.maxWaitMs,1)||Q.on!==void 0&&typeof Q.on!=="function"&&!(Array.isArray(Q.on)&&Q.on.every((J)=>typeof J==="string")))throw Error(`The provider's retry policy ${JSON.stringify(Q)} is not usable: patienceMs has to be a number of milliseconds (0 or more), initialWaitMs and maxWaitMs above 0, and on a list of error codes or a function.`)}function HQ(Q,$,J,Z,Y){let G=Q.patienceMs-Z;if(G<=0)return;let B=Q.maxWaitMs??b5,z=Q.initialWaitMs??v5,X=J!==void 0?Math.min(J,B):Math.round(Math.min(B,z*2**$)*(0.5+Y()*0.5));return Math.min(X,G)}var h5=500,lQ=20000;function y5(Q,$){if(!Q)return;let J=Q.trim();if(/^\d+(\.\d+)?$/.test(J))return Math.max(0,Number(J)*1000);let Z=Date.parse(J);if(Number.isNaN(Z))return;return Math.max(0,Z-$)}function a(Q,$){let J=Math.min(lQ,h5*2**Q);return Math.round(J*(0.5+$()*0.5))}function f5(Q){return Q===429||Q===408||Q===409||Q>=500}function g5(Q,$){return f5(Q)&&M($).retryable}function iQ(Q){return Q.reason??new DOMException("The operation was aborted.","AbortError")}function nQ(Q,$){return new Promise((J,Z)=>{let Y=setTimeout(J,Q);$?.addEventListener("abort",()=>{clearTimeout(Y),Z(iQ($))},{once:!0})})}async function jQ(Q,$,J=nQ){if(!$)return await J(Q);$.throwIfAborted();let Z;try{await Promise.race([J(Q,$),new Promise((Y,G)=>{Z=()=>G(iQ($)),$.addEventListener("abort",Z,{once:!0})})])}finally{if(Z)$.removeEventListener("abort",Z)}}async function g(Q,$,J){let Z=J.fetchImpl??((V,W)=>fetch(V,W)),Y=J.sleep??nQ,G=J.random??Math.random,B=J.now??Date.now,z=Math.max(0,J.maxRetries),X=J.startedAt??B(),K=J.retry,j=(V,W,q,C)=>{let P=B()-X;try{J.onRetry?.({attempt:W+1,maxRetries:z,error:M(q),...h(q),timedOut:C,delayMs:V,elapsedMs:P,...K?{remainingMs:Math.max(0,K.patienceMs-P-V)}:{}})}catch{}return jQ(V,J.signal,Y)},H=(V,W,q,C)=>{if(!K)return;let{status:P}=h(q);if(!XQ(K,M(q),{...P?{status:P}:{},timedOut:C}))return;return HQ(K,V-z,W,B()-X,G)};for(let V=0;;V++){J.signal?.throwIfAborted();let W=new AbortController,q=()=>W.abort(J.signal?.reason);J.signal?.addEventListener("abort",q,{once:!0});let C=!1,P=J.timeoutMs>0?setTimeout(()=>{C=!0,W.abort()},J.timeoutMs):void 0,D;try{D=await Z(Q,{...$,signal:W.signal})}catch(y){if(P!==void 0)clearTimeout(P);if(J.signal?.removeEventListener("abort",q),J.signal?.aborted)throw y;let S=C?new o(J.timeoutMs):y;if(C&&J.retryTimeouts===!1)throw S;let E=V<z?a(V,G):H(V,void 0,S,C);if(E===void 0)throw S;await j(E,V,S,C);continue}if(P!==void 0)clearTimeout(P);if(D.ok)return D;J.signal?.removeEventListener("abort",q);let c=await u5(D),U=new I(D.status,c,D.headers.get("x-request-id")??D.headers.get("request-id")??void 0,y5(D.headers.get("retry-after"),B()));if(!g5(D.status,U))throw U;let O=U.retryAfter??(D.status===429?M(U).retryAfter:void 0),i=V>=z?H(V,O,U,!1):O===void 0?a(V,G):Math.min(O,lQ);if(i===void 0)throw U;await j(i,V,U,!1)}}async function u5(Q){let $;try{$=await Q.text()}catch{return null}try{return JSON.parse($)}catch{return $}}function rQ(Q,$,J){let Z=$.idleMs>0?$.idleMs:0,Y=$.maxMs>0?$.maxMs:0;if(!Q||!Z&&!Y)return Q;let G=Y?performance.now()+Y:1/0,B=Q.getReader();return new ReadableStream({async pull(z){let X,K,j=Math.max(0,G-performance.now()),H=!Z||j<=Z,V=H?j:Z,W=new Promise((q,C)=>{X=setTimeout(()=>{K=H?J.max():J.idle(),C(K)},V)});try{let q=await Promise.race([B.read(),W]);if(q.done)z.close();else z.enqueue(q.value)}catch(q){let C=K??q;z.error(C),B.cancel(C).catch(()=>{})}finally{clearTimeout(X)}},cancel(z){return B.cancel(z)}},{highWaterMark:0})}var qQ=30000,sQ=10,aQ=7200,m5=600,c5="gpt-live-transcribe";function d5(Q){return Q.type==="transcription"}function p5(Q){if(Q.language!==void 0&&Q.languages!==void 0)throw TypeError("A transcription session takes `languages` or `language`, not both (gpt-live-transcribe reads `languages`).");for(let Y of Q.keywords??[])if(/[<>\r\n]/.test(Y))throw TypeError(`Transcription keywords must be one line without "<" or ">", got ${JSON.stringify(Y)}.`);let $={model:Q.model??c5};if(Q.prompt!==void 0)$.prompt=Q.prompt;if(Q.keywords?.length)$.keywords=Q.keywords;if(Q.languages?.length)$.languages=Q.languages;if(Q.language!==void 0)$.language=Q.language;if(Q.delay!==void 0)$.delay=Q.delay;let J={transcription:$,turn_detection:Q.turnDetection?tQ(Q.turnDetection):null};if(Q.noiseReduction!==void 0)J.noise_reduction=Q.noiseReduction&&{type:Q.noiseReduction};let Z={type:"transcription",audio:{input:J}};if(Q.logprobs)Z.include=["item.input_audio_transcription.logprobs"];return{...Z,...Q.vendor}}function l5(Q){if(!Q)return{type:"object",properties:{}};return oQ(Q)?Q.toJSONSchema():Q}function t(Q,$){if(d5(Q))return p5(Q);let J={type:"realtime"},Z=Q.model??$;if(Z)J.model=Z;if(Q.instructions!==void 0)J.instructions=Q.instructions;if(Q.outputModalities)J.output_modalities=Q.outputModalities;if(Q.maxOutputTokens!==void 0)J.max_output_tokens=Q.maxOutputTokens;if(Q.truncation!==void 0)J.truncation=Q.truncation;if(Q.tools)J.tools=Q.tools.map((B)=>({type:"function",name:B.name,...B.description?{description:B.description}:{},parameters:l5(B.parameters)}));if(Q.toolChoice!==void 0)J.tool_choice=typeof Q.toolChoice==="string"?Q.toolChoice:{type:"function",name:Q.toolChoice.name};let Y={};if(Q.turnDetection!==void 0)Y.turn_detection=Q.turnDetection&&tQ(Q.turnDetection);if(Q.transcription!==void 0)Y.transcription=Q.transcription;if(Q.noiseReduction!==void 0)Y.noise_reduction=Q.noiseReduction&&{type:Q.noiseReduction};let G={};if(Q.voice!==void 0)G.voice=Q.voice;if(Q.speed!==void 0)G.speed=Q.speed;if(Object.keys(Y).length||Object.keys(G).length)J.audio={...Object.keys(Y).length?{input:Y}:{},...Object.keys(G).length?{output:G}:{}};return{...J,...Q.vendor}}function tQ(Q){let $={type:Q.type};if(Q.createResponse!==void 0)$.create_response=Q.createResponse;if(Q.interruptResponse!==void 0)$.interrupt_response=Q.interruptResponse;if(Q.type==="semantic_vad"){if(Q.eagerness!==void 0)$.eagerness=Q.eagerness}else{if(Q.threshold!==void 0)$.threshold=Q.threshold;if(Q.prefixPaddingMs!==void 0)$.prefix_padding_ms=Q.prefixPaddingMs;if(Q.silenceDurationMs!==void 0)$.silence_duration_ms=Q.silenceDurationMs;if(Q.idleTimeoutMs!==void 0)$.idle_timeout_ms=Q.idleTimeoutMs}return $}function FQ(Q){let $=Number(Q?.input_tokens??0),J=Number(Q?.output_tokens??0),Z={inputTokens:$,outputTokens:J,totalTokens:Number(Q?.total_tokens??$+J)},Y=Q?.input_token_details??Q?.input_tokens_details,G=Q?.output_token_details??Q?.output_tokens_details;if(typeof Y?.cached_tokens==="number")Z.cachedInputTokens=Y.cached_tokens;if(typeof Y?.audio_tokens==="number")Z.audioInputTokens=Y.audio_tokens;let B=Y?.cached_tokens_details?.audio_tokens;if(typeof B==="number")Z.cachedAudioInputTokens=B;if(typeof Y?.image_tokens==="number"&&Y.image_tokens>0)Z.imageInputTokens=Y.image_tokens;if(typeof G?.audio_tokens==="number")Z.audioOutputTokens=G.audio_tokens;return Z}class d extends Error{code;retryable;status;constructor(Q,$={}){super(Q.message,{cause:$.cause});if(this.name="RealtimeRequestError",this.code=Q.code,this.retryable=Q.retryable,$.status!==void 0)this.status=$.status}}var i5=60;class e{model;target;options;constructor(Q,$){this.target=Q,this.options=$,this.model=$.model}url(Q){return`${this.target.base}/realtime${Q}${this.target.query}`}sidebandUrl(Q){let $=this.target.base.replace(/^http(s?):/i,(Z,Y)=>`ws${Y}:`),J=this.target.query?`${this.target.query}&`:"?";return`${$}/realtime${J}call_id=${encodeURIComponent(Q)}`}async createCall(Q){let $=Q.flow??this.options.callFlow??"unified",J,Z;if($==="ephemeral")J={authorization:`Bearer ${(await this.clientSecret({session:Q.session,ttlSeconds:i5,signal:Q.signal})).value}`,"content-type":"application/sdp"},Z=Q.sdp;else{let X=new FormData;X.set("sdp",Q.sdp),X.set("session",JSON.stringify(t(Q.session??{},this.model))),J=await this.target.headers(),Z=X}if(Q.safetyIdentifier)J["OpenAI-Safety-Identifier"]=Q.safetyIdentifier;let Y=this.url("/calls"),G=await this.request(Q.webrtcFilter?`${Y}${Y.includes("?")?"&":"?"}webrtcfilter=on`:Y,{method:"POST",headers:J,body:Z},Q.signal),B=await G.text(),z=r5(G);if(!z)throw new d({code:"provider_error",message:"The provider started a realtime call but did not say which one (no Location).",retryable:!1});return{sdpAnswer:B,callId:z}}async clientSecret(Q={}){let $=Q.ttlSeconds??m5;if(!Number.isInteger($)||$<sQ||$>aQ)throw RangeError(`ttlSeconds must be a whole number from ${sQ} to ${aQ}, got ${$}.`);let J={...await this.target.headers(),"content-type":"application/json"};if(Q.safetyIdentifier)J["OpenAI-Safety-Identifier"]=Q.safetyIdentifier;let Y=await(await this.request(this.url("/client_secrets"),{method:"POST",headers:J,body:JSON.stringify({expires_after:{anchor:"created_at",seconds:$},session:t(Q.session??{},this.model)})},Q.signal)).json();if(typeof Y?.value!=="string")throw new d({code:"provider_error",message:"The provider answered a client secret request with no secret.",retryable:!1});return{value:Y.value,expiresAt:Number(Y.expires_at??0),session:Y.session,callsUrl:this.url("/calls")}}async hangup(Q,$={}){try{await this.request(this.url(`/calls/${encodeURIComponent(Q)}/hangup`),{method:"POST",headers:await this.target.headers()},$.signal)}catch(J){if(n5(J,Q))return;throw J}}sideband(Q,$={}){return new zQ({...$,callId:Q,url:this.sidebandUrl(Q),headers:this.target.headers,webSocket:$.webSocket??this.options.webSocket,hangup:()=>this.hangup(Q)})}async request(Q,$,J){try{return await g(Q,$,{maxRetries:this.target.maxRetries,timeoutMs:this.target.timeoutMs,retryTimeouts:!1,signal:J,fetchImpl:this.options.fetchImpl})}catch(Z){if(J?.aborted)throw Z;throw new d(M(Z),{cause:Z,...Z instanceof I?{status:Z.status}:{}})}}}function n5(Q,$){if(!(Q instanceof d)||Q.status!==404)return!1;let J=Q.cause instanceof I?Q.cause.body:void 0,Z=J?.error??J,Y=String(Z?.code??"").toLowerCase(),G=String(Z?.message??"").toLowerCase();if(Y.includes("call"))return!0;if(G.includes($.toLowerCase()))return!0;return/\bcall\b/.test(G)&&/not (be )?found|does not exist|no longer|ended/.test(G)}function r5(Q){let $=Q.headers.get("location");if(!$)return;let J=$.split("?")[0].replace(/\/+$/,""),Z=J.slice(J.lastIndexOf("/")+1);return Z?decodeURIComponent(Z):void 0}var s5={"response.audio_transcript.delta":"response.output_audio_transcript.delta","response.audio_transcript.done":"response.output_audio_transcript.done","response.text.delta":"response.output_text.delta","response.text.done":"response.output_text.done","response.audio.delta":"response.output_audio.delta","response.audio.done":"response.output_audio.done"};function a5(Q){if(typeof Q!=="string")return;let $;try{$=JSON.parse(Q)}catch{return}if(!$||typeof $!=="object"||typeof $.type!=="string")return;let J=s5[$.type];if(J)$.type=J;if($.type==="response.done"&&$.response?.usage)$.usage=FQ($.response.usage);if($.type==="conversation.item.input_audio_transcription.completed"&&$.usage)if($.usage.type==="duration"){let Z=Number($.usage.seconds);if(Number.isFinite(Z))$.transcriptionSeconds=Z}else $.transcriptionUsage=FQ($.usage);return $}var eQ=1,o5=500;function t5(Q,$){let J=globalThis.WebSocket;if(!J)throw Error("No global WebSocket: the realtime sideband needs Bun or Node 22+.");return new J(Q,{headers:$.headers})}class zQ{callId;ready;closed;init;socket;finalEvent;outbox=[];subscribers=new Set;listeners=new Set;backlog=[];closing=!1;finished=!1;everOpened=!1;failures=0;resolveReady;rejectReady;resolveClosed;constructor(Q){this.init=Q,this.callId=Q.callId,this.ready=new Promise(($,J)=>{this.resolveReady=$,this.rejectReady=J}),this.ready.catch(()=>{}),this.closed=new Promise(($)=>this.resolveClosed=$),this.open()}send(Q){if(this.finished||this.closing)return;let $=JSON.stringify(Q);if(this.socket?.readyState===eQ)this.socket.send($);else this.outbox.push($)}updateSession(Q){this.send({type:"session.update",session:t(Q)})}addItem(Q){this.send({type:"conversation.item.create",item:Q})}addNote(Q){this.addItem({type:"message",role:"system",content:[{type:"input_text",text:Q}]})}functionOutput(Q,$){this.addItem({type:"function_call_output",call_id:Q,output:typeof $==="string"?$:JSON.stringify($)})}createResponse(Q={}){let $={};if(Q.instructions!==void 0)$.instructions=Q.instructions;if(Q.toolChoice!==void 0)$.tool_choice=typeof Q.toolChoice==="string"?Q.toolChoice:{type:"function",name:Q.toolChoice.name};if(Q.outputModalities)$.output_modalities=Q.outputModalities;if(Q.conversation)$.conversation=Q.conversation;if(Q.metadata)$.metadata=Q.metadata;Object.assign($,Q.vendor),this.send(Object.keys($).length?{type:"response.create",response:$}:{type:"response.create"})}cancelResponse(Q){this.send(Q?{type:"response.cancel",response_id:Q}:{type:"response.cancel"})}on(Q){return this.listeners.add(Q),()=>this.listeners.delete(Q)}[Symbol.asyncIterator](){let Q={queue:this.backlog??[],done:this.finished};return this.backlog=void 0,this.subscribers.add(Q),{next:async()=>{for(;;){let J=Q.queue.shift();if(J)return{value:J,done:!1};if(Q.done)return this.subscribers.delete(Q),{value:void 0,done:!0};await new Promise((Z)=>Q.wake=Z),Q.wake=void 0}},return:async()=>{return Q.done=!0,Q.queue.length=0,this.subscribers.delete(Q),{value:void 0,done:!0}}}}close(Q=1000,$="closed"){if(this.finished||this.closing)return;if(this.closing=!0,this.socket&&this.socket.readyState<=eQ)this.socket.close(Q,$);else this.finish(Q,$,!0)}async hangup(){try{await this.init.hangup()}catch(Q){if(this.finalEvent&&!this.finalEvent.byClient&&this.finalEvent.code===1000)return;throw Q}this.close(1000,"hangup")}async open(){let Q;try{let J=await this.init.headers();if(this.closing)return this.finish(1000,"closed",!0);Q=(this.init.webSocket??t5)(this.init.url,{headers:J})}catch(J){return this.dropped(1006,J instanceof Error?J.message:String(J),!1)}this.socket=Q;let $=!1;Q.addEventListener("open",()=>{$=!0;let J=this.everOpened;this.everOpened=!0;let Z=this.failures;this.failures=0;for(let Y of this.outbox.splice(0))Q.send(Y);if(this.resolveReady(),J)this.emit({type:"sideband.reconnected",attempt:Z})}),Q.addEventListener("message",(J)=>{let Z=a5(J.data);if(Z)this.emit(Z)}),Q.addEventListener("close",(J)=>{if(this.socket!==Q)return;this.dropped(J.code??1006,J.reason??"",$)}),Q.addEventListener("error",()=>{})}dropped(Q,$,J){if(this.socket=void 0,this.closing)return this.finish(Q,$,!0);let Z=this.init.reconnect?.attempts??3;if(!((Q!==1000||!J)&&this.failures<Z))return this.finish(Q,$,!1);this.failures+=1;let G=(this.init.reconnect?.delayMs??500)*2**(this.failures-1);setTimeout(()=>void this.open(),G)}finish(Q,$,J){if(this.finished)return;this.finished=!0,this.outbox.length=0;let Z={type:"sideband.closed",code:Q,reason:$,byClient:J};this.finalEvent=Z,this.emit(Z);for(let Y of this.subscribers)Y.done=!0,Y.wake?.();if(!this.everOpened)this.rejectReady(Error(`Realtime sideband did not open (${Q} ${$}).`));this.resolveClosed(Z)}emit(Q){if(this.backlog){if(this.backlog.push(Q),this.backlog.length>o5)this.backlog.shift()}for(let $ of this.subscribers){if($.done)continue;$.queue.push(Q),$.wake?.()}for(let $ of this.listeners)try{$(Q)}catch{}}}var J5=3;function CQ(Q){let $=new Map;for(let J of Q)for(let Z of J.content??[]){if(Z.type!=="file"||!Z.fileId||$.has(Z.fileId))continue;$.set(Z.fileId,{name:Z.name,mimeType:Z.mimeType})}return $}function Z5(Q,$,J=new Map){if(!($ instanceof I))return[];if($.status!==400&&$.status!==404)return[];let Z=UQ($.body);if(!Z)return[];let Y=e5(Q.input);if(Y.length===0)return[];let G=/^input\[(\d+)\]\.content\[(\d+)\]\.file_id$/.exec(Z.param??"");if(G){let K=Q.input[Number(G[1])],j=LQ(K)[Number(G[2])],H=j&&typeof j.file_id==="string"?j.file_id:void 0;if(H)return[H]}let B=Z.message??"",z=$5(Y.map((K)=>K.fileId).filter((K)=>Q6(B,K)));if(z.length>0)return z;let X=/Expected (image type|context stuffing file type) to be a supported format:.*but got \.([a-z0-9]+)\.?\s*$/is.exec(B);if(X){let K=X[1].toLowerCase()==="image type"?"input_image":"input_file",j=X[2].toLowerCase(),H=$5(Y.filter((W)=>W.type===K).map((W)=>W.fileId)),V=H.filter((W)=>(J.get(W)?.name??"").trim().toLowerCase().endsWith(`.${j}`));if(V.length===1)return V;if(V.length===0&&H.length===1)return H}return[]}function Y5(Q,$,J=new Map){return{...Q,input:Q.input.map((Z)=>{let Y=LQ(Z);if(!Y.some((G)=>Q5(G,$)))return Z;return{...Z,content:Y.map((G)=>Q5(G,$)?{type:"input_text",text:p(J.get(String(G.file_id))?.name)}:G)}})}}function p(Q){return`[${Q?`attachment ${JSON.stringify(Q)}`:"an attachment"} could not be read by the provider and is not shown to you. Tell the user if it matters to the answer; uploading it again may help.]`}function Q5(Q,$){return typeof Q.file_id==="string"&&$.has(Q.file_id)}function LQ(Q){let $=Q?.content;return Array.isArray($)?$:[]}function e5(Q){let $=[];for(let J of Q)for(let Z of LQ(J))if(typeof Z.file_id==="string"&&Z.file_id)$.push({type:String(Z.type),fileId:Z.file_id});return $}function UQ(Q){if(!Q||typeof Q!=="object")return null;let $=Q,J=$.error&&typeof $.error==="object"?$.error:Q;return{message:typeof J.message==="string"?J.message:void 0,param:typeof J.param==="string"?J.param:void 0}}function Q6(Q,$){let J=$.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return new RegExp(`(^|[^A-Za-z0-9_-])${J}($|[^A-Za-z0-9_-])`).test(Q)}function $5(Q){return[...new Set(Q)]}function G5(Q,$){if(!($ instanceof I))return null;if($.status!==400&&$.status!==404)return null;let J=Q?.input;if(!Array.isArray(J))return null;let Z=UQ($.body)?.message??"",Y=/Item with id '([^']+)' not found/i.exec(Z)?.[1];if(!Y)return null;let G=(B)=>B?.type==="reasoning";if(!J.some((B)=>G(B)&&B.id===Y))return null;return{...Q,input:J.filter((B)=>!G(B))}}async function*DQ(Q){let $="",J="",Z=[],Y,G=()=>{if(Z.length===0&&!J)return null;let X={event:J,data:Z.join(`
3
+ `),id:Y};return J="",Z=[],Y=void 0,X.data?X:null},B=(X)=>{let K=X.endsWith("\r")?X.slice(0,-1):X;if(K==="")return G();if(K.startsWith(":"))return null;let j=K.indexOf(":"),H=j===-1?K:K.slice(0,j),V=j===-1?"":K.slice(j+1);if(V.startsWith(" "))V=V.slice(1);if(H==="event")J=V;else if(H==="data")Z.push(V);else if(H==="id")Y=V;return null};for await(let X of Q){$+=X;let K=$.indexOf(`
4
+ `);while(K!==-1){let j=$.slice(0,K);$=$.slice(K+1);let H=B(j);if(H)yield H;K=$.indexOf(`
5
+ `)}}if($.length>0){let X=B($);if(X)yield X}let z=G();if(z)yield z}async function*V5(Q,$={}){let J=new Map,Z=new Set,Y,G=!1,B,z=(X,K)=>({type:"finish",reason:X,usage:K,...B?{model:B}:{}});for await(let X of DQ(Q)){if(X.data==="[DONE]")break;let K;try{K=JSON.parse(X.data)}catch{continue}let j=typeof K.type==="string"?K.type:X.event,H=K.response?.model;if(typeof H==="string"&&H)B=H;switch(j){case"response.output_text.delta":{let V=String(K.delta??"");if(!V)break;yield $.structuredOutput?{type:"output-delta",delta:V}:{type:"text-delta",delta:V};break}case"response.reasoning_summary_text.delta":case"response.reasoning_text.delta":{let V=String(K.delta??"");if(!V)break;yield{type:"reasoning-delta",delta:V,id:K.item_id};break}case"response.output_item.added":{let V=K.item;if(!V)break;if(V.type==="function_call"){let W=String(V.id??K.item_id??V.call_id??"");J.set(W,{callId:String(V.call_id??W),name:String(V.name??""),namespace:typeof V.namespace==="string"&&V.namespace?V.namespace:void 0,done:!1})}break}case"response.function_call_arguments.delta":{let V=J.get(String(K.item_id??""));if(!V)break;let W=String(K.delta??"");if(!W)break;yield{type:"tool-call-delta",toolCallId:V.callId,name:V.name,argsDelta:W,...V.namespace?{namespace:V.namespace}:{}};break}case"response.function_call_arguments.done":{let V=String(K.item_id??""),W=J.get(V);if(!W)break;W.done=!0,yield{type:"tool-call",toolCallId:W.callId,name:W.name,args:String(K.arguments??""),...W.namespace?{namespace:W.namespace}:{}};break}case"response.output_item.done":{let V=K.item;if(!V)break;if(V.type==="function_call"){let W=String(V.id??K.item_id??V.call_id??""),q=J.get(W);if(q?.done)break;let C=(typeof V.namespace==="string"?V.namespace:"")||q?.namespace;if(yield{type:"tool-call",toolCallId:String(V.call_id??W),name:String(V.name??q?.name??""),args:String(V.arguments??""),...C?{namespace:C}:{}},q)q.done=!0;break}if(V.type==="tool_search_call"||V.type==="tool_search_output"){if(V.type==="tool_search_call"&&V.arguments!==void 0)Y=V.arguments;let W=$6(V);if(W.loaded.length===0&&W.namespaces.length===0)break;let q=String(V.tool_search_call_id??V.id??"");if(Z.has(q))break;Z.add(q);let C=Y;Y=void 0,yield{type:"tool-search",...W,...C!==void 0&&C!==null?{arguments:C}:{}}}break}case"response.refusal.done":{yield{type:"error",error:{code:"content_filtered",message:String(K.refusal??"The model refused to answer."),retryable:!1}};break}case"response.completed":{G=!0,yield z("stop",NQ(K.response?.usage));break}case"response.incomplete":{G=!0;let V=NQ(K.response?.usage),W=K.response?.incomplete_details?.reason;if(W==="content_filter"){yield{type:"error",error:{code:"content_filtered",message:J6(K.response?.content_filters),retryable:!1}},yield z("error",V);break}yield z(W==="max_output_tokens"?"length":"stop",V);break}case"response.failed":case"error":{G=!0;let V=K.response?.error??K.error??K;yield{type:"error",error:Z6(V),...QQ(V)},yield z("error",NQ(K.response?.usage));break}}if(G)return}if(!G)yield{type:"error",error:{code:"provider_error",message:"The provider stream ended without a terminal event.",retryable:!0}},yield z("error",R())}function $6(Q){let $=[],J=[];return B5(Q.results??Q.tools??Q.loaded??Q.output,$,J,0),{loaded:PQ($),namespaces:PQ(J)}}function B5(Q,$,J,Z){if(!Array.isArray(Q)||Z>4)return;for(let Y of Q){if(typeof Y==="string"){$.push(Y);continue}if(!Y||typeof Y!=="object")continue;let G=Y,B=typeof G.name==="string"?G.name:typeof G.tool_name==="string"?G.tool_name:"",z=G.tools??G.functions;if(Array.isArray(z)){if(B)J.push(B);B5(z,$,J,Z+1);continue}if(B)$.push(B)}}function PQ(Q){return Q.filter(($,J)=>Q.indexOf($)===J)}function J6(Q){if(!Array.isArray(Q))return"The provider's content filter blocked this request.";let J=[];for(let Z of Q){if(!Z||typeof Z!=="object")continue;let Y=Z,G=Y.content_filter_results;if(!G||typeof G!=="object")continue;for(let[B,z]of Object.entries(G))if(z&&typeof z==="object"&&z.filtered===!0)J.push(`${B} (${String(Y.source_type??"unknown")})`)}return J.length===0?"The provider's content filter blocked this request.":`The provider's content filter blocked this request. Categories: ${PQ(J).join(", ")}.`}function Z6(Q){let $=typeof Q?.message==="string"?Q.message:"The provider stream failed.",J=String(Q?.code??"").toLowerCase();if(J==="rate_limit_exceeded")return{code:"rate_limited",message:$,retryable:!0};if(J==="context_length_exceeded")return{code:"context_length_exceeded",message:$,retryable:!1};if(J.includes("content_filter"))return{code:"content_filtered",message:$,retryable:!1};return{code:"provider_error",message:$,retryable:!0}}function R(){return{inputTokens:0,outputTokens:0,totalTokens:0}}function NQ(Q){if(!Q)return R();let $=Number(Q.input_tokens??0),J=Number(Q.output_tokens??0),Z={inputTokens:$,outputTokens:J,totalTokens:Number(Q.total_tokens??$+J)},Y=Q.output_tokens_details?.reasoning_tokens;if(typeof Y==="number")Z.reasoningTokens=Y;let G=Q.input_tokens_details?.cached_tokens;if(typeof G==="number")Z.cachedInputTokens=G;return Z}async function*K5(Q){if(!Q)return;let $=Q.getReader(),J=new TextDecoder;try{while(!0){let{done:Y,value:G}=await $.read();if(Y)break;if(G)yield J.decode(G,{stream:!0})}let Z=J.decode();if(Z)yield Z}finally{$.releaseLock()}}function ZQ(Q){return{responsesUrl:`${Q.base}/responses${Q.query}`,filesUrl:`${Q.base}/files${Q.query}`,headers:Q.headers,timeoutMs:Q.timeoutMs,streamIdleTimeoutMs:Q.streamIdleTimeoutMs,streamMaxDurationMs:Q.streamMaxDurationMs,maxToolArgumentChars:Q.maxToolArgumentChars,maxToolArgumentWhitespace:Q.maxToolArgumentWhitespace,maxRetries:Q.maxRetries,...Q.retry?{retry:Q.retry}:{}}}async function*YQ(Q,$,J){let Z=J.parse??V5,Y=$,G=new Set,B=0,z=!1,X=Math.max(0,Q.maxRetries),K=Q.random??Math.random,j,H=(U)=>{if(!j)return U;let O=$Q($Q(R(),j),U.usage);return j=void 0,{...U,usage:O}},V=()=>H({type:"finish",reason:"aborted",usage:R()}),W=Q.streamIdleTimeoutMs??0,q=Q.streamMaxDurationMs??0,C=Q.maxToolArgumentChars??0,P=Q.maxToolArgumentWhitespace??0,D=Q.now??Date.now,c=D();for(let U=0;;U++){let O=new AbortController,i=J.signal?AbortSignal.any([J.signal,O.signal]):O.signal,y;while(y===void 0)try{let L=[],F=()=>{},N=g(Q.responsesUrl,{method:"POST",headers:{...await Q.headers(),"content-type":"application/json"},body:JSON.stringify(Y)},{maxRetries:Q.maxRetries,timeoutMs:Q.timeoutMs,signal:i,fetchImpl:Q.fetchImpl,sleep:Q.sleep,random:Q.random,now:Q.now,startedAt:c,...Q.retry?{retry:Q.retry}:{},onRetry:(_)=>{L.push({type:"retry",..._,phase:"request"}),F()}}),T=N.then(()=>!0,()=>!0);for(;;){let _=new Promise((b)=>F=()=>b(!1)),k=await Promise.race([T,_]);if(yield*L.splice(0),k)break}y=await N}catch(L){let F=Y,N=J.files&&B<J5?Z5(F,L,J.files).filter((k)=>!G.has(k)):[];if(N.length>0){B++;let k=M(L).message;for(let b of N)G.add(b),yield{type:"file-rejected",fileId:b,message:k,...h(L)};Y=Y5(F,new Set(N),J.files);continue}let T=z?null:G5(Y,L);if(T){z=!0,Y=T;continue}let _=M(L);if(_.code==="aborted"){yield V();return}yield{type:"error",error:_,...h(L)},yield H({type:"finish",reason:"error",usage:R()});return}let S=[],E=!1,f,WQ=!1,A,w=new Map,dQ,n;try{let L=rQ(y.body,{idleMs:W,maxMs:q},{idle:()=>{let F=new X5(W);return O.abort(F),F},max:()=>{let F=new H5(q);return O.abort(F),F}});for await(let F of Z(K5(L),{structuredOutput:J.structuredOutput,onUsage:(N)=>dQ=N})){if(F.type==="tool-call-delta"){let N=w.get(F.toolCallId);if(!N)w.set(F.toolCallId,N=Y6());G6(N,F.argsDelta,P>0);let T=N.chars;if(P>0&&N.space>P){let _=N.text.trimEnd(),k=V6(_);if(B6(F.name,F.toolCallId,T,N.space,P,k),!k){let b=new j5(P,F.name,F.toolCallId,T,N.space);throw O.abort(b),b}w.delete(F.toolCallId),n={type:"tool-call",toolCallId:F.toolCallId,name:F.name,args:_,...F.namespace?{namespace:F.namespace}:{}};break}if(C>0&&T>C){let _=new xQ(C,F.name,F.toolCallId,T);throw O.abort(_),_}yield F;continue}if(F.type==="tool-call")w.delete(F.toolCallId);if(E){yield F.type==="finish"?H(F):F;continue}if(JQ(F)){E=!0,yield*S.splice(0),yield F;continue}if(F.type==="error")f=F.error;S.push(F)}if(n)await L?.cancel().catch(()=>{})}catch(L){WQ=L instanceof o;let F=M(L);if(F.code==="aborted"||J.signal?.aborted){yield V();return}if(L instanceof xQ)A=L.detail;if(E){yield{type:"error",error:F,...A?{toolArgumentsTooLong:A}:{}},yield H({type:"finish",reason:"error",usage:R()});return}f=F,S.push({type:"error",error:F,...A?{toolArgumentsTooLong:A}:{}},{type:"finish",reason:"error",usage:R()})}if(n){if(O.abort(),!E)yield*S.splice(0);if(yield n,w.size>0)yield{type:"tool-call-discard",toolCallIds:[...w.keys()]};yield H({type:"finish",reason:"stop",usage:dQ??R()});return}if(E)return;let r={};for(let L of S)if(L.type==="error")r=h(L);let s=!f?.retryable||J.signal?.aborted||A&&J.retryToolArgumentsTooLong===!1?void 0:U<X?a(U,K):Q.retry&&XQ(Q.retry,f,{...r.status!==void 0?{status:r.status}:{},timedOut:WQ,...A?{toolArgumentsTooLong:A}:{}})?HQ(Q.retry,U-X,f.retryAfter,D()-c,K):void 0;if(s!==void 0){for(let F of S)if(F.type==="finish")j=$Q(j??R(),F.usage);if(w.size>0)yield{type:"tool-call-discard",toolCallIds:[...w.keys()]};let L=D()-c;yield{type:"retry",attempt:U+1,maxRetries:X,error:f,...r,phase:"stream",timedOut:WQ,...A?{toolArgumentsTooLong:A}:{},delayMs:s,elapsedMs:L,...Q.retry?{remainingMs:Math.max(0,Q.retry.patienceMs-L-s)}:{}};try{await jQ(s,J.signal,Q.sleep)}catch{yield V();return}continue}for(let L of S)yield L.type==="finish"?H(L):L;return}}function Y6(){return{chars:0,text:"",inString:!1,escaped:!1,space:0}}function G6(Q,$,J){if(Q.chars+=$.length,!J)return;Q.text+=$;for(let Z of $){if(Q.inString){if(Q.escaped)Q.escaped=!1;else if(Z==="\\")Q.escaped=!0;else if(Z==='"')Q.inString=!1}else if(Z===" "||Z===`
6
+ `||Z==="\r"||Z==="\t"){Q.space++;continue}else if(Z==='"')Q.inString=!0;Q.space=0}}function V6(Q){try{return JSON.parse(Q),!0}catch{return!1}}function B6(Q,$,J,Z,Y,G){let B=`[gemi/ai] tool call "${Q}" ran away in white space (more than ${Y} characters, maxToolArgumentWhitespace); ${G?"its arguments were whole JSON, so it was finished as written":"its arguments were not whole JSON, so it was cut"}`,z={tool:Q,toolCallId:$,chars:J,whitespace:Z,limit:Y,whole:G},X=!1;try{W5.warning(B,z),X=!0}catch{}if(!X||Bun.env.NODE_ENV==="development")console.warn(B,z)}async function GQ(Q,$,J="user_data"){let Z=new FormData;if(J)Z.set("purpose",J);Z.set("file",$);let G=await(await g(Q.filesUrl,{method:"POST",headers:await Q.headers(),body:Z},{maxRetries:Q.maxRetries,timeoutMs:Q.timeoutMs,fetchImpl:Q.fetchImpl})).json();if(!G?.id)throw Error("The provider accepted the upload but returned no file id.");return G.id}async function VQ(Q,$){let J=Q.filesUrl.indexOf("?"),Z=J===-1?Q.filesUrl:Q.filesUrl.slice(0,J),Y=J===-1?"":Q.filesUrl.slice(J);try{await(await g(`${Z}/${encodeURIComponent($)}${Y}`,{method:"DELETE",headers:await Q.headers()},{maxRetries:Q.maxRetries,timeoutMs:Q.timeoutMs,fetchImpl:Q.fetchImpl,...Q.sleep?{sleep:Q.sleep}:{},...Q.random?{random:Q.random}:{}})).body?.cancel()}catch(G){if(G instanceof I&&G.status===404)return;throw G}}function MQ(Q,$){let{capabilities:J}=$,Z={model:$.model,input:K6(Q.messages,J,Q.tools),stream:!0};if(Q.systemPrompt)Z.instructions=Q.systemPrompt;let Y=L6(Q.tools,J);if(Y.length>0){if(Z.tools=Y,!J.parallelToolCalls)Z.parallel_tool_calls=!1;if(Q.toolChoice!==void 0)Z.tool_choice=typeof Q.toolChoice==="string"?Q.toolChoice:{type:"function",name:Q.toolChoice.name}}if(Q.output)Z.text={format:{type:"json_schema",name:Q.output.name,schema:Q.output.schema,strict:Q.output.strict}};if(Q.reasoning&&J.reasoning)Z.reasoning=Q.reasoning==="none"?{effort:"none"}:{effort:Q.reasoning,summary:"auto"};if(typeof Q.temperature==="number")Z.temperature=Q.temperature;if(typeof Q.maxOutputTokens==="number")Z.max_output_tokens=Q.maxOutputTokens;if(Q.promptCacheKey)Z.prompt_cache_key=Q.promptCacheKey;return Z}function K6(Q,$,J){let Z=[],Y=new Map;if($.toolSearch){for(let G of J??[])if(BQ(G))Y.set(G.name,G)}for(let G of Q){let B=G.role,z=!q6.has(G.finishReason),X=[],K=()=>{if(X.length===0)return;Z.push({type:"message",role:B,content:X}),X=[]};for(let j of G.content??[])switch(j.type){case"text":{if(!j.text)break;X.push(u(B,j.text));break}case"output":{if(j.partial)break;X.push(u(B,JSON.stringify(j.value)));break}case"file":{if(B==="assistant")break;let H=SQ(j);if(!$.fileInput){if(H)X.push(u(B,l(j,!1)));break}if(RQ(j,H),j.providerRejected){if(H)X.push(u(B,l(j,!1)));X.push(u(B,p(j.name)));break}if(H)X.push(u(B,l(j,!!j.fileId)));if(j.fileId)X.push(H6(j));break}case"reasoning":{if(K(),!z)break;let H=F6(j);if(H)Z.push(H);break}case"tool-call":{if(j.partial)break;if(K(),$.toolSearch&&Array.isArray(j.toolSearches))for(let V of j.toolSearches)Z.push(...C6(V,J??[]));let H={type:"function_call",call_id:j.toolCallId,name:String(j.name),arguments:JSON.stringify(j.input??{})};if(j.namespace&&Y.has(j.namespace))H.namespace=j.namespace;Z.push(H);break}case"tool-result":{K(),Z.push({type:"function_call_output",call_id:j.toolCallId,output:IQ(j)});break}}K()}return X6(Z)}var W6="No result was recorded for this tool call. Assume it did not complete.";function X6(Q){let $=new Set,J=new Set,Z=[];for(let G of Q){if(G.type==="function_call"){let B=String(G.call_id);if($.has(B))continue;$.add(B)}else if(G.type==="function_call_output"){let B=String(G.call_id);if(!$.has(B)||J.has(B))continue;J.add(B)}Z.push(G)}if(J.size===$.size)return Z;let Y=[];for(let G of Z){if(Y.push(G),G.type!=="function_call")continue;let B=String(G.call_id);if(J.has(B))continue;J.add(B),Y.push({type:"function_call_output",call_id:B,output:W6})}return Y}function u(Q,$){return{type:Q==="assistant"?"output_text":"input_text",text:$}}function SQ(Q){let $=Q.attachmentId;return typeof $==="string"&&$.startsWith(OQ)?$:void 0}function l(Q,$){let J=[`id=${JSON.stringify(Q.attachmentId)}`];if(Q.name)J.push(`name=${JSON.stringify(Q.name)}`);if(Q.mimeType)J.push(`mimeType=${JSON.stringify(Q.mimeType)}`);let Z=`attachment ${J.join(" ")}`;return $?`[${Z}]`:`[${Z} \u2014 its contents are not shown to you; a tool can read the file by this id]`}function H6(Q){return{type:_Q(Q)?"input_image":"input_file",file_id:Q.fileId}}function _Q(Q){let $=Q.mimeType?.trim().toLowerCase()??"";return $?$.startsWith("image/")&&$!=="image/svg+xml":j6(Q.name)}function RQ(Q,$){if(Q.fileId?.startsWith(OQ))throw Error(`FilePart.fileId holds a gemi attachment id (${Q.fileId}). That field is the *provider's* file id, from \`fileId\` on the upload response; the \`attachmentId\` goes in \`FilePart.attachmentId\`, is shown to the model as text, and is resolved by a tool through \`ctx.attachments\`.`);if(!Q.fileId&&!$)throw Error("FilePart.fileId is empty and there is no `attachmentId` either. `fileId` is the *provider's* file id and `attachmentId` is gemi's (`gemi_att_\u2026`), both from the upload response; an upload always answers at least one, so a part with neither was built from something other than that answer.")}function j6(Q){let $=/\.([a-z0-9]+)$/.exec(Q?.trim().toLowerCase()??"");return $?.[1]!==void 0&&z6.has($[1])}var z6=new Set(["jpeg","jpg","png","gif","webp"]),q6=new Set(["error","aborted","interrupted"]);function F6(Q){if(!Q.id)return null;let $={type:"reasoning",id:Q.id};return $.summary=Q.text?[{type:"summary_text",text:Q.text}]:[],$}function IQ(Q){if(Q.status==="ok"){let $=Q.modelOutput!==void 0?Q.modelOutput:Q.output;return typeof $==="string"?$:JSON.stringify($??null)}if(Q.status==="running"){let $=Q.job?.summary===void 0?"":` Started with: ${JSON.stringify(Q.job.summary)}.`;return`Started background job ${Q.job?.id??"(unknown)"}. It is still running, so there is no result yet: this message will be replaced by the result when it finishes. Do not start it again.${$}`}if(Q.status==="denied"){let $=Q.reason?` Reason given: ${Q.reason}`:"";if(Q.cause==="stopped")return`The run was stopped before this tool call could complete, so it did not run.${$}`;if(Q.cause==="interrupted")return`The run was interrupted (the server stopped) while this tool call was in progress, so its result was lost. It may have run in part or in full: check its effects before repeating it.${$}`;if(Q.cause==="denied-earlier")return`The user already declined this tool call earlier in this conversation, so it did not run and they were not asked again. Do not ask for it again; carry on without it.${$}`;return`The user declined this tool call, so it did not run.${$}`}return`The tool call failed and produced no result. Error (${Q.error?.code??"unknown"}): ${Q.error?.message??"no message"}`}function C6(Q,$){let J=new Set(z5(Q?.loaded)),Z=z5(Q?.namespaces),Y=new Set(Z),G=[];for(let z of $)if(BQ(z)){if(!Y.has(z.name))continue;let X=z.tools.filter((K)=>J.size===0||J.has(K.name));if(X.length===0)continue;G.push({type:"namespace",name:z.name,description:z.description,tools:X.map((K)=>m(K,!0))})}else if(z.deferred&&J.has(z.name))G.push(m(z,!0));if(G.length===0)return[];return[{type:"tool_search_call",call_id:null,execution:"server",status:"completed",arguments:Q.arguments&&typeof Q.arguments==="object"?Q.arguments:{paths:Z.length>0?Z:[...J]}},{type:"tool_search_output",call_id:null,execution:"server",status:"completed",tools:G}]}function z5(Q){return Array.isArray(Q)?Q.filter(($)=>typeof $==="string"):[]}function BQ(Q){return Array.isArray(Q.tools)}function L6(Q,$){if(!Q||Q.length===0)return[];if(!$.toolSearch){let Y=[];for(let G of Q)if(BQ(G))for(let B of G.tools)Y.push(m(B,!1));else Y.push(m(G,!1));return Y}let J=[],Z=!1;for(let Y of Q)if(BQ(Y)){let G=Y.tools.map((B)=>{if(B.deferred)Z=!0;return m(B,!0)});J.push({type:"namespace",name:Y.name,description:Y.description,tools:G})}else{if(Y.deferred)Z=!0;J.push(m(Y,!0))}if(Z)J.push({type:"tool_search"});return J}function m(Q,$){let J={type:"function",name:Q.name,description:Q.description,parameters:Q.parameters,strict:Q.strict};if($&&Q.deferred)J.defer_loading=!0;return J}var U6=64000;function q5(Q,$){let J={model:$.model,max_tokens:Q.maxOutputTokens??U6,messages:A6(Q.messages,$.capabilities),stream:!0},Z=Q.output,Y=!!Z?.strict&&!_6(Z.schema),G=Z&&!Y?R6(Z.schema):void 0,B=[Q.systemPrompt,G].filter(Boolean);if(B.length>0)J.system=[{type:"text",text:B.join(`
7
+
8
+ `)}];let z=$.capabilities.reasoning?Q.reasoning:void 0;if(z==="none"){if(/^claude-sonnet-5-5(?:-\d{8})?$/.test($.modelId))J.thinking={type:"between_tools"};J.output_config={effort:"low"}}else if(z)J.thinking={type:"adaptive",display:"summarized"},J.output_config={effort:P6(z,$.modelId)};else if($.capabilities.reasoning&&N6(J.messages))J.thinking={type:"adaptive"};if(J.thinking?.type==="adaptive"&&$.blockBinding)J.thinking.block_binding={prefix_mismatch_behavior:"drop_block"};if(Z&&Y)J.output_config={...J.output_config,format:{type:"json_schema",schema:S6(Z.schema)}};let X=g6(Q.tools);if(X.length>0){J.tools=X;let K=I6(Q.toolChoice,$.forcedToolChoice);if(!$.capabilities.parallelToolCalls)K.disable_parallel_tool_use=!0;if(Q.toolChoice!==void 0||K.disable_parallel_tool_use)J.tool_choice=K}return D6(J)}function N6(Q){return Q.some(($)=>$.content.some((J)=>J.type==="thinking"||J.type==="redacted_thinking"))}var AQ="thinking-binding-controls-2026-08-01";function F5(Q){if(/bound to a different conversation|Invalid `signature` in `thinking` block/i.test(Q))return"thinking";if(/schema is too complex/i.test(Q))return"schema";return}function C5(Q){let $=[];for(let J of Q.messages){let Z=J.content.filter((G)=>G.type!=="thinking"&&G.type!=="redacted_thinking");if(Z.length===0)continue;let Y=$.at(-1);if(Y?.role===J.role)Y.content.push(...Z);else $.push({role:J.role,content:Z})}return{...Q,messages:$}}function P6(Q,$){if(Q==="none"||Q==="minimal")return"low";if(Q==="xhigh"&&/^claude-(?:opus|sonnet)-4-6(?:-|$)/.test($))return"high";return Q}function D6(Q){let $=(Z)=>{if(Z)Z.cache_control={type:"ephemeral"}};$(Q.tools?.at(-1)),$(Q.system?.at(-1));let J=Q.messages.at(-1)?.content??[];return $([...J].reverse().find((Z)=>Z.type!=="thinking"&&Z.type!=="redacted_thinking")),Q}var x6=new Set(["minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf","minLength","maxLength","maxItems","uniqueItems"]),O6=new Set(["date-time","time","date","duration","email","hostname","uri","ipv4","ipv6","uuid"]),M6=/\\[1-9]|\(\?<?[=!]|\\[bB]/,L5=new Set(["properties","patternProperties","$defs","definitions"]);function S6(Q){let $=(J)=>{if(Array.isArray(J))return J.map($);if(!v(J))return J;let Z={},Y=[];for(let[G,B]of Object.entries(J)){if(x6.has(G)||G==="minItems"&&typeof B==="number"&&B>1||G==="format"&&typeof B==="string"&&!O6.has(B)||G==="pattern"&&typeof B==="string"&&M6.test(B)){Y.push(`${G}: ${JSON.stringify(B)}`);continue}Z[G]=L5.has(G)&&v(B)?Object.fromEntries(Object.entries(B).map(([X,K])=>[X,$(K)])):$(B)}if(Y.length>0){let G=`{${Y.join(", ")}}`;Z.description=typeof Z.description==="string"?`${Z.description} ${G}`:G}if(Z.type==="object"||v(Z.properties))Z.additionalProperties=!1;return Z};return $(Q)}function _6(Q){let $=0,J=0,Z=(Y)=>{if(Array.isArray(Y))return Y.forEach(Z);if(!v(Y))return;if(Array.isArray(Y.anyOf)||Array.isArray(Y.type))J++;if(v(Y.properties)){let G=new Set(Array.isArray(Y.required)?Y.required:[]);$+=Object.keys(Y.properties).filter((B)=>!G.has(B)).length}for(let[G,B]of Object.entries(Y))if(L5.has(G)&&v(B))Object.values(B).forEach(Z);else Z(B)};return Z(Q),$>24||J>16}function R6(Q){return`Answer with only a JSON value (no prose, no code fence) that matches this JSON schema:
9
+ ${JSON.stringify(Q)}`}function I6(Q,$){if(Q==="none")return{type:"none"};if(Q==="required")return $?{type:"any"}:{type:"auto"};if(Q&&typeof Q==="object")return $?{type:"tool",name:Q.name}:{type:"auto"};return{type:"auto"}}function A6(Q,$){let J=[],Z=new Map;for(let j of Q){let H=j.role==="assistant"?"assistant":"user";J.push("step-end");for(let V of j.content??[])switch(V.type){case"text":{if(H==="assistant"?!!V.text:!!V.text?.trim())J.push({role:H,block:{type:"text",text:V.text}});break}case"output":{if(V.partial)break;let W=V.text??JSON.stringify(V.value);J.push({role:H,block:{type:"text",text:W}});break}case"file":{if(H==="assistant")break;for(let W of b6(V,$))J.push({role:H,block:W});break}case"reasoning":{let W=H==="assistant"?v6(V):void 0;if(W)J.push({role:H,block:W});break}case"tool-call":{if(V.partial)break;J.push({role:"assistant",block:{type:"tool_use",id:V.toolCallId,name:String(V.name),input:v(V.input)?V.input:{}}});break}case"tool-result":{if(J.push("step-end"),Z.has(V.toolCallId))break;Z.set(V.toolCallId,{type:"tool_result",tool_use_id:V.toolCallId,content:IQ(V),...V.status==="error"?{is_error:!0}:{}});break}}}let Y=[],G=(j,H)=>{let V=Y[Y.length-1];if(V&&V.role===j)V.content.push(H);else Y.push({role:j,content:[H]})},B=new Set,z=[],X=!1,K=()=>{for(let j of z)G("user",Z.get(j)??k6(j));z=[],X=!1};for(let j of J){if(j==="step-end"){X=!0;continue}let{role:H,block:V}=j;if(X||H==="user")K();if(V.type==="tool_use"){let W=String(V.id);if(B.has(W))continue;B.add(W),z.push(W)}G(H,V)}if(K(),Y[0]?.role==="assistant")Y.unshift({role:"user",content:[{type:"text",text:T6}]});if(Y.at(-1)?.role==="assistant")Y.push({role:"user",content:[{type:"text",text:E6}]});return Y}var T6="(The conversation continues from an earlier point.)",E6="Continue.",w6="No result was recorded for this tool call. Assume it did not complete.";function k6(Q){return{type:"tool_result",tool_use_id:Q,content:w6}}function v6(Q){let $=Q.providerMetadata?.anthropic;if(!v($))return;if($.type==="thinking"&&typeof $.signature==="string")return{type:"thinking",thinking:Q.text??"",signature:$.signature};if($.type==="redacted_thinking"&&typeof $.data==="string")return{type:"redacted_thinking",data:$.data};return}function b6(Q,$){let J=SQ(Q),Z=(G)=>J?[{type:"text",text:l(Q,G)}]:[];if(!$.fileInput)return Z(!1);if(RQ(Q,J),!Q.fileId)return Z(!1);let Y=Q.providerRejected?void 0:y6(Q);if(!Y)return[...Z(!1),{type:"text",text:p(Q.name)}];return[...Z(!0),{type:Y,source:{type:"file",file_id:Q.fileId}}]}var h6=new Set(["image/jpeg","image/png","image/gif","image/webp"]);function y6(Q){let $=Q.mimeType?.trim().toLowerCase()??"";if(_Q(Q))return!$||h6.has($)?"image":void 0;if($)return $==="application/pdf"||$==="text/plain"?"document":void 0;return/\.(pdf|txt)$/i.test(Q.name??"")?"document":void 0}function v(Q){return!!Q&&typeof Q==="object"&&!Array.isArray(Q)}function f6(Q){return Array.isArray(Q.tools)}function g6(Q){let $=[];for(let J of Q??[])for(let Z of f6(J)?J.tools:[J])$.push({name:Z.name,description:Z.description,input_schema:Z.parameters,eager_input_streaming:!0});return $}async function*D5(Q,$={}){let J=new Map,Z=[],Y,G={},B,z,X=!1,K=(j)=>({type:"finish",reason:j,usage:TQ(G),...Y?{model:Y}:{}});for await(let j of DQ(Q)){let H;try{H=JSON.parse(j.data)}catch{continue}switch(typeof H.type==="string"?H.type:j.event){case"message_start":{let W=H.message??{};if(typeof W.model==="string"&&W.model)Y=W.model;G=P5(G,W.usage),$.onUsage?.(TQ(G));break}case"content_block_start":{let W=Number(H.index),q=H.content_block??{},C={type:String(q.type??""),id:typeof q.id==="string"?q.id:void 0,name:typeof q.name==="string"?q.name:void 0,args:"",signature:typeof q.signature==="string"?q.signature:""};if(J.set(W,C),C.type==="redacted_thinking")yield{type:"reasoning-delta",delta:"",providerMetadata:{anthropic:{type:"redacted_thinking",data:String(q.data??"")}}};if(C.type==="text"&&typeof q.text==="string"&&q.text)yield N5(q.text,$);break}case"content_block_delta":{let W=J.get(Number(H.index)),q=H.delta??{};if(!W)break;if(q.type==="text_delta"){let C=String(q.text??"");if(C)yield N5(C,$)}else if(q.type==="thinking_delta"){let C=String(q.thinking??"");if(C)yield{type:"reasoning-delta",delta:C}}else if(q.type==="signature_delta")W.signature+=String(q.signature??"");else if(q.type==="input_json_delta"&&W.type==="tool_use"){let C=String(q.partial_json??"");if(!C)break;W.args+=C,yield{type:"tool-call-delta",toolCallId:W.id??"",name:W.name??"",argsDelta:C}}break}case"content_block_stop":{let W=Number(H.index),q=J.get(W);if(J.delete(W),q?.type==="thinking")yield{type:"reasoning-delta",delta:"",providerMetadata:{anthropic:{type:"thinking",signature:q.signature}}};if(q?.type==="tool_use")if(q.args||="{}",u6(q.args))yield U5(q);else Z.push(q);break}case"message_delta":{if(typeof H.delta?.stop_reason==="string")B=H.delta.stop_reason;if(H.delta?.stop_details)z=H.delta.stop_details;G=P5(G,H.usage),$.onUsage?.(TQ(G));break}case"message_stop":{if(X=!0,B==="refusal"){yield{type:"error",error:c6(z)},yield K("error");break}let W=m6(B);if(Z.length>0&&W==="length")yield{type:"tool-call-discard",toolCallIds:Z.map((q)=>q.id??"")};else for(let q of Z)yield U5(q);yield K(W);break}case"error":{X=!0;let W=H.error??H;yield{type:"error",error:d6(W),...QQ(W)},yield K("error");break}}if(X)return}yield{type:"error",error:{code:"provider_error",message:"The provider stream ended without a terminal event.",retryable:!0}},yield K("error")}function U5(Q){return{type:"tool-call",toolCallId:Q.id??"",name:Q.name??"",args:Q.args}}function u6(Q){try{return JSON.parse(Q),!0}catch{return!1}}function N5(Q,$){return $.structuredOutput?{type:"output-delta",delta:Q}:{type:"text-delta",delta:Q}}function m6(Q){if(Q==="max_tokens"||Q==="model_context_window_exceeded")return"length";return"stop"}function c6(Q){let $=typeof Q?.explanation==="string"?Q.explanation:"",J=typeof Q?.category==="string"?` (${Q.category})`:"";return{code:"content_filtered",message:$||`The model declined to answer${J}.`,retryable:!1}}function d6(Q){let $=String(Q?.type??"").toLowerCase(),J=typeof Q?.message==="string"?Q.message:"The provider stream failed.";if($==="rate_limit_error")return{code:"rate_limited",message:J,retryable:!0};if($==="invalid_request_error"||$==="request_too_large")return{code:/prompt is too long|request_too_large/i.test(`${$} ${J}`)?"context_length_exceeded":"provider_error",message:J,retryable:!1};if($==="authentication_error"||$==="permission_error"||$==="billing_error"||$==="not_found_error")return{code:"provider_error",message:J,retryable:!1};return{code:"provider_error",message:J,retryable:!0}}function P5(Q,$){if(!$||typeof $!=="object")return Q;let J={...Q};for(let Y of["input_tokens","output_tokens","cache_creation_input_tokens","cache_read_input_tokens"])if(typeof $[Y]==="number")J[Y]=$[Y];let Z=$.output_tokens_details?.thinking_tokens;if(typeof Z==="number")J.thinking_tokens=Z;return J}function TQ(Q){if(!Q)return R();let{cache_read_input_tokens:$,cache_creation_input_tokens:J}=Q,Z=(Q.input_tokens??0)+($??0)+(J??0),Y=Q.output_tokens??0,G={inputTokens:Z,outputTokens:Y,totalTokens:Z+Y};if(typeof $==="number")G.cachedInputTokens=$;if(typeof J==="number")G.cacheWriteInputTokens=J;if(typeof Q.thinking_tokens==="number")G.reasoningTokens=Q.thinking_tokens;return G}function EQ(Q){let $=kQ(Q);if($.startsWith("gpt-3.5")||$.startsWith("text-")||$.startsWith("davinci"))return{reasoning:!1,structuredOutput:!1,fileInput:!1,parallelToolCalls:!0,toolSearch:!1,supportsForcedToolChoice:!0};let J=l6($);if(J?.kind==="o")return{reasoning:!0,structuredOutput:!0,fileInput:!0,parallelToolCalls:J.major>1,toolSearch:x5(J),supportsForcedToolChoice:!0};if(J?.kind==="gpt")return{reasoning:J.major>=5,structuredOutput:J.major>4||$.startsWith("gpt-4o")||$.startsWith("gpt-4.1"),fileInput:J.major>4||$.startsWith("gpt-4o")||$.startsWith("gpt-4.1"),parallelToolCalls:!0,toolSearch:x5(J),supportsForcedToolChoice:!0};return{reasoning:!0,structuredOutput:!0,fileInput:!0,parallelToolCalls:!0,toolSearch:!0,supportsForcedToolChoice:!0}}function x5(Q){if(Q.kind==="o")return Q.major>=5;return Q.major>5||Q.major===5&&Q.minor>=2}function wQ(Q){let $=kQ(Q),J=/^claude-(?:opus|sonnet|haiku)-4(?:-(\d{1,2}))?(?:-\d{8})?$/.exec($);return{reasoning:!(/^claude-(?:3|2|instant)/.test($)||!!J&&Number(J[1]??0)<=5),structuredOutput:!0,fileInput:!0,parallelToolCalls:!0,toolSearch:!1,supportsForcedToolChoice:p6(Q)}}function p6(Q){let $=kQ(Q);return/^claude-(?:3|2|instant)/.test($)||/^claude-(?:opus|sonnet|haiku)-4(?:-|$)/.test($)||/^claude-(?:opus|sonnet|fable|mythos)-5(?:-\d{8})?$/.test($)||/^claude-haiku-5-5(?:-\d{8})?$/.test($)}function kQ(Q){return Q.trim().toLowerCase()}function l6(Q){let $=/^gpt-(\d+)(?:\.(\d+))?/.exec(Q);if($?.[1])return{kind:"gpt",major:Number($[1]),minor:Number($[2]??0)};let J=/^o(\d+)(?:[-.]|$)/.exec(Q);if(J?.[1])return{kind:"o",major:Number(J[1]),minor:0};return null}var vQ=120000,bQ=2,hQ=120000,yQ=300000,fQ=1000;function x(Q){return typeof process>"u"?void 0:process.env?.[Q]}var i6="preview";function O5(Q){let $=Q.trim().replace(/\/+$/,"");if(!$)return"";return`${$.replace(/\/openai(?:\/v1)?$/i,"")}/openai`}function n6(Q){return/^\d{4}-\d{2}-\d{2}/.test(Q)?"":"/v1"}function gQ(Q,$={}){return{base:(Q.baseURL??x("OPENAI_BASE_URL")??"https://api.openai.com/v1").replace(/\/+$/,""),query:"",headers:async()=>{let Z=Q.apiKey??x("OPENAI_API_KEY");return{...Z?{authorization:`Bearer ${Z}`}:{},...Q.headers}},timeoutMs:Q.timeoutMs??$.timeoutMs??vQ,streamIdleTimeoutMs:Q.streamIdleTimeoutMs??hQ,streamMaxDurationMs:Q.streamMaxDurationMs??yQ,maxToolArgumentChars:Q.maxToolArgumentChars??0,maxToolArgumentWhitespace:Q.maxToolArgumentWhitespace??fQ,maxRetries:Q.maxRetries??bQ,...mQ(Q)}}function M5(Q){let $=Q.baseURL??Q.endpoint??x("AZURE_OPENAI_ENDPOINT");if($)return O5($);let J=Q.resourceName??x("AZURE_OPENAI_RESOURCE_NAME")??x("AZURE_RESOURCE_NAME");return J?O5(`https://${J.trim()}.cognitiveservices.azure.com`):""}function uQ(Q,$={}){let J=Q.apiVersion??x("AZURE_OPENAI_API_VERSION")??i6;return{base:`${M5(Q)}${n6(J)}`,query:`?api-version=${encodeURIComponent(J)}`,headers:async()=>{if(Q.getToken)return{authorization:`Bearer ${await Q.getToken()}`,...Q.headers};let Z=Q.apiKey??x("AZURE_OPENAI_API_KEY");return{...Z?{"api-key":Z}:{},...Q.headers}},timeoutMs:Q.timeoutMs??$.timeoutMs??vQ,streamIdleTimeoutMs:Q.streamIdleTimeoutMs??hQ,streamMaxDurationMs:Q.streamMaxDurationMs??yQ,maxToolArgumentChars:Q.maxToolArgumentChars??0,maxToolArgumentWhitespace:Q.maxToolArgumentWhitespace??fQ,maxRetries:Q.maxRetries??bQ,...mQ(Q)}}var r6="2026-10-21";function S5(Q,$={}){let J=Q.baseURL??x("ANTHROPIC_BASE_URL")??"https://api.anthropic.com";return R5(J,Q,$,async()=>{let Z=Q.workspaceId??x("ANTHROPIC_WORKSPACE_ID"),Y=Z?{"anthropic-workspace-id":Z}:{},G=Q.apiKey??x("ANTHROPIC_API_KEY");if(G)return{"x-api-key":G,...Y};let B=x("ANTHROPIC_AUTH_TOKEN");return B?{authorization:`Bearer ${B}`,...Y}:Y})}function _5(Q,$={}){let J=Q.resourceName??x("ANTHROPIC_FOUNDRY_RESOURCE"),Z=Q.baseURL??Q.endpoint??x("ANTHROPIC_FOUNDRY_BASE_URL")??(J?`https://${J.trim()}.services.ai.azure.com/anthropic`:"");if(!Z.trim())throw Error("AzureAnthropicProvider has no Foundry endpoint. Set `endpoint` (the deployment's Target URI without `/v1/messages`, e.g. `https://<resource>.services.ai.azure.com/anthropic`) or `resourceName`, or the ANTHROPIC_FOUNDRY_BASE_URL or ANTHROPIC_FOUNDRY_RESOURCE environment variable.");return R5(Z,Q,$,async()=>{if(Q.getToken)return{authorization:`Bearer ${await Q.getToken()}`};let Y=Q.apiKey??x("ANTHROPIC_FOUNDRY_API_KEY");return Y?{"api-key":Y}:{}})}function R5(Q,$,J,Z){return{base:`${Q.trim().replace(/\/+$/,"").replace(/\/v1$/,"")}/v1`,query:"",headers:async()=>({...await Z(),"anthropic-version":r6,...$.headers}),timeoutMs:$.timeoutMs??J.timeoutMs??vQ,streamIdleTimeoutMs:$.streamIdleTimeoutMs??hQ,streamMaxDurationMs:$.streamMaxDurationMs??yQ,maxToolArgumentChars:$.maxToolArgumentChars??0,maxToolArgumentWhitespace:$.maxToolArgumentWhitespace??fQ,maxRetries:$.maxRetries??bQ,...mQ($)}}function I5(Q,$={}){return{...uQ(Q,$),base:`${M5(Q)}/v1`,query:""}}function mQ(Q){return pQ(Q.retry),Q.retry?{retry:Q.retry}:{}}class KQ{static models(){return[]}normalizeError(Q){return M(Q)}}var A5=["gpt-5.5","gpt-5.4","gpt-5.4-mini","gpt-5.4-nano","gpt-5.2","gpt-5.1","gpt-5","gpt-5-mini","gpt-5-nano","gpt-4.1","gpt-4.1-mini","gpt-4.1-nano","gpt-4o","gpt-4o-mini","o4-mini","o3","o3-mini"];class T5 extends KQ{model;capabilities;config;constructor(Q,$={}){super();this.model=Q,this.capabilities=EQ(Q),this.config=$}static model(Q,$){return new T5(Q,$)}static models(){return A5}stream(Q){let $=MQ(Q,{model:this.model,capabilities:this.capabilities});return YQ(this.endpoint(),$,{signal:Q.signal,retryToolArgumentsTooLong:Q.retryToolArgumentsTooLong,structuredOutput:Boolean(Q.output),files:CQ(Q.messages)})}upload(Q){return GQ(this.endpoint(),Q)}deleteFile(Q){return VQ(this.endpoint(),Q)}endpoint(){return ZQ(gQ(this.config))}get realtime(){return new e(gQ(this.config,{timeoutMs:qQ}),{model:this.model})}}var s6=["claude-opus-5-5","claude-sonnet-5-5","claude-haiku-5-5","claude-fable-5-2","claude-fable-5-1","claude-opus-5","claude-sonnet-5","claude-fable-5","claude-opus-4-8","claude-sonnet-4-6","claude-haiku-4-5"];class cQ extends KQ{model;capabilities;config;constructor(Q,$={}){super();this.model=Q,this.capabilities=wQ(Q),this.config=$}static model(Q,$){return new cQ(Q,$)}static models(){return s6}stream(Q){return this.send(Q)}async*send(Q){let $=Q,J=!1,Z=new Set;for(;;){let Y=this.request($);if(J)Y=C5(Y);let G,B=!1;for await(let z of YQ(this.endpointFor(Y),Y,{signal:Q.signal,retryToolArgumentsTooLong:Q.retryToolArgumentsTooLong,structuredOutput:Boolean(Q.output),parse:D5})){if(G)continue;if(!B&&z.type==="error"&&z.status===400){let X=F5(z.error.message);if(X&&!Z.has(X)){Z.add(X),G=X;continue}}if(JQ(z))B=!0;yield z}if(!G)return;if(G==="thinking")J=!0;else if($.output)$={...$,output:{...$.output,strict:!1}}}}request(Q){return q5(Q,{model:this.deployment(),modelId:this.model,capabilities:this.capabilities,forcedToolChoice:this.capabilities.supportsForcedToolChoice!==!1,blockBinding:this.bindsThinking()})}endpointFor(Q){let $=this.endpoint();if(!(Q.thinking?.type==="adaptive"&&Q.thinking.block_binding))return $;return{...$,headers:async()=>{let Z=await $.headers(),Y=Z["anthropic-beta"];return{...Z,"anthropic-beta":Y?`${Y},${AQ}`:AQ}}}}bindsThinking(){return!0}deployment(){return this.model}upload(Q){return GQ(this.endpoint(),Q,null)}deleteFile(Q){return VQ(this.endpoint(),Q)}endpoint(){return E5(S5(this.config))}}function E5(Q){return{...ZQ(Q),responsesUrl:`${Q.base}/messages`}}class w5 extends cQ{constructor(Q,$={}){super(Q,$);this.capabilities={...wQ(Q),fileInput:!1}}static model(Q,$){return new w5(Q,$)}upload(Q){return Promise.reject(Error("AzureAnthropicProvider does not upload files: the Files API is not available on Azure-hosted Foundry deployments. The file is still stored by gemi and named to the model by its attachment id."))}deleteFile(Q){return Promise.reject(Error("AzureAnthropicProvider does not delete files: the Files API is not available on Azure-hosted Foundry deployments."))}deployment(){return this.config.deployment??this.model}bindsThinking(){return!1}endpoint(){return E5(_5(this.config))}}class k5 extends KQ{model;capabilities;config;constructor(Q,$={}){super();this.model=Q,this.capabilities=EQ(Q),this.config=$}static model(Q,$){return new k5(Q,$)}static models(){return A5}stream(Q){let $=MQ(Q,{model:this.deployment(),capabilities:this.capabilities});return YQ(this.endpoint(),$,{signal:Q.signal,retryToolArgumentsTooLong:Q.retryToolArgumentsTooLong,structuredOutput:Boolean(Q.output),files:CQ(Q.messages)})}upload(Q){return GQ(this.endpoint(),Q,"assistants")}deleteFile(Q){return VQ(this.endpoint(),Q)}deployment(){return this.config.deployment??this.model}endpoint(){return ZQ(uQ(this.config))}get realtime(){return new e(I5(this.config,{timeoutMs:qQ}),{model:this.deployment(),callFlow:"ephemeral"})}}
10
+ export{g as ca,gQ as da,uQ as ea,zQ as fa,c5 as ga,FQ as ha,d as ia,e as ja,n5 as ka,KQ as la,T5 as ma,cQ as na,w5 as oa,k5 as pa};
11
+
12
+ //# debugId=935B3812E4C72C0B64756E2164756E21