diff --git a/src/tools/builtin/messaging.ts b/src/tools/builtin/messaging.ts index 34f71cd..44886c0 100644 --- a/src/tools/builtin/messaging.ts +++ b/src/tools/builtin/messaging.ts @@ -1,4 +1,4 @@ -import { ToolHandler } from '../base/ToolHandler'; +import { ToolHandler, ToolContext } from '../base/ToolHandler'; import { NatsClient } from '../../nats/NatsClient'; import { z } from 'zod'; @@ -11,22 +11,33 @@ function detectRole(): string { return 'unknown'; } -export class SendMessageTool extends ToolHandler { - name = 'send_message'; - description = 'Send real-time message to another developer via NATS'; +// Schemas +const SendMessageSchema = z.object({ + to: z.enum(['admin-dev', 'api-dev', 'web-dev']), + subject: z.string(), + message: z.string(), + data: z.record(z.any()).optional(), +}); - schema = z.object({ - to: z.enum(['admin-dev', 'api-dev', 'web-dev']).describe('Recipient role'), - subject: z.string().describe('Message subject/title'), - message: z.string().describe('Message content'), - data: z.record(z.any()).optional().describe('Optional structured data'), - }); +const ReceiveMessagesSchema = z.object({ + limit: z.number().default(10), +}); +type SendMessageInput = z.infer; +type ReceiveMessagesInput = z.infer; + +export class SendMessageTool extends ToolHandler { constructor(private natsClient: NatsClient) { - super(); + super( + { + name: 'send_message', + description: 'Send real-time message to another developer via NATS', + }, + SendMessageSchema, + ); } - async execute(input: any): Promise { + protected async handle(input: SendMessageInput, _context: ToolContext): Promise { const { to, subject, message, data } = input; const from = detectRole(); @@ -52,18 +63,17 @@ export class SendMessageTool extends ToolHandler { } } -export class ReceiveMessagesTool extends ToolHandler { - name = 'receive_messages'; - description = 'Receive real-time messages from other developers via NATS'; - - schema = z.object({ - limit: z.number().default(10).describe('Maximum number of messages to return'), - }); - +export class ReceiveMessagesTool extends ToolHandler { private messages: any[] = []; constructor(private natsClient: NatsClient) { - super(); + super( + { + name: 'receive_messages', + description: 'Receive real-time messages from other developers via NATS', + }, + ReceiveMessagesSchema, + ); this.setupSubscription(); } @@ -77,7 +87,7 @@ export class ReceiveMessagesTool extends ToolHandler { }); } - async execute(input: any): Promise { + protected async handle(input: ReceiveMessagesInput, _context: ToolContext): Promise { const limit = input.limit || 10; const recentMessages = this.messages.slice(-limit);