@ai-sdk/revai 3.0.0-beta.4 → 3.0.0-beta.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  AISDKError,
3
- TranscriptionModelV4,
4
- SharedV4Warning,
3
+ type TranscriptionModelV4,
4
+ type SharedV4Warning,
5
5
  } from '@ai-sdk/provider';
6
6
  import {
7
7
  combineHeaders,
@@ -12,207 +12,16 @@ import {
12
12
  getFromApi,
13
13
  parseProviderOptions,
14
14
  postFormDataToApi,
15
+ serializeModelOptions,
16
+ WORKFLOW_SERIALIZE,
17
+ WORKFLOW_DESERIALIZE,
15
18
  } from '@ai-sdk/provider-utils';
16
19
  import { z } from 'zod/v4';
17
- import { RevaiConfig } from './revai-config';
20
+ import type { RevaiConfig } from './revai-config';
18
21
  import { revaiFailedResponseHandler } from './revai-error';
19
- import { RevaiTranscriptionModelId } from './revai-transcription-options';
20
- import { RevaiTranscriptionAPITypes } from './revai-api-types';
21
-
22
- // https://docs.rev.ai/api/asynchronous/reference/#operation/SubmitTranscriptionJob
23
- const revaiTranscriptionModelOptionsSchema = z.object({
24
- /**
25
- * Optional metadata string to associate with the transcription job.
26
- */
27
- metadata: z.string().nullish(),
28
- /**
29
- * Configuration for webhook notifications when job is complete.
30
- */
31
- notification_config: z
32
- .object({
33
- /**
34
- * URL to send the notification to.
35
- */
36
- url: z.string(),
37
- /**
38
- * Optional authorization headers for the notification request.
39
- */
40
- auth_headers: z
41
- .object({
42
- Authorization: z.string(),
43
- })
44
- .nullish(),
45
- })
46
- .nullish(),
47
- /**
48
- * Number of seconds after which the job will be automatically deleted.
49
- */
50
- delete_after_seconds: z.number().nullish(),
51
- /**
52
- * Whether to include filler words and false starts in the transcription.
53
- */
54
- verbatim: z.boolean().optional(),
55
- /**
56
- * Whether to prioritize the job for faster processing.
57
- */
58
- rush: z.boolean().nullish().default(false),
59
- /**
60
- * Whether to run the job in test mode.
61
- */
62
- test_mode: z.boolean().nullish().default(false),
63
- /**
64
- * Specific segments of the audio to transcribe.
65
- */
66
- segments_to_transcribe: z
67
- .array(
68
- z.object({
69
- /**
70
- * Start time of the segment in seconds.
71
- */
72
- start: z.number(),
73
- /**
74
- * End time of the segment in seconds.
75
- */
76
- end: z.number(),
77
- }),
78
- )
79
- .nullish(),
80
- /**
81
- * Names to assign to speakers in the transcription.
82
- */
83
- speaker_names: z
84
- .array(
85
- z.object({
86
- /**
87
- * Display name for the speaker.
88
- */
89
- display_name: z.string(),
90
- }),
91
- )
92
- .nullish(),
93
- /**
94
- * Whether to skip speaker diarization.
95
- */
96
- skip_diarization: z.boolean().nullish().default(false),
97
- /**
98
- * Whether to skip post-processing steps.
99
- */
100
- skip_postprocessing: z.boolean().nullish().default(false),
101
- /**
102
- * Whether to skip adding punctuation to the transcription.
103
- */
104
- skip_punctuation: z.boolean().nullish().default(false),
105
- /**
106
- * Whether to remove disfluencies (um, uh, etc.) from the transcription.
107
- */
108
- remove_disfluencies: z.boolean().nullish().default(false),
109
- /**
110
- * Whether to remove atmospheric sounds from the transcription.
111
- */
112
- remove_atmospherics: z.boolean().nullish().default(false),
113
- /**
114
- * Whether to filter profanity from the transcription.
115
- */
116
- filter_profanity: z.boolean().nullish().default(false),
117
- /**
118
- * Number of speaker channels in the audio.
119
- */
120
- speaker_channels_count: z.number().nullish(),
121
- /**
122
- * Expected number of speakers in the audio.
123
- */
124
- speakers_count: z.number().nullish(),
125
- /**
126
- * Type of diarization to use.
127
- */
128
- diarization_type: z
129
- .enum(['standard', 'premium'])
130
- .nullish()
131
- .default('standard'),
132
- /**
133
- * ID of a custom vocabulary to use for the transcription.
134
- */
135
- custom_vocabulary_id: z.string().nullish(),
136
- /**
137
- * Custom vocabularies to use for the transcription.
138
- */
139
- custom_vocabularies: z.array(z.object({})).optional(),
140
- /**
141
- * Whether to strictly enforce custom vocabulary.
142
- */
143
- strict_custom_vocabulary: z.boolean().optional(),
144
- /**
145
- * Configuration for generating a summary of the transcription.
146
- */
147
- summarization_config: z
148
- .object({
149
- /**
150
- * Model to use for summarization.
151
- */
152
- model: z.enum(['standard', 'premium']).nullish().default('standard'),
153
- /**
154
- * Format of the summary.
155
- */
156
- type: z.enum(['paragraph', 'bullets']).nullish().default('paragraph'),
157
- /**
158
- * Custom prompt for the summarization.
159
- */
160
- prompt: z.string().nullish(),
161
- })
162
- .nullish(),
163
- /**
164
- * Configuration for translating the transcription.
165
- */
166
- translation_config: z
167
- .object({
168
- /**
169
- * Target languages for translation.
170
- */
171
- target_languages: z.array(
172
- z.object({
173
- /**
174
- * Language code for translation target.
175
- */
176
- language: z.enum([
177
- 'en',
178
- 'en-us',
179
- 'en-gb',
180
- 'ar',
181
- 'pt',
182
- 'pt-br',
183
- 'pt-pt',
184
- 'fr',
185
- 'fr-ca',
186
- 'es',
187
- 'es-es',
188
- 'es-la',
189
- 'it',
190
- 'ja',
191
- 'ko',
192
- 'de',
193
- 'ru',
194
- ]),
195
- }),
196
- ),
197
- /**
198
- * Model to use for translation.
199
- */
200
- model: z.enum(['standard', 'premium']).nullish().default('standard'),
201
- })
202
- .nullish(),
203
- /**
204
- * Language of the audio content.
205
- */
206
- language: z.string().nullish().default('en'),
207
- /**
208
- * Whether to perform forced alignment.
209
- */
210
- forced_alignment: z.boolean().nullish().default(false),
211
- });
212
-
213
- export type RevaiTranscriptionModelOptions = z.infer<
214
- typeof revaiTranscriptionModelOptionsSchema
215
- >;
22
+ import { revaiTranscriptionModelOptionsSchema } from './revai-transcription-model-options';
23
+ import type { RevaiTranscriptionModelId } from './revai-transcription-options';
24
+ import type { RevaiTranscriptionAPITypes } from './revai-api-types';
216
25
 
217
26
  interface RevaiTranscriptionModelConfig extends RevaiConfig {
218
27
  _internal?: {
@@ -227,6 +36,20 @@ export class RevaiTranscriptionModel implements TranscriptionModelV4 {
227
36
  return this.config.provider;
228
37
  }
229
38
 
39
+ static [WORKFLOW_SERIALIZE](model: RevaiTranscriptionModel) {
40
+ return serializeModelOptions({
41
+ modelId: model.modelId,
42
+ config: model.config,
43
+ });
44
+ }
45
+
46
+ static [WORKFLOW_DESERIALIZE](options: {
47
+ modelId: RevaiTranscriptionModelId;
48
+ config: RevaiTranscriptionModelConfig;
49
+ }) {
50
+ return new RevaiTranscriptionModel(options.modelId, options.config);
51
+ }
52
+
230
53
  constructor(
231
54
  readonly modelId: RevaiTranscriptionModelId,
232
55
  private readonly config: RevaiTranscriptionModelConfig,
@@ -324,7 +147,7 @@ export class RevaiTranscriptionModel implements TranscriptionModelV4 {
324
147
  path: '/speechtotext/v1/jobs',
325
148
  modelId: this.modelId,
326
149
  }),
327
- headers: combineHeaders(this.config.headers(), options.headers),
150
+ headers: combineHeaders(this.config.headers?.(), options.headers),
328
151
  formData,
329
152
  failedResponseHandler: revaiFailedResponseHandler,
330
153
  successfulResponseHandler: createJsonResponseHandler(
@@ -364,7 +187,7 @@ export class RevaiTranscriptionModel implements TranscriptionModelV4 {
364
187
  path: `/speechtotext/v1/jobs/${jobId}`,
365
188
  modelId: this.modelId,
366
189
  }),
367
- headers: combineHeaders(this.config.headers(), options.headers),
190
+ headers: combineHeaders(this.config.headers?.(), options.headers),
368
191
  failedResponseHandler: revaiFailedResponseHandler,
369
192
  successfulResponseHandler: createJsonResponseHandler(
370
193
  revaiTranscriptionJobResponseSchema,
@@ -398,7 +221,7 @@ export class RevaiTranscriptionModel implements TranscriptionModelV4 {
398
221
  path: `/speechtotext/v1/jobs/${jobId}/transcript`,
399
222
  modelId: this.modelId,
400
223
  }),
401
- headers: combineHeaders(this.config.headers(), options.headers),
224
+ headers: combineHeaders(this.config.headers?.(), options.headers),
402
225
  failedResponseHandler: revaiFailedResponseHandler,
403
226
  successfulResponseHandler: createJsonResponseHandler(
404
227
  revaiTranscriptionResponseSchema,
package/dist/index.d.mts DELETED
@@ -1,148 +0,0 @@
1
- import { TranscriptionModelV4, ProviderV4 } from '@ai-sdk/provider';
2
- import { FetchFunction } from '@ai-sdk/provider-utils';
3
- import { z } from 'zod/v4';
4
-
5
- type RevaiConfig = {
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 RevaiTranscriptionModelId = 'machine' | 'low_cost' | 'fusion';
17
-
18
- declare const revaiTranscriptionModelOptionsSchema: z.ZodObject<{
19
- metadata: z.ZodOptional<z.ZodNullable<z.ZodString>>;
20
- notification_config: z.ZodOptional<z.ZodNullable<z.ZodObject<{
21
- url: z.ZodString;
22
- auth_headers: z.ZodOptional<z.ZodNullable<z.ZodObject<{
23
- Authorization: z.ZodString;
24
- }, z.core.$strip>>>;
25
- }, z.core.$strip>>>;
26
- delete_after_seconds: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
27
- verbatim: z.ZodOptional<z.ZodBoolean>;
28
- rush: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodBoolean>>>;
29
- test_mode: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodBoolean>>>;
30
- segments_to_transcribe: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
31
- start: z.ZodNumber;
32
- end: z.ZodNumber;
33
- }, z.core.$strip>>>>;
34
- speaker_names: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodObject<{
35
- display_name: z.ZodString;
36
- }, z.core.$strip>>>>;
37
- skip_diarization: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodBoolean>>>;
38
- skip_postprocessing: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodBoolean>>>;
39
- skip_punctuation: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodBoolean>>>;
40
- remove_disfluencies: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodBoolean>>>;
41
- remove_atmospherics: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodBoolean>>>;
42
- filter_profanity: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodBoolean>>>;
43
- speaker_channels_count: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
44
- speakers_count: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
45
- diarization_type: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodEnum<{
46
- standard: "standard";
47
- premium: "premium";
48
- }>>>>;
49
- custom_vocabulary_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
50
- custom_vocabularies: z.ZodOptional<z.ZodArray<z.ZodObject<{}, z.core.$strip>>>;
51
- strict_custom_vocabulary: z.ZodOptional<z.ZodBoolean>;
52
- summarization_config: z.ZodOptional<z.ZodNullable<z.ZodObject<{
53
- model: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodEnum<{
54
- standard: "standard";
55
- premium: "premium";
56
- }>>>>;
57
- type: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodEnum<{
58
- paragraph: "paragraph";
59
- bullets: "bullets";
60
- }>>>>;
61
- prompt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
62
- }, z.core.$strip>>>;
63
- translation_config: z.ZodOptional<z.ZodNullable<z.ZodObject<{
64
- target_languages: z.ZodArray<z.ZodObject<{
65
- language: z.ZodEnum<{
66
- en: "en";
67
- "en-us": "en-us";
68
- "en-gb": "en-gb";
69
- ar: "ar";
70
- pt: "pt";
71
- "pt-br": "pt-br";
72
- "pt-pt": "pt-pt";
73
- fr: "fr";
74
- "fr-ca": "fr-ca";
75
- es: "es";
76
- "es-es": "es-es";
77
- "es-la": "es-la";
78
- it: "it";
79
- ja: "ja";
80
- ko: "ko";
81
- de: "de";
82
- ru: "ru";
83
- }>;
84
- }, z.core.$strip>>;
85
- model: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodEnum<{
86
- standard: "standard";
87
- premium: "premium";
88
- }>>>>;
89
- }, z.core.$strip>>>;
90
- language: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
91
- forced_alignment: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodBoolean>>>;
92
- }, z.core.$strip>;
93
- type RevaiTranscriptionModelOptions = z.infer<typeof revaiTranscriptionModelOptionsSchema>;
94
- interface RevaiTranscriptionModelConfig extends RevaiConfig {
95
- _internal?: {
96
- currentDate?: () => Date;
97
- };
98
- }
99
- declare class RevaiTranscriptionModel implements TranscriptionModelV4 {
100
- readonly modelId: RevaiTranscriptionModelId;
101
- private readonly config;
102
- readonly specificationVersion = "v4";
103
- get provider(): string;
104
- constructor(modelId: RevaiTranscriptionModelId, config: RevaiTranscriptionModelConfig);
105
- private getArgs;
106
- doGenerate(options: Parameters<TranscriptionModelV4['doGenerate']>[0]): Promise<Awaited<ReturnType<TranscriptionModelV4['doGenerate']>>>;
107
- }
108
-
109
- interface RevaiProvider extends ProviderV4 {
110
- (modelId: 'machine', settings?: {}): {
111
- transcription: RevaiTranscriptionModel;
112
- };
113
- /**
114
- * Creates a model for transcription.
115
- */
116
- transcription(modelId: RevaiTranscriptionModelId): TranscriptionModelV4;
117
- /**
118
- * @deprecated Use `embeddingModel` instead.
119
- */
120
- textEmbeddingModel(modelId: string): never;
121
- }
122
- interface RevaiProviderSettings {
123
- /**
124
- * API key for authenticating requests.
125
- */
126
- apiKey?: string;
127
- /**
128
- * Custom headers to include in the requests.
129
- */
130
- headers?: Record<string, string>;
131
- /**
132
- * Custom fetch implementation. You can use it as a middleware to intercept requests,
133
- * or to provide a custom fetch implementation for e.g. testing.
134
- */
135
- fetch?: FetchFunction;
136
- }
137
- /**
138
- * Create a Rev.ai provider instance.
139
- */
140
- declare function createRevai(options?: RevaiProviderSettings): RevaiProvider;
141
- /**
142
- * Default Rev.ai provider instance.
143
- */
144
- declare const revai: RevaiProvider;
145
-
146
- declare const VERSION: string;
147
-
148
- export { type RevaiProvider, type RevaiProviderSettings, type RevaiTranscriptionModelOptions, VERSION, createRevai, revai };