@mingxy/ocosay 1.1.31 → 1.1.32

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.30",
3
+ "version": "1.1.31",
4
4
  "description": "OpenCode TTS 播放插件 - 支持豆包模式边接收边朗读",
5
5
  "type": "module",
6
6
  "main": "dist/plugin.js",
package/dist/plugin.js CHANGED
@@ -2437,7 +2437,7 @@ var require_thread_stream = __commonJS({
2437
2437
  var require_transport = __commonJS({
2438
2438
  "node_modules/pino/lib/transport.js"(exports, module) {
2439
2439
  "use strict";
2440
- var { createRequire: createRequire3 } = __require("module");
2440
+ var { createRequire: createRequire2 } = __require("module");
2441
2441
  var { existsSync: existsSync8 } = __require("node:fs");
2442
2442
  var getCallers = require_caller();
2443
2443
  var { join: join9, isAbsolute, sep } = __require("node:path");
@@ -2640,7 +2640,7 @@ var require_transport = __commonJS({
2640
2640
  for (const filePath of callers) {
2641
2641
  try {
2642
2642
  const context = filePath === "node:repl" ? process.cwd() + sep : filePath;
2643
- fixTarget2 = createRequire3(context).resolve(origin);
2643
+ fixTarget2 = createRequire2(context).resolve(origin);
2644
2644
  break;
2645
2645
  } catch (err) {
2646
2646
  continue;
@@ -9901,360 +9901,8 @@ 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 { exec, execSync as execSync4 } from "child_process";
9905
- import { createRequire as createRequire2 } from "module";
9906
-
9907
- // src/core/dependency-detector.ts
9908
- import { execSync as execSync2 } from "child_process";
9909
- function parseMissingHeaders(errorOutput) {
9910
- const pattern = /fatal error:\s+([^:]+):\s+No such file or directory/g;
9911
- const headers = [];
9912
- let match = pattern.exec(errorOutput);
9913
- while (match !== null) {
9914
- headers.push(match[1]);
9915
- match = pattern.exec(errorOutput);
9916
- }
9917
- return headers;
9918
- }
9919
- function execCapture(cmd, cwd) {
9920
- try {
9921
- const stdout = execSync2(cmd, {
9922
- cwd,
9923
- encoding: "utf8",
9924
- stdio: ["pipe", "pipe", "pipe"]
9925
- });
9926
- return { success: true, stdout, stderr: "" };
9927
- } catch (err) {
9928
- const error = err;
9929
- return {
9930
- success: false,
9931
- stdout: error.stdout ? error.stdout.toString() : "",
9932
- stderr: error.stderr ? error.stderr.toString() : ""
9933
- };
9934
- }
9935
- }
9936
- function detectMissingDependencies(errorOutput) {
9937
- const missingHeaders = parseMissingHeaders(errorOutput);
9938
- return {
9939
- missingHeaders,
9940
- rawOutput: errorOutput
9941
- };
9942
- }
9943
-
9944
- // src/core/dependency-mapper.ts
9904
+ import { exec, execSync as execSync2 } from "child_process";
9945
9905
  import { createRequire } from "module";
9946
- var require2 = createRequire(import.meta.url);
9947
- var HEADER_TO_PACKAGE = [
9948
- // ALSA - Linux音频库
9949
- {
9950
- header: "alsa/asoundlib.h",
9951
- package: "libasound2-dev"
9952
- },
9953
- // PortAudio - 跨平台音频I/O库
9954
- {
9955
- header: "portaudio.h",
9956
- package: "libportaudio-dev",
9957
- packageMac: "portaudio",
9958
- packageWin: "portaudio"
9959
- },
9960
- // FFmpeg相关
9961
- {
9962
- header: "libavcodec/avcodec.h",
9963
- package: "libavcodec-dev",
9964
- packageMac: "ffmpeg",
9965
- packageWin: "ffmpeg"
9966
- },
9967
- {
9968
- header: "libavformat/avformat.h",
9969
- package: "libavformat-dev",
9970
- packageMac: "ffmpeg",
9971
- packageWin: "ffmpeg"
9972
- },
9973
- {
9974
- header: "libavutil/avutil.h",
9975
- package: "libavutil-dev",
9976
- packageMac: "ffmpeg",
9977
- packageWin: "ffmpeg"
9978
- },
9979
- {
9980
- header: "libswresample/swresample.h",
9981
- package: "libswresample-dev",
9982
- packageMac: "ffmpeg",
9983
- packageWin: "ffmpeg"
9984
- },
9985
- // OpenAL - 3D音频API
9986
- {
9987
- header: "AL/al.h",
9988
- package: "libopenal-dev",
9989
- packageMac: "openal",
9990
- packageWin: "openal"
9991
- },
9992
- // SDL - 多媒体库
9993
- {
9994
- header: "SDL2/SDL.h",
9995
- package: "libsdl2-dev",
9996
- packageMac: "sdl2",
9997
- packageWin: "sdl2"
9998
- },
9999
- // PulseAudio - Linux音频服务
10000
- {
10001
- header: "pulse/pulseaudio.h",
10002
- package: "libpulse-dev"
10003
- },
10004
- // CoreAudio - macOS音频框架 (无头文件,纯框架)
10005
- {
10006
- header: "CoreAudio/CoreAudio.h",
10007
- package: "\u81FA",
10008
- // macOS系统框架,无需安装包
10009
- packageMac: ""
10010
- },
10011
- // Windows特定
10012
- {
10013
- header: "windows.h",
10014
- package: "",
10015
- // Linux上不存在
10016
- packageWin: ""
10017
- // Windows SDK自带
10018
- }
10019
- ];
10020
- function detectPlatform() {
10021
- const platform = process.platform;
10022
- const isWsl3 = detectWsl();
10023
- let packageManager;
10024
- let installCommand;
10025
- if (platform === "linux" || isWsl3) {
10026
- packageManager = "apt-get";
10027
- installCommand = "sudo apt-get install -y";
10028
- } else if (platform === "darwin") {
10029
- packageManager = "brew";
10030
- installCommand = "brew install";
10031
- } else {
10032
- packageManager = "choco";
10033
- installCommand = "choco install -y";
10034
- }
10035
- return {
10036
- platform,
10037
- isWsl: isWsl3,
10038
- packageManager,
10039
- installCommand
10040
- };
10041
- }
10042
- function detectWsl() {
10043
- if (process.platform !== "linux") return false;
10044
- try {
10045
- return require2("fs").readFileSync("/proc/version", "utf8").toLowerCase().includes("microsoft");
10046
- } catch {
10047
- return false;
10048
- }
10049
- }
10050
- function getPackageForPlatform(mapping, platform, isWsl3) {
10051
- if (platform === "win32") {
10052
- if (isWsl3) {
10053
- return mapping.package || null;
10054
- }
10055
- return mapping.packageWin || mapping.package || null;
10056
- }
10057
- if (platform === "darwin") {
10058
- if (mapping.packageMac === "") return null;
10059
- return mapping.packageMac || mapping.package || null;
10060
- }
10061
- if (mapping.package === "") return null;
10062
- return mapping.package || null;
10063
- }
10064
- function mapHeaderToPackages(header, platform) {
10065
- const exactMatch = HEADER_TO_PACKAGE.find(
10066
- (m) => m.header.toLowerCase() === header.toLowerCase()
10067
- );
10068
- if (exactMatch) {
10069
- const pkg = getPackageForPlatform(exactMatch, platform, detectWsl());
10070
- if (pkg && pkg.length > 0 && pkg !== "\u81FA") {
10071
- return [pkg];
10072
- }
10073
- return [];
10074
- }
10075
- const headerBasename = header.split("/").pop()?.toLowerCase() || "";
10076
- const fuzzyMatch = HEADER_TO_PACKAGE.find((m) => {
10077
- const mappingBasename = m.header.split("/").pop()?.toLowerCase() || "";
10078
- return mappingBasename === headerBasename;
10079
- });
10080
- if (fuzzyMatch) {
10081
- const pkg = getPackageForPlatform(fuzzyMatch, platform, detectWsl());
10082
- if (pkg && pkg.length > 0 && pkg !== "\u81FA") {
10083
- return [pkg];
10084
- }
10085
- return [];
10086
- }
10087
- return [];
10088
- }
10089
- function mapHeadersToPackages(headers, platform) {
10090
- const packageSet = /* @__PURE__ */ new Set();
10091
- for (const header of headers) {
10092
- const packages = mapHeaderToPackages(header, platform);
10093
- for (const pkg of packages) {
10094
- if (pkg.length > 0) {
10095
- packageSet.add(pkg);
10096
- }
10097
- }
10098
- }
10099
- return Array.from(packageSet);
10100
- }
10101
-
10102
- // src/core/dependency-installer.ts
10103
- import { execSync as execSync3 } from "child_process";
10104
- var logger8 = createModuleLogger("DependencyInstaller");
10105
- function getInstallCommandPrefix() {
10106
- const { platform, isWsl: isWsl3 } = detectPlatform();
10107
- if (platform === "linux" || isWsl3) {
10108
- return "sudo apt-get install -y";
10109
- } else if (platform === "darwin") {
10110
- return "brew install";
10111
- }
10112
- return "choco install -y";
10113
- }
10114
- function getCheckCommand(packageName) {
10115
- const { platform, isWsl: isWsl3 } = detectPlatform();
10116
- if (platform === "linux" || isWsl3) {
10117
- return `dpkg -s ${packageName} 2>/dev/null | grep -q "Status: install ok installed"`;
10118
- } else if (platform === "darwin") {
10119
- return `brew list ${packageName} &>/dev/null`;
10120
- }
10121
- return `choco list --local-only ${packageName} &>/dev/null`;
10122
- }
10123
- function silentLog(level2, message, extra) {
10124
- switch (level2) {
10125
- case "info":
10126
- logger8.info(extra || {}, message);
10127
- break;
10128
- case "warn":
10129
- logger8.warn(extra || {}, message);
10130
- break;
10131
- case "error":
10132
- logger8.error(extra || {}, message);
10133
- break;
10134
- }
10135
- }
10136
- function canSudoWithoutPassword() {
10137
- try {
10138
- execSync3("sudo -n true 2>&1", { stdio: "pipe" });
10139
- return true;
10140
- } catch {
10141
- return false;
10142
- }
10143
- }
10144
- async function installSystemPackages(packages, notifSvc) {
10145
- const result = {
10146
- success: false,
10147
- installedPackages: [],
10148
- failedPackages: []
10149
- };
10150
- const validPackages = packages.filter((p) => p && p.length > 0 && p !== "\u81FA");
10151
- if (validPackages.length === 0) {
10152
- silentLog("info", "\u6CA1\u6709\u9700\u8981\u5B89\u88C5\u7684\u5305");
10153
- return { ...result, success: true };
10154
- }
10155
- silentLog("info", `\u5F00\u59CB\u5B89\u88C5\u7CFB\u7EDF\u4F9D\u8D56: ${validPackages.join(", ")}`, { packages: validPackages });
10156
- notifSvc?.info("\u6B63\u5728\u5B89\u88C5\u7CFB\u7EDF\u4F9D\u8D56...", "Ocosay", 3e3);
10157
- const installCommand = getInstallCommandPrefix();
10158
- const fullCommand = `${installCommand} ${validPackages.join(" ")}`;
10159
- silentLog("info", `\u6267\u884C\u5B89\u88C5\u547D\u4EE4: ${fullCommand}`);
10160
- if (!canSudoWithoutPassword()) {
10161
- const msg = "\u9700\u8981 sudo \u6743\u9650\uFF0C\u8BF7\u786E\u4FDD\u5DF2\u914D\u7F6E NOPASSWD";
10162
- result.error = msg;
10163
- notifSvc?.error("\u9700\u8981 sudo \u6743\u9650", "\u8BF7\u5728\u7EC8\u7AEF\u6267\u884C: sudo visudo \u6DFB\u52A0 NOPASSWD \u914D\u7F6E\uFF0C\u914D\u7F6E\u597D\u540E\u8BF7\u91CD\u542F OpenCode", 1e4);
10164
- silentLog("error", msg);
10165
- return result;
10166
- }
10167
- try {
10168
- const { platform, isWsl: isWsl3 } = detectPlatform();
10169
- if (platform === "linux" || isWsl3) {
10170
- notifSvc?.info("\u6B63\u5728\u66F4\u65B0\u5305\u5217\u8868...", "Ocosay", 3e3);
10171
- silentLog("info", "\u66F4\u65B0 apt \u5305\u5217\u8868");
10172
- try {
10173
- execSync3("sudo apt-get update", {
10174
- timeout: 12e4,
10175
- encoding: "utf8",
10176
- stdio: ["pipe", "pipe", "pipe"]
10177
- });
10178
- silentLog("info", "apt-get update \u5B8C\u6210");
10179
- } catch (updateErr) {
10180
- silentLog("warn", "apt-get update \u5931\u8D25\uFF0C\u7EE7\u7EED\u5C1D\u8BD5\u5B89\u88C5", { error: String(updateErr) });
10181
- }
10182
- }
10183
- notifSvc?.info(`\u6B63\u5728\u5B89\u88C5 ${validPackages.length} \u4E2A\u5305...`, "Ocosay", 5e3);
10184
- const output = execSync3(fullCommand, {
10185
- timeout: 3e5,
10186
- encoding: "utf8",
10187
- stdio: ["pipe", "pipe", "pipe"]
10188
- });
10189
- silentLog("info", `\u5B89\u88C5\u8F93\u51FA: ${output.substring(0, 500)}`);
10190
- const verifiedPackages = [];
10191
- const failedPackages = [];
10192
- for (const pkg of validPackages) {
10193
- const isInstalled = await verifyInstallation([pkg]);
10194
- if (isInstalled) {
10195
- verifiedPackages.push(pkg);
10196
- silentLog("info", `\u5305 ${pkg} \u5B89\u88C5\u9A8C\u8BC1\u6210\u529F`);
10197
- } else {
10198
- failedPackages.push(pkg);
10199
- silentLog("warn", `\u5305 ${pkg} \u5B89\u88C5\u9A8C\u8BC1\u5931\u8D25`);
10200
- }
10201
- }
10202
- result.installedPackages = verifiedPackages;
10203
- result.failedPackages = failedPackages;
10204
- result.success = failedPackages.length === 0;
10205
- if (result.success) {
10206
- notifSvc?.success("\u7CFB\u7EDF\u4F9D\u8D56\u5B89\u88C5\u6210\u529F", verifiedPackages.join(", "), 5e3);
10207
- silentLog("info", `\u6240\u6709\u5305\u5B89\u88C5\u6210\u529F: ${verifiedPackages.join(", ")}`);
10208
- } else {
10209
- const errorMsg = failedPackages.length > 0 ? `\u4EE5\u4E0B\u5305\u5B89\u88C5\u5931\u8D25: ${failedPackages.join(", ")}` : "\u90E8\u5206\u5305\u5B89\u88C5\u5931\u8D25";
10210
- result.error = errorMsg;
10211
- notifSvc?.warning("\u90E8\u5206\u4F9D\u8D56\u5B89\u88C5\u5931\u8D25", errorMsg, 8e3);
10212
- silentLog("warn", errorMsg);
10213
- }
10214
- } catch (err) {
10215
- const errorMessage = err instanceof Error ? err.message : String(err);
10216
- silentLog("error", `\u5B89\u88C5\u547D\u4EE4\u6267\u884C\u5931\u8D25: ${errorMessage}`, { error: errorMessage });
10217
- if (errorMessage.includes("sudo") || errorMessage.toLowerCase().includes("password")) {
10218
- result.error = "\u9700\u8981 sudo \u6743\u9650\uFF0C\u8BF7\u786E\u4FDD\u5DF2\u914D\u7F6E NOPASSWD";
10219
- notifSvc?.error("\u9700\u8981 sudo \u6743\u9650", "\u8BF7\u5728\u7EC8\u7AEF\u6267\u884C: sudo visudo", 1e4);
10220
- } else if (errorMessage.includes("already") || errorMessage.includes("is already")) {
10221
- result.success = true;
10222
- result.installedPackages = validPackages;
10223
- notifSvc?.success("\u4F9D\u8D56\u5DF2\u5B58\u5728", "\u65E0\u9700\u91CD\u65B0\u5B89\u88C5", 3e3);
10224
- } else {
10225
- result.error = errorMessage;
10226
- notifSvc?.error("\u4F9D\u8D56\u5B89\u88C5\u5931\u8D25", errorMessage.substring(0, 200), 8e3);
10227
- }
10228
- }
10229
- return result;
10230
- }
10231
- async function verifyInstallation(packages) {
10232
- if (packages.length === 0) {
10233
- return true;
10234
- }
10235
- const validPackages = packages.filter((p) => p && p.length > 0 && p !== "\u81FA");
10236
- if (validPackages.length === 0) {
10237
- return true;
10238
- }
10239
- silentLog("info", `\u9A8C\u8BC1\u5305\u5B89\u88C5\u72B6\u6001: ${validPackages.join(", ")}`);
10240
- try {
10241
- for (const pkg of validPackages) {
10242
- const checkCmd = getCheckCommand(pkg);
10243
- const { success } = execCapture(checkCmd);
10244
- if (!success) {
10245
- silentLog("warn", `\u5305 ${pkg} \u9A8C\u8BC1\u5931\u8D25`);
10246
- return false;
10247
- }
10248
- }
10249
- silentLog("info", `\u6240\u6709\u5305\u9A8C\u8BC1\u901A\u8FC7: ${validPackages.join(", ")}`);
10250
- return true;
10251
- } catch (err) {
10252
- silentLog("error", `\u9A8C\u8BC1\u8FC7\u7A0B\u5F02\u5E38: ${String(err)}`);
10253
- return false;
10254
- }
10255
- }
10256
-
10257
- // src/plugin.ts
10258
9906
  function execAsync(cmd, cwd) {
10259
9907
  return new Promise((resolve) => {
10260
9908
  exec(cmd, { cwd, encoding: "utf8" }, (error, stdout, stderr) => {
@@ -10262,12 +9910,12 @@ function execAsync(cmd, cwd) {
10262
9910
  });
10263
9911
  });
10264
9912
  }
10265
- var logger9 = createModuleLogger("Plugin");
10266
- var require3 = createRequire2(import.meta.url);
10267
- var opencodeBinPath = execSync4("which opencode").toString().trim();
9913
+ var logger8 = createModuleLogger("Plugin");
9914
+ var require2 = createRequire(import.meta.url);
9915
+ var opencodeBinPath = execSync2("which opencode").toString().trim();
10268
9916
  var opencodeRoot = dirname2(dirname2(opencodeBinPath));
10269
9917
  var opencodeNodeModules = join8(opencodeRoot, "node_modules");
10270
- var pluginRequire = createRequire2(join8(opencodeNodeModules, "package.json"));
9918
+ var pluginRequire = createRequire(join8(opencodeNodeModules, "package.json"));
10271
9919
  function getSkipFilePath() {
10272
9920
  return join8(homedir3(), ".config", "opencode", ".naudiodon_skip");
10273
9921
  }
@@ -10286,38 +9934,38 @@ async function markNaudiodonSkipped() {
10286
9934
  }
10287
9935
  async function verifyNaudiodonLoad() {
10288
9936
  try {
10289
- require3("naudiodon");
10290
- logger9.info("naudiodon loaded successfully");
9937
+ require2("naudiodon");
9938
+ logger8.info("naudiodon loaded successfully");
10291
9939
  return true;
10292
9940
  } catch (err) {
10293
- logger9.warn({ err }, "naudiodon load failed after rebuild");
9941
+ logger8.warn({ err }, "naudiodon load failed after rebuild");
10294
9942
  return false;
10295
9943
  }
10296
9944
  }
10297
9945
  async function rebuildNaudiodonDependency(dep) {
10298
- const naudiodonPath = dirname2(require3.resolve("naudiodon"));
9946
+ const naudiodonPath = dirname2(require2.resolve("naudiodon"));
10299
9947
  notificationService.info(`\u6B63\u5728\u7F16\u8BD1 ${dep}...`, "Ocosay \u4F9D\u8D56", 4e3);
10300
9948
  const result = await execAsync(`npm rebuild ${dep}`, naudiodonPath);
10301
9949
  if (result.error) {
10302
- logger9.warn({ err: result.error }, `${dep} rebuild failed`);
9950
+ logger8.warn({ err: result.error }, `${dep} rebuild failed`);
10303
9951
  return false;
10304
9952
  }
10305
- logger9.info(`${dep} rebuilt successfully`);
9953
+ logger8.info(`${dep} rebuilt successfully`);
10306
9954
  return true;
10307
9955
  }
10308
9956
  async function fixNaudiodonDependencies(maxRetries = 5) {
10309
- const naudiodonPath = dirname2(require3.resolve("naudiodon"));
9957
+ const naudiodonPath = dirname2(require2.resolve("naudiodon"));
10310
9958
  const criticalDeps = ["segfault-handler", "bindings", "node-pre-gyp"];
10311
9959
  for (let attempt = 0; attempt < maxRetries; attempt++) {
10312
9960
  if (await verifyNaudiodonLoad()) {
10313
9961
  return true;
10314
9962
  }
10315
- logger9.info({ attempt }, "naudiodon not loadable, trying dependency rebuild");
9963
+ logger8.info({ attempt }, "naudiodon not loadable, trying dependency rebuild");
10316
9964
  notificationService.info(`\u6B63\u5728\u68C0\u67E5\u4F9D\u8D56 (${attempt + 1}/${maxRetries})...`, "Ocosay", 3e3);
10317
9965
  let anySuccess = false;
10318
9966
  for (const dep of criticalDeps) {
10319
9967
  try {
10320
- require3.resolve(dep, { paths: [naudiodonPath] });
9968
+ require2.resolve(dep, { paths: [naudiodonPath] });
10321
9969
  if (await rebuildNaudiodonDependency(dep)) {
10322
9970
  anySuccess = true;
10323
9971
  }
@@ -10325,9 +9973,9 @@ async function fixNaudiodonDependencies(maxRetries = 5) {
10325
9973
  notificationService.info(`\u6B63\u5728\u5B89\u88C5 ${dep}...`, "Ocosay", 4e3);
10326
9974
  const installResult = await execAsync(`npm install ${dep}`, naudiodonPath);
10327
9975
  if (installResult.error) {
10328
- logger9.warn({ err: installResult.error }, `${dep} install failed`);
9976
+ logger8.warn({ err: installResult.error }, `${dep} install failed`);
10329
9977
  } else {
10330
- logger9.info(`${dep} installed successfully`);
9978
+ logger8.info(`${dep} installed successfully`);
10331
9979
  anySuccess = true;
10332
9980
  }
10333
9981
  }
@@ -10336,9 +9984,9 @@ async function fixNaudiodonDependencies(maxRetries = 5) {
10336
9984
  notificationService.info("\u6B63\u5728\u91CD\u65B0\u7F16\u8BD1 naudiodon...", "Ocosay", 4e3);
10337
9985
  const rebuildResult = await execAsync("npm rebuild naudiodon", naudiodonPath);
10338
9986
  if (rebuildResult.error) {
10339
- logger9.warn({ err: rebuildResult.error }, "naudiodon rebuild failed");
9987
+ logger8.warn({ err: rebuildResult.error }, "naudiodon rebuild failed");
10340
9988
  } else {
10341
- logger9.info("naudiodon rebuilt");
9989
+ logger8.info("naudiodon rebuilt");
10342
9990
  anySuccess = true;
10343
9991
  }
10344
9992
  }
@@ -10353,35 +10001,35 @@ async function fixNaudiodonDependencies(maxRetries = 5) {
10353
10001
  }
10354
10002
  async function ensureNaudiodonCompiled() {
10355
10003
  if (shouldSkipNaudiodon()) {
10356
- logger9.info("naudiodon skipped previously");
10004
+ logger8.info("naudiodon skipped previously");
10357
10005
  return;
10358
10006
  }
10359
10007
  try {
10360
- require3("naudiodon");
10361
- logger9.info("naudiodon already compiled");
10008
+ require2("naudiodon");
10009
+ logger8.info("naudiodon already compiled");
10362
10010
  return;
10363
10011
  } catch {
10364
- logger9.info("naudiodon not compiled, will attempt to compile");
10012
+ logger8.info("naudiodon not compiled, will attempt to compile");
10365
10013
  notificationService.info("\u6B63\u5728\u7F16\u8BD1 naudiodon...", "Ocosay \u97F3\u9891\u540E\u7AEF", 5e3);
10366
10014
  }
10367
10015
  try {
10368
- const naudiodonPath = dirname2(require3.resolve("naudiodon"));
10369
- logger9.info({ naudiodonPath }, "found naudiodon, rebuilding");
10016
+ const naudiodonPath = dirname2(require2.resolve("naudiodon"));
10017
+ logger8.info({ naudiodonPath }, "found naudiodon, rebuilding");
10370
10018
  const rebuildResult = await execAsync("npm rebuild naudiodon", naudiodonPath);
10371
10019
  if (rebuildResult.error) {
10372
- logger9.warn({ err: rebuildResult.error }, "naudiodon rebuild failed, checking for PortAudio");
10020
+ logger8.warn({ err: rebuildResult.error }, "naudiodon rebuild failed, checking for PortAudio");
10373
10021
  notificationService.warning("naudiodon \u7F16\u8BD1\u5931\u8D25", "\u6B63\u5728\u5C1D\u8BD5\u5B89\u88C5 PortAudio...", 5e3);
10374
10022
  const installed = await installPortAudio();
10375
10023
  if (installed.success) {
10376
- const retryPath = dirname2(require3.resolve("naudiodon"));
10024
+ const retryPath = dirname2(require2.resolve("naudiodon"));
10377
10025
  notificationService.info("\u6B63\u5728\u91CD\u65B0\u7F16\u8BD1 naudiodon...", "Ocosay", 5e3);
10378
10026
  const retryResult = await execAsync("npm rebuild naudiodon", retryPath);
10379
10027
  if (retryResult.error) {
10380
- logger9.error({ err: retryResult.error }, "naudiodon compile failed even after PortAudio install");
10028
+ logger8.error({ err: retryResult.error }, "naudiodon compile failed even after PortAudio install");
10381
10029
  notificationService.error("naudiodon \u7F16\u8BD1\u5931\u8D25", "\u81EA\u52A8\u5B89\u88C5\u5931\u8D25\uFF0C\u8BF7\u5C1D\u8BD5\u624B\u52A8\u5B89\u88C5", 8e3);
10382
10030
  markNaudiodonSkipped();
10383
10031
  } else {
10384
- logger9.info("naudiodon compiled successfully after PortAudio install");
10032
+ logger8.info("naudiodon compiled successfully after PortAudio install");
10385
10033
  const loadSuccess = await verifyNaudiodonLoad();
10386
10034
  if (loadSuccess) {
10387
10035
  notificationService.success("naudiodon \u7F16\u8BD1\u6210\u529F", "\u97F3\u9891\u540E\u7AEF\u5DF2\u5C31\u7EEA", 5e3);
@@ -10396,12 +10044,12 @@ async function ensureNaudiodonCompiled() {
10396
10044
  }
10397
10045
  }
10398
10046
  } else {
10399
- logger9.error("PortAudio install failed");
10047
+ logger8.error("PortAudio install failed");
10400
10048
  notificationService.error("PortAudio \u5B89\u88C5\u5931\u8D25", "\u81EA\u52A8\u5B89\u88C5\u5931\u8D25\uFF0C\u8BF7\u5C1D\u8BD5\u624B\u52A8\u5B89\u88C5", 8e3);
10401
10049
  markNaudiodonSkipped();
10402
10050
  }
10403
10051
  } else {
10404
- logger9.info("naudiodon compiled, verifying...");
10052
+ logger8.info("naudiodon compiled, verifying...");
10405
10053
  const loadSuccess = await verifyNaudiodonLoad();
10406
10054
  if (loadSuccess) {
10407
10055
  notificationService.success("naudiodon \u7F16\u8BD1\u6210\u529F", "\u97F3\u9891\u540E\u7AEF\u5DF2\u5C31\u7EEA", 5e3);
@@ -10416,19 +10064,19 @@ async function ensureNaudiodonCompiled() {
10416
10064
  }
10417
10065
  }
10418
10066
  } catch (err) {
10419
- logger9.warn({ err }, "naudiodon rebuild failed, checking for PortAudio");
10067
+ logger8.warn({ err }, "naudiodon rebuild failed, checking for PortAudio");
10420
10068
  notificationService.warning("naudiodon \u7F16\u8BD1\u5931\u8D25", "\u6B63\u5728\u5C1D\u8BD5\u5B89\u88C5 PortAudio...", 5e3);
10421
10069
  const installed = await installPortAudio();
10422
10070
  if (installed.success) {
10423
- const retryPath = dirname2(require3.resolve("naudiodon"));
10071
+ const retryPath = dirname2(require2.resolve("naudiodon"));
10424
10072
  notificationService.info("\u6B63\u5728\u91CD\u65B0\u7F16\u8BD1 naudiodon...", "Ocosay", 5e3);
10425
10073
  const retryResult = await execAsync("npm rebuild naudiodon", retryPath);
10426
10074
  if (retryResult.error) {
10427
- logger9.error({ err: retryResult.error }, "naudiodon compile failed even after PortAudio install");
10075
+ logger8.error({ err: retryResult.error }, "naudiodon compile failed even after PortAudio install");
10428
10076
  notificationService.error("naudiodon \u7F16\u8BD1\u5931\u8D25", "\u81EA\u52A8\u5B89\u88C5\u5931\u8D25\uFF0C\u8BF7\u5C1D\u8BD5\u624B\u52A8\u5B89\u88C5", 8e3);
10429
10077
  markNaudiodonSkipped();
10430
10078
  } else {
10431
- logger9.info("naudiodon compiled successfully after PortAudio install");
10079
+ logger8.info("naudiodon compiled successfully after PortAudio install");
10432
10080
  const loadSuccess = await verifyNaudiodonLoad();
10433
10081
  if (loadSuccess) {
10434
10082
  notificationService.success("naudiodon \u7F16\u8BD1\u6210\u529F", "\u97F3\u9891\u540E\u7AEF\u5DF2\u5C31\u7EEA", 5e3);
@@ -10443,7 +10091,7 @@ async function ensureNaudiodonCompiled() {
10443
10091
  }
10444
10092
  }
10445
10093
  } else {
10446
- logger9.error("PortAudio install failed");
10094
+ logger8.error("PortAudio install failed");
10447
10095
  notificationService.error("PortAudio \u5B89\u88C5\u5931\u8D25", "\u81EA\u52A8\u5B89\u88C5\u5931\u8D25\uFF0C\u8BF7\u5C1D\u8BD5\u624B\u52A8\u5B89\u88C5", 8e3);
10448
10096
  markNaudiodonSkipped();
10449
10097
  }
@@ -10460,87 +10108,34 @@ function isModuleInstalled(moduleName) {
10460
10108
  async function verifyModuleLoad(dep) {
10461
10109
  try {
10462
10110
  pluginRequire(dep);
10463
- logger9.info(`${dep} loaded successfully`);
10111
+ logger8.info(`${dep} loaded successfully`);
10464
10112
  return true;
10465
10113
  } catch (err) {
10466
- logger9.warn({ err }, `${dep} load failed`);
10114
+ logger8.warn({ err }, `${dep} load failed`);
10467
10115
  return false;
10468
10116
  }
10469
10117
  }
10470
- async function tryCompileSpeaker() {
10471
- const dep = "speaker";
10472
- const result = { success: false, stderr: "" };
10473
- if (isModuleInstalled(dep)) {
10474
- if (await verifyModuleLoad(dep)) {
10475
- result.success = true;
10476
- return result;
10477
- }
10478
- }
10479
- if (!isModuleInstalled(dep)) {
10480
- const installResult = await execAsync("npm install speaker", opencodeNodeModules);
10481
- if (installResult.error) {
10482
- logger9.warn({ err: installResult.error }, "speaker install failed");
10483
- }
10484
- }
10485
- const rebuildResult = await execAsync("npm rebuild speaker", opencodeNodeModules);
10486
- result.stderr = (rebuildResult.stdout || "") + "\n" + (rebuildResult.stderr || "");
10487
- if (rebuildResult.error) {
10488
- result.stderr += "\n" + (rebuildResult.error.message || "");
10489
- }
10490
- if (await verifyModuleLoad(dep)) {
10491
- result.success = true;
10492
- }
10493
- return result;
10494
- }
10495
- async function ensureSpeakerCompiledAsync() {
10496
- const compileResult = await tryCompileSpeaker();
10497
- if (compileResult.success) {
10498
- logger9.info("speaker compiled successfully");
10499
- return;
10500
- }
10501
- const detectResult = detectMissingDependencies(compileResult.stderr);
10502
- if (detectResult.missingHeaders.length === 0) {
10503
- logger9.info("speaker compile failed with unknown error");
10504
- return;
10505
- }
10506
- logger9.info({ missingHeaders: detectResult.missingHeaders }, "detected missing headers");
10507
- const platformInfo = detectPlatform();
10508
- const packages = mapHeadersToPackages(detectResult.missingHeaders, platformInfo.platform);
10509
- if (packages.length === 0) {
10510
- logger9.info("no known packages for missing headers");
10511
- return;
10512
- }
10513
- logger9.info({ packages }, "mapped headers to packages, installing");
10514
- await installSystemPackages(packages, notificationService);
10515
- const retryResult = await tryCompileSpeaker();
10516
- if (retryResult.success) {
10517
- logger9.info("speaker compiled successfully after installing dependencies");
10518
- } else {
10519
- logger9.warn("speaker compile still failed after dependency installation");
10520
- }
10521
- }
10522
10118
  async function ensureSpeakerInstalledAsync() {
10523
10119
  await ensurePlaySoundInstalled();
10524
10120
  }
10525
10121
  async function initAsync() {
10526
10122
  setTimeout(async () => {
10527
- await ensureSpeakerCompiledAsync();
10528
10123
  await ensureSpeakerInstalledAsync();
10529
10124
  }, 100);
10530
10125
  }
10531
10126
  async function ensurePlaySoundInstalled() {
10532
10127
  const dep = "play-sound";
10533
10128
  if (isModuleInstalled(dep)) {
10534
- logger9.info("play-sound already installed");
10129
+ logger8.info("play-sound already installed");
10535
10130
  if (await verifyModuleLoad(dep)) {
10536
10131
  return;
10537
10132
  }
10538
10133
  }
10539
- logger9.info("play-sound not found, installing");
10134
+ logger8.info("play-sound not found, installing");
10540
10135
  notificationService.info("\u6B63\u5728\u5B89\u88C5 play-sound...", "Ocosay \u97F3\u9891\u540E\u7AEF", 5e3);
10541
10136
  const installResult = await execAsync("npm install play-sound", opencodeNodeModules);
10542
10137
  if (installResult.error) {
10543
- logger9.warn({ err: installResult.error }, "play-sound install failed");
10138
+ logger8.warn({ err: installResult.error }, "play-sound install failed");
10544
10139
  notificationService.warning(
10545
10140
  "play-sound \u5B89\u88C5\u5931\u8D25",
10546
10141
  "\u8BF7\u624B\u52A8\u8FD0\u884C: npm install play-sound",
@@ -10548,7 +10143,7 @@ async function ensurePlaySoundInstalled() {
10548
10143
  );
10549
10144
  return;
10550
10145
  }
10551
- logger9.info("play-sound installed");
10146
+ logger8.info("play-sound installed");
10552
10147
  if (await verifyModuleLoad(dep)) {
10553
10148
  notificationService.success("play-sound \u5B89\u88C5\u6210\u529F", "\u97F3\u9891\u540E\u7AEF\u5DF2\u5C31\u7EEA", 5e3);
10554
10149
  } else {
@@ -10560,14 +10155,11 @@ async function ensurePlaySoundInstalled() {
10560
10155
  }
10561
10156
  }
10562
10157
  async function ensureOptionalDepsInstalled() {
10563
- ensureSpeakerCompiledAsync().catch((err) => {
10564
- logger9.warn({ err }, "ensureSpeakerCompiledAsync failed");
10565
- });
10566
10158
  await ensurePlaySoundInstalled();
10567
10159
  }
10568
10160
  function execCmd2(cmd) {
10569
10161
  try {
10570
- const output = execSync4(cmd, { stdio: "pipe", encoding: "utf8" });
10162
+ const output = execSync2(cmd, { stdio: "pipe", encoding: "utf8" });
10571
10163
  return { success: true, output };
10572
10164
  } catch (err) {
10573
10165
  return { success: false, output: err.message || "" };
@@ -10576,7 +10168,7 @@ function execCmd2(cmd) {
10576
10168
  function isWsl2() {
10577
10169
  if (process.platform !== "linux") return false;
10578
10170
  try {
10579
- return require3("fs").readFileSync("/proc/version", "utf8").toLowerCase().includes("microsoft");
10171
+ return require2("fs").readFileSync("/proc/version", "utf8").toLowerCase().includes("microsoft");
10580
10172
  } catch {
10581
10173
  return false;
10582
10174
  }
@@ -10613,9 +10205,9 @@ async function checkAudioEnvironmentForBackend() {
10613
10205
  async function installPortAudio() {
10614
10206
  const platform = process.platform;
10615
10207
  const wsl = isWsl2();
10616
- logger9.info({ platform, wsl }, "installing PortAudio");
10208
+ logger8.info({ platform, wsl }, "installing PortAudio");
10617
10209
  const runInstall = async (cmd, desc) => {
10618
- logger9.info(`Running: ${cmd}`);
10210
+ logger8.info(`Running: ${cmd}`);
10619
10211
  notificationService.info(desc, "\u6B63\u5728\u5B89\u88C5...", 5e3);
10620
10212
  const result = await execAsync(cmd);
10621
10213
  if (result.error) {
@@ -10626,15 +10218,15 @@ async function installPortAudio() {
10626
10218
  "# \u8BF7\u5728WSL\u7EC8\u7AEF\u6267\u884C\u4E00\u6B21\nsudo visudo\n# \u6DFB\u52A0\u884C\uFF1Ayour user name ALL=(ALL) NOPASSWD: ALL",
10627
10219
  1e4
10628
10220
  );
10629
- 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");
10221
+ logger8.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");
10630
10222
  return false;
10631
10223
  }
10632
10224
  if (msg.includes("already") || msg.includes("is already")) {
10633
- logger9.info("already installed");
10225
+ logger8.info("already installed");
10634
10226
  return true;
10635
10227
  }
10636
10228
  notificationService.error(desc + " \u5931\u8D25", msg.substring(0, 100), 8e3);
10637
- logger9.error({ err: result.error }, `install failed: ${desc}`);
10229
+ logger8.error({ err: result.error }, `install failed: ${desc}`);
10638
10230
  return false;
10639
10231
  }
10640
10232
  return true;
@@ -10643,7 +10235,7 @@ async function installPortAudio() {
10643
10235
  notificationService.info("\u68C0\u6D4B ffmpeg...", "\u97F3\u9891\u540E\u7AEF", 5e3);
10644
10236
  const ffmpegCheck = execCmd2("which ffplay");
10645
10237
  if (ffmpegCheck.success) {
10646
- logger9.info("ffmpeg already available");
10238
+ logger8.info("ffmpeg already available");
10647
10239
  notificationService.success("ffmpeg \u5C31\u7EEA", "ffplay \u53EF\u7528\u4E8E\u65E0\u58F0\u5361\u64AD\u653E", 5e3);
10648
10240
  } else {
10649
10241
  notificationService.info("\u5B89\u88C5 ffmpeg...", "\u97F3\u9891\u540E\u7AEF", 5e3);
@@ -10659,7 +10251,7 @@ async function installPortAudio() {
10659
10251
  }
10660
10252
  notificationService.info("\u68C0\u6D4B\u97F3\u9891\u8BBE\u5907...", "\u97F3\u9891\u540E\u7AEF", 5e3);
10661
10253
  if (checkAlsa()) {
10662
- logger9.info("alsa-utils already available and working");
10254
+ logger8.info("alsa-utils already available and working");
10663
10255
  notificationService.success("alsa-utils \u5C31\u7EEA", "\u97F3\u9891\u540E\u7AEF\u5DF2\u53EF\u7528", 5e3);
10664
10256
  return { success: true, message: "alsa" };
10665
10257
  }
@@ -10850,7 +10442,7 @@ var server = (async (input, _options) => {
10850
10442
  });
10851
10443
  } catch (err) {
10852
10444
  initError = err instanceof Error ? err : new Error(String(err));
10853
- logger9.error({ error: initError }, "initialization failed");
10445
+ logger8.error({ error: initError }, "initialization failed");
10854
10446
  }
10855
10447
  initAsync();
10856
10448
  await ensureNaudiodonCompiled();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mingxy/ocosay",
3
- "version": "1.1.31",
3
+ "version": "1.1.32",
4
4
  "description": "OpenCode TTS 播放插件 - 支持豆包模式边接收边朗读",
5
5
  "type": "module",
6
6
  "main": "dist/plugin.js",