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
@@ -4,6 +4,7 @@
*/
import { isSqliteAvailable, getDb } from '../index'
import { SESSIONS_TABLE, MESSAGES_TABLE } from './schemas'
import { normalizeMessageContentForStorageRole } from './message-content'
// Re-export types for compatibility with sessions-db.ts consumers
export interface HermesSessionRow {
@@ -377,7 +378,7 @@ export function addMessage(msg: {
`INSERT INTO ${MESSAGES_TABLE} (session_id, role, content, tool_call_id, tool_calls, tool_name, timestamp, token_count, finish_reason, reasoning, reasoning_details, reasoning_content)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
).run(
msg.session_id, msg.role, msg.content,
msg.session_id, msg.role, normalizeMessageContentForStorageRole(msg.role, msg.content),
msg.tool_call_id ?? null, toolCallsJson, msg.tool_name ?? null,
msg.timestamp ?? Math.floor(Date.now() / 1000),
msg.token_count ?? null, msg.finish_reason ?? null,
@@ -412,7 +413,7 @@ export function addMessages(msgs: Array<{
for (const msg of msgs) {
const toolCallsJson = msg.tool_calls ? JSON.stringify(msg.tool_calls) : null
insert.run(
msg.session_id, msg.role, msg.content,
msg.session_id, msg.role, normalizeMessageContentForStorageRole(msg.role, msg.content),
msg.tool_call_id ?? null, toolCallsJson, msg.tool_name ?? null,
msg.timestamp ?? Math.floor(Date.now() / 1000),
msg.token_count ?? null, msg.finish_reason ?? null,