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A;AACE;AACF,wDAAC","file":"/Users/ami/Documents/prometheus/x12i/ai-tools/dist/chunk-FRGT3BTD.cjs","sourcesContent":[null,"import {\n  AIProfilesError,\n  buildOpenRouterModelId,\n  isKnownProfileInput,\n  resolveInput,\n} from \"@x12i/ai-profiles\";\nimport type {\n  AIProfileBackend,\n  AIModelPricing,\n  InstructionTier,\n  ProfileCatalogLane,\n  RegistrySourceMode,\n  ResolvedAIProfile,\n} from \"@x12i/ai-profiles\";\nimport { TEXT_CATALOG_LANE } from \"../profiles/catalogLane.js\";\nimport { normalizeProvider, normalizeString } from \"../sync/modelNameResolver/normalize.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\" | \"model-id\";\n  profile?: string;\n  choice?: string;\n};\n\nexport type MatchModelInAiProfilesOptions = {\n  source?: RegistrySourceMode;\n  /** OpenRouter catalog lane (required by @x12i/ai-profiles). Defaults to {@link TEXT_CATALOG_LANE}. */\n  catalogLane?: ProfileCatalogLane;\n};\n\n/** When set (tests), overrides default `auto` registry/catalog source. */\nlet registrySourceOverride: RegistrySourceMode | undefined;\n\nfunction registrySource(options?: MatchModelInAiProfilesOptions): RegistrySourceMode {\n  return options?.source ?? registrySourceOverride ?? \"auto\";\n}\n\nfunction catalogLane(options?: MatchModelInAiProfilesOptions): ProfileCatalogLane {\n  return options?.catalogLane ?? TEXT_CATALOG_LANE;\n}\n\n/** ai-profiles returns a valid in-memory cache before honoring `source`; refresh on explicit sources. */\nfunction resolveInputOptions(\n  source: RegistrySourceMode,\n  lane: ProfileCatalogLane,\n) {\n  const base = { source, catalogLane: lane };\n  return source === \"auto\" ? base : { ...base, refresh: true as const };\n}\n\nfunction isLowConfidenceModelResolution(resolved: ResolvedAIProfile): boolean {\n  return (\n    resolved.resolutionKind === \"model\" &&\n    resolved.warnings?.some((w) => w.code === \"MODEL_INPUT_FALLBACK_GUESS\") === true\n  );\n}\n\nfunction resolvedToMatch(resolved: ResolvedAIProfile): AiProfilesModelMatch {\n  const direct = resolved.invocation.direct;\n  const canonical =\n    resolved.invocation.openrouter?.modelId ??\n    buildOpenRouterModelId(direct.provider, direct.modelId);\n  return {\n    provider: normalizeProvider(direct.provider) ?? direct.provider,\n    modelId: normalizeString(direct.modelId),\n    canonicalModelId: canonical,\n    pricing: resolved.pricing,\n    instructionTier: resolved.instructionTier,\n    backend: resolved.backend,\n    matchedVia: resolved.resolutionKind === \"model\" ? \"model-id\" : \"profile\",\n    profile: resolved.profile,\n    choice: resolved.choice,\n  };\n}\n\n/**\n * Resolve via `@x12i/ai-profiles` {@link resolveInput} (profile-first, remote-capable).\n *\n * `provider` is only used for concrete model ids (`{ provider, modelId }`).\n * Known profile inputs are always passed as the bare string so a transport\n * hint like `openrouter` cannot turn `cheap/default` into a fake SKU.\n */\nexport async function matchModelInAiProfiles(\n  model: string,\n  provider?: string,\n  options?: MatchModelInAiProfilesOptions,\n): Promise<AiProfilesModelMatch | null> {\n  const source = registrySource(options);\n  const lane = catalogLane(options);\n  const trimmed = model.trim();\n  const input =\n    provider && provider.trim() && !isKnownProfileInput(trimmed)\n      ? { provider: provider.trim(), modelId: trimmed }\n      : trimmed;\n\n  try {\n    const resolved = await resolveInput(input, resolveInputOptions(source, lane));\n    if (isLowConfidenceModelResolution(resolved)) return null;\n    return resolvedToMatch(resolved);\n  } catch (err) {\n    if (!(err instanceof AIProfilesError)) throw err;\n    return null;\n  }\n}\n\n/** @internal Test-only — reset module cache between tests. */\nexport function resetAiProfilesMatchCacheForTests(\n  options?: { source?: RegistrySourceMode },\n): void {\n  registrySourceOverride = options?.source ?? \"bundled\";\n}\n"]}