@shumai-one/shumai 0.2.1 → 0.2.3

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 (140) hide show
  1. package/bin/{chunk-qag3w2dd.js → chunk-0aj303as.js} +1 -1
  2. package/bin/{chunk-976v5s8y.js → chunk-0qkj838r.js} +1 -1
  3. package/bin/{chunk-mg6fce5x.js → chunk-0rxhc7ka.js} +1 -1
  4. package/bin/chunk-0xbf8bcg.js +2 -0
  5. package/bin/{chunk-t1mxqskx.js → chunk-15sefy5t.js} +1 -1
  6. package/bin/{chunk-jfjcxyhf.js → chunk-1wm57c6y.js} +3 -3
  7. package/bin/{chunk-7ktvhtp1.js → chunk-1xpec5r8.js} +1 -1
  8. package/bin/chunk-23d3968z.js +2 -0
  9. package/bin/{chunk-y4s3xr4n.js → chunk-262hkppb.js} +2 -2
  10. package/bin/{chunk-qj2kpkje.js → chunk-29tx9qe2.js} +1 -1
  11. package/bin/chunk-2a9n3dhx.js +1 -0
  12. package/bin/{chunk-a5s5ny4z.js → chunk-2aamsc5v.js} +1 -1
  13. package/bin/{chunk-gd5xwgp6.js → chunk-2aascrtb.js} +1 -1
  14. package/bin/{chunk-pv76qkym.js → chunk-31baz5n0.js} +1 -1
  15. package/bin/chunk-3hzj13pj.js +1 -0
  16. package/bin/{chunk-2xnys7v4.js → chunk-3n1rezd0.js} +1 -1
  17. package/bin/{chunk-zn9jbc6t.js → chunk-3qks722n.js} +1 -1
  18. package/bin/{chunk-hmsb7ehr.js → chunk-46ar48f9.js} +1 -1
  19. package/bin/{chunk-ga0drqj7.js → chunk-4qpa7b5t.js} +1 -1
  20. package/bin/{chunk-9n783gva.js → chunk-5d2q46mx.js} +1 -1
  21. package/bin/{chunk-ydagqpny.js → chunk-5t6c3038.js} +1 -1
  22. package/bin/chunk-5vkf99sk.js +1 -0
  23. package/bin/chunk-6xg65n5y.js +2 -0
  24. package/bin/chunk-6z65xd0w.js +3 -0
  25. package/bin/chunk-6zascpcz.js +2 -0
  26. package/bin/{chunk-qjjr3fff.js → chunk-77r8w95d.js} +1 -1
  27. package/bin/{chunk-58aabg1f.js → chunk-7hsgmjpa.js} +2 -2
  28. package/bin/{chunk-7mnezagc.js → chunk-88fg1sw7.js} +1 -1
  29. package/bin/{chunk-jyjnt0s9.js → chunk-898q6x3q.js} +2 -2
  30. package/bin/chunk-8dqq1fk0.js +2 -0
  31. package/bin/chunk-8tf6kgdj.js +2 -0
  32. package/bin/{chunk-b9hb5jzt.js → chunk-8wqfkm4c.js} +1 -1
  33. package/bin/{chunk-ag35pxnb.js → chunk-922nnh39.js} +1 -1
  34. package/bin/{chunk-ymyyap80.js → chunk-925q4paa.js} +1 -1
  35. package/bin/{chunk-0a5k9avd.js → chunk-97jzve52.js} +1 -1
  36. package/bin/{chunk-dzm2f82x.js → chunk-9ab6k4rq.js} +1 -1
  37. package/bin/{chunk-mwh2n8yt.js → chunk-9avkn3x1.js} +1 -1
  38. package/bin/{chunk-pmx9760x.js → chunk-9h027f50.js} +1 -1
  39. package/bin/chunk-av71yjaa.js +1 -0
  40. package/bin/{chunk-9bpjfkjf.js → chunk-b73ktdmd.js} +1 -1
  41. package/bin/{chunk-mjncyjwf.js → chunk-b8js74jk.js} +1 -1
  42. package/bin/{chunk-861dz0bf.js → chunk-bd71dp4j.js} +1 -1
  43. package/bin/{chunk-v3j7acwn.js → chunk-bs0fjz3w.js} +2 -2
  44. package/bin/chunk-carknytp.js +1 -0
  45. package/bin/chunk-chkx04mw.js +1 -0
  46. package/bin/chunk-crt1e1w1.js +2 -0
  47. package/bin/{chunk-kj751zje.js → chunk-cxhmr356.js} +1 -1
  48. package/bin/{chunk-hcz4snm7.js → chunk-d3wmdjze.js} +1 -1
  49. package/bin/{chunk-qf7n519d.js → chunk-dgat7wqv.js} +2 -2
  50. package/bin/{chunk-dwf5e5g3.js → chunk-dghtwyq1.js} +1 -1
  51. package/bin/chunk-dm2w12rc.js +2 -0
  52. package/bin/{chunk-5k03xpzq.js → chunk-dqgv5yy1.js} +1 -1
  53. package/bin/{chunk-q72ax3m8.js → chunk-e3s3rz2e.js} +1 -1
  54. package/bin/{chunk-79n633wf.js → chunk-e52nga6c.js} +1 -1
  55. package/bin/{chunk-8abs8d48.js → chunk-e7ndw3hg.js} +2 -2
  56. package/bin/{chunk-044xt1se.js → chunk-fbte2rmd.js} +1 -1
  57. package/bin/{chunk-k1r17nfa.js → chunk-fcvtgx1y.js} +1 -1
  58. package/bin/{chunk-cpr05qng.js → chunk-fz88kkk1.js} +1 -1
  59. package/bin/{chunk-82w2419d.js → chunk-g21jxrt9.js} +2 -2
  60. package/bin/{chunk-6724dtsx.js → chunk-g8th86na.js} +1 -1
  61. package/bin/chunk-gswbc6y9.js +2 -0
  62. package/bin/{chunk-pvy0gccg.js → chunk-gtrc5ka2.js} +1 -1
  63. package/bin/{chunk-mv8c5fky.js → chunk-hkbybhww.js} +1 -1
  64. package/bin/chunk-hnhq0dh9.js +1 -0
  65. package/bin/{chunk-e3c6hyz8.js → chunk-hr97a5j5.js} +1 -1
  66. package/bin/chunk-j0c7d9y1.js +1 -0
  67. package/bin/{chunk-7h75r7ep.js → chunk-j8qtab70.js} +1 -1
  68. package/bin/chunk-jqh8kavv.js +2 -0
  69. package/bin/{chunk-1w9dnk5p.js → chunk-js9yf457.js} +1 -1
  70. package/bin/chunk-jyzegph4.js +1 -0
  71. package/bin/{chunk-azfgjqjx.js → chunk-kfhtk3eh.js} +1 -1
  72. package/bin/chunk-kr06nrbx.js +2 -0
  73. package/bin/{chunk-nceqrqey.js → chunk-m4zpf9gg.js} +1 -1
  74. package/bin/{chunk-hqptebzb.js → chunk-mnfqdxms.js} +1 -1
  75. package/bin/{chunk-1ae8csk6.js → chunk-mqjzmn0e.js} +1 -1
  76. package/bin/{chunk-sp75qe28.js → chunk-mzg1h07d.js} +1 -1
  77. package/bin/chunk-nhsqp8jc.js +2 -0
  78. package/bin/chunk-nnkkem25.js +3 -0
  79. package/bin/{chunk-cj5qwc9c.js → chunk-nrwna4ha.js} +1 -1
  80. package/bin/chunk-nyhqy6q2.js +62 -0
  81. package/bin/{chunk-2djd6pq1.js → chunk-qksb0v3c.js} +2 -2
  82. package/bin/{chunk-wfex9jw0.js → chunk-qwg2e3wr.js} +6 -6
  83. package/bin/{chunk-2dz8nn9v.js → chunk-re0b7sj7.js} +1 -1
  84. package/bin/{chunk-x9q2vzn8.js → chunk-rtngbgpk.js} +1 -1
  85. package/bin/{chunk-k5bekrrp.js → chunk-s46zwr4p.js} +1 -1
  86. package/bin/chunk-s8t74q9m.js +1 -0
  87. package/bin/chunk-se8rgwp8.js +1 -0
  88. package/bin/{chunk-v98yavtp.js → chunk-srn8t0v7.js} +1 -1
  89. package/bin/{chunk-46c5xkmn.js → chunk-t3t6021k.js} +1 -1
  90. package/bin/{chunk-jbde7evp.js → chunk-thsbcbay.js} +1 -1
  91. package/bin/chunk-tm6z4hkd.css +1 -0
  92. package/bin/{chunk-v05d1aeq.js → chunk-w7dn1m95.js} +1 -1
  93. package/bin/{chunk-w1d5vmtc.js → chunk-wc8sc9r9.js} +1 -1
  94. package/bin/chunk-wckjyvtb.js +5 -0
  95. package/bin/{chunk-p3emandj.js → chunk-wfx81mfv.js} +2 -2
  96. package/bin/chunk-wsyg4rwg.js +2 -0
  97. package/bin/chunk-wtjc4565.js +1 -0
  98. package/bin/{chunk-ga3mh3cd.js → chunk-xcwbg4w9.js} +1 -1
  99. package/bin/chunk-y79r28gd.js +1 -0
  100. package/bin/{chunk-ngd23mtc.js → chunk-ybhgmvxa.js} +1 -1
  101. package/bin/{chunk-phw4ne8b.js → chunk-ygz6pawn.js} +1 -1
  102. package/bin/{chunk-m11g9hx7.js → chunk-yj4x7tpw.js} +2 -2
  103. package/bin/{chunk-hy50c4pw.js → chunk-ymeycphq.js} +2 -2
  104. package/bin/{chunk-c1v946wb.js → chunk-zemrvz79.js} +2 -2
  105. package/bin/{chunk-29pkpmvy.js → chunk-zzx99j8t.js} +1 -1
  106. package/bin/shumai-app.html +1 -1
  107. package/bin/shumai-app.js +248 -224
  108. package/package.json +8 -8
  109. package/prisma/migrations/20260723025234_add_ai_usage_table/migration.sql +28 -0
  110. package/prisma/migrations/20260723032755_add_ai_usage_unique_constraint/migration.sql +8 -0
  111. package/prisma/schema.prisma +25 -0
  112. package/bin/chunk-211y81mp.js +0 -1
  113. package/bin/chunk-25d1g086.js +0 -2
  114. package/bin/chunk-4fnak2zn.js +0 -2
  115. package/bin/chunk-4zq8vxcy.css +0 -1
  116. package/bin/chunk-50ebjdkv.js +0 -2
  117. package/bin/chunk-5j7axztv.js +0 -2
  118. package/bin/chunk-6h4ay2p8.js +0 -2
  119. package/bin/chunk-6w5cn6p3.js +0 -3
  120. package/bin/chunk-75jka5v9.js +0 -5
  121. package/bin/chunk-99db4j0k.js +0 -3
  122. package/bin/chunk-9evm8x70.js +0 -1
  123. package/bin/chunk-bepnbw1g.js +0 -2
  124. package/bin/chunk-bg24g9kk.js +0 -1
  125. package/bin/chunk-dqtq9t8e.js +0 -1
  126. package/bin/chunk-fgnxtqtk.js +0 -1
  127. package/bin/chunk-fxvb6g2r.js +0 -1
  128. package/bin/chunk-kjkmh26f.js +0 -1
  129. package/bin/chunk-m3dwydr3.js +0 -2
  130. package/bin/chunk-mk1jewvw.js +0 -2
  131. package/bin/chunk-q9sgjs4d.js +0 -1
  132. package/bin/chunk-s2725w64.js +0 -1
  133. package/bin/chunk-saq5797j.js +0 -1
  134. package/bin/chunk-sy8rqacm.js +0 -2
  135. package/bin/chunk-t84t3v6q.js +0 -1
  136. package/bin/chunk-ttsqdsxr.js +0 -2
  137. package/bin/chunk-vreq89j6.js +0 -1
  138. package/bin/chunk-wbhsmhgp.js +0 -2
  139. package/bin/chunk-wf4d1anc.js +0 -62
  140. package/bin/chunk-xv4mfppt.js +0 -2
@@ -1,3 +1,3 @@
1
1
  // @bun
2
2
  function L(G,q,D){return{temperature:q?.temperature,maxTokens:q?.maxTokens,signal:q?.signal,apiKey:D||q?.apiKey,transport:q?.transport,cacheRetention:q?.cacheRetention,sessionId:q?.sessionId,headers:q?.headers,onPayload:q?.onPayload,onResponse:q?.onResponse,timeoutMs:q?.timeoutMs,websocketConnectTimeoutMs:q?.websocketConnectTimeoutMs,maxRetries:q?.maxRetries,maxRetryDelayMs:q?.maxRetryDelayMs,metadata:q?.metadata}}function K(G){return G==="xhigh"?"high":G}function y(G,q,D,N){let _={...{minimal:1024,low:2048,medium:8192,high:16384},...N},O=1024,V=K(D),J=_[V],Q=G===void 0?q:Math.min(G+J,q);if(Q<=J)J=Math.max(0,Q-1024);return{maxTokens:Q,thinkingBudget:J}}function j(G,q){let D=[],N=!1;for(let Y of G){if(Y.type==="image"){if(!N)D.push({type:"text",text:q});N=!0;continue}D.push(Y),N=Y.text===q}return D}function U(G,q){if(q.input.includes("image"))return G;return G.map((D)=>{if(D.role==="user"&&Array.isArray(D.content))return{...D,content:j(D.content,"(image omitted: model does not support images)")};if(D.role==="toolResult")return{...D,content:j(D.content,"(tool image omitted: model does not support images)")};return D})}function W(G,q,D){let N=new Map,_=U(G,q).map((E)=>{if(E.role==="user")return E;if(E.role==="toolResult"){let A=N.get(E.toolCallId);if(A&&A!==E.toolCallId)return{...E,toolCallId:A};return E}if(E.role==="assistant"){let A=E,H=A.provider===q.provider&&A.api===q.api&&A.model===q.id,$=A.content.flatMap((F)=>{if(F.type==="thinking"){if(F.redacted)return H?F:[];if(H&&F.thinkingSignature)return F;if(!F.thinking||F.thinking.trim()==="")return[];if(H)return F;return{type:"text",text:F.thinking}}if(F.type==="text"){if(H)return F;return{type:"text",text:F.text}}if(F.type==="toolCall"){let X=F,Z=X;if(!H&&X.thoughtSignature)Z={...X},delete Z.thoughtSignature;if(!H&&D){let w=D(X.id,q,A);if(w!==X.id)N.set(X.id,w),Z={...Z,id:w}}return Z}return F});return{...A,content:$}}return E}),O=[],V=[],J=new Set,Q=()=>{if(V.length>0){for(let E of V)if(!J.has(E.id))O.push({role:"toolResult",toolCallId:E.id,toolName:E.name,content:[{type:"text",text:"No result provided"}],isError:!0,timestamp:Date.now()});V=[],J=new Set}};for(let E=0;E<_.length;E++){let A=_[E];if(A.role==="assistant"){Q();let H=A;if(H.stopReason==="error"||H.stopReason==="aborted")continue;let $=H.content.filter((F)=>F.type==="toolCall");if($.length>0)V=$,J=new Set;O.push(A)}else if(A.role==="toolResult")J.add(A.toolCallId),O.push(A);else if(A.role==="user")Q(),O.push(A);else O.push(A)}return Q(),O}
3
- export{L as Ik,y as Jk,W as Kk};
3
+ export{L as Ok,y as Pk,W as Qk};
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{Sb as m,Tb as c}from"./chunk-7we7ex0m.js";import{Yb as s}from"./chunk-s1n39qte.js";import{Zb as d}from"./chunk-mwh2n8yt.js";import{ec as l,fc as a}from"./chunk-w88219ex.js";import{hc as i,jc as n}from"./chunk-2dsmsa6a.js";import{kc as w}from"./chunk-ta7bfdrn.js";import{lc as p}from"./chunk-pxw97qbq.js";import{Xe as T}from"./chunk-ngd23mtc.js";import{$e as g,af as r}from"./chunk-q09dfja5.js";import{bf as k}from"./chunk-d2vxmn9v.js";import{rk as h}from"./chunk-dzm2f82x.js";import"./chunk-v3j7acwn.js";import"./chunk-976v5s8y.js";function C(J,X){if(!J)return!1;let Q=X.toLowerCase();for(let[Y,_]of Object.entries(J))if(Y.toLowerCase()===Q&&_!==null&&_.trim().length>0)return!0;return!1}function t(J,X,Q){if(X)return X;if(C(Q,"authorization")||C(Q,"cf-aig-authorization"))return"unused";throw Error(`No API key for provider: ${J}`)}function $J(J){for(let X of J){if(X.role==="toolResult")return!0;if(X.role==="assistant"){if(X.content.some((Q)=>Q.type==="toolCall"))return!0}}return!1}function u(J){return J.type==="text"}function qJ(J){return J.type==="thinking"}function ZJ(J){return J.type==="toolCall"}function KJ(J){return J.type==="image"}function jJ(J){if(typeof J!=="object"||J===null)return!1;let X=J;return X.type==="reasoning.encrypted"&&typeof X.id==="string"&&X.id.length>0&&typeof X.data==="string"&&X.data.length>0}function e(J,X){if(J)return J;if(d("PI_CACHE_RETENTION",X)==="long")return"long";return"short"}var zJ=(J,X,Q)=>{let Y=new k;return(async()=>{let _={role:"assistant",content:[],api:J.api,provider:J.provider,model:J.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:"stop",timestamp:Date.now()};try{let H=t(J.provider,Q?.apiKey,Q?.headers),K=f(J),$=e(Q?.cacheRetention,Q?.env),q=$==="none"?void 0:Q?.sessionId,j=HJ(J,X,H,Q?.headers,q,K),V=LJ(J,X,Q,K,$),O=await Q?.onPayload?.(V,J);if(O!==void 0)V=O;let P={...Q?.signal?{signal:Q.signal}:{},...Q?.timeoutMs!==void 0?{timeout:Q.timeoutMs}:{},maxRetries:Q?.maxRetries??0},{data:A,response:F}=await j.chat.completions.create(V,P).withResponse();await Q?.onResponse?.({status:F.status,headers:p(F.headers)},J),Y.push({type:"start",partial:_});let E=null,L=null,G=!1,v=new Map,U=new Map,I=new Map,B=_.content,y=(Z)=>B.indexOf(Z),JJ=(Z)=>{let z=y(Z);if(z===-1)return;if(Z.type==="text")Y.push({type:"text_end",contentIndex:z,content:Z.text,partial:_});else if(Z.type==="thinking")Y.push({type:"thinking_end",contentIndex:z,content:Z.thinking,partial:_});else if(Z.type==="toolCall")Z.arguments=T(Z.partialArgs),delete Z.partialArgs,delete Z.streamIndex,Y.push({type:"toolcall_end",contentIndex:z,toolCall:Z,partial:_})},QJ=()=>{if(!E)E={type:"text",text:""},B.push(E),Y.push({type:"text_start",contentIndex:y(E),partial:_});return E},XJ=(Z)=>{if(!L)L={type:"thinking",thinking:"",thinkingSignature:Z},B.push(L),Y.push({type:"thinking_start",contentIndex:y(L),partial:_});return L},YJ=(Z)=>{if(!Z.id)return;let z=I.get(Z.id);if(z)Z.thoughtSignature=z,I.delete(Z.id)},_J=(Z)=>{let z=typeof Z.index==="number"?Z.index:void 0,N=z!==void 0?v.get(z):void 0;if(!N&&Z.id)N=U.get(Z.id);if(!N){if(N={type:"toolCall",id:Z.id||"",name:Z.function?.name||"",arguments:{},partialArgs:"",streamIndex:z},z!==void 0)v.set(z,N);if(Z.id)U.set(Z.id,N);B.push(N),Y.push({type:"toolcall_start",contentIndex:y(N),partial:_})}if(z!==void 0&&N.streamIndex===void 0)N.streamIndex=z,v.set(z,N);if(Z.id)U.set(Z.id,N);return YJ(N),N};for await(let Z of A){if(!Z||typeof Z!=="object")continue;if(_.responseId||=Z.id,typeof Z.model==="string"&&Z.model.length>0&&Z.model!==J.id)_.responseModel||=Z.model;if(Z.usage)_.usage=b(Z.usage,J);let z=Array.isArray(Z.choices)?Z.choices[0]:void 0;if(!z)continue;if(!Z.usage&&z.usage)_.usage=b(z.usage,J);if(z.finish_reason){let N=yJ(z.finish_reason);if(_.stopReason=N.stopReason,N.errorMessage)_.errorMessage=N.errorMessage;G=!0}if(z.delta){if(z.delta.content!==null&&z.delta.content!==void 0&&z.delta.content.length>0){let W=QJ();W.text+=z.delta.content,Y.push({type:"text_delta",contentIndex:y(W),delta:z.delta.content,partial:_})}let N=["reasoning_content","reasoning","reasoning_text"],R=z.delta,M=null;for(let W of N){let S=R[W];if(typeof S==="string"&&S.length>0){M=W;break}}if(M){let W=R[M];if(typeof W==="string"&&W.length>0){let S=J.provider==="opencode-go"&&M==="reasoning"?"reasoning_content":M,D=XJ(S);D.thinking+=W,Y.push({type:"thinking_delta",contentIndex:y(D),delta:W,partial:_})}}if(z?.delta?.tool_calls)for(let W of z.delta.tool_calls){let S=_J(W);if(!S.id&&W.id)S.id=W.id,U.set(W.id,S);if(!S.name&&W.function?.name)S.name=W.function.name;let D="";if(W.function?.arguments)D=W.function.arguments,S.partialArgs=(S.partialArgs??"")+W.function.arguments,S.arguments=T(S.partialArgs);Y.push({type:"toolcall_delta",contentIndex:y(S),delta:D,partial:_})}let x=z.delta.reasoning_details;if(Array.isArray(x)){for(let W of x)if(jJ(W)){let S=JSON.stringify(W),D=U.get(W.id);if(D)D.thoughtSignature=S;else I.set(W.id,S)}}}}for(let Z of B)JJ(Z);if(Q?.signal?.aborted)throw Error("Request was aborted");if(_.stopReason==="aborted")throw Error("Request was aborted");if(_.stopReason==="error")throw Error(_.errorMessage||"Provider returned an error stop reason");if(!G)throw Error("Stream ended without finish_reason");Y.push({type:"done",reason:_.stopReason,message:_}),Y.end()}catch(H){for(let $ of _.content)delete $.index,delete $.partialArgs,delete $.streamIndex;_.stopReason=Q?.signal?.aborted?"aborted":"error",_.errorMessage=a(l(H));let K=H?.error?.metadata?.raw;if(K&&!_.errorMessage.includes(String(K)))_.errorMessage+=`
2
+ import{Sb as m,Tb as c}from"./chunk-7we7ex0m.js";import{Yb as s}from"./chunk-s1n39qte.js";import{Zb as d}from"./chunk-9avkn3x1.js";import{ec as l,fc as a}from"./chunk-w88219ex.js";import{hc as i,jc as n}from"./chunk-2dsmsa6a.js";import{kc as w}from"./chunk-ta7bfdrn.js";import{lc as p}from"./chunk-pxw97qbq.js";import{Xe as T}from"./chunk-ybhgmvxa.js";import{$e as g,af as r}from"./chunk-q09dfja5.js";import{bf as k}from"./chunk-d2vxmn9v.js";import{xk as h}from"./chunk-9ab6k4rq.js";import"./chunk-bs0fjz3w.js";import"./chunk-0qkj838r.js";function C(J,X){if(!J)return!1;let Q=X.toLowerCase();for(let[Y,_]of Object.entries(J))if(Y.toLowerCase()===Q&&_!==null&&_.trim().length>0)return!0;return!1}function t(J,X,Q){if(X)return X;if(C(Q,"authorization")||C(Q,"cf-aig-authorization"))return"unused";throw Error(`No API key for provider: ${J}`)}function $J(J){for(let X of J){if(X.role==="toolResult")return!0;if(X.role==="assistant"){if(X.content.some((Q)=>Q.type==="toolCall"))return!0}}return!1}function u(J){return J.type==="text"}function qJ(J){return J.type==="thinking"}function ZJ(J){return J.type==="toolCall"}function KJ(J){return J.type==="image"}function jJ(J){if(typeof J!=="object"||J===null)return!1;let X=J;return X.type==="reasoning.encrypted"&&typeof X.id==="string"&&X.id.length>0&&typeof X.data==="string"&&X.data.length>0}function e(J,X){if(J)return J;if(d("PI_CACHE_RETENTION",X)==="long")return"long";return"short"}var zJ=(J,X,Q)=>{let Y=new k;return(async()=>{let _={role:"assistant",content:[],api:J.api,provider:J.provider,model:J.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:"stop",timestamp:Date.now()};try{let H=t(J.provider,Q?.apiKey,Q?.headers),K=f(J),$=e(Q?.cacheRetention,Q?.env),q=$==="none"?void 0:Q?.sessionId,j=HJ(J,X,H,Q?.headers,q,K),V=LJ(J,X,Q,K,$),O=await Q?.onPayload?.(V,J);if(O!==void 0)V=O;let P={...Q?.signal?{signal:Q.signal}:{},...Q?.timeoutMs!==void 0?{timeout:Q.timeoutMs}:{},maxRetries:Q?.maxRetries??0},{data:A,response:F}=await j.chat.completions.create(V,P).withResponse();await Q?.onResponse?.({status:F.status,headers:p(F.headers)},J),Y.push({type:"start",partial:_});let E=null,L=null,G=!1,v=new Map,U=new Map,I=new Map,B=_.content,y=(Z)=>B.indexOf(Z),JJ=(Z)=>{let z=y(Z);if(z===-1)return;if(Z.type==="text")Y.push({type:"text_end",contentIndex:z,content:Z.text,partial:_});else if(Z.type==="thinking")Y.push({type:"thinking_end",contentIndex:z,content:Z.thinking,partial:_});else if(Z.type==="toolCall")Z.arguments=T(Z.partialArgs),delete Z.partialArgs,delete Z.streamIndex,Y.push({type:"toolcall_end",contentIndex:z,toolCall:Z,partial:_})},QJ=()=>{if(!E)E={type:"text",text:""},B.push(E),Y.push({type:"text_start",contentIndex:y(E),partial:_});return E},XJ=(Z)=>{if(!L)L={type:"thinking",thinking:"",thinkingSignature:Z},B.push(L),Y.push({type:"thinking_start",contentIndex:y(L),partial:_});return L},YJ=(Z)=>{if(!Z.id)return;let z=I.get(Z.id);if(z)Z.thoughtSignature=z,I.delete(Z.id)},_J=(Z)=>{let z=typeof Z.index==="number"?Z.index:void 0,N=z!==void 0?v.get(z):void 0;if(!N&&Z.id)N=U.get(Z.id);if(!N){if(N={type:"toolCall",id:Z.id||"",name:Z.function?.name||"",arguments:{},partialArgs:"",streamIndex:z},z!==void 0)v.set(z,N);if(Z.id)U.set(Z.id,N);B.push(N),Y.push({type:"toolcall_start",contentIndex:y(N),partial:_})}if(z!==void 0&&N.streamIndex===void 0)N.streamIndex=z,v.set(z,N);if(Z.id)U.set(Z.id,N);return YJ(N),N};for await(let Z of A){if(!Z||typeof Z!=="object")continue;if(_.responseId||=Z.id,typeof Z.model==="string"&&Z.model.length>0&&Z.model!==J.id)_.responseModel||=Z.model;if(Z.usage)_.usage=b(Z.usage,J);let z=Array.isArray(Z.choices)?Z.choices[0]:void 0;if(!z)continue;if(!Z.usage&&z.usage)_.usage=b(z.usage,J);if(z.finish_reason){let N=yJ(z.finish_reason);if(_.stopReason=N.stopReason,N.errorMessage)_.errorMessage=N.errorMessage;G=!0}if(z.delta){if(z.delta.content!==null&&z.delta.content!==void 0&&z.delta.content.length>0){let W=QJ();W.text+=z.delta.content,Y.push({type:"text_delta",contentIndex:y(W),delta:z.delta.content,partial:_})}let N=["reasoning_content","reasoning","reasoning_text"],R=z.delta,M=null;for(let W of N){let S=R[W];if(typeof S==="string"&&S.length>0){M=W;break}}if(M){let W=R[M];if(typeof W==="string"&&W.length>0){let S=J.provider==="opencode-go"&&M==="reasoning"?"reasoning_content":M,D=XJ(S);D.thinking+=W,Y.push({type:"thinking_delta",contentIndex:y(D),delta:W,partial:_})}}if(z?.delta?.tool_calls)for(let W of z.delta.tool_calls){let S=_J(W);if(!S.id&&W.id)S.id=W.id,U.set(W.id,S);if(!S.name&&W.function?.name)S.name=W.function.name;let D="";if(W.function?.arguments)D=W.function.arguments,S.partialArgs=(S.partialArgs??"")+W.function.arguments,S.arguments=T(S.partialArgs);Y.push({type:"toolcall_delta",contentIndex:y(S),delta:D,partial:_})}let x=z.delta.reasoning_details;if(Array.isArray(x)){for(let W of x)if(jJ(W)){let S=JSON.stringify(W),D=U.get(W.id);if(D)D.thoughtSignature=S;else I.set(W.id,S)}}}}for(let Z of B)JJ(Z);if(Q?.signal?.aborted)throw Error("Request was aborted");if(_.stopReason==="aborted")throw Error("Request was aborted");if(_.stopReason==="error")throw Error(_.errorMessage||"Provider returned an error stop reason");if(!G)throw Error("Stream ended without finish_reason");Y.push({type:"done",reason:_.stopReason,message:_}),Y.end()}catch(H){for(let $ of _.content)delete $.index,delete $.partialArgs,delete $.streamIndex;_.stopReason=Q?.signal?.aborted?"aborted":"error",_.errorMessage=a(l(H));let K=H?.error?.metadata?.raw;if(K&&!_.errorMessage.includes(String(K)))_.errorMessage+=`
3
3
  ${K}`;Y.push({type:"error",reason:_.stopReason,error:_}),Y.end()}})(),Y},hJ=(J,X,Q)=>{t(J.provider,Q?.apiKey,Q?.headers);let Y=i(J,X,Q,Q?.apiKey),_=Q?.reasoning?r(J,Q.reasoning):void 0,H=_==="off"?void 0:_,K=Q?.toolChoice;return zJ(J,X,{...Y,reasoningEffort:H,toolChoice:K})};function HJ(J,X,Q,Y,_,H=f(J)){let K={...J.headers};if(J.provider==="github-copilot"){let $=m(X.messages),q=c({messages:X.messages,hasImages:$});Object.assign(K,q)}if(_&&H.sendSessionAffinityHeaders)if(H.sessionAffinityFormat==="openrouter")K["x-session-id"]=_;else{if(H.sessionAffinityFormat==="openai")K.session_id=_;K["x-client-request-id"]=_,K["x-session-affinity"]=_}if(Y)Object.assign(K,Y);return new h({apiKey:Q,baseURL:J.baseUrl,dangerouslyAllowBrowser:!0,defaultHeaders:K})}function LJ(J,X,Q,Y=f(J),_=e(Q?.cacheRetention,Q?.env)){let H=EJ(J,X,Y),K=GJ(Y,_),$={model:J.id,messages:H,stream:!0,prompt_cache_key:J.baseUrl.includes("api.openai.com")&&_!=="none"||_==="long"&&Y.supportsLongCacheRetention?s(Q?.sessionId):void 0,prompt_cache_retention:_==="long"&&Y.supportsLongCacheRetention?"24h":void 0};if(Y.supportsUsageInStreaming!==!1)$.stream_options={include_usage:!0};if(Y.supportsStore)$.store=!1;if(Q?.maxTokens)if(Y.maxTokensField==="max_tokens")$.max_tokens=Q.maxTokens;else $.max_completion_tokens=Q.maxTokens;if(Q?.temperature!==void 0)$.temperature=Q.temperature;if(X.tools&&X.tools.length>0){if($.tools=DJ(X.tools,Y),Y.zaiToolStream)$.tool_stream=!0}else if($J(X.messages))$.tools=[];if(K)NJ(H,$.tools,K);if(Q?.toolChoice)$.tool_choice=Q.toolChoice;if(Y.thinkingFormat==="zai"&&J.reasoning){let q=$;if(q.thinking=Q?.reasoningEffort?{type:"enabled",clear_thinking:!1}:{type:"disabled"},Q?.reasoningEffort&&Y.supportsReasoningEffort){let j=J.thinkingLevelMap?.[Q.reasoningEffort],V=j===void 0?Q.reasoningEffort:j;if(typeof V==="string")q.reasoning_effort=V}}else if(Y.thinkingFormat==="qwen"&&J.reasoning)$.enable_thinking=!!Q?.reasoningEffort;else if(Y.thinkingFormat==="qwen-chat-template"&&J.reasoning)$.chat_template_kwargs={enable_thinking:!!Q?.reasoningEffort,preserve_thinking:!0};else if(Y.thinkingFormat==="chat-template"&&J.reasoning){let q=VJ(J,Q,Y);if(q)$.chat_template_kwargs=q}else if(Y.thinkingFormat==="deepseek"&&J.reasoning){if(Q?.reasoningEffort)$.thinking={type:"enabled"};else if(J.thinkingLevelMap?.off!==null)$.thinking={type:"disabled"};if(Q?.reasoningEffort&&Y.supportsReasoningEffort)$.reasoning_effort=J.thinkingLevelMap?.[Q.reasoningEffort]??Q.reasoningEffort}else if(Y.thinkingFormat==="openrouter"&&J.reasoning){let q=$;if(Q?.reasoningEffort)q.reasoning={effort:J.thinkingLevelMap?.[Q.reasoningEffort]??Q.reasoningEffort};else if(J.thinkingLevelMap?.off!==null)q.reasoning={effort:J.thinkingLevelMap?.off??"none"}}else if(Y.thinkingFormat==="ant-ling"&&J.reasoning&&Q?.reasoningEffort){let q=J.thinkingLevelMap?.[Q.reasoningEffort];if(typeof q==="string")$.reasoning={effort:q}}else if(Y.thinkingFormat==="together"&&J.reasoning){let q=$;if(q.reasoning={enabled:!!Q?.reasoningEffort},Q?.reasoningEffort&&Y.supportsReasoningEffort)q.reasoning_effort=J.thinkingLevelMap?.[Q.reasoningEffort]??Q.reasoningEffort}else if(Y.thinkingFormat==="string-thinking"&&J.reasoning){let q=$;if(Q?.reasoningEffort)q.thinking=J.thinkingLevelMap?.[Q.reasoningEffort]??Q.reasoningEffort;else if(J.thinkingLevelMap?.off!==null)q.thinking=J.thinkingLevelMap?.off??"none"}else if(Q?.reasoningEffort&&J.reasoning&&Y.supportsReasoningEffort)$.reasoning_effort=J.thinkingLevelMap?.[Q.reasoningEffort]??Q.reasoningEffort;else if(!Q?.reasoningEffort&&J.reasoning&&Y.supportsReasoningEffort){let q=J.thinkingLevelMap?.off;if(typeof q==="string")$.reasoning_effort=q}if(J.compat?.openRouterRouting)$.provider=J.compat.openRouterRouting;if(J.compat?.vercelGatewayRouting){let q=J.compat.vercelGatewayRouting;if(q.only||q.order){let j={};if(q.only)j.only=q.only;if(q.order)j.order=q.order;$.providerOptions={gateway:j}}}return $}function VJ(J,X,Q){let Y={};for(let[_,H]of Object.entries(Q.chatTemplateKwargs)){let K=WJ(J,X,H);if(K!==void 0)Y[_]=K}return Object.keys(Y).length>0?Y:void 0}function WJ(J,X,Q){if(typeof Q!=="object"||Q===null)return Q;let Y=X?.reasoningEffort;if(!Y&&Q.omitWhenOff)return;if(Q.$var==="thinking.enabled")return!!Y;let _=Y?J.thinkingLevelMap?.[Y]:J.thinkingLevelMap?.off;return _===void 0?Y:typeof _==="string"?_:void 0}function GJ(J,X){if(J.cacheControlFormat!=="anthropic"||X==="none")return;let Q=X==="long"&&J.supportsLongCacheRetention?"1h":void 0;return{type:"ephemeral",...Q?{ttl:Q}:{}}}function NJ(J,X,Q){SJ(J,Q),FJ(X,Q),OJ(J,Q)}function SJ(J,X){for(let Q of J)if(Q.role==="system"||Q.role==="developer"){PJ(Q,X);return}}function OJ(J,X){for(let Q=J.length-1;Q>=0;Q--){let Y=J[Q];if(Y.role==="user"||Y.role==="assistant"){if(AJ(Y,X))return}}}function FJ(J,X){if(!J||J.length===0)return;let Q=J[J.length-1];Q.cache_control=X}function PJ(J,X){return o(J,X)}function AJ(J,X){if(J.role==="user"||J.role==="assistant")return o(J,X);return!1}function o(J,X){let Q=J.content;if(typeof Q==="string"){if(Q.length===0)return!1;return J.content=[{type:"text",text:Q,cache_control:X}],!0}if(!Array.isArray(Q))return!1;for(let Y=Q.length-1;Y>=0;Y--){let _=Q[Y];if(_?.type==="text"){let H=_;return H.cache_control=X,!0}}return!1}function EJ(J,X,Q){let Y=[],_=($)=>{if($.includes("|")){let[q]=$.split("|");return q.replace(/[^a-zA-Z0-9_-]/g,"_").slice(0,40)}if(J.provider==="openai")return $.length>40?$.slice(0,40):$;return $},H=n(X.messages,J,($)=>_($));if(X.systemPrompt){let q=J.reasoning&&Q.supportsDeveloperRole?"developer":"system";Y.push({role:q,content:w(X.systemPrompt)})}let K=null;for(let $=0;$<H.length;$++){let q=H[$];if(Q.requiresAssistantAfterToolResult&&K==="toolResult"&&q.role==="user")Y.push({role:"assistant",content:"I have processed the tool results."});if(q.role==="user")if(typeof q.content==="string")Y.push({role:"user",content:w(q.content)});else{let j=q.content.map((V)=>{if(V.type==="text")return{type:"text",text:w(V.text)};else return{type:"image_url",image_url:{url:`data:${V.mimeType};base64,${V.data}`}}});if(j.length===0)continue;Y.push({role:"user",content:j})}else if(q.role==="assistant"){let j={role:"assistant",content:Q.requiresAssistantAfterToolResult?"":null},V=q.content.filter(u).filter((L)=>L.text.trim().length>0).map((L)=>({type:"text",text:w(L.text)})),O=V.map((L)=>L.text).join(""),P=q.content.filter(qJ).filter((L)=>L.thinking.trim().length>0);if(P.length>0)if(Q.requiresThinkingAsText){let L=P.map((G)=>w(G.thinking)).join(`
4
4
 
5
5
  `);j.content=[{type:"text",text:L},...V]}else{if(O.length>0)j.content=O;let L=P[0].thinkingSignature;if(J.provider==="opencode-go"&&L==="reasoning")L="reasoning_content";if(L&&L.length>0)j[L]=P.map((G)=>G.thinking).join(`
@@ -38,4 +38,4 @@ If you understand the risks and have appropriate mitigations in place,
38
38
  you can set the \`dangerouslyAllowBrowser\` option to \`true\`, e.g.,
39
39
 
40
40
  new Anthropic({ apiKey, dangerouslyAllowBrowser: true });
41
- `);this.baseURL=W.baseURL,this.timeout=W.timeout??C0.DEFAULT_TIMEOUT,this.logger=W.logger??console;let J="warn";this.logLevel=J,this.logLevel=iZ(W.logLevel,"ClientOptions.logLevel",this)??iZ(GZ("ANTHROPIC_LOG"),"process.env['ANTHROPIC_LOG']",this)??J,this.fetchOptions=W.fetchOptions,this.maxRetries=W.maxRetries??2,this.fetch=W.fetch??D0(),G(this,vZ,P0,"f"),this._options=W,this.apiKey=typeof Z==="string"?Z:null,this.authToken=$}withOptions(X){return new this.constructor({...this._options,baseURL:this.baseURL,maxRetries:this.maxRetries,timeout:this.timeout,logger:this.logger,logLevel:this.logLevel,fetch:this.fetch,fetchOptions:this.fetchOptions,apiKey:this.apiKey,authToken:this.authToken,...X})}defaultQuery(){return this._options.defaultQuery}validateHeaders({values:X,nulls:Z}){if(X.get("x-api-key")||X.get("authorization"))return;if(this.apiKey&&X.get("x-api-key"))return;if(Z.has("x-api-key"))return;if(this.authToken&&X.get("authorization"))return;if(Z.has("authorization"))return;throw Error('Could not resolve authentication method. Expected either apiKey or authToken to be set. Or for one of the "X-Api-Key" or "Authorization" headers to be explicitly omitted')}async authHeaders(X){return w([await this.apiKeyAuth(X),await this.bearerAuth(X)])}async apiKeyAuth(X){if(this.apiKey==null)return;return w([{"X-Api-Key":this.apiKey}])}async bearerAuth(X){if(this.authToken==null)return;return w([{Authorization:`Bearer ${this.authToken}`}])}stringifyQuery(X){return k0(X)}getUserAgent(){return`${this.constructor.name}/JS ${m}`}defaultIdempotencyKey(){return`stainless-node-retry-${cZ()}`}makeStatusError(X,Z,$,z){return A.generate(X,Z,$,z)}buildURL(X,Z,$){let z=!Y(this,U0,"m",Q1).call(this)&&$||this.baseURL,W=E0(X)?new URL(X):new URL(z+(z.endsWith("/")&&X.startsWith("/")?X.slice(1):X)),J=this.defaultQuery(),Q=Object.fromEntries(W.searchParams);if(!uZ(J)||!uZ(Q))Z={...Q,...J,...Z};if(typeof Z==="object"&&Z&&!Array.isArray(Z))W.search=this.stringifyQuery(Z);return W.toString()}_calculateNonstreamingTimeout(X){if(3600*X/128000>600)throw new N("Streaming is required for operations that may take longer than 10 minutes. See https://github.com/anthropics/anthropic-sdk-typescript#streaming-responses for more details");return 600000}async prepareOptions(X){}async prepareRequest(X,{url:Z,options:$}){}get(X,Z){return this.methodRequest("get",X,Z)}post(X,Z){return this.methodRequest("post",X,Z)}patch(X,Z){return this.methodRequest("patch",X,Z)}put(X,Z){return this.methodRequest("put",X,Z)}delete(X,Z){return this.methodRequest("delete",X,Z)}methodRequest(X,Z,$){return this.request(Promise.resolve($).then((z)=>{return{method:X,path:Z,...z}}))}request(X,Z=null){return new r(this,this.makeRequest(X,Z,void 0))}async makeRequest(X,Z,$){let z=await X,W=z.maxRetries??this.maxRetries;if(Z==null)Z=W;await this.prepareOptions(z);let{req:J,url:Q,timeout:K}=await this.buildRequest(z,{retryCount:W-Z});await this.prepareRequest(J,{url:Q,options:z});let x="log_"+(Math.random()*16777216|0).toString(16).padStart(6,"0"),E=$===void 0?"":`, retryOf: ${$}`,O=Date.now();if(T(this).debug(`[${x}] sending request`,g({retryOfRequestLogID:$,method:z.method,url:Q,options:z,headers:J.headers})),z.signal?.aborted)throw new L;let k=new AbortController,C=await this.fetchWithTimeout(Q,J,K,k).catch(MX),F=Date.now();if(C instanceof globalThis.Error){let h=`retrying, ${Z} attempts remaining`;if(z.signal?.aborted)throw new L;let _=b(C)||/timed? ?out/i.test(String(C)+("cause"in C?String(C.cause):""));if(Z)return T(this).info(`[${x}] connection ${_?"timed out":"failed"} - ${h}`),T(this).debug(`[${x}] connection ${_?"timed out":"failed"} (${h})`,g({retryOfRequestLogID:$,url:Q,durationMs:F-O,message:C.message})),this.retryRequest(z,Z,$??x);if(T(this).info(`[${x}] connection ${_?"timed out":"failed"} - error; no more retries left`),T(this).debug(`[${x}] connection ${_?"timed out":"failed"} (error; no more retries left)`,g({retryOfRequestLogID:$,url:Q,durationMs:F-O,message:C.message})),_)throw new EX;throw new o({cause:C})}let a=[...C.headers.entries()].filter(([h])=>h==="request-id").map(([h,_])=>", "+h+": "+JSON.stringify(_)).join(""),OX=`[${x}${E}${a}] ${J.method} ${Q} ${C.ok?"succeeded":"failed"} with status ${C.status} in ${F-O}ms`;if(!C.ok){let h=await this.shouldRetry(C);if(Z&&h){let NZ=`retrying, ${Z} attempts remaining`;return await f0(C.body),T(this).info(`${OX} - ${NZ}`),T(this).debug(`[${x}] response error (${NZ})`,g({retryOfRequestLogID:$,url:C.url,status:C.status,headers:C.headers,durationMs:F-O})),this.retryRequest(z,Z,$??x,C.headers)}let _=h?"error; no more retries left":"error; not retryable";T(this).info(`${OX} - ${_}`);let q0=await C.text().catch((NZ)=>MX(NZ).message),O0=UZ(q0),M0=O0?void 0:q0;throw T(this).debug(`[${x}] response error (${_})`,g({retryOfRequestLogID:$,url:C.url,status:C.status,headers:C.headers,message:M0,durationMs:Date.now()-O})),this.makeStatusError(C.status,O0,M0,C.headers)}return T(this).info(OX),T(this).debug(`[${x}] response start`,g({retryOfRequestLogID:$,url:C.url,status:C.status,headers:C.headers,durationMs:F-O})),{response:C,options:z,controller:k,requestLogID:x,retryOfRequestLogID:$,startTime:O}}getAPIList(X,Z,$){return this.requestAPIList(Z,$&&"then"in $?$.then((z)=>({method:"get",path:X,...z})):{method:"get",path:X,...$})}requestAPIList(X,Z){let $=this.makeRequest(Z,null,void 0);return new AZ(this,$,X)}async fetchWithTimeout(X,Z,$,z){let{signal:W,method:J,...Q}=Z||{},K=this._makeAbort(z);if(W)W.addEventListener("abort",K,{once:!0});let x=setTimeout(K,$),E=globalThis.ReadableStream&&Q.body instanceof globalThis.ReadableStream||typeof Q.body==="object"&&Q.body!==null&&Symbol.asyncIterator in Q.body,O={signal:z.signal,...E?{duplex:"half"}:{},method:"GET",...Q};if(J)O.method=J.toUpperCase();try{return await this.fetch.call(void 0,X,O)}finally{clearTimeout(x)}}async shouldRetry(X){let Z=X.headers.get("x-should-retry");if(Z==="true")return!0;if(Z==="false")return!1;if(X.status===408)return!0;if(X.status===409)return!0;if(X.status===429)return!0;if(X.status>=500)return!0;return!1}async retryRequest(X,Z,$,z){let W,J=z?.get("retry-after-ms");if(J){let K=parseFloat(J);if(!Number.isNaN(K))W=K}let Q=z?.get("retry-after");if(Q&&!W){let K=parseFloat(Q);if(!Number.isNaN(K))W=K*1000;else W=Date.parse(Q)-Date.now()}if(W===void 0){let K=X.maxRetries??this.maxRetries;W=this.calculateDefaultRetryTimeoutMillis(Z,K)}return await F0(W),this.makeRequest(X,Z-1,$)}calculateDefaultRetryTimeoutMillis(X,Z){let W=Z-X,J=Math.min(0.5*Math.pow(2,W),8),Q=1-Math.random()*0.25;return J*Q*1000}calculateNonstreamingTimeout(X,Z){if(3600000*X/128000>600000||Z!=null&&X>Z)throw new N("Streaming is required for operations that may take longer than 10 minutes. See https://github.com/anthropics/anthropic-sdk-typescript#long-requests for more details");return 600000}async buildRequest(X,{retryCount:Z=0}={}){let $={...X},{method:z,path:W,query:J,defaultBaseURL:Q}=$,K=this.buildURL(W,J,Q);if("timeout"in $)H0("timeout",$.timeout);$.timeout=$.timeout??this.timeout;let{bodyHeaders:x,body:E}=this.buildBody({options:$}),O=await this.buildHeaders({options:X,method:z,bodyHeaders:x,retryCount:Z});return{req:{method:z,headers:O,...$.signal&&{signal:$.signal},...globalThis.ReadableStream&&E instanceof globalThis.ReadableStream&&{duplex:"half"},...E&&{body:E},...this.fetchOptions??{},...$.fetchOptions??{}},url:K,timeout:$.timeout}}async buildHeaders({options:X,method:Z,bodyHeaders:$,retryCount:z}){let W={};if(this.idempotencyHeader&&Z!=="get"){if(!X.idempotencyKey)X.idempotencyKey=this.defaultIdempotencyKey();W[this.idempotencyHeader]=X.idempotencyKey}let J=w([W,{Accept:"application/json","User-Agent":this.getUserAgent(),"X-Stainless-Retry-Count":String(z),...X.timeout?{"X-Stainless-Timeout":String(Math.trunc(X.timeout/1000))}:{},...B0(),...this._options.dangerouslyAllowBrowser?{"anthropic-dangerous-direct-browser-access":"true"}:void 0,"anthropic-version":"2023-06-01"},await this.authHeaders(X),this._options.defaultHeaders,$,X.headers]);return this.validateHeaders(J),J.values}_makeAbort(X){return()=>X.abort()}buildBody({options:{body:X,headers:Z}}){if(!X)return{bodyHeaders:void 0,body:void 0};let $=w([Z]);if(ArrayBuffer.isView(X)||X instanceof ArrayBuffer||X instanceof DataView||typeof X==="string"&&$.values.has("content-type")||globalThis.Blob&&X instanceof globalThis.Blob||X instanceof FormData||X instanceof URLSearchParams||globalThis.ReadableStream&&X instanceof globalThis.ReadableStream)return{bodyHeaders:void 0,body:X};else if(typeof X==="object"&&((Symbol.asyncIterator in X)||(Symbol.iterator in X)&&("next"in X)&&typeof X.next==="function"))return{bodyHeaders:void 0,body:CZ(X)};else if(typeof X==="object"&&$.values.get("content-type")==="application/x-www-form-urlencoded")return{bodyHeaders:{"content-type":"application/x-www-form-urlencoded"},body:this.stringifyQuery(X)};else return Y(this,vZ,"f").call(this,{body:X,headers:$})}}C0=M,vZ=new WeakMap,U0=new WeakSet,Q1=function(){return this.baseURL!=="https://api.anthropic.com"};M.Anthropic=C0;M.HUMAN_PROMPT=V1;M.AI_PROMPT=G1;M.DEFAULT_TIMEOUT=600000;M.AnthropicError=N;M.APIError=A;M.APIConnectionError=o;M.APIConnectionTimeoutError=EX;M.APIUserAbortError=L;M.NotFoundError=TX;M.ConflictError=LX;M.RateLimitError=jX;M.BadRequestError=AX;M.AuthenticationError=HX;M.InternalServerError=BX;M.PermissionDeniedError=FX;M.UnprocessableEntityError=SX;M.toFile=HZ;class WX extends M{constructor(){super(...arguments);this.completions=new UX(this),this.messages=new zX(this),this.models=new qX(this),this.beta=new S(this)}}WX.Completions=UX;WX.Messages=zX;WX.Models=qX;WX.Beta=S;export{WX as lk};
41
+ `);this.baseURL=W.baseURL,this.timeout=W.timeout??C0.DEFAULT_TIMEOUT,this.logger=W.logger??console;let J="warn";this.logLevel=J,this.logLevel=iZ(W.logLevel,"ClientOptions.logLevel",this)??iZ(GZ("ANTHROPIC_LOG"),"process.env['ANTHROPIC_LOG']",this)??J,this.fetchOptions=W.fetchOptions,this.maxRetries=W.maxRetries??2,this.fetch=W.fetch??D0(),G(this,vZ,P0,"f"),this._options=W,this.apiKey=typeof Z==="string"?Z:null,this.authToken=$}withOptions(X){return new this.constructor({...this._options,baseURL:this.baseURL,maxRetries:this.maxRetries,timeout:this.timeout,logger:this.logger,logLevel:this.logLevel,fetch:this.fetch,fetchOptions:this.fetchOptions,apiKey:this.apiKey,authToken:this.authToken,...X})}defaultQuery(){return this._options.defaultQuery}validateHeaders({values:X,nulls:Z}){if(X.get("x-api-key")||X.get("authorization"))return;if(this.apiKey&&X.get("x-api-key"))return;if(Z.has("x-api-key"))return;if(this.authToken&&X.get("authorization"))return;if(Z.has("authorization"))return;throw Error('Could not resolve authentication method. Expected either apiKey or authToken to be set. Or for one of the "X-Api-Key" or "Authorization" headers to be explicitly omitted')}async authHeaders(X){return w([await this.apiKeyAuth(X),await this.bearerAuth(X)])}async apiKeyAuth(X){if(this.apiKey==null)return;return w([{"X-Api-Key":this.apiKey}])}async bearerAuth(X){if(this.authToken==null)return;return w([{Authorization:`Bearer ${this.authToken}`}])}stringifyQuery(X){return k0(X)}getUserAgent(){return`${this.constructor.name}/JS ${m}`}defaultIdempotencyKey(){return`stainless-node-retry-${cZ()}`}makeStatusError(X,Z,$,z){return A.generate(X,Z,$,z)}buildURL(X,Z,$){let z=!Y(this,U0,"m",Q1).call(this)&&$||this.baseURL,W=E0(X)?new URL(X):new URL(z+(z.endsWith("/")&&X.startsWith("/")?X.slice(1):X)),J=this.defaultQuery(),Q=Object.fromEntries(W.searchParams);if(!uZ(J)||!uZ(Q))Z={...Q,...J,...Z};if(typeof Z==="object"&&Z&&!Array.isArray(Z))W.search=this.stringifyQuery(Z);return W.toString()}_calculateNonstreamingTimeout(X){if(3600*X/128000>600)throw new N("Streaming is required for operations that may take longer than 10 minutes. See https://github.com/anthropics/anthropic-sdk-typescript#streaming-responses for more details");return 600000}async prepareOptions(X){}async prepareRequest(X,{url:Z,options:$}){}get(X,Z){return this.methodRequest("get",X,Z)}post(X,Z){return this.methodRequest("post",X,Z)}patch(X,Z){return this.methodRequest("patch",X,Z)}put(X,Z){return this.methodRequest("put",X,Z)}delete(X,Z){return this.methodRequest("delete",X,Z)}methodRequest(X,Z,$){return this.request(Promise.resolve($).then((z)=>{return{method:X,path:Z,...z}}))}request(X,Z=null){return new r(this,this.makeRequest(X,Z,void 0))}async makeRequest(X,Z,$){let z=await X,W=z.maxRetries??this.maxRetries;if(Z==null)Z=W;await this.prepareOptions(z);let{req:J,url:Q,timeout:K}=await this.buildRequest(z,{retryCount:W-Z});await this.prepareRequest(J,{url:Q,options:z});let x="log_"+(Math.random()*16777216|0).toString(16).padStart(6,"0"),E=$===void 0?"":`, retryOf: ${$}`,O=Date.now();if(T(this).debug(`[${x}] sending request`,g({retryOfRequestLogID:$,method:z.method,url:Q,options:z,headers:J.headers})),z.signal?.aborted)throw new L;let k=new AbortController,C=await this.fetchWithTimeout(Q,J,K,k).catch(MX),F=Date.now();if(C instanceof globalThis.Error){let h=`retrying, ${Z} attempts remaining`;if(z.signal?.aborted)throw new L;let _=b(C)||/timed? ?out/i.test(String(C)+("cause"in C?String(C.cause):""));if(Z)return T(this).info(`[${x}] connection ${_?"timed out":"failed"} - ${h}`),T(this).debug(`[${x}] connection ${_?"timed out":"failed"} (${h})`,g({retryOfRequestLogID:$,url:Q,durationMs:F-O,message:C.message})),this.retryRequest(z,Z,$??x);if(T(this).info(`[${x}] connection ${_?"timed out":"failed"} - error; no more retries left`),T(this).debug(`[${x}] connection ${_?"timed out":"failed"} (error; no more retries left)`,g({retryOfRequestLogID:$,url:Q,durationMs:F-O,message:C.message})),_)throw new EX;throw new o({cause:C})}let a=[...C.headers.entries()].filter(([h])=>h==="request-id").map(([h,_])=>", "+h+": "+JSON.stringify(_)).join(""),OX=`[${x}${E}${a}] ${J.method} ${Q} ${C.ok?"succeeded":"failed"} with status ${C.status} in ${F-O}ms`;if(!C.ok){let h=await this.shouldRetry(C);if(Z&&h){let NZ=`retrying, ${Z} attempts remaining`;return await f0(C.body),T(this).info(`${OX} - ${NZ}`),T(this).debug(`[${x}] response error (${NZ})`,g({retryOfRequestLogID:$,url:C.url,status:C.status,headers:C.headers,durationMs:F-O})),this.retryRequest(z,Z,$??x,C.headers)}let _=h?"error; no more retries left":"error; not retryable";T(this).info(`${OX} - ${_}`);let q0=await C.text().catch((NZ)=>MX(NZ).message),O0=UZ(q0),M0=O0?void 0:q0;throw T(this).debug(`[${x}] response error (${_})`,g({retryOfRequestLogID:$,url:C.url,status:C.status,headers:C.headers,message:M0,durationMs:Date.now()-O})),this.makeStatusError(C.status,O0,M0,C.headers)}return T(this).info(OX),T(this).debug(`[${x}] response start`,g({retryOfRequestLogID:$,url:C.url,status:C.status,headers:C.headers,durationMs:F-O})),{response:C,options:z,controller:k,requestLogID:x,retryOfRequestLogID:$,startTime:O}}getAPIList(X,Z,$){return this.requestAPIList(Z,$&&"then"in $?$.then((z)=>({method:"get",path:X,...z})):{method:"get",path:X,...$})}requestAPIList(X,Z){let $=this.makeRequest(Z,null,void 0);return new AZ(this,$,X)}async fetchWithTimeout(X,Z,$,z){let{signal:W,method:J,...Q}=Z||{},K=this._makeAbort(z);if(W)W.addEventListener("abort",K,{once:!0});let x=setTimeout(K,$),E=globalThis.ReadableStream&&Q.body instanceof globalThis.ReadableStream||typeof Q.body==="object"&&Q.body!==null&&Symbol.asyncIterator in Q.body,O={signal:z.signal,...E?{duplex:"half"}:{},method:"GET",...Q};if(J)O.method=J.toUpperCase();try{return await this.fetch.call(void 0,X,O)}finally{clearTimeout(x)}}async shouldRetry(X){let Z=X.headers.get("x-should-retry");if(Z==="true")return!0;if(Z==="false")return!1;if(X.status===408)return!0;if(X.status===409)return!0;if(X.status===429)return!0;if(X.status>=500)return!0;return!1}async retryRequest(X,Z,$,z){let W,J=z?.get("retry-after-ms");if(J){let K=parseFloat(J);if(!Number.isNaN(K))W=K}let Q=z?.get("retry-after");if(Q&&!W){let K=parseFloat(Q);if(!Number.isNaN(K))W=K*1000;else W=Date.parse(Q)-Date.now()}if(W===void 0){let K=X.maxRetries??this.maxRetries;W=this.calculateDefaultRetryTimeoutMillis(Z,K)}return await F0(W),this.makeRequest(X,Z-1,$)}calculateDefaultRetryTimeoutMillis(X,Z){let W=Z-X,J=Math.min(0.5*Math.pow(2,W),8),Q=1-Math.random()*0.25;return J*Q*1000}calculateNonstreamingTimeout(X,Z){if(3600000*X/128000>600000||Z!=null&&X>Z)throw new N("Streaming is required for operations that may take longer than 10 minutes. See https://github.com/anthropics/anthropic-sdk-typescript#long-requests for more details");return 600000}async buildRequest(X,{retryCount:Z=0}={}){let $={...X},{method:z,path:W,query:J,defaultBaseURL:Q}=$,K=this.buildURL(W,J,Q);if("timeout"in $)H0("timeout",$.timeout);$.timeout=$.timeout??this.timeout;let{bodyHeaders:x,body:E}=this.buildBody({options:$}),O=await this.buildHeaders({options:X,method:z,bodyHeaders:x,retryCount:Z});return{req:{method:z,headers:O,...$.signal&&{signal:$.signal},...globalThis.ReadableStream&&E instanceof globalThis.ReadableStream&&{duplex:"half"},...E&&{body:E},...this.fetchOptions??{},...$.fetchOptions??{}},url:K,timeout:$.timeout}}async buildHeaders({options:X,method:Z,bodyHeaders:$,retryCount:z}){let W={};if(this.idempotencyHeader&&Z!=="get"){if(!X.idempotencyKey)X.idempotencyKey=this.defaultIdempotencyKey();W[this.idempotencyHeader]=X.idempotencyKey}let J=w([W,{Accept:"application/json","User-Agent":this.getUserAgent(),"X-Stainless-Retry-Count":String(z),...X.timeout?{"X-Stainless-Timeout":String(Math.trunc(X.timeout/1000))}:{},...B0(),...this._options.dangerouslyAllowBrowser?{"anthropic-dangerous-direct-browser-access":"true"}:void 0,"anthropic-version":"2023-06-01"},await this.authHeaders(X),this._options.defaultHeaders,$,X.headers]);return this.validateHeaders(J),J.values}_makeAbort(X){return()=>X.abort()}buildBody({options:{body:X,headers:Z}}){if(!X)return{bodyHeaders:void 0,body:void 0};let $=w([Z]);if(ArrayBuffer.isView(X)||X instanceof ArrayBuffer||X instanceof DataView||typeof X==="string"&&$.values.has("content-type")||globalThis.Blob&&X instanceof globalThis.Blob||X instanceof FormData||X instanceof URLSearchParams||globalThis.ReadableStream&&X instanceof globalThis.ReadableStream)return{bodyHeaders:void 0,body:X};else if(typeof X==="object"&&((Symbol.asyncIterator in X)||(Symbol.iterator in X)&&("next"in X)&&typeof X.next==="function"))return{bodyHeaders:void 0,body:CZ(X)};else if(typeof X==="object"&&$.values.get("content-type")==="application/x-www-form-urlencoded")return{bodyHeaders:{"content-type":"application/x-www-form-urlencoded"},body:this.stringifyQuery(X)};else return Y(this,vZ,"f").call(this,{body:X,headers:$})}}C0=M,vZ=new WeakMap,U0=new WeakSet,Q1=function(){return this.baseURL!=="https://api.anthropic.com"};M.Anthropic=C0;M.HUMAN_PROMPT=V1;M.AI_PROMPT=G1;M.DEFAULT_TIMEOUT=600000;M.AnthropicError=N;M.APIError=A;M.APIConnectionError=o;M.APIConnectionTimeoutError=EX;M.APIUserAbortError=L;M.NotFoundError=TX;M.ConflictError=LX;M.RateLimitError=jX;M.BadRequestError=AX;M.AuthenticationError=HX;M.InternalServerError=BX;M.PermissionDeniedError=FX;M.UnprocessableEntityError=SX;M.toFile=HZ;class WX extends M{constructor(){super(...arguments);this.completions=new UX(this),this.messages=new zX(this),this.models=new qX(this),this.beta=new S(this)}}WX.Completions=UX;WX.Messages=zX;WX.Models=qX;WX.Beta=S;export{WX as rk};
@@ -0,0 +1 @@
1
+ import{a as W,b as X,c as Y,d,e as f,f as P}from"./chunk-wc8sc9r9.js";import{qf as M,rf as U,sf as C,tf as H,uf as I}from"./chunk-15sefy5t.js";import{Gh as T,Qj as q,Sh as N,Vh as l,ai as G,ek as K,gk as y,hk as A,ik as D,jk as L,mh as J,mk as o,oh as n,ph as i,sh as Q,th as w,vj as b}from"./chunk-nyhqy6q2.js";import{Vk as E}from"./chunk-0qkj838r.js";var x=E(J(),1);var Z=E(J(),1);var R=E(J(),1);var B=q("inline-flex items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-[color,box-shadow] outline-none hover:bg-muted hover:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",{variants:{variant:{default:"bg-transparent",outline:"border border-input bg-transparent shadow-xs hover:bg-accent hover:text-accent-foreground"},size:{default:"h-9 min-w-9 px-2",sm:"h-8 min-w-8 px-1.5",lg:"h-10 min-w-10 px-2.5"}},defaultVariants:{variant:"default",size:"default"}});var k=R.createContext({size:"default",variant:"default",spacing:0});function O({className:p,variant:r,size:v,spacing:c=0,children:u,...g}){return n(K.Root,{"data-slot":"toggle-group","data-variant":r,"data-size":v,"data-spacing":c,style:{"--gap":c},className:y("group/toggle-group flex w-fit items-center gap-[--spacing(var(--gap))] rounded-md data-[spacing=default]:data-[variant=outline]:shadow-xs",p),...g,children:n(k.Provider,{value:{variant:r,size:v,spacing:c},children:u})})}function z({className:p,children:r,variant:v,size:c,...u}){let g=R.useContext(k);return n(K.Item,{"data-slot":"toggle-group-item","data-variant":g.variant||v,"data-size":g.size||c,"data-spacing":g.spacing,className:y(B({variant:g.variant||v,size:g.size||c}),"w-auto min-w-0 shrink-0 px-3 focus:z-10 focus-visible:z-10","data-[spacing=0]:rounded-none data-[spacing=0]:shadow-none data-[spacing=0]:first:rounded-l-md data-[spacing=0]:last:rounded-r-md data-[spacing=0]:data-[variant=outline]:border-l-0 data-[spacing=0]:data-[variant=outline]:first:border-l",p),...u,children:r})}function a({teamId:p}){let[r,v]=Z.useState("team"),[c,u]=Z.useState("1h"),{data:g,isLoading:s}=w({queryKey:["teams",p,"ai-usage",c,"team"],queryFn:async()=>{let t=await N.api.teams[":teamId"]["ai-usage"].$get({param:{teamId:p},query:{timeframe:c}});if(!t.ok)throw Error("Failed to fetch team AI usage");return await t.json()},enabled:!!p&&r==="team"}),{data:$,isLoading:j}=w({queryKey:["teams",p,"members"],queryFn:async()=>{let t=await N.api.teams[":teamId"].members.$get({param:{teamId:p},query:{}});if(!t.ok)throw Error("Failed to fetch team members");return await t.json()},enabled:!!p&&r==="members"}),F=Q({queries:($||[]).map((t)=>({queryKey:["teams",p,"ai-usage",c,t.id],queryFn:async()=>{let V=await N.api.teams[":teamId"]["ai-usage"].$get({param:{teamId:p},query:{timeframe:c,userId:t.id}});if(!V.ok)throw Error(`Failed to fetch AI usage for member ${t.id}`);return await V.json()},enabled:!!p&&r==="members"}))}),m=j||F.some((t)=>t.isLoading),e=(t)=>{if(!t)return"U";let V=t.split(" ");if(V.length>1)return`${V[0][0]}${V[V.length-1][0]}`.toUpperCase();return t.substring(0,2).toUpperCase()},nn=(t)=>{if(!t)return"";switch(t.toLowerCase()){case"owner":return o.owner();case"editor":return o.editor();case"reviewer":return o.reviewer();default:return t}},h=(t)=>(t??0).toLocaleString(),S=(t)=>`$${(t??0).toFixed(6)}`;return i(M,{className:"border-border/60 shadow-sm",children:[i(U,{className:"flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between pb-6",children:[i("div",{children:[n(C,{className:"text-xl font-semibold tracking-tight",children:o.ai_usage()}),n(H,{className:"text-sm text-muted-foreground mt-1",children:o.ai_usage_description()})]}),i("div",{className:"flex flex-wrap items-center gap-3",children:[i(O,{type:"single",value:r,onValueChange:(t)=>{if(t)v(t)},className:"border rounded-lg p-1 bg-muted/30",children:[n(z,{value:"team",className:"px-3 py-1.5 text-xs font-medium",children:o.team_view()}),n(z,{value:"members",className:"px-3 py-1.5 text-xs font-medium",children:o.members_view()})]}),i(O,{type:"single",value:c,onValueChange:(t)=>{if(t)u(t)},className:"border rounded-lg p-1 bg-muted/30",children:[n(z,{value:"1h",className:"px-2.5 py-1.5 text-xs font-medium",children:"1h"}),n(z,{value:"24h",className:"px-2.5 py-1.5 text-xs font-medium",children:"24h"}),n(z,{value:"7d",className:"px-2.5 py-1.5 text-xs font-medium",children:"7d"}),n(z,{value:"30d",className:"px-2.5 py-1.5 text-xs font-medium",children:"30d"})]})]})]}),n(I,{children:r==="team"?s?n("div",{className:"flex h-48 items-center justify-center",children:n(G,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):n("div",{className:"rounded-md border",children:i(W,{children:[n(X,{children:i(d,{children:[n(f,{children:o.team()}),n(f,{className:"text-right",children:o.input_tokens()}),n(f,{className:"text-right",children:o.output_tokens()}),n(f,{className:"text-right",children:o.cache_read_tokens()}),n(f,{className:"text-right",children:o.total_tokens()}),n(f,{className:"text-right",children:o.cost()})]})}),n(Y,{children:i(d,{children:[n(P,{className:"font-medium",children:o.team()}),n(P,{className:"text-right",children:h(g?.team?.inputTokens)}),n(P,{className:"text-right",children:h(g?.team?.outputTokens)}),n(P,{className:"text-right",children:h(g?.team?.cacheReadTokens)}),n(P,{className:"text-right font-medium",children:h(g?.team?.totalTokens)}),n(P,{className:"text-right font-medium",children:S(g?.team?.cost)})]})})]})}):m?n("div",{className:"flex h-48 items-center justify-center",children:n(G,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):n("div",{className:"rounded-md border",children:i(W,{children:[n(X,{children:i(d,{children:[n(f,{children:o.members()}),n(f,{children:o.role()}),n(f,{className:"text-right",children:o.input_tokens()}),n(f,{className:"text-right",children:o.output_tokens()}),n(f,{className:"text-right",children:o.cache_read_tokens()}),n(f,{className:"text-right",children:o.total_tokens()}),n(f,{className:"text-right",children:o.cost()})]})}),n(Y,{children:($||[]).map((t,V)=>{let _=F[V]?.data?.member;return i(d,{children:[n(P,{children:i("div",{className:"flex items-center gap-3",children:[i(A,{className:"h-8 w-8 rounded-full",children:[t.image&&n(D,{src:t.image,alt:t.name,className:"object-cover"}),n(L,{className:"bg-primary/20 text-xs",children:e(t.name)})]}),i("div",{className:"flex flex-col",children:[n("span",{className:"text-sm font-medium leading-none",children:t.name}),n("span",{className:"text-xs text-muted-foreground mt-0.5",children:t.email})]})]})}),n(P,{className:"text-xs text-muted-foreground",children:nn(t.role)}),n(P,{className:"text-right",children:h(_?.inputTokens)}),n(P,{className:"text-right",children:h(_?.outputTokens)}),n(P,{className:"text-right",children:h(_?.cacheReadTokens)}),n(P,{className:"text-right font-medium",children:h(_?.totalTokens)}),n(P,{className:"text-right font-medium",children:S(_?.cost)})]},t.id)})})]})})})]})}function tn(){let{teamId:p}=on.useParams(),[r,v]=x.useState("ai-usage"),{data:c,isLoading:u}=w({queryKey:["teams",p,"me"],queryFn:async()=>{let g=await N.api.teams[":teamId"].me.$get({param:{teamId:p}});if(!g.ok)throw Error("Failed to fetch me");return await g.json()},enabled:!!p});if(u)return n("div",{className:"flex h-screen items-center justify-center",children:n(G,{className:"h-8 w-8 animate-spin text-muted-foreground"})});if(c?.role?.toLowerCase()!=="owner")return i("div",{className:"flex h-full flex-col items-center justify-center p-8 text-center",children:[n(b,{className:"h-12 w-12 text-destructive mb-4"}),n("h2",{className:"text-xl font-bold tracking-tight mb-2",children:o.access_denied()}),n("p",{className:"text-sm text-muted-foreground max-w-md",children:o.only_owner_dashboard()})]});return n("div",{className:"h-full bg-background font-sans selection:bg-primary/20 transition-colors duration-300",children:i("div",{className:"flex flex-col md:flex-row h-full",children:[n("div",{className:"w-full h-full md:w-72 bg-sidebar border-b md:border-b-0 md:border-r border-sidebar-border z-10 md:left-16 overflow-y-auto transition-colors duration-300",children:i("nav",{className:"p-4 space-y-1 mt-4",children:[n("div",{className:"mb-2 px-4 text-xs font-semibold text-sidebar-foreground/60 uppercase tracking-wider",children:o.dashboard()}),n("div",{className:"mt-4 mb-2 px-4 text-xs font-semibold text-sidebar-foreground/60 uppercase tracking-wider pt-4 border-t border-sidebar-border",children:o.ai()}),i("button",{onClick:()=>v("ai-usage"),className:y("w-full flex items-center gap-3 px-4 py-3 text-sm font-medium rounded-lg transition-all",r==="ai-usage"?"bg-sidebar-accent text-sidebar-accent-foreground ring-1 ring-sidebar-border":"text-sidebar-foreground/75 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground"),children:[n(l,{className:"w-5 h-5"}),o.usage(),r==="ai-usage"&&n("div",{className:"ml-auto w-1.5 h-1.5 rounded-full bg-sidebar-primary"})]})]})}),n("div",{className:"flex-1 overflow-y-auto p-4 md:p-8",children:n("div",{className:"max-w-6xl mx-auto space-y-8",children:r==="ai-usage"&&n(a,{teamId:p})})})]})})}var on=T("/teams/$teamId/dashboard")({component:tn});export{on as Route};
@@ -0,0 +1 @@
1
+ import{j as U}from"./chunk-jqh8kavv.js";import"./chunk-8dqq1fk0.js";import"./chunk-mnfqdxms.js";import"./chunk-b73ktdmd.js";import"./chunk-wckjyvtb.js";import"./chunk-crt1e1w1.js";import"./chunk-wsyg4rwg.js";import"./chunk-nhsqp8jc.js";import"./chunk-srn8t0v7.js";import"./chunk-kfhtk3eh.js";import"./chunk-kr06nrbx.js";import"./chunk-b8js74jk.js";import"./chunk-0xbf8bcg.js";import{cf as N}from"./chunk-898q6x3q.js";import"./chunk-88fg1sw7.js";import{zf as K}from"./chunk-3qks722n.js";import"./chunk-77r8w95d.js";import"./chunk-t3t6021k.js";import"./chunk-nnkkem25.js";import"./chunk-1xpec5r8.js";import"./chunk-0rxhc7ka.js";import"./chunk-3n1rezd0.js";import"./chunk-fz88kkk1.js";import"./chunk-dghtwyq1.js";import{bh as J}from"./chunk-gswbc6y9.js";import{Gh as G,Sh as H,mh as Z,oh as q,th as B,uh as D}from"./chunk-nyhqy6q2.js";import{Vk as Y}from"./chunk-0qkj838r.js";var V=Y(Z(),1);function _(){let{projectId:h,folderId:W}=z.useParams(),{teamId:v,ensureTeamIdForProject:w}=J();V.useEffect(()=>{w(h)},[h,w]);let{data:A}=D(N(h)),b=A?.rootFolder,{data:X}=B({queryKey:["folders",b],queryFn:()=>(async()=>{return await(await H.api.folders[":folderId"].$get({param:{folderId:b}})).json()})(),enabled:!!b});if(!v||!b||!X)return q(K,{});return q(U,{teamId:v,projectId:h,projectName:A.name??"",assetId:W,rootFolderId:b})}var z=G("/projects/$projectId/folders/$folderId")({component:_});export{z as Route};
@@ -1,4 +1,4 @@
1
- import{Rg as x0,Tg as TJ,Ug as PZ,eh as N5}from"./chunk-wf4d1anc.js";import{Pk as TZ}from"./chunk-976v5s8y.js";var FQ=TZ(x0(),1);var b5=({onResize:J,className:Q=""})=>{let[Z,$]=FQ.useState(!1),q=FQ.useRef(0);FQ.useEffect(()=>{if(!Z)return;let K=(B)=>{let N=B.clientX-q.current;q.current=B.clientX,J(N)},X=()=>{$(!1),document.body.style.cursor=""};return document.addEventListener("mousemove",K),document.addEventListener("mouseup",X),document.body.style.cursor="col-resize",()=>{document.removeEventListener("mousemove",K),document.removeEventListener("mouseup",X),document.body.style.cursor=""}},[Z,J]);let Y=(K)=>{K.preventDefault(),K.stopPropagation(),$(!0),q.current=K.clientX},H=()=>TJ("div",{className:"absolute inset-y-0 -left-4 -right-4 z-20 cursor-col-resize touch-none"});return PZ("div",{className:`group relative z-20 flex h-full w-[2px] cursor-col-resize items-center justify-center bg-border transition-all hover:bg-transparent ${Q}`,onMouseDown:Y,children:[TJ(H,{}),TJ("div",{className:`absolute inset-y-0 w-[2px] transition-all duration-300 ease-out
1
+ import{Ch as N5,mh as x0,oh as TJ,ph as PZ}from"./chunk-nyhqy6q2.js";import{Vk as TZ}from"./chunk-0qkj838r.js";var FQ=TZ(x0(),1);var b5=({onResize:J,className:Q=""})=>{let[Z,$]=FQ.useState(!1),q=FQ.useRef(0);FQ.useEffect(()=>{if(!Z)return;let K=(B)=>{let N=B.clientX-q.current;q.current=B.clientX,J(N)},X=()=>{$(!1),document.body.style.cursor=""};return document.addEventListener("mousemove",K),document.addEventListener("mouseup",X),document.body.style.cursor="col-resize",()=>{document.removeEventListener("mousemove",K),document.removeEventListener("mouseup",X),document.body.style.cursor=""}},[Z,J]);let Y=(K)=>{K.preventDefault(),K.stopPropagation(),$(!0),q.current=K.clientX},H=()=>TJ("div",{className:"absolute inset-y-0 -left-4 -right-4 z-20 cursor-col-resize touch-none"});return PZ("div",{className:`group relative z-20 flex h-full w-[2px] cursor-col-resize items-center justify-center bg-border transition-all hover:bg-transparent ${Q}`,onMouseDown:Y,children:[TJ(H,{}),TJ("div",{className:`absolute inset-y-0 w-[2px] transition-all duration-300 ease-out
2
2
  ${Z?"bg-blue-600 shadow-[0_0_15px_rgba(37,99,235,0.6)] opacity-100":"bg-blue-400 opacity-0 group-hover:opacity-100 group-hover:shadow-[0_0_8px_rgba(96,165,250,0.5)]"}
3
3
  `}),TJ("div",{className:`absolute top-1/2 left-1/2 h-10 w-1.5 -translate-x-1/2 -translate-y-1/2 rounded-full bg-blue-600 transition-all duration-300 ease-out
4
4
  ${Z?"opacity-100 scale-100 shadow-[0_0_10px_rgba(37,99,235,0.5)]":"opacity-0 scale-75 group-hover:opacity-100 group-hover:scale-100"}`})]})};var e$=Symbol.for("preact-signals");function xZ(){if(!(PJ>1)){var J,Q=!1;(function(){var q=SZ;SZ=void 0;while(q!==void 0){if(q.S.v===q.v)q.S.i=q.i;q=q.o}})();while(cQ!==void 0){var Z=cQ;cQ=void 0,EZ++;while(Z!==void 0){var $=Z.u;if(Z.u=void 0,Z.f&=-3,!(8&Z.f)&&_9(Z))try{Z.c()}catch(q){if(!Q)J=q,Q=!0}Z=$}}if(EZ=0,PJ--,Q)throw J}else PJ--}function JJ(J){if(PJ>0)return J();h0=++Jq,PJ++;try{return J()}finally{xZ()}}var k=void 0;function C(J){var Q=k;k=void 0;try{return J()}finally{k=Q}}var p9,cQ=void 0,PJ=0,EZ=0,Jq=0,h0=0,SZ=void 0,kZ=0;function d9(J){if(k!==void 0){var Q=J.n;if(Q===void 0||Q.t!==k){if(Q={i:0,S:J,p:k.s,n:void 0,t:k,e:void 0,x:void 0,r:Q},k.s!==void 0)k.s.n=Q;if(k.s=Q,J.n=Q,32&k.f)J.S(Q);return Q}else if(Q.i===-1){if(Q.i=0,Q.n!==void 0){if(Q.n.p=Q.p,Q.p!==void 0)Q.p.n=Q.n;Q.p=k.s,Q.n=void 0,k.s.n=Q,k.s=Q}return Q}}}function r(J,Q){this.v=J,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=Q==null?void 0:Q.watched,this.Z=Q==null?void 0:Q.unwatched,this.name=Q==null?void 0:Q.name}r.prototype.brand=e$;r.prototype.h=function(){return!0};r.prototype.S=function(J){var Q=this,Z=this.t;if(Z!==J&&J.e===void 0)if(J.x=Z,this.t=J,Z!==void 0)Z.e=J;else C(function(){var $;($=Q.W)==null||$.call(Q)})};r.prototype.U=function(J){var Q=this;if(this.t!==void 0){var{e:Z,x:$}=J;if(Z!==void 0)Z.x=$,J.e=void 0;if($!==void 0)$.e=Z,J.x=void 0;if(J===this.t){if(this.t=$,$===void 0)C(function(){var q;(q=Q.Z)==null||q.call(Q)})}}};r.prototype.subscribe=function(J){var Q=this;return o(function(){var Z=Q.value,$=k;k=void 0;try{J(Z)}finally{k=$}},{name:"sub"})};r.prototype.valueOf=function(){return this.value};r.prototype.toString=function(){return this.value+""};r.prototype.toJSON=function(){return this.value};r.prototype.peek=function(){var J=this;return C(function(){return J.value})};Object.defineProperty(r.prototype,"value",{get:function(){var J=d9(this);if(J!==void 0)J.i=this.i;return this.v},set:function(J){if(J!==this.v){if(EZ>100)throw Error("Cycle detected");(function(Z){if(PJ!==0&&EZ===0){if(Z.l!==h0)Z.l=h0,SZ={S:Z,v:Z.v,i:Z.i,o:SZ}}})(this),this.v=J,this.i++,kZ++,PJ++;try{for(var Q=this.t;Q!==void 0;Q=Q.x)Q.t.N()}finally{xZ()}}}});function IJ(J,Q){return new r(J,Q)}function _9(J){for(var Q=J.s;Q!==void 0;Q=Q.n)if(Q.S.i!==Q.i||!Q.S.h()||Q.S.i!==Q.i)return!0;return!1}function c9(J){for(var Q=J.s;Q!==void 0;Q=Q.n){var Z=Q.S.n;if(Z!==void 0)Q.r=Z;if(Q.S.n=Q,Q.i=-1,Q.n===void 0){J.s=Q;break}}}function l9(J){var Q=J.s,Z=void 0;while(Q!==void 0){var $=Q.p;if(Q.i===-1){if(Q.S.U(Q),$!==void 0)$.n=Q.n;if(Q.n!==void 0)Q.n.p=$}else Z=Q;if(Q.S.n=Q.r,Q.r!==void 0)Q.r=void 0;Q=$}J.s=Z}function sJ(J,Q){r.call(this,void 0),this.x=J,this.s=void 0,this.g=kZ-1,this.f=4,this.W=Q==null?void 0:Q.watched,this.Z=Q==null?void 0:Q.unwatched,this.name=Q==null?void 0:Q.name}sJ.prototype=new r;sJ.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32)return!0;if(this.f&=-5,this.g===kZ)return!0;if(this.g=kZ,this.f|=1,this.i>0&&!_9(this))return this.f&=-2,!0;var J=k;try{c9(this),k=this;var Q=this.x();if(16&this.f||this.v!==Q||this.i===0)this.v=Q,this.f&=-17,this.i++}catch(Z){this.v=Z,this.f|=16,this.i++}return k=J,l9(this),this.f&=-2,!0};sJ.prototype.S=function(J){if(this.t===void 0){this.f|=36;for(var Q=this.s;Q!==void 0;Q=Q.n)Q.S.S(Q)}r.prototype.S.call(this,J)};sJ.prototype.U=function(J){if(this.t!==void 0){if(r.prototype.U.call(this,J),this.t===void 0){this.f&=-33;for(var Q=this.s;Q!==void 0;Q=Q.n)Q.S.U(Q)}}};sJ.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var J=this.t;J!==void 0;J=J.x)J.t.N()}};Object.defineProperty(sJ.prototype,"value",{get:function(){if(1&this.f)throw Error("Cycle detected");var J=d9(this);if(this.h(),J!==void 0)J.i=this.i;if(16&this.f)throw this.v;return this.v}});function y0(J,Q){return new sJ(J,Q)}function s9(J){var Q=J.m;if(J.m=void 0,typeof Q=="function"){PJ++;var Z=k;k=void 0;try{Q()}catch($){throw J.f&=-2,J.f|=8,f0(J),$}finally{k=Z,xZ()}}}function f0(J){for(var Q=J.s;Q!==void 0;Q=Q.n)Q.S.U(Q);J.x=void 0,J.s=void 0,s9(J)}function Qq(J){if(k!==this)throw Error("Out-of-order effect");if(l9(this),k=J,this.f&=-2,8&this.f)f0(this);xZ()}function zQ(J,Q){if(this.x=J,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=Q==null?void 0:Q.name,p9)p9.push(this)}zQ.prototype.c=function(){var J=this.S();try{if(8&this.f)return;if(this.x===void 0)return;var Q=this.x();if(typeof Q=="function")this.m=Q}finally{J()}};zQ.prototype.S=function(){if(1&this.f)throw Error("Cycle detected");this.f|=1,this.f&=-9,s9(this),c9(this),PJ++;var J=k;return k=this,Qq.bind(this,J)};zQ.prototype.N=function(){if(!(2&this.f))this.f|=2,this.u=cQ,cQ=this};zQ.prototype.d=function(){if(this.f|=8,!(1&this.f))f0(this)};zQ.prototype.dispose=function(){this.d()};function o(J,Q){var Z=new zQ(J,Q);try{Z.c()}catch(q){throw Z.d(),q}var $=Z.d.bind(Z);return $[Symbol.dispose]=$,$}var{create:Zq,defineProperty:s0,defineProperties:$q,getOwnPropertyDescriptor:qq,getOwnPropertyDescriptors:Yq,getOwnPropertySymbols:o9}=Object,Kq=Object.prototype.hasOwnProperty,Hq=Object.prototype.propertyIsEnumerable,n9=(J,Q)=>(Q=Symbol[J])?Q:Symbol.for("Symbol."+J),MQ=(J)=>{throw TypeError(J)},m0=(J,Q,Z)=>(Q in J)?s0(J,Q,{enumerable:!0,configurable:!0,writable:!0,value:Z}):J[Q]=Z,Xq=(J,Q)=>{for(var Z in Q||(Q={}))if(Kq.call(Q,Z))m0(J,Z,Q[Z]);if(o9){for(var Z of o9(Q))if(Hq.call(Q,Z))m0(J,Z,Q[Z])}return J},Wq=(J,Q)=>$q(J,Yq(Q)),i9=(J,Q)=>s0(J,"name",{value:Q,configurable:!0}),Bq=(J)=>{var Q;return[,,,Zq((Q=J==null?void 0:J[n9("metadata")])!=null?Q:null)]},a9=["class","method","getter","setter","accessor","field","value","get","set"],lQ=(J)=>J!==void 0&&typeof J!=="function"?MQ("Function expected"):J,Nq=(J,Q,Z,$,q)=>({kind:a9[J],name:Q,metadata:$,addInitializer:(Y)=>Z._?MQ("Already initialized"):q.push(lQ(Y||null))}),r9=(J,Q)=>m0(Q,n9("metadata"),J[3]),oJ=(J,Q,Z,$)=>{for(var q=0,Y=J[Q>>1],H=Y&&Y.length;q<H;q++)Q&1?Y[q].call(Z):$=Y[q].call(Z,$);return $},wQ=(J,Q,Z,$,q,Y)=>{var H,K,X,B,N,W=Q&7,G=!!(Q&8),L=!!(Q&16),F=W>3?J.length+1:W?G?1:2:0,z=a9[W+5],A=W>3&&(J[F-1]=[]),I=J[F]||(J[F]=[]),U=W&&(!L&&!G&&(q=q.prototype),W<5&&(W>3||!L)&&qq(W<4?q:{get[Z](){return LJ(this,Y)},set[Z](V){return vJ(this,Y,V)}},Z));W?L&&W<4&&i9(Y,(W>2?"set ":W>1?"get ":"")+Z):i9(q,Z);for(var M=$.length-1;M>=0;M--){if(B=Nq(W,Z,X={},J[3],I),W){if(B.static=G,B.private=L,N=B.access={has:L?(V)=>Uq(q,V):(V)=>(Z in V)},W^3)N.get=L?(V)=>(W^1?LJ:Lq)(V,q,W^4?Y:U.get):(V)=>V[Z];if(W>2)N.set=L?(V,w)=>vJ(V,q,w,W^4?Y:U.set):(V,w)=>V[Z]=w}if(K=(0,$[M])(W?W<4?L?Y:U[z]:W>4?void 0:{get:U.get,set:U.set}:q,B),X._=1,W^4||K===void 0)lQ(K)&&(W>4?A.unshift(K):W?L?Y=K:U[z]=K:q=K);else if(typeof K!=="object"||K===null)MQ("Object expected");else lQ(H=K.get)&&(U.get=H),lQ(H=K.set)&&(U.set=H),lQ(H=K.init)&&A.unshift(H)}return W||r9(J,q),U&&s0(q,Z,U),L?W^4?Y:U:q},o0=(J,Q,Z)=>Q.has(J)||MQ("Cannot "+Z),Uq=(J,Q)=>Object(Q)!==Q?MQ('Cannot use the "in" operator on this value'):J.has(Q),LJ=(J,Q,Z)=>(o0(J,Q,"read from private field"),Z?Z.call(J):Q.get(J)),sQ=(J,Q,Z)=>Q.has(J)?MQ("Cannot add the same private member more than once"):Q instanceof WeakSet?Q.add(J):Q.set(J,Z),vJ=(J,Q,Z,$)=>(o0(J,Q,"write to private field"),$?$.call(J,Z):Q.set(J,Z),Z),Lq=(J,Q,Z)=>(o0(J,Q,"access private method"),Z);function AQ(J,Q){if(Q){let Z;return y0(()=>{let $=J();if($&&Z&&Q(Z,$))return Z;return Z=$,$})}return y0(J)}function EJ(J,Q){if(Object.is(J,Q))return!0;if(J===null||Q===null)return!1;if(typeof J==="function"&&typeof Q==="function")return J===Q;if(J instanceof Set&&Q instanceof Set){if(J.size!==Q.size)return!1;for(let Z of J)if(!Q.has(Z))return!1;return!0}if(Array.isArray(J)){if(!Array.isArray(Q)||J.length!==Q.length)return!1;return!J.some(($,q)=>!EJ($,Q[q]))}if(typeof J==="object"&&typeof Q==="object"){let Z=Object.keys(J),$=Object.keys(Q);if(Z.length!==$.length)return!1;return!Z.some((Y)=>!EJ(J[Y],Q[Y]))}return!1}function T({get:J},Q){return{init(Z){return IJ(Z)},get(){return J.call(this).value},set(Z){let $=J.call(this);if($.peek()===Z)return;$.value=Z}}}function h(J,Q){let Z=new WeakMap;return function(){let $=Z.get(this);if(!$)$=AQ(J.bind(this)),Z.set(this,$);return $.value}}function v0(J=!0){return function(Q,Z){Z.addInitializer(function(){let $=Z.kind==="field"?this:Z.static?this:Object.getPrototypeOf(this),q=Object.getOwnPropertyDescriptor($,Z.name);if(q)Object.defineProperty($,Z.name,Wq(Xq({},q),{enumerable:J}))})}}function nJ(...J){let Q=J.map((Z)=>o(Z));return()=>Q.forEach((Z)=>Z())}var t9,e9,J8,Q8,Z8,$8,QJ,i0,b0,p0,d0,t,n0,g0,q8,_0,a0,u0,c0,l0;$8=[T],Z8=[T],Q8=[T],J8=[v0()],e9=[v0()],t9=[v0()];var jJ=class{constructor(J,Q=Object.is){this.defaultValue=J,this.equals=Q,oJ(QJ,5,this),sQ(this,t),sQ(this,i0,oJ(QJ,8,this)),oJ(QJ,11,this),sQ(this,n0,oJ(QJ,12,this)),oJ(QJ,15,this),sQ(this,a0,oJ(QJ,16,this)),oJ(QJ,19,this),this.reset=this.reset.bind(this),this.reset()}get current(){return LJ(this,t,c0)}get initial(){return LJ(this,t,p0)}get previous(){return LJ(this,t,q8)}set current(J){let Q=C(()=>LJ(this,t,c0));if(J&&Q&&this.equals(Q,J))return;JJ(()=>{if(!LJ(this,t,p0))vJ(this,t,J,d0);vJ(this,t,Q,_0),vJ(this,t,J,l0)})}reset(J=this.defaultValue){JJ(()=>{vJ(this,t,void 0,_0),vJ(this,t,J,d0),vJ(this,t,J,l0)})}};QJ=Bq(null);i0=new WeakMap;t=new WeakSet;n0=new WeakMap;a0=new WeakMap;b0=wQ(QJ,20,"#initial",$8,t,i0),p0=b0.get,d0=b0.set;g0=wQ(QJ,20,"#previous",Z8,t,n0),q8=g0.get,_0=g0.set;u0=wQ(QJ,20,"#current",Q8,t,a0),c0=u0.get,l0=u0.set;wQ(QJ,2,"current",J8,jJ);wQ(QJ,2,"initial",e9,jJ);wQ(QJ,2,"previous",t9,jJ);r9(QJ,jJ);function hZ(J){return C(()=>{let Q={};for(let Z in J)Q[Z]=J[Z];return Q})}var iJ,o5=class{constructor(){sQ(this,iJ,new WeakMap)}get(J,Q){var Z;return J?(Z=LJ(this,iJ).get(J))==null?void 0:Z.get(Q):void 0}set(J,Q,Z){var $;if(!J)return;if(!LJ(this,iJ).has(J))LJ(this,iJ).set(J,new Map);return($=LJ(this,iJ).get(J))==null?void 0:$.set(Q,Z)}clear(J){var Q;return J?(Q=LJ(this,iJ).get(J))==null?void 0:Q.clear():void 0}};iJ=new WeakMap;var{create:Gq,defineProperty:Q1,getOwnPropertyDescriptor:Vq,getOwnPropertySymbols:Y8}=Object,Fq=Object.prototype.hasOwnProperty,zq=Object.prototype.propertyIsEnumerable,X8=(J,Q)=>(Q=Symbol[J])?Q:Symbol.for("Symbol."+J),IQ=(J)=>{throw TypeError(J)},K8=Math.pow,r0=(J,Q,Z)=>(Q in J)?Q1(J,Q,{enumerable:!0,configurable:!0,writable:!0,value:Z}):J[Q]=Z,Mq=(J,Q)=>{for(var Z in Q||(Q={}))if(Fq.call(Q,Z))r0(J,Z,Q[Z]);if(Y8){for(var Z of Y8(Q))if(zq.call(Q,Z))r0(J,Z,Q[Z])}return J},H8=(J,Q)=>Q1(J,"name",{value:Q,configurable:!0}),wq=(J)=>{var Q;return[,,,Gq((Q=J==null?void 0:J[X8("metadata")])!=null?Q:null)]},W8=["class","method","getter","setter","accessor","field","value","get","set"],oQ=(J)=>J!==void 0&&typeof J!=="function"?IQ("Function expected"):J,Aq=(J,Q,Z,$,q)=>({kind:W8[J],name:Q,metadata:$,addInitializer:(Y)=>Z._?IQ("Already initialized"):q.push(oQ(Y||null))}),B8=(J,Q)=>r0(Q,X8("metadata"),J[3]),Iq=(J,Q,Z,$)=>{for(var q=0,Y=J[Q>>1],H=Y&&Y.length;q<H;q++)Q&1?Y[q].call(Z):$=Y[q].call(Z,$);return $},N8=(J,Q,Z,$,q,Y)=>{var H,K,X,B,N,W=Q&7,G=!!(Q&8),L=!!(Q&16),F=W>3?J.length+1:W?G?1:2:0,z=W8[W+5],A=W>3&&(J[F-1]=[]),I=J[F]||(J[F]=[]),U=W&&(!L&&!G&&(q=q.prototype),W<5&&(W>3||!L)&&Vq(W<4?q:{get[Z](){return t0(this,Y)},set[Z](V){return e0(this,Y,V)}},Z));W?L&&W<4&&H8(Y,(W>2?"set ":W>1?"get ":"")+Z):H8(q,Z);for(var M=$.length-1;M>=0;M--){if(B=Aq(W,Z,X={},J[3],I),W){if(B.static=G,B.private=L,N=B.access={has:L?(V)=>jq(q,V):(V)=>(Z in V)},W^3)N.get=L?(V)=>(W^1?t0:Rq)(V,q,W^4?Y:U.get):(V)=>V[Z];if(W>2)N.set=L?(V,w)=>e0(V,q,w,W^4?Y:U.set):(V,w)=>V[Z]=w}if(K=(0,$[M])(W?W<4?L?Y:U[z]:W>4?void 0:{get:U.get,set:U.set}:q,B),X._=1,W^4||K===void 0)oQ(K)&&(W>4?A.unshift(K):W?L?Y=K:U[z]=K:q=K);else if(typeof K!=="object"||K===null)IQ("Object expected");else oQ(H=K.get)&&(U.get=H),oQ(H=K.set)&&(U.set=H),oQ(H=K.init)&&A.unshift(H)}return W||B8(J,q),U&&Q1(q,Z,U),L?W^4?Y:U:q},Z1=(J,Q,Z)=>Q.has(J)||IQ("Cannot "+Z),jq=(J,Q)=>Object(Q)!==Q?IQ('Cannot use the "in" operator on this value'):J.has(Q),t0=(J,Q,Z)=>(Z1(J,Q,"read from private field"),Z?Z.call(J):Q.get(J)),Oq=(J,Q,Z)=>Q.has(J)?IQ("Cannot add the same private member more than once"):Q instanceof WeakSet?Q.add(J):Q.set(J,Z),e0=(J,Q,Z,$)=>(Z1(J,Q,"write to private field"),$?$.call(J,Z):Q.set(J,Z),Z),Rq=(J,Q,Z)=>(Z1(J,Q,"access private method"),Z),e=class J{constructor(Q,Z){this.x=Q,this.y=Z}static delta(Q,Z){return new J(Q.x-Z.x,Q.y-Z.y)}static distance(Q,Z){return Math.hypot(Q.x-Z.x,Q.y-Z.y)}static equals(Q,Z){return Q.x===Z.x&&Q.y===Z.y}static from({x:Q,y:Z}){return new J(Q,Z)}},XJ=class J{constructor(Q,Z,$,q){this.left=Q,this.top=Z,this.width=$,this.height=q,this.scale={x:1,y:1}}get inverseScale(){return{x:1/this.scale.x,y:1/this.scale.y}}translate(Q,Z){let{top:$,left:q,width:Y,height:H,scale:K}=this,X=new J(q+Q,$+Z,Y,H);return X.scale=Mq({},K),X}get boundingRectangle(){let{width:Q,height:Z,left:$,top:q,right:Y,bottom:H}=this;return{width:Q,height:Z,left:$,top:q,right:Y,bottom:H}}get center(){let{left:Q,top:Z,right:$,bottom:q}=this;return new e((Q+$)/2,(Z+q)/2)}get area(){let{width:Q,height:Z}=this;return Q*Z}equals(Q){if(!(Q instanceof J))return!1;let{left:Z,top:$,width:q,height:Y}=this;return Z===Q.left&&$===Q.top&&q===Q.width&&Y===Q.height}containsPoint(Q){let{top:Z,left:$,bottom:q,right:Y}=this;return Z<=Q.y&&Q.y<=q&&$<=Q.x&&Q.x<=Y}intersectionArea(Q){if(Q instanceof J)return Dq(this,Q);return 0}intersectionRatio(Q){let{area:Z}=this,$=this.intersectionArea(Q);return $/(Q.area+Z-$)}get bottom(){let{top:Q,height:Z}=this;return Q+Z}get right(){let{left:Q,width:Z}=this;return Q+Z}get aspectRatio(){let{width:Q,height:Z}=this;return Q/Z}get corners(){return[{x:this.left,y:this.top},{x:this.right,y:this.top},{x:this.left,y:this.bottom},{x:this.right,y:this.bottom}]}static from({top:Q,left:Z,width:$,height:q}){return new J(Z,Q,$,q)}static delta(Q,Z,$={x:"center",y:"center"}){let q=(Y,H)=>{let K=$[H],X=H==="x"?Y.left:Y.top,B=H==="x"?Y.width:Y.height;if(K=="start")return X;if(K=="end")return X+B;return X+B/2};return e.delta({x:q(Q,"x"),y:q(Q,"y")},{x:q(Z,"x"),y:q(Z,"y")})}static intersectionRatio(Q,Z){return J.from(Q).intersectionRatio(J.from(Z))}};function Dq(J,Q){let Z=Math.max(Q.top,J.top),$=Math.max(Q.left,J.left),q=Math.min(Q.left+Q.width,J.left+J.width),Y=Math.min(Q.top+Q.height,J.top+J.height),H=q-$,K=Y-Z;if($<q&&Z<Y)return H*K;return 0}var U8,L8,J1,yZ,iQ,nQ=class extends(J1=jJ,L8=[h],U8=[h],J1){constructor(J){let Q=e.from(J);super(Q,(Z,$)=>e.equals(Z,$));Iq(iQ,5,this),Oq(this,yZ,0),this.velocity={x:0,y:0}}get delta(){return e.delta(this.current,this.initial)}get direction(){let{current:J,previous:Q}=this;if(!Q)return null;let Z={x:J.x-Q.x,y:J.y-Q.y};if(!Z.x&&!Z.y)return null;if(Math.abs(Z.x)>Math.abs(Z.y))return Z.x>0?"right":"left";return Z.y>0?"down":"up"}get current(){return super.current}set current(J){let{current:Q}=this,Z=e.from(J),$={x:Z.x-Q.x,y:Z.y-Q.y},q=Date.now(),Y=q-t0(this,yZ),H=(K)=>Math.round(K/Y*100);JJ(()=>{e0(this,yZ,q),this.velocity={x:H($.x),y:H($.y)},super.current=Z})}reset(J=this.defaultValue){super.reset(e.from(J)),this.velocity={x:0,y:0}}};iQ=wq(J1);yZ=new WeakMap;N8(iQ,2,"delta",L8,nQ);N8(iQ,2,"direction",U8,nQ);B8(iQ,nQ);function fZ({x:J,y:Q},Z){let $=Math.abs(J),q=Math.abs(Q);if(typeof Z==="number")return Math.sqrt(K8($,2)+K8(q,2))>Z;if("x"in Z&&"y"in Z)return $>Z.x&&q>Z.y;if("x"in Z)return $>Z.x;if("y"in Z)return q>Z.y;return!1}var G8=((J)=>{return J.Horizontal="x",J.Vertical="y",J})(G8||{}),$1=Object.values(G8);var{create:Cq,defineProperty:X1,defineProperties:Tq,getOwnPropertyDescriptor:Pq,getOwnPropertyDescriptors:Eq,getOwnPropertySymbols:dZ}=Object,M8=Object.prototype.hasOwnProperty,w8=Object.prototype.propertyIsEnumerable,A8=(J,Q)=>(Q=Symbol[J])?Q:Symbol.for("Symbol."+J),TQ=(J)=>{throw TypeError(J)},Y1=(J,Q,Z)=>(Q in J)?X1(J,Q,{enumerable:!0,configurable:!0,writable:!0,value:Z}):J[Q]=Z,W1=(J,Q)=>{for(var Z in Q||(Q={}))if(M8.call(Q,Z))Y1(J,Z,Q[Z]);if(dZ){for(var Z of dZ(Q))if(w8.call(Q,Z))Y1(J,Z,Q[Z])}return J},B1=(J,Q)=>Tq(J,Eq(Q)),V8=(J,Q)=>X1(J,"name",{value:Q,configurable:!0}),I8=(J,Q)=>{var Z={};for(var $ in J)if(M8.call(J,$)&&Q.indexOf($)<0)Z[$]=J[$];if(J!=null&&dZ){for(var $ of dZ(J))if(Q.indexOf($)<0&&w8.call(J,$))Z[$]=J[$]}return Z},PQ=(J)=>{var Q;return[,,,Cq((Q=J==null?void 0:J[A8("metadata")])!=null?Q:null)]},j8=["class","method","getter","setter","accessor","field","value","get","set"],aQ=(J)=>J!==void 0&&typeof J!=="function"?TQ("Function expected"):J,Sq=(J,Q,Z,$,q)=>({kind:j8[J],name:Q,metadata:$,addInitializer:(Y)=>Z._?TQ("Already initialized"):q.push(aQ(Y||null))}),rJ=(J,Q)=>Y1(Q,A8("metadata"),J[3]),O=(J,Q,Z,$)=>{for(var q=0,Y=J[Q>>1],H=Y&&Y.length;q<H;q++)Q&1?Y[q].call(Z):$=Y[q].call(Z,$);return $},P=(J,Q,Z,$,q,Y)=>{var H,K,X,B,N,W=Q&7,G=!!(Q&8),L=!!(Q&16),F=W>3?J.length+1:W?G?1:2:0,z=j8[W+5],A=W>3&&(J[F-1]=[]),I=J[F]||(J[F]=[]),U=W&&(!L&&!G&&(q=q.prototype),W<5&&(W>3||!L)&&Pq(W<4?q:{get[Z](){return u(this,Y)},set[Z](V){return WJ(this,Y,V)}},Z));W?L&&W<4&&V8(Y,(W>2?"set ":W>1?"get ":"")+Z):V8(q,Z);for(var M=$.length-1;M>=0;M--){if(B=Sq(W,Z,X={},J[3],I),W){if(B.static=G,B.private=L,N=B.access={has:L?(V)=>kq(q,V):(V)=>(Z in V)},W^3)N.get=L?(V)=>(W^1?u:O8)(V,q,W^4?Y:U.get):(V)=>V[Z];if(W>2)N.set=L?(V,w)=>WJ(V,q,w,W^4?Y:U.set):(V,w)=>V[Z]=w}if(K=(0,$[M])(W?W<4?L?Y:U[z]:W>4?void 0:{get:U.get,set:U.set}:q,B),X._=1,W^4||K===void 0)aQ(K)&&(W>4?A.unshift(K):W?L?Y=K:U[z]=K:q=K);else if(typeof K!=="object"||K===null)TQ("Object expected");else aQ(H=K.get)&&(U.get=H),aQ(H=K.set)&&(U.set=H),aQ(H=K.init)&&A.unshift(H)}return W||rJ(J,q),U&&X1(q,Z,U),L?W^4?Y:U:q},N1=(J,Q,Z)=>Q.has(J)||TQ("Cannot "+Z),kq=(J,Q)=>Object(Q)!==Q?TQ('Cannot use the "in" operator on this value'):J.has(Q),u=(J,Q,Z)=>(N1(J,Q,"read from private field"),Z?Z.call(J):Q.get(J)),E=(J,Q,Z)=>Q.has(J)?TQ("Cannot add the same private member more than once"):Q instanceof WeakSet?Q.add(J):Q.set(J,Z),WJ=(J,Q,Z,$)=>(N1(J,Q,"write to private field"),$?$.call(J,Z):Q.set(J,Z),Z),O8=(J,Q,Z)=>(N1(J,Q,"access private method"),Z);function R8(J,Q){return{plugin:J,options:Q}}function EQ(J){return(Q)=>{return R8(J,Q)}}function CQ(J){if(typeof J==="function")return{plugin:J,options:void 0};return J}var D8,eQ,U1,bZ;D8=[T];var $J=class{constructor(J,Q){this.manager=J,this.options=Q,E(this,U1,O(eQ,8,this,!1)),O(eQ,11,this),E(this,bZ,new Set)}enable(){this.disabled=!1}disable(){this.disabled=!0}isDisabled(){return C(()=>{return this.disabled})}configure(J){this.options=J}registerEffect(J){let Q=o(J.bind(this));return u(this,bZ).add(Q),Q}destroy(){u(this,bZ).forEach((J)=>J())}static configure(J){return R8(this,J)}};eQ=PQ(null);U1=new WeakMap;bZ=new WeakMap;P(eQ,4,"disabled",D8,$J,U1);rJ(eQ,$J);var SQ=class extends $J{},gZ,q1=class{constructor(J){this.manager=J,this.instances=new Map,E(this,gZ,[])}get values(){return Array.from(this.instances.values())}set values(J){let Q=J.map(CQ).reduce(($,q)=>{let Y=$.find(({plugin:H})=>H===q.plugin);if(Y)return Y.options=q.options,$;return[...$,q]},[]),Z=Q.map(({plugin:$})=>$);for(let $ of u(this,gZ))if(!Z.includes($)){if($.prototype instanceof SQ)continue;this.unregister($)}for(let{plugin:$,options:q}of Q)this.register($,q);WJ(this,gZ,Z)}get(J){return this.instances.get(J)}register(J,Q){let Z=this.instances.get(J);if(Z){if(Z.options!==Q)Z.options=Q;return Z}let $=new J(this.manager,Q);return this.instances.set(J,$),$}unregister(J){let Q=this.instances.get(J);if(Q)Q.destroy(),this.instances.delete(J)}destroy(){for(let J of this.instances.values())J.destroy();this.instances.clear()}};gZ=new WeakMap;function xq(J,Q){if(J.priority===Q.priority){if(J.type===Q.type)return Q.value-J.value;return Q.type-J.type}return Q.priority-J.priority}var vZ=[],jQ,OQ,hq=class extends $J{constructor(J){super(J);E(this,jQ),E(this,OQ),this.computeCollisions=this.computeCollisions.bind(this),WJ(this,OQ,IJ(vZ)),this.destroy=nJ(()=>{let Q=this.computeCollisions(),Z=C(()=>this.manager.dragOperation.position.current);if(Q!==vZ){let $=u(this,jQ);if(WJ(this,jQ,Z),$&&Z.x==$.x&&Z.y==$.y)return}else WJ(this,jQ,void 0);u(this,OQ).value=Q},()=>{let{dragOperation:Q}=this.manager;if(Q.status.initialized)this.forceUpdate()})}forceUpdate(J=!0){C(()=>{if(J)u(this,OQ).value=this.computeCollisions();else WJ(this,jQ,void 0)})}computeCollisions(J,Q){let{registry:Z,dragOperation:$}=this.manager,{source:q,shape:Y,status:H}=$;if(!H.initialized||!Y)return vZ;let K=[],X=[];for(let B of J!=null?J:Z.droppables){if(B.disabled)continue;if(q&&!B.accepts(q))continue;let N=Q!=null?Q:B.collisionDetector;if(!N)continue;X.push(B),B.shape;let W=C(()=>N({droppable:B,dragOperation:$}));if(W){if(B.collisionPriority!=null)W.priority=B.collisionPriority;K.push(W)}}if(X.length===0)return vZ;return K.sort(xq),K}get collisions(){return u(this,OQ).value}};jQ=new WeakMap;OQ=new WeakMap;var C8,T8,P8,L1,E8,zJ,G1,DQ,V1,F1;P8=[T],T8=[T],C8=[T];var SJ=class J{constructor(Q,Z){E(this,G1,O(zJ,8,this)),O(zJ,11,this),E(this,DQ),E(this,V1,O(zJ,12,this)),O(zJ,15,this),E(this,F1,O(zJ,16,this)),O(zJ,19,this);let{effects:$,id:q,data:Y={},disabled:H=!1,register:K=!0}=Q,X=q;if(WJ(this,DQ,IJ(q)),this.manager=Z,this.data=Y,this.disabled=H,this.effects=()=>{var B;return[()=>{let{id:N,manager:W}=this;if(N===X)return;return X=N,W==null||W.registry.register(this),()=>W==null?void 0:W.registry.unregister(this)},...(B=$==null?void 0:$())!=null?B:[]]},this.register=this.register.bind(this),this.unregister=this.unregister.bind(this),this.destroy=this.destroy.bind(this),Z&&K)queueMicrotask(this.register)}get id(){var Q,Z;let $=u(this,DQ).value;return(Z=(Q=J.pendingIdChanges)==null?void 0:Q.get(this))!=null?Z:$}set id(Q){var Z,$;let q=($=(Z=J.pendingIdChanges)==null?void 0:Z.get(this))!=null?$:u(this,DQ).peek();if(Q===q)return;if(!J.pendingIdChanges)J.pendingIdChanges=new Map,queueMicrotask(()=>{var Y;return O8(Y=J,L1,E8).call(Y)});J.pendingIdChanges.set(this,Q)}register(){var Q;return(Q=this.manager)==null?void 0:Q.registry.register(this)}unregister(){var Q;(Q=this.manager)==null||Q.registry.unregister(this)}destroy(){var Q;(Q=this.manager)==null||Q.registry.unregister(this)}};zJ=PQ(null);L1=new WeakSet;E8=function(){let J=SJ.pendingIdChanges;if(SJ.pendingIdChanges=null,J)JJ(()=>{for(let[Q,Z]of J)u(Q,DQ).value=Z})};G1=new WeakMap;DQ=new WeakMap;V1=new WeakMap;F1=new WeakMap;P(zJ,4,"manager",P8,SJ,G1);P(zJ,4,"data",T8,SJ,V1);P(zJ,4,"disabled",C8,SJ,F1);E(SJ,L1);rJ(zJ,SJ);SJ.pendingIdChanges=null;var _Z=SJ,F8=class{constructor(){this.map=IJ(new Map),this.cleanupFunctions=new WeakMap,this.register=(J,Q)=>{let Z=this.map.peek(),$=Z.get(J),q=()=>this.unregister(J,Q);if($===Q)return q;if($){if($.id===J){let K=this.cleanupFunctions.get($);K==null||K(),this.cleanupFunctions.delete($)}}let Y=new Map(Z);for(let[K,X]of Z)if(X===Q&&K!==J){Y.delete(K);break}Y.set(J,Q),this.map.value=Y;let H=nJ(...Q.effects());return this.cleanupFunctions.set(Q,H),q},this.unregister=(J,Q)=>{let Z=this.map.peek();if(Z.get(J)!==Q)return;let $=this.cleanupFunctions.get(Q);$==null||$(),this.cleanupFunctions.delete(Q);let q=new Map(Z);q.delete(J),this.map.value=q}}[Symbol.iterator](){return this.map.peek().values()}get value(){return this.map.value.values()}has(J){return this.map.value.has(J)}get(J){return this.map.value.get(J)}destroy(){for(let J of this){let Q=this.cleanupFunctions.get(J);Q==null||Q(),J.destroy()}this.map.value=new Map}},S8,k8,x8,h8,y8,f8,K1,ZJ,z1,M1,w1,MJ=class extends(K1=_Z,f8=[T],y8=[T],h8=[T],x8=[h],k8=[h],S8=[h],K1){constructor(J,Q){var Z=J,{modifiers:$,type:q,sensors:Y,plugins:H,effects:K}=Z,X=I8(Z,["modifiers","type","sensors","plugins","effects"]);super(B1(W1({},X),{effects:()=>{var B;return[...(B=K==null?void 0:K())!=null?B:[],()=>{let{manager:N,plugins:W}=this;if(!N||!W)return;for(let G of W){let{plugin:L}=CQ(G);N.registry.plugins.register(L)}}]}}),Q);O(ZJ,5,this),E(this,z1,O(ZJ,8,this)),O(ZJ,11,this),E(this,M1,O(ZJ,12,this)),O(ZJ,15,this),E(this,w1,O(ZJ,16,this,this.isDragSource?"dragging":"idle")),O(ZJ,19,this),this.type=q,this.sensors=Y,this.modifiers=$,this.alignment=X.alignment,this.plugins=H}pluginConfig(J){if(!this.plugins)return;for(let Q of this.plugins){let Z=CQ(Q);if(Z.plugin===J)return Z.options}return}get isDropping(){return this.status==="dropping"&&this.isDragSource}get isDragging(){return this.status==="dragging"&&this.isDragSource}get isDragSource(){var J,Q;return((Q=(J=this.manager)==null?void 0:J.dragOperation.source)==null?void 0:Q.id)===this.id}};ZJ=PQ(K1);z1=new WeakMap;M1=new WeakMap;w1=new WeakMap;P(ZJ,4,"type",f8,MJ,z1);P(ZJ,4,"modifiers",y8,MJ,M1);P(ZJ,4,"status",h8,MJ,w1);P(ZJ,2,"isDropping",x8,MJ);P(ZJ,2,"isDragging",k8,MJ);P(ZJ,2,"isDragSource",S8,MJ);rJ(ZJ,MJ);var v8,b8,g8,u8,m8,p8,H1,c,A1,I1,j1,O1,R1,wJ=class extends(H1=_Z,p8=[T],m8=[T],u8=[T],g8=[T],b8=[T],v8=[h],H1){constructor(J,Q){var Z=J,{accept:$,collisionDetector:q,collisionPriority:Y,type:H}=Z,K=I8(Z,["accept","collisionDetector","collisionPriority","type"]);super(K,Q);O(c,5,this),E(this,A1,O(c,8,this)),O(c,11,this),E(this,I1,O(c,12,this)),O(c,15,this),E(this,j1,O(c,16,this)),O(c,19,this),E(this,O1,O(c,20,this)),O(c,23,this),E(this,R1,O(c,24,this)),O(c,27,this),this.accept=$,this.collisionDetector=q,this.collisionPriority=Y,this.type=H}accepts(J){let{accept:Q}=this;if(!Q)return!0;if(typeof Q==="function")return Q(J);if(!J.type)return!1;if(Array.isArray(Q))return Q.includes(J.type);return J.type===Q}get isDropTarget(){var J,Q;return((Q=(J=this.manager)==null?void 0:J.dragOperation.target)==null?void 0:Q.id)===this.id}};c=PQ(H1);A1=new WeakMap;I1=new WeakMap;j1=new WeakMap;O1=new WeakMap;R1=new WeakMap;P(c,4,"accept",p8,wJ,A1);P(c,4,"type",m8,wJ,I1);P(c,4,"collisionDetector",u8,wJ,j1);P(c,4,"collisionPriority",g8,wJ,O1);P(c,4,"shape",b8,wJ,R1);P(c,2,"isDropTarget",v8,wJ);rJ(c,wJ);var yq=class{constructor(){this.registry=new Map}addEventListener(J,Q){let{registry:Z}=this,$=new Set(Z.get(J));return $.add(Q),Z.set(J,$),()=>this.removeEventListener(J,Q)}removeEventListener(J,Q){let{registry:Z}=this,$=new Set(Z.get(J));$.delete(Q),Z.set(J,$)}dispatch(J,...Q){let{registry:Z}=this,$=Z.get(J);if(!$)return;for(let q of $)q(...Q)}},fq=class extends yq{constructor(J){super();this.manager=J}dispatch(J,Q){let Z=[Q,this.manager];super.dispatch(J,...Z)}};function uZ(J,Q=!0){let Z=!1;return B1(W1({},J),{cancelable:Q,get defaultPrevented(){return Z},preventDefault(){if(!Q)return;Z=!0}})}var vq=class extends SQ{constructor(J){super(J);let Q=($,q)=>$.map(({id:Y})=>Y).join("")===q.map(({id:Y})=>Y).join(""),Z=[];this.destroy=nJ(()=>{let{dragOperation:$,collisionObserver:q}=J;if($.status.initializing)Z=[],q.enable()},()=>{let{collisionObserver:$,monitor:q}=J,{collisions:Y}=$;if($.isDisabled())return;if(_Z.pendingIdChanges)return;let H=uZ({collisions:Y});if(q.dispatch("collision",H),H.defaultPrevented)return;if(Q(Y,Z))return;else Z=Y;let[K]=Y;C(()=>{var X;if((K==null?void 0:K.id)!==((X=J.dragOperation.target)==null?void 0:X.id))$.disable(),J.actions.setDropTarget(K==null?void 0:K.id).then(()=>{$.enable()})})})}},OJ=((J)=>{return J[J.Lowest=0]="Lowest",J[J.Low=1]="Low",J[J.Normal=2]="Normal",J[J.High=3]="High",J[J.Highest=4]="Highest",J})(OJ||{}),RJ=((J)=>{return J[J.Collision=0]="Collision",J[J.ShapeIntersection=1]="ShapeIntersection",J[J.PointerIntersection=2]="PointerIntersection",J})(RJ||{}),d8,_8,c8,l8,s8,o8,i8,GJ,D1;i8=[T],o8=[h],s8=[h],l8=[h],c8=[h],_8=[h],d8=[h];var kJ=class{constructor(){O(GJ,5,this),E(this,D1,O(GJ,8,this,"idle")),O(GJ,11,this)}get current(){return this.value}get idle(){return this.value==="idle"}get initializing(){return this.value==="initializing"}get initialized(){let{value:J}=this;return J!=="idle"&&J!=="initialization-pending"}get dragging(){return this.value==="dragging"}get dropped(){return this.value==="dropped"}set(J){this.value=J}};GJ=PQ(null);D1=new WeakMap;P(GJ,4,"value",i8,kJ,D1);P(GJ,2,"current",o8,kJ);P(GJ,2,"idle",s8,kJ);P(GJ,2,"initializing",l8,kJ);P(GJ,2,"initialized",c8,kJ);P(GJ,2,"dragging",_8,kJ);P(GJ,2,"dropped",d8,kJ);rJ(GJ,kJ);var bq=class{constructor(J){this.manager=J}setDragSource(J){let{dragOperation:Q}=this.manager;Q.sourceIdentifier=typeof J==="string"||typeof J==="number"?J:J.id}setDropTarget(J){return C(()=>{let{dragOperation:Q}=this.manager,Z=J!=null?J:null;if(Q.targetIdentifier===Z)return Promise.resolve(!1);Q.targetIdentifier=Z;let $=uZ({operation:Q.snapshot()});if(Q.status.dragging)this.manager.monitor.dispatch("dragover",$);return this.manager.renderer.rendering.then(()=>$.defaultPrevented)})}start(J){return C(()=>{let{dragOperation:Q}=this.manager;if(J.source!=null)this.setDragSource(J.source);if(!Q.source)throw Error("Cannot start a drag operation without a drag source");if(!Q.status.idle)throw Error("Cannot start a drag operation while another is active");let $=new AbortController,{event:q,coordinates:Y}=J;JJ(()=>{Q.status.set("initialization-pending"),Q.shape=null,Q.canceled=!1,Q.activatorEvent=q!=null?q:null,Q.position.reset(Y)});let H=uZ({operation:Q.snapshot()});if(this.manager.monitor.dispatch("beforedragstart",H),H.defaultPrevented)return Q.reset(),$.abort(),$;return Q.status.set("initializing"),Q.controller=$,this.manager.renderer.rendering.then(()=>{if($.signal.aborted)return;let{status:K}=Q;if(K.current!=="initializing")return;JJ(()=>{Q.status.set("dragging"),this.manager.monitor.dispatch("dragstart",{nativeEvent:q,operation:Q.snapshot(),cancelable:!1})})}),$})}move(J){return C(()=>{var Q,Z;let{dragOperation:$}=this.manager,{status:q,controller:Y}=$;if(!q.dragging||!Y||Y.signal.aborted)return;let H=uZ({nativeEvent:J.event,operation:$.snapshot(),by:J.by,to:J.to},(Q=J.cancelable)!=null?Q:!0);if((Z=J.propagate)!=null?Z:!0)this.manager.monitor.dispatch("dragmove",H);queueMicrotask(()=>{var K,X,B,N,W;if(H.defaultPrevented)return;let G=(W=J.to)!=null?W:{x:$.position.current.x+((X=(K=J.by)==null?void 0:K.x)!=null?X:0),y:$.position.current.y+((N=(B=J.by)==null?void 0:B.y)!=null?N:0)};$.position.current=G})})}stop(J={}){return C(()=>{var Q,Z;let{dragOperation:$}=this.manager,{controller:q}=$;if(!q||q.signal.aborted)return;let Y,H=()=>{let X={resume:()=>{},abort:()=>{}};return Y=new Promise((B,N)=>{X.resume=B,X.abort=N}),X};q.abort();let K=()=>{this.manager.renderer.rendering.then(()=>{$.status.set("dropped");let X=C(()=>{var N;return((N=$.source)==null?void 0:N.status)==="dropping"}),B=()=>{if($.controller===q)$.controller=void 0;$.reset()};if(X){let{source:N}=$,W=o(()=>{if((N==null?void 0:N.status)==="idle")W(),B()})}else this.manager.renderer.rendering.then(B)})};if($.canceled=(Q=J.canceled)!=null?Q:!1,this.manager.monitor.dispatch("dragend",{nativeEvent:J.event,operation:$.snapshot(),canceled:(Z=J.canceled)!=null?Z:!1,suspend:H}),Y)Y.then(K).catch(()=>$.reset());else K()})}},aJ=class extends $J{constructor(J,Q){super(J,Q);this.manager=J,this.options=Q}},n8=class extends AbortController{constructor(J,Q){super();this.constraints=J,this.onActivate=Q,this.activated=!1;for(let Z of J!=null?J:[])Z.controller=this}onEvent(J){var Q;if(this.activated)return;if((Q=this.constraints)==null?void 0:Q.length)for(let Z of this.constraints)Z.onEvent(J);else this.activate(J)}activate(J){if(this.activated)return;this.activated=!0,this.onActivate(J)}abort(J){this.activated=!1,super.abort(J)}},mZ,C1=class{constructor(J){this.options=J,E(this,mZ)}set controller(J){WJ(this,mZ,J),J.signal.addEventListener("abort",()=>this.abort())}activate(J){var Q;(Q=u(this,mZ))==null||Q.activate(J)}};mZ=new WeakMap;var z8=class extends $J{constructor(J,Q){super(J,Q);this.manager=J,this.options=Q}apply(J){return J.transform}},gq=class{constructor(J){this.draggables=new F8,this.droppables=new F8,this.plugins=new q1(J),this.sensors=new q1(J),this.modifiers=new q1(J)}register(J,Q){if(J instanceof MJ)return this.draggables.register(J.id,J);if(J instanceof wJ)return this.droppables.register(J.id,J);if(J.prototype instanceof z8)return this.modifiers.register(J,Q);if(J.prototype instanceof aJ)return this.sensors.register(J,Q);if(J.prototype instanceof $J)return this.plugins.register(J,Q);throw Error("Invalid instance type")}unregister(J){if(J instanceof _Z){if(J instanceof MJ)return this.draggables.unregister(J.id,J);if(J instanceof wJ)return this.droppables.unregister(J.id,J);return()=>{}}if(J.prototype instanceof z8)return this.modifiers.unregister(J);if(J.prototype instanceof aJ)return this.sensors.unregister(J);if(J.prototype instanceof $J)return this.plugins.unregister(J);throw Error("Invalid instance type")}destroy(){this.draggables.destroy(),this.droppables.destroy(),this.plugins.destroy(),this.sensors.destroy(),this.modifiers.destroy()}},a8,r8,t8,e8,J2,Q2,Z2,$2,q2,rQ,pZ,RQ,g,T1,P1,E1,S1,k1,tQ;q2=[h],$2=[T],Z2=[T],Q2=[T],J2=[T],e8=[T],t8=[h],r8=[h],a8=[h];var AJ=class{constructor(J){O(g,5,this),E(this,rQ),E(this,pZ),E(this,RQ,new jJ(void 0,(Q,Z)=>Q&&Z?Q.equals(Z):Q===Z)),this.status=new kJ,E(this,T1,O(g,8,this,!1)),O(g,11,this),E(this,P1,O(g,12,this,null)),O(g,15,this),E(this,E1,O(g,16,this,null)),O(g,19,this),E(this,S1,O(g,20,this,null)),O(g,23,this),E(this,k1,O(g,24,this,[])),O(g,27,this),this.position=new nQ({x:0,y:0}),E(this,tQ,{x:0,y:0}),WJ(this,rQ,J)}get shape(){let{current:J,initial:Q,previous:Z}=u(this,RQ);if(!J||!Q)return null;return{current:J,initial:Q,previous:Z}}set shape(J){if(!J)u(this,RQ).reset();else u(this,RQ).current=J}get source(){var J;let Q=this.sourceIdentifier;if(Q==null)return null;let Z=u(this,rQ).registry.draggables.get(Q);if(Z)WJ(this,pZ,Z);return(J=Z!=null?Z:u(this,pZ))!=null?J:null}get target(){var J;let Q=this.targetIdentifier;return Q!=null?(J=u(this,rQ).registry.droppables.get(Q))!=null?J:null:null}get transform(){let{x:J,y:Q}=this.position.delta,Z={x:J,y:Q};for(let $ of this.modifiers)Z=$.apply(B1(W1({},this.snapshot()),{transform:Z}));return WJ(this,tQ,Z),Z}snapshot(){return C(()=>({source:this.source,target:this.target,activatorEvent:this.activatorEvent,transform:u(this,tQ),shape:this.shape?hZ(this.shape):null,position:hZ(this.position),status:hZ(this.status),canceled:this.canceled}))}reset(){JJ(()=>{this.status.set("idle"),this.sourceIdentifier=null,this.targetIdentifier=null,u(this,RQ).reset(),this.position.reset({x:0,y:0}),WJ(this,tQ,{x:0,y:0}),this.modifiers=[]})}};g=PQ(null);rQ=new WeakMap;pZ=new WeakMap;RQ=new WeakMap;T1=new WeakMap;P1=new WeakMap;E1=new WeakMap;S1=new WeakMap;k1=new WeakMap;tQ=new WeakMap;P(g,2,"shape",q2,AJ);P(g,4,"canceled",$2,AJ,T1);P(g,4,"activatorEvent",Z2,AJ,P1);P(g,4,"sourceIdentifier",Q2,AJ,E1);P(g,4,"targetIdentifier",J2,AJ,S1);P(g,4,"modifiers",e8,AJ,k1);P(g,2,"source",t8,AJ);P(g,2,"target",r8,AJ);P(g,2,"transform",a8,AJ);rJ(g,AJ);var uq={get rendering(){return Promise.resolve()}};function VJ(J,Q){if(typeof J==="function")return J(Q);return J!=null?J:Q}var Y2=class{constructor(J){this.destroy=()=>{if(!this.dragOperation.status.idle)this.actions.stop({canceled:!0});this.dragOperation.modifiers.forEach((W)=>W.destroy()),this.registry.destroy(),this.collisionObserver.destroy()};var Q;let Z=J!=null?J:{},$=VJ(Z.plugins,[]),q=VJ(Z.sensors,[]),Y=VJ(Z.modifiers,[]),H=(Q=Z.renderer)!=null?Q:uq,K=new fq(this),X=new gq(this);this.registry=X,this.monitor=K,this.renderer=H,this.actions=new bq(this),this.dragOperation=new AJ(this),this.collisionObserver=new hq(this),this.plugins=[vq,...$],this.modifiers=Y,this.sensors=q;let{destroy:B}=this,N=nJ(()=>{var W,G,L;let F=C(()=>this.dragOperation.modifiers),z=this.modifiers;for(let A of F)if(!z.includes(A))A.destroy();this.dragOperation.modifiers=(L=(G=(W=this.dragOperation.source)==null?void 0:W.modifiers)==null?void 0:G.map((A)=>{let{plugin:I,options:U}=CQ(A);return new I(this,U)}))!=null?L:z});this.destroy=()=>{N(),B()}}get plugins(){return this.registry.plugins.values}set plugins(J){this.registry.plugins.values=J}get modifiers(){return this.registry.modifiers.values}set modifiers(J){this.registry.modifiers.values=J}get sensors(){return this.registry.sensors.values}set sensors(J){this.registry.sensors.values=J}};var U2=(J)=>{throw TypeError(J)},y1=(J,Q,Z)=>Q.has(J)||U2("Cannot "+Z),R=(J,Q,Z)=>(y1(J,Q,"read from private field"),Q.get(J)),YJ=(J,Q,Z)=>Q.has(J)?U2("Cannot add the same private member more than once"):Q instanceof WeakSet?Q.add(J):Q.set(J,Z),BJ=(J,Q,Z,$)=>(y1(J,Q,"write to private field"),Q.set(J,Z),Z),L2=(J,Q,Z)=>(y1(J,Q,"access private method"),Z);function eZ(J){if(!J)return!1;if(J instanceof KeyframeEffect)return!0;return"getKeyframes"in J&&typeof J.getKeyframes==="function"}function f1(J,Q){let Z=J.getAnimations(),$=null;for(let q of Z){if(q.playState!=="running")continue;let{effect:Y}=q,K=(eZ(Y)?Y.getKeyframes():[]).filter(Q);if(K.length>0)$=[K[K.length-1],q]}return $}function J0(J){let{width:Q,height:Z,top:$,left:q,bottom:Y,right:H}=J.getBoundingClientRect();return{width:Q,height:Z,top:$,left:q,bottom:Y,right:H}}function v1(J){let Q=Object.prototype.toString.call(J);return Q==="[object Window]"||Q==="[object global]"}function KZ(J){return"nodeType"in J}function NJ(J){var Q,Z,$;if(!J)return window;if(v1(J))return J;if(!KZ(J))return window;if("defaultView"in J)return(Q=J.defaultView)!=null?Q:window;return($=(Z=J.ownerDocument)==null?void 0:Z.defaultView)!=null?$:window}function Q0(J){let{Document:Q}=NJ(J);return J instanceof Q||"nodeType"in J&&J.nodeType===Node.DOCUMENT_NODE}function xJ(J){if(!J||v1(J))return!1;return J instanceof NJ(J).HTMLElement||"namespaceURI"in J&&typeof J.namespaceURI==="string"&&J.namespaceURI.endsWith("html")}function G2(J){return J instanceof NJ(J).SVGElement||"namespaceURI"in J&&typeof J.namespaceURI==="string"&&J.namespaceURI.endsWith("svg")}function QQ(J){if(!J)return document;if(v1(J))return J.document;if(!KZ(J))return document;if(Q0(J))return J;if(xJ(J)||G2(J))return J.ownerDocument;return document}function mq(J){var Q,Z,$,q;let{documentElement:Y}=QQ(J),H=NJ(J).visualViewport,K=(Q=H==null?void 0:H.width)!=null?Q:Y.clientWidth,X=(Z=H==null?void 0:H.height)!=null?Z:Y.clientHeight,B=($=H==null?void 0:H.offsetTop)!=null?$:0,N=(q=H==null?void 0:H.offsetLeft)!=null?q:0;return{top:B,left:N,right:N+K,bottom:B+X,width:K,height:X}}function pq(J,Q){if(dq(J)&&J.open===!1)return!1;let{overflow:Z,overflowX:$,overflowY:q}=getComputedStyle(J);return Z==="visible"&&$==="visible"&&q==="visible"}function dq(J){return J.tagName==="DETAILS"}function iZ(J,Q=J.getBoundingClientRect(),Z=0){var $,q,Y,H,K;let X=Q,{ownerDocument:B}=J,N=($=B.defaultView)!=null?$:window,W=J.parentElement;while(W&&W!==B.documentElement){if(!pq(W)){let M=W.getBoundingClientRect(),V=Z*(M.bottom-M.top),w=Z*(M.right-M.left),f=Z*(M.bottom-M.top),j=Z*(M.right-M.left);X={top:Math.max(X.top,M.top-V),right:Math.min(X.right,M.right+w),bottom:Math.min(X.bottom,M.bottom+f),left:Math.max(X.left,M.left-j),width:0,height:0},X.width=X.right-X.left,X.height=X.bottom-X.top}W=W.parentElement}let G=N.visualViewport,L=(q=G==null?void 0:G.offsetTop)!=null?q:0,F=(Y=G==null?void 0:G.offsetLeft)!=null?Y:0,z=(H=G==null?void 0:G.width)!=null?H:N.innerWidth,A=(K=G==null?void 0:G.height)!=null?K:N.innerHeight,I=Z*A,U=Z*z;if(X={top:Math.max(X.top,L-I),right:Math.min(X.right,F+z+U),bottom:Math.min(X.bottom,L+A+I),left:Math.max(X.left,F-U),width:0,height:0},X.width=X.right-X.left,X.height=X.bottom-X.top,X.width<0)X.width=0;if(X.height<0)X.height=0;return X}function ZQ(J){return{x:J.clientX,y:J.clientY}}var V2=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function nZ(J=document,Q=new Set){if(Q.has(J))return[];Q.add(J);let Z=[J];for(let $ of Array.from(J.querySelectorAll("iframe, frame")))try{let q=$.contentDocument;if(q&&!Q.has(q))Z.push(...nZ(q,Q))}catch(q){}try{let $=J.defaultView;if($&&$!==window.top){let q=$.parent;if(q&&q.document&&q.document!==J)Z.push(...nZ(q.document,Q))}}catch($){}return Z}function Z0(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function b1(){var J,Q;let Z=Z0()?window.visualViewport:null;return{x:(J=Z==null?void 0:Z.offsetLeft)!=null?J:0,y:(Q=Z==null?void 0:Z.offsetTop)!=null?Q:0}}function $0(J){if(!J||!KZ(J))return!1;return J instanceof NJ(J).ShadowRoot}function HZ(J){if(J&&KZ(J)){let Q=J.getRootNode();if($0(Q))return Q;else if(Q instanceof Document)return Q}return QQ(J)}function g1(J){return J.matchMedia("(prefers-reduced-motion: reduce)").matches}function F2(J){let Z=J.cloneNode(!0),$=Array.from(J.querySelectorAll("input, textarea, select, canvas, [contenteditable]"));return Array.from(Z.querySelectorAll("input, textarea, select, canvas, [contenteditable]")).forEach((Y,H)=>{let K=$[H];if(K2(Y)&&K2(K)){if(Y.type!=="file")Y.value=K.value;if(Y.type==="radio"&&Y.name)Y.name=`Cloned__${Y.name}`}if(H2(Y)&&H2(K)&&K.width>0&&K.height>0){let X=Y.getContext("2d");X==null||X.drawImage(K,0,0)}}),Z}function K2(J){return"value"in J}function H2(J){return J.tagName==="CANVAS"}function u1(J,{x:Q,y:Z}){let $=J.elementFromPoint(Q,Z);if(_q($)){let{contentDocument:q}=$;if(q){let{left:Y,top:H}=$.getBoundingClientRect();return u1(q,{x:Q-Y,y:Z-H})}}return $}function _q(J){return(J==null?void 0:J.tagName)==="IFRAME"}var m1=new WeakMap;function z2(J){return Boolean(J.closest(`
@@ -1,2 +1,2 @@
1
- import{Rg as W,Tg as b,Ug as Y,nh as Z}from"./chunk-wf4d1anc.js";import{Pk as R}from"./chunk-976v5s8y.js";var r=Z((u)=>({uploading:0,tasks:{},fileProgress:{},increment:()=>u((d)=>({uploading:d.uploading+1})),decrement:()=>u((d)=>({uploading:d.uploading-1})),startTask:(d,k,F)=>u((o)=>{let l={},s=0;F.forEach((f)=>{l[f.fileId]={fileId:f.fileId,name:f.name,loaded:0,total:f.size,status:"uploading"},s+=f.size});let g={...o.tasks,[d]:{taskId:d,name:k,loaded:0,total:s,files:l}},P={...o.fileProgress};return F.forEach((f)=>{P[f.fileId]=l[f.fileId]}),{tasks:g,fileProgress:P}}),updateFileProgress:(d,k,F)=>u((o)=>{let l=o.tasks[d];if(!l)return{};let s=l.files[k];if(!s)return{};let g={...s,loaded:F},P={...l.files,[k]:g},f=Object.values(P).reduce((p,w)=>p+w.loaded,0);return{tasks:{...o.tasks,[d]:{...l,loaded:f,files:P}},fileProgress:{...o.fileProgress,[k]:g}}}),completeFile:(d,k)=>u((F)=>{let o=F.tasks[d];if(!o)return{};let l=o.files[k];if(!l)return{};let s={...l,status:"completed",loaded:l.total},g={...o.files,[k]:s},P=Object.values(g).reduce((f,p)=>f+p.loaded,0);return{tasks:{...F.tasks,[d]:{...o,loaded:P,files:g}},fileProgress:{...F.fileProgress,[k]:s}}}),failFile:(d,k)=>u((F)=>{let o=F.tasks[d];if(!o)return{};let l=o.files[k];if(!l)return{};let s={...l,status:"failed"},g={...o.files,[k]:s},P=Object.values(g).reduce((f,p)=>f+p.loaded,0);return{tasks:{...F.tasks,[d]:{...o,loaded:P,files:g}},fileProgress:{...F.fileProgress,[k]:s}}})}));var a=R(W(),1);var q=10,Q=10,$=q*Q,S=({spriteUrl:u,thumbnailUrl:d,videoWidth:k,videoHeight:F,className:o=""})=>{let l=a.useRef(null),[s,g]=a.useState({width:0,height:0}),[P,f]=a.useState({width:0,height:0}),[p,w]=a.useState(!1),[c,E]=a.useState(!1),[V,J]=a.useState(!1),[K,N]=a.useState(0),[j,n]=a.useState(0);a.useEffect(()=>{if(!l.current)return;let t=new ResizeObserver((m)=>{for(let B of m)g({width:B.contentRect.width,height:B.contentRect.height})});return t.observe(l.current),()=>t.disconnect()},[]);let X=a.useCallback(()=>{if(c||V)return;J(!0);let t=new Image;t.src=u,t.onload=()=>{f({width:t.naturalWidth,height:t.naturalHeight}),E(!0),J(!1)},t.onerror=()=>{console.error("Failed to load sprite image"),J(!1)}},[u,c,V]),M=()=>{w(!0),X()},A=()=>{w(!1)},D=(t)=>{if(!l.current)return;let m=l.current.getBoundingClientRect(),B=t.clientX-m.left,y=Math.max(0,Math.min(B,m.width));n(y);let T=y/m.width,U=Math.min(Math.floor(T*$),$-1);N(U)},G=a.useMemo(()=>{if(s.width===0||s.height===0)return{};let t=k/F;if(P.width>0&&P.height>0){let z=P.width/q,i=P.height/Q;t=z/i}let m=s.width/s.height,B,y;if(m>t)y=s.height,B=y*t;else B=s.width,y=B/t;let T=Math.ceil(B),U=Math.ceil(y),I=T*q,O=U*Q,v=K%q,x=Math.floor(K/q),C=-(v*T),_=-(x*U);return{backgroundImage:`url(${u})`,backgroundSize:`${I}px ${O}px`,backgroundPosition:`${C}px ${_}px`,backgroundRepeat:"no-repeat",width:`${T}px`,height:`${U}px`,imageRendering:"auto"}},[s,k,F,K,u,P]);return Y("div",{ref:l,className:`relative w-full h-full overflow-hidden cursor-crosshair group bg-black select-none ${o}`,onMouseEnter:M,onMouseLeave:A,onMouseMove:D,children:[b("img",{src:d,alt:"Thumbnail",className:`absolute inset-0 w-full h-full object-contain transition-opacity duration-200 ${p&&c?"opacity-0":"opacity-100"}`,draggable:!1}),p&&!c&&b("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50 z-10",children:b("div",{className:"w-6 h-6 border-2 border-white/30 border-t-white rounded-full animate-spin"})}),c&&b("div",{className:`absolute inset-0 flex items-center justify-center transition-opacity duration-75 ${p?"opacity-100":"opacity-0"}`,children:b("div",{style:G})}),p&&b("div",{className:"absolute top-0 bottom-0 w-0.5 bg-red-500 shadow-[0_0_4px_rgba(255,0,0,0.8)] z-20 pointer-events-none",style:{transform:`translateX(${j}px)`}})]})};
1
+ import{Lh as Z,mh as W,oh as b,ph as Y}from"./chunk-nyhqy6q2.js";import{Vk as R}from"./chunk-0qkj838r.js";var r=Z((u)=>({uploading:0,tasks:{},fileProgress:{},increment:()=>u((d)=>({uploading:d.uploading+1})),decrement:()=>u((d)=>({uploading:d.uploading-1})),startTask:(d,k,F)=>u((o)=>{let l={},s=0;F.forEach((f)=>{l[f.fileId]={fileId:f.fileId,name:f.name,loaded:0,total:f.size,status:"uploading"},s+=f.size});let g={...o.tasks,[d]:{taskId:d,name:k,loaded:0,total:s,files:l}},P={...o.fileProgress};return F.forEach((f)=>{P[f.fileId]=l[f.fileId]}),{tasks:g,fileProgress:P}}),updateFileProgress:(d,k,F)=>u((o)=>{let l=o.tasks[d];if(!l)return{};let s=l.files[k];if(!s)return{};let g={...s,loaded:F},P={...l.files,[k]:g},f=Object.values(P).reduce((p,w)=>p+w.loaded,0);return{tasks:{...o.tasks,[d]:{...l,loaded:f,files:P}},fileProgress:{...o.fileProgress,[k]:g}}}),completeFile:(d,k)=>u((F)=>{let o=F.tasks[d];if(!o)return{};let l=o.files[k];if(!l)return{};let s={...l,status:"completed",loaded:l.total},g={...o.files,[k]:s},P=Object.values(g).reduce((f,p)=>f+p.loaded,0);return{tasks:{...F.tasks,[d]:{...o,loaded:P,files:g}},fileProgress:{...F.fileProgress,[k]:s}}}),failFile:(d,k)=>u((F)=>{let o=F.tasks[d];if(!o)return{};let l=o.files[k];if(!l)return{};let s={...l,status:"failed"},g={...o.files,[k]:s},P=Object.values(g).reduce((f,p)=>f+p.loaded,0);return{tasks:{...F.tasks,[d]:{...o,loaded:P,files:g}},fileProgress:{...F.fileProgress,[k]:s}}})}));var a=R(W(),1);var q=10,Q=10,$=q*Q,S=({spriteUrl:u,thumbnailUrl:d,videoWidth:k,videoHeight:F,className:o=""})=>{let l=a.useRef(null),[s,g]=a.useState({width:0,height:0}),[P,f]=a.useState({width:0,height:0}),[p,w]=a.useState(!1),[c,E]=a.useState(!1),[V,J]=a.useState(!1),[K,N]=a.useState(0),[j,n]=a.useState(0);a.useEffect(()=>{if(!l.current)return;let t=new ResizeObserver((m)=>{for(let B of m)g({width:B.contentRect.width,height:B.contentRect.height})});return t.observe(l.current),()=>t.disconnect()},[]);let X=a.useCallback(()=>{if(c||V)return;J(!0);let t=new Image;t.src=u,t.onload=()=>{f({width:t.naturalWidth,height:t.naturalHeight}),E(!0),J(!1)},t.onerror=()=>{console.error("Failed to load sprite image"),J(!1)}},[u,c,V]),M=()=>{w(!0),X()},A=()=>{w(!1)},D=(t)=>{if(!l.current)return;let m=l.current.getBoundingClientRect(),B=t.clientX-m.left,y=Math.max(0,Math.min(B,m.width));n(y);let T=y/m.width,U=Math.min(Math.floor(T*$),$-1);N(U)},G=a.useMemo(()=>{if(s.width===0||s.height===0)return{};let t=k/F;if(P.width>0&&P.height>0){let z=P.width/q,i=P.height/Q;t=z/i}let m=s.width/s.height,B,y;if(m>t)y=s.height,B=y*t;else B=s.width,y=B/t;let T=Math.ceil(B),U=Math.ceil(y),I=T*q,O=U*Q,v=K%q,x=Math.floor(K/q),C=-(v*T),_=-(x*U);return{backgroundImage:`url(${u})`,backgroundSize:`${I}px ${O}px`,backgroundPosition:`${C}px ${_}px`,backgroundRepeat:"no-repeat",width:`${T}px`,height:`${U}px`,imageRendering:"auto"}},[s,k,F,K,u,P]);return Y("div",{ref:l,className:`relative w-full h-full overflow-hidden cursor-crosshair group bg-black select-none ${o}`,onMouseEnter:M,onMouseLeave:A,onMouseMove:D,children:[b("img",{src:d,alt:"Thumbnail",className:`absolute inset-0 w-full h-full object-contain transition-opacity duration-200 ${p&&c?"opacity-0":"opacity-100"}`,draggable:!1}),p&&!c&&b("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50 z-10",children:b("div",{className:"w-6 h-6 border-2 border-white/30 border-t-white rounded-full animate-spin"})}),c&&b("div",{className:`absolute inset-0 flex items-center justify-center transition-opacity duration-75 ${p?"opacity-100":"opacity-0"}`,children:b("div",{style:G})}),p&&b("div",{className:"absolute top-0 bottom-0 w-0.5 bg-red-500 shadow-[0_0_4px_rgba(255,0,0,0.8)] z-20 pointer-events-none",style:{transform:`translateX(${j}px)`}})]})};
2
2
  export{S as eg,r as fg};
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{Rb as $Q}from"./chunk-891h8br6.js";import{Ub as c,Vb as XQ,Wb as l}from"./chunk-q72ax3m8.js";import"./chunk-3rmc8nz6.js";import{Yb as VQ}from"./chunk-s1n39qte.js";import{Zb as g}from"./chunk-mwh2n8yt.js";import{ec as GQ,fc as FQ}from"./chunk-w88219ex.js";import{hc as YQ}from"./chunk-2dsmsa6a.js";import"./chunk-ta7bfdrn.js";import{lc as u}from"./chunk-pxw97qbq.js";import{ke as NQ}from"./chunk-8qg47kj6.js";import{le as x,me as JQ,ne as zQ}from"./chunk-c45rh4hk.js";import"./chunk-ngd23mtc.js";import{af as ZQ}from"./chunk-q09dfja5.js";import{bf as QQ}from"./chunk-d2vxmn9v.js";import"./chunk-v3j7acwn.js";import"./chunk-976v5s8y.js";function i(Q){let $=Q.filter((G)=>G!==void 0);if($.length===0)return{cleanup:()=>{}};if($.length===1)return{signal:$[0],cleanup:()=>{}};let Z=new AbortController,Y=[],F=(G)=>{if(!Z.signal.aborted)Z.abort(G.reason)};for(let G of $){if(G.aborted){F(G);break}let V=()=>F(G);G.addEventListener("abort",V,{once:!0}),Y.push({signal:G,listener:V})}return{signal:Z.signal,cleanup:()=>{for(let{signal:G,listener:V}of Y)G.removeEventListener("abort",V)}}}var PQ={ftp:21,gopher:70,http:80,https:443,ws:80,wss:443};function v(Q,$){let Z=Q.toLowerCase(),Y=Q.toUpperCase();return $?.[Z]||$?.[Y]||g(Z)||g(Y)||""}function AQ(Q){if(Q instanceof URL)return Q;try{return new URL(Q)}catch{return}}function UQ(Q,$,Z){let Y=v("no_proxy",Z).toLowerCase();if(!Y)return!0;if(Y==="*")return!1;return Y.split(/[,\s]/).every((F)=>{if(!F)return!0;let G=F.match(/^(.+):(\d+)$/),V=G?G[1]:F,j=G?Number.parseInt(G[2],10):0;if(j&&j!==$)return!0;if(!/^[.*]/.test(V))return Q!==V;if(V.startsWith("*"))V=V.slice(1);return!Q.endsWith(V)})}function wQ(Q,$){let Z=AQ(Q);if(!Z?.protocol||!Z.host)return"";let Y=Z.protocol.split(":",1)[0],F=Z.host.replace(/:\d*$/,""),G=Number.parseInt(Z.port,10)||PQ[Y]||0;if(!UQ(F,G,$))return"";let V=v(`${Y}_proxy`,$)||v("all_proxy",$);if(V&&!V.includes("://"))V=`${Y}://${V}`;return V}var CQ="Unsupported proxy protocol. SOCKS and PAC proxy URLs are not supported; use an HTTP or HTTPS proxy URL.";function a(Q,$){let Z=wQ(Q,$);if(!Z)return;let Y;try{Y=new URL(Z)}catch(F){throw Error(`Invalid proxy URL ${JSON.stringify(Z)}: ${F instanceof Error?F.message:String(F)}`)}if(Y.protocol!=="http:"&&Y.protocol!=="https:")throw Error(`${CQ} Got ${Y.protocol}`);return Y}function EQ(){if(typeof process>"u"||!(process.versions?.node||process.versions?.bun))return null;return process.getBuiltinModule?.("node:os")??null}var T=EQ(),fQ="https://chatgpt.com/backend-api",MQ="https://api.openai.com/auth",SQ=0,n=1000,TQ=60000,hQ=15000,IQ=3,jQ=new Set(["openai","openai-codex","opencode"]),xQ=1009,kQ="websocket_connection_limit_reached",bQ=new Set(["completed","incomplete","failed","cancelled","queued","in_progress"]);function gQ(Q){return/GoUsageLimitError|FreeUsageLimitError|Monthly usage limit reached|available balance|insufficient_quota|out of budget|quota exceeded|billing/i.test(Q)}function vQ(Q,$){if(Q===429&&gQ($))return!1;if(Q===429||Q===500||Q===502||Q===503||Q===504)return!0;return/rate.?limit|overloaded|service.?unavailable|upstream.?connect|connection.?refused/i.test($)}function yQ(Q){let $=Q.get("retry-after-ms");if($!==null){let G=Number($);if(Number.isFinite(G))return Math.max(0,G)}let Z=Q.get("retry-after");if(!Z)return;let Y=Number(Z);if(Number.isFinite(Y))return Math.max(0,Y*1000);let F=Date.parse(Z);if(!Number.isNaN(F))return Math.max(0,F-Date.now());return}function mQ(Q,$){let Z=$?.maxRetryDelayMs??TQ;return Z>0?Math.min(Q,Z):Q}function r(Q,$){return new Promise((Z,Y)=>{if($?.aborted){Y(Error("Request was aborted"));return}let F=setTimeout(Z,Q);$?.addEventListener("abort",()=>{clearTimeout(F),Y(Error("Request was aborted"))})})}function t(Q){if(Q===void 0)return;if(!Number.isFinite(Q)||Q<0)throw Error(`Invalid timeoutMs: ${String(Q)}`);return Math.floor(Q)}function uQ(){if(typeof process>"u"||!(process.versions?.node||process.versions?.bun))return null;return process.getBuiltinModule?.("node:zlib")??null}function cQ(Q){let $=uQ();if(!$||typeof $.zstdCompressSync!=="function")return null;try{let Z=$.zstdCompressSync(Q,{params:{[$.constants.ZSTD_c_compressionLevel]:IQ}});return new Uint8Array(Z.buffer,Z.byteOffset,Z.byteLength)}catch{return null}}var lQ=(Q,$,Z)=>{let Y=new QQ;return(async()=>{let F={role:"assistant",content:[],api:"openai-codex-responses",provider:Q.provider,model:Q.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:"stop",timestamp:Date.now()};try{let G=Z?.apiKey;if(!G)throw Error(`No API key for provider: ${Q.provider}`);let V=qZ(G),j=pQ(Q,$,Z),N=await Z?.onPayload?.(j,Q);if(N!==void 0)j=N;let X=Z?.sessionId||_Z(),W=OZ(Q.headers,Z?.headers,V,G,Z?.sessionId),J=RZ(Q.headers,Z?.headers,V,G,X),_=JSON.stringify(j),z=t(Z?.timeoutMs),q=t(Z?.websocketConnectTimeoutMs),D=Z?.transport||"auto",B=D!=="sse"&&BQ(Z?.sessionId);if(B)s(Z?.sessionId);if(D!=="sse"&&!B){let O=!1,H=!1;while(!0){O=!1;try{if(await WZ(iQ(Q.baseUrl),j,J,F,Y,Q,()=>{O=!0},z,q,Z),Z?.signal?.aborted)throw Error("Request was aborted");Y.push({type:"done",reason:F.stopReason,message:F}),Y.end();return}catch(A){let C=Z?.signal?.aborted,S=!O&&rQ(A);if(!C&&S&&!H){H=!0;continue}if(C||nQ(A)&&!S)throw A;if(zQ(F,JQ("provider_transport_failure",A,{configuredTransport:D,fallbackTransport:O?void 0:"sse",eventsEmitted:O,phase:O?"after_message_stream_start":"before_message_stream_start",requestBytes:new TextEncoder().encode(_).byteLength})),YZ(Z?.sessionId,A),O)throw A;s(Z?.sessionId);break}}}let R=cQ(_);if(R)W.set("content-encoding","zstd");let K=R??_,L,w,b=Z?.maxRetries??SQ;for(let O=0;O<=b;O++){if(Z?.signal?.aborted)throw Error("Request was aborted");try{let H=z!==void 0&&z>0?AbortSignal.timeout(z):void 0,A=i([Z?.signal,H]);try{L=await fetch(DQ(Q.baseUrl),{method:"POST",headers:W,body:K,signal:A.signal})}catch(E){if(H?.aborted&&!Z?.signal?.aborted)throw Error(`Codex SSE response headers timed out after ${z}ms`);throw E}finally{A.cleanup()}if(await Z?.onResponse?.({status:L.status,headers:u(L.headers)},Q),L.ok)break;let C=await L.text();if(O<b&&vQ(L.status,C)){let E=yQ(L.headers),HQ=E===void 0?n*2**O:L.status===429?mQ(E,Z):E;await r(HQ,Z?.signal);continue}let S=new Response(C,{status:L.status,statusText:L.statusText}),d=await BZ(S);throw Error(d.friendlyMessage||d.message)}catch(H){if(H instanceof Error){if(H.name==="AbortError"||H.message==="Request was aborted")throw Error("Request was aborted")}if(w=H instanceof Error?H:Error(String(H)),O<b&&!w.message.includes("usage limit")){let A=n*2**O;await r(A,Z?.signal);continue}throw w}}if(!L?.ok)throw w??Error("Failed after retries");if(!L.body)throw Error("No response body");if(Y.push({type:"start",partial:F}),await aQ(L,F,Y,Q,Z),Z?.signal?.aborted)throw Error("Request was aborted");Y.push({type:"done",reason:F.stopReason,message:F}),Y.end()}catch(G){for(let V of F.content)delete V.partialJson;F.stopReason=Z?.signal?.aborted?"aborted":"error",F.errorMessage=FQ(GQ(G)),Y.push({type:"error",reason:F.stopReason,error:F}),Y.end()}})(),Y},bZ=(Q,$,Z)=>{let Y=Z?.apiKey;if(!Y)throw Error(`No API key for provider: ${Q.provider}`);let F=YQ(Q,$,Z,Y),G=Z?.reasoning?ZQ(Q,Z.reasoning):void 0;return lQ(Q,$,{...F,reasoningEffort:G==="off"?void 0:G})};function pQ(Q,$,Z){let Y=$Q($,Q.compat?.supportsToolSearch??!1),F=c(Q,$,jQ,{includeSystemPrompt:!1,deferredTools:Y.deferred}),G={model:Q.id,store:!1,stream:!0,instructions:$.systemPrompt||"You are a helpful assistant.",input:F,text:{verbosity:Z?.textVerbosity||"low"},include:["reasoning.encrypted_content"],prompt_cache_key:VQ(Z?.sessionId),tool_choice:Z?.toolChoice??"auto",parallel_tool_calls:!0};if(Z?.temperature!==void 0)G.temperature=Z.temperature;if(Z?.serviceTier!==void 0)G.service_tier=Z.serviceTier;if(Y.immediate.length>0)G.tools=XQ(Y.immediate,{strict:null});if(Z?.reasoningEffort!==void 0){let V=Z.reasoningEffort==="none"?Q.thinkingLevelMap?.off??"none":Q.thinkingLevelMap?.[Z.reasoningEffort]??Z.reasoningEffort;if(V!==null)G.reasoning={effort:V,summary:Z.reasoningSummary??"auto"}}return G}function dQ(Q,$){switch($){case"flex":return 0.5;case"priority":return Q.id==="gpt-5.5"?2.5:2;default:return 1}}function KQ(Q,$,Z){let Y=dQ(Z,$);if(Y===1)return;Q.cost.input*=Y,Q.cost.output*=Y,Q.cost.cacheRead*=Y,Q.cost.cacheWrite*=Y,Q.cost.total=Q.cost.input+Q.cost.output+Q.cost.cacheRead+Q.cost.cacheWrite}function LQ(Q,$){if(Q==="default"&&($==="flex"||$==="priority"))return $;return Q??$}function DQ(Q){let Z=(Q&&Q.trim().length>0?Q:fQ).replace(/\/+$/,"");if(Z.endsWith("/codex/responses"))return Z;if(Z.endsWith("/codex"))return`${Z}/responses`;return`${Z}/codex/responses`}function iQ(Q){let $=new URL(DQ(Q));if($.protocol==="https:")$.protocol="wss:";if($.protocol==="http:")$.protocol="ws:";return $.toString()}async function aQ(Q,$,Z,Y,F){await l(WQ(oQ(Q,F?.signal)),$,Z,Y,{serviceTier:F?.serviceTier,resolveServiceTier:LQ,applyServiceTierPricing:(G,V)=>KQ(G,V,Y)})}class f extends Error{code;payload;constructor(Q,$){super(Q);this.name="CodexApiError",this.code=$?.code,this.payload=$?.payload,this.cause=$?.cause}}class k extends Error{payload;constructor(Q,$){super(Q);this.name="CodexProtocolError",this.payload=$?.payload,this.cause=$?.cause}}function nQ(Q){return Q instanceof f||Q instanceof k}function rQ(Q){return Q instanceof f&&Q.code===kQ}function tQ(Q){let $=Q.error&&typeof Q.error==="object"?Q.error:void 0;return{code:typeof Q.code==="string"?Q.code:typeof $?.code==="string"?$.code:void 0,message:typeof Q.message==="string"?Q.message:typeof $?.message==="string"?$.message:void 0}}async function*WQ(Q){for await(let $ of Q){let Z=typeof $.type==="string"?$.type:void 0;if(!Z)continue;if(Z==="error"){let{code:Y,message:F}=tQ($);throw new f(`Codex error: ${F||Y||JSON.stringify($)}`,{code:Y,payload:$})}if(Z==="response.failed"){let Y=$.response,F=Y?.error?.code,G=Y?.error?.message;throw new f(G||"Codex response failed",{code:F,payload:$})}if(Z==="response.done"||Z==="response.completed"||Z==="response.incomplete"){let Y=$.response,F=Y?{...Y,status:sQ(Y.status)}:Y;yield{...$,type:"response.completed",response:F};return}yield $}}function sQ(Q){if(typeof Q!=="string")return;return bQ.has(Q)?Q:void 0}async function*oQ(Q,$){if(!Q.body)return;let Z=Q.body.getReader(),Y=new TextDecoder,F="",G=()=>{Z.cancel().catch(()=>{})};$?.addEventListener("abort",G,{once:!0});try{while(!0){if($?.aborted)throw Error("Request was aborted");let{done:V,value:j}=await Z.read();if($?.aborted)throw Error("Request was aborted");if(V)break;F+=Y.decode(j,{stream:!0});let N=F.indexOf(`
2
+ import{Rb as $Q}from"./chunk-891h8br6.js";import{Ub as c,Vb as XQ,Wb as l}from"./chunk-e3s3rz2e.js";import"./chunk-3rmc8nz6.js";import{Yb as VQ}from"./chunk-s1n39qte.js";import{Zb as g}from"./chunk-9avkn3x1.js";import{ec as GQ,fc as FQ}from"./chunk-w88219ex.js";import{hc as YQ}from"./chunk-2dsmsa6a.js";import"./chunk-ta7bfdrn.js";import{lc as u}from"./chunk-pxw97qbq.js";import{ke as NQ}from"./chunk-8qg47kj6.js";import{le as x,me as JQ,ne as zQ}from"./chunk-c45rh4hk.js";import"./chunk-ybhgmvxa.js";import{af as ZQ}from"./chunk-q09dfja5.js";import{bf as QQ}from"./chunk-d2vxmn9v.js";import"./chunk-bs0fjz3w.js";import"./chunk-0qkj838r.js";function i(Q){let $=Q.filter((G)=>G!==void 0);if($.length===0)return{cleanup:()=>{}};if($.length===1)return{signal:$[0],cleanup:()=>{}};let Z=new AbortController,Y=[],F=(G)=>{if(!Z.signal.aborted)Z.abort(G.reason)};for(let G of $){if(G.aborted){F(G);break}let V=()=>F(G);G.addEventListener("abort",V,{once:!0}),Y.push({signal:G,listener:V})}return{signal:Z.signal,cleanup:()=>{for(let{signal:G,listener:V}of Y)G.removeEventListener("abort",V)}}}var PQ={ftp:21,gopher:70,http:80,https:443,ws:80,wss:443};function v(Q,$){let Z=Q.toLowerCase(),Y=Q.toUpperCase();return $?.[Z]||$?.[Y]||g(Z)||g(Y)||""}function AQ(Q){if(Q instanceof URL)return Q;try{return new URL(Q)}catch{return}}function UQ(Q,$,Z){let Y=v("no_proxy",Z).toLowerCase();if(!Y)return!0;if(Y==="*")return!1;return Y.split(/[,\s]/).every((F)=>{if(!F)return!0;let G=F.match(/^(.+):(\d+)$/),V=G?G[1]:F,j=G?Number.parseInt(G[2],10):0;if(j&&j!==$)return!0;if(!/^[.*]/.test(V))return Q!==V;if(V.startsWith("*"))V=V.slice(1);return!Q.endsWith(V)})}function wQ(Q,$){let Z=AQ(Q);if(!Z?.protocol||!Z.host)return"";let Y=Z.protocol.split(":",1)[0],F=Z.host.replace(/:\d*$/,""),G=Number.parseInt(Z.port,10)||PQ[Y]||0;if(!UQ(F,G,$))return"";let V=v(`${Y}_proxy`,$)||v("all_proxy",$);if(V&&!V.includes("://"))V=`${Y}://${V}`;return V}var CQ="Unsupported proxy protocol. SOCKS and PAC proxy URLs are not supported; use an HTTP or HTTPS proxy URL.";function a(Q,$){let Z=wQ(Q,$);if(!Z)return;let Y;try{Y=new URL(Z)}catch(F){throw Error(`Invalid proxy URL ${JSON.stringify(Z)}: ${F instanceof Error?F.message:String(F)}`)}if(Y.protocol!=="http:"&&Y.protocol!=="https:")throw Error(`${CQ} Got ${Y.protocol}`);return Y}function EQ(){if(typeof process>"u"||!(process.versions?.node||process.versions?.bun))return null;return process.getBuiltinModule?.("node:os")??null}var T=EQ(),fQ="https://chatgpt.com/backend-api",MQ="https://api.openai.com/auth",SQ=0,n=1000,TQ=60000,hQ=15000,IQ=3,jQ=new Set(["openai","openai-codex","opencode"]),xQ=1009,kQ="websocket_connection_limit_reached",bQ=new Set(["completed","incomplete","failed","cancelled","queued","in_progress"]);function gQ(Q){return/GoUsageLimitError|FreeUsageLimitError|Monthly usage limit reached|available balance|insufficient_quota|out of budget|quota exceeded|billing/i.test(Q)}function vQ(Q,$){if(Q===429&&gQ($))return!1;if(Q===429||Q===500||Q===502||Q===503||Q===504)return!0;return/rate.?limit|overloaded|service.?unavailable|upstream.?connect|connection.?refused/i.test($)}function yQ(Q){let $=Q.get("retry-after-ms");if($!==null){let G=Number($);if(Number.isFinite(G))return Math.max(0,G)}let Z=Q.get("retry-after");if(!Z)return;let Y=Number(Z);if(Number.isFinite(Y))return Math.max(0,Y*1000);let F=Date.parse(Z);if(!Number.isNaN(F))return Math.max(0,F-Date.now());return}function mQ(Q,$){let Z=$?.maxRetryDelayMs??TQ;return Z>0?Math.min(Q,Z):Q}function r(Q,$){return new Promise((Z,Y)=>{if($?.aborted){Y(Error("Request was aborted"));return}let F=setTimeout(Z,Q);$?.addEventListener("abort",()=>{clearTimeout(F),Y(Error("Request was aborted"))})})}function t(Q){if(Q===void 0)return;if(!Number.isFinite(Q)||Q<0)throw Error(`Invalid timeoutMs: ${String(Q)}`);return Math.floor(Q)}function uQ(){if(typeof process>"u"||!(process.versions?.node||process.versions?.bun))return null;return process.getBuiltinModule?.("node:zlib")??null}function cQ(Q){let $=uQ();if(!$||typeof $.zstdCompressSync!=="function")return null;try{let Z=$.zstdCompressSync(Q,{params:{[$.constants.ZSTD_c_compressionLevel]:IQ}});return new Uint8Array(Z.buffer,Z.byteOffset,Z.byteLength)}catch{return null}}var lQ=(Q,$,Z)=>{let Y=new QQ;return(async()=>{let F={role:"assistant",content:[],api:"openai-codex-responses",provider:Q.provider,model:Q.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:"stop",timestamp:Date.now()};try{let G=Z?.apiKey;if(!G)throw Error(`No API key for provider: ${Q.provider}`);let V=qZ(G),j=pQ(Q,$,Z),N=await Z?.onPayload?.(j,Q);if(N!==void 0)j=N;let X=Z?.sessionId||_Z(),W=OZ(Q.headers,Z?.headers,V,G,Z?.sessionId),J=RZ(Q.headers,Z?.headers,V,G,X),_=JSON.stringify(j),z=t(Z?.timeoutMs),q=t(Z?.websocketConnectTimeoutMs),D=Z?.transport||"auto",B=D!=="sse"&&BQ(Z?.sessionId);if(B)s(Z?.sessionId);if(D!=="sse"&&!B){let O=!1,H=!1;while(!0){O=!1;try{if(await WZ(iQ(Q.baseUrl),j,J,F,Y,Q,()=>{O=!0},z,q,Z),Z?.signal?.aborted)throw Error("Request was aborted");Y.push({type:"done",reason:F.stopReason,message:F}),Y.end();return}catch(A){let C=Z?.signal?.aborted,S=!O&&rQ(A);if(!C&&S&&!H){H=!0;continue}if(C||nQ(A)&&!S)throw A;if(zQ(F,JQ("provider_transport_failure",A,{configuredTransport:D,fallbackTransport:O?void 0:"sse",eventsEmitted:O,phase:O?"after_message_stream_start":"before_message_stream_start",requestBytes:new TextEncoder().encode(_).byteLength})),YZ(Z?.sessionId,A),O)throw A;s(Z?.sessionId);break}}}let R=cQ(_);if(R)W.set("content-encoding","zstd");let K=R??_,L,w,b=Z?.maxRetries??SQ;for(let O=0;O<=b;O++){if(Z?.signal?.aborted)throw Error("Request was aborted");try{let H=z!==void 0&&z>0?AbortSignal.timeout(z):void 0,A=i([Z?.signal,H]);try{L=await fetch(DQ(Q.baseUrl),{method:"POST",headers:W,body:K,signal:A.signal})}catch(E){if(H?.aborted&&!Z?.signal?.aborted)throw Error(`Codex SSE response headers timed out after ${z}ms`);throw E}finally{A.cleanup()}if(await Z?.onResponse?.({status:L.status,headers:u(L.headers)},Q),L.ok)break;let C=await L.text();if(O<b&&vQ(L.status,C)){let E=yQ(L.headers),HQ=E===void 0?n*2**O:L.status===429?mQ(E,Z):E;await r(HQ,Z?.signal);continue}let S=new Response(C,{status:L.status,statusText:L.statusText}),d=await BZ(S);throw Error(d.friendlyMessage||d.message)}catch(H){if(H instanceof Error){if(H.name==="AbortError"||H.message==="Request was aborted")throw Error("Request was aborted")}if(w=H instanceof Error?H:Error(String(H)),O<b&&!w.message.includes("usage limit")){let A=n*2**O;await r(A,Z?.signal);continue}throw w}}if(!L?.ok)throw w??Error("Failed after retries");if(!L.body)throw Error("No response body");if(Y.push({type:"start",partial:F}),await aQ(L,F,Y,Q,Z),Z?.signal?.aborted)throw Error("Request was aborted");Y.push({type:"done",reason:F.stopReason,message:F}),Y.end()}catch(G){for(let V of F.content)delete V.partialJson;F.stopReason=Z?.signal?.aborted?"aborted":"error",F.errorMessage=FQ(GQ(G)),Y.push({type:"error",reason:F.stopReason,error:F}),Y.end()}})(),Y},bZ=(Q,$,Z)=>{let Y=Z?.apiKey;if(!Y)throw Error(`No API key for provider: ${Q.provider}`);let F=YQ(Q,$,Z,Y),G=Z?.reasoning?ZQ(Q,Z.reasoning):void 0;return lQ(Q,$,{...F,reasoningEffort:G==="off"?void 0:G})};function pQ(Q,$,Z){let Y=$Q($,Q.compat?.supportsToolSearch??!1),F=c(Q,$,jQ,{includeSystemPrompt:!1,deferredTools:Y.deferred}),G={model:Q.id,store:!1,stream:!0,instructions:$.systemPrompt||"You are a helpful assistant.",input:F,text:{verbosity:Z?.textVerbosity||"low"},include:["reasoning.encrypted_content"],prompt_cache_key:VQ(Z?.sessionId),tool_choice:Z?.toolChoice??"auto",parallel_tool_calls:!0};if(Z?.temperature!==void 0)G.temperature=Z.temperature;if(Z?.serviceTier!==void 0)G.service_tier=Z.serviceTier;if(Y.immediate.length>0)G.tools=XQ(Y.immediate,{strict:null});if(Z?.reasoningEffort!==void 0){let V=Z.reasoningEffort==="none"?Q.thinkingLevelMap?.off??"none":Q.thinkingLevelMap?.[Z.reasoningEffort]??Z.reasoningEffort;if(V!==null)G.reasoning={effort:V,summary:Z.reasoningSummary??"auto"}}return G}function dQ(Q,$){switch($){case"flex":return 0.5;case"priority":return Q.id==="gpt-5.5"?2.5:2;default:return 1}}function KQ(Q,$,Z){let Y=dQ(Z,$);if(Y===1)return;Q.cost.input*=Y,Q.cost.output*=Y,Q.cost.cacheRead*=Y,Q.cost.cacheWrite*=Y,Q.cost.total=Q.cost.input+Q.cost.output+Q.cost.cacheRead+Q.cost.cacheWrite}function LQ(Q,$){if(Q==="default"&&($==="flex"||$==="priority"))return $;return Q??$}function DQ(Q){let Z=(Q&&Q.trim().length>0?Q:fQ).replace(/\/+$/,"");if(Z.endsWith("/codex/responses"))return Z;if(Z.endsWith("/codex"))return`${Z}/responses`;return`${Z}/codex/responses`}function iQ(Q){let $=new URL(DQ(Q));if($.protocol==="https:")$.protocol="wss:";if($.protocol==="http:")$.protocol="ws:";return $.toString()}async function aQ(Q,$,Z,Y,F){await l(WQ(oQ(Q,F?.signal)),$,Z,Y,{serviceTier:F?.serviceTier,resolveServiceTier:LQ,applyServiceTierPricing:(G,V)=>KQ(G,V,Y)})}class f extends Error{code;payload;constructor(Q,$){super(Q);this.name="CodexApiError",this.code=$?.code,this.payload=$?.payload,this.cause=$?.cause}}class k extends Error{payload;constructor(Q,$){super(Q);this.name="CodexProtocolError",this.payload=$?.payload,this.cause=$?.cause}}function nQ(Q){return Q instanceof f||Q instanceof k}function rQ(Q){return Q instanceof f&&Q.code===kQ}function tQ(Q){let $=Q.error&&typeof Q.error==="object"?Q.error:void 0;return{code:typeof Q.code==="string"?Q.code:typeof $?.code==="string"?$.code:void 0,message:typeof Q.message==="string"?Q.message:typeof $?.message==="string"?$.message:void 0}}async function*WQ(Q){for await(let $ of Q){let Z=typeof $.type==="string"?$.type:void 0;if(!Z)continue;if(Z==="error"){let{code:Y,message:F}=tQ($);throw new f(`Codex error: ${F||Y||JSON.stringify($)}`,{code:Y,payload:$})}if(Z==="response.failed"){let Y=$.response,F=Y?.error?.code,G=Y?.error?.message;throw new f(G||"Codex response failed",{code:F,payload:$})}if(Z==="response.done"||Z==="response.completed"||Z==="response.incomplete"){let Y=$.response,F=Y?{...Y,status:sQ(Y.status)}:Y;yield{...$,type:"response.completed",response:F};return}yield $}}function sQ(Q){if(typeof Q!=="string")return;return bQ.has(Q)?Q:void 0}async function*oQ(Q,$){if(!Q.body)return;let Z=Q.body.getReader(),Y=new TextDecoder,F="",G=()=>{Z.cancel().catch(()=>{})};$?.addEventListener("abort",G,{once:!0});try{while(!0){if($?.aborted)throw Error("Request was aborted");let{done:V,value:j}=await Z.read();if($?.aborted)throw Error("Request was aborted");if(V)break;F+=Y.decode(j,{stream:!0});let N=F.indexOf(`
3
3
 
4
4
  `);while(N!==-1){let X=F.slice(0,N);F=F.slice(N+2);let W=X.split(`
5
5
  `).filter((J)=>J.startsWith("data:")).map((J)=>J.slice(5).trim());if(W.length>0){let J=W.join(`