@ai-sdk/lmnt 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/lmnt-error.test.ts +0 -34
- package/src/lmnt-speech-model.test.ts +0 -197
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @ai-sdk/lmnt
|
|
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
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/lmnt",
|
|
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/lmnt-error.test.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { safeParseJSON } from '@ai-sdk/provider-utils';
|
|
2
|
-
import { lmntErrorDataSchema } from './lmnt-error';
|
|
3
|
-
import { describe, it, expect } from 'vitest';
|
|
4
|
-
|
|
5
|
-
describe('lmntErrorDataSchema', () => {
|
|
6
|
-
it('should parse LMNT 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: lmntErrorDataSchema,
|
|
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,197 +0,0 @@
|
|
|
1
|
-
import { createTestServer } from '@ai-sdk/test-server/with-vitest';
|
|
2
|
-
import { LMNTSpeechModel } from './lmnt-speech-model';
|
|
3
|
-
import { createLMNT } from './lmnt-provider';
|
|
4
|
-
import { describe, it, expect, vi } from 'vitest';
|
|
5
|
-
|
|
6
|
-
vi.mock('./version', () => ({
|
|
7
|
-
VERSION: '0.0.0-test',
|
|
8
|
-
}));
|
|
9
|
-
|
|
10
|
-
const provider = createLMNT({ apiKey: 'test-api-key' });
|
|
11
|
-
const model = provider.speech('aurora');
|
|
12
|
-
|
|
13
|
-
const server = createTestServer({
|
|
14
|
-
'https://api.lmnt.com/v1/ai/speech/bytes': {},
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
describe('doGenerate', () => {
|
|
18
|
-
function prepareAudioResponse({
|
|
19
|
-
headers,
|
|
20
|
-
format = 'mp3',
|
|
21
|
-
}: {
|
|
22
|
-
headers?: Record<string, string>;
|
|
23
|
-
format?: 'aac' | 'mp3' | 'mulaw' | 'raw' | 'wav';
|
|
24
|
-
} = {}) {
|
|
25
|
-
const audioBuffer = new Uint8Array(100); // Mock audio data
|
|
26
|
-
server.urls['https://api.lmnt.com/v1/ai/speech/bytes'].response = {
|
|
27
|
-
type: 'binary',
|
|
28
|
-
headers: {
|
|
29
|
-
'content-type': `audio/${format}`,
|
|
30
|
-
...headers,
|
|
31
|
-
},
|
|
32
|
-
body: Buffer.from(audioBuffer),
|
|
33
|
-
};
|
|
34
|
-
return audioBuffer;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
it('should pass the model and text', async () => {
|
|
38
|
-
prepareAudioResponse();
|
|
39
|
-
|
|
40
|
-
await model.doGenerate({
|
|
41
|
-
text: 'Hello from the AI SDK!',
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
expect(await server.calls[0].requestBodyJson).toMatchObject({
|
|
45
|
-
model: 'aurora',
|
|
46
|
-
text: 'Hello from the AI SDK!',
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('should pass headers', async () => {
|
|
51
|
-
prepareAudioResponse();
|
|
52
|
-
|
|
53
|
-
const provider = createLMNT({
|
|
54
|
-
apiKey: 'test-api-key',
|
|
55
|
-
headers: {
|
|
56
|
-
'Custom-Provider-Header': 'provider-header-value',
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
await provider.speech('aurora').doGenerate({
|
|
61
|
-
text: 'Hello from the AI SDK!',
|
|
62
|
-
headers: {
|
|
63
|
-
'Custom-Request-Header': 'request-header-value',
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
expect(server.calls[0].requestHeaders).toMatchObject({
|
|
68
|
-
'x-api-key': 'test-api-key',
|
|
69
|
-
'content-type': 'application/json',
|
|
70
|
-
'custom-provider-header': 'provider-header-value',
|
|
71
|
-
'custom-request-header': 'request-header-value',
|
|
72
|
-
});
|
|
73
|
-
expect(server.calls[0].requestUserAgent).toContain(
|
|
74
|
-
`ai-sdk/lmnt/0.0.0-test`,
|
|
75
|
-
);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('should pass options', async () => {
|
|
79
|
-
prepareAudioResponse();
|
|
80
|
-
|
|
81
|
-
await model.doGenerate({
|
|
82
|
-
text: 'Hello from the AI SDK!',
|
|
83
|
-
voice: 'nova',
|
|
84
|
-
outputFormat: 'mp3',
|
|
85
|
-
speed: 1.5,
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
expect(await server.calls[0].requestBodyJson).toMatchObject({
|
|
89
|
-
model: 'aurora',
|
|
90
|
-
text: 'Hello from the AI SDK!',
|
|
91
|
-
voice: 'nova',
|
|
92
|
-
speed: 1.5,
|
|
93
|
-
response_format: 'mp3',
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('should return audio data with correct content type', async () => {
|
|
98
|
-
const audio = new Uint8Array(100); // Mock audio data
|
|
99
|
-
prepareAudioResponse({
|
|
100
|
-
format: 'mp3',
|
|
101
|
-
headers: {
|
|
102
|
-
'x-request-id': 'test-request-id',
|
|
103
|
-
'x-ratelimit-remaining': '123',
|
|
104
|
-
},
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
const result = await model.doGenerate({
|
|
108
|
-
text: 'Hello from the AI SDK!',
|
|
109
|
-
outputFormat: 'mp3',
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
expect(result.audio).toStrictEqual(audio);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('should include response data with timestamp, modelId and headers', async () => {
|
|
116
|
-
prepareAudioResponse({
|
|
117
|
-
headers: {
|
|
118
|
-
'x-request-id': 'test-request-id',
|
|
119
|
-
'x-ratelimit-remaining': '123',
|
|
120
|
-
},
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
const testDate = new Date(0);
|
|
124
|
-
const customModel = new LMNTSpeechModel('aurora', {
|
|
125
|
-
provider: 'test-provider',
|
|
126
|
-
url: () => 'https://api.lmnt.com/v1/ai/speech/bytes',
|
|
127
|
-
headers: () => ({}),
|
|
128
|
-
_internal: {
|
|
129
|
-
currentDate: () => testDate,
|
|
130
|
-
},
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
const result = await customModel.doGenerate({
|
|
134
|
-
text: 'Hello from the AI SDK!',
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
expect(result.response).toMatchObject({
|
|
138
|
-
timestamp: testDate,
|
|
139
|
-
modelId: 'aurora',
|
|
140
|
-
headers: {
|
|
141
|
-
'content-type': 'audio/mp3',
|
|
142
|
-
'x-request-id': 'test-request-id',
|
|
143
|
-
'x-ratelimit-remaining': '123',
|
|
144
|
-
},
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it('should use real date when no custom date provider is specified', async () => {
|
|
149
|
-
prepareAudioResponse();
|
|
150
|
-
|
|
151
|
-
const testDate = new Date(0);
|
|
152
|
-
const customModel = new LMNTSpeechModel('aurora', {
|
|
153
|
-
provider: 'test-provider',
|
|
154
|
-
url: () => 'https://api.lmnt.com/v1/ai/speech/bytes',
|
|
155
|
-
headers: () => ({}),
|
|
156
|
-
_internal: {
|
|
157
|
-
currentDate: () => testDate,
|
|
158
|
-
},
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
const result = await customModel.doGenerate({
|
|
162
|
-
text: 'Hello from the AI SDK!',
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
expect(result.response.timestamp.getTime()).toEqual(testDate.getTime());
|
|
166
|
-
expect(result.response.modelId).toBe('aurora');
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it('should handle different audio formats', async () => {
|
|
170
|
-
const formats = ['aac', 'mp3', 'mulaw', 'raw', 'wav'] as const;
|
|
171
|
-
|
|
172
|
-
for (const format of formats) {
|
|
173
|
-
const audio = prepareAudioResponse({ format });
|
|
174
|
-
|
|
175
|
-
const result = await model.doGenerate({
|
|
176
|
-
text: 'Hello from the AI SDK!',
|
|
177
|
-
providerOptions: {
|
|
178
|
-
lmnt: {
|
|
179
|
-
format,
|
|
180
|
-
},
|
|
181
|
-
},
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
expect(result.audio).toStrictEqual(audio);
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it('should include warnings if any are generated', async () => {
|
|
189
|
-
prepareAudioResponse();
|
|
190
|
-
|
|
191
|
-
const result = await model.doGenerate({
|
|
192
|
-
text: 'Hello from the AI SDK!',
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
expect(result.warnings).toEqual([]);
|
|
196
|
-
});
|
|
197
|
-
});
|