@mcowger/pi-plexus 1.0.4 → 1.1.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 CHANGED
@@ -227,8 +227,10 @@ Models with a falsy `id` are skipped. Missing metadata falls back to safe defaul
227
227
 
228
228
  ## Adapter behavior
229
229
 
230
- - **pi** refreshes on startup, extension reload, and through `/plexus refresh`. It accepts either root URLs or URLs ending in `/v1` and normalizes them before calling Plexus.
230
+ - **pi** refreshes on session start and through `/plexus refresh`. It accepts either root URLs or URLs ending in `/v1` and normalizes them before calling Plexus.
231
231
  - **OpenCode** seeds the provider from cache or a placeholder model during config loading, then performs live discovery through the `provider.models` hook. If Plexus is slow or unavailable, OpenCode uses the cache and lets the refresh continue in the background.
232
+ - OpenCode models retain their upstream model ID, SDK dialect, release date, and reasoning metadata so OpenCode can generate its native GPT, Claude, Gemini, and OpenAI-compatible variants and apply its current request transforms. DeepSeek models also preserve `reasoning_content` across tool-call turns.
233
+ - OpenCode uses a 250K-token context window when Plexus supplies no context metadata; its output fallback remains 20% of that window.
232
234
  - Both adapters convert Plexus's per-token base and tier rates to the per-million-token units expected by their host.
233
235
 
234
236
  ## Development
package/dist/extension.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  // ../plexus-models/src/convert.ts
3
3
  var REASONING_PARAMS = new Set(["reasoning", "include_reasoning", "reasoning_effort"]);
4
- var NON_CHAT_ID_PATTERN = /embedding|embed|tts|whisper|image-[0-9]|image\b.*gen|diffusion|dall-e|stable-diff|sdxl|dream/i;
4
+ 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;
5
5
  var API_DIALECT_MAP = {
6
6
  chat_completions: "openai-completions",
7
7
  "openai-completions": "openai-completions",
@@ -45,15 +45,6 @@ function mapInputModalities(model) {
45
45
  }
46
46
  return result.length > 0 ? result : ["text"];
47
47
  }
48
- function isChatModel(model) {
49
- const inputModalities = model.architecture?.input_modalities;
50
- if (inputModalities !== undefined && !inputModalities.includes("text"))
51
- return false;
52
- const outputModalities = model.architecture?.output_modalities;
53
- if (outputModalities !== undefined)
54
- return outputModalities.includes("text");
55
- return !NON_CHAT_ID_PATTERN.test(model.id);
56
- }
57
48
  function inferReasoning(model) {
58
49
  const params = model.supported_parameters;
59
50
  if (!params)
@@ -123,10 +114,25 @@ function convertToDescriptor(raw, baseUrl) {
123
114
  descriptor.piOptions = raw.pi_options;
124
115
  return descriptor;
125
116
  }
117
+ function isChatModel(model) {
118
+ if (!model.id)
119
+ return false;
120
+ const outputModalities = model.architecture?.output_modalities;
121
+ if (outputModalities !== undefined && !outputModalities.includes("text"))
122
+ return false;
123
+ const modality = model.architecture?.modality;
124
+ if (modality?.includes("->")) {
125
+ const output = modality.split("->").at(-1) ?? "";
126
+ if (!output.toLowerCase().includes("text"))
127
+ return false;
128
+ }
129
+ const apiHints = Array.isArray(model.preferred_api) ? model.preferred_api.join(" ") : model.preferred_api ?? "";
130
+ return !NON_CHAT_PATTERN.test(`${model.id} ${model.name ?? ""} ${apiHints}`);
131
+ }
126
132
  function convertDescriptors(models, baseUrl) {
127
133
  const result = [];
128
134
  for (const m of models) {
129
- if (!m.id || !isChatModel(m))
135
+ if (!isChatModel(m))
130
136
  continue;
131
137
  result.push(convertToDescriptor(m, baseUrl));
132
138
  }
@@ -409,12 +415,12 @@ async function writeLogLine(message, data) {
409
415
  }
410
416
 
411
417
  // src/mapper.ts
412
- import { getModel } from "@earendil-works/pi-ai/compat";
418
+ import { getBuiltinModel } from "@earendil-works/pi-ai/providers/all";
413
419
  function descriptorToPiModel(descriptor) {
414
420
  let builtinModel;
415
421
  if (descriptor.piProvider && descriptor.piModel) {
416
422
  try {
417
- builtinModel = getModel(descriptor.piProvider, descriptor.piModel);
423
+ builtinModel = getBuiltinModel(descriptor.piProvider, descriptor.piModel);
418
424
  } catch {
419
425
  builtinModel = undefined;
420
426
  }
@@ -465,19 +471,11 @@ function descriptorToPiModel(descriptor) {
465
471
  var PROVIDER_NAME = "plexus";
466
472
  var PROVIDER_API_KEY_TEMPLATE = "${PLEXUS_API_KEY}";
467
473
  var PLEXUS_CREDENTIAL_EXPIRES_AT = 253402300799000;
468
- function getPlexusModelBaseUrl(baseUrl, api) {
469
- const normalized = baseUrl.trim().replace(/\/+$/, "");
470
- const apiBase = normalized.endsWith("/v1") ? normalized : `${normalized}/v1`;
471
- return adjustBaseUrl(apiBase, api);
472
- }
473
- function shouldRefreshModels(reason) {
474
- return reason === "startup" || reason === "reload";
475
- }
476
474
  var currentModels = [];
477
475
  function plexusExtension(pi) {
478
476
  const cached = readCachedModelsSync();
479
477
  const startupBaseUrl = getBaseUrl() ?? "http://localhost/v1";
480
- const startupModels = cached?.models.filter(isChatModel).map(descriptorToPiModel) ?? [];
478
+ const startupModels = cached?.models.map(descriptorToPiModel) ?? [];
481
479
  log("startup", {
482
480
  cachedModelCount: startupModels.length,
483
481
  startupBaseUrl
@@ -491,11 +489,7 @@ function plexusExtension(pi) {
491
489
  oauth: createPlexusLoginProvider(pi)
492
490
  });
493
491
  currentModels = startupModels;
494
- pi.on("session_start", async (event, ctx) => {
495
- if (!shouldRefreshModels(event.reason)) {
496
- log("session_start: skipping refresh", { reason: event.reason });
497
- return;
498
- }
492
+ pi.on("session_start", async (_event, ctx) => {
499
493
  const apiKey = await ctx.modelRegistry.authStorage.getApiKey(PROVIDER_NAME) ?? getEnvApiKey();
500
494
  const baseUrl = getBaseUrl();
501
495
  log("session_start", { hasApiKey: !!apiKey, baseUrl });
@@ -554,7 +548,8 @@ function createPlexusLoginProvider(pi) {
554
548
  const baseUrl = credentials.plexusBaseUrl;
555
549
  if (!baseUrl)
556
550
  return models;
557
- return models.map((model) => model.provider === PROVIDER_NAME ? { ...model, baseUrl: getPlexusModelBaseUrl(baseUrl, model.api) } : model);
551
+ const apiBase = baseUrl.trim().replace(/\/+$/, "").endsWith("/v1") ? baseUrl.trim().replace(/\/+$/, "") : `${baseUrl.trim().replace(/\/+$/, "")}/v1`;
552
+ return models.map((model) => model.provider === PROVIDER_NAME ? { ...model, baseUrl: apiBase } : model);
558
553
  }
559
554
  };
560
555
  }
@@ -615,7 +610,5 @@ async function trySetDefaultModel(pi, models) {
615
610
  log("trySetDefaultModel", { defaultModelId, ok });
616
611
  }
617
612
  export {
618
- shouldRefreshModels,
619
- getPlexusModelBaseUrl,
620
613
  plexusExtension as default
621
614
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcowger/pi-plexus",
3
- "version": "1.0.4",
3
+ "version": "1.1.1",
4
4
  "description": "Plexus AI proxy plugin for the pi coding agent",
5
5
  "type": "module",
6
6
  "files": [