@mcowger/pi-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.
- package/README.md +68 -18
- package/dist/extension.js +122 -173
- 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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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/extension.js
CHANGED
|
@@ -462,6 +462,47 @@ function getBaseUrlResolution() {
|
|
|
462
462
|
const saved = resolveStringOption(config.baseUrl);
|
|
463
463
|
return { baseUrl: saved ?? null, source: saved ? "saved" : "none" };
|
|
464
464
|
}
|
|
465
|
+
function resolveApiKeyEnvSetting() {
|
|
466
|
+
const raw = getConfigSync().apiKeyEnv;
|
|
467
|
+
if (raw === undefined || raw === null)
|
|
468
|
+
return { name: ENV_API_KEY, explicit: false };
|
|
469
|
+
const name = typeof raw === "string" ? raw.trim() : "";
|
|
470
|
+
if (!ENV_VAR_NAME_RE.test(name)) {
|
|
471
|
+
throw new Error("Invalid apiKeyEnv: expected an environment variable name");
|
|
472
|
+
}
|
|
473
|
+
return { name, explicit: true };
|
|
474
|
+
}
|
|
475
|
+
function getApiKeyEnvName() {
|
|
476
|
+
return resolveApiKeyEnvSetting().name;
|
|
477
|
+
}
|
|
478
|
+
function isApiKeyEnvExplicit() {
|
|
479
|
+
return resolveApiKeyEnvSetting().explicit;
|
|
480
|
+
}
|
|
481
|
+
function requireApiKeyEnvValue(name, raw) {
|
|
482
|
+
const value = raw?.trim();
|
|
483
|
+
if (!value) {
|
|
484
|
+
throw new Error(`apiKeyEnv environment variable "${name}" is missing or empty`);
|
|
485
|
+
}
|
|
486
|
+
return value;
|
|
487
|
+
}
|
|
488
|
+
async function resolveExplicitApiKeyFromEnv(readEnv) {
|
|
489
|
+
const { name, explicit } = resolveApiKeyEnvSetting();
|
|
490
|
+
if (!explicit)
|
|
491
|
+
return;
|
|
492
|
+
return requireApiKeyEnvValue(name, await readEnv(name));
|
|
493
|
+
}
|
|
494
|
+
function resolveExplicitApiKey() {
|
|
495
|
+
const { name, explicit } = resolveApiKeyEnvSetting();
|
|
496
|
+
if (!explicit)
|
|
497
|
+
return;
|
|
498
|
+
return requireApiKeyEnvValue(name, process.env[name]);
|
|
499
|
+
}
|
|
500
|
+
function resolveApiKey(storedKey) {
|
|
501
|
+
const explicit = resolveExplicitApiKey();
|
|
502
|
+
if (explicit)
|
|
503
|
+
return explicit;
|
|
504
|
+
return storedKey || getEnvApiKey() || undefined;
|
|
505
|
+
}
|
|
465
506
|
function getEnvApiKey() {
|
|
466
507
|
return resolveStringOption(process.env[ENV_API_KEY]) ?? null;
|
|
467
508
|
}
|
|
@@ -639,126 +680,8 @@ function normalizeMalformedFunctionCall(message, providerName) {
|
|
|
639
680
|
return { message: { ...message, errorMessage: NORMALIZED_MESSAGE } };
|
|
640
681
|
}
|
|
641
682
|
|
|
642
|
-
// src/service-tier.ts
|
|
643
|
-
var TIER_ALIASES = {
|
|
644
|
-
default: "default",
|
|
645
|
-
off: "default",
|
|
646
|
-
none: "default",
|
|
647
|
-
priority: "priority",
|
|
648
|
-
fast: "priority",
|
|
649
|
-
flex: "flex",
|
|
650
|
-
ultrafast: "ultrafast"
|
|
651
|
-
};
|
|
652
|
-
function parseServiceTierArg(input) {
|
|
653
|
-
return TIER_ALIASES[input.trim().toLowerCase()];
|
|
654
|
-
}
|
|
655
|
-
var OPENAI_RESPONSES_APIS = ["openai-responses", "openai-codex-responses"];
|
|
656
|
-
var GPT_VERSION = /^gpt-(\d+)(?:\.(\d+))?(?:-|$)/i;
|
|
657
|
-
var PRIORITY_EXTRA_FAMILIES = [/^gpt-4o(?=$|-)/i, /^o3(?=$|-)/i, /^o4-mini(?=$|-)/i];
|
|
658
|
-
function isPriorityEligible(modelId) {
|
|
659
|
-
const id = modelId.trim();
|
|
660
|
-
const match = GPT_VERSION.exec(id);
|
|
661
|
-
if (match) {
|
|
662
|
-
const major = Number(match[1]);
|
|
663
|
-
const minor = match[2] === undefined ? 0 : Number(match[2]);
|
|
664
|
-
return major >= 5 || major === 4 && minor >= 1;
|
|
665
|
-
}
|
|
666
|
-
return PRIORITY_EXTRA_FAMILIES.some((pattern) => pattern.test(id));
|
|
667
|
-
}
|
|
668
|
-
function isFlexEligible(modelId) {
|
|
669
|
-
const match = GPT_VERSION.exec(modelId.trim());
|
|
670
|
-
if (!match)
|
|
671
|
-
return false;
|
|
672
|
-
const major = Number(match[1]);
|
|
673
|
-
const minor = match[2] === undefined ? 0 : Number(match[2]);
|
|
674
|
-
return major > 5 || major === 5 && minor >= 5;
|
|
675
|
-
}
|
|
676
|
-
var ULTRAFAST_FAMILIES = [/^gpt-6(?:\.\d+)?-astra(?=$|-)/i, /^gpt-5\.6-sol(?=$|-)/i];
|
|
677
|
-
var OPENAI_RESPONSES_DIALECT = {
|
|
678
|
-
id: "openai-responses",
|
|
679
|
-
apis: OPENAI_RESPONSES_APIS,
|
|
680
|
-
tiers: ["priority", "flex", "ultrafast"],
|
|
681
|
-
supportsModel: isPriorityEligible,
|
|
682
|
-
supportsTier(modelId, tier) {
|
|
683
|
-
switch (tier) {
|
|
684
|
-
case "priority":
|
|
685
|
-
return isPriorityEligible(modelId);
|
|
686
|
-
case "flex":
|
|
687
|
-
return isFlexEligible(modelId);
|
|
688
|
-
case "ultrafast":
|
|
689
|
-
return ULTRAFAST_FAMILIES.some((pattern) => pattern.test(modelId));
|
|
690
|
-
}
|
|
691
|
-
},
|
|
692
|
-
inject(payload, _modelId, tier) {
|
|
693
|
-
return { ...payload, service_tier: tier };
|
|
694
|
-
}
|
|
695
|
-
};
|
|
696
|
-
var ANTHROPIC_MESSAGES_APIS = ["anthropic-messages"];
|
|
697
|
-
var ANTHROPIC_FAST_MODE_BETA = "fast-mode-2026-02-01";
|
|
698
|
-
var CLAUDE_FAST_FAMILIES = [/^claude-opus-5(?=$|-)/i, /^claude-opus-4-8(?=$|-)/i];
|
|
699
|
-
var ANTHROPIC_MESSAGES_DIALECT = {
|
|
700
|
-
id: "anthropic-messages",
|
|
701
|
-
apis: ANTHROPIC_MESSAGES_APIS,
|
|
702
|
-
tiers: ["priority"],
|
|
703
|
-
supportsModel(modelId) {
|
|
704
|
-
return /^claude-/i.test(modelId.trim());
|
|
705
|
-
},
|
|
706
|
-
supportsTier(modelId, tier) {
|
|
707
|
-
return tier === "priority" && CLAUDE_FAST_FAMILIES.some((pattern) => pattern.test(modelId.trim()));
|
|
708
|
-
},
|
|
709
|
-
inject(payload, _modelId, _tier) {
|
|
710
|
-
const existing = Array.isArray(payload.betas) ? payload.betas.filter((beta) => typeof beta === "string") : [];
|
|
711
|
-
const betas = existing.includes(ANTHROPIC_FAST_MODE_BETA) ? existing : [...existing, ANTHROPIC_FAST_MODE_BETA];
|
|
712
|
-
return { ...payload, speed: "fast", betas };
|
|
713
|
-
}
|
|
714
|
-
};
|
|
715
|
-
var SERVICE_TIER_DIALECTS = [
|
|
716
|
-
OPENAI_RESPONSES_DIALECT,
|
|
717
|
-
ANTHROPIC_MESSAGES_DIALECT
|
|
718
|
-
];
|
|
719
|
-
function dialectForApi(api, dialects = SERVICE_TIER_DIALECTS) {
|
|
720
|
-
if (!api)
|
|
721
|
-
return;
|
|
722
|
-
return dialects.find((dialect) => dialect.apis.includes(api));
|
|
723
|
-
}
|
|
724
|
-
function isTierSupportedByModel(model, tier, dialects = SERVICE_TIER_DIALECTS) {
|
|
725
|
-
if (tier === "default")
|
|
726
|
-
return true;
|
|
727
|
-
if (!model)
|
|
728
|
-
return false;
|
|
729
|
-
const dialect = dialectForApi(model.api, dialects);
|
|
730
|
-
if (!dialect || !dialect.supportsModel(model.id))
|
|
731
|
-
return false;
|
|
732
|
-
return dialect.supportsTier(model.id, tier);
|
|
733
|
-
}
|
|
734
|
-
function applyServiceTier(payload, model, tier, options) {
|
|
735
|
-
if (tier === "default" || !model || model.provider !== options.provider)
|
|
736
|
-
return payload;
|
|
737
|
-
const dialect = dialectForApi(model.api, options.dialects);
|
|
738
|
-
if (!dialect || !dialect.supportsModel(model.id) || !dialect.supportsTier(model.id, tier)) {
|
|
739
|
-
return payload;
|
|
740
|
-
}
|
|
741
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
742
|
-
return payload;
|
|
743
|
-
return dialect.inject(payload, model.id, tier);
|
|
744
|
-
}
|
|
745
|
-
var SERVICE_TIER_NOTIFICATION_TYPE = "plexus.serviceTier";
|
|
746
|
-
var SERVICE_TIER_COMMAND = "service-tier";
|
|
747
|
-
function buildServiceTierNotification(input) {
|
|
748
|
-
return JSON.stringify({
|
|
749
|
-
type: SERVICE_TIER_NOTIFICATION_TYPE,
|
|
750
|
-
command: SERVICE_TIER_COMMAND,
|
|
751
|
-
success: input.success,
|
|
752
|
-
tier: input.tier,
|
|
753
|
-
supported: input.supported,
|
|
754
|
-
provider: input.provider,
|
|
755
|
-
model: input.model
|
|
756
|
-
});
|
|
757
|
-
}
|
|
758
|
-
|
|
759
683
|
// src/extension.ts
|
|
760
684
|
var PROVIDER_NAME = "plexus";
|
|
761
|
-
var PROVIDER_API_KEY_TEMPLATE = "${PLEXUS_API_KEY}";
|
|
762
685
|
var PLEXUS_CREDENTIAL_EXPIRES_AT = 253402300799000;
|
|
763
686
|
var PLACEHOLDER_BASE_URL = "http://localhost/v1";
|
|
764
687
|
var currentModels = [];
|
|
@@ -788,23 +711,64 @@ function enforceMinimumOutputTokens(payload) {
|
|
|
788
711
|
}
|
|
789
712
|
return changed ? next : payload;
|
|
790
713
|
}
|
|
714
|
+
function withAuthoritativeApiKeyEnv(provider, envName, getHeaderModels = () => currentModels) {
|
|
715
|
+
const apiKey = provider.auth.apiKey;
|
|
716
|
+
if (!apiKey)
|
|
717
|
+
return provider;
|
|
718
|
+
const withModelHeaders = (models) => {
|
|
719
|
+
const headersById = new Map;
|
|
720
|
+
for (const model of getHeaderModels()) {
|
|
721
|
+
if (model.headers)
|
|
722
|
+
headersById.set(model.id, model.headers);
|
|
723
|
+
}
|
|
724
|
+
if (headersById.size === 0)
|
|
725
|
+
return [...models];
|
|
726
|
+
return models.map((model) => {
|
|
727
|
+
const headers = headersById.get(model.id);
|
|
728
|
+
return headers ? { ...model, headers: { ...model.headers, ...headers } } : model;
|
|
729
|
+
});
|
|
730
|
+
};
|
|
731
|
+
return {
|
|
732
|
+
...provider,
|
|
733
|
+
auth: {
|
|
734
|
+
...provider.auth,
|
|
735
|
+
apiKey: {
|
|
736
|
+
...apiKey,
|
|
737
|
+
resolve: async (input) => {
|
|
738
|
+
const explicit = await resolveExplicitApiKeyFromEnv((name) => input.ctx.env(name));
|
|
739
|
+
if (explicit === undefined)
|
|
740
|
+
return apiKey.resolve(input);
|
|
741
|
+
const result = await apiKey.resolve({
|
|
742
|
+
...input,
|
|
743
|
+
credential: {
|
|
744
|
+
type: "api_key",
|
|
745
|
+
key: explicit,
|
|
746
|
+
...input.credential?.env ? { env: input.credential.env } : {}
|
|
747
|
+
}
|
|
748
|
+
});
|
|
749
|
+
return result ? { ...result, source: `${envName} (apiKeyEnv)` } : result;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
},
|
|
753
|
+
getModels: () => withModelHeaders(provider.getModels()),
|
|
754
|
+
getAllModels: () => withModelHeaders(provider.getAllModels?.() ?? provider.getModels())
|
|
755
|
+
};
|
|
756
|
+
}
|
|
791
757
|
function plexusExtension(pi) {
|
|
792
|
-
const
|
|
758
|
+
const apiKeyEnvExplicit = isApiKeyEnvExplicit();
|
|
759
|
+
const explicitApiKey = apiKeyEnvExplicit ? resolveExplicitApiKey() : undefined;
|
|
760
|
+
const apiKeyEnvName = getApiKeyEnvName();
|
|
761
|
+
const envApiKey = explicitApiKey ?? getEnvApiKey();
|
|
793
762
|
const startupBaseUrl = getBaseUrl();
|
|
794
763
|
const suppressPatterns = getSuppressedModels();
|
|
795
764
|
const storedCatalog = readStoredModelsSync();
|
|
796
765
|
const startupModels = (storedCatalog?.models ?? []).filter((model) => !isModelSuppressed({ id: model.id, name: model.name }, suppressPatterns));
|
|
797
766
|
currentModels = startupModels;
|
|
798
767
|
catalogSource = startupModels.length > 0 ? "host store" : "none";
|
|
799
|
-
let activeServiceTier = "default";
|
|
800
|
-
pi.on("session_start", () => {
|
|
801
|
-
activeServiceTier = "default";
|
|
802
|
-
});
|
|
803
768
|
pi.on("before_provider_request", (event, ctx) => {
|
|
804
769
|
if (ctx.model?.provider !== PROVIDER_NAME)
|
|
805
770
|
return;
|
|
806
|
-
const
|
|
807
|
-
const next = enforceMinimumOutputTokens(withTier);
|
|
771
|
+
const next = enforceMinimumOutputTokens(event.payload);
|
|
808
772
|
return next === event.payload ? undefined : next;
|
|
809
773
|
});
|
|
810
774
|
log("startup", {
|
|
@@ -815,13 +779,27 @@ function plexusExtension(pi) {
|
|
|
815
779
|
pi.on("message_end", (event) => normalizeMalformedFunctionCall(event.message, PROVIDER_NAME));
|
|
816
780
|
pi.registerProvider(PROVIDER_NAME, {
|
|
817
781
|
api: "openai-completions",
|
|
818
|
-
...envApiKey ? { apiKey:
|
|
782
|
+
...envApiKey ? { apiKey: `\${${apiKeyEnvName}}` } : {},
|
|
819
783
|
authHeader: true,
|
|
820
784
|
baseUrl: startupBaseUrl ?? PLACEHOLDER_BASE_URL,
|
|
821
785
|
models: startupModels,
|
|
822
786
|
refreshModels: refreshPlexusModels,
|
|
823
787
|
oauth: createPlexusLoginProvider()
|
|
824
788
|
});
|
|
789
|
+
if (apiKeyEnvExplicit) {
|
|
790
|
+
let authOverrideApplied = false;
|
|
791
|
+
pi.on("session_start", (_event, ctx) => {
|
|
792
|
+
if (authOverrideApplied)
|
|
793
|
+
return;
|
|
794
|
+
const composed = ctx.modelRegistry.getProvider(PROVIDER_NAME);
|
|
795
|
+
if (!composed?.auth.apiKey) {
|
|
796
|
+
throw new Error("Plexus apiKeyEnv override failed: provider API-key auth is unavailable");
|
|
797
|
+
}
|
|
798
|
+
pi.registerProvider(withAuthoritativeApiKeyEnv(composed, apiKeyEnvName));
|
|
799
|
+
authOverrideApplied = true;
|
|
800
|
+
log("auth: applied authoritative apiKeyEnv override", { apiKeyEnv: apiKeyEnvName });
|
|
801
|
+
});
|
|
802
|
+
}
|
|
825
803
|
pi.registerCommand("plexus", {
|
|
826
804
|
description: "Plexus provider commands: refresh, status (setup: /login plexus)",
|
|
827
805
|
getArgumentCompletions: (prefix) => {
|
|
@@ -840,52 +818,11 @@ function plexusExtension(pi) {
|
|
|
840
818
|
ctx.ui.notify(`Unknown sub-command: "${args}". Use /login plexus, /plexus refresh, or /plexus status.`, "warning");
|
|
841
819
|
}
|
|
842
820
|
});
|
|
843
|
-
const handleServiceTier = async (args, ctx) => {
|
|
844
|
-
const sub = args.trim().toLowerCase();
|
|
845
|
-
if (sub === "" || sub === "status") {
|
|
846
|
-
notifyServiceTier(ctx, activeServiceTier, true);
|
|
847
|
-
return;
|
|
848
|
-
}
|
|
849
|
-
const tier = parseServiceTierArg(sub);
|
|
850
|
-
if (!tier) {
|
|
851
|
-
notifyServiceTier(ctx, activeServiceTier, false);
|
|
852
|
-
return;
|
|
853
|
-
}
|
|
854
|
-
activeServiceTier = tier;
|
|
855
|
-
notifyServiceTier(ctx, tier, true);
|
|
856
|
-
};
|
|
857
|
-
const serviceTierCommand = {
|
|
858
|
-
description: "Set the per-session Plexus service tier: default, fast, flex, ultrafast, or status",
|
|
859
|
-
getArgumentCompletions: (prefix) => {
|
|
860
|
-
const tiers = [
|
|
861
|
-
{ value: "default", label: "default", description: "Use the provider's default tier" },
|
|
862
|
-
{ value: "fast", label: "fast", description: "Priority tier (alias: priority)" },
|
|
863
|
-
{ value: "flex", label: "flex", description: "Flex tier" },
|
|
864
|
-
{ value: "ultrafast", label: "ultrafast", description: "Ultrafast tier" },
|
|
865
|
-
{ value: "status", label: "status", description: "Show the current service tier" }
|
|
866
|
-
];
|
|
867
|
-
return tiers.filter((tier) => tier.value.startsWith(prefix.trim().toLowerCase()));
|
|
868
|
-
},
|
|
869
|
-
handler: handleServiceTier
|
|
870
|
-
};
|
|
871
|
-
pi.registerCommand("service-tier", serviceTierCommand);
|
|
872
|
-
pi.registerCommand("plexus-service-tier", serviceTierCommand);
|
|
873
|
-
}
|
|
874
|
-
function notifyServiceTier(ctx, tier, success) {
|
|
875
|
-
const model = ctx.model;
|
|
876
|
-
const supported = isTierSupportedByModel(model, tier);
|
|
877
|
-
ctx.ui.notify(buildServiceTierNotification({
|
|
878
|
-
tier,
|
|
879
|
-
success,
|
|
880
|
-
supported,
|
|
881
|
-
provider: model?.provider ?? PROVIDER_NAME,
|
|
882
|
-
model: model?.id ?? ""
|
|
883
|
-
}), !success || !supported ? "warning" : "info");
|
|
884
821
|
}
|
|
885
822
|
async function refreshPlexusModels(context) {
|
|
886
823
|
const baseUrl = getBaseUrl();
|
|
887
824
|
const modelsUrl = getModelsUrl();
|
|
888
|
-
const apiKey = credentialApiKey(context.credential)
|
|
825
|
+
const apiKey = resolveApiKey(credentialApiKey(context.credential));
|
|
889
826
|
const suppress = getSuppressedModels();
|
|
890
827
|
if (!context.allowNetwork || !apiKey || !modelsUrl || !baseUrl) {
|
|
891
828
|
if (currentModels.length > 0) {
|
|
@@ -972,7 +909,8 @@ function createPlexusLoginProvider() {
|
|
|
972
909
|
return { ...credentials, expires: PLEXUS_CREDENTIAL_EXPIRES_AT };
|
|
973
910
|
},
|
|
974
911
|
getApiKey(credentials) {
|
|
975
|
-
|
|
912
|
+
const stored = String(credentials.access || credentials.refresh || "");
|
|
913
|
+
return resolveExplicitApiKey() ?? stored;
|
|
976
914
|
},
|
|
977
915
|
modifyModels(models, credentials) {
|
|
978
916
|
const baseUrl = credentials.plexusBaseUrl;
|
|
@@ -984,7 +922,13 @@ function createPlexusLoginProvider() {
|
|
|
984
922
|
};
|
|
985
923
|
}
|
|
986
924
|
async function handleRefresh(ctx) {
|
|
987
|
-
|
|
925
|
+
let apiKey;
|
|
926
|
+
try {
|
|
927
|
+
apiKey = await ctx.modelRegistry.getApiKeyForProvider(PROVIDER_NAME);
|
|
928
|
+
} catch (error) {
|
|
929
|
+
ctx.ui.notify(`Plexus API key resolution failed: ${error instanceof Error ? error.message : String(error)}`, "error");
|
|
930
|
+
return;
|
|
931
|
+
}
|
|
988
932
|
if (!apiKey) {
|
|
989
933
|
ctx.ui.notify("No Plexus API key configured. Run /login plexus first.", "error");
|
|
990
934
|
return;
|
|
@@ -1004,10 +948,14 @@ async function handleRefresh(ctx) {
|
|
|
1004
948
|
}
|
|
1005
949
|
async function handleStatus(ctx) {
|
|
1006
950
|
const baseUrl = getBaseUrlResolution();
|
|
1007
|
-
const
|
|
951
|
+
const apiKeyEnvName = getApiKeyEnvName();
|
|
952
|
+
const apiKey = await ctx.modelRegistry.getApiKeyForProvider(PROVIDER_NAME).catch(() => {
|
|
953
|
+
return;
|
|
954
|
+
});
|
|
955
|
+
const explicitApiKey = apiKey ? resolveExplicitApiKey() : undefined;
|
|
1008
956
|
ctx.ui.notify([
|
|
1009
957
|
`Plexus base URL: ${baseUrl.baseUrl ?? "not configured"} (${baseUrl.source})`,
|
|
1010
|
-
`API key: ${apiKey ? getEnvApiKey() ?
|
|
958
|
+
`API key: ${apiKey ? explicitApiKey !== undefined ? `${apiKeyEnvName} (apiKeyEnv)` : getEnvApiKey() ? `host credential or ${apiKeyEnvName} fallback` : "host credential" : "not configured"}`,
|
|
1011
959
|
`Catalog: ${currentModels.length} models (${catalogSource})`,
|
|
1012
960
|
"Default model: managed by Pi. Use /model and save the selection there."
|
|
1013
961
|
].join(`
|
|
@@ -1015,5 +963,6 @@ async function handleStatus(ctx) {
|
|
|
1015
963
|
}
|
|
1016
964
|
export {
|
|
1017
965
|
plexusExtension as default,
|
|
1018
|
-
enforceMinimumOutputTokens
|
|
966
|
+
enforceMinimumOutputTokens,
|
|
967
|
+
withAuthoritativeApiKeyEnv
|
|
1019
968
|
};
|