dsh-subagent-default-model 2.0.1 → 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 +130 -0
- package/README.en.md +14 -0
- package/README.md +14 -2
- package/lib/client.js +773 -156
- package/lib/index.js +50 -11
- package/package.json +4 -4
package/lib/client.js
CHANGED
|
@@ -21,9 +21,16 @@ 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}";
|
|
33
|
+
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}";
|
|
27
34
|
|
|
28
35
|
if (typeof document !== "undefined") {
|
|
29
36
|
var cssId = "dsh-subagent-default-model/client.css";
|
|
@@ -38,6 +45,23 @@ window.__ModuleLoader__.load({
|
|
|
38
45
|
|
|
39
46
|
// ── locale ───────────────────────────────────────────────────────────
|
|
40
47
|
var SUBAGENT_ROW_LOCALE = "settings.subagentModel";
|
|
48
|
+
|
|
49
|
+
// ── 对话流注入行的自有节点 kind(2026-09-25)─────────────────────────
|
|
50
|
+
//
|
|
51
|
+
// 宿主 0.1.7 起,插件注入消息在**对话流不可见**:`dsh-client-ui-chat` 的分类
|
|
52
|
+
// 逻辑是 `if (event.data.source.kind !== "user") → kind: "context"`(与 form
|
|
53
|
+
// 无关),而可见性规则 `isVisibleChatNode()` 硬排除 `node.kind !== "context"`
|
|
54
|
+
// (注释明写「Exclude system prompts, ordinary Context, and permission
|
|
55
|
+
// commands from visible Chat rows」)。故本插件的注入只进轨迹。
|
|
56
|
+
//
|
|
57
|
+
// 绕开方式是注册**自有节点 kind**:该可见性黑名单只列 system-prompt /
|
|
58
|
+
// context / permission 三项,自定义 kind 默认可见;渲染器经
|
|
59
|
+
// `conversation.chat.node` 槽位按 `entryKey = node.kind` 运行时分派。
|
|
60
|
+
//
|
|
61
|
+
// 注意:`source.kind`(消息来源标识,仍是 "plugin:dsh-subagent-default-model")
|
|
62
|
+
// 与这里的**节点 kind** 是两件事,不要混改。trajectory 侧不受此影响
|
|
63
|
+
// (isVisibleChatNode 只在 ui-chat),故 trajectory definition 保持原样。
|
|
64
|
+
var CHAT_MODEL_NODE_KIND = "chat-subagent-model-notice";
|
|
41
65
|
var SUBAGENT_ROW_ZH = {
|
|
42
66
|
"row.title": "子代理默认模型(dsh-subagent-default-model)",
|
|
43
67
|
"row.desc": "为 subagent / subagent_fork 选择一个或多个默认路由;清空后子代理继承父会话路由。",
|
|
@@ -60,16 +84,19 @@ window.__ModuleLoader__.load({
|
|
|
60
84
|
"row.saving": "保存中…",
|
|
61
85
|
"row.saved": "已保存",
|
|
62
86
|
"row.incomplete": "请为每个模型路由选择 Provider 和 Model。",
|
|
87
|
+
"row.catalogEmpty": "模型目录尚未就绪(正在等待网关返回供应商与模型)。稍候片刻;若长时间为空,请检查 Provider 插件是否已启用。",
|
|
63
88
|
"row.effortNoDeclaration": "该模型当前未声明任何推理强度;子代理会因 effort 不被支持而一个请求都发不出(清空此项或改选模型)。",
|
|
64
89
|
"row.effortNotDeclared": "该模型当前未声明「{effort}」推理强度;子代理会因此无法启动(改选其它强度或清空此项)。",
|
|
65
|
-
"row.saveFailed": "
|
|
90
|
+
"row.saveFailed": "保存失败({message}),请重试。",
|
|
91
|
+
"row.settingsUnavailable": "本机宿主未为此插件提供设置存储({message}),暂时无法保存;请确认插件已在当前 profile 中启用,然后重启 DSH。",
|
|
66
92
|
"row.toastSaved": "子代理默认模型设置已保存。",
|
|
67
93
|
"row.failoverEnabled": "连接失败时按队列与策略切换模型",
|
|
68
94
|
"row.failoverHint": "(需配置 ≥2 个 Provider,切换才会生效)。",
|
|
69
95
|
"row.trajectoryModel": "当前供应商/模型",
|
|
70
96
|
"row.chatModelInitial": "当前供应商/模型",
|
|
71
97
|
"row.chatModelChange": "已切换到",
|
|
72
|
-
"row.chatModelResume": "继续使用"
|
|
98
|
+
"row.chatModelResume": "继续使用",
|
|
99
|
+
"row.noticeLabel": "上下文注入 · dsh-subagent-default-model"
|
|
73
100
|
};
|
|
74
101
|
var SUBAGENT_ROW_EN = {
|
|
75
102
|
"row.title": "Subagent default model (dsh-subagent-default-model)",
|
|
@@ -93,70 +120,32 @@ window.__ModuleLoader__.load({
|
|
|
93
120
|
"row.saving": "Saving…",
|
|
94
121
|
"row.saved": "Saved",
|
|
95
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.",
|
|
96
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).",
|
|
97
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).",
|
|
98
|
-
"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.",
|
|
99
128
|
"row.toastSaved": "Subagent default model settings saved.",
|
|
100
129
|
"row.failoverEnabled": "Switch models by queue and strategy on connection failure",
|
|
101
130
|
"row.failoverHint": "(requires at least 2 configured providers).",
|
|
102
131
|
"row.trajectoryModel": "Current provider/model",
|
|
103
132
|
"row.chatModelInitial": "Current provider/model",
|
|
104
133
|
"row.chatModelChange": "Switched to",
|
|
105
|
-
"row.chatModelResume": "Resumed on"
|
|
134
|
+
"row.chatModelResume": "Resumed on",
|
|
135
|
+
"row.noticeLabel": "Context injection · dsh-subagent-default-model"
|
|
106
136
|
};
|
|
107
137
|
|
|
108
138
|
// ── helpers ──────────────────────────────────────────────────────────
|
|
109
139
|
// This plugin's DECLARED Loader entry id = `cordis.patch.yml` `insert.id`.
|
|
110
|
-
//
|
|
111
|
-
//
|
|
112
|
-
//
|
|
113
|
-
// served-namespace directory EXACTLY
|
|
114
|
-
// fails silently (`status: unavailable`, no error
|
|
115
|
-
//
|
|
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).
|
|
116
147
|
var SUBAGENT_MODEL_SETTINGS_NS = "dsh-subagent-default-model";
|
|
117
148
|
|
|
118
|
-
/**
|
|
119
|
-
* Resolve the settings namespace the host actually serves for this plugin.
|
|
120
|
-
*
|
|
121
|
-
* Match order: the declared entry id exactly, then a `include:`-prefixed
|
|
122
|
-
* form of it, then the host-served namespace carrying the package name.
|
|
123
|
-
* The legacy section name (`subagent-default-model`, pre-0.1.7
|
|
124
|
-
* `settings.yaml` keying) is deliberately accepted last, so it can only win
|
|
125
|
-
* when it is genuinely the served namespace. Falls back to the declared id
|
|
126
|
-
* while the mirror is not ready.
|
|
127
|
-
*
|
|
128
|
-
* @param {object} forms - the `configForms` client service.
|
|
129
|
-
* @param {Set<string>} [servedNamespaces] - authoritative served-namespace set
|
|
130
|
-
* handed over by `configForms.whileServed(...)`. When present it is preferred
|
|
131
|
-
* over the mirror snapshot, because it is the very set that decided the
|
|
132
|
-
* registration was due — the mirror may still be mid-fold.
|
|
133
|
-
* @returns {string} the namespace to pass to `forms.get()`.
|
|
134
|
-
*/
|
|
135
|
-
function subagentEntryIdOf(forms, servedNamespaces) {
|
|
136
|
-
var pick = function (names) {
|
|
137
|
-
return names.find(function (ns) {
|
|
138
|
-
return ns === SUBAGENT_MODEL_SETTINGS_NS;
|
|
139
|
-
}) ?? names.find(function (ns) {
|
|
140
|
-
return ns === "include:" + SUBAGENT_MODEL_SETTINGS_NS;
|
|
141
|
-
}) ?? names.find(function (ns) {
|
|
142
|
-
return /subagent-default-model/i.test(ns || "");
|
|
143
|
-
});
|
|
144
|
-
};
|
|
145
|
-
try {
|
|
146
|
-
if (servedNamespaces && typeof servedNamespaces.has === "function") {
|
|
147
|
-
var fromServed = pick(Array.from(servedNamespaces));
|
|
148
|
-
if (typeof fromServed === "string" && fromServed !== "") return fromServed;
|
|
149
|
-
}
|
|
150
|
-
var view = forms.describe().getSnapshot().view;
|
|
151
|
-
var namespaces = ((view && view.namespaces) || []).map(function (entry) {
|
|
152
|
-
return entry && entry.ns;
|
|
153
|
-
});
|
|
154
|
-
var served = pick(namespaces);
|
|
155
|
-
if (typeof served === "string" && served !== "") return served;
|
|
156
|
-
} catch (_e) { /* mirror not ready: the declared id is still the right guess */ }
|
|
157
|
-
return SUBAGENT_MODEL_SETTINGS_NS;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
149
|
function normalizeDefaultModels(value) {
|
|
161
150
|
var result = [];
|
|
162
151
|
if (Array.isArray(value.models) && value.models.length > 0) {
|
|
@@ -244,16 +233,85 @@ window.__ModuleLoader__.load({
|
|
|
244
233
|
}
|
|
245
234
|
|
|
246
235
|
function persistDefaultModels(scope, value) {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
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";
|
|
257
315
|
});
|
|
258
316
|
}
|
|
259
317
|
|
|
@@ -272,11 +330,44 @@ window.__ModuleLoader__.load({
|
|
|
272
330
|
var snap = useSettingsScopeSnapshot(props.settingsScope);
|
|
273
331
|
var value = (snap && snap.status === "ready" && snap.value) || {};
|
|
274
332
|
var groupsState = React.useState([]);
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
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);
|
|
278
365
|
var savedState = React.useState(false);
|
|
279
|
-
|
|
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);
|
|
280
371
|
var toastState = React.useState(null);
|
|
281
372
|
var toastSeq = React.useRef(0);
|
|
282
373
|
var dirtyState = React.useState(false);
|
|
@@ -290,11 +381,27 @@ window.__ModuleLoader__.load({
|
|
|
290
381
|
}, []);
|
|
291
382
|
React.useEffect(function () {
|
|
292
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
|
+
}
|
|
293
400
|
routesState[1](normalizeDefaultModels(value));
|
|
294
401
|
strategyState[1](value.strategy === "random" ? "random" : "round-robin");
|
|
295
402
|
failoverEnabledState[1](value.failoverEnabled !== false);
|
|
296
403
|
savedState[1](false);
|
|
297
|
-
saveErrorState[1](
|
|
404
|
+
saveErrorState[1](null);
|
|
298
405
|
}, [snap ? snap.revision : -1, dirtyState[0], busyState[0]]);
|
|
299
406
|
function updateRoute(index, field, nextValue) {
|
|
300
407
|
routesState[1](function (routes) {
|
|
@@ -310,7 +417,7 @@ window.__ModuleLoader__.load({
|
|
|
310
417
|
});
|
|
311
418
|
});
|
|
312
419
|
savedState[1](false);
|
|
313
|
-
saveErrorState[1](
|
|
420
|
+
saveErrorState[1](null);
|
|
314
421
|
dirtyState[1](true);
|
|
315
422
|
}
|
|
316
423
|
function addRoute() {
|
|
@@ -319,28 +426,133 @@ window.__ModuleLoader__.load({
|
|
|
319
426
|
return routes.concat({ provider: firstGroup ? firstGroup.id : "", model: "", reasoningEffort: "" });
|
|
320
427
|
});
|
|
321
428
|
savedState[1](false);
|
|
322
|
-
saveErrorState[1](
|
|
429
|
+
saveErrorState[1](null);
|
|
323
430
|
dirtyState[1](true);
|
|
324
431
|
}
|
|
325
432
|
function removeRoute(index) {
|
|
326
433
|
routesState[1](function (routes) { return routes.filter(function (_, routeIndex) { return routeIndex !== index; }); });
|
|
327
434
|
savedState[1](false);
|
|
328
|
-
saveErrorState[1](
|
|
435
|
+
saveErrorState[1](null);
|
|
329
436
|
dirtyState[1](true);
|
|
330
437
|
}
|
|
331
438
|
function save() {
|
|
332
|
-
|
|
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;
|
|
333
455
|
var nextValue = serializeDefaultModels(value, routesState[0], strategyState[0], failoverEnabledState[0]);
|
|
334
456
|
savedState[1](false);
|
|
335
|
-
saveErrorState[1](
|
|
457
|
+
saveErrorState[1](null);
|
|
336
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
|
+
};
|
|
337
517
|
Promise.resolve().then(function () {
|
|
338
518
|
return props.write(nextValue);
|
|
339
|
-
}).then(function () {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
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)));
|
|
344
556
|
}
|
|
345
557
|
routesState[1](normalizeDefaultModels(acceptedValue));
|
|
346
558
|
strategyState[1](acceptedValue.strategy === "random" ? "random" : "round-robin");
|
|
@@ -348,11 +560,54 @@ window.__ModuleLoader__.load({
|
|
|
348
560
|
dirtyState[1](false);
|
|
349
561
|
busyState[1](false);
|
|
350
562
|
savedState[1](true);
|
|
563
|
+
saveErrorState[1](null);
|
|
351
564
|
toastSeq.current = toastSeq.current + 1;
|
|
352
565
|
toastState[1]({ seq: toastSeq.current, text: t("row.toastSaved") });
|
|
353
|
-
|
|
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) {
|
|
354
609
|
busyState[1](false);
|
|
355
|
-
saveErrorState[1](
|
|
610
|
+
saveErrorState[1](error && error.message ? error.message : "writeRefused");
|
|
356
611
|
});
|
|
357
612
|
}
|
|
358
613
|
function discard() {
|
|
@@ -361,7 +616,7 @@ window.__ModuleLoader__.load({
|
|
|
361
616
|
failoverEnabledState[1](value.failoverEnabled !== false);
|
|
362
617
|
dirtyState[1](false);
|
|
363
618
|
savedState[1](false);
|
|
364
|
-
saveErrorState[1](
|
|
619
|
+
saveErrorState[1](null);
|
|
365
620
|
toastState[1](null);
|
|
366
621
|
}
|
|
367
622
|
var hasIncompleteRoute = routesState[0].some(function (route) { return !route.provider || !route.model; });
|
|
@@ -370,7 +625,18 @@ window.__ModuleLoader__.load({
|
|
|
370
625
|
var warning = checkEffortSupport(route, groupsState[0]);
|
|
371
626
|
if (warning !== null) effortWarnings.push({ index: index, key: warning.key, warning: warning });
|
|
372
627
|
});
|
|
373
|
-
|
|
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;
|
|
374
640
|
var discardDisabled = !dirtyState[0] || busyState[0];
|
|
375
641
|
var routes = routesState[0].map(function (route, index) {
|
|
376
642
|
var group = null;
|
|
@@ -452,7 +718,36 @@ window.__ModuleLoader__.load({
|
|
|
452
718
|
}, t(effortWarning.key, effortWarning.params))
|
|
453
719
|
);
|
|
454
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
|
+
}
|
|
455
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,
|
|
456
751
|
routes.length ? React.createElement("div", { className: "dsm-model-settings-list" }, routes) : React.createElement("div", { className: "dsm-model-settings-hint" }, t("row.empty")),
|
|
457
752
|
React.createElement("div", { className: "dsm-model-settings-options" },
|
|
458
753
|
React.createElement("button", { type: "button", className: "dsm-btn dsm-btn-outline", onClick: addRoute }, t("row.add")),
|
|
@@ -461,7 +756,7 @@ window.__ModuleLoader__.load({
|
|
|
461
756
|
React.createElement("select", {
|
|
462
757
|
className: "dsm-model-settings-select",
|
|
463
758
|
value: strategyState[0],
|
|
464
|
-
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); }
|
|
465
760
|
},
|
|
466
761
|
React.createElement("option", { value: "round-robin" }, t("row.roundRobin")),
|
|
467
762
|
React.createElement("option", { value: "random" }, t("row.random"))
|
|
@@ -472,7 +767,7 @@ window.__ModuleLoader__.load({
|
|
|
472
767
|
React.createElement("input", {
|
|
473
768
|
type: "checkbox",
|
|
474
769
|
checked: failoverEnabledState[0],
|
|
475
|
-
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); }
|
|
476
771
|
}),
|
|
477
772
|
React.createElement("span", null, t("row.failoverEnabled")),
|
|
478
773
|
React.createElement("span", { className: "dsm-failover-hint" }, t("row.failoverHint"))
|
|
@@ -485,6 +780,25 @@ window.__ModuleLoader__.load({
|
|
|
485
780
|
}, effortWarnings.map(function (entry) {
|
|
486
781
|
return React.createElement("div", { key: entry.key + ":" + entry.index }, t(entry.warning.key, entry.warning.params));
|
|
487
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,
|
|
488
802
|
React.createElement("div", { className: "dsm-model-settings-footer" },
|
|
489
803
|
React.createElement("div", { className: "dsm-model-settings-footer-left" },
|
|
490
804
|
React.createElement("a", {
|
|
@@ -539,6 +853,63 @@ window.__ModuleLoader__.load({
|
|
|
539
853
|
);
|
|
540
854
|
}
|
|
541
855
|
|
|
856
|
+
// ── 对话流注入行的渲染器(自有节点 kind)─────────────────────────────
|
|
857
|
+
//
|
|
858
|
+
// 宿主按 `entryKey = node.kind` 在 `conversation.chat.node` 槽位**运行时分派**
|
|
859
|
+
// 渲染器(`ChatNodeSeat` 传 `entryKey: routedNode.kind`)。该分派是 keyed 槽位:
|
|
860
|
+
// 没有占用者的 kind 走 `ChatNodeSeat` 传入的 `fallback`——一个 `JsonBlock`
|
|
861
|
+
// (标签 "unknown surface" + 节点数据原样 JSON)。所以只改 kind 而不注册渲染器
|
|
862
|
+
// 不是「行消失」,而是**对话流里出现一行原始 JSON**(比不可见更糟)。
|
|
863
|
+
//
|
|
864
|
+
// 渲染器收到的是 `{ node }`(`ChatNodeOwnerProps`),节点数据即 `start()` 的
|
|
865
|
+
// state(`buildViewNode` 把它放进 `data`)。这里只读 content / source.summary,
|
|
866
|
+
// 不依赖任何宿主内部工具。
|
|
867
|
+
function SubagentModelNoticeRow(props) {
|
|
868
|
+
var node = props.node;
|
|
869
|
+
var data = node && node.data ? node.data : {};
|
|
870
|
+
// `t` is the framework-injected locale seat: this registration declares
|
|
871
|
+
// `locale:`, so the renderer receives it. Keep the label in the
|
|
872
|
+
// dictionary rather than inlining one language (the plugin ships zh+en).
|
|
873
|
+
var t = props.t || function (key) { return key; };
|
|
874
|
+
var openState = React.useState(false);
|
|
875
|
+
var open = openState[0];
|
|
876
|
+
var setOpen = openState[1];
|
|
877
|
+
var blocks = Array.isArray(data.content) ? data.content : [];
|
|
878
|
+
var text = blocks.map(function (block) {
|
|
879
|
+
return block && typeof block.text === "string" ? block.text : "";
|
|
880
|
+
}).join("\n");
|
|
881
|
+
var summary = data.source && typeof data.source.summary === "string" ? data.source.summary : "";
|
|
882
|
+
return React.createElement("div", { className: "dsm-notice-row" },
|
|
883
|
+
React.createElement("button", {
|
|
884
|
+
type: "button",
|
|
885
|
+
className: "dsm-notice-toggle",
|
|
886
|
+
"aria-expanded": open,
|
|
887
|
+
onClick: function () { setOpen(!open); }
|
|
888
|
+
},
|
|
889
|
+
React.createElement("span", { className: "dsm-notice-dot", "aria-hidden": "true" }),
|
|
890
|
+
React.createElement("span", { className: "dsm-notice-label" }, t("row.noticeLabel")),
|
|
891
|
+
summary ? React.createElement("span", { className: "dsm-notice-summary" }, summary) : null
|
|
892
|
+
),
|
|
893
|
+
open ? React.createElement("pre", { className: "dsm-notice-body" }, text) : null
|
|
894
|
+
);
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
/** 注册自有 kind 的渲染器;返回卸载函数。槽位缺失时静默跳过。 */
|
|
898
|
+
function registerSubagentModelNotice(ctx) {
|
|
899
|
+
try {
|
|
900
|
+
return ctx.slots.inject("conversation.chat.node", function () {
|
|
901
|
+
return ctx.slots.register({
|
|
902
|
+
name: "conversation.chat.node",
|
|
903
|
+
key: CHAT_MODEL_NODE_KIND,
|
|
904
|
+
locale: SUBAGENT_ROW_LOCALE
|
|
905
|
+
}, SubagentModelNoticeRow);
|
|
906
|
+
});
|
|
907
|
+
} catch (error) {
|
|
908
|
+
console.error("[dsh-subagent-default-model] notice renderer failed to register (chat row absent):", error);
|
|
909
|
+
return function () { };
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
|
|
542
913
|
// ── apply: inject settings row ───────────────────────────────────────
|
|
543
914
|
// `settingsScope` service was REMOVED in DSH 0.1.7 (settings moved to
|
|
544
915
|
// `configForms` + the plugin's own `Config`). Hard-injecting it would keep
|
|
@@ -583,14 +954,67 @@ window.__ModuleLoader__.load({
|
|
|
583
954
|
// we stay soft-injected (a missing gateway must not withhold the card)
|
|
584
955
|
// and re-probe instead.
|
|
585
956
|
var remoteRoot = typeof ctx.get === "function" ? ctx.get("remote") : undefined;
|
|
586
|
-
|
|
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 () {
|
|
587
973
|
var sessionRemote = ctx.get ? ctx.get("remote.session") : undefined;
|
|
588
974
|
if (!sessionRemote) sessionRemote = remoteRoot && remoteRoot.session;
|
|
589
|
-
if (!sessionRemote || typeof sessionRemote.modelCatalog !== "function") return Promise.resolve(
|
|
975
|
+
if (!sessionRemote || typeof sessionRemote.modelCatalog !== "function") return Promise.resolve(null);
|
|
590
976
|
return sessionRemote.modelCatalog().then(function (response) {
|
|
591
|
-
if (!response || !response.ok) return
|
|
977
|
+
if (!response || !response.ok) return null;
|
|
592
978
|
return (response.value && response.value.groups) || [];
|
|
593
|
-
}).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();
|
|
594
1018
|
};
|
|
595
1019
|
|
|
596
1020
|
// Register locale for this component.
|
|
@@ -672,8 +1096,12 @@ window.__ModuleLoader__.load({
|
|
|
672
1096
|
// persisted session resumes ("resume"). The frame header carries the
|
|
673
1097
|
// full config (provider/model), so the conversation can show exactly
|
|
674
1098
|
// which route is in use — no host-side changes required.
|
|
675
|
-
//
|
|
676
|
-
//
|
|
1099
|
+
// 节点 kind 用**自有值**(`CHAT_MODEL_NODE_KIND`),不复用内置 `context`。
|
|
1100
|
+
// 旧注释曾写「复用内置注入行(ContextMessageNodeView)」——该复用目标在
|
|
1101
|
+
// 宿主 0.1.7 已不存在:`dsh-client-ui-chat` 的 `isVisibleChatNode()` 明确
|
|
1102
|
+
// 排除 `node.kind === "context"`(除非含 tool-addition/removal 块),故
|
|
1103
|
+
// 复用 `context` 的结果是**行永远不可见**。自有 kind 不在黑名单内,配一个
|
|
1104
|
+
// 自有渲染器即可见。trajectory 侧不受影响(该黑名单只在 ui-chat)。
|
|
677
1105
|
var chatT = ctx.locale.bind(SUBAGENT_ROW_LOCALE);
|
|
678
1106
|
var chatModelDefinition = {
|
|
679
1107
|
kind: "chat-subagent-model",
|
|
@@ -695,7 +1123,7 @@ window.__ModuleLoader__.load({
|
|
|
695
1123
|
var reason = data.reason === "change" ? "row.chatModelChange" : data.reason === "resume" ? "row.chatModelResume" : "row.chatModelInitial";
|
|
696
1124
|
var label = chatT(reason) + ":" + (config.provider ? config.provider + (config.model ? "/" + config.model : "") : (config.model || ""));
|
|
697
1125
|
return {
|
|
698
|
-
kind:
|
|
1126
|
+
kind: CHAT_MODEL_NODE_KIND,
|
|
699
1127
|
seq: event.seq,
|
|
700
1128
|
time: event.time,
|
|
701
1129
|
content: [{ type: "text", text: label }],
|
|
@@ -712,7 +1140,7 @@ window.__ModuleLoader__.load({
|
|
|
712
1140
|
if (context.state === void 0) return null;
|
|
713
1141
|
return {
|
|
714
1142
|
key: context.key,
|
|
715
|
-
kind:
|
|
1143
|
+
kind: CHAT_MODEL_NODE_KIND,
|
|
716
1144
|
id: context.id,
|
|
717
1145
|
target: "chat",
|
|
718
1146
|
anchorSeq: context.state.seq,
|
|
@@ -725,23 +1153,34 @@ window.__ModuleLoader__.load({
|
|
|
725
1153
|
ctx.effect(function () {
|
|
726
1154
|
return ctx.uiConversation.events.register(chatModelDefinition);
|
|
727
1155
|
}, "dsh-subagent-default-model: chat model row");
|
|
1156
|
+
|
|
1157
|
+
// 自有节点 kind 必须配自己的渲染器(宿主按 `entryKey = node.kind` 分派)。
|
|
1158
|
+
// 缺这一步,该行会落到 `ChatNodeSeat` 的 `fallback`(JsonBlock)——用户看到
|
|
1159
|
+
// 的不是「模型行」,而是一坨原始 JSON。
|
|
1160
|
+
ctx.effect(function () {
|
|
1161
|
+
return registerSubagentModelNotice(ctx);
|
|
1162
|
+
}, "dsh-subagent-default-model: chat notice row");
|
|
728
1163
|
}
|
|
729
1164
|
|
|
730
|
-
//
|
|
731
|
-
//
|
|
732
|
-
//
|
|
733
|
-
//
|
|
734
|
-
//
|
|
735
|
-
//
|
|
736
|
-
//
|
|
737
|
-
|
|
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; };
|
|
738
1176
|
var subagentRowInjected = function () {
|
|
739
1177
|
return {
|
|
740
|
-
settingsScope:
|
|
1178
|
+
settingsScope: settingsScope,
|
|
741
1179
|
loadCatalog: loadCatalog,
|
|
742
1180
|
write: function (value) {
|
|
743
|
-
return persistDefaultModels(
|
|
744
|
-
}
|
|
1181
|
+
return persistDefaultModels(settingsScope, value);
|
|
1182
|
+
},
|
|
1183
|
+
diagnostics: runtimeDiagnostics
|
|
745
1184
|
};
|
|
746
1185
|
};
|
|
747
1186
|
|
|
@@ -749,70 +1188,248 @@ window.__ModuleLoader__.load({
|
|
|
749
1188
|
// card simply stays absent when the service is unavailable, instead of
|
|
750
1189
|
// blocking the whole client plugin.
|
|
751
1190
|
//
|
|
752
|
-
//
|
|
753
|
-
//
|
|
754
|
-
//
|
|
755
|
-
//
|
|
756
|
-
// (`dsh-subagent-default-model`
|
|
757
|
-
//
|
|
758
|
-
//
|
|
759
|
-
//
|
|
760
|
-
//
|
|
761
|
-
//
|
|
762
|
-
//
|
|
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.
|
|
763
1202
|
//
|
|
764
|
-
//
|
|
765
|
-
//
|
|
766
|
-
// namespace
|
|
767
|
-
//
|
|
768
|
-
// 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.
|
|
769
1207
|
ctx.inject(["configForms"], function (formsCtx) {
|
|
770
1208
|
var forms = formsCtx.configForms;
|
|
771
1209
|
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
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;
|
|
776
1349
|
try {
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
inject: subagentRowInjected
|
|
783
|
-
}, SubagentModelCard);
|
|
784
|
-
}));
|
|
785
|
-
} catch (error) {
|
|
786
|
-
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();
|
|
787
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
|
+
});
|
|
788
1362
|
};
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
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();
|
|
797
1377
|
}
|
|
798
|
-
|
|
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
|
|
799
1406
|
};
|
|
800
1407
|
};
|
|
801
1408
|
|
|
802
|
-
//
|
|
803
|
-
//
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
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");
|
|
816
1433
|
});
|
|
817
1434
|
}
|
|
818
1435
|
|