@bkm016/basalt 0.1.3 → 0.1.5
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 +53 -5
- package/{chunk-y648fzx0.js → chunk-0039s4jt.js} +3 -3
- package/{chunk-m40gxwq4.js → chunk-00gwse5r.js} +3 -3
- package/{chunk-t6zs4kw0.js → chunk-0fwdxd45.js} +2 -2
- package/{chunk-6hssbcgj.js → chunk-0j0qggej.js} +1 -1
- package/chunk-0n99m9m4.js +2 -0
- package/{chunk-d8gtbw9g.js → chunk-0stvywr8.js} +1 -1
- package/{chunk-ztsjgssj.js → chunk-1xa7d5mh.js} +1 -1
- package/chunk-2nb3d92s.js +2 -0
- package/chunk-2nkfxhef.js +3868 -0
- package/chunk-2pa1z37c.js +2 -0
- package/{chunk-fw2bpqmw.js → chunk-2qcpq99g.js} +1 -1
- package/{chunk-981f9dw8.js → chunk-36cqq0ga.js} +6 -6
- package/{chunk-3cjsd292.js → chunk-3c330qna.js} +2 -2
- package/chunk-3k627vf2.js +3 -0
- package/{chunk-r7fpkb49.js → chunk-3k7ejpkc.js} +1 -1
- package/chunk-4g5f43ea.js +3 -0
- package/{chunk-fjtvjrkg.js → chunk-539ekagy.js} +4 -4
- package/{chunk-97rzj7f6.js → chunk-5v4g21rw.js} +1 -1
- package/{chunk-aefadsy6.js → chunk-6dsq0fns.js} +2 -2
- package/{chunk-pbcy6zdt.js → chunk-7as47pcw.js} +1 -1
- package/{chunk-g2t6t8fk.js → chunk-7jezts2n.js} +2 -2
- package/{chunk-8tjad3r0.js → chunk-7qq99360.js} +6 -6
- package/{chunk-gp7y0fja.js → chunk-7tgqhveh.js} +15 -15
- package/{chunk-mvfsxdx6.js → chunk-7w0mefgk.js} +10 -10
- package/{chunk-y58ygzn9.js → chunk-818nd6s1.js} +3 -3
- package/{chunk-vv7fp27r.js → chunk-8mezk0cb.js} +2 -2
- package/{chunk-rtzqqngy.js → chunk-8xb636vr.js} +5 -5
- package/{chunk-2esbgxps.js → chunk-980drajf.js} +15 -15
- package/{chunk-c7x1zq39.js → chunk-9z7sdh5e.js} +3 -3
- package/{chunk-10xzzn07.js → chunk-a4b75ekk.js} +2 -2
- package/{chunk-5j1krv9v.js → chunk-ar3dbfp9.js} +1 -1
- package/{chunk-vk1gxk1t.js → chunk-aw65h276.js} +1 -1
- package/{chunk-75m78j7x.js → chunk-b9fqretv.js} +2 -2
- package/{chunk-y0m980k3.js → chunk-bgkegf0k.js} +22 -22
- package/{chunk-0y7ne3d0.js → chunk-bwawt15q.js} +2 -2
- package/{chunk-pxsrqrd0.js → chunk-c4qr1f41.js} +2 -2
- package/chunk-dddsrff6.js +478 -0
- package/{chunk-xfvvh1s5.js → chunk-e63c1186.js} +1 -1
- package/{chunk-8296hw9m.js → chunk-ebzkckyw.js} +2 -2
- package/chunk-eegztdzb.js +2 -0
- package/{chunk-hwr56pfj.js → chunk-gw05p4g3.js} +1 -1
- package/{chunk-k23t7vhs.js → chunk-h1rypb99.js} +5 -5
- package/{chunk-nbb9trwz.js → chunk-hq5ke1yp.js} +2 -2
- package/{chunk-jwdb0ccj.js → chunk-jvwg4rn1.js} +3 -3
- package/{chunk-fm0k0qtz.js → chunk-jyrwk08p.js} +2 -2
- package/chunk-kns4kv7b.js +3 -0
- package/{chunk-8d46jtbj.js → chunk-mat08ab1.js} +2 -2
- package/{chunk-bannb9xm.js → chunk-mkp28k1x.js} +2 -2
- package/{chunk-d2j735sd.js → chunk-npez1492.js} +2 -2
- package/{chunk-shadcb9z.js → chunk-nx3jnbv8.js} +2 -2
- package/{chunk-ykens1hy.js → chunk-nxkmd29x.js} +1 -1
- package/{chunk-y7nma9rk.js → chunk-pjr91g6k.js} +2 -2
- package/{chunk-m8vkwdgr.js → chunk-r0jc8e7t.js} +4 -4
- package/chunk-rxj6tct8.js +2 -0
- package/{chunk-362g64pd.js → chunk-sqaam5ak.js} +1 -1
- package/{chunk-gzxnene8.js → chunk-srjgvdvs.js} +12 -12
- package/{chunk-r9aatvwm.js → chunk-stj493dn.js} +2 -2
- package/{chunk-k6w6y71k.js → chunk-t7sc0wwc.js} +2 -2
- package/{chunk-27gntzs5.js → chunk-v4k3qmdm.js} +2 -2
- package/{chunk-x1xss1d7.js → chunk-vt1anydc.js} +4 -4
- package/chunk-wd3z74av.js +2 -0
- package/{chunk-z55bmysw.js → chunk-wfyrfvfn.js} +1 -1
- package/{chunk-v9fea96h.js → chunk-wnzvnskb.js} +2 -2
- package/{chunk-cjc90f84.js → chunk-x89em726.js} +3 -3
- package/{chunk-1qpces5a.js → chunk-xtq1xpq0.js} +2 -2
- package/chunk-yna8bwqc.js +2 -0
- package/{chunk-k506w58v.js → chunk-zn0g0859.js} +2 -2
- package/{chunk-qe0teyn1.js → chunk-zrkh5dw7.js} +1 -1
- package/chunk-zzwjt7fp.js +2 -0
- package/compiled.js +12 -12
- package/package.json +1 -1
- package/ui-test-worker.js +20 -20
- package/web/chunk-01hcjafh.js +2 -0
- package/web/{chunk-n8sky2q6.js → chunk-07agqp8h.js} +1 -1
- package/web/{chunk-tx8240k4.js → chunk-0k9aec1s.js} +20 -20
- package/web/{chunk-74j07k8k.js → chunk-0p1nmj5n.js} +2 -2
- package/web/chunk-0qr891eq.js +70 -0
- package/web/{chunk-ts7zrf5b.js → chunk-0whceqes.js} +2 -2
- package/web/chunk-0ytga215.js +1 -0
- package/web/{chunk-h288yd5w.js → chunk-12z7d0hp.js} +3 -3
- package/web/chunk-14bad871.js +2 -0
- package/web/chunk-1amzv4ha.js +1 -0
- package/web/chunk-1cfh0e2e.js +324 -0
- package/web/chunk-1pasbxwh.js +89 -0
- package/web/{chunk-j0bwwc1g.js → chunk-1s2hp6h1.js} +1 -1
- package/web/chunk-26bwh1sb.js +169 -0
- package/web/{chunk-b0a8nbj0.js → chunk-2nht58dc.js} +5 -5
- package/web/chunk-2y0rc1fe.js +1 -0
- package/web/chunk-3hkgdw6f.js +36 -0
- package/web/chunk-4a4j030b.js +1 -0
- package/web/{chunk-4fzj0azw.js → chunk-4m3zdd41.js} +6 -6
- package/web/chunk-4w298aqs.js +1 -0
- package/web/{chunk-2hd1pe9w.js → chunk-56krfj3b.js} +7 -7
- package/web/{chunk-ds7srg4p.js → chunk-5nda24gv.js} +1 -1
- package/web/{chunk-5hmfk69r.js → chunk-5shygfgb.js} +19 -19
- package/web/chunk-65nwc4cf.js +1 -0
- package/web/chunk-6bwgdvf6.js +1 -0
- package/web/chunk-6enn8p66.js +1 -0
- package/web/chunk-6stt9d18.js +1 -0
- package/web/{chunk-4gavbw65.js → chunk-7a3c137d.js} +1 -1
- package/web/chunk-7e47b1sn.js +1 -0
- package/web/chunk-7pypx5h8.js +2 -0
- package/web/chunk-7znyd1mj.js +39 -0
- package/web/{chunk-0z0jycs8.js → chunk-892nf39p.js} +7 -7
- package/web/chunk-8r0s8tx7.js +1 -0
- package/web/chunk-9dy7z3ej.js +2 -0
- package/web/chunk-9mq2cdtq.js +1 -0
- package/web/chunk-9w5tf22s.js +1 -0
- package/web/{chunk-es28k2t7.js → chunk-9xgspn75.js} +2 -2
- package/web/{chunk-0xc2c540.js → chunk-abhad4zj.js} +56 -56
- package/web/chunk-advfpyb9.js +140 -0
- package/web/chunk-affear07.js +3 -0
- package/web/chunk-ahztazsg.js +1 -0
- package/web/chunk-aqt7kc3s.js +106 -0
- package/web/chunk-b5hah4mf.js +1 -0
- package/web/chunk-b8tfetd8.js +1 -0
- package/web/{chunk-7yc083xj.js → chunk-bnb9xhgw.js} +15 -15
- package/web/{chunk-n1dmrz44.js → chunk-c01176kn.js} +2 -2
- package/web/chunk-c3nn0vvc.js +1 -0
- package/web/chunk-c53xmf48.js +30 -0
- package/web/chunk-ckgpy4r4.js +1 -0
- package/web/chunk-crzseqbx.js +24 -0
- package/web/chunk-d22wq71s.js +1 -0
- package/web/{chunk-97b62pvb.js → chunk-d60dpf69.js} +19 -19
- package/web/{chunk-sn9ecfvy.js → chunk-d6ddkh6e.js} +1 -1
- package/web/{chunk-cg3jterp.js → chunk-d9wdsjkk.js} +2 -2
- package/web/{chunk-ttg6tbwx.js → chunk-da7m1kva.js} +2 -2
- package/web/chunk-dbnrfxt1.js +8 -0
- package/web/chunk-ddxf8e84.js +1 -0
- package/web/chunk-dzg1pv80.js +200 -0
- package/web/{chunk-xnq41dgs.js → chunk-e8h45nyr.js} +1 -1
- package/web/chunk-ej9vb61c.js +1 -0
- package/web/chunk-f9k3xrwb.js +2 -0
- package/web/{chunk-7xk0ntav.js → chunk-fjag6yg8.js} +2 -2
- package/web/chunk-fnnrrzqa.js +78 -0
- package/web/{chunk-n90cqdvg.js → chunk-fv6vm14n.js} +2 -2
- package/web/{chunk-axkyft9f.js → chunk-g5jxwkdh.js} +1 -1
- package/web/{chunk-ep37qp12.js → chunk-g8kkc6vz.js} +1 -1
- package/web/chunk-g9sqbafw.js +2 -0
- package/web/{chunk-g46f421r.js → chunk-gcv91974.js} +4 -4
- package/web/{chunk-7qxhk1kz.js → chunk-gxqaa4sv.js} +7 -7
- package/web/chunk-gxsb5tx3.js +1 -0
- package/web/{chunk-54thej0t.js → chunk-gyp6v7jd.js} +2 -2
- package/web/chunk-h0c42zy3.js +1 -0
- package/web/chunk-h2ag4kvz.js +2 -0
- package/web/{chunk-eqsd8zta.js → chunk-h6gh63xj.js} +2 -2
- package/web/{chunk-6m69hczt.js → chunk-h6k1x096.js} +2 -2
- package/web/{chunk-24mfx6w1.js → chunk-j1bw5v1g.js} +2 -2
- package/web/chunk-j34q5jn6.js +1 -0
- package/web/{chunk-0pbjgdgp.js → chunk-ja7w629n.js} +2 -2
- package/web/{chunk-zbj1trar.js → chunk-jam45rqg.js} +2 -2
- package/web/{chunk-23c1df7e.js → chunk-jcdw85mv.js} +1 -1
- package/web/chunk-jfvxxp5c.js +1 -0
- package/web/chunk-jg6fmz2d.js +1 -0
- package/web/{chunk-90xqeczk.js → chunk-k67v6dyg.js} +40 -40
- package/web/chunk-ka7c5rhx.js +99 -0
- package/web/{chunk-acybsx44.js → chunk-kza0t0gj.js} +1 -1
- package/web/{chunk-7520nrbb.js → chunk-m8knte9z.js} +1 -1
- package/web/{chunk-v5cnt7c8.js → chunk-mnzramhc.js} +1 -1
- package/web/{chunk-7v5rxabp.js → chunk-mpfgr049.js} +1 -1
- package/web/chunk-mz1dabxh.js +1 -0
- package/web/chunk-mz9b5bsa.js +1 -0
- package/web/chunk-p53n0hwr.js +1 -0
- package/web/chunk-paywgcf7.js +40 -0
- package/web/chunk-pfcnr9tw.js +1 -0
- package/web/chunk-pyg1mr80.js +303 -0
- package/web/chunk-q7xkscc5.js +1 -0
- package/web/{chunk-xzp7jf7e.js → chunk-qcge7d6s.js} +2 -2
- package/web/chunk-qmbgb79a.js +1139 -0
- package/web/{chunk-5b2nw6j1.js → chunk-qq5gh5zr.js} +1 -1
- package/web/chunk-qrdh9j62.js +1 -0
- package/web/{chunk-w7snhcyg.js → chunk-s24qs1bn.js} +9 -9
- package/web/chunk-sd22cnjy.js +1 -0
- package/web/{chunk-ydtrc1ay.js → chunk-sd3cdqcm.js} +2 -2
- package/web/{chunk-rykfak98.js → chunk-sf101c23.js} +2 -2
- package/web/{chunk-p9hsd3rn.js → chunk-sfq6cw45.js} +2 -2
- package/web/chunk-svqj4az8.js +1 -0
- package/web/chunk-t7jwyvvr.js +1 -0
- package/web/{chunk-47q4hmfp.js → chunk-tcp77cp2.js} +2 -2
- package/web/chunk-tf18d2dk.css +1 -0
- package/web/chunk-thbqwq6b.js +1 -0
- package/web/chunk-v0g4cqc1.js +4 -0
- package/web/chunk-vhzys0rr.js +292 -0
- package/web/chunk-vnt34mkb.js +1 -0
- package/web/chunk-vqfz99ff.js +1 -0
- package/web/chunk-vttgyb5v.js +2 -0
- package/web/chunk-x7sb3bwf.js +370 -0
- package/web/chunk-xce8n339.js +1 -0
- package/web/{chunk-mb4qx9hy.js → chunk-xk1t58c4.js} +12 -12
- package/web/chunk-xsrvw7dt.js +4 -0
- package/web/chunk-xtss82z2.js +1 -0
- package/web/{chunk-2j4m0bh1.js → chunk-y7jq61nv.js} +2 -2
- package/web/{chunk-7ba8vrfc.js → chunk-ybw6vgf6.js} +2 -2
- package/web/{chunk-24h1rfje.js → chunk-yvgs6bm3.js} +4 -4
- package/web/{chunk-sb1cjpq8.js → chunk-z4aj066q.js} +1 -1
- package/web/chunk-zazs8p6c.js +1 -0
- package/web/{chunk-n8gfjj9a.js → chunk-zc1mk10n.js} +19 -19
- package/web/{chunk-5qqw2e0t.js → chunk-zqht0jzx.js} +6 -6
- package/web/{chunk-mwj9tpkz.js → chunk-zz397b0v.js} +12 -12
- package/web/index.html +1 -1
- package/worker.js +1 -1
- package/chunk-06hdzq5n.js +0 -2
- package/chunk-09rj27b2.js +0 -2
- package/chunk-1zdwrgd4.js +0 -2
- package/chunk-5c9j8qe4.js +0 -478
- package/chunk-9mmz6wt3.js +0 -2
- package/chunk-bpw6q7g0.js +0 -3
- package/chunk-bxn5kmpz.js +0 -3753
- package/chunk-n6e43rvk.js +0 -3
- package/chunk-pmqtkqsf.js +0 -2
- package/chunk-ry0z4ev6.js +0 -2
- package/chunk-v258nxcz.js +0 -2
- package/chunk-zmsgwr3s.js +0 -2
- package/web/chunk-0s80zw00.js +0 -1
- package/web/chunk-166qe5j6.js +0 -2
- package/web/chunk-1c95wfvq.js +0 -1
- package/web/chunk-329rtxa9.js +0 -1
- package/web/chunk-33qwz9bc.js +0 -2
- package/web/chunk-3qjnwsph.js +0 -1
- package/web/chunk-4rm1vy7w.js +0 -1
- package/web/chunk-59kqahb3.js +0 -1
- package/web/chunk-61jahh35.js +0 -292
- package/web/chunk-6beqrmtq.js +0 -1
- package/web/chunk-6gxf3vsg.js +0 -1
- package/web/chunk-6parf7sy.js +0 -2
- package/web/chunk-89fkdgbp.js +0 -2
- package/web/chunk-8qgpfxkz.js +0 -1
- package/web/chunk-9a3q0jsh.js +0 -36
- package/web/chunk-9bgey148.js +0 -169
- package/web/chunk-9xh96b33.js +0 -2
- package/web/chunk-a5sg33w2.js +0 -3
- package/web/chunk-a91vxtx4.js +0 -1
- package/web/chunk-agec7jj4.js +0 -1
- package/web/chunk-c516cghj.js +0 -1
- package/web/chunk-cqp1d4p0.js +0 -1
- package/web/chunk-cwtdnacf.js +0 -1
- package/web/chunk-dg1vas6z.js +0 -8
- package/web/chunk-dy2gm1fs.js +0 -1
- package/web/chunk-f91wzwtk.js +0 -1
- package/web/chunk-fc0nx23g.js +0 -1
- package/web/chunk-fhnypcrm.js +0 -1139
- package/web/chunk-fv60p68p.js +0 -1
- package/web/chunk-g1ev11wx.js +0 -1
- package/web/chunk-h18tnrf2.js +0 -1
- package/web/chunk-hfaffkrh.js +0 -1
- package/web/chunk-hszjc2ny.js +0 -70
- package/web/chunk-j2vt8c8v.js +0 -1
- package/web/chunk-jqa39f8t.js +0 -78
- package/web/chunk-jvbbrnpa.js +0 -1
- package/web/chunk-jzfd7cyh.js +0 -2
- package/web/chunk-ka3q31t1.js +0 -1
- package/web/chunk-ka9ak8wr.js +0 -1
- package/web/chunk-m2d1sp30.js +0 -1
- package/web/chunk-mnjd59jk.js +0 -1
- package/web/chunk-ng0nbfhh.js +0 -1
- package/web/chunk-nz9nxk48.js +0 -1
- package/web/chunk-phw908hn.js +0 -1
- package/web/chunk-pjmmma1k.js +0 -1
- package/web/chunk-pxe3vna4.js +0 -1
- package/web/chunk-q7yn4m3t.js +0 -1
- package/web/chunk-qh15dxav.css +0 -1
- package/web/chunk-qnhqexe0.js +0 -1
- package/web/chunk-rcx1aee5.js +0 -99
- package/web/chunk-rjqj6ffe.js +0 -1
- package/web/chunk-rks7ksv3.js +0 -106
- package/web/chunk-rtf2zzzv.js +0 -1
- package/web/chunk-sgvp8vge.js +0 -1
- package/web/chunk-sjjwte12.js +0 -1
- package/web/chunk-srrfphes.js +0 -1
- package/web/chunk-t7bwsdbr.js +0 -1
- package/web/chunk-tse9gvyq.js +0 -89
- package/web/chunk-vd6y2pcm.js +0 -39
- package/web/chunk-vpa55vje.js +0 -4
- package/web/chunk-vymqrpm3.js +0 -303
- package/web/chunk-wdtnhpd6.js +0 -4
- package/web/chunk-wmvd6j0b.js +0 -200
- package/web/chunk-xvsmtetz.js +0 -30
- package/web/chunk-y3ajqthy.js +0 -370
- package/web/chunk-yd1ez3wd.js +0 -2
- package/web/chunk-yfbxtg5p.js +0 -1
- package/web/chunk-ywp4s71k.js +0 -40
- package/web/chunk-z4x331rx.js +0 -140
- package/web/chunk-z6bpamwq.js +0 -24
- package/web/chunk-zmdnxn6m.js +0 -2
- package/web/install.ps1 +0 -91
- package/web/install.sh +0 -177
package/README.md
CHANGED
|
@@ -85,8 +85,11 @@ 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
|
升级到最新版本:
|
|
@@ -104,14 +107,39 @@ bun i -g @bkm016/basalt@latest
|
|
|
104
107
|
```bash
|
|
105
108
|
bun install
|
|
106
109
|
bun run dev # 启动开发服务器(支持热重载)
|
|
107
|
-
bun packages/cli/src/main.ts --demo
|
|
110
|
+
bun packages/cli/src/main.ts --demo --open # 无需 API Key,使用内置演示模型体验工作台
|
|
108
111
|
```
|
|
109
112
|
|
|
110
113
|
### 配对与首次使用
|
|
111
114
|
|
|
112
|
-
1.
|
|
115
|
+
1. 首次启动建议使用 `basalt --open`,服务就绪后会自动在浏览器中打开带配对链接的工作台。未使用 `--open` 时,可通过 `basalt logs` 查看 10 分钟有效的一次性配对码、二维码及配对链接。
|
|
113
116
|
2. 首次进入工作台若尚未配置模型,界面会引导前往「设置 → 模型」添加服务商与 API Key,也可直接通过环境变量(如 `ANTHROPIC_API_KEY`、`OPENAI_API_KEY`)提供。
|
|
114
117
|
|
|
118
|
+
### 远程访问(Cloudflare 隧道)
|
|
119
|
+
|
|
120
|
+
用自己域名下的**固定主机名**,从手机或另一台电脑访问这台机器上的 Basalt。前提:域名托管在 Cloudflare,本机装好 [`cloudflared`](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/)。
|
|
121
|
+
|
|
122
|
+
在工作台 **设置 → 远程访问** 里按向导走,全程不用进 Cloudflare 后台:
|
|
123
|
+
|
|
124
|
+
1. **连接 Cloudflare 账号**:点「连接 Cloudflare」,Basalt 会给出一个授权链接。在浏览器(手机也行)里打开它,登录并选择你的域名,点授权。完成后页面自动继续。
|
|
125
|
+
2. **选一个访问地址**:填该域名下的子域名,如 `basalt.example.com`。
|
|
126
|
+
3. **创建并连接**:Basalt 通过 `cloudflared` 自动创建隧道、添加域名解析、写好转发配置并连接。
|
|
127
|
+
|
|
128
|
+
之后每次启动 `basalt` 都会自动带起隧道,随 Basalt 退出而退出,掉线自动重连;终端里的配对二维码和链接改用 `https://basalt.example.com`。授权证书和隧道凭据保存在数据目录的 `cloudflared/` 下,不会写进你自己的 `~/.cloudflared`。
|
|
129
|
+
|
|
130
|
+
已经在 Cloudflare 后台建好隧道的人,向导里点「我已有隧道令牌」,把后台给出的安装命令整段粘贴进来即可(也可用命令行:`BASALT_TUNNEL_TOKEN=<令牌> basalt tunnel set basalt.example.com`;`basalt tunnel status` / `basalt tunnel off` 查看或删除)。令牌模式下,隧道的服务地址要在 Cloudflare 里填 `http://localhost:<端口>`,设置页会显示端口。
|
|
131
|
+
|
|
132
|
+
**可选:Cloudflare Access(再加一道只认你的登录)**
|
|
133
|
+
|
|
134
|
+
配好之后在同一页的「Access 校验」点「设置」。在 Cloudflare 后台(菜单名按官方文档原文):`Zero Trust › Access controls › Applications › Create new application › Self-hosted and private`,域名填你的主机名,策略选你的邮箱;应用的 `Configure › Additional settings` 里复制 **Audience Tag**,团队域名是 `团队名.cloudflareaccess.com`,填回 Basalt。之后经隧道进来的请求必须带 Cloudflare 签发的有效 JWT,否则被直接拒绝。
|
|
135
|
+
|
|
136
|
+
**安全说明**
|
|
137
|
+
|
|
138
|
+
- 配置了远程访问就不能用 `--no-auth` 启动,设置页也会拒绝在免认证服务上开启。
|
|
139
|
+
- 配了 Access 后,Basalt 会校验 Cloudflare 签发的 `Cf-Access-Jwt-Assertion`(签名、颁发者、Audience、有效期;公钥取自团队域名的 `/cdn-cgi/access/certs`):**经隧道进来**且没有合法凭据的请求会被直接 403,即使 Access 策略被误改成放行也不会只剩 Basalt 自己的令牌守着公网。本机直连不受影响。
|
|
140
|
+
- 直接用 `https://你的主机名` 打开时,页面与 API 同源,无需额外设置。若用 basalt.work 等其他网址连接,需要在 Access 应用里为跨域请求开启「Bypass OPTIONS」,并在添加服务器时填写服务令牌请求头(`CF-Access-Client-Id` / `CF-Access-Client-Secret`)。
|
|
141
|
+
- 远程设备只能用终端里的配对码配对;「本机免码授权」对经隧道的请求不可用。
|
|
142
|
+
|
|
115
143
|
---
|
|
116
144
|
|
|
117
145
|
## 命令行与配置参考
|
|
@@ -119,20 +147,32 @@ bun packages/cli/src/main.ts --demo # 无需 API Key,使用内置演示模
|
|
|
119
147
|
### CLI 选项
|
|
120
148
|
|
|
121
149
|
```text
|
|
122
|
-
用法: basalt [选项]
|
|
150
|
+
用法: basalt [选项] 后台启动服务,就绪后返回
|
|
151
|
+
basalt status 查看服务状态
|
|
152
|
+
basalt stop 停止服务
|
|
153
|
+
basalt restart 按原参数重启服务
|
|
154
|
+
basalt logs 查看最近后台日志
|
|
155
|
+
basalt autostart <enable|disable|status> 管理登录自启
|
|
123
156
|
basalt update 更新到最新版本(正在运行的服务会自动重启)
|
|
157
|
+
basalt setup 把 basalt 所在目录加入 PATH(装完提示找不到命令时用)
|
|
124
158
|
basalt plugin reload <id> [--data <目录>]
|
|
159
|
+
basalt tunnel set <主机名> [--token <令牌>] [--team <团队域名> --aud <Audience>]
|
|
160
|
+
basalt tunnel off | status 远程访问(Cloudflare 隧道)
|
|
125
161
|
|
|
126
162
|
选项:
|
|
127
163
|
--host <地址> 监听地址(默认 127.0.0.1,仅本机回环)
|
|
128
164
|
--port <端口> 监听端口(默认 7420)
|
|
129
165
|
--open 启动后在浏览器里打开工作台(带配对链接)
|
|
166
|
+
--foreground 在前台运行服务,供调试、launchd 和 systemd 使用
|
|
130
167
|
--replace 已有实例在运行时先停止旧实例再启动
|
|
131
168
|
--model <provider/id> 指定启动时默认使用的模型(如 anthropic/claude-sonnet-4-20250514)
|
|
132
169
|
--demo 启用内置演示模型(demo/echo,无需 API Key)
|
|
133
170
|
--data <目录> 指定运行时数据目录(默认遵循平台规范或 BASALT_HOME)
|
|
134
171
|
--web-url <地址> 生成配对链接时使用的外部 Web 工作台地址
|
|
135
172
|
--allow-origin <来源> 允许跨域访问的 Web 来源,可多次传入;* 表示允许任意来源
|
|
173
|
+
--token <令牌> tunnel set 用:隧道令牌(更推荐用环境变量,避免进 shell 历史)
|
|
174
|
+
--team <团队域名> tunnel set 用:Access 团队域名
|
|
175
|
+
--aud <Audience> tunnel set 用:Access 应用的 Audience 标签
|
|
136
176
|
--no-tray 不启动系统托盘图标
|
|
137
177
|
--no-update-check 不自动检查新版本(也可设 BASALT_NO_UPDATE_CHECK=1)
|
|
138
178
|
--no-auth 关闭令牌认证(仅本机监听可用,或需配合 --allow-remote-no-auth)
|
|
@@ -142,6 +182,12 @@ bun packages/cli/src/main.ts --demo # 无需 API Key,使用内置演示模
|
|
|
142
182
|
-h, --help 显示帮助信息
|
|
143
183
|
```
|
|
144
184
|
|
|
185
|
+
默认 `basalt` 会在后台启动服务,等待 HTTP 就绪后返回终端;需要查看实时输出或由服务管理器托管时使用 `--foreground`。`basalt restart` 沿用当前实例的参数和工作目录,`basalt logs` 读取最近 256 KB 后台日志。
|
|
186
|
+
|
|
187
|
+
执行一次 `basalt autostart enable` 即可注册当前用户的登录自启:Windows 使用隐藏启动脚本,macOS 使用 LaunchAgent,Linux 使用 systemd 用户服务。启动项固定当前 Bun/npm 包入口,登录时不会联网安装或升级;`disable` 关闭自启,`status` 查看配置。启用时会沿用正在运行实例的参数,不会改变或重启当前服务。
|
|
188
|
+
|
|
189
|
+
自启只保存启动参数、数据目录和工作目录,不复制当前终端的环境变量。只在交互式 shell 中设置的 API Key、`BASALT_MODEL` 等变量不会自动带入登录会话;请在 Web 中配置模型,或把所需变量配置到系统用户环境。
|
|
190
|
+
|
|
145
191
|
### 环境变量
|
|
146
192
|
|
|
147
193
|
| 环境变量 | 说明 |
|
|
@@ -149,6 +195,7 @@ bun packages/cli/src/main.ts --demo # 无需 API Key,使用内置演示模
|
|
|
149
195
|
| `BASALT_HOME` | 显式指定 Basalt 数据根目录,优先级高于平台默认路径。 |
|
|
150
196
|
| `BASALT_MODEL` | 默认启动模型标识符(格式为 `<provider>/<model-id>`),命令行 `--model` 优先级高于此变量。 |
|
|
151
197
|
| `BASALT_TOKEN` | 执行 `basalt plugin reload <id>` 等 CLI 进程外管理命令时,用于向已开启认证的运行中服务提供设备令牌。 |
|
|
198
|
+
| `BASALT_TUNNEL_TOKEN` | `basalt tunnel set` 读取的 Cloudflare 隧道令牌,等价于 `--token`。 |
|
|
152
199
|
| `BASALT_NO_UPDATE_CHECK` | 设为 `1` 时禁用后台自动版本更新检查。 |
|
|
153
200
|
| `ANTHROPIC_API_KEY` / `OPENAI_API_KEY` 等 | 由 `@earendil-works/pi-ai` 自动识别的上游模型提供商凭据。 |
|
|
154
201
|
|
|
@@ -168,6 +215,7 @@ bun packages/cli/src/main.ts --demo # 无需 API Key,使用内置演示模
|
|
|
168
215
|
├── search.db # 独立 Worker 维护的会话历史全文检索索引库
|
|
169
216
|
├── models.json # Web 端配置的自定义模型提供商与脱敏凭据持久化文件
|
|
170
217
|
├── devices.json # 已配对设备的元数据与令牌 SHA-256 哈希记录
|
|
218
|
+
├── basalt.log # 后台服务标准输出与错误日志
|
|
171
219
|
├── server.json # 单实例运行锁文件(记录当前活动服务的 PID、监听 URL 与托盘句柄)
|
|
172
220
|
└── plugins/ # 用户级自定义插件目录(支持 <id>.ts 或 <id>/index.ts)
|
|
173
221
|
```
|
|
@@ -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,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
2
|
+
import{J,H}from"./chunk-36cqq0ga.js";import{r,p}from"./chunk-bwawt15q.js";var Be=r(function(me){var{hasOwn:Q}=J(),{streamCollector:ne}=J();me.streamCollector=ne;var{buildQueryString:G,HttpResponse:X}=H(),A=p("https"),{Readable:se}=p("stream"),O=p("http2");function U(e){let t=e&&typeof e==="object"&&"reason"in e?e.reason:void 0;if(t){if(t instanceof Error){let s=Error("Request aborted");return s.name="AbortError",s.cause=t,s}let n=Error(String(t));return n.name="AbortError",n}let o=Error("Request aborted");return o.name="AbortError",o}var re=["ECONNRESET","EPIPE","ETIMEDOUT"],Y=(e)=>{let t={};for(let o in e){if(!Q(e,o))continue;let n=e[o];t[o]=Array.isArray(n)?n.join(","):n}return t},l={setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:(e)=>clearTimeout(e)},B=1000,ie=(e,t,o=0)=>{if(!o)return-1;let n=(s)=>{let c=l.setTimeout(()=>{e.destroy(),t(Object.assign(Error(`@smithy/node-http-handler - the request socket did not establish a connection with the server within the configured timeout of ${o} ms.`),{name:"TimeoutError"}))},o-s),a=(u)=>{if(u?.connecting)u.on("connect",()=>{l.clearTimeout(c)});else l.clearTimeout(c)};if(e.socket)a(e.socket);else e.on("socket",a)};if(o<2000)return n(0),0;return l.setTimeout(n.bind(null,B),B)},ce=(e,t,o=0,n,s)=>{if(o)return l.setTimeout(()=>{let c=`@smithy/node-http-handler - [${n?"ERROR":"WARN"}] a request has exceeded the configured ${o} ms requestTimeout.`;if(n){let a=Object.assign(Error(c),{name:"TimeoutError",code:"ETIMEDOUT"});e.destroy(a),t(a)}else c+=" Init client requestHandler with throwOnRequestTimeout=true to turn this into an error.",s?.warn?.(c)},o);return-1},ae=3000,ue=(e,{keepAlive:t,keepAliveMsecs:o},n=ae)=>{if(t!==!0)return-1;let s=()=>{if(e.socket)e.socket.setKeepAlive(t,o||0);else e.on("socket",(c)=>{c.setKeepAlive(t,o||0)})};if(n===0)return s(),0;return l.setTimeout(s,n)},W=3000,fe=(e,t,o=0)=>{let n=(s)=>{let c=o-s,a=()=>{e.destroy(),t(Object.assign(Error(`@smithy/node-http-handler - the request socket timed out after ${o} ms of inactivity (configured by client requestHandler).`),{name:"TimeoutError"}))};if(e.socket)e.socket.setTimeout(c,a),e.on("close",()=>e.socket?.removeListener("timeout",a));else e.setTimeout(c,a)};if(0<o&&o<6000)return n(0),0;return l.setTimeout(n.bind(null,o===0?0:W),W)},z=6000;async function Z(e,t,o=z,n=!1){let s=t.headers,c=s?s.Expect||s.expect:void 0,a=-1,u=!0;if(!n&&c==="100-continue")u=await Promise.race([new Promise((f)=>{a=Number(l.setTimeout(()=>f(!0),Math.max(z,o)))}),new Promise((f)=>{e.on("continue",()=>{l.clearTimeout(a),f(!0)}),e.on("response",()=>{l.clearTimeout(a),f(!1)}),e.on("error",()=>{l.clearTimeout(a),f(!1)})})]);if(u)de(e,t.body)}function de(e,t){if(t instanceof se){t.pipe(e);return}if(t){let o=Buffer.isBuffer(t);if(o||typeof t==="string"){if(o&&t.byteLength===0)e.end();else e.end(t);return}let s=t;if(typeof s==="object"&&s.buffer&&typeof s.byteOffset==="number"&&typeof s.byteLength==="number"){e.end(Buffer.from(s.buffer,s.byteOffset,s.byteLength));return}e.end(Buffer.from(t));return}e.end()}var he=0,M=void 0,V=void 0;class N{config;configProvider;socketWarningTimestamp=0;externalAgent=!1;metadata={handlerProtocol:"http/1.1"};static create(e){if(typeof e?.handle==="function")return e;return new N(e)}static checkSocketUsage(e,t,o=console){let{sockets:n,requests:s,maxSockets:c}=e;if(typeof c!=="number"||c===1/0)return t;let a=15000;if(Date.now()-a<t)return t;if(n&&s)for(let u in n){if(!Q(n,u))continue;let f=n[u]?.length??0,m=s[u]?.length??0;if(f>=c&&m>=2*c)return o?.warn?.(`@smithy/node-http-handler:WARN - socket usage at capacity=${f} and ${m} additional requests are enqueued.
|
|
3
3
|
See https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/node-configuring-maxsockets.html
|
|
4
|
-
or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler config.`),Date.now()}return t}constructor(e){this.configProvider=new Promise((t,o)=>{if(typeof e==="function")e().then((n)=>{t(this.resolveDefaultConfig(n))}).catch(o);else t(this.resolveDefaultConfig(e))})}destroy(){this.config?.httpAgent?.destroy(),this.config?.httpsAgent?.destroy()}async handle(e,{abortSignal:t,requestTimeout:o}={}){if(!this.config)this.config=await this.configProvider;let n=this.config,s=n.logger,c=e.protocol==="https:";if(!c&&!this.config.httpAgent)this.config.httpAgent=await this.config.httpAgentProvider();return new Promise((a,u)=>{let f=void 0,m=-1,g=-1,w=-1,v=-1,C=-1,_=()=>{l.clearTimeout(m),l.clearTimeout(g),l.clearTimeout(w),l.clearTimeout(v),l.clearTimeout(C)},
|
|
5
|
-
export{
|
|
4
|
+
or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler config.`),Date.now()}return t}constructor(e){this.configProvider=new Promise((t,o)=>{if(typeof e==="function")e().then((n)=>{t(this.resolveDefaultConfig(n))}).catch(o);else t(this.resolveDefaultConfig(e))})}destroy(){this.config?.httpAgent?.destroy(),this.config?.httpsAgent?.destroy()}async handle(e,{abortSignal:t,requestTimeout:o}={}){if(!this.config)this.config=await this.configProvider;let n=this.config,s=n.logger,c=e.protocol==="https:";if(!c&&!this.config.httpAgent)this.config.httpAgent=await this.config.httpAgentProvider();return new Promise((a,u)=>{let f=void 0,m=-1,g=-1,w=-1,v=-1,C=-1,_=()=>{l.clearTimeout(m),l.clearTimeout(g),l.clearTimeout(w),l.clearTimeout(v),l.clearTimeout(C)},q=async(i)=>{await f,_(),a(i)},E=async(i)=>{await f,_(),u(i)};if(t?.aborted){let i=U(t);E(i);return}let D=e.headers,I=D?(D.Expect??D.expect)==="100-continue":!1,P=c?n.httpsAgent:n.httpAgent;if(I&&!this.externalAgent)P=new(c?A.Agent:M)({keepAlive:!1,maxSockets:1/0});m=l.setTimeout(()=>{this.socketWarningTimestamp=N.checkSocketUsage(P,this.socketWarningTimestamp,s)},n.socketAcquisitionWarningTimeout??(n.requestTimeout??2000)+(n.connectionTimeout??1000));let L=e.query?G(e.query):"",b=void 0;if(e.username!=null||e.password!=null){let i=e.username??"",d=e.password??"";b=`${i}:${d}`}let k=e.path;if(L)k+=`?${L}`;if(e.fragment)k+=`#${e.fragment}`;let y=e.hostname??"";if(y[0]==="["&&y.endsWith("]"))y=e.hostname.slice(1,-1);else y=e.hostname;let S={headers:e.headers,host:y,method:e.method,path:k,port:e.port,agent:P,auth:b},T=(c?A.request:V)(S,(i)=>{let d=new X({statusCode:i.statusCode||-1,reason:i.statusMessage,headers:Y(i.headers),body:i});q({response:d})});if(T.on("error",(i)=>{if(re.includes(i.code))E(Object.assign(i,{name:"TimeoutError"}));else E(i)}),t){let i=()=>{T.destroy();let d=U(t);E(d)};if(typeof t.addEventListener==="function"){let d=t;d.addEventListener("abort",i,{once:!0}),T.once("close",()=>d.removeEventListener("abort",i))}else t.onabort=i}let R=o??n.requestTimeout;g=ie(T,E,n.connectionTimeout),w=ce(T,E,R,n.throwOnRequestTimeout,s??console),v=fe(T,E,n.socketTimeout);let h=S.agent;if(typeof h==="object"&&"keepAlive"in h)C=ue(T,{keepAlive:h.keepAlive,keepAliveMsecs:h.keepAliveMsecs});f=Z(T,e,R,this.externalAgent).catch((i)=>(_(),u(i)))})}updateHttpClientConfig(e,t){this.config=void 0,this.configProvider=this.configProvider.then((o)=>{if(e===Symbol.for("logger"))return{...o,logger:o.logger??t};return{...o,[e]:t}})}httpHandlerConfigs(){return this.config??{}}resolveDefaultConfig(e){let{requestTimeout:t,connectionTimeout:o,socketTimeout:n,socketAcquisitionWarningTimeout:s,httpAgent:c,httpsAgent:a,throwOnRequestTimeout:u,logger:f}=e||{},m=!0,g=50;return{connectionTimeout:o,requestTimeout:t,socketTimeout:n,socketAcquisitionWarningTimeout:s,throwOnRequestTimeout:u,httpAgentProvider:async()=>{let w=p("http"),{Agent:v,request:C}=w.default??w;if(V=C,M=v,c instanceof M||typeof c?.destroy==="function")return this.externalAgent=!0,c;return new M({keepAlive:!0,maxSockets:50,...c})},httpsAgent:(()=>{if(a instanceof A.Agent||typeof a?.destroy==="function")return this.externalAgent=!0,a;return new A.Agent({keepAlive:!0,maxSockets:50,...a})})(),logger:f}}}var le=new Uint16Array(1);class F{id=le[0]++;total=0;max=0;session;refs=0;constructor(e){e.unref(),this.session=e}retain(){if(this.session.destroyed)throw Error("@smithy/node-http-handler - cannot acquire reference to destroyed session.");this.refs+=1,this.total+=1,this.max=Math.max(this.refs,this.max),this.session.ref()}free(){if(this.session.destroyed)return;if(this.refs-=1,this.refs===0)this.session.unref();if(this.refs<0)throw Error("@smithy/node-http-handler - ClientHttp2Session refcount at zero, cannot decrement.")}deref(){return this.session}close(){if(!this.session.closed)this.session.close()}destroy(){if(this.refs=0,!this.session.destroyed)this.session.setTimeout(0),this.session.destroy()}useCount(){return this.refs}}class ee{sessions=[];maxConcurrency=0;constructor(e){this.sessions=(e??[]).map((t)=>new F(t))}poll(){let e=!1;for(let t of this.sessions){if(t.deref().destroyed){e=!0;continue}if(!this.maxConcurrency||t.useCount()<this.maxConcurrency)return t}if(e){for(let t of this.sessions)if(t.deref().destroyed)this.remove(t)}}offerLast(e){this.sessions.push(e)}remove(e){let t=this.sessions.indexOf(e);if(t>-1)this.sessions.splice(t,1)}[Symbol.iterator](){return this.sessions[Symbol.iterator]()}setMaxConcurrency(e){this.maxConcurrency=e}destroy(e){this.remove(e),e.destroy()}}class te{config;connectOptions;connectionPools=new Map;constructor(e){if(this.config=e,this.config.maxConcurrency&&this.config.maxConcurrency<=0)throw RangeError("maxConcurrency must be greater than zero.")}lease(e,t){let o=this.getUrlString(e),n=this.getPool(o);if(!this.config.disableConcurrency&&!t.isEventStream){let f=n.poll();if(f)return f.retain(),f}let s=new F(this.connect(o)),c=s.deref();if(this.config.maxConcurrency)c.settings({maxConcurrentStreams:this.config.maxConcurrency},(f)=>{if(f)throw Error("Fail to set maxConcurrentStreams to "+this.config.maxConcurrency+"when creating new session for "+e.destination.toString())});let a=()=>{this.removeFromPoolAndClose(o,s)},u=()=>{this.removeFromPoolAndCheckedDestroy(o,s)};if(c.on("goaway",a),c.on("error",u),c.on("frameError",u),c.on("close",u),t.requestTimeout)c.setTimeout(t.requestTimeout,u);return n.offerLast(s),s.retain(),s}release(e,t){t.free()}createIsolatedSession(e,t){let o=this.getUrlString(e),n=new F(this.connect(o)),s=n.deref();s.settings({maxConcurrentStreams:1});let c=()=>{n.destroy()};s.on("error",c),s.on("frameError",c),s.on("close",c);let a=t.requestTimeout??300000;return s.setTimeout(a,c),n.retain(),n}destroy(){for(let[e,t]of this.connectionPools){for(let o of[...t])o.destroy();this.connectionPools.delete(e)}}setMaxConcurrentStreams(e){if(e&&e<=0)throw RangeError("maxConcurrentStreams must be greater than zero.");this.config.maxConcurrency=e;for(let t of this.connectionPools.values())t.setMaxConcurrency(e)}setDisableConcurrentStreams(e){this.config.disableConcurrency=e}setNodeHttp2ConnectOptions(e){this.connectOptions=e}debug(){let e={};for(let[t,o]of this.connectionPools){let n=[];for(let s of o)n.push({id:s.id,active:s.useCount(),maxConcurrent:s.max,totalRequests:s.total});e[t]={sessions:n}}return e}removeFromPoolAndClose(e,t){this.connectionPools.get(e)?.remove(t),t.close()}removeFromPoolAndCheckedDestroy(e,t){this.connectionPools.get(e)?.remove(t),t.destroy()}getPool(e){if(!this.connectionPools.has(e)){let t=new ee;if(this.config.maxConcurrency)t.setMaxConcurrency(this.config.maxConcurrency);this.connectionPools.set(e,t)}return this.connectionPools.get(e)}getUrlString(e){return e.destination.toString()}connect(e){return this.connectOptions===void 0?O.connect(e):O.connect(e,this.connectOptions)}}var{constants:K}=O;class j{config;configProvider;metadata={handlerProtocol:"h2"};connectionManager=new te({});static create(e){if(typeof e?.handle==="function")return e;return new j(e)}constructor(e){this.configProvider=new Promise((t,o)=>{if(typeof e==="function")e().then((n)=>{t(n||{})}).catch(o);else t(e||{})})}destroy(){this.connectionManager.destroy()}async handle(e,{abortSignal:t,requestTimeout:o,isEventStream:n}={}){if(!this.config){this.config=await this.configProvider;let{disableConcurrentStreams:f,maxConcurrentStreams:m,nodeHttp2ConnectOptions:g}=this.config;if(this.connectionManager.setDisableConcurrentStreams(f??!1),m)this.connectionManager.setMaxConcurrentStreams(m);if(g)this.connectionManager.setNodeHttp2ConnectOptions(g)}let{requestTimeout:s,disableConcurrentStreams:c}=this.config,a=c||n,u=o??s;return new Promise((f,m)=>{let g=!1,w=void 0,v=async(i)=>{await w,f(i)},C=async(i)=>{await w,m(i)};if(t?.aborted){g=!0;let i=U(t);C(i);return}let{hostname:_,method:q,port:E,protocol:D,query:I}=e,P="";if(e.username!=null||e.password!=null){let i=e.username??"",d=e.password??"";P=`${i}:${d}@`}let L=`${D}//${P}${_}${E?`:${E}`:""}`,b={destination:new URL(L)},k={requestTimeout:this.config?.sessionTimeout,isEventStream:n},y=a?this.connectionManager.createIsolatedSession(b,k):this.connectionManager.lease(b,k),S=y.deref(),x=(i)=>{if(a)y.destroy();g=!0,C(i)},T=I?G(I):"",R=e.path;if(T)R+=`?${T}`;if(e.fragment)R+=`#${e.fragment}`;let h=S.request({...e.headers,[K.HTTP2_HEADER_PATH]:R,[K.HTTP2_HEADER_METHOD]:q});if(u)h.setTimeout(u,()=>{h.close();let i=Error(`Stream timed out because of no activity for ${u} ms`);i.name="TimeoutError",x(i)});if(t){let i=()=>{h.close();let d=U(t);x(d)};if(typeof t.addEventListener==="function"){let d=t;d.addEventListener("abort",i,{once:!0}),h.once("close",()=>d.removeEventListener("abort",i))}else t.onabort=i}h.on("frameError",(i,d,oe)=>{x(Error(`Frame type id ${i} in stream id ${oe} has failed with code ${d}.`))}),h.on("error",x),h.on("aborted",()=>{x(Error(`HTTP/2 stream is abnormally aborted in mid-communication with result code ${h.rstCode}.`))}),h.on("response",(i)=>{let d=new X({statusCode:i[":status"]??-1,headers:Y(i),body:h});if(g=!0,v({response:d}),a)S.close(),h.on("end",()=>{y.destroy()})}),h.on("close",()=>{if(a)y.destroy();else this.connectionManager.release(b,y);if(!g){let i=Error("Unexpected error: http2 request did not get a response");if(S.destroyed)i.name="TimeoutError";x(i)}}),w=Z(h,e,u)})}updateHttpClientConfig(e,t){this.config=void 0,this.configProvider=this.configProvider.then((o)=>({...o,[e]:t}))}httpHandlerConfigs(){return this.config??{}}}me.DEFAULT_REQUEST_TIMEOUT=he;me.NodeHttp2Handler=j;me.NodeHttpHandler=N});
|
|
5
|
+
export{Be};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
2
|
+
import{W}from"./chunk-r0jc8e7t.js";import{P}from"./chunk-c4qr1f41.js";import{z,fe}from"./chunk-x4874m8e.js";import{M,Ht,Te}from"./chunk-nx3jnbv8.js";class u extends Error{code;diagnosticDetails;constructor(r,t,n){super(r);this.name="PiMessagesResponseError",this.code=t,this.diagnosticDetails=n}}function x(r){try{let t=JSON.parse(r),n=t?.error;return t&&typeof n==="object"&&n!==null&&!Array.isArray(n)?t:void 0}catch{return}}function m(r){return r.length>8192?`${r.slice(0,8192)}\u2026`:r}function y(r,t,n){let e=typeof n?.error?.message==="string"?n.error.message:void 0,s=typeof n?.error?.code==="string"?n.error.code:void 0,a=e??t,o=s?` (${s})`:"";return`${r.status} ${r.statusText}: ${a}${o}`}function k(r,t,n,e){let s=x(e),a=typeof s?.error?.code==="string"?s.error.code:void 0;return new u(y(n,e,s),a,{version:1,provider:r.provider,model:r.id,url:t.toString(),status:n.status,statusText:n.statusText,...s?.error===void 0?{}:{error:s.error},...s?{}:{body:m(e)},timestampMs:Date.now()})}function h(){return{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}}}function l(r,t){if(!t)return;Te(r,{type:"pi_messages_rewrite",timestamp:Date.now(),details:{...t}})}function w(r){let t={role:"assistant",content:[],api:r.api,provider:r.provider,model:r.id,usage:h(),stopReason:"pending",timestamp:Date.now()},n=new Map;return(e)=>{switch(e.type){case"done":if(Object.assign(t,{stopReason:e.reason,usage:e.usage,responseId:e.responseId}),e.providerThinkingLevel!==void 0)t.providerThinkingLevel=e.providerThinkingLevel;return l(t,e.rewrite),{type:"done",reason:e.reason,message:t};case"error":if(Object.assign(t,{stopReason:e.reason,usage:e.usage,errorMessage:e.errorMessage,responseId:e.responseId}),e.providerThinkingLevel!==void 0)t.providerThinkingLevel=e.providerThinkingLevel;return l(t,e.rewrite),{type:"error",reason:e.reason,error:t};case"start":break;case"text_start":t.content[e.contentIndex]={type:"text",text:""};break;case"text_delta":t.content[e.contentIndex].text+=e.delta;break;case"text_end":Object.assign(t.content[e.contentIndex],{text:e.content,textSignature:e.contentSignature});break;case"thinking_start":t.content[e.contentIndex]={type:"thinking",thinking:""};break;case"thinking_delta":t.content[e.contentIndex].thinking+=e.delta;break;case"thinking_end":Object.assign(t.content[e.contentIndex],{thinking:e.content,thinkingSignature:e.contentSignature,redacted:e.redacted});break;case"toolcall_start":t.content[e.contentIndex]={type:"toolCall",id:e.id,name:e.toolName,arguments:{}},n.set(e.contentIndex,"");break;case"toolcall_delta":{let s=`${n.get(e.contentIndex)??""}${e.delta}`;n.set(e.contentIndex,s),t.content[e.contentIndex].arguments=W(s);break}case"toolcall_end":return Object.assign(t.content[e.contentIndex],e.toolCall),n.delete(e.contentIndex),{type:"toolcall_end",contentIndex:e.contentIndex,toolCall:t.content[e.contentIndex],partial:t}}return{...e,partial:t}}}async function*b(r){let t=new TextDecoder,n=r.getReader(),e="";try{while(!0){let{done:s,value:a}=await n.read();e+=s?t.decode():t.decode(a,{stream:!0}),e=e.replace(/\r\n/g,`
|
|
3
3
|
`);let o=e.indexOf(`
|
|
4
4
|
|
|
5
5
|
`);while(o!==-1){let c=f(e.slice(0,o));if(c)yield c;e=e.slice(o+2),o=e.indexOf(`
|
|
6
6
|
|
|
7
7
|
`)}if(s)break}if(e.trim()){let s=f(e);if(s)yield s}}finally{n.releaseLock()}}function f(r){let t=r.split(`
|
|
8
|
-
`).find((n)=>n.startsWith("data:"))?.slice(5).trim();return t&&t!=="[DONE]"?JSON.parse(t):void 0}function I(r,t,n){let e=n?"aborted":"error",s={role:"assistant",content:[],api:r.api,provider:r.provider,model:r.id,usage:h(),stopReason:e,errorMessage:t instanceof Error?t.message:String(t),timestamp:Date.now()};if(!n&&t instanceof u)Te(s,
|
|
8
|
+
`).find((n)=>n.startsWith("data:"))?.slice(5).trim();return t&&t!=="[DONE]"?JSON.parse(t):void 0}function I(r,t,n){let e=n?"aborted":"error",s={role:"assistant",content:[],api:r.api,provider:r.provider,model:r.id,usage:h(),stopReason:e,errorMessage:t instanceof Error?t.message:String(t),timestamp:Date.now()};if(!n&&t instanceof u)Te(s,Ht("pi_messages_response_failure",t,t.diagnosticDetails));return{type:"error",reason:e,error:s}}function E(r,t){if(r)return r;return P("PI_CACHE_RETENTION",t)==="long"?"long":void 0}var T=(r,t,n)=>{let e=new M,s=w(r);return(async()=>{try{let a=n?.apiKey;if(!a)throw Error(`No API key provided for provider "${r.provider}"`);let o=new URL(`${r.baseUrl.replace(/\/+$/u,"")}/messages`);if(n?.debug)o.searchParams.set("debug","1");let c={model:r.id,context:t,options:{temperature:n?.temperature,maxTokens:n?.maxTokens,reasoning:n?.reasoning,cacheRetention:E(n?.cacheRetention,n?.env),sessionId:n?.sessionId,toolChoice:n?.toolChoice}},p=await n?.onPayload?.(c,r);if(p!==void 0)c=p;let i=await(n?.fetch??globalThis.fetch)(o,{method:"POST",headers:{authorization:`Bearer ${a}`,accept:"text/event-stream","content-type":"application/json",...fe(n?.headers)},body:JSON.stringify(c),signal:n?.signal});if(await n?.onResponse?.({status:i.status,headers:z(i.headers)},r),!i.ok){let d=await i.text();throw k(r,o,i,d)}if(!i.body)throw Error(`${r.provider} response has no body`);for await(let d of b(i.body)){await n?.onProviderStreamEvent?.(d,r);let g=s(d);if(e.push(g),g.type==="done"||g.type==="error")return}throw Error(`${r.provider} stream ended without a terminal event`)}catch(a){e.push(I(r,a,n?.signal?.aborted??!1))}})(),e},C=(r,t,n)=>{let e=n;return T(r,t,{...n,reasoning:n?.reasoning,toolChoice:n?.toolChoice,debug:e?.debug})};export{u as PiMessagesResponseError,T as stream,C as streamSimple};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{L}from"./chunk-
|
|
2
|
+
import{L}from"./chunk-jvwg4rn1.js";import{b}from"./chunk-36cqq0ga.js";import{i}from"./chunk-bwawt15q.js";var u=i(b());var B=i(b());var p=i(L()),d=i(b());var P=i(L()),f=i(b()),S=(e,t,r)=>{let o={EcsContainer:async(s)=>{let{fromHttp:a}=await import("./chunk-x89em726.js"),{fromContainerMetadata:n}=await import("./chunk-pjr91g6k.js");return r?.debug("@aws-sdk/credential-provider-ini - credential_source is EcsContainer"),async()=>f.chain(a(s??{}),n(s))().then(m)},Ec2InstanceMetadata:async(s)=>{r?.debug("@aws-sdk/credential-provider-ini - credential_source is Ec2InstanceMetadata");let{fromInstanceMetadata:a}=await import("./chunk-pjr91g6k.js");return async()=>a(s)().then(m)},Environment:async(s)=>{r?.debug("@aws-sdk/credential-provider-ini - credential_source is Environment");let{fromEnv:a}=await import("./chunk-yna8bwqc.js");return async()=>a(s)().then(m)}};if(e in o)return o[e];else throw new f.CredentialsProviderError(`Unsupported credential source in profile ${t}. Got ${e}, expected EcsContainer or Ec2InstanceMetadata or Environment.`,{logger:r})},m=(e)=>P.setCredentialFeature(e,"CREDENTIALS_PROFILE_NAMED_PROVIDER","p");var I=(e,{profile:t="default",logger:r}={})=>Boolean(e)&&typeof e==="object"&&typeof e.role_arn==="string"&&["undefined","string"].indexOf(typeof e.role_session_name)>-1&&["undefined","string"].indexOf(typeof e.external_id)>-1&&["undefined","string"].indexOf(typeof e.mfa_serial)>-1&&(q(e,{profile:t,logger:r})||H(e,{profile:t,logger:r})),q=(e,{profile:t,logger:r})=>{let o=typeof e.source_profile==="string"&&typeof e.credential_source>"u";if(o)r?.debug?.(` ${t} isAssumeRoleWithSourceProfile source_profile=${e.source_profile}`);return o},H=(e,{profile:t,logger:r})=>{let o=typeof e.credential_source==="string"&&typeof e.source_profile>"u";if(o)r?.debug?.(` ${t} isCredentialSourceProfile credential_source=${e.credential_source}`);return o},R=async(e,t,r,o,s={},a)=>{r.logger?.debug("@aws-sdk/credential-provider-ini - resolveAssumeRoleCredentials (STS)");let n=t[e],{source_profile:c,region:K}=n;if(!r.roleAssumer){let{getDefaultRoleAssumer:l}=await import("./chunk-e63c1186.js");r.roleAssumer=l({...r.clientConfig,credentialProviderLogger:r.logger,parentClientConfig:{...o,...r?.parentClientConfig,region:K??r?.parentClientConfig?.region??o?.region}},r.clientPlugins)}if(c&&c in s)throw new d.CredentialsProviderError(`Detected a cycle attempting to resolve credentials for profile ${d.getProfileName(r)}. Profiles visited: `+Object.keys(s).join(", "),{logger:r.logger});r.logger?.debug(`@aws-sdk/credential-provider-ini - finding credential resolver using ${c?`source_profile=[${c}]`:`profile=[${e}]`}`);let E=c?a(c,t,r,o,{...s,[c]:!0},v(t[c]??{})):(await S(n.credential_source,e,r.logger)(r))();if(v(n))return E.then((l)=>p.setCredentialFeature(l,"CREDENTIALS_PROFILE_SOURCE_PROFILE","o"));else{let l={RoleArn:n.role_arn,RoleSessionName:n.role_session_name||`aws-sdk-js-${Date.now()}`,ExternalId:n.external_id,DurationSeconds:parseInt(n.duration_seconds||"3600",10)},{mfa_serial:_}=n;if(_){if(!r.mfaCodeProvider)throw new d.CredentialsProviderError(`Profile ${e} requires multi-factor authentication, but no MFA code callback was provided.`,{logger:r.logger,tryNextLink:!1});l.SerialNumber=_,l.TokenCode=await r.mfaCodeProvider(_)}let G=await E;return r.roleAssumer(G,l).then((U)=>p.setCredentialFeature(U,"CREDENTIALS_PROFILE_SOURCE_PROFILE","o"))}},v=(e)=>!e.role_arn&&!!e.credential_source;var A=i(L()),O=(e)=>Boolean(e&&e.login_session),x=async(e,t,r)=>{let{fromLoginCredentials:o}=await import("./chunk-5v4g21rw.js"),s=await o({...t,profile:e})({callerClientConfig:r});return A.setCredentialFeature(s,"CREDENTIALS_PROFILE_LOGIN","AC")};var k=i(L()),F=(e)=>Boolean(e)&&typeof e==="object"&&typeof e.credential_process==="string",h=async(e,t)=>{let{fromProcess:r}=await import("./chunk-aw65h276.js"),o=await r({...e,profile:t})();return k.setCredentialFeature(o,"CREDENTIALS_PROFILE_PROCESS","v")};var C=i(L()),D=async(e,t,r={},o)=>{let{fromSSO:s}=await import("./chunk-1xa7d5mh.js");return s({profile:e,logger:r.logger,parentClientConfig:r.parentClientConfig,clientConfig:r.clientConfig})({callerClientConfig:o}).then((a)=>{if(t.sso_session)return C.setCredentialFeature(a,"CREDENTIALS_PROFILE_SSO","r");else return C.setCredentialFeature(a,"CREDENTIALS_PROFILE_SSO_LEGACY","t")})},T=(e)=>e&&(typeof e.sso_start_url==="string"||typeof e.sso_account_id==="string"||typeof e.sso_session==="string"||typeof e.sso_region==="string"||typeof e.sso_role_name==="string");var W=i(L()),y=(e)=>Boolean(e)&&typeof e==="object"&&typeof e.aws_access_key_id==="string"&&typeof e.aws_secret_access_key==="string"&&["undefined","string"].indexOf(typeof e.aws_session_token)>-1&&["undefined","string"].indexOf(typeof e.aws_account_id)>-1,g=async(e,t)=>{t?.logger?.debug("@aws-sdk/credential-provider-ini - resolveStaticCredentials");let r={accessKeyId:e.aws_access_key_id,secretAccessKey:e.aws_secret_access_key,sessionToken:e.aws_session_token,...e.aws_credential_scope&&{credentialScope:e.aws_credential_scope},...e.aws_account_id&&{accountId:e.aws_account_id}};return W.setCredentialFeature(r,"CREDENTIALS_PROFILE","n")};var N=i(L()),j=(e)=>Boolean(e)&&typeof e==="object"&&typeof e.web_identity_token_file==="string"&&typeof e.role_arn==="string"&&["undefined","string"].indexOf(typeof e.role_session_name)>-1,M=async(e,t,r)=>{let{fromTokenFile:o}=await import("./chunk-7as47pcw.js"),s=await o({webIdentityTokenFile:e.web_identity_token_file,roleArn:e.role_arn,roleSessionName:e.role_session_name,roleAssumerWithWebIdentity:t.roleAssumerWithWebIdentity,logger:t.logger,parentClientConfig:t.parentClientConfig})({callerClientConfig:r});return N.setCredentialFeature(s,"CREDENTIALS_PROFILE_STS_WEB_ID_TOKEN","q")};var w=async(e,t,r,o,s={},a=!1)=>{let n=t[e];if(Object.keys(s).length>0&&y(n))return g(n,r);if(a||I(n,{profile:e,logger:r.logger}))return R(e,t,r,o,s,w);if(y(n))return g(n,r);if(j(n))return M(n,r,o);if(F(n))return h(r,e);if(T(n))return await D(e,n,r,o);if(O(n))return x(e,r,o);throw new B.CredentialsProviderError(`Could not resolve credentials using profile: [${e}] in configuration/credentials file(s).`,{logger:r.logger})};var V=(e={})=>async({callerClientConfig:t}={})=>{e.logger?.debug("@aws-sdk/credential-provider-ini - fromIni");let r=await u.parseKnownFiles(e);return w(u.getProfileName({profile:e.profile??t?.profile}),r,e,t)};export{V as fromIni};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
2
|
+
import{hr}from"./chunk-ebzkckyw.js";import{se}from"./chunk-hq5ke1yp.js";var t={api:"typesafe-system-one",label:"System One API",url:(e)=>new URL("systemone",`${e.baseUrl.replace(/\/+$/u,"")}/`),payload:(e,r)=>({model:e.id,...r}),output:(e)=>{if(!se(e))throw Error("System One API returned an unexpected response");return e}},a=(e,r,s)=>hr(t,e,r,s);export{a as classify};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{L}from"./chunk-
|
|
2
|
+
import{L}from"./chunk-jvwg4rn1.js";import{b}from"./chunk-36cqq0ga.js";import{i}from"./chunk-bwawt15q.js";var g=i(b());var U=(e)=>e&&(typeof e.sso_start_url==="string"||typeof e.sso_account_id==="string"||typeof e.sso_session==="string"||typeof e.sso_region==="string"||typeof e.sso_role_name==="string");var R=i(L());var f=i(b());var j=300000,k="To refresh this SSO session run 'aws sso login' with the corresponding profile.";var q=async(e,o={},r)=>{let{SSOOIDCClient:t}=await import("./chunk-2qcpq99g.js"),n=(p)=>o.clientConfig?.[p]??o.parentClientConfig?.[p]??r?.[p];return new t(Object.assign({},o.clientConfig??{},{region:e??o.clientConfig?.region,logger:n("logger"),userAgentAppId:n("userAgentAppId")}))};var W=async(e,o,r={},t)=>{let{CreateTokenCommand:n}=await import("./chunk-2qcpq99g.js");return(await q(o,r,t)).send(new n({clientId:e.clientId,clientSecret:e.clientSecret,refreshToken:e.refreshToken,grantType:"refresh_token"}))};var X=i(b());var I=(e)=>{if(e.expiration&&e.expiration.getTime()<Date.now())throw new X.TokenProviderError(`Token is expired. ${k}`,!1)};var z=i(b());var w=(e,o,r=!1)=>{if(typeof o>"u")throw new z.TokenProviderError(`Value not present for '${e}' in SSO Token${r?". Cannot refresh":""}. ${k}`,!1)};var J=i(b());import{promises as ee}from"fs";var{writeFile:oe}=ee,V=(e,o)=>{let r=J.getSSOTokenFilepath(e),t=JSON.stringify(o,null,2);return oe(r,t)};var Y=new Map,N=(e={})=>async({callerClientConfig:o}={})=>{e.logger?.debug("@aws-sdk/token-providers - fromSso");let r=await f.parseKnownFiles(e),t=f.getProfileName({profile:e.profile??o?.profile}),n=r[t];if(!n)throw new f.TokenProviderError(`Profile '${t}' could not be found in shared credentials file.`,!1);else if(!n.sso_session)throw new f.TokenProviderError(`Profile '${t}' is missing required property 'sso_session'.`);let a=n.sso_session,S=(await f.loadSsoSessionData(e))[a];if(!S)throw new f.TokenProviderError(`Sso session '${a}' could not be found in shared credentials file.`,!1);for(let c of["sso_start_url","sso_region"])if(!S[c])throw new f.TokenProviderError(`Sso session '${a}' is missing required property '${c}'.`,!1);let{sso_start_url:d,sso_region:y}=S,s;try{s=await f.getSSOTokenFromFile(a)}catch(c){throw new f.TokenProviderError(`The SSO session token associated with profile=${t} was not found or is invalid. ${k}`,!1)}w("accessToken",s.accessToken),w("expiresAt",s.expiresAt);let{accessToken:T,expiresAt:x}=s,l={token:T,expiration:new Date(x)};if(l.expiration.getTime()-Date.now()>j)return l;let m=Y.get(a)??0;if(Date.now()-m<30000)return I(l),l;w("clientId",s.clientId,!0),w("clientSecret",s.clientSecret,!0),w("refreshToken",s.refreshToken,!0);try{Y.set(a,Date.now());let c=await W(s,y,e,o);w("accessToken",c.accessToken),w("expiresIn",c.expiresIn);let C=new Date(Date.now()+c.expiresIn*1000);try{await V(a,{...s,accessToken:c.accessToken,expiresAt:C.toISOString(),refreshToken:c.refreshToken})}catch(u){}return{token:c.accessToken,expiration:C}}catch(c){return I(l),l}};var h=i(b()),O=!1,v=async({ssoStartUrl:e,ssoSession:o,ssoAccountId:r,ssoRegion:t,ssoRoleName:n,ssoClient:a,clientConfig:p,parentClientConfig:S,callerClientConfig:d,profile:y,filepath:s,configFilepath:T,ignoreCache:x,logger:l})=>{let m,c="To refresh this SSO session run aws sso login with the corresponding profile.";if(o)try{let _=await N({profile:y,filepath:s,configFilepath:T,ignoreCache:x,clientConfig:p,parentClientConfig:S,logger:l})({callerClientConfig:d});m={accessToken:_.token,expiresAt:new Date(_.expiration).toISOString()}}catch(_){throw new h.CredentialsProviderError(_.message,{tryNextLink:O,logger:l})}else try{m=await h.getSSOTokenFromFile(e)}catch(_){throw new h.CredentialsProviderError("The SSO session associated with this profile is invalid. To refresh this SSO session run aws sso login with the corresponding profile.",{tryNextLink:O,logger:l})}if(new Date(m.expiresAt).getTime()-Date.now()<=0)throw new h.CredentialsProviderError("The SSO session associated with this profile has expired. To refresh this SSO session run aws sso login with the corresponding profile.",{tryNextLink:O,logger:l});let{accessToken:C}=m,{SSOClient:u,GetRoleCredentialsCommand:E}=await import("./chunk-zrkh5dw7.js"),Z=a||new u(Object.assign({},p??{},{logger:p?.logger??d?.logger??S?.logger,region:p?.region??t,userAgentAppId:p?.userAgentAppId??d?.userAgentAppId??S?.userAgentAppId})),P;try{P=await Z.send(new E({accountId:r,roleName:n,accessToken:C}))}catch(_){throw new h.CredentialsProviderError(_,{tryNextLink:O,logger:l})}let{roleCredentials:{accessKeyId:F,secretAccessKey:D,sessionToken:M,expiration:G,credentialScope:K,accountId:H}={}}=P;if(!F||!D||!M||!G)throw new h.CredentialsProviderError("SSO returns an invalid temporary credential.",{tryNextLink:O,logger:l});let A={accessKeyId:F,secretAccessKey:D,sessionToken:M,expiration:new Date(G),...K&&{credentialScope:K},...H&&{accountId:H}};if(o)R.setCredentialFeature(A,"CREDENTIALS_SSO","s");else R.setCredentialFeature(A,"CREDENTIALS_SSO_LEGACY","u");return A};var B=i(b()),Q=(e,o)=>{let{sso_start_url:r,sso_account_id:t,sso_region:n,sso_role_name:a}=e;if(!r||!t||!n||!a)throw new B.CredentialsProviderError(`Profile is configured with invalid SSO credentials. Required parameters "sso_account_id", "sso_region", "sso_role_name", "sso_start_url". Got ${Object.keys(e).join(", ")}
|
|
3
3
|
Reference: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sso.html`,{tryNextLink:!1,logger:o});return e};var se=(e={})=>async({callerClientConfig:o}={})=>{e.logger?.debug("@aws-sdk/credential-provider-sso - fromSSO");let{ssoStartUrl:r,ssoAccountId:t,ssoRegion:n,ssoRoleName:a,ssoSession:p}=e,{ssoClient:S}=e,d=g.getProfileName({profile:e.profile??o?.profile});if(!r&&!t&&!n&&!a&&!p){let s=(await g.parseKnownFiles(e))[d];if(!s)throw new g.CredentialsProviderError(`Profile ${d} was not found.`,{logger:e.logger});if(!U(s))throw new g.CredentialsProviderError(`Profile ${d} is not configured with SSO credentials.`,{logger:e.logger});if(s?.sso_session){let u=(await g.loadSsoSessionData(e))[s.sso_session],E=` configurations in profile ${d} and sso-session ${s.sso_session}`;if(n&&n!==u.sso_region)throw new g.CredentialsProviderError("Conflicting SSO region"+E,{tryNextLink:!1,logger:e.logger});if(r&&r!==u.sso_start_url)throw new g.CredentialsProviderError("Conflicting SSO start_url"+E,{tryNextLink:!1,logger:e.logger});s.sso_region=u.sso_region,s.sso_start_url=u.sso_start_url}let{sso_start_url:T,sso_account_id:x,sso_region:l,sso_role_name:m,sso_session:c}=Q(s,e.logger);return v({ssoStartUrl:T,ssoSession:c,ssoAccountId:x,ssoRegion:l,ssoRoleName:m,ssoClient:S,clientConfig:e.clientConfig,parentClientConfig:e.parentClientConfig,callerClientConfig:e.callerClientConfig,profile:d,filepath:e.filepath,configFilepath:e.configFilepath,ignoreCache:e.ignoreCache,logger:e.logger})}else if(!r||!t||!n||!a)throw new g.CredentialsProviderError('Incomplete configuration. The fromSSO() argument hash must include "ssoStartUrl", "ssoAccountId", "ssoRegion", "ssoRoleName"',{tryNextLink:!1,logger:e.logger});else return v({ssoStartUrl:r,ssoSession:p,ssoAccountId:t,ssoRegion:n,ssoRoleName:a,ssoClient:S,clientConfig:e.clientConfig,parentClientConfig:e.parentClientConfig,callerClientConfig:e.callerClientConfig,profile:d,filepath:e.filepath,configFilepath:e.configFilepath,ignoreCache:e.ignoreCache,logger:e.logger})};export{se as fromSSO};
|