(params: Record<string, unknown>, context: ToolExecutionContext)
| 15 | } |
| 16 | |
| 17 | async function handler(params: Record<string, unknown>, context: ToolExecutionContext): Promise<ToolResult> { |
| 18 | const { locale, maxMessagesLimit } = context |
| 19 | const limit = maxMessagesLimit || (params.limit as number) || 1000 |
| 20 | |
| 21 | const result = await context.dataProvider!.getSegmentMessages(params.segment_id as number, limit) |
| 22 | |
| 23 | if (!result) { |
| 24 | const data = { |
| 25 | error: isChineseLocale(locale) ? '未找到指定的段落' : 'Segment not found', |
| 26 | segmentId: params.segment_id, |
| 27 | } |
| 28 | return { content: JSON.stringify(data), data } |
| 29 | } |
| 30 | |
| 31 | const localeStr = isChineseLocale(locale) ? 'zh-CN' : 'en-US' |
| 32 | const startTime = new Date(result.startTs * 1000).toLocaleString(localeStr) |
| 33 | const endTime = new Date(result.endTs * 1000).toLocaleString(localeStr) |
| 34 | const rawMessages = result.messages.map((m) => ({ |
| 35 | id: m.id, |
| 36 | senderName: m.senderName, |
| 37 | content: m.content, |
| 38 | timestamp: m.timestamp, |
| 39 | })) |
| 40 | |
| 41 | const data = { |
| 42 | segmentId: result.segmentId, |
| 43 | time: `${startTime} ~ ${endTime}`, |
| 44 | messageCount: result.messageCount, |
| 45 | returnedCount: result.returnedCount, |
| 46 | participants: result.participants, |
| 47 | rawMessages, |
| 48 | } |
| 49 | |
| 50 | return { content: JSON.stringify(data), data, rawMessages } |
| 51 | } |
| 52 | |
| 53 | export const getSegmentMessagesTool: ToolDefinition = { |
| 54 | name: 'get_segment_messages', |
nothing calls this directly
no test coverage detected