import type { GatewayProviderContext, GatewayProviderFactory, GatewayStreamRequest } from "@cline/shared"; import { type CallSettings } from "ai"; import type { AiSdkStreamTotalUsage, AiSdkStreamUsage, ProviderFactoryResult } from "./vendors/types"; interface GatewayNormalizedUsage { inputTokens: number; outputTokens: number; cacheReadTokens: number; cacheWriteTokens: number; reasoningTokenCount?: number; totalCost?: number; } export declare function buildAiSdkStreamConfig(request: GatewayStreamRequest, _context: GatewayProviderContext): Partial; interface RepairableToolCall { toolCallId: string; toolName: string; input: string; } /** * Last-chance repair for tool calls whose arguments are not valid JSON * (truncated payloads, single quotes, unescaped newlines — common with * weaker models). Runs the raw argument text through the shared jsonrepair * strategies; unknown tool names and already-valid JSON are not repairable * here, and returning null preserves the AI SDK's original error behavior. */ export declare function repairMalformedToolCall({ toolCall, error, }: { toolCall: T; error: unknown; }): Promise; /** * Normalizes usage from various provider formats into a standard structure. * Accepts both AI SDK's normalized shapes (AiSdkStreamTotalUsage, AiSdkStreamUsage) * and raw provider responses. Handles multiple naming conventions (camelCase vs snake_case), * extracts costs from provider-specific fields, and falls back to pricing-based calculation. * Provider-reported billed cost takes precedence over market cost so gateway discounts * are reflected in user-facing totals. Market cost remains a fallback when no billed * cost is available. * * @param usageValue - AI SDK normalized usage or raw provider response object * @param providerMetadata - Provider-specific metadata for cost extraction * @param pricingValue - Fallback pricing config (per 1M tokens) when no explicit cost found */ export declare function normalizeUsage(usageValue: AiSdkStreamUsage | AiSdkStreamTotalUsage | Record | undefined, providerMetadata?: unknown, pricingValue?: unknown): GatewayNormalizedUsage; /** * Wrap a vendor-constructed model with the transient-failure retry * middleware (empty responses + pre-content network interruptions). * * All-empty turns (no text, no reasoning, no tool call) are a cross-provider * phenomenon: production telemetry shows them on hosted backends (openrouter, * cline, generic OpenAI-compatible endpoints), not just local Ollama. An * empty assistant turn is a hard failure in the agent runtime ("Model * returned empty response"), so a single transient flake kills the task. * The same telemetry shows mid-stream network deaths (UND_ERR_SOCKET, * body/headers timeouts, ECONNRESET) as the dominant network-class run * killer — the AI SDK's own retry covers only request initiation, so once a * stream has started nothing else retries. Retrying here — the one * composition point every AI SDK vendor flows through — turns those flakes * into non-events while leaving the runtime's loud failure in place for * models that are persistently empty or connections that are truly down. * * Applied as the *outermost* wrap so each retry re-runs the vendor's full * request pipeline, including any vendor-level middleware attached inside * `provider.operations.language(...)`. Vendors opt out or tune attempts through * `ProviderFactoryResult.retryEmptyResponses`. */ export declare function withEmptyResponseRetry(model: unknown, retryEmptyResponses: ProviderFactoryResult["retryEmptyResponses"], logger: GatewayProviderContext["logger"]): unknown; export declare const createOpenAIProvider: GatewayProviderFactory; export declare const createClineProvider: GatewayProviderFactory; export declare const createOpenAICompatibleProvider: GatewayProviderFactory; export declare const createAnthropicProvider: GatewayProviderFactory; export declare const createGoogleProvider: GatewayProviderFactory; export declare const createVertexProvider: GatewayProviderFactory; export declare const createBedrockProvider: GatewayProviderFactory; export declare const createMistralProvider: GatewayProviderFactory; export declare const createClaudeCodeProvider: GatewayProviderFactory; export declare const createOpenAICodexProvider: GatewayProviderFactory; export declare const createOpenCodeProvider: GatewayProviderFactory; export declare const createDifyProvider: GatewayProviderFactory; export declare const createOllamaProvider: GatewayProviderFactory; export declare const createSapAiCoreProvider: GatewayProviderFactory; export {}; //# sourceMappingURL=ai-sdk.d.ts.map