import { Observation } from '../types/types'; import { ParametersType, ToolInfo } from '../types/tool_types'; import { BaseTool } from './BaseTool'; const calculateToolParams = [ { name: 'expression', type: 'string', description: 'The mathematical expression to evaluate', required: true, }, ] as const; type CalculateToolParamsType = typeof calculateToolParams; const calculateToolInfo: ToolInfo = { name: 'calculate', citationRules: 'No citation needed.', parameterRules: calculateToolParams, description: 'Runs a calculation and returns the number - uses JavaScript so be sure to use floating point syntax if necessary', }; export class CalculateTool extends BaseTool { constructor() { super(calculateToolInfo); } async execute(args: ParametersType): Promise { // TypeScript will ensure 'args.expression' is a string based on the param config const result = eval(args.expression); // Be cautious with eval(), as it can be dangerous. Consider using a safer alternative. return [{ type: 'text', text: result.toString() }]; } }