dsh-session-tg-notify 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +13 -5
- package/package.json +8 -4
- package/src/events.js +0 -19
- package/src/index.js +4 -18
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 kriskwok
|
|
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
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -10,11 +10,19 @@ DSH 会话通知插件:监控会话事件,按**浏览器前后台状态**自
|
|
|
10
10
|
|
|
11
11
|
## 安装
|
|
12
12
|
|
|
13
|
+
从 npm 安装(推荐):
|
|
14
|
+
|
|
13
15
|
```sh
|
|
14
|
-
dsh plugin --profile web add
|
|
16
|
+
dsh plugin --profile web add dsh-session-tg-notify
|
|
15
17
|
```
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
装完需要重启 DSH 进程才会加载插件。
|
|
20
|
+
|
|
21
|
+
开发时用 `link:` 安装本仓库,改完源码只需重启,不必重新安装:
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
dsh plugin --profile web add link:/绝对路径/dsh-session-tg-notify
|
|
25
|
+
```
|
|
18
26
|
|
|
19
27
|
## 使用
|
|
20
28
|
|
|
@@ -35,18 +43,18 @@ dsh plugin --profile web add link:/绝对路径/dsh-session-tg-notify
|
|
|
35
43
|
标题与正文由宿主统一组装,**页面内 toast、macOS 系统通知、Telegram 三处完全一致**:
|
|
36
44
|
|
|
37
45
|
```
|
|
38
|
-
标题:{emoji} {事件类型}
|
|
46
|
+
标题:{emoji} {事件类型}
|
|
39
47
|
正文:{事件正文} 「{工作区名称}」
|
|
40
48
|
```
|
|
41
49
|
|
|
42
50
|
例如:
|
|
43
51
|
|
|
44
52
|
```
|
|
45
|
-
✅
|
|
53
|
+
✅ 会话完成
|
|
46
54
|
帮我重构一下(172s) 「finance」
|
|
47
55
|
```
|
|
48
56
|
|
|
49
|
-
-
|
|
57
|
+
- **标题只显示事件类型**,不带会话标题。会话标题在系统通知里常被截断、信息量也低,而通知本身已经能点击直达会话,点进去即可看到完整标题。
|
|
50
58
|
- **工作区名称**取会话 `cwd` 的末段(DSH 的工作区以目录为单位),拿不到时回退为 session id 前 8 位;两者都拿不到时正文不追加这段。
|
|
51
59
|
|
|
52
60
|
### 可通知的事件
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-tg-notify",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "DSH 会话通知插件:监控会话事件(完成 / 审批 / 提问 / 受阻 / 出错),按浏览器前后台与锁屏状态路由到页面内 toast、系统通知或 Telegram,点击通知直达对应会话。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"files": [
|
|
18
18
|
"src",
|
|
19
19
|
"cordis.patch.yml",
|
|
20
|
-
"README.md"
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE"
|
|
21
22
|
],
|
|
22
23
|
"dependencies": {},
|
|
23
24
|
"engines": {
|
|
@@ -33,8 +34,7 @@
|
|
|
33
34
|
],
|
|
34
35
|
"repository": {
|
|
35
36
|
"type": "git",
|
|
36
|
-
"url": "git+https://github.com/kriskwok/dsh-
|
|
37
|
-
"directory": "dsh-session-notify"
|
|
37
|
+
"url": "git+https://github.com/kriskwok/dsh-session-tg-notify.git"
|
|
38
38
|
},
|
|
39
39
|
"dsh": {
|
|
40
40
|
"bundle": {
|
|
@@ -48,5 +48,9 @@
|
|
|
48
48
|
"@deepseek-ai/dsh-client-ui-workspace"
|
|
49
49
|
]
|
|
50
50
|
}
|
|
51
|
+
},
|
|
52
|
+
"homepage": "https://github.com/kriskwok/dsh-session-tg-notify#readme",
|
|
53
|
+
"bugs": {
|
|
54
|
+
"url": "https://github.com/kriskwok/dsh-session-tg-notify/issues"
|
|
51
55
|
}
|
|
52
56
|
}
|
package/src/events.js
CHANGED
|
@@ -42,25 +42,6 @@ export function workspaceName(session) {
|
|
|
42
42
|
return typeof id === 'string' && id.length > 0 ? id.slice(0, 8) : '';
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
/**
|
|
46
|
-
* 读会话标题(用于通知标题的「:」之后那一段)。
|
|
47
|
-
*
|
|
48
|
-
* 标题由 `@deepseek-ai/dsh-session-title` 的 TitleService 提供(ctx 键
|
|
49
|
-
* `sessionTitle`),`get(session)` 返回 `{ title, ... }`;会话还没有标题事件
|
|
50
|
-
* 时返回 undefined。标题读不到绝不能影响通知本身,所以这里吞掉所有异常。
|
|
51
|
-
*/
|
|
52
|
-
export function readSessionTitle(service, session) {
|
|
53
|
-
if (!service || typeof service.get !== 'function' || !session) return null;
|
|
54
|
-
try {
|
|
55
|
-
const value = service.get(session);
|
|
56
|
-
if (typeof value === 'string' && value.length > 0) return value;
|
|
57
|
-
if (value && typeof value.title === 'string' && value.title.length > 0) return value.title;
|
|
58
|
-
} catch {
|
|
59
|
-
// 标题服务不可用/会话已销毁:降级为「没有标题」,不影响通知
|
|
60
|
-
}
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
45
|
/** 截断为单行,避免通知正文过长。 */
|
|
65
46
|
export function oneLine(text, max = 120) {
|
|
66
47
|
if (typeof text !== 'string') return '';
|
package/src/index.js
CHANGED
|
@@ -27,7 +27,6 @@ import {
|
|
|
27
27
|
classifyGoalChange,
|
|
28
28
|
classifyAgentError,
|
|
29
29
|
workspaceName,
|
|
30
|
-
readSessionTitle,
|
|
31
30
|
oneLine
|
|
32
31
|
} from './events.js';
|
|
33
32
|
import { createPresenceHub } from './presence.js';
|
|
@@ -35,7 +34,7 @@ import { readScreenLocked } from './screenlock.js';
|
|
|
35
34
|
import { sendTelegram, getTelegramMe, getTelegramChats, getTelegramChat } from './telegram.js';
|
|
36
35
|
|
|
37
36
|
export const name = 'session-notify';
|
|
38
|
-
export const VERSION = '0.1.
|
|
37
|
+
export const VERSION = '0.1.3';
|
|
39
38
|
/** 只消费事件与 webServer,不依赖其他服务。 */
|
|
40
39
|
export const inject = [];
|
|
41
40
|
|
|
@@ -107,19 +106,6 @@ export function apply(ctx, cordisConfig = {}, options = {}) {
|
|
|
107
106
|
}
|
|
108
107
|
};
|
|
109
108
|
|
|
110
|
-
/**
|
|
111
|
-
* 会话标题(通知标题里「:」之后那一段)。
|
|
112
|
-
* 服务缺失、或该会话还没生成标题时返回 null —— 通知降级为只有事件类型。
|
|
113
|
-
*/
|
|
114
|
-
const sessionTitleOf = (session) => {
|
|
115
|
-
if (!session) return null;
|
|
116
|
-
try {
|
|
117
|
-
return readSessionTitle(typeof ctx.get === 'function' ? ctx.get('sessionTitle') : null, session);
|
|
118
|
-
} catch {
|
|
119
|
-
return null;
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
|
|
123
109
|
/**
|
|
124
110
|
* 组装最终通知文案(两个通道共用,保证 toast / 系统通知 / Telegram 完全一致):
|
|
125
111
|
* 标题 = `{emoji} {事件类型}:{会话标题}`,标题缺失时省去「:…」
|
|
@@ -128,12 +114,12 @@ export function apply(ctx, cordisConfig = {}, options = {}) {
|
|
|
128
114
|
const compose = (kind, body, session) => {
|
|
129
115
|
const emoji = EVENT_EMOJI[kind] ?? '';
|
|
130
116
|
const label = EVENT_LABELS[kind] ?? kind;
|
|
131
|
-
const head = `${emoji} ${label}`.trim();
|
|
132
|
-
const sessionTitle = sessionTitleOf(session);
|
|
133
117
|
const workspace = session ? workspaceName(session) : '';
|
|
134
118
|
const text = typeof body === 'string' ? body : '';
|
|
135
119
|
return {
|
|
136
|
-
|
|
120
|
+
// 标题只显示事件类型(「✅ 会话完成」)。会话标题不进通知 —— 它在
|
|
121
|
+
// 通知里容易被截断且信息量低,点进去就能看到。
|
|
122
|
+
title: `${emoji} ${label}`.trim(),
|
|
137
123
|
body: workspace.length > 0 ? `${text} 「${workspace}」`.trim() : text
|
|
138
124
|
};
|
|
139
125
|
};
|