yuanflow-cli 0.1.50 → 0.1.51
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/package.json +1 -1
- package/src/ai-tools.js +26 -2
package/package.json
CHANGED
package/src/ai-tools.js
CHANGED
|
@@ -587,7 +587,7 @@ export function normalizeAudioResponseBytes(rawBytes, contentType = '') {
|
|
|
587
587
|
return rawBytes;
|
|
588
588
|
}
|
|
589
589
|
const chunks = [];
|
|
590
|
-
for (const line of text
|
|
590
|
+
for (const line of splitJsonBase64AudioRecords(text)) {
|
|
591
591
|
const trimmed = line.trim();
|
|
592
592
|
if (!trimmed) {
|
|
593
593
|
continue;
|
|
@@ -598,10 +598,14 @@ export function normalizeAudioResponseBytes(rawBytes, contentType = '') {
|
|
|
598
598
|
} catch {
|
|
599
599
|
return rawBytes;
|
|
600
600
|
}
|
|
601
|
-
|
|
601
|
+
const code = payload && payload.code !== undefined ? Number(payload.code) : 0;
|
|
602
|
+
if (payload && payload.code !== undefined && code !== 0 && code !== 20000000) {
|
|
602
603
|
throw new Error(payload.message || '音频生成失败。');
|
|
603
604
|
}
|
|
604
605
|
if (!payload || typeof payload.data !== 'string' || !payload.data) {
|
|
606
|
+
if (chunks.length > 0) {
|
|
607
|
+
continue;
|
|
608
|
+
}
|
|
605
609
|
return rawBytes;
|
|
606
610
|
}
|
|
607
611
|
chunks.push(Buffer.from(payload.data, 'base64'));
|
|
@@ -609,6 +613,26 @@ export function normalizeAudioResponseBytes(rawBytes, contentType = '') {
|
|
|
609
613
|
return chunks.length > 0 ? Buffer.concat(chunks) : rawBytes;
|
|
610
614
|
}
|
|
611
615
|
|
|
616
|
+
function splitJsonBase64AudioRecords(text) {
|
|
617
|
+
const lines = text.split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
|
|
618
|
+
if (lines.length > 1) {
|
|
619
|
+
return lines;
|
|
620
|
+
}
|
|
621
|
+
return text
|
|
622
|
+
.split(/}\s*{/)
|
|
623
|
+
.map((part, index, parts) => {
|
|
624
|
+
let value = part.trim();
|
|
625
|
+
if (index > 0) {
|
|
626
|
+
value = `{${value}`;
|
|
627
|
+
}
|
|
628
|
+
if (index < parts.length - 1) {
|
|
629
|
+
value = `${value}}`;
|
|
630
|
+
}
|
|
631
|
+
return value;
|
|
632
|
+
})
|
|
633
|
+
.filter(Boolean);
|
|
634
|
+
}
|
|
635
|
+
|
|
612
636
|
async function buildRequest(apiPath, options, method, body) {
|
|
613
637
|
const config = await readConfig();
|
|
614
638
|
const baseUrl = cleanBaseUrl(options.baseUrl || config.baseUrl);
|