@mcowger/pi-plexus 1.3.8 → 1.3.10
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 +42 -0
- package/dist/extension.js +158 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -244,6 +244,47 @@ Both adapters also accept pi-style environment interpolation in configured strin
|
|
|
244
244
|
|
|
245
245
|
---
|
|
246
246
|
|
|
247
|
+
## Model suppression
|
|
248
|
+
|
|
249
|
+
All plugin packages support suppressing models by name or pattern so undesired models do not appear in model selectors or cache restored lists.
|
|
250
|
+
|
|
251
|
+
### Pattern matching syntax
|
|
252
|
+
|
|
253
|
+
- **Exact match** (case-insensitive): Matches model `id`, `name`, or short ID (suffix after `/` or `:`). Example: `"gpt-4o"`, `"Claude 3.5 Sonnet"`.
|
|
254
|
+
- **Glob wildcards**: Supports `*` (0+ characters) and `?` (1 character). Example: `"gpt-3.5*"`, `"*deprecated*"`, `"anthropic/*"`.
|
|
255
|
+
- **Regex patterns**: Prefix with `regex:`. Example: `"regex:^gpt-[34]"`.
|
|
256
|
+
|
|
257
|
+
### Configuration methods
|
|
258
|
+
|
|
259
|
+
- **Environment variables**:
|
|
260
|
+
```sh
|
|
261
|
+
export PLEXUS_SUPPRESS_MODELS="gpt-3.5*, *deprecated*, whisper"
|
|
262
|
+
```
|
|
263
|
+
`PLEXUS_EXCLUDE_MODELS` is also accepted. Values can be comma-, semicolon-, or newline-separated.
|
|
264
|
+
|
|
265
|
+
- **pi / Oh My Pi config**: Add `suppressModels` (or `suppress`) to `config.json`:
|
|
266
|
+
```json
|
|
267
|
+
{
|
|
268
|
+
"baseUrl": "https://plexus.example.com",
|
|
269
|
+
"suppressModels": ["gpt-3.5*", "*deprecated*"]
|
|
270
|
+
}
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
- **OpenCode config**: Add `suppressModels` (or `suppress`) under `provider.plexus.options` in `opencode.json`:
|
|
274
|
+
```json
|
|
275
|
+
{
|
|
276
|
+
"provider": {
|
|
277
|
+
"plexus": {
|
|
278
|
+
"options": {
|
|
279
|
+
"suppressModels": ["gpt-3.5*", "claude-2*"]
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
---
|
|
287
|
+
|
|
247
288
|
## Package layout
|
|
248
289
|
|
|
249
290
|
```
|
|
@@ -252,6 +293,7 @@ packages/
|
|
|
252
293
|
src/
|
|
253
294
|
types.ts # wire types (PlexusApiModel, PlexusModelDescriptor, etc.)
|
|
254
295
|
convert.ts # model fetching, conversion, compat detection
|
|
296
|
+
suppress.ts # model pattern suppression / exclusion matching
|
|
255
297
|
index.ts # barrel export
|
|
256
298
|
plexus-pi/ # pi host adapter
|
|
257
299
|
src/
|
package/dist/extension.js
CHANGED
|
@@ -1,4 +1,53 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
// ../plexus-models/src/suppress.ts
|
|
3
|
+
function parseSuppressionPatterns(raw) {
|
|
4
|
+
if (!raw)
|
|
5
|
+
return [];
|
|
6
|
+
const items = Array.isArray(raw) ? raw : raw.split(/[\n,;]+/);
|
|
7
|
+
return items.map((s) => s.trim()).filter((s) => s.length > 0);
|
|
8
|
+
}
|
|
9
|
+
function getEnvSuppressedModels() {
|
|
10
|
+
const env = typeof process !== "undefined" && process?.env ? process.env : {};
|
|
11
|
+
const raw = env.PLEXUS_SUPPRESS_MODELS ?? env.PLEXUS_EXCLUDE_MODELS;
|
|
12
|
+
return parseSuppressionPatterns(raw);
|
|
13
|
+
}
|
|
14
|
+
function isModelSuppressed(model, patterns) {
|
|
15
|
+
const envPatterns = getEnvSuppressedModels();
|
|
16
|
+
const explicitPatterns = parseSuppressionPatterns(patterns);
|
|
17
|
+
const allPatterns = [...envPatterns, ...explicitPatterns];
|
|
18
|
+
if (allPatterns.length === 0)
|
|
19
|
+
return false;
|
|
20
|
+
const id = model.id.toLowerCase();
|
|
21
|
+
const name = (model.name ?? "").toLowerCase();
|
|
22
|
+
const shortId = id.includes("/") ? id.split("/").pop() : id.includes(":") ? id.split(":").pop() : id;
|
|
23
|
+
for (const pattern of allPatterns) {
|
|
24
|
+
if (matchesPattern(id, name, shortId, pattern)) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
function matchesPattern(id, name, shortId, pattern) {
|
|
31
|
+
const p = pattern.toLowerCase();
|
|
32
|
+
if (p.startsWith("regex:")) {
|
|
33
|
+
try {
|
|
34
|
+
const re = new RegExp(pattern.slice(6), "i");
|
|
35
|
+
return re.test(id) || re.test(name) || re.test(shortId);
|
|
36
|
+
} catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (p.includes("*") || p.includes("?")) {
|
|
41
|
+
const regexStr = "^" + p.replace(/([.+^${}()|[\]\\])/g, "\\$1").replace(/\*/g, ".*").replace(/\?/g, ".") + "$";
|
|
42
|
+
try {
|
|
43
|
+
const re = new RegExp(regexStr, "i");
|
|
44
|
+
return re.test(id) || re.test(name) || re.test(shortId);
|
|
45
|
+
} catch {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return id === p || name === p || shortId === p;
|
|
50
|
+
}
|
|
2
51
|
// ../plexus-models/src/convert.ts
|
|
3
52
|
var REASONING_PARAMS = new Set(["reasoning", "include_reasoning", "reasoning_effort"]);
|
|
4
53
|
var NON_CHAT_PATTERN = /(?:^|[\W_])(?:embed(?:ding|dings)?|transcri(?:be[ds]?|ptions?)|whisper|speech[\W_]*to[\W_]*text|stt|text[\W_]*to[\W_]*speech|tts|image[\W_]*(?:gen(?:eration)?|\d+)|diffusion|dall[\W_]*e|stable[\W_]*diffusion|sdxl|dream)(?:$|[\W_])/i;
|
|
@@ -132,11 +181,68 @@ function isChatModel(model) {
|
|
|
132
181
|
const apiHints = Array.isArray(model.preferred_api) ? model.preferred_api.join(" ") : model.preferred_api ?? "";
|
|
133
182
|
return !NON_CHAT_PATTERN.test(`${model.id} ${model.name ?? ""} ${apiHints}`);
|
|
134
183
|
}
|
|
135
|
-
function
|
|
184
|
+
function parseSuppressionPatterns2(input) {
|
|
185
|
+
if (!input)
|
|
186
|
+
return [];
|
|
187
|
+
const rawItems = Array.isArray(input) ? input : [input];
|
|
188
|
+
const patterns = [];
|
|
189
|
+
for (const item of rawItems) {
|
|
190
|
+
if (!item || typeof item !== "string")
|
|
191
|
+
continue;
|
|
192
|
+
const parts = item.split(/[\n,]/);
|
|
193
|
+
for (const part of parts) {
|
|
194
|
+
const trimmed = part.trim();
|
|
195
|
+
if (trimmed.length > 0) {
|
|
196
|
+
patterns.push(trimmed);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return patterns;
|
|
201
|
+
}
|
|
202
|
+
function isSuppressedModel(model, suppress) {
|
|
203
|
+
if (!model || !model.id)
|
|
204
|
+
return false;
|
|
205
|
+
const patterns = parseSuppressionPatterns2(suppress);
|
|
206
|
+
if (patterns.length === 0)
|
|
207
|
+
return false;
|
|
208
|
+
const idLower = model.id.toLowerCase();
|
|
209
|
+
const nameLower = (model.name ?? "").toLowerCase();
|
|
210
|
+
for (const pattern of patterns) {
|
|
211
|
+
const patternLower = pattern.toLowerCase();
|
|
212
|
+
if (idLower === patternLower || nameLower && nameLower === patternLower) {
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
if (pattern.startsWith("/") && pattern.lastIndexOf("/") > 0) {
|
|
216
|
+
const lastSlash = pattern.lastIndexOf("/");
|
|
217
|
+
const regexBody = pattern.slice(1, lastSlash);
|
|
218
|
+
const regexFlags = pattern.slice(lastSlash + 1) || "i";
|
|
219
|
+
try {
|
|
220
|
+
const re = new RegExp(regexBody, regexFlags);
|
|
221
|
+
if (re.test(model.id) || model.name && re.test(model.name)) {
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
} catch {}
|
|
225
|
+
}
|
|
226
|
+
if (pattern.includes("*") || pattern.includes("?")) {
|
|
227
|
+
try {
|
|
228
|
+
const escaped = patternLower.replace(/[.+^$()|[{}]\\]/g, "\\$&");
|
|
229
|
+
const regexStr = "^" + escaped.replace(/\*/g, ".*").replace(/\?/g, ".") + "$";
|
|
230
|
+
const globRe = new RegExp(regexStr, "i");
|
|
231
|
+
if (globRe.test(model.id) || model.name && globRe.test(model.name)) {
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
234
|
+
} catch {}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
function convertDescriptors(models, baseUrl, suppress) {
|
|
136
240
|
const result = [];
|
|
137
241
|
for (const m of models) {
|
|
138
242
|
if (!isChatModel(m))
|
|
139
243
|
continue;
|
|
244
|
+
if (isSuppressedModel(m, suppress))
|
|
245
|
+
continue;
|
|
140
246
|
result.push(convertToDescriptor(m, baseUrl));
|
|
141
247
|
}
|
|
142
248
|
return result;
|
|
@@ -201,22 +307,28 @@ function detectOpenAICompletionsCompat(providerName, baseUrl) {
|
|
|
201
307
|
return compat;
|
|
202
308
|
}
|
|
203
309
|
var DEFAULT_MODELS_FETCH_TIMEOUT_MS = 1e4;
|
|
204
|
-
async function fetchPlexusModels(apiKey, modelsUrl, timeoutMs = DEFAULT_MODELS_FETCH_TIMEOUT_MS) {
|
|
310
|
+
async function fetchPlexusModels(apiKey, modelsUrl, timeoutMs = DEFAULT_MODELS_FETCH_TIMEOUT_MS, etag) {
|
|
205
311
|
const controller = new AbortController;
|
|
206
312
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
207
313
|
try {
|
|
208
314
|
const headers = { Accept: "application/json" };
|
|
209
315
|
if (apiKey)
|
|
210
316
|
headers.Authorization = `Bearer ${apiKey}`;
|
|
317
|
+
if (etag)
|
|
318
|
+
headers["If-None-Match"] = etag;
|
|
211
319
|
const res = await fetch(modelsUrl, {
|
|
212
320
|
headers,
|
|
213
321
|
signal: controller.signal
|
|
214
322
|
});
|
|
323
|
+
if (res.status === 304) {
|
|
324
|
+
return { models: [], notModified: true };
|
|
325
|
+
}
|
|
215
326
|
if (!res.ok) {
|
|
216
327
|
throw new Error(`Plexus models fetch failed: ${res.status} ${res.statusText}`);
|
|
217
328
|
}
|
|
218
329
|
const raw = await res.json();
|
|
219
|
-
|
|
330
|
+
const responseEtag = res.headers.get("etag") ?? undefined;
|
|
331
|
+
return { models: raw.data ?? [], raw, etag: responseEtag };
|
|
220
332
|
} catch (err) {
|
|
221
333
|
if (err instanceof Error && err.name === "AbortError") {
|
|
222
334
|
throw new Error(`Plexus models fetch timed out after ${timeoutMs}ms`);
|
|
@@ -350,18 +462,44 @@ function getBaseUrl() {
|
|
|
350
462
|
const raw = getRawBaseUrl();
|
|
351
463
|
return raw ? normalizeApiBase(raw) : null;
|
|
352
464
|
}
|
|
465
|
+
function getSuppressedModels() {
|
|
466
|
+
const config = getConfigSync();
|
|
467
|
+
const envSuppressed = getEnvSuppressedModels();
|
|
468
|
+
const configSuppressed = parseSuppressionPatterns(config.suppressModels ?? config.suppress);
|
|
469
|
+
return [...envSuppressed, ...configSuppressed];
|
|
470
|
+
}
|
|
353
471
|
|
|
354
472
|
// src/cache.ts
|
|
355
|
-
import { mkdir as mkdir2, writeFile as writeFile2 } from "fs/promises";
|
|
473
|
+
import { mkdir as mkdir2, writeFile as writeFile2, readFile } from "fs/promises";
|
|
474
|
+
import { existsSync as existsSync2 } from "fs";
|
|
356
475
|
import { join as join2 } from "path";
|
|
357
476
|
import { getAgentDir as getAgentDir2 } from "@earendil-works/pi-coding-agent";
|
|
358
477
|
var getCacheDir = () => join2(getAgentDir2(), "extensions", "plexus");
|
|
359
478
|
var getRawResponsePath = () => join2(getCacheDir(), "plexus-models-response.json");
|
|
479
|
+
var getEtagPath = () => join2(getCacheDir(), "plexus-models-etag.txt");
|
|
360
480
|
async function writeRawResponse(data) {
|
|
361
481
|
await mkdir2(getCacheDir(), { recursive: true });
|
|
362
482
|
await writeFile2(getRawResponsePath(), `${JSON.stringify(data, null, 2)}
|
|
363
483
|
`, "utf8");
|
|
364
484
|
}
|
|
485
|
+
async function readCachedEtag() {
|
|
486
|
+
try {
|
|
487
|
+
const p = getEtagPath();
|
|
488
|
+
if (!existsSync2(p))
|
|
489
|
+
return;
|
|
490
|
+
return (await readFile(p, "utf8")).trim();
|
|
491
|
+
} catch {
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
async function writeCachedEtag(etag) {
|
|
496
|
+
if (!etag)
|
|
497
|
+
return;
|
|
498
|
+
try {
|
|
499
|
+
await mkdir2(getCacheDir(), { recursive: true });
|
|
500
|
+
await writeFile2(getEtagPath(), etag, "utf8");
|
|
501
|
+
} catch {}
|
|
502
|
+
}
|
|
365
503
|
|
|
366
504
|
// src/log.ts
|
|
367
505
|
import { mkdir as mkdir3, appendFile } from "fs/promises";
|
|
@@ -619,8 +757,12 @@ async function refreshPlexusModels(context) {
|
|
|
619
757
|
const baseUrl = getBaseUrl();
|
|
620
758
|
const modelsUrl = getModelsUrl();
|
|
621
759
|
const apiKey = credentialApiKey(context.credential) ?? getEnvApiKey() ?? undefined;
|
|
760
|
+
const suppress = getSuppressedModels();
|
|
761
|
+
const storedEtag = await readCachedEtag();
|
|
622
762
|
if (!context.allowNetwork || !apiKey || !modelsUrl || !baseUrl) {
|
|
623
763
|
if (currentModels.length > 0) {
|
|
764
|
+
const filteredCurrent = currentModels.filter((m) => !isModelSuppressed({ id: m.id, name: m.name }, suppress));
|
|
765
|
+
currentModels = filteredCurrent;
|
|
624
766
|
await context.store.write({ models: currentModels, checkedAt: Date.now() });
|
|
625
767
|
return currentModels;
|
|
626
768
|
}
|
|
@@ -630,11 +772,18 @@ async function refreshPlexusModels(context) {
|
|
|
630
772
|
throw new Error(!modelsUrl || !baseUrl ? "Plexus base URL not configured. Run /login plexus first." : "No Plexus API key configured. Run /login plexus first.");
|
|
631
773
|
}
|
|
632
774
|
try {
|
|
633
|
-
const { models: apiModels, raw } = await fetchPlexusModels(apiKey, modelsUrl);
|
|
634
|
-
|
|
775
|
+
const { models: apiModels, raw, etag, notModified } = await fetchPlexusModels(apiKey, modelsUrl, undefined, storedEtag);
|
|
776
|
+
if (notModified) {
|
|
777
|
+
log("refreshModels: not modified", { etag: storedEtag });
|
|
778
|
+
const restored = await restoreStoredModels(context);
|
|
779
|
+
if (restored)
|
|
780
|
+
return restored;
|
|
781
|
+
}
|
|
782
|
+
const piModels = convertDescriptors(apiModels, baseUrl, suppress).map(descriptorToPiModel);
|
|
635
783
|
await Promise.all([
|
|
636
784
|
context.store.write({ models: piModels, checkedAt: Date.now() }),
|
|
637
|
-
|
|
785
|
+
writeCachedEtag(etag),
|
|
786
|
+
raw ? writeRawResponse(raw) : Promise.resolve()
|
|
638
787
|
]);
|
|
639
788
|
currentModels = piModels;
|
|
640
789
|
log("refreshModels: fetched", { count: piModels.length });
|
|
@@ -648,7 +797,8 @@ async function restoreStoredModels(context) {
|
|
|
648
797
|
const stored = await context.store.read();
|
|
649
798
|
if (!stored || stored.models.length === 0)
|
|
650
799
|
return;
|
|
651
|
-
const
|
|
800
|
+
const suppress = getSuppressedModels();
|
|
801
|
+
const models = stored.models.filter((m) => !isModelSuppressed({ id: m.id, name: m.name }, suppress));
|
|
652
802
|
currentModels = models;
|
|
653
803
|
log("refreshModels: restored from store", { count: models.length });
|
|
654
804
|
return models;
|