@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/dist/index.d.ts
CHANGED
|
@@ -1,37 +1,108 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @oai2lmapi/opencode-provider
|
|
3
3
|
*
|
|
4
|
-
* OpenAI-compatible
|
|
4
|
+
* AI SDK Provider for OpenAI-compatible APIs with automatic model discovery.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* -
|
|
6
|
+
* This provider:
|
|
7
|
+
* 1. Reads configuration from oai2lm.json (baseURL, apiKey, etc.)
|
|
8
|
+
* 2. Auto-discovers models from the /models endpoint
|
|
9
|
+
* 3. Provides LanguageModelV2 instances for each discovered model
|
|
9
10
|
*
|
|
10
|
-
*
|
|
11
|
+
* Usage in opencode.json:
|
|
12
|
+
* {
|
|
13
|
+
* "provider": {
|
|
14
|
+
* "my-provider": {
|
|
15
|
+
* "npm": "@oai2lmapi/opencode-provider",
|
|
16
|
+
* "options": {
|
|
17
|
+
* "baseURL": "https://api.example.com/v1",
|
|
18
|
+
* "apiKey": "your-api-key"
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
11
23
|
*/
|
|
12
|
-
import {
|
|
13
|
-
import { loadConfig
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export type
|
|
17
|
-
export type { ModelDiscovery } from './modelDiscovery.js';
|
|
24
|
+
import { type OpenAICompatibleProvider } from "@ai-sdk/openai-compatible";
|
|
25
|
+
import { loadConfig, resolveApiKey, type OAI2LMConfig, type ModelOverride } from "./config.js";
|
|
26
|
+
import { discoverModels, type DiscoveredModel } from "./discover.js";
|
|
27
|
+
import { type ModelMetadata } from "./metadata.js";
|
|
28
|
+
export { loadConfig, resolveApiKey, discoverModels, type OAI2LMConfig, type ModelOverride, type DiscoveredModel, type ModelMetadata, };
|
|
18
29
|
/**
|
|
19
|
-
*
|
|
20
|
-
* This prevents OpenCode's plugin loader from crashing when iterating over exports.
|
|
30
|
+
* Provider settings that extend OpenAI-compatible settings
|
|
21
31
|
*/
|
|
22
|
-
|
|
32
|
+
export interface Oai2lmProviderSettings {
|
|
33
|
+
/**
|
|
34
|
+
* Base URL for API calls (required).
|
|
35
|
+
* Example: "https://api.example.com/v1"
|
|
36
|
+
*/
|
|
37
|
+
baseURL: string;
|
|
38
|
+
/**
|
|
39
|
+
* API key for authentication.
|
|
40
|
+
* If not provided, will try to load from config file or environment.
|
|
41
|
+
*/
|
|
42
|
+
apiKey?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Provider name (used for identification in logs).
|
|
45
|
+
* Defaults to "oai2lm".
|
|
46
|
+
*/
|
|
47
|
+
name?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Custom headers to include in all requests.
|
|
50
|
+
*/
|
|
51
|
+
headers?: Record<string, string>;
|
|
52
|
+
/**
|
|
53
|
+
* Model filter pattern (regex). Only models matching this pattern will be available.
|
|
54
|
+
*/
|
|
55
|
+
modelFilter?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Per-model configuration overrides.
|
|
58
|
+
* Keys can use wildcards (e.g., "gpt-*", "claude-*").
|
|
59
|
+
*/
|
|
60
|
+
modelOverrides?: Record<string, ModelOverride>;
|
|
61
|
+
/**
|
|
62
|
+
* Whether to use config file for additional settings.
|
|
63
|
+
* If true, will merge settings from oai2lm.json.
|
|
64
|
+
* @default true
|
|
65
|
+
*/
|
|
66
|
+
useConfigFile?: boolean;
|
|
67
|
+
}
|
|
23
68
|
/**
|
|
24
|
-
*
|
|
69
|
+
* Extended provider interface with model discovery
|
|
25
70
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
71
|
+
export interface Oai2lmProvider extends OpenAICompatibleProvider<string, string, string, string> {
|
|
72
|
+
/**
|
|
73
|
+
* Get list of available models (discovered from API)
|
|
74
|
+
*/
|
|
75
|
+
listModels(): Promise<DiscoveredModel[]>;
|
|
76
|
+
/**
|
|
77
|
+
* Get metadata for a specific model
|
|
78
|
+
*/
|
|
79
|
+
getModelMetadata(modelId: string): Promise<ModelMetadata | undefined>;
|
|
80
|
+
/**
|
|
81
|
+
* Refresh the model list from the API
|
|
82
|
+
*/
|
|
83
|
+
refreshModels(): Promise<void>;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Create an Oai2lm provider instance.
|
|
87
|
+
*
|
|
88
|
+
* This provider wraps @ai-sdk/openai-compatible and adds:
|
|
89
|
+
* - Automatic model discovery from /models endpoint
|
|
90
|
+
* - Configuration file support (oai2lm.json)
|
|
91
|
+
* - Model metadata from pattern matching
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* import { createOai2lm } from "@oai2lmapi/opencode-provider";
|
|
96
|
+
*
|
|
97
|
+
* const provider = createOai2lm({
|
|
98
|
+
* baseURL: "https://api.example.com/v1",
|
|
99
|
+
* apiKey: "your-api-key",
|
|
100
|
+
* });
|
|
101
|
+
*
|
|
102
|
+
* // Use any model
|
|
103
|
+
* const model = provider.languageModel("gpt-4");
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export declare function createOai2lm(options: Oai2lmProviderSettings): Oai2lmProvider;
|
|
107
|
+
export default createOai2lm;
|
|
37
108
|
//# 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
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAEL,KAAK,wBAAwB,EAC9B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,UAAU,EACV,aAAa,EACb,KAAK,YAAY,EACjB,KAAK,aAAa,EACnB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EAGL,KAAK,aAAa,EACnB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,UAAU,EACV,aAAa,EACb,cAAc,EACd,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,aAAa,GACnB,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEjC;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CA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