@ai-sdk/deepgram 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.
package/dist/index.js CHANGED
@@ -1,108 +1,101 @@
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
- DeepgramSpeechModel: () => DeepgramSpeechModel,
24
- VERSION: () => VERSION,
25
- createDeepgram: () => createDeepgram,
26
- deepgram: () => deepgram
27
- });
28
- module.exports = __toCommonJS(index_exports);
29
-
30
1
  // src/deepgram-provider.ts
31
- var import_provider = require("@ai-sdk/provider");
32
- var import_provider_utils4 = 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";
33
9
 
34
10
  // src/deepgram-transcription-model.ts
35
- var import_provider_utils2 = require("@ai-sdk/provider-utils");
36
- var import_v42 = require("zod/v4");
11
+ import {
12
+ combineHeaders,
13
+ createJsonResponseHandler,
14
+ parseProviderOptions,
15
+ postToApi,
16
+ serializeModelOptions,
17
+ WORKFLOW_SERIALIZE,
18
+ WORKFLOW_DESERIALIZE
19
+ } from "@ai-sdk/provider-utils";
20
+ import { z as z2 } from "zod/v4";
37
21
 
38
22
  // src/deepgram-error.ts
39
- var import_v4 = require("zod/v4");
40
- var import_provider_utils = require("@ai-sdk/provider-utils");
41
- var deepgramErrorDataSchema = import_v4.z.object({
42
- error: import_v4.z.object({
43
- message: import_v4.z.string(),
44
- code: import_v4.z.number()
23
+ import { z } from "zod/v4";
24
+ import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
25
+ var deepgramErrorDataSchema = z.object({
26
+ error: z.object({
27
+ message: z.string(),
28
+ code: z.number()
45
29
  })
46
30
  });
47
- var deepgramFailedResponseHandler = (0, import_provider_utils.createJsonErrorResponseHandler)({
31
+ var deepgramFailedResponseHandler = createJsonErrorResponseHandler({
48
32
  errorSchema: deepgramErrorDataSchema,
49
33
  errorToMessage: (data) => data.error.message
50
34
  });
51
35
 
52
36
  // src/deepgram-transcription-model.ts
53
- var deepgramTranscriptionModelOptionsSchema = import_v42.z.object({
37
+ var deepgramTranscriptionModelOptionsSchema = z2.object({
54
38
  /** Language to use for transcription. If not specified, Deepgram defaults to English. Use `detectLanguage: true` to enable automatic language detection. */
55
- language: import_v42.z.string().nullish(),
39
+ language: z2.string().nullish(),
56
40
  /** Whether to enable automatic language detection. When true, Deepgram will detect the language of the audio. */
57
- detectLanguage: import_v42.z.boolean().nullish(),
41
+ detectLanguage: z2.boolean().nullish(),
58
42
  /** Whether to use smart formatting, which formats written-out numbers, dates, times, etc. */
59
- smartFormat: import_v42.z.boolean().nullish(),
43
+ smartFormat: z2.boolean().nullish(),
60
44
  /** Whether to add punctuation to the transcript. */
61
- punctuate: import_v42.z.boolean().nullish(),
45
+ punctuate: z2.boolean().nullish(),
62
46
  /** Whether to format the transcript into paragraphs. */
63
- paragraphs: import_v42.z.boolean().nullish(),
47
+ paragraphs: z2.boolean().nullish(),
64
48
  /** Whether to generate a summary of the transcript. Use 'v2' for the latest version or false to disable. */
65
- summarize: import_v42.z.union([import_v42.z.literal("v2"), import_v42.z.literal(false)]).nullish(),
49
+ summarize: z2.union([z2.literal("v2"), z2.literal(false)]).nullish(),
66
50
  /** Whether to identify topics in the transcript. */
67
- topics: import_v42.z.boolean().nullish(),
51
+ topics: z2.boolean().nullish(),
68
52
  /** Whether to identify intents in the transcript. */
69
- intents: import_v42.z.boolean().nullish(),
53
+ intents: z2.boolean().nullish(),
70
54
  /** Whether to analyze sentiment in the transcript. */
71
- sentiment: import_v42.z.boolean().nullish(),
55
+ sentiment: z2.boolean().nullish(),
72
56
  /** Whether to detect and tag named entities in the transcript. */
73
- detectEntities: import_v42.z.boolean().nullish(),
57
+ detectEntities: z2.boolean().nullish(),
74
58
  /** Specify terms or patterns to redact from the transcript. Can be a string or array of strings. */
75
- redact: import_v42.z.union([import_v42.z.string(), import_v42.z.array(import_v42.z.string())]).nullish(),
59
+ redact: z2.union([z2.string(), z2.array(z2.string())]).nullish(),
76
60
  /** String to replace redacted content with. */
77
- replace: import_v42.z.string().nullish(),
61
+ replace: z2.string().nullish(),
78
62
  /** Term or phrase to search for in the transcript. */
79
- search: import_v42.z.string().nullish(),
63
+ search: z2.string().nullish(),
80
64
  /** Key term to identify in the transcript. */
81
- keyterm: import_v42.z.string().nullish(),
65
+ keyterm: z2.string().nullish(),
82
66
  /** Whether to identify different speakers in the audio. */
83
- diarize: import_v42.z.boolean().nullish(),
67
+ diarize: z2.boolean().nullish(),
84
68
  /** Whether to segment the transcript into utterances. */
85
- utterances: import_v42.z.boolean().nullish(),
69
+ utterances: z2.boolean().nullish(),
86
70
  /** Minimum duration of silence (in seconds) to trigger a new utterance. */
87
- uttSplit: import_v42.z.number().nullish(),
71
+ uttSplit: z2.number().nullish(),
88
72
  /** Whether to include filler words (um, uh, etc.) in the transcript. */
89
- fillerWords: import_v42.z.boolean().nullish()
73
+ fillerWords: z2.boolean().nullish()
90
74
  });
91
- var DeepgramTranscriptionModel = class {
75
+ var DeepgramTranscriptionModel = class _DeepgramTranscriptionModel {
92
76
  constructor(modelId, config) {
93
77
  this.modelId = modelId;
94
78
  this.config = config;
95
- this.specificationVersion = "v3";
79
+ this.specificationVersion = "v4";
96
80
  }
97
81
  get provider() {
98
82
  return this.config.provider;
99
83
  }
84
+ static [WORKFLOW_SERIALIZE](model) {
85
+ return serializeModelOptions({
86
+ modelId: model.modelId,
87
+ config: model.config
88
+ });
89
+ }
90
+ static [WORKFLOW_DESERIALIZE](options) {
91
+ return new _DeepgramTranscriptionModel(options.modelId, options.config);
92
+ }
100
93
  async getArgs({
101
94
  providerOptions
102
95
  }) {
103
96
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
104
97
  const warnings = [];
105
- const deepgramOptions = await (0, import_provider_utils2.parseProviderOptions)({
98
+ const deepgramOptions = await parseProviderOptions({
106
99
  provider: "deepgram",
107
100
  providerOptions,
108
101
  schema: deepgramTranscriptionModelOptionsSchema
@@ -140,20 +133,20 @@ var DeepgramTranscriptionModel = class {
140
133
  };
141
134
  }
142
135
  async doGenerate(options) {
143
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
136
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
144
137
  const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
145
138
  const { queryParams, warnings } = await this.getArgs(options);
146
139
  const {
147
140
  value: response,
148
141
  responseHeaders,
149
142
  rawValue: rawResponse
150
- } = await (0, import_provider_utils2.postToApi)({
143
+ } = await postToApi({
151
144
  url: this.config.url({
152
145
  path: "/v1/listen",
153
146
  modelId: this.modelId
154
147
  }) + "?" + queryParams.toString(),
155
148
  headers: {
156
- ...(0, import_provider_utils2.combineHeaders)(this.config.headers(), options.headers),
149
+ ...combineHeaders((_e = (_d = this.config).headers) == null ? void 0 : _e.call(_d), options.headers),
157
150
  "Content-Type": options.mediaType
158
151
  },
159
152
  body: {
@@ -161,21 +154,21 @@ var DeepgramTranscriptionModel = class {
161
154
  values: options.audio
162
155
  },
163
156
  failedResponseHandler: deepgramFailedResponseHandler,
164
- successfulResponseHandler: (0, import_provider_utils2.createJsonResponseHandler)(
157
+ successfulResponseHandler: createJsonResponseHandler(
165
158
  deepgramTranscriptionResponseSchema
166
159
  ),
167
160
  abortSignal: options.abortSignal,
168
161
  fetch: this.config.fetch
169
162
  });
170
163
  return {
171
- text: (_g = (_f = (_e = (_d = response.results) == null ? void 0 : _d.channels.at(0)) == null ? void 0 : _e.alternatives.at(0)) == null ? void 0 : _f.transcript) != null ? _g : "",
172
- segments: (_j = (_i = (_h = response.results) == null ? void 0 : _h.channels[0].alternatives[0].words) == null ? void 0 : _i.map((word) => ({
164
+ text: (_i = (_h = (_g = (_f = response.results) == null ? void 0 : _f.channels.at(0)) == null ? void 0 : _g.alternatives.at(0)) == null ? void 0 : _h.transcript) != null ? _i : "",
165
+ segments: (_l = (_k = (_j = response.results) == null ? void 0 : _j.channels[0].alternatives[0].words) == null ? void 0 : _k.map((word) => ({
173
166
  text: word.word,
174
167
  startSecond: word.start,
175
168
  endSecond: word.end
176
- }))) != null ? _j : [],
177
- language: (_m = (_l = (_k = response.results) == null ? void 0 : _k.channels.at(0)) == null ? void 0 : _l.detected_language) != null ? _m : void 0,
178
- durationInSeconds: (_o = (_n = response.metadata) == null ? void 0 : _n.duration) != null ? _o : void 0,
169
+ }))) != null ? _l : [],
170
+ language: (_o = (_n = (_m = response.results) == null ? void 0 : _m.channels.at(0)) == null ? void 0 : _n.detected_language) != null ? _o : void 0,
171
+ durationInSeconds: (_q = (_p = response.metadata) == null ? void 0 : _p.duration) != null ? _q : void 0,
179
172
  warnings,
180
173
  response: {
181
174
  timestamp: currentDate,
@@ -186,22 +179,22 @@ var DeepgramTranscriptionModel = class {
186
179
  };
187
180
  }
188
181
  };
189
- var deepgramTranscriptionResponseSchema = import_v42.z.object({
190
- metadata: import_v42.z.object({
191
- duration: import_v42.z.number()
182
+ var deepgramTranscriptionResponseSchema = z2.object({
183
+ metadata: z2.object({
184
+ duration: z2.number()
192
185
  }).nullish(),
193
- results: import_v42.z.object({
194
- channels: import_v42.z.array(
195
- import_v42.z.object({
196
- detected_language: import_v42.z.string().nullish(),
197
- alternatives: import_v42.z.array(
198
- import_v42.z.object({
199
- transcript: import_v42.z.string(),
200
- words: import_v42.z.array(
201
- import_v42.z.object({
202
- word: import_v42.z.string(),
203
- start: import_v42.z.number(),
204
- end: import_v42.z.number()
186
+ results: z2.object({
187
+ channels: z2.array(
188
+ z2.object({
189
+ detected_language: z2.string().nullish(),
190
+ alternatives: z2.array(
191
+ z2.object({
192
+ transcript: z2.string(),
193
+ words: z2.array(
194
+ z2.object({
195
+ word: z2.string(),
196
+ start: z2.number(),
197
+ end: z2.number()
205
198
  })
206
199
  )
207
200
  })
@@ -212,35 +205,52 @@ var deepgramTranscriptionResponseSchema = import_v42.z.object({
212
205
  });
213
206
 
214
207
  // src/deepgram-speech-model.ts
215
- var import_provider_utils3 = require("@ai-sdk/provider-utils");
216
- var import_v43 = require("zod/v4");
217
- var deepgramSpeechModelOptionsSchema = import_v43.z.object({
208
+ import {
209
+ combineHeaders as combineHeaders2,
210
+ createBinaryResponseHandler,
211
+ parseProviderOptions as parseProviderOptions2,
212
+ postJsonToApi,
213
+ serializeModelOptions as serializeModelOptions2,
214
+ WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE2,
215
+ WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE2
216
+ } from "@ai-sdk/provider-utils";
217
+ import { z as z3 } from "zod/v4";
218
+ var deepgramSpeechModelOptionsSchema = z3.object({
218
219
  /** Bitrate of the audio in bits per second. Can be a number or predefined enum value. */
219
- bitRate: import_v43.z.union([import_v43.z.number(), import_v43.z.string()]).nullish(),
220
+ bitRate: z3.union([z3.number(), z3.string()]).nullish(),
220
221
  /** Container format for the output audio (mp3, wav, etc.). */
221
- container: import_v43.z.string().nullish(),
222
+ container: z3.string().nullish(),
222
223
  /** Encoding type for the audio output (linear16, mulaw, alaw, etc.). */
223
- encoding: import_v43.z.string().nullish(),
224
+ encoding: z3.string().nullish(),
224
225
  /** Sample rate for the output audio in Hz (8000, 16000, 24000, 44100, 48000). */
225
- sampleRate: import_v43.z.number().nullish(),
226
+ sampleRate: z3.number().nullish(),
226
227
  /** URL to which we'll make the callback request. */
227
- callback: import_v43.z.string().url().nullish(),
228
+ callback: z3.string().url().nullish(),
228
229
  /** HTTP method by which the callback request will be made (POST or PUT). */
229
- callbackMethod: import_v43.z.enum(["POST", "PUT"]).nullish(),
230
+ callbackMethod: z3.enum(["POST", "PUT"]).nullish(),
230
231
  /** Opts out requests from the Deepgram Model Improvement Program. */
231
- mipOptOut: import_v43.z.boolean().nullish(),
232
+ mipOptOut: z3.boolean().nullish(),
232
233
  /** Label your requests for the purpose of identification during usage reporting. */
233
- tag: import_v43.z.union([import_v43.z.string(), import_v43.z.array(import_v43.z.string())]).nullish()
234
+ tag: z3.union([z3.string(), z3.array(z3.string())]).nullish()
234
235
  });
235
- var DeepgramSpeechModel = class {
236
+ var DeepgramSpeechModel = class _DeepgramSpeechModel {
236
237
  constructor(modelId, config) {
237
238
  this.modelId = modelId;
238
239
  this.config = config;
239
- this.specificationVersion = "v3";
240
+ this.specificationVersion = "v4";
240
241
  }
241
242
  get provider() {
242
243
  return this.config.provider;
243
244
  }
245
+ static [WORKFLOW_SERIALIZE2](model) {
246
+ return serializeModelOptions2({
247
+ modelId: model.modelId,
248
+ config: model.config
249
+ });
250
+ }
251
+ static [WORKFLOW_DESERIALIZE2](options) {
252
+ return new _DeepgramSpeechModel(options.modelId, options.config);
253
+ }
244
254
  async getArgs({
245
255
  text,
246
256
  voice,
@@ -252,7 +262,7 @@ var DeepgramSpeechModel = class {
252
262
  }) {
253
263
  var _a, _b, _c;
254
264
  const warnings = [];
255
- const deepgramOptions = await (0, import_provider_utils3.parseProviderOptions)({
265
+ const deepgramOptions = await parseProviderOptions2({
256
266
  provider: "deepgram",
257
267
  providerOptions,
258
268
  schema: deepgramSpeechModelOptionsSchema
@@ -553,14 +563,14 @@ var DeepgramSpeechModel = class {
553
563
  };
554
564
  }
555
565
  async doGenerate(options) {
556
- var _a, _b, _c;
566
+ var _a, _b, _c, _d, _e;
557
567
  const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
558
568
  const { requestBody, queryParams, warnings } = await this.getArgs(options);
559
569
  const {
560
570
  value: audio,
561
571
  responseHeaders,
562
572
  rawValue: rawResponse
563
- } = await (0, import_provider_utils3.postJsonToApi)({
573
+ } = await postJsonToApi({
564
574
  url: (() => {
565
575
  const baseUrl = this.config.url({
566
576
  path: "/v1/speak",
@@ -569,10 +579,10 @@ var DeepgramSpeechModel = class {
569
579
  const queryString = new URLSearchParams(queryParams).toString();
570
580
  return queryString ? `${baseUrl}?${queryString}` : baseUrl;
571
581
  })(),
572
- headers: (0, import_provider_utils3.combineHeaders)(this.config.headers(), options.headers),
582
+ headers: combineHeaders2((_e = (_d = this.config).headers) == null ? void 0 : _e.call(_d), options.headers),
573
583
  body: requestBody,
574
584
  failedResponseHandler: deepgramFailedResponseHandler,
575
- successfulResponseHandler: (0, import_provider_utils3.createBinaryResponseHandler)(),
585
+ successfulResponseHandler: createBinaryResponseHandler(),
576
586
  abortSignal: options.abortSignal,
577
587
  fetch: this.config.fetch
578
588
  });
@@ -593,13 +603,13 @@ var DeepgramSpeechModel = class {
593
603
  };
594
604
 
595
605
  // src/version.ts
596
- var VERSION = true ? "3.0.0-beta.3" : "0.0.0-test";
606
+ var VERSION = true ? "3.0.0-beta.30" : "0.0.0-test";
597
607
 
598
608
  // src/deepgram-provider.ts
599
609
  function createDeepgram(options = {}) {
600
- const getHeaders = () => (0, import_provider_utils4.withUserAgentSuffix)(
610
+ const getHeaders = () => withUserAgentSuffix(
601
611
  {
602
- authorization: `Token ${(0, import_provider_utils4.loadApiKey)({
612
+ authorization: `Token ${loadApiKey({
603
613
  apiKey: options.apiKey,
604
614
  environmentVariableName: "DEEPGRAM_API_KEY",
605
615
  description: "Deepgram"
@@ -625,20 +635,20 @@ function createDeepgram(options = {}) {
625
635
  transcription: createTranscriptionModel(modelId)
626
636
  };
627
637
  };
628
- provider.specificationVersion = "v3";
638
+ provider.specificationVersion = "v4";
629
639
  provider.transcription = createTranscriptionModel;
630
640
  provider.transcriptionModel = createTranscriptionModel;
631
641
  provider.speech = createSpeechModel;
632
642
  provider.speechModel = createSpeechModel;
633
643
  provider.languageModel = (modelId) => {
634
- throw new import_provider.NoSuchModelError({
644
+ throw new NoSuchModelError({
635
645
  modelId,
636
646
  modelType: "languageModel",
637
647
  message: "Deepgram does not provide language models"
638
648
  });
639
649
  };
640
650
  provider.embeddingModel = (modelId) => {
641
- throw new import_provider.NoSuchModelError({
651
+ throw new NoSuchModelError({
642
652
  modelId,
643
653
  modelType: "embeddingModel",
644
654
  message: "Deepgram does not provide text embedding models"
@@ -646,7 +656,7 @@ function createDeepgram(options = {}) {
646
656
  };
647
657
  provider.textEmbeddingModel = provider.embeddingModel;
648
658
  provider.imageModel = (modelId) => {
649
- throw new import_provider.NoSuchModelError({
659
+ throw new NoSuchModelError({
650
660
  modelId,
651
661
  modelType: "imageModel",
652
662
  message: "Deepgram does not provide image models"
@@ -655,11 +665,10 @@ function createDeepgram(options = {}) {
655
665
  return provider;
656
666
  }
657
667
  var deepgram = createDeepgram();
658
- // Annotate the CommonJS export names for ESM import in node:
659
- 0 && (module.exports = {
668
+ export {
660
669
  DeepgramSpeechModel,
661
670
  VERSION,
662
671
  createDeepgram,
663
672
  deepgram
664
- });
673
+ };
665
674
  //# sourceMappingURL=index.js.map