mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-30 15:59:09 +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,
|
||||
GetAgentResponseSchema,
|
||||
GetAgentSessionResponse,
|
||||
GetAgentSessionResponseSchema,
|
||||
ListAgentSessionsResponse,
|
||||
ListAgentSessionsResponseSchema,
|
||||
type ListAgentsResponse,
|
||||
@ -172,7 +171,9 @@ export class AgentApiClient {
|
||||
const url = this.getSessionPaths(agentId).withId(sessionId)
|
||||
try {
|
||||
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) {
|
||||
throw new Error('Session ID mismatch in response')
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ export const useSession = (agentId: string, sessionId: string) => {
|
||||
if (!agentId || !sessionId || !data) return
|
||||
const origin = cloneDeep(data)
|
||||
const newMessageDraft = {
|
||||
id: -1,
|
||||
id: 77777,
|
||||
session_id: '',
|
||||
role: 'user',
|
||||
content: {
|
||||
|
||||
@ -1,11 +1,15 @@
|
||||
import { loggerService } from '@logger'
|
||||
import ContextMenu from '@renderer/components/ContextMenu'
|
||||
import Scrollbar from '@renderer/components/Scrollbar'
|
||||
import { useSession } from '@renderer/hooks/agents/useSession'
|
||||
import { ModelMessage } from 'ai'
|
||||
import { memo } from 'react'
|
||||
import styled from 'styled-components'
|
||||
|
||||
import NarrowLayout from './NarrowLayout'
|
||||
|
||||
const logger = loggerService.withContext('AgentSessionMessages')
|
||||
|
||||
type Props = {
|
||||
agentId: string
|
||||
sessionId: string
|
||||
@ -14,18 +18,28 @@ type Props = {
|
||||
const AgentSessionMessages: React.FC<Props> = ({ 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 (
|
||||
<MessagesContainer id="messages" className="messages-container">
|
||||
<NarrowLayout style={{ display: 'flex', flexDirection: 'column-reverse' }}>
|
||||
<ContextMenu>
|
||||
<ScrollContainer>
|
||||
{messages.map((message) => {
|
||||
const content = message.content.content
|
||||
if (typeof content === 'string') {
|
||||
return <div key={message.id}>{content}</div>
|
||||
} else {
|
||||
return 'Not string content'
|
||||
}
|
||||
const content = getTextFromContent(message.content)
|
||||
return <div key={message.id}>{content}</div>
|
||||
})}
|
||||
</ScrollContainer>
|
||||
</ContextMenu>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user