@mcowger/opencode-plexus 1.4.8 → 1.4.10

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 +21 -7
  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
@@ -470,6 +470,19 @@ function buildOutputModalities(model) {
470
470
  }
471
471
  return ["text"];
472
472
  }
473
+ function orderModelsByApiBase(models) {
474
+ const current = [];
475
+ const beta = [];
476
+ for (const entry of Object.entries(models)) {
477
+ const api = (entry[1].provider?.api ?? entry[1].api?.url ?? "").trim().replace(/\/+$/, "");
478
+ if (api.endsWith("/v1beta")) {
479
+ beta.push(entry);
480
+ } else {
481
+ current.push(entry);
482
+ }
483
+ }
484
+ return Object.fromEntries([...current, ...beta]);
485
+ }
473
486
  function buildModels(models, baseURL, suppress) {
474
487
  const result = {};
475
488
  for (const m of models) {
@@ -527,7 +540,7 @@ function buildModels(models, baseURL, suppress) {
527
540
  };
528
541
  result[m.id] = entry;
529
542
  }
530
- return result;
543
+ return orderModelsByApiBase(result);
531
544
  }
532
545
 
533
546
  // src/plugin.ts
@@ -597,13 +610,13 @@ function toRuntimeModels(models, provider) {
597
610
  ...model.variants ? { variants: model.variants } : {}
598
611
  };
599
612
  }
600
- return result;
613
+ return orderModelsByApiBase(result);
601
614
  }
602
615
  function toConfigModels(models) {
603
- return Object.fromEntries(Object.entries(models).map(([id, model]) => {
616
+ return orderModelsByApiBase(Object.fromEntries(Object.entries(models).map(([id, model]) => {
604
617
  const { pricingTiers: _pricingTiers, ...configModel } = model;
605
618
  return [id, configModel];
606
- }));
619
+ })));
607
620
  }
608
621
  function authMetadata(auth) {
609
622
  return auth?.type === "api" ? auth.metadata : undefined;
@@ -664,7 +677,7 @@ var PlexusProviderPlugin = async (ctx) => {
664
677
  const { baseURL, apiKey } = resolveConfig(existing);
665
678
  log.info(`Resolved plexus config: baseURL=${baseURL ?? "(missing)"} apiKey=${apiKey ? "present" : "missing"}`);
666
679
  if (typeof existingOptions["baseURL"] === "string") {
667
- log.warn(`Ignoring legacy provider.options.baseURL=${String(existingOptions["baseURL"])}`);
680
+ log.info(`Using provider.options.baseURL=${String(existingOptions["baseURL"])} as input-only OpenChamber compatibility config`);
668
681
  }
669
682
  const cachedAsync = await readCachedModels(client, suppress);
670
683
  if (cachedAsync) {
@@ -721,8 +734,8 @@ var PlexusProviderPlugin = async (ctx) => {
721
734
  const key = authKey ?? apiKey;
722
735
  if (!baseURL) {
723
736
  log.info("Provider hook skipped live refresh; baseURL missing");
724
- const cached2 = await readCachedModels(client, suppress);
725
- return cached2 ? toRuntimeModels(cached2.models, provider) : {};
737
+ const cached = await readCachedModels(client, suppress);
738
+ return cached ? toRuntimeModels(cached.models, provider) : {};
726
739
  }
727
740
  const refreshPromise = refreshModels(client, baseURL, log, key, false, suppress);
728
741
  const race = await raceWithTimeout(refreshPromise, CONFIG_HOOK_REFRESH_BUDGET_MS);
@@ -842,5 +855,6 @@ export {
842
855
  REFRESH_TTL_MS,
843
856
  buildModels,
844
857
  src_default as default,
858
+ orderModelsByApiBase,
845
859
  toRuntimeModels
846
860
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcowger/opencode-plexus",
3
- "version": "1.4.8",
3
+ "version": "1.4.10",
4
4
  "description": "OpenCode plugin: Plexus provider with dynamic model discovery",
5
5
  "type": "module",
6
6
  "module": "./dist/index.js",