import { Observation } from '../../types/types'; import { ParametersType, ToolInfo } from '../../types/tool_types'; import { BaseTool } from '../BaseTool'; const wordCountParams = [ { name: 'phrase', type: 'string', description: 'The phrase to count words in', required: true } ] as const; type WordCountParamsType = typeof wordCountParams; const wordCountInfo: ToolInfo = { name: 'wordcount', description: 'Counts the number of words in a given phrase', citationRules: 'No citation needed.', parameterRules: wordCountParams }; export class WordCountTool extends BaseTool { constructor() { super(wordCountInfo); } async execute(args: ParametersType): Promise { const { phrase } = args; const wordCount = phrase ? phrase.trim().split(/\s+/).length : 0; return [{ type: 'text', text: `Word count: ${wordCount}` }]; } }