@vymalo/opencode-models-info 0.1.0 → 0.4.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.
Files changed (2) hide show
  1. package/README.md +35 -7
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -24,30 +24,32 @@ Add it to your `opencode.json` plugin list:
24
24
 
25
25
  ## Usage
26
26
 
27
- For every provider you want enriched, add `options.meta.modelsInfoUrl`:
27
+ `meta.modelsInfoUrl` is **the HTTP(S) endpoint that returns the metadata JSON** — an absolute URL or a path resolved against `options.baseURL`. Point it at your own provider's metadata endpoint:
28
28
 
29
29
  ```json
30
30
  {
31
31
  "plugin": ["@vymalo/opencode-models-info"],
32
32
  "provider": {
33
- "my-gateway": {
33
+ "my-provider": {
34
34
  "npm": "@ai-sdk/openai-compatible",
35
35
  "options": {
36
- "baseURL": "https://gateway.example.com/v1",
36
+ "baseURL": "https://api.example.com/v1",
37
37
  "meta": {
38
- "modelsInfoUrl": "models/info",
38
+ "modelsInfoUrl": "https://api.example.com/v1/models",
39
39
  "modelsInfoTtlSeconds": 86400,
40
40
  "modelsInfoTimeoutMs": 5000
41
41
  }
42
42
  },
43
- "models": {
44
- "gpt-x-large": {}
45
- }
43
+ "models": { "my-model-large": {} }
46
44
  }
47
45
  }
48
46
  }
49
47
  ```
50
48
 
49
+ An absolute URL is clearest. A relative path is also accepted — it resolves against `baseURL` (e.g. `"models"` → `https://api.example.com/v1/models`); see [URL resolution](#url-resolution).
50
+
51
+ > **What shape must that endpoint return?** The JSON described in [Expected response shape](#expected-response-shape-openrouter) below — commonly called the **OpenRouter shape** because OpenRouter's `/models` endpoint returns it, but the plugin has no dependency on OpenRouter and never contacts it. The compatibility bar is low: a **bare top-level array** (no `data` wrapper) is accepted, and the mapping is **partial**, so your endpoint only needs to emit the fields you want enriched (e.g. just `id` + `context_length` + `pricing`). **But note:** a vanilla OpenAI-compatible `/v1/models` returns only `id` / `object` / `owned_by` — *none* of the fields this plugin maps — so pointing `modelsInfoUrl` there fetches successfully and enriches nothing. The endpoint has to actually carry the richer data.
52
+
51
53
  That's it. After OpenCode starts:
52
54
 
53
55
  1. The hook picks up every provider with a `meta.modelsInfoUrl`.
@@ -87,6 +89,32 @@ The plugin sends the union of `options.headers` and `meta.modelsInfoHeaders` (me
87
89
 
88
90
  If you need a different token for the metadata endpoint than for inference (e.g. a service-account bearer), set it explicitly under `meta.modelsInfoHeaders.Authorization` — it'll override whatever the provider has set.
89
91
 
92
+ #### Example: with `@vymalo/opencode-oauth2`
93
+
94
+ List the oauth2 plugin **first** so its `config` hook runs before this one — that's what puts the bearer on `options.headers` in time for the metadata fetch:
95
+
96
+ ```jsonc
97
+ {
98
+ "plugin": ["@vymalo/opencode-oauth2", "@vymalo/opencode-models-info"],
99
+ "provider": {
100
+ "my-provider": {
101
+ "npm": "@ai-sdk/openai-compatible",
102
+ "options": {
103
+ "baseURL": "https://api.example.com/v1",
104
+ "oauth2": {
105
+ "issuer": "https://auth.example.com",
106
+ "clientId": "opencode-client",
107
+ "scopes": ["openid", "profile", "offline_access"]
108
+ },
109
+ "meta": { "modelsInfoUrl": "https://api.example.com/v1/models" }
110
+ }
111
+ }
112
+ }
113
+ }
114
+ ```
115
+
116
+ oauth2 authenticates the provider and discovers its models; this plugin then fetches `modelsInfoUrl` using the token oauth2 stamped onto the provider headers, and enriches those discovered models. No `models` block and no `Authorization` header to manage — both are handled for you.
117
+
90
118
  ### Expected response shape (OpenRouter)
91
119
 
92
120
  ```json
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vymalo/opencode-models-info",
3
- "version": "0.1.0",
3
+ "version": "0.4.0",
4
4
  "description": "OpenCode plugin that enriches model entries with full metadata (context length, pricing, modalities, capability flags) fetched from a provider-supplied OpenRouter-shaped endpoint.",
5
5
  "license": "MIT",
6
6
  "author": "vymalo contributors",