@mingxy/ocosay 1.1.25 → 1.1.27

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.25",
3
+ "version": "1.1.26",
4
4
  "description": "OpenCode TTS 播放插件 - 支持豆包模式边接收边朗读",
5
5
  "type": "module",
6
6
  "main": "dist/plugin.js",
package/dist/plugin.js CHANGED
@@ -9901,7 +9901,7 @@ import { readFileSync as readFileSync2, existsSync as existsSync7, writeFileSync
9901
9901
  import { fileURLToPath } from "url";
9902
9902
  import { dirname as dirname2, join as join8 } from "path";
9903
9903
  import { homedir as homedir3 } from "os";
9904
- import { execSync as execSync4 } from "child_process";
9904
+ import { exec, execSync as execSync4 } from "child_process";
9905
9905
  import { createRequire as createRequire2 } from "module";
9906
9906
 
9907
9907
  // src/core/dependency-detector.ts
@@ -10254,6 +10254,13 @@ async function verifyInstallation(packages) {
10254
10254
  }
10255
10255
 
10256
10256
  // src/plugin.ts
10257
+ function execAsync(cmd, cwd) {
10258
+ return new Promise((resolve) => {
10259
+ exec(cmd, { cwd, encoding: "utf8" }, (error, stdout, stderr) => {
10260
+ resolve({ stdout: stdout || "", stderr: stderr || "", error: error || void 0 });
10261
+ });
10262
+ });
10263
+ }
10257
10264
  var logger9 = createModuleLogger("Plugin");
10258
10265
  var require3 = createRequire2(import.meta.url);
10259
10266
  var opencodeBinPath = execSync4("which opencode").toString().trim();
@@ -10266,11 +10273,11 @@ function getSkipFilePath() {
10266
10273
  function shouldSkipNaudiodon() {
10267
10274
  return existsSync7(getSkipFilePath());
10268
10275
  }
10269
- function markNaudiodonSkipped() {
10276
+ async function markNaudiodonSkipped() {
10270
10277
  try {
10271
10278
  const dir = join8(homedir3(), ".config", "opencode");
10272
10279
  if (!existsSync7(dir)) {
10273
- execSync4("mkdir -p", { cwd: dir });
10280
+ await execAsync("mkdir -p", dir);
10274
10281
  }
10275
10282
  writeFileSync6(getSkipFilePath(), Date.now().toString(), "utf-8");
10276
10283
  } catch {
@@ -10288,18 +10295,14 @@ async function verifyNaudiodonLoad() {
10288
10295
  }
10289
10296
  async function rebuildNaudiodonDependency(dep) {
10290
10297
  const naudiodonPath = dirname2(require3.resolve("naudiodon"));
10291
- try {
10292
- notificationService.info(`\u6B63\u5728\u7F16\u8BD1 ${dep}...`, "Ocosay \u4F9D\u8D56", 4e3);
10293
- execSync4(`npm rebuild ${dep}`, {
10294
- cwd: naudiodonPath,
10295
- stdio: "inherit"
10296
- });
10297
- logger9.info(`${dep} rebuilt successfully`);
10298
- return true;
10299
- } catch (err) {
10300
- logger9.warn({ err }, `${dep} rebuild failed`);
10298
+ notificationService.info(`\u6B63\u5728\u7F16\u8BD1 ${dep}...`, "Ocosay \u4F9D\u8D56", 4e3);
10299
+ const result = await execAsync(`npm rebuild ${dep}`, naudiodonPath);
10300
+ if (result.error) {
10301
+ logger9.warn({ err: result.error }, `${dep} rebuild failed`);
10301
10302
  return false;
10302
10303
  }
10304
+ logger9.info(`${dep} rebuilt successfully`);
10305
+ return true;
10303
10306
  }
10304
10307
  async function fixNaudiodonDependencies(maxRetries = 5) {
10305
10308
  const naudiodonPath = dirname2(require3.resolve("naudiodon"));
@@ -10318,30 +10321,24 @@ async function fixNaudiodonDependencies(maxRetries = 5) {
10318
10321
  anySuccess = true;
10319
10322
  }
10320
10323
  } catch {
10321
- try {
10322
- notificationService.info(`\u6B63\u5728\u5B89\u88C5 ${dep}...`, "Ocosay", 4e3);
10323
- execSync4(`npm install ${dep}`, {
10324
- cwd: naudiodonPath,
10325
- stdio: "inherit"
10326
- });
10324
+ notificationService.info(`\u6B63\u5728\u5B89\u88C5 ${dep}...`, "Ocosay", 4e3);
10325
+ const installResult = await execAsync(`npm install ${dep}`, naudiodonPath);
10326
+ if (installResult.error) {
10327
+ logger9.warn({ err: installResult.error }, `${dep} install failed`);
10328
+ } else {
10327
10329
  logger9.info(`${dep} installed successfully`);
10328
10330
  anySuccess = true;
10329
- } catch (installErr) {
10330
- logger9.warn({ err: installErr }, `${dep} install failed`);
10331
10331
  }
10332
10332
  }
10333
10333
  }
10334
10334
  if (!anySuccess || !await verifyNaudiodonLoad()) {
10335
- try {
10336
- notificationService.info("\u6B63\u5728\u91CD\u65B0\u7F16\u8BD1 naudiodon...", "Ocosay", 4e3);
10337
- execSync4("npm rebuild naudiodon", {
10338
- cwd: naudiodonPath,
10339
- stdio: "inherit"
10340
- });
10335
+ notificationService.info("\u6B63\u5728\u91CD\u65B0\u7F16\u8BD1 naudiodon...", "Ocosay", 4e3);
10336
+ const rebuildResult = await execAsync("npm rebuild naudiodon", naudiodonPath);
10337
+ if (rebuildResult.error) {
10338
+ logger9.warn({ err: rebuildResult.error }, "naudiodon rebuild failed");
10339
+ } else {
10341
10340
  logger9.info("naudiodon rebuilt");
10342
10341
  anySuccess = true;
10343
- } catch (err) {
10344
- logger9.warn({ err }, "naudiodon rebuild failed");
10345
10342
  }
10346
10343
  }
10347
10344
  if (await verifyNaudiodonLoad()) {
@@ -10369,21 +10366,52 @@ async function ensureNaudiodonCompiled() {
10369
10366
  try {
10370
10367
  const naudiodonPath = dirname2(require3.resolve("naudiodon"));
10371
10368
  logger9.info({ naudiodonPath }, "found naudiodon, rebuilding");
10372
- execSync4("npm rebuild naudiodon", {
10373
- cwd: naudiodonPath,
10374
- stdio: "inherit"
10375
- });
10376
- logger9.info("naudiodon compiled, verifying...");
10377
- const loadSuccess = await verifyNaudiodonLoad();
10378
- if (loadSuccess) {
10379
- notificationService.success("naudiodon \u7F16\u8BD1\u6210\u529F", "\u97F3\u9891\u540E\u7AEF\u5DF2\u5C31\u7EEA", 5e3);
10369
+ const rebuildResult = await execAsync("npm rebuild naudiodon", naudiodonPath);
10370
+ if (rebuildResult.error) {
10371
+ logger9.warn({ err: rebuildResult.error }, "naudiodon rebuild failed, checking for PortAudio");
10372
+ notificationService.warning("naudiodon \u7F16\u8BD1\u5931\u8D25", "\u6B63\u5728\u5C1D\u8BD5\u5B89\u88C5 PortAudio...", 5e3);
10373
+ const installed = await installPortAudio();
10374
+ if (installed.success) {
10375
+ const retryPath = dirname2(require3.resolve("naudiodon"));
10376
+ notificationService.info("\u6B63\u5728\u91CD\u65B0\u7F16\u8BD1 naudiodon...", "Ocosay", 5e3);
10377
+ const retryResult = await execAsync("npm rebuild naudiodon", retryPath);
10378
+ if (retryResult.error) {
10379
+ logger9.error({ err: retryResult.error }, "naudiodon compile failed even after PortAudio install");
10380
+ notificationService.error("naudiodon \u7F16\u8BD1\u5931\u8D25", "\u81EA\u52A8\u5B89\u88C5\u5931\u8D25\uFF0C\u8BF7\u5C1D\u8BD5\u624B\u52A8\u5B89\u88C5", 8e3);
10381
+ markNaudiodonSkipped();
10382
+ } else {
10383
+ logger9.info("naudiodon compiled successfully after PortAudio install");
10384
+ const loadSuccess = await verifyNaudiodonLoad();
10385
+ if (loadSuccess) {
10386
+ notificationService.success("naudiodon \u7F16\u8BD1\u6210\u529F", "\u97F3\u9891\u540E\u7AEF\u5DF2\u5C31\u7EEA", 5e3);
10387
+ } else {
10388
+ notificationService.warning("naudiodon \u52A0\u8F7D\u5931\u8D25", "\u6B63\u5728\u68C0\u67E5\u4F9D\u8D56...", 5e3);
10389
+ const fixed = await fixNaudiodonDependencies();
10390
+ if (fixed) {
10391
+ notificationService.success("naudiodon \u4F9D\u8D56\u4FEE\u590D\u6210\u529F", "\u97F3\u9891\u540E\u7AEF\u5DF2\u5C31\u7EEA", 5e3);
10392
+ } else {
10393
+ markNaudiodonSkipped();
10394
+ }
10395
+ }
10396
+ }
10397
+ } else {
10398
+ logger9.error("PortAudio install failed");
10399
+ notificationService.error("PortAudio \u5B89\u88C5\u5931\u8D25", "\u81EA\u52A8\u5B89\u88C5\u5931\u8D25\uFF0C\u8BF7\u5C1D\u8BD5\u624B\u52A8\u5B89\u88C5", 8e3);
10400
+ markNaudiodonSkipped();
10401
+ }
10380
10402
  } else {
10381
- notificationService.warning("naudiodon \u52A0\u8F7D\u5931\u8D25", "\u6B63\u5728\u68C0\u67E5\u4F9D\u8D56...", 5e3);
10382
- const fixed = await fixNaudiodonDependencies();
10383
- if (fixed) {
10384
- notificationService.success("naudiodon \u4F9D\u8D56\u4FEE\u590D\u6210\u529F", "\u97F3\u9891\u540E\u7AEF\u5DF2\u5C31\u7EEA", 5e3);
10403
+ logger9.info("naudiodon compiled, verifying...");
10404
+ const loadSuccess = await verifyNaudiodonLoad();
10405
+ if (loadSuccess) {
10406
+ notificationService.success("naudiodon \u7F16\u8BD1\u6210\u529F", "\u97F3\u9891\u540E\u7AEF\u5DF2\u5C31\u7EEA", 5e3);
10385
10407
  } else {
10386
- throw new Error("naudiodon dependencies could not be fixed");
10408
+ notificationService.warning("naudiodon \u52A0\u8F7D\u5931\u8D25", "\u6B63\u5728\u68C0\u67E5\u4F9D\u8D56...", 5e3);
10409
+ const fixed = await fixNaudiodonDependencies();
10410
+ if (fixed) {
10411
+ notificationService.success("naudiodon \u4F9D\u8D56\u4FEE\u590D\u6210\u529F", "\u97F3\u9891\u540E\u7AEF\u5DF2\u5C31\u7EEA", 5e3);
10412
+ } else {
10413
+ markNaudiodonSkipped();
10414
+ }
10387
10415
  }
10388
10416
  }
10389
10417
  } catch (err) {
@@ -10391,13 +10419,14 @@ async function ensureNaudiodonCompiled() {
10391
10419
  notificationService.warning("naudiodon \u7F16\u8BD1\u5931\u8D25", "\u6B63\u5728\u5C1D\u8BD5\u5B89\u88C5 PortAudio...", 5e3);
10392
10420
  const installed = await installPortAudio();
10393
10421
  if (installed.success) {
10394
- try {
10395
- const naudiodonPath = dirname2(require3.resolve("naudiodon"));
10396
- notificationService.info("\u6B63\u5728\u91CD\u65B0\u7F16\u8BD1 naudiodon...", "Ocosay", 5e3);
10397
- execSync4("npm rebuild naudiodon", {
10398
- cwd: naudiodonPath,
10399
- stdio: "inherit"
10400
- });
10422
+ const retryPath = dirname2(require3.resolve("naudiodon"));
10423
+ notificationService.info("\u6B63\u5728\u91CD\u65B0\u7F16\u8BD1 naudiodon...", "Ocosay", 5e3);
10424
+ const retryResult = await execAsync("npm rebuild naudiodon", retryPath);
10425
+ if (retryResult.error) {
10426
+ logger9.error({ err: retryResult.error }, "naudiodon compile failed even after PortAudio install");
10427
+ notificationService.error("naudiodon \u7F16\u8BD1\u5931\u8D25", "\u81EA\u52A8\u5B89\u88C5\u5931\u8D25\uFF0C\u8BF7\u5C1D\u8BD5\u624B\u52A8\u5B89\u88C5", 8e3);
10428
+ markNaudiodonSkipped();
10429
+ } else {
10401
10430
  logger9.info("naudiodon compiled successfully after PortAudio install");
10402
10431
  const loadSuccess = await verifyNaudiodonLoad();
10403
10432
  if (loadSuccess) {
@@ -10408,13 +10437,9 @@ async function ensureNaudiodonCompiled() {
10408
10437
  if (fixed) {
10409
10438
  notificationService.success("naudiodon \u4F9D\u8D56\u4FEE\u590D\u6210\u529F", "\u97F3\u9891\u540E\u7AEF\u5DF2\u5C31\u7EEA", 5e3);
10410
10439
  } else {
10411
- throw new Error("naudiodon dependencies could not be fixed");
10440
+ markNaudiodonSkipped();
10412
10441
  }
10413
10442
  }
10414
- } catch (retryErr) {
10415
- logger9.error({ err: retryErr }, "naudiodon compile failed even after PortAudio install");
10416
- notificationService.error("naudiodon \u7F16\u8BD1\u5931\u8D25", "\u81EA\u52A8\u5B89\u88C5\u5931\u8D25\uFF0C\u8BF7\u5C1D\u8BD5\u624B\u52A8\u5B89\u88C5", 8e3);
10417
- markNaudiodonSkipped();
10418
10443
  }
10419
10444
  } else {
10420
10445
  logger9.error("PortAudio install failed");
@@ -10451,24 +10476,17 @@ async function tryCompileSpeaker() {
10451
10476
  }
10452
10477
  }
10453
10478
  if (!isModuleInstalled(dep)) {
10454
- try {
10455
- execSync4("npm install speaker", {
10456
- cwd: opencodeNodeModules,
10457
- stdio: "pipe"
10458
- });
10459
- } catch {
10479
+ const installResult = await execAsync("npm install speaker", opencodeNodeModules);
10480
+ if (installResult.error) {
10481
+ logger9.warn({ err: installResult.error }, "speaker install failed");
10460
10482
  }
10461
10483
  }
10462
- try {
10463
- execSync4("npm rebuild speaker", {
10464
- cwd: opencodeNodeModules,
10465
- stdio: "pipe"
10466
- });
10467
- if (await verifyModuleLoad(dep)) {
10468
- result.success = true;
10469
- }
10470
- } catch (err) {
10471
- result.stderr = err.stderr?.toString() || err.message || "";
10484
+ const rebuildResult = await execAsync("npm rebuild speaker", opencodeNodeModules);
10485
+ if (rebuildResult.error) {
10486
+ result.stderr = rebuildResult.stderr || rebuildResult.error.message || "";
10487
+ }
10488
+ if (await verifyModuleLoad(dep)) {
10489
+ result.success = true;
10472
10490
  }
10473
10491
  return result;
10474
10492
  }
@@ -10517,14 +10535,11 @@ async function ensureSpeakerCompiled(maxRetries = 5) {
10517
10535
  }
10518
10536
  logger9.info("speaker installed but not loadable, rebuilding");
10519
10537
  notificationService.info("\u6B63\u5728\u7F16\u8BD1 speaker...", "Ocosay \u97F3\u9891\u540E\u7AEF", 5e3);
10520
- try {
10521
- execSync4("npm rebuild speaker", {
10522
- cwd: opencodeNodeModules,
10523
- stdio: "inherit"
10524
- });
10538
+ const rebuildResult = await execAsync("npm rebuild speaker", opencodeNodeModules);
10539
+ if (rebuildResult.error) {
10540
+ logger9.warn({ err: rebuildResult.error }, "speaker rebuild failed");
10541
+ } else {
10525
10542
  logger9.info("speaker rebuilt");
10526
- } catch (err) {
10527
- logger9.warn({ err }, "speaker rebuild failed");
10528
10543
  }
10529
10544
  if (await verifyModuleLoad(dep)) {
10530
10545
  notificationService.success("speaker \u7F16\u8BD1\u6210\u529F", "\u97F3\u9891\u540E\u7AEF\u5DF2\u5C31\u7EEA", 5e3);
@@ -10533,14 +10548,11 @@ async function ensureSpeakerCompiled(maxRetries = 5) {
10533
10548
  } else {
10534
10549
  logger9.info("speaker not found, installing");
10535
10550
  notificationService.info("\u6B63\u5728\u5B89\u88C5 speaker...", "Ocosay \u97F3\u9891\u540E\u7AEF", 5e3);
10536
- try {
10537
- execSync4("npm install speaker", {
10538
- cwd: opencodeNodeModules,
10539
- stdio: "inherit"
10540
- });
10551
+ const installResult = await execAsync("npm install speaker", opencodeNodeModules);
10552
+ if (installResult.error) {
10553
+ logger9.warn({ err: installResult.error }, "speaker install failed");
10554
+ } else {
10541
10555
  logger9.info("speaker installed");
10542
- } catch (err) {
10543
- logger9.warn({ err }, "speaker install failed");
10544
10556
  }
10545
10557
  }
10546
10558
  for (let attempt = 0; attempt < maxRetries; attempt++) {
@@ -10550,14 +10562,11 @@ async function ensureSpeakerCompiled(maxRetries = 5) {
10550
10562
  }
10551
10563
  logger9.info({ attempt, dep }, "speaker not loadable, trying rebuild");
10552
10564
  notificationService.info(`\u6B63\u5728\u91CD\u65B0\u7F16\u8BD1 speaker (${attempt + 1}/${maxRetries})...`, "Ocosay", 3e3);
10553
- try {
10554
- execSync4("npm rebuild speaker", {
10555
- cwd: opencodeNodeModules,
10556
- stdio: "inherit"
10557
- });
10565
+ const rebuildResult = await execAsync("npm rebuild speaker", opencodeNodeModules);
10566
+ if (rebuildResult.error) {
10567
+ logger9.warn({ err: rebuildResult.error }, "speaker rebuild failed");
10568
+ } else {
10558
10569
  logger9.info("speaker rebuilt");
10559
- } catch (err) {
10560
- logger9.warn({ err }, "speaker rebuild failed");
10561
10570
  }
10562
10571
  if (await verifyModuleLoad(dep)) {
10563
10572
  notificationService.success("speaker \u7F16\u8BD1\u6210\u529F", "\u97F3\u9891\u540E\u7AEF\u5DF2\u5C31\u7EEA", 5e3);
@@ -10580,14 +10589,9 @@ async function ensurePlaySoundInstalled() {
10580
10589
  }
10581
10590
  logger9.info("play-sound not found, installing");
10582
10591
  notificationService.info("\u6B63\u5728\u5B89\u88C5 play-sound...", "Ocosay \u97F3\u9891\u540E\u7AEF", 5e3);
10583
- try {
10584
- execSync4("npm install play-sound", {
10585
- cwd: opencodeNodeModules,
10586
- stdio: "inherit"
10587
- });
10588
- logger9.info("play-sound installed");
10589
- } catch (err) {
10590
- logger9.warn({ err }, "play-sound install failed");
10592
+ const installResult = await execAsync("npm install play-sound", opencodeNodeModules);
10593
+ if (installResult.error) {
10594
+ logger9.warn({ err: installResult.error }, "play-sound install failed");
10591
10595
  notificationService.warning(
10592
10596
  "play-sound \u5B89\u88C5\u5931\u8D25",
10593
10597
  "\u8BF7\u624B\u52A8\u8FD0\u884C: npm install play-sound",
@@ -10595,6 +10599,7 @@ async function ensurePlaySoundInstalled() {
10595
10599
  );
10596
10600
  return;
10597
10601
  }
10602
+ logger9.info("play-sound installed");
10598
10603
  if (await verifyModuleLoad(dep)) {
10599
10604
  notificationService.success("play-sound \u5B89\u88C5\u6210\u529F", "\u97F3\u9891\u540E\u7AEF\u5DF2\u5C31\u7EEA", 5e3);
10600
10605
  } else {
@@ -10661,18 +10666,16 @@ async function installPortAudio() {
10661
10666
  const runInstall = async (cmd, desc) => {
10662
10667
  logger9.info(`Running: ${cmd}`);
10663
10668
  notificationService.info(desc, "\u6B63\u5728\u5B89\u88C5...", 5e3);
10664
- try {
10665
- execSync4(cmd, { stdio: "inherit" });
10666
- return true;
10667
- } catch (err) {
10668
- const msg = err.message || "";
10669
+ const result = await execAsync(cmd);
10670
+ if (result.error) {
10671
+ const msg = result.error.message || "";
10669
10672
  if (msg.includes("sudo") || msg.includes("password") || msg.includes("Password")) {
10670
10673
  notificationService.error(
10671
10674
  "\u9700\u8981 sudo \u6743\u9650",
10672
10675
  "# \u8BF7\u5728WSL\u7EC8\u7AEF\u6267\u884C\u4E00\u6B21\nsudo visudo\n# \u6DFB\u52A0\u884C\uFF1Ayour user name ALL=(ALL) NOPASSWD: ALL",
10673
10676
  1e4
10674
10677
  );
10675
- logger9.error({ err }, "\u9700\u8981 sudo \u6743\u9650 \u8BF7\u5728WSL\u7EC8\u7AEF\u6267\u884C\u4E00\u6B21sudo visudo # \u6DFB\u52A0\u884C\uFF1Ayour user name ALL=(ALL) NOPASSWD: ALL");
10678
+ logger9.error({ err: result.error }, "\u9700\u8981 sudo \u6743\u9650 \u8BF7\u5728WSL\u7EC8\u7AEF\u6267\u884C\u4E00\u6B21sudo visudo # \u6DFB\u52A0\u884C\uFF1Ayour user name ALL=(ALL) NOPASSWD: ALL");
10676
10679
  return false;
10677
10680
  }
10678
10681
  if (msg.includes("already") || msg.includes("is already")) {
@@ -10680,9 +10683,10 @@ async function installPortAudio() {
10680
10683
  return true;
10681
10684
  }
10682
10685
  notificationService.error(desc + " \u5931\u8D25", msg.substring(0, 100), 8e3);
10683
- logger9.error({ err }, `install failed: ${desc}`);
10686
+ logger9.error({ err: result.error }, `install failed: ${desc}`);
10684
10687
  return false;
10685
10688
  }
10689
+ return true;
10686
10690
  };
10687
10691
  if (platform === "linux" || wsl) {
10688
10692
  notificationService.info("\u68C0\u6D4B ffmpeg...", "\u97F3\u9891\u540E\u7AEF", 5e3);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mingxy/ocosay",
3
- "version": "1.1.25",
3
+ "version": "1.1.27",
4
4
  "description": "OpenCode TTS 播放插件 - 支持豆包模式边接收边朗读",
5
5
  "type": "module",
6
6
  "main": "dist/plugin.js",