RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
Fix: Variables within the "Wait for Input" and "Start" components of an agent are not accessible in the floating window. (#21900)
balibabu62a4eae87be3
diff --git a/web/src/components/floating-chat-widget.tsx b/web/src/components/floating-chat-widget.tsxindex 5f94f243f8..3f93648124 100644--- a/web/src/components/floating-chat-widget.tsx+++ b/web/src/components/floating-chat-widget.tsx@@ -17,12 +17,19 @@import CopyToClipboard from '@/components/copy-to-clipboard';import PdfSheet from '@/components/pdf-drawer';import { useClickDrawer } from '@/components/pdf-drawer/hooks';+import { Modal } from '@/components/ui/modal/modal';+import { Spin } from '@/components/ui/spin';import { MessageType, SharedFrom } from '@/constants/chat';import { useFetchExternalAgentInputs } from '@/hooks/use-agent-request';import { useFetchExternalChatInfo } from '@/hooks/use-chat-request';+import { IMessage } from '@/interfaces/database/chat';import i18n, { changeLanguageAsync } from '@/locales/config';+import DebugContent from '@/pages/agent/debug-content';+import { buildBeginInputListFromObject } from '@/pages/agent/form/begin-form/utils';+import { useAwaitComponentData } from '@/pages/agent/hooks/use-chat-logic';import { useSendNextSharedMessage } from '@/pages/agent/hooks/use-send-shared-message';import { removeThinkSection } from '@/utils/chat';+import isEmpty from 'lodash/isEmpty';import { MessageCircle, Minimize2, Send, X } from 'lucide-react';import React, { useCallback, useEffect, useRef, useState } from 'react';import { useTranslation } from 'react-i18next';@@ -105,6 +112,65 @@ const normalizeWidgetFooterLink = (value: string | null) => {*/const PROLOGUE_MESSAGE_ID = 'prologue';+/**+ * How long a streaming answer may go without a content update before the+ * typing indicator reappears (the canvas is working between components,+ * e.g. the LLM thinking after a Message component emitted its template).+ */+const StreamStallTimeoutMs = 1000;++/**+ * The chatbot flow has no form-submit path (only agent canvases pause on+ * "Await response" nodes), so the await hook gets a noop there.+ */+const noopSendFormMessage = () => {};++interface AwaitInteractionProps {+ message: IMessage;+ isActive: boolean;+ sendLoading: boolean;+ buildInputList: ReturnType<typeof useAwaitComponentData>['buildInputList'];+ handleOk: ReturnType<typeof useAwaitComponentData>['handleOk'];+}++/**+ * Renders the agent's "Await response" (UserFillUp) interaction, mirroring+ * web/src/pages/agent/share: the active (latest) await message shows the+ * input form; resolved ones keep the tips as conversation history.+ */+const AwaitInteraction = ({+ message,+ isActive,+ sendLoading,+ buildInputList,+ handleOk,+}: AwaitInteractionProps) => {+ const { t } = useTranslation();++ if (isActive) {+ return (+ <DebugContent+ parameters={buildInputList(message)}+ message={message}+ ok={handleOk(message)}+ isNext={false}+ loading={sendLoading}+ btnText={t('common.submit')}+ />+ );+ }++ if (message?.data?.tips) {+ return (+ <p className="text-sm leading-relaxed whitespace-pre-wrap">+ {message.data.tips}+ </p>+ );+ }++ return null;+};+/*** Renders the embeddable floating chat widget and applies URL-driven widget settings.*/@@ -173,13 +239,54 @@ const FloatingChatWidget = () => {const findReferenceByMessageId = (hookResult as any).findReferenceByMessageId;// Only the agent flow exposes these. The chat flow receives its prologue// through the completions handshake instead, so both stay optional here.- const { addNewestOneAnswer, isTaskMode } = hookResult as Partial<+ const {+ addNewestOneAnswer,+ isTaskMode,+ sendFormMessage,+ inputsData,+ ok: submitBeginParams,+ } = hookResult as Partial<Pick<ReturnType<typeof useSendNextSharedMessage>,- 'addNewestOneAnswer' | 'isTaskMode'+ | 'addNewestOneAnswer'+ | 'isTaskMode'+ | 'sendFormMessage'+ | 'inputsData'+ | 'ok'>>;+ // An agent canvas pausing on an "Await response" node surfaces its form+ // spec on the latest assistant message's `data.inputs`; isWaiting stays+ // true until the user submits it (sendFormMessage resumes the run).+ const { buildInputList, handleOk, isWaiting } = useAwaitComponentData({+ derivedMessages: derivedMessages ?? [],+ sendFormMessage: sendFormMessage ?? noopSendFormMessage,+ });+ const hasAwaitInputs = useCallback(+ (message: IMessage) => buildInputList(message).length > 0,+ [buildInputList],+ );++ // An agent's Begin component inputs reach the completions endpoint only+ // after `ok` stores them in the send hook, so collect them up front the+ // same way pages/agent/share does: a forced parameter dialog shown while+ // the inputs are known but not yet submitted. Only the modes rendering+ // the chat UI show it — in button/master mode the sibling window-mode+ // iframe runs its own copy.+ const beginInputs = inputsData?.inputs;+ const hasBeginInputs = isFromAgent && !isEmpty(beginInputs);+ const canShowBeginDialog = mode === 'window' || (mode === 'full' && isOpen);+ const [beginParamsSubmitted, setBeginParamsSubmitted] = useState(false);++ const handleSubmitBeginParams = useCallback(+ (params: any[]) => {+ submitBeginParams?.(params);+ setBeginParamsSubmitted(true);+ },+ [submitBeginParams],+ );+// Sync our local input with the hook's value when neededuseEffect(() => {if (hookValue && hookValue !== inputValue) {@@ -187,7 +294,7 @@ const FloatingChatWidget = () => {}}, [hookValue, inputValue]);- const { data } = (+ const { data, loading: infoLoading } = (isFromAgent ? useFetchExternalAgentInputs : useFetchExternalChatInfo)();@@ -473,8 +580,60 @@ const FloatingChatWidget = () => {setIsMinimized(true);}, []);+ // Initial loading covers the first external-info fetch and the chatbot+ // session handshake: no messages exist yet, so a centered spinner (same+ // pattern as the chat list page) replaces the empty message area and the+ // input stays disabled — this also closes the race where a fast message+ // goes out before the Begin-parameter dialog appears.+ const isInitialLoading =+ (infoLoading || sendLoading) && (displayMessages?.length ?? 0) === 0;++ // Waiting-for-reply indicator, mirroring the "..." bubble of the agent+ // debug chat: up from the moment the question goes out until the first+ // assistant content arrives. In non-streaming mode the in-progress bubble+ // is filtered out of displayMessages, so it stays up for the whole round+ // trip; in streaming mode it covers the pre-first-frame gap and, via the+ // stall detection below, mid-stream pauses between canvas components.+ const lastDisplayMessage = displayMessages?.at(-1);+ const latestStreamContent = lastDisplayMessage?.content;++ // A streaming answer whose content stops growing past the timeout means+ // the canvas is working without emitting (e.g. the LLM thinking after a+ // Message component echoed the begin variables). The timer resets on+ // every token, so steady streaming never triggers it; comparing the+ // captured content instead of resetting state keeps the effect free of+ // synchronous setState.+ const [stalledStreamContent, setStalledStreamContent] = useState<+ string | undefined+ >();++ useEffect(() => {+ if (!sendLoading) {+ return;+ }+ const stalledContent = latestStreamContent;+ const timer = setTimeout(+ () => setStalledStreamContent(stalledContent),+ StreamStallTimeoutMs,+ );+ return () => clearTimeout(timer);+ }, [sendLoading, latestStreamContent]);++ const isStreamStalled =+ sendLoading &&+ stalledStreamContent !== undefined &&+ stalledStreamContent === latestStreamContent;++ const isAwaitingReply =+ sendLoading &&+ !isInitialLoading &&+ (!enableStreaming ||+ lastDisplayMessage?.role === MessageType.User ||+ isStreamStalled);+const handleSendMessage = useCallback(() => {- if (!inputValue.trim() || sendLoading) return;+ if (!inputValue.trim() || sendLoading || isWaiting || isInitialLoading)+ return;// Update the hook's internal state firstconst syntheticEvent = {@@ -491,7 +650,14 @@ const FloatingChatWidget = () => {// Clear our local input after sendingsetInputValue('');}, 50);- }, [inputValue, sendLoading, handleInputChange, handlePressEnter]);+ }, [+ inputValue,+ sendLoading,+ isWaiting,+ isInitialLoading,+ handleInputChange,+ handlePressEnter,+ ]);const handleKeyPress = useCallback((e: React.KeyboardEvent) => {@@ -503,6 +669,94 @@ const FloatingChatWidget = () => {[handleSendMessage],);+ // Assistant bubble body shared by the window and full modes. Messages+ // carrying an await-form spec render the AwaitInteraction instead of the+ // markdown body — their content is empty by design (the canvas paused+ // before producing an answer), which the markdown view would otherwise+ // misrender as a permanent "Searching..." placeholder.+ const renderAssistantMessageContent = useCallback(+ (message: IMessage, index: number) => {+ if (hasAwaitInputs(message)) {+ return (+ <AwaitInteraction+ message={message}+ isActive={index === displayMessages.length - 1}+ sendLoading={sendLoading}+ buildInputList={buildInputList}+ handleOk={handleOk}+ />+ );+ }++ return (+ <>+ <FloatingChatWidgetMarkdown+ loading={+ enableStreaming &&+ sendLoading &&+ index === displayMessages.length - 1+ }+ content={message.content}+ reference={+ findReferenceByMessageId?.(message.id) ||+ message.reference || {+ doc_aggs: [],+ chunks: [],+ total: 0,+ }+ }+ clickDocumentButton={clickDocumentButton}+ />+ <div className="flex justify-end" role="toolbar">+ <CopyToClipboard+ text={removeThinkSection(message.content)}+ className="border-0"+ size="icon-xs"+ />+ </div>+ </>+ );+ },+ [+ buildInputList,+ clickDocumentButton,+ displayMessages.length,+ enableStreaming,+ findReferenceByMessageId,+ handleOk,+ hasAwaitInputs,+ sendLoading,+ ],+ );++ // Begin-parameter dialog shared by the window and full modes. Non-closable+ // like the share page: chatting without these inputs would send empty+ // Begin variables for the whole conversation. The width follows the small+ // widget iframe instead of the modal's 700px default.+ const beginParamsDialog = hasBeginInputs &&+ canShowBeginDialog &&+ !beginParamsSubmitted &&+ submitBeginParams && (+ <Modal+ open+ title={t('flow.beginInput')}+ closable={false}+ showfooter={false}+ maskClosable={false}+ size="small"+ className="w-[calc(100vw-2rem)]"+ >+ <div className="mb-4">+ <DebugContent+ parameters={buildBeginInputListFromObject(beginInputs ?? {})}+ ok={handleSubmitBeginParams}+ isNext={false}+ btnText={t('common.submit')}+ />+ </div>+ </Modal>+ );+if (!conversationId) {return (<div className="fixed bottom-5 right-5 z-50">@@ -651,13 +905,23 @@ const FloatingChatWidget = () => {}}}>+ {isInitialLoading && (+ <div className="flex h-full items-center justify-center">+ <Spin size="large" />+ </div>+ )}{displayMessages?.map((message, index) => (<divkey={index}className={`flex ${message.role === MessageType.User ? 'justify-end' : 'justify-start'}`}><div- className={`max-w-[280px] px-4 py-2 rounded-2xl ${+ className={`${+ message.role === MessageType.Assistant &&+ hasAwaitInputs(message)+ ? 'w-full'+ : 'max-w-[280px]'+ } px-4 py-2 rounded-2xl ${message.role === MessageType.User? 'text-white rounded-br-md': 'rounded-bl-md'@@ -677,30 +941,7 @@ const FloatingChatWidget = () => {</p>) : (<div className="space-y-2">- <FloatingChatWidgetMarkdown- loading={- enableStreaming &&- sendLoading &&- index === displayMessages.length - 1- }- content={message.content}- reference={- findReferenceByMessageId?.(message.id) ||- message.reference || {- doc_aggs: [],- chunks: [],- total: 0,- }- }- clickDocumentButton={clickDocumentButton}- />- <div className="flex justify-end" role="toolbar">- <CopyToClipboard- text={removeThinkSection(message.content)}- className="border-0"- size="icon-xs"- />- </div>+ {renderAssistantMessageContent(message, index)}</div>)}</div>@@ -708,7 +949,7 @@ const FloatingChatWidget = () => {))}{/* Clean Typing Indicator */}- {sendLoading && !enableStreaming && (+ {isAwaitingReply && (<div className="flex justify-start pl-4"><div className="flex space-x-1"><div@@ -755,13 +996,20 @@ const FloatingChatWidget = () => {rows={1}className="w-full resize-none border border-gray-300 rounded-2xl px-4 py-3 text-sm focus:outline-none focus:ring-2 focus:border-transparent"style={inputStyle}- disabled={hasError || sendLoading}+ disabled={+ hasError || sendLoading || isWaiting || isInitialLoading+ }/></div><buttontype="button"onClick={handleSendMessage}- disabled={!inputValue.trim() || sendLoading}+ disabled={+ !inputValue.trim() ||+ sendLoading ||+ isWaiting ||+ isInitialLoading+ }className="p-3 text-white rounded-full disabled:opacity-50 disabled:cursor-not-allowed transition-colors"style={{ backgroundColor: widgetAccentColor }}>@@ -772,6 +1020,7 @@ const FloatingChatWidget = () => {</div></div></div>+ {beginParamsDialog}{visible && (<PdfSheetvisible={visible}@@ -867,13 +1116,23 @@ const FloatingChatWidget = () => {}}}>+ {isInitialLoading && (+ <div className="flex h-full items-center justify-center">+ <Spin size="large" />+ </div>+ )}{displayMessages?.map((message, index) => (<divkey={index}className={`flex ${message.role === MessageType.User ? 'justify-end' : 'justify-start'}`}><div- className={`max-w-[280px] px-4 py-2 rounded-2xl ${+ className={`${+ message.role === MessageType.Assistant &&+ hasAwaitInputs(message)+ ? 'w-full'+ : 'max-w-[280px]'+ } px-4 py-2 rounded-2xl ${message.role === MessageType.User? 'text-white rounded-br-md': 'rounded-bl-md'@@ -893,30 +1152,7 @@ const FloatingChatWidget = () => {</p>) : (<div className="space-y-2">- <FloatingChatWidgetMarkdown- loading={- enableStreaming &&- sendLoading &&- index === displayMessages.length - 1- }- content={message.content}- reference={- findReferenceByMessageId?.(message.id) ||- message.reference || {- doc_aggs: [],- chunks: [],- total: 0,- }- }- clickDocumentButton={clickDocumentButton}- />- <div className="flex justify-end" role="toolbar">- <CopyToClipboard- text={removeThinkSection(message.content)}- className="border-0"- size="icon-xs"- />- </div>+ {renderAssistantMessageContent(message, index)}</div>)}</div>@@ -924,7 +1160,7 @@ const FloatingChatWidget = () => {))}{/* Typing Indicator */}- {sendLoading && (+ {isAwaitingReply && (<div className="flex justify-start"><div className="bg-gray-100 rounded-2xl rounded-bl-md px-4 py-3"><div className="flex space-x-1">@@ -962,13 +1198,20 @@ const FloatingChatWidget = () => {rows={1}className="w-full resize-none border border-gray-300 rounded-2xl px-4 py-3 text-sm focus:outline-none focus:ring-2 focus:border-transparent"style={inputStyle}- disabled={hasError || sendLoading}+ disabled={+ hasError || sendLoading || isWaiting || isInitialLoading+ }/></div><buttontype="button"onClick={handleSendMessage}- disabled={!inputValue.trim() || sendLoading}+ disabled={+ !inputValue.trim() ||+ sendLoading ||+ isWaiting ||+ isInitialLoading+ }className="p-3 text-white rounded-full disabled:opacity-50 disabled:cursor-not-allowed transition-colors"style={{ backgroundColor: widgetAccentColor }}>@@ -1006,6 +1249,7 @@ const FloatingChatWidget = () => {</div>)}</div>+ {beginParamsDialog}<PdfSheetvisible={visible}hideModal={hideModal}diff --git a/web/src/pages/agent/debug-content/index.tsx b/web/src/pages/agent/debug-content/index.tsxindex d241e75b9a..b2b603dd95 100644--- a/web/src/pages/agent/debug-content/index.tsx+++ b/web/src/pages/agent/debug-content/index.tsx@@ -1,22 +1,16 @@import MarkdownContent from '@/components/next-markdown-content';import JsonEditor from '@/components/json-edit';import { SelectWithSearch } from '@/components/originui/select-with-search';+import { RAGFlowFormItem } from '@/components/ragflow-form';+import { SwitchFormField } from '@/components/switch-form-field';import { ButtonLoading } from '@/components/ui/button';-import {- Form,- FormControl,- FormField,- FormItem,- FormLabel,- FormMessage,-} from '@/components/ui/form';+import { Form } from '@/components/ui/form';import { Input } from '@/components/ui/input';-import { Switch } from '@/components/ui/switch';import { Textarea } from '@/components/ui/textarea';import { IMessage } from '@/interfaces/database/chat';import { cn } from '@/lib/utils';import { zodResolver } from '@hookform/resolvers/zod';-import React, { ReactNode, useCallback, useMemo } from 'react';+import { ReactNode, useCallback, useMemo } from 'react';import { useForm } from 'react-hook-form';import { useTranslation } from 'react-i18next';import { z } from 'zod';@@ -118,152 +112,67 @@ const DebugContent = ({const submittable = true;- const renderWidget = useCallback(- (q: BeginQuery, idx: string) => {- const props = {- key: idx,- label: q.name ?? q.key,- name: idx,- };-- const BeginQueryTypeMap = {- [BeginQueryType.Line]: (- <FormField- control={form.control}- name={props.name}- render={({ field }) => (- <FormItem className="flex-1">- <FormLabel>{props.label}</FormLabel>- <FormControl>- <Input {...field}></Input>- </FormControl>- <FormMessage />- </FormItem>- )}- />- ),- [BeginQueryType.Paragraph]: (- <FormField- control={form.control}- name={props.name}- render={({ field }) => (- <FormItem className="flex-1">- <FormLabel>{props.label}</FormLabel>- <FormControl>- <Textarea rows={1} {...field}></Textarea>- </FormControl>- <FormMessage />- </FormItem>- )}- />- ),- [BeginQueryType.Options]: (- <FormField- control={form.control}- name={props.name}- render={({ field }) => (- <FormItem className="flex-1">- <FormLabel>{props.label}</FormLabel>- <FormControl>- <SelectWithSearch- allowClear- options={- q.options?.map((x) => ({- label: x,- value: x as string,- })) ?? []- }- {...field}- ></SelectWithSearch>- </FormControl>- <FormMessage />- </FormItem>- )}+ const renderWidget = useCallback((q: BeginQuery, idx: string) => {+ const label = q.name ?? q.key;++ const BeginQueryTypeMap = {+ [BeginQueryType.Line]: (+ <RAGFlowFormItem name={idx} label={label}>+ <Input />+ </RAGFlowFormItem>+ ),+ [BeginQueryType.Paragraph]: (+ <RAGFlowFormItem name={idx} label={label}>+ <Textarea rows={1} />+ </RAGFlowFormItem>+ ),+ [BeginQueryType.Options]: (+ <RAGFlowFormItem name={idx} label={label}>+ <SelectWithSearch+ allowClear+ options={+ q.options?.map((x) => ({+ label: x,+ value: x as string,+ })) ?? []+ }/>- ),- [BeginQueryType.File]: (- <React.Fragment key={idx}>- <FormField- control={form.control}- name={props.name}- render={({ field }) => (- <div className="space-y-6">- <FormItem className="w-full">- <FormLabel>{props.label}</FormLabel>- <FormControl>- <FileUploadDirectUpload- value={field.value}- onChange={field.onChange}- ></FileUploadDirectUpload>- </FormControl>- <FormMessage />- </FormItem>- </div>- )}+ </RAGFlowFormItem>+ ),+ [BeginQueryType.File]: (+ <RAGFlowFormItem name={idx} label={label}>+ {(field) => (+ <FileUploadDirectUpload+ value={field.value}+ onChange={field.onChange}/>- </React.Fragment>- ),- [BeginQueryType.Integer]: (- <FormField- control={form.control}- name={props.name}- render={({ field }) => (- <FormItem className="flex-1">- <FormLabel>{props.label}</FormLabel>- <FormControl>- <Input type="number" {...field}></Input>- </FormControl>- <FormMessage />- </FormItem>- )}- />- ),- [BeginQueryType.Boolean]: (- <FormField- control={form.control}- name={props.name}- render={({ field }) => (- <FormItem className="flex-1">- <FormLabel>{props.label}</FormLabel>- <FormControl>- <Switch- checked={field.value}- onCheckedChange={field.onChange}- ></Switch>- </FormControl>- <FormMessage />- </FormItem>- )}- />- ),- [BeginQueryType.Object]: (- <FormField- control={form.control}- name={props.name}- render={({ field }) => (- <FormItem className="flex-1">- <FormLabel>{props.label}</FormLabel>- <FormControl>- <JsonEditor- value={field.value ?? {}}- onChange={field.onChange}- height="200px"- />- </FormControl>- <FormMessage />- </FormItem>- )}- />- ),- };-- return (- BeginQueryTypeMap[q.type as BeginQueryType] ??- BeginQueryTypeMap[BeginQueryType.Paragraph]- );- },- [form],- );+ )}+ </RAGFlowFormItem>+ ),+ [BeginQueryType.Integer]: (+ <RAGFlowFormItem name={idx} label={label}>+ <Input type="number" />+ </RAGFlowFormItem>+ ),+ [BeginQueryType.Boolean]: <SwitchFormField name={idx} label={label} />,+ [BeginQueryType.Object]: (+ <RAGFlowFormItem name={idx} label={label}>+ {(field) => (+ <JsonEditor+ value={field.value ?? {}}+ onChange={field.onChange}+ height="200px"+ />+ )}+ </RAGFlowFormItem>+ ),+ };++ return (+ BeginQueryTypeMap[q.type as BeginQueryType] ??+ BeginQueryTypeMap[BeginQueryType.Paragraph]+ );+ }, []);const onSubmit = useCallback((values: z.infer<typeof formSchemaValues.schema>) => {@@ -274,7 +183,7 @@ const DebugContent = ({ok(nextValues);},- [formSchemaValues, ok, parameters],+ [ok, parameters],);return (<>diff --git a/web/src/pages/agent/run-sheet/index.tsx b/web/src/pages/agent/run-sheet/index.tsxindex 3afe759db6..8fdb6a43d9 100644--- a/web/src/pages/agent/run-sheet/index.tsx+++ b/web/src/pages/agent/run-sheet/index.tsx@@ -54,7 +54,7 @@ const RunSheet = ({<Sheet onOpenChange={hideModal} open modal={false}><SheetContent className={cn('top-20 px-0 flex flex-col')}><SheetHeader>- <SheetTitle>{t('flow.testRun')}</SheetTitle>+ <SheetTitle className="px-2">{t('flow.testRun')}</SheetTitle></SheetHeader><DebugContentok={onOk}