@promptbook/remote-server
Version:
Promptbook: Create persistent AI agents that turn your company's scattered knowledge into action
98 lines (97 loc) • 2.86 kB
TypeScript
import type { Promisable } from 'type-fest';
import type { id } from '../../../types/string_token';
import type { ChatFeedbackMode, ChatFeedbackResponse, ChatProps } from '../Chat/ChatProps';
import type { ChatMessage } from '../types/ChatMessage';
/**
* Input parameters for the chat rating hook.
*
* @private component of `<Chat/>`
*/
export type UseChatRatingsOptions = {
/**
* Messages in the chat thread.
*/
messages: ReadonlyArray<ChatMessage>;
/**
* Optional feedback handler passed to Chat.
*/
onFeedback?: (feedback: {
message: ChatMessage;
rating: number;
textRating: string;
chatThread: string;
expectedAnswer: string | null;
url: string;
}) => Promisable<ChatFeedbackResponse | void>;
/**
* Feedback mode currently used by the chat UI.
*/
feedbackMode: ChatFeedbackMode;
/**
* Optional localized labels and status messages used by the feedback UI.
*/
feedbackTranslations?: ChatProps['feedbackTranslations'];
/**
* Whether the UI should apply mobile-specific behavior.
*/
isMobile: boolean;
};
/**
* Indicates how the feedback status message should be rendered.
*
* @private component of `<Chat/>`
*/
export type FeedbackStatusVariant = 'success' | 'error';
/**
* Data used to show the transient feedback status toast.
*
* @private component of `<Chat/>`
*/
export type FeedbackStatus = {
/**
* Message displayed to the user.
*/
readonly message: string;
/**
* Whether the message indicates success or failure.
*/
readonly variant: FeedbackStatusVariant;
};
/**
* Rating state tracked for the chat UI.
*
* @private component of `<Chat/>`
*/
export type ChatRatingsState = {
ratingModalOpen: boolean;
selectedMessage: ChatMessage | null;
messageRatings: Map<id, number>;
textRating: string;
hoveredRating: number;
expandedMessageId: id | null;
feedbackStatus: FeedbackStatus | null;
};
/**
* Rating actions for the chat UI.
*
* @private component of `<Chat/>`
*/
export type ChatRatingsActions = {
setRatingModalOpen: (value: boolean) => void;
setSelectedMessage: (value: ChatMessage | null) => void;
setMessageRatings: (value: Map<id, number> | ((previous: Map<id, number>) => Map<id, number>)) => void;
setTextRating: (value: string) => void;
setHoveredRating: (value: number) => void;
setExpandedMessageId: (value: id | null) => void;
handleRating: (message: ChatMessage, newRating: number) => void;
submitRating: () => Promise<void>;
};
/**
* Hook that centralizes rating state and handlers for Chat.
*
* @private component of `<Chat/>`
*/
export declare function useChatRatings(options: UseChatRatingsOptions): {
state: ChatRatingsState;
actions: ChatRatingsActions;
};