dsh-plugin-lark-bridge 0.1.2 → 0.1.4

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.
Files changed (66) hide show
  1. package/README.md +20 -60
  2. package/cordis.patch.yml +2 -8
  3. package/dist/auth.d.ts +12 -38
  4. package/dist/auth.d.ts.map +1 -1
  5. package/dist/bridge.d.ts +19 -5
  6. package/dist/bridge.d.ts.map +1 -1
  7. package/dist/cli.d.ts +17 -21
  8. package/dist/cli.d.ts.map +1 -1
  9. package/dist/client/api.d.ts +9 -33
  10. package/dist/client/api.d.ts.map +1 -1
  11. package/dist/client/auth-overlay.d.ts +54 -6
  12. package/dist/client/auth-overlay.d.ts.map +1 -1
  13. package/dist/client/auth-panel.d.ts +17 -5
  14. package/dist/client/auth-panel.d.ts.map +1 -1
  15. package/dist/client/config-form.d.ts +10 -11
  16. package/dist/client/config-form.d.ts.map +1 -1
  17. package/dist/client/config-page.d.ts +40 -6
  18. package/dist/client/config-page.d.ts.map +1 -1
  19. package/dist/client/index.d.ts +4 -8
  20. package/dist/client/index.d.ts.map +1 -1
  21. package/dist/client/locales.d.ts +37 -41
  22. package/dist/client/locales.d.ts.map +1 -1
  23. package/dist/client/model-defaults.d.ts +49 -0
  24. package/dist/client/model-defaults.d.ts.map +1 -0
  25. package/dist/client/preset-defaults.d.ts +84 -0
  26. package/dist/client/preset-defaults.d.ts.map +1 -0
  27. package/dist/client/preset-select.d.ts +26 -0
  28. package/dist/client/preset-select.d.ts.map +1 -0
  29. package/dist/client/status-controller.d.ts +43 -0
  30. package/dist/client/status-controller.d.ts.map +1 -0
  31. package/dist/client/terminal-command.d.ts +11 -0
  32. package/dist/client/terminal-command.d.ts.map +1 -0
  33. package/dist/client.js +2004 -656
  34. package/dist/config.d.ts +25 -21
  35. package/dist/config.d.ts.map +1 -1
  36. package/dist/constants.d.ts +8 -4
  37. package/dist/constants.d.ts.map +1 -1
  38. package/dist/index.d.ts +5 -1
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.mjs +814 -510
  41. package/dist/message.d.ts +27 -0
  42. package/dist/message.d.ts.map +1 -0
  43. package/dist/quote.d.ts +49 -0
  44. package/dist/quote.d.ts.map +1 -0
  45. package/dist/reminder.d.ts +33 -0
  46. package/dist/reminder.d.ts.map +1 -0
  47. package/dist/routes.d.ts +5 -15
  48. package/dist/routes.d.ts.map +1 -1
  49. package/dist/sessions.d.ts +22 -17
  50. package/dist/sessions.d.ts.map +1 -1
  51. package/dist/state.d.ts +0 -2
  52. package/dist/state.d.ts.map +1 -1
  53. package/dist/tools.d.ts +1 -0
  54. package/dist/tools.d.ts.map +1 -1
  55. package/dist/types.d.ts +2 -0
  56. package/dist/types.d.ts.map +1 -1
  57. package/dist/utils.d.ts +5 -1
  58. package/dist/utils.d.ts.map +1 -1
  59. package/dist/workspace-path.d.ts +8 -0
  60. package/dist/workspace-path.d.ts.map +1 -0
  61. package/dist/workspace.d.ts +32 -0
  62. package/dist/workspace.d.ts.map +1 -0
  63. package/icon.svg +9 -0
  64. package/locale/en.json +1 -1
  65. package/locale/zh.json +1 -1
  66. package/package.json +33 -21
package/dist/client.js CHANGED
@@ -7,12 +7,41 @@ window.__ModuleLoader__.load({
7
7
  let _deepseek_ai_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
8
8
  let react = require("react");
9
9
  let react_jsx_runtime = require("react/jsx-runtime");
10
+ let react_dom = require("react-dom");
11
+ let _deepseek_ai_dsh_client_store = require("@deepseek-ai/dsh-client-store");
12
+ //#region src/workspace-path.ts
13
+ /** 工作区路径:统一 Linux 风格表示、平台比较与 Host 原生路径转换。 */
14
+ /** 判断原始或归一化路径是否使用 Windows 语义。 */
15
+ function isWindowsPath(value) {
16
+ return /^(?:[A-Za-z]:[\\/]|\\\\|\/\/|\/[A-Za-z](?:\/|$))/.test(value);
17
+ }
18
+ /** 统一斜杠、末尾分隔符与 Windows 盘符,例如 `C:\work\demo` 转为 `/c/work/demo`。 */
19
+ function normalizeWorkspacePath(value) {
20
+ const slashed = value.trim().replaceAll("\\", "/");
21
+ if (slashed === "") return "";
22
+ const drive = /^([A-Za-z]):(?:\/+(.*))?$/.exec(slashed);
23
+ if (drive !== null) {
24
+ const rest = (drive[2] ?? "").replace(/\/{2,}/g, "/").replace(/\/+$/, "");
25
+ return `/${drive[1]?.toLowerCase()}${rest === "" ? "" : `/${rest}`}`;
26
+ }
27
+ const unc = slashed.startsWith("//");
28
+ const collapsed = slashed.replace(/\/{2,}/g, "/");
29
+ const withoutTrailing = collapsed.length > 1 ? collapsed.replace(/\/+$/, "") : collapsed;
30
+ return unc ? `/${withoutTrailing}` : withoutTrailing;
31
+ }
32
+ /** 比较工作区路径;Windows 忽略大小写,POSIX 保持大小写敏感。 */
33
+ function sameWorkspacePath(a, b) {
34
+ const left = normalizeWorkspacePath(a);
35
+ const right = normalizeWorkspacePath(b);
36
+ return isWindowsPath(a) || isWindowsPath(b) ? left.toLowerCase() === right.toLowerCase() : left === right;
37
+ }
38
+ //#endregion
10
39
  //#region src/client/api.ts
11
40
  /** 构造路由地址。 */
12
41
  function endpoint(path) {
13
42
  return `${window.location.origin}/lark-bridge/${path}`;
14
43
  }
15
- /** 发起一次 JSON 调用;网络失败映射为可显示的失败。 */
44
+ /** 发起一次 JSON 调用;网络失败映射为内部结果。 */
16
45
  async function callApi(path, init = {}, signal) {
17
46
  try {
18
47
  const text = await (await fetch(endpoint(path), {
@@ -59,392 +88,276 @@ window.__ModuleLoader__.load({
59
88
  };
60
89
  }
61
90
  }
62
- /** 读取鉴权状态。 */
91
+ /** 读取最近一次连接状态。 */
63
92
  function fetchStatus(signal) {
64
93
  return callApi("status", { method: "GET" }, signal);
65
94
  }
66
- /** 重新检测。 */
95
+ /** 执行一次完整检测。 */
67
96
  function checkAuth() {
68
97
  return callApi("check", {
69
98
  method: "POST",
70
99
  body: "{}"
71
100
  });
72
101
  }
73
- /** 开始设备码授权。 */
74
- function startLogin() {
75
- return callApi("auth/start", {
76
- method: "POST",
77
- body: "{}"
78
- });
79
- }
80
- /** 取消设备码授权。 */
81
- function cancelLogin() {
82
- return callApi("auth/cancel", {
83
- method: "POST",
84
- body: "{}"
85
- });
102
+ //#endregion
103
+ //#region src/client/status-controller.ts
104
+ /** 共享连接状态控制器:完整检测、只读轮询、订阅与清理。 */
105
+ const INITIAL_STATUS = {
106
+ cli: "checking",
107
+ bot: "checking",
108
+ user: "checking",
109
+ ready: false,
110
+ checkedAt: 0
111
+ };
112
+ /** 共享一份状态,避免弹窗与配置页分别执行检测。 */
113
+ var StatusController = class {
114
+ options;
115
+ fetchStatus;
116
+ checkAuth;
117
+ snapshot = {
118
+ status: INITIAL_STATUS,
119
+ busy: false
120
+ };
121
+ listeners = /* @__PURE__ */ new Set();
122
+ timer;
123
+ checking;
124
+ generation = 0;
125
+ disposed = false;
126
+ constructor(options = {}) {
127
+ this.options = options;
128
+ this.fetchStatus = options.fetchStatus ?? fetchStatus;
129
+ this.checkAuth = options.checkAuth ?? checkAuth;
130
+ if (options.autoStart !== false) this.start();
131
+ }
132
+ /** 当前状态快照。 */
133
+ getSnapshot = () => this.snapshot;
134
+ /** 订阅状态变化。 */
135
+ subscribe(listener) {
136
+ this.listeners.add(listener);
137
+ return () => this.listeners.delete(listener);
138
+ }
139
+ /** 开始加载检测和只读轮询。 */
140
+ start() {
141
+ if (this.disposed || this.timer !== void 0) return;
142
+ this.timer = setInterval(() => {
143
+ this.refresh();
144
+ }, this.options.intervalMs ?? 3e3);
145
+ this.check();
146
+ }
147
+ /** 完整检测;并发调用共享同一次请求。 */
148
+ check() {
149
+ if (this.checking !== void 0) return this.checking;
150
+ const generation = ++this.generation;
151
+ this.publish({
152
+ ...this.snapshot,
153
+ busy: true
154
+ });
155
+ this.checking = this.checkAuth().then((result) => {
156
+ if (!this.disposed && generation === this.generation && result.ok) this.publish({
157
+ status: result.data,
158
+ busy: false
159
+ });
160
+ }).finally(() => {
161
+ if (generation === this.generation) {
162
+ this.checking = void 0;
163
+ if (!this.disposed && this.snapshot.busy) this.publish({
164
+ ...this.snapshot,
165
+ busy: false
166
+ });
167
+ }
168
+ });
169
+ return this.checking;
170
+ }
171
+ /** 停止轮询并使未完成的请求结果失效。 */
172
+ dispose() {
173
+ this.disposed = true;
174
+ this.generation += 1;
175
+ if (this.timer !== void 0) clearInterval(this.timer);
176
+ this.timer = void 0;
177
+ this.checking = void 0;
178
+ this.listeners.clear();
179
+ }
180
+ async refresh() {
181
+ if (this.disposed || this.checking !== void 0) return;
182
+ const generation = this.generation;
183
+ const result = await this.fetchStatus();
184
+ if (!this.disposed && generation === this.generation && result.ok) this.publish({
185
+ ...this.snapshot,
186
+ status: result.data
187
+ });
188
+ }
189
+ publish(next) {
190
+ if (this.disposed) return;
191
+ this.snapshot = next;
192
+ for (const listener of this.listeners) listener(next);
193
+ }
194
+ };
195
+ /** 在 React 组件中订阅共享状态。 */
196
+ function useStatusSnapshot(controller) {
197
+ return (0, react.useSyncExternalStore)((listener) => controller.subscribe(() => listener()), controller.getSnapshot, controller.getSnapshot);
86
198
  }
87
- /** 清除桥接会话记录。 */
88
- function resetSession() {
89
- return callApi("session/reset", {
90
- method: "POST",
91
- body: "{}"
199
+ //#endregion
200
+ //#region src/client/terminal-command.tsx
201
+ /** 只读终端命令:展示需要在插件外执行的命令,并在右侧提供复制。 */
202
+ /** 展示一条可选择文本的只读命令与复制按钮。 */
203
+ function TerminalCommand({ kind, command, t }) {
204
+ const { copied, onCopy } = (0, _deepseek_ai_dsh_client_ui_primitives.useClipboardCopy)(command);
205
+ const label = copied ? t("auth.command.copied") : t("auth.command.copy");
206
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
207
+ style: rowStyle$1,
208
+ "data-dsh-lark-command-row": kind,
209
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
210
+ "data-dsh-lark-command": kind,
211
+ style: commandStyle,
212
+ children: command
213
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
214
+ type: "button",
215
+ variant: "ghost",
216
+ size: "sm",
217
+ style: copyButtonStyle,
218
+ "aria-label": label,
219
+ title: label,
220
+ "data-copied": copied ? "" : void 0,
221
+ icon: copied ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconCheckOutlineRegular, { size: 16 }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopyIcon, {}),
222
+ onClick: onCopy
223
+ })]
92
224
  });
93
225
  }
94
- //#endregion
95
- //#region src/client/auth-overlay.tsx
96
- /**
97
- * 全局鉴权弹窗:每次打开 GUI 读取状态,未就绪时显示可关闭的提示。
98
- * 导出 AuthOverlay。
99
- */
100
- /** 鉴权弹窗。 */
101
- function AuthOverlay({ t, openSettings }) {
102
- const [status, setStatus] = (0, react.useState)(void 0);
103
- const [dismissed, setDismissed] = (0, react.useState)(false);
104
- const [busy, setBusy] = (0, react.useState)(false);
105
- const lastReady = (0, react.useRef)(void 0);
106
- const refresh = (0, react.useCallback)(async () => {
107
- const result = await fetchStatus();
108
- if (!result.ok) return;
109
- setStatus(result.data);
110
- if (lastReady.current === true && !result.data.ready) setDismissed(false);
111
- lastReady.current = result.data.ready;
112
- }, []);
113
- (0, react.useEffect)(() => {
114
- refresh();
115
- const timer = window.setInterval(() => {
116
- refresh();
117
- }, 5e3);
118
- return () => {
119
- window.clearInterval(timer);
120
- };
121
- }, [refresh]);
122
- if (status === void 0 || status.ready || dismissed) return null;
123
- const stage = status.stage;
124
- const hint = t(`auth.stage.${stage}.hint`);
125
- const detail = status.detail !== void 0 && status.detail !== "" ? `\n${t("auth.detail", { detail: status.detail })}` : "";
126
- const onRetry = async () => {
127
- setBusy(true);
128
- try {
129
- const result = await checkAuth();
130
- if (result.ok) {
131
- setStatus(result.data);
132
- lastReady.current = result.data.ready;
133
- }
134
- } finally {
135
- setBusy(false);
136
- }
137
- };
138
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Modal, {
139
- open: true,
140
- onClose: () => setDismissed(true),
141
- title: t("auth.title"),
142
- closeLabel: t("auth.close"),
143
- description: `${hint}${detail}`,
144
- tone: "warning",
145
- footer: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
146
- style: footerStyle,
147
- children: [
148
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
149
- type: "button",
150
- style: secondaryStyle,
151
- onClick: () => setDismissed(true),
152
- children: t("auth.close")
153
- }),
154
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { style: spacerStyle }),
155
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
156
- type: "button",
157
- style: secondaryStyle,
158
- disabled: busy,
159
- onClick: () => void onRetry(),
160
- children: busy ? t("auth.checking") : t("auth.retry")
161
- }),
162
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
163
- type: "button",
164
- style: primaryStyle,
165
- onClick: () => {
166
- openSettings();
167
- setDismissed(true);
168
- },
169
- children: t("auth.openSettings")
170
- })
171
- ]
172
- }),
173
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
174
- style: bodyStyle,
175
- children: t("auth.description")
176
- })
226
+ /** 复制图标:宿主没有对应图标,用 16px 描边 SVG。 */
227
+ function CopyIcon() {
228
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
229
+ viewBox: "0 0 16 16",
230
+ width: 16,
231
+ height: 16,
232
+ fill: "none",
233
+ stroke: "currentColor",
234
+ strokeWidth: 1.3,
235
+ strokeLinecap: "round",
236
+ strokeLinejoin: "round",
237
+ "aria-hidden": "true",
238
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
239
+ x: "5.75",
240
+ y: "5.75",
241
+ width: "7.5",
242
+ height: "7.5",
243
+ rx: "1.5"
244
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M10.25 3.25h-4.5A1.5 1.5 0 0 0 4.25 4.75v4.5" })]
177
245
  });
178
246
  }
179
- const footerStyle = {
247
+ const rowStyle$1 = {
180
248
  display: "flex",
181
249
  alignItems: "center",
182
- gap: 8,
183
- width: "100%"
250
+ gap: 4
184
251
  };
185
- const spacerStyle = { flex: 1 };
186
- const buttonBase$1 = {
187
- padding: "4px 10px",
252
+ const commandStyle = {
253
+ flex: "1 1 auto",
254
+ minWidth: 0,
255
+ padding: "6px 8px",
188
256
  borderRadius: "var(--dsw-radius-sm, 6px)",
189
- font: "inherit",
190
- fontSize: 12,
191
- cursor: "pointer"
192
- };
193
- const secondaryStyle = {
194
- ...buttonBase$1,
195
- border: "1px solid var(--dsw-alias-border-l2)",
196
- background: "var(--dsw-alias-button-tool-bar-fill, transparent)",
197
- color: "var(--dsw-alias-label-primary)"
198
- };
199
- const primaryStyle = {
200
- ...buttonBase$1,
201
- border: "1px solid var(--dsw-alias-brand-fill, #0969da)",
202
- background: "var(--dsw-alias-brand-fill, #0969da)",
203
- color: "var(--dsw-alias-label-on-brand, #fff)"
204
- };
205
- const bodyStyle = {
206
- margin: "0 0 6px",
257
+ background: "var(--dsw-alias-bg-secondary, transparent)",
258
+ color: "var(--dsw-alias-label-primary)",
259
+ fontFamily: "monospace",
207
260
  fontSize: 12,
208
261
  lineHeight: "18px",
209
- color: "var(--dsw-alias-label-secondary)"
210
- };
211
- //#endregion
212
- //#region src/client/config-form.ts
213
- /** 插件在前端使用的行键:`<包名>#<行 id>`。 */
214
- const ROW_KEY = "dsh-plugin-lark-bridge#dsh-plugin-lark-bridge";
215
- /** 行 id,同时是宿主配置的条目 id 与表单命名空间。 */
216
- const ROW_ID = "dsh-plugin-lark-bridge";
217
- /** 判断路径是否为绝对路径。 */
218
- function isAbsolutePath(value) {
219
- return /^(?:[A-Za-z]:[\\/]|\\\\|\/)/.test(value);
220
- }
221
- const workspaceSpec = {
222
- field: "workspaceRoot",
223
- format: (value) => typeof value === "string" ? value : "",
224
- parse: (text) => {
225
- const path = text.trim();
226
- return isAbsolutePath(path) ? {
227
- kind: "set",
228
- value: path
229
- } : void 0;
230
- }
231
- };
232
- const titleSpec = {
233
- field: "sessionTitle",
234
- format: (value) => typeof value === "string" ? value : "",
235
- parse: (text) => {
236
- const title = text.trim();
237
- return title === "" ? void 0 : {
238
- kind: "set",
239
- value: title
240
- };
241
- }
242
- };
243
- const cliSpec = {
244
- field: "larkCli",
245
- format: (value) => typeof value === "string" ? value : "",
246
- parse: (text) => ({
247
- kind: "set",
248
- value: text.trim()
249
- })
250
- };
251
- const authCheckSpec = {
252
- field: "authCheckOnStartup",
253
- format: (value) => value === false ? "false" : "true",
254
- parse: (text) => text === "true" || text === "false" ? {
255
- kind: "set",
256
- value: text === "true"
257
- } : void 0
262
+ overflowWrap: "anywhere",
263
+ userSelect: "text"
258
264
  };
259
- /** 暂存配置页的编辑,保存时一次写入宿主配置。 */
260
- var PluginConfigForm = class {
261
- form;
262
- state;
263
- /** @param scope - 宿主为该行提供的配置表单。 */
264
- constructor(scope) {
265
- this.form = new _deepseek_ai_dsh_client_ui_primitives.SettingsFormModel(scope, [
266
- workspaceSpec,
267
- titleSpec,
268
- cliSpec,
269
- authCheckSpec
270
- ]);
271
- this.state = this.form.bind(() => ({
272
- ...this.form.shell(),
273
- workspaceRoot: this.form.field("workspaceRoot"),
274
- sessionTitle: this.form.field("sessionTitle"),
275
- larkCli: this.form.field("larkCli"),
276
- authCheckOnStartup: this.form.field("authCheckOnStartup")
277
- }));
278
- }
279
- /** @returns 配置页向槽位组件提供的注入值。 */
280
- inject() {
281
- return {
282
- hooks: { configForm: this.state },
283
- ...this.form.actions()
284
- };
285
- }
286
- /** 释放对宿主表单的订阅。 */
287
- dispose() {
288
- this.form.dispose();
289
- }
265
+ const copyButtonStyle = {
266
+ flex: "none",
267
+ width: 28,
268
+ padding: 0,
269
+ color: "var(--dsw-alias-label-secondary)"
290
270
  };
291
271
  //#endregion
292
272
  //#region src/client/auth-panel.tsx
293
- /** 从失败结果取提示文本。 */
294
- function messageOf(result, fallback) {
295
- return result.ok ? "" : result.error.message === "" ? fallback : result.error.message;
296
- }
297
- /** 鉴权面板。 */
298
- function AuthPanel({ t }) {
299
- const [status, setStatus] = (0, react.useState)(void 0);
300
- const [error, setError] = (0, react.useState)("");
301
- const [busy, setBusy] = (0, react.useState)(void 0);
302
- const mounted = (0, react.useRef)(true);
303
- const refresh = (0, react.useCallback)(async () => {
304
- const result = await fetchStatus();
305
- if (!mounted.current) return;
306
- if (result.ok) {
307
- setStatus(result.data);
308
- setError("");
309
- } else setError(result.error.message);
310
- }, []);
311
- (0, react.useEffect)(() => {
312
- mounted.current = true;
313
- refresh();
314
- const timer = window.setInterval(() => {
315
- refresh();
316
- }, 3e3);
317
- return () => {
318
- mounted.current = false;
319
- window.clearInterval(timer);
320
- };
321
- }, [refresh]);
322
- const apply = (result, fallback) => {
323
- if (!mounted.current) return;
324
- if (result.ok) {
325
- setStatus(result.data);
326
- setError("");
327
- } else setError(messageOf(result, fallback));
328
- };
329
- const onStart = async () => {
330
- setBusy("login");
331
- try {
332
- const result = await startLogin();
333
- if (!mounted.current) return;
334
- if (result.ok) {
335
- setStatus((current) => current === void 0 ? current : {
336
- ...current,
337
- login: result.data
338
- });
339
- setError("");
340
- } else setError(result.error.message);
341
- } finally {
342
- if (mounted.current) setBusy(void 0);
343
- }
344
- };
345
- const onCancel = async () => {
346
- setBusy("cancel");
347
- try {
348
- const result = await cancelLogin();
349
- apply(result, "");
350
- } finally {
351
- if (mounted.current) setBusy(void 0);
352
- }
353
- };
354
- const onCheck = async () => {
355
- setBusy("check");
356
- try {
357
- const result = await checkAuth();
358
- apply(result, "");
359
- } finally {
360
- if (mounted.current) setBusy(void 0);
361
- }
362
- };
363
- const stage = status?.stage ?? "cli-missing";
364
- const ready = status?.ready === true;
365
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
273
+ const CONNECTIONS = [
274
+ {
275
+ key: "cli",
276
+ name: "auth.name.cli",
277
+ check: "auth.check.cli",
278
+ command: "auth.command.cli"
279
+ },
280
+ {
281
+ key: "bot",
282
+ name: "auth.name.bot",
283
+ check: "auth.check.bot",
284
+ command: "auth.command.bot"
285
+ },
286
+ {
287
+ key: "user",
288
+ name: "auth.name.user",
289
+ check: "auth.check.user",
290
+ command: "auth.command.user"
291
+ }
292
+ ];
293
+ /** 只读连接状态与三个检测入口。 */
294
+ function AuthPanelStatus({ t, status, busy, onCheck }) {
295
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("section", {
366
296
  "data-dsh-lark-auth-panel": true,
367
297
  style: sectionStyle,
368
- children: [
369
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("header", {
370
- style: headerStyle,
371
- children: [
372
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
373
- style: ready ? okDotStyle : warnDotStyle,
374
- "aria-hidden": "true"
375
- }),
376
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
377
- style: titleStyle$1,
378
- children: t(`auth.stage.${stage}`)
379
- }),
380
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
381
- type: "button",
382
- style: linkButtonStyle,
383
- disabled: busy !== void 0,
384
- onClick: () => void onCheck(),
385
- children: busy === "check" ? t("auth.checking") : t("auth.retry")
386
- })
387
- ]
388
- }),
389
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
390
- style: hintStyle,
391
- children: t(`auth.stage.${stage}.hint`)
392
- }),
393
- status?.userName !== void 0 && ready ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
394
- style: metaStyle,
395
- children: t("auth.readyAccount", { name: status.userName })
396
- }) : null,
397
- status?.appId !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
398
- style: metaStyle,
399
- children: t("auth.appIdLabel", { appId: status.appId })
400
- }) : null,
401
- status?.detail !== void 0 && status.detail !== "" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
402
- style: errorStyle,
403
- children: t("auth.detail", { detail: status.detail })
404
- }) : null,
405
- error !== "" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
406
- style: errorStyle,
407
- children: t("auth.actionError", { message: error })
408
- }) : null,
409
- stage === "user-missing" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
410
- style: formStyle,
411
- children: status?.login !== null && status?.login !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
412
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
413
- href: status.login.verificationUrl,
414
- target: "_blank",
415
- rel: "noreferrer",
416
- style: linkStyle,
417
- children: t("auth.openLink")
418
- }),
419
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
420
- style: metaStyle,
421
- children: t("auth.waiting")
422
- }),
423
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
424
- type: "button",
425
- style: secondaryButtonStyle$1,
426
- disabled: busy !== void 0,
427
- onClick: () => void onCancel(),
428
- children: busy === "cancel" ? t("auth.checking") : t("auth.cancel")
429
- })
430
- ] }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
431
- type: "button",
432
- style: primaryButtonStyle,
433
- disabled: busy !== void 0,
434
- onClick: () => void onStart(),
435
- children: busy === "login" ? t("auth.starting") : t("auth.startLogin")
436
- })
437
- }) : null
438
- ]
298
+ children: CONNECTIONS.map((connection) => {
299
+ const state = status?.[connection.key] ?? "checking";
300
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
301
+ style: rowStyle,
302
+ "data-dsh-lark-connection": connection.key,
303
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
304
+ style: headerStyle,
305
+ children: [
306
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
307
+ style: {
308
+ ...dotStyle,
309
+ ...stateDotStyle[state]
310
+ },
311
+ "data-state": state,
312
+ "aria-hidden": "true"
313
+ }),
314
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
315
+ style: titleStyle$1,
316
+ children: t(connection.name)
317
+ }),
318
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
319
+ style: stateStyle,
320
+ children: t(`auth.state.${state}`)
321
+ }),
322
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
323
+ type: "button",
324
+ style: linkButtonStyle,
325
+ disabled: busy,
326
+ onClick: onCheck,
327
+ children: t(connection.check)
328
+ })
329
+ ]
330
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TerminalCommand, {
331
+ kind: connection.key,
332
+ command: t(connection.command),
333
+ t
334
+ })]
335
+ }, connection.key);
336
+ })
337
+ });
338
+ }
339
+ /** 从共享控制器读取状态的面板。 */
340
+ function AuthPanel({ t, controller }) {
341
+ const snapshot = useStatusSnapshot(controller);
342
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AuthPanelStatus, {
343
+ t,
344
+ status: snapshot.status,
345
+ busy: snapshot.busy,
346
+ onCheck: () => void controller.check()
439
347
  });
440
348
  }
441
349
  const sectionStyle = {
442
350
  display: "flex",
443
351
  flexDirection: "column",
444
- gap: 8,
352
+ gap: 12,
445
353
  padding: "12px 0",
446
354
  borderBottom: "0.5px solid var(--dsw-alias-border-l2)"
447
355
  };
356
+ const rowStyle = {
357
+ display: "flex",
358
+ flexDirection: "column",
359
+ gap: 6
360
+ };
448
361
  const headerStyle = {
449
362
  display: "flex",
450
363
  alignItems: "center",
@@ -456,62 +369,20 @@ window.__ModuleLoader__.load({
456
369
  borderRadius: 999,
457
370
  flex: "none"
458
371
  };
459
- const okDotStyle = {
460
- ...dotStyle,
461
- background: "var(--dsw-alias-success-fill, #2da44e)"
462
- };
463
- const warnDotStyle = {
464
- ...dotStyle,
465
- background: "var(--dsw-alias-warning-fill, #bf8700)"
372
+ const stateDotStyle = {
373
+ checking: { background: "var(--dsw-alias-warning-fill, #bf8700)" },
374
+ connected: { background: "var(--dsw-alias-success-fill, #2da44e)" },
375
+ disconnected: { background: "var(--dsw-alias-label-tertiary, #8c959f)" }
466
376
  };
467
377
  const titleStyle$1 = {
468
378
  fontSize: 13,
469
379
  fontWeight: 500,
470
- color: "var(--dsw-alias-label-primary)",
471
- flex: 1
472
- };
473
- const hintStyle = {
474
- margin: 0,
475
- fontSize: 12,
476
- lineHeight: "18px",
477
- color: "var(--dsw-alias-label-secondary)"
380
+ color: "var(--dsw-alias-label-primary)"
478
381
  };
479
- const metaStyle = {
480
- margin: 0,
382
+ const stateStyle = {
481
383
  fontSize: 12,
482
- lineHeight: "18px",
483
384
  color: "var(--dsw-alias-label-secondary)"
484
385
  };
485
- const errorStyle = {
486
- ...metaStyle,
487
- color: "var(--dsw-alias-error-fill, #cf222e)"
488
- };
489
- const formStyle = {
490
- display: "flex",
491
- flexDirection: "column",
492
- gap: 8,
493
- paddingTop: 4
494
- };
495
- const buttonBase = {
496
- alignSelf: "flex-start",
497
- padding: "4px 10px",
498
- borderRadius: "var(--dsw-radius-sm, 6px)",
499
- font: "inherit",
500
- fontSize: 12,
501
- cursor: "pointer"
502
- };
503
- const primaryButtonStyle = {
504
- ...buttonBase,
505
- border: "1px solid var(--dsw-alias-brand-fill, #0969da)",
506
- background: "var(--dsw-alias-brand-fill, #0969da)",
507
- color: "var(--dsw-alias-label-on-brand, #fff)"
508
- };
509
- const secondaryButtonStyle$1 = {
510
- ...buttonBase,
511
- border: "1px solid var(--dsw-alias-border-l2)",
512
- background: "var(--dsw-alias-button-tool-bar-fill, transparent)",
513
- color: "var(--dsw-alias-label-primary)"
514
- };
515
386
  const linkButtonStyle = {
516
387
  border: "none",
517
388
  background: "transparent",
@@ -521,169 +392,1016 @@ window.__ModuleLoader__.load({
521
392
  cursor: "pointer",
522
393
  padding: 0
523
394
  };
524
- const linkStyle = {
525
- ...linkButtonStyle,
526
- fontSize: 12,
527
- textDecoration: "underline"
395
+ //#endregion
396
+ //#region node_modules/.pnpm/clsx@2.1.1/node_modules/clsx/dist/clsx.mjs
397
+ function r(e) {
398
+ var t, f, n = "";
399
+ if ("string" == typeof e || "number" == typeof e) n += e;
400
+ else if ("object" == typeof e) if (Array.isArray(e)) {
401
+ var o = e.length;
402
+ for (t = 0; t < o; t++) e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
403
+ } else for (f in e) e[f] && (n && (n += " "), n += f);
404
+ return n;
405
+ }
406
+ function clsx() {
407
+ for (var e, t, f = 0, n = "", o = arguments.length; f < o; f++) (e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
408
+ return n;
409
+ }
410
+ //#endregion
411
+ //#region node_modules/.pnpm/@deepseek-ai+dsh-client-ui-model-selection@0.2.2-rc.5_@deepseek-ai+cordis@4.1.0/node_modules/@deepseek-ai/dsh-client-ui-model-selection/src/client/ModelSelect.module.css
412
+ var ModelSelect_module_default = {
413
+ "badge": "KofATW_badge",
414
+ "badgedName": "KofATW_badgedName",
415
+ "badgedNameText": "KofATW_badgedNameText",
416
+ "cell": "KofATW_cell",
417
+ "cellChevron": "KofATW_cellChevron",
418
+ "cellLabel": "KofATW_cellLabel",
419
+ "cellValue": "KofATW_cellValue",
420
+ "check": "KofATW_check",
421
+ "chevron": "KofATW_chevron",
422
+ "chevronOpen": "KofATW_chevronOpen",
423
+ "empty": "KofATW_empty",
424
+ "error": "KofATW_error",
425
+ "groups": "KofATW_groups",
426
+ "menu": "KofATW_menu",
427
+ "modelName": "KofATW_modelName",
428
+ "modelOption": "KofATW_modelOption",
429
+ "option": "KofATW_option",
430
+ "optionActive": "KofATW_optionActive",
431
+ "optionCopy": "KofATW_optionCopy",
432
+ "retry": "KofATW_retry",
433
+ "root": "KofATW_root",
434
+ "search": "KofATW_search",
435
+ "searchClear": "KofATW_searchClear",
436
+ "searchRow": "KofATW_searchRow",
437
+ "searchWithQuery": "KofATW_searchWithQuery",
438
+ "selected": "KofATW_selected",
439
+ "status": "KofATW_status",
440
+ "trigger": "KofATW_trigger",
441
+ "triggerEffort": "KofATW_triggerEffort",
442
+ "triggerIcon": "KofATW_triggerIcon",
443
+ "triggerLabel": "KofATW_triggerLabel",
444
+ "warning": "KofATW_warning"
528
445
  };
529
446
  //#endregion
530
- //#region src/client/config-page.tsx
531
- /** 表单框架文案。 */
532
- function formLabels(t) {
533
- return {
534
- unavailable: t("config.unavailable"),
535
- readOnly: t("config.readOnly"),
536
- saveFailed: t("config.saveFailed"),
537
- save: t("config.save"),
538
- saving: t("config.saving")
539
- };
447
+ //#region node_modules/.pnpm/@deepseek-ai+dsh-client-ui-model-selection@0.2.2-rc.5_@deepseek-ai+cordis@4.1.0/node_modules/@deepseek-ai/dsh-client-ui-model-selection/src/client/provider-order.ts
448
+ /** Shared provider display order for the composer and command model pickers. */
449
+ /**
450
+ * Put the account and official providers first, preserving every other relative order.
451
+ * @param groups - Provider groups in catalog order.
452
+ * @returns a sorted copy; model order within each group is unchanged.
453
+ */
454
+ function orderModelProviders(groups) {
455
+ return groups.toSorted((left, right) => (left.id === "deepseek-account" ? 0 : left.id === "deepseek-official" ? 1 : 2) - (right.id === "deepseek-account" ? 0 : right.id === "deepseek-official" ? 1 : 2));
540
456
  }
541
- /** 渲染插件行配置。 */
542
- function ConfigPage(props) {
543
- const { t } = props;
457
+ //#endregion
458
+ //#region node_modules/.pnpm/@deepseek-ai+dsh-client-ui-model-selection@0.2.2-rc.5_@deepseek-ai+cordis@4.1.0/node_modules/@deepseek-ai/dsh-client-ui-model-selection/src/client/ModelSelect.tsx
459
+ /**
460
+ * ModelSelect: the composer's named model seat (`conversation.input.model`).
461
+ * Two-level selection per figma 496:26454's MenuDropdown: the root menu is
462
+ * the Model / Effort row pair (label + current value + a right chevron),
463
+ * each drilling into its own list — the provider-grouped model list over
464
+ * the shared directory, and the effort levels. The trigger (313:14108's
465
+ * ToggleButton) shows both: model name + effort in the caption tone.
466
+ * Model catalogs above four entries show search, which retains focus while
467
+ * ↑/↓ cycle the highlighted result; Enter and Tab accept it. Smaller model
468
+ * catalogs, root panes, and effort panes move focus between rows. Escape and Shift+Tab leave a drilled pane first and otherwise close
469
+ * back to the trigger. A drilled pane focuses the current effort or model
470
+ * search field. Provider headings paint their background only while pinned
471
+ * by scrolling. Clearing a query restores the full list and search focus.
472
+ * Selecting restores trigger focus without a ring until the trigger loses focus
473
+ * or the menu reopens. Mobile devices restore button focus when opening or
474
+ * drilling; model search takes focus only after explicit user input.
475
+ * Model names match a case-insensitive ordered subsequence
476
+ * within each provider group, ranked by
477
+ * prefix, alignment score, then catalog order. Returning to the root pane
478
+ * hands focus back to the cell that opened it. Data and submission ride the
479
+ * same per-session ModelDirectory as the /model popup; exact-model reasoning
480
+ * metadata and the selected effort come from the Host rather than a
481
+ * client-owned vocabulary. A rejected selection announces through the shared
482
+ * transient Toast anchored to the composer card; the in-menu strip with
483
+ * Retry remains the catalog-load surface. While the directory's pending
484
+ * selection is unsettled, the trigger shows a spinner in place of its
485
+ * chevron, and each row whose value that selection carries shows one in place
486
+ * of its check mark.
487
+ */
488
+ /**
489
+ * Render the composer model seat.
490
+ * @param props - owner share (locked) + injected face (shared directory
491
+ * store/verbs) + the standard locale seat.
492
+ * @returns the trigger and, while open, the two-level menu.
493
+ */
494
+ function ModelSelect({ locked, available, directory, load, select, resolveText, t, renderSlot }) {
495
+ const state = (0, react.useSyncExternalStore)((fn) => directory.subscribe(fn), () => directory.getSnapshot());
496
+ const [open, setOpen] = (0, react.useState)(false);
497
+ const [pane, setPane] = (0, react.useState)("root");
498
+ const [query, setQuery] = (0, react.useState)("");
499
+ const [highlightedIndex, setHighlightedIndex] = (0, react.useState)(null);
500
+ const [selectionFocus, setSelectionFocus] = (0, react.useState)(false);
501
+ const lastActionRef = (0, react.useRef)("load");
502
+ const [toast, setToast] = (0, react.useState)(null);
503
+ const toastSeq = (0, react.useRef)(0);
504
+ const rootRef = (0, react.useRef)(null);
505
+ const triggerRef = (0, react.useRef)(null);
506
+ const searchRef = (0, react.useRef)(null);
507
+ const menuRef = (0, react.useRef)(null);
508
+ const groupsRef = (0, react.useRef)(null);
509
+ const itemRefs = (0, react.useRef)([]);
544
510
  const id = (0, react.useId)();
545
- const state = props.useConfigForm((value) => value);
546
- const [resetNotice, setResetNotice] = (0, react.useState)("");
547
- if (props.view === "summary") return t("config.summary");
548
- const disabled = !state.writable || state.saving;
549
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(AuthPanel, { t }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_deepseek_ai_dsh_client_ui_primitives.SettingsForm, {
550
- state,
551
- labels: formLabels(t),
552
- onSave: props.save,
553
- onDiscard: props.discard,
554
- children: [
555
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h4", {
556
- style: sectionTitleStyle,
557
- children: t("config.section.session")
558
- }),
559
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
560
- style: fieldStyle,
561
- "data-dsh-lark-config-workspace": true,
562
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.SettingsValueField, {
563
- id: `${id}-workspace`,
564
- label: t("config.workspaceRoot.title"),
565
- hint: t("config.workspaceRoot.description"),
566
- invalidLabel: t("config.workspaceRoot.invalid"),
567
- overriddenLabel: t("config.overridden"),
568
- resetLabel: t("config.reset"),
569
- text: state.workspaceRoot.text,
570
- overridden: state.workspaceRoot.overridden,
571
- invalid: state.workspaceRoot.invalid,
572
- disabled,
573
- onEdit: (text) => props.edit("workspaceRoot", text),
574
- onReset: () => props.resetField("workspaceRoot")
511
+ const anchorStyle = { "--dsh-model-anchor": `--dsh-model-${id.replaceAll(":", "")}` };
512
+ const accountProviderName = t("provider.account");
513
+ const groups = (0, react.useMemo)(() => orderModelProviders(state.groups).map((group) => ({
514
+ ...group,
515
+ provider: {
516
+ id: group.id,
517
+ name: group.id === "deepseek-account" ? accountProviderName : group.name
518
+ }
519
+ })), [state.groups, accountProviderName]);
520
+ const choices = (0, react.useMemo)(() => groups.flatMap((group) => group.models.map((model) => ({
521
+ group,
522
+ model,
523
+ selection: {
524
+ provider: group.id,
525
+ model: model.id,
526
+ ...model.reasoning?.defaultEffort === void 0 ? {} : { reasoningEffort: model.reasoning.defaultEffort }
527
+ }
528
+ }))), [groups]);
529
+ const showSearch = choices.length > 4;
530
+ const filteredGroups = (0, react.useMemo)(() => groups.map((group) => ({
531
+ ...group,
532
+ models: (0, _deepseek_ai_dsh_client_ui_primitives.rankByName)(group.models, showSearch ? query.trim() : "")
533
+ })).filter((group) => group.models.length > 0), [
534
+ groups,
535
+ query,
536
+ showSearch
537
+ ]);
538
+ const visibleModels = (0, react.useMemo)(() => filteredGroups.flatMap((group) => group.models.map((model) => ({
539
+ provider: group.id,
540
+ model: model.id
541
+ }))), [filteredGroups]);
542
+ const currentVisibleIndex = visibleModels.findIndex((model) => model.provider === state.current?.provider && model.model === state.current.model);
543
+ const activeModelIndex = Math.min(highlightedIndex ?? Math.max(0, currentVisibleIndex), visibleModels.length - 1);
544
+ const currentChoice = choices[state.current === null ? -1 : choices.findIndex((c) => c.selection.provider === state.current?.provider && c.selection.model === state.current.model)];
545
+ const reasoning = currentChoice?.model.reasoning;
546
+ const effectiveEffort = state.current?.reasoningEffort ?? reasoning?.defaultEffort;
547
+ const effortLabel = currentChoice === void 0 ? void 0 : reasoning === void 0 ? state.retainedEffort : effectiveEffort === void 0 ? t("effort.providerDefault") : reasoning.efforts.find((level) => level.id === effectiveEffort)?.name ?? effectiveEffort;
548
+ const effortChoices = (0, react.useMemo)(() => reasoning === void 0 ? [] : [...reasoning.defaultEffort === void 0 ? [{
549
+ key: "provider-default",
550
+ effort: void 0,
551
+ label: t("effort.providerDefault")
552
+ }] : [], ...reasoning.efforts.map((effort) => ({
553
+ key: `effort:${effort.id}`,
554
+ effort: effort.id,
555
+ label: effort.name
556
+ }))], [reasoning, t]);
557
+ const { pending } = state;
558
+ const busy = pending !== null;
559
+ const reload = () => {
560
+ lastActionRef.current = "load";
561
+ load();
562
+ };
563
+ (0, react.useEffect)(() => {
564
+ if (!open) return;
565
+ const closeOutside = (event) => {
566
+ if (rootRef.current?.contains(event.target) === true) return;
567
+ if (menuRef.current?.contains(event.target) === true) return;
568
+ setOpen(false);
569
+ };
570
+ document.addEventListener("mousedown", closeOutside);
571
+ return () => {
572
+ document.removeEventListener("mousedown", closeOutside);
573
+ };
574
+ }, [open]);
575
+ (0, react.useLayoutEffect)(() => {
576
+ if (!showSearch) {
577
+ setQuery("");
578
+ setHighlightedIndex(null);
579
+ }
580
+ }, [showSearch]);
581
+ const paneFocus = (0, react.useRef)(null);
582
+ const previousShowSearch = (0, react.useRef)(showSearch);
583
+ (0, react.useEffect)(() => {
584
+ const changedSearchMode = previousShowSearch.current !== showSearch;
585
+ previousShowSearch.current = showSearch;
586
+ const intent = paneFocus.current ?? (changedSearchMode && pane === "model" ? "drill" : null);
587
+ paneFocus.current = null;
588
+ if (!open || intent === null) return;
589
+ if (intent === "drill") {
590
+ if (pane === "model" && showSearch && !(0, _deepseek_ai_dsh_client_ui_primitives.isMobileDevice)()) {
591
+ searchRef.current?.focus();
592
+ return;
593
+ }
594
+ (menuRef.current?.querySelector("[role=\"menuitemradio\"][aria-checked=\"true\"]:not([disabled])") ?? itemRefs.current.find((item) => item !== null && !item.disabled) ?? triggerRef.current)?.focus();
595
+ return;
596
+ }
597
+ const cell = itemRefs.current[intent === "effort" ? 1 : 0];
598
+ (cell !== null && cell !== void 0 && !cell.disabled ? cell : triggerRef.current)?.focus();
599
+ }, [
600
+ open,
601
+ pane,
602
+ showSearch
603
+ ]);
604
+ (0, react.useEffect)(() => {
605
+ const viewport = groupsRef.current;
606
+ if (viewport === null) return;
607
+ return (0, _deepseek_ai_dsh_client_ui_primitives.observeStickyMenuGroups)(viewport);
608
+ }, [
609
+ available,
610
+ open,
611
+ pane,
612
+ filteredGroups
613
+ ]);
614
+ (0, react.useLayoutEffect)(() => {
615
+ if (open && pane === "model" && activeModelIndex >= 0) itemRefs.current[activeModelIndex]?.scrollIntoView({ block: "nearest" });
616
+ }, [
617
+ open,
618
+ pane,
619
+ activeModelIndex,
620
+ visibleModels
621
+ ]);
622
+ if (!available) return null;
623
+ const show = () => {
624
+ setSelectionFocus(false);
625
+ triggerRef.current?.focus();
626
+ setQuery("");
627
+ setHighlightedIndex(null);
628
+ if (currentChoice === void 0) paneFocus.current = "drill";
629
+ setPane(currentChoice === void 0 ? "model" : "root");
630
+ setOpen(true);
631
+ reload();
632
+ };
633
+ const changeQuery = (next) => {
634
+ setQuery(next);
635
+ setHighlightedIndex(0);
636
+ };
637
+ const close = (restoreFocus = false) => {
638
+ setOpen(false);
639
+ setPane("root");
640
+ if (restoreFocus) queueMicrotask(() => {
641
+ triggerRef.current?.focus();
642
+ });
643
+ };
644
+ const closeAfterSelection = () => {
645
+ setSelectionFocus(true);
646
+ close(true);
647
+ };
648
+ const drill = (next) => {
649
+ setQuery("");
650
+ setHighlightedIndex(null);
651
+ paneFocus.current = "drill";
652
+ setPane(next);
653
+ };
654
+ /** Leave a drilled pane for the root one, handing the keyboard back to its cell. */
655
+ const back = (from) => {
656
+ paneFocus.current = from;
657
+ setPane("root");
658
+ };
659
+ const moveFocus = (offset) => {
660
+ const items = Array.from(menuRef.current?.querySelectorAll("button[role=\"menuitem\"]:not([disabled]), button[role=\"menuitemradio\"]:not([disabled]), button[role=\"switch\"]:not([disabled])") ?? []);
661
+ if (items.length === 0) return;
662
+ const active = items.findIndex((item) => item === document.activeElement);
663
+ items[active === -1 ? offset > 0 ? 0 : items.length - 1 : (active + offset + items.length) % items.length]?.focus();
664
+ };
665
+ const onRootKeyDown = (event) => {
666
+ if (event.nativeEvent.isComposing) return;
667
+ if (event.key === "Escape" && open) {
668
+ event.preventDefault();
669
+ if (pane !== "root" && currentChoice !== void 0) back(pane);
670
+ else close(true);
671
+ return;
672
+ }
673
+ if (!open) return;
674
+ if (pane === "model" && showSearch && (event.key === "ArrowDown" || event.key === "ArrowUp")) {
675
+ event.preventDefault();
676
+ if (!busy && visibleModels.length > 0) {
677
+ const direction = event.key === "ArrowDown" ? 1 : -1;
678
+ setHighlightedIndex((activeModelIndex + direction + visibleModels.length) % visibleModels.length);
679
+ searchRef.current?.focus();
680
+ }
681
+ return;
682
+ }
683
+ if (pane === "model" && showSearch && event.target instanceof HTMLInputElement && (event.key === "Enter" || event.key === "Tab" && !event.shiftKey)) {
684
+ if (event.key === "Tab" && visibleModels.length === 0) return;
685
+ event.preventDefault();
686
+ const highlighted = visibleModels[activeModelIndex];
687
+ if (!busy && highlighted !== void 0) choose(highlighted);
688
+ return;
689
+ }
690
+ if (event.key === "Tab") {
691
+ if (event.shiftKey) {
692
+ event.preventDefault();
693
+ if (pane !== "root" && currentChoice !== void 0) back(pane);
694
+ else close(true);
695
+ return;
696
+ }
697
+ const focused = document.activeElement;
698
+ const rows = Array.from(menuRef.current?.querySelectorAll("button[role=\"menuitem\"]:not([disabled]), button[role=\"menuitemradio\"]:not([disabled]), button[role=\"switch\"]:not([disabled])") ?? []);
699
+ if (focused instanceof HTMLButtonElement && rows.includes(focused)) {
700
+ event.preventDefault();
701
+ focused.click();
702
+ return;
703
+ }
704
+ if (focused !== triggerRef.current) return;
705
+ event.preventDefault();
706
+ if (pane === "model" && showSearch) {
707
+ setHighlightedIndex(null);
708
+ searchRef.current?.focus();
709
+ return;
710
+ }
711
+ (menuRef.current?.querySelector("[role=\"menuitemradio\"][aria-checked=\"true\"]:not([disabled])") ?? rows.find((item) => !item.disabled))?.focus();
712
+ return;
713
+ }
714
+ if (event.key === "ArrowDown" || event.key === "ArrowUp") {
715
+ event.preventDefault();
716
+ moveFocus(event.key === "ArrowDown" ? 1 : -1);
717
+ }
718
+ };
719
+ const onBlur = (event) => {
720
+ if (event.relatedTarget instanceof Node && (rootRef.current?.contains(event.relatedTarget) === true || menuRef.current?.contains(event.relatedTarget) === true)) return;
721
+ close();
722
+ };
723
+ const settleSelection = (result) => {
724
+ if (result === void 0) return;
725
+ if (result.ok) {
726
+ if (rootRef.current !== null) closeAfterSelection();
727
+ return;
728
+ }
729
+ const { error } = result;
730
+ toastSeq.current += 1;
731
+ setToast({
732
+ seq: toastSeq.current,
733
+ text: error.code === "session/writer-held" ? t("error.sessionInUse") : t("error.action", { message: `${error.code}: ${error.message}` })
734
+ });
735
+ };
736
+ const submit = (selection) => {
737
+ lastActionRef.current = "select";
738
+ setSelectionFocus(true);
739
+ triggerRef.current?.focus();
740
+ select(selection).then(settleSelection);
741
+ };
742
+ const choose = (selection) => {
743
+ if (state.current?.provider === selection.provider && state.current.model === selection.model) {
744
+ closeAfterSelection();
745
+ return;
746
+ }
747
+ submit(selection);
748
+ };
749
+ const chooseEffort = (effort) => {
750
+ if (state.current === null) return;
751
+ if (effectiveEffort === effort) {
752
+ closeAfterSelection();
753
+ return;
754
+ }
755
+ const selection = {
756
+ provider: state.current.provider,
757
+ model: state.current.model,
758
+ ...effort === void 0 ? {} : { reasoningEffort: effort }
759
+ };
760
+ submit(selection);
761
+ };
762
+ const waiting = currentChoice === void 0 && state.status === "loading";
763
+ const modelLabel = waiting ? t("trigger.loading") : currentChoice?.model.name ?? t("trigger.fallback");
764
+ const triggerLabel = effortLabel === void 0 ? modelLabel : `${modelLabel} · ${effortLabel}`;
765
+ const triggerAria = waiting ? t("trigger.loading") : currentChoice === void 0 ? t("trigger.selectAria") : effortLabel === void 0 ? t("trigger.aria", { model: modelLabel }) : t("trigger.ariaEffort", {
766
+ model: modelLabel,
767
+ effort: effortLabel
768
+ });
769
+ const renderModelLabel = (provider, model, placement, selected) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
770
+ "data-provider-id": provider.id,
771
+ "data-model-id": model.id,
772
+ children: renderSlot("conversation.input.model.label", {
773
+ provider,
774
+ model,
775
+ placement,
776
+ selected
777
+ }, { fallback: model.badge === void 0 ? model.name : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
778
+ className: ModelSelect_module_default.badgedName,
779
+ children: [
780
+ placement === "trigger" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tag, {
781
+ className: ModelSelect_module_default.badge,
782
+ tone: model.badge.tone,
783
+ children: resolveText(model.badge.text)
784
+ }), " "] }) : null,
785
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
786
+ className: ModelSelect_module_default.badgedNameText,
787
+ children: model.name
788
+ }),
789
+ placement === "trigger" ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [" ", /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tag, {
790
+ className: ModelSelect_module_default.badge,
791
+ tone: model.badge.tone,
792
+ children: resolveText(model.badge.text)
793
+ })] })
794
+ ]
795
+ }) })
796
+ });
797
+ let itemIndex = 0;
798
+ let modelIndex = 0;
799
+ const itemRef = () => {
800
+ const at = itemIndex++;
801
+ return (node) => {
802
+ itemRefs.current[at] = node;
803
+ };
804
+ };
805
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
806
+ ref: rootRef,
807
+ className: ModelSelect_module_default.root,
808
+ onKeyDown: onRootKeyDown,
809
+ onBlur,
810
+ onMouseDown: (event) => {
811
+ if (event.target instanceof Element && event.target.closest("button") !== null) event.preventDefault();
812
+ },
813
+ children: [
814
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
815
+ ref: triggerRef,
816
+ type: "button",
817
+ className: ModelSelect_module_default.trigger,
818
+ style: anchorStyle,
819
+ "aria-label": triggerAria,
820
+ "aria-haspopup": "menu",
821
+ "aria-expanded": open,
822
+ "aria-controls": open ? `${id}-menu` : void 0,
823
+ title: triggerLabel,
824
+ "aria-busy": busy,
825
+ "data-selection-focus": selectionFocus ? "" : void 0,
826
+ onBlur: () => {
827
+ setSelectionFocus(false);
828
+ },
829
+ disabled: locked,
830
+ onClick: () => {
831
+ if (open) close(true);
832
+ else show();
833
+ },
834
+ children: [
835
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconDataOutlineRegular, {
836
+ className: ModelSelect_module_default.triggerIcon,
837
+ size: 16
838
+ }),
839
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
840
+ className: ModelSelect_module_default.triggerLabel,
841
+ children: currentChoice === void 0 ? modelLabel : renderModelLabel(currentChoice.group.provider, currentChoice.model, "trigger", true)
842
+ }),
843
+ effortLabel !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
844
+ className: ModelSelect_module_default.triggerEffort,
845
+ children: effortLabel
846
+ }),
847
+ busy ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.StateDot, { state: "ongoing" }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconChevronDownOutlineRegular, { className: clsx(ModelSelect_module_default.chevron, open && ModelSelect_module_default.chevronOpen) })
848
+ ]
849
+ }),
850
+ open && (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_deepseek_ai_dsh_client_ui_primitives.MenuSurface, {
851
+ ref: menuRef,
852
+ id: `${id}-menu`,
853
+ className: ModelSelect_module_default.menu,
854
+ style: anchorStyle,
855
+ role: pane === "model" ? "group" : "menu",
856
+ "aria-label": t("menu.aria"),
857
+ "aria-busy": state.status === "loading" || busy,
858
+ children: [
859
+ pane === "root" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
860
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
861
+ ref: itemRef(),
862
+ type: "button",
863
+ role: "menuitem",
864
+ className: ModelSelect_module_default.cell,
865
+ onClick: () => {
866
+ drill("model");
867
+ },
868
+ children: [
869
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
870
+ className: ModelSelect_module_default.cellLabel,
871
+ children: t("menu.model")
872
+ }),
873
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
874
+ className: ModelSelect_module_default.cellValue,
875
+ children: currentChoice === void 0 ? modelLabel : renderModelLabel(currentChoice.group.provider, currentChoice.model, "menu", true)
876
+ }),
877
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconChevronRightOutlineRegular, { className: ModelSelect_module_default.cellChevron })
878
+ ]
879
+ }),
880
+ reasoning !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
881
+ ref: itemRef(),
882
+ type: "button",
883
+ role: "menuitem",
884
+ className: ModelSelect_module_default.cell,
885
+ onClick: () => {
886
+ drill("effort");
887
+ },
888
+ children: [
889
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
890
+ className: ModelSelect_module_default.cellLabel,
891
+ children: t("menu.effort")
892
+ }),
893
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
894
+ className: ModelSelect_module_default.cellValue,
895
+ children: effortLabel
896
+ }),
897
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconChevronRightOutlineRegular, { className: ModelSelect_module_default.cellChevron })
898
+ ]
899
+ }),
900
+ renderSlot("conversation.input.model.options", {
901
+ locked: locked || busy,
902
+ dismiss: () => {
903
+ close();
904
+ triggerRef.current?.focus();
905
+ },
906
+ reportFailure: (message) => {
907
+ setToast({
908
+ seq: ++toastSeq.current,
909
+ text: message
910
+ });
911
+ }
912
+ })
913
+ ] }),
914
+ pane === "model" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
915
+ showSearch && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
916
+ className: ModelSelect_module_default.searchRow,
917
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Input, {
918
+ ref: searchRef,
919
+ className: clsx(ModelSelect_module_default.search, query !== "" && ModelSelect_module_default.searchWithQuery),
920
+ type: "text",
921
+ role: "searchbox",
922
+ "aria-label": t("search.placeholder"),
923
+ "aria-controls": `${id}-models`,
924
+ "aria-activedescendant": activeModelIndex < 0 ? void 0 : `${id}-model-${activeModelIndex}`,
925
+ placeholder: t("search.placeholder"),
926
+ value: query,
927
+ readOnly: busy,
928
+ onChange: (event) => {
929
+ changeQuery(event.target.value);
930
+ }
931
+ }), query !== "" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
932
+ type: "button",
933
+ className: ModelSelect_module_default.searchClear,
934
+ "aria-label": t("search.clear"),
935
+ disabled: busy,
936
+ onClick: () => {
937
+ changeQuery("");
938
+ searchRef.current?.focus();
939
+ },
940
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconCloseFillRegular, {})
941
+ })]
942
+ }),
943
+ state.status === "loading" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
944
+ className: ModelSelect_module_default.status,
945
+ children: t("status.loading")
946
+ }),
947
+ state.error !== null && lastActionRef.current === "load" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
948
+ className: ModelSelect_module_default.error,
949
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("error.action", { message: state.error }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
950
+ type: "button",
951
+ className: ModelSelect_module_default.retry,
952
+ onClick: reload,
953
+ children: t("retry")
954
+ })]
955
+ }),
956
+ state.failures.map((failure) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
957
+ className: ModelSelect_module_default.warning,
958
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("warning.groupLoad", {
959
+ name: failure.id === "deepseek-account" ? t("provider.account") : failure.name,
960
+ message: failure.message
961
+ }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
962
+ type: "button",
963
+ className: ModelSelect_module_default.retry,
964
+ onClick: reload,
965
+ children: t("retry")
966
+ })]
967
+ }, failure.id)),
968
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
969
+ ref: groupsRef,
970
+ id: `${id}-models`,
971
+ className: clsx(ModelSelect_module_default.groups, "scrollable"),
972
+ role: "menu",
973
+ "aria-label": t("menu.model"),
974
+ hidden: filteredGroups.length === 0,
975
+ children: filteredGroups.map((group) => {
976
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.MenuGroup, {
977
+ label: group.provider.name,
978
+ children: group.models.map((model) => {
979
+ const index = modelIndex++;
980
+ const selected = state.current?.provider === group.id && state.current.model === model.id;
981
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
982
+ ref: itemRef(),
983
+ type: "button",
984
+ role: "menuitemradio",
985
+ "aria-checked": selected,
986
+ id: `${id}-model-${index}`,
987
+ tabIndex: showSearch ? -1 : 0,
988
+ onFocus: () => {
989
+ setHighlightedIndex(index);
990
+ },
991
+ "data-highlighted": index === activeModelIndex ? "" : void 0,
992
+ className: clsx(ModelSelect_module_default.option, ModelSelect_module_default.modelOption, selected && ModelSelect_module_default.selected, index === activeModelIndex && ModelSelect_module_default.optionActive),
993
+ onMouseMove: busy || index === activeModelIndex ? void 0 : () => {
994
+ if (showSearch) setHighlightedIndex(index);
995
+ else itemRefs.current[index]?.focus();
996
+ },
997
+ title: model.name,
998
+ disabled: busy,
999
+ onClick: () => {
1000
+ choose({
1001
+ provider: group.id,
1002
+ model: model.id
1003
+ });
1004
+ },
1005
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1006
+ className: ModelSelect_module_default.optionCopy,
1007
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1008
+ className: ModelSelect_module_default.modelName,
1009
+ children: renderModelLabel(group.provider, model, "option", selected)
1010
+ })
1011
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1012
+ className: ModelSelect_module_default.check,
1013
+ children: pending?.provider === group.id && pending.model === model.id ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.StateDot, { state: "ongoing" }) : selected ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconCheckOutlineRegular, {}) : null
1014
+ })]
1015
+ }, model.id);
1016
+ })
1017
+ }, group.id);
1018
+ })
1019
+ }),
1020
+ state.status === "ready" && filteredGroups.length === 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1021
+ className: ModelSelect_module_default.empty,
1022
+ role: "status",
1023
+ children: t(choices.length === 0 ? "empty.models" : "search.empty")
1024
+ })
1025
+ ] }),
1026
+ pane === "effort" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [state.error !== null && lastActionRef.current === "load" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1027
+ className: ModelSelect_module_default.error,
1028
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("error.action", { message: state.error }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1029
+ type: "button",
1030
+ className: ModelSelect_module_default.retry,
1031
+ onClick: reload,
1032
+ children: t("action.reload")
1033
+ })]
1034
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1035
+ className: clsx(ModelSelect_module_default.groups, "scrollable"),
1036
+ children: effortChoices.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1037
+ className: ModelSelect_module_default.empty,
1038
+ children: t("empty.efforts")
1039
+ }) : effortChoices.map((level) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1040
+ ref: itemRef(),
1041
+ type: "button",
1042
+ role: "menuitemradio",
1043
+ "aria-checked": effectiveEffort === level.effort,
1044
+ className: clsx(ModelSelect_module_default.option, effectiveEffort === level.effort && ModelSelect_module_default.selected),
1045
+ disabled: busy,
1046
+ onClick: () => {
1047
+ chooseEffort(level.effort);
1048
+ },
1049
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1050
+ className: ModelSelect_module_default.optionCopy,
1051
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1052
+ className: ModelSelect_module_default.modelName,
1053
+ children: level.label
1054
+ })
1055
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1056
+ className: ModelSelect_module_default.check,
1057
+ children: pending !== null && pending.provider === state.current?.provider && pending.model === state.current.model && pending.reasoningEffort === level.effort ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.StateDot, { state: "ongoing" }) : effectiveEffort === level.effort ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconCheckOutlineRegular, {}) : null
1058
+ })]
1059
+ }, level.key))
1060
+ })] })
1061
+ ]
1062
+ }), document.body),
1063
+ toast !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Toast, {
1064
+ text: toast.text,
1065
+ icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconWarningOutlineRegular, {}),
1066
+ anchor: rootRef.current?.closest("[data-composer-card]") ?? null,
1067
+ onDone: () => {
1068
+ setToast(null);
1069
+ }
1070
+ }, toast.seq)
1071
+ ]
1072
+ });
1073
+ }
1074
+ //#endregion
1075
+ //#region src/client/preset-select.tsx
1076
+ /**
1077
+ * 预设选择器:右侧 select 触发器,浮窗使用宿主自带 Menu。
1078
+ * 导出 PresetSelect、currentText 与 menuItems。
1079
+ */
1080
+ /** 当前选择的显示文案。 */
1081
+ function currentText(state, t) {
1082
+ if (state.status === "loading") return t("config.sessionPreset.loading");
1083
+ if (state.status === "noService") return t("config.sessionPreset.noService");
1084
+ if (state.status === "error") return t("config.sessionPreset.loadFailed");
1085
+ if (state.current === "") return t("config.sessionPreset.followHost");
1086
+ const row = state.rows.find((entry) => entry.id === state.current);
1087
+ if (row === void 0) return `${state.current} · ${t("config.sessionPreset.unavailable")}`;
1088
+ const name = row.name?.trim();
1089
+ return name === void 0 || name === "" ? row.id : name;
1090
+ }
1091
+ /** 菜单项:先「跟随宿主默认」,再列出可用预设,不可用的已存值以禁用项补足。 */
1092
+ function menuItems(state, t) {
1093
+ const items = [{
1094
+ id: "",
1095
+ label: t("config.sessionPreset.followHost")
1096
+ }, ...state.rows.map((row) => ({
1097
+ id: row.id,
1098
+ label: row.name?.trim() || row.id
1099
+ }))];
1100
+ if (state.status === "ready" && state.current !== "" && !state.rows.some((row) => row.id === state.current)) items.push({
1101
+ id: state.current,
1102
+ label: `${state.current} · ${t("config.sessionPreset.unavailable")}`,
1103
+ disabled: true
1104
+ });
1105
+ return items;
1106
+ }
1107
+ /**
1108
+ * 渲染预设行右侧的选择控制。
1109
+ * @param props - 名册状态、选择动作、只读开关与字典。
1110
+ * @returns 触发器、可选的重试提示与浮窗菜单。
1111
+ */
1112
+ function PresetSelect({ hooks, load, select, locked, t }) {
1113
+ const state = (0, react.useSyncExternalStore)((notify) => hooks.presetDefaults.subscribe(notify), () => hooks.presetDefaults.getSnapshot(), () => hooks.presetDefaults.getSnapshot());
1114
+ const [open, setOpen] = (0, react.useState)(false);
1115
+ const triggerRef = (0, react.useRef)(null);
1116
+ const editable = !locked && state.status === "ready";
1117
+ (0, react.useEffect)(() => {
1118
+ load();
1119
+ }, [load]);
1120
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Menu, {
1121
+ open,
1122
+ anchor: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1123
+ ref: triggerRef,
1124
+ type: "button",
1125
+ "data-dsh-lark-preset-trigger": true,
1126
+ style: triggerStyle$1,
1127
+ "aria-haspopup": "menu",
1128
+ "aria-expanded": open,
1129
+ "aria-label": t("config.sessionPreset.menuLabel"),
1130
+ disabled: !editable,
1131
+ onClick: () => setOpen((value) => !value),
1132
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1133
+ style: triggerLabelStyle$1,
1134
+ children: currentText(state, t)
1135
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconChevronDownOutlineRegular, {
1136
+ size: 14,
1137
+ "aria-hidden": "true"
1138
+ })]
1139
+ }),
1140
+ items: menuItems(state, t),
1141
+ selectedId: state.current,
1142
+ onSelect: (id) => {
1143
+ select(id);
1144
+ setOpen(false);
1145
+ },
1146
+ onClose: () => setOpen(false),
1147
+ returnFocus: () => triggerRef.current,
1148
+ portal: true,
1149
+ align: "start"
1150
+ }), state.status === "error" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
1151
+ style: noticeStyle,
1152
+ role: "alert",
1153
+ children: [state.error ?? t("config.sessionPreset.loadFailed"), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1154
+ type: "button",
1155
+ style: retryStyle,
1156
+ onClick: load,
1157
+ children: t("config.sessionPreset.retry")
1158
+ })]
1159
+ })] });
1160
+ }
1161
+ const triggerStyle$1 = {
1162
+ display: "flex",
1163
+ alignItems: "center",
1164
+ justifyContent: "space-between",
1165
+ gap: 8,
1166
+ width: "100%",
1167
+ paddingInline: 10,
1168
+ minHeight: 32,
1169
+ fontSize: 13,
1170
+ fontWeight: 400,
1171
+ color: "var(--dsw-alias-label-primary)",
1172
+ background: "var(--dsw-alias-bg-l1)",
1173
+ border: "0.5px solid var(--dsw-alias-border-l2)",
1174
+ borderRadius: 6,
1175
+ cursor: "pointer"
1176
+ };
1177
+ const triggerLabelStyle$1 = {
1178
+ flex: "1 1 auto",
1179
+ minWidth: 0,
1180
+ overflow: "hidden",
1181
+ textOverflow: "ellipsis",
1182
+ whiteSpace: "nowrap",
1183
+ textAlign: "left"
1184
+ };
1185
+ const noticeStyle = {
1186
+ margin: 0,
1187
+ fontSize: 12,
1188
+ lineHeight: "18px",
1189
+ color: "var(--dsw-alias-error-fill, #cf222e)"
1190
+ };
1191
+ const retryStyle = {
1192
+ marginLeft: 8,
1193
+ font: "inherit",
1194
+ color: "var(--dsw-alias-label-link, #0969da)",
1195
+ background: "none",
1196
+ border: "none",
1197
+ padding: 0,
1198
+ cursor: "pointer"
1199
+ };
1200
+ //#endregion
1201
+ //#region src/client/config-page.tsx
1202
+ /** 读取宿主当前工作区条目。 */
1203
+ function useWorkspaceItems(useWorkspaces) {
1204
+ return useWorkspaces((state) => state.items);
1205
+ }
1206
+ /** 把注册列表转成下拉选项,路径统一为 Linux 风格。 */
1207
+ function workspaceOptions(items) {
1208
+ return items.map((item) => ({
1209
+ id: String(item.workspaceId),
1210
+ title: item.title,
1211
+ path: normalizeWorkspacePath(item.path)
1212
+ }));
1213
+ }
1214
+ /** 从当前注册列表选择工作区,值为归一化路径。 */
1215
+ function WorkspaceSelect({ t, useWorkspaces, value, disabled, onChange, invalid = false }) {
1216
+ const id = (0, react.useId)();
1217
+ const options = workspaceOptions(useWorkspaceItems(useWorkspaces));
1218
+ const selected = options.find((option) => sameWorkspacePath(option.path, value));
1219
+ const [open, setOpen] = (0, react.useState)(false);
1220
+ const triggerRef = (0, react.useRef)(null);
1221
+ const empty = options.length === 0;
1222
+ const label = empty ? t("config.workspaceRoot.empty") : selected === void 0 ? t("config.workspaceRoot.placeholder") : `${selected.title} — ${selected.path}`;
1223
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1224
+ style: fieldStyle,
1225
+ "data-dsh-lark-config-workspace": true,
1226
+ children: [
1227
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1228
+ style: labelRowStyle,
1229
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
1230
+ htmlFor: id,
1231
+ style: titleStyle,
1232
+ children: t("config.workspaceRoot.title")
575
1233
  })
576
1234
  }),
577
1235
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
578
- style: fieldStyle,
579
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.SettingsValueField, {
580
- id: `${id}-title`,
581
- label: t("config.sessionTitle.title"),
582
- hint: t("config.sessionTitle.description"),
583
- invalidLabel: t("config.sessionTitle.invalid"),
584
- overriddenLabel: t("config.overridden"),
585
- resetLabel: t("config.reset"),
586
- text: state.sessionTitle.text,
587
- overridden: state.sessionTitle.overridden,
588
- invalid: state.sessionTitle.invalid,
589
- disabled,
590
- onEdit: (text) => props.edit("sessionTitle", text),
591
- onReset: () => props.resetField("sessionTitle")
1236
+ style: triggerRowStyle,
1237
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Menu, {
1238
+ open,
1239
+ anchorRef: triggerRef,
1240
+ portal: true,
1241
+ align: "start",
1242
+ items: options.map((option) => ({
1243
+ id: option.id,
1244
+ label: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1245
+ style: optionLabelStyle,
1246
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1247
+ style: optionTitleStyle,
1248
+ children: option.title
1249
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1250
+ style: optionPathStyle,
1251
+ children: option.path
1252
+ })]
1253
+ })
1254
+ })),
1255
+ selectedId: selected?.id,
1256
+ onSelect: (selectedId) => {
1257
+ setOpen(false);
1258
+ const option = options.find((candidate) => candidate.id === selectedId);
1259
+ if (option !== void 0) onChange(option.path);
1260
+ },
1261
+ onClose: () => setOpen(false),
1262
+ anchor: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_deepseek_ai_dsh_client_ui_primitives.Button, {
1263
+ ref: triggerRef,
1264
+ id,
1265
+ type: "button",
1266
+ variant: "outline",
1267
+ size: "md",
1268
+ style: triggerStyle,
1269
+ disabled: disabled || empty,
1270
+ "aria-haspopup": "menu",
1271
+ "aria-expanded": open,
1272
+ onClick: () => setOpen((previous) => !previous),
1273
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1274
+ style: triggerLabelStyle,
1275
+ children: label
1276
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconChevronDownOutlineRegular, { size: 16 })]
1277
+ })
592
1278
  })
593
1279
  }),
594
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
595
- style: rowStyle,
596
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
597
- style: textStyle,
598
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
599
- style: titleStyle,
600
- children: t("config.authCheckOnStartup.title")
601
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
602
- style: descriptionStyle,
603
- children: t("config.authCheckOnStartup.description")
604
- })]
605
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Switch, {
606
- checked: state.authCheckOnStartup.text !== "false",
607
- label: t("config.authCheckOnStartup.title"),
608
- disabled,
609
- onChange: (next) => props.edit("authCheckOnStartup", next ? "true" : "false")
610
- })]
1280
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1281
+ style: descriptionStyle,
1282
+ children: t("config.workspaceRoot.description")
611
1283
  }),
612
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h4", {
613
- style: sectionTitleStyle,
614
- children: t("config.section.auth")
1284
+ invalid ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1285
+ style: invalidStyle,
1286
+ children: t("config.workspaceRoot.invalid")
1287
+ }) : null
1288
+ ]
1289
+ });
1290
+ }
1291
+ /** 模型标签:在 trigger、根菜单与选项中显示 provider。 */
1292
+ const renderModelSlot = (name, owner) => {
1293
+ if (name === "conversation.input.model.label") {
1294
+ const label = owner;
1295
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1296
+ "data-dsh-lark-provider": label.provider.id,
1297
+ children: [
1298
+ label.provider.name,
1299
+ " / ",
1300
+ label.model.name
1301
+ ]
1302
+ });
1303
+ }
1304
+ return null;
1305
+ };
1306
+ /** 表单框架文案。 */
1307
+ function formLabels(t) {
1308
+ return {
1309
+ unavailable: t("config.unavailable"),
1310
+ readOnly: t("config.readOnly"),
1311
+ saveFailed: t("config.saveFailed"),
1312
+ save: t("config.save"),
1313
+ saving: t("config.saving")
1314
+ };
1315
+ }
1316
+ /** 渲染插件行配置。 */
1317
+ function ConfigPage(props) {
1318
+ const { t } = props;
1319
+ const state = props.useConfigForm((value) => value);
1320
+ if (props.view === "summary") return t("config.summary");
1321
+ const disabled = !state.available || !state.writable || state.saving;
1322
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(AuthPanel, {
1323
+ t,
1324
+ controller: props.controller
1325
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_deepseek_ai_dsh_client_ui_primitives.SettingsForm, {
1326
+ state,
1327
+ labels: formLabels(t),
1328
+ onSave: props.save,
1329
+ onDiscard: props.discard,
1330
+ children: [
1331
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WorkspaceSelect, {
1332
+ t,
1333
+ useWorkspaces: props.useWorkspaces,
1334
+ value: state.workspaceRoot.text,
1335
+ disabled,
1336
+ invalid: state.workspaceRoot.invalid,
1337
+ onChange: (path) => props.edit("workspaceRoot", path)
615
1338
  }),
616
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1339
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1340
+ "data-dsh-lark-config-model": "default",
617
1341
  style: fieldStyle,
618
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.SettingsValueField, {
619
- id: `${id}-cli`,
620
- label: t("config.larkCli.title"),
621
- hint: t("config.larkCli.description"),
622
- invalidLabel: t("config.larkCli.description"),
623
- overriddenLabel: t("config.overridden"),
624
- resetLabel: t("config.reset"),
625
- text: state.larkCli.text,
626
- overridden: state.larkCli.overridden,
627
- invalid: state.larkCli.invalid,
628
- disabled,
629
- onEdit: (text) => props.edit("larkCli", text),
630
- onReset: () => props.resetField("larkCli")
631
- })
1342
+ children: [
1343
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1344
+ style: labelRowStyle,
1345
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1346
+ style: titleStyle,
1347
+ children: t("config.sessionModel.label")
1348
+ })
1349
+ }),
1350
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1351
+ style: triggerRowStyle,
1352
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ModelSelect, {
1353
+ ...props.modelDefaults,
1354
+ locked: disabled,
1355
+ available: state.available,
1356
+ renderSlot: renderModelSlot
1357
+ })
1358
+ }),
1359
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1360
+ style: descriptionStyle,
1361
+ children: t("config.sessionModel.description")
1362
+ })
1363
+ ]
632
1364
  }),
633
1365
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
634
- style: rowStyle,
635
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
636
- style: textStyle,
637
- children: [
638
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1366
+ "data-dsh-lark-config-preset": "default",
1367
+ style: fieldStyle,
1368
+ children: [
1369
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1370
+ style: labelRowStyle,
1371
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
639
1372
  style: titleStyle,
640
- children: t("config.resetSession")
641
- }),
642
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
643
- style: descriptionStyle,
644
- children: t("config.resetSessionHint")
645
- }),
646
- resetNotice !== "" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
647
- style: noticeStyle,
648
- children: resetNotice
649
- }) : null
650
- ]
651
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
652
- type: "button",
653
- style: secondaryButtonStyle,
654
- disabled,
655
- onClick: () => {
656
- resetSession().then((result) => {
657
- setResetNotice(result.ok ? t("config.resetDone") : result.error.message);
658
- });
659
- },
660
- children: t("config.resetSession")
661
- })]
1373
+ children: t("config.sessionPreset.label")
1374
+ })
1375
+ }),
1376
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1377
+ style: triggerRowStyle,
1378
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PresetSelect, {
1379
+ ...props.presetDefaults,
1380
+ locked: disabled,
1381
+ t
1382
+ })
1383
+ }),
1384
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1385
+ style: descriptionStyle,
1386
+ children: t("config.sessionPreset.description")
1387
+ })
1388
+ ]
662
1389
  })
663
1390
  ]
664
1391
  })] });
665
1392
  }
666
- const sectionTitleStyle = {
667
- margin: "16px 0 0",
668
- fontSize: 12,
669
- fontWeight: 600,
670
- color: "var(--dsw-alias-label-secondary)",
671
- textTransform: "uppercase",
672
- letterSpacing: "0.04em"
1393
+ const fieldStyle = {
1394
+ display: "flex",
1395
+ flexDirection: "column",
1396
+ gap: 6,
1397
+ padding: "12px 0",
1398
+ borderTop: "0.5px solid var(--dsw-alias-border-l2)"
673
1399
  };
674
- const rowStyle = {
1400
+ const labelRowStyle = {
675
1401
  display: "flex",
676
1402
  alignItems: "center",
677
1403
  justifyContent: "space-between",
678
- gap: 24,
679
- padding: "12px 0"
680
- };
681
- const fieldStyle = { borderTop: "0.5px solid var(--dsw-alias-border-l2)" };
682
- const textStyle = {
683
- display: "flex",
684
- flexDirection: "column",
685
- gap: 4,
686
- minWidth: 0
1404
+ gap: 12
687
1405
  };
688
1406
  const titleStyle = {
689
1407
  fontSize: 13,
@@ -691,142 +1409,747 @@ window.__ModuleLoader__.load({
691
1409
  lineHeight: 1.5,
692
1410
  color: "var(--dsw-alias-label-primary)"
693
1411
  };
1412
+ const triggerRowStyle = { display: "grid" };
1413
+ const triggerStyle = {
1414
+ width: "100%",
1415
+ justifyContent: "space-between",
1416
+ gap: 8,
1417
+ paddingInline: 10,
1418
+ fontSize: 13,
1419
+ fontWeight: 400
1420
+ };
1421
+ const triggerLabelStyle = {
1422
+ flex: "1 1 auto",
1423
+ minWidth: 0,
1424
+ overflow: "hidden",
1425
+ textOverflow: "ellipsis",
1426
+ whiteSpace: "nowrap",
1427
+ textAlign: "left"
1428
+ };
1429
+ const optionLabelStyle = {
1430
+ display: "flex",
1431
+ flexDirection: "column",
1432
+ gap: 1,
1433
+ minWidth: 0,
1434
+ whiteSpace: "normal"
1435
+ };
1436
+ const optionTitleStyle = {
1437
+ overflow: "hidden",
1438
+ textOverflow: "ellipsis",
1439
+ whiteSpace: "nowrap"
1440
+ };
1441
+ const optionPathStyle = {
1442
+ overflow: "hidden",
1443
+ textOverflow: "ellipsis",
1444
+ whiteSpace: "nowrap",
1445
+ fontSize: 11,
1446
+ lineHeight: "16px",
1447
+ color: "var(--dsw-alias-label-secondary)"
1448
+ };
694
1449
  const descriptionStyle = {
695
1450
  margin: 0,
696
1451
  fontSize: 12,
697
1452
  lineHeight: "18px",
698
1453
  color: "var(--dsw-alias-label-secondary)"
699
1454
  };
700
- const noticeStyle = {
1455
+ const invalidStyle = {
701
1456
  ...descriptionStyle,
702
- color: "var(--dsw-alias-label-link, #0969da)"
1457
+ color: "var(--dsw-alias-error-fill, #cf222e)"
703
1458
  };
704
- const secondaryButtonStyle = {
705
- flex: "none",
1459
+ //#endregion
1460
+ //#region src/client/auth-overlay.tsx
1461
+ /** 共用设置弹窗:连接状态、注册工作区选择、失效重开与保存状态。 */
1462
+ /** 计算当前失效签名;连接与工作区均有效时返回空串。 */
1463
+ function getAuthOverlaySignature(status, workspaceRoot, workspacePaths) {
1464
+ const root = normalizeWorkspacePath(workspaceRoot);
1465
+ const workspaceValid = workspacePaths.some((path) => sameWorkspacePath(path, root));
1466
+ if (status.ready && workspaceValid) return "";
1467
+ return `${status.cli}/${status.bot}/${status.user}|${workspaceValid ? "valid" : "invalid"}:${root}`;
1468
+ }
1469
+ /** 弹窗初始状态。 */
1470
+ const INITIAL_AUTH_OVERLAY_STATE = {
1471
+ signature: "initial",
1472
+ open: true,
1473
+ dismissed: false,
1474
+ settleDismissed: false,
1475
+ editing: false,
1476
+ saving: false
1477
+ };
1478
+ /** 管理失效重开和显式保存;未发起保存的 settle 不产生副作用。 */
1479
+ function reduceAuthOverlayState(state, action) {
1480
+ switch (action.type) {
1481
+ case "sync": {
1482
+ const changed = action.signature !== state.signature;
1483
+ if (action.signature === "" && !state.editing && !state.saving) return {
1484
+ signature: "",
1485
+ open: false,
1486
+ dismissed: false,
1487
+ settleDismissed: false,
1488
+ editing: false,
1489
+ saving: false
1490
+ };
1491
+ if (state.dismissed && (state.settleDismissed || !changed)) return {
1492
+ ...state,
1493
+ signature: action.signature,
1494
+ settleDismissed: false
1495
+ };
1496
+ return {
1497
+ ...state,
1498
+ signature: action.signature,
1499
+ open: true,
1500
+ dismissed: false
1501
+ };
1502
+ }
1503
+ case "editStart": return {
1504
+ ...state,
1505
+ open: true,
1506
+ dismissed: false,
1507
+ editing: true
1508
+ };
1509
+ case "dismiss": return {
1510
+ ...state,
1511
+ open: false,
1512
+ dismissed: true,
1513
+ settleDismissed: false,
1514
+ editing: false,
1515
+ saving: false
1516
+ };
1517
+ case "discard": return {
1518
+ ...state,
1519
+ open: false,
1520
+ dismissed: true,
1521
+ settleDismissed: true,
1522
+ editing: false,
1523
+ saving: false
1524
+ };
1525
+ case "saveStart": return {
1526
+ ...state,
1527
+ open: true,
1528
+ dismissed: false,
1529
+ saving: true
1530
+ };
1531
+ case "saveSettled":
1532
+ if (!state.saving) return state;
1533
+ if (action.saving || action.dirty || action.failed) return {
1534
+ ...state,
1535
+ open: true,
1536
+ saving: false,
1537
+ editing: true
1538
+ };
1539
+ return {
1540
+ signature: "",
1541
+ open: false,
1542
+ dismissed: false,
1543
+ settleDismissed: false,
1544
+ editing: false,
1545
+ saving: false
1546
+ };
1547
+ }
1548
+ }
1549
+ /** 连接面板与工作区选择正文。 */
1550
+ function AuthOverlayContent({ t, controller, useWorkspaces, form, onEdit, onSave, onClose, onOpenSettings }) {
1551
+ const disabled = !form.available || !form.writable || form.saving;
1552
+ const saveDisabled = disabled || !form.dirty || form.invalid || form.workspaceRoot.text === "";
1553
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [
1554
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AuthPanel, {
1555
+ t,
1556
+ controller
1557
+ }),
1558
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WorkspaceSelect, {
1559
+ t,
1560
+ useWorkspaces,
1561
+ value: form.workspaceRoot.text,
1562
+ disabled,
1563
+ invalid: form.workspaceRoot.invalid,
1564
+ onChange: onEdit
1565
+ }),
1566
+ form.failed ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1567
+ style: failedStyle,
1568
+ children: t("config.saveFailed")
1569
+ }) : null,
1570
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1571
+ style: actionsStyle,
1572
+ children: [
1573
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1574
+ type: "button",
1575
+ style: secondaryStyle,
1576
+ onClick: onClose,
1577
+ children: t("auth.close")
1578
+ }),
1579
+ onOpenSettings === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1580
+ type: "button",
1581
+ style: secondaryStyle,
1582
+ onClick: onOpenSettings,
1583
+ children: t("auth.openSettings")
1584
+ }),
1585
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1586
+ type: "button",
1587
+ style: {
1588
+ ...primaryStyle,
1589
+ ...saveDisabled ? disabledButtonStyle : {}
1590
+ },
1591
+ disabled: saveDisabled,
1592
+ onClick: onSave,
1593
+ children: form.saving ? t("config.saving") : t("config.saveSelection")
1594
+ })
1595
+ ]
1596
+ })
1597
+ ] });
1598
+ }
1599
+ /** 共用设置弹窗。 */
1600
+ function AuthOverlay(props) {
1601
+ const { t, controller } = props;
1602
+ const { status } = useStatusSnapshot(controller);
1603
+ const form = props.useConfigForm((value) => value);
1604
+ const workspacePaths = useWorkspaceItems(props.useWorkspaces).map((item) => item.path);
1605
+ const signature = getAuthOverlaySignature(status, form.workspaceRoot.text, workspacePaths);
1606
+ const [state, dispatch] = (0, react.useReducer)(reduceAuthOverlayState, INITIAL_AUTH_OVERLAY_STATE, (initial) => ({
1607
+ ...initial,
1608
+ signature,
1609
+ open: signature !== ""
1610
+ }));
1611
+ const wasSaving = (0, react.useRef)(false);
1612
+ (0, react.useEffect)(() => {
1613
+ dispatch({
1614
+ type: "sync",
1615
+ signature
1616
+ });
1617
+ }, [signature]);
1618
+ (0, react.useEffect)(() => {
1619
+ if (wasSaving.current && !form.saving) dispatch({
1620
+ type: "saveSettled",
1621
+ saving: form.saving,
1622
+ dirty: form.dirty,
1623
+ failed: form.failed
1624
+ });
1625
+ wasSaving.current = form.saving;
1626
+ }, [
1627
+ form.saving,
1628
+ form.dirty,
1629
+ form.failed
1630
+ ]);
1631
+ if (!state.open) return null;
1632
+ const onClose = () => {
1633
+ if (state.editing) {
1634
+ props.discard();
1635
+ dispatch({ type: "discard" });
1636
+ return;
1637
+ }
1638
+ dispatch({ type: "dismiss" });
1639
+ };
1640
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Modal, {
1641
+ open: true,
1642
+ onClose,
1643
+ title: t("auth.title"),
1644
+ closeLabel: t("auth.close"),
1645
+ description: t("auth.description"),
1646
+ tone: "warning",
1647
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AuthOverlayContent, {
1648
+ t,
1649
+ controller,
1650
+ useWorkspaces: props.useWorkspaces,
1651
+ form,
1652
+ onEdit: (path) => {
1653
+ dispatch({ type: "editStart" });
1654
+ props.edit("workspaceRoot", path);
1655
+ },
1656
+ onSave: () => {
1657
+ dispatch({ type: "saveStart" });
1658
+ props.save();
1659
+ },
1660
+ onClose,
1661
+ onOpenSettings: () => {
1662
+ props.openSettings();
1663
+ dispatch({ type: "dismiss" });
1664
+ }
1665
+ })
1666
+ });
1667
+ }
1668
+ const actionsStyle = {
1669
+ display: "flex",
1670
+ justifyContent: "flex-end",
1671
+ gap: 8,
1672
+ paddingTop: 12
1673
+ };
1674
+ const buttonBase = {
706
1675
  padding: "4px 10px",
707
- border: "1px solid var(--dsw-alias-border-l2)",
708
1676
  borderRadius: "var(--dsw-radius-sm, 6px)",
709
- background: "var(--dsw-alias-button-tool-bar-fill, transparent)",
710
- color: "var(--dsw-alias-label-primary)",
711
1677
  font: "inherit",
712
1678
  fontSize: 12,
713
1679
  cursor: "pointer"
714
1680
  };
1681
+ const secondaryStyle = {
1682
+ ...buttonBase,
1683
+ border: "1px solid var(--dsw-alias-border-l2)",
1684
+ background: "var(--dsw-alias-button-tool-bar-fill, transparent)",
1685
+ color: "var(--dsw-alias-label-primary)"
1686
+ };
1687
+ const primaryStyle = {
1688
+ ...buttonBase,
1689
+ border: "1px solid var(--dsw-alias-brand-fill, #0969da)",
1690
+ background: "var(--dsw-alias-brand-fill, #0969da)",
1691
+ color: "var(--dsw-alias-label-on-brand, #fff)"
1692
+ };
1693
+ const disabledButtonStyle = {
1694
+ borderColor: "var(--dsw-alias-border-l2)",
1695
+ background: "var(--dsw-alias-button-tool-bar-fill, transparent)",
1696
+ color: "var(--dsw-alias-label-secondary)",
1697
+ cursor: "not-allowed",
1698
+ opacity: .65
1699
+ };
1700
+ const failedStyle = {
1701
+ margin: "8px 0 0",
1702
+ fontSize: 12,
1703
+ color: "var(--dsw-alias-error-fill, #cf222e)"
1704
+ };
1705
+ //#endregion
1706
+ //#region src/client/config-form.ts
1707
+ /** 插件在前端使用的行键:`<包名>#<行 id>`。 */
1708
+ const ROW_KEY = "dsh-plugin-lark-bridge#dsh-plugin-lark-bridge";
1709
+ /** 行 id,同时是宿主配置的条目 id 与表单命名空间。 */
1710
+ const ROW_ID = "dsh-plugin-lark-bridge";
1711
+ const FIELD_SPECS = [{
1712
+ field: "workspaceRoot",
1713
+ format: (value) => typeof value === "string" ? normalizeWorkspacePath(value) : "",
1714
+ parse: (text) => {
1715
+ const path = normalizeWorkspacePath(text);
1716
+ return path.startsWith("/") ? {
1717
+ kind: "set",
1718
+ value: path
1719
+ } : void 0;
1720
+ }
1721
+ }, ...[
1722
+ "sessionProvider",
1723
+ "sessionModel",
1724
+ "sessionEffort",
1725
+ "sessionPreset"
1726
+ ].map((field) => (0, _deepseek_ai_dsh_client_ui_primitives.settingsTextField)(field))];
1727
+ /** 暂存配置编辑,保存时写入宿主配置。 */
1728
+ var PluginConfigForm = class {
1729
+ form;
1730
+ state;
1731
+ /** @param scope - 宿主为该行提供的配置表单。 */
1732
+ constructor(scope) {
1733
+ this.form = new _deepseek_ai_dsh_client_ui_primitives.SettingsFormModel(scope, FIELD_SPECS);
1734
+ this.state = this.form.bind(() => ({
1735
+ ...this.form.shell(),
1736
+ workspaceRoot: this.form.field("workspaceRoot"),
1737
+ sessionProvider: this.form.field("sessionProvider"),
1738
+ sessionModel: this.form.field("sessionModel"),
1739
+ sessionEffort: this.form.field("sessionEffort"),
1740
+ sessionPreset: this.form.field("sessionPreset")
1741
+ }));
1742
+ }
1743
+ /** @returns 配置页向槽位组件提供的注入值。 */
1744
+ inject() {
1745
+ return {
1746
+ hooks: { configForm: this.state },
1747
+ ...this.form.actions()
1748
+ };
1749
+ }
1750
+ /** 释放对宿主表单的订阅。 */
1751
+ dispose() {
1752
+ this.form.dispose();
1753
+ }
1754
+ };
715
1755
  //#endregion
716
1756
  //#region src/client/locales.ts
717
- /** 前端字典与命名空间。中文字典是键集事实源。 */
718
1757
  /** 前端使用的字典命名空间,与插件名一致。 */
719
1758
  const NS = "dsh-plugin-lark-bridge";
720
1759
  /** 中文字典。 */
721
1760
  const zh = {
722
- "auth.title": "飞书机器人尚未就绪",
723
- "auth.description": "完成鉴权后,插件才能接收飞书消息并以机器人身份回复。",
1761
+ "auth.title": "飞书桥接设置",
1762
+ "auth.description": "完成连接检查并选择工作区。命令需要在终端执行。",
1763
+ "auth.ready": "飞书连接已就绪",
724
1764
  "auth.close": "本次不再提示",
725
1765
  "auth.openSettings": "打开设置",
726
- "auth.retry": "重新检测",
727
- "auth.checking": "检测中…",
728
- "auth.ready": "飞书机器人已就绪",
729
- "auth.readyAccount": "授权用户:{name}",
730
- "auth.appIdLabel": "机器人 App ID:{appId}",
731
- "auth.actionError": "操作失败:{message}",
732
- "auth.stage.cli-missing": "缺少 lark-cli",
733
- "auth.stage.cli-missing.hint": "插件依赖 @larksuite/cli。重新安装插件或检查网络后重试。",
734
- "auth.stage.bot-unavailable": "机器人身份不可用",
735
- "auth.stage.bot-unavailable.hint": "插件使用 lark-cli 自带的机器人。在终端运行 lark-cli config init 完成配置,然后点击重新检测。",
736
- "auth.stage.user-missing": "等待用户授权",
737
- "auth.stage.user-missing.hint": "点击开始授权,在浏览器完成飞书登录。",
738
- "auth.stage.ready": "已就绪",
739
- "auth.stage.ready.hint": "机器人可以接收飞书私聊,并向你发送通知。",
740
- "auth.startLogin": "开始授权",
741
- "auth.starting": "启动授权…",
742
- "auth.openLink": "打开授权链接",
743
- "auth.waiting": "等待浏览器授权完成…",
744
- "auth.cancel": "取消授权",
745
- "auth.detail": "详情:{detail}",
746
- "config.summary": "工作区、会话标题与飞书鉴权",
747
- "config.section.auth": "鉴权",
748
- "config.section.session": "会话",
1766
+ "auth.name.cli": "lark-cli",
1767
+ "auth.name.bot": "机器人身份(bot)",
1768
+ "auth.name.user": "用户身份(user)",
1769
+ "auth.state.checking": "检测中…",
1770
+ "auth.state.connected": "已连接",
1771
+ "auth.state.disconnected": "未连接",
1772
+ "auth.check.cli": "检测 lark-cli",
1773
+ "auth.check.bot": "检测机器人身份",
1774
+ "auth.check.user": "检测用户身份",
1775
+ "auth.command.cli": "npm install -g @larksuite/cli@latest",
1776
+ "auth.command.bot": "lark-cli config init",
1777
+ "auth.command.user": "lark-cli auth login --scope auth:user.id:read",
1778
+ "auth.command.copy": "复制命令",
1779
+ "auth.command.copied": "已复制",
1780
+ "config.summary": "工作区、模型、预设与飞书连接",
749
1781
  "config.workspaceRoot.title": "工作区",
750
- "config.workspaceRoot.description": "飞书消息注入到这个目录对应的 DSH 会话;必须是已存在的绝对路径。",
751
- "config.workspaceRoot.invalid": "请填写已存在的目录绝对路径。",
752
- "config.sessionTitle.title": "会话标题",
753
- "config.sessionTitle.description": "桥接会话显示的名称;修改后下一个消息会同步到会话。",
754
- "config.sessionTitle.invalid": "标题不能为空。",
755
- "config.larkCli.title": "lark-cli 路径",
756
- "config.larkCli.description": "留空自动使用插件依赖的 @larksuite/cli。",
757
- "config.authCheckOnStartup.title": "启动时检测鉴权",
758
- "config.authCheckOnStartup.description": "每次打开 DSH 都检查一次;失败时显示提示弹窗。",
759
- "config.resetSession": "重置桥接会话",
760
- "config.resetSessionHint": "清除已记录的会话标识,下一条飞书消息会在工作区新建会话。",
761
- "config.resetDone": "会话记录已清除。",
1782
+ "config.workspaceRoot.description": "飞书消息注入到所选 DSH 工作区的会话。",
1783
+ "config.workspaceRoot.invalid": "请选择一个已注册的工作区。",
1784
+ "config.workspaceRoot.placeholder": "请选择工作区",
1785
+ "config.workspaceRoot.empty": "暂无已注册工作区",
1786
+ "config.sessionModel.label": "模型",
1787
+ "config.sessionModel.description": "选择新建桥接会话时使用的模型。",
1788
+ "config.sessionPreset.label": "预设",
1789
+ "config.sessionPreset.description": "选择新建桥接会话时使用的预设。",
1790
+ "config.sessionPreset.followHost": "跟随宿主默认",
1791
+ "config.sessionPreset.loading": "加载中…",
1792
+ "config.sessionPreset.unavailable": "不可用",
1793
+ "config.sessionPreset.noService": "此部署不提供预设",
1794
+ "config.sessionPreset.loadFailed": "预设加载失败",
1795
+ "config.sessionPreset.retry": "重试",
1796
+ "config.sessionPreset.menuLabel": "预设",
1797
+ "config.saveSelection": "保存选择",
762
1798
  "config.unavailable": "配置不可用。",
763
1799
  "config.readOnly": "此部署以只读方式保存设置。",
764
1800
  "config.saveFailed": "此部署未接受这些值,已保留以便修改。",
765
1801
  "config.save": "保存",
766
- "config.saving": "保存中…",
767
- "config.overridden": "已覆盖",
768
- "config.reset": "恢复默认",
769
- "config.currentSession": "当前会话:{session}",
770
- "config.noSession": "尚未创建桥接会话。"
1802
+ "config.saving": "保存中…"
771
1803
  };
772
1804
  /** 英文字典,键集与中文一致。 */
773
1805
  const en = {
774
- "auth.title": "Lark bot is not ready",
775
- "auth.description": "Finish authentication before the plugin can receive messages and reply as the bot.",
1806
+ "auth.title": "Lark bridge setup",
1807
+ "auth.description": "Check the connections and select a workspace. Run commands in a terminal.",
1808
+ "auth.ready": "Lark connections are ready",
776
1809
  "auth.close": "Not now",
777
1810
  "auth.openSettings": "Open settings",
778
- "auth.retry": "Check again",
779
- "auth.checking": "Checking…",
780
- "auth.ready": "Lark bot is ready",
781
- "auth.readyAccount": "Authorized user: {name}",
782
- "auth.appIdLabel": "Bot App ID: {appId}",
783
- "auth.actionError": "Action failed: {message}",
784
- "auth.stage.cli-missing": "lark-cli is missing",
785
- "auth.stage.cli-missing.hint": "The plugin depends on @larksuite/cli. Reinstall the plugin or check the network, then retry.",
786
- "auth.stage.bot-unavailable": "Bot identity is unavailable",
787
- "auth.stage.bot-unavailable.hint": "The plugin uses the bot built into lark-cli. Run lark-cli config init in a terminal to set it up, then check again.",
788
- "auth.stage.user-missing": "Waiting for user authorization",
789
- "auth.stage.user-missing.hint": "Start authorization and complete the Lark sign-in in your browser.",
790
- "auth.stage.ready": "Ready",
791
- "auth.stage.ready.hint": "The bot can receive Lark direct messages and send you notifications.",
792
- "auth.startLogin": "Start authorization",
793
- "auth.starting": "Starting…",
794
- "auth.openLink": "Open authorization link",
795
- "auth.waiting": "Waiting for the browser authorization…",
796
- "auth.cancel": "Cancel authorization",
797
- "auth.detail": "Details: {detail}",
798
- "config.summary": "Workspace, session title, and Lark authentication",
799
- "config.section.auth": "Authentication",
800
- "config.section.session": "Session",
1811
+ "auth.name.cli": "lark-cli",
1812
+ "auth.name.bot": "Bot identity",
1813
+ "auth.name.user": "User identity",
1814
+ "auth.state.checking": "Checking…",
1815
+ "auth.state.connected": "Connected",
1816
+ "auth.state.disconnected": "Disconnected",
1817
+ "auth.check.cli": "Check lark-cli",
1818
+ "auth.check.bot": "Check bot identity",
1819
+ "auth.check.user": "Check user identity",
1820
+ "auth.command.cli": "npm install -g @larksuite/cli@latest",
1821
+ "auth.command.bot": "lark-cli config init",
1822
+ "auth.command.user": "lark-cli auth login --scope auth:user.id:read",
1823
+ "auth.command.copy": "Copy command",
1824
+ "auth.command.copied": "Copied",
1825
+ "config.summary": "Workspace, model, preset, and Lark connections",
801
1826
  "config.workspaceRoot.title": "Workspace",
802
- "config.workspaceRoot.description": "Lark messages are injected into the DSH session for this directory; it must be an existing absolute path.",
803
- "config.workspaceRoot.invalid": "Enter an existing absolute directory path.",
804
- "config.sessionTitle.title": "Session title",
805
- "config.sessionTitle.description": "The bridge session name; changes apply with the next message.",
806
- "config.sessionTitle.invalid": "The title must not be empty.",
807
- "config.larkCli.title": "lark-cli path",
808
- "config.larkCli.description": "Leave empty to use the bundled @larksuite/cli dependency.",
809
- "config.authCheckOnStartup.title": "Check authentication on startup",
810
- "config.authCheckOnStartup.description": "Run one check whenever DSH opens and show the notice when it fails.",
811
- "config.resetSession": "Reset bridge session",
812
- "config.resetSessionHint": "Clears the recorded session id; the next Lark message creates a new session in the workspace.",
813
- "config.resetDone": "The session record was cleared.",
1827
+ "config.workspaceRoot.description": "Lark messages are injected into the selected DSH workspace.",
1828
+ "config.workspaceRoot.invalid": "Select a registered workspace.",
1829
+ "config.workspaceRoot.placeholder": "Select a workspace",
1830
+ "config.workspaceRoot.empty": "No registered workspaces",
1831
+ "config.sessionModel.label": "Model",
1832
+ "config.sessionModel.description": "Choose the model new bridge sessions use.",
1833
+ "config.sessionPreset.label": "Preset",
1834
+ "config.sessionPreset.description": "Choose the preset new bridge sessions use.",
1835
+ "config.sessionPreset.followHost": "Follow Host default",
1836
+ "config.sessionPreset.loading": "Loading…",
1837
+ "config.sessionPreset.unavailable": "Unavailable",
1838
+ "config.sessionPreset.noService": "This deployment provides no presets.",
1839
+ "config.sessionPreset.loadFailed": "Could not load presets",
1840
+ "config.sessionPreset.retry": "Retry",
1841
+ "config.sessionPreset.menuLabel": "Preset",
1842
+ "config.saveSelection": "Save selection",
814
1843
  "config.unavailable": "Configuration is unavailable.",
815
1844
  "config.readOnly": "This deployment stores settings read-only.",
816
1845
  "config.saveFailed": "The deployment did not accept these values; they were left for you to correct.",
817
1846
  "config.save": "Save",
818
- "config.saving": "Saving…",
819
- "config.overridden": "Overridden",
820
- "config.reset": "Restore default",
821
- "config.currentSession": "Current session: {session}",
822
- "config.noSession": "No bridge session yet."
1847
+ "config.saving": "Saving…"
1848
+ };
1849
+ //#endregion
1850
+ //#region node_modules/.pnpm/@deepseek-ai+dsh-client-ui-model-selection@0.2.2-rc.5_@deepseek-ai+cordis@4.1.0/node_modules/@deepseek-ai/dsh-client-ui-model-selection/src/client/catalog.ts
1851
+ /** Loads at most one model catalog for the current Host generation. */
1852
+ var ModelCatalogDirectory = class {
1853
+ ctx;
1854
+ /** Current shared catalog value and load lifecycle. */
1855
+ store = (0, _deepseek_ai_dsh_client_store.createSnapshotStore)({
1856
+ value: null,
1857
+ status: "idle",
1858
+ error: null
1859
+ });
1860
+ reasoning = /* @__PURE__ */ new Map();
1861
+ /**
1862
+ * Read the last advertised reasoning metadata, including unavailable models.
1863
+ * @param selection - provider and model whose effort is displayed.
1864
+ * @returns reasoning metadata observed during this Host generation.
1865
+ */
1866
+ reasoningFor(selection) {
1867
+ return this.reasoning.get(JSON.stringify([selection.provider, selection.model]));
1868
+ }
1869
+ generation = 0;
1870
+ inflight;
1871
+ /**
1872
+ * @param ctx - the providing plugin's context, whose `remote.session`
1873
+ * namespace carries the Host-generation catalog.
1874
+ */
1875
+ constructor(ctx) {
1876
+ this.ctx = ctx;
1877
+ }
1878
+ /**
1879
+ * Return the current generation's catalog, sharing its one in-flight load.
1880
+ * @returns the loaded global catalog.
1881
+ */
1882
+ load() {
1883
+ const state = this.store.getSnapshot();
1884
+ if (state.status === "ready" && state.value !== null) return Promise.resolve(state.value);
1885
+ if (this.inflight !== void 0) return this.inflight;
1886
+ const generation = this.generation;
1887
+ this.store.update((draft) => {
1888
+ draft.status = "loading";
1889
+ draft.error = null;
1890
+ });
1891
+ const operation = this.ctx.remote.session.modelCatalog().then((response) => {
1892
+ if (!response.ok) throw new Error(`${response.error.code}: ${response.error.message}`);
1893
+ if (generation === this.generation) {
1894
+ for (const group of response.value.groups) for (const model of group.models) this.reasoning.set(JSON.stringify([group.id, model.id]), model.reasoning);
1895
+ this.store.set({
1896
+ value: response.value,
1897
+ status: "ready",
1898
+ error: null
1899
+ });
1900
+ }
1901
+ return response.value;
1902
+ }).catch((error) => {
1903
+ if (generation === this.generation) this.store.update((draft) => {
1904
+ draft.status = "error";
1905
+ draft.error = error instanceof Error ? error.message : String(error);
1906
+ });
1907
+ throw error;
1908
+ }).finally(() => {
1909
+ if (generation === this.generation && this.inflight === operation) this.inflight = void 0;
1910
+ });
1911
+ this.inflight = operation;
1912
+ return operation;
1913
+ }
1914
+ /**
1915
+ * Invalidate the loaded catalog; the next explicit menu read reloads it.
1916
+ * @param clear - whether values from the previous Host generation must be hidden.
1917
+ */
1918
+ invalidate(clear = false) {
1919
+ this.generation += 1;
1920
+ this.inflight = void 0;
1921
+ const value = clear ? null : this.store.getSnapshot().value;
1922
+ this.store.set({
1923
+ value,
1924
+ status: "idle",
1925
+ error: null
1926
+ });
1927
+ }
1928
+ /** Invalidate and reload the catalog after a Host-side model input changes. */
1929
+ refresh() {
1930
+ this.invalidate();
1931
+ this.load().catch(() => {});
1932
+ }
1933
+ /** Clear Host-specific values and load the replacement Host generation. */
1934
+ resetGeneration() {
1935
+ this.reasoning.clear();
1936
+ this.invalidate(true);
1937
+ this.load().catch(() => {});
1938
+ }
1939
+ };
1940
+ //#endregion
1941
+ //#region src/client/model-defaults.ts
1942
+ /** 保存模型目录、配置草稿与选择器共享状态的订阅。 */
1943
+ var ModelDefaults = class {
1944
+ form;
1945
+ edit;
1946
+ catalog;
1947
+ store = (0, _deepseek_ai_dsh_client_store.createSnapshotStore)({
1948
+ current: null,
1949
+ routable: null,
1950
+ groups: [],
1951
+ failures: [],
1952
+ status: "idle",
1953
+ pending: null,
1954
+ error: null
1955
+ });
1956
+ disposers = [];
1957
+ /**
1958
+ * @param ctx - 前端根上下文,提供模型目录与连接事件。
1959
+ * @param form - 配置页草稿状态。
1960
+ * @param edit - 配置页草稿编辑动作。
1961
+ */
1962
+ constructor(ctx, form, edit) {
1963
+ this.form = form;
1964
+ this.edit = edit;
1965
+ this.catalog = new ModelCatalogDirectory(ctx);
1966
+ this.disposers.push(this.catalog.store.subscribe(() => this.sync()));
1967
+ this.disposers.push(form.subscribe(() => this.sync()));
1968
+ this.disposers.push(ctx.on("connection/reset", () => {
1969
+ this.catalog.resetGeneration();
1970
+ }));
1971
+ for (const event of [
1972
+ "llm/adapters-updated",
1973
+ "llm/models-updated",
1974
+ "settings/document-updated",
1975
+ "credentials/record-updated",
1976
+ "credentials/reference-updated"
1977
+ ]) this.disposers.push(ctx.remote.$on(event, () => {
1978
+ this.catalog.refresh();
1979
+ }));
1980
+ this.catalog.load().catch(() => void 0);
1981
+ this.sync();
1982
+ }
1983
+ /** @returns 配置页选择器的注入值。 */
1984
+ inject(t, resolveText) {
1985
+ return {
1986
+ directory: this.store,
1987
+ load: () => {
1988
+ this.catalog.load().catch(() => void 0);
1989
+ },
1990
+ select: (selection) => this.select(selection),
1991
+ t,
1992
+ resolveText
1993
+ };
1994
+ }
1995
+ /** 释放目录、配置与连接事件的订阅。 */
1996
+ dispose() {
1997
+ for (const dispose of this.disposers.splice(0)) dispose();
1998
+ }
1999
+ /** 把选择写入草稿,并立即更新选择器显示。 */
2000
+ select(selection) {
2001
+ this.store.update((state) => {
2002
+ state.pending = selection;
2003
+ state.status = "selecting";
2004
+ state.error = null;
2005
+ });
2006
+ this.edit("sessionProvider", selection.provider);
2007
+ this.edit("sessionModel", selection.model);
2008
+ this.edit("sessionEffort", selection.reasoningEffort ?? "");
2009
+ this.store.update((state) => {
2010
+ state.pending = null;
2011
+ state.status = "ready";
2012
+ });
2013
+ return Promise.resolve({
2014
+ ok: true,
2015
+ value: void 0
2016
+ });
2017
+ }
2018
+ /** 从目录与配置草稿重建选择器状态。 */
2019
+ sync() {
2020
+ const config = this.form.getSnapshot();
2021
+ const catalog = this.catalog.store.getSnapshot();
2022
+ const provider = config.sessionProvider?.text.trim() ?? "";
2023
+ const model = config.sessionModel?.text.trim() ?? "";
2024
+ const effort = config.sessionEffort?.text.trim() ?? "";
2025
+ const current = provider === "" || model === "" ? null : {
2026
+ provider,
2027
+ model,
2028
+ ...effort === "" ? {} : { reasoningEffort: effort }
2029
+ };
2030
+ const groups = catalog.value?.groups ?? [];
2031
+ const routable = current === null || catalog.status !== "ready" ? null : groups.some((group) => group.id === current.provider && group.models.some((entry) => entry.id === current.model));
2032
+ this.store.update((state) => {
2033
+ state.current = current;
2034
+ if (effort === "") delete state.retainedEffort;
2035
+ else state.retainedEffort = effort;
2036
+ state.routable = routable;
2037
+ state.groups = groups;
2038
+ state.failures = catalog.value?.failures ?? [];
2039
+ state.status = catalog.status === "error" ? "error" : catalog.status === "ready" ? "ready" : "loading";
2040
+ state.error = catalog.error;
2041
+ });
2042
+ }
2043
+ };
2044
+ //#endregion
2045
+ //#region src/client/preset-defaults.ts
2046
+ /** 保存名册、配置草稿与选择器共享状态的订阅。 */
2047
+ var PresetDefaults = class {
2048
+ form;
2049
+ edit;
2050
+ store = (0, _deepseek_ai_dsh_client_store.createSnapshotStore)({
2051
+ status: "noService",
2052
+ error: null,
2053
+ rows: [],
2054
+ current: ""
2055
+ });
2056
+ disposers = [];
2057
+ reading = false;
2058
+ remote;
2059
+ /**
2060
+ * @param ctx - 前端根上下文,提供连接事件。
2061
+ * @param form - 配置页草稿状态。
2062
+ * @param edit - 配置页草稿编辑动作。
2063
+ * @param remote - 预设名册远程命名空间;缺失时选择器保持禁用。
2064
+ */
2065
+ constructor(ctx, form, edit, remote) {
2066
+ this.form = form;
2067
+ this.edit = edit;
2068
+ this.remote = remote;
2069
+ this.disposers.push(form.subscribe(() => this.sync()));
2070
+ this.disposers.push(ctx.on("connection/reset", () => this.load(true)));
2071
+ this.sync();
2072
+ }
2073
+ /** 宿主预设服务就绪后接入名册,并读取一次。 */
2074
+ attach(remote) {
2075
+ this.remote = remote;
2076
+ this.load(true);
2077
+ }
2078
+ /** @returns 配置页选择器的注入值。 */
2079
+ inject() {
2080
+ return {
2081
+ hooks: { presetDefaults: this.store },
2082
+ load: () => {
2083
+ this.load(true);
2084
+ },
2085
+ select: (id) => this.edit("sessionPreset", id)
2086
+ };
2087
+ }
2088
+ /** 释放对配置草稿与连接事件的订阅。 */
2089
+ dispose() {
2090
+ for (const dispose of this.disposers.splice(0)) dispose();
2091
+ }
2092
+ /** 读取宿主的可用预设;失败时保留已保存值。 */
2093
+ async load(force = false) {
2094
+ if (this.reading) return;
2095
+ if (!force && this.store.getSnapshot().status === "ready") return;
2096
+ const remote = this.remote;
2097
+ if (remote === void 0) {
2098
+ this.store.update((state) => {
2099
+ state.status = "noService";
2100
+ state.error = null;
2101
+ });
2102
+ return;
2103
+ }
2104
+ this.reading = true;
2105
+ this.store.update((state) => {
2106
+ state.status = "loading";
2107
+ state.error = null;
2108
+ });
2109
+ try {
2110
+ const result = await remote.list();
2111
+ if (result.ok) {
2112
+ const rows = result.value.presets.filter((row) => row.broken === void 0);
2113
+ this.store.update((state) => {
2114
+ state.status = "ready";
2115
+ state.rows = rows;
2116
+ });
2117
+ } else if (result.error.code === "gateway/invocation-unavailable") this.store.update((state) => {
2118
+ state.status = "noService";
2119
+ state.error = null;
2120
+ });
2121
+ else this.store.update((state) => {
2122
+ state.status = "error";
2123
+ state.error = result.error.message;
2124
+ });
2125
+ } catch (error) {
2126
+ this.store.update((state) => {
2127
+ state.status = "error";
2128
+ state.error = error instanceof Error ? error.message : String(error);
2129
+ });
2130
+ } finally {
2131
+ this.reading = false;
2132
+ }
2133
+ }
2134
+ /** 从配置草稿重建当前选择。 */
2135
+ sync() {
2136
+ const current = this.form.getSnapshot().sessionPreset?.text ?? "";
2137
+ this.store.update((state) => {
2138
+ state.current = current.trim();
2139
+ });
2140
+ }
823
2141
  };
824
2142
  //#endregion
825
2143
  //#region src/client/index.ts
826
- /**
827
- * 插件在前端启用时调用。
828
- * 字典、弹窗与配置页各自等待所需服务;服务缺失时该功能不加载。
829
- */
2144
+ /** 需要宿主注入的客户端服务。 */
2145
+ const inject = [
2146
+ "slots",
2147
+ "locale",
2148
+ "configForms",
2149
+ "remote",
2150
+ "remote.session"
2151
+ ];
2152
+ /** 注册共享状态、弹窗和配置页。 */
830
2153
  function apply(ctx) {
831
2154
  ctx.inject(["locale"], (ctx) => {
832
2155
  ctx.effect(() => ctx.locale.register(NS, {
@@ -834,42 +2157,67 @@ window.__ModuleLoader__.load({
834
2157
  en
835
2158
  }), `${NS}: dictionaries`);
836
2159
  });
837
- ctx.inject(["slots", "locale"], (ctx) => {
2160
+ ctx.inject([
2161
+ "slots",
2162
+ "locale",
2163
+ "configForms",
2164
+ "remote",
2165
+ "remote.session"
2166
+ ], (ctx) => {
2167
+ const form = new PluginConfigForm(ctx.configForms.get(ROW_ID));
2168
+ const injected = form.inject();
2169
+ const models = new ModelDefaults(ctx, injected.hooks.configForm, injected.edit);
2170
+ const presets = new PresetDefaults(ctx, injected.hooks.configForm, injected.edit);
2171
+ ctx.inject(["remote.agentPresets"], (scoped) => {
2172
+ const remote = scoped.remote.agentPresets;
2173
+ if (remote !== void 0 && typeof remote.list === "function") presets.attach(remote);
2174
+ });
2175
+ const modelT = ctx.locale.bind("model");
2176
+ const controller = new StatusController({ autoStart: typeof window !== "undefined" && typeof window.setInterval === "function" && typeof window.clearInterval === "function" });
2177
+ ctx.effect(() => () => {
2178
+ controller.dispose();
2179
+ form.dispose();
2180
+ models.dispose();
2181
+ presets.dispose();
2182
+ }, `${NS}: shared state`);
838
2183
  const layout = ctx.get("layout");
839
2184
  const navigation = ctx.get("pluginNavigation");
2185
+ const openSettings = () => {
2186
+ if (navigation?.openBundle !== void 0) {
2187
+ navigation.openBundle("dsh-plugin-lark-bridge");
2188
+ return;
2189
+ }
2190
+ layout?.selectPanel("plugins");
2191
+ };
840
2192
  ctx.slots.inject("shell.overlay", () => ctx.slots.register({
841
2193
  name: "shell.overlay",
842
2194
  id: "lark-bridge-auth",
843
2195
  order: 20,
844
2196
  locale: NS,
845
- inject: () => ({ openSettings: () => {
846
- if (navigation?.openBundle !== void 0) {
847
- navigation.openBundle("dsh-plugin-lark-bridge");
848
- return;
849
- }
850
- layout?.selectPanel("plugins");
851
- } })
2197
+ inject: () => ({
2198
+ ...injected,
2199
+ controller,
2200
+ openSettings
2201
+ })
852
2202
  }, AuthOverlay));
853
- });
854
- ctx.inject([
855
- "slots",
856
- "locale",
857
- "configForms"
858
- ], (ctx) => {
859
- const form = new PluginConfigForm(ctx.configForms.get(ROW_ID));
860
- ctx.effect(() => () => {
861
- form.dispose();
862
- }, `${NS}: config form`);
863
2203
  ctx.slots.inject("plugins.row.config", () => ctx.slots.register({
864
2204
  name: "plugins.row.config",
865
2205
  key: ROW_KEY,
866
2206
  locale: NS,
867
- inject: () => form.inject()
2207
+ inject: () => ({
2208
+ ...injected,
2209
+ controller,
2210
+ modelDefaults: models.inject(modelT, (text) => ctx.locale.resolveText(text)),
2211
+ presetDefaults: presets.inject()
2212
+ })
868
2213
  }, ConfigPage));
869
2214
  });
870
2215
  }
871
2216
  //#endregion
872
2217
  exports.apply = apply;
2218
+ exports.inject = inject;
873
2219
  return module.exports;
874
2220
  }
875
2221
  });
2222
+
2223
+ ;(() => { if (typeof document === 'undefined') return; const id = 'dsh-plugin-lark-bridge-model-selection'; document.getElementById(id)?.remove(); const style = document.createElement('style'); style.id = id; style.setAttribute('data-dsh-lark-bridge-model-selection', ''); style.textContent = ".KofATW_root {\n min-width: 0;\n position: relative;\n}\n\n.KofATW_trigger {\n anchor-name: var(--dsh-model-anchor);\n border-radius: var(--dsw-radius-sm);\n min-width: 0;\n max-width: 360px;\n height: 28px;\n color: var(--dsw-alias-label-secondary);\n cursor: pointer;\n background: none;\n border: none;\n outline: none;\n align-items: center;\n gap: 4px;\n padding: 0 4px 0 8px;\n font-size: 13px;\n font-weight: 400;\n line-height: 20px;\n display: flex;\n}\n\n@media (hover: hover) {\n .KofATW_trigger:hover:not(:disabled) {\n background: var(--dsw-alias-interactive-bg-hover);\n }\n}\n\n.KofATW_trigger:focus-visible:not([data-selection-focus]) {\n box-shadow: 0 0 0 2px var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary));\n}\n\n.KofATW_trigger:disabled {\n color: var(--dsw-alias-label-dimmed);\n cursor: default;\n}\n\n.KofATW_triggerLabel {\n text-overflow: ellipsis;\n white-space: nowrap;\n min-width: 0;\n overflow: hidden;\n}\n\n.KofATW_triggerEffort {\n text-overflow: ellipsis;\n white-space: nowrap;\n min-width: 0;\n color: var(--dsw-alias-label-caption);\n flex-shrink: 1000;\n overflow: hidden;\n}\n\n.KofATW_triggerIcon {\n display: var(--dsh-composer-model-icon-display, none);\n flex: none;\n}\n\n.KofATW_triggerLabel, .KofATW_triggerEffort {\n display: var(--dsh-composer-model-text-display, block);\n}\n\n.KofATW_chevron {\n color: var(--dsw-alias-label-caption);\n flex: none;\n transition: transform .12s;\n}\n\n.KofATW_chevronOpen {\n transform: rotate(180deg);\n}\n\n.KofATW_menu {\n box-sizing: border-box;\n position-anchor: var(--dsh-model-anchor);\n top: max(12px, var(--dsh-frame-overlay-top, 12px));\n left: 12px;\n right: anchor(right);\n bottom: calc(anchor(top) + 8px);\n z-index: 1100;\n --dsw-elevation-stroke-color: var(--dsw-alias-border-l1);\n width: fit-content;\n min-width: min(240px, 100vw - 24px);\n max-width: min(420px, 100vw - 24px);\n height: fit-content;\n max-height: min(360px, 100dvh - 96px);\n box-shadow: var(--dsw-elevation-prominent);\n color: var(--dsw-alias-label-primary);\n --dsh-scrollbar-thumb: var(--dsw-alias-scrollbar-bg-l2);\n --dsh-scrollbar-thumb-hover: var(--dsw-alias-scrollbar-hover-l2);\n border: 0;\n flex-direction: column;\n place-self: safe end;\n margin: 0;\n padding: 4px;\n display: flex;\n position: fixed;\n overflow: hidden;\n}\n\n.KofATW_status, .KofATW_empty {\n color: var(--dsw-alias-label-tertiary);\n padding: 8px;\n font-size: 12px;\n line-height: 18px;\n}\n\n.KofATW_error, .KofATW_warning {\n border-radius: var(--dsw-radius-md);\n background: var(--dsw-alias-interactive-bg-hover-danger);\n color: var(--dsw-alias-state-error-primary);\n justify-content: space-between;\n align-items: flex-start;\n gap: 6px;\n margin-bottom: 3px;\n padding: 6px 7px;\n font-size: 11px;\n line-height: 16px;\n display: flex;\n}\n\n.KofATW_warning {\n background: var(--dsw-alias-bg-module-platform);\n color: var(--dsw-alias-state-warn-label);\n}\n\n.KofATW_retry {\n color: inherit;\n font: inherit;\n cursor: pointer;\n background: none;\n border: none;\n flex: none;\n padding: 0;\n font-weight: 600;\n}\n\n.KofATW_searchRow {\n flex-shrink: 0;\n margin: 2px 0 3px;\n position: relative;\n}\n\n.KofATW_searchRow .KofATW_search {\n border-radius: var(--dsw-radius-md);\n background: none;\n border: 0 solid #0000;\n height: auto;\n padding: 5px 7px;\n display: flex;\n}\n\n.KofATW_searchRow .KofATW_searchWithQuery {\n padding-right: 34px;\n}\n\n.KofATW_searchClear {\n corner-shape: round;\n width: 24px;\n height: 24px;\n color: var(--dsw-alias-label-secondary);\n cursor: pointer;\n background: none;\n border: none;\n border-radius: 50%;\n justify-content: center;\n align-items: center;\n padding: 0;\n display: inline-flex;\n position: absolute;\n top: 50%;\n right: 4px;\n transform: translateY(-50%);\n}\n\n.KofATW_searchClear:focus-visible {\n background: var(--dsw-alias-interactive-bg-hover);\n outline: none;\n}\n\n@media (hover: hover) {\n .KofATW_searchClear:hover {\n background: var(--dsw-alias-interactive-bg-hover);\n outline: none;\n }\n}\n\n.KofATW_searchRow .KofATW_search:focus-within {\n border-color: #0000;\n}\n\n.KofATW_searchRow .KofATW_search input {\n padding: 0;\n font-size: 12px;\n line-height: normal;\n}\n\n@media (pointer: coarse) {\n .KofATW_searchRow .KofATW_search input {\n font-size: 16px;\n }\n}\n\n.KofATW_searchRow .KofATW_search input::placeholder {\n color: var(--dsw-alias-label-caption);\n}\n\n.KofATW_groups:not([hidden]) {\n min-height: 0;\n overflow: hidden auto;\n}\n\n.KofATW_option {\n box-sizing: border-box;\n border-radius: var(--dsw-radius-md);\n width: auto;\n min-width: 100%;\n min-height: 34px;\n color: inherit;\n text-align: left;\n cursor: pointer;\n background: none;\n border: none;\n outline: none;\n align-items: center;\n gap: 6px;\n padding: 5px 7px;\n display: flex;\n}\n\n.KofATW_option:focus-visible, .KofATW_optionActive:not(:disabled) {\n background: var(--dsw-alias-interactive-bg-hover);\n}\n\n.KofATW_modelOption {\n max-width: 100%;\n}\n\n@media (hover: hover) {\n .KofATW_option:not(.KofATW_modelOption):hover:not(:disabled) {\n background: var(--dsw-alias-interactive-bg-hover);\n }\n}\n\n.KofATW_selected {\n background: none;\n}\n\n.KofATW_option:disabled {\n color: var(--dsw-alias-label-dimmed);\n cursor: default;\n}\n\n.KofATW_optionCopy {\n flex-direction: column;\n flex: 1;\n min-width: 0;\n display: flex;\n}\n\n.KofATW_modelName {\n color: inherit;\n text-overflow: ellipsis;\n white-space: nowrap;\n font-size: 13px;\n font-weight: 400;\n line-height: 18px;\n overflow: hidden;\n}\n\n.KofATW_badgedName {\n vertical-align: baseline;\n white-space: nowrap;\n align-items: center;\n gap: 4px;\n max-width: 100%;\n display: inline-flex;\n}\n\n.KofATW_badgedNameText {\n text-overflow: ellipsis;\n min-width: 0;\n overflow: hidden;\n}\n\n.KofATW_badge {\n flex: none;\n}\n\n.KofATW_check {\n color: var(--dsw-alias-label-primary);\n flex: 0 0 14px;\n place-items: center;\n display: grid;\n}\n\n.KofATW_check svg {\n width: 14px;\n height: 14px;\n}\n\n.KofATW_cell {\n box-sizing: border-box;\n border-radius: var(--dsw-radius-md);\n width: auto;\n min-width: 100%;\n height: 34px;\n color: var(--dsw-alias-label-primary);\n cursor: pointer;\n text-align: left;\n background: none;\n border: none;\n outline: none;\n align-items: center;\n gap: 6px;\n padding: 0 8px;\n font-size: 13px;\n line-height: 20px;\n display: flex;\n}\n\n.KofATW_cell:focus-visible {\n background: var(--dsw-alias-interactive-bg-hover);\n}\n\n@media (hover: hover) {\n .KofATW_cell:hover {\n background: var(--dsw-alias-interactive-bg-hover);\n }\n}\n\n.KofATW_cellLabel {\n white-space: nowrap;\n flex: none;\n}\n\n.KofATW_cellValue {\n text-overflow: ellipsis;\n white-space: nowrap;\n text-align: right;\n min-width: 0;\n color: var(--dsw-alias-label-tertiary);\n flex: auto;\n overflow: hidden;\n}\n\n.KofATW_cellChevron {\n width: 12px;\n height: 12px;\n color: var(--dsw-alias-menu-icon);\n flex: none;\n}\n"; document.head.append(style); })();