dsh-connect-workbuddy-gateway 1.0.0 → 1.1.1
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 +42 -15
- package/client.js +121 -1
- package/index.js +162 -136
- package/package.json +1 -2
- package/src/config.js +80 -4
- package/src/routes.js +172 -6
- package/docs/RELEASE-TODO.md +0 -92
package/README.md
CHANGED
|
@@ -63,9 +63,7 @@ git clone https://github.com/Roozenlz/dsh-connect-workbuddy-gateway
|
|
|
63
63
|
dsh-connect-workbuddy-gateway
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
>
|
|
67
|
-
> `1.0.0` 而整包删除;npm 对整包删除有 24 小时重发冷却,之后会以 `1.0.0` 发布。
|
|
68
|
-
> 在此之前请用 A 或 B。
|
|
66
|
+
> 已发布:`1.0.1`(`latest`)。`1.0.0` 也在,两者的差别只是发布渠道,功能相同。
|
|
69
67
|
|
|
70
68
|
**D. 从插件市场**
|
|
71
69
|
|
|
@@ -254,15 +252,38 @@ hy4flash-free@#9 ← 昵称含中文/emoji,退化成序号
|
|
|
254
252
|
- 每把 key:名称、启停,以及**按账号分组的模型勾选**(带搜索、全选、清空)
|
|
255
253
|
- 直接列出「客户端会看到的名字」,重名后缀一目了然
|
|
256
254
|
- 账号不可用时给出警告条与恢复时间
|
|
255
|
+
- **存储位置**:查看并修改配置目录
|
|
257
256
|
- 底部一条 `curl` 示例
|
|
258
257
|
|
|
259
|
-
|
|
258
|
+
### 存储位置
|
|
260
259
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
260
|
+
配置目录**可以自定义**,在设置页底部的「存储位置」里改:
|
|
261
|
+
|
|
262
|
+
| 填什么 | 解析成 |
|
|
263
|
+
|---|---|
|
|
264
|
+
| 留空 | `$DSH_HOME/dsh-connect-workbuddy-gateway/`(默认,目录名与包名一致) |
|
|
265
|
+
| 相对路径(`my-keys`) | `$DSH_HOME/my-keys/` |
|
|
266
|
+
| 绝对路径(`D:\keys`) | 原样使用 |
|
|
267
|
+
|
|
268
|
+
`keys.json` 落在这个目录里,权限 600,只存本插件自己的 key 与勾选清单,
|
|
269
|
+
**不含任何 WorkBuddy 凭据**。
|
|
264
270
|
|
|
265
|
-
|
|
271
|
+
两项注意:
|
|
272
|
+
|
|
273
|
+
- **换目录不会搬数据。** 原目录里的 key 仍在原目录,新的空目录里没有它们。设置页
|
|
274
|
+
保存时会明确提示这一点。
|
|
275
|
+
- 改这一项写进的是**插件配置**(profile 的 `cordis.patch.yml`),不是 `keys.json`
|
|
276
|
+
—— 让 `keys.json` 描述「`keys.json` 自己在哪」是自相矛盾的。插件会重启一次来
|
|
277
|
+
应用新值。
|
|
278
|
+
|
|
279
|
+
也可以直接改 profile 里的那一行:
|
|
280
|
+
|
|
281
|
+
```yaml
|
|
282
|
+
- id: workbuddy-gateway
|
|
283
|
+
name: dsh-connect-workbuddy-gateway
|
|
284
|
+
config:
|
|
285
|
+
dataDir: D:\keys # 留空或删掉这一行 = 用默认
|
|
286
|
+
```
|
|
266
287
|
|
|
267
288
|
---
|
|
268
289
|
|
|
@@ -333,7 +354,7 @@ $DSH_HOME/workbuddy-gateway/keys.json # 权限 600
|
|
|
333
354
|
node tests/harness.mjs
|
|
334
355
|
```
|
|
335
356
|
|
|
336
|
-
覆盖
|
|
357
|
+
覆盖 176 项:首次建 key 与惰性补选、鉴权、模型勾选与清单投影、重名后缀(区域 / 昵称 /
|
|
337
358
|
非 ASCII 序号)、跨区同名、按名字路由、推理档透传、并行工具调用按 index 分组、
|
|
338
359
|
Responses 流的规范校验(`sequence_number`、part 一致性、terminal 的 output 顺序)、
|
|
339
360
|
上游失败与断流的诚实报告、账号可用性与恢复、四种协议的流式与非流式、工具调用三方言、
|
|
@@ -353,16 +374,18 @@ Responses 流的规范校验(`sequence_number`、part 一致性、terminal 的
|
|
|
353
374
|
推一个与 `package.json` 版本号一致的 tag:
|
|
354
375
|
|
|
355
376
|
```bash
|
|
356
|
-
# package.json 里是 1.0.
|
|
357
|
-
git tag v1.0.
|
|
358
|
-
git push origin v1.0.
|
|
377
|
+
# package.json 里是 1.0.1 就推 v1.0.1
|
|
378
|
+
git tag v1.0.1
|
|
379
|
+
git push origin v1.0.1
|
|
359
380
|
```
|
|
360
381
|
|
|
361
382
|
`.github/workflows/publish.yml` 会校验 tag 与版本一致、跑一遍自测,然后发布。
|
|
362
383
|
|
|
363
|
-
**凭据走 OIDC,仓库里不存任何 npm token。**
|
|
384
|
+
**凭据走 OIDC,仓库里不存任何 npm token。** 已验证可用:`1.0.1` 由 CI 发布,npm 记录的
|
|
385
|
+
发布者是 `GitHub Actions` 而不是某个账号。配置方式:
|
|
364
386
|
|
|
365
|
-
> `https://www.npmjs.com/package
|
|
387
|
+
> `https://www.npmjs.com/package/dsh-connect-workbuddy-gateway/access`
|
|
388
|
+
> → Trusted Publisher → GitHub Actions
|
|
366
389
|
>
|
|
367
390
|
> | 字段 | 值 |
|
|
368
391
|
> |---|---|
|
|
@@ -371,7 +394,11 @@ git push origin v1.0.0
|
|
|
371
394
|
> | Workflow name | `publish.yml` |
|
|
372
395
|
> | Environment | 留空 |
|
|
373
396
|
>
|
|
374
|
-
> 勾选 `npm publish` 权限。配好后状态是 **Pending validation
|
|
397
|
+
> 勾选 `npm publish` 权限。配好后状态是 **Pending validation**,成功发布一次才会变成已验证。
|
|
398
|
+
|
|
399
|
+
**关于日志里的 `NODE_AUTH_TOKEN`**:GitHub 会为 `actions/setup-node` 注入一个脱敏占位值,
|
|
400
|
+
日志显示为 `XXXXX-XXXXX-XXXXX-XXXXX`。那不代表仓库里存了 token —— `gh secret list` 为空
|
|
401
|
+
即可确认。真正生效的凭据是 OIDC 当场换取的。
|
|
375
402
|
|
|
376
403
|
为什么不用 token:npm 已宣布「绕过 2FA 的 token」将在 2027 年 1 月起不能用于发布,
|
|
377
404
|
而且长期 token 一旦泄漏就等于交出发布权。
|
package/client.js
CHANGED
|
@@ -58,6 +58,17 @@ window.__ModuleLoader__.load({
|
|
|
58
58
|
healthStale: '尚未读到上游账号状态',
|
|
59
59
|
brokenSelections: '其中 {n} 个模型所用的账号当前不可用,请求会失败;账号恢复后会自动生效。',
|
|
60
60
|
autoRefresh: '每 30 秒自动刷新',
|
|
61
|
+
storage: '存储位置',
|
|
62
|
+
storageHint: 'API key 与模型勾选存在这个目录的 keys.json 里。留空则用默认目录。',
|
|
63
|
+
storageCurrent: '当前目录',
|
|
64
|
+
storageFile: '配置文件',
|
|
65
|
+
storageDefault: '默认',
|
|
66
|
+
storagePlaceholder: '留空 = 默认({name})',
|
|
67
|
+
storageHintRelative: '相对路径基于 DSH 主目录;也可以填绝对路径。',
|
|
68
|
+
storageSave: '保存目录',
|
|
69
|
+
storageSaved: '已保存,插件会重新加载以生效',
|
|
70
|
+
storageWarn: '换目录后,原目录里的 key 不会自动带过来。',
|
|
71
|
+
storageEmptyUses: '留空时使用默认目录:',
|
|
61
72
|
selected: '已选',
|
|
62
73
|
noneSelected: '还没有勾选任何模型,这把 key 暂时不能用。',
|
|
63
74
|
willExpose: '客户端会看到',
|
|
@@ -115,6 +126,17 @@ window.__ModuleLoader__.load({
|
|
|
115
126
|
healthStale: 'No upstream account state yet',
|
|
116
127
|
brokenSelections: '{n} of these models use an account that is unavailable right now, so requests will fail until it recovers.',
|
|
117
128
|
autoRefresh: 'Refreshes every 30 s',
|
|
129
|
+
storage: 'Storage',
|
|
130
|
+
storageHint: 'API keys and model selections live in keys.json under this directory. Leave empty for the default.',
|
|
131
|
+
storageCurrent: 'Current directory',
|
|
132
|
+
storageFile: 'Config file',
|
|
133
|
+
storageDefault: 'default',
|
|
134
|
+
storagePlaceholder: 'Empty = default ({name})',
|
|
135
|
+
storageHintRelative: 'A relative path is resolved against the DSH home; an absolute path is used as-is.',
|
|
136
|
+
storageSave: 'Save directory',
|
|
137
|
+
storageSaved: 'Saved; the plugin reloads to apply it',
|
|
138
|
+
storageWarn: 'Keys in the previous directory are not copied over.',
|
|
139
|
+
storageEmptyUses: 'Empty uses the default directory:',
|
|
118
140
|
selected: 'selected',
|
|
119
141
|
noneSelected: 'No models ticked yet, so this key cannot be used.',
|
|
120
142
|
willExpose: 'The client will see',
|
|
@@ -656,6 +678,91 @@ window.__ModuleLoader__.load({
|
|
|
656
678
|
)
|
|
657
679
|
}
|
|
658
680
|
|
|
681
|
+
/* ── 存储位置 ───────────────────────────────────────────────────── */
|
|
682
|
+
|
|
683
|
+
/**
|
|
684
|
+
* 配置目录卡片:显示当前目录,允许改成任意路径。
|
|
685
|
+
*
|
|
686
|
+
* 「留空」和「填具体值」在这里是两种语义,界面上要说清:
|
|
687
|
+
* 留空 → 跟随默认(目录名与包名一致),升级/换机器都不用管
|
|
688
|
+
* 有值 → 用你指定的那个目录,相对路径基于 DSH 主目录
|
|
689
|
+
*/
|
|
690
|
+
function StorageCard({ state, t, onSave }) {
|
|
691
|
+
const paths = state?.paths ?? {}
|
|
692
|
+
const [value, setValue] = useState(
|
|
693
|
+
paths.dataDirIsDefault === false && typeof paths.dataDir === 'string' ? paths.dataDir : '',
|
|
694
|
+
)
|
|
695
|
+
const [busy, setBusy] = useState(false)
|
|
696
|
+
const [error, setError] = useState(undefined)
|
|
697
|
+
const [saved, setSaved] = useState(false)
|
|
698
|
+
|
|
699
|
+
/* 外部刷新(每 30 秒)回来时,如果用户没在编辑就跟着更新。 */
|
|
700
|
+
useEffect(() => {
|
|
701
|
+
if (busy || saved) return
|
|
702
|
+
setValue(paths.dataDirIsDefault === false && typeof paths.dataDir === 'string' ? paths.dataDir : '')
|
|
703
|
+
}, [paths.dataDir, paths.dataDirIsDefault])
|
|
704
|
+
|
|
705
|
+
const commit = async () => {
|
|
706
|
+
setBusy(true)
|
|
707
|
+
setError(undefined)
|
|
708
|
+
try {
|
|
709
|
+
await onSave(value)
|
|
710
|
+
setSaved(true)
|
|
711
|
+
setTimeout(() => setSaved(false), 4000)
|
|
712
|
+
} catch (caught) {
|
|
713
|
+
setError(String(caught.message ?? caught))
|
|
714
|
+
} finally {
|
|
715
|
+
setBusy(false)
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
const defaultName = paths.defaultDataDirName ?? 'dsh-connect-workbuddy-gateway'
|
|
720
|
+
|
|
721
|
+
return h('div', { className: 'wbg-card wbg-card-soft' },
|
|
722
|
+
h('div', { className: 'wbg-row' },
|
|
723
|
+
h('strong', { className: 'wbg-sec-title' }, t.storage),
|
|
724
|
+
h('span', { className: 'wbg-spacer' }),
|
|
725
|
+
h('span', { className: 'wbg-caption' }, t.storageHint),
|
|
726
|
+
),
|
|
727
|
+
|
|
728
|
+
h('div', { className: 'wbg-field' },
|
|
729
|
+
h('span', null, t.storageCurrent),
|
|
730
|
+
h('code', { className: 'wbg-mono', style: { wordBreak: 'break-all' } }, paths.dataDir ?? '(resolving)'),
|
|
731
|
+
),
|
|
732
|
+
h('p', { className: 'wbg-caption' },
|
|
733
|
+
`${t.storageFile}: ${paths.configPath ?? ''}`),
|
|
734
|
+
|
|
735
|
+
h('div', { className: 'wbg-field' },
|
|
736
|
+
h('span', null, t.storageHintRelative),
|
|
737
|
+
h('input', {
|
|
738
|
+
className: 'wbg-input',
|
|
739
|
+
value,
|
|
740
|
+
placeholder: t.storagePlaceholder.replace('{name}', defaultName),
|
|
741
|
+
'aria-label': t.storage,
|
|
742
|
+
onChange: (event) => setValue(event.target.value),
|
|
743
|
+
}),
|
|
744
|
+
),
|
|
745
|
+
|
|
746
|
+
h('p', { className: 'wbg-caption' }, `${t.storageEmptyUses} ${defaultName}`),
|
|
747
|
+
h('p', { className: 'wbg-warn' }, t.storageWarn),
|
|
748
|
+
|
|
749
|
+
error === undefined ? null : h('div', { className: 'wbg-alert wbg-alert-error' },
|
|
750
|
+
h('span', { className: 'wbg-alert-icon', 'aria-hidden': true }, '!'),
|
|
751
|
+
h('span', { className: 'wbg-alert-body' }, error)),
|
|
752
|
+
|
|
753
|
+
h('div', { className: 'wbg-row' },
|
|
754
|
+
saved ? h('span', { className: 'wbg-caption' }, t.storageSaved) : null,
|
|
755
|
+
h('span', { className: 'wbg-spacer' }),
|
|
756
|
+
h('button', {
|
|
757
|
+
type: 'button',
|
|
758
|
+
className: 'wbg-btn wbg-btn-primary',
|
|
759
|
+
onClick: commit,
|
|
760
|
+
disabled: busy,
|
|
761
|
+
}, t.storageSave),
|
|
762
|
+
),
|
|
763
|
+
)
|
|
764
|
+
}
|
|
765
|
+
|
|
659
766
|
/* ── 页面 ───────────────────────────────────────────────────────── */
|
|
660
767
|
|
|
661
768
|
function GatewaySection() {
|
|
@@ -724,6 +831,18 @@ window.__ModuleLoader__.load({
|
|
|
724
831
|
|
|
725
832
|
const revealKey = useCallback((id) => adminPost('/keys/reveal', { id }), [])
|
|
726
833
|
|
|
834
|
+
/*
|
|
835
|
+
* 保存配置目录。
|
|
836
|
+
*
|
|
837
|
+
* 它进的是**插件配置**(`cordis.patch.yml` 的那一行),不是 keys.json ——
|
|
838
|
+
* 让 keys.json 描述「keys.json 自己在哪」是自相矛盾的。保存后宿主会重启
|
|
839
|
+
* 这个插件,`apply` 读到的就是新值。
|
|
840
|
+
*/
|
|
841
|
+
const saveDataDir = useCallback(async (dataDir) => {
|
|
842
|
+
await adminPost('/config/data-dir', { dataDir })
|
|
843
|
+
await reload()
|
|
844
|
+
}, [reload])
|
|
845
|
+
|
|
727
846
|
if (state === undefined) {
|
|
728
847
|
return h('div', { className: 'wbg' },
|
|
729
848
|
h('style', null, CSS),
|
|
@@ -816,9 +935,10 @@ window.__ModuleLoader__.load({
|
|
|
816
935
|
h('strong', { className: 'wbg-sec-title' }, t.guide),
|
|
817
936
|
h('p', { className: 'wbg-hint' }, t.guideHint),
|
|
818
937
|
h('pre', { className: 'wbg-code wbg-mono' }, curlExample),
|
|
819
|
-
h('p', { className: 'wbg-caption' }, `${t.configPath}: ${state.configPath}`),
|
|
820
938
|
),
|
|
821
939
|
|
|
940
|
+
h(StorageCard, { state, t, onSave: saveDataDir }),
|
|
941
|
+
|
|
822
942
|
created === undefined ? null : h(SecretDialog, {
|
|
823
943
|
secret: created,
|
|
824
944
|
intro: t.created,
|
package/index.js
CHANGED
|
@@ -1,136 +1,162 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WorkBuddy Gateway —— 把 dsh-connect-workbuddy 提供的模型开放成本机可调用的
|
|
3
|
-
* HTTP API。
|
|
4
|
-
*
|
|
5
|
-
* 四种协议共用一个 base_url:
|
|
6
|
-
*
|
|
7
|
-
* OpenAI Chat Completions POST {base}/v1/chat/completions
|
|
8
|
-
* OpenAI Responses POST {base}/v1/responses
|
|
9
|
-
* Anthropic Messages POST {base}/v1/messages
|
|
10
|
-
* Gemini generateContent POST {base}/v1beta/models/{model}:generateContent
|
|
11
|
-
*
|
|
12
|
-
* **每把 key 勾选自己要对外提供的模型。** 用户直接勾哪些 (账号, 模型) 组合,
|
|
13
|
-
* `/v1/models` 就返回哪些;客户端选哪个模型由它自己决定,插件只负责照单发货。
|
|
14
|
-
* 见 src/catalog.js 与 src/resolve.js。
|
|
15
|
-
* (跟随 DSH 默认 / 跟随活跃会话 / 固定模型 / 固定账号 / 目录第一个),在
|
|
16
|
-
* 设置 → WorkBuddy Gateway 里管理。请求体不写 `model` 时就用这把 key 的策略。
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import { registerRoutes, baseUrlOf } from './src/routes.js'
|
|
20
|
-
import { workbuddyProviders } from './src/backend.js'
|
|
21
|
-
import { closeDirect } from './src/direct.js'
|
|
22
|
-
import { readConfig, writeConfig, makeKey, normalizeSelections, configPath } from './src/config.js'
|
|
23
|
-
import { catalogForSettings } from './src/models.js'
|
|
24
|
-
|
|
25
|
-
export const name = 'workbuddy-gateway'
|
|
26
|
-
|
|
27
|
-
/** 必须先有 webServer 才能挂路由;llm 由 workbuddy 插件提供,按需读取。 */
|
|
28
|
-
export const inject = ['webServer']
|
|
29
|
-
|
|
30
|
-
const DEFAULTS = {
|
|
31
|
-
/**
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*/
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
1
|
+
/**
|
|
2
|
+
* WorkBuddy Gateway —— 把 dsh-connect-workbuddy 提供的模型开放成本机可调用的
|
|
3
|
+
* HTTP API。
|
|
4
|
+
*
|
|
5
|
+
* 四种协议共用一个 base_url:
|
|
6
|
+
*
|
|
7
|
+
* OpenAI Chat Completions POST {base}/v1/chat/completions
|
|
8
|
+
* OpenAI Responses POST {base}/v1/responses
|
|
9
|
+
* Anthropic Messages POST {base}/v1/messages
|
|
10
|
+
* Gemini generateContent POST {base}/v1beta/models/{model}:generateContent
|
|
11
|
+
*
|
|
12
|
+
* **每把 key 勾选自己要对外提供的模型。** 用户直接勾哪些 (账号, 模型) 组合,
|
|
13
|
+
* `/v1/models` 就返回哪些;客户端选哪个模型由它自己决定,插件只负责照单发货。
|
|
14
|
+
* 见 src/catalog.js 与 src/resolve.js。
|
|
15
|
+
* (跟随 DSH 默认 / 跟随活跃会话 / 固定模型 / 固定账号 / 目录第一个),在
|
|
16
|
+
* 设置 → WorkBuddy Gateway 里管理。请求体不写 `model` 时就用这把 key 的策略。
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { registerRoutes, baseUrlOf } from './src/routes.js'
|
|
20
|
+
import { workbuddyProviders } from './src/backend.js'
|
|
21
|
+
import { closeDirect } from './src/direct.js'
|
|
22
|
+
import { readConfig, writeConfig, makeKey, normalizeSelections, configPath, useDataDir } from './src/config.js'
|
|
23
|
+
import { catalogForSettings } from './src/models.js'
|
|
24
|
+
|
|
25
|
+
export const name = 'workbuddy-gateway'
|
|
26
|
+
|
|
27
|
+
/** 必须先有 webServer 才能挂路由;llm 由 workbuddy 插件提供,按需读取。 */
|
|
28
|
+
export const inject = ['webServer']
|
|
29
|
+
|
|
30
|
+
const DEFAULTS = {
|
|
31
|
+
/**
|
|
32
|
+
* 配置目录。
|
|
33
|
+
*
|
|
34
|
+
* 空字符串表示「用默认」——`$DSH_HOME/dsh-connect-workbuddy-gateway/`,目录名与
|
|
35
|
+
* 包名一致,用户找得到。相对路径相对 `$DSH_HOME`,绝对路径原样使用。
|
|
36
|
+
*
|
|
37
|
+
* `keys.json` 落在这个目录里。改它会换一个数据文件——**旧目录里的 key 不会跟
|
|
38
|
+
* 过来**,所以设置页在保存后会把这件事说清楚。
|
|
39
|
+
*/
|
|
40
|
+
dataDir: '',
|
|
41
|
+
/** 关闭国际版区域(只服务国内区)。 */
|
|
42
|
+
enableGlobal: true,
|
|
43
|
+
/**
|
|
44
|
+
* 模型目录里是否把「接受图片」标为支持。
|
|
45
|
+
*
|
|
46
|
+
* 客户端会把这个标记填进它自己的表单。WorkBuddy 上游的图片能力按模型区分,
|
|
47
|
+
* 但目录接口不逐个声明,所以这里给一个总开关:默认 `true`(多数模型确实能
|
|
48
|
+
* 看图),遇到纯文本模型时用户可以在客户端里自己取消勾选。
|
|
49
|
+
*/
|
|
50
|
+
images: true,
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 插件入口。
|
|
55
|
+
* @param ctx Cordis 上下文
|
|
56
|
+
* @param config 行配置
|
|
57
|
+
*/
|
|
58
|
+
export function apply(ctx, config) {
|
|
59
|
+
const settings = { ...DEFAULTS, ...(config ?? {}) }
|
|
60
|
+
|
|
61
|
+
/*
|
|
62
|
+
* **第一件事:定下数据目录。** 后面所有 readConfig / writeConfig 都用它。
|
|
63
|
+
* 必须在建默认 key 之前,否则会先往默认目录写一份、再切到用户指定的目录,
|
|
64
|
+
* 用户看到的就是「设了目录但里面是空的」。
|
|
65
|
+
*/
|
|
66
|
+
const dataDir = useDataDir(settings.dataDir)
|
|
67
|
+
settings.resolvedDataDir = dataDir
|
|
68
|
+
|
|
69
|
+
/*
|
|
70
|
+
* 首次启动建一把默认 key,并**把所有可见模型都勾上** —— 用户拿到的 key 立刻
|
|
71
|
+
* 能用,不必先去勾选。只在 key 表为空时做,所以手动删光 key 之后重启会重新给
|
|
72
|
+
* 一把,那正是「我不小心删没了」的恢复路径。
|
|
73
|
+
*
|
|
74
|
+
* 勾选清单要等 provider 注册完才能读,所以放到异步里,失败只记一条日志。
|
|
75
|
+
*/
|
|
76
|
+
try {
|
|
77
|
+
const stored = readConfig()
|
|
78
|
+
if (stored.keys.length === 0) {
|
|
79
|
+
writeConfig({ ...stored, keys: [makeKey({ label: 'default' })] })
|
|
80
|
+
ctx.logger.info(`workbuddy-gateway: created the first API key in ${configPath()}`)
|
|
81
|
+
}
|
|
82
|
+
} catch (error) {
|
|
83
|
+
ctx.logger.warn(`workbuddy-gateway: could not prepare the key file: ${error instanceof Error ? error.message : String(error)}`)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const env = {
|
|
87
|
+
ctx,
|
|
88
|
+
config: settings,
|
|
89
|
+
logger: ctx.logger,
|
|
90
|
+
/*
|
|
91
|
+
* 本插件在 profile 里的 Loader 条目 id。
|
|
92
|
+
*
|
|
93
|
+
* 设置页要保存 `dataDir` 时,`settings.update(ns, ...)` 用的就是这个 id ——
|
|
94
|
+
* 宿主按**精确匹配**查表(`include:workbuddy-gateway` 这种,不是包名)。
|
|
95
|
+
* 取不到时留空,让保存路径老实报错,而不是写到别的条目上。
|
|
96
|
+
*/
|
|
97
|
+
entryId: ctx.fiber?.entry?.options?.id ?? '',
|
|
98
|
+
/*
|
|
99
|
+
* provider 路由每次请求现读:用户可能在设置里关掉一个区域,或让
|
|
100
|
+
* dsh-connect-workbuddy 重新注册(HMR)。采样一次会把「刚启用」的区域
|
|
101
|
+
* 一直当不存在。
|
|
102
|
+
*/
|
|
103
|
+
providers: () => workbuddyProviders(ctx, []),
|
|
104
|
+
/* 路由层在读到空清单时调它,见 {@link ensureSeeded}。 */
|
|
105
|
+
ensureSeeded: () => ensureSeeded(env),
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/*
|
|
109
|
+
* 首次启动建一把默认 key。**勾选清单不在这里补** —— 建 key 时 provider 往往
|
|
110
|
+
* 还没注册完,此处去读目录只能拿到空表。真正补选的时机是「第一次有人读它」:
|
|
111
|
+
* `/state` 与 `/v1/models` 都会在拿到清单为空时调 {@link ensureSeeded},那时
|
|
112
|
+
* provider 一定已经就绪。
|
|
113
|
+
*/
|
|
114
|
+
try {
|
|
115
|
+
const stored = readConfig()
|
|
116
|
+
if (stored.keys.length === 0) {
|
|
117
|
+
writeConfig({ ...stored, keys: [makeKey({ label: 'default' })] })
|
|
118
|
+
ctx.logger.info(`workbuddy-gateway: created the first API key in ${configPath()}`)
|
|
119
|
+
}
|
|
120
|
+
} catch (error) {
|
|
121
|
+
ctx.logger.warn(`workbuddy-gateway: could not prepare the key file: ${error instanceof Error ? error.message : String(error)}`)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
ctx.effect(() => {
|
|
125
|
+
const dispose = registerRoutes(ctx, env)
|
|
126
|
+
ctx.logger.info(`workbuddy-gateway: serving ${baseUrlOf(ctx)}`)
|
|
127
|
+
return () => {
|
|
128
|
+
dispose()
|
|
129
|
+
void closeDirect()
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* 惰性补选:某把 key 的清单为空、而本机确实有可用模型时,把它填满。
|
|
136
|
+
*
|
|
137
|
+
* 只在「从未补过 且 清单为空」时动手,所以用户主动清空的意图不会被覆盖(他清空
|
|
138
|
+
* 之后要么立刻再勾,要么就是想让这把 key 停用)。为了区分「刚建好还没勾」与
|
|
139
|
+
* 「用户故意清空」,落盘时给补过的 key 打 `seeded` 标记。
|
|
140
|
+
*
|
|
141
|
+
* @returns 是否写入了配置
|
|
142
|
+
*/
|
|
143
|
+
export async function ensureSeeded(env) {
|
|
144
|
+
const config = readConfig()
|
|
145
|
+
const target = config.keys.find((entry) => entry.seeded !== true && (entry.selections ?? []).length === 0)
|
|
146
|
+
if (target === undefined) return false
|
|
147
|
+
if (env.providers().length === 0) return false
|
|
148
|
+
let available
|
|
149
|
+
try {
|
|
150
|
+
available = await catalogForSettings(env)
|
|
151
|
+
} catch {
|
|
152
|
+
return false
|
|
153
|
+
}
|
|
154
|
+
if (available.length === 0) return false
|
|
155
|
+
target.selections = normalizeSelections(available)
|
|
156
|
+
target.seeded = true
|
|
157
|
+
writeConfig(config)
|
|
158
|
+
env.logger.info(`workbuddy-gateway: pre-selected ${String(target.selections.length)} models on key "${target.label || target.id}"`)
|
|
159
|
+
return true
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export { baseUrlOf }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-connect-workbuddy-gateway",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "把 dsh-connect-workbuddy 的 WorkBuddy 模型开放成本机 API:OpenAI Chat / Responses、Anthropic Messages、Gemini 四协议共用一个 base URL,模型按 API key 逐个勾选。",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh-plugin",
|
|
@@ -48,7 +48,6 @@
|
|
|
48
48
|
"src",
|
|
49
49
|
"cordis.patch.yml",
|
|
50
50
|
"locale",
|
|
51
|
-
"docs",
|
|
52
51
|
"icon.svg",
|
|
53
52
|
"README.md",
|
|
54
53
|
"LICENSE"
|
package/src/config.js
CHANGED
|
@@ -34,15 +34,91 @@
|
|
|
34
34
|
import { randomBytes } from 'node:crypto'
|
|
35
35
|
import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs'
|
|
36
36
|
import { homedir } from 'node:os'
|
|
37
|
-
import { dirname, join } from 'node:path'
|
|
37
|
+
import { dirname, join, resolve } from 'node:path'
|
|
38
38
|
|
|
39
39
|
export const CONFIG_VERSION = 2
|
|
40
40
|
|
|
41
|
+
/**
|
|
42
|
+
* 默认数据目录名 —— 与仓库/包名一致。
|
|
43
|
+
*
|
|
44
|
+
* 用户看得懂「dsh-connect-workbuddy-gateway 这个插件的数据在哪个目录」,
|
|
45
|
+
* 而 `workbuddy-gateway` 这种简称会让人找不到。
|
|
46
|
+
*/
|
|
47
|
+
export const DEFAULT_DATA_DIR_NAME = 'dsh-connect-workbuddy-gateway'
|
|
48
|
+
|
|
49
|
+
/** DSH 主目录。 */
|
|
50
|
+
export function dshHome() {
|
|
51
|
+
const home = process.env.DSH_HOME
|
|
52
|
+
return typeof home === 'string' && home.trim() !== '' ? home.trim() : join(homedir(), '.dsh')
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 把配置项里的 `dataDir` 解析成绝对目录。
|
|
57
|
+
*
|
|
58
|
+
* 三种写法:
|
|
59
|
+
* - 绝对路径(`D:\my-keys` 或 `/opt/keys`)→ 原样使用
|
|
60
|
+
* - 相对路径(`my-keys`)→ 相对 DSH 主目录
|
|
61
|
+
* - 空/未设 → `$DSH_HOME/dsh-connect-workbuddy-gateway`
|
|
62
|
+
*
|
|
63
|
+
* @param configured 插件配置里的 `dataDir`
|
|
64
|
+
*/
|
|
65
|
+
export function resolveDataDir(configured) {
|
|
66
|
+
const raw = typeof configured === 'string' ? configured.trim() : ''
|
|
67
|
+
|
|
68
|
+
if (raw !== '') {
|
|
69
|
+
/*
|
|
70
|
+
* 相对路径相对 DSH 主目录 —— 而不是进程 cwd。
|
|
71
|
+
* cwd 因启动方式而变,靠它拼路径会让「同一个配置在不同启动下指向不同文件」。
|
|
72
|
+
*/
|
|
73
|
+
return isAbsolutePath(raw) ? resolve(raw) : join(dshHome(), raw)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return join(dshHome(), DEFAULT_DATA_DIR_NAME)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** 跨平台的绝对路径判断(Windows 盘符 + UNC + POSIX 根)。 */
|
|
80
|
+
function isAbsolutePath(value) {
|
|
81
|
+
return /^[A-Za-z]:[\\/]/u.test(value) || value.startsWith('\\\\') || value.startsWith('/')
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* 当前生效的数据目录。
|
|
86
|
+
*
|
|
87
|
+
* 由插件入口在 `apply` 里调 {@link useDataDir} 设一次,之后所有读写都用它。
|
|
88
|
+
*
|
|
89
|
+
* 为什么用模块级状态而不是给每个函数加参数:`readConfig` / `writeConfig` 在路由
|
|
90
|
+
* 层有近二十个调用点,逐个传参既啰嗦又容易漏一个——漏掉的那个会对**另一个目录**
|
|
91
|
+
* 读写,症状是「某个按钮存的东西消失了」。目录在插件生命周期内是固定的(改它要
|
|
92
|
+
* 重启插件),所以在这里存一份是安全的。
|
|
93
|
+
*/
|
|
94
|
+
let activeDataDir
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 设定本插件使用的数据目录。由 `apply` 调一次。
|
|
98
|
+
* @param configured 插件配置里的 `dataDir`(空表示用默认)
|
|
99
|
+
* @returns 解析后的绝对目录
|
|
100
|
+
*/
|
|
101
|
+
export function useDataDir(configured) {
|
|
102
|
+
activeDataDir = resolveDataDir(configured)
|
|
103
|
+
return activeDataDir
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** 读出当前生效的目录(未设置时按默认解析)。 */
|
|
107
|
+
export function activeDataDirPath() {
|
|
108
|
+
return activeDataDir ?? resolveDataDir(undefined)
|
|
109
|
+
}
|
|
110
|
+
|
|
41
111
|
/** 数据文件路径。 */
|
|
42
112
|
export function configPath() {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
113
|
+
return join(activeDataDirPath(), 'keys.json')
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 路径是否是「跟随默认」而不是用户显式设的。
|
|
118
|
+
* 设置页据此显示「默认(DEFAULT_DATA_DIR_NAME)」而不是把一长串路径当用户输入。
|
|
119
|
+
*/
|
|
120
|
+
export function isDefaultDataDir(configured) {
|
|
121
|
+
return typeof configured !== 'string' || configured.trim() === ''
|
|
46
122
|
}
|
|
47
123
|
|
|
48
124
|
/** 空配置。 */
|
package/src/routes.js
CHANGED
|
@@ -20,7 +20,19 @@ import { handleResponses } from './openai-responses.js'
|
|
|
20
20
|
import { handleMessages } from './anthropic.js'
|
|
21
21
|
import { handleGenerate, parseGeminiPath, geminiCatalog } from './gemini.js'
|
|
22
22
|
import { collectModels, directModelsByRegion, openAiCatalog, anthropicCatalog, catalogForSettings } from './models.js'
|
|
23
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
readConfig,
|
|
25
|
+
writeConfig,
|
|
26
|
+
makeKey,
|
|
27
|
+
normalizeSelections,
|
|
28
|
+
normalizeConfig,
|
|
29
|
+
newSecret,
|
|
30
|
+
maskSecret,
|
|
31
|
+
configPath,
|
|
32
|
+
activeDataDirPath,
|
|
33
|
+
isDefaultDataDir,
|
|
34
|
+
DEFAULT_DATA_DIR_NAME,
|
|
35
|
+
} from './config.js'
|
|
24
36
|
import { buildCatalog, safeSuffixOf } from './catalog.js'
|
|
25
37
|
import { allAccounts } from './accounts.js'
|
|
26
38
|
import { regionOfProvider, providerOfRegion } from './resolve.js'
|
|
@@ -310,6 +322,94 @@ async function dispatchAdmin(req, res, ctx, env) {
|
|
|
310
322
|
sendJson(res, 200, { keys: publicKeys(config, env), secret: target.secret })
|
|
311
323
|
return
|
|
312
324
|
}
|
|
325
|
+
if (method === 'POST' && path === '/config/data-dir') {
|
|
326
|
+
/*
|
|
327
|
+
* 改配置目录。
|
|
328
|
+
*
|
|
329
|
+
* **不能只写进 keys.json** —— 那个文件就在被指向的目录里,改它等于让一个新
|
|
330
|
+
* 文件去描述「以后该读哪个文件」,自相矛盾。所以这项写进插件配置
|
|
331
|
+
* (`cordis.patch.yml` 的那一行),由 settings 服务落盘,插件下次激活时
|
|
332
|
+
* `apply` 读到的就是新值。
|
|
333
|
+
*
|
|
334
|
+
* 这里只做校验与说明,真正的写入交给宿主。
|
|
335
|
+
*/
|
|
336
|
+
const body = await readJsonBody(req)
|
|
337
|
+
const requested = typeof body?.dataDir === 'string' ? body.dataDir.trim() : ''
|
|
338
|
+
|
|
339
|
+
/* 相对路径要能被解析成绝对路径,否则运行时会拼出一个诡异位置。 */
|
|
340
|
+
if (requested !== '' && !isResolvablePath(requested)) {
|
|
341
|
+
sendJson(res, 400, { error: `"${requested}" is not a usable directory path` })
|
|
342
|
+
return
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
const settings = ctx.get('settings')
|
|
346
|
+
if (settings === undefined) {
|
|
347
|
+
sendJson(res, 503, { error: 'this profile cannot save plugin configuration' })
|
|
348
|
+
return
|
|
349
|
+
}
|
|
350
|
+
/*
|
|
351
|
+
* 找到能落盘这条配置的地方。
|
|
352
|
+
*
|
|
353
|
+
* 两条路都试,顺序有讲究:
|
|
354
|
+
*
|
|
355
|
+
* 1. `configEditor.edit(entry, ...)` —— 本插件最该用的那条。它认得这一行,
|
|
356
|
+
* 保留 patch 里其它内容与注释,并且会重启插件让改动生效。
|
|
357
|
+
* 2. `settings.update(ns, ...)` —— 只在插件注册了设置页时可用。本插件
|
|
358
|
+
* **没有**注册(`describe()` 里找不到它),所以这条基本走不通,保留是为了
|
|
359
|
+
* 将来加了设置页时自动能用上。
|
|
360
|
+
*
|
|
361
|
+
* 都不行就如实报错,让用户去改 patch —— 绝不自己去重写 cordis.patch.yml,
|
|
362
|
+
* 那个文件属于用户,里面有别人的行和注释。
|
|
363
|
+
*/
|
|
364
|
+
const ownEntry = ctx.fiber?.entry
|
|
365
|
+
const editor = ctx.get('configEditor')
|
|
366
|
+
if (ownEntry !== undefined && editor?.edit !== undefined) {
|
|
367
|
+
try {
|
|
368
|
+
await editor.edit(ownEntry, (current) => ({ ...current, dataDir: requested }))
|
|
369
|
+
sendJson(res, 200, { ok: true, requested, via: 'configEditor' })
|
|
370
|
+
return
|
|
371
|
+
} catch (error) {
|
|
372
|
+
sendJson(res, 500, {
|
|
373
|
+
error: `could not save dataDir: ${error instanceof Error ? error.message : String(error)}`,
|
|
374
|
+
via: 'configEditor',
|
|
375
|
+
})
|
|
376
|
+
return
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const configService = ctx.get('settings')
|
|
381
|
+
if (configService === undefined) {
|
|
382
|
+
sendJson(res, 503, { error: 'this profile cannot save plugin configuration; set dataDir in the profile patch instead' })
|
|
383
|
+
return
|
|
384
|
+
}
|
|
385
|
+
const ns = resolveSettingsNs(configService, env, PACKAGE_NAME)
|
|
386
|
+
if (ns === undefined) {
|
|
387
|
+
sendJson(res, 503, {
|
|
388
|
+
error: 'this plugin is not registered as a configurable entry in this profile; set dataDir in the profile patch by hand',
|
|
389
|
+
entryId: env.entryId ?? null,
|
|
390
|
+
})
|
|
391
|
+
return
|
|
392
|
+
}
|
|
393
|
+
try {
|
|
394
|
+
await configService.update(ns, { dataDir: requested })
|
|
395
|
+
} catch (error) {
|
|
396
|
+
sendJson(res, 500, { error: `could not save: ${error instanceof Error ? error.message : String(error)}` })
|
|
397
|
+
return
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/*
|
|
401
|
+
* 如实告诉用户发生了什么:新目录**不会**自动继承旧 key。与其让他下次打开
|
|
402
|
+
* 设置页发现 key 全空,不如现在就说。
|
|
403
|
+
*/
|
|
404
|
+
const nextDir = requested === '' ? null : requested
|
|
405
|
+
sendJson(res, 200, {
|
|
406
|
+
ok: true,
|
|
407
|
+
requested,
|
|
408
|
+
note: 'the plugin reloads to apply this; keys in the previous directory are not copied over',
|
|
409
|
+
...(nextDir === null ? {} : { pendingDataDir: nextDir }),
|
|
410
|
+
})
|
|
411
|
+
return
|
|
412
|
+
}
|
|
313
413
|
if (method === 'POST' && path === '/config/reset') {
|
|
314
414
|
const config = readConfig()
|
|
315
415
|
if (config.keys.length === 0) {
|
|
@@ -367,7 +467,7 @@ async function adminState(ctx, env) {
|
|
|
367
467
|
/* 根地址就是 DSH 自己的地址,不带自定义前缀。 */
|
|
368
468
|
baseUrl: origin,
|
|
369
469
|
endpoints: describeEndpoints(origin).endpoints,
|
|
370
|
-
|
|
470
|
+
paths: configPathOf(env),
|
|
371
471
|
providers: env.providers().map((provider) => ({
|
|
372
472
|
id: provider,
|
|
373
473
|
region: regionOfProvider(provider) ?? null,
|
|
@@ -552,10 +652,76 @@ export function baseUrlOf(ctx) {
|
|
|
552
652
|
return `${originOf(ctx)}${PREFIX}`
|
|
553
653
|
}
|
|
554
654
|
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
655
|
+
/**
|
|
656
|
+
* 设置页展示用的路径信息。
|
|
657
|
+
*
|
|
658
|
+
* 同时给出三样东西,因为用户问的是不同的问题:
|
|
659
|
+
* - `configPath`:实际读写的那个文件(最长的那串)
|
|
660
|
+
* - `dataDir`:它所在的目录(可自定义的那一项)
|
|
661
|
+
* - `dataDirIsDefault`:这个目录是不是「跟随默认」——是的话界面显示默认名,
|
|
662
|
+
* 而不是把一长串绝对路径当成用户输入回填到输入框里
|
|
663
|
+
*/
|
|
664
|
+
function configPathOf(env) {
|
|
665
|
+
return {
|
|
666
|
+
configPath: configPath(),
|
|
667
|
+
dataDir: activeDataDirPath(),
|
|
668
|
+
dataDirIsDefault: isDefaultDataDir(env?.config?.dataDir),
|
|
669
|
+
defaultDataDirName: DEFAULT_DATA_DIR_NAME,
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
/**
|
|
674
|
+
* 定位本插件在 settings 服务里的命名空间。
|
|
675
|
+
*
|
|
676
|
+
* 候选顺序:env 里读到的条目 id → 该 id 加 `include:` 前缀 → 按包名在
|
|
677
|
+
* describe() 里反查。**每个候选都要在 describe() 的输出里真实存在才采用** ——
|
|
678
|
+
* `settings.update` 对不存在的 ns 会抛错,而写错条目比报错更糟。
|
|
679
|
+
*
|
|
680
|
+
* @returns 可用的 ns,或 undefined
|
|
681
|
+
*/
|
|
682
|
+
function resolveSettingsNs(settings, env, packageName) {
|
|
683
|
+
let descriptors
|
|
684
|
+
try {
|
|
685
|
+
descriptors = settings.describe?.() ?? []
|
|
686
|
+
} catch {
|
|
687
|
+
return undefined
|
|
688
|
+
}
|
|
689
|
+
const known = new Set(
|
|
690
|
+
(Array.isArray(descriptors) ? descriptors : [])
|
|
691
|
+
.map((descriptor) => descriptor?.ns)
|
|
692
|
+
.filter((ns) => typeof ns === 'string'),
|
|
693
|
+
)
|
|
694
|
+
if (known.size === 0) return undefined
|
|
695
|
+
|
|
696
|
+
const candidates = []
|
|
697
|
+
if (typeof env?.entryId === 'string' && env.entryId !== '') {
|
|
698
|
+
candidates.push(env.entryId)
|
|
699
|
+
candidates.push(`include:${env.entryId}`)
|
|
700
|
+
}
|
|
701
|
+
/* 按包名/条目名反查:`include:dsh-connect-workbuddy-gateway` 这类。 */
|
|
702
|
+
for (const ns of known) {
|
|
703
|
+
if (ns === packageName || ns.includes(packageName)) candidates.push(ns)
|
|
704
|
+
}
|
|
705
|
+
/* 最后按本插件条目 id 的常见拼法兜底。 */
|
|
706
|
+
for (const ns of known) {
|
|
707
|
+
if (/workbuddy-gateway/u.test(ns)) candidates.push(ns)
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
for (const candidate of candidates) {
|
|
711
|
+
if (known.has(candidate)) return candidate
|
|
712
|
+
}
|
|
713
|
+
return undefined
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
/** 本插件的包名,用于在 settings 目录里认出自己那一行。 */
|
|
717
|
+
const PACKAGE_NAME = 'dsh-connect-workbuddy-gateway'
|
|
718
|
+
|
|
719
|
+
/** 跨平台的「这是个可用路径」判断(不含盘符以外的怪字符)。 */
|
|
720
|
+
function isResolvablePath(value) {
|
|
721
|
+
if (value === '') return false
|
|
722
|
+
/* Windows 不允许这些字符出现在路径里;POSIX 只禁 NUL。 */
|
|
723
|
+
if (/[\u0000<>"|?*]/u.test(value)) return false
|
|
724
|
+
return true
|
|
559
725
|
}
|
|
560
726
|
|
|
561
727
|
function readJsonBody(req) {
|
package/docs/RELEASE-TODO.md
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
# npm 首次发布:待办清单
|
|
2
|
-
|
|
3
|
-
本文件记录「发布 1.0.0」这件事的当前状态与剩余步骤。完成后可删除。
|
|
4
|
-
|
|
5
|
-
## 为什么卡住了
|
|
6
|
-
|
|
7
|
-
为了把首次公开版本从 `2.1.0` 对齐到 `1.0.0`,整包被删除。npm 对整包删除有 **24 小时
|
|
8
|
-
重发冷却**:
|
|
9
|
-
|
|
10
|
-
```
|
|
11
|
-
删除时间(UTC): 2026-11-23 17:49:35
|
|
12
|
-
可重发(UTC): 2026-11-24 17:49:35
|
|
13
|
-
可重发(北京): 2026-11-25 01:49:35
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
## 副作用:OIDC 配置没了
|
|
17
|
-
|
|
18
|
-
Trusted Publisher 是挂在包上的元数据,整包删除后一起消失(访问 access 页返回 404)。
|
|
19
|
-
所以重发之后需要**重新配置一次**,否则 GitHub Actions 无法发布。
|
|
20
|
-
|
|
21
|
-
## 恢复步骤(按顺序)
|
|
22
|
-
|
|
23
|
-
### 1. 确认可重发
|
|
24
|
-
|
|
25
|
-
```bash
|
|
26
|
-
npm view dsh-connect-workbuddy-gateway --registry=https://registry.npmjs.org/
|
|
27
|
-
# 不再是 E404 "Unpublished on ..." 即可
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
### 2. 本地发布 1.0.0
|
|
31
|
-
|
|
32
|
-
```bash
|
|
33
|
-
cd <repo>
|
|
34
|
-
node tests/harness.mjs # 应全绿(165 项)
|
|
35
|
-
npm pack --dry-run # 应 32 files / ~75 kB
|
|
36
|
-
npm publish --registry=https://registry.npmjs.org/ --access public
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
凭据:本机已有 granular token(带 publish 权限、绕过 2FA)。若已失效,重新 `npm login`
|
|
40
|
-
或在 npm 网页生成新 token 后 `npm config set //registry.npmjs.org/:_authToken <token>`。
|
|
41
|
-
|
|
42
|
-
### 3. 重新配置 Trusted Publisher
|
|
43
|
-
|
|
44
|
-
浏览器打开:
|
|
45
|
-
|
|
46
|
-
```
|
|
47
|
-
https://www.npmjs.com/package/dsh-connect-workbuddy-gateway/access
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
Trusted Publisher → GitHub Actions,填:
|
|
51
|
-
|
|
52
|
-
| 字段 | 值 |
|
|
53
|
-
|---|---|
|
|
54
|
-
| Organization | `Roozenlz` |
|
|
55
|
-
| Repository | `dsh-connect-workbuddy-gateway` |
|
|
56
|
-
| Workflow name | `publish.yml` |
|
|
57
|
-
| Environment | 留空 |
|
|
58
|
-
|
|
59
|
-
勾选 `npm publish` 权限,点 **Set up connection**,用安全密钥完成 2FA。
|
|
60
|
-
|
|
61
|
-
> 这一步必须人工做:绕过 2FA 的 token 被 npm 禁止执行账号变更类操作
|
|
62
|
-
> (`npm trust`、`npm unpublish` 都会 403)。
|
|
63
|
-
|
|
64
|
-
配好后状态是 **Pending validation**,需要再发布一次才算生效。
|
|
65
|
-
|
|
66
|
-
### 4. 打 tag 验证 OIDC 链路
|
|
67
|
-
|
|
68
|
-
```bash
|
|
69
|
-
git tag v1.0.0
|
|
70
|
-
git push origin v1.0.0
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
工作流会:校验 tag == package.json 版本 → 跑测试 → 用 OIDC 发布。因为 1.0.0 已经
|
|
74
|
-
被第 2 步发过,这次会因「版本已存在」失败——这是**预期**的,只用来确认 OIDC 握手
|
|
75
|
-
成功(日志里能看到它拿到了凭据,而不是报 401/403)。
|
|
76
|
-
|
|
77
|
-
要真正验证「CI 能发布」,需要下一个版本:把 `package.json` 改成 `1.0.1`,
|
|
78
|
-
提交后推 `v1.0.1`。
|
|
79
|
-
|
|
80
|
-
### 5. 更新 README
|
|
81
|
-
|
|
82
|
-
- 把「C. 从 npm」那段 ⚠️ 警告去掉,改成可用
|
|
83
|
-
- 确认徽章、仓库链接正确
|
|
84
|
-
|
|
85
|
-
## 另需清理
|
|
86
|
-
|
|
87
|
-
```bash
|
|
88
|
-
git stash drop # 清掉一条纯行尾噪音的 stash(内容与 HEAD 一致)
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
以及本地临时文件:`D:\dsh-workspace\.ego-npm\`(浏览器脚本)、
|
|
92
|
-
`D:\dsh-workspace\.npm-login.log`。
|