UNPKG

@maximai/maxim-js

Version:

Maxim AI JS SDK. Visit https://getmaxim.ai for more info.

81 lines (80 loc) 3.91 kB
import { LanguageModelV1CallOptions, LanguageModelV1ProviderMetadata } from "ai-sdk-provider-v1"; import { LanguageModelV2CallOptions, LanguageModelV2ToolResultOutput, SharedV2ProviderOptions } from "ai-sdk-provider-v2"; import { LanguageModelV3CallOptions, LanguageModelV3ToolResultOutput, SharedV3ProviderOptions } from "ai-sdk-provider-v3"; import { MaximVercelProviderMetadata } from "./types"; /** * Determines the provider type from a given model string. * * This function inspects the model identifier and returns a type-safe provider name (such as 'openai', 'bedrock', 'anthropic', etc.) based on known substrings in the model name. * If no known provider is found, it defaults to 'openai'. * * @param model - The model identifier string to inspect. * @returns The detected provider name. */ export declare function determineProvider(model: string): "openai" | "bedrock" | "anthropic" | "huggingface" | "azure" | "together" | "groq" | "google" | "elevenlabs"; /** * Extracts supported model parameters from the given language model call options. * * This function pulls out relevant generation parameters (such as temperature, maxTokens, penalties, etc.) from the provided LanguageModelV1CallOptions object, returning them in a plain object for downstream use. * * @param options - The call options containing model parameters. * @returns An object containing the extracted model parameters, including temperature, maxTokens, topP, topK, frequencyPenalty, stopSequences, seed, headers, presencePenalty, abortSignal, and responseFormat. */ export declare function extractModelParameters(options: LanguageModelV1CallOptions | LanguageModelV2CallOptions | LanguageModelV3CallOptions): { temperature: number | undefined; topP: number | undefined; topK: number | undefined; frequencyPenalty: number | undefined; stopSequences: string[] | undefined; seed: number | undefined; headers: Record<string, string | undefined> | undefined; presencePenalty: number | undefined; abortSignal: AbortSignal | undefined; responseFormat: { type: "text"; } | { type: "json"; schema?: import("json-schema").JSONSchema7; name?: string; description?: string; } | { type: "text"; } | { type: "json"; schema?: import("json-schema").JSONSchema7; name?: string; description?: string; } | { type: "text"; } | { type: "json"; schema?: import("json-schema").JSONSchema7; name?: string; description?: string; } | undefined; }; /** * Extracts Maxim-specific provider metadata from the given language model call options. * * This function retrieves the `maxim` metadata object from the `providerMetadata` field of the options, for advanced tracing and logging in Maxim's observability system. * * @param options - The call options containing provider metadata. * @returns The extracted Maxim metadata with a guaranteed `spanId`, or undefined if not present. */ export declare function extractMaximMetadataFromOptions(metadata: LanguageModelV1ProviderMetadata | SharedV2ProviderOptions | SharedV3ProviderOptions | undefined): MaximVercelProviderMetadata | undefined; /** * Extracts structured error information from any thrown value. * * Handles standard Error objects, API error objects (with code/type fields), * plain strings, and unknown values — so generation.error() always receives * a meaningful message instead of an empty object. * * @param error - The caught value from a catch block. * @returns An object with message, and optionally code and type. */ export declare function extractErrorInfo(error: unknown): { message: string; code?: string; type?: string; }; export declare function parseToolResultOutput(content: LanguageModelV2ToolResultOutput | LanguageModelV3ToolResultOutput): string;