27 lines
1.1 KiB
TypeScript
27 lines
1.1 KiB
TypeScript
import type { ChatMessage } from '../../types/bot';
|
|
import { normalizeAttachmentPaths } from './shared/botDashboardWorkspace';
|
|
|
|
export * from './shared/botDashboardTypes';
|
|
export * from './shared/botDashboardConstants';
|
|
export * from './shared/botDashboardWorkspace';
|
|
export * from './shared/botDashboardUtils';
|
|
export * from './shared/botDashboardConversation';
|
|
export * from './shared/botDashboardTopicUtils';
|
|
|
|
export function mapBotMessageResponseRow(row: any): ChatMessage {
|
|
const roleRaw = String(row?.role || '').toLowerCase();
|
|
const role: ChatMessage['role'] =
|
|
roleRaw === 'user' || roleRaw === 'assistant' || roleRaw === 'system' ? roleRaw : 'assistant';
|
|
const feedbackRaw = String(row?.feedback || '').trim().toLowerCase();
|
|
const feedback: ChatMessage['feedback'] = feedbackRaw === 'up' || feedbackRaw === 'down' ? feedbackRaw : null;
|
|
return {
|
|
id: Number.isFinite(Number(row?.id)) ? Number(row.id) : undefined,
|
|
role,
|
|
text: String(row?.text || ''),
|
|
attachments: normalizeAttachmentPaths(row?.media),
|
|
ts: Number(row?.ts || Date.now()),
|
|
feedback,
|
|
kind: 'final',
|
|
} as ChatMessage;
|
|
}
|