@mcowger/opencode-plexus 1.9.0 → 1.10.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 -5
  2. package/dist/index.js +43 -3
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -176,21 +176,21 @@ To force a model refresh:
176
176
  /plexus-refresh
177
177
  ```
178
178
 
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).
179
+ `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
180
 
181
181
  ## Configuration files
182
182
 
183
183
  ### Connection state
184
184
 
185
- Each adapter stores only non-secret Plexus settings in its own `config.json`:
185
+ Pi and OMP store only non-secret Plexus settings in their own `config.json`:
186
186
 
187
187
  ```text
188
- <agent-dir>/extensions/plexus/config.json # base URL and optional model suppression
188
+ <agent-dir>/extensions/plexus/config.json # base URL, apiKeyEnv, model suppression
189
189
  ```
190
190
 
191
191
  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
192
 
193
- At runtime, configuration resolves as follows:
193
+ With `apiKeyEnv` omitted, Pi resolves configuration as follows:
194
194
 
195
195
  ```text
196
196
  base URL: PLEXUS_API_URL → PLEXUS_BASE_URL → saved Plexus base URL
@@ -199,10 +199,73 @@ catalog: host model store → live Plexus refresh
199
199
  startup model: host model-picker preference
200
200
  ```
201
201
 
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.
202
+ 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.
203
+
204
+ `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
205
 
204
206
  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
207
 
208
+ ### Separate API-key environment variables
209
+
210
+ 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.
211
+
212
+ For Pi, edit `~/.pi/agent/extensions/plexus/config.json` (or `<agent-dir>/extensions/plexus/config.json` when using a custom agent directory):
213
+
214
+ ```json
215
+ {
216
+ "baseUrl": "https://plexus.example.com",
217
+ "apiKeyEnv": "AIHOME_PI_API_KEY"
218
+ }
219
+ ```
220
+
221
+ For OMP, edit `~/.omp/agent/extensions/plexus/config.json` (under the active profile's agent directory when using profiles):
222
+
223
+ ```json
224
+ {
225
+ "baseUrl": "https://plexus.example.com",
226
+ "apiKeyEnv": "AIHOME_OMP_API_KEY"
227
+ }
228
+ ```
229
+
230
+ For OpenCode V2, put `apiKeyEnv` in the plugin's `options` in `~/.config/opencode/opencode.jsonc` (or your project `opencode.jsonc`):
231
+
232
+ ```jsonc
233
+ {
234
+ "plugins": [
235
+ {
236
+ "package": "@mcowger/opencode-plexus",
237
+ "options": {
238
+ "plexusBaseURL": "https://plexus.example.com",
239
+ "apiKeyEnv": "AIHOME_OPENCODE_API_KEY"
240
+ }
241
+ }
242
+ ]
243
+ }
244
+ ```
245
+
246
+ 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.
247
+
248
+ Credential precedence:
249
+
250
+ | Client | `apiKeyEnv` omitted | `apiKeyEnv` explicitly set |
251
+ |---|---|---|
252
+ | Pi | Saved host credential, then `PLEXUS_API_KEY` fallback | Only the named environment variable, ahead of saved credentials |
253
+ | OMP | Registered `PLEXUS_API_KEY` env override, then host credentials | Only the named environment variable, ahead of saved credentials |
254
+ | 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` |
255
+
256
+ 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.
257
+
258
+ ### Native login with `apiKeyEnv`
259
+
260
+ `apiKeyEnv` changes which key authenticates requests, not the native login UI:
261
+
262
+ - Pi and OMP: `/login plexus` still prompts for the base URL and API key, and saves both through the normal configuration and credential stores.
263
+ - OpenCode V2: `/connect` still stores the Plexus base URL and API key normally.
264
+
265
+ 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.
266
+
267
+ 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.
268
+
206
269
  ---
207
270
 
208
271
  ## 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.10.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",