dsh-subagent-default-model 2.0.2 → 2.0.7
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/CHANGELOG.md +114 -0
- package/README.en.md +14 -0
- package/README.md +14 -2
- package/lib/client.js +680 -150
- package/lib/index.js +50 -11
- package/package.json +4 -4
package/lib/client.js
CHANGED
|
@@ -21,6 +21,13 @@ window.__ModuleLoader__.load({
|
|
|
21
21
|
// ── GitHub 页面(「鼓励一下」链接目标) ──────────────────────────────
|
|
22
22
|
var DSM_GITHUB_URL = "https://github.com/dingminhua/dsh-subagent-default-model";
|
|
23
23
|
|
|
24
|
+
// ── 客户端构建标记(诊断用)──────────────────────────────────────────
|
|
25
|
+
// 出现在设置卡常显的 [diag] 行里。保存失败排查期间,它回答「页面到底
|
|
26
|
+
// 跑的是哪一个 client bundle」——宿主在启动时快照 bundle,页面可能仍
|
|
27
|
+
// 持有旧版本;一眼对出构建号即可排除/坐实这一点。每次改 client.js
|
|
28
|
+
// 排查时必须递增它。
|
|
29
|
+
var DSM_CLIENT_BUILD = "2026-09-26.6";
|
|
30
|
+
|
|
24
31
|
// ── plugin icon (LD brand logo, 64px) ────────────────────────────────
|
|
25
32
|
var DSM_ICON = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAXGUlEQVR4nH1bC7BdVXn+1tr7nHPvzb3JvUloSAQp0JHWoAMttKOCFrWU8irQSbCTQYG21IahnTJUUTsM0FJhZCzCSIcKImOpDkhrhQ5YC7ROB3lUBU3EyCuBFBIIedzcx3ntvTr/a621TwIns3PO3mfvddf/+v7v/9c6DvYKoYBz1cZNYfJpVBcNBm7dcIhj3TBM15VzqAE6XAWEGggVADroOl0byDW+PtRr9E732rl9r2PxOMNsrCogVE7PA0Kge4Lcz5/TGI6v00UaK+h98u4QUA9quIDg4Pe2i2LTsknc++mzZu9cv37VHNaFAveSJICj/9aFUNzrXHXSTwdnznl/Y+X9M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var SETTINGS_CSS = ".dsm-model-settings{display:flex;flex-direction:column;gap:14px;margin:0;padding:0}.dsm-model-settings-list{display:flex;flex-direction:column;gap:10px}.dsm-model-settings-route{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr) minmax(0,1fr) auto;gap:8px;align-items:end;padding:10px;border:1px solid var(--dsw-alias-border-l2,#36373b);border-radius:10px;background:var(--dsw-alias-bg-layer-3,#202126)}.dsm-model-settings-field{display:flex;flex-direction:column;gap:4px;min-width:0;font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary,#b8b8b8)}.dsm-model-settings-select{width:100%;max-width:220px;height:32px;padding:0 28px 0 10px;border:1px solid var(--dsw-alias-border-l2,#36373b);border-radius:8px;background:var(--dsw-alias-bg-layer-2,#232529);color:var(--dsw-alias-label-primary,#e6e6e6);font:inherit;font-size:13px;line-height:1.5}.dsm-model-settings-select:focus{outline:2px solid var(--dsw-alias-state-business-primary,#5686fe);outline-offset:1px}.dsm-model-settings-select:disabled{color:var(--dsw-alias-label-tertiary,#999);cursor:default}.dsm-model-settings-remove{height:32px;min-width:32px;border:1px solid var(--dsw-alias-border-l2,#36373b);border-radius:8px;background:transparent;color:var(--dsw-alias-label-secondary,#b8b8b8);cursor:pointer;font-size:16px;line-height:1}.dsm-model-settings-remove:hover{color:var(--dsw-alias-state-error-primary,#ef4444);background:var(--dsw-alias-interactive-bg-hover-danger,rgba(242,90,90,.15))}.dsm-model-settings-options{display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap}.dsm-model-settings-strategy{display:flex;align-items:center;gap:8px;white-space:nowrap;font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary,#b8b8b8)}.dsm-model-settings-strategy .dsm-model-settings-select{max-width:150px}.dsm-model-settings-failover{display:flex;align-items:center;gap:6px;font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary,#b8b8b8);cursor:pointer}.dsm-model-settings-failover input[type=checkbox]{cursor:pointer}.dsm-failover-hint{font-size:12px;line-height:18px;color:var(--dsw-alias-label-tertiary,#999);white-space:nowrap}.dsm-model-settings-footer{border-top:1px solid var(--dsw-alias-border-l2,#36373b);display:flex;align-items:center;justify-content:flex-end;gap:8px;padding:12px 0 4px}.dsm-model-settings-footer-left{display:flex;align-items:center;gap:10px;flex:1;min-width:0}.dsm-model-settings-footer-status{flex:1;min-width:0;color:var(--dsw-alias-label-secondary,#b8b8b8);font-size:12px;line-height:1.5}.dsm-model-settings-footer-error{flex:1;min-width:0;color:var(--dsw-alias-label-error,#ef4444);font-size:12px;line-height:1.5}.dsm-btn{appearance:none;font:inherit;cursor:pointer;border:1px solid transparent;border-radius:8px;padding:5px 14px;font-size:13px;line-height:1.5}.dsm-btn:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#5686fe);outline-offset:1px}.dsm-btn:disabled{opacity:.4;cursor:default}.dsm-btn-outline{border-color:var(--dsw-alias-border-l2);color:var(--dsw-alias-label-secondary);background:transparent;font-weight:500}.dsm-btn-outline:hover:not(:disabled){color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-dimmed);background:rgba(255,255,255,.04)}.dsm-btn-primary{background:var(--dsw-alias-label-primary);color:var(--dsw-alias-bg-layer-3)}.dsm-btn-primary:hover:not(:disabled){opacity:.9}.dsm-model-settings-hint{font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary,#b8b8b8)}.dsm-plugin-card{border:1px solid var(--dsw-alias-border-l2,#36373b);background:var(--dsw-alias-bg-layer-3,#202126);border-radius:12px;list-style:none;transition:border-color .16s,background .16s}.dsm-plugin-card:hover{border-color:var(--dsw-alias-label-dimmed,#777)}.dsm-plugin-card-open{background:var(--dsw-alias-bg-layer-2,#25262b);border-color:var(--dsw-alias-label-dimmed,#777)}.dsm-plugin-card-header{appearance:none;width:100%;font:inherit;color:inherit;text-align:left;cursor:pointer;background:transparent;border:0;border-radius:12px;align-items:center;gap:12px;padding:14px 16px;display:flex}.dsm-plugin-card-header:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#5686fe);outline-offset:-2px}.dsm-plugin-card-head{flex-direction:column;flex:1;gap:4px;min-width:0;display:flex}.dsm-plugin-card-title{color:var(--dsw-alias-label-primary,#e6e6e6);font-size:15px;font-weight:600;line-height:1.4}.dsm-plugin-card-description{color:var(--dsw-alias-label-tertiary,#999);font-size:13px;line-height:1.5}.dsm-plugin-card-chevron{color:var(--dsw-alias-label-tertiary,#999);flex:none;display:inline-flex;transition:transform .16s}.dsm-plugin-card-chevron-open{transform:rotate(180deg)}.dsm-plugin-card-caret{color:inherit;font-size:12px;line-height:1;display:inline-flex}.dsm-plugin-card-body{border-top:1px solid var(--dsw-alias-border-l2,#36373b);margin:0 16px;padding:0 0 8px}.dsm-plugin-card-body .dsm-model-settings{margin:0;padding:12px 0 0;background:transparent;border:0;border-radius:0}.dsm-plugin-card-body .dsm-model-settings-head{display:none}.dsm-plugin-card-icon{width:32px;height:32px;flex:none;border-radius:7px}.dsm-model-settings-cheer{display:inline-flex;align-items:center;gap:4px;flex:none;text-decoration:underline;text-underline-offset:2px;color:var(--dsw-alias-label-tertiary,#999);font-size:13px;line-height:1.5;transition:color .16s}.dsm-model-settings-cheer-star{font-size:12px;line-height:1;display:inline-flex}.dsm-model-settings-cheer:hover{color:var(--dsw-alias-label-primary,#e6e6e6)}.dsm-model-settings-cheer:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#5686fe);outline-offset:2px}.dsm-model-settings-warn{grid-column:1/-1;color:var(--dsw-alias-label-error,#ef4444);font-size:12px;line-height:18px}.dsm-model-settings-warn-list{display:flex;flex-direction:column;gap:4px;color:var(--dsw-alias-label-error,#ef4444);font-size:12px;line-height:18px}.dsm-notice-row{display:flex;flex-direction:column;gap:4px;margin:6px 0;font-size:12px}.dsm-notice-toggle{appearance:none;font:inherit;cursor:pointer;background:transparent;border:0;padding:2px 0;display:flex;align-items:center;gap:6px;color:var(--dsw-alias-label-tertiary,#9a9a9a);text-align:left;min-width:0}.dsm-notice-toggle:hover{color:var(--dsw-alias-label-secondary,#b8b8b8)}.dsm-notice-toggle:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#5686fe);outline-offset:1px;border-radius:3px}.dsm-notice-dot{flex:none;width:5px;height:5px;border-radius:50%;background:var(--dsw-alias-label-caption,#777)}.dsm-notice-label{flex:none;font-weight:500}.dsm-notice-summary{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--dsw-alias-label-secondary,#b8b8b8)}.dsm-notice-summary:before{content:'·';margin-right:6px;color:var(--dsw-alias-label-caption,#777)}.dsm-notice-body{margin:0;padding:8px 10px;border-left:2px solid var(--dsw-alias-border-l2,#36373b);background:var(--dsw-alias-bg-layer-1,#1b1b1d);color:var(--dsw-alias-label-secondary,#b8b8b8);font-size:12px;line-height:18px;white-space:pre-wrap;overflow-wrap:anywhere;max-height:420px;overflow:auto}";
|
|
@@ -77,9 +84,11 @@ window.__ModuleLoader__.load({
|
|
|
77
84
|
"row.saving": "保存中…",
|
|
78
85
|
"row.saved": "已保存",
|
|
79
86
|
"row.incomplete": "请为每个模型路由选择 Provider 和 Model。",
|
|
87
|
+
"row.catalogEmpty": "模型目录尚未就绪(正在等待网关返回供应商与模型)。稍候片刻;若长时间为空,请检查 Provider 插件是否已启用。",
|
|
80
88
|
"row.effortNoDeclaration": "该模型当前未声明任何推理强度;子代理会因 effort 不被支持而一个请求都发不出(清空此项或改选模型)。",
|
|
81
89
|
"row.effortNotDeclared": "该模型当前未声明「{effort}」推理强度;子代理会因此无法启动(改选其它强度或清空此项)。",
|
|
82
|
-
"row.saveFailed": "
|
|
90
|
+
"row.saveFailed": "保存失败({message}),请重试。",
|
|
91
|
+
"row.settingsUnavailable": "本机宿主未为此插件提供设置存储({message}),暂时无法保存;请确认插件已在当前 profile 中启用,然后重启 DSH。",
|
|
83
92
|
"row.toastSaved": "子代理默认模型设置已保存。",
|
|
84
93
|
"row.failoverEnabled": "连接失败时按队列与策略切换模型",
|
|
85
94
|
"row.failoverHint": "(需配置 ≥2 个 Provider,切换才会生效)。",
|
|
@@ -111,9 +120,11 @@ window.__ModuleLoader__.load({
|
|
|
111
120
|
"row.saving": "Saving…",
|
|
112
121
|
"row.saved": "Saved",
|
|
113
122
|
"row.incomplete": "Choose a provider and model for every route.",
|
|
123
|
+
"row.catalogEmpty": "The model catalog is not ready yet (waiting for the gateway to report providers and models). Give it a moment; if it stays empty, check whether the provider plugin is enabled.",
|
|
114
124
|
"row.effortNoDeclaration": "This model declares no reasoning efforts right now; subagents will fail to issue any request with the configured effort (clear it or pick another model).",
|
|
115
125
|
"row.effortNotDeclared": "This model does not declare the \"{effort}\" reasoning effort right now; subagents will fail to start (pick another effort or clear it).",
|
|
116
|
-
"row.saveFailed": "Could not save the setting. Try again.",
|
|
126
|
+
"row.saveFailed": "Could not save the setting ({message}). Try again.",
|
|
127
|
+
"row.settingsUnavailable": "This Host serves no settings store for the plugin ({message}), so saving is unavailable. Check that the plugin is enabled in the current profile, then restart DSH.",
|
|
117
128
|
"row.toastSaved": "Subagent default model settings saved.",
|
|
118
129
|
"row.failoverEnabled": "Switch models by queue and strategy on connection failure",
|
|
119
130
|
"row.failoverHint": "(requires at least 2 configured providers).",
|
|
@@ -126,56 +137,15 @@ window.__ModuleLoader__.load({
|
|
|
126
137
|
|
|
127
138
|
// ── helpers ──────────────────────────────────────────────────────────
|
|
128
139
|
// This plugin's DECLARED Loader entry id = `cordis.patch.yml` `insert.id`.
|
|
129
|
-
//
|
|
130
|
-
//
|
|
131
|
-
//
|
|
132
|
-
// served-namespace directory EXACTLY
|
|
133
|
-
// fails silently (`status: unavailable`, no error
|
|
134
|
-
//
|
|
140
|
+
// On 0.1.7 the settings namespace IS a Loader entry id, and the Desktop host
|
|
141
|
+
// mounts community bundles as `include:<name>` — so the served name is
|
|
142
|
+
// host-chosen and cannot be assumed here. `configForms.get()` matches the
|
|
143
|
+
// served-namespace directory EXACTLY: binding a namespace nothing serves
|
|
144
|
+
// fails silently (`status: unavailable`, no error, every write refused), so
|
|
145
|
+
// the served name is probed from the describe mirror on every change instead
|
|
146
|
+
// (see `servedNamespaceNow` in the `configForms` block).
|
|
135
147
|
var SUBAGENT_MODEL_SETTINGS_NS = "dsh-subagent-default-model";
|
|
136
148
|
|
|
137
|
-
/**
|
|
138
|
-
* Resolve the settings namespace the host actually serves for this plugin.
|
|
139
|
-
*
|
|
140
|
-
* Match order: the declared entry id exactly, then a `include:`-prefixed
|
|
141
|
-
* form of it, then the host-served namespace carrying the package name.
|
|
142
|
-
* The legacy section name (`subagent-default-model`, pre-0.1.7
|
|
143
|
-
* `settings.yaml` keying) is deliberately accepted last, so it can only win
|
|
144
|
-
* when it is genuinely the served namespace. Falls back to the declared id
|
|
145
|
-
* while the mirror is not ready.
|
|
146
|
-
*
|
|
147
|
-
* @param {object} forms - the `configForms` client service.
|
|
148
|
-
* @param {Set<string>} [servedNamespaces] - authoritative served-namespace set
|
|
149
|
-
* handed over by `configForms.whileServed(...)`. When present it is preferred
|
|
150
|
-
* over the mirror snapshot, because it is the very set that decided the
|
|
151
|
-
* registration was due — the mirror may still be mid-fold.
|
|
152
|
-
* @returns {string} the namespace to pass to `forms.get()`.
|
|
153
|
-
*/
|
|
154
|
-
function subagentEntryIdOf(forms, servedNamespaces) {
|
|
155
|
-
var pick = function (names) {
|
|
156
|
-
return names.find(function (ns) {
|
|
157
|
-
return ns === SUBAGENT_MODEL_SETTINGS_NS;
|
|
158
|
-
}) ?? names.find(function (ns) {
|
|
159
|
-
return ns === "include:" + SUBAGENT_MODEL_SETTINGS_NS;
|
|
160
|
-
}) ?? names.find(function (ns) {
|
|
161
|
-
return /subagent-default-model/i.test(ns || "");
|
|
162
|
-
});
|
|
163
|
-
};
|
|
164
|
-
try {
|
|
165
|
-
if (servedNamespaces && typeof servedNamespaces.has === "function") {
|
|
166
|
-
var fromServed = pick(Array.from(servedNamespaces));
|
|
167
|
-
if (typeof fromServed === "string" && fromServed !== "") return fromServed;
|
|
168
|
-
}
|
|
169
|
-
var view = forms.describe().getSnapshot().view;
|
|
170
|
-
var namespaces = ((view && view.namespaces) || []).map(function (entry) {
|
|
171
|
-
return entry && entry.ns;
|
|
172
|
-
});
|
|
173
|
-
var served = pick(namespaces);
|
|
174
|
-
if (typeof served === "string" && served !== "") return served;
|
|
175
|
-
} catch (_e) { /* mirror not ready: the declared id is still the right guess */ }
|
|
176
|
-
return SUBAGENT_MODEL_SETTINGS_NS;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
149
|
function normalizeDefaultModels(value) {
|
|
180
150
|
var result = [];
|
|
181
151
|
if (Array.isArray(value.models) && value.models.length > 0) {
|
|
@@ -263,16 +233,85 @@ window.__ModuleLoader__.load({
|
|
|
263
233
|
}
|
|
264
234
|
|
|
265
235
|
function persistDefaultModels(scope, value) {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
236
|
+
// Every `set()` answers whether the Host ACCEPTED that field, and the
|
|
237
|
+
// chain must stop at the first refusal. Ignoring the answers (which this
|
|
238
|
+
// used to do) turns a half-written section into a "successful" save: the
|
|
239
|
+
// caller sees the promise resolve, the card then compares the verdict
|
|
240
|
+
// against a section that only partially changed, and reports a message
|
|
241
|
+
// built from the SCOPE state instead of the real cause.
|
|
242
|
+
//
|
|
243
|
+
// A refusal (`false`) means the operation never reached the document: the
|
|
244
|
+
// namespace is unbound, the page resolved `persistence: "memory"`, or the
|
|
245
|
+
// Host rejected the write. The scope snapshot explains which, so carry it
|
|
246
|
+
// in the same `notApplied:` shape the successful-but-not-landed case uses
|
|
247
|
+
// — one actionable report, naming the field that was refused.
|
|
248
|
+
var fields = [
|
|
249
|
+
["provider", value.provider],
|
|
250
|
+
["model", value.model],
|
|
251
|
+
["models", value.models],
|
|
252
|
+
["strategy", value.strategy],
|
|
253
|
+
["failoverEnabled", value.failoverEnabled === false ? false : true],
|
|
254
|
+
["reasoningEffort", value.reasoningEffort || ""]
|
|
255
|
+
];
|
|
256
|
+
// ONE atomic mutation, when the bound controller offers it.
|
|
257
|
+
//
|
|
258
|
+
// This is the stronger fix, because the six operations are one logical
|
|
259
|
+
// save and only the atomic form keeps them one Host transaction. Written
|
|
260
|
+
// as six independent `set()` calls, each takes its OWN expectedRevision
|
|
261
|
+
// from the controller, and every accepted write makes the controller fold
|
|
262
|
+
// the new revision in. `configEditor.edit()` then reloads the entry, so
|
|
263
|
+
// the fiber identity (and therefore the revision) changes underneath the
|
|
264
|
+
// chain: a later field is refused with a revision conflict while the
|
|
265
|
+
// promise still resolves, the read-back shows the earlier fields only,
|
|
266
|
+
// and Save reports `notApplied:ready:writable=true` — accepted, writable,
|
|
267
|
+
// and mysteriously not applied. `mutate()` sends the whole set against one
|
|
268
|
+
// revision, so it either lands entirely or refuses once, actionably.
|
|
269
|
+
var snapshotPart = function () {
|
|
270
|
+
var snap = scope.getSnapshot();
|
|
271
|
+
return ":" + String(snap ? snap.status : "noScope")
|
|
272
|
+
+ ":writable=" + String(snap ? snap.writable : false)
|
|
273
|
+
+ ":rev=" + String(snap && snap.revision !== void 0 ? snap.revision : "?");
|
|
274
|
+
};
|
|
275
|
+
var refused = function (field, path) {
|
|
276
|
+
return new Error("notApplied" + snapshotPart() + ":refused=" + field + ":write=" + path);
|
|
277
|
+
};
|
|
278
|
+
// A refusal is usually a revision fence, and the controller has ALREADY
|
|
279
|
+
// recovered by then: `ConfigFormController.mutate()` answers `false` only
|
|
280
|
+
// after `recover()` reloaded Host state into the mirror. One immediate
|
|
281
|
+
// retry therefore carries the fresh revision and is expected to land;
|
|
282
|
+
// only a SECOND refusal is a real failure worth reporting.
|
|
283
|
+
var retryAfterRecovery = function (attempt, write) {
|
|
284
|
+
return Promise.resolve(write()).then(function (accepted) {
|
|
285
|
+
if (accepted !== false) return accepted;
|
|
286
|
+
if (attempt >= 2) return false;
|
|
287
|
+
var refreshed = typeof scope.refresh === "function" ? scope.refresh() : Promise.resolve();
|
|
288
|
+
return Promise.resolve(refreshed).catch(function () { /* refresh is best-effort */ }).then(function () {
|
|
289
|
+
return retryAfterRecovery(attempt + 1, write);
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
};
|
|
293
|
+
// Fallback for a controller without `mutate`: sequential, but stop at the
|
|
294
|
+
// first refusal so a partial write is never reported as a success.
|
|
295
|
+
var sequential = function () {
|
|
296
|
+
var chain = Promise.resolve(true);
|
|
297
|
+
fields.forEach(function (entry) {
|
|
298
|
+
chain = chain.then(function () {
|
|
299
|
+
return retryAfterRecovery(1, function () { return scope.set(entry[0], entry[1]); }).then(function (accepted) {
|
|
300
|
+
if (accepted === false) throw refused(entry[0], "sequential");
|
|
301
|
+
return accepted;
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
return chain.then(function () { return "sequential"; });
|
|
306
|
+
};
|
|
307
|
+
if (typeof scope.setMany !== "function") return sequential();
|
|
308
|
+
return retryAfterRecovery(1, function () { return scope.setMany(fields); }).then(function (accepted) {
|
|
309
|
+
// `undefined` means the scope had no atomic form to offer (unbound, or a
|
|
310
|
+
// controller without `mutate`). That is NOT a success: treating it as one
|
|
311
|
+
// would report a save that wrote nothing at all. Fall back instead.
|
|
312
|
+
if (accepted === void 0) return sequential();
|
|
313
|
+
if (accepted === false) throw refused("all", "atomic");
|
|
314
|
+
return "atomic";
|
|
276
315
|
});
|
|
277
316
|
}
|
|
278
317
|
|
|
@@ -291,11 +330,44 @@ window.__ModuleLoader__.load({
|
|
|
291
330
|
var snap = useSettingsScopeSnapshot(props.settingsScope);
|
|
292
331
|
var value = (snap && snap.status === "ready" && snap.value) || {};
|
|
293
332
|
var groupsState = React.useState([]);
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
333
|
+
// Seed from the SAVED form when one is held (the mirror may still serve
|
|
334
|
+
// the previous document after a save; observed-live the remounted card
|
|
335
|
+
// then showed the route the user had just deleted). The held form is the
|
|
336
|
+
// ROUTE shape (normalizeDefaultModels output); rebuild a full section
|
|
337
|
+
// from it instead of trusting the lagging mirror. Falls back to the
|
|
338
|
+
// mirror value when nothing is held — the normal, converged case.
|
|
339
|
+
var seedValue = (function () {
|
|
340
|
+
var held = typeof props.settingsScope.savedForm === "function" ? props.settingsScope.savedForm() : null;
|
|
341
|
+
if (held === null || held === void 0) return value;
|
|
342
|
+
try {
|
|
343
|
+
var routes = JSON.parse(held);
|
|
344
|
+
var seed = { ...(value || {}) };
|
|
345
|
+
seed.models = routes.map(function (route) {
|
|
346
|
+
if (route.provider === (value && value.provider) && !route.reasoningEffort) return route.model;
|
|
347
|
+
var entry = { provider: route.provider, model: route.model };
|
|
348
|
+
if (route.reasoningEffort) entry.reasoningEffort = route.reasoningEffort;
|
|
349
|
+
return entry;
|
|
350
|
+
});
|
|
351
|
+
var efforts = routes.map(function (route) { return route.reasoningEffort || ""; });
|
|
352
|
+
if (routes.length > 0 && efforts.every(function (e) { return e === efforts[0] && e !== ""; })) {
|
|
353
|
+
seed.reasoningEffort = efforts[0];
|
|
354
|
+
} else if (routes.length === 0) {
|
|
355
|
+
delete seed.reasoningEffort;
|
|
356
|
+
}
|
|
357
|
+
return seed;
|
|
358
|
+
} catch (_e) {
|
|
359
|
+
return value;
|
|
360
|
+
}
|
|
361
|
+
})();
|
|
362
|
+
var routesState = React.useState(normalizeDefaultModels(seedValue));
|
|
363
|
+
var strategyState = React.useState(seedValue.strategy === "random" ? "random" : "round-robin");
|
|
364
|
+
var failoverEnabledState = React.useState(seedValue.failoverEnabled !== false);
|
|
297
365
|
var savedState = React.useState(false);
|
|
298
|
-
|
|
366
|
+
// The failure REASON, not a boolean. A boolean was dead state here (written
|
|
367
|
+
// but never read), so a refused write produced no visible feedback at all —
|
|
368
|
+
// the button simply appeared to do nothing. The family cards all surface a
|
|
369
|
+
// message (`row.saveError` in workbuddy/trae); this now does the same.
|
|
370
|
+
var saveErrorState = React.useState(null);
|
|
299
371
|
var toastState = React.useState(null);
|
|
300
372
|
var toastSeq = React.useRef(0);
|
|
301
373
|
var dirtyState = React.useState(false);
|
|
@@ -309,11 +381,27 @@ window.__ModuleLoader__.load({
|
|
|
309
381
|
}, []);
|
|
310
382
|
React.useEffect(function () {
|
|
311
383
|
if (dirtyState[0] || busyState[0]) return;
|
|
384
|
+
// The last completed save lives on the SCOPE (plugin lifetime), not in
|
|
385
|
+
// this component: the card unmounts whenever the user leaves the
|
|
386
|
+
// Plugins page, and a value held only in component state would die with
|
|
387
|
+
// it — the remounted card would then re-seed from whatever the mirror
|
|
388
|
+
// answers, which observed-live can still be the PREVIOUS document long
|
|
389
|
+
// after the write landed. Holding it on the scope means the remounted
|
|
390
|
+
// card seeds from what was actually SAVED.
|
|
391
|
+
var saved = typeof props.settingsScope.savedForm === "function" ? props.settingsScope.savedForm() : null;
|
|
392
|
+
if (saved !== null) {
|
|
393
|
+
// A save is held: a mirror still serving the previous document must
|
|
394
|
+
// not overwrite the just-saved form (that is the resurrection). Only
|
|
395
|
+
// a mirror that agrees with the save — i.e. the Host's reload has
|
|
396
|
+
// actually propagated — may re-seed again.
|
|
397
|
+
if (JSON.stringify(normalizeDefaultModels(value)) !== saved) return;
|
|
398
|
+
if (typeof props.settingsScope.clearSavedForm === "function") props.settingsScope.clearSavedForm();
|
|
399
|
+
}
|
|
312
400
|
routesState[1](normalizeDefaultModels(value));
|
|
313
401
|
strategyState[1](value.strategy === "random" ? "random" : "round-robin");
|
|
314
402
|
failoverEnabledState[1](value.failoverEnabled !== false);
|
|
315
403
|
savedState[1](false);
|
|
316
|
-
saveErrorState[1](
|
|
404
|
+
saveErrorState[1](null);
|
|
317
405
|
}, [snap ? snap.revision : -1, dirtyState[0], busyState[0]]);
|
|
318
406
|
function updateRoute(index, field, nextValue) {
|
|
319
407
|
routesState[1](function (routes) {
|
|
@@ -329,7 +417,7 @@ window.__ModuleLoader__.load({
|
|
|
329
417
|
});
|
|
330
418
|
});
|
|
331
419
|
savedState[1](false);
|
|
332
|
-
saveErrorState[1](
|
|
420
|
+
saveErrorState[1](null);
|
|
333
421
|
dirtyState[1](true);
|
|
334
422
|
}
|
|
335
423
|
function addRoute() {
|
|
@@ -338,28 +426,133 @@ window.__ModuleLoader__.load({
|
|
|
338
426
|
return routes.concat({ provider: firstGroup ? firstGroup.id : "", model: "", reasoningEffort: "" });
|
|
339
427
|
});
|
|
340
428
|
savedState[1](false);
|
|
341
|
-
saveErrorState[1](
|
|
429
|
+
saveErrorState[1](null);
|
|
342
430
|
dirtyState[1](true);
|
|
343
431
|
}
|
|
344
432
|
function removeRoute(index) {
|
|
345
433
|
routesState[1](function (routes) { return routes.filter(function (_, routeIndex) { return routeIndex !== index; }); });
|
|
346
434
|
savedState[1](false);
|
|
347
|
-
saveErrorState[1](
|
|
435
|
+
saveErrorState[1](null);
|
|
348
436
|
dirtyState[1](true);
|
|
349
437
|
}
|
|
350
438
|
function save() {
|
|
351
|
-
|
|
439
|
+
// Attempt the write REGARDLESS of the scope's derived status.
|
|
440
|
+
//
|
|
441
|
+
// `ConfigFormController.mutate()` sends the operation straight to the
|
|
442
|
+
// Host (`remote.settings.mutate`); only `persistence === 'memory'` makes
|
|
443
|
+
// it refuse locally (`enqueue()`), and that case returns `false`, which
|
|
444
|
+
// the verification below already catches and reports. The derived
|
|
445
|
+
// `status`/`writable` come from the describe MIRROR (`derive()`), which is
|
|
446
|
+
// a separate, asynchronously-filled read path — gating a write on it is
|
|
447
|
+
// exactly the "Save can never be pressed" defect, merely relocated from
|
|
448
|
+
// the button into an error message (observed: a bare
|
|
449
|
+
// `settingsUnavailable` with the Host perfectly able to accept the write).
|
|
450
|
+
//
|
|
451
|
+
// So: try, then report what actually happened. That is what the family
|
|
452
|
+
// cards do — `trae`/`workbuddy` disable on `!dirty || saving` and let the
|
|
453
|
+
// write answer for itself.
|
|
454
|
+
if (busyState[0]) return;
|
|
352
455
|
var nextValue = serializeDefaultModels(value, routesState[0], strategyState[0], failoverEnabledState[0]);
|
|
353
456
|
savedState[1](false);
|
|
354
|
-
saveErrorState[1](
|
|
457
|
+
saveErrorState[1](null);
|
|
355
458
|
busyState[1](true);
|
|
459
|
+
// Which write path persistDefaultModels took ("atomic" | "sequential"),
|
|
460
|
+
// carried into every failure report so one paste is enough to tell the
|
|
461
|
+
// two apart in the field.
|
|
462
|
+
var writePath = "unknown";
|
|
463
|
+
// Compare the stored section against what was just written. A landed
|
|
464
|
+
// write is not immediately visible: `configEditor.edit()` re-creates the
|
|
465
|
+
// entry's fiber, and the describe mirror only learns the new document
|
|
466
|
+
// once that reload commits. So re-read through the scope (which forces a
|
|
467
|
+
// mirror load and re-derives), retrying a few times, and only then judge.
|
|
468
|
+
// Without the retry a perfectly accepted write is reported as
|
|
469
|
+
// `notApplied:ready:writable=true`.
|
|
470
|
+
var fieldDiff = function (acceptedValue) {
|
|
471
|
+
var diffs = [];
|
|
472
|
+
var note = function (field, got, exp) {
|
|
473
|
+
diffs.push(field + "[got=" + JSON.stringify(got) + " exp=" + JSON.stringify(exp) + "]");
|
|
474
|
+
};
|
|
475
|
+
if (acceptedValue.provider !== nextValue.provider) note("provider", acceptedValue.provider, nextValue.provider);
|
|
476
|
+
if (acceptedValue.model !== nextValue.model) note("model", acceptedValue.model, nextValue.model);
|
|
477
|
+
if (acceptedValue.strategy !== nextValue.strategy) note("strategy", acceptedValue.strategy, nextValue.strategy);
|
|
478
|
+
if ((acceptedValue.reasoningEffort || "") !== (nextValue.reasoningEffort || "")) note("reasoningEffort", acceptedValue.reasoningEffort, nextValue.reasoningEffort);
|
|
479
|
+
if ((acceptedValue.failoverEnabled === false ? false : true) !== nextValue.failoverEnabled) note("failoverEnabled", acceptedValue.failoverEnabled, nextValue.failoverEnabled);
|
|
480
|
+
if (JSON.stringify(acceptedValue.models || []) !== JSON.stringify(nextValue.models || [])) note("models", acceptedValue.models, nextValue.models);
|
|
481
|
+
return diffs;
|
|
482
|
+
};
|
|
483
|
+
var assertLanded = function (snap) {
|
|
484
|
+
var acceptedValue = (snap && snap.status === "ready" && snap.value) || {};
|
|
485
|
+
var diffs = fieldDiff(acceptedValue);
|
|
486
|
+
if (diffs.length === 0) return { landed: true, acceptedValue: acceptedValue };
|
|
487
|
+
return {
|
|
488
|
+
landed: false,
|
|
489
|
+
// Name the state that explains a write that did NOT land, so the
|
|
490
|
+
// report stays actionable instead of generic. The field-level diff
|
|
491
|
+
// and the mirror revision turn one paste of this message into
|
|
492
|
+
// enough evidence to tell "the Host refused it", "it landed but the
|
|
493
|
+
// read-back is stale", and "it landed in a different shape" apart.
|
|
494
|
+
reason: "notApplied:" + String(snap ? snap.status : "noScope")
|
|
495
|
+
+ ":writable=" + String(snap ? snap.writable : false)
|
|
496
|
+
+ ":rev=" + String(snap && snap.revision !== void 0 ? snap.revision : "?")
|
|
497
|
+
+ ":write=" + writePath
|
|
498
|
+
+ ":diff=" + diffs.join(";")
|
|
499
|
+
};
|
|
500
|
+
};
|
|
501
|
+
var READBACK_ATTEMPTS = 6;
|
|
502
|
+
var READBACK_DELAY_MS = 250;
|
|
503
|
+
var settleReadback = function (attempt) {
|
|
504
|
+
var scope = props.settingsScope;
|
|
505
|
+
var refreshed = scope && typeof scope.refresh === "function" ? scope.refresh() : Promise.resolve();
|
|
506
|
+
return Promise.resolve(refreshed).then(function () {
|
|
507
|
+
var verdict = assertLanded(scope.getSnapshot());
|
|
508
|
+
if (verdict.landed) return verdict;
|
|
509
|
+
if (attempt >= READBACK_ATTEMPTS) return verdict;
|
|
510
|
+
// A reload may still be committing. Wait, then re-read, bounded.
|
|
511
|
+
return new Promise(function (resolve) {
|
|
512
|
+
if (typeof setTimeout !== "function") { resolve(); return; }
|
|
513
|
+
setTimeout(resolve, READBACK_DELAY_MS);
|
|
514
|
+
}).then(function () { return settleReadback(attempt + 1); });
|
|
515
|
+
});
|
|
516
|
+
};
|
|
356
517
|
Promise.resolve().then(function () {
|
|
357
518
|
return props.write(nextValue);
|
|
358
|
-
}).then(function () {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
519
|
+
}).then(function (path) {
|
|
520
|
+
if (typeof path === "string" && path) writePath = path;
|
|
521
|
+
return settleReadback(1);
|
|
522
|
+
}).then(function (verdict) {
|
|
523
|
+
var acceptedValue;
|
|
524
|
+
var mirrorLagged = false;
|
|
525
|
+
if (verdict.landed) {
|
|
526
|
+
acceptedValue = verdict.acceptedValue;
|
|
527
|
+
} else {
|
|
528
|
+
// The write was ACCEPTED by the Host — `persistDefaultModels`
|
|
529
|
+
// resolved, and any refusal would have thrown with `:refused=`.
|
|
530
|
+
// An accepted write IS a landed write: `configEditor.edit()` only
|
|
531
|
+
// resolves after the profile patch is written AND the Loader
|
|
532
|
+
// reconciled, so a still-mismatching read-back can only mean the
|
|
533
|
+
// describe MIRROR is serving the previous document while the
|
|
534
|
+
// reload propagates through it. Reporting that as a failure is
|
|
535
|
+
// precisely the false `notApplied:ready:writable=true` this card
|
|
536
|
+
// became known for — observed live: the patch file held the new
|
|
537
|
+
// value while the read-back kept answering the old one.
|
|
538
|
+
//
|
|
539
|
+
// So take the DRAFT as the saved truth here, and HOLD it: the
|
|
540
|
+
// re-seed effect must not let the lagging mirror overwrite the
|
|
541
|
+
// form (that resurrects deleted routes), so the saved form is
|
|
542
|
+
// recorded in `lastSavedFormRef` and the poll below keeps
|
|
543
|
+
// refreshing the mirror until it agrees, then hands control back.
|
|
544
|
+
acceptedValue = nextValue;
|
|
545
|
+
mirrorLagged = true;
|
|
546
|
+
try {
|
|
547
|
+
console.warn("[dsh-subagent-default-model] write accepted; the read-back mirror is still serving the previous document:", verdict.reason);
|
|
548
|
+
} catch (_e) {}
|
|
549
|
+
}
|
|
550
|
+
// Hold the saved form ON THE SCOPE (plugin lifetime, survives the
|
|
551
|
+
// card unmounting when the user switches away): the re-seed effect
|
|
552
|
+
// only accepts a mirror that agrees with this from now on, and the
|
|
553
|
+
// poll below releases the hold once the mirror converges.
|
|
554
|
+
if (typeof props.settingsScope.setSavedForm === "function") {
|
|
555
|
+
props.settingsScope.setSavedForm(JSON.stringify(normalizeDefaultModels(acceptedValue)));
|
|
363
556
|
}
|
|
364
557
|
routesState[1](normalizeDefaultModels(acceptedValue));
|
|
365
558
|
strategyState[1](acceptedValue.strategy === "random" ? "random" : "round-robin");
|
|
@@ -367,11 +560,54 @@ window.__ModuleLoader__.load({
|
|
|
367
560
|
dirtyState[1](false);
|
|
368
561
|
busyState[1](false);
|
|
369
562
|
savedState[1](true);
|
|
563
|
+
saveErrorState[1](null);
|
|
370
564
|
toastSeq.current = toastSeq.current + 1;
|
|
371
565
|
toastState[1]({ seq: toastSeq.current, text: t("row.toastSaved") });
|
|
372
|
-
|
|
566
|
+
if (mirrorLagged) {
|
|
567
|
+
// Bounded background convergence: keep re-reading the mirror until
|
|
568
|
+
// it serves what the Host verifiably stored. Each load() drives the
|
|
569
|
+
// scope subscription, so when the mirror finally agrees, the held
|
|
570
|
+
// re-seed effect runs with the agreeing value (a no-op against the
|
|
571
|
+
// draft we already seeded) and clears the hold. If the mirror never
|
|
572
|
+
// catches up, the form simply keeps the saved truth — never the
|
|
573
|
+
// stale document it was saved from. The hold lives on the scope,
|
|
574
|
+
// so it survives the card unmounting mid-poll: the remounted card
|
|
575
|
+
// seeds from the saved truth, not the lagging mirror.
|
|
576
|
+
var POLL_ATTEMPTS = 20;
|
|
577
|
+
var POLL_DELAY_MS = 500;
|
|
578
|
+
var pollMirror = function (attempt) {
|
|
579
|
+
var scope = props.settingsScope;
|
|
580
|
+
var held = typeof scope.savedForm === "function" ? scope.savedForm() : null;
|
|
581
|
+
if (held === null || held === void 0) return; // already converged (or a newer save took over)
|
|
582
|
+
var refreshed = scope && typeof scope.refresh === "function" ? scope.refresh() : Promise.resolve();
|
|
583
|
+
Promise.resolve(refreshed).catch(function () {}).then(function () {
|
|
584
|
+
var snapNow = scope ? scope.getSnapshot() : void 0;
|
|
585
|
+
var stored = (snapNow && snapNow.status === "ready" && snapNow.value) || {};
|
|
586
|
+
if (JSON.stringify(normalizeDefaultModels(stored)) === held) {
|
|
587
|
+
// Converged: release the hold. The mirror-driven re-render
|
|
588
|
+
// now re-seeds from the agreed document — identical to the
|
|
589
|
+
// draft — and normal sync resumes.
|
|
590
|
+
if (typeof scope.clearSavedForm === "function") scope.clearSavedForm();
|
|
591
|
+
routesState[1](normalizeDefaultModels(stored));
|
|
592
|
+
strategyState[1](stored.strategy === "random" ? "random" : "round-robin");
|
|
593
|
+
failoverEnabledState[1](stored.failoverEnabled !== false);
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
if (attempt >= POLL_ATTEMPTS) {
|
|
597
|
+
try { console.warn("[dsh-subagent-default-model] the describe mirror never caught up with the accepted write; the form keeps the saved draft."); } catch (_e) {}
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
return new Promise(function (resolve) {
|
|
601
|
+
if (typeof setTimeout !== "function") { resolve(); return; }
|
|
602
|
+
setTimeout(resolve, POLL_DELAY_MS);
|
|
603
|
+
}).then(function () { return pollMirror(attempt + 1); });
|
|
604
|
+
});
|
|
605
|
+
};
|
|
606
|
+
pollMirror(1);
|
|
607
|
+
}
|
|
608
|
+
}).catch(function (error) {
|
|
373
609
|
busyState[1](false);
|
|
374
|
-
saveErrorState[1](
|
|
610
|
+
saveErrorState[1](error && error.message ? error.message : "writeRefused");
|
|
375
611
|
});
|
|
376
612
|
}
|
|
377
613
|
function discard() {
|
|
@@ -380,7 +616,7 @@ window.__ModuleLoader__.load({
|
|
|
380
616
|
failoverEnabledState[1](value.failoverEnabled !== false);
|
|
381
617
|
dirtyState[1](false);
|
|
382
618
|
savedState[1](false);
|
|
383
|
-
saveErrorState[1](
|
|
619
|
+
saveErrorState[1](null);
|
|
384
620
|
toastState[1](null);
|
|
385
621
|
}
|
|
386
622
|
var hasIncompleteRoute = routesState[0].some(function (route) { return !route.provider || !route.model; });
|
|
@@ -389,7 +625,18 @@ window.__ModuleLoader__.load({
|
|
|
389
625
|
var warning = checkEffortSupport(route, groupsState[0]);
|
|
390
626
|
if (warning !== null) effortWarnings.push({ index: index, key: warning.key, warning: warning });
|
|
391
627
|
});
|
|
392
|
-
|
|
628
|
+
// Save gate, aligned with the family cards (`trae` / `workbuddy` disable on
|
|
629
|
+
// `!dirty || saving` plus one content rule). Two scope gates used to sit
|
|
630
|
+
// here — `snap.status !== "ready"` and `snap.writable === false` — and they
|
|
631
|
+
// are exactly what made Save permanently unclickable: the settings scope is
|
|
632
|
+
// bound asynchronously from the describe mirror, so while the mirror has not
|
|
633
|
+
// answered (or the Host never serves this namespace) both conditions stay
|
|
634
|
+
// true forever, the button stays grey, and no message ever explains why.
|
|
635
|
+
// The family does not pre-gate on scope state: it lets the write happen and
|
|
636
|
+
// reports the refusal. `hasIncompleteRoute` stays, because a half-filled
|
|
637
|
+
// route genuinely has nothing valid to save — the family's equivalent of
|
|
638
|
+
// "no models enabled".
|
|
639
|
+
var saveDisabled = busyState[0] || !dirtyState[0] || hasIncompleteRoute;
|
|
393
640
|
var discardDisabled = !dirtyState[0] || busyState[0];
|
|
394
641
|
var routes = routesState[0].map(function (route, index) {
|
|
395
642
|
var group = null;
|
|
@@ -471,7 +718,36 @@ window.__ModuleLoader__.load({
|
|
|
471
718
|
}, t(effortWarning.key, effortWarning.params))
|
|
472
719
|
);
|
|
473
720
|
});
|
|
721
|
+
var diagnostics = typeof props.diagnostics === "function" ? props.diagnostics() : null;
|
|
722
|
+
var diagnosticText = "";
|
|
723
|
+
if (diagnostics) {
|
|
724
|
+
// Always rendered while the save failure is under triage: a ready and
|
|
725
|
+
// writable scope used to hide this row exactly when the interesting
|
|
726
|
+
// failures started. The `build` marker identifies WHICH client bundle is
|
|
727
|
+
// running (the page may be serving a stale one), and `rev` is the
|
|
728
|
+
// mirror revision the next save will be fenced against.
|
|
729
|
+
diagnosticText = "[diag " + DSM_CLIENT_BUILD + "] mirror=" + String(diagnostics.mirrorStatus)
|
|
730
|
+
+ " · view.ns=" + String(diagnostics.viewNamespaces)
|
|
731
|
+
+ " · bound=" + (diagnostics.bound === null ? "null" : diagnostics.bound)
|
|
732
|
+
+ " · candidates=[" + (diagnostics.candidates || []).join(", ") + "]"
|
|
733
|
+
+ " · scope=" + String(diagnostics.scopeStatus)
|
|
734
|
+
+ " · writable=" + String(diagnostics.writable)
|
|
735
|
+
+ " · rev=" + (diagnostics.revision === null || diagnostics.revision === void 0 ? "?" : String(diagnostics.revision));
|
|
736
|
+
}
|
|
474
737
|
return React.createElement("section", { className: "dsm-model-settings" },
|
|
738
|
+
diagnosticText ? React.createElement("div", {
|
|
739
|
+
className: "dsm-model-settings-hint",
|
|
740
|
+
"data-bindings-diag": diagnosticText
|
|
741
|
+
}, diagnosticText) : null,
|
|
742
|
+
// An empty catalog is the cause of "the model cannot be selected": the
|
|
743
|
+
// Provider select then offers only "inherit" and the Model select is
|
|
744
|
+
// disabled behind `!route.provider`. Say so instead of showing a select
|
|
745
|
+
// with nothing in it.
|
|
746
|
+
groupsState[0].length === 0 ? React.createElement("div", {
|
|
747
|
+
className: "dsm-model-settings-hint",
|
|
748
|
+
role: "status",
|
|
749
|
+
"data-catalog-empty": "1"
|
|
750
|
+
}, t("row.catalogEmpty")) : null,
|
|
475
751
|
routes.length ? React.createElement("div", { className: "dsm-model-settings-list" }, routes) : React.createElement("div", { className: "dsm-model-settings-hint" }, t("row.empty")),
|
|
476
752
|
React.createElement("div", { className: "dsm-model-settings-options" },
|
|
477
753
|
React.createElement("button", { type: "button", className: "dsm-btn dsm-btn-outline", onClick: addRoute }, t("row.add")),
|
|
@@ -480,7 +756,7 @@ window.__ModuleLoader__.load({
|
|
|
480
756
|
React.createElement("select", {
|
|
481
757
|
className: "dsm-model-settings-select",
|
|
482
758
|
value: strategyState[0],
|
|
483
|
-
onChange: function (event) { strategyState[1](event.target.value); savedState[1](false); saveErrorState[1](
|
|
759
|
+
onChange: function (event) { strategyState[1](event.target.value); savedState[1](false); saveErrorState[1](null); dirtyState[1](true); }
|
|
484
760
|
},
|
|
485
761
|
React.createElement("option", { value: "round-robin" }, t("row.roundRobin")),
|
|
486
762
|
React.createElement("option", { value: "random" }, t("row.random"))
|
|
@@ -491,7 +767,7 @@ window.__ModuleLoader__.load({
|
|
|
491
767
|
React.createElement("input", {
|
|
492
768
|
type: "checkbox",
|
|
493
769
|
checked: failoverEnabledState[0],
|
|
494
|
-
onChange: function (event) { failoverEnabledState[1](event.target.checked); savedState[1](false); saveErrorState[1](
|
|
770
|
+
onChange: function (event) { failoverEnabledState[1](event.target.checked); savedState[1](false); saveErrorState[1](null); dirtyState[1](true); }
|
|
495
771
|
}),
|
|
496
772
|
React.createElement("span", null, t("row.failoverEnabled")),
|
|
497
773
|
React.createElement("span", { className: "dsm-failover-hint" }, t("row.failoverHint"))
|
|
@@ -504,6 +780,25 @@ window.__ModuleLoader__.load({
|
|
|
504
780
|
}, effortWarnings.map(function (entry) {
|
|
505
781
|
return React.createElement("div", { key: entry.key + ":" + entry.index }, t(entry.warning.key, entry.warning.params));
|
|
506
782
|
})),
|
|
783
|
+
// Save outcome. The success half was already surfaced as a toast; the
|
|
784
|
+
// FAILURE half used to be written to state nobody rendered, so a refused
|
|
785
|
+
// write looked like a dead button. The value is the write's own message:
|
|
786
|
+
// either a transport/refusal error, or `notApplied:<scopeStatus>:writable=…`
|
|
787
|
+
// a write that was accepted but the stored document did not change — the
|
|
788
|
+
// latter names the exact scope state, which is what makes the report
|
|
789
|
+
// actionable rather than a generic refusal.
|
|
790
|
+
saveErrorState[0] ? React.createElement("div", {
|
|
791
|
+
className: "dsm-model-settings-footer-error",
|
|
792
|
+
role: "alert",
|
|
793
|
+
"data-settings-save-error": String(saveErrorState[0])
|
|
794
|
+
}, String(saveErrorState[0]).indexOf("notApplied:") === 0
|
|
795
|
+
? t("row.settingsUnavailable", { message: String(saveErrorState[0]) })
|
|
796
|
+
: t("row.saveFailed", { message: String(saveErrorState[0]) })) : null,
|
|
797
|
+
savedState[0] ? React.createElement("div", {
|
|
798
|
+
className: "dsm-model-settings-footer-status",
|
|
799
|
+
role: "status",
|
|
800
|
+
"data-settings-save-status": "saved"
|
|
801
|
+
}, t("row.saved")) : null,
|
|
507
802
|
React.createElement("div", { className: "dsm-model-settings-footer" },
|
|
508
803
|
React.createElement("div", { className: "dsm-model-settings-footer-left" },
|
|
509
804
|
React.createElement("a", {
|
|
@@ -560,7 +855,7 @@ window.__ModuleLoader__.load({
|
|
|
560
855
|
|
|
561
856
|
// ── 对话流注入行的渲染器(自有节点 kind)─────────────────────────────
|
|
562
857
|
//
|
|
563
|
-
// 宿主按 `entryKey = node.kind`
|
|
858
|
+
// 宿主按 `entryKey = node.kind` 在 `conversation.chat.node` 槽位**运行时分派**
|
|
564
859
|
// 渲染器(`ChatNodeSeat` 传 `entryKey: routedNode.kind`)。该分派是 keyed 槽位:
|
|
565
860
|
// 没有占用者的 kind 走 `ChatNodeSeat` 传入的 `fallback`——一个 `JsonBlock`
|
|
566
861
|
// (标签 "unknown surface" + 节点数据原样 JSON)。所以只改 kind 而不注册渲染器
|
|
@@ -659,14 +954,67 @@ window.__ModuleLoader__.load({
|
|
|
659
954
|
// we stay soft-injected (a missing gateway must not withhold the card)
|
|
660
955
|
// and re-probe instead.
|
|
661
956
|
var remoteRoot = typeof ctx.get === "function" ? ctx.get("remote") : undefined;
|
|
662
|
-
|
|
957
|
+
|
|
958
|
+
// Bounded re-probe budget. Spaced in a browser so a late `remote.$mount()`
|
|
959
|
+
// is picked up; `sleep` degrades to a no-op where `setTimeout` is absent
|
|
960
|
+
// (the Node test sandbox), so the retry PATH stays covered without real
|
|
961
|
+
// waiting.
|
|
962
|
+
var CATALOG_RETRY_ATTEMPTS = 4;
|
|
963
|
+
var CATALOG_RETRY_DELAY_MS = 250;
|
|
964
|
+
var sleep = function (ms) {
|
|
965
|
+
return new Promise(function (resolve) {
|
|
966
|
+
if (typeof setTimeout !== "function") { resolve(); return; }
|
|
967
|
+
setTimeout(resolve, ms);
|
|
968
|
+
});
|
|
969
|
+
};
|
|
970
|
+
|
|
971
|
+
/** One probe. `null` means "not answerable yet" — the retryable case. */
|
|
972
|
+
var loadCatalogOnce = function () {
|
|
663
973
|
var sessionRemote = ctx.get ? ctx.get("remote.session") : undefined;
|
|
664
974
|
if (!sessionRemote) sessionRemote = remoteRoot && remoteRoot.session;
|
|
665
|
-
if (!sessionRemote || typeof sessionRemote.modelCatalog !== "function") return Promise.resolve(
|
|
975
|
+
if (!sessionRemote || typeof sessionRemote.modelCatalog !== "function") return Promise.resolve(null);
|
|
666
976
|
return sessionRemote.modelCatalog().then(function (response) {
|
|
667
|
-
if (!response || !response.ok) return
|
|
977
|
+
if (!response || !response.ok) return null;
|
|
668
978
|
return (response.value && response.value.groups) || [];
|
|
669
|
-
}).catch(function () { return
|
|
979
|
+
}).catch(function () { return null; });
|
|
980
|
+
};
|
|
981
|
+
|
|
982
|
+
/**
|
|
983
|
+
* Load the model catalog, re-probing a BOUNDED number of times while the
|
|
984
|
+
* answer is still empty.
|
|
985
|
+
*
|
|
986
|
+
* A single probe is not enough, and the failure it produces is not
|
|
987
|
+
* cosmetic: `SubagentModelRow` reads this catalog to populate the
|
|
988
|
+
* Provider/Model selects, and `addRoute()` seeds a new route from
|
|
989
|
+
* `groups[0].id`. With an empty catalog `addRoute()` writes
|
|
990
|
+
* `provider: ""`, so the Provider select offers ONLY the "inherit"
|
|
991
|
+
* option, the Model select is disabled behind `!route.provider`, and
|
|
992
|
+
* `hasIncompleteRoute` then keeps Save permanently disabled. The report
|
|
993
|
+
* is "the model cannot be selected at all".
|
|
994
|
+
*
|
|
995
|
+
* The window is real: `remote.session` is mounted by an asynchronous
|
|
996
|
+
* `remote.$mount()`, and this plugin deliberately soft-probes it (so a
|
|
997
|
+
* host without the gateway still shows the card) instead of declaring
|
|
998
|
+
* `inject: ['remote','remote.session']` the way the official
|
|
999
|
+
* `ui-settings-subagent` card does. Declaring it is what makes the
|
|
1000
|
+
* official card wait; soft-probing without a re-probe just reports the
|
|
1001
|
+
* moment the probe happened. Re-probing closes that gap on both sides.
|
|
1002
|
+
*
|
|
1003
|
+
* Stops early on the first non-empty answer, so the common path is one
|
|
1004
|
+
* round trip; an empty catalog after the full budget is returned as-is
|
|
1005
|
+
* (a host that genuinely has no providers must not spin).
|
|
1006
|
+
*/
|
|
1007
|
+
var loadCatalog = function () {
|
|
1008
|
+
var attempt = 0;
|
|
1009
|
+
var step = function () {
|
|
1010
|
+
return loadCatalogOnce().then(function (groups) {
|
|
1011
|
+
if (groups !== null && groups.length > 0) return groups;
|
|
1012
|
+
attempt = attempt + 1;
|
|
1013
|
+
if (attempt >= CATALOG_RETRY_ATTEMPTS) return groups === null ? [] : groups;
|
|
1014
|
+
return sleep(CATALOG_RETRY_DELAY_MS).then(step);
|
|
1015
|
+
});
|
|
1016
|
+
};
|
|
1017
|
+
return step();
|
|
670
1018
|
};
|
|
671
1019
|
|
|
672
1020
|
// Register locale for this component.
|
|
@@ -814,21 +1162,25 @@ window.__ModuleLoader__.load({
|
|
|
814
1162
|
}, "dsh-subagent-default-model: chat notice row");
|
|
815
1163
|
}
|
|
816
1164
|
|
|
817
|
-
//
|
|
818
|
-
//
|
|
819
|
-
//
|
|
820
|
-
//
|
|
821
|
-
//
|
|
822
|
-
//
|
|
823
|
-
//
|
|
824
|
-
|
|
1165
|
+
// The card's settings scope. The `configForms` block below assigns a
|
|
1166
|
+
// FORWARDING scope here: the reference stays stable while its target
|
|
1167
|
+
// controller re-binds underneath, so the card never needs re-registering
|
|
1168
|
+
// (see that block for why pinning one controller is the "card shows but
|
|
1169
|
+
// will not save" failure).
|
|
1170
|
+
//
|
|
1171
|
+
// `runtimeDiagnostics` is filled by the same block and surfaces the
|
|
1172
|
+
// live binding state inside the card, so a host whose mirror never
|
|
1173
|
+
// answers shows WHY instead of a silently grey Save button.
|
|
1174
|
+
var settingsScope = null;
|
|
1175
|
+
var runtimeDiagnostics = function () { return null; };
|
|
825
1176
|
var subagentRowInjected = function () {
|
|
826
1177
|
return {
|
|
827
|
-
settingsScope:
|
|
1178
|
+
settingsScope: settingsScope,
|
|
828
1179
|
loadCatalog: loadCatalog,
|
|
829
1180
|
write: function (value) {
|
|
830
|
-
return persistDefaultModels(
|
|
831
|
-
}
|
|
1181
|
+
return persistDefaultModels(settingsScope, value);
|
|
1182
|
+
},
|
|
1183
|
+
diagnostics: runtimeDiagnostics
|
|
832
1184
|
};
|
|
833
1185
|
};
|
|
834
1186
|
|
|
@@ -836,70 +1188,248 @@ window.__ModuleLoader__.load({
|
|
|
836
1188
|
// card simply stays absent when the service is unavailable, instead of
|
|
837
1189
|
// blocking the whole client plugin.
|
|
838
1190
|
//
|
|
839
|
-
//
|
|
840
|
-
//
|
|
841
|
-
//
|
|
842
|
-
//
|
|
843
|
-
// (`dsh-subagent-default-model`
|
|
844
|
-
//
|
|
845
|
-
//
|
|
846
|
-
//
|
|
847
|
-
//
|
|
848
|
-
//
|
|
849
|
-
//
|
|
1191
|
+
// The scope is a FORWARDING scope, following `dsh-connect-trae` — the local
|
|
1192
|
+
// sibling running against this same Desktop host. The describe mirror
|
|
1193
|
+
// answers ASYNCHRONOUSLY relative to `apply()`, and the Host may serve this
|
|
1194
|
+
// bundle under a name that does not exist yet at boot
|
|
1195
|
+
// (`include:dsh-subagent-default-model` is exactly such an entry). Binding
|
|
1196
|
+
// ONE controller and keeping it is the observed failure: the controller is
|
|
1197
|
+
// pinned to its namespace forever, so a card bound to the declared id
|
|
1198
|
+
// writes to a namespace the Host does not serve — every write is REFUSED
|
|
1199
|
+
// (`No configurable plugin entry "…"`) while the controls stay enabled,
|
|
1200
|
+
// because the mirror reports a global `writable` even for a missing
|
|
1201
|
+
// namespace. That is the "card appears but will not save" report.
|
|
850
1202
|
//
|
|
851
|
-
//
|
|
852
|
-
//
|
|
853
|
-
// namespace
|
|
854
|
-
//
|
|
855
|
-
// goes away. Every official consumer registers this way.
|
|
1203
|
+
// The scope therefore forwards every read/write to the CURRENT controller
|
|
1204
|
+
// and re-binds whenever the mirror changes; before the mirror lists the
|
|
1205
|
+
// namespace it reports `status: 'unavailable', writable: false`, so the card
|
|
1206
|
+
// is read-only rather than offering controls that cannot save.
|
|
856
1207
|
ctx.inject(["configForms"], function (formsCtx) {
|
|
857
1208
|
var forms = formsCtx.configForms;
|
|
858
1209
|
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
1210
|
+
// Namespace the mirror ALREADY lists as served, or null while the mirror
|
|
1211
|
+
// has not answered yet. Only a namespace that really exists may be bound:
|
|
1212
|
+
// guessing is what produces the refused writes described above. The
|
|
1213
|
+
// probe also records EVERY candidate it saw, for the in-card diagnostics.
|
|
1214
|
+
var seenCandidates = [];
|
|
1215
|
+
var servedNamespaceNow = function () {
|
|
1216
|
+
seenCandidates = [];
|
|
1217
|
+
try {
|
|
1218
|
+
var view = forms.describe().getSnapshot().view;
|
|
1219
|
+
var namespaces = ((view && view.namespaces) || []).map(function (entry) {
|
|
1220
|
+
return entry && entry.ns;
|
|
1221
|
+
});
|
|
1222
|
+
for (var i = 0; i < namespaces.length; i++) {
|
|
1223
|
+
if (typeof namespaces[i] === "string" && /subagent-default-model/i.test(namespaces[i])) {
|
|
1224
|
+
seenCandidates.push(namespaces[i]);
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
return namespaces.find(function (ns) {
|
|
1228
|
+
return ns === SUBAGENT_MODEL_SETTINGS_NS;
|
|
1229
|
+
}) ?? namespaces.find(function (ns) {
|
|
1230
|
+
return ns === "include:" + SUBAGENT_MODEL_SETTINGS_NS;
|
|
1231
|
+
}) ?? namespaces.find(function (ns) {
|
|
1232
|
+
return /subagent-default-model/i.test(ns || "");
|
|
1233
|
+
}) ?? null;
|
|
1234
|
+
} catch (_e) {
|
|
1235
|
+
return null;
|
|
1236
|
+
}
|
|
1237
|
+
};
|
|
1238
|
+
|
|
1239
|
+
var lastBoundNamespace = null;
|
|
1240
|
+
var lastMirrorStatus = "unknown";
|
|
1241
|
+
var lastSeenViewNamespaces = 0;
|
|
1242
|
+
// The last SAVE this plugin completed, serialized. It lives HERE — on
|
|
1243
|
+
// the scope, i.e. for the plugin's lifetime — rather than in the card's
|
|
1244
|
+
// state, because the card is UNMOUNTED whenever the user switches away
|
|
1245
|
+
// from the Plugins page. A ref dies with the unmount, and the remounted
|
|
1246
|
+
// card re-seeds itself from whatever the mirror answers then — observed
|
|
1247
|
+
// live: the mirror can still serve the PREVIOUS document long after the
|
|
1248
|
+
// write verifiably landed, so the remounted card showed the route the
|
|
1249
|
+
// user had just deleted. Holding the save here lets the remounted card
|
|
1250
|
+
// seed from what was actually SAVED, and the convergence poll release
|
|
1251
|
+
// the hold once the mirror agrees.
|
|
1252
|
+
var lastSavedForm = null;
|
|
1253
|
+
settingsScope = (function () {
|
|
1254
|
+
var current;
|
|
1255
|
+
var currentOff;
|
|
1256
|
+
// Bounded mirror (re)loads. ONE forced read is not enough: the mirror
|
|
1257
|
+
// reads through the ASYNCHRONOUS `remote.settings` namespace, so a read
|
|
1258
|
+
// issued before that mount settles comes back empty — and the store's
|
|
1259
|
+
// own `ensure()` only reads from `idle`, so it will not retry for us.
|
|
1260
|
+
// A one-shot attempt therefore leaves the scope unbound FOREVER: the
|
|
1261
|
+
// card still renders (it registers unconditionally), but every Save
|
|
1262
|
+
// reports that the Host serves no settings store. That is the reported
|
|
1263
|
+
// failure, and re-reading until the namespace appears is the fix.
|
|
1264
|
+
var MIRROR_LOAD_ATTEMPTS = 6;
|
|
1265
|
+
var MIRROR_LOAD_DELAY_MS = 300;
|
|
1266
|
+
var loadAttempts = 0;
|
|
1267
|
+
var listeners = new Set();
|
|
1268
|
+
var notify = function () {
|
|
1269
|
+
Array.from(listeners).forEach(function (listener) { listener(); });
|
|
1270
|
+
};
|
|
1271
|
+
var scope = {
|
|
1272
|
+
getSnapshot: function () {
|
|
1273
|
+
return current ? current.getSnapshot() : { status: "unavailable", value: void 0, writable: false };
|
|
1274
|
+
},
|
|
1275
|
+
subscribe: function (listener) {
|
|
1276
|
+
listeners.add(listener);
|
|
1277
|
+
return function () { listeners.delete(listener); };
|
|
1278
|
+
},
|
|
1279
|
+
set: function (field, value) {
|
|
1280
|
+
return current ? current.set(field, value) : Promise.resolve(false);
|
|
1281
|
+
},
|
|
1282
|
+
// One atomic mutation for a whole save, when the controller exposes
|
|
1283
|
+
// `mutate`. Six independent `set()` calls are six Host transactions,
|
|
1284
|
+
// each taking its own expectedRevision; a reload between them makes a
|
|
1285
|
+
// later field fail a revision check while the promise still resolves,
|
|
1286
|
+
// which the card then reports as `notApplied:ready:writable=true`.
|
|
1287
|
+
// `mutate(namespace, ops, revision)` is the controller's own
|
|
1288
|
+
// path-addressed, single-revision write, so the save either lands
|
|
1289
|
+
// entirely or refuses once. Returns whether the Host accepted it,
|
|
1290
|
+
// matching the `set()` contract; `undefined` means this controller
|
|
1291
|
+
// has no atomic form and the caller must fall back.
|
|
1292
|
+
setMany: function (pairs) {
|
|
1293
|
+
if (!current || typeof current.mutate !== "function") return Promise.resolve(void 0);
|
|
1294
|
+
var ops = pairs.map(function (pair) {
|
|
1295
|
+
return { op: "set", path: [pair[0]], value: pair[1] };
|
|
1296
|
+
});
|
|
1297
|
+
return Promise.resolve(current.mutate(ops));
|
|
1298
|
+
},
|
|
1299
|
+
// Force one mirror re-read, then re-derive the bound controller.
|
|
1300
|
+
//
|
|
1301
|
+
// A write needs this: `configEditor.edit()` persists the profile
|
|
1302
|
+
// patch and the Loader RE-CREATES the entry's fiber, so between the
|
|
1303
|
+
// write answering and the mirror seeing the new document there is a
|
|
1304
|
+
// window where a read-back still returns the PREVIOUS value. The
|
|
1305
|
+
// card's Save verification reads exactly that snapshot, so without
|
|
1306
|
+
// a forced re-read a landed write is reported as
|
|
1307
|
+
// `notApplied:ready:writable=true` — accepted by the Host, invisible
|
|
1308
|
+
// to the client. `derive()` cannot cover it either: it is driven by
|
|
1309
|
+
// mirror CHANGES, and a reload that changes nothing observable emits
|
|
1310
|
+
// none.
|
|
1311
|
+
//
|
|
1312
|
+
// The bounded attempt counter is deliberately NOT consulted here:
|
|
1313
|
+
// this is an explicit, caller-driven refresh (one per read-back
|
|
1314
|
+
// attempt), not a boot-time retry loop.
|
|
1315
|
+
refresh: function () {
|
|
1316
|
+
var loaded;
|
|
1317
|
+
try {
|
|
1318
|
+
var mirror = forms.describe();
|
|
1319
|
+
loaded = mirror && typeof mirror.load === "function" ? Promise.resolve(mirror.load()) : Promise.resolve();
|
|
1320
|
+
} catch (_e) {
|
|
1321
|
+
loaded = Promise.resolve();
|
|
1322
|
+
}
|
|
1323
|
+
return loaded.catch(function () { /* re-derive below regardless */ }).then(function () {
|
|
1324
|
+
rebind();
|
|
1325
|
+
});
|
|
1326
|
+
},
|
|
1327
|
+
// The last completed save, held for the plugin's LIFETIME (not the
|
|
1328
|
+
// card's mount). The card reads it on remount to seed its form from
|
|
1329
|
+
// what was actually saved — rather than from a mirror that may still
|
|
1330
|
+
// answer the previous document — and clears it once the mirror
|
|
1331
|
+
// agrees. See `lastSavedForm` above for why it lives here.
|
|
1332
|
+
savedForm: function () {
|
|
1333
|
+
return lastSavedForm;
|
|
1334
|
+
},
|
|
1335
|
+
clearSavedForm: function () {
|
|
1336
|
+
lastSavedForm = null;
|
|
1337
|
+
},
|
|
1338
|
+
setSavedForm: function (form) {
|
|
1339
|
+
lastSavedForm = form;
|
|
1340
|
+
}
|
|
1341
|
+
};
|
|
1342
|
+
// Force one mirror read, then arrange the next bounded attempt. The
|
|
1343
|
+
// read's own store update usually triggers `rebind` through the mirror
|
|
1344
|
+
// subscription; the timer only covers the case where it does not.
|
|
1345
|
+
var scheduleMirrorLoad = function () {
|
|
1346
|
+
if (loadAttempts >= MIRROR_LOAD_ATTEMPTS) return;
|
|
1347
|
+
loadAttempts = loadAttempts + 1;
|
|
1348
|
+
var loaded;
|
|
863
1349
|
try {
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
inject: subagentRowInjected
|
|
870
|
-
}, SubagentModelCard);
|
|
871
|
-
}));
|
|
872
|
-
} catch (error) {
|
|
873
|
-
console.error('[dsh-subagent-default-model] settings card slot "' + slotName + '" failed to register (host provider unaffected):', error);
|
|
1350
|
+
var mirror = forms.describe();
|
|
1351
|
+
if (!mirror || typeof mirror.load !== "function") return;
|
|
1352
|
+
loaded = Promise.resolve(mirror.load());
|
|
1353
|
+
} catch (_e) {
|
|
1354
|
+
loaded = Promise.resolve();
|
|
874
1355
|
}
|
|
1356
|
+
loaded.catch(function () { /* attempt below still runs */ }).then(function () {
|
|
1357
|
+
if (current !== void 0) return;
|
|
1358
|
+
if (loadAttempts >= MIRROR_LOAD_ATTEMPTS) return;
|
|
1359
|
+
if (typeof setTimeout !== "function") { rebind(); return; }
|
|
1360
|
+
setTimeout(rebind, MIRROR_LOAD_DELAY_MS);
|
|
1361
|
+
});
|
|
875
1362
|
};
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
1363
|
+
var rebind = function () {
|
|
1364
|
+
try {
|
|
1365
|
+
var snapshot = forms.describe().getSnapshot();
|
|
1366
|
+
lastMirrorStatus = snapshot.status;
|
|
1367
|
+
lastSeenViewNamespaces = ((snapshot.view && snapshot.view.namespaces) || []).length;
|
|
1368
|
+
} catch (_e) { /* diagnostics only */ }
|
|
1369
|
+
var namespace = servedNamespaceNow();
|
|
1370
|
+
lastBoundNamespace = namespace;
|
|
1371
|
+
var next = namespace === null ? void 0 : forms.get(namespace);
|
|
1372
|
+
if (next !== current) {
|
|
1373
|
+
if (typeof currentOff === "function") currentOff();
|
|
1374
|
+
current = next;
|
|
1375
|
+
currentOff = current && typeof current.subscribe === "function" ? current.subscribe(notify) : void 0;
|
|
1376
|
+
notify();
|
|
884
1377
|
}
|
|
885
|
-
|
|
1378
|
+
// Still unbound: the mirror has not listed the namespace yet, so ask
|
|
1379
|
+
// it again (bounded) rather than latching read-only for the session.
|
|
1380
|
+
if (next === void 0) scheduleMirrorLoad();
|
|
1381
|
+
};
|
|
1382
|
+
rebind();
|
|
1383
|
+
try {
|
|
1384
|
+
var describe = forms.describe();
|
|
1385
|
+
if (describe && typeof describe.subscribe === "function") describe.subscribe(rebind);
|
|
1386
|
+
} catch (_e) { /* no mirror surface: the card stays read-only */ }
|
|
1387
|
+
return scope;
|
|
1388
|
+
})();
|
|
1389
|
+
|
|
1390
|
+
// One-shot runtime diagnostics for the card: the exact facts a grey Save
|
|
1391
|
+
// button hides — did the mirror answer, what namespaces does it list for
|
|
1392
|
+
// this plugin, and which one got bound. The revision rides along because
|
|
1393
|
+
// a save that fails at a constant revision never reached the Host at
|
|
1394
|
+
// all, while one that fails across RISING revisions is being refused on
|
|
1395
|
+
// the fence — the single most useful number when triaging a save.
|
|
1396
|
+
runtimeDiagnostics = function () {
|
|
1397
|
+
var snap = settingsScope ? settingsScope.getSnapshot() : void 0;
|
|
1398
|
+
return {
|
|
1399
|
+
mirrorStatus: lastMirrorStatus,
|
|
1400
|
+
viewNamespaces: lastSeenViewNamespaces,
|
|
1401
|
+
candidates: seenCandidates,
|
|
1402
|
+
bound: lastBoundNamespace,
|
|
1403
|
+
scopeStatus: snap ? snap.status : "unavailable",
|
|
1404
|
+
writable: snap ? snap.writable === true : false,
|
|
1405
|
+
revision: snap && snap.revision !== void 0 ? snap.revision : null
|
|
886
1406
|
};
|
|
887
1407
|
};
|
|
888
1408
|
|
|
889
|
-
//
|
|
890
|
-
//
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
1409
|
+
// Cards register ONCE, unconditionally, exactly like the local siblings
|
|
1410
|
+
// (`dsh-connect-workbuddy` / `dsh-connect-trae`). They deliberately do NOT
|
|
1411
|
+
// follow the namespace: the forwarding scope above re-routes itself, so a
|
|
1412
|
+
// late mirror answer cannot leave a card pinned to a namespace the Host
|
|
1413
|
+
// does not serve, and the card needs no re-registration to recover.
|
|
1414
|
+
var registerCard = function (slotName, key) {
|
|
1415
|
+
try {
|
|
1416
|
+
ctx.slots.inject(slotName, function () {
|
|
1417
|
+
return ctx.slots.register({
|
|
1418
|
+
name: slotName,
|
|
1419
|
+
key: key,
|
|
1420
|
+
priority: 30,
|
|
1421
|
+
locale: SUBAGENT_ROW_LOCALE,
|
|
1422
|
+
inject: subagentRowInjected
|
|
1423
|
+
}, SubagentModelCard);
|
|
1424
|
+
});
|
|
1425
|
+
} catch (error) {
|
|
1426
|
+
console.error('[dsh-subagent-default-model] settings card slot "' + slotName + '" failed to register (host provider unaffected):', error);
|
|
1427
|
+
}
|
|
1428
|
+
};
|
|
1429
|
+
// 0.1.7 placement: register under Plugins config surfaces (the old
|
|
1430
|
+
// `settings.plugin.item` slot was removed in 0.1.7).
|
|
1431
|
+
registerCard("plugins.bundle.config", "dsh-subagent-default-model");
|
|
1432
|
+
registerCard("plugins.row.config", "dsh-subagent-default-model#dsh-subagent-default-model");
|
|
903
1433
|
});
|
|
904
1434
|
}
|
|
905
1435
|
|