Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions backend/chainlit/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ class CommandDict(TypedDict):
button: Optional[bool]
# Whether the command will be persistent unless the user toggles it
persistent: Optional[bool]
# Whether the command should be pre-selected when loaded
selected: Optional[bool]


class FeedbackDict(TypedDict):
Expand Down
12 changes: 11 additions & 1 deletion frontend/src/components/chat/MessageComposer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import {
useRef,
useState
} from 'react';
import { useRecoilState, useSetRecoilState } from 'recoil';
import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';
import { v4 as uuidv4 } from 'uuid';

import {
FileSpec,
IStep,
commandsState,
useAuth,
useChatData,
useChatInteract,
Expand Down Expand Up @@ -62,7 +63,16 @@ export default function MessageComposer({
const [selectedCommand, setSelectedCommand] = useRecoilState(
persistentCommandState
);
const commands = useRecoilValue(commandsState);
const setChatSettingsOpen = useSetRecoilState(chatSettingsOpenState);

// Pre-select the command marked as selected by the backend
useEffect(() => {
const defaultSelected = commands.find((c) => c.selected);
if (defaultSelected && !selectedCommand) {
setSelectedCommand(defaultSelected);
}
}, [commands]);
const [attachments, setAttachments] = useRecoilState(attachmentsState);
const { t } = useTranslation();

Expand Down
1 change: 1 addition & 0 deletions libs/react-client/src/types/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export interface ICommand {
description: string;
button?: boolean;
persistent?: boolean;
selected?: boolean;
}
Loading