@ai-sdk/revai 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 +16 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +8 -4
- package/src/revai-error.test.ts +0 -34
- package/src/revai-transcription-model.test.ts +0 -282
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @ai-sdk/revai
|
|
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
|
@@ -455,7 +455,7 @@ var revaiTranscriptionResponseSchema = import_v42.z.object({
|
|
|
455
455
|
});
|
|
456
456
|
|
|
457
457
|
// src/version.ts
|
|
458
|
-
var VERSION = true ? "2.0.
|
|
458
|
+
var VERSION = true ? "2.0.12" : "0.0.0-test";
|
|
459
459
|
|
|
460
460
|
// src/revai-provider.ts
|
|
461
461
|
function createRevai(options = {}) {
|
package/dist/index.mjs
CHANGED
|
@@ -443,7 +443,7 @@ var revaiTranscriptionResponseSchema = z2.object({
|
|
|
443
443
|
});
|
|
444
444
|
|
|
445
445
|
// src/version.ts
|
|
446
|
-
var VERSION = true ? "2.0.
|
|
446
|
+
var VERSION = true ? "2.0.12" : "0.0.0-test";
|
|
447
447
|
|
|
448
448
|
// src/revai-provider.ts
|
|
449
449
|
function createRevai(options = {}) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/revai",
|
|
3
|
-
"version": "2.0.
|
|
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.
|
|
29
|
-
"@ai-sdk/provider-utils": "4.0.
|
|
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.
|
|
40
|
+
"@ai-sdk/test-server": "1.0.3",
|
|
37
41
|
"@vercel/ai-tsconfig": "0.0.0"
|
|
38
42
|
},
|
|
39
43
|
"peerDependencies": {
|
package/src/revai-error.test.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { safeParseJSON } from '@ai-sdk/provider-utils';
|
|
2
|
-
import { revaiErrorDataSchema } from './revai-error';
|
|
3
|
-
import { describe, it, expect } from 'vitest';
|
|
4
|
-
|
|
5
|
-
describe('revaiErrorDataSchema', () => {
|
|
6
|
-
it('should parse Rev.ai 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: revaiErrorDataSchema,
|
|
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,282 +0,0 @@
|
|
|
1
|
-
import { createTestServer } from '@ai-sdk/test-server/with-vitest';
|
|
2
|
-
import { RevaiTranscriptionModel } from './revai-transcription-model';
|
|
3
|
-
import { createRevai } from './revai-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 = createRevai({ apiKey: 'test-api-key' });
|
|
14
|
-
const model = provider.transcription('machine');
|
|
15
|
-
|
|
16
|
-
const server = createTestServer({
|
|
17
|
-
'https://api.rev.ai/speechtotext/v1/jobs': {},
|
|
18
|
-
'https://api.rev.ai/speechtotext/v1/jobs/test-id': {},
|
|
19
|
-
'https://api.rev.ai/speechtotext/v1/jobs/test-id/transcript': {},
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
describe('doGenerate', () => {
|
|
23
|
-
function prepareJsonResponse({
|
|
24
|
-
headers,
|
|
25
|
-
}: {
|
|
26
|
-
headers?: Record<string, string>;
|
|
27
|
-
} = {}) {
|
|
28
|
-
server.urls['https://api.rev.ai/speechtotext/v1/jobs'].response = {
|
|
29
|
-
type: 'json-value',
|
|
30
|
-
headers,
|
|
31
|
-
body: {
|
|
32
|
-
id: 'test-id',
|
|
33
|
-
status: 'in_progress',
|
|
34
|
-
language: 'en',
|
|
35
|
-
created_on: '2018-05-05T23:23:22.29Z',
|
|
36
|
-
transcriber: 'machine',
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
|
-
server.urls['https://api.rev.ai/speechtotext/v1/jobs/test-id'].response = {
|
|
40
|
-
type: 'json-value',
|
|
41
|
-
headers,
|
|
42
|
-
body: {
|
|
43
|
-
id: 'test-id',
|
|
44
|
-
status: 'transcribed',
|
|
45
|
-
language: 'en',
|
|
46
|
-
created_on: '2018-05-05T23:23:22.29Z',
|
|
47
|
-
transcriber: 'machine',
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
server.urls[
|
|
51
|
-
'https://api.rev.ai/speechtotext/v1/jobs/test-id/transcript'
|
|
52
|
-
].response = {
|
|
53
|
-
type: 'json-value',
|
|
54
|
-
headers,
|
|
55
|
-
body: {
|
|
56
|
-
monologues: [
|
|
57
|
-
{
|
|
58
|
-
speaker: 1,
|
|
59
|
-
elements: [
|
|
60
|
-
{
|
|
61
|
-
type: 'text',
|
|
62
|
-
value: 'Hello',
|
|
63
|
-
ts: 0.5,
|
|
64
|
-
end_ts: 1.5,
|
|
65
|
-
confidence: 1,
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
type: 'punct',
|
|
69
|
-
value: ' ',
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
type: 'text',
|
|
73
|
-
value: 'World',
|
|
74
|
-
ts: 1.75,
|
|
75
|
-
end_ts: 2.85,
|
|
76
|
-
confidence: 0.8,
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
type: 'punct',
|
|
80
|
-
value: '.',
|
|
81
|
-
},
|
|
82
|
-
],
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
speaker: 2,
|
|
86
|
-
elements: [
|
|
87
|
-
{
|
|
88
|
-
type: 'text',
|
|
89
|
-
value: 'monologues',
|
|
90
|
-
ts: 3,
|
|
91
|
-
end_ts: 3.5,
|
|
92
|
-
confidence: 1,
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
type: 'punct',
|
|
96
|
-
value: ' ',
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
type: 'text',
|
|
100
|
-
value: 'are',
|
|
101
|
-
ts: 3.6,
|
|
102
|
-
end_ts: 3.9,
|
|
103
|
-
confidence: 1,
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
type: 'punct',
|
|
107
|
-
value: ' ',
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
type: 'text',
|
|
111
|
-
value: 'a',
|
|
112
|
-
ts: 4,
|
|
113
|
-
end_ts: 4.3,
|
|
114
|
-
confidence: 1,
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
type: 'punct',
|
|
118
|
-
value: ' ',
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
type: 'text',
|
|
122
|
-
value: 'block',
|
|
123
|
-
ts: 4.5,
|
|
124
|
-
end_ts: 5.5,
|
|
125
|
-
confidence: 1,
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
type: 'punct',
|
|
129
|
-
value: ' ',
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
type: 'text',
|
|
133
|
-
value: 'of',
|
|
134
|
-
ts: 5.75,
|
|
135
|
-
end_ts: 6.14,
|
|
136
|
-
confidence: 1,
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
type: 'punct',
|
|
140
|
-
value: ' ',
|
|
141
|
-
},
|
|
142
|
-
{
|
|
143
|
-
type: 'unknown',
|
|
144
|
-
value: '<inaudible>',
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
type: 'punct',
|
|
148
|
-
value: ' ',
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
type: 'text',
|
|
152
|
-
value: 'text',
|
|
153
|
-
ts: 6.5,
|
|
154
|
-
end_ts: 7.78,
|
|
155
|
-
confidence: 1,
|
|
156
|
-
},
|
|
157
|
-
{
|
|
158
|
-
type: 'punct',
|
|
159
|
-
value: '.',
|
|
160
|
-
},
|
|
161
|
-
],
|
|
162
|
-
},
|
|
163
|
-
],
|
|
164
|
-
},
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
it('should pass the model', async () => {
|
|
169
|
-
prepareJsonResponse();
|
|
170
|
-
|
|
171
|
-
await model.doGenerate({
|
|
172
|
-
audio: audioData,
|
|
173
|
-
mediaType: 'audio/wav',
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
expect(await server.calls[0].requestBodyMultipart).toMatchObject({
|
|
177
|
-
media: expect.any(File),
|
|
178
|
-
config: '{"transcriber":"machine"}',
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it('should pass headers', async () => {
|
|
183
|
-
prepareJsonResponse();
|
|
184
|
-
|
|
185
|
-
const provider = createRevai({
|
|
186
|
-
apiKey: 'test-api-key',
|
|
187
|
-
headers: {
|
|
188
|
-
'Custom-Provider-Header': 'provider-header-value',
|
|
189
|
-
},
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
await provider.transcription('machine').doGenerate({
|
|
193
|
-
audio: audioData,
|
|
194
|
-
mediaType: 'audio/wav',
|
|
195
|
-
headers: {
|
|
196
|
-
'Custom-Request-Header': 'request-header-value',
|
|
197
|
-
},
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
expect(server.calls[0].requestHeaders).toMatchObject({
|
|
201
|
-
authorization: 'Bearer test-api-key',
|
|
202
|
-
'content-type': expect.stringMatching(
|
|
203
|
-
/^multipart\/form-data; boundary=----formdata-undici-\d+$/,
|
|
204
|
-
),
|
|
205
|
-
'custom-provider-header': 'provider-header-value',
|
|
206
|
-
'custom-request-header': 'request-header-value',
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
expect(server.calls[0].requestUserAgent).toContain(
|
|
210
|
-
`ai-sdk/revai/0.0.0-test`,
|
|
211
|
-
);
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
it('should extract the transcription text', async () => {
|
|
215
|
-
prepareJsonResponse();
|
|
216
|
-
|
|
217
|
-
const result = await model.doGenerate({
|
|
218
|
-
audio: audioData,
|
|
219
|
-
mediaType: 'audio/wav',
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
expect(result.text).toBe(
|
|
223
|
-
'Hello World. monologues are a block of <inaudible> text.',
|
|
224
|
-
);
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
it('should include response data with timestamp, modelId and headers', async () => {
|
|
228
|
-
prepareJsonResponse({
|
|
229
|
-
headers: {
|
|
230
|
-
'x-request-id': 'test-request-id',
|
|
231
|
-
'x-ratelimit-remaining': '123',
|
|
232
|
-
},
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
const testDate = new Date(0);
|
|
236
|
-
const customModel = new RevaiTranscriptionModel('machine', {
|
|
237
|
-
provider: 'test-provider',
|
|
238
|
-
url: ({ path }) => `https://api.rev.ai${path}`,
|
|
239
|
-
headers: () => ({}),
|
|
240
|
-
_internal: {
|
|
241
|
-
currentDate: () => testDate,
|
|
242
|
-
},
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
const result = await customModel.doGenerate({
|
|
246
|
-
audio: audioData,
|
|
247
|
-
mediaType: 'audio/wav',
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
expect(result.response).toMatchObject({
|
|
251
|
-
timestamp: testDate,
|
|
252
|
-
modelId: 'machine',
|
|
253
|
-
headers: {
|
|
254
|
-
'content-type': 'application/json',
|
|
255
|
-
'x-request-id': 'test-request-id',
|
|
256
|
-
'x-ratelimit-remaining': '123',
|
|
257
|
-
},
|
|
258
|
-
});
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
it('should use real date when no custom date provider is specified', async () => {
|
|
262
|
-
prepareJsonResponse();
|
|
263
|
-
|
|
264
|
-
const testDate = new Date(0);
|
|
265
|
-
const customModel = new RevaiTranscriptionModel('machine', {
|
|
266
|
-
provider: 'test-provider',
|
|
267
|
-
url: ({ path }) => `https://api.rev.ai${path}`,
|
|
268
|
-
headers: () => ({}),
|
|
269
|
-
_internal: {
|
|
270
|
-
currentDate: () => testDate,
|
|
271
|
-
},
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
const result = await customModel.doGenerate({
|
|
275
|
-
audio: audioData,
|
|
276
|
-
mediaType: 'audio/wav',
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
expect(result.response.timestamp.getTime()).toEqual(testDate.getTime());
|
|
280
|
-
expect(result.response.modelId).toBe('machine');
|
|
281
|
-
});
|
|
282
|
-
});
|