Fix: Share-log bugs (#9172)

### What problem does this PR solve?

Fix Share-log bugs #3221

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
chanx
2025-08-01 21:55:49 +08:00
committed by GitHub
parent a16cd4f110
commit 47ba683728
4 changed files with 93 additions and 48 deletions

View File

@ -16,7 +16,7 @@ import { useFetchUserInfo } from '@/hooks/user-setting-hooks';
import { Message } from '@/interfaces/database/chat'; import { Message } from '@/interfaces/database/chat';
import { buildMessageUuidWithRole } from '@/utils/chat'; import { buildMessageUuidWithRole } from '@/utils/chat';
import { get } from 'lodash'; import { get } from 'lodash';
import { memo, useCallback } from 'react'; import { memo, useCallback, useMemo } from 'react';
import { useParams } from 'umi'; import { useParams } from 'umi';
import DebugContent from '../debug-content'; import DebugContent from '../debug-content';
import { BeginQuery } from '../interface'; import { BeginQuery } from '../interface';
@ -43,7 +43,6 @@ function AgentChatBox() {
const { data: canvasInfo } = useFetchAgent(); const { data: canvasInfo } = useFetchAgent();
const { id: canvasId } = useParams(); const { id: canvasId } = useParams();
const { uploadCanvasFile, loading } = useUploadCanvasFileWithProgress(); const { uploadCanvasFile, loading } = useUploadCanvasFileWithProgress();
const getInputs = useCallback((message: Message) => { const getInputs = useCallback((message: Message) => {
return get(message, 'data.inputs', {}) as Record<string, BeginQuery>; return get(message, 'data.inputs', {}) as Record<string, BeginQuery>;
}, []); }, []);
@ -80,7 +79,16 @@ function AgentChatBox() {
}, },
[appendUploadResponseList, uploadCanvasFile], [appendUploadResponseList, uploadCanvasFile],
); );
const isWaitting = useMemo(() => {
const temp = derivedMessages?.some((message, i) => {
const flag =
message.role === MessageType.Assistant &&
derivedMessages.length - 1 === i &&
message.data;
return flag;
});
return temp;
}, [derivedMessages]);
return ( return (
<> <>
<section className="flex flex-1 flex-col px-5 h-[90vh]"> <section className="flex flex-1 flex-col px-5 h-[90vh]">
@ -106,12 +114,26 @@ function AgentChatBox() {
showLikeButton={false} showLikeButton={false}
sendLoading={sendLoading} sendLoading={sendLoading}
> >
{message.role === MessageType.Assistant &&
derivedMessages.length - 1 === i && (
<DebugContent <DebugContent
parameters={buildInputList(message)} parameters={buildInputList(message)}
message={message}
ok={handleOk(message)} ok={handleOk(message)}
isNext={false} isNext={false}
btnText={'Submit'} btnText={'Submit'}
></DebugContent> ></DebugContent>
)}
{message.role === MessageType.Assistant &&
derivedMessages.length - 1 !== i && (
<div>
<div>{message?.data?.tips}</div>
<div>
{buildInputList(message)?.map((item) => item.value)}
</div>
</div>
)}
</MessageItem> </MessageItem>
); );
})} })}
@ -122,9 +144,9 @@ function AgentChatBox() {
<NextMessageInput <NextMessageInput
value={value} value={value}
sendLoading={sendLoading} sendLoading={sendLoading}
disabled={false} disabled={isWaitting}
sendDisabled={sendLoading} sendDisabled={sendLoading || isWaitting}
isUploading={loading} isUploading={loading || isWaitting}
onPressEnter={handlePressEnter} onPressEnter={handlePressEnter}
onInputChange={handleInputChange} onInputChange={handleInputChange}
stopOutputMessage={stopOutputMessage} stopOutputMessage={stopOutputMessage}

View File

@ -11,6 +11,7 @@ import { Input } from '@/components/ui/input';
import { RAGFlowSelect } from '@/components/ui/select'; import { RAGFlowSelect } from '@/components/ui/select';
import { Switch } from '@/components/ui/switch'; import { Switch } from '@/components/ui/switch';
import { Textarea } from '@/components/ui/textarea'; import { Textarea } from '@/components/ui/textarea';
import { IMessage } from '@/pages/chat/interface';
import { zodResolver } from '@hookform/resolvers/zod'; import { zodResolver } from '@hookform/resolvers/zod';
import React, { ReactNode, useCallback, useMemo } from 'react'; import React, { ReactNode, useCallback, useMemo } from 'react';
import { useForm } from 'react-hook-form'; import { useForm } from 'react-hook-form';
@ -28,6 +29,7 @@ const StringFields = [
interface IProps { interface IProps {
parameters: BeginQuery[]; parameters: BeginQuery[];
message?: IMessage;
ok(parameters: any[]): void; ok(parameters: any[]): void;
isNext?: boolean; isNext?: boolean;
loading?: boolean; loading?: boolean;
@ -37,6 +39,7 @@ interface IProps {
const DebugContent = ({ const DebugContent = ({
parameters, parameters,
message,
ok, ok,
isNext = true, isNext = true,
loading = false, loading = false,
@ -228,10 +231,10 @@ const DebugContent = ({
}, },
[formSchemaValues, ok, parameters], [formSchemaValues, ok, parameters],
); );
return ( return (
<> <>
<section> <section>
{message?.data?.tips && <div className="mb-2">{message.data.tips}</div>}
<Form {...form}> <Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4"> <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
{parameters.map((x, idx) => { {parameters.map((x, idx) => {
@ -242,7 +245,7 @@ const DebugContent = ({
type="submit" type="submit"
loading={loading} loading={loading}
disabled={!submittable || submitButtonDisabled} disabled={!submittable || submitButtonDisabled}
className="w-full mt-8" className="w-full mt-1"
> >
{btnText || t(isNext ? 'common.next' : 'flow.run')} {btnText || t(isNext ? 'common.next' : 'flow.run')}
</ButtonLoading> </ButtonLoading>

View File

@ -12,6 +12,7 @@ import {
AccordionTrigger, AccordionTrigger,
} from '@/components/ui/accordion'; } from '@/components/ui/accordion';
import { cn } from '@/lib/utils'; import { cn } from '@/lib/utils';
import { isEmpty } from 'lodash';
import { Operator } from '../constant'; import { Operator } from '../constant';
import OperatorIcon from '../operator-icon'; import OperatorIcon from '../operator-icon';
import { import {
@ -19,7 +20,20 @@ import {
toLowerCaseStringAndDeleteChar, toLowerCaseStringAndDeleteChar,
typeMap, typeMap,
} from './workFlowTimeline'; } from './workFlowTimeline';
const capitalizeWords = (str: string, separator: string = '_'): string => {
if (!str) return '';
return str
.split(separator)
.map((word) => {
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
})
.join(' ');
};
const changeToolName = (toolName: any) => {
const name = 'Agent ' + capitalizeWords(toolName);
return name;
};
const ToolTimelineItem = ({ const ToolTimelineItem = ({
tools, tools,
sendLoading = false, sendLoading = false,
@ -34,16 +48,7 @@ const ToolTimelineItem = ({
const filteredTools = tools.filter( const filteredTools = tools.filter(
(tool) => !blackList.includes(tool.tool_name), (tool) => !blackList.includes(tool.tool_name),
); );
const capitalizeWords = (str: string, separator: string = '_'): string => {
if (!str) return '';
return str
.split(separator)
.map((word) => {
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
})
.join(' ');
};
const parentName = (str: string, separator: string = '-->') => { const parentName = (str: string, separator: string = '-->') => {
if (!str) return ''; if (!str) return '';
const strs = str.split(separator); const strs = str.split(separator);
@ -124,13 +129,11 @@ const ToolTimelineItem = ({
)} )}
{isShare && ( {isShare && (
<span> <span>
{ {typeMap[
typeMap[
toLowerCaseStringAndDeleteChar( toLowerCaseStringAndDeleteChar(
tool.tool_name, tool.tool_name,
) as keyof typeof typeMap ) as keyof typeof typeMap
] ] ?? changeToolName(tool.tool_name)}
}
</span> </span>
)} )}
<span className="text-text-sub-title text-xs"> <span className="text-text-sub-title text-xs">
@ -146,22 +149,37 @@ const ToolTimelineItem = ({
</span> </span>
</div> </div>
</AccordionTrigger> </AccordionTrigger>
{!isShare && (
<AccordionContent> <AccordionContent>
<div className="space-y-2"> <div className="space-y-2">
{!isShare && (
<JsonViewer <JsonViewer
data={tool.result} data={tool.result}
title="content" title="content"
></JsonViewer> ></JsonViewer>
)}
{isShare && (
<JsonViewer
data={tool.result}
title={''}
></JsonViewer>
)}
</div> </div>
</AccordionContent> </AccordionContent>
)}
{isShare && !isEmpty(tool.arguments) && (
<AccordionContent>
<div className="space-y-2">
{tool &&
tool.arguments &&
Object.entries(tool.arguments).length &&
Object.entries(tool.arguments).map(([key, val]) => {
return (
<div key={key}>
<div className="text-sm font-medium leading-none">
{key}
</div>
<div className="text-sm text-muted-foreground">
{val || ''}
</div>
</div>
);
})}
</div>
</AccordionContent>
)}
</AccordionItem> </AccordionItem>
</Accordion> </Accordion>
</section> </section>

View File

@ -144,12 +144,14 @@ const AgentLogPage: React.FC = () => {
const handlePageChange = (current?: number, pageSize?: number) => { const handlePageChange = (current?: number, pageSize?: number) => {
console.log('current', current, 'pageSize', pageSize); console.log('current', current, 'pageSize', pageSize);
setPagination((pre) => { let page = current || 1;
return { if (pagination.pageSize !== pageSize) {
...pre, page = 1;
current: current ?? pre.pageSize ? 1 : pre.current, }
pageSize: pageSize ?? pre.pageSize, setPagination({
}; ...pagination,
current: page,
pageSize: pageSize || 10,
}); });
}; };