UNPKG

@hashbrownai/core

Version:

Runtime helpers for Hashbrown AI

88 lines 4.06 kB
import { Chat } from './models'; import { s } from './schema'; import { StateSignal } from './utils/micro-ngrx'; import { KnownModelIds } from './utils'; /** * Represents a Hashbrown chat instance, providing methods to send and observe messages, track state, and handle errors. * * @template Output - The type of messages received from the LLM, either a string or structured output defined by HashbrownType. * @template Tools - The set of tools available to the chat instance. */ export interface Hashbrown<Output, Tools extends Chat.AnyTool> { messages: StateSignal<Chat.Message<Output, Tools>[]>; error: StateSignal<Error | undefined>; isReceiving: StateSignal<boolean>; isSending: StateSignal<boolean>; isRunningToolCalls: StateSignal<boolean>; isLoading: StateSignal<boolean>; exhaustedRetries: StateSignal<boolean>; lastAssistantMessage: StateSignal<Chat.AssistantMessage<Output, Tools> | undefined>; /** Replace the current set of messages in the chat state. */ setMessages: (messages: Chat.Message<Output, Tools>[]) => void; /** Send a new message to the LLM and update state. */ sendMessage: (message: Chat.Message<Output, Tools>) => void; /** Resend messages and update state. Often used manually after an error.*/ resendMessages: () => void; /** Update the chat options after initialization */ updateOptions: (options: Partial<{ debugName?: string; apiUrl: string; model: KnownModelIds; system: string; tools: Tools[]; responseSchema: s.HashbrownType; middleware: Chat.Middleware[]; emulateStructuredOutput: boolean; debounce: number; retries: number; }>) => void; /** Stop the current LLM interaction. */ stop: (clearStreamingMessage?: boolean) => void; /** Start the Hashbrown effect loop. */ sizzle: () => () => void; } /** * Initialize a Hashbrown chat instance with the given configuration. * * @template Output - The type of messages expected from the LLM. * @template Tools - The set of tools to register with the chat instance. * @param {Object} init - Initialization options. * @param {string} [init.debugName] - Optional debug name for devtools tracing. * @param {string} init.apiUrl - Base URL of the Hashbrown API endpoint. * @param {string} init.model - The LLM model identifier to use. * @param {string} init.system - System prompt or initial context for the chat. * @param {Chat.Message<Output, Tools>[]} [init.messages] - Initial message history. * @param {Tools[]} [init.tools] - Array of tools to enable in the instance. * @param {s.HashbrownType} [init.responseSchema] - JSON schema for validating structured output. * @param {Chat.Middleware[]} [init.middleware] - Middleware functions to run on messages. * @param {boolean} [init.emulateStructuredOutput] - Whether to emulate structured output behavior. * @param {number} [init.debounce] - Debounce interval in milliseconds for sending messages. * @returns {Hashbrown<Output, Tools>} A configured Hashbrown instance. * @throws {Error} If a reserved tool name ("output") is used. */ export declare function fryHashbrown<Tools extends Chat.AnyTool>(init: { debugName?: string; apiUrl: string; model: KnownModelIds; system: string; messages?: Chat.Message<string, Tools>[]; tools?: Tools[]; middleware?: Chat.Middleware[]; emulateStructuredOutput?: boolean; debounce?: number; retries?: number; }): Hashbrown<string, Tools>; export declare function fryHashbrown<Schema extends s.HashbrownType, Tools extends Chat.AnyTool, Output extends s.Infer<Schema> = s.Infer<Schema>>(init: { debugName?: string; apiUrl: string; model: KnownModelIds; system: string; messages?: Chat.Message<Output, Tools>[]; tools?: Tools[]; responseSchema: Schema; middleware?: Chat.Middleware[]; emulateStructuredOutput?: boolean; debounce?: number; retries?: number; }): Hashbrown<Output, Tools>; //# sourceMappingURL=hashbrown.d.ts.map