UNPKG

@maximai/maxim-js

Version:

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

96 lines (95 loc) 3.78 kB
import type { LanguageModelV2, LanguageModelV2CallOptions, LanguageModelV2StreamPart } from "ai-sdk-provider-v2"; import { MaximLogger } from "../../logger"; export declare class MaximAISDKWrapperV2 implements LanguageModelV2 { private model; private logger; private currentTraceId; private currentTrace; private currentSession; private isInToolCallSequence; /** * @constructor * Creates a new MaximAISDKWrapper instance. * * @param model - The Vercel AI SDK language model instance to wrap. * @param logger - The MaximLogger instance to use for tracing and logging. */ constructor(model: LanguageModelV2, logger: MaximLogger); /** * Sets up Maxim logging and tracing for a model call. * * Extracts Maxim metadata, parses prompt messages, and initializes session, trace, and span objects. * Also logs user input to the trace if appropriate. * * @private * @param options - The call options for the model invocation. * @param promptMessages - The parsed prompt messages (used to detect tool calls). * @returns An object containing maximMetadata, trace, session, span, and promptMessages. */ private setupLogging; /** * Executes a text or object generation call with Maxim tracing and logging. * * This method is called internally by generateText and generateObject, and logs the generation * result, errors, and relevant metadata to Maxim. * * @param options - The call options for the model invocation. * @returns The result of the underlying model's doGenerate call. */ doGenerate(options: LanguageModelV2CallOptions): Promise<{ content: Array<import("ai-sdk-provider-v2").LanguageModelV2Content>; finishReason: import("ai-sdk-provider-v2").LanguageModelV2FinishReason; usage: import("ai-sdk-provider-v2").LanguageModelV2Usage; providerMetadata?: import("ai-sdk-provider-v2").SharedV2ProviderMetadata; request?: { body?: unknown; }; response?: import("ai-sdk-provider-v2").LanguageModelV2ResponseMetadata & { headers?: import("ai-sdk-provider-v2").SharedV2Headers; body?: unknown; }; warnings: Array<import("ai-sdk-provider-v2").LanguageModelV2CallWarning>; }>; /** * Executes a streaming generation call with Maxim tracing and logging. * * This method is called internally by streamText and streamObject, and logs the streaming * result, errors, and relevant metadata to Maxim. * * @param options - The call options for the model invocation. * @returns The result of the underlying model's doStream call, with a wrapped stream. */ doStream(options: LanguageModelV2CallOptions): Promise<{ stream: import("stream/web").ReadableStream<LanguageModelV2StreamPart>; request?: { body?: unknown; }; response?: { headers?: import("ai-sdk-provider-v2").SharedV2Headers; }; }>; /** * Returns the model ID of the wrapped model. * * @returns The model ID. */ get modelId(): string; /** * Returns the provider name of the wrapped model. * * @returns The provider name. */ get provider(): string; /** * Returns the specification version of the wrapped model. * * @returns The specification version. */ get specificationVersion(): "v2"; /** * Supported URL patterns by media type for the provider. * * @returns A map of supported URL patterns by media type (as a promise or a plain object). */ get supportedUrls(): Record<string, RegExp[]> | PromiseLike<Record<string, RegExp[]>>; }