@x12i/ai-tools 2.2.0 → 2.3.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.
- package/dist/{AiModelsCatalogClient-DgBdVFk-.d.cts → AiModelsCatalogClient-CQf-zHc6.d.cts} +1 -1
- package/dist/{AiModelsCatalogClient-C9ZJHhv3.d.ts → AiModelsCatalogClient-Cohl3zfe.d.ts} +1 -1
- package/dist/aliases/index.d.cts +4 -3
- package/dist/aliases/index.d.ts +4 -3
- package/dist/catalog/index.cjs +5 -4
- package/dist/catalog/index.cjs.map +1 -1
- package/dist/catalog/index.d.cts +5 -4
- package/dist/catalog/index.d.ts +5 -4
- package/dist/catalog/index.js +4 -3
- package/dist/{chunk-FWPH5YE6.cjs → chunk-3JDAPUZM.cjs} +8 -6
- package/dist/chunk-3JDAPUZM.cjs.map +1 -0
- package/dist/chunk-6T7QT6YH.cjs +7 -0
- package/dist/chunk-6T7QT6YH.cjs.map +1 -0
- package/dist/{chunk-TFQUMP2O.js → chunk-A7JKTDSD.js} +5 -3
- package/dist/{chunk-TFQUMP2O.js.map → chunk-A7JKTDSD.js.map} +1 -1
- package/dist/{chunk-GHRUS5UF.cjs → chunk-AGLZXZCH.cjs} +23 -21
- package/dist/chunk-AGLZXZCH.cjs.map +1 -0
- package/dist/{chunk-QILRLRA4.cjs → chunk-EE3Z75GO.cjs} +5 -5
- package/dist/{chunk-QILRLRA4.cjs.map → chunk-EE3Z75GO.cjs.map} +1 -1
- package/dist/{chunk-M35MNKDY.js → chunk-FHJDIYPJ.js} +3 -3
- package/dist/{chunk-XD5RQKYL.cjs → chunk-H7W5LMP6.cjs} +25 -14
- package/dist/chunk-H7W5LMP6.cjs.map +1 -0
- package/dist/{chunk-XJQODPN6.js → chunk-LHJV2YLY.js} +13 -3
- package/dist/{chunk-XJQODPN6.js.map → chunk-LHJV2YLY.js.map} +1 -1
- package/dist/chunk-OPKL4YNL.js +7 -0
- package/dist/chunk-OPKL4YNL.js.map +1 -0
- package/dist/{chunk-MLMQ5LGW.js → chunk-U2LOUZP7.js} +2 -1
- package/dist/chunk-U2LOUZP7.js.map +1 -0
- package/dist/{chunk-WMB3YEQQ.js → chunk-VR4P5QB2.js} +5 -3
- package/dist/{chunk-WMB3YEQQ.js.map → chunk-VR4P5QB2.js.map} +1 -1
- package/dist/{chunk-UIDCBJXR.cjs → chunk-VVCG536Q.cjs} +7 -7
- package/dist/{chunk-UIDCBJXR.cjs.map → chunk-VVCG536Q.cjs.map} +1 -1
- package/dist/{chunk-PP75SWKY.js → chunk-WVJZCVI7.js} +2 -2
- package/dist/{chunk-33AAM7KQ.cjs → chunk-XKJFO6VG.cjs} +16 -6
- package/dist/chunk-XKJFO6VG.cjs.map +1 -0
- package/dist/{chunk-TLUM25FM.js → chunk-YERYMWKM.js} +21 -10
- package/dist/chunk-YERYMWKM.js.map +1 -0
- package/dist/{chunk-FYRPN3N2.cjs → chunk-YGOZDVK3.cjs} +2 -1
- package/dist/chunk-YGOZDVK3.cjs.map +1 -0
- package/dist/cli/index.cjs +16 -15
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +7 -6
- package/dist/cli/index.js.map +1 -1
- package/dist/cost/index.cjs +5 -4
- package/dist/cost/index.cjs.map +1 -1
- package/dist/cost/index.d.cts +6 -5
- package/dist/cost/index.d.ts +6 -5
- package/dist/cost/index.js +4 -3
- package/dist/index.cjs +12 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -9
- package/dist/index.d.ts +9 -9
- package/dist/index.js +11 -7
- package/dist/{modelCache-xzoTUue2.d.ts → modelCache-Bbw8Yc8Y.d.ts} +1 -1
- package/dist/{modelCache-sL3dBfRM.d.cts → modelCache-_mEwDBW7.d.cts} +1 -1
- package/dist/{modelNameResolver-2WroQlqt.d.ts → modelNameResolver-6k18Wvys.d.ts} +1 -1
- package/dist/{modelNameResolver-Bxlehrbp.d.cts → modelNameResolver-MoyOpdC3.d.cts} +1 -1
- package/dist/models/index.cjs +6 -5
- package/dist/models/index.cjs.map +1 -1
- package/dist/models/index.d.cts +5 -4
- package/dist/models/index.d.ts +5 -4
- package/dist/models/index.js +5 -4
- package/dist/profiles/index.cjs +6 -2
- package/dist/profiles/index.cjs.map +1 -1
- package/dist/profiles/index.d.cts +8 -3
- package/dist/profiles/index.d.ts +8 -3
- package/dist/profiles/index.js +5 -1
- package/dist/{resolveModelVendor-DQpJpk0w.d.ts → resolveModelVendor-Bb-TvXHF.d.ts} +3 -3
- package/dist/{resolveModelVendor-uphYBFMY.d.ts → resolveModelVendor-CF9l_SVN.d.ts} +1 -1
- package/dist/{resolveModelVendor-XvmXsVzo.d.cts → resolveModelVendor-CI64t5sk.d.cts} +3 -3
- package/dist/{resolveModelVendor-B0t5nq-v.d.cts → resolveModelVendor-Ck059GDf.d.cts} +1 -1
- package/dist/sync/index.d.cts +5 -4
- package/dist/sync/index.d.ts +5 -4
- package/dist/{types-BZYGjN2O.d.cts → types-CILRAzjr.d.cts} +4 -0
- package/dist/{types-BZYGjN2O.d.ts → types-CILRAzjr.d.ts} +4 -0
- package/package.json +2 -2
- package/dist/chunk-33AAM7KQ.cjs.map +0 -1
- package/dist/chunk-FWPH5YE6.cjs.map +0 -1
- package/dist/chunk-FYRPN3N2.cjs.map +0 -1
- package/dist/chunk-GHRUS5UF.cjs.map +0 -1
- package/dist/chunk-MLMQ5LGW.js.map +0 -1
- package/dist/chunk-TLUM25FM.js.map +0 -1
- package/dist/chunk-XD5RQKYL.cjs.map +0 -1
- /package/dist/{chunk-M35MNKDY.js.map → chunk-FHJDIYPJ.js.map} +0 -0
- /package/dist/{chunk-PP75SWKY.js.map → chunk-WVJZCVI7.js.map} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/ami/Documents/prometheus/x12i/ai-tools/dist/chunk-AGLZXZCH.cjs","../src/cost/constants.ts","../src/cost/enrichCostResult.ts","../src/cost/extractUsageInput.ts","../src/cost/resolveUsageModel.ts","../src/cost/profilePricing.ts","../src/cost/CostCalculator.ts"],"names":["routedViaOpenRouter","pricing","cost","breakdown"],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACA;ACfO,IAAM,+BAAA,EAAiC,IAAA;AAGvC,IAAM,iCAAA,EAAmC,GAAA;ADehD;AACA;AEjBO,SAAS,gBAAA,CACd,UAAA,EACkB;AAClB,EAAA,OAAO;AAAA,IACL,KAAA,EAAO,EAAE,KAAA,EAAO,UAAA,CAAW,KAAA,CAAM,KAAA,EAAO,IAAA,EAAM,UAAA,CAAW,KAAA,CAAM,KAAK,CAAA;AAAA,IACpE,MAAA,EAAQ;AAAA,MACN,MAAA,EAAQ,UAAA,CAAW,MAAA,CAAO,MAAA;AAAA,MAC1B,IAAA,EAAM,UAAA,CAAW,MAAA,CAAO,IAAA;AAAA,MACxB,SAAA,EAAW,UAAA,CAAW,MAAA,CAAO;AAAA,IAC/B,CAAA;AAAA,IACA,GAAI,UAAA,CAAW,UAAA,EACX;AAAA,MACE,SAAA,EAAW;AAAA,QACT,KAAA,EAAO,UAAA,CAAW,SAAA,CAAU,KAAA;AAAA,QAC5B,IAAA,EAAM,UAAA,CAAW,SAAA,CAAU;AAAA,MAC7B;AAAA,IACF,EAAA,EACA,CAAC,CAAA;AAAA,IACL,GAAI,UAAA,CAAW,SAAA,EACX;AAAA,MACE,QAAA,EAAU;AAAA,QACR,KAAA,EAAO,UAAA,CAAW,QAAA,CAAS,KAAA;AAAA,QAC3B,IAAA,EAAM,UAAA,CAAW,QAAA,CAAS;AAAA,MAC5B;AAAA,IACF,EAAA,EACA,CAAC;AAAA,EACP,CAAA;AACF;AAGO,SAAS,gBAAA,CACd,MAAA,EAIA,KAAA,EACA,UAAA,EACc;AAEd,EAAA,MAAM,gBAAA,oCAAkB,KAAA,CAAM,SAAA,UAAa,KAAA,CAAM,WAAA,U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AAEd,IAAA;AACL,MAAA;AACQ,QAAA;AACG,QAAA;AACX,MAAA;AACF,IAAA;AACF,EAAA;AAQE,EAAA;AAEiB,IAAA;AACW,IAAA;AAC1B,MAAA;AACQ,MAAA;AACR,MAAA;AACF,IAAA;AAC4B,IAAA;AACD,MAAA;AAC3B,IAAA;AACO,IAAA;AACT,EAAA;AAGE,EAAA;AAIkC,IAAA;AAChC,MAAA;AACQ,QAAA;AACG,QAAA;AACX,MAAA;AACF,IAAA;AAC2B,IAAA;AACf,IAAA;AACV,MAAA;AACQ,QAAA;AACW,QAAA;AACI,QAAA;AACJ,QAAA;AACA,QAAA;AACT,QAAA;AACR,QAAA;AACF,MAAA;AACA,MAAA;AACF,IAAA;AACF,EAAA;AAGE,EAAA;AAIS,IAAA;AACG,MAAA;AACZ,IAAA;AAEkC,IAAA;AAChC,MAAA;AACQ,QAAA;AACG,QAAA;AACX,MAAA;AACF,IAAA;AAC2B,IAAA;AAEf,IAAA;AACV,MAAA;AACQ,QAAA;AACW,QAAA;AACI,QAAA;AACb,UAAA;AACN,UAAA;AACA,UAAA;AACsB,0BAAA;AACxB,QAAA;AACiB,QAAA;AACA,QAAA;AACT,QAAA;AACM,QAAA;AACd,QAAA;AACF,MAAA;AACA,MAAA;AACF,IAAA;AACF,EAAA;AACF;ANqVgC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/ami/Documents/prometheus/x12i/ai-tools/dist/chunk-AGLZXZCH.cjs","sourcesContent":[null,"/** Default OpenRouter platform surcharge when catalog markup fields are absent (5%). */\nexport const DEFAULT_OPENROUTER_MARKUP_RATE = 0.05;\n\n/** ai-profiles tiered pricing threshold (tokens). */\nexport const PROFILE_TIERED_CONTEXT_THRESHOLD = 200_000;\n","import type { ExtractUsageInputResult } from \"./extractUsageInput.js\";\nimport type { AiCostExtraction, AiCostResult, AiUsageInput } from \"./types.js\";\n\nexport function toCostExtraction(\n provenance: ExtractUsageInputResult[\"provenance\"],\n): AiCostExtraction {\n return {\n model: { field: provenance.model.field, path: provenance.model.path },\n tokens: {\n source: provenance.tokens.source,\n path: provenance.tokens.path,\n estimated: provenance.tokens.estimated,\n },\n ...(provenance.modelUsed\n ? {\n modelUsed: {\n field: provenance.modelUsed.field,\n path: provenance.modelUsed.path,\n },\n }\n : {}),\n ...(provenance.provider\n ? {\n provider: {\n field: provenance.provider.field,\n path: provenance.provider.path,\n },\n }\n : {}),\n };\n}\n\n/** Attach usage, provider, and model fields callers expect on every cost response. */\nexport function enrichCostResult(\n result: Omit<\n AiCostResult,\n \"usage\" | \"provider\" | \"usedModel\" | \"model\" | \"extraction\"\n >,\n input: AiUsageInput,\n extraction?: AiCostExtraction,\n): AiCostResult {\n /** Original model id from the caller — never replaced by catalog resolution. */\n const receivedModelId = input.usedModel ?? input.modelUsed ?? input.model;\n\n return {\n ...result,\n provider: input.provider,\n usage: { ...input.tokens },\n ...(receivedModelId ? { usedModel: receivedModelId } : {}),\n ...(input.model && input.model !== receivedModelId ? { model: input.model } : {}),\n ...(extraction ? { extraction } : {}),\n };\n}\n","import type { AiUsageInput } from \"./types.js\";\n\n/** Model id field priority (higher wins). Runtime ids beat request/config aliases. */\nexport const MODEL_FIELD_PRIORITY: readonly { key: string; score: number }[] = [\n { key: \"usedModel\", score: 1000 },\n { key: \"modelUsed\", score: 990 },\n { key: \"resolvedModel\", score: 980 },\n { key: \"model\", score: 500 },\n { key: \"xynthesisModel\", score: 120 },\n { key: \"skillModel\", score: 110 },\n] as const;\n\n/** Path segments that boost or penalize a model candidate. */\nconst MODEL_PATH_BONUS: readonly { pattern: RegExp; bonus: number }[] = [\n { pattern: /(^|\\.)response(\\.|$)/i, bonus: 40 },\n { pattern: /(^|\\.)outer\\.input(\\.|$)/i, bonus: 35 },\n { pattern: /(^|\\.)config(?!\\.rawConfig)(\\.|$)/i, bonus: 30 },\n { pattern: /(^|\\.)outer\\.input\\.config(\\.|$)/i, bonus: 28 },\n { pattern: /(^|\\.)usage(\\.|$)/i, bonus: 15 },\n { pattern: /(^|\\.)rawConfig(\\.|$)/i, bonus: -40 },\n { pattern: /workingMemory/i, bonus: -50 },\n { pattern: /requestExample/i, bonus: -80 },\n { pattern: /graphsStudio/i, bonus: -80 },\n];\n\nconst PROVIDER_FIELD_PRIORITY: readonly { key: string; score: number }[] = [\n { key: \"provider\", score: 500 },\n { key: \"providerId\", score: 480 },\n] as const;\n\nconst PROVIDER_PATH_BONUS: readonly { pattern: RegExp; bonus: number }[] = [\n { pattern: /(^|\\.)config(?!\\.rawConfig)(\\.|$)/i, bonus: 30 },\n { pattern: /(^|\\.)outer\\.input(\\.|$)/i, bonus: 20 },\n { pattern: /(^|\\.)rawConfig(\\.|$)/i, bonus: -20 },\n];\n\nconst PROMPT_TOKEN_KEYS = new Set([\n \"prompt\",\n \"prompt_tokens\",\n \"promptTokens\",\n \"input_tokens\",\n \"inputTokens\",\n \"estimatedInputTokens\",\n \"input\",\n]);\n\nconst COMPLETION_TOKEN_KEYS = new Set([\n \"completion\",\n \"completion_tokens\",\n \"completionTokens\",\n \"output_tokens\",\n \"outputTokens\",\n \"estimatedOutputTokens\",\n \"output\",\n]);\n\nconst OPTIONAL_TOKEN_KEYS: Record<string, keyof AiUsageInput[\"tokens\"]> = {\n total: \"total\",\n total_tokens: \"total\",\n totalTokens: \"total\",\n cached: \"cached\",\n cached_tokens: \"cached\",\n cache_read_tokens: \"cached\",\n cacheReadTokens: \"cached\",\n cacheWrite: \"cacheWrite\",\n cache_write_tokens: \"cacheWrite\",\n cacheWriteTokens: \"cacheWrite\",\n reasoning: \"reasoning\",\n reasoning_tokens: \"reasoning\",\n reasoningTokens: \"reasoning\",\n audio: \"audio\",\n audio_tokens: \"audio\",\n image: \"image\",\n image_tokens: \"image\",\n};\n\nexport type FieldProvenance = {\n field: string;\n path: string;\n score: number;\n};\n\nexport type TokenExtractionProvenance = {\n source: \"usage\" | \"tokens\" | \"diagnostics\" | \"estimated\";\n path: string;\n estimated?: boolean;\n};\n\nexport type ExtractUsageInputResult = {\n input: AiUsageInput;\n provenance: {\n model: FieldProvenance;\n modelUsed?: FieldProvenance;\n provider?: FieldProvenance;\n tokens: TokenExtractionProvenance;\n };\n};\n\nexport type ExtractUsageInputOptions = {\n /** Default when no provider field is found (default: `openrouter`). */\n defaultProvider?: string;\n};\n\ntype ModelCandidate = FieldProvenance & { value: string };\ntype ProviderCandidate = FieldProvenance & { value: string };\n\nfunction isPlainObject(v: unknown): v is Record<string, unknown> {\n return v !== null && typeof v === \"object\" && !Array.isArray(v);\n}\n\nfunction modelKeyScore(key: string): number {\n return MODEL_FIELD_PRIORITY.find((e) => e.key === key)?.score ?? 0;\n}\n\nfunction providerKeyScore(key: string): number {\n return PROVIDER_FIELD_PRIORITY.find((e) => e.key === key)?.score ?? 0;\n}\n\nfunction pathBonus(path: string, rules: readonly { pattern: RegExp; bonus: number }[]): number {\n let bonus = 0;\n for (const { pattern, bonus: b } of rules) {\n if (pattern.test(path)) bonus += b;\n }\n return bonus;\n}\n\nfunction normalizeModelValue(v: unknown): string | undefined {\n if (typeof v !== \"string\") return undefined;\n const t = v.trim();\n return t.length > 0 ? t : undefined;\n}\n\nfunction normalizeProviderValue(v: unknown): string | undefined {\n if (typeof v !== \"string\") return undefined;\n const t = v.trim().toLowerCase();\n if (!t || t === \"null\") return undefined;\n return t;\n}\n\nfunction collectModelCandidates(\n node: unknown,\n path: string,\n out: ModelCandidate[],\n depth: number,\n maxDepth: number,\n): void {\n if (depth > maxDepth || node === null || node === undefined) return;\n\n if (isPlainObject(node)) {\n for (const [key, value] of Object.entries(node)) {\n const childPath = path ? `${path}.${key}` : key;\n const base = modelKeyScore(key);\n if (base > 0) {\n const model = normalizeModelValue(value);\n if (model) {\n out.push({\n field: key,\n path: childPath,\n value: model,\n score: base + pathBonus(childPath, MODEL_PATH_BONUS),\n });\n }\n }\n collectModelCandidates(value, childPath, out, depth + 1, maxDepth);\n }\n return;\n }\n\n if (Array.isArray(node)) {\n for (let i = 0; i < node.length; i++) {\n collectModelCandidates(node[i], `${path}[${i}]`, out, depth + 1, maxDepth);\n }\n }\n}\n\nfunction collectProviderCandidates(\n node: unknown,\n path: string,\n out: ProviderCandidate[],\n depth: number,\n maxDepth: number,\n): void {\n if (depth > maxDepth || node === null || node === undefined) return;\n\n if (isPlainObject(node)) {\n for (const [key, value] of Object.entries(node)) {\n const childPath = path ? `${path}.${key}` : key;\n const base = providerKeyScore(key);\n if (base > 0) {\n const provider = normalizeProviderValue(value);\n if (provider) {\n out.push({\n field: key,\n path: childPath,\n value: provider,\n score: base + pathBonus(childPath, PROVIDER_PATH_BONUS),\n });\n }\n }\n collectProviderCandidates(value, childPath, out, depth + 1, maxDepth);\n }\n return;\n }\n\n if (Array.isArray(node)) {\n for (let i = 0; i < node.length; i++) {\n collectProviderCandidates(node[i], `${path}[${i}]`, out, depth + 1, maxDepth);\n }\n }\n}\n\nfunction readNumber(obj: Record<string, unknown>, keys: Set<string>): number | undefined {\n for (const [k, v] of Object.entries(obj)) {\n if (!keys.has(k)) continue;\n if (typeof v === \"number\" && Number.isFinite(v) && v >= 0) return v;\n }\n return undefined;\n}\n\nfunction readOptionalNumbers(\n obj: Record<string, unknown>,\n): Partial<AiUsageInput[\"tokens\"]> {\n const extra: Partial<AiUsageInput[\"tokens\"]> = {};\n for (const [k, v] of Object.entries(obj)) {\n const target = OPTIONAL_TOKEN_KEYS[k];\n if (!target || typeof v !== \"number\" || !Number.isFinite(v) || v < 0) continue;\n extra[target] = v;\n }\n return extra;\n}\n\nfunction looksLikeUsageObject(obj: Record<string, unknown>): boolean {\n const hasPrompt = readNumber(obj, PROMPT_TOKEN_KEYS) !== undefined;\n const hasCompletion = readNumber(obj, COMPLETION_TOKEN_KEYS) !== undefined;\n return hasPrompt && hasCompletion;\n}\n\nfunction looksLikeDiagnosticsObject(obj: Record<string, unknown>): boolean {\n return (\n typeof obj.estimatedInputTokens === \"number\" &&\n typeof obj.estimatedOutputTokens === \"number\"\n );\n}\n\ntype TokenCandidate = {\n tokens: AiUsageInput[\"tokens\"];\n provenance: TokenExtractionProvenance;\n score: number;\n};\n\nfunction tokensFromObject(\n obj: Record<string, unknown>,\n source: TokenExtractionProvenance[\"source\"],\n path: string,\n estimated: boolean,\n score: number,\n): TokenCandidate | null {\n const prompt = readNumber(obj, PROMPT_TOKEN_KEYS);\n const completion = readNumber(obj, COMPLETION_TOKEN_KEYS);\n if (prompt === undefined || completion === undefined) return null;\n\n const extra = readOptionalNumbers(obj);\n const total =\n typeof extra.total === \"number\" ? extra.total : prompt + completion;\n\n return {\n tokens: {\n prompt,\n completion,\n total,\n ...extra,\n },\n provenance: { source, path, estimated },\n score,\n };\n}\n\nfunction collectTokenCandidates(\n node: unknown,\n path: string,\n out: TokenCandidate[],\n depth: number,\n maxDepth: number,\n): void {\n if (depth > maxDepth || node === null || node === undefined) return;\n\n if (isPlainObject(node)) {\n if (path.endsWith(\"diagnostics\") || looksLikeDiagnosticsObject(node)) {\n const cand = tokensFromObject(node, \"diagnostics\", path, true, 200);\n if (cand) out.push(cand);\n } else if (path.endsWith(\"usage\") || path.endsWith(\"tokens\") || looksLikeUsageObject(node)) {\n const source = path.endsWith(\"tokens\") ? \"tokens\" : \"usage\";\n const estimated = false;\n const score = path.endsWith(\"usage\") ? 500 : 450;\n const cand = tokensFromObject(node, source, path, estimated, score);\n if (cand) out.push(cand);\n }\n\n for (const [key, value] of Object.entries(node)) {\n const childPath = path ? `${path}.${key}` : key;\n if (key === \"usage\" || key === \"tokens\" || key === \"diagnostics\") {\n if (isPlainObject(value)) {\n collectTokenCandidates(value, childPath, out, depth + 1, maxDepth);\n }\n } else {\n collectTokenCandidates(value, childPath, out, depth + 1, maxDepth);\n }\n }\n return;\n }\n\n if (Array.isArray(node)) {\n for (let i = 0; i < node.length; i++) {\n collectTokenCandidates(node[i], `${path}[${i}]`, out, depth + 1, maxDepth);\n }\n }\n}\n\nfunction pickBestModel(candidates: ModelCandidate[]): ModelCandidate | null {\n if (candidates.length === 0) return null;\n return [...candidates].sort((a, b) => b.score - a.score)[0]!;\n}\n\nfunction pickBestProvider(candidates: ProviderCandidate[]): ProviderCandidate | null {\n if (candidates.length === 0) return null;\n return [...candidates].sort((a, b) => b.score - a.score)[0]!;\n}\n\nfunction pickBestTokens(candidates: TokenCandidate[]): TokenCandidate | null {\n if (candidates.length === 0) return null;\n return [...candidates].sort((a, b) => b.score - a.score)[0]!;\n}\n\nfunction inferProviderFromModel(model: string, fallback: string): string {\n const slash = model.indexOf(\"/\");\n if (slash > 0) {\n const prefix = model.slice(0, slash).toLowerCase();\n if (prefix !== \"openrouter\") return prefix;\n }\n return fallback;\n}\n\n/**\n * Extract {@link AiUsageInput} from activity logs, gateway records, MongoDB exports,\n * or any nested JSON shape (e.g. `outer.input`, `config`, `metadata.diagnostics`).\n */\nexport function extractUsageInput(\n record: unknown,\n options: ExtractUsageInputOptions = {},\n): ExtractUsageInputResult {\n const defaultProvider = options.defaultProvider ?? \"openrouter\";\n const maxDepth = 24;\n\n const modelCandidates: ModelCandidate[] = [];\n const providerCandidates: ProviderCandidate[] = [];\n const tokenCandidates: TokenCandidate[] = [];\n\n collectModelCandidates(record, \"\", modelCandidates, 0, maxDepth);\n collectProviderCandidates(record, \"\", providerCandidates, 0, maxDepth);\n collectTokenCandidates(record, \"\", tokenCandidates, 0, maxDepth);\n\n const bestModel = pickBestModel(modelCandidates);\n if (!bestModel) {\n throw new Error(\n \"[ai-tools] Could not extract a model from the record (looked for usedModel, modelUsed, model, …).\",\n );\n }\n\n const runtimeFields = new Set([\"usedModel\", \"modelUsed\", \"resolvedModel\"]);\n const isRuntimeModel = runtimeFields.has(bestModel.field);\n const requestModel = modelCandidates.find(\n (c) => c.field === \"model\" && c.path !== bestModel.path,\n );\n\n const bestProvider = pickBestProvider(providerCandidates);\n const provider =\n bestProvider?.value ??\n inferProviderFromModel(bestModel.value, defaultProvider);\n\n const bestTokens = pickBestTokens(tokenCandidates);\n if (!bestTokens) {\n throw new Error(\n \"[ai-tools] Could not extract token usage from the record (usage, tokens, or metadata.diagnostics).\",\n );\n }\n\n const input: AiUsageInput = {\n tokens: bestTokens.tokens,\n provider,\n ...(isRuntimeModel\n ? { modelUsed: bestModel.value, model: requestModel?.value }\n : { model: bestModel.value }),\n };\n\n const provenance: ExtractUsageInputResult[\"provenance\"] = {\n model: {\n field: bestModel.field,\n path: bestModel.path,\n score: bestModel.score,\n },\n tokens: bestTokens.provenance,\n };\n\n if (bestProvider) {\n provenance.provider = {\n field: bestProvider.field,\n path: bestProvider.path,\n score: bestProvider.score,\n };\n }\n\n if (isRuntimeModel && requestModel) {\n provenance.modelUsed = {\n field: bestModel.field,\n path: bestModel.path,\n score: bestModel.score,\n };\n } else if (input.modelUsed) {\n provenance.modelUsed = provenance.model;\n }\n\n return { input, provenance };\n}\n","import type { AiUsageInput } from \"./types.js\";\n\n/** Prefer runtime id (`usedModel` / `modelUsed`); fall back to `model`. */\nexport function resolveUsageModel(input: AiUsageInput): string {\n const value = input.usedModel ?? input.modelUsed ?? input.model;\n if (!value?.trim()) {\n throw new Error(\n \"[ai-tools] Cost calculation requires `usedModel`, `modelUsed`, or `model` on usage input.\",\n );\n }\n return value.trim();\n}\n","import type { AIModelPricing } from \"@x12i/ai-profiles\";\nimport {\n DEFAULT_OPENROUTER_MARKUP_RATE,\n PROFILE_TIERED_CONTEXT_THRESHOLD,\n} from \"./constants.js\";\nimport type { AiModelPricing, AiUsageInput } from \"./types.js\";\n\nconst TOKENS_PER_UNIT = 1_000_000;\n\nfunction usdPerToken(perMillion?: number): number {\n return (perMillion ?? 0) / TOKENS_PER_UNIT;\n}\n\nfunction pickInputRatePerMillion(\n pricing: AIModelPricing,\n promptTokens: number,\n): number | undefined {\n if (\n pricing.inputBelow200k !== undefined &&\n pricing.inputAbove200k !== undefined\n ) {\n return promptTokens <= PROFILE_TIERED_CONTEXT_THRESHOLD\n ? pricing.inputBelow200k\n : pricing.inputAbove200k;\n }\n return pricing.input ?? pricing.inputBelow200k ?? pricing.inputAbove200k;\n}\n\nfunction pickOutputRatePerMillion(\n pricing: AIModelPricing,\n promptTokens: number,\n): number | undefined {\n if (\n pricing.outputBelow200k !== undefined &&\n pricing.outputAbove200k !== undefined\n ) {\n return promptTokens <= PROFILE_TIERED_CONTEXT_THRESHOLD\n ? pricing.outputBelow200k\n : pricing.outputAbove200k;\n }\n return pricing.output ?? pricing.outputBelow200k ?? pricing.outputAbove200k;\n}\n\nexport type AiProfilesPricingOptions = {\n promptTokens?: number;\n routedViaOpenRouter?: boolean;\n};\n\nexport function aiProfilesPricingToCatalogPricing(\n pricing: AIModelPricing,\n pricedAt: string,\n options: AiProfilesPricingOptions = {},\n): AiModelPricing {\n const promptTokens = options.promptTokens ?? 0;\n const promptUsdPerToken = usdPerToken(pickInputRatePerMillion(pricing, promptTokens));\n const completionUsdPerToken = usdPerToken(\n pickOutputRatePerMillion(pricing, promptTokens),\n );\n\n const snapshot: AiModelPricing = {\n promptUsdPerToken,\n completionUsdPerToken,\n cacheReadUsdPerToken: usdPerToken(pricing.cachedInput ?? pricing.cacheHit),\n cacheWriteUsdPerToken: usdPerToken(pricing.cacheWrite5m ?? pricing.cacheWrite1h),\n imageUsdPerUnit: 0,\n requestUsdPerRequest: 0,\n pricedAt,\n source: \"manual\",\n };\n\n if (options.routedViaOpenRouter) {\n snapshot.openRouterMarkupUsdPerInputToken =\n promptUsdPerToken * DEFAULT_OPENROUTER_MARKUP_RATE;\n snapshot.openRouterMarkupUsdPerOutputToken =\n completionUsdPerToken * DEFAULT_OPENROUTER_MARKUP_RATE;\n }\n\n return snapshot;\n}\n\nexport function computeCostFromPricing(\n input: AiUsageInput,\n pricing: AiModelPricing,\n routedViaOpenRouter: boolean,\n includeBreakdown: boolean,\n): { cost: number; breakdown?: import(\"./types.js\").AiCostResult[\"breakdown\"] } {\n const { tokens } = input;\n\n let promptCost = tokens.prompt * pricing.promptUsdPerToken;\n let completionCost = tokens.completion * pricing.completionUsdPerToken;\n\n const cachingCost =\n (tokens.cacheWrite ?? 0) * (pricing.cacheWriteUsdPerToken ?? 0) +\n (tokens.cached ?? 0) * (pricing.cacheReadUsdPerToken ?? 0);\n\n const reasoningCost =\n (tokens.reasoning ?? 0) *\n (pricing.reasoningUsdPerToken ?? pricing.promptUsdPerToken);\n\n const audioCost = (tokens.audio ?? 0) * pricing.promptUsdPerToken;\n const imageCost = (tokens.image ?? 0) * (pricing.imageUsdPerUnit ?? 0);\n const requestFlat = pricing.requestUsdPerRequest;\n\n if (routedViaOpenRouter) {\n promptCost +=\n tokens.prompt * (pricing.openRouterMarkupUsdPerInputToken ?? 0);\n completionCost +=\n tokens.completion * (pricing.openRouterMarkupUsdPerOutputToken ?? 0);\n }\n\n const cost =\n promptCost +\n completionCost +\n cachingCost +\n reasoningCost +\n audioCost +\n imageCost +\n requestFlat;\n\n if (!includeBreakdown) {\n return { cost };\n }\n\n return {\n cost,\n breakdown: {\n promptCostUsd: promptCost,\n completionCostUsd: completionCost,\n cachingCostUsd: cachingCost || undefined,\n reasoningCostUsd: reasoningCost || undefined,\n audioCostUsd: audioCost || undefined,\n imageCostUsd: imageCost || undefined,\n requestFlatCostUsd: requestFlat || undefined,\n },\n };\n}\n","import type { AliasRegistry } from \"../aliases/AliasRegistry.js\";\nimport type { AiModelsCatalogClient } from \"../catalog/AiModelsCatalogClient.js\";\nimport { UnknownModelCostError } from \"../errors.js\";\nimport { normalizeString } from \"../sync/modelNameResolver/normalize.js\";\nimport { stripModelVersionSuffix } from \"../sync/modelNameResolver/stripVersionSuffix.js\";\nimport type {\n ModelResolutionResult,\n ModelResolverOptions,\n} from \"../sync/modelNameResolver/types.js\";\nimport { matchModelInAiProfiles } from \"./aiProfilesMatch.js\";\nimport {\n buildCatalogResolveAttempts,\n isLocalProvider,\n isLocalProviderResolution,\n resolveFromCatalogAttempts,\n resolveRoutedViaOpenRouter,\n} from \"./costModelResolution.js\";\nimport {\n aiProfilesPricingToCatalogPricing,\n computeCostFromPricing,\n} from \"./profilePricing.js\";\nimport { enrichCostResult, toCostExtraction } from \"./enrichCostResult.js\";\nimport {\n extractUsageInput,\n type ExtractUsageInputOptions,\n} from \"./extractUsageInput.js\";\nimport { resolveUsageModel } from \"./resolveUsageModel.js\";\nimport type { AiCostResult, AiCostWarning, AiModelPricing, AiUsageInput } from \"./types.js\";\n\nexport type CostCalculatorOptions = {\n aliasRegistry?: AliasRegistry;\n includeBreakdown?: boolean;\n resolverOptions?: ModelResolverOptions;\n /** When true, throw {@link UnknownModelCostError} instead of zero-cost fallback. */\n throwOnUnknownModel?: boolean;\n};\n\nfunction emptyPricing(): AiModelPricing {\n return {\n promptUsdPerToken: 0,\n completionUsdPerToken: 0,\n imageUsdPerUnit: 0,\n requestUsdPerRequest: 0,\n pricedAt: new Date().toISOString(),\n source: \"manual\",\n };\n}\n\nfunction mergeAttempts(\n ...groups: ReturnType<typeof buildCatalogResolveAttempts>[]\n): ReturnType<typeof buildCatalogResolveAttempts> {\n const seen = new Set<string>();\n const out: ReturnType<typeof buildCatalogResolveAttempts> = [];\n for (const group of groups) {\n for (const a of group) {\n const key = `${a.provider ?? \"\"}\\0${a.model}`;\n if (seen.has(key)) continue;\n seen.add(key);\n out.push(a);\n }\n }\n return out;\n}\n\nexport class CostCalculator {\n private readonly aliasRegistry?: AliasRegistry;\n private readonly includeBreakdown: boolean;\n private readonly resolverOptions?: ModelResolverOptions;\n private readonly throwOnUnknownModel: boolean;\n\n constructor(\n private readonly catalog: AiModelsCatalogClient,\n options: CostCalculatorOptions = {},\n ) {\n this.aliasRegistry = options.aliasRegistry;\n this.includeBreakdown = options.includeBreakdown ?? true;\n this.resolverOptions = options.resolverOptions;\n this.throwOnUnknownModel = options.throwOnUnknownModel ?? false;\n }\n\n /**\n * Extract model, provider, and token usage from an activity / gateway record\n * (MongoDB export, nested `outer`, `config`, `metadata.diagnostics`, etc.)\n * then run {@link calculate}.\n */\n async calculateFromRecord(\n record: unknown,\n extractOptions?: ExtractUsageInputOptions,\n ): Promise<AiCostResult> {\n const { input, provenance } = extractUsageInput(record, extractOptions);\n const warnings: AiCostWarning[] = [];\n if (provenance.tokens.estimated) {\n warnings.push({\n code: \"ESTIMATED_TOKEN_USAGE\",\n message: `Token counts are estimates from ${provenance.tokens.path} (not billed usage).`,\n });\n }\n const result = await this.calculate(input);\n const enriched = enrichCostResult(result, input, toCostExtraction(provenance));\n if (warnings.length > 0) {\n enriched.warnings = [...(enriched.warnings ?? []), ...warnings];\n }\n return enriched;\n }\n\n async calculate(input: AiUsageInput): Promise<AiCostResult> {\n const modelInput = resolveUsageModel(input);\n const resolverOpts = {\n ...this.resolverOptions,\n aliasRegistry: this.aliasRegistry ?? this.resolverOptions?.aliasRegistry,\n };\n\n let resolved = await resolveFromCatalogAttempts(\n this.catalog,\n buildCatalogResolveAttempts(modelInput, input.provider),\n resolverOpts,\n );\n\n if (isLocalProviderResolution(resolved, input.provider)) {\n return this.localProviderResult(modelInput, input, resolved);\n }\n\n let profileMatch = null as Awaited<ReturnType<typeof matchModelInAiProfiles>>;\n const warnings: AiCostWarning[] = [];\n\n if (!resolved?.found || !resolved.record) {\n if (!isLocalProvider(input.provider)) {\n profileMatch = await matchModelInAiProfiles(modelInput, input.provider, {\n catalogLane: this.resolverOptions?.catalogLane,\n });\n }\n if (profileMatch) {\n resolved = await resolveFromCatalogAttempts(\n this.catalog,\n mergeAttempts(\n buildCatalogResolveAttempts(\n profileMatch.canonicalModelId,\n input.provider ?? profileMatch.provider,\n ),\n buildCatalogResolveAttempts(\n profileMatch.canonicalModelId,\n profileMatch.provider,\n ),\n ),\n resolverOpts,\n );\n }\n\n if (isLocalProviderResolution(resolved, input.provider)) {\n return this.localProviderResult(modelInput, input, resolved);\n }\n\n if ((!resolved?.found || !resolved.record) && profileMatch?.pricing) {\n const routedViaOpenRouter = resolveRoutedViaOpenRouter(\n input.provider,\n resolved,\n profileMatch.canonicalModelId,\n resolverOpts?.routingEnv,\n );\n const pricing = aiProfilesPricingToCatalogPricing(\n profileMatch.pricing,\n new Date().toISOString(),\n {\n promptTokens: input.tokens.prompt,\n routedViaOpenRouter,\n },\n );\n const { cost, breakdown } = computeCostFromPricing(\n input,\n pricing,\n routedViaOpenRouter,\n this.includeBreakdown,\n );\n\n warnings.push({\n code: \"AI_PROFILES_ESTIMATE\",\n message: `Catalog has no pricing for \"${modelInput}\"; estimated from ai-profiles (${profileMatch.matchedVia} → ${profileMatch.canonicalModelId}).`,\n });\n if (\n routedViaOpenRouter &&\n pricing.openRouterMarkupUsdPerInputToken !== undefined\n ) {\n warnings.push({\n code: \"OPENROUTER_MARKUP_ESTIMATED\",\n message:\n \"OpenRouter markup estimated at 5% of base token rates (catalog markup fields absent).\",\n });\n }\n\n console.warn(`[ai-tools] ${warnings.map((w) => w.message).join(\" \")}`);\n\n return this.finish(\n {\n cost,\n breakdown,\n resolvedModelId: profileMatch.canonicalModelId,\n routedViaOpenRouter,\n isAuthoritative: false,\n pricingSnapshot: pricing,\n source: \"ai-profiles\",\n warnings,\n },\n input,\n resolved,\n );\n }\n }\n\n if (!resolved?.found || !resolved.record) {\n return this.unknownModelResult(modelInput, input, resolved);\n }\n\n const { record, modelId } = resolved;\n const routedViaOpenRouter = resolveRoutedViaOpenRouter(\n input.provider,\n resolved,\n modelId,\n resolverOpts?.routingEnv,\n );\n const pricing = record.pricing;\n const { cost, breakdown } = computeCostFromPricing(\n input,\n pricing,\n routedViaOpenRouter,\n this.includeBreakdown,\n );\n\n return this.finish(\n {\n cost,\n breakdown,\n resolvedModelId: modelId,\n routedViaOpenRouter,\n isAuthoritative: true,\n pricingSnapshot: pricing,\n source: \"catalog\",\n },\n input,\n resolved,\n );\n }\n\n private versionSuffixWarnings(\n input: AiUsageInput,\n pricedModelId: string,\n resolved?: ModelResolutionResult | null,\n ): AiCostWarning[] {\n const received = input.usedModel ?? input.modelUsed ?? input.model;\n if (!received) return [];\n\n const normalizedReceived = normalizeString(received);\n const normalizedPriced = normalizeString(pricedModelId);\n if (normalizedReceived === normalizedPriced) return [];\n\n const stripped = stripModelVersionSuffix(received);\n const viaResolver =\n resolved?.found === true &&\n resolved.resolvedVia.some(\n (s) => s === \"version-suffix-strip\" || s === \"date-suffix-strip\",\n );\n const pricedViaStrip =\n stripped !== null && normalizeString(stripped) === normalizedPriced;\n\n if (!viaResolver && !pricedViaStrip) return [];\n\n return [\n {\n code: \"VERSION_SUFFIX_PRICING\",\n message: `Priced using catalog model \"${pricedModelId}\" (no exact pricing for \"${received}\").`,\n },\n ];\n }\n\n private finish(\n partial: Omit<\n AiCostResult,\n \"usage\" | \"provider\" | \"usedModel\" | \"model\" | \"extraction\"\n >,\n input: AiUsageInput,\n resolved?: ModelResolutionResult | null,\n ): AiCostResult {\n const enriched = enrichCostResult(partial, input);\n const suffixWarnings = this.versionSuffixWarnings(\n input,\n partial.resolvedModelId,\n resolved,\n );\n if (suffixWarnings.length > 0) {\n enriched.warnings = [...(enriched.warnings ?? []), ...suffixWarnings];\n }\n return enriched;\n }\n\n private localProviderResult(\n modelInput: string,\n input: AiUsageInput,\n resolved: Awaited<ReturnType<typeof resolveFromCatalogAttempts>>,\n ): AiCostResult {\n const warnings: AiCostWarning[] = [\n {\n code: \"LOCAL_PROVIDER_NO_PRICING\",\n message: `Local provider \"${input.provider}\" has no catalog pricing for \"${modelInput}\".`,\n },\n ];\n console.warn(`[ai-tools] ${warnings[0]!.message}`);\n return this.finish(\n {\n cost: 0,\n resolvedModelId: resolved?.found ? resolved.modelId : modelInput,\n routedViaOpenRouter: false,\n isAuthoritative: false,\n pricingSnapshot: emptyPricing(),\n source: \"local\",\n warnings,\n },\n input,\n );\n }\n\n private unknownModelResult(\n modelInput: string,\n input: AiUsageInput,\n resolved: Awaited<ReturnType<typeof resolveFromCatalogAttempts>>,\n ): AiCostResult {\n if (this.throwOnUnknownModel) {\n throw new UnknownModelCostError(modelInput, input.provider);\n }\n\n const warnings: AiCostWarning[] = [\n {\n code: \"UNKNOWN_MODEL\",\n message: `Unknown model \"${modelInput}\" (provider: \"${input.provider}\") — returning zero-cost fallback.`,\n },\n ];\n console.warn(`[ai-tools] ${warnings[0]!.message}`);\n\n return this.finish(\n {\n cost: 0,\n resolvedModelId: modelInput,\n routedViaOpenRouter: resolveRoutedViaOpenRouter(\n input.provider,\n resolved,\n modelInput,\n this.resolverOptions?.routingEnv,\n ),\n isAuthoritative: false,\n pricingSnapshot: emptyPricing(),\n source: \"estimate-fallback\",\n unknownModel: true,\n warnings,\n },\n input,\n );\n }\n}\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunk3JDAPUZMcjs = require('./chunk-3JDAPUZM.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkXKJFO6VGcjs = require('./chunk-XKJFO6VG.cjs');
|
|
7
7
|
|
|
8
8
|
// src/models/filterModels.ts
|
|
9
9
|
function matchesSearch(record, search) {
|
|
@@ -49,7 +49,7 @@ function countModels(models, filters = {}) {
|
|
|
49
49
|
var AiModelsService = class {
|
|
50
50
|
|
|
51
51
|
constructor(options = {}) {
|
|
52
|
-
this.client = new (0,
|
|
52
|
+
this.client = new (0, _chunkXKJFO6VGcjs.AiModelsCatalogClient)(options);
|
|
53
53
|
}
|
|
54
54
|
async getAllModels() {
|
|
55
55
|
return this.client.getAllModels();
|
|
@@ -73,7 +73,7 @@ var AiModelsService = class {
|
|
|
73
73
|
return this.client.resolveModel({ model: modelIdOrAlias, provider });
|
|
74
74
|
}
|
|
75
75
|
async resolveVendor(model, options) {
|
|
76
|
-
return
|
|
76
|
+
return _chunk3JDAPUZMcjs.resolveModelVendor.call(void 0, model, this.client, options);
|
|
77
77
|
}
|
|
78
78
|
async refresh() {
|
|
79
79
|
await this.client.refresh();
|
|
@@ -89,4 +89,4 @@ async function getModelInfo(modelIdOrAlias, options = {}, provider) {
|
|
|
89
89
|
|
|
90
90
|
|
|
91
91
|
exports.filterModels = filterModels; exports.countModels = countModels; exports.AiModelsService = AiModelsService; exports.getModelInfo = getModelInfo;
|
|
92
|
-
//# sourceMappingURL=chunk-
|
|
92
|
+
//# sourceMappingURL=chunk-EE3Z75GO.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/ami/Documents/prometheus/x12i/ai-tools/dist/chunk-
|
|
1
|
+
{"version":3,"sources":["/Users/ami/Documents/prometheus/x12i/ai-tools/dist/chunk-EE3Z75GO.cjs","../src/models/filterModels.ts","../src/models/AiModelsService.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACA;ACLA,SAAS,aAAA,CAAc,MAAA,EAAuB,MAAA,EAAyB;AACrE,EAAA,MAAM,EAAA,EAAI,MAAA,CAAO,WAAA,CAAY,CAAA;AAC7B,EAAA,OACE,MAAA,CAAO,OAAA,CAAQ,WAAA,CAAY,CAAA,CAAE,QAAA,CAAS,CAAC,EAAA,GACvC,MAAA,CAAO,IAAA,CAAK,WAAA,CAAY,CAAA,CAAE,QAAA,CAAS,CAAC,EAAA,GACpC,MAAA,CAAO,WAAA,CAAY,WAAA,CAAY,CAAA,CAAE,QAAA,CAAS,CAAC,EAAA,GAC3C,MAAA,CAAO,aAAA,CAAc,WAAA,CAAY,CAAA,CAAE,QAAA,CAAS,CAAC,EAAA,GAC7C,MAAA,CAAO,OAAA,CAAQ,IAAA,CAAK,CAAC,CAAA,EAAA,GAAM,CAAA,CAAE,WAAA,CAAY,CAAA,CAAE,QAAA,CAAS,CAAC,CAAC,CAAA;AAE1D;AAEO,SAAS,YAAA,CACd,MAAA,EACA,QAAA,EAA4B,CAAC,CAAA,EACZ;AACjB,EAAA,IAAI,KAAA,EAAO,CAAC,GAAG,MAAM,CAAA;AAErB,EAAA,GAAA,CAAI,OAAA,CAAQ,UAAA,EAAY;AACtB,IAAA,KAAA,EAAO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A,MAAM,IAAA,CAAK,MAAA,CAAO,OAAA,CAAQ,CAAA;AAAA,EAC5B;AACF,CAAA;AAEA,MAAA,SAAsB,YAAA,CACpB,cAAA,EACA,QAAA,EAAkC,CAAC,CAAA,EACnC,QAAA,EAC+B;AAC/B,EAAA,OAAO,IAAI,eAAA,CAAgB,OAAO,CAAA,CAAE,YAAA,CAAa,cAAA,EAAgB,QAAQ,CAAA;AAC3E;AFeA;AACA;AACE;AACA;AACA;AACA;AACF,uJAAC","file":"/Users/ami/Documents/prometheus/x12i/ai-tools/dist/chunk-EE3Z75GO.cjs","sourcesContent":[null,"import type { AiModelRecord, ModelListFilters } from \"./types.js\";\n\nfunction matchesSearch(record: AiModelRecord, search: string): boolean {\n const q = search.toLowerCase();\n return (\n record.modelId.toLowerCase().includes(q) ||\n record.name.toLowerCase().includes(q) ||\n record.description.toLowerCase().includes(q) ||\n record.canonicalSlug.toLowerCase().includes(q) ||\n record.aliases.some((a) => a.toLowerCase().includes(q))\n );\n}\n\nexport function filterModels(\n models: Iterable<AiModelRecord>,\n filters: ModelListFilters = {},\n): AiModelRecord[] {\n let list = [...models];\n\n if (filters.providerId) {\n list = list.filter((m) => m.providerId === filters.providerId);\n }\n if (filters.status) {\n list = list.filter((m) => m.status === filters.status);\n }\n if (filters.outputModality) {\n list = list.filter((m) => m.outputModalities.includes(filters.outputModality!));\n }\n if (filters.inputModality) {\n list = list.filter((m) => m.inputModalities.includes(filters.inputModality!));\n }\n if (filters.supportedParameter) {\n list = list.filter((m) => m.supportedParameters.includes(filters.supportedParameter!));\n }\n if (filters.supportsTools !== undefined) {\n list = list.filter((m) => m.supportsTools === filters.supportsTools);\n }\n if (filters.supportsReasoning !== undefined) {\n list = list.filter((m) => m.supportsReasoning === filters.supportsReasoning);\n }\n if (filters.search) {\n list = list.filter((m) => matchesSearch(m, filters.search!));\n }\n\n list.sort((a, b) => a.name.localeCompare(b.name));\n\n const offset = filters.offset ?? 0;\n const limit = filters.limit ?? list.length;\n return list.slice(offset, offset + limit);\n}\n\nexport function countModels(\n models: Iterable<AiModelRecord>,\n filters: Omit<ModelListFilters, \"limit\" | \"offset\"> = {},\n): number {\n return filterModels(models, { ...filters, limit: Number.MAX_SAFE_INTEGER, offset: 0 }).length;\n}\n","import { AiModelsCatalogClient } from \"../catalog/AiModelsCatalogClient.js\";\nimport type { AiModelsCatalogClientOptions } from \"../catalog/AiModelsCatalogClient.js\";\nimport { countModels, filterModels } from \"./filterModels.js\";\nimport type { AiModelRecord, ModelListFilters, ModelListResult } from \"./types.js\";\nimport {\n resolveModelVendor,\n type ModelVendorRef,\n type ResolveModelVendorOptions,\n} from \"../cost/resolveModelVendor.js\";\n\nexport type AiModelsServiceOptions = AiModelsCatalogClientOptions;\n\n/**\n * High-level model catalog API — list, filter, count, and get full model info.\n */\nexport class AiModelsService {\n private readonly client: AiModelsCatalogClient;\n\n constructor(options: AiModelsServiceOptions = {}) {\n this.client = new AiModelsCatalogClient(options);\n }\n\n async getAllModels(): Promise<Map<string, AiModelRecord>> {\n return this.client.getAllModels();\n }\n\n async listModels(filters: ModelListFilters = {}): Promise<ModelListResult> {\n const all = await this.getAllModels();\n const total = countModels(all.values(), filters);\n const limit = filters.limit ?? 50;\n const offset = filters.offset ?? 0;\n const models = filterModels(all.values(), { ...filters, limit, offset });\n return { models, total, limit, offset };\n }\n\n async countModels(filters: Omit<ModelListFilters, \"limit\" | \"offset\"> = {}): Promise<number> {\n const all = await this.getAllModels();\n return countModels(all.values(), filters);\n }\n\n async getModelInfo(modelIdOrAlias: string, provider?: string): Promise<AiModelRecord | null> {\n return this.client.getModel(modelIdOrAlias, provider);\n }\n\n async resolve(\n modelIdOrAlias: string,\n provider?: string,\n ): Promise<import(\"../sync/modelNameResolver/types.js\").ModelResolutionResult> {\n return this.client.resolveModel({ model: modelIdOrAlias, provider });\n }\n\n async resolveVendor(\n model: string,\n options?: ResolveModelVendorOptions,\n ): Promise<ModelVendorRef | null> {\n return resolveModelVendor(model, this.client, options);\n }\n\n async refresh(): Promise<void> {\n await this.client.refresh();\n }\n}\n\nexport async function getModelInfo(\n modelIdOrAlias: string,\n options: AiModelsServiceOptions = {},\n provider?: string,\n): Promise<AiModelRecord | null> {\n return new AiModelsService(options).getModelInfo(modelIdOrAlias, provider);\n}\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
resolveModelVendor
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-VR4P5QB2.js";
|
|
4
4
|
import {
|
|
5
5
|
AiModelsCatalogClient
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-LHJV2YLY.js";
|
|
7
7
|
|
|
8
8
|
// src/models/filterModels.ts
|
|
9
9
|
function matchesSearch(record, search) {
|
|
@@ -89,4 +89,4 @@ export {
|
|
|
89
89
|
AiModelsService,
|
|
90
90
|
getModelInfo
|
|
91
91
|
};
|
|
92
|
-
//# sourceMappingURL=chunk-
|
|
92
|
+
//# sourceMappingURL=chunk-FHJDIYPJ.js.map
|
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
|
|
8
8
|
var _chunkOZE336BLcjs = require('./chunk-OZE336BL.cjs');
|
|
9
9
|
|
|
10
|
+
|
|
11
|
+
var _chunk6T7QT6YHcjs = require('./chunk-6T7QT6YH.cjs');
|
|
12
|
+
|
|
10
13
|
// src/cost/costModelResolution.ts
|
|
11
14
|
function isOpenRouterProvider(provider) {
|
|
12
15
|
return _chunkOZE336BLcjs.normalizeProvider.call(void 0, provider) === "openrouter";
|
|
@@ -107,8 +110,12 @@ var registrySourceOverride;
|
|
|
107
110
|
function registrySource(options) {
|
|
108
111
|
return _nullishCoalesce(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _4 => _4.source]), () => ( registrySourceOverride)), () => ( "auto"));
|
|
109
112
|
}
|
|
110
|
-
function
|
|
111
|
-
return
|
|
113
|
+
function catalogLane(options) {
|
|
114
|
+
return _nullishCoalesce(_optionalChain([options, 'optionalAccess', _5 => _5.catalogLane]), () => ( _chunk6T7QT6YHcjs.TEXT_CATALOG_LANE));
|
|
115
|
+
}
|
|
116
|
+
function profileResolveOptions(source, lane) {
|
|
117
|
+
const base = { source, catalogLane: lane };
|
|
118
|
+
return source === "auto" ? base : { ...base, refresh: true };
|
|
112
119
|
}
|
|
113
120
|
function indexRegistry(registry) {
|
|
114
121
|
const byKey = /* @__PURE__ */ new Map();
|
|
@@ -147,9 +154,11 @@ function choiceEntry(choice, profile, choiceKey) {
|
|
|
147
154
|
};
|
|
148
155
|
}
|
|
149
156
|
async function getProfileIndex(source) {
|
|
150
|
-
const registry = await _aiprofiles.loadAIProfilesRegistry.call(void 0,
|
|
157
|
+
const registry = await _aiprofiles.loadAIProfilesRegistry.call(void 0,
|
|
158
|
+
profileResolveOptions(source, _chunk6T7QT6YHcjs.TEXT_CATALOG_LANE)
|
|
159
|
+
);
|
|
151
160
|
const cacheKey = `${source}:${registry.version}:${_nullishCoalesce(registry.generatedAt, () => ( ""))}:${registry.source}`;
|
|
152
|
-
if (_optionalChain([cachedIndex, 'optionalAccess',
|
|
161
|
+
if (_optionalChain([cachedIndex, 'optionalAccess', _6 => _6.cacheKey]) === cacheKey) {
|
|
153
162
|
return cachedIndex.byKey;
|
|
154
163
|
}
|
|
155
164
|
const byKey = indexRegistry(registry);
|
|
@@ -181,11 +190,11 @@ function pickBest(candidates, model, providerHint) {
|
|
|
181
190
|
return best;
|
|
182
191
|
}
|
|
183
192
|
function isLowConfidenceModelResolution(resolved) {
|
|
184
|
-
return resolved.resolutionKind === "model" && _optionalChain([resolved, 'access',
|
|
193
|
+
return resolved.resolutionKind === "model" && _optionalChain([resolved, 'access', _7 => _7.warnings, 'optionalAccess', _8 => _8.some, 'call', _9 => _9((w) => w.code === "MODEL_INPUT_FALLBACK_GUESS")]) === true;
|
|
185
194
|
}
|
|
186
195
|
function resolvedToMatch(resolved) {
|
|
187
196
|
const direct = resolved.invocation.direct;
|
|
188
|
-
const canonical = _nullishCoalesce(_optionalChain([resolved, 'access',
|
|
197
|
+
const canonical = _nullishCoalesce(_optionalChain([resolved, 'access', _10 => _10.invocation, 'access', _11 => _11.openrouter, 'optionalAccess', _12 => _12.modelId]), () => ( _aiprofiles.buildOpenRouterModelId.call(void 0, direct.provider, direct.modelId)));
|
|
189
198
|
return {
|
|
190
199
|
provider: _nullishCoalesce(_chunkOZE336BLcjs.normalizeProvider.call(void 0, direct.provider), () => ( direct.provider)),
|
|
191
200
|
modelId: _chunkOZE336BLcjs.normalizeString.call(void 0, direct.modelId),
|
|
@@ -198,16 +207,16 @@ function resolvedToMatch(resolved) {
|
|
|
198
207
|
choice: resolved.choice
|
|
199
208
|
};
|
|
200
209
|
}
|
|
201
|
-
async function fromIndexed(entry, source) {
|
|
210
|
+
async function fromIndexed(entry, source, lane) {
|
|
202
211
|
const resolved = await _aiprofiles.resolveAIProfile.call(void 0, entry.profile, {
|
|
203
212
|
choice: entry.choice,
|
|
204
|
-
...profileResolveOptions(source)
|
|
213
|
+
...profileResolveOptions(source, lane)
|
|
205
214
|
});
|
|
206
215
|
const direct = resolved.invocation.direct;
|
|
207
216
|
return {
|
|
208
217
|
provider: _nullishCoalesce(_chunkOZE336BLcjs.normalizeProvider.call(void 0, direct.provider), () => ( direct.provider)),
|
|
209
218
|
modelId: _chunkOZE336BLcjs.normalizeString.call(void 0, direct.modelId),
|
|
210
|
-
canonicalModelId: _nullishCoalesce(_optionalChain([resolved, 'access',
|
|
219
|
+
canonicalModelId: _nullishCoalesce(_optionalChain([resolved, 'access', _13 => _13.invocation, 'access', _14 => _14.openrouter, 'optionalAccess', _15 => _15.modelId]), () => ( _aiprofiles.buildOpenRouterModelId.call(void 0, direct.provider, direct.modelId))),
|
|
211
220
|
pricing: _nullishCoalesce(resolved.pricing, () => ( entry.pricing)),
|
|
212
221
|
instructionTier: resolved.instructionTier,
|
|
213
222
|
backend: resolved.backend,
|
|
@@ -216,7 +225,7 @@ async function fromIndexed(entry, source) {
|
|
|
216
225
|
choice: resolved.choice
|
|
217
226
|
};
|
|
218
227
|
}
|
|
219
|
-
async function lookupInIndex(index, model, source, provider) {
|
|
228
|
+
async function lookupInIndex(index, model, source, lane, provider) {
|
|
220
229
|
const providerHint = provider ? _chunkOZE336BLcjs.normalizeProvider.call(void 0, provider) : void 0;
|
|
221
230
|
const keys = [
|
|
222
231
|
profileKey(model),
|
|
@@ -243,11 +252,12 @@ async function lookupInIndex(index, model, source, provider) {
|
|
|
243
252
|
unique.set(`${e.profile}:${e.choice}:${e.canonicalModelId}`, e);
|
|
244
253
|
}
|
|
245
254
|
const best = pickBest([...unique.values()], model, providerHint);
|
|
246
|
-
return best ? fromIndexed(best, source) : null;
|
|
255
|
+
return best ? fromIndexed(best, source, lane) : null;
|
|
247
256
|
}
|
|
248
257
|
async function matchModelInAiProfiles(model, provider, options) {
|
|
249
258
|
const source = registrySource(options);
|
|
250
|
-
const
|
|
259
|
+
const lane = catalogLane(options);
|
|
260
|
+
const resolveOpts = profileResolveOptions(source, lane);
|
|
251
261
|
try {
|
|
252
262
|
const resolved = await _aiprofiles.resolveAIProfile.call(void 0, model, resolveOpts);
|
|
253
263
|
if (!isLowConfidenceModelResolution(resolved)) {
|
|
@@ -260,7 +270,7 @@ async function matchModelInAiProfiles(model, provider, options) {
|
|
|
260
270
|
}
|
|
261
271
|
const index = await getProfileIndex(source);
|
|
262
272
|
const hint = providerHintForProfiles(model, provider);
|
|
263
|
-
const direct = await lookupInIndex(index, model, source, hint);
|
|
273
|
+
const direct = await lookupInIndex(index, model, source, lane, hint);
|
|
264
274
|
if (direct) return direct;
|
|
265
275
|
const stripped = _chunkOZE336BLcjs.stripModelVersionSuffix.call(void 0, model);
|
|
266
276
|
if (stripped && stripped !== _chunkOZE336BLcjs.normalizeString.call(void 0, model)) {
|
|
@@ -268,6 +278,7 @@ async function matchModelInAiProfiles(model, provider, options) {
|
|
|
268
278
|
index,
|
|
269
279
|
stripped,
|
|
270
280
|
source,
|
|
281
|
+
lane,
|
|
271
282
|
providerHintForProfiles(stripped, provider)
|
|
272
283
|
);
|
|
273
284
|
}
|
|
@@ -282,4 +293,4 @@ async function matchModelInAiProfiles(model, provider, options) {
|
|
|
282
293
|
|
|
283
294
|
|
|
284
295
|
exports.isLocalProvider = isLocalProvider; exports.isLocalProviderResolution = isLocalProviderResolution; exports.buildCatalogResolveAttempts = buildCatalogResolveAttempts; exports.resolveFromCatalogAttempts = resolveFromCatalogAttempts; exports.resolveRoutedViaOpenRouter = resolveRoutedViaOpenRouter; exports.matchModelInAiProfiles = matchModelInAiProfiles;
|
|
285
|
-
//# sourceMappingURL=chunk-
|
|
296
|
+
//# sourceMappingURL=chunk-H7W5LMP6.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/ami/Documents/prometheus/x12i/ai-tools/dist/chunk-H7W5LMP6.cjs","../src/cost/costModelResolution.ts","../src/cost/aiProfilesMatch.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACA;ACEO,SAAS,oBAAA,CAAqB,QAAA,EAA4B;AAC/D,EAAA,OAAO,iDAAA,QAA0B,EAAA,IAAM,YAAA;AACzC;AAEO,SAAS,eAAA,CAAgB,QAAA,EAA4B;AAC1D,EAAA,MAAM,EAAA,mBAAI,iDAAA,QAA0B,CAAA,UAAK,+CAAA,iBAAgB,QAAA,UAAY,IAAE,GAAA;AACvE,EAAA,OAAO,iCAAA,CAAgB,GAAA,CAAI,CAAC,CAAA;AAC9B;AAGO,SAAS,yBAAA,CACd,QAAA,EACA,aAAA,EACS;AACT,EAAA,GAAA,CAAI,iBAAC,QAAA,2BAAU,QAAA,GAAS,QAAA,CAAS,MAAA,EAAQ,OAAO,KAAA;AAChD,EAAA,GAAA,CAAI,QAAA,CAAS,WAAA,CAAY,QAAA,CAAS,4BAA4B,CAAA,EAAG,OAAO,IAAA;AACxE,EAAA,OAAO,eAAA,CAAgB,aAAa,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;AACT,IAAA;AACS,IAAA;AACT,IAAA;AACS,IAAA;AAEP,IAAA;AAKO,IAAA;AACD,IAAA;AACV,EAAA;AACF;AAEe;AAKP,EAAA;AACI,IAAA;AACL,IAAA;AACJ,EAAA;AACc,EAAA;AACR,EAAA;AACK,IAAA;AACD,IAAA;AACT,IAAA;AAGS,IAAA;AACT,IAAA;AACS,IAAA;AACG,IAAA;AACH,IAAA;AACD,IAAA;AACV,EAAA;AACF;AAEe;AAOP,EAAA;AACO,EAAA;AACA,IAAA;AACA,IAAA;AACb,EAAA;AACI,EAAA;AACQ,IAAA;AACZ,EAAA;AAEgC,EAAA;AACrB,EAAA;AACI,IAAA;AACH,IAAA;AACZ,EAAA;AAEa,EAAA;AACH,EAAA;AACG,IAAA;AACE,MAAA;AACL,QAAA;AACN,MAAA;AACF,IAAA;AACF,EAAA;AAEe,EAAA;AACJ,EAAA;AACE,IAAA;AACb,EAAA;AAEa,EAAA;AACC,EAAA;AAChB;AAMsB;AAKL,EAAA;AACF,EAAA;AACP,EAAA;AAEF,EAAA;AACI,IAAA;AACD,IAAA;AACI,MAAA;AACT,IAAA;AACY,EAAA;AACN,IAAA;AACE,MAAA;AACR,IAAA;AACF,EAAA;AAEc,EAAA;AACD,EAAA;AACE,EAAA;AACH,EAAA;AAEN,EAAA;AACF,EAAA;AACK,IAAA;AACL,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACF,EAAA;AAEO,EAAA;AACT;AFzCiB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/ami/Documents/prometheus/x12i/ai-tools/dist/chunk-H7W5LMP6.cjs","sourcesContent":[null,"import type { AiModelsCatalogClient } from \"../catalog/AiModelsCatalogClient.js\";\nimport { LOCAL_PROVIDERS } from \"../sync/modelNameResolver/constants.js\";\nimport {\n loadOpenRouterRoutingEnv,\n shouldDefaultRouteViaOpenRouter,\n} from \"../sync/openRouterRoutingEnv.js\";\nimport { normalizeProvider, normalizeString } from \"../sync/modelNameResolver/normalize.js\";\nimport type {\n ModelResolutionInput,\n ModelResolutionResult,\n ModelResolverOptions,\n} from \"../sync/modelNameResolver/types.js\";\nimport type { OpenRouterRoutingConfig } from \"../sync/openRouterRoutingEnv.js\";\n\nexport function isOpenRouterProvider(provider?: string): boolean {\n return normalizeProvider(provider) === \"openrouter\";\n}\n\nexport function isLocalProvider(provider?: string): boolean {\n const p = normalizeProvider(provider) ?? normalizeString(provider ?? \"\");\n return LOCAL_PROVIDERS.has(p);\n}\n\n/** Catalog resolver returned success without a priced record (Ollama, LM Studio, …). */\nexport function isLocalProviderResolution(\n resolved: ModelResolutionResult | null,\n inputProvider?: string,\n): boolean {\n if (!resolved?.found || resolved.record) return false;\n if (resolved.resolvedVia.includes(\"local-provider-passthrough\")) return true;\n return isLocalProvider(inputProvider);\n}\n\n/**\n * Vendor id for a model slug (`openai/gpt-4o` → `openai`).\n * Ignores `openrouter` as a provider hint — it is a routing layer, not the model owner.\n */\nexport function underlyingProviderFromModel(\n model: string,\n providerHint?: string,\n): string | undefined {\n const normalized = normalizeString(model);\n if (normalized.includes(\"/\")) {\n const prefix = normalized.split(\"/\")[0]!;\n if (!isOpenRouterProvider(prefix)) return prefix;\n }\n if (providerHint && !isOpenRouterProvider(providerHint)) {\n return normalizeProvider(providerHint);\n }\n return undefined;\n}\n\n/** Provider hint for ai-profiles index lookup (openrouter → underlying vendor). */\nexport function providerHintForProfiles(\n model: string,\n provider?: string,\n): string | undefined {\n if (isOpenRouterProvider(provider)) {\n return underlyingProviderFromModel(model, provider);\n }\n return normalizeProvider(provider);\n}\n\n/**\n * Catalog resolve attempts for direct API and OpenRouter usage.\n * Tries the caller hint, inferred vendor, no hint, and openrouter routing.\n */\nexport function buildCatalogResolveAttempts(\n model: string,\n provider?: string,\n): ModelResolutionInput[] {\n const attempts: ModelResolutionInput[] = [];\n const seen = new Set<string>();\n const add = (m: string, p?: string) => {\n const key = `${p ?? \"\"}\\0${normalizeString(m)}`;\n if (seen.has(key)) return;\n seen.add(key);\n attempts.push({ model: m, provider: p });\n };\n\n add(model, provider);\n\n const underlying = underlyingProviderFromModel(model, provider);\n if (provider) add(model, undefined);\n if (underlying) add(model, underlying);\n if (!isOpenRouterProvider(provider)) {\n add(model, \"openrouter\");\n }\n\n return attempts;\n}\n\nexport async function resolveFromCatalogAttempts(\n catalog: AiModelsCatalogClient,\n attempts: ModelResolutionInput[],\n options?: ModelResolverOptions,\n): Promise<ModelResolutionResult | null> {\n let last: ModelResolutionResult | null = null;\n let localPassthrough: ModelResolutionResult | null = null;\n\n for (const attempt of attempts) {\n const result = await catalog.resolveModel(attempt, options);\n last = result;\n if (result.found && result.record) return result;\n if (\n result.found &&\n !result.record &&\n isLocalProviderResolution(result, attempt.provider)\n ) {\n localPassthrough = result;\n }\n }\n\n return localPassthrough ?? last;\n}\n\nexport function resolveRoutedViaOpenRouter(\n inputProvider: string | undefined,\n resolved: ModelResolutionResult | null,\n modelId?: string,\n routingEnv?: OpenRouterRoutingConfig,\n): boolean {\n const env = routingEnv ?? loadOpenRouterRoutingEnv();\n\n if (isOpenRouterProvider(inputProvider)) return true;\n\n if (resolved?.found) {\n return resolved.routedViaOpenRouter;\n }\n\n const vendor = underlyingProviderFromModel(\n modelId ?? (resolved?.found ? resolved.modelId : \"\") ?? \"\",\n inputProvider,\n );\n if (vendor && shouldDefaultRouteViaOpenRouter(vendor, env)) {\n return true;\n }\n\n return false;\n}\n","import {\n AIProfilesError,\n buildOpenRouterModelId,\n getChoiceOpenRouterModelId,\n getChoicePricing,\n getChoiceVendorModelId,\n loadAIProfilesRegistry,\n resolveAIProfile,\n} from \"@x12i/ai-profiles\";\nimport type {\n AIProfileBackend,\n AIProfileChoice,\n AIModelPricing,\n AIProfilesRegistry,\n InstructionTier,\n ProfileCatalogLane,\n RegistrySourceMode,\n ResolvedAIProfile,\n} from \"@x12i/ai-profiles\";\nimport { TEXT_CATALOG_LANE } from \"../profiles/catalogLane.js\";\nimport { providerHintForProfiles } from \"./costModelResolution.js\";\nimport { normalizeProvider, normalizeString } from \"../sync/modelNameResolver/normalize.js\";\nimport { stripModelVersionSuffix } from \"../sync/modelNameResolver/stripVersionSuffix.js\";\n\nexport type AiProfilesModelMatch = {\n provider: string;\n modelId: string;\n canonicalModelId: string;\n pricing?: AIModelPricing;\n instructionTier: InstructionTier;\n backend: AIProfileBackend;\n matchedVia: \"profile\" | \"shortcut\" | \"profile-alias\" | \"model-id\";\n profile?: string;\n choice?: string;\n};\n\nfunction profileKey(value: string): string {\n return value.trim().toLowerCase();\n}\n\nfunction canonicalModelId(provider: string, modelId: string): string {\n const normalized = normalizeString(modelId);\n if (normalized.includes(\"/\")) return normalized;\n return buildOpenRouterModelId(provider, normalized);\n}\n\ntype IndexedChoice = {\n provider: string;\n modelId: string;\n canonicalModelId: string;\n pricing?: AIModelPricing;\n profile: string;\n choice: string;\n};\n\nlet cachedIndex: {\n cacheKey: string;\n byKey: Map<string, IndexedChoice[]>;\n} | null = null;\n\nexport type MatchModelInAiProfilesOptions = {\n source?: RegistrySourceMode;\n /** OpenRouter catalog lane (required by @x12i/ai-profiles 2.x). Defaults to {@link TEXT_CATALOG_LANE}. */\n catalogLane?: ProfileCatalogLane;\n};\n\n/** When set (tests), overrides default `auto` registry/catalog source. */\nlet registrySourceOverride: RegistrySourceMode | undefined;\n\nfunction registrySource(options?: MatchModelInAiProfilesOptions): RegistrySourceMode {\n return options?.source ?? registrySourceOverride ?? \"auto\";\n}\n\nfunction catalogLane(options?: MatchModelInAiProfilesOptions): ProfileCatalogLane {\n return options?.catalogLane ?? TEXT_CATALOG_LANE;\n}\n\n/** ai-profiles returns a valid in-memory cache before honoring `source`; refresh on explicit sources. */\nfunction profileResolveOptions(\n source: RegistrySourceMode,\n lane: ProfileCatalogLane,\n) {\n const base = { source, catalogLane: lane };\n return source === \"auto\" ? base : { ...base, refresh: true as const };\n}\n\n/** Index bare model ids only — profile/shortcut names resolve via {@link resolveAIProfile}. */\nfunction indexRegistry(registry: AIProfilesRegistry): Map<string, IndexedChoice[]> {\n const byKey = new Map<string, IndexedChoice[]>();\n\n const add = (key: string, entry: IndexedChoice) => {\n const k = profileKey(key);\n if (!k) return;\n const list = byKey.get(k) ?? [];\n if (\n list.some(\n (e) =>\n e.canonicalModelId === entry.canonicalModelId &&\n e.choice === entry.choice &&\n e.profile === entry.profile,\n )\n ) {\n return;\n }\n list.push(entry);\n byKey.set(k, list);\n };\n\n for (const profile of Object.values(registry.profiles)) {\n for (const [choiceKey, choice] of Object.entries(profile.choices)) {\n const entry = choiceEntry(choice, profile.profile, choiceKey);\n add(getChoiceVendorModelId(choice), entry);\n add(canonicalModelId(choice.provider, getChoiceVendorModelId(choice)), entry);\n }\n }\n\n return byKey;\n}\n\nfunction choiceEntry(\n choice: AIProfileChoice,\n profile: string,\n choiceKey: string,\n): IndexedChoice {\n const vendorModelId = getChoiceVendorModelId(choice);\n const provider = normalizeProvider(choice.provider) ?? choice.provider;\n const canonical =\n getChoiceOpenRouterModelId(choice) ??\n canonicalModelId(choice.provider, vendorModelId);\n return {\n provider,\n modelId: normalizeString(vendorModelId),\n canonicalModelId: canonical,\n pricing: getChoicePricing(choice),\n profile,\n choice: choiceKey,\n };\n}\n\nasync function getProfileIndex(\n source: RegistrySourceMode,\n): Promise<Map<string, IndexedChoice[]>> {\n const registry = await loadAIProfilesRegistry(\n profileResolveOptions(source, TEXT_CATALOG_LANE),\n );\n const cacheKey = `${source}:${registry.version}:${registry.generatedAt ?? \"\"}:${registry.source}`;\n if (cachedIndex?.cacheKey === cacheKey) {\n return cachedIndex.byKey;\n }\n const byKey = indexRegistry(registry);\n cachedIndex = { cacheKey, byKey };\n return byKey;\n}\n\nfunction scoreCandidate(\n entry: IndexedChoice,\n model: string,\n providerHint?: string,\n): number {\n const normalized = normalizeString(model);\n let score = 0;\n\n if (normalized === entry.canonicalModelId) score += 100;\n if (normalized === entry.modelId) score += 80;\n if (providerHint && entry.provider === providerHint) score += 50;\n if (entry.pricing) score += 2;\n\n return score;\n}\n\nfunction pickBest(\n candidates: IndexedChoice[],\n model: string,\n providerHint?: string,\n): IndexedChoice | null {\n if (candidates.length === 0) return null;\n if (candidates.length === 1) return candidates[0]!;\n\n let best = candidates[0]!;\n let bestScore = scoreCandidate(best, model, providerHint);\n for (let i = 1; i < candidates.length; i++) {\n const c = candidates[i]!;\n const s = scoreCandidate(c, model, providerHint);\n if (s > bestScore) {\n best = c;\n bestScore = s;\n }\n }\n return best;\n}\n\nfunction isLowConfidenceModelResolution(resolved: ResolvedAIProfile): boolean {\n return (\n resolved.resolutionKind === \"model\" &&\n resolved.warnings?.some((w) => w.code === \"MODEL_INPUT_FALLBACK_GUESS\") === true\n );\n}\n\nfunction resolvedToMatch(resolved: ResolvedAIProfile): AiProfilesModelMatch {\n const direct = resolved.invocation.direct;\n const canonical =\n resolved.invocation.openrouter?.modelId ??\n buildOpenRouterModelId(direct.provider, direct.modelId);\n return {\n provider: normalizeProvider(direct.provider) ?? direct.provider,\n modelId: normalizeString(direct.modelId),\n canonicalModelId: canonical,\n pricing: resolved.pricing,\n instructionTier: resolved.instructionTier,\n backend: resolved.backend,\n matchedVia:\n resolved.resolutionKind === \"model\"\n ? \"model-id\"\n : resolved.shortcut\n ? \"shortcut\"\n : \"profile\",\n profile: resolved.profile,\n choice: resolved.choice,\n };\n}\n\nasync function fromIndexed(\n entry: IndexedChoice,\n source: RegistrySourceMode,\n lane: ProfileCatalogLane,\n): Promise<AiProfilesModelMatch> {\n const resolved = await resolveAIProfile(entry.profile, {\n choice: entry.choice,\n ...profileResolveOptions(source, lane),\n });\n const direct = resolved.invocation.direct;\n return {\n provider: normalizeProvider(direct.provider) ?? direct.provider,\n modelId: normalizeString(direct.modelId),\n canonicalModelId:\n resolved.invocation.openrouter?.modelId ??\n buildOpenRouterModelId(direct.provider, direct.modelId),\n pricing: resolved.pricing ?? entry.pricing,\n instructionTier: resolved.instructionTier,\n backend: resolved.backend,\n matchedVia: \"model-id\",\n profile: resolved.profile,\n choice: resolved.choice,\n };\n}\n\nasync function lookupInIndex(\n index: Map<string, IndexedChoice[]>,\n model: string,\n source: RegistrySourceMode,\n lane: ProfileCatalogLane,\n provider?: string,\n): Promise<AiProfilesModelMatch | null> {\n const providerHint = provider ? normalizeProvider(provider) : undefined;\n const keys = [\n profileKey(model),\n profileKey(normalizeString(model)),\n ];\n if (providerHint) {\n keys.push(profileKey(canonicalModelId(providerHint, model)));\n }\n\n const pooled: IndexedChoice[] = [];\n for (const key of keys) {\n const hits = index.get(key);\n if (hits) pooled.push(...hits);\n }\n\n const bare = normalizeString(model);\n if (!bare.includes(\"/\")) {\n for (const list of index.values()) {\n for (const entry of list) {\n if (entry.modelId === bare) pooled.push(entry);\n }\n }\n }\n\n const unique = new Map<string, IndexedChoice>();\n for (const e of pooled) {\n unique.set(`${e.profile}:${e.choice}:${e.canonicalModelId}`, e);\n }\n\n const best = pickBest([...unique.values()], model, providerHint);\n return best ? fromIndexed(best, source, lane) : null;\n}\n\n/**\n * Resolve a model string via @x12i/ai-profiles — profile/shortcut names, aliases,\n * or a concrete model id that appears on a profile choice.\n */\nexport async function matchModelInAiProfiles(\n model: string,\n provider?: string,\n options?: MatchModelInAiProfilesOptions,\n): Promise<AiProfilesModelMatch | null> {\n const source = registrySource(options);\n const lane = catalogLane(options);\n const resolveOpts = profileResolveOptions(source, lane);\n\n try {\n const resolved = await resolveAIProfile(model, resolveOpts);\n if (!isLowConfidenceModelResolution(resolved)) {\n return resolvedToMatch(resolved);\n }\n } catch (err) {\n if (!(err instanceof AIProfilesError) || err.code !== \"UNKNOWN_PROFILE\") {\n throw err;\n }\n }\n\n const index = await getProfileIndex(source);\n const hint = providerHintForProfiles(model, provider);\n const direct = await lookupInIndex(index, model, source, lane, hint);\n if (direct) return direct;\n\n const stripped = stripModelVersionSuffix(model);\n if (stripped && stripped !== normalizeString(model)) {\n return lookupInIndex(\n index,\n stripped,\n source,\n lane,\n providerHintForProfiles(stripped, provider),\n );\n }\n\n return null;\n}\n\n/** @internal Test-only — reset module cache between tests. */\nexport function resetAiProfilesMatchCacheForTests(\n options?: { source?: RegistrySourceMode },\n): void {\n cachedIndex = null;\n registrySourceOverride = options?.source ?? \"bundled\";\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
matchModelInAiProfiles
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-YERYMWKM.js";
|
|
4
4
|
import {
|
|
5
5
|
computeSupportsReasoning
|
|
6
6
|
} from "./chunk-SQ6NOF4Z.js";
|
|
@@ -11,6 +11,9 @@ import {
|
|
|
11
11
|
normalizeProvider,
|
|
12
12
|
normalizeString
|
|
13
13
|
} from "./chunk-OB44D7RG.js";
|
|
14
|
+
import {
|
|
15
|
+
TEXT_CATALOG_LANE
|
|
16
|
+
} from "./chunk-OPKL4YNL.js";
|
|
14
17
|
|
|
15
18
|
// src/cache/modelCache.ts
|
|
16
19
|
import { createNxCache } from "nx-cache";
|
|
@@ -2003,7 +2006,14 @@ var AiModelsCatalogClient = class {
|
|
|
2003
2006
|
return { ...result, modelId, record };
|
|
2004
2007
|
}
|
|
2005
2008
|
async resolveViaProfile(input, options) {
|
|
2006
|
-
const
|
|
2009
|
+
const profileOpts = {
|
|
2010
|
+
catalogLane: options?.catalogLane ?? TEXT_CATALOG_LANE
|
|
2011
|
+
};
|
|
2012
|
+
const profileMatch = await matchModelInAiProfiles(
|
|
2013
|
+
input.model,
|
|
2014
|
+
input.provider,
|
|
2015
|
+
profileOpts
|
|
2016
|
+
);
|
|
2007
2017
|
if (!profileMatch) return null;
|
|
2008
2018
|
const strategy = profileResolutionStrategy(profileMatch.matchedVia);
|
|
2009
2019
|
const attempts = [];
|
|
@@ -2094,4 +2104,4 @@ export {
|
|
|
2094
2104
|
loadCatalogSourcesCached,
|
|
2095
2105
|
AiModelsCatalogClient
|
|
2096
2106
|
};
|
|
2097
|
-
//# sourceMappingURL=chunk-
|
|
2107
|
+
//# sourceMappingURL=chunk-LHJV2YLY.js.map
|