UNPKG

@promptbook/vercel

Version:

Promptbook: Turn your company's scattered knowledge into AI ready books

45 lines (44 loc) 1.46 kB
/** * Function type for sending a message to LlmChat. * * Implementation detail: The returned function is "attachable". * LlmChat will call the internal `_attach` method (if present) to bind * its real message handler. Messages sent before attachment are queued * and flushed after attachment. * * @public exported from `@promptbook/components` */ export type SendMessageToLlmChatFunction = { /** * Send a message to the bound LlmChat instance (or queue it until attached). */ (message: string): void; /** * Internal method used by the <LlmChat/> component to attach its handler. * Not intended for consumer usage. * * @internal */ _attach?: (handler: (message: string) => Promise<void> | void) => void; }; /** * Hook to create a sendMessage function for an <LlmChat/> component WITHOUT needing any React Context. * * Usage pattern: * ```tsx * const sendMessage = useSendMessageToLlmChat(); * return ( * <> * <button onClick={() => sendMessage('Hello!')}>Hello</button> * <LlmChat llmTools={llmTools} sendMessage={sendMessage} /> * </> * ); * ``` * * - No provider wrapping needed. * - Safe to call before the <LlmChat/> mounts (messages will be queued). * - Keeps DRY by letting <LlmChat/> reuse its internal `handleMessage` logic. * * @public exported from `@promptbook/components` */ export declare function useSendMessageToLlmChat(): SendMessageToLlmChatFunction;