mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-07 05:39:05 +08:00
fix(agent): update message id and improve content handling
- Change default message id from -1 to 77777 in useSession - Remove schema validation for session response temporarily - Add proper content parsing for agent session messages
This commit is contained in:
parent
4bd6087dc0
commit
078fd57eb5
@ -14,7 +14,6 @@ import {
|
|||||||
GetAgentResponse,
|
GetAgentResponse,
|
||||||
GetAgentResponseSchema,
|
GetAgentResponseSchema,
|
||||||
GetAgentSessionResponse,
|
GetAgentSessionResponse,
|
||||||
GetAgentSessionResponseSchema,
|
|
||||||
ListAgentSessionsResponse,
|
ListAgentSessionsResponse,
|
||||||
ListAgentSessionsResponseSchema,
|
ListAgentSessionsResponseSchema,
|
||||||
type ListAgentsResponse,
|
type ListAgentsResponse,
|
||||||
@ -172,7 +171,9 @@ export class AgentApiClient {
|
|||||||
const url = this.getSessionPaths(agentId).withId(sessionId)
|
const url = this.getSessionPaths(agentId).withId(sessionId)
|
||||||
try {
|
try {
|
||||||
const response = await this.axios.get(url)
|
const response = await this.axios.get(url)
|
||||||
const data = GetAgentSessionResponseSchema.parse(response.data)
|
// const data = GetAgentSessionResponseSchema.parse(response.data)
|
||||||
|
// TODO: enable validation
|
||||||
|
const data = response.data
|
||||||
if (sessionId !== data.id) {
|
if (sessionId !== data.id) {
|
||||||
throw new Error('Session ID mismatch in response')
|
throw new Error('Session ID mismatch in response')
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,7 +35,7 @@ export const useSession = (agentId: string, sessionId: string) => {
|
|||||||
if (!agentId || !sessionId || !data) return
|
if (!agentId || !sessionId || !data) return
|
||||||
const origin = cloneDeep(data)
|
const origin = cloneDeep(data)
|
||||||
const newMessageDraft = {
|
const newMessageDraft = {
|
||||||
id: -1,
|
id: 77777,
|
||||||
session_id: '',
|
session_id: '',
|
||||||
role: 'user',
|
role: 'user',
|
||||||
content: {
|
content: {
|
||||||
|
|||||||
@ -1,11 +1,15 @@
|
|||||||
|
import { loggerService } from '@logger'
|
||||||
import ContextMenu from '@renderer/components/ContextMenu'
|
import ContextMenu from '@renderer/components/ContextMenu'
|
||||||
import Scrollbar from '@renderer/components/Scrollbar'
|
import Scrollbar from '@renderer/components/Scrollbar'
|
||||||
import { useSession } from '@renderer/hooks/agents/useSession'
|
import { useSession } from '@renderer/hooks/agents/useSession'
|
||||||
|
import { ModelMessage } from 'ai'
|
||||||
import { memo } from 'react'
|
import { memo } from 'react'
|
||||||
import styled from 'styled-components'
|
import styled from 'styled-components'
|
||||||
|
|
||||||
import NarrowLayout from './NarrowLayout'
|
import NarrowLayout from './NarrowLayout'
|
||||||
|
|
||||||
|
const logger = loggerService.withContext('AgentSessionMessages')
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
agentId: string
|
agentId: string
|
||||||
sessionId: string
|
sessionId: string
|
||||||
@ -14,18 +18,28 @@ type Props = {
|
|||||||
const AgentSessionMessages: React.FC<Props> = ({ agentId, sessionId }) => {
|
const AgentSessionMessages: React.FC<Props> = ({ agentId, sessionId }) => {
|
||||||
const { messages } = useSession(agentId, sessionId)
|
const { messages } = useSession(agentId, sessionId)
|
||||||
|
|
||||||
|
const getTextFromContent = (content: string | ModelMessage): string => {
|
||||||
|
logger.debug('content', { content })
|
||||||
|
if (typeof content === 'string') {
|
||||||
|
return content
|
||||||
|
} else if (typeof content.content === 'string') {
|
||||||
|
return content.content
|
||||||
|
} else {
|
||||||
|
return content.content
|
||||||
|
.filter((part) => part.type === 'text')
|
||||||
|
.map((part) => part.text)
|
||||||
|
.join('\n')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MessagesContainer id="messages" className="messages-container">
|
<MessagesContainer id="messages" className="messages-container">
|
||||||
<NarrowLayout style={{ display: 'flex', flexDirection: 'column-reverse' }}>
|
<NarrowLayout style={{ display: 'flex', flexDirection: 'column-reverse' }}>
|
||||||
<ContextMenu>
|
<ContextMenu>
|
||||||
<ScrollContainer>
|
<ScrollContainer>
|
||||||
{messages.map((message) => {
|
{messages.map((message) => {
|
||||||
const content = message.content.content
|
const content = getTextFromContent(message.content)
|
||||||
if (typeof content === 'string') {
|
return <div key={message.id}>{content}</div>
|
||||||
return <div key={message.id}>{content}</div>
|
|
||||||
} else {
|
|
||||||
return 'Not string content'
|
|
||||||
}
|
|
||||||
})}
|
})}
|
||||||
</ScrollContainer>
|
</ScrollContainer>
|
||||||
</ContextMenu>
|
</ContextMenu>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user