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