-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Feat/add thinking message #349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| type Props = { | ||
| thinking?: string; | ||
| thinkingDuration?: number; | ||
| isThinking?: boolean; | ||
| backgroundColor?: string; | ||
| textColor?: string; | ||
| }; | ||
| export declare const ThinkingCard: (props: Props) => import("solid-js").JSX.Element; | ||
| export {}; | ||
| //# sourceMappingURL=ThinkingBubble.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { JSXElement } from 'solid-js'; | ||
| type IconProps = { | ||
| size?: number; | ||
| color?: string; | ||
| }; | ||
| export declare const MaximizeIcon: (props: IconProps) => import("solid-js").JSX.Element; | ||
| type AgentflowIconEntry = { | ||
| name: string; | ||
| icon: (props: IconProps) => JSXElement; | ||
| color: string; | ||
| }; | ||
| export declare const AGENTFLOW_ICONS: AgentflowIconEntry[]; | ||
| export declare function getAgentflowIcon(name: string): AgentflowIconEntry | null; | ||
| export {}; | ||
| //# sourceMappingURL=AgentflowIcons.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| type NodeDetailsDialogProps = { | ||
| isOpen: boolean; | ||
| onClose: () => void; | ||
| node: { | ||
| label: string; | ||
| name: string; | ||
| status: string; | ||
| data: any; | ||
| } | null; | ||
| backgroundColor?: string; | ||
| textColor?: string; | ||
| apiHost?: string; | ||
| chatflowid?: string; | ||
| chatId?: string; | ||
| }; | ||
| export declare const NodeDetailsDialog: (props: NodeDetailsDialogProps) => import("solid-js").JSX.Element; | ||
| export {}; | ||
| //# sourceMappingURL=NodeDetailsDialog.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -133,6 +133,9 @@ export type MessageType = { | |
| id?: string; | ||
| followUpPrompts?: string; | ||
| dateTime?: string; | ||
| thinking?: string; | ||
| thinkingDuration?: number; | ||
| isThinking?: boolean; | ||
| }; | ||
|
|
||
| type IUploads = { | ||
|
|
@@ -495,6 +498,7 @@ export const Bot = (botProps: BotProps & { class?: string }) => { | |
| const [isLeadSaved, setIsLeadSaved] = createSignal(false); | ||
| const [leadEmail, setLeadEmail] = createSignal(''); | ||
| const [disclaimerPopupOpen, setDisclaimerPopupOpen] = createSignal(false); | ||
| const [isThinking, setIsThinking] = createSignal(false); | ||
|
|
||
| const [openFeedbackDialog, setOpenFeedbackDialog] = createSignal(false); | ||
| const [feedback, setFeedback] = createSignal(''); | ||
|
|
@@ -788,6 +792,41 @@ export const Bot = (botProps: BotProps & { class?: string }) => { | |
| }); | ||
| }; | ||
|
|
||
| const handleThinkingEvent = (data: string, duration?: number) => { | ||
| if (data && duration === undefined) { | ||
| setIsThinking(true); | ||
| setMessages((prevMessages) => { | ||
| const lastMsg = prevMessages[prevMessages.length - 1]; | ||
| if (lastMsg.type === 'userMessage') return prevMessages; | ||
| const allMessages = [...prevMessages.slice(0, -1), { ...lastMsg, thinking: (lastMsg.thinking || '') + data, isThinking: true }]; | ||
| addChatMessage(allMessages); | ||
| return allMessages; | ||
| }); | ||
| } else if (data === '' && duration !== undefined) { | ||
| setIsThinking(false); | ||
| setMessages((prevMessages) => { | ||
| const lastMsg = prevMessages[prevMessages.length - 1]; | ||
| if (lastMsg.type === 'userMessage') return prevMessages; | ||
| const allMessages = [...prevMessages.slice(0, -1), { ...lastMsg, thinkingDuration: duration, isThinking: false }]; | ||
| addChatMessage(allMessages); | ||
| return allMessages; | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| const finalizeThinking = () => { | ||
| if (isThinking()) { | ||
| setIsThinking(false); | ||
| setMessages((prevMessages) => { | ||
| const lastMsg = prevMessages[prevMessages.length - 1]; | ||
| if (lastMsg.type === 'userMessage') return prevMessages; | ||
| const allMessages = [...prevMessages.slice(0, -1), { ...lastMsg, isThinking: false }]; | ||
| addChatMessage(allMessages); | ||
| return allMessages; | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| const clearPreviews = () => { | ||
| // Revoke the data uris to avoid memory leaks | ||
| previews().forEach((file) => URL.revokeObjectURL(file.preview)); | ||
|
|
@@ -918,6 +957,9 @@ export const Bot = (botProps: BotProps & { class?: string }) => { | |
| case 'agentReasoning': | ||
| updateLastMessageAgentReasoning(payload.data); | ||
| break; | ||
| case 'thinking': | ||
| handleThinkingEvent(payload.data, payload.duration); | ||
| break; | ||
| case 'agentFlowEvent': | ||
| updateAgentFlowEvent(payload.data); | ||
| break; | ||
|
|
@@ -941,6 +983,7 @@ export const Bot = (botProps: BotProps & { class?: string }) => { | |
| closeResponse(); | ||
| break; | ||
| case 'end': | ||
| finalizeThinking(); | ||
| setLocalStorageChatflow(chatflowid, chatId); | ||
| closeResponse(); | ||
| break; | ||
|
|
@@ -1193,6 +1236,8 @@ export const Bot = (botProps: BotProps & { class?: string }) => { | |
| agentFlowExecutedData: data?.agentFlowExecutedData, | ||
| action: data?.action, | ||
| artifacts: data?.artifacts, | ||
| thinking: data?.reasonContent?.thinking, | ||
| thinkingDuration: data?.reasonContent?.thinkingDuration, | ||
| type: 'apiMessage' as messageType, | ||
| feedback: null, | ||
| dateTime: new Date().toISOString(), | ||
|
|
@@ -1314,6 +1359,7 @@ export const Bot = (botProps: BotProps & { class?: string }) => { | |
| messages.push({ message: '', type: 'leadCaptureMessage' }); | ||
| } | ||
| setMessages(messages); | ||
| setShowScrollButton(false); | ||
| } catch (error: any) { | ||
| const errorData = error.response.data || `${error.response.status}: ${error.response.statusText}`; | ||
| console.error(`error: ${errorData}`); | ||
|
|
@@ -1397,6 +1443,12 @@ export const Bot = (botProps: BotProps & { class?: string }) => { | |
| if (message.fileAnnotations) chatHistory.fileAnnotations = message.fileAnnotations; | ||
| if (message.fileUploads) chatHistory.fileUploads = message.fileUploads; | ||
| if (message.agentReasoning) chatHistory.agentReasoning = message.agentReasoning; | ||
| if ((message as any).reasonContent && typeof (message as any).reasonContent === 'object') { | ||
| chatHistory.thinking = (message as any).reasonContent.thinking; | ||
| chatHistory.thinkingDuration = (message as any).reasonContent.thinkingDuration; | ||
| } | ||
| if (message.thinking) chatHistory.thinking = message.thinking; | ||
| if (message.thinkingDuration !== undefined) chatHistory.thinkingDuration = message.thinkingDuration; | ||
|
Comment on lines
+1446
to
+1451
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic for populating |
||
| if (message.action) chatHistory.action = message.action; | ||
| if (message.artifacts) chatHistory.artifacts = message.artifacts; | ||
| if (message.followUpPrompts) chatHistory.followUpPrompts = message.followUpPrompts; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic in
handleThinkingEventseems a bit brittle. It relies on a strict contract where eitherdatais provided for streaming, or an emptydatastring and adurationare provided for completion. If the backend sends a payload that doesn't match these exact conditions (e.g.,dataisundefinedbutdurationis present), the event might be ignored. Consider making the logic more robust by prioritizing thedurationcheck to signify the final event, which makes the handler more resilient to variations in the event payload.