Skip to content

Let's use AI to Earn!

feat(web): agent UI optimization (#432)

yikaf53b1968bdb7
diff --git a/project/web/src/app/[lng]/chat/[taskId]/utils/convertMessages.ts b/project/web/src/app/[lng]/chat/[taskId]/utils/convertMessages.ts
index a8a133e7..d1890c12 100644
--- a/project/web/src/app/[lng]/chat/[taskId]/utils/convertMessages.ts
+++ b/project/web/src/app/[lng]/chat/[taskId]/utils/convertMessages.ts
@@ -334,20 +334,57 @@ function processResultMessage(
msg: TaskMessage,
index: number,
displayMessages: IDisplayMessage[],
-): { contentToAdd?: string; newAssistantMsgIndex?: number } {
- // result 消息的 message 字段直接在第一层
- const content = (msg as any).message || ''
+): { contentToAdd?: string; newAssistantMsgIndex?: number; actions?: any[] } {
+ const msgData = (msg as any).message
+ let content = ''
+ let actions: any[] = []
+
+ // 处理 result 消息格式
+ // 格式1: message 是字符串
+ if (msgData && typeof msgData === 'string') {
+ content = msgData
+ }
+ // 格式2: message 是对象,包含 message 文本和 result 数组/对象
+ else if (msgData && typeof msgData === 'object') {
+ // 获取文本消息
+ if (msgData.message && typeof msgData.message === 'string') {
+ content = msgData.message
+ }
+
+ // 解析 result 数据中的 action(支持数组和单个对象)
+ if (msgData.result) {
+ // 统一转换为数组处理
+ const resultArray = Array.isArray(msgData.result) ? msgData.result : [msgData.result]
+
+ actions = resultArray
+ .filter((item: any) => item && item.action) // 只处理有 action 的项
+ .map((item: any) => ({
+ type: item.action, // 映射 action -> type
+ platform: item.platform,
+ accountId: item.accountId,
+ title: item.title,
+ description: item.description,
+ medias: item.medias,
+ tags: item.tags,
+ }))
+ }
+ }
- if (content && typeof content === 'string') {
+ if (content || actions.length > 0) {
const lastMsg = displayMessages[displayMessages.length - 1]
if (lastMsg && lastMsg.role === 'assistant') {
- return { contentToAdd: content }
+ // 将 actions 附加到最后一条 assistant 消息
+ if (actions.length > 0) {
+ lastMsg.actions = [...(lastMsg.actions || []), ...actions]
+ }
+ return { contentToAdd: content || undefined }
} else {
displayMessages.push({
id: (msg as any).uuid || `result-${index}`,
role: 'assistant',
- content,
+ content: content || '',
status: 'done',
+ actions: actions.length > 0 ? actions : undefined,
})
return { newAssistantMsgIndex: displayMessages.length - 1 }
}
diff --git a/project/web/src/components/Home/HomeChat/index.tsx b/project/web/src/components/Home/HomeChat/index.tsx
index 09912979..75763647 100644
--- a/project/web/src/components/Home/HomeChat/index.tsx
+++ b/project/web/src/components/Home/HomeChat/index.tsx
@@ -62,15 +62,14 @@ export function HomeChat({
const [isSubmitting, setIsSubmitting] = useState(false)
const [addAccountVisible, setAddAccountVisible] = useState(false)
- // 处理添加账号点击 - 未登录时跳转登录
+ // 处理添加账号点击 - 未登录时弹出登录弹窗
const handleAddChannelClick = useCallback(() => {
if (!token) {
- toast.warning(t('home.loginRequired' as any) || 'Please login first')
- router.push('/auth/login')
+ openLoginModal(() => setAddAccountVisible(true))
return
}
setAddAccountVisible(true)
- }, [token, router, t])
+ }, [token])
// 使用媒体上传 Hook
const {