@cedrugs/opencode-omniauth 1.2.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/LICENSE +21 -0
- package/README.md +387 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime.d.ts +6 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +5 -0
- package/dist/runtime.js.map +1 -0
- package/dist/src/constants.d.ts +37 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +64 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/models-dev.d.ts +52 -0
- package/dist/src/models-dev.d.ts.map +1 -0
- package/dist/src/models-dev.js +199 -0
- package/dist/src/models-dev.js.map +1 -0
- package/dist/src/models.d.ts +7 -0
- package/dist/src/models.d.ts.map +1 -0
- package/dist/src/models.js +411 -0
- package/dist/src/models.js.map +1 -0
- package/dist/src/omniroute-combos.d.ts +26 -0
- package/dist/src/omniroute-combos.d.ts.map +1 -0
- package/dist/src/omniroute-combos.js +192 -0
- package/dist/src/omniroute-combos.js.map +1 -0
- package/dist/src/plugin.d.ts +3 -0
- package/dist/src/plugin.d.ts.map +1 -0
- package/dist/src/plugin.js +668 -0
- package/dist/src/plugin.js.map +1 -0
- package/dist/src/types.d.ts +120 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 OpenCode OmniRoute Auth Plugin Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
# OpenCode OmniRoute Auth Plugin
|
|
2
|
+
|
|
3
|
+
🔌 Authentication plugin for [OpenCode](https://opencode.ai) to connect to [OmniRoute](https://omniroute.ai) API.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ✅ **Simple `/connect` Command** - No manual configuration needed
|
|
8
|
+
- ✅ **API Key Authentication** - Simple and secure API key-based auth
|
|
9
|
+
- ✅ **Dynamic Model Fetching** - Automatically fetches available models from `/v1/models` endpoint
|
|
10
|
+
- ✅ **Provider Auto-Registration** - Registers an `omniroute` provider via plugin hooks
|
|
11
|
+
- ✅ **Model Caching** - Intelligent caching with TTL for better performance
|
|
12
|
+
- ✅ **Fallback Models** - Default models when API is unavailable
|
|
13
|
+
- ✅ **Combo Model Capability Enrichment** - Automatically calculates lowest common capabilities for OmniRoute combo models
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
### 1. Add plugin to opencode config
|
|
20
|
+
```json
|
|
21
|
+
{
|
|
22
|
+
"plugin": [
|
|
23
|
+
"opencode-omniroute-auth"
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### 2. Connect to OmniRoute
|
|
29
|
+
|
|
30
|
+
Simply run the `/connect` command in OpenCode:
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
/connect omniroute
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
The plugin will prompt you for your **API key**.
|
|
37
|
+
|
|
38
|
+
### 3. Done! 🎉
|
|
39
|
+
|
|
40
|
+
The plugin automatically:
|
|
41
|
+
- Fetches available models from `/v1/models`
|
|
42
|
+
- Configures OpenCode to use OmniRoute
|
|
43
|
+
- Stores your credentials securely
|
|
44
|
+
|
|
45
|
+
No manual configuration file editing required!
|
|
46
|
+
|
|
47
|
+
## Usage
|
|
48
|
+
|
|
49
|
+
Once connected, OpenCode will automatically use OmniRoute for AI requests:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
# The plugin is now active and ready to use
|
|
53
|
+
# All AI requests will be routed through OmniRoute
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Refresh Models
|
|
57
|
+
|
|
58
|
+
By default, the plugin refreshes the model list whenever provider options are reloaded (`refreshOnList: true`).
|
|
59
|
+
|
|
60
|
+
You can disable refreshes by setting `provider.omniroute.options.refreshOnList` to `false` and clear the cache programmatically:
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
import { clearModelCache } from 'opencode-omniroute-auth/runtime';
|
|
64
|
+
|
|
65
|
+
clearModelCache();
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Configuration (Optional)
|
|
69
|
+
|
|
70
|
+
While the plugin works out-of-the-box with `/connect`, you can also configure it manually in your OpenCode config:
|
|
71
|
+
|
|
72
|
+
```json
|
|
73
|
+
{
|
|
74
|
+
"plugin": [
|
|
75
|
+
"opencode-omniroute-auth"
|
|
76
|
+
],
|
|
77
|
+
"provider": {
|
|
78
|
+
"omniroute": {
|
|
79
|
+
"options": {
|
|
80
|
+
"baseURL": "http://localhost:20128/v1",
|
|
81
|
+
"apiMode": "chat",
|
|
82
|
+
"refreshOnList": true,
|
|
83
|
+
"modelCacheTtl": 300000
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Use `/connect omniroute` to store your API key in `~/.local/share/opencode/auth.json`.
|
|
91
|
+
|
|
92
|
+
### Configuration Options
|
|
93
|
+
|
|
94
|
+
| Option | Type | Required | Description |
|
|
95
|
+
|--------|------|----------|-------------|
|
|
96
|
+
| `plugin` | string[] | No | npm plugin packages to load (use `opencode-omniroute-auth` when installed from npm) |
|
|
97
|
+
| `provider.omniroute.options.baseURL` | string | No | OmniRoute API base URL (default: `http://localhost:20128/v1`) |
|
|
98
|
+
| `provider.omniroute.options.apiMode` | `'chat' \| 'responses'` | No | Provider API mode (default: `chat`) |
|
|
99
|
+
| `provider.omniroute.options.modelCacheTtl` | number | No | Model cache TTL in milliseconds (default: 5 minutes) |
|
|
100
|
+
| `provider.omniroute.options.refreshOnList` | boolean | No | Whether to refresh models when provider options load (default: true) |
|
|
101
|
+
| `provider.omniroute.options.modelsDev` | object | No | Enrich model metadata from models.dev on refresh (default: enabled) |
|
|
102
|
+
| `provider.omniroute.options.modelMetadata` | object \| array | No | Override/add metadata for custom/virtual models (works well in `opencode.js`) |
|
|
103
|
+
|
|
104
|
+
### Model Metadata Enrichment (models.dev)
|
|
105
|
+
|
|
106
|
+
OmniRoute may not expose model context/output limits in `/v1/models`. When enabled, this plugin attempts to
|
|
107
|
+
enrich `contextWindow` and `maxTokens` by matching your OmniRoute models against `models.dev`.
|
|
108
|
+
|
|
109
|
+
You can disable enrichment or override defaults:
|
|
110
|
+
|
|
111
|
+
```js
|
|
112
|
+
{
|
|
113
|
+
provider: {
|
|
114
|
+
omniroute: {
|
|
115
|
+
options: {
|
|
116
|
+
modelsDev: {
|
|
117
|
+
enabled: true,
|
|
118
|
+
url: 'https://models.dev/api.json',
|
|
119
|
+
timeoutMs: 1000,
|
|
120
|
+
cacheTtl: 86400000,
|
|
121
|
+
providerAliases: {
|
|
122
|
+
cx: 'openai',
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Custom / Virtual Model Overrides (config blocks)
|
|
132
|
+
|
|
133
|
+
For custom/virtual models (or when matching is imperfect), you can provide metadata overrides.
|
|
134
|
+
|
|
135
|
+
In `opencode.js` you can use RegExp matchers:
|
|
136
|
+
|
|
137
|
+
```js
|
|
138
|
+
{
|
|
139
|
+
provider: {
|
|
140
|
+
omniroute: {
|
|
141
|
+
options: {
|
|
142
|
+
modelMetadata: [
|
|
143
|
+
{ match: /gpt-5\.3-codex$/i, contextWindow: 200000, maxTokens: 8192 },
|
|
144
|
+
{ match: 'omniroute/virtual/my-custom-model', addIfMissing: true, contextWindow: 50000 },
|
|
145
|
+
],
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
In JSON configs, use an object keyed by model id:
|
|
153
|
+
|
|
154
|
+
```json
|
|
155
|
+
{
|
|
156
|
+
"provider": {
|
|
157
|
+
"omniroute": {
|
|
158
|
+
"options": {
|
|
159
|
+
"modelMetadata": {
|
|
160
|
+
"virtual/my-custom-model": { "contextWindow": 50000, "maxTokens": 2048 }
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Combo Model Capability Enrichment
|
|
169
|
+
|
|
170
|
+
OmniRoute supports "combo models" - virtual models that route to multiple underlying models with fallback strategies. This plugin automatically detects combo models and calculates their capabilities using a **lowest common denominator** approach:
|
|
171
|
+
|
|
172
|
+
- **Context Window**: Minimum of all underlying models
|
|
173
|
+
- **Max Tokens**: Minimum of all underlying models
|
|
174
|
+
- **Vision Support**: Only if ALL underlying models support vision
|
|
175
|
+
- **Tool Support**: Only if ALL underlying models support tools
|
|
176
|
+
|
|
177
|
+
This ensures safe operation by never exceeding the capabilities of any single model in the combo.
|
|
178
|
+
|
|
179
|
+
**How it works:**
|
|
180
|
+
1. The plugin fetches combo definitions from OmniRoute's `/api/combos` endpoint
|
|
181
|
+
2. For each combo model, it resolves the underlying models
|
|
182
|
+
3. It looks up each underlying model's capabilities from `models.dev`
|
|
183
|
+
4. It calculates the lowest common capabilities across all resolvable models
|
|
184
|
+
5. These calculated capabilities are applied to the combo model
|
|
185
|
+
|
|
186
|
+
**Example:**
|
|
187
|
+
The "Designer" combo might route to:
|
|
188
|
+
- `kmc/kimi-k2.5` (context: 256000, tools: yes)
|
|
189
|
+
- `cx/gpt-5.1-codex-mini` (context: 204800, tools: yes)
|
|
190
|
+
- `gemini/models/gemini-3-flash-preview` (context: 1048576, tools: yes)
|
|
191
|
+
|
|
192
|
+
Calculated capabilities:
|
|
193
|
+
- Context: **204800** (minimum)
|
|
194
|
+
- Max Tokens: **32768** (minimum)
|
|
195
|
+
- Tools: **true** (all support tools)
|
|
196
|
+
|
|
197
|
+
Note: Some underlying models may not be found in `models.dev` (e.g., custom models). In such cases, they are excluded from capability calculation, and a warning is logged.
|
|
198
|
+
|
|
199
|
+
### API Mode
|
|
200
|
+
|
|
201
|
+
### API Mode
|
|
202
|
+
|
|
203
|
+
The plugin supports two provider API modes:
|
|
204
|
+
|
|
205
|
+
- `chat` (default) - best compatibility with existing OpenAI-compatible chat workflows.
|
|
206
|
+
- `responses` - enables Responses API mode when your OmniRoute/OpenCode setup supports it.
|
|
207
|
+
|
|
208
|
+
Example:
|
|
209
|
+
|
|
210
|
+
```json
|
|
211
|
+
{
|
|
212
|
+
"provider": {
|
|
213
|
+
"omniroute": {
|
|
214
|
+
"options": {
|
|
215
|
+
"apiMode": "responses"
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
If an unsupported value is provided, the plugin falls back to `chat`.
|
|
223
|
+
|
|
224
|
+
## Dynamic Model Fetching
|
|
225
|
+
|
|
226
|
+
This plugin automatically fetches available models from OmniRoute's `/v1/models` endpoint. This ensures you always have access to the latest models without manual configuration.
|
|
227
|
+
|
|
228
|
+
### How It Works
|
|
229
|
+
|
|
230
|
+
1. On first request, the plugin fetches models from `/v1/models`
|
|
231
|
+
2. By default, models are refreshed every time you open the model list (`refreshOnList: true`)
|
|
232
|
+
3. If `refreshOnList` is disabled, models are cached for 5 minutes (configurable via `modelCacheTtl`)
|
|
233
|
+
4. If the API is unavailable, fallback models are used
|
|
234
|
+
|
|
235
|
+
## Default Models
|
|
236
|
+
|
|
237
|
+
When the `/v1/models` endpoint is unavailable, the plugin provides these fallback models:
|
|
238
|
+
|
|
239
|
+
- `gpt-4o` - GPT-4o model with full capabilities
|
|
240
|
+
- `gpt-4o-mini` - Fast and cost-effective
|
|
241
|
+
- `claude-3-5-sonnet` - Claude 3.5 Sonnet
|
|
242
|
+
- `llama-3-1-405b` - Llama 3.1 405B
|
|
243
|
+
|
|
244
|
+
## API
|
|
245
|
+
|
|
246
|
+
### Types
|
|
247
|
+
|
|
248
|
+
```typescript
|
|
249
|
+
import type {
|
|
250
|
+
OmniRouteApiMode,
|
|
251
|
+
OmniRouteConfig,
|
|
252
|
+
OmniRouteModel,
|
|
253
|
+
OmniRouteModelMetadataConfig,
|
|
254
|
+
OmniRouteModelsDevConfig,
|
|
255
|
+
} from "opencode-omniroute-auth";
|
|
256
|
+
|
|
257
|
+
interface OmniRouteConfig {
|
|
258
|
+
baseUrl: string;
|
|
259
|
+
apiKey: string;
|
|
260
|
+
apiMode: OmniRouteApiMode;
|
|
261
|
+
defaultModels?: OmniRouteModel[];
|
|
262
|
+
modelCacheTtl?: number;
|
|
263
|
+
refreshOnList?: boolean;
|
|
264
|
+
modelsDev?: OmniRouteModelsDevConfig;
|
|
265
|
+
modelMetadata?: OmniRouteModelMetadataConfig;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
type OmniRouteApiMode = 'chat' | 'responses';
|
|
269
|
+
|
|
270
|
+
interface OmniRouteModel {
|
|
271
|
+
id: string;
|
|
272
|
+
name: string;
|
|
273
|
+
description?: string;
|
|
274
|
+
contextWindow?: number;
|
|
275
|
+
maxTokens?: number;
|
|
276
|
+
supportsStreaming?: boolean;
|
|
277
|
+
supportsVision?: boolean;
|
|
278
|
+
supportsTools?: boolean;
|
|
279
|
+
pricing?: {
|
|
280
|
+
input?: number;
|
|
281
|
+
output?: number;
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### Functions
|
|
287
|
+
|
|
288
|
+
```typescript
|
|
289
|
+
import {
|
|
290
|
+
fetchModels,
|
|
291
|
+
clearModelCache,
|
|
292
|
+
refreshModels,
|
|
293
|
+
// New: Combo model utilities
|
|
294
|
+
clearComboCache,
|
|
295
|
+
fetchComboData,
|
|
296
|
+
resolveUnderlyingModels,
|
|
297
|
+
calculateModelCapabilities,
|
|
298
|
+
} from 'opencode-omniroute-auth/runtime';
|
|
299
|
+
|
|
300
|
+
// Fetch models manually (with automatic enrichment)
|
|
301
|
+
const models = await fetchModels(config, apiKey);
|
|
302
|
+
|
|
303
|
+
// Clear model cache (also clears combo cache)
|
|
304
|
+
clearModelCache();
|
|
305
|
+
|
|
306
|
+
// Force refresh models
|
|
307
|
+
const freshModels = await refreshModels(config, apiKey);
|
|
308
|
+
|
|
309
|
+
// Combo model utilities
|
|
310
|
+
const combos = await fetchComboData(config);
|
|
311
|
+
const underlyingModels = await resolveUnderlyingModels('Designer', config);
|
|
312
|
+
const capabilities = await calculateModelCapabilities(model, config, modelsDevIndex);
|
|
313
|
+
```
|
|
314
|
+
import {
|
|
315
|
+
fetchModels,
|
|
316
|
+
clearModelCache,
|
|
317
|
+
refreshModels,
|
|
318
|
+
} from 'opencode-omniroute-auth/runtime';
|
|
319
|
+
|
|
320
|
+
// Fetch models manually
|
|
321
|
+
const models = await fetchModels(config, apiKey);
|
|
322
|
+
|
|
323
|
+
// Clear model cache
|
|
324
|
+
clearModelCache();
|
|
325
|
+
|
|
326
|
+
// Force refresh models
|
|
327
|
+
const freshModels = await refreshModels(config, apiKey);
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
## Development
|
|
331
|
+
|
|
332
|
+
```bash
|
|
333
|
+
# Install dependencies
|
|
334
|
+
npm install
|
|
335
|
+
|
|
336
|
+
# Build
|
|
337
|
+
npm run build
|
|
338
|
+
|
|
339
|
+
# Watch mode
|
|
340
|
+
npm run dev
|
|
341
|
+
|
|
342
|
+
# Clean
|
|
343
|
+
npm run clean
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
## Troubleshooting
|
|
347
|
+
|
|
348
|
+
### Connection Failed
|
|
349
|
+
|
|
350
|
+
If you see "Connection failed" when running `/connect omniroute`:
|
|
351
|
+
|
|
352
|
+
1. **Check your configured base URL** - Ensure `provider.omniroute.options.baseURL` points to your OmniRoute endpoint
|
|
353
|
+
2. **Verify your API key** - Ensure your API key starts with `sk-` and is valid
|
|
354
|
+
3. **Check OmniRoute is running** - Ensure your OmniRoute instance is accessible
|
|
355
|
+
|
|
356
|
+
### Models Not Loading
|
|
357
|
+
|
|
358
|
+
If models aren't loading:
|
|
359
|
+
|
|
360
|
+
1. Check your OmniRoute `/v1/models` endpoint is accessible
|
|
361
|
+
2. Ensure `provider.omniroute.options.baseURL` points to your OmniRoute endpoint
|
|
362
|
+
3. Re-run `/connect omniroute` to refresh your API key
|
|
363
|
+
4. If you use the package programmatically, call `clearModelCache()` from `opencode-omniroute-auth/runtime`
|
|
364
|
+
5. Check the OpenCode logs for error messages
|
|
365
|
+
|
|
366
|
+
### Plugin Not Loading Outside This Repo
|
|
367
|
+
|
|
368
|
+
If the plugin loads only through a local shim (for example from `.opencode/plugins` or `.opencode/plugi`) but not from npm in `opencode.json`:
|
|
369
|
+
|
|
370
|
+
1. Ensure you are using `opencode-omniroute-auth@1.0.1` or newer
|
|
371
|
+
2. Confirm your config includes `"plugin": ["opencode-omniroute-auth"]`
|
|
372
|
+
3. Restart OpenCode so npm plugins are reloaded
|
|
373
|
+
4. Check plugin install cache/logs under `~/.cache/opencode/node_modules`
|
|
374
|
+
|
|
375
|
+
If needed, clear and reinstall plugin dependencies, then restart OpenCode.
|
|
376
|
+
|
|
377
|
+
## License
|
|
378
|
+
|
|
379
|
+
MIT
|
|
380
|
+
|
|
381
|
+
## Contributing
|
|
382
|
+
|
|
383
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
384
|
+
|
|
385
|
+
## Support
|
|
386
|
+
|
|
387
|
+
For support, please open an issue on GitHub or contact OmniRoute support.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { OmniRouteAuthPlugin } from './src/plugin.js';
|
|
2
|
+
export { OmniRouteAuthPlugin };
|
|
3
|
+
export default OmniRouteAuthPlugin;
|
|
4
|
+
export type { OmniRouteApiMode, OmniRouteConfig, OmniRouteModel, OmniRouteModelMetadata, OmniRouteModelMetadataBlock, OmniRouteModelMetadataConfig, OmniRouteModelsDevConfig, } from './src/types.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,CAAC;AAC/B,eAAe,mBAAmB,CAAC;AACnC,YAAY,EACV,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,sBAAsB,EACtB,2BAA2B,EAC3B,4BAA4B,EAC5B,wBAAwB,GACzB,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,CAAC;AAC/B,eAAe,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { OmniRouteApiMode, OmniRouteConfig, OmniRouteModel, OmniRouteModelMetadata, OmniRouteModelMetadataBlock, OmniRouteModelMetadataConfig, OmniRouteModelsDevConfig, } from './src/types.js';
|
|
2
|
+
export { fetchModels, clearModelCache, refreshModels, getCachedModels, isCacheValid, } from './src/models.js';
|
|
3
|
+
export { OMNIROUTE_PROVIDER_ID, OMNIROUTE_DEFAULT_MODELS, MODEL_CACHE_TTL, OMNIROUTE_ENDPOINTS, REQUEST_TIMEOUT, } from './src/constants.js';
|
|
4
|
+
export { clearModelsDevCache, } from './src/models-dev.js';
|
|
5
|
+
export { clearComboCache, fetchComboData, resolveUnderlyingModels, calculateModelCapabilities, } from './src/omniroute-combos.js';
|
|
6
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../runtime.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,sBAAsB,EACtB,2BAA2B,EAC3B,4BAA4B,EAC5B,wBAAwB,GACzB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,WAAW,EACX,eAAe,EACf,aAAa,EACb,eAAe,EACf,YAAY,GACb,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,qBAAqB,EACrB,wBAAwB,EACxB,eAAe,EACf,mBAAmB,EACnB,eAAe,GAChB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,mBAAmB,GACpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,eAAe,EACf,cAAc,EACd,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,2BAA2B,CAAC"}
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { fetchModels, clearModelCache, refreshModels, getCachedModels, isCacheValid, } from './src/models.js';
|
|
2
|
+
export { OMNIROUTE_PROVIDER_ID, OMNIROUTE_DEFAULT_MODELS, MODEL_CACHE_TTL, OMNIROUTE_ENDPOINTS, REQUEST_TIMEOUT, } from './src/constants.js';
|
|
3
|
+
export { clearModelsDevCache, } from './src/models-dev.js';
|
|
4
|
+
export { clearComboCache, fetchComboData, resolveUnderlyingModels, calculateModelCapabilities, } from './src/omniroute-combos.js';
|
|
5
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../runtime.ts"],"names":[],"mappings":"AASA,OAAO,EACL,WAAW,EACX,eAAe,EACf,aAAa,EACb,eAAe,EACf,YAAY,GACb,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,qBAAqB,EACrB,wBAAwB,EACxB,eAAe,EACf,mBAAmB,EACnB,eAAe,GAChB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,mBAAmB,GACpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,eAAe,EACf,cAAc,EACd,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export declare const log: {
|
|
2
|
+
info: {
|
|
3
|
+
(...data: any[]): void;
|
|
4
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
5
|
+
};
|
|
6
|
+
warn: {
|
|
7
|
+
(...data: any[]): void;
|
|
8
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
9
|
+
};
|
|
10
|
+
error: {
|
|
11
|
+
(...data: any[]): void;
|
|
12
|
+
(message?: any, ...optionalParams: any[]): void;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export declare const OMNIROUTE_PROVIDER_ID = "omniroute";
|
|
16
|
+
export declare const OMNIROUTE_ENDPOINTS: {
|
|
17
|
+
BASE_URL: string;
|
|
18
|
+
MODELS: string;
|
|
19
|
+
CHAT_COMPLETIONS: string;
|
|
20
|
+
RESPONSES: string;
|
|
21
|
+
};
|
|
22
|
+
export declare const OMNIROUTE_DEFAULT_MODELS: {
|
|
23
|
+
id: string;
|
|
24
|
+
name: string;
|
|
25
|
+
description: string;
|
|
26
|
+
contextWindow: number;
|
|
27
|
+
maxTokens: number;
|
|
28
|
+
supportsStreaming: boolean;
|
|
29
|
+
supportsVision: boolean;
|
|
30
|
+
supportsTools: boolean;
|
|
31
|
+
}[];
|
|
32
|
+
export declare const MODEL_CACHE_TTL: number;
|
|
33
|
+
export declare const REQUEST_TIMEOUT = 30000;
|
|
34
|
+
export declare const MODELS_DEV_DEFAULT_URL = "https://models.dev/api.json";
|
|
35
|
+
export declare const MODELS_DEV_CACHE_TTL: number;
|
|
36
|
+
export declare const MODELS_DEV_TIMEOUT_MS = 1000;
|
|
37
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,GAAG;;;;;;;;;;;;;CAIf,CAAC;AAEF,eAAO,MAAM,qBAAqB,cAAc,CAAC;AAEjD,eAAO,MAAM,mBAAmB;;;;;CAK/B,CAAC;AAEF,eAAO,MAAM,wBAAwB;;;;;;;;;GAyCpC,CAAC;AAEF,eAAO,MAAM,eAAe,QAAgB,CAAC;AAC7C,eAAO,MAAM,eAAe,QAAQ,CAAC;AAErC,eAAO,MAAM,sBAAsB,gCAAgC,CAAC;AACpE,eAAO,MAAM,oBAAoB,QAAsB,CAAC;AACxD,eAAO,MAAM,qBAAqB,OAAO,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const _global = globalThis;
|
|
2
|
+
const _process = _global.process;
|
|
3
|
+
const _env = _process?.env;
|
|
4
|
+
const DEBUG_ENABLED = !!(_env?.OMNIROUTE_DEBUG);
|
|
5
|
+
export const log = {
|
|
6
|
+
info: DEBUG_ENABLED ? console.log.bind(console) : () => { },
|
|
7
|
+
warn: DEBUG_ENABLED ? console.warn.bind(console) : () => { },
|
|
8
|
+
error: DEBUG_ENABLED ? console.error.bind(console) : () => { },
|
|
9
|
+
};
|
|
10
|
+
export const OMNIROUTE_PROVIDER_ID = 'omniroute';
|
|
11
|
+
export const OMNIROUTE_ENDPOINTS = {
|
|
12
|
+
BASE_URL: 'http://localhost:20128/v1',
|
|
13
|
+
MODELS: '/models',
|
|
14
|
+
CHAT_COMPLETIONS: '/chat/completions',
|
|
15
|
+
RESPONSES: '/responses',
|
|
16
|
+
};
|
|
17
|
+
export const OMNIROUTE_DEFAULT_MODELS = [
|
|
18
|
+
{
|
|
19
|
+
id: 'gpt-4o',
|
|
20
|
+
name: 'GPT-4o',
|
|
21
|
+
description: 'GPT-4o model with full capabilities',
|
|
22
|
+
contextWindow: 128000,
|
|
23
|
+
maxTokens: 4096,
|
|
24
|
+
supportsStreaming: true,
|
|
25
|
+
supportsVision: true,
|
|
26
|
+
supportsTools: true,
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
id: 'gpt-4o-mini',
|
|
30
|
+
name: 'GPT-4o Mini',
|
|
31
|
+
description: 'Fast and cost-effective model for everyday tasks',
|
|
32
|
+
contextWindow: 128000,
|
|
33
|
+
maxTokens: 4096,
|
|
34
|
+
supportsStreaming: true,
|
|
35
|
+
supportsVision: true,
|
|
36
|
+
supportsTools: true,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: 'claude-3-5-sonnet',
|
|
40
|
+
name: 'Claude 3.5 Sonnet',
|
|
41
|
+
description: "Anthropic's Claude 3.5 Sonnet",
|
|
42
|
+
contextWindow: 200000,
|
|
43
|
+
maxTokens: 8192,
|
|
44
|
+
supportsStreaming: true,
|
|
45
|
+
supportsVision: true,
|
|
46
|
+
supportsTools: true,
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
id: 'llama-3-1-405b',
|
|
50
|
+
name: 'Llama 3.1 405B',
|
|
51
|
+
description: "Meta's Llama 3.1 405B",
|
|
52
|
+
contextWindow: 128000,
|
|
53
|
+
maxTokens: 4096,
|
|
54
|
+
supportsStreaming: true,
|
|
55
|
+
supportsVision: false,
|
|
56
|
+
supportsTools: true,
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
export const MODEL_CACHE_TTL = 5 * 60 * 1000;
|
|
60
|
+
export const REQUEST_TIMEOUT = 30000;
|
|
61
|
+
export const MODELS_DEV_DEFAULT_URL = 'https://models.dev/api.json';
|
|
62
|
+
export const MODELS_DEV_CACHE_TTL = 24 * 60 * 60 * 1000;
|
|
63
|
+
export const MODELS_DEV_TIMEOUT_MS = 1000;
|
|
64
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG,UAAqC,CAAC;AACtD,MAAM,QAAQ,GAAG,OAAO,CAAC,OAA8C,CAAC;AACxE,MAAM,IAAI,GAAG,QAAQ,EAAE,GAAyC,CAAC;AACjE,MAAM,aAAa,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;AAEhD,MAAM,CAAC,MAAM,GAAG,GAAG;IAClB,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,GAAE,CAAC;IAC1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ACpC,aAAa,EAAE,MAAM;QACrB,SAAS,EAAE,IAAI;QACf,iBAAiB,EAAE,IAAI;QACvB,cAAc,EAAE,KAAK;QACrB,aAAa,EAAE,IAAI;KACnB;CACD,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AAC7C,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,CAAC;AAErC,MAAM,CAAC,MAAM,sBAAsB,GAAG,6BAA6B,CAAC;AACpE,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AACxD,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { OmniRouteConfig, OmniRouteModelMetadata } from './types.js';
|
|
2
|
+
export interface ModelsDevModel {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
family?: string;
|
|
6
|
+
attachment?: boolean;
|
|
7
|
+
reasoning?: boolean;
|
|
8
|
+
tool_call?: boolean;
|
|
9
|
+
structured_output?: boolean;
|
|
10
|
+
temperature?: boolean;
|
|
11
|
+
knowledge?: string;
|
|
12
|
+
release_date?: string;
|
|
13
|
+
last_updated?: string;
|
|
14
|
+
modalities?: {
|
|
15
|
+
input?: string[];
|
|
16
|
+
output?: string[];
|
|
17
|
+
};
|
|
18
|
+
open_weights?: boolean;
|
|
19
|
+
cost?: {
|
|
20
|
+
input?: number;
|
|
21
|
+
output?: number;
|
|
22
|
+
cache_read?: number;
|
|
23
|
+
};
|
|
24
|
+
limit?: {
|
|
25
|
+
context?: number;
|
|
26
|
+
output?: number;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export interface ModelsDevProvider {
|
|
30
|
+
id: string;
|
|
31
|
+
env?: string[];
|
|
32
|
+
npm?: string;
|
|
33
|
+
name?: string;
|
|
34
|
+
doc?: string;
|
|
35
|
+
models: Record<string, ModelsDevModel>;
|
|
36
|
+
}
|
|
37
|
+
export type ModelsDevData = Record<string, ModelsDevProvider>;
|
|
38
|
+
export interface ModelsDevIndex {
|
|
39
|
+
exactByProvider: Map<string, Map<string, ModelsDevModel>>;
|
|
40
|
+
normalizedByProvider: Map<string, Map<string, ModelsDevModel>>;
|
|
41
|
+
exactGlobal: Map<string, ModelsDevModel[]>;
|
|
42
|
+
normalizedGlobal: Map<string, ModelsDevModel[]>;
|
|
43
|
+
}
|
|
44
|
+
export declare function fetchModelsDevData(config?: OmniRouteConfig): Promise<ModelsDevData | null>;
|
|
45
|
+
export declare function buildModelsDevIndex(data: ModelsDevData | null): ModelsDevIndex | null;
|
|
46
|
+
export declare function getModelsDevIndex(config?: OmniRouteConfig): Promise<ModelsDevIndex | null>;
|
|
47
|
+
export declare function clearModelsDevCache(): void;
|
|
48
|
+
export declare function normalizeModelKey(modelId: string): string;
|
|
49
|
+
export declare function modelsDevToMetadata(model: ModelsDevModel): OmniRouteModelMetadata;
|
|
50
|
+
export declare function calculateLowestCommonCapabilities(models: ModelsDevModel[]): OmniRouteModelMetadata;
|
|
51
|
+
export declare function resolveProviderAlias(providerKey: string | null, config?: OmniRouteConfig): string | null;
|
|
52
|
+
//# sourceMappingURL=models-dev.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models-dev.d.ts","sourceRoot":"","sources":["../../src/models-dev.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAQ1E,MAAM,WAAW,cAAc;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,iBAAiB,CAAC,EAAE,OAAO,CAAC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