@mingxy/ocosay 1.0.28 → 1.0.31
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/.idea/UniappTool.xml +10 -0
- package/.idea/modules.xml +8 -0
- package/.idea/ocosay.iml +12 -0
- package/.idea/vcs.xml +6 -0
- package/README.md +34 -6
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +7 -6
- package/dist/config.js.map +1 -1
- package/dist/core/speaker.d.ts.map +1 -1
- package/dist/core/speaker.js +34 -49
- package/dist/core/speaker.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -6
- package/dist/index.js.map +1 -1
- package/dist/package.json +1 -1
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +140 -168
- package/dist/plugin.js.map +3 -3
- package/dist/tools/tts.d.ts +0 -62
- package/dist/tools/tts.d.ts.map +1 -1
- package/dist/tools/tts.js +20 -66
- package/dist/tools/tts.js.map +1 -1
- package/dist/utils/logger.d.ts +0 -4
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +21 -31
- package/dist/utils/logger.js.map +1 -1
- package/package.json +1 -1
package/dist/plugin.js
CHANGED
|
@@ -4336,7 +4336,7 @@ var require_thread_stream = __commonJS({
|
|
|
4336
4336
|
nextFlush(stream);
|
|
4337
4337
|
});
|
|
4338
4338
|
} else {
|
|
4339
|
-
|
|
4339
|
+
destroy(stream, new Error("overwritten"));
|
|
4340
4340
|
}
|
|
4341
4341
|
}
|
|
4342
4342
|
function onWorkerMessage(msg) {
|
|
@@ -4355,7 +4355,7 @@ var require_thread_stream = __commonJS({
|
|
|
4355
4355
|
});
|
|
4356
4356
|
break;
|
|
4357
4357
|
case "ERROR":
|
|
4358
|
-
|
|
4358
|
+
destroy(stream, msg.err);
|
|
4359
4359
|
break;
|
|
4360
4360
|
case "EVENT":
|
|
4361
4361
|
if (Array.isArray(msg.args)) {
|
|
@@ -4368,7 +4368,7 @@ var require_thread_stream = __commonJS({
|
|
|
4368
4368
|
process.emitWarning(msg.err);
|
|
4369
4369
|
break;
|
|
4370
4370
|
default:
|
|
4371
|
-
|
|
4371
|
+
destroy(stream, new Error("this should not happen: " + msg.code));
|
|
4372
4372
|
}
|
|
4373
4373
|
}
|
|
4374
4374
|
function onWorkerExit(code) {
|
|
@@ -4379,7 +4379,7 @@ var require_thread_stream = __commonJS({
|
|
|
4379
4379
|
registry.unregister(stream);
|
|
4380
4380
|
stream.worker.exited = true;
|
|
4381
4381
|
stream.worker.off("exit", onWorkerExit);
|
|
4382
|
-
|
|
4382
|
+
destroy(stream, code !== 0 ? new Error("the worker thread exited") : null);
|
|
4383
4383
|
}
|
|
4384
4384
|
var ThreadStream = class extends EventEmitter6 {
|
|
4385
4385
|
constructor(opts = {}) {
|
|
@@ -4422,7 +4422,7 @@ var require_thread_stream = __commonJS({
|
|
|
4422
4422
|
writeSync(this);
|
|
4423
4423
|
this[kImpl].flushing = true;
|
|
4424
4424
|
} catch (err) {
|
|
4425
|
-
|
|
4425
|
+
destroy(this, err);
|
|
4426
4426
|
return false;
|
|
4427
4427
|
}
|
|
4428
4428
|
}
|
|
@@ -4432,7 +4432,7 @@ var require_thread_stream = __commonJS({
|
|
|
4432
4432
|
writeSync(this);
|
|
4433
4433
|
return true;
|
|
4434
4434
|
} catch (err) {
|
|
4435
|
-
|
|
4435
|
+
destroy(this, err);
|
|
4436
4436
|
return false;
|
|
4437
4437
|
}
|
|
4438
4438
|
}
|
|
@@ -4460,7 +4460,7 @@ var require_thread_stream = __commonJS({
|
|
|
4460
4460
|
const writeIndex = Atomics.load(this[kImpl].state, WRITE_INDEX);
|
|
4461
4461
|
wait(this[kImpl].state, READ_INDEX, writeIndex, Infinity, (err, res) => {
|
|
4462
4462
|
if (err) {
|
|
4463
|
-
|
|
4463
|
+
destroy(this, err);
|
|
4464
4464
|
process.nextTick(cb, err);
|
|
4465
4465
|
return;
|
|
4466
4466
|
}
|
|
@@ -4517,7 +4517,7 @@ var require_thread_stream = __commonJS({
|
|
|
4517
4517
|
stream.emit("error", err);
|
|
4518
4518
|
});
|
|
4519
4519
|
}
|
|
4520
|
-
function
|
|
4520
|
+
function destroy(stream, err) {
|
|
4521
4521
|
if (stream[kImpl].destroyed) {
|
|
4522
4522
|
return;
|
|
4523
4523
|
}
|
|
@@ -4563,11 +4563,11 @@ var require_thread_stream = __commonJS({
|
|
|
4563
4563
|
Atomics.wait(stream[kImpl].state, READ_INDEX, readIndex, 1e3);
|
|
4564
4564
|
readIndex = Atomics.load(stream[kImpl].state, READ_INDEX);
|
|
4565
4565
|
if (readIndex === -2) {
|
|
4566
|
-
|
|
4566
|
+
destroy(stream, new Error("end() failed"));
|
|
4567
4567
|
return;
|
|
4568
4568
|
}
|
|
4569
4569
|
if (++spins === 10) {
|
|
4570
|
-
|
|
4570
|
+
destroy(stream, new Error("end() took too long (10s)"));
|
|
4571
4571
|
return;
|
|
4572
4572
|
}
|
|
4573
4573
|
}
|
|
@@ -4576,7 +4576,7 @@ var require_thread_stream = __commonJS({
|
|
|
4576
4576
|
stream.emit("finish");
|
|
4577
4577
|
});
|
|
4578
4578
|
} catch (err) {
|
|
4579
|
-
|
|
4579
|
+
destroy(stream, err);
|
|
4580
4580
|
}
|
|
4581
4581
|
}
|
|
4582
4582
|
function writeSync(stream) {
|
|
@@ -4902,10 +4902,10 @@ var require_tools = __commonJS({
|
|
|
4902
4902
|
var asString = nodeMajor >= 25 ? (str) => JSON.stringify(str) : _asString;
|
|
4903
4903
|
function noop() {
|
|
4904
4904
|
}
|
|
4905
|
-
function genLog(
|
|
4905
|
+
function genLog(level2, hook) {
|
|
4906
4906
|
if (!hook) return LOG;
|
|
4907
4907
|
return function hookWrappedLog(...args) {
|
|
4908
|
-
hook.call(this, args, LOG,
|
|
4908
|
+
hook.call(this, args, LOG, level2);
|
|
4909
4909
|
};
|
|
4910
4910
|
function LOG(o, ...n) {
|
|
4911
4911
|
if (typeof o === "object") {
|
|
@@ -4927,13 +4927,13 @@ var require_tools = __commonJS({
|
|
|
4927
4927
|
if (typeof this[msgPrefixSym] === "string" && msg !== void 0 && msg !== null) {
|
|
4928
4928
|
msg = this[msgPrefixSym] + msg;
|
|
4929
4929
|
}
|
|
4930
|
-
this[writeSym](o, format(msg, formatParams, this[formatOptsSym]),
|
|
4930
|
+
this[writeSym](o, format(msg, formatParams, this[formatOptsSym]), level2);
|
|
4931
4931
|
} else {
|
|
4932
4932
|
let msg = o === void 0 ? n.shift() : o;
|
|
4933
4933
|
if (typeof this[msgPrefixSym] === "string" && msg !== void 0 && msg !== null) {
|
|
4934
4934
|
msg = this[msgPrefixSym] + msg;
|
|
4935
4935
|
}
|
|
4936
|
-
this[writeSym](null, format(msg, n, this[formatOptsSym]),
|
|
4936
|
+
this[writeSym](null, format(msg, n, this[formatOptsSym]), level2);
|
|
4937
4937
|
}
|
|
4938
4938
|
}
|
|
4939
4939
|
}
|
|
@@ -5166,9 +5166,9 @@ var require_tools = __commonJS({
|
|
|
5166
5166
|
}
|
|
5167
5167
|
}
|
|
5168
5168
|
}
|
|
5169
|
-
function buildFormatters(
|
|
5169
|
+
function buildFormatters(level2, bindings, log) {
|
|
5170
5170
|
return {
|
|
5171
|
-
level,
|
|
5171
|
+
level: level2,
|
|
5172
5172
|
bindings,
|
|
5173
5173
|
log
|
|
5174
5174
|
};
|
|
@@ -5267,17 +5267,17 @@ var require_levels = __commonJS({
|
|
|
5267
5267
|
const { labels } = instance.levels;
|
|
5268
5268
|
const cache = {};
|
|
5269
5269
|
for (const label in labels) {
|
|
5270
|
-
const
|
|
5271
|
-
cache[label] = JSON.stringify(
|
|
5270
|
+
const level2 = formatter(labels[label], Number(label));
|
|
5271
|
+
cache[label] = JSON.stringify(level2).slice(0, -1);
|
|
5272
5272
|
}
|
|
5273
5273
|
instance[lsCacheSym] = cache;
|
|
5274
5274
|
return instance;
|
|
5275
5275
|
}
|
|
5276
|
-
function isStandardLevel(
|
|
5276
|
+
function isStandardLevel(level2, useOnlyCustomLevels) {
|
|
5277
5277
|
if (useOnlyCustomLevels) {
|
|
5278
5278
|
return false;
|
|
5279
5279
|
}
|
|
5280
|
-
switch (
|
|
5280
|
+
switch (level2) {
|
|
5281
5281
|
case "fatal":
|
|
5282
5282
|
case "error":
|
|
5283
5283
|
case "warn":
|
|
@@ -5289,15 +5289,15 @@ var require_levels = __commonJS({
|
|
|
5289
5289
|
return false;
|
|
5290
5290
|
}
|
|
5291
5291
|
}
|
|
5292
|
-
function setLevel(
|
|
5292
|
+
function setLevel(level2) {
|
|
5293
5293
|
const { labels, values } = this.levels;
|
|
5294
|
-
if (typeof
|
|
5295
|
-
if (labels[
|
|
5296
|
-
|
|
5294
|
+
if (typeof level2 === "number") {
|
|
5295
|
+
if (labels[level2] === void 0) throw Error("unknown level value" + level2);
|
|
5296
|
+
level2 = labels[level2];
|
|
5297
5297
|
}
|
|
5298
|
-
if (values[
|
|
5298
|
+
if (values[level2] === void 0) throw Error("unknown level " + level2);
|
|
5299
5299
|
const preLevelVal = this[levelValSym];
|
|
5300
|
-
const levelVal = this[levelValSym] = values[
|
|
5300
|
+
const levelVal = this[levelValSym] = values[level2];
|
|
5301
5301
|
const useOnlyCustomLevelsVal = this[useOnlyCustomLevelsSym];
|
|
5302
5302
|
const levelComparison = this[levelCompSym];
|
|
5303
5303
|
const hook = this[hooksSym].logMethod;
|
|
@@ -5310,14 +5310,14 @@ var require_levels = __commonJS({
|
|
|
5310
5310
|
}
|
|
5311
5311
|
this.emit(
|
|
5312
5312
|
"level-change",
|
|
5313
|
-
|
|
5313
|
+
level2,
|
|
5314
5314
|
levelVal,
|
|
5315
5315
|
labels[preLevelVal],
|
|
5316
5316
|
preLevelVal,
|
|
5317
5317
|
this
|
|
5318
5318
|
);
|
|
5319
5319
|
}
|
|
5320
|
-
function getLevel(
|
|
5320
|
+
function getLevel(level2) {
|
|
5321
5321
|
const { levels, levelVal } = this;
|
|
5322
5322
|
return levels && levels.labels ? levels.labels[levelVal] : "";
|
|
5323
5323
|
}
|
|
@@ -5359,7 +5359,7 @@ var require_levels = __commonJS({
|
|
|
5359
5359
|
if (typeof defaultLevel === "number") {
|
|
5360
5360
|
const values = [].concat(
|
|
5361
5361
|
Object.keys(customLevels || {}).map((key) => customLevels[key]),
|
|
5362
|
-
useOnlyCustomLevels ? [] : Object.keys(nums).map((
|
|
5362
|
+
useOnlyCustomLevels ? [] : Object.keys(nums).map((level2) => +level2),
|
|
5363
5363
|
Infinity
|
|
5364
5364
|
);
|
|
5365
5365
|
if (!values.includes(defaultLevel)) {
|
|
@@ -5551,9 +5551,9 @@ var require_proto = __commonJS({
|
|
|
5551
5551
|
}
|
|
5552
5552
|
} else instance[serializersSym] = serializers;
|
|
5553
5553
|
if (options.hasOwnProperty("formatters")) {
|
|
5554
|
-
const { level, bindings: chindings, log } = options.formatters;
|
|
5554
|
+
const { level: level2, bindings: chindings, log } = options.formatters;
|
|
5555
5555
|
instance[formattersSym] = buildFormatters(
|
|
5556
|
-
|
|
5556
|
+
level2 || formatters.level,
|
|
5557
5557
|
chindings || resetChildingsFormatter,
|
|
5558
5558
|
log || formatters.log
|
|
5559
5559
|
);
|
|
@@ -6286,20 +6286,20 @@ var require_multistream = __commonJS({
|
|
|
6286
6286
|
return res;
|
|
6287
6287
|
function write(data) {
|
|
6288
6288
|
let dest;
|
|
6289
|
-
const
|
|
6290
|
-
const { streams } = this;
|
|
6289
|
+
const level2 = this.lastLevel;
|
|
6290
|
+
const { streams: streams2 } = this;
|
|
6291
6291
|
let recordedLevel = 0;
|
|
6292
6292
|
let stream;
|
|
6293
|
-
for (let i = initLoopVar(
|
|
6294
|
-
dest =
|
|
6295
|
-
if (dest.level <=
|
|
6293
|
+
for (let i = initLoopVar(streams2.length, opts.dedupe); checkLoopVar(i, streams2.length, opts.dedupe); i = adjustLoopVar(i, opts.dedupe)) {
|
|
6294
|
+
dest = streams2[i];
|
|
6295
|
+
if (dest.level <= level2) {
|
|
6296
6296
|
if (recordedLevel !== 0 && recordedLevel !== dest.level) {
|
|
6297
6297
|
break;
|
|
6298
6298
|
}
|
|
6299
6299
|
stream = dest.stream;
|
|
6300
6300
|
if (stream[metadata]) {
|
|
6301
6301
|
const { lastTime, lastMsg, lastObj, lastLogger } = this;
|
|
6302
|
-
stream.lastLevel =
|
|
6302
|
+
stream.lastLevel = level2;
|
|
6303
6303
|
stream.lastTime = lastTime;
|
|
6304
6304
|
stream.lastMsg = lastMsg;
|
|
6305
6305
|
stream.lastObj = lastObj;
|
|
@@ -6337,35 +6337,35 @@ var require_multistream = __commonJS({
|
|
|
6337
6337
|
if (!isStream) {
|
|
6338
6338
|
throw Error("stream object needs to implement either StreamEntry or DestinationStream interface");
|
|
6339
6339
|
}
|
|
6340
|
-
const { streams, streamLevels: streamLevels2 } = this;
|
|
6341
|
-
let
|
|
6340
|
+
const { streams: streams2, streamLevels: streamLevels2 } = this;
|
|
6341
|
+
let level2;
|
|
6342
6342
|
if (typeof dest.levelVal === "number") {
|
|
6343
|
-
|
|
6343
|
+
level2 = dest.levelVal;
|
|
6344
6344
|
} else if (typeof dest.level === "string") {
|
|
6345
|
-
|
|
6345
|
+
level2 = streamLevels2[dest.level];
|
|
6346
6346
|
} else if (typeof dest.level === "number") {
|
|
6347
|
-
|
|
6347
|
+
level2 = dest.level;
|
|
6348
6348
|
} else {
|
|
6349
|
-
|
|
6349
|
+
level2 = DEFAULT_INFO_LEVEL;
|
|
6350
6350
|
}
|
|
6351
6351
|
const dest_ = {
|
|
6352
6352
|
stream: stream_,
|
|
6353
|
-
level,
|
|
6353
|
+
level: level2,
|
|
6354
6354
|
levelVal: void 0,
|
|
6355
6355
|
id: ++res.lastId
|
|
6356
6356
|
};
|
|
6357
|
-
|
|
6358
|
-
|
|
6359
|
-
this.minLevel =
|
|
6357
|
+
streams2.unshift(dest_);
|
|
6358
|
+
streams2.sort(compareByLevel);
|
|
6359
|
+
this.minLevel = streams2[0].level;
|
|
6360
6360
|
return res;
|
|
6361
6361
|
}
|
|
6362
6362
|
function remove(id2) {
|
|
6363
|
-
const { streams } = this;
|
|
6364
|
-
const index =
|
|
6363
|
+
const { streams: streams2 } = this;
|
|
6364
|
+
const index = streams2.findIndex((s) => s.id === id2);
|
|
6365
6365
|
if (index >= 0) {
|
|
6366
|
-
|
|
6367
|
-
|
|
6368
|
-
this.minLevel =
|
|
6366
|
+
streams2.splice(index, 1);
|
|
6367
|
+
streams2.sort(compareByLevel);
|
|
6368
|
+
this.minLevel = streams2.length > 0 ? streams2[0].level : -1;
|
|
6369
6369
|
}
|
|
6370
6370
|
return res;
|
|
6371
6371
|
}
|
|
@@ -6377,11 +6377,11 @@ var require_multistream = __commonJS({
|
|
|
6377
6377
|
stream.end();
|
|
6378
6378
|
}
|
|
6379
6379
|
}
|
|
6380
|
-
function clone(
|
|
6381
|
-
const
|
|
6382
|
-
for (let i = 0; i <
|
|
6383
|
-
|
|
6384
|
-
level,
|
|
6380
|
+
function clone(level2) {
|
|
6381
|
+
const streams2 = new Array(this.streams.length);
|
|
6382
|
+
for (let i = 0; i < streams2.length; i++) {
|
|
6383
|
+
streams2[i] = {
|
|
6384
|
+
level: level2,
|
|
6385
6385
|
stream: this.streams[i].stream
|
|
6386
6386
|
};
|
|
6387
6387
|
}
|
|
@@ -6389,8 +6389,8 @@ var require_multistream = __commonJS({
|
|
|
6389
6389
|
write,
|
|
6390
6390
|
add,
|
|
6391
6391
|
remove,
|
|
6392
|
-
minLevel:
|
|
6393
|
-
streams,
|
|
6392
|
+
minLevel: level2,
|
|
6393
|
+
streams: streams2,
|
|
6394
6394
|
clone,
|
|
6395
6395
|
emit,
|
|
6396
6396
|
flushSync,
|
|
@@ -6515,7 +6515,7 @@ var require_pino = __commonJS({
|
|
|
6515
6515
|
nestedKey,
|
|
6516
6516
|
base,
|
|
6517
6517
|
name,
|
|
6518
|
-
level,
|
|
6518
|
+
level: level2,
|
|
6519
6519
|
customLevels,
|
|
6520
6520
|
levelComparison,
|
|
6521
6521
|
mixin,
|
|
@@ -6564,7 +6564,7 @@ var require_pino = __commonJS({
|
|
|
6564
6564
|
if (useOnlyCustomLevels && !customLevels) throw Error("customLevels is required if useOnlyCustomLevels is set true");
|
|
6565
6565
|
if (mixin && typeof mixin !== "function") throw Error(`Unknown mixin type "${typeof mixin}" - expected "function"`);
|
|
6566
6566
|
if (msgPrefix && typeof msgPrefix !== "string") throw Error(`Unknown msgPrefix type "${typeof msgPrefix}" - expected "string"`);
|
|
6567
|
-
assertDefaultLevelFound(
|
|
6567
|
+
assertDefaultLevelFound(level2, customLevels, useOnlyCustomLevels);
|
|
6568
6568
|
const levels = mappings(customLevels, useOnlyCustomLevels);
|
|
6569
6569
|
if (typeof stream.emit === "function") {
|
|
6570
6570
|
stream.emit("message", { code: "PINO_CONFIG", config: { levels, messageKey, errorKey } });
|
|
@@ -6600,7 +6600,7 @@ var require_pino = __commonJS({
|
|
|
6600
6600
|
});
|
|
6601
6601
|
Object.setPrototypeOf(instance, proto());
|
|
6602
6602
|
genLsCache(instance);
|
|
6603
|
-
instance[setLevelSym](
|
|
6603
|
+
instance[setLevelSym](level2);
|
|
6604
6604
|
return instance;
|
|
6605
6605
|
}
|
|
6606
6606
|
module.exports = pino2;
|
|
@@ -7604,32 +7604,46 @@ import { homedir } from "os";
|
|
|
7604
7604
|
import { join as join5 } from "path";
|
|
7605
7605
|
import { existsSync as existsSync4, mkdirSync } from "fs";
|
|
7606
7606
|
var logDir = join5(homedir(), ".ocosay");
|
|
7607
|
-
|
|
7608
|
-
|
|
7609
|
-
|
|
7610
|
-
|
|
7611
|
-
|
|
7612
|
-
}
|
|
7607
|
+
var logFile = join5(logDir, "ocosay.log");
|
|
7608
|
+
if (!existsSync4(logDir)) {
|
|
7609
|
+
try {
|
|
7610
|
+
mkdirSync(logDir, { recursive: true });
|
|
7611
|
+
} catch {
|
|
7613
7612
|
}
|
|
7614
7613
|
}
|
|
7615
|
-
|
|
7616
|
-
|
|
7617
|
-
|
|
7618
|
-
|
|
7619
|
-
|
|
7620
|
-
|
|
7621
|
-
target: "pino/file",
|
|
7622
|
-
options: { destination: join5(logDir, "ocosay.log"), mkdir: false },
|
|
7623
|
-
level: "info"
|
|
7624
|
-
}
|
|
7625
|
-
]
|
|
7626
|
-
}
|
|
7627
|
-
});
|
|
7628
|
-
if (process.env.NODE_ENV !== "production") {
|
|
7629
|
-
logger.level = "debug";
|
|
7614
|
+
var streams = [
|
|
7615
|
+
{ stream: process.stdout }
|
|
7616
|
+
];
|
|
7617
|
+
try {
|
|
7618
|
+
streams.push({ stream: import_pino.default.destination({ dest: logFile, mkdir: true }) });
|
|
7619
|
+
} catch {
|
|
7630
7620
|
}
|
|
7621
|
+
var level = process.env.NODE_ENV !== "production" ? "debug" : process.env.OCOSAY_LOG_LEVEL || "info";
|
|
7622
|
+
var logger = (0, import_pino.default)(
|
|
7623
|
+
{
|
|
7624
|
+
level,
|
|
7625
|
+
base: { service: "ocosay" },
|
|
7626
|
+
timestamp: import_pino.default.stdTimeFunctions.isoTime
|
|
7627
|
+
},
|
|
7628
|
+
import_pino.default.multistream(streams)
|
|
7629
|
+
);
|
|
7631
7630
|
|
|
7632
7631
|
// src/core/speaker.ts
|
|
7632
|
+
function toast(options) {
|
|
7633
|
+
const tui = global.__opencode_tui__;
|
|
7634
|
+
if (tui?.showToast) {
|
|
7635
|
+
try {
|
|
7636
|
+
tui.showToast({
|
|
7637
|
+
title: options.title,
|
|
7638
|
+
message: options.body,
|
|
7639
|
+
variant: options.type,
|
|
7640
|
+
duration: 3e3
|
|
7641
|
+
});
|
|
7642
|
+
} catch (err) {
|
|
7643
|
+
logger.warn({ err }, "toast call failed");
|
|
7644
|
+
}
|
|
7645
|
+
}
|
|
7646
|
+
}
|
|
7633
7647
|
var Speaker = class extends EventEmitter2 {
|
|
7634
7648
|
constructor(options = {}) {
|
|
7635
7649
|
super();
|
|
@@ -7639,21 +7653,11 @@ var Speaker = class extends EventEmitter2 {
|
|
|
7639
7653
|
onEnd: () => {
|
|
7640
7654
|
this.isSpeaking = false;
|
|
7641
7655
|
this.emit("end", this.currentText);
|
|
7642
|
-
|
|
7643
|
-
|
|
7644
|
-
|
|
7645
|
-
|
|
7646
|
-
|
|
7647
|
-
title: "\u{1F399}\uFE0F TTS",
|
|
7648
|
-
message: "Playback completed",
|
|
7649
|
-
variant: "success",
|
|
7650
|
-
duration: 3e3
|
|
7651
|
-
}
|
|
7652
|
-
});
|
|
7653
|
-
} catch (err) {
|
|
7654
|
-
console.warn("[Speaker] Toast playback completed failed:", err);
|
|
7655
|
-
}
|
|
7656
|
-
}
|
|
7656
|
+
toast({
|
|
7657
|
+
title: "TTS playback success",
|
|
7658
|
+
body: "Audio generated and playing",
|
|
7659
|
+
type: "info"
|
|
7660
|
+
});
|
|
7657
7661
|
},
|
|
7658
7662
|
onError: (error) => this.emit("error", error),
|
|
7659
7663
|
onPause: () => {
|
|
@@ -7696,21 +7700,6 @@ var Speaker = class extends EventEmitter2 {
|
|
|
7696
7700
|
}
|
|
7697
7701
|
this.isSpeaking = true;
|
|
7698
7702
|
this.currentText = text;
|
|
7699
|
-
const showToastFn = global.__opencode_tui__?.showToast;
|
|
7700
|
-
if (showToastFn) {
|
|
7701
|
-
try {
|
|
7702
|
-
showToastFn({
|
|
7703
|
-
body: {
|
|
7704
|
-
title: "\u{1F399}\uFE0F TTS",
|
|
7705
|
-
message: `Playing: ${text.substring(0, 30)}...`,
|
|
7706
|
-
variant: "info",
|
|
7707
|
-
duration: 3e3
|
|
7708
|
-
}
|
|
7709
|
-
});
|
|
7710
|
-
} catch (err) {
|
|
7711
|
-
console.warn("[Speaker] Toast playback start failed:", err);
|
|
7712
|
-
}
|
|
7713
|
-
}
|
|
7714
7703
|
try {
|
|
7715
7704
|
const providerName = options.provider || this.options.defaultProvider || "minimax";
|
|
7716
7705
|
if (!hasProvider(providerName)) {
|
|
@@ -7735,21 +7724,12 @@ var Speaker = class extends EventEmitter2 {
|
|
|
7735
7724
|
}
|
|
7736
7725
|
} catch (error) {
|
|
7737
7726
|
this.isSpeaking = false;
|
|
7738
|
-
const
|
|
7739
|
-
|
|
7740
|
-
|
|
7741
|
-
|
|
7742
|
-
|
|
7743
|
-
|
|
7744
|
-
message: "Playback failed, please check config",
|
|
7745
|
-
variant: "error",
|
|
7746
|
-
duration: 3e3
|
|
7747
|
-
}
|
|
7748
|
-
});
|
|
7749
|
-
} catch (err) {
|
|
7750
|
-
console.warn("[Speaker] Toast playback failed:", err);
|
|
7751
|
-
}
|
|
7752
|
-
}
|
|
7727
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
7728
|
+
toast({
|
|
7729
|
+
title: "TTS playback error",
|
|
7730
|
+
body: errorMessage,
|
|
7731
|
+
type: "error"
|
|
7732
|
+
});
|
|
7753
7733
|
if (error instanceof TTSError) {
|
|
7754
7734
|
this.emit("error", error);
|
|
7755
7735
|
throw error;
|
|
@@ -7877,21 +7857,30 @@ function extractTextArg(args) {
|
|
|
7877
7857
|
return text.trim();
|
|
7878
7858
|
}
|
|
7879
7859
|
const text7 = argObj.text7;
|
|
7880
|
-
if (
|
|
7881
|
-
|
|
7882
|
-
|
|
7860
|
+
if (text7 !== null && text7 !== void 0) {
|
|
7861
|
+
if (typeof text7 === "string" && text7.trim().length > 0) {
|
|
7862
|
+
logger.warn("received text7 instead of text from OpenCode framework");
|
|
7863
|
+
return text7.trim();
|
|
7864
|
+
}
|
|
7865
|
+
if (typeof text7 === "object" && "content" in text7) {
|
|
7866
|
+
const content = text7.content;
|
|
7867
|
+
if (typeof content === "string" && content.trim().length > 0) {
|
|
7868
|
+
logger.warn("text7 is an object with content field");
|
|
7869
|
+
return content.trim();
|
|
7870
|
+
}
|
|
7871
|
+
}
|
|
7872
|
+
logger.warn({ type: typeof text7 }, "text7 is not a valid string or object with content");
|
|
7883
7873
|
}
|
|
7884
7874
|
for (const key of Object.keys(argObj)) {
|
|
7885
7875
|
if (key.startsWith("text") && key !== "text" && key !== "text7") {
|
|
7886
7876
|
const val = argObj[key];
|
|
7887
7877
|
if (typeof val === "string" && val.trim().length > 0) {
|
|
7888
|
-
console.debug(`[tts] Using ${key} as text source`);
|
|
7889
7878
|
return val.trim();
|
|
7890
7879
|
}
|
|
7891
7880
|
}
|
|
7892
7881
|
}
|
|
7893
7882
|
if (text !== void 0) {
|
|
7894
|
-
|
|
7883
|
+
logger.warn({ type: typeof text }, "text arg is not a valid string");
|
|
7895
7884
|
}
|
|
7896
7885
|
return void 0;
|
|
7897
7886
|
}
|
|
@@ -7903,14 +7892,7 @@ async function handleToolCall(toolName, args) {
|
|
|
7903
7892
|
if (!text) {
|
|
7904
7893
|
return { success: false, error: "No valid text found in args" };
|
|
7905
7894
|
}
|
|
7906
|
-
await speak(text
|
|
7907
|
-
provider: args?.provider,
|
|
7908
|
-
voice: args?.voice,
|
|
7909
|
-
model: args?.model,
|
|
7910
|
-
speed: args?.speed,
|
|
7911
|
-
volume: args?.volume,
|
|
7912
|
-
pitch: args?.pitch
|
|
7913
|
-
});
|
|
7895
|
+
await speak(text);
|
|
7914
7896
|
return { success: true, message: "Speech completed" };
|
|
7915
7897
|
}
|
|
7916
7898
|
case "tts_stop":
|
|
@@ -7960,7 +7942,7 @@ async function handleToolCall(toolName, args) {
|
|
|
7960
7942
|
streamReader2.start();
|
|
7961
7943
|
const textArg = extractTextArg(args);
|
|
7962
7944
|
if (textArg && typeof textArg === "string" && textArg.trim().length > 0) {
|
|
7963
|
-
|
|
7945
|
+
logger.info({ text: textArg.substring(0, 50) + "..." }, "synthesizing text");
|
|
7964
7946
|
synthesizer.synthesize(textArg);
|
|
7965
7947
|
}
|
|
7966
7948
|
return { success: true, message: "Stream speak started" };
|
|
@@ -8915,7 +8897,7 @@ function initializeStreamComponents(config) {
|
|
|
8915
8897
|
},
|
|
8916
8898
|
onProgress: (bytesWritten) => {
|
|
8917
8899
|
},
|
|
8918
|
-
onError: (error) =>
|
|
8900
|
+
onError: (error) => logger.error({ error }, "stream player error"),
|
|
8919
8901
|
onStop: () => {
|
|
8920
8902
|
}
|
|
8921
8903
|
};
|
|
@@ -8929,7 +8911,7 @@ function initializeStreamComponents(config) {
|
|
|
8929
8911
|
try {
|
|
8930
8912
|
await streamingSynthesizer?.synthesize(text);
|
|
8931
8913
|
} catch (error) {
|
|
8932
|
-
|
|
8914
|
+
logger.error({ error }, "synthesize error");
|
|
8933
8915
|
}
|
|
8934
8916
|
}
|
|
8935
8917
|
isSynthesizing = false;
|
|
@@ -9106,7 +9088,7 @@ function loadOrCreateConfig() {
|
|
|
9106
9088
|
}
|
|
9107
9089
|
}
|
|
9108
9090
|
if (!fs2.existsSync(CONFIG_PATH)) {
|
|
9109
|
-
|
|
9091
|
+
logger.info("config file not found, creating default config");
|
|
9110
9092
|
const defaultConfig = generateDefaultConfig();
|
|
9111
9093
|
const configContent = JSON.stringify(defaultConfig, null, 2);
|
|
9112
9094
|
try {
|
|
@@ -9114,13 +9096,13 @@ function loadOrCreateConfig() {
|
|
|
9114
9096
|
try {
|
|
9115
9097
|
fs2.chmodSync(CONFIG_PATH, 384);
|
|
9116
9098
|
} catch (err) {
|
|
9117
|
-
|
|
9099
|
+
logger.warn({ err }, "failed to set config file permissions");
|
|
9118
9100
|
}
|
|
9119
9101
|
} catch (err) {
|
|
9120
|
-
throw new Error(`[ocosay]
|
|
9102
|
+
throw new Error(`[ocosay] cannot write config file ${CONFIG_PATH}: ${err}`);
|
|
9121
9103
|
}
|
|
9122
|
-
|
|
9123
|
-
|
|
9104
|
+
logger.info({ path: CONFIG_PATH }, "config file created");
|
|
9105
|
+
logger.info("please edit config file to add API Key and Base URL");
|
|
9124
9106
|
return defaultConfig;
|
|
9125
9107
|
}
|
|
9126
9108
|
try {
|
|
@@ -9142,7 +9124,7 @@ function loadOrCreateConfig() {
|
|
|
9142
9124
|
}
|
|
9143
9125
|
};
|
|
9144
9126
|
} catch (error) {
|
|
9145
|
-
|
|
9127
|
+
logger.error({ error }, "config file read failed, using default config");
|
|
9146
9128
|
return generateDefaultConfig();
|
|
9147
9129
|
}
|
|
9148
9130
|
}
|
|
@@ -9161,15 +9143,9 @@ try {
|
|
|
9161
9143
|
} catch {
|
|
9162
9144
|
}
|
|
9163
9145
|
var ttsSpeakTool = tool({
|
|
9164
|
-
description: "\u5C06\u6587\u672C\u8F6C\u6362\u4E3A\u8BED\u97F3\u5E76\u64AD\u653E",
|
|
9146
|
+
description: "\u5C06\u6587\u672C\u8F6C\u6362\u4E3A\u8BED\u97F3\u5E76\u64AD\u653E\uFF08\u4F7F\u7528\u914D\u7F6E\u6587\u4EF6\u4E2D\u7684\u9ED8\u8BA4\u97F3\u8272\u548C\u6A21\u578B\uFF09",
|
|
9165
9147
|
args: {
|
|
9166
|
-
text: tool.schema.string().describe("\u8981\u8F6C\u6362\u7684\u6587\u672C\u5185\u5BB9")
|
|
9167
|
-
provider: tool.schema.string().optional().describe("TTS \u63D0\u4F9B\u5546\u540D\u79F0"),
|
|
9168
|
-
voice: tool.schema.string().optional().describe("\u97F3\u8272 ID"),
|
|
9169
|
-
model: tool.schema.enum(["sync", "async", "stream"]).optional().describe("\u5408\u6210\u6A21\u5F0F"),
|
|
9170
|
-
speed: tool.schema.number().optional().describe("\u8BED\u901F 0.5-2.0"),
|
|
9171
|
-
volume: tool.schema.number().optional().describe("\u97F3\u91CF 0-100"),
|
|
9172
|
-
pitch: tool.schema.number().optional().describe("\u97F3\u8C03 0.5-2.0")
|
|
9148
|
+
text: tool.schema.string().describe("\u8981\u8F6C\u6362\u7684\u6587\u672C\u5185\u5BB9")
|
|
9173
9149
|
},
|
|
9174
9150
|
execute: async (args) => {
|
|
9175
9151
|
const result = await handleToolCall("tts_speak", args);
|
|
@@ -9213,10 +9189,8 @@ var ttsResumeTool = tool({
|
|
|
9213
9189
|
}
|
|
9214
9190
|
});
|
|
9215
9191
|
var ttsListVoicesTool = tool({
|
|
9216
|
-
description: "\u5217\u51FA\u53EF\u7528\u7684\u97F3\u8272",
|
|
9217
|
-
args: {
|
|
9218
|
-
provider: tool.schema.string().optional().describe("TTS \u63D0\u4F9B\u5546\u540D\u79F0")
|
|
9219
|
-
},
|
|
9192
|
+
description: "\u5217\u51FA\u53EF\u7528\u7684\u97F3\u8272\uFF08\u4F7F\u7528\u914D\u7F6E\u6587\u4EF6\u4E2D\u7684\u9ED8\u8BA4\u63D0\u4F9B\u5546\uFF09",
|
|
9193
|
+
args: {},
|
|
9220
9194
|
execute: async (args) => {
|
|
9221
9195
|
const result = await handleToolCall("tts_list_voices", args);
|
|
9222
9196
|
if (result.success === false) {
|
|
@@ -9248,11 +9222,9 @@ var ttsStatusTool = tool({
|
|
|
9248
9222
|
}
|
|
9249
9223
|
});
|
|
9250
9224
|
var ttsStreamSpeakTool = tool({
|
|
9251
|
-
description: "\u542F\u52A8\u6D41\u5F0F\u6717\u8BFB\uFF08\u8C46\u5305\u6A21\u5F0F\uFF09\uFF0C\u8BA2\u9605AI\u56DE\u590D\u5E76\u8FB9\u751F\u6210\u8FB9\u6717\u8BFB",
|
|
9225
|
+
description: "\u542F\u52A8\u6D41\u5F0F\u6717\u8BFB\uFF08\u8C46\u5305\u6A21\u5F0F\uFF09\uFF0C\u8BA2\u9605AI\u56DE\u590D\u5E76\u8FB9\u751F\u6210\u8FB9\u6717\u8BFB\uFF08\u4F7F\u7528\u914D\u7F6E\u6587\u4EF6\u4E2D\u7684\u9ED8\u8BA4\u97F3\u8272\uFF09",
|
|
9252
9226
|
args: {
|
|
9253
|
-
text: tool.schema.string().optional().describe("\u521D\u59CB\u6587\u672C\uFF08\u53EF\u9009\uFF09")
|
|
9254
|
-
voice: tool.schema.string().optional().describe("\u97F3\u8272ID"),
|
|
9255
|
-
model: tool.schema.enum(["sync", "async", "stream"]).optional().describe("\u5408\u6210\u6A21\u5F0F")
|
|
9227
|
+
text: tool.schema.string().optional().describe("\u521D\u59CB\u6587\u672C\uFF08\u53EF\u9009\uFF09")
|
|
9256
9228
|
},
|
|
9257
9229
|
execute: async (args) => {
|
|
9258
9230
|
const result = await handleToolCall("tts_stream_speak", args);
|
|
@@ -9300,7 +9272,7 @@ var server = (async (input, _options) => {
|
|
|
9300
9272
|
});
|
|
9301
9273
|
} catch (err) {
|
|
9302
9274
|
initError = err instanceof Error ? err : new Error(String(err));
|
|
9303
|
-
|
|
9275
|
+
logger.error({ error: initError }, "initialization failed");
|
|
9304
9276
|
}
|
|
9305
9277
|
const opencodeTui = input.client?.tui;
|
|
9306
9278
|
global.__opencode_tui__ = opencodeTui;
|