dsh-connect-godagent 0.1.0 → 0.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 +7 -1
- package/lib/client.js +99 -75
- package/package.json +2 -4
package/README.md
CHANGED
|
@@ -95,7 +95,13 @@ Config 的整个 namespace 会从 `settings.describe()` 消失(表现为"等
|
|
|
95
95
|
|
|
96
96
|
## 在 DSH 中安装(一句话)
|
|
97
97
|
|
|
98
|
-
|
|
98
|
+
**npm 包(推荐)**——预构建产物,一条命令、无需 allowBuilds 授权:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
dsh plugin --profile web add dsh-connect-godagent
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
也可以对 DSH 助手说这一句,让它代劳:
|
|
99
105
|
|
|
100
106
|
> 安装 dsh-connect-godagent 插件,仓库地址 https://github.com/atorber/dsh-connect-godagent
|
|
101
107
|
|
package/lib/client.js
CHANGED
|
@@ -98,50 +98,71 @@ window.__ModuleLoader__.load({
|
|
|
98
98
|
//#endregion
|
|
99
99
|
|
|
100
100
|
//#region 设置卡片
|
|
101
|
-
/** 与 workbuddy 的 WorkBuddyCard 相同的 props 约定:inject 返回 {
|
|
102
|
-
function GodAgentSettingsCard({ settingsScope,
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
|
|
101
|
+
/** 与 workbuddy 的 WorkBuddyCard 相同的 props 约定:inject 返回 { settingsScope, settingsMirror, surface }。 */
|
|
102
|
+
function GodAgentSettingsCard({ settingsScope, settingsMirror }) {
|
|
103
|
+
// 订阅 ConfigFormController 快照:不要只调 setDraft(undefined)——draft 本就是 undefined 时
|
|
104
|
+
// React 会 bailout 不重渲染,导致 loading → ready 转换永远卡在等待文案。
|
|
105
|
+
const [snapshot, setSnapshot] = useState(() => settingsScope?.getSnapshot?.());
|
|
106
|
+
const [mirrorSnap, setMirrorSnap] = useState(() => settingsMirror?.getSnapshot?.());
|
|
107
107
|
/** 本地草稿:undefined = 未编辑(跟随服务端值)。字段级编辑后切到草稿值。 */
|
|
108
108
|
const [draft, setDraft] = useState(undefined);
|
|
109
109
|
const [groups, setGroups] = useState(undefined); // undefined=加载中, []=失败/空
|
|
110
110
|
const [groupError, setGroupError] = useState('');
|
|
111
111
|
const [busy, setBusy] = useState(false);
|
|
112
|
-
|
|
113
|
-
* 等待超过 12s 进入 slow 分支。describe mirror 首拉失败后不会自动重试
|
|
114
|
-
* (status 停在 idle,直到下次 settings 写入触发 settings/document-updated
|
|
115
|
-
* 或 WS 重连才重拉),所以 slow 后做一次"同值写回"自愈:
|
|
116
|
-
* describe → 用原值 mutate 一次 → 宿主广播 document-updated → mirror 重拉 →
|
|
117
|
-
* whileServed 边沿触发 → 表单无需刷新即渲染(2026-11-24 实机验证有效)。
|
|
118
|
-
* 自愈过一次仍不 ready 则只给手动重试按钮,避免循环写。
|
|
119
|
-
*/
|
|
112
|
+
const [retrying, setRetrying] = useState(false);
|
|
120
113
|
const [slow, setSlow] = useState(false);
|
|
121
|
-
const [
|
|
122
|
-
const
|
|
114
|
+
const [note, setNote] = useState(''); // 保存结果 { ok, text }
|
|
115
|
+
const [hoverRow, setHoverRow] = useState('');
|
|
116
|
+
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
setSnapshot(settingsScope?.getSnapshot?.());
|
|
119
|
+
return settingsScope?.subscribe?.(() => {
|
|
120
|
+
setSnapshot(settingsScope.getSnapshot());
|
|
121
|
+
setDraft(undefined);
|
|
122
|
+
});
|
|
123
|
+
}, [settingsScope]);
|
|
124
|
+
|
|
125
|
+
useEffect(() => {
|
|
126
|
+
setMirrorSnap(settingsMirror?.getSnapshot?.());
|
|
127
|
+
return settingsMirror?.subscribe?.(() => {
|
|
128
|
+
setMirrorSnap(settingsMirror.getSnapshot());
|
|
129
|
+
});
|
|
130
|
+
}, [settingsMirror]);
|
|
131
|
+
|
|
132
|
+
const ready = snapshot?.status === 'ready' && snapshot.value && typeof snapshot.value === 'object';
|
|
133
|
+
const server = ready ? snapshot.value : {};
|
|
134
|
+
|
|
135
|
+
// describe mirror 首拉失败后会退回 idle(保留 error),ensure() 会重新发起 settings.describe()。
|
|
136
|
+
// 未 ready 时按 1.5s / 4s / 8s 做轻量重试,超过 10s 进入 slow 展示手动重试按钮与真实错误信息。
|
|
137
|
+
const retryDescribe = useCallback(() => {
|
|
138
|
+
if (!settingsMirror?.ensure) {
|
|
139
|
+
if (typeof window !== 'undefined' && window.location?.reload) window.location.reload();
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
setRetrying(true);
|
|
143
|
+
Promise.resolve()
|
|
144
|
+
.then(() => settingsMirror.ensure())
|
|
145
|
+
.catch((error) => console.warn('[dsh-connect-godagent] settings.describe 重试失败:', error))
|
|
146
|
+
.finally(() => setRetrying(false));
|
|
147
|
+
}, [settingsMirror]);
|
|
148
|
+
|
|
123
149
|
useEffect(() => {
|
|
124
150
|
if (ready) {
|
|
125
|
-
setSlow(false);
|
|
151
|
+
setSlow(false);
|
|
152
|
+
setRetrying(false);
|
|
126
153
|
return undefined;
|
|
127
154
|
}
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
}, [ready]);
|
|
140
|
-
const [note, setNote] = useState(''); // 保存结果 { ok, text }
|
|
141
|
-
const [hoverRow, setHoverRow] = useState('');
|
|
142
|
-
|
|
143
|
-
// 服务端值变化(保存回包 / 其他端修改)时丢弃草稿,回到权威值。
|
|
144
|
-
useEffect(() => settingsScope?.subscribe?.(() => setDraft(undefined)), [settingsScope]);
|
|
155
|
+
const timers = [1500, 4000, 8000].map((delay) => setTimeout(() => {
|
|
156
|
+
if (settingsMirror?.getSnapshot?.()?.status === 'idle') {
|
|
157
|
+
Promise.resolve().then(() => settingsMirror.ensure?.()).catch(() => {});
|
|
158
|
+
}
|
|
159
|
+
}, delay));
|
|
160
|
+
const slowTimer = setTimeout(() => setSlow(true), 10000);
|
|
161
|
+
return () => {
|
|
162
|
+
for (const id of timers) clearTimeout(id);
|
|
163
|
+
clearTimeout(slowTimer);
|
|
164
|
+
};
|
|
165
|
+
}, [ready, settingsMirror]);
|
|
145
166
|
|
|
146
167
|
useEffect(() => {
|
|
147
168
|
let alive = true;
|
|
@@ -171,14 +192,22 @@ window.__ModuleLoader__.load({
|
|
|
171
192
|
const groups$1 = ['default', ...enabledGroups.filter((c) => c !== 'default')];
|
|
172
193
|
const fields = {
|
|
173
194
|
enabled: value.enabled !== false,
|
|
174
|
-
apiKey: String(next.apiKey ?? '').trim(),
|
|
175
195
|
enabledGroups: groups$1,
|
|
176
196
|
enabledModelIds: modelIds,
|
|
177
197
|
refreshMinutes: Math.max(5, Math.round(Number(next.refreshMinutes) || 30)),
|
|
178
198
|
};
|
|
199
|
+
// apiKey 标了 role('secret'),describe 会脱敏省略;仅在用户实际编辑过时才写回,避免误清空已有 key
|
|
200
|
+
if (draft && Object.prototype.hasOwnProperty.call(draft, 'apiKey')) {
|
|
201
|
+
fields.apiKey = String(next.apiKey ?? '').trim();
|
|
202
|
+
}
|
|
179
203
|
let ok = true;
|
|
180
|
-
|
|
181
|
-
|
|
204
|
+
if (typeof settingsScope.mutate === 'function') {
|
|
205
|
+
const ops = Object.entries(fields).map(([field, v]) => ({ op: 'set', path: [field], value: v }));
|
|
206
|
+
ok = Boolean(await settingsScope.mutate(ops));
|
|
207
|
+
} else {
|
|
208
|
+
for (const [field, v] of Object.entries(fields)) {
|
|
209
|
+
if (!(await settingsScope.set(field, v))) ok = false;
|
|
210
|
+
}
|
|
182
211
|
}
|
|
183
212
|
setNote(ok
|
|
184
213
|
? { ok: true, text: '已保存 · 模型目录正在按新配置重建(分组 key 首次启用时自动创建)' }
|
|
@@ -284,14 +313,14 @@ window.__ModuleLoader__.load({
|
|
|
284
313
|
!ready ? react.createElement('span', { style: S.status },
|
|
285
314
|
snapshot?.status === 'unavailable'
|
|
286
315
|
? '宿主未提供 God Agent 配置表单(硬刷新页面 / 重启 DSH 后重试)'
|
|
287
|
-
: (
|
|
288
|
-
?
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
slow && !
|
|
316
|
+
: (retrying
|
|
317
|
+
? '正在重新读取 God Agent 主配置...'
|
|
318
|
+
: (slow
|
|
319
|
+
? `等待God Agent主配置就绪...${mirrorSnap?.error ? `(${mirrorSnap.error})` : '(可点"重试",或硬刷新 Cmd+Shift+R)'}`
|
|
320
|
+
: '等待God Agent主配置就绪...'))) : null,
|
|
321
|
+
!ready && (slow || mirrorSnap?.error) && !retrying ? react.createElement('button', {
|
|
293
322
|
style: S.button,
|
|
294
|
-
onClick:
|
|
323
|
+
onClick: retryDescribe,
|
|
295
324
|
}, '重试') : null,
|
|
296
325
|
dirty && ready && !busy ? react.createElement('span', { style: S.status }, '有未保存的修改') : null,
|
|
297
326
|
note ? react.createElement('span', { style: { ...S.status, ...(note.ok ? {} : S.statusError) } }, note.text) : null,
|
|
@@ -318,32 +347,25 @@ window.__ModuleLoader__.load({
|
|
|
318
347
|
//#endregion
|
|
319
348
|
|
|
320
349
|
//#region 入口
|
|
321
|
-
|
|
350
|
+
// 必须声明 'configForms':与官方所有 settings 插件(settings-general / settings-models 等)一致。
|
|
351
|
+
// 不声明时 Cordis 可能在 @deepseek-ai/dsh-client-ui-settings 挂载 ConfigForms 之前执行 apply,
|
|
352
|
+
// 导致 ctx.get('configForms') 拿到 undefined,settingsScope 永久缺失。
|
|
353
|
+
const inject = ['slots', 'configForms'];
|
|
322
354
|
|
|
323
355
|
function apply(ctx) {
|
|
324
356
|
try {
|
|
325
|
-
const
|
|
357
|
+
const forms = ctx.configForms ?? ctx.get('configForms');
|
|
358
|
+
const settingsMirror = typeof forms?.describe === 'function' ? forms.describe() : undefined;
|
|
326
359
|
|
|
327
|
-
/**
|
|
328
|
-
|
|
360
|
+
/** 默认直接绑定 PLUGIN_ID 的 ConfigFormController,避免首次注册时传入 undefined;
|
|
361
|
+
* 若宿主以 include:dsh-connect-godagent 等别名提供,whileServed 会自动切换到真实 namespace。 */
|
|
362
|
+
let boundNs = PLUGIN_ID;
|
|
363
|
+
let settingsScope = typeof forms?.get === 'function' ? forms.get(PLUGIN_ID) : undefined;
|
|
329
364
|
let liveDisposers = [];
|
|
330
365
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
* describe → whileServed 边沿触发 → 表单无需刷新即渲染(2026-11-24 实机验证)。
|
|
335
|
-
*/
|
|
336
|
-
const healDescribe = async () => {
|
|
337
|
-
const remoteSettings = ctx.remote?.settings;
|
|
338
|
-
if (!remoteSettings?.describe || !remoteSettings?.mutate) throw new Error('remote.settings 不可用');
|
|
339
|
-
const described = await remoteSettings.describe();
|
|
340
|
-
const rows = described?.namespaces ?? described?.value?.namespaces ?? [];
|
|
341
|
-
const row = rows.find((entry) => entry?.ns === PLUGIN_ID)
|
|
342
|
-
?? rows.find((entry) => /godagent/i.test(String(entry?.ns ?? '')));
|
|
343
|
-
if (!row) throw new Error('describe 结果里没有本插件配置');
|
|
344
|
-
const current = row.value ?? {};
|
|
345
|
-
const ops = [{ op: 'set', path: ['refreshMinutes'], value: current.refreshMinutes ?? 30 }];
|
|
346
|
-
await remoteSettings.mutate(row.ns, ops, row.revision);
|
|
366
|
+
const disposeSlots = () => {
|
|
367
|
+
for (const dispose of liveDisposers) try { dispose(); } catch {}
|
|
368
|
+
liveDisposers = [];
|
|
347
369
|
};
|
|
348
370
|
|
|
349
371
|
const registerAllSlots = () => {
|
|
@@ -354,7 +376,7 @@ window.__ModuleLoader__.load({
|
|
|
354
376
|
id: PLUGIN_ID,
|
|
355
377
|
order: 36,
|
|
356
378
|
label: () => 'God Agent',
|
|
357
|
-
inject: () => ({ settingsScope, surface: 'settings'
|
|
379
|
+
inject: () => ({ settingsScope, settingsMirror, surface: 'settings' }),
|
|
358
380
|
}, GodAgentSettingsCard));
|
|
359
381
|
disposers.push(sectionInject);
|
|
360
382
|
} catch (error) {
|
|
@@ -373,25 +395,27 @@ window.__ModuleLoader__.load({
|
|
|
373
395
|
};
|
|
374
396
|
|
|
375
397
|
const rebindSlots = () => {
|
|
376
|
-
|
|
398
|
+
disposeSlots();
|
|
377
399
|
liveDisposers = registerAllSlots();
|
|
378
400
|
};
|
|
379
401
|
|
|
380
|
-
|
|
402
|
+
ctx.effect(() => disposeSlots, 'dsh-connect-godagent: settings slots');
|
|
403
|
+
|
|
381
404
|
const candidates = [PLUGIN_ID, `include:${PLUGIN_ID}`];
|
|
382
405
|
if (forms && typeof forms.whileServed === 'function') {
|
|
383
406
|
ctx.effect(() => forms.whileServed(candidates, (served) => {
|
|
384
407
|
const ns = candidates.find((candidate) => served.has(candidate))
|
|
385
408
|
?? [...served].find((entry) => /godagent/i.test(entry));
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
409
|
+
if (ns !== undefined) {
|
|
410
|
+
const nextScope = forms.get(ns);
|
|
411
|
+
if (nextScope !== settingsScope || ns !== boundNs) {
|
|
412
|
+
boundNs = ns;
|
|
413
|
+
settingsScope = nextScope;
|
|
414
|
+
rebindSlots();
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
return () => {};
|
|
392
418
|
}), 'dsh-connect-godagent: settings namespace binding');
|
|
393
|
-
} else {
|
|
394
|
-
console.warn('[dsh-connect-godagent] configForms 服务不可用,设置页不可用(模型接入不受影响)');
|
|
395
419
|
}
|
|
396
420
|
rebindSlots();
|
|
397
421
|
} catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-connect-godagent",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "把本机登录的 God Agent 桌面 App(gptgod.online)模型接入 DSH:复用其会话凭据自动创建/复用 API Key,注册 OpenAI 兼容模型目录,展示分组倍率。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -25,9 +25,7 @@
|
|
|
25
25
|
"platform": "web",
|
|
26
26
|
"inject": [
|
|
27
27
|
"@deepseek-ai/dsh-client-ui-settings",
|
|
28
|
-
"@deepseek-ai/dsh-client-ui-slots"
|
|
29
|
-
"remote",
|
|
30
|
-
"remote.settings"
|
|
28
|
+
"@deepseek-ai/dsh-client-ui-slots"
|
|
31
29
|
]
|
|
32
30
|
}
|
|
33
31
|
},
|