blob: 818332c44a6a4aeb781d164cbc271be5c112a456 (
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
|
import { BaseTool } from './BaseTool';
export class CalculateTool extends BaseTool<{ expression: string }> {
constructor() {
super(
'calculate',
'Perform a calculation',
{
expression: {
type: 'string',
description: 'The mathematical expression to evaluate',
required: 'true',
},
},
'Provide a mathematical expression to calculate that would work with JavaScript eval().',
'Runs a calculation and returns the number - uses JavaScript so be sure to use floating point syntax if necessary'
);
}
async execute(args: { expression: string }): Promise<any> {
// Note: Using eval() can be dangerous. Consider using a safer alternative.
const result = eval(args.expression);
return [{ type: 'text', text: result.toString() }];
}
}
|