@mcowger/opencode-plexus 1.1.0 → 1.1.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.
Files changed (2) hide show
  1. package/dist/index.js +28 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -16,6 +16,7 @@ var PLACEHOLDER_MODEL_ID = "plexus-unconfigured";
16
16
 
17
17
  // ../plexus-models/src/convert.ts
18
18
  var REASONING_PARAMS = new Set(["reasoning", "include_reasoning", "reasoning_effort"]);
19
+ 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;
19
20
  var API_DIALECT_MAP = {
20
21
  chat_completions: "openai-completions",
21
22
  "openai-completions": "openai-completions",
@@ -48,6 +49,21 @@ function adjustBaseUrl(baseUrl, preferredApi) {
48
49
  return stripped;
49
50
  }
50
51
  }
52
+ function isChatModel(model) {
53
+ if (!model.id)
54
+ return false;
55
+ const outputModalities = model.architecture?.output_modalities;
56
+ if (outputModalities !== undefined && !outputModalities.includes("text"))
57
+ return false;
58
+ const modality = model.architecture?.modality;
59
+ if (modality?.includes("->")) {
60
+ const output = modality.split("->").at(-1) ?? "";
61
+ if (!output.toLowerCase().includes("text"))
62
+ return false;
63
+ }
64
+ const apiHints = Array.isArray(model.preferred_api) ? model.preferred_api.join(" ") : model.preferred_api ?? "";
65
+ return !NON_CHAT_PATTERN.test(`${model.id} ${model.name ?? ""} ${apiHints}`);
66
+ }
51
67
  var DEFAULT_MODELS_FETCH_TIMEOUT_MS = 1e4;
52
68
  async function fetchPlexusModels(apiKey, modelsUrl, timeoutMs = DEFAULT_MODELS_FETCH_TIMEOUT_MS) {
53
69
  const controller = new AbortController;
@@ -87,13 +103,23 @@ function fallbackDir() {
87
103
  function getDir() {
88
104
  return fallbackDir();
89
105
  }
106
+ function filterCachedModels(models) {
107
+ return Object.fromEntries(Object.entries(models).filter(([, model]) => isChatModel({
108
+ id: model.id,
109
+ name: model.name,
110
+ architecture: {
111
+ input_modalities: model.modalities.input,
112
+ output_modalities: model.modalities.output
113
+ }
114
+ })));
115
+ }
90
116
  async function readCachedModels(_client) {
91
117
  try {
92
118
  const dir = getDir();
93
119
  const content = await readFile(join(dir, CACHE_FILE), "utf8");
94
120
  const parsed = JSON.parse(content);
95
121
  if (parsed && typeof parsed.models === "object" && !Array.isArray(parsed.models)) {
96
- return parsed.models;
122
+ return filterCachedModels(parsed.models);
97
123
  }
98
124
  return null;
99
125
  } catch {
@@ -296,7 +322,6 @@ function buildInputModalities(model) {
296
322
  const mapped = raw.map(mapModality).filter((m) => m !== null);
297
323
  return mapped.length > 0 ? [...new Set(mapped)] : ["text"];
298
324
  }
299
- var NON_CHAT_ID_PATTERN = /embedding|embed|tts|whisper|image-[0-9]|image\b.*gen|diffusion|dall-e|stable-diff|sdxl|dream/i;
300
325
  function buildOutputModalities(model) {
301
326
  const raw = model.architecture?.output_modalities;
302
327
  if (raw !== undefined) {
@@ -305,14 +330,12 @@ function buildOutputModalities(model) {
305
330
  const mapped = raw.map(mapModality).filter((m) => m !== null);
306
331
  return mapped.length > 0 ? [...new Set(mapped)] : ["text"];
307
332
  }
308
- if (NON_CHAT_ID_PATTERN.test(model.id))
309
- return null;
310
333
  return ["text"];
311
334
  }
312
335
  function buildModels(models, baseURL) {
313
336
  const result = {};
314
337
  for (const m of models) {
315
- if (!m.id)
338
+ if (!isChatModel(m))
316
339
  continue;
317
340
  const outputModalities = buildOutputModalities(m);
318
341
  if (outputModalities === null)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcowger/opencode-plexus",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "OpenCode plugin: Plexus provider with dynamic model discovery",
5
5
  "type": "module",
6
6
  "module": "./dist/index.js",