@openclaw/volcengine-provider 2026.9.8 → 2026.10.1-beta.2

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.
Files changed (2) hide show
  1. package/dist/tts.js +42 -72
  2. package/package.json +4 -4
package/dist/tts.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { asOptionalRecord, isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
1
2
  import * as crypto from "node:crypto";
2
3
  //#region extensions/volcengine/tts.ts
3
4
  const DEFAULT_SEED_VOICE = "en_female_anna_mars_bigtts";
@@ -11,7 +12,7 @@ const VOLCENGINE_LEGACY_TTS_URL = "https://openspeech.bytedance.com/api/v1/tts";
11
12
  function parseJsonObject(text, providerName) {
12
13
  try {
13
14
  const parsed = JSON.parse(text);
14
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error("expected JSON object");
15
+ if (!isRecord(parsed)) throw new Error("expected JSON object");
15
16
  return parsed;
16
17
  } catch (err) {
17
18
  const detail = err instanceof Error ? err.message : String(err);
@@ -19,7 +20,7 @@ function parseJsonObject(text, providerName) {
19
20
  }
20
21
  }
21
22
  function toTtsResponse(parsed) {
22
- const header = parsed.header && typeof parsed.header === "object" && !Array.isArray(parsed.header) ? parsed.header : void 0;
23
+ const header = asOptionalRecord(parsed.header);
23
24
  return {
24
25
  code: typeof parsed.code === "number" ? parsed.code : typeof header?.code === "number" ? header.code : void 0,
25
26
  message: typeof parsed.message === "string" ? parsed.message : typeof header?.message === "string" ? header.message : void 0,
@@ -41,69 +42,26 @@ function parseSeedTtsFrames(text) {
41
42
  }
42
43
  return frames;
43
44
  }
44
- async function seedSpeechTTS(params) {
45
- const { text, apiKey, voice = DEFAULT_SEED_VOICE, resourceId = DEFAULT_SEED_TTS_RESOURCE_ID, appKey = DEFAULT_SEED_TTS_APP_KEY, baseUrl = BYTEPLUS_SEED_TTS_URL, speedRatio = 1, emotion, encoding = "ogg_opus", timeoutMs = 3e4 } = params;
46
- const audioFormat = encoding === "wav" ? "pcm" : encoding;
45
+ async function volcengineTTS(params) {
46
+ if (!params.apiKey && (!params.appId || !params.token)) throw new Error("Volcengine TTS credentials missing. Set a BytePlus Seed Speech API key or legacy AppID/token.");
47
+ const { text, apiKey, appId, token, voice = apiKey ? DEFAULT_SEED_VOICE : DEFAULT_LEGACY_VOICE, cluster = DEFAULT_CLUSTER, resourceId = DEFAULT_SEED_TTS_RESOURCE_ID, appKey = DEFAULT_SEED_TTS_APP_KEY, baseUrl = apiKey ? BYTEPLUS_SEED_TTS_URL : VOLCENGINE_LEGACY_TTS_URL, speedRatio = 1, volumeRatio = 1, pitchRatio = 1, emotion, encoding = "ogg_opus", timeoutMs = 3e4 } = params;
47
48
  const { canonicalizeBase64 } = await import("openclaw/plugin-sdk/media-runtime");
48
49
  const { readResponseWithLimit } = await import("openclaw/plugin-sdk/response-limit-runtime");
49
50
  const { fetchWithSsrFGuard } = await import("openclaw/plugin-sdk/ssrf-runtime");
50
- const payload = JSON.stringify({
51
+ const providerName = apiKey ? "BytePlus Seed Speech" : "Volcengine";
52
+ const payload = apiKey ? {
51
53
  user: { uid: "openclaw" },
52
54
  req_params: {
53
55
  text,
54
56
  speaker: voice,
55
57
  audio_params: {
56
- format: audioFormat,
58
+ format: encoding === "wav" ? "pcm" : encoding,
57
59
  sample_rate: 24e3
58
60
  },
59
61
  ...speedRatio !== 1 ? { speed_ratio: speedRatio } : {},
60
62
  ...emotion ? { emotion } : {}
61
63
  }
62
- });
63
- const { response, release } = await fetchWithSsrFGuard({
64
- url: baseUrl,
65
- init: {
66
- method: "POST",
67
- headers: {
68
- "Content-Type": "application/json",
69
- Connection: "keep-alive",
70
- "X-Api-Key": apiKey,
71
- "X-Api-Resource-Id": resourceId,
72
- "X-Api-App-Key": appKey
73
- },
74
- body: payload
75
- },
76
- timeoutMs,
77
- policy: { hostnameAllowlist: [new URL(baseUrl).hostname] },
78
- auditContext: "volcengine.tts"
79
- });
80
- try {
81
- const frames = parseSeedTtsFrames(new TextDecoder("utf-8", { fatal: true }).decode(await readResponseWithLimit(response, VOLCENGINE_TTS_RESPONSE_MAX_BYTES, { onOverflow: ({ maxBytes }) => /* @__PURE__ */ new Error(`BytePlus Seed Speech TTS response exceeds ${maxBytes} bytes`) })));
82
- const chunks = [];
83
- for (const frame of frames) {
84
- if (frame.code === 0) {
85
- if (frame.data) {
86
- const canonicalAudio = canonicalizeBase64(frame.data);
87
- if (!canonicalAudio) throw new Error("BytePlus Seed Speech TTS returned malformed base64 audio data");
88
- chunks.push(Buffer.from(canonicalAudio, "base64"));
89
- }
90
- continue;
91
- }
92
- if (frame.code === 2e7) continue;
93
- throw new Error(`BytePlus Seed Speech TTS error ${frame.code ?? response.status}: ${frame.message ?? "unknown"}`);
94
- }
95
- if (!response.ok || chunks.length === 0) throw new Error(`BytePlus Seed Speech TTS error ${response.status}: no audio data`);
96
- return Buffer.concat(chunks);
97
- } finally {
98
- await release();
99
- }
100
- }
101
- async function legacyVolcengineTTS(params) {
102
- const { canonicalizeBase64 } = await import("openclaw/plugin-sdk/media-runtime");
103
- const { readResponseWithLimit } = await import("openclaw/plugin-sdk/response-limit-runtime");
104
- const { fetchWithSsrFGuard } = await import("openclaw/plugin-sdk/ssrf-runtime");
105
- const { text, appId, token, voice = DEFAULT_LEGACY_VOICE, cluster = DEFAULT_CLUSTER, baseUrl = VOLCENGINE_LEGACY_TTS_URL, speedRatio = 1, volumeRatio = 1, pitchRatio = 1, emotion, encoding = "ogg_opus", timeoutMs = 3e4 } = params;
106
- const payload = JSON.stringify({
64
+ } : {
107
65
  app: {
108
66
  appid: appId,
109
67
  token,
@@ -124,42 +82,54 @@ async function legacyVolcengineTTS(params) {
124
82
  text_type: "plain",
125
83
  operation: "query"
126
84
  }
127
- });
85
+ };
128
86
  const { response, release } = await fetchWithSsrFGuard({
129
87
  url: baseUrl,
130
88
  init: {
131
89
  method: "POST",
132
90
  headers: {
133
91
  "Content-Type": "application/json",
134
- Authorization: `Bearer;${token}`
92
+ ...apiKey ? {
93
+ Connection: "keep-alive",
94
+ "X-Api-Key": apiKey,
95
+ "X-Api-Resource-Id": resourceId,
96
+ "X-Api-App-Key": appKey
97
+ } : { Authorization: `Bearer;${token}` }
135
98
  },
136
- body: payload
99
+ body: JSON.stringify(payload)
137
100
  },
138
101
  timeoutMs,
139
102
  policy: { hostnameAllowlist: [new URL(baseUrl).hostname] },
140
103
  auditContext: "volcengine.tts"
141
104
  });
142
105
  try {
143
- const body = toTtsResponse(parseJsonObject(new TextDecoder("utf-8", { fatal: true }).decode(await readResponseWithLimit(response, VOLCENGINE_TTS_RESPONSE_MAX_BYTES, { onOverflow: ({ maxBytes }) => /* @__PURE__ */ new Error(`Volcengine TTS response exceeds ${maxBytes} bytes`) })), "Volcengine"));
144
- if (!response.ok || body.code !== 3e3 || !body.data) throw new Error(`Volcengine TTS error ${body.code ?? response.status}: ${body.message ?? "unknown"}`);
145
- const canonicalAudio = canonicalizeBase64(body.data);
146
- if (!canonicalAudio) throw new Error("Volcengine TTS returned malformed base64 audio data");
147
- return Buffer.from(canonicalAudio, "base64");
106
+ const responseText = new TextDecoder("utf-8", { fatal: true }).decode(await readResponseWithLimit(response, VOLCENGINE_TTS_RESPONSE_MAX_BYTES, { onOverflow: ({ maxBytes }) => /* @__PURE__ */ new Error(`${providerName} TTS response exceeds ${maxBytes} bytes`) }));
107
+ if (!apiKey) {
108
+ const body = toTtsResponse(parseJsonObject(responseText, providerName));
109
+ if (!response.ok || body.code !== 3e3 || !body.data) throw new Error(`Volcengine TTS error ${body.code ?? response.status}: ${body.message ?? "unknown"}`);
110
+ const canonicalAudio = canonicalizeBase64(body.data);
111
+ if (!canonicalAudio) throw new Error("Volcengine TTS returned malformed base64 audio data");
112
+ return Buffer.from(canonicalAudio, "base64");
113
+ }
114
+ const frames = parseSeedTtsFrames(responseText);
115
+ const chunks = [];
116
+ for (const frame of frames) {
117
+ if (frame.code === 0) {
118
+ if (frame.data) {
119
+ const canonicalAudio = canonicalizeBase64(frame.data);
120
+ if (!canonicalAudio) throw new Error("BytePlus Seed Speech TTS returned malformed base64 audio data");
121
+ chunks.push(Buffer.from(canonicalAudio, "base64"));
122
+ }
123
+ continue;
124
+ }
125
+ if (frame.code === 2e7) continue;
126
+ throw new Error(`BytePlus Seed Speech TTS error ${frame.code ?? response.status}: ${frame.message ?? "unknown"}`);
127
+ }
128
+ if (!response.ok || chunks.length === 0) throw new Error(`BytePlus Seed Speech TTS error ${response.status}: no audio data`);
129
+ return Buffer.concat(chunks);
148
130
  } finally {
149
131
  await release();
150
132
  }
151
133
  }
152
- async function volcengineTTS(params) {
153
- if (params.apiKey) return seedSpeechTTS({
154
- ...params,
155
- apiKey: params.apiKey
156
- });
157
- if (params.appId && params.token) return legacyVolcengineTTS({
158
- ...params,
159
- appId: params.appId,
160
- token: params.token
161
- });
162
- throw new Error("Volcengine TTS credentials missing. Set a BytePlus Seed Speech API key or legacy AppID/token.");
163
- }
164
134
  //#endregion
165
135
  export { volcengineTTS };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openclaw/volcengine-provider",
3
- "version": "2026.9.8",
3
+ "version": "2026.10.1-beta.2",
4
4
  "description": "OpenClaw Volcengine provider plugin.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -18,10 +18,10 @@
18
18
  "minHostVersion": ">=2026.7.2"
19
19
  },
20
20
  "compat": {
21
- "pluginApi": ">=2026.9.8"
21
+ "pluginApi": ">=2026.10.1-beta.2"
22
22
  },
23
23
  "build": {
24
- "openclawVersion": "2026.9.8",
24
+ "openclawVersion": "2026.10.1-beta.2",
25
25
  "bundledDist": false
26
26
  },
27
27
  "release": {
@@ -40,7 +40,7 @@
40
40
  "assets/activity.svg"
41
41
  ],
42
42
  "peerDependencies": {
43
- "openclaw": ">=2026.9.8"
43
+ "openclaw": ">=2026.10.1-beta.2"
44
44
  },
45
45
  "peerDependenciesMeta": {
46
46
  "openclaw": {