@ai-sdk/gladia 2.0.10 → 2.0.12

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 CHANGED
@@ -1,5 +1,21 @@
1
1
  # @ai-sdk/gladia
2
2
 
3
+ ## 2.0.12
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [462ad00]
8
+ - @ai-sdk/provider-utils@4.0.10
9
+
10
+ ## 2.0.11
11
+
12
+ ### Patch Changes
13
+
14
+ - 4de5a1d: chore: excluded tests from src folder in npm package
15
+ - Updated dependencies [4de5a1d]
16
+ - @ai-sdk/provider@3.0.5
17
+ - @ai-sdk/provider-utils@4.0.9
18
+
3
19
  ## 2.0.10
4
20
 
5
21
  ### Patch Changes
package/dist/index.js CHANGED
@@ -553,7 +553,7 @@ var gladiaTranscriptionResultResponseSchema = import_v42.z.object({
553
553
  });
554
554
 
555
555
  // src/version.ts
556
- var VERSION = true ? "2.0.10" : "0.0.0-test";
556
+ var VERSION = true ? "2.0.12" : "0.0.0-test";
557
557
 
558
558
  // src/gladia-provider.ts
559
559
  function createGladia(options = {}) {
package/dist/index.mjs CHANGED
@@ -542,7 +542,7 @@ var gladiaTranscriptionResultResponseSchema = z2.object({
542
542
  });
543
543
 
544
544
  // src/version.ts
545
- var VERSION = true ? "2.0.10" : "0.0.0-test";
545
+ var VERSION = true ? "2.0.12" : "0.0.0-test";
546
546
 
547
547
  // src/gladia-provider.ts
548
548
  function createGladia(options = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/gladia",
3
- "version": "2.0.10",
3
+ "version": "2.0.12",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -10,6 +10,10 @@
10
10
  "dist/**/*",
11
11
  "docs/**/*",
12
12
  "src",
13
+ "!src/**/*.test.ts",
14
+ "!src/**/*.test-d.ts",
15
+ "!src/**/__snapshots__",
16
+ "!src/**/__fixtures__",
13
17
  "CHANGELOG.md",
14
18
  "README.md"
15
19
  ],
@@ -25,15 +29,15 @@
25
29
  }
26
30
  },
27
31
  "dependencies": {
28
- "@ai-sdk/provider": "3.0.4",
29
- "@ai-sdk/provider-utils": "4.0.8"
32
+ "@ai-sdk/provider": "3.0.5",
33
+ "@ai-sdk/provider-utils": "4.0.10"
30
34
  },
31
35
  "devDependencies": {
32
36
  "@types/node": "20.17.24",
33
37
  "tsup": "^8",
34
38
  "typescript": "5.6.3",
35
39
  "zod": "3.25.76",
36
- "@ai-sdk/test-server": "1.0.2",
40
+ "@ai-sdk/test-server": "1.0.3",
37
41
  "@vercel/ai-tsconfig": "0.0.0"
38
42
  },
39
43
  "peerDependencies": {
@@ -1,34 +0,0 @@
1
- import { safeParseJSON } from '@ai-sdk/provider-utils';
2
- import { gladiaErrorDataSchema } from './gladia-error';
3
- import { describe, it, expect } from 'vitest';
4
-
5
- describe('gladiaErrorDataSchema', () => {
6
- it('should parse Gladia resource exhausted error', async () => {
7
- const error = `
8
- {"error":{"message":"{\\n \\"error\\": {\\n \\"code\\": 429,\\n \\"message\\": \\"Resource has been exhausted (e.g. check quota).\\",\\n \\"status\\": \\"RESOURCE_EXHAUSTED\\"\\n }\\n}\\n","code":429}}
9
- `;
10
-
11
- const result = await safeParseJSON({
12
- text: error,
13
- schema: gladiaErrorDataSchema,
14
- });
15
-
16
- expect(result).toStrictEqual({
17
- success: true,
18
- value: {
19
- error: {
20
- message:
21
- '{\n "error": {\n "code": 429,\n "message": "Resource has been exhausted (e.g. check quota).",\n "status": "RESOURCE_EXHAUSTED"\n }\n}\n',
22
- code: 429,
23
- },
24
- },
25
- rawValue: {
26
- error: {
27
- message:
28
- '{\n "error": {\n "code": 429,\n "message": "Resource has been exhausted (e.g. check quota).",\n "status": "RESOURCE_EXHAUSTED"\n }\n}\n',
29
- code: 429,
30
- },
31
- },
32
- });
33
- });
34
- });
@@ -1,230 +0,0 @@
1
- import { createTestServer } from '@ai-sdk/test-server/with-vitest';
2
- import { GladiaTranscriptionModel } from './gladia-transcription-model';
3
- import { createGladia } from './gladia-provider';
4
- import { readFile } from 'node:fs/promises';
5
- import path from 'node:path';
6
- import { describe, it, expect, vi } from 'vitest';
7
-
8
- vi.mock('./version', () => ({
9
- VERSION: '0.0.0-test',
10
- }));
11
-
12
- const audioData = await readFile(path.join(__dirname, 'transcript-test.mp3'));
13
- const provider = createGladia({ apiKey: 'test-api-key' });
14
- const model = provider.transcription();
15
-
16
- const server = createTestServer({
17
- 'https://api.gladia.io/v2/upload': {
18
- response: {
19
- type: 'json-value',
20
- body: {
21
- audio_url: 'https://storage.gladia.io/mock-upload-url',
22
- audio_metadata: {
23
- id: 'test-id',
24
- filename: 'test-file.mp3',
25
- extension: 'mp3',
26
- size: 1024,
27
- audio_duration: 60,
28
- number_of_channels: 2,
29
- },
30
- },
31
- },
32
- },
33
- 'https://api.gladia.io/v2/pre-recorded': {},
34
- 'https://api.gladia.io/v2/transcription/test-id': {},
35
- });
36
-
37
- describe('doGenerate', () => {
38
- function prepareJsonResponse({
39
- headers,
40
- }: {
41
- headers?: Record<string, string>;
42
- } = {}) {
43
- // No need to set the upload response here as it's already set in the server creation
44
- server.urls['https://api.gladia.io/v2/pre-recorded'].response = {
45
- type: 'json-value',
46
- headers,
47
- body: {
48
- id: 'test-id',
49
- result_url: 'https://api.gladia.io/v2/transcription/test-id',
50
- },
51
- };
52
- server.urls['https://api.gladia.io/v2/transcription/test-id'].response = {
53
- type: 'json-value',
54
- headers,
55
- body: {
56
- id: '45463597-20b7-4af7-b3b3-f5fb778203ab',
57
- request_id: 'G-45463597',
58
- version: 2,
59
- status: 'done',
60
- created_at: '2023-12-28T09:04:17.210Z',
61
- completed_at: '2023-12-28T09:04:37.210Z',
62
- custom_metadata: {},
63
- error_code: null,
64
- kind: 'pre-recorded',
65
- file: {
66
- id: 'test-id',
67
- filename: 'test-file.mp3',
68
- source: 'upload',
69
- audio_duration: 60,
70
- number_of_channels: 2,
71
- },
72
- request_params: {
73
- audio_url: 'https://storage.gladia.io/mock-upload-url',
74
- },
75
- result: {
76
- metadata: {
77
- audio_duration: 60,
78
- number_of_distinct_channels: 2,
79
- billing_time: 60,
80
- transcription_time: 20,
81
- },
82
- transcription: {
83
- full_transcript: 'Smoke from hundreds of wildfires.',
84
- languages: ['en'],
85
- utterances: [
86
- {
87
- language: 'en',
88
- start: 0,
89
- end: 3,
90
- confidence: 0.95,
91
- channel: 1,
92
- speaker: 1,
93
- words: [
94
- {
95
- word: 'Smoke',
96
- start: 0,
97
- end: 1,
98
- confidence: 0.95,
99
- },
100
- {
101
- word: 'from',
102
- start: 1,
103
- end: 2,
104
- confidence: 0.95,
105
- },
106
- {
107
- word: 'hundreds',
108
- start: 2,
109
- end: 3,
110
- confidence: 0.95,
111
- },
112
- ],
113
- text: 'Smoke from hundreds of wildfires.',
114
- },
115
- ],
116
- },
117
- },
118
- },
119
- };
120
- }
121
-
122
- it('should pass the model', async () => {
123
- prepareJsonResponse();
124
-
125
- await model.doGenerate({
126
- audio: audioData,
127
- mediaType: 'audio/wav',
128
- });
129
-
130
- expect(await server.calls[1].requestBodyJson).toMatchObject({
131
- audio_url: 'https://storage.gladia.io/mock-upload-url',
132
- });
133
- });
134
-
135
- it('should pass headers', async () => {
136
- prepareJsonResponse();
137
-
138
- const provider = createGladia({
139
- apiKey: 'test-api-key',
140
- headers: {
141
- 'Custom-Provider-Header': 'provider-header-value',
142
- },
143
- });
144
-
145
- await provider.transcription().doGenerate({
146
- audio: audioData,
147
- mediaType: 'audio/wav',
148
- headers: {
149
- 'Custom-Request-Header': 'request-header-value',
150
- },
151
- });
152
-
153
- expect(server.calls[1].requestHeaders).toMatchObject({
154
- 'x-gladia-key': 'test-api-key',
155
- 'content-type': 'application/json',
156
- 'custom-provider-header': 'provider-header-value',
157
- 'custom-request-header': 'request-header-value',
158
- });
159
- expect(server.calls[0].requestUserAgent).toContain(
160
- `ai-sdk/gladia/0.0.0-test`,
161
- );
162
- });
163
-
164
- it('should extract the transcription text', async () => {
165
- prepareJsonResponse();
166
-
167
- const result = await model.doGenerate({
168
- audio: audioData,
169
- mediaType: 'audio/wav',
170
- });
171
-
172
- expect(result.text).toBe('Smoke from hundreds of wildfires.');
173
- });
174
-
175
- it('should include response data with timestamp, modelId and headers', async () => {
176
- prepareJsonResponse({
177
- headers: {
178
- 'x-request-id': 'test-request-id',
179
- 'x-ratelimit-remaining': '123',
180
- },
181
- });
182
-
183
- const testDate = new Date(0);
184
- const customModel = new GladiaTranscriptionModel('default', {
185
- provider: 'test-provider',
186
- url: ({ path }) => `https://api.gladia.io${path}`,
187
- headers: () => ({}),
188
- _internal: {
189
- currentDate: () => testDate,
190
- },
191
- });
192
-
193
- const result = await customModel.doGenerate({
194
- audio: audioData,
195
- mediaType: 'audio/wav',
196
- });
197
-
198
- expect(result.response).toMatchObject({
199
- timestamp: testDate,
200
- modelId: 'default',
201
- headers: {
202
- 'content-type': 'application/json',
203
- 'x-request-id': 'test-request-id',
204
- 'x-ratelimit-remaining': '123',
205
- },
206
- });
207
- });
208
-
209
- it('should use real date when no custom date provider is specified', async () => {
210
- prepareJsonResponse();
211
-
212
- const testDate = new Date(0);
213
- const customModel = new GladiaTranscriptionModel('default', {
214
- provider: 'test-provider',
215
- url: ({ path }) => `https://api.gladia.io${path}`,
216
- headers: () => ({}),
217
- _internal: {
218
- currentDate: () => testDate,
219
- },
220
- });
221
-
222
- const result = await customModel.doGenerate({
223
- audio: audioData,
224
- mediaType: 'audio/wav',
225
- });
226
-
227
- expect(result.response.timestamp.getTime()).toEqual(testDate.getTime());
228
- expect(result.response.modelId).toBe('default');
229
- });
230
- });