@superdurable/connector-elevenlabs 0.0.0-stage → 0.2.0
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/LICENSE +21 -0
- package/README.md +8 -2
- package/dex-connector.json +565 -0
- package/dist/chunk-UBMQRHWH.js +481 -0
- package/dist/connection-BWnmpStG.d.ts +347 -0
- package/dist/index.d.ts +599 -0
- package/dist/index.js +924 -0
- package/dist/mock.d.ts +208 -0
- package/dist/mock.js +501 -0
- package/package.json +62 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,924 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ConfigSchema,
|
|
3
|
+
Connection,
|
|
4
|
+
ConnectorID,
|
|
5
|
+
CreateSpeechBranch,
|
|
6
|
+
CreateSpeechBranchCreated,
|
|
7
|
+
CreateSpeechBranchDefect,
|
|
8
|
+
CreateSpeechBranchInvalidResponse,
|
|
9
|
+
CreateSpeechBranchProviderRejected,
|
|
10
|
+
CreateSpeechDefinition,
|
|
11
|
+
CreateSpeechInputSchema,
|
|
12
|
+
CreateSpeechMetadata,
|
|
13
|
+
CreateSpeechOutputSchema,
|
|
14
|
+
CredentialMaterialError,
|
|
15
|
+
DeleteHistoryItemBranch,
|
|
16
|
+
DeleteHistoryItemBranchDefect,
|
|
17
|
+
DeleteHistoryItemBranchDeleted,
|
|
18
|
+
DeleteHistoryItemBranchInvalidResponse,
|
|
19
|
+
DeleteHistoryItemBranchProviderRejected,
|
|
20
|
+
DeleteHistoryItemDefinition,
|
|
21
|
+
DeleteHistoryItemMetadata,
|
|
22
|
+
DeleteVoiceBranch,
|
|
23
|
+
DeleteVoiceBranchDefect,
|
|
24
|
+
DeleteVoiceBranchDeleted,
|
|
25
|
+
DeleteVoiceBranchInvalidResponse,
|
|
26
|
+
DeleteVoiceBranchProviderRejected,
|
|
27
|
+
DeleteVoiceDefinition,
|
|
28
|
+
DeleteVoiceMetadata,
|
|
29
|
+
DeletedHistoryItemSchema,
|
|
30
|
+
DeletedVoiceSchema,
|
|
31
|
+
EditVoiceMetadataBranch,
|
|
32
|
+
EditVoiceMetadataBranchDefect,
|
|
33
|
+
EditVoiceMetadataBranchEdited,
|
|
34
|
+
EditVoiceMetadataBranchInvalidResponse,
|
|
35
|
+
EditVoiceMetadataBranchNotFound,
|
|
36
|
+
EditVoiceMetadataBranchProviderRejected,
|
|
37
|
+
EditVoiceMetadataDefinition,
|
|
38
|
+
EditVoiceMetadataInputSchema,
|
|
39
|
+
EditVoiceMetadataMetadata,
|
|
40
|
+
EditedVoiceMetadataSchema,
|
|
41
|
+
GetHistoryItemBranch,
|
|
42
|
+
GetHistoryItemBranchDefect,
|
|
43
|
+
GetHistoryItemBranchFound,
|
|
44
|
+
GetHistoryItemBranchInvalidResponse,
|
|
45
|
+
GetHistoryItemBranchNotFound,
|
|
46
|
+
GetHistoryItemBranchProviderRejected,
|
|
47
|
+
GetHistoryItemDefinition,
|
|
48
|
+
GetHistoryItemMetadata,
|
|
49
|
+
GetVoiceBranch,
|
|
50
|
+
GetVoiceBranchDefect,
|
|
51
|
+
GetVoiceBranchFound,
|
|
52
|
+
GetVoiceBranchInvalidResponse,
|
|
53
|
+
GetVoiceBranchNotFound,
|
|
54
|
+
GetVoiceBranchProviderRejected,
|
|
55
|
+
GetVoiceDefinition,
|
|
56
|
+
GetVoiceInputSchema,
|
|
57
|
+
GetVoiceMetadata,
|
|
58
|
+
HistoryItemIdentityInputSchema,
|
|
59
|
+
HistoryItemMetadataSchema,
|
|
60
|
+
HistoryItemsPageSchema,
|
|
61
|
+
ListHistoryItemsBranch,
|
|
62
|
+
ListHistoryItemsBranchDefect,
|
|
63
|
+
ListHistoryItemsBranchInvalidResponse,
|
|
64
|
+
ListHistoryItemsBranchListed,
|
|
65
|
+
ListHistoryItemsBranchProviderRejected,
|
|
66
|
+
ListHistoryItemsDefinition,
|
|
67
|
+
ListHistoryItemsInputSchema,
|
|
68
|
+
ListHistoryItemsMetadata,
|
|
69
|
+
ListModelsBranch,
|
|
70
|
+
ListModelsBranchDefect,
|
|
71
|
+
ListModelsBranchInvalidResponse,
|
|
72
|
+
ListModelsBranchListed,
|
|
73
|
+
ListModelsBranchProviderRejected,
|
|
74
|
+
ListModelsDefinition,
|
|
75
|
+
ListModelsInputSchema,
|
|
76
|
+
ListModelsMetadata,
|
|
77
|
+
ListVoicesBranch,
|
|
78
|
+
ListVoicesBranchDefect,
|
|
79
|
+
ListVoicesBranchInvalidResponse,
|
|
80
|
+
ListVoicesBranchListed,
|
|
81
|
+
ListVoicesBranchProviderRejected,
|
|
82
|
+
ListVoicesDefinition,
|
|
83
|
+
ListVoicesInputSchema,
|
|
84
|
+
ListVoicesMetadata,
|
|
85
|
+
ListVoicesOutputSchema,
|
|
86
|
+
ModelMetadataSchema,
|
|
87
|
+
ModelsListSchema,
|
|
88
|
+
ProviderID,
|
|
89
|
+
UpdateVoiceSettingsBranch,
|
|
90
|
+
UpdateVoiceSettingsBranchDefect,
|
|
91
|
+
UpdateVoiceSettingsBranchNotFound,
|
|
92
|
+
UpdateVoiceSettingsBranchProviderRejected,
|
|
93
|
+
UpdateVoiceSettingsBranchUpdated,
|
|
94
|
+
UpdateVoiceSettingsDefinition,
|
|
95
|
+
UpdateVoiceSettingsInputSchema,
|
|
96
|
+
UpdateVoiceSettingsMetadata,
|
|
97
|
+
UpdatedVoiceSettingsSchema,
|
|
98
|
+
VoiceSchema,
|
|
99
|
+
decodeCredentials,
|
|
100
|
+
isCredentialMaterialError,
|
|
101
|
+
newConnection,
|
|
102
|
+
newConnectionWithOperations,
|
|
103
|
+
newProjectConnection
|
|
104
|
+
} from "./chunk-UBMQRHWH.js";
|
|
105
|
+
|
|
106
|
+
// src/generated/steps.ts
|
|
107
|
+
import { goToBranch, newMutationStep, newQueryStep } from "@superdurable/connectors-sdk";
|
|
108
|
+
function newListModelsStep(configuration) {
|
|
109
|
+
const { connection, connectionName, listed, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
|
|
110
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
111
|
+
return newQueryStep({ ...stepConfiguration, operation: connection.operations.listModels(), connection: connection.reference, branches: [
|
|
112
|
+
goToBranch("listed", listed),
|
|
113
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
114
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
115
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
116
|
+
] });
|
|
117
|
+
}
|
|
118
|
+
function newListHistoryItemsStep(configuration) {
|
|
119
|
+
const { connection, connectionName, listed, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
|
|
120
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
121
|
+
return newQueryStep({ ...stepConfiguration, operation: connection.operations.listHistoryItems(), connection: connection.reference, branches: [
|
|
122
|
+
goToBranch("listed", listed),
|
|
123
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
124
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
125
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
126
|
+
] });
|
|
127
|
+
}
|
|
128
|
+
function newGetHistoryItemStep(configuration) {
|
|
129
|
+
const { connection, connectionName, found, notFound, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
|
|
130
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
131
|
+
return newQueryStep({ ...stepConfiguration, operation: connection.operations.getHistoryItem(), connection: connection.reference, branches: [
|
|
132
|
+
goToBranch("found", found),
|
|
133
|
+
...notFound ? [goToBranch("notFound", notFound)] : [],
|
|
134
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
135
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
136
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
137
|
+
] });
|
|
138
|
+
}
|
|
139
|
+
function newDeleteHistoryItemStep(configuration) {
|
|
140
|
+
const { connection, connectionName, deleted, providerRejected, invalidResponse, defect, maxSends, ...stepConfiguration } = configuration;
|
|
141
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
142
|
+
return newMutationStep({ ...stepConfiguration, operation: connection.operations.deleteHistoryItem(), connection: connection.reference, branches: [
|
|
143
|
+
goToBranch("deleted", deleted),
|
|
144
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
145
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
146
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
147
|
+
] });
|
|
148
|
+
}
|
|
149
|
+
function newGetVoiceStep(configuration) {
|
|
150
|
+
const { connection, connectionName, found, notFound, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
|
|
151
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
152
|
+
return newQueryStep({ ...stepConfiguration, operation: connection.operations.getVoice(), connection: connection.reference, branches: [
|
|
153
|
+
goToBranch("found", found),
|
|
154
|
+
...notFound ? [goToBranch("notFound", notFound)] : [],
|
|
155
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
156
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
157
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
158
|
+
] });
|
|
159
|
+
}
|
|
160
|
+
function newEditVoiceMetadataStep(configuration) {
|
|
161
|
+
const { connection, connectionName, edited, notFound, providerRejected, invalidResponse, defect, maxSends, ...stepConfiguration } = configuration;
|
|
162
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
163
|
+
return newMutationStep({ ...stepConfiguration, operation: connection.operations.editVoiceMetadata(), connection: connection.reference, branches: [
|
|
164
|
+
goToBranch("edited", edited),
|
|
165
|
+
...notFound ? [goToBranch("notFound", notFound)] : [],
|
|
166
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
167
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
168
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
169
|
+
] });
|
|
170
|
+
}
|
|
171
|
+
function newDeleteVoiceStep(configuration) {
|
|
172
|
+
const { connection, connectionName, deleted, providerRejected, invalidResponse, defect, maxSends, ...stepConfiguration } = configuration;
|
|
173
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
174
|
+
return newMutationStep({ ...stepConfiguration, operation: connection.operations.deleteVoice(), connection: connection.reference, branches: [
|
|
175
|
+
goToBranch("deleted", deleted),
|
|
176
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
177
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
178
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
179
|
+
] });
|
|
180
|
+
}
|
|
181
|
+
function newUpdateVoiceSettingsStep(configuration) {
|
|
182
|
+
const { connection, connectionName, updated, notFound, providerRejected, defect, maxSends, ...stepConfiguration } = configuration;
|
|
183
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
184
|
+
return newMutationStep({ ...stepConfiguration, operation: connection.operations.updateVoiceSettings(), connection: connection.reference, branches: [
|
|
185
|
+
goToBranch("updated", updated),
|
|
186
|
+
...notFound ? [goToBranch("notFound", notFound)] : [],
|
|
187
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
188
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
189
|
+
] });
|
|
190
|
+
}
|
|
191
|
+
function newListVoicesStep(configuration) {
|
|
192
|
+
const { connection, connectionName, listed, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
|
|
193
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
194
|
+
return newQueryStep({ ...stepConfiguration, operation: connection.operations.listVoices(), connection: connection.reference, branches: [
|
|
195
|
+
goToBranch("listed", listed),
|
|
196
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
197
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
198
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
199
|
+
] });
|
|
200
|
+
}
|
|
201
|
+
function newCreateSpeechStep(configuration) {
|
|
202
|
+
const { connection, connectionName, created, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
|
|
203
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
204
|
+
return newQueryStep({ ...stepConfiguration, operation: connection.operations.createSpeech(), connection: connection.reference, branches: [
|
|
205
|
+
goToBranch("created", created),
|
|
206
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
207
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
208
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
209
|
+
] });
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// src/project.ts
|
|
213
|
+
import { SecretString as SecretString2 } from "@superdurable/connectors-sdk";
|
|
214
|
+
import { z } from "zod";
|
|
215
|
+
|
|
216
|
+
// src/client.ts
|
|
217
|
+
import { BodyTooLargeError, ProviderTransportError, isHeaderSafeCredential, parseRetryAfter, sendProviderRequest, validateBaseURL } from "@superdurable/connectors-sdk/providerhttp";
|
|
218
|
+
import { SecretString, newMutationBranch as newMutationBranch2, newMutationRetry, newQueryBranch as newQueryBranch2, newQueryRetry } from "@superdurable/connectors-sdk";
|
|
219
|
+
|
|
220
|
+
// src/operations.ts
|
|
221
|
+
import { newMutationBranch, newQueryBranch } from "@superdurable/connectors-sdk";
|
|
222
|
+
var emptyVoices = { voices: [], hasMore: false };
|
|
223
|
+
var emptySpeech = { audioBase64: "", contentType: "" };
|
|
224
|
+
var voiceIDPattern = /^[A-Za-z0-9_-]{1,128}$/;
|
|
225
|
+
var ListVoicesOperation = class {
|
|
226
|
+
/** Bind an authenticated client. */
|
|
227
|
+
constructor(client) {
|
|
228
|
+
this.client = client;
|
|
229
|
+
}
|
|
230
|
+
client;
|
|
231
|
+
/** Return the generated manifest definition. */
|
|
232
|
+
definition() {
|
|
233
|
+
return ListVoicesDefinition;
|
|
234
|
+
}
|
|
235
|
+
/** Validate and fetch one voice page. */
|
|
236
|
+
invoke(call, input) {
|
|
237
|
+
const pageSize = input.pageSize ?? 0;
|
|
238
|
+
const token = input.nextPageToken ?? "";
|
|
239
|
+
if (!Number.isSafeInteger(pageSize) || pageSize < 0 || pageSize > 100 || typeof token !== "string" || /[\r\n]/.test(token)) {
|
|
240
|
+
return Promise.resolve(newQueryBranch("defect", emptyVoices, {}, { kind: "VALIDATION", provider: "elevenlabs", operation: "listVoices", message: "page size or token is invalid" }));
|
|
241
|
+
}
|
|
242
|
+
const query = new URLSearchParams();
|
|
243
|
+
if (token) query.set("next_page_token", token);
|
|
244
|
+
if (pageSize > 0) query.set("page_size", String(pageSize));
|
|
245
|
+
return this.client.invokeQuery(call, "listVoices", "listed", "GET", "/v2/voices", query, void 0, emptyVoices, decodeVoices);
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
var CreateSpeechOperation = class {
|
|
249
|
+
/** Bind an authenticated client. */
|
|
250
|
+
constructor(client) {
|
|
251
|
+
this.client = client;
|
|
252
|
+
}
|
|
253
|
+
client;
|
|
254
|
+
/** Return the generated manifest definition. */
|
|
255
|
+
definition() {
|
|
256
|
+
return CreateSpeechDefinition;
|
|
257
|
+
}
|
|
258
|
+
/** Validate and synthesize one response. */
|
|
259
|
+
invoke(call, input) {
|
|
260
|
+
if (typeof input.voiceId !== "string" || !voiceIDPattern.test(input.voiceId) || typeof input.text !== "string" || !input.text.trim() || input.modelId !== void 0 && typeof input.modelId !== "string") {
|
|
261
|
+
return Promise.resolve(newQueryBranch("defect", emptySpeech, {}, { kind: "VALIDATION", provider: "elevenlabs", operation: "createSpeech", message: "voiceId and text are required" }));
|
|
262
|
+
}
|
|
263
|
+
const body = Buffer.from(JSON.stringify({ text: input.text, model_id: input.modelId || "eleven_multilingual_v2" }), "utf8");
|
|
264
|
+
return this.client.invokeQuery(call, "createSpeech", "created", "POST", `/v1/text-to-speech/${input.voiceId}`, new URLSearchParams({ output_format: "mp3_44100_128" }), body, emptySpeech, decodeSpeech);
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
function decodeVoices(body) {
|
|
268
|
+
const document = JSON.parse(Buffer.from(body).toString("utf8"));
|
|
269
|
+
if (!isObject(document) || !Array.isArray(document.voices)) throw new TypeError("voices missing");
|
|
270
|
+
const voices = document.voices.map((voice) => {
|
|
271
|
+
if (!isObject(voice) || typeof voice.voice_id !== "string" || !voice.voice_id || voice.name != null && typeof voice.name !== "string") throw new TypeError("voice invalid");
|
|
272
|
+
return { voiceId: voice.voice_id, name: voice.name ?? "" };
|
|
273
|
+
});
|
|
274
|
+
if (document.has_more != null && typeof document.has_more !== "boolean") throw new TypeError("has_more invalid");
|
|
275
|
+
if (document.next_page_token != null && typeof document.next_page_token !== "string") throw new TypeError("next_page_token invalid");
|
|
276
|
+
return { voices, hasMore: document.has_more ?? false, ...document.next_page_token ? { nextPageToken: document.next_page_token } : {} };
|
|
277
|
+
}
|
|
278
|
+
function decodeSpeech(body) {
|
|
279
|
+
if (!body.length) throw new TypeError("audio missing");
|
|
280
|
+
return { audioBase64: Buffer.from(body).toString("base64"), contentType: "audio/mpeg" };
|
|
281
|
+
}
|
|
282
|
+
function isObject(value) {
|
|
283
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
284
|
+
}
|
|
285
|
+
var ListModelsOperation = class {
|
|
286
|
+
/** Bind the provider client. */
|
|
287
|
+
constructor(client) {
|
|
288
|
+
this.client = client;
|
|
289
|
+
}
|
|
290
|
+
client;
|
|
291
|
+
/** Return the manifest Query contract. */
|
|
292
|
+
definition() {
|
|
293
|
+
return ListModelsDefinition;
|
|
294
|
+
}
|
|
295
|
+
/** Validate input and classify the provider response. */
|
|
296
|
+
async invoke(call, input) {
|
|
297
|
+
const operation = "listModels";
|
|
298
|
+
if (!isObject(input)) return queryDefect(operation, emptyModels, "model catalog input is invalid");
|
|
299
|
+
return this.client.invokeQuery(call, operation, "listed", "GET", "/v1/models", new URLSearchParams(), void 0, emptyModels, modelCatalog);
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
var ListHistoryItemsOperation = class {
|
|
303
|
+
/** Bind the provider client. */
|
|
304
|
+
constructor(client) {
|
|
305
|
+
this.client = client;
|
|
306
|
+
}
|
|
307
|
+
client;
|
|
308
|
+
/** Return the manifest Query contract. */
|
|
309
|
+
definition() {
|
|
310
|
+
return ListHistoryItemsDefinition;
|
|
311
|
+
}
|
|
312
|
+
/** Validate input and classify the provider response. */
|
|
313
|
+
async invoke(call, input) {
|
|
314
|
+
const operation = "listHistoryItems";
|
|
315
|
+
const { pageSize = 0, startAfterHistoryItemId = "", voiceId = "", modelId = "", source = "" } = input;
|
|
316
|
+
if (!Number.isSafeInteger(pageSize) || pageSize < 0 || pageSize > 1e3 || [startAfterHistoryItemId, voiceId, modelId].some((value) => value && !isVoiceID(value)) || modelId && !source || !["", "TTS", "STS", "Flows"].includes(source)) {
|
|
317
|
+
return queryDefect(operation, emptyHistoryPage, "history page filters are invalid");
|
|
318
|
+
}
|
|
319
|
+
const query = new URLSearchParams();
|
|
320
|
+
if (pageSize) query.set("page_size", String(pageSize));
|
|
321
|
+
if (startAfterHistoryItemId) query.set("start_after_history_item_id", startAfterHistoryItemId);
|
|
322
|
+
if (voiceId) query.set("voice_id", voiceId);
|
|
323
|
+
if (modelId) query.set("model_id", modelId);
|
|
324
|
+
if (source) query.set("source", source);
|
|
325
|
+
query.sort();
|
|
326
|
+
return this.client.invokeQuery(call, operation, "listed", "GET", "/v1/history", query, void 0, emptyHistoryPage, historyPage);
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
var GetHistoryItemOperation = class {
|
|
330
|
+
/** Bind the provider client. */
|
|
331
|
+
constructor(client) {
|
|
332
|
+
this.client = client;
|
|
333
|
+
}
|
|
334
|
+
client;
|
|
335
|
+
/** Return the manifest Query contract. */
|
|
336
|
+
definition() {
|
|
337
|
+
return GetHistoryItemDefinition;
|
|
338
|
+
}
|
|
339
|
+
/** Validate input and classify the provider response. */
|
|
340
|
+
async invoke(call, input) {
|
|
341
|
+
const operation = "getHistoryItem";
|
|
342
|
+
if (!isVoiceID(input.historyItemId)) return queryDefect(operation, emptyHistory, "history item ID is invalid");
|
|
343
|
+
return this.client.invokeQuery(call, operation, "found", "GET", `/v1/history/${input.historyItemId}`, new URLSearchParams(), void 0, emptyHistory, (bytes) => {
|
|
344
|
+
const item = historyMetadata(parseJSON(bytes));
|
|
345
|
+
if (item.historyItemId !== input.historyItemId) throw new TypeError("history identity differs");
|
|
346
|
+
return item;
|
|
347
|
+
}, true);
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
var DeleteHistoryItemOperation = class {
|
|
351
|
+
/** Bind the provider client. */
|
|
352
|
+
constructor(client) {
|
|
353
|
+
this.client = client;
|
|
354
|
+
}
|
|
355
|
+
client;
|
|
356
|
+
/** Return the manifest Mutation contract. */
|
|
357
|
+
definition() {
|
|
358
|
+
return DeleteHistoryItemDefinition;
|
|
359
|
+
}
|
|
360
|
+
/** Preserve one call identity across retries. */
|
|
361
|
+
idempotencyKey(callId) {
|
|
362
|
+
return callId;
|
|
363
|
+
}
|
|
364
|
+
/** Validate input and classify the provider response. */
|
|
365
|
+
async invoke(call, input) {
|
|
366
|
+
const operation = "deleteHistoryItem";
|
|
367
|
+
if (!isVoiceID(input.historyItemId)) return mutationDefect(operation, emptyDeletion, "history item ID is invalid");
|
|
368
|
+
return this.client[elevenLabsWrite](
|
|
369
|
+
call,
|
|
370
|
+
operation,
|
|
371
|
+
"deleted",
|
|
372
|
+
{ method: "DELETE", path: `/v1/history/${input.historyItemId}`, absentIsSuccess: true },
|
|
373
|
+
emptyDeletion,
|
|
374
|
+
{ historyItemId: input.historyItemId, deleted: true }
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
var GetVoiceOperation = class {
|
|
379
|
+
/** Bind the provider client. */
|
|
380
|
+
constructor(client) {
|
|
381
|
+
this.client = client;
|
|
382
|
+
}
|
|
383
|
+
client;
|
|
384
|
+
/** Return the manifest Query contract. */
|
|
385
|
+
definition() {
|
|
386
|
+
return GetVoiceDefinition;
|
|
387
|
+
}
|
|
388
|
+
/** Validate input and classify the provider response. */
|
|
389
|
+
async invoke(call, input) {
|
|
390
|
+
const operation = "getVoice";
|
|
391
|
+
if (!isVoiceID(input.voiceId)) return queryDefect(operation, emptyVoice, "voiceId is invalid");
|
|
392
|
+
return this.client.invokeQuery(
|
|
393
|
+
call,
|
|
394
|
+
operation,
|
|
395
|
+
"found",
|
|
396
|
+
"GET",
|
|
397
|
+
`/v1/voices/${input.voiceId}`,
|
|
398
|
+
new URLSearchParams(),
|
|
399
|
+
void 0,
|
|
400
|
+
emptyVoice,
|
|
401
|
+
(bytes) => {
|
|
402
|
+
const voice = asObject(parseJSON(bytes));
|
|
403
|
+
const voiceId = readString(field(voice, "voice_id")), name = readString(field(voice, "name"));
|
|
404
|
+
if (!isVoiceID(voiceId) || !name) throw new TypeError("voice identity missing");
|
|
405
|
+
return { voiceId, name };
|
|
406
|
+
},
|
|
407
|
+
true
|
|
408
|
+
);
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
var EditVoiceMetadataOperation = class {
|
|
412
|
+
/** Bind the provider client. */
|
|
413
|
+
constructor(client) {
|
|
414
|
+
this.client = client;
|
|
415
|
+
}
|
|
416
|
+
client;
|
|
417
|
+
/** Return the manifest Mutation contract. */
|
|
418
|
+
definition() {
|
|
419
|
+
return EditVoiceMetadataDefinition;
|
|
420
|
+
}
|
|
421
|
+
/** Preserve one call identity across retries. */
|
|
422
|
+
idempotencyKey(callId) {
|
|
423
|
+
return callId;
|
|
424
|
+
}
|
|
425
|
+
/** Validate input and classify the provider response. */
|
|
426
|
+
async invoke(call, input) {
|
|
427
|
+
const operation = "editVoiceMetadata";
|
|
428
|
+
const description = input.description ?? "";
|
|
429
|
+
if (!isVoiceID(input.voiceId) || !input.name.trim() || !isDisplayText(input.name, 256) || !isDisplayText(description, 1e3)) {
|
|
430
|
+
return mutationDefect(operation, emptyEdit, "voice ID, name, or description is invalid");
|
|
431
|
+
}
|
|
432
|
+
const fields = new FormData();
|
|
433
|
+
fields.set("name", input.name);
|
|
434
|
+
if (description) fields.set("description", description);
|
|
435
|
+
const multipart = new Response(fields);
|
|
436
|
+
const contentType = multipart.headers.get("Content-Type");
|
|
437
|
+
if (!contentType) return newMutationBranch("defect", emptyEdit, {}, validationFailure(operation, "LOCAL_DEFECT", "voice edit body could not be built"));
|
|
438
|
+
return this.client[elevenLabsWrite](call, operation, "edited", {
|
|
439
|
+
method: "POST",
|
|
440
|
+
path: `/v1/voices/${input.voiceId}/edit`,
|
|
441
|
+
body: new Uint8Array(await multipart.arrayBuffer()),
|
|
442
|
+
contentType
|
|
443
|
+
}, emptyEdit, { voiceId: input.voiceId, name: input.name });
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
var DeleteVoiceOperation = class {
|
|
447
|
+
/** Bind the provider client. */
|
|
448
|
+
constructor(client) {
|
|
449
|
+
this.client = client;
|
|
450
|
+
}
|
|
451
|
+
client;
|
|
452
|
+
/** Return the manifest Mutation contract. */
|
|
453
|
+
definition() {
|
|
454
|
+
return DeleteVoiceDefinition;
|
|
455
|
+
}
|
|
456
|
+
/** Preserve one call identity across retries. */
|
|
457
|
+
idempotencyKey(callId) {
|
|
458
|
+
return callId;
|
|
459
|
+
}
|
|
460
|
+
/** Validate input and classify the provider response. */
|
|
461
|
+
async invoke(call, input) {
|
|
462
|
+
const operation = "deleteVoice";
|
|
463
|
+
if (!isVoiceID(input.voiceId)) return mutationDefect(operation, emptyVoiceDeletion, "voice ID is invalid");
|
|
464
|
+
return this.client[elevenLabsWrite](
|
|
465
|
+
call,
|
|
466
|
+
operation,
|
|
467
|
+
"deleted",
|
|
468
|
+
{ method: "DELETE", path: `/v1/voices/${input.voiceId}`, absentIsSuccess: true },
|
|
469
|
+
emptyVoiceDeletion,
|
|
470
|
+
{ voiceId: input.voiceId, deleted: true }
|
|
471
|
+
);
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
var UpdateVoiceSettingsOperation = class {
|
|
475
|
+
/** Bind the provider client. */
|
|
476
|
+
constructor(client) {
|
|
477
|
+
this.client = client;
|
|
478
|
+
}
|
|
479
|
+
client;
|
|
480
|
+
/** Return the manifest Mutation contract. */
|
|
481
|
+
definition() {
|
|
482
|
+
return UpdateVoiceSettingsDefinition;
|
|
483
|
+
}
|
|
484
|
+
/** Preserve one call identity across retries. */
|
|
485
|
+
idempotencyKey(callId) {
|
|
486
|
+
return callId;
|
|
487
|
+
}
|
|
488
|
+
/** Validate input and classify the provider response. */
|
|
489
|
+
async invoke(call, input) {
|
|
490
|
+
const operation = "updateVoiceSettings";
|
|
491
|
+
if (!isVoiceID(input.voiceId) || !Number.isFinite(input.speed) || input.speed <= 0 || ![input.stability, input.similarityBoost, input.style].every((value) => value >= 0 && value <= 1)) {
|
|
492
|
+
return mutationDefect(operation, emptySettings, "voice ID or settings are invalid");
|
|
493
|
+
}
|
|
494
|
+
const body = Buffer.from(JSON.stringify({
|
|
495
|
+
stability: input.stability,
|
|
496
|
+
similarity_boost: input.similarityBoost,
|
|
497
|
+
style: input.style,
|
|
498
|
+
speed: input.speed,
|
|
499
|
+
use_speaker_boost: input.useSpeakerBoost
|
|
500
|
+
}));
|
|
501
|
+
return this.client[elevenLabsWrite](call, operation, "updated", {
|
|
502
|
+
method: "POST",
|
|
503
|
+
path: `/v1/voices/${input.voiceId}/settings/edit`,
|
|
504
|
+
body
|
|
505
|
+
}, emptySettings, { voiceId: input.voiceId });
|
|
506
|
+
}
|
|
507
|
+
};
|
|
508
|
+
var emptyModels = { models: [] };
|
|
509
|
+
var emptyHistoryPage = { items: [], hasMore: false };
|
|
510
|
+
var emptyHistory = { historyItemId: "", dateUnix: 0, contentType: "" };
|
|
511
|
+
var emptyDeletion = { historyItemId: "", deleted: false };
|
|
512
|
+
var emptyVoice = { voiceId: "", name: "" };
|
|
513
|
+
var emptyEdit = { voiceId: "", name: "" };
|
|
514
|
+
var emptyVoiceDeletion = { voiceId: "", deleted: false };
|
|
515
|
+
var emptySettings = { voiceId: "" };
|
|
516
|
+
function isVoiceID(value) {
|
|
517
|
+
return voiceIDPattern.exec(value)?.[0] === value;
|
|
518
|
+
}
|
|
519
|
+
function isDisplayText(value, limit) {
|
|
520
|
+
return ![...value].some((character) => {
|
|
521
|
+
const point = character.charCodeAt(0);
|
|
522
|
+
return point < 32 || point >= 127 && point <= 159;
|
|
523
|
+
}) && !/[\uD800-\uDFFF]/u.test(value) && Buffer.byteLength(value) <= limit;
|
|
524
|
+
}
|
|
525
|
+
function modelCatalog(body) {
|
|
526
|
+
const list = parseJSON(body);
|
|
527
|
+
if (!Array.isArray(list)) throw new TypeError("model catalog missing");
|
|
528
|
+
return { models: list.map((row) => {
|
|
529
|
+
const document = asObject(row);
|
|
530
|
+
const modelId = readString(field(document, "model_id"));
|
|
531
|
+
const maximumTextLengthPerRequest = readInteger(field(document, "maximum_text_length_per_request"));
|
|
532
|
+
const supported = field(document, "can_do_text_to_speech");
|
|
533
|
+
if (!isVoiceID(modelId) || maximumTextLengthPerRequest < 0 || supported != null && typeof supported !== "boolean") {
|
|
534
|
+
throw new TypeError("model metadata invalid");
|
|
535
|
+
}
|
|
536
|
+
return { modelId, name: readString(field(document, "name")), maximumTextLengthPerRequest, canDoTextToSpeech: supported ?? false };
|
|
537
|
+
}) };
|
|
538
|
+
}
|
|
539
|
+
function historyMetadata(value) {
|
|
540
|
+
const document = asObject(value);
|
|
541
|
+
const historyItemId = readString(field(document, "history_item_id"));
|
|
542
|
+
const dateUnix = readInteger(field(document, "date_unix"));
|
|
543
|
+
const voiceId = readString(field(document, "voice_id"));
|
|
544
|
+
const modelId = readString(field(document, "model_id"));
|
|
545
|
+
const contentType = readString(field(document, "content_type"));
|
|
546
|
+
const source = readString(field(document, "source"));
|
|
547
|
+
if (!isVoiceID(historyItemId) || dateUnix <= 0 || !contentType.trim() || voiceId && !isVoiceID(voiceId) || modelId && !isVoiceID(modelId)) throw new TypeError("history metadata invalid");
|
|
548
|
+
return { historyItemId, dateUnix, contentType, ...voiceId ? { voiceId } : {}, ...modelId ? { modelId } : {}, ...source ? { source } : {} };
|
|
549
|
+
}
|
|
550
|
+
function historyPage(body) {
|
|
551
|
+
const document = asObject(parseJSON(body));
|
|
552
|
+
const history = field(document, "history"), hasMore = field(document, "has_more");
|
|
553
|
+
const lastHistoryItemId = readString(field(document, "last_history_item_id"));
|
|
554
|
+
if (!Array.isArray(history) || typeof hasMore !== "boolean" || hasMore && !isVoiceID(lastHistoryItemId)) {
|
|
555
|
+
throw new TypeError("history page invalid");
|
|
556
|
+
}
|
|
557
|
+
return { items: history.map(historyMetadata), hasMore, ...lastHistoryItemId ? { lastHistoryItemId } : {} };
|
|
558
|
+
}
|
|
559
|
+
function parseJSON(body) {
|
|
560
|
+
return JSON.parse(Buffer.from(body).toString("utf8"), (key, value, context) => {
|
|
561
|
+
if (["date_unix", "maximum_text_length_per_request"].includes(key.toLowerCase()) && typeof value === "number" && context?.source && !/^-?[0-9]+$/u.test(context.source)) return Number.NaN;
|
|
562
|
+
return value;
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
function asObject(value) {
|
|
566
|
+
if (!isObject(value)) throw new TypeError("ElevenLabs response object missing");
|
|
567
|
+
return value;
|
|
568
|
+
}
|
|
569
|
+
function field(document, name) {
|
|
570
|
+
const key = Object.keys(document).reverse().find((candidate) => candidate.toLowerCase() === name);
|
|
571
|
+
return key === void 0 ? void 0 : document[key];
|
|
572
|
+
}
|
|
573
|
+
function readString(value) {
|
|
574
|
+
if (value == null) return "";
|
|
575
|
+
if (typeof value !== "string") throw new TypeError("ElevenLabs response string invalid");
|
|
576
|
+
return value;
|
|
577
|
+
}
|
|
578
|
+
function readInteger(value) {
|
|
579
|
+
if (value == null) return 0;
|
|
580
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value)) throw new TypeError("ElevenLabs response integer invalid");
|
|
581
|
+
return value;
|
|
582
|
+
}
|
|
583
|
+
function queryDefect(operation, value, message) {
|
|
584
|
+
return newQueryBranch("defect", value, {}, validationFailure(operation, "VALIDATION", message));
|
|
585
|
+
}
|
|
586
|
+
function mutationDefect(operation, value, message) {
|
|
587
|
+
return newMutationBranch("defect", value, {}, validationFailure(operation, "VALIDATION", message));
|
|
588
|
+
}
|
|
589
|
+
function validationFailure(operation, kind, message) {
|
|
590
|
+
return { kind, provider: "elevenlabs", operation, message };
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
// src/client.ts
|
|
594
|
+
var elevenLabsWrite = /* @__PURE__ */ Symbol("ElevenLabs write dispatch");
|
|
595
|
+
var ElevenLabsClient = class {
|
|
596
|
+
baseUrl;
|
|
597
|
+
timeoutMs;
|
|
598
|
+
maxResponseBytes;
|
|
599
|
+
credentials;
|
|
600
|
+
send;
|
|
601
|
+
now;
|
|
602
|
+
/** Validate settings without contacting the provider. */
|
|
603
|
+
constructor(config, credentials, options = {}) {
|
|
604
|
+
if (!credentials) throw new TypeError("ElevenLabs credential source is required");
|
|
605
|
+
this.baseUrl = validateBaseURL(config.baseUrl || "https://api.elevenlabs.io");
|
|
606
|
+
this.timeoutMs = config.timeoutMs || 12e4;
|
|
607
|
+
this.maxResponseBytes = config.maxResponseBytes || 2097152;
|
|
608
|
+
if (!Number.isSafeInteger(this.timeoutMs) || this.timeoutMs < 0) throw new TypeError("ElevenLabs timeout must be nonnegative");
|
|
609
|
+
if (!Number.isSafeInteger(this.maxResponseBytes) || this.maxResponseBytes < 0) throw new TypeError("ElevenLabs response limit must be nonnegative");
|
|
610
|
+
this.credentials = credentials;
|
|
611
|
+
this.send = options.send ?? sendProviderRequest;
|
|
612
|
+
this.now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
613
|
+
}
|
|
614
|
+
/** Bind the voice-list query. */
|
|
615
|
+
listVoices() {
|
|
616
|
+
return new ListVoicesOperation(this);
|
|
617
|
+
}
|
|
618
|
+
/** Bind the speech-generation query. */
|
|
619
|
+
createSpeech() {
|
|
620
|
+
return new CreateSpeechOperation(this);
|
|
621
|
+
}
|
|
622
|
+
/** List available ElevenLabs speech models and input limits. */
|
|
623
|
+
listModels() {
|
|
624
|
+
return new ListModelsOperation(this);
|
|
625
|
+
}
|
|
626
|
+
/** List operational metadata for generated history items. */
|
|
627
|
+
listHistoryItems() {
|
|
628
|
+
return new ListHistoryItemsOperation(this);
|
|
629
|
+
}
|
|
630
|
+
/** Read one history item's operational metadata. */
|
|
631
|
+
getHistoryItem() {
|
|
632
|
+
return new GetHistoryItemOperation(this);
|
|
633
|
+
}
|
|
634
|
+
/** Permanently delete one generated history item. */
|
|
635
|
+
deleteHistoryItem() {
|
|
636
|
+
return new DeleteHistoryItemOperation(this);
|
|
637
|
+
}
|
|
638
|
+
/** Read one ElevenLabs voice ID and name. */
|
|
639
|
+
getVoice() {
|
|
640
|
+
return new GetVoiceOperation(this);
|
|
641
|
+
}
|
|
642
|
+
/** Replace a voice name and optionally its description. */
|
|
643
|
+
editVoiceMetadata() {
|
|
644
|
+
return new EditVoiceMetadataOperation(this);
|
|
645
|
+
}
|
|
646
|
+
/** Permanently delete one ElevenLabs voice. */
|
|
647
|
+
deleteVoice() {
|
|
648
|
+
return new DeleteVoiceOperation(this);
|
|
649
|
+
}
|
|
650
|
+
/** Replace the five generation settings for one voice. */
|
|
651
|
+
updateVoiceSettings() {
|
|
652
|
+
return new UpdateVoiceSettingsOperation(this);
|
|
653
|
+
}
|
|
654
|
+
/** Send one request and classify its status before decoding its body. */
|
|
655
|
+
async invokeQuery(call, operation, success, method, path, query, body, empty, decode, hasNotFoundBranch = false) {
|
|
656
|
+
const response = await this.exchange(call, method, path, query, body);
|
|
657
|
+
if (response.error === "credential") return failed(operation, "defect", empty, "AUTHENTICATION", "connection credentials are unavailable or invalid");
|
|
658
|
+
if (response.error === "request") return newQueryRetry(failure(operation, "AVAILABILITY", "provider request failed"));
|
|
659
|
+
const transient = transientStatus(response.status);
|
|
660
|
+
if (transient) return newQueryRetry(failure(operation, ...transient), response.retryAfterMs);
|
|
661
|
+
if (response.status === 404 && hasNotFoundBranch) return failed(operation, "notFound", empty, "NOT_FOUND", "provider did not find the resource");
|
|
662
|
+
if (response.status !== 200) return failed(operation, "providerRejected", empty, "PROVIDER_REJECTION", `provider rejected the request with HTTP ${response.status}`);
|
|
663
|
+
if (response.error === "tooLarge") return failed(operation, "invalidResponse", empty, "RESPONSE_TOO_LARGE", "provider response exceeded the configured limit");
|
|
664
|
+
if (response.error) return newQueryRetry(failure(operation, "AVAILABILITY", "provider response was interrupted"));
|
|
665
|
+
try {
|
|
666
|
+
return newQueryBranch2(success, decode(response.body), {});
|
|
667
|
+
} catch {
|
|
668
|
+
return failed(operation, "invalidResponse", empty, "PROTOCOL", "provider returned an invalid response");
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
async [elevenLabsWrite](call, operation, branch, request, empty, value) {
|
|
672
|
+
const response = await this.exchange(call, request.method, request.path, new URLSearchParams(), request.body, request.contentType);
|
|
673
|
+
const transportKind = operation === "updateVoiceSettings" ? "AVAILABILITY" : "TRANSPORT";
|
|
674
|
+
if (response.error === "credential") return failedWrite(operation, "defect", empty, "AUTHENTICATION", "connection credentials are unavailable or invalid");
|
|
675
|
+
if (response.error === "request") return newMutationRetry(failure(operation, transportKind, "provider request failed"));
|
|
676
|
+
const transient = transientStatus(response.status);
|
|
677
|
+
if (transient) return newMutationRetry(failure(operation, ...transient), response.retryAfterMs);
|
|
678
|
+
if (response.status === 404 && request.absentIsSuccess) return newMutationBranch2(branch, value);
|
|
679
|
+
if (response.status !== 200) {
|
|
680
|
+
if (isDefiniteRefusal(response)) {
|
|
681
|
+
if (response.status === 404) return failedWrite(operation, "notFound", empty, "NOT_FOUND", "provider did not find the voice");
|
|
682
|
+
return failedWrite(operation, "providerRejected", empty, "PROVIDER_REJECTION", `ElevenLabs rejected HTTP ${response.status}`);
|
|
683
|
+
}
|
|
684
|
+
return newMutationRetry(failure(operation, "AVAILABILITY", "provider write outcome is unknown"), response.retryAfterMs);
|
|
685
|
+
}
|
|
686
|
+
const confirmationDelay = operation === "updateVoiceSettings" ? 0 : response.retryAfterMs;
|
|
687
|
+
if (response.error === "tooLarge") return newMutationRetry(failure(operation, "RESPONSE_TOO_LARGE", "provider confirmation exceeded the configured limit"), confirmationDelay);
|
|
688
|
+
if (response.error) return newMutationRetry(failure(operation, transportKind, "provider response was interrupted"));
|
|
689
|
+
try {
|
|
690
|
+
if (field2(parseObject(response.body), "status") !== "ok") throw new TypeError("provider confirmation missing");
|
|
691
|
+
} catch {
|
|
692
|
+
return newMutationRetry(failure(operation, "PROTOCOL", "provider confirmation was unusable"), confirmationDelay);
|
|
693
|
+
}
|
|
694
|
+
return newMutationBranch2(branch, value);
|
|
695
|
+
}
|
|
696
|
+
async exchange(call, method, path, query, body, contentType = "application/json") {
|
|
697
|
+
let key;
|
|
698
|
+
try {
|
|
699
|
+
const resolved = await this.credentials.resolve(call, call.context.cancellationSignal);
|
|
700
|
+
if (!(resolved.apiKey instanceof SecretString)) throw new TypeError("API key is invalid");
|
|
701
|
+
key = resolved.apiKey.reveal();
|
|
702
|
+
if (!isHeaderSafeCredential(key)) throw new TypeError("API key is invalid");
|
|
703
|
+
} catch {
|
|
704
|
+
return { status: 0, body: new Uint8Array(), retryAfterMs: 0, error: "credential" };
|
|
705
|
+
}
|
|
706
|
+
const encodedQuery = query.toString();
|
|
707
|
+
const request = {
|
|
708
|
+
url: `${this.baseUrl}${path}${encodedQuery ? `?${encodedQuery}` : ""}`,
|
|
709
|
+
method,
|
|
710
|
+
headers: { "xi-api-key": key, Accept: path.startsWith("/v1/text-to-speech/") ? "audio/mpeg" : "application/json", ...body ? { "Content-Type": contentType } : {} },
|
|
711
|
+
...body ? { body } : {},
|
|
712
|
+
maxResponseBytes: this.maxResponseBytes,
|
|
713
|
+
addressPolicy: this.baseUrl.startsWith("http://") ? "privateNetworkHTTP" : "publicHTTPS",
|
|
714
|
+
timeoutMs: this.timeoutMs,
|
|
715
|
+
signal: call.context.cancellationSignal
|
|
716
|
+
};
|
|
717
|
+
try {
|
|
718
|
+
const response = await this.send(request);
|
|
719
|
+
const retryAfterMs = parseRetryAfter(header(response, "retry-after"), this.now());
|
|
720
|
+
if (response.body.length > this.maxResponseBytes) {
|
|
721
|
+
return { status: response.status, body: new Uint8Array(), retryAfterMs, error: "tooLarge" };
|
|
722
|
+
}
|
|
723
|
+
return { status: response.status, body: response.body, retryAfterMs };
|
|
724
|
+
} catch (error) {
|
|
725
|
+
if ((error instanceof BodyTooLargeError || error instanceof ProviderTransportError) && error.status !== void 0) {
|
|
726
|
+
return {
|
|
727
|
+
status: error.status,
|
|
728
|
+
body: new Uint8Array(),
|
|
729
|
+
retryAfterMs: parseRetryAfter(header({ headers: error.headers ?? {} }, "retry-after"), this.now()),
|
|
730
|
+
error: error instanceof BodyTooLargeError ? "tooLarge" : "interrupted"
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
return { status: 0, body: new Uint8Array(), retryAfterMs: 0, error: "request" };
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
};
|
|
737
|
+
function header(response, name) {
|
|
738
|
+
const value = Object.entries(response.headers).find(([key]) => key.toLowerCase() === name)?.[1];
|
|
739
|
+
return Array.isArray(value) ? value[0] ?? "" : value ?? "";
|
|
740
|
+
}
|
|
741
|
+
function failure(operation, kind, message) {
|
|
742
|
+
return { kind, provider: "elevenlabs", operation, message };
|
|
743
|
+
}
|
|
744
|
+
function failed(operation, branch, empty, kind, message) {
|
|
745
|
+
return newQueryBranch2(branch, empty, {}, failure(operation, kind, message));
|
|
746
|
+
}
|
|
747
|
+
function failedWrite(operation, branch, empty, kind, message) {
|
|
748
|
+
return newMutationBranch2(branch, empty, {}, failure(operation, kind, message));
|
|
749
|
+
}
|
|
750
|
+
function transientStatus(status) {
|
|
751
|
+
if (status === 429) return ["RATE_LIMIT", "provider rate limited the request"];
|
|
752
|
+
if (status === 408 || status >= 500) return ["AVAILABILITY", "provider is temporarily unavailable"];
|
|
753
|
+
return void 0;
|
|
754
|
+
}
|
|
755
|
+
var refusalStatuses = /* @__PURE__ */ new Set([400, 401, 403, 404, 411, 413, 414, 415, 422]);
|
|
756
|
+
function isDefiniteRefusal(response) {
|
|
757
|
+
if (response.error || !refusalStatuses.has(response.status)) return false;
|
|
758
|
+
try {
|
|
759
|
+
const document = parseObject(response.body);
|
|
760
|
+
const status = field2(document, "status");
|
|
761
|
+
if (status === "ok" || status != null && typeof status !== "string") return false;
|
|
762
|
+
const detail = field2(document, "detail");
|
|
763
|
+
if (typeof detail === "string") return !!detail.trim();
|
|
764
|
+
if (!isObject2(detail)) return false;
|
|
765
|
+
const detailStatus = field2(detail, "status"), message = field2(detail, "message");
|
|
766
|
+
return typeof detailStatus === "string" && !!detailStatus && typeof message === "string" && !!message;
|
|
767
|
+
} catch {
|
|
768
|
+
return false;
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
function parseObject(bytes) {
|
|
772
|
+
const value = JSON.parse(Buffer.from(bytes).toString("utf8"));
|
|
773
|
+
if (!isObject2(value)) throw new TypeError("ElevenLabs response object missing");
|
|
774
|
+
return value;
|
|
775
|
+
}
|
|
776
|
+
function isObject2(value) {
|
|
777
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
778
|
+
}
|
|
779
|
+
function field2(document, name) {
|
|
780
|
+
const key = Object.keys(document).reverse().find((candidate) => candidate.toLowerCase() === name);
|
|
781
|
+
return key === void 0 ? void 0 : document[key];
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
// src/project.ts
|
|
785
|
+
function newProjectConnection2(project, connectionName) {
|
|
786
|
+
return newProjectConnection(project, connectionName, (loadedProject, name) => {
|
|
787
|
+
const selected = loadedProject.configuration.connections.find((entry) => entry.connectorId === "elevenlabs" && entry.connectionName === name);
|
|
788
|
+
if (!selected) throw new TypeError("ElevenLabs project connection is not configured");
|
|
789
|
+
const config = ConfigSchema.parse(selected.configuration);
|
|
790
|
+
const credentials = {
|
|
791
|
+
async resolve(_call, signal) {
|
|
792
|
+
const fields = await loadedProject.resolveCredential("elevenlabs", name, signal);
|
|
793
|
+
const decoded = z.object({ api_key: z.string().min(1) }).parse(fields);
|
|
794
|
+
return { apiKey: new SecretString2(decoded.api_key) };
|
|
795
|
+
}
|
|
796
|
+
};
|
|
797
|
+
return new ElevenLabsClient(config, credentials);
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
export {
|
|
801
|
+
ConfigSchema,
|
|
802
|
+
Connection,
|
|
803
|
+
ConnectorID,
|
|
804
|
+
CreateSpeechBranch,
|
|
805
|
+
CreateSpeechBranchCreated,
|
|
806
|
+
CreateSpeechBranchDefect,
|
|
807
|
+
CreateSpeechBranchInvalidResponse,
|
|
808
|
+
CreateSpeechBranchProviderRejected,
|
|
809
|
+
CreateSpeechDefinition,
|
|
810
|
+
CreateSpeechInputSchema,
|
|
811
|
+
CreateSpeechMetadata,
|
|
812
|
+
CreateSpeechOperation,
|
|
813
|
+
CreateSpeechOutputSchema,
|
|
814
|
+
CredentialMaterialError,
|
|
815
|
+
DeleteHistoryItemBranch,
|
|
816
|
+
DeleteHistoryItemBranchDefect,
|
|
817
|
+
DeleteHistoryItemBranchDeleted,
|
|
818
|
+
DeleteHistoryItemBranchInvalidResponse,
|
|
819
|
+
DeleteHistoryItemBranchProviderRejected,
|
|
820
|
+
DeleteHistoryItemDefinition,
|
|
821
|
+
DeleteHistoryItemMetadata,
|
|
822
|
+
DeleteHistoryItemOperation,
|
|
823
|
+
DeleteVoiceBranch,
|
|
824
|
+
DeleteVoiceBranchDefect,
|
|
825
|
+
DeleteVoiceBranchDeleted,
|
|
826
|
+
DeleteVoiceBranchInvalidResponse,
|
|
827
|
+
DeleteVoiceBranchProviderRejected,
|
|
828
|
+
DeleteVoiceDefinition,
|
|
829
|
+
DeleteVoiceMetadata,
|
|
830
|
+
DeleteVoiceOperation,
|
|
831
|
+
DeletedHistoryItemSchema,
|
|
832
|
+
DeletedVoiceSchema,
|
|
833
|
+
EditVoiceMetadataBranch,
|
|
834
|
+
EditVoiceMetadataBranchDefect,
|
|
835
|
+
EditVoiceMetadataBranchEdited,
|
|
836
|
+
EditVoiceMetadataBranchInvalidResponse,
|
|
837
|
+
EditVoiceMetadataBranchNotFound,
|
|
838
|
+
EditVoiceMetadataBranchProviderRejected,
|
|
839
|
+
EditVoiceMetadataDefinition,
|
|
840
|
+
EditVoiceMetadataInputSchema,
|
|
841
|
+
EditVoiceMetadataMetadata,
|
|
842
|
+
EditVoiceMetadataOperation,
|
|
843
|
+
EditedVoiceMetadataSchema,
|
|
844
|
+
ElevenLabsClient,
|
|
845
|
+
GetHistoryItemBranch,
|
|
846
|
+
GetHistoryItemBranchDefect,
|
|
847
|
+
GetHistoryItemBranchFound,
|
|
848
|
+
GetHistoryItemBranchInvalidResponse,
|
|
849
|
+
GetHistoryItemBranchNotFound,
|
|
850
|
+
GetHistoryItemBranchProviderRejected,
|
|
851
|
+
GetHistoryItemDefinition,
|
|
852
|
+
GetHistoryItemMetadata,
|
|
853
|
+
GetHistoryItemOperation,
|
|
854
|
+
GetVoiceBranch,
|
|
855
|
+
GetVoiceBranchDefect,
|
|
856
|
+
GetVoiceBranchFound,
|
|
857
|
+
GetVoiceBranchInvalidResponse,
|
|
858
|
+
GetVoiceBranchNotFound,
|
|
859
|
+
GetVoiceBranchProviderRejected,
|
|
860
|
+
GetVoiceDefinition,
|
|
861
|
+
GetVoiceInputSchema,
|
|
862
|
+
GetVoiceMetadata,
|
|
863
|
+
GetVoiceOperation,
|
|
864
|
+
HistoryItemIdentityInputSchema,
|
|
865
|
+
HistoryItemMetadataSchema,
|
|
866
|
+
HistoryItemsPageSchema,
|
|
867
|
+
ListHistoryItemsBranch,
|
|
868
|
+
ListHistoryItemsBranchDefect,
|
|
869
|
+
ListHistoryItemsBranchInvalidResponse,
|
|
870
|
+
ListHistoryItemsBranchListed,
|
|
871
|
+
ListHistoryItemsBranchProviderRejected,
|
|
872
|
+
ListHistoryItemsDefinition,
|
|
873
|
+
ListHistoryItemsInputSchema,
|
|
874
|
+
ListHistoryItemsMetadata,
|
|
875
|
+
ListHistoryItemsOperation,
|
|
876
|
+
ListModelsBranch,
|
|
877
|
+
ListModelsBranchDefect,
|
|
878
|
+
ListModelsBranchInvalidResponse,
|
|
879
|
+
ListModelsBranchListed,
|
|
880
|
+
ListModelsBranchProviderRejected,
|
|
881
|
+
ListModelsDefinition,
|
|
882
|
+
ListModelsInputSchema,
|
|
883
|
+
ListModelsMetadata,
|
|
884
|
+
ListModelsOperation,
|
|
885
|
+
ListVoicesBranch,
|
|
886
|
+
ListVoicesBranchDefect,
|
|
887
|
+
ListVoicesBranchInvalidResponse,
|
|
888
|
+
ListVoicesBranchListed,
|
|
889
|
+
ListVoicesBranchProviderRejected,
|
|
890
|
+
ListVoicesDefinition,
|
|
891
|
+
ListVoicesInputSchema,
|
|
892
|
+
ListVoicesMetadata,
|
|
893
|
+
ListVoicesOperation,
|
|
894
|
+
ListVoicesOutputSchema,
|
|
895
|
+
ModelMetadataSchema,
|
|
896
|
+
ModelsListSchema,
|
|
897
|
+
ProviderID,
|
|
898
|
+
UpdateVoiceSettingsBranch,
|
|
899
|
+
UpdateVoiceSettingsBranchDefect,
|
|
900
|
+
UpdateVoiceSettingsBranchNotFound,
|
|
901
|
+
UpdateVoiceSettingsBranchProviderRejected,
|
|
902
|
+
UpdateVoiceSettingsBranchUpdated,
|
|
903
|
+
UpdateVoiceSettingsDefinition,
|
|
904
|
+
UpdateVoiceSettingsInputSchema,
|
|
905
|
+
UpdateVoiceSettingsMetadata,
|
|
906
|
+
UpdateVoiceSettingsOperation,
|
|
907
|
+
UpdatedVoiceSettingsSchema,
|
|
908
|
+
VoiceSchema,
|
|
909
|
+
decodeCredentials,
|
|
910
|
+
isCredentialMaterialError,
|
|
911
|
+
newConnection,
|
|
912
|
+
newConnectionWithOperations,
|
|
913
|
+
newCreateSpeechStep,
|
|
914
|
+
newDeleteHistoryItemStep,
|
|
915
|
+
newDeleteVoiceStep,
|
|
916
|
+
newEditVoiceMetadataStep,
|
|
917
|
+
newGetHistoryItemStep,
|
|
918
|
+
newGetVoiceStep,
|
|
919
|
+
newListHistoryItemsStep,
|
|
920
|
+
newListModelsStep,
|
|
921
|
+
newListVoicesStep,
|
|
922
|
+
newProjectConnection2 as newProjectConnection,
|
|
923
|
+
newUpdateVoiceSettingsStep
|
|
924
|
+
};
|