@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.
package/dist/index.js CHANGED
@@ -1,195 +1,187 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- VERSION: () => VERSION,
24
- createRevai: () => createRevai,
25
- revai: () => revai
26
- });
27
- module.exports = __toCommonJS(index_exports);
28
-
29
1
  // src/revai-provider.ts
30
- var import_provider2 = require("@ai-sdk/provider");
31
- var import_provider_utils3 = require("@ai-sdk/provider-utils");
2
+ import {
3
+ NoSuchModelError
4
+ } from "@ai-sdk/provider";
5
+ import {
6
+ loadApiKey,
7
+ withUserAgentSuffix
8
+ } from "@ai-sdk/provider-utils";
32
9
 
33
10
  // src/revai-transcription-model.ts
34
- var import_provider = require("@ai-sdk/provider");
35
- var import_provider_utils2 = require("@ai-sdk/provider-utils");
36
- var import_v42 = require("zod/v4");
11
+ import {
12
+ AISDKError
13
+ } from "@ai-sdk/provider";
14
+ import {
15
+ combineHeaders,
16
+ convertBase64ToUint8Array,
17
+ createJsonResponseHandler,
18
+ mediaTypeToExtension,
19
+ delay,
20
+ getFromApi,
21
+ parseProviderOptions,
22
+ postFormDataToApi,
23
+ serializeModelOptions,
24
+ WORKFLOW_SERIALIZE,
25
+ WORKFLOW_DESERIALIZE
26
+ } from "@ai-sdk/provider-utils";
27
+ import { z as z3 } from "zod/v4";
37
28
 
38
29
  // src/revai-error.ts
39
- var import_v4 = require("zod/v4");
40
- var import_provider_utils = require("@ai-sdk/provider-utils");
41
- var revaiErrorDataSchema = import_v4.z.object({
42
- error: import_v4.z.object({
43
- message: import_v4.z.string(),
44
- code: import_v4.z.number()
30
+ import { z } from "zod/v4";
31
+ import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
32
+ var revaiErrorDataSchema = z.object({
33
+ error: z.object({
34
+ message: z.string(),
35
+ code: z.number()
45
36
  })
46
37
  });
47
- var revaiFailedResponseHandler = (0, import_provider_utils.createJsonErrorResponseHandler)({
38
+ var revaiFailedResponseHandler = createJsonErrorResponseHandler({
48
39
  errorSchema: revaiErrorDataSchema,
49
40
  errorToMessage: (data) => data.error.message
50
41
  });
51
42
 
52
- // src/revai-transcription-model.ts
53
- var revaiTranscriptionModelOptionsSchema = import_v42.z.object({
43
+ // src/revai-transcription-model-options.ts
44
+ import { z as z2 } from "zod/v4";
45
+ var revaiTranscriptionModelOptionsSchema = z2.object({
54
46
  /**
55
47
  * Optional metadata string to associate with the transcription job.
56
48
  */
57
- metadata: import_v42.z.string().nullish(),
49
+ metadata: z2.string().nullish(),
58
50
  /**
59
51
  * Configuration for webhook notifications when job is complete.
60
52
  */
61
- notification_config: import_v42.z.object({
53
+ notification_config: z2.object({
62
54
  /**
63
55
  * URL to send the notification to.
64
56
  */
65
- url: import_v42.z.string(),
57
+ url: z2.string(),
66
58
  /**
67
59
  * Optional authorization headers for the notification request.
68
60
  */
69
- auth_headers: import_v42.z.object({
70
- Authorization: import_v42.z.string()
61
+ auth_headers: z2.object({
62
+ Authorization: z2.string()
71
63
  }).nullish()
72
64
  }).nullish(),
73
65
  /**
74
66
  * Number of seconds after which the job will be automatically deleted.
75
67
  */
76
- delete_after_seconds: import_v42.z.number().nullish(),
68
+ delete_after_seconds: z2.number().nullish(),
77
69
  /**
78
70
  * Whether to include filler words and false starts in the transcription.
79
71
  */
80
- verbatim: import_v42.z.boolean().optional(),
72
+ verbatim: z2.boolean().optional(),
81
73
  /**
82
74
  * Whether to prioritize the job for faster processing.
83
75
  */
84
- rush: import_v42.z.boolean().nullish().default(false),
76
+ rush: z2.boolean().nullish().default(false),
85
77
  /**
86
78
  * Whether to run the job in test mode.
87
79
  */
88
- test_mode: import_v42.z.boolean().nullish().default(false),
80
+ test_mode: z2.boolean().nullish().default(false),
89
81
  /**
90
82
  * Specific segments of the audio to transcribe.
91
83
  */
92
- segments_to_transcribe: import_v42.z.array(
93
- import_v42.z.object({
84
+ segments_to_transcribe: z2.array(
85
+ z2.object({
94
86
  /**
95
87
  * Start time of the segment in seconds.
96
88
  */
97
- start: import_v42.z.number(),
89
+ start: z2.number(),
98
90
  /**
99
91
  * End time of the segment in seconds.
100
92
  */
101
- end: import_v42.z.number()
93
+ end: z2.number()
102
94
  })
103
95
  ).nullish(),
104
96
  /**
105
97
  * Names to assign to speakers in the transcription.
106
98
  */
107
- speaker_names: import_v42.z.array(
108
- import_v42.z.object({
99
+ speaker_names: z2.array(
100
+ z2.object({
109
101
  /**
110
102
  * Display name for the speaker.
111
103
  */
112
- display_name: import_v42.z.string()
104
+ display_name: z2.string()
113
105
  })
114
106
  ).nullish(),
115
107
  /**
116
108
  * Whether to skip speaker diarization.
117
109
  */
118
- skip_diarization: import_v42.z.boolean().nullish().default(false),
110
+ skip_diarization: z2.boolean().nullish().default(false),
119
111
  /**
120
112
  * Whether to skip post-processing steps.
121
113
  */
122
- skip_postprocessing: import_v42.z.boolean().nullish().default(false),
114
+ skip_postprocessing: z2.boolean().nullish().default(false),
123
115
  /**
124
116
  * Whether to skip adding punctuation to the transcription.
125
117
  */
126
- skip_punctuation: import_v42.z.boolean().nullish().default(false),
118
+ skip_punctuation: z2.boolean().nullish().default(false),
127
119
  /**
128
120
  * Whether to remove disfluencies (um, uh, etc.) from the transcription.
129
121
  */
130
- remove_disfluencies: import_v42.z.boolean().nullish().default(false),
122
+ remove_disfluencies: z2.boolean().nullish().default(false),
131
123
  /**
132
124
  * Whether to remove atmospheric sounds from the transcription.
133
125
  */
134
- remove_atmospherics: import_v42.z.boolean().nullish().default(false),
126
+ remove_atmospherics: z2.boolean().nullish().default(false),
135
127
  /**
136
128
  * Whether to filter profanity from the transcription.
137
129
  */
138
- filter_profanity: import_v42.z.boolean().nullish().default(false),
130
+ filter_profanity: z2.boolean().nullish().default(false),
139
131
  /**
140
132
  * Number of speaker channels in the audio.
141
133
  */
142
- speaker_channels_count: import_v42.z.number().nullish(),
134
+ speaker_channels_count: z2.number().nullish(),
143
135
  /**
144
136
  * Expected number of speakers in the audio.
145
137
  */
146
- speakers_count: import_v42.z.number().nullish(),
138
+ speakers_count: z2.number().nullish(),
147
139
  /**
148
140
  * Type of diarization to use.
149
141
  */
150
- diarization_type: import_v42.z.enum(["standard", "premium"]).nullish().default("standard"),
142
+ diarization_type: z2.enum(["standard", "premium"]).nullish().default("standard"),
151
143
  /**
152
144
  * ID of a custom vocabulary to use for the transcription.
153
145
  */
154
- custom_vocabulary_id: import_v42.z.string().nullish(),
146
+ custom_vocabulary_id: z2.string().nullish(),
155
147
  /**
156
148
  * Custom vocabularies to use for the transcription.
157
149
  */
158
- custom_vocabularies: import_v42.z.array(import_v42.z.object({})).optional(),
150
+ custom_vocabularies: z2.array(z2.object({})).optional(),
159
151
  /**
160
152
  * Whether to strictly enforce custom vocabulary.
161
153
  */
162
- strict_custom_vocabulary: import_v42.z.boolean().optional(),
154
+ strict_custom_vocabulary: z2.boolean().optional(),
163
155
  /**
164
156
  * Configuration for generating a summary of the transcription.
165
157
  */
166
- summarization_config: import_v42.z.object({
158
+ summarization_config: z2.object({
167
159
  /**
168
160
  * Model to use for summarization.
169
161
  */
170
- model: import_v42.z.enum(["standard", "premium"]).nullish().default("standard"),
162
+ model: z2.enum(["standard", "premium"]).nullish().default("standard"),
171
163
  /**
172
164
  * Format of the summary.
173
165
  */
174
- type: import_v42.z.enum(["paragraph", "bullets"]).nullish().default("paragraph"),
166
+ type: z2.enum(["paragraph", "bullets"]).nullish().default("paragraph"),
175
167
  /**
176
168
  * Custom prompt for the summarization.
177
169
  */
178
- prompt: import_v42.z.string().nullish()
170
+ prompt: z2.string().nullish()
179
171
  }).nullish(),
180
172
  /**
181
173
  * Configuration for translating the transcription.
182
174
  */
183
- translation_config: import_v42.z.object({
175
+ translation_config: z2.object({
184
176
  /**
185
177
  * Target languages for translation.
186
178
  */
187
- target_languages: import_v42.z.array(
188
- import_v42.z.object({
179
+ target_languages: z2.array(
180
+ z2.object({
189
181
  /**
190
182
  * Language code for translation target.
191
183
  */
192
- language: import_v42.z.enum([
184
+ language: z2.enum([
193
185
  "en",
194
186
  "en-us",
195
187
  "en-gb",
@@ -213,18 +205,20 @@ var revaiTranscriptionModelOptionsSchema = import_v42.z.object({
213
205
  /**
214
206
  * Model to use for translation.
215
207
  */
216
- model: import_v42.z.enum(["standard", "premium"]).nullish().default("standard")
208
+ model: z2.enum(["standard", "premium"]).nullish().default("standard")
217
209
  }).nullish(),
218
210
  /**
219
211
  * Language of the audio content.
220
212
  */
221
- language: import_v42.z.string().nullish().default("en"),
213
+ language: z2.string().nullish().default("en"),
222
214
  /**
223
215
  * Whether to perform forced alignment.
224
216
  */
225
- forced_alignment: import_v42.z.boolean().nullish().default(false)
217
+ forced_alignment: z2.boolean().nullish().default(false)
226
218
  });
227
- var RevaiTranscriptionModel = class {
219
+
220
+ // src/revai-transcription-model.ts
221
+ var RevaiTranscriptionModel = class _RevaiTranscriptionModel {
228
222
  constructor(modelId, config) {
229
223
  this.modelId = modelId;
230
224
  this.config = config;
@@ -233,6 +227,15 @@ var RevaiTranscriptionModel = class {
233
227
  get provider() {
234
228
  return this.config.provider;
235
229
  }
230
+ static [WORKFLOW_SERIALIZE](model) {
231
+ return serializeModelOptions({
232
+ modelId: model.modelId,
233
+ config: model.config
234
+ });
235
+ }
236
+ static [WORKFLOW_DESERIALIZE](options) {
237
+ return new _RevaiTranscriptionModel(options.modelId, options.config);
238
+ }
236
239
  async getArgs({
237
240
  audio,
238
241
  mediaType,
@@ -240,14 +243,14 @@ var RevaiTranscriptionModel = class {
240
243
  }) {
241
244
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
242
245
  const warnings = [];
243
- const revaiOptions = await (0, import_provider_utils2.parseProviderOptions)({
246
+ const revaiOptions = await parseProviderOptions({
244
247
  provider: "revai",
245
248
  providerOptions,
246
249
  schema: revaiTranscriptionModelOptionsSchema
247
250
  });
248
251
  const formData = new FormData();
249
- const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([(0, import_provider_utils2.convertBase64ToUint8Array)(audio)]);
250
- const fileExtension = (0, import_provider_utils2.mediaTypeToExtension)(mediaType);
252
+ const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
253
+ const fileExtension = mediaTypeToExtension(mediaType);
251
254
  formData.append(
252
255
  "media",
253
256
  new File([blob], "audio", { type: mediaType }),
@@ -297,25 +300,25 @@ var RevaiTranscriptionModel = class {
297
300
  };
298
301
  }
299
302
  async doGenerate(options) {
300
- var _a, _b, _c, _d, _e, _f, _g, _h;
303
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
301
304
  const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
302
305
  const { formData, warnings } = await this.getArgs(options);
303
- const { value: submissionResponse } = await (0, import_provider_utils2.postFormDataToApi)({
306
+ const { value: submissionResponse } = await postFormDataToApi({
304
307
  url: this.config.url({
305
308
  path: "/speechtotext/v1/jobs",
306
309
  modelId: this.modelId
307
310
  }),
308
- headers: (0, import_provider_utils2.combineHeaders)(this.config.headers(), options.headers),
311
+ headers: combineHeaders((_e = (_d = this.config).headers) == null ? void 0 : _e.call(_d), options.headers),
309
312
  formData,
310
313
  failedResponseHandler: revaiFailedResponseHandler,
311
- successfulResponseHandler: (0, import_provider_utils2.createJsonResponseHandler)(
314
+ successfulResponseHandler: createJsonResponseHandler(
312
315
  revaiTranscriptionJobResponseSchema
313
316
  ),
314
317
  abortSignal: options.abortSignal,
315
318
  fetch: this.config.fetch
316
319
  });
317
320
  if (submissionResponse.status === "failed") {
318
- throw new import_provider.AISDKError({
321
+ throw new AISDKError({
319
322
  message: "Failed to submit transcription job to Rev.ai",
320
323
  name: "TranscriptionJobSubmissionFailed",
321
324
  cause: submissionResponse
@@ -328,20 +331,20 @@ var RevaiTranscriptionModel = class {
328
331
  let jobResponse = submissionResponse;
329
332
  while (jobResponse.status !== "transcribed") {
330
333
  if (Date.now() - startTime > timeoutMs) {
331
- throw new import_provider.AISDKError({
334
+ throw new AISDKError({
332
335
  message: "Transcription job polling timed out",
333
336
  name: "TranscriptionJobPollingTimedOut",
334
337
  cause: submissionResponse
335
338
  });
336
339
  }
337
- const pollingResult = await (0, import_provider_utils2.getFromApi)({
340
+ const pollingResult = await getFromApi({
338
341
  url: this.config.url({
339
342
  path: `/speechtotext/v1/jobs/${jobId}`,
340
343
  modelId: this.modelId
341
344
  }),
342
- headers: (0, import_provider_utils2.combineHeaders)(this.config.headers(), options.headers),
345
+ headers: combineHeaders((_g = (_f = this.config).headers) == null ? void 0 : _g.call(_f), options.headers),
343
346
  failedResponseHandler: revaiFailedResponseHandler,
344
- successfulResponseHandler: (0, import_provider_utils2.createJsonResponseHandler)(
347
+ successfulResponseHandler: createJsonResponseHandler(
345
348
  revaiTranscriptionJobResponseSchema
346
349
  ),
347
350
  abortSignal: options.abortSignal,
@@ -349,28 +352,28 @@ var RevaiTranscriptionModel = class {
349
352
  });
350
353
  jobResponse = pollingResult.value;
351
354
  if (jobResponse.status === "failed") {
352
- throw new import_provider.AISDKError({
355
+ throw new AISDKError({
353
356
  message: "Transcription job failed",
354
357
  name: "TranscriptionJobFailed",
355
358
  cause: jobResponse
356
359
  });
357
360
  }
358
361
  if (jobResponse.status !== "transcribed") {
359
- await (0, import_provider_utils2.delay)(pollingInterval);
362
+ await delay(pollingInterval);
360
363
  }
361
364
  }
362
365
  const {
363
366
  value: transcriptionResult,
364
367
  responseHeaders,
365
368
  rawValue: rawResponse
366
- } = await (0, import_provider_utils2.getFromApi)({
369
+ } = await getFromApi({
367
370
  url: this.config.url({
368
371
  path: `/speechtotext/v1/jobs/${jobId}/transcript`,
369
372
  modelId: this.modelId
370
373
  }),
371
- headers: (0, import_provider_utils2.combineHeaders)(this.config.headers(), options.headers),
374
+ headers: combineHeaders((_i = (_h = this.config).headers) == null ? void 0 : _i.call(_h), options.headers),
372
375
  failedResponseHandler: revaiFailedResponseHandler,
373
- successfulResponseHandler: (0, import_provider_utils2.createJsonResponseHandler)(
376
+ successfulResponseHandler: createJsonResponseHandler(
374
377
  revaiTranscriptionResponseSchema
375
378
  ),
376
379
  abortSignal: options.abortSignal,
@@ -378,11 +381,11 @@ var RevaiTranscriptionModel = class {
378
381
  });
379
382
  let durationInSeconds = 0;
380
383
  const segments = [];
381
- for (const monologue of (_d = transcriptionResult.monologues) != null ? _d : []) {
384
+ for (const monologue of (_j = transcriptionResult.monologues) != null ? _j : []) {
382
385
  let currentSegmentText = "";
383
386
  let segmentStartSecond = 0;
384
387
  let hasStartedSegment = false;
385
- for (const element of (_e = monologue == null ? void 0 : monologue.elements) != null ? _e : []) {
388
+ for (const element of (_k = monologue == null ? void 0 : monologue.elements) != null ? _k : []) {
386
389
  currentSegmentText += element.value;
387
390
  if (element.type === "text") {
388
391
  if (element.end_ts && element.end_ts > durationInSeconds) {
@@ -415,14 +418,14 @@ var RevaiTranscriptionModel = class {
415
418
  }
416
419
  }
417
420
  return {
418
- text: (_g = (_f = transcriptionResult.monologues) == null ? void 0 : _f.map(
421
+ text: (_m = (_l = transcriptionResult.monologues) == null ? void 0 : _l.map(
419
422
  (monologue) => {
420
423
  var _a2;
421
424
  return (_a2 = monologue == null ? void 0 : monologue.elements) == null ? void 0 : _a2.map((element) => element.value).join("");
422
425
  }
423
- ).join(" ")) != null ? _g : "",
426
+ ).join(" ")) != null ? _m : "",
424
427
  segments,
425
- language: (_h = submissionResponse.language) != null ? _h : void 0,
428
+ language: (_n = submissionResponse.language) != null ? _n : void 0,
426
429
  durationInSeconds,
427
430
  warnings,
428
431
  response: {
@@ -434,20 +437,20 @@ var RevaiTranscriptionModel = class {
434
437
  };
435
438
  }
436
439
  };
437
- var revaiTranscriptionJobResponseSchema = import_v42.z.object({
438
- id: import_v42.z.string().nullish(),
439
- status: import_v42.z.string().nullish(),
440
- language: import_v42.z.string().nullish()
440
+ var revaiTranscriptionJobResponseSchema = z3.object({
441
+ id: z3.string().nullish(),
442
+ status: z3.string().nullish(),
443
+ language: z3.string().nullish()
441
444
  });
442
- var revaiTranscriptionResponseSchema = import_v42.z.object({
443
- monologues: import_v42.z.array(
444
- import_v42.z.object({
445
- elements: import_v42.z.array(
446
- import_v42.z.object({
447
- type: import_v42.z.string().nullish(),
448
- value: import_v42.z.string().nullish(),
449
- ts: import_v42.z.number().nullish(),
450
- end_ts: import_v42.z.number().nullish()
445
+ var revaiTranscriptionResponseSchema = z3.object({
446
+ monologues: z3.array(
447
+ z3.object({
448
+ elements: z3.array(
449
+ z3.object({
450
+ type: z3.string().nullish(),
451
+ value: z3.string().nullish(),
452
+ ts: z3.number().nullish(),
453
+ end_ts: z3.number().nullish()
451
454
  })
452
455
  ).nullish()
453
456
  })
@@ -455,13 +458,13 @@ var revaiTranscriptionResponseSchema = import_v42.z.object({
455
458
  });
456
459
 
457
460
  // src/version.ts
458
- var VERSION = true ? "3.0.0-beta.4" : "0.0.0-test";
461
+ var VERSION = true ? "3.0.0-beta.51" : "0.0.0-test";
459
462
 
460
463
  // src/revai-provider.ts
461
464
  function createRevai(options = {}) {
462
- const getHeaders = () => (0, import_provider_utils3.withUserAgentSuffix)(
465
+ const getHeaders = () => withUserAgentSuffix(
463
466
  {
464
- authorization: `Bearer ${(0, import_provider_utils3.loadApiKey)({
467
+ authorization: `Bearer ${loadApiKey({
465
468
  apiKey: options.apiKey,
466
469
  environmentVariableName: "REVAI_API_KEY",
467
470
  description: "Rev.ai"
@@ -485,14 +488,14 @@ function createRevai(options = {}) {
485
488
  provider.transcription = createTranscriptionModel;
486
489
  provider.transcriptionModel = createTranscriptionModel;
487
490
  provider.languageModel = () => {
488
- throw new import_provider2.NoSuchModelError({
491
+ throw new NoSuchModelError({
489
492
  modelId: "unknown",
490
493
  modelType: "languageModel",
491
494
  message: "Rev.ai does not provide language models"
492
495
  });
493
496
  };
494
497
  provider.embeddingModel = () => {
495
- throw new import_provider2.NoSuchModelError({
498
+ throw new NoSuchModelError({
496
499
  modelId: "unknown",
497
500
  modelType: "embeddingModel",
498
501
  message: "Rev.ai does not provide text embedding models"
@@ -500,7 +503,7 @@ function createRevai(options = {}) {
500
503
  };
501
504
  provider.textEmbeddingModel = provider.embeddingModel;
502
505
  provider.imageModel = () => {
503
- throw new import_provider2.NoSuchModelError({
506
+ throw new NoSuchModelError({
504
507
  modelId: "unknown",
505
508
  modelType: "imageModel",
506
509
  message: "Rev.ai does not provide image models"
@@ -509,10 +512,9 @@ function createRevai(options = {}) {
509
512
  return provider;
510
513
  }
511
514
  var revai = createRevai();
512
- // Annotate the CommonJS export names for ESM import in node:
513
- 0 && (module.exports = {
515
+ export {
514
516
  VERSION,
515
517
  createRevai,
516
518
  revai
517
- });
519
+ };
518
520
  //# sourceMappingURL=index.js.map