@xiaoqiong0v0/opencode-sound-notify 1.1.3 → 1.1.7
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 +8 -5
- package/dist/sound-notify.js +53 -2
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -33,6 +33,8 @@ npm install @xiaoqiong0v0/opencode-sound-notify
|
|
|
33
33
|
"events": ["session.idle", "session.error", "permission.asked"],
|
|
34
34
|
// 全局默认防抖间隔(ms),未单独配置的事件使用此值
|
|
35
35
|
"defaultDebounceMs": 30000,
|
|
36
|
+
// 全局最小间隔(ms),所有声音播放不能低于此间隔,覆盖单独配置
|
|
37
|
+
"minIntervalMs": 3000,
|
|
36
38
|
// 按事件单独配置防抖间隔(ms),覆盖 defaultDebounceMs
|
|
37
39
|
"debounceMs": {
|
|
38
40
|
"permission.asked": 5000
|
|
@@ -50,6 +52,7 @@ npm install @xiaoqiong0v0/opencode-sound-notify
|
|
|
50
52
|
| `sounds` | `{}` | 按事件单独配置,key=事件名,value=wav 路径 |
|
|
51
53
|
| `events` | `["session.idle", "session.error", "permission.asked"]` | 触发事件列表 |
|
|
52
54
|
| `defaultDebounceMs` | `30000` | 全局默认防抖间隔 |
|
|
55
|
+
| `minIntervalMs` | `3000` | 全局最小间隔,所有声音不能小于此值,设为 0 关闭 |
|
|
53
56
|
| `debounceMs` | `{}` | 按事件单独配置,key=事件名,value=防抖间隔(ms) |
|
|
54
57
|
| `lang` | `"en"` | 语言设置 |
|
|
55
58
|
| `enabled` | `true` | 总开关 |
|
|
@@ -73,13 +76,13 @@ npm install @xiaoqiong0v0/opencode-sound-notify
|
|
|
73
76
|
| `session.updated` | 会话更新 |
|
|
74
77
|
| `session.status` | 会话状态变更 |
|
|
75
78
|
|
|
76
|
-
##
|
|
79
|
+
## 运行时开关
|
|
77
80
|
|
|
78
|
-
|
|
81
|
+
不写配置,重启恢复。支持三种方式:
|
|
79
82
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
+
1. **对话**:对 AI 说"关声音" / "mute" / "开声音" / "声音开关"
|
|
84
|
+
2. **命令**:在 TUI 输入 `/sound-toggle on|off|toggle`
|
|
85
|
+
3. **工具**:AI 自动调用 `sound_toggle`
|
|
83
86
|
|
|
84
87
|
## 平台支持
|
|
85
88
|
|
package/dist/sound-notify.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { tool } from "@opencode-ai/plugin";
|
|
1
2
|
import { spawn } from "node:child_process";
|
|
2
3
|
import { existsSync, readFileSync, writeFileSync, mkdirSync } from "node:fs";
|
|
3
4
|
import { join, dirname } from "node:path";
|
|
@@ -36,11 +37,17 @@ const SAMPLE_CFG = `{
|
|
|
36
37
|
}
|
|
37
38
|
`;
|
|
38
39
|
let LANG = "en";
|
|
40
|
+
let muted = false;
|
|
39
41
|
const TX = {
|
|
40
42
|
init_failed: { zh: "初始化失败,使用默认配置", en: "Init failed, using defaults" },
|
|
41
43
|
play_error: { zh: "播放失败", en: "Playback failed" },
|
|
42
44
|
unsupported_platform: { zh: "不支持的播放平台: {platform}", en: "Unsupported platform: {platform}" },
|
|
43
45
|
no_sound_file: { zh: "声音文件不存在: {path}", en: "Sound file not found: {path}" },
|
|
46
|
+
muted_on: { zh: "声音已关闭", en: "Sound muted" },
|
|
47
|
+
muted_off: { zh: "声音已开启", en: "Sound unmuted" },
|
|
48
|
+
mute_desc: { zh: "控制提示音开关:action=on 开启,action=off 关闭,action=toggle 切换", en: "Control notification sound: action=on to enable, action=off to disable, action=toggle to switch" },
|
|
49
|
+
mute_template: { zh: "用户想要切换声音状态。调用 sound_toggle 工具,action 参数:on=开启,off=关闭,toggle=切换。", en: "User wants to control sound. Call sound_toggle tool: action=on to enable, action=off to disable, action=toggle to switch." },
|
|
50
|
+
mute_action: { zh: "on 开启声音 off 关闭声音 toggle 切换", en: "on enable off disable toggle switch" },
|
|
44
51
|
};
|
|
45
52
|
const T = (key, params) => {
|
|
46
53
|
const entry = TX[key] || { zh: key, en: key };
|
|
@@ -80,6 +87,7 @@ catch (e) {
|
|
|
80
87
|
log.error(T("init_failed"), e instanceof Error ? e : Error(String(e)));
|
|
81
88
|
}
|
|
82
89
|
const eventTimestamps = new Map();
|
|
90
|
+
const subSessions = new Set();
|
|
83
91
|
let globalLastPlay = 0;
|
|
84
92
|
function getPlayerArgs(sound) {
|
|
85
93
|
switch (process.platform) {
|
|
@@ -129,6 +137,8 @@ function play(eventType) {
|
|
|
129
137
|
});
|
|
130
138
|
}
|
|
131
139
|
function shouldPlay(eventType) {
|
|
140
|
+
if (muted)
|
|
141
|
+
return false;
|
|
132
142
|
if (!cfg.enabled)
|
|
133
143
|
return false;
|
|
134
144
|
if (!cfg.events?.includes(eventType))
|
|
@@ -150,10 +160,51 @@ function shouldPlay(eventType) {
|
|
|
150
160
|
export const SoundNotify = async () => {
|
|
151
161
|
log.loaded();
|
|
152
162
|
return {
|
|
163
|
+
config: async (config) => {
|
|
164
|
+
log.hook("config", "register command sound-toggle");
|
|
165
|
+
try {
|
|
166
|
+
const commands = config.command ?? {};
|
|
167
|
+
commands["sound-toggle"] = {
|
|
168
|
+
description: T("mute_desc"),
|
|
169
|
+
template: T("mute_template"),
|
|
170
|
+
};
|
|
171
|
+
config.command = commands;
|
|
172
|
+
log.info("sound-toggle command registered");
|
|
173
|
+
}
|
|
174
|
+
catch (e) {
|
|
175
|
+
log.error("command registration failed", e instanceof Error ? e : Error(String(e)));
|
|
176
|
+
}
|
|
177
|
+
},
|
|
153
178
|
event: async ({ event }) => {
|
|
154
|
-
if (
|
|
155
|
-
|
|
179
|
+
if (event.type === "session.created") {
|
|
180
|
+
const info = event.properties?.info;
|
|
181
|
+
if (info?.parentID)
|
|
182
|
+
subSessions.add(info.id);
|
|
183
|
+
return;
|
|
156
184
|
}
|
|
185
|
+
const sid = event.properties?.sessionID;
|
|
186
|
+
if (sid && subSessions.has(sid))
|
|
187
|
+
return;
|
|
188
|
+
if (shouldPlay(event.type))
|
|
189
|
+
play(event.type);
|
|
190
|
+
},
|
|
191
|
+
tool: {
|
|
192
|
+
sound_toggle: tool({
|
|
193
|
+
description: T("mute_desc"),
|
|
194
|
+
args: {
|
|
195
|
+
action: tool.schema.enum(["on", "off", "toggle"]).describe(T("mute_action")),
|
|
196
|
+
},
|
|
197
|
+
execute: async ({ action }) => {
|
|
198
|
+
if (action === "on")
|
|
199
|
+
muted = false;
|
|
200
|
+
else if (action === "off")
|
|
201
|
+
muted = true;
|
|
202
|
+
else
|
|
203
|
+
muted = !muted;
|
|
204
|
+
return T(muted ? "muted_on" : "muted_off");
|
|
205
|
+
},
|
|
206
|
+
}),
|
|
157
207
|
},
|
|
158
208
|
};
|
|
159
209
|
};
|
|
210
|
+
export default SoundNotify;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xiaoqiong0v0/opencode-sound-notify",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "OpenCode plugin: play notification sounds on session events (idle, error, permission asked).",
|
|
6
6
|
"files": [
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
".": "./dist/sound-notify.js"
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
|
-
"build": "tsc
|
|
16
|
+
"build": "tsc",
|
|
17
17
|
"prepublishOnly": "npm run build"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
@@ -28,8 +28,10 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@xiaoqiong0v0/opencode-plugin-logger": "^1.0.2"
|
|
30
30
|
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"@opencode-ai/plugin": "^1.18.0"
|
|
33
|
+
},
|
|
31
34
|
"devDependencies": {
|
|
32
|
-
"@opencode-ai/plugin": "^1.18.4",
|
|
33
35
|
"@types/node": "^26.1.1",
|
|
34
36
|
"typescript": "^7.0.2"
|
|
35
37
|
}
|