Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Iframe should support input variables (#5156)

gstrat880c6d787f929c
diff --git a/web/src/pages/chat/shared-hooks.ts b/web/src/pages/chat/shared-hooks.ts
index 4e59077000..ba058142b9 100644
--- a/web/src/pages/chat/shared-hooks.ts
+++ b/web/src/pages/chat/shared-hooks.ts
@@ -22,11 +22,18 @@ export const useSendButtonDisabled = (value: string) => {
export const useGetSharedChatSearchParams = () => {
const [searchParams] = useSearchParams();
-
+ const data_prefix = 'data_';
+ const data = Object.fromEntries(
+ searchParams
+ .entries()
+ .filter(([key, value]) => key.startsWith(data_prefix))
+ .map(([key, value]) => [key.replace(data_prefix, ''), value]),
+ );
return {
from: searchParams.get('from') as SharedFrom,
sharedId: searchParams.get('shared_id'),
locale: searchParams.get('locale'),
+ data: data,
visibleAvatar: searchParams.get('visible_avatar')
? searchParams.get('visible_avatar') !== '1'
: true,
@@ -34,7 +41,11 @@ export const useGetSharedChatSearchParams = () => {
};
export const useSendSharedMessage = () => {
- const { from, sharedId: conversationId } = useGetSharedChatSearchParams();
+ const {
+ from,
+ sharedId: conversationId,
+ data: data,
+ } = useGetSharedChatSearchParams();
const { createSharedConversation: setConversation } =
useCreateNextSharedConversation();
const { handleInputChange, value, setValue } = useHandleMessageInputChange();
@@ -84,7 +95,8 @@ export const useSendSharedMessage = () => {
);
const fetchSessionId = useCallback(async () => {
- const ret = await send({ question: '' });
+ const payload = { question: '' };
+ const ret = await send({ ...payload, ...data });
if (isCompletionError(ret)) {
message.error(ret?.data.message);
setHasError(true);
diff --git a/web/src/pages/flow/header/index.tsx b/web/src/pages/flow/header/index.tsx
index 245e33101e..161c92a957 100644
--- a/web/src/pages/flow/header/index.tsx
+++ b/web/src/pages/flow/header/index.tsx
@@ -9,7 +9,7 @@ import { useCallback } from 'react';
import { Link, useParams } from 'umi';
import {
useGetBeginNodeDataQuery,
- useGetBeginNodeDataQueryIsEmpty,
+ useGetBeginNodeDataQueryIsSafe,
} from '../hooks/use-get-begin-query';
import {
useSaveGraph,
@@ -35,7 +35,7 @@ const FlowHeader = ({ showChatDrawer, chatDrawerVisible }: IProps) => {
const getBeginNodeDataQuery = useGetBeginNodeDataQuery();
const { showEmbedModal, hideEmbedModal, embedVisible, beta } =
useShowEmbedModal();
- const isBeginNodeDataQueryEmpty = useGetBeginNodeDataQueryIsEmpty();
+ const isBeginNodeDataQuerySafe = useGetBeginNodeDataQueryIsSafe();
const handleShowEmbedModal = useCallback(() => {
showEmbedModal();
@@ -79,7 +79,7 @@ const FlowHeader = ({ showChatDrawer, chatDrawerVisible }: IProps) => {
<Button
type="primary"
onClick={handleShowEmbedModal}
- disabled={!isBeginNodeDataQueryEmpty}
+ disabled={!isBeginNodeDataQuerySafe}
>
<b>{t('embedIntoSite', { keyPrefix: 'common' })}</b>
</Button>
diff --git a/web/src/pages/flow/hooks/use-get-begin-query.tsx b/web/src/pages/flow/hooks/use-get-begin-query.tsx
index ae0e4d783a..557bbfce03 100644
--- a/web/src/pages/flow/hooks/use-get-begin-query.tsx
+++ b/web/src/pages/flow/hooks/use-get-begin-query.tsx
@@ -16,18 +16,19 @@ export const useGetBeginNodeDataQuery = () => {
return getBeginNodeDataQuery;
};
-export const useGetBeginNodeDataQueryIsEmpty = () => {
- const [isBeginNodeDataQueryEmpty, setIsBeginNodeDataQueryEmpty] =
+export const useGetBeginNodeDataQueryIsSafe = () => {
+ const [isBeginNodeDataQuerySafe, setIsBeginNodeDataQuerySafe] =
useState(false);
const getBeginNodeDataQuery = useGetBeginNodeDataQuery();
const nodes = useGraphStore((state) => state.nodes);
useEffect(() => {
const query: BeginQuery[] = getBeginNodeDataQuery();
- setIsBeginNodeDataQueryEmpty(query.length === 0);
+ const isSafe = !query.some((q) => !q.optional && q.type === 'file');
+ setIsBeginNodeDataQuerySafe(isSafe);
}, [getBeginNodeDataQuery, nodes]);
- return isBeginNodeDataQueryEmpty;
+ return isBeginNodeDataQuerySafe;
};
// exclude nodes with branches