Skip to content

Commit 47ba683

Browse files
authored
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)
1 parent a16cd4f commit 47ba683

File tree

4 files changed

+93
-48
lines changed

4 files changed

+93
-48
lines changed

web/src/pages/agent/chat/box.tsx

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { useFetchUserInfo } from '@/hooks/user-setting-hooks';
1616
import { Message } from '@/interfaces/database/chat';
1717
import { buildMessageUuidWithRole } from '@/utils/chat';
1818
import { get } from 'lodash';
19-
import { memo, useCallback } from 'react';
19+
import { memo, useCallback, useMemo } from 'react';
2020
import { useParams } from 'umi';
2121
import DebugContent from '../debug-content';
2222
import { BeginQuery } from '../interface';
@@ -43,7 +43,6 @@ function AgentChatBox() {
4343
const { data: canvasInfo } = useFetchAgent();
4444
const { id: canvasId } = useParams();
4545
const { uploadCanvasFile, loading } = useUploadCanvasFileWithProgress();
46-
4746
const getInputs = useCallback((message: Message) => {
4847
return get(message, 'data.inputs', {}) as Record<string, BeginQuery>;
4948
}, []);
@@ -80,7 +79,16 @@ function AgentChatBox() {
8079
},
8180
[appendUploadResponseList, uploadCanvasFile],
8281
);
83-
82+
const isWaitting = useMemo(() => {
83+
const temp = derivedMessages?.some((message, i) => {
84+
const flag =
85+
message.role === MessageType.Assistant &&
86+
derivedMessages.length - 1 === i &&
87+
message.data;
88+
return flag;
89+
});
90+
return temp;
91+
}, [derivedMessages]);
8492
return (
8593
<>
8694
<section className="flex flex-1 flex-col px-5 h-[90vh]">
@@ -106,12 +114,26 @@ function AgentChatBox() {
106114
showLikeButton={false}
107115
sendLoading={sendLoading}
108116
>
109-
<DebugContent
110-
parameters={buildInputList(message)}
111-
ok={handleOk(message)}
112-
isNext={false}
113-
btnText={'Submit'}
114-
></DebugContent>
117+
{message.role === MessageType.Assistant &&
118+
derivedMessages.length - 1 === i && (
119+
<DebugContent
120+
parameters={buildInputList(message)}
121+
message={message}
122+
ok={handleOk(message)}
123+
isNext={false}
124+
btnText={'Submit'}
125+
></DebugContent>
126+
)}
127+
{message.role === MessageType.Assistant &&
128+
derivedMessages.length - 1 !== i && (
129+
<div>
130+
<div>{message?.data?.tips}</div>
131+
132+
<div>
133+
{buildInputList(message)?.map((item) => item.value)}
134+
</div>
135+
</div>
136+
)}
115137
</MessageItem>
116138
);
117139
})}
@@ -122,9 +144,9 @@ function AgentChatBox() {
122144
<NextMessageInput
123145
value={value}
124146
sendLoading={sendLoading}
125-
disabled={false}
126-
sendDisabled={sendLoading}
127-
isUploading={loading}
147+
disabled={isWaitting}
148+
sendDisabled={sendLoading || isWaitting}
149+
isUploading={loading || isWaitting}
128150
onPressEnter={handlePressEnter}
129151
onInputChange={handleInputChange}
130152
stopOutputMessage={stopOutputMessage}

web/src/pages/agent/debug-content/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Input } from '@/components/ui/input';
1111
import { RAGFlowSelect } from '@/components/ui/select';
1212
import { Switch } from '@/components/ui/switch';
1313
import { Textarea } from '@/components/ui/textarea';
14+
import { IMessage } from '@/pages/chat/interface';
1415
import { zodResolver } from '@hookform/resolvers/zod';
1516
import React, { ReactNode, useCallback, useMemo } from 'react';
1617
import { useForm } from 'react-hook-form';
@@ -28,6 +29,7 @@ const StringFields = [
2829

2930
interface IProps {
3031
parameters: BeginQuery[];
32+
message?: IMessage;
3133
ok(parameters: any[]): void;
3234
isNext?: boolean;
3335
loading?: boolean;
@@ -37,6 +39,7 @@ interface IProps {
3739

3840
const DebugContent = ({
3941
parameters,
42+
message,
4043
ok,
4144
isNext = true,
4245
loading = false,
@@ -228,10 +231,10 @@ const DebugContent = ({
228231
},
229232
[formSchemaValues, ok, parameters],
230233
);
231-
232234
return (
233235
<>
234236
<section>
237+
{message?.data?.tips && <div className="mb-2">{message.data.tips}</div>}
235238
<Form {...form}>
236239
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
237240
{parameters.map((x, idx) => {
@@ -242,7 +245,7 @@ const DebugContent = ({
242245
type="submit"
243246
loading={loading}
244247
disabled={!submittable || submitButtonDisabled}
245-
className="w-full mt-8"
248+
className="w-full mt-1"
246249
>
247250
{btnText || t(isNext ? 'common.next' : 'flow.run')}
248251
</ButtonLoading>

web/src/pages/agent/log-sheet/toolTimelineItem.tsx

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,28 @@ import {
1212
AccordionTrigger,
1313
} from '@/components/ui/accordion';
1414
import { cn } from '@/lib/utils';
15+
import { isEmpty } from 'lodash';
1516
import { Operator } from '../constant';
1617
import OperatorIcon from '../operator-icon';
1718
import {
1819
JsonViewer,
1920
toLowerCaseStringAndDeleteChar,
2021
typeMap,
2122
} from './workFlowTimeline';
23+
const capitalizeWords = (str: string, separator: string = '_'): string => {
24+
if (!str) return '';
2225

26+
return str
27+
.split(separator)
28+
.map((word) => {
29+
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
30+
})
31+
.join(' ');
32+
};
33+
const changeToolName = (toolName: any) => {
34+
const name = 'Agent ' + capitalizeWords(toolName);
35+
return name;
36+
};
2337
const ToolTimelineItem = ({
2438
tools,
2539
sendLoading = false,
@@ -34,16 +48,7 @@ const ToolTimelineItem = ({
3448
const filteredTools = tools.filter(
3549
(tool) => !blackList.includes(tool.tool_name),
3650
);
37-
const capitalizeWords = (str: string, separator: string = '_'): string => {
38-
if (!str) return '';
3951

40-
return str
41-
.split(separator)
42-
.map((word) => {
43-
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
44-
})
45-
.join(' ');
46-
};
4752
const parentName = (str: string, separator: string = '-->') => {
4853
if (!str) return '';
4954
const strs = str.split(separator);
@@ -124,13 +129,11 @@ const ToolTimelineItem = ({
124129
)}
125130
{isShare && (
126131
<span>
127-
{
128-
typeMap[
129-
toLowerCaseStringAndDeleteChar(
130-
tool.tool_name,
131-
) as keyof typeof typeMap
132-
]
133-
}
132+
{typeMap[
133+
toLowerCaseStringAndDeleteChar(
134+
tool.tool_name,
135+
) as keyof typeof typeMap
136+
] ?? changeToolName(tool.tool_name)}
134137
</span>
135138
)}
136139
<span className="text-text-sub-title text-xs">
@@ -146,22 +149,37 @@ const ToolTimelineItem = ({
146149
</span>
147150
</div>
148151
</AccordionTrigger>
149-
<AccordionContent>
150-
<div className="space-y-2">
151-
{!isShare && (
152+
{!isShare && (
153+
<AccordionContent>
154+
<div className="space-y-2">
152155
<JsonViewer
153156
data={tool.result}
154157
title="content"
155158
></JsonViewer>
156-
)}
157-
{isShare && (
158-
<JsonViewer
159-
data={tool.result}
160-
title={''}
161-
></JsonViewer>
162-
)}
163-
</div>
164-
</AccordionContent>
159+
</div>
160+
</AccordionContent>
161+
)}
162+
{isShare && !isEmpty(tool.arguments) && (
163+
<AccordionContent>
164+
<div className="space-y-2">
165+
{tool &&
166+
tool.arguments &&
167+
Object.entries(tool.arguments).length &&
168+
Object.entries(tool.arguments).map(([key, val]) => {
169+
return (
170+
<div key={key}>
171+
<div className="text-sm font-medium leading-none">
172+
{key}
173+
</div>
174+
<div className="text-sm text-muted-foreground">
175+
{val || ''}
176+
</div>
177+
</div>
178+
);
179+
})}
180+
</div>
181+
</AccordionContent>
182+
)}
165183
</AccordionItem>
166184
</Accordion>
167185
</section>

web/src/pages/agents/agent-log-page.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,14 @@ const AgentLogPage: React.FC = () => {
144144

145145
const handlePageChange = (current?: number, pageSize?: number) => {
146146
console.log('current', current, 'pageSize', pageSize);
147-
setPagination((pre) => {
148-
return {
149-
...pre,
150-
current: current ?? pre.pageSize ? 1 : pre.current,
151-
pageSize: pageSize ?? pre.pageSize,
152-
};
147+
let page = current || 1;
148+
if (pagination.pageSize !== pageSize) {
149+
page = 1;
150+
}
151+
setPagination({
152+
...pagination,
153+
current: page,
154+
pageSize: pageSize || 10,
153155
});
154156
};
155157

0 commit comments

Comments
 (0)