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 { NatsClient } from '../../nats/NatsClient';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
@@ -11,22 +11,33 @@ function detectRole(): string {
|
|||||||
return 'unknown';
|
return 'unknown';
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SendMessageTool extends ToolHandler {
|
// Schemas
|
||||||
name = 'send_message';
|
const SendMessageSchema = z.object({
|
||||||
description = 'Send real-time message to another developer via NATS';
|
to: z.enum(['admin-dev', 'api-dev', 'web-dev']),
|
||||||
|
subject: z.string(),
|
||||||
|
message: z.string(),
|
||||||
|
data: z.record(z.any()).optional(),
|
||||||
|
});
|
||||||
|
|
||||||
schema = z.object({
|
const ReceiveMessagesSchema = z.object({
|
||||||
to: z.enum(['admin-dev', 'api-dev', 'web-dev']).describe('Recipient role'),
|
limit: z.number().default(10),
|
||||||
subject: z.string().describe('Message subject/title'),
|
});
|
||||||
message: z.string().describe('Message content'),
|
|
||||||
data: z.record(z.any()).optional().describe('Optional structured data'),
|
|
||||||
});
|
|
||||||
|
|
||||||
|
type SendMessageInput = z.infer<typeof SendMessageSchema>;
|
||||||
|
type ReceiveMessagesInput = z.infer<typeof ReceiveMessagesSchema>;
|
||||||
|
|
||||||
|
export class SendMessageTool extends ToolHandler<SendMessageInput, any> {
|
||||||
constructor(private natsClient: NatsClient) {
|
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 { to, subject, message, data } = input;
|
||||||
const from = detectRole();
|
const from = detectRole();
|
||||||
|
|
||||||
@@ -52,18 +63,17 @@ export class SendMessageTool extends ToolHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ReceiveMessagesTool extends ToolHandler {
|
export class ReceiveMessagesTool extends ToolHandler<ReceiveMessagesInput, any> {
|
||||||
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'),
|
|
||||||
});
|
|
||||||
|
|
||||||
private messages: any[] = [];
|
private messages: any[] = [];
|
||||||
|
|
||||||
constructor(private natsClient: NatsClient) {
|
constructor(private natsClient: NatsClient) {
|
||||||
super();
|
super(
|
||||||
|
{
|
||||||
|
name: 'receive_messages',
|
||||||
|
description: 'Receive real-time messages from other developers via NATS',
|
||||||
|
},
|
||||||
|
ReceiveMessagesSchema,
|
||||||
|
);
|
||||||
this.setupSubscription();
|
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 limit = input.limit || 10;
|
||||||
const recentMessages = this.messages.slice(-limit);
|
const recentMessages = this.messages.slice(-limit);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user