Files
hapi/web/src/chat/normalizeUser.ts
T
weishu 34cfe49f87 refactor: extract chat normalization and reducer logic, cleanup legacy credentials
- Split normalize.ts into focused modules: normalizeAgent, normalizeUser, normalizeUtils
- Extract reducer.ts into specialized modules: reducerCliOutput, reducerEvents, reducerTimeline, reducerTools
- Remove legacy credentials support (zod schema, readCredentials, writeCredentialsLegacy)
- Refactor NewSession component from monolithic file into modular subcomponents
- Improves code organization and maintainability across chat and authentication layers
2026-01-03 23:39:10 +08:00

37 lines
908 B
TypeScript

import type { NormalizedMessage } from '@/chat/types'
import { isObject } from '@/chat/normalizeUtils'
export function normalizeUserRecord(
messageId: string,
localId: string | null,
createdAt: number,
content: unknown,
meta?: unknown
): NormalizedMessage | null {
if (typeof content === 'string') {
return {
id: messageId,
localId,
createdAt,
role: 'user',
content: { type: 'text', text: content },
isSidechain: false,
meta
}
}
if (isObject(content) && content.type === 'text' && typeof content.text === 'string') {
return {
id: messageId,
localId,
createdAt,
role: 'user',
content: { type: 'text', text: content.text },
isSidechain: false,
meta
}
}
return null
}