@caspian2026/agent-sdk 0.0.19 → 0.0.21

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 (214) hide show
  1. package/dist/{chunk-v311af96.js → chunk-06xmvpv7.js} +17 -17
  2. package/dist/{chunk-pgs47kqs.js → chunk-079tw1d6.js} +13 -13
  3. package/dist/{chunk-1ts9qapj.js → chunk-08prz7zp.js} +6 -6
  4. package/dist/{chunk-e2nwdr09.js → chunk-0hqv6vq3.js} +15 -15
  5. package/dist/{chunk-hszdxe8f.js → chunk-0rbxzwnb.js} +15 -15
  6. package/dist/{chunk-dnb45dhp.js → chunk-102ee39t.js} +13 -13
  7. package/dist/{chunk-dn00fcy7.js → chunk-1058brys.js} +2 -2
  8. package/dist/{chunk-fvm8gehr.js → chunk-14qkwgmf.js} +3 -3
  9. package/dist/{chunk-6mqmk16a.js → chunk-1871fy77.js} +13 -13
  10. package/dist/{chunk-a2v77s0p.js → chunk-1ksywqf6.js} +2 -2
  11. package/dist/{chunk-qzf23s30.js → chunk-1q2taz28.js} +2 -2
  12. package/dist/{chunk-0rs4m3ya.js → chunk-24q2kxjm.js} +1 -1
  13. package/dist/{chunk-3t7kecay.js → chunk-25s7wwvz.js} +15 -15
  14. package/dist/{chunk-hav5hw2k.js → chunk-26b7qsct.js} +13 -13
  15. package/dist/{chunk-v4162e76.js → chunk-26sypsqa.js} +3 -4
  16. package/dist/{chunk-5cj7yfg1.js → chunk-26vzce3s.js} +19 -19
  17. package/dist/{chunk-3t2pkmek.js → chunk-27dhfb9v.js} +1 -1
  18. package/dist/{chunk-9hd3p970.js → chunk-2mdzhnxj.js} +14 -14
  19. package/dist/{chunk-gw9291xk.js → chunk-2qghgd3d.js} +3 -3
  20. package/dist/{chunk-xtanrzac.js → chunk-2qkcx6gx.js} +9 -9
  21. package/dist/{chunk-m86p6rs2.js → chunk-2xes6j9k.js} +24 -24
  22. package/dist/{chunk-7hfzfe98.js → chunk-33e7y2ye.js} +1 -1
  23. package/dist/{chunk-d4q90j1w.js → chunk-3csagva2.js} +13 -13
  24. package/dist/{chunk-kwp6116t.js → chunk-3jwpbxxx.js} +15 -15
  25. package/dist/{chunk-0r04e4ap.js → chunk-3mqgy4d8.js} +2 -2
  26. package/dist/{chunk-5xkp0tnb.js → chunk-3pm48qgm.js} +21 -21
  27. package/dist/{chunk-hpd100ja.js → chunk-3tx97a7z.js} +17 -17
  28. package/dist/{chunk-nc7kjfxk.js → chunk-3w6dvw7z.js} +13 -13
  29. package/dist/{chunk-vj9segre.js → chunk-40p1xyv4.js} +7 -7
  30. package/dist/{chunk-dhfag5m0.js → chunk-4621eys4.js} +3 -3
  31. package/dist/{chunk-ngc2r6jc.js → chunk-46y1vrxs.js} +1 -1
  32. package/dist/{chunk-a5cj5yk1.js → chunk-49ce42vr.js} +1 -1
  33. package/dist/{chunk-1hg8ktay.js → chunk-4bjfp2cp.js} +14 -14
  34. package/dist/{chunk-dmahh26f.js → chunk-4nyewkpd.js} +1 -1
  35. package/dist/{chunk-p81gg65v.js → chunk-4sk0ekmh.js} +9253 -2390
  36. package/dist/{chunk-110c7hek.js → chunk-4th9sgzv.js} +2 -2
  37. package/dist/{chunk-zt86q6j5.js → chunk-50cqjkgy.js} +14 -14
  38. package/dist/{chunk-3jp8zgek.js → chunk-530bp1wc.js} +1 -1
  39. package/dist/{chunk-qpaeatmf.js → chunk-59564wn5.js} +13 -13
  40. package/dist/{chunk-qwa7xy95.js → chunk-5e4jj4hd.js} +13 -13
  41. package/dist/{chunk-w328d3yn.js → chunk-5jkawn33.js} +3 -3
  42. package/dist/{chunk-40gj4vgn.js → chunk-5wnkq46y.js} +2 -2
  43. package/dist/{chunk-5h1wfdk2.js → chunk-65w2019d.js} +8 -8
  44. package/dist/{chunk-03jc62cq.js → chunk-66wbs5de.js} +13 -13
  45. package/dist/{chunk-ft4dxnwq.js → chunk-68ypktng.js} +1 -1
  46. package/dist/{chunk-nsbtda9y.js → chunk-69bms9eh.js} +14 -14
  47. package/dist/{chunk-m626yecd.js → chunk-7641fj0b.js} +13 -13
  48. package/dist/{chunk-1j0n05rf.js → chunk-7gy9xrjc.js} +1 -1
  49. package/dist/{chunk-0zprysa2.js → chunk-7k74bhsg.js} +13 -13
  50. package/dist/{chunk-bdb81673.js → chunk-7pz9rdg8.js} +1 -1
  51. package/dist/{chunk-ntztbz5t.js → chunk-7ry9qp54.js} +13 -13
  52. package/dist/{chunk-6fes9049.js → chunk-7v902gw4.js} +4 -4
  53. package/dist/{chunk-vtjgsgyf.js → chunk-7vhfhyq0.js} +13 -13
  54. package/dist/{chunk-d564dtpq.js → chunk-7w4n7zr8.js} +21 -21
  55. package/dist/{chunk-kde61fqf.js → chunk-86fwp0mg.js} +62 -62
  56. package/dist/{chunk-bamjc1k5.js → chunk-8knpmkt5.js} +1 -1
  57. package/dist/{chunk-f0eqte4j.js → chunk-8mpv3j7b.js} +13 -13
  58. package/dist/{chunk-ypsecc1v.js → chunk-8scyf6tf.js} +14 -14
  59. package/dist/chunk-92cczfwx.js +903 -0
  60. package/dist/{chunk-rtbrh4ac.js → chunk-9r16nw6z.js} +19 -19
  61. package/dist/{chunk-3jh2z27c.js → chunk-9rm2hczd.js} +13 -13
  62. package/dist/{chunk-2e8ybf05.js → chunk-9shyda79.js} +2 -2
  63. package/dist/{chunk-rtbar3a1.js → chunk-9t8650e0.js} +13 -13
  64. package/dist/{chunk-t300xs2e.js → chunk-9znd08ha.js} +5 -5
  65. package/dist/{chunk-drqk484j.js → chunk-a0qftggg.js} +1 -1
  66. package/dist/{chunk-t5jqejqk.js → chunk-ab78zrxc.js} +22 -22
  67. package/dist/{chunk-fkr3tfcs.js → chunk-acj1j3dw.js} +3 -3
  68. package/dist/{chunk-1vyfr81c.js → chunk-aj7nt1ae.js} +1 -1
  69. package/dist/{chunk-xq0q4bky.js → chunk-akd5hjav.js} +2 -2
  70. package/dist/{chunk-4ce75svs.js → chunk-ang6j1ma.js} +5 -5
  71. package/dist/{chunk-302xme7e.js → chunk-arrvgw6z.js} +51 -50
  72. package/dist/{chunk-f84vvk41.js → chunk-as3pvrmw.js} +4 -4
  73. package/dist/{chunk-eqj42wkk.js → chunk-b08zb0sw.js} +15 -15
  74. package/dist/{chunk-844zmnw6.js → chunk-ba473zak.js} +13 -13
  75. package/dist/{chunk-z0pmdn8s.js → chunk-bgzwt111.js} +2 -2
  76. package/dist/{chunk-7wg82yq4.js → chunk-bpes1x7d.js} +63 -63
  77. package/dist/{chunk-czsjnagp.js → chunk-brbrrj03.js} +21 -21
  78. package/dist/{chunk-hca6b2e5.js → chunk-bs975312.js} +15 -15
  79. package/dist/{chunk-yrr23vr1.js → chunk-bww6hm2e.js} +2 -2
  80. package/dist/{chunk-qs3g8f9e.js → chunk-c67ypsa8.js} +1 -1
  81. package/dist/{chunk-s6cxke3j.js → chunk-cgy9g4wp.js} +14 -14
  82. package/dist/{chunk-gmdt7w5d.js → chunk-cmtvwbwf.js} +1 -1
  83. package/dist/{chunk-sqckd5nx.js → chunk-cpywwph7.js} +14 -14
  84. package/dist/{chunk-6rvr3wwq.js → chunk-crcrnd8y.js} +4 -4
  85. package/dist/{chunk-srkc8pwp.js → chunk-crfk7ed8.js} +2 -2
  86. package/dist/{chunk-c073acgz.js → chunk-crvwmrey.js} +2 -2
  87. package/dist/{chunk-rn7w9k0a.js → chunk-d6kvya9n.js} +9 -9
  88. package/dist/{chunk-pd0yqtm8.js → chunk-daqd8kee.js} +24 -24
  89. package/dist/{chunk-v6qvcajp.js → chunk-db2awvr6.js} +1 -1
  90. package/dist/{chunk-bpkpy613.js → chunk-dhk2dt7n.js} +14 -14
  91. package/dist/{chunk-c33r7wby.js → chunk-dq94esjd.js} +1 -1
  92. package/dist/{chunk-d6eym4sa.js → chunk-dw1x0kzg.js} +13 -13
  93. package/dist/{chunk-1fb0jqty.js → chunk-e28pnfmr.js} +15 -15
  94. package/dist/{chunk-w022zpyz.js → chunk-effhh1pw.js} +1 -1
  95. package/dist/{chunk-xk89d6vy.js → chunk-efrjt26j.js} +3 -3
  96. package/dist/{chunk-readr4t2.js → chunk-em7h8kqy.js} +15 -15
  97. package/dist/{chunk-k6bpr2zz.js → chunk-enkgx9p5.js} +13 -13
  98. package/dist/{chunk-hz31bs21.js → chunk-f99jr604.js} +2 -2
  99. package/dist/{chunk-c2nnhgr2.js → chunk-f9mnmjf4.js} +2 -2
  100. package/dist/{chunk-mccjtnrw.js → chunk-fc8mescd.js} +13 -2
  101. package/dist/{chunk-wn3zb71r.js → chunk-fddfa07d.js} +14 -14
  102. package/dist/{chunk-g0x0gksg.js → chunk-ffcwak1t.js} +14 -14
  103. package/dist/{chunk-jqn60wdn.js → chunk-fgmmtj9k.js} +8 -8
  104. package/dist/{chunk-txn11vtv.js → chunk-fj3a38w3.js} +1 -1
  105. package/dist/{chunk-a1gwg4fx.js → chunk-fk60d1qf.js} +2 -2
  106. package/dist/{chunk-knbjqnc7.js → chunk-fnxysrtm.js} +2 -2
  107. package/dist/{chunk-bjwdqabf.js → chunk-fq24vgdm.js} +21 -21
  108. package/dist/{chunk-tz9r44d9.js → chunk-fs7jna05.js} +14 -14
  109. package/dist/{chunk-a6328ts5.js → chunk-g0wv2y40.js} +2 -2
  110. package/dist/{chunk-f6xzr8q2.js → chunk-g3gr434c.js} +13 -13
  111. package/dist/{chunk-hr9c2w99.js → chunk-g3zgsm5x.js} +1 -1
  112. package/dist/{chunk-p1sn36ax.js → chunk-g9q2patf.js} +1 -1
  113. package/dist/{chunk-5bs3xf11.js → chunk-ge8zt73c.js} +13 -13
  114. package/dist/{chunk-rnajq3vk.js → chunk-gk8dvdsw.js} +14 -14
  115. package/dist/{chunk-0075f5sb.js → chunk-gw6kn54v.js} +2 -2
  116. package/dist/{chunk-65j4q40b.js → chunk-gzt1cd1y.js} +14 -14
  117. package/dist/{chunk-36akc07b.js → chunk-hcwcwa84.js} +1 -1
  118. package/dist/{chunk-7yp1ra14.js → chunk-hf96emr1.js} +1 -1
  119. package/dist/{chunk-7s3g2nbw.js → chunk-hgteysah.js} +3 -3
  120. package/dist/{chunk-vc12yftf.js → chunk-hszppxh0.js} +1 -1
  121. package/dist/{chunk-ajrrg4t1.js → chunk-hvbnh0ht.js} +16 -16
  122. package/dist/{chunk-rjsfkzty.js → chunk-hwyp85fa.js} +3 -3
  123. package/dist/{chunk-v8twrmnw.js → chunk-jagq2tcw.js} +22 -22
  124. package/dist/{chunk-yvvgfb9f.js → chunk-jgwfkvdk.js} +14 -14
  125. package/dist/{chunk-q9t2n7d1.js → chunk-jhrshs1y.js} +14 -14
  126. package/dist/{chunk-pywnxth6.js → chunk-jjnmcaeb.js} +6 -6
  127. package/dist/{chunk-m8wxbjg3.js → chunk-jtjqrrtq.js} +2 -2
  128. package/dist/{chunk-9ed7v1qq.js → chunk-jtx7ka0g.js} +13 -13
  129. package/dist/{chunk-k2p273gs.js → chunk-jvdhwjth.js} +15 -15
  130. package/dist/{chunk-5c980jax.js → chunk-k4xyha98.js} +2 -2
  131. package/dist/{chunk-hgdxffqr.js → chunk-k6tvcn37.js} +2 -2
  132. package/dist/{chunk-q0kafg58.js → chunk-kbqx20y8.js} +13 -13
  133. package/dist/{chunk-e8s2e141.js → chunk-khnqc2x8.js} +1 -1
  134. package/dist/{chunk-brqy29g9.js → chunk-kqc0x8w6.js} +18 -18
  135. package/dist/{chunk-dfszv6kn.js → chunk-m1ergjg5.js} +2 -2
  136. package/dist/{chunk-t04tpqda.js → chunk-m4k4mve9.js} +14 -14
  137. package/dist/{chunk-4e708nwk.js → chunk-mfdqvcr5.js} +2 -2
  138. package/dist/{chunk-eert2day.js → chunk-mgv4r1af.js} +3 -3
  139. package/dist/{chunk-6s68m1dg.js → chunk-mh52m71p.js} +3 -3
  140. package/dist/{chunk-a1s9n17m.js → chunk-mjcxt56a.js} +3 -3
  141. package/dist/{chunk-kc8am0nn.js → chunk-mpc6f96q.js} +13 -13
  142. package/dist/{chunk-a5ry85ct.js → chunk-mra3tr23.js} +2 -2
  143. package/dist/{chunk-k737m0z6.js → chunk-mxt0a1ab.js} +14 -14
  144. package/dist/{chunk-0e495v4y.js → chunk-mympkkbw.js} +13 -13
  145. package/dist/{chunk-3kf30xba.js → chunk-mzrxzmpm.js} +16 -16
  146. package/dist/{chunk-b9t57m67.js → chunk-n0zd06za.js} +3 -3
  147. package/dist/{chunk-e83tfqyt.js → chunk-n22k5xdw.js} +1 -1
  148. package/dist/{chunk-w2qjc4dy.js → chunk-n9ftnh2y.js} +4 -4
  149. package/dist/{chunk-6g0hnb1k.js → chunk-nd39ny9k.js} +13 -13
  150. package/dist/{chunk-8457y05z.js → chunk-nd7zx01p.js} +3 -3
  151. package/dist/{chunk-4wx02mba.js → chunk-pajqjgkr.js} +3 -3
  152. package/dist/{chunk-b3q5g3x5.js → chunk-pe824pp5.js} +1 -1
  153. package/dist/{chunk-89vrm4ae.js → chunk-phr23vzw.js} +1 -1
  154. package/dist/{chunk-t3se5crr.js → chunk-pqe0s3es.js} +14 -14
  155. package/dist/{chunk-e4vx828d.js → chunk-px0z9762.js} +15 -15
  156. package/dist/{chunk-bbc9f5q9.js → chunk-q4wj3v8n.js} +4 -4
  157. package/dist/{chunk-mys37bb4.js → chunk-qr516hqj.js} +13 -13
  158. package/dist/{chunk-2vj1ta7d.js → chunk-qswz887n.js} +13 -13
  159. package/dist/{chunk-sa1pvh58.js → chunk-r1w3jrs8.js} +15 -15
  160. package/dist/{chunk-xrb6mn8j.js → chunk-r5q49139.js} +15 -15
  161. package/dist/{chunk-3f2ryn4p.js → chunk-rs4yvre8.js} +4 -4
  162. package/dist/{chunk-adtgferq.js → chunk-s07p92v4.js} +13 -13
  163. package/dist/{chunk-pzxz2an7.js → chunk-s8hykxf5.js} +14 -14
  164. package/dist/{chunk-5gjwp5bc.js → chunk-scz7dzwq.js} +25 -25
  165. package/dist/{chunk-7d24zw5w.js → chunk-sncz1ag3.js} +13 -13
  166. package/dist/{chunk-py5ytxp4.js → chunk-ssec5007.js} +1 -1
  167. package/dist/{chunk-q3w82drt.js → chunk-t32ddjb3.js} +2 -2
  168. package/dist/{chunk-2ewarpza.js → chunk-t7j96x8z.js} +14 -14
  169. package/dist/{chunk-d9e7ndag.js → chunk-tgafrp5a.js} +4 -4
  170. package/dist/{chunk-f3ychkjd.js → chunk-tgnbeeyx.js} +2 -2
  171. package/dist/{chunk-d5eckc42.js → chunk-tndhag9g.js} +3 -3
  172. package/dist/{chunk-0n4n14c1.js → chunk-tr9zera9.js} +4 -4
  173. package/dist/{chunk-1e1rjstz.js → chunk-tz3td6hy.js} +13 -13
  174. package/dist/{chunk-arhmkw0v.js → chunk-v17y7qay.js} +13 -13
  175. package/dist/{chunk-qh5p43j4.js → chunk-v5brqghz.js} +2 -2
  176. package/dist/{chunk-ywhmg8xp.js → chunk-vbmdqx87.js} +3 -3
  177. package/dist/{chunk-a2hq2yt9.js → chunk-vcwzs8xk.js} +1 -1
  178. package/dist/{chunk-ahxpxdqg.js → chunk-vf9320w1.js} +14 -14
  179. package/dist/{chunk-nc0ve25x.js → chunk-vneepj82.js} +3 -3
  180. package/dist/{chunk-8bxm9bv1.js → chunk-vr96pznr.js} +15 -15
  181. package/dist/{chunk-7eb2qp91.js → chunk-vszex7fm.js} +16 -16
  182. package/dist/{chunk-rs4yayw6.js → chunk-vv7kzavx.js} +1 -1
  183. package/dist/{chunk-2tb0e476.js → chunk-vwxpwg2r.js} +24 -24
  184. package/dist/{chunk-s7x8ajv3.js → chunk-vzzsjg7m.js} +4 -4
  185. package/dist/{chunk-hnwg3k83.js → chunk-w0dz2sa5.js} +1 -1
  186. package/dist/{chunk-wc67aegv.js → chunk-w1fb9aqj.js} +1 -1
  187. package/dist/{chunk-1cpeddhv.js → chunk-w43b6749.js} +3 -3
  188. package/dist/{chunk-1pjgxfeq.js → chunk-w9a226y4.js} +13 -13
  189. package/dist/{chunk-rshp5b43.js → chunk-wf16jx1f.js} +2 -2
  190. package/dist/{chunk-eady4fzn.js → chunk-wkny3k77.js} +1 -1
  191. package/dist/{chunk-vffwxpad.js → chunk-wsfq03qa.js} +16 -16
  192. package/dist/{chunk-z2npjf0h.js → chunk-x12h3n65.js} +650 -52
  193. package/dist/{chunk-j03zh8dy.js → chunk-x1dw8vry.js} +15 -15
  194. package/dist/{chunk-8svj497n.js → chunk-x5wgbcme.js} +1 -1
  195. package/dist/{chunk-y6x9kgba.js → chunk-x70f036b.js} +4 -4
  196. package/dist/{chunk-qatqd4rk.js → chunk-xca0q5ap.js} +1 -1
  197. package/dist/{chunk-c0vhnnct.js → chunk-xg08qv1e.js} +13 -13
  198. package/dist/{chunk-by2e46kd.js → chunk-xv78ch6z.js} +16 -16
  199. package/dist/{chunk-3dx4h9pq.js → chunk-xy94q6qg.js} +14 -14
  200. package/dist/{chunk-gy4se0z5.js → chunk-y4d1sgf4.js} +14 -14
  201. package/dist/{chunk-mq451b1k.js → chunk-y9ffgh1g.js} +22 -22
  202. package/dist/{chunk-py7pm42n.js → chunk-ycs5r2ef.js} +3 -3
  203. package/dist/{chunk-7n6tk7rw.js → chunk-yde1e32y.js} +6 -6
  204. package/dist/{chunk-w28zrffk.js → chunk-yfztvfhh.js} +22 -22
  205. package/dist/{chunk-m2yqqry6.js → chunk-yjk0f08a.js} +85 -85
  206. package/dist/{chunk-7m3a6kb8.js → chunk-zcq3r82m.js} +13 -13
  207. package/dist/{chunk-4xwfsejb.js → chunk-zecx4x3b.js} +2 -2
  208. package/dist/{chunk-f9wnty9x.js → chunk-zpdzhck8.js} +1 -1
  209. package/dist/{chunk-670trxyg.js → chunk-zpw4ny96.js} +1 -1
  210. package/dist/{chunk-nzdz8raj.js → chunk-zv1frw5e.js} +13 -13
  211. package/dist/cli.js +6 -6
  212. package/dist/gateway/worker.js +161802 -158117
  213. package/package.json +1 -1
  214. package/dist/chunk-ggg97179.js +0 -7442
@@ -0,0 +1,903 @@
1
+ // @bun
2
+ import {
3
+ anthropicToolChoiceToOpenAI,
4
+ anthropicToolsToOpenAI,
5
+ createAssistantAPIErrorMessage,
6
+ createUserMessage,
7
+ extractDiscoveredToolNames,
8
+ getEmptyToolPermissionContext,
9
+ getOpenAIClient,
10
+ init_Tool,
11
+ init_api,
12
+ init_client1 as init_client,
13
+ init_convertTools,
14
+ init_messages1 as init_messages,
15
+ init_modelMapping,
16
+ init_toolSearch,
17
+ isDeferredToolsDeltaEnabled,
18
+ isToolSearchEnabled,
19
+ normalizeContentFromAPI,
20
+ normalizeMessagesForAPI,
21
+ resolveOpenAIModel,
22
+ toolMatchesName,
23
+ toolToAPISchema
24
+ } from "./chunk-4sk0ekmh.js";
25
+ import"./chunk-mcws22k3.js";
26
+ import"./chunk-jzthz1bx.js";
27
+ import"./chunk-24q2kxjm.js";
28
+ import"./chunk-hwfknpxv.js";
29
+ import"./chunk-1gx78081.js";
30
+ import"./chunk-ehtwnxpg.js";
31
+ import"./chunk-3mqgy4d8.js";
32
+ import"./chunk-khnqc2x8.js";
33
+ import"./chunk-x47h283a.js";
34
+ import"./chunk-hf96emr1.js";
35
+ import"./chunk-2gzv8nrw.js";
36
+ import"./chunk-e0abab5b.js";
37
+ import"./chunk-cgfdkzhb.js";
38
+ import"./chunk-4k9d7gxv.js";
39
+ import"./chunk-j5bth84e.js";
40
+ import"./chunk-xca0q5ap.js";
41
+ import"./chunk-68ffk5qa.js";
42
+ import"./chunk-ps49ymvj.js";
43
+ import {
44
+ addToTotalSessionCost,
45
+ init_cost_tracker
46
+ } from "./chunk-26sypsqa.js";
47
+ import {
48
+ calculateUSDCost,
49
+ getModelMaxOutputTokens,
50
+ init_context,
51
+ init_modelCost
52
+ } from "./chunk-fc8mescd.js";
53
+ import"./chunk-pgtnj1mt.js";
54
+ import {
55
+ TOOL_SEARCH_TOOL_NAME,
56
+ formatDeferredToolLine,
57
+ init_prompt,
58
+ isDeferredTool
59
+ } from "./chunk-68ypktng.js";
60
+ import"./chunk-p7vkh4wx.js";
61
+ import"./chunk-y9bhjjdz.js";
62
+ import"./chunk-7pz9rdg8.js";
63
+ import"./chunk-7gy9xrjc.js";
64
+ import"./chunk-dfzkwynj.js";
65
+ import"./chunk-xeb6075z.js";
66
+ import"./chunk-fcynwjpm.js";
67
+ import"./chunk-v4t6dyyh.js";
68
+ import"./chunk-phr23vzw.js";
69
+ import"./chunk-v8kjswxt.js";
70
+ import"./chunk-q4wj3v8n.js";
71
+ import"./chunk-rnxctq9p.js";
72
+ import"./chunk-f98yad99.js";
73
+ import"./chunk-6nsd9606.js";
74
+ import"./chunk-64c1avct.js";
75
+ import"./chunk-8g5pe1gr.js";
76
+ import"./chunk-4pbx3g7s.js";
77
+ import"./chunk-26wtxbdc.js";
78
+ import"./chunk-6dngjwkh.js";
79
+ import"./chunk-4jm600zv.js";
80
+ import"./chunk-s8gy4ky9.js";
81
+ import"./chunk-cxrktb5g.js";
82
+ import"./chunk-3c25bcsw.js";
83
+ import"./chunk-5ekyhb1w.js";
84
+ import"./chunk-fqak69ft.js";
85
+ import"./chunk-cdz5yb0r.js";
86
+ import"./chunk-c7jwbe76.js";
87
+ import"./chunk-0vkfrmqm.js";
88
+ import"./chunk-7sgtxrsc.js";
89
+ import"./chunk-0xjaqda8.js";
90
+ import"./chunk-x8d2ehd7.js";
91
+ import"./chunk-byfawrfx.js";
92
+ import"./chunk-3vy1jt9p.js";
93
+ import"./chunk-vkhrrvfq.js";
94
+ import"./chunk-qnfx3qtx.js";
95
+ import"./chunk-64r16v22.js";
96
+ import"./chunk-s8kj6ajy.js";
97
+ import"./chunk-8yhf030a.js";
98
+ import"./chunk-zxh62ved.js";
99
+ import"./chunk-5z28bqne.js";
100
+ import"./chunk-qajrkk97.js";
101
+ import {
102
+ init_debug,
103
+ logForDebugging
104
+ } from "./chunk-gg55fns0.js";
105
+ import {
106
+ init_envUtils,
107
+ isEnvDefinedFalsy,
108
+ isEnvTruthy
109
+ } from "./chunk-5n1jc02d.js";
110
+ import"./chunk-fbv4apne.js";
111
+ import"./chunk-k8vp0atq.js";
112
+ import"./chunk-vf612n57.js";
113
+ import"./chunk-07069jq1.js";
114
+ import"./chunk-d4mdda98.js";
115
+ import"./chunk-55raexh7.js";
116
+ import"./chunk-v9smspw2.js";
117
+ import"./chunk-v1kzp02e.js";
118
+ import"./chunk-7wm5s02e.js";
119
+ import"./chunk-b0kf00ff.js";
120
+ import"./chunk-netzwgv1.js";
121
+ import {
122
+ __esm,
123
+ __require
124
+ } from "./chunk-qp2qdcda.js";
125
+
126
+ // src/services/api/openai/convertMessages.ts
127
+ function anthropicMessagesToOpenAI(messages, systemPrompt, options) {
128
+ const result = [];
129
+ const enableThinking = options?.enableThinking ?? false;
130
+ const systemText = systemPromptToText(systemPrompt);
131
+ if (systemText) {
132
+ result.push({
133
+ role: "system",
134
+ content: systemText
135
+ });
136
+ }
137
+ const turnBoundaries = new Set;
138
+ if (enableThinking) {
139
+ let hasSeenAssistant = false;
140
+ for (let i = 0;i < messages.length; i++) {
141
+ const msg = messages[i];
142
+ if (msg.type === "assistant") {
143
+ hasSeenAssistant = true;
144
+ }
145
+ if (msg.type === "user" && hasSeenAssistant) {
146
+ const content = msg.message.content;
147
+ const startsNewUserTurn = typeof content === "string" ? content.length > 0 : Array.isArray(content) && content.some((b) => typeof b === "string" || b && typeof b === "object" && ("type" in b) && b.type !== "tool_result");
148
+ if (startsNewUserTurn) {
149
+ turnBoundaries.add(i);
150
+ }
151
+ }
152
+ }
153
+ }
154
+ for (let i = 0;i < messages.length; i++) {
155
+ const msg = messages[i];
156
+ switch (msg.type) {
157
+ case "user":
158
+ result.push(...convertInternalUserMessage(msg));
159
+ break;
160
+ case "assistant":
161
+ const preserveReasoning = enableThinking && !isBeforeAnyTurnBoundary(i, turnBoundaries);
162
+ result.push(...convertInternalAssistantMessage(msg, preserveReasoning));
163
+ break;
164
+ default:
165
+ break;
166
+ }
167
+ }
168
+ return result;
169
+ }
170
+ function systemPromptToText(systemPrompt) {
171
+ if (!systemPrompt || systemPrompt.length === 0)
172
+ return "";
173
+ return systemPrompt.filter(Boolean).join(`
174
+
175
+ `);
176
+ }
177
+ function isBeforeAnyTurnBoundary(i, boundaries) {
178
+ for (const b of boundaries) {
179
+ if (i < b)
180
+ return true;
181
+ }
182
+ return false;
183
+ }
184
+ function convertInternalUserMessage(msg) {
185
+ const result = [];
186
+ const content = msg.message.content;
187
+ if (typeof content === "string") {
188
+ result.push({
189
+ role: "user",
190
+ content
191
+ });
192
+ } else if (Array.isArray(content)) {
193
+ const textParts = [];
194
+ const imageParts = [];
195
+ const toolResults = [];
196
+ for (const block of content) {
197
+ if (typeof block === "string") {
198
+ textParts.push(block);
199
+ } else if (block.type === "text") {
200
+ textParts.push(block.text);
201
+ } else if (block.type === "tool_result") {
202
+ toolResults.push(block);
203
+ } else if (block.type === "image") {
204
+ if (block.source.type === "base64") {
205
+ imageParts.push({
206
+ type: "image_url",
207
+ image_url: { url: `data:${block.source.media_type};base64,${block.source.data}` }
208
+ });
209
+ } else if (block.source.type === "url") {
210
+ imageParts.push({
211
+ type: "image_url",
212
+ image_url: { url: block.source.url }
213
+ });
214
+ }
215
+ }
216
+ }
217
+ const toolFollowUpMessages = [];
218
+ for (const tr of toolResults) {
219
+ const [toolMessage, ...followUpMessages] = convertToolResult(tr);
220
+ result.push(toolMessage);
221
+ toolFollowUpMessages.push(...followUpMessages);
222
+ }
223
+ result.push(...toolFollowUpMessages);
224
+ if (textParts.length > 0 || imageParts.length > 0) {
225
+ if (imageParts.length > 0) {
226
+ const contentParts = [];
227
+ if (textParts.length > 0) {
228
+ contentParts.push({ type: "text", text: textParts.join(`
229
+ `) });
230
+ }
231
+ contentParts.push(...imageParts);
232
+ result.push({
233
+ role: "user",
234
+ content: contentParts
235
+ });
236
+ } else {
237
+ result.push({
238
+ role: "user",
239
+ content: textParts.join(`
240
+ `)
241
+ });
242
+ }
243
+ }
244
+ }
245
+ return result;
246
+ }
247
+ function convertToolResult(block) {
248
+ const textParts = [];
249
+ if (typeof block.content === "string") {
250
+ textParts.push(block.content);
251
+ } else if (Array.isArray(block.content)) {
252
+ for (const c of block.content) {
253
+ if (typeof c === "string") {
254
+ textParts.push(c);
255
+ continue;
256
+ }
257
+ if ("text" in c && typeof c.text === "string") {
258
+ textParts.push(c.text);
259
+ continue;
260
+ }
261
+ if (c.type === "image") {
262
+ textParts.push("[image returned by tool]");
263
+ } else if (c.type === "document") {
264
+ textParts.push("[document returned by tool]");
265
+ }
266
+ }
267
+ }
268
+ return [{
269
+ role: "tool",
270
+ tool_call_id: block.tool_use_id,
271
+ content: textParts.filter(Boolean).join(`
272
+ `) || ""
273
+ }];
274
+ }
275
+ function convertInternalAssistantMessage(msg, preserveReasoning = false) {
276
+ const content = msg.message.content;
277
+ if (typeof content === "string") {
278
+ return [
279
+ {
280
+ role: "assistant",
281
+ content
282
+ }
283
+ ];
284
+ }
285
+ if (!Array.isArray(content)) {
286
+ return [
287
+ {
288
+ role: "assistant",
289
+ content: ""
290
+ }
291
+ ];
292
+ }
293
+ const textParts = [];
294
+ const toolCalls = [];
295
+ const reasoningParts = [];
296
+ for (const block of content) {
297
+ if (typeof block === "string") {
298
+ textParts.push(block);
299
+ } else if (block.type === "text") {
300
+ textParts.push(block.text);
301
+ } else if (block.type === "tool_use") {
302
+ const tu = block;
303
+ toolCalls.push({
304
+ id: tu.id,
305
+ type: "function",
306
+ function: {
307
+ name: tu.name,
308
+ arguments: typeof tu.input === "string" ? tu.input : JSON.stringify(tu.input)
309
+ }
310
+ });
311
+ } else if (block.type === "thinking" && preserveReasoning) {
312
+ const thinkingText = block.thinking;
313
+ if (typeof thinkingText === "string" && thinkingText) {
314
+ reasoningParts.push(thinkingText);
315
+ }
316
+ }
317
+ }
318
+ const result = {
319
+ role: "assistant",
320
+ content: textParts.length > 0 ? textParts.join(`
321
+ `) : null,
322
+ ...toolCalls.length > 0 && { tool_calls: toolCalls },
323
+ ...reasoningParts.length > 0 && { reasoning_content: reasoningParts.join(`
324
+ `) }
325
+ };
326
+ return [result];
327
+ }
328
+ var init_convertMessages = () => {};
329
+
330
+ // src/services/api/openai/streamAdapter.ts
331
+ import { randomUUID } from "crypto";
332
+ async function* adaptOpenAIStreamToAnthropic(stream, model) {
333
+ const messageId = `msg_${randomUUID().replace(/-/g, "").slice(0, 24)}`;
334
+ let started = false;
335
+ let currentContentIndex = -1;
336
+ const toolBlocks = new Map;
337
+ let thinkingBlockOpen = false;
338
+ let textBlockOpen = false;
339
+ let inputTokens = 0;
340
+ let outputTokens = 0;
341
+ let cachedReadTokens = 0;
342
+ const openBlockIndices = new Set;
343
+ let pendingFinishReason = null;
344
+ let pendingHasToolCalls = false;
345
+ for await (const chunk of stream) {
346
+ const choice = chunk.choices?.[0];
347
+ const delta = choice?.delta;
348
+ if (chunk.usage) {
349
+ inputTokens = chunk.usage.prompt_tokens ?? inputTokens;
350
+ outputTokens = chunk.usage.completion_tokens ?? outputTokens;
351
+ const details = chunk.usage.prompt_tokens_details;
352
+ if (details?.cached_tokens != null) {
353
+ cachedReadTokens = details.cached_tokens;
354
+ }
355
+ }
356
+ if (!started) {
357
+ started = true;
358
+ yield {
359
+ type: "message_start",
360
+ message: {
361
+ id: messageId,
362
+ type: "message",
363
+ role: "assistant",
364
+ content: [],
365
+ model,
366
+ stop_reason: null,
367
+ stop_sequence: null,
368
+ usage: {
369
+ input_tokens: inputTokens,
370
+ output_tokens: 0,
371
+ cache_creation_input_tokens: 0,
372
+ cache_read_input_tokens: cachedReadTokens
373
+ }
374
+ }
375
+ };
376
+ }
377
+ if (!delta)
378
+ continue;
379
+ const reasoningContent = delta.reasoning_content;
380
+ if (reasoningContent != null && reasoningContent !== "") {
381
+ if (!thinkingBlockOpen) {
382
+ currentContentIndex++;
383
+ thinkingBlockOpen = true;
384
+ openBlockIndices.add(currentContentIndex);
385
+ yield {
386
+ type: "content_block_start",
387
+ index: currentContentIndex,
388
+ content_block: {
389
+ type: "thinking",
390
+ thinking: "",
391
+ signature: ""
392
+ }
393
+ };
394
+ }
395
+ yield {
396
+ type: "content_block_delta",
397
+ index: currentContentIndex,
398
+ delta: {
399
+ type: "thinking_delta",
400
+ thinking: reasoningContent
401
+ }
402
+ };
403
+ }
404
+ if (delta.content != null && delta.content !== "") {
405
+ if (!textBlockOpen) {
406
+ if (thinkingBlockOpen) {
407
+ yield {
408
+ type: "content_block_stop",
409
+ index: currentContentIndex
410
+ };
411
+ openBlockIndices.delete(currentContentIndex);
412
+ thinkingBlockOpen = false;
413
+ }
414
+ currentContentIndex++;
415
+ textBlockOpen = true;
416
+ openBlockIndices.add(currentContentIndex);
417
+ yield {
418
+ type: "content_block_start",
419
+ index: currentContentIndex,
420
+ content_block: {
421
+ type: "text",
422
+ text: ""
423
+ }
424
+ };
425
+ }
426
+ yield {
427
+ type: "content_block_delta",
428
+ index: currentContentIndex,
429
+ delta: {
430
+ type: "text_delta",
431
+ text: delta.content
432
+ }
433
+ };
434
+ }
435
+ if (delta.tool_calls) {
436
+ for (const tc of delta.tool_calls) {
437
+ const tcIndex = tc.index;
438
+ if (!toolBlocks.has(tcIndex)) {
439
+ if (thinkingBlockOpen) {
440
+ yield {
441
+ type: "content_block_stop",
442
+ index: currentContentIndex
443
+ };
444
+ openBlockIndices.delete(currentContentIndex);
445
+ thinkingBlockOpen = false;
446
+ }
447
+ if (textBlockOpen) {
448
+ yield {
449
+ type: "content_block_stop",
450
+ index: currentContentIndex
451
+ };
452
+ openBlockIndices.delete(currentContentIndex);
453
+ textBlockOpen = false;
454
+ }
455
+ currentContentIndex++;
456
+ const toolId = tc.id || `toolu_${randomUUID().replace(/-/g, "").slice(0, 24)}`;
457
+ const toolName = tc.function?.name || "";
458
+ toolBlocks.set(tcIndex, {
459
+ contentIndex: currentContentIndex,
460
+ id: toolId,
461
+ name: toolName,
462
+ arguments: ""
463
+ });
464
+ openBlockIndices.add(currentContentIndex);
465
+ yield {
466
+ type: "content_block_start",
467
+ index: currentContentIndex,
468
+ content_block: {
469
+ type: "tool_use",
470
+ id: toolId,
471
+ name: toolName,
472
+ input: {}
473
+ }
474
+ };
475
+ }
476
+ const argFragment = tc.function?.arguments;
477
+ if (argFragment) {
478
+ toolBlocks.get(tcIndex).arguments += argFragment;
479
+ yield {
480
+ type: "content_block_delta",
481
+ index: toolBlocks.get(tcIndex).contentIndex,
482
+ delta: {
483
+ type: "input_json_delta",
484
+ partial_json: argFragment
485
+ }
486
+ };
487
+ }
488
+ }
489
+ }
490
+ if (choice?.finish_reason) {
491
+ if (thinkingBlockOpen) {
492
+ yield {
493
+ type: "content_block_stop",
494
+ index: currentContentIndex
495
+ };
496
+ openBlockIndices.delete(currentContentIndex);
497
+ thinkingBlockOpen = false;
498
+ }
499
+ if (textBlockOpen) {
500
+ yield {
501
+ type: "content_block_stop",
502
+ index: currentContentIndex
503
+ };
504
+ openBlockIndices.delete(currentContentIndex);
505
+ textBlockOpen = false;
506
+ }
507
+ for (const [, block] of toolBlocks) {
508
+ if (openBlockIndices.has(block.contentIndex)) {
509
+ yield {
510
+ type: "content_block_stop",
511
+ index: block.contentIndex
512
+ };
513
+ openBlockIndices.delete(block.contentIndex);
514
+ }
515
+ }
516
+ pendingFinishReason = choice.finish_reason;
517
+ pendingHasToolCalls = toolBlocks.size > 0;
518
+ }
519
+ }
520
+ for (const idx of openBlockIndices) {
521
+ yield {
522
+ type: "content_block_stop",
523
+ index: idx
524
+ };
525
+ }
526
+ if (pendingFinishReason !== null) {
527
+ const stopReason = pendingFinishReason === "length" ? "max_tokens" : pendingHasToolCalls ? "tool_use" : mapFinishReason(pendingFinishReason);
528
+ yield {
529
+ type: "message_delta",
530
+ delta: {
531
+ stop_reason: stopReason,
532
+ stop_sequence: null
533
+ },
534
+ usage: {
535
+ input_tokens: inputTokens,
536
+ output_tokens: outputTokens,
537
+ cache_read_input_tokens: cachedReadTokens,
538
+ cache_creation_input_tokens: 0
539
+ }
540
+ };
541
+ yield {
542
+ type: "message_stop"
543
+ };
544
+ }
545
+ }
546
+ function mapFinishReason(reason) {
547
+ switch (reason) {
548
+ case "stop":
549
+ return "end_turn";
550
+ case "tool_calls":
551
+ return "tool_use";
552
+ case "length":
553
+ return "max_tokens";
554
+ case "content_filter":
555
+ return "end_turn";
556
+ default:
557
+ return "end_turn";
558
+ }
559
+ }
560
+ var init_streamAdapter = () => {};
561
+
562
+ // src/services/api/openai/index.ts
563
+ import { randomUUID as randomUUID2 } from "crypto";
564
+ function isOpenAIThinkingEnabled(model) {
565
+ if (isEnvDefinedFalsy(process.env.OPENAI_ENABLE_THINKING))
566
+ return false;
567
+ if (isEnvTruthy(process.env.OPENAI_ENABLE_THINKING))
568
+ return true;
569
+ const modelLower = model.toLowerCase();
570
+ return modelLower.includes("deepseek");
571
+ }
572
+ function buildOpenAIRequestBody(params) {
573
+ const { model, messages, tools, toolChoice, enableThinking, maxTokens, temperatureOverride } = params;
574
+ return {
575
+ model,
576
+ messages,
577
+ max_tokens: maxTokens,
578
+ ...tools.length > 0 && {
579
+ tools,
580
+ ...toolChoice && { tool_choice: toolChoice }
581
+ },
582
+ stream: true,
583
+ stream_options: { include_usage: true },
584
+ ...enableThinking && {
585
+ thinking: { type: "enabled" },
586
+ enable_thinking: true,
587
+ chat_template_kwargs: { thinking: true }
588
+ },
589
+ ...!enableThinking && temperatureOverride !== undefined && {
590
+ temperature: temperatureOverride
591
+ }
592
+ };
593
+ }
594
+ function resolveOpenAIMaxTokens(upperLimit, maxOutputTokensOverride) {
595
+ return maxOutputTokensOverride ?? (process.env.OPENAI_MAX_TOKENS ? parseInt(process.env.OPENAI_MAX_TOKENS, 10) || undefined : undefined) ?? (process.env.CLAUDE_CODE_MAX_OUTPUT_TOKENS ? parseInt(process.env.CLAUDE_CODE_MAX_OUTPUT_TOKENS, 10) || undefined : undefined) ?? upperLimit;
596
+ }
597
+ function prependDeferredToolListIfNeeded(messages, tools, deferredToolNames, useToolSearch) {
598
+ if (!useToolSearch || isDeferredToolsDeltaEnabled())
599
+ return messages;
600
+ const deferredToolList = tools.filter((tool) => deferredToolNames.has(tool.name)).map(formatDeferredToolLine).sort().join(`
601
+ `);
602
+ if (!deferredToolList)
603
+ return messages;
604
+ return [
605
+ createUserMessage({
606
+ content: `<available-deferred-tools>
607
+ ${deferredToolList}
608
+ </available-deferred-tools>`,
609
+ isMeta: true
610
+ }),
611
+ ...messages
612
+ ];
613
+ }
614
+ function isOpenAIConvertibleMessage(msg) {
615
+ return msg.type === "assistant" || msg.type === "user";
616
+ }
617
+ function assembleFinalAssistantOutputs(params) {
618
+ const { partialMessage, contentBlocks, tools, agentId, usage, stopReason, maxTokens } = params;
619
+ const outputs = [];
620
+ const allBlocks = Object.keys(contentBlocks).sort((a, b) => Number(a) - Number(b)).map((k) => contentBlocks[Number(k)]).filter(Boolean);
621
+ if (allBlocks.length > 0) {
622
+ outputs.push({
623
+ message: {
624
+ ...partialMessage,
625
+ content: normalizeContentFromAPI(allBlocks, tools, agentId),
626
+ usage,
627
+ stop_reason: stopReason,
628
+ stop_sequence: null
629
+ },
630
+ requestId: undefined,
631
+ type: "assistant",
632
+ uuid: randomUUID2(),
633
+ timestamp: new Date().toISOString()
634
+ });
635
+ }
636
+ if (stopReason === "max_tokens") {
637
+ outputs.push(createAssistantAPIErrorMessage({
638
+ content: `Output truncated: response exceeded the ${maxTokens} token limit. ` + `Set OPENAI_MAX_TOKENS or CLAUDE_CODE_MAX_OUTPUT_TOKENS to override.`,
639
+ apiError: "max_output_tokens",
640
+ error: "max_output_tokens"
641
+ }));
642
+ }
643
+ return outputs;
644
+ }
645
+ async function* queryModelOpenAI(messages, systemPrompt, tools, signal, options) {
646
+ try {
647
+ const openaiModel = resolveOpenAIModel(options.model);
648
+ const messagesForAPI = normalizeMessagesForAPI(messages, tools);
649
+ const useToolSearch = await isToolSearchEnabled(options.model, tools, options.getToolPermissionContext || (async () => getEmptyToolPermissionContext()), options.agents || [], options.querySource);
650
+ const deferredToolNames = new Set;
651
+ if (useToolSearch) {
652
+ for (const t of tools) {
653
+ if (isDeferredTool(t))
654
+ deferredToolNames.add(t.name);
655
+ }
656
+ }
657
+ let filteredTools = tools;
658
+ if (useToolSearch && deferredToolNames.size > 0) {
659
+ const discoveredToolNames = extractDiscoveredToolNames(messages);
660
+ filteredTools = tools.filter((tool) => {
661
+ if (!deferredToolNames.has(tool.name))
662
+ return true;
663
+ if (toolMatchesName(tool, TOOL_SEARCH_TOOL_NAME))
664
+ return true;
665
+ return discoveredToolNames.has(tool.name);
666
+ });
667
+ }
668
+ const toolSchemas = await Promise.all(filteredTools.map((tool) => toolToAPISchema(tool, {
669
+ getToolPermissionContext: options.getToolPermissionContext,
670
+ tools,
671
+ agents: options.agents,
672
+ allowedAgentTypes: options.allowedAgentTypes,
673
+ model: options.model,
674
+ deferLoading: useToolSearch && deferredToolNames.has(tool.name)
675
+ })));
676
+ const standardTools = toolSchemas.filter((t) => {
677
+ const anyT = t;
678
+ return anyT.type !== "advisor_20260301" && anyT.type !== "computer_20250124";
679
+ });
680
+ const enableThinking = isOpenAIThinkingEnabled(openaiModel);
681
+ const openAIConvertibleMessages = messagesForAPI.filter(isOpenAIConvertibleMessage);
682
+ const messagesWithDeferredToolList = prependDeferredToolListIfNeeded(openAIConvertibleMessages, tools, deferredToolNames, useToolSearch);
683
+ const openaiMessages = anthropicMessagesToOpenAI(messagesWithDeferredToolList, systemPrompt, { enableThinking });
684
+ const openaiTools = anthropicToolsToOpenAI(standardTools);
685
+ const openaiToolChoice = anthropicToolChoiceToOpenAI(options.toolChoice);
686
+ if (useToolSearch) {
687
+ const includedDeferredTools = filteredTools.filter((t) => deferredToolNames.has(t.name)).length;
688
+ logForDebugging(`[OpenAI] Tool search enabled: ${includedDeferredTools}/${deferredToolNames.size} deferred tools included, total tools=${openaiTools.length}`);
689
+ } else {
690
+ logForDebugging(`[OpenAI] Tool search disabled, total tools=${openaiTools.length}`);
691
+ }
692
+ const { upperLimit } = getModelMaxOutputTokens(openaiModel);
693
+ const maxTokens = resolveOpenAIMaxTokens(upperLimit, options.maxOutputTokensOverride);
694
+ const client = getOpenAIClient({
695
+ maxRetries: 0,
696
+ fetchOverride: options.fetchOverride,
697
+ source: options.querySource
698
+ });
699
+ const debugTimestamp = Date.now();
700
+ const debugRequestData = {
701
+ model: openaiModel,
702
+ systemPrompt_text: systemPrompt.join(`
703
+
704
+ `),
705
+ openai_messages_preview: openaiMessages.slice(0, 3).map((m) => ({
706
+ role: m.role,
707
+ content_preview: typeof m.content === "string" ? m.content.substring(0, 500) : JSON.stringify(m.content)?.substring(0, 500)
708
+ })),
709
+ tools_names: openaiTools.map((t) => t.function?.name ?? t.name)
710
+ };
711
+ logForDebugging(`[OpenAI] Calling model=${openaiModel}, messages=${openaiMessages.length}, tools=${openaiTools.length}, thinking=${enableThinking}`);
712
+ const requestBody = buildOpenAIRequestBody({
713
+ model: openaiModel,
714
+ messages: openaiMessages,
715
+ tools: openaiTools,
716
+ toolChoice: openaiToolChoice,
717
+ enableThinking,
718
+ maxTokens,
719
+ temperatureOverride: options.temperatureOverride
720
+ });
721
+ const stream = await client.chat.completions.create(requestBody, { signal });
722
+ const adaptedStream = adaptOpenAIStreamToAnthropic(stream, openaiModel);
723
+ const contentBlocks = {};
724
+ const collectedMessages = [];
725
+ let partialMessage;
726
+ let stopReason = null;
727
+ let usage = {
728
+ input_tokens: 0,
729
+ output_tokens: 0,
730
+ cache_creation_input_tokens: 0,
731
+ cache_read_input_tokens: 0
732
+ };
733
+ let ttftMs = 0;
734
+ const start = Date.now();
735
+ for await (const event of adaptedStream) {
736
+ switch (event.type) {
737
+ case "message_start": {
738
+ partialMessage = event.message;
739
+ ttftMs = Date.now() - start;
740
+ if (event.message?.usage) {
741
+ usage = {
742
+ ...usage,
743
+ ...event.message.usage
744
+ };
745
+ }
746
+ break;
747
+ }
748
+ case "content_block_start": {
749
+ const idx = event.index;
750
+ const cb = event.content_block;
751
+ if (cb.type === "tool_use") {
752
+ contentBlocks[idx] = { ...cb, input: "" };
753
+ } else if (cb.type === "text") {
754
+ contentBlocks[idx] = { ...cb, text: "" };
755
+ } else if (cb.type === "thinking") {
756
+ contentBlocks[idx] = { ...cb, thinking: "", signature: "" };
757
+ } else {
758
+ contentBlocks[idx] = { ...cb };
759
+ }
760
+ break;
761
+ }
762
+ case "content_block_delta": {
763
+ const idx = event.index;
764
+ const delta = event.delta;
765
+ const block = contentBlocks[idx];
766
+ if (!block)
767
+ break;
768
+ if (delta.type === "text_delta") {
769
+ block.text = (block.text || "") + delta.text;
770
+ } else if (delta.type === "input_json_delta") {
771
+ block.input = (block.input || "") + delta.partial_json;
772
+ } else if (delta.type === "thinking_delta") {
773
+ block.thinking = (block.thinking || "") + delta.thinking;
774
+ } else if (delta.type === "signature_delta") {
775
+ block.signature = delta.signature;
776
+ }
777
+ break;
778
+ }
779
+ case "content_block_stop": {
780
+ break;
781
+ }
782
+ case "message_delta": {
783
+ const deltaUsage = event.usage;
784
+ if (deltaUsage) {
785
+ usage = { ...usage, ...deltaUsage };
786
+ }
787
+ if (event.delta?.stop_reason != null) {
788
+ stopReason = event.delta.stop_reason;
789
+ }
790
+ break;
791
+ }
792
+ case "message_stop": {
793
+ if (partialMessage) {
794
+ for (const output of assembleFinalAssistantOutputs({
795
+ partialMessage,
796
+ contentBlocks,
797
+ tools,
798
+ agentId: options.agentId,
799
+ usage,
800
+ stopReason,
801
+ maxTokens
802
+ })) {
803
+ if (output.type === "assistant") {
804
+ collectedMessages.push(output);
805
+ }
806
+ yield output;
807
+ }
808
+ partialMessage = null;
809
+ }
810
+ if (usage.input_tokens + usage.output_tokens > 0) {
811
+ const costUSD = calculateUSDCost(openaiModel, usage);
812
+ addToTotalSessionCost(costUSD, usage, options.model);
813
+ }
814
+ break;
815
+ }
816
+ }
817
+ yield {
818
+ type: "stream_event",
819
+ event,
820
+ ...event.type === "message_start" ? { ttftMs } : undefined
821
+ };
822
+ }
823
+ if (partialMessage) {
824
+ for (const output of assembleFinalAssistantOutputs({
825
+ partialMessage,
826
+ contentBlocks,
827
+ tools,
828
+ agentId: options.agentId,
829
+ usage,
830
+ stopReason,
831
+ maxTokens
832
+ })) {
833
+ yield output;
834
+ }
835
+ }
836
+ try {
837
+ const { writeFileSync, mkdirSync } = await import("fs");
838
+ const { join } = await import("path");
839
+ const { tmpdir } = await import("os");
840
+ const debugDir = join(tmpdir(), "claude-code-debug");
841
+ mkdirSync(debugDir, { recursive: true });
842
+ const debugFile = join(debugDir, `openai-${debugTimestamp}.json`);
843
+ const allBlocks = Object.keys(contentBlocks).sort((a, b) => Number(a) - Number(b)).map((k) => contentBlocks[Number(k)]).filter(Boolean);
844
+ const debugPayload = {
845
+ timestamp: new Date(debugTimestamp).toISOString(),
846
+ model: openaiModel,
847
+ request: debugRequestData,
848
+ response: {
849
+ stop_reason: stopReason,
850
+ usage,
851
+ content_blocks: allBlocks.map((b) => {
852
+ if (b.type === "text")
853
+ return { type: "text", text: b.text };
854
+ if (b.type === "thinking")
855
+ return { type: "thinking", thinking_preview: b.thinking?.substring(0, 200) };
856
+ if (b.type === "tool_use")
857
+ return { type: "tool_use", name: b.name, input_preview: typeof b.input === "string" ? b.input.substring(0, 500) : b.input };
858
+ return { type: b.type };
859
+ }),
860
+ duration_ms: Date.now() - start
861
+ }
862
+ };
863
+ writeFileSync(debugFile, JSON.stringify(debugPayload, null, 2), "utf-8");
864
+ logForDebugging(`[DEBUG] OpenAI request+response dumped to ${debugFile}`);
865
+ } catch (e) {
866
+ logForDebugging(`[DEBUG] Failed to dump OpenAI debug file: ${e}`);
867
+ }
868
+ } catch (error) {
869
+ const errorMessage = error instanceof Error ? error.message : String(error);
870
+ logForDebugging(`[OpenAI] Error: ${errorMessage}`, { level: "error" });
871
+ yield createAssistantAPIErrorMessage({
872
+ content: `API Error: ${errorMessage}`,
873
+ apiError: "api_error",
874
+ error: error instanceof Error ? error : new Error(String(error))
875
+ });
876
+ }
877
+ }
878
+ var init_openai = __esm(() => {
879
+ init_client();
880
+ init_convertMessages();
881
+ init_convertTools();
882
+ init_streamAdapter();
883
+ init_modelMapping();
884
+ init_messages();
885
+ init_api();
886
+ init_Tool();
887
+ init_debug();
888
+ init_cost_tracker();
889
+ init_modelCost();
890
+ init_envUtils();
891
+ init_context();
892
+ init_messages();
893
+ init_toolSearch();
894
+ init_prompt();
895
+ });
896
+ init_openai();
897
+
898
+ export {
899
+ resolveOpenAIMaxTokens,
900
+ queryModelOpenAI,
901
+ isOpenAIThinkingEnabled,
902
+ buildOpenAIRequestBody
903
+ };