@mcowger/opencode-plexus 1.9.0 → 1.11.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 (3) hide show
  1. package/README.md +68 -18
  2. package/dist/index.js +43 -3
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -139,19 +139,6 @@ Inspect the effective URL, authentication availability, and catalog source witho
139
139
  /plexus status
140
140
  ```
141
141
 
142
- Choose the per-session service tier for eligible Plexus models:
143
-
144
- ```
145
- /service-tier fast
146
- ```
147
-
148
- Tiers are `default` (aliases `off`, `none`), `fast` (alias `priority`), `flex`, and `ultrafast`; `/service-tier status` reports the active tier and whether the current model supports it. The tier is applied per API:
149
-
150
- - **OpenAI Responses** models get a `service_tier` field. `priority` covers OpenAI's Fast-mode set (GPT-5 and newer, GPT-4.1+, GPT-4o, and o3/o4-mini); `flex` and `ultrafast` are limited to their documented models.
151
- - **Anthropic Messages** models use Claude Fast mode (`speed: "fast"` plus the `anthropic-beta: fast-mode-2026-02-01` flag) for `priority`, on `claude-opus-5` and `claude-opus-4-8`; `flex` and `ultrafast` are unsupported. This is a first-party research-preview feature, so it only works when the upstream allows it.
152
-
153
- The tier resets to `default` on every session start. `/plexus-service-tier` is an alias for the same command.
154
-
155
142
  Select a Plexus model in `/model`. Save its startup default with the host's normal model-picker action; Plexus does not maintain a separate default-model setting.
156
143
 
157
144
  Use `/login plexus` for setup and `/logout plexus` to remove stored credentials.
@@ -176,21 +163,21 @@ To force a model refresh:
176
163
  /plexus-refresh
177
164
  ```
178
165
 
179
- `PLEXUS_API_URL` / `PLEXUS_BASE_URL` / `PLEXUS_API_KEY` env vars and plugin options (`plexusBaseURL`, `suppressModels`) are also honored. Until a URL is configured, the provider shows a single `plexus-unconfigured` placeholder. Plugin logs are written to `~/.local/share/opencode/plugins/plexus/plugin.log` (the OpenCode service discards plugin stdout).
166
+ `PLEXUS_API_URL` / `PLEXUS_BASE_URL` / `PLEXUS_API_KEY` env vars and plugin options (`plexusBaseURL`, `apiKey`, `apiKeyEnv`, `suppressModels`) are also honored. Until a URL is configured, the provider shows a single `plexus-unconfigured` placeholder. Plugin logs are written to `~/.local/share/opencode/plugins/plexus/plugin.log` (the OpenCode service discards plugin stdout).
180
167
 
181
168
  ## Configuration files
182
169
 
183
170
  ### Connection state
184
171
 
185
- Each adapter stores only non-secret Plexus settings in its own `config.json`:
172
+ Pi and OMP store only non-secret Plexus settings in their own `config.json`:
186
173
 
187
174
  ```text
188
- <agent-dir>/extensions/plexus/config.json # base URL and optional model suppression
175
+ <agent-dir>/extensions/plexus/config.json # base URL, apiKeyEnv, model suppression
189
176
  ```
190
177
 
191
178
  Credentials stay in the host credential store (`auth.json` for Pi, `agent.db` for OMP). Model catalogs stay in the host model registry/store. The extension no longer writes a second model cache, ETag file, raw API response, or default-model preference.
192
179
 
193
- At runtime, configuration resolves as follows:
180
+ With `apiKeyEnv` omitted, Pi resolves configuration as follows:
194
181
 
195
182
  ```text
196
183
  base URL: PLEXUS_API_URL → PLEXUS_BASE_URL → saved Plexus base URL
@@ -199,10 +186,73 @@ catalog: host model store → live Plexus refresh
199
186
  startup model: host model-picker preference
200
187
  ```
201
188
 
202
- `PLEXUS_API_URL` and `PLEXUS_BASE_URL` are process-only URL overrides; `PLEXUS_API_KEY` is a process-only credential fallback. None are persisted. `/plexus status` reports the effective URL source, whether auth is available, and catalog state without exposing credentials.
189
+ OMP uses the same URL precedence, but its registered `PLEXUS_API_KEY` environment reference is a native config-key override, ahead of saved credentials. If that variable isn't set, OMP uses its host credential resolver. OpenCode uses `PLEXUS_API_KEY` before the saved `/connect` credential and plugin `apiKey` option.
190
+
191
+ `PLEXUS_API_URL` and `PLEXUS_BASE_URL` are process-only URL overrides; environment API keys aren't persisted. `/plexus status` reports the effective URL source, whether auth is available, and catalog state without exposing credentials.
203
192
 
204
193
  Plexus accepts a root URL or a `/v1` API URL. The adapter normalizes that only for the Plexus discovery request. Each model then receives its own API-specific base URL: OpenAI stays on `/v1`, Anthropic uses the root, and Google uses `/v1beta`.
205
194
 
195
+ ### Separate API-key environment variables
196
+
197
+ Set `apiKeyEnv` to the **name** of an environment variable, not its value or a `$VAR` template. The default is `PLEXUS_API_KEY`; no client-specific name is built in.
198
+
199
+ For Pi, edit `~/.pi/agent/extensions/plexus/config.json` (or `<agent-dir>/extensions/plexus/config.json` when using a custom agent directory):
200
+
201
+ ```json
202
+ {
203
+ "baseUrl": "https://plexus.example.com",
204
+ "apiKeyEnv": "AIHOME_PI_API_KEY"
205
+ }
206
+ ```
207
+
208
+ For OMP, edit `~/.omp/agent/extensions/plexus/config.json` (under the active profile's agent directory when using profiles):
209
+
210
+ ```json
211
+ {
212
+ "baseUrl": "https://plexus.example.com",
213
+ "apiKeyEnv": "AIHOME_OMP_API_KEY"
214
+ }
215
+ ```
216
+
217
+ For OpenCode V2, put `apiKeyEnv` in the plugin's `options` in `~/.config/opencode/opencode.jsonc` (or your project `opencode.jsonc`):
218
+
219
+ ```jsonc
220
+ {
221
+ "plugins": [
222
+ {
223
+ "package": "@mcowger/opencode-plexus",
224
+ "options": {
225
+ "plexusBaseURL": "https://plexus.example.com",
226
+ "apiKeyEnv": "AIHOME_OPENCODE_API_KEY"
227
+ }
228
+ }
229
+ ]
230
+ }
231
+ ```
232
+
233
+ Set the named variable in the process environment that launches the client. Restart Pi/OMP after editing their config; restart the OpenCode service after editing plugin options or changing its environment.
234
+
235
+ Credential precedence:
236
+
237
+ | Client | `apiKeyEnv` omitted | `apiKeyEnv` explicitly set |
238
+ |---|---|---|
239
+ | Pi | Saved host credential, then `PLEXUS_API_KEY` fallback | Only the named environment variable, ahead of saved credentials |
240
+ | OMP | Registered `PLEXUS_API_KEY` env override, then host credentials | Only the named environment variable, ahead of saved credentials |
241
+ | OpenCode V2 | `PLEXUS_API_KEY`, then saved `/connect` credential, then plugin `apiKey` option | Only the named environment variable, ahead of both saved credentials and `apiKey` |
242
+
243
+ An explicit setting is authoritative even when it names `PLEXUS_API_KEY`. If the selected variable is missing, empty, or whitespace-only, the plugin reports an error naming the variable without showing its value. It does not fall back to a saved key, OpenCode's `apiKey` option, or the shared `PLEXUS_API_KEY`. Saved credentials remain stored; remove `apiKeyEnv` to restore the default precedence.
244
+
245
+ ### Native login with `apiKeyEnv`
246
+
247
+ `apiKeyEnv` changes which key authenticates requests, not the native login UI:
248
+
249
+ - Pi and OMP: `/login plexus` still prompts for the base URL and API key, and saves both through the normal configuration and credential stores.
250
+ - OpenCode V2: `/connect` still stores the Plexus base URL and API key normally.
251
+
252
+ With an explicit `apiKeyEnv`, discovery and model requests use the named environment variable rather than the key entered during login. OMP's immediate post-login refresh also uses the environment key. Login remains useful for configuring the base URL, but entering a different key won't override the environment setting.
253
+
254
+ If the named variable is missing or empty at startup, the plugin fails to load. Native login cannot repair that setting: set the variable in the launching process environment or remove `apiKeyEnv`, then restart. Removing the setting restores the default precedence above without deleting saved credentials.
255
+
206
256
  ---
207
257
 
208
258
  ## Model suppression
package/dist/index.js CHANGED
@@ -162,6 +162,7 @@ var ANTHROPIC_PKG = "aisdk:@ai-sdk/anthropic";
162
162
  var GOOGLE_PKG = "aisdk:@ai-sdk/google";
163
163
  var OPENAI_RESPONSES_PKG = "aisdk:@ai-sdk/openai";
164
164
  var PLEXUS_BASE_URL_OPTION = "plexusBaseURL";
165
+ var PLEXUS_API_KEY_ENV_OPTION = "apiKeyEnv";
165
166
  var ENV_BASE_URL = "PLEXUS_BASE_URL";
166
167
  var ENV_API_URL = "PLEXUS_API_URL";
167
168
  var ENV_API_KEY = "PLEXUS_API_KEY";
@@ -304,6 +305,20 @@ function resolveStringOption(value) {
304
305
  const resolved = resolveConfigTemplate(value)?.trim();
305
306
  return resolved || undefined;
306
307
  }
308
+ function resolveExplicitApiKey(options) {
309
+ const raw = options?.[PLEXUS_API_KEY_ENV_OPTION];
310
+ if (raw === undefined || raw === null)
311
+ return;
312
+ const name = typeof raw === "string" ? raw.trim() : "";
313
+ if (!ENV_VAR_NAME_RE.test(name)) {
314
+ throw new Error(`Invalid ${PLEXUS_API_KEY_ENV_OPTION}: expected an environment variable name`);
315
+ }
316
+ const value = process.env[name]?.trim();
317
+ if (!value) {
318
+ throw new Error(`${PLEXUS_API_KEY_ENV_OPTION} environment variable "${name}" is missing or empty`);
319
+ }
320
+ return value;
321
+ }
307
322
  function metadataBaseURL(credential) {
308
323
  if (!credential)
309
324
  return;
@@ -314,13 +329,14 @@ function metadataBaseURL(credential) {
314
329
  return typeof rawConfig === "string" ? resolveStringOption(rawConfig) : undefined;
315
330
  }
316
331
  function resolveConfig(options, credential) {
332
+ const explicitApiKey = resolveExplicitApiKey(options);
317
333
  const envBaseURL = process.env[ENV_API_URL] ?? process.env[ENV_BASE_URL];
318
334
  const envApiKey = process.env[ENV_API_KEY];
319
335
  const metaBaseURL = credential ? metadataBaseURL(credential) : undefined;
320
336
  const optBaseURL = resolveStringOption(options?.[PLEXUS_BASE_URL_OPTION]);
321
337
  const optApiKey = resolveStringOption(options?.["apiKey"]);
322
338
  const baseURL = (envBaseURL ? rootURL(envBaseURL) : undefined) || (metaBaseURL ? rootURL(metaBaseURL) : undefined) || (optBaseURL ? rootURL(optBaseURL) : undefined) || undefined;
323
- const apiKey = (envApiKey ? envApiKey.trim() : undefined) || credential?.key?.trim() || optApiKey || undefined;
339
+ const apiKey = explicitApiKey || (envApiKey ? envApiKey.trim() : undefined) || credential?.key?.trim() || optApiKey || undefined;
324
340
  return {
325
341
  baseURL: baseURL || undefined,
326
342
  apiKey: apiKey || undefined
@@ -574,6 +590,9 @@ function placeholderModel() {
574
590
  }
575
591
 
576
592
  // src/plugin.ts
593
+ function errorMessage(e) {
594
+ return e instanceof Error ? e.message : String(e);
595
+ }
577
596
  var lastRefresh = null;
578
597
  var inFlightRefresh = null;
579
598
  function toModelInfo(models) {
@@ -692,7 +711,12 @@ var plugin_default = Plugin.define({
692
711
  source.apiKey = next.apiKey;
693
712
  source.connection = next.connection;
694
713
  };
695
- await reloadSource(false);
714
+ try {
715
+ await reloadSource(false);
716
+ } catch (e) {
717
+ log.error(`Plexus setup failed: ${errorMessage(e)}`);
718
+ throw e;
719
+ }
696
720
  const providerID = Provider.ID.make(PLEXUS_PROVIDER_ID);
697
721
  await ctx.provider.transform((editor) => {
698
722
  const existing = editor.get(providerID);
@@ -751,7 +775,20 @@ var plugin_default = Plugin.define({
751
775
  description: "Refresh Plexus models from the live server",
752
776
  execute: async ({ sessionID, delivery }) => {
753
777
  lastRefresh = null;
754
- await reloadSource(true);
778
+ try {
779
+ await reloadSource(true);
780
+ } catch (e) {
781
+ const text = `Plexus refresh failed: ${errorMessage(e)}. Existing state left untouched.`;
782
+ log.error(text);
783
+ await ctx.session.synthetic({
784
+ sessionID,
785
+ text,
786
+ description: text,
787
+ delivery,
788
+ resume: false
789
+ });
790
+ return;
791
+ }
755
792
  await ctx.provider.reload();
756
793
  const count = source.models.length;
757
794
  const placeholderOnly = count === 1 && source.models[0]?.id === PLACEHOLDER_MODEL_ID;
@@ -806,6 +843,7 @@ export {
806
843
  OPENAI_COMPATIBLE_PKG,
807
844
  OPENAI_RESPONSES_PKG,
808
845
  PLACEHOLDER_MODEL_ID,
846
+ PLEXUS_API_KEY_ENV_OPTION,
809
847
  PLEXUS_BASE_URL_OPTION,
810
848
  PLEXUS_INTEGRATION_ID,
811
849
  PLEXUS_PLUGIN_ID,
@@ -823,9 +861,11 @@ export {
823
861
  modelsUrl,
824
862
  orderModelsByApiBase,
825
863
  placeholderModel,
864
+ providerInfo,
826
865
  readCachedModels,
827
866
  resolveConfig,
828
867
  resolveConfigTemplate,
868
+ resolveExplicitApiKey,
829
869
  rootURL,
830
870
  trimURL,
831
871
  writeCache
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcowger/opencode-plexus",
3
- "version": "1.9.0",
3
+ "version": "1.11.0",
4
4
  "description": "Plexus AI proxy plugin for OpenCode V2 with dynamic model discovery",
5
5
  "type": "module",
6
6
  "module": "./dist/index.js",