@mcowger/pi-plexus 1.13.0 → 1.13.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.
Files changed (2) hide show
  1. package/dist/extension.js +145 -8
  2. package/package.json +1 -1
package/dist/extension.js CHANGED
@@ -6891,19 +6891,153 @@ function enforceMinimumOutputTokens(payload) {
6891
6891
  changed = true;
6892
6892
  }
6893
6893
  }
6894
- const generationConfig = next.generationConfig;
6895
- if (generationConfig && typeof generationConfig === "object" && !Array.isArray(generationConfig)) {
6896
- const maxOutputTokens = generationConfig.maxOutputTokens;
6897
- if (typeof maxOutputTokens === "number" && Number.isFinite(maxOutputTokens) && maxOutputTokens < MINIMUM_OUTPUT_TOKENS) {
6898
- next.generationConfig = {
6899
- ...generationConfig,
6900
- maxOutputTokens: MINIMUM_OUTPUT_TOKENS
6894
+ for (const configKey of ["generationConfig", "config"]) {
6895
+ const generationConfig = next[configKey];
6896
+ if (generationConfig && typeof generationConfig === "object" && !Array.isArray(generationConfig)) {
6897
+ const maxOutputTokens = generationConfig.maxOutputTokens;
6898
+ if (typeof maxOutputTokens === "number" && Number.isFinite(maxOutputTokens) && maxOutputTokens < MINIMUM_OUTPUT_TOKENS) {
6899
+ next[configKey] = {
6900
+ ...generationConfig,
6901
+ maxOutputTokens: MINIMUM_OUTPUT_TOKENS
6902
+ };
6903
+ changed = true;
6904
+ }
6905
+ }
6906
+ }
6907
+ return changed ? next : payload;
6908
+ }
6909
+ var EXTENDED_THINKING_LEVELS = [
6910
+ "off",
6911
+ "minimal",
6912
+ "low",
6913
+ "medium",
6914
+ "high",
6915
+ "xhigh",
6916
+ "max"
6917
+ ];
6918
+ var GOOGLE_THINKING_LEVELS = {
6919
+ minimal: "MINIMAL",
6920
+ low: "LOW",
6921
+ medium: "MEDIUM",
6922
+ high: "HIGH"
6923
+ };
6924
+ function getGeminiMajorVersion(modelId) {
6925
+ const match = modelId.toLowerCase().match(/^gemini(?:-live)?-(\d+)/);
6926
+ if (!match?.[1])
6927
+ return;
6928
+ return Number.parseInt(match[1], 10);
6929
+ }
6930
+ function usesGoogleThinkingLevel(model) {
6931
+ if (model.thinkingLevelMap && EXTENDED_THINKING_LEVELS.some((level) => level !== "off" && typeof model.thinkingLevelMap?.[level] === "string")) {
6932
+ return true;
6933
+ }
6934
+ const id = model.id.toLowerCase();
6935
+ const majorVersion = getGeminiMajorVersion(id);
6936
+ return majorVersion !== undefined && majorVersion >= 3 || id === "gemini-flash-latest" || id === "gemini-flash-lite-latest" || /gemma-?4/.test(id);
6937
+ }
6938
+ function getSupportedThinkingLevelsForModel(model) {
6939
+ if (!model.reasoning)
6940
+ return ["off"];
6941
+ return EXTENDED_THINKING_LEVELS.filter((level) => {
6942
+ const mapped = model.thinkingLevelMap?.[level];
6943
+ if (mapped === null)
6944
+ return false;
6945
+ if (level === "xhigh" || level === "max")
6946
+ return mapped !== undefined;
6947
+ return true;
6948
+ });
6949
+ }
6950
+ function clampModelThinkingLevel(model, level) {
6951
+ const availableLevels = getSupportedThinkingLevelsForModel(model);
6952
+ if (availableLevels.includes(level))
6953
+ return level;
6954
+ const requestedIndex = EXTENDED_THINKING_LEVELS.indexOf(level);
6955
+ if (requestedIndex === -1)
6956
+ return availableLevels[0] ?? "off";
6957
+ for (let i = requestedIndex;i < EXTENDED_THINKING_LEVELS.length; i++) {
6958
+ const candidate = EXTENDED_THINKING_LEVELS[i];
6959
+ if (candidate && availableLevels.includes(candidate))
6960
+ return candidate;
6961
+ }
6962
+ for (let i = requestedIndex - 1;i >= 0; i--) {
6963
+ const candidate = EXTENDED_THINKING_LEVELS[i];
6964
+ if (candidate && availableLevels.includes(candidate))
6965
+ return candidate;
6966
+ }
6967
+ return availableLevels[0] ?? "off";
6968
+ }
6969
+ function toGoogleThinkingLevel(model, level) {
6970
+ const clamped = clampModelThinkingLevel(model, level);
6971
+ if (clamped === "off")
6972
+ return;
6973
+ const mapped = model.thinkingLevelMap?.[clamped];
6974
+ const resolved = (typeof mapped === "string" ? mapped : clamped).trim().toLowerCase();
6975
+ return GOOGLE_THINKING_LEVELS[resolved];
6976
+ }
6977
+ function normalizeThinkingConfigObject(thinkingConfig, model, thinkingLevel) {
6978
+ if (thinkingConfig.thinkingLevel !== undefined)
6979
+ return thinkingConfig;
6980
+ if (thinkingConfig.thinkingBudget === -1) {
6981
+ const effectiveLevel = thinkingLevel && thinkingLevel !== "off" ? thinkingLevel : "high";
6982
+ const googleLevel = toGoogleThinkingLevel(model, effectiveLevel);
6983
+ if (!googleLevel)
6984
+ return thinkingConfig;
6985
+ const { thinkingBudget: _thinkingBudget, ...rest } = thinkingConfig;
6986
+ return {
6987
+ ...rest,
6988
+ thinkingLevel: googleLevel
6989
+ };
6990
+ }
6991
+ if (thinkingConfig.thinkingBudget === 0) {
6992
+ const googleLevel = toGoogleThinkingLevel(model, "off");
6993
+ if (!googleLevel)
6994
+ return thinkingConfig;
6995
+ const { thinkingBudget: _thinkingBudget, ...rest } = thinkingConfig;
6996
+ return {
6997
+ ...rest,
6998
+ thinkingLevel: googleLevel
6999
+ };
7000
+ }
7001
+ return thinkingConfig;
7002
+ }
7003
+ function normalizeGoogleThinkingConfig(payload, model, thinkingLevel) {
7004
+ if (!payload || typeof payload !== "object" || Array.isArray(payload))
7005
+ return payload;
7006
+ if (!model?.reasoning)
7007
+ return payload;
7008
+ if (model.api !== "google-generative-ai" && model.api !== "google-vertex")
7009
+ return payload;
7010
+ if (!usesGoogleThinkingLevel(model))
7011
+ return payload;
7012
+ const next = { ...payload };
7013
+ let changed = false;
7014
+ for (const configKey of ["config", "generationConfig"]) {
7015
+ const container = next[configKey];
7016
+ if (!container || typeof container !== "object" || Array.isArray(container))
7017
+ continue;
7018
+ const containerRecord = container;
7019
+ const thinkingConfig = containerRecord.thinkingConfig;
7020
+ if (!thinkingConfig || typeof thinkingConfig !== "object" || Array.isArray(thinkingConfig)) {
7021
+ continue;
7022
+ }
7023
+ const normalized = normalizeThinkingConfigObject(thinkingConfig, model, thinkingLevel);
7024
+ if (normalized !== thinkingConfig) {
7025
+ next[configKey] = {
7026
+ ...containerRecord,
7027
+ thinkingConfig: normalized
6901
7028
  };
6902
7029
  changed = true;
6903
7030
  }
6904
7031
  }
6905
7032
  return changed ? next : payload;
6906
7033
  }
7034
+ function getSessionThinkingLevel(pi) {
7035
+ try {
7036
+ return pi.getThinkingLevel?.();
7037
+ } catch {
7038
+ return;
7039
+ }
7040
+ }
6907
7041
  function withAuthoritativeApiKeyEnv(provider, envName, getHeaderModels = () => []) {
6908
7042
  const apiKey = provider.auth.apiKey;
6909
7043
  if (!apiKey)
@@ -7083,7 +7217,8 @@ function plexusExtension(pi) {
7083
7217
  return;
7084
7218
  state.activeModel = ctx.model;
7085
7219
  const withTier = injectServiceTier(event.payload, state.policy?.serviceTierFor(ctx.model));
7086
- const next = enforceMinimumOutputTokens(withTier);
7220
+ const withThinking = normalizeGoogleThinkingConfig(withTier, ctx.model, ctx.thinkingLevel ?? getSessionThinkingLevel(pi));
7221
+ const next = enforceMinimumOutputTokens(withThinking);
7087
7222
  return next === event.payload ? undefined : next;
7088
7223
  });
7089
7224
  log("startup", {
@@ -7405,6 +7540,8 @@ export {
7405
7540
  createPolicyHost,
7406
7541
  plexusExtension as default,
7407
7542
  enforceMinimumOutputTokens,
7543
+ normalizeGoogleThinkingConfig,
7408
7544
  serviceTierPolicyFromApiModel,
7545
+ usesGoogleThinkingLevel,
7409
7546
  withAuthoritativeApiKeyEnv
7410
7547
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcowger/pi-plexus",
3
- "version": "1.13.0",
3
+ "version": "1.13.1",
4
4
  "description": "Plexus AI proxy plugin for the pi coding agent",
5
5
  "type": "module",
6
6
  "files": [