Fix: Properly extend ToolHandler abstract class
- Use super() constructor with options and schema - Implement protected handle() method instead of execute() - Define proper TypeScript types with z.infer - Fixes compilation errors with ToolHandler interface 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -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';
|
||||
|
||||
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'),
|
||||
// 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(),
|
||||
});
|
||||
|
||||
const ReceiveMessagesSchema = z.object({
|
||||
limit: z.number().default(10),
|
||||
});
|
||||
|
||||
type SendMessageInput = z.infer<typeof SendMessageSchema>;
|
||||
type ReceiveMessagesInput = z.infer<typeof ReceiveMessagesSchema>;
|
||||
|
||||
export class SendMessageTool extends ToolHandler<SendMessageInput, any> {
|
||||
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<any> {
|
||||
protected async handle(input: SendMessageInput, _context: ToolContext): Promise<any> {
|
||||
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<ReceiveMessagesInput, any> {
|
||||
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<any> {
|
||||
protected async handle(input: ReceiveMessagesInput, _context: ToolContext): Promise<any> {
|
||||
const limit = input.limit || 10;
|
||||
const recentMessages = this.messages.slice(-limit);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user