/** * Base class for model gateway providers * Gateways fetch provider configurations and build URLs for model access */ import type { LanguageModelV2 } from '../../../_types/@ai-sdk_provider-v5/dist/index.d.ts'; import type { LanguageModelV3 } from '../../../_types/@ai-sdk_provider-v6/dist/index.d.ts'; import type { StreamTransport } from '../../../stream/types.js'; import type { OpenAITransport, ResponsesWebSocketOptions } from '../provider-options.js'; export interface ProviderConfig { url?: string; apiKeyHeader?: string; apiKeyEnvVar: string | string[]; name: string; models: string[]; docUrl?: string; gateway: string; npm?: string; } /** * Compact capability data collected from gateways during generation. * Each provider maps to a list of model IDs that support attachments. */ export type AttachmentCapabilities = Record; /** * Union type for language models that can be returned by gateways. * Supports both AI SDK v5 (LanguageModelV2) and v6 (LanguageModelV3). */ export type GatewayLanguageModel = LanguageModelV2 | LanguageModelV3; export type GatewayStreamTransportHandle = Pick; /** @internal Stream transport handle attached by gateways that own custom streaming transports. */ export declare const MASTRA_GATEWAY_STREAM_TRANSPORT: unique symbol; export type GatewayLanguageModelWithStreamTransport = GatewayLanguageModel & { [MASTRA_GATEWAY_STREAM_TRANSPORT]?: GatewayStreamTransportHandle; }; export type GatewayAuthSource = 'explicit' | 'gateway' | 'legacy'; export type GatewayAuthRequest = { gatewayId: string; providerId: string; modelId: string; routerId: string; }; export type GatewayAuthResult = { apiKey?: string; bearerToken?: string; headers?: Record; source?: GatewayAuthSource; }; export interface MastraModelGatewayInterface { /** * Unique identifier for the gateway * This ID is used as the prefix for all providers from this gateway (e.g., "netlify/anthropic") * Exception: models.dev is a provider registry and doesn't use a prefix */ readonly id: string; /** * Name of the gateway provider */ readonly name: string; /** * Get the gateway ID. Optional for plain object gateways; defaults to `id`. * @deprecated Use `id` instead. * @returns The gateway ID. */ getId?(): string; /** * Whether this gateway should be enabled for the current runtime. * Disabled gateways are skipped when syncing and filtered out when reading cached registry data. * Optional for plain object gateways; defaults to `true`. */ shouldEnable?(): boolean; /** * Fetch provider configurations from the gateway. * Should return providers in the standard format. */ fetchProviders(): Promise>; /** * Build the URL for a specific model/provider combination * @param modelId Full model ID (e.g., "openai/gpt-4o" or "netlify/openai/gpt-4o") * @param envVars Environment variables available * @returns URL string if this gateway can handle the model, false otherwise */ buildUrl(modelId: string, envVars: Record): string | undefined | Promise; getApiKey(modelId: string): Promise; /** * Resolve auth before falling back to getApiKey/env behavior. */ resolveAuth?(request: GatewayAuthRequest): Promise | GatewayAuthResult | undefined; /** * Resolve a language model from the gateway. * Supports returning either LanguageModelV2 (AI SDK v5) or LanguageModelV3 (AI SDK v6). */ resolveLanguageModel(args: { modelId: string; providerId: string; apiKey: string; headers?: Record; transport?: OpenAITransport; responsesWebSocket?: ResponsesWebSocketOptions; }): Promise | GatewayLanguageModel; /** * Custom serialization for tracing/observability spans. * Gateways typically hold credentials (apiKey, OAuth tokens, customFetch * closures that capture secrets). The base implementation exposes only * the gateway identity so subclasses are safe by default. */ serializeForSpan?(): { id: string; name: string; } & Record; } export declare abstract class MastraModelGateway implements MastraModelGatewayInterface { abstract readonly id: string; abstract readonly name: string; getId(): string; shouldEnable(): boolean; abstract fetchProviders(): Promise>; abstract buildUrl(modelId: string, envVars: Record): string | undefined | Promise; abstract getApiKey(modelId: string): Promise; abstract resolveLanguageModel(args: { modelId: string; providerId: string; apiKey: string; headers?: Record; transport?: OpenAITransport; responsesWebSocket?: ResponsesWebSocketOptions; }): Promise | GatewayLanguageModel; serializeForSpan(): { id: string; name: string; }; } //# sourceMappingURL=base.d.ts.map