Skip to content

Commit

Permalink
Enhance AIChat with dynamic assistant update and reset functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
trheyi committed Feb 9, 2025
1 parent cf29dc1 commit 65f1548
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/xgen/layouts/components/Neo/components/AIChat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const AIChat = (props: AIChatProps) => {
cancel,
uploadFile,
attachments,
updateAssistant,
resetAssistant,
removeAttachment,
addAttachment,
Expand Down Expand Up @@ -231,6 +232,13 @@ const AIChat = (props: AIChatProps) => {
})
}

// Reset the assistant
if (options?.assistant) {
updateAssistant(options?.assistant)
} else {
resetAssistant()
}

// Focus using the new method
setTimeout(() => {
focusRef.current?.()
Expand Down Expand Up @@ -567,7 +575,10 @@ const AIChat = (props: AIChatProps) => {
<Assistant
assistant={assistant || {}}
loading={loadingChat}
onDelete={resetAssistant}
onDelete={() => {
resetAssistant()
focusRef.current?.() // focus on the input
}}
/>
{/* Current Page Info */}
{showCurrentPage && currentPage && (
Expand Down
1 change: 1 addition & 0 deletions packages/xgen/layouts/components/Neo/hooks/useAIChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1400,6 +1400,7 @@ export default ({ chat_id, upload_options = {} }: Args) => {
generatePrompts,
titleGenerating,
resetAssistant,
updateAssistant,
setTitleGenerating,
getAssistants,
findAssistant,
Expand Down
1 change: 1 addition & 0 deletions packages/xgen/types/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ export declare namespace App {
interface NewChatOptions {
content?: string
chat_id?: string
assistant?: AssistantSummary
attachments?: ChatAttachment[]
placeholder?: ChatPlaceholder
}
Expand Down

0 comments on commit 65f1548

Please sign in to comment.