@dsh-plus/subagent-model 0.1.7 → 0.1.9
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/lib/client.js +414 -286
- package/package.json +4 -2
- package/src/client/card.tsx +94 -157
- package/src/client/client.ts +5 -84
- package/src/client/draft.ts +69 -0
- package/src/client/i18n.ts +7 -22
- package/src/client/styles.ts +12 -48
- package/src/client/fields.tsx +0 -75
- package/src/client/scope.ts +0 -56
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dsh-plus/subagent-model",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "dsh-plus service+ui plugin: 为 subagent/subagent_fork 等子代理按提供商配置模型与思考程度(或继承主代理)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -31,7 +31,9 @@
|
|
|
31
31
|
"platform": "web"
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
|
-
"dependencies": {
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@dsh-plus/shared": "0.1.3"
|
|
36
|
+
},
|
|
35
37
|
"peerDependencies": {
|
|
36
38
|
"@deepseek-ai/cordis": "^4.0.1",
|
|
37
39
|
"@deepseek-ai/dsh-settings": "^0.1.0-rc.8",
|
package/src/client/card.tsx
CHANGED
|
@@ -1,18 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 「子代理模型配置」配置卡片:注册进 settings.plugin.item 插槽(官方插件配置页)。
|
|
3
|
-
*
|
|
4
|
-
* 配置读写走官方 settingsScope
|
|
5
|
-
*
|
|
3
|
+
* 外壳与基础控件走 @dsh-plus/shared/client 套件(CardChrome/CheckRow/SelectField)。
|
|
4
|
+
* 配置读写走官方 settingsScope 传输:value 为 schema 解析后的命名空间值
|
|
5
|
+
* (enabled + entries),行集合 = 目录返回的已注册子代理 provider
|
|
6
6
|
* ∪ 已配置条目,保存时全量写回 entries(未配置的新 provider 行以默认空值
|
|
7
7
|
* 落盘,自文档化);「模型目录」为唯一保留的自定义端点。
|
|
8
8
|
* @module subagent-model/client/card
|
|
9
9
|
*/
|
|
10
|
-
import { type ReactElement, useEffect, useMemo, useState, useSyncExternalStore } from 'react'
|
|
11
10
|
|
|
11
|
+
import {
|
|
12
|
+
CardChrome,
|
|
13
|
+
type CardStatusState,
|
|
14
|
+
CheckRow,
|
|
15
|
+
IDLE_STATUS,
|
|
16
|
+
type Scope,
|
|
17
|
+
SelectField,
|
|
18
|
+
type SelectOption,
|
|
19
|
+
type SettingsApi,
|
|
20
|
+
} from '@dsh-plus/shared/client'
|
|
21
|
+
import { type ReactElement, useEffect, useMemo, useState, useSyncExternalStore } from 'react'
|
|
12
22
|
import { SETTINGS_NS } from '../ns.ts'
|
|
13
23
|
import { type CatalogProvider, fetchCatalog, type ModelCatalog } from './api.ts'
|
|
14
|
-
import {
|
|
15
|
-
|
|
24
|
+
import {
|
|
25
|
+
type ConfigValue,
|
|
26
|
+
type Draft,
|
|
27
|
+
type DraftRow,
|
|
28
|
+
draftFrom,
|
|
29
|
+
EMPTY_ROW,
|
|
30
|
+
toPatch,
|
|
31
|
+
} from './draft.ts'
|
|
16
32
|
|
|
17
33
|
export interface CardProps {
|
|
18
34
|
t(key: string): string
|
|
@@ -20,70 +36,9 @@ export interface CardProps {
|
|
|
20
36
|
api: SettingsApi
|
|
21
37
|
}
|
|
22
38
|
|
|
23
|
-
/** settings 命名空间的解析值(无 secret 字段)。 */
|
|
24
|
-
export interface ConfigValue {
|
|
25
|
-
enabled: boolean
|
|
26
|
-
entries: Record<string, WireEntry>
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface WireEntry {
|
|
30
|
-
enabled: boolean
|
|
31
|
-
provider: string
|
|
32
|
-
model: string
|
|
33
|
-
reasoningEffort: string
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
interface DraftRow {
|
|
37
|
-
enabled: boolean
|
|
38
|
-
provider: string
|
|
39
|
-
model: string
|
|
40
|
-
reasoningEffort: string
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
interface Draft {
|
|
44
|
-
enabled: boolean
|
|
45
|
-
rows: Record<string, DraftRow>
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
interface Status {
|
|
49
|
-
kind: 'idle' | 'ok' | 'error'
|
|
50
|
-
text: string
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const IDLE_STATUS: Status = { kind: 'idle', text: '' }
|
|
54
|
-
const EMPTY_ROW: DraftRow = {
|
|
55
|
-
enabled: false,
|
|
56
|
-
provider: '',
|
|
57
|
-
model: '',
|
|
58
|
-
reasoningEffort: 'inherit',
|
|
59
|
-
}
|
|
60
39
|
const EFFORT_INHERIT = 'inherit'
|
|
61
40
|
const EFFORT_DEFAULT = 'default'
|
|
62
41
|
|
|
63
|
-
function draftFrom(value: ConfigValue, catalog: ModelCatalog | null): Draft {
|
|
64
|
-
const rows: Record<string, DraftRow> = {}
|
|
65
|
-
const names = new Set<string>()
|
|
66
|
-
for (const name of catalog?.subagentProviders ?? []) names.add(name)
|
|
67
|
-
for (const name of Object.keys(value.entries).sort()) names.add(name)
|
|
68
|
-
for (const name of names) {
|
|
69
|
-
const entry = value.entries[name]
|
|
70
|
-
rows[name] =
|
|
71
|
-
entry === undefined
|
|
72
|
-
? { ...EMPTY_ROW }
|
|
73
|
-
: {
|
|
74
|
-
enabled: entry.enabled,
|
|
75
|
-
provider: entry.provider,
|
|
76
|
-
model: entry.model,
|
|
77
|
-
reasoningEffort: entry.reasoningEffort,
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return { enabled: value.enabled, rows }
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function toPatch(draft: Draft): Record<string, unknown> {
|
|
84
|
-
return { enabled: draft.enabled, entries: draft.rows }
|
|
85
|
-
}
|
|
86
|
-
|
|
87
42
|
function unknownOption(value: string, label: string): SelectOption {
|
|
88
43
|
return { value, label: `${value}(${label})` }
|
|
89
44
|
}
|
|
@@ -152,6 +107,7 @@ function RowBlock(props: RowBlockProps): ReactElement {
|
|
|
152
107
|
<div className="dsm-rowHead">
|
|
153
108
|
<span className="dsm-rowName">{name}</span>
|
|
154
109
|
<CheckRow
|
|
110
|
+
prefix="dsm"
|
|
155
111
|
id={`dsm-row-${name}`}
|
|
156
112
|
label={t('rowEnabled')}
|
|
157
113
|
checked={row.enabled}
|
|
@@ -161,6 +117,7 @@ function RowBlock(props: RowBlockProps): ReactElement {
|
|
|
161
117
|
</div>
|
|
162
118
|
<p className="dsm-rowHint">{t('rowHint')}</p>
|
|
163
119
|
<SelectField
|
|
120
|
+
prefix="dsm"
|
|
164
121
|
id={`dsm-provider-${name}`}
|
|
165
122
|
label={t('provider')}
|
|
166
123
|
hint={t('providerHint')}
|
|
@@ -170,6 +127,7 @@ function RowBlock(props: RowBlockProps): ReactElement {
|
|
|
170
127
|
onEdit={(v) => onEdit({ ...row, provider: v })}
|
|
171
128
|
/>
|
|
172
129
|
<SelectField
|
|
130
|
+
prefix="dsm"
|
|
173
131
|
id={`dsm-model-${name}`}
|
|
174
132
|
label={t('model')}
|
|
175
133
|
hint={t('modelHint')}
|
|
@@ -181,6 +139,7 @@ function RowBlock(props: RowBlockProps): ReactElement {
|
|
|
181
139
|
onEdit={(v) => onEdit({ ...row, model: v })}
|
|
182
140
|
/>
|
|
183
141
|
<SelectField
|
|
142
|
+
prefix="dsm"
|
|
184
143
|
id={`dsm-effort-${name}`}
|
|
185
144
|
label={t('effort')}
|
|
186
145
|
hint={t('effortHint')}
|
|
@@ -205,7 +164,7 @@ export function SubagentModelCard(props: CardProps): ReactElement | null {
|
|
|
205
164
|
const [catalog, setCatalog] = useState<ModelCatalog | null>(null)
|
|
206
165
|
const [catalogFailed, setCatalogFailed] = useState(false)
|
|
207
166
|
const [saving, setSaving] = useState(false)
|
|
208
|
-
const [status, setStatus] = useState<
|
|
167
|
+
const [status, setStatus] = useState<CardStatusState>(IDLE_STATUS)
|
|
209
168
|
|
|
210
169
|
// 播种草稿(行集 = 已配置条目);catalog 到达后只补缺失的 provider 空行,
|
|
211
170
|
// 不覆盖在途编辑;后续 Host 更新同样不覆盖。
|
|
@@ -306,97 +265,75 @@ export function SubagentModelCard(props: CardProps): ReactElement | null {
|
|
|
306
265
|
const rowNames = Object.keys(draft.rows).sort()
|
|
307
266
|
const providerCount = (catalog?.providers ?? []).length
|
|
308
267
|
return (
|
|
309
|
-
<
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
{
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
{t('noRows')}
|
|
354
|
-
</p>
|
|
355
|
-
) : null}
|
|
356
|
-
{rowNames.map((name) => (
|
|
357
|
-
<RowBlock
|
|
358
|
-
key={name}
|
|
359
|
-
name={name}
|
|
360
|
-
row={draft.rows[name] ?? { ...EMPTY_ROW }}
|
|
361
|
-
catalog={catalog}
|
|
362
|
-
disabled={disabled}
|
|
363
|
-
t={t}
|
|
364
|
-
onEdit={(row) => editRow(name, row)}
|
|
365
|
-
/>
|
|
366
|
-
))}
|
|
367
|
-
<p className="dsm-hint dsm-rowHint">{providerCount > 0 ? t('rowDesc') : ''}</p>
|
|
368
|
-
<div className="dsm-footer">
|
|
369
|
-
{status.kind !== 'idle' ? (
|
|
370
|
-
<p
|
|
371
|
-
className={`dsm-status${status.kind === 'error' ? ' dsm-statusError' : ''}`}
|
|
372
|
-
role="status"
|
|
373
|
-
>
|
|
374
|
-
{status.text}
|
|
375
|
-
</p>
|
|
376
|
-
) : null}
|
|
377
|
-
<button
|
|
378
|
-
type="button"
|
|
379
|
-
className="dsm-btn dsm-btnGhost"
|
|
380
|
-
disabled={!dirty || saving}
|
|
381
|
-
onClick={() => {
|
|
382
|
-
setDraft(draftFrom(value, catalog))
|
|
383
|
-
setStatus(IDLE_STATUS)
|
|
384
|
-
}}
|
|
385
|
-
>
|
|
386
|
-
{t('discard')}
|
|
387
|
-
</button>
|
|
388
|
-
<button
|
|
389
|
-
type="button"
|
|
390
|
-
className="dsm-btn dsm-btnPrimary"
|
|
391
|
-
disabled={!dirty || invalid || saving || disabled}
|
|
392
|
-
onClick={onSave}
|
|
393
|
-
>
|
|
394
|
-
{t(saving ? 'saving' : 'save')}
|
|
395
|
-
</button>
|
|
396
|
-
</div>
|
|
268
|
+
<CardChrome
|
|
269
|
+
prefix="dsm"
|
|
270
|
+
title={t('title')}
|
|
271
|
+
description={t('description')}
|
|
272
|
+
open={open}
|
|
273
|
+
onToggle={setOpen}
|
|
274
|
+
statusBadge={{ text: t(draft.enabled ? 'enabledOn' : 'enabledOff'), on: draft.enabled }}
|
|
275
|
+
dirty={dirty}
|
|
276
|
+
dirtyLabel={t('unsaved')}
|
|
277
|
+
readOnlyNotice={disabled ? t('readOnly') : undefined}
|
|
278
|
+
status={status}
|
|
279
|
+
actions={[
|
|
280
|
+
{
|
|
281
|
+
key: 'discard',
|
|
282
|
+
label: t('discard'),
|
|
283
|
+
disabled: !dirty || saving,
|
|
284
|
+
onClick: () => {
|
|
285
|
+
setDraft(draftFrom(value, catalog))
|
|
286
|
+
setStatus(IDLE_STATUS)
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
key: 'save',
|
|
291
|
+
label: t(saving ? 'saving' : 'save'),
|
|
292
|
+
variant: 'primary',
|
|
293
|
+
disabled: !dirty || invalid || saving || disabled,
|
|
294
|
+
onClick: onSave,
|
|
295
|
+
},
|
|
296
|
+
]}
|
|
297
|
+
>
|
|
298
|
+
<CheckRow
|
|
299
|
+
prefix="dsm"
|
|
300
|
+
id="dsm-enabled"
|
|
301
|
+
label={t('enabled')}
|
|
302
|
+
checked={draft.enabled}
|
|
303
|
+
disabled={disabled}
|
|
304
|
+
onEdit={(v) => edit('enabled', v)}
|
|
305
|
+
/>
|
|
306
|
+
{catalogFailed ? (
|
|
307
|
+
<div className="dsm-banner" role="status">
|
|
308
|
+
<span>{t('catalogError')}</span>
|
|
309
|
+
<button type="button" className="dsm-bannerRetry" onClick={onRetryCatalog}>
|
|
310
|
+
{t('catalogRetry')}
|
|
311
|
+
</button>
|
|
397
312
|
</div>
|
|
398
313
|
) : null}
|
|
399
|
-
|
|
314
|
+
{catalog === null && !catalogFailed ? (
|
|
315
|
+
<p className="dsm-empty" role="status">
|
|
316
|
+
{t('catalogLoading')}
|
|
317
|
+
</p>
|
|
318
|
+
) : null}
|
|
319
|
+
{rowNames.length === 0 ? (
|
|
320
|
+
<p className="dsm-empty" role="status">
|
|
321
|
+
{t('noRows')}
|
|
322
|
+
</p>
|
|
323
|
+
) : null}
|
|
324
|
+
{rowNames.map((name) => (
|
|
325
|
+
<RowBlock
|
|
326
|
+
key={name}
|
|
327
|
+
name={name}
|
|
328
|
+
row={draft.rows[name] ?? { ...EMPTY_ROW }}
|
|
329
|
+
catalog={catalog}
|
|
330
|
+
disabled={disabled}
|
|
331
|
+
t={t}
|
|
332
|
+
onEdit={(row) => editRow(name, row)}
|
|
333
|
+
/>
|
|
334
|
+
))}
|
|
335
|
+
<p className="dsm-hint dsm-rowHint">{providerCount > 0 ? t('rowDesc') : ''}</p>
|
|
336
|
+
</CardChrome>
|
|
400
337
|
)
|
|
401
338
|
}
|
|
402
339
|
|
package/src/client/client.ts
CHANGED
|
@@ -4,23 +4,20 @@
|
|
|
4
4
|
* (包装见 tsdown.config.ts);样式沿用官方 data-plugin-css 约定,HMR 据此卸载。
|
|
5
5
|
*
|
|
6
6
|
* 类型说明:浏览器半只用到 slots/locale/connection/remote 的很窄一面,
|
|
7
|
-
*
|
|
8
|
-
* client 依赖树;运行时契约以官方 dsh-client-ui-settings-plugins 的
|
|
9
|
-
* settings.plugin.item 插槽与 dsh-client-connection 的 settings RPC 面为准。
|
|
7
|
+
* scope 与基础控件走 @dsh-plus/shared/client 套件(收编自本插件原实现)。
|
|
10
8
|
* rc7 起该插槽为 keyed 槽位:key 必须是卡片编辑的 settings 命名空间
|
|
11
9
|
* (即服务端 settingsNamespace() 注册的同一字面量,见 ../ns.ts),
|
|
12
10
|
* 官方配置页按此 key 与 Host 已注册命名空间配对分发。
|
|
13
11
|
* 配置读写经官方 settings RPC 直连(rc7 起第三方命名空间全量开放;
|
|
14
|
-
* 不复用 settingsScope 服务——非 loopback
|
|
12
|
+
* 不复用 settingsScope 服务——非 loopback 页面下它无数据);
|
|
15
13
|
* 自定义端点仅剩「模型目录」(api.ts)。
|
|
16
14
|
* @module @dsh-plus/subagent-model/client
|
|
17
15
|
*/
|
|
18
16
|
import type { Context } from '@deepseek-ai/cordis'
|
|
19
|
-
|
|
17
|
+
import { createApiScope } from '@dsh-plus/shared/client'
|
|
20
18
|
import { SETTINGS_NS } from '../ns.ts'
|
|
21
19
|
import { SubagentModelCard } from './card.tsx'
|
|
22
20
|
import { en, NS, zh } from './i18n.ts'
|
|
23
|
-
import type { Scope, SettingsApi } from './scope.ts'
|
|
24
21
|
import { injectStyle } from './styles.ts'
|
|
25
22
|
|
|
26
23
|
export const name = 'dsh-plus-subagent-model'
|
|
@@ -43,7 +40,7 @@ interface RemoteLike {
|
|
|
43
40
|
}
|
|
44
41
|
|
|
45
42
|
interface ConnectionLike {
|
|
46
|
-
api: { settings:
|
|
43
|
+
api: { settings: Parameters<typeof createApiScope>[0] }
|
|
47
44
|
}
|
|
48
45
|
|
|
49
46
|
interface ClientContext {
|
|
@@ -55,82 +52,6 @@ interface ClientContext {
|
|
|
55
52
|
effect(execute: () => () => void, label?: string): unknown
|
|
56
53
|
}
|
|
57
54
|
|
|
58
|
-
/**
|
|
59
|
-
* api 直连实现的命名空间 scope(官方配置页 tab 同款模式)。
|
|
60
|
-
* 读:describe 取命名空间视图(脱敏 value/revision + 顶层 writable);
|
|
61
|
-
* 刷新:remote `settings/document-updated`(按命名空间过滤)与
|
|
62
|
-
* `connection/reset`;generation 防旧读覆盖新发布。任何页面 origin
|
|
63
|
-
* (loopback 或 tailnet 信任域名)下行为一致。
|
|
64
|
-
*/
|
|
65
|
-
function createApiScope(api: SettingsApi, ns: string, c: ClientContext): Scope {
|
|
66
|
-
let state: ScopeSnapshot = {
|
|
67
|
-
status: 'loading',
|
|
68
|
-
value: undefined,
|
|
69
|
-
revision: undefined,
|
|
70
|
-
writable: false,
|
|
71
|
-
}
|
|
72
|
-
const listeners = new Set<() => void>()
|
|
73
|
-
let generation = 0
|
|
74
|
-
const publish = (next: ScopeSnapshot): void => {
|
|
75
|
-
state = next
|
|
76
|
-
for (const listener of [...listeners]) listener()
|
|
77
|
-
}
|
|
78
|
-
const load = async (): Promise<void> => {
|
|
79
|
-
const gen = ++generation
|
|
80
|
-
let response: Awaited<ReturnType<SettingsApi['describe']>>
|
|
81
|
-
try {
|
|
82
|
-
response = await api.describe({})
|
|
83
|
-
} catch {
|
|
84
|
-
return
|
|
85
|
-
}
|
|
86
|
-
if (gen !== generation || !response.result.ok) return
|
|
87
|
-
const writable = response.result.value?.writable ?? false
|
|
88
|
-
const view = response.result.value?.namespaces.find((candidate) => candidate.ns === ns)
|
|
89
|
-
if (view === undefined) {
|
|
90
|
-
publish({
|
|
91
|
-
status: 'unavailable',
|
|
92
|
-
value: undefined,
|
|
93
|
-
revision: undefined,
|
|
94
|
-
writable,
|
|
95
|
-
})
|
|
96
|
-
return
|
|
97
|
-
}
|
|
98
|
-
publish({
|
|
99
|
-
status: 'ready',
|
|
100
|
-
value: view.value,
|
|
101
|
-
revision: view.revision,
|
|
102
|
-
writable,
|
|
103
|
-
})
|
|
104
|
-
}
|
|
105
|
-
const refresh = (namespace?: unknown): void => {
|
|
106
|
-
if (namespace !== undefined && namespace !== ns) return
|
|
107
|
-
void load()
|
|
108
|
-
}
|
|
109
|
-
const disposers = [
|
|
110
|
-
c.get('remote').$on('settings/document-updated', refresh),
|
|
111
|
-
c.on('connection/reset', () => {
|
|
112
|
-
void load()
|
|
113
|
-
}),
|
|
114
|
-
]
|
|
115
|
-
c.effect(
|
|
116
|
-
() => () => {
|
|
117
|
-
for (const dispose of disposers) dispose()
|
|
118
|
-
},
|
|
119
|
-
'subagent-model: settings scope',
|
|
120
|
-
)
|
|
121
|
-
void load()
|
|
122
|
-
return {
|
|
123
|
-
getSnapshot: () => state,
|
|
124
|
-
subscribe: (listener: () => void) => {
|
|
125
|
-
listeners.add(listener)
|
|
126
|
-
return () => {
|
|
127
|
-
listeners.delete(listener)
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
load,
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
55
|
export function apply(ctx: Context): void {
|
|
135
56
|
const c = ctx as unknown as ClientContext
|
|
136
57
|
const tag = injectStyle()
|
|
@@ -142,7 +63,7 @@ export function apply(ctx: Context): void {
|
|
|
142
63
|
)
|
|
143
64
|
c.effect(() => c.locale.register(NS, { zh, en }), 'subagent-model: locale')
|
|
144
65
|
const api = c.get('connection').api.settings
|
|
145
|
-
const scope = createApiScope(api, SETTINGS_NS, c)
|
|
66
|
+
const scope = createApiScope(api, SETTINGS_NS, c, 'subagent-model: settings scope')
|
|
146
67
|
c.slots.inject('settings.plugin.item', () =>
|
|
147
68
|
c.slots.register(
|
|
148
69
|
{
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 配置卡片的可编辑草稿模型:ConfigValue ↔ Draft 转换与提交补丁(纯函数,
|
|
3
|
+
* 与渲染分离以便单测)。行集合 = 目录返回的已注册子代理 provider ∪ 已配置条目;
|
|
4
|
+
* 未配置的新 provider 行以默认空值落盘(自文档化)。
|
|
5
|
+
* @module subagent-model/client/draft
|
|
6
|
+
*/
|
|
7
|
+
import type { ModelCatalog } from './api.ts'
|
|
8
|
+
|
|
9
|
+
/** settings 命名空间的解析值(无 secret 字段)。 */
|
|
10
|
+
export interface ConfigValue {
|
|
11
|
+
enabled: boolean
|
|
12
|
+
entries: Record<string, WireEntry>
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface WireEntry {
|
|
16
|
+
enabled: boolean
|
|
17
|
+
provider: string
|
|
18
|
+
model: string
|
|
19
|
+
reasoningEffort: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface DraftRow {
|
|
23
|
+
enabled: boolean
|
|
24
|
+
provider: string
|
|
25
|
+
model: string
|
|
26
|
+
reasoningEffort: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface Draft {
|
|
30
|
+
enabled: boolean
|
|
31
|
+
rows: Record<string, DraftRow>
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const EMPTY_ROW: DraftRow = {
|
|
35
|
+
enabled: false,
|
|
36
|
+
provider: '',
|
|
37
|
+
model: '',
|
|
38
|
+
reasoningEffort: 'inherit',
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** 行集 = 目录 subagentProviders ∪ 已配置条目;目录行缺省为空行。 */
|
|
42
|
+
export function draftFrom(value: ConfigValue, catalog: ModelCatalog | null): Draft {
|
|
43
|
+
const rows: Record<string, DraftRow> = {}
|
|
44
|
+
const names = new Set<string>()
|
|
45
|
+
for (const name of catalog?.subagentProviders ?? []) names.add(name)
|
|
46
|
+
for (const name of Object.keys(value.entries).sort()) names.add(name)
|
|
47
|
+
for (const name of names) {
|
|
48
|
+
const entry = value.entries[name]
|
|
49
|
+
rows[name] =
|
|
50
|
+
entry === undefined
|
|
51
|
+
? { ...EMPTY_ROW }
|
|
52
|
+
: {
|
|
53
|
+
enabled: entry.enabled,
|
|
54
|
+
provider: entry.provider,
|
|
55
|
+
model: entry.model,
|
|
56
|
+
reasoningEffort: entry.reasoningEffort,
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return { enabled: value.enabled, rows }
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function toPatch(draft: Draft): Record<string, unknown> {
|
|
63
|
+
// entries 按键排序物化:dirty 比较走 JSON.stringify,而草稿的播种路径
|
|
64
|
+
// (先 entries 后补目录空行)与 draftFrom(先目录后 entries)键序不同,
|
|
65
|
+
// 不排序会出现「未改动却永久 dirty」的假阳性。
|
|
66
|
+
const entries: Record<string, DraftRow> = {}
|
|
67
|
+
for (const name of Object.keys(draft.rows).sort()) entries[name] = draft.rows[name]
|
|
68
|
+
return { enabled: draft.enabled, entries }
|
|
69
|
+
}
|
package/src/client/i18n.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 配置卡片文案(zh/en)。经 ctx.locale.register 注册、bind 取用,与官方卡片同机制。
|
|
3
|
+
* 公共键(save/discard/unsaved 等)来自 shared 的 common 字典,本文件只维护业务键。
|
|
3
4
|
* @module subagent-model/client/i18n
|
|
4
5
|
*/
|
|
6
|
+
import { commonEn, commonZh, mergeDict } from '@dsh-plus/shared/client'
|
|
5
7
|
|
|
6
8
|
export const NS = 'dsh-plus-subagent-model'
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
const ownZh = {
|
|
9
11
|
title: '子代理模型配置',
|
|
10
12
|
description: '为 subagent / subagent_fork 等子代理单独指定提供商、模型与思考程度,或继承主代理。',
|
|
11
13
|
enabled: '启用插件',
|
|
@@ -28,20 +30,10 @@ export const zh: Record<string, string> = {
|
|
|
28
30
|
catalogRetry: '重试',
|
|
29
31
|
catalogLoading: '目录加载中…',
|
|
30
32
|
unknownValue: '目录外',
|
|
31
|
-
save: '保存',
|
|
32
|
-
saving: '保存中…',
|
|
33
|
-
discard: '放弃',
|
|
34
|
-
unsaved: '未保存',
|
|
35
|
-
saveFailed: '保存失败:',
|
|
36
|
-
loading: '加载中…',
|
|
37
|
-
unavailable: '配置服务不可用。',
|
|
38
|
-
readOnly: '当前部署无 settings provider,配置为只读;请编辑 settings.yaml。',
|
|
39
|
-
expand: '展开',
|
|
40
|
-
collapse: '收起',
|
|
41
33
|
invalidModel: '模型不能脱离提供商单独配置。',
|
|
42
34
|
}
|
|
43
35
|
|
|
44
|
-
|
|
36
|
+
const ownEn = {
|
|
45
37
|
title: 'Subagent model config',
|
|
46
38
|
description:
|
|
47
39
|
'Pick a provider, model, and thinking effort for subagent / subagent_fork children, or inherit from the main agent.',
|
|
@@ -66,15 +58,8 @@ export const en: Record<string, string> = {
|
|
|
66
58
|
catalogRetry: 'Retry',
|
|
67
59
|
catalogLoading: 'Loading catalog\u2026',
|
|
68
60
|
unknownValue: 'outside catalog',
|
|
69
|
-
save: 'Save',
|
|
70
|
-
saving: 'Saving\u2026',
|
|
71
|
-
discard: 'Discard',
|
|
72
|
-
unsaved: 'Unsaved',
|
|
73
|
-
saveFailed: 'Save failed: ',
|
|
74
|
-
loading: 'Loading\u2026',
|
|
75
|
-
unavailable: 'Configuration service unavailable.',
|
|
76
|
-
readOnly: 'No settings provider in this deployment; edit settings.yaml instead.',
|
|
77
|
-
expand: 'Expand',
|
|
78
|
-
collapse: 'Collapse',
|
|
79
61
|
invalidModel: 'Model cannot be set without a provider.',
|
|
80
62
|
}
|
|
63
|
+
|
|
64
|
+
export const zh: Record<string, string> = mergeDict(commonZh, ownZh)
|
|
65
|
+
export const en: Record<string, string> = mergeDict(commonEn, ownEn)
|
package/src/client/styles.ts
CHANGED
|
@@ -1,66 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* 配置卡片样式:基础规则走 @dsh-plus/shared/client 的 cardCss('dsm'),
|
|
3
|
+
* 本文件只补插件特有规则(provider 行块 / banner / 目录空态)。
|
|
4
|
+
* 沿用官方 data-plugin / data-plugin-css 约定(HMR 据此卸载)。
|
|
4
5
|
* @module subagent-model/client/styles
|
|
5
6
|
*/
|
|
7
|
+
import { cardCss, injectCardStyle } from '@dsh-plus/shared/client'
|
|
6
8
|
|
|
7
9
|
export const PLUGIN_ID = '@dsh-plus/subagent-model'
|
|
8
|
-
export const STYLE_TAG_ID = `${PLUGIN_ID}/card.css`
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
.dsm-card{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);border-radius:12px;list-style:none;transition:border-color .16s,background .16s}
|
|
12
|
-
.dsm-card:hover{border-color:var(--dsw-alias-label-dimmed)}
|
|
13
|
-
.dsm-cardOpen{background:var(--dsw-alias-bg-layer-2);border-color:var(--dsw-alias-label-dimmed)}
|
|
14
|
-
.dsm-header{appearance:none;width:100%;font:inherit;color:inherit;text-align:left;cursor:pointer;background:0 0;border:0;border-radius:12px;align-items:center;gap:12px;padding:14px 16px;display:flex}
|
|
15
|
-
.dsm-header:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:-2px}
|
|
16
|
-
.dsm-headText{flex-direction:column;flex:1;gap:4px;min-width:0;display:flex}
|
|
17
|
-
.dsm-name{color:var(--dsw-alias-label-primary);font-size:15px;font-weight:600;line-height:1.4}
|
|
18
|
-
.dsm-description{color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:1.5}
|
|
19
|
-
.dsm-chevron{color:var(--dsw-alias-label-tertiary);flex:none;transition:transform .16s;font-size:12px}
|
|
20
|
-
.dsm-chevronOpen{transform:rotate(180deg)}
|
|
21
|
-
.dsm-pending{white-space:nowrap;background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary);border-radius:999px;flex:none;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}
|
|
22
|
-
.dsm-body{border-top:1px solid var(--dsw-alias-border-l2);margin:0 16px;padding-bottom:8px}
|
|
23
|
-
.dsm-field{flex-direction:column;gap:6px;padding:12px 0;display:flex}
|
|
24
|
-
.dsm-field+.dsm-field{border-top:1px solid var(--dsw-alias-border-l2)}
|
|
25
|
-
.dsm-head{align-items:center;gap:8px;display:flex}
|
|
26
|
-
.dsm-label{min-width:0;color:var(--dsw-alias-label-primary);flex:1;font-size:13px;font-weight:500;line-height:1.5}
|
|
27
|
-
.dsm-select{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);height:34px;min-width:0;font:inherit;color:var(--dsw-alias-label-primary);border-radius:8px;padding:0 8px;font-size:13px}
|
|
28
|
-
.dsm-select:focus-visible{border-color:var(--dsw-alias-brand-primary);outline:none}
|
|
29
|
-
.dsm-select:disabled{color:var(--dsw-alias-label-tertiary);cursor:default}
|
|
30
|
-
.dsm-hint{color:var(--dsw-alias-label-tertiary);margin:0;font-size:12px;line-height:1.5}
|
|
31
|
-
.dsm-invalid{color:var(--dsw-alias-label-error);margin:0;font-size:12px;line-height:1.5}
|
|
32
|
-
.dsm-checkRow{align-items:center;gap:8px;display:flex;padding:6px 0}
|
|
33
|
-
.dsm-checkRow input{accent-color:var(--dsw-alias-brand-primary)}
|
|
34
|
-
.dsm-checkRow label{color:var(--dsw-alias-label-primary);font-size:13px;line-height:1.5;cursor:pointer}
|
|
11
|
+
const extraCss = `
|
|
35
12
|
.dsm-row{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-2);border-radius:10px;margin:12px 0 0;padding:4px 12px 10px}
|
|
36
13
|
.dsm-rowHead{align-items:center;gap:8px;padding:8px 0 2px;display:flex}
|
|
37
14
|
.dsm-rowName{min-width:0;color:var(--dsw-alias-label-primary);flex:1;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:13px;font-weight:600;line-height:1.5}
|
|
38
15
|
.dsm-rowHint{color:var(--dsw-alias-label-tertiary);margin:0 0 4px;font-size:12px;line-height:1.5}
|
|
39
|
-
.dsm-groupLabel{color:var(--dsw-alias-label-secondary);font-size:12px;font-weight:600;padding:12px 0 2px;margin:0}
|
|
40
|
-
.dsm-status{min-width:0;color:var(--dsw-alias-label-secondary);flex:1;margin:0;font-size:12px;line-height:1.5}
|
|
41
|
-
.dsm-statusError{color:var(--dsw-alias-label-error)}
|
|
42
16
|
.dsm-banner{background:var(--dsw-alias-interactive-bg-hover-danger);color:var(--dsw-alias-state-error-primary);justify-content:space-between;align-items:center;gap:8px;border-radius:8px;margin-top:12px;padding:7px 8px;font-size:12px;line-height:18px;display:flex}
|
|
43
17
|
.dsm-bannerRetry{color:inherit;font:inherit;cursor:pointer;background:0 0;border:none;flex:none;padding:0;font-weight:600}
|
|
44
18
|
.dsm-empty{color:var(--dsw-alias-label-tertiary);margin:12px 0 0;font-size:12px;line-height:1.5}
|
|
45
|
-
|
|
46
|
-
.dsm-
|
|
47
|
-
.dsm-
|
|
48
|
-
|
|
49
|
-
.dsm-btnPrimary{background:var(--dsw-alias-label-primary);color:var(--dsw-alias-bg-layer-3)}
|
|
50
|
-
.dsm-btn:disabled{opacity:.4;cursor:default}
|
|
51
|
-
.dsm-btn:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}
|
|
19
|
+
@media (max-width:767px){
|
|
20
|
+
.dsm-row{padding:2px 8px 8px}
|
|
21
|
+
.dsm-rowHead{flex-wrap:wrap}
|
|
22
|
+
}
|
|
52
23
|
`
|
|
53
24
|
|
|
25
|
+
export const cardCssAll = cardCss('dsm', extraCss)
|
|
26
|
+
|
|
54
27
|
/** 幂等注入样式标签;返回标签(已存在或环境无 document 时为 null)。 */
|
|
55
28
|
export function injectStyle(): HTMLStyleElement | null {
|
|
56
|
-
|
|
57
|
-
if (document.querySelector(`style[data-plugin-css=${JSON.stringify(STYLE_TAG_ID)}]`) !== null) {
|
|
58
|
-
return null
|
|
59
|
-
}
|
|
60
|
-
const tag = document.createElement('style')
|
|
61
|
-
tag.dataset.plugin = PLUGIN_ID
|
|
62
|
-
tag.dataset.pluginCss = STYLE_TAG_ID
|
|
63
|
-
tag.textContent = cardCss
|
|
64
|
-
document.head.appendChild(tag)
|
|
65
|
-
return tag
|
|
29
|
+
return injectCardStyle(PLUGIN_ID, cardCssAll)
|
|
66
30
|
}
|