language-models 2.1.1 → 2.3.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 +36 -0
- package/README.md +106 -43
- 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 +6 -2
- 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 -7
- 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/.turbo/turbo-build.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
# language-models
|
|
2
2
|
|
|
3
|
+
## 2.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 2787830: Fold llm-pricing primitive into language-models (consolidate accidentally-scoped @primitives/llm-pricing).
|
|
8
|
+
|
|
9
|
+
The canonical LLM model pricing table (rates, tiers, context-tier breakpoints, `priceFor()` cost computation) now lives inside `language-models` under `src/pricing/`. Two ways to import:
|
|
10
|
+
|
|
11
|
+
- Subpath: `import { priceFor, PRICING_TABLE } from 'language-models/pricing'`
|
|
12
|
+
- Root: `import { priceFor, PRICING_TABLE } from 'language-models'` (re-exported for convenience)
|
|
13
|
+
|
|
14
|
+
The standalone `@primitives/llm-pricing` package is removed — it was accidentally scoped under `@primitives/`, an npm scope we do not own, and was always intended to live alongside the model catalog.
|
|
15
|
+
|
|
16
|
+
## 2.2.0
|
|
17
|
+
|
|
18
|
+
### Minor Changes
|
|
19
|
+
|
|
20
|
+
- Add `ModelPolicy` MDXLD type and per-model policy derivation layer
|
|
21
|
+
(aip-70mk). `policyFor(alias)` returns derived retry, circuit-breaker,
|
|
22
|
+
fallback-chain, and batch-tier data for any catalog model. Heuristics
|
|
23
|
+
encode "frontier providers retry more aggressively", "same-family
|
|
24
|
+
siblings fall back first, sorted by recency then price", and
|
|
25
|
+
"OpenAI/Bedrock are flex-eligible". `ai-functions` reads policy via
|
|
26
|
+
`RetryPolicy.forModel`, `CircuitBreaker.forModel`,
|
|
27
|
+
`FallbackChain.forModel`.
|
|
28
|
+
|
|
29
|
+
## 2.1.3
|
|
30
|
+
|
|
31
|
+
### Patch Changes
|
|
32
|
+
|
|
33
|
+
- Documentation and testing improvements
|
|
34
|
+
- Add deterministic AI testing suite with self-validating patterns
|
|
35
|
+
- Apply StoryBrand narrative to all package READMEs
|
|
36
|
+
- Update TESTING.md with four principles of deterministic AI testing
|
|
37
|
+
- Fix duplicate examples package name conflict
|
|
38
|
+
|
|
3
39
|
## 2.1.1
|
|
4
40
|
|
|
5
41
|
## 2.0.3
|
package/README.md
CHANGED
|
@@ -1,79 +1,142 @@
|
|
|
1
1
|
# language-models
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
**Stop memorizing model IDs. Start shipping.**
|
|
6
|
+
|
|
7
|
+
You're building AI-powered applications, but every provider has different naming conventions. Is it `claude-opus-4-5-20251101` or `anthropic/claude-opus-4.5`? Was it `gpt-4o` or `openai/gpt-4o`? You shouldn't have to care.
|
|
8
|
+
|
|
9
|
+
## The Problem
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
// Without language-models: fragile, provider-specific, constantly breaking
|
|
13
|
+
const model = 'anthropic/claude-3-opus-20240229' // Wait, is this still current?
|
|
14
|
+
const model = 'claude-opus-4-5-20251101' // Or was it this format?
|
|
15
|
+
const model = 'anthropic/claude-opus-4.5' // Which one does OpenRouter want?
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## The Solution
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
// With language-models: simple, memorable, always resolves correctly
|
|
22
|
+
import { resolve } from 'language-models'
|
|
23
|
+
|
|
24
|
+
resolve('opus') // 'anthropic/claude-opus-4.5'
|
|
25
|
+
resolve('sonnet') // 'anthropic/claude-sonnet-4.5'
|
|
26
|
+
resolve('gpt') // 'openai/gpt-4o'
|
|
27
|
+
resolve('llama') // 'meta-llama/llama-4-maverick'
|
|
28
|
+
```
|
|
4
29
|
|
|
5
30
|
## Quick Start
|
|
6
31
|
|
|
32
|
+
**1. Install**
|
|
33
|
+
```bash
|
|
34
|
+
npm install language-models
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**2. Import**
|
|
7
38
|
```typescript
|
|
8
39
|
import { resolve, list, search } from 'language-models'
|
|
40
|
+
```
|
|
9
41
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
resolve('
|
|
14
|
-
resolve('mistral') // 'mistralai/mistral-large-2411'
|
|
15
|
-
|
|
16
|
-
// List all available models
|
|
17
|
-
const models = list()
|
|
42
|
+
**3. Use**
|
|
43
|
+
```typescript
|
|
44
|
+
// Resolve human-friendly aliases to full model IDs
|
|
45
|
+
const modelId = resolve('opus')
|
|
18
46
|
|
|
19
|
-
// Search models
|
|
47
|
+
// Search across 200+ models
|
|
20
48
|
const claudeModels = search('claude')
|
|
49
|
+
|
|
50
|
+
// Get full model catalog with pricing and context info
|
|
51
|
+
const allModels = list()
|
|
21
52
|
```
|
|
22
53
|
|
|
23
|
-
## API
|
|
54
|
+
## API Reference
|
|
24
55
|
|
|
25
56
|
### `resolve(input: string): string`
|
|
26
57
|
|
|
27
|
-
Resolve an alias or partial name to a full model ID.
|
|
58
|
+
Resolve an alias or partial name to a full OpenRouter model ID.
|
|
28
59
|
|
|
29
60
|
```typescript
|
|
30
61
|
resolve('opus') // 'anthropic/claude-opus-4.5'
|
|
31
62
|
resolve('sonnet') // 'anthropic/claude-sonnet-4.5'
|
|
32
63
|
resolve('gpt') // 'openai/gpt-4o'
|
|
33
64
|
resolve('llama') // 'meta-llama/llama-4-maverick'
|
|
34
|
-
resolve('anthropic/claude-opus-4.5') //
|
|
65
|
+
resolve('anthropic/claude-opus-4.5') // Pass-through for full IDs
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### `resolveWithProvider(input: string): ResolvedModel`
|
|
69
|
+
|
|
70
|
+
Get full routing information including provider details for direct SDK access.
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
const info = resolveWithProvider('opus')
|
|
74
|
+
// {
|
|
75
|
+
// id: 'anthropic/claude-opus-4.5',
|
|
76
|
+
// provider: 'anthropic',
|
|
77
|
+
// providerModelId: 'claude-opus-4-5-20251101',
|
|
78
|
+
// supportsDirectRouting: true,
|
|
79
|
+
// model: { name, pricing, context_length, ... }
|
|
80
|
+
// }
|
|
35
81
|
```
|
|
36
82
|
|
|
37
83
|
### `list(): ModelInfo[]`
|
|
38
84
|
|
|
39
|
-
|
|
85
|
+
Get the complete model catalog with pricing, context lengths, and capabilities.
|
|
40
86
|
|
|
41
87
|
### `get(id: string): ModelInfo | undefined`
|
|
42
88
|
|
|
43
|
-
|
|
89
|
+
Fetch a specific model by exact ID.
|
|
44
90
|
|
|
45
91
|
### `search(query: string): ModelInfo[]`
|
|
46
92
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
##
|
|
50
|
-
|
|
51
|
-
|
|
|
52
|
-
|
|
53
|
-
| `opus` | anthropic/claude-opus-4.5 |
|
|
54
|
-
| `sonnet` | anthropic/claude-sonnet-4.5 |
|
|
55
|
-
| `haiku` | anthropic/claude-haiku-4.5 |
|
|
56
|
-
| `
|
|
57
|
-
| `
|
|
58
|
-
| `
|
|
59
|
-
| `gemini
|
|
60
|
-
| `
|
|
61
|
-
| `llama
|
|
62
|
-
| `
|
|
63
|
-
| `
|
|
64
|
-
| `
|
|
65
|
-
| `
|
|
66
|
-
| `
|
|
67
|
-
| `
|
|
68
|
-
| `
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
93
|
+
Find models matching a search query across IDs and names.
|
|
94
|
+
|
|
95
|
+
## Supported Aliases
|
|
96
|
+
|
|
97
|
+
| You type | You get |
|
|
98
|
+
|----------|---------|
|
|
99
|
+
| `opus` | `anthropic/claude-opus-4.5` |
|
|
100
|
+
| `sonnet` | `anthropic/claude-sonnet-4.5` |
|
|
101
|
+
| `haiku` | `anthropic/claude-haiku-4.5` |
|
|
102
|
+
| `gpt`, `gpt-4o`, `4o` | `openai/gpt-4o` |
|
|
103
|
+
| `o1`, `o3`, `o3-mini` | `openai/o1`, `openai/o3`, `openai/o3-mini` |
|
|
104
|
+
| `gemini`, `flash` | `google/gemini-2.5-flash` |
|
|
105
|
+
| `gemini-pro` | `google/gemini-2.5-pro` |
|
|
106
|
+
| `llama`, `llama-4` | `meta-llama/llama-4-maverick` |
|
|
107
|
+
| `llama-70b` | `meta-llama/llama-3.3-70b-instruct` |
|
|
108
|
+
| `mistral` | `mistralai/mistral-large-2411` |
|
|
109
|
+
| `codestral` | `mistralai/codestral-2501` |
|
|
110
|
+
| `deepseek` | `deepseek/deepseek-chat` |
|
|
111
|
+
| `r1` | `deepseek/deepseek-r1` |
|
|
112
|
+
| `qwen` | `qwen/qwen3-235b-a22b` |
|
|
113
|
+
| `grok` | `x-ai/grok-3` |
|
|
114
|
+
| `sonar` | `perplexity/sonar-pro` |
|
|
115
|
+
|
|
116
|
+
## Direct Provider Routing
|
|
117
|
+
|
|
118
|
+
For providers that support direct SDK access (Anthropic, OpenAI, Google), use `resolveWithProvider` to get the native model ID:
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
import { resolveWithProvider, DIRECT_PROVIDERS } from 'language-models'
|
|
122
|
+
|
|
123
|
+
const { provider, providerModelId, supportsDirectRouting } = resolveWithProvider('opus')
|
|
124
|
+
|
|
125
|
+
if (supportsDirectRouting) {
|
|
126
|
+
// Use native SDK with providerModelId
|
|
127
|
+
} else {
|
|
128
|
+
// Route through OpenRouter
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Updating the Model Catalog
|
|
74
133
|
|
|
75
134
|
```bash
|
|
76
135
|
pnpm fetch-models
|
|
77
136
|
```
|
|
78
137
|
|
|
79
|
-
|
|
138
|
+
Fetches the latest models from OpenRouter and updates `data/models.json`.
|
|
139
|
+
|
|
140
|
+
## License
|
|
141
|
+
|
|
142
|
+
MIT
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @packageDocumentation
|
|
7
7
|
*/
|
|
8
|
-
export { resolve, resolveWithProvider, list, get, search, DIRECT_PROVIDERS, type ModelInfo, type ProviderEndpoint, type ResolvedModel, type DirectProvider } from './models.js';
|
|
8
|
+
export { resolve, resolveWithProvider, list, get, search, DIRECT_PROVIDERS, type ModelInfo, type ProviderEndpoint, type ResolvedModel, type DirectProvider, } from './models.js';
|
|
9
9
|
export { ALIASES } from './aliases.js';
|
|
10
|
+
export { policyFor, derivePolicy, defaultPolicy, resetPolicyCache, listAliases, DEFAULT_RETRY, DEFAULT_CIRCUIT_BREAKER, type ModelPolicy, type RetryPolicyData, type CircuitBreakerPolicyData, type BatchTier, type ErrorCategoryName, type ErrorMapping, } from './policy.js';
|
|
11
|
+
export { PRICING_TABLE, priceFor, listSlugs, hasPricing, rowsForSlug, type ModelPricing, type PricingTier, type Provider, type RateBlock, type PriceForArgs, type PriceForResult, type HasPricingArgs, } from './pricing/index.js';
|
|
10
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,OAAO,EACP,mBAAmB,EACnB,IAAI,EACJ,GAAG,EACH,MAAM,EACN,gBAAgB,EAChB,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,OAAO,EACP,mBAAmB,EACnB,IAAI,EACJ,GAAG,EACH,MAAM,EACN,gBAAgB,EAChB,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,cAAc,GACpB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAOtC,OAAO,EACL,SAAS,EACT,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,aAAa,EACb,uBAAuB,EACvB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,wBAAwB,EAC7B,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,YAAY,GAClB,MAAM,aAAa,CAAA;AAOpB,OAAO,EACL,aAAa,EACb,QAAQ,EACR,SAAS,EACT,UAAU,EACV,WAAW,EACX,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,cAAc,GACpB,MAAM,oBAAoB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,18 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @packageDocumentation
|
|
7
7
|
*/
|
|
8
|
-
export { resolve, resolveWithProvider, list, get, search, DIRECT_PROVIDERS } from './models.js';
|
|
8
|
+
export { resolve, resolveWithProvider, list, get, search, DIRECT_PROVIDERS, } from './models.js';
|
|
9
9
|
export { ALIASES } from './aliases.js';
|
|
10
|
+
// Per-model resilience and tier policy data.
|
|
11
|
+
// The runtime *machinery* (RetryPolicy, CircuitBreaker, FallbackChain) lives
|
|
12
|
+
// in `ai-functions`; the *data* (which categories are retryable, which models
|
|
13
|
+
// to fall back to, which batch tiers are eligible) lives here alongside the
|
|
14
|
+
// catalog because it's a per-model concern.
|
|
15
|
+
export { policyFor, derivePolicy, defaultPolicy, resetPolicyCache, listAliases, DEFAULT_RETRY, DEFAULT_CIRCUIT_BREAKER, } from './policy.js';
|
|
16
|
+
// =============================================================================
|
|
17
|
+
// Pricing (consolidated from former @primitives/llm-pricing — see
|
|
18
|
+
// `./pricing/` for the source. Also re-exported under the subpath
|
|
19
|
+
// `language-models/pricing` for surgical imports.)
|
|
20
|
+
// =============================================================================
|
|
21
|
+
export { PRICING_TABLE, priceFor, listSlugs, hasPricing, rowsForSlug, } from './pricing/index.js';
|
|
10
22
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,OAAO,EACP,mBAAmB,EACnB,IAAI,EACJ,GAAG,EACH,MAAM,EACN,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,OAAO,EACP,mBAAmB,EACnB,IAAI,EACJ,GAAG,EACH,MAAM,EACN,gBAAgB,GAKjB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,6CAA6C;AAC7C,6EAA6E;AAC7E,8EAA8E;AAC9E,4EAA4E;AAC5E,4CAA4C;AAC5C,OAAO,EACL,SAAS,EACT,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,aAAa,EACb,uBAAuB,GAOxB,MAAM,aAAa,CAAA;AAEpB,gFAAgF;AAChF,kEAAkE;AAClE,kEAAkE;AAClE,mDAAmD;AACnD,gFAAgF;AAChF,OAAO,EACL,aAAa,EACb,QAAQ,EACR,SAAS,EACT,UAAU,EACV,WAAW,GAQZ,MAAM,oBAAoB,CAAA"}
|
package/dist/models.d.ts
CHANGED
|
@@ -64,7 +64,7 @@ export declare function resolve(input: string): string;
|
|
|
64
64
|
* These providers have special capabilities like MCP, extended thinking, etc.
|
|
65
65
|
*/
|
|
66
66
|
export declare const DIRECT_PROVIDERS: readonly ["openai", "anthropic", "google"];
|
|
67
|
-
export type DirectProvider = typeof DIRECT_PROVIDERS[number];
|
|
67
|
+
export type DirectProvider = (typeof DIRECT_PROVIDERS)[number];
|
|
68
68
|
/**
|
|
69
69
|
* Result of resolving a model with provider routing info
|
|
70
70
|
*/
|
package/dist/models.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,mEAAmE;IACnE,OAAO,EAAE,MAAM,CAAA;IACf,2DAA2D;IAC3D,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,cAAc,EAAE,MAAM,CAAA;IACtB,OAAO,EAAE;QACP,MAAM,EAAE,MAAM,CAAA;QACd,UAAU,EAAE,MAAM,CAAA;KACnB,CAAA;IACD,YAAY,CAAC,EAAE;QACb,QAAQ,EAAE,MAAM,CAAA;QAChB,gBAAgB,EAAE,MAAM,EAAE,CAAA;QAC1B,iBAAiB,EAAE,MAAM,EAAE,CAAA;KAC5B,CAAA;IACD,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,sDAAsD;IACtD,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,gDAAgD;IAChD,QAAQ,CAAC,EAAE,gBAAgB,CAAA;CAC5B;AAeD;;GAEG;AACH,wBAAgB,IAAI,IAAI,SAAS,EAAE,CAElC;AAED;;GAEG;AACH,wBAAgB,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAErD;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,mEAAmE;IACnE,OAAO,EAAE,MAAM,CAAA;IACf,2DAA2D;IAC3D,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MA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ACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,CAchE"}
|
package/dist/models.js
CHANGED
|
@@ -27,7 +27,7 @@ export function list() {
|
|
|
27
27
|
* Get a model by exact ID
|
|
28
28
|
*/
|
|
29
29
|
export function get(id) {
|
|
30
|
-
return loadModels().find(m => m.id === id);
|
|
30
|
+
return loadModels().find((m) => m.id === id);
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
33
|
* Search models by query string
|
|
@@ -35,8 +35,7 @@ export function get(id) {
|
|
|
35
35
|
*/
|
|
36
36
|
export function search(query) {
|
|
37
37
|
const q = query.toLowerCase();
|
|
38
|
-
return loadModels().filter(m => m.id.toLowerCase().includes(q) ||
|
|
39
|
-
m.name.toLowerCase().includes(q));
|
|
38
|
+
return loadModels().filter((m) => m.id.toLowerCase().includes(q) || m.name.toLowerCase().includes(q));
|
|
40
39
|
}
|
|
41
40
|
/**
|
|
42
41
|
* Resolve a model alias or partial name to a full model ID
|
|
@@ -98,12 +97,11 @@ export function resolveWithProvider(input) {
|
|
|
98
97
|
const slashIndex = id.indexOf('/');
|
|
99
98
|
const provider = slashIndex > 0 ? id.substring(0, slashIndex) : 'unknown';
|
|
100
99
|
const supportsDirectRouting = DIRECT_PROVIDERS.includes(provider);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
};
|
|
100
|
+
const result = { id, provider, supportsDirectRouting };
|
|
101
|
+
if (model)
|
|
102
|
+
result.model = model;
|
|
103
|
+
if (model?.provider_model_id)
|
|
104
|
+
result.providerModelId = model.provider_model_id;
|
|
105
|
+
return result;
|
|
108
106
|
}
|
|
109
107
|
//# sourceMappingURL=models.js.map
|
package/dist/models.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.js","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,aAAa,EA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gCAAgC;IAChC,OAAO,KAAK,CAAA;AACd,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,QAAQ,EAAE,WAAW,EAAE,QAAQ,CAAU,CAAA;AAmB1E;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAa;IAC/C,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,CAAA;IACzB,MAAM,KAAK,GAAG,GAAG,CAAC,EAAE,CAAC,CAAA;IAErB,gFAAgF;IAChF,MAAM,UAAU,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IAClC,MAAM,QAAQ,GAAG,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAEzE,MAAM,qBAAqB,GAAI,gBAAsC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;IAExF,MAAM,MAAM,GAAkB,EAAE,EAAE,EAAE,QAAQ,EAAE,qBAAqB,EAAE,CAAA;IACrE,IAAI,KAAK;QAAE,MAAM,CAAC,KAAK,GAAG,KAAK,CAAA;IAC/B,IAAI,KAAK,EAAE,iBAAiB;QAAE,MAAM,CAAC,eAAe,GAAG,KAAK,CAAC,iBAAiB,CAAA;IAC9E,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/dist/policy.d.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ModelPolicy - per-model resilience and tier policy data
|
|
3
|
+
*
|
|
4
|
+
* `language-models` owns model identity (alias resolution, capability lookup).
|
|
5
|
+
* Resilience policy (retry, circuit breaker, fallback chain, batch tier) is
|
|
6
|
+
* a per-model concern that belongs alongside the catalog data — but the
|
|
7
|
+
* runtime *machinery* that applies the policy lives in `ai-functions`.
|
|
8
|
+
*
|
|
9
|
+
* This module provides:
|
|
10
|
+
* - `ModelPolicy` MDXLD type (`$type: 'ModelPolicy'`)
|
|
11
|
+
* - `policyFor(alias)` - resolve an alias and return its derived policy
|
|
12
|
+
* - `derivePolicy(model, alias?)` - inference layer that turns OpenRouter raw
|
|
13
|
+
* data into a policy by applying heuristics (newest frontier model is best,
|
|
14
|
+
* price within a family is inversely correlated with capability, etc.)
|
|
15
|
+
*
|
|
16
|
+
* Source of truth: OpenRouter raw catalog (data/models.json) + heuristics.
|
|
17
|
+
* Strategy: runtime derivation, cached. A static snapshot generator could be
|
|
18
|
+
* added later (see `derivePolicy` — it's pure, so you can pre-compute it).
|
|
19
|
+
*
|
|
20
|
+
* @packageDocumentation
|
|
21
|
+
*/
|
|
22
|
+
import { type ModelInfo } from './models.js';
|
|
23
|
+
/**
|
|
24
|
+
* Error category taxonomy. Mirrors `ai-functions`'s `ErrorCategory` enum by
|
|
25
|
+
* string value — we don't import it (circular), but the strings line up.
|
|
26
|
+
*/
|
|
27
|
+
export type ErrorCategoryName = 'network' | 'rate_limit' | 'invalid_input' | 'authentication' | 'server' | 'context_length' | 'unknown';
|
|
28
|
+
/**
|
|
29
|
+
* Retry classification: which error categories are retryable for this model,
|
|
30
|
+
* plus backoff parameters.
|
|
31
|
+
*/
|
|
32
|
+
export interface RetryPolicyData {
|
|
33
|
+
maxRetries: number;
|
|
34
|
+
baseDelay: number;
|
|
35
|
+
maxDelay: number;
|
|
36
|
+
multiplier: number;
|
|
37
|
+
jitter: number;
|
|
38
|
+
/** Categories that should trigger a retry */
|
|
39
|
+
retryableCategories: ErrorCategoryName[];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Circuit-breaker policy data (per-model state keys come from the alias).
|
|
43
|
+
*/
|
|
44
|
+
export interface CircuitBreakerPolicyData {
|
|
45
|
+
failureThreshold: number;
|
|
46
|
+
resetTimeout: number;
|
|
47
|
+
successThreshold: number;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Tiers a model is eligible for.
|
|
51
|
+
*
|
|
52
|
+
* - `immediate`: synchronous online inference (always available)
|
|
53
|
+
* - `flex`: faster-than-batch processing (~minutes, ~50% discount)
|
|
54
|
+
* — only OpenAI/Bedrock currently
|
|
55
|
+
* - `batch`: batch API processing (~hours, ~50% discount)
|
|
56
|
+
* — OpenAI/Anthropic/Google/Bedrock/Cloudflare
|
|
57
|
+
*/
|
|
58
|
+
export type BatchTier = 'immediate' | 'flex' | 'batch';
|
|
59
|
+
/**
|
|
60
|
+
* Provider-specific HTTP status code → ErrorCategory mapping.
|
|
61
|
+
* Empty here by default — `ai-functions/retry.ts#classifyError` handles the
|
|
62
|
+
* common cases. Override per-model if a provider has unusual error codes.
|
|
63
|
+
*/
|
|
64
|
+
export type ErrorMapping = Record<number, ErrorCategoryName>;
|
|
65
|
+
/**
|
|
66
|
+
* MDXLD-shaped per-model resilience and tier policy.
|
|
67
|
+
*
|
|
68
|
+
* `$type: 'ModelPolicy'`, `$id` is the resolved model id (e.g.
|
|
69
|
+
* `'anthropic/claude-opus-4.5'`).
|
|
70
|
+
*/
|
|
71
|
+
export interface ModelPolicy {
|
|
72
|
+
$type: 'ModelPolicy';
|
|
73
|
+
$id: string;
|
|
74
|
+
/** Provider slug (e.g. 'anthropic') */
|
|
75
|
+
provider: string;
|
|
76
|
+
retry: RetryPolicyData;
|
|
77
|
+
circuitBreaker: CircuitBreakerPolicyData;
|
|
78
|
+
/** Ordered list of model ids to try after this one fails */
|
|
79
|
+
fallbackChain: string[];
|
|
80
|
+
/** Tiers this model is eligible for */
|
|
81
|
+
batchTier: BatchTier[];
|
|
82
|
+
/** Provider-specific HTTP code → category overrides */
|
|
83
|
+
errorMapping: ErrorMapping;
|
|
84
|
+
}
|
|
85
|
+
/** Default retry policy — matches `ai-functions` `RetryPolicy` defaults. */
|
|
86
|
+
export declare const DEFAULT_RETRY: RetryPolicyData;
|
|
87
|
+
/** Default circuit breaker — matches `ai-functions` defaults. */
|
|
88
|
+
export declare const DEFAULT_CIRCUIT_BREAKER: CircuitBreakerPolicyData;
|
|
89
|
+
/**
|
|
90
|
+
* Default policy for an unknown model. Used when no catalog entry is found.
|
|
91
|
+
*/
|
|
92
|
+
export declare function defaultPolicy(modelId: string): ModelPolicy;
|
|
93
|
+
/**
|
|
94
|
+
* Derivation layer — turn a `ModelInfo` (from OpenRouter raw data) into a
|
|
95
|
+
* `ModelPolicy` by applying heuristics.
|
|
96
|
+
*
|
|
97
|
+
* Pure function; safe to call at build time to pre-compute a static snapshot.
|
|
98
|
+
*
|
|
99
|
+
* @param model - The catalog entry for the model.
|
|
100
|
+
* @param allModels - The full catalog, used for sibling lookup. Optional;
|
|
101
|
+
* defaults to `list()`.
|
|
102
|
+
*/
|
|
103
|
+
export declare function derivePolicy(model: ModelInfo, allModels?: ModelInfo[]): ModelPolicy;
|
|
104
|
+
/**
|
|
105
|
+
* Resolve an alias (or full model id) and return its policy.
|
|
106
|
+
*
|
|
107
|
+
* Falls back to `defaultPolicy(id)` if the model is not in the catalog —
|
|
108
|
+
* callers always get a usable policy.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* const p = policyFor('sonnet')
|
|
113
|
+
* // p.fallbackChain → ['anthropic/claude-opus-4.5', 'openai/gpt-4o', ...]
|
|
114
|
+
* // p.batchTier → ['immediate', 'batch']
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export declare function policyFor(input: string): ModelPolicy;
|
|
118
|
+
/**
|
|
119
|
+
* Reset the policy cache. Useful for tests, or after the catalog is reloaded.
|
|
120
|
+
*/
|
|
121
|
+
export declare function resetPolicyCache(): void;
|
|
122
|
+
/**
|
|
123
|
+
* List all known aliases. Convenience for tooling that wants to enumerate
|
|
124
|
+
* derived policies (e.g. a static snapshot generator).
|
|
125
|
+
*/
|
|
126
|
+
export declare function listAliases(): string[];
|
|
127
|
+
//# sourceMappingURL=policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.d.ts","sourceRoot":"","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