mongodb-chatbot-ui
Version:
UI React components for the MongoDB Assistant
58 lines (57 loc) • 2.44 kB
TypeScript
import { ConversationFetchOptions, MessageData } from "./services/conversations";
import { SortReferences } from "./references";
import { ChoosePromotion } from "./promotions";
import { type ConversationState } from "./conversationStore";
import { type ConversationCache } from "./conversation-cache";
export type ConversationMethods = {
createConversation: () => Promise<void>;
switchConversation: (conversationId: string, options?: {
from?: "cache" | "server";
}) => Promise<void>;
submit: (content: string) => Promise<void>;
getMessage: (messageId: string) => MessageData | undefined;
rateMessage: (messageId: string, rating: boolean) => Promise<void>;
commentMessage: (messageId: string, comment: string) => Promise<void>;
getCachedConversationInfo: () => Promise<{
_id: string;
name: string;
}[]>;
getCacheVersion: () => number;
};
export type Conversation = ConversationState & ConversationMethods;
export type UseConversationParams = {
serverBaseUrl: string;
shouldStream?: boolean;
sortMessageReferences?: SortReferences;
choosePriorityPromotion?: ChoosePromotion;
cache?: ConversationCache;
/**
* Optional fetch options for the ConversationService. Can be either a static
* `ConversationFetchOptions` object for all request or a function that
* dynamically returns a new `ConversationFetchOptions` object for each request.
*/
fetchOptions?: ConversationFetchOptions | (() => ConversationFetchOptions);
getClientContext?: () => Record<string, unknown>;
};
export declare function useConversation(params: UseConversationParams): {
conversationId: string | undefined;
conversationName: string | undefined;
messages: MessageData[];
error: string | undefined;
streamingMessageId: string | undefined;
createConversation: (args?: {
name?: string;
}) => Promise<void>;
submit: (content: string) => Promise<void>;
getMessage: (messageId: string) => 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;
};