@mcowger/pi-plexus 1.14.1 → 1.14.2
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 +8 -7
- package/dist/extension.js +52 -63
- package/package.json +1 -1
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
|
|
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
|
|
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
|
-
|
|
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 |
|
|
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
|
-
|
|
243
|
+
Environment overrides authenticate requests independently of saved login credentials:
|
|
244
244
|
|
|
245
|
-
- Pi
|
|
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
|
|
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",
|
|
@@ -396,8 +421,7 @@ var getConfigDir = () => join2(getAgentDir2(), "extensions", "plexus");
|
|
|
396
421
|
var getConfigPath = () => join2(getConfigDir(), "config.json");
|
|
397
422
|
var ENV_BASE_URL = "PLEXUS_BASE_URL";
|
|
398
423
|
var ENV_API_URL = "PLEXUS_API_URL";
|
|
399
|
-
var
|
|
400
|
-
var ENV_VAR_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
424
|
+
var ENV_VAR_NAME_RE2 = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
401
425
|
var ENV_VAR_NAME_PREFIX_RE = /^[A-Za-z_][A-Za-z0-9_]*/;
|
|
402
426
|
var normalizeRoot = (raw) => raw.trim().replace(/\/+$/, "");
|
|
403
427
|
function resolveConfigTemplate(value) {
|
|
@@ -424,7 +448,7 @@ function resolveConfigTemplate(value) {
|
|
|
424
448
|
continue;
|
|
425
449
|
}
|
|
426
450
|
const name = value.slice(dollarIndex + 2, endIndex);
|
|
427
|
-
if (!
|
|
451
|
+
if (!ENV_VAR_NAME_RE2.test(name)) {
|
|
428
452
|
result += value.slice(dollarIndex, endIndex + 1);
|
|
429
453
|
index = endIndex + 1;
|
|
430
454
|
continue;
|
|
@@ -499,49 +523,15 @@ function getBaseUrlResolution() {
|
|
|
499
523
|
const saved = resolveStringOption(config.baseUrl);
|
|
500
524
|
return { baseUrl: saved ?? null, source: saved ? "saved" : "none" };
|
|
501
525
|
}
|
|
502
|
-
function
|
|
503
|
-
|
|
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;
|
|
526
|
+
function resolveApiKeyEnvSetting2() {
|
|
527
|
+
return resolveApiKeyEnvSetting(getConfigSync().apiKeyEnv);
|
|
514
528
|
}
|
|
515
|
-
function
|
|
516
|
-
return
|
|
517
|
-
}
|
|
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]);
|
|
529
|
+
function getApiKeyEnvSetting() {
|
|
530
|
+
return resolveApiKeyEnvSetting2();
|
|
536
531
|
}
|
|
537
532
|
function resolveApiKey(storedKey) {
|
|
538
|
-
const
|
|
539
|
-
|
|
540
|
-
return explicit;
|
|
541
|
-
return storedKey || getEnvApiKey() || undefined;
|
|
542
|
-
}
|
|
543
|
-
function getEnvApiKey() {
|
|
544
|
-
return resolveStringOption(process.env[ENV_API_KEY]) ?? null;
|
|
533
|
+
const setting = resolveApiKeyEnvSetting2();
|
|
534
|
+
return resolvePlexusApiKey(setting, process.env[setting.name], storedKey);
|
|
545
535
|
}
|
|
546
536
|
function getModelsUrl() {
|
|
547
537
|
const { baseUrl } = getBaseUrlResolution();
|
|
@@ -7273,7 +7263,7 @@ function getSessionThinkingLevel(pi) {
|
|
|
7273
7263
|
return;
|
|
7274
7264
|
}
|
|
7275
7265
|
}
|
|
7276
|
-
function withAuthoritativeApiKeyEnv(provider,
|
|
7266
|
+
function withAuthoritativeApiKeyEnv(provider, setting, getHeaderModels = () => []) {
|
|
7277
7267
|
const apiKey = provider.auth.apiKey;
|
|
7278
7268
|
if (!apiKey)
|
|
7279
7269
|
return provider;
|
|
@@ -7297,18 +7287,19 @@ function withAuthoritativeApiKeyEnv(provider, envName, getHeaderModels = () => [
|
|
|
7297
7287
|
apiKey: {
|
|
7298
7288
|
...apiKey,
|
|
7299
7289
|
resolve: async (input) => {
|
|
7300
|
-
const
|
|
7301
|
-
|
|
7290
|
+
const envValue = await input.ctx.env(setting.name);
|
|
7291
|
+
const envKey = resolveApiKeyEnvValue(setting, envValue);
|
|
7292
|
+
if (envKey === undefined)
|
|
7302
7293
|
return apiKey.resolve(input);
|
|
7303
7294
|
const result = await apiKey.resolve({
|
|
7304
7295
|
...input,
|
|
7305
7296
|
credential: {
|
|
7306
7297
|
type: "api_key",
|
|
7307
|
-
key:
|
|
7298
|
+
key: envKey,
|
|
7308
7299
|
...input.credential?.env ? { env: input.credential.env } : {}
|
|
7309
7300
|
}
|
|
7310
7301
|
});
|
|
7311
|
-
return result ? { ...result, source: `${
|
|
7302
|
+
return result ? { ...result, source: `${setting.name} (apiKeyEnv)` } : result;
|
|
7312
7303
|
}
|
|
7313
7304
|
}
|
|
7314
7305
|
},
|
|
@@ -7387,10 +7378,9 @@ function plexusExtension(pi) {
|
|
|
7387
7378
|
if (state.policy === policy)
|
|
7388
7379
|
state.policy = undefined;
|
|
7389
7380
|
});
|
|
7390
|
-
const
|
|
7391
|
-
const
|
|
7392
|
-
const
|
|
7393
|
-
const envApiKey = explicitApiKey ?? getEnvApiKey();
|
|
7381
|
+
const apiKeySetting = getApiKeyEnvSetting();
|
|
7382
|
+
const apiKeyEnvName = apiKeySetting.name;
|
|
7383
|
+
const envApiKey = resolveApiKeyEnvValue(apiKeySetting, process.env[apiKeyEnvName]);
|
|
7394
7384
|
const startupBaseUrl = getBaseUrl();
|
|
7395
7385
|
const suppressPatterns = getSuppressedModels();
|
|
7396
7386
|
const storedCatalog = readStoredModelsSync();
|
|
@@ -7432,20 +7422,17 @@ function plexusExtension(pi) {
|
|
|
7432
7422
|
refreshModels: (context) => refreshPlexusModels(state, context),
|
|
7433
7423
|
oauth: createPlexusLoginProvider()
|
|
7434
7424
|
});
|
|
7435
|
-
if (
|
|
7425
|
+
if (envApiKey !== undefined) {
|
|
7436
7426
|
let authOverrideApplied = false;
|
|
7437
7427
|
pi.on("session_start", (_event, ctx) => {
|
|
7438
7428
|
if (authOverrideApplied)
|
|
7439
7429
|
return;
|
|
7440
7430
|
const composed = ctx.modelRegistry.getProvider(PROVIDER_NAME);
|
|
7441
7431
|
if (!composed?.auth.apiKey) {
|
|
7442
|
-
throw new Error("Plexus
|
|
7432
|
+
throw new Error("Plexus API-key auth is unavailable");
|
|
7443
7433
|
}
|
|
7444
|
-
pi.registerProvider(withAuthoritativeApiKeyEnv(composed,
|
|
7434
|
+
pi.registerProvider(withAuthoritativeApiKeyEnv(composed, apiKeySetting, () => state.models));
|
|
7445
7435
|
authOverrideApplied = true;
|
|
7446
|
-
log("auth: applied authoritative apiKeyEnv override", {
|
|
7447
|
-
apiKeyEnv: apiKeyEnvName
|
|
7448
|
-
});
|
|
7449
7436
|
});
|
|
7450
7437
|
}
|
|
7451
7438
|
pi.registerCommand("plexus", {
|
|
@@ -7478,7 +7465,8 @@ function plexusExtension(pi) {
|
|
|
7478
7465
|
async function refreshPlexusModels(state, context) {
|
|
7479
7466
|
const baseUrl = getBaseUrl();
|
|
7480
7467
|
const modelsUrl = getModelsUrl();
|
|
7481
|
-
const
|
|
7468
|
+
const setting = getApiKeyEnvSetting();
|
|
7469
|
+
const apiKey = resolvePlexusApiKey(setting, process.env[setting.name], credentialApiKey(context.credential));
|
|
7482
7470
|
const suppress = getSuppressedModels();
|
|
7483
7471
|
if (!context.allowNetwork || !apiKey || !modelsUrl || !baseUrl) {
|
|
7484
7472
|
if (state.models.length > 0) {
|
|
@@ -7633,8 +7621,9 @@ function createPlexusLoginProvider() {
|
|
|
7633
7621
|
return { ...credentials, expires: PLEXUS_CREDENTIAL_EXPIRES_AT };
|
|
7634
7622
|
},
|
|
7635
7623
|
getApiKey(credentials) {
|
|
7624
|
+
const setting = getApiKeyEnvSetting();
|
|
7636
7625
|
const stored = String(credentials.access || credentials.refresh || "");
|
|
7637
|
-
return
|
|
7626
|
+
return resolvePlexusApiKey(setting, process.env[setting.name], stored) ?? "";
|
|
7638
7627
|
},
|
|
7639
7628
|
modifyModels(models, credentials) {
|
|
7640
7629
|
const baseUrl = credentials.plexusBaseUrl;
|
|
@@ -7675,14 +7664,14 @@ async function handleRefresh(state, ctx) {
|
|
|
7675
7664
|
}
|
|
7676
7665
|
async function handleStatus(state, ctx) {
|
|
7677
7666
|
const baseUrl = getBaseUrlResolution();
|
|
7678
|
-
const apiKeyEnvName =
|
|
7667
|
+
const apiKeyEnvName = getApiKeyEnvSetting().name;
|
|
7679
7668
|
const apiKey = await ctx.modelRegistry.getApiKeyForProvider(PROVIDER_NAME).catch(() => {
|
|
7680
7669
|
return;
|
|
7681
7670
|
});
|
|
7682
|
-
const
|
|
7671
|
+
const effectiveApiKey = resolveApiKey(apiKey);
|
|
7683
7672
|
ctx.ui.notify([
|
|
7684
7673
|
`Plexus base URL: ${baseUrl.baseUrl ?? "not configured"} (${baseUrl.source})`,
|
|
7685
|
-
`API key: ${
|
|
7674
|
+
`API key: ${effectiveApiKey ? `${apiKeyEnvName} or host credential` : "not configured"}`,
|
|
7686
7675
|
`Catalog: ${state.models.length} models (${state.catalogSource})`,
|
|
7687
7676
|
"Default model: managed by Pi. Use /model and save the selection there."
|
|
7688
7677
|
].join(`
|