aieo 0.1.37 → 0.1.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -47,10 +47,11 @@ type Provider = "anthropic" | "google" | "openai" | "openrouter" | "xai";
47
47
  * URLs without hand-rolling the suffix.
48
48
  *
49
49
  * NOTE: OpenRouter has no dedicated Bifrost route and rides the OpenAI
50
- * path. If you spawn an agent in a way where the runtime would override
51
- * the model to an OpenRouter model, you want the OpenAI suffix here too.
52
- * xAI likewise rides the OpenAI-compat path (model id prefixed `xai/`
53
- * in getModel), since Bifrost has no dedicated Grok route.
50
+ * path (model id prefixed `openrouter/` in getModel so Bifrost routes it
51
+ * upstream). If you spawn an agent in a way where the runtime would
52
+ * override the model to an OpenRouter model, you want the OpenAI suffix
53
+ * here too. xAI likewise rides the OpenAI-compat path (model id prefixed
54
+ * `xai/` in getModel), since Bifrost has no dedicated Grok route.
54
55
  */
55
56
  declare const GATEWAY_PATHS: Record<Provider, string>;
56
57
  declare function getGatewayBaseURL(provider: Provider): string | undefined;
@@ -125,6 +126,9 @@ declare function gatewayEnvForProviders(baseUrl: string): {
125
126
  declare const normalizeCallerBaseURL: typeof gatewayUrlFor;
126
127
  declare const PROVIDERS: Provider[];
127
128
  type ModelName = "sonnet" | "opus" | "haiku" | "gemini" | "gpt" | "kimi" | "grok";
129
+ type ModelId = string;
130
+ declare const MODELS: Record<Provider, Partial<Record<ModelName, ModelId>>>;
131
+ declare const DEFAULT_MODELS: Record<Provider, string>;
128
132
  declare function getLightModelForProvider(provider: Provider): string;
129
133
  interface TokenPricing {
130
134
  inputTokenPrice: number;
@@ -151,6 +155,11 @@ declare function getProviderForModel(modelName?: ModelName | string): Provider;
151
155
  * pasted with a trailing space still authenticates.
152
156
  */
153
157
  declare function normalizeApiKey(key?: string | null): string | undefined;
158
+ /**
159
+ * The env var each provider's API key is read from. Exported so a host with
160
+ * its own secret store knows which NAME to look up (see resolve.ts).
161
+ */
162
+ declare const API_KEY_ENV: Record<Provider, string>;
154
163
  declare function hasApiKeyForProvider(provider: Provider | string): boolean;
155
164
  declare function getApiKeyForProvider(provider: Provider | string): string;
156
165
  interface GetModelOptions {
@@ -252,6 +261,91 @@ declare function resolveLLMConfig(opts?: {
252
261
  light?: boolean;
253
262
  }): LLMConfig;
254
263
 
264
+ interface ModelOption {
265
+ provider: Provider;
266
+ alias: ModelName;
267
+ modelId: string;
268
+ /** The provider's default — what you get with no model name at all. */
269
+ default: boolean;
270
+ }
271
+ /**
272
+ * Every alias in the MODELS table, in PROVIDERS order. Pure and keyless,
273
+ * which is what a UI picker or a server-config endpoint needs.
274
+ */
275
+ declare function listModels(): ModelOption[];
276
+ interface ParsedModelName {
277
+ /** Set only when the name carries an explicit "<provider>/" prefix. */
278
+ provider?: Provider;
279
+ /** The name with that prefix stripped. Aliases are NOT resolved here.
280
+ * undefined for an empty name (or a bare "<provider>/"). */
281
+ modelId?: string;
282
+ }
283
+ /** Pure syntax: strip an explicit provider prefix, nothing else. */
284
+ declare function parseModelName(name?: string): ParsedModelName;
285
+ interface ModelRef {
286
+ provider: Provider;
287
+ /** Concrete id as the provider knows it (alias resolved, prefix stripped). */
288
+ modelId: string;
289
+ /** Canonical "<provider>/<modelId>" — unambiguous, itself a valid model name. */
290
+ name: string;
291
+ }
292
+ /**
293
+ * Resolve a model name to its provider + concrete id WITHOUT an API key.
294
+ * Follows getModel's rules — explicit `provider` wins, then an explicit
295
+ * prefix, then getProviderForModel's inference; aliases map through MODELS;
296
+ * no name → the provider's default — so what this reports is what
297
+ * resolveModel / getModel will build. (One deliberate extra: an alias after
298
+ * a prefix, "anthropic/sonnet", resolves too.)
299
+ *
300
+ * Rejects the one input getModel silently gets wrong: a slashed name whose
301
+ * first segment is NOT a provider ("moonshotai/kimi-k2.6") with nothing
302
+ * else naming the provider — inference falls to the default and the request
303
+ * 404s at the wrong API. Say so up front, with the fix. LLM_PROVIDER, when
304
+ * set, counts as "something naming the provider", exactly as it does for
305
+ * getProviderForModel.
306
+ */
307
+ declare function canonicalModelName(model?: string, provider?: Provider | string): ModelRef;
308
+ /**
309
+ * Per-call output-token cap. An explicit MAX_OUTPUT_TOKENS env always wins.
310
+ * Otherwise the default is provider-aware: Anthropic runs at 128k because
311
+ * @ai-sdk/anthropic clamps known models down to their true per-model max
312
+ * instead of erroring, while OpenAI-compatible hosts (OpenRouter et al)
313
+ * reject max_tokens above the model limit rather than clamping, so they keep
314
+ * the conservative 64k default. Thinking tokens count against this same
315
+ * budget, so headroom matters more than the visible text length suggests.
316
+ */
317
+ declare function maxOutputTokensFor(provider?: string): number;
318
+ interface ResolveOptions {
319
+ /** alias | id | "provider/id" | "openrouter/org/id". Omit for the provider's default. */
320
+ model?: string;
321
+ /** Explicit provider; otherwise inferred from `model`. */
322
+ provider?: Provider | string;
323
+ apiKey?: string;
324
+ /**
325
+ * Async key source consulted by env-var NAME ("OPENAI_API_KEY", …) before
326
+ * process.env — a host's own secret store. Only called when `apiKey` is
327
+ * absent.
328
+ */
329
+ getSecret?: (envName: string) => Promise<string | undefined>;
330
+ baseUrl?: string;
331
+ headers?: Record<string, string>;
332
+ abortSignal?: AbortSignal;
333
+ timeoutMs?: number;
334
+ }
335
+ interface ResolvedModel extends ModelRef {
336
+ model: LanguageModel;
337
+ apiKey: string;
338
+ contextLimit: number;
339
+ maxOutputTokens: number;
340
+ }
341
+ /**
342
+ * Name → everything a caller needs to run: provider, concrete id, canonical
343
+ * name, the API key that was used, the LanguageModel, its context window,
344
+ * and the output-token cap. Key precedence: `apiKey` → `getSecret(envName)`
345
+ * → process.env; none → an error that names the env var. Logs nothing.
346
+ */
347
+ declare function resolveModel(opts?: ResolveOptions): Promise<ResolvedModel>;
348
+
255
349
  interface AiUsage {
256
350
  input: number;
257
351
  cache_read: number;
@@ -749,4 +843,4 @@ declare function createWebFetch(opts: CreateWebFetchOptions): WebFetchHandle;
749
843
  */
750
844
  declare function captureNativeFetchResults(stepContent: unknown, target: WebFetchResult[]): void;
751
845
 
752
- export { type AiUsage, type AiUsageWithLegacy, type Conversation, type ConversationData, ConversationStorage, type CreateWebFetchOptions, type CreateWebSearchOptions, type FetchBackend, type FetchUrlOptions, GATEWAY_PATHS, type GetModelOptions, type HostLookup, type LLMConfig, type Logger, MAX_CONVERSATIONS, type ModelName, OUTRO, PROVIDERS, type Provider, type ProviderTool, SYSTEM, type SearchBackend, type ThinkingSpeed, type TokenPricing, type TokenUsageForCost, WEB_FETCH_TOOL_NAME, WEB_SEARCH_TOOL_NAME, type WebFetchHandle, type WebFetchOptions, type WebFetchResult, type WebSearchHandle, type WebSearchOptions, type WebSearchResult, addUsage, callGenerateObject, callGenerateText, callModel, captureNativeFetchResults, captureNativeResults, computeSessionCost, consoleLogger, createWebFetch, createWebSearch, emptyUsage, fetchUrl, gatewayEnvForProviders, gatewayUrlFor, gatewayUrlForModel, getApiKeyForProvider, getContextLimit, getGatewayBaseURL, getLightModelForProvider, getModel, getModelDetails, getProviderForModel, getProviderOptions, getProviderTool, getSearchApiKey, getTokenPricing, hasApiKeyForProvider, hasSearchApiKey, htmlToText, isPrivateAddress, linkifyCitations, loadModelPricing, normalizeApiKey, normalizeCallerBaseURL, normalizeUsage, resolveFetchBackend, resolveLLMConfig, resolveSearchBackend, searchWeb, stripCitations, validateFetchUrl, withLegacyUsage, withProviderCacheUsage };
846
+ export { API_KEY_ENV, type AiUsage, type AiUsageWithLegacy, type Conversation, type ConversationData, ConversationStorage, type CreateWebFetchOptions, type CreateWebSearchOptions, DEFAULT_MODELS, type FetchBackend, type FetchUrlOptions, GATEWAY_PATHS, type GetModelOptions, type HostLookup, type LLMConfig, type Logger, MAX_CONVERSATIONS, MODELS, type ModelName, type ModelOption, type ModelRef, OUTRO, PROVIDERS, type ParsedModelName, type Provider, type ProviderTool, type ResolveOptions, type ResolvedModel, SYSTEM, type SearchBackend, type ThinkingSpeed, type TokenPricing, type TokenUsageForCost, WEB_FETCH_TOOL_NAME, WEB_SEARCH_TOOL_NAME, type WebFetchHandle, type WebFetchOptions, type WebFetchResult, type WebSearchHandle, type WebSearchOptions, type WebSearchResult, addUsage, callGenerateObject, callGenerateText, callModel, canonicalModelName, captureNativeFetchResults, captureNativeResults, computeSessionCost, consoleLogger, createWebFetch, createWebSearch, emptyUsage, fetchUrl, gatewayEnvForProviders, gatewayUrlFor, gatewayUrlForModel, getApiKeyForProvider, getContextLimit, getGatewayBaseURL, getLightModelForProvider, getModel, getModelDetails, getProviderForModel, getProviderOptions, getProviderTool, getSearchApiKey, getTokenPricing, hasApiKeyForProvider, hasSearchApiKey, htmlToText, isPrivateAddress, linkifyCitations, listModels, loadModelPricing, maxOutputTokensFor, normalizeApiKey, normalizeCallerBaseURL, normalizeUsage, parseModelName, resolveFetchBackend, resolveLLMConfig, resolveModel, resolveSearchBackend, searchWeb, stripCitations, validateFetchUrl, withLegacyUsage, withProviderCacheUsage };
package/dist/index.d.ts CHANGED
@@ -47,10 +47,11 @@ type Provider = "anthropic" | "google" | "openai" | "openrouter" | "xai";
47
47
  * URLs without hand-rolling the suffix.
48
48
  *
49
49
  * NOTE: OpenRouter has no dedicated Bifrost route and rides the OpenAI
50
- * path. If you spawn an agent in a way where the runtime would override
51
- * the model to an OpenRouter model, you want the OpenAI suffix here too.
52
- * xAI likewise rides the OpenAI-compat path (model id prefixed `xai/`
53
- * in getModel), since Bifrost has no dedicated Grok route.
50
+ * path (model id prefixed `openrouter/` in getModel so Bifrost routes it
51
+ * upstream). If you spawn an agent in a way where the runtime would
52
+ * override the model to an OpenRouter model, you want the OpenAI suffix
53
+ * here too. xAI likewise rides the OpenAI-compat path (model id prefixed
54
+ * `xai/` in getModel), since Bifrost has no dedicated Grok route.
54
55
  */
55
56
  declare const GATEWAY_PATHS: Record<Provider, string>;
56
57
  declare function getGatewayBaseURL(provider: Provider): string | undefined;
@@ -125,6 +126,9 @@ declare function gatewayEnvForProviders(baseUrl: string): {
125
126
  declare const normalizeCallerBaseURL: typeof gatewayUrlFor;
126
127
  declare const PROVIDERS: Provider[];
127
128
  type ModelName = "sonnet" | "opus" | "haiku" | "gemini" | "gpt" | "kimi" | "grok";
129
+ type ModelId = string;
130
+ declare const MODELS: Record<Provider, Partial<Record<ModelName, ModelId>>>;
131
+ declare const DEFAULT_MODELS: Record<Provider, string>;
128
132
  declare function getLightModelForProvider(provider: Provider): string;
129
133
  interface TokenPricing {
130
134
  inputTokenPrice: number;
@@ -151,6 +155,11 @@ declare function getProviderForModel(modelName?: ModelName | string): Provider;
151
155
  * pasted with a trailing space still authenticates.
152
156
  */
153
157
  declare function normalizeApiKey(key?: string | null): string | undefined;
158
+ /**
159
+ * The env var each provider's API key is read from. Exported so a host with
160
+ * its own secret store knows which NAME to look up (see resolve.ts).
161
+ */
162
+ declare const API_KEY_ENV: Record<Provider, string>;
154
163
  declare function hasApiKeyForProvider(provider: Provider | string): boolean;
155
164
  declare function getApiKeyForProvider(provider: Provider | string): string;
156
165
  interface GetModelOptions {
@@ -252,6 +261,91 @@ declare function resolveLLMConfig(opts?: {
252
261
  light?: boolean;
253
262
  }): LLMConfig;
254
263
 
264
+ interface ModelOption {
265
+ provider: Provider;
266
+ alias: ModelName;
267
+ modelId: string;
268
+ /** The provider's default — what you get with no model name at all. */
269
+ default: boolean;
270
+ }
271
+ /**
272
+ * Every alias in the MODELS table, in PROVIDERS order. Pure and keyless,
273
+ * which is what a UI picker or a server-config endpoint needs.
274
+ */
275
+ declare function listModels(): ModelOption[];
276
+ interface ParsedModelName {
277
+ /** Set only when the name carries an explicit "<provider>/" prefix. */
278
+ provider?: Provider;
279
+ /** The name with that prefix stripped. Aliases are NOT resolved here.
280
+ * undefined for an empty name (or a bare "<provider>/"). */
281
+ modelId?: string;
282
+ }
283
+ /** Pure syntax: strip an explicit provider prefix, nothing else. */
284
+ declare function parseModelName(name?: string): ParsedModelName;
285
+ interface ModelRef {
286
+ provider: Provider;
287
+ /** Concrete id as the provider knows it (alias resolved, prefix stripped). */
288
+ modelId: string;
289
+ /** Canonical "<provider>/<modelId>" — unambiguous, itself a valid model name. */
290
+ name: string;
291
+ }
292
+ /**
293
+ * Resolve a model name to its provider + concrete id WITHOUT an API key.
294
+ * Follows getModel's rules — explicit `provider` wins, then an explicit
295
+ * prefix, then getProviderForModel's inference; aliases map through MODELS;
296
+ * no name → the provider's default — so what this reports is what
297
+ * resolveModel / getModel will build. (One deliberate extra: an alias after
298
+ * a prefix, "anthropic/sonnet", resolves too.)
299
+ *
300
+ * Rejects the one input getModel silently gets wrong: a slashed name whose
301
+ * first segment is NOT a provider ("moonshotai/kimi-k2.6") with nothing
302
+ * else naming the provider — inference falls to the default and the request
303
+ * 404s at the wrong API. Say so up front, with the fix. LLM_PROVIDER, when
304
+ * set, counts as "something naming the provider", exactly as it does for
305
+ * getProviderForModel.
306
+ */
307
+ declare function canonicalModelName(model?: string, provider?: Provider | string): ModelRef;
308
+ /**
309
+ * Per-call output-token cap. An explicit MAX_OUTPUT_TOKENS env always wins.
310
+ * Otherwise the default is provider-aware: Anthropic runs at 128k because
311
+ * @ai-sdk/anthropic clamps known models down to their true per-model max
312
+ * instead of erroring, while OpenAI-compatible hosts (OpenRouter et al)
313
+ * reject max_tokens above the model limit rather than clamping, so they keep
314
+ * the conservative 64k default. Thinking tokens count against this same
315
+ * budget, so headroom matters more than the visible text length suggests.
316
+ */
317
+ declare function maxOutputTokensFor(provider?: string): number;
318
+ interface ResolveOptions {
319
+ /** alias | id | "provider/id" | "openrouter/org/id". Omit for the provider's default. */
320
+ model?: string;
321
+ /** Explicit provider; otherwise inferred from `model`. */
322
+ provider?: Provider | string;
323
+ apiKey?: string;
324
+ /**
325
+ * Async key source consulted by env-var NAME ("OPENAI_API_KEY", …) before
326
+ * process.env — a host's own secret store. Only called when `apiKey` is
327
+ * absent.
328
+ */
329
+ getSecret?: (envName: string) => Promise<string | undefined>;
330
+ baseUrl?: string;
331
+ headers?: Record<string, string>;
332
+ abortSignal?: AbortSignal;
333
+ timeoutMs?: number;
334
+ }
335
+ interface ResolvedModel extends ModelRef {
336
+ model: LanguageModel;
337
+ apiKey: string;
338
+ contextLimit: number;
339
+ maxOutputTokens: number;
340
+ }
341
+ /**
342
+ * Name → everything a caller needs to run: provider, concrete id, canonical
343
+ * name, the API key that was used, the LanguageModel, its context window,
344
+ * and the output-token cap. Key precedence: `apiKey` → `getSecret(envName)`
345
+ * → process.env; none → an error that names the env var. Logs nothing.
346
+ */
347
+ declare function resolveModel(opts?: ResolveOptions): Promise<ResolvedModel>;
348
+
255
349
  interface AiUsage {
256
350
  input: number;
257
351
  cache_read: number;
@@ -749,4 +843,4 @@ declare function createWebFetch(opts: CreateWebFetchOptions): WebFetchHandle;
749
843
  */
750
844
  declare function captureNativeFetchResults(stepContent: unknown, target: WebFetchResult[]): void;
751
845
 
752
- export { type AiUsage, type AiUsageWithLegacy, type Conversation, type ConversationData, ConversationStorage, type CreateWebFetchOptions, type CreateWebSearchOptions, type FetchBackend, type FetchUrlOptions, GATEWAY_PATHS, type GetModelOptions, type HostLookup, type LLMConfig, type Logger, MAX_CONVERSATIONS, type ModelName, OUTRO, PROVIDERS, type Provider, type ProviderTool, SYSTEM, type SearchBackend, type ThinkingSpeed, type TokenPricing, type TokenUsageForCost, WEB_FETCH_TOOL_NAME, WEB_SEARCH_TOOL_NAME, type WebFetchHandle, type WebFetchOptions, type WebFetchResult, type WebSearchHandle, type WebSearchOptions, type WebSearchResult, addUsage, callGenerateObject, callGenerateText, callModel, captureNativeFetchResults, captureNativeResults, computeSessionCost, consoleLogger, createWebFetch, createWebSearch, emptyUsage, fetchUrl, gatewayEnvForProviders, gatewayUrlFor, gatewayUrlForModel, getApiKeyForProvider, getContextLimit, getGatewayBaseURL, getLightModelForProvider, getModel, getModelDetails, getProviderForModel, getProviderOptions, getProviderTool, getSearchApiKey, getTokenPricing, hasApiKeyForProvider, hasSearchApiKey, htmlToText, isPrivateAddress, linkifyCitations, loadModelPricing, normalizeApiKey, normalizeCallerBaseURL, normalizeUsage, resolveFetchBackend, resolveLLMConfig, resolveSearchBackend, searchWeb, stripCitations, validateFetchUrl, withLegacyUsage, withProviderCacheUsage };
846
+ export { API_KEY_ENV, type AiUsage, type AiUsageWithLegacy, type Conversation, type ConversationData, ConversationStorage, type CreateWebFetchOptions, type CreateWebSearchOptions, DEFAULT_MODELS, type FetchBackend, type FetchUrlOptions, GATEWAY_PATHS, type GetModelOptions, type HostLookup, type LLMConfig, type Logger, MAX_CONVERSATIONS, MODELS, type ModelName, type ModelOption, type ModelRef, OUTRO, PROVIDERS, type ParsedModelName, type Provider, type ProviderTool, type ResolveOptions, type ResolvedModel, SYSTEM, type SearchBackend, type ThinkingSpeed, type TokenPricing, type TokenUsageForCost, WEB_FETCH_TOOL_NAME, WEB_SEARCH_TOOL_NAME, type WebFetchHandle, type WebFetchOptions, type WebFetchResult, type WebSearchHandle, type WebSearchOptions, type WebSearchResult, addUsage, callGenerateObject, callGenerateText, callModel, canonicalModelName, captureNativeFetchResults, captureNativeResults, computeSessionCost, consoleLogger, createWebFetch, createWebSearch, emptyUsage, fetchUrl, gatewayEnvForProviders, gatewayUrlFor, gatewayUrlForModel, getApiKeyForProvider, getContextLimit, getGatewayBaseURL, getLightModelForProvider, getModel, getModelDetails, getProviderForModel, getProviderOptions, getProviderTool, getSearchApiKey, getTokenPricing, hasApiKeyForProvider, hasSearchApiKey, htmlToText, isPrivateAddress, linkifyCitations, listModels, loadModelPricing, maxOutputTokensFor, normalizeApiKey, normalizeCallerBaseURL, normalizeUsage, parseModelName, resolveFetchBackend, resolveLLMConfig, resolveModel, resolveSearchBackend, searchWeb, stripCitations, validateFetchUrl, withLegacyUsage, withProviderCacheUsage };
package/dist/index.js CHANGED
@@ -23178,23 +23178,19 @@ function normalizeApiKey(key) {
23178
23178
  const trimmed = key.trim();
23179
23179
  return trimmed.length > 0 ? trimmed : void 0;
23180
23180
  }
23181
+ var API_KEY_ENV = {
23182
+ anthropic: "ANTHROPIC_API_KEY",
23183
+ google: "GOOGLE_API_KEY",
23184
+ openai: "OPENAI_API_KEY",
23185
+ openrouter: "OPENROUTER_API_KEY",
23186
+ xai: "XAI_API_KEY"
23187
+ };
23181
23188
  function lookupApiKeyForProvider(provider) {
23182
- switch (provider) {
23183
- case "anthropic":
23184
- return normalizeApiKey(process.env.ANTHROPIC_API_KEY);
23185
- case "google":
23186
- return normalizeApiKey(process.env.GOOGLE_API_KEY);
23187
- case "openai":
23188
- return normalizeApiKey(process.env.OPENAI_API_KEY);
23189
- case "openrouter":
23190
- return normalizeApiKey(process.env.OPENROUTER_API_KEY);
23191
- case "xai":
23192
- return normalizeApiKey(process.env.XAI_API_KEY);
23193
- case "claude_code":
23194
- return normalizeApiKey(process.env.CLAUDE_CODE_API_KEY);
23195
- default:
23196
- return void 0;
23189
+ if (provider === "claude_code") {
23190
+ return normalizeApiKey(process.env.CLAUDE_CODE_API_KEY);
23197
23191
  }
23192
+ if (!PROVIDERS.includes(provider)) return void 0;
23193
+ return normalizeApiKey(process.env[API_KEY_ENV[provider]]);
23198
23194
  }
23199
23195
  function hasApiKeyForProvider(provider) {
23200
23196
  return !!lookupApiKeyForProvider(provider);
@@ -23421,7 +23417,8 @@ function getModel(provider, opts) {
23421
23417
  usage: { include: true },
23422
23418
  ...isMoonshot ? { provider: { order: ["moonshotai"], allow_fallbacks: true } } : {}
23423
23419
  };
23424
- return openrouter(modelId, settings);
23420
+ const gatewayModelId = baseURL ? `openrouter/${modelId}` : modelId;
23421
+ return openrouter(gatewayModelId, settings);
23425
23422
  }
23426
23423
  case "xai": {
23427
23424
  if (baseURL) {
@@ -23664,6 +23661,95 @@ function resolveLLMConfig(opts) {
23664
23661
  return { provider, apiKey, model, modelName: effectiveModelName };
23665
23662
  }
23666
23663
 
23664
+ // src/resolve.ts
23665
+ function listModels() {
23666
+ const out = [];
23667
+ for (const provider of PROVIDERS) {
23668
+ for (const [alias, modelId] of Object.entries(MODELS[provider])) {
23669
+ if (!modelId) continue;
23670
+ out.push({
23671
+ provider,
23672
+ alias,
23673
+ modelId,
23674
+ default: DEFAULT_MODELS[provider] === modelId
23675
+ });
23676
+ }
23677
+ }
23678
+ return out;
23679
+ }
23680
+ function parseModelName(name19) {
23681
+ if (!name19) return {};
23682
+ const slash = name19.indexOf("/");
23683
+ if (slash > 0) {
23684
+ const head = name19.slice(0, slash);
23685
+ if (PROVIDERS.includes(head)) {
23686
+ return { provider: head, modelId: name19.slice(slash + 1) || void 0 };
23687
+ }
23688
+ }
23689
+ return { modelId: name19 };
23690
+ }
23691
+ var ALIASES = new Set(Object.values(MODELS).flatMap((m) => Object.keys(m)));
23692
+ function envProvider() {
23693
+ const v = process.env.LLM_PROVIDER;
23694
+ return v && PROVIDERS.includes(v) ? v : void 0;
23695
+ }
23696
+ function canonicalModelName(model, provider) {
23697
+ const parsed = parseModelName(model);
23698
+ const chosen = provider ?? parsed.provider ?? getProviderForModel(model);
23699
+ if (!PROVIDERS.includes(chosen)) {
23700
+ throw new Error(`Unknown LLM provider: "${chosen}". Supported: ${PROVIDERS.join(", ")}`);
23701
+ }
23702
+ const p = chosen;
23703
+ if (model && !provider && !parsed.provider && model.includes("/") && !envProvider()) {
23704
+ const head = model.split("/")[0];
23705
+ throw new Error(
23706
+ `Model "${model}" has no provider prefix: "${head}" is not a provider (${PROVIDERS.join(", ")}). For an OpenRouter-hosted model write "openrouter/${model}"; otherwise pass the provider explicitly.`
23707
+ );
23708
+ }
23709
+ let modelId = parsed.modelId;
23710
+ if (modelId && ALIASES.has(modelId)) {
23711
+ const hit = MODELS[p][modelId];
23712
+ if (!hit) {
23713
+ throw new Error(
23714
+ `Model "${modelId}" is not available for provider "${p}". Available models: ${Object.keys(MODELS[p]).join(", ")}`
23715
+ );
23716
+ }
23717
+ modelId = hit;
23718
+ }
23719
+ if (!modelId) modelId = DEFAULT_MODELS[p];
23720
+ return { provider: p, modelId, name: `${p}/${modelId}` };
23721
+ }
23722
+ function maxOutputTokensFor(provider) {
23723
+ const env = Number(process.env.MAX_OUTPUT_TOKENS);
23724
+ if (env > 0) return env;
23725
+ return provider === "anthropic" ? 128e3 : 64e3;
23726
+ }
23727
+ async function resolveModel(opts = {}) {
23728
+ const ref = canonicalModelName(opts.model, opts.provider);
23729
+ const envName = API_KEY_ENV[ref.provider];
23730
+ const apiKey = normalizeApiKey(opts.apiKey) ?? normalizeApiKey(await opts.getSecret?.(envName)) ?? normalizeApiKey(process.env[envName]);
23731
+ if (!apiKey) {
23732
+ throw new Error(
23733
+ `No API key for provider "${ref.provider}": set ${envName} (or pass apiKey / getSecret)`
23734
+ );
23735
+ }
23736
+ const model = getModel(ref.provider, {
23737
+ modelName: ref.name,
23738
+ apiKey,
23739
+ baseUrl: opts.baseUrl,
23740
+ headers: opts.headers,
23741
+ abortSignal: opts.abortSignal,
23742
+ timeoutMs: opts.timeoutMs
23743
+ });
23744
+ return {
23745
+ ...ref,
23746
+ model,
23747
+ apiKey,
23748
+ contextLimit: getContextLimit(ref.modelId, ref.provider),
23749
+ maxOutputTokens: maxOutputTokensFor(ref.provider)
23750
+ };
23751
+ }
23752
+
23667
23753
  // src/stream.ts
23668
23754
  import {
23669
23755
  streamText,
@@ -24483,9 +24569,12 @@ function consoleLogger(name19) {
24483
24569
  };
24484
24570
  }
24485
24571
  export {
24572
+ API_KEY_ENV,
24486
24573
  ConversationStorage,
24574
+ DEFAULT_MODELS,
24487
24575
  GATEWAY_PATHS,
24488
24576
  MAX_CONVERSATIONS,
24577
+ MODELS,
24489
24578
  OUTRO,
24490
24579
  PROVIDERS,
24491
24580
  SYSTEM,
@@ -24495,6 +24584,7 @@ export {
24495
24584
  callGenerateObject,
24496
24585
  callGenerateText,
24497
24586
  callModel,
24587
+ canonicalModelName,
24498
24588
  captureNativeFetchResults,
24499
24589
  captureNativeResults,
24500
24590
  computeSessionCost,
@@ -24522,12 +24612,16 @@ export {
24522
24612
  htmlToText,
24523
24613
  isPrivateAddress,
24524
24614
  linkifyCitations,
24615
+ listModels,
24525
24616
  loadModelPricing,
24617
+ maxOutputTokensFor,
24526
24618
  normalizeApiKey,
24527
24619
  normalizeCallerBaseURL,
24528
24620
  normalizeUsage,
24621
+ parseModelName,
24529
24622
  resolveFetchBackend,
24530
24623
  resolveLLMConfig,
24624
+ resolveModel,
24531
24625
  resolveSearchBackend,
24532
24626
  searchWeb,
24533
24627
  stripCitations,