@x12i/ai-tools 2.1.0 → 2.1.2
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/catalog/index.cjs +5 -5
- package/dist/catalog/index.js +4 -4
- package/dist/{chunk-VYVX46VO.js → chunk-4ILJWO64.js} +53 -33
- package/dist/chunk-4ILJWO64.js.map +1 -0
- package/dist/{chunk-WFRS32EQ.js → chunk-5RW5ARLO.js} +3 -3
- package/dist/{chunk-25O27USJ.js → chunk-7VGEQTJA.js} +2 -2
- package/dist/{chunk-4AIEM4AE.js → chunk-DSDN65JH.js} +3 -3
- package/dist/{chunk-TDO5SDQ3.cjs → chunk-GNOZFRKR.cjs} +45 -44
- package/dist/chunk-GNOZFRKR.cjs.map +1 -0
- package/dist/{chunk-2A6EUGR5.cjs → chunk-H6HDETJK.cjs} +19 -19
- package/dist/{chunk-2A6EUGR5.cjs.map → chunk-H6HDETJK.cjs.map} +1 -1
- package/dist/{chunk-JCMLIXIX.js → chunk-IA4HCHJV.js} +2 -2
- package/dist/{chunk-JCMLIXIX.js.map → chunk-IA4HCHJV.js.map} +1 -1
- package/dist/{chunk-GVFL2LRG.cjs → chunk-IJTDND4V.cjs} +5 -5
- package/dist/{chunk-GVFL2LRG.cjs.map → chunk-IJTDND4V.cjs.map} +1 -1
- package/dist/{chunk-R6P4AWOM.cjs → chunk-JDOFFZJA.cjs} +4 -4
- package/dist/{chunk-R6P4AWOM.cjs.map → chunk-JDOFFZJA.cjs.map} +1 -1
- package/dist/{chunk-SYHLDADG.js → chunk-OB44D7RG.js} +1 -2
- package/dist/{chunk-5XBMNY7Q.cjs → chunk-OZE336BL.cjs} +2 -3
- package/dist/chunk-OZE336BL.cjs.map +1 -0
- package/dist/{chunk-XMOALOYU.js → chunk-RNSXRGIA.js} +30 -26
- package/dist/chunk-RNSXRGIA.js.map +1 -0
- package/dist/{chunk-I6CDT2NG.cjs → chunk-RVQPQI63.cjs} +7 -7
- package/dist/{chunk-I6CDT2NG.cjs.map → chunk-RVQPQI63.cjs.map} +1 -1
- package/dist/chunk-SYDW33AL.cjs +143 -0
- package/dist/chunk-SYDW33AL.cjs.map +1 -0
- package/dist/{chunk-ET5LPVPT.js → chunk-TZHPZGDB.js} +3 -3
- package/dist/chunk-UQ4NSEXF.js +41 -0
- package/dist/chunk-UQ4NSEXF.js.map +1 -0
- package/dist/{chunk-SIR4LDHD.cjs → chunk-UY2VLJN6.cjs} +14 -14
- package/dist/{chunk-SIR4LDHD.cjs.map → chunk-UY2VLJN6.cjs.map} +1 -1
- package/dist/chunk-ZHRU337O.cjs +41 -0
- package/dist/chunk-ZHRU337O.cjs.map +1 -0
- package/dist/cli/index.cjs +17 -17
- package/dist/cli/index.js +8 -8
- package/dist/cost/index.cjs +12 -6
- package/dist/cost/index.cjs.map +1 -1
- package/dist/cost/index.d.cts +3 -3
- package/dist/cost/index.d.ts +3 -3
- package/dist/cost/index.js +11 -5
- package/dist/index.cjs +16 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +15 -9
- package/dist/models/index.cjs +7 -7
- package/dist/models/index.d.cts +1 -1
- package/dist/models/index.d.ts +1 -1
- package/dist/models/index.js +6 -6
- package/dist/resolveModelVendor-B0t5nq-v.d.cts +22 -0
- package/dist/{resolveModelVendor--2JdUZlR.d.ts → resolveModelVendor-DQpJpk0w.d.ts} +1 -1
- package/dist/{resolveModelVendor-BPPvzxE8.d.cts → resolveModelVendor-XvmXsVzo.d.cts} +1 -1
- package/dist/resolveModelVendor-uphYBFMY.d.ts +22 -0
- package/dist/sync/index.cjs +10 -4
- package/dist/sync/index.cjs.map +1 -1
- package/dist/sync/index.d.cts +1 -1
- package/dist/sync/index.d.ts +1 -1
- package/dist/sync/index.js +9 -3
- package/package.json +2 -2
- package/dist/chunk-5XBMNY7Q.cjs.map +0 -1
- package/dist/chunk-EBBJCLJQ.js +0 -29
- package/dist/chunk-EBBJCLJQ.js.map +0 -1
- package/dist/chunk-FISSYP27.cjs +0 -29
- package/dist/chunk-FISSYP27.cjs.map +0 -1
- package/dist/chunk-TDO5SDQ3.cjs.map +0 -1
- package/dist/chunk-TMDWPWKB.cjs +0 -123
- package/dist/chunk-TMDWPWKB.cjs.map +0 -1
- package/dist/chunk-VYVX46VO.js.map +0 -1
- package/dist/chunk-XMOALOYU.js.map +0 -1
- package/dist/resolveModelVendor-Dd4N6Vds.d.cts +0 -16
- package/dist/resolveModelVendor-oKeiH9ig.d.ts +0 -16
- /package/dist/{chunk-WFRS32EQ.js.map → chunk-5RW5ARLO.js.map} +0 -0
- /package/dist/{chunk-25O27USJ.js.map → chunk-7VGEQTJA.js.map} +0 -0
- /package/dist/{chunk-4AIEM4AE.js.map → chunk-DSDN65JH.js.map} +0 -0
- /package/dist/{chunk-SYHLDADG.js.map → chunk-OB44D7RG.js.map} +0 -0
- /package/dist/{chunk-ET5LPVPT.js.map → chunk-TZHPZGDB.js.map} +0 -0
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
normalizeString,
|
|
6
6
|
shouldDefaultRouteViaOpenRouter,
|
|
7
7
|
stripModelVersionSuffix
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-OB44D7RG.js";
|
|
9
9
|
|
|
10
10
|
// src/cost/costModelResolution.ts
|
|
11
11
|
function isOpenRouterProvider(provider) {
|
|
@@ -85,23 +85,22 @@ function resolveRoutedViaOpenRouter(inputProvider, resolved, modelId, routingEnv
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
// src/cost/aiProfilesMatch.ts
|
|
88
|
-
import {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
88
|
+
import {
|
|
89
|
+
AIProfilesError,
|
|
90
|
+
buildOpenRouterModelId,
|
|
91
|
+
getChoiceOpenRouterModelId,
|
|
92
|
+
getChoicePricing,
|
|
93
|
+
getChoiceVendorModelId,
|
|
94
|
+
loadAIProfilesRegistry,
|
|
95
|
+
resolveAIProfile
|
|
96
|
+
} from "@x12i/ai-profiles";
|
|
97
97
|
function profileKey(value) {
|
|
98
98
|
return value.trim().toLowerCase();
|
|
99
99
|
}
|
|
100
100
|
function canonicalModelId(provider, modelId) {
|
|
101
101
|
const normalized = normalizeString(modelId);
|
|
102
102
|
if (normalized.includes("/")) return normalized;
|
|
103
|
-
|
|
104
|
-
return `${p}/${normalized}`;
|
|
103
|
+
return buildOpenRouterModelId(provider, normalized);
|
|
105
104
|
}
|
|
106
105
|
var cachedIndex = null;
|
|
107
106
|
function indexRegistry(registry) {
|
|
@@ -121,25 +120,27 @@ function indexRegistry(registry) {
|
|
|
121
120
|
for (const profile of Object.values(registry.profiles)) {
|
|
122
121
|
for (const [choiceKey, choice] of Object.entries(profile.choices)) {
|
|
123
122
|
const entry = choiceEntry(choice, profile.profile, choiceKey);
|
|
124
|
-
add(choice
|
|
125
|
-
add(canonicalModelId(choice.provider, choice
|
|
123
|
+
add(getChoiceVendorModelId(choice), entry);
|
|
124
|
+
add(canonicalModelId(choice.provider, getChoiceVendorModelId(choice)), entry);
|
|
126
125
|
}
|
|
127
126
|
}
|
|
128
127
|
return byKey;
|
|
129
128
|
}
|
|
130
129
|
function choiceEntry(choice, profile, choiceKey) {
|
|
131
|
-
const
|
|
130
|
+
const vendorModelId = getChoiceVendorModelId(choice);
|
|
131
|
+
const provider = normalizeProvider(choice.provider) ?? choice.provider;
|
|
132
|
+
const canonical = getChoiceOpenRouterModelId(choice) ?? canonicalModelId(choice.provider, vendorModelId);
|
|
132
133
|
return {
|
|
133
|
-
provider
|
|
134
|
-
modelId: normalizeString(
|
|
134
|
+
provider,
|
|
135
|
+
modelId: normalizeString(vendorModelId),
|
|
135
136
|
canonicalModelId: canonical,
|
|
136
|
-
pricing: choice
|
|
137
|
+
pricing: getChoicePricing(choice),
|
|
137
138
|
profile,
|
|
138
139
|
choice: choiceKey
|
|
139
140
|
};
|
|
140
141
|
}
|
|
141
142
|
async function getProfileIndex() {
|
|
142
|
-
const registry = await
|
|
143
|
+
const registry = await loadAIProfilesRegistry({ source: "auto" });
|
|
143
144
|
const cacheKey = `${registry.version}:${registry.generatedAt ?? ""}:${registry.source}`;
|
|
144
145
|
if (cachedIndex?.cacheKey === cacheKey) {
|
|
145
146
|
return cachedIndex.byKey;
|
|
@@ -173,10 +174,12 @@ function pickBest(candidates, model, providerHint) {
|
|
|
173
174
|
return best;
|
|
174
175
|
}
|
|
175
176
|
function resolvedToMatch(resolved) {
|
|
177
|
+
const direct = resolved.invocation.direct;
|
|
178
|
+
const canonical = resolved.invocation.openrouter?.modelId ?? buildOpenRouterModelId(direct.provider, direct.modelId);
|
|
176
179
|
return {
|
|
177
|
-
provider: normalizeProvider(
|
|
178
|
-
modelId: normalizeString(
|
|
179
|
-
canonicalModelId:
|
|
180
|
+
provider: normalizeProvider(direct.provider) ?? direct.provider,
|
|
181
|
+
modelId: normalizeString(direct.modelId),
|
|
182
|
+
canonicalModelId: canonical,
|
|
180
183
|
pricing: resolved.pricing,
|
|
181
184
|
instructionTier: resolved.instructionTier,
|
|
182
185
|
backend: resolved.backend,
|
|
@@ -187,10 +190,11 @@ function resolvedToMatch(resolved) {
|
|
|
187
190
|
}
|
|
188
191
|
async function fromIndexed(entry) {
|
|
189
192
|
const resolved = await resolveAIProfile(entry.profile, { choice: entry.choice });
|
|
193
|
+
const direct = resolved.invocation.direct;
|
|
190
194
|
return {
|
|
191
|
-
provider: normalizeProvider(
|
|
192
|
-
modelId: normalizeString(
|
|
193
|
-
canonicalModelId:
|
|
195
|
+
provider: normalizeProvider(direct.provider) ?? direct.provider,
|
|
196
|
+
modelId: normalizeString(direct.modelId),
|
|
197
|
+
canonicalModelId: resolved.invocation.openrouter?.modelId ?? buildOpenRouterModelId(direct.provider, direct.modelId),
|
|
194
198
|
pricing: resolved.pricing ?? entry.pricing,
|
|
195
199
|
instructionTier: resolved.instructionTier,
|
|
196
200
|
backend: resolved.backend,
|
|
@@ -260,4 +264,4 @@ export {
|
|
|
260
264
|
resolveRoutedViaOpenRouter,
|
|
261
265
|
matchModelInAiProfiles
|
|
262
266
|
};
|
|
263
|
-
//# sourceMappingURL=chunk-
|
|
267
|
+
//# sourceMappingURL=chunk-RNSXRGIA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cost/costModelResolution.ts","../src/cost/aiProfilesMatch.ts"],"sourcesContent":["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 ResolvedAIProfile,\n} from \"@x12i/ai-profiles\";\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\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(): Promise<Map<string, IndexedChoice[]>> {\n const registry = await loadAIProfilesRegistry({ source: \"auto\" });\n const cacheKey = `${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 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: resolved.shortcut ? \"shortcut\" : \"profile\",\n profile: resolved.profile,\n choice: resolved.choice,\n };\n}\n\nasync function fromIndexed(entry: IndexedChoice): Promise<AiProfilesModelMatch> {\n const resolved = await resolveAIProfile(entry.profile, { choice: entry.choice });\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 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) : 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): Promise<AiProfilesModelMatch | null> {\n try {\n const resolved = await resolveAIProfile(model);\n return resolvedToMatch(resolved);\n } catch (err) {\n if (!(err instanceof AIProfilesError) || err.code !== \"UNKNOWN_PROFILE\") {\n throw err;\n }\n }\n\n const index = await getProfileIndex();\n const hint = providerHintForProfiles(model, provider);\n const direct = await lookupInIndex(index, model, 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 providerHintForProfiles(stripped, provider),\n );\n }\n\n return null;\n}\n\n/** @internal Test-only — reset module cache between tests. */\nexport function resetAiProfilesMatchCacheForTests(): void {\n cachedIndex = null;\n}\n"],"mappings":";;;;;;;;;;AAcO,SAAS,qBAAqB,UAA4B;AAC/D,SAAO,kBAAkB,QAAQ,MAAM;AACzC;AAEO,SAAS,gBAAgB,UAA4B;AAC1D,QAAM,IAAI,kBAAkB,QAAQ,KAAK,gBAAgB,YAAY,EAAE;AACvE,SAAO,gBAAgB,IAAI,CAAC;AAC9B;AAGO,SAAS,0BACd,UACA,eACS;AACT,MAAI,CAAC,UAAU,SAAS,SAAS,OAAQ,QAAO;AAChD,MAAI,SAAS,YAAY,SAAS,4BAA4B,EAAG,QAAO;AACxE,SAAO,gBAAgB,aAAa;AACtC;AAMO,SAAS,4BACd,OACA,cACoB;AACpB,QAAM,aAAa,gBAAgB,KAAK;AACxC,MAAI,WAAW,SAAS,GAAG,GAAG;AAC5B,UAAM,SAAS,WAAW,MAAM,GAAG,EAAE,CAAC;AACtC,QAAI,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,UAAU,QAAQ;AAAA,IAC5C;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkUY2VLJN6cjs = require('./chunk-UY2VLJN6.cjs');
|
|
7
7
|
|
|
8
8
|
// src/catalog/catalogMaintenance.ts
|
|
9
9
|
async function refreshAiModelsCatalog(options = {}) {
|
|
10
|
-
const client = new (0,
|
|
10
|
+
const client = new (0, _chunkUY2VLJN6cjs.AiModelsCatalogClient)(options);
|
|
11
11
|
await client.refresh();
|
|
12
|
-
const loaded = await
|
|
12
|
+
const loaded = await _chunkUY2VLJN6cjs.loadCatalogSourcesCached.call(void 0, options, {
|
|
13
13
|
cacheKey: options.cacheKey,
|
|
14
14
|
ttlMs: options.cacheTtlMs,
|
|
15
15
|
forceRefresh: false
|
|
@@ -23,7 +23,7 @@ async function refreshAiModelsCatalog(options = {}) {
|
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
async function verifyAiModelsCatalog(options = {}) {
|
|
26
|
-
const loaded = await
|
|
26
|
+
const loaded = await _chunkUY2VLJN6cjs.loadCatalogSourcesCached.call(void 0, options, {
|
|
27
27
|
cacheKey: options.cacheKey,
|
|
28
28
|
ttlMs: options.cacheTtlMs,
|
|
29
29
|
forceRefresh: _nullishCoalesce(options.forceRefresh, () => ( options.bundledOnly === true))
|
|
@@ -34,8 +34,8 @@ async function verifyAiModelsCatalog(options = {}) {
|
|
|
34
34
|
openRouterCount: loaded.meta.openRouterCount,
|
|
35
35
|
directSource: loaded.meta.directSource,
|
|
36
36
|
openRouterSource: loaded.meta.openRouterSource,
|
|
37
|
-
directUrl: _nullishCoalesce(options.directCatalogUrl, () => (
|
|
38
|
-
openRouterUrl: _nullishCoalesce(options.openRouterCatalogUrl, () => (
|
|
37
|
+
directUrl: _nullishCoalesce(options.directCatalogUrl, () => ( _chunkUY2VLJN6cjs.DEFAULT_DIRECT_CATALOG_URL)),
|
|
38
|
+
openRouterUrl: _nullishCoalesce(options.openRouterCatalogUrl, () => ( _chunkUY2VLJN6cjs.DEFAULT_OPENROUTER_CATALOG_URL))
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
|
|
@@ -43,4 +43,4 @@ async function verifyAiModelsCatalog(options = {}) {
|
|
|
43
43
|
|
|
44
44
|
|
|
45
45
|
exports.refreshAiModelsCatalog = refreshAiModelsCatalog; exports.verifyAiModelsCatalog = verifyAiModelsCatalog;
|
|
46
|
-
//# sourceMappingURL=chunk-
|
|
46
|
+
//# sourceMappingURL=chunk-RVQPQI63.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-RVQPQI63.cjs","../src/catalog/catalogMaintenance.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACeA,MAAA,SAAsB,sBAAA,CACpB,QAAA,EAAiC,CAAC,CAAA,EACH;AAC/B,EAAA,MAAM,OAAA,EAAS,IAAI,4CAAA,CAAsB,OAAO,CAAA;AAChD,EAAA,MAAM,MAAA,CAAO,OAAA,CAAQ,CAAA;AACrB,EAAA,MAAM,OAAA,EAAS,MAAM,wDAAA,OAAyB,EAAS;AAAA,IACrD,QAAA,EAAU,OAAA,CAAQ,QAAA;AAAA,IAClB,KAAA,EAAO,OAAA,CAAQ,UAAA;AAAA,IACf,YAAA,EAAc;AAAA,EAChB,CAAC,CAAA;AACD,EAAA,OAAO;AAAA,IACL,EAAA,EAAI,IAAA;AAAA,IACJ,WAAA,EAAa,MAAA,CAAO,IAAA,CAAK,WAAA;AAAA,IACzB,eAAA,EAAiB,MAAA,CAAO,IAAA,CAAK,eAAA;AAAA,IAC7B,YAAA,EAAc,MAAA,CAAO,IAAA,CAAK,YAAA;AAAA,IAC1B,gBAAA,EAAkB,MAAA,CAAO,IAAA,CAAK;AAAA,EAChC,CAAA;AACF;AAkBA,MAAA,SAAsB,qBAAA,CACpB,QAAA,EAA6D,CAAC,CAAA,EAChC;AAC9B,EAAA,MAAM,OAAA,EAAS,MAAM,wDAAA,OAAyB,EAAS;AAAA,IACrD,QAAA,EAAU,OAAA,CAAQ,QAAA;AAAA,IAClB,KAAA,EAAO,OAAA,CAAQ,UAAA;AAAA,IACf,YAAA,mBAAc,OAAA,CAAQ,YAAA,UAAgB,OAAA,CAAQ,YAAA,IAAgB;AAAA,EAChE,CAAC,CAAA;AACD,EAAA,OAAO;AAAA,IACL,EAAA,EAAI,MAAA,CAAO,MAAA,CAAO,KAAA,EAAO,EAAA,GAAK,MAAA,CAAO,UAAA,CAAW,KAAA,EAAO,CAAA;AAAA,IACvD,WAAA,EAAa,MAAA,CAAO,IAAA,CAAK,WAAA;AAAA,IACzB,eAAA,EAAiB,MAAA,CAAO,IAAA,CAAK,eAAA;AAAA,IAC7B,YAAA,EAAc,MAAA,CAAO,IAAA,CAAK,YAAA;AAAA,IAC1B,gBAAA,EAAkB,MAAA,CAAO,IAAA,CAAK,gBAAA;AAAA,IAC9B,SAAA,mBAAW,OAAA,CAAQ,gBAAA,UAAoB,8CAAA;AAAA,IACvC,aAAA,mBAAe,OAAA,CAAQ,oBAAA,UAAwB;AAAA,EACjD,CAAA;AACF;ADlCA;AACA;AACE;AACA;AACF,+GAAC","file":"/Users/ami/Documents/prometheus/x12i/ai-tools/dist/chunk-RVQPQI63.cjs","sourcesContent":[null,"import {\n DEFAULT_DIRECT_CATALOG_URL,\n DEFAULT_OPENROUTER_CATALOG_URL,\n type LoadCatalogOptions,\n} from \"./loadCatalogSources.js\";\nimport { loadCatalogSourcesCached } from \"./catalogLoadCache.js\";\nimport { AiModelsCatalogClient } from \"./AiModelsCatalogClient.js\";\n\nexport type CatalogRefreshOptions = LoadCatalogOptions & {\n cacheKey?: string;\n cacheTtlMs?: number;\n};\n\nexport type CatalogRefreshResult = {\n ok: true;\n directCount: number;\n openRouterCount: number;\n directSource: \"remote\" | \"bundled\";\n openRouterSource: \"remote\" | \"bundled\";\n};\n\n/** Fetch remote catalogs and warm the in-memory cache (forces a network load). */\nexport async function refreshAiModelsCatalog(\n options: CatalogRefreshOptions = {},\n): Promise<CatalogRefreshResult> {\n const client = new AiModelsCatalogClient(options);\n await client.refresh();\n const loaded = await loadCatalogSourcesCached(options, {\n cacheKey: options.cacheKey,\n ttlMs: options.cacheTtlMs,\n forceRefresh: false,\n });\n return {\n ok: true,\n directCount: loaded.meta.directCount,\n openRouterCount: loaded.meta.openRouterCount,\n directSource: loaded.meta.directSource,\n openRouterSource: loaded.meta.openRouterSource,\n };\n}\n\nexport type CatalogVerifyOptions = LoadCatalogOptions & {\n cacheKey?: string;\n cacheTtlMs?: number;\n};\n\nexport type CatalogVerifyReport = {\n ok: boolean;\n directCount: number;\n openRouterCount: number;\n directSource: \"remote\" | \"bundled\";\n openRouterSource: \"remote\" | \"bundled\";\n directUrl: string;\n openRouterUrl: string;\n};\n\n/** Load and validate both catalogs (uses cache unless `forceRefresh`). */\nexport async function verifyAiModelsCatalog(\n options: CatalogVerifyOptions & { forceRefresh?: boolean } = {},\n): Promise<CatalogVerifyReport> {\n const loaded = await loadCatalogSourcesCached(options, {\n cacheKey: options.cacheKey,\n ttlMs: options.cacheTtlMs,\n forceRefresh: options.forceRefresh ?? options.bundledOnly === true,\n });\n return {\n ok: loaded.direct.size > 0 && loaded.openrouter.size > 0,\n directCount: loaded.meta.directCount,\n openRouterCount: loaded.meta.openRouterCount,\n directSource: loaded.meta.directSource,\n openRouterSource: loaded.meta.openRouterSource,\n directUrl: options.directCatalogUrl ?? DEFAULT_DIRECT_CATALOG_URL,\n openRouterUrl: options.openRouterCatalogUrl ?? DEFAULT_OPENROUTER_CATALOG_URL,\n };\n}\n"]}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkOZE336BLcjs = require('./chunk-OZE336BL.cjs');
|
|
7
|
+
|
|
8
|
+
// src/sync/modelNameResolver/resolveModelVendor.ts
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
var _aiprofiles = require('@x12i/ai-profiles');
|
|
14
|
+
function isOpenRouterProvider(provider) {
|
|
15
|
+
return _chunkOZE336BLcjs.normalizeProvider.call(void 0, provider) === "openrouter";
|
|
16
|
+
}
|
|
17
|
+
function buildVendorResolveAttempts(model) {
|
|
18
|
+
const attempts = [];
|
|
19
|
+
const seen = /* @__PURE__ */ new Set();
|
|
20
|
+
const add = (m, p) => {
|
|
21
|
+
const key = `${_nullishCoalesce(p, () => ( ""))}\0${_chunkOZE336BLcjs.normalizeString.call(void 0, m)}`;
|
|
22
|
+
if (seen.has(key)) return;
|
|
23
|
+
seen.add(key);
|
|
24
|
+
attempts.push({ model: m, provider: p });
|
|
25
|
+
};
|
|
26
|
+
add(model, void 0);
|
|
27
|
+
const normalised = _chunkOZE336BLcjs.normalizeString.call(void 0, model);
|
|
28
|
+
if (normalised.includes("/")) {
|
|
29
|
+
const prefix = normalised.split("/")[0];
|
|
30
|
+
if (!isOpenRouterProvider(prefix)) {
|
|
31
|
+
add(model, _chunkOZE336BLcjs.normalizeProvider.call(void 0, prefix));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
add(model, "openrouter");
|
|
35
|
+
return attempts;
|
|
36
|
+
}
|
|
37
|
+
function endpointToRef(endpoint) {
|
|
38
|
+
return { provider: endpoint.provider, model: endpoint.modelId };
|
|
39
|
+
}
|
|
40
|
+
function invocationToRef(providerHint, modelId, options) {
|
|
41
|
+
const invocation = _aiprofiles.buildModelInvocation.call(void 0, providerHint, _chunkOZE336BLcjs.normalizeString.call(void 0, modelId));
|
|
42
|
+
if (_optionalChain([options, 'optionalAccess', _ => _.asOpenRouter])) {
|
|
43
|
+
return endpointToRef(
|
|
44
|
+
_nullishCoalesce(invocation.openrouter, () => ( {
|
|
45
|
+
provider: "openrouter",
|
|
46
|
+
modelId: _aiprofiles.buildOpenRouterModelId.call(void 0, providerHint, modelId)
|
|
47
|
+
}))
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
return endpointToRef(invocation.direct);
|
|
51
|
+
}
|
|
52
|
+
function fromAiProfilesIdentity(ref) {
|
|
53
|
+
return { provider: ref.provider, model: ref.modelId };
|
|
54
|
+
}
|
|
55
|
+
function modelVendorRefFromIdentity(model, options) {
|
|
56
|
+
const identity = _aiprofiles.resolveModelIdentity.call(void 0, model, {
|
|
57
|
+
asOpenRouter: _optionalChain([options, 'optionalAccess', _2 => _2.asOpenRouter])
|
|
58
|
+
});
|
|
59
|
+
return identity ? fromAiProfilesIdentity(identity) : null;
|
|
60
|
+
}
|
|
61
|
+
function modelVendorRefFromVendorAndSlug(providerHint, modelId, options) {
|
|
62
|
+
return invocationToRef(providerHint, modelId, options);
|
|
63
|
+
}
|
|
64
|
+
function inferProviderFromSlug(slug, options) {
|
|
65
|
+
const patterns = [
|
|
66
|
+
..._nullishCoalesce(_optionalChain([options, 'optionalAccess', _3 => _3.additionalProviderPatterns]), () => ( [])),
|
|
67
|
+
..._chunkOZE336BLcjs.PROVIDER_INFERENCE_MAP
|
|
68
|
+
];
|
|
69
|
+
for (const { pattern, provider } of patterns) {
|
|
70
|
+
if (pattern.test(slug)) return provider;
|
|
71
|
+
}
|
|
72
|
+
return void 0;
|
|
73
|
+
}
|
|
74
|
+
function providerHintForModelId(modelId, record, options) {
|
|
75
|
+
if (_optionalChain([record, 'optionalAccess', _4 => _4.providerId])) {
|
|
76
|
+
const vendor = _chunkOZE336BLcjs.normalizeProvider.call(void 0, record.providerId);
|
|
77
|
+
if (vendor && !isOpenRouterProvider(vendor)) return vendor;
|
|
78
|
+
}
|
|
79
|
+
const normalised = _chunkOZE336BLcjs.normalizeString.call(void 0, modelId);
|
|
80
|
+
if (normalised.includes("/")) {
|
|
81
|
+
const prefix = normalised.split("/")[0];
|
|
82
|
+
if (!isOpenRouterProvider(prefix)) {
|
|
83
|
+
return _nullishCoalesce(_chunkOZE336BLcjs.normalizeProvider.call(void 0, prefix), () => ( prefix));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return inferProviderFromSlug(normalised, options);
|
|
87
|
+
}
|
|
88
|
+
function formatModelVendorRef(modelId, record, options) {
|
|
89
|
+
const hint = providerHintForModelId(modelId, record, options);
|
|
90
|
+
if (!hint) return null;
|
|
91
|
+
return invocationToRef(hint, modelId, options);
|
|
92
|
+
}
|
|
93
|
+
function resolveModelVendorLastResort(model, options) {
|
|
94
|
+
const hint = providerHintForModelId(model, null, options);
|
|
95
|
+
if (!hint) return null;
|
|
96
|
+
return invocationToRef(hint, model, options);
|
|
97
|
+
}
|
|
98
|
+
function resolveModelVendorFromResolution(result, inputModel, options) {
|
|
99
|
+
if (result.found) {
|
|
100
|
+
const ref = formatModelVendorRef(result.modelId, result.record, options);
|
|
101
|
+
if (ref) return ref;
|
|
102
|
+
}
|
|
103
|
+
if (!result.found && result.bestRejectedCandidate) {
|
|
104
|
+
const ref = formatModelVendorRef(result.bestRejectedCandidate.modelId, null, options);
|
|
105
|
+
if (ref) return ref;
|
|
106
|
+
}
|
|
107
|
+
return resolveModelVendorLastResort(inputModel, options);
|
|
108
|
+
}
|
|
109
|
+
function resolveModelVendorSync(model, catalog, options) {
|
|
110
|
+
const exact = modelVendorRefFromIdentity(model, options);
|
|
111
|
+
if (exact) return exact;
|
|
112
|
+
const resolver = new (0, _chunkOZE336BLcjs.ModelNameResolver)(catalog, options);
|
|
113
|
+
const attempts = buildVendorResolveAttempts(model);
|
|
114
|
+
let last = null;
|
|
115
|
+
for (const attempt of attempts) {
|
|
116
|
+
const result = resolver.resolve(attempt);
|
|
117
|
+
last = result;
|
|
118
|
+
if (result.found) {
|
|
119
|
+
const ref = resolveModelVendorFromResolution(result, model, options);
|
|
120
|
+
if (ref) return ref;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return resolveModelVendorFromResolution(
|
|
124
|
+
_nullishCoalesce(last, () => ( {
|
|
125
|
+
found: false,
|
|
126
|
+
modelId: null,
|
|
127
|
+
record: null,
|
|
128
|
+
attemptedStrategies: [],
|
|
129
|
+
reason: "Model not found in catalog"
|
|
130
|
+
})),
|
|
131
|
+
model,
|
|
132
|
+
options
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
exports.modelVendorRefFromIdentity = modelVendorRefFromIdentity; exports.modelVendorRefFromVendorAndSlug = modelVendorRefFromVendorAndSlug; exports.resolveModelVendorLastResort = resolveModelVendorLastResort; exports.resolveModelVendorFromResolution = resolveModelVendorFromResolution; exports.resolveModelVendorSync = resolveModelVendorSync;
|
|
143
|
+
//# sourceMappingURL=chunk-SYDW33AL.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/ami/Documents/prometheus/x12i/ai-tools/dist/chunk-SYDW33AL.cjs","../src/sync/modelNameResolver/resolveModelVendor.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACPA;AACE;AACA;AACA;AAAA,+CACK;AAYP,SAAS,oB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EAAA;AACmC,EAAA;AAE9B,EAAA;AACH,IAAA;AACC,IAAA;AACI,IAAA;AACH,MAAA;AACG,MAAA;AACX,IAAA;AACF,EAAA;AAEO,EAAA;AACG,qBAAA;AACC,MAAA;AACE,MAAA;AACD,MAAA;AACR,MAAA;AACQ,MAAA;AACV,IAAA;AACA,IAAA;AACA,IAAA;AACF,EAAA;AACF;AD1EiB;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/ami/Documents/prometheus/x12i/ai-tools/dist/chunk-SYDW33AL.cjs","sourcesContent":[null,"import {\n buildModelInvocation,\n buildOpenRouterModelId,\n resolveModelIdentity,\n} from \"@x12i/ai-profiles\";\nimport type { ModelInvocationEndpoint } from \"@x12i/ai-profiles\";\nimport type { AiModelRecord } from \"../../models/types.js\";\nimport { ModelNameResolver } from \"./ModelNameResolver.js\";\nimport { PROVIDER_INFERENCE_MAP } from \"./constants.js\";\nimport { normalizeProvider, normalizeString } from \"./normalize.js\";\nimport type {\n ModelResolutionInput,\n ModelResolutionResult,\n ModelResolverOptions,\n} from \"./types.js\";\n\nfunction isOpenRouterProvider(provider?: string): boolean {\n return normalizeProvider(provider) === \"openrouter\";\n}\n\nfunction buildVendorResolveAttempts(model: string): 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, undefined);\n\n const normalised = normalizeString(model);\n if (normalised.includes(\"/\")) {\n const prefix = normalised.split(\"/\")[0]!;\n if (!isOpenRouterProvider(prefix)) {\n add(model, normalizeProvider(prefix));\n }\n }\n\n add(model, \"openrouter\");\n return attempts;\n}\n\nexport type ModelVendorRef = {\n provider: string;\n model: string;\n};\n\nexport type ResolveModelVendorOptions = ModelResolverOptions & {\n /** Return OpenRouter transport shape: provider `openrouter`, model `vendor/slug`. */\n asOpenRouter?: boolean;\n};\n\nfunction endpointToRef(endpoint: ModelInvocationEndpoint): ModelVendorRef {\n return { provider: endpoint.provider, model: endpoint.modelId };\n}\n\nfunction invocationToRef(\n providerHint: string,\n modelId: string,\n options?: ResolveModelVendorOptions,\n): ModelVendorRef {\n const invocation = buildModelInvocation(providerHint, normalizeString(modelId));\n if (options?.asOpenRouter) {\n return endpointToRef(\n invocation.openrouter ?? {\n provider: \"openrouter\",\n modelId: buildOpenRouterModelId(providerHint, modelId),\n },\n );\n }\n return endpointToRef(invocation.direct);\n}\n\nfunction fromAiProfilesIdentity(\n ref: NonNullable<ReturnType<typeof resolveModelIdentity>>,\n): ModelVendorRef {\n return { provider: ref.provider, model: ref.modelId };\n}\n\n/** Exact registry / bundled-catalog lookup via @x12i/ai-profiles. */\nexport function modelVendorRefFromIdentity(\n model: string,\n options?: ResolveModelVendorOptions,\n): ModelVendorRef | null {\n const identity = resolveModelIdentity(model, {\n asOpenRouter: options?.asOpenRouter,\n });\n return identity ? fromAiProfilesIdentity(identity) : null;\n}\n\n/** Build `{ provider, model }` using @x12i/ai-profiles transport mapping. */\nexport function modelVendorRefFromVendorAndSlug(\n providerHint: string,\n modelId: string,\n options?: ResolveModelVendorOptions,\n): ModelVendorRef {\n return invocationToRef(providerHint, modelId, options);\n}\n\nfunction inferProviderFromSlug(\n slug: string,\n options?: ResolveModelVendorOptions,\n): string | undefined {\n const patterns = [\n ...(options?.additionalProviderPatterns ?? []),\n ...PROVIDER_INFERENCE_MAP,\n ];\n for (const { pattern, provider } of patterns) {\n if (pattern.test(slug)) return provider;\n }\n return undefined;\n}\n\nfunction providerHintForModelId(\n modelId: string,\n record: AiModelRecord | null | undefined,\n options?: ResolveModelVendorOptions,\n): string | undefined {\n if (record?.providerId) {\n const vendor = normalizeProvider(record.providerId);\n if (vendor && !isOpenRouterProvider(vendor)) return vendor;\n }\n\n const normalised = normalizeString(modelId);\n if (normalised.includes(\"/\")) {\n const prefix = normalised.split(\"/\")[0]!;\n if (!isOpenRouterProvider(prefix)) {\n return normalizeProvider(prefix) ?? prefix;\n }\n }\n\n return inferProviderFromSlug(normalised, options);\n}\n\nfunction formatModelVendorRef(\n modelId: string,\n record: AiModelRecord | null | undefined,\n options?: ResolveModelVendorOptions,\n): ModelVendorRef | null {\n const hint = providerHintForModelId(modelId, record, options);\n if (!hint) return null;\n return invocationToRef(hint, modelId, options);\n}\n\n/** Pattern inference when registry and catalog both miss. */\nexport function resolveModelVendorLastResort(\n model: string,\n options?: ResolveModelVendorOptions,\n): ModelVendorRef | null {\n const hint = providerHintForModelId(model, null, options);\n if (!hint) return null;\n return invocationToRef(hint, model, options);\n}\n\n/** Map a fuzzy catalog resolution result to `{ provider, model }`. */\nexport function resolveModelVendorFromResolution(\n result: ModelResolutionResult,\n inputModel: string,\n options?: ResolveModelVendorOptions,\n): ModelVendorRef | null {\n if (result.found) {\n const ref = formatModelVendorRef(result.modelId, result.record, options);\n if (ref) return ref;\n }\n\n if (!result.found && result.bestRejectedCandidate) {\n const ref = formatModelVendorRef(result.bestRejectedCandidate.modelId, null, options);\n if (ref) return ref;\n }\n\n return resolveModelVendorLastResort(inputModel, options);\n}\n\n/** Best-effort vendor lookup from a model name alone (sync, catalog map only). */\nexport function resolveModelVendorSync(\n model: string,\n catalog: Map<string, AiModelRecord>,\n options?: ResolveModelVendorOptions,\n): ModelVendorRef | null {\n const exact = modelVendorRefFromIdentity(model, options);\n if (exact) return exact;\n\n const resolver = new ModelNameResolver(catalog, options);\n const attempts = buildVendorResolveAttempts(model);\n let last: ModelResolutionResult | null = null;\n\n for (const attempt of attempts) {\n const result = resolver.resolve(attempt);\n last = result;\n if (result.found) {\n const ref = resolveModelVendorFromResolution(result, model, options);\n if (ref) return ref;\n }\n }\n\n return resolveModelVendorFromResolution(\n last ?? {\n found: false,\n modelId: null,\n record: null,\n attemptedStrategies: [],\n reason: \"Model not found in catalog\",\n },\n model,\n options,\n );\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
matchModelInAiProfiles
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-RNSXRGIA.js";
|
|
4
4
|
import {
|
|
5
5
|
computeSupportsReasoning
|
|
6
6
|
} from "./chunk-SQ6NOF4Z.js";
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
loadOpenRouterRoutingEnv,
|
|
11
11
|
normalizeProvider,
|
|
12
12
|
normalizeString
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-OB44D7RG.js";
|
|
14
14
|
|
|
15
15
|
// src/cache/modelCache.ts
|
|
16
16
|
import { createNxCache } from "nx-cache";
|
|
@@ -2094,4 +2094,4 @@ export {
|
|
|
2094
2094
|
loadCatalogSourcesCached,
|
|
2095
2095
|
AiModelsCatalogClient
|
|
2096
2096
|
};
|
|
2097
|
-
//# sourceMappingURL=chunk-
|
|
2097
|
+
//# sourceMappingURL=chunk-TZHPZGDB.js.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import {
|
|
2
|
+
modelVendorRefFromIdentity,
|
|
3
|
+
modelVendorRefFromVendorAndSlug,
|
|
4
|
+
resolveModelVendorFromResolution,
|
|
5
|
+
resolveModelVendorLastResort
|
|
6
|
+
} from "./chunk-4ILJWO64.js";
|
|
7
|
+
import {
|
|
8
|
+
buildCatalogResolveAttempts,
|
|
9
|
+
matchModelInAiProfiles,
|
|
10
|
+
resolveFromCatalogAttempts
|
|
11
|
+
} from "./chunk-RNSXRGIA.js";
|
|
12
|
+
|
|
13
|
+
// src/cost/resolveModelVendor.ts
|
|
14
|
+
async function resolveModelVendor(model, catalog, options) {
|
|
15
|
+
const exact = modelVendorRefFromIdentity(model, options);
|
|
16
|
+
if (exact) return exact;
|
|
17
|
+
const attempts = buildCatalogResolveAttempts(model);
|
|
18
|
+
const result = await resolveFromCatalogAttempts(catalog, attempts, options);
|
|
19
|
+
if (result?.found) {
|
|
20
|
+
const ref = resolveModelVendorFromResolution(result, model, options);
|
|
21
|
+
if (ref) return ref;
|
|
22
|
+
}
|
|
23
|
+
const profileMatch = await matchModelInAiProfiles(model);
|
|
24
|
+
if (profileMatch) {
|
|
25
|
+
return modelVendorRefFromVendorAndSlug(
|
|
26
|
+
profileMatch.provider,
|
|
27
|
+
profileMatch.modelId,
|
|
28
|
+
options
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
if (!result?.found && result?.bestRejectedCandidate) {
|
|
32
|
+
const ref = resolveModelVendorFromResolution(result, model, options);
|
|
33
|
+
if (ref) return ref;
|
|
34
|
+
}
|
|
35
|
+
return resolveModelVendorLastResort(model, options);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export {
|
|
39
|
+
resolveModelVendor
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=chunk-UQ4NSEXF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cost/resolveModelVendor.ts"],"sourcesContent":["import type { AiModelsCatalogClient } from \"../catalog/AiModelsCatalogClient.js\";\nimport {\n modelVendorRefFromIdentity,\n modelVendorRefFromVendorAndSlug,\n resolveModelVendorFromResolution,\n resolveModelVendorLastResort,\n type ModelVendorRef,\n type ResolveModelVendorOptions,\n} from \"../sync/modelNameResolver/resolveModelVendor.js\";\nimport { matchModelInAiProfiles } from \"./aiProfilesMatch.js\";\nimport { buildCatalogResolveAttempts, resolveFromCatalogAttempts } from \"./costModelResolution.js\";\n\nexport type { ModelVendorRef, ResolveModelVendorOptions };\nexport {\n resolveModelVendorFromResolution,\n resolveModelVendorSync,\n resolveModelVendorLastResort,\n modelVendorRefFromIdentity,\n modelVendorRefFromVendorAndSlug,\n} from \"../sync/modelNameResolver/resolveModelVendor.js\";\n\n/** Best-effort vendor lookup from a model name alone (catalog + ai-profiles). */\nexport async function resolveModelVendor(\n model: string,\n catalog: AiModelsCatalogClient,\n options?: ResolveModelVendorOptions,\n): Promise<ModelVendorRef | null> {\n const exact = modelVendorRefFromIdentity(model, options);\n if (exact) return exact;\n\n const attempts = buildCatalogResolveAttempts(model);\n const result = await resolveFromCatalogAttempts(catalog, attempts, options);\n\n if (result?.found) {\n const ref = resolveModelVendorFromResolution(result, model, options);\n if (ref) return ref;\n }\n\n const profileMatch = await matchModelInAiProfiles(model);\n if (profileMatch) {\n return modelVendorRefFromVendorAndSlug(\n profileMatch.provider,\n profileMatch.modelId,\n options,\n );\n }\n\n if (!result?.found && result?.bestRejectedCandidate) {\n const ref = resolveModelVendorFromResolution(result, model, options);\n if (ref) return ref;\n }\n\n return resolveModelVendorLastResort(model, options);\n}\n"],"mappings":";;;;;;;;;;;;;AAsBA,eAAsB,mBACpB,OACA,SACA,SACgC;AAChC,QAAM,QAAQ,2BAA2B,OAAO,OAAO;AACvD,MAAI,MAAO,QAAO;AAElB,QAAM,WAAW,4BAA4B,KAAK;AAClD,QAAM,SAAS,MAAM,2BAA2B,SAAS,UAAU,OAAO;AAE1E,MAAI,QAAQ,OAAO;AACjB,UAAM,MAAM,iCAAiC,QAAQ,OAAO,OAAO;AACnE,QAAI,IAAK,QAAO;AAAA,EAClB;AAEA,QAAM,eAAe,MAAM,uBAAuB,KAAK;AACvD,MAAI,cAAc;AAChB,WAAO;AAAA,MACL,aAAa;AAAA,MACb,aAAa;AAAA,MACb;AAAA,IACF;AAAA,EACF;AAEA,MAAI,CAAC,QAAQ,SAAS,QAAQ,uBAAuB;AACnD,UAAM,MAAM,iCAAiC,QAAQ,OAAO,OAAO;AACnE,QAAI,IAAK,QAAO;AAAA,EAClB;AAEA,SAAO,6BAA6B,OAAO,OAAO;AACpD;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkGNOZFRKRcjs = require('./chunk-GNOZFRKR.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
var _chunk2KPWVOOTcjs = require('./chunk-2KPWVOOT.cjs');
|
|
@@ -10,7 +10,7 @@ var _chunk2KPWVOOTcjs = require('./chunk-2KPWVOOT.cjs');
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
var
|
|
13
|
+
var _chunkOZE336BLcjs = require('./chunk-OZE336BL.cjs');
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
var _chunkGS7T56RPcjs = require('./chunk-GS7T56RP.cjs');
|
|
@@ -52,9 +52,9 @@ function firstRate(raw, ...keys) {
|
|
|
52
52
|
return void 0;
|
|
53
53
|
}
|
|
54
54
|
function canonicalCatalogModelId(provider, modelId) {
|
|
55
|
-
const m =
|
|
55
|
+
const m = _chunkOZE336BLcjs.normalizeString.call(void 0, modelId);
|
|
56
56
|
if (m.includes("/")) return m;
|
|
57
|
-
const p = _nullishCoalesce(
|
|
57
|
+
const p = _nullishCoalesce(_chunkOZE336BLcjs.normalizeProvider.call(void 0, provider), () => ( _chunkOZE336BLcjs.normalizeString.call(void 0, provider)));
|
|
58
58
|
return `${p}/${m}`;
|
|
59
59
|
}
|
|
60
60
|
function mapStatus(status) {
|
|
@@ -145,7 +145,7 @@ function normalizeX12iCatalogModel(entry, kind, verifiedAt) {
|
|
|
145
145
|
const outputRate = firstRate(pricingRaw, "output", "textOutput", "outputBelow200k");
|
|
146
146
|
if (inputRate == null && outputRate == null) return null;
|
|
147
147
|
const modelId = canonicalCatalogModelId(entry.provider, entry.modelId);
|
|
148
|
-
const providerId = kind === "openrouter" && modelId.includes("/") ? modelId.split("/")[0] : _nullishCoalesce(
|
|
148
|
+
const providerId = kind === "openrouter" && modelId.includes("/") ? modelId.split("/")[0] : _nullishCoalesce(_chunkOZE336BLcjs.normalizeProvider.call(void 0, entry.provider), () => ( entry.provider));
|
|
149
149
|
const modalities = mapModalities(entry.modalities);
|
|
150
150
|
const pricedAt = verifiedAt || (/* @__PURE__ */ new Date()).toISOString();
|
|
151
151
|
const pricingSource = kind === "openrouter" ? "openrouter" : "direct";
|
|
@@ -1867,7 +1867,7 @@ async function loadCatalogSourcesCached(options = {}, cacheOptions = {}) {
|
|
|
1867
1867
|
|
|
1868
1868
|
// src/catalog/AiModelsCatalogClient.ts
|
|
1869
1869
|
function isOpenRouterProvider(provider) {
|
|
1870
|
-
return
|
|
1870
|
+
return _chunkOZE336BLcjs.normalizeProvider.call(void 0, provider) === "openrouter";
|
|
1871
1871
|
}
|
|
1872
1872
|
function profileResolutionStrategy(matchedVia) {
|
|
1873
1873
|
switch (matchedVia) {
|
|
@@ -1942,7 +1942,7 @@ var AiModelsCatalogClient = (_class = class {
|
|
|
1942
1942
|
return _nullishCoalesce(this.directModels, () => ( /* @__PURE__ */ new Map()));
|
|
1943
1943
|
}
|
|
1944
1944
|
resolver(models, options) {
|
|
1945
|
-
return new (0,
|
|
1945
|
+
return new (0, _chunkOZE336BLcjs.ModelNameResolver)(models, { ...this.resolverOptions, ...options });
|
|
1946
1946
|
}
|
|
1947
1947
|
async getAllModels() {
|
|
1948
1948
|
await this.ensureLoaded();
|
|
@@ -1993,7 +1993,7 @@ var AiModelsCatalogClient = (_class = class {
|
|
|
1993
1993
|
if (!result.routedViaOpenRouter) return result;
|
|
1994
1994
|
let { modelId, record } = result;
|
|
1995
1995
|
if (!modelId.includes("/")) {
|
|
1996
|
-
const vendor = _nullishCoalesce(_nullishCoalesce(_optionalChain([record, 'optionalAccess', _13 => _13.providerId]), () => (
|
|
1996
|
+
const vendor = _nullishCoalesce(_nullishCoalesce(_optionalChain([record, 'optionalAccess', _13 => _13.providerId]), () => ( _chunkOZE336BLcjs.normalizeProvider.call(void 0, input.provider))), () => ( void 0));
|
|
1997
1997
|
if (vendor && vendor !== "openrouter") {
|
|
1998
1998
|
modelId = `${vendor}/${modelId}`;
|
|
1999
1999
|
}
|
|
@@ -2006,13 +2006,13 @@ var AiModelsCatalogClient = (_class = class {
|
|
|
2006
2006
|
return { ...result, modelId, record };
|
|
2007
2007
|
}
|
|
2008
2008
|
async resolveViaProfile(input, options) {
|
|
2009
|
-
const profileMatch = await
|
|
2009
|
+
const profileMatch = await _chunkGNOZFRKRcjs.matchModelInAiProfiles.call(void 0, input.model, input.provider);
|
|
2010
2010
|
if (!profileMatch) return null;
|
|
2011
2011
|
const strategy = profileResolutionStrategy(profileMatch.matchedVia);
|
|
2012
2012
|
const attempts = [];
|
|
2013
2013
|
const seen = /* @__PURE__ */ new Set();
|
|
2014
2014
|
const add = (model, provider) => {
|
|
2015
|
-
const key = `${_nullishCoalesce(provider, () => ( ""))}\0${
|
|
2015
|
+
const key = `${_nullishCoalesce(provider, () => ( ""))}\0${_chunkOZE336BLcjs.normalizeString.call(void 0, model)}`;
|
|
2016
2016
|
if (seen.has(key)) return;
|
|
2017
2017
|
seen.add(key);
|
|
2018
2018
|
attempts.push({ model, provider });
|
|
@@ -2028,10 +2028,10 @@ var AiModelsCatalogClient = (_class = class {
|
|
|
2028
2028
|
catalogResult = result;
|
|
2029
2029
|
if (result.found && result.record) break;
|
|
2030
2030
|
}
|
|
2031
|
-
const normalisedInput =
|
|
2031
|
+
const normalisedInput = _chunkOZE336BLcjs.normalizeString.call(void 0, input.model);
|
|
2032
2032
|
if (!_optionalChain([catalogResult, 'optionalAccess', _17 => _17.found])) {
|
|
2033
|
-
const routingEnv = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _18 => _18.routingEnv]), () => (
|
|
2034
|
-
const routedViaOpenRouter =
|
|
2033
|
+
const routingEnv = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _18 => _18.routingEnv]), () => ( _chunkOZE336BLcjs.loadOpenRouterRoutingEnv.call(void 0, )));
|
|
2034
|
+
const routedViaOpenRouter = _chunkOZE336BLcjs.isEffectiveOpenRouterTransport.call(void 0, routingEnv, {
|
|
2035
2035
|
provider: _nullishCoalesce(input.provider, () => ( profileMatch.provider)),
|
|
2036
2036
|
modelId: profileMatch.canonicalModelId,
|
|
2037
2037
|
routeViaOpenRouter: _optionalChain([options, 'optionalAccess', _19 => _19.routeViaOpenRouter])
|
|
@@ -2097,4 +2097,4 @@ var AiModelsCatalogClient = (_class = class {
|
|
|
2097
2097
|
|
|
2098
2098
|
|
|
2099
2099
|
exports.DEFAULT_CATALOG_CACHE_TTL_MS = DEFAULT_CATALOG_CACHE_TTL_MS; exports.resolveCatalogCacheTtlMs = resolveCatalogCacheTtlMs; exports.DEFAULT_DIRECT_CATALOG_URL = DEFAULT_DIRECT_CATALOG_URL; exports.DEFAULT_OPENROUTER_CATALOG_URL = DEFAULT_OPENROUTER_CATALOG_URL; exports.canonicalCatalogModelId = canonicalCatalogModelId; exports.normalizeX12iCatalogModel = normalizeX12iCatalogModel; exports.modelsFromX12iCatalogFile = modelsFromX12iCatalogFile; exports.loadCatalogSources = loadCatalogSources; exports.readBundledCatalogFiles = readBundledCatalogFiles; exports.invalidateCatalogLoadCache = invalidateCatalogLoadCache; exports.loadCatalogSourcesCached = loadCatalogSourcesCached; exports.AiModelsCatalogClient = AiModelsCatalogClient;
|
|
2100
|
-
//# sourceMappingURL=chunk-
|
|
2100
|
+
//# sourceMappingURL=chunk-UY2VLJN6.cjs.map
|