import { type ChatMessage, type ChatResponse } from 'openai-fetch'; import { type Jsonifiable } from 'type-fest'; import { type Msg } from '../types.js'; type ChatResponseMessage = ChatResponse['choices'][0]['message']; /** Utility class for creating and checking message types. */ export declare class MsgUtil { /** Create a system message. Cleans indentation and newlines by default. */ static system(content: string, opts?: { /** Custom name for the message. */ name?: string; /** Whether to clean extra newlines and indentation. Defaults to true. */ cleanContent?: boolean; }): Msg.System; /** Create a developer message. Cleans indentation and newlines by default. */ static developer(content: string, opts?: { /** Custom name for the message. */ name?: string; /** Whether to clean extra newlines and indentation. Defaults to true. */ cleanContent?: boolean; }): Msg.Developer; /** Create a user message. Cleans indentation and newlines by default. */ static user(content: string, opts?: { /** Custom name for the message. */ name?: string; /** Whether to clean extra newlines and indentation. Defaults to true. */ cleanContent?: boolean; }): Msg.User; /** Create an assistant message. Cleans indentation and newlines by default. */ static assistant(content: string, opts?: { /** Custom name for the message. */ name?: string; /** Whether to clean extra newlines and indentation. Defaults to true. */ cleanContent?: boolean; }): Msg.Assistant; /** Create a function call message with argumets. */ static funcCall(function_call: { /** Name of the function to call. */ name: string; /** Arguments to pass to the function. */ arguments: string; }, opts?: { /** The name descriptor for the message.(message.name) */ name?: string; }): Msg.FuncCall; /** Create a function result message. */ static funcResult(content: Jsonifiable, name: string): Msg.FuncResult; /** Create a function call message with argumets. */ static toolCall(tool_calls: Msg.Call.Tool[], opts?: { /** The name descriptor for the message.(message.name) */ name?: string; }): Msg.ToolCall; /** Create a tool call result message. */ static toolResult(content: Jsonifiable, tool_call_id: string, opts?: { /** The name of the tool which was called */ name?: string; }): Msg.ToolResult; /** Check if a message is a system message. */ static isSystem(message: ChatMessage | ChatResponseMessage | Msg): message is Msg.System; /** Check if a message is a developer message. */ static isDeveloper(message: ChatMessage | ChatResponseMessage | Msg): message is Msg.Developer; /** Throw a RefusalError if a message is a refusal. */ private static throwIfRefusal; /** Assert that a message is a system message. */ static assertSystem(message: ChatMessage | ChatResponseMessage | Msg): asserts message is Msg.System; /** Check if a message is a user message. */ static isUser(message: ChatMessage | ChatResponseMessage | Msg): message is Msg.User; /** Assert that a message is a user message. */ static assertUser(message: ChatMessage | ChatResponseMessage | Msg): asserts message is Msg.User; /** Check if a message is an assistant message. */ static isAssistant(message: ChatMessage | ChatResponseMessage | Msg): message is Msg.Assistant; /** Assert that a message is an assistant message. */ static assertAssistant(message: ChatMessage | ChatResponseMessage | Msg): asserts message is Msg.Assistant; /** Check if a message is a refusal message. */ static isRefusal(message: ChatMessage | ChatResponseMessage): message is Msg.Refusal; /** Assert that a message is a refusal message. */ static assertRefusal(message: ChatMessage | ChatResponseMessage | Msg): asserts message is Msg.Refusal; /** Check if a message is a function call message with arguments. */ static isFuncCall(message: ChatMessage | ChatResponseMessage | Msg): message is Msg.FuncCall; /** Assert that a message is a function call message with arguments. */ static assertFuncCall(message: ChatMessage | ChatResponseMessage | Msg): asserts message is Msg.FuncCall; /** Check if a message is a function result message. */ static isFuncResult(message: ChatMessage | ChatResponseMessage | Msg): message is Msg.FuncResult; /** Assert that a message is a function result message. */ static assertFuncResult(message: ChatMessage | ChatResponseMessage | Msg): asserts message is Msg.FuncResult; /** Check if a message is a tool calls message. */ static isToolCall(message: ChatMessage | ChatResponseMessage | Msg): message is Msg.ToolCall; /** Assert that a message is a tool calls message. */ static assertToolCall(message: ChatMessage | ChatResponseMessage | Msg): asserts message is Msg.ToolCall; /** Check if a message is a tool call result message. */ static isToolResult(message: ChatMessage | ChatResponseMessage | Msg): message is Msg.ToolResult; /** Assert that a message is a tool call result message. */ static assertToolResult(message: ChatMessage | ChatResponseMessage | Msg): asserts message is Msg.ToolResult; /** * Narrow a ChatModel.Message to a specific type. */ static fromChatMessage(message: ChatMessage | ChatResponseMessage): Msg.System | Msg.User | Msg.Assistant | Msg.Refusal | Msg.FuncCall | Msg.FuncResult | Msg.ToolCall | Msg.ToolResult; } /** * Clean a string by removing extra newlines and indentation. * @see: https://github.com/dmnd/dedent */ export declare function cleanString(text: string): string; export {};