@mcowger/pi-plexus 1.14.1 → 1.14.3

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.
package/README.md CHANGED
@@ -173,16 +173,16 @@ Pi and OMP store only non-secret Plexus settings in their own `config.json`:
173
173
 
174
174
  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.
175
175
 
176
- With `apiKeyEnv` omitted, Pi resolves configuration as follows:
176
+ With `apiKeyEnv` omitted, Pi and OMP resolve configuration as follows:
177
177
 
178
178
  ```text
179
179
  base URL: PLEXUS_API_URL → PLEXUS_BASE_URL → saved Plexus base URL
180
- API key: host credential store → PLEXUS_API_KEY process fallback
180
+ API key: PLEXUS_API_KEY → host credential store
181
181
  catalog: host model store → live Plexus refresh
182
182
  startup model: host model-picker preference
183
183
  ```
184
184
 
185
- 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.
185
+ Pi and OMP share credential selection in `plexus-models`: environment keys override saved credentials for discovery and every inference API, including Messages, Responses, and Chat Completions. OpenCode uses `PLEXUS_API_KEY` before the saved `/connect` credential and plugin `apiKey` option.
186
186
 
187
187
  `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.
188
188
 
@@ -232,7 +232,7 @@ Credential precedence:
232
232
 
233
233
  | Client | `apiKeyEnv` omitted | `apiKeyEnv` explicitly set |
234
234
  | ----------- | ------------------------------------------------------------------------------- | --------------------------------------------------------------------------------- |
235
- | Pi | Saved host credential, then `PLEXUS_API_KEY` fallback | Only the named environment variable, ahead of saved credentials |
235
+ | Pi | `PLEXUS_API_KEY`, then saved host credential | Only the named environment variable, ahead of saved credentials |
236
236
  | OMP | Registered `PLEXUS_API_KEY` env override, then host credentials | Only the named environment variable, ahead of saved credentials |
237
237
  | 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` |
238
238
 
@@ -240,12 +240,13 @@ An explicit setting is authoritative even when it names `PLEXUS_API_KEY`. If the
240
240
 
241
241
  ### Native login with `apiKeyEnv`
242
242
 
243
- `apiKeyEnv` changes which key authenticates requests, not the native login UI:
243
+ Environment overrides authenticate requests independently of saved login credentials:
244
244
 
245
- - Pi and OMP: `/login plexus` still prompts for the base URL and API key, and saves both through the normal configuration and credential stores.
245
+ - Pi: `/login plexus` still prompts for the base URL and API key and saves both normally.
246
+ - OMP: `/login plexus` is registered only when no environment key override is active. Otherwise OMP would treat the env key as a fallback behind saved credentials. Configure the URL through `config.json` or a URL environment override instead.
246
247
  - OpenCode V2: `/connect` still stores the Plexus base URL and API key normally.
247
248
 
248
- 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.
249
+ With an explicit `apiKeyEnv`, discovery and model requests use the named environment variable rather than a saved login key. Entering a different key during login won't override the environment setting.
249
250
 
250
251
  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.
251
252
 
package/dist/extension.js CHANGED
@@ -1,4 +1,29 @@
1
1
  // @bun
2
+ // ../plexus-models/src/auth.ts
3
+ var DEFAULT_API_KEY_ENV = "PLEXUS_API_KEY";
4
+ var ENV_VAR_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
5
+ function resolveApiKeyEnvSetting(raw) {
6
+ if (raw === undefined || raw === null)
7
+ return { name: DEFAULT_API_KEY_ENV, explicit: false };
8
+ const name = typeof raw === "string" ? raw.trim() : "";
9
+ if (!ENV_VAR_NAME_RE.test(name)) {
10
+ throw new Error("Invalid apiKeyEnv: expected an environment variable name");
11
+ }
12
+ return { name, explicit: true };
13
+ }
14
+ function resolveApiKeyEnvValue(setting, raw) {
15
+ const value = raw?.trim();
16
+ if (!value && setting.explicit) {
17
+ throw new Error(`apiKeyEnv environment variable "${setting.name}" is missing or empty`);
18
+ }
19
+ return value || undefined;
20
+ }
21
+ function resolvePlexusApiKey(setting, envValue, storedKey) {
22
+ const envKey = resolveApiKeyEnvValue(setting, envValue);
23
+ if (envKey !== undefined)
24
+ return envKey;
25
+ return storedKey || undefined;
26
+ }
2
27
  // ../plexus-models/src/convert.ts
3
28
  var REASONING_PARAMS = new Set([
4
29
  "reasoning",
@@ -124,6 +149,12 @@ function convertToDescriptor(raw, baseUrl) {
124
149
  descriptor.piModel = raw.pi_model;
125
150
  if (raw.pi_options && Object.keys(raw.pi_options).length > 0)
126
151
  descriptor.piOptions = raw.pi_options;
152
+ const effortOption = raw.reasoning_options?.find((option) => option.type === "effort");
153
+ if (effortOption !== undefined) {
154
+ const values = effortOption.values.filter((value) => typeof value === "string" && value.length > 0);
155
+ if (values.length > 0)
156
+ descriptor.effortValues = values;
157
+ }
127
158
  return descriptor;
128
159
  }
129
160
  function isChatModel(model) {
@@ -396,8 +427,7 @@ var getConfigDir = () => join2(getAgentDir2(), "extensions", "plexus");
396
427
  var getConfigPath = () => join2(getConfigDir(), "config.json");
397
428
  var ENV_BASE_URL = "PLEXUS_BASE_URL";
398
429
  var ENV_API_URL = "PLEXUS_API_URL";
399
- var ENV_API_KEY = "PLEXUS_API_KEY";
400
- var ENV_VAR_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
430
+ var ENV_VAR_NAME_RE2 = /^[A-Za-z_][A-Za-z0-9_]*$/;
401
431
  var ENV_VAR_NAME_PREFIX_RE = /^[A-Za-z_][A-Za-z0-9_]*/;
402
432
  var normalizeRoot = (raw) => raw.trim().replace(/\/+$/, "");
403
433
  function resolveConfigTemplate(value) {
@@ -424,7 +454,7 @@ function resolveConfigTemplate(value) {
424
454
  continue;
425
455
  }
426
456
  const name = value.slice(dollarIndex + 2, endIndex);
427
- if (!ENV_VAR_NAME_RE.test(name)) {
457
+ if (!ENV_VAR_NAME_RE2.test(name)) {
428
458
  result += value.slice(dollarIndex, endIndex + 1);
429
459
  index = endIndex + 1;
430
460
  continue;
@@ -499,49 +529,15 @@ function getBaseUrlResolution() {
499
529
  const saved = resolveStringOption(config.baseUrl);
500
530
  return { baseUrl: saved ?? null, source: saved ? "saved" : "none" };
501
531
  }
502
- function resolveApiKeyEnvSetting() {
503
- const raw = getConfigSync().apiKeyEnv;
504
- if (raw === undefined || raw === null)
505
- return { name: ENV_API_KEY, explicit: false };
506
- const name = typeof raw === "string" ? raw.trim() : "";
507
- if (!ENV_VAR_NAME_RE.test(name)) {
508
- throw new Error("Invalid apiKeyEnv: expected an environment variable name");
509
- }
510
- return { name, explicit: true };
511
- }
512
- function getApiKeyEnvName() {
513
- return resolveApiKeyEnvSetting().name;
514
- }
515
- function isApiKeyEnvExplicit() {
516
- return resolveApiKeyEnvSetting().explicit;
532
+ function resolveApiKeyEnvSetting2() {
533
+ return resolveApiKeyEnvSetting(getConfigSync().apiKeyEnv);
517
534
  }
518
- function requireApiKeyEnvValue(name, raw) {
519
- const value = raw?.trim();
520
- if (!value) {
521
- throw new Error(`apiKeyEnv environment variable "${name}" is missing or empty`);
522
- }
523
- return value;
524
- }
525
- async function resolveExplicitApiKeyFromEnv(readEnv) {
526
- const { name, explicit } = resolveApiKeyEnvSetting();
527
- if (!explicit)
528
- return;
529
- return requireApiKeyEnvValue(name, await readEnv(name));
530
- }
531
- function resolveExplicitApiKey() {
532
- const { name, explicit } = resolveApiKeyEnvSetting();
533
- if (!explicit)
534
- return;
535
- return requireApiKeyEnvValue(name, process.env[name]);
535
+ function getApiKeyEnvSetting() {
536
+ return resolveApiKeyEnvSetting2();
536
537
  }
537
538
  function resolveApiKey(storedKey) {
538
- const explicit = resolveExplicitApiKey();
539
- if (explicit)
540
- return explicit;
541
- return storedKey || getEnvApiKey() || undefined;
542
- }
543
- function getEnvApiKey() {
544
- return resolveStringOption(process.env[ENV_API_KEY]) ?? null;
539
+ const setting = resolveApiKeyEnvSetting2();
540
+ return resolvePlexusApiKey(setting, process.env[setting.name], storedKey);
545
541
  }
546
542
  function getModelsUrl() {
547
543
  const { baseUrl } = getBaseUrlResolution();
@@ -644,6 +640,30 @@ import {
644
640
  getModel
645
641
  } from "@earendil-works/pi-ai/compat";
646
642
  var MINIMUM_OUTPUT_TOKENS = 8192;
643
+ var SERVER_EFFORT_LEVELS = [
644
+ "minimal",
645
+ "low",
646
+ "medium",
647
+ "high",
648
+ "xhigh",
649
+ "max"
650
+ ];
651
+ function serverThinkingLevelMap(descriptor) {
652
+ if (!descriptor.reasoning)
653
+ return;
654
+ if (descriptor.preferredApi !== "openai-completions" && descriptor.preferredApi !== "openai-responses") {
655
+ return;
656
+ }
657
+ const values = descriptor.effortValues;
658
+ if (values === undefined)
659
+ return;
660
+ const map = {};
661
+ for (const level of SERVER_EFFORT_LEVELS) {
662
+ if (values.includes(level))
663
+ map[level] = level;
664
+ }
665
+ return Object.keys(map).length > 0 ? map : undefined;
666
+ }
647
667
  function descriptorToPiModel(descriptor) {
648
668
  let builtinModel;
649
669
  if (descriptor.piProvider && descriptor.piModel) {
@@ -683,6 +703,7 @@ function descriptorToPiModel(descriptor) {
683
703
  } else if (builtinModel?.compat) {
684
704
  compat = builtinModel.compat;
685
705
  }
706
+ const serverThinkingLevelMapValue = serverThinkingLevelMap(descriptor);
686
707
  return {
687
708
  id: descriptor.id,
688
709
  name: descriptor.name,
@@ -695,7 +716,7 @@ function descriptorToPiModel(descriptor) {
695
716
  cost,
696
717
  contextWindow: descriptor.contextWindow,
697
718
  maxTokens: Math.max(descriptor.maxTokens, MINIMUM_OUTPUT_TOKENS),
698
- ...builtinModel?.thinkingLevelMap !== undefined ? { thinkingLevelMap: builtinModel.thinkingLevelMap } : {},
719
+ ...serverThinkingLevelMapValue !== undefined ? { thinkingLevelMap: serverThinkingLevelMapValue } : builtinModel?.thinkingLevelMap !== undefined ? { thinkingLevelMap: builtinModel.thinkingLevelMap } : {},
699
720
  ...builtinModel?.headers !== undefined ? { headers: builtinModel.headers } : {},
700
721
  ...compat !== undefined ? { compat } : {}
701
722
  };
@@ -7273,7 +7294,7 @@ function getSessionThinkingLevel(pi) {
7273
7294
  return;
7274
7295
  }
7275
7296
  }
7276
- function withAuthoritativeApiKeyEnv(provider, envName, getHeaderModels = () => []) {
7297
+ function withAuthoritativeApiKeyEnv(provider, setting, getHeaderModels = () => []) {
7277
7298
  const apiKey = provider.auth.apiKey;
7278
7299
  if (!apiKey)
7279
7300
  return provider;
@@ -7297,18 +7318,19 @@ function withAuthoritativeApiKeyEnv(provider, envName, getHeaderModels = () => [
7297
7318
  apiKey: {
7298
7319
  ...apiKey,
7299
7320
  resolve: async (input) => {
7300
- const explicit = await resolveExplicitApiKeyFromEnv((name) => input.ctx.env(name));
7301
- if (explicit === undefined)
7321
+ const envValue = await input.ctx.env(setting.name);
7322
+ const envKey = resolveApiKeyEnvValue(setting, envValue);
7323
+ if (envKey === undefined)
7302
7324
  return apiKey.resolve(input);
7303
7325
  const result = await apiKey.resolve({
7304
7326
  ...input,
7305
7327
  credential: {
7306
7328
  type: "api_key",
7307
- key: explicit,
7329
+ key: envKey,
7308
7330
  ...input.credential?.env ? { env: input.credential.env } : {}
7309
7331
  }
7310
7332
  });
7311
- return result ? { ...result, source: `${envName} (apiKeyEnv)` } : result;
7333
+ return result ? { ...result, source: `${setting.name} (apiKeyEnv)` } : result;
7312
7334
  }
7313
7335
  }
7314
7336
  },
@@ -7387,10 +7409,9 @@ function plexusExtension(pi) {
7387
7409
  if (state.policy === policy)
7388
7410
  state.policy = undefined;
7389
7411
  });
7390
- const apiKeyEnvExplicit = isApiKeyEnvExplicit();
7391
- const explicitApiKey = apiKeyEnvExplicit ? resolveExplicitApiKey() : undefined;
7392
- const apiKeyEnvName = getApiKeyEnvName();
7393
- const envApiKey = explicitApiKey ?? getEnvApiKey();
7412
+ const apiKeySetting = getApiKeyEnvSetting();
7413
+ const apiKeyEnvName = apiKeySetting.name;
7414
+ const envApiKey = resolveApiKeyEnvValue(apiKeySetting, process.env[apiKeyEnvName]);
7394
7415
  const startupBaseUrl = getBaseUrl();
7395
7416
  const suppressPatterns = getSuppressedModels();
7396
7417
  const storedCatalog = readStoredModelsSync();
@@ -7432,20 +7453,17 @@ function plexusExtension(pi) {
7432
7453
  refreshModels: (context) => refreshPlexusModels(state, context),
7433
7454
  oauth: createPlexusLoginProvider()
7434
7455
  });
7435
- if (apiKeyEnvExplicit) {
7456
+ if (envApiKey !== undefined) {
7436
7457
  let authOverrideApplied = false;
7437
7458
  pi.on("session_start", (_event, ctx) => {
7438
7459
  if (authOverrideApplied)
7439
7460
  return;
7440
7461
  const composed = ctx.modelRegistry.getProvider(PROVIDER_NAME);
7441
7462
  if (!composed?.auth.apiKey) {
7442
- throw new Error("Plexus apiKeyEnv override failed: provider API-key auth is unavailable");
7463
+ throw new Error("Plexus API-key auth is unavailable");
7443
7464
  }
7444
- pi.registerProvider(withAuthoritativeApiKeyEnv(composed, apiKeyEnvName, () => state.models));
7465
+ pi.registerProvider(withAuthoritativeApiKeyEnv(composed, apiKeySetting, () => state.models));
7445
7466
  authOverrideApplied = true;
7446
- log("auth: applied authoritative apiKeyEnv override", {
7447
- apiKeyEnv: apiKeyEnvName
7448
- });
7449
7467
  });
7450
7468
  }
7451
7469
  pi.registerCommand("plexus", {
@@ -7478,7 +7496,8 @@ function plexusExtension(pi) {
7478
7496
  async function refreshPlexusModels(state, context) {
7479
7497
  const baseUrl = getBaseUrl();
7480
7498
  const modelsUrl = getModelsUrl();
7481
- const apiKey = resolveApiKey(credentialApiKey(context.credential));
7499
+ const setting = getApiKeyEnvSetting();
7500
+ const apiKey = resolvePlexusApiKey(setting, process.env[setting.name], credentialApiKey(context.credential));
7482
7501
  const suppress = getSuppressedModels();
7483
7502
  if (!context.allowNetwork || !apiKey || !modelsUrl || !baseUrl) {
7484
7503
  if (state.models.length > 0) {
@@ -7633,8 +7652,9 @@ function createPlexusLoginProvider() {
7633
7652
  return { ...credentials, expires: PLEXUS_CREDENTIAL_EXPIRES_AT };
7634
7653
  },
7635
7654
  getApiKey(credentials) {
7655
+ const setting = getApiKeyEnvSetting();
7636
7656
  const stored = String(credentials.access || credentials.refresh || "");
7637
- return resolveExplicitApiKey() ?? stored;
7657
+ return resolvePlexusApiKey(setting, process.env[setting.name], stored) ?? "";
7638
7658
  },
7639
7659
  modifyModels(models, credentials) {
7640
7660
  const baseUrl = credentials.plexusBaseUrl;
@@ -7675,14 +7695,14 @@ async function handleRefresh(state, ctx) {
7675
7695
  }
7676
7696
  async function handleStatus(state, ctx) {
7677
7697
  const baseUrl = getBaseUrlResolution();
7678
- const apiKeyEnvName = getApiKeyEnvName();
7698
+ const apiKeyEnvName = getApiKeyEnvSetting().name;
7679
7699
  const apiKey = await ctx.modelRegistry.getApiKeyForProvider(PROVIDER_NAME).catch(() => {
7680
7700
  return;
7681
7701
  });
7682
- const explicitApiKey = apiKey ? resolveExplicitApiKey() : undefined;
7702
+ const effectiveApiKey = resolveApiKey(apiKey);
7683
7703
  ctx.ui.notify([
7684
7704
  `Plexus base URL: ${baseUrl.baseUrl ?? "not configured"} (${baseUrl.source})`,
7685
- `API key: ${apiKey ? explicitApiKey !== undefined ? `${apiKeyEnvName} (apiKeyEnv)` : getEnvApiKey() ? `host credential or ${apiKeyEnvName} fallback` : "host credential" : "not configured"}`,
7705
+ `API key: ${effectiveApiKey ? `${apiKeyEnvName} or host credential` : "not configured"}`,
7686
7706
  `Catalog: ${state.models.length} models (${state.catalogSource})`,
7687
7707
  "Default model: managed by Pi. Use /model and save the selection there."
7688
7708
  ].join(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcowger/pi-plexus",
3
- "version": "1.14.1",
3
+ "version": "1.14.3",
4
4
  "description": "Plexus AI proxy plugin for the pi coding agent",
5
5
  "type": "module",
6
6
  "files": [