UNPKG

@hashbrownai/core

Version:

Runtime helpers for Hashbrown AI

116 lines 4.59 kB
import { Chat } from './models'; import { s } from './schema'; import { StateSignal } from './utils/micro-ngrx'; import { type ModelInput, TransportOrFactory } from './transport'; /** * Represents a Hashbrown chat instance, providing methods to send and observe messages, track state, and handle errors. * * @public * @typeParam Output - The type of messages received from the LLM, either a string or structured output defined by HashbrownType. * @typeParam 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>; isGenerating: StateSignal<boolean>; isRunningToolCalls: StateSignal<boolean>; isLoading: StateSignal<boolean>; exhaustedRetries: StateSignal<boolean>; sendingError: StateSignal<Error | undefined>; generatingError: StateSignal<Error | undefined>; lastAssistantMessage: StateSignal<Chat.AssistantMessage<Output, Tools> | undefined>; threadId: StateSignal<string | undefined>; isLoadingThread: StateSignal<boolean>; isSavingThread: StateSignal<boolean>; threadLoadError: StateSignal<{ error: string; stacktrace?: string; } | undefined>; threadSaveError: StateSignal<{ error: string; stacktrace?: string; } | 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: ModelInput; system: string; tools: Tools[]; responseSchema: s.HashbrownType; middleware: Chat.Middleware[]; emulateStructuredOutput: boolean; debounce: number; retries: number; transport: TransportOrFactory; ui?: boolean; threadId: string; }>) => 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. * * @public * @typeParam Output - The type of messages expected from the LLM. * @typeParam Tools - The set of tools to register with the chat instance. * @param init - Initialization options containing: * - `debugName`: Optional debug name for devtools tracing * - `apiUrl`: Base URL of the Hashbrown API endpoint * - `model`: The LLM model identifier to use * - `system`: System prompt or initial context for the chat * - `messages`: Initial message history * - `tools`: Array of tools to enable in the instance * - `responseSchema`: JSON schema for validating structured output * - `middleware`: Middleware functions to run on messages * - `emulateStructuredOutput`: Whether to emulate structured output behavior * - `debounce`: Debounce interval in milliseconds for sending messages * @returns A configured Hashbrown instance. * @throws If a reserved tool name ("output") is used. */ export declare function fryHashbrown<Tools extends Chat.AnyTool>(init: { debugName?: string; apiUrl?: string; model: ModelInput; system: string; messages?: Chat.Message<string, Tools>[]; tools?: Tools[]; middleware?: Chat.Middleware[]; emulateStructuredOutput?: boolean; debounce?: number; retries?: number; transport?: TransportOrFactory; ui?: boolean; threadId?: string; }): Hashbrown<string, Tools>; /** * @public */ 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: ModelInput; system: string; messages?: Chat.Message<Output, Tools>[]; tools?: Tools[]; responseSchema: Schema; middleware?: Chat.Middleware[]; emulateStructuredOutput?: boolean; debounce?: number; retries?: number; transport?: TransportOrFactory; ui?: boolean; threadId?: string; }): Hashbrown<Output, Tools>; //# sourceMappingURL=hashbrown.d.ts.map