@shumai-one/shumai 0.4.2 → 0.4.4

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 (269) hide show
  1. package/bin/chunk-071x515q.js +4 -0
  2. package/bin/{chunk-adekdctx.css → chunk-0ccg9ddn.css} +1 -1
  3. package/bin/chunk-0cmx7k4c.js +1 -0
  4. package/bin/chunk-0qaq0sp8.js +5 -0
  5. package/bin/chunk-0qjfahk9.js +2 -0
  6. package/bin/chunk-0zv3bks2.js +2 -0
  7. package/bin/chunk-16xax8kk.js +1 -0
  8. package/bin/chunk-1gvscz88.js +5 -0
  9. package/bin/chunk-1j27fzy1.js +2 -0
  10. package/bin/chunk-1t167cvj.js +11 -0
  11. package/bin/chunk-1xh34aew.js +2 -0
  12. package/bin/chunk-1zwajpwf.js +8 -0
  13. package/bin/chunk-2w5xqhjm.js +1 -0
  14. package/bin/chunk-3tedzb2j.js +54 -0
  15. package/bin/chunk-3ttrhqy3.js +2 -0
  16. package/bin/chunk-3zkasqb8.js +1 -0
  17. package/bin/chunk-453ykvaw.js +2 -0
  18. package/bin/chunk-4991gz3y.js +13 -0
  19. package/bin/chunk-4hkkdm2q.js +2 -0
  20. package/bin/chunk-4mjywsj8.js +3 -0
  21. package/bin/chunk-4v41a1r9.js +6 -0
  22. package/bin/chunk-4wy87hwd.js +3 -0
  23. package/bin/chunk-579e4wv4.js +3 -0
  24. package/bin/chunk-5adsx8x4.js +2 -0
  25. package/bin/chunk-5hg6kcfz.js +45 -0
  26. package/bin/chunk-5nm2jvg5.js +32 -0
  27. package/bin/chunk-5tcdwep5.js +11 -0
  28. package/bin/chunk-5vzrpz50.js +2 -0
  29. package/bin/chunk-6ghcj4a9.js +3 -0
  30. package/bin/chunk-77fmkpdz.js +10 -0
  31. package/bin/chunk-7bcxj1jd.js +2 -0
  32. package/bin/chunk-7gmdnsdg.js +2 -0
  33. package/bin/chunk-7jtmwt5a.js +3 -0
  34. package/bin/chunk-7kjgvxqa.js +2 -0
  35. package/bin/chunk-7pw1550a.js +2 -0
  36. package/bin/chunk-7rhz2gze.js +211 -0
  37. package/bin/chunk-837fky18.js +3 -0
  38. package/bin/chunk-84as6x83.js +1 -0
  39. package/bin/chunk-8e28hcny.js +2 -0
  40. package/bin/chunk-914bp49r.js +4 -0
  41. package/bin/chunk-97f2af6d.js +12 -0
  42. package/bin/chunk-98715kc3.js +2 -0
  43. package/bin/chunk-9ccw540k.js +2 -0
  44. package/bin/chunk-9t8n2des.js +2 -0
  45. package/bin/chunk-9ybt6vbm.js +1 -0
  46. package/bin/chunk-a6gx7f5q.js +1 -0
  47. package/bin/chunk-avwgktxb.js +2 -0
  48. package/bin/chunk-bkr5zm4h.js +2 -0
  49. package/bin/chunk-cbgq517y.js +2 -0
  50. package/bin/chunk-d27mm390.js +1 -0
  51. package/bin/chunk-dj92fss9.js +2 -0
  52. package/bin/chunk-dqxeztfa.js +2 -0
  53. package/bin/chunk-drepsbb4.js +2 -0
  54. package/bin/chunk-f6svp4dp.js +2 -0
  55. package/bin/chunk-fahk9h62.js +8 -0
  56. package/bin/chunk-fb40xxz3.js +3 -0
  57. package/bin/chunk-fnmwksnb.js +3 -0
  58. package/bin/chunk-fpc4p0j8.js +3 -0
  59. package/bin/chunk-fsyzs0tf.js +1 -0
  60. package/bin/chunk-fxecgp5k.js +1 -0
  61. package/bin/chunk-g3fpmyyn.js +3 -0
  62. package/bin/chunk-gc5sbfa5.js +2 -0
  63. package/bin/chunk-gdm6yfqq.js +2 -0
  64. package/bin/chunk-gk2q9a3f.js +2 -0
  65. package/bin/chunk-gt4csat6.js +3 -0
  66. package/bin/chunk-gye8gabk.js +2 -0
  67. package/bin/chunk-hk5rc6cd.js +24 -0
  68. package/bin/chunk-hm0dkzed.js +3 -0
  69. package/bin/chunk-hmpwg5za.js +16 -0
  70. package/bin/chunk-j1tkmcae.js +3 -0
  71. package/bin/chunk-j2bvj2yn.js +2 -0
  72. package/bin/chunk-jffktpqg.js +1 -0
  73. package/bin/chunk-jgs8an3h.js +18 -0
  74. package/bin/chunk-jmpb5633.js +2 -0
  75. package/bin/chunk-jrjnqx78.js +2 -0
  76. package/bin/chunk-k2k9vjq6.js +1 -0
  77. package/bin/chunk-kpgfqkp0.js +3 -0
  78. package/bin/chunk-ks8xzc95.js +3 -0
  79. package/bin/chunk-kswvyqq1.js +2 -0
  80. package/bin/chunk-m9pr03kn.js +2 -0
  81. package/bin/chunk-mfn9qjm4.js +2 -0
  82. package/bin/chunk-msfw3jmc.js +3 -0
  83. package/bin/chunk-mz0yjra0.js +5 -0
  84. package/bin/chunk-nbdw8fen.js +1 -0
  85. package/bin/chunk-nkdk229f.js +2 -0
  86. package/bin/chunk-nr20tvnw.js +3 -0
  87. package/bin/chunk-pazjhrnf.js +12 -0
  88. package/bin/chunk-q806pqeh.js +1 -0
  89. package/bin/chunk-qka4mkmj.js +2 -0
  90. package/bin/chunk-qsr1a0rp.js +2 -0
  91. package/bin/chunk-rchsme43.js +3 -0
  92. package/bin/chunk-reyxk4bw.js +2 -0
  93. package/bin/chunk-rhvv1vvk.js +3 -0
  94. package/bin/chunk-rq0n0vcc.js +2 -0
  95. package/bin/chunk-rqf7999q.js +42 -0
  96. package/bin/chunk-rssgmj7x.js +2 -0
  97. package/bin/chunk-ryzz5fht.js +2 -0
  98. package/bin/chunk-s2fnfyn9.js +2 -0
  99. package/bin/chunk-s2k4qntr.js +3 -0
  100. package/bin/chunk-snhsjs4x.js +299 -0
  101. package/bin/chunk-t2hy6tj9.js +2 -0
  102. package/bin/chunk-t7nsgg5k.js +4 -0
  103. package/bin/chunk-tm7f32c7.js +14 -0
  104. package/bin/chunk-trveq4wg.js +3 -0
  105. package/bin/chunk-vap4k11j.js +20 -0
  106. package/bin/chunk-vm5fx7td.js +3 -0
  107. package/bin/chunk-vy8gntez.js +1 -0
  108. package/bin/chunk-vyzptrea.js +2 -0
  109. package/bin/chunk-w4ghe71n.js +2 -0
  110. package/bin/chunk-wdsf44hs.js +2 -0
  111. package/bin/chunk-wjyaezs7.js +2 -0
  112. package/bin/chunk-wndm3px3.js +1 -0
  113. package/bin/chunk-x5jwwvs0.js +1 -0
  114. package/bin/chunk-x92cq59c.js +1 -0
  115. package/bin/chunk-xa18z1py.js +3 -0
  116. package/bin/chunk-xarsrs08.js +2 -0
  117. package/bin/chunk-xtf3c29c.css +1 -0
  118. package/bin/chunk-xx337zcw.js +2 -0
  119. package/bin/chunk-xz6713tj.js +2 -0
  120. package/bin/chunk-yfnem6se.js +2 -0
  121. package/bin/chunk-ytdwk2fq.js +2 -0
  122. package/bin/chunk-ze20rm02.js +7 -0
  123. package/bin/chunk-zw86wnwe.js +7 -0
  124. package/bin/chunk-zxk7q0zk.js +2 -0
  125. package/bin/{pdf.worker.min-szxdj13d.mjs → pdf.worker.min-vf48er29.mjs} +14423 -13889
  126. package/bin/shumai-app.html +1 -1
  127. package/bin/shumai-app.js +841 -678
  128. package/package.json +18 -18
  129. package/prisma/migrations/20260904022457_add_agent_id_to_assets_and_audit_logs/migration.sql +17 -0
  130. package/prisma/migrations/20260906081230_default_denied_tools_delete_asset/migration.sql +15 -0
  131. package/prisma/migrations/20260907021754_add_asset_upload_id/migration.sql +2 -0
  132. package/prisma/schema.prisma +10 -0
  133. package/bin/chunk-07h4b77v.js +0 -2
  134. package/bin/chunk-0t4n4d5w.js +0 -4
  135. package/bin/chunk-1611z9jg.js +0 -2
  136. package/bin/chunk-1phqxp6z.js +0 -3
  137. package/bin/chunk-23hckrrz.js +0 -2
  138. package/bin/chunk-30z44j1g.js +0 -2
  139. package/bin/chunk-3j463k1g.js +0 -1
  140. package/bin/chunk-4181tdds.js +0 -14
  141. package/bin/chunk-480jtqng.js +0 -4
  142. package/bin/chunk-4c3g146q.js +0 -2
  143. package/bin/chunk-4ca0zt5e.js +0 -1
  144. package/bin/chunk-4d9bgmf2.js +0 -2
  145. package/bin/chunk-4ev56fss.js +0 -9
  146. package/bin/chunk-4gk52tjq.js +0 -45
  147. package/bin/chunk-4mdqkj4d.js +0 -1
  148. package/bin/chunk-4r91fggc.js +0 -2
  149. package/bin/chunk-50fb1x3w.js +0 -1
  150. package/bin/chunk-59gj1njz.js +0 -1
  151. package/bin/chunk-5pr0t7fb.js +0 -2
  152. package/bin/chunk-5vewxmz7.js +0 -3
  153. package/bin/chunk-62zx96pe.js +0 -2
  154. package/bin/chunk-63y0eb07.js +0 -2
  155. package/bin/chunk-6d5xrgfx.js +0 -2
  156. package/bin/chunk-6gbtz5bf.js +0 -67
  157. package/bin/chunk-6gjg5egq.js +0 -3
  158. package/bin/chunk-6m4jz9s1.js +0 -44
  159. package/bin/chunk-6s4x525w.js +0 -2
  160. package/bin/chunk-6w2wmvqs.js +0 -3
  161. package/bin/chunk-77d23vcn.js +0 -2
  162. package/bin/chunk-77m5p188.js +0 -2
  163. package/bin/chunk-7bvx087f.js +0 -1
  164. package/bin/chunk-7pfjfrjg.js +0 -5
  165. package/bin/chunk-7q10s127.js +0 -4
  166. package/bin/chunk-7thx8ctx.js +0 -3
  167. package/bin/chunk-8t4s91gh.js +0 -2
  168. package/bin/chunk-98ey5p2e.js +0 -3
  169. package/bin/chunk-9amndcyh.js +0 -6
  170. package/bin/chunk-9bk23g9x.js +0 -1
  171. package/bin/chunk-9mkcfy43.js +0 -1
  172. package/bin/chunk-9t3nsq5n.js +0 -2
  173. package/bin/chunk-9tjq99ds.js +0 -2
  174. package/bin/chunk-9wm9rwh1.js +0 -2
  175. package/bin/chunk-ab16fyg4.js +0 -4
  176. package/bin/chunk-arv0g2av.js +0 -1
  177. package/bin/chunk-aytj4zxg.js +0 -3
  178. package/bin/chunk-b1ypjqgp.js +0 -2
  179. package/bin/chunk-bdjv0ykq.js +0 -2
  180. package/bin/chunk-c1k86mfa.js +0 -10
  181. package/bin/chunk-caa96dgd.js +0 -2
  182. package/bin/chunk-ce4v2yjy.js +0 -1
  183. package/bin/chunk-cqh60y54.js +0 -3
  184. package/bin/chunk-cvq7zgw7.js +0 -1
  185. package/bin/chunk-d9mjbtp2.js +0 -2
  186. package/bin/chunk-dn7sbjws.js +0 -3
  187. package/bin/chunk-dxyq9h8n.js +0 -3
  188. package/bin/chunk-e3cabksx.js +0 -3
  189. package/bin/chunk-egcrbj94.js +0 -2
  190. package/bin/chunk-ev17v1mv.js +0 -2
  191. package/bin/chunk-evtpwg71.js +0 -2
  192. package/bin/chunk-f3e0nsv2.js +0 -2
  193. package/bin/chunk-f40gjqpq.js +0 -2
  194. package/bin/chunk-fe7822ak.js +0 -299
  195. package/bin/chunk-g8tkhw9j.js +0 -2
  196. package/bin/chunk-g9r0p4t8.js +0 -2
  197. package/bin/chunk-gbjyh9ms.js +0 -1
  198. package/bin/chunk-gtbsb39v.js +0 -3
  199. package/bin/chunk-gytz1q13.js +0 -13
  200. package/bin/chunk-h0fxysxs.js +0 -7
  201. package/bin/chunk-h8bdvsqt.js +0 -2
  202. package/bin/chunk-hag024w8.js +0 -2
  203. package/bin/chunk-hc6w5nw4.js +0 -7
  204. package/bin/chunk-j69dqc48.js +0 -2
  205. package/bin/chunk-jbtw1zym.js +0 -8
  206. package/bin/chunk-jc1vb7rj.js +0 -5
  207. package/bin/chunk-jdv78w9r.js +0 -2
  208. package/bin/chunk-jjs70y9v.js +0 -3
  209. package/bin/chunk-jmdar2gz.js +0 -2
  210. package/bin/chunk-jvwz10n4.js +0 -2
  211. package/bin/chunk-k47md1g4.js +0 -2
  212. package/bin/chunk-k4v0brcb.js +0 -2
  213. package/bin/chunk-k6n7c07e.js +0 -1
  214. package/bin/chunk-kk2cstsg.js +0 -2
  215. package/bin/chunk-knz4h56q.js +0 -12
  216. package/bin/chunk-kqqtt6bd.js +0 -3
  217. package/bin/chunk-kvyp1t4j.js +0 -7
  218. package/bin/chunk-kxskpgsq.js +0 -5
  219. package/bin/chunk-m6srbjcs.js +0 -2
  220. package/bin/chunk-mcc1scxs.js +0 -12
  221. package/bin/chunk-mq83a0kk.js +0 -2
  222. package/bin/chunk-mxm8g4q0.js +0 -1
  223. package/bin/chunk-nhpgdqq5.js +0 -2
  224. package/bin/chunk-nne496aa.js +0 -2
  225. package/bin/chunk-nqpb0r9h.js +0 -11
  226. package/bin/chunk-ns0zww9g.js +0 -2
  227. package/bin/chunk-ps4xfp23.js +0 -2
  228. package/bin/chunk-pz2ec6xt.js +0 -2
  229. package/bin/chunk-q163k309.js +0 -2
  230. package/bin/chunk-q1da61ps.js +0 -1
  231. package/bin/chunk-qrf0ady6.js +0 -68
  232. package/bin/chunk-qy28f25e.js +0 -2
  233. package/bin/chunk-r7s4ypw1.js +0 -2
  234. package/bin/chunk-ran23vm9.js +0 -1
  235. package/bin/chunk-rfvdc4n0.js +0 -2
  236. package/bin/chunk-rgthkvgx.js +0 -3
  237. package/bin/chunk-s39n3yw3.js +0 -2
  238. package/bin/chunk-s7wdd0g7.js +0 -8
  239. package/bin/chunk-s88ha5kx.js +0 -3
  240. package/bin/chunk-sf91bt9m.js +0 -2
  241. package/bin/chunk-sjwbjf9j.js +0 -2
  242. package/bin/chunk-t62076pv.js +0 -1
  243. package/bin/chunk-tbbwss3v.js +0 -3
  244. package/bin/chunk-tjcc7a6y.js +0 -24
  245. package/bin/chunk-tp6ab26e.js +0 -2
  246. package/bin/chunk-v2wxk9p5.js +0 -4
  247. package/bin/chunk-vbk6y4hk.js +0 -2
  248. package/bin/chunk-vfgfg5fk.js +0 -2
  249. package/bin/chunk-vm6c3xx9.js +0 -2
  250. package/bin/chunk-vsx96mt6.js +0 -3
  251. package/bin/chunk-wbyw1shz.js +0 -6
  252. package/bin/chunk-whh2vh50.css +0 -1
  253. package/bin/chunk-wjkcq65s.js +0 -2
  254. package/bin/chunk-wkefwkfp.js +0 -41
  255. package/bin/chunk-x7bsnk1e.js +0 -2
  256. package/bin/chunk-xbhw6bpz.js +0 -3
  257. package/bin/chunk-xg5yrcj5.js +0 -2
  258. package/bin/chunk-xg9xscqz.js +0 -1
  259. package/bin/chunk-xw2gpcsh.js +0 -3
  260. package/bin/chunk-ycq8ank7.js +0 -2
  261. package/bin/chunk-yp9hvkc5.js +0 -73
  262. package/bin/chunk-ytypyfkc.js +0 -65
  263. package/bin/chunk-z1kjmf60.js +0 -2
  264. package/bin/chunk-z36bx86r.js +0 -2
  265. package/bin/chunk-z7hdnecp.js +0 -3
  266. package/bin/chunk-zeby1cq7.js +0 -2
  267. package/bin/chunk-zs5e8z1w.js +0 -1
  268. package/bin/chunk-zxnyefg5.js +0 -2
  269. /package/bin/{chunk-24ke0th1.css → chunk-kegybs91.css} +0 -0
@@ -0,0 +1,2 @@
1
+ import{t,E}from"./chunk-7rhz2gze.js";function Tn({className:e,...a}){return t("div",{"data-slot":"table-container",className:"relative w-full overflow-x-auto",children:t("table",{"data-slot":"table",className:E("w-full caption-bottom text-sm",e),...a})})}function Mn({className:e,...a}){return t("thead",{"data-slot":"table-header",className:E("[&_tr]:border-b",e),...a})}function Rn({className:e,...a}){return t("tbody",{"data-slot":"table-body",className:E("[&_tr:last-child]:border-0",e),...a})}function _r({className:e,...a}){return t("tr",{"data-slot":"table-row",className:E("border-b transition-colors hover:bg-muted/50 has-aria-expanded:bg-muted/50 data-[state=selected]:bg-muted",e),...a})}function bt({className:e,...a}){return t("th",{"data-slot":"table-head",className:E("h-10 px-2 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",e),...a})}function mt({className:e,...a}){return t("td",{"data-slot":"table-cell",className:E("p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",e),...a})}
2
+ export{Tn,Mn,Rn,_r,bt,mt};
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ import{Yd}from"./chunk-msfw3jmc.js";export default Yd();
@@ -0,0 +1,2 @@
1
+ import{T}from"./chunk-7rhz2gze.js";var e=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]],zl=T("shield",e);
2
+ export{zl};
@@ -0,0 +1,2 @@
1
+ import{T}from"./chunk-7rhz2gze.js";var a=[["path",{d:"M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z",key:"1s2grr"}],["path",{d:"M20 2v4",key:"1rf3ol"}],["path",{d:"M22 4h-4",key:"gwowj6"}],["circle",{cx:"4",cy:"20",r:"2",key:"6kqj1y"}]],rn=T("sparkles",a);
2
+ export{rn};
@@ -0,0 +1,7 @@
1
+ // @bun
2
+ import{Ke}from"./chunk-hk5rc6cd.js";import{Wr}from"./chunk-mz0yjra0.js";import{ar}from"./chunk-579e4wv4.js";import{ka,Pa}from"./chunk-ks8xzc95.js";import{es}from"./chunk-837fky18.js";import{mn,hn}from"./chunk-4wy87hwd.js";import{As}from"./chunk-g3fpmyyn.js";import{ts}from"./chunk-gt4csat6.js";import{je,tc,rc,io,Hi,$n,Cr,lo}from"./chunk-hm0dkzed.js";import{on}from"./chunk-rchsme43.js";import{sn,qr}from"./chunk-trveq4wg.js";import{Yt}from"./chunk-nr20tvnw.js";function B(e,n){if(!e)return!1;let t=n.toLowerCase();for(let[r,s]of Object.entries(e))if(r.toLowerCase()===t&&s!==null&&s.trim().length>0)return!0;return!1}function z(e,n,t){if(n)return n;if(B(t,"authorization")||B(t,"cf-aig-authorization"))return"unused";throw Error(`No API key for provider: ${e}`)}function Q(e){for(let n of e){if(n.role==="toolResult")return!0;if(n.role==="assistant"){if(n.content.some((t)=>t.type==="toolCall"))return!0}}return!1}function X(e){let n=new Set;for(let t of e)if(t.role==="toolResult")for(let r of t.addedToolNames??[])n.add(r);return n}function Y(e,n){if(!e)return[];let t=new Map(e.map((r)=>[r.name,r]));return Array.from(n).map((r)=>t.get(r)).filter((r)=>r!==void 0)}function D(e){return e.type==="text"}function ee(e){return e.type==="thinking"}function te(e){return e.type==="toolCall"}function ne(e){return e.type==="image"}function re(e){if(typeof e!=="object"||e===null)return!1;let n=e;return n.type==="reasoning.encrypted"&&typeof n.id==="string"&&n.id.length>0&&typeof n.data==="string"&&n.data.length>0}function G(e,n){if(e)return e;if(ar("PI_CACHE_RETENTION",n)==="long")return"long";return"short"}var se=(e,n,t)=>{let r=new Yt;return(async()=>{let s={role:"assistant",content:[],api:e.api,provider:e.provider,model:e.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:"stop",timestamp:Date.now()};try{let g=z(e.provider,t?.apiKey,t?.headers),f=P(e),k=$n(n.tools,f.supportsOpenAIGrammarTools),i=G(t?.cacheRetention,t?.env),d=i==="none"?void 0:t?.sessionId,l=oe(e,n,g,t?.headers,d,f),a=ie(e,n,t,f,i,k),m=await t?.onPayload?.(a,e);if(m!==void 0)a=m;let y={...t?.signal?{signal:t.signal}:{},...t?.timeoutMs!==void 0?{timeout:t.timeoutMs}:{},maxRetries:0},{data:v,response:C}=await ts(()=>l.chat.completions.create(a,y).withResponse(),{maxRetries:t?.maxRetries,maxRetryDelayMs:t?.maxRetryDelayMs,signal:t?.signal});await t?.onResponse?.({status:C.status,headers:on(C.headers)},e),r.push({type:"start",partial:s});let M=null,h=null,T=!1,x=new Map,E=new Map,O=new Map,F=s.content,w=(o)=>F.indexOf(o),q=(o)=>{let u=o.customInput?.property;if(u===void 0)return"";let _=o.arguments[u];return typeof _==="string"?_:""},L=(o,u,_)=>{let c=o.customInput;if(!c)return;let A=rc(c.jsonBuffer,c.property,u,_);return o.arguments={[c.property]:u},A},H=(o)=>{let u=w(o);if(u===-1)return;if(o.type==="text")r.push({type:"text_end",contentIndex:u,content:o.text,partial:s});else if(o.type==="thinking")r.push({type:"thinking_end",contentIndex:u,content:o.thinking,partial:s});else if(o.type==="toolCall"){if(o.customInput){let _=L(o,q(o),!0);if(_!==void 0)r.push({type:"toolcall_delta",contentIndex:u,delta:_,partial:s})}else o.arguments=Wr(o.partialArgs);delete o.partialArgs,delete o.customInput,delete o.streamIndex,r.push({type:"toolcall_end",contentIndex:u,toolCall:o,partial:s})}},W=()=>{if(!M)M={type:"text",text:""},F.push(M),r.push({type:"text_start",contentIndex:w(M),partial:s});return M},U=(o)=>{if(!h)h={type:"thinking",thinking:"",thinkingSignature:o},F.push(h),r.push({type:"thinking_start",contentIndex:w(h),partial:s});return h},J=(o)=>{if(!o.id)return;let u=O.get(o.id);if(u)o.thoughtSignature=u,O.delete(o.id)},V=(o)=>{let u=typeof o.index==="number"?o.index:void 0,_=o.function?.name??o.custom?.name??"",c=u!==void 0?x.get(u):void 0;if(!c&&o.id)c=E.get(o.id);if(!c){let A=o.custom?k.get(_)??"input":void 0,S=A!==void 0;if(c={type:"toolCall",id:o.id||"",name:_,arguments:S?{[A]:""}:{},partialArgs:S?void 0:"",customInput:S?{property:A,jsonBuffer:{input:"",started:!1,closed:!1}}:void 0,streamIndex:u},u!==void 0)x.set(u,c);if(o.id)E.set(o.id,c);F.push(c),r.push({type:"toolcall_start",contentIndex:w(c),partial:s})}if(u!==void 0&&c.streamIndex===void 0)c.streamIndex=u,x.set(u,c);if(o.id)E.set(o.id,c);if(!c.name&&_)c.name=_;if(o.custom&&!c.customInput){let A=k.get(c.name)??"input";c.arguments={[A]:""},c.customInput={property:A,jsonBuffer:{input:"",started:!1,closed:!1}},delete c.partialArgs}return J(c),c};for await(let o of v){if(!o||typeof o!=="object")continue;if(s.responseId||=o.id,typeof o.model==="string"&&o.model.length>0&&o.model!==e.id)s.responseModel||=o.model;if(o.usage)s.usage=N(o.usage,e);let u=Array.isArray(o.choices)?o.choices[0]:void 0;if(!u)continue;if(!o.usage&&u.usage)s.usage=N(u.usage,e);if(u.finish_reason){let _=ye(u.finish_reason);if(s.stopReason=_.stopReason,_.errorMessage)s.errorMessage=_.errorMessage;T=!0}if(u.delta){if(u.delta.content!==null&&u.delta.content!==void 0&&u.delta.content.length>0){let p=W();p.text+=u.delta.content,r.push({type:"text_delta",contentIndex:w(p),delta:u.delta.content,partial:s})}let _=["reasoning_content","reasoning","reasoning_text"],c=u.delta,A=null;for(let p of _){let R=c[p];if(typeof R==="string"&&R.length>0){A=p;break}}if(A){let p=c[A];if(typeof p==="string"&&p.length>0){let R=e.provider==="opencode-go"&&A==="reasoning"?"reasoning_content":A,I=U(R);I.thinking+=p,r.push({type:"thinking_delta",contentIndex:w(I),delta:p,partial:s})}}if(u?.delta?.tool_calls)for(let p of u.delta.tool_calls){let R=V(p);if(!R.id&&p.id)R.id=p.id,E.set(p.id,R);let I=p.function?.name??p.custom?.name;if(!R.name&&I)R.name=I;let b="";if(p.function?.arguments)b=p.function.arguments,R.partialArgs=(R.partialArgs??"")+p.function.arguments,R.arguments=Wr(R.partialArgs);else if(p.custom?.input){let Z=q(R)+p.custom.input;b=L(R,Z,!1)??""}r.push({type:"toolcall_delta",contentIndex:w(R),delta:b,partial:s})}let S=u.delta.reasoning_details;if(Array.isArray(S)){for(let p of S)if(re(p)){let R=JSON.stringify(p),I=E.get(p.id);if(I)I.thoughtSignature=R;else O.set(p.id,R)}}}}for(let o of F)H(o);if(t?.signal?.aborted)throw Error("Request was aborted");if(s.stopReason==="aborted")throw Error("Request was aborted");if(s.stopReason==="error")throw Error(s.errorMessage||"Provider returned an error stop reason");if(!T)throw Error("Stream ended without finish_reason");r.push({type:"done",reason:s.stopReason,message:s}),r.end()}catch(g){for(let k of s.content)delete k.index,delete k.partialArgs,delete k.customInput,delete k.streamIndex;s.stopReason=t?.signal?.aborted?"aborted":"error",s.errorMessage=hn(mn(g));let f=g?.error?.metadata?.raw;if(f&&!s.errorMessage.includes(String(f)))s.errorMessage+=`
3
+ ${f}`;r.push({type:"error",reason:s.stopReason,error:s}),r.end()}})(),r},Pe=(e,n,t)=>{z(e.provider,t?.apiKey,t?.headers);let r=Cr(e,n,t,t?.apiKey),s=t?.reasoning?qr(e,t.reasoning):void 0,g=s==="off"?void 0:s,f=t?.toolChoice;return se(e,n,{...r,reasoningEffort:g,toolChoice:f})};function oe(e,n,t,r,s,g=P(e)){let f={...e.headers};if(e.provider==="github-copilot"){let k=ka(n.messages),i=Pa({messages:n.messages,hasImages:k});Object.assign(f,i)}if(s&&g.sendSessionAffinityHeaders)if(g.sessionAffinityFormat==="openrouter")f["x-session-id"]=s;else{if(g.sessionAffinityFormat==="openai")f.session_id=s;f["x-client-request-id"]=s,f["x-session-affinity"]=s}if(r)Object.assign(f,r);return new Ke({apiKey:t,baseURL:e.baseUrl,dangerouslyAllowBrowser:!0,defaultHeaders:f})}function ie(e,n,t,r=P(e),s=G(t?.cacheRetention,t?.env),g=$n(n.tools,r.supportsOpenAIGrammarTools)){let f=me(e,n,r,{grammarToolInputProperties:g}),k=fe(r,s),i={model:e.id,messages:f,stream:!0,prompt_cache_key:e.baseUrl.includes("api.openai.com")&&s!=="none"||s==="long"&&r.supportsLongCacheRetention?es(t?.sessionId):void 0,prompt_cache_retention:s==="long"&&r.supportsLongCacheRetention?"24h":void 0};if(r.supportsUsageInStreaming!==!1)i.stream_options={include_usage:!0};if(r.supportsStore)i.store=!1;if(t?.maxTokens)if(r.maxTokensField==="max_tokens")i.max_tokens=t.maxTokens;else i.max_completion_tokens=t.maxTokens;if(t?.temperature!==void 0)i.temperature=t.temperature;let d=r.deferredToolsMode==="kimi"?X(n.messages):new Set,l=n.tools?.filter((a)=>!d.has(a.name));if(l&&l.length>0){if(i.tools=K(l,r),r.zaiToolStream)i.tool_stream=!0}else if(Q(n.messages))i.tools=[];if(k)le(f,i.tools,k);if(t?.toolChoice)i.tool_choice=t.toolChoice;if(r.thinkingFormat==="zai"&&e.reasoning){let a=i;if(a.thinking=t?.reasoningEffort?{type:"enabled",clear_thinking:!1}:{type:"disabled"},t?.reasoningEffort&&r.supportsReasoningEffort){let m=e.thinkingLevelMap?.[t.reasoningEffort],y=m===void 0?t.reasoningEffort:m;if(typeof y==="string")a.reasoning_effort=y}}else if(r.thinkingFormat==="qwen"&&e.reasoning)i.enable_thinking=!!t?.reasoningEffort;else if(r.thinkingFormat==="qwen-chat-template"&&e.reasoning)i.chat_template_kwargs={enable_thinking:!!t?.reasoningEffort,preserve_thinking:!0};else if(r.thinkingFormat==="chat-template"&&e.reasoning){let a=ae(e,t,r);if(a)i.chat_template_kwargs=a}else if(r.thinkingFormat==="deepseek"&&e.reasoning){if(t?.reasoningEffort)i.thinking={type:"enabled"};else if(e.thinkingLevelMap?.off!==null)i.thinking={type:"disabled"};if(t?.reasoningEffort&&r.supportsReasoningEffort)i.reasoning_effort=e.thinkingLevelMap?.[t.reasoningEffort]??t.reasoningEffort}else if(r.thinkingFormat==="openrouter"&&e.reasoning){let a=i;if(t?.reasoningEffort)a.reasoning={effort:e.thinkingLevelMap?.[t.reasoningEffort]??t.reasoningEffort};else if(e.thinkingLevelMap?.off!==null)a.reasoning={effort:e.thinkingLevelMap?.off??"none"}}else if(r.thinkingFormat==="ant-ling"&&e.reasoning&&t?.reasoningEffort){let a=e.thinkingLevelMap?.[t.reasoningEffort];if(typeof a==="string")i.reasoning={effort:a}}else if(r.thinkingFormat==="together"&&e.reasoning){let a=i;if(a.reasoning={enabled:!!t?.reasoningEffort},t?.reasoningEffort&&r.supportsReasoningEffort)a.reasoning_effort=e.thinkingLevelMap?.[t.reasoningEffort]??t.reasoningEffort}else if(r.thinkingFormat==="string-thinking"&&e.reasoning){let a=i;if(t?.reasoningEffort)a.thinking=e.thinkingLevelMap?.[t.reasoningEffort]??t.reasoningEffort;else if(e.thinkingLevelMap?.off!==null)a.thinking=e.thinkingLevelMap?.off??"none"}else if(t?.reasoningEffort&&e.reasoning&&r.supportsReasoningEffort)i.reasoning_effort=e.thinkingLevelMap?.[t.reasoningEffort]??t.reasoningEffort;else if(!t?.reasoningEffort&&e.reasoning&&r.supportsReasoningEffort){let a=e.thinkingLevelMap?.off;if(typeof a==="string")i.reasoning_effort=a}if(e.compat?.openRouterRouting)i.provider=e.compat.openRouterRouting;if(e.compat?.vercelGatewayRouting){let a=e.compat.vercelGatewayRouting;if(a.only||a.order){let m={};if(a.only)m.only=a.only;if(a.order)m.order=a.order;i.providerOptions={gateway:m}}}return i}function ae(e,n,t){let r={};for(let[s,g]of Object.entries(t.chatTemplateKwargs)){let f=ue(e,n,g);if(f!==void 0)r[s]=f}return Object.keys(r).length>0?r:void 0}function ue(e,n,t){if(typeof t!=="object"||t===null)return t;let r=n?.reasoningEffort;if(!r&&t.omitWhenOff)return;if(t.$var==="thinking.enabled")return!!r;let s=r?e.thinkingLevelMap?.[r]:e.thinkingLevelMap?.off;return s===void 0?r:typeof s==="string"?s:void 0}function fe(e,n){if(e.cacheControlFormat!=="anthropic"||n==="none")return;let t=n==="long"&&e.supportsLongCacheRetention?"1h":void 0;return{type:"ephemeral",...t?{ttl:t}:{}}}function le(e,n,t){ce(e,t),ge(n,t),pe(e,t)}function ce(e,n){for(let t of e)if(t.role==="system"||t.role==="developer"){de(t,n);return}}function pe(e,n){for(let t=e.length-1;t>=0;t--){let r=e[t];if(r.role==="user"||r.role==="assistant"||r.role==="tool"){if(he(r,n))return}}}function ge(e,n){if(!e||e.length===0)return;let t=e[e.length-1];t.cache_control=n}function de(e,n){return j(e,n)}function he(e,n){if(e.role==="user"||e.role==="assistant"||e.role==="tool")return j(e,n);return!1}function j(e,n){let t=e.content;if(typeof t==="string"){if(t.length===0)return!1;return e.content=[{type:"text",text:t,cache_control:n}],!0}if(!Array.isArray(t))return!1;for(let r=t.length-1;r>=0;r--){let s=t[r];if(s?.type==="text"){let g=s;return g.cache_control=n,!0}}return!1}function me(e,n,t,r){let s=[],g=(i)=>{if(i.includes("|")){let d=i.indexOf("|"),l=i.slice(0,d).replace(/[^a-zA-Z0-9_-]/g,"_"),a=i.slice(d+1).replace(/[^a-zA-Z0-9_-]/g,"_"),m=a.length>0?`${l}_${a}`:l;if(m.length<=40)return m;let y=As(i).slice(0,8);return`${l.slice(0,Math.max(1,40-y.length-1))}_${y}`}if(e.provider==="openai")return i.length>40?i.slice(0,40):i;return i},f=lo(n.messages,e,(i)=>g(i));if(n.systemPrompt){let d=e.reasoning&&t.supportsDeveloperRole?"developer":"system";s.push({role:d,content:je(n.systemPrompt)})}let k=null;for(let i=0;i<f.length;i++){let d=f[i];if(t.requiresAssistantAfterToolResult&&k==="toolResult"&&d.role==="user")s.push({role:"assistant",content:"I have processed the tool results."});if(d.role==="user")if(typeof d.content==="string")s.push({role:"user",content:je(d.content)});else{let l=d.content.map((a)=>{if(a.type==="text")return{type:"text",text:je(a.text)};else return{type:"image_url",image_url:{url:`data:${a.mimeType};base64,${a.data}`}}});if(l.length===0)continue;s.push({role:"user",content:l})}else if(d.role==="assistant"){let l={role:"assistant",content:t.requiresAssistantAfterToolResult?"":null},a=d.content.filter(D).filter((h)=>h.text.trim().length>0).map((h)=>({type:"text",text:je(h.text)})),m=a.map((h)=>h.text).join(""),y=d.content.filter(ee).filter((h)=>h.thinking.trim().length>0);if(y.length>0)if(t.requiresThinkingAsText){let h=y.map((T)=>je(T.thinking)).join(`
4
+
5
+ `);l.content=[{type:"text",text:h},...a]}else{if(m.length>0)l.content=m;let h=y[0].thinkingSignature;if(e.provider==="opencode-go"&&h==="reasoning")h="reasoning_content";if(h&&h.length>0)l[h]=y.map((T)=>T.thinking).join(`
6
+ `)}else if(m.length>0)l.content=m;let v=d.content.filter(te);if(v.length>0){l.tool_calls=v.map((T)=>{let x=r?.grammarToolInputProperties?.get(T.name);if(x!==void 0)return{id:T.id,type:"custom",custom:{name:T.name,input:je(tc(T.name,T.arguments,x))}};return{id:T.id,type:"function",function:{name:T.name,arguments:JSON.stringify(T.arguments)}}});let h=v.filter((T)=>T.thoughtSignature).map((T)=>{try{return JSON.parse(T.thoughtSignature)}catch{return null}}).filter(Boolean);if(h.length>0)l.reasoning_details=h}if(t.requiresReasoningContentOnAssistantMessages&&e.reasoning&&l.reasoning_content===void 0)l.reasoning_content="";let C=l.content;if(!(C!==null&&C!==void 0&&(typeof C==="string"?C.length>0:C.length>0))&&!l.tool_calls)continue;s.push(l)}else if(d.role==="toolResult"){let l=[],a=new Set,m=i;for(;m<f.length&&f[m].role==="toolResult";m++){let y=f[m],v=y.content.filter(D).map((x)=>x.text).join(`
7
+ `),C=y.content.some((x)=>x.type==="image"),h=v.length>0?v:C?"(see attached image)":"(no tool output)",T={role:"tool",content:je(h),tool_call_id:y.toolCallId};if(t.requiresToolResultName&&y.toolName)T.name=y.toolName;if(s.push(T),t.deferredToolsMode==="kimi")for(let x of y.addedToolNames??[])a.add(x);if(C&&e.input.includes("image")){for(let x of y.content)if(ne(x))l.push({type:"image_url",image_url:{url:`data:${x.mimeType};base64,${x.data}`}})}}if(i=m-1,l.length>0){if(t.requiresAssistantAfterToolResult)s.push({role:"assistant",content:"I have processed the tool results."});s.push({role:"user",content:[{type:"text",text:"Attached image(s) from tool result:"},...l]}),k="user"}else k="toolResult";if(a.size>0){let y=Y(n.tools,a);if(y.length>0){let v={role:"system",tools:K(y,t)};s.push(v)}}continue}k=d.role}return s}function K(e,n){return e.map((t)=>{let r=Hi(t,n.supportsOpenAIGrammarTools);if(r)return{type:"custom",custom:{name:t.name,description:t.description,format:{type:"grammar",grammar:{syntax:r.format,definition:r.definition}}}};let s=io(t,n.supportsStrictMode!==!1);return{type:"function",function:{name:t.name,description:t.description,parameters:t.parameters,...n.supportsStrictMode!==!1&&{strict:s??!1}}}})}function N(e,n){let t=e.prompt_tokens||0,r=e.prompt_tokens_details?.cached_tokens??e.prompt_cache_hit_tokens??0,s=e.prompt_tokens_details?.cache_write_tokens||0,g=Math.max(0,t-r-s),f=e.completion_tokens||0,k={input:g,output:f,cacheRead:r,cacheWrite:s,reasoning:e.completion_tokens_details?.reasoning_tokens||0,totalTokens:g+f+r+s,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}};return sn(n,k),k}function ye(e){if(e===null)return{stopReason:"stop"};switch(e){case"stop":case"end":return{stopReason:"stop"};case"length":return{stopReason:"length"};case"function_call":case"tool_calls":return{stopReason:"toolUse"};case"content_filter":return{stopReason:"error",errorMessage:"Provider finish_reason: content_filter"};case"network_error":return{stopReason:"error",errorMessage:"Provider finish_reason: network_error"};default:return{stopReason:"error",errorMessage:`Provider finish_reason: ${e}`}}}function ke(e){let{provider:n,baseUrl:t}=e,r=n==="zai"||n==="zai-coding-cn"||t.includes("api.z.ai")||t.includes("open.bigmodel.cn"),s=n==="together"||t.includes("api.together.ai")||t.includes("api.together.xyz"),g=n==="moonshotai"||n==="moonshotai-cn"||t.includes("api.moonshot."),f=n==="openrouter"||t.includes("openrouter.ai"),k=n==="cloudflare-workers-ai"||t.includes("api.cloudflare.com"),i=n==="cloudflare-ai-gateway"||t.includes("gateway.ai.cloudflare.com"),d=n==="nvidia"||t.includes("integrate.api.nvidia.com"),l=n==="ant-ling"||t.includes("api.ant-ling.com"),a=d||n==="cerebras"||t.includes("cerebras.ai")||n==="xai"||t.includes("api.x.ai")||s||t.includes("chutes.ai")||t.includes("deepseek.com")||r||g||n==="opencode"||t.includes("opencode.ai")||k||i||l,m=t.includes("chutes.ai")||g||i||s||d||l,y=n==="xai"||t.includes("api.x.ai"),v=n==="deepseek"||t.includes("deepseek.com"),C=f&&(e.id.startsWith("anthropic/")||e.id.startsWith("openai/")),M=n==="openrouter"&&e.id.startsWith("anthropic/")?"anthropic":void 0;return{supportsStore:!a,supportsDeveloperRole:C||!a&&!f,supportsReasoningEffort:!y&&!r&&!g&&!s&&!i&&!d&&!l,supportsUsageInStreaming:!0,maxTokensField:m?"max_tokens":"max_completion_tokens",requiresToolResultName:!1,requiresAssistantAfterToolResult:!1,requiresThinkingAsText:!1,requiresReasoningContentOnAssistantMessages:v,thinkingFormat:v?"deepseek":r?"zai":s?"together":l?"ant-ling":f?"openrouter":"openai",openRouterRouting:{},vercelGatewayRouting:{},chatTemplateKwargs:{},zaiToolStream:!1,supportsStrictMode:!g&&!s&&!i&&!d,supportsOpenAIGrammarTools:!1,cacheControlFormat:M,sendSessionAffinityHeaders:!1,deferredToolsMode:void 0,sessionAffinityFormat:f?"openrouter":"openai",supportsLongCacheRetention:!(s||k||i||d||l)}}function P(e){let n=ke(e);if(!e.compat)return n;return{supportsStore:e.compat.supportsStore??n.supportsStore,supportsDeveloperRole:e.compat.supportsDeveloperRole??n.supportsDeveloperRole,supportsReasoningEffort:e.compat.supportsReasoningEffort??n.supportsReasoningEffort,supportsUsageInStreaming:e.compat.supportsUsageInStreaming??n.supportsUsageInStreaming,maxTokensField:e.compat.maxTokensField??n.maxTokensField,requiresToolResultName:e.compat.requiresToolResultName??n.requiresToolResultName,requiresAssistantAfterToolResult:e.compat.requiresAssistantAfterToolResult??n.requiresAssistantAfterToolResult,requiresThinkingAsText:e.compat.requiresThinkingAsText??n.requiresThinkingAsText,requiresReasoningContentOnAssistantMessages:e.compat.requiresReasoningContentOnAssistantMessages??n.requiresReasoningContentOnAssistantMessages,thinkingFormat:e.compat.thinkingFormat??n.thinkingFormat,openRouterRouting:e.compat.openRouterRouting??{},vercelGatewayRouting:e.compat.vercelGatewayRouting??n.vercelGatewayRouting,chatTemplateKwargs:e.compat.chatTemplateKwargs??n.chatTemplateKwargs,zaiToolStream:e.compat.zaiToolStream??n.zaiToolStream,supportsStrictMode:e.compat.supportsStrictMode??n.supportsStrictMode,supportsOpenAIGrammarTools:e.compat.supportsOpenAIGrammarTools??n.supportsOpenAIGrammarTools,cacheControlFormat:e.compat.cacheControlFormat??n.cacheControlFormat,sendSessionAffinityHeaders:e.compat.sendSessionAffinityHeaders??n.sendSessionAffinityHeaders,deferredToolsMode:e.compat.deferredToolsMode??n.deferredToolsMode,sessionAffinityFormat:e.compat.sessionAffinityFormat??n.sessionAffinityFormat,supportsLongCacheRetention:e.compat.supportsLongCacheRetention??n.supportsLongCacheRetention}}export{me as convertMessages,se as stream,Pe as streamSimple};
@@ -0,0 +1,7 @@
1
+ // @bun
2
+ import{Go}from"./chunk-1gvscz88.js";import{kt}from"./chunk-5tcdwep5.js";import{He,Jt,jt}from"./chunk-jgs8an3h.js";import{z}from"./chunk-fnmwksnb.js";var N=z(kt()),c=z(He()),w=z(Go());import L from"fs/promises";var l=z(He());var O="169.254.170.2",y="169.254.170.23",v="[fd00:ec2::23]",A=(e,o)=>{if(e.protocol==="https:")return;if(e.hostname===O||e.hostname===y||e.hostname===v)return;if(e.hostname.includes("[")){if(e.hostname==="[::1]"||e.hostname==="[0000:0000:0000:0000:0000:0000:0000:0001]")return}else{if(e.hostname==="localhost")return;let n=e.hostname.split("."),r=(t)=>{let s=parseInt(t,10);return 0<=s&&s<=255};if(n[0]==="127"&&r(n[1])&&r(n[2])&&r(n[3])&&n.length===4)return}throw new l.CredentialsProviderError(`URL not accepted. It must either be HTTPS or match one of the following:
3
+ - loopback CIDR 127.0.0.0/8 or [::1/128]
4
+ - ECS container host 169.254.170.2
5
+ - EKS container host 169.254.170.23 or [fd00:ec2::23]`,{logger:o})};var i=z(He()),C=z(jt()),p=z(Jt()),_=z(Jt());function f(e){return new C.HttpRequest({protocol:e.protocol,hostname:e.hostname,port:Number(e.port),path:e.pathname,query:Array.from(e.searchParams.entries()).reduce((o,[n,r])=>(o[n]=r,o),{}),fragment:e.hash})}async function I(e,o){let r=await _.sdkStreamMixin(e.body).transformToString();if(e.statusCode===200){let t=JSON.parse(r);if(typeof t.AccessKeyId!=="string"||typeof t.SecretAccessKey!=="string"||typeof t.Token!=="string"||typeof t.Expiration!=="string")throw new i.CredentialsProviderError("HTTP credential provider response not of the required format, an object matching: { AccessKeyId: string, SecretAccessKey: string, Token: string, Expiration: string(rfc3339) }",{logger:o});return{accessKeyId:t.AccessKeyId,secretAccessKey:t.SecretAccessKey,sessionToken:t.Token,expiration:p.parseRfc3339DateTime(t.Expiration)}}if(e.statusCode>=400&&e.statusCode<500){let t={};try{t=JSON.parse(r)}catch(s){}throw Object.assign(new i.CredentialsProviderError(`Server responded with status: ${e.statusCode}`,{logger:o}),{Code:t.Code,Message:t.Message})}throw new i.CredentialsProviderError(`Server responded with status: ${e.statusCode}`,{logger:o})}var u=(e,o,n)=>async()=>{for(let r=0;r<o;++r)try{return await e()}catch(t){await new Promise((s)=>setTimeout(s,n))}return await e()};var U="AWS_CONTAINER_CREDENTIALS_RELATIVE_URI",k="http://169.254.170.2",H="AWS_CONTAINER_CREDENTIALS_FULL_URI",K="AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE",P="AWS_CONTAINER_AUTHORIZATION_TOKEN",F=(e={})=>{e.logger?.debug("@aws-sdk/credential-provider-http - fromHttp");let o,n=e.awsContainerCredentialsRelativeUri??process.env[U],r=e.awsContainerCredentialsFullUri??process.env[H],t=e.awsContainerAuthorizationToken??process.env[P],s=e.awsContainerAuthorizationTokenFile??process.env[K],a=e.logger?.constructor?.name==="NoOpLogger"||!e.logger?.warn?console.warn:e.logger.warn.bind(e.logger);if(n&&r)a("@aws-sdk/credential-provider-http: you have set both awsContainerCredentialsRelativeUri and awsContainerCredentialsFullUri."),a("awsContainerCredentialsRelativeUri will take precedence.");if(t&&s)a("@aws-sdk/credential-provider-http: you have set both awsContainerAuthorizationToken and awsContainerAuthorizationTokenFile."),a("awsContainerAuthorizationTokenFile will take precedence.");if(n)o=`${k}${n}`;else if(r)o=r;else throw new c.CredentialsProviderError(`No HTTP credential provider host provided.
6
+ Set AWS_CONTAINER_CREDENTIALS_FULL_URI or AWS_CONTAINER_CREDENTIALS_RELATIVE_URI.`,{logger:e.logger});let T=new URL(o);A(T,e.logger);let h=w.NodeHttpHandler.create({connectionTimeout:e.timeout??1000}),R=e.timeout??1000,g=u(async()=>{let d=f(T);if(s)d.headers.Authorization=E((await L.readFile(s)).toString());else if(t)d.headers.Authorization=E(t);try{let m=await h.handle(d,{requestTimeout:R});return I(m.response).then((S)=>N.setCredentialFeature(S,"CREDENTIALS_HTTP","z"))}catch(m){throw new c.CredentialsProviderError(String(m),{logger:e.logger})}},e.maxRetries??3,e.timeout??1000);return async()=>{try{return await g()}finally{h.destroy?.()}}},E=(e)=>{if(e.includes(`\r
7
+ `))throw new c.CredentialsProviderError("Authorization token contains invalid \\r\\n sequence.");return e};export{F as fromHttp};
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ import{pu}from"./chunk-hk5rc6cd.js";import{ar}from"./chunk-579e4wv4.js";import"./chunk-mz0yjra0.js";import{$s,Gs,Qs}from"./chunk-pazjhrnf.js";import{es}from"./chunk-837fky18.js";import{mn,hn}from"./chunk-4wy87hwd.js";import{ts}from"./chunk-gt4csat6.js";import{$n,Cr}from"./chunk-hm0dkzed.js";import{on}from"./chunk-rchsme43.js";import{qr}from"./chunk-trveq4wg.js";import{Yt}from"./chunk-nr20tvnw.js";var d="v1",A=new Set(["openai","openai-codex","opencode","azure-openai-responses"]),E=16;function R(r){let a=new Map;if(!r)return a;for(let e of r.split(",")){let n=e.trim();if(!n)continue;let[s,t]=n.split("=",2);if(!s||!t)continue;a.set(s.trim(),t.trim())}return a}function h(r,a){if(a?.azureDeploymentName)return a.azureDeploymentName;return R(ar("AZURE_OPENAI_DEPLOYMENT_NAME_MAP",a?.env)).get(r.id)||r.id}function g(r){return hn(mn(r),"Azure OpenAI API error")}var y=(r,a,e)=>{let n=new Yt;return(async()=>{let s=h(r,e),t={role:"assistant",content:[],api:"azure-openai-responses",provider:r.provider,model:r.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:"stop",timestamp:Date.now()};try{let o=e?.apiKey;if(!o)throw Error(`No API key for provider: ${r.provider}`);let i=O(r,o,e),m=$n(a.tools,r.compat?.supportsOpenAIGrammarTools??!1),p=U(r,a,e,s,m),u=await e?.onPayload?.(p,r);if(u!==void 0)p=u;let f={...e?.signal?{signal:e.signal}:{},...e?.timeoutMs!==void 0?{timeout:e.timeoutMs}:{},maxRetries:0},{data:l,response:c}=await ts(()=>i.responses.create(p,f).withResponse(),{maxRetries:e?.maxRetries,maxRetryDelayMs:e?.maxRetryDelayMs,signal:e?.signal});if(await e?.onResponse?.({status:c.status,headers:on(c.headers)},r),n.push({type:"start",partial:t}),await Qs(l,t,n,r,{grammarToolInputProperties:m}),e?.signal?.aborted)throw Error("Request was aborted");if(t.stopReason==="aborted"||t.stopReason==="error")throw Error("An unknown error occurred");n.push({type:"done",reason:t.stopReason,message:t}),n.end()}catch(o){for(let i of t.content)delete i.index,delete i.partialJson,delete i.customInput;t.stopReason=e?.signal?.aborted?"aborted":"error",t.errorMessage=g(o),n.push({type:"error",reason:t.stopReason,error:t}),n.end()}})(),n},B=(r,a,e)=>{let n=e?.apiKey;if(!n)throw Error(`No API key for provider: ${r.provider}`);let s=Cr(r,a,e,n),t=e?.reasoning?qr(r,e.reasoning):void 0;return y(r,a,{...s,reasoningEffort:t==="off"?void 0:t})};function _(r){let a=r.trim().replace(/\/+$/,""),e;try{e=new URL(a)}catch{throw Error(`Invalid Azure OpenAI base URL: ${r}`)}let n=e.hostname.endsWith(".openai.azure.com")||e.hostname.endsWith(".cognitiveservices.azure.com")||e.hostname.endsWith(".ai.azure.com"),s=e.pathname.replace(/\/+$/,"");if(n&&(s===""||s==="/"||s==="/openai"||s==="/openai/v1/responses"))e.pathname="/openai/v1",e.search="";return e.toString().replace(/\/+$/,"")}function I(r){return`https://${r}.openai.azure.com/openai/v1`}function v(r,a){let e=a?.azureApiVersion||ar("AZURE_OPENAI_API_VERSION",a?.env)||d,n=a?.azureBaseUrl?.trim()||ar("AZURE_OPENAI_BASE_URL",a?.env)?.trim()||void 0,s=a?.azureResourceName||ar("AZURE_OPENAI_RESOURCE_NAME",a?.env),t=n;if(!t&&s)t=I(s);if(!t&&r.baseUrl)t=r.baseUrl;if(!t)throw Error("Azure OpenAI base URL is required. Set AZURE_OPENAI_BASE_URL or AZURE_OPENAI_RESOURCE_NAME, or pass azureBaseUrl, azureResourceName, or model.baseUrl.");return{baseUrl:_(t),apiVersion:e}}function O(r,a,e){let n={...r.headers};if(e?.headers)Object.assign(n,e.headers);let{baseUrl:s,apiVersion:t}=v(r,e);return new pu({apiKey:a,apiVersion:t,dangerouslyAllowBrowser:!0,defaultHeaders:n,baseURL:s})}function U(r,a,e,n,s=$n(a.tools,r.compat?.supportsOpenAIGrammarTools??!1)){let t=$s(r,a,A,{grammarToolInputProperties:s}),o={model:n,input:t,stream:!0,prompt_cache_key:es(e?.sessionId),store:!1};if(e?.maxTokens)o.max_output_tokens=Math.max(e.maxTokens,E);if(e?.temperature!==void 0)o.temperature=e?.temperature;if(a.tools&&a.tools.length>0)o.tools=Gs(a.tools,{supportsStrictMode:r.compat?.supportsStrictMode??!0,supportsOpenAIGrammarTools:r.compat?.supportsOpenAIGrammarTools??!1});if(r.reasoning){if(e?.reasoningEffort||e?.reasoningSummary){let i=e?.reasoningEffort?r.thinkingLevelMap?.[e.reasoningEffort]??e.reasoningEffort:"medium";o.reasoning={effort:i,summary:e?.reasoningSummary||"auto"},o.include=["reasoning.encrypted_content"]}else if(r.thinkingLevelMap?.off!==null)o.reasoning={effort:r.thinkingLevelMap?.off??"none"}}return o}export{y as stream,B as streamSimple};