@oai2lmapi/opencode-provider 0.1.3 → 0.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/README.md +164 -266
- package/dist/config.d.ts +24 -41
- package/dist/config.d.ts.map +1 -1
- package/dist/discover.d.ts +28 -0
- package/dist/discover.d.ts.map +1 -0
- package/dist/index.d.ts +97 -26
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +274 -333
- package/dist/index.js.map +3 -3
- package/dist/metadata.d.ts +36 -0
- package/dist/metadata.d.ts.map +1 -0
- package/oai2lm.schema.json +79 -0
- package/package.json +20 -13
- package/dist/modelDiscovery.d.ts +0 -31
- package/dist/modelDiscovery.d.ts.map +0 -1
- package/dist/modelMetadata.d.ts +0 -14
- package/dist/modelMetadata.d.ts.map +0 -1
- package/dist/provider.d.ts +0 -65
- package/dist/provider.d.ts.map +0 -1
- package/dist/types.d.ts +0 -69
- package/dist/types.d.ts.map +0 -1
- package/dist/utils.d.ts +0 -18
- package/dist/utils.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
# @oai2lmapi/opencode-provider
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
AI SDK Provider for **OpenAI-compatible APIs** with **automatic model discovery**.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Use this provider in [OpenCode](https://opencode.ai) to connect to any OpenAI-compatible API endpoint. Unlike static configurations, this provider automatically discovers all available models from your API's `/models` endpoint.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
- **Smart Configuration**: Automatically detects model capabilities (tool calling, vision, context limits)
|
|
9
|
-
- **Flexible Overrides**: Per-model configuration via OpenCode settings
|
|
10
|
-
- **Based on AI SDK**: Built on top of Vercel AI SDK's `@ai-sdk/openai-compatible`
|
|
7
|
+
## Features
|
|
11
8
|
|
|
12
|
-
|
|
9
|
+
- **AI SDK Provider**: Native provider for OpenCode and Vercel AI SDK
|
|
10
|
+
- **Auto-discovery**: Automatically fetches models from `$baseURL/models`
|
|
11
|
+
- **Zero model configuration**: No need to manually list each model
|
|
12
|
+
- **Metadata enrichment**: Merges API-returned metadata with `@oai2lmapi/model-metadata` registry
|
|
13
|
+
- **Wildcard overrides**: Apply settings to multiple models using patterns like `gpt-4*`
|
|
14
|
+
- **Config file support**: Optional `oai2lm.json` for persistent configuration
|
|
13
15
|
|
|
14
16
|
## Installation
|
|
15
17
|
|
|
@@ -17,325 +19,221 @@ OpenAI-compatible provider for [OpenCode](https://github.com/anomalyco/opencode)
|
|
|
17
19
|
npm install @oai2lmapi/opencode-provider
|
|
18
20
|
# or
|
|
19
21
|
pnpm add @oai2lmapi/opencode-provider
|
|
20
|
-
# or
|
|
21
|
-
yarn add @oai2lmapi/opencode-provider
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
## Usage
|
|
24
|
+
## Usage with OpenCode
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
Add to your `opencode.json`:
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
```json
|
|
29
|
+
{
|
|
30
|
+
"$schema": "https://opencode.ai/config.json",
|
|
31
|
+
"provider": {
|
|
32
|
+
"my-api": {
|
|
33
|
+
"npm": "@oai2lmapi/opencode-provider",
|
|
34
|
+
"options": {
|
|
35
|
+
"baseURL": "https://api.example.com/v1",
|
|
36
|
+
"apiKey": "your-api-key"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
```
|
|
29
42
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
That's it! OpenCode will automatically discover all available models from your API.
|
|
44
|
+
|
|
45
|
+
### Using environment variables
|
|
46
|
+
|
|
47
|
+
```json
|
|
48
|
+
{
|
|
49
|
+
"provider": {
|
|
50
|
+
"my-api": {
|
|
51
|
+
"npm": "@oai2lmapi/opencode-provider",
|
|
52
|
+
"env": ["MY_API_KEY"],
|
|
53
|
+
"options": {
|
|
54
|
+
"baseURL": "https://api.example.com/v1"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
41
59
|
```
|
|
42
60
|
|
|
43
|
-
|
|
61
|
+
Set `MY_API_KEY` in your environment:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
export MY_API_KEY=your-api-key
|
|
65
|
+
```
|
|
44
66
|
|
|
45
|
-
|
|
67
|
+
## Programmatic Usage
|
|
46
68
|
|
|
47
69
|
```typescript
|
|
48
|
-
import {
|
|
70
|
+
import { createOai2lm } from "@oai2lmapi/opencode-provider";
|
|
71
|
+
import { streamText } from "ai";
|
|
49
72
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
baseURL:
|
|
53
|
-
|
|
73
|
+
// Create provider
|
|
74
|
+
const provider = createOai2lm({
|
|
75
|
+
baseURL: "https://api.example.com/v1",
|
|
76
|
+
apiKey: "your-api-key",
|
|
54
77
|
});
|
|
55
78
|
|
|
56
|
-
//
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
79
|
+
// List discovered models
|
|
80
|
+
const models = await provider.listModels();
|
|
81
|
+
console.log(models);
|
|
82
|
+
|
|
83
|
+
// Use a model
|
|
84
|
+
const model = provider.languageModel("gpt-4");
|
|
85
|
+
const result = await streamText({
|
|
86
|
+
model,
|
|
87
|
+
messages: [{ role: "user", content: "Hello!" }],
|
|
60
88
|
});
|
|
61
89
|
```
|
|
62
90
|
|
|
63
|
-
|
|
91
|
+
## Provider Options
|
|
64
92
|
|
|
65
|
-
|
|
93
|
+
| Option | Type | Required | Description |
|
|
94
|
+
| ---------------- | --------- | -------- | ----------------------------------------------------------- |
|
|
95
|
+
| `baseURL` | `string` | Yes | Base URL for API calls (e.g., `https://api.example.com/v1`) |
|
|
96
|
+
| `apiKey` | `string` | No | API key for authentication |
|
|
97
|
+
| `name` | `string` | No | Provider name (default: `"oai2lm"`) |
|
|
98
|
+
| `headers` | `object` | No | Custom headers for all requests |
|
|
99
|
+
| `modelFilter` | `string` | No | Regex pattern to filter models |
|
|
100
|
+
| `modelOverrides` | `object` | No | Per-model configuration overrides (supports wildcards) |
|
|
101
|
+
| `useConfigFile` | `boolean` | No | Merge settings from `oai2lm.json` (default: `true`) |
|
|
66
102
|
|
|
67
|
-
|
|
68
|
-
const provider = createOAI2LMProvider({
|
|
69
|
-
apiKey: process.env.MY_API_KEY,
|
|
70
|
-
baseURL: 'https://api.example.com/v1',
|
|
71
|
-
modelOverrides: {
|
|
72
|
-
'deepseek-*': {
|
|
73
|
-
// Use prompt-based tool calling for DeepSeek models
|
|
74
|
-
usePromptBasedToolCalling: true,
|
|
75
|
-
// Strip chain-of-thought tags
|
|
76
|
-
suppressChainOfThought: true,
|
|
77
|
-
},
|
|
78
|
-
'o1-*': {
|
|
79
|
-
// Enable reasoning capture for o1 models
|
|
80
|
-
captureReasoning: true,
|
|
81
|
-
},
|
|
82
|
-
'gpt-4-vision': {
|
|
83
|
-
// Override capabilities
|
|
84
|
-
supportsImageInput: true,
|
|
85
|
-
maxInputTokens: 128000,
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
});
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
### Chain-of-Thought Handling
|
|
103
|
+
## Config File
|
|
92
104
|
|
|
93
|
-
For
|
|
105
|
+
For persistent configuration, create `oai2lm.json` in one of these locations:
|
|
94
106
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
apiKey: process.env.MY_API_KEY,
|
|
98
|
-
baseURL: 'https://api.example.com/v1',
|
|
99
|
-
modelOverrides: {
|
|
100
|
-
'reasoning-model-*': {
|
|
101
|
-
// Capture and expose chain-of-thought
|
|
102
|
-
captureReasoning: true,
|
|
103
|
-
// Or suppress it from output
|
|
104
|
-
suppressChainOfThought: false,
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
});
|
|
107
|
+
1. `~/.local/share/opencode/oai2lm.json`
|
|
108
|
+
2. `~/.config/opencode/oai2lm.json`
|
|
108
109
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
```jsonc
|
|
111
|
+
{
|
|
112
|
+
// Base URL for your OpenAI-compatible API
|
|
113
|
+
"baseURL": "https://api.example.com/v1",
|
|
113
114
|
|
|
114
|
-
//
|
|
115
|
-
|
|
116
|
-
console.log(result.text); // Final answer without <think> tags
|
|
117
|
-
```
|
|
115
|
+
// API key (supports variable substitution)
|
|
116
|
+
"apiKey": "{env:MY_API_KEY}",
|
|
118
117
|
|
|
119
|
-
|
|
118
|
+
// Provider ID
|
|
119
|
+
"name": "myapi",
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
// Display name
|
|
122
|
+
"displayName": "My API",
|
|
122
123
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
baseURL: 'https://api.example.com/v1',
|
|
127
|
-
modelOverrides: {
|
|
128
|
-
'legacy-model': {
|
|
129
|
-
usePromptBasedToolCalling: true,
|
|
130
|
-
},
|
|
124
|
+
// Custom headers
|
|
125
|
+
"headers": {
|
|
126
|
+
"X-Custom-Header": "value",
|
|
131
127
|
},
|
|
132
|
-
});
|
|
133
128
|
|
|
134
|
-
//
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
location: z.string(),
|
|
143
|
-
}),
|
|
144
|
-
execute: async ({ location }) => {
|
|
145
|
-
// ... fetch weather
|
|
146
|
-
},
|
|
129
|
+
// Filter models by regex
|
|
130
|
+
"modelFilter": "^(gpt-|claude-)",
|
|
131
|
+
|
|
132
|
+
// Override model metadata (supports wildcards)
|
|
133
|
+
"modelOverrides": {
|
|
134
|
+
"gpt-4*": {
|
|
135
|
+
"maxInputTokens": 128000,
|
|
136
|
+
"supportsImageInput": true,
|
|
147
137
|
},
|
|
148
138
|
},
|
|
149
|
-
}
|
|
139
|
+
}
|
|
150
140
|
```
|
|
151
141
|
|
|
152
|
-
|
|
142
|
+
### Variable substitution
|
|
153
143
|
|
|
154
|
-
|
|
144
|
+
The `apiKey` field supports:
|
|
155
145
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
/** API key for authentication */
|
|
159
|
-
apiKey: string;
|
|
160
|
-
|
|
161
|
-
/** Base URL for API calls (e.g., 'https://api.example.com/v1') */
|
|
162
|
-
baseURL: string;
|
|
163
|
-
|
|
164
|
-
/** Provider name (defaults to 'oai2lm') */
|
|
165
|
-
name?: string;
|
|
166
|
-
|
|
167
|
-
/** Custom headers */
|
|
168
|
-
headers?: Record<string, string>;
|
|
169
|
-
|
|
170
|
-
/** Auto-discover models on initialization (default: true) */
|
|
171
|
-
autoDiscoverModels?: boolean;
|
|
172
|
-
|
|
173
|
-
/** Per-model configuration overrides */
|
|
174
|
-
modelOverrides?: Record<string, ModelOverride>;
|
|
175
|
-
|
|
176
|
-
/** Custom fetch implementation */
|
|
177
|
-
fetch?: typeof fetch;
|
|
178
|
-
}
|
|
179
|
-
```
|
|
146
|
+
- `{env:VAR_NAME}` - Read from environment variable
|
|
147
|
+
- `{file:/path/to/file}` - Read from file
|
|
180
148
|
|
|
181
|
-
|
|
149
|
+
## Extended API
|
|
150
|
+
|
|
151
|
+
### `provider.listModels()`
|
|
152
|
+
|
|
153
|
+
Returns a list of discovered models with metadata:
|
|
182
154
|
|
|
183
155
|
```typescript
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
maxInputTokens?: number;
|
|
187
|
-
|
|
188
|
-
/** Max output tokens */
|
|
189
|
-
maxOutputTokens?: number;
|
|
190
|
-
|
|
191
|
-
/** Supports native tool/function calling */
|
|
192
|
-
supportsToolCalling?: boolean;
|
|
193
|
-
|
|
194
|
-
/** Supports image inputs */
|
|
195
|
-
supportsImageInput?: boolean;
|
|
196
|
-
|
|
197
|
-
/** Default temperature */
|
|
198
|
-
temperature?: number;
|
|
199
|
-
|
|
200
|
-
/** Use XML-based prompt engineering for tools */
|
|
201
|
-
usePromptBasedToolCalling?: boolean;
|
|
202
|
-
|
|
203
|
-
/** Strip <think>...</think> blocks from output */
|
|
204
|
-
suppressChainOfThought?: boolean;
|
|
205
|
-
|
|
206
|
-
/** Capture reasoning content separately */
|
|
207
|
-
captureReasoning?: boolean;
|
|
208
|
-
|
|
209
|
-
/** Thinking level: token budget or 'low'/'medium'/'high' */
|
|
210
|
-
thinkingLevel?: number | 'low' | 'medium' | 'high' | 'auto';
|
|
211
|
-
}
|
|
156
|
+
const models = await provider.listModels();
|
|
157
|
+
// [{ id: "gpt-4", name: "GPT-4", object: "model", ... }]
|
|
212
158
|
```
|
|
213
159
|
|
|
214
|
-
|
|
160
|
+
### `provider.getModelMetadata(modelId)`
|
|
215
161
|
|
|
216
|
-
|
|
217
|
-
2. **Capability Detection**: Analyzes model metadata to determine capabilities
|
|
218
|
-
3. **Shared Metadata Registry**: Uses `@oai2lmapi/model-metadata` for fallback model info
|
|
219
|
-
4. **Metadata Caching**: Model info is cached to reduce API calls
|
|
220
|
-
5. **Override Application**: User-defined overrides are applied on top of discovered capabilities
|
|
221
|
-
6. **Request Translation**: Converts AI SDK requests to OpenAI-compatible format
|
|
222
|
-
7. **Response Parsing**: Handles special formats like `<think>` tags and XML tool calls
|
|
162
|
+
Returns enriched metadata for a specific model:
|
|
223
163
|
|
|
224
|
-
|
|
164
|
+
```typescript
|
|
165
|
+
const metadata = await provider.getModelMetadata("gpt-4");
|
|
166
|
+
// { maxInputTokens: 128000, maxOutputTokens: 4096, supportsToolCalling: true, ... }
|
|
167
|
+
```
|
|
225
168
|
|
|
226
|
-
|
|
169
|
+
### `provider.refreshModels()`
|
|
227
170
|
|
|
228
|
-
|
|
229
|
-
- `~/.config/opencode/oai2lm.json` (alternative location, checked second as a fallback — corresponds to `$XDG_CONFIG_HOME/opencode/oai2lm.json` with the common default of `~/.config`)
|
|
171
|
+
Force refresh the model list from the API:
|
|
230
172
|
|
|
231
|
-
|
|
173
|
+
```typescript
|
|
174
|
+
await provider.refreshModels();
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Example Configurations
|
|
232
178
|
|
|
233
|
-
###
|
|
179
|
+
### OpenRouter
|
|
234
180
|
|
|
235
181
|
```json
|
|
236
182
|
{
|
|
237
|
-
"
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
"suppressChainOfThought": true
|
|
245
|
-
},
|
|
246
|
-
"gpt-4-vision": {
|
|
247
|
-
"supportsImageInput": true,
|
|
248
|
-
"maxInputTokens": 128000
|
|
183
|
+
"provider": {
|
|
184
|
+
"openrouter": {
|
|
185
|
+
"npm": "@oai2lmapi/opencode-provider",
|
|
186
|
+
"env": ["OPENROUTER_API_KEY"],
|
|
187
|
+
"options": {
|
|
188
|
+
"baseURL": "https://openrouter.ai/api/v1"
|
|
189
|
+
}
|
|
249
190
|
}
|
|
250
191
|
}
|
|
251
192
|
}
|
|
252
193
|
```
|
|
253
194
|
|
|
254
|
-
###
|
|
195
|
+
### Local Ollama
|
|
255
196
|
|
|
256
|
-
```
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
});
|
|
197
|
+
```json
|
|
198
|
+
{
|
|
199
|
+
"provider": {
|
|
200
|
+
"ollama": {
|
|
201
|
+
"npm": "@oai2lmapi/opencode-provider",
|
|
202
|
+
"options": {
|
|
203
|
+
"baseURL": "http://localhost:11434/v1",
|
|
204
|
+
"apiKey": "ollama"
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
269
209
|
```
|
|
270
210
|
|
|
271
|
-
###
|
|
272
|
-
|
|
273
|
-
You can also configure via environment variables:
|
|
274
|
-
|
|
275
|
-
- `OAI2LM_API_KEY` - API key for authentication
|
|
276
|
-
- `OAI2LM_BASE_URL` - Base URL for API calls
|
|
211
|
+
### Together AI
|
|
277
212
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
providers: {
|
|
291
|
-
myapi: {
|
|
292
|
-
type: '@oai2lmapi/opencode-provider',
|
|
293
|
-
apiKey: process.env.MY_API_KEY,
|
|
294
|
-
baseURL: 'https://api.example.com/v1',
|
|
295
|
-
modelOverrides: {
|
|
296
|
-
// Configure models as needed
|
|
297
|
-
},
|
|
298
|
-
},
|
|
299
|
-
},
|
|
300
|
-
models: {
|
|
301
|
-
default: 'myapi:gpt-4',
|
|
302
|
-
},
|
|
303
|
-
};
|
|
213
|
+
```json
|
|
214
|
+
{
|
|
215
|
+
"provider": {
|
|
216
|
+
"together": {
|
|
217
|
+
"npm": "@oai2lmapi/opencode-provider",
|
|
218
|
+
"env": ["TOGETHER_API_KEY"],
|
|
219
|
+
"options": {
|
|
220
|
+
"baseURL": "https://api.together.xyz/v1"
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
304
225
|
```
|
|
305
226
|
|
|
306
|
-
##
|
|
307
|
-
|
|
308
|
-
### Using with Multiple Providers
|
|
309
|
-
|
|
310
|
-
```typescript
|
|
311
|
-
import { createOAI2LMProvider } from '@oai2lmapi/opencode-provider';
|
|
312
|
-
|
|
313
|
-
const openai = createOAI2LMProvider({
|
|
314
|
-
name: 'openai',
|
|
315
|
-
apiKey: process.env.OPENAI_API_KEY,
|
|
316
|
-
baseURL: 'https://api.openai.com/v1',
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
const deepseek = createOAI2LMProvider({
|
|
320
|
-
name: 'deepseek',
|
|
321
|
-
apiKey: process.env.DEEPSEEK_API_KEY,
|
|
322
|
-
baseURL: 'https://api.deepseek.com/v1',
|
|
323
|
-
modelOverrides: {
|
|
324
|
-
'*': {
|
|
325
|
-
usePromptBasedToolCalling: true,
|
|
326
|
-
},
|
|
327
|
-
},
|
|
328
|
-
});
|
|
227
|
+
## How It Works
|
|
329
228
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
229
|
+
1. When loaded, the provider creates an `@ai-sdk/openai-compatible` instance
|
|
230
|
+
2. On first model request or `listModels()` call, it fetches `/models` from your API
|
|
231
|
+
3. Each model is enriched with metadata from:
|
|
232
|
+
- API response (context_length, max_tokens, etc.)
|
|
233
|
+
- `@oai2lmapi/model-metadata` pattern matching
|
|
234
|
+
- Your config file overrides
|
|
235
|
+
4. The provider then works like any standard AI SDK provider
|
|
334
236
|
|
|
335
237
|
## License
|
|
336
238
|
|
|
337
239
|
MIT
|
|
338
|
-
|
|
339
|
-
## Contributing
|
|
340
|
-
|
|
341
|
-
Contributions are welcome! Please see the main repository for guidelines.
|
package/dist/config.d.ts
CHANGED
|
@@ -9,7 +9,19 @@
|
|
|
9
9
|
* - ~/.local/share/opencode/ contains data files (auth.json, etc.)
|
|
10
10
|
* - ~/.config/opencode/ contains user configuration
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Model override configuration.
|
|
14
|
+
*/
|
|
15
|
+
export interface ModelOverride {
|
|
16
|
+
/** Max input tokens */
|
|
17
|
+
maxInputTokens?: number;
|
|
18
|
+
/** Max output tokens */
|
|
19
|
+
maxOutputTokens?: number;
|
|
20
|
+
/** Supports native tool/function calling */
|
|
21
|
+
supportsToolCalling?: boolean;
|
|
22
|
+
/** Supports image inputs */
|
|
23
|
+
supportsImageInput?: boolean;
|
|
24
|
+
}
|
|
13
25
|
/**
|
|
14
26
|
* Configuration file structure for oai2lm.json
|
|
15
27
|
*/
|
|
@@ -18,32 +30,27 @@ export interface OAI2LMConfig {
|
|
|
18
30
|
apiKey?: string;
|
|
19
31
|
/** Base URL for API calls */
|
|
20
32
|
baseURL?: string;
|
|
21
|
-
/** Provider
|
|
33
|
+
/** Provider ID used in OpenCode (defaults to 'oai2lm') */
|
|
22
34
|
name?: string;
|
|
35
|
+
/** Display name shown in OpenCode UI */
|
|
36
|
+
displayName?: string;
|
|
23
37
|
/**
|
|
24
38
|
* Custom headers applied to all requests.
|
|
25
|
-
*
|
|
26
|
-
* When combined with override headers (e.g. from model overrides or
|
|
27
|
-
* runtime settings), config file headers are applied first and then
|
|
28
|
-
* override headers are spread on top. This means any override header
|
|
29
|
-
* with the same key will replace the corresponding config file value.
|
|
30
39
|
*/
|
|
31
40
|
headers?: Record<string, string>;
|
|
32
|
-
/** Auto-discover models on initialization (default: true) */
|
|
33
|
-
autoDiscoverModels?: boolean;
|
|
34
41
|
/** Per-model configuration overrides (supports wildcards) */
|
|
35
42
|
modelOverrides?: Record<string, ModelOverride>;
|
|
43
|
+
/** Filter function pattern - only include models matching this pattern */
|
|
44
|
+
modelFilter?: string;
|
|
36
45
|
}
|
|
37
46
|
/**
|
|
38
47
|
* Get the OpenCode data directory path
|
|
39
48
|
* Follows XDG Base Directory Specification
|
|
40
|
-
* Note: XDG spec requires absolute paths; relative paths are ignored
|
|
41
49
|
*/
|
|
42
50
|
export declare function getDataDir(): string;
|
|
43
51
|
/**
|
|
44
52
|
* Get the OpenCode config directory path
|
|
45
53
|
* Follows XDG Base Directory Specification
|
|
46
|
-
* Note: XDG spec requires absolute paths; relative paths are ignored
|
|
47
54
|
*/
|
|
48
55
|
export declare function getConfigDir(): string;
|
|
49
56
|
/**
|
|
@@ -57,40 +64,16 @@ export declare const CONFIG_FILENAME = "oai2lm.json";
|
|
|
57
64
|
* 1. ~/.local/share/opencode/oai2lm.json (data directory)
|
|
58
65
|
* 2. ~/.config/opencode/oai2lm.json (config directory)
|
|
59
66
|
*
|
|
60
|
-
*
|
|
61
|
-
* the first readable file found in this order is used.
|
|
67
|
+
* @returns Merged configuration or undefined if no config found
|
|
62
68
|
*/
|
|
63
69
|
export declare function loadConfig(): OAI2LMConfig | undefined;
|
|
64
70
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
* Priority:
|
|
68
|
-
* 1. Explicit apiKey in settings
|
|
69
|
-
* 2. Environment variable OAI2LM_API_KEY
|
|
70
|
-
* 3. Config file apiKey
|
|
71
|
-
*/
|
|
72
|
-
export declare function resolveApiKey(explicitKey?: string, config?: OAI2LMConfig): string | undefined;
|
|
73
|
-
/**
|
|
74
|
-
* Load base URL from environment or config
|
|
75
|
-
*
|
|
76
|
-
* Priority:
|
|
77
|
-
* 1. Explicit baseURL in settings
|
|
78
|
-
* 2. Environment variable OAI2LM_BASE_URL
|
|
79
|
-
* 3. Config file baseURL
|
|
80
|
-
* 4. Default: https://api.openai.com/v1
|
|
81
|
-
*/
|
|
82
|
-
export declare function resolveBaseURL(explicitURL?: string, config?: OAI2LMConfig): string;
|
|
83
|
-
/**
|
|
84
|
-
* Create provider settings from config file and overrides
|
|
85
|
-
*
|
|
86
|
-
* This is a convenience function that:
|
|
87
|
-
* 1. Loads config from oai2lm.json
|
|
88
|
-
* 2. Applies explicit settings as overrides
|
|
89
|
-
* 3. Returns complete settings ready for provider creation
|
|
71
|
+
* Get the path to the configuration file if it exists.
|
|
90
72
|
*/
|
|
91
|
-
export declare function
|
|
73
|
+
export declare function getConfigFilePath(): string | undefined;
|
|
92
74
|
/**
|
|
93
|
-
*
|
|
75
|
+
* Resolve API key from config or environment variable.
|
|
76
|
+
* Supports {env:VAR} and {file:path} syntax.
|
|
94
77
|
*/
|
|
95
|
-
export declare function
|
|
78
|
+
export declare function resolveApiKey(config: OAI2LMConfig): string | undefined;
|
|
96
79
|
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAMH;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,uBAAuB;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,wBAAwB;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,4CAA4C;IAC5C,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,4BAA4B;IAC5B,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,6DAA6D;IAC7D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,6BAA6B;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0DAA0D;IAC1D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wCAAwC;IACxC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,6DAA6D;IAC7D,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC/C,0EAA0E;IAC1E,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;GAGG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAMnC;AAED;;;GAGG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAMrC;AAED;;GAEG;AACH,eAAO,MAAM,eAAe,gBAAgB,CAAC;AAwB7C;;;;;;;;GAQG;AACH,wBAAgB,UAAU,IAAI,YAAY,GAAG,SAAS,CA6BrD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,GAAG,SAAS,CAYtD;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,GAAG,SAAS,CA0BtE"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model discovery: fetch models from OpenAI-compatible /models endpoint
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Partial metadata extracted from API response
|
|
6
|
+
*/
|
|
7
|
+
export interface PartialModelMetadata {
|
|
8
|
+
maxInputTokens?: number;
|
|
9
|
+
maxOutputTokens?: number;
|
|
10
|
+
supportsToolCalling?: boolean;
|
|
11
|
+
supportsImageInput?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Discovered model from API
|
|
15
|
+
*/
|
|
16
|
+
export interface DiscoveredModel {
|
|
17
|
+
id: string;
|
|
18
|
+
name?: string;
|
|
19
|
+
object: string;
|
|
20
|
+
created?: number;
|
|
21
|
+
owned_by?: string;
|
|
22
|
+
metadata?: PartialModelMetadata;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Fetch models from the OpenAI-compatible /models endpoint
|
|
26
|
+
*/
|
|
27
|
+
export declare function discoverModels(baseURL: string, apiKey: string, headers?: Record<string, string>): Promise<DiscoveredModel[]>;
|
|
28
|
+
//# sourceMappingURL=discover.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discover.d.ts","sourceRoot":"","sources":["../src/discover.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,oBAAoB,CAAC;CACjC;AA2BD;;GAEG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,OAAO,CAAC,eAAe,EAAE,CAAC,CA8B5B"}
|