@takboo/dsh-coopanion 0.4.3 → 0.4.5
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 +28 -10
- package/desktop/main.cjs +18 -14
- package/dist/bridge.js +68 -25
- package/dist/bridge.js.map +2 -2
- package/dist/client.js +20238 -54
- package/dist/index.js +875 -112
- package/dist/index.js.map +4 -4
- package/dist/model.js +49 -10
- package/dist/model.js.map +2 -2
- package/docs/characters.md +18 -1
- package/docs/evidence/notification-n0/ci-final-summary.json +1251 -0
- package/docs/evidence/notification-n0/ci-summary.json +219 -0
- package/docs/evidence/notification-n0/macos-notification-center.png +0 -0
- package/docs/evidence/notification-n0/macos-single-instance-click.png +0 -0
- package/docs/evidence/notification-n0/single-instance-receipts.jsonl +13 -0
- package/docs/evidence/notification-n0/single-instance-session-header.json +10 -0
- package/docs/evidence/notification-n0/single-instance-session.zip +0 -0
- package/docs/evidence/notification-n0/single-instance-summary.json +80 -0
- package/docs/evidence/notification-n3/ci-final-summary.json +176 -0
- package/docs/evidence/notification-n3/ci-verification.json +7 -0
- package/docs/evidence/notification-n3/client-build-after.log +9 -0
- package/docs/evidence/notification-n3/client-build-before.log +1 -0
- package/docs/evidence/notification-n3/client-install-0.2.0-rc.2.json +23 -0
- package/docs/evidence/notification-n3/client-install-0.2.1-alpha.1.json +23 -0
- package/docs/evidence/notification-n3/completion-order-after.log +1 -0
- package/docs/evidence/notification-n3/completion-order-before.log +11 -0
- package/docs/evidence/notification-n3/desktop-after.log +5 -0
- package/docs/evidence/notification-n3/desktop-before.log +20 -0
- package/docs/evidence/notification-n3/desktop-exclusive-after.log +5 -0
- package/docs/evidence/notification-n3/install-rc2-redacted.log +29 -0
- package/docs/evidence/notification-n3/install-rc2-v2-redacted.log +24 -0
- package/docs/evidence/notification-n3/install-rc2-v3-redacted.log +33 -0
- package/docs/evidence/notification-n3/install-rc2-v4-redacted.log +32 -0
- package/docs/evidence/notification-n3/late-click-after.log +10 -0
- package/docs/evidence/notification-n3/late-click-before.log +39 -0
- package/docs/evidence/notification-n3/local-verification.json +7 -0
- package/docs/evidence/notification-n3/native-cold-after.log +8 -0
- package/docs/evidence/notification-n3/native-cold-before.log +22 -0
- package/docs/evidence/notification-n3/optional-projection-before.log +52 -0
- package/docs/evidence/notification-n3/ptc-restore-after.log +10 -0
- package/docs/evidence/notification-n3/ptc-restore-before.log +60 -0
- package/docs/evidence/notification-n3/request-capacity-before.log +39 -0
- package/docs/evidence/notification-n3/settlement-after.log +10 -0
- package/docs/evidence/notification-n3/settlement-before.log +47 -0
- package/docs/evidence/notification-n3/tool-error-after.log +10 -0
- package/docs/evidence/notification-n3/tool-error-before.log +57 -0
- package/docs/notification-contract.md +51 -0
- package/docs/notification-implementation.md +57 -0
- package/docs/notification-n0.md +59 -0
- package/docs/notification-n3.md +24 -0
- package/docs/notification-plan.md +180 -0
- package/docs/release-notes.md +16 -0
- package/docs/releasing.md +4 -0
- package/npm-shrinkwrap.json +871 -79
- package/package.json +29 -6
- package/scripts/build.mjs +5 -1
- package/scripts/check-npm.mjs +1 -1
- package/scripts/prepare-notification-probe.mjs +21 -0
- package/scripts/release-support.mjs +20 -9
- package/src/bridge.ts +70 -35
- package/src/client/Settings.tsx +48 -3
- package/src/client/index.ts +29 -1
- package/src/client/locales.ts +24 -6
- package/src/client/notification-client.ts +161 -0
- package/src/client/notification-copy.ts +25 -0
- package/src/client/system-notifications.ts +76 -0
- package/src/controls.ts +64 -24
- package/src/index.ts +99 -20
- package/src/model.ts +55 -13
- package/src/notification-broker.ts +363 -0
- package/src/notification-contract.ts +77 -0
- package/tests/bridge.test.ts +16 -0
- package/tests/client-build.mjs +28 -0
- package/tests/controls.test.ts +59 -10
- package/tests/desktop.mjs +9 -0
- package/tests/fixtures/host.mjs +10 -1
- package/tests/fixtures/notification-probe/client.tsx +42 -0
- package/tests/fixtures/notification-probe/host.mjs +28 -0
- package/tests/helpers/installed-notifications.mjs +77 -0
- package/tests/helpers/installed-services.mjs +103 -0
- package/tests/helpers/native-pointer.mjs +47 -2
- package/tests/install.mjs +42 -0
- package/tests/model.test.ts +87 -2
- package/tests/notification-broker.test.ts +233 -0
- package/tests/notification-client.test.ts +162 -0
- package/tests/notification-contract.test.ts +62 -0
- package/tests/notification-host-contract.mjs +66 -0
- package/tests/notification-integration.test.ts +168 -0
- package/tests/notification-ui.mjs +121 -0
- package/tests/plugin.test.ts +23 -6
- package/tests/presentation.test.js +21 -0
- package/tests/release-checks.mjs +37 -0
- package/web/index.html +10 -0
- package/web/notification-ui.js +53 -0
- package/web/pet.js +117 -16
- package/web/style.css +19 -0
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
给 [DeepSeek Harness Desktop](https://github.com/deepseek-ai/deepseek-harness) 加一只桌面伙伴。她会陪你工作,在任务完成、出错或需要确认时提醒你;双击角色,可以向已打开的 Harness 会话发送消息。
|
|
4
4
|
|
|
5
|
-
**v0.4.
|
|
5
|
+
**v0.4.5 使用 Coopanion 的原生动画与角色运行时,组合程序采用 AGPL-3.0-or-later。** 大肥鱼的网格变形、弹簧动作、动态五官、物理拖拽和八套配色直接复用上游固定版本。角色贴图保留独立权利声明,见 [第三方声明](THIRD_PARTY_NOTICES.md) 和 [上游版本记录](web/upstream/UPSTREAM.md)。
|
|
6
6
|
|
|
7
7
|
## 功能
|
|
8
8
|
|
|
@@ -11,9 +11,11 @@
|
|
|
11
11
|
- 最终回复使用描边气泡,短预览在最多约 3 秒内显示;可立即显示、展开完整阅读和返回源会话。嘴部同步与合成音效可关闭,不是 TTS。
|
|
12
12
|
- `figure.json` API 2 ZIP 角色包导入、动画预览、配色 / 多轴换装、切换、删除;角色和搭配在重启后保留。
|
|
13
13
|
- 透明、无边框、置顶桌宠;空白区域点击穿透。点击互动、双击聊天、右键菜单、闲时活动、休息和显示 / 隐藏。
|
|
14
|
-
-
|
|
14
|
+
- 角色周围不显示常驻操作按钮或名称标签;有未读回复、待处理审批 / 提问或异常时出现小信封。聊天面板中点击当前会话可切换对话。
|
|
15
15
|
- Harness 原生 **Settings → 桌宠** 页面:运行状态、启动 / 重启 / 关闭、显示 / 隐藏、角色管理及实时保存的偏好设置。
|
|
16
|
-
- 实时思考 / 生成 /
|
|
16
|
+
- 实时思考 / 生成 / 工具工作动画;完成、审批、AI 提问、出错和各类停止通过角色表情与互动提示呈现。流式片段驱动嘴部,最终回复独立进入阅读气泡;完成表情约 2.5 秒后回到待机。
|
|
17
|
+
- 角色显示时由角色提醒;运行中隐藏角色时,可由 Harness 发送系统通知并点击返回源会话。系统通知默认关闭,设置页提供权限申请、测试通知和送达回执。
|
|
18
|
+
- 审批与 AI 提问的待处理列表、默认 10 分钟后的一次自动补提醒及“稍后提醒”;同一会话同时到期的请求合并提示。
|
|
17
19
|
- 会话以真实提问、项目路径、时间和有效短编号区分,支持搜索及键盘切换;旧会话从公开历史恢复提问。
|
|
18
20
|
- 菜单与聊天使用角色风格的描边卡片,颜色跟随换装;摸头、叫醒、拖拽等互动使用上游身体事件。
|
|
19
21
|
- macOS 状态栏采用随系统明暗变化的角色模板图标与状态小图形,不显示状态文字;悬停和菜单保留会话、任务、未读及设置详情,与桌面共用状态判断和持久偏好。
|
|
@@ -24,7 +26,7 @@
|
|
|
24
26
|
|
|
25
27
|
后台最终回复进入未读列表,确认 / 异常优先排序;点击会话可读回复或回到 Harness 处理。正在阅读的回复不会被新结果替换,阅读器可前后翻看同一会话的结果。保留本次 Harness 运行内最近 200 份完整结果,优先淘汰已读;重启后原始对话仍由 Harness 保存。
|
|
26
28
|
|
|
27
|
-
|
|
29
|
+
回复气泡展示或自动收起不会标记已读;主动展开阅读、关闭回复或通过该回复回到源会话时,才确认这一份结果。审批与 AI 提问由 Harness 的实际答复、决定或取消结果结算;查看、收起互动提示或打开源会话均不会代替处理请求。
|
|
28
30
|
|
|
29
31
|
高频流式事件仅发送动画元数据,完整结果只在结果列表或已读状态变化时传输,避免长回复和多会话拖慢桌面更新。
|
|
30
32
|
|
|
@@ -40,7 +42,7 @@ v0.4.0 移除了旧 Canvas 关键帧引擎、`dsh-character` v1 协议、`.dshpe
|
|
|
40
42
|
|
|
41
43
|
支持 **DSH 0.2.0-rc.2 和 0.2.1-alpha.1**;其他版本未声明兼容。
|
|
42
44
|
|
|
43
|
-
1. 下载对应 [Release](https://github.com/takboo/dsh-coopanion/releases) 的 `dsh-coopanion-0.4.
|
|
45
|
+
1. 下载对应 [Release](https://github.com/takboo/dsh-coopanion/releases) 的 `dsh-coopanion-0.4.5.tgz`,或按下面步骤构建 `takboo-dsh-coopanion-0.4.5.tgz`。npm 包名为 `@takboo/dsh-coopanion`;本地 `npm pack` 的文件名包含 scope。
|
|
44
46
|
2. 在 Harness 侧边栏 **插件** 页安装压缩包的绝对路径,启用 `dsh-coopanion`。
|
|
45
47
|
3. 完全退出再重新打开 Harness。首次启动时会下载并校验 Electron 44 运行时。
|
|
46
48
|
4. 打开一段 Harness 会话,双击角色聊天,或从 **Settings → 桌宠** 管理角色。
|
|
@@ -48,13 +50,15 @@ v0.4.0 移除了旧 Canvas 关键帧引擎、`dsh-character` v1 协议、`.dshpe
|
|
|
48
50
|
也可使用 Desktop 自带的 CLI。先启动 Desktop 一次初始化 profile,完全退出应用,再执行:
|
|
49
51
|
|
|
50
52
|
```bash
|
|
51
|
-
dsh plugin --profile desktop add /absolute/path/dsh-coopanion-0.4.
|
|
53
|
+
dsh plugin --profile desktop add /absolute/path/dsh-coopanion-0.4.5.tgz
|
|
52
54
|
```
|
|
53
55
|
|
|
54
56
|
npm 安装的 dsh 不能管理 Desktop 所拥有的 profile。Desktop 完全退出后执行包管理命令,再重新打开应用。
|
|
55
57
|
|
|
56
58
|
## 开发与验证
|
|
57
59
|
|
|
60
|
+
通知阶段及交付状态见 [通知执行计划](docs/notification-plan.md),本轮集成验收范围见 [N3 验收记录](docs/notification-n3.md)。
|
|
61
|
+
|
|
58
62
|
开发工具链固定 Node.js 24.21.0 和 npm 11.19.1。Electron 支持 Windows、macOS、Linux;Linux 的窗口测试需要 X11 / XWayland 或 Xvfb,以及 Python 3 和 libX11,用于同步原生鼠标位置。原生网格需要 Chromium 的 WebGL 支持。
|
|
59
63
|
|
|
60
64
|
```bash
|
|
@@ -66,6 +70,7 @@ npm test
|
|
|
66
70
|
npm run build
|
|
67
71
|
npm run character:pack -- examples/star paper-star.zip
|
|
68
72
|
npm run test:ui
|
|
73
|
+
npm run test:notification-ui
|
|
69
74
|
npm run test:desktop
|
|
70
75
|
npm pack
|
|
71
76
|
node scripts/check-package.mjs
|
|
@@ -78,7 +83,7 @@ npm run test:install
|
|
|
78
83
|
|
|
79
84
|
浏览器测试检查实际 WebGL 动画、逐字说话与嘴部同步、拖拽 / 落地、会话、聊天、换装、包导入、重启保存及脚本隔离。桌面测试验证真实 Electron 窗口、IPC、流式动画、最终回复与完整阅读、休息唤醒、实际状态栏图标和角色数据;CI 同时运行 Linux、macOS、Windows 原生窗口测试。安装测试使用官方 DSH profile loader 安装实际 `.tgz`,检查任务事件、会话导航、设置页、配置持久化和重启;`DSH_TEST_VERSION=0.2.1-alpha.1` 测试另一支持版本。
|
|
80
85
|
|
|
81
|
-
|
|
86
|
+
CI 窗口测试使用隔离数据和测试沙箱参数;Linux 在虚拟显示中运行。普通安装保留 Chromium sandbox、contextIsolation,关闭 Node integration。安装测试中的通知适配器、原生可见性及答复器为受控边界;完整系统实机验收和外部真实模型会话尚未验证。
|
|
82
87
|
|
|
83
88
|
## 新角色
|
|
84
89
|
|
|
@@ -94,7 +99,7 @@ npm run character:pack -- examples/star paper-star.zip
|
|
|
94
99
|
|
|
95
100
|
## 配置与会话
|
|
96
101
|
|
|
97
|
-
**Settings → 桌宠** 沿用 Harness 的主题、中英文与系统语言设置。可控制随 Harness
|
|
102
|
+
**Settings → 桌宠** 沿用 Harness 的主题、中英文与系统语言设置。可控制随 Harness 启动、闲时活动、任务通知、系统通知、待处理请求补提醒、等待时间、角色尺寸(90–240)和气泡时长(2–60 秒);数值按 Enter 或离开输入框保存。
|
|
98
103
|
|
|
99
104
|
```yaml
|
|
100
105
|
- id: dsh-coopanion
|
|
@@ -103,13 +108,26 @@ npm run character:pack -- examples/star paper-star.zip
|
|
|
103
108
|
size: 180
|
|
104
109
|
roam: true
|
|
105
110
|
notifications: true
|
|
111
|
+
systemNotifications: false
|
|
112
|
+
reminders: true
|
|
113
|
+
reminderDelayMs: 600000
|
|
106
114
|
bubbleDurationMs: 12000
|
|
107
115
|
# electronPath: /absolute/path/to/electron
|
|
108
116
|
```
|
|
109
117
|
|
|
110
|
-
|
|
118
|
+
最终回复气泡与事件互动提示分别显示。回复气泡时长从逐字显示完成后计时,鼠标停留或键盘聚焦时暂停收起;互动提示收起后,未处理的审批和提问仍保留在小信封列表。超过 180 字的回复展示按句子截取的开头(不做模型摘要),可展开完整阅读;原文保留且不截断,完整阅读器不会自动关闭。减少动态效果时禁用闲时活动与逐字显示,保留直接拖动及落地。
|
|
119
|
+
|
|
120
|
+
桌宠仅展示已加载的顶层会话,忽略子代理;首次可用会话成为当前对话,之后保持用户选中的关注会话。未加载的历史会话需先在 Harness 中打开。桌面版通过公开的 `dsh://open` 协议唤回 Harness。多个本机客户端同时连接时,返回请求由首先领取的客户端处理。
|
|
121
|
+
|
|
122
|
+
## 提醒与系统通知
|
|
123
|
+
|
|
124
|
+
开启任务通知后,角色显示时用动作、表情和互动提示提醒;输入、阅读或拖拽期间先排队,结束后再呈现。最终回复与未读列表独立保留。审批/提问可预览内容、返回源会话或选择“稍后提醒”;限时提问标记“仍可回答”时,回合结束后仍可处理。
|
|
125
|
+
|
|
126
|
+
补提醒默认开启,等待时间可设为 1–1440 分钟。新的待处理请求自动补提醒一次;“稍后提醒”按当前等待时间重新计时。处理、取消或销毁会话后撤销该请求的计时。历史恢复保留待处理入口,不重放旧提醒。关闭任务通知会停止主动提醒,保留会话状态和未读回复。
|
|
127
|
+
|
|
128
|
+
系统通知默认关闭。在 **Settings → 桌宠 → 提醒与通知** 开启后,点击 **申请/刷新权限**,隐藏运行中的角色,再发送 **测试系统通知**。Desktop 使用 DeepSeek Harness 的应用身份,本机 `dsh web` 使用浏览器身份;点击通知请求打开源会话。角色关闭、启动中、失败或锁屏/休眠期间暂停主动投递。
|
|
111
129
|
|
|
112
|
-
|
|
130
|
+
网页权限“允许”、已请求和收到显示回执分别表示不同步骤;系统送达需在通知中心核对,并点击检查源会话。macOS 在 **系统设置 → 通知 → DeepSeek Harness** 管理授权;Windows 在 **设置 → 系统 → 通知**,Linux 在桌面通知设置中管理。权限或客户端不可用时,待处理入口仍保留;恢复显示不会补发旧系统通知。
|
|
113
131
|
|
|
114
132
|
## CI 与发布
|
|
115
133
|
|
package/desktop/main.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { app, BrowserWindow, ipcMain,
|
|
1
|
+
const { app, BrowserWindow, ipcMain, powerMonitor, screen, Menu, Tray, nativeImage, shell } = require('electron');
|
|
2
2
|
const { join } = require('node:path');
|
|
3
3
|
const { randomBytes } = require('node:crypto');
|
|
4
4
|
const { once } = require('node:events');
|
|
@@ -24,12 +24,16 @@ if (process.env.DSH_PET_TEST_DEBUG_PORT) {
|
|
|
24
24
|
let win, tray, options, lastFrame, poll, assetServer, characters;
|
|
25
25
|
let presentation = {}, lastTrayKey, lastIconKey, iconBase, iconAppearance;
|
|
26
26
|
let interactive = null;
|
|
27
|
-
const
|
|
27
|
+
const generation = Number(process.env.DSH_PET_GENERATION ?? 1);
|
|
28
|
+
let visibilityRevision = 0, suspended = false, screenLocked = false, systemAsleep = false;
|
|
29
|
+
function visibility() { if (win && !win.isDestroyed()) { process.send?.({ type: 'visibility', generation, visibilityRevision: ++visibilityRevision, visible: win.isVisible(), suspended }); syncTray(); } }
|
|
28
30
|
function forward(message) { if (win && !win.isDestroyed()) win.webContents.send('pet:update', message); }
|
|
29
31
|
function hit(active) {
|
|
30
|
-
if (!win || win.isDestroyed()
|
|
31
|
-
interactive
|
|
32
|
-
|
|
32
|
+
if (!win || win.isDestroyed()) return;
|
|
33
|
+
if (active !== interactive) {
|
|
34
|
+
interactive = active;
|
|
35
|
+
win.setIgnoreMouseEvents(!active, { forward: true });
|
|
36
|
+
}
|
|
33
37
|
forward({ type: 'hit-state', active, focused: win.isFocused(), visible: win.isVisible() });
|
|
34
38
|
}
|
|
35
39
|
function show() { win?.showInactive(); syncTray(); }
|
|
@@ -108,15 +112,10 @@ process.on('message', message => {
|
|
|
108
112
|
if (message.command === 'focus-harness' && process.env.DSH_PET_TEST_NO_SANDBOX !== '1') void shell.openExternal('dsh://open').catch(() => {});
|
|
109
113
|
}
|
|
110
114
|
if (message.type === 'snapshot') { lastFrame = { type: 'init', options, snapshot: { ...message.snapshot, results: message.snapshot.results ?? lastFrame?.snapshot?.results ?? [] } }; forward(message); syncTray(); }
|
|
115
|
+
if (message.type === 'notification-state' || message.type === 'notification-snooze-result') forward(message);
|
|
111
116
|
if (message.type === 'notice') {
|
|
117
|
+
if (message.generation !== undefined && (message.generation !== generation || message.visibilityRevision !== visibilityRevision || !win?.isVisible() || suspended)) return;
|
|
112
118
|
forward(message);
|
|
113
|
-
if (options?.notifications && Notification.isSupported()) {
|
|
114
|
-
const notice = new Notification({ title: message.notice.title, body: message.notice.body, silent: true });
|
|
115
|
-
notices.add(notice);
|
|
116
|
-
notice.on('close', () => notices.delete(notice));
|
|
117
|
-
notice.on('click', () => { process.send?.({ type: 'action', action: { type: 'open-session', sessionId: message.notice.sessionId } }); });
|
|
118
|
-
notice.show();
|
|
119
|
-
}
|
|
120
119
|
}
|
|
121
120
|
});
|
|
122
121
|
process.on('disconnect', () => app.quit());
|
|
@@ -152,8 +151,12 @@ app.whenReady().then(async () => {
|
|
|
152
151
|
});
|
|
153
152
|
win = new BrowserWindow({ ...screen.getPrimaryDisplay().workArea, transparent: true, frame: false, resizable: false, skipTaskbar: true, hasShadow: false, show: false, alwaysOnTop: true, backgroundColor: '#00000000', webPreferences: { preload: join(__dirname, 'preload.cjs'), sandbox: true, contextIsolation: true, nodeIntegration: false } });
|
|
154
153
|
win.setAlwaysOnTop(true, 'floating');
|
|
155
|
-
const visibility = () => { process.send?.({ type: 'visibility', visible: win.isVisible() }); syncTray(); };
|
|
156
154
|
win.on('show', visibility); win.on('hide', visibility);
|
|
155
|
+
const suspendState = () => { suspended = screenLocked || systemAsleep; visibility(); };
|
|
156
|
+
powerMonitor.on('suspend', () => { systemAsleep = true; suspendState(); });
|
|
157
|
+
powerMonitor.on('resume', () => { systemAsleep = false; suspendState(); });
|
|
158
|
+
powerMonitor.on('lock-screen', () => { screenLocked = true; suspendState(); });
|
|
159
|
+
powerMonitor.on('unlock-screen', () => { screenLocked = false; suspendState(); });
|
|
157
160
|
win.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true });
|
|
158
161
|
if (process.platform === 'darwin') app.dock?.hide();
|
|
159
162
|
win.webContents.setWindowOpenHandler(() => ({ action: 'deny' }));
|
|
@@ -169,6 +172,7 @@ app.whenReady().then(async () => {
|
|
|
169
172
|
if (typeof action.characterId !== 'string' || !/^[a-z0-9-]{1,32}$/.test(action.characterId) || typeof action.scheme !== 'string' || action.scheme.length > 200 || typeof action.name !== 'string' || action.name.length > 200 || typeof action.sleeping !== 'boolean' || typeof action.sound !== 'boolean') return;
|
|
170
173
|
presentation = { characterId: action.characterId, scheme: action.scheme, name: action.name, sleeping: action.sleeping, sound: action.sound, ready: action.ready === true }; syncTray(); return;
|
|
171
174
|
}
|
|
175
|
+
if (action.type === 'notification-snooze') { if (typeof action.interactionId === 'string' && action.interactionId.length <= 2048 && Number.isSafeInteger(action.generation)) act(action); return; }
|
|
172
176
|
if (action.type !== 'chat' && action.type !== 'select' && action.type !== 'open-session' && action.type !== 'preference' && action.type !== 'read') return;
|
|
173
177
|
process.send?.({ type: 'action', action });
|
|
174
178
|
});
|
|
@@ -194,5 +198,5 @@ app.whenReady().then(async () => {
|
|
|
194
198
|
process.send?.({ type: 'ready' });
|
|
195
199
|
}).catch(error => { console.error(error); app.exit(1); });
|
|
196
200
|
|
|
197
|
-
app.on('before-quit', () => { clearInterval(poll); assetServer?.close();
|
|
201
|
+
app.on('before-quit', () => { clearInterval(poll); assetServer?.close(); tray?.destroy(); });
|
|
198
202
|
app.on('window-all-closed', () => app.quit());
|
package/dist/bridge.js
CHANGED
|
@@ -8,63 +8,86 @@ var ElectronBridge = class extends EventEmitter {
|
|
|
8
8
|
latest;
|
|
9
9
|
resultKey;
|
|
10
10
|
closing = false;
|
|
11
|
-
|
|
11
|
+
generation = 0;
|
|
12
|
+
visibilityRevision = 0;
|
|
13
|
+
nativeVisible = false;
|
|
14
|
+
suspended = false;
|
|
15
|
+
lastNotificationState;
|
|
16
|
+
async start(options, lifetime) {
|
|
12
17
|
if (this.child) throw new Error("Desktop pet is already running");
|
|
18
|
+
if (lifetime?.signal.aborted) throw new Error("\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88");
|
|
13
19
|
this.closing = false;
|
|
14
|
-
|
|
20
|
+
this.generation = lifetime?.generation ?? this.generation + 1;
|
|
21
|
+
this.visibilityRevision = 0;
|
|
22
|
+
this.nativeVisible = false;
|
|
23
|
+
this.suspended = false;
|
|
24
|
+
if (process.platform === "linux" && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY) throw new Error("\u684C\u5BA0\u9700\u8981\u684C\u9762\u663E\u793A\u73AF\u5883\u3002");
|
|
15
25
|
const executable = options.electronPath ?? createRequire(import.meta.url)("electron");
|
|
16
|
-
const env = { ...process.env };
|
|
26
|
+
const env = { ...process.env, DSH_PET_GENERATION: String(this.generation) };
|
|
17
27
|
delete env.ELECTRON_RUN_AS_NODE;
|
|
18
28
|
const args = [fileURLToPath(new URL("../desktop/main.cjs", import.meta.url))];
|
|
19
29
|
if (env.DSH_PET_TEST_NO_SANDBOX === "1") args.unshift("--no-sandbox");
|
|
20
30
|
const child = spawn(executable, args, { env, stdio: ["ignore", "pipe", "pipe", "ipc"] });
|
|
31
|
+
const generation = this.generation;
|
|
21
32
|
this.child = child;
|
|
22
33
|
let diagnostic = "";
|
|
23
34
|
child.stderr?.on("data", (data) => {
|
|
24
35
|
diagnostic = (diagnostic + data.toString()).slice(-4e3);
|
|
25
36
|
});
|
|
26
37
|
child.on("message", (message) => {
|
|
27
|
-
if (
|
|
28
|
-
if (
|
|
29
|
-
if (
|
|
30
|
-
if (
|
|
38
|
+
if (this.child !== child || !isRecord(message)) return;
|
|
39
|
+
if (message.type === "action") this.emit("action", message.action);
|
|
40
|
+
if (message.type === "tray-state") this.emit("tray-state", message.state);
|
|
41
|
+
if (message.type === "tray-icon") this.emit("tray-icon", message);
|
|
42
|
+
if (message.type === "visibility" && message.generation === generation && typeof message.visible === "boolean" && Number.isSafeInteger(message.visibilityRevision) && message.visibilityRevision > this.visibilityRevision) {
|
|
43
|
+
this.visibilityRevision = message.visibilityRevision;
|
|
44
|
+
this.nativeVisible = message.visible;
|
|
45
|
+
this.suspended = message.suspended === true;
|
|
46
|
+
this.emit("lifecycle", { running: true, visible: this.nativeVisible, generation, visibilityRevision: this.visibilityRevision, suspended: this.suspended });
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
child.once("exit", (code, signal) => {
|
|
50
|
+
if (this.child !== child) return;
|
|
51
|
+
this.child = void 0;
|
|
52
|
+
this.nativeVisible = false;
|
|
53
|
+
const error = !this.closing && (code !== 0 || signal) ? `\u684C\u5BA0\u8FDB\u7A0B\u5DF2\u9000\u51FA (${signal ?? code})` : void 0;
|
|
54
|
+
this.emit("lifecycle", { running: false, visible: false, generation, visibilityRevision: ++this.visibilityRevision, suspended: false, ...error ? { error } : {} });
|
|
55
|
+
if (error) this.emit("failure", new Error(error));
|
|
31
56
|
});
|
|
32
57
|
await new Promise((resolve, reject) => {
|
|
58
|
+
let done = false;
|
|
33
59
|
const finish = (error) => {
|
|
60
|
+
if (done) return;
|
|
61
|
+
done = true;
|
|
34
62
|
clearTimeout(timer);
|
|
35
63
|
child.off("message", ready);
|
|
36
64
|
child.off("error", failed);
|
|
37
65
|
child.off("exit", exited);
|
|
66
|
+
lifetime?.signal.removeEventListener("abort", aborted);
|
|
38
67
|
if (error) {
|
|
39
68
|
child.kill();
|
|
40
69
|
reject(error);
|
|
41
70
|
} else resolve();
|
|
42
71
|
};
|
|
43
72
|
const ready = (message) => {
|
|
44
|
-
if (isRecord(message) && message.type === "ready") {
|
|
73
|
+
if (isRecord(message) && message.type === "ready" && this.child === child && !lifetime?.signal.aborted) {
|
|
45
74
|
this.send({ type: "init", options, snapshot: this.latest && desktopSnapshot(this.latest, true) });
|
|
75
|
+
if (this.lastNotificationState) this.notificationState(this.lastNotificationState);
|
|
46
76
|
finish();
|
|
47
77
|
}
|
|
48
78
|
};
|
|
49
|
-
const failed = (error) =>
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
};
|
|
53
|
-
const exited = (code, signal) => {
|
|
54
|
-
this.child = void 0;
|
|
55
|
-
finish(new Error(`\u684C\u5BA0\u542F\u52A8\u5931\u8D25 (${signal ?? code}): ${diagnostic}`));
|
|
56
|
-
};
|
|
79
|
+
const failed = (error) => finish(error);
|
|
80
|
+
const exited = (code, signal) => finish(new Error(`\u684C\u5BA0\u542F\u52A8\u5931\u8D25 (${signal ?? code}): ${diagnostic}`));
|
|
81
|
+
const aborted = () => finish(new Error("\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88"));
|
|
57
82
|
const timer = setTimeout(() => finish(new Error(`\u684C\u5BA0\u672A\u80FD\u5728 20 \u79D2\u5185\u542F\u52A8: ${diagnostic}`)), 2e4);
|
|
58
83
|
child.on("message", ready);
|
|
59
84
|
child.once("error", failed);
|
|
60
85
|
child.once("exit", exited);
|
|
86
|
+
lifetime?.signal.addEventListener("abort", aborted, { once: true });
|
|
87
|
+
if (lifetime?.signal.aborted) aborted();
|
|
61
88
|
});
|
|
62
|
-
child.on("error", (error) =>
|
|
63
|
-
|
|
64
|
-
this.child = void 0;
|
|
65
|
-
const error = !this.closing && code !== 0 ? `\u684C\u5BA0\u8FDB\u7A0B\u5DF2\u9000\u51FA (${code})` : void 0;
|
|
66
|
-
this.emit("lifecycle", { running: false, visible: false, ...error ? { error } : {} });
|
|
67
|
-
if (error) this.emit("failure", new Error(error));
|
|
89
|
+
child.on("error", (error) => {
|
|
90
|
+
if (this.child === child && !this.closing) this.emit("failure", error);
|
|
68
91
|
});
|
|
69
92
|
}
|
|
70
93
|
update(snapshot) {
|
|
@@ -76,6 +99,18 @@ var ElectronBridge = class extends EventEmitter {
|
|
|
76
99
|
notify(notice) {
|
|
77
100
|
this.send({ type: "notice", notice });
|
|
78
101
|
}
|
|
102
|
+
notificationState(snapshot) {
|
|
103
|
+
this.lastNotificationState = structuredClone(snapshot);
|
|
104
|
+
this.send({ type: "notification-state", snapshot });
|
|
105
|
+
}
|
|
106
|
+
snoozeResult(interactionId, ok, error) {
|
|
107
|
+
this.send({ type: "notification-snooze-result", interactionId, ok, ...error ? { error: error.slice(0, 600) } : {} });
|
|
108
|
+
}
|
|
109
|
+
presentRole(notice, runtime) {
|
|
110
|
+
if (!this.child?.connected || this.closing || !this.nativeVisible || this.suspended || runtime.generation !== this.generation || runtime.visibilityRevision !== this.visibilityRevision || !runtime.visible) return false;
|
|
111
|
+
this.send({ type: "notice", notice, generation: runtime.generation, visibilityRevision: runtime.visibilityRevision });
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
79
114
|
onAction(listener) {
|
|
80
115
|
this.on("action", listener);
|
|
81
116
|
}
|
|
@@ -106,19 +141,27 @@ var ElectronBridge = class extends EventEmitter {
|
|
|
106
141
|
this.closing = true;
|
|
107
142
|
const child = this.child;
|
|
108
143
|
if (!child) return;
|
|
109
|
-
if (child.exitCode !== null || child.signalCode !== null) {
|
|
144
|
+
if (child.pid === void 0 || child.exitCode !== null || child.signalCode !== null) {
|
|
110
145
|
if (this.child === child) this.child = void 0;
|
|
111
146
|
return;
|
|
112
147
|
}
|
|
113
|
-
await new Promise((resolve) => {
|
|
148
|
+
await new Promise((resolve, reject) => {
|
|
149
|
+
let deadline;
|
|
114
150
|
const timer = setTimeout(() => {
|
|
115
151
|
child.kill("SIGKILL");
|
|
152
|
+
deadline = setTimeout(() => {
|
|
153
|
+
if (child.exitCode !== null || child.signalCode !== null) resolve();
|
|
154
|
+
else reject(new Error("\u684C\u5BA0\u8FDB\u7A0B\u672A\u786E\u8BA4\u9000\u51FA"));
|
|
155
|
+
}, 1e3);
|
|
116
156
|
}, 3e3);
|
|
117
157
|
child.once("exit", () => {
|
|
118
158
|
clearTimeout(timer);
|
|
159
|
+
clearTimeout(deadline);
|
|
119
160
|
resolve();
|
|
120
161
|
});
|
|
121
|
-
if (child.connected) child.send({ type: "quit" })
|
|
162
|
+
if (child.connected) child.send({ type: "quit" }, (error) => {
|
|
163
|
+
if (error) child.kill();
|
|
164
|
+
});
|
|
122
165
|
else child.kill();
|
|
123
166
|
});
|
|
124
167
|
if (this.child === child) this.child = void 0;
|
package/dist/bridge.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/bridge.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 { PetSnapshot, PetNotice } from './model.ts';\n\nexport interface DesktopOptions { size: number; roam: boolean; notifications: boolean; bubbleDurationMs: number; electronPath?: string; }\nexport interface PetBridge {\n start(options: DesktopOptions): Promise<void>;\n update(snapshot: PetSnapshot): void;\n notify(notice: PetNotice): void;\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: { running: boolean; visible: boolean; error?: string }) => void): void;\n removeLifecycle?(listener: (state: { running: boolean; visible: boolean; error?: string }) => 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 resultKey?: string;\n private closing = false;\n\n async start(options: DesktopOptions): Promise<void> {\n if (this.child) throw new Error('Desktop pet is already running');\n this.closing = false;\n if (process.platform === 'linux' && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY) throw new Error('\u684C\u5BA0\u9700\u8981\u684C\u9762\u663E\u793A\u73AF\u5883\u3002\u65E0\u684C\u9762\u7684\u4E91\u73AF\u5883\u53EF\u8FD0\u884C npm run dev \u9884\u89C8\uFF0C\u6216\u7528 Xvfb \u8FD0\u884C\u684C\u9762\u6D4B\u8BD5\u3002');\n const executable: string = options.electronPath ?? createRequire(import.meta.url)('electron');\n const env = { ...process.env };\n // The Harness host runs Electron as Node; the pet needs a normal Electron GUI process.\n delete env.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 this.child = child;\n let diagnostic = '';\n child.stderr?.on('data', data => { diagnostic = (diagnostic + data.toString()).slice(-4000); });\n child.on('message', message => {\n if (isRecord(message) && message.type === 'action') this.emit('action', message.action);\n if (isRecord(message) && message.type === 'tray-state') this.emit('tray-state', message.state);\n if (isRecord(message) && message.type === 'tray-icon') this.emit('tray-icon', message);\n if (isRecord(message) && message.type === 'visibility' && typeof message.visible === 'boolean') this.emit('lifecycle', { running: true, visible: message.visible });\n });\n await new Promise<void>((resolve, reject) => {\n const finish = (error?: Error) => {\n clearTimeout(timer); child.off('message', ready); child.off('error', failed); child.off('exit', exited);\n if (error) { child.kill(); reject(error); } else resolve();\n };\n const ready = (message: unknown) => {\n if (isRecord(message) && message.type === 'ready') {\n this.send({ type: 'init', options, snapshot: this.latest && desktopSnapshot(this.latest, true) }); finish();\n }\n };\n const failed = (error: Error) => { this.child = undefined; finish(error); };\n const exited = (code: number | null, signal: string | null) => { this.child = undefined; finish(new Error(`\u684C\u5BA0\u542F\u52A8\u5931\u8D25 (${signal ?? code}): ${diagnostic}`)); };\n const timer = setTimeout(() => finish(new Error(`\u684C\u5BA0\u672A\u80FD\u5728 20 \u79D2\u5185\u542F\u52A8: ${diagnostic}`)), 20000);\n child.on('message', ready); child.once('error', failed); child.once('exit', exited);\n });\n child.on('error', error => this.emit('failure', error));\n child.once('exit', code => {\n this.child = undefined;\n const error = !this.closing && code !== 0 ? `\u684C\u5BA0\u8FDB\u7A0B\u5DF2\u9000\u51FA (${code})` : undefined;\n this.emit('lifecycle', { running: false, visible: false, ...(error ? { error } : {}) });\n if (error) this.emit('failure', new Error(error));\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): void { this.send({ type: 'notice', notice }); }\n onAction(listener: (action: unknown) => void): void { this.on('action', listener); }\n removeAction(listener: (action: unknown) => void): void { this.off('action', listener); }\n configure(options: DesktopOptions): void { this.send({ type: 'configure', options }); }\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: { running: boolean; visible: boolean; error?: string }) => void): void { this.on('lifecycle', listener); }\n removeLifecycle(listener: (state: { running: boolean; visible: boolean; error?: string }) => void): void { this.off('lifecycle', listener); }\n private send(message: object): void {\n if (this.child?.connected) this.child.send(message, error => { if (error && !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.exitCode !== null || child.signalCode !== null) { if (this.child === child) this.child = undefined; return; }\n await new Promise<void>(resolve => {\n const timer = setTimeout(() => { child.kill('SIGKILL'); }, 3000);\n child.once('exit', () => { clearTimeout(timer); resolve(); });\n if (child.connected) child.send({ type: 'quit' }); 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"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,aAAgC;AACzC,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,oBAAoB;
|
|
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 { PetSnapshot, PetNotice } from './model.ts';\nimport type { NotificationRuntime, NotificationSnapshot, TaskNotice } from './notification-contract.ts';\n\nexport interface StartLifetime { signal: AbortSignal; generation: number; }\nexport interface NativeLifecycle { running: boolean; visible: boolean; error?: string; generation?: number; visibilityRevision?: number; suspended?: boolean; }\n\nexport interface DesktopOptions { size: number; roam: boolean; 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 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 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 lastNotificationState?: NotificationSnapshot;\n\n async start(options: DesktopOptions, lifetime?: StartLifetime): Promise<void> {\n if (this.child) throw new Error('Desktop pet is already running');\n if (lifetime?.signal.aborted) throw new Error('\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88');\n this.closing = false;\n this.generation = lifetime?.generation ?? this.generation + 1;\n this.visibilityRevision = 0; this.nativeVisible = false; this.suspended = false;\n if (process.platform === 'linux' && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY) throw new Error('\u684C\u5BA0\u9700\u8981\u684C\u9762\u663E\u793A\u73AF\u5883\u3002');\n const executable: string = options.electronPath ?? createRequire(import.meta.url)('electron');\n const env: NodeJS.ProcessEnv = { ...process.env, DSH_PET_GENERATION: String(this.generation) };\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 = '';\n child.stderr?.on('data', data => { diagnostic = (diagnostic + data.toString()).slice(-4000); });\n child.on('message', message => {\n if (this.child !== child || !isRecord(message)) return;\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 this.emit('lifecycle', { running: true, visible: this.nativeVisible, generation, visibilityRevision: this.visibilityRevision, suspended: this.suspended });\n }\n });\n child.once('exit', (code, signal) => {\n if (this.child !== child) return;\n this.child = undefined; this.nativeVisible = false;\n const error = !this.closing && (code !== 0 || signal) ? `\u684C\u5BA0\u8FDB\u7A0B\u5DF2\u9000\u51FA (${signal ?? code})` : undefined;\n this.emit('lifecycle', { running: false, visible: false, generation, visibilityRevision: ++this.visibilityRevision, suspended: false, ...(error ? { error } : {}) });\n if (error) this.emit('failure', new Error(error));\n });\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 === 'ready' && this.child === child && !lifetime?.signal.aborted) {\n this.send({ type: 'init', options, snapshot: this.latest && desktopSnapshot(this.latest, true) });\n if (this.lastNotificationState) this.notificationState(this.lastNotificationState);\n finish();\n }\n };\n const failed = (error: Error) => finish(error);\n const exited = (code: number | null, signal: string | null) => finish(new Error(`\u684C\u5BA0\u542F\u52A8\u5931\u8D25 (${signal ?? code}): ${diagnostic}`));\n const aborted = () => finish(new Error('\u684C\u5BA0\u542F\u52A8\u5DF2\u53D6\u6D88'));\n const timer = setTimeout(() => finish(new Error(`\u684C\u5BA0\u672A\u80FD\u5728 20 \u79D2\u5185\u542F\u52A8: ${diagnostic}`)), 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 child.on('error', error => { if (this.child === child && !this.closing) this.emit('failure', error); });\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 onAction(listener: (action: unknown) => void): void { this.on('action', listener); }\n removeAction(listener: (action: unknown) => void): void { this.off('action', listener); }\n configure(options: DesktopOptions): void { this.send({ type: 'configure', options }); }\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 if (this.child?.connected) this.child.send(message, error => { if (error && !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"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,aAAgC;AACzC,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,oBAAoB;AA0BtB,IAAM,iBAAN,cAA6B,aAAkC;AAAA,EAC5D;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAU;AAAA,EAEV,aAAa;AAAA,EACb,qBAAqB;AAAA,EACrB,gBAAgB;AAAA,EAChB,YAAY;AAAA,EACZ;AAAA,EAER,MAAM,MAAM,SAAyB,UAAyC;AAC5E,QAAI,KAAK,MAAO,OAAM,IAAI,MAAM,gCAAgC;AAChE,QAAI,UAAU,OAAO,QAAS,OAAM,IAAI,MAAM,4CAAS;AACvD,SAAK,UAAU;AACf,SAAK,aAAa,UAAU,cAAc,KAAK,aAAa;AAC5D,SAAK,qBAAqB;AAAG,SAAK,gBAAgB;AAAO,SAAK,YAAY;AAC1E,QAAI,QAAQ,aAAa,WAAW,CAAC,QAAQ,IAAI,WAAW,CAAC,QAAQ,IAAI,gBAAiB,OAAM,IAAI,MAAM,oEAAa;AACvH,UAAM,aAAqB,QA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