@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/dist/index.d.ts CHANGED
@@ -1,37 +1,108 @@
1
1
  /**
2
2
  * @oai2lmapi/opencode-provider
3
3
  *
4
- * OpenAI-compatible provider for OpenCode with auto-discovery and advanced features
4
+ * AI SDK Provider for OpenAI-compatible APIs with automatic model discovery.
5
5
  *
6
- * Main exports:
7
- * - createOAI2LMProvider: Factory function to create a callable provider
8
- * - createOAI2LMProviderFromConfig: Factory function to create provider from config file
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
- * For configuration utilities, import from './config.js'
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 { createOAI2LMProvider as _createOAI2LMProvider, createOAI2LMProviderFromConfig as _createOAI2LMProviderFromConfig, type OAI2LMProvider } from './provider.js';
13
- import { loadConfig as _loadConfig, createSettingsFromConfig as _createSettingsFromConfig, getConfigFilePath as _getConfigFilePath, getDataDir as _getDataDir, getConfigDir as _getConfigDir, resolveApiKey as _resolveApiKey, resolveBaseURL as _resolveBaseURL, type OAI2LMConfig } from './config.js';
14
- export type { OAI2LMProvider };
15
- export type { OAI2LMProviderSettings, ModelOverride, ModelMetadata, ModelInfo, } from './types.js';
16
- export type { OAI2LMConfig };
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
- * Empty hooks object returned when functions are mistakenly called as plugin factories.
20
- * This prevents OpenCode's plugin loader from crashing when iterating over exports.
30
+ * Provider settings that extend OpenAI-compatible settings
21
31
  */
22
- declare const EMPTY_HOOKS: Readonly<{}>;
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
- * Type for a guarded function that may return EMPTY_HOOKS when called with PluginInput.
69
+ * Extended provider interface with model discovery
25
70
  */
26
- type Guarded<T extends (...args: any[]) => any> = (...args: Parameters<T>) => ReturnType<T> | typeof EMPTY_HOOKS;
27
- export declare const createOAI2LMProvider: Guarded<typeof _createOAI2LMProvider>;
28
- export declare const createOAI2LMProviderFromConfig: Guarded<typeof _createOAI2LMProviderFromConfig>;
29
- export declare const loadConfig: Guarded<typeof _loadConfig>;
30
- export declare const createSettingsFromConfig: Guarded<typeof _createSettingsFromConfig>;
31
- export declare const getConfigFilePath: Guarded<typeof _getConfigFilePath>;
32
- export declare const getDataDir: Guarded<typeof _getDataDir>;
33
- export declare const getConfigDir: Guarded<typeof _getConfigDir>;
34
- export declare const resolveApiKey: Guarded<typeof _resolveApiKey>;
35
- export declare const resolveBaseURL: Guarded<typeof _resolveBaseURL>;
36
- export declare const getModelMetadataFromPatterns: Guarded<(modelId: string) => import("./types.js").ModelMetadata>;
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
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EACL,oBAAoB,IAAI,qBAAqB,EAC7C,8BAA8B,IAAI,+BAA+B,EACjE,KAAK,cAAc,EACpB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL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