@m5kdev/commons 0.27.2 → 0.28.0

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.
@@ -141,20 +141,21 @@ function rankModels(models, profile, category, weights) {
141
141
  };
142
142
  }).sort((a, b) => b.score - a.score);
143
143
  }
144
- function getSortedRankedModel(models, category = "chat", weights, tokenProfile) {
145
- return rankModels(models, typeof tokenProfile === "string" ? {
144
+ function getSortedRankedModel(models, category = "chat", weights, tokenProfile, filter) {
145
+ const rankedModels = rankModels(models, typeof tokenProfile === "string" ? {
146
146
  inputTokens: require_src_modules_ai_ai_constants.TOKEN_PRESETS[tokenProfile],
147
147
  outputTokens: require_src_modules_ai_ai_constants.TOKEN_PRESETS[tokenProfile]
148
148
  } : typeof tokenProfile === "number" ? {
149
149
  inputTokens: tokenProfile,
150
150
  outputTokens: tokenProfile
151
151
  } : tokenProfile ? tokenProfile : getDefaultTokenProfile(category), category, getDefaultWeights(weights));
152
+ return filter ? rankedModels.filter(filter) : rankedModels;
152
153
  }
153
- function getSortedRecommendedModels(category = "chat", weights, tokenProfile) {
154
- return getSortedRankedModel(require_src_modules_ai_ai_models_contsants.RANKED_MODELS, category, weights, tokenProfile);
154
+ function getSortedRecommendedModels(category = "chat", weights, tokenProfile, filter) {
155
+ return getSortedRankedModel(require_src_modules_ai_ai_models_contsants.RANKED_MODELS, category, weights, tokenProfile, filter);
155
156
  }
156
- function getSortedRecommendedModelIds(category = "chat", weights, tokenProfile) {
157
- return getSortedRankedModel(require_src_modules_ai_ai_models_contsants.RANKED_MODELS, category, weights, tokenProfile).map((model) => model.id);
157
+ function getSortedRecommendedModelIds(category = "chat", weights, tokenProfile, filter) {
158
+ return getSortedRankedModel(require_src_modules_ai_ai_models_contsants.RANKED_MODELS, category, weights, tokenProfile, filter).map((model) => model.id);
158
159
  }
159
160
  function arrayToPseudoXML(array, keys, name = "item") {
160
161
  return array.map((item) => `<${name}>${keys.map((key) => `<${String(key)}>${String(item[key])}</${String(key)}>`).join("\n")}</${name}>`).join("\n");
@@ -1 +1 @@
1
- {"version":3,"file":"ai.utils.cjs","names":["TOKEN_PRESETS","RANKED_MODELS"],"sources":["../../../../src/modules/ai/ai.utils.ts"],"sourcesContent":["import { RANKED_MODELS, TOKEN_PRESETS } from \"./ai.constants\";\r\nimport type { Category, RankedModel, SortType, TokenProfile, TokenSize } from \"./ai.types\";\r\n\r\nexport function getDefaultTokenProfile(category: Category): TokenProfile {\r\n switch (category) {\r\n case \"structured_output\":\r\n return { inputTokens: TOKEN_PRESETS.lg, outputTokens: TOKEN_PRESETS.md };\r\n case \"creative\":\r\n return { inputTokens: TOKEN_PRESETS.md, outputTokens: TOKEN_PRESETS.lg };\r\n case \"research\":\r\n return { inputTokens: TOKEN_PRESETS.xl, outputTokens: TOKEN_PRESETS.xl };\r\n case \"chat\":\r\n return { inputTokens: TOKEN_PRESETS.sm, outputTokens: TOKEN_PRESETS.md };\r\n case \"tool_use\":\r\n return { inputTokens: TOKEN_PRESETS.md, outputTokens: TOKEN_PRESETS.sm };\r\n case \"planning\":\r\n return { inputTokens: TOKEN_PRESETS.lg, outputTokens: TOKEN_PRESETS.lg };\r\n case \"classification\":\r\n return { inputTokens: TOKEN_PRESETS.sm, outputTokens: TOKEN_PRESETS.xs };\r\n default:\r\n return { inputTokens: TOKEN_PRESETS.md, outputTokens: TOKEN_PRESETS.md };\r\n }\r\n}\r\n\r\nexport function getDefaultWeights(\r\n weights?: SortType | [SortType, SortType, SortType] | [number, number, number]\r\n): [number, number, number] {\r\n if (Array.isArray(weights)) {\r\n return weights.every((weight) => typeof weight === \"number\")\r\n ? weights\r\n : weights.reduce<[number, number, number]>(\r\n (acc, weight, index) => {\r\n switch (weight) {\r\n case \"quality\":\r\n acc[0] = index === 0 ? 50 : index === 1 ? 30 : 20;\r\n break;\r\n case \"price\":\r\n acc[1] = index === 0 ? 50 : index === 1 ? 30 : 20;\r\n break;\r\n case \"speed\":\r\n acc[2] = index === 0 ? 50 : index === 1 ? 30 : 20;\r\n break;\r\n }\r\n return acc;\r\n },\r\n [20, 50, 30]\r\n );\r\n }\r\n switch (weights) {\r\n case \"quality\":\r\n return [50, 30, 20];\r\n case \"price\":\r\n return [20, 50, 30];\r\n case \"speed\":\r\n return [20, 30, 50];\r\n default:\r\n return [50, 25, 25];\r\n }\r\n}\r\n\r\nexport function weightsToPriceSensitivity(weights: [number, number, number]): number {\r\n const [qualityWeight, priceWeight, speedWeight] = weights;\r\n\r\n const total = qualityWeight + priceWeight + speedWeight;\r\n\r\n if (total <= 0) {\r\n return 1;\r\n }\r\n\r\n const normalizedPriceWeight = priceWeight / total;\r\n\r\n const min = 0.55; // very price-sensitive\r\n const max = 1.75; // price is soft / secondary\r\n\r\n // Higher price weight -> lower exponent -> stronger price penalty.\r\n const sensitivity = max - normalizedPriceWeight * (max - min);\r\n\r\n return Number(sensitivity.toFixed(3));\r\n}\r\n\r\nexport function addPriceScores(\r\n models: RankedModel[],\r\n profile: TokenProfile,\r\n priceSensitivity = 1\r\n): Array<RankedModel & { price: number; estimatedCost: number }> {\r\n const costs = models.map((model) => {\r\n return (\r\n (profile.inputTokens / 1_000_000) * model.inputCost +\r\n (profile.outputTokens / 1_000_000) * model.outputCost\r\n );\r\n });\r\n\r\n const cheapest = Math.min(...costs);\r\n const mostExpensive = Math.max(...costs);\r\n\r\n return models.map((model, index) => {\r\n const cost = costs[index];\r\n\r\n if (mostExpensive === cheapest) {\r\n return {\r\n ...model,\r\n estimatedCost: cost,\r\n price: 10,\r\n };\r\n }\r\n\r\n const safeCheapest = Math.max(cheapest, Number.EPSILON);\r\n const safeCost = Math.max(cost, Number.EPSILON);\r\n const safeMostExpensive = Math.max(mostExpensive, Number.EPSILON);\r\n\r\n const logMin = Math.log(safeCheapest);\r\n const logMax = Math.log(safeMostExpensive);\r\n const logCost = Math.log(safeCost);\r\n\r\n const normalizedRaw = (logCost - logMin) / (logMax - logMin);\r\n\r\n // < 1 makes price matter less.\r\n // > 1 makes price matter more.\r\n const normalized = normalizedRaw ** priceSensitivity;\r\n\r\n return {\r\n ...model,\r\n estimatedCost: cost,\r\n price: Math.round(10 - normalized * 9),\r\n };\r\n });\r\n}\r\n\r\nfunction clampScore(value: number): number {\r\n return Math.max(1, Math.min(10, value));\r\n}\r\n\r\nfunction shapeScoreByWeight(value: number, weight: number, maxWeight: number): number {\r\n const score = clampScore(value);\r\n const normalized = score / 10;\r\n\r\n if (maxWeight <= 0 || weight <= 0) {\r\n return 0;\r\n }\r\n\r\n const importance = (weight / maxWeight) ** 2;\r\n const expanded = normalized ** 2 * 10;\r\n const compressed = 8 + normalized * 2;\r\n return compressed + (expanded - compressed) * importance;\r\n}\r\n\r\nexport function rankModels(\r\n models: RankedModel[],\r\n profile: TokenProfile,\r\n category: Category,\r\n weights: [number, number, number]\r\n) {\r\n const scoredModels = addPriceScores(models, profile, weightsToPriceSensitivity(weights));\r\n\r\n const [qualityWeight, priceWeight, speedWeight] = weights;\r\n const maxWeight = Math.max(qualityWeight, priceWeight, speedWeight);\r\n\r\n return scoredModels\r\n .map((model) => {\r\n const qualityScore = shapeScoreByWeight(model.quality[category], qualityWeight, maxWeight);\r\n\r\n const priceScore = shapeScoreByWeight(model.price, priceWeight, maxWeight);\r\n\r\n const speedScore = shapeScoreByWeight(model.speed, speedWeight, maxWeight);\r\n\r\n return {\r\n ...model,\r\n score: qualityScore * qualityWeight + priceScore * priceWeight + speedScore * speedWeight,\r\n };\r\n })\r\n .sort((a, b) => b.score - a.score);\r\n}\r\n\r\nexport function getSortedRankedModel(\r\n models: RankedModel[],\r\n category: Category = \"chat\",\r\n weights?: SortType | [SortType, SortType, SortType] | [number, number, number],\r\n tokenProfile?: TokenProfile | number | TokenSize\r\n): RankedModel[] {\r\n const profile =\r\n typeof tokenProfile === \"string\"\r\n ? {\r\n inputTokens: TOKEN_PRESETS[tokenProfile as TokenSize],\r\n outputTokens: TOKEN_PRESETS[tokenProfile as TokenSize],\r\n }\r\n : typeof tokenProfile === \"number\"\r\n ? { inputTokens: tokenProfile, outputTokens: tokenProfile }\r\n : tokenProfile\r\n ? (tokenProfile as TokenProfile)\r\n : getDefaultTokenProfile(category);\r\n return rankModels(models, profile, category, getDefaultWeights(weights));\r\n}\r\n\r\nexport function getSortedRecommendedModels(\r\n category: Category = \"chat\",\r\n weights?: SortType | [SortType, SortType, SortType] | [number, number, number],\r\n tokenProfile?: TokenProfile | number | TokenSize\r\n): RankedModel[] {\r\n return getSortedRankedModel(RANKED_MODELS, category, weights, tokenProfile);\r\n}\r\n\r\nexport function getSortedRecommendedModelIds(\r\n category: Category = \"chat\",\r\n weights?: SortType | [SortType, SortType, SortType] | [number, number, number],\r\n tokenProfile?: TokenProfile | number | TokenSize\r\n): string[] {\r\n return getSortedRankedModel(RANKED_MODELS, category, weights, tokenProfile).map(\r\n (model) => model.id\r\n );\r\n}\r\n\r\nexport function arrayToPseudoXML<T extends Record<string, unknown>>(\r\n array: readonly T[],\r\n keys: readonly (keyof T)[],\r\n name = \"item\"\r\n): string {\r\n return array\r\n .map(\r\n (item) =>\r\n `<${name}>${keys\r\n .map((key) => `<${String(key)}>${String(item[key])}</${String(key)}>`)\r\n .join(\"\\n\")}</${name}>`\r\n )\r\n .join(\"\\n\");\r\n}\r\n"],"mappings":";;;;AAGA,SAAgB,uBAAuB,UAAkC;AACvE,SAAQ,UAAR;EACE,KAAK,oBACH,QAAO;GAAE,aAAaA,oCAAAA,cAAc;GAAI,cAAcA,oCAAAA,cAAc;GAAI;EAC1E,KAAK,WACH,QAAO;GAAE,aAAaA,oCAAAA,cAAc;GAAI,cAAcA,oCAAAA,cAAc;GAAI;EAC1E,KAAK,WACH,QAAO;GAAE,aAAaA,oCAAAA,cAAc;GAAI,cAAcA,oCAAAA,cAAc;GAAI;EAC1E,KAAK,OACH,QAAO;GAAE,aAAaA,oCAAAA,cAAc;GAAI,cAAcA,oCAAAA,cAAc;GAAI;EAC1E,KAAK,WACH,QAAO;GAAE,aAAaA,oCAAAA,cAAc;G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Y;AAEnE,QAAO,aACJ,KAAK,UAAU;EACd,MAAM,eAAe,mBAAmB,MAAM,QAAQ,WAAW,eAAe,UAAU;EAE1F,MAAM,aAAa,mBAAmB,MAAM,OAAO,aAAa,UAAU;EAE1E,MAAM,aAAa,mBAAmB,MAAM,OAAO,aAAa,UAAU;AAE1E,SAAO;GACL,GAAG;GACH,OAAO,eAAe,gBAAgB,aAAa,cAAc,aAAa;GAC/E;GACD,CACD,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,MAAM;;AAGtC,SAAgB,qBACd,QACA,WAAqB,QACrB,SACA,cACe;AAYf,QAAO,WAAW,QAVhB,OAAO,iBAAiB,WACpB;EACE,aAAaA,oCAAAA,cAAc;EAC3B,cAAcA,oCAAAA,cAAc;EAC7B,GACD,OAAO,iBAAiB,WACtB;EAAE,aAAa;EAAc,cAAc;EAAc,GACzD,eACG,eACD,uBAAuB,SAAS,EACP,UAAU,kBAAkB,QAAQ,CAAC;;AAG1E,SAAgB,2BACd,WAAqB,QACrB,SACA,cACe;AACf,QAAO,qBAAqBC,2CAAAA,eAAe,UAAU,SAAS,aAAa;;AAG7E,SAAgB,6BACd,WAAqB,QACrB,SACA,cACU;AACV,QAAO,qBAAqBA,2CAAAA,eAAe,UAAU,SAAS,aAAa,CAAC,KACzE,UAAU,MAAM,GAClB;;AAGH,SAAgB,iBACd,OACA,MACA,OAAO,QACC;AACR,QAAO,MACJ,KACE,SACC,IAAI,KAAK,GAAG,KACT,KAAK,QAAQ,IAAI,OAAO,IAAI,CAAC,GAAG,OAAO,KAAK,KAAK,CAAC,IAAI,OAAO,IAAI,CAAC,GAAG,CACrE,KAAK,KAAK,CAAC,IAAI,KAAK,GAC1B,CACA,KAAK,KAAK"}
1
+ {"version":3,"file":"ai.utils.cjs","names":["TOKEN_PRESETS","RANKED_MODELS"],"sources":["../../../../src/modules/ai/ai.utils.ts"],"sourcesContent":["import { RANKED_MODELS, TOKEN_PRESETS } from \"./ai.constants\";\r\nimport type { Category, RankedModel, SortType, TokenProfile, TokenSize } from \"./ai.types\";\r\n\r\nexport function getDefaultTokenProfile(category: Category): TokenProfile {\r\n switch (category) {\r\n case \"structured_output\":\r\n return { inputTokens: TOKEN_PRESETS.lg, outputTokens: TOKEN_PRESETS.md };\r\n case \"creative\":\r\n return { inputTokens: TOKEN_PRESETS.md, outputTokens: TOKEN_PRESETS.lg };\r\n case \"research\":\r\n return { inputTokens: TOKEN_PRESETS.xl, outputTokens: TOKEN_PRESETS.xl };\r\n case \"chat\":\r\n return { inputTokens: TOKEN_PRESETS.sm, outputTokens: TOKEN_PRESETS.md };\r\n case \"tool_use\":\r\n return { inputTokens: TOKEN_PRESETS.md, outputTokens: TOKEN_PRESETS.sm };\r\n case \"planning\":\r\n return { inputTokens: TOKEN_PRESETS.lg, outputTokens: TOKEN_PRESETS.lg };\r\n case \"classification\":\r\n return { inputTokens: TOKEN_PRESETS.sm, outputTokens: TOKEN_PRESETS.xs };\r\n default:\r\n return { inputTokens: TOKEN_PRESETS.md, outputTokens: TOKEN_PRESETS.md };\r\n }\r\n}\r\n\r\nexport function getDefaultWeights(\r\n weights?: SortType | [SortType, SortType, SortType] | [number, number, number]\r\n): [number, number, number] {\r\n if (Array.isArray(weights)) {\r\n return weights.every((weight) => typeof weight === \"number\")\r\n ? weights\r\n : weights.reduce<[number, number, number]>(\r\n (acc, weight, index) => {\r\n switch (weight) {\r\n case \"quality\":\r\n acc[0] = index === 0 ? 50 : index === 1 ? 30 : 20;\r\n break;\r\n case \"price\":\r\n acc[1] = index === 0 ? 50 : index === 1 ? 30 : 20;\r\n break;\r\n case \"speed\":\r\n acc[2] = index === 0 ? 50 : index === 1 ? 30 : 20;\r\n break;\r\n }\r\n return acc;\r\n },\r\n [20, 50, 30]\r\n );\r\n }\r\n switch (weights) {\r\n case \"quality\":\r\n return [50, 30, 20];\r\n case \"price\":\r\n return [20, 50, 30];\r\n case \"speed\":\r\n return [20, 30, 50];\r\n default:\r\n return [50, 25, 25];\r\n }\r\n}\r\n\r\nexport function weightsToPriceSensitivity(weights: [number, number, number]): number {\r\n const [qualityWeight, priceWeight, speedWeight] = weights;\r\n\r\n const total = qualityWeight + priceWeight + speedWeight;\r\n\r\n if (total <= 0) {\r\n return 1;\r\n }\r\n\r\n const normalizedPriceWeight = priceWeight / total;\r\n\r\n const min = 0.55; // very price-sensitive\r\n const max = 1.75; // price is soft / secondary\r\n\r\n // Higher price weight -> lower exponent -> stronger price penalty.\r\n const sensitivity = max - normalizedPriceWeight * (max - min);\r\n\r\n return Number(sensitivity.toFixed(3));\r\n}\r\n\r\nexport function addPriceScores(\r\n models: RankedModel[],\r\n profile: TokenProfile,\r\n priceSensitivity = 1\r\n): Array<RankedModel & { price: number; estimatedCost: number }> {\r\n const costs = models.map((model) => {\r\n return (\r\n (profile.inputTokens / 1_000_000) * model.inputCost +\r\n (profile.outputTokens / 1_000_000) * model.outputCost\r\n );\r\n });\r\n\r\n const cheapest = Math.min(...costs);\r\n const mostExpensive = Math.max(...costs);\r\n\r\n return models.map((model, index) => {\r\n const cost = costs[index];\r\n\r\n if (mostExpensive === cheapest) {\r\n return {\r\n ...model,\r\n estimatedCost: cost,\r\n price: 10,\r\n };\r\n }\r\n\r\n const safeCheapest = Math.max(cheapest, Number.EPSILON);\r\n const safeCost = Math.max(cost, Number.EPSILON);\r\n const safeMostExpensive = Math.max(mostExpensive, Number.EPSILON);\r\n\r\n const logMin = Math.log(safeCheapest);\r\n const logMax = Math.log(safeMostExpensive);\r\n const logCost = Math.log(safeCost);\r\n\r\n const normalizedRaw = (logCost - logMin) / (logMax - logMin);\r\n\r\n // < 1 makes price matter less.\r\n // > 1 makes price matter more.\r\n const normalized = normalizedRaw ** priceSensitivity;\r\n\r\n return {\r\n ...model,\r\n estimatedCost: cost,\r\n price: Math.round(10 - normalized * 9),\r\n };\r\n });\r\n}\r\n\r\nfunction clampScore(value: number): number {\r\n return Math.max(1, Math.min(10, value));\r\n}\r\n\r\nfunction shapeScoreByWeight(value: number, weight: number, maxWeight: number): number {\r\n const score = clampScore(value);\r\n const normalized = score / 10;\r\n\r\n if (maxWeight <= 0 || weight <= 0) {\r\n return 0;\r\n }\r\n\r\n const importance = (weight / maxWeight) ** 2;\r\n const expanded = normalized ** 2 * 10;\r\n const compressed = 8 + normalized * 2;\r\n return compressed + (expanded - compressed) * importance;\r\n}\r\n\r\nexport function rankModels(\r\n models: RankedModel[],\r\n profile: TokenProfile,\r\n category: Category,\r\n weights: [number, number, number]\r\n) {\r\n const scoredModels = addPriceScores(models, profile, weightsToPriceSensitivity(weights));\r\n\r\n const [qualityWeight, priceWeight, speedWeight] = weights;\r\n const maxWeight = Math.max(qualityWeight, priceWeight, speedWeight);\r\n\r\n return scoredModels\r\n .map((model) => {\r\n const qualityScore = shapeScoreByWeight(model.quality[category], qualityWeight, maxWeight);\r\n\r\n const priceScore = shapeScoreByWeight(model.price, priceWeight, maxWeight);\r\n\r\n const speedScore = shapeScoreByWeight(model.speed, speedWeight, maxWeight);\r\n\r\n return {\r\n ...model,\r\n score: qualityScore * qualityWeight + priceScore * priceWeight + speedScore * speedWeight,\r\n };\r\n })\r\n .sort((a, b) => b.score - a.score);\r\n}\r\n\r\nexport function getSortedRankedModel(\r\n models: RankedModel[],\r\n category: Category = \"chat\",\r\n weights?: SortType | [SortType, SortType, SortType] | [number, number, number],\r\n tokenProfile?: TokenProfile | number | TokenSize,\r\n filter?: (model: RankedModel) => boolean\r\n): RankedModel[] {\r\n const profile =\r\n typeof tokenProfile === \"string\"\r\n ? {\r\n inputTokens: TOKEN_PRESETS[tokenProfile as TokenSize],\r\n outputTokens: TOKEN_PRESETS[tokenProfile as TokenSize],\r\n }\r\n : typeof tokenProfile === \"number\"\r\n ? { inputTokens: tokenProfile, outputTokens: tokenProfile }\r\n : tokenProfile\r\n ? (tokenProfile as TokenProfile)\r\n : getDefaultTokenProfile(category);\r\n const rankedModels = rankModels(models, profile, category, getDefaultWeights(weights));\r\n return filter ? rankedModels.filter(filter) : rankedModels;\r\n}\r\n\r\nexport function getSortedRecommendedModels(\r\n category: Category = \"chat\",\r\n weights?: SortType | [SortType, SortType, SortType] | [number, number, number],\r\n tokenProfile?: TokenProfile | number | TokenSize,\r\n filter?: (model: RankedModel) => boolean\r\n): RankedModel[] {\r\n return getSortedRankedModel(RANKED_MODELS, category, weights, tokenProfile, filter);\r\n}\r\n\r\nexport function getSortedRecommendedModelIds(\r\n category: Category = \"chat\",\r\n weights?: SortType | [SortType, SortType, SortType] | [number, number, number],\r\n tokenProfile?: TokenProfile | number | TokenSize,\r\n filter?: (model: RankedModel) => boolean\r\n): string[] {\r\n return getSortedRankedModel(RANKED_MODELS, category, weights, tokenProfile, filter).map(\r\n (model) => model.id\r\n );\r\n}\r\n\r\nexport function arrayToPseudoXML<T extends Record<string, unknown>>(\r\n array: readonly T[],\r\n keys: readonly (keyof T)[],\r\n name = \"item\"\r\n): string {\r\n return array\r\n .map(\r\n (item) =>\r\n `<${name}>${keys\r\n .map((key) => `<${String(key)}>${String(item[key])}</${String(key)}>`)\r\n .join(\"\\n\")}</${name}>`\r\n )\r\n .join(\"\\n\");\r\n}\r\n"],"mappings":";;;;AAGA,SAAgB,uBAAuB,UAAkC;AACvE,SAAQ,UAAR;EACE,KAAK,oBACH,QAAO;GAAE,aAAaA,oCAAAA,cAAc;GAAI,cAAcA,oCAAAA,cAAc;GAAI;EAC1E,KAAK,WACH,QAAO;GAAE,aAAaA,oCAAAA,cAAc;GAAI,cAAcA,oCAAAA,cAAc;GAAI;EAC1E,KAAK,WACH,QAAO;GAAE,aAAaA,oCAAAA,cAAc;GAAI,cAAcA,oCAAAA,cAAc;GAAI;EAC1E,KAAK,OACH,QAAO;GAAE,aAAaA,oCAAAA,cAAc;GAAI,cAAcA,oCAAAA,cAAc;GAAI;EAC1E,KAAK,WACH,QAAO;GAAE,aAAaA,oCAAAA,cAAc;GAAI,cAAcA,oCAAAA,cAAc;GAAI;EAC1E,KAAK,WACH,QAAO;GAAE,aAAaA,oCAAAA,cAAc;G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AAU;EAE1F,MAAM,aAAa,mBAAmB,MAAM,OAAO,aAAa,UAAU;EAE1E,MAAM,aAAa,mBAAmB,MAAM,OAAO,aAAa,UAAU;AAE1E,SAAO;GACL,GAAG;GACH,OAAO,eAAe,gBAAgB,aAAa,cAAc,aAAa;GAC/E;GACD,CACD,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,MAAM;;AAGtC,SAAgB,qBACd,QACA,WAAqB,QACrB,SACA,cACA,QACe;CAYf,MAAM,eAAe,WAAW,QAV9B,OAAO,iBAAiB,WACpB;EACE,aAAaA,oCAAAA,cAAc;EAC3B,cAAcA,oCAAAA,cAAc;EAC7B,GACD,OAAO,iBAAiB,WACtB;EAAE,aAAa;EAAc,cAAc;EAAc,GACzD,eACG,eACD,uBAAuB,SAAS,EACO,UAAU,kBAAkB,QAAQ,CAAC;AACtF,QAAO,SAAS,aAAa,OAAO,OAAO,GAAG;;AAGhD,SAAgB,2BACd,WAAqB,QACrB,SACA,cACA,QACe;AACf,QAAO,qBAAqBC,2CAAAA,eAAe,UAAU,SAAS,cAAc,OAAO;;AAGrF,SAAgB,6BACd,WAAqB,QACrB,SACA,cACA,QACU;AACV,QAAO,qBAAqBA,2CAAAA,eAAe,UAAU,SAAS,cAAc,OAAO,CAAC,KACjF,UAAU,MAAM,GAClB;;AAGH,SAAgB,iBACd,OACA,MACA,OAAO,QACC;AACR,QAAO,MACJ,KACE,SACC,IAAI,KAAK,GAAG,KACT,KAAK,QAAQ,IAAI,OAAO,IAAI,CAAC,GAAG,OAAO,KAAK,KAAK,CAAC,IAAI,OAAO,IAAI,CAAC,GAAG,CACrE,KAAK,KAAK,CAAC,IAAI,KAAK,GAC1B,CACA,KAAK,KAAK"}
@@ -18,9 +18,9 @@ declare function rankModels(models: RankedModel[], profile: TokenProfile, catego
18
18
  price: number;
19
19
  estimatedCost: number;
20
20
  }[];
21
- declare function getSortedRankedModel(models: RankedModel[], category?: Category, weights?: SortType | [SortType, SortType, SortType] | [number, number, number], tokenProfile?: TokenProfile | number | TokenSize): RankedModel[];
22
- declare function getSortedRecommendedModels(category?: Category, weights?: SortType | [SortType, SortType, SortType] | [number, number, number], tokenProfile?: TokenProfile | number | TokenSize): RankedModel[];
23
- declare function getSortedRecommendedModelIds(category?: Category, weights?: SortType | [SortType, SortType, SortType] | [number, number, number], tokenProfile?: TokenProfile | number | TokenSize): string[];
21
+ declare function getSortedRankedModel(models: RankedModel[], category?: Category, weights?: SortType | [SortType, SortType, SortType] | [number, number, number], tokenProfile?: TokenProfile | number | TokenSize, filter?: (model: RankedModel) => boolean): RankedModel[];
22
+ declare function getSortedRecommendedModels(category?: Category, weights?: SortType | [SortType, SortType, SortType] | [number, number, number], tokenProfile?: TokenProfile | number | TokenSize, filter?: (model: RankedModel) => boolean): RankedModel[];
23
+ declare function getSortedRecommendedModelIds(category?: Category, weights?: SortType | [SortType, SortType, SortType] | [number, number, number], tokenProfile?: TokenProfile | number | TokenSize, filter?: (model: RankedModel) => boolean): string[];
24
24
  declare function arrayToPseudoXML<T extends Record<string, unknown>>(array: readonly T[], keys: readonly (keyof T)[], name?: string): string;
25
25
  //#endregion
26
26
  export { addPriceScores, arrayToPseudoXML, getDefaultTokenProfile, getDefaultWeights, getSortedRankedModel, getSortedRecommendedModelIds, getSortedRecommendedModels, rankModels, weightsToPriceSensitivity };
@@ -18,9 +18,9 @@ declare function rankModels(models: RankedModel[], profile: TokenProfile, catego
18
18
  price: number;
19
19
  estimatedCost: number;
20
20
  }[];
21
- declare function getSortedRankedModel(models: RankedModel[], category?: Category, weights?: SortType | [SortType, SortType, SortType] | [number, number, number], tokenProfile?: TokenProfile | number | TokenSize): RankedModel[];
22
- declare function getSortedRecommendedModels(category?: Category, weights?: SortType | [SortType, SortType, SortType] | [number, number, number], tokenProfile?: TokenProfile | number | TokenSize): RankedModel[];
23
- declare function getSortedRecommendedModelIds(category?: Category, weights?: SortType | [SortType, SortType, SortType] | [number, number, number], tokenProfile?: TokenProfile | number | TokenSize): string[];
21
+ declare function getSortedRankedModel(models: RankedModel[], category?: Category, weights?: SortType | [SortType, SortType, SortType] | [number, number, number], tokenProfile?: TokenProfile | number | TokenSize, filter?: (model: RankedModel) => boolean): RankedModel[];
22
+ declare function getSortedRecommendedModels(category?: Category, weights?: SortType | [SortType, SortType, SortType] | [number, number, number], tokenProfile?: TokenProfile | number | TokenSize, filter?: (model: RankedModel) => boolean): RankedModel[];
23
+ declare function getSortedRecommendedModelIds(category?: Category, weights?: SortType | [SortType, SortType, SortType] | [number, number, number], tokenProfile?: TokenProfile | number | TokenSize, filter?: (model: RankedModel) => boolean): string[];
24
24
  declare function arrayToPseudoXML<T extends Record<string, unknown>>(array: readonly T[], keys: readonly (keyof T)[], name?: string): string;
25
25
  //#endregion
26
26
  export { addPriceScores, arrayToPseudoXML, getDefaultTokenProfile, getDefaultWeights, getSortedRankedModel, getSortedRecommendedModelIds, getSortedRecommendedModels, rankModels, weightsToPriceSensitivity };
@@ -140,20 +140,21 @@ function rankModels(models, profile, category, weights) {
140
140
  };
141
141
  }).sort((a, b) => b.score - a.score);
142
142
  }
143
- function getSortedRankedModel(models, category = "chat", weights, tokenProfile) {
144
- return rankModels(models, typeof tokenProfile === "string" ? {
143
+ function getSortedRankedModel(models, category = "chat", weights, tokenProfile, filter) {
144
+ const rankedModels = rankModels(models, typeof tokenProfile === "string" ? {
145
145
  inputTokens: TOKEN_PRESETS[tokenProfile],
146
146
  outputTokens: TOKEN_PRESETS[tokenProfile]
147
147
  } : typeof tokenProfile === "number" ? {
148
148
  inputTokens: tokenProfile,
149
149
  outputTokens: tokenProfile
150
150
  } : tokenProfile ? tokenProfile : getDefaultTokenProfile(category), category, getDefaultWeights(weights));
151
+ return filter ? rankedModels.filter(filter) : rankedModels;
151
152
  }
152
- function getSortedRecommendedModels(category = "chat", weights, tokenProfile) {
153
- return getSortedRankedModel(RANKED_MODELS, category, weights, tokenProfile);
153
+ function getSortedRecommendedModels(category = "chat", weights, tokenProfile, filter) {
154
+ return getSortedRankedModel(RANKED_MODELS, category, weights, tokenProfile, filter);
154
155
  }
155
- function getSortedRecommendedModelIds(category = "chat", weights, tokenProfile) {
156
- return getSortedRankedModel(RANKED_MODELS, category, weights, tokenProfile).map((model) => model.id);
156
+ function getSortedRecommendedModelIds(category = "chat", weights, tokenProfile, filter) {
157
+ return getSortedRankedModel(RANKED_MODELS, category, weights, tokenProfile, filter).map((model) => model.id);
157
158
  }
158
159
  function arrayToPseudoXML(array, keys, name = "item") {
159
160
  return array.map((item) => `<${name}>${keys.map((key) => `<${String(key)}>${String(item[key])}</${String(key)}>`).join("\n")}</${name}>`).join("\n");
@@ -1 +1 @@
1
- {"version":3,"file":"ai.utils.mjs","names":[],"sources":["../../../../src/modules/ai/ai.utils.ts"],"sourcesContent":["import { RANKED_MODELS, TOKEN_PRESETS } from \"./ai.constants\";\r\nimport type { Category, RankedModel, SortType, TokenProfile, TokenSize } from \"./ai.types\";\r\n\r\nexport function getDefaultTokenProfile(category: Category): TokenProfile {\r\n switch (category) {\r\n case \"structured_output\":\r\n return { inputTokens: TOKEN_PRESETS.lg, outputTokens: TOKEN_PRESETS.md };\r\n case \"creative\":\r\n return { inputTokens: TOKEN_PRESETS.md, outputTokens: TOKEN_PRESETS.lg };\r\n case \"research\":\r\n return { inputTokens: TOKEN_PRESETS.xl, outputTokens: TOKEN_PRESETS.xl };\r\n case \"chat\":\r\n return { inputTokens: TOKEN_PRESETS.sm, outputTokens: TOKEN_PRESETS.md };\r\n case \"tool_use\":\r\n return { inputTokens: TOKEN_PRESETS.md, outputTokens: TOKEN_PRESETS.sm };\r\n case \"planning\":\r\n return { inputTokens: TOKEN_PRESETS.lg, outputTokens: TOKEN_PRESETS.lg };\r\n case \"classification\":\r\n return { inputTokens: TOKEN_PRESETS.sm, outputTokens: TOKEN_PRESETS.xs };\r\n default:\r\n return { inputTokens: TOKEN_PRESETS.md, outputTokens: TOKEN_PRESETS.md };\r\n }\r\n}\r\n\r\nexport function getDefaultWeights(\r\n weights?: SortType | [SortType, SortType, SortType] | [number, number, number]\r\n): [number, number, number] {\r\n if (Array.isArray(weights)) {\r\n return weights.every((weight) => typeof weight === \"number\")\r\n ? weights\r\n : weights.reduce<[number, number, number]>(\r\n (acc, weight, index) => {\r\n switch (weight) {\r\n case \"quality\":\r\n acc[0] = index === 0 ? 50 : index === 1 ? 30 : 20;\r\n break;\r\n case \"price\":\r\n acc[1] = index === 0 ? 50 : index === 1 ? 30 : 20;\r\n break;\r\n case \"speed\":\r\n acc[2] = index === 0 ? 50 : index === 1 ? 30 : 20;\r\n break;\r\n }\r\n return acc;\r\n },\r\n [20, 50, 30]\r\n );\r\n }\r\n switch (weights) {\r\n case \"quality\":\r\n return [50, 30, 20];\r\n case \"price\":\r\n return [20, 50, 30];\r\n case \"speed\":\r\n return [20, 30, 50];\r\n default:\r\n return [50, 25, 25];\r\n }\r\n}\r\n\r\nexport function weightsToPriceSensitivity(weights: [number, number, number]): number {\r\n const [qualityWeight, priceWeight, speedWeight] = weights;\r\n\r\n const total = qualityWeight + priceWeight + speedWeight;\r\n\r\n if (total <= 0) {\r\n return 1;\r\n }\r\n\r\n const normalizedPriceWeight = priceWeight / total;\r\n\r\n const min = 0.55; // very price-sensitive\r\n const max = 1.75; // price is soft / secondary\r\n\r\n // Higher price weight -> lower exponent -> stronger price penalty.\r\n const sensitivity = max - normalizedPriceWeight * (max - min);\r\n\r\n return Number(sensitivity.toFixed(3));\r\n}\r\n\r\nexport function addPriceScores(\r\n models: RankedModel[],\r\n profile: TokenProfile,\r\n priceSensitivity = 1\r\n): Array<RankedModel & { price: number; estimatedCost: number }> {\r\n const costs = models.map((model) => {\r\n return (\r\n (profile.inputTokens / 1_000_000) * model.inputCost +\r\n (profile.outputTokens / 1_000_000) * model.outputCost\r\n );\r\n });\r\n\r\n const cheapest = Math.min(...costs);\r\n const mostExpensive = Math.max(...costs);\r\n\r\n return models.map((model, index) => {\r\n const cost = costs[index];\r\n\r\n if (mostExpensive === cheapest) {\r\n return {\r\n ...model,\r\n estimatedCost: cost,\r\n price: 10,\r\n };\r\n }\r\n\r\n const safeCheapest = Math.max(cheapest, Number.EPSILON);\r\n const safeCost = Math.max(cost, Number.EPSILON);\r\n const safeMostExpensive = Math.max(mostExpensive, Number.EPSILON);\r\n\r\n const logMin = Math.log(safeCheapest);\r\n const logMax = Math.log(safeMostExpensive);\r\n const logCost = Math.log(safeCost);\r\n\r\n const normalizedRaw = (logCost - logMin) / (logMax - logMin);\r\n\r\n // < 1 makes price matter less.\r\n // > 1 makes price matter more.\r\n const normalized = normalizedRaw ** priceSensitivity;\r\n\r\n return {\r\n ...model,\r\n estimatedCost: cost,\r\n price: Math.round(10 - normalized * 9),\r\n };\r\n });\r\n}\r\n\r\nfunction clampScore(value: number): number {\r\n return Math.max(1, Math.min(10, value));\r\n}\r\n\r\nfunction shapeScoreByWeight(value: number, weight: number, maxWeight: number): number {\r\n const score = clampScore(value);\r\n const normalized = score / 10;\r\n\r\n if (maxWeight <= 0 || weight <= 0) {\r\n return 0;\r\n }\r\n\r\n const importance = (weight / maxWeight) ** 2;\r\n const expanded = normalized ** 2 * 10;\r\n const compressed = 8 + normalized * 2;\r\n return compressed + (expanded - compressed) * importance;\r\n}\r\n\r\nexport function rankModels(\r\n models: RankedModel[],\r\n profile: TokenProfile,\r\n category: Category,\r\n weights: [number, number, number]\r\n) {\r\n const scoredModels = addPriceScores(models, profile, weightsToPriceSensitivity(weights));\r\n\r\n const [qualityWeight, priceWeight, speedWeight] = weights;\r\n const maxWeight = Math.max(qualityWeight, priceWeight, speedWeight);\r\n\r\n return scoredModels\r\n .map((model) => {\r\n const qualityScore = shapeScoreByWeight(model.quality[category], qualityWeight, maxWeight);\r\n\r\n const priceScore = shapeScoreByWeight(model.price, priceWeight, maxWeight);\r\n\r\n const speedScore = shapeScoreByWeight(model.speed, speedWeight, maxWeight);\r\n\r\n return {\r\n ...model,\r\n score: qualityScore * qualityWeight + priceScore * priceWeight + speedScore * speedWeight,\r\n };\r\n })\r\n .sort((a, b) => b.score - a.score);\r\n}\r\n\r\nexport function getSortedRankedModel(\r\n models: RankedModel[],\r\n category: Category = \"chat\",\r\n weights?: SortType | [SortType, SortType, SortType] | [number, number, number],\r\n tokenProfile?: TokenProfile | number | TokenSize\r\n): RankedModel[] {\r\n const profile =\r\n typeof tokenProfile === \"string\"\r\n ? {\r\n inputTokens: TOKEN_PRESETS[tokenProfile as TokenSize],\r\n outputTokens: TOKEN_PRESETS[tokenProfile as TokenSize],\r\n }\r\n : typeof tokenProfile === \"number\"\r\n ? { inputTokens: tokenProfile, outputTokens: tokenProfile }\r\n : tokenProfile\r\n ? (tokenProfile as TokenProfile)\r\n : getDefaultTokenProfile(category);\r\n return rankModels(models, profile, category, getDefaultWeights(weights));\r\n}\r\n\r\nexport function getSortedRecommendedModels(\r\n category: Category = \"chat\",\r\n weights?: SortType | [SortType, SortType, SortType] | [number, number, number],\r\n tokenProfile?: TokenProfile | number | TokenSize\r\n): RankedModel[] {\r\n return getSortedRankedModel(RANKED_MODELS, category, weights, tokenProfile);\r\n}\r\n\r\nexport function getSortedRecommendedModelIds(\r\n category: Category = \"chat\",\r\n weights?: SortType | [SortType, SortType, SortType] | [number, number, number],\r\n tokenProfile?: TokenProfile | number | TokenSize\r\n): string[] {\r\n return getSortedRankedModel(RANKED_MODELS, category, weights, tokenProfile).map(\r\n (model) => model.id\r\n );\r\n}\r\n\r\nexport function arrayToPseudoXML<T extends Record<string, unknown>>(\r\n array: readonly T[],\r\n keys: readonly (keyof T)[],\r\n name = \"item\"\r\n): string {\r\n return array\r\n .map(\r\n (item) =>\r\n `<${name}>${keys\r\n .map((key) => `<${String(key)}>${String(item[key])}</${String(key)}>`)\r\n .join(\"\\n\")}</${name}>`\r\n )\r\n .join(\"\\n\");\r\n}\r\n"],"mappings":";;;AAGA,SAAgB,uBAAuB,UAAkC;AACvE,SAAQ,UAAR;EACE,KAAK,oBACH,QAAO;GAAE,aAAa,cAAc;GAAI,cAAc,cAAc;GAAI;EAC1E,KAAK,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":["../../../../src/modules/ai/ai.utils.ts"],"sourcesContent":["import { RANKED_MODELS, TOKEN_PRESETS } from \"./ai.constants\";\r\nimport type { Category, RankedModel, SortType, TokenProfile, TokenSize } from \"./ai.types\";\r\n\r\nexport function getDefaultTokenProfile(category: Category): TokenProfile {\r\n switch (category) {\r\n case \"structured_output\":\r\n return { inputTokens: TOKEN_PRESETS.lg, outputTokens: TOKEN_PRESETS.md };\r\n case \"creative\":\r\n return { inputTokens: TOKEN_PRESETS.md, outputTokens: TOKEN_PRESETS.lg };\r\n case \"research\":\r\n return { inputTokens: TOKEN_PRESETS.xl, outputTokens: TOKEN_PRESETS.xl };\r\n case \"chat\":\r\n return { inputTokens: TOKEN_PRESETS.sm, outputTokens: TOKEN_PRESETS.md };\r\n case \"tool_use\":\r\n return { inputTokens: TOKEN_PRESETS.md, outputTokens: TOKEN_PRESETS.sm };\r\n case \"planning\":\r\n return { inputTokens: TOKEN_PRESETS.lg, outputTokens: TOKEN_PRESETS.lg };\r\n case \"classification\":\r\n return { inputTokens: TOKEN_PRESETS.sm, outputTokens: TOKEN_PRESETS.xs };\r\n default:\r\n return { inputTokens: TOKEN_PRESETS.md, outputTokens: TOKEN_PRESETS.md };\r\n }\r\n}\r\n\r\nexport function getDefaultWeights(\r\n weights?: SortType | [SortType, SortType, SortType] | [number, number, number]\r\n): [number, number, number] {\r\n if (Array.isArray(weights)) {\r\n return weights.every((weight) => typeof weight === \"number\")\r\n ? weights\r\n : weights.reduce<[number, number, number]>(\r\n (acc, weight, index) => {\r\n switch (weight) {\r\n case \"quality\":\r\n acc[0] = index === 0 ? 50 : index === 1 ? 30 : 20;\r\n break;\r\n case \"price\":\r\n acc[1] = index === 0 ? 50 : index === 1 ? 30 : 20;\r\n break;\r\n case \"speed\":\r\n acc[2] = index === 0 ? 50 : index === 1 ? 30 : 20;\r\n break;\r\n }\r\n return acc;\r\n },\r\n [20, 50, 30]\r\n );\r\n }\r\n switch (weights) {\r\n case \"quality\":\r\n return [50, 30, 20];\r\n case \"price\":\r\n return [20, 50, 30];\r\n case \"speed\":\r\n return [20, 30, 50];\r\n default:\r\n return [50, 25, 25];\r\n }\r\n}\r\n\r\nexport function weightsToPriceSensitivity(weights: [number, number, number]): number {\r\n const [qualityWeight, priceWeight, speedWeight] = weights;\r\n\r\n const total = qualityWeight + priceWeight + speedWeight;\r\n\r\n if (total <= 0) {\r\n return 1;\r\n }\r\n\r\n const normalizedPriceWeight = priceWeight / total;\r\n\r\n const min = 0.55; // very price-sensitive\r\n const max = 1.75; // price is soft / secondary\r\n\r\n // Higher price weight -> lower exponent -> stronger price penalty.\r\n const sensitivity = max - normalizedPriceWeight * (max - min);\r\n\r\n return Number(sensitivity.toFixed(3));\r\n}\r\n\r\nexport function addPriceScores(\r\n models: RankedModel[],\r\n profile: TokenProfile,\r\n priceSensitivity = 1\r\n): Array<RankedModel & { price: number; estimatedCost: number }> {\r\n const costs = models.map((model) => {\r\n return (\r\n (profile.inputTokens / 1_000_000) * model.inputCost +\r\n (profile.outputTokens / 1_000_000) * model.outputCost\r\n );\r\n });\r\n\r\n const cheapest = Math.min(...costs);\r\n const mostExpensive = Math.max(...costs);\r\n\r\n return models.map((model, index) => {\r\n const cost = costs[index];\r\n\r\n if (mostExpensive === cheapest) {\r\n return {\r\n ...model,\r\n estimatedCost: cost,\r\n price: 10,\r\n };\r\n }\r\n\r\n const safeCheapest = Math.max(cheapest, Number.EPSILON);\r\n const safeCost = Math.max(cost, Number.EPSILON);\r\n const safeMostExpensive = Math.max(mostExpensive, Number.EPSILON);\r\n\r\n const logMin = Math.log(safeCheapest);\r\n const logMax = Math.log(safeMostExpensive);\r\n const logCost = Math.log(safeCost);\r\n\r\n const normalizedRaw = (logCost - logMin) / (logMax - logMin);\r\n\r\n // < 1 makes price matter less.\r\n // > 1 makes price matter more.\r\n const normalized = normalizedRaw ** priceSensitivity;\r\n\r\n return {\r\n ...model,\r\n estimatedCost: cost,\r\n price: Math.round(10 - normalized * 9),\r\n };\r\n });\r\n}\r\n\r\nfunction clampScore(value: number): number {\r\n return Math.max(1, Math.min(10, value));\r\n}\r\n\r\nfunction shapeScoreByWeight(value: number, weight: number, maxWeight: number): number {\r\n const score = clampScore(value);\r\n const normalized = score / 10;\r\n\r\n if (maxWeight <= 0 || weight <= 0) {\r\n return 0;\r\n }\r\n\r\n const importance = (weight / maxWeight) ** 2;\r\n const expanded = normalized ** 2 * 10;\r\n const compressed = 8 + normalized * 2;\r\n return compressed + (expanded - compressed) * importance;\r\n}\r\n\r\nexport function rankModels(\r\n models: RankedModel[],\r\n profile: TokenProfile,\r\n category: Category,\r\n weights: [number, number, number]\r\n) {\r\n const scoredModels = addPriceScores(models, profile, weightsToPriceSensitivity(weights));\r\n\r\n const [qualityWeight, priceWeight, speedWeight] = weights;\r\n const maxWeight = Math.max(qualityWeight, priceWeight, speedWeight);\r\n\r\n return scoredModels\r\n .map((model) => {\r\n const qualityScore = shapeScoreByWeight(model.quality[category], qualityWeight, maxWeight);\r\n\r\n const priceScore = shapeScoreByWeight(model.price, priceWeight, maxWeight);\r\n\r\n const speedScore = shapeScoreByWeight(model.speed, speedWeight, maxWeight);\r\n\r\n return {\r\n ...model,\r\n score: qualityScore * qualityWeight + priceScore * priceWeight + speedScore * speedWeight,\r\n };\r\n })\r\n .sort((a, b) => b.score - a.score);\r\n}\r\n\r\nexport function getSortedRankedModel(\r\n models: RankedModel[],\r\n category: Category = \"chat\",\r\n weights?: SortType | [SortType, SortType, SortType] | [number, number, number],\r\n tokenProfile?: TokenProfile | number | TokenSize,\r\n filter?: (model: RankedModel) => boolean\r\n): RankedModel[] {\r\n const profile =\r\n typeof tokenProfile === \"string\"\r\n ? {\r\n inputTokens: TOKEN_PRESETS[tokenProfile as TokenSize],\r\n outputTokens: TOKEN_PRESETS[tokenProfile as TokenSize],\r\n }\r\n : typeof tokenProfile === \"number\"\r\n ? { inputTokens: tokenProfile, outputTokens: tokenProfile }\r\n : tokenProfile\r\n ? (tokenProfile as TokenProfile)\r\n : getDefaultTokenProfile(category);\r\n const rankedModels = rankModels(models, profile, category, getDefaultWeights(weights));\r\n return filter ? rankedModels.filter(filter) : rankedModels;\r\n}\r\n\r\nexport function getSortedRecommendedModels(\r\n category: Category = \"chat\",\r\n weights?: SortType | [SortType, SortType, SortType] | [number, number, number],\r\n tokenProfile?: TokenProfile | number | TokenSize,\r\n filter?: (model: RankedModel) => boolean\r\n): RankedModel[] {\r\n return getSortedRankedModel(RANKED_MODELS, category, weights, tokenProfile, filter);\r\n}\r\n\r\nexport function getSortedRecommendedModelIds(\r\n category: Category = \"chat\",\r\n weights?: SortType | [SortType, SortType, SortType] | [number, number, number],\r\n tokenProfile?: TokenProfile | number | TokenSize,\r\n filter?: (model: RankedModel) => boolean\r\n): string[] {\r\n return getSortedRankedModel(RANKED_MODELS, category, weights, tokenProfile, filter).map(\r\n (model) => model.id\r\n );\r\n}\r\n\r\nexport function arrayToPseudoXML<T extends Record<string, unknown>>(\r\n array: readonly T[],\r\n keys: readonly (keyof T)[],\r\n name = \"item\"\r\n): string {\r\n return array\r\n .map(\r\n (item) =>\r\n `<${name}>${keys\r\n .map((key) => `<${String(key)}>${String(item[key])}</${String(key)}>`)\r\n .join(\"\\n\")}</${name}>`\r\n )\r\n .join(\"\\n\");\r\n}\r\n"],"mappings":";;;AAGA,SAAgB,uBAAuB,UAAkC;AACvE,SAAQ,UAAR;EACE,KAAK,oBACH,QAAO;GAAE,aAAa,cAAc;GAAI,cAAc,cAAc;GAAI;EAC1E,KAAK,WACH,QAAO;GAAE,aAAa,cAAc;GAAI,cAAc,cAAc;GAAI;EAC1E,KAAK,WACH,QAAO;GAAE,aAAa,cAAc;GAAI,cAAc,cAAc;GAAI;EAC1E,KAAK,OACH,QAAO;GAAE,aAAa,cAAc;GAAI,cAAc,cAAc;GAAI;EAC1E,KAAK,WACH,QAAO;GAAE,aAAa,cAAc;GAAI,cAAc,cAAc;GAAI;EAC1E,KAAK,WACH,QAAO;GAAE,aAAa,cAAc;GAAI,cAAc,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E1E,MAAM,aAAa,mBAAmB,MAAM,OAAO,aAAa,UAAU;AAE1E,SAAO;GACL,GAAG;GACH,OAAO,eAAe,gBAAgB,aAAa,cAAc,aAAa;GAC/E;GACD,CACD,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,MAAM;;AAGtC,SAAgB,qBACd,QACA,WAAqB,QACrB,SACA,cACA,QACe;CAYf,MAAM,eAAe,WAAW,QAV9B,OAAO,iBAAiB,WACpB;EACE,aAAa,cAAc;EAC3B,cAAc,cAAc;EAC7B,GACD,OAAO,iBAAiB,WACtB;EAAE,aAAa;EAAc,cAAc;EAAc,GACzD,eACG,eACD,uBAAuB,SAAS,EACO,UAAU,kBAAkB,QAAQ,CAAC;AACtF,QAAO,SAAS,aAAa,OAAO,OAAO,GAAG;;AAGhD,SAAgB,2BACd,WAAqB,QACrB,SACA,cACA,QACe;AACf,QAAO,qBAAqB,eAAe,UAAU,SAAS,cAAc,OAAO;;AAGrF,SAAgB,6BACd,WAAqB,QACrB,SACA,cACA,QACU;AACV,QAAO,qBAAqB,eAAe,UAAU,SAAS,cAAc,OAAO,CAAC,KACjF,UAAU,MAAM,GAClB;;AAGH,SAAgB,iBACd,OACA,MACA,OAAO,QACC;AACR,QAAO,MACJ,KACE,SACC,IAAI,KAAK,GAAG,KACT,KAAK,QAAQ,IAAI,OAAO,IAAI,CAAC,GAAG,OAAO,KAAK,KAAK,CAAC,IAAI,OAAO,IAAI,CAAC,GAAG,CACrE,KAAK,KAAK,CAAC,IAAI,KAAK,GAC1B,CACA,KAAK,KAAK"}
@@ -12,9 +12,9 @@ declare const notificationProviderSchema: z.ZodEnum<{
12
12
  fcm: "fcm";
13
13
  }>;
14
14
  declare const notificationSendStatusSchema: z.ZodEnum<{
15
+ failed: "failed";
15
16
  pending: "pending";
16
17
  sent: "sent";
17
- failed: "failed";
18
18
  }>;
19
19
  /** Web Push `PushSubscriptionJSON` subset we persist and accept from clients. */
20
20
  declare const pushSubscriptionJsonSchema: z.ZodObject<{
@@ -100,9 +100,9 @@ declare const notificationSendLogSelectSchema: z.ZodObject<{
100
100
  body: z.ZodString;
101
101
  data: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
102
102
  status: z.ZodEnum<{
103
+ failed: "failed";
103
104
  pending: "pending";
104
105
  sent: "sent";
105
- failed: "failed";
106
106
  }>;
107
107
  error: z.ZodNullable<z.ZodString>;
108
108
  jobId: z.ZodNullable<z.ZodString>;
@@ -127,9 +127,9 @@ declare const notificationListSendLogsOutputSchema: z.ZodArray<z.ZodObject<{
127
127
  body: z.ZodString;
128
128
  data: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
129
129
  status: z.ZodEnum<{
130
+ failed: "failed";
130
131
  pending: "pending";
131
132
  sent: "sent";
132
- failed: "failed";
133
133
  }>;
134
134
  error: z.ZodNullable<z.ZodString>;
135
135
  jobId: z.ZodNullable<z.ZodString>;
@@ -12,9 +12,9 @@ declare const notificationProviderSchema: z.ZodEnum<{
12
12
  fcm: "fcm";
13
13
  }>;
14
14
  declare const notificationSendStatusSchema: z.ZodEnum<{
15
+ failed: "failed";
15
16
  pending: "pending";
16
17
  sent: "sent";
17
- failed: "failed";
18
18
  }>;
19
19
  /** Web Push `PushSubscriptionJSON` subset we persist and accept from clients. */
20
20
  declare const pushSubscriptionJsonSchema: z.ZodObject<{
@@ -100,9 +100,9 @@ declare const notificationSendLogSelectSchema: z.ZodObject<{
100
100
  body: z.ZodString;
101
101
  data: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
102
102
  status: z.ZodEnum<{
103
+ failed: "failed";
103
104
  pending: "pending";
104
105
  sent: "sent";
105
- failed: "failed";
106
106
  }>;
107
107
  error: z.ZodNullable<z.ZodString>;
108
108
  jobId: z.ZodNullable<z.ZodString>;
@@ -127,9 +127,9 @@ declare const notificationListSendLogsOutputSchema: z.ZodArray<z.ZodObject<{
127
127
  body: z.ZodString;
128
128
  data: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
129
129
  status: z.ZodEnum<{
130
+ failed: "failed";
130
131
  pending: "pending";
131
132
  sent: "sent";
132
- failed: "failed";
133
133
  }>;
134
134
  error: z.ZodNullable<z.ZodString>;
135
135
  jobId: z.ZodNullable<z.ZodString>;
@@ -11,10 +11,10 @@ declare const workflowSelectSchema: z.ZodObject<{
11
11
  input: z.ZodUnknown;
12
12
  output: z.ZodUnknown;
13
13
  status: z.ZodEnum<{
14
- failed: "failed";
15
14
  queued: "queued";
16
15
  running: "running";
17
16
  completed: "completed";
17
+ failed: "failed";
18
18
  }>;
19
19
  error: z.ZodNullable<z.ZodString>;
20
20
  retries: z.ZodNumber;
@@ -28,10 +28,10 @@ declare const workflowReadInputSchema: z.ZodObject<{
28
28
  }, z.core.$strip>;
29
29
  declare const workflowListInputSchema: z.ZodObject<{
30
30
  status: z.ZodOptional<z.ZodArray<z.ZodEnum<{
31
- failed: "failed";
32
31
  queued: "queued";
33
32
  running: "running";
34
33
  completed: "completed";
34
+ failed: "failed";
35
35
  }>>>;
36
36
  jobName: z.ZodOptional<z.ZodString>;
37
37
  }, z.core.$strip>;
@@ -51,10 +51,10 @@ declare const workflowReadOutputSchema: z.ZodObject<{
51
51
  input: z.ZodUnknown;
52
52
  output: z.ZodUnknown;
53
53
  status: z.ZodEnum<{
54
- failed: "failed";
55
54
  queued: "queued";
56
55
  running: "running";
57
56
  completed: "completed";
57
+ failed: "failed";
58
58
  }>;
59
59
  error: z.ZodNullable<z.ZodString>;
60
60
  retries: z.ZodNumber;
@@ -73,10 +73,10 @@ declare const workflowListOutputSchema: z.ZodArray<z.ZodObject<{
73
73
  input: z.ZodUnknown;
74
74
  output: z.ZodUnknown;
75
75
  status: z.ZodEnum<{
76
- failed: "failed";
77
76
  queued: "queued";
78
77
  running: "running";
79
78
  completed: "completed";
79
+ failed: "failed";
80
80
  }>;
81
81
  error: z.ZodNullable<z.ZodString>;
82
82
  retries: z.ZodNumber;
@@ -11,10 +11,10 @@ declare const workflowSelectSchema: z.ZodObject<{
11
11
  input: z.ZodUnknown;
12
12
  output: z.ZodUnknown;
13
13
  status: z.ZodEnum<{
14
- failed: "failed";
15
14
  queued: "queued";
16
15
  running: "running";
17
16
  completed: "completed";
17
+ failed: "failed";
18
18
  }>;
19
19
  error: z.ZodNullable<z.ZodString>;
20
20
  retries: z.ZodNumber;
@@ -28,10 +28,10 @@ declare const workflowReadInputSchema: z.ZodObject<{
28
28
  }, z.core.$strip>;
29
29
  declare const workflowListInputSchema: z.ZodObject<{
30
30
  status: z.ZodOptional<z.ZodArray<z.ZodEnum<{
31
- failed: "failed";
32
31
  queued: "queued";
33
32
  running: "running";
34
33
  completed: "completed";
34
+ failed: "failed";
35
35
  }>>>;
36
36
  jobName: z.ZodOptional<z.ZodString>;
37
37
  }, z.core.$strip>;
@@ -51,10 +51,10 @@ declare const workflowReadOutputSchema: z.ZodObject<{
51
51
  input: z.ZodUnknown;
52
52
  output: z.ZodUnknown;
53
53
  status: z.ZodEnum<{
54
- failed: "failed";
55
54
  queued: "queued";
56
55
  running: "running";
57
56
  completed: "completed";
57
+ failed: "failed";
58
58
  }>;
59
59
  error: z.ZodNullable<z.ZodString>;
60
60
  retries: z.ZodNumber;
@@ -73,10 +73,10 @@ declare const workflowListOutputSchema: z.ZodArray<z.ZodObject<{
73
73
  input: z.ZodUnknown;
74
74
  output: z.ZodUnknown;
75
75
  status: z.ZodEnum<{
76
- failed: "failed";
77
76
  queued: "queued";
78
77
  running: "running";
79
78
  completed: "completed";
79
+ failed: "failed";
80
80
  }>;
81
81
  error: z.ZodNullable<z.ZodString>;
82
82
  retries: z.ZodNumber;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m5kdev/commons",
3
- "version": "0.27.2",
3
+ "version": "0.28.0",
4
4
  "license": "GPL-3.0-only",
5
5
  "repository": {
6
6
  "type": "git",
@@ -18,7 +18,7 @@
18
18
  "devDependencies": {
19
19
  "tsdown": "0.21.7",
20
20
  "typescript": "6.0.3",
21
- "@m5kdev/config": "0.27.2"
21
+ "@m5kdev/config": "0.28.0"
22
22
  },
23
23
  "exports": {
24
24
  "./utils/*": {