llm-strings 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +117 -45
  2. package/dist/ai-sdk.cjs +831 -0
  3. package/dist/ai-sdk.cjs.map +1 -0
  4. package/dist/ai-sdk.d.cts +27 -0
  5. package/dist/ai-sdk.d.ts +27 -0
  6. package/dist/ai-sdk.js +465 -0
  7. package/dist/ai-sdk.js.map +1 -0
  8. package/dist/{chunk-MPIHGH6L.js → chunk-2ARD4TFU.js} +5 -4
  9. package/dist/chunk-2ARD4TFU.js.map +1 -0
  10. package/dist/{chunk-FCEV23OT.js → chunk-BCOUH7LH.js} +9 -3
  11. package/dist/chunk-BCOUH7LH.js.map +1 -0
  12. package/dist/{chunk-UYMVUTLV.js → chunk-RPXK2A7O.js} +5 -9
  13. package/dist/chunk-RPXK2A7O.js.map +1 -0
  14. package/dist/{chunk-XID353H7.js → chunk-W4NIQY7M.js} +412 -52
  15. package/dist/chunk-W4NIQY7M.js.map +1 -0
  16. package/dist/index.cjs +1032 -12
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +1 -1
  19. package/dist/index.d.ts +1 -1
  20. package/dist/index.js +9 -4
  21. package/dist/normalize.cjs +370 -4
  22. package/dist/normalize.cjs.map +1 -1
  23. package/dist/normalize.d.cts +1 -1
  24. package/dist/normalize.d.ts +1 -1
  25. package/dist/normalize.js +2 -2
  26. package/dist/parse.cjs +129 -5
  27. package/dist/parse.cjs.map +1 -1
  28. package/dist/parse.d.cts +5 -1
  29. package/dist/parse.d.ts +5 -1
  30. package/dist/parse.js +2 -1
  31. package/dist/{provider-core-DinpG40u.d.ts → provider-core-BiAl8MCV.d.cts} +20 -1
  32. package/dist/{provider-core-DinpG40u.d.cts → provider-core-BiAl8MCV.d.ts} +20 -1
  33. package/dist/providers.cjs +1145 -90
  34. package/dist/providers.cjs.map +1 -1
  35. package/dist/providers.d.cts +2 -2
  36. package/dist/providers.d.ts +2 -2
  37. package/dist/providers.js +379 -60
  38. package/dist/providers.js.map +1 -1
  39. package/dist/validate.cjs +1017 -6
  40. package/dist/validate.cjs.map +1 -1
  41. package/dist/validate.js +4 -4
  42. package/package.json +13 -2
  43. package/dist/chunk-FCEV23OT.js.map +0 -1
  44. package/dist/chunk-MGWGNZDJ.cjs +0 -116
  45. package/dist/chunk-MGWGNZDJ.cjs.map +0 -1
  46. package/dist/chunk-MPIHGH6L.js.map +0 -1
  47. package/dist/chunk-N6NVBE43.cjs +0 -37
  48. package/dist/chunk-N6NVBE43.cjs.map +0 -1
  49. package/dist/chunk-NSCBY4VD.cjs +0 -370
  50. package/dist/chunk-NSCBY4VD.cjs.map +0 -1
  51. package/dist/chunk-RSUXM42X.cjs +0 -180
  52. package/dist/chunk-RSUXM42X.cjs.map +0 -1
  53. package/dist/chunk-UYMVUTLV.js.map +0 -1
  54. package/dist/chunk-XID353H7.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/dan/code/oss/llm-strings/dist/normalize.cjs"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B,gCAA6B;AAC7B;AACE;AACF,gDAAC","file":"/Users/dan/code/oss/llm-strings/dist/normalize.cjs"}
1
+ {"version":3,"sources":["../src/normalize.ts","../src/provider-core.ts"],"sourcesContent":["import type { LlmConnectionConfig } from \"./parse.js\";\nimport {\n ALIASES,\n CACHE_TTLS,\n CACHE_VALUES,\n DURATION_RE,\n PROVIDER_PARAMS,\n bedrockSupportsCaching,\n canHostOpenAIModels,\n detectGatewaySubProvider,\n detectProvider,\n isGatewayProvider,\n isReasoningModel,\n providerFromHostAlias,\n type Provider,\n} from \"./provider-core.js\";\n\nexport interface NormalizeChange {\n from: string;\n to: string;\n value: string;\n reason: string;\n}\n\nexport interface NormalizeResult {\n config: LlmConnectionConfig;\n provider: Provider | undefined;\n /** Underlying provider extracted from gateway model prefix (e.g. \"anthropic\" from \"anthropic/claude-sonnet-4-5\"). */\n subProvider: Provider | undefined;\n changes: NormalizeChange[];\n}\n\nexport interface NormalizeOptions {\n /** Include detailed change log in the result. */\n verbose?: boolean;\n}\n\n/**\n * Normalize an LLM connection config's params for its target provider.\n *\n * 1. Expands shorthand aliases (e.g. `temp` → `temperature`)\n * 2. Maps canonical param names to provider-specific names\n * (e.g. `max_tokens` → `maxOutputTokens` for Google)\n * 3. Normalizes special values (e.g. `cache=true` → `cache_control=ephemeral` for Anthropic)\n * 4. For OpenAI reasoning models, remaps `max_tokens` → `max_completion_tokens`\n * and warns about unsupported sampling params\n */\nexport function normalize(\n config: LlmConnectionConfig,\n options: NormalizeOptions = {},\n): NormalizeResult {\n const provider =\n (config.hostAlias ? providerFromHostAlias(config.hostAlias) : undefined) ??\n detectProvider(config.host);\n const subProvider =\n provider && isGatewayProvider(provider)\n ? detectGatewaySubProvider(config.model)\n : undefined;\n const changes: NormalizeChange[] = [];\n const params: Record<string, string> = {};\n\n for (const [rawKey, value] of Object.entries(config.params)) {\n let key = rawKey;\n\n // Step 1: Expand aliases to canonical name\n if (ALIASES[key]) {\n const canonical = ALIASES[key];\n if (options.verbose) {\n changes.push({\n from: key,\n to: canonical,\n value,\n reason: `alias: \"${key}\" → \"${canonical}\"`,\n });\n }\n key = canonical;\n }\n\n // Step 2: Handle special \"cache\" param\n if (key === \"cache\" && provider) {\n let cacheValue = CACHE_VALUES[provider];\n\n // Bedrock supports cache for Anthropic Claude and Amazon Nova models\n if (provider === \"bedrock\" && !bedrockSupportsCaching(config.model)) {\n cacheValue = undefined;\n }\n\n // Provider/model doesn't support cache — drop it\n if (!cacheValue) {\n if (options.verbose) {\n changes.push({\n from: \"cache\",\n to: \"(dropped)\",\n value,\n reason: `${provider} does not use a cache param for this model (caching is automatic or unsupported)`,\n });\n }\n continue;\n }\n\n const isBool = value === \"true\" || value === \"1\" || value === \"yes\";\n const isDuration = DURATION_RE.test(value);\n\n if (isBool || isDuration) {\n const providerKey = PROVIDER_PARAMS[provider]?.[\"cache\"] ?? \"cache\";\n if (options.verbose) {\n changes.push({\n from: \"cache\",\n to: providerKey,\n value: cacheValue,\n reason: `cache=${value} → ${providerKey}=${cacheValue} for ${provider}`,\n });\n }\n params[providerKey] = cacheValue;\n\n // Emit cache_ttl when a duration is specified\n if (isDuration && CACHE_TTLS[provider]) {\n if (options.verbose) {\n changes.push({\n from: \"cache\",\n to: \"cache_ttl\",\n value,\n reason: `cache=${value} → cache_ttl=${value} for ${provider}`,\n });\n }\n params[\"cache_ttl\"] = value;\n }\n continue;\n }\n }\n\n // Step 3: Map canonical → provider-specific param name\n if (provider && PROVIDER_PARAMS[provider]) {\n const providerKey = PROVIDER_PARAMS[provider][key];\n if (providerKey && providerKey !== key) {\n if (options.verbose) {\n changes.push({\n from: key,\n to: providerKey,\n value,\n reason: `${provider} uses \"${providerKey}\" instead of \"${key}\"`,\n });\n }\n key = providerKey;\n }\n }\n\n // Step 4: OpenAI reasoning model adjustments (direct or via gateway)\n if (\n provider &&\n canHostOpenAIModels(provider) &&\n isReasoningModel(config.model) &&\n key === \"max_tokens\"\n ) {\n if (options.verbose) {\n changes.push({\n from: \"max_tokens\",\n to: \"max_completion_tokens\",\n value,\n reason:\n \"OpenAI reasoning models use max_completion_tokens instead of max_tokens\",\n });\n }\n key = \"max_completion_tokens\";\n }\n\n params[key] = value;\n }\n\n return {\n config: { ...config, params },\n provider,\n subProvider,\n changes,\n };\n}\n","export type Provider =\n | \"openai\"\n | \"anthropic\"\n | \"google\"\n | \"mistral\"\n | \"cohere\"\n | \"bedrock\"\n | \"openrouter\"\n | \"vercel\";\n\nexport type HostAlias =\n | Provider\n | \"aistudio\"\n | \"alibaba\"\n | \"alibabacloud\"\n | \"atlascloud\"\n | \"baidu\"\n | \"dashscope\"\n | \"deepinfra\"\n | \"fireworks\"\n | \"fireworksai\"\n | \"grok\"\n | \"minimax\"\n | \"novita\"\n | \"novitaai\"\n | \"parasail\"\n | \"qianfan\"\n | \"vertex\"\n | \"venice\"\n | \"wandb\"\n | \"weightsandbiases\"\n | \"xai\"\n | \"xiaomi\";\n\ntype Env = Record<string, string | undefined>;\n\ndeclare const process:\n | {\n env?: Env;\n }\n | undefined;\n\nfunction hasOwn<T extends object>(object: T, key: PropertyKey): key is keyof T {\n return Object.prototype.hasOwnProperty.call(object, key);\n}\n\nexport const HOST_ALIASES: Record<HostAlias, string> = {\n openai: \"api.openai.com\",\n anthropic: \"api.anthropic.com\",\n google: \"generativelanguage.googleapis.com\",\n aistudio: \"generativelanguage.googleapis.com\",\n mistral: \"api.mistral.ai\",\n cohere: \"api.cohere.com\",\n bedrock: \"bedrock-runtime.us-east-1.amazonaws.com\",\n openrouter: \"openrouter.ai\",\n vercel: \"gateway.ai.vercel.app\",\n alibaba: \"dashscope-intl.aliyuncs.com\",\n alibabacloud: \"dashscope-intl.aliyuncs.com\",\n dashscope: \"dashscope-intl.aliyuncs.com\",\n fireworks: \"api.fireworks.ai\",\n fireworksai: \"api.fireworks.ai\",\n venice: \"api.venice.ai\",\n parasail: \"api.parasail.io\",\n deepinfra: \"api.deepinfra.com\",\n atlascloud: \"api.atlascloud.ai\",\n novita: \"api.novita.ai\",\n novitaai: \"api.novita.ai\",\n grok: \"api.x.ai\",\n xai: \"api.x.ai\",\n wandb: \"api.inference.wandb.ai\",\n weightsandbiases: \"api.inference.wandb.ai\",\n baidu: \"qianfan.baidubce.com\",\n qianfan: \"qianfan.baidubce.com\",\n vertex: \"aiplatform.googleapis.com\",\n xiaomi: \"api.xiaomimimo.com\",\n minimax: \"api.minimax.io\",\n};\n\nexport interface HostResolution {\n /** The hostname/host to use for requests. */\n host: string;\n /** The provider alias that was expanded, if any. */\n alias?: HostAlias;\n}\n\nfunction readProcessEnv(): Env {\n return typeof process !== \"undefined\" && process.env ? process.env : {};\n}\n\nfunction normalizeHostValue(value: string): string {\n const trimmed = value.trim();\n if (!trimmed) return trimmed;\n\n try {\n if (trimmed.includes(\"://\")) {\n return new URL(trimmed).host;\n }\n } catch {\n // Fall through and treat it as a host-ish string.\n }\n\n return trimmed.replace(/^\\/\\//, \"\").split(\"/\")[0] ?? trimmed;\n}\n\nfunction envHostOverride(alias: HostAlias, env: Env): string | undefined {\n const upper = alias.toUpperCase();\n const override =\n env[`LLM_STRINGS_${upper}_HOST`] ?? env[`LLM_STRINGS_HOST_${upper}`];\n return override?.trim() ? override : undefined;\n}\n\n/**\n * Resolve short provider host aliases (`openai`, `anthropic`, etc.) to their\n * canonical hostnames. Per-provider environment overrides can redirect aliases\n * to regional or private endpoints:\n *\n * - `LLM_STRINGS_OPENAI_HOST`\n * - `LLM_STRINGS_HOST_OPENAI`\n */\nexport function resolveHostAlias(\n host: string,\n env: Env = readProcessEnv(),\n): HostResolution {\n const normalizedHost = host.toLowerCase();\n if (!hasOwn(HOST_ALIASES, normalizedHost)) {\n return { host };\n }\n\n const alias = normalizedHost as HostAlias;\n const override = envHostOverride(alias, env);\n return {\n host: normalizeHostValue(override ?? HOST_ALIASES[alias]),\n alias,\n };\n}\n\nexport function providerFromHostAlias(alias: string): Provider | undefined {\n const normalizedAlias = alias.toLowerCase();\n if (hasOwn(PROVIDER_PARAMS, normalizedAlias)) {\n return normalizedAlias as Provider;\n }\n return undefined;\n}\n\nexport function detectProvider(host: string): Provider | undefined {\n host = host.toLowerCase();\n\n // Gateways and aggregators first — they proxy to other providers\n if (host.includes(\"openrouter\")) return \"openrouter\";\n if (host.includes(\"gateway.ai.vercel\")) return \"vercel\";\n // Bedrock before native providers since it hosts models from multiple vendors\n if (host.includes(\"amazonaws\") || host.includes(\"bedrock\")) return \"bedrock\";\n if (host.includes(\"openai\")) return \"openai\";\n if (host.includes(\"anthropic\") || host.includes(\"claude\")) return \"anthropic\";\n if (host.includes(\"googleapis\") || host.includes(\"google\")) return \"google\";\n if (host.includes(\"mistral\")) return \"mistral\";\n if (host.includes(\"cohere\")) return \"cohere\";\n return undefined;\n}\n\n/**\n * Shorthand aliases → canonical param name.\n * Canonical names use snake_case and follow OpenAI conventions where possible.\n */\nexport const ALIASES: Record<string, string> = {\n // temperature\n temp: \"temperature\",\n\n // max_tokens\n max: \"max_tokens\",\n max_out: \"max_tokens\",\n max_output: \"max_tokens\",\n max_output_tokens: \"max_tokens\",\n max_completion_tokens: \"max_tokens\",\n maxOutputTokens: \"max_tokens\",\n maxTokens: \"max_tokens\",\n\n // top_p\n topp: \"top_p\",\n topP: \"top_p\",\n nucleus: \"top_p\",\n\n // top_k\n topk: \"top_k\",\n topK: \"top_k\",\n\n // frequency_penalty\n freq: \"frequency_penalty\",\n freq_penalty: \"frequency_penalty\",\n frequencyPenalty: \"frequency_penalty\",\n repetition_penalty: \"frequency_penalty\",\n\n // presence_penalty\n pres: \"presence_penalty\",\n pres_penalty: \"presence_penalty\",\n presencePenalty: \"presence_penalty\",\n\n // stop\n stop_sequences: \"stop\",\n stopSequences: \"stop\",\n stop_sequence: \"stop\",\n\n // seed\n random_seed: \"seed\",\n randomSeed: \"seed\",\n\n // n (completions count)\n candidateCount: \"n\",\n candidate_count: \"n\",\n num_completions: \"n\",\n\n // effort / reasoning\n reasoning_effort: \"effort\",\n reasoning: \"effort\",\n\n // cache\n cache_control: \"cache\",\n cacheControl: \"cache\",\n cachePoint: \"cache\",\n cache_point: \"cache\",\n};\n\n/**\n * Canonical param name → provider-specific API param name.\n * Only includes params the provider actually supports.\n */\nexport const PROVIDER_PARAMS: Record<Provider, Record<string, string>> = {\n openai: {\n temperature: \"temperature\",\n max_tokens: \"max_tokens\",\n top_p: \"top_p\",\n frequency_penalty: \"frequency_penalty\",\n presence_penalty: \"presence_penalty\",\n stop: \"stop\",\n n: \"n\",\n seed: \"seed\",\n stream: \"stream\",\n effort: \"reasoning_effort\",\n },\n anthropic: {\n temperature: \"temperature\",\n max_tokens: \"max_tokens\",\n top_p: \"top_p\",\n top_k: \"top_k\",\n stop: \"stop_sequences\",\n stream: \"stream\",\n effort: \"effort\",\n cache: \"cache_control\",\n cache_ttl: \"cache_ttl\",\n },\n google: {\n temperature: \"temperature\",\n max_tokens: \"maxOutputTokens\",\n top_p: \"topP\",\n top_k: \"topK\",\n frequency_penalty: \"frequencyPenalty\",\n presence_penalty: \"presencePenalty\",\n stop: \"stopSequences\",\n n: \"candidateCount\",\n stream: \"stream\",\n seed: \"seed\",\n responseMimeType: \"responseMimeType\",\n responseSchema: \"responseSchema\",\n },\n mistral: {\n temperature: \"temperature\",\n max_tokens: \"max_tokens\",\n top_p: \"top_p\",\n frequency_penalty: \"frequency_penalty\",\n presence_penalty: \"presence_penalty\",\n stop: \"stop\",\n n: \"n\",\n seed: \"random_seed\",\n stream: \"stream\",\n safe_prompt: \"safe_prompt\",\n min_tokens: \"min_tokens\",\n },\n cohere: {\n temperature: \"temperature\",\n max_tokens: \"max_tokens\",\n top_p: \"p\",\n top_k: \"k\",\n frequency_penalty: \"frequency_penalty\",\n presence_penalty: \"presence_penalty\",\n stop: \"stop_sequences\",\n stream: \"stream\",\n seed: \"seed\",\n },\n bedrock: {\n // Bedrock Converse API uses camelCase\n temperature: \"temperature\",\n max_tokens: \"maxTokens\",\n top_p: \"topP\",\n top_k: \"topK\", // Claude models via additionalModelRequestFields\n stop: \"stopSequences\",\n stream: \"stream\",\n cache: \"cache_control\",\n cache_ttl: \"cache_ttl\",\n },\n openrouter: {\n // OpenAI-compatible API with extra routing params\n temperature: \"temperature\",\n max_tokens: \"max_tokens\",\n top_p: \"top_p\",\n top_k: \"top_k\",\n frequency_penalty: \"frequency_penalty\",\n presence_penalty: \"presence_penalty\",\n stop: \"stop\",\n n: \"n\",\n seed: \"seed\",\n stream: \"stream\",\n effort: \"reasoning_effort\",\n },\n vercel: {\n // OpenAI-compatible gateway\n temperature: \"temperature\",\n max_tokens: \"max_tokens\",\n top_p: \"top_p\",\n top_k: \"top_k\",\n frequency_penalty: \"frequency_penalty\",\n presence_penalty: \"presence_penalty\",\n stop: \"stop\",\n n: \"n\",\n seed: \"seed\",\n stream: \"stream\",\n effort: \"reasoning_effort\",\n },\n};\n\n/**\n * Validation specs per provider, keyed by provider-specific param name.\n */\nexport interface ParamSpec {\n type: \"number\" | \"string\" | \"boolean\";\n min?: number;\n max?: number;\n values?: string[];\n default?: string | number | boolean;\n description?: string;\n}\n\nexport const PARAM_SPECS: Record<Provider, Record<string, ParamSpec>> = {\n openai: {\n temperature: {\n type: \"number\",\n min: 0,\n max: 2,\n default: 0.7,\n description: \"Controls randomness\",\n },\n max_tokens: {\n type: \"number\",\n min: 1,\n default: 4096,\n description: \"Maximum output tokens\",\n },\n top_p: {\n type: \"number\",\n min: 0,\n max: 1,\n default: 1,\n description: \"Nucleus sampling\",\n },\n frequency_penalty: {\n type: \"number\",\n min: -2,\n max: 2,\n default: 0,\n description: \"Penalize frequent tokens\",\n },\n presence_penalty: {\n type: \"number\",\n min: -2,\n max: 2,\n default: 0,\n description: \"Penalize repeated topics\",\n },\n stop: { type: \"string\", description: \"Stop sequences\" },\n n: { type: \"number\", min: 1, default: 1, description: \"Completions count\" },\n seed: { type: \"number\", description: \"Random seed\" },\n stream: { type: \"boolean\", default: false, description: \"Stream response\" },\n reasoning_effort: {\n type: \"string\",\n values: [\"none\", \"minimal\", \"low\", \"medium\", \"high\", \"xhigh\"],\n default: \"medium\",\n description: \"Reasoning effort\",\n },\n },\n anthropic: {\n temperature: {\n type: \"number\",\n min: 0,\n max: 1,\n default: 0.7,\n description: \"Controls randomness\",\n },\n max_tokens: {\n type: \"number\",\n min: 1,\n default: 4096,\n description: \"Maximum output tokens\",\n },\n top_p: {\n type: \"number\",\n min: 0,\n max: 1,\n default: 1,\n description: \"Nucleus sampling\",\n },\n top_k: {\n type: \"number\",\n min: 0,\n default: 40,\n description: \"Top-K sampling\",\n },\n stop_sequences: { type: \"string\", description: \"Stop sequences\" },\n stream: { type: \"boolean\", default: false, description: \"Stream response\" },\n effort: {\n type: \"string\",\n values: [\"low\", \"medium\", \"high\", \"max\"],\n default: \"medium\",\n description: \"Thinking effort\",\n },\n cache_control: {\n type: \"string\",\n values: [\"ephemeral\"],\n default: \"ephemeral\",\n description: \"Cache control\",\n },\n cache_ttl: {\n type: \"string\",\n values: [\"5m\", \"1h\"],\n default: \"5m\",\n description: \"Cache TTL\",\n },\n },\n google: {\n temperature: {\n type: \"number\",\n min: 0,\n max: 2,\n default: 0.7,\n description: \"Controls randomness\",\n },\n maxOutputTokens: {\n type: \"number\",\n min: 1,\n default: 4096,\n description: \"Maximum output tokens\",\n },\n topP: {\n type: \"number\",\n min: 0,\n max: 1,\n default: 1,\n description: \"Nucleus sampling\",\n },\n topK: {\n type: \"number\",\n min: 0,\n default: 40,\n description: \"Top-K sampling\",\n },\n frequencyPenalty: {\n type: \"number\",\n min: -2,\n max: 2,\n default: 0,\n description: \"Penalize frequent tokens\",\n },\n presencePenalty: {\n type: \"number\",\n min: -2,\n max: 2,\n default: 0,\n description: \"Penalize repeated topics\",\n },\n stopSequences: { type: \"string\", description: \"Stop sequences\" },\n candidateCount: {\n type: \"number\",\n min: 1,\n default: 1,\n description: \"Candidate count\",\n },\n stream: { type: \"boolean\", default: false, description: \"Stream response\" },\n seed: { type: \"number\", description: \"Random seed\" },\n responseMimeType: { type: \"string\", description: \"Response MIME type\" },\n responseSchema: { type: \"string\", description: \"Response schema\" },\n },\n mistral: {\n temperature: {\n type: \"number\",\n min: 0,\n max: 1,\n default: 0.7,\n description: \"Controls randomness\",\n },\n max_tokens: {\n type: \"number\",\n min: 1,\n default: 4096,\n description: \"Maximum output tokens\",\n },\n top_p: {\n type: \"number\",\n min: 0,\n max: 1,\n default: 1,\n description: \"Nucleus sampling\",\n },\n frequency_penalty: {\n type: \"number\",\n min: -2,\n max: 2,\n default: 0,\n description: \"Penalize frequent tokens\",\n },\n presence_penalty: {\n type: \"number\",\n min: -2,\n max: 2,\n default: 0,\n description: \"Penalize repeated topics\",\n },\n stop: { type: \"string\", description: \"Stop sequences\" },\n n: { type: \"number\", min: 1, default: 1, description: \"Completions count\" },\n random_seed: { type: \"number\", description: \"Random seed\" },\n stream: { type: \"boolean\", default: false, description: \"Stream response\" },\n safe_prompt: {\n type: \"boolean\",\n default: false,\n description: \"Enable safe prompt\",\n },\n min_tokens: {\n type: \"number\",\n min: 0,\n default: 0,\n description: \"Minimum tokens\",\n },\n },\n cohere: {\n temperature: {\n type: \"number\",\n min: 0,\n max: 1,\n default: 0.7,\n description: \"Controls randomness\",\n },\n max_tokens: {\n type: \"number\",\n min: 1,\n default: 4096,\n description: \"Maximum output tokens\",\n },\n p: {\n type: \"number\",\n min: 0,\n max: 1,\n default: 1,\n description: \"Nucleus sampling (p)\",\n },\n k: {\n type: \"number\",\n min: 0,\n max: 500,\n default: 40,\n description: \"Top-K sampling (k)\",\n },\n frequency_penalty: {\n type: \"number\",\n min: 0,\n max: 1,\n default: 0,\n description: \"Penalize frequent tokens\",\n },\n presence_penalty: {\n type: \"number\",\n min: 0,\n max: 1,\n default: 0,\n description: \"Penalize repeated topics\",\n },\n stop_sequences: { type: \"string\", description: \"Stop sequences\" },\n stream: { type: \"boolean\", default: false, description: \"Stream response\" },\n seed: { type: \"number\", description: \"Random seed\" },\n },\n bedrock: {\n // Converse API inferenceConfig params\n temperature: {\n type: \"number\",\n min: 0,\n max: 1,\n default: 0.7,\n description: \"Controls randomness\",\n },\n maxTokens: {\n type: \"number\",\n min: 1,\n default: 4096,\n description: \"Maximum output tokens\",\n },\n topP: {\n type: \"number\",\n min: 0,\n max: 1,\n default: 1,\n description: \"Nucleus sampling\",\n },\n topK: {\n type: \"number\",\n min: 0,\n default: 40,\n description: \"Top-K sampling\",\n },\n stopSequences: { type: \"string\", description: \"Stop sequences\" },\n stream: { type: \"boolean\", default: false, description: \"Stream response\" },\n cache_control: {\n type: \"string\",\n values: [\"ephemeral\"],\n default: \"ephemeral\",\n description: \"Cache control\",\n },\n cache_ttl: {\n type: \"string\",\n values: [\"5m\", \"1h\"],\n default: \"5m\",\n description: \"Cache TTL\",\n },\n },\n openrouter: {\n // Loose validation — proxies to many providers with varying ranges\n temperature: {\n type: \"number\",\n min: 0,\n max: 2,\n default: 0.7,\n description: \"Controls randomness\",\n },\n max_tokens: {\n type: \"number\",\n min: 1,\n default: 4096,\n description: \"Maximum output tokens\",\n },\n top_p: {\n type: \"number\",\n min: 0,\n max: 1,\n default: 1,\n description: \"Nucleus sampling\",\n },\n top_k: {\n type: \"number\",\n min: 0,\n default: 40,\n description: \"Top-K sampling\",\n },\n frequency_penalty: {\n type: \"number\",\n min: -2,\n max: 2,\n default: 0,\n description: \"Penalize frequent tokens\",\n },\n presence_penalty: {\n type: \"number\",\n min: -2,\n max: 2,\n default: 0,\n description: \"Penalize repeated topics\",\n },\n stop: { type: \"string\", description: \"Stop sequences\" },\n n: { type: \"number\", min: 1, default: 1, description: \"Completions count\" },\n seed: { type: \"number\", description: \"Random seed\" },\n stream: { type: \"boolean\", default: false, description: \"Stream response\" },\n reasoning_effort: {\n type: \"string\",\n values: [\"none\", \"minimal\", \"low\", \"medium\", \"high\", \"xhigh\"],\n default: \"medium\",\n description: \"Reasoning effort\",\n },\n },\n vercel: {\n // Loose validation — proxies to many providers with varying ranges\n temperature: {\n type: \"number\",\n min: 0,\n max: 2,\n default: 0.7,\n description: \"Controls randomness\",\n },\n max_tokens: {\n type: \"number\",\n min: 1,\n default: 4096,\n description: \"Maximum output tokens\",\n },\n top_p: {\n type: \"number\",\n min: 0,\n max: 1,\n default: 1,\n description: \"Nucleus sampling\",\n },\n top_k: {\n type: \"number\",\n min: 0,\n default: 40,\n description: \"Top-K sampling\",\n },\n frequency_penalty: {\n type: \"number\",\n min: -2,\n max: 2,\n default: 0,\n description: \"Penalize frequent tokens\",\n },\n presence_penalty: {\n type: \"number\",\n min: -2,\n max: 2,\n default: 0,\n description: \"Penalize repeated topics\",\n },\n stop: { type: \"string\", description: \"Stop sequences\" },\n n: { type: \"number\", min: 1, default: 1, description: \"Completions count\" },\n seed: { type: \"number\", description: \"Random seed\" },\n stream: { type: \"boolean\", default: false, description: \"Stream response\" },\n reasoning_effort: {\n type: \"string\",\n values: [\"none\", \"minimal\", \"low\", \"medium\", \"high\", \"xhigh\"],\n default: \"medium\",\n description: \"Reasoning effort\",\n },\n },\n};\n\n/** OpenAI reasoning models don't support standard sampling params. */\nexport function isReasoningModel(model: string): boolean {\n // Strip gateway prefix: \"openai/o3\" → \"o3\"\n const name = model.includes(\"/\") ? model.split(\"/\").pop()! : model;\n return /^o[134]/.test(name);\n}\n\n/** Providers that can route to OpenAI models (and need reasoning-model checks). */\nexport function canHostOpenAIModels(provider: Provider): boolean {\n return (\n provider === \"openai\" || provider === \"openrouter\" || provider === \"vercel\"\n );\n}\n\n/** Whether this provider is a gateway/router that proxies to other providers. */\nexport function isGatewayProvider(provider: Provider): boolean {\n return provider === \"openrouter\" || provider === \"vercel\";\n}\n\n/**\n * Extract the underlying provider from a gateway model string.\n * e.g. \"anthropic/claude-sonnet-4-5\" → \"anthropic\"\n * Returns undefined for unknown prefixes (qwen, deepseek, etc.) or models without \"/\".\n */\nexport function detectGatewaySubProvider(model: string): Provider | undefined {\n const slash = model.indexOf(\"/\");\n if (slash < 1) return undefined;\n const prefix = model.slice(0, slash);\n const direct: Provider[] = [\n \"openai\",\n \"anthropic\",\n \"google\",\n \"mistral\",\n \"cohere\",\n ];\n return direct.find((p) => p === prefix);\n}\n\nexport const REASONING_MODEL_UNSUPPORTED = new Set([\n \"temperature\",\n \"top_p\",\n \"frequency_penalty\",\n \"presence_penalty\",\n \"n\",\n]);\n\n/**\n * Bedrock model IDs are prefixed with the vendor name.\n * e.g. \"anthropic.claude-sonnet-4-5-20250929-v1:0\"\n */\nexport type BedrockModelFamily =\n | \"anthropic\"\n | \"meta\"\n | \"amazon\"\n | \"mistral\"\n | \"cohere\"\n | \"ai21\";\n\nexport function detectBedrockModelFamily(\n model: string,\n): BedrockModelFamily | undefined {\n // Handle cross-region inference profiles (e.g. \"us.anthropic.claude-sonnet-4-5...\")\n // and global inference profiles (e.g. \"global.anthropic.claude-sonnet-4-5...\")\n const parts = model.split(\".\");\n\n // If first part is a region prefix (us, eu, apac) or global, skip it\n let prefix = parts[0];\n if ([\"us\", \"eu\", \"apac\", \"global\"].includes(prefix) && parts.length > 1) {\n prefix = parts[1];\n }\n\n const families: BedrockModelFamily[] = [\n \"anthropic\",\n \"meta\",\n \"amazon\",\n \"mistral\",\n \"cohere\",\n \"ai21\",\n ];\n return families.find((f) => prefix === f);\n}\n\n/** Whether a Bedrock model supports prompt caching (Claude and Nova only). */\nexport function bedrockSupportsCaching(model: string): boolean {\n const family = detectBedrockModelFamily(model);\n if (family === \"anthropic\") return true;\n if (family === \"amazon\" && model.includes(\"nova\")) return true;\n return false;\n}\n\n/** Cache value normalization per provider. */\nexport const CACHE_VALUES: Record<Provider, string | undefined> = {\n openai: undefined, // OpenAI auto-caches; no explicit param\n anthropic: \"ephemeral\",\n google: undefined, // Google uses explicit caching API, not a param\n mistral: undefined,\n cohere: undefined,\n bedrock: \"ephemeral\", // Supported for Claude models on Bedrock\n openrouter: undefined, // Depends on underlying provider\n vercel: undefined, // Depends on underlying provider\n};\n\n/** Valid cache TTL values per provider. */\nexport const CACHE_TTLS: Record<Provider, string[] | undefined> = {\n openai: undefined,\n anthropic: [\"5m\", \"1h\"],\n google: undefined,\n mistral: undefined,\n cohere: undefined,\n bedrock: [\"5m\", \"1h\"], // Claude on Bedrock uses same TTLs as direct Anthropic\n openrouter: undefined,\n vercel: undefined,\n};\n\n/** Match a duration expression like \"5m\", \"1h\", \"30m\". */\nexport const DURATION_RE = /^\\d+[mh]$/;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC0CA,SAAS,OAAyB,QAAW,KAAkC;AAC7E,SAAO,OAAO,UAAU,eAAe,KAAK,QAAQ,GAAG;AACzD;AA4FO,SAAS,sBAAsB,OAAqC;AACzE,QAAM,kBAAkB,MAAM,YAAY;AAC1C,MAAI,OAAO,iBAAiB,eAAe,GAAG;AAC5C,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEO,SAAS,eAAe,MAAoC;AACjE,SAAO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Q,KAAK;AAAA,YACX,MAAM;AAAA,YACN,IAAI;AAAA,YACJ;AAAA,YACA,QAAQ,GAAG,QAAQ,UAAU,WAAW,iBAAiB,GAAG;AAAA,UAC9D,CAAC;AAAA,QACH;AACA,cAAM;AAAA,MACR;AAAA,IACF;AAGA,QACE,YACA,oBAAoB,QAAQ,KAC5B,iBAAiB,OAAO,KAAK,KAC7B,QAAQ,cACR;AACA,UAAI,QAAQ,SAAS;AACnB,gBAAQ,KAAK;AAAA,UACX,MAAM;AAAA,UACN,IAAI;AAAA,UACJ;AAAA,UACA,QACE;AAAA,QACJ,CAAC;AAAA,MACH;AACA,YAAM;AAAA,IACR;AAEA,WAAO,GAAG,IAAI;AAAA,EAChB;AAEA,SAAO;AAAA,IACL,QAAQ,EAAE,GAAG,QAAQ,OAAO;AAAA,IAC5B;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
@@ -1,5 +1,5 @@
1
1
  import { LlmConnectionConfig } from './parse.cjs';
2
- import { P as Provider } from './provider-core-DinpG40u.cjs';
2
+ import { P as Provider } from './provider-core-BiAl8MCV.cjs';
3
3
 
4
4
  interface NormalizeChange {
5
5
  from: string;
@@ -1,5 +1,5 @@
1
1
  import { LlmConnectionConfig } from './parse.js';
2
- import { P as Provider } from './provider-core-DinpG40u.js';
2
+ import { P as Provider } from './provider-core-BiAl8MCV.js';
3
3
 
4
4
  interface NormalizeChange {
5
5
  from: string;
package/dist/normalize.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  normalize
3
- } from "./chunk-MPIHGH6L.js";
4
- import "./chunk-XID353H7.js";
3
+ } from "./chunk-2ARD4TFU.js";
4
+ import "./chunk-W4NIQY7M.js";
5
5
  export {
6
6
  normalize
7
7
  };
package/dist/parse.cjs CHANGED
@@ -1,9 +1,133 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
2
19
 
20
+ // src/parse.ts
21
+ var parse_exports = {};
22
+ __export(parse_exports, {
23
+ build: () => build,
24
+ parse: () => parse
25
+ });
26
+ module.exports = __toCommonJS(parse_exports);
3
27
 
4
- var _chunkN6NVBE43cjs = require('./chunk-N6NVBE43.cjs');
28
+ // src/provider-core.ts
29
+ function hasOwn(object, key) {
30
+ return Object.prototype.hasOwnProperty.call(object, key);
31
+ }
32
+ var HOST_ALIASES = {
33
+ openai: "api.openai.com",
34
+ anthropic: "api.anthropic.com",
35
+ google: "generativelanguage.googleapis.com",
36
+ aistudio: "generativelanguage.googleapis.com",
37
+ mistral: "api.mistral.ai",
38
+ cohere: "api.cohere.com",
39
+ bedrock: "bedrock-runtime.us-east-1.amazonaws.com",
40
+ openrouter: "openrouter.ai",
41
+ vercel: "gateway.ai.vercel.app",
42
+ alibaba: "dashscope-intl.aliyuncs.com",
43
+ alibabacloud: "dashscope-intl.aliyuncs.com",
44
+ dashscope: "dashscope-intl.aliyuncs.com",
45
+ fireworks: "api.fireworks.ai",
46
+ fireworksai: "api.fireworks.ai",
47
+ venice: "api.venice.ai",
48
+ parasail: "api.parasail.io",
49
+ deepinfra: "api.deepinfra.com",
50
+ atlascloud: "api.atlascloud.ai",
51
+ novita: "api.novita.ai",
52
+ novitaai: "api.novita.ai",
53
+ grok: "api.x.ai",
54
+ xai: "api.x.ai",
55
+ wandb: "api.inference.wandb.ai",
56
+ weightsandbiases: "api.inference.wandb.ai",
57
+ baidu: "qianfan.baidubce.com",
58
+ qianfan: "qianfan.baidubce.com",
59
+ vertex: "aiplatform.googleapis.com",
60
+ xiaomi: "api.xiaomimimo.com",
61
+ minimax: "api.minimax.io"
62
+ };
63
+ function readProcessEnv() {
64
+ return typeof process !== "undefined" && process.env ? process.env : {};
65
+ }
66
+ function normalizeHostValue(value) {
67
+ const trimmed = value.trim();
68
+ if (!trimmed) return trimmed;
69
+ try {
70
+ if (trimmed.includes("://")) {
71
+ return new URL(trimmed).host;
72
+ }
73
+ } catch {
74
+ }
75
+ return trimmed.replace(/^\/\//, "").split("/")[0] ?? trimmed;
76
+ }
77
+ function envHostOverride(alias, env) {
78
+ const upper = alias.toUpperCase();
79
+ const override = env[`LLM_STRINGS_${upper}_HOST`] ?? env[`LLM_STRINGS_HOST_${upper}`];
80
+ return override?.trim() ? override : void 0;
81
+ }
82
+ function resolveHostAlias(host, env = readProcessEnv()) {
83
+ const normalizedHost = host.toLowerCase();
84
+ if (!hasOwn(HOST_ALIASES, normalizedHost)) {
85
+ return { host };
86
+ }
87
+ const alias = normalizedHost;
88
+ const override = envHostOverride(alias, env);
89
+ return {
90
+ host: normalizeHostValue(override ?? HOST_ALIASES[alias]),
91
+ alias
92
+ };
93
+ }
5
94
 
6
-
7
-
8
- exports.build = _chunkN6NVBE43cjs.build; exports.parse = _chunkN6NVBE43cjs.parse;
95
+ // src/parse.ts
96
+ function parse(connectionString) {
97
+ const url = new URL(connectionString);
98
+ if (url.protocol !== "llm:") {
99
+ throw new Error(
100
+ `Invalid scheme: expected "llm://", got "${url.protocol}//"`
101
+ );
102
+ }
103
+ const { host, alias: hostAlias } = resolveHostAlias(url.host);
104
+ const model = url.pathname.replace(/^\//, "");
105
+ const label = url.username || void 0;
106
+ const apiKey = url.password || void 0;
107
+ const params = {};
108
+ for (const [key, value] of url.searchParams) {
109
+ params[key] = value;
110
+ }
111
+ return {
112
+ raw: connectionString,
113
+ host,
114
+ hostAlias,
115
+ model,
116
+ label,
117
+ apiKey,
118
+ params
119
+ };
120
+ }
121
+ function build(config) {
122
+ const { host } = resolveHostAlias(config.host);
123
+ const auth = config.label || config.apiKey ? `${config.label ?? ""}${config.apiKey ? `:${config.apiKey}` : ""}@` : "";
124
+ const query = new URLSearchParams(config.params).toString();
125
+ const qs = query ? `?${query}` : "";
126
+ return `llm://${auth}${host}/${config.model}${qs}`;
127
+ }
128
+ // Annotate the CommonJS export names for ESM import in node:
129
+ 0 && (module.exports = {
130
+ build,
131
+ parse
132
+ });
9
133
  //# sourceMappingURL=parse.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/dan/code/oss/llm-strings/dist/parse.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACF,iFAAC","file":"/Users/dan/code/oss/llm-strings/dist/parse.cjs"}
1
+ {"version":3,"sources":["../src/parse.ts","../src/provider-core.ts"],"sourcesContent":["import { resolveHostAlias } from \"./provider-core.js\";\nimport type { HostAlias } from \"./provider-core.js\";\n\nexport interface LlmConnectionConfig {\n /** The original connection string */\n raw: string;\n /** Provider's API host (e.g. \"api.openai.com\") */\n host: string;\n /** Short provider alias that was expanded to host, if any. */\n hostAlias?: HostAlias;\n /** Model name (e.g. \"gpt-5.2\") */\n model: string;\n /** Optional label or app name */\n label?: string;\n /** Optional API key or password */\n apiKey?: string;\n /** Additional config parameters (temp, max_tokens, etc.) */\n params: Record<string, string>;\n}\n\n/**\n * Parse an LLM connection string into its component parts.\n *\n * Format: `llm://[label[:apiKey]@]host/model[?key=value&...]`\n *\n * @example\n * ```ts\n * parse(\"llm://api.openai.com/gpt-5.2?temp=0.7&max_tokens=1500\")\n * parse(\"llm://app-name:sk-proj-123456@api.openai.com/gpt-5.2?temp=0.7\")\n * ```\n */\nexport function parse(connectionString: string): LlmConnectionConfig {\n const url = new URL(connectionString);\n\n if (url.protocol !== \"llm:\") {\n throw new Error(\n `Invalid scheme: expected \"llm://\", got \"${url.protocol}//\"`,\n );\n }\n\n const { host, alias: hostAlias } = resolveHostAlias(url.host);\n const model = url.pathname.replace(/^\\//, \"\");\n const label = url.username || undefined;\n const apiKey = url.password || undefined;\n\n const params: Record<string, string> = {};\n for (const [key, value] of url.searchParams) {\n params[key] = value;\n }\n\n return {\n raw: connectionString,\n host,\n hostAlias,\n model,\n label,\n apiKey,\n params,\n };\n}\n\n/**\n * Build an LLM connection string from a config object.\n */\nexport function build(config: Omit<LlmConnectionConfig, \"raw\">): string {\n const { host } = resolveHostAlias(config.host);\n const auth =\n config.label || config.apiKey\n ? `${config.label ?? \"\"}${config.apiKey ? `:${config.apiKey}` : \"\"}@`\n : \"\";\n\n const query = new URLSearchParams(config.params).toString();\n const qs = query ? `?${query}` : \"\";\n\n return `llm://${auth}${host}/${config.model}${qs}`;\n}\n","export type Provider =\n | \"openai\"\n | \"anthropic\"\n | \"google\"\n | \"mistral\"\n | \"cohere\"\n | \"bedrock\"\n | \"openrouter\"\n | \"vercel\";\n\nexport type HostAlias =\n | Provider\n | \"aistudio\"\n | \"alibaba\"\n | \"alibabacloud\"\n | \"atlascloud\"\n | \"baidu\"\n | \"dashscope\"\n | \"deepinfra\"\n | \"fireworks\"\n | \"fireworksai\"\n | \"grok\"\n | \"minimax\"\n | \"novita\"\n | \"novitaai\"\n | \"parasail\"\n | \"qianfan\"\n | \"vertex\"\n | \"venice\"\n | \"wandb\"\n | \"weightsandbiases\"\n | \"xai\"\n | \"xiaomi\";\n\ntype Env = Record<string, string | undefined>;\n\ndeclare const process:\n | {\n env?: Env;\n }\n | undefined;\n\nfunction hasOwn<T extends object>(object: T, key: PropertyKey): key is keyof T {\n return Object.prototype.hasOwnProperty.call(object, key);\n}\n\nexport const HOST_ALIASES: Record<HostAlias, string> = {\n openai: \"api.openai.com\",\n anthropic: \"api.anthropic.com\",\n google: \"generativelanguage.googleapis.com\",\n aistudio: \"generativelanguage.googleapis.com\",\n mistral: \"api.mistral.ai\",\n cohere: \"api.cohere.com\",\n bedrock: \"bedrock-runtime.us-east-1.amazonaws.com\",\n openrouter: \"openrouter.ai\",\n vercel: \"gateway.ai.vercel.app\",\n alibaba: \"dashscope-intl.aliyuncs.com\",\n alibabacloud: \"dashscope-intl.aliyuncs.com\",\n dashscope: \"dashscope-intl.aliyuncs.com\",\n fireworks: \"api.fireworks.ai\",\n fireworksai: \"api.fireworks.ai\",\n venice: \"api.venice.ai\",\n parasail: \"api.parasail.io\",\n deepinfra: \"api.deepinfra.com\",\n atlascloud: \"api.atlascloud.ai\",\n novita: \"api.novita.ai\",\n novitaai: \"api.novita.ai\",\n grok: \"api.x.ai\",\n xai: \"api.x.ai\",\n wandb: \"api.inference.wandb.ai\",\n weightsandbiases: \"api.inference.wandb.ai\",\n baidu: \"qianfan.baidubce.com\",\n qianfan: \"qianfan.baidubce.com\",\n vertex: \"aiplatform.googleapis.com\",\n xiaomi: \"api.xiaomimimo.com\",\n minimax: \"api.minimax.io\",\n};\n\nexport interface HostResolution {\n /** The hostname/host to use for requests. */\n host: string;\n /** The provider alias that was expanded, if any. */\n alias?: HostAlias;\n}\n\nfunction readProcessEnv(): Env {\n return typeof process !== \"undefined\" && process.env ? process.env : {};\n}\n\nfunction normalizeHostValue(value: string): string {\n const trimmed = value.trim();\n if (!trimmed) return trimmed;\n\n try {\n if (trimmed.includes(\"://\")) {\n return new URL(trimmed).host;\n }\n } catch {\n // Fall through and treat it as a host-ish string.\n }\n\n return trimmed.replace(/^\\/\\//, \"\").split(\"/\")[0] ?? trimmed;\n}\n\nfunction envHostOverride(alias: HostAlias, env: Env): string | undefined {\n const upper = alias.toUpperCase();\n const override =\n env[`LLM_STRINGS_${upper}_HOST`] ?? env[`LLM_STRINGS_HOST_${upper}`];\n return override?.trim() ? override : undefined;\n}\n\n/**\n * Resolve short provider host aliases (`openai`, `anthropic`, etc.) to their\n * canonical hostnames. Per-provider environment overrides can redirect aliases\n * to regional or private endpoints:\n *\n * - `LLM_STRINGS_OPENAI_HOST`\n * - `LLM_STRINGS_HOST_OPENAI`\n */\nexport function resolveHostAlias(\n host: string,\n env: Env = readProcessEnv(),\n): HostResolution {\n const normalizedHost = host.toLowerCase();\n if (!hasOwn(HOST_ALIASES, normalizedHost)) {\n return { host };\n }\n\n const alias = normalizedHost as HostAlias;\n const override = envHostOverride(alias, env);\n return {\n host: normalizeHostValue(override ?? HOST_ALIASES[alias]),\n alias,\n };\n}\n\nexport function providerFromHostAlias(alias: string): Provider | undefined {\n const normalizedAlias = alias.toLowerCase();\n if (hasOwn(PROVIDER_PARAMS, normalizedAlias)) {\n return normalizedAlias as Provider;\n }\n return undefined;\n}\n\nexport function detectProvider(host: string): Provider | undefined {\n host = host.toLowerCase();\n\n // Gateways and aggregators first — they proxy to other providers\n if (host.includes(\"openrouter\")) return \"openrouter\";\n if (host.includes(\"gateway.ai.vercel\")) return \"vercel\";\n // Bedrock before native providers since it hosts models from multiple vendors\n if (host.includes(\"amazonaws\") || host.includes(\"bedrock\")) return \"bedrock\";\n if (host.includes(\"openai\")) return \"openai\";\n if (host.includes(\"anthropic\") || host.includes(\"claude\")) return \"anthropic\";\n if (host.includes(\"googleapis\") || host.includes(\"google\")) return \"google\";\n if (host.includes(\"mistral\")) return \"mistral\";\n if (host.includes(\"cohere\")) return \"cohere\";\n return undefined;\n}\n\n/**\n * Shorthand aliases → canonical param name.\n * Canonical names use snake_case and follow OpenAI conventions where possible.\n */\nexport const ALIASES: Record<string, string> = {\n // temperature\n temp: \"temperature\",\n\n // max_tokens\n max: \"max_tokens\",\n max_out: \"max_tokens\",\n max_output: \"max_tokens\",\n max_output_tokens: \"max_tokens\",\n max_completion_tokens: \"max_tokens\",\n maxOutputTokens: \"max_tokens\",\n maxTokens: \"max_tokens\",\n\n // top_p\n topp: \"top_p\",\n topP: \"top_p\",\n nucleus: \"top_p\",\n\n // top_k\n topk: \"top_k\",\n topK: \"top_k\",\n\n // frequency_penalty\n freq: \"frequency_penalty\",\n freq_penalty: \"frequency_penalty\",\n frequencyPenalty: \"frequency_penalty\",\n repetition_penalty: \"frequency_penalty\",\n\n // presence_penalty\n pres: \"presence_penalty\",\n pres_penalty: \"presence_penalty\",\n presencePenalty: \"presence_penalty\",\n\n // stop\n stop_sequences: \"stop\",\n stopSequences: \"stop\",\n stop_sequence: \"stop\",\n\n // seed\n random_seed: \"seed\",\n randomSeed: \"seed\",\n\n // n (completions count)\n candidateCount: \"n\",\n candidate_count: \"n\",\n num_completions: \"n\",\n\n // effort / reasoning\n reasoning_effort: \"effort\",\n reasoning: \"effort\",\n\n // cache\n cache_control: \"cache\",\n cacheControl: \"cache\",\n cachePoint: \"cache\",\n cache_point: \"cache\",\n};\n\n/**\n * Canonical param name → provider-specific API param name.\n * Only includes params the provider actually supports.\n */\nexport const PROVIDER_PARAMS: Record<Provider, Record<string, string>> = {\n openai: {\n temperature: \"temperature\",\n max_tokens: \"max_tokens\",\n top_p: \"top_p\",\n frequency_penalty: \"frequency_penalty\",\n presence_penalty: \"presence_penalty\",\n stop: \"stop\",\n n: \"n\",\n seed: \"seed\",\n stream: \"stream\",\n effort: \"reasoning_effort\",\n },\n anthropic: {\n temperature: \"temperature\",\n max_tokens: \"max_tokens\",\n top_p: \"top_p\",\n top_k: \"top_k\",\n stop: \"stop_sequences\",\n stream: \"stream\",\n effort: \"effort\",\n cache: \"cache_control\",\n cache_ttl: \"cache_ttl\",\n },\n google: {\n temperature: \"temperature\",\n max_tokens: \"maxOutputTokens\",\n top_p: \"topP\",\n top_k: \"topK\",\n frequency_penalty: \"frequencyPenalty\",\n presence_penalty: \"presencePenalty\",\n stop: \"stopSequences\",\n n: \"candidateCount\",\n stream: \"stream\",\n seed: \"seed\",\n responseMimeType: \"responseMimeType\",\n responseSchema: \"responseSchema\",\n },\n mistral: {\n temperature: \"temperature\",\n max_tokens: \"max_tokens\",\n top_p: \"top_p\",\n frequency_penalty: \"frequency_penalty\",\n presence_penalty: \"presence_penalty\",\n stop: \"stop\",\n n: \"n\",\n seed: \"random_seed\",\n stream: \"stream\",\n safe_prompt: \"safe_prompt\",\n min_tokens: \"min_tokens\",\n },\n cohere: {\n temperature: \"temperature\",\n max_tokens: \"max_tokens\",\n top_p: \"p\",\n top_k: \"k\",\n frequency_penalty: \"frequency_penalty\",\n presence_penalty: \"presence_penalty\",\n stop: \"stop_sequences\",\n stream: \"stream\",\n seed: \"seed\",\n },\n bedrock: {\n // Bedrock Converse API uses camelCase\n temperature: \"temperature\",\n max_tokens: \"maxTokens\",\n top_p: \"topP\",\n top_k: \"topK\", // Claude models via additionalModelRequestFields\n stop: \"stopSequences\",\n stream: \"stream\",\n cache: \"cache_control\",\n cache_ttl: \"cache_ttl\",\n },\n openrouter: {\n // OpenAI-compatible API with extra routing params\n temperature: \"temperature\",\n max_tokens: \"max_tokens\",\n top_p: \"top_p\",\n top_k: \"top_k\",\n frequency_penalty: \"frequency_penalty\",\n presence_penalty: \"presence_penalty\",\n stop: \"stop\",\n n: \"n\",\n seed: \"seed\",\n stream: \"stream\",\n effort: \"reasoning_effort\",\n },\n vercel: {\n // OpenAI-compatible gateway\n temperature: \"temperature\",\n max_tokens: \"max_tokens\",\n top_p: \"top_p\",\n top_k: \"top_k\",\n frequency_penalty: \"frequency_penalty\",\n presence_penalty: \"presence_penalty\",\n stop: \"stop\",\n n: \"n\",\n seed: \"seed\",\n stream: \"stream\",\n effort: \"reasoning_effort\",\n },\n};\n\n/**\n * Validation specs per provider, keyed by provider-specific param name.\n */\nexport interface ParamSpec {\n type: \"number\" | \"string\" | \"boolean\";\n min?: number;\n max?: number;\n values?: string[];\n default?: string | number | boolean;\n description?: string;\n}\n\nexport const PARAM_SPECS: Record<Provider, Record<string, ParamSpec>> = {\n openai: {\n temperature: {\n type: \"number\",\n min: 0,\n max: 2,\n default: 0.7,\n description: \"Controls randomness\",\n },\n max_tokens: {\n type: \"number\",\n min: 1,\n default: 4096,\n description: \"Maximum output tokens\",\n },\n top_p: {\n type: \"number\",\n min: 0,\n max: 1,\n default: 1,\n description: \"Nucleus sampling\",\n },\n frequency_penalty: {\n type: \"number\",\n min: -2,\n max: 2,\n default: 0,\n description: \"Penalize frequent tokens\",\n },\n presence_penalty: {\n type: \"number\",\n min: -2,\n max: 2,\n default: 0,\n description: \"Penalize repeated topics\",\n },\n stop: { type: \"string\", description: \"Stop sequences\" },\n n: { type: \"number\", min: 1, default: 1, description: \"Completions count\" },\n seed: { type: \"number\", description: \"Random seed\" },\n stream: { type: \"boolean\", default: false, description: \"Stream response\" },\n reasoning_effort: {\n type: \"string\",\n values: [\"none\", \"minimal\", \"low\", \"medium\", \"high\", \"xhigh\"],\n default: \"medium\",\n description: \"Reasoning effort\",\n },\n },\n anthropic: {\n temperature: {\n type: \"number\",\n min: 0,\n max: 1,\n default: 0.7,\n description: \"Controls randomness\",\n },\n max_tokens: {\n type: \"number\",\n min: 1,\n default: 4096,\n description: \"Maximum output tokens\",\n },\n top_p: {\n type: \"number\",\n min: 0,\n max: 1,\n default: 1,\n description: \"Nucleus sampling\",\n },\n top_k: {\n type: \"number\",\n min: 0,\n default: 40,\n description: \"Top-K sampling\",\n },\n stop_sequences: { type: \"string\", description: \"Stop sequences\" },\n stream: { type: \"boolean\", default: false, description: \"Stream response\" },\n effort: {\n type: \"string\",\n values: [\"low\", \"medium\", \"high\", \"max\"],\n default: \"medium\",\n description: \"Thinking effort\",\n },\n cache_control: {\n type: \"string\",\n values: [\"ephemeral\"],\n default: \"ephemeral\",\n description: \"Cache control\",\n },\n cache_ttl: {\n type: \"string\",\n values: [\"5m\", \"1h\"],\n default: \"5m\",\n description: \"Cache TTL\",\n },\n },\n google: {\n temperature: {\n type: \"number\",\n min: 0,\n max: 2,\n default: 0.7,\n description: \"Controls randomness\",\n },\n maxOutputTokens: {\n type: \"number\",\n min: 1,\n default: 4096,\n description: \"Maximum output tokens\",\n },\n topP: {\n type: \"number\",\n min: 0,\n max: 1,\n default: 1,\n description: \"Nucleus sampling\",\n },\n topK: {\n type: \"number\",\n min: 0,\n default: 40,\n description: \"Top-K sampling\",\n },\n frequencyPenalty: {\n type: \"number\",\n min: -2,\n max: 2,\n default: 0,\n description: \"Penalize frequent tokens\",\n },\n presencePenalty: {\n type: \"number\",\n min: -2,\n max: 2,\n default: 0,\n description: \"Penalize repeated topics\",\n },\n stopSequences: { type: \"string\", description: \"Stop sequences\" },\n candidateCount: {\n type: \"number\",\n min: 1,\n default: 1,\n description: \"Candidate count\",\n },\n stream: { type: \"boolean\", default: false, description: \"Stream response\" },\n seed: { type: \"number\", description: \"Random seed\" },\n responseMimeType: { type: \"string\", description: \"Response MIME type\" },\n responseSchema: { type: \"string\", description: \"Response schema\" },\n },\n mistral: {\n temperature: {\n type: \"number\",\n min: 0,\n max: 1,\n default: 0.7,\n description: \"Controls randomness\",\n },\n max_tokens: {\n type: \"number\",\n min: 1,\n default: 4096,\n description: \"Maximum output tokens\",\n },\n top_p: {\n type: \"number\",\n min: 0,\n max: 1,\n default: 1,\n description: \"Nucleus sampling\",\n },\n frequency_penalty: {\n type: \"number\",\n min: -2,\n max: 2,\n default: 0,\n description: \"Penalize frequent tokens\",\n },\n presence_penalty: {\n type: \"number\",\n min: -2,\n max: 2,\n default: 0,\n description: \"Penalize repeated topics\",\n },\n stop: { type: \"string\", description: \"Stop sequences\" },\n n: { type: \"number\", min: 1, default: 1, description: \"Completions count\" },\n random_seed: { type: \"number\", description: \"Random seed\" },\n stream: { type: \"boolean\", default: false, description: \"Stream response\" },\n safe_prompt: {\n type: \"boolean\",\n default: false,\n description: \"Enable safe prompt\",\n },\n min_tokens: {\n type: \"number\",\n min: 0,\n default: 0,\n description: \"Minimum tokens\",\n },\n },\n cohere: {\n temperature: {\n type: \"number\",\n min: 0,\n max: 1,\n default: 0.7,\n description: \"Controls randomness\",\n },\n max_tokens: {\n type: \"number\",\n min: 1,\n default: 4096,\n description: \"Maximum output tokens\",\n },\n p: {\n type: \"number\",\n min: 0,\n max: 1,\n default: 1,\n description: \"Nucleus sampling (p)\",\n },\n k: {\n type: \"number\",\n min: 0,\n max: 500,\n default: 40,\n description: \"Top-K sampling (k)\",\n },\n frequency_penalty: {\n type: \"number\",\n min: 0,\n max: 1,\n default: 0,\n description: \"Penalize frequent tokens\",\n },\n presence_penalty: {\n type: \"number\",\n min: 0,\n max: 1,\n default: 0,\n description: \"Penalize repeated topics\",\n },\n stop_sequences: { type: \"string\", description: \"Stop sequences\" },\n stream: { type: \"boolean\", default: false, description: \"Stream response\" },\n seed: { type: \"number\", description: \"Random seed\" },\n },\n bedrock: {\n // Converse API inferenceConfig params\n temperature: {\n type: \"number\",\n min: 0,\n max: 1,\n default: 0.7,\n description: \"Controls randomness\",\n },\n maxTokens: {\n type: \"number\",\n min: 1,\n default: 4096,\n description: \"Maximum output tokens\",\n },\n topP: {\n type: \"number\",\n min: 0,\n max: 1,\n default: 1,\n description: \"Nucleus sampling\",\n },\n topK: {\n type: \"number\",\n min: 0,\n default: 40,\n description: \"Top-K sampling\",\n },\n stopSequences: { type: \"string\", description: \"Stop sequences\" },\n stream: { type: \"boolean\", default: false, description: \"Stream response\" },\n cache_control: {\n type: \"string\",\n values: [\"ephemeral\"],\n default: \"ephemeral\",\n description: \"Cache control\",\n },\n cache_ttl: {\n type: \"string\",\n values: [\"5m\", \"1h\"],\n default: \"5m\",\n description: \"Cache TTL\",\n },\n },\n openrouter: {\n // Loose validation — proxies to many providers with varying ranges\n temperature: {\n type: \"number\",\n min: 0,\n max: 2,\n default: 0.7,\n description: \"Controls randomness\",\n },\n max_tokens: {\n type: \"number\",\n min: 1,\n default: 4096,\n description: \"Maximum output tokens\",\n },\n top_p: {\n type: \"number\",\n min: 0,\n max: 1,\n default: 1,\n description: \"Nucleus sampling\",\n },\n top_k: {\n type: \"number\",\n min: 0,\n default: 40,\n description: \"Top-K sampling\",\n },\n frequency_penalty: {\n type: \"number\",\n min: -2,\n max: 2,\n default: 0,\n description: \"Penalize frequent tokens\",\n },\n presence_penalty: {\n type: \"number\",\n min: -2,\n max: 2,\n default: 0,\n description: \"Penalize repeated topics\",\n },\n stop: { type: \"string\", description: \"Stop sequences\" },\n n: { type: \"number\", min: 1, default: 1, description: \"Completions count\" },\n seed: { type: \"number\", description: \"Random seed\" },\n stream: { type: \"boolean\", default: false, description: \"Stream response\" },\n reasoning_effort: {\n type: \"string\",\n values: [\"none\", \"minimal\", \"low\", \"medium\", \"high\", \"xhigh\"],\n default: \"medium\",\n description: \"Reasoning effort\",\n },\n },\n vercel: {\n // Loose validation — proxies to many providers with varying ranges\n temperature: {\n type: \"number\",\n min: 0,\n max: 2,\n default: 0.7,\n description: \"Controls randomness\",\n },\n max_tokens: {\n type: \"number\",\n min: 1,\n default: 4096,\n description: \"Maximum output tokens\",\n },\n top_p: {\n type: \"number\",\n min: 0,\n max: 1,\n default: 1,\n description: \"Nucleus sampling\",\n },\n top_k: {\n type: \"number\",\n min: 0,\n default: 40,\n description: \"Top-K sampling\",\n },\n frequency_penalty: {\n type: \"number\",\n min: -2,\n max: 2,\n default: 0,\n description: \"Penalize frequent tokens\",\n },\n presence_penalty: {\n type: \"number\",\n min: -2,\n max: 2,\n default: 0,\n description: \"Penalize repeated topics\",\n },\n stop: { type: \"string\", description: \"Stop sequences\" },\n n: { type: \"number\", min: 1, default: 1, description: \"Completions count\" },\n seed: { type: \"number\", description: \"Random seed\" },\n stream: { type: \"boolean\", default: false, description: \"Stream response\" },\n reasoning_effort: {\n type: \"string\",\n values: [\"none\", \"minimal\", \"low\", \"medium\", \"high\", \"xhigh\"],\n default: \"medium\",\n description: \"Reasoning effort\",\n },\n },\n};\n\n/** OpenAI reasoning models don't support standard sampling params. */\nexport function isReasoningModel(model: string): boolean {\n // Strip gateway prefix: \"openai/o3\" → \"o3\"\n const name = model.includes(\"/\") ? model.split(\"/\").pop()! : model;\n return /^o[134]/.test(name);\n}\n\n/** Providers that can route to OpenAI models (and need reasoning-model checks). */\nexport function canHostOpenAIModels(provider: Provider): boolean {\n return (\n provider === \"openai\" || provider === \"openrouter\" || provider === \"vercel\"\n );\n}\n\n/** Whether this provider is a gateway/router that proxies to other providers. */\nexport function isGatewayProvider(provider: Provider): boolean {\n return provider === \"openrouter\" || provider === \"vercel\";\n}\n\n/**\n * Extract the underlying provider from a gateway model string.\n * e.g. \"anthropic/claude-sonnet-4-5\" → \"anthropic\"\n * Returns undefined for unknown prefixes (qwen, deepseek, etc.) or models without \"/\".\n */\nexport function detectGatewaySubProvider(model: string): Provider | undefined {\n const slash = model.indexOf(\"/\");\n if (slash < 1) return undefined;\n const prefix = model.slice(0, slash);\n const direct: Provider[] = [\n \"openai\",\n \"anthropic\",\n \"google\",\n \"mistral\",\n \"cohere\",\n ];\n return direct.find((p) => p === prefix);\n}\n\nexport const REASONING_MODEL_UNSUPPORTED = new Set([\n \"temperature\",\n \"top_p\",\n \"frequency_penalty\",\n \"presence_penalty\",\n \"n\",\n]);\n\n/**\n * Bedrock model IDs are prefixed with the vendor name.\n * e.g. \"anthropic.claude-sonnet-4-5-20250929-v1:0\"\n */\nexport type BedrockModelFamily =\n | \"anthropic\"\n | \"meta\"\n | \"amazon\"\n | \"mistral\"\n | \"cohere\"\n | \"ai21\";\n\nexport function detectBedrockModelFamily(\n model: string,\n): BedrockModelFamily | undefined {\n // Handle cross-region inference profiles (e.g. \"us.anthropic.claude-sonnet-4-5...\")\n // and global inference profiles (e.g. \"global.anthropic.claude-sonnet-4-5...\")\n const parts = model.split(\".\");\n\n // If first part is a region prefix (us, eu, apac) or global, skip it\n let prefix = parts[0];\n if ([\"us\", \"eu\", \"apac\", \"global\"].includes(prefix) && parts.length > 1) {\n prefix = parts[1];\n }\n\n const families: BedrockModelFamily[] = [\n \"anthropic\",\n \"meta\",\n \"amazon\",\n \"mistral\",\n \"cohere\",\n \"ai21\",\n ];\n return families.find((f) => prefix === f);\n}\n\n/** Whether a Bedrock model supports prompt caching (Claude and Nova only). */\nexport function bedrockSupportsCaching(model: string): boolean {\n const family = detectBedrockModelFamily(model);\n if (family === \"anthropic\") return true;\n if (family === \"amazon\" && model.includes(\"nova\")) return true;\n return false;\n}\n\n/** Cache value normalization per provider. */\nexport const CACHE_VALUES: Record<Provider, string | undefined> = {\n openai: undefined, // OpenAI auto-caches; no explicit param\n anthropic: \"ephemeral\",\n google: undefined, // Google uses explicit caching API, not a param\n mistral: undefined,\n cohere: undefined,\n bedrock: \"ephemeral\", // Supported for Claude models on Bedrock\n openrouter: undefined, // Depends on underlying provider\n vercel: undefined, // Depends on underlying provider\n};\n\n/** Valid cache TTL values per provider. */\nexport const CACHE_TTLS: Record<Provider, string[] | undefined> = {\n openai: undefined,\n anthropic: [\"5m\", \"1h\"],\n google: undefined,\n mistral: undefined,\n cohere: undefined,\n bedrock: [\"5m\", \"1h\"], // Claude on Bedrock uses same TTLs as direct Anthropic\n openrouter: undefined,\n vercel: undefined,\n};\n\n/** Match a duration expression like \"5m\", \"1h\", \"30m\". */\nexport const DURATION_RE = /^\\d+[mh]$/;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC0CA,SAAS,OAAyB,QAAW,KAAkC;AAC7E,SAAO,OAAO,UAAU,eAAe,KAAK,QAAQ,GAAG;AACzD;AAEO,IAAM,eAA0C;AAAA,EACrD,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,cAAc;AAAA,EACd,WAAW;AAAA,EACX,WAAW;AAAA,EACX,aAAa;AAAA,EACb,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,MAAM;AAAA,EACN,KAAK;AAAA,EACL,OAAO;AAAA,EACP,kBAAkB;AAAA,EAClB,OAAO;AAAA,E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AAM,QAAQ,IAAI,YAAY;AAC9B,QAAM,SAAS,IAAI,YAAY;AAE/B,QAAM,SAAiC,CAAC;AACxC,aAAW,CAAC,KAAK,KAAK,KAAK,IAAI,cAAc;AAC3C,WAAO,GAAG,IAAI;AAAA,EAChB;AAEA,SAAO;AAAA,IACL,KAAK;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAKO,SAAS,MAAM,QAAkD;AACtE,QAAM,EAAE,KAAK,IAAI,iBAAiB,OAAO,IAAI;AAC7C,QAAM,OACJ,OAAO,SAAS,OAAO,SACnB,GAAG,OAAO,SAAS,EAAE,GAAG,OAAO,SAAS,IAAI,OAAO,MAAM,KAAK,EAAE,MAChE;AAEN,QAAM,QAAQ,IAAI,gBAAgB,OAAO,MAAM,EAAE,SAAS;AAC1D,QAAM,KAAK,QAAQ,IAAI,KAAK,KAAK;AAEjC,SAAO,SAAS,IAAI,GAAG,IAAI,IAAI,OAAO,KAAK,GAAG,EAAE;AAClD;","names":[]}
package/dist/parse.d.cts CHANGED
@@ -1,8 +1,12 @@
1
+ import { a as HostAlias } from './provider-core-BiAl8MCV.cjs';
2
+
1
3
  interface LlmConnectionConfig {
2
4
  /** The original connection string */
3
5
  raw: string;
4
- /** Provider's API base URL (e.g. "api.openai.com") */
6
+ /** Provider's API host (e.g. "api.openai.com") */
5
7
  host: string;
8
+ /** Short provider alias that was expanded to host, if any. */
9
+ hostAlias?: HostAlias;
6
10
  /** Model name (e.g. "gpt-5.2") */
7
11
  model: string;
8
12
  /** Optional label or app name */
package/dist/parse.d.ts CHANGED
@@ -1,8 +1,12 @@
1
+ import { a as HostAlias } from './provider-core-BiAl8MCV.js';
2
+
1
3
  interface LlmConnectionConfig {
2
4
  /** The original connection string */
3
5
  raw: string;
4
- /** Provider's API base URL (e.g. "api.openai.com") */
6
+ /** Provider's API host (e.g. "api.openai.com") */
5
7
  host: string;
8
+ /** Short provider alias that was expanded to host, if any. */
9
+ hostAlias?: HostAlias;
6
10
  /** Model name (e.g. "gpt-5.2") */
7
11
  model: string;
8
12
  /** Optional label or app name */
package/dist/parse.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  build,
3
3
  parse
4
- } from "./chunk-FCEV23OT.js";
4
+ } from "./chunk-BCOUH7LH.js";
5
+ import "./chunk-W4NIQY7M.js";
5
6
  export {
6
7
  build,
7
8
  parse
@@ -1,4 +1,23 @@
1
1
  type Provider = "openai" | "anthropic" | "google" | "mistral" | "cohere" | "bedrock" | "openrouter" | "vercel";
2
+ type HostAlias = Provider | "aistudio" | "alibaba" | "alibabacloud" | "atlascloud" | "baidu" | "dashscope" | "deepinfra" | "fireworks" | "fireworksai" | "grok" | "minimax" | "novita" | "novitaai" | "parasail" | "qianfan" | "vertex" | "venice" | "wandb" | "weightsandbiases" | "xai" | "xiaomi";
3
+ type Env = Record<string, string | undefined>;
4
+ declare const HOST_ALIASES: Record<HostAlias, string>;
5
+ interface HostResolution {
6
+ /** The hostname/host to use for requests. */
7
+ host: string;
8
+ /** The provider alias that was expanded, if any. */
9
+ alias?: HostAlias;
10
+ }
11
+ /**
12
+ * Resolve short provider host aliases (`openai`, `anthropic`, etc.) to their
13
+ * canonical hostnames. Per-provider environment overrides can redirect aliases
14
+ * to regional or private endpoints:
15
+ *
16
+ * - `LLM_STRINGS_OPENAI_HOST`
17
+ * - `LLM_STRINGS_HOST_OPENAI`
18
+ */
19
+ declare function resolveHostAlias(host: string, env?: Env): HostResolution;
20
+ declare function providerFromHostAlias(alias: string): Provider | undefined;
2
21
  declare function detectProvider(host: string): Provider | undefined;
3
22
  /**
4
23
  * Shorthand aliases → canonical param name.
@@ -50,4 +69,4 @@ declare const CACHE_TTLS: Record<Provider, string[] | undefined>;
50
69
  /** Match a duration expression like "5m", "1h", "30m". */
51
70
  declare const DURATION_RE: RegExp;
52
71
 
53
- export { ALIASES as A, type BedrockModelFamily as B, CACHE_TTLS as C, DURATION_RE as D, type Provider as P, REASONING_MODEL_UNSUPPORTED as R, CACHE_VALUES as a, PARAM_SPECS as b, PROVIDER_PARAMS as c, type ParamSpec as d, bedrockSupportsCaching as e, canHostOpenAIModels as f, detectBedrockModelFamily as g, detectGatewaySubProvider as h, detectProvider as i, isGatewayProvider as j, isReasoningModel as k };
72
+ export { ALIASES as A, type BedrockModelFamily as B, CACHE_TTLS as C, DURATION_RE as D, HOST_ALIASES as H, type Provider as P, REASONING_MODEL_UNSUPPORTED as R, type HostAlias as a, type HostResolution as b, CACHE_VALUES as c, PARAM_SPECS as d, PROVIDER_PARAMS as e, type ParamSpec as f, bedrockSupportsCaching as g, canHostOpenAIModels as h, detectBedrockModelFamily as i, detectGatewaySubProvider as j, detectProvider as k, isGatewayProvider as l, isReasoningModel as m, providerFromHostAlias as p, resolveHostAlias as r };
@@ -1,4 +1,23 @@
1
1
  type Provider = "openai" | "anthropic" | "google" | "mistral" | "cohere" | "bedrock" | "openrouter" | "vercel";
2
+ type HostAlias = Provider | "aistudio" | "alibaba" | "alibabacloud" | "atlascloud" | "baidu" | "dashscope" | "deepinfra" | "fireworks" | "fireworksai" | "grok" | "minimax" | "novita" | "novitaai" | "parasail" | "qianfan" | "vertex" | "venice" | "wandb" | "weightsandbiases" | "xai" | "xiaomi";
3
+ type Env = Record<string, string | undefined>;
4
+ declare const HOST_ALIASES: Record<HostAlias, string>;
5
+ interface HostResolution {
6
+ /** The hostname/host to use for requests. */
7
+ host: string;
8
+ /** The provider alias that was expanded, if any. */
9
+ alias?: HostAlias;
10
+ }
11
+ /**
12
+ * Resolve short provider host aliases (`openai`, `anthropic`, etc.) to their
13
+ * canonical hostnames. Per-provider environment overrides can redirect aliases
14
+ * to regional or private endpoints:
15
+ *
16
+ * - `LLM_STRINGS_OPENAI_HOST`
17
+ * - `LLM_STRINGS_HOST_OPENAI`
18
+ */
19
+ declare function resolveHostAlias(host: string, env?: Env): HostResolution;
20
+ declare function providerFromHostAlias(alias: string): Provider | undefined;
2
21
  declare function detectProvider(host: string): Provider | undefined;
3
22
  /**
4
23
  * Shorthand aliases → canonical param name.
@@ -50,4 +69,4 @@ declare const CACHE_TTLS: Record<Provider, string[] | undefined>;
50
69
  /** Match a duration expression like "5m", "1h", "30m". */
51
70
  declare const DURATION_RE: RegExp;
52
71
 
53
- export { ALIASES as A, type BedrockModelFamily as B, CACHE_TTLS as C, DURATION_RE as D, type Provider as P, REASONING_MODEL_UNSUPPORTED as R, CACHE_VALUES as a, PARAM_SPECS as b, PROVIDER_PARAMS as c, type ParamSpec as d, bedrockSupportsCaching as e, canHostOpenAIModels as f, detectBedrockModelFamily as g, detectGatewaySubProvider as h, detectProvider as i, isGatewayProvider as j, isReasoningModel as k };
72
+ export { ALIASES as A, type BedrockModelFamily as B, CACHE_TTLS as C, DURATION_RE as D, HOST_ALIASES as H, type Provider as P, REASONING_MODEL_UNSUPPORTED as R, type HostAlias as a, type HostResolution as b, CACHE_VALUES as c, PARAM_SPECS as d, PROVIDER_PARAMS as e, type ParamSpec as f, bedrockSupportsCaching as g, canHostOpenAIModels as h, detectBedrockModelFamily as i, detectGatewaySubProvider as j, detectProvider as k, isGatewayProvider as l, isReasoningModel as m, providerFromHostAlias as p, resolveHostAlias as r };