| 23 | } |
| 24 | |
| 25 | async function handler(params: Record<string, unknown>, context: ToolExecutionContext): Promise<ToolResult> { |
| 26 | const keyword = params.keyword as string |
| 27 | const limit = (params.limit as number) || 50 |
| 28 | |
| 29 | const result = await context.dataProvider!.searchMessages([keyword], { |
| 30 | timeFilter: context.timeFilter, |
| 31 | limit, |
| 32 | }) |
| 33 | |
| 34 | const data = { |
| 35 | total: result.total, |
| 36 | returned: result.messages.length, |
| 37 | hasMore: result.messages.length < result.total, |
| 38 | messages: result.messages.map((m) => ({ |
| 39 | sender: m.senderName, |
| 40 | content: m.content, |
| 41 | time: new Date(m.timestamp * 1000).toISOString(), |
| 42 | })), |
| 43 | } |
| 44 | |
| 45 | return { |
| 46 | content: JSON.stringify(data), |
| 47 | data, |
| 48 | rawMessages: result.messages, |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | export const searchTool: ToolDefinition = { |
| 53 | name: 'search_keyword', |