opencode-openai-compatible-discovery 0.1.0 → 0.1.1
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 +24 -21
- package/discovery.ts +4 -4
- package/index.ts +10 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -33,26 +33,31 @@ Then configure the endpoint in `~/.config/opencode/opencode.jsonc`:
|
|
|
33
33
|
}
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
| Option
|
|
37
|
-
|
|
|
38
|
-
| `baseURL`
|
|
39
|
-
| `apiKey`
|
|
40
|
-
| `providerID`
|
|
41
|
-
| `providerName`
|
|
42
|
-
| `
|
|
43
|
-
| `
|
|
44
|
-
| `
|
|
36
|
+
| Option | Default | Description |
|
|
37
|
+
| --------------- | ----------------------------------------------- | -------------------------------------------------------------------------------------------- |
|
|
38
|
+
| `baseURL` | None (required per provider) | Base URL of the OpenAI-compatible API, including `/v1` if required by the endpoint. |
|
|
39
|
+
| `apiKey` | None | Optional bearer token for inventory requests. |
|
|
40
|
+
| `providerID` | `local` | Unique provider ID and model prefix (`<providerID>/<model-id>`). |
|
|
41
|
+
| `providerName` | `Local` for `local`; otherwise the `providerID` | Display name for a new provider. An existing name is preserved unless explicitly overridden. |
|
|
42
|
+
| `includeModels` | All discoverable chat models | Optional list of exact model IDs to discover for this provider. |
|
|
43
|
+
| `refreshMs` | `60000` (60 seconds) | Wait after a discovery pass finishes before starting the next one. |
|
|
44
|
+
| `timeoutMs` | `3000` (3 seconds) | Timeout per discovery HTTP request, including requests to enrich metadata. |
|
|
45
|
+
| `providers` | None | Optional array of provider configurations; available only at the top level of `options`. |
|
|
45
46
|
|
|
46
47
|
The endpoint should return OpenAI-compatible model records from `GET <baseURL>/models`. Temporary discovery failures
|
|
47
48
|
keep the last successfully published inventory. Tool calling defaults to enabled when the inventory does not specify
|
|
48
49
|
support; an endpoint can set `capabilities.tools: false` on a model to disable it.
|
|
49
50
|
|
|
51
|
+
Use `includeModels` to limit which models from a shared endpoint appear in OpenCode. IDs are case-sensitive and
|
|
52
|
+
match the `id` returned by `/models`, without an added provider prefix. An empty list discovers no models and leaves
|
|
53
|
+
manually configured models alone. The filter applies on startup and on every refresh.
|
|
54
|
+
|
|
50
55
|
Both `refreshMs` and `timeoutMs` must be integers in milliseconds from `1` to `2147483647`. The first discovery pass
|
|
51
56
|
runs immediately.
|
|
52
57
|
|
|
53
58
|
For multiple endpoints, configure one plugin entry with a `providers` array. Use a unique `providerID` for each
|
|
54
|
-
endpoint. If you also keep the top-level `baseURL`, it configures one additional provider. The top-level
|
|
55
|
-
options apply only to that provider; entries in `providers` use their own values or the defaults.
|
|
59
|
+
endpoint. If you also keep the top-level `baseURL`, it configures one additional provider. The top-level filter and
|
|
60
|
+
timing options apply only to that provider; entries in `providers` use their own values or the defaults.
|
|
56
61
|
|
|
57
62
|
```jsonc
|
|
58
63
|
{
|
|
@@ -71,6 +76,7 @@ options apply only to that provider; entries in `providers` use their own values
|
|
|
71
76
|
"providerName": "Team models",
|
|
72
77
|
"baseURL": "https://llm.example.com/v1",
|
|
73
78
|
"apiKey": "{env:TEAM_LLM_API_KEY}",
|
|
79
|
+
"includeModels": ["team/general-chat", "team/coding"],
|
|
74
80
|
"refreshMs": 120000,
|
|
75
81
|
"timeoutMs": 10000
|
|
76
82
|
}
|
|
@@ -106,20 +112,17 @@ Commits](https://www.conventionalcommits.org/) for commit messages and PR titles
|
|
|
106
112
|
Use `feat`, `fix`, `perf`, or `revert` for changes to the published plugin; these trigger a patch release. CI-only
|
|
107
113
|
(`ci`), documentation (`docs`), test-only (`test`), and maintenance (`chore`) changes do not bump the version.
|
|
108
114
|
If several merges land before a release runs, semantic-release can publish them together from the latest `main` commit.
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
115
|
+
Semantic-release creates the version tag, publishes via npm Trusted Publishing, and creates the GitHub release.
|
|
116
|
+
Tests and the smoke check run on the PR. Semantic-release updates the package version for publishing without committing
|
|
117
|
+
a version bump. Update dependencies manually when needed; `bun audit` checks the Bun lockfile, including transitive
|
|
118
|
+
dependencies.
|
|
113
119
|
|
|
114
120
|
### One-time setup
|
|
115
121
|
|
|
116
122
|
1. Protect `main` with a required PR and the `Validate package` status check from GitHub Actions. Require branches to be
|
|
117
|
-
up to date before merging and disallow bypasses.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
builds the `npm-package` artifact. Download and unpack it, then publish the tarball once with an authenticated npm
|
|
121
|
-
account and 2FA: `npm publish ./opencode-openai-compatible-discovery-0.1.0.tgz --access public`. Create the GitHub
|
|
122
|
-
release `v0.1.0` on the exact commit used by that workflow run to establish the starting version.
|
|
123
|
+
up to date before merging and disallow bypasses.
|
|
124
|
+
2. The Release workflow records the already-published npm version `0.1.0` in GitHub. It verifies the tarball's integrity
|
|
125
|
+
and creates the `v0.1.0` tag and GitHub release on the original commit. It does not publish that version again.
|
|
123
126
|
3. Use the GitHub environment `npm`, restricted to `main` and without required reviewers. In the npm package's
|
|
124
127
|
[Trusted Publishing settings](https://docs.npmjs.com/trusted-publishers/), authorize this repository's `release.yml`
|
|
125
128
|
workflow and the `npm` environment, with permission for `npm publish`. Set `NPM_RELEASES_ENABLED=true` once ready,
|
package/discovery.ts
CHANGED
|
@@ -16,6 +16,7 @@ export interface DiscoverModelsOptions {
|
|
|
16
16
|
signal: AbortSignal
|
|
17
17
|
timeoutMs: number
|
|
18
18
|
providerID: Provider.ID
|
|
19
|
+
includeModels?: ReadonlySet<string>
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
async function loadJSON(url: string, apiKey: string, signal: AbortSignal, timeoutMs: number): Promise<JSONResult> {
|
|
@@ -47,6 +48,7 @@ export async function discoverModels({
|
|
|
47
48
|
signal,
|
|
48
49
|
timeoutMs,
|
|
49
50
|
providerID,
|
|
51
|
+
includeModels,
|
|
50
52
|
}: DiscoverModelsOptions): Promise<DiscoverySnapshot> {
|
|
51
53
|
const fetchJSON = (url: string) => loadJSON(url, apiKey, signal, timeoutMs)
|
|
52
54
|
const inventory = await fetchJSON(`${baseURL}/models`)
|
|
@@ -67,8 +69,6 @@ export async function discoverModels({
|
|
|
67
69
|
return { available: false, reason: "aborted" }
|
|
68
70
|
}
|
|
69
71
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
models: normalizeInventory(entries, enrichment, providerID, adapter),
|
|
73
|
-
}
|
|
72
|
+
const models = normalizeInventory(entries, enrichment, providerID, adapter)
|
|
73
|
+
return { available: true, models: includeModels ? models.filter(({ id }) => includeModels.has(id)) : models }
|
|
74
74
|
}
|
package/index.ts
CHANGED
|
@@ -20,7 +20,7 @@ function readDuration(value: unknown, fallback: number, option: string, provider
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
function readProvider(options: Record<string, unknown>, baseURL: string) {
|
|
23
|
-
const { providerID = DEFAULT_PROVIDER_ID, providerName, apiKey } = options
|
|
23
|
+
const { providerID = DEFAULT_PROVIDER_ID, providerName, apiKey, includeModels } = options
|
|
24
24
|
if (typeof providerID !== "string" || !/^[\w.-]+$/.test(providerID.trim())) {
|
|
25
25
|
throw new Error("providerID must contain only letters, digits, underscores, hyphens, or dots")
|
|
26
26
|
}
|
|
@@ -28,6 +28,12 @@ function readProvider(options: Record<string, unknown>, baseURL: string) {
|
|
|
28
28
|
throw new Error("providerName must be a non-empty string")
|
|
29
29
|
}
|
|
30
30
|
const id = Provider.ID.make(providerID.trim())
|
|
31
|
+
if (
|
|
32
|
+
includeModels !== undefined &&
|
|
33
|
+
(!Array.isArray(includeModels) || includeModels.some((modelID) => typeof modelID !== "string" || !modelID.trim()))
|
|
34
|
+
) {
|
|
35
|
+
throw new Error(`includeModels for provider ${id} must be an array of non-empty model IDs`)
|
|
36
|
+
}
|
|
31
37
|
return {
|
|
32
38
|
providerID: id,
|
|
33
39
|
providerName: providerName?.trim(),
|
|
@@ -35,6 +41,7 @@ function readProvider(options: Record<string, unknown>, baseURL: string) {
|
|
|
35
41
|
apiKey: typeof apiKey === "string" ? apiKey.trim() : "",
|
|
36
42
|
refreshMs: readDuration(options.refreshMs, DEFAULT_REFRESH_MS, "refreshMs", id),
|
|
37
43
|
timeoutMs: readDuration(options.timeoutMs, DEFAULT_TIMEOUT_MS, "timeoutMs", id),
|
|
44
|
+
includeModels: includeModels === undefined ? undefined : new Set<string>(includeModels),
|
|
38
45
|
}
|
|
39
46
|
}
|
|
40
47
|
|
|
@@ -61,8 +68,8 @@ export default Plugin.define({
|
|
|
61
68
|
const controller = new AbortController()
|
|
62
69
|
const { signal } = controller
|
|
63
70
|
const sources = await Promise.all(
|
|
64
|
-
providers.map(async ({ providerID, providerName, baseURL, apiKey, refreshMs, timeoutMs }) => {
|
|
65
|
-
const load = () => discoverModels({ baseURL, apiKey, signal, timeoutMs, providerID })
|
|
71
|
+
providers.map(async ({ providerID, providerName, baseURL, apiKey, refreshMs, timeoutMs, includeModels }) => {
|
|
72
|
+
const load = () => discoverModels({ baseURL, apiKey, signal, timeoutMs, providerID, includeModels })
|
|
66
73
|
return {
|
|
67
74
|
providerID,
|
|
68
75
|
providerName,
|
package/package.json
CHANGED