aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/ChatBox/tools/BaseTool.ts
blob: c7942e3598cc8f86186e76f1471c2cd08ab818c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { Tool } from '../types';

export abstract class BaseTool<T extends Record<string, any> = Record<string, any>> implements Tool<T> {
    constructor(
        public name: string,
        public description: string,
        public parameters: Record<string, any>,
        public useRules: string,
        public briefSummary: string
    ) {}

    abstract execute(args: T): Promise<any>;

    getActionRule(isCurrentTool: boolean): Record<string, any> {
        if (isCurrentTool) {
            return {
                [this.name]: {
                    name: this.name,
                    useRules: this.useRules,
                    description: this.description,
                    parameters: this.parameters,
                },
            };
        }
        return {
            [this.name]: {
                description: 'This tool is not currently selected.',
            },
        };
    }
}