@bkm016/basalt 0.1.0 → 0.1.2

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/README.md +16 -22
  2. package/chunk-06hdzq5n.js +2 -0
  3. package/chunk-09rj27b2.js +2 -0
  4. package/{chunk-qnr1f5pj.js → chunk-0y7ne3d0.js} +2 -2
  5. package/{chunk-8wjgbd9k.js → chunk-10xzzn07.js} +2 -2
  6. package/{chunk-bj14jshr.js → chunk-1qpces5a.js} +2 -2
  7. package/chunk-1zdwrgd4.js +2 -0
  8. package/chunk-27gntzs5.js +5 -0
  9. package/chunk-2esbgxps.js +25 -0
  10. package/{chunk-913tfr9c.js → chunk-362g64pd.js} +1 -1
  11. package/{chunk-rjdhaasf.js → chunk-3cjsd292.js} +2 -2
  12. package/chunk-5c9j8qe4.js +478 -0
  13. package/chunk-5j1krv9v.js +2 -0
  14. package/{chunk-vkkj4awb.js → chunk-6hssbcgj.js} +1 -1
  15. package/chunk-75m78j7x.js +10 -0
  16. package/{chunk-zt1wvkyf.js → chunk-8296hw9m.js} +1 -1
  17. package/{chunk-9y69ywyg.js → chunk-8d46jtbj.js} +2 -2
  18. package/{chunk-sf13azm4.js → chunk-8tjad3r0.js} +4 -4
  19. package/{chunk-agntrqs9.js → chunk-97rzj7f6.js} +1 -1
  20. package/{chunk-k7w7ac9q.js → chunk-981f9dw8.js} +8 -8
  21. package/chunk-9mmz6wt3.js +2 -0
  22. package/chunk-aefadsy6.js +3 -0
  23. package/chunk-bannb9xm.js +3 -0
  24. package/chunk-bpw6q7g0.js +3 -0
  25. package/{chunk-3jz9g8ab.js → chunk-c7x1zq39.js} +3 -3
  26. package/{chunk-rv06x0kn.js → chunk-cjc90f84.js} +1 -1
  27. package/{chunk-6gyhajhx.js → chunk-d2j735sd.js} +2 -2
  28. package/{chunk-qcwnkr5y.js → chunk-d8gtbw9g.js} +1 -1
  29. package/{chunk-rm3kcxq9.js → chunk-fjtvjrkg.js} +13 -13
  30. package/{chunk-qbf8x2ft.js → chunk-fm0k0qtz.js} +1 -1
  31. package/{chunk-1yzt0qm0.js → chunk-fw2bpqmw.js} +1 -1
  32. package/{chunk-kgdrjqsy.js → chunk-g2t6t8fk.js} +2 -2
  33. package/{chunk-wc5j0hfw.js → chunk-gp7y0fja.js} +13 -13
  34. package/{chunk-5fdgy0q2.js → chunk-gzxnene8.js} +10 -10
  35. package/{chunk-y9xe9ct2.js → chunk-hwr56pfj.js} +1 -1
  36. package/{chunk-0hbjv3y6.js → chunk-jwdb0ccj.js} +3 -3
  37. package/{chunk-x9982ek7.js → chunk-k23t7vhs.js} +5 -5
  38. package/{chunk-qffb7een.js → chunk-k506w58v.js} +2 -2
  39. package/{chunk-0tdv0t5q.js → chunk-k6w6y71k.js} +2 -2
  40. package/chunk-m40gxwq4.js +5 -0
  41. package/chunk-m8vkwdgr.js +5 -0
  42. package/{chunk-7yw8aa5j.js → chunk-mvfsxdx6.js} +13 -13
  43. package/{chunk-3p7q2pyp.js → chunk-nbb9trwz.js} +1 -1
  44. package/{chunk-0szjy61m.js → chunk-pbcy6zdt.js} +1 -1
  45. package/chunk-pmqtkqsf.js +2 -0
  46. package/{chunk-hat3s3pr.js → chunk-pxsrqrd0.js} +1 -1
  47. package/{chunk-xsbxykr4.js → chunk-qe0teyn1.js} +1 -1
  48. package/{chunk-2zqny2sy.js → chunk-r7fpkb49.js} +1 -1
  49. package/{chunk-xhk54h2q.js → chunk-rtzqqngy.js} +4 -4
  50. package/chunk-ry0z4ev6.js +2 -0
  51. package/{chunk-0rya8cxe.js → chunk-shadcb9z.js} +2 -2
  52. package/chunk-shhrr741.js +3753 -0
  53. package/{chunk-tnrqkc7b.js → chunk-t6zs4kw0.js} +2 -2
  54. package/chunk-tvm4zmgj.js +3 -0
  55. package/{chunk-hcn9cf6v.js → chunk-v258nxcz.js} +1 -1
  56. package/{chunk-a6r4z44b.js → chunk-vk1gxk1t.js} +1 -1
  57. package/{chunk-d913kpyw.js → chunk-vv7fp27r.js} +2 -2
  58. package/{chunk-g2k3yhgh.js → chunk-x1xss1d7.js} +3 -3
  59. package/{chunk-dakrpbe6.js → chunk-x4874m8e.js} +2 -2
  60. package/{chunk-wx7kdf0b.js → chunk-xfvvh1s5.js} +1 -1
  61. package/{chunk-1egbcp85.js → chunk-y0m980k3.js} +7 -7
  62. package/{chunk-5wp4egky.js → chunk-y58ygzn9.js} +4 -4
  63. package/{chunk-kjr81mrd.js → chunk-y648fzx0.js} +5 -5
  64. package/{chunk-32at88hc.js → chunk-y7nma9rk.js} +1 -1
  65. package/{chunk-wd9zxhza.js → chunk-ykens1hy.js} +1 -1
  66. package/chunk-z55bmysw.js +2 -0
  67. package/chunk-zmsgwr3s.js +2 -0
  68. package/{chunk-501zkf9b.js → chunk-ztsjgssj.js} +1 -1
  69. package/cli.js +89 -0
  70. package/compiled.js +12 -3762
  71. package/package.json +4 -3
  72. package/ui-test-worker.js +67 -67
  73. package/web/chunk-0sewdyz1.js +1 -0
  74. package/web/{chunk-g9qv15hq.js → chunk-1z5p7a1h.js} +1 -1
  75. package/web/chunk-21ke27j6.js +1 -0
  76. package/web/{chunk-svmhj9hd.js → chunk-24k0r5aq.js} +1 -1
  77. package/web/{chunk-vqjs551t.js → chunk-284a17k8.js} +1 -1
  78. package/web/{chunk-3cfabjey.js → chunk-2pjdtesn.js} +14 -14
  79. package/web/{chunk-ngpq43vn.js → chunk-3mvr2gwh.js} +1 -1
  80. package/web/chunk-3t3zwx9j.js +1 -0
  81. package/web/{chunk-ezyvv4ab.js → chunk-3z93efr4.js} +1 -1
  82. package/web/{chunk-rkesqprv.js → chunk-43jqvsrg.js} +1 -1
  83. package/web/{chunk-4y2td14d.js → chunk-4bry4xds.js} +2 -2
  84. package/web/{chunk-ea9swkkt.js → chunk-5e7ygjdn.js} +1 -1
  85. package/web/{chunk-3ahpr030.js → chunk-5jbf7n5q.js} +1 -1
  86. package/web/{chunk-bhe4jzha.js → chunk-5rx8rtsa.js} +1 -1
  87. package/web/chunk-5xc9d5ft.js +1 -0
  88. package/web/{chunk-fdkp6tzq.js → chunk-693m9kt7.js} +3 -3
  89. package/web/{chunk-mq92vqb1.js → chunk-6qejm5s2.js} +1 -1
  90. package/web/{chunk-z1jtv4c0.js → chunk-8ah6ce1b.js} +2 -2
  91. package/web/{chunk-zk2f7x5e.js → chunk-8e43yaq3.js} +3 -3
  92. package/web/{chunk-hejz98gw.js → chunk-8wye0wbb.js} +1 -1
  93. package/web/{chunk-pz934t6t.js → chunk-986z0p48.js} +5 -5
  94. package/web/{chunk-jtwhjp20.js → chunk-9dd1c37b.js} +77 -77
  95. package/web/{chunk-sc63gh9d.js → chunk-9re6yttj.js} +2 -2
  96. package/web/{chunk-1t760bg0.js → chunk-abbvjt4e.js} +1 -1
  97. package/web/{chunk-1v3d60pp.js → chunk-agmkx996.js} +3 -3
  98. package/web/{chunk-kbtbbarw.js → chunk-anbn2ttv.js} +2 -2
  99. package/web/chunk-aqm3spxt.js +1139 -0
  100. package/web/{chunk-jvhmna7z.js → chunk-avwpjsxw.js} +5 -5
  101. package/web/chunk-b470hvpk.js +1 -0
  102. package/web/{chunk-29e1trsq.js → chunk-bt1m87ck.js} +2 -2
  103. package/web/chunk-cqp1d4p0.js +1 -0
  104. package/web/{chunk-b5brnfv9.js → chunk-ctcrk3qn.js} +2 -2
  105. package/web/{chunk-zakv2xdf.js → chunk-ctd8bfg2.js} +1 -1
  106. package/web/{chunk-5hex8g0y.js → chunk-cwvtraca.js} +1 -1
  107. package/web/{chunk-1x8fn8w9.js → chunk-dk90px7g.js} +1 -1
  108. package/web/{chunk-0mrkjnte.js → chunk-ds7srg4p.js} +1 -1
  109. package/web/{chunk-6r912gfj.js → chunk-dt8ss97f.js} +5 -5
  110. package/web/{chunk-ykxpb3wv.js → chunk-ezkqa7we.js} +1 -1
  111. package/web/{chunk-svdzmaxb.js → chunk-f078k1ej.js} +1 -1
  112. package/web/chunk-fekjj24p.css +1 -0
  113. package/web/{chunk-v6v831tc.js → chunk-fqj9kry9.js} +5 -5
  114. package/web/chunk-frjfamx7.js +8 -0
  115. package/web/{chunk-rz6wwdd5.js → chunk-fy8ey195.js} +1 -1
  116. package/web/{chunk-p8y0hjx9.js → chunk-g8ee1csm.js} +1 -1
  117. package/web/{chunk-ktqt87qw.js → chunk-h31p43qa.js} +1 -1
  118. package/web/chunk-h5p5jsrw.js +1 -0
  119. package/web/chunk-h9fmr6ch.js +1 -0
  120. package/web/{chunk-x9q4kh67.js → chunk-jf2ehmvp.js} +2 -2
  121. package/web/{chunk-canbct9d.js → chunk-jmnaq7c1.js} +1 -1
  122. package/web/chunk-jq0pw0k2.js +1 -0
  123. package/web/{chunk-ghxe4gam.js → chunk-jvj66qhs.js} +2 -2
  124. package/web/{chunk-7f0m2yrd.js → chunk-jzmzhj8z.js} +4 -4
  125. package/web/chunk-k4cfnvyq.js +1 -0
  126. package/web/{chunk-942prjb6.js → chunk-kgerjbn4.js} +1 -1
  127. package/web/{chunk-3bqh2dkw.js → chunk-kww4azv5.js} +5 -5
  128. package/web/chunk-m29dhjkh.js +1 -0
  129. package/web/chunk-mj6tee5h.js +1 -0
  130. package/web/{chunk-a3xt6840.js → chunk-mjpjkyd1.js} +1 -1
  131. package/web/{chunk-20q90epj.js → chunk-n8sky2q6.js} +1 -1
  132. package/web/{chunk-3pf33xsm.js → chunk-pk3ap3wh.js} +4 -4
  133. package/web/{chunk-tfyxp2qs.js → chunk-q1pkntc6.js} +4 -4
  134. package/web/{chunk-gxn0bey7.js → chunk-qryrg2pq.js} +2 -2
  135. package/web/{chunk-0xck277j.js → chunk-r92sbgwv.js} +5 -5
  136. package/web/{chunk-ev1g5cqw.js → chunk-raqqscwa.js} +2 -2
  137. package/web/{chunk-c85wxnpw.js → chunk-rc2vq9wz.js} +3 -3
  138. package/web/{chunk-rsn8j7xv.js → chunk-rkj743fg.js} +3 -3
  139. package/web/{chunk-v47rhg7b.js → chunk-rrws61wf.js} +1 -1
  140. package/web/{chunk-ytpwz01r.js → chunk-s3hwejnr.js} +2 -2
  141. package/web/{chunk-bwyw10wx.js → chunk-s3rdx28k.js} +2 -2
  142. package/web/{chunk-hryhthxr.js → chunk-shbw6wg8.js} +1 -1
  143. package/web/chunk-szcy5z56.js +1 -0
  144. package/web/{chunk-ejd43q75.js → chunk-t1xk6hca.js} +4 -4
  145. package/web/chunk-t2hhdg9r.js +1 -0
  146. package/web/chunk-tj4cmkwe.js +1 -0
  147. package/web/{chunk-mdsgekpk.js → chunk-tn1xzmgx.js} +1 -1
  148. package/web/{chunk-0k0hvh59.js → chunk-tnv7z83q.js} +1 -1
  149. package/web/chunk-v2b5q0n5.js +1 -0
  150. package/web/{chunk-haphmhz8.js → chunk-vj6kstpp.js} +5 -5
  151. package/web/{chunk-e5rmr47n.js → chunk-vjqmnkh2.js} +1 -1
  152. package/web/{chunk-vfqe8298.js → chunk-vkc149rb.js} +1 -1
  153. package/web/{chunk-n5fn9khr.js → chunk-vny496ba.js} +1 -1
  154. package/web/{chunk-s8vapqgr.js → chunk-vz5ck6x9.js} +1 -1
  155. package/web/{chunk-6atq9qtt.js → chunk-xa88zgkr.js} +1 -1
  156. package/web/{chunk-d4d3mnak.js → chunk-xdcs8qz3.js} +4 -4
  157. package/web/chunk-y5x74t89.js +1 -0
  158. package/web/{chunk-x3zwjkwg.js → chunk-yen2kkn2.js} +1 -1
  159. package/web/{chunk-vadqkz3x.js → chunk-yjv2c45j.js} +4 -4
  160. package/web/chunk-yx3dh5hg.js +1 -0
  161. package/web/chunk-yz4fmtk2.js +1 -0
  162. package/web/{chunk-4b5mt5pd.js → chunk-z24vs8q9.js} +3 -3
  163. package/web/chunk-z5j6x6j8.js +2 -0
  164. package/web/chunk-z5stjrhc.js +1 -0
  165. package/web/{chunk-3pm4645m.js → chunk-z760wagr.js} +1 -1
  166. package/web/{chunk-nerx2q12.js → chunk-znvnb9dh.js} +1 -1
  167. package/web/{chunk-55kw67nv.js → chunk-zrzq29e6.js} +1 -1
  168. package/web/{icon-yx2p2pye.svg → icon-1wgy7kzy.svg} +13 -13
  169. package/web/icon.svg +13 -13
  170. package/web/index.html +2 -2
  171. package/web/install.sh +0 -0
  172. package/web/sw.js +9 -0
  173. package/worker.js +1 -1
  174. package/chunk-1fv27j4b.js +0 -3
  175. package/chunk-356q8e0y.js +0 -10
  176. package/chunk-58vz2qsq.js +0 -2
  177. package/chunk-665jzf2w.js +0 -25
  178. package/chunk-97kjn55j.js +0 -2
  179. package/chunk-b9bg5fhd.js +0 -2
  180. package/chunk-c25s4w6a.js +0 -5
  181. package/chunk-j2x0g1vg.js +0 -2
  182. package/chunk-k0t23cmx.js +0 -2
  183. package/chunk-m38ber71.js +0 -2
  184. package/chunk-rad3dm0q.js +0 -2
  185. package/chunk-sytpmbfp.js +0 -471
  186. package/chunk-t057xfrt.js +0 -5
  187. package/chunk-tjpvayr1.js +0 -2
  188. package/chunk-ve7qx8wm.js +0 -3
  189. package/chunk-y8ced1jm.js +0 -5
  190. package/chunk-yb1jxgnk.js +0 -2
  191. package/web/chunk-00mq7bhx.js +0 -1
  192. package/web/chunk-0atfn8jf.js +0 -1
  193. package/web/chunk-310yey4q.js +0 -1
  194. package/web/chunk-32ezm0ry.js +0 -1136
  195. package/web/chunk-3hvgs5aw.js +0 -1
  196. package/web/chunk-3kh6zefg.js +0 -1
  197. package/web/chunk-401v5ht6.js +0 -8
  198. package/web/chunk-5r5kv4gh.js +0 -1
  199. package/web/chunk-95q1bwxn.js +0 -1
  200. package/web/chunk-9s7c178f.js +0 -1
  201. package/web/chunk-benmmqt2.js +0 -1
  202. package/web/chunk-bgqdcnke.js +0 -1
  203. package/web/chunk-eqegxtdt.js +0 -1
  204. package/web/chunk-gmfp7fg4.js +0 -1
  205. package/web/chunk-gxay64d5.js +0 -1
  206. package/web/chunk-jg6nzn6q.js +0 -1
  207. package/web/chunk-kx2xk3bb.js +0 -1
  208. package/web/chunk-ry9256r7.js +0 -1
  209. package/web/chunk-vfqdy860.js +0 -1
  210. package/web/chunk-wtawdeej.css +0 -1
  211. package/web/chunk-x59p8sg2.js +0 -1
  212. package/web/chunk-y7z144e3.js +0 -1
  213. package/web/chunk-ydgqrfvw.js +0 -2
  214. package/web/chunk-yj1a2d37.js +0 -1
package/README.md CHANGED
@@ -74,34 +74,28 @@ cli ──► builtins ──► plugin ──► core ──► protocol
74
74
 
75
75
  ## 快速开始
76
76
 
77
- ### 一键安装(推荐)
77
+ ### 全局安装
78
78
 
79
- 安装脚本会自动下载最新发布版、校验 SHA-256 摘要并安装到用户目录(无需管理员权限),随后自动启动服务并在浏览器打开配对好的工作台。
80
-
81
- **macOS / Linux**
79
+ 通过 npm 或 Bun 全局安装预构建、零外部依赖的 [`@bkm016/basalt`](https://www.npmjs.com/package/@bkm016/basalt)(约 4 MB,内嵌完整 Web 工作台):
82
80
 
83
81
  ```bash
84
- curl -fsSL https://basalt.work/install.sh | sh
85
- ```
82
+ # 通过 npm 全局安装(推荐,若本机尚未安装 Bun 会在首次启动时自动按需下载运行时)
83
+ npm i -g @bkm016/basalt
86
84
 
87
- **Windows(PowerShell)**
85
+ # 或使用 Bun 全局安装
86
+ bun i -g @bkm016/basalt
88
87
 
89
- ```powershell
90
- irm https://basalt.work/install.ps1 | iex
88
+ # 启动服务(加 --open 可自动在浏览器打开工作台)
89
+ basalt
91
90
  ```
92
91
 
93
- 支持在安装前通过环境变量调整安装行为(例如 `curl -fsSL https://basalt.work/install.sh | BASALT_AUTOSTART=1 sh`):
94
-
95
- | 变量 | 作用 |
96
- | :--- | :--- |
97
- | `BASALT_VERSION=0.2.0` | 安装指定版本(默认最新正式版)。 |
98
- | `BASALT_INSTALL_DIR=<目录>` | 自定义安装目录(默认 `~/.basalt/bin`,Windows 为 `%LOCALAPPDATA%\Programs\Basalt`)。 |
99
- | `BASALT_AUTOSTART=1` | 配置登录自启动(macOS LaunchAgent / Linux systemd 用户服务 / Windows 启动文件夹)。 |
100
- | `BASALT_NO_START=1` | 仅完成安装,不立即启动服务。 |
101
- | `BASALT_NO_MODIFY_PATH=1` | 不修改 Shell 配置文件(仅 macOS / Linux)。 |
102
- | `BASALT_DOWNLOAD_URL=<地址>` | 从自定义镜像下载(目录内需包含发布产物与 `SHA256SUMS`)。 |
92
+ 升级到最新版本:
103
93
 
104
- 也可直接从 [GitHub Releases](https://github.com/Bkm016/Basalt/releases) 下载对应平台的单文件可执行程序运行。
94
+ ```bash
95
+ npm i -g @bkm016/basalt@latest
96
+ # 或
97
+ bun i -g @bkm016/basalt@latest
98
+ ```
105
99
 
106
100
  ### 从源码运行
107
101
 
@@ -117,7 +111,6 @@ bun packages/cli/src/main.ts --demo # 无需 API Key,使用内置演示模
117
111
 
118
112
  1. 服务启动后,终端会输出当前监听地址、10 分钟有效的一次性配对码、二维码及配对链接;点击链接或运行 `basalt --open` 即可在浏览器中自动完成配对。
119
113
  2. 首次进入工作台若尚未配置模型,界面会引导前往「设置 → 模型」添加服务商与 API Key,也可直接通过环境变量(如 `ANTHROPIC_API_KEY`、`OPENAI_API_KEY`)提供。
120
- 3. 服务运行期间会定期检查新版本;可通过工作台「设置 → 服务器 → 版本更新」一键更新,或在终端执行 `basalt update` 无缝升级并自动重启。
121
114
 
122
115
  ---
123
116
 
@@ -250,6 +243,7 @@ basalt plugin reload hello
250
243
  | `bun run format` | 使用 Biome 自动格式化全仓代码。 |
251
244
  | `bun run build` | 编译内嵌完整 Web 前端资源的单文件可执行程序,产物位于 `packages/cli/dist/basalt`(Windows 下为 `basalt.exe`)。 |
252
245
  | `bun run build:web` | 构建可独立部署(如 Vercel)的静态 Web 工作台与 PWA 资产,产物位于 `packages/web/dist`(Shiki 语言包自动按需分块)。 |
246
+ | `bun run build:npm` | 构建自包含、零外部依赖的 npm 发布包(含预构建 Web 静态目录与 Node/Bun 双运行时引导入口),产物位于 `packages/cli/dist/npm`。 |
253
247
 
254
248
  如需交叉编译单文件可执行程序,可直接向构建脚本传入 `--target` 参数:
255
249
 
@@ -261,7 +255,7 @@ bun scripts/build.ts cli --target=bun-linux-x64
261
255
 
262
256
  ### 版本发布
263
257
 
264
- 更新 `packages/cli/package.json` 中的 `version` 字段并推送至 `main` 分支,GitHub Actions 检测到对应 `v<版本号>` 标签尚不存在时,将自动编译 Linux / macOS(x64、arm64)与 Windows x64 单文件程序,连同安装脚本与 `SHA256SUMS` 发布至 GitHub Releases(包含 `-` 的版本号如 `0.2.0-beta.1` 将标记为预发布版,不推送给自动更新通道)。
258
+ 更新 `packages/cli/package.json` 中的 `version` 字段并推送至 `main` 分支,GitHub Actions 检测到 `@bkm016/basalt` 的该版本尚未发布到 npm 时,将自动构建 npm 包并发布(需在仓库机密中配置 `NPM_TOKEN`;包含 `-` 的版本号如 `0.2.0-beta.1` 将发布到 `next` 标签,不进入 `latest`)。
265
259
 
266
260
  ---
267
261
 
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ import{kn,Ri}from"./chunk-k6w6y71k.js";export{kn as runUIWorker,Ri as uiTest};
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ import{Nr,Dr,Rn}from"./chunk-v258nxcz.js";export{Nr as ENV_KEY,Dr as ENV_SECRET,Rn as fromEnv};
@@ -1,3 +1,3 @@
1
1
  // @bun
2
- var l=Object.create;var{getPrototypeOf:m,defineProperty:f,getOwnPropertyNames:n}=Object;var k=Object.prototype.hasOwnProperty;function o(a){return this[a]}var q,r,i=(a,b,c)=>{var d=a!=null&&typeof a==="object";if(d){var h=b?q??=new WeakMap:r??=new WeakMap,j=h.get(a);if(j)return j}c=a!=null?l(m(a)):{};let e=b||!a||!a.__esModule||!k.call(a,"default")?f(c,"default",{value:a,enumerable:!0}):c;if(a&&typeof a==="object"||typeof a==="function"){for(let g of n(a))if(!k.call(e,g))f(e,g,{get:o.bind(a,g),enumerable:!0})}if(d)h.set(a,e);return e};var t=(a,b)=>()=>(b||a((b={exports:{}}).exports,b),b.exports);var s=(a)=>a;function u(a,b){this[a]=s.bind(null,b)}var Ye=(a,b)=>{for(var c in b)f(a,c,{get:b[c],enumerable:!0,configurable:!0,set:u.bind(b,c)})};var Gt=(a,b,c)=>{for(var d in b)f(a,d,{get:b[d],set:c[d],enumerable:!0,configurable:!0})},p=import.meta.require;
3
- export{i,t,Ye,Gt,p};
2
+ var l=Object.create;var{getPrototypeOf:m,defineProperty:f,getOwnPropertyNames:n}=Object;var k=Object.prototype.hasOwnProperty;function o(a){return this[a]}var q,s,i=(a,b,c)=>{var d=a!=null&&typeof a==="object";if(d){var h=b?q??=new WeakMap:s??=new WeakMap,j=h.get(a);if(j)return j}c=a!=null?l(m(a)):{};let e=b||!a||!a.__esModule||!k.call(a,"default")?f(c,"default",{value:a,enumerable:!0}):c;if(a&&typeof a==="object"||typeof a==="function"){for(let g of n(a))if(!k.call(e,g))f(e,g,{get:o.bind(a,g),enumerable:!0})}if(d)h.set(a,e);return e};var r=(a,b)=>()=>(b||a((b={exports:{}}).exports,b),b.exports);var t=(a)=>a;function u(a,b){this[a]=t.bind(null,b)}var Ye=(a,b)=>{for(var c in b)f(a,c,{get:b[c],enumerable:!0,configurable:!0,set:u.bind(b,c)})};var Gt=(a,b,c)=>{for(var d in b)f(a,d,{get:b[d],set:c[d],enumerable:!0,configurable:!0})},p=import.meta.require;
3
+ export{i,r,Ye,Gt,p};
@@ -1,3 +1,3 @@
1
1
  // @bun
2
- function n(t,r,o,i,s){if(i==="m")throw TypeError("Private method is not writable");if(i==="a"&&!s)throw TypeError("Private accessor was defined without a setter");if(typeof r==="function"?t!==r||!s:!r.has(t))throw TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(t,o):s?s.value=o:r.set(t,o),o}function e(t,r,o,i){if(o==="a"&&!i)throw TypeError("Private accessor was defined without a getter");if(typeof r==="function"?t!==r||!i:!r.has(t))throw TypeError("Cannot read private member from an object whose class did not declare it");return o==="m"?i:o==="a"?i.call(t):i?i.value:r.get(t)}function Ge(t){return typeof t==="object"&&t!==null&&(("name"in t)&&t.name==="AbortError"||("message"in t)&&String(t.message).includes("FetchRequestCanceledException"))}var Nt=(t)=>{if(t instanceof Error)return t;if(typeof t==="object"&&t!==null){try{let r=Object.prototype.toString.call(t);if(r==="[object Error]"||r==="[object DOMException]"){let o=Error(t.message,t.cause?{cause:t.cause}:{});if(t.stack)o.stack=t.stack;if(t.cause&&!o.cause)o.cause=t.cause;if(t.name)o.name=t.name;return o}}catch{}try{return Error(JSON.stringify(t))}catch{}}return Error(t)};var c=(()=>{class t extends Error{}return t})();class Z extends c{constructor(t,r,o,i,s){super(`${Z.makeMessage(t,r,o)}`);this.status=t,this.headers=i,this.requestID=i?.get("request-id"),this.workspaceID=i?.get("anthropic-workspace-id"),this.error=r,this.type=s??null}static makeMessage(t,r,o){let i=r?.message?typeof r.message==="string"?r.message:JSON.stringify(r.message):r?JSON.stringify(r):o;if(t&&i)return`${t} ${i}`;if(t)return`${t} status code (no body)`;if(i)return i;return"(no status code or body)"}static generate(t,r,o,i){if(!t||!i)return new xt({message:o,cause:Nt(r)});let s=r,u=s?.error?.type;if(t===400)return new gn(t,s,o,i,u);if(t===401)return new yn(t,s,o,i,u);if(t===403)return new bn(t,s,o,i,u);if(t===404)return new Sn(t,s,o,i,u);if(t===409)return new xn(t,s,o,i,u);if(t===422)return new wn(t,s,o,i,u);if(t===429)return new vn(t,s,o,i,u);if(t>=500)return new An(t,s,o,i,u);return new Z(t,s,o,i,u)}}class Ae extends Z{constructor({message:t}={}){super(void 0,void 0,t||"Request was aborted.",void 0)}}class xt extends Z{constructor({message:t,cause:r}){super(void 0,void 0,t||"Connection error.",void 0);if(r)this.cause=r}}class fn extends xt{constructor({message:t}={}){super({message:t??"Request timed out."})}}class yo extends c{constructor(t,{cause:r}={}){super(t??"Retryable error.");if(r!==void 0)this.cause=r}}class gn extends Z{}class yn extends Z{}class bn extends Z{}class Sn extends Z{}class xn extends Z{}class wn extends Z{}class vn extends Z{}class An extends Z{}var b=/^[a-z][a-z0-9+.-]*:/i,ti=(t)=>b.test(t),xe=(t)=>(xe=Array.isArray,xe(t)),bo=xe;function kr(t){if(typeof t!=="object")return{};return t??{}}function So(t){if(!t)return!0;for(let r in t)return!1;return!0}function l(t,r){return Object.prototype.hasOwnProperty.call(t,r)}function xo(t){return t!=null&&typeof t==="object"&&!Array.isArray(t)}var En=(t,r)=>{if(typeof r!=="number"||!Number.isInteger(r))throw new c(`${t} must be an integer`);if(r<0)throw new c(`${t} must be a positive integer`);return r};var _n=(t)=>{try{return JSON.parse(t)}catch(r){return}};function wt(t){}var k=(t)=>{if(typeof globalThis.process<"u")return globalThis.process.env?.[t]?.trim()||void 0;if(typeof globalThis.Deno<"u")return globalThis.Deno.env?.get?.(t)?.trim()||void 0;return};function ri(t){let r=0;for(let s of t)r+=s.length;let o=new Uint8Array(r),i=0;for(let s of t)o.set(s,i),i+=s.length;return o}var y;function Dt(t){let r;return(y??(r=new globalThis.TextEncoder,y=r.encode.bind(r)))(t)}var w;function vt(t){let r;return(w??(r=new globalThis.TextDecoder,w=r.decode.bind(r)))(t)}var Rr="warn",a={off:0,error:200,warn:300,info:400,debug:500},Pn=(t,r,o)=>{if(!t)return;if(l(a,t))return t;o.warn(`${r} was set to ${JSON.stringify(t)}, expected one of ${JSON.stringify(Object.keys(a))}`);return};function f(){}function p(t,r,o){if(!r||a[t]>a[o])return f;else return r[t].bind(r)}var O={error:f,warn:f,info:f,debug:f},h=new WeakMap;function x(t,r){let o=h.get(t);if(o&&o[0]===r)return o[1];let i={error:p("error",t,r),warn:p("warn",t,r),info:p("info",t,r),debug:p("debug",t,r)};return h.set(t,[r,i]),i}function T(t){let r=t.logger,o=t.logLevel??"off";if(!r)return O;return x(r,o)}var m,d;function ni(){let t=k("ANTHROPIC_LOG");if(!d||t!==m)m=t,d=x(console,Pn(t,"process.env['ANTHROPIC_LOG']",x(console,Rr))??Rr);return d}function Ze(t,r,o){if(t.debug===f)return;t.debug(r,L(o))}var L=(t)=>{if(t.options)t.options={...t.options},delete t.options.headers;if(t.headers)t.headers=Object.fromEntries((t.headers instanceof Headers?[...t.headers]:Object.entries(t.headers)).map(([r,o])=>[r,r.toLowerCase()==="authorization"||r.toLowerCase()==="api-key"||r.toLowerCase()==="x-api-key"||r.toLowerCase()==="cookie"||r.toLowerCase()==="set-cookie"?"***":o]));if("retryOfRequestLogID"in t){if(t.retryOfRequestLogID)t.retryOf=t.retryOfRequestLogID;delete t.retryOfRequestLogID}return t};function le(t,r){return t instanceof Z&&t.status===r}function R(t){return t instanceof Z&&typeof t.status==="number"&&t.status>=400&&t.status<500}function Ut(t){return R(t)&&!le(t,408)&&!le(t,409)&&!le(t,429)}function Tn(t,r,o){return Math.min(r*2**t,o)}function oi(t,r){return t+Math.random()*(r-t)}function kn(t){return t*(1-Math.random()*0.25)}var E=(()=>{class t extends Error{constructor(r){let o=typeof r==="string"?r:r.map((i)=>{if(i.type==="text")return i.text;return`[${i.type}]`}).join(" ");super(o);this.name="ToolError",this.content=r}}return t})();var wo=15000,g=5000;function Ir(t,r){if(!(t>=g))throw new c(`${r} must be at least ${g}ms (got ${t}); to run without memory sync, pass \`memorySyncIntervalMs: null\` to the worker instead`)}function Ft(){let t,r;return{promise:new Promise((i,s)=>{t=i,r=s}),resolve:t,reject:r}}
3
- export{n,e,Ge,Nt,c,Z,Ae,xt,fn,yo,gn,yn,bn,Sn,xn,wn,vn,An,ti,xe,bo,kr,So,xo,En,_n,wt,k,ri,Dt,vt,Rr,Pn,T,ni,Ze,le,Ut,Tn,oi,kn,E,wo,Ir,Ft};
2
+ function n(t,r,o,i,s){if(i==="m")throw TypeError("Private method is not writable");if(i==="a"&&!s)throw TypeError("Private accessor was defined without a setter");if(typeof r==="function"?t!==r||!s:!r.has(t))throw TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?s.call(t,o):s?s.value=o:r.set(t,o),o}function e(t,r,o,i){if(o==="a"&&!i)throw TypeError("Private accessor was defined without a getter");if(typeof r==="function"?t!==r||!i:!r.has(t))throw TypeError("Cannot read private member from an object whose class did not declare it");return o==="m"?i:o==="a"?i.call(t):i?i.value:r.get(t)}function He(t){return typeof t==="object"&&t!==null&&(("name"in t)&&t.name==="AbortError"||("message"in t)&&String(t.message).includes("FetchRequestCanceledException"))}var Ot=(t)=>{if(t instanceof Error)return t;if(typeof t==="object"&&t!==null){try{let r=Object.prototype.toString.call(t);if(r==="[object Error]"||r==="[object DOMException]"){let o=Error(t.message,t.cause?{cause:t.cause}:{});if(t.stack)o.stack=t.stack;if(t.cause&&!o.cause)o.cause=t.cause;if(t.name)o.name=t.name;return o}}catch{}try{return Error(JSON.stringify(t))}catch{}}return Error(t)};var c=(()=>{class t extends Error{}return t})();class Z extends c{constructor(t,r,o,i,s){super(`${Z.makeMessage(t,r,o)}`);this.status=t,this.headers=i,this.requestID=i?.get("request-id"),this.workspaceID=i?.get("anthropic-workspace-id"),this.error=r,this.type=s??null}static makeMessage(t,r,o){let i=r?.message?typeof r.message==="string"?r.message:JSON.stringify(r.message):r?JSON.stringify(r):o;if(t&&i)return`${t} ${i}`;if(t)return`${t} status code (no body)`;if(i)return i;return"(no status code or body)"}static generate(t,r,o,i){if(!t||!i)return new xt({message:o,cause:Ot(r)});let s=r,u=s?.error?.type;if(t===400)return new hn(t,s,o,i,u);if(t===401)return new fn(t,s,o,i,u);if(t===403)return new gn(t,s,o,i,u);if(t===404)return new yn(t,s,o,i,u);if(t===409)return new bn(t,s,o,i,u);if(t===422)return new Sn(t,s,o,i,u);if(t===429)return new xn(t,s,o,i,u);if(t>=500)return new wn(t,s,o,i,u);return new Z(t,s,o,i,u)}}class Ae extends Z{constructor({message:t}={}){super(void 0,void 0,t||"Request was aborted.",void 0)}}class xt extends Z{constructor({message:t,cause:r}){super(void 0,void 0,t||"Connection error.",void 0);if(r)this.cause=r}}class mn extends xt{constructor({message:t}={}){super({message:t??"Request timed out."})}}class yo extends c{constructor(t,{cause:r}={}){super(t??"Retryable error.");if(r!==void 0)this.cause=r}}class hn extends Z{}class fn extends Z{}class gn extends Z{}class yn extends Z{}class bn extends Z{}class Sn extends Z{}class xn extends Z{}class wn extends Z{}var b=/^[a-z][a-z0-9+.-]*:/i,ri=(t)=>b.test(t),xe=(t)=>(xe=Array.isArray,xe(t)),bo=xe;function Tr(t){if(typeof t!=="object")return{};return t??{}}function So(t){if(!t)return!0;for(let r in t)return!1;return!0}function l(t,r){return Object.prototype.hasOwnProperty.call(t,r)}function xo(t){return t!=null&&typeof t==="object"&&!Array.isArray(t)}var vn=(t,r)=>{if(typeof r!=="number"||!Number.isInteger(r))throw new c(`${t} must be an integer`);if(r<0)throw new c(`${t} must be a positive integer`);return r};var An=(t)=>{try{return JSON.parse(t)}catch(r){return}};function wt(t){}var k=(t)=>{if(typeof globalThis.process<"u")return globalThis.process.env?.[t]?.trim()||void 0;if(typeof globalThis.Deno<"u")return globalThis.Deno.env?.get?.(t)?.trim()||void 0;return};function ni(t){let r=0;for(let s of t)r+=s.length;let o=new Uint8Array(r),i=0;for(let s of t)o.set(s,i),i+=s.length;return o}var y;function Nt(t){let r;return(y??(r=new globalThis.TextEncoder,y=r.encode.bind(r)))(t)}var w;function vt(t){let r;return(w??(r=new globalThis.TextDecoder,w=r.decode.bind(r)))(t)}var kr="warn",a={off:0,error:200,warn:300,info:400,debug:500},En=(t,r,o)=>{if(!t)return;if(l(a,t))return t;o.warn(`${r} was set to ${JSON.stringify(t)}, expected one of ${JSON.stringify(Object.keys(a))}`);return};function f(){}function p(t,r,o){if(!r||a[t]>a[o])return f;else return r[t].bind(r)}var O={error:f,warn:f,info:f,debug:f},h=new WeakMap;function x(t,r){let o=h.get(t);if(o&&o[0]===r)return o[1];let i={error:p("error",t,r),warn:p("warn",t,r),info:p("info",t,r),debug:p("debug",t,r)};return h.set(t,[r,i]),i}function T(t){let r=t.logger,o=t.logLevel??"off";if(!r)return O;return x(r,o)}var m,d;function oi(){let t=k("ANTHROPIC_LOG");if(!d||t!==m)m=t,d=x(console,En(t,"process.env['ANTHROPIC_LOG']",x(console,kr))??kr);return d}function Xe(t,r,o){if(t.debug===f)return;t.debug(r,L(o))}var L=(t)=>{if(t.options)t.options={...t.options},delete t.options.headers;if(t.headers)t.headers=Object.fromEntries((t.headers instanceof Headers?[...t.headers]:Object.entries(t.headers)).map(([r,o])=>[r,r.toLowerCase()==="authorization"||r.toLowerCase()==="api-key"||r.toLowerCase()==="x-api-key"||r.toLowerCase()==="cookie"||r.toLowerCase()==="set-cookie"?"***":o]));if("retryOfRequestLogID"in t){if(t.retryOfRequestLogID)t.retryOf=t.retryOfRequestLogID;delete t.retryOfRequestLogID}return t};function le(t,r){return t instanceof Z&&t.status===r}function R(t){return t instanceof Z&&typeof t.status==="number"&&t.status>=400&&t.status<500}function Dt(t){return R(t)&&!le(t,408)&&!le(t,409)&&!le(t,429)}function _n(t,r,o){return Math.min(r*2**t,o)}function ii(t,r){return t+Math.random()*(r-t)}function Pn(t){return t*(1-Math.random()*0.25)}var E=(()=>{class t extends Error{constructor(r){let o=typeof r==="string"?r:r.map((i)=>{if(i.type==="text")return i.text;return`[${i.type}]`}).join(" ");super(o);this.name="ToolError",this.content=r}}return t})();var wo=15000,g=5000;function Rr(t,r){if(!(t>=g))throw new c(`${r} must be at least ${g}ms (got ${t}); to run without memory sync, pass \`memorySyncIntervalMs: null\` to the worker instead`)}function Ut(){let t,r;return{promise:new Promise((i,s)=>{t=i,r=s}),resolve:t,reject:r}}
3
+ export{n,e,He,Ot,c,Z,Ae,xt,mn,yo,hn,fn,gn,yn,bn,Sn,xn,wn,ri,xe,bo,Tr,So,xo,vn,An,wt,k,ni,Nt,vt,kr,En,T,oi,Xe,le,Dt,_n,ii,Pn,E,wo,Rr,Ut};
@@ -1,3 +1,3 @@
1
1
  // @bun
2
- import{_}from"./chunk-hat3s3pr.js";var a={ftp:21,gopher:70,http:80,https:443,ws:80,wss:443};function p(e,r){let o=e.toLowerCase(),t=e.toUpperCase();return r?.[o]||r?.[t]||_(o)||_(t)||""}function f(e){if(e instanceof URL)return e;try{return new URL(e)}catch{return}}function u(e){return e.startsWith("[")&&e.endsWith("]")?e.slice(1,-1):e}function l(e){let r=e.trim().toLowerCase();if(!r)return;if(r.startsWith("[")){let t=r.indexOf("]");if(t!==-1){let n=r.slice(1,t),c=r.slice(t+1);if(c.startsWith(":")){let s=Number.parseInt(c.slice(1),10);return{host:n,port:Number.isNaN(s)?0:s}}return{host:n,port:0}}}if(r.includes(":")&&r.split(":").length>2)return{host:r,port:0};let o=r.lastIndexOf(":");if(o!==-1&&o===r.indexOf(":")){let t=r.slice(0,o),n=Number.parseInt(r.slice(o+1),10);if(!Number.isNaN(n))return{host:t,port:n}}return{host:r,port:0}}function d(e,r,o){let t=p("no_proxy",o).toLowerCase();if(!t)return!0;if(t==="*")return!1;let n=u(e.toLowerCase());return t.split(/[,\s]/).every((c)=>{let s=l(c);if(!s)return!0;if(s.port&&s.port!==r)return!0;let i=u(s.host);if(i.startsWith("*."))i=i.slice(2);else if(i.startsWith(".")||i.startsWith("*"))i=i.slice(1);if(!i)return!0;if(n===i)return!1;if(n.endsWith(`.${i}`))return!1;return!0})}function h(e,r){let o=f(e);if(!o?.protocol||!o.host)return"";let t=o.protocol.split(":",1)[0],n=u(o.hostname||o.host.replace(/:\d*$/,"")),c=Number.parseInt(o.port,10)||a[t]||0;if(!d(n,c,r))return"";let s=p(`${t}_proxy`,r)||p("all_proxy",r);if(s&&!s.includes("://"))s=`${t}://${s}`;return s}var x="Unsupported proxy protocol. SOCKS and PAC proxy URLs are not supported; use an HTTP or HTTPS proxy URL.";function Er(e,r){let o=h(e,r);if(!o)return;let t;try{t=new URL(o)}catch(n){throw Error(`Invalid proxy URL ${JSON.stringify(o)}: ${n instanceof Error?n.message:String(n)}`)}if(t.protocol!=="http:"&&t.protocol!=="https:")throw Error(`${x} Got ${t.protocol}`);return t}
3
- export{Er};
2
+ import{_}from"./chunk-pxsrqrd0.js";var a={ftp:21,gopher:70,http:80,https:443,ws:80,wss:443};function p(e,r){let o=e.toLowerCase(),t=e.toUpperCase();return r?.[o]||r?.[t]||_(o)||_(t)||""}function f(e){if(e instanceof URL)return e;try{return new URL(e)}catch{return}}function u(e){return e.startsWith("[")&&e.endsWith("]")?e.slice(1,-1):e}function l(e){let r=e.trim().toLowerCase();if(!r)return;if(r.startsWith("[")){let t=r.indexOf("]");if(t!==-1){let n=r.slice(1,t),c=r.slice(t+1);if(c.startsWith(":")){let s=Number.parseInt(c.slice(1),10);return{host:n,port:Number.isNaN(s)?0:s}}return{host:n,port:0}}}if(r.includes(":")&&r.split(":").length>2)return{host:r,port:0};let o=r.lastIndexOf(":");if(o!==-1&&o===r.indexOf(":")){let t=r.slice(0,o),n=Number.parseInt(r.slice(o+1),10);if(!Number.isNaN(n))return{host:t,port:n}}return{host:r,port:0}}function d(e,r,o){let t=p("no_proxy",o).toLowerCase();if(!t)return!0;if(t==="*")return!1;let n=u(e.toLowerCase());return t.split(/[,\s]/).every((c)=>{let s=l(c);if(!s)return!0;if(s.port&&s.port!==r)return!0;let i=u(s.host);if(i.startsWith("*."))i=i.slice(2);else if(i.startsWith(".")||i.startsWith("*"))i=i.slice(1);if(!i)return!0;if(n===i)return!1;if(n.endsWith(`.${i}`))return!1;return!0})}function h(e,r){let o=f(e);if(!o?.protocol||!o.host)return"";let t=o.protocol.split(":",1)[0],n=u(o.hostname||o.host.replace(/:\d*$/,"")),c=Number.parseInt(o.port,10)||a[t]||0;if(!d(n,c,r))return"";let s=p(`${t}_proxy`,r)||p("all_proxy",r);if(s&&!s.includes("://"))s=`${t}://${s}`;return s}var x="Unsupported proxy protocol. SOCKS and PAC proxy URLs are not supported; use an HTTP or HTTPS proxy URL.";function Cr(e,r){let o=h(e,r);if(!o)return;let t;try{t=new URL(o)}catch(n){throw Error(`Invalid proxy URL ${JSON.stringify(o)}: ${n instanceof Error?n.message:String(n)}`)}if(t.protocol!=="http:"&&t.protocol!=="https:")throw Error(`${x} Got ${t.protocol}`);return t}
3
+ export{Cr};
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ import{kt,zt,jt,Vt,Kt,dr,mr,Rt,hr,fr,gr,yr,br,Sr}from"./chunk-gp7y0fja.js";import{ee}from"./chunk-tvm4zmgj.js";import{q,j}from"./chunk-y69ewdn2.js";import{V}from"./chunk-3cjsd292.js";import{g}from"./chunk-n6e43rvk.js";import{fe}from"./chunk-x4874m8e.js";import{N,pe,ne,Le,Q,H}from"./chunk-8tjad3r0.js";import{M}from"./chunk-shadcb9z.js";var w=0,C=(n,a,t)=>{let o=new M,l=Le(a);return(async()=>{let e={role:"assistant",content:[],api:"google-generative-ai",provider:n.provider,model:n.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:"pending",timestamp:Date.now()};try{if(t?.fetch&&t.fetch!==globalThis.fetch)throw Error("Custom fetch is not supported by the Google Generative AI adapter");let u=t?.apiKey;if(!u)throw Error(`No API key for provider: ${n.provider}`);let d=T(n,u,t?.headers),p=S(n,l,t),m=await t?.onPayload?.(p,n);if(m!==void 0)p=m;let f=await Sr(()=>d.models.generateContentStream(p),t);o.push({type:"start",partial:e});let i=null,k=e.content,c=()=>k.length-1;for await(let s of f){await t?.onProviderStreamEvent?.(s,n),e.responseId||=s.responseId;let y=s.candidates?.[0];if(y?.content?.parts)for(let r of y.content.parts){if(r.text!==void 0){let h=mr(r);if(!i||h&&i.type!=="thinking"||!h&&i.type!=="text"){if(i)if(i.type==="text")o.push({type:"text_end",contentIndex:k.length-1,content:i.text,partial:e});else o.push({type:"thinking_end",contentIndex:c(),content:i.thinking,partial:e});if(h)i={type:"thinking",thinking:"",thinkingSignature:void 0},e.content.push(i),o.push({type:"thinking_start",contentIndex:c(),partial:e});else i={type:"text",text:""},e.content.push(i),o.push({type:"text_start",contentIndex:c(),partial:e})}if(i.type==="thinking")i.thinking+=r.text,i.thinkingSignature=Rt(i.thinkingSignature,r.thoughtSignature),o.push({type:"thinking_delta",contentIndex:c(),delta:r.text,partial:e});else i.text+=r.text,i.textSignature=Rt(i.textSignature,r.thoughtSignature),o.push({type:"text_delta",contentIndex:c(),delta:r.text,partial:e})}if(r.functionCall){if(i){if(i.type==="text")o.push({type:"text_end",contentIndex:c(),content:i.text,partial:e});else o.push({type:"thinking_end",contentIndex:c(),content:i.thinking,partial:e});i=null}let h=r.functionCall.id,x={type:"toolCall",id:!h||e.content.some((b)=>b.type==="toolCall"&&b.id===h)?`${r.functionCall.name}_${Date.now()}_${++w}`:h,name:r.functionCall.name||"",arguments:r.functionCall.args??{},...r.thoughtSignature&&{thoughtSignature:r.thoughtSignature}};e.content.push(x),o.push({type:"toolcall_start",contentIndex:c(),partial:e}),o.push({type:"toolcall_delta",contentIndex:c(),delta:JSON.stringify(x.arguments),partial:e}),o.push({type:"toolcall_end",contentIndex:c(),toolCall:x,partial:e})}}if(y?.finishReason){if(e.rawStopReason=y.finishReason,e.stopReason=br(y.finishReason),e.content.some((r)=>r.type==="toolCall")&&e.stopReason==="stop")e.stopReason="toolUse"}if(s.usageMetadata)e.usage={input:(s.usageMetadata.promptTokenCount||0)-(s.usageMetadata.cachedContentTokenCount||0),output:(s.usageMetadata.candidatesTokenCount||0)+(s.usageMetadata.thoughtsTokenCount||0),cacheRead:s.usageMetadata.cachedContentTokenCount||0,cacheWrite:0,reasoning:s.usageMetadata.thoughtsTokenCount||0,totalTokens:s.usageMetadata.totalTokenCount||0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},Q(n,e.usage)}if(i)if(i.type==="text")o.push({type:"text_end",contentIndex:c(),content:i.text,partial:e});else o.push({type:"thinking_end",contentIndex:c(),content:i.thinking,partial:e});if(t?.signal?.aborted)throw Error("Request was aborted");if(e.stopReason==="pending")throw Error("Google stream ended without a finish reason");if(e.stopReason==="aborted"||e.stopReason==="error"){let s=e.rawStopReason?`Provider stopped with: ${e.rawStopReason}`:"An unknown error occurred";throw Error(s)}o.push({type:"done",reason:e.stopReason,message:e}),o.end()}catch(u){for(let d of e.content)if("index"in d)delete d.index;e.stopReason=t?.signal?.aborted?"aborted":"error",e.errorMessage=j(q(u)),o.push({type:"error",reason:e.stopReason,error:e}),o.end()}})(),o},z=(n,a,t)=>{let o=t?.apiKey;if(!o)throw Error(`No API key for provider: ${n.provider}`);let l={...V(n,a,t,o),toolChoice:t?.toolChoice};if(!t?.reasoning)return C(n,a,{...l,thinking:{enabled:!1}});let e=H(n,t.reasoning);if(e==="off")return C(n,a,{...l,thinking:{enabled:!1}});let u=zt(n,e);if(jt(n))return C(n,a,{...l,thinking:{enabled:!0,level:Vt(u)}});return C(n,a,{...l,thinking:{enabled:!0,budgetTokens:I(n,u,t.thinkingBudgets)}})};function T(n,a,t){let o={};if(n.baseUrl)o.baseUrl=n.baseUrl,o.apiVersion="";let l=fe({"User-Agent":ee(),...n.headers,...t});if(l)o.headers=l;return new kt({apiKey:a,httpOptions:Object.keys(o).length>0?o:void 0})}function S(n,a,t={}){let o=hr(n,a),l=pe(a.messages),e=ne(a.messages),u={};if(t.temperature!==void 0)u.temperature=t.temperature;if(t.maxTokens!==void 0)u.maxOutputTokens=t.maxTokens;let d=gr(n.id),p=e.length>0?yr(e,t.toolChoice,d):void 0,m=l?N(l):"",f={...Object.keys(u).length>0&&u,...m&&{systemInstruction:g(m)},...e.length>0&&{tools:fr(e,!1,d)},...p!==void 0&&{toolConfig:{functionCallingConfig:{mode:p}}}};if(t.thinking?.enabled&&n.reasoning){let k={includeThoughts:!0};if(t.thinking.level!==void 0)k.thinkingLevel=Kt(t.thinking.level);else if(t.thinking.budgetTokens!==void 0)k.thinkingBudget=t.thinking.budgetTokens;f.thinkingConfig=k}else if(n.reasoning&&t.thinking&&!t.thinking.enabled)f.thinkingConfig=dr(n);if(t.signal){if(t.signal.aborted)throw Error("Request aborted");f.abortSignal=t.signal}return{model:n.id,contents:o,config:f}}function I(n,a,t){if(t?.[a]!==void 0)return t[a];if(n.id.includes("2.5-pro"))return{minimal:128,low:2048,medium:8192,high:32768}[a];if(n.id.includes("2.5-flash-lite"))return{minimal:512,low:2048,medium:8192,high:24576}[a];if(n.id.includes("2.5-flash"))return{minimal:128,low:2048,medium:8192,high:24576}[a];return-1}export{C as stream,z as streamSimple};
@@ -0,0 +1,5 @@
1
+ // @bun
2
+ import{F}from"./chunk-m8vkwdgr.js";import{xr}from"./chunk-v9fea96h.js";import{Ze}from"./chunk-g2t6t8fk.js";import{ee}from"./chunk-tvm4zmgj.js";import{me,ce,V,he}from"./chunk-3cjsd292.js";import{g}from"./chunk-n6e43rvk.js";import{z}from"./chunk-x4874m8e.js";import{N,Me,ne,re,Q,H}from"./chunk-8tjad3r0.js";import{M}from"./chunk-shadcb9z.js";var S=9,U=4000,D=(t,e,n)=>{let r=new M,o=re(e,t.compat?.supportsMidConvoSystemMessages);return(async()=>{let s=B(t);try{let l=n?.apiKey;if(!l)throw Error(`No API key for provider: ${t.provider}`);let f=J(),u=he(o.messages,t,(d)=>f(d)),a=se(t,o,u,n),i=await n?.onPayload?.(a,t);if(i!==void 0)a=i;let c=await Z(t,a,l,n);if(r.push({type:"start",partial:s}),await ie(t,s,r,c,n?.onProviderStreamEvent),n?.signal?.aborted)throw Error("Request was aborted");if(s.stopReason==="pending")throw Error("Mistral stream ended without a finish reason");if(s.stopReason==="aborted"||s.stopReason==="error")throw Error(s.errorMessage||"An unknown error occurred");r.push({type:"done",reason:s.stopReason,message:s}),r.end()}catch(l){for(let f of s.content)delete f.partialArgs;s.stopReason=n?.signal?.aborted?"aborted":"error",s.errorMessage=K(l),r.push({type:"error",reason:s.stopReason,error:s}),r.end()}})(),r},Ee=(t,e,n)=>{let r=n?.apiKey;if(!r)throw Error(`No API key for provider: ${t.provider}`);let o={...V(t,e,n,r),toolChoice:n?.toolChoice},s=n?.reasoning?H(t,n.reasoning):void 0,l=s==="off"?void 0:s,f=t.reasoning?t.thinkingLevelMap:void 0,u=f?l?f[l]??"high":f.off??void 0:void 0;return D(t,e,{...o,promptMode:t.reasoning&&!f&&l?"reasoning":void 0,reasoningEffort:u})};function B(t){return{role:"assistant",content:[],api:t.api,provider:t.provider,model:t.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:"pending",timestamp:Date.now()}}function J(){let t=new Map,e=new Map;return(n)=>{let r=t.get(n);if(r)return r;let o=0;while(!0){let s=P(n,o),l=e.get(s);if(!l||l===n)return t.set(n,s),e.set(s,n),s;o++}}}function P(t,e){let n=t.replace(/[^a-zA-Z0-9]/g,"");if(e===0&&n.length===S)return n;let r=n||t,o=e===0?r:`${r}:${e}`;return Ze(o).replace(/[^a-zA-Z0-9]/g,"").slice(0,S)}function K(t){if(t instanceof Error){let e=t,n=typeof e.statusCode==="number"?e.statusCode:void 0,r=typeof e.body==="string"?e.body.trim():void 0;if(n!==void 0&&r)return`Mistral API error (${n}): ${W(r,U)}`;if(n!==void 0)return`Mistral API error (${n}): ${t.message}`;return t.message}return q(t)}function W(t,e){if(t.length<=e)return t;return`${t.slice(0,e)}... [truncated ${t.length-e} chars]`}function q(t){try{let e=JSON.stringify(t);return e===void 0?String(t):e}catch{return String(t)}}async function Z(t,e,n,r){let o=new URL(t.baseUrl);o.pathname=`${o.pathname.replace(/\/+$/u,"")}/`;let s=new URL("v1/chat/completions",o),l=G(t,n,r),f=r?.timeoutMs??60000,u=AbortSignal.timeout(f),a=xr([r?.signal,u]),i;try{i=await(r?.fetch??globalThis.fetch)(s,{method:"POST",headers:l,body:JSON.stringify(X(e)),signal:a.signal})}catch(c){if(u.aborted&&!r?.signal?.aborted)throw Error(`Mistral response headers timed out after ${f}ms`);throw c}finally{a.cleanup()}if(await r?.onResponse?.({status:i.status,headers:z(i.headers)},t),!i.ok){let c=await i.text();throw new O(i.status,c,i.statusText)}if(!i.body)throw Error("Mistral response has no body");return oe(i.body,r?.signal)}class O extends Error{statusCode;body;constructor(t,e,n){super(n||`Request failed with status ${t}`);this.name="MistralHttpError",this.statusCode=t,this.body=e}}function G(t,e,n){let r=new Headers({"User-Agent":ee(),accept:"text/event-stream",authorization:`Bearer ${e}`,"content-type":"application/json"});A(r,t.headers),A(r,n?.headers);let o=I(t.headers,"x-affinity")||I(n?.headers,"x-affinity");if(L(n)&&!o)r.set("x-affinity",n.sessionId);return r}function A(t,e){if(!e)return;for(let[n,r]of Object.entries(e))if(r===null)t.delete(n);else t.set(n,r)}function I(t,e){return!!t&&Object.keys(t).some((n)=>n.toLowerCase()===e)}function X(t){let e={...t};for(let[r,o]of[["topP","top_p"],["maxTokens","max_tokens"],["randomSeed","random_seed"],["responseFormat","response_format"],["toolChoice","tool_choice"],["presencePenalty","presence_penalty"],["frequencyPenalty","frequency_penalty"],["parallelToolCalls","parallel_tool_calls"],["reasoningEffort","reasoning_effort"],["promptMode","prompt_mode"],["promptCacheKey","prompt_cache_key"],["safePrompt","safe_prompt"]])k(e,r,o);e.messages=t.messages.map((r)=>Y(r));let n=e.response_format;if(w(n)){let r={...n};k(r,"jsonSchema","json_schema");let o=r.json_schema;if(w(o)){let s={...o};k(s,"schemaDefinition","schema"),r.json_schema=s}e.response_format=r}return e}function Y(t){let e={...t};if(k(e,"toolCalls","tool_calls"),k(e,"toolCallId","tool_call_id"),Array.isArray(t.content))e.content=t.content.map((n)=>te(n));return e}function te(t){let e={...t};for(let[n,r]of[["imageUrl","image_url"],["documentUrl","document_url"],["documentName","document_name"],["fileId","file_id"],["referenceIds","reference_ids"],["inputAudio","input_audio"]])k(e,n,r);return e}function k(t,e,n){if(!(e in t))return;t[n]=t[e],delete t[e]}function w(t){return typeof t==="object"&&t!==null&&!Array.isArray(t)}var b=Symbol("mistral-stream-done");async function*oe(t,e){let n=t.getReader(),r=new TextDecoder,o="",s=()=>{n.cancel().catch(()=>{})};e?.addEventListener("abort",s,{once:!0});try{while(!0){if(e?.aborted)throw e.reason;let{done:l,value:f}=await n.read();if(e?.aborted)throw e.reason;o+=l?r.decode():r.decode(f,{stream:!0});let u=E(o);while(u){let a=v(o.slice(0,u.index));if(o=o.slice(u.index+u.length),a===b)return;if(a)yield a;u=E(o)}if(l)break}if(o.trim()){let l=v(o);if(l!==b&&l)yield l}}finally{e?.removeEventListener("abort",s);try{await n.cancel()}catch{}try{n.releaseLock()}catch{}}}function E(t){let e=/\r\n\r\n|\r\n\r|\r\n\n|\r\r\n|\n\r\n|\r\r|\n\r|\n\n/u.exec(t);return e?.index===void 0?void 0:{index:e.index,length:e[0].length}}function v(t){let e=t.split(/\r\n|\r|\n/u).filter((r)=>r.startsWith("data:")).map((r)=>r.slice(5).trimStart()).join(`
3
+ `).trim();if(!e)return;if(e==="[DONE]")return b;let n=JSON.parse(e);if(!w(n)||!Array.isArray(n.choices))throw Error("Invalid Mistral streaming event");return{data:n}}function se(t,e,n,r){let o={model:t.id,stream:!0,messages:fe(n,t.input.includes("image"))},s=ne(e.messages);if(s.length>0)o.tools=le(s);if(r?.temperature!==void 0)o.temperature=r.temperature;if(r?.maxTokens!==void 0)o.maxTokens=r.maxTokens;if(r?.toolChoice)o.toolChoice=ue(r.toolChoice);if(r?.promptMode)o.promptMode=r.promptMode;if(r?.reasoningEffort)o.reasoningEffort=r.reasoningEffort;if(L(r))o.promptCacheKey=r.sessionId;return o}function L(t){return t?.cacheRetention!=="none"&&!!t?.sessionId}function ae(t,e){let n=t,r=n.promptTokensDetails?.cachedTokens??n.prompt_tokens_details?.cached_tokens??n.promptTokenDetails?.cachedTokens??n.prompt_token_details?.cached_tokens??n.numCachedTokens??n.num_cached_tokens??0,o=typeof r==="number"&&Number.isFinite(r)?r:0;return Math.min(e,Math.max(0,o))}async function ie(t,e,n,r,o){let s=null,l=e.content,f=()=>l.length-1,u=new Map,a=(i)=>{if(!i)return;if(i.type==="text"){n.push({type:"text_end",contentIndex:f(),content:i.text,partial:e});return}if(i.type==="thinking")n.push({type:"thinking_end",contentIndex:f(),content:i.thinking,partial:e})};for await(let i of r){let c=i.data;if(await o?.(c,t),e.responseId||=c.id,c.usage){let p=c.usage.prompt_tokens||0,h=ae(c.usage,p);e.usage.input=Math.max(0,p-h),e.usage.output=c.usage.completion_tokens||0,e.usage.cacheRead=h,e.usage.cacheWrite=0,e.usage.totalTokens=c.usage.total_tokens||e.usage.input+e.usage.output+e.usage.cacheRead+e.usage.cacheWrite,Q(t,e.usage)}let d=c.choices[0];if(!d)continue;if(d.finish_reason){e.rawStopReason=d.finish_reason;let p=pe(d.finish_reason);if(e.stopReason=p.stopReason,p.errorMessage)e.errorMessage=p.errorMessage}let x=d.delta;if(x.content!==null&&x.content!==void 0){let p=typeof x.content==="string"?[x.content]:x.content;for(let h of p){if(typeof h==="string"){let m=g(h);if(!m)continue;if(!s||s.type!=="text")a(s),s={type:"text",text:""},e.content.push(s),n.push({type:"text_start",contentIndex:f(),partial:e});s.text+=m,n.push({type:"text_delta",contentIndex:f(),delta:m,partial:e});continue}if(h.type==="thinking"){let m=(h.thinking??[]).map((y)=>y.text??"").filter((y)=>y.length>0).join(""),_=g(m);if(!_)continue;if(!s||s.type!=="thinking")a(s),s={type:"thinking",thinking:""},e.content.push(s),n.push({type:"thinking_start",contentIndex:f(),partial:e});s.thinking+=_,n.push({type:"thinking_delta",contentIndex:f(),delta:_,partial:e});continue}if(h.type==="text"){let m=g(h.text??"");if(!m)continue;if(!s||s.type!=="text")a(s),s={type:"text",text:""},e.content.push(s),n.push({type:"text_start",contentIndex:f(),partial:e});s.text+=m,n.push({type:"text_delta",contentIndex:f(),delta:m,partial:e})}}}let j=x.tool_calls||[];for(let p of j){if(s)a(s),s=null;let h=p.id&&p.id!=="null"?p.id:P(`toolcall:${p.index??0}`,0),m=p.index??h,_=u.get(m),y;if(_!==void 0){let R=e.content[_];if(R?.type==="toolCall")y=R}if(!y)y={type:"toolCall",id:h,name:p.function.name,arguments:{},partialArgs:""},e.content.push(y),u.set(m,e.content.length-1),n.push({type:"toolcall_start",contentIndex:e.content.length-1,partial:e});let C=typeof p.function.arguments==="string"?p.function.arguments:JSON.stringify(p.function.arguments||{});y.partialArgs=(y.partialArgs||"")+C,y.arguments=F(y.partialArgs),n.push({type:"toolcall_delta",contentIndex:u.get(m),delta:C,partial:e})}}a(s);for(let i of u.values()){let c=e.content[i];if(c.type!=="toolCall")continue;let d=c;d.arguments=F(d.partialArgs),delete d.partialArgs,n.push({type:"toolcall_end",contentIndex:i,toolCall:d,partial:e})}}function le(t){return t.map((e)=>{let n=ce(e,!0);return{type:"function",function:{name:e.name,description:e.description,parameters:T(me(e,n)),strict:n??!1}}})}function T(t){if(Array.isArray(t))return t.map((e)=>T(e));if(t&&typeof t==="object"){let e={};for(let[n,r]of Object.entries(t))e[n]=T(r);return e}return t}function fe(t,e){let n=[];for(let[r,o]of t.entries()){if(o.role==="system"){let a=r===0?N(o):Me(o);if(a.length>0)n.push({role:"system",content:g(a)});continue}if(o.role==="user"){if(typeof o.content==="string"){n.push({role:"user",content:g(o.content)});continue}let a=o.content.some((c)=>c.type==="image"),i=o.content.filter((c)=>c.type==="text"||e).map((c)=>{if(c.type==="text")return{type:"text",text:g(c.text)};return{type:"image_url",imageUrl:`data:${c.mimeType};base64,${c.data}`}});if(i.length>0){n.push({role:"user",content:i});continue}if(a&&!e)n.push({role:"user",content:"(image omitted: model does not support images)"});continue}if(o.role==="assistant"){let a=[],i=[];for(let d of o.content){if(d.type==="text"){if(d.text.trim().length>0)a.push({type:"text",text:g(d.text)});continue}if(d.type==="thinking"){if(d.thinking.trim().length>0)a.push({type:"thinking",thinking:[{type:"text",text:g(d.thinking)}]});continue}i.push({id:d.id,type:"function",function:{name:d.name,arguments:JSON.stringify(d.arguments||{})},index:0})}let c={role:"assistant",prefix:!1};if(a.length>0)c.content=a;if(i.length>0)c.toolCalls=i;if(a.length>0||i.length>0)n.push(c);continue}let s=[],l=o.content.filter((a)=>a.type==="text").map((a)=>a.type==="text"?g(a.text):"").join(`
4
+ `),f=o.content.some((a)=>a.type==="image"),u=de(l,f,e,o.isError);s.push({type:"text",text:u});for(let a of o.content){if(!e)continue;if(a.type!=="image")continue;s.push({type:"image_url",imageUrl:`data:${a.mimeType};base64,${a.data}`})}n.push({role:"tool",toolCallId:o.toolCallId,name:o.toolName,content:s})}return n}function de(t,e,n,r){let o=t.trim(),s=r?"[tool error] ":"";if(o.length>0)return`${s}${o}${e&&!n?`
5
+ [tool image omitted: model does not support images]`:""}`;if(e){if(n)return r?"[tool error] (see attached image)":"(see attached image)";return r?"[tool error] (image omitted: model does not support images)":"(image omitted: model does not support images)"}return r?"[tool error] (no tool output)":"(no tool output)"}function ue(t){if(!t)return;if(t==="auto"||t==="none"||t==="any"||t==="required")return t;return{type:"function",function:{name:t.function.name}}}function pe(t){if(t===null)return{stopReason:"stop"};switch(t){case"stop":return{stopReason:"stop"};case"length":case"model_length":return{stopReason:"length"};case"tool_calls":return{stopReason:"toolUse"};case"error":return{stopReason:"error",errorMessage:"Provider stopped with: error (server error)"};default:return{stopReason:"error",errorMessage:`Provider stopped with: ${t}`}}}export{D as stream,Ee as streamSimple};