@mcowger/opencode-plexus 1.4.9 → 1.4.11

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 (3) hide show
  1. package/README.md +21 -0
  2. package/dist/index.js +24 -8
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -186,6 +186,26 @@ The plugins normalize either form to the Plexus root URL for storage and derive
186
186
 
187
187
  OpenCode stores the API key in its native auth store and stores the Plexus base URL as auth metadata on that connection. Existing `provider.plexus.options.plexusBaseURL` config is still honored as a fallback.
188
188
 
189
+ `provider.plexus.options.baseURL` is also accepted as input-only compatibility config. Some external clients read OpenCode config files directly and only recognize `options.baseURL`. The plugin normalizes that value for Plexus discovery and then removes it from OpenCode's in-memory provider options, so individual models keep their own `/v1` or `/v1beta` endpoints instead of being overridden by a provider-wide URL.
190
+
191
+ For an OpenChamber-compatible OpenCode config, omit `options.apiKey` and authenticate through `/connect`:
192
+
193
+ ```json
194
+ {
195
+ "provider": {
196
+ "plexus": {
197
+ "options": {
198
+ "baseURL": "https://plexus.example.com/v1"
199
+ }
200
+ }
201
+ }
202
+ }
203
+ ```
204
+
205
+ Then run `/connect`, select **Plexus**, and authenticate against the same Plexus server. A raw unresolved `options.apiKey` value in this file can override the resolved runtime credential used by OpenChamber, including OpenCode `{env:NAME}` templates that OpenChamber does not expand when extra characters follow the template.
206
+
207
+ The plugin publishes models with `/v1` endpoints before `/v1beta` models. This ordering helps OpenChamber versions that derive a provider-wide endpoint from the first runtime model; it does not change model endpoints or OpenCode routing. Gemini models still use `/v1beta` through `@ai-sdk/google`.
208
+
189
209
  The OpenCode plugin respects each model's `preferred_api` value and routes models through the matching SDK/API shape:
190
210
 
191
211
  - `chat_completions` / `openai-completions` → OpenAI-compatible chat completions
@@ -350,6 +370,7 @@ Models with a falsy `id` are skipped. Missing metadata falls back to safe defaul
350
370
  - **OpenCode** seeds the provider from the on-disk cache (or a placeholder model) once, during config loading — OpenCode's `provider.models` hook never fires for custom providers, so there is no live discovery at startup. Run `/plexus-refresh` to force a live fetch and rewrite the cache; because OpenCode has no way to hot-reload a custom provider's model list mid-session, a restart is required afterward to see the refreshed models in the picker.
351
371
  - OpenCode models retain their upstream model ID, SDK dialect, release date, and reasoning metadata so OpenCode can generate its native GPT, Claude, Gemini, and OpenAI-compatible variants and apply its current request transforms. DeepSeek models also preserve `reasoning_content` across tool-call turns.
352
372
  - OpenCode uses a 250K-token context window when Plexus supplies no context metadata; its output fallback remains 20% of that window.
373
+ - OpenCode moves `/v1beta` models after `/v1` models in published model order. Model endpoints and per-model SDK selection are unchanged.
353
374
  - Both adapters convert Plexus's per-token base and tier rates to the per-million-token units expected by their host.
354
375
 
355
376
  ## Development
package/dist/index.js CHANGED
@@ -71,7 +71,7 @@ function matchesPattern(id, name, shortId, pattern) {
71
71
  }
72
72
  // ../plexus-models/src/convert.ts
73
73
  var REASONING_PARAMS = new Set(["reasoning", "include_reasoning", "reasoning_effort"]);
74
- var NON_CHAT_PATTERN = /(?:^|[\W_])(?:embed(?:ding|dings)?|transcri(?:be[ds]?|ptions?)|whisper|speech[\W_]*to[\W_]*text|stt|text[\W_]*to[\W_]*speech|tts|image[\W_]*(?:gen(?:eration)?|\d+)|diffusion|dall[\W_]*e|stable[\W_]*diffusion|sdxl|dream)(?:$|[\W_])/i;
74
+ var NON_CHAT_PATTERN = /(?:^|[\W_])(?:embed(?:ding|dings)?|transcri(?:be[ds]?|ptions?)|whisper|speech[\W_]*to[\W_]*text|stt|text[\W_]*to[\W_]*speech|tts|image(?:[\W_]*(?:gen(?:eration)?|\d+))?|diffusion|dall[\W_]*e|stable[\W_]*diffusion|sdxl|dream)(?:$|[\W_])/i;
75
75
  var API_DIALECT_MAP = {
76
76
  chat_completions: "openai-completions",
77
77
  "openai-completions": "openai-completions",
@@ -112,15 +112,17 @@ function isChatModel(model) {
112
112
  return false;
113
113
  }
114
114
  const outputModalities = model.architecture?.output_modalities;
115
- if (outputModalities !== undefined && !outputModalities.includes("text"))
115
+ if (outputModalities !== undefined && (outputModalities.length === 0 || outputModalities.some((m) => m !== "text"))) {
116
116
  return false;
117
+ }
117
118
  const modality = model.architecture?.modality;
118
119
  if (modality?.includes("->")) {
119
120
  const input = modality.split("->")[0] ?? "";
120
121
  if (!input.toLowerCase().includes("text"))
121
122
  return false;
122
123
  const output = modality.split("->").at(-1) ?? "";
123
- if (!output.toLowerCase().includes("text"))
124
+ const outputTokens = output.toLowerCase().split(/[+,]/).map((t) => t.trim()).filter((t) => t.length > 0);
125
+ if (outputTokens.length === 0 || outputTokens.some((t) => t !== "text"))
124
126
  return false;
125
127
  }
126
128
  const apiHints = Array.isArray(model.preferred_api) ? model.preferred_api.join(" ") : model.preferred_api ?? "";
@@ -470,6 +472,19 @@ function buildOutputModalities(model) {
470
472
  }
471
473
  return ["text"];
472
474
  }
475
+ function orderModelsByApiBase(models) {
476
+ const current = [];
477
+ const beta = [];
478
+ for (const entry of Object.entries(models)) {
479
+ const api = (entry[1].provider?.api ?? entry[1].api?.url ?? "").trim().replace(/\/+$/, "");
480
+ if (api.endsWith("/v1beta")) {
481
+ beta.push(entry);
482
+ } else {
483
+ current.push(entry);
484
+ }
485
+ }
486
+ return Object.fromEntries([...current, ...beta]);
487
+ }
473
488
  function buildModels(models, baseURL, suppress) {
474
489
  const result = {};
475
490
  for (const m of models) {
@@ -527,7 +542,7 @@ function buildModels(models, baseURL, suppress) {
527
542
  };
528
543
  result[m.id] = entry;
529
544
  }
530
- return result;
545
+ return orderModelsByApiBase(result);
531
546
  }
532
547
 
533
548
  // src/plugin.ts
@@ -597,13 +612,13 @@ function toRuntimeModels(models, provider) {
597
612
  ...model.variants ? { variants: model.variants } : {}
598
613
  };
599
614
  }
600
- return result;
615
+ return orderModelsByApiBase(result);
601
616
  }
602
617
  function toConfigModels(models) {
603
- return Object.fromEntries(Object.entries(models).map(([id, model]) => {
618
+ return orderModelsByApiBase(Object.fromEntries(Object.entries(models).map(([id, model]) => {
604
619
  const { pricingTiers: _pricingTiers, ...configModel } = model;
605
620
  return [id, configModel];
606
- }));
621
+ })));
607
622
  }
608
623
  function authMetadata(auth) {
609
624
  return auth?.type === "api" ? auth.metadata : undefined;
@@ -664,7 +679,7 @@ var PlexusProviderPlugin = async (ctx) => {
664
679
  const { baseURL, apiKey } = resolveConfig(existing);
665
680
  log.info(`Resolved plexus config: baseURL=${baseURL ?? "(missing)"} apiKey=${apiKey ? "present" : "missing"}`);
666
681
  if (typeof existingOptions["baseURL"] === "string") {
667
- log.warn(`Ignoring legacy provider.options.baseURL=${String(existingOptions["baseURL"])}`);
682
+ log.info(`Using provider.options.baseURL=${String(existingOptions["baseURL"])} as input-only OpenChamber compatibility config`);
668
683
  }
669
684
  const cachedAsync = await readCachedModels(client, suppress);
670
685
  if (cachedAsync) {
@@ -842,5 +857,6 @@ export {
842
857
  REFRESH_TTL_MS,
843
858
  buildModels,
844
859
  src_default as default,
860
+ orderModelsByApiBase,
845
861
  toRuntimeModels
846
862
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcowger/opencode-plexus",
3
- "version": "1.4.9",
3
+ "version": "1.4.11",
4
4
  "description": "OpenCode plugin: Plexus provider with dynamic model discovery",
5
5
  "type": "module",
6
6
  "module": "./dist/index.js",