@ai-sdk/elevenlabs 3.0.0-beta.3 → 3.0.0-beta.30

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.
@@ -1,21 +1,21 @@
1
1
  import {
2
- TranscriptionModelV3,
3
- SpeechModelV3,
4
- ProviderV3,
5
2
  NoSuchModelError,
3
+ type TranscriptionModelV4,
4
+ type SpeechModelV4,
5
+ type ProviderV4,
6
6
  } from '@ai-sdk/provider';
7
7
  import {
8
- FetchFunction,
9
8
  loadApiKey,
10
9
  withUserAgentSuffix,
10
+ type FetchFunction,
11
11
  } from '@ai-sdk/provider-utils';
12
12
  import { ElevenLabsTranscriptionModel } from './elevenlabs-transcription-model';
13
- import { ElevenLabsTranscriptionModelId } from './elevenlabs-transcription-options';
13
+ import type { ElevenLabsTranscriptionModelId } from './elevenlabs-transcription-options';
14
14
  import { ElevenLabsSpeechModel } from './elevenlabs-speech-model';
15
- import { ElevenLabsSpeechModelId } from './elevenlabs-speech-options';
15
+ import type { ElevenLabsSpeechModelId } from './elevenlabs-speech-options';
16
16
  import { VERSION } from './version';
17
17
 
18
- export interface ElevenLabsProvider extends ProviderV3 {
18
+ export interface ElevenLabsProvider extends ProviderV4 {
19
19
  (
20
20
  modelId: 'scribe_v1',
21
21
  settings?: {},
@@ -26,12 +26,12 @@ export interface ElevenLabsProvider extends ProviderV3 {
26
26
  /**
27
27
  * Creates a model for transcription.
28
28
  */
29
- transcription(modelId: ElevenLabsTranscriptionModelId): TranscriptionModelV3;
29
+ transcription(modelId: ElevenLabsTranscriptionModelId): TranscriptionModelV4;
30
30
 
31
31
  /**
32
32
  * Creates a model for speech generation.
33
33
  */
34
- speech(modelId: ElevenLabsSpeechModelId): SpeechModelV3;
34
+ speech(modelId: ElevenLabsSpeechModelId): SpeechModelV4;
35
35
 
36
36
  /**
37
37
  * @deprecated Use `embeddingModel` instead.
@@ -98,7 +98,7 @@ export function createElevenLabs(
98
98
  };
99
99
  };
100
100
 
101
- provider.specificationVersion = 'v3' as const;
101
+ provider.specificationVersion = 'v4' as const;
102
102
  provider.transcription = createTranscriptionModel;
103
103
  provider.transcriptionModel = createTranscriptionModel;
104
104
  provider.speech = createSpeechModel;
@@ -1,15 +1,18 @@
1
- import { SpeechModelV3, SharedV3Warning } from '@ai-sdk/provider';
1
+ import type { SpeechModelV4, SharedV4Warning } from '@ai-sdk/provider';
2
2
  import {
3
3
  combineHeaders,
4
4
  createBinaryResponseHandler,
5
5
  parseProviderOptions,
6
6
  postJsonToApi,
7
+ serializeModelOptions,
8
+ WORKFLOW_SERIALIZE,
9
+ WORKFLOW_DESERIALIZE,
7
10
  } from '@ai-sdk/provider-utils';
8
11
  import { z } from 'zod/v4';
9
- import { ElevenLabsConfig } from './elevenlabs-config';
12
+ import type { ElevenLabsConfig } from './elevenlabs-config';
10
13
  import { elevenlabsFailedResponseHandler } from './elevenlabs-error';
11
- import { ElevenLabsSpeechAPITypes } from './elevenlabs-speech-api-types';
12
- import {
14
+ import type { ElevenLabsSpeechAPITypes } from './elevenlabs-speech-api-types';
15
+ import type {
13
16
  ElevenLabsSpeechModelId,
14
17
  ElevenLabsSpeechVoiceId,
15
18
  } from './elevenlabs-speech-options';
@@ -54,13 +57,27 @@ interface ElevenLabsSpeechModelConfig extends ElevenLabsConfig {
54
57
  };
55
58
  }
56
59
 
57
- export class ElevenLabsSpeechModel implements SpeechModelV3 {
58
- readonly specificationVersion = 'v3';
60
+ export class ElevenLabsSpeechModel implements SpeechModelV4 {
61
+ readonly specificationVersion = 'v4';
59
62
 
60
63
  get provider(): string {
61
64
  return this.config.provider;
62
65
  }
63
66
 
67
+ static [WORKFLOW_SERIALIZE](model: ElevenLabsSpeechModel) {
68
+ return serializeModelOptions({
69
+ modelId: model.modelId,
70
+ config: model.config,
71
+ });
72
+ }
73
+
74
+ static [WORKFLOW_DESERIALIZE](options: {
75
+ modelId: ElevenLabsSpeechModelId;
76
+ config: ElevenLabsSpeechModelConfig;
77
+ }) {
78
+ return new ElevenLabsSpeechModel(options.modelId, options.config);
79
+ }
80
+
64
81
  constructor(
65
82
  readonly modelId: ElevenLabsSpeechModelId,
66
83
  private readonly config: ElevenLabsSpeechModelConfig,
@@ -74,8 +91,8 @@ export class ElevenLabsSpeechModel implements SpeechModelV3 {
74
91
  language,
75
92
  speed,
76
93
  providerOptions,
77
- }: Parameters<SpeechModelV3['doGenerate']>[0]) {
78
- const warnings: SharedV3Warning[] = [];
94
+ }: Parameters<SpeechModelV4['doGenerate']>[0]) {
95
+ const warnings: SharedV4Warning[] = [];
79
96
 
80
97
  // Parse provider options
81
98
  const elevenLabsOptions = await parseProviderOptions({
@@ -214,8 +231,8 @@ export class ElevenLabsSpeechModel implements SpeechModelV3 {
214
231
  }
215
232
 
216
233
  async doGenerate(
217
- options: Parameters<SpeechModelV3['doGenerate']>[0],
218
- ): Promise<Awaited<ReturnType<SpeechModelV3['doGenerate']>>> {
234
+ options: Parameters<SpeechModelV4['doGenerate']>[0],
235
+ ): Promise<Awaited<ReturnType<SpeechModelV4['doGenerate']>>> {
219
236
  const currentDate = this.config._internal?.currentDate?.() ?? new Date();
220
237
  const { requestBody, queryParams, warnings, voiceId } =
221
238
  await this.getArgs(options);
@@ -233,7 +250,7 @@ export class ElevenLabsSpeechModel implements SpeechModelV3 {
233
250
  const queryString = new URLSearchParams(queryParams).toString();
234
251
  return queryString ? `${baseUrl}?${queryString}` : baseUrl;
235
252
  })(),
236
- headers: combineHeaders(this.config.headers(), options.headers),
253
+ headers: combineHeaders(this.config.headers?.(), options.headers),
237
254
  body: requestBody,
238
255
  failedResponseHandler: elevenlabsFailedResponseHandler,
239
256
  successfulResponseHandler: createBinaryResponseHandler(),
@@ -1,4 +1,4 @@
1
- import { TranscriptionModelV3, SharedV3Warning } from '@ai-sdk/provider';
1
+ import type { TranscriptionModelV4, SharedV4Warning } from '@ai-sdk/provider';
2
2
  import {
3
3
  combineHeaders,
4
4
  convertBase64ToUint8Array,
@@ -6,12 +6,15 @@ import {
6
6
  mediaTypeToExtension,
7
7
  parseProviderOptions,
8
8
  postFormDataToApi,
9
+ serializeModelOptions,
10
+ WORKFLOW_SERIALIZE,
11
+ WORKFLOW_DESERIALIZE,
9
12
  } from '@ai-sdk/provider-utils';
10
13
  import { z } from 'zod/v4';
11
- import { ElevenLabsConfig } from './elevenlabs-config';
14
+ import type { ElevenLabsConfig } from './elevenlabs-config';
12
15
  import { elevenlabsFailedResponseHandler } from './elevenlabs-error';
13
- import { ElevenLabsTranscriptionModelId } from './elevenlabs-transcription-options';
14
- import { ElevenLabsTranscriptionAPITypes } from './elevenlabs-api-types';
16
+ import type { ElevenLabsTranscriptionModelId } from './elevenlabs-transcription-options';
17
+ import type { ElevenLabsTranscriptionAPITypes } from './elevenlabs-api-types';
15
18
 
16
19
  // https://elevenlabs.io/docs/api-reference/speech-to-text/convert
17
20
  const elevenLabsTranscriptionModelOptionsSchema = z.object({
@@ -36,13 +39,27 @@ interface ElevenLabsTranscriptionModelConfig extends ElevenLabsConfig {
36
39
  };
37
40
  }
38
41
 
39
- export class ElevenLabsTranscriptionModel implements TranscriptionModelV3 {
40
- readonly specificationVersion = 'v3';
42
+ export class ElevenLabsTranscriptionModel implements TranscriptionModelV4 {
43
+ readonly specificationVersion = 'v4';
41
44
 
42
45
  get provider(): string {
43
46
  return this.config.provider;
44
47
  }
45
48
 
49
+ static [WORKFLOW_SERIALIZE](model: ElevenLabsTranscriptionModel) {
50
+ return serializeModelOptions({
51
+ modelId: model.modelId,
52
+ config: model.config,
53
+ });
54
+ }
55
+
56
+ static [WORKFLOW_DESERIALIZE](options: {
57
+ modelId: ElevenLabsTranscriptionModelId;
58
+ config: ElevenLabsTranscriptionModelConfig;
59
+ }) {
60
+ return new ElevenLabsTranscriptionModel(options.modelId, options.config);
61
+ }
62
+
46
63
  constructor(
47
64
  readonly modelId: ElevenLabsTranscriptionModelId,
48
65
  private readonly config: ElevenLabsTranscriptionModelConfig,
@@ -52,8 +69,8 @@ export class ElevenLabsTranscriptionModel implements TranscriptionModelV3 {
52
69
  audio,
53
70
  mediaType,
54
71
  providerOptions,
55
- }: Parameters<TranscriptionModelV3['doGenerate']>[0]) {
56
- const warnings: SharedV3Warning[] = [];
72
+ }: Parameters<TranscriptionModelV4['doGenerate']>[0]) {
73
+ const warnings: SharedV4Warning[] = [];
57
74
 
58
75
  // Parse provider options
59
76
  const elevenlabsOptions = await parseProviderOptions({
@@ -111,8 +128,8 @@ export class ElevenLabsTranscriptionModel implements TranscriptionModelV3 {
111
128
  }
112
129
 
113
130
  async doGenerate(
114
- options: Parameters<TranscriptionModelV3['doGenerate']>[0],
115
- ): Promise<Awaited<ReturnType<TranscriptionModelV3['doGenerate']>>> {
131
+ options: Parameters<TranscriptionModelV4['doGenerate']>[0],
132
+ ): Promise<Awaited<ReturnType<TranscriptionModelV4['doGenerate']>>> {
116
133
  const currentDate = this.config._internal?.currentDate?.() ?? new Date();
117
134
  const { formData, warnings } = await this.getArgs(options);
118
135
 
@@ -125,7 +142,7 @@ export class ElevenLabsTranscriptionModel implements TranscriptionModelV3 {
125
142
  path: '/v1/speech-to-text',
126
143
  modelId: this.modelId,
127
144
  }),
128
- headers: combineHeaders(this.config.headers(), options.headers),
145
+ headers: combineHeaders(this.config.headers?.(), options.headers),
129
146
  formData,
130
147
  failedResponseHandler: elevenlabsFailedResponseHandler,
131
148
  successfulResponseHandler: createJsonResponseHandler(
package/dist/index.d.mts DELETED
@@ -1,122 +0,0 @@
1
- import { TranscriptionModelV3, ProviderV3, SpeechModelV3 } from '@ai-sdk/provider';
2
- import { FetchFunction } from '@ai-sdk/provider-utils';
3
- import { z } from 'zod/v4';
4
-
5
- type ElevenLabsConfig = {
6
- provider: string;
7
- url: (options: {
8
- modelId: string;
9
- path: string;
10
- }) => string;
11
- headers: () => Record<string, string | undefined>;
12
- fetch?: FetchFunction;
13
- generateId?: () => string;
14
- };
15
-
16
- type ElevenLabsTranscriptionModelId = 'scribe_v1' | 'scribe_v1_experimental' | (string & {});
17
-
18
- declare const elevenLabsTranscriptionModelOptionsSchema: z.ZodObject<{
19
- languageCode: z.ZodOptional<z.ZodNullable<z.ZodString>>;
20
- tagAudioEvents: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodBoolean>>>;
21
- numSpeakers: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
22
- timestampsGranularity: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodEnum<{
23
- none: "none";
24
- word: "word";
25
- character: "character";
26
- }>>>>;
27
- diarize: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodBoolean>>>;
28
- fileFormat: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodEnum<{
29
- pcm_s16le_16: "pcm_s16le_16";
30
- other: "other";
31
- }>>>>;
32
- }, z.core.$strip>;
33
- type ElevenLabsTranscriptionModelOptions = z.infer<typeof elevenLabsTranscriptionModelOptionsSchema>;
34
- interface ElevenLabsTranscriptionModelConfig extends ElevenLabsConfig {
35
- _internal?: {
36
- currentDate?: () => Date;
37
- };
38
- }
39
- declare class ElevenLabsTranscriptionModel implements TranscriptionModelV3 {
40
- readonly modelId: ElevenLabsTranscriptionModelId;
41
- private readonly config;
42
- readonly specificationVersion = "v3";
43
- get provider(): string;
44
- constructor(modelId: ElevenLabsTranscriptionModelId, config: ElevenLabsTranscriptionModelConfig);
45
- private getArgs;
46
- doGenerate(options: Parameters<TranscriptionModelV3['doGenerate']>[0]): Promise<Awaited<ReturnType<TranscriptionModelV3['doGenerate']>>>;
47
- }
48
-
49
- type ElevenLabsSpeechModelId = 'eleven_v3' | 'eleven_multilingual_v2' | 'eleven_flash_v2_5' | 'eleven_flash_v2' | 'eleven_turbo_v2_5' | 'eleven_turbo_v2' | 'eleven_monolingual_v1' | 'eleven_multilingual_v1' | (string & {});
50
- type ElevenLabsSpeechVoiceId = string;
51
-
52
- interface ElevenLabsProvider extends ProviderV3 {
53
- (modelId: 'scribe_v1', settings?: {}): {
54
- transcription: ElevenLabsTranscriptionModel;
55
- };
56
- /**
57
- * Creates a model for transcription.
58
- */
59
- transcription(modelId: ElevenLabsTranscriptionModelId): TranscriptionModelV3;
60
- /**
61
- * Creates a model for speech generation.
62
- */
63
- speech(modelId: ElevenLabsSpeechModelId): SpeechModelV3;
64
- /**
65
- * @deprecated Use `embeddingModel` instead.
66
- */
67
- textEmbeddingModel(modelId: string): never;
68
- }
69
- interface ElevenLabsProviderSettings {
70
- /**
71
- * API key for authenticating requests.
72
- */
73
- apiKey?: string;
74
- /**
75
- * Custom headers to include in the requests.
76
- */
77
- headers?: Record<string, string>;
78
- /**
79
- * Custom fetch implementation. You can use it as a middleware to intercept requests,
80
- * or to provide a custom fetch implementation for e.g. testing.
81
- */
82
- fetch?: FetchFunction;
83
- }
84
- /**
85
- * Create an ElevenLabs provider instance.
86
- */
87
- declare function createElevenLabs(options?: ElevenLabsProviderSettings): ElevenLabsProvider;
88
- /**
89
- * Default ElevenLabs provider instance.
90
- */
91
- declare const elevenlabs: ElevenLabsProvider;
92
-
93
- declare const elevenLabsSpeechModelOptionsSchema: z.ZodObject<{
94
- languageCode: z.ZodOptional<z.ZodString>;
95
- voiceSettings: z.ZodOptional<z.ZodObject<{
96
- stability: z.ZodOptional<z.ZodNumber>;
97
- similarityBoost: z.ZodOptional<z.ZodNumber>;
98
- style: z.ZodOptional<z.ZodNumber>;
99
- useSpeakerBoost: z.ZodOptional<z.ZodBoolean>;
100
- }, z.core.$strip>>;
101
- pronunciationDictionaryLocators: z.ZodOptional<z.ZodArray<z.ZodObject<{
102
- pronunciationDictionaryId: z.ZodString;
103
- versionId: z.ZodOptional<z.ZodString>;
104
- }, z.core.$strip>>>;
105
- seed: z.ZodOptional<z.ZodNumber>;
106
- previousText: z.ZodOptional<z.ZodString>;
107
- nextText: z.ZodOptional<z.ZodString>;
108
- previousRequestIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
109
- nextRequestIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
110
- applyTextNormalization: z.ZodOptional<z.ZodEnum<{
111
- auto: "auto";
112
- on: "on";
113
- off: "off";
114
- }>>;
115
- applyLanguageTextNormalization: z.ZodOptional<z.ZodBoolean>;
116
- enableLogging: z.ZodOptional<z.ZodBoolean>;
117
- }, z.core.$strip>;
118
- type ElevenLabsSpeechModelOptions = z.infer<typeof elevenLabsSpeechModelOptionsSchema>;
119
-
120
- declare const VERSION: string;
121
-
122
- export { type ElevenLabsProvider, type ElevenLabsProviderSettings, type ElevenLabsSpeechModelId, type ElevenLabsSpeechModelOptions, type ElevenLabsSpeechVoiceId, type ElevenLabsTranscriptionModelOptions, VERSION, createElevenLabs, elevenlabs };