MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / handler

Function handler

packages/tools/src/definitions/chat-overview.ts:15–50  ·  view source on GitHub ↗
(params: Record<string, unknown>, context: ToolExecutionContext)

Source from the content-addressed store, hash-verified

13}
14
15async function handler(params: Record<string, unknown>, context: ToolExecutionContext): Promise<ToolResult> {
16 const { locale } = context
17 const topN = (params.top_n as number) || 10
18
19 const result = await context.dataProvider!.getChatOverview(topN)
20 if (!result) {
21 const msg = isChineseLocale(locale) ? '无法获取聊天概览' : 'Unable to get chat overview'
22 return { content: msg, data: { error: msg } }
23 }
24
25 const msgSuffix = isChineseLocale(locale) ? '条' : ''
26 const lines: string[] = [
27 `name: ${result.name}`,
28 `platform: ${result.platform}`,
29 `type: ${result.type}`,
30 `totalMessages: ${result.totalMessages}`,
31 `totalMembers: ${result.totalMembers}`,
32 ]
33
34 if (result.firstMessageTs != null && result.lastMessageTs != null) {
35 const start = new Date(result.firstMessageTs * 1000).toLocaleDateString()
36 const end = new Date(result.lastMessageTs * 1000).toLocaleDateString()
37 lines.push(`timeRange: ${start} ~ ${end}`)
38 }
39
40 if (result.topMembers.length > 0) {
41 lines.push(`topMembers:`)
42 for (let i = 0; i < result.topMembers.length; i++) {
43 const m = result.topMembers[i]
44 const pct = result.totalMessages > 0 ? ((m.count / result.totalMessages) * 100).toFixed(1) : '0'
45 lines.push(`${i + 1}. ${m.name} ${m.count}${msgSuffix}(${pct}%)`)
46 }
47 }
48
49 return { content: lines.join('\n'), data: result }
50}
51
52export const chatOverviewTool: ToolDefinition = {
53 name: 'get_chat_overview',

Callers

nothing calls this directly

Calls 2

isChineseLocaleFunction · 0.90
getChatOverviewMethod · 0.65

Tested by

no test coverage detected