mongodb-chatbot-ui
Version:
UI React components for the MongoDB Assistant
69 lines (68 loc) • 2.79 kB
TypeScript
import { ChatbotTriggerProps } from "./ChatbotTrigger";
export type UseTextInputTriggerArgs = {
placeholder?: string;
fatalErrorMessage?: string;
};
/**
The base props for a Chatbot trigger component that allows the user to input text.
*/
export type ChatbotTextInputTriggerProps = ChatbotTriggerProps & UseTextInputTriggerArgs;
/**
* A hook that provides the necessary props to create a Chatbot trigger component that allows the user to input text.
* @param args - The arguments to configure the trigger.
* @returns The props to create a Chatbot trigger component that allows the user to input text.
* @example
* ```tsx
* const textInputTrigger = useTextInputTrigger({
* placeholder: "Type something...",
* fatalErrorMessage: "An error occurred. Please try again.",
* });
* return <MyInputBar
* value={textInputTrigger.inputText}
* placeholder={textInputTrigger.inputPlaceholder}
* error={textInputTrigger.inputTextError || undefined}
* onTextChange={newText => textInputTrigger.setInputText(newText)}
* onSubmit={() => {
* textInputTrigger.handleSubmit(textInputTrigger.inputText);
* }}
* />;
* ```
*/
export declare function useTextInputTrigger({ placeholder, fatalErrorMessage, }: UseTextInputTriggerArgs): {
conversation: {
conversationId: string | undefined;
conversationName: string | undefined;
messages: import(".").MessageData[];
error: string | undefined;
streamingMessageId: string | undefined;
createConversation: (args?: {
name?: string;
}) => Promise<void>;
submit: (content: string) => Promise<void>;
getMessage: (messageId: string) => import(".").MessageData | undefined;
rateMessage: (messageId: string, rating: boolean) => Promise<void>;
commentMessage: (messageId: string, comment: string) => Promise<void>;
switchConversation: (conversationId: string, options?: {
from?: "cache" | "server";
}) => Promise<void>;
getCachedConversationInfo: () => Promise<{
_id: string;
name: string;
}[]>;
getCacheVersion: () => number;
};
inputText: string;
setInputText: import("react").Dispatch<import("react").SetStateAction<string>>;
inputTextError: string;
inputPlaceholder: string;
setInputTextError: import("react").Dispatch<import("react").SetStateAction<string>>;
canSubmit: boolean;
awaitingReply: boolean;
openChat: () => void;
focused: boolean;
setFocused: import("react").Dispatch<import("react").SetStateAction<boolean>>;
handleSubmit: (text: string) => void | Promise<void>;
hasError: boolean;
showError: false;
onSuggestedPromptClick: ((prompt: string) => void) | undefined;
};