@ai-sdk/deepgram 3.0.0-beta.3 → 3.0.0-beta.31

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