@shumai-one/shumai 0.2.0 → 0.2.1

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 (156) hide show
  1. package/bin/{chunk-fcb14agg.js → chunk-044xt1se.js} +1 -1
  2. package/bin/chunk-0a5k9avd.js +4 -0
  3. package/bin/{chunk-xh2ntgmk.js → chunk-14fh4s1a.js} +2 -2
  4. package/bin/{chunk-y1xs4c5j.js → chunk-1ae8csk6.js} +1 -1
  5. package/bin/{chunk-yk3k5g5w.js → chunk-1w9dnk5p.js} +2 -2
  6. package/bin/chunk-211y81mp.js +1 -0
  7. package/bin/{chunk-twzgpwst.js → chunk-25d1g086.js} +2 -2
  8. package/bin/chunk-29pkpmvy.js +2 -0
  9. package/bin/{chunk-9rw65s3e.js → chunk-2djd6pq1.js} +2 -2
  10. package/bin/chunk-2dsmsa6a.js +3 -0
  11. package/bin/{chunk-08m8mzfa.js → chunk-2dz8nn9v.js} +1 -1
  12. package/bin/{chunk-mnv6pj0k.js → chunk-2xnys7v4.js} +2 -2
  13. package/bin/{chunk-a5kfa0k9.js → chunk-3rmc8nz6.js} +1 -1
  14. package/bin/{chunk-fwf8yne2.js → chunk-46c5xkmn.js} +2 -2
  15. package/bin/{chunk-axx5bh38.js → chunk-4fnak2zn.js} +2 -2
  16. package/bin/{chunk-gk7158n4.js → chunk-50ebjdkv.js} +2 -2
  17. package/bin/{chunk-29ectt6g.js → chunk-58aabg1f.js} +2 -2
  18. package/bin/{chunk-hb5v9ees.js → chunk-5j7axztv.js} +2 -2
  19. package/bin/chunk-5k03xpzq.js +6 -0
  20. package/bin/chunk-6724dtsx.js +2 -0
  21. package/bin/{chunk-q4f5vvtx.js → chunk-6h4ay2p8.js} +2 -2
  22. package/bin/chunk-6w5cn6p3.js +3 -0
  23. package/bin/{chunk-ps4h3387.js → chunk-75jka5v9.js} +2 -2
  24. package/bin/chunk-79n633wf.js +3 -0
  25. package/bin/chunk-7b17fb36.js +6 -0
  26. package/bin/{chunk-dypsm6m2.js → chunk-7h75r7ep.js} +1 -1
  27. package/bin/{chunk-pf8edn5x.js → chunk-7ktvhtp1.js} +2 -2
  28. package/bin/{chunk-6r9w7z15.js → chunk-7mnezagc.js} +2 -2
  29. package/bin/chunk-7we7ex0m.js +3 -0
  30. package/bin/{chunk-z42cyc20.js → chunk-82w2419d.js} +2 -2
  31. package/bin/chunk-861dz0bf.js +8 -0
  32. package/bin/chunk-891h8br6.js +3 -0
  33. package/bin/chunk-8abs8d48.js +12 -0
  34. package/bin/chunk-8qg47kj6.js +3 -0
  35. package/bin/{chunk-kbzm1pwx.js → chunk-976v5s8y.js} +1 -1
  36. package/bin/{chunk-8wv3kdz9.js → chunk-99db4j0k.js} +2 -2
  37. package/bin/{chunk-dgx2zxze.js → chunk-9bpjfkjf.js} +2 -2
  38. package/bin/chunk-9evm8x70.js +1 -0
  39. package/bin/{chunk-ec88pb09.js → chunk-9h3ds7rn.js} +2 -2
  40. package/bin/{chunk-ehfk24cf.js → chunk-9n783gva.js} +1 -1
  41. package/bin/chunk-a5s5ny4z.js +2 -0
  42. package/bin/{chunk-3rajscaz.js → chunk-ag35pxnb.js} +1 -1
  43. package/bin/{chunk-ajqsprm0.js → chunk-azfgjqjx.js} +2 -2
  44. package/bin/{chunk-s8d2045p.js → chunk-b9hb5jzt.js} +1 -1
  45. package/bin/chunk-bepnbw1g.js +2 -0
  46. package/bin/chunk-bg24g9kk.js +1 -0
  47. package/bin/{chunk-1fpqq6ed.js → chunk-c1v946wb.js} +2 -2
  48. package/bin/chunk-c45rh4hk.js +3 -0
  49. package/bin/{chunk-acxm86fh.js → chunk-cj5qwc9c.js} +1 -1
  50. package/bin/{chunk-j8q688sx.js → chunk-cpr05qng.js} +2 -2
  51. package/bin/chunk-d2vxmn9v.js +3 -0
  52. package/bin/chunk-dqtq9t8e.js +1 -0
  53. package/bin/{chunk-4kk5g619.js → chunk-dwf5e5g3.js} +2 -2
  54. package/bin/{chunk-w4y97tzy.js → chunk-dzm2f82x.js} +1 -1
  55. package/bin/chunk-e3c6hyz8.js +4 -0
  56. package/bin/chunk-fgnxtqtk.js +1 -0
  57. package/bin/chunk-fxvb6g2r.js +1 -0
  58. package/bin/{chunk-7ddaxdpf.js → chunk-ga0drqj7.js} +1 -1
  59. package/bin/{chunk-n5hfy93f.js → chunk-ga3mh3cd.js} +3 -3
  60. package/bin/chunk-gd5xwgp6.js +2 -0
  61. package/bin/chunk-hcz4snm7.js +8 -0
  62. package/bin/{chunk-dyybbn07.js → chunk-hmsb7ehr.js} +1 -1
  63. package/bin/{chunk-49ej1y67.js → chunk-hqptebzb.js} +2 -2
  64. package/bin/{chunk-mv79zk8q.js → chunk-hy50c4pw.js} +3 -3
  65. package/bin/chunk-jbde7evp.js +8 -0
  66. package/bin/{chunk-mjan6b09.js → chunk-jfjcxyhf.js} +3 -3
  67. package/bin/{chunk-hdk93ghf.js → chunk-jyjnt0s9.js} +2 -2
  68. package/bin/chunk-k1r17nfa.js +7 -0
  69. package/bin/{chunk-3qdn3pty.js → chunk-k5bekrrp.js} +1 -1
  70. package/bin/{chunk-3x62t1m0.js → chunk-kj751zje.js} +1 -1
  71. package/bin/chunk-kjkmh26f.js +1 -0
  72. package/bin/{chunk-m7jfszqt.js → chunk-m11g9hx7.js} +2 -2
  73. package/bin/{chunk-e5833tbd.js → chunk-m3dwydr3.js} +2 -2
  74. package/bin/{chunk-5a2maxwp.js → chunk-mg6fce5x.js} +2 -2
  75. package/bin/{chunk-xpqcvxej.js → chunk-mjncyjwf.js} +1 -1
  76. package/bin/{chunk-33ee1cvv.js → chunk-mk1jewvw.js} +2 -2
  77. package/bin/{chunk-gdm6y33a.js → chunk-mv8c5fky.js} +1 -1
  78. package/bin/chunk-mwh2n8yt.js +3 -0
  79. package/bin/{chunk-ysq64j13.js → chunk-n4meg9wb.js} +1 -1
  80. package/bin/{chunk-k5w64spz.js → chunk-nceqrqey.js} +2 -2
  81. package/bin/{chunk-wv4fe1fj.js → chunk-ngd23mtc.js} +2 -2
  82. package/bin/{chunk-m54p1cvp.js → chunk-p3emandj.js} +2 -2
  83. package/bin/{chunk-1wq9hjjr.js → chunk-phw4ne8b.js} +1 -1
  84. package/bin/{chunk-22dje1f5.js → chunk-pmx9760x.js} +1 -1
  85. package/bin/chunk-pv76qkym.js +2 -0
  86. package/bin/{chunk-d1ka11hc.js → chunk-pvy0gccg.js} +1 -1
  87. package/bin/chunk-pxw97qbq.js +3 -0
  88. package/bin/chunk-q09dfja5.js +3 -0
  89. package/bin/chunk-q72ax3m8.js +12 -0
  90. package/bin/{chunk-zsdwska1.js → chunk-q9sgjs4d.js} +1 -1
  91. package/bin/chunk-qag3w2dd.js +3 -0
  92. package/bin/{chunk-2cmg5sfn.js → chunk-qf7n519d.js} +2 -2
  93. package/bin/{chunk-3n1k9qt5.js → chunk-qj2kpkje.js} +1 -1
  94. package/bin/{chunk-cp18trqb.js → chunk-qjjr3fff.js} +2 -2
  95. package/bin/{chunk-fwe9g818.js → chunk-s1n39qte.js} +1 -1
  96. package/bin/chunk-s2725w64.js +1 -0
  97. package/bin/{chunk-09wp20mv.js → chunk-saq5797j.js} +1 -1
  98. package/bin/{chunk-d2y3rbjm.js → chunk-sp75qe28.js} +1 -1
  99. package/bin/{chunk-4hnrd4qh.js → chunk-sy8rqacm.js} +1 -1
  100. package/bin/{chunk-6mn3jqm9.js → chunk-t1mxqskx.js} +2 -2
  101. package/bin/chunk-t84t3v6q.js +1 -0
  102. package/bin/{chunk-eadb78m8.js → chunk-ta7bfdrn.js} +1 -1
  103. package/bin/{chunk-2s5a64nr.js → chunk-ttsqdsxr.js} +2 -2
  104. package/bin/chunk-v05d1aeq.js +2 -0
  105. package/bin/{chunk-yhj8c5re.js → chunk-v3j7acwn.js} +2 -2
  106. package/bin/{chunk-kpy0kpna.js → chunk-v98yavtp.js} +2 -2
  107. package/bin/chunk-vreq89j6.js +1 -0
  108. package/bin/{chunk-pqm0g14r.js → chunk-w1d5vmtc.js} +2 -2
  109. package/bin/chunk-w88219ex.js +3 -0
  110. package/bin/{chunk-vgvmt2m1.js → chunk-wbhsmhgp.js} +2 -2
  111. package/bin/{chunk-nwtb6dt1.js → chunk-wf4d1anc.js} +5 -5
  112. package/bin/{chunk-frm7vz6v.js → chunk-wfex9jw0.js} +2 -2
  113. package/bin/chunk-x9q2vzn8.js +7 -0
  114. package/bin/chunk-xv4mfppt.js +2 -0
  115. package/bin/{chunk-r3n9zpfw.js → chunk-y4s3xr4n.js} +2 -2
  116. package/bin/{chunk-9n0etqsy.js → chunk-ydagqpny.js} +1 -1
  117. package/bin/{chunk-aakzq0w1.js → chunk-ymyyap80.js} +1 -1
  118. package/bin/{chunk-5tmf3c0g.js → chunk-zn9jbc6t.js} +2 -2
  119. package/bin/{chunk-3rt9mnj3.js → chunk-ztmj61z9.js} +1 -1
  120. package/bin/shumai-app.html +1 -1
  121. package/bin/shumai-app.js +248 -247
  122. package/package.json +7 -7
  123. package/prisma/migrations/20260722022359_add_skill_permission/migration.sql +2 -0
  124. package/prisma/schema.prisma +1 -0
  125. package/bin/chunk-0at8vxt5.js +0 -3
  126. package/bin/chunk-0zv7f9ca.js +0 -2
  127. package/bin/chunk-2k4vp654.js +0 -2
  128. package/bin/chunk-2tbya52d.js +0 -2
  129. package/bin/chunk-2vs3evc7.js +0 -14
  130. package/bin/chunk-33169en9.js +0 -8
  131. package/bin/chunk-3m39v371.js +0 -1
  132. package/bin/chunk-6c4c7t0n.js +0 -1
  133. package/bin/chunk-6frqqxkv.js +0 -1
  134. package/bin/chunk-7rhjej0x.js +0 -3
  135. package/bin/chunk-7wvgtw25.js +0 -3
  136. package/bin/chunk-8s0ae37g.js +0 -1
  137. package/bin/chunk-94h8644q.js +0 -2
  138. package/bin/chunk-ac2ky3q0.js +0 -12
  139. package/bin/chunk-cthpdt54.js +0 -11
  140. package/bin/chunk-d0earxhc.js +0 -4
  141. package/bin/chunk-d0n8nxp3.js +0 -3
  142. package/bin/chunk-d22pyc5n.js +0 -1
  143. package/bin/chunk-dmgjse02.js +0 -4
  144. package/bin/chunk-g7wrxnmd.js +0 -1
  145. package/bin/chunk-jrvrg4fx.js +0 -1
  146. package/bin/chunk-k712q1zj.js +0 -2
  147. package/bin/chunk-kef0rnwn.js +0 -1
  148. package/bin/chunk-n296vcfw.js +0 -3
  149. package/bin/chunk-n6jgyv4y.js +0 -3
  150. package/bin/chunk-nar4s9v9.js +0 -3
  151. package/bin/chunk-nn8e9j7c.js +0 -1
  152. package/bin/chunk-qqesrgjk.js +0 -7
  153. package/bin/chunk-qz9xht6d.js +0 -2
  154. package/bin/chunk-symna5cj.js +0 -1
  155. package/bin/chunk-w4t9n9te.js +0 -6
  156. package/bin/chunk-z14hh99h.js +0 -2
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{rj as r,sj as p,tj as d,uj as i}from"./chunk-gdm6y33a.js";import{Aj as n}from"./chunk-fwe9g818.js";import{Bj as b}from"./chunk-w4y97tzy.js";import{Ej as I}from"./chunk-1fpqq6ed.js";import"./chunk-yhj8c5re.js";import{Gj as u}from"./chunk-n296vcfw.js";import{Sj as m,Uj as c}from"./chunk-08m8mzfa.js";import{Vj as h,Wj as k,Xj as g}from"./chunk-3rajscaz.js";import{Yj as w}from"./chunk-eadb78m8.js";import"./chunk-kbzm1pwx.js";function JJ(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 x(J){return J.type==="text"}function QJ(J){return J.type==="thinking"}function XJ(J){return J.type==="toolCall"}function YJ(J){return J.type==="image"}function a(J){if(J)return J;if(typeof process<"u"&&process.env.PI_CACHE_RETENTION==="long")return"long";return"short"}var _J=(J,X,Q)=>{let Y=new g;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 N=Q?.apiKey;if(!N)throw Error(`No API key for provider: ${J.provider}`);let V=T(J),_=a(Q?.cacheRetention),q=_==="none"?void 0:Q?.sessionId,j=$J(J,X,N,Q?.headers,q,V),W=qJ(J,X,Q,V,_),H=await Q?.onPayload?.(W,J);if(H!==void 0)W=H;let K={...Q?.signal?{signal:Q.signal}:{},...Q?.timeoutMs!==void 0?{timeout:Q.timeoutMs}:{},maxRetries:Q?.maxRetries??0},{data:P,response:A}=await j.chat.completions.create(W,K).withResponse();await Q?.onResponse?.({status:A.status,headers:u(A.headers)},J),Y.push({type:"start",partial:$});let S=null,L=null,O=!1,M=new Map,f=new Map,U=$.content,v=(z)=>U.indexOf(z),s=(z)=>{let Z=v(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=I(z.partialArgs),delete z.partialArgs,delete z.streamIndex,Y.push({type:"toolcall_end",contentIndex:Z,toolCall:z,partial:$})},t=()=>{if(!S)S={type:"text",text:""},U.push(S),Y.push({type:"text_start",contentIndex:v(S),partial:$});return S},e=(z)=>{if(!L)L={type:"thinking",thinking:"",thinkingSignature:z},U.push(L),Y.push({type:"thinking_start",contentIndex:v(L),partial:$});return L},o=(z)=>{let Z=typeof z.index==="number"?z.index:void 0,G=Z!==void 0?M.get(Z):void 0;if(!G&&z.id)G=f.get(z.id);if(!G){if(G={type:"toolCall",id:z.id||"",name:z.function?.name||"",arguments:{},partialArgs:"",streamIndex:Z},Z!==void 0)M.set(Z,G);if(z.id)f.set(z.id,G);U.push(G),Y.push({type:"toolcall_start",contentIndex:v(G),partial:$})}if(Z!==void 0&&G.streamIndex===void 0)G.streamIndex=Z,M.set(Z,G);if(z.id)f.set(z.id,G);return G};for await(let z of P){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=C(z.usage,J);let Z=Array.isArray(z.choices)?z.choices[0]:void 0;if(!Z)continue;if(!z.usage&&Z.usage)$.usage=C(Z.usage,J);if(Z.finish_reason){let G=DJ(Z.finish_reason);if($.stopReason=G.stopReason,G.errorMessage)$.errorMessage=G.errorMessage;O=!0}if(Z.delta){if(Z.delta.content!==null&&Z.delta.content!==void 0&&Z.delta.content.length>0){let E=t();E.text+=Z.delta.content,Y.push({type:"text_delta",contentIndex:v(E),delta:Z.delta.content,partial:$})}let G=["reasoning_content","reasoning","reasoning_text"],R=Z.delta,y=null;for(let E of G){let D=R[E];if(typeof D==="string"&&D.length>0){y=E;break}}if(y){let E=R[y];if(typeof E==="string"&&E.length>0){let D=J.provider==="opencode-go"&&y==="reasoning"?"reasoning_content":y,F=e(D);F.thinking+=E,Y.push({type:"thinking_delta",contentIndex:v(F),delta:E,partial:$})}}if(Z?.delta?.tool_calls)for(let E of Z.delta.tool_calls){let D=o(E);if(!D.id&&E.id)D.id=E.id,f.set(E.id,D);if(!D.name&&E.function?.name)D.name=E.function.name;let F="";if(E.function?.arguments)F=E.function.arguments,D.partialArgs=(D.partialArgs??"")+E.function.arguments,D.arguments=I(D.partialArgs);Y.push({type:"toolcall_delta",contentIndex:v(D),delta:F,partial:$})}let B=Z.delta.reasoning_details;if(B&&Array.isArray(B)){for(let E of B)if(E.type==="reasoning.encrypted"&&E.id&&E.data){let D=$.content.find((F)=>F.type==="toolCall"&&F.id===E.id);if(D)D.thoughtSignature=JSON.stringify(E)}}}}for(let z of U)s(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(!O)throw Error("Stream ended without finish_reason");Y.push({type:"done",reason:$.stopReason,message:$}),Y.end()}catch(N){for(let _ of $.content)delete _.index,delete _.partialArgs,delete _.streamIndex;$.stopReason=Q?.signal?.aborted?"aborted":"error",$.errorMessage=N instanceof Error?N.message:JSON.stringify(N);let V=N?.error?.metadata?.raw;if(V)$.errorMessage+=`
2
+ import{hk as r,ik as p,jk as d,kk as i}from"./chunk-mv8c5fky.js";import{qk as n}from"./chunk-ydagqpny.js";import{rk as b}from"./chunk-dzm2f82x.js";import{uk as I}from"./chunk-c1v946wb.js";import"./chunk-v3j7acwn.js";import{wk as u}from"./chunk-ga0drqj7.js";import{Ik as m,Kk as c}from"./chunk-2dz8nn9v.js";import{Lk as h,Mk as k,Nk as g}from"./chunk-ag35pxnb.js";import{Ok as w}from"./chunk-pmx9760x.js";import"./chunk-976v5s8y.js";function JJ(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 x(J){return J.type==="text"}function QJ(J){return J.type==="thinking"}function XJ(J){return J.type==="toolCall"}function YJ(J){return J.type==="image"}function a(J){if(J)return J;if(typeof process<"u"&&process.env.PI_CACHE_RETENTION==="long")return"long";return"short"}var _J=(J,X,Q)=>{let Y=new g;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 N=Q?.apiKey;if(!N)throw Error(`No API key for provider: ${J.provider}`);let V=T(J),_=a(Q?.cacheRetention),q=_==="none"?void 0:Q?.sessionId,j=$J(J,X,N,Q?.headers,q,V),W=qJ(J,X,Q,V,_),H=await Q?.onPayload?.(W,J);if(H!==void 0)W=H;let K={...Q?.signal?{signal:Q.signal}:{},...Q?.timeoutMs!==void 0?{timeout:Q.timeoutMs}:{},maxRetries:Q?.maxRetries??0},{data:P,response:A}=await j.chat.completions.create(W,K).withResponse();await Q?.onResponse?.({status:A.status,headers:u(A.headers)},J),Y.push({type:"start",partial:$});let S=null,L=null,O=!1,M=new Map,f=new Map,U=$.content,v=(z)=>U.indexOf(z),s=(z)=>{let Z=v(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=I(z.partialArgs),delete z.partialArgs,delete z.streamIndex,Y.push({type:"toolcall_end",contentIndex:Z,toolCall:z,partial:$})},t=()=>{if(!S)S={type:"text",text:""},U.push(S),Y.push({type:"text_start",contentIndex:v(S),partial:$});return S},e=(z)=>{if(!L)L={type:"thinking",thinking:"",thinkingSignature:z},U.push(L),Y.push({type:"thinking_start",contentIndex:v(L),partial:$});return L},o=(z)=>{let Z=typeof z.index==="number"?z.index:void 0,G=Z!==void 0?M.get(Z):void 0;if(!G&&z.id)G=f.get(z.id);if(!G){if(G={type:"toolCall",id:z.id||"",name:z.function?.name||"",arguments:{},partialArgs:"",streamIndex:Z},Z!==void 0)M.set(Z,G);if(z.id)f.set(z.id,G);U.push(G),Y.push({type:"toolcall_start",contentIndex:v(G),partial:$})}if(Z!==void 0&&G.streamIndex===void 0)G.streamIndex=Z,M.set(Z,G);if(z.id)f.set(z.id,G);return G};for await(let z of P){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=C(z.usage,J);let Z=Array.isArray(z.choices)?z.choices[0]:void 0;if(!Z)continue;if(!z.usage&&Z.usage)$.usage=C(Z.usage,J);if(Z.finish_reason){let G=DJ(Z.finish_reason);if($.stopReason=G.stopReason,G.errorMessage)$.errorMessage=G.errorMessage;O=!0}if(Z.delta){if(Z.delta.content!==null&&Z.delta.content!==void 0&&Z.delta.content.length>0){let E=t();E.text+=Z.delta.content,Y.push({type:"text_delta",contentIndex:v(E),delta:Z.delta.content,partial:$})}let G=["reasoning_content","reasoning","reasoning_text"],R=Z.delta,y=null;for(let E of G){let D=R[E];if(typeof D==="string"&&D.length>0){y=E;break}}if(y){let E=R[y];if(typeof E==="string"&&E.length>0){let D=J.provider==="opencode-go"&&y==="reasoning"?"reasoning_content":y,F=e(D);F.thinking+=E,Y.push({type:"thinking_delta",contentIndex:v(F),delta:E,partial:$})}}if(Z?.delta?.tool_calls)for(let E of Z.delta.tool_calls){let D=o(E);if(!D.id&&E.id)D.id=E.id,f.set(E.id,D);if(!D.name&&E.function?.name)D.name=E.function.name;let F="";if(E.function?.arguments)F=E.function.arguments,D.partialArgs=(D.partialArgs??"")+E.function.arguments,D.arguments=I(D.partialArgs);Y.push({type:"toolcall_delta",contentIndex:v(D),delta:F,partial:$})}let B=Z.delta.reasoning_details;if(B&&Array.isArray(B)){for(let E of B)if(E.type==="reasoning.encrypted"&&E.id&&E.data){let D=$.content.find((F)=>F.type==="toolCall"&&F.id===E.id);if(D)D.thoughtSignature=JSON.stringify(E)}}}}for(let z of U)s(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(!O)throw Error("Stream ended without finish_reason");Y.push({type:"done",reason:$.stopReason,message:$}),Y.end()}catch(N){for(let _ of $.content)delete _.index,delete _.partialArgs,delete _.streamIndex;$.stopReason=Q?.signal?.aborted?"aborted":"error",$.errorMessage=N instanceof Error?N.message:JSON.stringify(N);let V=N?.error?.metadata?.raw;if(V)$.errorMessage+=`
3
3
  ${V}`;Y.push({type:"error",reason:$.stopReason,error:$}),Y.end()}})(),Y},MJ=(J,X,Q)=>{let Y=Q?.apiKey;if(!Y)throw Error(`No API key for provider: ${J.provider}`);let $=m(J,Q,Y),N=Q?.reasoning?k(J,Q.reasoning):void 0,V=N==="off"?void 0:N,_=Q?.toolChoice;return _J(J,X,{...$,reasoningEffort:V,toolChoice:_})};function $J(J,X,Q,Y,$,N=T(J)){let V={...J.headers};if(J.provider==="github-copilot"){let q=d(X.messages),j=i({messages:X.messages,hasImages:q});Object.assign(V,j)}if($&&N.sendSessionAffinityHeaders)V.session_id=$,V["x-client-request-id"]=$,V["x-session-affinity"]=$;if(Y)Object.assign(V,Y);let _=J.provider==="cloudflare-ai-gateway"?{...V,Authorization:V.Authorization??null,"cf-aig-authorization":`Bearer ${Q}`}:V;return new b({apiKey:Q,baseURL:r(J.provider)?p(J):J.baseUrl,dangerouslyAllowBrowser:!0,defaultHeaders:_})}function qJ(J,X,Q,Y=T(J),$=a(Q?.cacheRetention)){let N=WJ(J,X,Y),V=zJ(Y,$),_={model:J.id,messages:N,stream:!0,prompt_cache_key:J.baseUrl.includes("api.openai.com")&&$!=="none"||$==="long"&&Y.supportsLongCacheRetention?n(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=GJ(X.tools,Y),Y.zaiToolStream)_.tool_stream=!0}else if(JJ(X.messages))_.tools=[];if(V)LJ(N,_.tools,V);if(Q?.toolChoice)_.tool_choice=Q.toolChoice;if(Y.thinkingFormat==="zai"&&J.reasoning)_.enable_thinking=!!Q?.reasoningEffort;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==="deepseek"&&J.reasoning){if(_.thinking={type:Q?.reasoningEffort?"enabled":"disabled"},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==="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.baseUrl.includes("openrouter.ai")&&J.compat?.openRouterRouting)_.provider=J.compat.openRouterRouting;if(J.baseUrl.includes("ai-gateway.vercel.sh")&&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 zJ(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 LJ(J,X,Q){NJ(J,Q),ZJ(X,Q),VJ(J,Q)}function NJ(J,X){for(let Q of J)if(Q.role==="system"||Q.role==="developer"){jJ(Q,X);return}}function VJ(J,X){for(let Q=J.length-1;Q>=0;Q--){let Y=J[Q];if(Y.role==="user"||Y.role==="assistant"){if(EJ(Y,X))return}}}function ZJ(J,X){if(!J||J.length===0)return;let Q=J[J.length-1];Q.cache_control=X}function jJ(J,X){return l(J,X)}function EJ(J,X){if(J.role==="user"||J.role==="assistant")return l(J,X);return!1}function l(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 N=$;return N.cache_control=X,!0}}return!1}function WJ(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 _},N=c(X.messages,J,(_)=>$(_));if(X.systemPrompt){let q=J.reasoning&&Q.supportsDeveloperRole?"developer":"system";Y.push({role:q,content:w(X.systemPrompt)})}let V=null;for(let _=0;_<N.length;_++){let q=N[_];if(Q.requiresAssistantAfterToolResult&&V==="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((W)=>{if(W.type==="text")return{type:"text",text:w(W.text)};else return{type:"image_url",image_url:{url:`data:${W.mimeType};base64,${W.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},W=q.content.filter(x).filter((L)=>L.text.trim().length>0).map((L)=>({type:"text",text:w(L.text)})),H=W.map((L)=>L.text).join(""),K=q.content.filter(QJ).filter((L)=>L.thinking.trim().length>0);if(K.length>0)if(Q.requiresThinkingAsText){let L=K.map((O)=>w(O.thinking)).join(`
4
4
 
5
5
  `);j.content=[{type:"text",text:L},...W]}else{if(H.length>0)j.content=H;let L=K[0].thinkingSignature;if(J.provider==="opencode-go"&&L==="reasoning")L="reasoning_content";if(L&&L.length>0)j[L]=K.map((O)=>O.thinking).join(`
@@ -0,0 +1,4 @@
1
+ // @bun
2
+ import{Ae as k,De as E,Fe as J,He as I,Ie as V,Ke as X,Ne as _,oe as JG,pe as r,qe as u,se as H,xe as W,ye as l,ze as N}from"./chunk-ga3mh3cd.js";function q(G,Q){let Y={};if(!Object.keys(Q).length)return Y=G,Y;for(let[K,B]of Object.entries(G)){let O=Q[K];if(O===null)continue;Y[O??K]=B}return Y}function UG(G){let Q={};for(let[Y,K]of Object.entries(G))if(typeof K<"u")Q[Y]=K;return Q}class C extends Error{rawValue;rawMessage;static[Symbol.hasInstance](G){if(!(G instanceof Error))return!1;if(!("rawValue"in G))return!1;if(!("rawMessage"in G))return!1;if(!("pretty"in G))return!1;if(typeof G.pretty!=="function")return!1;return!0}constructor(G,Q,Y){super(`${G}: ${Q}`);this.name="SDKValidationError",this.cause=Q,this.rawValue=Y,this.rawMessage=G}pretty(){if(this.cause instanceof r)return`${this.rawMessage}
3
+ ${yG(this.cause)}`;else return this.toString()}}function yG(G){return u(G)}function t(G){return{ok:!0,value:G}}function s(G){return{ok:!1,error:G}}async function vG(G){let Q=await G;if(!Q.ok)throw Q.error;return Q.value}function i(G,Q,Y){try{return t(Q(G))}catch(K){return s(new C(Y,K,G))}}var o=J({prompt_tokens:W().default(0),completion_tokens:W().default(0),total_tokens:W().default(0),prompt_audio_seconds:_(W()).optional()}).catchall(N()).transform((G)=>{return q(G,{prompt_tokens:"promptTokens",completion_tokens:"completionTokens",total_tokens:"totalTokens",prompt_audio_seconds:"promptAudioSeconds"})}),hG=J({promptTokens:W().default(0),completionTokens:W().default(0),totalTokens:W().default(0),promptAudioSeconds:_(W()).optional()}).catchall(N()).transform((G)=>{return{...q(G,{promptTokens:"prompt_tokens",completionTokens:"completion_tokens",totalTokens:"total_tokens",promptAudioSeconds:"prompt_audio_seconds"})}});function j(G){return z++,G}var z=0,a=0;function P(){a++;let G=z;return{end:(Q)=>{let Y=z-G;if(z=G+(Q??Y),--a===0)z=0;return Y}}}function M(G){let Q=Object.values(G);return I([...Q.map((Y)=>X(Y)),H().transform((Y)=>j(Y))])}function lG(G){let Q=Object.values(G).filter((Y)=>typeof Y==="number");return I([...Q.map((Y)=>X(Y)),W().transform((Y)=>j(Y))])}function f(G){return H()}function cG(G){return W()}var e=Symbol("UNKNOWN");function n(G){return typeof G==="object"&&G!==null&&e in G}function GG(G,Q,Y={}){let{unknownValue:K="UNKNOWN",outputPropertyName:B}=Y;return k().transform((O)=>{let w=Object.defineProperties({raw:O,[B??G]:K,isUnknown:!0},{[e]:{value:!0,enumerable:!1,configurable:!1}});if(!(typeof O==="object"&&O!==null))return w;let F=O[G];if(typeof F!=="string")return w;if(!(F in Q))return w;let $=Q[F];if(!$)return w;let T=P(),y=$.safeParse(O);if(!y.success)return T.end(0),w;if(T.end(),B)y.data[B]=F;return y.data})}var HG=/^\d{4}-\d{2}-\d{2}$/;class v{serialized;static today(){return new v(new Date)}constructor(G){if(typeof G==="string"&&!HG.test(G))throw RangeError("RFCDate: date strings must be in the format YYYY-MM-DD: "+G);let Q=new Date(G);if(isNaN(+Q))throw RangeError("RFCDate: invalid date provided: "+G);if(this.serialized=Q.toISOString().slice(0,10),!HG.test(this.serialized))throw TypeError(`RFCDate: failed to build valid date with given value: ${G} serialized to ${this.serialized}`)}toJSON(){return this.toString()}toString(){return this.serialized}}function Z(G){return k().transform((Q,Y)=>{let K=[],B=G.map(()=>[]),O=P();for(let[D,F]of G.entries()){let $=P(),T=F.safeParse(Q),y=$.end(),xG=0;if(T.success){K.push({data:T.data,inexactCount:y,zeroDefaultCount:0,fieldCount:-1});continue}B[D].push(...T.error.issues)}if(K.length===0)return O.end(0),Y.addIssue({input:Q,code:"invalid_union",errors:B}),JG;let w=K[0];for(let D of K){if(K.length>1)D.fieldCount=PG(D.data);w=zG(D,w)}return O.end(w.inexactCount),w.data})}function zG(G,Q){let Y=G.inexactCount===0,K=Q.inexactCount===0;if(Y!==K)return Y?G:Q;let B=G.fieldCount-G.zeroDefaultCount,O=Q.fieldCount-Q.zeroDefaultCount;if(B!==O)return B>O?G:Q;return G.inexactCount<Q.inexactCount?G:Q}function PG(G){let Q=0,Y=[G],K=0;while(K<Y.length){let B=Y[K++];if(B===void 0||n(B))continue;let O=typeof B;if(B===null||O==="number"||O==="string"||O==="boolean"||O==="bigint"||B instanceof Date||B instanceof v){Q++;continue}if(Array.isArray(B)){Y.push(...B);continue}if(O==="object")Y.push(...Object.values(B))}return Q}var QG=J({type:X("input_audio"),input_audio:H()}).transform((G)=>{return q(G,{input_audio:"inputAudio"})}),XG=J({type:X("input_audio"),inputAudio:H()}).transform((G)=>{return q(G,{inputAudio:"input_audio"})});var YG=J({type:X("document_url").default("document_url"),document_url:H(),document_name:_(H()).optional()}).transform((G)=>{return q(G,{document_url:"documentUrl",document_name:"documentName"})}),_G=J({type:X("document_url").default("document_url"),documentUrl:H(),documentName:_(H()).optional()}).transform((G)=>{return q(G,{documentUrl:"document_url",documentName:"document_name"})});var ZG=J({type:X("file").default("file"),file_id:H()}).transform((G)=>{return q(G,{file_id:"fileId"})}),WG=J({type:X("file").default("file"),fileId:H()}).transform((G)=>{return q(G,{fileId:"file_id"})});var qG={Low:"low",Auto:"auto",High:"high"},BG=M(qG),KG=f(qG);var b=J({url:H(),detail:_(BG).optional()}),p=J({url:H(),detail:_(KG).optional()});var BH=Z([b,H()]),KH=Z([p,H()]);var OG=J({type:X("image_url").default("image_url"),image_url:Z([b,H()])}).transform((G)=>{return q(G,{image_url:"imageUrl"})}),AG=J({type:X("image_url").default("image_url"),imageUrl:Z([p,H()])}).transform((G)=>{return q(G,{imageUrl:"image_url"})});var wH=Z([W(),H()]),NH=Z([W(),H()]);var L=J({type:X("reference").default("reference"),reference_ids:E(Z([W(),H()]))}).transform((G)=>{return q(G,{reference_ids:"referenceIds"})}),R=J({type:X("reference").default("reference"),referenceIds:E(Z([W(),H()]))}).transform((G)=>{return q(G,{referenceIds:"reference_ids"})});var x=J({type:X("text").default("text"),text:H()}),U=J({type:X("text").default("text"),text:H()});var EG={WebSearch:"web_search",WebSearchPremium:"web_search_premium",CodeInterpreter:"code_interpreter",ImageGeneration:"image_generation",DocumentLibrary:"document_library"},h=M(EG),g=f(EG);var yH=Z([h,H()]),zH=Z([g,H()]);var d=J({type:X("tool_reference").default("tool_reference"),tool:Z([h,H()]),title:H(),url:_(H()).optional(),favicon:_(H()).optional(),description:_(H()).optional()}),m=J({type:X("tool_reference").default("tool_reference"),tool:Z([g,H()]),title:H(),url:_(H()).optional(),favicon:_(H()).optional(),description:_(H()).optional()});var UH=Z([d,x,L]),$H=Z([m,U,R]);var wG=J({type:X("thinking").default("thinking"),thinking:E(Z([d,x,L])),signature:_(H()).optional(),closed:l().optional()}),NG=J({type:X("thinking").default("thinking"),thinking:E(Z([m,U,R])),signature:_(H()).optional(),closed:l().optional()});var c=GG("type",{image_url:OG.and(J({type:X("image_url")})),document_url:YG.and(J({type:X("document_url")})),text:x.and(J({type:X("text")})),reference:L.and(J({type:X("reference")})),file:ZG.and(J({type:X("file")})),thinking:wG.and(J({type:X("thinking")})),input_audio:QG}),gH=I([AG.and(J({type:X("image_url")})),_G.and(J({type:X("document_url")})),U.and(J({type:X("text")})),R.and(J({type:X("reference")})),WG.and(J({type:X("file")})),NG.and(J({type:X("thinking")})),XG]);var lH=Z([V(H(),N()),H()]),cH=Z([V(H(),N()),H()]);var VG=J({name:H(),arguments:Z([V(H(),N()),H()])}),DG=J({name:H(),arguments:Z([V(H(),N()),H()])});var FG=J({id:H().default("null"),type:H().optional(),function:VG,index:W().default(0)}),tH=J({id:H().default("null"),type:H().optional(),function:DG,index:W().default(0)});var nH=Z([H(),E(c)]);var TG=J({role:_(H()).optional(),content:_(Z([H(),E(c)])).optional(),tool_calls:_(E(FG)).optional(),tool_call_id:_(H()).optional(),index:_(W()).optional(),metadata:_(V(H(),N())).optional()}).transform((G)=>{return q(G,{tool_calls:"toolCalls",tool_call_id:"toolCallId"})});var IG={Stop:"stop",Length:"length",Error:"error",ToolCalls:"tool_calls"},LG=M(IG),MG=J({index:W(),delta:TG,finish_reason:_(LG)}).transform((G)=>{return q(G,{finish_reason:"finishReason"})});var RG=J({id:H(),object:H().optional(),created:W().optional(),model:H(),usage:o.optional(),choices:E(MG)});function ZJ(G){return i(G,(Q)=>RG.parse(JSON.parse(Q)),"Failed to parse 'CompletionChunk' from JSON")}
4
+ export{yG as gb,t as hb,s as ib,vG as jb,i as kb,q as lb,UG as mb,M as nb,lG as ob,f as pb,cG as qb,GG as rb,Z as sb,YG as tb,_G as ub,WG as vb,OG as wb,AG as xb,x as yb,U as zb,h as Ab,g as Bb,d as Cb,m as Db,wG as Eb,NG as Fb,c as Gb,gH as Hb,FG as Ib,tH as Jb,TG as Kb,o as Lb,hG as Mb,RG as Nb,ZJ as Ob};
@@ -1,3 +1,3 @@
1
1
  // @bun
2
- import{$c as J,Nc as c,Oc as V,Pc as _k,Qc as ek,Rc as kW,Tc as GW,Vc as _,Wc as kk,Xc as h,Yc as dk,Zc as j,dd as I,ed as zk,fd as x,gd as hk,hd as Kk,id as pW,jd as y,kd as dW,ld as v,md as fk,nd as Xk,od as w,pd as sW,qd as TW,rd as Mk,td as YW,ud as Ch}from"./chunk-ysq64j13.js";function z(k){return kk(k)&&_(k.toOperationNode)}var Q=h({is(k){return k.kind==="ValueNode"},create(k){return h({kind:"ValueNode",value:k})},createImmediate(k){return h({kind:"ValueNode",value:k,immediate:!0})}});var S=h({is(k){return k.kind==="ColumnNode"},create(k){return h({kind:"ColumnNode",column:J.create(k)})}});var pk=h({is(k){return k.kind==="SelectAllNode"},create(){return h({kind:"SelectAllNode"})}});var Ak=h({is(k){return k.kind==="ReferenceNode"},create(k,W){return h({kind:"ReferenceNode",table:W,column:k})},createSelectAll(k){return h({kind:"ReferenceNode",table:k,column:pk.create()})}});function ok(k){return kk(k)&&"expressionType"in k&&z(k)}function iW(k){return kk(k)&&"expression"in k&&V(k.alias)&&z(k)}var a=h({is(k){return k.kind==="SelectModifierNode"},create(k,W){return h({kind:"SelectModifierNode",modifier:k,of:W})},createWithExpression(k){return h({kind:"SelectModifierNode",rawModifier:k})}});var Yk=h({is(k){return k.kind==="BinaryOperationNode"},create(k,W,$){return h({kind:"BinaryOperationNode",leftOperand:k,operator:W,rightOperand:$})}});var sk=h({is(k){return k.kind==="PrimitiveValueListNode"},create(k){return h({kind:"PrimitiveValueListNode",values:h([...k])})}});var rk=h({is(k){return k.kind==="ValueListNode"},create(k){return h({kind:"ValueListNode",values:h(k)})}});function lW(k){if(j(k))return ih(k);return X(k)}function X(k){if(Wk(k))return p(k);return Q.create(k)}function WW(k){return _k(k)||ek(k)||kW(k)}function Bk(k){if(!WW(k))throw Error(`unsafe immediate value ${JSON.stringify(k)}`);return Q.createImmediate(k)}function ih(k){if(k.some(Wk))return rk.create(k.map((W)=>X(W)));return sk.create(k)}function L(k){if(k.length===3)return hW(k[0],k[1],k[2]);else if(k.length===1)return X(k[0]);throw Error(`invalid arguments: ${JSON.stringify(k)}`)}function hW(k,W,$){if(lh(W)&&oW($))return Yk.create(f(k),PW(W),Q.createImmediate($));return Yk.create(f(k),PW(W),lW($))}function m(k,W,$){return Yk.create(f(k),PW(W),f($))}function UW(k,W){return mk(Object.entries(k).filter(([,$])=>!c($)).map(([$,M])=>hW($,oW(M)?"is":"=",M)),W)}function mk(k,W,$=!0){let M=W==="and"?x.create:hk.create;if(k.length===0)return Yk.create(Q.createImmediate(1),y.create("="),Q.createImmediate(W==="and"?1:0));let G=aW(k[0]);for(let q=1;q<k.length;++q)G=M(G,aW(k[q]));if(k.length>1&&$)return Xk.create(G);return G}function lh(k){return k==="is"||k==="is not"}function oW(k){return kW(k)||ek(k)}function PW(k){if(V(k)&&pW.includes(k))return y.create(k);if(z(k))return k.toOperationNode();throw Error(`invalid operator ${JSON.stringify(k)}`)}function aW(k){return z(k)?k.toOperationNode():k}var $k=h({is(k){return k.kind==="OrderByNode"},create(k){return h({kind:"OrderByNode",items:h([...k])})},cloneWithItems(k,W){return h({...k,items:h([...k.items,...W])})}});var VW=h({is(k){return k.kind==="PartitionByNode"},create(k){return h({kind:"PartitionByNode",items:h(k)})},cloneWithItems(k,W){return h({...k,items:h([...k.items,...W])})}});var xk=h({is(k){return k.kind==="OverNode"},create(){return h({kind:"OverNode"})},cloneWithOrderByItems(k,W){return h({...k,orderBy:k.orderBy?$k.cloneWithItems(k.orderBy,W):$k.create(W)})},cloneWithPartitionByItems(k,W){return h({...k,partitionBy:k.partitionBy?VW.cloneWithItems(k.partitionBy,W):VW.create(W)})}});var Vk=h({is(k){return k.kind==="FromNode"},create(k){return h({kind:"FromNode",froms:h(k)})},cloneWithFroms(k,W){return h({...k,froms:h([...k.froms,...W])})}});var wW=h({is(k){return k.kind==="GroupByNode"},create(k){return h({kind:"GroupByNode",items:h(k)})},cloneWithItems(k,W){return h({...k,items:h([...k.items,...W])})}});var FW=h({is(k){return k.kind==="HavingNode"},create(k){return h({kind:"HavingNode",having:k})},cloneWithOperation(k,W,$){return h({...k,having:W==="And"?x.create(k.having,$):hk.create(k.having,$)})}});var o=h({is(k){return k.kind==="UpdateQueryNode"},create(k,W){return h({kind:"UpdateQueryNode",table:k.length===1?k[0]:sW.create(k),...W&&{with:W}})},createWithoutTable(){return h({kind:"UpdateQueryNode"})},cloneWithFromItems(k,W){return h({...k,from:k.from?Vk.cloneWithFroms(k.from,W):Vk.create(W)})},cloneWithUpdates(k,W){return h({...k,updates:k.updates?h([...k.updates,...W]):W})},cloneWithLimit(k,W){return h({...k,limit:W})}});var Dk=h({is(k){return k.kind==="DeleteQueryNode"},create(k,W){return h({kind:"DeleteQueryNode",from:Vk.create(k),...W&&{with:W}})},cloneWithOrderByItems:(k,W)=>K.cloneWithOrderByItems(k,W),cloneWithoutOrderBy:(k)=>K.cloneWithoutOrderBy(k),cloneWithLimit(k,W){return h({...k,limit:W})},cloneWithoutLimit(k){return h({...k,limit:void 0})},cloneWithUsing(k,W){return h({...k,using:k.using!==void 0?TW.cloneWithTables(k.using,W):TW.create(W)})}});var C=h({is(k){return k.kind==="WhereNode"},create(k){return h({kind:"WhereNode",where:k})},cloneWithOperation(k,W,$){return h({...k,where:W==="And"?x.create(k.where,$):hk.create(k.where,$)})}});var vW=h({is(k){return k.kind==="ReturningNode"},create(k){return h({kind:"ReturningNode",selections:h(k)})},cloneWithSelections(k,W){return h({...k,selections:k.selections?h([...k.selections,...W]):h(W)})}});var rW=h({is(k){return k.kind==="ExplainNode"},create(k,W){return h({kind:"ExplainNode",format:k,options:W})}});var N=h({is(k){return k.kind==="MergeQueryNode"},create(k,W){return h({kind:"MergeQueryNode",into:k,...W&&{with:W}})},cloneWithUsing(k,W){return h({...k,using:W})},cloneWithWhen(k,W){return h({...k,whens:k.whens?h([...k.whens,W]):h([W])})},cloneWithThen(k,W){return h({...k,whens:k.whens?h([...k.whens.slice(0,-1),Mk.cloneWithResult(k.whens[k.whens.length-1],W)]):void 0})}});var AW=h({is(k){return k.kind==="OutputNode"},create(k){return h({kind:"OutputNode",selections:h(k)})},cloneWithSelections(k,W){return h({...k,selections:k.selections?h([...k.selections,...W]):h(W)})}});var K=h({is(k){return Y.is(k)||w.is(k)||o.is(k)||Dk.is(k)||N.is(k)},cloneWithEndModifier(k,W){return h({...k,endModifiers:k.endModifiers?h([...k.endModifiers,W]):h([W])})},cloneWithWhere(k,W){return h({...k,where:k.where?C.cloneWithOperation(k.where,"And",W):C.create(W)})},cloneWithJoin(k,W){return h({...k,joins:k.joins?h([...k.joins,W]):h([W])})},cloneWithReturning(k,W){return h({...k,returning:k.returning?vW.cloneWithSelections(k.returning,W):vW.create(W)})},cloneWithoutReturning(k){return h({...k,returning:void 0})},cloneWithoutWhere(k){return h({...k,where:void 0})},cloneWithExplain(k,W,$){return h({...k,explain:rW.create(W,$?.toOperationNode())})},cloneWithTop(k,W){return h({...k,top:W})},cloneWithOutput(k,W){return h({...k,output:k.output?AW.cloneWithSelections(k.output,W):AW.create(W)})},cloneWithOrderByItems(k,W){return h({...k,orderBy:k.orderBy?$k.cloneWithItems(k.orderBy,W):$k.create(W)})},cloneWithoutOrderBy(k){return h({...k,orderBy:void 0})}});var Y=h({is(k){return k.kind==="SelectQueryNode"},create(k){return h({kind:"SelectQueryNode",...k&&{with:k}})},createFrom(k,W){return h({kind:"SelectQueryNode",from:Vk.create(k),...W&&{with:W}})},cloneWithSelections(k,W){return h({...k,selections:k.selections?h([...k.selections,...W]):h(W)})},cloneWithDistinctOn(k,W){return h({...k,distinctOn:k.distinctOn?h([...k.distinctOn,...W]):h(W)})},cloneWithFrontModifier(k,W){return h({...k,frontModifiers:k.frontModifiers?h([...k.frontModifiers,W]):h([W])})},cloneWithOrderByItems:(k,W)=>K.cloneWithOrderByItems(k,W),cloneWithGroupByItems(k,W){return h({...k,groupBy:k.groupBy?wW.cloneWithItems(k.groupBy,W):wW.create(W)})},cloneWithLimit(k,W){return h({...k,limit:W})},cloneWithOffset(k,W){return h({...k,offset:W})},cloneWithFetch(k,W){return h({...k,fetch:W})},cloneWithHaving(k,W){return h({...k,having:k.having?FW.cloneWithOperation(k.having,"And",W):FW.create(W)})},cloneWithSetOperations(k,W){return h({...k,setOperations:k.setOperations?h([...k.setOperations,...W]):h([...W])})},cloneWithoutSelections(k){return h({...k,selections:[]})},cloneWithoutLimit(k){return h({...k,limit:void 0})},cloneWithoutOffset(k){return h({...k,offset:void 0})},cloneWithoutOrderBy:(k)=>K.cloneWithoutOrderBy(k),cloneWithoutGroupBy(k){return h({...k,groupBy:void 0})}});class Rk{#k;constructor(k){this.#k=h(k)}on(...k){return new Rk({...this.#k,joinNode:Kk.cloneWithOn(this.#k.joinNode,L(k))})}onRef(k,W,$){return new Rk({...this.#k,joinNode:Kk.cloneWithOn(this.#k.joinNode,m(k,W,$))})}onTrue(){return new Rk({...this.#k,joinNode:Kk.cloneWithOn(this.#k.joinNode,v.createWithSql("true"))})}$call(k){return k(this)}toOperationNode(){return this.#k.joinNode}}class ah{#k;get dynamicReference(){return this.#k}get refType(){return}constructor(k){this.#k=k}toOperationNode(){return _W(this.#k)}}function $W(k){return kk(k)&&z(k)&&V(k.dynamicReference)}var g=h({is(k){return k.kind==="OrderByItemNode"},create(k,W){return h({kind:"OrderByItemNode",orderBy:k,direction:W})},cloneWith(k,W){return h({...k,...W})}});var eW=h({is(k){return k.kind==="CollateNode"},create(k){return h({kind:"CollateNode",collation:J.create(k)})}});class Lk{#k;constructor(k){this.#k=h(k)}desc(){return new Lk({node:g.cloneWith(this.#k.node,{direction:v.createWithSql("desc")})})}asc(){return new Lk({node:g.cloneWith(this.#k.node,{direction:v.createWithSql("asc")})})}nullsLast(){return new Lk({node:g.cloneWith(this.#k.node,{nulls:"last"})})}nullsFirst(){return new Lk({node:g.cloneWith(this.#k.node,{nulls:"first"})})}collate(k){return new Lk({node:g.cloneWith(this.#k.node,{collation:eW.create(k)})})}toOperationNode(){return this.#k.node}}function RW(k){return k==="asc"||k==="desc"}function B(k){if(k.length===2)return[mW(k[0],k[1])];if(k.length===1){let[W]=k;if(Array.isArray(W))return fk("orderBy(array) is deprecated, use multiple orderBy calls instead."),W.map(($)=>mW($));return[mW(W)]}throw Error(`Invalid number of arguments at order by! expected 1-2, received ${k.length}`)}function mW(k,W){let $=ph(k);if(g.is($)){if(W)throw Error("Cannot specify direction twice!");return $}return kh($,W)}function ph(k){if(Wk(k))return p(k);if($W(k))return k.toOperationNode();let[W,$]=k.split(" ");if($)return fk("`orderBy('column asc')` is deprecated. Use `orderBy('column', 'asc')` instead."),kh(t(W),$);return t(k)}function kh(k,W){if(typeof W==="string"){if(!RW(W))throw Error(`Invalid order by direction: ${W}`);return g.create(k,v.createWithSql(W))}if(ok(W))return fk("`orderBy(..., expr)` is deprecated. Use `orderBy(..., 'asc')` or `orderBy(..., (ob) => ...)` instead."),g.create(k,W.toOperationNode());let $=g.create(k);if(!W)return $;return W(new Lk({node:$})).toOperationNode()}var Wh=h({is(k){return k.kind==="PartitionByItemNode"},create(k){return h({kind:"PartitionByItemNode",partitionBy:k})}});function hh(k){return Gk(k).map(Wh.create)}class Ck{#k;constructor(k){this.#k=h(k)}orderBy(...k){return new Ck({overNode:xk.cloneWithOrderByItems(this.#k.overNode,B(k))})}clearOrderBy(){return new Ck({overNode:K.cloneWithoutOrderBy(this.#k.overNode)})}partitionBy(k){return new Ck({overNode:xk.cloneWithPartitionByItems(this.#k.overNode,hh(k))})}$call(k){return k(this)}toOperationNode(){return this.#k.overNode}}var Sk=h({is(k){return k.kind==="SelectionNode"},create(k){return h({kind:"SelectionNode",selection:k})},createSelectAll(){return h({kind:"SelectionNode",selection:pk.create()})},createSelectAllFromTable(k){return h({kind:"SelectionNode",selection:Ak.createSelectAll(k)})}});class oh{#k;get table(){return this.#k}constructor(k){this.#k=k}as(k){return new $h(this.#k,k)}}class $h{#k;#W;get table(){return this.#k}get alias(){return this.#W}constructor(k,W){this.#k=k,this.#W=W}toOperationNode(){return I.create(F(this.#k),J.create(this.#W))}}function Mh(k){return kk(k)&&z(k)&&V(k.table)&&V(k.alias)}function n(k){if(j(k))return k.map((W)=>wk(W));else return[wk(k)]}function wk(k){if(V(k))return fW(k);else if(Mh(k))return k.toOperationNode();else return MW(k)}function fW(k){if(k.includes(" as ")){let[$,M]=k.split(" as ").map(Kh);return I.create(F($),J.create(M))}else return F(k)}function F(k){if(k.includes(".")){let[$,M]=k.split(".").map(Kh);return zk.createWithSchema($,M)}else return zk.create(k)}function Kh(k){return k.trim()}function A(k){if(_(k))return A(k(d()));else if(j(k))return k.map((W)=>Gh(W));else return[Gh(k)]}function Gh(k){if(V(k))return Sk.create(Zh(k));else if($W(k))return Sk.create(k.toOperationNode());else return Sk.create(MW(k))}function R(k){if(!k)return[Sk.createSelectAll()];else if(Array.isArray(k))return k.map(Hh);else return[Hh(k)]}function Hh(k){if(V(k))return Sk.createSelectAllFromTable(F(k));throw Error(`invalid value selectAll expression: ${JSON.stringify(k)}`)}var Yh=h({is(k){return k.kind==="ValuesNode"},create(k){return h({kind:"ValuesNode",values:h(k)})}});var Xh=h({is(k){return k.kind==="DefaultInsertValueNode"},create(){return h({kind:"DefaultInsertValueNode"})}});function KW(k){let W=_(k)?k(d()):k,$=j(W)?W:h([W]);return sh($)}function sh(k){let W=rh(k);return[h([...W.keys()].map(S.create)),Yh.create(k.map(($)=>eh($,W)))]}function rh(k){let W=new Map;for(let $ of k){let M=Object.keys($);for(let G of M)if(!W.has(G)&&$[G]!==void 0)W.set(G,W.size)}return W}function eh(k,W){let $=Object.keys(k),M=Array.from({length:W.size}),G=!1,q=$.length;for(let ak of $){let Nk=W.get(ak);if(c(Nk)){q--;continue}let qW=k[ak];if(c(qW)||Wk(qW))G=!0;M[Nk]=qW}if(q<W.size||G){let ak=Xh.create();return rk.create(M.map((Nk)=>c(Nk)?ak:X(Nk)))}return sk.create(M)}var CW=h({is(k){return k.kind==="ColumnUpdateNode"},create(k,W){return h({kind:"ColumnUpdateNode",column:k,value:W})}});function Dh(...k){if(k.length===2)return[CW.create(f(k[0]),X(k[1]))];return ck(k[0])}function ck(k){let W=_(k)?k(d()):k;return Object.entries(W).filter(([$,M])=>M!==void 0).map(([$,M])=>{return CW.create(S.create($),X(M))})}var Lh=h({is(k){return k.kind==="OnDuplicateKeyNode"},create(k){return h({kind:"OnDuplicateKeyNode",updates:k})}});class SW{insertId;numInsertedOrUpdatedRows;constructor(k,W){this.insertId=k,this.numInsertedOrUpdatedRows=W}}class u extends Error{node;constructor(k){super("no result");this.node=k}}function s(k){return Object.prototype.hasOwnProperty.call(k,"prototype")}var E=h({is(k){return k.kind==="OnConflictNode"},create(){return h({kind:"OnConflictNode"})},cloneWith(k,W){return h({...k,...W})},cloneWithIndexWhere(k,W){return h({...k,indexWhere:k.indexWhere?C.cloneWithOperation(k.indexWhere,"And",W):C.create(W)})},cloneWithIndexOrWhere(k,W){return h({...k,indexWhere:k.indexWhere?C.cloneWithOperation(k.indexWhere,"Or",W):C.create(W)})},cloneWithUpdateWhere(k,W){return h({...k,updateWhere:k.updateWhere?C.cloneWithOperation(k.updateWhere,"And",W):C.create(W)})},cloneWithUpdateOrWhere(k,W){return h({...k,updateWhere:k.updateWhere?C.cloneWithOperation(k.updateWhere,"Or",W):C.create(W)})},cloneWithoutIndexWhere(k){return h({...k,indexWhere:void 0})},cloneWithoutUpdateWhere(k){return h({...k,updateWhere:void 0})}});class r{#k;constructor(k){this.#k=h(k)}column(k){let W=S.create(k);return new r({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{columns:this.#k.onConflictNode.columns?h([...this.#k.onConflictNode.columns,W]):h([W])})})}columns(k){let W=k.map(S.create);return new r({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{columns:this.#k.onConflictNode.columns?h([...this.#k.onConflictNode.columns,...W]):h(W)})})}constraint(k){return new r({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{constraint:J.create(k)})})}expression(k){return new r({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{indexExpression:k.toOperationNode()})})}where(...k){return new r({...this.#k,onConflictNode:E.cloneWithIndexWhere(this.#k.onConflictNode,L(k))})}whereRef(k,W,$){return new r({...this.#k,onConflictNode:E.cloneWithIndexWhere(this.#k.onConflictNode,m(k,W,$))})}clearWhere(){return new r({...this.#k,onConflictNode:E.cloneWithoutIndexWhere(this.#k.onConflictNode)})}doNothing(){return new zh({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{doNothing:!0})})}doUpdateSet(k){return new yk({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{updates:ck(k)})})}$call(k){return k(this)}}class zh{#k;constructor(k){this.#k=h(k)}toOperationNode(){return this.#k.onConflictNode}}class yk{#k;constructor(k){this.#k=h(k)}where(...k){return new yk({...this.#k,onConflictNode:E.cloneWithUpdateWhere(this.#k.onConflictNode,L(k))})}whereRef(k,W,$){return new yk({...this.#k,onConflictNode:E.cloneWithUpdateWhere(this.#k.onConflictNode,m(k,W,$))})}clearWhere(){return new yk({...this.#k,onConflictNode:E.cloneWithoutUpdateWhere(this.#k.onConflictNode)})}$call(k){return k(this)}toOperationNode(){return this.#k.onConflictNode}}var Jh=h({is(k){return k.kind==="TopNode"},create(k,W){return h({kind:"TopNode",expression:k,modifiers:W})}});function i(k,W){if(!_k(k)&&!GW(k))throw Error(`Invalid top expression: ${k}`);if(!c(W)&&!k$(W))throw Error(`Invalid top modifiers: ${W}`);return Jh.create(k,W)}function k$(k){return k==="percent"||k==="with ties"||k==="percent with ties"}var Fk=h({is(k){return k.kind==="OrActionNode"},create(k){return h({kind:"OrActionNode",action:k})}});class D{#k;constructor(k){this.#k=h(k)}values(k){let[W,$]=KW(k);return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{columns:W,values:$})})}columns(k){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{columns:h(k.map(S.create))})})}expression(k){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{values:p(k)})})}defaultValues(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{defaultValues:!0})})}modifyEnd(k){return new D({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,k.toOperationNode())})}ignore(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("ignore")})})}orIgnore(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("ignore")})})}orAbort(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("abort")})})}orFail(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("fail")})})}orReplace(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("replace")})})}orRollback(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("rollback")})})}top(k,W){return new D({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}onConflict(k){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{onConflict:k(new r({onConflictNode:E.create()})).toOperationNode()})})}onDuplicateKeyUpdate(k){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{onDuplicateKey:Lh.create(ck(k))})})}returning(k){return new D({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,A(k))})}returningAll(){return new D({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,R())})}output(k){return new D({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,A(k))})}outputAll(k){return new D({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,R(k))})}clearReturning(){return new D({...this.#k,queryNode:K.cloneWithoutReturning(this.#k.queryNode)})}$call(k){return k(this)}$if(k,W){if(k)return W(this);return new D({...this.#k})}$castTo(){return new D(this.#k)}$narrowType(){return new D(this.#k)}$assertType(){return new D(this.#k)}withPlugin(k){return new D({...this.#k,executor:this.#k.executor.withPlugin(k)})}toOperationNode(){return this.#k.executor.transformQuery(this.#k.queryNode,this.#k.queryId)}compile(){return this.#k.executor.compileQuery(this.toOperationNode(),this.#k.queryId)}async execute(){let k=this.compile(),W=await this.#k.executor.executeQuery(k),{adapter:$}=this.#k.executor,M=k.query;if(M.returning&&$.supportsReturning||M.output&&$.supportsOutput)return W.rows;return[new SW(W.insertId,W.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[k]=await this.execute();return k}async executeTakeFirstOrThrow(k=u){let W=await this.executeTakeFirst();if(W===void 0)throw s(k)?new k(this.toOperationNode()):k(this.toOperationNode());return W}async*stream(k=100){let W=this.compile(),$=this.#k.executor.stream(W,k);for await(let M of $)yield*M.rows}async explain(k,W){return await new D({...this.#k,queryNode:K.cloneWithExplain(this.#k.queryNode,k,W)}).execute()}}class IW{numDeletedRows;constructor(k){this.numDeletedRows=k}}var Ik=h({is(k){return k.kind==="LimitNode"},create(k){return h({kind:"LimitNode",limit:k})}});var P;class HW{#k;constructor(k){this.#k=h(k)}where(...k){return new P({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,L(k))})}whereRef(k,W,$){return new P({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,m(k,W,$))})}clearWhere(){return new P({...this.#k,queryNode:K.cloneWithoutWhere(this.#k.queryNode)})}top(k,W){return new P({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}using(k){return new P({...this.#k,queryNode:Dk.cloneWithUsing(this.#k.queryNode,n(k))})}innerJoin(...k){return this.#W("InnerJoin",k)}leftJoin(...k){return this.#W("LeftJoin",k)}rightJoin(...k){return this.#W("RightJoin",k)}fullJoin(...k){return this.#W("FullJoin",k)}#W(k,W){return new P({...this.#k,queryNode:K.cloneWithJoin(this.#k.queryNode,Jk(k,W))})}returning(k){return new P({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,A(k))})}returningAll(k){return new P({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,R(k))})}output(k){return new P({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,A(k))})}outputAll(k){return new P({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,R(k))})}clearReturning(){return new P({...this.#k,queryNode:K.cloneWithoutReturning(this.#k.queryNode)})}clearLimit(){return new P({...this.#k,queryNode:Dk.cloneWithoutLimit(this.#k.queryNode)})}orderBy(...k){return new P({...this.#k,queryNode:K.cloneWithOrderByItems(this.#k.queryNode,B(k))})}clearOrderBy(){return new P({...this.#k,queryNode:K.cloneWithoutOrderBy(this.#k.queryNode)})}limit(k){return new P({...this.#k,queryNode:Dk.cloneWithLimit(this.#k.queryNode,Ik.create(X(k)))})}modifyEnd(k){return new P({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,k.toOperationNode())})}$call(k){return k(this)}$if(k,W){if(k)return W(this);return new P({...this.#k})}$castTo(){return new P(this.#k)}$narrowType(){return new P(this.#k)}$assertType(){return new P(this.#k)}withPlugin(k){return new P({...this.#k,executor:this.#k.executor.withPlugin(k)})}toOperationNode(){return this.#k.executor.transformQuery(this.#k.queryNode,this.#k.queryId)}compile(){return this.#k.executor.compileQuery(this.toOperationNode(),this.#k.queryId)}async execute(){let k=this.compile(),W=await this.#k.executor.executeQuery(k),{adapter:$}=this.#k.executor,M=k.query;if(M.returning&&$.supportsReturning||M.output&&$.supportsOutput)return W.rows;return[new IW(W.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[k]=await this.execute();return k}async executeTakeFirstOrThrow(k=u){let W=await this.executeTakeFirst();if(W===void 0)throw s(k)?new k(this.toOperationNode()):k(this.toOperationNode());return W}async*stream(k=100){let W=this.compile(),$=this.#k.executor.stream(W,k);for await(let M of $)yield*M.rows}async explain(k,W){return await new P({...this.#k,queryNode:K.cloneWithExplain(this.#k.queryNode,k,W)}).execute()}}P=HW;class jW{numUpdatedRows;numChangedRows;constructor(k,W){this.numUpdatedRows=k,this.numChangedRows=W}}var U;class jk{#k;constructor(k){this.#k=h(k)}where(...k){return new U({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,L(k))})}whereRef(k,W,$){return new U({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,m(k,W,$))})}clearWhere(){return new U({...this.#k,queryNode:K.cloneWithoutWhere(this.#k.queryNode)})}top(k,W){return new U({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}from(k){return new U({...this.#k,queryNode:o.cloneWithFromItems(this.#k.queryNode,n(k))})}innerJoin(...k){return this.#W("InnerJoin",k)}leftJoin(...k){return this.#W("LeftJoin",k)}rightJoin(...k){return this.#W("RightJoin",k)}fullJoin(...k){return this.#W("FullJoin",k)}#W(k,W){return new U({...this.#k,queryNode:K.cloneWithJoin(this.#k.queryNode,Jk(k,W))})}orderBy(...k){return new U({...this.#k,queryNode:K.cloneWithOrderByItems(this.#k.queryNode,B(k))})}clearOrderBy(){return new U({...this.#k,queryNode:K.cloneWithoutOrderBy(this.#k.queryNode)})}limit(k){return new U({...this.#k,queryNode:o.cloneWithLimit(this.#k.queryNode,Ik.create(X(k)))})}set(...k){return new U({...this.#k,queryNode:o.cloneWithUpdates(this.#k.queryNode,Dh(...k))})}returning(k){return new U({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,A(k))})}returningAll(k){return new U({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,R(k))})}output(k){return new U({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,A(k))})}outputAll(k){return new U({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,R(k))})}modifyEnd(k){return new U({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,k.toOperationNode())})}clearReturning(){return new U({...this.#k,queryNode:K.cloneWithoutReturning(this.#k.queryNode)})}$call(k){return k(this)}$if(k,W){if(k)return W(this);return new U({...this.#k})}$castTo(){return new U(this.#k)}$narrowType(){return new U(this.#k)}$assertType(){return new U(this.#k)}withPlugin(k){return new U({...this.#k,executor:this.#k.executor.withPlugin(k)})}toOperationNode(){return this.#k.executor.transformQuery(this.#k.queryNode,this.#k.queryId)}compile(){return this.#k.executor.compileQuery(this.toOperationNode(),this.#k.queryId)}async execute(){let k=this.compile(),W=await this.#k.executor.executeQuery(k),{adapter:$}=this.#k.executor,M=k.query;if(M.returning&&$.supportsReturning||M.output&&$.supportsOutput)return W.rows;return[new jW(W.numAffectedRows??BigInt(0),W.numChangedRows)]}async executeTakeFirst(){let[k]=await this.execute();return k}async executeTakeFirstOrThrow(k=u){let W=await this.executeTakeFirst();if(W===void 0)throw s(k)?new k(this.toOperationNode()):k(this.toOperationNode());return W}async*stream(k=100){let W=this.compile(),$=this.#k.executor.stream(W,k);for await(let M of $)yield*M.rows}async explain(k,W){return await new U({...this.#k,queryNode:K.cloneWithExplain(this.#k.queryNode,k,W)}).execute()}}U=jk;var EW=h({is(k){return k.kind==="CommonTableExpressionNameNode"},create(k,W){return h({kind:"CommonTableExpressionNameNode",table:zk.create(k),columns:W?h(W.map(S.create)):void 0})}});var Ek=h({is(k){return k.kind==="CommonTableExpressionNode"},create(k,W){return h({kind:"CommonTableExpressionNode",name:k,expression:W})},cloneWith(k,W){return h({...k,...W})}});class gk{#k;constructor(k){this.#k=h(k)}materialized(){return new gk({...this.#k,node:Ek.cloneWith(this.#k.node,{materialized:!0})})}notMaterialized(){return new gk({...this.#k,node:Ek.cloneWith(this.#k.node,{materialized:!1})})}toOperationNode(){return this.#k.node}}function OW(k,W){let $=W(Ph()).toOperationNode();if(_(k))return k(W$($)).toOperationNode();return Ek.create(qh(k),$)}function W$(k){return(W)=>{return new gk({node:Ek.create(qh(W),k)})}}function qh(k){if(k.includes("(")){let W=k.split(/[\(\)]/),$=W[0],M=W[1].split(",").map((G)=>G.trim());return EW.create($,M)}else return EW.create(k)}var tk=h({is(k){return k.kind==="WithNode"},create(k,W){return h({kind:"WithNode",expressions:h([k]),...W})},cloneWithExpression(k,W){return h({...k,expressions:h([...k.expressions,W])})}});var Uh=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"];function Vh(k){let W="";for(let $=0;$<k;++$)W+=h$();return W}function h$(){return Uh[~~(Math.random()*Uh.length)]}function T(){return new wh}class wh{#k;get queryId(){if(this.#k===void 0)this.#k=Vh(8);return this.#k}}var Fh=h({is(k){return k.kind==="MatchedNode"},create(k,W=!1){return h({kind:"MatchedNode",not:k,bySource:W})}});function bW(k,W,$){return Mk.create(mk([Fh.create(!k.isMatched,k.bySource),...W&&W.length>0?[W.length===3&&$?m(W[0],W[1],W[2]):L(W)]:[]],"and",!1))}function Ok(k){if(V(k))return v.create([k],[]);if(z(k))return k.toOperationNode();return k}class ZW{#k;#W;#h;constructor(){this.#k=new Promise((k,W)=>{this.#h=W,this.#W=k})}get promise(){return this.#k}resolve=(k)=>{if(this.#W)this.#W(k)};reject=(k)=>{if(this.#h)this.#h(k)}}async function Th(k){let W=new ZW,$=new ZW;return k.provideConnection(async(M)=>{return W.resolve(M),await $.promise}).catch((M)=>W.reject(M)),h({connection:await W.promise,release:$.resolve})}var $$=h([]);class QW{#k;constructor(k=$$){this.#k=k}get plugins(){return this.#k}transformQuery(k,W){for(let $ of this.#k){let M=$.transformQuery({node:k,queryId:W});if(M.kind===k.kind)k=M;else throw Error(["KyselyPlugin.transformQuery must return a node","of the same kind that was given to it.",`The plugin was given a ${k.kind}`,`but it returned a ${M.kind}`].join(" "))}return k}async executeQuery(k){return await this.provideConnection(async(W)=>{let $=await W.executeQuery(k);if("numUpdatedOrDeletedRows"in $)fk("kysely:warning: outdated driver/plugin detected! `QueryResult.numUpdatedOrDeletedRows` has been replaced with `QueryResult.numAffectedRows`.");return await this.#W($,k.queryId)})}async*stream(k,W){let{connection:$,release:M}=await Th(this);try{for await(let G of $.streamQuery(k,W))yield await this.#W(G,k.queryId)}finally{M()}}async#W(k,W){for(let $ of this.#k)k=await $.transformResult({result:k,queryId:W});return k}}class bk extends QW{get adapter(){throw Error("this query cannot be compiled to SQL")}compileQuery(){throw Error("this query cannot be compiled to SQL")}provideConnection(){throw Error("this query cannot be executed")}withConnectionProvider(){throw Error("this query cannot have a connection provider")}withPlugin(k){return new bk([...this.plugins,k])}withPlugins(k){return new bk([...this.plugins,...k])}withPluginAtFront(k){return new bk([k,...this.plugins])}withoutPlugins(){return new bk([])}}var qk=new bk;class NW{numChangedRows;constructor(k){this.numChangedRows=k}}class Hk{#k;constructor(k){this.#k=h(k)}modifyEnd(k){return new Hk({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,k.toOperationNode())})}top(k,W){return new Hk({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}using(...k){return new O({...this.#k,queryNode:N.cloneWithUsing(this.#k.queryNode,Jk("Using",k))})}returning(k){return new Hk({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,A(k))})}returningAll(k){return new Hk({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,R(k))})}output(k){return new Hk({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,A(k))})}outputAll(k){return new Hk({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,R(k))})}}class O{#k;constructor(k){this.#k=h(k)}modifyEnd(k){return new O({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,k.toOperationNode())})}top(k,W){return new O({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}whenMatched(){return this.#W([])}whenMatchedAnd(...k){return this.#W(k)}whenMatchedAndRef(k,W,$){return this.#W([k,W,$],!0)}#W(k,W){return new BW({...this.#k,queryNode:N.cloneWithWhen(this.#k.queryNode,bW({isMatched:!0},k,W))})}whenNotMatched(){return this.#h([])}whenNotMatchedAnd(...k){return this.#h(k)}whenNotMatchedAndRef(k,W,$){return this.#h([k,W,$],!0)}whenNotMatchedBySource(){return this.#h([],!1,!0)}whenNotMatchedBySourceAnd(...k){return this.#h(k,!1,!0)}whenNotMatchedBySourceAndRef(k,W,$){return this.#h([k,W,$],!0,!0)}returning(k){return new O({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,A(k))})}returningAll(k){return new O({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,R(k))})}output(k){return new O({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,A(k))})}outputAll(k){return new O({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,R(k))})}#h(k,W=!1,$=!1){let M={...this.#k,queryNode:N.cloneWithWhen(this.#k.queryNode,bW({isMatched:!1,bySource:$},k,W))};return new($?BW:vh)(M)}$call(k){return k(this)}$if(k,W){if(k)return W(this);return new O({...this.#k})}toOperationNode(){return this.#k.executor.transformQuery(this.#k.queryNode,this.#k.queryId)}compile(){return this.#k.executor.compileQuery(this.toOperationNode(),this.#k.queryId)}async execute(){let k=this.compile(),W=await this.#k.executor.executeQuery(k),{adapter:$}=this.#k.executor,M=k.query;if(M.returning&&$.supportsReturning||M.output&&$.supportsOutput)return W.rows;return[new NW(W.numAffectedRows)]}async executeTakeFirst(){let[k]=await this.execute();return k}async executeTakeFirstOrThrow(k=u){let W=await this.executeTakeFirst();if(W===void 0)throw s(k)?new k(this.toOperationNode()):k(this.toOperationNode());return W}}class BW{#k;constructor(k){this.#k=h(k)}thenDelete(){return new O({...this.#k,queryNode:N.cloneWithThen(this.#k.queryNode,Ok("delete"))})}thenDoNothing(){return new O({...this.#k,queryNode:N.cloneWithThen(this.#k.queryNode,Ok("do nothing"))})}thenUpdate(k){return new O({...this.#k,queryNode:N.cloneWithThen(this.#k.queryNode,Ok(k(new jk({queryId:this.#k.queryId,executor:qk,queryNode:o.createWithoutTable()}))))})}thenUpdateSet(...k){return this.thenUpdate((W)=>W.set(...k))}}class vh{#k;constructor(k){this.#k=h(k)}thenDoNothing(){return new O({...this.#k,queryNode:N.cloneWithThen(this.#k.queryNode,Ok("do nothing"))})}thenInsertValues(k){let[W,$]=KW(k);return new O({...this.#k,queryNode:N.cloneWithThen(this.#k.queryNode,Ok(w.cloneWith(w.createWithoutInto(),{columns:W,values:$})))})}}class Pk{#k;constructor(k){this.#k=h(k)}selectFrom(k){return nk({queryId:T(),executor:this.#k.executor,queryNode:Y.createFrom(n(k),this.#k.withNode)})}selectNoFrom(k){return nk({queryId:T(),executor:this.#k.executor,queryNode:Y.cloneWithSelections(Y.create(this.#k.withNode),A(k))})}insertInto(k){return new D({queryId:T(),executor:this.#k.executor,queryNode:w.create(F(k),this.#k.withNode)})}replaceInto(k){return new D({queryId:T(),executor:this.#k.executor,queryNode:w.create(F(k),this.#k.withNode,!0)})}deleteFrom(k){return new HW({queryId:T(),executor:this.#k.executor,queryNode:Dk.create(n(k),this.#k.withNode)})}updateTable(k){return new jk({queryId:T(),executor:this.#k.executor,queryNode:o.create(n(k),this.#k.withNode)})}mergeInto(k){return new Hk({queryId:T(),executor:this.#k.executor,queryNode:N.create(fW(k),this.#k.withNode)})}with(k,W){let $=OW(k,W);return new Pk({...this.#k,withNode:this.#k.withNode?tk.cloneWithExpression(this.#k.withNode,$):tk.create($)})}withRecursive(k,W){let $=OW(k,W);return new Pk({...this.#k,withNode:this.#k.withNode?tk.cloneWithExpression(this.#k.withNode,$):tk.create($,{recursive:!0})})}withPlugin(k){return new Pk({...this.#k,executor:this.#k.executor.withPlugin(k)})}withoutPlugins(){return new Pk({...this.#k,executor:this.#k.executor.withoutPlugins()})}withSchema(k){return new Pk({...this.#k,executor:this.#k.executor.withPluginAtFront(new YW(k))})}}function Ph(){return new Pk({executor:qk})}function Ah(k,W){return new Rk({joinNode:Kk.create(k,wk(W))})}function _h(){return new Ck({overNode:xk.create()})}function Jk(k,W){if(W.length===3)return K$(k,W[0],W[1],W[2]);else if(W.length===2)return M$(k,W[0],W[1]);else if(W.length===1)return G$(k,W[0]);else throw Error("not implemented")}function M$(k,W,$){return $(Ah(k,W)).toOperationNode()}function K$(k,W,$,M){return Kk.createWithOn(k,wk(W),m($,"=",M))}function G$(k,W){return Kk.create(k,wk(W))}var mh=h({is(k){return k.kind==="OffsetNode"},create(k){return h({kind:"OffsetNode",offset:k})}});var Rh=h({is(k){return k.kind==="GroupByItemNode"},create(k){return h({kind:"GroupByItemNode",groupBy:k})}});function fh(k){return k=_(k)?k(d()):k,Gk(k).map(Rh.create)}function Tk(k,W,$){if(_(W))W=W(XW());if(!j(W))W=[W];return W.map((M)=>Ch.create(k,p(M),$))}class Z{#k;constructor(k){this.#k=k}get expressionType(){return}as(k){return new zW(this,k)}or(...k){return new DW(hk.create(this.#k,L(k)))}and(...k){return new LW(x.create(this.#k,L(k)))}$castTo(){return new Z(this.#k)}$notNull(){return new Z(this.#k)}toOperationNode(){return this.#k}}class zW{#k;#W;constructor(k,W){this.#k=k,this.#W=W}get expression(){return this.#k}get alias(){return this.#W}toOperationNode(){return I.create(this.#k.toOperationNode(),z(this.#W)?this.#W.toOperationNode():J.create(this.#W))}}class DW{#k;constructor(k){this.#k=k}get expressionType(){return}as(k){return new zW(this,k)}or(...k){return new DW(hk.create(this.#k,L(k)))}$castTo(){return new DW(this.#k)}toOperationNode(){return Xk.create(this.#k)}}class LW{#k;constructor(k){this.#k=k}get expressionType(){return}as(k){return new zW(this,k)}and(...k){return new LW(x.create(this.#k,L(k)))}$castTo(){return new LW(this.#k)}toOperationNode(){return Xk.create(this.#k)}}var Sh=h({is(k){return k.kind==="FetchNode"},create(k,W){return{kind:"FetchNode",rowCount:Q.create(k),modifier:W}}});function Ih(k,W){if(!_k(k)&&!GW(k))throw Error(`Invalid fetch row count: ${k}`);if(!H$(W))throw Error(`Invalid fetch modifier: ${W}`);return Sh.create(k,W)}function H$(k){return k==="only"||k==="with ties"}var H;class xW{#k;constructor(k){this.#k=h(k)}get expressionType(){return}get isSelectQueryBuilder(){return!0}where(...k){return new H({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,L(k))})}whereRef(k,W,$){return new H({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,m(k,W,$))})}having(...k){return new H({...this.#k,queryNode:Y.cloneWithHaving(this.#k.queryNode,L(k))})}havingRef(k,W,$){return new H({...this.#k,queryNode:Y.cloneWithHaving(this.#k.queryNode,m(k,W,$))})}select(k){return new H({...this.#k,queryNode:Y.cloneWithSelections(this.#k.queryNode,A(k))})}distinctOn(k){return new H({...this.#k,queryNode:Y.cloneWithDistinctOn(this.#k.queryNode,Gk(k))})}modifyFront(k){return new H({...this.#k,queryNode:Y.cloneWithFrontModifier(this.#k.queryNode,a.createWithExpression(k.toOperationNode()))})}modifyEnd(k){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.createWithExpression(k.toOperationNode()))})}distinct(){return new H({...this.#k,queryNode:Y.cloneWithFrontModifier(this.#k.queryNode,a.create("Distinct"))})}forUpdate(k){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("ForUpdate",k?dk(k).map(F):void 0))})}forShare(k){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("ForShare",k?dk(k).map(F):void 0))})}forKeyShare(k){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("ForKeyShare",k?dk(k).map(F):void 0))})}forNoKeyUpdate(k){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("ForNoKeyUpdate",k?dk(k).map(F):void 0))})}skipLocked(){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("SkipLocked"))})}noWait(){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("NoWait"))})}selectAll(k){return new H({...this.#k,queryNode:Y.cloneWithSelections(this.#k.queryNode,R(k))})}innerJoin(...k){return this.#W("InnerJoin",k)}leftJoin(...k){return this.#W("LeftJoin",k)}rightJoin(...k){return this.#W("RightJoin",k)}fullJoin(...k){return this.#W("FullJoin",k)}crossJoin(...k){return this.#W("CrossJoin",k)}innerJoinLateral(...k){return this.#W("LateralInnerJoin",k)}leftJoinLateral(...k){return this.#W("LateralLeftJoin",k)}crossJoinLateral(...k){return this.#W("LateralCrossJoin",k)}crossApply(...k){return this.#W("CrossApply",k)}outerApply(...k){return this.#W("OuterApply",k)}#W(k,W){return new H({...this.#k,queryNode:K.cloneWithJoin(this.#k.queryNode,Jk(k,W))})}orderBy(...k){return new H({...this.#k,queryNode:K.cloneWithOrderByItems(this.#k.queryNode,B(k))})}groupBy(k){return new H({...this.#k,queryNode:Y.cloneWithGroupByItems(this.#k.queryNode,fh(k))})}limit(k){return new H({...this.#k,queryNode:Y.cloneWithLimit(this.#k.queryNode,Ik.create(X(k)))})}offset(k){return new H({...this.#k,queryNode:Y.cloneWithOffset(this.#k.queryNode,mh.create(X(k)))})}fetch(k,W="only"){return new H({...this.#k,queryNode:Y.cloneWithFetch(this.#k.queryNode,Ih(k,W))})}top(k,W){return new H({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}union(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("union",k,!1))})}unionAll(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("union",k,!0))})}intersect(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("intersect",k,!1))})}intersectAll(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("intersect",k,!0))})}except(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("except",k,!1))})}exceptAll(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("except",k,!0))})}as(k){return new jh(this,k)}clearSelect(){return new H({...this.#k,queryNode:Y.cloneWithoutSelections(this.#k.queryNode)})}clearWhere(){return new H({...this.#k,queryNode:K.cloneWithoutWhere(this.#k.queryNode)})}clearLimit(){return new H({...this.#k,queryNode:Y.cloneWithoutLimit(this.#k.queryNode)})}clearOffset(){return new H({...this.#k,queryNode:Y.cloneWithoutOffset(this.#k.queryNode)})}clearOrderBy(){return new H({...this.#k,queryNode:K.cloneWithoutOrderBy(this.#k.queryNode)})}clearGroupBy(){return new H({...this.#k,queryNode:Y.cloneWithoutGroupBy(this.#k.queryNode)})}$call(k){return k(this)}$if(k,W){if(k)return W(this);return new H({...this.#k})}$castTo(){return new H(this.#k)}$narrowType(){return new H(this.#k)}$assertType(){return new H(this.#k)}$asTuple(){return new Z(this.toOperationNode())}$asScalar(){return new Z(this.toOperationNode())}withPlugin(k){return new H({...this.#k,executor:this.#k.executor.withPlugin(k)})}toOperationNode(){return this.#k.executor.transformQuery(this.#k.queryNode,this.#k.queryId)}compile(){return this.#k.executor.compileQuery(this.toOperationNode(),this.#k.queryId)}async execute(){let k=this.compile();return(await this.#k.executor.executeQuery(k)).rows}async executeTakeFirst(){let[k]=await this.execute();return k}async executeTakeFirstOrThrow(k=u){let W=await this.executeTakeFirst();if(W===void 0)throw s(k)?new k(this.toOperationNode()):k(this.toOperationNode());return W}async*stream(k=100){let W=this.compile(),$=this.#k.executor.stream(W,k);for await(let M of $)yield*M.rows}async explain(k,W){return await new H({...this.#k,queryNode:K.cloneWithExplain(this.#k.queryNode,k,W)}).execute()}}H=xW;function nk(k){return new xW(k)}class jh{#k;#W;constructor(k,W){this.#k=k,this.#W=W}get expression(){return this.#k}get alias(){return this.#W}get isAliasedSelectQueryBuilder(){return!0}toOperationNode(){return I.create(this.#k.toOperationNode(),J.create(this.#W))}}var e=h({is(k){return k.kind==="AggregateFunctionNode"},create(k,W=[]){return h({kind:"AggregateFunctionNode",func:k,aggregated:W})},cloneWithDistinct(k){return h({...k,distinct:!0})},cloneWithOrderBy(k,W,$=!1){let M=$?"withinGroup":"orderBy";return h({...k,[M]:k[M]?$k.cloneWithItems(k[M],W):$k.create(W)})},cloneWithFilter(k,W){return h({...k,filter:k.filter?C.cloneWithOperation(k.filter,"And",W):C.create(W)})},cloneWithOrFilter(k,W){return h({...k,filter:k.filter?C.cloneWithOperation(k.filter,"Or",W):C.create(W)})},cloneWithOver(k,W){return h({...k,over:W})}});var cW=h({is(k){return k.kind==="FunctionNode"},create(k,W){return h({kind:"FunctionNode",func:k,arguments:W})}});class b{#k;constructor(k){this.#k=h(k)}get expressionType(){return}as(k){return new Eh(this,k)}distinct(){return new b({...this.#k,aggregateFunctionNode:e.cloneWithDistinct(this.#k.aggregateFunctionNode)})}orderBy(...k){return new b({...this.#k,aggregateFunctionNode:K.cloneWithOrderByItems(this.#k.aggregateFunctionNode,B(k))})}clearOrderBy(){return new b({...this.#k,aggregateFunctionNode:K.cloneWithoutOrderBy(this.#k.aggregateFunctionNode)})}withinGroupOrderBy(...k){return new b({...this.#k,aggregateFunctionNode:e.cloneWithOrderBy(this.#k.aggregateFunctionNode,B(k),!0)})}filterWhere(...k){return new b({...this.#k,aggregateFunctionNode:e.cloneWithFilter(this.#k.aggregateFunctionNode,L(k))})}filterWhereRef(k,W,$){return new b({...this.#k,aggregateFunctionNode:e.cloneWithFilter(this.#k.aggregateFunctionNode,m(k,W,$))})}over(k){let W=_h();return new b({...this.#k,aggregateFunctionNode:e.cloneWithOver(this.#k.aggregateFunctionNode,(k?k(W):W).toOperationNode())})}$call(k){return k(this)}$castTo(){return new b(this.#k)}$notNull(){return new b(this.#k)}toOperationNode(){return this.#k.aggregateFunctionNode}}class Eh{#k;#W;constructor(k,W){this.#k=k,this.#W=W}get expression(){return this.#k}get alias(){return this.#W}toOperationNode(){return I.create(this.#k.toOperationNode(),J.create(this.#W))}}function Oh(){let k=($,M)=>{return new Z(cW.create($,Gk(M??[])))},W=($,M)=>{return new b({aggregateFunctionNode:e.create($,M?Gk(M):void 0)})};return Object.assign(k,{agg:W,avg($){return W("avg",[$])},coalesce(...$){return k("coalesce",$)},count($){return W("count",[$])},countAll($){return new b({aggregateFunctionNode:e.create("count",R($))})},max($){return W("max",[$])},min($){return W("min",[$])},sum($){return W("sum",[$])},any($){return k("any",[$])},jsonAgg($){return new b({aggregateFunctionNode:e.create("json_agg",[V($)?F($):$.toOperationNode()])})},toJson($){return new Z(cW.create("to_json",[V($)?F($):$.toOperationNode()]))}})}var bh=h({is(k){return k.kind==="UnaryOperationNode"},create(k,W){return h({kind:"UnaryOperationNode",operator:k,operand:W})}});function Qh(k,W){return bh.create(y.create(k),f(W))}var l=h({is(k){return k.kind==="CaseNode"},create(k){return h({kind:"CaseNode",value:k})},cloneWithWhen(k,W){return h({...k,when:h(k.when?[...k.when,W]:[W])})},cloneWithThen(k,W){return h({...k,when:k.when?h([...k.when.slice(0,-1),Mk.cloneWithResult(k.when[k.when.length-1],W)]):void 0})},cloneWith(k,W){return h({...k,...W})}});class yW{#k;constructor(k){this.#k=h(k)}when(...k){return new gW({...this.#k,node:l.cloneWithWhen(this.#k.node,Mk.create(L(k)))})}}class gW{#k;constructor(k){this.#k=h(k)}then(k){return new Nh({...this.#k,node:l.cloneWithThen(this.#k.node,WW(k)?Bk(k):X(k))})}}class Nh{#k;constructor(k){this.#k=h(k)}when(...k){return new gW({...this.#k,node:l.cloneWithWhen(this.#k.node,Mk.create(L(k)))})}else(k){return new Bh({...this.#k,node:l.cloneWith(this.#k.node,{else:WW(k)?Bk(k):X(k)})})}end(){return new Z(l.cloneWith(this.#k.node,{isStatement:!1}))}endCase(){return new Z(l.cloneWith(this.#k.node,{isStatement:!0}))}}class Bh{#k;constructor(k){this.#k=h(k)}end(){return new Z(l.cloneWith(this.#k.node,{isStatement:!1}))}endCase(){return new Z(l.cloneWith(this.#k.node,{isStatement:!0}))}}var JW=h({is(k){return k.kind==="JSONOperatorChainNode"},create(k){return h({kind:"JSONOperatorChainNode",operator:k,values:h([])})},cloneWithValue(k,W){return h({...k,values:h([...k.values,W])})}});var tW=h({is(k){return k.kind==="JSONPathLegNode"},create(k,W){return h({kind:"JSONPathLegNode",type:k,value:W})}});var Uk=h({is(k){return k.kind==="JSONPathNode"},create(k){return h({kind:"JSONPathNode",inOperator:k,pathLegs:h([])})},cloneWithLeg(k,W){return h({...k,pathLegs:h([...k.pathLegs,W])})}});var Qk=h({is(k){return k.kind==="JSONReferenceNode"},create(k,W){return h({kind:"JSONReferenceNode",reference:k,traversal:W})},cloneWithTraversal(k,W){return h({...k,traversal:W})}});var Z$=/^#-\d+$/;class ik{#k;constructor(k){this.#k=k}at(k){if(typeof k!=="number"&&typeof k!=="string"||typeof k==="number"&&!Number.isInteger(k)||typeof k==="string"&&k!=="last"&&!Z$.test(k))throw Error(`Unexpected index value in .at(...): ${k}`);return this.#W("ArrayLocation",k)}key(k){return this.#W("Member",k)}#W(k,W){if(Qk.is(this.#k))return new uk(Qk.cloneWithTraversal(this.#k,Uk.is(this.#k.traversal)?Uk.cloneWithLeg(this.#k.traversal,tW.create(k,W)):JW.cloneWithValue(this.#k.traversal,Q.createImmediate(W))));return new uk(Uk.cloneWithLeg(this.#k,tW.create(k,W)))}}class uk extends ik{#k;constructor(k){super(k);this.#k=k}get expressionType(){return}as(k){return new xh(this,k)}$castTo(){return new uk(this.#k)}$notNull(){return new uk(this.#k)}toOperationNode(){return this.#k}}class xh{#k;#W;constructor(k,W){this.#k=k,this.#W=W}get expression(){return this.#k}get alias(){return this.#W}toOperationNode(){return I.create(this.#k.toOperationNode(),z(this.#W)?this.#W.toOperationNode():J.create(this.#W))}}var nW=h({is(k){return k.kind==="TupleNode"},create(k){return h({kind:"TupleNode",values:h(k)})}});var Y$=["varchar","char","text","integer","int2","int4","int8","smallint","bigint","boolean","real","double precision","float4","float8","decimal","numeric","binary","bytea","date","datetime","time","timetz","timestamp","timestamptz","serial","bigserial","uuid","json","jsonb","blob","varbinary","int4range","int4multirange","int8range","int8multirange","numrange","nummultirange","tsrange","tsmultirange","tstzrange","tstzmultirange","daterange","datemultirange"],X$=[/^varchar\(\d+\)$/,/^char\(\d+\)$/,/^decimal\(\d+, \d+\)$/,/^numeric\(\d+, \d+\)$/,/^binary\(\d+\)$/,/^datetime\(\d+\)$/,/^time\(\d+\)$/,/^timetz\(\d+\)$/,/^timestamp\(\d+\)$/,/^timestamptz\(\d+\)$/,/^varbinary\(\d+\)$/],ch=h({is(k){return k.kind==="DataTypeNode"},create(k){return h({kind:"DataTypeNode",dataType:k})}});function yh(k){if(Y$.includes(k))return!0;if(X$.some((W)=>W.test(k)))return!0;return!1}function gh(k){if(z(k))return k.toOperationNode();if(yh(k))return ch.create(k);throw Error(`invalid column data type ${JSON.stringify(k)}`)}var th=h({is(k){return k.kind==="CastNode"},create(k,W){return h({kind:"CastNode",expression:k,dataType:W})}});function XW(k=qk){function W(G,q,vk){return new Z(hW(G,q,vk))}function $(G,q){return new Z(Qh(G,q))}let M=Object.assign(W,{fn:void 0,eb:void 0,selectFrom(G){return nk({queryId:T(),executor:k,queryNode:Y.createFrom(n(G))})},case(G){return new yW({node:l.create(c(G)?void 0:f(G))})},ref(G,q){if(c(q))return new Z(t(G));return new ik(nh(G,q))},jsonPath(){return new ik(Uk.create())},table(G){return new Z(F(G))},val(G){return new Z(X(G))},refTuple(...G){return new Z(nW.create(G.map(f)))},tuple(...G){return new Z(nW.create(G.map(X)))},lit(G){return new Z(Bk(G))},unary:$,not(G){return $("not",G)},exists(G){return $("exists",G)},neg(G){return $("-",G)},between(G,q,vk){return new Z(Yk.create(f(G),y.create("between"),x.create(X(q),X(vk))))},betweenSymmetric(G,q,vk){return new Z(Yk.create(f(G),y.create("between symmetric"),x.create(X(q),X(vk))))},and(G){if(j(G))return new Z(mk(G,"and"));return new Z(UW(G,"and"))},or(G){if(j(G))return new Z(mk(G,"or"));return new Z(UW(G,"or"))},parens(...G){let q=L(G);if(Xk.is(q))return new Z(q);else return new Z(Xk.create(q))},cast(G,q){return new Z(th.create(f(G),gh(q)))},withSchema(G){return XW(k.withPluginAtFront(new YW(G)))}});return M.fn=Oh(),M.eb=M,M}function d(k){return XW()}function p(k){if(z(k))return k.toOperationNode();else if(_(k))return k(d()).toOperationNode();throw Error(`invalid expression: ${JSON.stringify(k)}`)}function MW(k){if(z(k))return k.toOperationNode();else if(_(k))return k(d()).toOperationNode();throw Error(`invalid aliased expression: ${JSON.stringify(k)}`)}function Wk(k){return ok(k)||iW(k)||_(k)}function _W(k){if(V(k))return t(k);return k.toOperationNode()}function Gk(k){if(j(k))return k.map((W)=>f(W));else return[f(k)]}function f(k){if(Wk(k))return p(k);return _W(k)}function nh(k,W){let $=t(k);if(dW(W))return Qk.create($,JW.create(y.create(W)));let M=W.slice(0,-1);if(dW(M))return Qk.create($,Uk.create(y.create(M)));throw Error(`Invalid JSON operator: ${W}`)}function t(k){if(!k.includes("."))return Ak.create(S.create(k));let $=k.split(".").map(uW);if($.length===3)return L$($);if($.length===2)return z$($);throw Error(`invalid column reference ${k}`)}function Zh(k){if(k.includes(" as ")){let[$,M]=k.split(" as ").map(uW);return I.create(t($),J.create(M))}else return t(k)}function D$(k){return S.create(k)}function R3(k){if(k.includes(" ")){let[$,M]=k.split(" ").map(uW);if(!RW(M))throw Error(`invalid order direction "${M}" next to "${$}"`);return B([$,M])[0]}else return D$(k)}function L$(k){let[W,$,M]=k;return Ak.create(S.create(M),zk.createWithSchema(W,$))}function z$(k){let[W,$]=k;return Ak.create(S.create($),zk.create(W))}function uW(k){return k.trim()}class lk{#k;constructor(k){this.#k=h(k)}get expressionType(){return}get isRawBuilder(){return!0}as(k){return new dh(this,k)}$castTo(){return new lk({...this.#k})}$notNull(){return new lk(this.#k)}withPlugin(k){return new lk({...this.#k,plugins:this.#k.plugins!==void 0?h([...this.#k.plugins,k]):h([k])})}toOperationNode(){return this.#h(this.#W())}compile(k){return this.#$(this.#W(k))}async execute(k){let W=this.#W(k);return W.executeQuery(this.#$(W))}#W(k){let W=k!==void 0?k.getExecutor():qk;return this.#k.plugins!==void 0?W.withPlugins(this.#k.plugins):W}#h(k){return k.transformQuery(this.#k.rawNode,this.#k.queryId)}#$(k){return k.compileQuery(this.#h(k),this.#k.queryId)}}function Zk(k){return new lk(k)}class dh{#k;#W;constructor(k,W){this.#k=k,this.#W=W}get expression(){return this.#k}get alias(){return this.#W}get rawBuilder(){return this.#k}toOperationNode(){return I.create(this.#k.toOperationNode(),z(this.#W)?this.#W.toOperationNode():J.create(this.#W))}}var J$=Object.assign((k,...W)=>{return Zk({queryId:T(),rawNode:v.create(k,W?.map(uh)??[])})},{ref(k){return Zk({queryId:T(),rawNode:v.createWithChild(t(k))})},val(k){return Zk({queryId:T(),rawNode:v.createWithChild(X(k))})},value(k){return this.val(k)},table(k){return Zk({queryId:T(),rawNode:v.createWithChild(F(k))})},id(...k){let W=Array(k.length+1).fill(".");return W[0]="",W[W.length-1]="",Zk({queryId:T(),rawNode:v.create(W,k.map(J.create))})},lit(k){return Zk({queryId:T(),rawNode:v.createWithChild(Q.createImmediate(k))})},literal(k){return this.lit(k)},raw(k){return Zk({queryId:T(),rawNode:v.createWithSql(k)})},join(k,W=J$`, `){let $=Array(Math.max(2*k.length-1,0)),M=W.toOperationNode();for(let G=0;G<k.length;++G)if($[2*G]=uh(k[G]),G!==k.length-1)$[2*G+1]=M;return Zk({queryId:T(),rawNode:v.createWithChildren($)})}});function uh(k){if(z(k))return k.toOperationNode();return X(k)}var l3=h({raw(k,W=[]){return h({sql:k,query:v.createWithSql(k),parameters:h(W),queryId:T()})}});
3
- export{z as mc,S as nc,pk as oc,ah as pc,t as qc,D$ as rc,R3 as sc,rk as tc,Q as uc,L as vc,K as wc,Y as xc,Vh as yc,T as zc,ZW as Ac,Th as Bc,QW as Cc,Pk as Dc,Oh as Ec,l as Fc,yW as Gc,gh as Hc,p as Ic,oh as Jc,F as Kc,J$ as Lc,l3 as Mc};
2
+ import{$d as Mk,Bd as GW,Dd as _,Ed as kk,Fd as h,Gd as dk,Hd as j,Jd as J,Nd as I,Od as zk,Pd as x,Qd as hk,Rd as Kk,Sd as pW,Td as y,Ud as dW,Vd as v,Wd as fk,Xd as Xk,Yd as w,Zd as sW,_d as TW,be as YW,ce as Ch,vd as c,wd as V,xd as _k,yd as ek,zd as kW}from"./chunk-n4meg9wb.js";function z(k){return kk(k)&&_(k.toOperationNode)}var Q=h({is(k){return k.kind==="ValueNode"},create(k){return h({kind:"ValueNode",value:k})},createImmediate(k){return h({kind:"ValueNode",value:k,immediate:!0})}});var S=h({is(k){return k.kind==="ColumnNode"},create(k){return h({kind:"ColumnNode",column:J.create(k)})}});var pk=h({is(k){return k.kind==="SelectAllNode"},create(){return h({kind:"SelectAllNode"})}});var Ak=h({is(k){return k.kind==="ReferenceNode"},create(k,W){return h({kind:"ReferenceNode",table:W,column:k})},createSelectAll(k){return h({kind:"ReferenceNode",table:k,column:pk.create()})}});function ok(k){return kk(k)&&"expressionType"in k&&z(k)}function iW(k){return kk(k)&&"expression"in k&&V(k.alias)&&z(k)}var a=h({is(k){return k.kind==="SelectModifierNode"},create(k,W){return h({kind:"SelectModifierNode",modifier:k,of:W})},createWithExpression(k){return h({kind:"SelectModifierNode",rawModifier:k})}});var Yk=h({is(k){return k.kind==="BinaryOperationNode"},create(k,W,$){return h({kind:"BinaryOperationNode",leftOperand:k,operator:W,rightOperand:$})}});var sk=h({is(k){return k.kind==="PrimitiveValueListNode"},create(k){return h({kind:"PrimitiveValueListNode",values:h([...k])})}});var rk=h({is(k){return k.kind==="ValueListNode"},create(k){return h({kind:"ValueListNode",values:h(k)})}});function lW(k){if(j(k))return ih(k);return X(k)}function X(k){if(Wk(k))return p(k);return Q.create(k)}function WW(k){return _k(k)||ek(k)||kW(k)}function Bk(k){if(!WW(k))throw Error(`unsafe immediate value ${JSON.stringify(k)}`);return Q.createImmediate(k)}function ih(k){if(k.some(Wk))return rk.create(k.map((W)=>X(W)));return sk.create(k)}function L(k){if(k.length===3)return hW(k[0],k[1],k[2]);else if(k.length===1)return X(k[0]);throw Error(`invalid arguments: ${JSON.stringify(k)}`)}function hW(k,W,$){if(lh(W)&&oW($))return Yk.create(f(k),PW(W),Q.createImmediate($));return Yk.create(f(k),PW(W),lW($))}function m(k,W,$){return Yk.create(f(k),PW(W),f($))}function UW(k,W){return mk(Object.entries(k).filter(([,$])=>!c($)).map(([$,M])=>hW($,oW(M)?"is":"=",M)),W)}function mk(k,W,$=!0){let M=W==="and"?x.create:hk.create;if(k.length===0)return Yk.create(Q.createImmediate(1),y.create("="),Q.createImmediate(W==="and"?1:0));let G=aW(k[0]);for(let q=1;q<k.length;++q)G=M(G,aW(k[q]));if(k.length>1&&$)return Xk.create(G);return G}function lh(k){return k==="is"||k==="is not"}function oW(k){return kW(k)||ek(k)}function PW(k){if(V(k)&&pW.includes(k))return y.create(k);if(z(k))return k.toOperationNode();throw Error(`invalid operator ${JSON.stringify(k)}`)}function aW(k){return z(k)?k.toOperationNode():k}var $k=h({is(k){return k.kind==="OrderByNode"},create(k){return h({kind:"OrderByNode",items:h([...k])})},cloneWithItems(k,W){return h({...k,items:h([...k.items,...W])})}});var VW=h({is(k){return k.kind==="PartitionByNode"},create(k){return h({kind:"PartitionByNode",items:h(k)})},cloneWithItems(k,W){return h({...k,items:h([...k.items,...W])})}});var xk=h({is(k){return k.kind==="OverNode"},create(){return h({kind:"OverNode"})},cloneWithOrderByItems(k,W){return h({...k,orderBy:k.orderBy?$k.cloneWithItems(k.orderBy,W):$k.create(W)})},cloneWithPartitionByItems(k,W){return h({...k,partitionBy:k.partitionBy?VW.cloneWithItems(k.partitionBy,W):VW.create(W)})}});var Vk=h({is(k){return k.kind==="FromNode"},create(k){return h({kind:"FromNode",froms:h(k)})},cloneWithFroms(k,W){return h({...k,froms:h([...k.froms,...W])})}});var wW=h({is(k){return k.kind==="GroupByNode"},create(k){return h({kind:"GroupByNode",items:h(k)})},cloneWithItems(k,W){return h({...k,items:h([...k.items,...W])})}});var FW=h({is(k){return k.kind==="HavingNode"},create(k){return h({kind:"HavingNode",having:k})},cloneWithOperation(k,W,$){return h({...k,having:W==="And"?x.create(k.having,$):hk.create(k.having,$)})}});var o=h({is(k){return k.kind==="UpdateQueryNode"},create(k,W){return h({kind:"UpdateQueryNode",table:k.length===1?k[0]:sW.create(k),...W&&{with:W}})},createWithoutTable(){return h({kind:"UpdateQueryNode"})},cloneWithFromItems(k,W){return h({...k,from:k.from?Vk.cloneWithFroms(k.from,W):Vk.create(W)})},cloneWithUpdates(k,W){return h({...k,updates:k.updates?h([...k.updates,...W]):W})},cloneWithLimit(k,W){return h({...k,limit:W})}});var Dk=h({is(k){return k.kind==="DeleteQueryNode"},create(k,W){return h({kind:"DeleteQueryNode",from:Vk.create(k),...W&&{with:W}})},cloneWithOrderByItems:(k,W)=>K.cloneWithOrderByItems(k,W),cloneWithoutOrderBy:(k)=>K.cloneWithoutOrderBy(k),cloneWithLimit(k,W){return h({...k,limit:W})},cloneWithoutLimit(k){return h({...k,limit:void 0})},cloneWithUsing(k,W){return h({...k,using:k.using!==void 0?TW.cloneWithTables(k.using,W):TW.create(W)})}});var C=h({is(k){return k.kind==="WhereNode"},create(k){return h({kind:"WhereNode",where:k})},cloneWithOperation(k,W,$){return h({...k,where:W==="And"?x.create(k.where,$):hk.create(k.where,$)})}});var vW=h({is(k){return k.kind==="ReturningNode"},create(k){return h({kind:"ReturningNode",selections:h(k)})},cloneWithSelections(k,W){return h({...k,selections:k.selections?h([...k.selections,...W]):h(W)})}});var rW=h({is(k){return k.kind==="ExplainNode"},create(k,W){return h({kind:"ExplainNode",format:k,options:W})}});var N=h({is(k){return k.kind==="MergeQueryNode"},create(k,W){return h({kind:"MergeQueryNode",into:k,...W&&{with:W}})},cloneWithUsing(k,W){return h({...k,using:W})},cloneWithWhen(k,W){return h({...k,whens:k.whens?h([...k.whens,W]):h([W])})},cloneWithThen(k,W){return h({...k,whens:k.whens?h([...k.whens.slice(0,-1),Mk.cloneWithResult(k.whens[k.whens.length-1],W)]):void 0})}});var AW=h({is(k){return k.kind==="OutputNode"},create(k){return h({kind:"OutputNode",selections:h(k)})},cloneWithSelections(k,W){return h({...k,selections:k.selections?h([...k.selections,...W]):h(W)})}});var K=h({is(k){return Y.is(k)||w.is(k)||o.is(k)||Dk.is(k)||N.is(k)},cloneWithEndModifier(k,W){return h({...k,endModifiers:k.endModifiers?h([...k.endModifiers,W]):h([W])})},cloneWithWhere(k,W){return h({...k,where:k.where?C.cloneWithOperation(k.where,"And",W):C.create(W)})},cloneWithJoin(k,W){return h({...k,joins:k.joins?h([...k.joins,W]):h([W])})},cloneWithReturning(k,W){return h({...k,returning:k.returning?vW.cloneWithSelections(k.returning,W):vW.create(W)})},cloneWithoutReturning(k){return h({...k,returning:void 0})},cloneWithoutWhere(k){return h({...k,where:void 0})},cloneWithExplain(k,W,$){return h({...k,explain:rW.create(W,$?.toOperationNode())})},cloneWithTop(k,W){return h({...k,top:W})},cloneWithOutput(k,W){return h({...k,output:k.output?AW.cloneWithSelections(k.output,W):AW.create(W)})},cloneWithOrderByItems(k,W){return h({...k,orderBy:k.orderBy?$k.cloneWithItems(k.orderBy,W):$k.create(W)})},cloneWithoutOrderBy(k){return h({...k,orderBy:void 0})}});var Y=h({is(k){return k.kind==="SelectQueryNode"},create(k){return h({kind:"SelectQueryNode",...k&&{with:k}})},createFrom(k,W){return h({kind:"SelectQueryNode",from:Vk.create(k),...W&&{with:W}})},cloneWithSelections(k,W){return h({...k,selections:k.selections?h([...k.selections,...W]):h(W)})},cloneWithDistinctOn(k,W){return h({...k,distinctOn:k.distinctOn?h([...k.distinctOn,...W]):h(W)})},cloneWithFrontModifier(k,W){return h({...k,frontModifiers:k.frontModifiers?h([...k.frontModifiers,W]):h([W])})},cloneWithOrderByItems:(k,W)=>K.cloneWithOrderByItems(k,W),cloneWithGroupByItems(k,W){return h({...k,groupBy:k.groupBy?wW.cloneWithItems(k.groupBy,W):wW.create(W)})},cloneWithLimit(k,W){return h({...k,limit:W})},cloneWithOffset(k,W){return h({...k,offset:W})},cloneWithFetch(k,W){return h({...k,fetch:W})},cloneWithHaving(k,W){return h({...k,having:k.having?FW.cloneWithOperation(k.having,"And",W):FW.create(W)})},cloneWithSetOperations(k,W){return h({...k,setOperations:k.setOperations?h([...k.setOperations,...W]):h([...W])})},cloneWithoutSelections(k){return h({...k,selections:[]})},cloneWithoutLimit(k){return h({...k,limit:void 0})},cloneWithoutOffset(k){return h({...k,offset:void 0})},cloneWithoutOrderBy:(k)=>K.cloneWithoutOrderBy(k),cloneWithoutGroupBy(k){return h({...k,groupBy:void 0})}});class Rk{#k;constructor(k){this.#k=h(k)}on(...k){return new Rk({...this.#k,joinNode:Kk.cloneWithOn(this.#k.joinNode,L(k))})}onRef(k,W,$){return new Rk({...this.#k,joinNode:Kk.cloneWithOn(this.#k.joinNode,m(k,W,$))})}onTrue(){return new Rk({...this.#k,joinNode:Kk.cloneWithOn(this.#k.joinNode,v.createWithSql("true"))})}$call(k){return k(this)}toOperationNode(){return this.#k.joinNode}}class ah{#k;get dynamicReference(){return this.#k}get refType(){return}constructor(k){this.#k=k}toOperationNode(){return _W(this.#k)}}function $W(k){return kk(k)&&z(k)&&V(k.dynamicReference)}var g=h({is(k){return k.kind==="OrderByItemNode"},create(k,W){return h({kind:"OrderByItemNode",orderBy:k,direction:W})},cloneWith(k,W){return h({...k,...W})}});var eW=h({is(k){return k.kind==="CollateNode"},create(k){return h({kind:"CollateNode",collation:J.create(k)})}});class Lk{#k;constructor(k){this.#k=h(k)}desc(){return new Lk({node:g.cloneWith(this.#k.node,{direction:v.createWithSql("desc")})})}asc(){return new Lk({node:g.cloneWith(this.#k.node,{direction:v.createWithSql("asc")})})}nullsLast(){return new Lk({node:g.cloneWith(this.#k.node,{nulls:"last"})})}nullsFirst(){return new Lk({node:g.cloneWith(this.#k.node,{nulls:"first"})})}collate(k){return new Lk({node:g.cloneWith(this.#k.node,{collation:eW.create(k)})})}toOperationNode(){return this.#k.node}}function RW(k){return k==="asc"||k==="desc"}function B(k){if(k.length===2)return[mW(k[0],k[1])];if(k.length===1){let[W]=k;if(Array.isArray(W))return fk("orderBy(array) is deprecated, use multiple orderBy calls instead."),W.map(($)=>mW($));return[mW(W)]}throw Error(`Invalid number of arguments at order by! expected 1-2, received ${k.length}`)}function mW(k,W){let $=ph(k);if(g.is($)){if(W)throw Error("Cannot specify direction twice!");return $}return kh($,W)}function ph(k){if(Wk(k))return p(k);if($W(k))return k.toOperationNode();let[W,$]=k.split(" ");if($)return fk("`orderBy('column asc')` is deprecated. Use `orderBy('column', 'asc')` instead."),kh(t(W),$);return t(k)}function kh(k,W){if(typeof W==="string"){if(!RW(W))throw Error(`Invalid order by direction: ${W}`);return g.create(k,v.createWithSql(W))}if(ok(W))return fk("`orderBy(..., expr)` is deprecated. Use `orderBy(..., 'asc')` or `orderBy(..., (ob) => ...)` instead."),g.create(k,W.toOperationNode());let $=g.create(k);if(!W)return $;return W(new Lk({node:$})).toOperationNode()}var Wh=h({is(k){return k.kind==="PartitionByItemNode"},create(k){return h({kind:"PartitionByItemNode",partitionBy:k})}});function hh(k){return Gk(k).map(Wh.create)}class Ck{#k;constructor(k){this.#k=h(k)}orderBy(...k){return new Ck({overNode:xk.cloneWithOrderByItems(this.#k.overNode,B(k))})}clearOrderBy(){return new Ck({overNode:K.cloneWithoutOrderBy(this.#k.overNode)})}partitionBy(k){return new Ck({overNode:xk.cloneWithPartitionByItems(this.#k.overNode,hh(k))})}$call(k){return k(this)}toOperationNode(){return this.#k.overNode}}var Sk=h({is(k){return k.kind==="SelectionNode"},create(k){return h({kind:"SelectionNode",selection:k})},createSelectAll(){return h({kind:"SelectionNode",selection:pk.create()})},createSelectAllFromTable(k){return h({kind:"SelectionNode",selection:Ak.createSelectAll(k)})}});class oh{#k;get table(){return this.#k}constructor(k){this.#k=k}as(k){return new $h(this.#k,k)}}class $h{#k;#W;get table(){return this.#k}get alias(){return this.#W}constructor(k,W){this.#k=k,this.#W=W}toOperationNode(){return I.create(F(this.#k),J.create(this.#W))}}function Mh(k){return kk(k)&&z(k)&&V(k.table)&&V(k.alias)}function n(k){if(j(k))return k.map((W)=>wk(W));else return[wk(k)]}function wk(k){if(V(k))return fW(k);else if(Mh(k))return k.toOperationNode();else return MW(k)}function fW(k){if(k.includes(" as ")){let[$,M]=k.split(" as ").map(Kh);return I.create(F($),J.create(M))}else return F(k)}function F(k){if(k.includes(".")){let[$,M]=k.split(".").map(Kh);return zk.createWithSchema($,M)}else return zk.create(k)}function Kh(k){return k.trim()}function A(k){if(_(k))return A(k(d()));else if(j(k))return k.map((W)=>Gh(W));else return[Gh(k)]}function Gh(k){if(V(k))return Sk.create(Zh(k));else if($W(k))return Sk.create(k.toOperationNode());else return Sk.create(MW(k))}function R(k){if(!k)return[Sk.createSelectAll()];else if(Array.isArray(k))return k.map(Hh);else return[Hh(k)]}function Hh(k){if(V(k))return Sk.createSelectAllFromTable(F(k));throw Error(`invalid value selectAll expression: ${JSON.stringify(k)}`)}var Yh=h({is(k){return k.kind==="ValuesNode"},create(k){return h({kind:"ValuesNode",values:h(k)})}});var Xh=h({is(k){return k.kind==="DefaultInsertValueNode"},create(){return h({kind:"DefaultInsertValueNode"})}});function KW(k){let W=_(k)?k(d()):k,$=j(W)?W:h([W]);return sh($)}function sh(k){let W=rh(k);return[h([...W.keys()].map(S.create)),Yh.create(k.map(($)=>eh($,W)))]}function rh(k){let W=new Map;for(let $ of k){let M=Object.keys($);for(let G of M)if(!W.has(G)&&$[G]!==void 0)W.set(G,W.size)}return W}function eh(k,W){let $=Object.keys(k),M=Array.from({length:W.size}),G=!1,q=$.length;for(let ak of $){let Nk=W.get(ak);if(c(Nk)){q--;continue}let qW=k[ak];if(c(qW)||Wk(qW))G=!0;M[Nk]=qW}if(q<W.size||G){let ak=Xh.create();return rk.create(M.map((Nk)=>c(Nk)?ak:X(Nk)))}return sk.create(M)}var CW=h({is(k){return k.kind==="ColumnUpdateNode"},create(k,W){return h({kind:"ColumnUpdateNode",column:k,value:W})}});function Dh(...k){if(k.length===2)return[CW.create(f(k[0]),X(k[1]))];return ck(k[0])}function ck(k){let W=_(k)?k(d()):k;return Object.entries(W).filter(([$,M])=>M!==void 0).map(([$,M])=>{return CW.create(S.create($),X(M))})}var Lh=h({is(k){return k.kind==="OnDuplicateKeyNode"},create(k){return h({kind:"OnDuplicateKeyNode",updates:k})}});class SW{insertId;numInsertedOrUpdatedRows;constructor(k,W){this.insertId=k,this.numInsertedOrUpdatedRows=W}}class u extends Error{node;constructor(k){super("no result");this.node=k}}function s(k){return Object.prototype.hasOwnProperty.call(k,"prototype")}var E=h({is(k){return k.kind==="OnConflictNode"},create(){return h({kind:"OnConflictNode"})},cloneWith(k,W){return h({...k,...W})},cloneWithIndexWhere(k,W){return h({...k,indexWhere:k.indexWhere?C.cloneWithOperation(k.indexWhere,"And",W):C.create(W)})},cloneWithIndexOrWhere(k,W){return h({...k,indexWhere:k.indexWhere?C.cloneWithOperation(k.indexWhere,"Or",W):C.create(W)})},cloneWithUpdateWhere(k,W){return h({...k,updateWhere:k.updateWhere?C.cloneWithOperation(k.updateWhere,"And",W):C.create(W)})},cloneWithUpdateOrWhere(k,W){return h({...k,updateWhere:k.updateWhere?C.cloneWithOperation(k.updateWhere,"Or",W):C.create(W)})},cloneWithoutIndexWhere(k){return h({...k,indexWhere:void 0})},cloneWithoutUpdateWhere(k){return h({...k,updateWhere:void 0})}});class r{#k;constructor(k){this.#k=h(k)}column(k){let W=S.create(k);return new r({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{columns:this.#k.onConflictNode.columns?h([...this.#k.onConflictNode.columns,W]):h([W])})})}columns(k){let W=k.map(S.create);return new r({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{columns:this.#k.onConflictNode.columns?h([...this.#k.onConflictNode.columns,...W]):h(W)})})}constraint(k){return new r({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{constraint:J.create(k)})})}expression(k){return new r({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{indexExpression:k.toOperationNode()})})}where(...k){return new r({...this.#k,onConflictNode:E.cloneWithIndexWhere(this.#k.onConflictNode,L(k))})}whereRef(k,W,$){return new r({...this.#k,onConflictNode:E.cloneWithIndexWhere(this.#k.onConflictNode,m(k,W,$))})}clearWhere(){return new r({...this.#k,onConflictNode:E.cloneWithoutIndexWhere(this.#k.onConflictNode)})}doNothing(){return new zh({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{doNothing:!0})})}doUpdateSet(k){return new yk({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{updates:ck(k)})})}$call(k){return k(this)}}class zh{#k;constructor(k){this.#k=h(k)}toOperationNode(){return this.#k.onConflictNode}}class yk{#k;constructor(k){this.#k=h(k)}where(...k){return new yk({...this.#k,onConflictNode:E.cloneWithUpdateWhere(this.#k.onConflictNode,L(k))})}whereRef(k,W,$){return new yk({...this.#k,onConflictNode:E.cloneWithUpdateWhere(this.#k.onConflictNode,m(k,W,$))})}clearWhere(){return new yk({...this.#k,onConflictNode:E.cloneWithoutUpdateWhere(this.#k.onConflictNode)})}$call(k){return k(this)}toOperationNode(){return this.#k.onConflictNode}}var Jh=h({is(k){return k.kind==="TopNode"},create(k,W){return h({kind:"TopNode",expression:k,modifiers:W})}});function i(k,W){if(!_k(k)&&!GW(k))throw Error(`Invalid top expression: ${k}`);if(!c(W)&&!k$(W))throw Error(`Invalid top modifiers: ${W}`);return Jh.create(k,W)}function k$(k){return k==="percent"||k==="with ties"||k==="percent with ties"}var Fk=h({is(k){return k.kind==="OrActionNode"},create(k){return h({kind:"OrActionNode",action:k})}});class D{#k;constructor(k){this.#k=h(k)}values(k){let[W,$]=KW(k);return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{columns:W,values:$})})}columns(k){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{columns:h(k.map(S.create))})})}expression(k){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{values:p(k)})})}defaultValues(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{defaultValues:!0})})}modifyEnd(k){return new D({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,k.toOperationNode())})}ignore(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("ignore")})})}orIgnore(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("ignore")})})}orAbort(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("abort")})})}orFail(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("fail")})})}orReplace(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("replace")})})}orRollback(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("rollback")})})}top(k,W){return new D({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}onConflict(k){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{onConflict:k(new r({onConflictNode:E.create()})).toOperationNode()})})}onDuplicateKeyUpdate(k){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{onDuplicateKey:Lh.create(ck(k))})})}returning(k){return new D({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,A(k))})}returningAll(){return new D({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,R())})}output(k){return new D({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,A(k))})}outputAll(k){return new D({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,R(k))})}clearReturning(){return new D({...this.#k,queryNode:K.cloneWithoutReturning(this.#k.queryNode)})}$call(k){return k(this)}$if(k,W){if(k)return W(this);return new D({...this.#k})}$castTo(){return new D(this.#k)}$narrowType(){return new D(this.#k)}$assertType(){return new D(this.#k)}withPlugin(k){return new D({...this.#k,executor:this.#k.executor.withPlugin(k)})}toOperationNode(){return this.#k.executor.transformQuery(this.#k.queryNode,this.#k.queryId)}compile(){return this.#k.executor.compileQuery(this.toOperationNode(),this.#k.queryId)}async execute(){let k=this.compile(),W=await this.#k.executor.executeQuery(k),{adapter:$}=this.#k.executor,M=k.query;if(M.returning&&$.supportsReturning||M.output&&$.supportsOutput)return W.rows;return[new SW(W.insertId,W.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[k]=await this.execute();return k}async executeTakeFirstOrThrow(k=u){let W=await this.executeTakeFirst();if(W===void 0)throw s(k)?new k(this.toOperationNode()):k(this.toOperationNode());return W}async*stream(k=100){let W=this.compile(),$=this.#k.executor.stream(W,k);for await(let M of $)yield*M.rows}async explain(k,W){return await new D({...this.#k,queryNode:K.cloneWithExplain(this.#k.queryNode,k,W)}).execute()}}class IW{numDeletedRows;constructor(k){this.numDeletedRows=k}}var Ik=h({is(k){return k.kind==="LimitNode"},create(k){return h({kind:"LimitNode",limit:k})}});var P;class HW{#k;constructor(k){this.#k=h(k)}where(...k){return new P({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,L(k))})}whereRef(k,W,$){return new P({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,m(k,W,$))})}clearWhere(){return new P({...this.#k,queryNode:K.cloneWithoutWhere(this.#k.queryNode)})}top(k,W){return new P({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}using(k){return new P({...this.#k,queryNode:Dk.cloneWithUsing(this.#k.queryNode,n(k))})}innerJoin(...k){return this.#W("InnerJoin",k)}leftJoin(...k){return this.#W("LeftJoin",k)}rightJoin(...k){return this.#W("RightJoin",k)}fullJoin(...k){return this.#W("FullJoin",k)}#W(k,W){return new P({...this.#k,queryNode:K.cloneWithJoin(this.#k.queryNode,Jk(k,W))})}returning(k){return new P({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,A(k))})}returningAll(k){return new P({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,R(k))})}output(k){return new P({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,A(k))})}outputAll(k){return new P({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,R(k))})}clearReturning(){return new P({...this.#k,queryNode:K.cloneWithoutReturning(this.#k.queryNode)})}clearLimit(){return new P({...this.#k,queryNode:Dk.cloneWithoutLimit(this.#k.queryNode)})}orderBy(...k){return new P({...this.#k,queryNode:K.cloneWithOrderByItems(this.#k.queryNode,B(k))})}clearOrderBy(){return new P({...this.#k,queryNode:K.cloneWithoutOrderBy(this.#k.queryNode)})}limit(k){return new P({...this.#k,queryNode:Dk.cloneWithLimit(this.#k.queryNode,Ik.create(X(k)))})}modifyEnd(k){return new P({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,k.toOperationNode())})}$call(k){return k(this)}$if(k,W){if(k)return W(this);return new P({...this.#k})}$castTo(){return new P(this.#k)}$narrowType(){return new P(this.#k)}$assertType(){return new P(this.#k)}withPlugin(k){return new P({...this.#k,executor:this.#k.executor.withPlugin(k)})}toOperationNode(){return this.#k.executor.transformQuery(this.#k.queryNode,this.#k.queryId)}compile(){return this.#k.executor.compileQuery(this.toOperationNode(),this.#k.queryId)}async execute(){let k=this.compile(),W=await this.#k.executor.executeQuery(k),{adapter:$}=this.#k.executor,M=k.query;if(M.returning&&$.supportsReturning||M.output&&$.supportsOutput)return W.rows;return[new IW(W.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[k]=await this.execute();return k}async executeTakeFirstOrThrow(k=u){let W=await this.executeTakeFirst();if(W===void 0)throw s(k)?new k(this.toOperationNode()):k(this.toOperationNode());return W}async*stream(k=100){let W=this.compile(),$=this.#k.executor.stream(W,k);for await(let M of $)yield*M.rows}async explain(k,W){return await new P({...this.#k,queryNode:K.cloneWithExplain(this.#k.queryNode,k,W)}).execute()}}P=HW;class jW{numUpdatedRows;numChangedRows;constructor(k,W){this.numUpdatedRows=k,this.numChangedRows=W}}var U;class jk{#k;constructor(k){this.#k=h(k)}where(...k){return new U({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,L(k))})}whereRef(k,W,$){return new U({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,m(k,W,$))})}clearWhere(){return new U({...this.#k,queryNode:K.cloneWithoutWhere(this.#k.queryNode)})}top(k,W){return new U({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}from(k){return new U({...this.#k,queryNode:o.cloneWithFromItems(this.#k.queryNode,n(k))})}innerJoin(...k){return this.#W("InnerJoin",k)}leftJoin(...k){return this.#W("LeftJoin",k)}rightJoin(...k){return this.#W("RightJoin",k)}fullJoin(...k){return this.#W("FullJoin",k)}#W(k,W){return new U({...this.#k,queryNode:K.cloneWithJoin(this.#k.queryNode,Jk(k,W))})}orderBy(...k){return new U({...this.#k,queryNode:K.cloneWithOrderByItems(this.#k.queryNode,B(k))})}clearOrderBy(){return new U({...this.#k,queryNode:K.cloneWithoutOrderBy(this.#k.queryNode)})}limit(k){return new U({...this.#k,queryNode:o.cloneWithLimit(this.#k.queryNode,Ik.create(X(k)))})}set(...k){return new U({...this.#k,queryNode:o.cloneWithUpdates(this.#k.queryNode,Dh(...k))})}returning(k){return new U({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,A(k))})}returningAll(k){return new U({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,R(k))})}output(k){return new U({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,A(k))})}outputAll(k){return new U({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,R(k))})}modifyEnd(k){return new U({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,k.toOperationNode())})}clearReturning(){return new U({...this.#k,queryNode:K.cloneWithoutReturning(this.#k.queryNode)})}$call(k){return k(this)}$if(k,W){if(k)return W(this);return new U({...this.#k})}$castTo(){return new U(this.#k)}$narrowType(){return new U(this.#k)}$assertType(){return new U(this.#k)}withPlugin(k){return new U({...this.#k,executor:this.#k.executor.withPlugin(k)})}toOperationNode(){return this.#k.executor.transformQuery(this.#k.queryNode,this.#k.queryId)}compile(){return this.#k.executor.compileQuery(this.toOperationNode(),this.#k.queryId)}async execute(){let k=this.compile(),W=await this.#k.executor.executeQuery(k),{adapter:$}=this.#k.executor,M=k.query;if(M.returning&&$.supportsReturning||M.output&&$.supportsOutput)return W.rows;return[new jW(W.numAffectedRows??BigInt(0),W.numChangedRows)]}async executeTakeFirst(){let[k]=await this.execute();return k}async executeTakeFirstOrThrow(k=u){let W=await this.executeTakeFirst();if(W===void 0)throw s(k)?new k(this.toOperationNode()):k(this.toOperationNode());return W}async*stream(k=100){let W=this.compile(),$=this.#k.executor.stream(W,k);for await(let M of $)yield*M.rows}async explain(k,W){return await new U({...this.#k,queryNode:K.cloneWithExplain(this.#k.queryNode,k,W)}).execute()}}U=jk;var EW=h({is(k){return k.kind==="CommonTableExpressionNameNode"},create(k,W){return h({kind:"CommonTableExpressionNameNode",table:zk.create(k),columns:W?h(W.map(S.create)):void 0})}});var Ek=h({is(k){return k.kind==="CommonTableExpressionNode"},create(k,W){return h({kind:"CommonTableExpressionNode",name:k,expression:W})},cloneWith(k,W){return h({...k,...W})}});class gk{#k;constructor(k){this.#k=h(k)}materialized(){return new gk({...this.#k,node:Ek.cloneWith(this.#k.node,{materialized:!0})})}notMaterialized(){return new gk({...this.#k,node:Ek.cloneWith(this.#k.node,{materialized:!1})})}toOperationNode(){return this.#k.node}}function OW(k,W){let $=W(Ph()).toOperationNode();if(_(k))return k(W$($)).toOperationNode();return Ek.create(qh(k),$)}function W$(k){return(W)=>{return new gk({node:Ek.create(qh(W),k)})}}function qh(k){if(k.includes("(")){let W=k.split(/[\(\)]/),$=W[0],M=W[1].split(",").map((G)=>G.trim());return EW.create($,M)}else return EW.create(k)}var tk=h({is(k){return k.kind==="WithNode"},create(k,W){return h({kind:"WithNode",expressions:h([k]),...W})},cloneWithExpression(k,W){return h({...k,expressions:h([...k.expressions,W])})}});var Uh=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"];function Vh(k){let W="";for(let $=0;$<k;++$)W+=h$();return W}function h$(){return Uh[~~(Math.random()*Uh.length)]}function T(){return new wh}class wh{#k;get queryId(){if(this.#k===void 0)this.#k=Vh(8);return this.#k}}var Fh=h({is(k){return k.kind==="MatchedNode"},create(k,W=!1){return h({kind:"MatchedNode",not:k,bySource:W})}});function bW(k,W,$){return Mk.create(mk([Fh.create(!k.isMatched,k.bySource),...W&&W.length>0?[W.length===3&&$?m(W[0],W[1],W[2]):L(W)]:[]],"and",!1))}function Ok(k){if(V(k))return v.create([k],[]);if(z(k))return k.toOperationNode();return k}class ZW{#k;#W;#h;constructor(){this.#k=new Promise((k,W)=>{this.#h=W,this.#W=k})}get promise(){return this.#k}resolve=(k)=>{if(this.#W)this.#W(k)};reject=(k)=>{if(this.#h)this.#h(k)}}async function Th(k){let W=new ZW,$=new ZW;return k.provideConnection(async(M)=>{return W.resolve(M),await $.promise}).catch((M)=>W.reject(M)),h({connection:await W.promise,release:$.resolve})}var $$=h([]);class QW{#k;constructor(k=$$){this.#k=k}get plugins(){return this.#k}transformQuery(k,W){for(let $ of this.#k){let M=$.transformQuery({node:k,queryId:W});if(M.kind===k.kind)k=M;else throw Error(["KyselyPlugin.transformQuery must return a node","of the same kind that was given to it.",`The plugin was given a ${k.kind}`,`but it returned a ${M.kind}`].join(" "))}return k}async executeQuery(k){return await this.provideConnection(async(W)=>{let $=await W.executeQuery(k);if("numUpdatedOrDeletedRows"in $)fk("kysely:warning: outdated driver/plugin detected! `QueryResult.numUpdatedOrDeletedRows` has been replaced with `QueryResult.numAffectedRows`.");return await this.#W($,k.queryId)})}async*stream(k,W){let{connection:$,release:M}=await Th(this);try{for await(let G of $.streamQuery(k,W))yield await this.#W(G,k.queryId)}finally{M()}}async#W(k,W){for(let $ of this.#k)k=await $.transformResult({result:k,queryId:W});return k}}class bk extends QW{get adapter(){throw Error("this query cannot be compiled to SQL")}compileQuery(){throw Error("this query cannot be compiled to SQL")}provideConnection(){throw Error("this query cannot be executed")}withConnectionProvider(){throw Error("this query cannot have a connection provider")}withPlugin(k){return new bk([...this.plugins,k])}withPlugins(k){return new bk([...this.plugins,...k])}withPluginAtFront(k){return new bk([k,...this.plugins])}withoutPlugins(){return new bk([])}}var qk=new bk;class NW{numChangedRows;constructor(k){this.numChangedRows=k}}class Hk{#k;constructor(k){this.#k=h(k)}modifyEnd(k){return new Hk({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,k.toOperationNode())})}top(k,W){return new Hk({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}using(...k){return new O({...this.#k,queryNode:N.cloneWithUsing(this.#k.queryNode,Jk("Using",k))})}returning(k){return new Hk({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,A(k))})}returningAll(k){return new Hk({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,R(k))})}output(k){return new Hk({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,A(k))})}outputAll(k){return new Hk({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,R(k))})}}class O{#k;constructor(k){this.#k=h(k)}modifyEnd(k){return new O({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,k.toOperationNode())})}top(k,W){return new O({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}whenMatched(){return this.#W([])}whenMatchedAnd(...k){return this.#W(k)}whenMatchedAndRef(k,W,$){return this.#W([k,W,$],!0)}#W(k,W){return new BW({...this.#k,queryNode:N.cloneWithWhen(this.#k.queryNode,bW({isMatched:!0},k,W))})}whenNotMatched(){return this.#h([])}whenNotMatchedAnd(...k){return this.#h(k)}whenNotMatchedAndRef(k,W,$){return this.#h([k,W,$],!0)}whenNotMatchedBySource(){return this.#h([],!1,!0)}whenNotMatchedBySourceAnd(...k){return this.#h(k,!1,!0)}whenNotMatchedBySourceAndRef(k,W,$){return this.#h([k,W,$],!0,!0)}returning(k){return new O({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,A(k))})}returningAll(k){return new O({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,R(k))})}output(k){return new O({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,A(k))})}outputAll(k){return new O({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,R(k))})}#h(k,W=!1,$=!1){let M={...this.#k,queryNode:N.cloneWithWhen(this.#k.queryNode,bW({isMatched:!1,bySource:$},k,W))};return new($?BW:vh)(M)}$call(k){return k(this)}$if(k,W){if(k)return W(this);return new O({...this.#k})}toOperationNode(){return this.#k.executor.transformQuery(this.#k.queryNode,this.#k.queryId)}compile(){return this.#k.executor.compileQuery(this.toOperationNode(),this.#k.queryId)}async execute(){let k=this.compile(),W=await this.#k.executor.executeQuery(k),{adapter:$}=this.#k.executor,M=k.query;if(M.returning&&$.supportsReturning||M.output&&$.supportsOutput)return W.rows;return[new NW(W.numAffectedRows)]}async executeTakeFirst(){let[k]=await this.execute();return k}async executeTakeFirstOrThrow(k=u){let W=await this.executeTakeFirst();if(W===void 0)throw s(k)?new k(this.toOperationNode()):k(this.toOperationNode());return W}}class BW{#k;constructor(k){this.#k=h(k)}thenDelete(){return new O({...this.#k,queryNode:N.cloneWithThen(this.#k.queryNode,Ok("delete"))})}thenDoNothing(){return new O({...this.#k,queryNode:N.cloneWithThen(this.#k.queryNode,Ok("do nothing"))})}thenUpdate(k){return new O({...this.#k,queryNode:N.cloneWithThen(this.#k.queryNode,Ok(k(new jk({queryId:this.#k.queryId,executor:qk,queryNode:o.createWithoutTable()}))))})}thenUpdateSet(...k){return this.thenUpdate((W)=>W.set(...k))}}class vh{#k;constructor(k){this.#k=h(k)}thenDoNothing(){return new O({...this.#k,queryNode:N.cloneWithThen(this.#k.queryNode,Ok("do nothing"))})}thenInsertValues(k){let[W,$]=KW(k);return new O({...this.#k,queryNode:N.cloneWithThen(this.#k.queryNode,Ok(w.cloneWith(w.createWithoutInto(),{columns:W,values:$})))})}}class Pk{#k;constructor(k){this.#k=h(k)}selectFrom(k){return nk({queryId:T(),executor:this.#k.executor,queryNode:Y.createFrom(n(k),this.#k.withNode)})}selectNoFrom(k){return nk({queryId:T(),executor:this.#k.executor,queryNode:Y.cloneWithSelections(Y.create(this.#k.withNode),A(k))})}insertInto(k){return new D({queryId:T(),executor:this.#k.executor,queryNode:w.create(F(k),this.#k.withNode)})}replaceInto(k){return new D({queryId:T(),executor:this.#k.executor,queryNode:w.create(F(k),this.#k.withNode,!0)})}deleteFrom(k){return new HW({queryId:T(),executor:this.#k.executor,queryNode:Dk.create(n(k),this.#k.withNode)})}updateTable(k){return new jk({queryId:T(),executor:this.#k.executor,queryNode:o.create(n(k),this.#k.withNode)})}mergeInto(k){return new Hk({queryId:T(),executor:this.#k.executor,queryNode:N.create(fW(k),this.#k.withNode)})}with(k,W){let $=OW(k,W);return new Pk({...this.#k,withNode:this.#k.withNode?tk.cloneWithExpression(this.#k.withNode,$):tk.create($)})}withRecursive(k,W){let $=OW(k,W);return new Pk({...this.#k,withNode:this.#k.withNode?tk.cloneWithExpression(this.#k.withNode,$):tk.create($,{recursive:!0})})}withPlugin(k){return new Pk({...this.#k,executor:this.#k.executor.withPlugin(k)})}withoutPlugins(){return new Pk({...this.#k,executor:this.#k.executor.withoutPlugins()})}withSchema(k){return new Pk({...this.#k,executor:this.#k.executor.withPluginAtFront(new YW(k))})}}function Ph(){return new Pk({executor:qk})}function Ah(k,W){return new Rk({joinNode:Kk.create(k,wk(W))})}function _h(){return new Ck({overNode:xk.create()})}function Jk(k,W){if(W.length===3)return K$(k,W[0],W[1],W[2]);else if(W.length===2)return M$(k,W[0],W[1]);else if(W.length===1)return G$(k,W[0]);else throw Error("not implemented")}function M$(k,W,$){return $(Ah(k,W)).toOperationNode()}function K$(k,W,$,M){return Kk.createWithOn(k,wk(W),m($,"=",M))}function G$(k,W){return Kk.create(k,wk(W))}var mh=h({is(k){return k.kind==="OffsetNode"},create(k){return h({kind:"OffsetNode",offset:k})}});var Rh=h({is(k){return k.kind==="GroupByItemNode"},create(k){return h({kind:"GroupByItemNode",groupBy:k})}});function fh(k){return k=_(k)?k(d()):k,Gk(k).map(Rh.create)}function Tk(k,W,$){if(_(W))W=W(XW());if(!j(W))W=[W];return W.map((M)=>Ch.create(k,p(M),$))}class Z{#k;constructor(k){this.#k=k}get expressionType(){return}as(k){return new zW(this,k)}or(...k){return new DW(hk.create(this.#k,L(k)))}and(...k){return new LW(x.create(this.#k,L(k)))}$castTo(){return new Z(this.#k)}$notNull(){return new Z(this.#k)}toOperationNode(){return this.#k}}class zW{#k;#W;constructor(k,W){this.#k=k,this.#W=W}get expression(){return this.#k}get alias(){return this.#W}toOperationNode(){return I.create(this.#k.toOperationNode(),z(this.#W)?this.#W.toOperationNode():J.create(this.#W))}}class DW{#k;constructor(k){this.#k=k}get expressionType(){return}as(k){return new zW(this,k)}or(...k){return new DW(hk.create(this.#k,L(k)))}$castTo(){return new DW(this.#k)}toOperationNode(){return Xk.create(this.#k)}}class LW{#k;constructor(k){this.#k=k}get expressionType(){return}as(k){return new zW(this,k)}and(...k){return new LW(x.create(this.#k,L(k)))}$castTo(){return new LW(this.#k)}toOperationNode(){return Xk.create(this.#k)}}var Sh=h({is(k){return k.kind==="FetchNode"},create(k,W){return{kind:"FetchNode",rowCount:Q.create(k),modifier:W}}});function Ih(k,W){if(!_k(k)&&!GW(k))throw Error(`Invalid fetch row count: ${k}`);if(!H$(W))throw Error(`Invalid fetch modifier: ${W}`);return Sh.create(k,W)}function H$(k){return k==="only"||k==="with ties"}var H;class xW{#k;constructor(k){this.#k=h(k)}get expressionType(){return}get isSelectQueryBuilder(){return!0}where(...k){return new H({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,L(k))})}whereRef(k,W,$){return new H({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,m(k,W,$))})}having(...k){return new H({...this.#k,queryNode:Y.cloneWithHaving(this.#k.queryNode,L(k))})}havingRef(k,W,$){return new H({...this.#k,queryNode:Y.cloneWithHaving(this.#k.queryNode,m(k,W,$))})}select(k){return new H({...this.#k,queryNode:Y.cloneWithSelections(this.#k.queryNode,A(k))})}distinctOn(k){return new H({...this.#k,queryNode:Y.cloneWithDistinctOn(this.#k.queryNode,Gk(k))})}modifyFront(k){return new H({...this.#k,queryNode:Y.cloneWithFrontModifier(this.#k.queryNode,a.createWithExpression(k.toOperationNode()))})}modifyEnd(k){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.createWithExpression(k.toOperationNode()))})}distinct(){return new H({...this.#k,queryNode:Y.cloneWithFrontModifier(this.#k.queryNode,a.create("Distinct"))})}forUpdate(k){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("ForUpdate",k?dk(k).map(F):void 0))})}forShare(k){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("ForShare",k?dk(k).map(F):void 0))})}forKeyShare(k){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("ForKeyShare",k?dk(k).map(F):void 0))})}forNoKeyUpdate(k){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("ForNoKeyUpdate",k?dk(k).map(F):void 0))})}skipLocked(){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("SkipLocked"))})}noWait(){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("NoWait"))})}selectAll(k){return new H({...this.#k,queryNode:Y.cloneWithSelections(this.#k.queryNode,R(k))})}innerJoin(...k){return this.#W("InnerJoin",k)}leftJoin(...k){return this.#W("LeftJoin",k)}rightJoin(...k){return this.#W("RightJoin",k)}fullJoin(...k){return this.#W("FullJoin",k)}crossJoin(...k){return this.#W("CrossJoin",k)}innerJoinLateral(...k){return this.#W("LateralInnerJoin",k)}leftJoinLateral(...k){return this.#W("LateralLeftJoin",k)}crossJoinLateral(...k){return this.#W("LateralCrossJoin",k)}crossApply(...k){return this.#W("CrossApply",k)}outerApply(...k){return this.#W("OuterApply",k)}#W(k,W){return new H({...this.#k,queryNode:K.cloneWithJoin(this.#k.queryNode,Jk(k,W))})}orderBy(...k){return new H({...this.#k,queryNode:K.cloneWithOrderByItems(this.#k.queryNode,B(k))})}groupBy(k){return new H({...this.#k,queryNode:Y.cloneWithGroupByItems(this.#k.queryNode,fh(k))})}limit(k){return new H({...this.#k,queryNode:Y.cloneWithLimit(this.#k.queryNode,Ik.create(X(k)))})}offset(k){return new H({...this.#k,queryNode:Y.cloneWithOffset(this.#k.queryNode,mh.create(X(k)))})}fetch(k,W="only"){return new H({...this.#k,queryNode:Y.cloneWithFetch(this.#k.queryNode,Ih(k,W))})}top(k,W){return new H({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}union(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("union",k,!1))})}unionAll(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("union",k,!0))})}intersect(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("intersect",k,!1))})}intersectAll(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("intersect",k,!0))})}except(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("except",k,!1))})}exceptAll(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("except",k,!0))})}as(k){return new jh(this,k)}clearSelect(){return new H({...this.#k,queryNode:Y.cloneWithoutSelections(this.#k.queryNode)})}clearWhere(){return new H({...this.#k,queryNode:K.cloneWithoutWhere(this.#k.queryNode)})}clearLimit(){return new H({...this.#k,queryNode:Y.cloneWithoutLimit(this.#k.queryNode)})}clearOffset(){return new H({...this.#k,queryNode:Y.cloneWithoutOffset(this.#k.queryNode)})}clearOrderBy(){return new H({...this.#k,queryNode:K.cloneWithoutOrderBy(this.#k.queryNode)})}clearGroupBy(){return new H({...this.#k,queryNode:Y.cloneWithoutGroupBy(this.#k.queryNode)})}$call(k){return k(this)}$if(k,W){if(k)return W(this);return new H({...this.#k})}$castTo(){return new H(this.#k)}$narrowType(){return new H(this.#k)}$assertType(){return new H(this.#k)}$asTuple(){return new Z(this.toOperationNode())}$asScalar(){return new Z(this.toOperationNode())}withPlugin(k){return new H({...this.#k,executor:this.#k.executor.withPlugin(k)})}toOperationNode(){return this.#k.executor.transformQuery(this.#k.queryNode,this.#k.queryId)}compile(){return this.#k.executor.compileQuery(this.toOperationNode(),this.#k.queryId)}async execute(){let k=this.compile();return(await this.#k.executor.executeQuery(k)).rows}async executeTakeFirst(){let[k]=await this.execute();return k}async executeTakeFirstOrThrow(k=u){let W=await this.executeTakeFirst();if(W===void 0)throw s(k)?new k(this.toOperationNode()):k(this.toOperationNode());return W}async*stream(k=100){let W=this.compile(),$=this.#k.executor.stream(W,k);for await(let M of $)yield*M.rows}async explain(k,W){return await new H({...this.#k,queryNode:K.cloneWithExplain(this.#k.queryNode,k,W)}).execute()}}H=xW;function nk(k){return new xW(k)}class jh{#k;#W;constructor(k,W){this.#k=k,this.#W=W}get expression(){return this.#k}get alias(){return this.#W}get isAliasedSelectQueryBuilder(){return!0}toOperationNode(){return I.create(this.#k.toOperationNode(),J.create(this.#W))}}var e=h({is(k){return k.kind==="AggregateFunctionNode"},create(k,W=[]){return h({kind:"AggregateFunctionNode",func:k,aggregated:W})},cloneWithDistinct(k){return h({...k,distinct:!0})},cloneWithOrderBy(k,W,$=!1){let M=$?"withinGroup":"orderBy";return h({...k,[M]:k[M]?$k.cloneWithItems(k[M],W):$k.create(W)})},cloneWithFilter(k,W){return h({...k,filter:k.filter?C.cloneWithOperation(k.filter,"And",W):C.create(W)})},cloneWithOrFilter(k,W){return h({...k,filter:k.filter?C.cloneWithOperation(k.filter,"Or",W):C.create(W)})},cloneWithOver(k,W){return h({...k,over:W})}});var cW=h({is(k){return k.kind==="FunctionNode"},create(k,W){return h({kind:"FunctionNode",func:k,arguments:W})}});class b{#k;constructor(k){this.#k=h(k)}get expressionType(){return}as(k){return new Eh(this,k)}distinct(){return new b({...this.#k,aggregateFunctionNode:e.cloneWithDistinct(this.#k.aggregateFunctionNode)})}orderBy(...k){return new b({...this.#k,aggregateFunctionNode:K.cloneWithOrderByItems(this.#k.aggregateFunctionNode,B(k))})}clearOrderBy(){return new b({...this.#k,aggregateFunctionNode:K.cloneWithoutOrderBy(this.#k.aggregateFunctionNode)})}withinGroupOrderBy(...k){return new b({...this.#k,aggregateFunctionNode:e.cloneWithOrderBy(this.#k.aggregateFunctionNode,B(k),!0)})}filterWhere(...k){return new b({...this.#k,aggregateFunctionNode:e.cloneWithFilter(this.#k.aggregateFunctionNode,L(k))})}filterWhereRef(k,W,$){return new b({...this.#k,aggregateFunctionNode:e.cloneWithFilter(this.#k.aggregateFunctionNode,m(k,W,$))})}over(k){let W=_h();return new b({...this.#k,aggregateFunctionNode:e.cloneWithOver(this.#k.aggregateFunctionNode,(k?k(W):W).toOperationNode())})}$call(k){return k(this)}$castTo(){return new b(this.#k)}$notNull(){return new b(this.#k)}toOperationNode(){return this.#k.aggregateFunctionNode}}class Eh{#k;#W;constructor(k,W){this.#k=k,this.#W=W}get expression(){return this.#k}get alias(){return this.#W}toOperationNode(){return I.create(this.#k.toOperationNode(),J.create(this.#W))}}function Oh(){let k=($,M)=>{return new Z(cW.create($,Gk(M??[])))},W=($,M)=>{return new b({aggregateFunctionNode:e.create($,M?Gk(M):void 0)})};return Object.assign(k,{agg:W,avg($){return W("avg",[$])},coalesce(...$){return k("coalesce",$)},count($){return W("count",[$])},countAll($){return new b({aggregateFunctionNode:e.create("count",R($))})},max($){return W("max",[$])},min($){return W("min",[$])},sum($){return W("sum",[$])},any($){return k("any",[$])},jsonAgg($){return new b({aggregateFunctionNode:e.create("json_agg",[V($)?F($):$.toOperationNode()])})},toJson($){return new Z(cW.create("to_json",[V($)?F($):$.toOperationNode()]))}})}var bh=h({is(k){return k.kind==="UnaryOperationNode"},create(k,W){return h({kind:"UnaryOperationNode",operator:k,operand:W})}});function Qh(k,W){return bh.create(y.create(k),f(W))}var l=h({is(k){return k.kind==="CaseNode"},create(k){return h({kind:"CaseNode",value:k})},cloneWithWhen(k,W){return h({...k,when:h(k.when?[...k.when,W]:[W])})},cloneWithThen(k,W){return h({...k,when:k.when?h([...k.when.slice(0,-1),Mk.cloneWithResult(k.when[k.when.length-1],W)]):void 0})},cloneWith(k,W){return h({...k,...W})}});class yW{#k;constructor(k){this.#k=h(k)}when(...k){return new gW({...this.#k,node:l.cloneWithWhen(this.#k.node,Mk.create(L(k)))})}}class gW{#k;constructor(k){this.#k=h(k)}then(k){return new Nh({...this.#k,node:l.cloneWithThen(this.#k.node,WW(k)?Bk(k):X(k))})}}class Nh{#k;constructor(k){this.#k=h(k)}when(...k){return new gW({...this.#k,node:l.cloneWithWhen(this.#k.node,Mk.create(L(k)))})}else(k){return new Bh({...this.#k,node:l.cloneWith(this.#k.node,{else:WW(k)?Bk(k):X(k)})})}end(){return new Z(l.cloneWith(this.#k.node,{isStatement:!1}))}endCase(){return new Z(l.cloneWith(this.#k.node,{isStatement:!0}))}}class Bh{#k;constructor(k){this.#k=h(k)}end(){return new Z(l.cloneWith(this.#k.node,{isStatement:!1}))}endCase(){return new Z(l.cloneWith(this.#k.node,{isStatement:!0}))}}var JW=h({is(k){return k.kind==="JSONOperatorChainNode"},create(k){return h({kind:"JSONOperatorChainNode",operator:k,values:h([])})},cloneWithValue(k,W){return h({...k,values:h([...k.values,W])})}});var tW=h({is(k){return k.kind==="JSONPathLegNode"},create(k,W){return h({kind:"JSONPathLegNode",type:k,value:W})}});var Uk=h({is(k){return k.kind==="JSONPathNode"},create(k){return h({kind:"JSONPathNode",inOperator:k,pathLegs:h([])})},cloneWithLeg(k,W){return h({...k,pathLegs:h([...k.pathLegs,W])})}});var Qk=h({is(k){return k.kind==="JSONReferenceNode"},create(k,W){return h({kind:"JSONReferenceNode",reference:k,traversal:W})},cloneWithTraversal(k,W){return h({...k,traversal:W})}});var Z$=/^#-\d+$/;class ik{#k;constructor(k){this.#k=k}at(k){if(typeof k!=="number"&&typeof k!=="string"||typeof k==="number"&&!Number.isInteger(k)||typeof k==="string"&&k!=="last"&&!Z$.test(k))throw Error(`Unexpected index value in .at(...): ${k}`);return this.#W("ArrayLocation",k)}key(k){return this.#W("Member",k)}#W(k,W){if(Qk.is(this.#k))return new uk(Qk.cloneWithTraversal(this.#k,Uk.is(this.#k.traversal)?Uk.cloneWithLeg(this.#k.traversal,tW.create(k,W)):JW.cloneWithValue(this.#k.traversal,Q.createImmediate(W))));return new uk(Uk.cloneWithLeg(this.#k,tW.create(k,W)))}}class uk extends ik{#k;constructor(k){super(k);this.#k=k}get expressionType(){return}as(k){return new xh(this,k)}$castTo(){return new uk(this.#k)}$notNull(){return new uk(this.#k)}toOperationNode(){return this.#k}}class xh{#k;#W;constructor(k,W){this.#k=k,this.#W=W}get expression(){return this.#k}get alias(){return this.#W}toOperationNode(){return I.create(this.#k.toOperationNode(),z(this.#W)?this.#W.toOperationNode():J.create(this.#W))}}var nW=h({is(k){return k.kind==="TupleNode"},create(k){return h({kind:"TupleNode",values:h(k)})}});var Y$=["varchar","char","text","integer","int2","int4","int8","smallint","bigint","boolean","real","double precision","float4","float8","decimal","numeric","binary","bytea","date","datetime","time","timetz","timestamp","timestamptz","serial","bigserial","uuid","json","jsonb","blob","varbinary","int4range","int4multirange","int8range","int8multirange","numrange","nummultirange","tsrange","tsmultirange","tstzrange","tstzmultirange","daterange","datemultirange"],X$=[/^varchar\(\d+\)$/,/^char\(\d+\)$/,/^decimal\(\d+, \d+\)$/,/^numeric\(\d+, \d+\)$/,/^binary\(\d+\)$/,/^datetime\(\d+\)$/,/^time\(\d+\)$/,/^timetz\(\d+\)$/,/^timestamp\(\d+\)$/,/^timestamptz\(\d+\)$/,/^varbinary\(\d+\)$/],ch=h({is(k){return k.kind==="DataTypeNode"},create(k){return h({kind:"DataTypeNode",dataType:k})}});function yh(k){if(Y$.includes(k))return!0;if(X$.some((W)=>W.test(k)))return!0;return!1}function gh(k){if(z(k))return k.toOperationNode();if(yh(k))return ch.create(k);throw Error(`invalid column data type ${JSON.stringify(k)}`)}var th=h({is(k){return k.kind==="CastNode"},create(k,W){return h({kind:"CastNode",expression:k,dataType:W})}});function XW(k=qk){function W(G,q,vk){return new Z(hW(G,q,vk))}function $(G,q){return new Z(Qh(G,q))}let M=Object.assign(W,{fn:void 0,eb:void 0,selectFrom(G){return nk({queryId:T(),executor:k,queryNode:Y.createFrom(n(G))})},case(G){return new yW({node:l.create(c(G)?void 0:f(G))})},ref(G,q){if(c(q))return new Z(t(G));return new ik(nh(G,q))},jsonPath(){return new ik(Uk.create())},table(G){return new Z(F(G))},val(G){return new Z(X(G))},refTuple(...G){return new Z(nW.create(G.map(f)))},tuple(...G){return new Z(nW.create(G.map(X)))},lit(G){return new Z(Bk(G))},unary:$,not(G){return $("not",G)},exists(G){return $("exists",G)},neg(G){return $("-",G)},between(G,q,vk){return new Z(Yk.create(f(G),y.create("between"),x.create(X(q),X(vk))))},betweenSymmetric(G,q,vk){return new Z(Yk.create(f(G),y.create("between symmetric"),x.create(X(q),X(vk))))},and(G){if(j(G))return new Z(mk(G,"and"));return new Z(UW(G,"and"))},or(G){if(j(G))return new Z(mk(G,"or"));return new Z(UW(G,"or"))},parens(...G){let q=L(G);if(Xk.is(q))return new Z(q);else return new Z(Xk.create(q))},cast(G,q){return new Z(th.create(f(G),gh(q)))},withSchema(G){return XW(k.withPluginAtFront(new YW(G)))}});return M.fn=Oh(),M.eb=M,M}function d(k){return XW()}function p(k){if(z(k))return k.toOperationNode();else if(_(k))return k(d()).toOperationNode();throw Error(`invalid expression: ${JSON.stringify(k)}`)}function MW(k){if(z(k))return k.toOperationNode();else if(_(k))return k(d()).toOperationNode();throw Error(`invalid aliased expression: ${JSON.stringify(k)}`)}function Wk(k){return ok(k)||iW(k)||_(k)}function _W(k){if(V(k))return t(k);return k.toOperationNode()}function Gk(k){if(j(k))return k.map((W)=>f(W));else return[f(k)]}function f(k){if(Wk(k))return p(k);return _W(k)}function nh(k,W){let $=t(k);if(dW(W))return Qk.create($,JW.create(y.create(W)));let M=W.slice(0,-1);if(dW(M))return Qk.create($,Uk.create(y.create(M)));throw Error(`Invalid JSON operator: ${W}`)}function t(k){if(!k.includes("."))return Ak.create(S.create(k));let $=k.split(".").map(uW);if($.length===3)return L$($);if($.length===2)return z$($);throw Error(`invalid column reference ${k}`)}function Zh(k){if(k.includes(" as ")){let[$,M]=k.split(" as ").map(uW);return I.create(t($),J.create(M))}else return t(k)}function D$(k){return S.create(k)}function R3(k){if(k.includes(" ")){let[$,M]=k.split(" ").map(uW);if(!RW(M))throw Error(`invalid order direction "${M}" next to "${$}"`);return B([$,M])[0]}else return D$(k)}function L$(k){let[W,$,M]=k;return Ak.create(S.create(M),zk.createWithSchema(W,$))}function z$(k){let[W,$]=k;return Ak.create(S.create($),zk.create(W))}function uW(k){return k.trim()}class lk{#k;constructor(k){this.#k=h(k)}get expressionType(){return}get isRawBuilder(){return!0}as(k){return new dh(this,k)}$castTo(){return new lk({...this.#k})}$notNull(){return new lk(this.#k)}withPlugin(k){return new lk({...this.#k,plugins:this.#k.plugins!==void 0?h([...this.#k.plugins,k]):h([k])})}toOperationNode(){return this.#h(this.#W())}compile(k){return this.#$(this.#W(k))}async execute(k){let W=this.#W(k);return W.executeQuery(this.#$(W))}#W(k){let W=k!==void 0?k.getExecutor():qk;return this.#k.plugins!==void 0?W.withPlugins(this.#k.plugins):W}#h(k){return k.transformQuery(this.#k.rawNode,this.#k.queryId)}#$(k){return k.compileQuery(this.#h(k),this.#k.queryId)}}function Zk(k){return new lk(k)}class dh{#k;#W;constructor(k,W){this.#k=k,this.#W=W}get expression(){return this.#k}get alias(){return this.#W}get rawBuilder(){return this.#k}toOperationNode(){return I.create(this.#k.toOperationNode(),z(this.#W)?this.#W.toOperationNode():J.create(this.#W))}}var J$=Object.assign((k,...W)=>{return Zk({queryId:T(),rawNode:v.create(k,W?.map(uh)??[])})},{ref(k){return Zk({queryId:T(),rawNode:v.createWithChild(t(k))})},val(k){return Zk({queryId:T(),rawNode:v.createWithChild(X(k))})},value(k){return this.val(k)},table(k){return Zk({queryId:T(),rawNode:v.createWithChild(F(k))})},id(...k){let W=Array(k.length+1).fill(".");return W[0]="",W[W.length-1]="",Zk({queryId:T(),rawNode:v.create(W,k.map(J.create))})},lit(k){return Zk({queryId:T(),rawNode:v.createWithChild(Q.createImmediate(k))})},literal(k){return this.lit(k)},raw(k){return Zk({queryId:T(),rawNode:v.createWithSql(k)})},join(k,W=J$`, `){let $=Array(Math.max(2*k.length-1,0)),M=W.toOperationNode();for(let G=0;G<k.length;++G)if($[2*G]=uh(k[G]),G!==k.length-1)$[2*G+1]=M;return Zk({queryId:T(),rawNode:v.createWithChildren($)})}});function uh(k){if(z(k))return k.toOperationNode();return X(k)}var l3=h({raw(k,W=[]){return h({sql:k,query:v.createWithSql(k),parameters:h(W),queryId:T()})}});
3
+ export{z as Tc,S as Uc,pk as Vc,ah as Wc,t as Xc,D$ as Yc,R3 as Zc,rk as _c,Q as $c,L as ad,K as bd,Y as cd,Vh as dd,T as ed,ZW as fd,Th as gd,QW as hd,Pk as id,Oh as jd,l as kd,yW as ld,gh as md,p as nd,oh as od,F as pd,J$ as qd,l3 as rd};
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- import{Lc as P,Mc as J}from"./chunk-xh2ntgmk.js";import{wd as V,xd as W,yd as X}from"./chunk-ysq64j13.js";import"./chunk-kbzm1pwx.js";var Y=class{get supportsCreateIfNotExists(){return!0}get supportsTransactionalDdl(){return!1}get supportsReturning(){return!0}async acquireMigrationLock(){}async releaseMigrationLock(){}get supportsOutput(){return!0}},Z=class{#h;#j=new k;#z;#H;constructor(h){this.#h={...h}}async init(){if(this.#z=this.#h.database,this.#H=new $(this.#z),this.#h.onCreateConnection)await this.#h.onCreateConnection(this.#H)}async acquireConnection(){return await this.#j.lock(),this.#H}async beginTransaction(h){await h.executeQuery(J.raw("begin"))}async commitTransaction(h){await h.executeQuery(J.raw("commit"))}async rollbackTransaction(h){await h.executeQuery(J.raw("rollback"))}async releaseConnection(){this.#j.unlock()}async destroy(){this.#z?.close()}},$=class{#h;constructor(h){this.#h=h}executeQuery(h){let{sql:z,parameters:H}=h,j=this.#h.prepare(z).all(...H);return Promise.resolve({rows:j})}async*streamQuery(){throw Error("Streaming query is not supported by SQLite driver.")}},k=class{#h;#j;async lock(){while(this.#h!==void 0)await this.#h;this.#h=new Promise((h)=>{this.#j=h})}unlock(){let h=this.#j;this.#h=void 0,this.#j=void 0,h?.()}},w=class{#h;constructor(h){this.#h=h}async getSchemas(){return[]}async getTables(h={withInternalKyselyTables:!1}){let z=this.#h.selectFrom("sqlite_schema").where("type","=","table").where("name","not like","sqlite_%").select("name").$castTo();if(!h.withInternalKyselyTables)z=z.where("name","!=",W).where("name","!=",X);let H=await z.execute();return Promise.all(H.map(({name:j})=>this.#j(j)))}async getMetadata(h){return{tables:await this.getTables(h)}}async#j(h){let z=this.#h,H=(await z.selectFrom("sqlite_master").where("name","=",h).select("sql").$castTo().execute())[0]?.sql?.split(/[\(\),]/)?.find((j)=>j.toLowerCase().includes("autoincrement"))?.split(/\s+/)?.[0]?.replace(/["`]/g,"");return{name:h,columns:(await z.selectFrom(P`pragma_table_info(${h})`.as("table_info")).select(["name","type","notnull","dflt_value"]).execute()).map((j)=>({name:j.name,dataType:j.type,isNullable:!j.notnull,isAutoIncrementing:j.name===H,hasDefaultValue:j.dflt_value!=null})),isView:!0}}},K=class extends V{getCurrentParameterPlaceholder(){return"?"}getLeftIdentifierWrapper(){return'"'}getRightIdentifierWrapper(){return'"'}getAutoIncrement(){return"autoincrement"}},F=class{#h;constructor(h){this.#h={...h}}createDriver(){return new Z(this.#h)}createQueryCompiler(){return new K}createAdapter(){return new Y}createIntrospector(h){return new w(h)}};export{F as NodeSqliteDialect};
2
+ import{qd as P,rd as J}from"./chunk-14fh4s1a.js";import{ee as V,fe as W,ge as X}from"./chunk-n4meg9wb.js";import"./chunk-976v5s8y.js";var Y=class{get supportsCreateIfNotExists(){return!0}get supportsTransactionalDdl(){return!1}get supportsReturning(){return!0}async acquireMigrationLock(){}async releaseMigrationLock(){}get supportsOutput(){return!0}},Z=class{#h;#j=new k;#z;#H;constructor(h){this.#h={...h}}async init(){if(this.#z=this.#h.database,this.#H=new $(this.#z),this.#h.onCreateConnection)await this.#h.onCreateConnection(this.#H)}async acquireConnection(){return await this.#j.lock(),this.#H}async beginTransaction(h){await h.executeQuery(J.raw("begin"))}async commitTransaction(h){await h.executeQuery(J.raw("commit"))}async rollbackTransaction(h){await h.executeQuery(J.raw("rollback"))}async releaseConnection(){this.#j.unlock()}async destroy(){this.#z?.close()}},$=class{#h;constructor(h){this.#h=h}executeQuery(h){let{sql:z,parameters:H}=h,j=this.#h.prepare(z).all(...H);return Promise.resolve({rows:j})}async*streamQuery(){throw Error("Streaming query is not supported by SQLite driver.")}},k=class{#h;#j;async lock(){while(this.#h!==void 0)await this.#h;this.#h=new Promise((h)=>{this.#j=h})}unlock(){let h=this.#j;this.#h=void 0,this.#j=void 0,h?.()}},w=class{#h;constructor(h){this.#h=h}async getSchemas(){return[]}async getTables(h={withInternalKyselyTables:!1}){let z=this.#h.selectFrom("sqlite_schema").where("type","=","table").where("name","not like","sqlite_%").select("name").$castTo();if(!h.withInternalKyselyTables)z=z.where("name","!=",W).where("name","!=",X);let H=await z.execute();return Promise.all(H.map(({name:j})=>this.#j(j)))}async getMetadata(h){return{tables:await this.getTables(h)}}async#j(h){let z=this.#h,H=(await z.selectFrom("sqlite_master").where("name","=",h).select("sql").$castTo().execute())[0]?.sql?.split(/[\(\),]/)?.find((j)=>j.toLowerCase().includes("autoincrement"))?.split(/\s+/)?.[0]?.replace(/["`]/g,"");return{name:h,columns:(await z.selectFrom(P`pragma_table_info(${h})`.as("table_info")).select(["name","type","notnull","dflt_value"]).execute()).map((j)=>({name:j.name,dataType:j.type,isNullable:!j.notnull,isAutoIncrementing:j.name===H,hasDefaultValue:j.dflt_value!=null})),isView:!0}}},K=class extends V{getCurrentParameterPlaceholder(){return"?"}getLeftIdentifierWrapper(){return'"'}getRightIdentifierWrapper(){return'"'}getAutoIncrement(){return"autoincrement"}},F=class{#h;constructor(h){this.#h={...h}}createDriver(){return new Z(this.#h)}createQueryCompiler(){return new K}createAdapter(){return new Y}createIntrospector(h){return new w(h)}};export{F as NodeSqliteDialect};
@@ -1,2 +1,2 @@
1
- import{Uf as A}from"./chunk-5tmf3c0g.js";import{Eg as z,bg as v,rg as w}from"./chunk-nwtb6dt1.js";var B=(b)=>({queryKey:["projects",b],queryFn:async()=>{let h=await z.api.projects[":projectId"].$get({param:{projectId:b}});if(!h.ok)throw Error("failed to fetch project");return await h.json()}}),H=w("/projects/$projectId/")({loader:({context:{queryClient:b},params:{projectId:h}})=>b.ensureQueryData(B(h)),pendingComponent:()=>v(A,{})});
2
- export{B as we,H as xe};
1
+ import{zf as A}from"./chunk-zn9jbc6t.js";import{Tg as v,hh as w,uh as z}from"./chunk-wf4d1anc.js";var B=(b)=>({queryKey:["projects",b],queryFn:async()=>{let h=await z.api.projects[":projectId"].$get({param:{projectId:b}});if(!h.ok)throw Error("failed to fetch project");return await h.json()}}),H=w("/projects/$projectId/")({loader:({context:{queryClient:b},params:{projectId:h}})=>b.ensureQueryData(B(h)),pendingComponent:()=>v(A,{})});
2
+ export{B as wf,H as xf};
@@ -0,0 +1 @@
1
+ import{g as B}from"./chunk-50ebjdkv.js";import"./chunk-5j7axztv.js";import"./chunk-9bpjfkjf.js";import"./chunk-75jka5v9.js";import"./chunk-4fnak2zn.js";import"./chunk-6h4ay2p8.js";import"./chunk-mk1jewvw.js";import"./chunk-v98yavtp.js";import"./chunk-azfgjqjx.js";import"./chunk-m3dwydr3.js";import"./chunk-mjncyjwf.js";import"./chunk-sy8rqacm.js";import"./chunk-25d1g086.js";import"./chunk-t1mxqskx.js";import"./chunk-qjjr3fff.js";import"./chunk-46c5xkmn.js";import"./chunk-99db4j0k.js";import"./chunk-7ktvhtp1.js";import"./chunk-mg6fce5x.js";import"./chunk-2xnys7v4.js";import"./chunk-cpr05qng.js";import"./chunk-dwf5e5g3.js";import{Tg as q,ih as w}from"./chunk-wf4d1anc.js";import"./chunk-976v5s8y.js";function O(){let{shareId:C,fileId:D}=k.useParams(),{start:E,version:G,compare:H,cmpLeft:J,cmpRight:K,cmpActive:N}=k.useSearch();return q(B,{shareId:C,initialFileId:D,startTime:E,versionId:G,compare:H,compareLeftId:J,compareRightId:K,compareActiveSide:N})}var k=w("/share/$shareId/files/$fileId")({component:O});export{k as Route};
@@ -1,2 +1,2 @@
1
- import{Ve as Rf,We as Lf,Xe as Vf,Ye as Cf,bf as Hf,cf as Jf,df as Kf,ef as Qf,ff as Wf,if as _f}from"./chunk-cp18trqb.js";import{mf as Zf,nf as Gf}from"./chunk-8wv3kdz9.js";import{Mf as zf}from"./chunk-pf8edn5x.js";import{Xf as $f}from"./chunk-mnv6pj0k.js";import{Dh as o,Eg as i,Gh as s,Kg as x,Kh as ff,Pi as D,Vi as Sf,Wi as a,Xi as Nf,Yi as Uf,Zi as W,ag as O,aj as qf,bg as f,bh as e,bj as g,cg as V,cj as p,dj as l,ej as c,gh as j,hh as r,hj as X,jj as Xf,ng as u,pg as d,wh as n}from"./chunk-nwtb6dt1.js";function Yf({teamId:K,projectId:L,projectName:_,ancestorFolders:B,currentAsset:U,isRootFolder:Y,displayStyle:E,onDisplayStyleChange:h,isLeftSidebarCollapsed:P,onLeftSidebarToggle:T,isRightSidebarCollapsed:$,onRightSidebarToggle:v,isChatbotOpen:Z=!1,onChatbotToggle:N,isPublic:Q=!1,onFolderClick:w,fileId:q,shareId:G,downloadInfo:z,versions:S,compareMode:J=!1,canCompareVersions:b=!1,onCompareVersions:A}){let k=u(),{canEdit:y}=Xf(L),I=!1,m=(R)=>{if(!q)return;if(Q&&G){k({to:"/share/$shareId/files/$fileId",params:{shareId:G,fileId:q},search:(C)=>({...C,version:R})});return}if(!L)return;k({to:"/projects/$projectId/files/$fileId",params:{projectId:L,fileId:q},search:(C)=>({...C,version:R})})},M=async(R)=>{if(!q)return;try{let C=G?await i.api.shares[":shareId"].files[":fileId"]["download-url"].$post({param:{shareId:G,fileId:q},json:{key:R}}):await i.api.files["download-url"].$post({json:{key:R,assetId:q}});if(!C.ok)return;let{url:H}=await C.json(),F=document.createElement("a");F.href=H,F.download="",document.body.appendChild(F),F.click(),document.body.removeChild(F)}catch{}},Bf=U.proxyType!=="audio"&&z?.videoTranscodes&&z.videoTranscodes.filter((R)=>!R.isRaw).length>0,Ef=Q?[{name:_,id:"root"},...B.slice().reverse().map((R)=>({name:R.name||"",id:R.id}))]:[{name:X.all_projects(),path:`/teams/${K}`,isMuted:!0},{name:_,path:`/projects/${L}`},...B.slice().reverse().map((R)=>({name:R.name||"",path:`/projects/${L}/folders/${R.id}`}))];return V("div",{className:"flex h-14 flex-wrap items-center justify-between gap-2 border-b border-border bg-card px-4 py-2",children:[V("div",{className:"flex min-w-0 flex-shrink items-center gap-1",children:[Ef.map((R,C)=>V("div",{className:"flex items-center gap-1",children:[C>0&&f("span",{className:"text-muted-foreground",children:"/"}),R.path?f(d,{to:R.path,className:D("truncate rounded px-2 py-1 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground",R.isMuted?"text-muted-foreground":"text-foreground"),children:R.name}):f("button",{onClick:()=>R.id&&w?.(R.id),className:"truncate rounded px-2 py-1 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground text-foreground",children:R.name})]},C)),!Y&&!J&&V("div",{className:"flex items-center gap-1",children:[f("span",{className:"text-muted-foreground",children:"/"}),U.type==="folder"?f("span",{className:"truncate rounded px-2 py-1 text-sm font-medium text-foreground",children:U.name}):V(Sf,{children:[V(Nf,{className:"flex items-center gap-1 truncate rounded px-2 py-1 text-sm font-medium text-foreground transition-colors hover:bg-accent hover:text-accent-foreground",children:[f("span",{children:U.name}),U.version!==void 0&&V(zf,{variant:"outline",className:"px-1 py-0 text-xs",children:["v",U.version]}),f(r,{className:"h-4 w-4"})]}),V(Uf,{className:"w-56",children:[Bf?V(p,{children:[f(l,{className:"flex items-center gap-2",children:f("span",{children:X.download()})}),f(a,{children:V(c,{className:"w-48",children:[f(qf,{children:X.download()}),z?.videoTranscodes?.filter((R)=>!R.isRaw).map((R)=>{let C=Math.max(R.width,R.height),H=`${R.height}p`;if(C>=3840)H="2160p";else if(C>=1920)H="1080p";else if(C>=1280)H="720p";else if(C>=960)H="540p";else if(C>=640)H="360p";else if(C>=320)H="180p";return V(W,{onClick:()=>M(R.key),className:"flex items-center justify-between",children:[f("span",{children:H}),f("span",{className:"text-xs text-muted-foreground",children:"MP4"})]},H)}),z?.originalKey&&V(O,{children:[f(g,{}),V(W,{onClick:()=>M(z.originalKey),className:"flex items-center justify-between",children:[f("span",{children:"Original"}),f("span",{className:"text-xs text-muted-foreground",children:U.name?.split(".").pop()?.toUpperCase()||"RAW"})]})]})]})})]}):f(W,{onClick:()=>z?.originalKey&&M(z.originalKey),disabled:!z?.originalKey,children:X.download()}),y&&f(W,{onClick:()=>console.log("Rename"),children:"Rename"}),y&&f(W,{onClick:()=>console.log("Delete"),children:"Delete"}),b&&A&&V(O,{children:[f(g,{}),V(W,{onClick:()=>A(),children:[f(x,{className:"h-4 w-4"}),f("span",{children:X.compare_versions()})]})]}),S&&S.length>0&&V(O,{children:[f(g,{}),V(p,{children:[V(l,{className:"flex items-center gap-2",children:[f(o,{className:"h-4 w-4"}),f("span",{children:"Versions"})]}),f(a,{children:V(c,{className:"w-80 p-1",children:[f("div",{className:"flex flex-col gap-1 max-h-96 overflow-y-auto",children:S.map((R)=>{let C=U.version===R.version;return V(W,{onClick:()=>m(R.id),className:"flex items-center gap-3 py-2 px-3 rounded-md cursor-pointer focus:bg-accent focus:text-accent-foreground",children:[V("div",{className:"flex-shrink-0 flex items-center justify-center bg-muted dark:bg-muted-foreground/20 text-muted-foreground dark:text-muted-foreground rounded-full px-2 py-0.5 text-xs font-semibold select-none min-w-[2rem]",children:["v",R.version]}),f("div",{className:"h-10 w-16 flex-shrink-0 overflow-hidden rounded-md border border-border bg-muted flex items-center justify-center",children:R.previewUrl?f("img",{src:R.previewUrl,alt:R.name||void 0,className:"h-full w-full object-cover"}):f(n,{className:"h-4 w-4 text-muted-foreground"})}),V("div",{className:"flex flex-col flex-1 min-w-0 text-left",children:[f("span",{className:"truncate text-sm font-semibold text-foreground",children:R.name}),f("span",{className:"truncate text-xs text-muted-foreground",children:R.creator?.name||"Unknown"})]}),C&&f(j,{className:"h-4 w-4 text-primary ml-auto flex-shrink-0"})]},R.id)})}),f(g,{}),f("div",{className:"p-1",children:f("button",{className:"w-full text-center text-xs font-medium py-2 px-3 rounded-md bg-muted/80 hover:bg-muted text-foreground transition-colors",onClick:()=>console.log("Manage versions"),children:"Manage versions..."})})]})})]})]})]})]})]})]}),V("div",{className:"flex items-center gap-2",children:[V("div",{className:"flex flex-shrink-0 items-center gap-1 rounded-md border border-border bg-background p-1",children:[!q&&!Q&&T&&f("button",{onClick:T,className:"rounded p-1.5 text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground",title:P?"Show Left Sidebar":"Hide Left Sidebar",children:P?f(Hf,{className:"h-4 w-4"}):f(Kf,{className:"h-4 w-4 fill-primary stroke-0"})}),!q&&!Q&&E&&h&&V(O,{children:[f("button",{onClick:()=>h("card"),className:`rounded p-1.5 transition-colors ${E==="card"?"bg-accent text-accent-foreground":"text-muted-foreground hover:bg-accent/50 hover:text-foreground"}`,title:"Card View",children:f(s,{className:"h-4 w-4"})}),f("button",{onClick:()=>h("list"),className:`rounded p-1.5 transition-colors ${E==="list"?"bg-accent text-accent-foreground":"text-muted-foreground hover:bg-accent/50 hover:text-foreground"}`,title:"List View",children:f(ff,{className:"h-4 w-4"})})]}),f("button",{onClick:v,className:`rounded p-1.5 transition-colors ${!$&&!Z?"bg-accent text-accent-foreground":"text-muted-foreground hover:bg-accent/50 hover:text-foreground"}`,title:$?"Show Right Sidebar":"Hide Right Sidebar",children:!$&&!Z?f(Qf,{className:"h-4 w-4 fill-primary stroke-0"}):f(Jf,{className:"h-4 w-4"})})]}),!Q&&N&&f(Rf,{children:V(Lf,{children:[f(Vf,{asChild:!0,children:f("span",{children:f("button",{disabled:!1,onClick:N,className:D("h-9 w-9 flex items-center justify-center rounded-full border border-border bg-background transition-colors",Z?"bg-accent text-accent-foreground":"text-muted-foreground hover:bg-accent hover:text-foreground",!1),children:Z?f(Wf,{className:"h-6 w-6 text-primary transition-colors"}):f(e,{className:"h-6 w-6 text-muted-foreground transition-colors"})})})}),f(Cf,{children:f("p",{children:Z?X.hide_chatbot():X.show_chatbot()})})]})})]})]})}function cf(){let{projectState:K}=Zf(),L=$f(),{isChatbotOpen:_,setIsChatbotOpen:B}=Gf();if(!K)return f(hf,{});let{teamId:U,projectId:Y,projectName:E,ancestorFolders:h,currentAsset:P,isRootFolder:T,fileId:$,downloadInfo:v,versions:Z,isPublic:N,shareId:Q,onFolderClick:w,compareMode:q,canCompareVersions:G,onCompareVersions:z}=K,S=!!$,J=!!Q&&!S,b=S?L.fileViewLeftSidebarCollapsed:J?L.shareConfigLeftSidebarCollapsed:L.fileListLeftSidebarCollapsed,A=N?void 0:()=>S?L.setFileViewLeftSidebarCollapsed(!L.fileViewLeftSidebarCollapsed):J?L.setShareConfigLeftSidebarCollapsed(!L.shareConfigLeftSidebarCollapsed):L.setFileListLeftSidebarCollapsed(!L.fileListLeftSidebarCollapsed),k=N&&K.isRightSidebarCollapsed!==void 0?K.isRightSidebarCollapsed:S?L.fileViewRightSidebarCollapsed:J?L.shareConfigRightSidebarCollapsed:L.fileListRightSidebarCollapsed,y=N&&K.onRightSidebarToggle?K.onRightSidebarToggle:()=>{if(!N&&_)if(B(!1),S)L.setFileViewRightSidebarCollapsed(!1);else if(J)L.setShareConfigRightSidebarCollapsed(!1);else L.setFileListRightSidebarCollapsed(!1);else if(S)L.setFileViewRightSidebarCollapsed(!L.fileViewRightSidebarCollapsed);else if(J)L.setShareConfigRightSidebarCollapsed(!L.shareConfigRightSidebarCollapsed);else L.setFileListRightSidebarCollapsed(!L.fileListRightSidebarCollapsed)},I=N?void 0:()=>{B(!_)},m=Y?L.viewModes[Y]??"card":"card";return f(Yf,{teamId:U,projectId:Y,projectName:E,ancestorFolders:h,currentAsset:P,isRootFolder:T,displayStyle:S||J?void 0:m,onDisplayStyleChange:S||J?void 0:N?void 0:(t)=>{if(Y)L.setViewMode(Y,t)},isLeftSidebarCollapsed:b,onLeftSidebarToggle:A,isRightSidebarCollapsed:k,onRightSidebarToggle:y,isChatbotOpen:!N&&_,onChatbotToggle:I,isPublic:N,shareId:Q,fileId:$,downloadInfo:v,versions:Z,onFolderClick:w,compareMode:q,canCompareVersions:G,onCompareVersions:z})}function hf(){return f("div",{className:"flex h-14 flex-wrap items-center justify-center gap-2 border-b border-border bg-card px-4 py-2 flex-shrink-0",children:f(_f,{className:"w-10 h-10 text-orange-600"})})}
2
- export{cf as ve};
1
+ import{Of as Rf,Pf as Lf,Qf as Vf,Rf as Cf,Wf as Hf,Xf as Jf,Yf as Kf,Zf as Qf,_f as Wf,bg as _f}from"./chunk-qjjr3fff.js";import{hg as Zf,ig as Gf}from"./chunk-99db4j0k.js";import{jg as zf}from"./chunk-7ktvhtp1.js";import{pg as $f}from"./chunk-2xnys7v4.js";import{$j as Xf,Ah as x,Ai as ff,Fj as D,Lj as Sf,Mj as a,Nj as Nf,Oj as Uf,Pj as W,Sg as O,Sj as qf,Tg as f,Th as e,Tj as g,Ug as V,Uj as p,Vj as l,Wj as c,Yh as j,Zh as r,Zj as X,dh as u,fh as d,mi as n,ti as o,uh as i,wi as s}from"./chunk-wf4d1anc.js";function Yf({teamId:K,projectId:L,projectName:_,ancestorFolders:B,currentAsset:U,isRootFolder:Y,displayStyle:E,onDisplayStyleChange:h,isLeftSidebarCollapsed:P,onLeftSidebarToggle:T,isRightSidebarCollapsed:$,onRightSidebarToggle:v,isChatbotOpen:Z=!1,onChatbotToggle:N,isPublic:Q=!1,onFolderClick:w,fileId:q,shareId:G,downloadInfo:z,versions:S,compareMode:J=!1,canCompareVersions:b=!1,onCompareVersions:A}){let k=u(),{canEdit:y}=Xf(L),I=!1,m=(R)=>{if(!q)return;if(Q&&G){k({to:"/share/$shareId/files/$fileId",params:{shareId:G,fileId:q},search:(C)=>({...C,version:R})});return}if(!L)return;k({to:"/projects/$projectId/files/$fileId",params:{projectId:L,fileId:q},search:(C)=>({...C,version:R})})},M=async(R)=>{if(!q)return;try{let C=G?await i.api.shares[":shareId"].files[":fileId"]["download-url"].$post({param:{shareId:G,fileId:q},json:{key:R}}):await i.api.files["download-url"].$post({json:{key:R,assetId:q}});if(!C.ok)return;let{url:H}=await C.json(),F=document.createElement("a");F.href=H,F.download="",document.body.appendChild(F),F.click(),document.body.removeChild(F)}catch{}},Bf=U.proxyType!=="audio"&&z?.videoTranscodes&&z.videoTranscodes.filter((R)=>!R.isRaw).length>0,Ef=Q?[{name:_,id:"root"},...B.slice().reverse().map((R)=>({name:R.name||"",id:R.id}))]:[{name:X.all_projects(),path:`/teams/${K}`,isMuted:!0},{name:_,path:`/projects/${L}`},...B.slice().reverse().map((R)=>({name:R.name||"",path:`/projects/${L}/folders/${R.id}`}))];return V("div",{className:"flex h-14 flex-wrap items-center justify-between gap-2 border-b border-border bg-card px-4 py-2",children:[V("div",{className:"flex min-w-0 flex-shrink items-center gap-1",children:[Ef.map((R,C)=>V("div",{className:"flex items-center gap-1",children:[C>0&&f("span",{className:"text-muted-foreground",children:"/"}),R.path?f(d,{to:R.path,className:D("truncate rounded px-2 py-1 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground",R.isMuted?"text-muted-foreground":"text-foreground"),children:R.name}):f("button",{onClick:()=>R.id&&w?.(R.id),className:"truncate rounded px-2 py-1 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground text-foreground",children:R.name})]},C)),!Y&&!J&&V("div",{className:"flex items-center gap-1",children:[f("span",{className:"text-muted-foreground",children:"/"}),U.type==="folder"?f("span",{className:"truncate rounded px-2 py-1 text-sm font-medium text-foreground",children:U.name}):V(Sf,{children:[V(Nf,{className:"flex items-center gap-1 truncate rounded px-2 py-1 text-sm font-medium text-foreground transition-colors hover:bg-accent hover:text-accent-foreground",children:[f("span",{children:U.name}),U.version!==void 0&&V(zf,{variant:"outline",className:"px-1 py-0 text-xs",children:["v",U.version]}),f(r,{className:"h-4 w-4"})]}),V(Uf,{className:"w-56",children:[Bf?V(p,{children:[f(l,{className:"flex items-center gap-2",children:f("span",{children:X.download()})}),f(a,{children:V(c,{className:"w-48",children:[f(qf,{children:X.download()}),z?.videoTranscodes?.filter((R)=>!R.isRaw).map((R)=>{let C=Math.max(R.width,R.height),H=`${R.height}p`;if(C>=3840)H="2160p";else if(C>=1920)H="1080p";else if(C>=1280)H="720p";else if(C>=960)H="540p";else if(C>=640)H="360p";else if(C>=320)H="180p";return V(W,{onClick:()=>M(R.key),className:"flex items-center justify-between",children:[f("span",{children:H}),f("span",{className:"text-xs text-muted-foreground",children:"MP4"})]},H)}),z?.originalKey&&V(O,{children:[f(g,{}),V(W,{onClick:()=>M(z.originalKey),className:"flex items-center justify-between",children:[f("span",{children:"Original"}),f("span",{className:"text-xs text-muted-foreground",children:U.name?.split(".").pop()?.toUpperCase()||"RAW"})]})]})]})})]}):f(W,{onClick:()=>z?.originalKey&&M(z.originalKey),disabled:!z?.originalKey,children:X.download()}),y&&f(W,{onClick:()=>console.log("Rename"),children:"Rename"}),y&&f(W,{onClick:()=>console.log("Delete"),children:"Delete"}),b&&A&&V(O,{children:[f(g,{}),V(W,{onClick:()=>A(),children:[f(x,{className:"h-4 w-4"}),f("span",{children:X.compare_versions()})]})]}),S&&S.length>0&&V(O,{children:[f(g,{}),V(p,{children:[V(l,{className:"flex items-center gap-2",children:[f(o,{className:"h-4 w-4"}),f("span",{children:"Versions"})]}),f(a,{children:V(c,{className:"w-80 p-1",children:[f("div",{className:"flex flex-col gap-1 max-h-96 overflow-y-auto",children:S.map((R)=>{let C=U.version===R.version;return V(W,{onClick:()=>m(R.id),className:"flex items-center gap-3 py-2 px-3 rounded-md cursor-pointer focus:bg-accent focus:text-accent-foreground",children:[V("div",{className:"flex-shrink-0 flex items-center justify-center bg-muted dark:bg-muted-foreground/20 text-muted-foreground dark:text-muted-foreground rounded-full px-2 py-0.5 text-xs font-semibold select-none min-w-[2rem]",children:["v",R.version]}),f("div",{className:"h-10 w-16 flex-shrink-0 overflow-hidden rounded-md border border-border bg-muted flex items-center justify-center",children:R.previewUrl?f("img",{src:R.previewUrl,alt:R.name||void 0,className:"h-full w-full object-cover"}):f(n,{className:"h-4 w-4 text-muted-foreground"})}),V("div",{className:"flex flex-col flex-1 min-w-0 text-left",children:[f("span",{className:"truncate text-sm font-semibold text-foreground",children:R.name}),f("span",{className:"truncate text-xs text-muted-foreground",children:R.creator?.name||"Unknown"})]}),C&&f(j,{className:"h-4 w-4 text-primary ml-auto flex-shrink-0"})]},R.id)})}),f(g,{}),f("div",{className:"p-1",children:f("button",{className:"w-full text-center text-xs font-medium py-2 px-3 rounded-md bg-muted/80 hover:bg-muted text-foreground transition-colors",onClick:()=>console.log("Manage versions"),children:"Manage versions..."})})]})})]})]})]})]})]})]}),V("div",{className:"flex items-center gap-2",children:[V("div",{className:"flex flex-shrink-0 items-center gap-1 rounded-md border border-border bg-background p-1",children:[!q&&!Q&&T&&f("button",{onClick:T,className:"rounded p-1.5 text-muted-foreground transition-colors hover:bg-accent/50 hover:text-foreground",title:P?"Show Left Sidebar":"Hide Left Sidebar",children:P?f(Hf,{className:"h-4 w-4"}):f(Kf,{className:"h-4 w-4 fill-primary stroke-0"})}),!q&&!Q&&E&&h&&V(O,{children:[f("button",{onClick:()=>h("card"),className:`rounded p-1.5 transition-colors ${E==="card"?"bg-accent text-accent-foreground":"text-muted-foreground hover:bg-accent/50 hover:text-foreground"}`,title:"Card View",children:f(s,{className:"h-4 w-4"})}),f("button",{onClick:()=>h("list"),className:`rounded p-1.5 transition-colors ${E==="list"?"bg-accent text-accent-foreground":"text-muted-foreground hover:bg-accent/50 hover:text-foreground"}`,title:"List View",children:f(ff,{className:"h-4 w-4"})})]}),f("button",{onClick:v,className:`rounded p-1.5 transition-colors ${!$&&!Z?"bg-accent text-accent-foreground":"text-muted-foreground hover:bg-accent/50 hover:text-foreground"}`,title:$?"Show Right Sidebar":"Hide Right Sidebar",children:!$&&!Z?f(Qf,{className:"h-4 w-4 fill-primary stroke-0"}):f(Jf,{className:"h-4 w-4"})})]}),!Q&&N&&f(Rf,{children:V(Lf,{children:[f(Vf,{asChild:!0,children:f("span",{children:f("button",{disabled:!1,onClick:N,className:D("h-9 w-9 flex items-center justify-center rounded-full border border-border bg-background transition-colors",Z?"bg-accent text-accent-foreground":"text-muted-foreground hover:bg-accent hover:text-foreground",!1),children:Z?f(Wf,{className:"h-6 w-6 text-primary transition-colors"}):f(e,{className:"h-6 w-6 text-muted-foreground transition-colors"})})})}),f(Cf,{children:f("p",{children:Z?X.hide_chatbot():X.show_chatbot()})})]})})]})]})}function cf(){let{projectState:K}=Zf(),L=$f(),{isChatbotOpen:_,setIsChatbotOpen:B}=Gf();if(!K)return f(hf,{});let{teamId:U,projectId:Y,projectName:E,ancestorFolders:h,currentAsset:P,isRootFolder:T,fileId:$,downloadInfo:v,versions:Z,isPublic:N,shareId:Q,onFolderClick:w,compareMode:q,canCompareVersions:G,onCompareVersions:z}=K,S=!!$,J=!!Q&&!S,b=S?L.fileViewLeftSidebarCollapsed:J?L.shareConfigLeftSidebarCollapsed:L.fileListLeftSidebarCollapsed,A=N?void 0:()=>S?L.setFileViewLeftSidebarCollapsed(!L.fileViewLeftSidebarCollapsed):J?L.setShareConfigLeftSidebarCollapsed(!L.shareConfigLeftSidebarCollapsed):L.setFileListLeftSidebarCollapsed(!L.fileListLeftSidebarCollapsed),k=N&&K.isRightSidebarCollapsed!==void 0?K.isRightSidebarCollapsed:S?L.fileViewRightSidebarCollapsed:J?L.shareConfigRightSidebarCollapsed:L.fileListRightSidebarCollapsed,y=N&&K.onRightSidebarToggle?K.onRightSidebarToggle:()=>{if(!N&&_)if(B(!1),S)L.setFileViewRightSidebarCollapsed(!1);else if(J)L.setShareConfigRightSidebarCollapsed(!1);else L.setFileListRightSidebarCollapsed(!1);else if(S)L.setFileViewRightSidebarCollapsed(!L.fileViewRightSidebarCollapsed);else if(J)L.setShareConfigRightSidebarCollapsed(!L.shareConfigRightSidebarCollapsed);else L.setFileListRightSidebarCollapsed(!L.fileListRightSidebarCollapsed)},I=N?void 0:()=>{B(!_)},m=Y?L.viewModes[Y]??"card":"card";return f(Yf,{teamId:U,projectId:Y,projectName:E,ancestorFolders:h,currentAsset:P,isRootFolder:T,displayStyle:S||J?void 0:m,onDisplayStyleChange:S||J?void 0:N?void 0:(t)=>{if(Y)L.setViewMode(Y,t)},isLeftSidebarCollapsed:b,onLeftSidebarToggle:A,isRightSidebarCollapsed:k,onRightSidebarToggle:y,isChatbotOpen:!N&&_,onChatbotToggle:I,isPublic:N,shareId:Q,fileId:$,downloadInfo:v,versions:Z,onFolderClick:w,compareMode:q,canCompareVersions:G,onCompareVersions:z})}function hf(){return f("div",{className:"flex h-14 flex-wrap items-center justify-center gap-2 border-b border-border bg-card px-4 py-2 flex-shrink-0",children:f(_f,{className:"w-10 h-10 text-orange-600"})})}
2
+ export{cf as pf};
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ import{Zb as V}from"./chunk-mwh2n8yt.js";import{$b as U,_b as v,ac as x,bc as b,cc as f,dc as h}from"./chunk-nceqrqey.js";import{ec as I,fc as B}from"./chunk-w88219ex.js";import{hc as T}from"./chunk-2dsmsa6a.js";import{kc as C}from"./chunk-ta7bfdrn.js";import{mc as P}from"./chunk-pxw97qbq.js";import{$e as E,af as M}from"./chunk-q09dfja5.js";import{bf as y}from"./chunk-d2vxmn9v.js";import{Ek as F,Gk as K,Hk as j}from"./chunk-jfjcxyhf.js";import"./chunk-976v5s8y.js";var k="v1",u="gcp-vertex-credentials",a={THINKING_LEVEL_UNSPECIFIED:F.THINKING_LEVEL_UNSPECIFIED,MINIMAL:F.MINIMAL,LOW:F.LOW,MEDIUM:F.MEDIUM,HIGH:F.HIGH},c=0,R=(q,w,J)=>{let Y=new y;return(async()=>{let Q={role:"assistant",content:[],api:"google-vertex",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 $=n(J),D=$?l(q,$,J?.headers):p(q,t(J),o(J),J?.headers,J?.env),N=qq(q,w,J),L=await J?.onPayload?.(N,q);if(L!==void 0)N=L;let d=await D.models.generateContentStream(N);Y.push({type:"start",partial:Q});let Z=null,O=Q.content,X=()=>O.length-1;for await(let z of d){Q.responseId||=z.responseId;let H=z.candidates?.[0];if(H?.content?.parts)for(let W of H.content.parts){if(W.text!==void 0){let _=v(W);if(!Z||_&&Z.type!=="thinking"||!_&&Z.type!=="text"){if(Z)if(Z.type==="text")Y.push({type:"text_end",contentIndex:O.length-1,content:Z.text,partial:Q});else Y.push({type:"thinking_end",contentIndex:X(),content:Z.thinking,partial:Q});if(_)Z={type:"thinking",thinking:"",thinkingSignature:void 0},Q.content.push(Z),Y.push({type:"thinking_start",contentIndex:X(),partial:Q});else Z={type:"text",text:""},Q.content.push(Z),Y.push({type:"text_start",contentIndex:X(),partial:Q})}if(Z.type==="thinking")Z.thinking+=W.text,Z.thinkingSignature=U(Z.thinkingSignature,W.thoughtSignature),Y.push({type:"thinking_delta",contentIndex:X(),delta:W.text,partial:Q});else Z.text+=W.text,Z.textSignature=U(Z.textSignature,W.thoughtSignature),Y.push({type:"text_delta",contentIndex:X(),delta:W.text,partial:Q})}if(W.functionCall){if(Z){if(Z.type==="text")Y.push({type:"text_end",contentIndex:X(),content:Z.text,partial:Q});else Y.push({type:"thinking_end",contentIndex:X(),content:Z.thinking,partial:Q});Z=null}let _=W.functionCall.id,S={type:"toolCall",id:!_||Q.content.some((A)=>A.type==="toolCall"&&A.id===_)?`${W.functionCall.name}_${Date.now()}_${++c}`:_,name:W.functionCall.name||"",arguments:W.functionCall.args??{},...W.thoughtSignature&&{thoughtSignature:W.thoughtSignature}};Q.content.push(S),Y.push({type:"toolcall_start",contentIndex:X(),partial:Q}),Y.push({type:"toolcall_delta",contentIndex:X(),delta:JSON.stringify(S.arguments),partial:Q}),Y.push({type:"toolcall_end",contentIndex:X(),toolCall:S,partial:Q})}}if(H?.finishReason){if(Q.stopReason=h(H.finishReason),Q.content.some((W)=>W.type==="toolCall"))Q.stopReason="toolUse"}if(z.usageMetadata)Q.usage={input:(z.usageMetadata.promptTokenCount||0)-(z.usageMetadata.cachedContentTokenCount||0),output:(z.usageMetadata.candidatesTokenCount||0)+(z.usageMetadata.thoughtsTokenCount||0),cacheRead:z.usageMetadata.cachedContentTokenCount||0,cacheWrite:0,reasoning:z.usageMetadata.thoughtsTokenCount||0,totalTokens:z.usageMetadata.totalTokenCount||0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},E(q,Q.usage)}if(Z)if(Z.type==="text")Y.push({type:"text_end",contentIndex:X(),content:Z.text,partial:Q});else Y.push({type:"thinking_end",contentIndex:X(),content:Z.thinking,partial:Q});if(J?.signal?.aborted)throw Error("Request was aborted");if(Q.stopReason==="aborted"||Q.stopReason==="error")throw Error("An unknown error occurred");Y.push({type:"done",reason:Q.stopReason,message:Q}),Y.end()}catch($){for(let D of Q.content)if("index"in D)delete D.index;Q.stopReason=J?.signal?.aborted?"aborted":"error",Q.errorMessage=B(I($)),Y.push({type:"error",reason:Q.stopReason,error:Q}),Y.end()}})(),Y},Hq=(q,w,J)=>{let Y=T(q,w,J,void 0);if(!J?.reasoning)return R(q,w,{...Y,thinking:{enabled:!1}});let Q=M(q,J.reasoning),$=Q==="off"?"high":Q,D=q;if(G(D)||m(D))return R(q,w,{...Y,thinking:{enabled:!0,level:Jq($,D)}});return R(q,w,{...Y,thinking:{enabled:!0,budgetTokens:Qq(D,$,J.thinkingBudgets)}})};function p(q,w,J,Y,Q){let $=i(Q);return new j({vertexai:!0,project:w,location:J,apiVersion:k,...$?{googleAuthOptions:$}:{},httpOptions:g(q,Y)})}function l(q,w,J){return new j({vertexai:!0,apiKey:w,apiVersion:k,httpOptions:g(q,J)})}function g(q,w){let J={},Y=r(q.baseUrl);if(Y){if(J.baseUrl=Y,J.baseUrlResourceScope=K.COLLECTION,s(Y))J.apiVersion=""}let Q=P({...q.headers,...w});if(Q)J.headers=Q;return Object.keys(J).length>0?J:void 0}function r(q){let w=q.trim();if(!w||w.includes("{location}"))return;return w}function s(q){try{return new URL(q).pathname.split("/").some((J)=>/^v\d+(?:beta\d*)?$/.test(J))}catch{return/(?:^|\/)v\d+(?:beta\d*)?(?:\/|$)/.test(q)}}function i(q){let w=V("GOOGLE_APPLICATION_CREDENTIALS",q);return w?{keyFilename:w}:void 0}function n(q){let w=q?.apiKey?.trim();if(!w||w===u||e(w))return;return w}function e(q){return/^<[^>]+>$/.test(q)}function t(q){let w=q?.project||V("GOOGLE_CLOUD_PROJECT",q?.env)||V("GCLOUD_PROJECT",q?.env);if(!w)throw Error("Vertex AI requires a project ID. Set GOOGLE_CLOUD_PROJECT/GCLOUD_PROJECT or pass project in options.");return w}function o(q){let w=q?.location||V("GOOGLE_CLOUD_LOCATION",q?.env);if(!w)throw Error("Vertex AI requires a location. Set GOOGLE_CLOUD_LOCATION or pass location in options.");return w}function qq(q,w,J={}){let Y=x(q,w),Q={};if(J.temperature!==void 0)Q.temperature=J.temperature;if(J.maxTokens!==void 0)Q.maxOutputTokens=J.maxTokens;let $={...Object.keys(Q).length>0&&Q,...w.systemPrompt&&{systemInstruction:C(w.systemPrompt)},...w.tools&&w.tools.length>0&&{tools:b(w.tools)}};if(w.tools&&w.tools.length>0&&J.toolChoice)$.toolConfig={functionCallingConfig:{mode:f(J.toolChoice)}};else $.toolConfig=void 0;if(J.thinking?.enabled&&q.reasoning){let N={includeThoughts:!0};if(J.thinking.level!==void 0)N.thinkingLevel=a[J.thinking.level];else if(J.thinking.budgetTokens!==void 0)N.thinkingBudget=J.thinking.budgetTokens;$.thinkingConfig=N}else if(q.reasoning&&J.thinking&&!J.thinking.enabled)$.thinkingConfig=wq(q);if(J.signal){if(J.signal.aborted)throw Error("Request aborted");$.abortSignal=J.signal}return{model:q.id,contents:Y,config:$}}function G(q){return/gemini-3(?:\.\d+)?-pro/.test(q.id.toLowerCase())}function m(q){let w=q.id.toLowerCase();return/gemini-3(?:\.\d+)?-flash/.test(w)||w==="gemini-flash-latest"||w==="gemini-flash-lite-latest"}function wq(q){let w=q;if(G(w))return{thinkingLevel:F.LOW};if(m(w))return{thinkingLevel:F.MINIMAL};return{thinkingBudget:0}}function Jq(q,w){if(G(w))switch(q){case"minimal":case"low":return"LOW";case"medium":case"high":return"HIGH"}switch(q){case"minimal":return"MINIMAL";case"low":return"LOW";case"medium":return"MEDIUM";case"high":return"HIGH"}}function Qq(q,w,J){if(J?.[w]!==void 0)return J[w];if(q.id.includes("2.5-pro"))return{minimal:128,low:2048,medium:8192,high:32768}[w];if(q.id.includes("2.5-flash"))return{minimal:128,low:2048,medium:8192,high:24576}[w];return-1}export{Hq as streamSimple,R as stream};
@@ -1,4 +1,4 @@
1
1
  // @bun
2
- import{Nj as L,Pj as w}from"./chunk-mjan6b09.js";import{Uj as Z}from"./chunk-08m8mzfa.js";import{Yj as J}from"./chunk-eadb78m8.js";function d(b){return b.thought===!0}function B(b,j){if(typeof j==="string"&&j.length>0)return j;return b}var x=/^[A-Za-z0-9+/]+={0,2}$/;function T(b){if(!b)return!1;if(b.length%4!==0)return!1;return x.test(b)}function Q(b,j){return b&&T(j)?j:void 0}function U(b){return b.startsWith("claude-")||b.startsWith("gpt-oss-")}function f(b){let j=b.toLowerCase().match(/^gemini(?:-live)?-(\d+)/);if(!j)return;return Number.parseInt(j[1],10)}function y(b){let j=f(b);if(j!==void 0)return j>=3;return!0}function R(b,j){let A=[],N=(z)=>{if(!U(b.id))return z;return z.replace(/[^a-zA-Z0-9_-]/g,"_").slice(0,64)},$=Z(j.messages,b,N);for(let z of $)if(z.role==="user")if(typeof z.content==="string")A.push({role:"user",parts:[{text:J(z.content)}]});else{let E=z.content.map((D)=>{if(D.type==="text")return{text:J(D.text)};else return{inlineData:{mimeType:D.mimeType,data:D.data}}});if(E.length===0)continue;A.push({role:"user",parts:E})}else if(z.role==="assistant"){let E=[],D=z.provider===b.provider&&z.model===b.id;for(let q of z.content)if(q.type==="text"){if(!q.text||q.text.trim()==="")continue;let G=Q(D,q.textSignature);E.push({text:J(q.text),...G&&{thoughtSignature:G}})}else if(q.type==="thinking"){if(!q.thinking||q.thinking.trim()==="")continue;if(D){let G=Q(D,q.thinkingSignature);E.push({thought:!0,text:J(q.thinking),...G&&{thoughtSignature:G}})}else E.push({text:J(q.thinking)})}else if(q.type==="toolCall"){let G=Q(D,q.thoughtSignature),K={functionCall:{name:q.name,args:q.arguments??{},...U(b.id)?{id:q.id}:{}},...G&&{thoughtSignature:G}};E.push(K)}if(E.length===0)continue;A.push({role:"model",parts:E})}else if(z.role==="toolResult"){let D=z.content.filter((H)=>H.type==="text").map((H)=>H.text).join(`
2
+ import{Dk as L,Fk as w}from"./chunk-jfjcxyhf.js";import{Kk as Z}from"./chunk-2dz8nn9v.js";import{Ok as J}from"./chunk-pmx9760x.js";function d(b){return b.thought===!0}function B(b,j){if(typeof j==="string"&&j.length>0)return j;return b}var x=/^[A-Za-z0-9+/]+={0,2}$/;function T(b){if(!b)return!1;if(b.length%4!==0)return!1;return x.test(b)}function Q(b,j){return b&&T(j)?j:void 0}function U(b){return b.startsWith("claude-")||b.startsWith("gpt-oss-")}function f(b){let j=b.toLowerCase().match(/^gemini(?:-live)?-(\d+)/);if(!j)return;return Number.parseInt(j[1],10)}function y(b){let j=f(b);if(j!==void 0)return j>=3;return!0}function R(b,j){let A=[],N=(z)=>{if(!U(b.id))return z;return z.replace(/[^a-zA-Z0-9_-]/g,"_").slice(0,64)},$=Z(j.messages,b,N);for(let z of $)if(z.role==="user")if(typeof z.content==="string")A.push({role:"user",parts:[{text:J(z.content)}]});else{let E=z.content.map((D)=>{if(D.type==="text")return{text:J(D.text)};else return{inlineData:{mimeType:D.mimeType,data:D.data}}});if(E.length===0)continue;A.push({role:"user",parts:E})}else if(z.role==="assistant"){let E=[],D=z.provider===b.provider&&z.model===b.id;for(let q of z.content)if(q.type==="text"){if(!q.text||q.text.trim()==="")continue;let G=Q(D,q.textSignature);E.push({text:J(q.text),...G&&{thoughtSignature:G}})}else if(q.type==="thinking"){if(!q.thinking||q.thinking.trim()==="")continue;if(D){let G=Q(D,q.thinkingSignature);E.push({thought:!0,text:J(q.thinking),...G&&{thoughtSignature:G}})}else E.push({text:J(q.thinking)})}else if(q.type==="toolCall"){let G=Q(D,q.thoughtSignature),K={functionCall:{name:q.name,args:q.arguments??{},...U(b.id)?{id:q.id}:{}},...G&&{thoughtSignature:G}};E.push(K)}if(E.length===0)continue;A.push({role:"model",parts:E})}else if(z.role==="toolResult"){let D=z.content.filter((H)=>H.type==="text").map((H)=>H.text).join(`
3
3
  `),q=b.input.includes("image")?z.content.filter((H)=>H.type==="image"):[],G=D.length>0,K=q.length>0,V=y(b.id),W=G?J(D):K?"(see attached image)":"",X=q.map((H)=>({inlineData:{mimeType:H.mimeType,data:H.data}})),v=U(b.id),Y={functionResponse:{name:z.toolName,response:z.isError?{error:W}:{output:W},...K&&V&&{parts:X},...v?{id:z.toolCallId}:{}}},O=A[A.length-1];if(O?.role==="user"&&O.parts?.some((H)=>H.functionResponse))O.parts.push(Y);else A.push({role:"user",parts:[Y]});if(K&&!V)A.push({role:"user",parts:[{text:"Tool result image:"},...X]})}return A}var F=new Set(["$schema","$id","$anchor","$dynamicAnchor","$vocabulary","$comment","$defs","definitions"]);function _(b){if(typeof b!=="object"||b===null||Array.isArray(b))return b;let j={};for(let[A,N]of Object.entries(b)){if(F.has(A))continue;j[A]=_(N)}return j}function C(b,j=!1){if(b.length===0)return;return[{functionDeclarations:b.map((A)=>({name:A.name,description:A.description,...j?{parameters:_(A.parameters)}:{parametersJsonSchema:A.parameters}}))}]}function k(b){switch(b){case"auto":return L.AUTO;case"none":return L.NONE;case"any":return L.ANY;default:return L.AUTO}}function P(b){switch(b){case w.STOP:return"stop";case w.MAX_TOKENS:return"length";case w.BLOCKLIST:case w.PROHIBITED_CONTENT:case w.SPII:case w.SAFETY:case w.IMAGE_SAFETY:case w.IMAGE_PROHIBITED_CONTENT:case w.IMAGE_RECITATION:case w.IMAGE_OTHER:case w.RECITATION:case w.FINISH_REASON_UNSPECIFIED:case w.OTHER:case w.LANGUAGE:case w.MALFORMED_FUNCTION_CALL:case w.UNEXPECTED_TOOL_CALL:case w.NO_IMAGE:return"error";default:throw Error(`Unhandled stop reason: ${b}`)}}
4
- export{d as Hj,B as Ij,R as Jj,C as Kj,k as Lj,P as Mj};
4
+ export{d as xk,B as yk,R as zk,C as Ak,k as Bk,P as Ck};
@@ -0,0 +1,3 @@
1
+ // @bun
2
+ function _(q){return q.totalTokens||q.input+q.output+q.cacheRead+q.cacheWrite}function N(q){try{return JSON.stringify(q)??"undefined"}catch{return"[unserializable]"}}function z(q){if(typeof q==="string")return q.length;let G=0;for(let D of q)G+=D.type==="text"?D.text.length:4800;return G}function P(q){return Math.ceil(q.length/4)}function E(q){return Math.ceil(z(q)/4)}function K(q){let G=0;if(q.role==="user")return E(q.content);if(q.role==="toolResult")return E(q.content);for(let D of q.content)if(D.type==="text")G+=D.text.length;else if(D.type==="thinking")G+=D.thinking.length;else G+=D.name.length+N(D.arguments).length;return Math.ceil(G/4)}function h(q){let G=Number.NEGATIVE_INFINITY,D;for(let H=0;H<q.length;H++){let Z=q[H];if(Z.role==="assistant"){let V=Z;if(V.timestamp>=G&&V.stopReason!=="aborted"&&V.stopReason!=="error"&&_(V.usage)>0)D={usage:V.usage,index:H}}G=Math.max(G,Z.timestamp)}return D}function W(q){let G=h(q);if(G){let H=_(G.usage),Z=0;for(let V=G.index+1;V<q.length;V++)Z+=K(q[V]);return{tokens:H+Z,usageTokens:H,trailingTokens:Z,lastUsageIndex:G.index}}let D=0;for(let H of q)D+=K(H);return{tokens:D,usageTokens:0,trailingTokens:D,lastUsageIndex:null}}function B(q){if(!q||q.length===0)return 0;return P(N(q))}function f(q){return Array.isArray(q)}function R(q){if(f(q))return W(q);let G=W(q.messages);if(G.lastUsageIndex!==null){let H=new Set(q.messages.slice(G.lastUsageIndex+1).filter((V)=>V.role==="toolResult").flatMap((V)=>V.addedToolNames??[])),Z=B(q.tools?.filter((V)=>H.has(V.name)));return{tokens:G.tokens+Z,usageTokens:G.usageTokens,trailingTokens:G.trailingTokens+Z,lastUsageIndex:G.lastUsageIndex}}let D=(q.systemPrompt?P(q.systemPrompt):0)+B(q.tools);return{tokens:G.tokens+D,usageTokens:G.usageTokens,trailingTokens:G.trailingTokens+D,lastUsageIndex:G.lastUsageIndex}}var I=4096,v=1;function C(q,G,D){if(q.contextWindow<=0)return Math.max(v,D);let H=q.contextWindow-R(G).tokens-I;return Math.min(D,Math.max(v,H))}function T(q,G,D,H){return{temperature:D?.temperature,maxTokens:C(q,G,D?.maxTokens??q.maxTokens),signal:D?.signal,apiKey:H||D?.apiKey,transport:D?.transport,cacheRetention:D?.cacheRetention,sessionId:D?.sessionId,headers:D?.headers,onPayload:D?.onPayload,onResponse:D?.onResponse,timeoutMs:D?.timeoutMs,websocketConnectTimeoutMs:D?.websocketConnectTimeoutMs,maxRetries:D?.maxRetries,maxRetryDelayMs:D?.maxRetryDelayMs,metadata:D?.metadata,env:D?.env}}function M(q){return q==="xhigh"||q==="max"?"high":q}function p(q,G,D,H){let V={...{minimal:1024,low:2048,medium:8192,high:16384},...H},L=1024,Y=M(D),F=V[Y],j=q===void 0?G:Math.min(q+F,G);if(j<=F)F=Math.max(0,j-1024);return{maxTokens:j,thinkingBudget:F}}function S(q,G){let D=[],H=!1;for(let Z of q){if(Z.type==="image"){if(!H)D.push({type:"text",text:G});H=!0;continue}D.push(Z),H=Z.text===G}return D}function b(q,G){if(G.input.includes("image"))return q;return q.map((D)=>{if(D.role==="user"&&Array.isArray(D.content))return{...D,content:S(D.content,"(image omitted: model does not support images)")};if(D.role==="toolResult")return{...D,content:S(D.content,"(tool image omitted: model does not support images)")};return D})}function k(q,G,D){let H=new Map,Z=q.map((J)=>J.content==null?{...J,content:[]}:J),L=b(Z,G).map((J)=>{if(J.role==="user")return J;if(J.role==="toolResult"){let Q=H.get(J.toolCallId);if(Q&&Q!==J.toolCallId)return{...J,toolCallId:Q};return J}if(J.role==="assistant"){let Q=J,w=Q.provider===G.provider&&Q.api===G.api&&Q.model===G.id,O=Q.content.flatMap(($)=>{if($.type==="thinking"){if($.redacted)return w?$:[];if(w&&$.thinkingSignature)return $;if(!$.thinking||$.thinking.trim()==="")return[];if(w)return $;return{type:"text",text:$.thinking}}if($.type==="text"){if(w)return $;return{type:"text",text:$.text}}if($.type==="toolCall"){let U=$,X=U;if(!w&&U.thoughtSignature)X={...U},delete X.thoughtSignature;if(!w&&D){let A=D(U.id,G,Q);if(A!==U.id)H.set(U.id,A),X={...X,id:A}}return X}return $});return{...Q,content:O}}return J}),Y=[],F=[],j=new Set,y=()=>{if(F.length>0){for(let J of F)if(!j.has(J.id))Y.push({role:"toolResult",toolCallId:J.id,toolName:J.name,content:[{type:"text",text:"No result provided"}],isError:!0,timestamp:Date.now()});F=[],j=new Set}};for(let J=0;J<L.length;J++){let Q=L[J];if(Q.role==="assistant"){y();let w=Q;if(w.stopReason==="error"||w.stopReason==="aborted")continue;let O=w.content.filter(($)=>$.type==="toolCall");if(O.length>0)F=O,j=new Set;Y.push(Q)}else if(Q.role==="toolResult")j.add(Q.toolCallId),Y.push(Q);else if(Q.role==="user")y(),Y.push(Q);else Y.push(Q)}return y(),Y}
3
+ export{C as gc,T as hc,p as ic,k as jc};
@@ -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 Sj,y as Tj,W as Uj};
3
+ export{L as Ik,y as Jk,W as Kk};
@@ -1,2 +1,2 @@
1
- import{$f as x,Ag as h,Pi as a,bg as v,xg as g,zg as _}from"./chunk-nwtb6dt1.js";import{Zj as M}from"./chunk-kbzm1pwx.js";var m=M(x(),1),J=M(x(),1),N=M(x(),1);var T=new Map,W=new WeakMap,O=0,I;function w(S){if(!S)return"0";if(W.has(S))return W.get(S);return O+=1,W.set(S,O.toString()),W.get(S)}function p(S){return Object.keys(S).sort().filter((d)=>S[d]!==void 0).map((d)=>{return`${d}_${d==="root"?w(S.root):S[d]}`}).toString()}function k(S){let d=p(S),C=T.get(d);if(!C){let D=new Map,q,F=new IntersectionObserver((f)=>{f.forEach((L)=>{var U;let G=L.isIntersecting&&q.some((A)=>L.intersectionRatio>=A);if(S.trackVisibility&&typeof L.isVisible>"u")L.isVisible=G;[...(U=D.get(L.target))!=null?U:[]].forEach((A)=>{A(G,L)})})},S);q=F.thresholds||(Array.isArray(S.threshold)?S.threshold:[S.threshold||0]),C={id:d,observer:F,elements:D},T.set(d,C)}return C}function V(S,d,C={},D=I){if(typeof window.IntersectionObserver>"u"&&D!==void 0){let U=S.getBoundingClientRect();return d(D,{isIntersecting:D,target:S,intersectionRatio:typeof C.threshold==="number"?C.threshold:0,time:0,boundingClientRect:U,intersectionRect:U,rootBounds:U}),()=>{}}let{id:q,observer:F,elements:f}=k(C),L=f.get(S)||[];if(!f.has(S))f.set(S,L);return L.push(d),F.observe(S),function(){if(L.splice(L.indexOf(d),1),L.length===0)f.delete(S),F.unobserve(S);if(f.size===0)F.disconnect(),T.delete(q)}}function y({threshold:S,delay:d,trackVisibility:C,rootMargin:D,root:q,triggerOnce:F,skip:f,initialInView:L,fallbackInView:U,onChange:G}={}){var A;let[K,b]=J.useState(null),X=J.useRef(G),H=J.useRef(L),[Y,j]=J.useState({inView:!!L,entry:void 0});X.current=G,J.useEffect(()=>{if(H.current===void 0)H.current=L;if(f||!K)return;let B;return B=V(K,(Q,$)=>{let u=H.current;if(H.current=Q,u===void 0&&!Q)return;if(j({inView:Q,entry:$}),X.current)X.current(Q,$);if($.isIntersecting&&F&&B)B(),B=void 0},{root:q,rootMargin:D,threshold:S,trackVisibility:C,delay:d},U),()=>{if(B)B()}},[Array.isArray(S)?S.toString():S,K,q,D,F,f,C,U,d]);let Z=(A=Y.entry)==null?void 0:A.target,E=J.useRef(void 0);if(!K&&Z&&!F&&!f&&E.current!==Z)E.current=Z,j({inView:!!L,entry:void 0}),H.current=L;let z=[b,Y.inView,Y.entry];return z.ref=z[0],z.inView=z[1],z.entry=z[2],z}var P,R,l=(R=(P=("useInsertionEffect"in N)?N.useInsertionEffect:void 0)!=null?P:N.useLayoutEffect)!=null?R:N.useEffect;var o=g()(h((S)=>({fileViewLeftSidebarCollapsed:!0,setFileViewLeftSidebarCollapsed:(d)=>S({fileViewLeftSidebarCollapsed:d}),fileViewRightSidebarCollapsed:!0,setFileViewRightSidebarCollapsed:(d)=>S({fileViewRightSidebarCollapsed:d}),fileListLeftSidebarCollapsed:!1,setFileListLeftSidebarCollapsed:(d)=>S({fileListLeftSidebarCollapsed:d}),fileListRightSidebarCollapsed:!0,setFileListRightSidebarCollapsed:(d)=>S({fileListRightSidebarCollapsed:d}),shareConfigLeftSidebarCollapsed:!1,setShareConfigLeftSidebarCollapsed:(d)=>S({shareConfigLeftSidebarCollapsed:d}),shareConfigRightSidebarCollapsed:!1,setShareConfigRightSidebarCollapsed:(d)=>S({shareConfigRightSidebarCollapsed:d}),viewModes:{},setViewMode:(d,C)=>S((D)=>({viewModes:{...D.viewModes,[d]:C}})),videoTimeDisplayMode:"standard",setVideoTimeDisplayMode:(d)=>S({videoTimeDisplayMode:d})}),{name:"ui-storage",storage:_(()=>localStorage)}));function n({className:S,...d}){return v("div",{"data-slot":"skeleton",className:a("animate-pulse rounded-md bg-accent",S),...d})}
2
- export{y as Wf,o as Xf,n as Yf};
1
+ import{Fj as a,Rg as x,Tg as v,nh as g,ph as _,qh as h}from"./chunk-wf4d1anc.js";import{Pk as M}from"./chunk-976v5s8y.js";var m=M(x(),1),J=M(x(),1),N=M(x(),1);var T=new Map,W=new WeakMap,O=0,I;function w(S){if(!S)return"0";if(W.has(S))return W.get(S);return O+=1,W.set(S,O.toString()),W.get(S)}function p(S){return Object.keys(S).sort().filter((d)=>S[d]!==void 0).map((d)=>{return`${d}_${d==="root"?w(S.root):S[d]}`}).toString()}function k(S){let d=p(S),C=T.get(d);if(!C){let D=new Map,q,F=new IntersectionObserver((f)=>{f.forEach((L)=>{var U;let G=L.isIntersecting&&q.some((A)=>L.intersectionRatio>=A);if(S.trackVisibility&&typeof L.isVisible>"u")L.isVisible=G;[...(U=D.get(L.target))!=null?U:[]].forEach((A)=>{A(G,L)})})},S);q=F.thresholds||(Array.isArray(S.threshold)?S.threshold:[S.threshold||0]),C={id:d,observer:F,elements:D},T.set(d,C)}return C}function V(S,d,C={},D=I){if(typeof window.IntersectionObserver>"u"&&D!==void 0){let U=S.getBoundingClientRect();return d(D,{isIntersecting:D,target:S,intersectionRatio:typeof C.threshold==="number"?C.threshold:0,time:0,boundingClientRect:U,intersectionRect:U,rootBounds:U}),()=>{}}let{id:q,observer:F,elements:f}=k(C),L=f.get(S)||[];if(!f.has(S))f.set(S,L);return L.push(d),F.observe(S),function(){if(L.splice(L.indexOf(d),1),L.length===0)f.delete(S),F.unobserve(S);if(f.size===0)F.disconnect(),T.delete(q)}}function y({threshold:S,delay:d,trackVisibility:C,rootMargin:D,root:q,triggerOnce:F,skip:f,initialInView:L,fallbackInView:U,onChange:G}={}){var A;let[K,b]=J.useState(null),X=J.useRef(G),H=J.useRef(L),[Y,j]=J.useState({inView:!!L,entry:void 0});X.current=G,J.useEffect(()=>{if(H.current===void 0)H.current=L;if(f||!K)return;let B;return B=V(K,(Q,$)=>{let u=H.current;if(H.current=Q,u===void 0&&!Q)return;if(j({inView:Q,entry:$}),X.current)X.current(Q,$);if($.isIntersecting&&F&&B)B(),B=void 0},{root:q,rootMargin:D,threshold:S,trackVisibility:C,delay:d},U),()=>{if(B)B()}},[Array.isArray(S)?S.toString():S,K,q,D,F,f,C,U,d]);let Z=(A=Y.entry)==null?void 0:A.target,E=J.useRef(void 0);if(!K&&Z&&!F&&!f&&E.current!==Z)E.current=Z,j({inView:!!L,entry:void 0}),H.current=L;let z=[b,Y.inView,Y.entry];return z.ref=z[0],z.inView=z[1],z.entry=z[2],z}var P,R,l=(R=(P=("useInsertionEffect"in N)?N.useInsertionEffect:void 0)!=null?P:N.useLayoutEffect)!=null?R:N.useEffect;var o=g()(h((S)=>({fileViewLeftSidebarCollapsed:!0,setFileViewLeftSidebarCollapsed:(d)=>S({fileViewLeftSidebarCollapsed:d}),fileViewRightSidebarCollapsed:!0,setFileViewRightSidebarCollapsed:(d)=>S({fileViewRightSidebarCollapsed:d}),fileListLeftSidebarCollapsed:!1,setFileListLeftSidebarCollapsed:(d)=>S({fileListLeftSidebarCollapsed:d}),fileListRightSidebarCollapsed:!0,setFileListRightSidebarCollapsed:(d)=>S({fileListRightSidebarCollapsed:d}),shareConfigLeftSidebarCollapsed:!1,setShareConfigLeftSidebarCollapsed:(d)=>S({shareConfigLeftSidebarCollapsed:d}),shareConfigRightSidebarCollapsed:!1,setShareConfigRightSidebarCollapsed:(d)=>S({shareConfigRightSidebarCollapsed:d}),viewModes:{},setViewMode:(d,C)=>S((D)=>({viewModes:{...D.viewModes,[d]:C}})),videoTimeDisplayMode:"standard",setVideoTimeDisplayMode:(d)=>S({videoTimeDisplayMode:d})}),{name:"ui-storage",storage:_(()=>localStorage)}));function n({className:S,...d}){return v("div",{"data-slot":"skeleton",className:a("animate-pulse rounded-md bg-accent",S),...d})}
2
+ export{y as og,o as pg,n as qg};
@@ -1,3 +1,3 @@
1
1
  // @bun
2
2
  function q(k){let b=3735928559,d=1103547991;for(let f=0;f<k.length;f++){let l=k.charCodeAt(f);b=Math.imul(b^l,2654435761),d=Math.imul(d^l,1597334677)}return b=Math.imul(b^b>>>16,2246822507)^Math.imul(d^d>>>13,3266489909),d=Math.imul(d^d>>>16,2246822507)^Math.imul(b^b>>>13,3266489909),(d>>>0).toString(36)+(b>>>0).toString(36)}
3
- export{q as zj};
3
+ export{q as Xb};
@@ -1,2 +1,2 @@
1
- import{$f as W,bg as b,cg as Y,xg as Z}from"./chunk-nwtb6dt1.js";import{Zj as R}from"./chunk-kbzm1pwx.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
- export{S as Ge,r as He};
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)`}})]})};
2
+ export{S as eg,r as fg};