@aipanel/provider-deepseek 1.2.8 → 1.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/system.cjs CHANGED
@@ -24,25 +24,15 @@ __export(system_exports, {
24
24
  killOrphanDeepSeekProcesses: () => killOrphanDeepSeekProcesses
25
25
  });
26
26
  module.exports = __toCommonJS(system_exports);
27
- var import_child_process = require("child_process");
28
27
  var import_node = require("@aipanel/core/node");
29
- const log = (0, import_node.createLogger)("DeepSeekSystem");
30
- async function checkDeepSeekInstalled() {
31
- const timer = log.timer("checkDeepSeekInstalled");
32
- return new Promise((resolve) => {
33
- log.debug("Checking if dsh is installed...");
34
- const proc = (0, import_child_process.spawn)("dsh", ["--version"], { stdio: "ignore", shell: true });
35
- proc.on("close", (code) => {
36
- const installed = code === 0;
37
- timer.end(installed ? "\u2713 dsh is installed" : "\u274C dsh not found");
38
- resolve(installed);
39
- });
40
- proc.on("error", (err) => {
41
- log.debug("Failed to check dsh installation", { error: err.message });
42
- timer.end("\u274C Check failed");
43
- resolve(false);
44
- });
45
- });
28
+ function checkDeepSeekInstalled() {
29
+ return (0, import_node.checkCliInstalled)("dsh");
30
+ }
31
+ function getDeepSeekVersion() {
32
+ return (0, import_node.getCliVersion)("dsh");
33
+ }
34
+ function killOrphanDeepSeekProcesses() {
35
+ return (0, import_node.killOrphanCliProcesses)("dsh", { match: "dsh", winName: "node.exe", label: "dsh" });
46
36
  }
47
37
  const MIN_DSH_VERSION = "0.1.2-rc.1";
48
38
  function parseDshVersion(version) {
@@ -83,151 +73,6 @@ function isDeepSeekVersionAtLeast(version, minimum = MIN_DSH_VERSION) {
83
73
  }
84
74
  return true;
85
75
  }
86
- function getDeepSeekVersion() {
87
- return new Promise((resolve) => {
88
- const proc = (0, import_child_process.spawn)("dsh", ["--version"], { stdio: "pipe", shell: true });
89
- let output = "";
90
- proc.stdout?.on("data", (data) => {
91
- output += data.toString();
92
- });
93
- proc.on("close", (code) => {
94
- if (code === 0 && output.trim()) {
95
- resolve(output.trim());
96
- } else {
97
- resolve(null);
98
- }
99
- });
100
- proc.on("error", () => {
101
- resolve(null);
102
- });
103
- });
104
- }
105
- const KILL_ORPHAN_TIMEOUT = 5e3;
106
- async function killOrphanDeepSeekProcesses() {
107
- const timer = log.timer("killOrphanDeepSeekProcesses");
108
- log.debug("Looking for orphan dsh processes (PPID=1)");
109
- return new Promise((resolve) => {
110
- let settled = false;
111
- const done = (count) => {
112
- if (settled) return;
113
- settled = true;
114
- resolve(count);
115
- };
116
- const timeout = setTimeout(() => {
117
- log.warn("Kill orphan processes timed out, skipping");
118
- timer.end("\u26A0 Timeout, skipped");
119
- done(0);
120
- }, KILL_ORPHAN_TIMEOUT);
121
- const wrappedResolve = (count) => {
122
- clearTimeout(timeout);
123
- done(count);
124
- };
125
- if (process.platform === "win32") {
126
- killOrphanProcessesOnWindows(wrappedResolve, timer);
127
- } else {
128
- killOrphanProcessesOnUnix(wrappedResolve, timer);
129
- }
130
- });
131
- }
132
- function killOrphanProcessesOnWindows(resolve, timer) {
133
- log.debug("Using Windows method to find orphan processes");
134
- const proc = (0, import_child_process.spawn)(
135
- "wmic",
136
- ["process", "where", 'name="node.exe"', "get", "processid,parentprocessid,commandline"],
137
- { stdio: "pipe" }
138
- );
139
- let output = "";
140
- proc.stdout?.on("data", (data) => {
141
- output += data.toString();
142
- });
143
- proc.on("close", () => {
144
- const pidsToKill = [];
145
- output.split("\n").forEach((rawLine) => {
146
- const line = rawLine.trim();
147
- if (!line.includes("dsh")) return;
148
- const parts = line.trim().split(/\s+/);
149
- if (parts.length >= 2) {
150
- const ppid = parts[0];
151
- const pid = parts[1];
152
- if (ppid === "1" && pid && !isNaN(Number(pid))) {
153
- pidsToKill.push(pid);
154
- }
155
- }
156
- });
157
- if (pidsToKill.length > 0) {
158
- log.debug(`Found ${pidsToKill.length} orphan processes`, { pids: pidsToKill });
159
- let killedCount = 0;
160
- let completedCount = 0;
161
- pidsToKill.forEach((pid) => {
162
- const killProc = (0, import_child_process.spawn)("taskkill", ["/F", "/PID", pid], { stdio: "ignore" });
163
- killProc.on("close", (code) => {
164
- completedCount++;
165
- if (code === 0) killedCount++;
166
- if (completedCount === pidsToKill.length) {
167
- timer.end(`\u2713 Killed ${killedCount} orphan processes`);
168
- resolve(killedCount);
169
- }
170
- });
171
- });
172
- } else {
173
- log.debug("No orphan processes found");
174
- timer.end("No orphan processes found");
175
- resolve(0);
176
- }
177
- });
178
- proc.on("error", (err) => {
179
- log.debug("Failed to find orphan processes", { error: err.message });
180
- timer.end("\u274C Failed to find orphan processes");
181
- resolve(0);
182
- });
183
- }
184
- function killOrphanProcessesOnUnix(resolve, timer) {
185
- log.debug("Using Unix method to find orphan processes");
186
- const proc = (0, import_child_process.spawn)("ps", ["-e", "-o", "pid,ppid,args"], { stdio: "pipe" });
187
- let output = "";
188
- proc.stdout?.on("data", (data) => {
189
- output += data.toString();
190
- });
191
- proc.on("close", () => {
192
- const lines = output.split("\n");
193
- const pidsToKill = [];
194
- lines.forEach((line) => {
195
- if (!line.includes("dsh")) return;
196
- const parts = line.trim().split(/\s+/);
197
- if (parts.length >= 3) {
198
- const pid = parts[0];
199
- const ppid = parts[1];
200
- if (ppid === "1") {
201
- pidsToKill.push(pid);
202
- }
203
- }
204
- });
205
- if (pidsToKill.length > 0) {
206
- log.debug(`Found ${pidsToKill.length} orphan processes`, { pids: pidsToKill });
207
- const killProc = (0, import_child_process.spawn)("kill", ["-9", ...pidsToKill], { stdio: "ignore" });
208
- killProc.on("close", (code) => {
209
- const killedCount = code === 0 ? pidsToKill.length : 0;
210
- timer.end(
211
- killedCount > 0 ? `\u2713 Killed ${killedCount} orphan processes` : "\u274C Failed to kill processes"
212
- );
213
- resolve(killedCount);
214
- });
215
- killProc.on("error", () => {
216
- timer.end("\u274C Failed to kill processes");
217
- resolve(0);
218
- });
219
- } else {
220
- log.debug("No orphan processes found");
221
- timer.end("No orphan processes found");
222
- resolve(0);
223
- }
224
- });
225
- proc.on("error", (err) => {
226
- log.debug("Failed to find orphan processes", { error: err.message });
227
- timer.end("\u274C Failed to find orphan processes");
228
- resolve(0);
229
- });
230
- }
231
76
  // Annotate the CommonJS export names for ESM import in node:
232
77
  0 && (module.exports = {
233
78
  MIN_DSH_VERSION,
package/lib/system.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  export declare function checkDeepSeekInstalled(): Promise<boolean>;
2
+ export declare function getDeepSeekVersion(): Promise<string | null>;
3
+ export declare function killOrphanDeepSeekProcesses(): Promise<number>;
2
4
  /** 本 provider 要求的 dsh 最低版本(0.1.2 起:browser-session 认证 + {args} Remote RPC + remote.mux,协议不向下兼容) */
3
5
  export declare const MIN_DSH_VERSION = "0.1.2-rc.1";
4
6
  /**
5
7
  * 判定 version 是否 >= minimum(semver 风格,含 pre-release 比较:0.1.2 > 0.1.2-rc.1)。
6
- * @returns true/false;任一版本无法解析时返回 null(调用方按"无法确认"放行)。
8
+ * @returns true/false;任一版本无法解析时返回 null(调用方按“无法确认”放行)。
7
9
  */
8
10
  export declare function isDeepSeekVersionAtLeast(version: string, minimum?: string): boolean | null;
9
- export declare function getDeepSeekVersion(): Promise<string | null>;
10
- export declare function killOrphanDeepSeekProcesses(): Promise<number>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aipanel/provider-deepseek",
3
- "version": "1.2.8",
3
+ "version": "1.2.10",
4
4
  "type": "module",
5
5
  "main": "lib/index.cjs",
6
6
  "module": "es/index.js",
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "execa": "^9.6.1",
25
- "@aipanel/core": "1.2.8"
25
+ "@aipanel/core": "1.2.10"
26
26
  },
27
27
  "devDependencies": {
28
28
  "esbuild": "^0.25.0"
@@ -1,13 +0,0 @@
1
- export interface BridgeScriptOptions {
2
- /** 主题模式 */
3
- theme?: "light" | "dark" | "auto";
4
- /** 诊断功能开关(provider option enableDiagnostics;写入 localStorage 供 dsh-client 决定是否注册诊断视图) */
5
- diagnosticsEnabled?: boolean;
6
- }
7
- /**
8
- * 生成 PostMessage Bridge 脚本。
9
- * dsh 无正式"切换会话"URL 钩子,选中态持久化在 localStorage(CURRENT_SESSION),
10
- * 且 SPA 启动时会据此恢复选中——因此桥接采用"写入选中 + 刷新 iframe"的策略。
11
- * 若 dsh 后续暴露正式切会话接口,可替换以下 FOCUS_SESSION 分支。
12
- */
13
- export declare function generateBridgeScript(options?: BridgeScriptOptions): string;
@@ -1,195 +0,0 @@
1
- import { WIDGET_MSG } from "@aipanel/core";
2
- import { DSH_STORAGE_KEYS } from "./constants.js";
3
- function generateBridgeScript(options = {}) {
4
- const { theme = "auto", diagnosticsEnabled = false } = options;
5
- return `
6
- (function() {
7
- const CURRENT_SESSION_KEY = ${JSON.stringify(DSH_STORAGE_KEYS.CURRENT_SESSION)};
8
- const SELECTION_KEY = ${JSON.stringify(DSH_STORAGE_KEYS.SELECTION)};
9
- const DIAGNOSTICS_KEY = ${JSON.stringify(DSH_STORAGE_KEYS.DIAGNOSTICS_ENABLED)};
10
- const DIAGNOSTICS_ENABLED = ${JSON.stringify(diagnosticsEnabled)};
11
- const THEME = ${JSON.stringify(theme)};
12
-
13
- // \u8BCA\u65AD\u529F\u80FD\u5F00\u5173\uFF1A\u540C\u6B65\u5199\u5165\uFF08\u4E0D\u4F9D\u8D56 DOM\uFF09\uFF0C\u4FDD\u8BC1 dsh-client apply \u65F6\u5373\u53EF\u8BFB\u5230\u6807\u8BB0\u3002
14
- // bridge \u811A\u672C\u6CE8\u5165\u4E8E <head>\uFF0Cdsh-client \u63D2\u4EF6\u5728\u9875\u9762\u811A\u672C/React \u521D\u59CB\u5316\u540E\u624D apply\uFF0C
15
- // \u82E5\u7B49 DOMContentLoaded \u518D\u5199\u5219\u5B58\u5728\u65F6\u5E8F\u7ADE\u4E89\uFF0C\u89C6\u56FE\u53EF\u80FD\u6F0F\u6CE8\u518C\u3002
16
- try {
17
- if (DIAGNOSTICS_ENABLED) {
18
- localStorage.setItem(DIAGNOSTICS_KEY, "1");
19
- } else {
20
- localStorage.removeItem(DIAGNOSTICS_KEY);
21
- }
22
- } catch (e) { /* ignore */ }
23
-
24
- // \u6865\u63A5\u5C42\u901A\u77E5 dsh-client \u7684\u9009\u4E2D\u5143\u7D20\u63D2\u5165\u4E8B\u4EF6\uFF08\u4E0E opencode \u4E00\u81F4\uFF1A\u9009\u4E2D\u5373\u8FFD\u52A0\u5230\u5BF9\u8BDD\u6846\uFF09
25
- const INSERT_ELEMENT_EVENT = "aipanel:insert-element";
26
-
27
- // === \u8BB0\u5F55\u6700\u8FD1\u9009\u4E2D\u5143\u7D20 ===
28
- // \u4F9B dsh-client \u7684 @aipanel source \u4F5C\u4E3A\u5019\u9009\u8BFB\u53D6\uFF08\u53EF\u591A\u9009\uFF0C\u6700\u591A\u4FDD\u7559 20 \u4E2A\uFF09\uFF0C\u5E76\u6D3E\u53D1
29
- // aipanel:insert-element \u8BA9 dsh-client \u7ACB\u5373\u628A\u5143\u7D20\u8FFD\u52A0\u5230\u5F53\u524D\u4F1A\u8BDD\u8F93\u5165\u6846\u3002
30
- function pushSelection(element) {
31
- if (!element) return;
32
- try {
33
- var list = [];
34
- var raw = localStorage.getItem(SELECTION_KEY);
35
- if (raw) list = JSON.parse(raw) || [];
36
- if (!Array.isArray(list)) list = [];
37
- var exists = list.some(function (e) {
38
- return e && e.filePath === element.filePath && e.line === element.line;
39
- });
40
- if (!exists) list.unshift(element);
41
- if (list.length > 20) list.length = 20;
42
- localStorage.setItem(SELECTION_KEY, JSON.stringify(list));
43
- // \u901A\u77E5 dsh-client \u8FFD\u52A0\u5230\u5BF9\u8BDD\u6846\uFF08\u9009\u4E2D\u5373\u63D2\u5165\uFF0C\u65E0\u9700\u518D\u8F93\u5165 @\uFF09
44
- window.dispatchEvent(new CustomEvent(INSERT_ELEMENT_EVENT, {
45
- detail: { element: element }
46
- }));
47
- } catch (e) { /* ignore */ }
48
- }
49
-
50
- // === \u4E3B\u9898\u540C\u6B65\uFF08UI \u5448\u73B0\uFF1B\u6301\u4E45\u5316\u4EA4\u7531 dsh settings\u300Cui-theme.preference\u300D\uFF0C\u4E0D\u5728\u6B64\u5199 localStorage\uFF09===
51
- // dsh \u7684\u6697\u8272\u7531 body[data-ds-dark-theme] + colorScheme \u5448\u73B0\u3002
52
- // \u6CE8\u610F\uFF1Abridge \u53EF\u80FD\u88AB\u6CE8\u5165\u5230 <head>\uFF0C\u6B64\u65F6 document.body \u5C1A\u4E0D\u5B58\u5728\uFF0C\u987B\u5728 DOM ready \u540E\u518D\u6267\u884C\u3002
53
- // theme \u53C2\u6570\uFF1A"light" | "dark" | "auto"\uFF08auto \u4E0D\u5E72\u9884\uFF0C\u4EA4\u7ED9 dsh \u539F\u751F\u4E3B\u9898\u5904\u7406\uFF09\u3002
54
- function applyTheme(theme) {
55
- if (!document.body) return;
56
- if (theme === "dark") {
57
- document.body.setAttribute("data-ds-dark-theme", "");
58
- document.documentElement.style.colorScheme = "dark";
59
- } else if (theme === "light") {
60
- document.body.removeAttribute("data-ds-dark-theme");
61
- document.documentElement.style.colorScheme = "light";
62
- }
63
- }
64
-
65
- // === \u5E03\u5C40\u8986\u76D6 ===
66
- // \u9690\u85CF dsh \u7684\u4FA7\u8FB9\u680F\u5217\uFF0C\u907F\u514D\u4E0E AIPanel \u81EA\u5E26\u4F1A\u8BDD\u5217\u8868\u91CD\u590D\u3002
67
- // \u7A33\u5B9A\u951A\u70B9\uFF1AAppFrame \u6839\u7F51\u683C\u5728\u4FA7\u8FB9\u680F\u6298\u53E0\u65F6\u5E26 data-sidebar-collapsed\uFF08AIPanel \u7A84 iframe \u4E0B\u6052\u5B58\u5728\uFF09\uFF0C
68
- // \u4FA7\u8FB9\u680F\u5217\u662F\u6839\u7F51\u683C\u7684\u9996\u4E2A\u5B50\u5143\u7D20\u3002
69
- // \u6CE8\u610F\u4E0D\u80FD\u53EA display:none \u5143\u7D20\uFF1A\u663E\u5F0F gridTemplateColumns\uFF08\u5185\u8054\u6837\u5F0F\uFF09\u8F68\u9053\u4E0D\u4F1A\u56E0\u5B50\u9879
70
- // \u9690\u85CF\u800C\u6D88\u5931\uFF0C\u4F1A\u7559\u4E00\u6761\u7A7A\u767D\u5217\uFF0C\u987B\u628A\u9996\u5217\u8F68\u9053\u6539\u6210 auto\uFF08\u5B50\u9879\u9690\u85CF\u540E\u574D\u7F29\u4E3A 0\uFF09\u3002
71
- function applyLayoutOverrides() {
72
- try {
73
- if (document.getElementById("aipanel-layout-overrides")) return;
74
- var style = document.createElement("style");
75
- style.id = "aipanel-layout-overrides";
76
- style.textContent = [
77
- "[data-sidebar-collapsed] {",
78
- " grid-template-columns: auto !important;",
79
- "}",
80
- "[data-sidebar-collapsed] > :first-child {",
81
- " display: none !important;",
82
- "}",
83
- '[aria-label="\\u9009\\u62E9\\u5DE5\\u4F5C\\u533A"] {',
84
- " display: none !important;",
85
- "}",
86
- ].join("\\n");
87
- document.head.appendChild(style);
88
- } catch (e) { /* ignore */ }
89
- }
90
-
91
- // === \u9009\u62E9\u6A21\u5F0F\u72B6\u6001 ===
92
- // \u8BB0\u5F55\u5BBF\u4E3B\u662F\u5426\u5904\u4E8E"\u9009\u62E9\u5143\u7D20"\u6A21\u5F0F\uFF1A\u9009\u62E9\u6A21\u5F0F\u5F00\u542F\u65F6\uFF0Ciframe \u5185\u6355\u83B7\u7684 Esc \u5E94\u4F18\u5148
93
- // \u8F6C\u53D1\u7ED9\u5BBF\u4E3B\u9000\u51FA\u9009\u62E9\u6A21\u5F0F\uFF0C\u5E76\u541E\u6389\u672C\u9875\u81EA\u8EAB\u7684\u6309\u952E\u5904\u7406\uFF08\u5982\u505C\u6B62\u751F\u6210/\u5173\u95ED\u5F39\u5C42\uFF09\u3002
94
- let isInSelectMode = false;
95
-
96
- // === \u6D88\u606F\u76D1\u542C ===
97
- window.addEventListener("message", function(event) {
98
- if (!event.data) return;
99
-
100
- // \u6838\u5FC3\u5C42\u901A\u77E5\uFF1A\u5207\u6362\u4E3B\u9898\uFF08\u5DE5\u5177\u680F\u4E3B\u9898\u6309\u94AE/\u8DDF\u968F\u7CFB\u7EDF\u53D8\u5316\uFF09\u3002\u52A8\u6001\u5E94\u7528\uFF0C\u65E0\u9700\u91CD\u8F7D\u3002
101
- if (event.data.type === ${JSON.stringify(WIDGET_MSG.SET_THEME)}) {
102
- applyTheme(event.data.theme);
103
- }
104
-
105
- // \u6838\u5FC3\u5C42\u901A\u77E5\uFF1A\u805A\u7126\u6307\u5B9A\u4F1A\u8BDD\uFF08\u65E0 deepLink \u6A21\u5F0F\uFF09\u3002
106
- // dsh \u7684\u9009\u4E2D\u6001\u6301\u4E45\u5316\u4E3A JSON.stringify({ sessionId, subagentAddress? })\uFF0CSPA \u542F\u52A8\u65F6\u636E\u6B64\u6062\u590D\u3002
107
- if (event.data.type === ${JSON.stringify(WIDGET_MSG.FOCUS_SESSION)}) {
108
- const sessionId = event.data.sessionId;
109
- if (!sessionId) return;
110
- try {
111
- localStorage.setItem(CURRENT_SESSION_KEY, JSON.stringify({ sessionId }));
112
- } catch (e) {
113
- console.warn("dsh bridge: failed to persist session selection", e);
114
- }
115
- // dsh SPA \u4ECE\u6301\u4E45\u5316\u9009\u4E2D\u6062\u590D\uFF0C\u5237\u65B0\u4EE5\u5207\u6362\u5230\u76EE\u6807\u4F1A\u8BDD
116
- location.reload();
117
- }
118
-
119
- // \u6838\u5FC3\u5C42\u901A\u77E5\uFF1A\u9875\u9762\u9009\u4E2D\u5143\u7D20 \u2192 \u8BB0\u5F55\uFF0C\u4F9B @aipanel \u83DC\u5355\u7B5B\u9009\u540E\u4EE5 reference \u63D2\u5165
120
- if (event.data.type === ${JSON.stringify(WIDGET_MSG.INSERT_FILE_PART)}) {
121
- pushSelection(event.data.element);
122
- }
123
-
124
- // \u6838\u5FC3\u5C42\u901A\u77E5\uFF1A\u9009\u62E9\u5143\u7D20\u6A21\u5F0F\u53D8\u5316\uFF08\u66F4\u65B0\u672C\u5730\u72B6\u6001\uFF0C\u4F9B\u952E\u76D8\u8F6C\u53D1\u5224\u65AD\u662F\u5426\u541E\u6389\u672C\u9875 Esc \u5904\u7406\uFF09
125
- if (event.data.type === ${JSON.stringify(WIDGET_MSG.SELECT_MODE_CHANGE)}) {
126
- isInSelectMode = event.data.selectMode === true;
127
- }
128
- });
129
-
130
- // === \u952E\u76D8\u4E8B\u4EF6\u8F6C\u53D1\uFF08\u9000\u51FA/\u5207\u6362\u9009\u62E9\u6A21\u5F0F\uFF09 ===
131
- // \u4E0E opencode bridge \u4E00\u81F4\uFF1Aiframe \u5185\u7684 keydown \u4E0D\u4F1A\u5192\u6CE1\u5230\u5BBF\u4E3B\u6587\u6863\uFF08\u8DE8\u6587\u6863\u4E8B\u4EF6\u9694\u79BB\uFF09\uFF0C
132
- // \u56E0\u6B64\u5F53\u7126\u70B9\u5728\u804A\u5929 iframe \u5185\u65F6\uFF0C\u5BBF\u4E3B App \u6536\u4E0D\u5230 Esc / Ctrl+P\uFF0C\u5BFC\u81F4\uFF1A
133
- // - \u9009\u62E9\u5143\u7D20\u6A21\u5F0F\u5F00\u542F\u65F6\u6309 Esc \u65E0\u6CD5\u9000\u51FA\uFF08\u88AB dsh \u81EA\u8EAB\u6309\u952E\u5904\u7406\u541E\u6389\u6216\u76F4\u63A5\u4E22\u5931\uFF09\uFF1B
134
- // - \u5149\u6807\u5728\u804A\u5929\u8F93\u5165\u6846\u65F6\u65E0\u6CD5\u7528 Ctrl+P \u8FDB\u5165\u9009\u62E9\u5143\u7D20\u6A21\u5F0F\u3002
135
- // \u6B64\u5904\u7528\u6355\u83B7\u9636\u6BB5\u76D1\u542C Esc / Ctrl+P \u5E76\u8F6C\u53D1\u4E3A KEYDOWN \u6D88\u606F\u7ED9\u5BBF\u4E3B App\uFF08App.vue \u636E\u6B64
136
- // \u9000\u51FA/\u5207\u6362\u9009\u62E9\u6A21\u5F0F\uFF09\u3002\u9009\u62E9\u6A21\u5F0F\u5F00\u542F\u65F6\u4F18\u5148\u9000\u51FA\uFF1ApreventDefault + stopPropagation\uFF0C
137
- // \u907F\u514D dsh \u81EA\u8EAB\u5BF9 Esc \u7684\u5904\u7406\u62A2\u8D70\u6309\u952E\u3002
138
- window.addEventListener("keydown", function(event) {
139
- if (event.key === "Escape" || (event.ctrlKey && event.key.toLowerCase() === "p")) {
140
- if (isInSelectMode) {
141
- event.preventDefault();
142
- event.stopPropagation();
143
- }
144
- if (window.parent !== window) {
145
- window.parent.postMessage({
146
- type: ${JSON.stringify(WIDGET_MSG.KEYDOWN)},
147
- key: event.key,
148
- ctrlKey: event.ctrlKey,
149
- metaKey: event.metaKey,
150
- shiftKey: event.shiftKey,
151
- altKey: event.altKey
152
- }, "*");
153
- }
154
- }
155
- }, true);
156
-
157
- // === \u5C31\u7EEA\u901A\u77E5 ===
158
- // \u4E0D\u518D\u7528 MutationObserver \u6BCF\u5E27\u53D1 READY\uFF08\u90A3\u4F1A\u5728 dsh \u521A\u6E32\u67D3\u3001\u76EE\u6807\u4F1A\u8BDD\u5C1A\u672A\u6FC0\u6D3B\u65F6\u5C31
159
- // \u63D0\u524D\u653E\u884C loading\uFF09\u3002\u6539\u4E3A\u76D1\u542C dsh-client \u63D2\u4EF6\u5728"\u76EE\u6807\u4F1A\u8BDD\u6FC0\u6D3B\u4E14\u6E32\u67D3\u7A33\u5B9A"\u540E\u6D3E\u53D1\u7684
160
- // aipanel:session-ready \u4E8B\u4EF6\uFF0C\u6536\u5230\u540E\u4E0A\u62A5 SESSION_READY{sessionId}\u3002
161
- // \u53EA\u53D1 SESSION_READY \u800C\u4E0D\u53D1 READY\uFF1A\u5BA2\u6237\u7AEF\u5DF2\u80FD\u51ED sessionId \u5339\u914D\u5F53\u524D\u4F1A\u8BDD\u51B3\u5B9A\u4F55\u65F6
162
- // \u653E\u884C loading / \u8865\u53D1\u805A\u7126\uFF1B\u907F\u514D\u4E0E"FOCUS_SESSION \u2192 reload \u2192 \u518D\u5C31\u7EEA"\u6784\u6210\u5237\u65B0\u6B7B\u5FAA\u73AF\u3002
163
- const SESSION_READY_EVENT = "aipanel:session-ready";
164
-
165
- function sendSessionReady(sessionId) {
166
- if (window.parent !== window) {
167
- window.parent.postMessage({
168
- type: ${JSON.stringify(WIDGET_MSG.SESSION_READY)},
169
- sessionId
170
- }, "*");
171
- }
172
- }
173
-
174
- window.addEventListener(SESSION_READY_EVENT, function(e) {
175
- const sessionId = e && e.detail && e.detail.sessionId;
176
- if (!sessionId) return;
177
- sendSessionReady(sessionId);
178
- });
179
-
180
- // \u4E3B\u9898\u540C\u6B65/\u5E03\u5C40\u8986\u76D6\u4ECD\u987B\u5728\u6BCF\u6B21\u9875\u9762\u52A0\u8F7D\u65F6\u751F\u6548\uFF08\u4E0E\u5C31\u7EEA\u5224\u5B9A\u89E3\u8026\uFF0C\u4E0D\u53C2\u4E0E loading \u653E\u884C\uFF09
181
- function init() {
182
- applyTheme(THEME);
183
- applyLayoutOverrides();
184
- }
185
- if (document.readyState === "loading") {
186
- document.addEventListener("DOMContentLoaded", init);
187
- } else {
188
- init();
189
- }
190
- })();
191
- `;
192
- }
193
- export {
194
- generateBridgeScript
195
- };
@@ -1,218 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var bridge_script_exports = {};
19
- __export(bridge_script_exports, {
20
- generateBridgeScript: () => generateBridgeScript
21
- });
22
- module.exports = __toCommonJS(bridge_script_exports);
23
- var import_core = require("@aipanel/core");
24
- var import_constants = require("./constants.cjs");
25
- function generateBridgeScript(options = {}) {
26
- const { theme = "auto", diagnosticsEnabled = false } = options;
27
- return `
28
- (function() {
29
- const CURRENT_SESSION_KEY = ${JSON.stringify(import_constants.DSH_STORAGE_KEYS.CURRENT_SESSION)};
30
- const SELECTION_KEY = ${JSON.stringify(import_constants.DSH_STORAGE_KEYS.SELECTION)};
31
- const DIAGNOSTICS_KEY = ${JSON.stringify(import_constants.DSH_STORAGE_KEYS.DIAGNOSTICS_ENABLED)};
32
- const DIAGNOSTICS_ENABLED = ${JSON.stringify(diagnosticsEnabled)};
33
- const THEME = ${JSON.stringify(theme)};
34
-
35
- // \u8BCA\u65AD\u529F\u80FD\u5F00\u5173\uFF1A\u540C\u6B65\u5199\u5165\uFF08\u4E0D\u4F9D\u8D56 DOM\uFF09\uFF0C\u4FDD\u8BC1 dsh-client apply \u65F6\u5373\u53EF\u8BFB\u5230\u6807\u8BB0\u3002
36
- // bridge \u811A\u672C\u6CE8\u5165\u4E8E <head>\uFF0Cdsh-client \u63D2\u4EF6\u5728\u9875\u9762\u811A\u672C/React \u521D\u59CB\u5316\u540E\u624D apply\uFF0C
37
- // \u82E5\u7B49 DOMContentLoaded \u518D\u5199\u5219\u5B58\u5728\u65F6\u5E8F\u7ADE\u4E89\uFF0C\u89C6\u56FE\u53EF\u80FD\u6F0F\u6CE8\u518C\u3002
38
- try {
39
- if (DIAGNOSTICS_ENABLED) {
40
- localStorage.setItem(DIAGNOSTICS_KEY, "1");
41
- } else {
42
- localStorage.removeItem(DIAGNOSTICS_KEY);
43
- }
44
- } catch (e) { /* ignore */ }
45
-
46
- // \u6865\u63A5\u5C42\u901A\u77E5 dsh-client \u7684\u9009\u4E2D\u5143\u7D20\u63D2\u5165\u4E8B\u4EF6\uFF08\u4E0E opencode \u4E00\u81F4\uFF1A\u9009\u4E2D\u5373\u8FFD\u52A0\u5230\u5BF9\u8BDD\u6846\uFF09
47
- const INSERT_ELEMENT_EVENT = "aipanel:insert-element";
48
-
49
- // === \u8BB0\u5F55\u6700\u8FD1\u9009\u4E2D\u5143\u7D20 ===
50
- // \u4F9B dsh-client \u7684 @aipanel source \u4F5C\u4E3A\u5019\u9009\u8BFB\u53D6\uFF08\u53EF\u591A\u9009\uFF0C\u6700\u591A\u4FDD\u7559 20 \u4E2A\uFF09\uFF0C\u5E76\u6D3E\u53D1
51
- // aipanel:insert-element \u8BA9 dsh-client \u7ACB\u5373\u628A\u5143\u7D20\u8FFD\u52A0\u5230\u5F53\u524D\u4F1A\u8BDD\u8F93\u5165\u6846\u3002
52
- function pushSelection(element) {
53
- if (!element) return;
54
- try {
55
- var list = [];
56
- var raw = localStorage.getItem(SELECTION_KEY);
57
- if (raw) list = JSON.parse(raw) || [];
58
- if (!Array.isArray(list)) list = [];
59
- var exists = list.some(function (e) {
60
- return e && e.filePath === element.filePath && e.line === element.line;
61
- });
62
- if (!exists) list.unshift(element);
63
- if (list.length > 20) list.length = 20;
64
- localStorage.setItem(SELECTION_KEY, JSON.stringify(list));
65
- // \u901A\u77E5 dsh-client \u8FFD\u52A0\u5230\u5BF9\u8BDD\u6846\uFF08\u9009\u4E2D\u5373\u63D2\u5165\uFF0C\u65E0\u9700\u518D\u8F93\u5165 @\uFF09
66
- window.dispatchEvent(new CustomEvent(INSERT_ELEMENT_EVENT, {
67
- detail: { element: element }
68
- }));
69
- } catch (e) { /* ignore */ }
70
- }
71
-
72
- // === \u4E3B\u9898\u540C\u6B65\uFF08UI \u5448\u73B0\uFF1B\u6301\u4E45\u5316\u4EA4\u7531 dsh settings\u300Cui-theme.preference\u300D\uFF0C\u4E0D\u5728\u6B64\u5199 localStorage\uFF09===
73
- // dsh \u7684\u6697\u8272\u7531 body[data-ds-dark-theme] + colorScheme \u5448\u73B0\u3002
74
- // \u6CE8\u610F\uFF1Abridge \u53EF\u80FD\u88AB\u6CE8\u5165\u5230 <head>\uFF0C\u6B64\u65F6 document.body \u5C1A\u4E0D\u5B58\u5728\uFF0C\u987B\u5728 DOM ready \u540E\u518D\u6267\u884C\u3002
75
- // theme \u53C2\u6570\uFF1A"light" | "dark" | "auto"\uFF08auto \u4E0D\u5E72\u9884\uFF0C\u4EA4\u7ED9 dsh \u539F\u751F\u4E3B\u9898\u5904\u7406\uFF09\u3002
76
- function applyTheme(theme) {
77
- if (!document.body) return;
78
- if (theme === "dark") {
79
- document.body.setAttribute("data-ds-dark-theme", "");
80
- document.documentElement.style.colorScheme = "dark";
81
- } else if (theme === "light") {
82
- document.body.removeAttribute("data-ds-dark-theme");
83
- document.documentElement.style.colorScheme = "light";
84
- }
85
- }
86
-
87
- // === \u5E03\u5C40\u8986\u76D6 ===
88
- // \u9690\u85CF dsh \u7684\u4FA7\u8FB9\u680F\u5217\uFF0C\u907F\u514D\u4E0E AIPanel \u81EA\u5E26\u4F1A\u8BDD\u5217\u8868\u91CD\u590D\u3002
89
- // \u7A33\u5B9A\u951A\u70B9\uFF1AAppFrame \u6839\u7F51\u683C\u5728\u4FA7\u8FB9\u680F\u6298\u53E0\u65F6\u5E26 data-sidebar-collapsed\uFF08AIPanel \u7A84 iframe \u4E0B\u6052\u5B58\u5728\uFF09\uFF0C
90
- // \u4FA7\u8FB9\u680F\u5217\u662F\u6839\u7F51\u683C\u7684\u9996\u4E2A\u5B50\u5143\u7D20\u3002
91
- // \u6CE8\u610F\u4E0D\u80FD\u53EA display:none \u5143\u7D20\uFF1A\u663E\u5F0F gridTemplateColumns\uFF08\u5185\u8054\u6837\u5F0F\uFF09\u8F68\u9053\u4E0D\u4F1A\u56E0\u5B50\u9879
92
- // \u9690\u85CF\u800C\u6D88\u5931\uFF0C\u4F1A\u7559\u4E00\u6761\u7A7A\u767D\u5217\uFF0C\u987B\u628A\u9996\u5217\u8F68\u9053\u6539\u6210 auto\uFF08\u5B50\u9879\u9690\u85CF\u540E\u574D\u7F29\u4E3A 0\uFF09\u3002
93
- function applyLayoutOverrides() {
94
- try {
95
- if (document.getElementById("aipanel-layout-overrides")) return;
96
- var style = document.createElement("style");
97
- style.id = "aipanel-layout-overrides";
98
- style.textContent = [
99
- "[data-sidebar-collapsed] {",
100
- " grid-template-columns: auto !important;",
101
- "}",
102
- "[data-sidebar-collapsed] > :first-child {",
103
- " display: none !important;",
104
- "}",
105
- '[aria-label="\\u9009\\u62E9\\u5DE5\\u4F5C\\u533A"] {',
106
- " display: none !important;",
107
- "}",
108
- ].join("\\n");
109
- document.head.appendChild(style);
110
- } catch (e) { /* ignore */ }
111
- }
112
-
113
- // === \u9009\u62E9\u6A21\u5F0F\u72B6\u6001 ===
114
- // \u8BB0\u5F55\u5BBF\u4E3B\u662F\u5426\u5904\u4E8E"\u9009\u62E9\u5143\u7D20"\u6A21\u5F0F\uFF1A\u9009\u62E9\u6A21\u5F0F\u5F00\u542F\u65F6\uFF0Ciframe \u5185\u6355\u83B7\u7684 Esc \u5E94\u4F18\u5148
115
- // \u8F6C\u53D1\u7ED9\u5BBF\u4E3B\u9000\u51FA\u9009\u62E9\u6A21\u5F0F\uFF0C\u5E76\u541E\u6389\u672C\u9875\u81EA\u8EAB\u7684\u6309\u952E\u5904\u7406\uFF08\u5982\u505C\u6B62\u751F\u6210/\u5173\u95ED\u5F39\u5C42\uFF09\u3002
116
- let isInSelectMode = false;
117
-
118
- // === \u6D88\u606F\u76D1\u542C ===
119
- window.addEventListener("message", function(event) {
120
- if (!event.data) return;
121
-
122
- // \u6838\u5FC3\u5C42\u901A\u77E5\uFF1A\u5207\u6362\u4E3B\u9898\uFF08\u5DE5\u5177\u680F\u4E3B\u9898\u6309\u94AE/\u8DDF\u968F\u7CFB\u7EDF\u53D8\u5316\uFF09\u3002\u52A8\u6001\u5E94\u7528\uFF0C\u65E0\u9700\u91CD\u8F7D\u3002
123
- if (event.data.type === ${JSON.stringify(import_core.WIDGET_MSG.SET_THEME)}) {
124
- applyTheme(event.data.theme);
125
- }
126
-
127
- // \u6838\u5FC3\u5C42\u901A\u77E5\uFF1A\u805A\u7126\u6307\u5B9A\u4F1A\u8BDD\uFF08\u65E0 deepLink \u6A21\u5F0F\uFF09\u3002
128
- // dsh \u7684\u9009\u4E2D\u6001\u6301\u4E45\u5316\u4E3A JSON.stringify({ sessionId, subagentAddress? })\uFF0CSPA \u542F\u52A8\u65F6\u636E\u6B64\u6062\u590D\u3002
129
- if (event.data.type === ${JSON.stringify(import_core.WIDGET_MSG.FOCUS_SESSION)}) {
130
- const sessionId = event.data.sessionId;
131
- if (!sessionId) return;
132
- try {
133
- localStorage.setItem(CURRENT_SESSION_KEY, JSON.stringify({ sessionId }));
134
- } catch (e) {
135
- console.warn("dsh bridge: failed to persist session selection", e);
136
- }
137
- // dsh SPA \u4ECE\u6301\u4E45\u5316\u9009\u4E2D\u6062\u590D\uFF0C\u5237\u65B0\u4EE5\u5207\u6362\u5230\u76EE\u6807\u4F1A\u8BDD
138
- location.reload();
139
- }
140
-
141
- // \u6838\u5FC3\u5C42\u901A\u77E5\uFF1A\u9875\u9762\u9009\u4E2D\u5143\u7D20 \u2192 \u8BB0\u5F55\uFF0C\u4F9B @aipanel \u83DC\u5355\u7B5B\u9009\u540E\u4EE5 reference \u63D2\u5165
142
- if (event.data.type === ${JSON.stringify(import_core.WIDGET_MSG.INSERT_FILE_PART)}) {
143
- pushSelection(event.data.element);
144
- }
145
-
146
- // \u6838\u5FC3\u5C42\u901A\u77E5\uFF1A\u9009\u62E9\u5143\u7D20\u6A21\u5F0F\u53D8\u5316\uFF08\u66F4\u65B0\u672C\u5730\u72B6\u6001\uFF0C\u4F9B\u952E\u76D8\u8F6C\u53D1\u5224\u65AD\u662F\u5426\u541E\u6389\u672C\u9875 Esc \u5904\u7406\uFF09
147
- if (event.data.type === ${JSON.stringify(import_core.WIDGET_MSG.SELECT_MODE_CHANGE)}) {
148
- isInSelectMode = event.data.selectMode === true;
149
- }
150
- });
151
-
152
- // === \u952E\u76D8\u4E8B\u4EF6\u8F6C\u53D1\uFF08\u9000\u51FA/\u5207\u6362\u9009\u62E9\u6A21\u5F0F\uFF09 ===
153
- // \u4E0E opencode bridge \u4E00\u81F4\uFF1Aiframe \u5185\u7684 keydown \u4E0D\u4F1A\u5192\u6CE1\u5230\u5BBF\u4E3B\u6587\u6863\uFF08\u8DE8\u6587\u6863\u4E8B\u4EF6\u9694\u79BB\uFF09\uFF0C
154
- // \u56E0\u6B64\u5F53\u7126\u70B9\u5728\u804A\u5929 iframe \u5185\u65F6\uFF0C\u5BBF\u4E3B App \u6536\u4E0D\u5230 Esc / Ctrl+P\uFF0C\u5BFC\u81F4\uFF1A
155
- // - \u9009\u62E9\u5143\u7D20\u6A21\u5F0F\u5F00\u542F\u65F6\u6309 Esc \u65E0\u6CD5\u9000\u51FA\uFF08\u88AB dsh \u81EA\u8EAB\u6309\u952E\u5904\u7406\u541E\u6389\u6216\u76F4\u63A5\u4E22\u5931\uFF09\uFF1B
156
- // - \u5149\u6807\u5728\u804A\u5929\u8F93\u5165\u6846\u65F6\u65E0\u6CD5\u7528 Ctrl+P \u8FDB\u5165\u9009\u62E9\u5143\u7D20\u6A21\u5F0F\u3002
157
- // \u6B64\u5904\u7528\u6355\u83B7\u9636\u6BB5\u76D1\u542C Esc / Ctrl+P \u5E76\u8F6C\u53D1\u4E3A KEYDOWN \u6D88\u606F\u7ED9\u5BBF\u4E3B App\uFF08App.vue \u636E\u6B64
158
- // \u9000\u51FA/\u5207\u6362\u9009\u62E9\u6A21\u5F0F\uFF09\u3002\u9009\u62E9\u6A21\u5F0F\u5F00\u542F\u65F6\u4F18\u5148\u9000\u51FA\uFF1ApreventDefault + stopPropagation\uFF0C
159
- // \u907F\u514D dsh \u81EA\u8EAB\u5BF9 Esc \u7684\u5904\u7406\u62A2\u8D70\u6309\u952E\u3002
160
- window.addEventListener("keydown", function(event) {
161
- if (event.key === "Escape" || (event.ctrlKey && event.key.toLowerCase() === "p")) {
162
- if (isInSelectMode) {
163
- event.preventDefault();
164
- event.stopPropagation();
165
- }
166
- if (window.parent !== window) {
167
- window.parent.postMessage({
168
- type: ${JSON.stringify(import_core.WIDGET_MSG.KEYDOWN)},
169
- key: event.key,
170
- ctrlKey: event.ctrlKey,
171
- metaKey: event.metaKey,
172
- shiftKey: event.shiftKey,
173
- altKey: event.altKey
174
- }, "*");
175
- }
176
- }
177
- }, true);
178
-
179
- // === \u5C31\u7EEA\u901A\u77E5 ===
180
- // \u4E0D\u518D\u7528 MutationObserver \u6BCF\u5E27\u53D1 READY\uFF08\u90A3\u4F1A\u5728 dsh \u521A\u6E32\u67D3\u3001\u76EE\u6807\u4F1A\u8BDD\u5C1A\u672A\u6FC0\u6D3B\u65F6\u5C31
181
- // \u63D0\u524D\u653E\u884C loading\uFF09\u3002\u6539\u4E3A\u76D1\u542C dsh-client \u63D2\u4EF6\u5728"\u76EE\u6807\u4F1A\u8BDD\u6FC0\u6D3B\u4E14\u6E32\u67D3\u7A33\u5B9A"\u540E\u6D3E\u53D1\u7684
182
- // aipanel:session-ready \u4E8B\u4EF6\uFF0C\u6536\u5230\u540E\u4E0A\u62A5 SESSION_READY{sessionId}\u3002
183
- // \u53EA\u53D1 SESSION_READY \u800C\u4E0D\u53D1 READY\uFF1A\u5BA2\u6237\u7AEF\u5DF2\u80FD\u51ED sessionId \u5339\u914D\u5F53\u524D\u4F1A\u8BDD\u51B3\u5B9A\u4F55\u65F6
184
- // \u653E\u884C loading / \u8865\u53D1\u805A\u7126\uFF1B\u907F\u514D\u4E0E"FOCUS_SESSION \u2192 reload \u2192 \u518D\u5C31\u7EEA"\u6784\u6210\u5237\u65B0\u6B7B\u5FAA\u73AF\u3002
185
- const SESSION_READY_EVENT = "aipanel:session-ready";
186
-
187
- function sendSessionReady(sessionId) {
188
- if (window.parent !== window) {
189
- window.parent.postMessage({
190
- type: ${JSON.stringify(import_core.WIDGET_MSG.SESSION_READY)},
191
- sessionId
192
- }, "*");
193
- }
194
- }
195
-
196
- window.addEventListener(SESSION_READY_EVENT, function(e) {
197
- const sessionId = e && e.detail && e.detail.sessionId;
198
- if (!sessionId) return;
199
- sendSessionReady(sessionId);
200
- });
201
-
202
- // \u4E3B\u9898\u540C\u6B65/\u5E03\u5C40\u8986\u76D6\u4ECD\u987B\u5728\u6BCF\u6B21\u9875\u9762\u52A0\u8F7D\u65F6\u751F\u6548\uFF08\u4E0E\u5C31\u7EEA\u5224\u5B9A\u89E3\u8026\uFF0C\u4E0D\u53C2\u4E0E loading \u653E\u884C\uFF09
203
- function init() {
204
- applyTheme(THEME);
205
- applyLayoutOverrides();
206
- }
207
- if (document.readyState === "loading") {
208
- document.addEventListener("DOMContentLoaded", init);
209
- } else {
210
- init();
211
- }
212
- })();
213
- `;
214
- }
215
- // Annotate the CommonJS export names for ESM import in node:
216
- 0 && (module.exports = {
217
- generateBridgeScript
218
- });
@@ -1,13 +0,0 @@
1
- export interface BridgeScriptOptions {
2
- /** 主题模式 */
3
- theme?: "light" | "dark" | "auto";
4
- /** 诊断功能开关(provider option enableDiagnostics;写入 localStorage 供 dsh-client 决定是否注册诊断视图) */
5
- diagnosticsEnabled?: boolean;
6
- }
7
- /**
8
- * 生成 PostMessage Bridge 脚本。
9
- * dsh 无正式"切换会话"URL 钩子,选中态持久化在 localStorage(CURRENT_SESSION),
10
- * 且 SPA 启动时会据此恢复选中——因此桥接采用"写入选中 + 刷新 iframe"的策略。
11
- * 若 dsh 后续暴露正式切会话接口,可替换以下 FOCUS_SESSION 分支。
12
- */
13
- export declare function generateBridgeScript(options?: BridgeScriptOptions): string;