Clean multimodal tool results before storage (#911)

This commit is contained in:
ekko
2026-05-21 20:19:06 +08:00
committed by GitHub
parent 39ead94352
commit 4d89767847
4 changed files with 175 additions and 3 deletions
@@ -3,6 +3,7 @@ import type { Server as HttpServer } from 'http'
import { getToken } from '../../../services/auth'
import { logger } from '../../../services/logger'
import { getDb } from '../../../db'
import { normalizeMessageContentForStorage, normalizeMessageContentForStorageRole } from '../../../db/hermes/message-content'
import { AgentClients, GROUP_CHAT_AGENT_SOCKET_SECRET } from './agent-clients'
import { ContextEngine } from '../context-engine/compressor'
import { SessionDeleter } from '../session-deleter'
@@ -34,6 +35,10 @@ function contentToStorageString(content: unknown): string {
return JSON.stringify(content ?? '')
}
function messageContentForStorage(role: string | undefined, content: string): string {
return normalizeMessageContentForStorageRole(role, content)
}
function contentToText(content: unknown): string {
if (typeof content === 'string') {
const trimmed = content.trim()
@@ -406,7 +411,7 @@ class ChatStorage {
reasoning_details = excluded.reasoning_details,
reasoning_content = excluded.reasoning_content`
).run(
msg.id, msg.roomId, msg.senderId, msg.senderName, msg.content, msg.timestamp,
msg.id, msg.roomId, msg.senderId, msg.senderName, messageContentForStorage(msg.role, msg.content), msg.timestamp,
msg.role || 'user',
msg.tool_call_id ?? null,
toolCallsJson,