dsh-plugin-lark-bridge 0.1.2 → 0.1.3

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 (56) hide show
  1. package/README.md +44 -22
  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 +6 -4
  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 +2 -11
  16. package/dist/client/config-form.d.ts.map +1 -1
  17. package/dist/client/config-page.d.ts +32 -6
  18. package/dist/client/config-page.d.ts.map +1 -1
  19. package/dist/client/index.d.ts +2 -8
  20. package/dist/client/index.d.ts.map +1 -1
  21. package/dist/client/locales.d.ts +23 -41
  22. package/dist/client/locales.d.ts.map +1 -1
  23. package/dist/client/status-controller.d.ts +43 -0
  24. package/dist/client/status-controller.d.ts.map +1 -0
  25. package/dist/client/terminal-command.d.ts +11 -0
  26. package/dist/client/terminal-command.d.ts.map +1 -0
  27. package/dist/client.js +776 -651
  28. package/dist/config.d.ts +6 -22
  29. package/dist/config.d.ts.map +1 -1
  30. package/dist/constants.d.ts +2 -4
  31. package/dist/constants.d.ts.map +1 -1
  32. package/dist/index.d.ts +5 -1
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.mjs +415 -453
  35. package/dist/message.d.ts +27 -0
  36. package/dist/message.d.ts.map +1 -0
  37. package/dist/reminder.d.ts +33 -0
  38. package/dist/reminder.d.ts.map +1 -0
  39. package/dist/routes.d.ts +5 -15
  40. package/dist/routes.d.ts.map +1 -1
  41. package/dist/sessions.d.ts +12 -13
  42. package/dist/sessions.d.ts.map +1 -1
  43. package/dist/state.d.ts +0 -2
  44. package/dist/state.d.ts.map +1 -1
  45. package/dist/tools.d.ts.map +1 -1
  46. package/dist/types.d.ts +2 -0
  47. package/dist/types.d.ts.map +1 -1
  48. package/dist/utils.d.ts +3 -1
  49. package/dist/utils.d.ts.map +1 -1
  50. package/dist/workspace-path.d.ts +8 -0
  51. package/dist/workspace-path.d.ts.map +1 -0
  52. package/dist/workspace.d.ts +32 -0
  53. package/dist/workspace.d.ts.map +1 -0
  54. package/locale/en.json +1 -1
  55. package/locale/zh.json +1 -1
  56. package/package.json +6 -5
package/dist/client.js CHANGED
@@ -7,12 +7,39 @@ 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
+ //#region src/workspace-path.ts
11
+ /** 工作区路径:统一 Linux 风格表示、平台比较与 Host 原生路径转换。 */
12
+ /** 判断原始或归一化路径是否使用 Windows 语义。 */
13
+ function isWindowsPath(value) {
14
+ return /^(?:[A-Za-z]:[\\/]|\\\\|\/\/|\/[A-Za-z](?:\/|$))/.test(value);
15
+ }
16
+ /** 统一斜杠、末尾分隔符与 Windows 盘符,例如 `C:\work\demo` 转为 `/c/work/demo`。 */
17
+ function normalizeWorkspacePath(value) {
18
+ const slashed = value.trim().replaceAll("\\", "/");
19
+ if (slashed === "") return "";
20
+ const drive = /^([A-Za-z]):(?:\/+(.*))?$/.exec(slashed);
21
+ if (drive !== null) {
22
+ const rest = (drive[2] ?? "").replace(/\/{2,}/g, "/").replace(/\/+$/, "");
23
+ return `/${drive[1]?.toLowerCase()}${rest === "" ? "" : `/${rest}`}`;
24
+ }
25
+ const unc = slashed.startsWith("//");
26
+ const collapsed = slashed.replace(/\/{2,}/g, "/");
27
+ const withoutTrailing = collapsed.length > 1 ? collapsed.replace(/\/+$/, "") : collapsed;
28
+ return unc ? `/${withoutTrailing}` : withoutTrailing;
29
+ }
30
+ /** 比较工作区路径;Windows 忽略大小写,POSIX 保持大小写敏感。 */
31
+ function sameWorkspacePath(a, b) {
32
+ const left = normalizeWorkspacePath(a);
33
+ const right = normalizeWorkspacePath(b);
34
+ return isWindowsPath(a) || isWindowsPath(b) ? left.toLowerCase() === right.toLowerCase() : left === right;
35
+ }
36
+ //#endregion
10
37
  //#region src/client/api.ts
11
38
  /** 构造路由地址。 */
12
39
  function endpoint(path) {
13
40
  return `${window.location.origin}/lark-bridge/${path}`;
14
41
  }
15
- /** 发起一次 JSON 调用;网络失败映射为可显示的失败。 */
42
+ /** 发起一次 JSON 调用;网络失败映射为内部结果。 */
16
43
  async function callApi(path, init = {}, signal) {
17
44
  try {
18
45
  const text = await (await fetch(endpoint(path), {
@@ -59,392 +86,276 @@ window.__ModuleLoader__.load({
59
86
  };
60
87
  }
61
88
  }
62
- /** 读取鉴权状态。 */
89
+ /** 读取最近一次连接状态。 */
63
90
  function fetchStatus(signal) {
64
91
  return callApi("status", { method: "GET" }, signal);
65
92
  }
66
- /** 重新检测。 */
93
+ /** 执行一次完整检测。 */
67
94
  function checkAuth() {
68
95
  return callApi("check", {
69
96
  method: "POST",
70
97
  body: "{}"
71
98
  });
72
99
  }
73
- /** 开始设备码授权。 */
74
- function startLogin() {
75
- return callApi("auth/start", {
76
- method: "POST",
77
- body: "{}"
78
- });
100
+ //#endregion
101
+ //#region src/client/status-controller.ts
102
+ /** 共享连接状态控制器:完整检测、只读轮询、订阅与清理。 */
103
+ const INITIAL_STATUS = {
104
+ cli: "checking",
105
+ bot: "checking",
106
+ user: "checking",
107
+ ready: false,
108
+ checkedAt: 0
109
+ };
110
+ /** 共享一份状态,避免弹窗与配置页分别执行检测。 */
111
+ var StatusController = class {
112
+ options;
113
+ fetchStatus;
114
+ checkAuth;
115
+ snapshot = {
116
+ status: INITIAL_STATUS,
117
+ busy: false
118
+ };
119
+ listeners = /* @__PURE__ */ new Set();
120
+ timer;
121
+ checking;
122
+ generation = 0;
123
+ disposed = false;
124
+ constructor(options = {}) {
125
+ this.options = options;
126
+ this.fetchStatus = options.fetchStatus ?? fetchStatus;
127
+ this.checkAuth = options.checkAuth ?? checkAuth;
128
+ if (options.autoStart !== false) this.start();
129
+ }
130
+ /** 当前状态快照。 */
131
+ getSnapshot = () => this.snapshot;
132
+ /** 订阅状态变化。 */
133
+ subscribe(listener) {
134
+ this.listeners.add(listener);
135
+ return () => this.listeners.delete(listener);
136
+ }
137
+ /** 开始加载检测和只读轮询。 */
138
+ start() {
139
+ if (this.disposed || this.timer !== void 0) return;
140
+ this.timer = setInterval(() => {
141
+ this.refresh();
142
+ }, this.options.intervalMs ?? 3e3);
143
+ this.check();
144
+ }
145
+ /** 完整检测;并发调用共享同一次请求。 */
146
+ check() {
147
+ if (this.checking !== void 0) return this.checking;
148
+ const generation = ++this.generation;
149
+ this.publish({
150
+ ...this.snapshot,
151
+ busy: true
152
+ });
153
+ this.checking = this.checkAuth().then((result) => {
154
+ if (!this.disposed && generation === this.generation && result.ok) this.publish({
155
+ status: result.data,
156
+ busy: false
157
+ });
158
+ }).finally(() => {
159
+ if (generation === this.generation) {
160
+ this.checking = void 0;
161
+ if (!this.disposed && this.snapshot.busy) this.publish({
162
+ ...this.snapshot,
163
+ busy: false
164
+ });
165
+ }
166
+ });
167
+ return this.checking;
168
+ }
169
+ /** 停止轮询并使未完成的请求结果失效。 */
170
+ dispose() {
171
+ this.disposed = true;
172
+ this.generation += 1;
173
+ if (this.timer !== void 0) clearInterval(this.timer);
174
+ this.timer = void 0;
175
+ this.checking = void 0;
176
+ this.listeners.clear();
177
+ }
178
+ async refresh() {
179
+ if (this.disposed || this.checking !== void 0) return;
180
+ const generation = this.generation;
181
+ const result = await this.fetchStatus();
182
+ if (!this.disposed && generation === this.generation && result.ok) this.publish({
183
+ ...this.snapshot,
184
+ status: result.data
185
+ });
186
+ }
187
+ publish(next) {
188
+ if (this.disposed) return;
189
+ this.snapshot = next;
190
+ for (const listener of this.listeners) listener(next);
191
+ }
192
+ };
193
+ /** 在 React 组件中订阅共享状态。 */
194
+ function useStatusSnapshot(controller) {
195
+ return (0, react.useSyncExternalStore)((listener) => controller.subscribe(() => listener()), controller.getSnapshot, controller.getSnapshot);
79
196
  }
80
- /** 取消设备码授权。 */
81
- function cancelLogin() {
82
- return callApi("auth/cancel", {
83
- method: "POST",
84
- body: "{}"
197
+ //#endregion
198
+ //#region src/client/terminal-command.tsx
199
+ /** 只读终端命令:展示需要在插件外执行的命令,并在右侧提供复制。 */
200
+ /** 展示一条可选择文本的只读命令与复制按钮。 */
201
+ function TerminalCommand({ kind, command, t }) {
202
+ const { copied, onCopy } = (0, _deepseek_ai_dsh_client_ui_primitives.useClipboardCopy)(command);
203
+ const label = copied ? t("auth.command.copied") : t("auth.command.copy");
204
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
205
+ style: rowStyle$1,
206
+ "data-dsh-lark-command-row": kind,
207
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
208
+ "data-dsh-lark-command": kind,
209
+ style: commandStyle,
210
+ children: command
211
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
212
+ type: "button",
213
+ variant: "ghost",
214
+ size: "sm",
215
+ style: copyButtonStyle,
216
+ "aria-label": label,
217
+ title: label,
218
+ "data-copied": copied ? "" : void 0,
219
+ icon: copied ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconCheckOutlineRegular, { size: 16 }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopyIcon, {}),
220
+ onClick: onCopy
221
+ })]
85
222
  });
86
223
  }
87
- /** 清除桥接会话记录。 */
88
- function resetSession() {
89
- return callApi("session/reset", {
90
- method: "POST",
91
- body: "{}"
224
+ /** 复制图标:宿主没有对应图标,用 16px 描边 SVG。 */
225
+ function CopyIcon() {
226
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
227
+ viewBox: "0 0 16 16",
228
+ width: 16,
229
+ height: 16,
230
+ fill: "none",
231
+ stroke: "currentColor",
232
+ strokeWidth: 1.3,
233
+ strokeLinecap: "round",
234
+ strokeLinejoin: "round",
235
+ "aria-hidden": "true",
236
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
237
+ x: "5.75",
238
+ y: "5.75",
239
+ width: "7.5",
240
+ height: "7.5",
241
+ rx: "1.5"
242
+ }), /* @__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" })]
92
243
  });
93
244
  }
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
- })
177
- });
178
- }
179
- const footerStyle = {
245
+ const rowStyle$1 = {
180
246
  display: "flex",
181
247
  alignItems: "center",
182
- gap: 8,
183
- width: "100%"
248
+ gap: 4
184
249
  };
185
- const spacerStyle = { flex: 1 };
186
- const buttonBase$1 = {
187
- padding: "4px 10px",
250
+ const commandStyle = {
251
+ flex: "1 1 auto",
252
+ minWidth: 0,
253
+ padding: "6px 8px",
188
254
  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",
255
+ background: "var(--dsw-alias-bg-secondary, transparent)",
256
+ color: "var(--dsw-alias-label-primary)",
257
+ fontFamily: "monospace",
207
258
  fontSize: 12,
208
259
  lineHeight: "18px",
209
- color: "var(--dsw-alias-label-secondary)"
260
+ overflowWrap: "anywhere",
261
+ userSelect: "text"
210
262
  };
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
258
- };
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
- }
263
+ const copyButtonStyle = {
264
+ flex: "none",
265
+ width: 28,
266
+ padding: 0,
267
+ color: "var(--dsw-alias-label-secondary)"
290
268
  };
291
269
  //#endregion
292
270
  //#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", {
271
+ const CONNECTIONS = [
272
+ {
273
+ key: "cli",
274
+ name: "auth.name.cli",
275
+ check: "auth.check.cli",
276
+ command: "auth.command.cli"
277
+ },
278
+ {
279
+ key: "bot",
280
+ name: "auth.name.bot",
281
+ check: "auth.check.bot",
282
+ command: "auth.command.bot"
283
+ },
284
+ {
285
+ key: "user",
286
+ name: "auth.name.user",
287
+ check: "auth.check.user",
288
+ command: "auth.command.user"
289
+ }
290
+ ];
291
+ /** 只读连接状态与三个检测入口。 */
292
+ function AuthPanelStatus({ t, status, busy, onCheck }) {
293
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("section", {
366
294
  "data-dsh-lark-auth-panel": true,
367
295
  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
- ]
296
+ children: CONNECTIONS.map((connection) => {
297
+ const state = status?.[connection.key] ?? "checking";
298
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
299
+ style: rowStyle,
300
+ "data-dsh-lark-connection": connection.key,
301
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
302
+ style: headerStyle,
303
+ children: [
304
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
305
+ style: {
306
+ ...dotStyle,
307
+ ...stateDotStyle[state]
308
+ },
309
+ "data-state": state,
310
+ "aria-hidden": "true"
311
+ }),
312
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
313
+ style: titleStyle$1,
314
+ children: t(connection.name)
315
+ }),
316
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
317
+ style: stateStyle,
318
+ children: t(`auth.state.${state}`)
319
+ }),
320
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
321
+ type: "button",
322
+ style: linkButtonStyle,
323
+ disabled: busy,
324
+ onClick: onCheck,
325
+ children: t(connection.check)
326
+ })
327
+ ]
328
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TerminalCommand, {
329
+ kind: connection.key,
330
+ command: t(connection.command),
331
+ t
332
+ })]
333
+ }, connection.key);
334
+ })
335
+ });
336
+ }
337
+ /** 从共享控制器读取状态的面板。 */
338
+ function AuthPanel({ t, controller }) {
339
+ const snapshot = useStatusSnapshot(controller);
340
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AuthPanelStatus, {
341
+ t,
342
+ status: snapshot.status,
343
+ busy: snapshot.busy,
344
+ onCheck: () => void controller.check()
439
345
  });
440
346
  }
441
347
  const sectionStyle = {
442
348
  display: "flex",
443
349
  flexDirection: "column",
444
- gap: 8,
350
+ gap: 12,
445
351
  padding: "12px 0",
446
352
  borderBottom: "0.5px solid var(--dsw-alias-border-l2)"
447
353
  };
354
+ const rowStyle = {
355
+ display: "flex",
356
+ flexDirection: "column",
357
+ gap: 6
358
+ };
448
359
  const headerStyle = {
449
360
  display: "flex",
450
361
  alignItems: "center",
@@ -456,62 +367,20 @@ window.__ModuleLoader__.load({
456
367
  borderRadius: 999,
457
368
  flex: "none"
458
369
  };
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)"
370
+ const stateDotStyle = {
371
+ checking: { background: "var(--dsw-alias-warning-fill, #bf8700)" },
372
+ connected: { background: "var(--dsw-alias-success-fill, #2da44e)" },
373
+ disconnected: { background: "var(--dsw-alias-label-tertiary, #8c959f)" }
466
374
  };
467
375
  const titleStyle$1 = {
468
376
  fontSize: 13,
469
377
  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)"
378
+ color: "var(--dsw-alias-label-primary)"
478
379
  };
479
- const metaStyle = {
480
- margin: 0,
380
+ const stateStyle = {
481
381
  fontSize: 12,
482
- lineHeight: "18px",
483
382
  color: "var(--dsw-alias-label-secondary)"
484
383
  };
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
384
  const linkButtonStyle = {
516
385
  border: "none",
517
386
  background: "transparent",
@@ -521,13 +390,97 @@ window.__ModuleLoader__.load({
521
390
  cursor: "pointer",
522
391
  padding: 0
523
392
  };
524
- const linkStyle = {
525
- ...linkButtonStyle,
526
- fontSize: 12,
527
- textDecoration: "underline"
528
- };
529
393
  //#endregion
530
394
  //#region src/client/config-page.tsx
395
+ /** 读取宿主当前工作区条目。 */
396
+ function useWorkspaceItems(useWorkspaces) {
397
+ return useWorkspaces((state) => state.items);
398
+ }
399
+ /** 把注册列表转成下拉选项,路径统一为 Linux 风格。 */
400
+ function workspaceOptions(items) {
401
+ return items.map((item) => ({
402
+ id: String(item.workspaceId),
403
+ title: item.title,
404
+ path: normalizeWorkspacePath(item.path)
405
+ }));
406
+ }
407
+ /** 从当前注册列表选择工作区,值为归一化路径。 */
408
+ function WorkspaceSelect({ t, useWorkspaces, value, disabled, onChange, invalid = false }) {
409
+ const id = (0, react.useId)();
410
+ const options = workspaceOptions(useWorkspaceItems(useWorkspaces));
411
+ const selected = options.find((option) => sameWorkspacePath(option.path, value));
412
+ const [open, setOpen] = (0, react.useState)(false);
413
+ const triggerRef = (0, react.useRef)(null);
414
+ const empty = options.length === 0;
415
+ const label = empty ? t("config.workspaceRoot.empty") : selected === void 0 ? t("config.workspaceRoot.placeholder") : `${selected.title} — ${selected.path}`;
416
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
417
+ style: fieldStyle,
418
+ "data-dsh-lark-config-workspace": true,
419
+ children: [
420
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
421
+ style: labelRowStyle,
422
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
423
+ htmlFor: id,
424
+ style: titleStyle,
425
+ children: t("config.workspaceRoot.title")
426
+ })
427
+ }),
428
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
429
+ style: triggerRowStyle,
430
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Menu, {
431
+ open,
432
+ anchorRef: triggerRef,
433
+ portal: true,
434
+ align: "start",
435
+ items: options.map((option) => ({
436
+ id: option.id,
437
+ label: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
438
+ style: optionLabelStyle,
439
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
440
+ style: optionTitleStyle,
441
+ children: option.title
442
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
443
+ style: optionPathStyle,
444
+ children: option.path
445
+ })]
446
+ })
447
+ })),
448
+ selectedId: selected?.id,
449
+ onSelect: (selectedId) => {
450
+ setOpen(false);
451
+ const option = options.find((candidate) => candidate.id === selectedId);
452
+ if (option !== void 0) onChange(option.path);
453
+ },
454
+ onClose: () => setOpen(false),
455
+ anchor: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_deepseek_ai_dsh_client_ui_primitives.Button, {
456
+ ref: triggerRef,
457
+ id,
458
+ type: "button",
459
+ variant: "outline",
460
+ size: "md",
461
+ style: triggerStyle,
462
+ disabled: disabled || empty,
463
+ "aria-haspopup": "menu",
464
+ "aria-expanded": open,
465
+ onClick: () => setOpen((previous) => !previous),
466
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
467
+ style: triggerLabelStyle,
468
+ children: label
469
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconChevronDownOutlineRegular, { size: 16 })]
470
+ })
471
+ })
472
+ }),
473
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
474
+ style: descriptionStyle,
475
+ children: t("config.workspaceRoot.description")
476
+ }),
477
+ invalid ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
478
+ style: invalidStyle,
479
+ children: t("config.workspaceRoot.invalid")
480
+ }) : null
481
+ ]
482
+ });
483
+ }
531
484
  /** 表单框架文案。 */
532
485
  function formLabels(t) {
533
486
  return {
@@ -541,149 +494,39 @@ window.__ModuleLoader__.load({
541
494
  /** 渲染插件行配置。 */
542
495
  function ConfigPage(props) {
543
496
  const { t } = props;
544
- const id = (0, react.useId)();
545
497
  const state = props.useConfigForm((value) => value);
546
- const [resetNotice, setResetNotice] = (0, react.useState)("");
547
498
  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, {
499
+ const disabled = !state.available || !state.writable || state.saving;
500
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(AuthPanel, {
501
+ t,
502
+ controller: props.controller
503
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.SettingsForm, {
550
504
  state,
551
505
  labels: formLabels(t),
552
506
  onSave: props.save,
553
507
  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")
575
- })
576
- }),
577
- /* @__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")
592
- })
593
- }),
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
- })]
611
- }),
612
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h4", {
613
- style: sectionTitleStyle,
614
- children: t("config.section.auth")
615
- }),
616
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
617
- 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
- })
632
- }),
633
- /* @__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", {
639
- 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
- })]
662
- })
663
- ]
508
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WorkspaceSelect, {
509
+ t,
510
+ useWorkspaces: props.useWorkspaces,
511
+ value: state.workspaceRoot.text,
512
+ disabled,
513
+ invalid: state.workspaceRoot.invalid,
514
+ onChange: (path) => props.edit("workspaceRoot", path)
515
+ })
664
516
  })] });
665
517
  }
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"
518
+ const fieldStyle = {
519
+ display: "flex",
520
+ flexDirection: "column",
521
+ gap: 6,
522
+ padding: "12px 0",
523
+ borderTop: "0.5px solid var(--dsw-alias-border-l2)"
673
524
  };
674
- const rowStyle = {
525
+ const labelRowStyle = {
675
526
  display: "flex",
676
527
  alignItems: "center",
677
528
  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
529
+ gap: 12
687
530
  };
688
531
  const titleStyle = {
689
532
  fontSize: 13,
@@ -691,27 +534,340 @@ window.__ModuleLoader__.load({
691
534
  lineHeight: 1.5,
692
535
  color: "var(--dsw-alias-label-primary)"
693
536
  };
537
+ const triggerRowStyle = { display: "grid" };
538
+ const triggerStyle = {
539
+ width: "100%",
540
+ justifyContent: "space-between",
541
+ gap: 8,
542
+ paddingInline: 10,
543
+ fontSize: 13,
544
+ fontWeight: 400
545
+ };
546
+ const triggerLabelStyle = {
547
+ flex: "1 1 auto",
548
+ minWidth: 0,
549
+ overflow: "hidden",
550
+ textOverflow: "ellipsis",
551
+ whiteSpace: "nowrap",
552
+ textAlign: "left"
553
+ };
554
+ const optionLabelStyle = {
555
+ display: "flex",
556
+ flexDirection: "column",
557
+ gap: 1,
558
+ minWidth: 0,
559
+ whiteSpace: "normal"
560
+ };
561
+ const optionTitleStyle = {
562
+ overflow: "hidden",
563
+ textOverflow: "ellipsis",
564
+ whiteSpace: "nowrap"
565
+ };
566
+ const optionPathStyle = {
567
+ overflow: "hidden",
568
+ textOverflow: "ellipsis",
569
+ whiteSpace: "nowrap",
570
+ fontSize: 11,
571
+ lineHeight: "16px",
572
+ color: "var(--dsw-alias-label-secondary)"
573
+ };
694
574
  const descriptionStyle = {
695
575
  margin: 0,
696
576
  fontSize: 12,
697
577
  lineHeight: "18px",
698
578
  color: "var(--dsw-alias-label-secondary)"
699
579
  };
700
- const noticeStyle = {
580
+ const invalidStyle = {
701
581
  ...descriptionStyle,
702
- color: "var(--dsw-alias-label-link, #0969da)"
582
+ color: "var(--dsw-alias-error-fill, #cf222e)"
703
583
  };
704
- const secondaryButtonStyle = {
705
- flex: "none",
584
+ //#endregion
585
+ //#region src/client/auth-overlay.tsx
586
+ /** 共用设置弹窗:连接状态、注册工作区选择、失效重开与保存状态。 */
587
+ /** 计算当前失效签名;连接与工作区均有效时返回空串。 */
588
+ function getAuthOverlaySignature(status, workspaceRoot, workspacePaths) {
589
+ const root = normalizeWorkspacePath(workspaceRoot);
590
+ const workspaceValid = workspacePaths.some((path) => sameWorkspacePath(path, root));
591
+ if (status.ready && workspaceValid) return "";
592
+ return `${status.cli}/${status.bot}/${status.user}|${workspaceValid ? "valid" : "invalid"}:${root}`;
593
+ }
594
+ /** 弹窗初始状态。 */
595
+ const INITIAL_AUTH_OVERLAY_STATE = {
596
+ signature: "initial",
597
+ open: true,
598
+ dismissed: false,
599
+ settleDismissed: false,
600
+ editing: false,
601
+ saving: false
602
+ };
603
+ /** 管理失效重开和显式保存;未发起保存的 settle 不产生副作用。 */
604
+ function reduceAuthOverlayState(state, action) {
605
+ switch (action.type) {
606
+ case "sync": {
607
+ const changed = action.signature !== state.signature;
608
+ if (action.signature === "" && !state.editing && !state.saving) return {
609
+ signature: "",
610
+ open: false,
611
+ dismissed: false,
612
+ settleDismissed: false,
613
+ editing: false,
614
+ saving: false
615
+ };
616
+ if (state.dismissed && (state.settleDismissed || !changed)) return {
617
+ ...state,
618
+ signature: action.signature,
619
+ settleDismissed: false
620
+ };
621
+ return {
622
+ ...state,
623
+ signature: action.signature,
624
+ open: true,
625
+ dismissed: false
626
+ };
627
+ }
628
+ case "editStart": return {
629
+ ...state,
630
+ open: true,
631
+ dismissed: false,
632
+ editing: true
633
+ };
634
+ case "dismiss": return {
635
+ ...state,
636
+ open: false,
637
+ dismissed: true,
638
+ settleDismissed: false,
639
+ editing: false,
640
+ saving: false
641
+ };
642
+ case "discard": return {
643
+ ...state,
644
+ open: false,
645
+ dismissed: true,
646
+ settleDismissed: true,
647
+ editing: false,
648
+ saving: false
649
+ };
650
+ case "saveStart": return {
651
+ ...state,
652
+ open: true,
653
+ dismissed: false,
654
+ saving: true
655
+ };
656
+ case "saveSettled":
657
+ if (!state.saving) return state;
658
+ if (action.saving || action.dirty || action.failed) return {
659
+ ...state,
660
+ open: true,
661
+ saving: false,
662
+ editing: true
663
+ };
664
+ return {
665
+ signature: "",
666
+ open: false,
667
+ dismissed: false,
668
+ settleDismissed: false,
669
+ editing: false,
670
+ saving: false
671
+ };
672
+ }
673
+ }
674
+ /** 连接面板与工作区选择正文。 */
675
+ function AuthOverlayContent({ t, controller, useWorkspaces, form, onEdit, onSave, onClose, onOpenSettings }) {
676
+ const disabled = !form.available || !form.writable || form.saving;
677
+ const saveDisabled = disabled || !form.dirty || form.invalid || form.workspaceRoot.text === "";
678
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [
679
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AuthPanel, {
680
+ t,
681
+ controller
682
+ }),
683
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(WorkspaceSelect, {
684
+ t,
685
+ useWorkspaces,
686
+ value: form.workspaceRoot.text,
687
+ disabled,
688
+ invalid: form.workspaceRoot.invalid,
689
+ onChange: onEdit
690
+ }),
691
+ form.failed ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
692
+ style: failedStyle,
693
+ children: t("config.saveFailed")
694
+ }) : null,
695
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
696
+ style: actionsStyle,
697
+ children: [
698
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
699
+ type: "button",
700
+ style: secondaryStyle,
701
+ onClick: onClose,
702
+ children: t("auth.close")
703
+ }),
704
+ onOpenSettings === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
705
+ type: "button",
706
+ style: secondaryStyle,
707
+ onClick: onOpenSettings,
708
+ children: t("auth.openSettings")
709
+ }),
710
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
711
+ type: "button",
712
+ style: {
713
+ ...primaryStyle,
714
+ ...saveDisabled ? disabledButtonStyle : {}
715
+ },
716
+ disabled: saveDisabled,
717
+ onClick: onSave,
718
+ children: form.saving ? t("config.saving") : t("config.saveSelection")
719
+ })
720
+ ]
721
+ })
722
+ ] });
723
+ }
724
+ /** 共用设置弹窗。 */
725
+ function AuthOverlay(props) {
726
+ const { t, controller } = props;
727
+ const { status } = useStatusSnapshot(controller);
728
+ const form = props.useConfigForm((value) => value);
729
+ const workspacePaths = useWorkspaceItems(props.useWorkspaces).map((item) => item.path);
730
+ const signature = getAuthOverlaySignature(status, form.workspaceRoot.text, workspacePaths);
731
+ const [state, dispatch] = (0, react.useReducer)(reduceAuthOverlayState, INITIAL_AUTH_OVERLAY_STATE, (initial) => ({
732
+ ...initial,
733
+ signature,
734
+ open: signature !== ""
735
+ }));
736
+ const wasSaving = (0, react.useRef)(false);
737
+ (0, react.useEffect)(() => {
738
+ dispatch({
739
+ type: "sync",
740
+ signature
741
+ });
742
+ }, [signature]);
743
+ (0, react.useEffect)(() => {
744
+ if (wasSaving.current && !form.saving) dispatch({
745
+ type: "saveSettled",
746
+ saving: form.saving,
747
+ dirty: form.dirty,
748
+ failed: form.failed
749
+ });
750
+ wasSaving.current = form.saving;
751
+ }, [
752
+ form.saving,
753
+ form.dirty,
754
+ form.failed
755
+ ]);
756
+ if (!state.open) return null;
757
+ const onClose = () => {
758
+ if (state.editing) {
759
+ props.discard();
760
+ dispatch({ type: "discard" });
761
+ return;
762
+ }
763
+ dispatch({ type: "dismiss" });
764
+ };
765
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Modal, {
766
+ open: true,
767
+ onClose,
768
+ title: t("auth.title"),
769
+ closeLabel: t("auth.close"),
770
+ description: t("auth.description"),
771
+ tone: "warning",
772
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AuthOverlayContent, {
773
+ t,
774
+ controller,
775
+ useWorkspaces: props.useWorkspaces,
776
+ form,
777
+ onEdit: (path) => {
778
+ dispatch({ type: "editStart" });
779
+ props.edit("workspaceRoot", path);
780
+ },
781
+ onSave: () => {
782
+ dispatch({ type: "saveStart" });
783
+ props.save();
784
+ },
785
+ onClose,
786
+ onOpenSettings: () => {
787
+ props.openSettings();
788
+ dispatch({ type: "dismiss" });
789
+ }
790
+ })
791
+ });
792
+ }
793
+ const actionsStyle = {
794
+ display: "flex",
795
+ justifyContent: "flex-end",
796
+ gap: 8,
797
+ paddingTop: 12
798
+ };
799
+ const buttonBase = {
706
800
  padding: "4px 10px",
707
- border: "1px solid var(--dsw-alias-border-l2)",
708
801
  borderRadius: "var(--dsw-radius-sm, 6px)",
709
- background: "var(--dsw-alias-button-tool-bar-fill, transparent)",
710
- color: "var(--dsw-alias-label-primary)",
711
802
  font: "inherit",
712
803
  fontSize: 12,
713
804
  cursor: "pointer"
714
805
  };
806
+ const secondaryStyle = {
807
+ ...buttonBase,
808
+ border: "1px solid var(--dsw-alias-border-l2)",
809
+ background: "var(--dsw-alias-button-tool-bar-fill, transparent)",
810
+ color: "var(--dsw-alias-label-primary)"
811
+ };
812
+ const primaryStyle = {
813
+ ...buttonBase,
814
+ border: "1px solid var(--dsw-alias-brand-fill, #0969da)",
815
+ background: "var(--dsw-alias-brand-fill, #0969da)",
816
+ color: "var(--dsw-alias-label-on-brand, #fff)"
817
+ };
818
+ const disabledButtonStyle = {
819
+ borderColor: "var(--dsw-alias-border-l2)",
820
+ background: "var(--dsw-alias-button-tool-bar-fill, transparent)",
821
+ color: "var(--dsw-alias-label-secondary)",
822
+ cursor: "not-allowed",
823
+ opacity: .65
824
+ };
825
+ const failedStyle = {
826
+ margin: "8px 0 0",
827
+ fontSize: 12,
828
+ color: "var(--dsw-alias-error-fill, #cf222e)"
829
+ };
830
+ //#endregion
831
+ //#region src/client/config-form.ts
832
+ /** 插件在前端使用的行键:`<包名>#<行 id>`。 */
833
+ const ROW_KEY = "dsh-plugin-lark-bridge#dsh-plugin-lark-bridge";
834
+ /** 行 id,同时是宿主配置的条目 id 与表单命名空间。 */
835
+ const ROW_ID = "dsh-plugin-lark-bridge";
836
+ const workspaceSpec = {
837
+ field: "workspaceRoot",
838
+ format: (value) => typeof value === "string" ? normalizeWorkspacePath(value) : "",
839
+ parse: (text) => {
840
+ const path = normalizeWorkspacePath(text);
841
+ return path.startsWith("/") ? {
842
+ kind: "set",
843
+ value: path
844
+ } : void 0;
845
+ }
846
+ };
847
+ /** 暂存工作区编辑,保存时写入宿主配置。 */
848
+ var PluginConfigForm = class {
849
+ form;
850
+ state;
851
+ /** @param scope - 宿主为该行提供的配置表单。 */
852
+ constructor(scope) {
853
+ this.form = new _deepseek_ai_dsh_client_ui_primitives.SettingsFormModel(scope, [workspaceSpec]);
854
+ this.state = this.form.bind(() => ({
855
+ ...this.form.shell(),
856
+ workspaceRoot: this.form.field("workspaceRoot")
857
+ }));
858
+ }
859
+ /** @returns 配置页向槽位组件提供的注入值。 */
860
+ inject() {
861
+ return {
862
+ hooks: { configForm: this.state },
863
+ ...this.form.actions()
864
+ };
865
+ }
866
+ /** 释放对宿主表单的订阅。 */
867
+ dispose() {
868
+ this.form.dispose();
869
+ }
870
+ };
715
871
  //#endregion
716
872
  //#region src/client/locales.ts
717
873
  /** 前端字典与命名空间。中文字典是键集事实源。 */
@@ -719,114 +875,75 @@ window.__ModuleLoader__.load({
719
875
  const NS = "dsh-plugin-lark-bridge";
720
876
  /** 中文字典。 */
721
877
  const zh = {
722
- "auth.title": "飞书机器人尚未就绪",
723
- "auth.description": "完成鉴权后,插件才能接收飞书消息并以机器人身份回复。",
878
+ "auth.title": "飞书桥接设置",
879
+ "auth.description": "完成连接检查并选择工作区。命令需要在终端执行。",
880
+ "auth.ready": "飞书连接已就绪",
724
881
  "auth.close": "本次不再提示",
725
882
  "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": "会话",
883
+ "auth.name.cli": "lark-cli",
884
+ "auth.name.bot": "机器人身份(bot)",
885
+ "auth.name.user": "用户身份(user)",
886
+ "auth.state.checking": "检测中…",
887
+ "auth.state.connected": "已连接",
888
+ "auth.state.disconnected": "未连接",
889
+ "auth.check.cli": "检测 lark-cli",
890
+ "auth.check.bot": "检测机器人身份",
891
+ "auth.check.user": "检测用户身份",
892
+ "auth.command.cli": "npm install -g @larksuite/cli@latest",
893
+ "auth.command.bot": "lark-cli config init",
894
+ "auth.command.user": "lark-cli auth login --scope auth:user.id:read",
895
+ "auth.command.copy": "复制命令",
896
+ "auth.command.copied": "已复制",
897
+ "config.summary": "工作区与飞书连接",
749
898
  "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": "会话记录已清除。",
899
+ "config.workspaceRoot.description": "飞书消息注入到所选 DSH 工作区的会话。",
900
+ "config.workspaceRoot.invalid": "请选择一个已注册的工作区。",
901
+ "config.workspaceRoot.placeholder": "请选择工作区",
902
+ "config.workspaceRoot.empty": "暂无已注册工作区",
903
+ "config.saveSelection": "保存选择",
762
904
  "config.unavailable": "配置不可用。",
763
905
  "config.readOnly": "此部署以只读方式保存设置。",
764
906
  "config.saveFailed": "此部署未接受这些值,已保留以便修改。",
765
907
  "config.save": "保存",
766
- "config.saving": "保存中…",
767
- "config.overridden": "已覆盖",
768
- "config.reset": "恢复默认",
769
- "config.currentSession": "当前会话:{session}",
770
- "config.noSession": "尚未创建桥接会话。"
908
+ "config.saving": "保存中…"
771
909
  };
772
910
  /** 英文字典,键集与中文一致。 */
773
911
  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.",
912
+ "auth.title": "Lark bridge setup",
913
+ "auth.description": "Check the connections and select a workspace. Run commands in a terminal.",
914
+ "auth.ready": "Lark connections are ready",
776
915
  "auth.close": "Not now",
777
916
  "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",
917
+ "auth.name.cli": "lark-cli",
918
+ "auth.name.bot": "Bot identity",
919
+ "auth.name.user": "User identity",
920
+ "auth.state.checking": "Checking…",
921
+ "auth.state.connected": "Connected",
922
+ "auth.state.disconnected": "Disconnected",
923
+ "auth.check.cli": "Check lark-cli",
924
+ "auth.check.bot": "Check bot identity",
925
+ "auth.check.user": "Check user identity",
926
+ "auth.command.cli": "npm install -g @larksuite/cli@latest",
927
+ "auth.command.bot": "lark-cli config init",
928
+ "auth.command.user": "lark-cli auth login --scope auth:user.id:read",
929
+ "auth.command.copy": "Copy command",
930
+ "auth.command.copied": "Copied",
931
+ "config.summary": "Workspace and Lark connections",
801
932
  "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.",
933
+ "config.workspaceRoot.description": "Lark messages are injected into the selected DSH workspace.",
934
+ "config.workspaceRoot.invalid": "Select a registered workspace.",
935
+ "config.workspaceRoot.placeholder": "Select a workspace",
936
+ "config.workspaceRoot.empty": "No registered workspaces",
937
+ "config.saveSelection": "Save selection",
814
938
  "config.unavailable": "Configuration is unavailable.",
815
939
  "config.readOnly": "This deployment stores settings read-only.",
816
940
  "config.saveFailed": "The deployment did not accept these values; they were left for you to correct.",
817
941
  "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."
942
+ "config.saving": "Saving…"
823
943
  };
824
944
  //#endregion
825
945
  //#region src/client/index.ts
826
- /**
827
- * 插件在前端启用时调用。
828
- * 字典、弹窗与配置页各自等待所需服务;服务缺失时该功能不加载。
829
- */
946
+ /** 注册共享状态、弹窗和配置页。 */
830
947
  function apply(ctx) {
831
948
  ctx.inject(["locale"], (ctx) => {
832
949
  ctx.effect(() => ctx.locale.register(NS, {
@@ -834,37 +951,45 @@ window.__ModuleLoader__.load({
834
951
  en
835
952
  }), `${NS}: dictionaries`);
836
953
  });
837
- ctx.inject(["slots", "locale"], (ctx) => {
838
- const layout = ctx.get("layout");
839
- const navigation = ctx.get("pluginNavigation");
840
- ctx.slots.inject("shell.overlay", () => ctx.slots.register({
841
- name: "shell.overlay",
842
- id: "lark-bridge-auth",
843
- order: 20,
844
- 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
- } })
852
- }, AuthOverlay));
853
- });
854
954
  ctx.inject([
855
955
  "slots",
856
956
  "locale",
857
957
  "configForms"
858
958
  ], (ctx) => {
859
959
  const form = new PluginConfigForm(ctx.configForms.get(ROW_ID));
960
+ const controller = new StatusController({ autoStart: typeof window !== "undefined" && typeof window.setInterval === "function" && typeof window.clearInterval === "function" });
860
961
  ctx.effect(() => () => {
962
+ controller.dispose();
861
963
  form.dispose();
862
- }, `${NS}: config form`);
964
+ }, `${NS}: shared state`);
965
+ const layout = ctx.get("layout");
966
+ const navigation = ctx.get("pluginNavigation");
967
+ const openSettings = () => {
968
+ if (navigation?.openBundle !== void 0) {
969
+ navigation.openBundle("dsh-plugin-lark-bridge");
970
+ return;
971
+ }
972
+ layout?.selectPanel("plugins");
973
+ };
974
+ ctx.slots.inject("shell.overlay", () => ctx.slots.register({
975
+ name: "shell.overlay",
976
+ id: "lark-bridge-auth",
977
+ order: 20,
978
+ locale: NS,
979
+ inject: () => ({
980
+ ...form.inject(),
981
+ controller,
982
+ openSettings
983
+ })
984
+ }, AuthOverlay));
863
985
  ctx.slots.inject("plugins.row.config", () => ctx.slots.register({
864
986
  name: "plugins.row.config",
865
987
  key: ROW_KEY,
866
988
  locale: NS,
867
- inject: () => form.inject()
989
+ inject: () => ({
990
+ ...form.inject(),
991
+ controller
992
+ })
868
993
  }, ConfigPage));
869
994
  });
870
995
  }