diff options
author | A.J. Shulman <Shulman.aj@gmail.com> | 2024-10-17 10:41:49 -0400 |
---|---|---|
committer | A.J. Shulman <Shulman.aj@gmail.com> | 2024-10-17 10:41:49 -0400 |
commit | 80d86bd5ae3e1d3dc70e7636f72a872a5fb2f01d (patch) | |
tree | 0eaea49f596bd16720f05a6535958ab8270673c8 /src/client/views/nodes/chatbot/tools/CreateCSVTool.ts | |
parent | 596502c232ea6b6b88c3c58486e139074ea056ff (diff) |
Implemented strict typechecking for tools, specifically tool inputs
Diffstat (limited to 'src/client/views/nodes/chatbot/tools/CreateCSVTool.ts')
-rw-r--r-- | src/client/views/nodes/chatbot/tools/CreateCSVTool.ts | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/src/client/views/nodes/chatbot/tools/CreateCSVTool.ts b/src/client/views/nodes/chatbot/tools/CreateCSVTool.ts index fff57c6d4..b321d98ba 100644 --- a/src/client/views/nodes/chatbot/tools/CreateCSVTool.ts +++ b/src/client/views/nodes/chatbot/tools/CreateCSVTool.ts @@ -1,36 +1,46 @@ import { BaseTool } from './BaseTool'; import { Networking } from '../../../../Network'; import { Observation } from '../types/types'; +import { ParametersType } from './ToolTypes'; -export class CreateCSVTool extends BaseTool<{ csvData: { type: string; description: string; required: boolean }; filename: { type: string; description: string; required: boolean } }> { +const createCSVToolParams = [ + { + name: 'csvData', + type: 'string', + description: 'A string of comma-separated values representing the CSV data.', + required: true, + }, + { + name: 'filename', + type: 'string', + description: 'The base name of the CSV file to be created. Should end in ".csv".', + required: true, + }, +] as const; + +type CreateCSVToolParamsType = typeof createCSVToolParams; + +export class CreateCSVTool extends BaseTool<CreateCSVToolParamsType> { private _handleCSVResult: (url: string, filename: string, id: string, data: string) => void; constructor(handleCSVResult: (url: string, title: string, id: string, data: string) => void) { super( 'createCSV', 'Creates a CSV file from raw CSV data and saves it to the server', - { - csvData: { - type: 'string', - description: 'A string of comma-separated values representing the CSV data.', - required: true, - }, - filename: { - type: 'string', - description: 'The base name of the CSV file to be created. Should end in ".csv".', - required: true, - }, - }, + createCSVToolParams, 'Provide a CSV string and a filename to create a CSV file.', 'Creates a CSV file from the provided CSV string and saves it to the server with a unique identifier, returning the file URL and UUID.' ); this._handleCSVResult = handleCSVResult; } - async execute(args: { csvData: string; filename: string }): Promise<Observation[]> { + async execute(args: ParametersType<CreateCSVToolParamsType>): Promise<Observation[]> { try { console.log('Creating CSV file:', args.filename, ' with data:', args.csvData); - const { fileUrl, id } = await Networking.PostToServer('/createCSV', { filename: args.filename, data: args.csvData }); + const { fileUrl, id } = await Networking.PostToServer('/createCSV', { + filename: args.filename, + data: args.csvData, + }); this._handleCSVResult(fileUrl, args.filename, id, args.csvData); |