diff options
| author | A.J. Shulman <Shulman.aj@gmail.com> | 2024-07-10 16:16:26 -0400 |
|---|---|---|
| committer | A.J. Shulman <Shulman.aj@gmail.com> | 2024-07-10 16:16:26 -0400 |
| commit | cab0311e2fd9a6379628c000d11ddcd805e01f64 (patch) | |
| tree | 60cb3f397426cb3931c13ebe3b8a1e8eb98480dd /src/client/views/nodes/ChatBox/tools/CalculateTool.ts | |
| parent | d0e09ff3526e4f6b9aad824fad1020d083a87631 (diff) | |
first attempt at integrating everything
Diffstat (limited to 'src/client/views/nodes/ChatBox/tools/CalculateTool.ts')
| -rw-r--r-- | src/client/views/nodes/ChatBox/tools/CalculateTool.ts | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/client/views/nodes/ChatBox/tools/CalculateTool.ts b/src/client/views/nodes/ChatBox/tools/CalculateTool.ts new file mode 100644 index 000000000..b881d90fa --- /dev/null +++ b/src/client/views/nodes/ChatBox/tools/CalculateTool.ts @@ -0,0 +1,25 @@ +import { BaseTool } from './BaseTool'; + +export class CalculateTool extends BaseTool { + 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() }]; + } +} |
