@takboo/dsh-coopanion 0.4.13 → 0.4.15
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/README.md +4 -4
- package/desktop/display-controller.cjs +8 -4
- package/desktop/main.cjs +8 -2
- package/desktop/preload.cjs +2 -0
- package/dist/bridge.js +90 -8
- package/dist/bridge.js.map +4 -4
- package/dist/build-info.json +2 -2
- package/dist/client.js +1 -1
- package/dist/figure-server.cjs +1 -1
- package/dist/index.js +91 -9
- package/dist/index.js.map +4 -4
- package/docs/desktop-recovery-contract.md +4 -0
- package/docs/development.md +20 -0
- package/docs/multi-display-contract.md +6 -0
- package/docs/release-notes.md +25 -0
- package/docs/releasing.md +2 -2
- package/docs/session-chat-contract.md +1 -1
- package/docs/usage.md +22 -7
- package/npm-shrinkwrap.json +21 -21
- package/package.json +20 -20
- package/scripts/observe-companion.mjs +1 -1
- package/src/bridge.ts +19 -4
- package/src/client/index.ts +1 -1
- package/src/controls.ts +1 -1
- package/src/electron-runtime.ts +50 -0
- package/src/figure-server.ts +3 -1
- package/tests/companionship-ui.mjs +38 -4
- package/tests/display-geometry.test.js +37 -1
- package/tests/electron-startup.test.ts +93 -0
- package/tests/figures.test.ts +45 -2
- package/tests/fixtures/late-display-quit.cjs +8 -0
- package/tests/fixtures/lifecycle-shutdown-trace.cjs +37 -0
- package/tests/helpers/native-pointer.mjs +33 -7
- package/tests/helpers/windows-taskbar.ps1 +22 -0
- package/tests/inbox-ui.mjs +1 -0
- package/tests/install.mjs +15 -5
- package/tests/lifecycle-startup-native.mjs +44 -9
- package/tests/locale-client.mjs +23 -0
- package/tests/multi-display-ui.mjs +42 -0
- package/tests/preload-geometry.test.js +23 -0
- package/tests/session-replies-ui.mjs +22 -0
- package/tests/windows-geometry-native.mjs +78 -0
- package/tests/windows-pointer-native.mjs +43 -0
- package/web/pet.js +23 -5
package/README.md
CHANGED
|
@@ -51,14 +51,14 @@
|
|
|
51
51
|
|
|
52
52
|
## 开始一起工作
|
|
53
53
|
|
|
54
|
-
需要 **DeepSeek Harness Desktop 0.2.0-rc.2、0.2.1-alpha.1、0.2.1-rc.1 或 0.2.1-rc.
|
|
54
|
+
需要 **DeepSeek Harness Desktop 0.2.0-rc.2、0.2.1-alpha.1、0.2.1-rc.1、0.2.1-rc.2 或 0.2.1-rc.3**。这是 Harness 插件,聊天使用你在 Harness 中配置的模型,无需另填 API Key。
|
|
55
55
|
|
|
56
56
|
### 在 Harness 中从 npm 安装(推荐)
|
|
57
57
|
|
|
58
58
|
打开侧边栏 **插件 → 添加插件**,在「包名或地址」中填入:
|
|
59
59
|
|
|
60
60
|
```text
|
|
61
|
-
@takboo/dsh-coopanion@0.4.
|
|
61
|
+
@takboo/dsh-coopanion@0.4.15
|
|
62
62
|
```
|
|
63
63
|
|
|
64
64
|
点击安装,完成后启用 `dsh-coopanion`,再完全退出并重新打开 Harness。
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
使用 **Desktop 自带的 `dsh` 命令**。先启动 Desktop 一次完成初始化,完全退出应用后执行:
|
|
71
71
|
|
|
72
72
|
```bash
|
|
73
|
-
dsh plugin --profile desktop add @takboo/dsh-coopanion@0.4.
|
|
73
|
+
dsh plugin --profile desktop add @takboo/dsh-coopanion@0.4.15
|
|
74
74
|
```
|
|
75
75
|
|
|
76
76
|
完成后重新打开 Desktop。其他 profile 的安装方法见[使用指南](docs/usage.md#通过-dsh-命令行安装)。
|
|
@@ -79,7 +79,7 @@ dsh plugin --profile desktop add @takboo/dsh-coopanion@0.4.13
|
|
|
79
79
|
|
|
80
80
|
[下载最新插件包 `dsh-coopanion.tgz`](https://github.com/takboo/dsh-coopanion/releases/latest/download/dsh-coopanion.tgz),在 **插件 → 添加插件** 中填入压缩包的绝对路径,安装并启用,然后重启 Harness。
|
|
81
81
|
|
|
82
|
-
安装后在 **Settings → 桌宠**
|
|
82
|
+
安装后在 **Settings → 桌宠** 查看运行状态。首次启动会在后台下载并校验 Electron 运行时,期间桌宠显示“正在启动”,Harness 可继续使用;网络受限时可按[运行时准备说明](docs/usage.md#electron-运行时准备)配置镜像或提前安装。
|
|
83
83
|
|
|
84
84
|
| 操作 | 会发生什么 |
|
|
85
85
|
|---|---|
|
|
@@ -3,8 +3,12 @@ const { displayTarget } = require('../web/display-geometry.js');
|
|
|
3
3
|
// The injected screen/window are also used by the deterministic CI layout tests.
|
|
4
4
|
module.exports.createDisplayController = ({ screen, win, send, changed = () => {} }) => {
|
|
5
5
|
let currentId = screen.getPrimaryDisplay().id, previous, state, lastKey, revision = 0;
|
|
6
|
-
const
|
|
6
|
+
const alive = () => !win.isDestroyed();
|
|
7
|
+
const emit = () => { if (state && alive()) send({ type: 'display-changed', ...state }); };
|
|
8
|
+
// A replay must sample again: getContentBounds can settle after setBounds.
|
|
9
|
+
const publish = () => { if (!alive()) return; const before = revision; refresh(); if (before === revision) emit(); };
|
|
7
10
|
function refresh({ point, displayId } = {}) {
|
|
11
|
+
if (!alive()) return;
|
|
8
12
|
const target = displayTarget(screen.getAllDisplays(), { currentId, previous, point, displayId });
|
|
9
13
|
if (!target) return;
|
|
10
14
|
currentId = target.id; previous = { ...target.workArea };
|
|
@@ -13,9 +17,9 @@ module.exports.createDisplayController = ({ screen, win, send, changed = () => {
|
|
|
13
17
|
const next = { displayId: target.id, workArea: { ...target.workArea }, contentBounds: win.getContentBounds(), scaleFactor: target.scaleFactor };
|
|
14
18
|
const key = JSON.stringify(next);
|
|
15
19
|
if (key !== lastKey) {
|
|
16
|
-
lastKey = key; state = { ...next, revision: ++revision };
|
|
20
|
+
lastKey = key; state = { ...next, revision: ++revision }; emit(); changed();
|
|
17
21
|
}
|
|
18
22
|
}
|
|
19
|
-
return { refresh, publish, get state() { return state; }, moveToCursor() { const before = revision; refresh({ point: screen.getCursorScreenPoint() }); if (before === revision) publish(); },
|
|
20
|
-
cursor() { const p = screen.getCursorScreenPoint(), b = state?.contentBounds; return b ? { type: 'cursor', x: p.x - b.x, y: p.y - b.y, revision: state.revision } : undefined; } };
|
|
23
|
+
return { refresh, publish, get state() { return state; }, moveToCursor() { if (!alive()) return; const before = revision; refresh({ point: screen.getCursorScreenPoint() }); if (before === revision) publish(); },
|
|
24
|
+
cursor() { if (!alive()) return; const p = screen.getCursorScreenPoint(), b = state?.contentBounds; return b ? { type: 'cursor', x: p.x - b.x, y: p.y - b.y, revision: state.revision } : undefined; } };
|
|
21
25
|
};
|
package/desktop/main.cjs
CHANGED
|
@@ -227,8 +227,11 @@ app.whenReady().then(async () => {
|
|
|
227
227
|
displays = createDisplayController({ screen, win, send: forward, changed: syncTray });
|
|
228
228
|
displays.refresh();
|
|
229
229
|
if (displayTest) require('./test-display-probe.cjs').installDisplayProbe({ ipcMain, screen, win, displays });
|
|
230
|
-
for (const event of ['resize', 'move']) win.on(event, () => setImmediate(() => { if (!win.isDestroyed()) displays.refresh(); }));
|
|
230
|
+
for (const event of ['resize', 'resized', 'move']) win.on(event, () => setImmediate(() => { if (!win.isDestroyed()) displays.refresh(); }));
|
|
231
231
|
win.webContents.on('did-finish-load', () => { if (lastFrame) forward(lastFrame); displays.publish(); });
|
|
232
|
+
ipcMain.on('pet:geometry-request', event => {
|
|
233
|
+
if (event.sender === win.webContents && event.senderFrame === win.webContents.mainFrame) displays.publish();
|
|
234
|
+
});
|
|
232
235
|
ipcMain.on('pet:diagnostics-response', (event, message) => {
|
|
233
236
|
if (event.sender !== win.webContents || event.senderFrame !== win.webContents.mainFrame || options?.diagnostics !== true || !diagnosticRead || message?.requestId !== diagnosticRead.requestId) return;
|
|
234
237
|
const value = diagnosticRenderer.safeParse(message.value);
|
|
@@ -266,7 +269,10 @@ app.whenReady().then(async () => {
|
|
|
266
269
|
const icon = nativeImage.createFromPath(join(__dirname, 'icon.png')).resize({ height: 24 });
|
|
267
270
|
tray = new Tray(icon); syncTray();
|
|
268
271
|
tray.on('click', show);
|
|
269
|
-
|
|
272
|
+
const displayEvents = ['display-added', 'display-removed', 'display-metrics-changed'];
|
|
273
|
+
const displayChanged = () => { if (!win.isDestroyed()) { displays.refresh(); lastTrayKey = undefined; syncTray(); } };
|
|
274
|
+
for (const event of displayEvents) screen.on(event, displayChanged);
|
|
275
|
+
win.once('closed', () => { for (const event of displayEvents) screen.off(event, displayChanged); });
|
|
270
276
|
process.send?.({ type: 'ready' });
|
|
271
277
|
}).catch(error => {
|
|
272
278
|
console.error(error);
|
package/desktop/preload.cjs
CHANGED
|
@@ -10,8 +10,10 @@ contextBridge.exposeInMainWorld('dshPetBridge', {
|
|
|
10
10
|
subscribe(callback) {
|
|
11
11
|
const listener = (_event, message) => callback(message);
|
|
12
12
|
ipcRenderer.on('pet:update', listener);
|
|
13
|
+
ipcRenderer.send('pet:geometry-request');
|
|
13
14
|
return () => ipcRenderer.removeListener('pet:update', listener);
|
|
14
15
|
},
|
|
16
|
+
requestGeometry() { ipcRenderer.send('pet:geometry-request'); },
|
|
15
17
|
// Chat carries its immutable target and client request identity unchanged.
|
|
16
18
|
action(value) { ipcRenderer.send('pet:action', value); },
|
|
17
19
|
hit(active) { ipcRenderer.send('pet:hit', active); },
|
package/dist/bridge.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// src/bridge.ts
|
|
2
|
-
import { spawn } from "node:child_process";
|
|
3
|
-
import { createRequire } from "node:module";
|
|
2
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
4
3
|
import { fileURLToPath } from "node:url";
|
|
5
4
|
import { EventEmitter } from "node:events";
|
|
6
5
|
|
|
@@ -13,6 +12,71 @@ var NativeStartError = class extends Error {
|
|
|
13
12
|
}
|
|
14
13
|
};
|
|
15
14
|
|
|
15
|
+
// src/electron-runtime.ts
|
|
16
|
+
import { spawn } from "node:child_process";
|
|
17
|
+
import { access, readFile } from "node:fs/promises";
|
|
18
|
+
import { createRequire } from "node:module";
|
|
19
|
+
import { dirname, join } from "node:path";
|
|
20
|
+
async function electronExecutable(signal) {
|
|
21
|
+
const directory = dirname(createRequire(import.meta.url).resolve("electron"));
|
|
22
|
+
async function installed() {
|
|
23
|
+
let relative;
|
|
24
|
+
try {
|
|
25
|
+
relative = await readFile(join(directory, "path.txt"), "utf8");
|
|
26
|
+
} catch (error) {
|
|
27
|
+
if (error.code !== "ENOENT") throw error;
|
|
28
|
+
relative = "";
|
|
29
|
+
}
|
|
30
|
+
if (process.env.ELECTRON_OVERRIDE_DIST_PATH) return join(process.env.ELECTRON_OVERRIDE_DIST_PATH, relative || "electron");
|
|
31
|
+
if (!relative) return;
|
|
32
|
+
const executable2 = join(directory, "dist", relative);
|
|
33
|
+
try {
|
|
34
|
+
await access(executable2);
|
|
35
|
+
return executable2;
|
|
36
|
+
} catch (error) {
|
|
37
|
+
if (error.code !== "ENOENT") throw error;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (signal.aborted) throw new Error("\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88");
|
|
41
|
+
const existing = await installed();
|
|
42
|
+
if (existing) return existing;
|
|
43
|
+
await new Promise((resolve, reject) => {
|
|
44
|
+
if (signal.aborted) {
|
|
45
|
+
reject(new Error("\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88"));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const child = spawn(process.execPath, [join(directory, "install.js")], {
|
|
49
|
+
env: { ...process.env, ELECTRON_RUN_AS_NODE: "1" },
|
|
50
|
+
stdio: "ignore",
|
|
51
|
+
windowsHide: true
|
|
52
|
+
});
|
|
53
|
+
let failure, killTimer;
|
|
54
|
+
const stop = (error) => {
|
|
55
|
+
if (failure) return;
|
|
56
|
+
failure = error;
|
|
57
|
+
child.kill();
|
|
58
|
+
killTimer = setTimeout(() => child.kill("SIGKILL"), 1e3);
|
|
59
|
+
};
|
|
60
|
+
const aborted = () => stop(new Error("\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88"));
|
|
61
|
+
const timer = setTimeout(() => stop(new NativeStartError("Electron \u8FD0\u884C\u65F6\u51C6\u5907\u8D85\u65F6\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u6216\u6309\u4F7F\u7528\u6307\u5357\u9884\u5148\u5B89\u88C5\u8FD0\u884C\u65F6\u3002", false)), 24e4);
|
|
62
|
+
signal.addEventListener("abort", aborted, { once: true });
|
|
63
|
+
const finish = (error) => {
|
|
64
|
+
clearTimeout(timer);
|
|
65
|
+
clearTimeout(killTimer);
|
|
66
|
+
signal.removeEventListener("abort", aborted);
|
|
67
|
+
if (failure || error) reject(failure ?? error);
|
|
68
|
+
else resolve();
|
|
69
|
+
};
|
|
70
|
+
child.once("error", (error) => finish(new NativeStartError(error.message.slice(0, 600), false)));
|
|
71
|
+
child.once("exit", (code) => finish(code === 0 ? void 0 : new NativeStartError(`Electron \u8FD0\u884C\u65F6\u51C6\u5907\u5931\u8D25 (${code})\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u6216\u6309\u4F7F\u7528\u6307\u5357\u9884\u5148\u5B89\u88C5\u8FD0\u884C\u65F6\u3002`, false)));
|
|
72
|
+
if (signal.aborted) aborted();
|
|
73
|
+
});
|
|
74
|
+
if (signal.aborted) throw new Error("\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88");
|
|
75
|
+
const executable = await installed();
|
|
76
|
+
if (!executable) throw new NativeStartError("Electron \u5B89\u88C5\u672A\u751F\u6210\u53EF\u7528\u8FD0\u884C\u65F6\uFF0C\u8BF7\u6309\u4F7F\u7528\u6307\u5357\u91CD\u65B0\u51C6\u5907\u3002", false);
|
|
77
|
+
return executable;
|
|
78
|
+
}
|
|
79
|
+
|
|
16
80
|
// src/bridge.ts
|
|
17
81
|
var ElectronBridge = class extends EventEmitter {
|
|
18
82
|
child;
|
|
@@ -20,6 +84,8 @@ var ElectronBridge = class extends EventEmitter {
|
|
|
20
84
|
latestOptions;
|
|
21
85
|
resultKey;
|
|
22
86
|
closing = false;
|
|
87
|
+
preparing;
|
|
88
|
+
preparation;
|
|
23
89
|
generation = 0;
|
|
24
90
|
visibilityRevision = 0;
|
|
25
91
|
nativeVisible = false;
|
|
@@ -28,7 +94,7 @@ var ElectronBridge = class extends EventEmitter {
|
|
|
28
94
|
systemAsleep = false;
|
|
29
95
|
lastNotificationState;
|
|
30
96
|
async start(options, lifetime) {
|
|
31
|
-
if (this.child) throw new NativeStartError("Desktop pet is already running", false);
|
|
97
|
+
if (this.child || this.preparing) throw new NativeStartError("Desktop pet is already running or starting", false);
|
|
32
98
|
if (lifetime?.signal.aborted) throw new Error("\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88");
|
|
33
99
|
this.latestOptions = { ...options };
|
|
34
100
|
this.closing = false;
|
|
@@ -37,16 +103,30 @@ var ElectronBridge = class extends EventEmitter {
|
|
|
37
103
|
this.nativeVisible = false;
|
|
38
104
|
if (process.platform === "linux" && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY) throw new NativeStartError("\u684C\u5BA0\u9700\u8981\u684C\u9762\u663E\u793A\u73AF\u5883\u3002", false);
|
|
39
105
|
let executable;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
106
|
+
if (options.electronPath !== void 0) executable = options.electronPath;
|
|
107
|
+
else {
|
|
108
|
+
const preparing = new AbortController();
|
|
109
|
+
this.preparing = preparing;
|
|
110
|
+
const abort = () => preparing.abort();
|
|
111
|
+
lifetime?.signal.addEventListener("abort", abort, { once: true });
|
|
112
|
+
if (lifetime?.signal.aborted) abort();
|
|
113
|
+
try {
|
|
114
|
+
this.preparation = electronExecutable(preparing.signal);
|
|
115
|
+
executable = await this.preparation;
|
|
116
|
+
if (preparing.signal.aborted || this.closing) throw new Error("\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88");
|
|
117
|
+
} catch (error) {
|
|
118
|
+
throw error instanceof NativeStartError ? error : new NativeStartError(String(error).slice(0, 600), false);
|
|
119
|
+
} finally {
|
|
120
|
+
lifetime?.signal.removeEventListener("abort", abort);
|
|
121
|
+
this.preparing = void 0;
|
|
122
|
+
this.preparation = void 0;
|
|
123
|
+
}
|
|
44
124
|
}
|
|
45
125
|
const env = { ...process.env, DSH_PET_GENERATION: String(this.generation), DSH_PET_VISIBLE: lifetime?.visible === false ? "0" : "1", DSH_PET_SCREEN_LOCKED: this.screenLocked ? "1" : "0", DSH_PET_SYSTEM_ASLEEP: this.systemAsleep ? "1" : "0" };
|
|
46
126
|
delete env.ELECTRON_RUN_AS_NODE;
|
|
47
127
|
const args = [fileURLToPath(new URL("../desktop/main.cjs", import.meta.url))];
|
|
48
128
|
if (env.DSH_PET_TEST_NO_SANDBOX === "1") args.unshift("--no-sandbox");
|
|
49
|
-
const child =
|
|
129
|
+
const child = spawn2(executable, args, { env, stdio: ["ignore", "pipe", "pipe", "ipc"] });
|
|
50
130
|
const generation = this.generation;
|
|
51
131
|
this.child = child;
|
|
52
132
|
let diagnostic = "", userClosed = false;
|
|
@@ -175,6 +255,8 @@ var ElectronBridge = class extends EventEmitter {
|
|
|
175
255
|
}
|
|
176
256
|
async dispose() {
|
|
177
257
|
this.closing = true;
|
|
258
|
+
this.preparing?.abort();
|
|
259
|
+
await this.preparation?.catch(() => void 0);
|
|
178
260
|
const child = this.child;
|
|
179
261
|
if (!child) return;
|
|
180
262
|
if (child.pid === void 0 || child.exitCode !== null || child.signalCode !== null) {
|
package/dist/bridge.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/bridge.ts", "../src/desktop-lifecycle.ts"],
|
|
4
|
-
"sourcesContent": ["import { spawn, type ChildProcess } from 'node:child_process';\nimport { createRequire } from 'node:module';\nimport { fileURLToPath } from 'node:url';\nimport { EventEmitter } from 'node:events';\nimport type { ChatReceipt } from '../web/chat-contract.js';\nimport type { PetSnapshot, PetNotice } from './model.ts';\nimport type { NotificationRuntime, NotificationSnapshot, TaskNotice } from './notification-contract.ts';\nimport { NativeStartError, type StartLifetime, type NativeLifecycle } from './desktop-lifecycle.ts';\nexport { NativeStartError, type StartLifetime, type NativeLifecycle } from './desktop-lifecycle.ts';\n\nimport type { CompanionshipMode } from '../web/companionship.js';\nimport type { TextScale } from '../web/text-scale.js';\n\nexport interface DesktopOptions { size: number; npcHome?: number; npcRange?: number; textScale?: TextScale; roam: boolean; diagnostics?: boolean; companionship?: CompanionshipMode; notifications: boolean; bubbleDurationMs: number; electronPath?: string; locale?: string; systemNotifications?: boolean; reminders?: boolean; reminderDelayMs?: number; }\nexport interface PetBridge {\n start(options: DesktopOptions, lifetime?: StartLifetime): Promise<void>;\n update(snapshot: PetSnapshot): void;\n chatResult?(receipt: ChatReceipt): void;\n notify(notice: PetNotice | TaskNotice): void;\n notificationState?(snapshot: NotificationSnapshot): void;\n snoozeResult?(interactionId: string, ok: boolean, error?: string): void;\n presentRole?(notice: TaskNotice, runtime: NotificationRuntime): boolean;\n onAction(listener: (action: unknown) => void): void;\n removeAction(listener: (action: unknown) => void): void;\n dispose(): Promise<void>;\n configure?(options: DesktopOptions): void;\n control?(command: 'show' | 'hide' | 'characters'): void;\n focusHarness?(): void;\n onLifecycle?(listener: (state: NativeLifecycle) => void): void;\n removeLifecycle?(listener: (state: NativeLifecycle) => void): void;\n}\n\n/** Owns a separate Electron window; no changes or private IPC in the Harness desktop shell are needed. */\nexport class ElectronBridge extends EventEmitter implements PetBridge {\n private child?: ChildProcess;\n private latest?: PetSnapshot;\n private latestOptions?: DesktopOptions;\n private resultKey?: string;\n private closing = false;\n\n private generation = 0;\n private visibilityRevision = 0;\n private nativeVisible = false;\n private suspended = false;\n private screenLocked = false;\n private systemAsleep = false;\n private lastNotificationState?: NotificationSnapshot;\n\n async start(options: DesktopOptions, lifetime?: StartLifetime): Promise<void> {\n if (this.child) throw new NativeStartError('Desktop pet is already running', false);\n if (lifetime?.signal.aborted) throw new Error('\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88');\n this.latestOptions = { ...options };\n this.closing = false;\n this.generation = lifetime?.generation ?? this.generation + 1;\n this.visibilityRevision = 0; this.nativeVisible = false;\n if (process.platform === 'linux' && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY) throw new NativeStartError('\u684C\u5BA0\u9700\u8981\u684C\u9762\u663E\u793A\u73AF\u5883\u3002', false);\n let executable: string;\n try { executable = options.electronPath ?? createRequire(import.meta.url)('electron'); }\n catch (error) { throw new NativeStartError(String(error).slice(0, 600), false); }\n const env: NodeJS.ProcessEnv = { ...process.env, DSH_PET_GENERATION: String(this.generation), DSH_PET_VISIBLE: lifetime?.visible === false ? '0' : '1', DSH_PET_SCREEN_LOCKED: this.screenLocked ? '1' : '0', DSH_PET_SYSTEM_ASLEEP: this.systemAsleep ? '1' : '0' };\n delete (env as NodeJS.ProcessEnv).ELECTRON_RUN_AS_NODE;\n const args = [fileURLToPath(new URL('../desktop/main.cjs', import.meta.url))];\n if (env.DSH_PET_TEST_NO_SANDBOX === '1') args.unshift('--no-sandbox');\n const child = spawn(executable, args, { env, stdio: ['ignore', 'pipe', 'pipe', 'ipc'] });\n const generation = this.generation; this.child = child;\n let diagnostic = '', userClosed = false;\n child.stderr?.on('data', data => { diagnostic = (diagnostic + data.toString()).slice(-4000); });\n child.on('message', message => {\n if (this.child !== child || this.closing || lifetime?.signal.aborted || !isRecord(message)) return;\n if (message.type === 'closed') userClosed = true;\n if (message.type === 'action') this.emit('action', message.action);\n if (message.type === 'tray-state') this.emit('tray-state', message.state);\n if (message.type === 'tray-icon') this.emit('tray-icon', message);\n if (message.type === 'visibility' && message.generation === generation && typeof message.visible === 'boolean' && Number.isSafeInteger(message.visibilityRevision) && (message.visibilityRevision as number) > this.visibilityRevision) {\n this.visibilityRevision = message.visibilityRevision as number;\n this.nativeVisible = message.visible; this.suspended = message.suspended === true;\n if (typeof message.screenLocked === 'boolean') this.screenLocked = message.screenLocked;\n if (typeof message.systemAsleep === 'boolean') this.systemAsleep = message.systemAsleep;\n this.emit('lifecycle', { running: true, visible: this.nativeVisible, generation, visibilityRevision: this.visibilityRevision, suspended: this.suspended, ...(typeof message.desiredVisible === 'boolean' ? { desiredVisible: message.desiredVisible } : {}) });\n }\n });\n child.once('exit', (code, signal) => {\n if (this.child !== child) return;\n this.child = undefined; this.nativeVisible = false;\n const unexpected = !this.closing && !userClosed && !lifetime?.signal.aborted;\n const error = unexpected ? `\u684C\u5BA0\u8FDB\u7A0B\u5DF2\u9000\u51FA (${signal ?? code}): ${diagnostic}`.slice(0, 600) : undefined;\n this.emit('lifecycle', { running: false, visible: false, generation, visibilityRevision: ++this.visibilityRevision, suspended: false, unexpected, ...(error ? { error } : {}) });\n if (error) this.emit('failure', new Error(error));\n });\n child.on('error', error => { if (this.child === child && !this.closing && !lifetime?.signal.aborted) this.emit('failure', error); });\n await new Promise<void>((resolve, reject) => {\n let done = false;\n const finish = (error?: Error) => {\n if (done) return; done = true;\n clearTimeout(timer); child.off('message', ready); child.off('error', failed); child.off('exit', exited); lifetime?.signal.removeEventListener('abort', aborted);\n if (error) { child.kill(); reject(error); } else resolve();\n };\n const ready = (message: unknown) => {\n if (isRecord(message) && message.type === 'startup-error' && this.child === child && typeof message.error === 'string') {\n finish(new NativeStartError(message.error.slice(0, 600), message.recoverable === true)); return;\n }\n if (isRecord(message) && message.type === 'ready' && this.child === child && !lifetime?.signal.aborted) {\n this.resultKey = undefined;\n this.send({ type: 'init', options: { ...this.latestOptions, locale: this.latestOptions?.locale ?? null }, baseline: true, snapshot: this.latest && desktopSnapshot(this.latest, true) });\n if (this.lastNotificationState) this.notificationState(this.lastNotificationState);\n finish();\n }\n };\n const failed = (error: NodeJS.ErrnoException) => finish(new NativeStartError(error.message.slice(0, 600), error.code === 'EAGAIN' || error.code === 'ENOMEM'));\n const exited = (code: number | null, signal: string | null) => finish(new NativeStartError(`\u684C\u5BA0\u542F\u52A8\u5931\u8D25 (${signal ?? code}): ${diagnostic}`.slice(0, 600), true));\n const aborted = () => finish(new Error('\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88'));\n const timer = setTimeout(() => finish(new NativeStartError(`\u684C\u5BA0\u672A\u80FD\u5728 20 \u79D2\u5185\u542F\u52A8: ${diagnostic}`.slice(0, 600), true)), 20000);\n child.on('message', ready); child.once('error', failed); child.once('exit', exited);\n lifetime?.signal.addEventListener('abort', aborted, { once: true });\n if (lifetime?.signal.aborted) aborted();\n });\n }\n\n update(snapshot: PetSnapshot): void {\n this.latest = snapshot;\n const key = snapshot.results.map(result => `${result.id}:${result.read}`).join('|');\n this.send({ type: 'snapshot', snapshot: desktopSnapshot(snapshot, key !== this.resultKey) });\n this.resultKey = key;\n }\n notify(notice: PetNotice | TaskNotice): void { this.send({ type: 'notice', notice }); }\n notificationState(snapshot: NotificationSnapshot): void { this.lastNotificationState = structuredClone(snapshot); this.send({ type: 'notification-state', snapshot }); }\n snoozeResult(interactionId: string, ok: boolean, error?: string): void { this.send({ type: 'notification-snooze-result', interactionId, ok, ...(error ? { error: error.slice(0, 600) } : {}) }); }\n presentRole(notice: TaskNotice, runtime: NotificationRuntime): boolean {\n if (!this.child?.connected || this.closing || !this.nativeVisible || this.suspended || runtime.generation !== this.generation || runtime.visibilityRevision !== this.visibilityRevision || !runtime.visible) return false;\n this.send({ type: 'notice', notice, generation: runtime.generation, visibilityRevision: runtime.visibilityRevision }); return true;\n }\n chatResult(receipt: ChatReceipt): void { this.send(receipt); }\n onAction(listener: (action: unknown) => void): void { this.on('action', listener); }\n removeAction(listener: (action: unknown) => void): void { this.off('action', listener); }\n // JSON IPC omits undefined. An explicit null lets a cleared Harness\n // preference restore the renderer's automatic language instead of retaining\n // its previous locale during a merged configuration update.\n configure(options: DesktopOptions): void { this.latestOptions = { ...options }; this.send({ type: 'configure', options: { ...options, locale: options.locale ?? null } }); }\n control(command: 'show' | 'hide' | 'characters'): void { this.send({ type: 'control', command }); }\n focusHarness(): void { this.send({ type: 'control', command: 'focus-harness' }); }\n onLifecycle(listener: (state: NativeLifecycle) => void): void { this.on('lifecycle', listener); }\n removeLifecycle(listener: (state: NativeLifecycle) => void): void { this.off('lifecycle', listener); }\n private send(message: object): void {\n const child = this.child;\n if (child?.connected && !this.closing) child.send(message, error => { if (error && this.child === child && !this.closing) this.emit('failure', error); });\n }\n\n async dispose(): Promise<void> {\n this.closing = true;\n const child = this.child;\n if (!child) return;\n if (child.pid === undefined || child.exitCode !== null || child.signalCode !== null) { if (this.child === child) this.child = undefined; return; }\n await new Promise<void>((resolve, reject) => {\n let deadline: ReturnType<typeof setTimeout>;\n const timer = setTimeout(() => { child.kill('SIGKILL'); deadline = setTimeout(() => { if (child.exitCode !== null || child.signalCode !== null) resolve(); else reject(new Error('\u684C\u5BA0\u8FDB\u7A0B\u672A\u786E\u8BA4\u9000\u51FA')); }, 1000); }, 3000);\n child.once('exit', () => { clearTimeout(timer); clearTimeout(deadline); resolve(); });\n if (child.connected) child.send({ type: 'quit' }, error => { if (error) child.kill(); }); else child.kill();\n });\n if (this.child === child) this.child = undefined;\n }\n}\n\nexport function isRecord(value: unknown): value is Record<string, unknown> { return typeof value === 'object' && value !== null && !Array.isArray(value); }\n\n/** Stream animation updates carry metadata; full result text crosses IPC only when it changes. */\nfunction desktopSnapshot(snapshot: PetSnapshot, includeResults: boolean) {\n const { results, ...state } = snapshot;\n return { ...state, text: state.mood === 'happy' ? '' : state.text,\n sessions: state.sessions.map(session => ({ ...session, text: session.mood === 'happy' ? '' : session.text, reply: '' })),\n ...(includeResults ? { results } : {}),\n };\n}\n", "/** Shared Host/native lifetime contract. Only explicitly recoverable failures retry. */\nexport interface StartLifetime { signal: AbortSignal; generation: number; visible?: boolean; }\nexport interface NativeLifecycle {\n running: boolean; visible: boolean; error?: string;\n generation?: number; visibilityRevision?: number; suspended?: boolean;\n desiredVisible?: boolean; unexpected?: boolean;\n}\nexport class NativeStartError extends Error {\n constructor(message: string, readonly recoverable: boolean) { super(message); this.name = 'NativeStartError'; }\n}\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,
|
|
6
|
-
"names": []
|
|
3
|
+
"sources": ["../src/bridge.ts", "../src/desktop-lifecycle.ts", "../src/electron-runtime.ts"],
|
|
4
|
+
"sourcesContent": ["import { spawn, type ChildProcess } from 'node:child_process';\nimport { fileURLToPath } from 'node:url';\nimport { EventEmitter } from 'node:events';\nimport type { ChatReceipt } from '../web/chat-contract.js';\nimport type { PetSnapshot, PetNotice } from './model.ts';\nimport type { NotificationRuntime, NotificationSnapshot, TaskNotice } from './notification-contract.ts';\nimport { NativeStartError, type StartLifetime, type NativeLifecycle } from './desktop-lifecycle.ts';\nimport { electronExecutable } from './electron-runtime.ts';\nexport { NativeStartError, type StartLifetime, type NativeLifecycle } from './desktop-lifecycle.ts';\n\nimport type { CompanionshipMode } from '../web/companionship.js';\nimport type { TextScale } from '../web/text-scale.js';\n\nexport interface DesktopOptions { size: number; npcHome?: number; npcRange?: number; textScale?: TextScale; roam: boolean; diagnostics?: boolean; companionship?: CompanionshipMode; notifications: boolean; bubbleDurationMs: number; electronPath?: string; locale?: string; systemNotifications?: boolean; reminders?: boolean; reminderDelayMs?: number; }\nexport interface PetBridge {\n start(options: DesktopOptions, lifetime?: StartLifetime): Promise<void>;\n update(snapshot: PetSnapshot): void;\n chatResult?(receipt: ChatReceipt): void;\n notify(notice: PetNotice | TaskNotice): void;\n notificationState?(snapshot: NotificationSnapshot): void;\n snoozeResult?(interactionId: string, ok: boolean, error?: string): void;\n presentRole?(notice: TaskNotice, runtime: NotificationRuntime): boolean;\n onAction(listener: (action: unknown) => void): void;\n removeAction(listener: (action: unknown) => void): void;\n dispose(): Promise<void>;\n configure?(options: DesktopOptions): void;\n control?(command: 'show' | 'hide' | 'characters'): void;\n focusHarness?(): void;\n onLifecycle?(listener: (state: NativeLifecycle) => void): void;\n removeLifecycle?(listener: (state: NativeLifecycle) => void): void;\n}\n\n/** Owns a separate Electron window; no changes or private IPC in the Harness desktop shell are needed. */\nexport class ElectronBridge extends EventEmitter implements PetBridge {\n private child?: ChildProcess;\n private latest?: PetSnapshot;\n private latestOptions?: DesktopOptions;\n private resultKey?: string;\n private closing = false;\n private preparing?: AbortController;\n private preparation?: Promise<string>;\n\n private generation = 0;\n private visibilityRevision = 0;\n private nativeVisible = false;\n private suspended = false;\n private screenLocked = false;\n private systemAsleep = false;\n private lastNotificationState?: NotificationSnapshot;\n\n async start(options: DesktopOptions, lifetime?: StartLifetime): Promise<void> {\n if (this.child || this.preparing) throw new NativeStartError('Desktop pet is already running or starting', false);\n if (lifetime?.signal.aborted) throw new Error('\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88');\n this.latestOptions = { ...options };\n this.closing = false;\n this.generation = lifetime?.generation ?? this.generation + 1;\n this.visibilityRevision = 0; this.nativeVisible = false;\n if (process.platform === 'linux' && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY) throw new NativeStartError('\u684C\u5BA0\u9700\u8981\u684C\u9762\u663E\u793A\u73AF\u5883\u3002', false);\n let executable: string;\n if (options.electronPath !== undefined) executable = options.electronPath;\n else {\n const preparing = new AbortController(); this.preparing = preparing;\n const abort = () => preparing.abort();\n lifetime?.signal.addEventListener('abort', abort, { once: true });\n if (lifetime?.signal.aborted) abort();\n try {\n this.preparation = electronExecutable(preparing.signal);\n executable = await this.preparation;\n if (preparing.signal.aborted || this.closing) throw new Error('\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88');\n } catch (error) { throw error instanceof NativeStartError ? error : new NativeStartError(String(error).slice(0, 600), false); }\n finally { lifetime?.signal.removeEventListener('abort', abort); this.preparing = undefined; this.preparation = undefined; }\n }\n const env: NodeJS.ProcessEnv = { ...process.env, DSH_PET_GENERATION: String(this.generation), DSH_PET_VISIBLE: lifetime?.visible === false ? '0' : '1', DSH_PET_SCREEN_LOCKED: this.screenLocked ? '1' : '0', DSH_PET_SYSTEM_ASLEEP: this.systemAsleep ? '1' : '0' };\n delete (env as NodeJS.ProcessEnv).ELECTRON_RUN_AS_NODE;\n const args = [fileURLToPath(new URL('../desktop/main.cjs', import.meta.url))];\n if (env.DSH_PET_TEST_NO_SANDBOX === '1') args.unshift('--no-sandbox');\n const child = spawn(executable, args, { env, stdio: ['ignore', 'pipe', 'pipe', 'ipc'] });\n const generation = this.generation; this.child = child;\n let diagnostic = '', userClosed = false;\n child.stderr?.on('data', data => { diagnostic = (diagnostic + data.toString()).slice(-4000); });\n child.on('message', message => {\n if (this.child !== child || this.closing || lifetime?.signal.aborted || !isRecord(message)) return;\n if (message.type === 'closed') userClosed = true;\n if (message.type === 'action') this.emit('action', message.action);\n if (message.type === 'tray-state') this.emit('tray-state', message.state);\n if (message.type === 'tray-icon') this.emit('tray-icon', message);\n if (message.type === 'visibility' && message.generation === generation && typeof message.visible === 'boolean' && Number.isSafeInteger(message.visibilityRevision) && (message.visibilityRevision as number) > this.visibilityRevision) {\n this.visibilityRevision = message.visibilityRevision as number;\n this.nativeVisible = message.visible; this.suspended = message.suspended === true;\n if (typeof message.screenLocked === 'boolean') this.screenLocked = message.screenLocked;\n if (typeof message.systemAsleep === 'boolean') this.systemAsleep = message.systemAsleep;\n this.emit('lifecycle', { running: true, visible: this.nativeVisible, generation, visibilityRevision: this.visibilityRevision, suspended: this.suspended, ...(typeof message.desiredVisible === 'boolean' ? { desiredVisible: message.desiredVisible } : {}) });\n }\n });\n child.once('exit', (code, signal) => {\n if (this.child !== child) return;\n this.child = undefined; this.nativeVisible = false;\n const unexpected = !this.closing && !userClosed && !lifetime?.signal.aborted;\n const error = unexpected ? `\u684C\u5BA0\u8FDB\u7A0B\u5DF2\u9000\u51FA (${signal ?? code}): ${diagnostic}`.slice(0, 600) : undefined;\n this.emit('lifecycle', { running: false, visible: false, generation, visibilityRevision: ++this.visibilityRevision, suspended: false, unexpected, ...(error ? { error } : {}) });\n if (error) this.emit('failure', new Error(error));\n });\n child.on('error', error => { if (this.child === child && !this.closing && !lifetime?.signal.aborted) this.emit('failure', error); });\n await new Promise<void>((resolve, reject) => {\n let done = false;\n const finish = (error?: Error) => {\n if (done) return; done = true;\n clearTimeout(timer); child.off('message', ready); child.off('error', failed); child.off('exit', exited); lifetime?.signal.removeEventListener('abort', aborted);\n if (error) { child.kill(); reject(error); } else resolve();\n };\n const ready = (message: unknown) => {\n if (isRecord(message) && message.type === 'startup-error' && this.child === child && typeof message.error === 'string') {\n finish(new NativeStartError(message.error.slice(0, 600), message.recoverable === true)); return;\n }\n if (isRecord(message) && message.type === 'ready' && this.child === child && !lifetime?.signal.aborted) {\n this.resultKey = undefined;\n this.send({ type: 'init', options: { ...this.latestOptions, locale: this.latestOptions?.locale ?? null }, baseline: true, snapshot: this.latest && desktopSnapshot(this.latest, true) });\n if (this.lastNotificationState) this.notificationState(this.lastNotificationState);\n finish();\n }\n };\n const failed = (error: NodeJS.ErrnoException) => finish(new NativeStartError(error.message.slice(0, 600), error.code === 'EAGAIN' || error.code === 'ENOMEM'));\n const exited = (code: number | null, signal: string | null) => finish(new NativeStartError(`\u684C\u5BA0\u542F\u52A8\u5931\u8D25 (${signal ?? code}): ${diagnostic}`.slice(0, 600), true));\n const aborted = () => finish(new Error('\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88'));\n const timer = setTimeout(() => finish(new NativeStartError(`\u684C\u5BA0\u672A\u80FD\u5728 20 \u79D2\u5185\u542F\u52A8: ${diagnostic}`.slice(0, 600), true)), 20000);\n child.on('message', ready); child.once('error', failed); child.once('exit', exited);\n lifetime?.signal.addEventListener('abort', aborted, { once: true });\n if (lifetime?.signal.aborted) aborted();\n });\n }\n\n update(snapshot: PetSnapshot): void {\n this.latest = snapshot;\n const key = snapshot.results.map(result => `${result.id}:${result.read}`).join('|');\n this.send({ type: 'snapshot', snapshot: desktopSnapshot(snapshot, key !== this.resultKey) });\n this.resultKey = key;\n }\n notify(notice: PetNotice | TaskNotice): void { this.send({ type: 'notice', notice }); }\n notificationState(snapshot: NotificationSnapshot): void { this.lastNotificationState = structuredClone(snapshot); this.send({ type: 'notification-state', snapshot }); }\n snoozeResult(interactionId: string, ok: boolean, error?: string): void { this.send({ type: 'notification-snooze-result', interactionId, ok, ...(error ? { error: error.slice(0, 600) } : {}) }); }\n presentRole(notice: TaskNotice, runtime: NotificationRuntime): boolean {\n if (!this.child?.connected || this.closing || !this.nativeVisible || this.suspended || runtime.generation !== this.generation || runtime.visibilityRevision !== this.visibilityRevision || !runtime.visible) return false;\n this.send({ type: 'notice', notice, generation: runtime.generation, visibilityRevision: runtime.visibilityRevision }); return true;\n }\n chatResult(receipt: ChatReceipt): void { this.send(receipt); }\n onAction(listener: (action: unknown) => void): void { this.on('action', listener); }\n removeAction(listener: (action: unknown) => void): void { this.off('action', listener); }\n // JSON IPC omits undefined. An explicit null lets a cleared Harness\n // preference restore the renderer's automatic language instead of retaining\n // its previous locale during a merged configuration update.\n configure(options: DesktopOptions): void { this.latestOptions = { ...options }; this.send({ type: 'configure', options: { ...options, locale: options.locale ?? null } }); }\n control(command: 'show' | 'hide' | 'characters'): void { this.send({ type: 'control', command }); }\n focusHarness(): void { this.send({ type: 'control', command: 'focus-harness' }); }\n onLifecycle(listener: (state: NativeLifecycle) => void): void { this.on('lifecycle', listener); }\n removeLifecycle(listener: (state: NativeLifecycle) => void): void { this.off('lifecycle', listener); }\n private send(message: object): void {\n const child = this.child;\n if (child?.connected && !this.closing) child.send(message, error => { if (error && this.child === child && !this.closing) this.emit('failure', error); });\n }\n\n async dispose(): Promise<void> {\n this.closing = true;\n this.preparing?.abort();\n await this.preparation?.catch(() => undefined);\n const child = this.child;\n if (!child) return;\n if (child.pid === undefined || child.exitCode !== null || child.signalCode !== null) { if (this.child === child) this.child = undefined; return; }\n await new Promise<void>((resolve, reject) => {\n let deadline: ReturnType<typeof setTimeout>;\n const timer = setTimeout(() => { child.kill('SIGKILL'); deadline = setTimeout(() => { if (child.exitCode !== null || child.signalCode !== null) resolve(); else reject(new Error('\u684C\u5BA0\u8FDB\u7A0B\u672A\u786E\u8BA4\u9000\u51FA')); }, 1000); }, 3000);\n child.once('exit', () => { clearTimeout(timer); clearTimeout(deadline); resolve(); });\n if (child.connected) child.send({ type: 'quit' }, error => { if (error) child.kill(); }); else child.kill();\n });\n if (this.child === child) this.child = undefined;\n }\n}\n\nexport function isRecord(value: unknown): value is Record<string, unknown> { return typeof value === 'object' && value !== null && !Array.isArray(value); }\n\n/** Stream animation updates carry metadata; full result text crosses IPC only when it changes. */\nfunction desktopSnapshot(snapshot: PetSnapshot, includeResults: boolean) {\n const { results, ...state } = snapshot;\n return { ...state, text: state.mood === 'happy' ? '' : state.text,\n sessions: state.sessions.map(session => ({ ...session, text: session.mood === 'happy' ? '' : session.text, reply: '' })),\n ...(includeResults ? { results } : {}),\n };\n}\n", "/** Shared Host/native lifetime contract. Only explicitly recoverable failures retry. */\nexport interface StartLifetime { signal: AbortSignal; generation: number; visible?: boolean; }\nexport interface NativeLifecycle {\n running: boolean; visible: boolean; error?: string;\n generation?: number; visibilityRevision?: number; suspended?: boolean;\n desiredVisible?: boolean; unexpected?: boolean;\n}\nexport class NativeStartError extends Error {\n constructor(message: string, readonly recoverable: boolean) { super(message); this.name = 'NativeStartError'; }\n}\n", "import { spawn } from 'node:child_process';\nimport { access, readFile } from 'node:fs/promises';\nimport { createRequire } from 'node:module';\nimport { dirname, join } from 'node:path';\nimport { NativeStartError } from './desktop-lifecycle.ts';\n\n// Electron 44's index.js may spawnSync its installer. Resolve files without\n// executing that entrypoint, then prepare missing binaries off the Host loop.\nexport async function electronExecutable(signal: AbortSignal): Promise<string> {\n const directory = dirname(createRequire(import.meta.url).resolve('electron'));\n async function installed(): Promise<string | undefined> {\n let relative: string;\n try { relative = await readFile(join(directory, 'path.txt'), 'utf8'); }\n catch (error) { if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error; relative = ''; }\n if (process.env.ELECTRON_OVERRIDE_DIST_PATH) return join(process.env.ELECTRON_OVERRIDE_DIST_PATH, relative || 'electron');\n if (!relative) return;\n const executable = join(directory, 'dist', relative);\n try { await access(executable); return executable; }\n catch (error) { if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error; }\n }\n if (signal.aborted) throw new Error('\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88');\n const existing = await installed();\n if (existing) return existing;\n await new Promise<void>((resolve, reject) => {\n if (signal.aborted) { reject(new Error('\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88')); return; }\n const child = spawn(process.execPath, [join(directory, 'install.js')], {\n env: { ...process.env, ELECTRON_RUN_AS_NODE: '1' }, stdio: 'ignore', windowsHide: true,\n });\n let failure: Error | undefined, killTimer: ReturnType<typeof setTimeout> | undefined;\n const stop = (error: Error) => {\n if (failure) return;\n failure = error; child.kill();\n killTimer = setTimeout(() => child.kill('SIGKILL'), 1000);\n };\n const aborted = () => stop(new Error('\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88'));\n const timer = setTimeout(() => stop(new NativeStartError('Electron \u8FD0\u884C\u65F6\u51C6\u5907\u8D85\u65F6\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u6216\u6309\u4F7F\u7528\u6307\u5357\u9884\u5148\u5B89\u88C5\u8FD0\u884C\u65F6\u3002', false)), 240_000);\n signal.addEventListener('abort', aborted, { once: true });\n const finish = (error?: Error) => {\n clearTimeout(timer); clearTimeout(killTimer); signal.removeEventListener('abort', aborted);\n if (failure || error) reject(failure ?? error); else resolve();\n };\n child.once('error', error => finish(new NativeStartError(error.message.slice(0, 600), false)));\n child.once('exit', code => finish(code === 0 ? undefined : new NativeStartError(`Electron \u8FD0\u884C\u65F6\u51C6\u5907\u5931\u8D25 (${code})\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u6216\u6309\u4F7F\u7528\u6307\u5357\u9884\u5148\u5B89\u88C5\u8FD0\u884C\u65F6\u3002`, false)));\n if (signal.aborted) aborted();\n });\n if (signal.aborted) throw new Error('\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88');\n const executable = await installed();\n if (!executable) throw new NativeStartError('Electron \u5B89\u88C5\u672A\u751F\u6210\u53EF\u7528\u8FD0\u884C\u65F6\uFF0C\u8B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AAA,cAAQ,QAAO,IAAI,MAAM,wDAAW,CAAC;AAAA,QAAG,GAAG,GAAI;AAAA,MAAG,GAAG,GAAI;AACjN,YAAM,KAAK,QAAQ,MAAM;AAAE,qBAAa,KAAK;AAAG,qBAAa,QAAQ;AAAG,gBAAQ;AAAA,MAAG,CAAC;AACpF,UAAI,MAAM,UAAW,OAAM,KAAK,EAAE,MAAM,OAAO,GAAG,WAAS;AAAE,YAAI,MAAO,OAAM,KAAK;AAAA,MAAG,CAAC;AAAA,UAAQ,OAAM,KAAK;AAAA,IAC5G,CAAC;AACD,QAAI,KAAK,UAAU,MAAO,MAAK,QAAQ;AAAA,EACzC;AACF;AAEO,SAAS,SAAS,OAAkD;AAAE,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAAG;AAG1J,SAAS,gBAAgB,UAAuB,gBAAyB;AACvE,QAAM,EAAE,SAAS,GAAG,MAAM,IAAI;AAC9B,SAAO;AAAA,IAAE,GAAG;AAAA,IAAO,MAAM,MAAM,SAAS,UAAU,KAAK,MAAM;AAAA,IAC3D,UAAU,MAAM,SAAS,IAAI,cAAY,EAAE,GAAG,SAAS,MAAM,QAAQ,SAAS,UAAU,KAAK,QAAQ,MAAM,OAAO,GAAG,EAAE;AAAA,IACvH,GAAI,iBAAiB,EAAE,QAAQ,IAAI,CAAC;AAAA,EACtC;AACF;",
|
|
6
|
+
"names": ["spawn", "executable", "spawn"]
|
|
7
7
|
}
|
package/dist/build-info.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schema": 1,
|
|
3
|
-
"commit": "
|
|
3
|
+
"commit": "54684143f4c86724c852b1a93cde00cb2c43a7e0",
|
|
4
4
|
"dirty": false,
|
|
5
|
-
"productDigest": "
|
|
5
|
+
"productDigest": "b0c7471a03a716d55e364b5871f5098c1727d24b036ccd247aee06d5bbaa039a"
|
|
6
6
|
}
|
package/dist/client.js
CHANGED
|
@@ -20959,7 +20959,7 @@ function apply(ctx) {
|
|
|
20959
20959
|
const reply = await ctx.connection.rpc.call("/api", command ? "coopanion/control" : "coopanion/status", command ? { command } : {}, signal);
|
|
20960
20960
|
if (!reply.ok) throw new Error(reply.error.message);
|
|
20961
20961
|
const value = reply.value;
|
|
20962
|
-
if (!value || !["stopped", "starting", "running", "stopping", "error"].includes(value.phase) || typeof value.visible !== "boolean") throw new Error("Invalid desktop pet status");
|
|
20962
|
+
if (!value || !["stopped", "starting", "running", "stopping", "recovering", "error"].includes(value.phase) || typeof value.visible !== "boolean") throw new Error("Invalid desktop pet status");
|
|
20963
20963
|
return value;
|
|
20964
20964
|
}
|
|
20965
20965
|
};
|
package/dist/figure-server.cjs
CHANGED
|
@@ -20455,7 +20455,7 @@ async function sourceArchive(project) {
|
|
|
20455
20455
|
function createPetServer({ webRoot, store, companions, prefix = "/" }) {
|
|
20456
20456
|
let operation = Promise.resolve();
|
|
20457
20457
|
const server = (0, import_node_http.createServer)(async (req, res) => {
|
|
20458
|
-
const origin = `http://127.0.0.1:${
|
|
20458
|
+
const origin = `http://127.0.0.1:${req.socket.localPort}`;
|
|
20459
20459
|
const json2 = (value, status = 200) => {
|
|
20460
20460
|
res.writeHead(status, { "Content-Type": "application/json", "Cache-Control": "no-store" });
|
|
20461
20461
|
res.end(JSON.stringify(value));
|
package/dist/index.js
CHANGED
|
@@ -662,8 +662,7 @@ function chatErrorCode(error) {
|
|
|
662
662
|
import z2 from "@deepseek-ai/schemastery";
|
|
663
663
|
|
|
664
664
|
// src/bridge.ts
|
|
665
|
-
import { spawn } from "node:child_process";
|
|
666
|
-
import { createRequire } from "node:module";
|
|
665
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
667
666
|
import { fileURLToPath } from "node:url";
|
|
668
667
|
import { EventEmitter } from "node:events";
|
|
669
668
|
|
|
@@ -676,6 +675,71 @@ var NativeStartError = class extends Error {
|
|
|
676
675
|
}
|
|
677
676
|
};
|
|
678
677
|
|
|
678
|
+
// src/electron-runtime.ts
|
|
679
|
+
import { spawn } from "node:child_process";
|
|
680
|
+
import { access, readFile } from "node:fs/promises";
|
|
681
|
+
import { createRequire } from "node:module";
|
|
682
|
+
import { dirname, join } from "node:path";
|
|
683
|
+
async function electronExecutable(signal) {
|
|
684
|
+
const directory = dirname(createRequire(import.meta.url).resolve("electron"));
|
|
685
|
+
async function installed() {
|
|
686
|
+
let relative;
|
|
687
|
+
try {
|
|
688
|
+
relative = await readFile(join(directory, "path.txt"), "utf8");
|
|
689
|
+
} catch (error) {
|
|
690
|
+
if (error.code !== "ENOENT") throw error;
|
|
691
|
+
relative = "";
|
|
692
|
+
}
|
|
693
|
+
if (process.env.ELECTRON_OVERRIDE_DIST_PATH) return join(process.env.ELECTRON_OVERRIDE_DIST_PATH, relative || "electron");
|
|
694
|
+
if (!relative) return;
|
|
695
|
+
const executable2 = join(directory, "dist", relative);
|
|
696
|
+
try {
|
|
697
|
+
await access(executable2);
|
|
698
|
+
return executable2;
|
|
699
|
+
} catch (error) {
|
|
700
|
+
if (error.code !== "ENOENT") throw error;
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
if (signal.aborted) throw new Error("\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88");
|
|
704
|
+
const existing = await installed();
|
|
705
|
+
if (existing) return existing;
|
|
706
|
+
await new Promise((resolve, reject) => {
|
|
707
|
+
if (signal.aborted) {
|
|
708
|
+
reject(new Error("\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88"));
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
const child = spawn(process.execPath, [join(directory, "install.js")], {
|
|
712
|
+
env: { ...process.env, ELECTRON_RUN_AS_NODE: "1" },
|
|
713
|
+
stdio: "ignore",
|
|
714
|
+
windowsHide: true
|
|
715
|
+
});
|
|
716
|
+
let failure, killTimer;
|
|
717
|
+
const stop = (error) => {
|
|
718
|
+
if (failure) return;
|
|
719
|
+
failure = error;
|
|
720
|
+
child.kill();
|
|
721
|
+
killTimer = setTimeout(() => child.kill("SIGKILL"), 1e3);
|
|
722
|
+
};
|
|
723
|
+
const aborted = () => stop(new Error("\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88"));
|
|
724
|
+
const timer = setTimeout(() => stop(new NativeStartError("Electron \u8FD0\u884C\u65F6\u51C6\u5907\u8D85\u65F6\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u6216\u6309\u4F7F\u7528\u6307\u5357\u9884\u5148\u5B89\u88C5\u8FD0\u884C\u65F6\u3002", false)), 24e4);
|
|
725
|
+
signal.addEventListener("abort", aborted, { once: true });
|
|
726
|
+
const finish = (error) => {
|
|
727
|
+
clearTimeout(timer);
|
|
728
|
+
clearTimeout(killTimer);
|
|
729
|
+
signal.removeEventListener("abort", aborted);
|
|
730
|
+
if (failure || error) reject(failure ?? error);
|
|
731
|
+
else resolve();
|
|
732
|
+
};
|
|
733
|
+
child.once("error", (error) => finish(new NativeStartError(error.message.slice(0, 600), false)));
|
|
734
|
+
child.once("exit", (code) => finish(code === 0 ? void 0 : new NativeStartError(`Electron \u8FD0\u884C\u65F6\u51C6\u5907\u5931\u8D25 (${code})\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u6216\u6309\u4F7F\u7528\u6307\u5357\u9884\u5148\u5B89\u88C5\u8FD0\u884C\u65F6\u3002`, false)));
|
|
735
|
+
if (signal.aborted) aborted();
|
|
736
|
+
});
|
|
737
|
+
if (signal.aborted) throw new Error("\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88");
|
|
738
|
+
const executable = await installed();
|
|
739
|
+
if (!executable) throw new NativeStartError("Electron \u5B89\u88C5\u672A\u751F\u6210\u53EF\u7528\u8FD0\u884C\u65F6\uFF0C\u8BF7\u6309\u4F7F\u7528\u6307\u5357\u91CD\u65B0\u51C6\u5907\u3002", false);
|
|
740
|
+
return executable;
|
|
741
|
+
}
|
|
742
|
+
|
|
679
743
|
// src/bridge.ts
|
|
680
744
|
var ElectronBridge = class extends EventEmitter {
|
|
681
745
|
child;
|
|
@@ -683,6 +747,8 @@ var ElectronBridge = class extends EventEmitter {
|
|
|
683
747
|
latestOptions;
|
|
684
748
|
resultKey;
|
|
685
749
|
closing = false;
|
|
750
|
+
preparing;
|
|
751
|
+
preparation;
|
|
686
752
|
generation = 0;
|
|
687
753
|
visibilityRevision = 0;
|
|
688
754
|
nativeVisible = false;
|
|
@@ -691,7 +757,7 @@ var ElectronBridge = class extends EventEmitter {
|
|
|
691
757
|
systemAsleep = false;
|
|
692
758
|
lastNotificationState;
|
|
693
759
|
async start(options, lifetime) {
|
|
694
|
-
if (this.child) throw new NativeStartError("Desktop pet is already running", false);
|
|
760
|
+
if (this.child || this.preparing) throw new NativeStartError("Desktop pet is already running or starting", false);
|
|
695
761
|
if (lifetime?.signal.aborted) throw new Error("\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88");
|
|
696
762
|
this.latestOptions = { ...options };
|
|
697
763
|
this.closing = false;
|
|
@@ -700,16 +766,30 @@ var ElectronBridge = class extends EventEmitter {
|
|
|
700
766
|
this.nativeVisible = false;
|
|
701
767
|
if (process.platform === "linux" && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY) throw new NativeStartError("\u684C\u5BA0\u9700\u8981\u684C\u9762\u663E\u793A\u73AF\u5883\u3002", false);
|
|
702
768
|
let executable;
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
769
|
+
if (options.electronPath !== void 0) executable = options.electronPath;
|
|
770
|
+
else {
|
|
771
|
+
const preparing = new AbortController();
|
|
772
|
+
this.preparing = preparing;
|
|
773
|
+
const abort = () => preparing.abort();
|
|
774
|
+
lifetime?.signal.addEventListener("abort", abort, { once: true });
|
|
775
|
+
if (lifetime?.signal.aborted) abort();
|
|
776
|
+
try {
|
|
777
|
+
this.preparation = electronExecutable(preparing.signal);
|
|
778
|
+
executable = await this.preparation;
|
|
779
|
+
if (preparing.signal.aborted || this.closing) throw new Error("\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88");
|
|
780
|
+
} catch (error) {
|
|
781
|
+
throw error instanceof NativeStartError ? error : new NativeStartError(String(error).slice(0, 600), false);
|
|
782
|
+
} finally {
|
|
783
|
+
lifetime?.signal.removeEventListener("abort", abort);
|
|
784
|
+
this.preparing = void 0;
|
|
785
|
+
this.preparation = void 0;
|
|
786
|
+
}
|
|
707
787
|
}
|
|
708
788
|
const env = { ...process.env, DSH_PET_GENERATION: String(this.generation), DSH_PET_VISIBLE: lifetime?.visible === false ? "0" : "1", DSH_PET_SCREEN_LOCKED: this.screenLocked ? "1" : "0", DSH_PET_SYSTEM_ASLEEP: this.systemAsleep ? "1" : "0" };
|
|
709
789
|
delete env.ELECTRON_RUN_AS_NODE;
|
|
710
790
|
const args = [fileURLToPath(new URL("../desktop/main.cjs", import.meta.url))];
|
|
711
791
|
if (env.DSH_PET_TEST_NO_SANDBOX === "1") args.unshift("--no-sandbox");
|
|
712
|
-
const child =
|
|
792
|
+
const child = spawn2(executable, args, { env, stdio: ["ignore", "pipe", "pipe", "ipc"] });
|
|
713
793
|
const generation = this.generation;
|
|
714
794
|
this.child = child;
|
|
715
795
|
let diagnostic = "", userClosed = false;
|
|
@@ -838,6 +918,8 @@ var ElectronBridge = class extends EventEmitter {
|
|
|
838
918
|
}
|
|
839
919
|
async dispose() {
|
|
840
920
|
this.closing = true;
|
|
921
|
+
this.preparing?.abort();
|
|
922
|
+
await this.preparation?.catch(() => void 0);
|
|
841
923
|
const child = this.child;
|
|
842
924
|
if (!child) return;
|
|
843
925
|
if (child.pid === void 0 || child.exitCode !== null || child.signalCode !== null) {
|
|
@@ -1320,7 +1402,7 @@ var PetControls = class {
|
|
|
1320
1402
|
this.startupExit = void 0;
|
|
1321
1403
|
this.set({ ...this.state, phase: "starting", error: void 0, retryAt: void 0, visible: false, generation: this.state.generation + 1, visibilityRevision: 0, suspended: false });
|
|
1322
1404
|
try {
|
|
1323
|
-
await this.withDeadline(this.bridge.start(this.options(), { signal: startup.signal, generation: this.state.generation, visible: this.state.desiredVisible }), this.limits.startTimeoutMs ??
|
|
1405
|
+
await this.withDeadline(this.bridge.start(this.options(), { signal: startup.signal, generation: this.state.generation, visible: this.state.desiredVisible }), this.limits.startTimeoutMs ?? 265e3, "\u684C\u5BA0\u542F\u52A8\u8D85\u65F6", startup.signal, true);
|
|
1324
1406
|
} catch (error) {
|
|
1325
1407
|
throw this.startupExit ?? error;
|
|
1326
1408
|
}
|