@mcowger/pi-plexus 1.3.7 → 1.3.9
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 +119 -3
- 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;
|
|
@@ -350,6 +456,12 @@ function getBaseUrl() {
|
|
|
350
456
|
const raw = getRawBaseUrl();
|
|
351
457
|
return raw ? normalizeApiBase(raw) : null;
|
|
352
458
|
}
|
|
459
|
+
function getSuppressedModels() {
|
|
460
|
+
const config = getConfigSync();
|
|
461
|
+
const envSuppressed = getEnvSuppressedModels();
|
|
462
|
+
const configSuppressed = parseSuppressionPatterns(config.suppressModels ?? config.suppress);
|
|
463
|
+
return [...envSuppressed, ...configSuppressed];
|
|
464
|
+
}
|
|
353
465
|
|
|
354
466
|
// src/cache.ts
|
|
355
467
|
import { mkdir as mkdir2, writeFile as writeFile2 } from "fs/promises";
|
|
@@ -619,8 +731,11 @@ async function refreshPlexusModels(context) {
|
|
|
619
731
|
const baseUrl = getBaseUrl();
|
|
620
732
|
const modelsUrl = getModelsUrl();
|
|
621
733
|
const apiKey = credentialApiKey(context.credential) ?? getEnvApiKey() ?? undefined;
|
|
734
|
+
const suppress = getSuppressedModels();
|
|
622
735
|
if (!context.allowNetwork || !apiKey || !modelsUrl || !baseUrl) {
|
|
623
736
|
if (currentModels.length > 0) {
|
|
737
|
+
const filteredCurrent = currentModels.filter((m) => !isModelSuppressed({ id: m.id, name: m.name }, suppress));
|
|
738
|
+
currentModels = filteredCurrent;
|
|
624
739
|
await context.store.write({ models: currentModels, checkedAt: Date.now() });
|
|
625
740
|
return currentModels;
|
|
626
741
|
}
|
|
@@ -631,7 +746,7 @@ async function refreshPlexusModels(context) {
|
|
|
631
746
|
}
|
|
632
747
|
try {
|
|
633
748
|
const { models: apiModels, raw } = await fetchPlexusModels(apiKey, modelsUrl);
|
|
634
|
-
const piModels = convertDescriptors(apiModels, baseUrl).map(descriptorToPiModel);
|
|
749
|
+
const piModels = convertDescriptors(apiModels, baseUrl, suppress).map(descriptorToPiModel);
|
|
635
750
|
await Promise.all([
|
|
636
751
|
context.store.write({ models: piModels, checkedAt: Date.now() }),
|
|
637
752
|
writeRawResponse(raw)
|
|
@@ -648,7 +763,8 @@ async function restoreStoredModels(context) {
|
|
|
648
763
|
const stored = await context.store.read();
|
|
649
764
|
if (!stored || stored.models.length === 0)
|
|
650
765
|
return;
|
|
651
|
-
const
|
|
766
|
+
const suppress = getSuppressedModels();
|
|
767
|
+
const models = stored.models.filter((m) => !isModelSuppressed({ id: m.id, name: m.name }, suppress));
|
|
652
768
|
currentModels = models;
|
|
653
769
|
log("refreshModels: restored from store", { count: models.length });
|
|
654
770
|
return models;
|