mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-21 03:57:04 +00:00
- 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
37 lines
908 B
TypeScript
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
|
|
}
|