blob: 38fed231ca6616b18edc694da87a11487d1de324 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
import { Observation } from '../../types/types';
import { ParametersType, ToolInfo } from '../../types/tool_types';
import { BaseTool } from '../BaseTool';
const characterCountParams = [
{
name: 'text',
type: 'string',
description: 'The text to count characters in',
required: true
}
] as const;
type CharacterCountParamsType = typeof characterCountParams;
const characterCountInfo: ToolInfo<CharacterCountParamsType> = {
name: 'charactercount',
description: 'Counts characters in text, excluding spaces',
citationRules: 'No citation needed.',
parameterRules: characterCountParams
};
export class CharacterCountTool extends BaseTool<CharacterCountParamsType> {
constructor() {
super(characterCountInfo);
}
async execute(args: ParametersType<CharacterCountParamsType>): Promise<Observation[]> {
const { text } = args;
const count = text ? text.replace(/\s/g, '').length : 0;
return [{ type: 'text', text: `Character count (excluding spaces): ${count}` }];
}
}
|