@maximai/maxim-js
Version:
Maxim AI JS SDK. Visit https://getmaxim.ai for more info.
45 lines (44 loc) • 3.05 kB
TypeScript
import { LanguageModelV2Prompt, LanguageModelV2StreamPart } from "ai-sdk-provider-v2";
import { ChatCompletionMessage, ChatCompletionResult, CompletionRequest, Generation, Span, Trace } from "index";
import type { MaximLogger } from "../../logger";
import { DoGenerateV2Result, MaximVercelProviderMetadata } from "../types";
/**
* Converts a LanguageModelV2Prompt into an array of CompletionRequest or ChatCompletionMessage objects.
*
* This function transforms the structured prompt format used by the Vercel AI SDK v2 into the message format expected by downstream consumers, handling system, user, assistant, and tool roles.
*
* @param prompt - The prompt to be parsed, consisting of structured message parts.
* @returns An array of parsed messages suitable for completion requests or chat completions.
* @throws If an unsupported user message type is encountered.
*/
export declare function parsePromptMessagesV2(prompt: LanguageModelV2Prompt): Array<CompletionRequest | ChatCompletionMessage>;
/**
* Processes tool results from the raw prompt and logs them to Maxim.
* Calls toolCallError for error-type results (error-text, error-json) and toolCallResult for successes.
*
* @param prompt - The raw LanguageModelV2 prompt containing tool results
* @param logger - The MaximLogger instance for logging tool results/errors
*/
export declare function processToolResultsFromPromptV2(prompt: LanguageModelV2Prompt, logger: MaximLogger): void;
/**
* Converts a doGenerate result object into a ChatCompletionResult format.
*
* This function adapts the result of a language model generation v2 (including token usage, model info, and choices) into the standardized ChatCompletionResult structure expected by downstream consumers.
*
* @param result - The result object from a generation call, including usage, response, and content fields.
* @returns The formatted chat completion result, including id, model, choices, and token usage.
*/
export declare function convertDoGenerateResultToChatCompletionResultV2(result: DoGenerateV2Result): ChatCompletionResult;
/**
* Processes a stream of language model output chunks and logs the result to Maxim tracing.
*
* This function aggregates streamed output parts, constructs a chat completion result, and finalizes the generation, span, and trace as appropriate. It also handles errors and ensures proper cleanup of tracing resources.
*
* @param chunks - The array of streamed output parts from the language model.
* @param span - The Maxim tracing span associated with this generation.
* @param trace - The Maxim tracing trace associated with this generation.
* @param generation - The Maxim generation object to log the result to.
* @param model - The model identifier used for this generation.
* @param maximMetadata - Optional Maxim metadata for advanced tracing.
*/
export declare function processStreamV2(chunks: LanguageModelV2StreamPart[], span: Span, trace: Trace, generation: Generation, model: string, maximMetadata: MaximVercelProviderMetadata | undefined): void;