language-models 2.1.3 → 2.4.0
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +28 -0
- package/README.md +2 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -1
- package/dist/index.js.map +1 -1
- package/dist/models.d.ts +1 -1
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +8 -10
- package/dist/models.js.map +1 -1
- package/dist/policy.d.ts +127 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +246 -0
- package/dist/policy.js.map +1 -0
- package/dist/pricing/index.d.ts +19 -0
- package/dist/pricing/index.d.ts.map +1 -0
- package/dist/pricing/index.js +18 -0
- package/dist/pricing/index.js.map +1 -0
- package/dist/pricing/lookup.d.ts +46 -0
- package/dist/pricing/lookup.d.ts.map +1 -0
- package/dist/pricing/lookup.js +94 -0
- package/dist/pricing/lookup.js.map +1 -0
- package/dist/pricing/table.d.ts +46 -0
- package/dist/pricing/table.d.ts.map +1 -0
- package/dist/pricing/table.js +214 -0
- package/dist/pricing/table.js.map +1 -0
- package/dist/pricing/types.d.ts +84 -0
- package/dist/pricing/types.d.ts.map +1 -0
- package/dist/pricing/types.js +32 -0
- package/dist/pricing/types.js.map +1 -0
- package/package.json +16 -12
- package/src/index.ts +42 -1
- package/src/models.ts +8 -12
- package/src/policy.ts +343 -0
- package/src/pricing/index.ts +29 -0
- package/src/pricing/lookup.ts +124 -0
- package/src/pricing/table.ts +235 -0
- package/src/pricing/types.ts +90 -0
- package/{src → test}/aliases.test.ts +20 -22
- package/{src → test}/index.test.ts +9 -9
- package/{src → test}/models.test.ts +8 -6
- package/test/policy.test.ts +203 -0
- package/test/pricing.test.ts +279 -0
- package/vitest.config.ts +21 -1
- package/.turbo/turbo-test.log +0 -18
- package/LICENSE +0 -21
- package/src/aliases.js +0 -40
- package/src/aliases.test.js +0 -264
- package/src/index.js +0 -9
- package/src/index.test.js +0 -320
- package/src/models.js +0 -108
- package/src/models.test.js +0 -335
- package/vitest.config.js +0 -10
package/src/aliases.test.js
DELETED
|
@@ -1,264 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for model aliases
|
|
3
|
-
*
|
|
4
|
-
* These tests verify the alias mapping and ensure all documented
|
|
5
|
-
* aliases are present and correctly mapped.
|
|
6
|
-
*/
|
|
7
|
-
import { describe, it, expect } from 'vitest';
|
|
8
|
-
import { ALIASES } from './aliases.js';
|
|
9
|
-
describe('ALIASES', () => {
|
|
10
|
-
it('is an object', () => {
|
|
11
|
-
expect(typeof ALIASES).toBe('object');
|
|
12
|
-
expect(ALIASES).not.toBeNull();
|
|
13
|
-
});
|
|
14
|
-
it('has string keys and values', () => {
|
|
15
|
-
for (const [key, value] of Object.entries(ALIASES)) {
|
|
16
|
-
expect(typeof key).toBe('string');
|
|
17
|
-
expect(typeof value).toBe('string');
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
it('has no empty keys or values', () => {
|
|
21
|
-
for (const [key, value] of Object.entries(ALIASES)) {
|
|
22
|
-
expect(key.length).toBeGreaterThan(0);
|
|
23
|
-
expect(value.length).toBeGreaterThan(0);
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
it('all values are valid model IDs with provider prefix', () => {
|
|
27
|
-
for (const [key, value] of Object.entries(ALIASES)) {
|
|
28
|
-
expect(value).toContain('/');
|
|
29
|
-
const [provider, modelName] = value.split('/');
|
|
30
|
-
expect(provider.length).toBeGreaterThan(0);
|
|
31
|
-
expect(modelName.length).toBeGreaterThan(0);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
describe('Claude (Anthropic) aliases', () => {
|
|
35
|
-
it('has opus alias', () => {
|
|
36
|
-
expect(ALIASES['opus']).toBe('anthropic/claude-opus-4.5');
|
|
37
|
-
});
|
|
38
|
-
it('has sonnet alias', () => {
|
|
39
|
-
expect(ALIASES['sonnet']).toBe('anthropic/claude-sonnet-4.5');
|
|
40
|
-
});
|
|
41
|
-
it('has haiku alias', () => {
|
|
42
|
-
expect(ALIASES['haiku']).toBe('anthropic/claude-haiku-4.5');
|
|
43
|
-
});
|
|
44
|
-
it('has claude default alias', () => {
|
|
45
|
-
expect(ALIASES['claude']).toBe('anthropic/claude-sonnet-4.5');
|
|
46
|
-
});
|
|
47
|
-
it('claude aliases point to anthropic provider', () => {
|
|
48
|
-
expect(ALIASES['opus']).toContain('anthropic/');
|
|
49
|
-
expect(ALIASES['sonnet']).toContain('anthropic/');
|
|
50
|
-
expect(ALIASES['haiku']).toContain('anthropic/');
|
|
51
|
-
expect(ALIASES['claude']).toContain('anthropic/');
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
describe('GPT (OpenAI) aliases', () => {
|
|
55
|
-
it('has gpt alias', () => {
|
|
56
|
-
expect(ALIASES['gpt']).toBe('openai/gpt-4o');
|
|
57
|
-
});
|
|
58
|
-
it('has gpt-4o alias', () => {
|
|
59
|
-
expect(ALIASES['gpt-4o']).toBe('openai/gpt-4o');
|
|
60
|
-
});
|
|
61
|
-
it('has gpt-4o-mini alias', () => {
|
|
62
|
-
expect(ALIASES['gpt-4o-mini']).toBe('openai/gpt-4o-mini');
|
|
63
|
-
});
|
|
64
|
-
it('has 4o shorthand', () => {
|
|
65
|
-
expect(ALIASES['4o']).toBe('openai/gpt-4o');
|
|
66
|
-
});
|
|
67
|
-
it('has o1 alias', () => {
|
|
68
|
-
expect(ALIASES['o1']).toBe('openai/o1');
|
|
69
|
-
});
|
|
70
|
-
it('has o3 alias', () => {
|
|
71
|
-
expect(ALIASES['o3']).toBe('openai/o3');
|
|
72
|
-
});
|
|
73
|
-
it('has o3-mini alias', () => {
|
|
74
|
-
expect(ALIASES['o3-mini']).toBe('openai/o3-mini');
|
|
75
|
-
});
|
|
76
|
-
it('has o4-mini alias', () => {
|
|
77
|
-
expect(ALIASES['o4-mini']).toBe('openai/o4-mini');
|
|
78
|
-
});
|
|
79
|
-
it('openai aliases point to openai provider', () => {
|
|
80
|
-
expect(ALIASES['gpt']).toContain('openai/');
|
|
81
|
-
expect(ALIASES['gpt-4o']).toContain('openai/');
|
|
82
|
-
expect(ALIASES['4o']).toContain('openai/');
|
|
83
|
-
expect(ALIASES['o1']).toContain('openai/');
|
|
84
|
-
expect(ALIASES['o3']).toContain('openai/');
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
describe('Gemini (Google) aliases', () => {
|
|
88
|
-
it('has gemini alias', () => {
|
|
89
|
-
expect(ALIASES['gemini']).toBe('google/gemini-2.5-flash');
|
|
90
|
-
});
|
|
91
|
-
it('has flash alias', () => {
|
|
92
|
-
expect(ALIASES['flash']).toBe('google/gemini-2.5-flash');
|
|
93
|
-
});
|
|
94
|
-
it('has gemini-flash alias', () => {
|
|
95
|
-
expect(ALIASES['gemini-flash']).toBe('google/gemini-2.5-flash');
|
|
96
|
-
});
|
|
97
|
-
it('has gemini-pro alias', () => {
|
|
98
|
-
expect(ALIASES['gemini-pro']).toBe('google/gemini-2.5-pro');
|
|
99
|
-
});
|
|
100
|
-
it('google aliases point to google provider', () => {
|
|
101
|
-
expect(ALIASES['gemini']).toContain('google/');
|
|
102
|
-
expect(ALIASES['flash']).toContain('google/');
|
|
103
|
-
expect(ALIASES['gemini-flash']).toContain('google/');
|
|
104
|
-
expect(ALIASES['gemini-pro']).toContain('google/');
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
describe('Llama (Meta) aliases', () => {
|
|
108
|
-
it('has llama alias', () => {
|
|
109
|
-
expect(ALIASES['llama']).toBe('meta-llama/llama-4-maverick');
|
|
110
|
-
});
|
|
111
|
-
it('has llama-4 alias', () => {
|
|
112
|
-
expect(ALIASES['llama-4']).toBe('meta-llama/llama-4-maverick');
|
|
113
|
-
});
|
|
114
|
-
it('has llama-70b alias', () => {
|
|
115
|
-
expect(ALIASES['llama-70b']).toBe('meta-llama/llama-3.3-70b-instruct');
|
|
116
|
-
});
|
|
117
|
-
it('llama aliases point to meta-llama provider', () => {
|
|
118
|
-
expect(ALIASES['llama']).toContain('meta-llama/');
|
|
119
|
-
expect(ALIASES['llama-4']).toContain('meta-llama/');
|
|
120
|
-
expect(ALIASES['llama-70b']).toContain('meta-llama/');
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
describe('DeepSeek aliases', () => {
|
|
124
|
-
it('has deepseek alias', () => {
|
|
125
|
-
expect(ALIASES['deepseek']).toBe('deepseek/deepseek-chat');
|
|
126
|
-
});
|
|
127
|
-
it('has r1 alias', () => {
|
|
128
|
-
expect(ALIASES['r1']).toBe('deepseek/deepseek-r1');
|
|
129
|
-
});
|
|
130
|
-
it('deepseek aliases point to deepseek provider', () => {
|
|
131
|
-
expect(ALIASES['deepseek']).toContain('deepseek/');
|
|
132
|
-
expect(ALIASES['r1']).toContain('deepseek/');
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
describe('Mistral aliases', () => {
|
|
136
|
-
it('has mistral alias', () => {
|
|
137
|
-
expect(ALIASES['mistral']).toBe('mistralai/mistral-large-2411');
|
|
138
|
-
});
|
|
139
|
-
it('has codestral alias', () => {
|
|
140
|
-
expect(ALIASES['codestral']).toBe('mistralai/codestral-2501');
|
|
141
|
-
});
|
|
142
|
-
it('mistral aliases point to mistralai provider', () => {
|
|
143
|
-
expect(ALIASES['mistral']).toContain('mistralai/');
|
|
144
|
-
expect(ALIASES['codestral']).toContain('mistralai/');
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
describe('Qwen aliases', () => {
|
|
148
|
-
it('has qwen alias', () => {
|
|
149
|
-
expect(ALIASES['qwen']).toBe('qwen/qwen3-235b-a22b');
|
|
150
|
-
});
|
|
151
|
-
it('qwen alias points to qwen provider', () => {
|
|
152
|
-
expect(ALIASES['qwen']).toContain('qwen/');
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
describe('Grok (X.AI) aliases', () => {
|
|
156
|
-
it('has grok alias', () => {
|
|
157
|
-
expect(ALIASES['grok']).toBe('x-ai/grok-3');
|
|
158
|
-
});
|
|
159
|
-
it('grok alias points to x-ai provider', () => {
|
|
160
|
-
expect(ALIASES['grok']).toContain('x-ai/');
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
describe('Perplexity aliases', () => {
|
|
164
|
-
it('has sonar alias', () => {
|
|
165
|
-
expect(ALIASES['sonar']).toBe('perplexity/sonar-pro');
|
|
166
|
-
});
|
|
167
|
-
it('sonar alias points to perplexity provider', () => {
|
|
168
|
-
expect(ALIASES['sonar']).toContain('perplexity/');
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
describe('alias uniqueness', () => {
|
|
172
|
-
it('has no duplicate keys', () => {
|
|
173
|
-
const keys = Object.keys(ALIASES);
|
|
174
|
-
const uniqueKeys = new Set(keys);
|
|
175
|
-
expect(keys.length).toBe(uniqueKeys.size);
|
|
176
|
-
});
|
|
177
|
-
it('has unique lowercase keys', () => {
|
|
178
|
-
const lowerKeys = Object.keys(ALIASES).map(k => k.toLowerCase());
|
|
179
|
-
const uniqueLowerKeys = new Set(lowerKeys);
|
|
180
|
-
expect(lowerKeys.length).toBe(uniqueLowerKeys.size);
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
describe('alias conventions', () => {
|
|
184
|
-
it('uses lowercase keys', () => {
|
|
185
|
-
for (const key of Object.keys(ALIASES)) {
|
|
186
|
-
expect(key).toBe(key.toLowerCase());
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
it('uses lowercase provider names in values', () => {
|
|
190
|
-
for (const value of Object.values(ALIASES)) {
|
|
191
|
-
const provider = value.split('/')[0];
|
|
192
|
-
expect(provider).toBe(provider.toLowerCase());
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
it('uses kebab-case or lowercase for model names', () => {
|
|
196
|
-
for (const value of Object.values(ALIASES)) {
|
|
197
|
-
const modelName = value.split('/')[1];
|
|
198
|
-
// Model names should not have uppercase letters or spaces
|
|
199
|
-
expect(modelName).not.toMatch(/[A-Z]/);
|
|
200
|
-
expect(modelName).not.toContain(' ');
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
describe('provider coverage', () => {
|
|
205
|
-
it('covers major AI providers', () => {
|
|
206
|
-
const providers = new Set(Object.values(ALIASES).map(v => v.split('/')[0]));
|
|
207
|
-
expect(providers.has('anthropic')).toBe(true);
|
|
208
|
-
expect(providers.has('openai')).toBe(true);
|
|
209
|
-
expect(providers.has('google')).toBe(true);
|
|
210
|
-
expect(providers.has('meta-llama')).toBe(true);
|
|
211
|
-
});
|
|
212
|
-
it('has multiple aliases per major provider', () => {
|
|
213
|
-
const providerCounts = {};
|
|
214
|
-
for (const value of Object.values(ALIASES)) {
|
|
215
|
-
const provider = value.split('/')[0];
|
|
216
|
-
providerCounts[provider] = (providerCounts[provider] || 0) + 1;
|
|
217
|
-
}
|
|
218
|
-
// Major providers should have multiple aliases
|
|
219
|
-
expect(providerCounts['anthropic']).toBeGreaterThanOrEqual(3);
|
|
220
|
-
expect(providerCounts['openai']).toBeGreaterThanOrEqual(5);
|
|
221
|
-
expect(providerCounts['google']).toBeGreaterThanOrEqual(3);
|
|
222
|
-
});
|
|
223
|
-
});
|
|
224
|
-
describe('README documentation alignment', () => {
|
|
225
|
-
it('matches all aliases documented in README', () => {
|
|
226
|
-
// These are the aliases listed in the README.md table
|
|
227
|
-
const documentedAliases = {
|
|
228
|
-
'opus': 'anthropic/claude-opus-4.5',
|
|
229
|
-
'sonnet': 'anthropic/claude-sonnet-4.5',
|
|
230
|
-
'haiku': 'anthropic/claude-haiku-4.5',
|
|
231
|
-
'claude': 'anthropic/claude-sonnet-4.5',
|
|
232
|
-
'gpt': 'openai/gpt-4o',
|
|
233
|
-
'gpt-4o': 'openai/gpt-4o',
|
|
234
|
-
'4o': 'openai/gpt-4o',
|
|
235
|
-
'o1': 'openai/o1',
|
|
236
|
-
'o3': 'openai/o3',
|
|
237
|
-
'o3-mini': 'openai/o3-mini',
|
|
238
|
-
'gemini': 'google/gemini-2.5-flash',
|
|
239
|
-
'flash': 'google/gemini-2.5-flash',
|
|
240
|
-
'gemini-pro': 'google/gemini-2.5-pro',
|
|
241
|
-
'llama': 'meta-llama/llama-4-maverick',
|
|
242
|
-
'llama-4': 'meta-llama/llama-4-maverick',
|
|
243
|
-
'llama-70b': 'meta-llama/llama-3.3-70b-instruct',
|
|
244
|
-
'mistral': 'mistralai/mistral-large-2411',
|
|
245
|
-
'codestral': 'mistralai/codestral-2501',
|
|
246
|
-
'deepseek': 'deepseek/deepseek-chat',
|
|
247
|
-
'r1': 'deepseek/deepseek-r1',
|
|
248
|
-
'qwen': 'qwen/qwen3-235b-a22b',
|
|
249
|
-
'grok': 'x-ai/grok-3',
|
|
250
|
-
'sonar': 'perplexity/sonar-pro',
|
|
251
|
-
};
|
|
252
|
-
for (const [alias, expectedId] of Object.entries(documentedAliases)) {
|
|
253
|
-
expect(ALIASES[alias]).toBe(expectedId);
|
|
254
|
-
}
|
|
255
|
-
});
|
|
256
|
-
});
|
|
257
|
-
describe('alias count', () => {
|
|
258
|
-
it('has reasonable number of aliases', () => {
|
|
259
|
-
const count = Object.keys(ALIASES).length;
|
|
260
|
-
expect(count).toBeGreaterThanOrEqual(20);
|
|
261
|
-
expect(count).toBeLessThanOrEqual(100);
|
|
262
|
-
});
|
|
263
|
-
});
|
|
264
|
-
});
|
package/src/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* language-models - Model listing and resolution
|
|
3
|
-
*
|
|
4
|
-
* Lists all available models and resolves aliases to full model IDs.
|
|
5
|
-
*
|
|
6
|
-
* @packageDocumentation
|
|
7
|
-
*/
|
|
8
|
-
export { resolve, resolveWithProvider, list, get, search, DIRECT_PROVIDERS } from './models.js';
|
|
9
|
-
export { ALIASES } from './aliases.js';
|
package/src/index.test.js
DELETED
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Integration tests for the language-models package
|
|
3
|
-
*
|
|
4
|
-
* These tests verify the public API exports and end-to-end functionality.
|
|
5
|
-
*/
|
|
6
|
-
import { describe, it, expect } from 'vitest';
|
|
7
|
-
import { resolve, resolveWithProvider, list, get, search, DIRECT_PROVIDERS, ALIASES, } from './index.js';
|
|
8
|
-
describe('package exports', () => {
|
|
9
|
-
it('exports resolve function', () => {
|
|
10
|
-
expect(typeof resolve).toBe('function');
|
|
11
|
-
});
|
|
12
|
-
it('exports resolveWithProvider function', () => {
|
|
13
|
-
expect(typeof resolveWithProvider).toBe('function');
|
|
14
|
-
});
|
|
15
|
-
it('exports list function', () => {
|
|
16
|
-
expect(typeof list).toBe('function');
|
|
17
|
-
});
|
|
18
|
-
it('exports get function', () => {
|
|
19
|
-
expect(typeof get).toBe('function');
|
|
20
|
-
});
|
|
21
|
-
it('exports search function', () => {
|
|
22
|
-
expect(typeof search).toBe('function');
|
|
23
|
-
});
|
|
24
|
-
it('exports DIRECT_PROVIDERS constant', () => {
|
|
25
|
-
expect(DIRECT_PROVIDERS).toBeDefined();
|
|
26
|
-
expect(Array.isArray(DIRECT_PROVIDERS)).toBe(true);
|
|
27
|
-
});
|
|
28
|
-
it('exports ALIASES constant', () => {
|
|
29
|
-
expect(ALIASES).toBeDefined();
|
|
30
|
-
expect(typeof ALIASES).toBe('object');
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
describe('type exports', () => {
|
|
34
|
-
it('ModelInfo type is available', () => {
|
|
35
|
-
// Type check - if this compiles, the type is exported correctly
|
|
36
|
-
const model = {
|
|
37
|
-
id: 'test/model',
|
|
38
|
-
name: 'Test Model',
|
|
39
|
-
context_length: 8192,
|
|
40
|
-
pricing: {
|
|
41
|
-
prompt: '0',
|
|
42
|
-
completion: '0',
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
expect(model).toBeDefined();
|
|
46
|
-
});
|
|
47
|
-
it('ProviderEndpoint type is available', () => {
|
|
48
|
-
const endpoint = {
|
|
49
|
-
baseUrl: 'https://api.example.com',
|
|
50
|
-
modelId: 'test-model-id',
|
|
51
|
-
};
|
|
52
|
-
expect(endpoint).toBeDefined();
|
|
53
|
-
});
|
|
54
|
-
it('ResolvedModel type is available', () => {
|
|
55
|
-
const resolved = {
|
|
56
|
-
id: 'test/model',
|
|
57
|
-
provider: 'test',
|
|
58
|
-
supportsDirectRouting: false,
|
|
59
|
-
};
|
|
60
|
-
expect(resolved).toBeDefined();
|
|
61
|
-
});
|
|
62
|
-
it('DirectProvider type is available', () => {
|
|
63
|
-
const provider = 'anthropic';
|
|
64
|
-
expect(provider).toBeDefined();
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
describe('end-to-end workflows', () => {
|
|
68
|
-
describe('simple alias resolution', () => {
|
|
69
|
-
it('resolves opus and gets model info', () => {
|
|
70
|
-
const modelId = resolve('opus');
|
|
71
|
-
expect(modelId).toBe('anthropic/claude-opus-4.5');
|
|
72
|
-
const model = get(modelId);
|
|
73
|
-
if (model) {
|
|
74
|
-
expect(model.id).toBe(modelId);
|
|
75
|
-
expect(model.name).toContain('Claude');
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
it('resolves gpt and gets model info', () => {
|
|
79
|
-
const modelId = resolve('gpt');
|
|
80
|
-
expect(modelId).toBe('openai/gpt-4o');
|
|
81
|
-
const model = get(modelId);
|
|
82
|
-
if (model) {
|
|
83
|
-
expect(model.id).toBe(modelId);
|
|
84
|
-
expect(model.name).toContain('GPT');
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
describe('advanced resolution with provider info', () => {
|
|
89
|
-
it('resolves opus with full provider details', () => {
|
|
90
|
-
const resolved = resolveWithProvider('opus');
|
|
91
|
-
expect(resolved.id).toBe('anthropic/claude-opus-4.5');
|
|
92
|
-
expect(resolved.provider).toBe('anthropic');
|
|
93
|
-
expect(resolved.supportsDirectRouting).toBe(true);
|
|
94
|
-
if (resolved.model) {
|
|
95
|
-
expect(resolved.model.name).toBeTruthy();
|
|
96
|
-
expect(resolved.model.context_length).toBeGreaterThan(0);
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
it('resolves with provider model ID if available', () => {
|
|
100
|
-
const resolved = resolveWithProvider('opus');
|
|
101
|
-
if (resolved.model?.provider_model_id) {
|
|
102
|
-
expect(resolved.providerModelId).toBe(resolved.model.provider_model_id);
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
describe('search and select workflow', () => {
|
|
107
|
-
it('searches for claude models and selects one', () => {
|
|
108
|
-
const matches = search('claude');
|
|
109
|
-
expect(matches.length).toBeGreaterThan(0);
|
|
110
|
-
const first = matches[0];
|
|
111
|
-
expect(first.id).toContain('/');
|
|
112
|
-
expect(first.name).toBeTruthy();
|
|
113
|
-
const retrieved = get(first.id);
|
|
114
|
-
expect(retrieved).toBeDefined();
|
|
115
|
-
expect(retrieved?.id).toBe(first.id);
|
|
116
|
-
});
|
|
117
|
-
it('searches for openai models', () => {
|
|
118
|
-
const matches = search('openai');
|
|
119
|
-
expect(matches.length).toBeGreaterThan(0);
|
|
120
|
-
for (const model of matches) {
|
|
121
|
-
expect(model.id).toContain('openai/');
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
describe('listing and filtering', () => {
|
|
126
|
-
it('lists all models and filters by provider', () => {
|
|
127
|
-
const allModels = list();
|
|
128
|
-
expect(allModels.length).toBeGreaterThanOrEqual(0);
|
|
129
|
-
if (allModels.length > 0) {
|
|
130
|
-
const anthropicModels = allModels.filter(m => m.id.startsWith('anthropic/'));
|
|
131
|
-
const openaiModels = allModels.filter(m => m.id.startsWith('openai/'));
|
|
132
|
-
if (anthropicModels.length > 0) {
|
|
133
|
-
expect(anthropicModels[0].id).toContain('anthropic/');
|
|
134
|
-
}
|
|
135
|
-
if (openaiModels.length > 0) {
|
|
136
|
-
expect(openaiModels[0].id).toContain('openai/');
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
it('lists models and checks for direct routing', () => {
|
|
141
|
-
const allModels = list();
|
|
142
|
-
if (allModels.length > 0) {
|
|
143
|
-
const directModels = allModels.filter(m => {
|
|
144
|
-
const provider = m.id.split('/')[0];
|
|
145
|
-
return DIRECT_PROVIDERS.includes(provider);
|
|
146
|
-
});
|
|
147
|
-
for (const model of directModels) {
|
|
148
|
-
const resolved = resolveWithProvider(model.id);
|
|
149
|
-
expect(resolved.supportsDirectRouting).toBe(true);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
describe('case insensitivity', () => {
|
|
155
|
-
it('resolves aliases case-insensitively', () => {
|
|
156
|
-
const lower = resolve('opus');
|
|
157
|
-
const upper = resolve('OPUS');
|
|
158
|
-
const mixed = resolve('OpUs');
|
|
159
|
-
expect(lower).toBe(upper);
|
|
160
|
-
expect(lower).toBe(mixed);
|
|
161
|
-
});
|
|
162
|
-
it('searches case-insensitively', () => {
|
|
163
|
-
const lower = search('claude');
|
|
164
|
-
const upper = search('CLAUDE');
|
|
165
|
-
expect(lower).toEqual(upper);
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
describe('unknown inputs', () => {
|
|
169
|
-
it('handles unknown alias gracefully', () => {
|
|
170
|
-
const result = resolve('unknown-alias-xyz');
|
|
171
|
-
expect(result).toBe('unknown-alias-xyz');
|
|
172
|
-
});
|
|
173
|
-
it('handles unknown model ID gracefully', () => {
|
|
174
|
-
const model = get('unknown/model-id');
|
|
175
|
-
expect(model).toBeUndefined();
|
|
176
|
-
});
|
|
177
|
-
it('handles unknown search gracefully', () => {
|
|
178
|
-
const results = search('this-should-not-exist-xyz123');
|
|
179
|
-
expect(results).toEqual([]);
|
|
180
|
-
});
|
|
181
|
-
it('resolves unknown with provider info', () => {
|
|
182
|
-
const resolved = resolveWithProvider('unknown/model');
|
|
183
|
-
expect(resolved.id).toBe('unknown/model');
|
|
184
|
-
expect(resolved.provider).toBe('unknown');
|
|
185
|
-
expect(resolved.model).toBeUndefined();
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
describe('README examples', () => {
|
|
189
|
-
it('works with README quick start examples', () => {
|
|
190
|
-
// Examples from README.md Quick Start section
|
|
191
|
-
const opus = resolve('opus');
|
|
192
|
-
expect(opus).toBe('anthropic/claude-opus-4.5');
|
|
193
|
-
const gpt4o = resolve('gpt-4o');
|
|
194
|
-
expect(gpt4o).toBe('openai/gpt-4o');
|
|
195
|
-
const llama70b = resolve('llama-70b');
|
|
196
|
-
expect(llama70b).toBe('meta-llama/llama-3.3-70b-instruct');
|
|
197
|
-
const mistral = resolve('mistral');
|
|
198
|
-
expect(mistral).toBe('mistralai/mistral-large-2411');
|
|
199
|
-
});
|
|
200
|
-
it('works with README API examples', () => {
|
|
201
|
-
// Examples from README.md API section
|
|
202
|
-
const opus = resolve('opus');
|
|
203
|
-
expect(opus).toBe('anthropic/claude-opus-4.5');
|
|
204
|
-
const sonnet = resolve('sonnet');
|
|
205
|
-
expect(sonnet).toBe('anthropic/claude-sonnet-4.5');
|
|
206
|
-
const gpt = resolve('gpt');
|
|
207
|
-
expect(gpt).toBe('openai/gpt-4o');
|
|
208
|
-
const llama = resolve('llama');
|
|
209
|
-
expect(llama).toBe('meta-llama/llama-4-maverick');
|
|
210
|
-
// Pass-through example
|
|
211
|
-
const fullId = resolve('anthropic/claude-opus-4.5');
|
|
212
|
-
expect(fullId).toBe('anthropic/claude-opus-4.5');
|
|
213
|
-
});
|
|
214
|
-
it('list returns array as shown in README', () => {
|
|
215
|
-
const models = list();
|
|
216
|
-
expect(Array.isArray(models)).toBe(true);
|
|
217
|
-
});
|
|
218
|
-
it('search returns matching models as shown in README', () => {
|
|
219
|
-
const claudeModels = search('claude');
|
|
220
|
-
expect(Array.isArray(claudeModels)).toBe(true);
|
|
221
|
-
if (claudeModels.length > 0) {
|
|
222
|
-
expect(claudeModels.some(m => m.id.includes('claude') || m.name.toLowerCase().includes('claude'))).toBe(true);
|
|
223
|
-
}
|
|
224
|
-
});
|
|
225
|
-
});
|
|
226
|
-
describe('data directory integration', () => {
|
|
227
|
-
it('loads models from data/models.json', () => {
|
|
228
|
-
const models = list();
|
|
229
|
-
// Should load from data directory, even if empty
|
|
230
|
-
expect(Array.isArray(models)).toBe(true);
|
|
231
|
-
});
|
|
232
|
-
it('handles missing data file gracefully', () => {
|
|
233
|
-
// Even without data/models.json, functions should not throw
|
|
234
|
-
expect(() => list()).not.toThrow();
|
|
235
|
-
expect(() => get('test/model')).not.toThrow();
|
|
236
|
-
expect(() => search('test')).not.toThrow();
|
|
237
|
-
});
|
|
238
|
-
});
|
|
239
|
-
describe('model metadata completeness', () => {
|
|
240
|
-
it('models have pricing information', () => {
|
|
241
|
-
const models = list();
|
|
242
|
-
if (models.length > 0) {
|
|
243
|
-
const model = models[0];
|
|
244
|
-
expect(model.pricing).toBeDefined();
|
|
245
|
-
expect(model.pricing.prompt).toBeDefined();
|
|
246
|
-
expect(model.pricing.completion).toBeDefined();
|
|
247
|
-
}
|
|
248
|
-
});
|
|
249
|
-
it('models have context length', () => {
|
|
250
|
-
const models = list();
|
|
251
|
-
if (models.length > 0) {
|
|
252
|
-
for (const model of models.slice(0, 5)) {
|
|
253
|
-
expect(typeof model.context_length).toBe('number');
|
|
254
|
-
expect(model.context_length).toBeGreaterThan(0);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
it('models may have architecture info', () => {
|
|
259
|
-
const models = list();
|
|
260
|
-
if (models.length > 0) {
|
|
261
|
-
const modelWithArch = models.find(m => m.architecture);
|
|
262
|
-
if (modelWithArch?.architecture) {
|
|
263
|
-
expect(modelWithArch.architecture.modality).toBeDefined();
|
|
264
|
-
expect(Array.isArray(modelWithArch.architecture.input_modalities)).toBe(true);
|
|
265
|
-
expect(Array.isArray(modelWithArch.architecture.output_modalities)).toBe(true);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
});
|
|
269
|
-
});
|
|
270
|
-
describe('provider routing', () => {
|
|
271
|
-
it('correctly identifies direct routing providers', () => {
|
|
272
|
-
const directProviders = ['anthropic', 'openai', 'google'];
|
|
273
|
-
for (const provider of directProviders) {
|
|
274
|
-
const models = list().filter(m => m.id.startsWith(`${provider}/`));
|
|
275
|
-
if (models.length > 0) {
|
|
276
|
-
const resolved = resolveWithProvider(models[0].id);
|
|
277
|
-
expect(resolved.supportsDirectRouting).toBe(true);
|
|
278
|
-
expect(resolved.provider).toBe(provider);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
});
|
|
282
|
-
it('identifies non-direct routing providers', () => {
|
|
283
|
-
const models = list();
|
|
284
|
-
const nonDirectModel = models.find(m => {
|
|
285
|
-
const provider = m.id.split('/')[0];
|
|
286
|
-
return !DIRECT_PROVIDERS.includes(provider);
|
|
287
|
-
});
|
|
288
|
-
if (nonDirectModel) {
|
|
289
|
-
const resolved = resolveWithProvider(nonDirectModel.id);
|
|
290
|
-
expect(resolved.supportsDirectRouting).toBe(false);
|
|
291
|
-
}
|
|
292
|
-
});
|
|
293
|
-
});
|
|
294
|
-
});
|
|
295
|
-
describe('consistency checks', () => {
|
|
296
|
-
it('all aliases resolve to valid format', () => {
|
|
297
|
-
for (const [alias, modelId] of Object.entries(ALIASES)) {
|
|
298
|
-
expect(modelId).toContain('/');
|
|
299
|
-
const [provider, model] = modelId.split('/');
|
|
300
|
-
expect(provider.length).toBeGreaterThan(0);
|
|
301
|
-
expect(model.length).toBeGreaterThan(0);
|
|
302
|
-
}
|
|
303
|
-
});
|
|
304
|
-
it('resolve and resolveWithProvider are consistent', () => {
|
|
305
|
-
const testCases = ['opus', 'gpt', 'gemini', 'llama'];
|
|
306
|
-
for (const alias of testCases) {
|
|
307
|
-
const simpleResolve = resolve(alias);
|
|
308
|
-
const fullResolve = resolveWithProvider(alias);
|
|
309
|
-
expect(fullResolve.id).toBe(simpleResolve);
|
|
310
|
-
}
|
|
311
|
-
});
|
|
312
|
-
it('search results are all valid models', () => {
|
|
313
|
-
const results = search('claude');
|
|
314
|
-
for (const model of results) {
|
|
315
|
-
const retrieved = get(model.id);
|
|
316
|
-
// All search results should be retrievable
|
|
317
|
-
expect(retrieved?.id).toBe(model.id);
|
|
318
|
-
}
|
|
319
|
-
});
|
|
320
|
-
});
|