mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-02 14:04:50 +00:00
feat(agent): refactor message context into unified shumai_message (#365)
* feat(agent): refactor message context into unified shumai_message * fix(agent): persist custom_message entry type in DatabaseSessionStorage and handle message mapping defensively * fix(agent): pass clean prompt to harness and replace optimistic messages on shumai_message stream * fix(agent): align asset context DTO contract, sync comment attachments, and fix session stats
This commit is contained in:
@@ -30,11 +30,31 @@ export function buildSessionMessages(pathEntries: PathEntry[]): ChatMessage[] {
|
||||
const appendMessage = (entry: PathEntry) => {
|
||||
const timestampMs = new Date(entry.timestamp).getTime()
|
||||
if (entry.type === 'message') {
|
||||
messages.push({
|
||||
...entry.message,
|
||||
id: entry.id,
|
||||
timestamp: entry.message.timestamp || timestampMs,
|
||||
} as unknown as ChatMessage)
|
||||
if ((entry as unknown as { customType?: string }).customType === 'shumai_message') {
|
||||
const customEntry = entry as unknown as {
|
||||
customType: string
|
||||
content: string
|
||||
display?: boolean
|
||||
details?: Record<string, unknown>
|
||||
}
|
||||
messages.push({
|
||||
id: entry.id,
|
||||
role: 'custom',
|
||||
customType: customEntry.customType,
|
||||
content: customEntry.content,
|
||||
display: customEntry.display,
|
||||
details: customEntry.details,
|
||||
timestamp: timestampMs,
|
||||
} as unknown as ChatMessage)
|
||||
return
|
||||
}
|
||||
if (entry.message) {
|
||||
messages.push({
|
||||
...entry.message,
|
||||
id: entry.id,
|
||||
timestamp: entry.message.timestamp || timestampMs,
|
||||
} as unknown as ChatMessage)
|
||||
}
|
||||
} else if (entry.type === 'custom_message') {
|
||||
if (entry.customType === 'context') return
|
||||
messages.push({
|
||||
@@ -117,9 +137,13 @@ export function mapEntryToMessage(
|
||||
entryRecord: Prisma.AgentSessionEntryGetPayload<Record<string, never>>,
|
||||
): ChatMessage | null {
|
||||
const payload = (entryRecord.data as Record<string, unknown>) || {}
|
||||
let type = (entryRecord.type || 'message') as SessionTreeEntry['type']
|
||||
if (type === 'message' && payload.customType === 'shumai_message') {
|
||||
type = 'custom_message'
|
||||
}
|
||||
const entryObj = {
|
||||
id: entryRecord.id,
|
||||
type: (entryRecord.type || 'message') as SessionTreeEntry['type'],
|
||||
type,
|
||||
parentId: entryRecord.parentId,
|
||||
timestamp: entryRecord.createdAt.toISOString(),
|
||||
...payload,
|
||||
|
||||
Reference in New Issue
Block a user