UNPKG

@maximai/maxim-js

Version:

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

93 lines (92 loc) 3.52 kB
import type { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3StreamPart } from "ai-sdk-provider-v3"; import { MaximLogger } from "../../logger"; export declare class MaximAISDKWrapperV3 implements LanguageModelV3 { private model; private logger; private currentTraceId; private currentTrace; private currentSession; private isInToolCallSequence; private addedAttachmentHashes; /** * @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: LanguageModelV3, 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: LanguageModelV3CallOptions): Promise<import("ai-sdk-provider-v3").LanguageModelV3GenerateResult>; /** * 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: LanguageModelV3CallOptions): Promise<{ stream: import("stream/web").ReadableStream<LanguageModelV3StreamPart>; request?: { body?: unknown; }; response?: { headers?: import("ai-sdk-provider-v3").SharedV3Headers; }; }>; /** * 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(): "v3"; /** * 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[]>>; /** * Creates a simple hash of a buffer for duplicate detection. * Uses a combination of buffer length and a sample of the data. * * @private * @param buffer - The buffer to hash * @returns A hash string identifying the buffer */ private hashBuffer; }