dsh-codearts 1.2.14 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,6 +4,7 @@ window.__ModuleLoader__.load({
4
4
  var module = { exports: {} };
5
5
  var exports = module.exports;
6
6
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
7
+ //#endregion
7
8
  let react = require("react");
8
9
  let _deepseek_ai_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
9
10
  let react_jsx_runtime = require("react/jsx-runtime");
@@ -23,38 +24,105 @@ function stripModelSuffixes(name) {
23
24
  }
24
25
  //#endregion
25
26
  //#region src/client/panel-switch.ts
27
+ /** 一个纯内存的布尔开关 + 订阅表;不持久化,真实值来自 `/api/codearts/dock`。 */
28
+ function createWantedSwitch(initial) {
29
+ let wanted = initial;
30
+ const listeners = /* @__PURE__ */ new Set();
31
+ return {
32
+ get: () => wanted,
33
+ set(next) {
34
+ if (wanted === next) return;
35
+ wanted = next;
36
+ for (const listener of [...listeners]) try {
37
+ listener();
38
+ } catch (error) {
39
+ console.error("[dsh-codearts] entry switch listener failed:", error);
40
+ }
41
+ },
42
+ subscribe(listener) {
43
+ listeners.add(listener);
44
+ return () => {
45
+ listeners.delete(listener);
46
+ };
47
+ }
48
+ };
49
+ }
50
+ /** 侧边栏图标列里的入口(缺省关)。 */
51
+ const sidebarEntrySwitch = createWantedSwitch(false);
52
+ /** 设置左侧导航里的入口(缺省开)。 */
53
+ const settingsEntrySwitch = createWantedSwitch(true);
54
+ const sidebarPanelWanted = sidebarEntrySwitch.get;
55
+ const setSidebarPanelWanted = sidebarEntrySwitch.set;
56
+ const subscribeSidebarPanelWanted = sidebarEntrySwitch.subscribe;
57
+ const settingsEntryWanted = settingsEntrySwitch.get;
58
+ const setSettingsEntryWanted = settingsEntrySwitch.set;
59
+ const subscribeSettingsEntryWanted = settingsEntrySwitch.subscribe;
60
+ BigInt("0xFFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551") >> 1n;
61
+ new TextEncoder();
62
+ //#endregion
63
+ //#region src/web-status.ts
26
64
  /**
27
- * 「要不要在 DSH 侧边栏占一格」这个偏好,浏览器侧的单一真相。
65
+ * 开关的默认值:没有 settings provider(或老配置没这两个键)时保持原有行为 ——
66
+ * 底部两行都显示;侧边栏相反,缺省不开(那一格是所有插件共用的全局座位)。
67
+ * `modelDetail` 缺省开(保持老版本的样子),`autoClaim` 缺省关。
68
+ */
69
+ const DEFAULT_DOCK_FLAGS = {
70
+ credits: true,
71
+ queue: true,
72
+ sidebar: false,
73
+ settingsEntry: true,
74
+ modelDetail: true,
75
+ autoClaim: false,
76
+ keepAliveDaemon: false
77
+ };
78
+ //#endregion
79
+ //#region src/client/dock-store.ts
80
+ /**
81
+ * 「显示」页那些开关在浏览器侧的共享状态。
82
+ *
83
+ * 为什么需要它:同一张卡片会被挂到三个地方 —— 设置里的 CodeArts 页、侧边栏的整页
84
+ * 面板、插件详情页。每个实例各自 fetch `/api/codearts/dock` 的话,在 A 处改了开关,
85
+ * B 处只要已经挂载过就永远显示旧值(实测:设置页取消「设置左侧导航显示 CodeArts」,
86
+ * 侧边栏那张卡片仍显示勾选)。
28
87
  *
29
- * 为什么不靠组件返回 null 来隐藏:宿主是按**槽位里的注册条目**(entry metadata)
30
- * 画侧边栏导航行的 —— 只要注册还在,那一行就在;渲染函数 return null 只会留下一个
31
- * 「空白但可点」的按钮。所以开关必须落到「注册 / 不注册」上,这里只存那个意图,
32
- * 真正的注册动作由 index.tsx 的 sync 控制器按它做。
88
+ * 所以开关值只存一份:谁 fetch/POST 成功就写进来,所有挂着的实例订阅它。
89
+ * 乐观更新只改调用方自己的局部状态,成功后才 publish —— 别的实例不该看到还没被
90
+ * 服务端确认的值。
33
91
  *
34
- * 默认 **false**:读不到配置时必须当作关闭。侧边栏那一格是所有插件共用的全局座位,
35
- * 猜错的代价比「少一个入口」大得多(用户还能从「设置 → 插件」进同一张卡片)。
92
+ * @module dsh-codearts/client/dock-store
36
93
  */
37
- let wanted = false;
38
- /** 当前是否要显示侧边栏入口。 */
39
- function sidebarPanelWanted() {
40
- return wanted;
41
- }
94
+ let snapshot = {
95
+ dock: DEFAULT_DOCK_FLAGS,
96
+ writable: false,
97
+ loaded: false
98
+ };
42
99
  const listeners = /* @__PURE__ */ new Set();
100
+ function dockSnapshot() {
101
+ return snapshot;
102
+ }
43
103
  /**
44
- * 改开关。值没变就直接返回 —— 调用方会在每次刷新状态时调用它,
45
- * 无变化的重注册会让侧边栏闪一下。
104
+ * 写入新值。`patch.dock` 只给变化的键也行:缺省键用 DEFAULT_DOCK_FLAGS 补齐,
105
+ * 老后端少字段时不会把已经打开的开关注销成 undefined。
46
106
  */
47
- function setSidebarPanelWanted(next) {
48
- if (wanted === next) return;
49
- wanted = next;
107
+ function publishDock(patch) {
108
+ const dock = patch.dock === void 0 ? snapshot.dock : {
109
+ ...DEFAULT_DOCK_FLAGS,
110
+ ...patch.dock
111
+ };
112
+ const writable = patch.writable ?? snapshot.writable;
113
+ if (dock === snapshot.dock && writable === snapshot.writable && snapshot.loaded) return;
114
+ snapshot = {
115
+ dock,
116
+ writable,
117
+ loaded: true
118
+ };
50
119
  for (const listener of [...listeners]) try {
51
120
  listener();
52
121
  } catch (error) {
53
- console.error("[dsh-codearts] sidebar panel listener failed:", error);
122
+ console.error("[dsh-codearts] dock-store listener failed:", error);
54
123
  }
55
124
  }
56
- /** 订阅开关变化,返回取消订阅函数。 */
57
- function subscribeSidebarPanelWanted(listener) {
125
+ function subscribeDock(listener) {
58
126
  listeners.add(listener);
59
127
  return () => {
60
128
  listeners.delete(listener);
@@ -87,98 +155,98 @@ if (typeof document !== "undefined" && document.querySelector("style[data-plugin
87
155
  document.head.appendChild(tag);
88
156
  }
89
157
  var CodeArtsPluginCard_module_css_default = {
90
- "field": "xoziZG_field",
91
- "sectionHead": "xoziZG_sectionHead",
92
- "trendTip": "xoziZG_trendTip",
93
- "usageFill": "xoziZG_usageFill",
94
- "area": "xoziZG_area",
95
- "body": "xoziZG_body",
96
- "modelName": "xoziZG_modelName",
97
- "doctorName": "xoziZG_doctorName",
98
- "creditLink": "xoziZG_creditLink",
99
- "manual": "xoziZG_manual",
100
- "statGrid": "xoziZG_statGrid",
101
- "accountName": "xoziZG_accountName",
102
- "manualSummary": "xoziZG_manualSummary",
103
- "doctorList": "xoziZG_doctorList",
104
- "expiryLabel": "xoziZG_expiryLabel",
105
- "balanceUnit": "xoziZG_balanceUnit",
158
+ "skeletonRow": "xoziZG_skeletonRow",
159
+ "meta": "xoziZG_meta",
160
+ "fieldLabel": "xoziZG_fieldLabel",
161
+ "usageTipSep": "xoziZG_usageTipSep",
162
+ "usageTipRow": "xoziZG_usageTipRow",
106
163
  "heatHours": "xoziZG_heatHours",
107
- "statCard": "xoziZG_statCard",
108
- "section": "xoziZG_section",
109
- "statusLine": "xoziZG_statusLine",
164
+ "balance": "xoziZG_balance",
165
+ "name": "xoziZG_name",
166
+ "heatHourCell": "xoziZG_heatHourCell",
167
+ "heatLegendChip": "xoziZG_heatLegendChip",
168
+ "choices": "xoziZG_choices",
110
169
  "hint": "xoziZG_hint",
111
- "tabPanel": "xoziZG_tabPanel",
170
+ "heatLegend": "xoziZG_heatLegend",
171
+ "accountCard": "xoziZG_accountCard",
172
+ "accountNameRow": "xoziZG_accountNameRow",
173
+ "heatCell": "xoziZG_heatCell",
174
+ "desc": "xoziZG_desc",
175
+ "accountToolbar": "xoziZG_accountToolbar",
176
+ "danger": "xoziZG_danger",
177
+ "modelSpec": "xoziZG_modelSpec",
178
+ "creditRow": "xoziZG_creditRow",
179
+ "doctorRow": "xoziZG_doctorRow",
112
180
  "updated": "xoziZG_updated",
113
- "balanceRow": "xoziZG_balanceRow",
114
- "name": "xoziZG_name",
115
- "count": "xoziZG_count",
116
- "usageTipName": "xoziZG_usageTipName",
117
- "check": "xoziZG_check",
181
+ "usageTip": "xoziZG_usageTip",
182
+ "modelRequests": "xoziZG_modelRequests",
118
183
  "skeleton": "xoziZG_skeleton",
119
- "header": "xoziZG_header",
184
+ "tabs": "xoziZG_tabs",
185
+ "body": "xoziZG_body",
186
+ "area": "xoziZG_area",
187
+ "claimAllRow": "xoziZG_claimAllRow",
188
+ "statGrid": "xoziZG_statGrid",
189
+ "creditLink": "xoziZG_creditLink",
190
+ "accountToggle": "xoziZG_accountToggle",
191
+ "creditFooter": "xoziZG_creditFooter",
192
+ "expiryRow": "xoziZG_expiryRow",
193
+ "expiryLabel": "xoziZG_expiryLabel",
194
+ "section": "xoziZG_section",
195
+ "accountRowActions": "xoziZG_accountRowActions",
120
196
  "modelRow": "xoziZG_modelRow",
121
- "modelRequests": "xoziZG_modelRequests",
122
- "skeletonRow": "xoziZG_skeletonRow",
123
- "choices": "xoziZG_choices",
124
- "headText": "xoziZG_headText",
125
- "heatCell": "xoziZG_heatCell",
126
- "skeletonBreath": "xoziZG_skeletonBreath",
127
- "modelFill": "xoziZG_modelFill",
128
- "modelTrack": "xoziZG_modelTrack",
129
197
  "accountHint": "xoziZG_accountHint",
130
- "choiceRow": "xoziZG_choiceRow",
131
- "bar": "xoziZG_bar",
132
- "heatWeekday": "xoziZG_heatWeekday",
133
- "claimAllRow": "xoziZG_claimAllRow",
134
- "usageBar": "xoziZG_usageBar",
135
- "modelChart": "xoziZG_modelChart",
136
- "usageTip": "xoziZG_usageTip",
137
- "accountCard": "xoziZG_accountCard",
138
- "balance": "xoziZG_balance",
139
- "creditRow": "xoziZG_creditRow",
140
198
  "modelShare": "xoziZG_modelShare",
141
- "usageTipSep": "xoziZG_usageTipSep",
142
- "heatLegendChip": "xoziZG_heatLegendChip",
143
- "accountToggle": "xoziZG_accountToggle",
144
- "fieldLabel": "xoziZG_fieldLabel",
145
- "heatAxis": "xoziZG_heatAxis",
146
- "statValue": "xoziZG_statValue",
147
- "modelSpec": "xoziZG_modelSpec",
148
- "heatGrid": "xoziZG_heatGrid",
149
- "usageTipRow": "xoziZG_usageTipRow",
150
- "statSub": "xoziZG_statSub",
151
- "heatHourCell": "xoziZG_heatHourCell",
199
+ "manual": "xoziZG_manual",
152
200
  "avatar": "xoziZG_avatar",
153
- "expiryRow": "xoziZG_expiryRow",
201
+ "trendTip": "xoziZG_trendTip",
202
+ "manualSummary": "xoziZG_manualSummary",
203
+ "doctorList": "xoziZG_doctorList",
154
204
  "creditRows": "xoziZG_creditRows",
155
- "error": "xoziZG_error",
156
- "accountToolbar": "xoziZG_accountToolbar",
157
- "sectionLabel": "xoziZG_sectionLabel",
158
- "doctorRow": "xoziZG_doctorRow",
159
- "desc": "xoziZG_desc",
160
- "manualForm": "xoziZG_manualForm",
161
- "barFill": "xoziZG_barFill",
162
- "tabs": "xoziZG_tabs",
163
205
  "accountEntry": "xoziZG_accountEntry",
164
- "accountInfo": "xoziZG_accountInfo",
165
- "creditFooter": "xoziZG_creditFooter",
166
- "link": "xoziZG_link",
167
- "meta": "xoziZG_meta",
168
- "card": "xoziZG_card",
169
- "accountNameRow": "xoziZG_accountNameRow",
170
- "accountRowActions": "xoziZG_accountRowActions",
171
- "accountRow": "xoziZG_accountRow",
172
- "accountToggleLabel": "xoziZG_accountToggleLabel",
206
+ "balanceRow": "xoziZG_balanceRow",
207
+ "doctorName": "xoziZG_doctorName",
208
+ "accountName": "xoziZG_accountName",
173
209
  "balanceMeta": "xoziZG_balanceMeta",
174
- "danger": "xoziZG_danger",
210
+ "barFill": "xoziZG_barFill",
211
+ "count": "xoziZG_count",
212
+ "header": "xoziZG_header",
213
+ "heatWeekday": "xoziZG_heatWeekday",
214
+ "accountToggleLabel": "xoziZG_accountToggleLabel",
215
+ "choiceRow": "xoziZG_choiceRow",
216
+ "statCard": "xoziZG_statCard",
217
+ "heatAxis": "xoziZG_heatAxis",
218
+ "check": "xoziZG_check",
219
+ "skeletonBreath": "xoziZG_skeletonBreath",
220
+ "usageTipName": "xoziZG_usageTipName",
221
+ "creditBlock": "xoziZG_creditBlock",
222
+ "bar": "xoziZG_bar",
175
223
  "creditHint": "xoziZG_creditHint",
176
- "statLabel": "xoziZG_statLabel",
177
- "heatAxisSlot": "xoziZG_heatAxisSlot",
178
224
  "actions": "xoziZG_actions",
225
+ "statValue": "xoziZG_statValue",
226
+ "statLabel": "xoziZG_statLabel",
227
+ "card": "xoziZG_card",
228
+ "modelFill": "xoziZG_modelFill",
229
+ "accountInfo": "xoziZG_accountInfo",
230
+ "accountRow": "xoziZG_accountRow",
231
+ "usageFill": "xoziZG_usageFill",
232
+ "modelTrack": "xoziZG_modelTrack",
233
+ "manualForm": "xoziZG_manualForm",
234
+ "balanceUnit": "xoziZG_balanceUnit",
235
+ "statusLine": "xoziZG_statusLine",
236
+ "link": "xoziZG_link",
237
+ "sectionHead": "xoziZG_sectionHead",
238
+ "field": "xoziZG_field",
179
239
  "modelTokens": "xoziZG_modelTokens",
180
- "heatLegend": "xoziZG_heatLegend",
181
- "creditBlock": "xoziZG_creditBlock"
240
+ "heatGrid": "xoziZG_heatGrid",
241
+ "error": "xoziZG_error",
242
+ "sectionLabel": "xoziZG_sectionLabel",
243
+ "headText": "xoziZG_headText",
244
+ "modelName": "xoziZG_modelName",
245
+ "tabPanel": "xoziZG_tabPanel",
246
+ "modelChart": "xoziZG_modelChart",
247
+ "usageBar": "xoziZG_usageBar",
248
+ "statSub": "xoziZG_statSub",
249
+ "heatAxisSlot": "xoziZG_heatAxisSlot"
182
250
  };
183
251
  //#endregion
184
252
  //#region src/client/CodeArtsPluginCard.tsx
@@ -229,15 +297,6 @@ function claimMessagesOf(data, accountIds, t) {
229
297
  return out;
230
298
  }
231
299
  /**
232
- * 开关的兜底值:后端没这条路由(老版本)时按「都显示」渲染,与原有行为一致。
233
- * 侧边栏那一格相反 —— 缺省关闭。
234
- */
235
- const DOCK_DEFAULT = {
236
- credits: true,
237
- queue: true,
238
- sidebar: false
239
- };
240
- /**
241
300
  * 上一次读到的状态。`/api/codearts/status` 会顺带去上游拉积分(有 TTL 缓存),
242
301
  * 冷的时候要等近一秒;模块级留一份快照,再进这一页就能立刻按旧值画出来,
243
302
  * 后台再刷新 —— 比每次都先闪骨架舒服,也不会把「还没读到」误判成未登录。
@@ -341,6 +400,8 @@ function CreditBlock({ credits, error, t, onClaim, claiming, claimResult, justCl
341
400
  if (credits === void 0 && error === void 0) return null;
342
401
  const c = credits?.credits;
343
402
  const claimedToday = justClaimed || credits?.welfare?.claimedToday === true;
403
+ /** 上游当前每日签到活动给多少分;没有就退回不带数字的文案。 */
404
+ const claimAmount = credits?.welfare?.amount ?? 0;
344
405
  const expiring = c?.total.expiring ?? 0;
345
406
  const expiringRatio = c !== void 0 && c.total.total > 0 ? Math.min(100, Math.max(0, expiring / c.total.total * 100)) : 0;
346
407
  const usedRatio = c !== void 0 && c.total.total > 0 ? Math.min(100, Math.max(0, c.total.used / c.total.total * 100)) : 0;
@@ -445,7 +506,7 @@ function CreditBlock({ credits, error, t, onClaim, claiming, claimResult, justCl
445
506
  }),
446
507
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
447
508
  className: CodeArtsPluginCard_module_css_default.creditHint,
448
- children: claimResult ?? t("claimHint")
509
+ children: claimResult ?? (claimAmount > 0 ? t("claimHintAmount", { amount: formatCredits(claimAmount) }) : t("claimHint"))
449
510
  })
450
511
  ]
451
512
  });
@@ -1026,10 +1087,20 @@ function CodeArtsPluginCard({ t }) {
1026
1087
  const [tab, setTab] = (0, react.useState)("accounts");
1027
1088
  const tabIdBase = (0, react.useId)();
1028
1089
  /** 对话底部那一行的两个显隐开关(后端 = 插件 settings 里的两个布尔)。 */
1029
- const [dock, setDock] = (0, react.useState)(DOCK_DEFAULT);
1030
- const [dockWritable, setDockWritable] = (0, react.useState)(false);
1031
- const [dockSaving, setDockSaving] = (0, react.useState)(false);
1090
+ const [dock, setDock] = (0, react.useState)(() => dockSnapshot().dock);
1091
+ const [dockWritable, setDockWritable] = (0, react.useState)(() => dockSnapshot().writable);
1092
+ /**
1093
+ * 正在保存的开关(按键记录)。
1094
+ *
1095
+ * 早先是一个共享布尔:点任何一个勾选框都会把**全部**勾选框置灰,POST 回来再恢复 ——
1096
+ * 肉眼就是「整个配置页的勾选都在闪」。现在只有被点的那一个在处理中。
1097
+ */
1098
+ const [dockSavingKeys, setDockSavingKeys] = (0, react.useState)(() => /* @__PURE__ */ new Set());
1032
1099
  const [dockError, setDockError] = (0, react.useState)(null);
1100
+ /** 「结束守护进程」按钮在飞,防止连点。 */
1101
+ const [keeperStopping, setKeeperStopping] = (0, react.useState)(false);
1102
+ /** 结束按钮的结果/失败原因(成功也留一句,让用户知道进程真没了)。 */
1103
+ const [keeperNotice, setKeeperNotice] = (0, react.useState)(null);
1033
1104
  /**
1034
1105
  * 首次读取状态的三态。为什么要单独记:`status === null` 只说明「还没读到」,
1035
1106
  * 直接按它画就会先闪一下「未登录」,等数据回来再翻成「已登录」—— 看起来像
@@ -1043,14 +1114,11 @@ function CodeArtsPluginCard({ t }) {
1043
1114
  if (!res.ok) return;
1044
1115
  const data = await res.json();
1045
1116
  if (data.dock !== void 0) {
1046
- const next = {
1047
- ...DOCK_DEFAULT,
1048
- ...data.dock
1049
- };
1050
- setDock(next);
1051
- setSidebarPanelWanted(next.sidebar);
1117
+ publishDock({ dock: data.dock });
1118
+ setSidebarPanelWanted(data.dock.sidebar === true);
1119
+ setSettingsEntryWanted(data.dock.settingsEntry !== false);
1052
1120
  }
1053
- setDockWritable(data.writable === true);
1121
+ publishDock({ writable: data.writable === true });
1054
1122
  } catch {}
1055
1123
  }
1056
1124
  /**
@@ -1065,7 +1133,7 @@ function CodeArtsPluginCard({ t }) {
1065
1133
  ...dock,
1066
1134
  [key]: on
1067
1135
  });
1068
- setDockSaving(true);
1136
+ setDockSavingKeys((current) => new Set(current).add(key));
1069
1137
  setDockError(null);
1070
1138
  if (key === "sidebar") setSidebarPanelWanted(on);
1071
1139
  try {
@@ -1083,19 +1151,52 @@ function CodeArtsPluginCard({ t }) {
1083
1151
  }
1084
1152
  const data = await res.json();
1085
1153
  if (data.dock !== void 0) {
1086
- const next = {
1087
- ...DOCK_DEFAULT,
1088
- ...data.dock
1089
- };
1090
- setDock(next);
1091
- setSidebarPanelWanted(next.sidebar);
1154
+ publishDock({ dock: data.dock });
1155
+ setSidebarPanelWanted(data.dock.sidebar === true);
1156
+ setSettingsEntryWanted(data.dock.settingsEntry !== false);
1092
1157
  }
1093
1158
  } catch (error) {
1094
1159
  setDock(previous);
1095
1160
  if (key === "sidebar") setSidebarPanelWanted(previous.sidebar);
1096
1161
  setDockError(error instanceof Error ? error.message : String(error));
1097
1162
  } finally {
1098
- setDockSaving(false);
1163
+ setDockSavingKeys((current) => {
1164
+ if (!current.has(key)) return current;
1165
+ const next = new Set(current);
1166
+ next.delete(key);
1167
+ return next;
1168
+ });
1169
+ }
1170
+ }
1171
+ /**
1172
+ * 结束守护进程。
1173
+ *
1174
+ * 服务端在kill之后**顺手把开关写成 false**(见 web-status.ts 的 keeperStopHandler):
1175
+ * 只杀进程不改开关会留下「开关开着却没进程」的矛盾状态,插件下次启动还会把它拉起来。
1176
+ * 这里拿响应里的 `dock` 直接覆盖本地状态,不等下一轮 refreshDock —— 否则按钮点完
1177
+ * 界面上开关还亮着,用户会以为没生效。
1178
+ */
1179
+ async function stopKeeper() {
1180
+ setKeeperStopping(true);
1181
+ setKeeperNotice(null);
1182
+ try {
1183
+ const res = await fetch("/api/codearts/keeper/stop", {
1184
+ method: "POST",
1185
+ headers: {
1186
+ "Content-Type": "application/json",
1187
+ Accept: "application/json"
1188
+ },
1189
+ body: "{}"
1190
+ });
1191
+ const data = await res.json().catch(() => ({}));
1192
+ if (data.dock !== void 0) publishDock({ dock: data.dock });
1193
+ if (!res.ok || data.ok === false) setKeeperNotice(t("displayKeeperStopFailed", { message: data.reason ?? data.error ?? `HTTP ${res.status}` }));
1194
+ else setKeeperNotice(t("displayKeeperStopped"));
1195
+ } catch (error) {
1196
+ setKeeperNotice(t("displayKeeperStopFailed", { message: error instanceof Error ? error.message : String(error) }));
1197
+ } finally {
1198
+ setKeeperStopping(false);
1199
+ await Promise.all([refreshDock(), refresh()]);
1099
1200
  }
1100
1201
  }
1101
1202
  /**
@@ -1171,6 +1272,10 @@ function CodeArtsPluginCard({ t }) {
1171
1272
  (0, react.useEffect)(() => {
1172
1273
  refreshDock();
1173
1274
  }, []);
1275
+ (0, react.useEffect)(() => subscribeDock(() => {
1276
+ setDock(dockSnapshot().dock);
1277
+ setDockWritable(dockSnapshot().writable);
1278
+ }), []);
1174
1279
  (0, react.useEffect)(() => {
1175
1280
  if (status?.status === "signed-in") refreshSelection();
1176
1281
  }, [status?.status]);
@@ -1935,33 +2040,154 @@ function CodeArtsPluginCard({ t }) {
1935
2040
  }),
1936
2041
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1937
2042
  className: CodeArtsPluginCard_module_css_default.choices,
1938
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2043
+ children: [
2044
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2045
+ className: CodeArtsPluginCard_module_css_default.choiceRow,
2046
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Checkbox, {
2047
+ className: CodeArtsPluginCard_module_css_default.check,
2048
+ checked: dock.credits,
2049
+ disabled: !dockWritable || dockSavingKeys.has("credits"),
2050
+ onChange: (on) => void toggleDock("credits", on),
2051
+ label: t("displayCreditsToggle")
2052
+ })
2053
+ }),
2054
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2055
+ className: CodeArtsPluginCard_module_css_default.choiceRow,
2056
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Checkbox, {
2057
+ className: CodeArtsPluginCard_module_css_default.check,
2058
+ checked: dock.queue,
2059
+ disabled: !dockWritable || dockSavingKeys.has("queue"),
2060
+ onChange: (on) => void toggleDock("queue", on),
2061
+ label: t("displayQueueToggle")
2062
+ })
2063
+ }),
2064
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2065
+ className: CodeArtsPluginCard_module_css_default.choiceRow,
2066
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Checkbox, {
2067
+ className: CodeArtsPluginCard_module_css_default.check,
2068
+ checked: dock.modelDetail,
2069
+ disabled: !dockWritable || dockSavingKeys.has("modelDetail"),
2070
+ onChange: (on) => void toggleDock("modelDetail", on),
2071
+ label: t("displayModelDetailToggle")
2072
+ })
2073
+ })
2074
+ ]
2075
+ }),
2076
+ !dockWritable && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
2077
+ className: CodeArtsPluginCard_module_css_default.hint,
2078
+ children: t("displayNotWritable")
2079
+ }),
2080
+ dockError !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
2081
+ className: CodeArtsPluginCard_module_css_default.error,
2082
+ children: t("displayFailed", { message: dockError })
2083
+ })
2084
+ ]
2085
+ }),
2086
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2087
+ className: CodeArtsPluginCard_module_css_default.section,
2088
+ children: [
2089
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2090
+ className: CodeArtsPluginCard_module_css_default.sectionHead,
2091
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2092
+ className: CodeArtsPluginCard_module_css_default.sectionLabel,
2093
+ children: t("displayAutoClaimTitle")
2094
+ })
2095
+ }),
2096
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
2097
+ className: CodeArtsPluginCard_module_css_default.hint,
2098
+ children: t("displayAutoClaimHint")
2099
+ }),
2100
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2101
+ className: CodeArtsPluginCard_module_css_default.choices,
2102
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1939
2103
  className: CodeArtsPluginCard_module_css_default.choiceRow,
1940
2104
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Checkbox, {
1941
2105
  className: CodeArtsPluginCard_module_css_default.check,
1942
- checked: dock.credits,
1943
- disabled: !dockWritable || dockSaving,
1944
- onChange: (on) => void toggleDock("credits", on),
1945
- label: t("displayCreditsToggle")
2106
+ checked: dock.autoClaim,
2107
+ disabled: !dockWritable || dockSavingKeys.has("autoClaim"),
2108
+ onChange: (on) => void toggleDock("autoClaim", on),
2109
+ label: t("displayAutoClaimToggle")
1946
2110
  })
1947
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2111
+ })
2112
+ })
2113
+ ]
2114
+ }),
2115
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2116
+ className: CodeArtsPluginCard_module_css_default.section,
2117
+ children: [
2118
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2119
+ className: CodeArtsPluginCard_module_css_default.sectionHead,
2120
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2121
+ className: CodeArtsPluginCard_module_css_default.sectionLabel,
2122
+ children: t("displayKeeperTitle")
2123
+ }), dock.keepAliveDaemon && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
2124
+ variant: "outline",
2125
+ size: "sm",
2126
+ disabled: keeperStopping,
2127
+ onClick: () => void stopKeeper(),
2128
+ children: keeperStopping ? t("displayKeeperStopping") : t("displayKeeperStop")
2129
+ })]
2130
+ }),
2131
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
2132
+ className: CodeArtsPluginCard_module_css_default.hint,
2133
+ children: t("displayKeeperHint")
2134
+ }),
2135
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2136
+ className: CodeArtsPluginCard_module_css_default.choices,
2137
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1948
2138
  className: CodeArtsPluginCard_module_css_default.choiceRow,
1949
2139
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Checkbox, {
1950
2140
  className: CodeArtsPluginCard_module_css_default.check,
1951
- checked: dock.queue,
1952
- disabled: !dockWritable || dockSaving,
1953
- onChange: (on) => void toggleDock("queue", on),
1954
- label: t("displayQueueToggle")
2141
+ checked: dock.keepAliveDaemon,
2142
+ disabled: !dockWritable || dockSavingKeys.has("keepAliveDaemon"),
2143
+ onChange: (on) => void toggleDock("keepAliveDaemon", on),
2144
+ label: t("displayKeeperToggle")
1955
2145
  })
1956
- })]
2146
+ })
1957
2147
  }),
1958
- !dockWritable && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
2148
+ dock.keepAliveDaemon && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1959
2149
  className: CodeArtsPluginCard_module_css_default.hint,
1960
- children: t("displayNotWritable")
2150
+ children: status?.keeper?.alive === true ? t("displayKeeperRunning", {
2151
+ pid: status.keeper.pid ?? "?",
2152
+ time: formatStored(status.keeper.heartbeatAt)
2153
+ }) : status?.keeper?.starting === true ? t("displayKeeperStarting") : t("displayKeeperDown", { message: status?.keeper?.error ?? "" })
1961
2154
  }),
1962
- dockError !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1963
- className: CodeArtsPluginCard_module_css_default.error,
1964
- children: t("displayFailed", { message: dockError })
2155
+ keeperNotice !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
2156
+ className: CodeArtsPluginCard_module_css_default.hint,
2157
+ children: keeperNotice
2158
+ }),
2159
+ status?.keeper?.logPath !== void 0 && dock.keepAliveDaemon && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
2160
+ className: CodeArtsPluginCard_module_css_default.hint,
2161
+ children: t("displayKeeperLog", { path: status.keeper.logPath })
2162
+ })
2163
+ ]
2164
+ }),
2165
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2166
+ className: CodeArtsPluginCard_module_css_default.section,
2167
+ children: [
2168
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2169
+ className: CodeArtsPluginCard_module_css_default.sectionHead,
2170
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2171
+ className: CodeArtsPluginCard_module_css_default.sectionLabel,
2172
+ children: t("displaySettingsEntryTitle")
2173
+ })
2174
+ }),
2175
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
2176
+ className: CodeArtsPluginCard_module_css_default.hint,
2177
+ children: t("displaySettingsEntryHint")
2178
+ }),
2179
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2180
+ className: CodeArtsPluginCard_module_css_default.choices,
2181
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2182
+ className: CodeArtsPluginCard_module_css_default.choiceRow,
2183
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Checkbox, {
2184
+ className: CodeArtsPluginCard_module_css_default.check,
2185
+ checked: dock.settingsEntry,
2186
+ disabled: !dockWritable || dockSavingKeys.has("settingsEntry"),
2187
+ onChange: (on) => void toggleDock("settingsEntry", on),
2188
+ label: t("displaySettingsEntryToggle")
2189
+ })
2190
+ })
1965
2191
  })
1966
2192
  ]
1967
2193
  }),
@@ -1986,7 +2212,7 @@ function CodeArtsPluginCard({ t }) {
1986
2212
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Checkbox, {
1987
2213
  className: CodeArtsPluginCard_module_css_default.check,
1988
2214
  checked: dock.sidebar,
1989
- disabled: !dockWritable || dockSaving,
2215
+ disabled: !dockWritable || dockSavingKeys.has("sidebar"),
1990
2216
  onChange: (on) => void toggleDock("sidebar", on),
1991
2217
  label: t("displaySidebarToggle")
1992
2218
  })
@@ -2101,12 +2327,14 @@ function CodeArtsPluginCard({ t }) {
2101
2327
  //#region src/client/dock-line.ts
2102
2328
  /** 段分隔符 —— 与邻居插件一致,改这里等于改整行的样子。 */
2103
2329
  const DOCK_SEGMENT_SEPARATOR = " · ";
2104
- function buildDockLine(parts, t) {
2330
+ function buildDockLine(parts, t, showModelDetail = true) {
2105
2331
  const rest = [];
2106
2332
  rest.push(t("dockProvider", { provider: parts.provider }));
2107
- rest.push(parts.model === void 0 ? t("dockNoModel") : t("dockModel", { model: parts.model }));
2108
- if (parts.ratio !== void 0) rest.push(parts.ratio);
2109
- if (parts.queue !== void 0) rest.push(parts.queue);
2333
+ if (showModelDetail) {
2334
+ rest.push(parts.model === void 0 ? t("dockNoModel") : t("dockModel", { model: parts.model }));
2335
+ if (parts.ratio !== void 0) rest.push(parts.ratio);
2336
+ if (parts.queue !== void 0) rest.push(parts.queue);
2337
+ }
2110
2338
  return {
2111
2339
  ...parts.credits === void 0 ? {} : { credits: parts.credits },
2112
2340
  rest: rest.join(DOCK_SEGMENT_SEPARATOR)
@@ -2208,7 +2436,7 @@ const QUEUE_INTERVAL_MS = 5e3;
2208
2436
  * `min(248px, …)`)取一档窄宽度 —— 这一层回答的是「哪个号还有多少积分」,
2209
2437
  * 用量数字不该把它撑成一张报表。
2210
2438
  */
2211
- const PANEL_WIDTH = 260;
2439
+ const PANEL_WIDTH = 280;
2212
2440
  /** 弹层与那一行之间的缝隙。 */
2213
2441
  const PANEL_GAP = 8;
2214
2442
  /**
@@ -2320,7 +2548,7 @@ function rowsOf(data) {
2320
2548
  function placeAbove(rect) {
2321
2549
  return rect.top > PANEL_MIN_ABOVE;
2322
2550
  }
2323
- function CodeArtsCreditDock({ useProjection, t, zone = "dock" }) {
2551
+ function CodeArtsCreditDock({ useProjection, t, zone = "dock", onOpenSettings }) {
2324
2552
  const selection = readSelection(useProjection);
2325
2553
  const active = isCodeArts(selection);
2326
2554
  const [remain, setRemain] = (0, react.useState)(null);
@@ -2332,12 +2560,12 @@ function CodeArtsCreditDock({ useProjection, t, zone = "dock" }) {
2332
2560
  * 名字用 `stripModelSuffixes` 剥掉尾巴,倍率直接用服务端算好的 `ratio`。
2333
2561
  */
2334
2562
  const [modelInfo, setModelInfo] = (0, react.useState)({});
2335
- const [flags, setFlags] = (0, react.useState)({
2336
- credits: true,
2337
- queue: true,
2338
- sidebar: false
2339
- });
2563
+ const [flags, setFlags] = (0, react.useState)(() => dockSnapshot().dock);
2564
+ /** 开关的共享状态:设置页改了「显示」里的勾选,弹层这边立刻跟上。 */
2565
+ (0, react.useEffect)(() => subscribeDock(() => setFlags(dockSnapshot().dock)), []);
2340
2566
  const [queued, setQueued] = (0, react.useState)(null);
2567
+ /** 「设置」按钮两条路都没走通时的提示(宿主壳形状不认识)。 */
2568
+ const [settingsFailed, setSettingsFailed] = (0, react.useState)(false);
2341
2569
  const [anchor, setAnchor] = (0, react.useState)(null);
2342
2570
  /**
2343
2571
  * 弹层的包含块原点(视口坐标)。
@@ -2369,11 +2597,7 @@ function CodeArtsCreditDock({ useProjection, t, zone = "dock" }) {
2369
2597
  if (!res.ok) return;
2370
2598
  const data = await res.json().catch(() => void 0);
2371
2599
  if (data === void 0 || !mounted.current) return;
2372
- setFlags(data.dock ?? {
2373
- credits: true,
2374
- queue: true,
2375
- sidebar: false
2376
- });
2600
+ if (data.dock !== void 0) publishDock({ dock: data.dock });
2377
2601
  setRows(rowsOf(data));
2378
2602
  setModelInfo(Object.fromEntries((data.models ?? []).map((model) => [model.id, {
2379
2603
  name: model.name,
@@ -2496,7 +2720,7 @@ function CodeArtsCreditDock({ useProjection, t, zone = "dock" }) {
2496
2720
  ...modelLabel === "" ? {} : { model: modelLabel },
2497
2721
  ...ratio === void 0 ? {} : { ratio },
2498
2722
  ...zone === "dock" && showQueue && queued !== null ? { queue: t("queueDock", { position: queued.position }) } : {}
2499
- }, t);
2723
+ }, t, flags.modelDetail !== false);
2500
2724
  const fetchedAt = rows.reduce((latest, row) => Math.max(latest, row.fetchedAt ?? 0), 0);
2501
2725
  const lastUpdated = fetchedAt > 0 ? formatClock(fetchedAt) : "";
2502
2726
  const toggle = (event) => {
@@ -2593,16 +2817,46 @@ function CodeArtsCreditDock({ useProjection, t, zone = "dock" }) {
2593
2817
  gap: 8
2594
2818
  },
2595
2819
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2596
- style: { fontWeight: 600 },
2820
+ style: {
2821
+ fontWeight: 600,
2822
+ flex: "1 1 auto",
2823
+ minWidth: 0,
2824
+ overflow: "hidden",
2825
+ textOverflow: "ellipsis",
2826
+ whiteSpace: "nowrap"
2827
+ },
2597
2828
  children: t("creditsDockPanelTitle")
2598
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
2599
- variant: "outline",
2600
- size: "sm",
2601
- disabled: refreshing,
2602
- onClick: () => void forceRefresh(),
2603
- children: refreshing ? t("creditsDockRefreshing") : t("creditsDockRefresh")
2829
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
2830
+ style: {
2831
+ display: "inline-flex",
2832
+ alignItems: "center",
2833
+ gap: 6,
2834
+ flex: "0 0 auto",
2835
+ whiteSpace: "nowrap"
2836
+ },
2837
+ children: [onOpenSettings !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
2838
+ variant: "outline",
2839
+ size: "sm",
2840
+ style: { whiteSpace: "nowrap" },
2841
+ onClick: () => setSettingsFailed(!onOpenSettings()),
2842
+ children: t("creditsDockSettings")
2843
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
2844
+ variant: "outline",
2845
+ size: "sm",
2846
+ style: { whiteSpace: "nowrap" },
2847
+ disabled: refreshing,
2848
+ onClick: () => void forceRefresh(),
2849
+ children: refreshing ? t("creditsDockRefreshing") : t("creditsDockRefresh")
2850
+ })]
2604
2851
  })]
2605
2852
  }),
2853
+ settingsFailed && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
2854
+ style: {
2855
+ fontSize: 11,
2856
+ color: "var(--dsw-alias-label-tertiary)"
2857
+ },
2858
+ children: t("creditsDockSettingsFailed")
2859
+ }),
2606
2860
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2607
2861
  style: {
2608
2862
  display: "flex",
@@ -2691,14 +2945,14 @@ if (typeof document !== "undefined" && document.querySelector("style[data-plugin
2691
2945
  document.head.appendChild(tag);
2692
2946
  }
2693
2947
  var CodeArtsPanel_module_css_default = {
2694
- "title": "Z66cgG_title",
2948
+ "icon": "Z66cgG_icon",
2695
2949
  "desc": "Z66cgG_desc",
2696
- "backCaret": "Z66cgG_backCaret",
2697
- "head": "Z66cgG_head",
2698
2950
  "back": "Z66cgG_back",
2951
+ "backCaret": "Z66cgG_backCaret",
2699
2952
  "page": "Z66cgG_page",
2700
2953
  "body": "Z66cgG_body",
2701
- "icon": "Z66cgG_icon"
2954
+ "head": "Z66cgG_head",
2955
+ "title": "Z66cgG_title"
2702
2956
  };
2703
2957
  //#endregion
2704
2958
  //#region src/client/CodeArtsPanel.tsx
@@ -2769,6 +3023,84 @@ function CodeArtsPanelPage({ t, backToConversation }) {
2769
3023
  });
2770
3024
  }
2771
3025
  //#endregion
3026
+ //#region src/client/settings-route.ts
3027
+ /**
3028
+ * 「打开设置 → CodeArts」这条路的实现。
3029
+ *
3030
+ * 宿主没有给插件一个直白的「打开某节设置」服务,但设置壳把自己挂在
3031
+ * `sidebar.settings` 槽位上,并且带了一个 **store seat**:
3032
+ *
3033
+ * const shellHandle = createSettingsShellStore()
3034
+ * const shellInstance = shellHandle.create()
3035
+ * ctx.slots.register({ name: 'sidebar.settings', store: { ...shellHandle, create: () => shellInstance }, … })
3036
+ *
3037
+ * 这个 seat 是壳公开的状态把手(`StoredEntry.store` 是文档字段,`slots.entries()`
3038
+ * 是公开方法;宿主自己的客户端测试也这么读)。`actions.openSection(id)` 一次把
3039
+ * `activeId = id` 和 `open = true` 都设上,正好是「在 CodeArts 那一节打开设置」。
3040
+ *
3041
+ * 旧壳没有 `openSection` 时退回到「打开设置面板 + 点同名导航行」。判断按**逐字**
3042
+ * 相等:`模型` 是 `模型与预设` 的子串,模糊匹配会点错节。两条路都不抛异常 ——
3043
+ * 调用方是一个按钮的 click handler,抛出去会把整条积分行带没。
3044
+ *
3045
+ * @module dsh-codearts/client/settings-route
3046
+ */
3047
+ /** 设置壳所在的槽位:它的 store seat 就是对外唯一的状态把手。 */
3048
+ const SETTINGS_SLOT = "sidebar.settings";
3049
+ /** 面板挂载后导航行的标签要等一次 locale 快照,所以重试几次、总共约 300ms。 */
3050
+ const RETRY_DELAYS_MS = [
3051
+ 0,
3052
+ 60,
3053
+ 70,
3054
+ 80,
3055
+ 90
3056
+ ];
3057
+ function defaultSchedule(run, ms) {
3058
+ globalThis.setTimeout(run, ms);
3059
+ }
3060
+ function findSectionRow(scope, label) {
3061
+ const want = label.trim();
3062
+ if (want === "") return void 0;
3063
+ return Array.from(scope.querySelectorAll("button")).find((button) => (button.textContent ?? "").trim() === want);
3064
+ }
3065
+ /**
3066
+ * 打开本插件的设置节。
3067
+ *
3068
+ * @returns true = 已经走通一条路(设置面板会在我们这一节打开,或至少已打开)。
3069
+ */
3070
+ function openPluginSettings(deps) {
3071
+ try {
3072
+ const openSection = ((deps.slots?.entries?.(SETTINGS_SLOT))?.[0]?.store?.create?.())?.actions?.openSection;
3073
+ if (typeof openSection === "function") {
3074
+ openSection(deps.sectionId);
3075
+ return true;
3076
+ }
3077
+ } catch {}
3078
+ const doc = deps.doc ?? (typeof document === "undefined" ? void 0 : document);
3079
+ const label = deps.label?.() ?? "";
3080
+ try {
3081
+ const invoke = deps.shortcuts?.invoke;
3082
+ if (typeof invoke === "function") invoke("settings.open", { modal: null });
3083
+ else return false;
3084
+ } catch {
3085
+ return false;
3086
+ }
3087
+ if (doc === void 0 || label.trim() === "") return true;
3088
+ const schedule = deps.schedule ?? defaultSchedule;
3089
+ const scopeOf = () => doc.querySelector("[data-shortcut-modal=\"settings\"]") ?? doc;
3090
+ let clicked = false;
3091
+ for (const delay of RETRY_DELAYS_MS) schedule(() => {
3092
+ if (clicked) return;
3093
+ try {
3094
+ const row = findSectionRow(scopeOf(), label);
3095
+ if (row !== void 0) {
3096
+ clicked = true;
3097
+ row.click();
3098
+ }
3099
+ } catch {}
3100
+ }, delay);
3101
+ return true;
3102
+ }
3103
+ //#endregion
2772
3104
  //#region src/client/locales.ts
2773
3105
  const zh = {
2774
3106
  tabLabel: "CodeArts",
@@ -2925,6 +3257,8 @@ const zh = {
2925
3257
  creditsDockPanelTitle: "CodeArts 积分",
2926
3258
  creditsDockRefresh: "刷新积分",
2927
3259
  creditsDockRefreshing: "刷新中…",
3260
+ creditsDockSettings: "设置",
3261
+ creditsDockSettingsFailed: "打不开设置面板,请从「设置 → CodeArts」进入。",
2928
3262
  creditsDockNoTokens: "今天还没有经插件发出的请求",
2929
3263
  creditsDockEmpty: "暂时没有积分数据",
2930
3264
  creditsDockExpiring: "{account}:{expiring} 积分将在本周期结束时作废",
@@ -2934,11 +3268,29 @@ const zh = {
2934
3268
  dockNoModel: "未选择模型",
2935
3269
  tabDisplay: "显示",
2936
3270
  displayTitle: "输入框两侧显示",
2937
- displayHint: "这两项只管输入框下方那一行的积分与排队两段;中间那段「Provider CodeArts · Model 模型 · 倍率」一直显示,不受开关影响。底部那条每 60 秒读一次设置,所以关掉最多要等一分钟才见效。",
3271
+ displayHint: "这几项只管输入框上下那两行显示什么,不影响任何请求。`Provider CodeArts` 是插件的身份标识,一直显示,不受开关控制;「显示模型与倍率」只收掉它右边那段(模型名、倍率、排队)。底部那条每 60 秒读一次设置,所以关掉最多要等一分钟才见效。",
2938
3272
  displayCreditsToggle: "在输入框工具行显示剩余积分(点开可看各账号明细)",
2939
3273
  displayQueueToggle: "显示上游排队位置",
3274
+ displayModelDetailToggle: "显示模型与倍率(Provider CodeArts 不受影响,始终显示)",
3275
+ displayAutoClaimTitle: "每日签到积分",
3276
+ displayAutoClaimHint: "打开后,DSH 启动约 30 秒会自动把每个已登录账号的每日签到积分领一遍;没领到会隔 30 分钟再试,最多 3 次。上游按天去重,重复领取不会出错。领取结果可以点开积分条查看。注意:这个功能只在 DSH 运行时生效,关掉 DSH 后不会替你领。",
3277
+ displayAutoClaimToggle: "自动领取每日签到积分(默认关闭)",
3278
+ displayKeeperTitle: "常驻保活(DSH 关掉后仍续登录)",
3279
+ displayKeeperHint: "上游给的登录凭证只活 2 小时,但要靠它换新的登录凭证(refresh token),那个能活 30 天。打开这一项后,DSH 会在系统里另起一个独立的后台进程,每 20 分钟替你续一次——所以哪怕 DSH 关着、好几天不开,回来也不用重新登录。这个进程不随 DSH 退出,要用下面的「结束」按钮手动停。默认关闭:不经你同意就在系统里留一个常驻进程不合适。",
3280
+ displayKeeperToggle: "开启常驻保活进程(默认关闭)",
3281
+ displayKeeperRunning: "后台进程运行中 · PID {pid} · 最近心跳 {time}",
3282
+ displayKeeperStarting: "后台进程正在启动……稍等几秒刷新这一页。",
3283
+ displayKeeperDown: "后台进程没有在跑(可能被你结束或启动失败),保活开关已关闭。{message}",
3284
+ displayKeeperStop: "结束进程",
3285
+ displayKeeperStopping: "正在结束……",
3286
+ displayKeeperStopped: "后台进程已结束,保活开关已同时关闭。",
3287
+ displayKeeperStopFailed: "结束失败:{message}",
3288
+ displayKeeperLog: "进程日志:{path}",
2940
3289
  displayNotWritable: "这个宿主没给插件开配置存储,开关只能看不能改。",
2941
3290
  displayFailed: "保存失败:{message}",
3291
+ displaySettingsEntryTitle: "设置左侧入口",
3292
+ displaySettingsEntryHint: "勾上以后,DSH 设置左侧那一列里会多一项 CodeArts,点开就是当前这一页。默认勾上:插件自带的配置页本来挂在「内置插件」的详情页里,第一次用的人基本找不到。不想要可以在这里关掉,关掉后仍可从「内置插件 → dsh-codearts」进入。改完立刻生效。",
3293
+ displaySettingsEntryToggle: "在设置左侧导航显示 CodeArts",
2942
3294
  displaySidebarTitle: "侧边栏图标",
2943
3295
  displaySidebarHint: "勾上以后,DSH 左侧那一列图标里会多一个 CodeArts,点它直接在中间列打开当前这一页,不必每次都绕进设置。默认不勾:这列图标是全宿主共用的,每个插件都来占一格很快就挤满了。改完立刻生效,没有保存步骤。",
2944
3296
  displaySidebarToggle: "在侧边栏图标列显示 CodeArts",
@@ -2948,7 +3300,8 @@ const zh = {
2948
3300
  claimButtonDone: "今日已领",
2949
3301
  claimPending: "领取中…",
2950
3302
  claimAll: "全部账号领取",
2951
- claimHint: "每天领一次 1000 积分,走官方福利中心接口(与客户端里那个「每日签到」同一件事)。",
3303
+ claimHint: "每天可领一次签到积分,走官方福利中心接口(与客户端里那个「每日签到」同一件事)。",
3304
+ claimHintAmount: "每天领一次 {amount} 积分,走官方福利中心接口(与客户端里那个「每日签到」同一件事)。",
2952
3305
  claimDone: "已领取 {amount} 积分",
2953
3306
  claimAlready: "今日已领,明天再来",
2954
3307
  claimUnavailable: "这个账号当前没有可领的签到活动",
@@ -3111,6 +3464,8 @@ const en = {
3111
3464
  creditsDockPanelTitle: "CodeArts credits",
3112
3465
  creditsDockRefresh: "Refresh credits",
3113
3466
  creditsDockRefreshing: "Refreshing…",
3467
+ creditsDockSettings: "Settings",
3468
+ creditsDockSettingsFailed: "Could not open Settings. Open Settings → CodeArts instead.",
3114
3469
  creditsDockNoTokens: "No requests through the plugin today yet",
3115
3470
  creditsDockEmpty: "No credit data yet",
3116
3471
  creditsDockExpiring: "{account}: {expiring} credits expire when this cycle ends",
@@ -3120,11 +3475,29 @@ const en = {
3120
3475
  dockNoModel: "No model selected",
3121
3476
  tabDisplay: "Display",
3122
3477
  displayTitle: "Around the chat input box",
3123
- displayHint: "These two only control the credits and queue segments of that line under the input box; the middle “Provider CodeArts · Model … · rate” segments always show. The bar re-reads settings every 60 seconds, so hiding the rest can take up to a minute.",
3478
+ displayHint: "These only change what the two lines around the input box show; nothing here touches a request. \"Provider CodeArts\" identifies the plugin and always shows. \"Model and rate\" hides only the part to its right (model name, rate, queue). The bar re-reads settings every 60 seconds, so a change can take up to a minute.",
3124
3479
  displayCreditsToggle: "Show remaining credits in the composer tool row (click for per-account details)",
3125
3480
  displayQueueToggle: "Show the upstream queue position",
3481
+ displayModelDetailToggle: "Show the model and rate (Provider CodeArts is not affected and always shows)",
3482
+ displayAutoClaimTitle: "Daily sign-in credits",
3483
+ displayAutoClaimHint: "When on, about 30 seconds after DSH starts the plugin claims the daily sign-in credits for every signed-in account; if nothing was claimed it retries after 30 minutes, up to 3 times. Upstream deduplicates by day, so claiming twice is harmless. Open the credits bar to see the result. Note: this only runs while DSH is running — it cannot claim for you once DSH is closed.",
3484
+ displayAutoClaimToggle: "Claim daily sign-in credits automatically (off by default)",
3485
+ displayKeeperTitle: "Keep-alive process (stays signed in while DSH is closed)",
3486
+ displayKeeperHint: "The login token upstream hands out only lives 2 hours, but the refresh token behind it lives 30 days. With this on, DSH starts a separate background process that refreshes the credential every 20 minutes — so even after DSH has been closed for days, you come back without signing in again. That process outlives DSH; stop it with the button below. Off by default: leaving a resident process on your machine without asking is not something a plugin should do.",
3487
+ displayKeeperToggle: "Run the keep-alive background process (off by default)",
3488
+ displayKeeperRunning: "Background process running · PID {pid} · last heartbeat {time}",
3489
+ displayKeeperStarting: "The background process is starting… refresh this page in a few seconds.",
3490
+ displayKeeperDown: "The background process is not running (stopped by you, or it failed to start); the keep-alive switch has been turned off. {message}",
3491
+ displayKeeperStop: "Stop process",
3492
+ displayKeeperStopping: "Stopping…",
3493
+ displayKeeperStopped: "Background process stopped and the keep-alive switch turned off.",
3494
+ displayKeeperStopFailed: "Failed to stop: {message}",
3495
+ displayKeeperLog: "Process log: {path}",
3126
3496
  displayNotWritable: "This host gives the plugin nowhere to persist settings, so the switches are read-only.",
3127
3497
  displayFailed: "Failed to save: {message}",
3498
+ displaySettingsEntryTitle: "Settings entry",
3499
+ displaySettingsEntryHint: "Once checked, a CodeArts item joins the left navigation of DSH Settings and opens this very page. On by default: the plugin-owned page otherwise lives inside the Built-in plugins detail page, which first-time users rarely find. Uncheck to hide it — the page stays reachable from Built-in plugins → dsh-codearts. Takes effect immediately.",
3500
+ displaySettingsEntryToggle: "Show CodeArts in the Settings navigation",
3128
3501
  displaySidebarTitle: "Sidebar icon",
3129
3502
  displaySidebarHint: "Once checked, a CodeArts icon joins the icon column on the left of DSH and opens this very page in the middle column, so you do not have to go through Settings each time. Off by default: that column is shared by the whole host, and it fills up quickly if every plugin claims a slot. Takes effect immediately — there is nothing to save.",
3130
3503
  displaySidebarToggle: "Show CodeArts in the sidebar icon column",
@@ -3134,7 +3507,8 @@ const en = {
3134
3507
  claimButtonDone: "Claimed today",
3135
3508
  claimPending: "Claiming…",
3136
3509
  claimAll: "Claim for all accounts",
3137
- claimHint: "Claim 1,000 credits once a day through CodeArts’ welfare centre — the same check-in the official client does.",
3510
+ claimHint: "Claim your check-in credits once a day through CodeArts’ welfare centre — the same check-in the official client does.",
3511
+ claimHintAmount: "Claim {amount} credits once a day through CodeArts’ welfare centre — the same check-in the official client does.",
3138
3512
  claimDone: "Claimed {amount} credits",
3139
3513
  claimAlready: "Already claimed today — come back tomorrow",
3140
3514
  claimUnavailable: "No check-in campaign available for this account",
@@ -3171,6 +3545,19 @@ function apply(ctx) {
3171
3545
  en
3172
3546
  }), "dsh-codearts: settings copy");
3173
3547
  const t = ctx.locale.bind(namespace);
3548
+ /**
3549
+ * 打开「设置 → CodeArts」。
3550
+ *
3551
+ * 宿主没有直白的「打开某节设置」服务,走设置壳公开挂在 `sidebar.settings`
3552
+ * 槽位上的 store seat(见 settings-route.ts 的说明)。点按钮时现取,不缓存:
3553
+ * 那个槽位属于另一个 bundle,apply 顺序不是我们能假定的。
3554
+ */
3555
+ const openSettings = () => openPluginSettings({
3556
+ slots: ctx.slots,
3557
+ shortcuts: ctx.get("shortcuts"),
3558
+ sectionId: PANEL_ID,
3559
+ label: () => t("tabLabel")
3560
+ });
3174
3561
  ctx.slots.inject("plugins.bundle.config", () => ctx.slots.register({
3175
3562
  name: "plugins.bundle.config",
3176
3563
  key: "dsh-codearts",
@@ -3183,7 +3570,8 @@ function apply(ctx) {
3183
3570
  locale: namespace,
3184
3571
  inject: () => ({
3185
3572
  t,
3186
- zone: "bar"
3573
+ zone: "bar",
3574
+ onOpenSettings: openSettings
3187
3575
  })
3188
3576
  }, CodeArtsCreditDock));
3189
3577
  ctx.slots.inject("conversation.composer.dock", () => ctx.slots.register({
@@ -3193,7 +3581,8 @@ function apply(ctx) {
3193
3581
  locale: namespace,
3194
3582
  inject: () => ({
3195
3583
  t,
3196
- zone: "dock"
3584
+ zone: "dock",
3585
+ onOpenSettings: openSettings
3197
3586
  })
3198
3587
  }, CodeArtsCreditDock));
3199
3588
  /** 每次 claim 拿到的 inject disposer;拆的时候逐个调用(连带注销里面的注册)。 */
@@ -3268,11 +3657,76 @@ function apply(ctx) {
3268
3657
  dropPanelSlots();
3269
3658
  };
3270
3659
  }, "dsh-codearts: sidebar panel opt-in");
3660
+ /**
3661
+ * 设置左侧导航里的入口(settings.section)。
3662
+ *
3663
+ * 和侧边栏那格一样按「注册 / 拆注册」实现:宿主是按槽位条目画导航行的,
3664
+ * 渲染 null 只会留下一个空白可点的行。缺省开 —— 这是用户找插件的主路径
3665
+ * (issue #7),只有明确关掉才拆。
3666
+ */
3667
+ const settingsEntryClaims = [];
3668
+ const dropSettingsEntry = () => {
3669
+ for (const dispose of settingsEntryClaims.splice(0)) try {
3670
+ dispose();
3671
+ } catch (error) {
3672
+ console.error("[dsh-codearts] failed to release settings entry:", error);
3673
+ }
3674
+ };
3675
+ const syncSettingsEntry = () => {
3676
+ dropSettingsEntry();
3677
+ if (!settingsEntryWanted()) return;
3678
+ try {
3679
+ settingsEntryClaims.push(ctx.slots.inject("settings.section", () => {
3680
+ try {
3681
+ return ctx.slots.register({
3682
+ name: "settings.section",
3683
+ id: PANEL_ID,
3684
+ order: 50,
3685
+ label: () => t("tabLabel"),
3686
+ locale: namespace,
3687
+ inject: () => ({ t })
3688
+ }, CodeArtsPluginCard);
3689
+ } catch (error) {
3690
+ console.error("[dsh-codearts] settings entry unavailable:", error);
3691
+ return () => {};
3692
+ }
3693
+ }));
3694
+ } catch (error) {
3695
+ console.error("[dsh-codearts] settings section slot unavailable:", error);
3696
+ }
3697
+ };
3698
+ ctx.effect(() => {
3699
+ const off = subscribeSettingsEntryWanted(syncSettingsEntry);
3700
+ syncSettingsEntry();
3701
+ return () => {
3702
+ off();
3703
+ dropSettingsEntry();
3704
+ };
3705
+ }, "dsh-codearts: settings entry opt-out");
3706
+ /**
3707
+ * 共享的 dock 状态一变,两个入口的注册/拆注册跟着走。
3708
+ *
3709
+ * 以前只有「卡片挂载时」才把开关值写进 panel-switch;如果另一张卡片或 60 秒
3710
+ * 轮询先拿到新值,就会出现「卡片上勾着、导航里却没有入口」(实测)。
3711
+ */
3712
+ ctx.effect(() => {
3713
+ const apply = () => {
3714
+ const { dock, loaded } = dockSnapshot();
3715
+ if (!loaded) return;
3716
+ setSettingsEntryWanted(dock.settingsEntry !== false);
3717
+ setSidebarPanelWanted(dock.sidebar === true);
3718
+ };
3719
+ const off = subscribeDock(apply);
3720
+ apply();
3721
+ return off;
3722
+ }, "dsh-codearts: entry switches follow dock state");
3271
3723
  (async () => {
3272
3724
  try {
3273
3725
  const res = await fetch("/api/codearts/dock", { headers: { Accept: "application/json" } });
3274
3726
  if (!res.ok) return;
3275
- setSidebarPanelWanted((await res.json()).dock?.sidebar === true);
3727
+ const data = await res.json();
3728
+ setSidebarPanelWanted(data.dock?.sidebar === true);
3729
+ setSettingsEntryWanted(data.dock?.settingsEntry !== false);
3276
3730
  } catch {}
3277
3731
  })();
3278
3732
  } catch (error) {