UNPKG

@hashbrownai/react

Version:

React components for Hashbrown AI

82 lines (81 loc) 2.5 kB
import { Chat, type ModelInput, SystemPrompt, type TransportOrFactory } from '@hashbrownai/core'; import { Dispatch, ReactElement, SetStateAction } from 'react'; import { ExposedComponent } from '../expose-component.fn'; import { UiAssistantMessage, UiChatSchema } from './use-ui-chat'; import { type UseStructuredCompletionResult } from './use-structured-completion'; /** * Options for the `useUiCompletion` hook. * * @public */ export interface UiCompletionOptions<Input, Tools extends Chat.AnyTool = Chat.AnyTool> { /** * The input for the completion. */ input: Input | null | undefined; /** * The model to use for the completion. */ model: ModelInput; /** * The system prompt to use for the completion. */ system: string | SystemPrompt; /** * The components that can be rendered by the completion. */ components: ExposedComponent<any>[]; /** * The tools to make available to the completion. */ tools?: Tools[]; /** * The debounce time between requests. */ debounceTime?: number; /** * The name of the hook, useful for debugging. */ debugName?: string; /** * Number of retries if an error is received. */ retries?: number; /** * Optional transport override for this hook. */ transport?: TransportOrFactory; /** * Optional thread identifier used to load or continue an existing conversation. */ threadId?: string; } /** * The result of the `useUiCompletion` hook. * * @public */ export interface UseUiCompletionResult<Tools extends Chat.AnyTool> extends Omit<UseStructuredCompletionResult<UiChatSchema>, 'output'> { /** * The assistant message that contains the rendered UI elements. */ output: UiAssistantMessage<Tools> | null; /** * The rendered React elements produced by the completion. */ ui: ReactElement[] | null; /** * The raw structured output returned by the model before rendering components. */ rawOutput: UiChatSchema | null; /** * Updates the available components for future completions. */ setComponents: Dispatch<SetStateAction<ExposedComponent<any>[]>>; } /** * A React hook that generates UI completions using the provided component set. * * @public */ export declare const useUiCompletion: <Input, Tools extends Chat.AnyTool = Chat.AnyTool>(options: UiCompletionOptions<Input, Tools>) => UseUiCompletionResult<Tools>;