dsh-submodel 0.2.0 → 0.4.0
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.en.md +144 -92
- package/README.md +127 -75
- package/client.js +474 -0
- package/docs/plugin-detail.md +5 -0
- package/lib/config.js +164 -0
- package/lib/delegation.js +49 -51
- package/lib/index.js +84 -130
- package/lib/policy.js +110 -43
- package/lib/setup.js +95 -184
- package/lib/team-fit.js +23 -0
- package/lib/watchdog.js +577 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +19 -4
package/client.js
ADDED
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: 'dsh-submodel',
|
|
3
|
+
factory(require) {
|
|
4
|
+
const { createElement: element, useEffect, useId, useRef, useState, useSyncExternalStore } = require('react');
|
|
5
|
+
const namespace = 'submodel.settings';
|
|
6
|
+
const dictionaries = {
|
|
7
|
+
en: {
|
|
8
|
+
title: 'Delegation settings', loading: 'Loading settings…', unavailable: 'Settings are unavailable in this profile.',
|
|
9
|
+
readOnly: 'These settings are read-only.', loadFailed: 'Could not load settings.', retry: 'Try again',
|
|
10
|
+
reconnect: 'Connection changed. Reload the page before editing again. Your draft was not sent to the new connection.',
|
|
11
|
+
reload: 'Reload page', saving: 'Saving…', saved: 'Saved. New conversations will use these settings.',
|
|
12
|
+
pending: 'Unsaved changes', saveFailed: 'Could not save settings. Try again.', transport: 'Connection lost. Please try again.',
|
|
13
|
+
conflict: 'Settings changed elsewhere. Reload the saved settings and review your changes before saving.',
|
|
14
|
+
retain: 'Load saved settings and review draft', review: 'Saved settings reloaded. Review the draft before saving again.',
|
|
15
|
+
reviewOverlap: 'The same settings changed elsewhere. Saving will replace those changes with the draft shown here.',
|
|
16
|
+
noChanges: 'The latest settings already match your draft.',
|
|
17
|
+
discard: 'Discard draft', save: 'Save settings',
|
|
18
|
+
authorization: 'Allow models separately under Plugins → Subagent. Authorization applies to new conversations.',
|
|
19
|
+
notAuthorized: 'Authorization needed', unavailableModel: 'Saved choice (currently unavailable)',
|
|
20
|
+
directoryLoading: 'Loading available models…', directoryFailed: 'Some models could not be loaded.',
|
|
21
|
+
noModels: 'There are no available models.', retryCatalog: 'Reload model list',
|
|
22
|
+
models: 'Delegation models', orderHelp: 'Put your usual choice first. The main model sees this order and your notes, and can choose a different starting model for the task.',
|
|
23
|
+
executors: 'Cost-effective models', experts: 'Expert models',
|
|
24
|
+
executorHelp: 'For routine work such as reading files and checking results.', expertHelp: 'For difficult decisions and problems that need stronger reasoning.',
|
|
25
|
+
chooseModel: 'Choose a model', addExecutor: 'Add a cost-effective model', addExpert: 'Add an expert model',
|
|
26
|
+
noChoices: 'No models in this group yet.', note: 'Use for', noteExample: 'For example, coding first',
|
|
27
|
+
effort: 'Reasoning effort', defaultEffort: 'Model default', previousEffort: 'Saved effort (currently unavailable)',
|
|
28
|
+
remove: 'Remove', up: 'Move up', down: 'Move down', items: 'Selected models',
|
|
29
|
+
legacyLists: 'Saving a group replaces the old backup lists with the order shown here. Review both groups before saving.',
|
|
30
|
+
watchdog: 'Usage reminders', usageHelp: 'Usage is what the model reports in tokens, the units it uses to count text. A single request can go over this amount.',
|
|
31
|
+
mode: 'When to act', off: 'Off', notify: 'Remind the subagent to finish', stop: 'Remind, then prompt me to stop it',
|
|
32
|
+
retryMode: 'Try the next model after failure', manualStop: 'If the task is still running after the wait, use the Subagent panel to stop it.',
|
|
33
|
+
retryHelp: 'After the current model exhausts its retries (five by default), eligible tasks try the next model in the same group if it is authorized. A different provider may charge for the new attempt.',
|
|
34
|
+
legacyRetryHelp: 'Your saved backup lists still apply until you save the new group order.',
|
|
35
|
+
tiers: 'Apply to', executorTier: 'Cost-effective models', expertTier: 'Expert models',
|
|
36
|
+
warnTokens: 'Remind me at this usage (tokens)', graceSeconds: 'Wait after the reminder (seconds)', maxRetries: 'Maximum number of model switches',
|
|
37
|
+
},
|
|
38
|
+
zh: {
|
|
39
|
+
title: '派活设置', loading: '正在加载设置', unavailable: '当前配置环境没有可用的设置页。',
|
|
40
|
+
readOnly: '当前配置只读', loadFailed: '无法加载设置。', retry: '重试',
|
|
41
|
+
reconnect: '连接已更换。请重新加载页面后再编辑;旧草稿不会发往新连接。',
|
|
42
|
+
reload: '重新加载页面', saving: '正在保存…', saved: '已保存。新会话使用此配置',
|
|
43
|
+
pending: '有未保存的修改', saveFailed: '保存失败。请重试', transport: '连接失败。请重试。',
|
|
44
|
+
conflict: '设置已在别处更新。请重新加载后确认修改',
|
|
45
|
+
retain: '读取最新设置并核对草稿', review: '已读到最新设置。请核对草稿后再保存。',
|
|
46
|
+
reviewOverlap: '你编辑的设置在别处也改过。保存会用当前草稿覆盖这部分修改。',
|
|
47
|
+
noChanges: '最新设置已和草稿一致。',
|
|
48
|
+
discard: '放弃草稿', save: '保存设置',
|
|
49
|
+
authorization: '请在插件里的「子代理」设置允许模型。授权对新会话生效。',
|
|
50
|
+
notAuthorized: '需另行授权', unavailableModel: '已保存的选择(当前不可用)',
|
|
51
|
+
directoryLoading: '正在加载模型列表…', directoryFailed: '部分模型暂时无法加载',
|
|
52
|
+
noModels: '暂无可选模型。', retryCatalog: '重试加载模型',
|
|
53
|
+
models: '派活模型', orderHelp: '常用模型排在第一位。主模型会看到顺序和备注,也可以按任务选择从哪一位开始。',
|
|
54
|
+
executors: '性价比模型', experts: '专家模型',
|
|
55
|
+
executorHelp: '适合查资料、读文件和验证结果等日常任务。', expertHelp: '适合棘手的判断和需要更强推理的任务。',
|
|
56
|
+
chooseModel: '选择模型', addExecutor: '添加性价比模型', addExpert: '添加专家模型',
|
|
57
|
+
noChoices: '这组还没有模型。', note: '用途备注', noteExample: '例如:代码优先',
|
|
58
|
+
effort: '默认推理强度', defaultEffort: '模型默认', previousEffort: '已保存档位(当前不可用)',
|
|
59
|
+
remove: '移除', up: '上移', down: '下移', items: '已选模型',
|
|
60
|
+
legacyLists: '保存两组模型后,会按这里的顺序接着试。想保留的旧备选,请先加到对应组里。',
|
|
61
|
+
watchdog: '用量提醒', usageHelp: '词元是模型计算文字用量的单位,以模型报告为准。单次请求可能超过提醒值。',
|
|
62
|
+
mode: '什么时候处理', off: '关闭', notify: '提醒子代理收尾', stop: '提醒后还在运行,就提示我停止',
|
|
63
|
+
retryMode: '失败后尝试下一位模型', manualStop: '等候时间到了如果任务还在运行,可以在「子代理」面板停止。',
|
|
64
|
+
retryHelp: '原模型用完重试次数(默认 5 次)后,满足用量等条件的任务会尝试同组下一位。下一位须已授权。换到其他渠道可能产生费用。',
|
|
65
|
+
legacyRetryHelp: '保存新的分组顺序之前,仍按已保存的旧备选设置处理。',
|
|
66
|
+
tiers: '应用于', executorTier: '性价比模型', expertTier: '专家模型',
|
|
67
|
+
warnTokens: '用量达到多少时提醒(词元)', graceSeconds: '提醒后再等(秒)', maxRetries: '最多换几次模型',
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
const style = `
|
|
71
|
+
.submodel-settings {color:var(--dsw-alias-label-primary);min-width:0;font:inherit;font-size:14px;line-height:1.5}
|
|
72
|
+
.submodel-settings [hidden] {display:none}
|
|
73
|
+
.submodel-settings h3,.submodel-settings h4,.submodel-settings p {margin:0;overflow-wrap:anywhere}
|
|
74
|
+
.submodel-settings h3 {font-size:18px;font-weight:600}
|
|
75
|
+
.submodel-settings h4,.submodel-settings legend {font-size:14px;font-weight:600}
|
|
76
|
+
.submodel-settings form,.submodel-section,.submodel-models,.submodel-field {display:grid;gap:8px;min-width:0}
|
|
77
|
+
.submodel-settings form {gap:24px;margin-top:12px}
|
|
78
|
+
.submodel-section {padding-block-start:16px;border-block-start:1px solid var(--dsw-alias-border-l1)}
|
|
79
|
+
.submodel-settings fieldset {margin:0;padding:0;border:0;min-width:0}
|
|
80
|
+
.submodel-field {margin-block:4px}
|
|
81
|
+
.submodel-settings label,.submodel-model-name {font-weight:500}
|
|
82
|
+
.submodel-muted {color:var(--dsw-alias-label-secondary);font-size:13px}
|
|
83
|
+
.submodel-settings :is(select,input[type=number],input[type=text],button) {box-sizing:border-box;min-height:40px;max-width:100%;text-align:start;border-radius:8px;border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-module-platform);color:inherit;font:inherit;padding:4px 12px}
|
|
84
|
+
.submodel-settings :is(select,input[type=number],input[type=text]) {width:min(100%,420px)}
|
|
85
|
+
.submodel-settings input[type=number] {font-variant-numeric:tabular-nums}
|
|
86
|
+
.submodel-settings button {cursor:pointer}
|
|
87
|
+
.submodel-settings button:not(:disabled):hover {background:var(--dsw-alias-interactive-bg-hover)}
|
|
88
|
+
.submodel-settings :is(input,select,button):focus-visible {outline:2px solid currentColor;outline-offset:2px}
|
|
89
|
+
.submodel-settings :is(button,input,select):disabled {opacity:.55;cursor:default}
|
|
90
|
+
.submodel-settings .submodel-save {font-weight:600;background:var(--dsw-alias-button-ghost-active-fill)}
|
|
91
|
+
.submodel-settings .submodel-save:not(:disabled):hover {background:var(--dsw-alias-button-ghost-active-hover)}
|
|
92
|
+
.submodel-list {display:grid;list-style:none;gap:8px;margin:0;padding:0}
|
|
93
|
+
.submodel-item,.submodel-actions {display:flex;align-items:center;flex-wrap:wrap;gap:8px;min-width:0}
|
|
94
|
+
.submodel-item {justify-content:space-between;overflow-wrap:anywhere}
|
|
95
|
+
.submodel-choices {display:flex;flex-wrap:wrap;gap:4px 16px}
|
|
96
|
+
.submodel-choices label {display:inline-flex;min-height:40px;align-items:center;gap:8px}
|
|
97
|
+
.submodel-group {display:grid;gap:8px;min-width:0;padding-block-start:12px}
|
|
98
|
+
.submodel-group + .submodel-group {border-block-start:1px solid var(--dsw-alias-border-l1)}
|
|
99
|
+
.submodel-choice {display:grid;gap:8px;min-width:0;padding:12px;border:1px solid var(--dsw-alias-border-l2);border-radius:8px}
|
|
100
|
+
.submodel-rank {font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-secondary)}
|
|
101
|
+
.submodel-feedback {min-height:1.5em}
|
|
102
|
+
`;
|
|
103
|
+
const fields = ['modelGroups', 'watchdog'];
|
|
104
|
+
const pair = ({ provider, model }) => ({ provider, model });
|
|
105
|
+
const keyOf = (route) => JSON.stringify([route?.provider, route?.model]);
|
|
106
|
+
const hasPair = (route) => Boolean(route?.provider && route?.model);
|
|
107
|
+
const unique = (rows) => {
|
|
108
|
+
const seen = new Set();
|
|
109
|
+
return rows.filter(row => {
|
|
110
|
+
const key = keyOf(row);
|
|
111
|
+
if (seen.has(key)) return false;
|
|
112
|
+
seen.add(key);
|
|
113
|
+
return true;
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
const reorder = (rows, index, by) => {
|
|
117
|
+
const next = rows.slice();
|
|
118
|
+
[next[index], next[index + by]] = [next[index + by], next[index]];
|
|
119
|
+
return next;
|
|
120
|
+
};
|
|
121
|
+
const canonical = (value) => Array.isArray(value) ? value.map(canonical)
|
|
122
|
+
: value && typeof value === 'object'
|
|
123
|
+
? Object.fromEntries(Object.keys(value).sort().map(key => [key, canonical(value[key])])) : value;
|
|
124
|
+
const equal = (left, right) => JSON.stringify(canonical(left)) === JSON.stringify(canonical(right));
|
|
125
|
+
const sourceOf = (store) => ({ listen: callback => store.subscribe(callback), read: () => store.getSnapshot() });
|
|
126
|
+
const isReady = (snapshot) => snapshot.status === 'ready' && snapshot.value && Number.isSafeInteger(snapshot.revision);
|
|
127
|
+
const text = (name, value, className = 'submodel-muted') => element('p', { className, key: name }, value);
|
|
128
|
+
const button = (label, onClick, disabled, ariaLabel) => element('button', {
|
|
129
|
+
type: 'button', onClick, disabled, ...(ariaLabel === undefined ? {} : { 'aria-label': ariaLabel }),
|
|
130
|
+
}, label);
|
|
131
|
+
const didLoad = (result) => result?.ok === true && Array.isArray(result.value?.groups);
|
|
132
|
+
|
|
133
|
+
function directoryOf(catalog) {
|
|
134
|
+
const models = (catalog?.groups ?? []).flatMap((group) => (group.models ?? [])
|
|
135
|
+
.filter(model => typeof model.name === 'string' && model.name.trim())
|
|
136
|
+
.map(model => ({ provider: group.id, model: model.id, name: model.name,
|
|
137
|
+
// The catalog group carries the provider's display name; fall back to its id.
|
|
138
|
+
channel: typeof group.name === 'string' && group.name.trim() ? group.name.trim() : group.id,
|
|
139
|
+
efforts: model.reasoning?.efforts ?? [] })));
|
|
140
|
+
const counts = new Map();
|
|
141
|
+
for (const model of models) counts.set(model.name, (counts.get(model.name) ?? 0) + 1);
|
|
142
|
+
return unique(models).map(model => ({ ...model, label: counts.get(model.name) > 1
|
|
143
|
+
? `${model.name} · ${model.channel}` : model.name }));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function PickModel({ label, placeholder, rows, onPick }) {
|
|
147
|
+
const id = useId();
|
|
148
|
+
return element('div', { className: 'submodel-field' },
|
|
149
|
+
element('label', { htmlFor: id }, label),
|
|
150
|
+
element('select', { id, value: '', 'data-submodel-model-picker': '', disabled: rows.length === 0,
|
|
151
|
+
onChange: event => { if (event.target.value !== '') onPick(rows[Number(event.target.value)]); } },
|
|
152
|
+
element('option', { value: '', disabled: true }, placeholder),
|
|
153
|
+
...rows.map((row, index) => element('option', { key: keyOf(row), value: String(index) }, row.label))));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function RowLabel({ route, catalog, allowed, translate }) {
|
|
157
|
+
const model = catalog.get(keyOf(route));
|
|
158
|
+
return element('span', { className: model ? 'submodel-model-name' : 'submodel-muted' },
|
|
159
|
+
model?.label ?? translate('unavailableModel'), model && allowed && !allowed.has(keyOf(route))
|
|
160
|
+
? element('span', { className: 'submodel-muted', 'data-submodel-not-authorized': '' }, ` · ${translate('notAuthorized')}`) : null);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function importedGroups(settings) {
|
|
164
|
+
if (Array.isArray(settings.modelGroups?.executors) && Array.isArray(settings.modelGroups?.experts)) return settings.modelGroups;
|
|
165
|
+
const executor = settings.executor;
|
|
166
|
+
return {
|
|
167
|
+
executors: hasPair(executor) ? [{ ...pair(executor), note: '', reasoningEffort: executor.reasoningEffort ?? 'max' }] : [],
|
|
168
|
+
experts: unique((settings.experts ?? []).filter(hasPair)).map(row => ({
|
|
169
|
+
...pair(row), reasoningEffort: row.reasoningEffort ?? '',
|
|
170
|
+
note: ([row.model, `${row.provider}/${row.model}`].includes(row.label) ? '' : row.label ?? '').slice(0, 120),
|
|
171
|
+
})),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function RowEffort({ row, update, catalog, translate }) {
|
|
176
|
+
const id = useId();
|
|
177
|
+
const options = catalog.get(keyOf(row))?.efforts ?? [];
|
|
178
|
+
const effort = row.reasoningEffort;
|
|
179
|
+
return element('div', { className: 'submodel-field' }, element('label', { htmlFor: id }, translate('effort')),
|
|
180
|
+
element('select', { id, value: effort, onChange: event => update({ reasoningEffort: event.target.value }) },
|
|
181
|
+
element('option', { value: '' }, translate('defaultEffort')),
|
|
182
|
+
effort && !options.some(option => option.id === effort)
|
|
183
|
+
? element('option', { value: effort, disabled: true }, translate('previousEffort')) : null,
|
|
184
|
+
...options.map(option => element('option', { key: option.id, value: option.id }, option.name))));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function OrderedModels({ group, rows, update, models, catalog, allowed, translate }) {
|
|
188
|
+
const title = translate(group);
|
|
189
|
+
const executor = group === 'executors';
|
|
190
|
+
const available = models.filter(model => !rows.some(row => keyOf(row) === keyOf(model)));
|
|
191
|
+
return element('section', { className: 'submodel-group', 'data-submodel-group': group, 'aria-label': title },
|
|
192
|
+
element('h4', null, title), text('help', translate(executor ? 'executorHelp' : 'expertHelp')),
|
|
193
|
+
rows.length ? element('ol', { className: 'submodel-list' }, ...rows.map((row, index) => {
|
|
194
|
+
const name = catalog.get(keyOf(row))?.label ?? `${translate('unavailableModel')} ${index + 1}`;
|
|
195
|
+
const updateRow = fields => update(rows.map((item, position) => position === index ? { ...item, ...fields } : item));
|
|
196
|
+
return element('li', { key: keyOf(row), className: 'submodel-choice' },
|
|
197
|
+
element('div', { className: 'submodel-item' },
|
|
198
|
+
element('div', { className: 'submodel-actions' }, element('span', { className: 'submodel-rank' }, `${index + 1}.`),
|
|
199
|
+
element(RowLabel, { route: row, catalog, allowed, translate })),
|
|
200
|
+
element('div', { className: 'submodel-actions' },
|
|
201
|
+
button(translate('up'), () => update(reorder(rows, index, -1)), index === 0, `${translate('up')}: ${name}`),
|
|
202
|
+
button(translate('down'), () => update(reorder(rows, index, 1)), index === rows.length - 1, `${translate('down')}: ${name}`),
|
|
203
|
+
button(translate('remove'), () => update(rows.filter((_item, position) => position !== index)), false, `${translate('remove')}: ${name}`))),
|
|
204
|
+
element('label', { className: 'submodel-field' }, translate('note'),
|
|
205
|
+
element('input', { type: 'text', value: row.note, maxLength: 120, placeholder: translate('noteExample'),
|
|
206
|
+
'aria-label': `${translate('note')}: ${name}`, onChange: event => updateRow({ note: event.target.value }) })),
|
|
207
|
+
element(RowEffort, { row, update: updateRow, catalog, translate }));
|
|
208
|
+
})) : text('empty', translate('noChoices')),
|
|
209
|
+
element(PickModel, { label: translate(executor ? 'addExecutor' : 'addExpert'),
|
|
210
|
+
placeholder: translate('chooseModel'), rows: available,
|
|
211
|
+
onPick: model => update([...rows, { ...pair(model), note: '', reasoningEffort: '' }]) }));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function ModelFields({ settings, legacyLists, change, models, catalog, allowed, translate }) {
|
|
215
|
+
const groups = importedGroups(settings);
|
|
216
|
+
return element('section', { className: 'submodel-section', 'aria-label': translate('models') },
|
|
217
|
+
text('order-help', translate('orderHelp')),
|
|
218
|
+
legacyLists ? text('legacy-lists', translate('legacyLists')) : null,
|
|
219
|
+
...['executors', 'experts'].map(group => element(OrderedModels, { key: group, group, rows: groups[group],
|
|
220
|
+
update: rows => change('modelGroups', { ...groups, [group]: rows }), models, catalog, allowed, translate })));
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function NumberField({ title, field, value, minimum, maximum, step = 1, onChange }) {
|
|
224
|
+
const id = useId();
|
|
225
|
+
return element('div', { className: 'submodel-field' }, element('label', { htmlFor: id }, title),
|
|
226
|
+
element('input', { id, type: 'number', inputMode: step === 1 ? 'numeric' : 'decimal',
|
|
227
|
+
'data-submodel-number': field, min: minimum, max: maximum, step, required: true,
|
|
228
|
+
value: value ?? '', onChange: event => onChange(event.target.value) }));
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function graceMilliseconds(seconds) {
|
|
232
|
+
const value = Number(seconds);
|
|
233
|
+
const milliseconds = Math.round(value * 1000);
|
|
234
|
+
return seconds !== '' && value === milliseconds / 1000 && milliseconds >= 1000 && milliseconds <= 600000
|
|
235
|
+
? milliseconds : seconds;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function MonitoringFields({ value, grouped, change, translate }) {
|
|
239
|
+
const modeId = useId();
|
|
240
|
+
const update = (patch) => change('watchdog', { ...value, ...patch });
|
|
241
|
+
const modes = { off: 'off', notify: 'notify', stop: 'stop', retry: 'retryMode' };
|
|
242
|
+
return element('section', { className: 'submodel-section', 'aria-label': translate('watchdog') },
|
|
243
|
+
element('h4', null, translate('watchdog')), text('usage', translate('usageHelp')),
|
|
244
|
+
element('div', { className: 'submodel-field' }, element('label', { htmlFor: modeId }, translate('mode')),
|
|
245
|
+
element('select', { id: modeId, value: value.mode, onChange: event => update({ mode: event.target.value }) },
|
|
246
|
+
...Object.entries(modes).map(([mode, label]) => element('option', { key: mode, value: mode }, translate(label))))),
|
|
247
|
+
value.mode === 'stop' ? text('manual', translate('manualStop')) : null,
|
|
248
|
+
value.mode === 'retry' ? text('retry', translate(grouped ? 'retryHelp' : 'legacyRetryHelp')) : null,
|
|
249
|
+
element('fieldset', null, element('legend', null, translate('tiers')),
|
|
250
|
+
element('div', { className: 'submodel-choices' }, ...['executor', 'expert'].map(tier => element('label', { key: tier },
|
|
251
|
+
element('input', { type: 'checkbox', checked: value.tiers.includes(tier),
|
|
252
|
+
disabled: value.tiers.length === 1 && value.tiers.includes(tier),
|
|
253
|
+
onChange: event => update({ tiers: event.target.checked ? [...value.tiers, tier] : value.tiers.filter(other => other !== tier) }) }),
|
|
254
|
+
translate(`${tier}Tier`))))),
|
|
255
|
+
element(NumberField, { field: 'usage', title: translate('warnTokens'), value: value.warnTokens, minimum: 1,
|
|
256
|
+
maximum: Number.MAX_SAFE_INTEGER, onChange: val => update({ warnTokens: val }) }),
|
|
257
|
+
element(NumberField, { field: 'wait', title: translate('graceSeconds'), minimum: 1, maximum: 600, step: 0.001,
|
|
258
|
+
value: typeof value.graceMs === 'number' ? value.graceMs / 1000 : value.graceMs,
|
|
259
|
+
onChange: val => update({ graceMs: graceMilliseconds(val) }) }),
|
|
260
|
+
element(NumberField, { field: 'switches', title: translate('maxRetries'), value: value.maxRetries, minimum: 0,
|
|
261
|
+
maximum: 2, onChange: val => update({ maxRetries: val }) }));
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function makeEditor({ form, authForm, mirror, generation, connectionChanged, getRemote }) {
|
|
265
|
+
const snapshotSource = sourceOf(form);
|
|
266
|
+
const authSource = sourceOf(authForm);
|
|
267
|
+
const mirrorSource = sourceOf(mirror);
|
|
268
|
+
const generationSource = sourceOf(generation);
|
|
269
|
+
return function Editor({ t: translate }) {
|
|
270
|
+
const saved = useSyncExternalStore(snapshotSource.listen, snapshotSource.read);
|
|
271
|
+
const authorization = useSyncExternalStore(authSource.listen, authSource.read);
|
|
272
|
+
const mirrorState = useSyncExternalStore(mirrorSource.listen, mirrorSource.read);
|
|
273
|
+
const epoch = useSyncExternalStore(generationSource.listen, generationSource.read);
|
|
274
|
+
const [catalogState, setCatalogState] = useState({ status: 'loading' });
|
|
275
|
+
const [catalogAttempt, setCatalogAttempt] = useState(0);
|
|
276
|
+
const [draft, setDraft] = useState(null);
|
|
277
|
+
const [feedback, setFeedback] = useState('');
|
|
278
|
+
const [saving, setSaving] = useState(false);
|
|
279
|
+
const active = useRef(false);
|
|
280
|
+
const busy = useRef(false);
|
|
281
|
+
useEffect(() => {
|
|
282
|
+
active.current = true;
|
|
283
|
+
return () => { active.current = false; };
|
|
284
|
+
}, []);
|
|
285
|
+
useEffect(() => {
|
|
286
|
+
if (!epoch || connectionChanged()) return undefined;
|
|
287
|
+
let cancelled = false;
|
|
288
|
+
const remote = getRemote();
|
|
289
|
+
const refresh = () => {
|
|
290
|
+
if (cancelled || generationSource.read() !== epoch || connectionChanged()) return;
|
|
291
|
+
setCatalogState({ status: 'loading' });
|
|
292
|
+
const accept = (result) => {
|
|
293
|
+
if (cancelled || generationSource.read() !== epoch || connectionChanged()) return;
|
|
294
|
+
setCatalogState(didLoad(result) ? { status: result.value.failures?.length ? 'partial' : 'ready', value: result.value }
|
|
295
|
+
: { status: 'error' });
|
|
296
|
+
};
|
|
297
|
+
Promise.resolve().then(() => remote.session.modelCatalog()).then(accept, () => accept(undefined));
|
|
298
|
+
};
|
|
299
|
+
const off = remote.$on?.('llm/adapters-updated', refresh);
|
|
300
|
+
refresh();
|
|
301
|
+
return () => {
|
|
302
|
+
cancelled = true;
|
|
303
|
+
off?.();
|
|
304
|
+
};
|
|
305
|
+
}, [epoch, catalogAttempt]);
|
|
306
|
+
|
|
307
|
+
const generationLost = connectionChanged() || (draft !== null && draft.epoch !== epoch);
|
|
308
|
+
const ready = isReady(saved);
|
|
309
|
+
const isStale = ready && draft !== null && saved.revision !== draft.revision;
|
|
310
|
+
const canEdit = ready && saved.writable && Boolean(epoch) && !generationLost && !mirrorState.error;
|
|
311
|
+
const settings = { ...saved.value, ...draft?.changes };
|
|
312
|
+
const models = directoryOf(catalogState.value);
|
|
313
|
+
const catalog = new Map(models.map(model => [keyOf(model), model]));
|
|
314
|
+
const allowed = isReady(authorization)
|
|
315
|
+
? new Set((authorization.value.enabled ? authorization.value.allowedModels ?? [] : []).map(keyOf)) : undefined;
|
|
316
|
+
const reload = () => globalThis.location.reload();
|
|
317
|
+
const reloadCatalog = () => setCatalogAttempt(previous => previous + 1);
|
|
318
|
+
const changed = draft !== null && Object.keys(draft.changes).length > 0;
|
|
319
|
+
|
|
320
|
+
function edit(field, value) {
|
|
321
|
+
if (!canEdit || busy.current || generationSource.read() !== epoch) return;
|
|
322
|
+
if (feedback !== 'conflict') setFeedback('');
|
|
323
|
+
setDraft(old => {
|
|
324
|
+
const base = old ?? { revision: saved.revision, epoch, source: saved.value, changes: {} };
|
|
325
|
+
const changes = { ...base.changes };
|
|
326
|
+
if (equal(value, base.source[field])) delete changes[field];
|
|
327
|
+
else changes[field] = structuredClone(value);
|
|
328
|
+
return Object.keys(changes).length > 0 ? { ...base, changes } : null;
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function review() {
|
|
333
|
+
const current = snapshotSource.read();
|
|
334
|
+
if (connectionChanged() || generationSource.read() !== draft?.epoch || !isReady(current) || !current.writable) return;
|
|
335
|
+
const changes = { ...draft.changes };
|
|
336
|
+
let overlap = false;
|
|
337
|
+
if (changes.modelGroups) {
|
|
338
|
+
const previous = importedGroups(draft.source);
|
|
339
|
+
const savedGroups = importedGroups(current.value);
|
|
340
|
+
const draftGroups = { ...changes.modelGroups };
|
|
341
|
+
for (const group of ['executors', 'experts']) {
|
|
342
|
+
if (equal(draftGroups[group], previous[group])) draftGroups[group] = savedGroups[group];
|
|
343
|
+
else if (!equal(savedGroups[group], previous[group]) && !equal(savedGroups[group], draftGroups[group])) overlap = true;
|
|
344
|
+
}
|
|
345
|
+
changes.modelGroups = draftGroups;
|
|
346
|
+
}
|
|
347
|
+
for (const field of fields) {
|
|
348
|
+
if (equal(changes[field], current.value[field])) delete changes[field];
|
|
349
|
+
else if (field === 'watchdog' && changes.watchdog && !equal(draft.source.watchdog, current.value.watchdog)) overlap = true;
|
|
350
|
+
}
|
|
351
|
+
const changed = Object.keys(changes).length > 0;
|
|
352
|
+
setDraft(changed ? { ...draft, changes, source: current.value, revision: current.revision } : null);
|
|
353
|
+
setFeedback(changed ? (overlap ? 'reviewOverlap' : 'review') : 'noChanges');
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
async function save(event) {
|
|
357
|
+
event.preventDefault();
|
|
358
|
+
if (!canEdit || !changed || busy.current || connectionChanged() || generationSource.read() !== draft.epoch) return;
|
|
359
|
+
const before = snapshotSource.read();
|
|
360
|
+
if (before.revision !== draft.revision) { setFeedback('conflict'); return; }
|
|
361
|
+
if (!isReady(before) || !before.writable) return;
|
|
362
|
+
const patch = structuredClone(draft.changes);
|
|
363
|
+
if (patch.watchdog) {
|
|
364
|
+
for (const [field, minimum, maximum] of [
|
|
365
|
+
['warnTokens', 1, Number.MAX_SAFE_INTEGER], ['graceMs', 1000, 600000], ['maxRetries', 0, 2],
|
|
366
|
+
]) {
|
|
367
|
+
const raw = patch.watchdog[field];
|
|
368
|
+
const number = field === 'graceMs' && typeof raw !== 'number' ? NaN : Number(raw);
|
|
369
|
+
if (raw === '' || !Number.isSafeInteger(number) || number < minimum || number > maximum) {
|
|
370
|
+
setFeedback('saveFailed');
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
patch.watchdog[field] = number;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
const operations = fields.filter(field => Object.hasOwn(patch, field))
|
|
377
|
+
.map(field => ({ op: 'set', path: [field], value: patch[field] }));
|
|
378
|
+
const currentConnection = () => active.current && !connectionChanged() && generationSource.read() === draft.epoch;
|
|
379
|
+
busy.current = true;
|
|
380
|
+
setSaving(true);
|
|
381
|
+
setFeedback('');
|
|
382
|
+
try {
|
|
383
|
+
const success = await form.mutate(operations, draft.revision);
|
|
384
|
+
if (!currentConnection()) return;
|
|
385
|
+
const after = snapshotSource.read();
|
|
386
|
+
if (success && isReady(after) && operations.every(op => equal(after.value[op.path[0]], op.value))) {
|
|
387
|
+
setDraft(null);
|
|
388
|
+
setFeedback('saved');
|
|
389
|
+
} else if (after.revision !== draft.revision) setFeedback('conflict');
|
|
390
|
+
else setFeedback(mirrorSource.read().error ? 'transport' : 'saveFailed');
|
|
391
|
+
} catch {
|
|
392
|
+
if (currentConnection()) setFeedback('transport');
|
|
393
|
+
} finally {
|
|
394
|
+
busy.current = false;
|
|
395
|
+
if (active.current) setSaving(false);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
const heading = element('h3', null, translate('title'));
|
|
400
|
+
const problem = generationLost ? 'reconnect' : !epoch && ready ? 'transport' : mirrorState.error ? 'loadFailed'
|
|
401
|
+
: saved.status === 'unavailable' ? 'unavailable' : !ready ? 'loading' : !saved.writable ? 'readOnly' : '';
|
|
402
|
+
const status = problem || (saving ? 'saving' : isStale ? 'conflict' : feedback || (changed ? 'pending' : ''));
|
|
403
|
+
const availableModels = catalogState.status === 'loading' || catalogState.status === 'error' ? [] : models;
|
|
404
|
+
return element('section', { className: 'submodel-settings', 'data-submodel-settings': '' }, element('style', null, style), heading,
|
|
405
|
+
ready ? element('form', { onSubmit: save, 'aria-busy': saving },
|
|
406
|
+
element('fieldset', { disabled: !canEdit || saving, className: 'submodel-models' },
|
|
407
|
+
text('allowed', translate('authorization')),
|
|
408
|
+
catalogState.status === 'loading' ? text('catalog', translate('directoryLoading')) : null,
|
|
409
|
+
catalogState.status === 'ready' && models.length === 0 ? text('catalog', translate('noModels')) : null,
|
|
410
|
+
catalogState.status === 'partial' || catalogState.status === 'error'
|
|
411
|
+
? element('div', { className: 'submodel-actions' }, text('catalog', translate('directoryFailed')), button(translate('retryCatalog'), reloadCatalog)) : null,
|
|
412
|
+
element(ModelFields, { settings, legacyLists: !saved.value.modelGroups?.executors &&
|
|
413
|
+
(saved.value.fallbacks?.length > 0 || saved.value.watchdog?.mode === 'retry'),
|
|
414
|
+
change: edit, models: availableModels, catalog, allowed, translate }),
|
|
415
|
+
element(MonitoringFields, { value: settings.watchdog, grouped: Boolean(settings.modelGroups?.executors), change: edit, translate })),
|
|
416
|
+
element('div', { className: 'submodel-actions' },
|
|
417
|
+
element('button', { type: 'submit', className: 'submodel-save', disabled: !canEdit || !changed || isStale || saving }, translate('save')),
|
|
418
|
+
changed ? button(translate('discard'), () => { setDraft(null); setFeedback(''); }, saving) : null,
|
|
419
|
+
isStale && canEdit ? button(translate('retain'), review, saving) : null)) : null,
|
|
420
|
+
element('p', { className: 'submodel-feedback submodel-muted', role: 'status' }, status ? translate(status) : ''),
|
|
421
|
+
problem === 'reconnect' || problem === 'loadFailed' || problem === 'transport'
|
|
422
|
+
? button(translate(problem === 'reconnect' ? 'reload' : 'retry'), reload, saving) : null);
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
return {
|
|
427
|
+
inject: ['slots', 'locale'],
|
|
428
|
+
apply(ctx) {
|
|
429
|
+
ctx.effect(() => ctx.locale.register(namespace, dictionaries));
|
|
430
|
+
const listeners = new Set();
|
|
431
|
+
let Editor;
|
|
432
|
+
const readEditor = () => Editor;
|
|
433
|
+
const subscribe = (listener) => {
|
|
434
|
+
listeners.add(listener);
|
|
435
|
+
return () => listeners.delete(listener);
|
|
436
|
+
};
|
|
437
|
+
const updateEditor = (component) => {
|
|
438
|
+
Editor = component;
|
|
439
|
+
for (const listener of listeners) listener();
|
|
440
|
+
};
|
|
441
|
+
ctx.inject(['configForms', 'connection', 'remote', 'remote.session'], (bound) => {
|
|
442
|
+
const forms = bound.configForms;
|
|
443
|
+
const { generation } = bound.connection;
|
|
444
|
+
let firstGeneration = generation.getSnapshot();
|
|
445
|
+
let retired = false;
|
|
446
|
+
const unwatch = generation.subscribe(() => {
|
|
447
|
+
const current = generation.getSnapshot();
|
|
448
|
+
if (firstGeneration === undefined) firstGeneration = current;
|
|
449
|
+
else if (current !== firstGeneration) retired = true;
|
|
450
|
+
});
|
|
451
|
+
updateEditor(makeEditor({
|
|
452
|
+
form: forms.get('submodel'), authForm: forms.get('subagent-model-selection-settings'),
|
|
453
|
+
mirror: forms.describe(), generation, connectionChanged: () => retired, getRemote: () => bound.remote,
|
|
454
|
+
}));
|
|
455
|
+
return () => {
|
|
456
|
+
retired = true;
|
|
457
|
+
unwatch();
|
|
458
|
+
updateEditor(undefined);
|
|
459
|
+
};
|
|
460
|
+
});
|
|
461
|
+
function Panel({ t: translate, view }) {
|
|
462
|
+
const Settings = useSyncExternalStore(subscribe, readEditor);
|
|
463
|
+
if (view !== 'page') return null;
|
|
464
|
+
return Settings ? element(Settings, { t: translate }) : element('section', {
|
|
465
|
+
className: 'submodel-settings', 'data-submodel-settings': '',
|
|
466
|
+
}, element('h3', null, translate('title')), element('p', { role: 'status' }, translate('unavailable')));
|
|
467
|
+
}
|
|
468
|
+
ctx.slots.inject('plugins.bundle.config', () => ctx.slots.register({
|
|
469
|
+
name: 'plugins.bundle.config', id: 'submodel-settings', key: 'dsh-submodel', locale: namespace,
|
|
470
|
+
}, Panel));
|
|
471
|
+
},
|
|
472
|
+
};
|
|
473
|
+
},
|
|
474
|
+
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# 派活模型设置 · Subagent model settings
|
|
2
|
+
|
|
3
|
+
分别给性价比模型和专家模型排序,写下什么任务适合用它。主模型可按用途选择起点,自动换模型时只向组内下一位尝试。到「子代理」设置单独授权要用的模型。
|
|
4
|
+
|
|
5
|
+
Order the cost-effective and expert models, and write a short purpose for each. The main model can pick a starting point; automatic switching moves to the next model in that group. Allow the models separately in Subagent settings.
|
package/lib/config.js
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import z from '@deepseek-ai/schemastery';
|
|
2
|
+
import { ROUTING_ORDER, routeKey } from './policy.js';
|
|
3
|
+
|
|
4
|
+
export const CONFIG_ENTRY = 'submodel';
|
|
5
|
+
export const SETUP_FIELDS = Object.freeze(['modelGroups', 'economyRoutes']);
|
|
6
|
+
export const WATCHDOG_DEFAULTS = Object.freeze({
|
|
7
|
+
mode: 'off', tiers: Object.freeze(['expert']), warnTokens: 100_000, graceMs: 60_000, maxRetries: 1,
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
/** The host projects and then serializes the form schema again. Keep runtime-only validation off the wire. */
|
|
11
|
+
function validatedLiveField(shape, defaults, validate) {
|
|
12
|
+
const form = shape.default(defaults).volatile();
|
|
13
|
+
const field = z.transform(shape, validate, true).default(defaults).volatile();
|
|
14
|
+
Object.defineProperty(field, 'toJSON', { value: form.toJSON.bind(form) });
|
|
15
|
+
return field;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const pair = z.object({
|
|
19
|
+
provider: z.string().pattern(/\S/u).required(),
|
|
20
|
+
model: z.string().pattern(/\S/u).required(),
|
|
21
|
+
}).required();
|
|
22
|
+
|
|
23
|
+
const fallbacks = validatedLiveField(z.array(z.object({
|
|
24
|
+
primary: pair,
|
|
25
|
+
alternatives: z.array(pair).required(),
|
|
26
|
+
}).required()), [], (rows) => {
|
|
27
|
+
const primaries = new Set();
|
|
28
|
+
for (const { primary, alternatives } of rows) {
|
|
29
|
+
const key = routeKey(primary);
|
|
30
|
+
if (primaries.has(key)) throw new Error('Each primary model can have only one fallback list.');
|
|
31
|
+
primaries.add(key);
|
|
32
|
+
const seen = new Set([key]);
|
|
33
|
+
for (const alternative of alternatives) {
|
|
34
|
+
const candidate = routeKey(alternative);
|
|
35
|
+
if (seen.has(candidate)) throw new Error('A fallback list cannot contain its primary model or a repeated model.');
|
|
36
|
+
seen.add(candidate);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return rows;
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// The explicit legacy value survives the host's two form serializations and
|
|
43
|
+
// distinguishes older settings from two deliberately empty ordered groups.
|
|
44
|
+
const modelRow = z.object({
|
|
45
|
+
provider: z.string().pattern(/^[^\p{Cc}]*[^\p{Cc}\s][^\p{Cc}]*$/u).required(),
|
|
46
|
+
model: z.string().pattern(/^[^\p{Cc}]*[^\p{Cc}\s][^\p{Cc}]*$/u).required(),
|
|
47
|
+
note: z.string().max(120).default(''),
|
|
48
|
+
reasoningEffort: z.string().default(''),
|
|
49
|
+
}).required();
|
|
50
|
+
const modelGroups = validatedLiveField(z.union(['legacy', z.object({
|
|
51
|
+
executors: z.array(modelRow).required(),
|
|
52
|
+
experts: z.array(modelRow).required(),
|
|
53
|
+
}).required()]), 'legacy', (groups) => {
|
|
54
|
+
if (groups === 'legacy') return groups;
|
|
55
|
+
for (const rows of [groups.executors, groups.experts]) {
|
|
56
|
+
if (new Set(rows.map(routeKey)).size !== rows.length) throw new Error('A model may appear only once in each group.');
|
|
57
|
+
}
|
|
58
|
+
return groups;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const watchdog = validatedLiveField(z.object({
|
|
62
|
+
mode: z.union(['off', 'notify', 'stop', 'retry']).default(WATCHDOG_DEFAULTS.mode),
|
|
63
|
+
tiers: z.array(z.union(['executor', 'expert']).required()).min(1).max(2).default(WATCHDOG_DEFAULTS.tiers),
|
|
64
|
+
warnTokens: z.number().min(1).max(Number.MAX_SAFE_INTEGER).step(1).default(WATCHDOG_DEFAULTS.warnTokens),
|
|
65
|
+
graceMs: z.number().min(1_000).max(600_000).step(1).default(WATCHDOG_DEFAULTS.graceMs),
|
|
66
|
+
maxRetries: z.number().min(0).max(2).step(1).default(WATCHDOG_DEFAULTS.maxRetries),
|
|
67
|
+
}), WATCHDOG_DEFAULTS, (value) => {
|
|
68
|
+
if (new Set(value.tiers).size !== value.tiers.length) throw new Error('Each monitored role must be unique.');
|
|
69
|
+
return value;
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
export const Config = z.object({
|
|
73
|
+
enabled: z.boolean().default(true),
|
|
74
|
+
preset: z.string().default('standard'),
|
|
75
|
+
teamFit: z.object({ enabled: z.boolean().default(false) }).default({ enabled: false }),
|
|
76
|
+
toolName: z.string().default('list_subagent_models'),
|
|
77
|
+
order: z.number().default(ROUTING_ORDER),
|
|
78
|
+
executor: z.object({
|
|
79
|
+
provider: z.string().default(''),
|
|
80
|
+
model: z.string().default(''),
|
|
81
|
+
reasoningEffort: z.string().default('max'),
|
|
82
|
+
}).default({ provider: '', model: '', reasoningEffort: 'max' }).volatile(),
|
|
83
|
+
experts: z.array(z.object({
|
|
84
|
+
label: z.string(),
|
|
85
|
+
provider: z.string(),
|
|
86
|
+
model: z.string(),
|
|
87
|
+
reasoningEffort: z.string().default('max'),
|
|
88
|
+
})).default([]).volatile(),
|
|
89
|
+
texts: z.object({
|
|
90
|
+
economize: z.string().default(''),
|
|
91
|
+
boss: z.string().default(''),
|
|
92
|
+
child: z.string().default(''),
|
|
93
|
+
}).default({ economize: '', boss: '', child: '' }),
|
|
94
|
+
guardNativeSubagent: z.boolean().default(true),
|
|
95
|
+
autoConfigure: z.boolean().default(true),
|
|
96
|
+
economyRoutes: z.array(z.object({
|
|
97
|
+
provider: z.string().default(''),
|
|
98
|
+
model: z.string().min(1),
|
|
99
|
+
})).default([]).volatile(),
|
|
100
|
+
fallbacks,
|
|
101
|
+
modelGroups,
|
|
102
|
+
watchdog,
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
/** Cordis uses references; direct callers can pass ordinary config values. */
|
|
106
|
+
export function readLive(config, field) {
|
|
107
|
+
const value = config?.[field];
|
|
108
|
+
return typeof value?.get === 'function' ? value.get() : value;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function readModelGroups(config) {
|
|
112
|
+
const groups = readLive(config, 'modelGroups');
|
|
113
|
+
return groups && typeof groups === 'object' && !Array.isArray(groups) &&
|
|
114
|
+
Array.isArray(groups.executors) && Array.isArray(groups.experts) ? groups : undefined;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function readExecutor(config, groups = readModelGroups(config)) {
|
|
118
|
+
const executor = groups ? groups.executors[0] : readLive(config, 'executor');
|
|
119
|
+
return {
|
|
120
|
+
provider: executor?.provider ?? '',
|
|
121
|
+
model: executor?.model ?? '',
|
|
122
|
+
reasoningEffort: executor?.reasoningEffort ?? (groups ? '' : 'max'),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function executorConfigured(config) {
|
|
127
|
+
const { provider, model } = readExecutor(config);
|
|
128
|
+
return provider !== '' && model !== '';
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function readWatchdog(config) {
|
|
132
|
+
return { ...WATCHDOG_DEFAULTS, ...readLive(config, 'watchdog') };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function freezeTree(value) {
|
|
136
|
+
if (value && typeof value === 'object') {
|
|
137
|
+
for (const child of Object.values(value)) freezeTree(child);
|
|
138
|
+
Object.freeze(value);
|
|
139
|
+
}
|
|
140
|
+
return value;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Body, guard and delegation use a single detached policy for the lifetime of a live Agent. */
|
|
144
|
+
export function routingSnapshot(config) {
|
|
145
|
+
const modelGroups = readModelGroups(config);
|
|
146
|
+
const experts = modelGroups?.experts ?? readLive(config, 'experts');
|
|
147
|
+
const economyRoutes = readLive(config, 'economyRoutes');
|
|
148
|
+
const snapshot = {
|
|
149
|
+
modelGroups,
|
|
150
|
+
executor: readExecutor(config, modelGroups),
|
|
151
|
+
experts: Array.isArray(experts) ? experts : [],
|
|
152
|
+
economyRoutes: Array.isArray(economyRoutes) ? economyRoutes.filter(row =>
|
|
153
|
+
row && typeof row.model === 'string' && row.model !== '',
|
|
154
|
+
).map(row => ({ provider: typeof row.provider === 'string' ? row.provider : '', model: row.model })) : [],
|
|
155
|
+
texts: config?.texts ?? {},
|
|
156
|
+
guardNativeSubagent: config?.guardNativeSubagent !== false,
|
|
157
|
+
};
|
|
158
|
+
return freezeTree(structuredClone(snapshot));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** One ordered mutation per namespace, common to a UI save and the setup tool. */
|
|
162
|
+
export function settingOps(fields, values) {
|
|
163
|
+
return fields.map(field => ({ op: 'set', path: [field], value: values[field] }));
|
|
164
|
+
}
|