@shumai-one/shumai 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/bin/{chunk-dwswqq3g.js → chunk-0a0sdyta.js} +1 -1
  2. package/bin/{chunk-qmtvy2j4.js → chunk-0dcv6kpk.js} +2 -2
  3. package/bin/chunk-1cjgpspz.js +2 -0
  4. package/bin/chunk-1pgtq4rc.js +2 -0
  5. package/bin/chunk-1rsp4hc5.js +1 -0
  6. package/bin/{chunk-7eycsyk6.js → chunk-2475z7vk.js} +1 -1
  7. package/bin/chunk-25qj10ny.js +1 -0
  8. package/bin/{chunk-gn8snrnk.js → chunk-2fc5hk8r.js} +1 -1
  9. package/bin/{chunk-qc6dmzn0.js → chunk-2jvqhps9.js} +2 -2
  10. package/bin/{chunk-ve7v8wtv.js → chunk-3823qzr0.js} +2 -2
  11. package/bin/{chunk-zxpef55w.js → chunk-3g9g2c7h.js} +3 -3
  12. package/bin/chunk-3gcnj1eq.js +2 -0
  13. package/bin/chunk-41m51y08.js +2 -0
  14. package/bin/chunk-4g7h9qhr.js +8 -0
  15. package/bin/chunk-4v5ykazp.js +1 -0
  16. package/bin/{chunk-k20bhxed.js → chunk-525eypdk.js} +1 -1
  17. package/bin/{chunk-h2wsm7h3.js → chunk-57kgmgfs.js} +2 -2
  18. package/bin/{chunk-gvn079hy.js → chunk-5cm4vge8.js} +2 -2
  19. package/bin/{chunk-31mjcykb.js → chunk-5vwkfxy7.js} +2 -2
  20. package/bin/chunk-5x3vzer8.js +1 -0
  21. package/bin/chunk-67rr836p.js +3 -0
  22. package/bin/chunk-6jgq154r.js +2 -0
  23. package/bin/chunk-7436fyrg.js +2 -0
  24. package/bin/{chunk-s05f0v9t.js → chunk-749c09cw.js} +1 -1
  25. package/bin/{chunk-9p2d0mk1.js → chunk-7anqxx1z.js} +1 -1
  26. package/bin/{chunk-s7qpj715.js → chunk-7pjes19z.js} +2 -2
  27. package/bin/{chunk-f8cn9m28.js → chunk-7x7jtkh8.js} +1 -1
  28. package/bin/chunk-804ndet8.js +2 -0
  29. package/bin/chunk-8a75zqbz.js +2 -0
  30. package/bin/{chunk-tsncwscz.js → chunk-9a7a1p1j.js} +2 -2
  31. package/bin/chunk-9e99n265.js +12 -0
  32. package/bin/chunk-9g6vy76b.js +2 -0
  33. package/bin/{chunk-wap08p4j.js → chunk-9sdhdhv4.js} +2 -2
  34. package/bin/{chunk-g2dk56e7.js → chunk-9vgjhemh.js} +1 -1
  35. package/bin/{chunk-1dawjfk8.js → chunk-9zvteyz0.js} +2 -2
  36. package/bin/chunk-a8daqpfh.js +7 -0
  37. package/bin/{chunk-na2nympm.js → chunk-am1m29pv.js} +1 -1
  38. package/bin/{chunk-xawwxdq9.js → chunk-bd6x5ns9.js} +2 -2
  39. package/bin/{chunk-wr5byz6r.js → chunk-bn4ewsy8.js} +1 -1
  40. package/bin/{chunk-ss45w8ks.js → chunk-bw6wyw7k.js} +2 -2
  41. package/bin/{chunk-8e5zvy88.js → chunk-c0c88nje.js} +48 -48
  42. package/bin/chunk-c7rj0f5r.js +3 -0
  43. package/bin/chunk-cdqvg03f.js +3 -0
  44. package/bin/{chunk-zs9b0f3z.js → chunk-d3kpqay2.js} +2 -2
  45. package/bin/chunk-d6v81kjj.js +1 -0
  46. package/bin/chunk-dfcrtdk2.js +1 -0
  47. package/bin/chunk-eczsk2xd.js +62 -0
  48. package/bin/{chunk-yahb7wan.js → chunk-ey7vty63.js} +2 -2
  49. package/bin/{chunk-nzy3pjjm.js → chunk-fwqpq2sy.js} +2 -2
  50. package/bin/{chunk-vnfmh5ke.js → chunk-g097058z.js} +2 -2
  51. package/bin/{chunk-a76c5r3c.js → chunk-g224r7mc.js} +2 -2
  52. package/bin/chunk-g5e93f59.js +2 -0
  53. package/bin/chunk-g5xkj9p3.js +2 -0
  54. package/bin/chunk-gaemak59.js +4 -0
  55. package/bin/{chunk-hrzm70wg.js → chunk-gh4w2bdg.js} +1 -1
  56. package/bin/chunk-gpeyctxd.js +2 -0
  57. package/bin/{chunk-v2kfr8fx.js → chunk-gpmaaca1.js} +2 -2
  58. package/bin/{chunk-1d22tysv.js → chunk-h4a3ms2b.js} +2 -2
  59. package/bin/chunk-h73653yp.js +1 -0
  60. package/bin/chunk-hp139z0j.js +2 -0
  61. package/bin/chunk-hz6s7by4.js +11 -0
  62. package/bin/chunk-j4y8c864.js +1 -0
  63. package/bin/chunk-jkh04dka.js +8 -0
  64. package/bin/chunk-m268vcdm.js +2 -0
  65. package/bin/{chunk-vy24ncn2.js → chunk-m6sssvg3.js} +1 -1
  66. package/bin/chunk-mggfc9ya.js +2 -0
  67. package/bin/chunk-mhwp74hh.js +3 -0
  68. package/bin/{chunk-vgb8bzcg.js → chunk-mm810jv7.js} +2 -2
  69. package/bin/chunk-p1bcbtmg.js +3 -0
  70. package/bin/chunk-p86w1eaw.js +45 -0
  71. package/bin/{chunk-1nh6xgek.js → chunk-p8enen2a.js} +1 -1
  72. package/bin/chunk-pbb1tdwt.js +1 -0
  73. package/bin/chunk-pbfkw90e.js +1 -0
  74. package/bin/chunk-pdajhyqm.js +2 -0
  75. package/bin/{chunk-ph3e1bpp.js → chunk-pqxh0cg7.js} +2 -2
  76. package/bin/chunk-q8me9zev.js +1 -0
  77. package/bin/chunk-qshm5vcn.js +2 -0
  78. package/bin/chunk-qx2mzv89.js +2 -0
  79. package/bin/{chunk-amsb41z5.js → chunk-r5jmnsqj.js} +1 -1
  80. package/bin/{chunk-arpna31w.js → chunk-rt0pvhdf.js} +1 -1
  81. package/bin/{chunk-kgb16ggd.css → chunk-s10v4b01.css} +1 -1
  82. package/bin/{chunk-rrxjvewm.js → chunk-s1b5kf34.js} +2 -2
  83. package/bin/{chunk-ws07a9kv.js → chunk-t15a1vp6.js} +1 -1
  84. package/bin/{chunk-3rcc5s99.js → chunk-tc7q988r.js} +2 -2
  85. package/bin/chunk-ts9f4zqh.js +5 -0
  86. package/bin/chunk-tzmzqmcg.js +7 -0
  87. package/bin/chunk-v0xbr5e6.js +2 -0
  88. package/bin/{chunk-08mxv0sm.js → chunk-v0yhkcj5.js} +2 -2
  89. package/bin/{chunk-3t7mjvdv.js → chunk-v75fanse.js} +2 -2
  90. package/bin/chunk-va6hxm7n.js +3 -0
  91. package/bin/chunk-vf3bg920.js +3 -0
  92. package/bin/{chunk-ejfmxjw6.js → chunk-vg6mkdj1.js} +2 -2
  93. package/bin/{chunk-j0p1peav.js → chunk-wkth5xwr.js} +2 -2
  94. package/bin/chunk-wpntb95k.js +2 -0
  95. package/bin/{chunk-mahxw48e.js → chunk-wtzkfwmx.js} +2 -2
  96. package/bin/{chunk-hfp4hpca.js → chunk-x0r8dcq0.js} +2 -2
  97. package/bin/{chunk-etces6ff.js → chunk-xcbb21j9.js} +2 -2
  98. package/bin/{chunk-mcxsk75h.js → chunk-xgb533n0.js} +3 -3
  99. package/bin/{chunk-7jjc175m.js → chunk-xn9cpax1.js} +3 -3
  100. package/bin/{chunk-5vqan9c4.js → chunk-xsw3pb5p.js} +2 -2
  101. package/bin/chunk-yedr4r8a.js +2 -0
  102. package/bin/chunk-yfjn4qn2.js +1 -0
  103. package/bin/chunk-yfkcv10v.js +2 -0
  104. package/bin/{chunk-20y3wte3.js → chunk-yj6tmjsc.js} +2 -2
  105. package/bin/chunk-z9560a6e.js +1 -0
  106. package/bin/chunk-zgsy3k3h.js +3 -0
  107. package/bin/shumai-app.html +1 -1
  108. package/bin/shumai-app.js +375 -338
  109. package/package.json +7 -7
  110. package/prisma/migrations/20260801065040_add_audit_log/migration.sql +33 -0
  111. package/prisma/migrations/20260805021613_add_asset_autofill_context/migration.sql +2 -0
  112. package/prisma/schema.prisma +25 -0
  113. package/bin/chunk-08dr94gp.js +0 -2
  114. package/bin/chunk-0t4z17qr.js +0 -2
  115. package/bin/chunk-2ynx0den.js +0 -8
  116. package/bin/chunk-31a3k77j.js +0 -2
  117. package/bin/chunk-3jdef7n4.js +0 -6
  118. package/bin/chunk-4ahve1nf.js +0 -2
  119. package/bin/chunk-4hdnrwh1.js +0 -1
  120. package/bin/chunk-4hdx2tv0.js +0 -2
  121. package/bin/chunk-4htdb0xp.js +0 -1
  122. package/bin/chunk-4p7xpfey.js +0 -2
  123. package/bin/chunk-5f81c951.js +0 -1
  124. package/bin/chunk-5zntjzxw.js +0 -3
  125. package/bin/chunk-6a2eb3b5.js +0 -3
  126. package/bin/chunk-6t3gdd7e.js +0 -2
  127. package/bin/chunk-7d5kep8c.js +0 -2
  128. package/bin/chunk-7kzqkp5z.js +0 -1
  129. package/bin/chunk-7sh6409h.js +0 -1
  130. package/bin/chunk-7y8dng8t.js +0 -2
  131. package/bin/chunk-8m6zg15c.js +0 -4
  132. package/bin/chunk-8qyke29r.js +0 -7
  133. package/bin/chunk-90et6bwm.js +0 -3
  134. package/bin/chunk-9c7fxjej.js +0 -2
  135. package/bin/chunk-a10tf0d8.js +0 -3
  136. package/bin/chunk-b10meywb.js +0 -2
  137. package/bin/chunk-b1e3tec3.js +0 -62
  138. package/bin/chunk-bdjhb77e.js +0 -2
  139. package/bin/chunk-beay9amy.js +0 -1
  140. package/bin/chunk-c3fvs0bv.js +0 -4
  141. package/bin/chunk-c5my1b3k.js +0 -7
  142. package/bin/chunk-d3s00sn0.js +0 -2
  143. package/bin/chunk-dhekxndw.js +0 -3
  144. package/bin/chunk-dwaj1yn4.js +0 -2
  145. package/bin/chunk-er1rb6yj.js +0 -1
  146. package/bin/chunk-etqpzc9e.js +0 -3
  147. package/bin/chunk-fdpjw17x.js +0 -7
  148. package/bin/chunk-gqh4ttjh.js +0 -3
  149. package/bin/chunk-hz31j0hk.js +0 -4
  150. package/bin/chunk-jm6bxtzt.js +0 -41
  151. package/bin/chunk-jstc7pka.js +0 -2
  152. package/bin/chunk-k0a35mg9.js +0 -2
  153. package/bin/chunk-k9w6mk9d.js +0 -3
  154. package/bin/chunk-m4py21f3.js +0 -2
  155. package/bin/chunk-mm1j72a8.js +0 -7
  156. package/bin/chunk-nr89225z.js +0 -2
  157. package/bin/chunk-nrf5r23d.js +0 -1
  158. package/bin/chunk-nt9tfjx6.js +0 -12
  159. package/bin/chunk-p396vw9h.js +0 -8
  160. package/bin/chunk-p9xfyqh1.js +0 -2
  161. package/bin/chunk-pj0fgb2x.js +0 -6
  162. package/bin/chunk-pp072ksj.js +0 -2
  163. package/bin/chunk-q5cdjzbv.js +0 -3
  164. package/bin/chunk-qn96vbke.js +0 -2
  165. package/bin/chunk-qvgc9e08.js +0 -3
  166. package/bin/chunk-s5rfya1p.js +0 -1
  167. package/bin/chunk-scsy69bp.js +0 -1
  168. package/bin/chunk-sf6fwvrs.js +0 -8
  169. package/bin/chunk-t2txvzkp.js +0 -3
  170. package/bin/chunk-td54rdfj.js +0 -8
  171. package/bin/chunk-vb9m47z9.js +0 -1
  172. package/bin/chunk-vf066xwh.js +0 -3
  173. package/bin/chunk-w3a50kz8.js +0 -3
  174. package/bin/chunk-w9w5301f.js +0 -4
  175. package/bin/chunk-wny0qagx.js +0 -3
  176. package/bin/chunk-wqhk76de.js +0 -14
  177. package/bin/chunk-wrz9e73c.js +0 -2
  178. package/bin/chunk-x5dcgk62.js +0 -6
  179. package/bin/chunk-xwmsxg5x.js +0 -1
  180. package/bin/chunk-y2nw8rbx.js +0 -4
  181. package/bin/chunk-y9ttm07y.js +0 -3
  182. package/bin/chunk-z0ej44ak.js +0 -3
  183. package/bin/chunk-zemgtnk0.js +0 -1
  184. package/bin/chunk-zg0vm233.js +0 -2
  185. package/bin/chunk-zhd2mkbr.js +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shumai-one/shumai",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "A fullstack AI-powered media workspace and workflow engine",
5
5
  "type": "module",
6
6
  "bin": {
@@ -27,12 +27,12 @@
27
27
  "zod": "4.4.3"
28
28
  },
29
29
  "optionalDependencies": {
30
- "@shumai-one/shumai-darwin-arm64": "0.3.2",
31
- "@shumai-one/shumai-darwin-x64": "0.3.2",
32
- "@shumai-one/shumai-linux-arm64": "0.3.2",
33
- "@shumai-one/shumai-linux-x64": "0.3.2",
34
- "@shumai-one/shumai-win32-arm64": "0.3.2",
35
- "@shumai-one/shumai-win32-x64": "0.3.2"
30
+ "@shumai-one/shumai-darwin-arm64": "0.3.3",
31
+ "@shumai-one/shumai-darwin-x64": "0.3.3",
32
+ "@shumai-one/shumai-linux-arm64": "0.3.3",
33
+ "@shumai-one/shumai-linux-x64": "0.3.3",
34
+ "@shumai-one/shumai-win32-arm64": "0.3.3",
35
+ "@shumai-one/shumai-win32-x64": "0.3.3"
36
36
  },
37
37
  "repository": {
38
38
  "type": "git",
@@ -0,0 +1,33 @@
1
+ -- CreateTable
2
+ CREATE TABLE "audit_logs" (
3
+ "id" TEXT NOT NULL,
4
+ "action" TEXT NOT NULL,
5
+ "team_id" TEXT NOT NULL,
6
+ "user_id" TEXT,
7
+ "project_id" TEXT,
8
+ "item_id" TEXT,
9
+ "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
10
+
11
+ CONSTRAINT "audit_logs_pkey" PRIMARY KEY ("id")
12
+ );
13
+
14
+ -- CreateIndex
15
+ CREATE INDEX "audit_logs_team_id_id_idx" ON "audit_logs"("team_id", "id" DESC);
16
+
17
+ -- CreateIndex
18
+ CREATE INDEX "audit_logs_user_id_idx" ON "audit_logs"("user_id");
19
+
20
+ -- CreateIndex
21
+ CREATE INDEX "audit_logs_action_idx" ON "audit_logs"("action");
22
+
23
+ -- CreateIndex
24
+ CREATE INDEX "audit_logs_item_id_idx" ON "audit_logs"("item_id");
25
+
26
+ -- AddForeignKey
27
+ ALTER TABLE "audit_logs" ADD CONSTRAINT "audit_logs_team_id_fkey" FOREIGN KEY ("team_id") REFERENCES "teams"("id") ON DELETE CASCADE ON UPDATE CASCADE;
28
+
29
+ -- AddForeignKey
30
+ ALTER TABLE "audit_logs" ADD CONSTRAINT "audit_logs_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;
31
+
32
+ -- AddForeignKey
33
+ ALTER TABLE "audit_logs" ADD CONSTRAINT "audit_logs_project_id_fkey" FOREIGN KEY ("project_id") REFERENCES "projects"("id") ON DELETE SET NULL ON UPDATE CASCADE;
@@ -0,0 +1,2 @@
1
+ -- AlterTable
2
+ ALTER TABLE "assets" ADD COLUMN "autofill_context" TEXT;
@@ -156,6 +156,7 @@ model User {
156
156
  shareLinks ShareLink[] @relation("UserToShareLink")
157
157
  apiTokens ApiToken[] @relation("UserToApiToken")
158
158
  aiUsages AiUsage[] @relation("UserToAiUsage")
159
+ auditLogs AuditLog[] @relation("UserToAuditLog")
159
160
 
160
161
  @@map("users")
161
162
  }
@@ -239,6 +240,7 @@ model Team {
239
240
  sandbox Sandbox? @relation("TeamToSandbox")
240
241
  agents Agent[] @relation("TeamToAgent")
241
242
  aiUsages AiUsage[] @relation("TeamToAiUsage")
243
+ auditLogs AuditLog[] @relation("TeamToAuditLog")
242
244
 
243
245
  @@map("teams")
244
246
  }
@@ -322,6 +324,7 @@ model Project {
322
324
  notifications Notification[] @relation("ProjectToNotification")
323
325
  shareLinks ShareLink[] @relation("ProjectToShareLink")
324
326
  collections Collection[] @relation("ProjectToCollection")
327
+ auditLogs AuditLog[] @relation("ProjectToAuditLog")
325
328
 
326
329
  @@map("projects")
327
330
  @@index([createdAt])
@@ -379,6 +382,7 @@ model Asset {
379
382
  transcodeTaskId String? @map("transcode_task_id")
380
383
  /// [MediaInfo]
381
384
  media Json?
385
+ autofillContext String? @map("autofill_context")
382
386
  isDeleted Boolean @default(false) @map("is_deleted")
383
387
  deletedAt DateTime? @map("deleted_at")
384
388
  sortIndex String? @map("sort_index")
@@ -845,3 +849,24 @@ model AiUsage {
845
849
  @@index([teamId, userId, periodStart])
846
850
  }
847
851
 
852
+ model AuditLog {
853
+ id String @id @default(ulid())
854
+ action String
855
+ teamId String @map("team_id")
856
+ userId String? @map("user_id")
857
+ projectId String? @map("project_id")
858
+ itemId String? @map("item_id")
859
+ createdAt DateTime @default(now()) @map("created_at")
860
+
861
+ team Team @relation("TeamToAuditLog", fields: [teamId], references: [id], onDelete: Cascade)
862
+ user User? @relation("UserToAuditLog", fields: [userId], references: [id], onDelete: SetNull)
863
+ project Project? @relation("ProjectToAuditLog", fields: [projectId], references: [id], onDelete: SetNull)
864
+
865
+ @@index([teamId, id(sort: Desc)])
866
+ @@index([userId])
867
+ @@index([action])
868
+ @@index([itemId])
869
+ @@map("audit_logs")
870
+ }
871
+
872
+
@@ -1,2 +0,0 @@
1
- // @bun
2
- import{gc as b,hc as E}from"./chunk-w3a50kz8.js";import{mc as S}from"./chunk-amsb41z5.js";import{nc as L,oc as M}from"./chunk-gn8snrnk.js";import{zk as I}from"./chunk-k20bhxed.js";import"./chunk-ws07a9kv.js";var P=async(B,J,D)=>{let F={api:B.api,provider:B.provider,model:B.id,output:[],stopReason:"stop",timestamp:Date.now()};try{let G=D?.apiKey;if(!G)throw Error(`No API key for provider: ${B.provider}`);let V=v(B,G,D?.headers),Q=z(B,J),X=await D?.onPayload?.(Q,B);if(X!==void 0)Q=X;let N={...D?.signal?{signal:D.signal}:{},...D?.timeoutMs!==void 0?{timeout:D.timeoutMs}:{},maxRetries:D?.maxRetries??0},{data:O,response:q}=await V.chat.completions.create(Q,N).withResponse();await D?.onResponse?.({status:q.status,headers:L(q.headers)},B);let Y=O;if(F.responseId=Y.id,Y.usage)F.usage=C(Y.usage,B);let Z=Y.choices[0];if(Z){let _=Z.message.content;if(typeof _==="string"&&_.length>0)F.output.push({type:"text",text:_});for(let $ of Z.message.images??[]){let A=typeof $.image_url==="string"?$.image_url:$.image_url?.url;if(!A?.startsWith("data:"))continue;let f=A.match(/^data:([^;]+);base64,(.+)$/);if(!f)continue;F.output.push({type:"image",mimeType:f[1],data:f[2]})}}return F}catch(G){return F.stopReason=D?.signal?.aborted?"aborted":"error",F.errorMessage=E(b(G)),F}};function v(B,J,D){return new I({apiKey:J,baseURL:B.baseUrl,dangerouslyAllowBrowser:!0,defaultHeaders:M({...B.headers,...D})})}function z(B,J){let D=J.input.map((F)=>{if(F.type==="text")return{type:"text",text:S(F.text)};return{type:"image_url",image_url:{url:`data:${F.mimeType};base64,${F.data}`}}});return{model:B.id,messages:[{role:"user",content:D}],stream:!1,modalities:B.output.includes("text")?["image","text"]:["image"]}}function C(B,J){let D=B.prompt_tokens||0,F=B.prompt_tokens_details?.cached_tokens||0,G=B.prompt_tokens_details?.cache_write_tokens||0,V=G>0?Math.max(0,F-G):F,Q=Math.max(0,D-V-G),X=B.completion_tokens||0,N={input:Q,output:X,cacheRead:V,cacheWrite:G,totalTokens:Q+X+V+G,cost:{input:J.cost.input/1e6*Q,output:J.cost.output/1e6*X,cacheRead:J.cost.cacheRead/1e6*V,cacheWrite:J.cost.cacheWrite/1e6*G,total:0}};return N.cost.total=N.cost.input+N.cost.output+N.cost.cacheRead+N.cost.cacheWrite,N}export{P as generateImages};
@@ -1,2 +0,0 @@
1
- // @bun
2
- import{uk as S,vk as T,wk as C}from"./chunk-wqhk76de.js";import"./chunk-dhekxndw.js";import{yk as D}from"./chunk-etqpzc9e.js";import{Ak as Z}from"./chunk-k20bhxed.js";import"./chunk-c3fvs0bv.js";import"./chunk-hz31j0hk.js";import{Ek as k}from"./chunk-90et6bwm.js";import{Qk as f}from"./chunk-5zntjzxw.js";import{Uk as M,Vk as V}from"./chunk-vf066xwh.js";import"./chunk-qvgc9e08.js";import"./chunk-ws07a9kv.js";var j="v1",E=new Set(["openai","openai-codex","opencode","azure-openai-responses"]);function K(G){let Q=new Map;if(!G)return Q;for(let w of G.split(",")){let W=w.trim();if(!W)continue;let[X,J]=W.split("=",2);if(!X||!J)continue;Q.set(X.trim(),J.trim())}return Q}function g(G,Q){if(Q?.azureDeploymentName)return Q.azureDeploymentName;return K(process.env.AZURE_OPENAI_DEPLOYMENT_NAME_MAP).get(G.id)||G.id}function B(G){if(G instanceof Error){let Q=G.status,w=typeof Q==="number"?Q:void 0;if(w!==void 0)return`Azure OpenAI API error (${w}): ${G.message}`;return G.message}try{return JSON.stringify(G)}catch{return String(G)}}var I=(G,Q,w)=>{let W=new V;return(async()=>{let X=g(G,w),J={role:"assistant",content:[],api:"azure-openai-responses",provider:G.provider,model:G.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 Y=w?.apiKey;if(!Y)throw Error(`No API key for provider: ${G.provider}`);let $=z(G,Y,w),q=b(G,Q,w,X),F=await w?.onPayload?.(q,G);if(F!==void 0)q=F;let L={...w?.signal?{signal:w.signal}:{},...w?.timeoutMs!==void 0?{timeout:w.timeoutMs}:{},maxRetries:w?.maxRetries??0},{data:_,response:H}=await $.responses.create(q,L).withResponse();if(await w?.onResponse?.({status:H.status,headers:k(H.headers)},G),W.push({type:"start",partial:J}),await C(_,J,W,G),w?.signal?.aborted)throw Error("Request was aborted");if(J.stopReason==="aborted"||J.stopReason==="error")throw Error("An unknown error occurred");W.push({type:"done",reason:J.stopReason,message:J}),W.end()}catch(Y){for(let $ of J.content)delete $.index,delete $.partialJson;J.stopReason=w?.signal?.aborted?"aborted":"error",J.errorMessage=B(Y),W.push({type:"error",reason:J.stopReason,error:J}),W.end()}})(),W},c=(G,Q,w)=>{let W=w?.apiKey;if(!W)throw Error(`No API key for provider: ${G.provider}`);let X=f(G,w,W),J=w?.reasoning?M(G,w.reasoning):void 0;return I(G,Q,{...X,reasoningEffort:J==="off"?void 0:J})};function P(G){let Q=G.trim().replace(/\/+$/,""),w;try{w=new URL(Q)}catch{throw Error(`Invalid Azure OpenAI base URL: ${G}`)}let W=w.hostname.endsWith(".openai.azure.com")||w.hostname.endsWith(".cognitiveservices.azure.com"),X=w.pathname.replace(/\/+$/,"");if(W&&(X===""||X==="/"||X==="/openai"))w.pathname="/openai/v1",w.search="";return w.toString().replace(/\/+$/,"")}function O(G){return`https://${G}.openai.azure.com/openai/v1`}function h(G,Q){let w=Q?.azureApiVersion||process.env.AZURE_OPENAI_API_VERSION||j,W=Q?.azureBaseUrl?.trim()||process.env.AZURE_OPENAI_BASE_URL?.trim()||void 0,X=Q?.azureResourceName||process.env.AZURE_OPENAI_RESOURCE_NAME,J=W;if(!J&&X)J=O(X);if(!J&&G.baseUrl)J=G.baseUrl;if(!J)throw Error("Azure OpenAI base URL is required. Set AZURE_OPENAI_BASE_URL or AZURE_OPENAI_RESOURCE_NAME, or pass azureBaseUrl, azureResourceName, or model.baseUrl.");return{baseUrl:P(J),apiVersion:w}}function z(G,Q,w){let W={...G.headers};if(w?.headers)Object.assign(W,w.headers);let{baseUrl:X,apiVersion:J}=h(G,w);return new Z({apiKey:Q,apiVersion:J,dangerouslyAllowBrowser:!0,defaultHeaders:W,baseURL:X})}function b(G,Q,w,W){let X=S(G,Q,E),J={model:W,input:X,stream:!0,prompt_cache_key:D(w?.sessionId)};if(w?.maxTokens)J.max_output_tokens=w?.maxTokens;if(w?.temperature!==void 0)J.temperature=w?.temperature;if(Q.tools&&Q.tools.length>0)J.tools=T(Q.tools);if(G.reasoning){if(w?.reasoningEffort||w?.reasoningSummary){let Y=w?.reasoningEffort?G.thinkingLevelMap?.[w.reasoningEffort]??w.reasoningEffort:"medium";J.reasoning={effort:Y,summary:w?.reasoningSummary||"auto"},J.include=["reasoning.encrypted_content"]}else if(G.thinkingLevelMap?.off!==null)J.reasoning={effort:G.thinkingLevelMap?.off??"none"}}return J}export{c as streamSimpleAzureOpenAIResponses,I as streamAzureOpenAIResponses};
@@ -1,8 +0,0 @@
1
- // @bun
2
- import{Tb as $Q}from"./chunk-s05f0v9t.js";import{Wb as c,Xb as XQ,Yb as l}from"./chunk-nt9tfjx6.js";import"./chunk-vy24ncn2.js";import{_b as VQ}from"./chunk-wr5byz6r.js";import{$b as g}from"./chunk-ss45w8ks.js";import{gc as GQ,hc as FQ}from"./chunk-w3a50kz8.js";import{jc as YQ}from"./chunk-6a2eb3b5.js";import"./chunk-amsb41z5.js";import{nc as u}from"./chunk-gn8snrnk.js";import{me as NQ}from"./chunk-t2txvzkp.js";import{ne as x,oe as JQ,pe as zQ}from"./chunk-a10tf0d8.js";import"./chunk-w9w5301f.js";import{cf as ZQ}from"./chunk-k9w6mk9d.js";import{df as QQ}from"./chunk-wny0qagx.js";import"./chunk-hz31j0hk.js";import"./chunk-ws07a9kv.js";function i(Q){let $=Q.filter((G)=>G!==void 0);if($.length===0)return{cleanup:()=>{}};if($.length===1)return{signal:$[0],cleanup:()=>{}};let Z=new AbortController,Y=[],F=(G)=>{if(!Z.signal.aborted)Z.abort(G.reason)};for(let G of $){if(G.aborted){F(G);break}let V=()=>F(G);G.addEventListener("abort",V,{once:!0}),Y.push({signal:G,listener:V})}return{signal:Z.signal,cleanup:()=>{for(let{signal:G,listener:V}of Y)G.removeEventListener("abort",V)}}}var PQ={ftp:21,gopher:70,http:80,https:443,ws:80,wss:443};function v(Q,$){let Z=Q.toLowerCase(),Y=Q.toUpperCase();return $?.[Z]||$?.[Y]||g(Z)||g(Y)||""}function AQ(Q){if(Q instanceof URL)return Q;try{return new URL(Q)}catch{return}}function UQ(Q,$,Z){let Y=v("no_proxy",Z).toLowerCase();if(!Y)return!0;if(Y==="*")return!1;return Y.split(/[,\s]/).every((F)=>{if(!F)return!0;let G=F.match(/^(.+):(\d+)$/),V=G?G[1]:F,j=G?Number.parseInt(G[2],10):0;if(j&&j!==$)return!0;if(!/^[.*]/.test(V))return Q!==V;if(V.startsWith("*"))V=V.slice(1);return!Q.endsWith(V)})}function wQ(Q,$){let Z=AQ(Q);if(!Z?.protocol||!Z.host)return"";let Y=Z.protocol.split(":",1)[0],F=Z.host.replace(/:\d*$/,""),G=Number.parseInt(Z.port,10)||PQ[Y]||0;if(!UQ(F,G,$))return"";let V=v(`${Y}_proxy`,$)||v("all_proxy",$);if(V&&!V.includes("://"))V=`${Y}://${V}`;return V}var CQ="Unsupported proxy protocol. SOCKS and PAC proxy URLs are not supported; use an HTTP or HTTPS proxy URL.";function a(Q,$){let Z=wQ(Q,$);if(!Z)return;let Y;try{Y=new URL(Z)}catch(F){throw Error(`Invalid proxy URL ${JSON.stringify(Z)}: ${F instanceof Error?F.message:String(F)}`)}if(Y.protocol!=="http:"&&Y.protocol!=="https:")throw Error(`${CQ} Got ${Y.protocol}`);return Y}function EQ(){if(typeof process>"u"||!(process.versions?.node||process.versions?.bun))return null;return process.getBuiltinModule?.("node:os")??null}var T=EQ(),fQ="https://chatgpt.com/backend-api",MQ="https://api.openai.com/auth",SQ=0,n=1000,TQ=60000,hQ=15000,IQ=3,jQ=new Set(["openai","openai-codex","opencode"]),xQ=1009,kQ="websocket_connection_limit_reached",bQ=new Set(["completed","incomplete","failed","cancelled","queued","in_progress"]);function gQ(Q){return/GoUsageLimitError|FreeUsageLimitError|Monthly usage limit reached|available balance|insufficient_quota|out of budget|quota exceeded|billing/i.test(Q)}function vQ(Q,$){if(Q===429&&gQ($))return!1;if(Q===429||Q===500||Q===502||Q===503||Q===504)return!0;return/rate.?limit|overloaded|service.?unavailable|upstream.?connect|connection.?refused/i.test($)}function yQ(Q){let $=Q.get("retry-after-ms");if($!==null){let G=Number($);if(Number.isFinite(G))return Math.max(0,G)}let Z=Q.get("retry-after");if(!Z)return;let Y=Number(Z);if(Number.isFinite(Y))return Math.max(0,Y*1000);let F=Date.parse(Z);if(!Number.isNaN(F))return Math.max(0,F-Date.now());return}function mQ(Q,$){let Z=$?.maxRetryDelayMs??TQ;return Z>0?Math.min(Q,Z):Q}function r(Q,$){return new Promise((Z,Y)=>{if($?.aborted){Y(Error("Request was aborted"));return}let F=setTimeout(Z,Q);$?.addEventListener("abort",()=>{clearTimeout(F),Y(Error("Request was aborted"))})})}function t(Q){if(Q===void 0)return;if(!Number.isFinite(Q)||Q<0)throw Error(`Invalid timeoutMs: ${String(Q)}`);return Math.floor(Q)}function uQ(){if(typeof process>"u"||!(process.versions?.node||process.versions?.bun))return null;return process.getBuiltinModule?.("node:zlib")??null}function cQ(Q){let $=uQ();if(!$||typeof $.zstdCompressSync!=="function")return null;try{let Z=$.zstdCompressSync(Q,{params:{[$.constants.ZSTD_c_compressionLevel]:IQ}});return new Uint8Array(Z.buffer,Z.byteOffset,Z.byteLength)}catch{return null}}var lQ=(Q,$,Z)=>{let Y=new QQ;return(async()=>{let F={role:"assistant",content:[],api:"openai-codex-responses",provider:Q.provider,model:Q.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:"stop",timestamp:Date.now()};try{let G=Z?.apiKey;if(!G)throw Error(`No API key for provider: ${Q.provider}`);let V=qZ(G),j=pQ(Q,$,Z),N=await Z?.onPayload?.(j,Q);if(N!==void 0)j=N;let X=Z?.sessionId||_Z(),W=OZ(Q.headers,Z?.headers,V,G,Z?.sessionId),J=RZ(Q.headers,Z?.headers,V,G,X),_=JSON.stringify(j),z=t(Z?.timeoutMs),q=t(Z?.websocketConnectTimeoutMs),D=Z?.transport||"auto",B=D!=="sse"&&BQ(Z?.sessionId);if(B)s(Z?.sessionId);if(D!=="sse"&&!B){let O=!1,H=!1;while(!0){O=!1;try{if(await WZ(iQ(Q.baseUrl),j,J,F,Y,Q,()=>{O=!0},z,q,Z),Z?.signal?.aborted)throw Error("Request was aborted");Y.push({type:"done",reason:F.stopReason,message:F}),Y.end();return}catch(A){let C=Z?.signal?.aborted,S=!O&&rQ(A);if(!C&&S&&!H){H=!0;continue}if(C||nQ(A)&&!S)throw A;if(zQ(F,JQ("provider_transport_failure",A,{configuredTransport:D,fallbackTransport:O?void 0:"sse",eventsEmitted:O,phase:O?"after_message_stream_start":"before_message_stream_start",requestBytes:new TextEncoder().encode(_).byteLength})),YZ(Z?.sessionId,A),O)throw A;s(Z?.sessionId);break}}}let R=cQ(_);if(R)W.set("content-encoding","zstd");let K=R??_,L,w,b=Z?.maxRetries??SQ;for(let O=0;O<=b;O++){if(Z?.signal?.aborted)throw Error("Request was aborted");try{let H=z!==void 0&&z>0?AbortSignal.timeout(z):void 0,A=i([Z?.signal,H]);try{L=await fetch(DQ(Q.baseUrl),{method:"POST",headers:W,body:K,signal:A.signal})}catch(E){if(H?.aborted&&!Z?.signal?.aborted)throw Error(`Codex SSE response headers timed out after ${z}ms`);throw E}finally{A.cleanup()}if(await Z?.onResponse?.({status:L.status,headers:u(L.headers)},Q),L.ok)break;let C=await L.text();if(O<b&&vQ(L.status,C)){let E=yQ(L.headers),HQ=E===void 0?n*2**O:L.status===429?mQ(E,Z):E;await r(HQ,Z?.signal);continue}let S=new Response(C,{status:L.status,statusText:L.statusText}),d=await BZ(S);throw Error(d.friendlyMessage||d.message)}catch(H){if(H instanceof Error){if(H.name==="AbortError"||H.message==="Request was aborted")throw Error("Request was aborted")}if(w=H instanceof Error?H:Error(String(H)),O<b&&!w.message.includes("usage limit")){let A=n*2**O;await r(A,Z?.signal);continue}throw w}}if(!L?.ok)throw w??Error("Failed after retries");if(!L.body)throw Error("No response body");if(Y.push({type:"start",partial:F}),await aQ(L,F,Y,Q,Z),Z?.signal?.aborted)throw Error("Request was aborted");Y.push({type:"done",reason:F.stopReason,message:F}),Y.end()}catch(G){for(let V of F.content)delete V.partialJson;F.stopReason=Z?.signal?.aborted?"aborted":"error",F.errorMessage=FQ(GQ(G)),Y.push({type:"error",reason:F.stopReason,error:F}),Y.end()}})(),Y},bZ=(Q,$,Z)=>{let Y=Z?.apiKey;if(!Y)throw Error(`No API key for provider: ${Q.provider}`);let F=YQ(Q,$,Z,Y),G=Z?.reasoning?ZQ(Q,Z.reasoning):void 0;return lQ(Q,$,{...F,reasoningEffort:G==="off"?void 0:G})};function pQ(Q,$,Z){let Y=$Q($,Q.compat?.supportsToolSearch??!1),F=c(Q,$,jQ,{includeSystemPrompt:!1,deferredTools:Y.deferred}),G={model:Q.id,store:!1,stream:!0,instructions:$.systemPrompt||"You are a helpful assistant.",input:F,text:{verbosity:Z?.textVerbosity||"low"},include:["reasoning.encrypted_content"],prompt_cache_key:VQ(Z?.sessionId),tool_choice:Z?.toolChoice??"auto",parallel_tool_calls:!0};if(Z?.temperature!==void 0)G.temperature=Z.temperature;if(Z?.serviceTier!==void 0)G.service_tier=Z.serviceTier;if(Y.immediate.length>0)G.tools=XQ(Y.immediate,{strict:null});if(Z?.reasoningEffort!==void 0){let V=Z.reasoningEffort==="none"?Q.thinkingLevelMap?.off??"none":Q.thinkingLevelMap?.[Z.reasoningEffort]??Z.reasoningEffort;if(V!==null)G.reasoning={effort:V,summary:Z.reasoningSummary??"auto"}}return G}function dQ(Q,$){switch($){case"flex":return 0.5;case"priority":return Q.id==="gpt-5.5"?2.5:2;default:return 1}}function KQ(Q,$,Z){let Y=dQ(Z,$);if(Y===1)return;Q.cost.input*=Y,Q.cost.output*=Y,Q.cost.cacheRead*=Y,Q.cost.cacheWrite*=Y,Q.cost.total=Q.cost.input+Q.cost.output+Q.cost.cacheRead+Q.cost.cacheWrite}function LQ(Q,$){if(Q==="default"&&($==="flex"||$==="priority"))return $;return Q??$}function DQ(Q){let Z=(Q&&Q.trim().length>0?Q:fQ).replace(/\/+$/,"");if(Z.endsWith("/codex/responses"))return Z;if(Z.endsWith("/codex"))return`${Z}/responses`;return`${Z}/codex/responses`}function iQ(Q){let $=new URL(DQ(Q));if($.protocol==="https:")$.protocol="wss:";if($.protocol==="http:")$.protocol="ws:";return $.toString()}async function aQ(Q,$,Z,Y,F){await l(WQ(oQ(Q,F?.signal)),$,Z,Y,{serviceTier:F?.serviceTier,resolveServiceTier:LQ,applyServiceTierPricing:(G,V)=>KQ(G,V,Y)})}class f extends Error{code;payload;constructor(Q,$){super(Q);this.name="CodexApiError",this.code=$?.code,this.payload=$?.payload,this.cause=$?.cause}}class k extends Error{payload;constructor(Q,$){super(Q);this.name="CodexProtocolError",this.payload=$?.payload,this.cause=$?.cause}}function nQ(Q){return Q instanceof f||Q instanceof k}function rQ(Q){return Q instanceof f&&Q.code===kQ}function tQ(Q){let $=Q.error&&typeof Q.error==="object"?Q.error:void 0;return{code:typeof Q.code==="string"?Q.code:typeof $?.code==="string"?$.code:void 0,message:typeof Q.message==="string"?Q.message:typeof $?.message==="string"?$.message:void 0}}async function*WQ(Q){for await(let $ of Q){let Z=typeof $.type==="string"?$.type:void 0;if(!Z)continue;if(Z==="error"){let{code:Y,message:F}=tQ($);throw new f(`Codex error: ${F||Y||JSON.stringify($)}`,{code:Y,payload:$})}if(Z==="response.failed"){let Y=$.response,F=Y?.error?.code,G=Y?.error?.message;throw new f(G||"Codex response failed",{code:F,payload:$})}if(Z==="response.done"||Z==="response.completed"||Z==="response.incomplete"){let Y=$.response,F=Y?{...Y,status:sQ(Y.status)}:Y;yield{...$,type:"response.completed",response:F};return}yield $}}function sQ(Q){if(typeof Q!=="string")return;return bQ.has(Q)?Q:void 0}async function*oQ(Q,$){if(!Q.body)return;let Z=Q.body.getReader(),Y=new TextDecoder,F="",G=()=>{Z.cancel().catch(()=>{})};$?.addEventListener("abort",G,{once:!0});try{while(!0){if($?.aborted)throw Error("Request was aborted");let{done:V,value:j}=await Z.read();if($?.aborted)throw Error("Request was aborted");if(V)break;F+=Y.decode(j,{stream:!0});let N=F.indexOf(`
3
-
4
- `);while(N!==-1){let X=F.slice(0,N);F=F.slice(N+2);let W=X.split(`
5
- `).filter((J)=>J.startsWith("data:")).map((J)=>J.slice(5).trim());if(W.length>0){let J=W.join(`
6
- `).trim();if(J&&J!=="[DONE]")try{yield JSON.parse(J)}catch(_){throw new k(`Invalid Codex SSE JSON: ${x(_)}`,{cause:_,payload:J})}}N=F.indexOf(`
7
-
8
- `)}}}finally{$?.removeEventListener("abort",G);try{await Z.cancel()}catch{}try{Z.releaseLock()}catch{}}}var eQ="responses_websockets=2026-02-06",QZ=300000,ZZ=3300000,P=new Map,M=new Map,I=new Set;function p(Q){let $=M.get(Q);if(!$)$={requests:0,connectionsCreated:0,connectionsReused:0,cachedContextRequests:0,storeTrueRequests:0,fullContextRequests:0,deltaRequests:0,lastInputItems:0,websocketFailures:0,sseFallbacks:0},M.set(Q,$);return $}function gZ(Q){let $=M.get(Q);return $?{...$}:void 0}function vZ(Q){if(Q){M.delete(Q),I.delete(Q);return}M.clear(),I.clear()}function $Z(Q){let $=(Z)=>{if(Z.idleTimer)clearTimeout(Z.idleTimer);U(Z.socket,1000,"debug_close")};if(Q){let Z=P.get(Q);if(Z)$(Z);P.delete(Q);return}for(let Z of P.values())$(Z);P.clear()}NQ($Z);function BQ(Q){return Q?I.has(Q):!1}function s(Q){if(!Q)return;let $=p(Q);$.sseFallbacks++,$.websocketFallbackActive=BQ(Q)}function YZ(Q,$){if(!Q)return;I.add(Q);let Z=p(Q);Z.websocketFailures++,Z.lastWebSocketError=x($),Z.websocketFallbackActive=!0}var y=null;async function GZ(Q){if(!Q&&y)return y;if(typeof process<"u"&&process.versions?.bun){let Z=class extends WebSocket{constructor(Y,F){let G={};if(Array.isArray(F)||typeof F==="string")G={protocols:F};else G={...F};let V=a(Y.toString().replace(/^wss:/,"https:").replace(/^ws:/,"http:"),Q);super(Y,{...G,...V?{proxy:V.toString()}:{}})}};if(!Q)y=Z;return Z}let $=globalThis.WebSocket;if(typeof $!=="function")return null;return $}class qQ extends Error{code;reason;wasClean;constructor(Q,$){super(Q);this.name="WebSocketCloseError",this.code=$?.code,this.reason=$?.reason,this.wasClean=$?.wasClean}}function FZ(Q){let $=Q.readyState;return typeof $==="number"?$:void 0}function h(Q){let $=FZ(Q);return $===void 0||$===1}function VZ(Q){return Date.now()-Q.createdAt>=ZZ}function U(Q,$=1000,Z="done"){try{Q.close($,Z)}catch{}}function o(Q,$){if($.idleTimer)clearTimeout($.idleTimer);$.idleTimer=setTimeout(()=>{if($.busy)return;U($.socket,1000,"idle_timeout"),P.delete(Q)},QZ)}async function m(Q,$,Z,Y=hQ,F){let G=await GZ(F);if(!G)throw Error("WebSocket transport is not available in this runtime");let V=u($);return delete V["OpenAI-Beta"],new Promise((j,N)=>{let X=!1,W,J;try{J=new G(Q,{headers:V})}catch(K){N(K instanceof Error?K:Error(String(K)));return}let _=()=>{if(W)clearTimeout(W),W=void 0;J.removeEventListener("open",q),J.removeEventListener("error",D),J.removeEventListener("close",B),Z?.removeEventListener("abort",R)},z=(K,L)=>{if(X)return;if(X=!0,_(),L)U(J,1000,L);N(K)},q=()=>{if(X)return;X=!0,_(),j(J)},D=(K)=>{z(_Q(K))},B=(K)=>{z(OQ(K))},R=()=>{z(Error("Request was aborted"),"aborted")};if(J.addEventListener("open",q),J.addEventListener("error",D),J.addEventListener("close",B),Z?.addEventListener("abort",R),Y>0)W=setTimeout(()=>{z(Error(`WebSocket connect timeout after ${Y}ms`),"connect_timeout")},Y);if(Z?.aborted)R()})}async function XZ(Q,$,Z,Y,F,G){if(!Z){let X=await m(Q,$,Y,F,G);return{socket:X,reused:!1,release:()=>U(X)}}let V=P.get(Z);if(V){if(V.idleTimer)clearTimeout(V.idleTimer),V.idleTimer=void 0;if(!V.busy&&VZ(V))U(V.socket,1000,"connection_age_limit"),P.delete(Z);else if(!V.busy&&h(V.socket))return V.busy=!0,{socket:V.socket,entry:V,reused:!0,release:({keep:X}={})=>{if(!X||!h(V.socket)){U(V.socket),P.delete(Z);return}V.busy=!1,o(Z,V)}};if(V.busy){let X=await m(Q,$,Y,F,G);return{socket:X,reused:!1,release:()=>{U(X)}}}if(!h(V.socket))U(V.socket),P.delete(Z)}let j=await m(Q,$,Y,F,G),N={socket:j,busy:!0,createdAt:Date.now()};return P.set(Z,N),{socket:j,entry:N,reused:!1,release:({keep:X}={})=>{if(!X||!h(N.socket)){if(U(N.socket),N.idleTimer)clearTimeout(N.idleTimer);if(P.get(Z)===N)P.delete(Z);return}N.busy=!1,o(Z,N)}}}function _Q(Q){if(Q&&typeof Q==="object"){let $="message"in Q?Q.message:void 0;if(typeof $==="string"&&$.length>0)return Error($);let Z="error"in Q?Q.error:void 0;if(Z instanceof Error&&Z.message.length>0)return Z;if(Z&&typeof Z==="object"&&"message"in Z){let Y=Z.message;if(typeof Y==="string"&&Y.length>0)return Error(Y)}}return Error("WebSocket error")}function OQ(Q){if(Q&&typeof Q==="object"){let $="code"in Q?Q.code:void 0,Z="reason"in Q?Q.reason:void 0,Y="wasClean"in Q?Q.wasClean:void 0,F=typeof $==="number"?` ${$}`:"",G=typeof Z==="string"&&Z.length>0?` ${Z}`:"";if(!G&&$===xQ)G=" message too big";return new qQ(`WebSocket closed${F}${G}`.trim(),{code:typeof $==="number"?$:void 0,reason:typeof Z==="string"&&Z.length>0?Z:void 0,wasClean:typeof Y==="boolean"?Y:void 0})}return Error("WebSocket closed")}async function NZ(Q){if(typeof Q==="string")return Q;if(Q instanceof ArrayBuffer)return new TextDecoder().decode(new Uint8Array(Q));if(ArrayBuffer.isView(Q)){let $=Q;return new TextDecoder().decode(new Uint8Array($.buffer,$.byteOffset,$.byteLength))}if(Q&&typeof Q==="object"&&"arrayBuffer"in Q){let Z=await Q.arrayBuffer();return new TextDecoder().decode(new Uint8Array(Z))}return null}async function*JZ(Q,$,Z){let Y=[],F=null,G=!1,V=null,j=!1,N=()=>{if(!F)return;let z=F;F=null,z()},X=(z)=>{(async()=>{let q=null;try{if(!z||typeof z!=="object"||!("data"in z))return;if(q=await NZ(z.data),!q)return;let D=JSON.parse(q),B=typeof D.type==="string"?D.type:"";if(B==="response.completed"||B==="response.done"||B==="response.incomplete")j=!0,G=!0;Y.push(D),N()}catch(D){V=new k(`Invalid Codex WebSocket JSON: ${x(D)}`,{cause:D,payload:q}),G=!0,N()}})()},W=(z)=>{V=_Q(z),G=!0,N()},J=(z)=>{if(j){G=!0,N();return}if(!V)V=OQ(z);G=!0,N()},_=()=>{V=Error("Request was aborted"),G=!0,N()};Q.addEventListener("message",X),Q.addEventListener("error",W),Q.addEventListener("close",J),$?.addEventListener("abort",_);try{while(!0){if($?.aborted)throw Error("Request was aborted");if(Y.length>0){yield Y.shift();continue}if(G)break;let z;await new Promise((q,D)=>{if(F=q,Z!==void 0&&Z>0)z=setTimeout(()=>{let B=Error(`WebSocket idle timeout after ${Z}ms`);V=B,G=!0,F=null,U(Q,1000,"idle_timeout"),D(B)},Z)}).finally(()=>{if(z)clearTimeout(z)})}if(V)throw V;if(!j)throw Error("WebSocket stream closed before response.completed")}finally{Q.removeEventListener("message",X),Q.removeEventListener("error",W),Q.removeEventListener("close",J),$?.removeEventListener("abort",_)}}function e(Q){let{input:$,previous_response_id:Z,...Y}=Q;return Y}function zZ(Q,$){return JSON.stringify(Q??[])===JSON.stringify($??[])}function jZ(Q,$){return JSON.stringify(e(Q))===JSON.stringify(e($))}function KZ(Q,$){if(!jZ(Q,$.lastRequestBody))return;let Z=Q.input??[],Y=[...$.lastRequestBody.input??[],...$.lastResponseItems];if(Z.length<Y.length)return;let F=Z.slice(0,Y.length);if(!zZ(F,Y))return;return Z.slice(Y.length)}function LZ(Q,$){let Z=Q.continuation;if(!Z)return $;let Y=KZ($,Z);if(!Y||!Z.lastResponseId)return Q.continuation=void 0,$;return{...$,previous_response_id:Z.lastResponseId,input:Y}}async function*DZ(Q,$,Z,Y){let F=!1;for await(let G of Q){if(!F)F=!0,Y(),Z.push({type:"start",partial:$});yield G}}async function WZ(Q,$,Z,Y,F,G,V,j,N,X){let{socket:W,entry:J,reused:_,release:z}=await XZ(Q,Z,X?.sessionId,X?.signal,N,X?.env),q=!0,D=X?.transport==="websocket-cached"||X?.transport==="auto",B=$,R=D&&J?LZ(J,B):B,K=X?.sessionId?p(X.sessionId):void 0;if(K){if(K.requests++,_)K.connectionsReused++;else K.connectionsCreated++;if(D)K.cachedContextRequests++;if(R.store===!0)K.storeTrueRequests++;if(K.lastInputItems=R.input?.length??0,R.previous_response_id)K.deltaRequests++,K.lastDeltaInputItems=R.input?.length??0,K.lastPreviousResponseId=R.previous_response_id;else K.fullContextRequests++,K.lastDeltaInputItems=void 0,K.lastPreviousResponseId=void 0}try{if(W.send(JSON.stringify({type:"response.create",...R})),await l(DZ(WQ(JZ(W,X?.signal,j)),Y,F,V),Y,F,G,{serviceTier:X?.serviceTier,resolveServiceTier:LQ,applyServiceTierPricing:(L,w)=>KQ(L,w,G)}),X?.signal?.aborted)q=!1;else if(D&&J&&Y.responseId){let L=c(G,{messages:[Y]},jQ,{includeSystemPrompt:!1}).filter((w)=>w.type!=="function_call_output");J.continuation={lastRequestBody:B,lastResponseId:Y.responseId,lastResponseItems:L}}}catch(L){if(J)J.continuation=void 0;throw q=!1,L}finally{z({keep:q})}}async function BZ(Q){let $=await Q.text(),Z=$||Q.statusText||"Request failed",Y;try{let G=JSON.parse($)?.error;if(G){let V=G.code||G.type||"";if(/usage_limit_reached|usage_not_included|rate_limit_exceeded/i.test(V)||Q.status===429){let j=G.plan_type?` (${G.plan_type.toLowerCase()} plan)`:"",N=G.resets_at?Math.max(0,Math.round((G.resets_at*1000-Date.now())/60000)):void 0,X=N!==void 0?` Try again in ~${N} min.`:"";Y=`You have hit your ChatGPT usage limit${j}.${X}`.trim()}Z=G.message||Y||Z}}catch{}return{message:Z,friendlyMessage:Y}}function qZ(Q){try{let $=Q.split(".");if($.length!==3)throw Error("Invalid token");let Y=JSON.parse(atob($[1]))?.[MQ]?.chatgpt_account_id;if(!Y)throw Error("No account ID in token");return Y}catch{throw Error("Failed to extract accountId from token")}}function _Z(){if(typeof globalThis.crypto?.randomUUID==="function")return globalThis.crypto.randomUUID();return`codex_${Date.now()}_${Math.random().toString(36).slice(2,10)}`}function RQ(Q,$,Z,Y){let F=new Headers(Q);for(let[V,j]of Object.entries($||{}))if(j===null)F.delete(V);else F.set(V,j);F.set("Authorization",`Bearer ${Y}`),F.set("chatgpt-account-id",Z),F.set("originator","pi");let G=T?`pi (${T.platform()} ${T.release()}; ${T.arch()})`:"pi (browser)";return F.set("User-Agent",G),F}function OZ(Q,$,Z,Y,F){let G=RQ(Q,$,Z,Y);if(G.set("OpenAI-Beta","responses=experimental"),G.set("accept","text/event-stream"),G.set("content-type","application/json"),F)G.set("session-id",F),G.set("x-client-request-id",F);return G}function RZ(Q,$,Z,Y,F){let G=RQ(Q,$,Z,Y);return G.delete("accept"),G.delete("content-type"),G.delete("OpenAI-Beta"),G.delete("openai-beta"),G.set("OpenAI-Beta",eQ),G.set("x-client-request-id",F),G.set("session-id",F),G}export{bZ as streamSimple,lQ as stream,vZ as resetOpenAICodexWebSocketDebugStats,gZ as getOpenAICodexWebSocketDebugStats,$Z as closeOpenAICodexWebSocketSessions};
@@ -1,2 +0,0 @@
1
- // @bun
2
- import{ac as I,bc as z,cc as M,dc as b,ec as B,fc as h}from"./chunk-y2nw8rbx.js";import{gc as v,hc as C}from"./chunk-w3a50kz8.js";import{jc as T}from"./chunk-6a2eb3b5.js";import{mc as G}from"./chunk-amsb41z5.js";import{oc as P}from"./chunk-gn8snrnk.js";import{bf as y,cf as j}from"./chunk-k9w6mk9d.js";import{df as S}from"./chunk-wny0qagx.js";import{Pk as O}from"./chunk-zxpef55w.js";import"./chunk-ws07a9kv.js";var k=0,F=(w,Q,J)=>{let N=new S;return(async()=>{let q={role:"assistant",content:[],api:"google-generative-ai",provider:w.provider,model:w.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 X=J?.apiKey;if(!X)throw Error(`No API key for provider: ${w.provider}`);let $=g(w,X,J?.headers),Y=a(w,Q,J),L=await J?.onPayload?.(Y,w);if(L!==void 0)Y=L;let f=await $.models.generateContentStream(Y);N.push({type:"start",partial:q});let V=null,R=q.content,Z=()=>R.length-1;for await(let _ of f){q.responseId||=_.responseId;let U=_.candidates?.[0];if(U?.content?.parts)for(let W of U.content.parts){if(W.text!==void 0){let D=I(W);if(!V||D&&V.type!=="thinking"||!D&&V.type!=="text"){if(V)if(V.type==="text")N.push({type:"text_end",contentIndex:R.length-1,content:V.text,partial:q});else N.push({type:"thinking_end",contentIndex:Z(),content:V.thinking,partial:q});if(D)V={type:"thinking",thinking:"",thinkingSignature:void 0},q.content.push(V),N.push({type:"thinking_start",contentIndex:Z(),partial:q});else V={type:"text",text:""},q.content.push(V),N.push({type:"text_start",contentIndex:Z(),partial:q})}if(V.type==="thinking")V.thinking+=W.text,V.thinkingSignature=z(V.thinkingSignature,W.thoughtSignature),N.push({type:"thinking_delta",contentIndex:Z(),delta:W.text,partial:q});else V.text+=W.text,V.textSignature=z(V.textSignature,W.thoughtSignature),N.push({type:"text_delta",contentIndex:Z(),delta:W.text,partial:q})}if(W.functionCall){if(V){if(V.type==="text")N.push({type:"text_end",contentIndex:Z(),content:V.text,partial:q});else N.push({type:"thinking_end",contentIndex:Z(),content:V.thinking,partial:q});V=null}let D=W.functionCall.id,A={type:"toolCall",id:!D||q.content.some((K)=>K.type==="toolCall"&&K.id===D)?`${W.functionCall.name}_${Date.now()}_${++k}`:D,name:W.functionCall.name||"",arguments:W.functionCall.args??{},...W.thoughtSignature&&{thoughtSignature:W.thoughtSignature}};q.content.push(A),N.push({type:"toolcall_start",contentIndex:Z(),partial:q}),N.push({type:"toolcall_delta",contentIndex:Z(),delta:JSON.stringify(A.arguments),partial:q}),N.push({type:"toolcall_end",contentIndex:Z(),toolCall:A,partial:q})}}if(U?.finishReason){if(q.stopReason=h(U.finishReason),q.content.some((W)=>W.type==="toolCall"))q.stopReason="toolUse"}if(_.usageMetadata)q.usage={input:(_.usageMetadata.promptTokenCount||0)-(_.usageMetadata.cachedContentTokenCount||0),output:(_.usageMetadata.candidatesTokenCount||0)+(_.usageMetadata.thoughtsTokenCount||0),cacheRead:_.usageMetadata.cachedContentTokenCount||0,cacheWrite:0,reasoning:_.usageMetadata.thoughtsTokenCount||0,totalTokens:_.usageMetadata.totalTokenCount||0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},y(w,q.usage)}if(V)if(V.type==="text")N.push({type:"text_end",contentIndex:Z(),content:V.text,partial:q});else N.push({type:"thinking_end",contentIndex:Z(),content:V.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");N.push({type:"done",reason:q.stopReason,message:q}),N.end()}catch(X){for(let $ of q.content)if("index"in $)delete $.index;q.stopReason=J?.signal?.aborted?"aborted":"error",q.errorMessage=C(v(X)),N.push({type:"error",reason:q.stopReason,error:q}),N.end()}})(),N},qq=(w,Q,J)=>{let N=J?.apiKey;if(!N)throw Error(`No API key for provider: ${w.provider}`);let q=T(w,Q,J,N);if(!J?.reasoning)return F(w,Q,{...q,thinking:{enabled:!1}});let X=j(w,J.reasoning),$=X==="off"?"high":X,Y=w;if(H(Y)||x(Y)||E(Y))return F(w,Q,{...q,thinking:{enabled:!0,level:u($,Y)}});return F(w,Q,{...q,thinking:{enabled:!0,budgetTokens:c(Y,$,J.thinkingBudgets)}})};function g(w,Q,J){let N={};if(w.baseUrl)N.baseUrl=w.baseUrl,N.apiVersion="";let q=P({...w.headers,...J});if(q)N.headers=q;return new O({apiKey:Q,httpOptions:Object.keys(N).length>0?N:void 0})}function a(w,Q,J={}){let N=M(w,Q),q={};if(J.temperature!==void 0)q.temperature=J.temperature;if(J.maxTokens!==void 0)q.maxOutputTokens=J.maxTokens;let X={...Object.keys(q).length>0&&q,...Q.systemPrompt&&{systemInstruction:G(Q.systemPrompt)},...Q.tools&&Q.tools.length>0&&{tools:b(Q.tools)}};if(Q.tools&&Q.tools.length>0&&J.toolChoice)X.toolConfig={functionCallingConfig:{mode:B(J.toolChoice)}};else X.toolConfig=void 0;if(J.thinking?.enabled&&w.reasoning){let Y={includeThoughts:!0};if(J.thinking.level!==void 0)Y.thinkingLevel=J.thinking.level;else if(J.thinking.budgetTokens!==void 0)Y.thinkingBudget=J.thinking.budgetTokens;X.thinkingConfig=Y}else if(w.reasoning&&J.thinking&&!J.thinking.enabled)X.thinkingConfig=m(w);if(J.signal){if(J.signal.aborted)throw Error("Request aborted");X.abortSignal=J.signal}return{model:w.id,contents:N,config:X}}function E(w){return/gemma-?4/.test(w.id.toLowerCase())}function H(w){return/gemini-3(?:\.\d+)?-pro/.test(w.id.toLowerCase())}function x(w){let Q=w.id.toLowerCase();return/gemini-3(?:\.\d+)?-flash/.test(Q)||Q==="gemini-flash-latest"||Q==="gemini-flash-lite-latest"}function m(w){if(H(w))return{thinkingLevel:"LOW"};if(x(w))return{thinkingLevel:"MINIMAL"};if(E(w))return{thinkingLevel:"MINIMAL"};return{thinkingBudget:0}}function u(w,Q){if(H(Q))switch(w){case"minimal":case"low":return"LOW";case"medium":case"high":return"HIGH"}if(E(Q))switch(w){case"minimal":case"low":return"MINIMAL";case"medium":case"high":return"HIGH"}switch(w){case"minimal":return"MINIMAL";case"low":return"LOW";case"medium":return"MEDIUM";case"high":return"HIGH"}}function c(w,Q,J){if(J?.[Q]!==void 0)return J[Q];if(w.id.includes("2.5-pro"))return{minimal:128,low:2048,medium:8192,high:32768}[Q];if(w.id.includes("2.5-flash-lite"))return{minimal:512,low:2048,medium:8192,high:24576}[Q];if(w.id.includes("2.5-flash"))return{minimal:128,low:2048,medium:8192,high:24576}[Q];return-1}export{qq as streamSimple,F as stream};
@@ -1,6 +0,0 @@
1
- // @bun
2
- import{qk as S,rk as I,sk as C}from"./chunk-y9ttm07y.js";import{tk as L}from"./chunk-jm6bxtzt.js";import{Bk as y,Ck as F}from"./chunk-c3fvs0bv.js";import"./chunk-hz31j0hk.js";import{Ek as T}from"./chunk-90et6bwm.js";import{Qk as f,Rk as h,Sk as g}from"./chunk-5zntjzxw.js";import{Tk as O,Vk as A}from"./chunk-vf066xwh.js";import{Wk as E}from"./chunk-qvgc9e08.js";import"./chunk-ws07a9kv.js";function v(Q){if(Q)return Q;if(typeof process<"u"&&process.env.PI_CACHE_RETENTION==="long")return"long";return"short"}function u(Q,Z){let Y=v(Z);if(Y==="none")return{retention:Y};let _=Y==="long"&&z(Q).supportsLongCacheRetention?"1h":void 0;return{retention:Y,cacheControl:{type:"ephemeral",..._&&{ttl:_}}}}var d="2.1.75",p=["Read","Write","Edit","Bash","Grep","Glob","AskUserQuestion","EnterPlanMode","ExitPlanMode","KillShell","NotebookEdit","Skill","Task","TaskOutput","TodoWrite","WebFetch","WebSearch"],m=new Map(p.map((Q)=>[Q.toLowerCase(),Q])),x=(Q)=>m.get(Q.toLowerCase())??Q,c=(Q,Z)=>{if(Z&&Z.length>0){let Y=Q.toLowerCase(),_=Z.find((X)=>X.name.toLowerCase()===Y);if(_)return _.name}return Q};function M(Q){if(!Q.some((X)=>X.type==="image"))return E(Q.map((X)=>X.text).join(`
3
- `));let Y=Q.map((X)=>{if(X.type==="text")return{type:"text",text:E(X.text)};return{type:"image",source:{type:"base64",media_type:X.mimeType,data:X.data}}});if(!Y.some((X)=>X.type==="text"))Y.unshift({type:"text",text:"(see attached image)"});return Y}var r="fine-grained-tool-streaming-2025-05-14",i="interleaved-thinking-2025-05-14";function z(Q){let Z=Q.provider==="fireworks",Y=Q.provider==="cloudflare-ai-gateway"&&Q.baseUrl.includes("anthropic");return{supportsEagerToolInputStreaming:Q.compat?.supportsEagerToolInputStreaming??!Z,supportsLongCacheRetention:Q.compat?.supportsLongCacheRetention??!Z,sendSessionAffinityHeaders:Q.compat?.sendSessionAffinityHeaders??!!(Z||Y),supportsCacheControlOnTools:Q.compat?.supportsCacheControlOnTools??!Z,allowEmptySignature:Q.compat?.allowEmptySignature??!1}}function H(...Q){let Z={};for(let Y of Q)if(Y)Object.assign(Z,Y);return Z}var l=new Set(["message_start","message_delta","message_stop","content_block_start","content_block_delta","content_block_stop"]);function k(Q){if(!Q.event&&Q.data.length===0)return null;let Z={event:Q.event,data:Q.data.join(`
4
- `),raw:[...Q.raw]};return Q.event=null,Q.data=[],Q.raw=[],Z}function w(Q,Z){if(Q==="")return k(Z);if(Z.raw.push(Q),Q.startsWith(":"))return null;let Y=Q.indexOf(":"),_=Y===-1?Q:Q.slice(0,Y),X=Y===-1?"":Q.slice(Y+1);if(X.startsWith(" "))X=X.slice(1);if(_==="event")Z.event=X;else if(_==="data")Z.data.push(X);return null}function a(Q){let Z=Q.indexOf("\r"),Y=Q.indexOf(`
5
- `);if(Z===-1)return Y;if(Y===-1)return Z;return Math.min(Z,Y)}function R(Q){let Z=a(Q);if(Z===-1)return null;let Y=Z+1;if(Q[Z]==="\r"&&Q[Y]===`
6
- `)Y+=1;return{line:Q.slice(0,Z),rest:Q.slice(Y)}}async function*n(Q,Z){let Y=Q.getReader(),_=new TextDecoder,X={event:null,data:[],raw:[]},$="";try{while(!0){if(Z?.aborted)throw Error("Request was aborted");let{value:V,done:N}=await Y.read();if(N)break;$+=_.decode(V,{stream:!0});let D=R($);while(D){$=D.rest;let J=w(D.line,X);if(J)yield J;D=R($)}}$+=_.decode();let W=R($);while(W){$=W.rest;let V=w(W.line,X);if(V)yield V;W=R($)}if($.length>0){let V=w($,X);if(V)yield V}let G=k(X);if(G)yield G}finally{Y.releaseLock()}}async function*s(Q,Z){if(!Q.body)throw Error("Attempted to iterate over an Anthropic response with no body");let Y=!1,_=!1;for await(let X of n(Q.body,Z)){if(X.event==="error")throw Error(X.data);if(!l.has(X.event??""))continue;try{let $=y(X.data);if($.type==="message_start")Y=!0;else if($.type==="message_stop")_=!0;yield $}catch($){let W=$ instanceof Error?$.message:String($);throw Error(`Could not parse Anthropic SSE event ${X.event}: ${W}; data=${X.data}; raw=${X.raw.join("\\n")}`)}}if(Y&&!_)throw Error("Anthropic stream ended before message_stop")}var K=(Q,Z,Y)=>{let _=new A;return(async()=>{let X={role:"assistant",content:[],api:Q.api,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 $,W;if(Y?.client)$=Y.client,W=!1;else{let q=Y?.apiKey;if(!q)throw Error(`No API key for provider: ${Q.provider}`);let P;if(Q.provider==="github-copilot"){let b=I(Z.messages);P=C({messages:Z.messages,hasImages:b})}let j=(Y?.cacheRetention??v())==="none"?void 0:Y?.sessionId,B=e(Q,q,Y?.interleavedThinking??!0,ZQ(Q,Z),Y?.headers,P,j);$=B.client,W=B.isOAuthToken}let G=QQ(Q,Z,W,Y),V=await Y?.onPayload?.(G,Q);if(V!==void 0)G=V;let N={...Y?.signal?{signal:Y.signal}:{},...Y?.timeoutMs!==void 0?{timeout:Y.timeoutMs}:{},maxRetries:Y?.maxRetries??0},D=await $.messages.create({...G,stream:!0},N).asResponse();await Y?.onResponse?.({status:D.status,headers:T(D.headers)},Q),_.push({type:"start",partial:X});let J=X.content;for await(let q of s(D,Y?.signal))if(q.type==="message_start")X.responseId=q.message.id,X.usage.input=q.message.usage.input_tokens||0,X.usage.output=q.message.usage.output_tokens||0,X.usage.cacheRead=q.message.usage.cache_read_input_tokens||0,X.usage.cacheWrite=q.message.usage.cache_creation_input_tokens||0,X.usage.totalTokens=X.usage.input+X.usage.output+X.usage.cacheRead+X.usage.cacheWrite,O(Q,X.usage);else if(q.type==="content_block_start"){if(q.content_block.type==="text"){let P={type:"text",text:"",index:q.index};X.content.push(P),_.push({type:"text_start",contentIndex:X.content.length-1,partial:X})}else if(q.content_block.type==="thinking"){let P={type:"thinking",thinking:"",thinkingSignature:"",index:q.index};X.content.push(P),_.push({type:"thinking_start",contentIndex:X.content.length-1,partial:X})}else if(q.content_block.type==="redacted_thinking"){let P={type:"thinking",thinking:"[Reasoning redacted]",thinkingSignature:q.content_block.data,redacted:!0,index:q.index};X.content.push(P),_.push({type:"thinking_start",contentIndex:X.content.length-1,partial:X})}else if(q.content_block.type==="tool_use"){let P={type:"toolCall",id:q.content_block.id,name:W?c(q.content_block.name,Z.tools):q.content_block.name,arguments:q.content_block.input??{},partialJson:"",index:q.index};X.content.push(P),_.push({type:"toolcall_start",contentIndex:X.content.length-1,partial:X})}}else if(q.type==="content_block_delta"){if(q.delta.type==="text_delta"){let P=J.findIndex((j)=>j.index===q.index),U=J[P];if(U&&U.type==="text")U.text+=q.delta.text,_.push({type:"text_delta",contentIndex:P,delta:q.delta.text,partial:X})}else if(q.delta.type==="thinking_delta"){let P=J.findIndex((j)=>j.index===q.index),U=J[P];if(U&&U.type==="thinking")U.thinking+=q.delta.thinking,_.push({type:"thinking_delta",contentIndex:P,delta:q.delta.thinking,partial:X})}else if(q.delta.type==="input_json_delta"){let P=J.findIndex((j)=>j.index===q.index),U=J[P];if(U&&U.type==="toolCall")U.partialJson+=q.delta.partial_json,U.arguments=F(U.partialJson),_.push({type:"toolcall_delta",contentIndex:P,delta:q.delta.partial_json,partial:X})}else if(q.delta.type==="signature_delta"){let P=J.findIndex((j)=>j.index===q.index),U=J[P];if(U&&U.type==="thinking")U.thinkingSignature=U.thinkingSignature||"",U.thinkingSignature+=q.delta.signature}}else if(q.type==="content_block_stop"){let P=J.findIndex((j)=>j.index===q.index),U=J[P];if(U){if(delete U.index,U.type==="text")_.push({type:"text_end",contentIndex:P,content:U.text,partial:X});else if(U.type==="thinking")_.push({type:"thinking_end",contentIndex:P,content:U.thinking,partial:X});else if(U.type==="toolCall")U.arguments=F(U.partialJson),delete U.partialJson,_.push({type:"toolcall_end",contentIndex:P,toolCall:U,partial:X})}}else if(q.type==="message_delta"){if(q.delta.stop_reason)X.stopReason=$Q(q.delta.stop_reason);if(q.usage.input_tokens!=null)X.usage.input=q.usage.input_tokens;if(q.usage.output_tokens!=null)X.usage.output=q.usage.output_tokens;if(q.usage.cache_read_input_tokens!=null)X.usage.cacheRead=q.usage.cache_read_input_tokens;if(q.usage.cache_creation_input_tokens!=null)X.usage.cacheWrite=q.usage.cache_creation_input_tokens;X.usage.totalTokens=X.usage.input+X.usage.output+X.usage.cacheRead+X.usage.cacheWrite,O(Q,X.usage)}if(Y?.signal?.aborted)throw Error("Request was aborted");if(X.stopReason==="aborted"||X.stopReason==="error")throw Error("An unknown error occurred");_.push({type:"done",reason:X.stopReason,message:X}),_.end()}catch($){for(let W of X.content)delete W.index,delete W.partialJson;X.stopReason=Y?.signal?.aborted?"aborted":"error",X.errorMessage=$ instanceof Error?$.message:JSON.stringify($),_.push({type:"error",reason:X.stopReason,error:X}),_.end()}})(),_};function t(Q,Z){let Y=Z?Q.thinkingLevelMap?.[Z]:void 0;if(typeof Y==="string")return Y;switch(Z){case"minimal":case"low":return"low";case"medium":return"medium";case"high":return"high";default:return"high"}}var EQ=(Q,Z,Y)=>{let _=Y?.apiKey;if(!_)throw Error(`No API key for provider: ${Q.provider}`);let X=f(Q,Y,_);if(!Y?.reasoning)return K(Q,Z,{...X,thinkingEnabled:!1});if(Q.compat?.forceAdaptiveThinking===!0){let W=t(Q,Y.reasoning);return K(Q,Z,{...X,thinkingEnabled:!0,effort:W})}let $=h(X.maxTokens,Q.maxTokens,Y.reasoning,Y.thinkingBudgets);return K(Q,Z,{...X,maxTokens:$.maxTokens,thinkingEnabled:!0,thinkingBudgetTokens:$.thinkingBudget})};function o(Q){return Q.includes("sk-ant-oat")}function e(Q,Z,Y,_,X,$,W){let G=Y&&Q.compat?.forceAdaptiveThinking!==!0,V=[];if(_)V.push(r);if(G)V.push(i);if(Q.provider==="cloudflare-ai-gateway")return{client:new L({apiKey:null,authToken:null,baseURL:S(Q),dangerouslyAllowBrowser:!0,defaultHeaders:H({accept:"application/json","anthropic-dangerous-direct-browser-access":"true","cf-aig-authorization":`Bearer ${Z}`,"x-api-key":null,Authorization:null,...V.length>0?{"anthropic-beta":V.join(",")}:{}},Q.headers,X)}),isOAuthToken:!1};if(Q.provider==="github-copilot")return{client:new L({apiKey:null,authToken:Z,baseURL:Q.baseUrl,dangerouslyAllowBrowser:!0,defaultHeaders:H({accept:"application/json","anthropic-dangerous-direct-browser-access":"true",...V.length>0?{"anthropic-beta":V.join(",")}:{}},Q.headers,$,X)}),isOAuthToken:!1};if(o(Z))return{client:new L({apiKey:null,authToken:Z,baseURL:Q.baseUrl,dangerouslyAllowBrowser:!0,defaultHeaders:H({accept:"application/json","anthropic-dangerous-direct-browser-access":"true","anthropic-beta":["claude-code-20250219","oauth-2025-04-20",...V].join(","),"user-agent":`claude-cli/${d}`,"x-app":"cli"},Q.headers,X)}),isOAuthToken:!0};let N=W&&z(Q).sendSessionAffinityHeaders?{"x-session-affinity":W}:{};return{client:new L({apiKey:Z,authToken:null,baseURL:Q.baseUrl,dangerouslyAllowBrowser:!0,defaultHeaders:H({accept:"application/json","anthropic-dangerous-direct-browser-access":"true",...V.length>0?{"anthropic-beta":V.join(",")}:{}},N,Q.headers,X)}),isOAuthToken:!1}}function QQ(Q,Z,Y,_){let{cacheControl:X}=u(Q,_?.cacheRetention),$={model:Q.id,messages:YQ(Z.messages,Q,Y,X,z(Q).allowEmptySignature),max_tokens:_?.maxTokens??Q.maxTokens,stream:!0};if(Y){if($.system=[{type:"text",text:"You are Claude Code, Anthropic's official CLI for Claude.",...X?{cache_control:X}:{}}],Z.systemPrompt)$.system.push({type:"text",text:E(Z.systemPrompt),...X?{cache_control:X}:{}})}else if(Z.systemPrompt)$.system=[{type:"text",text:E(Z.systemPrompt),...X?{cache_control:X}:{}}];if(_?.temperature!==void 0&&!_?.thinkingEnabled)$.temperature=_.temperature;if(Z.tools&&Z.tools.length>0){let W=z(Q);$.tools=_Q(Z.tools,Y,W.supportsEagerToolInputStreaming,W.supportsCacheControlOnTools?X:void 0)}if(Q.reasoning){if(_?.thinkingEnabled){let W=_.thinkingDisplay??"summarized";if(Q.compat?.forceAdaptiveThinking===!0){if($.thinking={type:"adaptive",display:W},_.effort)$.output_config=_.effort==="xhigh"?{effort:_.effort}:{effort:_.effort}}else $.thinking={type:"enabled",budget_tokens:_.thinkingBudgetTokens||1024,display:W}}else if(_?.thinkingEnabled===!1)$.thinking={type:"disabled"}}if(_?.metadata){let W=_.metadata.user_id;if(typeof W==="string")$.metadata={user_id:W}}if(_?.toolChoice)if(typeof _.toolChoice==="string")$.tool_choice={type:_.toolChoice};else $.tool_choice=_.toolChoice;return $}function XQ(Q){return Q.replace(/[^a-zA-Z0-9_-]/g,"_").slice(0,64)}function YQ(Q,Z,Y,_,X=!1){let $=[],W=g(Q,Z,XQ);for(let G=0;G<W.length;G++){let V=W[G];if(V.role==="user")if(typeof V.content==="string"){if(V.content.trim().length>0)$.push({role:"user",content:E(V.content)})}else{let D=V.content.map((J)=>{if(J.type==="text")return{type:"text",text:E(J.text)};else return{type:"image",source:{type:"base64",media_type:J.mimeType,data:J.data}}}).filter((J)=>{if(J.type==="text")return J.text.trim().length>0;return!0});if(D.length===0)continue;$.push({role:"user",content:D})}else if(V.role==="assistant"){let N=[];for(let D of V.content)if(D.type==="text"){if(D.text.trim().length===0)continue;N.push({type:"text",text:E(D.text)})}else if(D.type==="thinking"){if(D.redacted){N.push({type:"redacted_thinking",data:D.thinkingSignature});continue}if(D.thinking.trim().length===0)continue;if(!D.thinkingSignature||D.thinkingSignature.trim().length===0)N.push(X?{type:"thinking",thinking:E(D.thinking),signature:""}:{type:"text",text:E(D.thinking)});else N.push({type:"thinking",thinking:E(D.thinking),signature:D.thinkingSignature})}else if(D.type==="toolCall")N.push({type:"tool_use",id:D.id,name:Y?x(D.name):D.name,input:D.arguments??{}});if(N.length===0)continue;$.push({role:"assistant",content:N})}else if(V.role==="toolResult"){let N=[];N.push({type:"tool_result",tool_use_id:V.toolCallId,content:M(V.content),is_error:V.isError});let D=G+1;while(D<W.length&&W[D].role==="toolResult"){let J=W[D];N.push({type:"tool_result",tool_use_id:J.toolCallId,content:M(J.content),is_error:J.isError}),D++}G=D-1,$.push({role:"user",content:N})}}if(_&&$.length>0){let G=$[$.length-1];if(G.role==="user"){if(Array.isArray(G.content)){let V=G.content[G.content.length-1];if(V&&(V.type==="text"||V.type==="image"||V.type==="tool_result"))V.cache_control=_}else if(typeof G.content==="string")G.content=[{type:"text",text:G.content,cache_control:_}]}}return $}function ZQ(Q,Z){return!!Z.tools?.length&&!z(Q).supportsEagerToolInputStreaming}function _Q(Q,Z,Y,_){if(!Q)return[];return Q.map((X,$)=>{let W=X.parameters;return{name:Z?x(X.name):X.name,description:X.description,...Y?{eager_input_streaming:!0}:{},input_schema:{type:"object",properties:W.properties??{},required:W.required??[]},..._&&$===Q.length-1?{cache_control:_}:{}}})}function $Q(Q){switch(Q){case"end_turn":return"stop";case"max_tokens":return"length";case"tool_use":return"toolUse";case"refusal":return"error";case"pause_turn":return"stop";case"stop_sequence":return"stop";case"sensitive":return"error";default:throw Error(`Unhandled stop reason: ${Q}`)}}export{EQ as streamSimpleAnthropic,K as streamAnthropic};
@@ -1,2 +0,0 @@
1
- // @bun
2
- import{zk as b}from"./chunk-k20bhxed.js";import{Ek as q}from"./chunk-90et6bwm.js";import{Wk as A}from"./chunk-qvgc9e08.js";import"./chunk-ws07a9kv.js";var j=async(f,E,v)=>{let B={api:f.api,provider:f.provider,model:f.id,output:[],stopReason:"stop",timestamp:Date.now()};try{let D=v?.apiKey;if(!D)throw Error(`No API key for provider: ${f.provider}`);let J=L(f,D,v?.headers),G=M(f,E),N=await v?.onPayload?.(G,f);if(N!==void 0)G=N;let F={...v?.signal?{signal:v.signal}:{},...v?.timeoutMs!==void 0?{timeout:v.timeoutMs}:{},maxRetries:v?.maxRetries??0},{data:I,response:_}=await J.chat.completions.create(G,F).withResponse();await v?.onResponse?.({status:_.status,headers:q(_.headers)},f);let Q=I;if(B.responseId=Q.id,Q.usage)B.usage=S(Q.usage,f);let V=Q.choices[0];if(V){let X=V.message.content;if(typeof X==="string"&&X.length>0)B.output.push({type:"text",text:X});for(let Y of V.message.images??[]){let $=typeof Y.image_url==="string"?Y.image_url:Y.image_url?.url;if(!$?.startsWith("data:"))continue;let Z=$.match(/^data:([^;]+);base64,(.+)$/);if(!Z)continue;B.output.push({type:"image",mimeType:Z[1],data:Z[2]})}}return B}catch(D){return B.stopReason=v?.signal?.aborted?"aborted":"error",B.errorMessage=D instanceof Error?D.message:JSON.stringify(D),B}};function L(f,E,v){return new b({apiKey:E,baseURL:f.baseUrl,dangerouslyAllowBrowser:!0,defaultHeaders:{...f.headers,...v}})}function M(f,E){let v=E.input.map((B)=>{if(B.type==="text")return{type:"text",text:A(B.text)};return{type:"image_url",image_url:{url:`data:${B.mimeType};base64,${B.data}`}}});return{model:f.id,messages:[{role:"user",content:v}],stream:!1,modalities:f.output.includes("text")?["image","text"]:["image"]}}function S(f,E){let v=f.prompt_tokens||0,B=f.prompt_tokens_details?.cached_tokens||0,D=f.prompt_tokens_details?.cache_write_tokens||0,J=D>0?Math.max(0,B-D):B,G=Math.max(0,v-J-D),N=f.completion_tokens||0,F={input:G,output:N,cacheRead:J,cacheWrite:D,totalTokens:G+N+J+D,cost:{input:E.cost.input/1e6*G,output:E.cost.output/1e6*N,cacheRead:E.cost.cacheRead/1e6*J,cacheWrite:E.cost.cacheWrite/1e6*D,total:0}};return F.cost.total=F.cost.input+F.cost.output+F.cost.cacheRead+F.cost.cacheWrite,F}export{j as generateImagesOpenRouter};
@@ -1 +0,0 @@
1
- import{g as B}from"./chunk-jstc7pka.js";import"./chunk-rrxjvewm.js";import"./chunk-8e5zvy88.js";import"./chunk-nzy3pjjm.js";import"./chunk-mm1j72a8.js";import"./chunk-9c7fxjej.js";import"./chunk-zhd2mkbr.js";import"./chunk-bdjhb77e.js";import"./chunk-p9xfyqh1.js";import"./chunk-31mjcykb.js";import"./chunk-hfp4hpca.js";import"./chunk-wrz9e73c.js";import"./chunk-1nh6xgek.js";import"./chunk-3rcc5s99.js";import"./chunk-20y3wte3.js";import"./chunk-6t3gdd7e.js";import"./chunk-ejfmxjw6.js";import"./chunk-7y8dng8t.js";import"./chunk-3t7mjvdv.js";import"./chunk-z0ej44ak.js";import"./chunk-tsncwscz.js";import"./chunk-h2wsm7h3.js";import"./chunk-etces6ff.js";import"./chunk-yahb7wan.js";import"./chunk-mahxw48e.js";import"./chunk-wap08p4j.js";import"./chunk-nr89225z.js";import{Ah as w,ih as q}from"./chunk-b1e3tec3.js";import"./chunk-ws07a9kv.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 +0,0 @@
1
- // @bun
2
- import{Fk as T,Gk as A,Hk as G,Ik as C,Jk as I,Kk as M}from"./chunk-8m6zg15c.js";import{Pk as v}from"./chunk-zxpef55w.js";import{Qk as P}from"./chunk-5zntjzxw.js";import{Tk as K,Uk as O,Vk as S}from"./chunk-vf066xwh.js";import{Wk as y}from"./chunk-qvgc9e08.js";import"./chunk-ws07a9kv.js";var B=0,z=(q,V,J)=>{let N=new S;return(async()=>{let w={role:"assistant",content:[],api:"google-generative-ai",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 X=J?.apiKey;if(!X)throw Error(`No API key for provider: ${q.provider}`);let $=x(q,X,J?.headers),Y=f(q,V,J),H=await J?.onPayload?.(Y,q);if(H!==void 0)Y=H;let h=await $.models.generateContentStream(Y);N.push({type:"start",partial:w});let Q=null,R=w.content,Z=()=>R.length-1;for await(let _ of h){w.responseId||=_.responseId;let E=_.candidates?.[0];if(E?.content?.parts)for(let W of E.content.parts){if(W.text!==void 0){let D=T(W);if(!Q||D&&Q.type!=="thinking"||!D&&Q.type!=="text"){if(Q)if(Q.type==="text")N.push({type:"text_end",contentIndex:R.length-1,content:Q.text,partial:w});else N.push({type:"thinking_end",contentIndex:Z(),content:Q.thinking,partial:w});if(D)Q={type:"thinking",thinking:"",thinkingSignature:void 0},w.content.push(Q),N.push({type:"thinking_start",contentIndex:Z(),partial:w});else Q={type:"text",text:""},w.content.push(Q),N.push({type:"text_start",contentIndex:Z(),partial:w})}if(Q.type==="thinking")Q.thinking+=W.text,Q.thinkingSignature=A(Q.thinkingSignature,W.thoughtSignature),N.push({type:"thinking_delta",contentIndex:Z(),delta:W.text,partial:w});else Q.text+=W.text,Q.textSignature=A(Q.textSignature,W.thoughtSignature),N.push({type:"text_delta",contentIndex:Z(),delta:W.text,partial:w})}if(W.functionCall){if(Q){if(Q.type==="text")N.push({type:"text_end",contentIndex:Z(),content:Q.text,partial:w});else N.push({type:"thinking_end",contentIndex:Z(),content:Q.thinking,partial:w});Q=null}let D=W.functionCall.id,U={type:"toolCall",id:!D||w.content.some((j)=>j.type==="toolCall"&&j.id===D)?`${W.functionCall.name}_${Date.now()}_${++B}`:D,name:W.functionCall.name||"",arguments:W.functionCall.args??{},...W.thoughtSignature&&{thoughtSignature:W.thoughtSignature}};w.content.push(U),N.push({type:"toolcall_start",contentIndex:Z(),partial:w}),N.push({type:"toolcall_delta",contentIndex:Z(),delta:JSON.stringify(U.arguments),partial:w}),N.push({type:"toolcall_end",contentIndex:Z(),toolCall:U,partial:w})}}if(E?.finishReason){if(w.stopReason=M(E.finishReason),w.content.some((W)=>W.type==="toolCall"))w.stopReason="toolUse"}if(_.usageMetadata)w.usage={input:(_.usageMetadata.promptTokenCount||0)-(_.usageMetadata.cachedContentTokenCount||0),output:(_.usageMetadata.candidatesTokenCount||0)+(_.usageMetadata.thoughtsTokenCount||0),cacheRead:_.usageMetadata.cachedContentTokenCount||0,cacheWrite:0,totalTokens:_.usageMetadata.totalTokenCount||0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},K(q,w.usage)}if(Q)if(Q.type==="text")N.push({type:"text_end",contentIndex:Z(),content:Q.text,partial:w});else N.push({type:"thinking_end",contentIndex:Z(),content:Q.thinking,partial:w});if(J?.signal?.aborted)throw Error("Request was aborted");if(w.stopReason==="aborted"||w.stopReason==="error")throw Error("An unknown error occurred");N.push({type:"done",reason:w.stopReason,message:w}),N.end()}catch(X){for(let $ of w.content)if("index"in $)delete $.index;w.stopReason=J?.signal?.aborted?"aborted":"error",w.errorMessage=X instanceof Error?X.message:JSON.stringify(X),N.push({type:"error",reason:w.stopReason,error:w}),N.end()}})(),N},l=(q,V,J)=>{let N=J?.apiKey;if(!N)throw Error(`No API key for provider: ${q.provider}`);let w=P(q,J,N);if(!J?.reasoning)return z(q,V,{...w,thinking:{enabled:!1}});let X=O(q,J.reasoning),$=X==="off"?"high":X,Y=q;if(L(Y)||b(Y)||F(Y))return z(q,V,{...w,thinking:{enabled:!0,level:g($,Y)}});return z(q,V,{...w,thinking:{enabled:!0,budgetTokens:a(Y,$,J.thinkingBudgets)}})};function x(q,V,J){let N={};if(q.baseUrl)N.baseUrl=q.baseUrl,N.apiVersion="";if(q.headers||J)N.headers={...q.headers,...J};return new v({apiKey:V,httpOptions:Object.keys(N).length>0?N:void 0})}function f(q,V,J={}){let N=G(q,V),w={};if(J.temperature!==void 0)w.temperature=J.temperature;if(J.maxTokens!==void 0)w.maxOutputTokens=J.maxTokens;let X={...Object.keys(w).length>0&&w,...V.systemPrompt&&{systemInstruction:y(V.systemPrompt)},...V.tools&&V.tools.length>0&&{tools:C(V.tools)}};if(V.tools&&V.tools.length>0&&J.toolChoice)X.toolConfig={functionCallingConfig:{mode:I(J.toolChoice)}};else X.toolConfig=void 0;if(J.thinking?.enabled&&q.reasoning){let Y={includeThoughts:!0};if(J.thinking.level!==void 0)Y.thinkingLevel=J.thinking.level;else if(J.thinking.budgetTokens!==void 0)Y.thinkingBudget=J.thinking.budgetTokens;X.thinkingConfig=Y}else if(q.reasoning&&J.thinking&&!J.thinking.enabled)X.thinkingConfig=k(q);if(J.signal){if(J.signal.aborted)throw Error("Request aborted");X.abortSignal=J.signal}return{model:q.id,contents:N,config:X}}function F(q){return/gemma-?4/.test(q.id.toLowerCase())}function L(q){return/gemini-3(?:\.\d+)?-pro/.test(q.id.toLowerCase())}function b(q){return/gemini-3(?:\.\d+)?-flash/.test(q.id.toLowerCase())}function k(q){if(L(q))return{thinkingLevel:"LOW"};if(b(q))return{thinkingLevel:"MINIMAL"};if(F(q))return{thinkingLevel:"MINIMAL"};return{thinkingBudget:0}}function g(q,V){if(L(V))switch(q){case"minimal":case"low":return"LOW";case"medium":case"high":return"HIGH"}if(F(V))switch(q){case"minimal":case"low":return"MINIMAL";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 a(q,V,J){if(J?.[V]!==void 0)return J[V];if(q.id.includes("2.5-pro"))return{minimal:128,low:2048,medium:8192,high:32768}[V];if(q.id.includes("2.5-flash-lite"))return{minimal:512,low:2048,medium:8192,high:24576}[V];if(q.id.includes("2.5-flash"))return{minimal:128,low:2048,medium:8192,high:24576}[V];return-1}export{l as streamSimpleGoogle,z as streamGoogle};
@@ -1 +0,0 @@
1
- import{j as V}from"./chunk-k0a35mg9.js";import"./chunk-qn96vbke.js";import"./chunk-d3s00sn0.js";import"./chunk-8e5zvy88.js";import"./chunk-nzy3pjjm.js";import"./chunk-mm1j72a8.js";import"./chunk-9c7fxjej.js";import"./chunk-zhd2mkbr.js";import"./chunk-bdjhb77e.js";import"./chunk-p9xfyqh1.js";import"./chunk-31mjcykb.js";import"./chunk-hfp4hpca.js";import"./chunk-wrz9e73c.js";import"./chunk-1nh6xgek.js";import"./chunk-3rcc5s99.js";import"./chunk-20y3wte3.js";import{jf as U}from"./chunk-ph3e1bpp.js";import"./chunk-qc6dmzn0.js";import{Bf as N}from"./chunk-ve7v8wtv.js";import"./chunk-7y8dng8t.js";import"./chunk-3t7mjvdv.js";import"./chunk-z0ej44ak.js";import"./chunk-tsncwscz.js";import"./chunk-h2wsm7h3.js";import"./chunk-etces6ff.js";import"./chunk-yahb7wan.js";import"./chunk-mahxw48e.js";import"./chunk-wap08p4j.js";import{bh as K}from"./chunk-nr89225z.js";import{Ah as H,Mh as J,gh as Z,ih as q,nh as B,oh as G}from"./chunk-b1e3tec3.js";import{Xk as Y}from"./chunk-ws07a9kv.js";var W=Y(Z(),1);function _(){let{projectId:h}=$.useParams(),{teamId:v,ensureTeamIdForProject:w}=K();W.useEffect(()=>{w(h)},[h,w]);let{data:A}=G(U(h)),b=A?.rootFolder,{data:X}=B({queryKey:["folders",b],queryFn:()=>(async()=>{return await(await J.api.folders[":folderId"].$get({param:{folderId:b}})).json()})(),enabled:!!b});if(!v||!b||!X)return q(N,{});return q(V,{teamId:v,projectId:h,projectName:A.name??"",assetId:"recently-deleted",rootFolderId:b})}var $=H("/projects/$projectId/recently-deleted")({component:_});export{$ as Route};
@@ -1,2 +0,0 @@
1
- // @bun
2
- import{Rb as a}from"./chunk-5vqan9c4.js";import"./chunk-ws07a9kv.js";export default a();
@@ -1 +0,0 @@
1
- import{a as d,b as x,c as r,d as D,e as G,f as M}from"./chunk-s7qpj715.js";import{ga as m}from"./chunk-p9xfyqh1.js";import{Wa as p}from"./chunk-31mjcykb.js";import"./chunk-hfp4hpca.js";import"./chunk-20y3wte3.js";import{nf as I}from"./chunk-08mxv0sm.js";import{Bf as g}from"./chunk-ve7v8wtv.js";import{qg as u}from"./chunk-etces6ff.js";import{rg as f}from"./chunk-yahb7wan.js";import{bh as b}from"./chunk-nr89225z.js";import{Ah as L,Mh as N,Qi as S,Wh as h,dk as F,ek as P,fk as T,gh as o,hh as y,ih as q,ik as Y,jh as K,ji as z,ni as C,oh as R,qh as k,vh as v}from"./chunk-b1e3tec3.js";import{Xk as t}from"./chunk-ws07a9kv.js";var Z=t(o(),1);var s=(X)=>{if(!X)return"??";return X.split(" ").map((_)=>_[0]).slice(0,2).join("").toUpperCase()};function e(){let{projectId:X}=qq.useParams(),{teamId:_,ensureTeamIdForProject:E}=b(),j=v();Z.useEffect(()=>{E(X)},[X,E]);let{data:O}=R(I(X)),W=O?.rootFolder,[n,i]=Z.useState(240),{fileListLeftSidebarCollapsed:A,setFileListLeftSidebarCollapsed:c}=u(),{data:B,isLoading:a,fetchNextPage:Q,hasNextPage:V,isFetchingNextPage:U}=k({queryKey:["collections",X],queryFn:async({pageParam:J})=>{let $=await N.api.projects[":projectId"].collections.$get({param:{projectId:X},query:{first:"20",after:J}});if(!$.ok)throw Error("Failed to fetch collections");return await $.json()},initialPageParam:"",getNextPageParam:(J)=>J.pageInfo?.cursor||void 0,enabled:!!X}),{ref:l,inView:H}=f();Z.useEffect(()=>{if(H&&V&&!U)Q()},[H,V,U,Q]);let w=Z.useMemo(()=>B?.pages.flatMap((J)=>J.data)||[],[B]);if(!_||!W||!O)return q(g,{});return q("div",{className:"flex flex-1 flex-col bg-background min-h-0",children:K("div",{className:"flex flex-1 overflow-hidden relative",children:[!A&&q("div",{className:"md:hidden fixed inset-0 bg-black/50 z-40",onClick:()=>c(!0)}),!A&&K(y,{children:[q("div",{className:"bg-background",style:{width:n},children:q(m,{teamId:_,projectId:X,projectName:O.name??"",rootFolderId:W})}),q(p,{onResize:(J)=>{i(($)=>Math.max(180,Math.min(400,$+J)))},className:"hidden md:block"})]}),K("div",{className:"flex-1 flex flex-col min-h-0 bg-card overflow-hidden",children:[q("header",{className:"h-14 border-b flex items-center justify-between px-6 shrink-0 bg-background/50 backdrop-blur-sm sticky top-0 z-10",children:K("div",{className:"flex items-center gap-2",children:[q(z,{className:"h-5 w-5 text-primary"}),q("h1",{className:"font-bold text-lg text-foreground",children:Y.all_collections()})]})}),q("div",{className:"flex-1 overflow-y-auto p-6",children:a?q("div",{className:"flex justify-center items-center h-64",children:q("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary"})}):w.length===0?K("div",{className:"flex flex-col items-center justify-center h-64 text-muted-foreground gap-3",children:[q(S,{className:"h-10 w-10 text-muted-foreground/50"}),q("p",{children:Y.no_collections_yet()})]}):K("div",{className:"border border-border rounded-xl bg-background overflow-hidden shadow-xs",children:[K(d,{children:[q(x,{children:K(D,{className:"hover:bg-transparent bg-muted/20",children:[q(G,{className:"font-semibold px-4 py-3",children:Y.collection_name()}),q(G,{className:"font-semibold px-4 py-3",children:Y.creator()}),q(G,{className:"font-semibold px-4 py-3 w-[200px]",children:Y.created_date()})]})}),q(r,{children:w.map((J)=>K(D,{className:"hover:bg-muted/10 transition-colors cursor-pointer",onClick:()=>j({to:"/projects/$projectId/collections/$collectionId",params:{projectId:X,collectionId:J.id}}),children:[q(M,{className:"font-medium px-4 py-3.5",children:K("div",{className:"flex items-center gap-2",children:[q(z,{className:"h-4 w-4 text-primary shrink-0"}),q("span",{className:"text-foreground font-semibold hover:underline",children:J.name})]})}),q(M,{className:"px-4 py-3.5",children:K("div",{className:"flex items-center gap-2",children:[K(F,{className:"h-6 w-6",children:[J.creator?.image&&q(P,{src:J.creator.image,alt:J.creator.name,className:"object-cover"}),q(T,{className:"text-[10px]",children:s(J.creator?.name)})]}),q("span",{className:"text-sm font-medium text-foreground truncate max-w-[200px]",children:J.creator?.name||Y.unknown()})]})}),q(M,{className:"px-4 py-3.5 text-muted-foreground text-sm",children:K("div",{className:"flex items-center gap-2",children:[q(C,{className:"h-3.5 w-3.5 text-muted-foreground/70"}),q("span",{children:new Date(J.createdAt).toLocaleDateString()})]})})]},J.id))})]}),q("div",{ref:l,className:"h-10 w-full flex items-center justify-center",children:U&&q(h,{className:"h-6 w-6 animate-spin text-primary"})})]})})]})]})})}var qq=L("/projects/$projectId/collections/")({component:e});export{qq as Route};
@@ -1,3 +0,0 @@
1
- // @bun
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 Qk,y as Rk,W as Sk};
@@ -1,3 +0,0 @@
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 ic,T as jc,p as kc,k as lc};
@@ -1,2 +0,0 @@
1
- import{$f as Qf,Qf as Rf,Rf as Lf,Sf as Vf,Tf as Cf,Yf as Hf,Zf as Jf,_f as Kf,ag as Wf,dg as _f}from"./chunk-7y8dng8t.js";import{jg as Zf,kg as Gf}from"./chunk-z0ej44ak.js";import{pg as zf}from"./chunk-h2wsm7h3.js";import{qg as $f}from"./chunk-etces6ff.js";import{$g as l,Rg as Sf,Sg as a,Tg as Nf,Ug as Uf,Vg as W,Yg as qf,Zg as g,_g as p,ah as c,ch as Xf}from"./chunk-nr89225z.js";import{Gi as n,Mh as i,Ni as o,Qi as s,Th as x,Ui as ff,ak as D,hh as O,ih as f,ik as X,jh as V,ki as e,pi as j,qi as r,vh as u,xh as d}from"./chunk-b1e3tec3.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 rf};
@@ -1,2 +0,0 @@
1
- // @bun
2
- import{pc as e,qc as p,rc as t}from"./chunk-mcxsk75h.js";import"./chunk-7jjc175m.js";import"./chunk-gvn079hy.js";import"./chunk-1d22tysv.js";import"./chunk-f8cn9m28.js";import"./chunk-1dawjfk8.js";import"./chunk-ws07a9kv.js";export{t as kyselyAdapter,e as getKyselyDatabaseType,p as createKyselyAdapter};
@@ -1 +0,0 @@
1
- import{j as U}from"./chunk-k0a35mg9.js";import"./chunk-qn96vbke.js";import"./chunk-d3s00sn0.js";import"./chunk-8e5zvy88.js";import"./chunk-nzy3pjjm.js";import"./chunk-mm1j72a8.js";import"./chunk-9c7fxjej.js";import"./chunk-zhd2mkbr.js";import"./chunk-bdjhb77e.js";import"./chunk-p9xfyqh1.js";import"./chunk-31mjcykb.js";import"./chunk-hfp4hpca.js";import"./chunk-wrz9e73c.js";import"./chunk-1nh6xgek.js";import"./chunk-3rcc5s99.js";import"./chunk-20y3wte3.js";import{ef as N}from"./chunk-xawwxdq9.js";import"./chunk-qc6dmzn0.js";import{Bf as K}from"./chunk-ve7v8wtv.js";import"./chunk-7y8dng8t.js";import"./chunk-3t7mjvdv.js";import"./chunk-z0ej44ak.js";import"./chunk-tsncwscz.js";import"./chunk-h2wsm7h3.js";import"./chunk-etces6ff.js";import"./chunk-yahb7wan.js";import"./chunk-mahxw48e.js";import"./chunk-wap08p4j.js";import{bh as J}from"./chunk-nr89225z.js";import{Ah as G,Mh as H,gh as Z,ih as q,nh as B,oh as D}from"./chunk-b1e3tec3.js";import{Xk as Y}from"./chunk-ws07a9kv.js";var V=Y(Z(),1);function _(){let{projectId:h,folderId:W}=z.useParams(),{teamId:v,ensureTeamIdForProject:w}=J();V.useEffect(()=>{w(h)},[h,w]);let{data:A}=D(N(h)),b=A?.rootFolder,{data:X}=B({queryKey:["folders",b],queryFn:()=>(async()=>{return await(await H.api.folders[":folderId"].$get({param:{folderId:b}})).json()})(),enabled:!!b});if(!v||!b||!X)return q(K,{});return q(U,{teamId:v,projectId:h,projectName:A.name??"",assetId:W,rootFolderId:b})}var z=G("/projects/$projectId/folders/$folderId")({component:_});export{z as Route};
@@ -1 +0,0 @@
1
- import{g as q}from"./chunk-jstc7pka.js";import"./chunk-rrxjvewm.js";import"./chunk-8e5zvy88.js";import"./chunk-nzy3pjjm.js";import"./chunk-mm1j72a8.js";import"./chunk-9c7fxjej.js";import"./chunk-zhd2mkbr.js";import"./chunk-bdjhb77e.js";import"./chunk-p9xfyqh1.js";import"./chunk-31mjcykb.js";import"./chunk-hfp4hpca.js";import"./chunk-wrz9e73c.js";import"./chunk-1nh6xgek.js";import"./chunk-3rcc5s99.js";import"./chunk-20y3wte3.js";import"./chunk-6t3gdd7e.js";import"./chunk-ejfmxjw6.js";import"./chunk-7y8dng8t.js";import"./chunk-3t7mjvdv.js";import"./chunk-z0ej44ak.js";import"./chunk-tsncwscz.js";import"./chunk-h2wsm7h3.js";import"./chunk-etces6ff.js";import"./chunk-yahb7wan.js";import"./chunk-mahxw48e.js";import"./chunk-wap08p4j.js";import"./chunk-nr89225z.js";import{Ah as k,ih as f}from"./chunk-b1e3tec3.js";import"./chunk-ws07a9kv.js";function w(){let{shareId:v}=A.useParams();return f(q,{shareId:v})}var A=k("/share/$shareId/")({component:w});export{A as Route};
@@ -1,2 +0,0 @@
1
- import{$j as A,Lj as k,Zj as F,ak as V,ih as t,jh as R}from"./chunk-b1e3tec3.js";import{_k as l}from"./chunk-ws07a9kv.js";function D(a,b){var f=a.length;a.push(b);a:for(;0<f;){var g=f-1>>>1,d=a[g];if(0<q(d,b))a[g]=b,a[f]=d,f=g;else break a}}function C(a){return a.length===0?null:a[0]}function H(a){if(a.length===0)return null;var b=a[0],f=a.pop();if(f!==b){a[0]=f;a:for(var g=0,d=a.length,Z=d>>>1;g<Z;){var $=2*(g+1)-1,P=a[$],N=$+1,G=a[N];if(0>q(P,f))N<d&&0>q(G,P)?(a[g]=G,a[N]=f,g=N):(a[g]=P,a[$]=f,g=$);else if(N<d&&0>q(G,f))a[g]=G,a[N]=f,g=N;else break a}}return b}function q(a,b){var f=a.sortIndex-b.sortIndex;return f!==0?f:a.id-b.id}function S(a){for(var b=C(o);b!==null;){if(b.callback===null)H(o);else if(b.startTime<=a)H(o),b.sortIndex=b.expirationTime,D(w,b);else break;b=C(o)}}function c(a){if(K=!1,S(a),!J)if(C(w)!==null)J=!0,E||(E=!0,B());else{var b=C(o);b!==null&&I(c,b.startTime-a)}}function m(){return n?!0:_()-L<p?!1:!0}function U(){if(n=!1,E){var a=_();L=a;var b=!0;try{a:{J=!1,K&&(K=!1,j(X),X=-1),T=!0;var f=O;try{t:{S(a);for(z=C(w);z!==null&&!(z.expirationTime>a&&m());){var g=z.callback;if(typeof g==="function"){z.callback=null,O=z.priorityLevel;var d=g(z.expirationTime<=a);if(a=_(),typeof d==="function"){z.callback=d,S(a),b=!0;break t}z===C(w)&&H(w),S(a)}else H(w);z=C(w)}if(z!==null)b=!0;else{var Z=C(o);Z!==null&&I(c,Z.startTime-a),b=!1}}break a}finally{z=null,O=f,T=!1}b=void 0}}finally{b?B():E=!1}}}function I(a,b){X=u(function(){a(_())},b)}var _=void 0,M,v,W,w,o,h=1,z=null,O=3,T=!1,J=!1,K=!1,n=!1,u,j,s,E=!1,X=-1,p=5,L=-1,B,Q,y,i=5,r=1,e=4,aa=3,ta=2,ba=function(a){a.callback=null},fa=function(){return O},ga=function(){n=!0},da=function(a,b){switch(a){case 1:case 2:case 3:case 4:case 5:break;default:a=3}var f=O;O=a;try{return b()}finally{O=f}},za=function(a,b,f){var g=_();switch(typeof f==="object"&&f!==null?(f=f.delay,f=typeof f==="number"&&0<f?g+f:g):f=g,a){case 1:var d=-1;break;case 2:d=250;break;case 5:d=1073741823;break;case 4:d=1e4;break;default:d=5000}return d=f+d,a={id:h++,callback:b,priorityLevel:a,startTime:f,expirationTime:d,sortIndex:-1},f>g?(a.sortIndex=f,D(o,a),C(w)===null&&a===C(o)&&(K?(j(X),X=-1):K=!0,I(c,f-g))):(a.sortIndex=d,D(w,a),J||T||(J=!0,E||(E=!0,B()))),a},Ca;var wa=l(()=>{if(typeof performance==="object"&&typeof performance.now==="function")M=performance,_=function(){return M.now()};else v=Date,W=v.now(),_=function(){return v.now()-W};w=[],o=[],u=typeof setTimeout==="function"?setTimeout:null,j=typeof clearTimeout==="function"?clearTimeout:null,s=typeof setImmediate<"u"?setImmediate:null;if(typeof s==="function")B=function(){s(U)};else if(typeof MessageChannel<"u")Q=new MessageChannel,y=Q.port2,Q.port1.onmessage=U,B=function(){y.postMessage(null)};else B=function(){u(U,0)};Ca=m});function Na({className:a,orientation:b="horizontal",...f}){return t(F.Root,{"data-slot":"tabs","data-orientation":b,orientation:b,className:V("group/tabs flex gap-2 data-[orientation=horizontal]:flex-col",a),...f})}var x=k("group/tabs-list inline-flex w-fit items-center justify-center rounded-lg p-[3px] text-muted-foreground group-data-[orientation=horizontal]/tabs:h-9 group-data-[orientation=vertical]/tabs:h-fit group-data-[orientation=vertical]/tabs:flex-col data-[variant=line]:rounded-none",{variants:{variant:{default:"bg-muted",line:"gap-1 bg-transparent"}},defaultVariants:{variant:"default"}});function Va({className:a,variant:b="default",...f}){return t(F.List,{"data-slot":"tabs-list","data-variant":b,className:V(x({variant:b}),a),...f})}function Aa({className:a,...b}){return t(F.Trigger,{"data-slot":"tabs-trigger",className:V("relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap text-foreground/60 transition-all group-data-[orientation=vertical]/tabs:w-full group-data-[orientation=vertical]/tabs:justify-start hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 group-data-[variant=default]/tabs-list:data-[state=active]:shadow-sm group-data-[variant=line]/tabs-list:data-[state=active]:shadow-none dark:text-muted-foreground dark:hover:text-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4","group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-[state=active]:bg-transparent dark:group-data-[variant=line]/tabs-list:data-[state=active]:border-transparent dark:group-data-[variant=line]/tabs-list:data-[state=active]:bg-transparent","data-[state=active]:bg-background data-[state=active]:text-foreground dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 dark:data-[state=active]:text-foreground","after:absolute after:bg-foreground after:opacity-0 after:transition-opacity group-data-[orientation=horizontal]/tabs:after:inset-x-0 group-data-[orientation=horizontal]/tabs:after:bottom-[-5px] group-data-[orientation=horizontal]/tabs:after:h-0.5 group-data-[orientation=vertical]/tabs:after:inset-y-0 group-data-[orientation=vertical]/tabs:after:-right-1 group-data-[orientation=vertical]/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-[state=active]:after:opacity-100",a),...b})}function Oa({className:a,...b}){return t(F.Content,{"data-slot":"tabs-content",className:V("flex-1 outline-none",a),...b})}function Ka({delayDuration:a=0,...b}){return t(A.Provider,{"data-slot":"tooltip-provider",delayDuration:a,...b})}function Xa({...a}){return t(A.Root,{"data-slot":"tooltip",...a})}function Za({...a}){return t(A.Trigger,{"data-slot":"tooltip-trigger",...a})}function $a({className:a,sideOffset:b=0,children:f,...g}){return t(A.Portal,{children:R(A.Content,{"data-slot":"tooltip-content",sideOffset:b,className:V("z-50 w-fit origin-(--radix-tooltip-content-transform-origin) animate-in rounded-md bg-foreground px-3 py-1.5 text-xs text-balance text-background fade-in-0 zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95",a),...g,children:[f,t(A.Arrow,{className:"z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground"})]})})}var Y={viewBox:"0 -960 960 960",fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"},qa=(a)=>t("svg",{...Y,...a,children:t("path",{d:"M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Zm120-80v-560H200v560h120Zm80 0h360v-560H400v560Z"})}),va=(a)=>t("svg",{...Y,...a,children:t("path",{d:"M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Zm360-80v-560H200v560h360Zm200 0v-560H640v560h120Z"})}),Sa=(a)=>t("svg",{...Y,...a,children:t("path",{d:"M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Zm560-80v-560H400v560h360Z"})}),Qa=(a)=>t("svg",{...Y,...a,children:t("path",{d:"M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Zm360-80v-560H200v560h360Z"})}),Ha=(a)=>R("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",...a,children:[t("path",{d:"M12 8V4H8"}),t("path",{d:"M6 7H18A3 3 0 0 1 21 10V18A3 3 0 0 1 18 21H6A3 3 0 0 1 3 18V10A3 3 0 0 1 6 7ZM8 13V15A1 1 0 0 0 10 15V13A1 1 0 0 0 8 13ZM14 13V15A1 1 0 0 0 16 15V13A1 1 0 0 0 14 13Z",fill:"currentColor",stroke:"none"}),t("path",{d:"M2 14h2"}),t("path",{d:"M20 14h2"})]}),Pa=(a)=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:30,height:30,viewBox:"120 -792 720 720",fill:"none","aria-hidden":"true",focusable:"false",...a,children:t("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M 160 -180 v -72 h 80 v -252 q 0 -74.7 50 -132.75 T 420 -712.8 v -25.2 q 0 -22.5 17.5 -38.25 T 480 -792 q 25 0 42.5 15.75 T 540 -738 v 25.2 q 80 18 130 76.05 T 720 -504 v 252 h 80 v 72 H 160 Z M 480 -72 q -33 0 -56.5 -21.15 T 400 -144 h 160 q 0 29.7 -23.5 50.85 T 480 -72 Z",fill:"currentColor"})}),Ua=(a)=>R("svg",{xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",focusable:"false",...a,children:[t("path",{d:"M10.77 10.377a1 1 0 0 0-.132.437l-.105 1.665a.5.5 0 0 0 .793.436l1.32-.96a1 1 0 0 0 .278-.309l3.912-6.775a1.25 1.25 0 1 0-2.165-1.25l-3.901 6.756Z",fill:"currentColor"}),t("path",{d:"M11.016 6.75a.758.758 0 0 1-.758.748c-2.938 0-4.882 1.71-5.517 3.95-.708 2.499.245 4.459 1.979 5.851 1.767 1.42 4.31 2.203 6.547 2.203.415 0 .749.335.745.748a.758.758 0 0 1-.758.748c-2.536 0-5.421-.873-7.485-2.531-2.098-1.686-3.38-4.225-2.475-7.414.818-2.883 3.354-5.051 6.977-5.051.415 0 .749.335.745.748Z",fill:"currentColor"}),t("path",{d:"M17.147 8.315a.767.767 0 0 1 1.058-.168c1.666 1.188 2.508 2.542 2.733 3.876a4.5 4.5 0 0 1-.805 3.392c-.919 1.434-2.714 2.074-4.479 2.185-1.799.113-3.78-.302-5.292-1.216a.733.733 0 0 1-.242-1.022.768.768 0 0 1 1.042-.246c1.216.734 2.881 1.096 4.409 1 1.553-.097 2.755-.647 3.292-1.5l.015-.022.015-.021a3.025 3.025 0 0 0 .553-2.294c-.148-.876-.72-1.915-2.137-2.926a.733.733 0 0 1-.162-1.038Z",fill:"currentColor"})]}),Da=(a)=>{return R("svg",{viewBox:"0 0 100 100",fill:"none",xmlns:"http://www.w3.org/2000/svg",...a,children:[t("defs",{children:t("clipPath",{id:"bg-clip",children:t("rect",{x:"5",y:"5",width:"90",height:"90",rx:"22"})})}),t("rect",{x:"5",y:"5",width:"90",height:"90",rx:"22",fill:"#D95A66"}),t("path",{d:"M 35 75 L 65 75 L 80 60 L 75 30 L 175 130 L 135 175 Z",fill:"#A8384D",clipPath:"url(#bg-clip)"}),t("path",{d:"M 25 30 Q 38 36 50 42 L 35 55 L 35 75 L 20 60 Z",fill:"#FDF0D5"}),t("path",{d:"M 50 42 Q 62 36 75 30 L 80 60 L 65 75 L 65 55 Z",fill:"#E77A65"}),t("path",{d:"M 35 75 L 65 75 L 65 55 L 50 42 L 35 55 Z",fill:"#F5B895"}),t("path",{d:"M 50 42 Q 38 36 25 30 Q 38 26 50 20 Q 62 26 75 30 Q 62 36 50 42 Z",fill:"#F4B8B8"}),t("path",{d:"M 50 25 L 42 30 L 50 35 Z",fill:"#E57A5F"}),t("path",{d:"M 50 25 L 58 30 L 50 35 Z",fill:"#C2523C"})]})},Ma=(a)=>t("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"24 24 152 152",fill:"none","aria-hidden":"true",focusable:"false",...a,children:t("path",{d:"M 44 170 L 44 100 L 24 100 L 100 30 L 126 54 L 126 36 L 142 36 L 142 69 L 176 100 L 156 100 L 156 170 L 120 170 L 120 136 A 20 20 0 0 0 80 136 L 80 170 Z",fill:"currentColor"})});function Wa({uploading:a=!1,className:b="",...f}){return R("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"15 15 70 70",width:30,height:30,className:`${b} ${a?"animate-upload-breathing":""}`,"aria-hidden":"true",focusable:"false",style:a?{transformOrigin:"center"}:void 0,...f,children:[a&&t("defs",{children:R("linearGradient",{id:"upload-gradient",x1:"0%",y1:"0%",x2:"100%",y2:"100%",children:[t("stop",{offset:"0%",stopColor:"#3b82f6",children:t("animate",{attributeName:"stop-color",values:"#3b82f6;#ec4899;#8b5cf6;#3b82f6",dur:"3s",repeatCount:"indefinite"})}),t("stop",{offset:"50%",stopColor:"#8b5cf6",children:t("animate",{attributeName:"stop-color",values:"#8b5cf6;#3b82f6;#ec4899;#8b5cf6",dur:"3s",repeatCount:"indefinite"})}),t("stop",{offset:"100%",stopColor:"#ec4899",children:t("animate",{attributeName:"stop-color",values:"#ec4899;#8b5cf6;#3b82f6;#ec4899",dur:"3s",repeatCount:"indefinite"})})]})}),t("path",{d:"M 44.1 75 H 30 A 15 15 0 0 1 30 45 A 20 20 0 0 1 70 45 A 15 15 0 0 1 70 75 H 55.9 V 60.2 H 61.9 L 50 45.3 L 38.1 60.2 H 44.1 Z",fill:a?"url(#upload-gradient)":"currentColor"})]})}
2
- export{_ as Df,i as Ef,r as Ff,e as Gf,aa as Hf,ta as If,ba as Jf,fa as Kf,ga as Lf,da as Mf,za as Nf,Ca as Of,wa as Pf,Ka as Qf,Xa as Rf,Za as Sf,$a as Tf,Na as Uf,Va as Vf,Aa as Wf,Oa as Xf,qa as Yf,va as Zf,Sa as _f,Qa as $f,Ha as ag,Pa as bg,Ua as cg,Da as dg,Ma as eg,Wa as fg};
@@ -1,4 +0,0 @@
1
- // @bun
2
- import{Lk as L,Nk as w}from"./chunk-zxpef55w.js";import{Sk as Z}from"./chunk-5zntjzxw.js";import{Wk as J}from"./chunk-qvgc9e08.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
- `),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 Fk,B as Gk,R as Hk,C as Ik,k as Jk,P as Kk};
@@ -1,7 +0,0 @@
1
- // @bun
2
- import{Ub as m,Vb as c}from"./chunk-hrzm70wg.js";import{_b as s}from"./chunk-wr5byz6r.js";import{$b as d}from"./chunk-ss45w8ks.js";import{gc as l,hc as a}from"./chunk-w3a50kz8.js";import{jc as i,lc as n}from"./chunk-6a2eb3b5.js";import{mc as w}from"./chunk-amsb41z5.js";import{nc as p}from"./chunk-gn8snrnk.js";import{Ze as T}from"./chunk-w9w5301f.js";import{bf as g,cf as r}from"./chunk-k9w6mk9d.js";import{df as k}from"./chunk-wny0qagx.js";import{zk as h}from"./chunk-k20bhxed.js";import"./chunk-hz31j0hk.js";import"./chunk-ws07a9kv.js";function C(J,X){if(!J)return!1;let Q=X.toLowerCase();for(let[Y,_]of Object.entries(J))if(Y.toLowerCase()===Q&&_!==null&&_.trim().length>0)return!0;return!1}function t(J,X,Q){if(X)return X;if(C(Q,"authorization")||C(Q,"cf-aig-authorization"))return"unused";throw Error(`No API key for provider: ${J}`)}function $J(J){for(let X of J){if(X.role==="toolResult")return!0;if(X.role==="assistant"){if(X.content.some((Q)=>Q.type==="toolCall"))return!0}}return!1}function u(J){return J.type==="text"}function qJ(J){return J.type==="thinking"}function ZJ(J){return J.type==="toolCall"}function KJ(J){return J.type==="image"}function jJ(J){if(typeof J!=="object"||J===null)return!1;let X=J;return X.type==="reasoning.encrypted"&&typeof X.id==="string"&&X.id.length>0&&typeof X.data==="string"&&X.data.length>0}function e(J,X){if(J)return J;if(d("PI_CACHE_RETENTION",X)==="long")return"long";return"short"}var zJ=(J,X,Q)=>{let Y=new k;return(async()=>{let _={role:"assistant",content:[],api:J.api,provider:J.provider,model:J.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:"stop",timestamp:Date.now()};try{let H=t(J.provider,Q?.apiKey,Q?.headers),K=f(J),$=e(Q?.cacheRetention,Q?.env),q=$==="none"?void 0:Q?.sessionId,j=HJ(J,X,H,Q?.headers,q,K),V=LJ(J,X,Q,K,$),O=await Q?.onPayload?.(V,J);if(O!==void 0)V=O;let P={...Q?.signal?{signal:Q.signal}:{},...Q?.timeoutMs!==void 0?{timeout:Q.timeoutMs}:{},maxRetries:Q?.maxRetries??0},{data:A,response:F}=await j.chat.completions.create(V,P).withResponse();await Q?.onResponse?.({status:F.status,headers:p(F.headers)},J),Y.push({type:"start",partial:_});let E=null,L=null,G=!1,v=new Map,U=new Map,I=new Map,B=_.content,y=(Z)=>B.indexOf(Z),JJ=(Z)=>{let z=y(Z);if(z===-1)return;if(Z.type==="text")Y.push({type:"text_end",contentIndex:z,content:Z.text,partial:_});else if(Z.type==="thinking")Y.push({type:"thinking_end",contentIndex:z,content:Z.thinking,partial:_});else if(Z.type==="toolCall")Z.arguments=T(Z.partialArgs),delete Z.partialArgs,delete Z.streamIndex,Y.push({type:"toolcall_end",contentIndex:z,toolCall:Z,partial:_})},QJ=()=>{if(!E)E={type:"text",text:""},B.push(E),Y.push({type:"text_start",contentIndex:y(E),partial:_});return E},XJ=(Z)=>{if(!L)L={type:"thinking",thinking:"",thinkingSignature:Z},B.push(L),Y.push({type:"thinking_start",contentIndex:y(L),partial:_});return L},YJ=(Z)=>{if(!Z.id)return;let z=I.get(Z.id);if(z)Z.thoughtSignature=z,I.delete(Z.id)},_J=(Z)=>{let z=typeof Z.index==="number"?Z.index:void 0,N=z!==void 0?v.get(z):void 0;if(!N&&Z.id)N=U.get(Z.id);if(!N){if(N={type:"toolCall",id:Z.id||"",name:Z.function?.name||"",arguments:{},partialArgs:"",streamIndex:z},z!==void 0)v.set(z,N);if(Z.id)U.set(Z.id,N);B.push(N),Y.push({type:"toolcall_start",contentIndex:y(N),partial:_})}if(z!==void 0&&N.streamIndex===void 0)N.streamIndex=z,v.set(z,N);if(Z.id)U.set(Z.id,N);return YJ(N),N};for await(let Z of A){if(!Z||typeof Z!=="object")continue;if(_.responseId||=Z.id,typeof Z.model==="string"&&Z.model.length>0&&Z.model!==J.id)_.responseModel||=Z.model;if(Z.usage)_.usage=b(Z.usage,J);let z=Array.isArray(Z.choices)?Z.choices[0]:void 0;if(!z)continue;if(!Z.usage&&z.usage)_.usage=b(z.usage,J);if(z.finish_reason){let N=yJ(z.finish_reason);if(_.stopReason=N.stopReason,N.errorMessage)_.errorMessage=N.errorMessage;G=!0}if(z.delta){if(z.delta.content!==null&&z.delta.content!==void 0&&z.delta.content.length>0){let W=QJ();W.text+=z.delta.content,Y.push({type:"text_delta",contentIndex:y(W),delta:z.delta.content,partial:_})}let N=["reasoning_content","reasoning","reasoning_text"],R=z.delta,M=null;for(let W of N){let S=R[W];if(typeof S==="string"&&S.length>0){M=W;break}}if(M){let W=R[M];if(typeof W==="string"&&W.length>0){let S=J.provider==="opencode-go"&&M==="reasoning"?"reasoning_content":M,D=XJ(S);D.thinking+=W,Y.push({type:"thinking_delta",contentIndex:y(D),delta:W,partial:_})}}if(z?.delta?.tool_calls)for(let W of z.delta.tool_calls){let S=_J(W);if(!S.id&&W.id)S.id=W.id,U.set(W.id,S);if(!S.name&&W.function?.name)S.name=W.function.name;let D="";if(W.function?.arguments)D=W.function.arguments,S.partialArgs=(S.partialArgs??"")+W.function.arguments,S.arguments=T(S.partialArgs);Y.push({type:"toolcall_delta",contentIndex:y(S),delta:D,partial:_})}let x=z.delta.reasoning_details;if(Array.isArray(x)){for(let W of x)if(jJ(W)){let S=JSON.stringify(W),D=U.get(W.id);if(D)D.thoughtSignature=S;else I.set(W.id,S)}}}}for(let Z of B)JJ(Z);if(Q?.signal?.aborted)throw Error("Request was aborted");if(_.stopReason==="aborted")throw Error("Request was aborted");if(_.stopReason==="error")throw Error(_.errorMessage||"Provider returned an error stop reason");if(!G)throw Error("Stream ended without finish_reason");Y.push({type:"done",reason:_.stopReason,message:_}),Y.end()}catch(H){for(let $ of _.content)delete $.index,delete $.partialArgs,delete $.streamIndex;_.stopReason=Q?.signal?.aborted?"aborted":"error",_.errorMessage=a(l(H));let K=H?.error?.metadata?.raw;if(K&&!_.errorMessage.includes(String(K)))_.errorMessage+=`
3
- ${K}`;Y.push({type:"error",reason:_.stopReason,error:_}),Y.end()}})(),Y},hJ=(J,X,Q)=>{t(J.provider,Q?.apiKey,Q?.headers);let Y=i(J,X,Q,Q?.apiKey),_=Q?.reasoning?r(J,Q.reasoning):void 0,H=_==="off"?void 0:_,K=Q?.toolChoice;return zJ(J,X,{...Y,reasoningEffort:H,toolChoice:K})};function HJ(J,X,Q,Y,_,H=f(J)){let K={...J.headers};if(J.provider==="github-copilot"){let $=m(X.messages),q=c({messages:X.messages,hasImages:$});Object.assign(K,q)}if(_&&H.sendSessionAffinityHeaders)if(H.sessionAffinityFormat==="openrouter")K["x-session-id"]=_;else{if(H.sessionAffinityFormat==="openai")K.session_id=_;K["x-client-request-id"]=_,K["x-session-affinity"]=_}if(Y)Object.assign(K,Y);return new h({apiKey:Q,baseURL:J.baseUrl,dangerouslyAllowBrowser:!0,defaultHeaders:K})}function LJ(J,X,Q,Y=f(J),_=e(Q?.cacheRetention,Q?.env)){let H=EJ(J,X,Y),K=GJ(Y,_),$={model:J.id,messages:H,stream:!0,prompt_cache_key:J.baseUrl.includes("api.openai.com")&&_!=="none"||_==="long"&&Y.supportsLongCacheRetention?s(Q?.sessionId):void 0,prompt_cache_retention:_==="long"&&Y.supportsLongCacheRetention?"24h":void 0};if(Y.supportsUsageInStreaming!==!1)$.stream_options={include_usage:!0};if(Y.supportsStore)$.store=!1;if(Q?.maxTokens)if(Y.maxTokensField==="max_tokens")$.max_tokens=Q.maxTokens;else $.max_completion_tokens=Q.maxTokens;if(Q?.temperature!==void 0)$.temperature=Q.temperature;if(X.tools&&X.tools.length>0){if($.tools=DJ(X.tools,Y),Y.zaiToolStream)$.tool_stream=!0}else if($J(X.messages))$.tools=[];if(K)NJ(H,$.tools,K);if(Q?.toolChoice)$.tool_choice=Q.toolChoice;if(Y.thinkingFormat==="zai"&&J.reasoning){let q=$;if(q.thinking=Q?.reasoningEffort?{type:"enabled",clear_thinking:!1}:{type:"disabled"},Q?.reasoningEffort&&Y.supportsReasoningEffort){let j=J.thinkingLevelMap?.[Q.reasoningEffort],V=j===void 0?Q.reasoningEffort:j;if(typeof V==="string")q.reasoning_effort=V}}else if(Y.thinkingFormat==="qwen"&&J.reasoning)$.enable_thinking=!!Q?.reasoningEffort;else if(Y.thinkingFormat==="qwen-chat-template"&&J.reasoning)$.chat_template_kwargs={enable_thinking:!!Q?.reasoningEffort,preserve_thinking:!0};else if(Y.thinkingFormat==="chat-template"&&J.reasoning){let q=VJ(J,Q,Y);if(q)$.chat_template_kwargs=q}else if(Y.thinkingFormat==="deepseek"&&J.reasoning){if(Q?.reasoningEffort)$.thinking={type:"enabled"};else if(J.thinkingLevelMap?.off!==null)$.thinking={type:"disabled"};if(Q?.reasoningEffort&&Y.supportsReasoningEffort)$.reasoning_effort=J.thinkingLevelMap?.[Q.reasoningEffort]??Q.reasoningEffort}else if(Y.thinkingFormat==="openrouter"&&J.reasoning){let q=$;if(Q?.reasoningEffort)q.reasoning={effort:J.thinkingLevelMap?.[Q.reasoningEffort]??Q.reasoningEffort};else if(J.thinkingLevelMap?.off!==null)q.reasoning={effort:J.thinkingLevelMap?.off??"none"}}else if(Y.thinkingFormat==="ant-ling"&&J.reasoning&&Q?.reasoningEffort){let q=J.thinkingLevelMap?.[Q.reasoningEffort];if(typeof q==="string")$.reasoning={effort:q}}else if(Y.thinkingFormat==="together"&&J.reasoning){let q=$;if(q.reasoning={enabled:!!Q?.reasoningEffort},Q?.reasoningEffort&&Y.supportsReasoningEffort)q.reasoning_effort=J.thinkingLevelMap?.[Q.reasoningEffort]??Q.reasoningEffort}else if(Y.thinkingFormat==="string-thinking"&&J.reasoning){let q=$;if(Q?.reasoningEffort)q.thinking=J.thinkingLevelMap?.[Q.reasoningEffort]??Q.reasoningEffort;else if(J.thinkingLevelMap?.off!==null)q.thinking=J.thinkingLevelMap?.off??"none"}else if(Q?.reasoningEffort&&J.reasoning&&Y.supportsReasoningEffort)$.reasoning_effort=J.thinkingLevelMap?.[Q.reasoningEffort]??Q.reasoningEffort;else if(!Q?.reasoningEffort&&J.reasoning&&Y.supportsReasoningEffort){let q=J.thinkingLevelMap?.off;if(typeof q==="string")$.reasoning_effort=q}if(J.compat?.openRouterRouting)$.provider=J.compat.openRouterRouting;if(J.compat?.vercelGatewayRouting){let q=J.compat.vercelGatewayRouting;if(q.only||q.order){let j={};if(q.only)j.only=q.only;if(q.order)j.order=q.order;$.providerOptions={gateway:j}}}return $}function VJ(J,X,Q){let Y={};for(let[_,H]of Object.entries(Q.chatTemplateKwargs)){let K=WJ(J,X,H);if(K!==void 0)Y[_]=K}return Object.keys(Y).length>0?Y:void 0}function WJ(J,X,Q){if(typeof Q!=="object"||Q===null)return Q;let Y=X?.reasoningEffort;if(!Y&&Q.omitWhenOff)return;if(Q.$var==="thinking.enabled")return!!Y;let _=Y?J.thinkingLevelMap?.[Y]:J.thinkingLevelMap?.off;return _===void 0?Y:typeof _==="string"?_:void 0}function GJ(J,X){if(J.cacheControlFormat!=="anthropic"||X==="none")return;let Q=X==="long"&&J.supportsLongCacheRetention?"1h":void 0;return{type:"ephemeral",...Q?{ttl:Q}:{}}}function NJ(J,X,Q){SJ(J,Q),FJ(X,Q),OJ(J,Q)}function SJ(J,X){for(let Q of J)if(Q.role==="system"||Q.role==="developer"){PJ(Q,X);return}}function OJ(J,X){for(let Q=J.length-1;Q>=0;Q--){let Y=J[Q];if(Y.role==="user"||Y.role==="assistant"){if(AJ(Y,X))return}}}function FJ(J,X){if(!J||J.length===0)return;let Q=J[J.length-1];Q.cache_control=X}function PJ(J,X){return o(J,X)}function AJ(J,X){if(J.role==="user"||J.role==="assistant")return o(J,X);return!1}function o(J,X){let Q=J.content;if(typeof Q==="string"){if(Q.length===0)return!1;return J.content=[{type:"text",text:Q,cache_control:X}],!0}if(!Array.isArray(Q))return!1;for(let Y=Q.length-1;Y>=0;Y--){let _=Q[Y];if(_?.type==="text"){let H=_;return H.cache_control=X,!0}}return!1}function EJ(J,X,Q){let Y=[],_=($)=>{if($.includes("|")){let[q]=$.split("|");return q.replace(/[^a-zA-Z0-9_-]/g,"_").slice(0,40)}if(J.provider==="openai")return $.length>40?$.slice(0,40):$;return $},H=n(X.messages,J,($)=>_($));if(X.systemPrompt){let q=J.reasoning&&Q.supportsDeveloperRole?"developer":"system";Y.push({role:q,content:w(X.systemPrompt)})}let K=null;for(let $=0;$<H.length;$++){let q=H[$];if(Q.requiresAssistantAfterToolResult&&K==="toolResult"&&q.role==="user")Y.push({role:"assistant",content:"I have processed the tool results."});if(q.role==="user")if(typeof q.content==="string")Y.push({role:"user",content:w(q.content)});else{let j=q.content.map((V)=>{if(V.type==="text")return{type:"text",text:w(V.text)};else return{type:"image_url",image_url:{url:`data:${V.mimeType};base64,${V.data}`}}});if(j.length===0)continue;Y.push({role:"user",content:j})}else if(q.role==="assistant"){let j={role:"assistant",content:Q.requiresAssistantAfterToolResult?"":null},V=q.content.filter(u).filter((L)=>L.text.trim().length>0).map((L)=>({type:"text",text:w(L.text)})),O=V.map((L)=>L.text).join(""),P=q.content.filter(qJ).filter((L)=>L.thinking.trim().length>0);if(P.length>0)if(Q.requiresThinkingAsText){let L=P.map((G)=>w(G.thinking)).join(`
4
-
5
- `);j.content=[{type:"text",text:L},...V]}else{if(O.length>0)j.content=O;let L=P[0].thinkingSignature;if(J.provider==="opencode-go"&&L==="reasoning")L="reasoning_content";if(L&&L.length>0)j[L]=P.map((G)=>G.thinking).join(`
6
- `)}else if(O.length>0)j.content=O;let A=q.content.filter(ZJ);if(A.length>0){j.tool_calls=A.map((G)=>({id:G.id,type:"function",function:{name:G.name,arguments:JSON.stringify(G.arguments)}}));let L=A.filter((G)=>G.thoughtSignature).map((G)=>{try{return JSON.parse(G.thoughtSignature)}catch{return null}}).filter(Boolean);if(L.length>0)j.reasoning_details=L}if(Q.requiresReasoningContentOnAssistantMessages&&J.reasoning&&j.reasoning_content===void 0)j.reasoning_content="";let F=j.content;if(!(F!==null&&F!==void 0&&(typeof F==="string"?F.length>0:F.length>0))&&!j.tool_calls)continue;Y.push(j)}else if(q.role==="toolResult"){let j=[],V=$;for(;V<H.length&&H[V].role==="toolResult";V++){let O=H[V],P=O.content.filter(u).map((G)=>G.text).join(`
7
- `),A=O.content.some((G)=>G.type==="image"),E=P.length>0?P:A?"(see attached image)":"(no tool output)",L={role:"tool",content:w(E),tool_call_id:O.toolCallId};if(Q.requiresToolResultName&&O.toolName)L.name=O.toolName;if(Y.push(L),A&&J.input.includes("image")){for(let G of O.content)if(KJ(G))j.push({type:"image_url",image_url:{url:`data:${G.mimeType};base64,${G.data}`}})}}if($=V-1,j.length>0){if(Q.requiresAssistantAfterToolResult)Y.push({role:"assistant",content:"I have processed the tool results."});Y.push({role:"user",content:[{type:"text",text:"Attached image(s) from tool result:"},...j]}),K="user"}else K="toolResult";continue}K=q.role}return Y}function DJ(J,X){return J.map((Q)=>({type:"function",function:{name:Q.name,description:Q.description,parameters:Q.parameters,...X.supportsStrictMode!==!1&&{strict:!1}}}))}function b(J,X){let Q=J.prompt_tokens||0,Y=J.prompt_tokens_details?.cached_tokens??J.prompt_cache_hit_tokens??0,_=J.prompt_tokens_details?.cache_write_tokens||0,H=Math.max(0,Q-Y-_),K=J.completion_tokens||0,$={input:H,output:K,cacheRead:Y,cacheWrite:_,reasoning:J.completion_tokens_details?.reasoning_tokens||0,totalTokens:H+K+Y+_,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}};return g(X,$),$}function yJ(J){if(J===null)return{stopReason:"stop"};switch(J){case"stop":case"end":return{stopReason:"stop"};case"length":return{stopReason:"length"};case"function_call":case"tool_calls":return{stopReason:"toolUse"};case"content_filter":return{stopReason:"error",errorMessage:"Provider finish_reason: content_filter"};case"network_error":return{stopReason:"error",errorMessage:"Provider finish_reason: network_error"};default:return{stopReason:"error",errorMessage:`Provider finish_reason: ${J}`}}}function wJ(J){let{provider:X,baseUrl:Q}=J,Y=X==="zai"||X==="zai-coding-cn"||Q.includes("api.z.ai")||Q.includes("open.bigmodel.cn"),_=X==="together"||Q.includes("api.together.ai")||Q.includes("api.together.xyz"),H=X==="moonshotai"||X==="moonshotai-cn"||Q.includes("api.moonshot."),K=X==="openrouter"||Q.includes("openrouter.ai"),$=X==="cloudflare-workers-ai"||Q.includes("api.cloudflare.com"),q=X==="cloudflare-ai-gateway"||Q.includes("gateway.ai.cloudflare.com"),j=X==="nvidia"||Q.includes("integrate.api.nvidia.com"),V=X==="ant-ling"||Q.includes("api.ant-ling.com"),O=j||X==="cerebras"||Q.includes("cerebras.ai")||X==="xai"||Q.includes("api.x.ai")||_||Q.includes("chutes.ai")||Q.includes("deepseek.com")||Y||H||X==="opencode"||Q.includes("opencode.ai")||$||q||V,P=Q.includes("chutes.ai")||H||q||_||j||V,A=X==="xai"||Q.includes("api.x.ai"),F=X==="deepseek"||Q.includes("deepseek.com"),E=K&&(J.id.startsWith("anthropic/")||J.id.startsWith("openai/")),L=X==="openrouter"&&J.id.startsWith("anthropic/")?"anthropic":void 0;return{supportsStore:!O,supportsDeveloperRole:E||!O&&!K,supportsReasoningEffort:!A&&!Y&&!H&&!_&&!q&&!j&&!V,supportsUsageInStreaming:!0,maxTokensField:P?"max_tokens":"max_completion_tokens",requiresToolResultName:!1,requiresAssistantAfterToolResult:!1,requiresThinkingAsText:!1,requiresReasoningContentOnAssistantMessages:F,thinkingFormat:F?"deepseek":Y?"zai":_?"together":V?"ant-ling":K?"openrouter":"openai",openRouterRouting:{},vercelGatewayRouting:{},chatTemplateKwargs:{},zaiToolStream:!1,supportsStrictMode:!H&&!_&&!q&&!j,cacheControlFormat:L,sendSessionAffinityHeaders:!1,sessionAffinityFormat:K?"openrouter":"openai",supportsLongCacheRetention:!(_||$||q||j||V)}}function f(J){let X=wJ(J);if(!J.compat)return X;return{supportsStore:J.compat.supportsStore??X.supportsStore,supportsDeveloperRole:J.compat.supportsDeveloperRole??X.supportsDeveloperRole,supportsReasoningEffort:J.compat.supportsReasoningEffort??X.supportsReasoningEffort,supportsUsageInStreaming:J.compat.supportsUsageInStreaming??X.supportsUsageInStreaming,maxTokensField:J.compat.maxTokensField??X.maxTokensField,requiresToolResultName:J.compat.requiresToolResultName??X.requiresToolResultName,requiresAssistantAfterToolResult:J.compat.requiresAssistantAfterToolResult??X.requiresAssistantAfterToolResult,requiresThinkingAsText:J.compat.requiresThinkingAsText??X.requiresThinkingAsText,requiresReasoningContentOnAssistantMessages:J.compat.requiresReasoningContentOnAssistantMessages??X.requiresReasoningContentOnAssistantMessages,thinkingFormat:J.compat.thinkingFormat??X.thinkingFormat,openRouterRouting:J.compat.openRouterRouting??{},vercelGatewayRouting:J.compat.vercelGatewayRouting??X.vercelGatewayRouting,chatTemplateKwargs:J.compat.chatTemplateKwargs??X.chatTemplateKwargs,zaiToolStream:J.compat.zaiToolStream??X.zaiToolStream,supportsStrictMode:J.compat.supportsStrictMode??X.supportsStrictMode,cacheControlFormat:J.compat.cacheControlFormat??X.cacheControlFormat,sendSessionAffinityHeaders:J.compat.sendSessionAffinityHeaders??X.sendSessionAffinityHeaders,sessionAffinityFormat:J.compat.sessionAffinityFormat??X.sessionAffinityFormat,supportsLongCacheRetention:J.compat.supportsLongCacheRetention??X.supportsLongCacheRetention}}export{hJ as streamSimple,zJ as stream,EJ as convertMessages};
@@ -1,3 +0,0 @@
1
- // @bun
2
- function x(f){let b={};for(let[q,w]of f.entries())b[q]=w;return b}
3
- export{x as Ek};