@x12i/ai-tools 2.0.7 → 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.
Files changed (92) hide show
  1. package/dist/catalog/index.cjs +6 -6
  2. package/dist/catalog/index.js +5 -5
  3. package/dist/chunk-2KPWVOOT.cjs +32 -0
  4. package/dist/chunk-2KPWVOOT.cjs.map +1 -0
  5. package/dist/chunk-4ILJWO64.js +143 -0
  6. package/dist/chunk-4ILJWO64.js.map +1 -0
  7. package/dist/{chunk-KSJSLKYI.js → chunk-5RW5ARLO.js} +8 -2
  8. package/dist/chunk-5RW5ARLO.js.map +1 -0
  9. package/dist/{chunk-ZPUZ7DBO.js → chunk-7VGEQTJA.js} +2 -2
  10. package/dist/{chunk-PN4FF6YF.js → chunk-DSDN65JH.js} +3 -3
  11. package/dist/{chunk-WSUFQR3D.cjs → chunk-GNOZFRKR.cjs} +45 -44
  12. package/dist/chunk-GNOZFRKR.cjs.map +1 -0
  13. package/dist/{chunk-DDRWORUU.cjs → chunk-H6HDETJK.cjs} +19 -19
  14. package/dist/{chunk-DDRWORUU.cjs.map → chunk-H6HDETJK.cjs.map} +1 -1
  15. package/dist/{chunk-VBROBIVI.js → chunk-IA4HCHJV.js} +3 -3
  16. package/dist/{chunk-VBROBIVI.js.map → chunk-IA4HCHJV.js.map} +1 -1
  17. package/dist/{chunk-76FHWQH3.cjs → chunk-IJTDND4V.cjs} +9 -3
  18. package/dist/chunk-IJTDND4V.cjs.map +1 -0
  19. package/dist/{chunk-X42KFOUO.cjs → chunk-JDOFFZJA.cjs} +6 -6
  20. package/dist/{chunk-X42KFOUO.cjs.map → chunk-JDOFFZJA.cjs.map} +1 -1
  21. package/dist/chunk-LQLSD26Y.cjs +1 -0
  22. package/dist/chunk-LQLSD26Y.cjs.map +1 -0
  23. package/dist/{chunk-54GKLIDW.js → chunk-OB44D7RG.js} +232 -45
  24. package/dist/chunk-OB44D7RG.js.map +1 -0
  25. package/dist/{chunk-RSHI4OOY.cjs → chunk-OZE336BL.cjs} +251 -64
  26. package/dist/chunk-OZE336BL.cjs.map +1 -0
  27. package/dist/{chunk-HEB73GKJ.js → chunk-RNSXRGIA.js} +30 -26
  28. package/dist/chunk-RNSXRGIA.js.map +1 -0
  29. package/dist/{chunk-75ZVXZAV.cjs → chunk-RVQPQI63.cjs} +7 -7
  30. package/dist/{chunk-75ZVXZAV.cjs.map → chunk-RVQPQI63.cjs.map} +1 -1
  31. package/dist/chunk-SQ6NOF4Z.js +32 -0
  32. package/dist/chunk-SQ6NOF4Z.js.map +1 -0
  33. package/dist/chunk-SYDW33AL.cjs +143 -0
  34. package/dist/chunk-SYDW33AL.cjs.map +1 -0
  35. package/dist/{chunk-D6OIUYNC.js → chunk-TZHPZGDB.js} +5 -5
  36. package/dist/chunk-UQ4NSEXF.js +41 -0
  37. package/dist/chunk-UQ4NSEXF.js.map +1 -0
  38. package/dist/{chunk-HBNYVRLZ.cjs → chunk-UY2VLJN6.cjs} +16 -16
  39. package/dist/{chunk-HBNYVRLZ.cjs.map → chunk-UY2VLJN6.cjs.map} +1 -1
  40. package/dist/{chunk-MOLWV5LV.js → chunk-VDNKQRDG.js} +2 -2
  41. package/dist/chunk-XUUPJ7WO.js +1 -0
  42. package/dist/{chunk-TMA6QSNH.cjs → chunk-YO7AJ5Z3.cjs} +3 -3
  43. package/dist/{chunk-TMA6QSNH.cjs.map → chunk-YO7AJ5Z3.cjs.map} +1 -1
  44. package/dist/chunk-ZHRU337O.cjs +41 -0
  45. package/dist/chunk-ZHRU337O.cjs.map +1 -0
  46. package/dist/cli/index.cjs +36 -16
  47. package/dist/cli/index.cjs.map +1 -1
  48. package/dist/cli/index.js +27 -7
  49. package/dist/cli/index.js.map +1 -1
  50. package/dist/cost/index.cjs +21 -5
  51. package/dist/cost/index.cjs.map +1 -1
  52. package/dist/cost/index.d.cts +3 -2
  53. package/dist/cost/index.d.ts +3 -2
  54. package/dist/cost/index.js +20 -4
  55. package/dist/index.cjs +27 -11
  56. package/dist/index.cjs.map +1 -1
  57. package/dist/index.d.cts +2 -1
  58. package/dist/index.d.ts +2 -1
  59. package/dist/index.js +27 -11
  60. package/dist/models/index.cjs +9 -7
  61. package/dist/models/index.cjs.map +1 -1
  62. package/dist/models/index.d.cts +2 -0
  63. package/dist/models/index.d.ts +2 -0
  64. package/dist/models/index.js +8 -6
  65. package/dist/resolveModelVendor-B0t5nq-v.d.cts +22 -0
  66. package/dist/{resolveUsageModel-DrFuiuIW.d.ts → resolveModelVendor-DQpJpk0w.d.ts} +5 -1
  67. package/dist/{resolveUsageModel-xKZ2QpHy.d.cts → resolveModelVendor-XvmXsVzo.d.cts} +5 -1
  68. package/dist/resolveModelVendor-uphYBFMY.d.ts +22 -0
  69. package/dist/sync/index.cjs +16 -5
  70. package/dist/sync/index.cjs.map +1 -1
  71. package/dist/sync/index.d.cts +1 -0
  72. package/dist/sync/index.d.ts +1 -0
  73. package/dist/sync/index.js +17 -6
  74. package/package.json +2 -2
  75. package/dist/chunk-54GKLIDW.js.map +0 -1
  76. package/dist/chunk-56R4XA2S.js +0 -1
  77. package/dist/chunk-5GUKLOEK.cjs +0 -1
  78. package/dist/chunk-5GUKLOEK.cjs.map +0 -1
  79. package/dist/chunk-76FHWQH3.cjs.map +0 -1
  80. package/dist/chunk-BCX5CLJJ.cjs +0 -238
  81. package/dist/chunk-BCX5CLJJ.cjs.map +0 -1
  82. package/dist/chunk-HEB73GKJ.js.map +0 -1
  83. package/dist/chunk-KSJSLKYI.js.map +0 -1
  84. package/dist/chunk-RSHI4OOY.cjs.map +0 -1
  85. package/dist/chunk-SLSKQRMI.js +0 -238
  86. package/dist/chunk-SLSKQRMI.js.map +0 -1
  87. package/dist/chunk-WSUFQR3D.cjs.map +0 -1
  88. /package/dist/{chunk-ZPUZ7DBO.js.map → chunk-7VGEQTJA.js.map} +0 -0
  89. /package/dist/{chunk-PN4FF6YF.js.map → chunk-DSDN65JH.js.map} +0 -0
  90. /package/dist/{chunk-D6OIUYNC.js.map → chunk-TZHPZGDB.js.map} +0 -0
  91. /package/dist/{chunk-MOLWV5LV.js.map → chunk-VDNKQRDG.js.map} +0 -0
  92. /package/dist/{chunk-56R4XA2S.js.map → chunk-XUUPJ7WO.js.map} +0 -0
@@ -1,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
3
 
4
- var _chunk75ZVXZAVcjs = require('../chunk-75ZVXZAV.cjs');
4
+ var _chunkRVQPQI63cjs = require('../chunk-RVQPQI63.cjs');
5
5
 
6
6
 
7
7
 
@@ -15,10 +15,10 @@ var _chunk75ZVXZAVcjs = require('../chunk-75ZVXZAV.cjs');
15
15
 
16
16
 
17
17
 
18
- var _chunkHBNYVRLZcjs = require('../chunk-HBNYVRLZ.cjs');
19
- require('../chunk-WSUFQR3D.cjs');
20
- require('../chunk-RSHI4OOY.cjs');
21
- require('../chunk-BCX5CLJJ.cjs');
18
+ var _chunkUY2VLJN6cjs = require('../chunk-UY2VLJN6.cjs');
19
+ require('../chunk-GNOZFRKR.cjs');
20
+ require('../chunk-2KPWVOOT.cjs');
21
+ require('../chunk-OZE336BL.cjs');
22
22
  require('../chunk-PADNCGZB.cjs');
23
23
  require('../chunk-GS7T56RP.cjs');
24
24
 
@@ -36,5 +36,5 @@ require('../chunk-GS7T56RP.cjs');
36
36
 
37
37
 
38
38
 
39
- exports.AiModelsCatalogClient = _chunkHBNYVRLZcjs.AiModelsCatalogClient; exports.DEFAULT_CATALOG_CACHE_TTL_MS = _chunkHBNYVRLZcjs.DEFAULT_CATALOG_CACHE_TTL_MS; exports.DEFAULT_DIRECT_CATALOG_URL = _chunkHBNYVRLZcjs.DEFAULT_DIRECT_CATALOG_URL; exports.DEFAULT_OPENROUTER_CATALOG_URL = _chunkHBNYVRLZcjs.DEFAULT_OPENROUTER_CATALOG_URL; exports.canonicalCatalogModelId = _chunkHBNYVRLZcjs.canonicalCatalogModelId; exports.invalidateCatalogLoadCache = _chunkHBNYVRLZcjs.invalidateCatalogLoadCache; exports.loadCatalogSources = _chunkHBNYVRLZcjs.loadCatalogSources; exports.loadCatalogSourcesCached = _chunkHBNYVRLZcjs.loadCatalogSourcesCached; exports.modelsFromX12iCatalogFile = _chunkHBNYVRLZcjs.modelsFromX12iCatalogFile; exports.normalizeX12iCatalogModel = _chunkHBNYVRLZcjs.normalizeX12iCatalogModel; exports.readBundledCatalogFiles = _chunkHBNYVRLZcjs.readBundledCatalogFiles; exports.refreshAiModelsCatalog = _chunk75ZVXZAVcjs.refreshAiModelsCatalog; exports.resolveCatalogCacheTtlMs = _chunkHBNYVRLZcjs.resolveCatalogCacheTtlMs; exports.verifyAiModelsCatalog = _chunk75ZVXZAVcjs.verifyAiModelsCatalog;
39
+ exports.AiModelsCatalogClient = _chunkUY2VLJN6cjs.AiModelsCatalogClient; exports.DEFAULT_CATALOG_CACHE_TTL_MS = _chunkUY2VLJN6cjs.DEFAULT_CATALOG_CACHE_TTL_MS; exports.DEFAULT_DIRECT_CATALOG_URL = _chunkUY2VLJN6cjs.DEFAULT_DIRECT_CATALOG_URL; exports.DEFAULT_OPENROUTER_CATALOG_URL = _chunkUY2VLJN6cjs.DEFAULT_OPENROUTER_CATALOG_URL; exports.canonicalCatalogModelId = _chunkUY2VLJN6cjs.canonicalCatalogModelId; exports.invalidateCatalogLoadCache = _chunkUY2VLJN6cjs.invalidateCatalogLoadCache; exports.loadCatalogSources = _chunkUY2VLJN6cjs.loadCatalogSources; exports.loadCatalogSourcesCached = _chunkUY2VLJN6cjs.loadCatalogSourcesCached; exports.modelsFromX12iCatalogFile = _chunkUY2VLJN6cjs.modelsFromX12iCatalogFile; exports.normalizeX12iCatalogModel = _chunkUY2VLJN6cjs.normalizeX12iCatalogModel; exports.readBundledCatalogFiles = _chunkUY2VLJN6cjs.readBundledCatalogFiles; exports.refreshAiModelsCatalog = _chunkRVQPQI63cjs.refreshAiModelsCatalog; exports.resolveCatalogCacheTtlMs = _chunkUY2VLJN6cjs.resolveCatalogCacheTtlMs; exports.verifyAiModelsCatalog = _chunkRVQPQI63cjs.verifyAiModelsCatalog;
40
40
  //# sourceMappingURL=index.cjs.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  refreshAiModelsCatalog,
3
3
  verifyAiModelsCatalog
4
- } from "../chunk-ZPUZ7DBO.js";
4
+ } from "../chunk-7VGEQTJA.js";
5
5
  import {
6
6
  AiModelsCatalogClient,
7
7
  DEFAULT_CATALOG_CACHE_TTL_MS,
@@ -15,10 +15,10 @@ import {
15
15
  normalizeX12iCatalogModel,
16
16
  readBundledCatalogFiles,
17
17
  resolveCatalogCacheTtlMs
18
- } from "../chunk-D6OIUYNC.js";
19
- import "../chunk-HEB73GKJ.js";
20
- import "../chunk-54GKLIDW.js";
21
- import "../chunk-SLSKQRMI.js";
18
+ } from "../chunk-TZHPZGDB.js";
19
+ import "../chunk-RNSXRGIA.js";
20
+ import "../chunk-SQ6NOF4Z.js";
21
+ import "../chunk-OB44D7RG.js";
22
22
  import "../chunk-2PTCWPHV.js";
23
23
  export {
24
24
  AiModelsCatalogClient,
@@ -0,0 +1,32 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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; }// src/models/reasoningModel.ts
2
+ var REASONING_SUPPORTED_PARAMETERS = ["reasoning", "include_reasoning"];
3
+ function supportsReasoningParameter(model) {
4
+ return model.supportedParameters.some(
5
+ (p) => REASONING_SUPPORTED_PARAMETERS.includes(p)
6
+ );
7
+ }
8
+ function hasReasoningPricing(model) {
9
+ const raw = _optionalChain([model, 'access', _ => _.openRouterPricing, 'optionalAccess', _2 => _2.internal_reasoning]);
10
+ if (raw !== void 0 && raw !== null && String(raw).trim() !== "") {
11
+ return true;
12
+ }
13
+ return model.pricing.reasoningUsdPerToken !== void 0;
14
+ }
15
+ function computeSupportsReasoning(model) {
16
+ return supportsReasoningParameter(model) || hasReasoningPricing(model);
17
+ }
18
+ function isReasoningModel(model) {
19
+ if (model.supportsReasoning !== void 0) {
20
+ return model.supportsReasoning;
21
+ }
22
+ return computeSupportsReasoning(model);
23
+ }
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+ exports.REASONING_SUPPORTED_PARAMETERS = REASONING_SUPPORTED_PARAMETERS; exports.supportsReasoningParameter = supportsReasoningParameter; exports.hasReasoningPricing = hasReasoningPricing; exports.computeSupportsReasoning = computeSupportsReasoning; exports.isReasoningModel = isReasoningModel;
32
+ //# sourceMappingURL=chunk-2KPWVOOT.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/ami/Documents/prometheus/x12i/ai-tools/dist/chunk-2KPWVOOT.cjs","../src/models/reasoningModel.ts"],"names":[],"mappings":"AAAA;ACGO,IAAM,+BAAA,EAAiC,CAAC,WAAA,EAAa,mBAAmB,CAAA;AAaxE,SAAS,0BAAA,CAA2B,KAAA,EAA4D;AACrG,EAAA,OAAO,KAAA,CAAM,mBAAA,CAAoB,IAAA;AAAA,IAAK,CAAC,CAAA,EAAA,GACpC,8BAAA,CAAqD,QAAA,CAAS,CAAC;AAAA,EAClE,CAAA;AACF;AAMO,SAAS,mBAAA,CACd,KAAA,EACS;AACT,EAAA,MAAM,IAAA,kBAAM,KAAA,mBAAM,iBAAA,6BAAmB,oBAAA;AACrC,EAAA,GAAA,CAAI,IAAA,IAAQ,KAAA,EAAA,GAAa,IAAA,IAAQ,KAAA,GAAQ,MAAA,CAAO,GAAG,CAAA,CAAE,IAAA,CAAK,EAAA,IAAM,EAAA,EAAI;AAClE,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,OAAO,KAAA,CAAM,OAAA,CAAQ,qBAAA,IAAyB,KAAA,CAAA;AAChD;AAKO,SAAS,wBAAA,CAAyB,KAAA,EAAqC;AAC5E,EAAA,OAAO,0BAAA,CAA2B,KAAK,EAAA,GAAK,mBAAA,CAAoB,KAAK,CAAA;AACvE;AAQO,SAAS,gBAAA,CAAiB,KAAA,EAAqC;AACpE,EAAA,GAAA,CAAI,KAAA,CAAM,kBAAA,IAAsB,KAAA,CAAA,EAAW;AACzC,IAAA,OAAO,KAAA,CAAM,iBAAA;AAAA,EACf;AACA,EAAA,OAAO,wBAAA,CAAyB,KAAK,CAAA;AACvC;AD/BA;AACA;AACE;AACA;AACA;AACA;AACA;AACF,sSAAC","file":"/Users/ami/Documents/prometheus/x12i/ai-tools/dist/chunk-2KPWVOOT.cjs","sourcesContent":[null,"import type { AiModelRecord } from \"./types.js\";\n\n/** OpenRouter `supported_parameters` values that indicate reasoning API support. */\nexport const REASONING_SUPPORTED_PARAMETERS = [\"reasoning\", \"include_reasoning\"] as const;\n\nexport type ReasoningModelInput = Pick<\n AiModelRecord,\n \"supportedParameters\" | \"pricing\" | \"openRouterPricing\"\n> & {\n supportsReasoning?: boolean;\n};\n\n/**\n * Whether the model accepts OpenRouter's `reasoning` request parameter\n * (effort, max_tokens, exclude, enabled).\n */\nexport function supportsReasoningParameter(model: Pick<AiModelRecord, \"supportedParameters\">): boolean {\n return model.supportedParameters.some((p) =>\n (REASONING_SUPPORTED_PARAMETERS as readonly string[]).includes(p),\n );\n}\n\n/**\n * Whether the model bills separate reasoning / thinking tokens\n * (`internal_reasoning` in OpenRouter pricing).\n */\nexport function hasReasoningPricing(\n model: Pick<AiModelRecord, \"pricing\" | \"openRouterPricing\">,\n): boolean {\n const raw = model.openRouterPricing?.internal_reasoning;\n if (raw !== undefined && raw !== null && String(raw).trim() !== \"\") {\n return true;\n }\n return model.pricing.reasoningUsdPerToken !== undefined;\n}\n\n/**\n * Compute `supportsReasoning` from catalog fields (used when normalizing catalog entries).\n */\nexport function computeSupportsReasoning(model: ReasoningModelInput): boolean {\n return supportsReasoningParameter(model) || hasReasoningPricing(model);\n}\n\n/**\n * True when the model supports reasoning tokens (API param and/or separate reasoning pricing).\n *\n * Prefer `model.supportsReasoning` on {@link AiModelRecord} after catalog load;\n * this helper also works when only partial fields are available.\n */\nexport function isReasoningModel(model: ReasoningModelInput): boolean {\n if (model.supportsReasoning !== undefined) {\n return model.supportsReasoning;\n }\n return computeSupportsReasoning(model);\n}\n"]}
@@ -0,0 +1,143 @@
1
+ import {
2
+ ModelNameResolver,
3
+ PROVIDER_INFERENCE_MAP,
4
+ normalizeProvider,
5
+ normalizeString
6
+ } from "./chunk-OB44D7RG.js";
7
+
8
+ // src/sync/modelNameResolver/resolveModelVendor.ts
9
+ import {
10
+ buildModelInvocation,
11
+ buildOpenRouterModelId,
12
+ resolveModelIdentity
13
+ } from "@x12i/ai-profiles";
14
+ function isOpenRouterProvider(provider) {
15
+ return normalizeProvider(provider) === "openrouter";
16
+ }
17
+ function buildVendorResolveAttempts(model) {
18
+ const attempts = [];
19
+ const seen = /* @__PURE__ */ new Set();
20
+ const add = (m, p) => {
21
+ const key = `${p ?? ""}\0${normalizeString(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 = normalizeString(model);
28
+ if (normalised.includes("/")) {
29
+ const prefix = normalised.split("/")[0];
30
+ if (!isOpenRouterProvider(prefix)) {
31
+ add(model, normalizeProvider(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 = buildModelInvocation(providerHint, normalizeString(modelId));
42
+ if (options?.asOpenRouter) {
43
+ return endpointToRef(
44
+ invocation.openrouter ?? {
45
+ provider: "openrouter",
46
+ modelId: buildOpenRouterModelId(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 = resolveModelIdentity(model, {
57
+ asOpenRouter: options?.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
+ ...options?.additionalProviderPatterns ?? [],
67
+ ...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 (record?.providerId) {
76
+ const vendor = normalizeProvider(record.providerId);
77
+ if (vendor && !isOpenRouterProvider(vendor)) return vendor;
78
+ }
79
+ const normalised = normalizeString(modelId);
80
+ if (normalised.includes("/")) {
81
+ const prefix = normalised.split("/")[0];
82
+ if (!isOpenRouterProvider(prefix)) {
83
+ return normalizeProvider(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 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
+ 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
+ export {
137
+ modelVendorRefFromIdentity,
138
+ modelVendorRefFromVendorAndSlug,
139
+ resolveModelVendorLastResort,
140
+ resolveModelVendorFromResolution,
141
+ resolveModelVendorSync
142
+ };
143
+ //# sourceMappingURL=chunk-4ILJWO64.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/sync/modelNameResolver/resolveModelVendor.ts"],"sourcesContent":["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"],"mappings":";;;;;;;;AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAYP,SAAS,qBAAqB,UAA4B;AACxD,SAAO,kBAAkB,QAAQ,MAAM;AACzC;AAEA,SAAS,2BAA2B,OAAuC;AACzE,QAAM,WAAmC,CAAC;AAC1C,QAAM,OAAO,oBAAI,IAAY;AAC7B,QAAM,MAAM,CAAC,GAAW,MAAe;AACrC,UAAM,MAAM,GAAG,KAAK,EAAE,KAAK,gBAAgB,CAAC,CAAC;AAC7C,QAAI,KAAK,IAAI,GAAG,EAAG;AACnB,SAAK,IAAI,GAAG;AACZ,aAAS,KAAK,EAAE,OAAO,GAAG,UAAU,EAAE,CAAC;AAAA,EACzC;AAEA,MAAI,OAAO,MAAS;AAEpB,QAAM,aAAa,gBAAgB,KAAK;AACxC,MAAI,WAAW,SAAS,GAAG,GAAG;AAC5B,UAAM,SAAS,WAAW,MAAM,GAAG,EAAE,CAAC;AACtC,QAAI,CAAC,qBAAqB,MAAM,GAAG;AACjC,UAAI,OAAO,kBAAkB,MAAM,CAAC;AAAA,IACtC;AAAA,EACF;AAEA,MAAI,OAAO,YAAY;AACvB,SAAO;AACT;AAYA,SAAS,cAAc,UAAmD;AACxE,SAAO,EAAE,UAAU,SAAS,UAAU,OAAO,SAAS,QAAQ;AAChE;AAEA,SAAS,gBACP,cACA,SACA,SACgB;AAChB,QAAM,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
5
  AiModelsCatalogClient
3
- } from "./chunk-D6OIUYNC.js";
6
+ } from "./chunk-TZHPZGDB.js";
4
7
 
5
8
  // src/models/filterModels.ts
6
9
  function matchesSearch(record, search) {
@@ -69,6 +72,9 @@ var AiModelsService = class {
69
72
  async resolve(modelIdOrAlias, provider) {
70
73
  return this.client.resolveModel({ model: modelIdOrAlias, provider });
71
74
  }
75
+ async resolveVendor(model, options) {
76
+ return resolveModelVendor(model, this.client, options);
77
+ }
72
78
  async refresh() {
73
79
  await this.client.refresh();
74
80
  }
@@ -83,4 +89,4 @@ export {
83
89
  AiModelsService,
84
90
  getModelInfo
85
91
  };
86
- //# sourceMappingURL=chunk-KSJSLKYI.js.map
92
+ //# sourceMappingURL=chunk-5RW5ARLO.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/models/filterModels.ts","../src/models/AiModelsService.ts"],"sourcesContent":["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"],"mappings":";;;;;;;;AAEA,SAAS,cAAc,QAAuB,QAAyB;AACrE,QAAM,IAAI,OAAO,YAAY;AAC7B,SACE,OAAO,QAAQ,YAAY,EAAE,SAAS,CAAC,KACvC,OAAO,KAAK,YAAY,EAAE,SAAS,CAAC,KACpC,OAAO,YAAY,YAAY,EAAE,SAAS,CAAC,KAC3C,OAAO,cAAc,YAAY,EAAE,SAAS,CAAC,KAC7C,OAAO,QAAQ,KAAK,CAAC,MAAM,EAAE,YAAY,EAAE,SAAS,CAAC,CAAC;AAE1D;AAEO,SAAS,aACd,QACA,UAA4B,CAAC,GACZ;AACjB,MAAI,OAAO,CAAC,GAAG,MAAM;AAErB,MAAI,QAAQ,YAAY;AACtB,WAAO,KAAK,OAAO,CAAC,MAAM,EAAE,eAAe,QAAQ,UAAU;AAAA,EAC/D;AACA,MAAI,QAAQ,QAAQ;AAClB,WAAO,KAAK,OAAO,CAAC,MAAM,EAAE,WAAW,QAAQ,MAAM;AAAA,EACvD;AACA,MAAI,QAAQ,gBAAgB;AAC1B,WAAO,KAAK,OAAO,CAAC,MAAM,EAAE,iBAAiB,SAAS,QAAQ,cAAe,CAAC;AAAA,EAChF;AACA,MAAI,QAAQ,eAAe;AACzB,WAAO,KAAK,OAAO,CAAC,MAAM,EAAE,gBAAgB,SAAS,QAAQ,aAAc,CAAC;AAAA,EAC9E;AACA,MAAI,QAAQ,oBAAoB;AAC9B,WAAO,K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AAO,OAAO,OAAO;AAAA,EACxC;AAAA,EAEA,MAAM,YAAY,UAAsD,CAAC,GAAoB;AAC3F,UAAM,MAAM,MAAM,KAAK,aAAa;AACpC,WAAO,YAAY,IAAI,OAAO,GAAG,OAAO;AAAA,EAC1C;AAAA,EAEA,MAAM,aAAa,gBAAwB,UAAkD;AAC3F,WAAO,KAAK,OAAO,SAAS,gBAAgB,QAAQ;AAAA,EACtD;AAAA,EAEA,MAAM,QACJ,gBACA,UAC6E;AAC7E,WAAO,KAAK,OAAO,aAAa,EAAE,OAAO,gBAAgB,SAAS,CAAC;AAAA,EACrE;AAAA,EAEA,MAAM,cACJ,OACA,SACgC;AAChC,WAAO,mBAAmB,OAAO,KAAK,QAAQ,OAAO;AAAA,EACvD;AAAA,EAEA,MAAM,UAAyB;AAC7B,UAAM,KAAK,OAAO,QAAQ;AAAA,EAC5B;AACF;AAEA,eAAsB,aACpB,gBACA,UAAkC,CAAC,GACnC,UAC+B;AAC/B,SAAO,IAAI,gBAAgB,OAAO,EAAE,aAAa,gBAAgB,QAAQ;AAC3E;","names":[]}
@@ -3,7 +3,7 @@ import {
3
3
  DEFAULT_DIRECT_CATALOG_URL,
4
4
  DEFAULT_OPENROUTER_CATALOG_URL,
5
5
  loadCatalogSourcesCached
6
- } from "./chunk-D6OIUYNC.js";
6
+ } from "./chunk-TZHPZGDB.js";
7
7
 
8
8
  // src/catalog/catalogMaintenance.ts
9
9
  async function refreshAiModelsCatalog(options = {}) {
@@ -43,4 +43,4 @@ export {
43
43
  refreshAiModelsCatalog,
44
44
  verifyAiModelsCatalog
45
45
  };
46
- //# sourceMappingURL=chunk-ZPUZ7DBO.js.map
46
+ //# sourceMappingURL=chunk-7VGEQTJA.js.map
@@ -5,11 +5,11 @@ import {
5
5
  matchModelInAiProfiles,
6
6
  resolveFromCatalogAttempts,
7
7
  resolveRoutedViaOpenRouter
8
- } from "./chunk-HEB73GKJ.js";
8
+ } from "./chunk-RNSXRGIA.js";
9
9
  import {
10
10
  normalizeString,
11
11
  stripModelVersionSuffix
12
- } from "./chunk-SLSKQRMI.js";
12
+ } from "./chunk-OB44D7RG.js";
13
13
  import {
14
14
  UnknownModelCostError
15
15
  } from "./chunk-2PTCWPHV.js";
@@ -702,4 +702,4 @@ export {
702
702
  resolveUsageModel,
703
703
  CostCalculator
704
704
  };
705
- //# sourceMappingURL=chunk-PN4FF6YF.js.map
705
+ //# sourceMappingURL=chunk-DSDN65JH.js.map
@@ -5,18 +5,15 @@
5
5
 
6
6
 
7
7
 
8
- var _chunkBCX5CLJJcjs = require('./chunk-BCX5CLJJ.cjs');
9
-
10
-
11
- var _chunkGS7T56RPcjs = require('./chunk-GS7T56RP.cjs');
8
+ var _chunkOZE336BLcjs = require('./chunk-OZE336BL.cjs');
12
9
 
13
10
  // src/cost/costModelResolution.ts
14
11
  function isOpenRouterProvider(provider) {
15
- return _chunkBCX5CLJJcjs.normalizeProvider.call(void 0, provider) === "openrouter";
12
+ return _chunkOZE336BLcjs.normalizeProvider.call(void 0, provider) === "openrouter";
16
13
  }
17
14
  function isLocalProvider(provider) {
18
- const p = _nullishCoalesce(_chunkBCX5CLJJcjs.normalizeProvider.call(void 0, provider), () => ( _chunkBCX5CLJJcjs.normalizeString.call(void 0, _nullishCoalesce(provider, () => ( "")))));
19
- return _chunkBCX5CLJJcjs.LOCAL_PROVIDERS.has(p);
15
+ const p = _nullishCoalesce(_chunkOZE336BLcjs.normalizeProvider.call(void 0, provider), () => ( _chunkOZE336BLcjs.normalizeString.call(void 0, _nullishCoalesce(provider, () => ( "")))));
16
+ return _chunkOZE336BLcjs.LOCAL_PROVIDERS.has(p);
20
17
  }
21
18
  function isLocalProviderResolution(resolved, inputProvider) {
22
19
  if (!_optionalChain([resolved, 'optionalAccess', _ => _.found]) || resolved.record) return false;
@@ -24,13 +21,13 @@ function isLocalProviderResolution(resolved, inputProvider) {
24
21
  return isLocalProvider(inputProvider);
25
22
  }
26
23
  function underlyingProviderFromModel(model, providerHint) {
27
- const normalized = _chunkBCX5CLJJcjs.normalizeString.call(void 0, model);
24
+ const normalized = _chunkOZE336BLcjs.normalizeString.call(void 0, model);
28
25
  if (normalized.includes("/")) {
29
26
  const prefix = normalized.split("/")[0];
30
27
  if (!isOpenRouterProvider(prefix)) return prefix;
31
28
  }
32
29
  if (providerHint && !isOpenRouterProvider(providerHint)) {
33
- return _chunkBCX5CLJJcjs.normalizeProvider.call(void 0, providerHint);
30
+ return _chunkOZE336BLcjs.normalizeProvider.call(void 0, providerHint);
34
31
  }
35
32
  return void 0;
36
33
  }
@@ -38,13 +35,13 @@ function providerHintForProfiles(model, provider) {
38
35
  if (isOpenRouterProvider(provider)) {
39
36
  return underlyingProviderFromModel(model, provider);
40
37
  }
41
- return _chunkBCX5CLJJcjs.normalizeProvider.call(void 0, provider);
38
+ return _chunkOZE336BLcjs.normalizeProvider.call(void 0, provider);
42
39
  }
43
40
  function buildCatalogResolveAttempts(model, provider) {
44
41
  const attempts = [];
45
42
  const seen = /* @__PURE__ */ new Set();
46
43
  const add = (m, p) => {
47
- const key = `${_nullishCoalesce(p, () => ( ""))}\0${_chunkBCX5CLJJcjs.normalizeString.call(void 0, m)}`;
44
+ const key = `${_nullishCoalesce(p, () => ( ""))}\0${_chunkOZE336BLcjs.normalizeString.call(void 0, m)}`;
48
45
  if (seen.has(key)) return;
49
46
  seen.add(key);
50
47
  attempts.push({ model: m, provider: p });
@@ -72,7 +69,7 @@ async function resolveFromCatalogAttempts(catalog, attempts, options) {
72
69
  return _nullishCoalesce(localPassthrough, () => ( last));
73
70
  }
74
71
  function resolveRoutedViaOpenRouter(inputProvider, resolved, modelId, routingEnv) {
75
- const env = _nullishCoalesce(routingEnv, () => ( _chunkBCX5CLJJcjs.loadOpenRouterRoutingEnv.call(void 0, )));
72
+ const env = _nullishCoalesce(routingEnv, () => ( _chunkOZE336BLcjs.loadOpenRouterRoutingEnv.call(void 0, )));
76
73
  if (isOpenRouterProvider(inputProvider)) return true;
77
74
  if (_optionalChain([resolved, 'optionalAccess', _2 => _2.found])) {
78
75
  return resolved.routedViaOpenRouter;
@@ -81,30 +78,29 @@ function resolveRoutedViaOpenRouter(inputProvider, resolved, modelId, routingEnv
81
78
  _nullishCoalesce(_nullishCoalesce(modelId, () => ( (_optionalChain([resolved, 'optionalAccess', _3 => _3.found]) ? resolved.modelId : ""))), () => ( "")),
82
79
  inputProvider
83
80
  );
84
- if (vendor && _chunkBCX5CLJJcjs.shouldDefaultRouteViaOpenRouter.call(void 0, vendor, env)) {
81
+ if (vendor && _chunkOZE336BLcjs.shouldDefaultRouteViaOpenRouter.call(void 0, vendor, env)) {
85
82
  return true;
86
83
  }
87
84
  return false;
88
85
  }
89
86
 
90
87
  // src/cost/aiProfilesMatch.ts
91
- var _module = require('module');
92
- var _path = require('path');
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
93
96
  var _aiprofiles = require('@x12i/ai-profiles');
94
- var require2 = _module.createRequire.call(void 0, _chunkGS7T56RPcjs.importMetaUrl);
95
- function loadProfilesRegistry() {
96
- const entry = _path.dirname.call(void 0, require2.resolve("@x12i/ai-profiles"));
97
- const loader = require2(_path.join.call(void 0, entry, "loader/loadAIProfilesRegistry.js"));
98
- return loader.loadAIProfilesRegistry({ source: "auto" });
99
- }
100
97
  function profileKey(value) {
101
98
  return value.trim().toLowerCase();
102
99
  }
103
100
  function canonicalModelId(provider, modelId) {
104
- const normalized = _chunkBCX5CLJJcjs.normalizeString.call(void 0, modelId);
101
+ const normalized = _chunkOZE336BLcjs.normalizeString.call(void 0, modelId);
105
102
  if (normalized.includes("/")) return normalized;
106
- const p = _nullishCoalesce(_chunkBCX5CLJJcjs.normalizeProvider.call(void 0, provider), () => ( _chunkBCX5CLJJcjs.normalizeString.call(void 0, provider)));
107
- return `${p}/${normalized}`;
103
+ return _aiprofiles.buildOpenRouterModelId.call(void 0, provider, normalized);
108
104
  }
109
105
  var cachedIndex = null;
110
106
  function indexRegistry(registry) {
@@ -124,25 +120,27 @@ function indexRegistry(registry) {
124
120
  for (const profile of Object.values(registry.profiles)) {
125
121
  for (const [choiceKey, choice] of Object.entries(profile.choices)) {
126
122
  const entry = choiceEntry(choice, profile.profile, choiceKey);
127
- add(choice.modelId, entry);
128
- add(canonicalModelId(choice.provider, choice.modelId), entry);
123
+ add(_aiprofiles.getChoiceVendorModelId.call(void 0, choice), entry);
124
+ add(canonicalModelId(choice.provider, _aiprofiles.getChoiceVendorModelId.call(void 0, choice)), entry);
129
125
  }
130
126
  }
131
127
  return byKey;
132
128
  }
133
129
  function choiceEntry(choice, profile, choiceKey) {
134
- const canonical = canonicalModelId(choice.provider, choice.modelId);
130
+ const vendorModelId = _aiprofiles.getChoiceVendorModelId.call(void 0, choice);
131
+ const provider = _nullishCoalesce(_chunkOZE336BLcjs.normalizeProvider.call(void 0, choice.provider), () => ( choice.provider));
132
+ const canonical = _nullishCoalesce(_aiprofiles.getChoiceOpenRouterModelId.call(void 0, choice), () => ( canonicalModelId(choice.provider, vendorModelId)));
135
133
  return {
136
- provider: _nullishCoalesce(_chunkBCX5CLJJcjs.normalizeProvider.call(void 0, choice.provider), () => ( choice.provider)),
137
- modelId: _chunkBCX5CLJJcjs.normalizeString.call(void 0, choice.modelId),
134
+ provider,
135
+ modelId: _chunkOZE336BLcjs.normalizeString.call(void 0, vendorModelId),
138
136
  canonicalModelId: canonical,
139
- pricing: choice.pricing,
137
+ pricing: _aiprofiles.getChoicePricing.call(void 0, choice),
140
138
  profile,
141
139
  choice: choiceKey
142
140
  };
143
141
  }
144
142
  async function getProfileIndex() {
145
- const registry = await loadProfilesRegistry();
143
+ const registry = await _aiprofiles.loadAIProfilesRegistry.call(void 0, { source: "auto" });
146
144
  const cacheKey = `${registry.version}:${_nullishCoalesce(registry.generatedAt, () => ( ""))}:${registry.source}`;
147
145
  if (_optionalChain([cachedIndex, 'optionalAccess', _4 => _4.cacheKey]) === cacheKey) {
148
146
  return cachedIndex.byKey;
@@ -152,7 +150,7 @@ async function getProfileIndex() {
152
150
  return byKey;
153
151
  }
154
152
  function scoreCandidate(entry, model, providerHint) {
155
- const normalized = _chunkBCX5CLJJcjs.normalizeString.call(void 0, model);
153
+ const normalized = _chunkOZE336BLcjs.normalizeString.call(void 0, model);
156
154
  let score = 0;
157
155
  if (normalized === entry.canonicalModelId) score += 100;
158
156
  if (normalized === entry.modelId) score += 80;
@@ -176,10 +174,12 @@ function pickBest(candidates, model, providerHint) {
176
174
  return best;
177
175
  }
178
176
  function resolvedToMatch(resolved) {
177
+ const direct = resolved.invocation.direct;
178
+ const canonical = _nullishCoalesce(_optionalChain([resolved, 'access', _5 => _5.invocation, 'access', _6 => _6.openrouter, 'optionalAccess', _7 => _7.modelId]), () => ( _aiprofiles.buildOpenRouterModelId.call(void 0, direct.provider, direct.modelId)));
179
179
  return {
180
- provider: _nullishCoalesce(_chunkBCX5CLJJcjs.normalizeProvider.call(void 0, resolved.provider), () => ( resolved.provider)),
181
- modelId: _chunkBCX5CLJJcjs.normalizeString.call(void 0, resolved.modelId),
182
- canonicalModelId: canonicalModelId(resolved.provider, resolved.modelId),
180
+ provider: _nullishCoalesce(_chunkOZE336BLcjs.normalizeProvider.call(void 0, direct.provider), () => ( direct.provider)),
181
+ modelId: _chunkOZE336BLcjs.normalizeString.call(void 0, direct.modelId),
182
+ canonicalModelId: canonical,
183
183
  pricing: resolved.pricing,
184
184
  instructionTier: resolved.instructionTier,
185
185
  backend: resolved.backend,
@@ -190,10 +190,11 @@ function resolvedToMatch(resolved) {
190
190
  }
191
191
  async function fromIndexed(entry) {
192
192
  const resolved = await _aiprofiles.resolveAIProfile.call(void 0, entry.profile, { choice: entry.choice });
193
+ const direct = resolved.invocation.direct;
193
194
  return {
194
- provider: _nullishCoalesce(_chunkBCX5CLJJcjs.normalizeProvider.call(void 0, resolved.provider), () => ( resolved.provider)),
195
- modelId: _chunkBCX5CLJJcjs.normalizeString.call(void 0, resolved.modelId),
196
- canonicalModelId: canonicalModelId(resolved.provider, resolved.modelId),
195
+ provider: _nullishCoalesce(_chunkOZE336BLcjs.normalizeProvider.call(void 0, direct.provider), () => ( direct.provider)),
196
+ modelId: _chunkOZE336BLcjs.normalizeString.call(void 0, direct.modelId),
197
+ canonicalModelId: _nullishCoalesce(_optionalChain([resolved, 'access', _8 => _8.invocation, 'access', _9 => _9.openrouter, 'optionalAccess', _10 => _10.modelId]), () => ( _aiprofiles.buildOpenRouterModelId.call(void 0, direct.provider, direct.modelId))),
197
198
  pricing: _nullishCoalesce(resolved.pricing, () => ( entry.pricing)),
198
199
  instructionTier: resolved.instructionTier,
199
200
  backend: resolved.backend,
@@ -203,10 +204,10 @@ async function fromIndexed(entry) {
203
204
  };
204
205
  }
205
206
  async function lookupInIndex(index, model, provider) {
206
- const providerHint = provider ? _chunkBCX5CLJJcjs.normalizeProvider.call(void 0, provider) : void 0;
207
+ const providerHint = provider ? _chunkOZE336BLcjs.normalizeProvider.call(void 0, provider) : void 0;
207
208
  const keys = [
208
209
  profileKey(model),
209
- profileKey(_chunkBCX5CLJJcjs.normalizeString.call(void 0, model))
210
+ profileKey(_chunkOZE336BLcjs.normalizeString.call(void 0, model))
210
211
  ];
211
212
  if (providerHint) {
212
213
  keys.push(profileKey(canonicalModelId(providerHint, model)));
@@ -216,7 +217,7 @@ async function lookupInIndex(index, model, provider) {
216
217
  const hits = index.get(key);
217
218
  if (hits) pooled.push(...hits);
218
219
  }
219
- const bare = _chunkBCX5CLJJcjs.normalizeString.call(void 0, model);
220
+ const bare = _chunkOZE336BLcjs.normalizeString.call(void 0, model);
220
221
  if (!bare.includes("/")) {
221
222
  for (const list of index.values()) {
222
223
  for (const entry of list) {
@@ -244,8 +245,8 @@ async function matchModelInAiProfiles(model, provider) {
244
245
  const hint = providerHintForProfiles(model, provider);
245
246
  const direct = await lookupInIndex(index, model, hint);
246
247
  if (direct) return direct;
247
- const stripped = _chunkBCX5CLJJcjs.stripModelVersionSuffix.call(void 0, model);
248
- if (stripped && stripped !== _chunkBCX5CLJJcjs.normalizeString.call(void 0, model)) {
248
+ const stripped = _chunkOZE336BLcjs.stripModelVersionSuffix.call(void 0, model);
249
+ if (stripped && stripped !== _chunkOZE336BLcjs.normalizeString.call(void 0, model)) {
249
250
  return lookupInIndex(
250
251
  index,
251
252
  stripped,
@@ -263,4 +264,4 @@ async function matchModelInAiProfiles(model, provider) {
263
264
 
264
265
 
265
266
  exports.isLocalProvider = isLocalProvider; exports.isLocalProviderResolution = isLocalProviderResolution; exports.buildCatalogResolveAttempts = buildCatalogResolveAttempts; exports.resolveFromCatalogAttempts = resolveFromCatalogAttempts; exports.resolveRoutedViaOpenRouter = resolveRoutedViaOpenRouter; exports.matchModelInAiProfiles = matchModelInAiProfiles;
266
- //# sourceMappingURL=chunk-WSUFQR3D.cjs.map
267
+ //# sourceMappingURL=chunk-GNOZFRKR.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/ami/Documents/prometheus/x12i/ai-tools/dist/chunk-GNOZFRKR.cjs","../src/cost/costModelResolution.ts","../src/cost/aiProfilesMatch.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACKO,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;A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Ee;AACP,EAAA;AACS,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;AAKP,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;AAIhB,EAAA;AACI,IAAA;AACC,IAAA;AACK,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;AACF,IAAA;AACF,EAAA;AAEO,EAAA;AACT;AFPiB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/ami/Documents/prometheus/x12i/ai-tools/dist/chunk-GNOZFRKR.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 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"]}