@mcowger/pi-plexus 1.4.1 → 1.4.3

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/extension.js +43 -4
  2. package/package.json +1 -1
package/dist/extension.js CHANGED
@@ -482,13 +482,20 @@ var getModelsCachePath = () => join2(getCacheDir(), "plexus-models-cache.json");
482
482
  var getRawResponsePath = () => join2(getCacheDir(), "plexus-models-response.json");
483
483
  var getEtagPath = () => join2(getCacheDir(), "plexus-models-etag.txt");
484
484
  var getModelsStorePath = () => join2(getAgentDir2(), "models-store.json");
485
+ function isPlexusModelDescriptor(value) {
486
+ if (!value || typeof value !== "object" || Array.isArray(value))
487
+ return false;
488
+ const model = value;
489
+ const cost = model["cost"];
490
+ 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";
491
+ }
485
492
  function parseCacheData(raw) {
486
493
  try {
487
494
  const parsed = JSON.parse(raw);
488
495
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
489
496
  return null;
490
497
  const obj = parsed;
491
- if (!Array.isArray(obj["models"]))
498
+ if (!Array.isArray(obj["models"]) || !obj["models"].every(isPlexusModelDescriptor))
492
499
  return null;
493
500
  return {
494
501
  models: obj["models"],
@@ -609,6 +616,7 @@ async function writeLogLine(message, data) {
609
616
 
610
617
  // src/mapper.ts
611
618
  import { getModel } from "@earendil-works/pi-ai/compat";
619
+ var MINIMUM_OUTPUT_TOKENS = 8192;
612
620
  function descriptorToPiModel(descriptor) {
613
621
  let builtinModel;
614
622
  if (descriptor.piProvider && descriptor.piModel) {
@@ -654,7 +662,7 @@ function descriptorToPiModel(descriptor) {
654
662
  input: descriptor.input,
655
663
  cost,
656
664
  contextWindow: descriptor.contextWindow,
657
- maxTokens: descriptor.maxTokens,
665
+ maxTokens: Math.max(descriptor.maxTokens, MINIMUM_OUTPUT_TOKENS),
658
666
  ...builtinModel?.thinkingLevelMap !== undefined ? { thinkingLevelMap: builtinModel.thinkingLevelMap } : {},
659
667
  ...builtinModel?.headers !== undefined ? { headers: builtinModel.headers } : {},
660
668
  ...compat !== undefined ? { compat } : {}
@@ -704,6 +712,34 @@ var PROVIDER_API_KEY_TEMPLATE = "${PLEXUS_API_KEY}";
704
712
  var PLEXUS_CREDENTIAL_EXPIRES_AT = 253402300799000;
705
713
  var PLACEHOLDER_BASE_URL = "http://localhost/v1";
706
714
  var currentModels = [];
715
+ function cachedDescriptorsToPiModels(descriptors, suppressPatterns) {
716
+ return descriptors.filter((descriptor) => !isModelSuppressed({ id: descriptor.id, name: descriptor.name }, suppressPatterns)).map(descriptorToPiModel);
717
+ }
718
+ function enforceMinimumOutputTokens(payload) {
719
+ if (!payload || typeof payload !== "object" || Array.isArray(payload))
720
+ return payload;
721
+ const next = { ...payload };
722
+ let changed = false;
723
+ for (const field of ["max_completion_tokens", "max_tokens", "max_output_tokens"]) {
724
+ const value = next[field];
725
+ if (typeof value === "number" && Number.isFinite(value) && value < MINIMUM_OUTPUT_TOKENS) {
726
+ next[field] = MINIMUM_OUTPUT_TOKENS;
727
+ changed = true;
728
+ }
729
+ }
730
+ const generationConfig = next["generationConfig"];
731
+ if (generationConfig && typeof generationConfig === "object" && !Array.isArray(generationConfig)) {
732
+ const maxOutputTokens = generationConfig["maxOutputTokens"];
733
+ if (typeof maxOutputTokens === "number" && Number.isFinite(maxOutputTokens) && maxOutputTokens < MINIMUM_OUTPUT_TOKENS) {
734
+ next["generationConfig"] = {
735
+ ...generationConfig,
736
+ maxOutputTokens: MINIMUM_OUTPUT_TOKENS
737
+ };
738
+ changed = true;
739
+ }
740
+ }
741
+ return changed ? next : payload;
742
+ }
707
743
  function plexusExtension(pi) {
708
744
  const envApiKey = getEnvApiKey();
709
745
  const startupBaseUrl = getBaseUrl();
@@ -711,11 +747,12 @@ function plexusExtension(pi) {
711
747
  const cached = readCachedModelsSync();
712
748
  let startupModels = [];
713
749
  if (cached?.models && cached.models.length > 0) {
714
- startupModels = convertDescriptors(cached.models, startupBaseUrl ?? PLACEHOLDER_BASE_URL, suppressPatterns).map(descriptorToPiModel);
750
+ startupModels = cachedDescriptorsToPiModels(cached.models, suppressPatterns);
715
751
  } else if (cached?.piModels && cached.piModels.length > 0) {
716
752
  startupModels = cached.piModels.filter((m) => !isModelSuppressed({ id: m.id, name: m.name }, suppressPatterns));
717
753
  }
718
754
  currentModels = startupModels;
755
+ pi.on("before_provider_request", (event, ctx) => ctx.model?.provider === PROVIDER_NAME ? enforceMinimumOutputTokens(event.payload) : undefined);
719
756
  log("startup", {
720
757
  baseUrl: startupBaseUrl,
721
758
  hasEnvApiKey: !!envApiKey,
@@ -922,5 +959,7 @@ async function handleSetDefaultModel(pi, ctx, requestedModelId) {
922
959
  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");
923
960
  }
924
961
  export {
925
- plexusExtension as default
962
+ cachedDescriptorsToPiModels,
963
+ plexusExtension as default,
964
+ enforceMinimumOutputTokens
926
965
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcowger/pi-plexus",
3
- "version": "1.4.1",
3
+ "version": "1.4.3",
4
4
  "description": "Plexus AI proxy plugin for the pi coding agent",
5
5
  "type": "module",
6
6
  "files": [