diff options
Diffstat (limited to 'src/client/views/nodes/chatbot/tools/CalculateTool.ts')
| -rw-r--r-- | src/client/views/nodes/chatbot/tools/CalculateTool.ts | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/src/client/views/nodes/chatbot/tools/CalculateTool.ts b/src/client/views/nodes/chatbot/tools/CalculateTool.ts index 77ab1b39b..e96c9a98a 100644 --- a/src/client/views/nodes/chatbot/tools/CalculateTool.ts +++ b/src/client/views/nodes/chatbot/tools/CalculateTool.ts @@ -1,26 +1,32 @@ +import { Observation } from '../types/types'; +import { ParametersType } from './ToolTypes'; import { BaseTool } from './BaseTool'; -export class CalculateTool extends BaseTool<{ expression: string }> { +const calculateToolParams = [ + { + name: 'expression', + type: 'string', + description: 'The mathematical expression to evaluate', + required: true, + }, +] as const; + +type CalculateToolParamsType = typeof calculateToolParams; + +export class CalculateTool extends BaseTool<CalculateToolParamsType> { constructor() { super( 'calculate', 'Perform a calculation', - { - expression: { - type: 'string', - description: 'The mathematical expression to evaluate', - required: 'true', - max_inputs: '1', - }, - }, + calculateToolParams, // Use the reusable param config here '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<unknown> { - // Note: Using eval() can be dangerous. Consider using a safer alternative. - const result = eval(args.expression); + async execute(args: ParametersType<CalculateToolParamsType>): Promise<Observation[]> { + // 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() }]; } } |
