@bkm016/basalt 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) hide show
  1. package/README.md +16 -22
  2. package/chunk-06hdzq5n.js +2 -0
  3. package/chunk-09rj27b2.js +2 -0
  4. package/{chunk-qnr1f5pj.js → chunk-0y7ne3d0.js} +2 -2
  5. package/{chunk-vgvq3q12.js → chunk-10xzzn07.js} +2 -2
  6. package/{chunk-6qertm2t.js → chunk-1qpces5a.js} +1 -1
  7. package/{chunk-nt2gntad.js → chunk-1zdwrgd4.js} +1 -1
  8. package/{chunk-sh74qzvt.js → chunk-27gntzs5.js} +4 -4
  9. package/{chunk-1v7st27a.js → chunk-2esbgxps.js} +14 -14
  10. package/{chunk-exnn1867.js → chunk-362g64pd.js} +1 -1
  11. package/{chunk-1aspj1hn.js → chunk-3cjsd292.js} +2 -2
  12. package/chunk-5c9j8qe4.js +478 -0
  13. package/{chunk-8dxzqwq3.js → chunk-5j1krv9v.js} +1 -1
  14. package/{chunk-vkkj4awb.js → chunk-6hssbcgj.js} +1 -1
  15. package/{chunk-1b7gbe8g.js → chunk-75m78j7x.js} +2 -2
  16. package/{chunk-kfq8wyd3.js → chunk-8296hw9m.js} +1 -1
  17. package/{chunk-szat3vp4.js → chunk-8d46jtbj.js} +2 -2
  18. package/{chunk-qczbfccb.js → chunk-8tjad3r0.js} +4 -4
  19. package/{chunk-agntrqs9.js → chunk-97rzj7f6.js} +1 -1
  20. package/{chunk-k7w7ac9q.js → chunk-981f9dw8.js} +8 -8
  21. package/{chunk-xysny0ve.js → chunk-aefadsy6.js} +2 -2
  22. package/{chunk-jhd54p1b.js → chunk-bannb9xm.js} +1 -1
  23. package/{chunk-a3tqx584.js → chunk-c7x1zq39.js} +1 -1
  24. package/{chunk-rv06x0kn.js → chunk-cjc90f84.js} +1 -1
  25. package/{chunk-x3dnb9sz.js → chunk-d2j735sd.js} +2 -2
  26. package/{chunk-yskm0hsy.js → chunk-d8gtbw9g.js} +1 -1
  27. package/{chunk-rm3kcxq9.js → chunk-fjtvjrkg.js} +13 -13
  28. package/{chunk-h6sw8fbt.js → chunk-fm0k0qtz.js} +1 -1
  29. package/{chunk-1yzt0qm0.js → chunk-fw2bpqmw.js} +1 -1
  30. package/{chunk-45cz26ap.js → chunk-gp7y0fja.js} +13 -13
  31. package/{chunk-2bb01ddq.js → chunk-gzxnene8.js} +1 -1
  32. package/{chunk-a8nyk4k9.js → chunk-hwr56pfj.js} +1 -1
  33. package/{chunk-0hbjv3y6.js → chunk-jwdb0ccj.js} +3 -3
  34. package/{chunk-kf8hq21a.js → chunk-k23t7vhs.js} +5 -5
  35. package/{chunk-bhqyxyap.js → chunk-k506w58v.js} +1 -1
  36. package/{chunk-44ek81ad.js → chunk-k6w6y71k.js} +2 -2
  37. package/chunk-m40gxwq4.js +5 -0
  38. package/chunk-m8vkwdgr.js +5 -0
  39. package/{chunk-f7egr55n.js → chunk-mvfsxdx6.js} +13 -13
  40. package/{chunk-pvncysbb.js → chunk-nbb9trwz.js} +1 -1
  41. package/{chunk-0szjy61m.js → chunk-pbcy6zdt.js} +1 -1
  42. package/chunk-pmqtkqsf.js +2 -0
  43. package/{chunk-hat3s3pr.js → chunk-pxsrqrd0.js} +1 -1
  44. package/{chunk-xsbxykr4.js → chunk-qe0teyn1.js} +1 -1
  45. package/{chunk-2zqny2sy.js → chunk-r7fpkb49.js} +1 -1
  46. package/{chunk-3m7qwfm3.js → chunk-rtzqqngy.js} +3 -3
  47. package/{chunk-6e49xsf5.js → chunk-shadcb9z.js} +2 -2
  48. package/{chunk-0qqb6v41.js → chunk-shhrr741.js} +120 -120
  49. package/{chunk-cv5wsd9m.js → chunk-t6zs4kw0.js} +2 -2
  50. package/{chunk-hcn9cf6v.js → chunk-v258nxcz.js} +1 -1
  51. package/{chunk-a6r4z44b.js → chunk-vk1gxk1t.js} +1 -1
  52. package/{chunk-s37s3k24.js → chunk-x1xss1d7.js} +2 -2
  53. package/{chunk-dakrpbe6.js → chunk-x4874m8e.js} +2 -2
  54. package/{chunk-wx7kdf0b.js → chunk-xfvvh1s5.js} +1 -1
  55. package/{chunk-0yytz0r1.js → chunk-y0m980k3.js} +5 -5
  56. package/{chunk-dhm42y04.js → chunk-y58ygzn9.js} +3 -3
  57. package/{chunk-2wkaw73s.js → chunk-y648fzx0.js} +5 -5
  58. package/{chunk-32at88hc.js → chunk-y7nma9rk.js} +1 -1
  59. package/{chunk-pmc3y1z8.js → chunk-ykens1hy.js} +1 -1
  60. package/{chunk-q8zx3kt6.js → chunk-z55bmysw.js} +1 -1
  61. package/{chunk-qx0m82rw.js → chunk-zmsgwr3s.js} +1 -1
  62. package/{chunk-501zkf9b.js → chunk-ztsjgssj.js} +1 -1
  63. package/compiled.js +5 -5
  64. package/package.json +1 -1
  65. package/ui-test-worker.js +63 -63
  66. package/web/chunk-0sewdyz1.js +1 -0
  67. package/web/{chunk-xbty0rv7.js → chunk-1z5p7a1h.js} +1 -1
  68. package/web/chunk-21ke27j6.js +1 -0
  69. package/web/{chunk-2msj52w6.js → chunk-24k0r5aq.js} +1 -1
  70. package/web/{chunk-a5x2zveg.js → chunk-284a17k8.js} +1 -1
  71. package/web/{chunk-ca682sm6.js → chunk-2pjdtesn.js} +14 -14
  72. package/web/{chunk-z7dcbxws.js → chunk-3mvr2gwh.js} +1 -1
  73. package/web/chunk-3t3zwx9j.js +1 -0
  74. package/web/{chunk-e6jxqbv7.js → chunk-3z93efr4.js} +1 -1
  75. package/web/{chunk-05w4fyzc.js → chunk-43jqvsrg.js} +1 -1
  76. package/web/{chunk-jwzd9tzk.js → chunk-4bry4xds.js} +2 -2
  77. package/web/{chunk-4ks96e4r.js → chunk-5e7ygjdn.js} +1 -1
  78. package/web/{chunk-qefasa1j.js → chunk-5jbf7n5q.js} +1 -1
  79. package/web/{chunk-e32y85kx.js → chunk-5rx8rtsa.js} +1 -1
  80. package/web/chunk-5xc9d5ft.js +1 -0
  81. package/web/{chunk-a1z5qx1r.js → chunk-693m9kt7.js} +3 -3
  82. package/web/{chunk-70qwwwak.js → chunk-6qejm5s2.js} +1 -1
  83. package/web/{chunk-kdyjnwdx.js → chunk-8ah6ce1b.js} +2 -2
  84. package/web/{chunk-5vw9rs4r.js → chunk-8e43yaq3.js} +3 -3
  85. package/web/{chunk-qnaqf0cr.js → chunk-8wye0wbb.js} +1 -1
  86. package/web/{chunk-45fzdcgz.js → chunk-986z0p48.js} +5 -5
  87. package/web/{chunk-y0m8hrwz.js → chunk-9dd1c37b.js} +77 -77
  88. package/web/{chunk-9yakxvjb.js → chunk-9re6yttj.js} +2 -2
  89. package/web/{chunk-2scce33n.js → chunk-abbvjt4e.js} +1 -1
  90. package/web/{chunk-b4wbk7vc.js → chunk-agmkx996.js} +3 -3
  91. package/web/{chunk-hev4hq89.js → chunk-anbn2ttv.js} +2 -2
  92. package/web/chunk-aqm3spxt.js +1139 -0
  93. package/web/{chunk-fk0dh93x.js → chunk-avwpjsxw.js} +5 -5
  94. package/web/chunk-b470hvpk.js +1 -0
  95. package/web/{chunk-9dxjafp2.js → chunk-bt1m87ck.js} +2 -2
  96. package/web/chunk-cqp1d4p0.js +1 -0
  97. package/web/{chunk-ss1bcb0n.js → chunk-ctcrk3qn.js} +2 -2
  98. package/web/{chunk-pf2ab8p8.js → chunk-ctd8bfg2.js} +1 -1
  99. package/web/{chunk-q5ke7a33.js → chunk-cwvtraca.js} +1 -1
  100. package/web/{chunk-yd46jhqv.js → chunk-dk90px7g.js} +1 -1
  101. package/web/{chunk-0mrkjnte.js → chunk-ds7srg4p.js} +1 -1
  102. package/web/{chunk-fscafg24.js → chunk-dt8ss97f.js} +5 -5
  103. package/web/{chunk-9p12mgs6.js → chunk-ezkqa7we.js} +1 -1
  104. package/web/{chunk-f26smjjf.js → chunk-f078k1ej.js} +1 -1
  105. package/web/chunk-fekjj24p.css +1 -0
  106. package/web/{chunk-a3verqw9.js → chunk-fqj9kry9.js} +5 -5
  107. package/web/chunk-frjfamx7.js +8 -0
  108. package/web/{chunk-g4azyef7.js → chunk-fy8ey195.js} +1 -1
  109. package/web/{chunk-wptv8atc.js → chunk-g8ee1csm.js} +1 -1
  110. package/web/{chunk-w880psmw.js → chunk-h31p43qa.js} +1 -1
  111. package/web/chunk-h5p5jsrw.js +1 -0
  112. package/web/chunk-h9fmr6ch.js +1 -0
  113. package/web/{chunk-qh7265qw.js → chunk-jf2ehmvp.js} +2 -2
  114. package/web/{chunk-fz06t6km.js → chunk-jmnaq7c1.js} +1 -1
  115. package/web/chunk-jq0pw0k2.js +1 -0
  116. package/web/{chunk-p3b9crsa.js → chunk-jvj66qhs.js} +2 -2
  117. package/web/{chunk-xjxv8dg8.js → chunk-jzmzhj8z.js} +4 -4
  118. package/web/chunk-k4cfnvyq.js +1 -0
  119. package/web/{chunk-dt462hk9.js → chunk-kgerjbn4.js} +1 -1
  120. package/web/{chunk-bc78qf1m.js → chunk-kww4azv5.js} +5 -5
  121. package/web/chunk-m29dhjkh.js +1 -0
  122. package/web/chunk-mj6tee5h.js +1 -0
  123. package/web/{chunk-jrcyc9s9.js → chunk-mjpjkyd1.js} +1 -1
  124. package/web/{chunk-20q90epj.js → chunk-n8sky2q6.js} +1 -1
  125. package/web/{chunk-fm2ybfj5.js → chunk-pk3ap3wh.js} +4 -4
  126. package/web/{chunk-bgnnrpna.js → chunk-q1pkntc6.js} +4 -4
  127. package/web/{chunk-taynqrgq.js → chunk-qryrg2pq.js} +2 -2
  128. package/web/{chunk-gqw3f02j.js → chunk-r92sbgwv.js} +5 -5
  129. package/web/{chunk-0vt9fg48.js → chunk-raqqscwa.js} +2 -2
  130. package/web/{chunk-3jhyzmnf.js → chunk-rc2vq9wz.js} +3 -3
  131. package/web/{chunk-2ps6mepk.js → chunk-rkj743fg.js} +3 -3
  132. package/web/{chunk-e53wfgb8.js → chunk-rrws61wf.js} +1 -1
  133. package/web/{chunk-9an7cjd9.js → chunk-s3hwejnr.js} +2 -2
  134. package/web/{chunk-dzwxgqgm.js → chunk-s3rdx28k.js} +2 -2
  135. package/web/{chunk-2m12wyrb.js → chunk-shbw6wg8.js} +1 -1
  136. package/web/chunk-szcy5z56.js +1 -0
  137. package/web/{chunk-tmvakq7n.js → chunk-t1xk6hca.js} +4 -4
  138. package/web/chunk-t2hhdg9r.js +1 -0
  139. package/web/chunk-tj4cmkwe.js +1 -0
  140. package/web/{chunk-bjkc94mv.js → chunk-tn1xzmgx.js} +1 -1
  141. package/web/{chunk-4v8en1yw.js → chunk-tnv7z83q.js} +1 -1
  142. package/web/chunk-v2b5q0n5.js +1 -0
  143. package/web/{chunk-3ee04tmm.js → chunk-vj6kstpp.js} +5 -5
  144. package/web/{chunk-b1pe46zz.js → chunk-vjqmnkh2.js} +1 -1
  145. package/web/{chunk-qd8bxxdj.js → chunk-vkc149rb.js} +1 -1
  146. package/web/{chunk-v28fx2nd.js → chunk-vny496ba.js} +1 -1
  147. package/web/{chunk-rpmpttbk.js → chunk-vz5ck6x9.js} +1 -1
  148. package/web/{chunk-y49fhfda.js → chunk-xa88zgkr.js} +1 -1
  149. package/web/{chunk-q0p5xqe1.js → chunk-xdcs8qz3.js} +4 -4
  150. package/web/chunk-y5x74t89.js +1 -0
  151. package/web/{chunk-xrxne80b.js → chunk-yen2kkn2.js} +1 -1
  152. package/web/{chunk-bj90t5gh.js → chunk-yjv2c45j.js} +4 -4
  153. package/web/chunk-yx3dh5hg.js +1 -0
  154. package/web/chunk-yz4fmtk2.js +1 -0
  155. package/web/{chunk-8p4tc9f4.js → chunk-z24vs8q9.js} +3 -3
  156. package/web/chunk-z5j6x6j8.js +2 -0
  157. package/web/chunk-z5stjrhc.js +1 -0
  158. package/web/{chunk-90kp4pnz.js → chunk-z760wagr.js} +1 -1
  159. package/web/{chunk-tqmwd9qp.js → chunk-znvnb9dh.js} +1 -1
  160. package/web/{chunk-22a4ety5.js → chunk-zrzq29e6.js} +1 -1
  161. package/web/{icon-yx2p2pye.svg → icon-1wgy7kzy.svg} +13 -13
  162. package/web/icon.svg +13 -13
  163. package/web/index.html +2 -2
  164. package/web/install.sh +0 -0
  165. package/web/sw.js +9 -0
  166. package/worker.js +1 -1
  167. package/chunk-09vr609h.js +0 -2
  168. package/chunk-58vz2qsq.js +0 -2
  169. package/chunk-c25s4w6a.js +0 -5
  170. package/chunk-t057xfrt.js +0 -5
  171. package/chunk-wjd9fr23.js +0 -2
  172. package/chunk-zef13k3h.js +0 -471
  173. package/web/chunk-2pver6r4.js +0 -1
  174. package/web/chunk-37ajk6zg.js +0 -2
  175. package/web/chunk-4wkm9fda.js +0 -1
  176. package/web/chunk-amzgyy1k.js +0 -1
  177. package/web/chunk-cff5hcm8.js +0 -8
  178. package/web/chunk-esp1mmgr.js +0 -1
  179. package/web/chunk-ew3cgdtd.js +0 -1
  180. package/web/chunk-gjq1pxw3.js +0 -1
  181. package/web/chunk-h5ejbf6e.js +0 -1
  182. package/web/chunk-jjh5jvva.js +0 -1
  183. package/web/chunk-k5btcvbg.js +0 -1
  184. package/web/chunk-kpvgecwy.js +0 -1
  185. package/web/chunk-kq40ss39.js +0 -1
  186. package/web/chunk-q7dsnvpf.js +0 -1
  187. package/web/chunk-rg426vkf.js +0 -1
  188. package/web/chunk-ry9256r7.js +0 -1
  189. package/web/chunk-scpwc9ev.js +0 -1
  190. package/web/chunk-ssy07dd2.js +0 -1
  191. package/web/chunk-tgpbhzn9.js +0 -1
  192. package/web/chunk-vt40e1kp.js +0 -1136
  193. package/web/chunk-w53rba6g.js +0 -1
  194. package/web/chunk-w86n42dy.js +0 -1
  195. package/web/chunk-wtawdeej.css +0 -1
  196. package/web/chunk-zde7mj43.js +0 -1
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- import{f}from"./chunk-f7egr55n.js";import{ie}from"./chunk-d48bfd2e.js";import{q,j}from"./chunk-y69ewdn2.js";import{g}from"./chunk-n6e43rvk.js";import{z,he}from"./chunk-dakrpbe6.js";var P=async(e,s,t)=>{let a={api:e.api,provider:e.provider,model:e.id,output:[],stopReason:"stop",timestamp:Date.now()};try{let r=t?.apiKey;if(!r)throw Error(`No API key for provider: ${e.provider}`);let c=x(e,r,t?.headers,t?.fetch),n=_(e,s),i=await t?.onPayload?.(n,e);if(i!==void 0)n=i;let o={...t?.signal?{signal:t.signal}:{},...t?.timeoutMs!==void 0?{timeout:t.timeoutMs}:{},maxRetries:0},{data:R,response:l}=await ie(()=>c.chat.completions.create(n,o).withResponse(),{maxRetries:t?.maxRetries,maxRetryDelayMs:t?.maxRetryDelayMs,signal:t?.signal});await t?.onResponse?.({status:l.status,headers:z(l.headers)},e);let u=R;if(a.responseId=u.id,u.usage)a.usage=k(u.usage,e);let p=u.choices[0];if(p){let m=p.message.content;if(typeof m==="string"&&m.length>0)a.output.push({type:"text",text:m});for(let d of p.message.images??[]){let y=typeof d.image_url==="string"?d.image_url:d.image_url?.url;if(!y?.startsWith("data:"))continue;let h=y.match(/^data:([^;]+);base64,(.+)$/);if(!h)continue;a.output.push({type:"image",mimeType:h[1],data:h[2]})}}return a}catch(r){return a.stopReason=t?.signal?.aborted?"aborted":"error",a.errorMessage=j(q(r)),a}};function x(e,s,t,a){return new f({apiKey:s,baseURL:e.baseUrl,dangerouslyAllowBrowser:!0,fetch:a,defaultHeaders:he({...e.headers,...t})})}function _(e,s){let t=s.input.map((a)=>{if(a.type==="text")return{type:"text",text:g(a.text)};return{type:"image_url",image_url:{url:`data:${a.mimeType};base64,${a.data}`}}});return{model:e.id,messages:[{role:"user",content:t}],stream:!1,modalities:e.output.includes("text")?["image","text"]:["image"]}}function k(e,s){let t=e.prompt_tokens||0,a=e.prompt_tokens_details?.cached_tokens||0,r=e.prompt_tokens_details?.cache_write_tokens||0,c=r>0?Math.max(0,a-r):a,n=Math.max(0,t-c-r),i=e.completion_tokens||0,o={input:n,output:i,cacheRead:c,cacheWrite:r,totalTokens:n+i+c+r,cost:{input:s.cost.input/1e6*n,output:s.cost.output/1e6*i,cacheRead:s.cost.cacheRead/1e6*c,cacheWrite:s.cost.cacheWrite/1e6*r,total:0}};return o.cost.total=o.cost.input+o.cost.output+o.cost.cacheRead+o.cost.cacheWrite,o}export{P as generateImages};
2
+ import{f}from"./chunk-mvfsxdx6.js";import{ie}from"./chunk-d48bfd2e.js";import{q,j}from"./chunk-y69ewdn2.js";import{g}from"./chunk-n6e43rvk.js";import{z,fe}from"./chunk-x4874m8e.js";var P=async(e,s,t)=>{let a={api:e.api,provider:e.provider,model:e.id,output:[],stopReason:"stop",timestamp:Date.now()};try{let r=t?.apiKey;if(!r)throw Error(`No API key for provider: ${e.provider}`);let c=x(e,r,t?.headers,t?.fetch),n=_(e,s),i=await t?.onPayload?.(n,e);if(i!==void 0)n=i;let o={...t?.signal?{signal:t.signal}:{},...t?.timeoutMs!==void 0?{timeout:t.timeoutMs}:{},maxRetries:0},{data:R,response:l}=await ie(()=>c.chat.completions.create(n,o).withResponse(),{maxRetries:t?.maxRetries,maxRetryDelayMs:t?.maxRetryDelayMs,signal:t?.signal});await t?.onResponse?.({status:l.status,headers:z(l.headers)},e);let u=R;if(a.responseId=u.id,u.usage)a.usage=k(u.usage,e);let p=u.choices[0];if(p){let m=p.message.content;if(typeof m==="string"&&m.length>0)a.output.push({type:"text",text:m});for(let d of p.message.images??[]){let y=typeof d.image_url==="string"?d.image_url:d.image_url?.url;if(!y?.startsWith("data:"))continue;let h=y.match(/^data:([^;]+);base64,(.+)$/);if(!h)continue;a.output.push({type:"image",mimeType:h[1],data:h[2]})}}return a}catch(r){return a.stopReason=t?.signal?.aborted?"aborted":"error",a.errorMessage=j(q(r)),a}};function x(e,s,t,a){return new f({apiKey:s,baseURL:e.baseUrl,dangerouslyAllowBrowser:!0,fetch:a,defaultHeaders:fe({...e.headers,...t})})}function _(e,s){let t=s.input.map((a)=>{if(a.type==="text")return{type:"text",text:g(a.text)};return{type:"image_url",image_url:{url:`data:${a.mimeType};base64,${a.data}`}}});return{model:e.id,messages:[{role:"user",content:t}],stream:!1,modalities:e.output.includes("text")?["image","text"]:["image"]}}function k(e,s){let t=e.prompt_tokens||0,a=e.prompt_tokens_details?.cached_tokens||0,r=e.prompt_tokens_details?.cache_write_tokens||0,c=r>0?Math.max(0,a-r):a,n=Math.max(0,t-c-r),i=e.completion_tokens||0,o={input:n,output:i,cacheRead:c,cacheWrite:r,totalTokens:n+i+c+r,cost:{input:s.cost.input/1e6*n,output:s.cost.output/1e6*i,cacheRead:s.cost.cacheRead/1e6*c,cacheWrite:s.cost.cacheWrite/1e6*r,total:0}};return o.cost.total=o.cost.input+o.cost.output+o.cost.cacheRead+o.cost.cacheWrite,o}export{P as generateImages};
@@ -1,3 +1,3 @@
1
1
  // @bun
2
- import{N,H}from"./chunk-qczbfccb.js";class p extends Error{}var L=["$ref","$defs","definitions","allOf","oneOf","patternProperties","dependentSchemas","dependencies","unevaluatedProperties","propertyNames","contains","prefixItems","not","if","then","else"];function y(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function D(e){if(!y(e))return!1;let n=typeof e.type==="string"?[e.type]:Array.isArray(e.type)?e.type:[];return n.includes("object")||n.includes("array")||e.properties!==void 0||e.items!==void 0}function M(e){if(!y(e))return!1;if(e.type==="null"||Array.isArray(e.type)&&e.type.includes("null"))return!0;if(e.const===null||Array.isArray(e.enum)&&e.enum.includes(null))return!0;return Array.isArray(e.anyOf)&&e.anyOf.some((n)=>M(n))}function w(e,n){if(!y(e))throw new p("boolean schemas are unsupported");for(let a of L)if(e[a]!==void 0)throw new p(`${a} schemas are unsupported`);if(n){for(let[a,l]of Object.entries(e))if(n(a,l))throw new p(`${a}: ${JSON.stringify(l)} is unsupported`)}if(e.anyOf!==void 0){if(!Array.isArray(e.anyOf)||e.anyOf.length===0)throw new p("anyOf must contain at least one schema");for(let a of e.anyOf){if(D(a))throw new p("object and array unions are unsupported");w(a,n)}}if(e.items!==void 0){if(Array.isArray(e.items))throw new p("tuple schemas are unsupported");w(e.items,n)}let t=e.type==="object";if(e.properties!==void 0&&!t)throw new p("properties require type object");if(!t)return;if(e.additionalProperties!==void 0&&e.additionalProperties!==!1)throw new p("schema-valued or true additionalProperties is unsupported");if(e.properties!==void 0&&!y(e.properties))throw new p("object properties must be a schema map");if(e.required!==void 0&&(!Array.isArray(e.required)||e.required.some((a)=>typeof a!=="string")))throw new p("object required must be a string array");let r=e.properties??{},i=Object.keys(r),o=new Set(Array.isArray(e.required)?e.required:[]);if([...o].some((a)=>!i.includes(a)))throw new p("required contains an unknown property");for(let[a,l]of Object.entries(r))if(w(l,n),!o.has(a)&&!M(l))r[a]={anyOf:[l,{type:"null"}]};e.required=i,e.additionalProperties=!1}function k(e,n){let t=structuredClone(e);if(!y(t))throw new p("root schema must have type object");if(w(t,n),t.type!=="object")throw new p("root schema must have type object");return t}function de(e,n){return n===!0?k(e.parameters):e.parameters}function Mr(e,n,t){let r=n[t];if(typeof r!=="string")throw Error(`Grammar tool call "${e}" requires argument "${t}" to be a string.`);return r}function Lr(e,n,t,r){if(e.closed){if(r&&t===e.input)return;throw Error(`grammar tool input for property "${n}" changed after it was closed`)}if(!t.startsWith(e.input))throw Error(`grammar tool input for property "${n}" changed non-monotonically`);let i=t.slice(e.input.length);if(!r&&i.length===0)return;let o="";if(!e.started)o+=`{${JSON.stringify(n)}:"`,e.started=!0;if(o+=JSON.stringify(i).slice(1,-1),e.input=t,r)o+='"}',e.closed=!0;return o}function G(e){let n=e.parameters;if(n.type!=="object")throw Error("grammar constrained sampling requires an object parameter schema");if(!Array.isArray(n.required)||n.required.length!==1||typeof n.required[0]!=="string")throw Error("grammar constrained sampling requires exactly one required string property");let t=n.required[0];if(!n.properties?.[t])throw Error(`grammar constrained sampling requires a properties entry for ${t}`);if(n.properties[t]?.type!=="string")throw Error(`grammar constrained sampling property ${t} must have type string`);return t}function ce(e,n,t){let r=e.constrainedSampling;if(!r||r.type!=="json_schema")return;if(n)try{return k(e.parameters,t),!0}catch(i){if(!(i instanceof p))throw i;if(r.strict!=="require")return;throw Error(`Tool "${e.name}" requires JSON-schema constrained sampling, but ${i.message}.`)}if(r.strict==="require")throw Error(`Tool "${e.name}" requires JSON-schema constrained sampling, but strict tools are unsupported.`);return}function Jt(e,n){let t=e.constrainedSampling;if(!t||t.type!=="grammar")return;if(!n)return;let r=t.variants.openai_lark,i=t.variants.openai_regex,o=typeof r==="string"&&r.trim().length>0,a=typeof i==="string"&&i.trim().length>0;if(!o&&!a)throw Error(`Tool "${e.name}" cannot use grammar constrained sampling: no supported grammar variant was provided.`);try{return{format:o?"lark":"regex",definition:o?r:i,inputProperty:G(e)}}catch(l){let d=l instanceof Error?l.message:String(l);throw Error(`Tool "${e.name}" cannot use grammar constrained sampling: ${d}.`)}}function Ee(e,n){let t=new Map;for(let r of e??[]){let i=Jt(r,n);if(i)t.set(r.name,i.inputProperty)}return t}var O=3.5,b=4800;function _(e){return e.totalTokens||e.input+e.output+e.cacheRead+e.cacheWrite}function P(e){try{return JSON.stringify(e)??"undefined"}catch{return"[unserializable]"}}function W(e){if(typeof e==="string")return e.length;let n=0;for(let t of e)n+=t.type==="text"?t.text.length:b;return n}function v(e){return Math.ceil(e.length/O)}function C(e){return Math.ceil(W(e)/O)}function E(e){let n=0;if(e.role==="system")return v(N(e))+R(e.toolsAdded)+R(e.toolsRemoved);if(e.role==="user")return C(e.content);if(e.role==="toolResult")return C(e.content);for(let t of e.content)if(t.type==="text")n+=t.text.length;else if(t.type==="thinking")n+=t.thinking.length;else n+=t.name.length+P(t.arguments).length;return Math.ceil(n/O)}function B(e){let n=Number.NEGATIVE_INFINITY,t;for(let r=0;r<e.length;r++){let i=e[r];if(i.role==="assistant"){let o=i;if(o.timestamp>=n&&o.stopReason!=="aborted"&&o.stopReason!=="error"&&_(o.usage)>0)t={usage:o.usage,index:r}}n=Math.max(n,i.timestamp)}return t}function S(e){let n="messages"in e?e.messages:e,t=B(n);if(t){let i=_(t.usage),o=0;for(let a=t.index+1;a<n.length;a++)o+=E(n[a]);return{tokens:i+o,usageTokens:i,trailingTokens:o,lastUsageIndex:t.index}}let r=0;for(let i of n)r+=E(i);return{tokens:r,usageTokens:0,trailingTokens:r,lastUsageIndex:null}}function R(e){if(!e||e.length===0)return 0;return v(P(e))}var F=4096,q=1;function Zt(e,n,t){if(e.contextWindow<=0)return Math.max(q,t);let r=e.contextWindow-S(n).tokens-F;return Math.min(t,Math.max(q,r))}function ct(e,n,t){let r=H(e,n),i=e.samplingParamsByThinkingLevel?.[r];return e.samplingParams||i||t?{...e.samplingParams,...i,...t}:void 0}function V(e,n,t,r){let i=ct(e,t?.reasoning??"off",t?.samplingParams);return{temperature:t?.temperature,samplingParams:i,maxTokens:Zt(e,n,t?.maxTokens??e.maxTokens),signal:t?.signal,telemetryContext:t?.telemetryContext,apiKey:r||t?.apiKey,fetch:t?.fetch,transport:t?.transport,cacheRetention:t?.cacheRetention,sessionId:t?.sessionId,headers:t?.headers,onPayload:t?.onPayload,onResponse:t?.onResponse,onProviderStreamEvent:t?.onProviderStreamEvent,timeoutMs:t?.timeoutMs,websocketConnectTimeoutMs:t?.websocketConnectTimeoutMs,maxRetries:t?.maxRetries,maxRetryDelayMs:t?.maxRetryDelayMs,metadata:t?.metadata,env:t?.env}}var z=1024,K={minimal:1024,low:2048,medium:8192,high:16384};function Ao(e){return e==="xhigh"||e==="max"?"high":e}function Eo(e,n){let t={...K,...n},r=Ao(e);return t[r]}function _o(e,n){return Math.min(e,Math.max(0,n-z))}function Or(e,n,t,r){let i=Eo(t,r),o=e===void 0?n:Math.min(e+i,n);if(o<=i)i=_o(i,o);return{maxTokens:o,thinkingBudget:i}}function j(e,n){let t=[],r=!1;for(let i of e){if(i.type==="image"){if(!r)t.push({type:"text",text:n});r=!0;continue}t.push(i),r=i.text===n}return t}function Y(e,n){if(n.input.includes("image"))return e;return e.map((t)=>{if(t.role==="user"&&Array.isArray(t.content))return{...t,content:j(t.content,"(image omitted: model does not support images)")};if(t.role==="toolResult")return{...t,content:j(t.content,"(tool image omitted: model does not support images)")};return t})}function me(e,n,t){let r=new Map,i=e.map((s)=>s.content==null?{...s,content:[]}:s),a=Y(i,n).map((s)=>{if(s.role==="system"||s.role==="user")return s;if(s.role==="toolResult"){let u=r.get(s.toolCallId);if(u&&u!==s.toolCallId)return{...s,toolCallId:u};return s}if(s.role==="assistant"){let u=s,c=u.provider===n.provider&&u.api===n.api&&u.model===n.id,x=u.content.flatMap((f)=>{if(f.type==="thinking"){if(f.redacted)return c?f:[];if(c&&f.thinkingSignature)return f;if(!f.thinking||f.thinking.trim()==="")return[];if(c)return f;return{type:"text",text:f.thinking}}if(f.type==="text"){if(c)return f;return{type:"text",text:f.text}}if(f.type==="toolCall"){let m=f,g=m;if(!c&&m.thoughtSignature)g={...m},delete g.thoughtSignature;if(!c&&t){let I=t(m.id,n,u);if(I!==m.id)r.set(m.id,I),g={...g,id:I}}return g}return f});return{...u,content:x}}return s}),l=[],d=[],h=new Set,T=[],A=()=>{if(d.length>0){for(let s of d)if(!h.has(s.id))l.push({role:"toolResult",toolCallId:s.id,toolName:s.name,content:[{type:"text",text:"No result provided"}],isError:!0,timestamp:Date.now()});d=[],h=new Set}l.push(...T),T.length=0};for(let s=0;s<a.length;s++){let u=a[s];if(u.role==="assistant"){A();let c=u;if(c.stopReason==="error"||c.stopReason==="aborted")continue;let x=c.content.filter((f)=>f.type==="toolCall");if(x.length>0)d=x,h=new Set;l.push(u)}else if(u.role==="toolResult")h.add(u.toolCallId),l.push(u);else if(u.role==="system")if(d.length>0)T.push(u);else l.push(u);else if(u.role==="user")A(),l.push(u);else l.push(u)}return A(),l}
3
- export{de,Mr,Lr,ce,Jt,Ee,Zt,ct,V,Ao,Eo,_o,Or,me};
2
+ import{N,H}from"./chunk-8tjad3r0.js";class p extends Error{}var L=["$ref","$defs","definitions","allOf","oneOf","patternProperties","dependentSchemas","dependencies","unevaluatedProperties","propertyNames","contains","prefixItems","not","if","then","else"];function y(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function D(e){if(!y(e))return!1;let n=typeof e.type==="string"?[e.type]:Array.isArray(e.type)?e.type:[];return n.includes("object")||n.includes("array")||e.properties!==void 0||e.items!==void 0}function M(e){if(!y(e))return!1;if(e.type==="null"||Array.isArray(e.type)&&e.type.includes("null"))return!0;if(e.const===null||Array.isArray(e.enum)&&e.enum.includes(null))return!0;return Array.isArray(e.anyOf)&&e.anyOf.some((n)=>M(n))}function w(e,n){if(!y(e))throw new p("boolean schemas are unsupported");for(let a of L)if(e[a]!==void 0)throw new p(`${a} schemas are unsupported`);if(n){for(let[a,l]of Object.entries(e))if(n(a,l))throw new p(`${a}: ${JSON.stringify(l)} is unsupported`)}if(e.anyOf!==void 0){if(!Array.isArray(e.anyOf)||e.anyOf.length===0)throw new p("anyOf must contain at least one schema");for(let a of e.anyOf){if(D(a))throw new p("object and array unions are unsupported");w(a,n)}}if(e.items!==void 0){if(Array.isArray(e.items))throw new p("tuple schemas are unsupported");w(e.items,n)}let t=e.type==="object";if(e.properties!==void 0&&!t)throw new p("properties require type object");if(!t)return;if(e.additionalProperties!==void 0&&e.additionalProperties!==!1)throw new p("schema-valued or true additionalProperties is unsupported");if(e.properties!==void 0&&!y(e.properties))throw new p("object properties must be a schema map");if(e.required!==void 0&&(!Array.isArray(e.required)||e.required.some((a)=>typeof a!=="string")))throw new p("object required must be a string array");let r=e.properties??{},i=Object.keys(r),o=new Set(Array.isArray(e.required)?e.required:[]);if([...o].some((a)=>!i.includes(a)))throw new p("required contains an unknown property");for(let[a,l]of Object.entries(r))if(w(l,n),!o.has(a)&&!M(l))r[a]={anyOf:[l,{type:"null"}]};e.required=i,e.additionalProperties=!1}function k(e,n){let t=structuredClone(e);if(!y(t))throw new p("root schema must have type object");if(w(t,n),t.type!=="object")throw new p("root schema must have type object");return t}function me(e,n){return n===!0?k(e.parameters):e.parameters}function Mr(e,n,t){let r=n[t];if(typeof r!=="string")throw Error(`Grammar tool call "${e}" requires argument "${t}" to be a string.`);return r}function Lr(e,n,t,r){if(e.closed){if(r&&t===e.input)return;throw Error(`grammar tool input for property "${n}" changed after it was closed`)}if(!t.startsWith(e.input))throw Error(`grammar tool input for property "${n}" changed non-monotonically`);let i=t.slice(e.input.length);if(!r&&i.length===0)return;let o="";if(!e.started)o+=`{${JSON.stringify(n)}:"`,e.started=!0;if(o+=JSON.stringify(i).slice(1,-1),e.input=t,r)o+='"}',e.closed=!0;return o}function G(e){let n=e.parameters;if(n.type!=="object")throw Error("grammar constrained sampling requires an object parameter schema");if(!Array.isArray(n.required)||n.required.length!==1||typeof n.required[0]!=="string")throw Error("grammar constrained sampling requires exactly one required string property");let t=n.required[0];if(!n.properties?.[t])throw Error(`grammar constrained sampling requires a properties entry for ${t}`);if(n.properties[t]?.type!=="string")throw Error(`grammar constrained sampling property ${t} must have type string`);return t}function ce(e,n,t){let r=e.constrainedSampling;if(!r||r.type!=="json_schema")return;if(n)try{return k(e.parameters,t),!0}catch(i){if(!(i instanceof p))throw i;if(r.strict!=="require")return;throw Error(`Tool "${e.name}" requires JSON-schema constrained sampling, but ${i.message}.`)}if(r.strict==="require")throw Error(`Tool "${e.name}" requires JSON-schema constrained sampling, but strict tools are unsupported.`);return}function Jt(e,n){let t=e.constrainedSampling;if(!t||t.type!=="grammar")return;if(!n)return;let r=t.variants.openai_lark,i=t.variants.openai_regex,o=typeof r==="string"&&r.trim().length>0,a=typeof i==="string"&&i.trim().length>0;if(!o&&!a)throw Error(`Tool "${e.name}" cannot use grammar constrained sampling: no supported grammar variant was provided.`);try{return{format:o?"lark":"regex",definition:o?r:i,inputProperty:G(e)}}catch(l){let d=l instanceof Error?l.message:String(l);throw Error(`Tool "${e.name}" cannot use grammar constrained sampling: ${d}.`)}}function Ee(e,n){let t=new Map;for(let r of e??[]){let i=Jt(r,n);if(i)t.set(r.name,i.inputProperty)}return t}var O=3.5,b=4800;function _(e){return e.totalTokens||e.input+e.output+e.cacheRead+e.cacheWrite}function P(e){try{return JSON.stringify(e)??"undefined"}catch{return"[unserializable]"}}function W(e){if(typeof e==="string")return e.length;let n=0;for(let t of e)n+=t.type==="text"?t.text.length:b;return n}function v(e){return Math.ceil(e.length/O)}function C(e){return Math.ceil(W(e)/O)}function E(e){let n=0;if(e.role==="system")return v(N(e))+R(e.toolsAdded)+R(e.toolsRemoved);if(e.role==="user")return C(e.content);if(e.role==="toolResult")return C(e.content);for(let t of e.content)if(t.type==="text")n+=t.text.length;else if(t.type==="thinking")n+=t.thinking.length;else n+=t.name.length+P(t.arguments).length;return Math.ceil(n/O)}function B(e){let n=Number.NEGATIVE_INFINITY,t;for(let r=0;r<e.length;r++){let i=e[r];if(i.role==="assistant"){let o=i;if(o.timestamp>=n&&o.stopReason!=="aborted"&&o.stopReason!=="error"&&_(o.usage)>0)t={usage:o.usage,index:r}}n=Math.max(n,i.timestamp)}return t}function S(e){let n="messages"in e?e.messages:e,t=B(n);if(t){let i=_(t.usage),o=0;for(let a=t.index+1;a<n.length;a++)o+=E(n[a]);return{tokens:i+o,usageTokens:i,trailingTokens:o,lastUsageIndex:t.index}}let r=0;for(let i of n)r+=E(i);return{tokens:r,usageTokens:0,trailingTokens:r,lastUsageIndex:null}}function R(e){if(!e||e.length===0)return 0;return v(P(e))}var F=4096,q=1;function Zt(e,n,t){if(e.contextWindow<=0)return Math.max(q,t);let r=e.contextWindow-S(n).tokens-F;return Math.min(t,Math.max(q,r))}function ct(e,n,t){let r=H(e,n),i=e.samplingParamsByThinkingLevel?.[r];return e.samplingParams||i||t?{...e.samplingParams,...i,...t}:void 0}function V(e,n,t,r){let i=ct(e,t?.reasoning??"off",t?.samplingParams);return{temperature:t?.temperature,samplingParams:i,maxTokens:Zt(e,n,t?.maxTokens??e.maxTokens),signal:t?.signal,telemetryContext:t?.telemetryContext,apiKey:r||t?.apiKey,fetch:t?.fetch,transport:t?.transport,cacheRetention:t?.cacheRetention,sessionId:t?.sessionId,headers:t?.headers,onPayload:t?.onPayload,onResponse:t?.onResponse,onProviderStreamEvent:t?.onProviderStreamEvent,timeoutMs:t?.timeoutMs,websocketConnectTimeoutMs:t?.websocketConnectTimeoutMs,maxRetries:t?.maxRetries,maxRetryDelayMs:t?.maxRetryDelayMs,metadata:t?.metadata,env:t?.env}}var z=1024,K={minimal:1024,low:2048,medium:8192,high:16384};function Ao(e){return e==="xhigh"||e==="max"?"high":e}function Eo(e,n){let t={...K,...n},r=Ao(e);return t[r]}function _o(e,n){return Math.min(e,Math.max(0,n-z))}function Or(e,n,t,r){let i=Eo(t,r),o=e===void 0?n:Math.min(e+i,n);if(o<=i)i=_o(i,o);return{maxTokens:o,thinkingBudget:i}}function j(e,n){let t=[],r=!1;for(let i of e){if(i.type==="image"){if(!r)t.push({type:"text",text:n});r=!0;continue}t.push(i),r=i.text===n}return t}function Y(e,n){if(n.input.includes("image"))return e;return e.map((t)=>{if(t.role==="user"&&Array.isArray(t.content))return{...t,content:j(t.content,"(image omitted: model does not support images)")};if(t.role==="toolResult")return{...t,content:j(t.content,"(tool image omitted: model does not support images)")};return t})}function he(e,n,t){let r=new Map,i=e.map((s)=>s.content==null?{...s,content:[]}:s),a=Y(i,n).map((s)=>{if(s.role==="system"||s.role==="user")return s;if(s.role==="toolResult"){let u=r.get(s.toolCallId);if(u&&u!==s.toolCallId)return{...s,toolCallId:u};return s}if(s.role==="assistant"){let u=s,c=u.provider===n.provider&&u.api===n.api&&u.model===n.id,x=u.content.flatMap((f)=>{if(f.type==="thinking"){if(f.redacted)return c?f:[];if(c&&f.thinkingSignature)return f;if(!f.thinking||f.thinking.trim()==="")return[];if(c)return f;return{type:"text",text:f.thinking}}if(f.type==="text"){if(c)return f;return{type:"text",text:f.text}}if(f.type==="toolCall"){let m=f,g=m;if(!c&&m.thoughtSignature)g={...m},delete g.thoughtSignature;if(!c&&t){let I=t(m.id,n,u);if(I!==m.id)r.set(m.id,I),g={...g,id:I}}return g}return f});return{...u,content:x}}return s}),l=[],d=[],h=new Set,T=[],A=()=>{if(d.length>0){for(let s of d)if(!h.has(s.id))l.push({role:"toolResult",toolCallId:s.id,toolName:s.name,content:[{type:"text",text:"No result provided"}],isError:!0,timestamp:Date.now()});d=[],h=new Set}l.push(...T),T.length=0};for(let s=0;s<a.length;s++){let u=a[s];if(u.role==="assistant"){A();let c=u;if(c.stopReason==="error"||c.stopReason==="aborted")continue;let x=c.content.filter((f)=>f.type==="toolCall");if(x.length>0)d=x,h=new Set;l.push(u)}else if(u.role==="toolResult")h.add(u.toolCallId),l.push(u);else if(u.role==="system")if(d.length>0)T.push(u);else l.push(u);else if(u.role==="user")A(),l.push(u);else l.push(u)}return A(),l}
3
+ export{me,Mr,Lr,ce,Jt,Ee,Zt,ct,V,Ao,Eo,_o,Or,he};