@mcowger/pi-plexus 1.5.0 → 1.6.1
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 +23 -26
- package/dist/extension.js +58 -199
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ Exposes models from a self-hosted [Plexus](https://github.com/mcowger/plexus) AI
|
|
|
12
12
|
## Prerequisites
|
|
13
13
|
|
|
14
14
|
- A running Plexus instance
|
|
15
|
-
- pi 0.
|
|
15
|
+
- pi 0.85.1 or later (for `plexus-pi`)
|
|
16
16
|
|
|
17
17
|
## Installation
|
|
18
18
|
|
|
@@ -109,13 +109,14 @@ To force a model refresh:
|
|
|
109
109
|
/plexus refresh
|
|
110
110
|
```
|
|
111
111
|
|
|
112
|
-
|
|
112
|
+
Inspect the effective URL, authentication availability, and catalog source without exposing a credential:
|
|
113
113
|
|
|
114
114
|
```
|
|
115
|
-
/plexus
|
|
116
|
-
/plexus set-default-model claude-sonnet-4-5
|
|
115
|
+
/plexus status
|
|
117
116
|
```
|
|
118
117
|
|
|
118
|
+
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.
|
|
119
|
+
|
|
119
120
|
Use `/login plexus` for setup and `/logout plexus` to remove stored credentials.
|
|
120
121
|
|
|
121
122
|
### Oh My Pi
|
|
@@ -126,35 +127,32 @@ Run inside Oh My Pi using the native login flow:
|
|
|
126
127
|
/login plexus
|
|
127
128
|
```
|
|
128
129
|
|
|
129
|
-
Same prompts and `/plexus refresh` / `/plexus
|
|
130
|
+
Same prompts and `/plexus refresh` / `/plexus status` commands as pi (see above). Save the selected startup model through OMP's normal `/model` or `/models` flow.
|
|
130
131
|
|
|
131
132
|
## Configuration files
|
|
132
133
|
|
|
133
|
-
###
|
|
134
|
+
### Connection state
|
|
134
135
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
plexus-models-response.json # raw API response (diagnostics)
|
|
140
|
-
plexus.log # extension activity log
|
|
136
|
+
Each adapter stores only non-secret Plexus settings in its own `config.json`:
|
|
137
|
+
|
|
138
|
+
```text
|
|
139
|
+
<agent-dir>/extensions/plexus/config.json # base URL and optional model suppression
|
|
141
140
|
```
|
|
142
141
|
|
|
143
|
-
|
|
142
|
+
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.
|
|
144
143
|
|
|
145
|
-
|
|
144
|
+
At runtime, configuration resolves as follows:
|
|
146
145
|
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
plexus.log # extension activity log
|
|
146
|
+
```text
|
|
147
|
+
base URL: PLEXUS_API_URL → PLEXUS_BASE_URL → saved Plexus base URL
|
|
148
|
+
API key: host credential store → PLEXUS_API_KEY process fallback
|
|
149
|
+
catalog: host model store → live Plexus refresh
|
|
150
|
+
startup model: host model-picker preference
|
|
153
151
|
```
|
|
154
152
|
|
|
155
|
-
|
|
153
|
+
`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.
|
|
156
154
|
|
|
157
|
-
|
|
155
|
+
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`.
|
|
158
156
|
|
|
159
157
|
---
|
|
160
158
|
|
|
@@ -200,16 +198,15 @@ packages/
|
|
|
200
198
|
src/
|
|
201
199
|
extension.ts # entry point: commands, session refresh, auth flow
|
|
202
200
|
mapper.ts # PlexusModelDescriptor → pi ProviderModelConfig
|
|
203
|
-
config.ts # base URL /
|
|
204
|
-
cache.ts # model
|
|
201
|
+
config.ts # base URL / suppression config I/O
|
|
202
|
+
cache.ts # Pi native model-store restore
|
|
205
203
|
log.ts # append-only log
|
|
206
204
|
package.json # declares pi.extensions entry point
|
|
207
205
|
plexus-oh-my-pi/ # Oh My Pi host adapter (fork of pi; own runtime packages + catalog)
|
|
208
206
|
src/
|
|
209
207
|
extension.ts # entry point: commands, session refresh, auth flow
|
|
210
208
|
mapper.ts # PlexusModelDescriptor → Oh My Pi ProviderModelConfig
|
|
211
|
-
config.ts # base URL /
|
|
212
|
-
cache.ts # model cache I/O
|
|
209
|
+
config.ts # base URL / suppression config I/O
|
|
213
210
|
log.ts # append-only log
|
|
214
211
|
package.json # declares omp.extensions entry point
|
|
215
212
|
```
|
package/dist/extension.js
CHANGED
|
@@ -421,7 +421,7 @@ var normalizeConfigBaseUrl = (raw) => {
|
|
|
421
421
|
const root = normalizeRoot(raw);
|
|
422
422
|
return root.endsWith("/v1") ? root.slice(0, -3) : root;
|
|
423
423
|
};
|
|
424
|
-
var
|
|
424
|
+
var toPlexusApiBase = (raw) => {
|
|
425
425
|
const root = normalizeConfigBaseUrl(raw);
|
|
426
426
|
return root ? `${root}/v1` : "";
|
|
427
427
|
};
|
|
@@ -438,39 +438,38 @@ function getConfigSync() {
|
|
|
438
438
|
cachedConfig = {};
|
|
439
439
|
return cachedConfig;
|
|
440
440
|
}
|
|
441
|
-
async function saveBaseUrl(baseUrl
|
|
441
|
+
async function saveBaseUrl(baseUrl) {
|
|
442
442
|
await mkdir(getConfigDir(), { recursive: true });
|
|
443
|
-
const existing = getConfigSync();
|
|
443
|
+
const { defaultModel: _defaultModel, ...existing } = getConfigSync();
|
|
444
444
|
const config = {
|
|
445
445
|
...existing,
|
|
446
|
-
baseUrl: normalizeConfigBaseUrl(baseUrl)
|
|
447
|
-
...defaultModel !== undefined && { defaultModel }
|
|
446
|
+
baseUrl: normalizeConfigBaseUrl(baseUrl)
|
|
448
447
|
};
|
|
449
448
|
await writeFile(getConfigPath(), `${JSON.stringify(config, null, 2)}
|
|
450
449
|
`, "utf8");
|
|
451
450
|
cachedConfig = config;
|
|
452
451
|
}
|
|
453
|
-
|
|
454
|
-
await mkdir(getConfigDir(), { recursive: true });
|
|
455
|
-
const config = { ...getConfigSync(), defaultModel };
|
|
456
|
-
await writeFile(getConfigPath(), `${JSON.stringify(config, null, 2)}
|
|
457
|
-
`, "utf8");
|
|
458
|
-
cachedConfig = config;
|
|
459
|
-
}
|
|
460
|
-
function getRawBaseUrl() {
|
|
452
|
+
function getBaseUrlResolution() {
|
|
461
453
|
const config = getConfigSync();
|
|
462
|
-
|
|
454
|
+
const apiUrl = resolveStringOption(process.env[ENV_API_URL]);
|
|
455
|
+
if (apiUrl)
|
|
456
|
+
return { baseUrl: apiUrl, source: ENV_API_URL };
|
|
457
|
+
const baseUrl = resolveStringOption(process.env[ENV_BASE_URL]);
|
|
458
|
+
if (baseUrl)
|
|
459
|
+
return { baseUrl, source: ENV_BASE_URL };
|
|
460
|
+
const saved = resolveStringOption(config.baseUrl);
|
|
461
|
+
return { baseUrl: saved ?? null, source: saved ? "saved" : "none" };
|
|
463
462
|
}
|
|
464
463
|
function getEnvApiKey() {
|
|
465
464
|
return resolveStringOption(process.env[ENV_API_KEY]) ?? null;
|
|
466
465
|
}
|
|
467
466
|
function getModelsUrl() {
|
|
468
|
-
const
|
|
469
|
-
return
|
|
467
|
+
const { baseUrl } = getBaseUrlResolution();
|
|
468
|
+
return baseUrl ? `${toPlexusApiBase(baseUrl)}/models` : null;
|
|
470
469
|
}
|
|
471
470
|
function getBaseUrl() {
|
|
472
|
-
const
|
|
473
|
-
return
|
|
471
|
+
const { baseUrl } = getBaseUrlResolution();
|
|
472
|
+
return baseUrl ? toPlexusApiBase(baseUrl) : null;
|
|
474
473
|
}
|
|
475
474
|
function getSuppressedModels() {
|
|
476
475
|
const config = getConfigSync();
|
|
@@ -480,129 +479,36 @@ function getSuppressedModels() {
|
|
|
480
479
|
}
|
|
481
480
|
|
|
482
481
|
// src/cache.ts
|
|
483
|
-
import { mkdir as mkdir2, writeFile as writeFile2, readFile } from "fs/promises";
|
|
484
482
|
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
485
483
|
import { join as join2 } from "path";
|
|
486
484
|
import { getAgentDir as getAgentDir2 } from "@earendil-works/pi-coding-agent";
|
|
487
|
-
|
|
488
|
-
var getModelsCachePath = () => join2(getCacheDir(), "plexus-models-cache.json");
|
|
489
|
-
var getRawResponsePath = () => join2(getCacheDir(), "plexus-models-response.json");
|
|
490
|
-
var getEtagPath = () => join2(getCacheDir(), "plexus-models-etag.txt");
|
|
491
|
-
var getModelsStorePath = () => join2(getAgentDir2(), "models-store.json");
|
|
492
|
-
function isPlexusModelDescriptor(value) {
|
|
493
|
-
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
494
|
-
return false;
|
|
495
|
-
const model = value;
|
|
496
|
-
const cost = model["cost"];
|
|
497
|
-
return typeof model["id"] === "string" && typeof model["name"] === "string" && typeof model["preferredApi"] === "string" && model["provider"] === "plexus" && typeof model["baseUrl"] === "string" && typeof model["reasoning"] === "boolean" && Array.isArray(model["input"]) && typeof model["contextWindow"] === "number" && typeof model["maxTokens"] === "number" && !!cost && typeof cost === "object" && !Array.isArray(cost) && typeof cost["input"] === "number" && typeof cost["output"] === "number" && typeof cost["cacheRead"] === "number" && typeof cost["cacheWrite"] === "number";
|
|
498
|
-
}
|
|
499
|
-
function parseCacheData(raw) {
|
|
500
|
-
try {
|
|
501
|
-
const parsed = JSON.parse(raw);
|
|
502
|
-
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
503
|
-
return null;
|
|
504
|
-
const obj = parsed;
|
|
505
|
-
if (!Array.isArray(obj["models"]) || !obj["models"].every(isPlexusModelDescriptor))
|
|
506
|
-
return null;
|
|
507
|
-
return {
|
|
508
|
-
models: obj["models"],
|
|
509
|
-
timestamp: typeof obj["timestamp"] === "number" ? obj["timestamp"] : 0,
|
|
510
|
-
etag: typeof obj["etag"] === "string" ? obj["etag"] : undefined
|
|
511
|
-
};
|
|
512
|
-
} catch {
|
|
513
|
-
return null;
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
function parseModelsStoreData(raw) {
|
|
485
|
+
function readStoredModelsSync() {
|
|
517
486
|
try {
|
|
518
|
-
const
|
|
519
|
-
if (!
|
|
487
|
+
const path = join2(getAgentDir2(), "models-store.json");
|
|
488
|
+
if (!existsSync2(path))
|
|
520
489
|
return null;
|
|
521
|
-
const
|
|
522
|
-
const
|
|
523
|
-
if (!
|
|
490
|
+
const data = JSON.parse(readFileSync2(path, "utf8"));
|
|
491
|
+
const plexus = data["plexus"];
|
|
492
|
+
if (!plexus || typeof plexus !== "object" || Array.isArray(plexus))
|
|
524
493
|
return null;
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
if (Array.isArray(plexusObj)) {
|
|
528
|
-
modelsList = plexusObj;
|
|
529
|
-
} else if (typeof plexusObj === "object" && plexusObj !== null) {
|
|
530
|
-
const pObj = plexusObj;
|
|
531
|
-
if (Array.isArray(pObj["models"])) {
|
|
532
|
-
modelsList = pObj["models"];
|
|
533
|
-
}
|
|
534
|
-
if (typeof pObj["checkedAt"] === "number") {
|
|
535
|
-
checkedAt = pObj["checkedAt"];
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
if (!modelsList)
|
|
494
|
+
const catalog = plexus;
|
|
495
|
+
if (!Array.isArray(catalog["models"]))
|
|
539
496
|
return null;
|
|
540
497
|
return {
|
|
541
|
-
|
|
542
|
-
|
|
498
|
+
models: catalog["models"],
|
|
499
|
+
checkedAt: typeof catalog["checkedAt"] === "number" ? catalog["checkedAt"] : 0
|
|
543
500
|
};
|
|
544
501
|
} catch {
|
|
545
502
|
return null;
|
|
546
503
|
}
|
|
547
504
|
}
|
|
548
|
-
function readCachedModelsSync() {
|
|
549
|
-
try {
|
|
550
|
-
const cachePath = getModelsCachePath();
|
|
551
|
-
if (existsSync2(cachePath)) {
|
|
552
|
-
const cache = parseCacheData(readFileSync2(cachePath, "utf8"));
|
|
553
|
-
if (cache)
|
|
554
|
-
return cache;
|
|
555
|
-
}
|
|
556
|
-
const storePath = getModelsStorePath();
|
|
557
|
-
if (existsSync2(storePath)) {
|
|
558
|
-
const storeCache = parseModelsStoreData(readFileSync2(storePath, "utf8"));
|
|
559
|
-
if (storeCache)
|
|
560
|
-
return storeCache;
|
|
561
|
-
}
|
|
562
|
-
return null;
|
|
563
|
-
} catch {
|
|
564
|
-
return null;
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
async function writeCachedModels(models, etag) {
|
|
568
|
-
await mkdir2(getCacheDir(), { recursive: true });
|
|
569
|
-
const payload = { models, timestamp: Date.now(), etag };
|
|
570
|
-
await writeFile2(getModelsCachePath(), `${JSON.stringify(payload, null, 2)}
|
|
571
|
-
`, "utf8");
|
|
572
|
-
}
|
|
573
|
-
async function writeRawResponse(data) {
|
|
574
|
-
await mkdir2(getCacheDir(), { recursive: true });
|
|
575
|
-
await writeFile2(getRawResponsePath(), `${JSON.stringify(data, null, 2)}
|
|
576
|
-
`, "utf8");
|
|
577
|
-
}
|
|
578
|
-
async function readCachedEtag() {
|
|
579
|
-
try {
|
|
580
|
-
const cache = readCachedModelsSync();
|
|
581
|
-
if (cache?.etag)
|
|
582
|
-
return cache.etag;
|
|
583
|
-
const p = getEtagPath();
|
|
584
|
-
if (!existsSync2(p))
|
|
585
|
-
return;
|
|
586
|
-
return (await readFile(p, "utf8")).trim();
|
|
587
|
-
} catch {
|
|
588
|
-
return;
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
async function writeCachedEtag(etag) {
|
|
592
|
-
if (!etag)
|
|
593
|
-
return;
|
|
594
|
-
try {
|
|
595
|
-
await mkdir2(getCacheDir(), { recursive: true });
|
|
596
|
-
await writeFile2(getEtagPath(), etag, "utf8");
|
|
597
|
-
} catch {}
|
|
598
|
-
}
|
|
599
505
|
|
|
600
506
|
// src/log.ts
|
|
601
|
-
import { mkdir as
|
|
507
|
+
import { mkdir as mkdir2, appendFile } from "fs/promises";
|
|
602
508
|
import { join as join3 } from "path";
|
|
603
509
|
import { getAgentDir as getAgentDir3 } from "@earendil-works/pi-coding-agent";
|
|
604
|
-
var
|
|
605
|
-
var getLogPath = () => join3(
|
|
510
|
+
var getCacheDir = () => join3(getAgentDir3(), "extensions", "plexus");
|
|
511
|
+
var getLogPath = () => join3(getCacheDir(), "plexus.log");
|
|
606
512
|
var dirEnsured = false;
|
|
607
513
|
function log(message, data) {
|
|
608
514
|
writeLogLine(message, data);
|
|
@@ -610,7 +516,7 @@ function log(message, data) {
|
|
|
610
516
|
async function writeLogLine(message, data) {
|
|
611
517
|
try {
|
|
612
518
|
if (!dirEnsured) {
|
|
613
|
-
await
|
|
519
|
+
await mkdir2(getCacheDir(), { recursive: true });
|
|
614
520
|
dirEnsured = true;
|
|
615
521
|
}
|
|
616
522
|
const ts = new Date().toISOString();
|
|
@@ -737,9 +643,7 @@ var PROVIDER_API_KEY_TEMPLATE = "${PLEXUS_API_KEY}";
|
|
|
737
643
|
var PLEXUS_CREDENTIAL_EXPIRES_AT = 253402300799000;
|
|
738
644
|
var PLACEHOLDER_BASE_URL = "http://localhost/v1";
|
|
739
645
|
var currentModels = [];
|
|
740
|
-
|
|
741
|
-
return descriptors.filter((descriptor) => !isModelSuppressed({ id: descriptor.id, name: descriptor.name }, suppressPatterns)).map(descriptorToPiModel);
|
|
742
|
-
}
|
|
646
|
+
var catalogSource = "none";
|
|
743
647
|
function enforceMinimumOutputTokens(payload) {
|
|
744
648
|
if (!payload || typeof payload !== "object" || Array.isArray(payload))
|
|
745
649
|
return payload;
|
|
@@ -769,19 +673,15 @@ function plexusExtension(pi) {
|
|
|
769
673
|
const envApiKey = getEnvApiKey();
|
|
770
674
|
const startupBaseUrl = getBaseUrl();
|
|
771
675
|
const suppressPatterns = getSuppressedModels();
|
|
772
|
-
const
|
|
773
|
-
|
|
774
|
-
if (cached?.models && cached.models.length > 0) {
|
|
775
|
-
startupModels = cachedDescriptorsToPiModels(cached.models, suppressPatterns);
|
|
776
|
-
} else if (cached?.piModels && cached.piModels.length > 0) {
|
|
777
|
-
startupModels = cached.piModels.filter((m) => !isModelSuppressed({ id: m.id, name: m.name }, suppressPatterns));
|
|
778
|
-
}
|
|
676
|
+
const storedCatalog = readStoredModelsSync();
|
|
677
|
+
const startupModels = (storedCatalog?.models ?? []).filter((model) => !isModelSuppressed({ id: model.id, name: model.name }, suppressPatterns));
|
|
779
678
|
currentModels = startupModels;
|
|
679
|
+
catalogSource = startupModels.length > 0 ? "host store" : "none";
|
|
780
680
|
pi.on("before_provider_request", (event, ctx) => ctx.model?.provider === PROVIDER_NAME ? enforceMinimumOutputTokens(event.payload) : undefined);
|
|
781
681
|
log("startup", {
|
|
782
682
|
baseUrl: startupBaseUrl,
|
|
783
683
|
hasEnvApiKey: !!envApiKey,
|
|
784
|
-
|
|
684
|
+
hostStoredModelCount: startupModels.length
|
|
785
685
|
});
|
|
786
686
|
pi.on("message_end", (event) => normalizeMalformedFunctionCall(event.message, PROVIDER_NAME));
|
|
787
687
|
pi.registerProvider(PROVIDER_NAME, {
|
|
@@ -794,38 +694,21 @@ function plexusExtension(pi) {
|
|
|
794
694
|
oauth: createPlexusLoginProvider()
|
|
795
695
|
});
|
|
796
696
|
pi.registerCommand("plexus", {
|
|
797
|
-
description: "Plexus provider commands: refresh,
|
|
697
|
+
description: "Plexus provider commands: refresh, status (setup: /login plexus)",
|
|
798
698
|
getArgumentCompletions: (prefix) => {
|
|
799
699
|
const subcommands = [
|
|
800
700
|
{ value: "refresh", label: "refresh", description: "Refresh Plexus models from the API" },
|
|
801
|
-
{ value: "
|
|
701
|
+
{ value: "status", label: "status", description: "Show Plexus configuration and catalog status" }
|
|
802
702
|
];
|
|
803
|
-
|
|
804
|
-
return subcommands.filter((command) => command.value.startsWith(prefix));
|
|
805
|
-
}
|
|
806
|
-
const [subcommand, ...rest] = prefix.split(/\s+/);
|
|
807
|
-
if (subcommand !== "set-default-model")
|
|
808
|
-
return null;
|
|
809
|
-
const modelPrefix = rest.join(" ");
|
|
810
|
-
const choices = currentModels.map((model) => ({
|
|
811
|
-
value: model.id,
|
|
812
|
-
label: model.name === model.id ? model.id : `${model.name} (${model.id})`
|
|
813
|
-
}));
|
|
814
|
-
const filtered = choices.filter((choice) => choice.value.toLowerCase().startsWith(modelPrefix.toLowerCase()));
|
|
815
|
-
return filtered.length > 0 ? filtered : null;
|
|
703
|
+
return prefix.includes(" ") ? null : subcommands.filter((command) => command.value.startsWith(prefix));
|
|
816
704
|
},
|
|
817
705
|
handler: async (args, ctx) => {
|
|
818
|
-
const
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
return;
|
|
823
|
-
}
|
|
824
|
-
if (sub === "set-default-model" || sub.startsWith("set-default-model ")) {
|
|
825
|
-
await handleSetDefaultModel(pi, ctx, trimmed.slice("set-default-model".length).trim());
|
|
826
|
-
return;
|
|
827
|
-
}
|
|
828
|
-
ctx.ui.notify(`Unknown sub-command: "${args}". Use /login plexus, /plexus refresh, or /plexus set-default-model.`, "warning");
|
|
706
|
+
const sub = args.trim().toLowerCase();
|
|
707
|
+
if (sub === "refresh" || sub === "")
|
|
708
|
+
return handleRefresh(ctx);
|
|
709
|
+
if (sub === "status")
|
|
710
|
+
return handleStatus(ctx);
|
|
711
|
+
ctx.ui.notify(`Unknown sub-command: "${args}". Use /login plexus, /plexus refresh, or /plexus status.`, "warning");
|
|
829
712
|
}
|
|
830
713
|
});
|
|
831
714
|
}
|
|
@@ -850,31 +733,20 @@ async function refreshPlexusModels(context) {
|
|
|
850
733
|
return restored;
|
|
851
734
|
throw new Error(!modelsUrl || !baseUrl ? "Plexus base URL not configured. Run /login plexus first." : "No Plexus API key configured. Run /login plexus first.");
|
|
852
735
|
}
|
|
853
|
-
const storedEtag = await readCachedEtag();
|
|
854
736
|
try {
|
|
855
|
-
const { models: apiModels
|
|
856
|
-
if (notModified) {
|
|
857
|
-
log("refreshModels: not modified", { etag: storedEtag });
|
|
858
|
-
const restored = await restoreStoredModels(context);
|
|
859
|
-
if (restored)
|
|
860
|
-
return restored;
|
|
861
|
-
}
|
|
737
|
+
const { models: apiModels } = await fetchPlexusModels(apiKey, modelsUrl, undefined, undefined, context.signal);
|
|
862
738
|
const descriptors = convertDescriptors(apiModels, baseUrl, suppress);
|
|
863
739
|
const piModels = descriptors.map(descriptorToPiModel);
|
|
864
740
|
const published = await context.publish({
|
|
865
741
|
persist: { models: piModels, checkedAt: Date.now() },
|
|
866
742
|
update: () => {
|
|
867
743
|
currentModels = piModels;
|
|
744
|
+
catalogSource = "live refresh";
|
|
868
745
|
}
|
|
869
746
|
});
|
|
870
747
|
if (!published) {
|
|
871
748
|
log("refreshModels: publication superseded by a newer refresh", {});
|
|
872
749
|
}
|
|
873
|
-
await Promise.all([
|
|
874
|
-
writeCachedModels(descriptors, etag),
|
|
875
|
-
writeCachedEtag(etag),
|
|
876
|
-
raw ? writeRawResponse(raw) : Promise.resolve()
|
|
877
|
-
]);
|
|
878
750
|
log("refreshModels: fetched", { count: piModels.length });
|
|
879
751
|
return piModels;
|
|
880
752
|
} catch (error) {
|
|
@@ -891,6 +763,7 @@ async function restoreStoredModels(context) {
|
|
|
891
763
|
await context.publish({
|
|
892
764
|
update: () => {
|
|
893
765
|
currentModels = models;
|
|
766
|
+
catalogSource = "host store";
|
|
894
767
|
}
|
|
895
768
|
});
|
|
896
769
|
log("refreshModels: restored from store", { count: models.length });
|
|
@@ -959,32 +832,18 @@ async function handleRefresh(ctx) {
|
|
|
959
832
|
}
|
|
960
833
|
ctx.ui.notify(currentModels.length > 0 ? `Refreshed ${currentModels.length} Plexus models` : "Refresh finished but no Plexus models are available. Check the Plexus server and /login plexus.", currentModels.length > 0 ? "info" : "warning");
|
|
961
834
|
}
|
|
962
|
-
async function
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
}
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
return;
|
|
973
|
-
const selectedIndex = choices.indexOf(selected);
|
|
974
|
-
modelId = currentModels[selectedIndex]?.id ?? "";
|
|
975
|
-
}
|
|
976
|
-
const model = currentModels.find((candidate) => candidate.id === modelId);
|
|
977
|
-
if (!model) {
|
|
978
|
-
ctx.ui.notify(`Plexus model not found: "${modelId}". Run /plexus refresh and choose a model from the available list.`, "error");
|
|
979
|
-
return;
|
|
980
|
-
}
|
|
981
|
-
await saveDefaultModel(model.id);
|
|
982
|
-
const registryModel = ctx.modelRegistry.find(PROVIDER_NAME, model.id) ?? model;
|
|
983
|
-
const active = await pi.setModel(registryModel);
|
|
984
|
-
ctx.ui.notify(active ? `Plexus model selected: ${model.id}.` : `Plexus model ${model.id} was saved but could not be selected in this session.`, active ? "info" : "warning");
|
|
835
|
+
async function handleStatus(ctx) {
|
|
836
|
+
const baseUrl = getBaseUrlResolution();
|
|
837
|
+
const apiKey = await ctx.modelRegistry.getApiKeyForProvider(PROVIDER_NAME);
|
|
838
|
+
ctx.ui.notify([
|
|
839
|
+
`Plexus base URL: ${baseUrl.baseUrl ?? "not configured"} (${baseUrl.source})`,
|
|
840
|
+
`API key: ${apiKey ? getEnvApiKey() ? "host credential or PLEXUS_API_KEY fallback" : "host credential" : "not configured"}`,
|
|
841
|
+
`Catalog: ${currentModels.length} models (${catalogSource})`,
|
|
842
|
+
"Default model: managed by Pi. Use /model and save the selection there."
|
|
843
|
+
].join(`
|
|
844
|
+
`), "info");
|
|
985
845
|
}
|
|
986
846
|
export {
|
|
987
|
-
cachedDescriptorsToPiModels,
|
|
988
847
|
plexusExtension as default,
|
|
989
848
|
enforceMinimumOutputTokens
|
|
990
849
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcowger/pi-plexus",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "Plexus AI proxy plugin for the pi coding agent",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
"build": "bun run build.ts"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@earendil-works/pi-ai": ">=0.
|
|
29
|
-
"@earendil-works/pi-coding-agent": ">=0.
|
|
28
|
+
"@earendil-works/pi-ai": ">=0.99.0",
|
|
29
|
+
"@earendil-works/pi-coding-agent": ">=0.99.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@earendil-works/pi-ai": "^0.
|
|
33
|
-
"@earendil-works/pi-coding-agent": "^0.
|
|
32
|
+
"@earendil-works/pi-ai": "^0.99.0",
|
|
33
|
+
"@earendil-works/pi-coding-agent": "^0.99.0",
|
|
34
34
|
"@types/bun": "latest"
|
|
35
35
|
},
|
|
36
36
|
"repository": {
|