Import the client, server, skills, tests, and build scripts as the starting point for the rebuild, then trim the surfaces this project does not ship: Electron desktop packaging, the marketing website, and the ESP32 firmware tree. CI keeps the web build, e2e, lockfile, release, and Docker workflows. Rename the package and CLI entry points to hermes-ui, drop the prepare hook so npm ci no longer triggers a build, and drop the removed tsconfig and nodemon references. Rewrite AGENTS.md, ARCHITECTURE.md, DEVELOPMENT.md, and the READMEs so the documented package map and hard rules match this repository. reference_code/ is ignored: it is a read-only snapshot, not an input to the build.
63 lines
2.1 KiB
TypeScript
63 lines
2.1 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import {
|
|
normalizeMessageContentForStorage,
|
|
normalizeMessageContentForStorageRole,
|
|
} from '../../packages/server/src/db/hermes/message-content'
|
|
|
|
describe('message content normalization', () => {
|
|
it('summarizes multimodal envelopes without persisting base64 images', () => {
|
|
const content = {
|
|
_multimodal: true,
|
|
content: [
|
|
{ type: 'text', text: 'Image loaded into context.' },
|
|
{ type: 'image_url', image_url: { url: 'data:image/png;base64,AAAA' } },
|
|
],
|
|
}
|
|
|
|
const normalized = normalizeMessageContentForStorage(JSON.stringify(content))
|
|
|
|
expect(normalized).toBe('Image loaded into context.\n[screenshot]')
|
|
expect(normalized).not.toContain('data:image/')
|
|
expect(normalized).not.toContain('AAAA')
|
|
})
|
|
|
|
it('summarizes OpenAI-style content part arrays', () => {
|
|
const normalized = normalizeMessageContentForStorage([
|
|
{ type: 'text', text: 'Question: what is shown?' },
|
|
{ type: 'input_image', image_url: 'data:image/jpeg;base64,BBBB' },
|
|
])
|
|
|
|
expect(normalized).toBe('Question: what is shown?\n[screenshot]')
|
|
})
|
|
|
|
it('redacts nested data images in non-envelope JSON without dropping other fields', () => {
|
|
const normalized = normalizeMessageContentForStorage(JSON.stringify({
|
|
output: {
|
|
url: 'data:image/png;base64,CCCC',
|
|
status: 'ok',
|
|
},
|
|
}))
|
|
|
|
expect(JSON.parse(normalized)).toEqual({
|
|
output: {
|
|
url: '[screenshot]',
|
|
status: 'ok',
|
|
},
|
|
})
|
|
})
|
|
|
|
it('does not parse or rewrite unrelated JSON strings', () => {
|
|
const content = '{\n "type": "event",\n "payload": "ok"\n}'
|
|
|
|
expect(normalizeMessageContentForStorage(content)).toBe(content)
|
|
})
|
|
|
|
it('keeps user-authored image data untouched and only cleans non-user messages', () => {
|
|
const content = '{"content":[{"type":"image_url","image_url":{"url":"data:image/png;base64,DDDD"}}]}'
|
|
|
|
expect(normalizeMessageContentForStorageRole('user', content)).toBe(content)
|
|
expect(normalizeMessageContentForStorageRole('tool', content)).not.toContain('data:image/')
|
|
})
|
|
})
|