gemi 0.216.0 → 0.218.0

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 (257) hide show
  1. package/dist/ai/AgentController.d.ts +85 -2
  2. package/dist/ai/AgentController.d.ts.map +1 -1
  3. package/dist/ai/AgentProvider.d.ts +20 -0
  4. package/dist/ai/AgentProvider.d.ts.map +1 -1
  5. package/dist/ai/FallbackProvider.d.ts +2 -0
  6. package/dist/ai/FallbackProvider.d.ts.map +1 -1
  7. package/dist/ai/index.d.ts +2 -1
  8. package/dist/ai/index.d.ts.map +1 -1
  9. package/dist/ai/index.js +42 -42
  10. package/dist/ai/index.js.map +5 -5
  11. package/dist/ai/live/harness.d.ts +1 -0
  12. package/dist/ai/live/harness.d.ts.map +1 -1
  13. package/dist/ai/providers/call.d.ts +10 -0
  14. package/dist/ai/providers/call.d.ts.map +1 -1
  15. package/dist/ai/providers/fakeProvider.d.ts +3 -0
  16. package/dist/ai/providers/fakeProvider.d.ts.map +1 -1
  17. package/dist/ai/store/Attachments.d.ts +98 -2
  18. package/dist/ai/store/Attachments.d.ts.map +1 -1
  19. package/dist/ai/store/FileOwners.d.ts +18 -0
  20. package/dist/ai/store/FileOwners.d.ts.map +1 -1
  21. package/dist/ai/store/index.d.ts +1 -1
  22. package/dist/ai/store/index.d.ts.map +1 -1
  23. package/dist/ai/testing/RecordingProvider.d.ts +2 -0
  24. package/dist/ai/testing/RecordingProvider.d.ts.map +1 -1
  25. package/dist/ai/testing/index.js +3 -3
  26. package/dist/ai/testing/index.js.map +3 -3
  27. package/dist/app/index.js +1 -1
  28. package/dist/bin/ai-client/kotlin.d.ts +13 -1
  29. package/dist/bin/ai-client/kotlin.d.ts.map +1 -1
  30. package/dist/bin/ai-client/swift.d.ts +10 -1
  31. package/dist/bin/ai-client/swift.d.ts.map +1 -1
  32. package/dist/bin/gemi.js +40 -22
  33. package/dist/bin/gemi.js.map +4 -4
  34. package/dist/bin/http-client/render.d.ts +5 -0
  35. package/dist/bin/http-client/render.d.ts.map +1 -0
  36. package/dist/bun/plugin.js +1 -1
  37. package/dist/bun/preload.js +1 -1
  38. package/dist/{chunk-0ah98rf4.js → chunk-17agj0r3.js} +2 -2
  39. package/dist/{chunk-0ah98rf4.js.map → chunk-17agj0r3.js.map} +1 -1
  40. package/dist/{chunk-c2c21b6g.js → chunk-1nw9jhpt.js} +2 -2
  41. package/dist/{chunk-c2c21b6g.js.map → chunk-1nw9jhpt.js.map} +1 -1
  42. package/dist/{chunk-362a52jj.js → chunk-3r7z4kc0.js} +2 -2
  43. package/dist/{chunk-362a52jj.js.map → chunk-3r7z4kc0.js.map} +1 -1
  44. package/dist/{chunk-t0519abr.js → chunk-4k3r37be.js} +2 -2
  45. package/dist/{chunk-t0519abr.js.map → chunk-4k3r37be.js.map} +1 -1
  46. package/dist/{chunk-2crfg0m7.js → chunk-4s72m6zx.js} +3 -3
  47. package/dist/{chunk-2crfg0m7.js.map → chunk-4s72m6zx.js.map} +1 -1
  48. package/dist/{chunk-v7bbn1m0.js → chunk-4sbrvmz9.js} +5 -5
  49. package/dist/{chunk-v7bbn1m0.js.map → chunk-4sbrvmz9.js.map} +3 -3
  50. package/dist/{chunk-5294qsfq.js → chunk-5gp49wph.js} +2 -2
  51. package/dist/{chunk-0z8h6t7k.js.map → chunk-5gp49wph.js.map} +1 -1
  52. package/dist/{chunk-w1my1q4q.js → chunk-5vdkqv17.js} +2 -2
  53. package/dist/{chunk-w1my1q4q.js.map → chunk-5vdkqv17.js.map} +1 -1
  54. package/dist/{chunk-dqw432zh.js → chunk-5wh3cw2x.js} +3 -3
  55. package/dist/{chunk-dqw432zh.js.map → chunk-5wh3cw2x.js.map} +1 -1
  56. package/dist/{chunk-ttz05z12.js → chunk-6b7z5h54.js} +2 -2
  57. package/dist/{chunk-ttz05z12.js.map → chunk-6b7z5h54.js.map} +1 -1
  58. package/dist/{chunk-mw4c05vw.js → chunk-6ncn8rdn.js} +2 -2
  59. package/dist/{chunk-mw4c05vw.js.map → chunk-6ncn8rdn.js.map} +1 -1
  60. package/dist/chunk-7081awrd.js +11 -0
  61. package/dist/{chunk-rqa04dtq.js.map → chunk-7081awrd.js.map} +4 -4
  62. package/dist/{chunk-j6j0qxam.js → chunk-7rmb1v9c.js} +2 -2
  63. package/dist/{chunk-j6j0qxam.js.map → chunk-7rmb1v9c.js.map} +1 -1
  64. package/dist/{chunk-wcj083k2.js → chunk-7t13vyzg.js} +3 -3
  65. package/dist/{chunk-wcj083k2.js.map → chunk-7t13vyzg.js.map} +1 -1
  66. package/dist/{chunk-bk1e8sah.js → chunk-7xe5vd4w.js} +2 -2
  67. package/dist/{chunk-bk1e8sah.js.map → chunk-7xe5vd4w.js.map} +1 -1
  68. package/dist/{chunk-cws2tsxg.js → chunk-8524ejgk.js} +2 -2
  69. package/dist/{chunk-cws2tsxg.js.map → chunk-8524ejgk.js.map} +1 -1
  70. package/dist/{chunk-twb7x8j8.js → chunk-9c8e4nkz.js} +2 -2
  71. package/dist/{chunk-twb7x8j8.js.map → chunk-9c8e4nkz.js.map} +1 -1
  72. package/dist/{chunk-p5n1tqqg.js → chunk-9g5qh1ya.js} +2 -2
  73. package/dist/{chunk-p5n1tqqg.js.map → chunk-9g5qh1ya.js.map} +1 -1
  74. package/dist/{chunk-yjshg4e5.js → chunk-9pvxexh1.js} +2 -2
  75. package/dist/{chunk-yjshg4e5.js.map → chunk-9pvxexh1.js.map} +1 -1
  76. package/dist/{chunk-kd6z1t9z.js → chunk-aes0ecnp.js} +3 -3
  77. package/dist/{chunk-kd6z1t9z.js.map → chunk-aes0ecnp.js.map} +1 -1
  78. package/dist/{chunk-0a796avj.js → chunk-at6zjajz.js} +2 -2
  79. package/dist/{chunk-0a796avj.js.map → chunk-at6zjajz.js.map} +1 -1
  80. package/dist/{chunk-htkw9qbv.js → chunk-b1pps9bj.js} +2 -2
  81. package/dist/{chunk-htkw9qbv.js.map → chunk-b1pps9bj.js.map} +1 -1
  82. package/dist/{chunk-btf3t4qa.js → chunk-b8tmmpcf.js} +2 -2
  83. package/dist/{chunk-btf3t4qa.js.map → chunk-b8tmmpcf.js.map} +1 -1
  84. package/dist/chunk-bcfwa370.js +5 -0
  85. package/dist/chunk-bcfwa370.js.map +13 -0
  86. package/dist/{chunk-ybmy1rts.js → chunk-c95ds04p.js} +2 -2
  87. package/dist/{chunk-ybmy1rts.js.map → chunk-c95ds04p.js.map} +1 -1
  88. package/dist/{chunk-y9fye7az.js → chunk-cwm5x7rf.js} +2 -2
  89. package/dist/{chunk-y9fye7az.js.map → chunk-cwm5x7rf.js.map} +1 -1
  90. package/dist/{chunk-djwmrvsq.js → chunk-d6056zme.js} +2 -2
  91. package/dist/{chunk-djwmrvsq.js.map → chunk-d6056zme.js.map} +1 -1
  92. package/dist/chunk-d6bgh2nr.js +5 -0
  93. package/dist/{chunk-texzdarz.js.map → chunk-d6bgh2nr.js.map} +1 -1
  94. package/dist/{chunk-z03ds1qe.js → chunk-dgna0e7g.js} +2 -2
  95. package/dist/{chunk-z03ds1qe.js.map → chunk-dgna0e7g.js.map} +1 -1
  96. package/dist/{chunk-1k6dn4ba.js → chunk-ee7xb9qr.js} +1 -1
  97. package/dist/{chunk-5ya7fbfg.js → chunk-eh3ktv8k.js} +2 -2
  98. package/dist/{chunk-5ya7fbfg.js.map → chunk-eh3ktv8k.js.map} +1 -1
  99. package/dist/{chunk-aqjjknyk.js → chunk-evgs2tr8.js} +2 -2
  100. package/dist/{chunk-aqjjknyk.js.map → chunk-evgs2tr8.js.map} +1 -1
  101. package/dist/{chunk-mv2d2njy.js → chunk-fhb00fjx.js} +2 -2
  102. package/dist/{chunk-mv2d2njy.js.map → chunk-fhb00fjx.js.map} +1 -1
  103. package/dist/{chunk-py69zwwv.js → chunk-fq7wkefg.js} +2 -2
  104. package/dist/{chunk-py69zwwv.js.map → chunk-fq7wkefg.js.map} +1 -1
  105. package/dist/{chunk-01r2cx3k.js → chunk-g178aect.js} +4 -4
  106. package/dist/{chunk-01r2cx3k.js.map → chunk-g178aect.js.map} +1 -1
  107. package/dist/{chunk-jr9f5r65.js → chunk-gt6eq1p2.js} +3 -3
  108. package/dist/{chunk-jr9f5r65.js.map → chunk-gt6eq1p2.js.map} +1 -1
  109. package/dist/{chunk-z54zefss.js → chunk-gxd1388t.js} +2 -2
  110. package/dist/{chunk-z54zefss.js.map → chunk-gxd1388t.js.map} +1 -1
  111. package/dist/{chunk-dpm875be.js → chunk-gxfyd8wr.js} +3 -3
  112. package/dist/{chunk-dpm875be.js.map → chunk-gxfyd8wr.js.map} +1 -1
  113. package/dist/{chunk-gkjsanjh.js → chunk-h6knw9f0.js} +1 -1
  114. package/dist/{chunk-shn9t4vg.js → chunk-hmtn7996.js} +2 -2
  115. package/dist/{chunk-shn9t4vg.js.map → chunk-hmtn7996.js.map} +1 -1
  116. package/dist/{chunk-6s48nq83.js → chunk-jzqywxpj.js} +2 -2
  117. package/dist/{chunk-6s48nq83.js.map → chunk-jzqywxpj.js.map} +1 -1
  118. package/dist/{chunk-mnfk2r8z.js → chunk-k8nsefzb.js} +2 -2
  119. package/dist/{chunk-mnfk2r8z.js.map → chunk-k8nsefzb.js.map} +1 -1
  120. package/dist/{chunk-xw241q0q.js → chunk-kggwk7hz.js} +1 -1
  121. package/dist/chunk-ktee4gy4.js +484 -0
  122. package/dist/chunk-ktee4gy4.js.map +23 -0
  123. package/dist/{chunk-hknnxxg6.js → chunk-m0pfdc1n.js} +3 -3
  124. package/dist/{chunk-hknnxxg6.js.map → chunk-m0pfdc1n.js.map} +1 -1
  125. package/dist/{chunk-yak9kt1x.js → chunk-m68cxnbv.js} +2 -2
  126. package/dist/{chunk-yak9kt1x.js.map → chunk-m68cxnbv.js.map} +1 -1
  127. package/dist/{chunk-5m0vh0rg.js → chunk-ncw3zjxm.js} +2 -2
  128. package/dist/{chunk-5m0vh0rg.js.map → chunk-ncw3zjxm.js.map} +1 -1
  129. package/dist/{chunk-6cge785m.js → chunk-nhebjh6n.js} +1 -1
  130. package/dist/{chunk-djpqt7kh.js → chunk-ppdfwnqw.js} +1 -1
  131. package/dist/{chunk-62b7paq5.js → chunk-prc4bcgp.js} +2 -2
  132. package/dist/{chunk-62b7paq5.js.map → chunk-prc4bcgp.js.map} +1 -1
  133. package/dist/{chunk-hea3rwj3.js → chunk-q0d45r2j.js} +2 -2
  134. package/dist/{chunk-hea3rwj3.js.map → chunk-q0d45r2j.js.map} +1 -1
  135. package/dist/{chunk-6669vjve.js → chunk-qa528feb.js} +2 -2
  136. package/dist/{chunk-6669vjve.js.map → chunk-qa528feb.js.map} +1 -1
  137. package/dist/{chunk-4zw9gaey.js → chunk-qstjm3cb.js} +2 -2
  138. package/dist/{chunk-4zw9gaey.js.map → chunk-qstjm3cb.js.map} +1 -1
  139. package/dist/{chunk-t5af0fjq.js → chunk-r90djdx6.js} +2 -2
  140. package/dist/{chunk-t5af0fjq.js.map → chunk-r90djdx6.js.map} +1 -1
  141. package/dist/{chunk-bw1mvk6n.js → chunk-rp2f9mq1.js} +2 -2
  142. package/dist/{chunk-bw1mvk6n.js.map → chunk-rp2f9mq1.js.map} +1 -1
  143. package/dist/{chunk-9k6swvf1.js → chunk-s7jwsbfd.js} +3 -3
  144. package/dist/{chunk-9k6swvf1.js.map → chunk-s7jwsbfd.js.map} +1 -1
  145. package/dist/{chunk-3pfrqzw8.js → chunk-sba3s380.js} +2 -2
  146. package/dist/{chunk-3pfrqzw8.js.map → chunk-sba3s380.js.map} +1 -1
  147. package/dist/{chunk-naj8bmj5.js → chunk-snt0523y.js} +2 -2
  148. package/dist/{chunk-naj8bmj5.js.map → chunk-snt0523y.js.map} +1 -1
  149. package/dist/{chunk-5cf59esb.js → chunk-sqqh78tf.js} +2 -2
  150. package/dist/{chunk-5cf59esb.js.map → chunk-sqqh78tf.js.map} +1 -1
  151. package/dist/{chunk-9pjvetym.js → chunk-sxxkkx75.js} +4 -4
  152. package/dist/{chunk-9pjvetym.js.map → chunk-sxxkkx75.js.map} +1 -1
  153. package/dist/{chunk-1hs2fxxx.js → chunk-tw338bbv.js} +2 -2
  154. package/dist/{chunk-1hs2fxxx.js.map → chunk-tw338bbv.js.map} +1 -1
  155. package/dist/{chunk-rzhgcajs.js → chunk-v0sgcy87.js} +1 -1
  156. package/dist/{chunk-8q3pnwtj.js → chunk-vawqmdh4.js} +2 -2
  157. package/dist/{chunk-8q3pnwtj.js.map → chunk-vawqmdh4.js.map} +1 -1
  158. package/dist/{chunk-c231j2e7.js → chunk-vck02shp.js} +2 -2
  159. package/dist/{chunk-c231j2e7.js.map → chunk-vck02shp.js.map} +1 -1
  160. package/dist/{chunk-knmh8ynk.js → chunk-vewxnk3g.js} +2 -2
  161. package/dist/{chunk-knmh8ynk.js.map → chunk-vewxnk3g.js.map} +1 -1
  162. package/dist/{chunk-7bywa721.js → chunk-w3ks9nz7.js} +2 -2
  163. package/dist/{chunk-7bywa721.js.map → chunk-w3ks9nz7.js.map} +1 -1
  164. package/dist/{chunk-k9pch3e6.js → chunk-w85wrer7.js} +2 -2
  165. package/dist/{chunk-k9pch3e6.js.map → chunk-w85wrer7.js.map} +1 -1
  166. package/dist/{chunk-g7vyn179.js → chunk-w9sw2kn7.js} +3 -3
  167. package/dist/{chunk-g7vyn179.js.map → chunk-w9sw2kn7.js.map} +1 -1
  168. package/dist/{chunk-95yr9y9v.js → chunk-ww62b10k.js} +2 -2
  169. package/dist/{chunk-95yr9y9v.js.map → chunk-ww62b10k.js.map} +1 -1
  170. package/dist/{chunk-a6yge4kh.js → chunk-xb0evp2m.js} +2 -2
  171. package/dist/{chunk-a6yge4kh.js.map → chunk-xb0evp2m.js.map} +1 -1
  172. package/dist/{chunk-g1th1dfa.js → chunk-xese0rng.js} +3 -3
  173. package/dist/{chunk-g1th1dfa.js.map → chunk-xese0rng.js.map} +1 -1
  174. package/dist/{chunk-cgkp0ypn.js → chunk-xf3wke41.js} +2 -2
  175. package/dist/{chunk-cgkp0ypn.js.map → chunk-xf3wke41.js.map} +1 -1
  176. package/dist/{chunk-mjyr8at2.js → chunk-xn7azkgd.js} +3 -3
  177. package/dist/{chunk-mjyr8at2.js.map → chunk-xn7azkgd.js.map} +1 -1
  178. package/dist/{chunk-gwe9hbds.js → chunk-xp5mmgfp.js} +2 -2
  179. package/dist/{chunk-gwe9hbds.js.map → chunk-xp5mmgfp.js.map} +1 -1
  180. package/dist/{chunk-kc1y747c.js → chunk-xyv3y476.js} +3 -3
  181. package/dist/{chunk-kc1y747c.js.map → chunk-xyv3y476.js.map} +1 -1
  182. package/dist/{chunk-0z8h6t7k.js → chunk-yedb5vvg.js} +2 -2
  183. package/dist/{chunk-5294qsfq.js.map → chunk-yedb5vvg.js.map} +1 -1
  184. package/dist/{chunk-b02yzfpk.js → chunk-ykshxc5k.js} +2 -2
  185. package/dist/{chunk-b02yzfpk.js.map → chunk-ykshxc5k.js.map} +1 -1
  186. package/dist/{chunk-zbxvyanj.js → chunk-yxtfg4wy.js} +2 -2
  187. package/dist/{chunk-zbxvyanj.js.map → chunk-yxtfg4wy.js.map} +1 -1
  188. package/dist/{chunk-7mg2ash8.js → chunk-zy6hj5cc.js} +2 -2
  189. package/dist/{chunk-7mg2ash8.js.map → chunk-zy6hj5cc.js.map} +1 -1
  190. package/dist/{chunk-xg5r0383.js → chunk-zyvmbqcx.js} +3 -3
  191. package/dist/{chunk-xg5r0383.js.map → chunk-zyvmbqcx.js.map} +1 -1
  192. package/dist/config/index.js +1 -1
  193. package/dist/console/run.js +2 -2
  194. package/dist/console/run.js.map +1 -1
  195. package/dist/container/index.js +2 -2
  196. package/dist/container/index.js.map +1 -1
  197. package/dist/database/index.js +2 -2
  198. package/dist/database/index.js.map +1 -1
  199. package/dist/email/index.js +2 -2
  200. package/dist/email/index.js.map +1 -1
  201. package/dist/facades/index.js +2 -2
  202. package/dist/facades/index.js.map +1 -1
  203. package/dist/foundation/index.js +2 -2
  204. package/dist/foundation/index.js.map +1 -1
  205. package/dist/http/index.js +2 -2
  206. package/dist/http/index.js.map +1 -1
  207. package/dist/i18n/dictionaryRuntime.js +2 -2
  208. package/dist/i18n/dictionaryRuntime.js.map +1 -1
  209. package/dist/i18n/index.js +2 -2
  210. package/dist/i18n/index.js.map +1 -1
  211. package/dist/kernel/index.js +2 -2
  212. package/dist/kernel/index.js.map +1 -1
  213. package/dist/orm/index.js +2 -2
  214. package/dist/orm/index.js.map +1 -1
  215. package/dist/probe/index.js +2 -2
  216. package/dist/probe/index.js.map +1 -1
  217. package/dist/server/index.js +2 -2
  218. package/dist/server/index.js.map +1 -1
  219. package/dist/services/index.d.ts +2 -2
  220. package/dist/services/index.d.ts.map +1 -1
  221. package/dist/services/index.js +2 -2
  222. package/dist/services/index.js.map +1 -1
  223. package/dist/services/queue/DatabaseQueueDriver.d.ts +8 -1
  224. package/dist/services/queue/DatabaseQueueDriver.d.ts.map +1 -1
  225. package/dist/services/queue/work.js +2 -2
  226. package/dist/services/queue/work.js.map +1 -1
  227. package/dist/services/queue/workflow/DatabaseWorkflowStore.d.ts +20 -1
  228. package/dist/services/queue/workflow/DatabaseWorkflowStore.d.ts.map +1 -1
  229. package/dist/services/queue/workflow/MemoryWorkflowStore.d.ts +12 -1
  230. package/dist/services/queue/workflow/MemoryWorkflowStore.d.ts.map +1 -1
  231. package/dist/services/queue/workflow/Step.d.ts +131 -2
  232. package/dist/services/queue/workflow/Step.d.ts.map +1 -1
  233. package/dist/services/queue/workflow/Workflow.d.ts +18 -2
  234. package/dist/services/queue/workflow/Workflow.d.ts.map +1 -1
  235. package/dist/services/queue/workflow/WorkflowRuntime.d.ts +6 -0
  236. package/dist/services/queue/workflow/WorkflowRuntime.d.ts.map +1 -1
  237. package/dist/services/queue/workflow/WorkflowStore.d.ts +67 -3
  238. package/dist/services/queue/workflow/WorkflowStore.d.ts.map +1 -1
  239. package/dist/services/queue/workflow/workflowContract.d.ts +2 -0
  240. package/dist/services/queue/workflow/workflowContract.d.ts.map +1 -1
  241. package/dist/stats/route-table.js +1 -1
  242. package/dist/support/index.js +2 -2
  243. package/dist/support/index.js.map +1 -1
  244. package/dist/vitest/index.js +1 -1
  245. package/package.json +1 -1
  246. package/dist/chunk-g1b6zetz.js +0 -5
  247. package/dist/chunk-g1b6zetz.js.map +0 -13
  248. package/dist/chunk-q677pnq5.js +0 -416
  249. package/dist/chunk-q677pnq5.js.map +0 -23
  250. package/dist/chunk-rqa04dtq.js +0 -11
  251. package/dist/chunk-texzdarz.js +0 -5
  252. /package/dist/{chunk-1k6dn4ba.js.map → chunk-ee7xb9qr.js.map} +0 -0
  253. /package/dist/{chunk-gkjsanjh.js.map → chunk-h6knw9f0.js.map} +0 -0
  254. /package/dist/{chunk-xw241q0q.js.map → chunk-kggwk7hz.js.map} +0 -0
  255. /package/dist/{chunk-6cge785m.js.map → chunk-nhebjh6n.js.map} +0 -0
  256. /package/dist/{chunk-djpqt7kh.js.map → chunk-ppdfwnqw.js.map} +0 -0
  257. /package/dist/{chunk-rzhgcajs.js.map → chunk-v0sgcy87.js.map} +0 -0
@@ -1,11 +0,0 @@
1
- // @bun
2
- import{Nd as PQ,Td as A,Ud as s,Vd as Z5,Wd as Y5,Xd as NQ,Yd as k,Zd as t,_d as D,xd as QQ,zd as e}from"./chunk-g1b6zetz.js";import{Wj as lQ}from"./chunk-95yr9y9v.js";function VQ(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 _5=4000,R5=60000;function yQ(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 KQ(Q,$,J,Z,Y){let G=Q.patienceMs-Z;if(G<=0)return;let V=Q.maxWaitMs??R5,z=Q.initialWaitMs??_5,j=J!==void 0?Math.min(J,V):Math.round(Math.min(V,z*2**$)*(0.5+Y()*0.5));return Math.min(j,G)}var I5=500,gQ=20000;function A5(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 r(Q,$){let J=Math.min(gQ,I5*2**Q);return Math.round(J*(0.5+$()*0.5))}function T5(Q){return Q===429||Q===408||Q===409||Q>=500}function E5(Q,$){return T5(Q)&&D($).retryable}function uQ(Q){return Q.reason??new DOMException("The operation was aborted.","AbortError")}function cQ(Q,$){return new Promise((J,Z)=>{let Y=setTimeout(J,Q);$?.addEventListener("abort",()=>{clearTimeout(Y),Z(uQ($))},{once:!0})})}async function XQ(Q,$,J=cQ){if(!$)return await J(Q);$.throwIfAborted();let Z;try{await Promise.race([J(Q,$),new Promise((Y,G)=>{Z=()=>G(uQ($)),$.addEventListener("abort",Z,{once:!0})})])}finally{if(Z)$.removeEventListener("abort",Z)}}async function c(Q,$,J){let Z=J.fetchImpl??((W,X)=>fetch(W,X)),Y=J.sleep??cQ,G=J.random??Math.random,V=J.now??Date.now,z=Math.max(0,J.maxRetries),j=J.startedAt??V(),K=J.retry,B=(W,X,q,F)=>{let N=V()-j;try{J.onRetry?.({attempt:X+1,maxRetries:z,error:D(q),...k(q),timedOut:F,delayMs:W,elapsedMs:N,...K?{remainingMs:Math.max(0,K.patienceMs-N-W)}:{}})}catch{}return XQ(W,J.signal,Y)},H=(W,X,q,F)=>{if(!K)return;let{status:N}=k(q);if(!VQ(K,D(q),{...N?{status:N}:{},timedOut:F}))return;return KQ(K,W-z,X,V()-j,G)};for(let W=0;;W++){J.signal?.throwIfAborted();let X=new AbortController,q=()=>X.abort(J.signal?.reason);J.signal?.addEventListener("abort",q,{once:!0});let F=!1,N=J.timeoutMs>0?setTimeout(()=>{F=!0,X.abort()},J.timeoutMs):void 0,P;try{P=await Z(Q,{...$,signal:X.signal})}catch(_){if(N!==void 0)clearTimeout(N);if(J.signal?.removeEventListener("abort",q),J.signal?.aborted)throw _;let R=F?new s(J.timeoutMs):_;if(F&&J.retryTimeouts===!1)throw R;let I=W<z?r(W,G):H(W,void 0,R,F);if(I===void 0)throw R;await B(I,W,R,F);continue}if(N!==void 0)clearTimeout(N);if(P.ok)return P;J.signal?.removeEventListener("abort",q);let O=await w5(P),L=new A(P.status,O,P.headers.get("x-request-id")??P.headers.get("request-id")??void 0,A5(P.headers.get("retry-after"),V()));if(!E5(P.status,L))throw L;let y=L.retryAfter??(P.status===429?D(L).retryAfter:void 0),v=W>=z?H(W,y,L,!1):y===void 0?r(W,G):Math.min(y,gQ);if(v===void 0)throw L;await B(v,W,L,!1)}}async function w5(Q){let $;try{$=await Q.text()}catch{return null}try{return JSON.parse($)}catch{return $}}function mQ(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,V=Q.getReader();return new ReadableStream({async pull(z){let j,K,B=Math.max(0,G-performance.now()),H=!Z||B<=Z,W=H?B:Z,X=new Promise((q,F)=>{j=setTimeout(()=>{K=H?J.max():J.idle(),F(K)},W)});try{let q=await Promise.race([V.read(),X]);if(q.done)z.close();else z.enqueue(q.value)}catch(q){let F=K??q;z.error(F),V.cancel(F).catch(()=>{})}finally{clearTimeout(j)}},cancel(z){return V.cancel(z)}},{highWaterMark:0})}var HQ=30000,dQ=10,pQ=7200,k5=600,v5="gpt-live-transcribe";function h5(Q){return Q.type==="transcription"}function b5(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??v5};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?iQ(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 f5(Q){if(!Q)return{type:"object",properties:{}};return lQ(Q)?Q.toJSONSchema():Q}function a(Q,$){if(h5(Q))return b5(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((V)=>({type:"function",name:V.name,...V.description?{description:V.description}:{},parameters:f5(V.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&&iQ(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 iQ(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 jQ(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 V=Y?.cached_tokens_details?.audio_tokens;if(typeof V==="number")Z.cachedAudioInputTokens=V;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 m 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 y5=60;class o{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:y5,signal:Q.signal})).value}`,"content-type":"application/sdp"},Z=Q.sdp;else{let j=new FormData;j.set("sdp",Q.sdp),j.set("session",JSON.stringify(a(Q.session??{},this.model))),J=await this.target.headers(),Z=j}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),V=await G.text(),z=u5(G);if(!z)throw new m({code:"provider_error",message:"The provider started a realtime call but did not say which one (no Location).",retryable:!1});return{sdpAnswer:V,callId:z}}async clientSecret(Q={}){let $=Q.ttlSeconds??k5;if(!Number.isInteger($)||$<dQ||$>pQ)throw RangeError(`ttlSeconds must be a whole number from ${dQ} to ${pQ}, 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:a(Q.session??{},this.model)})},Q.signal)).json();if(typeof Y?.value!=="string")throw new m({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(g5(J,Q))return;throw J}}sideband(Q,$={}){return new BQ({...$,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 c(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 m(D(Z),{cause:Z,...Z instanceof A?{status:Z.status}:{}})}}}function g5(Q,$){if(!(Q instanceof m)||Q.status!==404)return!1;let J=Q.cause instanceof A?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 u5(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 c5={"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 m5(Q){if(typeof Q!=="string")return;let $;try{$=JSON.parse(Q)}catch{return}if(!$||typeof $!=="object"||typeof $.type!=="string")return;let J=c5[$.type];if(J)$.type=J;if($.type==="response.done"&&$.response?.usage)$.usage=jQ($.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=jQ($.usage);return $}var nQ=1,d5=500;function p5(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 BQ{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===nQ)this.socket.send($);else this.outbox.push($)}updateSession(Q){this.send({type:"session.update",session:a(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<=nQ)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??p5)(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=m5(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>d5)this.backlog.shift()}for(let $ of this.subscribers){if($.done)continue;$.queue.push(Q),$.wake?.()}for(let $ of this.listeners)try{$(Q)}catch{}}}var aQ=3;function zQ(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 oQ(Q,$,J=new Map){if(!($ instanceof A))return[];if($.status!==400&&$.status!==404)return[];let Z=FQ($.body);if(!Z)return[];let Y=l5(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])],B=qQ(K)[Number(G[2])],H=B&&typeof B.file_id==="string"?B.file_id:void 0;if(H)return[H]}let V=Z.message??"",z=sQ(Y.map((K)=>K.fileId).filter((K)=>i5(V,K)));if(z.length>0)return z;let j=/Expected (image type|context stuffing file type) to be a supported format:.*but got \.([a-z0-9]+)\.?\s*$/is.exec(V);if(j){let K=j[1].toLowerCase()==="image type"?"input_image":"input_file",B=j[2].toLowerCase(),H=sQ(Y.filter((X)=>X.type===K).map((X)=>X.fileId)),W=H.filter((X)=>(J.get(X)?.name??"").trim().toLowerCase().endsWith(`.${B}`));if(W.length===1)return W;if(W.length===0&&H.length===1)return H}return[]}function tQ(Q,$,J=new Map){return{...Q,input:Q.input.map((Z)=>{let Y=qQ(Z);if(!Y.some((G)=>rQ(G,$)))return Z;return{...Z,content:Y.map((G)=>rQ(G,$)?{type:"input_text",text:d(J.get(String(G.file_id))?.name)}:G)}})}}function d(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 rQ(Q,$){return typeof Q.file_id==="string"&&$.has(Q.file_id)}function qQ(Q){let $=Q?.content;return Array.isArray($)?$:[]}function l5(Q){let $=[];for(let J of Q)for(let Z of qQ(J))if(typeof Z.file_id==="string"&&Z.file_id)$.push({type:String(Z.type),fileId:Z.file_id});return $}function FQ(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 i5(Q,$){let J=$.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return new RegExp(`(^|[^A-Za-z0-9_-])${J}($|[^A-Za-z0-9_-])`).test(Q)}function sQ(Q){return[...new Set(Q)]}function eQ(Q,$){if(!($ instanceof A))return null;if($.status!==400&&$.status!==404)return null;let J=Q?.input;if(!Array.isArray(J))return null;let Z=FQ($.body)?.message??"",Y=/Item with id '([^']+)' not found/i.exec(Z)?.[1];if(!Y)return null;let G=(V)=>V?.type==="reasoning";if(!J.some((V)=>G(V)&&V.id===Y))return null;return{...Q,input:J.filter((V)=>!G(V))}}async function*LQ(Q){let $="",J="",Z=[],Y,G=()=>{if(Z.length===0&&!J)return null;let j={event:J,data:Z.join(`
3
- `),id:Y};return J="",Z=[],Y=void 0,j.data?j:null},V=(j)=>{let K=j.endsWith("\r")?j.slice(0,-1):j;if(K==="")return G();if(K.startsWith(":"))return null;let B=K.indexOf(":"),H=B===-1?K:K.slice(0,B),W=B===-1?"":K.slice(B+1);if(W.startsWith(" "))W=W.slice(1);if(H==="event")J=W;else if(H==="data")Z.push(W);else if(H==="id")Y=W;return null};for await(let j of Q){$+=j;let K=$.indexOf(`
4
- `);while(K!==-1){let B=$.slice(0,K);$=$.slice(K+1);let H=V(B);if(H)yield H;K=$.indexOf(`
5
- `)}}if($.length>0){let j=V($);if(j)yield j}let z=G();if(z)yield z}async function*Q5(Q,$={}){let J=new Map,Z=new Set,Y,G=!1,V,z=(j,K)=>({type:"finish",reason:j,usage:K,...V?{model:V}:{}});for await(let j of LQ(Q)){if(j.data==="[DONE]")break;let K;try{K=JSON.parse(j.data)}catch{continue}let B=typeof K.type==="string"?K.type:j.event,H=K.response?.model;if(typeof H==="string"&&H)V=H;switch(B){case"response.output_text.delta":{let W=String(K.delta??"");if(!W)break;yield $.structuredOutput?{type:"output-delta",delta:W}:{type:"text-delta",delta:W};break}case"response.reasoning_summary_text.delta":case"response.reasoning_text.delta":{let W=String(K.delta??"");if(!W)break;yield{type:"reasoning-delta",delta:W,id:K.item_id};break}case"response.output_item.added":{let W=K.item;if(!W)break;if(W.type==="function_call"){let X=String(W.id??K.item_id??W.call_id??"");J.set(X,{callId:String(W.call_id??X),name:String(W.name??""),namespace:typeof W.namespace==="string"&&W.namespace?W.namespace:void 0,done:!1})}break}case"response.function_call_arguments.delta":{let W=J.get(String(K.item_id??""));if(!W)break;let X=String(K.delta??"");if(!X)break;yield{type:"tool-call-delta",toolCallId:W.callId,name:W.name,argsDelta:X,...W.namespace?{namespace:W.namespace}:{}};break}case"response.function_call_arguments.done":{let W=String(K.item_id??""),X=J.get(W);if(!X)break;X.done=!0,yield{type:"tool-call",toolCallId:X.callId,name:X.name,args:String(K.arguments??""),...X.namespace?{namespace:X.namespace}:{}};break}case"response.output_item.done":{let W=K.item;if(!W)break;if(W.type==="function_call"){let X=String(W.id??K.item_id??W.call_id??""),q=J.get(X);if(q?.done)break;let F=(typeof W.namespace==="string"?W.namespace:"")||q?.namespace;if(yield{type:"tool-call",toolCallId:String(W.call_id??X),name:String(W.name??q?.name??""),args:String(W.arguments??""),...F?{namespace:F}:{}},q)q.done=!0;break}if(W.type==="tool_search_call"||W.type==="tool_search_output"){if(W.type==="tool_search_call"&&W.arguments!==void 0)Y=W.arguments;let X=n5(W);if(X.loaded.length===0&&X.namespaces.length===0)break;let q=String(W.tool_search_call_id??W.id??"");if(Z.has(q))break;Z.add(q);let F=Y;Y=void 0,yield{type:"tool-search",...X,...F!==void 0&&F!==null?{arguments:F}:{}}}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",UQ(K.response?.usage));break}case"response.incomplete":{G=!0;let W=UQ(K.response?.usage),X=K.response?.incomplete_details?.reason;if(X==="content_filter"){yield{type:"error",error:{code:"content_filtered",message:r5(K.response?.content_filters),retryable:!1}},yield z("error",W);break}yield z(X==="max_output_tokens"?"length":"stop",W);break}case"response.failed":case"error":{G=!0;let W=K.response?.error??K.error??K;yield{type:"error",error:s5(W),...t(W)},yield z("error",UQ(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",S())}function n5(Q){let $=[],J=[];return $5(Q.results??Q.tools??Q.loaded??Q.output,$,J,0),{loaded:CQ($),namespaces:CQ(J)}}function $5(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,V=typeof G.name==="string"?G.name:typeof G.tool_name==="string"?G.tool_name:"",z=G.tools??G.functions;if(Array.isArray(z)){if(V)J.push(V);$5(z,$,J,Z+1);continue}if(V)$.push(V)}}function CQ(Q){return Q.filter(($,J)=>Q.indexOf($)===J)}function r5(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[V,z]of Object.entries(G))if(z&&typeof z==="object"&&z.filtered===!0)J.push(`${V} (${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: ${CQ(J).join(", ")}.`}function s5(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 S(){return{inputTokens:0,outputTokens:0,totalTokens:0}}function UQ(Q){if(!Q)return S();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*J5(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 $Q(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,maxRetries:Q.maxRetries,...Q.retry?{retry:Q.retry}:{}}}async function*JQ(Q,$,J){let Z=J.parse??Q5,Y=$,G=new Set,V=0,z=!1,j=Math.max(0,Q.maxRetries),K=Q.random??Math.random,B,H=(O)=>{if(!B)return O;let L=e(e(S(),B),O.usage);return B=void 0,{...O,usage:L}},W=()=>H({type:"finish",reason:"aborted",usage:S()}),X=Q.streamIdleTimeoutMs??0,q=Q.streamMaxDurationMs??0,F=Q.maxToolArgumentChars??0,N=Q.now??Date.now,P=N();for(let O=0;;O++){let L=new AbortController,y=J.signal?AbortSignal.any([J.signal,L.signal]):L.signal,v;while(v===void 0)try{let C=[],U=()=>{},M=c(Q.responsesUrl,{method:"POST",headers:{...await Q.headers(),"content-type":"application/json"},body:JSON.stringify(Y)},{maxRetries:Q.maxRetries,timeoutMs:Q.timeoutMs,signal:y,fetchImpl:Q.fetchImpl,sleep:Q.sleep,random:Q.random,now:Q.now,startedAt:P,...Q.retry?{retry:Q.retry}:{},onRetry:(h)=>{C.push({type:"retry",...h,phase:"request"}),U()}}),w=M.then(()=>!0,()=>!0);for(;;){let h=new Promise((n)=>U=()=>n(!1)),u=await Promise.race([w,h]);if(yield*C.splice(0),u)break}v=await M}catch(C){let U=Y,M=J.files&&V<aQ?oQ(U,C,J.files).filter((u)=>!G.has(u)):[];if(M.length>0){V++;let u=D(C).message;for(let n of M)G.add(n),yield{type:"file-rejected",fileId:n,message:u,...k(C)};Y=tQ(U,new Set(M),J.files);continue}let w=z?null:eQ(Y,C);if(w){z=!0,Y=w;continue}let h=D(C);if(h.code==="aborted"){yield W();return}yield{type:"error",error:h,...k(C)},yield H({type:"finish",reason:"error",usage:S()});return}let _=[],R=!1,I,WQ=!1,T,g=new Map;try{let C=mQ(v.body,{idleMs:X,maxMs:q},{idle:()=>{let U=new Z5(X);return L.abort(U),U},max:()=>{let U=new Y5(q);return L.abort(U),U}});for await(let U of Z(J5(C),{structuredOutput:J.structuredOutput})){if(U.type==="tool-call-delta"){let M=(g.get(U.toolCallId)??0)+U.argsDelta.length;if(g.set(U.toolCallId,M),F>0&&M>F){let w=new NQ(F,U.name,U.toolCallId,M);throw L.abort(w),w}yield U;continue}if(U.type==="tool-call")g.delete(U.toolCallId);if(R){yield U.type==="finish"?H(U):U;continue}if(QQ(U)){R=!0,yield*_.splice(0),yield U;continue}if(U.type==="error")I=U.error;_.push(U)}}catch(C){WQ=C instanceof s;let U=D(C);if(U.code==="aborted"||J.signal?.aborted){yield W();return}if(R){yield{type:"error",error:U},yield H({type:"finish",reason:"error",usage:S()});return}if(I=U,C instanceof NQ)T=C.detail;_.push({type:"error",error:U,...T?{toolArgumentsTooLong:T}:{}},{type:"finish",reason:"error",usage:S()})}if(R)return;let l={};for(let C of _)if(C.type==="error")l=k(C);let i=!I?.retryable||J.signal?.aborted||T&&J.retryToolArgumentsTooLong===!1?void 0:O<j?r(O,K):Q.retry&&VQ(Q.retry,I,{...l.status!==void 0?{status:l.status}:{},timedOut:WQ,...T?{toolArgumentsTooLong:T}:{}})?KQ(Q.retry,O-j,I.retryAfter,N()-P,K):void 0;if(i!==void 0){for(let U of _)if(U.type==="finish")B=e(B??S(),U.usage);if(g.size>0)yield{type:"tool-call-discard",toolCallIds:[...g.keys()]};let C=N()-P;yield{type:"retry",attempt:O+1,maxRetries:j,error:I,...l,phase:"stream",timedOut:WQ,...T?{toolArgumentsTooLong:T}:{},delayMs:i,elapsedMs:C,...Q.retry?{remainingMs:Math.max(0,Q.retry.patienceMs-C-i)}:{}};try{await XQ(i,J.signal,Q.sleep)}catch{yield W();return}continue}for(let C of _)yield C.type==="finish"?H(C):C;return}}async function ZQ(Q,$,J="user_data"){let Z=new FormData;if(J)Z.set("purpose",J);Z.set("file",$);let G=await(await c(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}function xQ(Q,$){let{capabilities:J}=$,Z={model:$.model,input:a5(Q.messages,J,Q.tools),stream:!0};if(Q.systemPrompt)Z.instructions=Q.systemPrompt;let Y=G6(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 a5(Q,$,J){let Z=[],Y=new Map;if($.toolSearch){for(let G of J??[])if(YQ(G))Y.set(G.name,G)}for(let G of Q){let V=G.role,z=!J6.has(G.finishReason),j=[],K=()=>{if(j.length===0)return;Z.push({type:"message",role:V,content:j}),j=[]};for(let B of G.content??[])switch(B.type){case"text":{if(!B.text)break;j.push(b(V,B.text));break}case"output":{if(B.partial)break;j.push(b(V,JSON.stringify(B.value)));break}case"file":{if(V==="assistant")break;let H=DQ(B);if(!$.fileInput){if(H)j.push(b(V,p(B,!1)));break}if(SQ(B,H),B.providerRejected){if(H)j.push(b(V,p(B,!1)));j.push(b(V,d(B.name)));break}if(H)j.push(b(V,p(B,!!B.fileId)));if(B.fileId)j.push(e5(B));break}case"reasoning":{if(K(),!z)break;let H=Z6(B);if(H)Z.push(H);break}case"tool-call":{if(B.partial)break;if(K(),$.toolSearch&&Array.isArray(B.toolSearches))for(let W of B.toolSearches)Z.push(...Y6(W,J??[]));let H={type:"function_call",call_id:B.toolCallId,name:String(B.name),arguments:JSON.stringify(B.input??{})};if(B.namespace&&Y.has(B.namespace))H.namespace=B.namespace;Z.push(H);break}case"tool-result":{K(),Z.push({type:"function_call_output",call_id:B.toolCallId,output:MQ(B)});break}}K()}return t5(Z)}var o5="No result was recorded for this tool call. Assume it did not complete.";function t5(Q){let $=new Set,J=new Set,Z=[];for(let G of Q){if(G.type==="function_call"){let V=String(G.call_id);if($.has(V))continue;$.add(V)}else if(G.type==="function_call_output"){let V=String(G.call_id);if(!$.has(V)||J.has(V))continue;J.add(V)}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 V=String(G.call_id);if(J.has(V))continue;J.add(V),Y.push({type:"function_call_output",call_id:V,output:o5})}return Y}function b(Q,$){return{type:Q==="assistant"?"output_text":"input_text",text:$}}function DQ(Q){let $=Q.attachmentId;return typeof $==="string"&&$.startsWith(PQ)?$:void 0}function p(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 e5(Q){return{type:OQ(Q)?"input_image":"input_file",file_id:Q.fileId}}function OQ(Q){let $=Q.mimeType?.trim().toLowerCase()??"";return $?$.startsWith("image/")&&$!=="image/svg+xml":Q6(Q.name)}function SQ(Q,$){if(Q.fileId?.startsWith(PQ))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 Q6(Q){let $=/\.([a-z0-9]+)$/.exec(Q?.trim().toLowerCase()??"");return $?.[1]!==void 0&&$6.has($[1])}var $6=new Set(["jpeg","jpg","png","gif","webp"]),J6=new Set(["error","aborted","interrupted"]);function Z6(Q){if(!Q.id)return null;let $={type:"reasoning",id:Q.id};return $.summary=Q.text?[{type:"summary_text",text:Q.text}]:[],$}function MQ(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 Y6(Q,$){let J=new Set(G5(Q?.loaded)),Z=G5(Q?.namespaces),Y=new Set(Z),G=[];for(let z of $)if(YQ(z)){if(!Y.has(z.name))continue;let j=z.tools.filter((K)=>J.size===0||J.has(K.name));if(j.length===0)continue;G.push({type:"namespace",name:z.name,description:z.description,tools:j.map((K)=>f(K,!0))})}else if(z.deferred&&J.has(z.name))G.push(f(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 G5(Q){return Array.isArray(Q)?Q.filter(($)=>typeof $==="string"):[]}function YQ(Q){return Array.isArray(Q.tools)}function G6(Q,$){if(!Q||Q.length===0)return[];if(!$.toolSearch){let Y=[];for(let G of Q)if(YQ(G))for(let V of G.tools)Y.push(f(V,!1));else Y.push(f(G,!1));return Y}let J=[],Z=!1;for(let Y of Q)if(YQ(Y)){let G=Y.tools.map((V)=>{if(V.deferred)Z=!0;return f(V,!0)});J.push({type:"namespace",name:Y.name,description:Y.description,tools:G})}else{if(Y.deferred)Z=!0;J.push(f(Y,!0))}if(Z)J.push({type:"tool_search"});return J}function f(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 W6=64000;function W5(Q,$){let J={model:$.model,max_tokens:Q.maxOutputTokens??W6,messages:C6(Q.messages,$.capabilities),stream:!0},Z=Q.output,Y=!!Z?.strict&&!q6(Z.schema),G=Z&&!Y?F6(Z.schema):void 0,V=[Q.systemPrompt,G].filter(Boolean);if(V.length>0)J.system=[{type:"text",text:V.join(`
6
-
7
- `)}];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:K6(z,$.modelId)};else if($.capabilities.reasoning&&V6(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:z6(Z.schema)}};let j=R6(Q.tools);if(j.length>0){J.tools=j;let K=U6(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 X6(J)}function V6(Q){return Q.some(($)=>$.content.some((J)=>J.type==="thinking"||J.type==="redacted_thinking"))}var _Q="thinking-binding-controls-2026-08-01";function V5(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 K5(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 K6(Q,$){if(Q==="none"||Q==="minimal")return"low";if(Q==="xhigh"&&/^claude-(?:opus|sonnet)-4-6(?:-|$)/.test($))return"high";return Q}function X6(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 B6=new Set(["minimum","maximum","exclusiveMinimum","exclusiveMaximum","multipleOf","minLength","maxLength","maxItems","uniqueItems"]),H6=new Set(["date-time","time","date","duration","email","hostname","uri","ipv4","ipv6","uuid"]),j6=/\\[1-9]|\(\?<?[=!]|\\[bB]/,X5=new Set(["properties","patternProperties","$defs","definitions"]);function z6(Q){let $=(J)=>{if(Array.isArray(J))return J.map($);if(!E(J))return J;let Z={},Y=[];for(let[G,V]of Object.entries(J)){if(B6.has(G)||G==="minItems"&&typeof V==="number"&&V>1||G==="format"&&typeof V==="string"&&!H6.has(V)||G==="pattern"&&typeof V==="string"&&j6.test(V)){Y.push(`${G}: ${JSON.stringify(V)}`);continue}Z[G]=X5.has(G)&&E(V)?Object.fromEntries(Object.entries(V).map(([j,K])=>[j,$(K)])):$(V)}if(Y.length>0){let G=`{${Y.join(", ")}}`;Z.description=typeof Z.description==="string"?`${Z.description} ${G}`:G}if(Z.type==="object"||E(Z.properties))Z.additionalProperties=!1;return Z};return $(Q)}function q6(Q){let $=0,J=0,Z=(Y)=>{if(Array.isArray(Y))return Y.forEach(Z);if(!E(Y))return;if(Array.isArray(Y.anyOf)||Array.isArray(Y.type))J++;if(E(Y.properties)){let G=new Set(Array.isArray(Y.required)?Y.required:[]);$+=Object.keys(Y.properties).filter((V)=>!G.has(V)).length}for(let[G,V]of Object.entries(Y))if(X5.has(G)&&E(V))Object.values(V).forEach(Z);else Z(V)};return Z(Q),$>24||J>16}function F6(Q){return`Answer with only a JSON value (no prose, no code fence) that matches this JSON schema:
8
- ${JSON.stringify(Q)}`}function U6(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 C6(Q,$){let J=[],Z=new Map;for(let B of Q){let H=B.role==="assistant"?"assistant":"user";J.push("step-end");for(let W of B.content??[])switch(W.type){case"text":{if(H==="assistant"?!!W.text:!!W.text?.trim())J.push({role:H,block:{type:"text",text:W.text}});break}case"output":{if(W.partial)break;let X=W.text??JSON.stringify(W.value);J.push({role:H,block:{type:"text",text:X}});break}case"file":{if(H==="assistant")break;for(let X of O6(W,$))J.push({role:H,block:X});break}case"reasoning":{let X=H==="assistant"?D6(W):void 0;if(X)J.push({role:H,block:X});break}case"tool-call":{if(W.partial)break;J.push({role:"assistant",block:{type:"tool_use",id:W.toolCallId,name:String(W.name),input:E(W.input)?W.input:{}}});break}case"tool-result":{if(J.push("step-end"),Z.has(W.toolCallId))break;Z.set(W.toolCallId,{type:"tool_result",tool_use_id:W.toolCallId,content:MQ(W),...W.status==="error"?{is_error:!0}:{}});break}}}let Y=[],G=(B,H)=>{let W=Y[Y.length-1];if(W&&W.role===B)W.content.push(H);else Y.push({role:B,content:[H]})},V=new Set,z=[],j=!1,K=()=>{for(let B of z)G("user",Z.get(B)??x6(B));z=[],j=!1};for(let B of J){if(B==="step-end"){j=!0;continue}let{role:H,block:W}=B;if(j||H==="user")K();if(W.type==="tool_use"){let X=String(W.id);if(V.has(X))continue;V.add(X),z.push(X)}G(H,W)}if(K(),Y[0]?.role==="assistant")Y.unshift({role:"user",content:[{type:"text",text:L6}]});if(Y.at(-1)?.role==="assistant")Y.push({role:"user",content:[{type:"text",text:N6}]});return Y}var L6="(The conversation continues from an earlier point.)",N6="Continue.",P6="No result was recorded for this tool call. Assume it did not complete.";function x6(Q){return{type:"tool_result",tool_use_id:Q,content:P6}}function D6(Q){let $=Q.providerMetadata?.anthropic;if(!E($))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 O6(Q,$){let J=DQ(Q),Z=(G)=>J?[{type:"text",text:p(Q,G)}]:[];if(!$.fileInput)return Z(!1);if(SQ(Q,J),!Q.fileId)return Z(!1);let Y=Q.providerRejected?void 0:M6(Q);if(!Y)return[...Z(!1),{type:"text",text:d(Q.name)}];return[...Z(!0),{type:Y,source:{type:"file",file_id:Q.fileId}}]}var S6=new Set(["image/jpeg","image/png","image/gif","image/webp"]);function M6(Q){let $=Q.mimeType?.trim().toLowerCase()??"";if(OQ(Q))return!$||S6.has($)?"image":void 0;if($)return $==="application/pdf"||$==="text/plain"?"document":void 0;return/\.(pdf|txt)$/i.test(Q.name??"")?"document":void 0}function E(Q){return!!Q&&typeof Q==="object"&&!Array.isArray(Q)}function _6(Q){return Array.isArray(Q.tools)}function R6(Q){let $=[];for(let J of Q??[])for(let Z of _6(J)?J.tools:[J])$.push({name:Z.name,description:Z.description,input_schema:Z.parameters,eager_input_streaming:!0});return $}async function*z5(Q,$={}){let J=new Map,Z=[],Y,G={},V,z,j=!1,K=(B)=>({type:"finish",reason:B,usage:w6(G),...Y?{model:Y}:{}});for await(let B of LQ(Q)){let H;try{H=JSON.parse(B.data)}catch{continue}switch(typeof H.type==="string"?H.type:B.event){case"message_start":{let X=H.message??{};if(typeof X.model==="string"&&X.model)Y=X.model;G=j5(G,X.usage);break}case"content_block_start":{let X=Number(H.index),q=H.content_block??{},F={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(X,F),F.type==="redacted_thinking")yield{type:"reasoning-delta",delta:"",providerMetadata:{anthropic:{type:"redacted_thinking",data:String(q.data??"")}}};if(F.type==="text"&&typeof q.text==="string"&&q.text)yield H5(q.text,$);break}case"content_block_delta":{let X=J.get(Number(H.index)),q=H.delta??{};if(!X)break;if(q.type==="text_delta"){let F=String(q.text??"");if(F)yield H5(F,$)}else if(q.type==="thinking_delta"){let F=String(q.thinking??"");if(F)yield{type:"reasoning-delta",delta:F}}else if(q.type==="signature_delta")X.signature+=String(q.signature??"");else if(q.type==="input_json_delta"&&X.type==="tool_use"){let F=String(q.partial_json??"");if(!F)break;X.args+=F,yield{type:"tool-call-delta",toolCallId:X.id??"",name:X.name??"",argsDelta:F}}break}case"content_block_stop":{let X=Number(H.index),q=J.get(X);if(J.delete(X),q?.type==="thinking")yield{type:"reasoning-delta",delta:"",providerMetadata:{anthropic:{type:"thinking",signature:q.signature}}};if(q?.type==="tool_use")if(q.args||="{}",I6(q.args))yield B5(q);else Z.push(q);break}case"message_delta":{if(typeof H.delta?.stop_reason==="string")V=H.delta.stop_reason;if(H.delta?.stop_details)z=H.delta.stop_details;G=j5(G,H.usage);break}case"message_stop":{if(j=!0,V==="refusal"){yield{type:"error",error:T6(z)},yield K("error");break}let X=A6(V);if(Z.length>0&&X==="length")yield{type:"tool-call-discard",toolCallIds:Z.map((q)=>q.id??"")};else for(let q of Z)yield B5(q);yield K(X);break}case"error":{j=!0;let X=H.error??H;yield{type:"error",error:E6(X),...t(X)},yield K("error");break}}if(j)return}yield{type:"error",error:{code:"provider_error",message:"The provider stream ended without a terminal event.",retryable:!0}},yield K("error")}function B5(Q){return{type:"tool-call",toolCallId:Q.id??"",name:Q.name??"",args:Q.args}}function I6(Q){try{return JSON.parse(Q),!0}catch{return!1}}function H5(Q,$){return $.structuredOutput?{type:"output-delta",delta:Q}:{type:"text-delta",delta:Q}}function A6(Q){if(Q==="max_tokens"||Q==="model_context_window_exceeded")return"length";return"stop"}function T6(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 E6(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 j5(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 w6(Q){if(!Q)return S();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 RQ(Q){let $=AQ(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=v6($);if(J?.kind==="o")return{reasoning:!0,structuredOutput:!0,fileInput:!0,parallelToolCalls:J.major>1,toolSearch:q5(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:q5(J),supportsForcedToolChoice:!0};return{reasoning:!0,structuredOutput:!0,fileInput:!0,parallelToolCalls:!0,toolSearch:!0,supportsForcedToolChoice:!0}}function q5(Q){if(Q.kind==="o")return Q.major>=5;return Q.major>5||Q.major===5&&Q.minor>=2}function IQ(Q){let $=AQ(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:k6(Q)}}function k6(Q){let $=AQ(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 AQ(Q){return Q.trim().toLowerCase()}function v6(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 TQ=120000,EQ=2,wQ=120000,kQ=300000;function x(Q){return typeof process>"u"?void 0:process.env?.[Q]}var h6="preview";function F5(Q){let $=Q.trim().replace(/\/+$/,"");if(!$)return"";return`${$.replace(/\/openai(?:\/v1)?$/i,"")}/openai`}function b6(Q){return/^\d{4}-\d{2}-\d{2}/.test(Q)?"":"/v1"}function vQ(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??TQ,streamIdleTimeoutMs:Q.streamIdleTimeoutMs??wQ,streamMaxDurationMs:Q.streamMaxDurationMs??kQ,maxToolArgumentChars:Q.maxToolArgumentChars??0,maxRetries:Q.maxRetries??EQ,...bQ(Q)}}function U5(Q){let $=Q.baseURL??Q.endpoint??x("AZURE_OPENAI_ENDPOINT");if($)return F5($);let J=Q.resourceName??x("AZURE_OPENAI_RESOURCE_NAME")??x("AZURE_RESOURCE_NAME");return J?F5(`https://${J.trim()}.cognitiveservices.azure.com`):""}function hQ(Q,$={}){let J=Q.apiVersion??x("AZURE_OPENAI_API_VERSION")??h6;return{base:`${U5(Q)}${b6(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??TQ,streamIdleTimeoutMs:Q.streamIdleTimeoutMs??wQ,streamMaxDurationMs:Q.streamMaxDurationMs??kQ,maxToolArgumentChars:Q.maxToolArgumentChars??0,maxRetries:Q.maxRetries??EQ,...bQ(Q)}}var f6="2026-10-21";function C5(Q,$={}){let J=Q.baseURL??x("ANTHROPIC_BASE_URL")??"https://api.anthropic.com";return N5(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 V=x("ANTHROPIC_AUTH_TOKEN");return V?{authorization:`Bearer ${V}`,...Y}:Y})}function L5(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 N5(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 N5(Q,$,J,Z){return{base:`${Q.trim().replace(/\/+$/,"").replace(/\/v1$/,"")}/v1`,query:"",headers:async()=>({...await Z(),"anthropic-version":f6,...$.headers}),timeoutMs:$.timeoutMs??J.timeoutMs??TQ,streamIdleTimeoutMs:$.streamIdleTimeoutMs??wQ,streamMaxDurationMs:$.streamMaxDurationMs??kQ,maxToolArgumentChars:$.maxToolArgumentChars??0,maxRetries:$.maxRetries??EQ,...bQ($)}}function P5(Q,$={}){return{...hQ(Q,$),base:`${U5(Q)}/v1`,query:""}}function bQ(Q){return yQ(Q.retry),Q.retry?{retry:Q.retry}:{}}class GQ{static models(){return[]}normalizeError(Q){return D(Q)}}var x5=["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 D5 extends GQ{model;capabilities;config;constructor(Q,$={}){super();this.model=Q,this.capabilities=RQ(Q),this.config=$}static model(Q,$){return new D5(Q,$)}static models(){return x5}stream(Q){let $=xQ(Q,{model:this.model,capabilities:this.capabilities});return JQ(this.endpoint(),$,{signal:Q.signal,retryToolArgumentsTooLong:Q.retryToolArgumentsTooLong,structuredOutput:Boolean(Q.output),files:zQ(Q.messages)})}upload(Q){return ZQ(this.endpoint(),Q)}endpoint(){return $Q(vQ(this.config))}get realtime(){return new o(vQ(this.config,{timeoutMs:HQ}),{model:this.model})}}var y6=["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 fQ extends GQ{model;capabilities;config;constructor(Q,$={}){super();this.model=Q,this.capabilities=IQ(Q),this.config=$}static model(Q,$){return new fQ(Q,$)}static models(){return y6}stream(Q){return this.send(Q)}async*send(Q){let $=Q,J=!1,Z=new Set;for(;;){let Y=this.request($);if(J)Y=K5(Y);let G,V=!1;for await(let z of JQ(this.endpointFor(Y),Y,{signal:Q.signal,retryToolArgumentsTooLong:Q.retryToolArgumentsTooLong,structuredOutput:Boolean(Q.output),parse:z5})){if(G)continue;if(!V&&z.type==="error"&&z.status===400){let j=V5(z.error.message);if(j&&!Z.has(j)){Z.add(j),G=j;continue}}if(QQ(z))V=!0;yield z}if(!G)return;if(G==="thinking")J=!0;else if($.output)$={...$,output:{...$.output,strict:!1}}}}request(Q){return W5(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},${_Q}`:_Q}}}}bindsThinking(){return!0}deployment(){return this.model}upload(Q){return ZQ(this.endpoint(),Q,null)}endpoint(){return O5(C5(this.config))}}function O5(Q){return{...$Q(Q),responsesUrl:`${Q.base}/messages`}}class S5 extends fQ{constructor(Q,$={}){super(Q,$);this.capabilities={...IQ(Q),fileInput:!1}}static model(Q,$){return new S5(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."))}deployment(){return this.config.deployment??this.model}bindsThinking(){return!1}endpoint(){return O5(L5(this.config))}}class M5 extends GQ{model;capabilities;config;constructor(Q,$={}){super();this.model=Q,this.capabilities=RQ(Q),this.config=$}static model(Q,$){return new M5(Q,$)}static models(){return x5}stream(Q){let $=xQ(Q,{model:this.deployment(),capabilities:this.capabilities});return JQ(this.endpoint(),$,{signal:Q.signal,retryToolArgumentsTooLong:Q.retryToolArgumentsTooLong,structuredOutput:Boolean(Q.output),files:zQ(Q.messages)})}upload(Q){return ZQ(this.endpoint(),Q,"assistants")}deployment(){return this.config.deployment??this.model}endpoint(){return $Q(hQ(this.config))}get realtime(){return new o(P5(this.config,{timeoutMs:HQ}),{model:this.deployment(),callFlow:"ephemeral"})}}
9
- export{c as ca,vQ as da,hQ as ea,BQ as fa,v5 as ga,jQ as ha,m as ia,o as ja,g5 as ka,GQ as la,D5 as ma,fQ as na,S5 as oa,M5 as pa};
10
-
11
- //# debugId=3F83ED3EB895689964756E2164756E21
@@ -1,5 +0,0 @@
1
- // @bun
2
- import{Me as o}from"./chunk-wcj083k2.js";import{Ne as i}from"./chunk-5cf59esb.js";import{_k as t}from"./chunk-zbxvyanj.js";import{dm as r}from"./chunk-4zw9gaey.js";class n extends i{register(){this.app.singleton(r,()=>new r(t(o(),this.app.config.get("translation",{}))))}}
3
- export{n as pb};
4
-
5
- //# debugId=070418716567C2F564756E2164756E21