MCPcopy Create free account
hub / github.com/ChatLab/ChatLab / formatMessageCompact

Function formatMessageCompact

packages/node-runtime/src/ai/preprocessor/format.ts:45–63  ·  view source on GitHub ↗
(
  msg: {
    id?: number
    senderName: string
    content: string | null
    timestamp: number
  },
  locale?: string
)

Source from the content-addressed store, hash-verified

43 * 输出格式: "2025/3/3 07:25:04 张三: 消息内容"
44 */
45export function formatMessageCompact(
46 msg: {
47 id?: number
48 senderName: string
49 content: string | null
50 timestamp: number
51 },
52 locale?: string
53): string {
54 const localeStr = isChineseLocale(locale) ? 'zh-CN' : 'en-US'
55 const time = new Date(msg.timestamp * 1000).toLocaleString(localeStr)
56 let content = msg.content || (t('noContent', locale) as string)
57
58 if (content.length > MAX_MESSAGE_CONTENT_LENGTH) {
59 content = content.slice(0, MAX_MESSAGE_CONTENT_LENGTH) + '...'
60 }
61
62 return `${time} ${msg.senderName}: ${content}`
63}
64
65/**
66 * 格式化时间范围用于返回结果

Callers 1

Calls 2

isChineseLocaleFunction · 0.70
tFunction · 0.70

Tested by

no test coverage detected