@xiaoqiong0v0/opencode-sound-notify 1.1.3 → 1.1.6
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 +41 -0
- 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,16 @@ 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: "开/关提示音", en: "Toggle notification sound" },
|
|
49
|
+
mute_template: { zh: "用户想要切换声音状态。调用 sound_toggle 工具。", en: "User wants to toggle sound. Call sound_toggle tool." },
|
|
44
50
|
};
|
|
45
51
|
const T = (key, params) => {
|
|
46
52
|
const entry = TX[key] || { zh: key, en: key };
|
|
@@ -129,6 +135,8 @@ function play(eventType) {
|
|
|
129
135
|
});
|
|
130
136
|
}
|
|
131
137
|
function shouldPlay(eventType) {
|
|
138
|
+
if (muted)
|
|
139
|
+
return false;
|
|
132
140
|
if (!cfg.enabled)
|
|
133
141
|
return false;
|
|
134
142
|
if (!cfg.events?.includes(eventType))
|
|
@@ -150,10 +158,43 @@ function shouldPlay(eventType) {
|
|
|
150
158
|
export const SoundNotify = async () => {
|
|
151
159
|
log.loaded();
|
|
152
160
|
return {
|
|
161
|
+
config: async (config) => {
|
|
162
|
+
log.hook("config", "register command sound-toggle");
|
|
163
|
+
try {
|
|
164
|
+
const commands = config.command ?? {};
|
|
165
|
+
commands["sound-toggle"] = {
|
|
166
|
+
description: T("mute_desc"),
|
|
167
|
+
template: T("mute_template"),
|
|
168
|
+
};
|
|
169
|
+
config.command = commands;
|
|
170
|
+
log.info("sound-toggle command registered");
|
|
171
|
+
}
|
|
172
|
+
catch (e) {
|
|
173
|
+
log.error("command registration failed", e instanceof Error ? e : Error(String(e)));
|
|
174
|
+
}
|
|
175
|
+
},
|
|
153
176
|
event: async ({ event }) => {
|
|
154
177
|
if (shouldPlay(event.type)) {
|
|
155
178
|
play(event.type);
|
|
156
179
|
}
|
|
157
180
|
},
|
|
181
|
+
tool: {
|
|
182
|
+
sound_toggle: tool({
|
|
183
|
+
description: T("mute_desc"),
|
|
184
|
+
args: {
|
|
185
|
+
action: tool.schema.enum(["on", "off", "toggle"]).optional().describe("on=开启 off=关闭 toggle=切换"),
|
|
186
|
+
},
|
|
187
|
+
execute: async ({ action }) => {
|
|
188
|
+
if (action === "on")
|
|
189
|
+
muted = false;
|
|
190
|
+
else if (action === "off")
|
|
191
|
+
muted = true;
|
|
192
|
+
else
|
|
193
|
+
muted = !muted;
|
|
194
|
+
return T(muted ? "muted_on" : "muted_off");
|
|
195
|
+
},
|
|
196
|
+
}),
|
|
197
|
+
},
|
|
158
198
|
};
|
|
159
199
|
};
|
|
200
|
+
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.6",
|
|
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
|
}
|