@mingxy/ocosay 1.1.19 → 1.1.21

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/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mingxy/ocosay",
3
- "version": "1.1.18",
3
+ "version": "1.1.20",
4
4
  "description": "OpenCode TTS 播放插件 - 支持豆包模式边接收边朗读",
5
5
  "type": "module",
6
6
  "main": "dist/plugin.js",
package/dist/plugin.js CHANGED
@@ -9899,6 +9899,8 @@ import { execSync as execSync2 } from "child_process";
9899
9899
  import { createRequire } from "module";
9900
9900
  var logger8 = createModuleLogger("Plugin");
9901
9901
  var require2 = createRequire(import.meta.url);
9902
+ var opencodeNodeModules = join8(dirname2(require2.resolve("@opencode-ai/plugin")), "..", "..");
9903
+ var pluginRequire = createRequire(join8(opencodeNodeModules, "package.json"));
9902
9904
  function getSkipFilePath() {
9903
9905
  return join8(homedir3(), ".config", "opencode", ".naudiodon_skip");
9904
9906
  }
@@ -10062,9 +10064,17 @@ async function ensureNaudiodonCompiled() {
10062
10064
  }
10063
10065
  }
10064
10066
  }
10067
+ function isModuleInstalled(moduleName) {
10068
+ try {
10069
+ pluginRequire.resolve(moduleName);
10070
+ return true;
10071
+ } catch {
10072
+ return false;
10073
+ }
10074
+ }
10065
10075
  async function verifyModuleLoad(dep) {
10066
10076
  try {
10067
- require2(dep);
10077
+ pluginRequire(dep);
10068
10078
  logger8.info(`${dep} loaded successfully`);
10069
10079
  return true;
10070
10080
  } catch (err) {
@@ -10074,64 +10084,79 @@ async function verifyModuleLoad(dep) {
10074
10084
  }
10075
10085
  async function ensureSpeakerCompiled(maxRetries = 5) {
10076
10086
  const dep = "speaker";
10077
- const basePath = dirname2(require2.resolve("./package.json"));
10078
- if (await verifyModuleLoad(dep)) {
10079
- return;
10080
- }
10081
- try {
10082
- require2.resolve(dep);
10083
- logger8.info("speaker found, rebuilding");
10087
+ if (isModuleInstalled(dep)) {
10088
+ logger8.info("speaker already installed");
10089
+ if (await verifyModuleLoad(dep)) {
10090
+ return;
10091
+ }
10092
+ logger8.info("speaker installed but not loadable, rebuilding");
10084
10093
  notificationService.info("\u6B63\u5728\u7F16\u8BD1 speaker...", "Ocosay \u97F3\u9891\u540E\u7AEF", 5e3);
10085
- execSync2("npm rebuild speaker", {
10086
- cwd: basePath,
10087
- stdio: "inherit"
10088
- });
10089
- logger8.info("speaker rebuilt, verifying...");
10090
- } catch {
10091
- logger8.info("speaker not found or rebuild failed, installing");
10092
- notificationService.info("\u6B63\u5728\u5B89\u88C5 speaker...", "Ocosay \u97F3\u9891\u540E\u7AEF", 5e3);
10093
- }
10094
- for (let attempt = 0; attempt < maxRetries; attempt++) {
10094
+ try {
10095
+ execSync2("npm rebuild speaker", {
10096
+ cwd: opencodeNodeModules,
10097
+ stdio: "inherit"
10098
+ });
10099
+ logger8.info("speaker rebuilt");
10100
+ } catch (err) {
10101
+ logger8.warn({ err }, "speaker rebuild failed");
10102
+ }
10095
10103
  if (await verifyModuleLoad(dep)) {
10096
10104
  notificationService.success("speaker \u7F16\u8BD1\u6210\u529F", "\u97F3\u9891\u540E\u7AEF\u5DF2\u5C31\u7EEA", 5e3);
10097
10105
  return;
10098
10106
  }
10099
- logger8.info({ attempt, dep }, "speaker not loadable, trying reinstall");
10100
- notificationService.info(`\u6B63\u5728\u91CD\u65B0\u5B89\u88C5 speaker (${attempt + 1}/${maxRetries})...`, "Ocosay", 3e3);
10107
+ } else {
10108
+ logger8.info("speaker not found, installing");
10109
+ notificationService.info("\u6B63\u5728\u5B89\u88C5 speaker...", "Ocosay \u97F3\u9891\u540E\u7AEF", 5e3);
10101
10110
  try {
10102
10111
  execSync2("npm install speaker", {
10103
- cwd: basePath,
10112
+ cwd: opencodeNodeModules,
10104
10113
  stdio: "inherit"
10105
10114
  });
10106
10115
  logger8.info("speaker installed");
10107
10116
  } catch (err) {
10108
10117
  logger8.warn({ err }, "speaker install failed");
10109
10118
  }
10119
+ }
10120
+ for (let attempt = 0; attempt < maxRetries; attempt++) {
10110
10121
  if (await verifyModuleLoad(dep)) {
10111
- notificationService.success("speaker \u5B89\u88C5\u6210\u529F", "\u97F3\u9891\u540E\u7AEF\u5DF2\u5C31\u7EEA", 5e3);
10122
+ notificationService.success("speaker \u7F16\u8BD1\u6210\u529F", "\u97F3\u9891\u540E\u7AEF\u5DF2\u5C31\u7EEA", 5e3);
10123
+ return;
10124
+ }
10125
+ logger8.info({ attempt, dep }, "speaker not loadable, trying rebuild");
10126
+ notificationService.info(`\u6B63\u5728\u91CD\u65B0\u7F16\u8BD1 speaker (${attempt + 1}/${maxRetries})...`, "Ocosay", 3e3);
10127
+ try {
10128
+ execSync2("npm rebuild speaker", {
10129
+ cwd: opencodeNodeModules,
10130
+ stdio: "inherit"
10131
+ });
10132
+ logger8.info("speaker rebuilt");
10133
+ } catch (err) {
10134
+ logger8.warn({ err }, "speaker rebuild failed");
10135
+ }
10136
+ if (await verifyModuleLoad(dep)) {
10137
+ notificationService.success("speaker \u7F16\u8BD1\u6210\u529F", "\u97F3\u9891\u540E\u7AEF\u5DF2\u5C31\u7EEA", 5e3);
10112
10138
  return;
10113
10139
  }
10114
10140
  if (attempt < maxRetries - 1) {
10115
10141
  await new Promise((resolve) => setTimeout(resolve, 1e3));
10116
10142
  }
10117
10143
  }
10118
- if (await verifyModuleLoad(dep)) {
10119
- notificationService.success("speaker \u7F16\u8BD1\u6210\u529F", "\u97F3\u9891\u540E\u7AEF\u5DF2\u5C31\u7EEA", 5e3);
10120
- } else {
10121
- logger8.error({ dep }, "speaker could not be compiled");
10122
- notificationService.error("speaker \u7F16\u8BD1\u5931\u8D25", "\u8BF7\u624B\u52A8\u8FD0\u884C: npm install speaker && npm rebuild speaker", 8e3);
10123
- }
10144
+ logger8.error({ dep }, "speaker could not be compiled");
10145
+ notificationService.error("speaker \u7F16\u8BD1\u5931\u8D25", "\u8BF7\u624B\u52A8\u8FD0\u884C: npm install speaker && npm rebuild speaker", 8e3);
10124
10146
  }
10125
10147
  async function ensurePlaySoundInstalled() {
10126
10148
  const dep = "play-sound";
10127
- const basePath = dirname2(require2.resolve("./package.json"));
10128
- if (await verifyModuleLoad(dep)) {
10129
- return;
10149
+ if (isModuleInstalled(dep)) {
10150
+ logger8.info("play-sound already installed");
10151
+ if (await verifyModuleLoad(dep)) {
10152
+ return;
10153
+ }
10130
10154
  }
10155
+ logger8.info("play-sound not found, installing");
10131
10156
  notificationService.info("\u6B63\u5728\u5B89\u88C5 play-sound...", "Ocosay \u97F3\u9891\u540E\u7AEF", 5e3);
10132
10157
  try {
10133
10158
  execSync2("npm install play-sound", {
10134
- cwd: basePath,
10159
+ cwd: opencodeNodeModules,
10135
10160
  stdio: "inherit"
10136
10161
  });
10137
10162
  logger8.info("play-sound installed");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mingxy/ocosay",
3
- "version": "1.1.19",
3
+ "version": "1.1.21",
4
4
  "description": "OpenCode TTS 播放插件 - 支持豆包模式边接收边朗读",
5
5
  "type": "module",
6
6
  "main": "dist/plugin.js",