@ai-sdk/gladia 3.0.0-beta.5 → 3.0.0-beta.50
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/CHANGELOG.md +380 -4
- package/README.md +3 -1
- package/dist/index.d.ts +64 -54
- package/dist/index.js +152 -147
- package/dist/index.js.map +1 -1
- package/docs/120-gladia.mdx +1 -11
- package/package.json +15 -15
- package/src/gladia-config.ts +2 -2
- package/src/gladia-provider.ts +3 -3
- package/src/gladia-transcription-model-options.ts +309 -0
- package/src/gladia-transcription-model.ts +33 -317
- package/src/index.ts +1 -1
- package/dist/index.d.mts +0 -158
- package/dist/index.mjs +0 -604
- package/dist/index.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,307 +1,303 @@
|
|
|
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
|
-
createGladia: () => createGladia,
|
|
25
|
-
gladia: () => gladia
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(index_exports);
|
|
28
|
-
|
|
29
1
|
// src/gladia-provider.ts
|
|
30
|
-
|
|
31
|
-
|
|
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/gladia-transcription-model.ts
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
11
|
+
import {
|
|
12
|
+
AISDKError
|
|
13
|
+
} from "@ai-sdk/provider";
|
|
14
|
+
import {
|
|
15
|
+
combineHeaders,
|
|
16
|
+
convertBase64ToUint8Array,
|
|
17
|
+
createJsonResponseHandler,
|
|
18
|
+
mediaTypeToExtension,
|
|
19
|
+
delay,
|
|
20
|
+
getFromApi,
|
|
21
|
+
isSameOrigin,
|
|
22
|
+
parseProviderOptions,
|
|
23
|
+
postFormDataToApi,
|
|
24
|
+
postJsonToApi,
|
|
25
|
+
serializeModelOptions,
|
|
26
|
+
WORKFLOW_SERIALIZE,
|
|
27
|
+
WORKFLOW_DESERIALIZE
|
|
28
|
+
} from "@ai-sdk/provider-utils";
|
|
29
|
+
import { z as z3 } from "zod/v4";
|
|
37
30
|
|
|
38
31
|
// src/gladia-error.ts
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
var gladiaErrorDataSchema =
|
|
42
|
-
error:
|
|
43
|
-
message:
|
|
44
|
-
code:
|
|
32
|
+
import { z } from "zod/v4";
|
|
33
|
+
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
34
|
+
var gladiaErrorDataSchema = z.object({
|
|
35
|
+
error: z.object({
|
|
36
|
+
message: z.string(),
|
|
37
|
+
code: z.number()
|
|
45
38
|
})
|
|
46
39
|
});
|
|
47
|
-
var gladiaFailedResponseHandler =
|
|
40
|
+
var gladiaFailedResponseHandler = createJsonErrorResponseHandler({
|
|
48
41
|
errorSchema: gladiaErrorDataSchema,
|
|
49
42
|
errorToMessage: (data) => data.error.message
|
|
50
43
|
});
|
|
51
44
|
|
|
52
|
-
// src/gladia-transcription-model.ts
|
|
53
|
-
|
|
45
|
+
// src/gladia-transcription-model-options.ts
|
|
46
|
+
import { z as z2 } from "zod/v4";
|
|
47
|
+
var gladiaTranscriptionModelOptionsSchema = z2.object({
|
|
54
48
|
/**
|
|
55
49
|
* Optional context prompt to guide the transcription.
|
|
56
50
|
*/
|
|
57
|
-
contextPrompt:
|
|
51
|
+
contextPrompt: z2.string().nullish(),
|
|
58
52
|
/**
|
|
59
53
|
* Custom vocabulary to improve transcription accuracy.
|
|
60
54
|
* Can be a boolean or an array of custom terms.
|
|
61
55
|
*/
|
|
62
|
-
customVocabulary:
|
|
56
|
+
customVocabulary: z2.union([z2.boolean(), z2.array(z2.any())]).nullish(),
|
|
63
57
|
/**
|
|
64
58
|
* Configuration for custom vocabulary.
|
|
65
59
|
*/
|
|
66
|
-
customVocabularyConfig:
|
|
60
|
+
customVocabularyConfig: z2.object({
|
|
67
61
|
/**
|
|
68
62
|
* Array of vocabulary terms or objects with pronunciation details.
|
|
69
63
|
*/
|
|
70
|
-
vocabulary:
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
64
|
+
vocabulary: z2.array(
|
|
65
|
+
z2.union([
|
|
66
|
+
z2.string(),
|
|
67
|
+
z2.object({
|
|
74
68
|
/**
|
|
75
69
|
* The vocabulary term.
|
|
76
70
|
*/
|
|
77
|
-
value:
|
|
71
|
+
value: z2.string(),
|
|
78
72
|
/**
|
|
79
73
|
* Intensity of the term in recognition (optional).
|
|
80
74
|
*/
|
|
81
|
-
intensity:
|
|
75
|
+
intensity: z2.number().nullish(),
|
|
82
76
|
/**
|
|
83
77
|
* Alternative pronunciations for the term (optional).
|
|
84
78
|
*/
|
|
85
|
-
pronunciations:
|
|
79
|
+
pronunciations: z2.array(z2.string()).nullish(),
|
|
86
80
|
/**
|
|
87
81
|
* Language of the term (optional).
|
|
88
82
|
*/
|
|
89
|
-
language:
|
|
83
|
+
language: z2.string().nullish()
|
|
90
84
|
})
|
|
91
85
|
])
|
|
92
86
|
),
|
|
93
87
|
/**
|
|
94
88
|
* Default intensity for all vocabulary terms.
|
|
95
89
|
*/
|
|
96
|
-
defaultIntensity:
|
|
90
|
+
defaultIntensity: z2.number().nullish()
|
|
97
91
|
}).nullish(),
|
|
98
92
|
/**
|
|
99
93
|
* Whether to automatically detect the language of the audio.
|
|
100
94
|
*/
|
|
101
|
-
detectLanguage:
|
|
95
|
+
detectLanguage: z2.boolean().nullish(),
|
|
102
96
|
/**
|
|
103
97
|
* Whether to enable code switching (multiple languages in the same audio).
|
|
104
98
|
*/
|
|
105
|
-
enableCodeSwitching:
|
|
99
|
+
enableCodeSwitching: z2.boolean().nullish(),
|
|
106
100
|
/**
|
|
107
101
|
* Configuration for code switching.
|
|
108
102
|
*/
|
|
109
|
-
codeSwitchingConfig:
|
|
103
|
+
codeSwitchingConfig: z2.object({
|
|
110
104
|
/**
|
|
111
105
|
* Languages to consider for code switching.
|
|
112
106
|
*/
|
|
113
|
-
languages:
|
|
107
|
+
languages: z2.array(z2.string()).nullish()
|
|
114
108
|
}).nullish(),
|
|
115
109
|
/**
|
|
116
110
|
* Specific language for transcription.
|
|
117
111
|
*/
|
|
118
|
-
language:
|
|
112
|
+
language: z2.string().nullish(),
|
|
119
113
|
/**
|
|
120
114
|
* Whether to enable callback when transcription is complete.
|
|
121
115
|
*/
|
|
122
|
-
callback:
|
|
116
|
+
callback: z2.boolean().nullish(),
|
|
123
117
|
/**
|
|
124
118
|
* Configuration for callback.
|
|
125
119
|
*/
|
|
126
|
-
callbackConfig:
|
|
120
|
+
callbackConfig: z2.object({
|
|
127
121
|
/**
|
|
128
122
|
* URL to send the callback to.
|
|
129
123
|
*/
|
|
130
|
-
url:
|
|
124
|
+
url: z2.string(),
|
|
131
125
|
/**
|
|
132
126
|
* HTTP method for the callback.
|
|
133
127
|
*/
|
|
134
|
-
method:
|
|
128
|
+
method: z2.enum(["POST", "PUT"]).nullish()
|
|
135
129
|
}).nullish(),
|
|
136
130
|
/**
|
|
137
131
|
* Whether to generate subtitles.
|
|
138
132
|
*/
|
|
139
|
-
subtitles:
|
|
133
|
+
subtitles: z2.boolean().nullish(),
|
|
140
134
|
/**
|
|
141
135
|
* Configuration for subtitles generation.
|
|
142
136
|
*/
|
|
143
|
-
subtitlesConfig:
|
|
137
|
+
subtitlesConfig: z2.object({
|
|
144
138
|
/**
|
|
145
139
|
* Subtitle file formats to generate.
|
|
146
140
|
*/
|
|
147
|
-
formats:
|
|
141
|
+
formats: z2.array(z2.enum(["srt", "vtt"])).nullish(),
|
|
148
142
|
/**
|
|
149
143
|
* Minimum duration for subtitle segments.
|
|
150
144
|
*/
|
|
151
|
-
minimumDuration:
|
|
145
|
+
minimumDuration: z2.number().nullish(),
|
|
152
146
|
/**
|
|
153
147
|
* Maximum duration for subtitle segments.
|
|
154
148
|
*/
|
|
155
|
-
maximumDuration:
|
|
149
|
+
maximumDuration: z2.number().nullish(),
|
|
156
150
|
/**
|
|
157
151
|
* Maximum characters per row in subtitles.
|
|
158
152
|
*/
|
|
159
|
-
maximumCharactersPerRow:
|
|
153
|
+
maximumCharactersPerRow: z2.number().nullish(),
|
|
160
154
|
/**
|
|
161
155
|
* Maximum rows per caption in subtitles.
|
|
162
156
|
*/
|
|
163
|
-
maximumRowsPerCaption:
|
|
157
|
+
maximumRowsPerCaption: z2.number().nullish(),
|
|
164
158
|
/**
|
|
165
159
|
* Style of subtitles.
|
|
166
160
|
*/
|
|
167
|
-
style:
|
|
161
|
+
style: z2.enum(["default", "compliance"]).nullish()
|
|
168
162
|
}).nullish(),
|
|
169
163
|
/**
|
|
170
164
|
* Whether to enable speaker diarization (speaker identification).
|
|
171
165
|
*/
|
|
172
|
-
diarization:
|
|
166
|
+
diarization: z2.boolean().nullish(),
|
|
173
167
|
/**
|
|
174
168
|
* Configuration for diarization.
|
|
175
169
|
*/
|
|
176
|
-
diarizationConfig:
|
|
170
|
+
diarizationConfig: z2.object({
|
|
177
171
|
/**
|
|
178
172
|
* Exact number of speakers to identify.
|
|
179
173
|
*/
|
|
180
|
-
numberOfSpeakers:
|
|
174
|
+
numberOfSpeakers: z2.number().nullish(),
|
|
181
175
|
/**
|
|
182
176
|
* Minimum number of speakers to identify.
|
|
183
177
|
*/
|
|
184
|
-
minSpeakers:
|
|
178
|
+
minSpeakers: z2.number().nullish(),
|
|
185
179
|
/**
|
|
186
180
|
* Maximum number of speakers to identify.
|
|
187
181
|
*/
|
|
188
|
-
maxSpeakers:
|
|
182
|
+
maxSpeakers: z2.number().nullish(),
|
|
189
183
|
/**
|
|
190
184
|
* Whether to use enhanced diarization.
|
|
191
185
|
*/
|
|
192
|
-
enhanced:
|
|
186
|
+
enhanced: z2.boolean().nullish()
|
|
193
187
|
}).nullish(),
|
|
194
188
|
/**
|
|
195
189
|
* Whether to translate the transcription.
|
|
196
190
|
*/
|
|
197
|
-
translation:
|
|
191
|
+
translation: z2.boolean().nullish(),
|
|
198
192
|
/**
|
|
199
193
|
* Configuration for translation.
|
|
200
194
|
*/
|
|
201
|
-
translationConfig:
|
|
195
|
+
translationConfig: z2.object({
|
|
202
196
|
/**
|
|
203
197
|
* Target languages for translation.
|
|
204
198
|
*/
|
|
205
|
-
targetLanguages:
|
|
199
|
+
targetLanguages: z2.array(z2.string()),
|
|
206
200
|
/**
|
|
207
201
|
* Translation model to use.
|
|
208
202
|
*/
|
|
209
|
-
model:
|
|
203
|
+
model: z2.enum(["base", "enhanced"]).nullish(),
|
|
210
204
|
/**
|
|
211
205
|
* Whether to match original utterances in translation.
|
|
212
206
|
*/
|
|
213
|
-
matchOriginalUtterances:
|
|
207
|
+
matchOriginalUtterances: z2.boolean().nullish()
|
|
214
208
|
}).nullish(),
|
|
215
209
|
/**
|
|
216
210
|
* Whether to generate a summary of the transcription.
|
|
217
211
|
*/
|
|
218
|
-
summarization:
|
|
212
|
+
summarization: z2.boolean().nullish(),
|
|
219
213
|
/**
|
|
220
214
|
* Configuration for summarization.
|
|
221
215
|
*/
|
|
222
|
-
summarizationConfig:
|
|
216
|
+
summarizationConfig: z2.object({
|
|
223
217
|
/**
|
|
224
218
|
* Type of summary to generate.
|
|
225
219
|
*/
|
|
226
|
-
type:
|
|
220
|
+
type: z2.enum(["general", "bullet_points", "concise"]).nullish()
|
|
227
221
|
}).nullish(),
|
|
228
222
|
/**
|
|
229
223
|
* Whether to enable content moderation.
|
|
230
224
|
*/
|
|
231
|
-
moderation:
|
|
225
|
+
moderation: z2.boolean().nullish(),
|
|
232
226
|
/**
|
|
233
227
|
* Whether to enable named entity recognition.
|
|
234
228
|
*/
|
|
235
|
-
namedEntityRecognition:
|
|
229
|
+
namedEntityRecognition: z2.boolean().nullish(),
|
|
236
230
|
/**
|
|
237
231
|
* Whether to enable automatic chapter creation.
|
|
238
232
|
*/
|
|
239
|
-
chapterization:
|
|
233
|
+
chapterization: z2.boolean().nullish(),
|
|
240
234
|
/**
|
|
241
235
|
* Whether to ensure consistent naming of entities.
|
|
242
236
|
*/
|
|
243
|
-
nameConsistency:
|
|
237
|
+
nameConsistency: z2.boolean().nullish(),
|
|
244
238
|
/**
|
|
245
239
|
* Whether to enable custom spelling.
|
|
246
240
|
*/
|
|
247
|
-
customSpelling:
|
|
241
|
+
customSpelling: z2.boolean().nullish(),
|
|
248
242
|
/**
|
|
249
243
|
* Configuration for custom spelling.
|
|
250
244
|
*/
|
|
251
|
-
customSpellingConfig:
|
|
245
|
+
customSpellingConfig: z2.object({
|
|
252
246
|
/**
|
|
253
247
|
* Dictionary of custom spellings.
|
|
254
248
|
*/
|
|
255
|
-
spellingDictionary:
|
|
249
|
+
spellingDictionary: z2.record(z2.string(), z2.array(z2.string()))
|
|
256
250
|
}).nullish(),
|
|
257
251
|
/**
|
|
258
252
|
* Whether to extract structured data from the transcription.
|
|
259
253
|
*/
|
|
260
|
-
structuredDataExtraction:
|
|
254
|
+
structuredDataExtraction: z2.boolean().nullish(),
|
|
261
255
|
/**
|
|
262
256
|
* Configuration for structured data extraction.
|
|
263
257
|
*/
|
|
264
|
-
structuredDataExtractionConfig:
|
|
258
|
+
structuredDataExtractionConfig: z2.object({
|
|
265
259
|
/**
|
|
266
260
|
* Classes of data to extract.
|
|
267
261
|
*/
|
|
268
|
-
classes:
|
|
262
|
+
classes: z2.array(z2.string())
|
|
269
263
|
}).nullish(),
|
|
270
264
|
/**
|
|
271
265
|
* Whether to perform sentiment analysis on the transcription.
|
|
272
266
|
*/
|
|
273
|
-
sentimentAnalysis:
|
|
267
|
+
sentimentAnalysis: z2.boolean().nullish(),
|
|
274
268
|
/**
|
|
275
269
|
* Whether to send audio to a language model for processing.
|
|
276
270
|
*/
|
|
277
|
-
audioToLlm:
|
|
271
|
+
audioToLlm: z2.boolean().nullish(),
|
|
278
272
|
/**
|
|
279
273
|
* Configuration for audio to language model processing.
|
|
280
274
|
*/
|
|
281
|
-
audioToLlmConfig:
|
|
275
|
+
audioToLlmConfig: z2.object({
|
|
282
276
|
/**
|
|
283
277
|
* Prompts to send to the language model.
|
|
284
278
|
*/
|
|
285
|
-
prompts:
|
|
279
|
+
prompts: z2.array(z2.string())
|
|
286
280
|
}).nullish(),
|
|
287
281
|
/**
|
|
288
282
|
* Custom metadata to include with the transcription.
|
|
289
283
|
*/
|
|
290
|
-
customMetadata:
|
|
284
|
+
customMetadata: z2.record(z2.string(), z2.any()).nullish(),
|
|
291
285
|
/**
|
|
292
286
|
* Whether to include sentence-level segmentation.
|
|
293
287
|
*/
|
|
294
|
-
sentences:
|
|
288
|
+
sentences: z2.boolean().nullish(),
|
|
295
289
|
/**
|
|
296
290
|
* Whether to enable display mode.
|
|
297
291
|
*/
|
|
298
|
-
displayMode:
|
|
292
|
+
displayMode: z2.boolean().nullish(),
|
|
299
293
|
/**
|
|
300
294
|
* Whether to enhance punctuation in the transcription.
|
|
301
295
|
*/
|
|
302
|
-
punctuationEnhanced:
|
|
296
|
+
punctuationEnhanced: z2.boolean().nullish()
|
|
303
297
|
});
|
|
304
|
-
|
|
298
|
+
|
|
299
|
+
// src/gladia-transcription-model.ts
|
|
300
|
+
var GladiaTranscriptionModel = class _GladiaTranscriptionModel {
|
|
305
301
|
constructor(modelId, config) {
|
|
306
302
|
this.modelId = modelId;
|
|
307
303
|
this.config = config;
|
|
@@ -310,12 +306,21 @@ var GladiaTranscriptionModel = class {
|
|
|
310
306
|
get provider() {
|
|
311
307
|
return this.config.provider;
|
|
312
308
|
}
|
|
309
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
310
|
+
return serializeModelOptions({
|
|
311
|
+
modelId: model.modelId,
|
|
312
|
+
config: model.config
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
316
|
+
return new _GladiaTranscriptionModel(options.modelId, options.config);
|
|
317
|
+
}
|
|
313
318
|
async getArgs({
|
|
314
319
|
providerOptions
|
|
315
320
|
}) {
|
|
316
321
|
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, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N;
|
|
317
322
|
const warnings = [];
|
|
318
|
-
const gladiaOptions = await
|
|
323
|
+
const gladiaOptions = await parseProviderOptions({
|
|
319
324
|
provider: "gladia",
|
|
320
325
|
providerOptions,
|
|
321
326
|
schema: gladiaTranscriptionModelOptionsSchema
|
|
@@ -416,49 +421,50 @@ var GladiaTranscriptionModel = class {
|
|
|
416
421
|
};
|
|
417
422
|
}
|
|
418
423
|
async doGenerate(options) {
|
|
419
|
-
var _a, _b, _c;
|
|
424
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
420
425
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
421
426
|
const formData = new FormData();
|
|
422
|
-
const blob = options.audio instanceof Uint8Array ? new Blob([options.audio]) : new Blob([
|
|
423
|
-
const fileExtension =
|
|
427
|
+
const blob = options.audio instanceof Uint8Array ? new Blob([options.audio]) : new Blob([convertBase64ToUint8Array(options.audio)]);
|
|
428
|
+
const fileExtension = mediaTypeToExtension(options.mediaType);
|
|
424
429
|
formData.append(
|
|
425
430
|
"audio",
|
|
426
431
|
new File([blob], "audio", { type: options.mediaType }),
|
|
427
432
|
`audio.${fileExtension}`
|
|
428
433
|
);
|
|
429
|
-
const { value: uploadResponse } = await
|
|
434
|
+
const { value: uploadResponse } = await postFormDataToApi({
|
|
430
435
|
url: this.config.url({
|
|
431
436
|
path: "/v2/upload",
|
|
432
437
|
modelId: "default"
|
|
433
438
|
}),
|
|
434
|
-
headers: (
|
|
439
|
+
headers: combineHeaders((_e = (_d = this.config).headers) == null ? void 0 : _e.call(_d), options.headers),
|
|
435
440
|
formData,
|
|
436
441
|
failedResponseHandler: gladiaFailedResponseHandler,
|
|
437
|
-
successfulResponseHandler:
|
|
442
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
438
443
|
gladiaUploadResponseSchema
|
|
439
444
|
),
|
|
440
445
|
abortSignal: options.abortSignal,
|
|
441
446
|
fetch: this.config.fetch
|
|
442
447
|
});
|
|
443
448
|
const { body, warnings } = await this.getArgs(options);
|
|
444
|
-
const { value: transcriptionInitResponse } = await
|
|
449
|
+
const { value: transcriptionInitResponse } = await postJsonToApi({
|
|
445
450
|
url: this.config.url({
|
|
446
451
|
path: "/v2/pre-recorded",
|
|
447
452
|
modelId: "default"
|
|
448
453
|
}),
|
|
449
|
-
headers: (
|
|
454
|
+
headers: combineHeaders((_g = (_f = this.config).headers) == null ? void 0 : _g.call(_f), options.headers),
|
|
450
455
|
body: {
|
|
451
456
|
...body,
|
|
452
457
|
audio_url: uploadResponse.audio_url
|
|
453
458
|
},
|
|
454
459
|
failedResponseHandler: gladiaFailedResponseHandler,
|
|
455
|
-
successfulResponseHandler:
|
|
460
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
456
461
|
gladiaTranscriptionInitializeResponseSchema
|
|
457
462
|
),
|
|
458
463
|
abortSignal: options.abortSignal,
|
|
459
464
|
fetch: this.config.fetch
|
|
460
465
|
});
|
|
461
466
|
const resultUrl = transcriptionInitResponse.result_url;
|
|
467
|
+
const apiOrigin = this.config.url({ modelId: "default", path: "" });
|
|
462
468
|
let transcriptionResult;
|
|
463
469
|
let transcriptionResultHeaders;
|
|
464
470
|
const timeoutMs = 60 * 1e3;
|
|
@@ -466,17 +472,17 @@ var GladiaTranscriptionModel = class {
|
|
|
466
472
|
const pollingInterval = 1e3;
|
|
467
473
|
while (true) {
|
|
468
474
|
if (Date.now() - startTime > timeoutMs) {
|
|
469
|
-
throw new
|
|
475
|
+
throw new AISDKError({
|
|
470
476
|
message: "Transcription job polling timed out",
|
|
471
477
|
name: "TranscriptionJobPollingTimedOut",
|
|
472
478
|
cause: transcriptionResult
|
|
473
479
|
});
|
|
474
480
|
}
|
|
475
|
-
const response = await
|
|
481
|
+
const response = await getFromApi({
|
|
476
482
|
url: resultUrl,
|
|
477
|
-
headers: (
|
|
483
|
+
headers: isSameOrigin(resultUrl, apiOrigin) ? combineHeaders((_i = (_h = this.config).headers) == null ? void 0 : _i.call(_h), options.headers) : void 0,
|
|
478
484
|
failedResponseHandler: gladiaFailedResponseHandler,
|
|
479
|
-
successfulResponseHandler:
|
|
485
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
480
486
|
gladiaTranscriptionResultResponseSchema
|
|
481
487
|
),
|
|
482
488
|
abortSignal: options.abortSignal,
|
|
@@ -488,16 +494,16 @@ var GladiaTranscriptionModel = class {
|
|
|
488
494
|
break;
|
|
489
495
|
}
|
|
490
496
|
if (transcriptionResult.status === "error") {
|
|
491
|
-
throw new
|
|
497
|
+
throw new AISDKError({
|
|
492
498
|
message: "Transcription job failed",
|
|
493
499
|
name: "TranscriptionJobFailed",
|
|
494
500
|
cause: transcriptionResult
|
|
495
501
|
});
|
|
496
502
|
}
|
|
497
|
-
await
|
|
503
|
+
await delay(pollingInterval);
|
|
498
504
|
}
|
|
499
505
|
if (!transcriptionResult.result) {
|
|
500
|
-
throw new
|
|
506
|
+
throw new AISDKError({
|
|
501
507
|
message: "Transcription result is empty",
|
|
502
508
|
name: "TranscriptionResultEmpty",
|
|
503
509
|
cause: transcriptionResult
|
|
@@ -526,26 +532,26 @@ var GladiaTranscriptionModel = class {
|
|
|
526
532
|
};
|
|
527
533
|
}
|
|
528
534
|
};
|
|
529
|
-
var gladiaUploadResponseSchema =
|
|
530
|
-
audio_url:
|
|
535
|
+
var gladiaUploadResponseSchema = z3.object({
|
|
536
|
+
audio_url: z3.string()
|
|
531
537
|
});
|
|
532
|
-
var gladiaTranscriptionInitializeResponseSchema =
|
|
533
|
-
result_url:
|
|
538
|
+
var gladiaTranscriptionInitializeResponseSchema = z3.object({
|
|
539
|
+
result_url: z3.string()
|
|
534
540
|
});
|
|
535
|
-
var gladiaTranscriptionResultResponseSchema =
|
|
536
|
-
status:
|
|
537
|
-
result:
|
|
538
|
-
metadata:
|
|
539
|
-
audio_duration:
|
|
541
|
+
var gladiaTranscriptionResultResponseSchema = z3.object({
|
|
542
|
+
status: z3.enum(["queued", "processing", "done", "error"]),
|
|
543
|
+
result: z3.object({
|
|
544
|
+
metadata: z3.object({
|
|
545
|
+
audio_duration: z3.number()
|
|
540
546
|
}),
|
|
541
|
-
transcription:
|
|
542
|
-
full_transcript:
|
|
543
|
-
languages:
|
|
544
|
-
utterances:
|
|
545
|
-
|
|
546
|
-
start:
|
|
547
|
-
end:
|
|
548
|
-
text:
|
|
547
|
+
transcription: z3.object({
|
|
548
|
+
full_transcript: z3.string(),
|
|
549
|
+
languages: z3.array(z3.string()),
|
|
550
|
+
utterances: z3.array(
|
|
551
|
+
z3.object({
|
|
552
|
+
start: z3.number(),
|
|
553
|
+
end: z3.number(),
|
|
554
|
+
text: z3.string()
|
|
549
555
|
})
|
|
550
556
|
)
|
|
551
557
|
})
|
|
@@ -553,13 +559,13 @@ var gladiaTranscriptionResultResponseSchema = import_v42.z.object({
|
|
|
553
559
|
});
|
|
554
560
|
|
|
555
561
|
// src/version.ts
|
|
556
|
-
var VERSION = true ? "3.0.0-beta.
|
|
562
|
+
var VERSION = true ? "3.0.0-beta.50" : "0.0.0-test";
|
|
557
563
|
|
|
558
564
|
// src/gladia-provider.ts
|
|
559
565
|
function createGladia(options = {}) {
|
|
560
|
-
const getHeaders = () =>
|
|
566
|
+
const getHeaders = () => withUserAgentSuffix(
|
|
561
567
|
{
|
|
562
|
-
"x-gladia-key":
|
|
568
|
+
"x-gladia-key": loadApiKey({
|
|
563
569
|
apiKey: options.apiKey,
|
|
564
570
|
environmentVariableName: "GLADIA_API_KEY",
|
|
565
571
|
description: "Gladia"
|
|
@@ -583,14 +589,14 @@ function createGladia(options = {}) {
|
|
|
583
589
|
provider.transcription = createTranscriptionModel;
|
|
584
590
|
provider.transcriptionModel = createTranscriptionModel;
|
|
585
591
|
provider.languageModel = (modelId) => {
|
|
586
|
-
throw new
|
|
592
|
+
throw new NoSuchModelError({
|
|
587
593
|
modelId,
|
|
588
594
|
modelType: "languageModel",
|
|
589
595
|
message: "Gladia does not provide language models"
|
|
590
596
|
});
|
|
591
597
|
};
|
|
592
598
|
provider.embeddingModel = (modelId) => {
|
|
593
|
-
throw new
|
|
599
|
+
throw new NoSuchModelError({
|
|
594
600
|
modelId,
|
|
595
601
|
modelType: "embeddingModel",
|
|
596
602
|
message: "Gladia does not provide embedding models"
|
|
@@ -598,7 +604,7 @@ function createGladia(options = {}) {
|
|
|
598
604
|
};
|
|
599
605
|
provider.textEmbeddingModel = provider.embeddingModel;
|
|
600
606
|
provider.imageModel = (modelId) => {
|
|
601
|
-
throw new
|
|
607
|
+
throw new NoSuchModelError({
|
|
602
608
|
modelId,
|
|
603
609
|
modelType: "imageModel",
|
|
604
610
|
message: "Gladia does not provide image models"
|
|
@@ -607,10 +613,9 @@ function createGladia(options = {}) {
|
|
|
607
613
|
return provider;
|
|
608
614
|
}
|
|
609
615
|
var gladia = createGladia();
|
|
610
|
-
|
|
611
|
-
0 && (module.exports = {
|
|
616
|
+
export {
|
|
612
617
|
VERSION,
|
|
613
618
|
createGladia,
|
|
614
619
|
gladia
|
|
615
|
-
}
|
|
620
|
+
};
|
|
616
621
|
//# sourceMappingURL=index.js.map
|