dsh-meow-notifier 1.1.0 → 1.3.0
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/LICENSE +20 -20
- package/README.md +53 -22
- package/client.js +178 -36
- package/cordis.patch.yml +2 -2
- package/host.js +315 -54
- package/locale/en.json +2 -2
- package/locale/zh.json +2 -2
- package/package.json +10 -6
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Oliver-314
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Oliver-314
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
# dsh-meow-notifier
|
|
2
2
|
|
|
3
|
-
[](https://github.com/Oliver-314/dsh-meow-notifier/actions/workflows/test.yml)
|
|
4
4
|
[](https://www.npmjs.com/package/dsh-meow-notifier)
|
|
5
|
-
[](https://github.com/Oliver-314/dsh-
|
|
5
|
+
[](https://github.com/Oliver-314/dsh-meow-notifier/blob/main/LICENSE)
|
|
6
6
|
|
|
7
|
-
把 DeepSeek Harness
|
|
7
|
+
把 DeepSeek Harness 的关键状态推送到手机,离开电脑时也能收到项目的最新消息。支持 [MeoW](https://www.chuckfang.com/MeoW/api_doc.html)、[Bark](https://bark.day.app)(iOS)和 [ntfy](https://docs.ntfy.sh/publish/)(Android / 跨平台),**填写多个渠道会同时发送**。
|
|
8
8
|
|
|
9
9
|
- **任务完成 / 出错 / 中止**:一轮工作结束、Agent 回到空闲时发送。
|
|
10
10
|
- **等待你确认**:工具调用需要批准且等待超过 2 秒时发送(自动批准或秒答不会打扰)。
|
|
11
11
|
- **AI 向你提问**:`ask_user_question` 等待回答时发送。
|
|
12
12
|
- 插件挂在 profile 层,**所有工作区、所有会话**(含新开会话)都生效。
|
|
13
13
|
|
|
14
|
+
## 推送渠道
|
|
15
|
+
|
|
16
|
+
| 渠道 | 平台 | 需要填写 | 可选 |
|
|
17
|
+
|---|---|---|---|
|
|
18
|
+
| MeoW | 国内可用 | 昵称 | 通知分类 |
|
|
19
|
+
| Bark | iOS | 设备 key | 自建服务器地址 |
|
|
20
|
+
| ntfy | Android / 跨平台 | 主题 | 自建服务器地址、访问令牌 |
|
|
21
|
+
|
|
22
|
+
只填一个渠道也能用;填几个就向几个渠道发送。某个渠道失败不会影响其他渠道,设置页会逐个显示结果。
|
|
23
|
+
|
|
14
24
|
## 安装
|
|
15
25
|
|
|
16
26
|
要求:DeepSeek Harness 0.2.x,Node 22+。
|
|
@@ -24,18 +34,22 @@ dsh plugin add dsh-meow-notifier
|
|
|
24
34
|
从源码安装(本地目录会被链接,修改后需重启 Harness 加载 Host 代码):
|
|
25
35
|
|
|
26
36
|
```bash
|
|
27
|
-
git clone https://github.com/Oliver-314/dsh-
|
|
28
|
-
dsh plugin add ./dsh-
|
|
37
|
+
git clone https://github.com/Oliver-314/dsh-meow-notifier.git
|
|
38
|
+
dsh plugin add ./dsh-meow-notifier
|
|
29
39
|
```
|
|
30
40
|
|
|
31
|
-
也可以在 Web 界面的 **插件(Plugins) → Add plugin** 里填包名或本地目录,安装后启用
|
|
41
|
+
也可以在 Web 界面的 **插件(Plugins) → Add plugin** 里填包名或本地目录,安装后启用 **推送通知(Push Notifications)**。
|
|
32
42
|
|
|
33
43
|
## 配置
|
|
34
44
|
|
|
35
|
-
1. 打开侧边栏 **插件(Plugins) → Installed plugins →
|
|
36
|
-
2.
|
|
37
|
-
|
|
38
|
-
|
|
45
|
+
1. 打开侧边栏 **插件(Plugins) → Installed plugins → 推送通知**。
|
|
46
|
+
2. 按需填写推送渠道:
|
|
47
|
+
- **MeoW**:MeoW App 里注册的昵称。昵称需完全一致,多次输错可能导致 IP 被封禁。
|
|
48
|
+
- **Bark(iOS)**:Bark App 里的设备 key。也可以直接粘贴 App 显示的 `https://api.day.app/<key>`,会自动识别。
|
|
49
|
+
- **ntfy(Android / 跨平台)**:在 ntfy App 里订阅的主题名。主题相当于密码,请使用不易猜到的随机名字;受保护的主题再填访问令牌(`tk_...`)。
|
|
50
|
+
3. 可选:修改通知分类(最多 10 个字,Bark 用它作为通知分组)、三类通知开关和消息格式。
|
|
51
|
+
4. 点 **保存**,再点 **发送测试通知** 确认手机能收到;会向所有已填写的渠道发送。
|
|
52
|
+
5. 页面底部会显示“最近一次通知”的逐渠道结果,便于排查。
|
|
39
53
|
|
|
40
54
|
### 消息格式
|
|
41
55
|
|
|
@@ -49,7 +63,7 @@ dsh plugin add ./dsh-MeoW-notifier
|
|
|
49
63
|
|
|
50
64
|
状态词包括:`已完成 / 出错 / 已中止 / 超出长度上限 / 被阻断 / 等待确认 / 需要回答`。精简版的摘要是本地取回复的第一句话,不调用模型,不产生额外费用。
|
|
51
65
|
|
|
52
|
-
设置保存在 `$DSH_HOME/meow-notify/state.json`(默认 `~/.dsh/meow-notify/state.json
|
|
66
|
+
设置保存在 `$DSH_HOME/meow-notify/state.json`(默认 `~/.dsh/meow-notify/state.json`),包含昵称、Bark 设备 key、ntfy 主题与令牌;除各渠道自身的接口外不会上传任何内容。
|
|
53
67
|
|
|
54
68
|
## 工作原理
|
|
55
69
|
|
|
@@ -57,19 +71,29 @@ dsh plugin add ./dsh-MeoW-notifier
|
|
|
57
71
|
|
|
58
72
|
| 部分 | 文件 | 职责 |
|
|
59
73
|
|---|---|---|
|
|
60
|
-
| Host 半 | `host.js` | 监听 `agent/status`、`approval/request`、`user-questions/request
|
|
74
|
+
| Host 半 | `host.js` | 监听 `agent/status`、`approval/request`、`user-questions/request`,组装消息并发送到各渠道;在 `/meow-notify/api/` 下提供设置读写和测试发送的路由 |
|
|
61
75
|
| 浏览器半 | `client.js` | 在插件页注册 `plugins.bundle.config`,渲染设置表单(React 来自浏览器模块表,样式使用 `--dsw-alias-*` 主题变量) |
|
|
62
76
|
|
|
63
77
|
Host 半是纯 ESM,浏览器半是 `window.__ModuleLoader__` 工厂格式,**没有构建步骤,也没有运行时依赖**。
|
|
64
78
|
|
|
65
|
-
发送队列串行执行:最小间隔 4.5
|
|
79
|
+
发送队列串行执行:最小间隔 4.5 秒,避免触发渠道限流;MeoW 另有每小时 60 条、每天 1000 条的上限。推送不是幂等操作,超时、断连或服务端错误都不自动重试。仅当 Harness 对外公布的地址不是 `127.0.0.1` / `localhost` 时,通知才附带打开链接。
|
|
80
|
+
|
|
81
|
+
各渠道的请求形状:
|
|
82
|
+
|
|
83
|
+
| 渠道 | 请求 | 成功判定 |
|
|
84
|
+
|---|---|---|
|
|
85
|
+
| MeoW | `POST https://api.chuckfang.com/<昵称>`,JSON `{title,msg,url?,category?}` | 业务 JSON 中 `status=200` 且 `data=true` |
|
|
86
|
+
| Bark | `POST <服务器>/push`,JSON `{device_key,title,body,group,level,url?}` | `code=200`;等待确认用 `timeSensitive` |
|
|
87
|
+
| ntfy | `POST <服务器>/`,JSON `{topic,title,message,priority,tags,click?}`,令牌走 `Authorization: Bearer` | 返回带 `id` 的 JSON;等待确认 priority 4,其余 3 |
|
|
66
88
|
|
|
67
89
|
## 已知限制
|
|
68
90
|
|
|
69
91
|
- MeoW 每天允许输错昵称 3 次,超过会封禁 IP 一天;昵称务必与 App 中完全一致。
|
|
70
92
|
- 尽量避免通过多人共享的公共出口 IP 发送:同一 IP 向多个昵称推送可能被判定为攻击流量。
|
|
93
|
+
- ntfy.sh 免费额度约为每天 250 条、每秒 1 次请求,且同一出口 IP 共享额度;量大时建议自建服务器。
|
|
94
|
+
- Bark 设备 key 和 ntfy 主题都相当于密码:拿到 key 的人可以向你推送,拿到主题的人可以订阅你的消息。不要把它们提交到仓库或发给他人。
|
|
71
95
|
- 当前会话审批策略为 `never` 时工具调用会被自动拒绝,不会产生“等待确认”提醒;需要把权限策略调到会询问的模式。
|
|
72
|
-
-
|
|
96
|
+
- 所有渠道都只发送纯文本,不支持 Markdown。
|
|
73
97
|
|
|
74
98
|
## 开发
|
|
75
99
|
|
|
@@ -82,27 +106,34 @@ npm test
|
|
|
82
106
|
或者分别运行:
|
|
83
107
|
|
|
84
108
|
```bash
|
|
85
|
-
node test/host.test.mjs
|
|
86
|
-
node test/style.test.mjs
|
|
87
|
-
node test/
|
|
109
|
+
node test/host.test.mjs # 事件、消息组装、限流、发送队列
|
|
110
|
+
node test/style.test.mjs # 三种消息格式的长度与内容
|
|
111
|
+
node test/channels.test.mjs # 多渠道分发、优先级与失败聚合
|
|
112
|
+
node test/client.test.mjs # 设置页渲染冒烟
|
|
88
113
|
```
|
|
89
114
|
|
|
90
115
|
修改 Host 代码后需要重启 Harness 才会加载新模块(Node ESM 缓存);浏览器半由客户端按文件变更刷新。
|
|
91
116
|
|
|
92
|
-
发布说明见 [RELEASING.md](https://github.com/Oliver-314/dsh-
|
|
117
|
+
发布说明见 [RELEASING.md](https://github.com/Oliver-314/dsh-meow-notifier/blob/main/RELEASING.md),贡献指南见 [CONTRIBUTING.md](https://github.com/Oliver-314/dsh-meow-notifier/blob/main/CONTRIBUTING.md),安全问题见 [SECURITY.md](https://github.com/Oliver-314/dsh-meow-notifier/blob/main/SECURITY.md)。
|
|
93
118
|
|
|
94
119
|
## English
|
|
95
120
|
|
|
96
|
-
Push DeepSeek Harness task completion, approval, and question alerts to your phone through MeoW.
|
|
121
|
+
Push DeepSeek Harness task completion, approval, and question alerts to your phone through MeoW, Bark (iOS), or ntfy (Android / cross-platform). Every configured channel receives each notification.
|
|
97
122
|
|
|
98
123
|
```bash
|
|
99
124
|
dsh plugin add dsh-meow-notifier
|
|
100
125
|
```
|
|
101
126
|
|
|
102
|
-
Open **Plugins →
|
|
127
|
+
Open **Plugins → Push Notifications** and fill in at least one channel:
|
|
128
|
+
|
|
129
|
+
- **MeoW**: the nickname registered in the MeoW app.
|
|
130
|
+
- **Bark**: the device key from the Bark app; a full `https://api.day.app/<key>` URL is accepted too.
|
|
131
|
+
- **ntfy**: the topic you subscribed to in the ntfy app. Topics act like passwords, so pick an unguessable name; add an access token for protected topics.
|
|
132
|
+
|
|
133
|
+
Save, then send a test notification. Completion messages carry the session title, project folder, and the last reply; approvals and questions wait 2 and 1.5 seconds so instant answers stay quiet.
|
|
103
134
|
|
|
104
|
-
Phone clients show roughly 180 characters, so the page offers three formats: **Full**, **Compact** (default, one sentence, ≤ 160 characters), and **Status only** (for example `已完成 · 重构登录页`). The summary is local text processing and never calls a model.
|
|
135
|
+
Phone clients show roughly 180 characters, so the page offers three formats: **Full**, **Compact** (default, one sentence, ≤ 160 characters), and **Status only** (for example `已完成 · 重构登录页`). The summary is local text processing and never calls a model. Pushes are spaced 4.5 seconds apart and capped at 60 per hour for MeoW; a failing channel never blocks the others.
|
|
105
136
|
|
|
106
137
|
## License
|
|
107
138
|
|
|
108
|
-
[MIT](https://github.com/Oliver-314/dsh-
|
|
139
|
+
[MIT](https://github.com/Oliver-314/dsh-meow-notifier/blob/main/LICENSE)
|
package/client.js
CHANGED
|
@@ -18,11 +18,30 @@ window.__ModuleLoader__.load({
|
|
|
18
18
|
const NS = 'meowNotify'
|
|
19
19
|
|
|
20
20
|
const zh = {
|
|
21
|
-
lead: 'AI 完成任务、等待你确认或需要你回答时,通过 MeoW
|
|
21
|
+
lead: 'AI 完成任务、等待你确认或需要你回答时,通过 MeoW / Bark / ntfy 推送到手机;填写多个渠道会同时发送。',
|
|
22
|
+
channels: '推送渠道',
|
|
23
|
+
meowName: 'MeoW',
|
|
24
|
+
meowHint: '国内可用的推送服务,按注册昵称发送。',
|
|
22
25
|
nickname: 'MeoW 昵称',
|
|
23
|
-
nicknameHint: '填写 MeoW App
|
|
26
|
+
nicknameHint: '填写 MeoW App 中注册的昵称;留空则不通过 MeoW 发送。昵称需完全一致,多次输错可能导致 IP 被封禁。',
|
|
24
27
|
category: '通知分类',
|
|
25
|
-
categoryHint: '可选,最多 10 个字,例如 DSH
|
|
28
|
+
categoryHint: '可选,最多 10 个字,例如 DSH;Bark 会用它作为通知分组。',
|
|
29
|
+
barkName: 'Bark(iOS)',
|
|
30
|
+
barkHint: '在 Bark App 中复制设备 key,也可以直接粘贴 App 里的推送 URL。',
|
|
31
|
+
barkKey: '设备 key',
|
|
32
|
+
barkKeyHint: '形如 https://api.day.app/xxxxxxxx 的地址也可以,会自动识别。',
|
|
33
|
+
barkServer: '服务器地址(可选)',
|
|
34
|
+
barkServerHint: '自建 Bark 服务器时填写,留空使用 https://api.day.app。',
|
|
35
|
+
ntfyName: 'ntfy(Android / 跨平台)',
|
|
36
|
+
ntfyHint: '在 ntfy App 中订阅一个主题,把主题名填在这里;主题相当于密码,请使用不易猜到的名字。',
|
|
37
|
+
ntfyTopic: '主题',
|
|
38
|
+
ntfyTopicHint: '也可以粘贴完整地址,例如 https://ntfy.sh/mytopic。',
|
|
39
|
+
ntfyServer: '服务器地址(可选)',
|
|
40
|
+
ntfyServerHint: '留空使用 https://ntfy.sh;也可以填写自建服务器。',
|
|
41
|
+
ntfyToken: '访问令牌(可选)',
|
|
42
|
+
ntfyTokenHint: '只有受保护的主题才需要,形如 tk_...;令牌只保存在本机。',
|
|
43
|
+
channelOn: '已填写',
|
|
44
|
+
channelOff: '未填写',
|
|
26
45
|
events: '通知时机',
|
|
27
46
|
done: '任务完成时',
|
|
28
47
|
doneHint: '一轮工作结束后发送,并附上最后一段回复。',
|
|
@@ -43,7 +62,7 @@ window.__ModuleLoader__.load({
|
|
|
43
62
|
test: '发送测试通知',
|
|
44
63
|
testing: '发送中…',
|
|
45
64
|
saved: '设置已保存。',
|
|
46
|
-
|
|
65
|
+
needChannel: '请至少填写一个推送渠道(MeoW / Bark / ntfy)。',
|
|
47
66
|
testSent: '测试通知已发送,请查看手机。',
|
|
48
67
|
testFailed: '发送失败:{error}',
|
|
49
68
|
saveFailed: '保存失败:{error}',
|
|
@@ -53,16 +72,35 @@ window.__ModuleLoader__.load({
|
|
|
53
72
|
lastSend: '最近一次通知:{text}',
|
|
54
73
|
lastOk: '发送成功',
|
|
55
74
|
lastFail: '失败({error})',
|
|
56
|
-
privacy: '
|
|
75
|
+
privacy: '昵称、设备 key 与令牌只保存在本机;通知分别通过各渠道的官方接口发送。',
|
|
57
76
|
dirty: '有未保存的修改',
|
|
58
77
|
}
|
|
59
78
|
|
|
60
79
|
const en = {
|
|
61
|
-
lead: 'When the AI finishes a task, waits for your approval, or needs an answer, MeoW pushes it to your phone.',
|
|
80
|
+
lead: 'When the AI finishes a task, waits for your approval, or needs an answer, MeoW, Bark, or ntfy pushes it to your phone. Every filled-in channel receives each notification.',
|
|
81
|
+
channels: 'Push channels',
|
|
82
|
+
meowName: 'MeoW',
|
|
83
|
+
meowHint: 'A push service reached by the nickname registered in its app.',
|
|
62
84
|
nickname: 'MeoW nickname',
|
|
63
|
-
nicknameHint: 'The nickname registered in the MeoW app. Leave it blank to
|
|
85
|
+
nicknameHint: 'The nickname registered in the MeoW app. Leave it blank to stop sending through MeoW. It must match exactly; repeated wrong nicknames can get this IP banned.',
|
|
64
86
|
category: 'Notification category',
|
|
65
|
-
categoryHint: 'Optional, up to 10 characters, for example DSH.',
|
|
87
|
+
categoryHint: 'Optional, up to 10 characters, for example DSH; Bark uses it as the notification group.',
|
|
88
|
+
barkName: 'Bark (iOS)',
|
|
89
|
+
barkHint: 'Copy the device key from the Bark app, or paste the push URL the app shows.',
|
|
90
|
+
barkKey: 'Device key',
|
|
91
|
+
barkKeyHint: 'A URL such as https://api.day.app/xxxxxxxx also works and is parsed automatically.',
|
|
92
|
+
barkServer: 'Server (optional)',
|
|
93
|
+
barkServerHint: 'Only for a self-hosted Bark server; leave blank for https://api.day.app.',
|
|
94
|
+
ntfyName: 'ntfy (Android / cross-platform)',
|
|
95
|
+
ntfyHint: 'Subscribe to a topic in the ntfy app and enter the topic name here. A topic works like a password, so pick an unguessable name.',
|
|
96
|
+
ntfyTopic: 'Topic',
|
|
97
|
+
ntfyTopicHint: 'You can also paste a full address such as https://ntfy.sh/mytopic.',
|
|
98
|
+
ntfyServer: 'Server (optional)',
|
|
99
|
+
ntfyServerHint: 'Leave blank for https://ntfy.sh, or enter a self-hosted server.',
|
|
100
|
+
ntfyToken: 'Access token (optional)',
|
|
101
|
+
ntfyTokenHint: 'Only needed for protected topics, usually tk_...; the token stays on this machine.',
|
|
102
|
+
channelOn: 'Configured',
|
|
103
|
+
channelOff: 'Empty',
|
|
66
104
|
events: 'When to notify',
|
|
67
105
|
done: 'Task finished',
|
|
68
106
|
doneHint: 'Sent when a run settles, with the last reply attached.',
|
|
@@ -83,7 +121,7 @@ window.__ModuleLoader__.load({
|
|
|
83
121
|
test: 'Send test notification',
|
|
84
122
|
testing: 'Sending…',
|
|
85
123
|
saved: 'Settings saved.',
|
|
86
|
-
|
|
124
|
+
needChannel: 'Fill in at least one channel (MeoW / Bark / ntfy).',
|
|
87
125
|
testSent: 'Test notification sent. Check your phone.',
|
|
88
126
|
testFailed: 'Send failed: {error}',
|
|
89
127
|
saveFailed: 'Save failed: {error}',
|
|
@@ -93,7 +131,7 @@ window.__ModuleLoader__.load({
|
|
|
93
131
|
lastSend: 'Last notification: {text}',
|
|
94
132
|
lastOk: 'delivered',
|
|
95
133
|
lastFail: 'failed ({error})',
|
|
96
|
-
privacy: 'The nickname
|
|
134
|
+
privacy: 'The nickname, device key, and tokens stay on this machine; notifications go through each channel’s official API.',
|
|
97
135
|
dirty: 'Unsaved changes',
|
|
98
136
|
}
|
|
99
137
|
|
|
@@ -119,6 +157,11 @@ window.__ModuleLoader__.load({
|
|
|
119
157
|
.meow-seg-btn[aria-pressed="true"]{background:var(--dsw-alias-brand-primary);color:#fff}
|
|
120
158
|
.meow-seg-btn:disabled{opacity:.5;cursor:default}
|
|
121
159
|
.meow-seg-hint{margin:0;font-size:12px;line-height:1.5;color:var(--dsw-alias-label-tertiary)}
|
|
160
|
+
.meow-channel{display:flex;flex-direction:column;gap:10px;padding:12px 14px;border:.5px solid var(--dsw-alias-border-l2);border-radius:10px;background:var(--dsw-alias-bg-layer-1)}
|
|
161
|
+
.meow-channel-head{display:flex;align-items:center;gap:8px}
|
|
162
|
+
.meow-channel-title{font-size:13px;font-weight:600;color:var(--dsw-alias-label-primary)}
|
|
163
|
+
.meow-badge{flex:none;font-size:11px;line-height:18px;padding:0 8px;border-radius:999px;border:.5px solid var(--dsw-alias-border-l2);color:var(--dsw-alias-label-tertiary)}
|
|
164
|
+
.meow-badge[data-on="true"]{color:var(--dsw-alias-state-success-primary);border-color:color-mix(in srgb,var(--dsw-alias-state-success-primary) 35%,transparent)}
|
|
122
165
|
.meow-actions{display:flex;align-items:center;gap:10px;margin-top:4px;flex-wrap:wrap}
|
|
123
166
|
.meow-primary{height:32px;padding:0 14px;border:none;border-radius:8px;background:var(--dsw-alias-brand-primary);color:#fff;font:inherit;font-size:13px;cursor:pointer}
|
|
124
167
|
.meow-secondary{height:32px;padding:0 14px;border:.5px solid var(--dsw-alias-border-l2);border-radius:8px;background:transparent;color:var(--dsw-alias-label-primary);font:inherit;font-size:13px;cursor:pointer}
|
|
@@ -169,6 +212,16 @@ window.__ModuleLoader__.load({
|
|
|
169
212
|
return body
|
|
170
213
|
}
|
|
171
214
|
|
|
215
|
+
/** Whether a channel field has any non-whitespace content. */
|
|
216
|
+
function filled(value) {
|
|
217
|
+
return String(value ?? '').trim() !== ''
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** Whether at least one push channel is configured. */
|
|
221
|
+
function anyChannel(state) {
|
|
222
|
+
return filled(state?.nickname) || filled(state?.barkKey) || filled(state?.ntfyTopic)
|
|
223
|
+
}
|
|
224
|
+
|
|
172
225
|
/** Keep the Host's own `t` where available and degrade to local copy. */
|
|
173
226
|
function createTranslator(ctx) {
|
|
174
227
|
let bound
|
|
@@ -223,6 +276,40 @@ window.__ModuleLoader__.load({
|
|
|
223
276
|
)
|
|
224
277
|
}
|
|
225
278
|
|
|
279
|
+
/** One labelled input with an optional hint. */
|
|
280
|
+
function Field(props) {
|
|
281
|
+
return h('label', { className: 'meow-field' },
|
|
282
|
+
h('span', { className: 'meow-label' }, props.label),
|
|
283
|
+
h('input', {
|
|
284
|
+
className: 'meow-input',
|
|
285
|
+
type: props.secret === true ? 'password' : 'text',
|
|
286
|
+
value: props.value ?? '',
|
|
287
|
+
placeholder: props.placeholder ?? '',
|
|
288
|
+
maxLength: props.maxLength,
|
|
289
|
+
autoComplete: 'off',
|
|
290
|
+
spellCheck: false,
|
|
291
|
+
disabled: props.disabled === true,
|
|
292
|
+
onChange: (event) => props.onChange(event.currentTarget.value),
|
|
293
|
+
}),
|
|
294
|
+
props.hint ? h('span', { className: 'meow-hint' }, props.hint) : null,
|
|
295
|
+
)
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** One channel card: title, configured badge, hint, and fields. */
|
|
299
|
+
function Channel(props) {
|
|
300
|
+
return h('div', { className: 'meow-channel' },
|
|
301
|
+
h('div', { className: 'meow-channel-head' },
|
|
302
|
+
h('span', { className: 'meow-channel-title' }, props.title),
|
|
303
|
+
h('span', {
|
|
304
|
+
className: 'meow-badge',
|
|
305
|
+
'data-on': props.active === true,
|
|
306
|
+
}, props.badge),
|
|
307
|
+
),
|
|
308
|
+
props.hint ? h('p', { className: 'meow-hint' }, props.hint) : null,
|
|
309
|
+
props.children,
|
|
310
|
+
)
|
|
311
|
+
}
|
|
312
|
+
|
|
226
313
|
return {
|
|
227
314
|
name: 'meow-notify:settings',
|
|
228
315
|
inject: ['slots', 'locale'],
|
|
@@ -318,10 +405,10 @@ window.__ModuleLoader__.load({
|
|
|
318
405
|
setBusy('test')
|
|
319
406
|
setNotice(null)
|
|
320
407
|
try {
|
|
321
|
-
if (!
|
|
408
|
+
if (!anyChannel(draft)) throw new Error(t('needChannel'))
|
|
322
409
|
await persist()
|
|
323
410
|
const body = await apiRequest('test', { method: 'POST' })
|
|
324
|
-
const detail = body?.detail
|
|
411
|
+
const detail = body?.detail ? `(${body.detail})` : ''
|
|
325
412
|
setNotice({ tone: 'ok', text: t('testSent') + detail })
|
|
326
413
|
await refreshMeta()
|
|
327
414
|
} catch (error) {
|
|
@@ -351,42 +438,97 @@ window.__ModuleLoader__.load({
|
|
|
351
438
|
const last = meta?.diagnostics?.lastSend
|
|
352
439
|
const lastText = last
|
|
353
440
|
? (last.ok === true
|
|
354
|
-
? t('lastOk')
|
|
355
|
-
: t('lastFail', { error: String(last.detail || '').slice(0,
|
|
441
|
+
? String(last.detail || t('lastOk'))
|
|
442
|
+
: t('lastFail', { error: String(last.detail || '').slice(0, 120) }))
|
|
356
443
|
: ''
|
|
357
444
|
|
|
445
|
+
const channelBadge = (value) => (filled(value) ? t('channelOn') : t('channelOff'))
|
|
446
|
+
|
|
358
447
|
return h('div', { className: 'meow-page' },
|
|
359
448
|
h('p', { className: 'meow-lead' }, t('lead')),
|
|
360
449
|
|
|
361
|
-
h('
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
450
|
+
h('div', { className: 'meow-section' }, t('channels')),
|
|
451
|
+
|
|
452
|
+
h(Channel, {
|
|
453
|
+
title: t('meowName'),
|
|
454
|
+
hint: t('meowHint'),
|
|
455
|
+
active: filled(draft.nickname),
|
|
456
|
+
badge: channelBadge(draft.nickname),
|
|
457
|
+
},
|
|
458
|
+
h(Field, {
|
|
459
|
+
label: t('nickname'),
|
|
366
460
|
value: draft.nickname ?? '',
|
|
367
|
-
autoComplete: 'off',
|
|
368
|
-
spellCheck: false,
|
|
369
461
|
placeholder: 'your-meow-nickname',
|
|
462
|
+
hint: t('nicknameHint'),
|
|
370
463
|
disabled,
|
|
371
|
-
onChange: (
|
|
464
|
+
onChange: (value) => setField('nickname', value),
|
|
372
465
|
}),
|
|
373
|
-
h(
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
h('label', { className: 'meow-field' },
|
|
377
|
-
h('span', { className: 'meow-label' }, t('category')),
|
|
378
|
-
h('input', {
|
|
379
|
-
className: 'meow-input',
|
|
380
|
-
type: 'text',
|
|
466
|
+
h(Field, {
|
|
467
|
+
label: t('category'),
|
|
381
468
|
value: draft.category ?? '',
|
|
382
|
-
maxLength: 10,
|
|
383
|
-
autoComplete: 'off',
|
|
384
|
-
spellCheck: false,
|
|
385
469
|
placeholder: 'DSH',
|
|
470
|
+
maxLength: 10,
|
|
471
|
+
hint: t('categoryHint'),
|
|
472
|
+
disabled,
|
|
473
|
+
onChange: (value) => setField('category', value),
|
|
474
|
+
}),
|
|
475
|
+
),
|
|
476
|
+
|
|
477
|
+
h(Channel, {
|
|
478
|
+
title: t('barkName'),
|
|
479
|
+
hint: t('barkHint'),
|
|
480
|
+
active: filled(draft.barkKey),
|
|
481
|
+
badge: channelBadge(draft.barkKey),
|
|
482
|
+
},
|
|
483
|
+
h(Field, {
|
|
484
|
+
label: t('barkKey'),
|
|
485
|
+
value: draft.barkKey ?? '',
|
|
486
|
+
placeholder: 'https://api.day.app/your-key',
|
|
487
|
+
hint: t('barkKeyHint'),
|
|
488
|
+
disabled,
|
|
489
|
+
onChange: (value) => setField('barkKey', value),
|
|
490
|
+
}),
|
|
491
|
+
h(Field, {
|
|
492
|
+
label: t('barkServer'),
|
|
493
|
+
value: draft.barkServer ?? '',
|
|
494
|
+
placeholder: 'https://api.day.app',
|
|
495
|
+
hint: t('barkServerHint'),
|
|
496
|
+
disabled,
|
|
497
|
+
onChange: (value) => setField('barkServer', value),
|
|
498
|
+
}),
|
|
499
|
+
),
|
|
500
|
+
|
|
501
|
+
h(Channel, {
|
|
502
|
+
title: t('ntfyName'),
|
|
503
|
+
hint: t('ntfyHint'),
|
|
504
|
+
active: filled(draft.ntfyTopic),
|
|
505
|
+
badge: channelBadge(draft.ntfyTopic),
|
|
506
|
+
},
|
|
507
|
+
h(Field, {
|
|
508
|
+
label: t('ntfyTopic'),
|
|
509
|
+
value: draft.ntfyTopic ?? '',
|
|
510
|
+
placeholder: 'dsh-notify-8f3k',
|
|
511
|
+
hint: t('ntfyTopicHint'),
|
|
512
|
+
disabled,
|
|
513
|
+
onChange: (value) => setField('ntfyTopic', value),
|
|
514
|
+
}),
|
|
515
|
+
h(Field, {
|
|
516
|
+
label: t('ntfyServer'),
|
|
517
|
+
value: draft.ntfyServer ?? '',
|
|
518
|
+
placeholder: 'https://ntfy.sh',
|
|
519
|
+
hint: t('ntfyServerHint'),
|
|
520
|
+
disabled,
|
|
521
|
+
onChange: (value) => setField('ntfyServer', value),
|
|
522
|
+
}),
|
|
523
|
+
h(Field, {
|
|
524
|
+
label: t('ntfyToken'),
|
|
525
|
+
value: draft.ntfyToken ?? '',
|
|
526
|
+
placeholder: 'tk_…',
|
|
527
|
+
secret: true,
|
|
528
|
+
hint: t('ntfyTokenHint'),
|
|
386
529
|
disabled,
|
|
387
|
-
onChange: (
|
|
530
|
+
onChange: (value) => setField('ntfyToken', value),
|
|
388
531
|
}),
|
|
389
|
-
h('span', { className: 'meow-hint' }, t('categoryHint')),
|
|
390
532
|
),
|
|
391
533
|
|
|
392
534
|
h('div', { className: 'meow-section' }, t('events')),
|
|
@@ -442,7 +584,7 @@ window.__ModuleLoader__.load({
|
|
|
442
584
|
h('button', {
|
|
443
585
|
type: 'button',
|
|
444
586
|
className: 'meow-secondary',
|
|
445
|
-
disabled: disabled || !
|
|
587
|
+
disabled: disabled || !anyChannel(draft),
|
|
446
588
|
onClick: () => { void test() },
|
|
447
589
|
}, busy === 'test' ? t('testing') : t('test')),
|
|
448
590
|
dirty ? h('span', { className: 'meow-hint' }, t('dirty')) : null,
|
package/cordis.patch.yml
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
#
|
|
2
|
-
# browser settings routes, and pushes through
|
|
1
|
+
# Notifier bundle: one Host row that watches agent activity, registers the
|
|
2
|
+
# browser settings routes, and pushes through MeoW, Bark, or ntfy.
|
|
3
3
|
- insert:
|
|
4
4
|
- id: meow-notify
|
|
5
5
|
name: 'dsh-meow-notifier'
|
package/host.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Push notifications for DeepSeek Harness.
|
|
3
3
|
*
|
|
4
|
-
* Watches three Host signals and forwards them to
|
|
5
|
-
* (https://www.chuckfang.com/MeoW/api_doc.html)
|
|
4
|
+
* Watches three Host signals and forwards them to every configured channel:
|
|
5
|
+
* MeoW (https://www.chuckfang.com/MeoW/api_doc.html), Bark for iOS
|
|
6
|
+
* (https://bark.day.app), and ntfy for Android / cross-platform
|
|
7
|
+
* (https://docs.ntfy.sh/publish/):
|
|
6
8
|
*
|
|
7
9
|
* - `agent/status` running -> idle: one turn series finished, report the outcome.
|
|
8
10
|
* - `approval/request`: a tool call is waiting for the user's decision.
|
|
@@ -22,6 +24,10 @@ export const name = 'meow-notify'
|
|
|
22
24
|
|
|
23
25
|
/** MeoW push API root. */
|
|
24
26
|
const API_ENDPOINT = 'https://api.chuckfang.com'
|
|
27
|
+
/** Bark (iOS) server used when the user leaves the field empty. */
|
|
28
|
+
const BARK_DEFAULT_SERVER = 'https://api.day.app'
|
|
29
|
+
/** ntfy (Android / cross-platform) server used when the field is empty. */
|
|
30
|
+
const NTFY_DEFAULT_SERVER = 'https://ntfy.sh'
|
|
25
31
|
|
|
26
32
|
/** Route paths claimed on the Host web server. */
|
|
27
33
|
const STATE_PATH = '/meow-notify/api/state'
|
|
@@ -50,10 +56,18 @@ const COMPACT_MSG_CHARS = 160
|
|
|
50
56
|
/** Longest single-sentence excerpt a compact body keeps. */
|
|
51
57
|
const COMPACT_EXCERPT_CHARS = 96
|
|
52
58
|
|
|
59
|
+
/** ntfy topics are letters, digits, dashes, and underscores, up to 64 chars. */
|
|
60
|
+
const NTFY_TOPIC_PATTERN = /^[-_A-Za-z0-9]{1,64}$/u
|
|
61
|
+
|
|
53
62
|
/** Out-of-the-box settings. */
|
|
54
63
|
const DEFAULTS = Object.freeze({
|
|
55
64
|
nickname: '',
|
|
56
65
|
category: 'DSH',
|
|
66
|
+
barkKey: '',
|
|
67
|
+
barkServer: '',
|
|
68
|
+
ntfyTopic: '',
|
|
69
|
+
ntfyServer: '',
|
|
70
|
+
ntfyToken: '',
|
|
57
71
|
notifyDone: true,
|
|
58
72
|
notifyApproval: true,
|
|
59
73
|
notifyQuestion: true,
|
|
@@ -94,6 +108,80 @@ function messageOf(error) {
|
|
|
94
108
|
return String(error)
|
|
95
109
|
}
|
|
96
110
|
|
|
111
|
+
/**
|
|
112
|
+
* Normalize a self-hosted server address. An empty input stays empty so the
|
|
113
|
+
* settings page can show the default as a placeholder.
|
|
114
|
+
*/
|
|
115
|
+
function normalizeServer(value, max = 200) {
|
|
116
|
+
let text = String(value ?? '').trim()
|
|
117
|
+
if (!text) return ''
|
|
118
|
+
if (!/^https?:\/\//iu.test(text)) text = `https://${text}`
|
|
119
|
+
text = text.replace(/\/+$/u, '')
|
|
120
|
+
try {
|
|
121
|
+
const url = new URL(text)
|
|
122
|
+
if (url.protocol !== 'http:' && url.protocol !== 'https:') return ''
|
|
123
|
+
text = url.href.replace(/\/+$/u, '')
|
|
124
|
+
} catch {
|
|
125
|
+
/* keep the raw text; the sender reports the URL error */
|
|
126
|
+
}
|
|
127
|
+
return clampChars(text, max)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Split a Bark field into a device key and a server.
|
|
132
|
+
*
|
|
133
|
+
* Users can paste either the bare key or the push URL shown by the Bark app
|
|
134
|
+
* (`https://api.day.app/<key>`), so both shapes are accepted.
|
|
135
|
+
*/
|
|
136
|
+
function parseBarkTarget(rawKey, rawServer) {
|
|
137
|
+
const fallback = normalizeServer(rawServer) || BARK_DEFAULT_SERVER
|
|
138
|
+
let key = String(rawKey ?? '').trim()
|
|
139
|
+
let server = fallback
|
|
140
|
+
if (/^https?:\/\//iu.test(key)) {
|
|
141
|
+
try {
|
|
142
|
+
const url = new URL(key)
|
|
143
|
+
server = normalizeServer(rawServer) || `${url.protocol}//${url.host}`
|
|
144
|
+
key = decodeURIComponent(url.pathname.split('/').filter(Boolean).pop() ?? '')
|
|
145
|
+
} catch {
|
|
146
|
+
key = ''
|
|
147
|
+
}
|
|
148
|
+
} else if (key.includes('/')) {
|
|
149
|
+
const parts = key.split('/').filter(Boolean)
|
|
150
|
+
if (parts.length > 1) {
|
|
151
|
+
server = normalizeServer(rawServer) || normalizeServer(parts.slice(0, -1).join('/'))
|
|
152
|
+
key = parts[parts.length - 1]
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
key = key.replace(/\s+/gu, '')
|
|
156
|
+
return { key: clampChars(key, 200), server }
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Split an ntfy field into a topic and a server. A full topic URL such as
|
|
161
|
+
* `https://ntfy.sh/mytopic` is accepted and reduced to its parts.
|
|
162
|
+
*/
|
|
163
|
+
function parseNtfyTarget(rawTopic, rawServer) {
|
|
164
|
+
const fallback = normalizeServer(rawServer) || NTFY_DEFAULT_SERVER
|
|
165
|
+
let topic = String(rawTopic ?? '').trim()
|
|
166
|
+
let server = fallback
|
|
167
|
+
if (/^https?:\/\//iu.test(topic)) {
|
|
168
|
+
try {
|
|
169
|
+
const url = new URL(topic)
|
|
170
|
+
server = normalizeServer(rawServer) || `${url.protocol}//${url.host}`
|
|
171
|
+
topic = decodeURIComponent(url.pathname.split('/').filter(Boolean)[0] ?? '')
|
|
172
|
+
} catch {
|
|
173
|
+
topic = ''
|
|
174
|
+
}
|
|
175
|
+
} else if (topic.includes('/')) {
|
|
176
|
+
const parts = topic.split('/').filter(Boolean)
|
|
177
|
+
if (parts.length > 1) {
|
|
178
|
+
server = normalizeServer(rawServer) || normalizeServer(parts.slice(0, -1).join('/'))
|
|
179
|
+
topic = parts[parts.length - 1]
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return { topic: topic.replace(/\s+/gu, ''), server }
|
|
183
|
+
}
|
|
184
|
+
|
|
97
185
|
/** Log without ever letting logging break a notification path. */
|
|
98
186
|
function warn(ctx, message) {
|
|
99
187
|
try {
|
|
@@ -241,9 +329,23 @@ function normalizeState(input) {
|
|
|
241
329
|
const category = typeof source.category === 'string'
|
|
242
330
|
? clampChars(source.category.replace(/[\r\n\t]/gu, ' ').trim(), 10)
|
|
243
331
|
: DEFAULTS.category
|
|
332
|
+
const barkKey = typeof source.barkKey === 'string'
|
|
333
|
+
? source.barkKey.replace(/\s+/gu, '').trim().slice(0, 200)
|
|
334
|
+
: ''
|
|
335
|
+
const ntfyTopic = typeof source.ntfyTopic === 'string'
|
|
336
|
+
? source.ntfyTopic.replace(/\s+/gu, '').trim().slice(0, 200)
|
|
337
|
+
: ''
|
|
338
|
+
const ntfyToken = typeof source.ntfyToken === 'string'
|
|
339
|
+
? source.ntfyToken.trim().slice(0, 200)
|
|
340
|
+
: ''
|
|
244
341
|
return {
|
|
245
342
|
nickname,
|
|
246
343
|
category,
|
|
344
|
+
barkKey,
|
|
345
|
+
barkServer: normalizeServer(source.barkServer),
|
|
346
|
+
ntfyTopic,
|
|
347
|
+
ntfyServer: normalizeServer(source.ntfyServer),
|
|
348
|
+
ntfyToken,
|
|
247
349
|
notifyDone: source.notifyDone !== false,
|
|
248
350
|
notifyApproval: source.notifyApproval !== false,
|
|
249
351
|
notifyQuestion: source.notifyQuestion !== false,
|
|
@@ -255,6 +357,15 @@ function normalizeState(input) {
|
|
|
255
357
|
// Persistence
|
|
256
358
|
// ---------------------------------------------------------------------------
|
|
257
359
|
|
|
360
|
+
/** Reject settings that would only fail later at send time. */
|
|
361
|
+
function settingsProblem(state) {
|
|
362
|
+
const { topic } = parseNtfyTarget(state.ntfyTopic, state.ntfyServer)
|
|
363
|
+
if (topic && !NTFY_TOPIC_PATTERN.test(topic)) {
|
|
364
|
+
return 'ntfy 主题只能包含字母、数字、连字符和下划线,最长 64 个字符'
|
|
365
|
+
}
|
|
366
|
+
return undefined
|
|
367
|
+
}
|
|
368
|
+
|
|
258
369
|
/** Settings kept in one JSON file under the harness home. */
|
|
259
370
|
class SettingsStore {
|
|
260
371
|
constructor(ctx) {
|
|
@@ -277,7 +388,10 @@ class SettingsStore {
|
|
|
277
388
|
|
|
278
389
|
async save(patch) {
|
|
279
390
|
await this.ready
|
|
280
|
-
|
|
391
|
+
const next = normalizeState({ ...this.state, ...patch })
|
|
392
|
+
const problem = settingsProblem(next)
|
|
393
|
+
if (problem) throw new Error(problem)
|
|
394
|
+
this.state = next
|
|
281
395
|
const snapshot = { ...this.state }
|
|
282
396
|
const write = this.writeChain.then(async () => {
|
|
283
397
|
await mkdir(dirname(this.file), { recursive: true })
|
|
@@ -388,8 +502,183 @@ function sessionLabel(session) {
|
|
|
388
502
|
// Push delivery
|
|
389
503
|
// ---------------------------------------------------------------------------
|
|
390
504
|
|
|
391
|
-
/**
|
|
392
|
-
|
|
505
|
+
/** POST one notification to the MeoW API. Never throws. */
|
|
506
|
+
async function sendMeow(job, state) {
|
|
507
|
+
const nickname = String(state.nickname ?? '').trim()
|
|
508
|
+
if (!nickname) return { ok: false, error: '未填写 MeoW 昵称' }
|
|
509
|
+
const payload = {
|
|
510
|
+
title: job.title,
|
|
511
|
+
msg: job.msg,
|
|
512
|
+
}
|
|
513
|
+
if (job.url) payload.url = job.url
|
|
514
|
+
if (state.category) payload.category = state.category
|
|
515
|
+
try {
|
|
516
|
+
const response = await fetch(`${API_ENDPOINT}/${encodeURIComponent(nickname)}`, {
|
|
517
|
+
method: 'POST',
|
|
518
|
+
headers: { 'content-type': 'application/json; charset=utf-8' },
|
|
519
|
+
body: JSON.stringify(payload),
|
|
520
|
+
signal: AbortSignal.timeout(10000),
|
|
521
|
+
})
|
|
522
|
+
const text = await response.text()
|
|
523
|
+
let body
|
|
524
|
+
try {
|
|
525
|
+
body = JSON.parse(text)
|
|
526
|
+
} catch {
|
|
527
|
+
body = undefined
|
|
528
|
+
}
|
|
529
|
+
// The transport always answers 200; only the JSON business status decides
|
|
530
|
+
// success, and the reference contract requires `data: true` as well.
|
|
531
|
+
if (body && body.status === 200 && body.data === true) {
|
|
532
|
+
return { ok: true, detail: typeof body.msg === 'string' ? body.msg : '发送成功' }
|
|
533
|
+
}
|
|
534
|
+
const error = body && typeof body.msg === 'string' && body.msg
|
|
535
|
+
? body.msg.replace(/^发送失败[,,]\s*/u, '')
|
|
536
|
+
: `HTTP ${response.status}`
|
|
537
|
+
return { ok: false, error, status: body?.status ?? response.status }
|
|
538
|
+
} catch (error) {
|
|
539
|
+
return { ok: false, error: messageOf(error) }
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
/** POST one notification to a Bark server (iOS). Never throws. */
|
|
544
|
+
async function sendBark(job, state) {
|
|
545
|
+
const { key, server } = parseBarkTarget(state.barkKey, state.barkServer)
|
|
546
|
+
if (!key) return { ok: false, error: '未填写 Bark 设备 key' }
|
|
547
|
+
const urgent = job.kind === 'approval' || job.kind === 'question'
|
|
548
|
+
const payload = {
|
|
549
|
+
device_key: key,
|
|
550
|
+
title: clampChars(job.title, 100),
|
|
551
|
+
body: clampChars(job.msg, 1000),
|
|
552
|
+
// Bark groups notifications by `group` in its notification list.
|
|
553
|
+
group: state.category || undefined,
|
|
554
|
+
level: urgent ? 'timeSensitive' : 'active',
|
|
555
|
+
}
|
|
556
|
+
if (job.url) payload.url = job.url
|
|
557
|
+
try {
|
|
558
|
+
const response = await fetch(`${server}/push`, {
|
|
559
|
+
method: 'POST',
|
|
560
|
+
headers: { 'content-type': 'application/json; charset=utf-8' },
|
|
561
|
+
body: JSON.stringify(payload),
|
|
562
|
+
signal: AbortSignal.timeout(10000),
|
|
563
|
+
})
|
|
564
|
+
const text = await response.text()
|
|
565
|
+
let body
|
|
566
|
+
try {
|
|
567
|
+
body = JSON.parse(text)
|
|
568
|
+
} catch {
|
|
569
|
+
body = undefined
|
|
570
|
+
}
|
|
571
|
+
if (body && body.code === 200) {
|
|
572
|
+
return { ok: true, detail: typeof body.message === 'string' && body.message ? body.message : '发送成功' }
|
|
573
|
+
}
|
|
574
|
+
const error = body && typeof body.message === 'string' && body.message
|
|
575
|
+
? body.message
|
|
576
|
+
: `HTTP ${response.status}`
|
|
577
|
+
return { ok: false, error }
|
|
578
|
+
} catch (error) {
|
|
579
|
+
return { ok: false, error: messageOf(error) }
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
/** Emoji tags ntfy renders in front of a notification. */
|
|
584
|
+
function tagsFor(kind) {
|
|
585
|
+
if (kind === 'approval') return ['warning']
|
|
586
|
+
if (kind === 'question') return ['question']
|
|
587
|
+
if (kind === 'test') return ['bell']
|
|
588
|
+
return ['white_check_mark']
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
/** Publish one notification through ntfy (Android / cross-platform). Never throws. */
|
|
592
|
+
async function sendNtfy(job, state) {
|
|
593
|
+
const { topic, server } = parseNtfyTarget(state.ntfyTopic, state.ntfyServer)
|
|
594
|
+
if (!topic) return { ok: false, error: '未填写 ntfy 主题' }
|
|
595
|
+
if (!NTFY_TOPIC_PATTERN.test(topic)) {
|
|
596
|
+
return { ok: false, error: 'ntfy 主题只能包含字母、数字、- 和 _,且不超过 64 个字符' }
|
|
597
|
+
}
|
|
598
|
+
const urgent = job.kind === 'approval' || job.kind === 'question'
|
|
599
|
+
const payload = {
|
|
600
|
+
topic,
|
|
601
|
+
title: clampChars(job.title, 250),
|
|
602
|
+
message: clampChars(job.msg, 4096),
|
|
603
|
+
priority: urgent ? 4 : 3,
|
|
604
|
+
tags: tagsFor(job.kind),
|
|
605
|
+
}
|
|
606
|
+
if (job.url) payload.click = job.url
|
|
607
|
+
const headers = { 'content-type': 'application/json; charset=utf-8' }
|
|
608
|
+
if (state.ntfyToken) headers.authorization = `Bearer ${state.ntfyToken}`
|
|
609
|
+
try {
|
|
610
|
+
// The JSON publishing endpoint is the server root; the topic travels in the body.
|
|
611
|
+
const response = await fetch(`${server}/`, {
|
|
612
|
+
method: 'POST',
|
|
613
|
+
headers,
|
|
614
|
+
body: JSON.stringify(payload),
|
|
615
|
+
signal: AbortSignal.timeout(10000),
|
|
616
|
+
})
|
|
617
|
+
const text = await response.text()
|
|
618
|
+
let body
|
|
619
|
+
try {
|
|
620
|
+
body = JSON.parse(text)
|
|
621
|
+
} catch {
|
|
622
|
+
body = undefined
|
|
623
|
+
}
|
|
624
|
+
if (response.ok && body && typeof body.id === 'string') {
|
|
625
|
+
return { ok: true, detail: '发送成功' }
|
|
626
|
+
}
|
|
627
|
+
const error = body && typeof body.error === 'string' ? body.error : `HTTP ${response.status}`
|
|
628
|
+
return { ok: false, error }
|
|
629
|
+
} catch (error) {
|
|
630
|
+
return { ok: false, error: messageOf(error) }
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
/** Every channel the user has filled in. */
|
|
635
|
+
function configuredChannels(state) {
|
|
636
|
+
const channels = []
|
|
637
|
+
if (String(state?.nickname ?? '').trim()) channels.push({ id: 'meow', label: 'MeoW', send: sendMeow })
|
|
638
|
+
if (String(state?.barkKey ?? '').trim()) channels.push({ id: 'bark', label: 'Bark', send: sendBark })
|
|
639
|
+
if (String(state?.ntfyTopic ?? '').trim()) channels.push({ id: 'ntfy', label: 'ntfy', send: sendNtfy })
|
|
640
|
+
return channels
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
/**
|
|
644
|
+
* Send one notification to all configured channels in parallel.
|
|
645
|
+
*
|
|
646
|
+
* The result is `ok` when at least one channel accepted the message; `detail`
|
|
647
|
+
* always lists every channel so the settings page can explain a partial
|
|
648
|
+
* failure. Exported so the delivery contract can be tested without a runtime.
|
|
649
|
+
*
|
|
650
|
+
* @param job - title, body, optional tap URL, and the kind used for priority.
|
|
651
|
+
* @param state - the saved settings.
|
|
652
|
+
* @returns `{ ok, detail, error?, channels }`.
|
|
653
|
+
*/
|
|
654
|
+
export async function deliver(job, state) {
|
|
655
|
+
const channels = configuredChannels(state)
|
|
656
|
+
if (channels.length === 0) {
|
|
657
|
+
return { ok: false, error: '尚未配置推送渠道(MeoW / Bark / ntfy 至少填写一个)', channels: [] }
|
|
658
|
+
}
|
|
659
|
+
const results = await Promise.all(channels.map(async (channel) => {
|
|
660
|
+
try {
|
|
661
|
+
const outcome = await channel.send(job, state)
|
|
662
|
+
return {
|
|
663
|
+
id: channel.id,
|
|
664
|
+
label: channel.label,
|
|
665
|
+
ok: outcome.ok === true,
|
|
666
|
+
...(outcome.ok
|
|
667
|
+
? { detail: outcome.detail ?? '发送成功' }
|
|
668
|
+
: { error: outcome.error ?? '发送失败' }),
|
|
669
|
+
}
|
|
670
|
+
} catch (error) {
|
|
671
|
+
return { id: channel.id, label: channel.label, ok: false, error: messageOf(error) }
|
|
672
|
+
}
|
|
673
|
+
}))
|
|
674
|
+
const ok = results.some((result) => result.ok)
|
|
675
|
+
const detail = results.map((result) => `${result.label}:${result.ok ? '成功' : `失败(${result.error})`}`).join(';')
|
|
676
|
+
const error = ok ? undefined : results.map((result) => `${result.label}:${result.error}`).join(';')
|
|
677
|
+
return { ok, detail, error, channels: results }
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
/** Serial queue that respects the MeoW per-minute and per-hour limits. */
|
|
681
|
+
class Notifier {
|
|
393
682
|
constructor(ctx, store) {
|
|
394
683
|
this.ctx = ctx
|
|
395
684
|
this.store = store
|
|
@@ -443,27 +732,37 @@ class MeowNotifier {
|
|
|
443
732
|
const job = this.queue.shift()
|
|
444
733
|
await this.store.ready
|
|
445
734
|
const state = this.store.state
|
|
446
|
-
if (
|
|
447
|
-
job.resolve({ ok: false, error: '
|
|
735
|
+
if (configuredChannels(state).length === 0) {
|
|
736
|
+
job.resolve({ ok: false, error: '尚未配置推送渠道(MeoW / Bark / ntfy 至少填写一个)' })
|
|
448
737
|
continue
|
|
449
738
|
}
|
|
450
739
|
const wait = this.lastAttemptAt + MIN_SEND_INTERVAL_MS - Date.now()
|
|
451
740
|
if (wait > 0) await sleep(wait)
|
|
452
741
|
const now = Date.now()
|
|
453
|
-
|
|
742
|
+
const meowActive = Boolean(String(state.nickname ?? '').trim())
|
|
743
|
+
if (meowActive && !this.admitsSend(now)) {
|
|
454
744
|
job.resolve({ ok: false, error: '已达到 MeoW 的发送频率上限(每小时 60 条 / 每天 1000 条),本条已跳过' })
|
|
455
745
|
continue
|
|
456
746
|
}
|
|
457
747
|
this.lastAttemptAt = Date.now()
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
const
|
|
748
|
+
// Only MeoW publishes a quota; these counters track its sends alone.
|
|
749
|
+
if (meowActive) this.sentAt.push(this.lastAttemptAt)
|
|
750
|
+
const result = await deliver(job, state)
|
|
751
|
+
for (const channel of result.channels ?? []) {
|
|
752
|
+
if (!channel.ok) warn(this.ctx, `meow-notify: ${channel.label} push failed: ${channel.error}`)
|
|
753
|
+
}
|
|
754
|
+
this.diagnostics.lastSend = {
|
|
461
755
|
at: Date.now(),
|
|
462
756
|
kind: job.kind ?? 'unknown',
|
|
463
757
|
ok: result.ok === true,
|
|
464
758
|
detail: result.ok === true ? (result.detail ?? '') : (result.error ?? ''),
|
|
759
|
+
channels: (result.channels ?? []).map((channel) => ({
|
|
760
|
+
id: channel.id,
|
|
761
|
+
label: channel.label,
|
|
762
|
+
ok: channel.ok === true,
|
|
763
|
+
...(channel.ok ? {} : { error: channel.error }),
|
|
764
|
+
})),
|
|
465
765
|
}
|
|
466
|
-
this.diagnostics.lastSend = lastSend
|
|
467
766
|
job.resolve(result)
|
|
468
767
|
}
|
|
469
768
|
} finally {
|
|
@@ -471,44 +770,6 @@ class MeowNotifier {
|
|
|
471
770
|
}
|
|
472
771
|
}
|
|
473
772
|
|
|
474
|
-
/** One HTTPS call to the MeoW API. Never throws. */
|
|
475
|
-
async send(job, state) {
|
|
476
|
-
const payload = {
|
|
477
|
-
title: job.title,
|
|
478
|
-
msg: job.msg,
|
|
479
|
-
}
|
|
480
|
-
if (job.url) payload.url = job.url
|
|
481
|
-
if (state.category) payload.category = state.category
|
|
482
|
-
try {
|
|
483
|
-
const response = await fetch(`${API_ENDPOINT}/${encodeURIComponent(state.nickname)}`, {
|
|
484
|
-
method: 'POST',
|
|
485
|
-
headers: { 'content-type': 'application/json; charset=utf-8' },
|
|
486
|
-
body: JSON.stringify(payload),
|
|
487
|
-
signal: AbortSignal.timeout(10000),
|
|
488
|
-
})
|
|
489
|
-
const text = await response.text()
|
|
490
|
-
let body
|
|
491
|
-
try {
|
|
492
|
-
body = JSON.parse(text)
|
|
493
|
-
} catch {
|
|
494
|
-
body = undefined
|
|
495
|
-
}
|
|
496
|
-
// The transport always answers 200; only the JSON business status decides
|
|
497
|
-
// success, and the reference contract requires `data: true` as well.
|
|
498
|
-
if (body && body.status === 200 && body.data === true) {
|
|
499
|
-
return { ok: true, detail: typeof body.msg === 'string' ? body.msg : '发送成功' }
|
|
500
|
-
}
|
|
501
|
-
const error = body && typeof body.msg === 'string' && body.msg
|
|
502
|
-
? body.msg.replace(/^发送失败[,,]\s*/u, '')
|
|
503
|
-
: `HTTP ${response.status}`
|
|
504
|
-
warn(this.ctx, `meow-notify: push refused: ${error}`)
|
|
505
|
-
return { ok: false, error, status: body?.status ?? response.status }
|
|
506
|
-
} catch (error) {
|
|
507
|
-
warn(this.ctx, `meow-notify: push failed: ${messageOf(error)}`)
|
|
508
|
-
return { ok: false, error: messageOf(error) }
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
|
|
512
773
|
/**
|
|
513
774
|
* Build the notification in the configured style and hand it to the queue.
|
|
514
775
|
* @param kind - delivery kind recorded in diagnostics.
|
|
@@ -566,8 +827,8 @@ class MeowNotifier {
|
|
|
566
827
|
/** Deliver a manual test push using the saved settings. */
|
|
567
828
|
async test() {
|
|
568
829
|
await this.store.ready
|
|
569
|
-
if (
|
|
570
|
-
return { ok: false, error: '
|
|
830
|
+
if (configuredChannels(this.store.state).length === 0) {
|
|
831
|
+
return { ok: false, error: '请至少填写一个推送渠道(MeoW / Bark / ntfy)' }
|
|
571
832
|
}
|
|
572
833
|
this.recordEvent('test')
|
|
573
834
|
return this.enqueue({
|
|
@@ -713,7 +974,7 @@ function mountRoutes(ctx, store, notifier) {
|
|
|
713
974
|
*/
|
|
714
975
|
export function apply(ctx) {
|
|
715
976
|
const store = new SettingsStore(ctx)
|
|
716
|
-
const notifier = new
|
|
977
|
+
const notifier = new Notifier(ctx, store)
|
|
717
978
|
|
|
718
979
|
mountRoutes(ctx, store, notifier)
|
|
719
980
|
|
package/locale/en.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
|
-
"title": "
|
|
4
|
-
"description": "Push task completion, approval, and question alerts to your phone through MeoW."
|
|
3
|
+
"title": "Push Notifications",
|
|
4
|
+
"description": "Push task completion, approval, and question alerts to your phone through MeoW, Bark, or ntfy."
|
|
5
5
|
}
|
|
6
6
|
}
|
package/locale/zh.json
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-meow-notifier",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Push DeepSeek Harness task completion, approval, and question alerts to your phone through MeoW",
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"description": "Push DeepSeek Harness task completion, approval, and question alerts to your phone through MeoW, Bark, or ntfy",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "host.js",
|
|
7
7
|
"exports": {
|
|
@@ -25,19 +25,23 @@
|
|
|
25
25
|
"dsh",
|
|
26
26
|
"dsh-plugin",
|
|
27
27
|
"meow",
|
|
28
|
+
"bark",
|
|
29
|
+
"ntfy",
|
|
28
30
|
"push",
|
|
29
31
|
"notification",
|
|
30
|
-
"notify"
|
|
32
|
+
"notify",
|
|
33
|
+
"ios",
|
|
34
|
+
"android"
|
|
31
35
|
],
|
|
32
36
|
"author": "Oliver-314",
|
|
33
37
|
"license": "MIT",
|
|
34
38
|
"repository": {
|
|
35
39
|
"type": "git",
|
|
36
|
-
"url": "git+https://github.com/Oliver-314/dsh-
|
|
40
|
+
"url": "git+https://github.com/Oliver-314/dsh-meow-notifier.git"
|
|
37
41
|
},
|
|
38
|
-
"homepage": "https://github.com/Oliver-314/dsh-
|
|
42
|
+
"homepage": "https://github.com/Oliver-314/dsh-meow-notifier#readme",
|
|
39
43
|
"bugs": {
|
|
40
|
-
"url": "https://github.com/Oliver-314/dsh-
|
|
44
|
+
"url": "https://github.com/Oliver-314/dsh-meow-notifier/issues"
|
|
41
45
|
},
|
|
42
46
|
"engines": {
|
|
43
47
|
"node": ">=22"
|