UNPKG

assistant-stream

Version:

Streaming utilities for AI assistants

93 lines • 2.62 kB
/** * Generic message types for framework-agnostic LLM message interchange. * These types represent a common format that can be converted to/from * various LLM provider formats (AI SDK, LangChain, etc.). */ import type { ToolModelContentPart } from "../tool/tool-types.js"; export type GenericTextPart = { type: "text"; text: string; }; export type GenericFilePart = { type: "file"; data: string | URL; mediaType: string; filename?: string; }; export type GenericToolCallPart = { type: "tool-call"; toolCallId: string; toolName: string; args: Record<string, unknown>; }; export type GenericToolResultPart = { type: "tool-result"; toolCallId: string; toolName: string; result: unknown; /** Explicit model-visible content for a settled tool result. */ modelContent?: readonly ToolModelContentPart[]; isError?: boolean; }; export type GenericSystemMessage = { role: "system"; content: string; }; export type GenericUserMessage = { role: "user"; content: (GenericTextPart | GenericFilePart)[]; }; export type GenericAssistantMessage = { role: "assistant"; content: (GenericTextPart | GenericFilePart | GenericToolCallPart)[]; }; export type GenericToolMessage = { role: "tool"; content: GenericToolResultPart[]; }; export type GenericMessage = GenericSystemMessage | GenericUserMessage | GenericAssistantMessage | GenericToolMessage; type MessagePartLike = { type: string; text?: string; image?: string; audio?: { data?: string; format?: "mp3" | "wav"; }; data?: string; mimeType?: string; filename?: string; toolCallId?: string; toolName?: string; args?: Record<string, unknown>; state?: string; result?: unknown; modelContent?: readonly ToolModelContentPart[]; isError?: boolean; isPreliminary?: boolean; approval?: { approved?: boolean; resolution?: string; [key: string]: unknown; }; interrupt?: unknown; }; type AttachmentLike = { contentType?: string; content: readonly MessagePartLike[]; }; type ThreadMessageLike = { role: "system" | "user" | "assistant"; content: readonly MessagePartLike[]; attachments?: readonly AttachmentLike[]; status?: { type: string; }; }; /** * Converts thread messages to generic LLM messages. * This format can then be easily converted to provider-specific formats. */ export declare function toGenericMessages(messages: readonly ThreadMessageLike[]): GenericMessage[]; export {}; //# sourceMappingURL=toGenericMessages.d.ts.map