@superdurable/connector-elevenlabs 0.0.0-stage → 0.1.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 +23 -2
- package/dex-connector.json +77 -0
- package/dist/chunk-GIQKY62E.js +134 -0
- package/dist/connection-DFnhV-HC.d.ts +117 -0
- package/dist/index.d.ts +147 -0
- package/dist/index.js +259 -0
- package/dist/mock.d.ts +54 -0
- package/dist/mock.js +120 -0
- package/package.json +61 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Super Durable
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ElevenLabs TypeScript connector
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@superdurable/connector-elevenlabs` provides two Dex Query operations:
|
|
4
|
+
`listVoices` and `createSpeech`. The manifest generates the public models,
|
|
5
|
+
operation definitions, Step factories, connection bindings, and scripted mocks.
|
|
6
|
+
The provider client resolves the API key for each attempt and never puts it in
|
|
7
|
+
Flow input or results.
|
|
8
|
+
|
|
9
|
+
The [runnable demo](examples/demo/README.md) shows the complete Step and Flow
|
|
10
|
+
wiring. `listVoices` returns a bounded voice page. `createSpeech` returns
|
|
11
|
+
base64 MP3 data; it uses a three-attempt retry budget because generation may
|
|
12
|
+
be billed again. Both operations retry transport failures, 408, 429, and 5xx.
|
|
13
|
+
Other HTTP rejections select `providerRejected`, malformed or oversized 200
|
|
14
|
+
responses select `invalidResponse`, and invalid local input or credentials
|
|
15
|
+
select `defect`. Unwired optional branches fail the Flow.
|
|
16
|
+
|
|
17
|
+
Run `npm ci && npm run check` to verify types, lint, conformance replay, unit
|
|
18
|
+
tests, and the package build. With `dexcli dev` running, set
|
|
19
|
+
`DEX_FLOW_SERVICE_ADDRESS` and run `npm run test:integration` for a real Worker
|
|
20
|
+
and Client test against a local provider fixture. The checked-in Go conformance
|
|
21
|
+
recording supplies exact request and output parity for both operations.
|
|
22
|
+
|
|
23
|
+
The real ElevenLabs voice catalog, model access, audio format, billing, and
|
|
24
|
+
Dex Web Connections form have not been verified with a live provider key.
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"connectorId": "elevenlabs",
|
|
3
|
+
"releaseTag": "connectors/elevenlabs/go/v0.2.0",
|
|
4
|
+
"package": {
|
|
5
|
+
"ecosystem": "npm",
|
|
6
|
+
"name": "@superdurable/connector-elevenlabs",
|
|
7
|
+
"version": "0.1.0"
|
|
8
|
+
},
|
|
9
|
+
"factories": [
|
|
10
|
+
{
|
|
11
|
+
"name": "newListVoicesStep",
|
|
12
|
+
"kind": "query",
|
|
13
|
+
"operationId": "listVoices",
|
|
14
|
+
"fields": {
|
|
15
|
+
"stepType": "stepType",
|
|
16
|
+
"annotations": "annotations",
|
|
17
|
+
"connectionName": "connectionName",
|
|
18
|
+
"resultAttribute": "resultAttribute"
|
|
19
|
+
},
|
|
20
|
+
"branches": [
|
|
21
|
+
{
|
|
22
|
+
"id": "listed",
|
|
23
|
+
"field": "listed",
|
|
24
|
+
"optional": false
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"id": "providerRejected",
|
|
28
|
+
"field": "providerRejected",
|
|
29
|
+
"optional": true
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"id": "invalidResponse",
|
|
33
|
+
"field": "invalidResponse",
|
|
34
|
+
"optional": true
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"id": "defect",
|
|
38
|
+
"field": "defect",
|
|
39
|
+
"optional": true
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"name": "newCreateSpeechStep",
|
|
45
|
+
"kind": "query",
|
|
46
|
+
"operationId": "createSpeech",
|
|
47
|
+
"fields": {
|
|
48
|
+
"stepType": "stepType",
|
|
49
|
+
"annotations": "annotations",
|
|
50
|
+
"connectionName": "connectionName",
|
|
51
|
+
"resultAttribute": "resultAttribute"
|
|
52
|
+
},
|
|
53
|
+
"branches": [
|
|
54
|
+
{
|
|
55
|
+
"id": "created",
|
|
56
|
+
"field": "created",
|
|
57
|
+
"optional": false
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"id": "providerRejected",
|
|
61
|
+
"field": "providerRejected",
|
|
62
|
+
"optional": true
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"id": "invalidResponse",
|
|
66
|
+
"field": "invalidResponse",
|
|
67
|
+
"optional": true
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"id": "defect",
|
|
71
|
+
"field": "defect",
|
|
72
|
+
"optional": true
|
|
73
|
+
}
|
|
74
|
+
]
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// src/generated/models.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
var ConfigSchema = z.object({
|
|
4
|
+
"baseUrl": z.string().optional(),
|
|
5
|
+
"timeoutMs": z.number().int().optional(),
|
|
6
|
+
"maxResponseBytes": z.number().int().optional()
|
|
7
|
+
});
|
|
8
|
+
var ListVoicesInputSchema = z.strictObject({
|
|
9
|
+
"pageSize": z.number().int().optional(),
|
|
10
|
+
"nextPageToken": z.string().optional()
|
|
11
|
+
});
|
|
12
|
+
var VoiceSchema = z.strictObject({
|
|
13
|
+
"voiceId": z.string(),
|
|
14
|
+
"name": z.string()
|
|
15
|
+
});
|
|
16
|
+
var ListVoicesOutputSchema = z.strictObject({
|
|
17
|
+
"voices": z.array(VoiceSchema).nullable(),
|
|
18
|
+
"hasMore": z.boolean(),
|
|
19
|
+
"nextPageToken": z.string().optional()
|
|
20
|
+
});
|
|
21
|
+
var CreateSpeechInputSchema = z.strictObject({
|
|
22
|
+
"voiceId": z.string(),
|
|
23
|
+
"text": z.string(),
|
|
24
|
+
"modelId": z.string().optional()
|
|
25
|
+
});
|
|
26
|
+
var CreateSpeechOutputSchema = z.strictObject({
|
|
27
|
+
"audioBase64": z.string(),
|
|
28
|
+
"contentType": z.string()
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// src/generated/definitions.ts
|
|
32
|
+
var ConnectorID = "elevenlabs";
|
|
33
|
+
var ProviderID = "elevenlabs";
|
|
34
|
+
var ListVoicesBranch = {
|
|
35
|
+
Listed: "listed",
|
|
36
|
+
ProviderRejected: "providerRejected",
|
|
37
|
+
InvalidResponse: "invalidResponse",
|
|
38
|
+
Defect: "defect"
|
|
39
|
+
};
|
|
40
|
+
var ListVoicesBranchListed = ListVoicesBranch.Listed;
|
|
41
|
+
var ListVoicesBranchProviderRejected = ListVoicesBranch.ProviderRejected;
|
|
42
|
+
var ListVoicesBranchInvalidResponse = ListVoicesBranch.InvalidResponse;
|
|
43
|
+
var ListVoicesBranchDefect = ListVoicesBranch.Defect;
|
|
44
|
+
var ListVoicesDefinition = {
|
|
45
|
+
operation: { connectorId: ConnectorID, operationId: "listVoices" },
|
|
46
|
+
branches: [
|
|
47
|
+
{ id: "listed", description: "ElevenLabs returned the requested result." },
|
|
48
|
+
{ id: "providerRejected", description: "The provider conclusively rejected the request.", optional: true },
|
|
49
|
+
{ id: "invalidResponse", description: "The provider returned malformed or oversized data.", optional: true },
|
|
50
|
+
{ id: "defect", description: "Local input or credentials are invalid.", optional: true }
|
|
51
|
+
],
|
|
52
|
+
stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "async" }
|
|
53
|
+
};
|
|
54
|
+
var ListVoicesMetadata = { kind: "query", idempotency: "none", authorization: "required" };
|
|
55
|
+
var CreateSpeechBranch = {
|
|
56
|
+
Created: "created",
|
|
57
|
+
ProviderRejected: "providerRejected",
|
|
58
|
+
InvalidResponse: "invalidResponse",
|
|
59
|
+
Defect: "defect"
|
|
60
|
+
};
|
|
61
|
+
var CreateSpeechBranchCreated = CreateSpeechBranch.Created;
|
|
62
|
+
var CreateSpeechBranchProviderRejected = CreateSpeechBranch.ProviderRejected;
|
|
63
|
+
var CreateSpeechBranchInvalidResponse = CreateSpeechBranch.InvalidResponse;
|
|
64
|
+
var CreateSpeechBranchDefect = CreateSpeechBranch.Defect;
|
|
65
|
+
var CreateSpeechDefinition = {
|
|
66
|
+
operation: { connectorId: ConnectorID, operationId: "createSpeech" },
|
|
67
|
+
branches: [
|
|
68
|
+
{ id: "created", description: "ElevenLabs returned the requested result." },
|
|
69
|
+
{ id: "providerRejected", description: "The provider conclusively rejected the request.", optional: true },
|
|
70
|
+
{ id: "invalidResponse", description: "The provider returned malformed or oversized data.", optional: true },
|
|
71
|
+
{ id: "defect", description: "Local input or credentials are invalid.", optional: true }
|
|
72
|
+
],
|
|
73
|
+
stepDefaults: { executeMethodTimeoutMs: 15e4, executeDurability: "sync", executeRetry: { initialIntervalMs: 2e3, backoffCoefficient: 2, maximumIntervalMs: 3e4, maximumAttempts: 3, totalDurationMs: 3e5 } }
|
|
74
|
+
};
|
|
75
|
+
var CreateSpeechMetadata = { kind: "query", idempotency: "none", authorization: "required" };
|
|
76
|
+
|
|
77
|
+
// src/generated/connection.ts
|
|
78
|
+
import { ConnectionRefSchema } from "@superdurable/connectors-sdk";
|
|
79
|
+
var Connection = class {
|
|
80
|
+
/** Stable provider and connection name. */
|
|
81
|
+
reference;
|
|
82
|
+
/** Bound provider operations. */
|
|
83
|
+
operations;
|
|
84
|
+
/** Validate a reference and bind operations. */
|
|
85
|
+
constructor(reference, operations) {
|
|
86
|
+
this.reference = ConnectionRefSchema.parse(reference);
|
|
87
|
+
if (this.reference.provider !== ProviderID) throw new TypeError("connection provider differs from the manifest");
|
|
88
|
+
if (!operations) throw new TypeError("connector operations are required");
|
|
89
|
+
this.operations = operations;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
function newConnection(client, reference) {
|
|
93
|
+
if (!client) throw new TypeError("connector client is required");
|
|
94
|
+
return new Connection(reference, client);
|
|
95
|
+
}
|
|
96
|
+
function newConnectionWithOperations(operations, reference) {
|
|
97
|
+
return new Connection(reference, operations);
|
|
98
|
+
}
|
|
99
|
+
function newProjectConnection(project, connectionName, createClient) {
|
|
100
|
+
if (!project) throw new TypeError("loaded project is required");
|
|
101
|
+
const reference = ConnectionRefSchema.parse({ provider: ProviderID, name: connectionName });
|
|
102
|
+
const selected = project.configuration.connections.find((entry) => entry.connectorId === ConnectorID && entry.connectionName === connectionName);
|
|
103
|
+
if (!selected || selected.provider !== ProviderID) throw new TypeError("project connection is not configured");
|
|
104
|
+
return newConnection(createClient(project, connectionName), reference);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export {
|
|
108
|
+
ConfigSchema,
|
|
109
|
+
ListVoicesInputSchema,
|
|
110
|
+
VoiceSchema,
|
|
111
|
+
ListVoicesOutputSchema,
|
|
112
|
+
CreateSpeechInputSchema,
|
|
113
|
+
CreateSpeechOutputSchema,
|
|
114
|
+
ConnectorID,
|
|
115
|
+
ProviderID,
|
|
116
|
+
ListVoicesBranch,
|
|
117
|
+
ListVoicesBranchListed,
|
|
118
|
+
ListVoicesBranchProviderRejected,
|
|
119
|
+
ListVoicesBranchInvalidResponse,
|
|
120
|
+
ListVoicesBranchDefect,
|
|
121
|
+
ListVoicesDefinition,
|
|
122
|
+
ListVoicesMetadata,
|
|
123
|
+
CreateSpeechBranch,
|
|
124
|
+
CreateSpeechBranchCreated,
|
|
125
|
+
CreateSpeechBranchProviderRejected,
|
|
126
|
+
CreateSpeechBranchInvalidResponse,
|
|
127
|
+
CreateSpeechBranchDefect,
|
|
128
|
+
CreateSpeechDefinition,
|
|
129
|
+
CreateSpeechMetadata,
|
|
130
|
+
Connection,
|
|
131
|
+
newConnection,
|
|
132
|
+
newConnectionWithOperations,
|
|
133
|
+
newProjectConnection
|
|
134
|
+
};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { SecretString, CredentialProvider, Query, ConnectionRef } from '@superdurable/connectors-sdk';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
/** Connector configuration; omitted fields use manifest defaults. */
|
|
5
|
+
interface Config {
|
|
6
|
+
/** Public ElevenLabs API base URL. Leave blank for the displayed default; override only for a trusted compatible gateway or a loopback test server. */
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
/** Maximum duration of one provider HTTP request, as a positive Go duration such as 15s or 1m. Leave blank for the displayed default; increase only for slow responses. Runtime value in milliseconds. */
|
|
9
|
+
timeoutMs?: number;
|
|
10
|
+
/** Positive maximum response size in bytes. Leave blank for the displayed default; increase only for a known larger response. Oversized replies select invalidResponse. */
|
|
11
|
+
maxResponseBytes?: number;
|
|
12
|
+
}
|
|
13
|
+
/** Runtime schema for manifest configuration. */
|
|
14
|
+
declare const ConfigSchema: z.ZodObject<{
|
|
15
|
+
baseUrl: z.ZodOptional<z.ZodString>;
|
|
16
|
+
timeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
17
|
+
maxResponseBytes: z.ZodOptional<z.ZodNumber>;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
/** Private connector credentials resolved by the host. */
|
|
20
|
+
interface Credentials {
|
|
21
|
+
/** Secret API key from ElevenLabs > Developers > API Keys > Create API Key at https://elevenlabs.io/app/developers/api-keys. Copy the provider-issued string into this field; blank makes calls select defect. It is stored as a secret and sent only in the HTTP authorization header. */
|
|
22
|
+
apiKey: SecretString;
|
|
23
|
+
}
|
|
24
|
+
/** Host-owned source of private connector credentials. */
|
|
25
|
+
type CredentialSource = CredentialProvider<Credentials>;
|
|
26
|
+
/** ListVoicesInput selects one page of account voices. */
|
|
27
|
+
interface ListVoicesInput {
|
|
28
|
+
/** PageSize is the requested page size; zero uses the provider default. */
|
|
29
|
+
"pageSize"?: number | undefined;
|
|
30
|
+
/** NextPageToken is a token returned by the preceding page; blank starts at page one. */
|
|
31
|
+
"nextPageToken"?: string | undefined;
|
|
32
|
+
}
|
|
33
|
+
/** Voice identifies an ElevenLabs voice. */
|
|
34
|
+
interface Voice {
|
|
35
|
+
/** VoiceID is the stable provider voice identifier. */
|
|
36
|
+
"voiceId": string;
|
|
37
|
+
/** Name is the display name. */
|
|
38
|
+
"name": string;
|
|
39
|
+
}
|
|
40
|
+
/** ListVoicesOutput holds one voice page. */
|
|
41
|
+
interface ListVoicesOutput {
|
|
42
|
+
/** Voices is the page of available voices. */
|
|
43
|
+
"voices": Array<Voice> | null;
|
|
44
|
+
/** HasMore reports whether another page is available. */
|
|
45
|
+
"hasMore": boolean;
|
|
46
|
+
/** NextPageToken selects the next page when HasMore is true. */
|
|
47
|
+
"nextPageToken"?: string | undefined;
|
|
48
|
+
}
|
|
49
|
+
/** CreateSpeechInput selects a voice and the text to synthesize. */
|
|
50
|
+
interface CreateSpeechInput {
|
|
51
|
+
/** VoiceID is returned by listVoices or shown in the ElevenLabs voice library. */
|
|
52
|
+
"voiceId": string;
|
|
53
|
+
/** Text is the text to speak. */
|
|
54
|
+
"text": string;
|
|
55
|
+
/** ModelID selects a text-to-speech model; blank uses eleven_multilingual_v2. */
|
|
56
|
+
"modelId"?: string | undefined;
|
|
57
|
+
}
|
|
58
|
+
/** CreateSpeechOutput holds bounded MP3 audio as base64. */
|
|
59
|
+
interface CreateSpeechOutput {
|
|
60
|
+
/** AudioBase64 is the MP3 payload encoded for Dex persistence. */
|
|
61
|
+
"audioBase64": string;
|
|
62
|
+
/** ContentType identifies the MP3 format. */
|
|
63
|
+
"contentType": string;
|
|
64
|
+
}
|
|
65
|
+
/** Runtime validator for ListVoicesInput. */
|
|
66
|
+
declare const ListVoicesInputSchema: z.ZodObject<{
|
|
67
|
+
pageSize: z.ZodOptional<z.ZodNumber>;
|
|
68
|
+
nextPageToken: z.ZodOptional<z.ZodString>;
|
|
69
|
+
}, z.core.$strict>;
|
|
70
|
+
/** Runtime validator for Voice. */
|
|
71
|
+
declare const VoiceSchema: z.ZodObject<{
|
|
72
|
+
voiceId: z.ZodString;
|
|
73
|
+
name: z.ZodString;
|
|
74
|
+
}, z.core.$strict>;
|
|
75
|
+
/** Runtime validator for ListVoicesOutput. */
|
|
76
|
+
declare const ListVoicesOutputSchema: z.ZodObject<{
|
|
77
|
+
voices: z.ZodNullable<z.ZodArray<z.ZodObject<{
|
|
78
|
+
voiceId: z.ZodString;
|
|
79
|
+
name: z.ZodString;
|
|
80
|
+
}, z.core.$strict>>>;
|
|
81
|
+
hasMore: z.ZodBoolean;
|
|
82
|
+
nextPageToken: z.ZodOptional<z.ZodString>;
|
|
83
|
+
}, z.core.$strict>;
|
|
84
|
+
/** Runtime validator for CreateSpeechInput. */
|
|
85
|
+
declare const CreateSpeechInputSchema: z.ZodObject<{
|
|
86
|
+
voiceId: z.ZodString;
|
|
87
|
+
text: z.ZodString;
|
|
88
|
+
modelId: z.ZodOptional<z.ZodString>;
|
|
89
|
+
}, z.core.$strict>;
|
|
90
|
+
/** Runtime validator for CreateSpeechOutput. */
|
|
91
|
+
declare const CreateSpeechOutputSchema: z.ZodObject<{
|
|
92
|
+
audioBase64: z.ZodString;
|
|
93
|
+
contentType: z.ZodString;
|
|
94
|
+
}, z.core.$strict>;
|
|
95
|
+
|
|
96
|
+
/** Typed operations supplied by a client or mock. */
|
|
97
|
+
interface Operations {
|
|
98
|
+
/** Invoke listVoices through this connection. */
|
|
99
|
+
listVoices(): Query<ListVoicesInput, ListVoicesOutput>;
|
|
100
|
+
/** Invoke createSpeech through this connection. */
|
|
101
|
+
createSpeech(): Query<CreateSpeechInput, CreateSpeechOutput>;
|
|
102
|
+
}
|
|
103
|
+
/** Named connector connection kept outside Flow state. */
|
|
104
|
+
declare class Connection<BoundOperations = Operations> {
|
|
105
|
+
/** Stable provider and connection name. */
|
|
106
|
+
readonly reference: ConnectionRef;
|
|
107
|
+
/** Bound provider operations. */
|
|
108
|
+
readonly operations: BoundOperations;
|
|
109
|
+
/** Validate a reference and bind operations. */
|
|
110
|
+
constructor(reference: ConnectionRef, operations: BoundOperations);
|
|
111
|
+
}
|
|
112
|
+
/** Bind a client to a named connection. */
|
|
113
|
+
declare function newConnection(client: Operations, reference: ConnectionRef): Connection;
|
|
114
|
+
/** Bind scripted operations to a named connection. */
|
|
115
|
+
declare function newConnectionWithOperations(operations: Operations, reference: ConnectionRef): Connection;
|
|
116
|
+
|
|
117
|
+
export { type CreateSpeechInput as C, type ListVoicesInput as L, type Operations as O, type Voice as V, type CreateSpeechOutput as a, Connection as b, type ListVoicesOutput as c, type Config as d, type Credentials as e, ConfigSchema as f, CreateSpeechInputSchema as g, CreateSpeechOutputSchema as h, type CredentialSource as i, ListVoicesInputSchema as j, ListVoicesOutputSchema as k, VoiceSchema as l, newConnectionWithOperations as m, newConnection as n };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { C as CreateSpeechInput, a as CreateSpeechOutput, b as Connection, L as ListVoicesInput, c as ListVoicesOutput, O as Operations, d as Config, e as Credentials } from './connection-DFnhV-HC.js';
|
|
2
|
+
export { f as ConfigSchema, g as CreateSpeechInputSchema, h as CreateSpeechOutputSchema, i as CredentialSource, j as ListVoicesInputSchema, k as ListVoicesOutputSchema, V as Voice, l as VoiceSchema, n as newConnection, m as newConnectionWithOperations } from './connection-DFnhV-HC.js';
|
|
3
|
+
import * as _superdurable_connectors_sdk from '@superdurable/connectors-sdk';
|
|
4
|
+
import { QueryDefinition, QueryStepConfig, Query, QueryResult, QueryStep, Call, QueryAttempt, CredentialProvider } from '@superdurable/connectors-sdk';
|
|
5
|
+
import { StepTarget } from '@superdurable/dex';
|
|
6
|
+
import { LoadedProject } from '@superdurable/connectors-sdk/projectconfig';
|
|
7
|
+
import { ProviderRequest, ProviderResponse } from '@superdurable/connectors-sdk/providerhttp';
|
|
8
|
+
import 'zod';
|
|
9
|
+
|
|
10
|
+
/** Stable connector identity. */
|
|
11
|
+
declare const ConnectorID = "elevenlabs";
|
|
12
|
+
/** Provider identity for named connections. */
|
|
13
|
+
declare const ProviderID = "elevenlabs";
|
|
14
|
+
/** Branch IDs for listVoices. */
|
|
15
|
+
declare const ListVoicesBranch: {
|
|
16
|
+
readonly Listed: "listed";
|
|
17
|
+
readonly ProviderRejected: "providerRejected";
|
|
18
|
+
readonly InvalidResponse: "invalidResponse";
|
|
19
|
+
readonly Defect: "defect";
|
|
20
|
+
};
|
|
21
|
+
/** ElevenLabs returned the requested result. */
|
|
22
|
+
declare const ListVoicesBranchListed: "listed";
|
|
23
|
+
/** The provider conclusively rejected the request. */
|
|
24
|
+
declare const ListVoicesBranchProviderRejected: "providerRejected";
|
|
25
|
+
/** The provider returned malformed or oversized data. */
|
|
26
|
+
declare const ListVoicesBranchInvalidResponse: "invalidResponse";
|
|
27
|
+
/** Local input or credentials are invalid. */
|
|
28
|
+
declare const ListVoicesBranchDefect: "defect";
|
|
29
|
+
/** Manifest definition for listVoices. */
|
|
30
|
+
declare const ListVoicesDefinition: QueryDefinition;
|
|
31
|
+
/** Manifest metadata for listVoices. */
|
|
32
|
+
declare const ListVoicesMetadata: {
|
|
33
|
+
readonly kind: "query";
|
|
34
|
+
readonly idempotency: "none";
|
|
35
|
+
readonly authorization: "required";
|
|
36
|
+
};
|
|
37
|
+
/** Branch IDs for createSpeech. */
|
|
38
|
+
declare const CreateSpeechBranch: {
|
|
39
|
+
readonly Created: "created";
|
|
40
|
+
readonly ProviderRejected: "providerRejected";
|
|
41
|
+
readonly InvalidResponse: "invalidResponse";
|
|
42
|
+
readonly Defect: "defect";
|
|
43
|
+
};
|
|
44
|
+
/** ElevenLabs returned the requested result. */
|
|
45
|
+
declare const CreateSpeechBranchCreated: "created";
|
|
46
|
+
/** The provider conclusively rejected the request. */
|
|
47
|
+
declare const CreateSpeechBranchProviderRejected: "providerRejected";
|
|
48
|
+
/** The provider returned malformed or oversized data. */
|
|
49
|
+
declare const CreateSpeechBranchInvalidResponse: "invalidResponse";
|
|
50
|
+
/** Local input or credentials are invalid. */
|
|
51
|
+
declare const CreateSpeechBranchDefect: "defect";
|
|
52
|
+
/** Manifest definition for createSpeech. */
|
|
53
|
+
declare const CreateSpeechDefinition: QueryDefinition;
|
|
54
|
+
/** Manifest metadata for createSpeech. */
|
|
55
|
+
declare const CreateSpeechMetadata: {
|
|
56
|
+
readonly kind: "query";
|
|
57
|
+
readonly idempotency: "none";
|
|
58
|
+
readonly authorization: "required";
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/** Configuration for the listVoices connector Step. */
|
|
62
|
+
interface ListVoicesStepConfig<StepInput, OperationInput = ListVoicesInput, OperationOutput = ListVoicesOutput> extends Omit<QueryStepConfig<StepInput, OperationInput, OperationOutput>, 'operation' | 'connection' | 'branches'> {
|
|
63
|
+
/** Named connection supplying this operation. */
|
|
64
|
+
connection: Connection<{
|
|
65
|
+
listVoices(): Query<OperationInput, OperationOutput>;
|
|
66
|
+
}>;
|
|
67
|
+
/** Name matching the bound connection. */
|
|
68
|
+
connectionName: string;
|
|
69
|
+
/** ElevenLabs returned the requested result. */
|
|
70
|
+
listed: StepTarget<QueryResult<OperationOutput>>;
|
|
71
|
+
/** The provider conclusively rejected the request. */
|
|
72
|
+
providerRejected?: StepTarget<QueryResult<OperationOutput>>;
|
|
73
|
+
/** The provider returned malformed or oversized data. */
|
|
74
|
+
invalidResponse?: StepTarget<QueryResult<OperationOutput>>;
|
|
75
|
+
/** Local input or credentials are invalid. */
|
|
76
|
+
defect?: StepTarget<QueryResult<OperationOutput>>;
|
|
77
|
+
}
|
|
78
|
+
/** Build the listVoices Step from a named connection. */
|
|
79
|
+
declare function newListVoicesStep<StepInput, OperationInput = ListVoicesInput, OperationOutput = ListVoicesOutput>(configuration: ListVoicesStepConfig<StepInput, OperationInput, OperationOutput>): QueryStep<StepInput, OperationInput, OperationOutput>;
|
|
80
|
+
/** Configuration for the createSpeech connector Step. */
|
|
81
|
+
interface CreateSpeechStepConfig<StepInput, OperationInput = CreateSpeechInput, OperationOutput = CreateSpeechOutput> extends Omit<QueryStepConfig<StepInput, OperationInput, OperationOutput>, 'operation' | 'connection' | 'branches'> {
|
|
82
|
+
/** Named connection supplying this operation. */
|
|
83
|
+
connection: Connection<{
|
|
84
|
+
createSpeech(): Query<OperationInput, OperationOutput>;
|
|
85
|
+
}>;
|
|
86
|
+
/** Name matching the bound connection. */
|
|
87
|
+
connectionName: string;
|
|
88
|
+
/** ElevenLabs returned the requested result. */
|
|
89
|
+
created: StepTarget<QueryResult<OperationOutput>>;
|
|
90
|
+
/** The provider conclusively rejected the request. */
|
|
91
|
+
providerRejected?: StepTarget<QueryResult<OperationOutput>>;
|
|
92
|
+
/** The provider returned malformed or oversized data. */
|
|
93
|
+
invalidResponse?: StepTarget<QueryResult<OperationOutput>>;
|
|
94
|
+
/** Local input or credentials are invalid. */
|
|
95
|
+
defect?: StepTarget<QueryResult<OperationOutput>>;
|
|
96
|
+
}
|
|
97
|
+
/** Build the createSpeech Step from a named connection. */
|
|
98
|
+
declare function newCreateSpeechStep<StepInput, OperationInput = CreateSpeechInput, OperationOutput = CreateSpeechOutput>(configuration: CreateSpeechStepConfig<StepInput, OperationInput, OperationOutput>): QueryStep<StepInput, OperationInput, OperationOutput>;
|
|
99
|
+
|
|
100
|
+
/** Open one static ElevenLabs connection declared in a Dex project. */
|
|
101
|
+
declare function newProjectConnection(project: LoadedProject, connectionName: string): Connection<Operations>;
|
|
102
|
+
|
|
103
|
+
/** List one page of voices using the Go connector's validation and response rules. */
|
|
104
|
+
declare class ListVoicesOperation implements Query<ListVoicesInput, ListVoicesOutput> {
|
|
105
|
+
private readonly client;
|
|
106
|
+
/** Bind an authenticated client. */ constructor(client: ElevenLabsClient);
|
|
107
|
+
/** Return the generated manifest definition. */ definition(): _superdurable_connectors_sdk.QueryDefinition;
|
|
108
|
+
/** Validate and fetch one voice page. */
|
|
109
|
+
invoke(call: Call, input: ListVoicesInput): Promise<QueryAttempt<ListVoicesOutput>>;
|
|
110
|
+
}
|
|
111
|
+
/** Generate bounded MP3 audio from one voice and text. */
|
|
112
|
+
declare class CreateSpeechOperation implements Query<CreateSpeechInput, CreateSpeechOutput> {
|
|
113
|
+
private readonly client;
|
|
114
|
+
/** Bind an authenticated client. */ constructor(client: ElevenLabsClient);
|
|
115
|
+
/** Return the generated manifest definition. */ definition(): _superdurable_connectors_sdk.QueryDefinition;
|
|
116
|
+
/** Validate and synthesize one response. */
|
|
117
|
+
invoke(call: Call, input: CreateSpeechInput): Promise<QueryAttempt<CreateSpeechOutput>>;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** HTTP sender used by ElevenLabs, replaceable by a deterministic provider fixture. */
|
|
121
|
+
type ElevenLabsRequestSender = (request: ProviderRequest) => Promise<ProviderResponse>;
|
|
122
|
+
/** Injectable dependencies for provider tests. */
|
|
123
|
+
interface ElevenLabsClientOptions {
|
|
124
|
+
/** HTTP sender; production uses the SDK's bounded, no-redirect transport. */
|
|
125
|
+
send?: ElevenLabsRequestSender;
|
|
126
|
+
/** Clock used to interpret HTTP Retry-After dates. */
|
|
127
|
+
now?: () => Date;
|
|
128
|
+
}
|
|
129
|
+
/** Immutable provider settings with credentials resolved for every invocation. */
|
|
130
|
+
declare class ElevenLabsClient {
|
|
131
|
+
private readonly baseUrl;
|
|
132
|
+
private readonly timeoutMs;
|
|
133
|
+
private readonly maxResponseBytes;
|
|
134
|
+
private readonly credentials;
|
|
135
|
+
private readonly send;
|
|
136
|
+
private readonly now;
|
|
137
|
+
/** Validate settings without contacting the provider. */
|
|
138
|
+
constructor(config: Config, credentials: CredentialProvider<Credentials>, options?: ElevenLabsClientOptions);
|
|
139
|
+
/** Bind the voice-list query. */
|
|
140
|
+
listVoices(): ListVoicesOperation;
|
|
141
|
+
/** Bind the speech-generation query. */
|
|
142
|
+
createSpeech(): CreateSpeechOperation;
|
|
143
|
+
/** Send one request and classify its status before decoding its body. */
|
|
144
|
+
invokeQuery<Output>(call: Call, operation: string, success: string, method: string, path: string, query: URLSearchParams, body: Uint8Array | undefined, empty: Output, decode: (body: Uint8Array) => Output): Promise<QueryAttempt<Output>>;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export { Config, Connection, ConnectorID, CreateSpeechBranch, CreateSpeechBranchCreated, CreateSpeechBranchDefect, CreateSpeechBranchInvalidResponse, CreateSpeechBranchProviderRejected, CreateSpeechDefinition, CreateSpeechInput, CreateSpeechMetadata, CreateSpeechOperation, CreateSpeechOutput, type CreateSpeechStepConfig, Credentials, ElevenLabsClient, type ElevenLabsClientOptions, type ElevenLabsRequestSender, ListVoicesBranch, ListVoicesBranchDefect, ListVoicesBranchInvalidResponse, ListVoicesBranchListed, ListVoicesBranchProviderRejected, ListVoicesDefinition, ListVoicesInput, ListVoicesMetadata, ListVoicesOperation, ListVoicesOutput, type ListVoicesStepConfig, ProviderID, newCreateSpeechStep, newListVoicesStep, newProjectConnection };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
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
|
+
ListVoicesBranch,
|
|
15
|
+
ListVoicesBranchDefect,
|
|
16
|
+
ListVoicesBranchInvalidResponse,
|
|
17
|
+
ListVoicesBranchListed,
|
|
18
|
+
ListVoicesBranchProviderRejected,
|
|
19
|
+
ListVoicesDefinition,
|
|
20
|
+
ListVoicesInputSchema,
|
|
21
|
+
ListVoicesMetadata,
|
|
22
|
+
ListVoicesOutputSchema,
|
|
23
|
+
ProviderID,
|
|
24
|
+
VoiceSchema,
|
|
25
|
+
newConnection,
|
|
26
|
+
newConnectionWithOperations,
|
|
27
|
+
newProjectConnection
|
|
28
|
+
} from "./chunk-GIQKY62E.js";
|
|
29
|
+
|
|
30
|
+
// src/generated/steps.ts
|
|
31
|
+
import { goToBranch, newQueryStep } from "@superdurable/connectors-sdk";
|
|
32
|
+
function newListVoicesStep(configuration) {
|
|
33
|
+
const { connection, connectionName, listed, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
|
|
34
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
35
|
+
return newQueryStep({ ...stepConfiguration, operation: connection.operations.listVoices(), connection: connection.reference, branches: [
|
|
36
|
+
goToBranch("listed", listed),
|
|
37
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
38
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
39
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
40
|
+
] });
|
|
41
|
+
}
|
|
42
|
+
function newCreateSpeechStep(configuration) {
|
|
43
|
+
const { connection, connectionName, created, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
|
|
44
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
45
|
+
return newQueryStep({ ...stepConfiguration, operation: connection.operations.createSpeech(), connection: connection.reference, branches: [
|
|
46
|
+
goToBranch("created", created),
|
|
47
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
48
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
49
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
50
|
+
] });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/project.ts
|
|
54
|
+
import { SecretString as SecretString2 } from "@superdurable/connectors-sdk";
|
|
55
|
+
import { z } from "zod";
|
|
56
|
+
|
|
57
|
+
// src/client.ts
|
|
58
|
+
import { BodyTooLargeError, isHeaderSafeCredential, parseRetryAfter, sendProviderRequest, validateBaseURL } from "@superdurable/connectors-sdk/providerhttp";
|
|
59
|
+
import { SecretString, newQueryBranch as newQueryBranch2, newQueryRetry } from "@superdurable/connectors-sdk";
|
|
60
|
+
|
|
61
|
+
// src/operations.ts
|
|
62
|
+
import { newQueryBranch } from "@superdurable/connectors-sdk";
|
|
63
|
+
var emptyVoices = { voices: [], hasMore: false };
|
|
64
|
+
var emptySpeech = { audioBase64: "", contentType: "" };
|
|
65
|
+
var voiceIDPattern = /^[A-Za-z0-9_-]{1,128}$/;
|
|
66
|
+
var ListVoicesOperation = class {
|
|
67
|
+
/** Bind an authenticated client. */
|
|
68
|
+
constructor(client) {
|
|
69
|
+
this.client = client;
|
|
70
|
+
}
|
|
71
|
+
client;
|
|
72
|
+
/** Return the generated manifest definition. */
|
|
73
|
+
definition() {
|
|
74
|
+
return ListVoicesDefinition;
|
|
75
|
+
}
|
|
76
|
+
/** Validate and fetch one voice page. */
|
|
77
|
+
invoke(call, input) {
|
|
78
|
+
const pageSize = input.pageSize ?? 0;
|
|
79
|
+
const token = input.nextPageToken ?? "";
|
|
80
|
+
if (!Number.isSafeInteger(pageSize) || pageSize < 0 || pageSize > 100 || typeof token !== "string" || /[\r\n]/.test(token)) {
|
|
81
|
+
return Promise.resolve(newQueryBranch("defect", emptyVoices, {}, { kind: "VALIDATION", provider: "elevenlabs", operation: "listVoices", message: "page size or token is invalid" }));
|
|
82
|
+
}
|
|
83
|
+
const query = new URLSearchParams();
|
|
84
|
+
if (token) query.set("next_page_token", token);
|
|
85
|
+
if (pageSize > 0) query.set("page_size", String(pageSize));
|
|
86
|
+
return this.client.invokeQuery(call, "listVoices", "listed", "GET", "/v2/voices", query, void 0, emptyVoices, decodeVoices);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
var CreateSpeechOperation = class {
|
|
90
|
+
/** Bind an authenticated client. */
|
|
91
|
+
constructor(client) {
|
|
92
|
+
this.client = client;
|
|
93
|
+
}
|
|
94
|
+
client;
|
|
95
|
+
/** Return the generated manifest definition. */
|
|
96
|
+
definition() {
|
|
97
|
+
return CreateSpeechDefinition;
|
|
98
|
+
}
|
|
99
|
+
/** Validate and synthesize one response. */
|
|
100
|
+
invoke(call, input) {
|
|
101
|
+
if (typeof input.voiceId !== "string" || !voiceIDPattern.test(input.voiceId) || typeof input.text !== "string" || !input.text.trim() || input.modelId !== void 0 && typeof input.modelId !== "string") {
|
|
102
|
+
return Promise.resolve(newQueryBranch("defect", emptySpeech, {}, { kind: "VALIDATION", provider: "elevenlabs", operation: "createSpeech", message: "voiceId and text are required" }));
|
|
103
|
+
}
|
|
104
|
+
const body = Buffer.from(JSON.stringify({ text: input.text, model_id: input.modelId || "eleven_multilingual_v2" }), "utf8");
|
|
105
|
+
return this.client.invokeQuery(call, "createSpeech", "created", "POST", `/v1/text-to-speech/${input.voiceId}`, new URLSearchParams({ output_format: "mp3_44100_128" }), body, emptySpeech, decodeSpeech);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
function decodeVoices(body) {
|
|
109
|
+
const document = JSON.parse(Buffer.from(body).toString("utf8"));
|
|
110
|
+
if (!isObject(document) || !Array.isArray(document.voices)) throw new TypeError("voices missing");
|
|
111
|
+
const voices = document.voices.map((voice) => {
|
|
112
|
+
if (!isObject(voice) || typeof voice.voice_id !== "string" || !voice.voice_id || voice.name != null && typeof voice.name !== "string") throw new TypeError("voice invalid");
|
|
113
|
+
return { voiceId: voice.voice_id, name: voice.name ?? "" };
|
|
114
|
+
});
|
|
115
|
+
if (document.has_more != null && typeof document.has_more !== "boolean") throw new TypeError("has_more invalid");
|
|
116
|
+
if (document.next_page_token != null && typeof document.next_page_token !== "string") throw new TypeError("next_page_token invalid");
|
|
117
|
+
return { voices, hasMore: document.has_more ?? false, ...document.next_page_token ? { nextPageToken: document.next_page_token } : {} };
|
|
118
|
+
}
|
|
119
|
+
function decodeSpeech(body) {
|
|
120
|
+
if (!body.length) throw new TypeError("audio missing");
|
|
121
|
+
return { audioBase64: Buffer.from(body).toString("base64"), contentType: "audio/mpeg" };
|
|
122
|
+
}
|
|
123
|
+
function isObject(value) {
|
|
124
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// src/client.ts
|
|
128
|
+
var ElevenLabsClient = class {
|
|
129
|
+
baseUrl;
|
|
130
|
+
timeoutMs;
|
|
131
|
+
maxResponseBytes;
|
|
132
|
+
credentials;
|
|
133
|
+
send;
|
|
134
|
+
now;
|
|
135
|
+
/** Validate settings without contacting the provider. */
|
|
136
|
+
constructor(config, credentials, options = {}) {
|
|
137
|
+
if (!credentials) throw new TypeError("ElevenLabs credential source is required");
|
|
138
|
+
this.baseUrl = validateBaseURL(config.baseUrl || "https://api.elevenlabs.io");
|
|
139
|
+
this.timeoutMs = config.timeoutMs || 12e4;
|
|
140
|
+
this.maxResponseBytes = config.maxResponseBytes || 2097152;
|
|
141
|
+
if (!Number.isSafeInteger(this.timeoutMs) || this.timeoutMs < 0) throw new TypeError("ElevenLabs timeout must be nonnegative");
|
|
142
|
+
if (!Number.isSafeInteger(this.maxResponseBytes) || this.maxResponseBytes < 0) throw new TypeError("ElevenLabs response limit must be nonnegative");
|
|
143
|
+
this.credentials = credentials;
|
|
144
|
+
this.send = options.send ?? sendProviderRequest;
|
|
145
|
+
this.now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
146
|
+
}
|
|
147
|
+
/** Bind the voice-list query. */
|
|
148
|
+
listVoices() {
|
|
149
|
+
return new ListVoicesOperation(this);
|
|
150
|
+
}
|
|
151
|
+
/** Bind the speech-generation query. */
|
|
152
|
+
createSpeech() {
|
|
153
|
+
return new CreateSpeechOperation(this);
|
|
154
|
+
}
|
|
155
|
+
/** Send one request and classify its status before decoding its body. */
|
|
156
|
+
async invokeQuery(call, operation, success, method, path, query, body, empty, decode) {
|
|
157
|
+
let key;
|
|
158
|
+
try {
|
|
159
|
+
const resolved = await this.credentials.resolve(call, call.context.cancellationSignal);
|
|
160
|
+
if (!(resolved.apiKey instanceof SecretString)) throw new TypeError("API key is invalid");
|
|
161
|
+
key = resolved.apiKey.reveal();
|
|
162
|
+
if (!isHeaderSafeCredential(key)) throw new TypeError("API key is invalid");
|
|
163
|
+
} catch {
|
|
164
|
+
return failed(operation, "defect", empty, "AUTHENTICATION", "connection credentials are unavailable or invalid");
|
|
165
|
+
}
|
|
166
|
+
const encodedQuery = query.toString();
|
|
167
|
+
const request = {
|
|
168
|
+
url: `${this.baseUrl}${path}${encodedQuery ? `?${encodedQuery}` : ""}`,
|
|
169
|
+
method,
|
|
170
|
+
headers: { "xi-api-key": key, Accept: path.startsWith("/v1/text-to-speech/") ? "audio/mpeg" : "application/json", ...body ? { "Content-Type": "application/json" } : {} },
|
|
171
|
+
...body ? { body } : {},
|
|
172
|
+
maxResponseBytes: this.maxResponseBytes,
|
|
173
|
+
addressPolicy: this.baseUrl.startsWith("http://") ? "privateNetworkHTTP" : "publicHTTPS",
|
|
174
|
+
timeoutMs: this.timeoutMs,
|
|
175
|
+
signal: call.context.cancellationSignal
|
|
176
|
+
};
|
|
177
|
+
let response;
|
|
178
|
+
let isTooLarge = false;
|
|
179
|
+
try {
|
|
180
|
+
response = await this.send(request);
|
|
181
|
+
} catch (error) {
|
|
182
|
+
if (error instanceof BodyTooLargeError && error.status !== void 0) {
|
|
183
|
+
response = { status: error.status, headers: error.headers ?? {}, body: new Uint8Array() };
|
|
184
|
+
isTooLarge = true;
|
|
185
|
+
} else return newQueryRetry(failure(operation, "AVAILABILITY", "provider request failed"));
|
|
186
|
+
}
|
|
187
|
+
const status = response.status;
|
|
188
|
+
const retryAfter = parseRetryAfter(header(response, "retry-after"), this.now());
|
|
189
|
+
if (status === 429) return newQueryRetry(failure(operation, "RATE_LIMIT", "provider rate limited the request"), retryAfter);
|
|
190
|
+
if (status === 408 || status >= 500) return newQueryRetry(failure(operation, "AVAILABILITY", "provider is temporarily unavailable"), retryAfter);
|
|
191
|
+
if (status !== 200) return failed(operation, "providerRejected", empty, "PROVIDER_REJECTION", `provider rejected the request with HTTP ${status}`);
|
|
192
|
+
if (isTooLarge) return failed(operation, "invalidResponse", empty, "RESPONSE_TOO_LARGE", "provider response exceeded the configured limit");
|
|
193
|
+
try {
|
|
194
|
+
return newQueryBranch2(success, decode(response.body), {});
|
|
195
|
+
} catch {
|
|
196
|
+
return failed(operation, "invalidResponse", empty, "PROTOCOL", "provider returned an invalid response");
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
function header(response, name) {
|
|
201
|
+
const value = response.headers[name];
|
|
202
|
+
return Array.isArray(value) ? value[0] ?? "" : value ?? "";
|
|
203
|
+
}
|
|
204
|
+
function failure(operation, kind, message) {
|
|
205
|
+
return { kind, provider: "elevenlabs", operation, message };
|
|
206
|
+
}
|
|
207
|
+
function failed(operation, branch, empty, kind, message) {
|
|
208
|
+
return newQueryBranch2(branch, empty, {}, failure(operation, kind, message));
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// src/project.ts
|
|
212
|
+
function newProjectConnection2(project, connectionName) {
|
|
213
|
+
return newProjectConnection(project, connectionName, (loadedProject, name) => {
|
|
214
|
+
const selected = loadedProject.configuration.connections.find((entry) => entry.connectorId === "elevenlabs" && entry.connectionName === name);
|
|
215
|
+
if (!selected) throw new TypeError("ElevenLabs project connection is not configured");
|
|
216
|
+
const config = ConfigSchema.parse(selected.configuration);
|
|
217
|
+
const credentials = {
|
|
218
|
+
async resolve(_call, signal) {
|
|
219
|
+
const fields = await loadedProject.resolveCredential("elevenlabs", name, signal);
|
|
220
|
+
const decoded = z.object({ api_key: z.string().min(1) }).parse(fields);
|
|
221
|
+
return { apiKey: new SecretString2(decoded.api_key) };
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
return new ElevenLabsClient(config, credentials);
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
export {
|
|
228
|
+
ConfigSchema,
|
|
229
|
+
Connection,
|
|
230
|
+
ConnectorID,
|
|
231
|
+
CreateSpeechBranch,
|
|
232
|
+
CreateSpeechBranchCreated,
|
|
233
|
+
CreateSpeechBranchDefect,
|
|
234
|
+
CreateSpeechBranchInvalidResponse,
|
|
235
|
+
CreateSpeechBranchProviderRejected,
|
|
236
|
+
CreateSpeechDefinition,
|
|
237
|
+
CreateSpeechInputSchema,
|
|
238
|
+
CreateSpeechMetadata,
|
|
239
|
+
CreateSpeechOperation,
|
|
240
|
+
CreateSpeechOutputSchema,
|
|
241
|
+
ElevenLabsClient,
|
|
242
|
+
ListVoicesBranch,
|
|
243
|
+
ListVoicesBranchDefect,
|
|
244
|
+
ListVoicesBranchInvalidResponse,
|
|
245
|
+
ListVoicesBranchListed,
|
|
246
|
+
ListVoicesBranchProviderRejected,
|
|
247
|
+
ListVoicesDefinition,
|
|
248
|
+
ListVoicesInputSchema,
|
|
249
|
+
ListVoicesMetadata,
|
|
250
|
+
ListVoicesOperation,
|
|
251
|
+
ListVoicesOutputSchema,
|
|
252
|
+
ProviderID,
|
|
253
|
+
VoiceSchema,
|
|
254
|
+
newConnection,
|
|
255
|
+
newConnectionWithOperations,
|
|
256
|
+
newCreateSpeechStep,
|
|
257
|
+
newListVoicesStep,
|
|
258
|
+
newProjectConnection2 as newProjectConnection
|
|
259
|
+
};
|
package/dist/mock.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { MockQuery, Case } from '@superdurable/connectors-sdk/connectormock';
|
|
2
|
+
import { Failure } from '@superdurable/connectors-sdk';
|
|
3
|
+
import { O as Operations, b as Connection, L as ListVoicesInput, c as ListVoicesOutput, C as CreateSpeechInput, a as CreateSpeechOutput, V as Voice } from './connection-DFnhV-HC.js';
|
|
4
|
+
import 'zod';
|
|
5
|
+
|
|
6
|
+
/** Go zero value for ListVoicesInput in scripted cases. */
|
|
7
|
+
declare const emptyListVoicesInput: ListVoicesInput;
|
|
8
|
+
/** Go zero value for Voice in scripted cases. */
|
|
9
|
+
declare const emptyVoice: Voice;
|
|
10
|
+
/** Go zero value for ListVoicesOutput in scripted cases. */
|
|
11
|
+
declare const emptyListVoicesOutput: ListVoicesOutput;
|
|
12
|
+
/** Go zero value for CreateSpeechInput in scripted cases. */
|
|
13
|
+
declare const emptyCreateSpeechInput: CreateSpeechInput;
|
|
14
|
+
/** Go zero value for CreateSpeechOutput in scripted cases. */
|
|
15
|
+
declare const emptyCreateSpeechOutput: CreateSpeechOutput;
|
|
16
|
+
/** Script the listed branch. */
|
|
17
|
+
declare function listVoicesListed(value: ListVoicesOutput, failure?: Failure): Case<ListVoicesOutput>;
|
|
18
|
+
/** Script the providerRejected branch. */
|
|
19
|
+
declare function listVoicesProviderRejected(value: ListVoicesOutput, failure?: Failure): Case<ListVoicesOutput>;
|
|
20
|
+
/** Script the invalidResponse branch. */
|
|
21
|
+
declare function listVoicesInvalidResponse(value: ListVoicesOutput, failure?: Failure): Case<ListVoicesOutput>;
|
|
22
|
+
/** Script the defect branch. */
|
|
23
|
+
declare function listVoicesDefect(value: ListVoicesOutput, failure?: Failure): Case<ListVoicesOutput>;
|
|
24
|
+
/** Script a safe retry of listVoices. */
|
|
25
|
+
declare function listVoicesRetry(failure: Failure, retryAfterMs?: number): Case<ListVoicesOutput>;
|
|
26
|
+
/** Manifest scenario listedDefault for listVoices. */
|
|
27
|
+
declare function listVoicesListedDefault(): Case<ListVoicesOutput>;
|
|
28
|
+
/** Default listVoices scenario. */
|
|
29
|
+
declare function listVoicesDefault(): Case<ListVoicesOutput>;
|
|
30
|
+
/** Script the created branch. */
|
|
31
|
+
declare function createSpeechCreated(value: CreateSpeechOutput, failure?: Failure): Case<CreateSpeechOutput>;
|
|
32
|
+
/** Script the providerRejected branch. */
|
|
33
|
+
declare function createSpeechProviderRejected(value: CreateSpeechOutput, failure?: Failure): Case<CreateSpeechOutput>;
|
|
34
|
+
/** Script the invalidResponse branch. */
|
|
35
|
+
declare function createSpeechInvalidResponse(value: CreateSpeechOutput, failure?: Failure): Case<CreateSpeechOutput>;
|
|
36
|
+
/** Script the defect branch. */
|
|
37
|
+
declare function createSpeechDefect(value: CreateSpeechOutput, failure?: Failure): Case<CreateSpeechOutput>;
|
|
38
|
+
/** Script a safe retry of createSpeech. */
|
|
39
|
+
declare function createSpeechRetry(failure: Failure, retryAfterMs?: number): Case<CreateSpeechOutput>;
|
|
40
|
+
/** Manifest scenario createdDefault for createSpeech. */
|
|
41
|
+
declare function createSpeechCreatedDefault(): Case<CreateSpeechOutput>;
|
|
42
|
+
/** Default createSpeech scenario. */
|
|
43
|
+
declare function createSpeechDefault(): Case<CreateSpeechOutput>;
|
|
44
|
+
/** Scripted operations and manifest defaults for this connector. */
|
|
45
|
+
declare class GeneratedMock implements Operations {
|
|
46
|
+
#private;
|
|
47
|
+
constructor(connectionName: string);
|
|
48
|
+
connection(): Connection;
|
|
49
|
+
listVoices(): MockQuery<ListVoicesInput, ListVoicesOutput>;
|
|
50
|
+
createSpeech(): MockQuery<CreateSpeechInput, CreateSpeechOutput>;
|
|
51
|
+
assertNoFailures(): void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { GeneratedMock, createSpeechCreated, createSpeechCreatedDefault, createSpeechDefault, createSpeechDefect, createSpeechInvalidResponse, createSpeechProviderRejected, createSpeechRetry, emptyCreateSpeechInput, emptyCreateSpeechOutput, emptyListVoicesInput, emptyListVoicesOutput, emptyVoice, listVoicesDefault, listVoicesDefect, listVoicesInvalidResponse, listVoicesListed, listVoicesListedDefault, listVoicesProviderRejected, listVoicesRetry };
|
package/dist/mock.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CreateSpeechDefinition,
|
|
3
|
+
CreateSpeechInputSchema,
|
|
4
|
+
CreateSpeechOutputSchema,
|
|
5
|
+
ListVoicesDefinition,
|
|
6
|
+
ListVoicesInputSchema,
|
|
7
|
+
ListVoicesOutputSchema,
|
|
8
|
+
ProviderID,
|
|
9
|
+
VoiceSchema,
|
|
10
|
+
newConnectionWithOperations
|
|
11
|
+
} from "./chunk-GIQKY62E.js";
|
|
12
|
+
|
|
13
|
+
// src/generated/mock.ts
|
|
14
|
+
import { branchCase, retryCase, newQuery } from "@superdurable/connectors-sdk/connectormock";
|
|
15
|
+
var emptyListVoicesInput = ListVoicesInputSchema.parse({});
|
|
16
|
+
var emptyVoice = VoiceSchema.parse({
|
|
17
|
+
"voiceId": "",
|
|
18
|
+
"name": ""
|
|
19
|
+
});
|
|
20
|
+
var emptyListVoicesOutput = ListVoicesOutputSchema.parse({
|
|
21
|
+
"voices": [],
|
|
22
|
+
"hasMore": false
|
|
23
|
+
});
|
|
24
|
+
var emptyCreateSpeechInput = CreateSpeechInputSchema.parse({
|
|
25
|
+
"voiceId": "",
|
|
26
|
+
"text": ""
|
|
27
|
+
});
|
|
28
|
+
var emptyCreateSpeechOutput = CreateSpeechOutputSchema.parse({
|
|
29
|
+
"audioBase64": "",
|
|
30
|
+
"contentType": ""
|
|
31
|
+
});
|
|
32
|
+
function listVoicesListed(value, failure) {
|
|
33
|
+
return branchCase("listed", value, failure);
|
|
34
|
+
}
|
|
35
|
+
function listVoicesProviderRejected(value, failure) {
|
|
36
|
+
return branchCase("providerRejected", value, failure);
|
|
37
|
+
}
|
|
38
|
+
function listVoicesInvalidResponse(value, failure) {
|
|
39
|
+
return branchCase("invalidResponse", value, failure);
|
|
40
|
+
}
|
|
41
|
+
function listVoicesDefect(value, failure) {
|
|
42
|
+
return branchCase("defect", value, failure);
|
|
43
|
+
}
|
|
44
|
+
function listVoicesRetry(failure, retryAfterMs = 0) {
|
|
45
|
+
return retryCase(failure, retryAfterMs);
|
|
46
|
+
}
|
|
47
|
+
function listVoicesListedDefault() {
|
|
48
|
+
const value = ListVoicesOutputSchema.parse({ "hasMore": false, "voices": [{ "name": "Meridian Narrator", "voiceId": "voice_meridian" }] });
|
|
49
|
+
return branchCase("listed", value);
|
|
50
|
+
}
|
|
51
|
+
function listVoicesDefault() {
|
|
52
|
+
return listVoicesListedDefault();
|
|
53
|
+
}
|
|
54
|
+
function createSpeechCreated(value, failure) {
|
|
55
|
+
return branchCase("created", value, failure);
|
|
56
|
+
}
|
|
57
|
+
function createSpeechProviderRejected(value, failure) {
|
|
58
|
+
return branchCase("providerRejected", value, failure);
|
|
59
|
+
}
|
|
60
|
+
function createSpeechInvalidResponse(value, failure) {
|
|
61
|
+
return branchCase("invalidResponse", value, failure);
|
|
62
|
+
}
|
|
63
|
+
function createSpeechDefect(value, failure) {
|
|
64
|
+
return branchCase("defect", value, failure);
|
|
65
|
+
}
|
|
66
|
+
function createSpeechRetry(failure, retryAfterMs = 0) {
|
|
67
|
+
return retryCase(failure, retryAfterMs);
|
|
68
|
+
}
|
|
69
|
+
function createSpeechCreatedDefault() {
|
|
70
|
+
const value = CreateSpeechOutputSchema.parse({ "audioBase64": "SUQz", "contentType": "audio/mpeg" });
|
|
71
|
+
return branchCase("created", value);
|
|
72
|
+
}
|
|
73
|
+
function createSpeechDefault() {
|
|
74
|
+
return createSpeechCreatedDefault();
|
|
75
|
+
}
|
|
76
|
+
var GeneratedMock = class {
|
|
77
|
+
#listVoices;
|
|
78
|
+
#createSpeech;
|
|
79
|
+
#connection;
|
|
80
|
+
constructor(connectionName) {
|
|
81
|
+
this.#listVoices = newQuery(ListVoicesDefinition).default(listVoicesDefault());
|
|
82
|
+
this.#createSpeech = newQuery(CreateSpeechDefinition).default(createSpeechDefault());
|
|
83
|
+
this.#connection = newConnectionWithOperations(this, { provider: ProviderID, name: connectionName });
|
|
84
|
+
}
|
|
85
|
+
connection() {
|
|
86
|
+
return this.#connection;
|
|
87
|
+
}
|
|
88
|
+
listVoices() {
|
|
89
|
+
return this.#listVoices;
|
|
90
|
+
}
|
|
91
|
+
createSpeech() {
|
|
92
|
+
return this.#createSpeech;
|
|
93
|
+
}
|
|
94
|
+
assertNoFailures() {
|
|
95
|
+
this.#listVoices.assertNoFailures();
|
|
96
|
+
this.#createSpeech.assertNoFailures();
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
export {
|
|
100
|
+
GeneratedMock,
|
|
101
|
+
createSpeechCreated,
|
|
102
|
+
createSpeechCreatedDefault,
|
|
103
|
+
createSpeechDefault,
|
|
104
|
+
createSpeechDefect,
|
|
105
|
+
createSpeechInvalidResponse,
|
|
106
|
+
createSpeechProviderRejected,
|
|
107
|
+
createSpeechRetry,
|
|
108
|
+
emptyCreateSpeechInput,
|
|
109
|
+
emptyCreateSpeechOutput,
|
|
110
|
+
emptyListVoicesInput,
|
|
111
|
+
emptyListVoicesOutput,
|
|
112
|
+
emptyVoice,
|
|
113
|
+
listVoicesDefault,
|
|
114
|
+
listVoicesDefect,
|
|
115
|
+
listVoicesInvalidResponse,
|
|
116
|
+
listVoicesListed,
|
|
117
|
+
listVoicesListedDefault,
|
|
118
|
+
listVoicesProviderRejected,
|
|
119
|
+
listVoicesRetry
|
|
120
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superdurable/connector-elevenlabs",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "ElevenLabs voice listing and speech generation for Dex TypeScript applications",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/superdurable/dex-connectors-library.git",
|
|
8
|
+
"directory": "connectors/elevenlabs/typescript"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public",
|
|
13
|
+
"registry": "https://registry.npmjs.org"
|
|
14
|
+
},
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": "^22.0.0 || ^24.0.0"
|
|
17
|
+
},
|
|
18
|
+
"module": "./dist/index.js",
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./mock": {
|
|
26
|
+
"types": "./dist/mock.d.ts",
|
|
27
|
+
"import": "./dist/mock.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"README.md",
|
|
33
|
+
"LICENSE",
|
|
34
|
+
"dex-connector.json"
|
|
35
|
+
],
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsup src/index.ts src/mock.ts --format esm --dts --clean",
|
|
38
|
+
"typecheck": "tsc --noEmit",
|
|
39
|
+
"lint": "eslint src test examples",
|
|
40
|
+
"test": "vitest run --exclude test/integration/**",
|
|
41
|
+
"test:integration": "npm run build && vitest run test/integration/*.integration.test.ts",
|
|
42
|
+
"check": "npm run typecheck && npm run lint && npm test && npm run build",
|
|
43
|
+
"example:demo": "npm run build && tsx examples/demo/main.ts",
|
|
44
|
+
"example:demo:start": "npm run build && tsx examples/demo/start.ts"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@superdurable/connectors-sdk": "0.1.0",
|
|
48
|
+
"@superdurable/dex": ">=1.28.0",
|
|
49
|
+
"zod": "^4.1.0"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@eslint/js": "^9.0.0",
|
|
53
|
+
"@types/node": "^22.0.0",
|
|
54
|
+
"eslint": "^9.0.0",
|
|
55
|
+
"tsup": "^8.0.0",
|
|
56
|
+
"tsx": "^4.23.15",
|
|
57
|
+
"typescript": "^5.9.0",
|
|
58
|
+
"typescript-eslint": "^8.0.0",
|
|
59
|
+
"vitest": "^3.0.0",
|
|
60
|
+
"yaml": "^2.9.1"
|
|
61
|
+
},
|
|
62
|
+
"license": "MIT"
|
|
63
|
+
}
|