@bkm016/basalt 0.1.2 → 0.1.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 (152) hide show
  1. package/{chunk-x1xss1d7.js → chunk-1vd0f74z.js} +2 -2
  2. package/{chunk-v9fea96h.js → chunk-2hbfk5xd.js} +2 -2
  3. package/{chunk-5j1krv9v.js → chunk-2zp1mv3q.js} +1 -1
  4. package/{chunk-d2j735sd.js → chunk-3ct2tkr8.js} +2 -2
  5. package/{chunk-c7x1zq39.js → chunk-3x94302m.js} +1 -1
  6. package/{chunk-gzxnene8.js → chunk-4w17tzp5.js} +2 -2
  7. package/{chunk-1zdwrgd4.js → chunk-5dfbezv9.js} +1 -1
  8. package/{chunk-shhrr741.js → chunk-5x1sankd.js} +24 -24
  9. package/{chunk-pmqtkqsf.js → chunk-71h08f4g.js} +1 -1
  10. package/{chunk-fm0k0qtz.js → chunk-7afmgncg.js} +2 -2
  11. package/{chunk-v258nxcz.js → chunk-7nzhdrv9.js} +1 -1
  12. package/{chunk-zmsgwr3s.js → chunk-7q51n619.js} +1 -1
  13. package/{chunk-y0m980k3.js → chunk-7tbya5b5.js} +3 -3
  14. package/{chunk-8tjad3r0.js → chunk-8wc8qdx8.js} +5 -5
  15. package/{chunk-gp7y0fja.js → chunk-9rmqgc3c.js} +9 -9
  16. package/{chunk-nbb9trwz.js → chunk-akr0a8nc.js} +2 -2
  17. package/{chunk-k506w58v.js → chunk-aky4tztg.js} +2 -2
  18. package/{chunk-8296hw9m.js → chunk-em187cy3.js} +2 -2
  19. package/{chunk-2esbgxps.js → chunk-ev6yvy5y.js} +5 -5
  20. package/{chunk-75m78j7x.js → chunk-f3xadvab.js} +2 -2
  21. package/{chunk-5c9j8qe4.js → chunk-fvn32nzj.js} +26 -26
  22. package/{chunk-bannb9xm.js → chunk-jk25nt60.js} +1 -1
  23. package/{chunk-27gntzs5.js → chunk-kp22kaez.js} +1 -1
  24. package/{chunk-6hssbcgj.js → chunk-nmca5h6m.js} +1 -1
  25. package/{chunk-d8gtbw9g.js → chunk-pjyn2s97.js} +1 -1
  26. package/{chunk-rtzqqngy.js → chunk-q7t30zz2.js} +2 -2
  27. package/{chunk-aefadsy6.js → chunk-r0scgfwx.js} +1 -1
  28. package/{chunk-hwr56pfj.js → chunk-rmj5b73e.js} +1 -1
  29. package/{chunk-1qpces5a.js → chunk-vexrrw1b.js} +2 -2
  30. package/chunk-vkpvcxjr.js +2 -0
  31. package/{chunk-3cjsd292.js → chunk-whvj83b7.js} +2 -2
  32. package/{chunk-z55bmysw.js → chunk-xh3vr5vz.js} +1 -1
  33. package/{chunk-10xzzn07.js → chunk-zggzfa7j.js} +2 -2
  34. package/compiled.js +3 -3
  35. package/package.json +1 -1
  36. package/ui-test-worker.js +13 -13
  37. package/web/{chunk-shbw6wg8.js → chunk-0b47eyrf.js} +1 -1
  38. package/web/{chunk-vz5ck6x9.js → chunk-0h0vb6gt.js} +1 -1
  39. package/web/{chunk-24k0r5aq.js → chunk-0rmkpsgp.js} +1 -1
  40. package/web/{chunk-3mvr2gwh.js → chunk-0xkyryrq.js} +1 -1
  41. package/web/{chunk-284a17k8.js → chunk-0z0y25zf.js} +1 -1
  42. package/web/{chunk-ezkqa7we.js → chunk-1eg9sbbt.js} +1 -1
  43. package/web/{chunk-raqqscwa.js → chunk-1gbd61z0.js} +1 -1
  44. package/web/{chunk-s3rdx28k.js → chunk-2s0bmrkv.js} +1 -1
  45. package/web/{chunk-9re6yttj.js → chunk-2z1rwr28.js} +1 -1
  46. package/web/{chunk-avwpjsxw.js → chunk-344bq59c.js} +1 -1
  47. package/web/{chunk-kgerjbn4.js → chunk-3re8y26v.js} +1 -1
  48. package/web/chunk-3t0211rw.js +1 -0
  49. package/web/{chunk-q1pkntc6.js → chunk-42e3b9hv.js} +1 -1
  50. package/web/chunk-44rmrmcn.js +1 -0
  51. package/web/{chunk-aqm3spxt.js → chunk-4bzqrwr0.js} +89 -89
  52. package/web/{chunk-5e7ygjdn.js → chunk-4d3a7xs2.js} +1 -1
  53. package/web/{chunk-2pjdtesn.js → chunk-4jmazh6x.js} +1 -1
  54. package/web/{chunk-r92sbgwv.js → chunk-4re74xwm.js} +1 -1
  55. package/web/{chunk-rc2vq9wz.js → chunk-5qtyq3ce.js} +1 -1
  56. package/web/{chunk-vj6kstpp.js → chunk-5z4jcqct.js} +1 -1
  57. package/web/{chunk-abbvjt4e.js → chunk-5z6x2n5h.js} +1 -1
  58. package/web/{chunk-yen2kkn2.js → chunk-6cnek1xh.js} +1 -1
  59. package/web/chunk-6f5ke0x9.js +1 -0
  60. package/web/{chunk-vkc149rb.js → chunk-6xaqxcq8.js} +1 -1
  61. package/web/chunk-7q6wvv2x.js +1 -0
  62. package/web/{chunk-43jqvsrg.js → chunk-7qsa4p8h.js} +1 -1
  63. package/web/chunk-8nja0ygy.js +1 -0
  64. package/web/{chunk-4bry4xds.js → chunk-8y64fkpz.js} +1 -1
  65. package/web/{chunk-rkj743fg.js → chunk-92ssjk2y.js} +1 -1
  66. package/web/chunk-9ad7v7bm.js +8 -0
  67. package/web/{chunk-xdcs8qz3.js → chunk-9cx1be43.js} +1 -1
  68. package/web/{chunk-jf2ehmvp.js → chunk-9dzxv335.js} +1 -1
  69. package/web/{chunk-t1xk6hca.js → chunk-9t5dnjaz.js} +2 -2
  70. package/web/{chunk-h31p43qa.js → chunk-a408enpy.js} +1 -1
  71. package/web/{chunk-z24vs8q9.js → chunk-a497tykb.js} +1 -1
  72. package/web/{chunk-qryrg2pq.js → chunk-aqfpnhmt.js} +2 -2
  73. package/web/{chunk-rrws61wf.js → chunk-b1bgzz66.js} +1 -1
  74. package/web/{chunk-cwvtraca.js → chunk-b53bfkys.js} +1 -1
  75. package/web/{chunk-5jbf7n5q.js → chunk-b6k9w215.js} +1 -1
  76. package/web/{chunk-ctcrk3qn.js → chunk-bhsaj6qq.js} +1 -1
  77. package/web/chunk-cjfssg3m.js +2 -0
  78. package/web/{chunk-znvnb9dh.js → chunk-d11v5s7w.js} +1 -1
  79. package/web/{chunk-ctd8bfg2.js → chunk-df5zx17h.js} +1 -1
  80. package/web/chunk-e0zre35a.js +1 -0
  81. package/web/{chunk-3z93efr4.js → chunk-e9twvs9n.js} +1 -1
  82. package/web/chunk-f2kgtyfp.js +1 -0
  83. package/web/{chunk-8wye0wbb.js → chunk-f4tacm06.js} +1 -1
  84. package/web/chunk-f8bn5tzf.js +1 -0
  85. package/web/chunk-fdp9bsj7.js +1 -0
  86. package/web/{chunk-8ah6ce1b.js → chunk-fh2vj0wv.js} +1 -1
  87. package/web/{chunk-5rx8rtsa.js → chunk-gmzqdm7v.js} +1 -1
  88. package/web/{chunk-fqj9kry9.js → chunk-hvw3gn2a.js} +1 -1
  89. package/web/{chunk-fy8ey195.js → chunk-khxcn8tt.js} +1 -1
  90. package/web/{chunk-z760wagr.js → chunk-kmr7r9xj.js} +1 -1
  91. package/web/chunk-kqqmp1am.js +1 -0
  92. package/web/{chunk-s3hwejnr.js → chunk-kwccs9f6.js} +1 -1
  93. package/web/chunk-nbgqbxcy.js +1 -0
  94. package/web/{chunk-yjv2c45j.js → chunk-ncpnpe9w.js} +1 -1
  95. package/web/{chunk-g8ee1csm.js → chunk-ne0v8mfb.js} +1 -1
  96. package/web/{chunk-f078k1ej.js → chunk-ngx2cp8x.js} +1 -1
  97. package/web/{chunk-xa88zgkr.js → chunk-nvhmq4z5.js} +1 -1
  98. package/web/chunk-nxcgf7ec.js +1 -0
  99. package/web/{chunk-anbn2ttv.js → chunk-p0kvmf28.js} +1 -1
  100. package/web/chunk-p3k7m5nr.js +1 -0
  101. package/web/{chunk-jzmzhj8z.js → chunk-pggaffrh.js} +1 -1
  102. package/web/{chunk-zrzq29e6.js → chunk-pjkdrgm0.js} +1 -1
  103. package/web/{chunk-jmnaq7c1.js → chunk-pws2seas.js} +1 -1
  104. package/web/{chunk-1z5p7a1h.js → chunk-pz9ps2jm.js} +1 -1
  105. package/web/chunk-qh15dxav.css +1 -0
  106. package/web/chunk-qpmbxhh6.js +1 -0
  107. package/web/chunk-r0rctnxz.js +1 -0
  108. package/web/chunk-rn3dnqm8.js +1 -0
  109. package/web/{chunk-jvj66qhs.js → chunk-rvrf0f3h.js} +1 -1
  110. package/web/{chunk-pk3ap3wh.js → chunk-sfg2wkhe.js} +1 -1
  111. package/web/{chunk-tn1xzmgx.js → chunk-sspfxp5e.js} +1 -1
  112. package/web/{chunk-dt8ss97f.js → chunk-t4c8xavd.js} +1 -1
  113. package/web/{chunk-vny496ba.js → chunk-tdr6x2xc.js} +1 -1
  114. package/web/chunk-tncvg1nn.js +1 -0
  115. package/web/{chunk-6qejm5s2.js → chunk-vyp0ns1f.js} +1 -1
  116. package/web/{chunk-kww4azv5.js → chunk-wnskxerq.js} +1 -1
  117. package/web/{chunk-9dd1c37b.js → chunk-wvdehm9y.js} +66 -66
  118. package/web/chunk-x7ahcpj7.js +1 -0
  119. package/web/chunk-y38bf0wm.js +1 -0
  120. package/web/{chunk-vjqmnkh2.js → chunk-y56aaba5.js} +1 -1
  121. package/web/{chunk-mjpjkyd1.js → chunk-ybrf9mhz.js} +1 -1
  122. package/web/{chunk-8e43yaq3.js → chunk-ye58t45p.js} +3 -3
  123. package/web/{chunk-dk90px7g.js → chunk-yqbnps3a.js} +1 -1
  124. package/web/{chunk-bt1m87ck.js → chunk-z1h20s8c.js} +1 -1
  125. package/web/{chunk-693m9kt7.js → chunk-zj4q9jth.js} +1 -1
  126. package/web/{chunk-tnv7z83q.js → chunk-zj5k94dk.js} +1 -1
  127. package/web/{chunk-986z0p48.js → chunk-zqch0sc8.js} +1 -1
  128. package/web/{chunk-agmkx996.js → chunk-zx8zec24.js} +1 -1
  129. package/web/index.html +1 -1
  130. package/chunk-09rj27b2.js +0 -2
  131. package/web/chunk-0sewdyz1.js +0 -1
  132. package/web/chunk-21ke27j6.js +0 -1
  133. package/web/chunk-3t3zwx9j.js +0 -1
  134. package/web/chunk-5xc9d5ft.js +0 -1
  135. package/web/chunk-b470hvpk.js +0 -1
  136. package/web/chunk-fekjj24p.css +0 -1
  137. package/web/chunk-frjfamx7.js +0 -8
  138. package/web/chunk-h5p5jsrw.js +0 -1
  139. package/web/chunk-h9fmr6ch.js +0 -1
  140. package/web/chunk-jq0pw0k2.js +0 -1
  141. package/web/chunk-k4cfnvyq.js +0 -1
  142. package/web/chunk-m29dhjkh.js +0 -1
  143. package/web/chunk-mj6tee5h.js +0 -1
  144. package/web/chunk-szcy5z56.js +0 -1
  145. package/web/chunk-t2hhdg9r.js +0 -1
  146. package/web/chunk-tj4cmkwe.js +0 -1
  147. package/web/chunk-v2b5q0n5.js +0 -1
  148. package/web/chunk-y5x74t89.js +0 -1
  149. package/web/chunk-yx3dh5hg.js +0 -1
  150. package/web/chunk-yz4fmtk2.js +0 -1
  151. package/web/chunk-z5j6x6j8.js +0 -2
  152. package/web/chunk-z5stjrhc.js +0 -1
@@ -1,6 +1,6 @@
1
1
  // @bun
2
- import{F}from"./chunk-m8vkwdgr.js";import{Ze}from"./chunk-g2t6t8fk.js";import{me,Mr,Lr,ce,Jt,he}from"./chunk-3cjsd292.js";import{g}from"./chunk-n6e43rvk.js";import{N,Me,re,ye,Q}from"./chunk-8tjad3r0.js";function j(a,o){let l={v:1,id:a};if(o)l.phase=o;return JSON.stringify(l)}function E(a){if(!a)return;if(a.startsWith("{"))try{let o=JSON.parse(a);if(o.v===1&&typeof o.id==="string"){if(o.phase==="commentary"||o.phase==="final_answer")return{id:o.id,phase:o.phase};return{id:o.id}}}catch{}return{id:a}}function W(a,o){let l=o.filter((c)=>c.type==="text").map((c)=>c.text).join(`
3
- `),d=o.filter((c)=>c.type==="image"),u=l.length>0;if(d.length===0||!a.input.includes("image"))return g(u?l:d.length>0?"(see attached image)":"(no tool output)");let p=[];if(u)p.push({type:"input_text",text:g(l)});for(let c of d)p.push({type:"input_image",detail:"auto",image_url:`data:${c.mimeType};base64,${c.data}`});return p}function at(a,o,l,d){let u=re(o,d?.supportsMidConvoSystemMessages),p=[],c=(n)=>{let s=n.replace(/[^a-zA-Z0-9_-]/g,"_");return(s.length>64?s.slice(0,64):s).replace(/_+$/,"")},b=(n)=>{let s=`fc_${Ze(n)}`;return s.length>64?s.slice(0,64):s},k=(n,s,i)=>{if(!l.has(a.provider))return c(n);if(!n.includes("|"))return c(n);let[r,_]=n.split("|"),y=c(r),x=i.provider!==a.provider||i.api!==a.api?b(_):c(_);if(!x.startsWith("fc_"))x=c(`fc_${x}`);return`${y}|${x}`},m=he(u.messages,a,k),I=ye(u.messages,(d?.supportsAdditionalTools??!1)||(d?.supportsToolSearch??!1)),v=(n,s)=>{let i=I.anchorsAdditions?n.toolsAdded??[]:[];if(i.length===0)return;if(d?.supportsAdditionalTools){p.push({type:"additional_tools",role:"developer",tools:Je(i,d.toolOptions)});return}if(!d?.supportsToolSearch)return;let r=i.map((y)=>y.name),_=`pi_tool_load_${Ze(`${s}:${r.join(",")}`)}`;p.push({type:"tool_search_call",call_id:_,execution:"client",status:"completed",arguments:{query:r.join(" "),limit:r.length}}),p.push({type:"tool_search_output",call_id:_,execution:"client",status:"completed",tools:Je(i,{...d.toolOptions,toolSearchResult:!0})})},C=d?.includeSystemPrompt??!0,w=a.compat,M=a.reasoning&&w?.supportsDeveloperRole!==!1?"developer":"system",t=0,e=0;for(let n of m){let s=e++===0&&n.role==="system";if(n.role==="system"){if(!s)v(n,`system:${t}`);if(!s||C){let i=s?N(n):Me(n);if(i.length>0)p.push({role:M,content:g(i)})}}else if(n.role==="user")if(typeof n.content==="string")p.push({role:"user",content:[{type:"input_text",text:g(n.content)}]});else{let i=n.content.map((r)=>{if(r.type==="text")return{type:"input_text",text:g(r.text)};return{type:"input_image",detail:"auto",image_url:`data:${r.mimeType};base64,${r.data}`}});if(i.length===0)continue;p.push({role:"user",content:i})}else if(n.role==="assistant"){let i=[],r=n,_=r.provider===a.provider&&r.api===a.api,y=_&&r.model===a.id,P=_&&r.model!==a.id,x=0;for(let S of n.content)if(S.type==="thinking"){if(S.thinkingSignature){let f=JSON.parse(S.thinkingSignature);i.push(f)}}else if(S.type==="text"){let f=S,T=E(f.textSignature),J=x===0?`msg_pi_${t}`:`msg_pi_${t}_${x}`;x++;let h=T?.id;if(!h)h=J;else if(h.length>64)h=`msg_${Ze(h)}`;i.push({type:"message",role:"assistant",content:[{type:"output_text",text:g(f.text),annotations:[]}],status:"completed",id:h,phase:T?.phase})}else if(S.type==="toolCall"){let f=S,[T,J]=f.id.split("|"),h=d?.grammarToolInputProperties?.get(f.name),R=J,A=h===void 0?"fc_":"ctc_";if(P||!R?.startsWith(A))R=void 0;if(h!==void 0)i.push({type:"custom_tool_call",id:R,call_id:T,name:f.name,input:g(Mr(f.name,f.arguments,h)),...y&&f.namespace!==void 0?{namespace:f.namespace}:{}});else i.push({type:"function_call",id:R,call_id:T,name:f.name,arguments:JSON.stringify(f.arguments),...y&&f.namespace!==void 0?{namespace:f.namespace}:{}})}if(i.length===0)continue;p.push(...i)}else if(n.role==="toolResult"){let[i]=n.toolCallId.split("|"),r=W(a,n.content);if(d?.grammarToolInputProperties?.has(n.toolName))p.push({type:"custom_tool_call_output",call_id:i,output:r});else p.push({type:"function_call_output",call_id:i,output:r})}if(!s)t++}return p}function Je(a,o){let l=o?.strict===void 0?!1:o.strict,d=o?.supportsStrictMode??!0,u=o?.supportsOpenAIGrammarTools??!1;return a.map((p)=>{let c=Jt(p,u);if(c)return{type:"custom",name:p.name,description:p.description,format:{type:"grammar",syntax:c.format,definition:c.definition},...o?.toolSearchResult?{defer_loading:!0}:{}};let k=ce(p,d)??l,m={type:"function",name:p.name,description:p.description,parameters:me(p,k===!0),...o?.toolSearchResult?{defer_loading:!0}:{}};if(d)m.strict=k;return m})}function z(a){let o=a.customInput?.property;if(o===void 0)return"";let l=a.arguments[o];return typeof l==="string"?l:""}function O(a,o,l){let d=a.customInput;if(!d)return;let u=Lr(d.jsonBuffer,d.property,o,l);return a.arguments={[d.property]:o},u}async function lt(a,o,l,d,u){let p=!1,c=new Map,b=new Map,k=(t)=>{if(t.type==="message"&&t.phase==="final_answer")o.stopReason="stop"},m=(t,e)=>{let n=c.get(t);return n?.type===e?n:void 0},I=(t,e)=>{if(e===void 0)return;l.push({type:"toolcall_delta",contentIndex:t.contentIndex,delta:e,partial:o})},v=(t,e)=>{if(e.type==="reasoning"){let n={type:"thinking",thinking:""};o.content.push(n);let s={type:"thinking",block:n,contentIndex:o.content.length-1};return c.set(t,s),l.push({type:"thinking_start",contentIndex:s.contentIndex,partial:o}),s}if(e.type==="message"){k(e);let n={type:"text",text:""};o.content.push(n);let s={type:"text",block:n,contentIndex:o.content.length-1};return c.set(t,s),l.push({type:"text_start",contentIndex:s.contentIndex,partial:o}),s}if(e.type==="function_call"){let n={type:"toolCall",id:`${e.call_id}|${e.id}`,name:e.name,arguments:{},...e.namespace!==void 0?{namespace:e.namespace}:{},partialJson:e.arguments||""};o.content.push(n);let s={type:"toolCall",block:n,contentIndex:o.content.length-1};return c.set(t,s),l.push({type:"toolcall_start",contentIndex:s.contentIndex,partial:o}),s}if(e.type==="custom_tool_call"){let n=u?.grammarToolInputProperties?.get(e.name)??"input",s=e.input||"",i={type:"toolCall",id:`${e.call_id}|${e.id}`,name:e.name,arguments:{[n]:s},...e.namespace!==void 0?{namespace:e.namespace}:{},customInput:{property:n,jsonBuffer:{input:"",started:!1,closed:!1}}};o.content.push(i);let r={type:"toolCall",block:i,contentIndex:o.content.length-1};return c.set(t,r),l.push({type:"toolcall_start",contentIndex:r.contentIndex,partial:o}),r}return},C=(t,e)=>c.get(t)??v(t,e),w=(t)=>{for(let e of t){if(e.type!=="reasoning"||!e.encrypted_content)continue;let n=b.get(e.id);if(!n?.thinkingSignature)continue;let s=JSON.parse(n.thinkingSignature);if(s.encrypted_content)continue;n.thinkingSignature=JSON.stringify({...s,encrypted_content:e.encrypted_content})}},M=(t)=>{if(p=!0,w(t.output??[]),t?.id)o.responseId=t.id;if(t?.usage){let r=t.usage.input_tokens_details,_=r?.cached_tokens||0,y=r?.cache_write_tokens||0;o.usage={input:Math.max(0,(t.usage.input_tokens||0)-_-y),output:t.usage.output_tokens||0,cacheRead:_,cacheWrite:y,reasoning:t.usage.output_tokens_details?.reasoning_tokens||0,totalTokens:t.usage.total_tokens||0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}}}if(Q(d,o.usage),u?.applyServiceTierPricing){let r=u.resolveServiceTier?u.resolveServiceTier(t?.service_tier,u.serviceTier):t?.service_tier??u.serviceTier;u.applyServiceTierPricing(o.usage,r)}let e=t?.status,n=t?.incomplete_details,s=typeof n?.reason==="string"?n.reason:void 0;o.rawStopReason=s?`${e}.${s}`:e;let i=B(e,s);if(o.stopReason=i.stopReason,i.errorMessage===void 0)delete o.errorMessage;else o.errorMessage=i.errorMessage;if(o.content.some((r)=>r.type==="toolCall")&&o.stopReason==="stop")o.stopReason="toolUse"};for await(let t of a)if(await u?.onProviderStreamEvent?.(t,d),t.type==="response.created")o.responseId=t.response.id;else if(t.type==="response.output_item.added")v(t.output_index,t.item);else if(t.type==="response.reasoning_summary_text.delta"){let e=m(t.output_index,"thinking");if(!e)continue;e.block.thinking+=t.delta,l.push({type:"thinking_delta",contentIndex:e.contentIndex,delta:t.delta,partial:o})}else if(t.type==="response.reasoning_summary_part.done"){let e=m(t.output_index,"thinking");if(!e)continue;e.block.thinking+=`
2
+ import{F}from"./chunk-m8vkwdgr.js";import{Ze}from"./chunk-g2t6t8fk.js";import{me,Lr,Or,ce,Jt,he}from"./chunk-whvj83b7.js";import{g}from"./chunk-n6e43rvk.js";import{N,Me,re,ye,Q}from"./chunk-8wc8qdx8.js";function j(a,o){let l={v:1,id:a};if(o)l.phase=o;return JSON.stringify(l)}function E(a){if(!a)return;if(a.startsWith("{"))try{let o=JSON.parse(a);if(o.v===1&&typeof o.id==="string"){if(o.phase==="commentary"||o.phase==="final_answer")return{id:o.id,phase:o.phase};return{id:o.id}}}catch{}return{id:a}}function W(a,o){let l=o.filter((c)=>c.type==="text").map((c)=>c.text).join(`
3
+ `),d=o.filter((c)=>c.type==="image"),u=l.length>0;if(d.length===0||!a.input.includes("image"))return g(u?l:d.length>0?"(see attached image)":"(no tool output)");let p=[];if(u)p.push({type:"input_text",text:g(l)});for(let c of d)p.push({type:"input_image",detail:"auto",image_url:`data:${c.mimeType};base64,${c.data}`});return p}function at(a,o,l,d){let u=re(o,d?.supportsMidConvoSystemMessages),p=[],c=(n)=>{let s=n.replace(/[^a-zA-Z0-9_-]/g,"_");return(s.length>64?s.slice(0,64):s).replace(/_+$/,"")},b=(n)=>{let s=`fc_${Ze(n)}`;return s.length>64?s.slice(0,64):s},k=(n,s,i)=>{if(!l.has(a.provider))return c(n);if(!n.includes("|"))return c(n);let[r,_]=n.split("|"),y=c(r),x=i.provider!==a.provider||i.api!==a.api?b(_):c(_);if(!x.startsWith("fc_"))x=c(`fc_${x}`);return`${y}|${x}`},m=he(u.messages,a,k),I=ye(u.messages,(d?.supportsAdditionalTools??!1)||(d?.supportsToolSearch??!1)),v=(n,s)=>{let i=I.anchorsAdditions?n.toolsAdded??[]:[];if(i.length===0)return;if(d?.supportsAdditionalTools){p.push({type:"additional_tools",role:"developer",tools:Je(i,d.toolOptions)});return}if(!d?.supportsToolSearch)return;let r=i.map((y)=>y.name),_=`pi_tool_load_${Ze(`${s}:${r.join(",")}`)}`;p.push({type:"tool_search_call",call_id:_,execution:"client",status:"completed",arguments:{query:r.join(" "),limit:r.length}}),p.push({type:"tool_search_output",call_id:_,execution:"client",status:"completed",tools:Je(i,{...d.toolOptions,toolSearchResult:!0})})},C=d?.includeSystemPrompt??!0,w=a.compat,M=a.reasoning&&w?.supportsDeveloperRole!==!1?"developer":"system",t=0,e=0;for(let n of m){let s=e++===0&&n.role==="system";if(n.role==="system"){if(!s)v(n,`system:${t}`);if(!s||C){let i=s?N(n):Me(n);if(i.length>0)p.push({role:M,content:g(i)})}}else if(n.role==="user")if(typeof n.content==="string")p.push({role:"user",content:[{type:"input_text",text:g(n.content)}]});else{let i=n.content.map((r)=>{if(r.type==="text")return{type:"input_text",text:g(r.text)};return{type:"input_image",detail:"auto",image_url:`data:${r.mimeType};base64,${r.data}`}});if(i.length===0)continue;p.push({role:"user",content:i})}else if(n.role==="assistant"){let i=[],r=n,_=r.provider===a.provider&&r.api===a.api,y=_&&r.model===a.id,P=_&&r.model!==a.id,x=0;for(let S of n.content)if(S.type==="thinking"){if(S.thinkingSignature){let f=JSON.parse(S.thinkingSignature);i.push(f)}}else if(S.type==="text"){let f=S,T=E(f.textSignature),J=x===0?`msg_pi_${t}`:`msg_pi_${t}_${x}`;x++;let h=T?.id;if(!h)h=J;else if(h.length>64)h=`msg_${Ze(h)}`;i.push({type:"message",role:"assistant",content:[{type:"output_text",text:g(f.text),annotations:[]}],status:"completed",id:h,phase:T?.phase})}else if(S.type==="toolCall"){let f=S,[T,J]=f.id.split("|"),h=d?.grammarToolInputProperties?.get(f.name),R=J,A=h===void 0?"fc_":"ctc_";if(P||!R?.startsWith(A))R=void 0;if(h!==void 0)i.push({type:"custom_tool_call",id:R,call_id:T,name:f.name,input:g(Lr(f.name,f.arguments,h)),...y&&f.namespace!==void 0?{namespace:f.namespace}:{}});else i.push({type:"function_call",id:R,call_id:T,name:f.name,arguments:JSON.stringify(f.arguments),...y&&f.namespace!==void 0?{namespace:f.namespace}:{}})}if(i.length===0)continue;p.push(...i)}else if(n.role==="toolResult"){let[i]=n.toolCallId.split("|"),r=W(a,n.content);if(d?.grammarToolInputProperties?.has(n.toolName))p.push({type:"custom_tool_call_output",call_id:i,output:r});else p.push({type:"function_call_output",call_id:i,output:r})}if(!s)t++}return p}function Je(a,o){let l=o?.strict===void 0?!1:o.strict,d=o?.supportsStrictMode??!0,u=o?.supportsOpenAIGrammarTools??!1;return a.map((p)=>{let c=Jt(p,u);if(c)return{type:"custom",name:p.name,description:p.description,format:{type:"grammar",syntax:c.format,definition:c.definition},...o?.toolSearchResult?{defer_loading:!0}:{}};let k=ce(p,d)??l,m={type:"function",name:p.name,description:p.description,parameters:me(p,k===!0),...o?.toolSearchResult?{defer_loading:!0}:{}};if(d)m.strict=k;return m})}function z(a){let o=a.customInput?.property;if(o===void 0)return"";let l=a.arguments[o];return typeof l==="string"?l:""}function O(a,o,l){let d=a.customInput;if(!d)return;let u=Or(d.jsonBuffer,d.property,o,l);return a.arguments={[d.property]:o},u}async function lt(a,o,l,d,u){let p=!1,c=new Map,b=new Map,k=(t)=>{if(t.type==="message"&&t.phase==="final_answer")o.stopReason="stop"},m=(t,e)=>{let n=c.get(t);return n?.type===e?n:void 0},I=(t,e)=>{if(e===void 0)return;l.push({type:"toolcall_delta",contentIndex:t.contentIndex,delta:e,partial:o})},v=(t,e)=>{if(e.type==="reasoning"){let n={type:"thinking",thinking:""};o.content.push(n);let s={type:"thinking",block:n,contentIndex:o.content.length-1};return c.set(t,s),l.push({type:"thinking_start",contentIndex:s.contentIndex,partial:o}),s}if(e.type==="message"){k(e);let n={type:"text",text:""};o.content.push(n);let s={type:"text",block:n,contentIndex:o.content.length-1};return c.set(t,s),l.push({type:"text_start",contentIndex:s.contentIndex,partial:o}),s}if(e.type==="function_call"){let n={type:"toolCall",id:`${e.call_id}|${e.id}`,name:e.name,arguments:{},...e.namespace!==void 0?{namespace:e.namespace}:{},partialJson:e.arguments||""};o.content.push(n);let s={type:"toolCall",block:n,contentIndex:o.content.length-1};return c.set(t,s),l.push({type:"toolcall_start",contentIndex:s.contentIndex,partial:o}),s}if(e.type==="custom_tool_call"){let n=u?.grammarToolInputProperties?.get(e.name)??"input",s=e.input||"",i={type:"toolCall",id:`${e.call_id}|${e.id}`,name:e.name,arguments:{[n]:s},...e.namespace!==void 0?{namespace:e.namespace}:{},customInput:{property:n,jsonBuffer:{input:"",started:!1,closed:!1}}};o.content.push(i);let r={type:"toolCall",block:i,contentIndex:o.content.length-1};return c.set(t,r),l.push({type:"toolcall_start",contentIndex:r.contentIndex,partial:o}),r}return},C=(t,e)=>c.get(t)??v(t,e),w=(t)=>{for(let e of t){if(e.type!=="reasoning"||!e.encrypted_content)continue;let n=b.get(e.id);if(!n?.thinkingSignature)continue;let s=JSON.parse(n.thinkingSignature);if(s.encrypted_content)continue;n.thinkingSignature=JSON.stringify({...s,encrypted_content:e.encrypted_content})}},M=(t)=>{if(p=!0,w(t.output??[]),t?.id)o.responseId=t.id;if(t?.usage){let r=t.usage.input_tokens_details,_=r?.cached_tokens||0,y=r?.cache_write_tokens||0;o.usage={input:Math.max(0,(t.usage.input_tokens||0)-_-y),output:t.usage.output_tokens||0,cacheRead:_,cacheWrite:y,reasoning:t.usage.output_tokens_details?.reasoning_tokens||0,totalTokens:t.usage.total_tokens||0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}}}if(Q(d,o.usage),u?.applyServiceTierPricing){let r=u.resolveServiceTier?u.resolveServiceTier(t?.service_tier,u.serviceTier):t?.service_tier??u.serviceTier;u.applyServiceTierPricing(o.usage,r)}let e=t?.status,n=t?.incomplete_details,s=typeof n?.reason==="string"?n.reason:void 0;o.rawStopReason=s?`${e}.${s}`:e;let i=B(e,s);if(o.stopReason=i.stopReason,i.errorMessage===void 0)delete o.errorMessage;else o.errorMessage=i.errorMessage;if(o.content.some((r)=>r.type==="toolCall")&&o.stopReason==="stop")o.stopReason="toolUse"};for await(let t of a)if(await u?.onProviderStreamEvent?.(t,d),t.type==="response.created")o.responseId=t.response.id;else if(t.type==="response.output_item.added")v(t.output_index,t.item);else if(t.type==="response.reasoning_summary_text.delta"){let e=m(t.output_index,"thinking");if(!e)continue;e.block.thinking+=t.delta,l.push({type:"thinking_delta",contentIndex:e.contentIndex,delta:t.delta,partial:o})}else if(t.type==="response.reasoning_summary_part.done"){let e=m(t.output_index,"thinking");if(!e)continue;e.block.thinking+=`
4
4
 
5
5
  `,l.push({type:"thinking_delta",contentIndex:e.contentIndex,delta:`
6
6
 
@@ -1,3 +1,3 @@
1
1
  // @bun
2
- function xr(i){let e=i.filter((n)=>n!==void 0);if(e.length===0)return{cleanup:()=>{}};if(e.length===1)return{signal:e[0],cleanup:()=>{}};let r=new AbortController,o=[],s=(n)=>{if(!r.signal.aborted)r.abort(n.reason)};for(let n of e){if(n.aborted){s(n);break}let t=()=>s(n);n.addEventListener("abort",t,{once:!0}),o.push({signal:n,listener:t})}return{signal:r.signal,cleanup:()=>{for(let{signal:n,listener:t}of o)n.removeEventListener("abort",t)}}}
3
- export{xr};
2
+ function wr(i){let e=i.filter((n)=>n!==void 0);if(e.length===0)return{cleanup:()=>{}};if(e.length===1)return{signal:e[0],cleanup:()=>{}};let r=new AbortController,o=[],s=(n)=>{if(!r.signal.aborted)r.abort(n.reason)};for(let n of e){if(n.aborted){s(n);break}let t=()=>s(n);n.addEventListener("abort",t,{once:!0}),o.push({signal:n,listener:t})}return{signal:r.signal,cleanup:()=>{for(let{signal:n,listener:t}of o)n.removeEventListener("abort",t)}}}
3
+ export{wr};
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- import{Tn}from"./chunk-mvfsxdx6.js";import"./chunk-pxsrqrd0.js";import"./chunk-m8vkwdgr.js";import{Ir,si}from"./chunk-d2j735sd.js";import{at,Je,lt}from"./chunk-x1xss1d7.js";import{Ge}from"./chunk-bpw6q7g0.js";import{ee}from"./chunk-tvm4zmgj.js";import{ie}from"./chunk-d48bfd2e.js";import{q,j}from"./chunk-y69ewdn2.js";import{Ee,ct,V}from"./chunk-3cjsd292.js";import{z}from"./chunk-x4874m8e.js";import{re,ge,ye,H}from"./chunk-8tjad3r0.js";import{M}from"./chunk-shadcb9z.js";var g=new Set(["openai","openai-codex","opencode","azure"]),h=16;function y(r){return j(q(r),"Azure OpenAI API error")}var A=(r,a,e)=>{let t=new M,i=re(a,r.compat?.supportsMidConvoSystemMessages);return(async()=>{let n=Ir(r,e),s={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:"pending",timestamp:Date.now()};try{let p=e?.apiKey;if(!p)throw Error(`No API key for provider: ${r.provider}`);let c=R(r,p,e),o=Ee(ge(i.messages),r.compat?.supportsOpenAIGrammarTools??!1),m=T(r,i,e,n,o),u=await e?.onPayload?.(m,r);if(u!==void 0)m=u;let f={...e?.signal?{signal:e.signal}:{},...e?.timeoutMs!==void 0?{timeout:e.timeoutMs}:{},maxRetries:0},{data:d,response:l}=await ie(()=>c.responses.create(m,f).withResponse(),{maxRetries:e?.maxRetries,maxRetryDelayMs:e?.maxRetryDelayMs,signal:e?.signal});if(await e?.onResponse?.({status:l.status,headers:z(l.headers)},r),t.push({type:"start",partial:s}),await lt(d,s,t,r,{onProviderStreamEvent:e?.onProviderStreamEvent,grammarToolInputProperties:o}),e?.signal?.aborted)throw Error("Request was aborted");if(s.stopReason==="pending")throw Error("Azure OpenAI Responses stream ended without a stop reason");if(s.stopReason==="aborted"||s.stopReason==="error")throw Error(s.errorMessage||"An unknown error occurred");t.push({type:"done",reason:s.stopReason,message:s}),t.end()}catch(p){for(let c of s.content)delete c.index,delete c.partialJson,delete c.customInput;s.stopReason=e?.signal?.aborted?"aborted":"error",s.errorMessage=y(p),t.push({type:"error",reason:s.stopReason,error:s}),t.end()}})(),t},N=(r,a,e)=>{let t=e?.apiKey;if(!t)throw Error(`No API key for provider: ${r.provider}`);let i={...V(r,a,e,t),toolChoice:e?.toolChoice},n=e?.reasoning?H(r,e.reasoning):void 0;return A(r,a,{...i,reasoningEffort:n==="off"?void 0:n})};function R(r,a,e){let t={"User-Agent":ee(),...r.headers};if(e?.headers)Object.assign(t,e.headers);let{baseUrl:i,apiVersion:n}=si(r,e);return new Tn({apiKey:a,apiVersion:n,dangerouslyAllowBrowser:!0,fetch:e?.fetch,defaultHeaders:t,baseURL:i})}function T(r,a,e,t,i=Ee(ge(a.messages),r.compat?.supportsOpenAIGrammarTools??!1)){let n=r.compat?.supportsAdditionalTools??!1,s=r.compat?.supportsToolSearch??!1,p=ye(a.messages,n||s),c=at(r,a,g,{grammarToolInputProperties:i,supportsMidConvoSystemMessages:r.compat?.supportsMidConvoSystemMessages??!1,supportsAdditionalTools:n,supportsToolSearch:s,toolOptions:{supportsStrictMode:r.compat?.supportsStrictMode??!0,supportsOpenAIGrammarTools:r.compat?.supportsOpenAIGrammarTools??!1}}),o={model:t,input:c,stream:!0,prompt_cache_key:Ge(e?.sessionId),store:!1};if(e?.maxTokens)o.max_output_tokens=Math.max(e.maxTokens,h);if(e?.temperature!==void 0)o.temperature=e?.temperature;if(p.requestTools.length>0)o.tools=Je(p.requestTools,{supportsStrictMode:r.compat?.supportsStrictMode??!0,supportsOpenAIGrammarTools:r.compat?.supportsOpenAIGrammarTools??!1});if(e?.toolChoice!==void 0)o.tool_choice=e.toolChoice;let m=e?.reasoningEffort??(e?.reasoningSummary?"medium":void 0);if(r.reasoning){if(m){let f=e?.reasoningEffort?r.thinkingLevelMap?.[e.reasoningEffort]??e.reasoningEffort:m;o.reasoning={effort:f,summary:e?.reasoningSummary||"auto"},o.include=["reasoning.encrypted_content"]}else if(r.thinkingLevelMap?.off!==null)o.reasoning={effort:r.thinkingLevelMap?.off??"none"}}let u=ct(r,m??"off",e?.samplingParams);if(u)Object.assign(o,u);return o}export{A as stream,N as streamSimple};
2
+ import{Tn}from"./chunk-mvfsxdx6.js";import"./chunk-pxsrqrd0.js";import"./chunk-m8vkwdgr.js";import{Cr,si}from"./chunk-3ct2tkr8.js";import{at,Je,lt}from"./chunk-1vd0f74z.js";import{Ge}from"./chunk-bpw6q7g0.js";import{ee}from"./chunk-tvm4zmgj.js";import{ie}from"./chunk-d48bfd2e.js";import{q,j}from"./chunk-y69ewdn2.js";import{Ee,ct,V}from"./chunk-whvj83b7.js";import{z}from"./chunk-x4874m8e.js";import{re,ge,ye,H}from"./chunk-8wc8qdx8.js";import{M}from"./chunk-shadcb9z.js";var g=new Set(["openai","openai-codex","opencode","azure"]),h=16;function y(r){return j(q(r),"Azure OpenAI API error")}var A=(r,a,e)=>{let t=new M,i=re(a,r.compat?.supportsMidConvoSystemMessages);return(async()=>{let n=Cr(r,e),s={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:"pending",timestamp:Date.now()};try{let p=e?.apiKey;if(!p)throw Error(`No API key for provider: ${r.provider}`);let c=R(r,p,e),o=Ee(ge(i.messages),r.compat?.supportsOpenAIGrammarTools??!1),m=T(r,i,e,n,o),u=await e?.onPayload?.(m,r);if(u!==void 0)m=u;let f={...e?.signal?{signal:e.signal}:{},...e?.timeoutMs!==void 0?{timeout:e.timeoutMs}:{},maxRetries:0},{data:d,response:l}=await ie(()=>c.responses.create(m,f).withResponse(),{maxRetries:e?.maxRetries,maxRetryDelayMs:e?.maxRetryDelayMs,signal:e?.signal});if(await e?.onResponse?.({status:l.status,headers:z(l.headers)},r),t.push({type:"start",partial:s}),await lt(d,s,t,r,{onProviderStreamEvent:e?.onProviderStreamEvent,grammarToolInputProperties:o}),e?.signal?.aborted)throw Error("Request was aborted");if(s.stopReason==="pending")throw Error("Azure OpenAI Responses stream ended without a stop reason");if(s.stopReason==="aborted"||s.stopReason==="error")throw Error(s.errorMessage||"An unknown error occurred");t.push({type:"done",reason:s.stopReason,message:s}),t.end()}catch(p){for(let c of s.content)delete c.index,delete c.partialJson,delete c.customInput;s.stopReason=e?.signal?.aborted?"aborted":"error",s.errorMessage=y(p),t.push({type:"error",reason:s.stopReason,error:s}),t.end()}})(),t},N=(r,a,e)=>{let t=e?.apiKey;if(!t)throw Error(`No API key for provider: ${r.provider}`);let i={...V(r,a,e,t),toolChoice:e?.toolChoice},n=e?.reasoning?H(r,e.reasoning):void 0;return A(r,a,{...i,reasoningEffort:n==="off"?void 0:n})};function R(r,a,e){let t={"User-Agent":ee(),...r.headers};if(e?.headers)Object.assign(t,e.headers);let{baseUrl:i,apiVersion:n}=si(r,e);return new Tn({apiKey:a,apiVersion:n,dangerouslyAllowBrowser:!0,fetch:e?.fetch,defaultHeaders:t,baseURL:i})}function T(r,a,e,t,i=Ee(ge(a.messages),r.compat?.supportsOpenAIGrammarTools??!1)){let n=r.compat?.supportsAdditionalTools??!1,s=r.compat?.supportsToolSearch??!1,p=ye(a.messages,n||s),c=at(r,a,g,{grammarToolInputProperties:i,supportsMidConvoSystemMessages:r.compat?.supportsMidConvoSystemMessages??!1,supportsAdditionalTools:n,supportsToolSearch:s,toolOptions:{supportsStrictMode:r.compat?.supportsStrictMode??!0,supportsOpenAIGrammarTools:r.compat?.supportsOpenAIGrammarTools??!1}}),o={model:t,input:c,stream:!0,prompt_cache_key:Ge(e?.sessionId),store:!1};if(e?.maxTokens)o.max_output_tokens=Math.max(e.maxTokens,h);if(e?.temperature!==void 0)o.temperature=e?.temperature;if(p.requestTools.length>0)o.tools=Je(p.requestTools,{supportsStrictMode:r.compat?.supportsStrictMode??!0,supportsOpenAIGrammarTools:r.compat?.supportsOpenAIGrammarTools??!1});if(e?.toolChoice!==void 0)o.tool_choice=e.toolChoice;let m=e?.reasoningEffort??(e?.reasoningSummary?"medium":void 0);if(r.reasoning){if(m){let f=e?.reasoningEffort?r.thinkingLevelMap?.[e.reasoningEffort]??e.reasoningEffort:m;o.reasoning={effort:f,summary:e?.reasoningSummary||"auto"},o.include=["reasoning.encrypted_content"]}else if(r.thinkingLevelMap?.off!==null)o.reasoning={effort:r.thinkingLevelMap?.off??"none"}}let u=ct(r,m??"off",e?.samplingParams);if(u)Object.assign(o,u);return o}export{A as stream,N as streamSimple};
@@ -1,3 +1,3 @@
1
1
  // @bun
2
- import{_}from"./chunk-pxsrqrd0.js";var i="v1";function s(r){let e=new Map;if(!r)return e;for(let t of r.split(",")){let a=t.trim();if(!a)continue;let[n,o]=a.split("=",2);if(!n||!o)continue;e.set(n.trim(),o.trim())}return e}function Ir(r,e){if(e?.azureDeploymentName)return e.azureDeploymentName;return s(_("AZURE_OPENAI_DEPLOYMENT_NAME_MAP",e?.env)).get(r.id)||r.id}function m(r){let e=r.trim().replace(/\/+$/,""),t;try{t=new URL(e)}catch{throw Error(`Invalid Azure OpenAI base URL: ${r}`)}let a=t.hostname.endsWith(".openai.azure.com")||t.hostname.endsWith(".cognitiveservices.azure.com")||t.hostname.endsWith(".ai.azure.com"),n=t.pathname.replace(/\/+$/,"");if(a&&(n===""||n==="/"||n==="/openai"||n==="/openai/v1/responses"))t.pathname="/openai/v1",t.search="";return t.toString().replace(/\/+$/,"")}function u(r){return`https://${r}.openai.azure.com/openai/v1`}function vo(r,e){let t=e?.azureBaseUrl?.trim()||_("AZURE_OPENAI_BASE_URL",e?.env)?.trim()||void 0,a=e?.azureResourceName||_("AZURE_OPENAI_RESOURCE_NAME",e?.env),n=t;if(!n&&a)n=u(a);if(!n&&r.baseUrl)n=r.baseUrl;if(!n)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 m(n)}function si(r,e){return{baseUrl:vo(r,e),apiVersion:e?.azureApiVersion||_("AZURE_OPENAI_API_VERSION",e?.env)||i}}
3
- export{Ir,vo,si};
2
+ import{_}from"./chunk-pxsrqrd0.js";var i="v1";function s(r){let e=new Map;if(!r)return e;for(let t of r.split(",")){let a=t.trim();if(!a)continue;let[n,o]=a.split("=",2);if(!n||!o)continue;e.set(n.trim(),o.trim())}return e}function Cr(r,e){if(e?.azureDeploymentName)return e.azureDeploymentName;return s(_("AZURE_OPENAI_DEPLOYMENT_NAME_MAP",e?.env)).get(r.id)||r.id}function m(r){let e=r.trim().replace(/\/+$/,""),t;try{t=new URL(e)}catch{throw Error(`Invalid Azure OpenAI base URL: ${r}`)}let a=t.hostname.endsWith(".openai.azure.com")||t.hostname.endsWith(".cognitiveservices.azure.com")||t.hostname.endsWith(".ai.azure.com"),n=t.pathname.replace(/\/+$/,"");if(a&&(n===""||n==="/"||n==="/openai"||n==="/openai/v1/responses"))t.pathname="/openai/v1",t.search="";return t.toString().replace(/\/+$/,"")}function u(r){return`https://${r}.openai.azure.com/openai/v1`}function vo(r,e){let t=e?.azureBaseUrl?.trim()||_("AZURE_OPENAI_BASE_URL",e?.env)?.trim()||void 0,a=e?.azureResourceName||_("AZURE_OPENAI_RESOURCE_NAME",e?.env),n=t;if(!n&&a)n=u(a);if(!n&&r.baseUrl)n=r.baseUrl;if(!n)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 m(n)}function si(r,e){return{baseUrl:vo(r,e),apiVersion:e?.azureApiVersion||_("AZURE_OPENAI_API_VERSION",e?.env)||i}}
3
+ export{Cr,vo,si};
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{cr,Bn,Wn}from"./chunk-k506w58v.js";import{Gt}from"./chunk-0y7ne3d0.js";var vu={};Gt(vu,{unstable_now:()=>rl,unstable_IdlePriority:()=>wn,unstable_ImmediatePriority:()=>Fn,unstable_LowPriority:()=>rn,unstable_NormalPriority:()=>mu,unstable_Profiling:()=>Q0,unstable_UserBlockingPriority:()=>$n,unstable_cancelCallback:()=>In,unstable_forceFrameRate:()=>X0,unstable_getCurrentPriorityLevel:()=>kn,unstable_next:()=>Z0,unstable_requestPaint:()=>Pn,unstable_runWithPriority:()=>V0,unstable_scheduleCallback:()=>yu,unstable_shouldYield:()=>le,unstable_wrapCallback:()=>x0},{unstable_now:(R2)=>rl=R2,unstable_IdlePriority:(R2)=>wn=R2,unstable_ImmediatePriority:(R2)=>Fn=R2,unstable_LowPriority:(R2)=>rn=R2,unstable_NormalPriority:(R2)=>mu=R2,unstable_Profiling:(R2)=>Q0=R2,unstable_UserBlockingPriority:(R2)=>$n=R2,unstable_cancelCallback:(R2)=>In=R2,unstable_forceFrameRate:(R2)=>X0=R2,unstable_getCurrentPriorityLevel:(R2)=>kn=R2,unstable_next:(R2)=>Z0=R2,unstable_requestPaint:(R2)=>Pn=R2,unstable_runWithPriority:(R2)=>V0=R2,unstable_scheduleCallback:(R2)=>yu=R2,unstable_shouldYield:(R2)=>le=R2,unstable_wrapCallback:(R2)=>x0=R2});function Th(){if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!=="function")return;try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(Th)}catch(l){console.error(l)}}function Yf(l,t){var u=l.length;l.push(t);l:for(;0<u;){var a=u-1>>>1,n=l[a];if(0<jn(n,t))l[a]=t,l[u]=n,u=a;else break l}}function ut(l){return l.length===0?null:l[0]}function pn(l){if(l.length===0)return null;var t=l[0],u=l.pop();if(u!==t){l[0]=u;l:for(var a=0,n=l.length,e=n>>>1;a<e;){var f=2*(a+1)-1,c=l[f],i=f+1,y=l[i];if(0>jn(c,u))i<n&&0>jn(y,c)?(l[a]=y,l[i]=u,a=i):(l[a]=c,l[f]=u,a=f);else if(i<n&&0>jn(y,u))l[a]=y,l[i]=u,a=i;else break l}}return t}function jn(l,t){var u=l.sortIndex-t.sortIndex;return u!==0?u:l.id-t.id}var rl=void 0;if(typeof performance==="object"&&typeof performance.now==="function")Gf=performance,rl=function(){return Gf.now()};else Kn=Date,Qf=Kn.now(),rl=function(){return Kn.now()-Qf};var Gf,Kn,Qf,St=[],Yt=[],Eh=1,Zl=null,ol=3,Xf=!1,Ga=!1,Qa=!1,Vf=!1,B0=typeof setTimeout==="function"?setTimeout:null,R0=typeof clearTimeout==="function"?clearTimeout:null,C0=typeof setImmediate<"u"?setImmediate:null;function Ln(l){for(var t=ut(Yt);t!==null;){if(t.callback===null)pn(Yt);else if(t.startTime<=l)pn(Yt),t.sortIndex=t.expirationTime,Yf(St,t);else break;t=ut(Yt)}}function xf(l){if(Qa=!1,Ln(l),!Ga)if(ut(St)!==null)Ga=!0,ju||(ju=!0,xu());else{var t=ut(Yt);t!==null&&jf(xf,t.startTime-l)}}var ju=!1,Xa=-1,q0=5,Y0=-1;function G0(){return Vf?!0:vu.unstable_now()-Y0<q0?!1:!0}function qf(){if(Vf=!1,ju){var l=vu.unstable_now();Y0=l;var t=!0;try{l:{Ga=!1,Qa&&(Qa=!1,R0(Xa),Xa=-1),Xf=!0;var u=ol;try{t:{Ln(l);for(Zl=ut(St);Zl!==null&&!(Zl.expirationTime>l&&G0());){var a=Zl.callback;if(typeof a==="function"){Zl.callback=null,ol=Zl.priorityLevel;var n=a(Zl.expirationTime<=l);if(l=vu.unstable_now(),typeof n==="function"){Zl.callback=n,Ln(l),t=!0;break t}Zl===ut(St)&&pn(St),Ln(l)}else pn(St);Zl=ut(St)}if(Zl!==null)t=!0;else{var e=ut(Yt);e!==null&&jf(xf,e.startTime-l),t=!1}}break l}finally{Zl=null,ol=u,Xf=!1}t=void 0}}finally{t?xu():ju=!1}}}var xu;if(typeof C0==="function")xu=function(){C0(qf)};else if(typeof MessageChannel<"u")Jn=new MessageChannel,Zf=Jn.port2,Jn.port1.onmessage=qf,xu=function(){Zf.postMessage(null)};else xu=function(){B0(qf,0)};var Jn,Zf;function jf(l,t){Xa=B0(function(){l(vu.unstable_now())},t)}var wn=5,Fn=1,rn=4,mu=3,Q0=null,$n=2,In=function(l){l.callback=null},X0=function(l){0>l||125<l?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):q0=0<l?Math.floor(1000/l):5},kn=function(){return ol},Z0=function(l){switch(ol){case 1:case 2:case 3:var t=3;break;default:t=ol}var u=ol;ol=t;try{return l()}finally{ol=u}},Pn=function(){Vf=!0},V0=function(l,t){switch(l){case 1:case 2:case 3:case 4:case 5:break;default:l=3}var u=ol;ol=l;try{return t()}finally{ol=u}},yu=function(l,t,u){var a=vu.unstable_now();switch(typeof u==="object"&&u!==null?(u=u.delay,u=typeof u==="number"&&0<u?a+u:a):u=a,l){case 1:var n=-1;break;case 2:n=250;break;case 5:n=1073741823;break;case 4:n=1e4;break;default:n=5000}return n=u+n,l={id:Eh++,callback:t,priorityLevel:l,startTime:u,expirationTime:n,sortIndex:-1},u>a?(l.sortIndex=u,Yf(Yt,l),ut(St)===null&&l===ut(Yt)&&(Qa?(R0(Xa),Xa=-1):Qa=!0,jf(xf,u-a))):(l.sortIndex=n,Yf(St,l),Ga||Xf||(Ga=!0,ju||(ju=!0,xu()))),l},le=G0,x0=function(l){var t=ol;return function(){var u=ol;ol=t;try{return l.apply(this,arguments)}finally{ol=u}}};function T(l){var t="https://react.dev/errors/"+l;if(1<arguments.length){t+="?args[]="+encodeURIComponent(arguments[1]);for(var u=2;u<arguments.length;u++)t+="&args[]="+encodeURIComponent(arguments[u])}return"Minified React error #"+l+"; visit "+t+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}function Oh(l){return!(!l||l.nodeType!==1&&l.nodeType!==9&&l.nodeType!==11)}function Hn(l){for(var t=l,u=t;u&&!u.alternate;)t=u,(t.flags&4098)!==0&&(l=t.return),u=t.return;for(;t.return;)t=t.return;return t.tag===3?l:null}function Av(l){if(l.tag===13){var t=l.memoizedState;if(t===null&&(l=l.alternate,l!==null&&(t=l.memoizedState)),t!==null)return t.dehydrated}return null}function Dv(l){if(l.tag===31){var t=l.memoizedState;if(t===null&&(l=l.alternate,l!==null&&(t=l.memoizedState)),t!==null)return t.dehydrated}return null}function j0(l){if(Hn(l)!==l)throw Error(T(188))}function Nh(l){var t=l.alternate;if(!t){if(t=Hn(l),t===null)throw Error(T(188));return t!==l?null:l}for(var u=l,a=t;;){var n=u.return;if(n===null)break;var e=n.alternate;if(e===null){if(a=n.return,a!==null){u=a;continue}break}if(n.child===e.child){for(e=n.child;e;){if(e===u)return j0(n),l;if(e===a)return j0(n),t;e=e.sibling}throw Error(T(188))}if(u.return!==a.return)u=n,a=e;else{for(var f=!1,c=n.child;c;){if(c===u){f=!0,u=n,a=e;break}if(c===a){f=!0,a=n,u=e;break}c=c.sibling}if(!f){for(c=e.child;c;){if(c===u){f=!0,u=e,a=n;break}if(c===a){f=!0,a=e,u=n;break}c=c.sibling}if(!f)throw Error(T(189))}}if(u.alternate!==a)throw Error(T(190))}if(u.tag!==3)throw Error(T(188));return u.stateNode.current===u?l:t}function Mv(l){var t=l.tag;if(t===5||t===26||t===27||t===6)return l;for(l=l.child;l!==null;){if(t=Mv(l),t!==null)return t;l=l.sibling}return null}function Ul(l,t,u,a,n,e){for(;l!==null;){if((l.tag===5||l.tag===27||l.tag===6)&&u(l,a,n,e)||(l.tag!==22||l.memoizedState===null)&&(t||l.tag!==5&&l.tag!==27)&&Ul(l.child,t,u,a,n,e))return!0;l=l.sibling}return!1}function Gu(l){for(l=l.return;l!==null;){if(l.tag===3||l.tag===5||l.tag===27)return l;l=l.return}return null}function K0(l){var t=!1;for(l=l.return;l!==null;){if(l.tag===4&&(t=!0),l.tag===3||l.tag===5||l.tag===27)break;l=l.return}return t}function Uv(l){var t=[null,null],u=Gu(l);if(u===null)return t;return _v(t,l,u.child,{foundSelf:!1}),t}function _v(l,t,u,a){for(;u!==null;){if(u===t)a.foundSelf=!0;else if(u.tag===5||u.tag===27||u.tag===6){if(a.foundSelf)return l[1]=u,!0;l[0]=u}else if((u.tag!==22||u.memoizedState===null)&&_v(l,t,u.child,a))return!0;u=u.sibling}return!1}function al(l){switch(l.tag){case 5:case 27:case 6:return l.stateNode;case 3:return l.stateNode.containerInfo;default:throw Error(T(559))}}var Fu=null,Tc=null;function Ah(l,t,u){return l===u?!0:l===t?(Fu=l,!0):!1}function Dh(l,t,u){return l===u?(Tc=l,!1):l===t?(Tc!==null&&(Fu=l),!0):!1}function L0(l){if(l===null)return null;do l=l===null?null:l.return;while(l&&l.tag!==5&&l.tag!==27&&l.tag!==3);return l?l:null}function bc(l,t,u){for(var a=0,n=l;n;n=u(n))a++;n=0;for(var e=t;e;e=u(e))n++;for(;0<a-n;)l=u(l),a--;for(;0<n-a;)t=u(t),n--;for(;a--;){if(l===t||t!==null&&l===t.alternate)return l;l=u(l),t=u(t)}return null}var K=Object.assign,Mh=Symbol.for("react.element"),te=Symbol.for("react.transitional.element"),La=Symbol.for("react.portal"),ru=Symbol.for("react.fragment"),Hv=Symbol.for("react.strict_mode"),Ec=Symbol.for("react.profiler"),sv=Symbol.for("react.consumer"),it=Symbol.for("react.context"),Bi=Symbol.for("react.forward_ref"),Oc=Symbol.for("react.suspense"),Nc=Symbol.for("react.suspense_list"),Ri=Symbol.for("react.memo"),Vt=Symbol.for("react.lazy"),Ac=Symbol.for("react.activity"),Uh=Symbol.for("react.legacy_hidden"),_h=Symbol.for("react.memo_cache_sentinel"),Dc=Symbol.for("react.view_transition"),Hh=Symbol.for("react.recoverable"),J0=Symbol.iterator;function Za(l){if(l===null||typeof l!=="object")return null;return l=J0&&l[J0]||l["@@iterator"],typeof l==="function"?l:null}var sh=Symbol.for("react.client.reference");function Mc(l){if(l==null)return null;if(typeof l==="function")return l.$$typeof===sh?null:l.displayName||l.name||null;if(typeof l==="string")return l;switch(l){case ru:return"Fragment";case Ec:return"Profiler";case Hv:return"StrictMode";case Oc:return"Suspense";case Nc:return"SuspenseList";case Ac:return"Activity";case Dc:return"ViewTransition"}if(typeof l==="object")switch(l.$$typeof){case La:return"Portal";case it:return l.displayName||"Context";case sv:return(l._context.displayName||"Context")+".Consumer";case Bi:var t=l.render;return l=l.displayName,l||(l=t.displayName||t.name||"",l=l!==""?"ForwardRef("+l+")":"ForwardRef"),l;case Ri:return t=l.displayName||null,t!==null?t:Mc(l.type)||"Memo";case Vt:t=l._payload,l=l._init;try{return Mc(l(t))}catch(u){}}return null}var Ja=Array.isArray,D=cr,G=Wn,Eu={pending:!1,data:null,method:null,action:null},Uc=[],$u=-1;function ot(l){return{current:l}}function yl(l){0>$u||(l.current=Uc[$u],Uc[$u]=null,$u--)}function p(l,t){$u++,Uc[$u]=l.current,l.current=t}var ht=ot(null),hn=ot(null),Ft=ot(null),Ze=ot(null);function Ve(l,t){switch(p(Ft,t),p(hn,l),p(ht,null),t.nodeType){case 9:case 11:l=(l=t.documentElement)?(l=l.namespaceURI)?uv(l):0:0;break;default:if(l=t.tagName,t=t.namespaceURI)t=uv(t),l=$y(t,l);else switch(l){case"svg":l=1;break;case"math":l=2;break;default:l=0}}yl(ht),p(ht,l)}function Sa(){yl(ht),yl(hn),yl(Ft)}function _c(l){var t=l.memoizedState;t!==null&&(Ua._currentValue=t.memoizedState,p(Ze,l)),t=ht.current;var u=$y(t,l.type);t!==u&&(p(hn,l),p(ht,u))}function xe(l){hn.current===l&&(yl(ht),yl(hn)),Ze.current===l&&(yl(Ze),Ua._currentValue=Eu)}var Kf,p0;function Xt(l){if(Kf===void 0)try{throw Error()}catch(u){var t=u.stack.trim().match(/\n( *(at )?)/);Kf=t&&t[1]||"",p0=-1<u.stack.indexOf(`
2
+ import{ur,Bn,Wn}from"./chunk-aky4tztg.js";import{Gt}from"./chunk-0y7ne3d0.js";var vu={};Gt(vu,{unstable_now:()=>rl,unstable_IdlePriority:()=>wn,unstable_ImmediatePriority:()=>Fn,unstable_LowPriority:()=>rn,unstable_NormalPriority:()=>mu,unstable_Profiling:()=>Q0,unstable_UserBlockingPriority:()=>$n,unstable_cancelCallback:()=>In,unstable_forceFrameRate:()=>X0,unstable_getCurrentPriorityLevel:()=>kn,unstable_next:()=>Z0,unstable_requestPaint:()=>Pn,unstable_runWithPriority:()=>V0,unstable_scheduleCallback:()=>yu,unstable_shouldYield:()=>le,unstable_wrapCallback:()=>x0},{unstable_now:(R2)=>rl=R2,unstable_IdlePriority:(R2)=>wn=R2,unstable_ImmediatePriority:(R2)=>Fn=R2,unstable_LowPriority:(R2)=>rn=R2,unstable_NormalPriority:(R2)=>mu=R2,unstable_Profiling:(R2)=>Q0=R2,unstable_UserBlockingPriority:(R2)=>$n=R2,unstable_cancelCallback:(R2)=>In=R2,unstable_forceFrameRate:(R2)=>X0=R2,unstable_getCurrentPriorityLevel:(R2)=>kn=R2,unstable_next:(R2)=>Z0=R2,unstable_requestPaint:(R2)=>Pn=R2,unstable_runWithPriority:(R2)=>V0=R2,unstable_scheduleCallback:(R2)=>yu=R2,unstable_shouldYield:(R2)=>le=R2,unstable_wrapCallback:(R2)=>x0=R2});function Th(){if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!=="function")return;try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(Th)}catch(l){console.error(l)}}function Yf(l,t){var u=l.length;l.push(t);l:for(;0<u;){var a=u-1>>>1,n=l[a];if(0<jn(n,t))l[a]=t,l[u]=n,u=a;else break l}}function ut(l){return l.length===0?null:l[0]}function pn(l){if(l.length===0)return null;var t=l[0],u=l.pop();if(u!==t){l[0]=u;l:for(var a=0,n=l.length,e=n>>>1;a<e;){var f=2*(a+1)-1,c=l[f],i=f+1,y=l[i];if(0>jn(c,u))i<n&&0>jn(y,c)?(l[a]=y,l[i]=u,a=i):(l[a]=c,l[f]=u,a=f);else if(i<n&&0>jn(y,u))l[a]=y,l[i]=u,a=i;else break l}}return t}function jn(l,t){var u=l.sortIndex-t.sortIndex;return u!==0?u:l.id-t.id}var rl=void 0;if(typeof performance==="object"&&typeof performance.now==="function")Gf=performance,rl=function(){return Gf.now()};else Kn=Date,Qf=Kn.now(),rl=function(){return Kn.now()-Qf};var Gf,Kn,Qf,St=[],Yt=[],Eh=1,Zl=null,ol=3,Xf=!1,Ga=!1,Qa=!1,Vf=!1,B0=typeof setTimeout==="function"?setTimeout:null,R0=typeof clearTimeout==="function"?clearTimeout:null,C0=typeof setImmediate<"u"?setImmediate:null;function Ln(l){for(var t=ut(Yt);t!==null;){if(t.callback===null)pn(Yt);else if(t.startTime<=l)pn(Yt),t.sortIndex=t.expirationTime,Yf(St,t);else break;t=ut(Yt)}}function xf(l){if(Qa=!1,Ln(l),!Ga)if(ut(St)!==null)Ga=!0,ju||(ju=!0,xu());else{var t=ut(Yt);t!==null&&jf(xf,t.startTime-l)}}var ju=!1,Xa=-1,q0=5,Y0=-1;function G0(){return Vf?!0:vu.unstable_now()-Y0<q0?!1:!0}function qf(){if(Vf=!1,ju){var l=vu.unstable_now();Y0=l;var t=!0;try{l:{Ga=!1,Qa&&(Qa=!1,R0(Xa),Xa=-1),Xf=!0;var u=ol;try{t:{Ln(l);for(Zl=ut(St);Zl!==null&&!(Zl.expirationTime>l&&G0());){var a=Zl.callback;if(typeof a==="function"){Zl.callback=null,ol=Zl.priorityLevel;var n=a(Zl.expirationTime<=l);if(l=vu.unstable_now(),typeof n==="function"){Zl.callback=n,Ln(l),t=!0;break t}Zl===ut(St)&&pn(St),Ln(l)}else pn(St);Zl=ut(St)}if(Zl!==null)t=!0;else{var e=ut(Yt);e!==null&&jf(xf,e.startTime-l),t=!1}}break l}finally{Zl=null,ol=u,Xf=!1}t=void 0}}finally{t?xu():ju=!1}}}var xu;if(typeof C0==="function")xu=function(){C0(qf)};else if(typeof MessageChannel<"u")Jn=new MessageChannel,Zf=Jn.port2,Jn.port1.onmessage=qf,xu=function(){Zf.postMessage(null)};else xu=function(){B0(qf,0)};var Jn,Zf;function jf(l,t){Xa=B0(function(){l(vu.unstable_now())},t)}var wn=5,Fn=1,rn=4,mu=3,Q0=null,$n=2,In=function(l){l.callback=null},X0=function(l){0>l||125<l?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):q0=0<l?Math.floor(1000/l):5},kn=function(){return ol},Z0=function(l){switch(ol){case 1:case 2:case 3:var t=3;break;default:t=ol}var u=ol;ol=t;try{return l()}finally{ol=u}},Pn=function(){Vf=!0},V0=function(l,t){switch(l){case 1:case 2:case 3:case 4:case 5:break;default:l=3}var u=ol;ol=l;try{return t()}finally{ol=u}},yu=function(l,t,u){var a=vu.unstable_now();switch(typeof u==="object"&&u!==null?(u=u.delay,u=typeof u==="number"&&0<u?a+u:a):u=a,l){case 1:var n=-1;break;case 2:n=250;break;case 5:n=1073741823;break;case 4:n=1e4;break;default:n=5000}return n=u+n,l={id:Eh++,callback:t,priorityLevel:l,startTime:u,expirationTime:n,sortIndex:-1},u>a?(l.sortIndex=u,Yf(Yt,l),ut(St)===null&&l===ut(Yt)&&(Qa?(R0(Xa),Xa=-1):Qa=!0,jf(xf,u-a))):(l.sortIndex=n,Yf(St,l),Ga||Xf||(Ga=!0,ju||(ju=!0,xu()))),l},le=G0,x0=function(l){var t=ol;return function(){var u=ol;ol=t;try{return l.apply(this,arguments)}finally{ol=u}}};function T(l){var t="https://react.dev/errors/"+l;if(1<arguments.length){t+="?args[]="+encodeURIComponent(arguments[1]);for(var u=2;u<arguments.length;u++)t+="&args[]="+encodeURIComponent(arguments[u])}return"Minified React error #"+l+"; visit "+t+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}function Oh(l){return!(!l||l.nodeType!==1&&l.nodeType!==9&&l.nodeType!==11)}function Hn(l){for(var t=l,u=t;u&&!u.alternate;)t=u,(t.flags&4098)!==0&&(l=t.return),u=t.return;for(;t.return;)t=t.return;return t.tag===3?l:null}function Av(l){if(l.tag===13){var t=l.memoizedState;if(t===null&&(l=l.alternate,l!==null&&(t=l.memoizedState)),t!==null)return t.dehydrated}return null}function Dv(l){if(l.tag===31){var t=l.memoizedState;if(t===null&&(l=l.alternate,l!==null&&(t=l.memoizedState)),t!==null)return t.dehydrated}return null}function j0(l){if(Hn(l)!==l)throw Error(T(188))}function Nh(l){var t=l.alternate;if(!t){if(t=Hn(l),t===null)throw Error(T(188));return t!==l?null:l}for(var u=l,a=t;;){var n=u.return;if(n===null)break;var e=n.alternate;if(e===null){if(a=n.return,a!==null){u=a;continue}break}if(n.child===e.child){for(e=n.child;e;){if(e===u)return j0(n),l;if(e===a)return j0(n),t;e=e.sibling}throw Error(T(188))}if(u.return!==a.return)u=n,a=e;else{for(var f=!1,c=n.child;c;){if(c===u){f=!0,u=n,a=e;break}if(c===a){f=!0,a=n,u=e;break}c=c.sibling}if(!f){for(c=e.child;c;){if(c===u){f=!0,u=e,a=n;break}if(c===a){f=!0,a=e,u=n;break}c=c.sibling}if(!f)throw Error(T(189))}}if(u.alternate!==a)throw Error(T(190))}if(u.tag!==3)throw Error(T(188));return u.stateNode.current===u?l:t}function Mv(l){var t=l.tag;if(t===5||t===26||t===27||t===6)return l;for(l=l.child;l!==null;){if(t=Mv(l),t!==null)return t;l=l.sibling}return null}function Ul(l,t,u,a,n,e){for(;l!==null;){if((l.tag===5||l.tag===27||l.tag===6)&&u(l,a,n,e)||(l.tag!==22||l.memoizedState===null)&&(t||l.tag!==5&&l.tag!==27)&&Ul(l.child,t,u,a,n,e))return!0;l=l.sibling}return!1}function Gu(l){for(l=l.return;l!==null;){if(l.tag===3||l.tag===5||l.tag===27)return l;l=l.return}return null}function K0(l){var t=!1;for(l=l.return;l!==null;){if(l.tag===4&&(t=!0),l.tag===3||l.tag===5||l.tag===27)break;l=l.return}return t}function Uv(l){var t=[null,null],u=Gu(l);if(u===null)return t;return _v(t,l,u.child,{foundSelf:!1}),t}function _v(l,t,u,a){for(;u!==null;){if(u===t)a.foundSelf=!0;else if(u.tag===5||u.tag===27||u.tag===6){if(a.foundSelf)return l[1]=u,!0;l[0]=u}else if((u.tag!==22||u.memoizedState===null)&&_v(l,t,u.child,a))return!0;u=u.sibling}return!1}function al(l){switch(l.tag){case 5:case 27:case 6:return l.stateNode;case 3:return l.stateNode.containerInfo;default:throw Error(T(559))}}var Fu=null,Tc=null;function Ah(l,t,u){return l===u?!0:l===t?(Fu=l,!0):!1}function Dh(l,t,u){return l===u?(Tc=l,!1):l===t?(Tc!==null&&(Fu=l),!0):!1}function L0(l){if(l===null)return null;do l=l===null?null:l.return;while(l&&l.tag!==5&&l.tag!==27&&l.tag!==3);return l?l:null}function bc(l,t,u){for(var a=0,n=l;n;n=u(n))a++;n=0;for(var e=t;e;e=u(e))n++;for(;0<a-n;)l=u(l),a--;for(;0<n-a;)t=u(t),n--;for(;a--;){if(l===t||t!==null&&l===t.alternate)return l;l=u(l),t=u(t)}return null}var K=Object.assign,Mh=Symbol.for("react.element"),te=Symbol.for("react.transitional.element"),La=Symbol.for("react.portal"),ru=Symbol.for("react.fragment"),Hv=Symbol.for("react.strict_mode"),Ec=Symbol.for("react.profiler"),sv=Symbol.for("react.consumer"),it=Symbol.for("react.context"),Bi=Symbol.for("react.forward_ref"),Oc=Symbol.for("react.suspense"),Nc=Symbol.for("react.suspense_list"),Ri=Symbol.for("react.memo"),Vt=Symbol.for("react.lazy"),Ac=Symbol.for("react.activity"),Uh=Symbol.for("react.legacy_hidden"),_h=Symbol.for("react.memo_cache_sentinel"),Dc=Symbol.for("react.view_transition"),Hh=Symbol.for("react.recoverable"),J0=Symbol.iterator;function Za(l){if(l===null||typeof l!=="object")return null;return l=J0&&l[J0]||l["@@iterator"],typeof l==="function"?l:null}var sh=Symbol.for("react.client.reference");function Mc(l){if(l==null)return null;if(typeof l==="function")return l.$$typeof===sh?null:l.displayName||l.name||null;if(typeof l==="string")return l;switch(l){case ru:return"Fragment";case Ec:return"Profiler";case Hv:return"StrictMode";case Oc:return"Suspense";case Nc:return"SuspenseList";case Ac:return"Activity";case Dc:return"ViewTransition"}if(typeof l==="object")switch(l.$$typeof){case La:return"Portal";case it:return l.displayName||"Context";case sv:return(l._context.displayName||"Context")+".Consumer";case Bi:var t=l.render;return l=l.displayName,l||(l=t.displayName||t.name||"",l=l!==""?"ForwardRef("+l+")":"ForwardRef"),l;case Ri:return t=l.displayName||null,t!==null?t:Mc(l.type)||"Memo";case Vt:t=l._payload,l=l._init;try{return Mc(l(t))}catch(u){}}return null}var Ja=Array.isArray,D=ur,G=Wn,Eu={pending:!1,data:null,method:null,action:null},Uc=[],$u=-1;function ot(l){return{current:l}}function yl(l){0>$u||(l.current=Uc[$u],Uc[$u]=null,$u--)}function p(l,t){$u++,Uc[$u]=l.current,l.current=t}var ht=ot(null),hn=ot(null),Ft=ot(null),Ze=ot(null);function Ve(l,t){switch(p(Ft,t),p(hn,l),p(ht,null),t.nodeType){case 9:case 11:l=(l=t.documentElement)?(l=l.namespaceURI)?uv(l):0:0;break;default:if(l=t.tagName,t=t.namespaceURI)t=uv(t),l=$y(t,l);else switch(l){case"svg":l=1;break;case"math":l=2;break;default:l=0}}yl(ht),p(ht,l)}function Sa(){yl(ht),yl(hn),yl(Ft)}function _c(l){var t=l.memoizedState;t!==null&&(Ua._currentValue=t.memoizedState,p(Ze,l)),t=ht.current;var u=$y(t,l.type);t!==u&&(p(hn,l),p(ht,u))}function xe(l){hn.current===l&&(yl(ht),yl(hn)),Ze.current===l&&(yl(Ze),Ua._currentValue=Eu)}var Kf,p0;function Xt(l){if(Kf===void 0)try{throw Error()}catch(u){var t=u.stack.trim().match(/\n( *(at )?)/);Kf=t&&t[1]||"",p0=-1<u.stack.indexOf(`
3
3
  at`)?" (<anonymous>)":-1<u.stack.indexOf("@")?"@unknown:0:0":""}return`
4
4
  `+Kf+l+p0}var Lf=!1;function Jf(l,t){if(!l||Lf)return"";Lf=!0;var u=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{var a={DetermineComponentFrameRoot:function(){try{if(t){var z=function(){throw Error()};if(Object.defineProperty(z.prototype,"props",{set:function(){throw Error()}}),typeof Reflect==="object"&&Reflect.construct){try{Reflect.construct(z,[])}catch(b){var m=b}Reflect.construct(l,[],z)}else{try{z.call()}catch(b){m=b}z=!1;try{var g=Object.getOwnPropertyDescriptor(l.prototype,"props");Object.defineProperty(l.prototype,"props",{configurable:!0,set:function(){throw Error()}}),z=!0,new l}finally{z&&(g!==void 0?Object.defineProperty(l.prototype,"props",g):delete l.prototype.props)}}}else{try{throw Error()}catch(b){m=b}(z=l())&&typeof z.catch==="function"&&z.catch(function(){})}}catch(b){if(b&&m&&typeof b.stack==="string")return[b.stack,m.stack]}return[null,null]}};a.DetermineComponentFrameRoot.displayName="DetermineComponentFrameRoot";var n=Object.getOwnPropertyDescriptor(a.DetermineComponentFrameRoot,"name");n&&n.configurable&&Object.defineProperty(a.DetermineComponentFrameRoot,"name",{value:"DetermineComponentFrameRoot"});var e=a.DetermineComponentFrameRoot(),f=e[0],c=e[1];if(f&&c){var i=f.split(`
5
5
  `),y=c.split(`
@@ -1,9 +1,9 @@
1
1
  // @bun
2
- import{mo,St,st,x,an,ho}from"./chunk-ry0z4ev6.js";import{n,e,c,Nt,vt,T,le,E,wo,Rr,Ut}from"./chunk-10xzzn07.js";import*as S from"fs/promises";import*as ne from"fs";import*as M from"path";import*as $e from"child_process";import*as ct from"crypto";import*as lt from"readline";function C(a){if(a.inputSchema.type!=="object")throw Error(`JSON schema for tool "${a.name}" must be an object, but got ${a.inputSchema.type}`);return{type:"custom",name:a.name,input_schema:a.inputSchema,description:a.description,run:a.run,parse:(r)=>r,...a.close?{close:a.close}:{}}}var F=st.promises,J=448,yt=384;function ae(a,r){let t=x.relative(a,r);return t===""||!t.startsWith(".."+x.sep)&&t!==".."&&!x.isAbsolute(t)}async function Ee(a,r){for(let t of a)if(ae(await X(x.resolve(t)),r))return t;return}var wt=40;function Z(a){let r=a?.code;return typeof r==="string"?r:void 0}async function X(a){let r=[],t=a,i=0;for(;;){let o;try{o=await F.realpath(t)}catch(s){let l;try{l=(await F.lstat(t)).isSymbolicLink()}catch(f){let d=Z(f);if(d!=="ENOENT"&&d!=="ENOTDIR")throw f;let m=x.dirname(t);if(m===t)throw f;r.push(x.basename(t)),t=m;continue}if(!l)throw s;if(++i>wt)throw Object.assign(Error("too many levels of symbolic links"),{code:"ELOOP"});t=x.resolve(x.dirname(t),await F.readlink(t));continue}return r.length?x.join(o,...r.reverse()):o}}async function Ae(a,r,t){let i=t?.allowedRoots??[],o=await X(x.resolve(a)),s;try{s=await X(x.resolve(o,r))}catch(f){throw new E(q(f,`path ${JSON.stringify(r)}`))}if(ae(o,s)||await Ee(i,s)!==void 0)return s;let l=i.length?"the session's working directory and its other permitted directories":"the session's working directory";throw new E(`path ${JSON.stringify(r)} is outside ${l}`)}async function be(a,r){let t=x.dirname(a),i=x.join(t,`.tmp-${process.pid}-${St.randomUUID()}`),o=await F.stat(a).then((l)=>l.mode&511,()=>{return}),s;try{if(s=await F.open(i,"wx",yt),o!==void 0)await s.chmod(o);await s.writeFile(r,"utf-8"),await s.sync(),await s.close(),s=void 0,await F.rename(i,a)}catch(l){if(s)await s.close().catch(()=>{});throw await F.unlink(i).catch(()=>{}),l}}function q(a,r){let t=Z(a);switch(t){case"ENOENT":return`${r}: no such file or directory`;case"EACCES":case"EPERM":return`${r}: permission denied`;case"ENOTDIR":return`${r}: not a directory`;case"EISDIR":return`${r}: is a directory`;case"ELOOP":return`${r}: too many levels of symbolic links`;case"ENAMETOOLONG":return`${r}: file name too long`;case"ENOSPC":return`${r}: no space left on device`;case"EMFILE":case"ENFILE":return`${r}: too many open files`;default:return`${r}: ${t!==void 0?`i/o error (${t})`:"i/o error"}`}}var I=st.promises,_t=ho.promisify(mo.execFile);async function gt(a){let{client:r,sessionId:t}=a;if(!r)return async()=>{};let i=T(r),o=a.session;if(!o){if(t===void 0)return async()=>{};i.warn("AgentToolContext.sessionId is deprecated and costs an extra session fetch; fetch the session once and set `session` instead",{component:"agent-tool-context"}),o=await r.beta.sessions.retrieve(t)}let s=x.resolve(a.workdir,"skills"),l=[];for(let f of o.agent.skills)try{let d=await r.beta.skills.versions.retrieve(f.version,{skill_id:f.skill_id}),m=x.basename(d.name.trim());if(m===""||m==="."||m==="..")m=f.skill_id;let h=x.resolve(s,m);if(h!==s&&!h.startsWith(s+x.sep)){i.warn("skill name escapes the skills dir; skipping",{component:"agent-tool-context",name:d.name});continue}let u=await r.beta.skills.versions.download(d.id,{skill_id:f.skill_id});await I.rm(h,{recursive:!0,force:!0}),await I.mkdir(h,{recursive:!0,mode:J}),l.push(h),await Ce(u,h),i.info("downloaded skill",{component:"agent-tool-context",skill_id:f.skill_id,version:d.id,dest:h})}catch(d){i.warn("failed to download skill",{component:"agent-tool-context",skill_id:f.skill_id,error:String(d)})}return async()=>{for(let f of l)await I.rm(f,{recursive:!0,force:!0}).catch((d)=>{i.warn("failed to clean up skill",{component:"agent-tool-context",dest:f,error:String(d)})})}}function Et(a){for(let r of a){let t=r.trim();if(!t)continue;if(x.isAbsolute(t)||t.split(/[\\/]/).includes(".."))throw new c(`refusing to extract unsafe archive member: ${t}`)}}var Me="skill archive listing is inconsistent; refusing to extract",bt={unzip:new Set(["-","d","?"]),tar:new Set(["-","d","C"])};function xe(a){let r=a.split(`
2
+ import{mo,St,st,x,an,ho}from"./chunk-ry0z4ev6.js";import{n,e,c,Nt,vt,T,le,E,wo,Ir,Ut}from"./chunk-zggzfa7j.js";import*as S from"fs/promises";import*as ne from"fs";import*as M from"path";import*as $e from"child_process";import*as ct from"crypto";import*as lt from"readline";function C(a){if(a.inputSchema.type!=="object")throw Error(`JSON schema for tool "${a.name}" must be an object, but got ${a.inputSchema.type}`);return{type:"custom",name:a.name,input_schema:a.inputSchema,description:a.description,run:a.run,parse:(r)=>r,...a.close?{close:a.close}:{}}}var F=st.promises,J=448,yt=384;function ae(a,r){let t=x.relative(a,r);return t===""||!t.startsWith(".."+x.sep)&&t!==".."&&!x.isAbsolute(t)}async function Ee(a,r){for(let t of a)if(ae(await X(x.resolve(t)),r))return t;return}var wt=40;function Z(a){let r=a?.code;return typeof r==="string"?r:void 0}async function X(a){let r=[],t=a,i=0;for(;;){let o;try{o=await F.realpath(t)}catch(s){let l;try{l=(await F.lstat(t)).isSymbolicLink()}catch(f){let d=Z(f);if(d!=="ENOENT"&&d!=="ENOTDIR")throw f;let m=x.dirname(t);if(m===t)throw f;r.push(x.basename(t)),t=m;continue}if(!l)throw s;if(++i>wt)throw Object.assign(Error("too many levels of symbolic links"),{code:"ELOOP"});t=x.resolve(x.dirname(t),await F.readlink(t));continue}return r.length?x.join(o,...r.reverse()):o}}async function Ae(a,r,t){let i=t?.allowedRoots??[],o=await X(x.resolve(a)),s;try{s=await X(x.resolve(o,r))}catch(f){throw new E(q(f,`path ${JSON.stringify(r)}`))}if(ae(o,s)||await Ee(i,s)!==void 0)return s;let l=i.length?"the session's working directory and its other permitted directories":"the session's working directory";throw new E(`path ${JSON.stringify(r)} is outside ${l}`)}async function be(a,r){let t=x.dirname(a),i=x.join(t,`.tmp-${process.pid}-${St.randomUUID()}`),o=await F.stat(a).then((l)=>l.mode&511,()=>{return}),s;try{if(s=await F.open(i,"wx",yt),o!==void 0)await s.chmod(o);await s.writeFile(r,"utf-8"),await s.sync(),await s.close(),s=void 0,await F.rename(i,a)}catch(l){if(s)await s.close().catch(()=>{});throw await F.unlink(i).catch(()=>{}),l}}function q(a,r){let t=Z(a);switch(t){case"ENOENT":return`${r}: no such file or directory`;case"EACCES":case"EPERM":return`${r}: permission denied`;case"ENOTDIR":return`${r}: not a directory`;case"EISDIR":return`${r}: is a directory`;case"ELOOP":return`${r}: too many levels of symbolic links`;case"ENAMETOOLONG":return`${r}: file name too long`;case"ENOSPC":return`${r}: no space left on device`;case"EMFILE":case"ENFILE":return`${r}: too many open files`;default:return`${r}: ${t!==void 0?`i/o error (${t})`:"i/o error"}`}}var I=st.promises,_t=ho.promisify(mo.execFile);async function gt(a){let{client:r,sessionId:t}=a;if(!r)return async()=>{};let i=T(r),o=a.session;if(!o){if(t===void 0)return async()=>{};i.warn("AgentToolContext.sessionId is deprecated and costs an extra session fetch; fetch the session once and set `session` instead",{component:"agent-tool-context"}),o=await r.beta.sessions.retrieve(t)}let s=x.resolve(a.workdir,"skills"),l=[];for(let f of o.agent.skills)try{let d=await r.beta.skills.versions.retrieve(f.version,{skill_id:f.skill_id}),m=x.basename(d.name.trim());if(m===""||m==="."||m==="..")m=f.skill_id;let h=x.resolve(s,m);if(h!==s&&!h.startsWith(s+x.sep)){i.warn("skill name escapes the skills dir; skipping",{component:"agent-tool-context",name:d.name});continue}let u=await r.beta.skills.versions.download(d.id,{skill_id:f.skill_id});await I.rm(h,{recursive:!0,force:!0}),await I.mkdir(h,{recursive:!0,mode:J}),l.push(h),await Ce(u,h),i.info("downloaded skill",{component:"agent-tool-context",skill_id:f.skill_id,version:d.id,dest:h})}catch(d){i.warn("failed to download skill",{component:"agent-tool-context",skill_id:f.skill_id,error:String(d)})}return async()=>{for(let f of l)await I.rm(f,{recursive:!0,force:!0}).catch((d)=>{i.warn("failed to clean up skill",{component:"agent-tool-context",dest:f,error:String(d)})})}}function Et(a){for(let r of a){let t=r.trim();if(!t)continue;if(x.isAbsolute(t)||t.split(/[\\/]/).includes(".."))throw new c(`refusing to extract unsafe archive member: ${t}`)}}var Me="skill archive listing is inconsistent; refusing to extract",bt={unzip:new Set(["-","d","?"]),tar:new Set(["-","d","C"])};function xe(a){let r=a.split(`
3
3
  `);if(r[r.length-1]==="")r.pop();return r}function Ot(a,r){return/^[\x20-\x7E]+$/.test(r)&&!/[\\^#]/.test(r)&&!(a==="unzip"&&r.startsWith("-"))}function Mt(a,r,t){let i=xe(r),o=xe(t);if(i.length!==o.length)throw new c(Me);let s=[],l=[];return i.forEach((f,d)=>{if(bt[a].has(o[d].charAt(0))){s.push(f);return}if(!Ot(a,f))throw new c(`refusing to extract archive: cannot safely exclude member ${JSON.stringify(f)}`);l.push(f)}),{plain:s,special:l}}async function De(a){for(let r of await I.readdir(a,{withFileTypes:!0}))if(r.isDirectory())await De(x.join(a,r.name));else if(!r.isFile())throw new c(Me)}async function Oe(a,r){try{let{stdout:t}=await _t(a,r);return t}catch(t){if(Z(t)==="ENOENT")throw new c(`skill extraction requires the \`${a}\` command, but it was not found on PATH`);throw t}}function kt(a){let r,t=!1;for(let i of a){let o=i.trim().split("/").filter((l)=>l!==""&&l!==".");if(o.length===0)continue;let s=o[0];if(r===void 0)r=s;else if(s!==r)return"";if(o.length>1)t=!0}return r!==void 0&&t?r:""}async function Ce(a,r){let t=x.join(r,`.skill-archive-${process.pid}-${Date.now()}`);if(!a.body)throw new c("skill download response had no body");await an.promises.pipeline(an.Readable.fromWeb(a.body),st.createWriteStream(t));let i=x.join(x.dirname(r),`.skill-stage-${process.pid}-${Date.now()}`),o=x.join(x.dirname(r),`.skill-exclude-${process.pid}-${Date.now()}`);try{let s=await Rt(t,4),l=s.length>=4&&s[0]===80&&s[1]===75&&s[2]===3&&s[3]===4,f=l?"unzip":"tar",d=await Oe(f,l?["-Z1",t]:["-tf",t]),m=await Oe(f,l?["-Z","--h","--t",t]:["-tvf",t]),{plain:h,special:u}=Mt(f,d,m);Et([...h,...u]);let _=kt(h);if(await I.mkdir(i,{recursive:!0,mode:J}),h.length>0)await Oe(f,await It(f,t,i,u,o));await De(i);let b=_?x.join(i,_):i,D=await I.readdir(b).catch((v)=>{throw Z(v)==="ENOENT"?new c(Me):v});for(let v of D)await I.rename(x.join(b,v),x.join(r,v))}finally{await I.rm(t,{force:!0}),await I.rm(o,{force:!0}),await I.rm(i,{recursive:!0,force:!0})}}async function It(a,r,t,i,o){let s=i.map((l)=>l.replace(/[*?[\\]/g,"\\$&"));if(a==="unzip")return["-oq",r,"-d",t,...s.length>0?["-x",...s]:[]];if(s.length===0)return["-xf",r,"-C",t];return await I.writeFile(o,s.join(`
4
4
  `)+`
5
5
  `,{flag:"wx",mode:384}),["-xf",r,"-C",t,"-X",o]}async function Rt(a,r){let t=await I.open(a,"r");try{let i=Buffer.alloc(r),{bytesRead:o}=await t.read(i,0,r,0);return i.subarray(0,o)}finally{await t.close()}}var g=st.promises,z=st.constants,Ue=448,Tt=384,Lt=448,ke=z.O_NOFOLLOW??0,$t=z.O_NONBLOCK??0,y=(()=>{class a extends Error{constructor(r,t){super(`path ${JSON.stringify(t)} ${r}`);this.name="FileStoreError",this.reason=r,this.relPath=t}}return a.ESCAPES_ROOT="escapes the store root",a.IS_A_SYMLINK="is a symlink",a.NOT_A_FILE="is not a regular file",a.NOT_A_DIRECTORY="is not a directory",a.NOT_UTF8="is not valid utf-8",a.MOVE_DESTINATION_EXISTS="already exists",a})();function Ie(a){return a.startsWith("/")&&!a.split("/").includes("..")}var ve=(()=>{class a{constructor(r,t,i=!1){this.hashes=new Map,this.rootPath=r,this.removedOnDispose=t,this.decoder=i?new TextDecoder("utf-8",{fatal:!0}):void 0}static async open(r,t){if(!At())throw Error("FileStore requires O_NOFOLLOW support on this platform");let i=!1;try{await g.lstat(r)}catch(o){if(o.code!=="ENOENT")throw o;i=!0}return new a(x.resolve(r),i,t?.utf8??!1)}async createRoot(){await xt(this.rootPath)}root(){return{path:this.rootPath,removedOnDispose:this.removedOnDispose}}async dispose(){if(!this.removedOnDispose)return;await g.rm(this.rootPath,{recursive:!0,force:!0})}async put(r,t,i){let o=r.replace(/\\/g,"/");if(o.endsWith("/")||o.endsWith("/.")||o===""||o===".")throw new y(y.NOT_A_FILE,r);let s=this.resolveUnderRoot(r),l=typeof t==="string"?Nt(t):t;this.requireUtf8(r,l),await Fe(this.rootPath,x.dirname(s)),await Dt(s,l,i?.executable??!1)}async get(r){let t=this.resolveUnderRoot(r),i;try{i=await je(r,t)}catch(s){if(s.code==="ENOENT")return null;throw s}let o;try{let s=await i.readFile();o=new Uint8Array(s.buffer,s.byteOffset,s.byteLength)}finally{await i.close()}return this.requireUtf8(r,o),o}async ls(r="/"){let t=this.resolveUnderRoot(r);return new Set((await Pe(this.rootPath,r,t)).map(([i])=>i))}async findSymlinks(r="/"){let t=this.resolveUnderRoot(r);return Ft(this.rootPath,r,t)}async hashtree(r="/"){let t=this.resolveUnderRoot(r),i=ce.nowNs(),o=Object.create(null);for(let[s,l]of await Pe(this.rootPath,r,t)){let f=await this.hashViaCache(s,l,i);if(f!==null)o[s]=f}return o}async hashFile(r){let t=this.resolveUnderRoot(r),i;try{i=await g.lstat(t,{bigint:!0})}catch(s){if(s.code==="ENOENT")return null;throw s}if(i.isSymbolicLink())throw new y(y.IS_A_SYMLINK,r);if(!i.isFile())throw new y(y.NOT_A_FILE,r);let o=x.relative(this.rootPath,t).split(x.sep).join("/");return this.hashViaCache(o,t,ce.nowNs())}async move(r,t){let i=this.resolveUnderRoot(r),o=this.resolveUnderRoot(t);if(i===this.rootPath||o===this.rootPath)return;if(await g.stat(o).then(()=>!0,()=>!1))throw new y(y.MOVE_DESTINATION_EXISTS,t);await Fe(this.rootPath,x.dirname(o)),await g.rename(i,o)}async remove(r){let t=this.resolveUnderRoot(r);if(t===this.rootPath)return;let i;try{i=await g.lstat(t,{bigint:!0})}catch(o){if(o.code==="ENOENT")return;throw o}if(i.isDirectory())await g.rm(t,{recursive:!0,force:!0});else try{await g.unlink(t)}catch(o){if(o.code!=="ENOENT")throw o}}resolveUnderRoot(r){let t=r.replace(/\\/g,"/").replace(/^\/+/,""),i=t.split("/").filter((o)=>o!==""&&o!==".");if(x.posix.isAbsolute(t)||i.includes(".."))throw new y(y.ESCAPES_ROOT,r);return i.length===0?this.rootPath:x.join(this.rootPath,...i)}requireUtf8(r,t){if(!this.decoder)return;try{this.decoder.decode(t)}catch{throw new y(y.NOT_UTF8,r)}}async hashViaCache(r,t,i){let o;try{o=await g.lstat(t,{bigint:!0})}catch(f){if(f.code==="ENOENT")return null;throw f}if(!o.isFile())return null;let s=this.hashes.get(r),l;if(s!==void 0&&Wt(s,o))l=s.sha;else try{l=await ce.hashFile(t)}catch(f){let d=f.code;if(d==="ENOENT"||f instanceof y)return null;if(d==="ELOOP"||d==="EMLINK")return null;throw f}if(jt(o,i))this.hashes.set(r,{mtimeNs:o.mtimeNs,ctimeNs:o.ctimeNs,size:o.size,sha:l});return l}}return a.isPathLegal=Ie,a})();function At(){return ke!==0}async function xt(a){let r=[],t=a;for(;;){try{await g.stat(t);break}catch(o){let s=o.code;if(s!=="ENOENT"&&s!=="ENOTDIR"&&s!=="ELOOP")throw o}r.push(t);let i=x.dirname(t);if(i===t)break;t=i}for(let i of r.reverse())try{await g.mkdir(i,{mode:Ue})}catch(o){if(o.code!=="EEXIST")throw o}}async function Fe(a,r){let t=x.relative(a,r);if(t==="")return;let i=a;for(let o of t.split(x.sep)){i=x.join(i,o);try{await g.mkdir(i,{mode:Ue})}catch(s){if(s.code!=="EEXIST")throw s}}}async function Dt(a,r,t){let i=t?Lt:Tt,o=x.join(x.dirname(a),`.fs-${St.randomBytes(8).toString("hex")}.tmp`),s;try{s=await g.open(o,z.O_WRONLY|z.O_CREAT|z.O_EXCL|ke,i),await s.writeFile(r),await s.close(),s=void 0,await g.rename(o,a)}catch(l){if(s)await s.close().catch(()=>{});throw await g.unlink(o).catch(()=>{}),l}}async function je(a,r){let t;try{t=await g.open(r,z.O_RDONLY|ke|$t)}catch(i){let o=i.code;if(o==="ELOOP"||o==="EMLINK")throw new y(y.IS_A_SYMLINK,a);throw i}try{if(!(await t.stat()).isFile())throw new y(y.NOT_A_FILE,a)}catch(i){throw await t.close().catch(()=>{}),i}return t}async function Ct(a){let r=St.createHash("sha256"),t=await je(x.basename(a),a),i=new Uint8Array(1048576);try{for(;;){let{bytesRead:o}=await t.read(i,0,i.length);if(o===0)break;r.update(i.subarray(0,o))}}finally{await t.close()}return r.digest("hex")}async function Pe(a,r,t){if(!await Pt(r,t))return[];let i=[];return await Be(t,(o,s)=>{if(s.isFile())i.push([x.relative(a,o).split(x.sep).join("/"),o])}),i.sort(),i}async function Ft(a,r,t){let i=(l)=>x.relative(a,l).split(x.sep).join("/"),o;try{o=await g.lstat(t,{bigint:!0})}catch(l){let f=l.code;if(f==="ENOENT"||f==="ENOTDIR")return new Set;throw l}if(o.isSymbolicLink())return new Set([i(t)]);if(!o.isDirectory())throw new y(y.NOT_A_DIRECTORY,r);let s=new Set;return await Be(t,(l,f)=>{if(f.isSymbolicLink())s.add(i(l))}),s}async function Pt(a,r){let t;try{t=await g.lstat(r,{bigint:!0})}catch(i){let o=i.code;if(o==="ENOENT"||o==="ENOTDIR")return!1;throw i}if(!t.isDirectory())throw new y(y.NOT_A_DIRECTORY,a);return!0}async function Be(a,r){let t=[a];while(t.length){let i=t.pop(),o;try{o=await g.readdir(i,{withFileTypes:!0})}catch(s){if(s.code==="ENOENT")continue;throw s}for(let s of o){let l=x.join(i,s.name);if(r(l,s),s.isDirectory()&&!s.isSymbolicLink())t.push(l)}}}function Wt(a,r){return r.mtimeNs===a.mtimeNs&&r.ctimeNs===a.ctimeNs&&r.size===a.size}function jt(a,r){return(a.mtimeNs>a.ctimeNs?a.mtimeNs:a.ctimeNs)<r-ce.timestampTrustMarginNs}var Bt=2000000000n,ce={hashFile:Ct,timestampTrustMarginNs:Bt,nowNs:()=>BigInt(Date.now())*1000000n},Ye=ve,We=Symbol.asyncDispose;if(We)Object.defineProperty(ve.prototype,We,{value:ve.prototype.dispose,configurable:!0,writable:!0});var w,N,fe,Q,de,p,G,he,L,qe,me,ze,Ge,Re,Ne,He,Ke,Te,Ve,Xe,ue,pe,Je,Ze,Yt=30000,K=".anthropic-memory-store",et=1;function Qe(a){return St.createHash("sha256").update(`version ${et}
6
- ${a}`,"utf-8").digest("hex")}var qt=30000,zt=100,Gt=20,Ht=16,Kt=32,Vt=8,Xt=50;class P extends c{constructor(a,r){super(a);if(this.name="SessionMemoryError",r!==void 0)this.cause=r}}class tt{constructor(a,r,t){this.mode=a,this.cap=r,this.waiveWindow=t,this.attempted=0,this.capped=0,this.suppressed=0}takeSlot(){if(this.attempted>=this.cap)return this.capped++,!1;return this.attempted++,!0}}var Jt=(()=>{class a{constructor(r,t){w.add(this),N.set(this,void 0),fe.set(this,void 0),Q.set(this,void 0),de.set(this,void 0),p.set(this,void 0),G.set(this,void 0),he.set(this,!1),L.set(this,[]),n(this,N,r,"f"),n(this,fe,t.workdir,"f"),n(this,Q,t.syncIntervalMs??wo,"f"),Rr(e(this,Q,"f"),"syncIntervalMs"),n(this,de,t.syncDeletions??"enabled","f"),n(this,p,T(r),"f"),n(this,G,Date.now(),"f")}get roots(){return e(this,L,"f").map((r)=>r.files.root().path)}get readOnlyRoots(){return e(this,L,"f").filter((r)=>r.readOnly).map((r)=>r.files.root().path)}async download(r){for(let t of r.resources){if(t.type!=="memory_store")continue;let i=e(this,w,"m",qe).call(this,t),o;try{if(o={memoryStoreId:t.memory_store_id,files:await Ye.open(i,{utf8:!0}),readOnly:t.access==="read_only",baseline:new Map,refusedShas:new Map,pendingDeletes:new Map},!o.files.root().removedOnDispose)throw new P(`something already exists at the memory store's path: ${i} (memory_store_id=${t.memory_store_id}); it must not exist when the session starts`);try{await o.files.createRoot()}catch(s){if(!H(s))throw s;throw new P(`cannot create the memory store's folder: ${i} (memory_store_id=${t.memory_store_id}): ${s}; the worker host must make this mount path writable`,s)}await e(this,w,"m",Ne).call(this,o),e(this,p,"f").info("downloaded memories",{count:o.baseline.size,memory_store_id:o.memoryStoreId,dest:o.files.root().path}),e(this,L,"f").push(o)}catch(s){if(o)await o.files.dispose().catch(()=>{});if(s instanceof P)throw s;throw new P(`failed to download memory store memory_store_id=${t.memory_store_id}: ${s}`,s)}}n(this,G,Date.now(),"f")}async finish(){if(e(this,he,"f"))throw new c("finish() was already called: it is the session's last sync and runs once");n(this,he,!0,"f"),await this.syncAll(!0)}async syncAll(r){await Promise.all(e(this,L,"f").map((t)=>e(this,w,"m",ze).call(this,t,r))),n(this,G,Date.now(),"f")}async syncIfDue(){if(Date.now()-e(this,G,"f")<e(this,Q,"f"))return;await this.syncAll(!1)}async flushWrites(r){await Promise.all(e(this,L,"f").map((t)=>e(this,w,"m",Ge).call(this,t,r)))}async dispose(){for(let r of e(this,L,"f")){let t=r.files.root();try{let i=await e(this,w,"m",me).call(this,r);if(!i.markerOk&&Object.keys(i.files).length>0){e(this,p,"f").warn(`${i.distrustReason}; leaving the memory store folder on disk`,{root:t.path,memory_store_id:r.memoryStoreId});continue}await r.files.dispose()}catch(i){if(!(i instanceof y)&&!H(i))throw i;e(this,p,"f").warn("failed to remove the memory store folder",{root:r.files.root().path,memory_store_id:r.memoryStoreId,error:String(i)});continue}if(t.removedOnDispose)e(this,p,"f").info("removed memory store dir",{dest:t.path,memory_store_id:r.memoryStoreId})}}}return N=new WeakMap,fe=new WeakMap,Q=new WeakMap,de=new WeakMap,p=new WeakMap,G=new WeakMap,he=new WeakMap,L=new WeakMap,w=new WeakSet,qe=function(t){if(t.mount_path){if(!Ie(t.mount_path))throw new P(`memory store mount_path is not a clean absolute path: ${JSON.stringify(t.mount_path)} (memory_store_id=${t.memory_store_id})`);return t.mount_path}return x.join(e(this,fe,"f"),"memory",t.name||t.memory_store_id)},me=async function(t){let i=await t.files.hashtree(),o=i[K];if(delete i[K],o===Qe(t.memoryStoreId))return{files:i,markerOk:!0,distrustReason:null};return{files:i,markerOk:!1,distrustReason:o!==void 0?"the marker file does not match this store":"the marker file is gone"}},ze=async function(t,i){try{let o=await e(this,w,"m",me).call(this,t),s=o.files;if(!o.markerOk){if(Object.keys(s).length>0){e(this,p,"f").warn(`${o.distrustReason}; leaving the memory store folder as found and not syncing`,{root:t.files.root().path,memory_store_id:t.memoryStoreId});return}await e(this,w,"m",Re).call(this,t,"the folder or its marker is gone");return}if(Object.keys(s).length===0&&t.baseline.size>1){await e(this,w,"m",Re).call(this,t,"every memory file is gone at once");return}let l=new Map;for await(let[u,_]of e(this,w,"m",ue).call(this,t.memoryStoreId))l.set(u,_);let f=new tt(e(this,de,"f"),Math.max(Vt,Math.min(Xt,Math.floor(t.baseline.size/4))),i),d=[],m=new Map,h=[...new Set([...l.keys(),...Object.keys(s),...t.baseline.keys()])].sort();for(let u of h){let _=l.get(u),b=s[u],D=t.baseline.get(u),v;if(b===void 0&&D!==void 0&&_!==void 0&&_.content_sha256===D&&!t.readOnly)v=await e(this,w,"m",Je).call(this,t,u,_,D,f);else v=await e(this,w,"m",He).call(this,t,u,_,b,d);if(v!==void 0)m.set(u,v)}if(t.baseline=m,await e(this,w,"m",Ve).call(this,t,d),f.suppressed>0)e(this,p,"f").debug("remote deletes are disabled; locally deleted memories stay on the server",{count:f.suppressed,memory_store_id:t.memoryStoreId});if(f.capped>0)e(this,p,"f").warn(`delete cap reached: ${f.mode==="log_only"?"would send":"sent"} ${f.attempted} deletes, held ${f.capped} for later syncs`,{memory_store_id:t.memoryStoreId})}catch(o){e(this,p,"f").warn("memory sync failed",{memory_store_id:t.memoryStoreId,error:String(o)})}},Ge=async function(t,i){let o=new Map,s=new Set,l=async()=>{if(t.readOnly)return;let f=await e(this,w,"m",me).call(this,t);if(!f.markerOk){e(this,p,"f").warn(`${f.distrustReason}; not uploading anything from the memory store folder`,{root:t.files.root().path,memory_store_id:t.memoryStoreId});return}for(let[h,u]of Object.entries(f.files))if(u!==t.baseline.get(h)&&t.refusedShas.get(h)!==u)o.set(h,u),s.add(h);if(o.size===0||i?.aborted)return;let d=new Map;for await(let[h,u]of e(this,w,"m",ue).call(this,t.memoryStoreId)){if(i?.aborted)return;d.set(h,u)}let m=[];for(let h of[...o.keys()].sort()){let u=o.get(h),_=t.baseline.get(h),b=d.get(h);if(b!==void 0&&b.content_sha256===u){t.baseline.set(h,b.content_sha256),s.delete(h);continue}if(b!==void 0&&b.content_sha256!==_){e(this,p,"f").warn("memory changed both locally and remotely; the flush leaves the remote version",{path:h,memory_store_id:t.memoryStoreId}),s.delete(h);continue}m.push([h,u,b])}await e(this,w,"m",Xe).call(this,t,m,s,i)};try{if(await Zt(l(),i),i?.aborted&&s.size>0)e(this,p,"f").warn(`memory flush cut off part-way; ${s.size} of ${o.size} changed files had not finished uploading`,{memory_store_id:t.memoryStoreId})}catch(f){e(this,p,"f").warn("memory flush failed",{memory_store_id:t.memoryStoreId,error:String(f)})}},Re=async function(t,i){e(this,p,"f").warn(`${i}; re-downloading the memory store folder instead of syncing`,{root:t.files.root().path,memory_store_id:t.memoryStoreId}),await t.files.createRoot(),await e(this,w,"m",Ne).call(this,t)},Ne=async function(t){t.baseline=new Map,t.pendingDeletes.clear(),await t.files.put(K,`version ${et}
6
+ ${a}`,"utf-8").digest("hex")}var qt=30000,zt=100,Gt=20,Ht=16,Kt=32,Vt=8,Xt=50;class P extends c{constructor(a,r){super(a);if(this.name="SessionMemoryError",r!==void 0)this.cause=r}}class tt{constructor(a,r,t){this.mode=a,this.cap=r,this.waiveWindow=t,this.attempted=0,this.capped=0,this.suppressed=0}takeSlot(){if(this.attempted>=this.cap)return this.capped++,!1;return this.attempted++,!0}}var Jt=(()=>{class a{constructor(r,t){w.add(this),N.set(this,void 0),fe.set(this,void 0),Q.set(this,void 0),de.set(this,void 0),p.set(this,void 0),G.set(this,void 0),he.set(this,!1),L.set(this,[]),n(this,N,r,"f"),n(this,fe,t.workdir,"f"),n(this,Q,t.syncIntervalMs??wo,"f"),Ir(e(this,Q,"f"),"syncIntervalMs"),n(this,de,t.syncDeletions??"enabled","f"),n(this,p,T(r),"f"),n(this,G,Date.now(),"f")}get roots(){return e(this,L,"f").map((r)=>r.files.root().path)}get readOnlyRoots(){return e(this,L,"f").filter((r)=>r.readOnly).map((r)=>r.files.root().path)}async download(r){for(let t of r.resources){if(t.type!=="memory_store")continue;let i=e(this,w,"m",qe).call(this,t),o;try{if(o={memoryStoreId:t.memory_store_id,files:await Ye.open(i,{utf8:!0}),readOnly:t.access==="read_only",baseline:new Map,refusedShas:new Map,pendingDeletes:new Map},!o.files.root().removedOnDispose)throw new P(`something already exists at the memory store's path: ${i} (memory_store_id=${t.memory_store_id}); it must not exist when the session starts`);try{await o.files.createRoot()}catch(s){if(!H(s))throw s;throw new P(`cannot create the memory store's folder: ${i} (memory_store_id=${t.memory_store_id}): ${s}; the worker host must make this mount path writable`,s)}await e(this,w,"m",Ne).call(this,o),e(this,p,"f").info("downloaded memories",{count:o.baseline.size,memory_store_id:o.memoryStoreId,dest:o.files.root().path}),e(this,L,"f").push(o)}catch(s){if(o)await o.files.dispose().catch(()=>{});if(s instanceof P)throw s;throw new P(`failed to download memory store memory_store_id=${t.memory_store_id}: ${s}`,s)}}n(this,G,Date.now(),"f")}async finish(){if(e(this,he,"f"))throw new c("finish() was already called: it is the session's last sync and runs once");n(this,he,!0,"f"),await this.syncAll(!0)}async syncAll(r){await Promise.all(e(this,L,"f").map((t)=>e(this,w,"m",ze).call(this,t,r))),n(this,G,Date.now(),"f")}async syncIfDue(){if(Date.now()-e(this,G,"f")<e(this,Q,"f"))return;await this.syncAll(!1)}async flushWrites(r){await Promise.all(e(this,L,"f").map((t)=>e(this,w,"m",Ge).call(this,t,r)))}async dispose(){for(let r of e(this,L,"f")){let t=r.files.root();try{let i=await e(this,w,"m",me).call(this,r);if(!i.markerOk&&Object.keys(i.files).length>0){e(this,p,"f").warn(`${i.distrustReason}; leaving the memory store folder on disk`,{root:t.path,memory_store_id:r.memoryStoreId});continue}await r.files.dispose()}catch(i){if(!(i instanceof y)&&!H(i))throw i;e(this,p,"f").warn("failed to remove the memory store folder",{root:r.files.root().path,memory_store_id:r.memoryStoreId,error:String(i)});continue}if(t.removedOnDispose)e(this,p,"f").info("removed memory store dir",{dest:t.path,memory_store_id:r.memoryStoreId})}}}return N=new WeakMap,fe=new WeakMap,Q=new WeakMap,de=new WeakMap,p=new WeakMap,G=new WeakMap,he=new WeakMap,L=new WeakMap,w=new WeakSet,qe=function(t){if(t.mount_path){if(!Ie(t.mount_path))throw new P(`memory store mount_path is not a clean absolute path: ${JSON.stringify(t.mount_path)} (memory_store_id=${t.memory_store_id})`);return t.mount_path}return x.join(e(this,fe,"f"),"memory",t.name||t.memory_store_id)},me=async function(t){let i=await t.files.hashtree(),o=i[K];if(delete i[K],o===Qe(t.memoryStoreId))return{files:i,markerOk:!0,distrustReason:null};return{files:i,markerOk:!1,distrustReason:o!==void 0?"the marker file does not match this store":"the marker file is gone"}},ze=async function(t,i){try{let o=await e(this,w,"m",me).call(this,t),s=o.files;if(!o.markerOk){if(Object.keys(s).length>0){e(this,p,"f").warn(`${o.distrustReason}; leaving the memory store folder as found and not syncing`,{root:t.files.root().path,memory_store_id:t.memoryStoreId});return}await e(this,w,"m",Re).call(this,t,"the folder or its marker is gone");return}if(Object.keys(s).length===0&&t.baseline.size>1){await e(this,w,"m",Re).call(this,t,"every memory file is gone at once");return}let l=new Map;for await(let[u,_]of e(this,w,"m",ue).call(this,t.memoryStoreId))l.set(u,_);let f=new tt(e(this,de,"f"),Math.max(Vt,Math.min(Xt,Math.floor(t.baseline.size/4))),i),d=[],m=new Map,h=[...new Set([...l.keys(),...Object.keys(s),...t.baseline.keys()])].sort();for(let u of h){let _=l.get(u),b=s[u],D=t.baseline.get(u),v;if(b===void 0&&D!==void 0&&_!==void 0&&_.content_sha256===D&&!t.readOnly)v=await e(this,w,"m",Je).call(this,t,u,_,D,f);else v=await e(this,w,"m",He).call(this,t,u,_,b,d);if(v!==void 0)m.set(u,v)}if(t.baseline=m,await e(this,w,"m",Ve).call(this,t,d),f.suppressed>0)e(this,p,"f").debug("remote deletes are disabled; locally deleted memories stay on the server",{count:f.suppressed,memory_store_id:t.memoryStoreId});if(f.capped>0)e(this,p,"f").warn(`delete cap reached: ${f.mode==="log_only"?"would send":"sent"} ${f.attempted} deletes, held ${f.capped} for later syncs`,{memory_store_id:t.memoryStoreId})}catch(o){e(this,p,"f").warn("memory sync failed",{memory_store_id:t.memoryStoreId,error:String(o)})}},Ge=async function(t,i){let o=new Map,s=new Set,l=async()=>{if(t.readOnly)return;let f=await e(this,w,"m",me).call(this,t);if(!f.markerOk){e(this,p,"f").warn(`${f.distrustReason}; not uploading anything from the memory store folder`,{root:t.files.root().path,memory_store_id:t.memoryStoreId});return}for(let[h,u]of Object.entries(f.files))if(u!==t.baseline.get(h)&&t.refusedShas.get(h)!==u)o.set(h,u),s.add(h);if(o.size===0||i?.aborted)return;let d=new Map;for await(let[h,u]of e(this,w,"m",ue).call(this,t.memoryStoreId)){if(i?.aborted)return;d.set(h,u)}let m=[];for(let h of[...o.keys()].sort()){let u=o.get(h),_=t.baseline.get(h),b=d.get(h);if(b!==void 0&&b.content_sha256===u){t.baseline.set(h,b.content_sha256),s.delete(h);continue}if(b!==void 0&&b.content_sha256!==_){e(this,p,"f").warn("memory changed both locally and remotely; the flush leaves the remote version",{path:h,memory_store_id:t.memoryStoreId}),s.delete(h);continue}m.push([h,u,b])}await e(this,w,"m",Xe).call(this,t,m,s,i)};try{if(await Zt(l(),i),i?.aborted&&s.size>0)e(this,p,"f").warn(`memory flush cut off part-way; ${s.size} of ${o.size} changed files had not finished uploading`,{memory_store_id:t.memoryStoreId})}catch(f){e(this,p,"f").warn("memory flush failed",{memory_store_id:t.memoryStoreId,error:String(f)})}},Re=async function(t,i){e(this,p,"f").warn(`${i}; re-downloading the memory store folder instead of syncing`,{root:t.files.root().path,memory_store_id:t.memoryStoreId}),await t.files.createRoot(),await e(this,w,"m",Ne).call(this,t)},Ne=async function(t){t.baseline=new Map,t.pendingDeletes.clear(),await t.files.put(K,`version ${et}
7
7
  ${t.memoryStoreId}`);for await(let[i,o]of e(this,w,"m",ue).call(this,t.memoryStoreId,"full"))if(await e(this,w,"m",Te).call(this,t,i,o.content??""))t.baseline.set(i,o.content_sha256)},He=async function(t,i,o,s,l){let f=t.baseline.get(i);if(s!==void 0)t.pendingDeletes.delete(i);if(!o){if(s===void 0){t.pendingDeletes.delete(i);return}if(f!==void 0){if(s===f){let _=await e(this,w,"m",Ke).call(this,t,i,f);if(_===void 0)return;if(_===f)return f;s=_}if(t.readOnly)e(this,p,"f").warn("memory deleted remotely but edited locally; keeping the file, which a read-only store cannot push",{path:i,memory_store_id:t.memoryStoreId});else if(t.refusedShas.get(i)!==s)e(this,p,"f").info("memory deleted remotely but edited locally; re-creating it from the file",{path:i,memory_store_id:t.memoryStoreId})}if(t.readOnly)return;if(t.refusedShas.get(i)===s)return;return await e(this,w,"m",pe).call(this,t,i,s,void 0)}let d=o.content_sha256,m=d!==f,h=s!==void 0&&s!==f&&s!==d,u=!t.readOnly&&h;if(s===void 0&&f!==void 0){if(m)e(this,p,"f").warn("memory deleted locally but changed remotely; restoring the remote version",{path:i,memory_store_id:t.memoryStoreId}),t.pendingDeletes.delete(i),l.push([i,o]);return f}if(m){if(s===d)return d;if(h)e(this,p,"f").warn("memory changed both locally and remotely; keeping the remote version",{path:i,memory_store_id:t.memoryStoreId});return l.push([i,o]),f}if(u){if(t.refusedShas.get(i)===s)return d;return await e(this,w,"m",pe).call(this,t,i,s,o)??d}return d},Ke=async function(t,i,o){let s;try{s=await t.files.hashFile(i)}catch(l){if(!(l instanceof y)&&!H(l))throw l;return o}if(s===null)return;if(s!==o)return s;try{await t.files.remove(i)}catch(l){if(!(l instanceof y)&&!H(l))throw l;return e(this,p,"f").warn("failed to remove memory deleted remotely",{path:i,memory_store_id:t.memoryStoreId,error:String(l)}),o}return},Te=async function(t,i,o){try{await t.files.put(i,o)}catch(s){if(!(s instanceof y)&&!H(s))throw s;return e(this,p,"f").warn("failed to write memory",{path:i,memory_store_id:t.memoryStoreId,error:String(s)}),!1}return!0},Ve=async function(t,i){if(i.length===0)return;let o=async(f,d)=>{let m;try{m=await e(this,N,"f").beta.memoryStores.memories.retrieve(d.id,{memory_store_id:t.memoryStoreId,view:"full"})}catch(h){if(le(h,404))return;e(this,p,"f").warn("failed to fetch memory content",{path:f,memory_store_id:t.memoryStoreId,error:String(h)});return}if(await e(this,w,"m",Te).call(this,t,f,m.content??""))t.baseline.set(f,m.content_sha256)},s=i[Symbol.iterator](),l=async()=>{for(let[f,d]of s)await o(f,d)};await Promise.all(Array.from({length:Math.min(Ht,i.length)},l))},Xe=async function(t,i,o,s){let l=i[Symbol.iterator](),f=async()=>{for(let[d,m,h]of l){if(s?.aborted)return;let u=await e(this,w,"m",pe).call(this,t,d,m,h);if(o.delete(d),u!==void 0)t.baseline.set(d,u)}};await Promise.all(Array.from({length:Math.min(Kt,i.length)},f))},ue=async function*(t,i="basic"){let o=i==="basic"?zt:Gt;for await(let s of e(this,N,"f").beta.memoryStores.memories.list(t,{view:i,limit:o})){if(s.type!=="memory")continue;let l=s.path.replace(/^\/+/,"");if(l===K){e(this,p,"f").warn("the server listed the reserved marker path; skipping",{path:s.path,memory_store_id:t});continue}yield[l,s]}},pe=async function r(t,i,o,s){try{let l=await t.files.get(i);if(l===null)return;let f=vt(l),d=s?await e(this,N,"f").beta.memoryStores.memories.update(s.id,{memory_store_id:t.memoryStoreId,content:f,precondition:{type:"content_sha256",content_sha256:s.content_sha256}}):await e(this,N,"f").beta.memoryStores.memories.create(t.memoryStoreId,{path:"/"+i,content:f});return t.refusedShas.delete(i),d.content_sha256}catch(l){if(s&&le(l,404))return await e(this,w,"m",r).call(this,t,i,o,void 0);let f=l instanceof y||le(l,400)||le(l,413);if(s&&le(l,409))e(this,p,"f").warn("memory changed both locally and remotely; the upload was refused and the local edit loses",{path:i,memory_store_id:t.memoryStoreId});else if(f&&o!==void 0)t.refusedShas.set(i,o),e(this,p,"f").warn("the server rejected this memory file, so it stays un-synced until its content changes",{path:i,memory_store_id:t.memoryStoreId,rejection:String(l)});else e(this,p,"f").warn("failed to upload memory",{path:i,memory_store_id:t.memoryStoreId,error:String(l)});return}},Je=async function(t,i,o,s,l){if(l.mode==="disabled")return l.suppressed++,s;let f=t.pendingDeletes.get(i);if(f===void 0)f=Date.now(),t.pendingDeletes.set(i,f);if(!l.waiveWindow&&Date.now()-f<qt)return s;let d,m;try{d=await t.files.hashFile(K)===Qe(t.memoryStoreId),m=await t.files.hashFile(i)===null}catch(u){if(!(u instanceof y)&&!H(u))throw u;d=m=!1}if(!d)return s;if(!m)return t.pendingDeletes.delete(i),s;if(!l.takeSlot())return s;if(l.mode==="log_only")return e(this,p,"f").info("log-only: sync would delete this memory on the server",{path:i,memory_store_id:t.memoryStoreId}),s;let h=await e(this,w,"m",Ze).call(this,t,i,o,s);if(h===void 0)t.pendingDeletes.delete(i);return h},Ze=async function(t,i,o,s){try{await e(this,N,"f").beta.memoryStores.memories.delete(o.id,{memory_store_id:t.memoryStoreId,expected_content_sha256:s})}catch(l){if(le(l,404))return;if(le(l,409)||le(l,412))e(this,p,"f").warn("memory deleted locally but changed remotely; keeping the remote version",{path:i,memory_store_id:t.memoryStoreId});else e(this,p,"f").warn("failed to delete memory",{path:i,memory_store_id:t.memoryStoreId,error:String(l)});return s}e(this,p,"f").info("propagated local deletion",{path:i,memory_store_id:t.memoryStoreId});return},a})();function H(a){return typeof a==="object"&&a!==null&&typeof a.code==="string"}async function Zt(a,r){if(!r){await a;return}let t,i=new Promise((o)=>{if(t=o,r.aborted)o()});r.addEventListener("abort",t,{once:!0});try{await Promise.race([a,i])}finally{r.removeEventListener("abort",t)}}var ye,O,k,ee,W,R,Le,we,te,_e,ge,U,j,V,B,re,A,rt,it,nt=102400,ft=120000,Qt=262144,er=65536,ot=Buffer.from(`
8
8
  `),ie=102400,tr=2000,rr=200;class dt extends c{constructor(a){super(`bash command timed out after ${a}ms`);this.name="BashTimeoutError",this.timeoutMs=a}}var ir=/\x1b\[[0-9;?]*[ -/]*[@-~]/g,nr=S.glob;function ht(a){return a===void 0?Qt:a}function Y(a){if(a===void 0)return;throw new c("The `unrestrictedPaths` option you passed to the agent toolset (AgentToolContext) is no longer supported. The toolset's file tools (read, write, edit, glob, grep) are now always confined to the working directory plus the directories listed in `allowedRoots`. Remove `unrestrictedPaths` from your context; to let the file tools reach any other directory, add it to `allowedRoots`.")}function Xr(a){return[ar(a),cr(a),dr(a),hr(a),ur(a),pr(a)]}async function oe(a,r){return Y(a.unrestrictedPaths),Ae(a.workdir,r,{allowedRoots:a.allowedRoots??[]})}function mt(a,r){return Ee(a.readOnlyRoots??[],r)}function or(){let a={};for(let[r,t]of Object.entries(process.env)){if(r.startsWith("ANTHROPIC_"))continue;a[r]=t}return a}var sr=(()=>{class a{constructor(r,t=or()){ye.add(this),O.set(this,void 0),k.set(this,""),ee.set(this,!1),W.set(this,!1),R.set(this,null),n(this,O,$e.spawn("/bin/bash",["--noprofile","--norc"],{cwd:r,env:{...t,PS1:"",PS2:"",TERM:"dumb"},stdio:["pipe","pipe","pipe"],detached:!0}),"f"),e(this,O,"f").stdout.setEncoding("utf8"),e(this,O,"f").stderr.setEncoding("utf8"),e(this,O,"f").stdout.on("data",(i)=>e(this,ye,"m",Le).call(this,i)),e(this,O,"f").stderr.on("data",(i)=>e(this,ye,"m",Le).call(this,i)),e(this,O,"f").once("close",()=>{n(this,W,!0,"f");let i=e(this,R,"f");n(this,R,null,"f"),i?.resolve()})}get closed(){return e(this,W,"f")}async exec(r,t={}){if(e(this,W,"f"))throw new c("bash session terminated");let i=t.timeoutMs??ft,o=t.signal;o?.throwIfAborted(),n(this,k,"","f"),n(this,ee,!1,"f");let s=`__ANT_CMD_${ct.randomUUID()}_DONE__`,l=`${s.slice(0,8)}''${s.slice(8)}`,f=`{ ${r}
9
9
  } </dev/null 2>&1; printf '\\n${l}%d\\n' $?
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- import{kt,zt,jt,Vt,Kt,dr,mr,Rt,hr,fr,gr,yr,br,Sr}from"./chunk-gp7y0fja.js";import{ee}from"./chunk-tvm4zmgj.js";import{q,j}from"./chunk-y69ewdn2.js";import{V}from"./chunk-3cjsd292.js";import{g}from"./chunk-n6e43rvk.js";import{fe}from"./chunk-x4874m8e.js";import{N,pe,ne,Le,Q,H}from"./chunk-8tjad3r0.js";import{M}from"./chunk-shadcb9z.js";var w=0,C=(n,a,t)=>{let o=new M,l=Le(a);return(async()=>{let e={role:"assistant",content:[],api:"google-generative-ai",provider:n.provider,model:n.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:"pending",timestamp:Date.now()};try{if(t?.fetch&&t.fetch!==globalThis.fetch)throw Error("Custom fetch is not supported by the Google Generative AI adapter");let u=t?.apiKey;if(!u)throw Error(`No API key for provider: ${n.provider}`);let d=T(n,u,t?.headers),p=S(n,l,t),m=await t?.onPayload?.(p,n);if(m!==void 0)p=m;let f=await Sr(()=>d.models.generateContentStream(p),t);o.push({type:"start",partial:e});let i=null,k=e.content,c=()=>k.length-1;for await(let s of f){await t?.onProviderStreamEvent?.(s,n),e.responseId||=s.responseId;let y=s.candidates?.[0];if(y?.content?.parts)for(let r of y.content.parts){if(r.text!==void 0){let h=mr(r);if(!i||h&&i.type!=="thinking"||!h&&i.type!=="text"){if(i)if(i.type==="text")o.push({type:"text_end",contentIndex:k.length-1,content:i.text,partial:e});else o.push({type:"thinking_end",contentIndex:c(),content:i.thinking,partial:e});if(h)i={type:"thinking",thinking:"",thinkingSignature:void 0},e.content.push(i),o.push({type:"thinking_start",contentIndex:c(),partial:e});else i={type:"text",text:""},e.content.push(i),o.push({type:"text_start",contentIndex:c(),partial:e})}if(i.type==="thinking")i.thinking+=r.text,i.thinkingSignature=Rt(i.thinkingSignature,r.thoughtSignature),o.push({type:"thinking_delta",contentIndex:c(),delta:r.text,partial:e});else i.text+=r.text,i.textSignature=Rt(i.textSignature,r.thoughtSignature),o.push({type:"text_delta",contentIndex:c(),delta:r.text,partial:e})}if(r.functionCall){if(i){if(i.type==="text")o.push({type:"text_end",contentIndex:c(),content:i.text,partial:e});else o.push({type:"thinking_end",contentIndex:c(),content:i.thinking,partial:e});i=null}let h=r.functionCall.id,x={type:"toolCall",id:!h||e.content.some((b)=>b.type==="toolCall"&&b.id===h)?`${r.functionCall.name}_${Date.now()}_${++w}`:h,name:r.functionCall.name||"",arguments:r.functionCall.args??{},...r.thoughtSignature&&{thoughtSignature:r.thoughtSignature}};e.content.push(x),o.push({type:"toolcall_start",contentIndex:c(),partial:e}),o.push({type:"toolcall_delta",contentIndex:c(),delta:JSON.stringify(x.arguments),partial:e}),o.push({type:"toolcall_end",contentIndex:c(),toolCall:x,partial:e})}}if(y?.finishReason){if(e.rawStopReason=y.finishReason,e.stopReason=br(y.finishReason),e.content.some((r)=>r.type==="toolCall")&&e.stopReason==="stop")e.stopReason="toolUse"}if(s.usageMetadata)e.usage={input:(s.usageMetadata.promptTokenCount||0)-(s.usageMetadata.cachedContentTokenCount||0),output:(s.usageMetadata.candidatesTokenCount||0)+(s.usageMetadata.thoughtsTokenCount||0),cacheRead:s.usageMetadata.cachedContentTokenCount||0,cacheWrite:0,reasoning:s.usageMetadata.thoughtsTokenCount||0,totalTokens:s.usageMetadata.totalTokenCount||0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},Q(n,e.usage)}if(i)if(i.type==="text")o.push({type:"text_end",contentIndex:c(),content:i.text,partial:e});else o.push({type:"thinking_end",contentIndex:c(),content:i.thinking,partial:e});if(t?.signal?.aborted)throw Error("Request was aborted");if(e.stopReason==="pending")throw Error("Google stream ended without a finish reason");if(e.stopReason==="aborted"||e.stopReason==="error"){let s=e.rawStopReason?`Provider stopped with: ${e.rawStopReason}`:"An unknown error occurred";throw Error(s)}o.push({type:"done",reason:e.stopReason,message:e}),o.end()}catch(u){for(let d of e.content)if("index"in d)delete d.index;e.stopReason=t?.signal?.aborted?"aborted":"error",e.errorMessage=j(q(u)),o.push({type:"error",reason:e.stopReason,error:e}),o.end()}})(),o},z=(n,a,t)=>{let o=t?.apiKey;if(!o)throw Error(`No API key for provider: ${n.provider}`);let l={...V(n,a,t,o),toolChoice:t?.toolChoice};if(!t?.reasoning)return C(n,a,{...l,thinking:{enabled:!1}});let e=H(n,t.reasoning);if(e==="off")return C(n,a,{...l,thinking:{enabled:!1}});let u=zt(n,e);if(jt(n))return C(n,a,{...l,thinking:{enabled:!0,level:Vt(u)}});return C(n,a,{...l,thinking:{enabled:!0,budgetTokens:I(n,u,t.thinkingBudgets)}})};function T(n,a,t){let o={};if(n.baseUrl)o.baseUrl=n.baseUrl,o.apiVersion="";let l=fe({"User-Agent":ee(),...n.headers,...t});if(l)o.headers=l;return new kt({apiKey:a,httpOptions:Object.keys(o).length>0?o:void 0})}function S(n,a,t={}){let o=hr(n,a),l=pe(a.messages),e=ne(a.messages),u={};if(t.temperature!==void 0)u.temperature=t.temperature;if(t.maxTokens!==void 0)u.maxOutputTokens=t.maxTokens;let d=gr(n.id),p=e.length>0?yr(e,t.toolChoice,d):void 0,m=l?N(l):"",f={...Object.keys(u).length>0&&u,...m&&{systemInstruction:g(m)},...e.length>0&&{tools:fr(e,!1,d)},...p!==void 0&&{toolConfig:{functionCallingConfig:{mode:p}}}};if(t.thinking?.enabled&&n.reasoning){let k={includeThoughts:!0};if(t.thinking.level!==void 0)k.thinkingLevel=Kt(t.thinking.level);else if(t.thinking.budgetTokens!==void 0)k.thinkingBudget=t.thinking.budgetTokens;f.thinkingConfig=k}else if(n.reasoning&&t.thinking&&!t.thinking.enabled)f.thinkingConfig=dr(n);if(t.signal){if(t.signal.aborted)throw Error("Request aborted");f.abortSignal=t.signal}return{model:n.id,contents:o,config:f}}function I(n,a,t){if(t?.[a]!==void 0)return t[a];if(n.id.includes("2.5-pro"))return{minimal:128,low:2048,medium:8192,high:32768}[a];if(n.id.includes("2.5-flash-lite"))return{minimal:512,low:2048,medium:8192,high:24576}[a];if(n.id.includes("2.5-flash"))return{minimal:128,low:2048,medium:8192,high:24576}[a];return-1}export{C as stream,z as streamSimple};
2
+ import{kt,zt,jt,Vt,Kt,mr,hr,Rt,fr,gr,yr,br,Sr,xr}from"./chunk-9rmqgc3c.js";import{ee}from"./chunk-tvm4zmgj.js";import{q,j}from"./chunk-y69ewdn2.js";import{V}from"./chunk-whvj83b7.js";import{g}from"./chunk-n6e43rvk.js";import{fe}from"./chunk-x4874m8e.js";import{N,pe,ne,Le,Q,H}from"./chunk-8wc8qdx8.js";import{M}from"./chunk-shadcb9z.js";var w=0,C=(n,a,t)=>{let o=new M,l=Le(a);return(async()=>{let e={role:"assistant",content:[],api:"google-generative-ai",provider:n.provider,model:n.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:"pending",timestamp:Date.now()};try{if(t?.fetch&&t.fetch!==globalThis.fetch)throw Error("Custom fetch is not supported by the Google Generative AI adapter");let u=t?.apiKey;if(!u)throw Error(`No API key for provider: ${n.provider}`);let d=T(n,u,t?.headers),p=S(n,l,t),m=await t?.onPayload?.(p,n);if(m!==void 0)p=m;let f=await xr(()=>d.models.generateContentStream(p),t);o.push({type:"start",partial:e});let i=null,k=e.content,c=()=>k.length-1;for await(let s of f){await t?.onProviderStreamEvent?.(s,n),e.responseId||=s.responseId;let y=s.candidates?.[0];if(y?.content?.parts)for(let r of y.content.parts){if(r.text!==void 0){let h=hr(r);if(!i||h&&i.type!=="thinking"||!h&&i.type!=="text"){if(i)if(i.type==="text")o.push({type:"text_end",contentIndex:k.length-1,content:i.text,partial:e});else o.push({type:"thinking_end",contentIndex:c(),content:i.thinking,partial:e});if(h)i={type:"thinking",thinking:"",thinkingSignature:void 0},e.content.push(i),o.push({type:"thinking_start",contentIndex:c(),partial:e});else i={type:"text",text:""},e.content.push(i),o.push({type:"text_start",contentIndex:c(),partial:e})}if(i.type==="thinking")i.thinking+=r.text,i.thinkingSignature=Rt(i.thinkingSignature,r.thoughtSignature),o.push({type:"thinking_delta",contentIndex:c(),delta:r.text,partial:e});else i.text+=r.text,i.textSignature=Rt(i.textSignature,r.thoughtSignature),o.push({type:"text_delta",contentIndex:c(),delta:r.text,partial:e})}if(r.functionCall){if(i){if(i.type==="text")o.push({type:"text_end",contentIndex:c(),content:i.text,partial:e});else o.push({type:"thinking_end",contentIndex:c(),content:i.thinking,partial:e});i=null}let h=r.functionCall.id,x={type:"toolCall",id:!h||e.content.some((b)=>b.type==="toolCall"&&b.id===h)?`${r.functionCall.name}_${Date.now()}_${++w}`:h,name:r.functionCall.name||"",arguments:r.functionCall.args??{},...r.thoughtSignature&&{thoughtSignature:r.thoughtSignature}};e.content.push(x),o.push({type:"toolcall_start",contentIndex:c(),partial:e}),o.push({type:"toolcall_delta",contentIndex:c(),delta:JSON.stringify(x.arguments),partial:e}),o.push({type:"toolcall_end",contentIndex:c(),toolCall:x,partial:e})}}if(y?.finishReason){if(e.rawStopReason=y.finishReason,e.stopReason=Sr(y.finishReason),e.content.some((r)=>r.type==="toolCall")&&e.stopReason==="stop")e.stopReason="toolUse"}if(s.usageMetadata)e.usage={input:(s.usageMetadata.promptTokenCount||0)-(s.usageMetadata.cachedContentTokenCount||0),output:(s.usageMetadata.candidatesTokenCount||0)+(s.usageMetadata.thoughtsTokenCount||0),cacheRead:s.usageMetadata.cachedContentTokenCount||0,cacheWrite:0,reasoning:s.usageMetadata.thoughtsTokenCount||0,totalTokens:s.usageMetadata.totalTokenCount||0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},Q(n,e.usage)}if(i)if(i.type==="text")o.push({type:"text_end",contentIndex:c(),content:i.text,partial:e});else o.push({type:"thinking_end",contentIndex:c(),content:i.thinking,partial:e});if(t?.signal?.aborted)throw Error("Request was aborted");if(e.stopReason==="pending")throw Error("Google stream ended without a finish reason");if(e.stopReason==="aborted"||e.stopReason==="error"){let s=e.rawStopReason?`Provider stopped with: ${e.rawStopReason}`:"An unknown error occurred";throw Error(s)}o.push({type:"done",reason:e.stopReason,message:e}),o.end()}catch(u){for(let d of e.content)if("index"in d)delete d.index;e.stopReason=t?.signal?.aborted?"aborted":"error",e.errorMessage=j(q(u)),o.push({type:"error",reason:e.stopReason,error:e}),o.end()}})(),o},z=(n,a,t)=>{let o=t?.apiKey;if(!o)throw Error(`No API key for provider: ${n.provider}`);let l={...V(n,a,t,o),toolChoice:t?.toolChoice};if(!t?.reasoning)return C(n,a,{...l,thinking:{enabled:!1}});let e=H(n,t.reasoning);if(e==="off")return C(n,a,{...l,thinking:{enabled:!1}});let u=zt(n,e);if(jt(n))return C(n,a,{...l,thinking:{enabled:!0,level:Vt(u)}});return C(n,a,{...l,thinking:{enabled:!0,budgetTokens:I(n,u,t.thinkingBudgets)}})};function T(n,a,t){let o={};if(n.baseUrl)o.baseUrl=n.baseUrl,o.apiVersion="";let l=fe({"User-Agent":ee(),...n.headers,...t});if(l)o.headers=l;return new kt({apiKey:a,httpOptions:Object.keys(o).length>0?o:void 0})}function S(n,a,t={}){let o=fr(n,a),l=pe(a.messages),e=ne(a.messages),u={};if(t.temperature!==void 0)u.temperature=t.temperature;if(t.maxTokens!==void 0)u.maxOutputTokens=t.maxTokens;let d=yr(n.id),p=e.length>0?br(e,t.toolChoice,d):void 0,m=l?N(l):"",f={...Object.keys(u).length>0&&u,...m&&{systemInstruction:g(m)},...e.length>0&&{tools:gr(e,!1,d)},...p!==void 0&&{toolConfig:{functionCallingConfig:{mode:p}}}};if(t.thinking?.enabled&&n.reasoning){let k={includeThoughts:!0};if(t.thinking.level!==void 0)k.thinkingLevel=Kt(t.thinking.level);else if(t.thinking.budgetTokens!==void 0)k.thinkingBudget=t.thinking.budgetTokens;f.thinkingConfig=k}else if(n.reasoning&&t.thinking&&!t.thinking.enabled)f.thinkingConfig=mr(n);if(t.signal){if(t.signal.aborted)throw Error("Request aborted");f.abortSignal=t.signal}return{model:n.id,contents:o,config:f}}function I(n,a,t){if(t?.[a]!==void 0)return t[a];if(n.id.includes("2.5-pro"))return{minimal:128,low:2048,medium:8192,high:32768}[a];if(n.id.includes("2.5-flash-lite"))return{minimal:512,low:2048,medium:8192,high:24576}[a];if(n.id.includes("2.5-flash"))return{minimal:128,low:2048,medium:8192,high:24576}[a];return-1}export{C as stream,z as streamSimple};