mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-21 05:14:45 +08:00
feat: rag retrieving tool call result display (#263)
* feat: local search tool call result display * chore: add file copyright * fix: miss edit plan interrupt feedback * feat: disable pasting html into input box
This commit is contained in:
@@ -18,7 +18,7 @@ import { useDebouncedCallback } from "use-debounce";
|
||||
|
||||
import "~/styles/prosemirror.css";
|
||||
import { resourceSuggestion } from "./resource-suggestion";
|
||||
import React, { forwardRef, useMemo, useRef } from "react";
|
||||
import React, { forwardRef, useEffect, useMemo, useRef } from "react";
|
||||
import type { Resource } from "~/core/messages";
|
||||
import { useRAGProvider } from "~/core/api/hooks";
|
||||
import { LoadingOutlined } from "@ant-design/icons";
|
||||
@@ -76,6 +76,9 @@ function formatItem(item: JSONContent): {
|
||||
const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(
|
||||
({ className, onChange, onEnter }: MessageInputProps, ref) => {
|
||||
const editorRef = useRef<Editor>(null);
|
||||
const handleEnterRef = useRef<
|
||||
((message: string, resources: Array<Resource>) => void) | undefined
|
||||
>(onEnter);
|
||||
const debouncedUpdates = useDebouncedCallback(
|
||||
async (editor: EditorInstance) => {
|
||||
if (onChange) {
|
||||
@@ -100,6 +103,10 @@ const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(
|
||||
},
|
||||
}));
|
||||
|
||||
useEffect(() => {
|
||||
handleEnterRef.current = onEnter;
|
||||
}, [onEnter]);
|
||||
|
||||
const { provider, loading } = useRAGProvider();
|
||||
|
||||
const extensions = useMemo(() => {
|
||||
@@ -127,11 +134,11 @@ const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(
|
||||
addKeyboardShortcuts() {
|
||||
return {
|
||||
Enter: () => {
|
||||
if (onEnter) {
|
||||
if (handleEnterRef.current) {
|
||||
const { text, resources } = formatMessage(
|
||||
this.editor.getJSON() ?? [],
|
||||
);
|
||||
onEnter(text, resources);
|
||||
handleEnterRef.current(text, resources);
|
||||
}
|
||||
return this.editor.commands.clearContent();
|
||||
},
|
||||
@@ -150,7 +157,7 @@ const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(
|
||||
);
|
||||
}
|
||||
return extensions;
|
||||
}, [onEnter, provider]);
|
||||
}, [provider]);
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
@@ -172,6 +179,7 @@ const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(
|
||||
class:
|
||||
"prose prose-base dark:prose-invert inline-editor font-default focus:outline-none max-w-full",
|
||||
},
|
||||
transformPastedHTML: transformPastedHTML,
|
||||
}}
|
||||
onCreate={({ editor }) => {
|
||||
editorRef.current = editor;
|
||||
@@ -186,4 +194,18 @@ const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(
|
||||
},
|
||||
);
|
||||
|
||||
function transformPastedHTML(html: string) {
|
||||
try {
|
||||
// Strip HTML from user-pasted content
|
||||
const tempEl = document.createElement("div");
|
||||
tempEl.innerHTML = html;
|
||||
|
||||
return tempEl.textContent || tempEl.innerText || "";
|
||||
} catch (error) {
|
||||
console.error("Error transforming pasted HTML", error);
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
export default MessageInput;
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
// Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import { forwardRef, useEffect, useImperativeHandle, useState } from "react";
|
||||
import type { Resource } from "~/core/messages";
|
||||
import { cn } from "~/lib/utils";
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
// Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import type { MentionOptions } from "@tiptap/extension-mention";
|
||||
import { ReactRenderer } from "@tiptap/react";
|
||||
import {
|
||||
|
||||
Reference in New Issue
Block a user