@bkm016/basalt 0.1.4 → 0.1.6
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.
- package/README.md +61 -11
- package/{chunk-y648fzx0.js → chunk-0039s4jt.js} +3 -3
- package/{chunk-rmj5b73e.js → chunk-053vb71h.js} +1 -1
- package/{chunk-whvj83b7.js → chunk-063vbmtp.js} +2 -2
- package/{chunk-7tbya5b5.js → chunk-0javrjcm.js} +22 -22
- package/{chunk-y7nma9rk.js → chunk-10p3mb40.js} +2 -2
- package/{chunk-jk25nt60.js → chunk-39vwrg8n.js} +2 -2
- package/chunk-3k627vf2.js +3 -0
- package/{chunk-q7t30zz2.js → chunk-6kdgk70p.js} +5 -5
- package/{chunk-3x94302m.js → chunk-6ptv4g5e.js} +3 -3
- package/chunk-75434aay.js +2 -0
- package/{chunk-2zp1mv3q.js → chunk-7hr6zw2m.js} +1 -1
- package/{chunk-g2t6t8fk.js → chunk-7jezts2n.js} +2 -2
- package/{chunk-y58ygzn9.js → chunk-818nd6s1.js} +3 -3
- package/{chunk-k23t7vhs.js → chunk-8gw5bvh3.js} +5 -5
- package/{chunk-vv7fp27r.js → chunk-8mezk0cb.js} +2 -2
- package/{chunk-zggzfa7j.js → chunk-8saewt61.js} +2 -2
- package/{chunk-362g64pd.js → chunk-8wj32837.js} +1 -1
- package/{chunk-fjtvjrkg.js → chunk-8wv5t0w6.js} +5 -5
- package/{chunk-vk1gxk1t.js → chunk-8x21n7y9.js} +1 -1
- package/chunk-a0c989ky.js +2 -0
- package/{chunk-4w17tzp5.js → chunk-a5apjjcn.js} +12 -12
- package/chunk-a81p46j7.js +2 -0
- package/chunk-agsfy9w7.js +2 -0
- package/{chunk-fw2bpqmw.js → chunk-arcqjt91.js} +1 -1
- package/chunk-bdy4jksd.js +2 -0
- package/{chunk-qe0teyn1.js → chunk-benrzwea.js} +1 -1
- package/{chunk-0y7ne3d0.js → chunk-bwawt15q.js} +2 -2
- package/{chunk-pxsrqrd0.js → chunk-c4qr1f41.js} +2 -2
- package/{chunk-981f9dw8.js → chunk-c7rcw9fb.js} +6 -6
- package/{chunk-cjc90f84.js → chunk-ca982n62.js} +3 -3
- package/chunk-d20p02ny.js +2 -0
- package/{chunk-97rzj7f6.js → chunk-d6p2hgxh.js} +1 -1
- package/{chunk-k6w6y71k.js → chunk-dnx91jrd.js} +2 -2
- package/{chunk-8d46jtbj.js → chunk-dpz4hwqb.js} +2 -2
- package/{chunk-aky4tztg.js → chunk-ebpyvs1d.js} +2 -2
- package/{chunk-m40gxwq4.js → chunk-ecf896fz.js} +3 -3
- package/{chunk-pjyn2s97.js → chunk-ejsneb6f.js} +1 -1
- package/{chunk-pbcy6zdt.js → chunk-ey15ye2h.js} +1 -1
- package/{chunk-kp22kaez.js → chunk-f156y565.js} +2 -2
- package/{chunk-9rmqgc3c.js → chunk-f544p9rh.js} +15 -15
- package/chunk-fmq3zwzk.js +2 -0
- package/{chunk-em187cy3.js → chunk-fx7f4m3c.js} +2 -2
- package/{chunk-r7fpkb49.js → chunk-g0t9c3gv.js} +1 -1
- package/{chunk-mvfsxdx6.js → chunk-gv7wqkey.js} +10 -10
- package/chunk-hksqjts3.js +3884 -0
- package/{chunk-ztsjgssj.js → chunk-j7yvh0ae.js} +1 -1
- package/chunk-kns4kv7b.js +3 -0
- package/{chunk-nmca5h6m.js → chunk-n85qs7cs.js} +1 -1
- package/{chunk-8wc8qdx8.js → chunk-n981vx1t.js} +6 -6
- package/{chunk-3ct2tkr8.js → chunk-npez1492.js} +2 -2
- package/{chunk-t6zs4kw0.js → chunk-peja51xv.js} +2 -2
- package/{chunk-r0scgfwx.js → chunk-pg5nkf1y.js} +2 -2
- package/{chunk-7afmgncg.js → chunk-prgm07j4.js} +1 -1
- package/{chunk-jwdb0ccj.js → chunk-q9dd6fhj.js} +3 -3
- package/{chunk-ykens1hy.js → chunk-r8vvcp6c.js} +1 -1
- package/chunk-rfb85nj7.js +2 -0
- package/{chunk-ev6yvy5y.js → chunk-rfdt992v.js} +15 -15
- package/{chunk-xfvvh1s5.js → chunk-s6dejhfj.js} +1 -1
- package/{chunk-xh3vr5vz.js → chunk-s7skpgm2.js} +1 -1
- package/chunk-tgfbtehh.js +480 -0
- package/{chunk-m8vkwdgr.js → chunk-w67dvqtb.js} +4 -4
- package/{chunk-f3xadvab.js → chunk-whj87h4r.js} +2 -2
- package/{chunk-2hbfk5xd.js → chunk-wnzvnskb.js} +2 -2
- package/{chunk-vexrrw1b.js → chunk-xtq1xpq0.js} +2 -2
- package/{chunk-1vd0f74z.js → chunk-y8dkfpmj.js} +5 -5
- package/{chunk-shadcb9z.js → chunk-z02sj1je.js} +2 -2
- package/{chunk-akr0a8nc.js → chunk-zxkq9m8e.js} +1 -1
- package/compiled.js +12 -12
- package/package.json +1 -1
- package/ui-test-worker.js +32 -32
- package/web/{chunk-t4c8xavd.js → chunk-03dmzvaq.js} +7 -7
- package/web/{chunk-n8sky2q6.js → chunk-07agqp8h.js} +1 -1
- package/web/chunk-0fgaepwm.js +3 -0
- package/web/chunk-0gg00f86.js +292 -0
- package/web/chunk-0pecj6d7.js +1 -0
- package/web/{chunk-ts7zrf5b.js → chunk-0whceqes.js} +2 -2
- package/web/chunk-0wt1dgny.js +1 -0
- package/web/{chunk-sfg2wkhe.js → chunk-12xxh71x.js} +6 -6
- package/web/chunk-1ves7sq5.js +1 -0
- package/web/chunk-1yj79b48.js +1 -0
- package/web/chunk-296hgy6k.js +370 -0
- package/web/{chunk-f4tacm06.js → chunk-2bmq1whf.js} +1 -1
- package/web/chunk-2wqxhqr9.js +1 -0
- package/web/{chunk-2j4m0bh1.js → chunk-30b33r2w.js} +2 -2
- package/web/{chunk-sspfxp5e.js → chunk-30zfw7zg.js} +1 -1
- package/web/chunk-39ng8zwx.css +1 -0
- package/web/chunk-3de552rg.js +70 -0
- package/web/chunk-3nbzj48p.js +36 -0
- package/web/{chunk-0z0y25zf.js → chunk-3zebd9fq.js} +3 -3
- package/web/chunk-4r1n98zx.js +2 -0
- package/web/chunk-59678wmg.js +1 -0
- package/web/{chunk-ds7srg4p.js → chunk-5nda24gv.js} +1 -1
- package/web/chunk-5v44qv67.js +303 -0
- package/web/chunk-5wdk97mk.js +4 -0
- package/web/chunk-64rafq66.js +78 -0
- package/web/chunk-6bwgdvf6.js +1 -0
- package/web/chunk-6kkw9ptc.js +1 -0
- package/web/chunk-718mr5gc.js +2 -0
- package/web/chunk-7hs57qdr.js +1 -0
- package/web/chunk-7kp237t3.js +106 -0
- package/web/chunk-86p42kym.js +1 -0
- package/web/chunk-8n79cqyd.js +1 -0
- package/web/chunk-8r0s8tx7.js +1 -0
- package/web/chunk-96v2avmw.js +40 -0
- package/web/chunk-9an6wcnr.js +1 -0
- package/web/{chunk-5z4jcqct.js → chunk-9c1yt2ex.js} +20 -20
- package/web/chunk-9w5tf22s.js +1 -0
- package/web/{chunk-pws2seas.js → chunk-a7gtb4kg.js} +19 -19
- package/web/chunk-ahztazsg.js +1 -0
- package/web/chunk-b985y17w.js +2 -0
- package/web/chunk-bz2v64xe.js +1 -0
- package/web/{chunk-n1dmrz44.js → chunk-c01176kn.js} +2 -2
- package/web/chunk-c3nn0vvc.js +1 -0
- package/web/chunk-cb2rxtq9.js +2 -0
- package/web/{chunk-b1bgzz66.js → chunk-ck8rr0sr.js} +1 -1
- package/web/{chunk-aqfpnhmt.js → chunk-cktmyc13.js} +19 -19
- package/web/{chunk-rvrf0f3h.js → chunk-cm92fyr3.js} +2 -2
- package/web/chunk-cwtn2kdm.js +1 -0
- package/web/chunk-czq1yz51.js +99 -0
- package/web/chunk-d22wq71s.js +1 -0
- package/web/{chunk-pjkdrgm0.js → chunk-d4z2rgpx.js} +1 -1
- package/web/{chunk-hvw3gn2a.js → chunk-d6tbw8br.js} +20 -20
- package/web/{chunk-cg3jterp.js → chunk-d9wdsjkk.js} +2 -2
- package/web/{chunk-ttg6tbwx.js → chunk-da7m1kva.js} +2 -2
- package/web/chunk-dpkyygej.js +1 -0
- package/web/{chunk-0b47eyrf.js → chunk-dwajwrpk.js} +1 -1
- package/web/chunk-et5ess72.js +1 -0
- package/web/chunk-ez8b6neq.js +1 -0
- package/web/{chunk-bhsaj6qq.js → chunk-f5txt81n.js} +1 -1
- package/web/chunk-fd1kqwe3.js +1 -0
- package/web/chunk-fmthkpff.js +1 -0
- package/web/chunk-fp48zz2e.js +2 -0
- package/web/{chunk-n90cqdvg.js → chunk-fv6vm14n.js} +2 -2
- package/web/chunk-fx0n2g22.js +89 -0
- package/web/{chunk-9cx1be43.js → chunk-fxs4nb93.js} +16 -16
- package/web/chunk-g6k9z8zt.js +1 -0
- package/web/{chunk-42e3b9hv.js → chunk-g81h1e6n.js} +19 -19
- package/web/{chunk-pz9ps2jm.js → chunk-gsh80797.js} +12 -12
- package/web/{chunk-54thej0t.js → chunk-gyp6v7jd.js} +2 -2
- package/web/chunk-h0c42zy3.js +1 -0
- package/web/{chunk-6m69hczt.js → chunk-h6k1x096.js} +2 -2
- package/web/chunk-hs5x78fb.js +1 -0
- package/web/{chunk-zx8zec24.js → chunk-ht1dzftc.js} +56 -56
- package/web/{chunk-d11v5s7w.js → chunk-hy4m34qp.js} +6 -6
- package/web/chunk-hyd5hzpa.js +1 -0
- package/web/chunk-hyt1nkaw.js +1 -0
- package/web/{chunk-24mfx6w1.js → chunk-j1bw5v1g.js} +2 -2
- package/web/chunk-j6a4z530.js +1139 -0
- package/web/{chunk-0pbjgdgp.js → chunk-ja7w629n.js} +2 -2
- package/web/{chunk-zbj1trar.js → chunk-jam45rqg.js} +2 -2
- package/web/chunk-jfvxxp5c.js +1 -0
- package/web/{chunk-kmr7r9xj.js → chunk-jve1zc80.js} +2 -2
- package/web/chunk-kegv14sg.js +2 -0
- package/web/chunk-kw9emsqw.js +1 -0
- package/web/{chunk-df5zx17h.js → chunk-kyawkpv2.js} +1 -1
- package/web/chunk-m2prjwk3.js +4 -0
- package/web/chunk-m9bzz9m0.js +19 -0
- package/web/chunk-mqsyzzgt.js +30 -0
- package/web/chunk-mz9b5bsa.js +1 -0
- package/web/chunk-n1jpg57t.js +169 -0
- package/web/{chunk-ybrf9mhz.js → chunk-nyn9tghz.js} +4 -4
- package/web/{chunk-1eg9sbbt.js → chunk-nywdeb4m.js} +2 -2
- package/web/chunk-prvh9syp.js +324 -0
- package/web/chunk-pxkhm40r.js +2 -0
- package/web/{chunk-6cnek1xh.js → chunk-q9ekgjh6.js} +1 -1
- package/web/{chunk-xzp7jf7e.js → chunk-qcge7d6s.js} +2 -2
- package/web/chunk-r3mj50zs.js +1 -0
- package/web/{chunk-wnskxerq.js → chunk-rf9dt6bg.js} +5 -5
- package/web/{chunk-nvhmq4z5.js → chunk-s2920f21.js} +6 -6
- package/web/chunk-sc0ghp25.js +24 -0
- package/web/{chunk-ydtrc1ay.js → chunk-sd3cdqcm.js} +2 -2
- package/web/{chunk-rykfak98.js → chunk-sf101c23.js} +2 -2
- package/web/{chunk-4gavbw65.js → chunk-sy7e4dmq.js} +1 -1
- package/web/chunk-t74r2n8h.js +1 -0
- package/web/{chunk-0h0vb6gt.js → chunk-t851gdjh.js} +4 -4
- package/web/{chunk-a408enpy.js → chunk-t9mvsgt9.js} +1 -1
- package/web/chunk-thbqwq6b.js +1 -0
- package/web/{chunk-v5cnt7c8.js → chunk-twdy2f67.js} +1 -1
- package/web/chunk-v4yqrx5y.js +140 -0
- package/web/{chunk-b53bfkys.js → chunk-vf4vkcf9.js} +1 -1
- package/web/chunk-vnt34mkb.js +1 -0
- package/web/chunk-vtxw9rmr.js +1 -0
- package/web/{chunk-92ssjk2y.js → chunk-vw1pbv1x.js} +40 -40
- package/web/chunk-x19v2sxv.js +1 -0
- package/web/{chunk-3re8y26v.js → chunk-x5s7zr5f.js} +7 -7
- package/web/chunk-xc2sq3t5.js +2 -0
- package/web/chunk-xce8n339.js +1 -0
- package/web/chunk-xtss82z2.js +1 -0
- package/web/chunk-xvcfp1zh.js +2 -0
- package/web/chunk-y21zy3eh.js +1 -0
- package/web/chunk-ya3ghn3n.js +2 -0
- package/web/chunk-yd74yxzt.js +8 -0
- package/web/{chunk-74j07k8k.js → chunk-z1geewdf.js} +2 -2
- package/web/chunk-z4ha8181.js +1 -0
- package/web/chunk-z8rarqe6.js +1 -0
- package/web/{chunk-kwccs9f6.js → chunk-zp3qrrkb.js} +11 -11
- package/web/chunk-zsxw5fj7.js +39 -0
- package/web/index.html +1 -1
- package/worker.js +1 -1
- package/chunk-06hdzq5n.js +0 -2
- package/chunk-5dfbezv9.js +0 -2
- package/chunk-5x1sankd.js +0 -3753
- package/chunk-71h08f4g.js +0 -2
- package/chunk-7nzhdrv9.js +0 -2
- package/chunk-7q51n619.js +0 -2
- package/chunk-9mmz6wt3.js +0 -2
- package/chunk-fvn32nzj.js +0 -478
- package/chunk-n6e43rvk.js +0 -3
- package/chunk-ry0z4ev6.js +0 -2
- package/chunk-vkpvcxjr.js +0 -2
- package/web/chunk-0rmkpsgp.js +0 -1
- package/web/chunk-0s80zw00.js +0 -1
- package/web/chunk-0xkyryrq.js +0 -1
- package/web/chunk-1gbd61z0.js +0 -2
- package/web/chunk-2s0bmrkv.js +0 -39
- package/web/chunk-2z1rwr28.js +0 -2
- package/web/chunk-344bq59c.js +0 -89
- package/web/chunk-3t0211rw.js +0 -1
- package/web/chunk-44rmrmcn.js +0 -1
- package/web/chunk-4bzqrwr0.js +0 -1139
- package/web/chunk-4d3a7xs2.js +0 -1
- package/web/chunk-4jmazh6x.js +0 -370
- package/web/chunk-4re74xwm.js +0 -140
- package/web/chunk-4rm1vy7w.js +0 -1
- package/web/chunk-59kqahb3.js +0 -1
- package/web/chunk-5qtyq3ce.js +0 -292
- package/web/chunk-5z6x2n5h.js +0 -1
- package/web/chunk-6beqrmtq.js +0 -1
- package/web/chunk-6f5ke0x9.js +0 -1
- package/web/chunk-6xaqxcq8.js +0 -1
- package/web/chunk-7q6wvv2x.js +0 -1
- package/web/chunk-7qsa4p8h.js +0 -1
- package/web/chunk-8nja0ygy.js +0 -1
- package/web/chunk-8y64fkpz.js +0 -24
- package/web/chunk-9ad7v7bm.js +0 -8
- package/web/chunk-9dzxv335.js +0 -4
- package/web/chunk-9t5dnjaz.js +0 -19
- package/web/chunk-a497tykb.js +0 -70
- package/web/chunk-b6k9w215.js +0 -2
- package/web/chunk-cjfssg3m.js +0 -2
- package/web/chunk-cqp1d4p0.js +0 -1
- package/web/chunk-dy2gm1fs.js +0 -1
- package/web/chunk-e0zre35a.js +0 -1
- package/web/chunk-e9twvs9n.js +0 -3
- package/web/chunk-f2kgtyfp.js +0 -1
- package/web/chunk-f8bn5tzf.js +0 -1
- package/web/chunk-f91wzwtk.js +0 -1
- package/web/chunk-fdp9bsj7.js +0 -1
- package/web/chunk-fh2vj0wv.js +0 -2
- package/web/chunk-g1ev11wx.js +0 -1
- package/web/chunk-gmzqdm7v.js +0 -1
- package/web/chunk-hfaffkrh.js +0 -1
- package/web/chunk-j2vt8c8v.js +0 -1
- package/web/chunk-ka3q31t1.js +0 -1
- package/web/chunk-khxcn8tt.js +0 -106
- package/web/chunk-kqqmp1am.js +0 -1
- package/web/chunk-m2d1sp30.js +0 -1
- package/web/chunk-nbgqbxcy.js +0 -1
- package/web/chunk-ncpnpe9w.js +0 -99
- package/web/chunk-ne0v8mfb.js +0 -2
- package/web/chunk-ngx2cp8x.js +0 -2
- package/web/chunk-nxcgf7ec.js +0 -1
- package/web/chunk-p0kvmf28.js +0 -2
- package/web/chunk-p3k7m5nr.js +0 -1
- package/web/chunk-pggaffrh.js +0 -169
- package/web/chunk-pxe3vna4.js +0 -1
- package/web/chunk-qh15dxav.css +0 -1
- package/web/chunk-qpmbxhh6.js +0 -1
- package/web/chunk-r0rctnxz.js +0 -1
- package/web/chunk-rn3dnqm8.js +0 -1
- package/web/chunk-rtf2zzzv.js +0 -1
- package/web/chunk-srrfphes.js +0 -1
- package/web/chunk-tdr6x2xc.js +0 -1
- package/web/chunk-tncvg1nn.js +0 -1
- package/web/chunk-vyp0ns1f.js +0 -2
- package/web/chunk-wvdehm9y.js +0 -303
- package/web/chunk-x7ahcpj7.js +0 -1
- package/web/chunk-y38bf0wm.js +0 -1
- package/web/chunk-y56aaba5.js +0 -2
- package/web/chunk-ye58t45p.js +0 -4
- package/web/chunk-yqbnps3a.js +0 -1
- package/web/chunk-z1h20s8c.js +0 -78
- package/web/chunk-zj4q9jth.js +0 -36
- package/web/chunk-zj5k94dk.js +0 -40
- package/web/chunk-zqch0sc8.js +0 -30
- package/web/install.ps1 +0 -91
- package/web/install.sh +0 -177
package/README.md
CHANGED
|
@@ -85,16 +85,20 @@ npm i -g @bkm016/basalt
|
|
|
85
85
|
# 或使用 Bun 全局安装
|
|
86
86
|
bun i -g @bkm016/basalt
|
|
87
87
|
|
|
88
|
-
#
|
|
89
|
-
basalt
|
|
88
|
+
# 后台启动并打开工作台(就绪后命令返回,服务继续运行)
|
|
89
|
+
basalt --open
|
|
90
|
+
|
|
91
|
+
# 提示 command not found 时(Bun 的全局 bin 目录不在 PATH),先用完整路径运行一次 setup,再重开终端
|
|
92
|
+
~/.bun/bin/basalt setup
|
|
90
93
|
```
|
|
91
94
|
|
|
92
|
-
|
|
95
|
+
升级:服务运行时每 6 小时查一次 npm 上的最新版本,按安装方式自动用 npm 或 bun 全局安装,并等所有对话空闲后按原参数重启,不会打断进行中的对话。也可以手动更新,运行中的服务同样会在空闲时切换到新版本:
|
|
93
96
|
|
|
94
97
|
```bash
|
|
98
|
+
basalt update
|
|
99
|
+
# 或直接用包管理器
|
|
95
100
|
npm i -g @bkm016/basalt@latest
|
|
96
|
-
|
|
97
|
-
bun i -g @bkm016/basalt@latest
|
|
101
|
+
bun add -g @bkm016/basalt@latest
|
|
98
102
|
```
|
|
99
103
|
|
|
100
104
|
### 从源码运行
|
|
@@ -104,14 +108,39 @@ bun i -g @bkm016/basalt@latest
|
|
|
104
108
|
```bash
|
|
105
109
|
bun install
|
|
106
110
|
bun run dev # 启动开发服务器(支持热重载)
|
|
107
|
-
bun packages/cli/src/main.ts --demo
|
|
111
|
+
bun packages/cli/src/main.ts --demo --open # 无需 API Key,使用内置演示模型体验工作台
|
|
108
112
|
```
|
|
109
113
|
|
|
110
114
|
### 配对与首次使用
|
|
111
115
|
|
|
112
|
-
1.
|
|
116
|
+
1. 首次启动建议使用 `basalt --open`,服务就绪后会自动在浏览器中打开带配对链接的工作台。未使用 `--open` 或配对码已过期时,在服务所在机器上运行 `basalt pair`,即可生成 10 分钟有效的一次性配对码及配对链接。
|
|
113
117
|
2. 首次进入工作台若尚未配置模型,界面会引导前往「设置 → 模型」添加服务商与 API Key,也可直接通过环境变量(如 `ANTHROPIC_API_KEY`、`OPENAI_API_KEY`)提供。
|
|
114
118
|
|
|
119
|
+
### 远程访问(Cloudflare 隧道)
|
|
120
|
+
|
|
121
|
+
用自己域名下的**固定主机名**,从手机或另一台电脑访问这台机器上的 Basalt。前提:域名托管在 Cloudflare,本机装好 [`cloudflared`](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/)。
|
|
122
|
+
|
|
123
|
+
在工作台 **设置 → 远程访问** 里按向导走,全程不用进 Cloudflare 后台:
|
|
124
|
+
|
|
125
|
+
1. **连接 Cloudflare 账号**:点「连接 Cloudflare」,Basalt 会给出一个授权链接。在浏览器(手机也行)里打开它,登录并选择你的域名,点授权。完成后页面自动继续。
|
|
126
|
+
2. **选一个访问地址**:填该域名下的子域名,如 `basalt.example.com`。
|
|
127
|
+
3. **创建并连接**:Basalt 通过 `cloudflared` 自动创建隧道、添加域名解析、写好转发配置并连接。
|
|
128
|
+
|
|
129
|
+
之后每次启动 `basalt` 都会自动带起隧道,随 Basalt 退出而退出,掉线自动重连;终端里的配对二维码和链接改用 `https://basalt.example.com`。授权证书和隧道凭据保存在数据目录的 `cloudflared/` 下,不会写进你自己的 `~/.cloudflared`。
|
|
130
|
+
|
|
131
|
+
已经在 Cloudflare 后台建好隧道的人,向导里点「我已有隧道令牌」,把后台给出的安装命令整段粘贴进来即可(也可用命令行:`BASALT_TUNNEL_TOKEN=<令牌> basalt tunnel set basalt.example.com`;`basalt tunnel status` / `basalt tunnel off` 查看或删除)。令牌模式下,隧道的服务地址要在 Cloudflare 里填 `http://localhost:<端口>`,设置页会显示端口。
|
|
132
|
+
|
|
133
|
+
**可选:Cloudflare Access(再加一道只认你的登录)**
|
|
134
|
+
|
|
135
|
+
配好之后在同一页的「Access 校验」点「设置」。在 Cloudflare 后台(菜单名按官方文档原文):`Zero Trust › Access controls › Applications › Create new application › Self-hosted and private`,域名填你的主机名,策略选你的邮箱;应用的 `Configure › Additional settings` 里复制 **Audience Tag**,团队域名是 `团队名.cloudflareaccess.com`,填回 Basalt。之后经隧道进来的请求必须带 Cloudflare 签发的有效 JWT,否则被直接拒绝。
|
|
136
|
+
|
|
137
|
+
**安全说明**
|
|
138
|
+
|
|
139
|
+
- 配置了远程访问就不能用 `--no-auth` 启动,设置页也会拒绝在免认证服务上开启。
|
|
140
|
+
- 配了 Access 后,Basalt 会校验 Cloudflare 签发的 `Cf-Access-Jwt-Assertion`(签名、颁发者、Audience、有效期;公钥取自团队域名的 `/cdn-cgi/access/certs`):**经隧道进来**且没有合法凭据的请求会被直接 403,即使 Access 策略被误改成放行也不会只剩 Basalt 自己的令牌守着公网。本机直连不受影响。
|
|
141
|
+
- 直接用 `https://你的主机名` 打开时,页面与 API 同源,无需额外设置。若用 basalt.work 等其他网址连接,需要在 Access 应用里为跨域请求开启「Bypass OPTIONS」,并在添加服务器时填写服务令牌请求头(`CF-Access-Client-Id` / `CF-Access-Client-Secret`)。
|
|
142
|
+
- 远程设备只能用终端里的配对码配对;「本机免码授权」对经隧道的请求不可用。
|
|
143
|
+
|
|
115
144
|
---
|
|
116
145
|
|
|
117
146
|
## 命令行与配置参考
|
|
@@ -119,22 +148,35 @@ bun packages/cli/src/main.ts --demo # 无需 API Key,使用内置演示模
|
|
|
119
148
|
### CLI 选项
|
|
120
149
|
|
|
121
150
|
```text
|
|
122
|
-
用法: basalt [选项]
|
|
123
|
-
basalt
|
|
151
|
+
用法: basalt [选项] 后台启动服务,就绪后返回
|
|
152
|
+
basalt status 查看服务状态
|
|
153
|
+
basalt stop 停止服务
|
|
154
|
+
basalt restart 按原参数重启服务
|
|
155
|
+
basalt logs 查看最近后台日志
|
|
156
|
+
basalt pair 为运行中的服务生成新配对码和配对链接
|
|
157
|
+
basalt autostart <enable|disable|status> 管理登录自启
|
|
158
|
+
basalt update 用安装时的 npm/bun 更新到最新版本(运行中的服务空闲时自动重启)
|
|
159
|
+
basalt setup 把 basalt 所在目录加入 PATH(装完提示找不到命令时用)
|
|
124
160
|
basalt plugin reload <id> [--data <目录>]
|
|
161
|
+
basalt tunnel set <主机名> [--token <令牌>] [--team <团队域名> --aud <Audience>]
|
|
162
|
+
basalt tunnel off | status 远程访问(Cloudflare 隧道)
|
|
125
163
|
|
|
126
164
|
选项:
|
|
127
165
|
--host <地址> 监听地址(默认 127.0.0.1,仅本机回环)
|
|
128
166
|
--port <端口> 监听端口(默认 7420)
|
|
129
167
|
--open 启动后在浏览器里打开工作台(带配对链接)
|
|
168
|
+
--foreground 在前台运行服务,供调试、launchd 和 systemd 使用
|
|
130
169
|
--replace 已有实例在运行时先停止旧实例再启动
|
|
131
170
|
--model <provider/id> 指定启动时默认使用的模型(如 anthropic/claude-sonnet-4-20250514)
|
|
132
171
|
--demo 启用内置演示模型(demo/echo,无需 API Key)
|
|
133
172
|
--data <目录> 指定运行时数据目录(默认遵循平台规范或 BASALT_HOME)
|
|
134
173
|
--web-url <地址> 生成配对链接时使用的外部 Web 工作台地址
|
|
135
174
|
--allow-origin <来源> 允许跨域访问的 Web 来源,可多次传入;* 表示允许任意来源
|
|
175
|
+
--token <令牌> tunnel set 用:隧道令牌(更推荐用环境变量,避免进 shell 历史)
|
|
176
|
+
--team <团队域名> tunnel set 用:Access 团队域名
|
|
177
|
+
--aud <Audience> tunnel set 用:Access 应用的 Audience 标签
|
|
136
178
|
--no-tray 不启动系统托盘图标
|
|
137
|
-
--no-update-check
|
|
179
|
+
--no-update-check 不自动检查和安装新版本(也可设 BASALT_NO_UPDATE_CHECK=1)
|
|
138
180
|
--no-auth 关闭令牌认证(仅本机监听可用,或需配合 --allow-remote-no-auth)
|
|
139
181
|
--insecure-http 允许在非本机回环地址上使用明文 HTTP 监听
|
|
140
182
|
--allow-remote-no-auth 允许在非本机回环地址上关闭认证(极不安全,仅限受控隔离环境)
|
|
@@ -142,6 +184,12 @@ bun packages/cli/src/main.ts --demo # 无需 API Key,使用内置演示模
|
|
|
142
184
|
-h, --help 显示帮助信息
|
|
143
185
|
```
|
|
144
186
|
|
|
187
|
+
默认 `basalt` 会在后台启动服务,等待 HTTP 就绪后返回终端;需要查看实时输出或由服务管理器托管时使用 `--foreground`。`basalt restart` 沿用当前实例的参数和工作目录,`basalt logs` 读取最近 256 KB 后台日志。
|
|
188
|
+
|
|
189
|
+
执行一次 `basalt autostart enable` 即可注册当前用户的登录自启:Windows 使用隐藏启动脚本,macOS 使用 LaunchAgent,Linux 使用 systemd 用户服务。启动项固定当前 Bun/npm 包入口,登录时不会联网安装或升级;`disable` 关闭自启,`status` 查看配置。启用时会沿用正在运行实例的参数,不会改变或重启当前服务。
|
|
190
|
+
|
|
191
|
+
自启只保存启动参数、数据目录和工作目录,不复制当前终端的环境变量。只在交互式 shell 中设置的 API Key、`BASALT_MODEL` 等变量不会自动带入登录会话;请在 Web 中配置模型,或把所需变量配置到系统用户环境。
|
|
192
|
+
|
|
145
193
|
### 环境变量
|
|
146
194
|
|
|
147
195
|
| 环境变量 | 说明 |
|
|
@@ -149,7 +197,8 @@ bun packages/cli/src/main.ts --demo # 无需 API Key,使用内置演示模
|
|
|
149
197
|
| `BASALT_HOME` | 显式指定 Basalt 数据根目录,优先级高于平台默认路径。 |
|
|
150
198
|
| `BASALT_MODEL` | 默认启动模型标识符(格式为 `<provider>/<model-id>`),命令行 `--model` 优先级高于此变量。 |
|
|
151
199
|
| `BASALT_TOKEN` | 执行 `basalt plugin reload <id>` 等 CLI 进程外管理命令时,用于向已开启认证的运行中服务提供设备令牌。 |
|
|
152
|
-
| `
|
|
200
|
+
| `BASALT_TUNNEL_TOKEN` | `basalt tunnel set` 读取的 Cloudflare 隧道令牌,等价于 `--token`。 |
|
|
201
|
+
| `BASALT_NO_UPDATE_CHECK` | 设为 `1` 时禁用后台自动检查与安装新版本;手动装好的新版本仍会在对话空闲时生效。 |
|
|
153
202
|
| `ANTHROPIC_API_KEY` / `OPENAI_API_KEY` 等 | 由 `@earendil-works/pi-ai` 自动识别的上游模型提供商凭据。 |
|
|
154
203
|
|
|
155
204
|
### 数据目录与存储布局
|
|
@@ -168,6 +217,7 @@ bun packages/cli/src/main.ts --demo # 无需 API Key,使用内置演示模
|
|
|
168
217
|
├── search.db # 独立 Worker 维护的会话历史全文检索索引库
|
|
169
218
|
├── models.json # Web 端配置的自定义模型提供商与脱敏凭据持久化文件
|
|
170
219
|
├── devices.json # 已配对设备的元数据与令牌 SHA-256 哈希记录
|
|
220
|
+
├── basalt.log # 后台服务标准输出与错误日志
|
|
171
221
|
├── server.json # 单实例运行锁文件(记录当前活动服务的 PID、监听 URL 与托盘句柄)
|
|
172
222
|
└── plugins/ # 用户级自定义插件目录(支持 <id>.ts 或 <id>/index.ts)
|
|
173
223
|
```
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
3
|
-
`).some((n)=>n.indexOf("(https.js:")!==-1||n.indexOf("node:https:")!==-1)}incrementSockets(e){if(this.maxSockets===1/0&&this.maxTotalSockets===1/0)return null;if(!this.sockets[e])this.sockets[e]=[];let t=new ue.Socket({writable:!1});return this.sockets[e].push(t),this.totalSocketCount++,t}decrementSockets(e,t){if(!this.sockets[e]||t===null)return;let n=this.sockets[e],o=n.indexOf(t);if(o!==-1){if(n.splice(o,1),this.totalSocketCount--,n.length===0)delete this.sockets[e]}}getName(e){if(this.isSecureEndpoint(e))return R.Agent.prototype.getName.call(this,e);return super.getName(e)}createSocket(e,t,n){let o={...t,secureEndpoint:this.isSecureEndpoint(t)},s=this.getName(o),a=this.incrementSockets(s);Promise.resolve().then(()=>this.connect(e,o)).then((i)=>{if(this.decrementSockets(s,a),i instanceof H.Agent)try{return i.addRequest(e,o)}catch(_){return n(_)}this[d].currentSocket=i,super.createSocket(e,t,n)},(i)=>{this.decrementSockets(s,a),n(i)})}createConnection(){let e=this[d].currentSocket;if(this[d].currentSocket=void 0,!e)throw Error("No socket was returned in the `connect()` function");return e}get defaultPort(){return this[d].defaultPort??(this.protocol==="https:"?443:80)}set defaultPort(e){if(this[d])this[d].defaultPort=e}get protocol(){return this[d].protocol??(this.isSecureEndpoint()?"https:":"http:")}set protocol(e){if(this[d])this[d].protocol=e}}u.Agent=k});var z=r(function(g){var ae=g&&g.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(g,"__esModule",{value:!0});g.parseProxyResponse=void 0;var fe=ae(
|
|
2
|
+
import{Bt}from"./chunk-818nd6s1.js";import{r,p}from"./chunk-bwawt15q.js";var T=r(function(c){var ee=c&&c.__createBinding||(Object.create?function(e,t,n,o){if(o===void 0)o=n;var s=Object.getOwnPropertyDescriptor(t,n);if(!s||("get"in s?!t.__esModule:s.writable||s.configurable))s={enumerable:!0,get:function(){return t[n]}};Object.defineProperty(e,o,s)}:function(e,t,n,o){if(o===void 0)o=n;e[o]=t[n]}),te=c&&c.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),B=c&&c.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null){for(var n in e)if(n!=="default"&&Object.prototype.hasOwnProperty.call(e,n))ee(t,e,n)}return te(t,e),t};Object.defineProperty(c,"__esModule",{value:!0});c.req=c.json=c.toBuffer=void 0;var re=B(p("http")),ne=B(p("https"));async function D(e){let t=0,n=[];for await(let o of e)t+=o.length,n.push(o);return Buffer.concat(n,t)}c.toBuffer=D;async function oe(e){let n=(await D(e)).toString("utf8");try{return JSON.parse(n)}catch(o){let s=o;throw s.message+=` (input: ${n})`,s}}c.json=oe;function se(e,t={}){let o=((typeof e==="string"?e:e.href).startsWith("https:")?ne:re).request(e,t),s=new Promise((a,i)=>{o.once("response",a).once("error",i).end()});return o.then=s.then.bind(s),o}c.req=se});var U=r(function(u){var I=u&&u.__createBinding||(Object.create?function(e,t,n,o){if(o===void 0)o=n;var s=Object.getOwnPropertyDescriptor(t,n);if(!s||("get"in s?!t.__esModule:s.writable||s.configurable))s={enumerable:!0,get:function(){return t[n]}};Object.defineProperty(e,o,s)}:function(e,t,n,o){if(o===void 0)o=n;e[o]=t[n]}),ie=u&&u.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),L=u&&u.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null){for(var n in e)if(n!=="default"&&Object.prototype.hasOwnProperty.call(e,n))I(t,e,n)}return ie(t,e),t},ce=u&&u.__exportStar||function(e,t){for(var n in e)if(n!=="default"&&!Object.prototype.hasOwnProperty.call(t,n))I(t,e,n)};Object.defineProperty(u,"__esModule",{value:!0});u.Agent=void 0;var ue=L(p("net")),H=L(p("http")),R=p("https");ce(T(),u);var d=Symbol("AgentBaseInternalState");class k extends H.Agent{constructor(e){super(e);this[d]={}}isSecureEndpoint(e){if(e){if(typeof e.secureEndpoint==="boolean")return e.secureEndpoint;if(typeof e.protocol==="string")return e.protocol==="https:"}let{stack:t}=Error();if(typeof t!=="string")return!1;return t.split(`
|
|
3
|
+
`).some((n)=>n.indexOf("(https.js:")!==-1||n.indexOf("node:https:")!==-1)}incrementSockets(e){if(this.maxSockets===1/0&&this.maxTotalSockets===1/0)return null;if(!this.sockets[e])this.sockets[e]=[];let t=new ue.Socket({writable:!1});return this.sockets[e].push(t),this.totalSocketCount++,t}decrementSockets(e,t){if(!this.sockets[e]||t===null)return;let n=this.sockets[e],o=n.indexOf(t);if(o!==-1){if(n.splice(o,1),this.totalSocketCount--,n.length===0)delete this.sockets[e]}}getName(e){if(this.isSecureEndpoint(e))return R.Agent.prototype.getName.call(this,e);return super.getName(e)}createSocket(e,t,n){let o={...t,secureEndpoint:this.isSecureEndpoint(t)},s=this.getName(o),a=this.incrementSockets(s);Promise.resolve().then(()=>this.connect(e,o)).then((i)=>{if(this.decrementSockets(s,a),i instanceof H.Agent)try{return i.addRequest(e,o)}catch(_){return n(_)}this[d].currentSocket=i,super.createSocket(e,t,n)},(i)=>{this.decrementSockets(s,a),n(i)})}createConnection(){let e=this[d].currentSocket;if(this[d].currentSocket=void 0,!e)throw Error("No socket was returned in the `connect()` function");return e}get defaultPort(){return this[d].defaultPort??(this.protocol==="https:"?443:80)}set defaultPort(e){if(this[d])this[d].defaultPort=e}get protocol(){return this[d].protocol??(this.isSecureEndpoint()?"https:":"http:")}set protocol(e){if(this[d])this[d].protocol=e}}u.Agent=k});var z=r(function(g){var ae=g&&g.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(g,"__esModule",{value:!0});g.parseProxyResponse=void 0;var fe=ae(Bt()),S=(0,fe.default)("https-proxy-agent:parse-proxy-response");function le(e){return new Promise((t,n)=>{let o=0,s=[];function a(){let h=e.read();if(h)j(h);else e.once("readable",a)}function i(){e.removeListener("end",_),e.removeListener("error",y),e.removeListener("readable",a)}function _(){i(),S("onend"),n(Error("Proxy connection ended before receiving CONNECT response"))}function y(h){i(),S("onerror %o",h),n(h)}function j(h){s.push(h),o+=h.length;let f=Buffer.concat(s,o),M=f.indexOf(`\r
|
|
4
4
|
\r
|
|
5
5
|
`);if(M===-1){S("have not received end of HTTP headers yet..."),a();return}let q=f.slice(0,M).toString("ascii").split(`\r
|
|
6
|
-
`),C=q.shift();if(!C)return e.destroy(),n(Error("No header received from proxy CONNECT response"));let A=C.split(" "),Y=+A[1],Z=A.slice(2).join(" "),b={};for(let v of q){if(!v)continue;let E=v.indexOf(":");if(E===-1)return e.destroy(),n(Error(`Invalid header from proxy CONNECT response: "${v}"`));let m=v.slice(0,E).toLowerCase(),N=v.slice(E+1).trimStart(),P=b[m];if(typeof P==="string")b[m]=[P,N];else if(Array.isArray(P))P.push(N);else b[m]=N}S("got proxy server response: %o %o",C,b),i(),t({connect:{statusCode:Y,statusText:Z,headers:b},buffered:f})}e.on("error",y),e.on("end",_),a()})}g.parseProxyResponse=le});var ge=r(function(l){var he=l&&l.__createBinding||(Object.create?function(e,t,n,o){if(o===void 0)o=n;var s=Object.getOwnPropertyDescriptor(t,n);if(!s||("get"in s?!t.__esModule:s.writable||s.configurable))s={enumerable:!0,get:function(){return t[n]}};Object.defineProperty(e,o,s)}:function(e,t,n,o){if(o===void 0)o=n;e[o]=t[n]}),de=l&&l.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),W=l&&l.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null){for(var n in e)if(n!=="default"&&Object.prototype.hasOwnProperty.call(e,n))he(t,e,n)}return de(t,e),t},G=l&&l.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(l,"__esModule",{value:!0});l.HttpsProxyAgent=void 0;var w=W(p("net")),F=W(p("tls")),pe=G(p("assert")),_e=G(
|
|
6
|
+
`),C=q.shift();if(!C)return e.destroy(),n(Error("No header received from proxy CONNECT response"));let A=C.split(" "),Y=+A[1],Z=A.slice(2).join(" "),b={};for(let v of q){if(!v)continue;let E=v.indexOf(":");if(E===-1)return e.destroy(),n(Error(`Invalid header from proxy CONNECT response: "${v}"`));let m=v.slice(0,E).toLowerCase(),N=v.slice(E+1).trimStart(),P=b[m];if(typeof P==="string")b[m]=[P,N];else if(Array.isArray(P))P.push(N);else b[m]=N}S("got proxy server response: %o %o",C,b),i(),t({connect:{statusCode:Y,statusText:Z,headers:b},buffered:f})}e.on("error",y),e.on("end",_),a()})}g.parseProxyResponse=le});var ge=r(function(l){var he=l&&l.__createBinding||(Object.create?function(e,t,n,o){if(o===void 0)o=n;var s=Object.getOwnPropertyDescriptor(t,n);if(!s||("get"in s?!t.__esModule:s.writable||s.configurable))s={enumerable:!0,get:function(){return t[n]}};Object.defineProperty(e,o,s)}:function(e,t,n,o){if(o===void 0)o=n;e[o]=t[n]}),de=l&&l.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),W=l&&l.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null){for(var n in e)if(n!=="default"&&Object.prototype.hasOwnProperty.call(e,n))he(t,e,n)}return de(t,e),t},G=l&&l.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(l,"__esModule",{value:!0});l.HttpsProxyAgent=void 0;var w=W(p("net")),F=W(p("tls")),pe=G(p("assert")),_e=G(Bt()),Q=U(),V=p("url"),X=z(),O=(0,_e.default)("https-proxy-agent"),J=(e)=>{if(e.servername===void 0&&e.host&&!w.isIP(e.host))return{...e,servername:e.host};return e};class x extends Q.Agent{constructor(e,t){super(t);this.options={path:void 0},this.proxy=typeof e==="string"?new V.URL(e):e,this.proxyHeaders=t?.headers??{},O("Creating new HttpsProxyAgent instance: %o",this.proxy.href);let n=(this.proxy.hostname||this.proxy.host).replace(/^\[|\]$/g,""),o=this.proxy.port?parseInt(this.proxy.port,10):this.proxy.protocol==="https:"?443:80;this.connectOpts={ALPNProtocols:["http/1.1"],...t?K(t,"headers"):null,host:n,port:o}}async connect(e,t){let{proxy:n}=this;if(!t.host)throw TypeError('No "host" provided');let o;if(n.protocol==="https:")O("Creating `tls.Socket`: %o",this.connectOpts),o=F.connect(J(this.connectOpts));else O("Creating `net.Socket`: %o",this.connectOpts),o=w.connect(this.connectOpts);let s=typeof this.proxyHeaders==="function"?this.proxyHeaders():{...this.proxyHeaders},a=w.isIPv6(t.host)?`[${t.host}]`:t.host,i=`CONNECT ${a}:${t.port} HTTP/1.1\r
|
|
7
7
|
`;if(n.username||n.password){let f=`${decodeURIComponent(n.username)}:${decodeURIComponent(n.password)}`;s["Proxy-Authorization"]=`Basic ${Buffer.from(f).toString("base64")}`}if(s.Host=`${a}:${t.port}`,!s["Proxy-Connection"])s["Proxy-Connection"]=this.keepAlive?"Keep-Alive":"close";for(let f of Object.keys(s))i+=`${f}: ${s[f]}\r
|
|
8
8
|
`;let _=X.parseProxyResponse(o);o.write(`${i}\r
|
|
9
9
|
`);let{connect:y,buffered:j}=await _;if(e.emit("proxyConnect",y),this.emit("proxyConnect",y,e),y.statusCode===200){if(e.once("socket",ye),t.secureEndpoint)return O("Upgrading socket connection to TLS"),F.connect({...K(J(t),"host","path","port"),socket:o});return o}o.destroy();let h=new w.Socket({writable:!1});return h.readable=!0,e.once("socket",(f)=>{O("Replaying proxy buffer for failed request"),(0,pe.default)(f.listenerCount("data")>0),f.push(j),f.push(null)}),h}}x.protocols=["http","https"];l.HttpsProxyAgent=x;function ye(e){e.resume()}function K(e,...t){let n={},o;for(o in e)if(!t.includes(o))n[o]=e[o];return n}});export default ge();
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
2
|
+
import{hr}from"./chunk-fx7f4m3c.js";import{se}from"./chunk-zxkq9m8e.js";var s="Cloudflare Workers AI";function n(r){if(Array.isArray(r)){let e=r.map((t)=>se(t)&&typeof t.message==="string"?t.message:void 0).filter((t)=>t!==void 0);if(e.length>0)return`${s} error: ${e.join("; ")}`}return`${s} request failed`}var o={api:"cloudflare-workers-ai-system-one",label:s,url:(r)=>new URL("run",`${r.baseUrl.replace(/\/+$/u,"")}/`),payload:(r,e)=>({model:r.id,input:e}),output:(r)=>{if(!se(r))throw Error(`${s} returned an unexpected response`);if(r.success===!1)throw Error(n(r.errors));let e=r.result;if(!se(e))throw Error(`${s} returned an unexpected response`);if("answers"in e)return e;if(e.state!=="Completed")throw Error(`${s} run did not complete (state: ${String(e.state)})`);if(!se(e.result))throw Error(`${s} returned an unexpected response`);return e.result}},i=(r,e,t)=>hr(o,r,e,t);export{i as classify};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{N,
|
|
3
|
-
export{me,
|
|
2
|
+
import{N,G}from"./chunk-n981vx1t.js";class p extends Error{}var L=["$ref","$defs","definitions","allOf","oneOf","patternProperties","dependentSchemas","dependencies","unevaluatedProperties","propertyNames","contains","prefixItems","not","if","then","else"];function y(e){return typeof e==="object"&&e!==null&&!Array.isArray(e)}function D(e){if(!y(e))return!1;let n=typeof e.type==="string"?[e.type]:Array.isArray(e.type)?e.type:[];return n.includes("object")||n.includes("array")||e.properties!==void 0||e.items!==void 0}function M(e){if(!y(e))return!1;if(e.type==="null"||Array.isArray(e.type)&&e.type.includes("null"))return!0;if(e.const===null||Array.isArray(e.enum)&&e.enum.includes(null))return!0;return Array.isArray(e.anyOf)&&e.anyOf.some((n)=>M(n))}function w(e,n){if(!y(e))throw new p("boolean schemas are unsupported");for(let a of L)if(e[a]!==void 0)throw new p(`${a} schemas are unsupported`);if(n){for(let[a,l]of Object.entries(e))if(n(a,l))throw new p(`${a}: ${JSON.stringify(l)} is unsupported`)}if(e.anyOf!==void 0){if(!Array.isArray(e.anyOf)||e.anyOf.length===0)throw new p("anyOf must contain at least one schema");for(let a of e.anyOf){if(D(a))throw new p("object and array unions are unsupported");w(a,n)}}if(e.items!==void 0){if(Array.isArray(e.items))throw new p("tuple schemas are unsupported");w(e.items,n)}let t=e.type==="object";if(e.properties!==void 0&&!t)throw new p("properties require type object");if(!t)return;if(e.additionalProperties!==void 0&&e.additionalProperties!==!1)throw new p("schema-valued or true additionalProperties is unsupported");if(e.properties!==void 0&&!y(e.properties))throw new p("object properties must be a schema map");if(e.required!==void 0&&(!Array.isArray(e.required)||e.required.some((a)=>typeof a!=="string")))throw new p("object required must be a string array");let r=e.properties??{},i=Object.keys(r),o=new Set(Array.isArray(e.required)?e.required:[]);if([...o].some((a)=>!i.includes(a)))throw new p("required contains an unknown property");for(let[a,l]of Object.entries(r))if(w(l,n),!o.has(a)&&!M(l))r[a]={anyOf:[l,{type:"null"}]};e.required=i,e.additionalProperties=!1}function k(e,n){let t=structuredClone(e);if(!y(t))throw new p("root schema must have type object");if(w(t,n),t.type!=="object")throw new p("root schema must have type object");return t}function me(e,n){return n===!0?k(e.parameters):e.parameters}function Or(e,n,t){let r=n[t];if(typeof r!=="string")throw Error(`Grammar tool call "${e}" requires argument "${t}" to be a string.`);return r}function Nr(e,n,t,r){if(e.closed){if(r&&t===e.input)return;throw Error(`grammar tool input for property "${n}" changed after it was closed`)}if(!t.startsWith(e.input))throw Error(`grammar tool input for property "${n}" changed non-monotonically`);let i=t.slice(e.input.length);if(!r&&i.length===0)return;let o="";if(!e.started)o+=`{${JSON.stringify(n)}:"`,e.started=!0;if(o+=JSON.stringify(i).slice(1,-1),e.input=t,r)o+='"}',e.closed=!0;return o}function b(e){let n=e.parameters;if(n.type!=="object")throw Error("grammar constrained sampling requires an object parameter schema");if(!Array.isArray(n.required)||n.required.length!==1||typeof n.required[0]!=="string")throw Error("grammar constrained sampling requires exactly one required string property");let t=n.required[0];if(!n.properties?.[t])throw Error(`grammar constrained sampling requires a properties entry for ${t}`);if(n.properties[t]?.type!=="string")throw Error(`grammar constrained sampling property ${t} must have type string`);return t}function ce(e,n,t){let r=e.constrainedSampling;if(!r||r.type!=="json_schema")return;if(n)try{return k(e.parameters,t),!0}catch(i){if(!(i instanceof p))throw i;if(r.strict!=="require")return;throw Error(`Tool "${e.name}" requires JSON-schema constrained sampling, but ${i.message}.`)}if(r.strict==="require")throw Error(`Tool "${e.name}" requires JSON-schema constrained sampling, but strict tools are unsupported.`);return}function Yt(e,n){let t=e.constrainedSampling;if(!t||t.type!=="grammar")return;if(!n)return;let r=t.variants.openai_lark,i=t.variants.openai_regex,o=typeof r==="string"&&r.trim().length>0,a=typeof i==="string"&&i.trim().length>0;if(!o&&!a)throw Error(`Tool "${e.name}" cannot use grammar constrained sampling: no supported grammar variant was provided.`);try{return{format:o?"lark":"regex",definition:o?r:i,inputProperty:b(e)}}catch(l){let d=l instanceof Error?l.message:String(l);throw Error(`Tool "${e.name}" cannot use grammar constrained sampling: ${d}.`)}}function Ae(e,n){let t=new Map;for(let r of e??[]){let i=Yt(r,n);if(i)t.set(r.name,i.inputProperty)}return t}var O=3.5,H=4800;function _(e){return e.totalTokens||e.input+e.output+e.cacheRead+e.cacheWrite}function P(e){try{return JSON.stringify(e)??"undefined"}catch{return"[unserializable]"}}function W(e){if(typeof e==="string")return e.length;let n=0;for(let t of e)n+=t.type==="text"?t.text.length:H;return n}function v(e){return Math.ceil(e.length/O)}function C(e){return Math.ceil(W(e)/O)}function E(e){let n=0;if(e.role==="system")return v(N(e))+R(e.toolsAdded)+R(e.toolsRemoved);if(e.role==="user")return C(e.content);if(e.role==="toolResult")return C(e.content);for(let t of e.content)if(t.type==="text")n+=t.text.length;else if(t.type==="thinking")n+=t.thinking.length;else n+=t.name.length+P(t.arguments).length;return Math.ceil(n/O)}function B(e){let n=Number.NEGATIVE_INFINITY,t;for(let r=0;r<e.length;r++){let i=e[r];if(i.role==="assistant"){let o=i;if(o.timestamp>=n&&o.stopReason!=="aborted"&&o.stopReason!=="error"&&_(o.usage)>0)t={usage:o.usage,index:r}}n=Math.max(n,i.timestamp)}return t}function S(e){let n="messages"in e?e.messages:e,t=B(n);if(t){let i=_(t.usage),o=0;for(let a=t.index+1;a<n.length;a++)o+=E(n[a]);return{tokens:i+o,usageTokens:i,trailingTokens:o,lastUsageIndex:t.index}}let r=0;for(let i of n)r+=E(i);return{tokens:r,usageTokens:0,trailingTokens:r,lastUsageIndex:null}}function R(e){if(!e||e.length===0)return 0;return v(P(e))}var F=4096,q=1;function Zt(e,n,t){if(e.contextWindow<=0)return Math.max(q,t);let r=e.contextWindow-S(n).tokens-F;return Math.min(t,Math.max(q,r))}function ut(e,n,t){let r=G(e,n),i=e.samplingParamsByThinkingLevel?.[r];return e.samplingParams||i||t?{...e.samplingParams,...i,...t}:void 0}function V(e,n,t,r){let i=ut(e,t?.reasoning??"off",t?.samplingParams);return{temperature:t?.temperature,samplingParams:i,maxTokens:Zt(e,n,t?.maxTokens??e.maxTokens),signal:t?.signal,telemetryContext:t?.telemetryContext,apiKey:r||t?.apiKey,fetch:t?.fetch,transport:t?.transport,cacheRetention:t?.cacheRetention,sessionId:t?.sessionId,headers:t?.headers,onPayload:t?.onPayload,onResponse:t?.onResponse,onProviderStreamEvent:t?.onProviderStreamEvent,timeoutMs:t?.timeoutMs,websocketConnectTimeoutMs:t?.websocketConnectTimeoutMs,maxRetries:t?.maxRetries,maxRetryDelayMs:t?.maxRetryDelayMs,metadata:t?.metadata,env:t?.env}}var z=1024,K={minimal:1024,low:2048,medium:8192,high:16384};function Eo(e){return e==="xhigh"||e==="max"?"high":e}function Po(e,n){let t={...K,...n},r=Eo(e);return t[r]}function To(e,n){return Math.min(e,Math.max(0,n-z))}function Dr(e,n,t,r){let i=Po(t,r),o=e===void 0?n:Math.min(e+i,n);if(o<=i)i=To(i,o);return{maxTokens:o,thinkingBudget:i}}function j(e,n){let t=[],r=!1;for(let i of e){if(i.type==="image"){if(!r)t.push({type:"text",text:n});r=!0;continue}t.push(i),r=i.text===n}return t}function Y(e,n){if(n.input.includes("image"))return e;return e.map((t)=>{if(t.role==="user"&&Array.isArray(t.content))return{...t,content:j(t.content,"(image omitted: model does not support images)")};if(t.role==="toolResult")return{...t,content:j(t.content,"(tool image omitted: model does not support images)")};return t})}function he(e,n,t){let r=new Map,i=e.map((s)=>s.content==null?{...s,content:[]}:s),a=Y(i,n).map((s)=>{if(s.role==="system"||s.role==="user")return s;if(s.role==="toolResult"){let u=r.get(s.toolCallId);if(u&&u!==s.toolCallId)return{...s,toolCallId:u};return s}if(s.role==="assistant"){let u=s,c=u.provider===n.provider&&u.api===n.api&&u.model===n.id,x=u.content.flatMap((f)=>{if(f.type==="thinking"){if(f.redacted)return c?f:[];if(c&&f.thinkingSignature)return f;if(!f.thinking||f.thinking.trim()==="")return[];if(c)return f;return{type:"text",text:f.thinking}}if(f.type==="text"){if(c)return f;return{type:"text",text:f.text}}if(f.type==="toolCall"){let m=f,g=m;if(!c&&m.thoughtSignature)g={...m},delete g.thoughtSignature;if(!c&&t){let I=t(m.id,n,u);if(I!==m.id)r.set(m.id,I),g={...g,id:I}}return g}return f});return{...u,content:x}}return s}),l=[],d=[],h=new Set,T=[],A=()=>{if(d.length>0){for(let s of d)if(!h.has(s.id))l.push({role:"toolResult",toolCallId:s.id,toolName:s.name,content:[{type:"text",text:"No result provided"}],isError:!0,timestamp:Date.now()});d=[],h=new Set}l.push(...T),T.length=0};for(let s=0;s<a.length;s++){let u=a[s];if(u.role==="assistant"){A();let c=u;if(c.stopReason==="error"||c.stopReason==="aborted")continue;let x=c.content.filter((f)=>f.type==="toolCall");if(x.length>0)d=x,h=new Set;l.push(u)}else if(u.role==="toolResult")h.add(u.toolCallId),l.push(u);else if(u.role==="system")if(d.length>0)T.push(u);else l.push(u);else if(u.role==="user")A(),l.push(u);else l.push(u)}return A(),l}
|
|
3
|
+
export{me,Or,Nr,ce,Yt,Ae,Zt,ut,V,Eo,Po,To,Dr,he};
|