import { AnalyzeDataFunction } from './AnalyzeData.js';
import { AgentFunctionBase } from './utils/index.js';
import { AgentOutputType, ChatMessageBuilder } from '../agent-core/index.js';
export class ReadAndAnalyzeCSVDataFunction extends AgentFunctionBase {
    name = 'readAndAnalyzeCSVData';
    description = 'Read and analyze CSV datasets to answer questions. Returns a comprehensive summary of all relevant details. Only use on CSV files';
    parameters = {
        type: 'object',
        properties: {
            path: {
                type: 'string',
                description: 'path to the data file',
            },
            question: {
                type: 'string',
                description: 'the question your analysis is trying to answer',
            },
        },
        required: ['path', 'question'],
        additionalProperties: false,
    };
    buildExecutor(agent) {
        return async (params, rawParams) => {
            const analyzeData = new AnalyzeDataFunction(agent.context.llm, agent.context.chat.tokenizer);
            const data = await agent.context.workspace.readFile(params.path);
            const summary = await analyzeData.analyze({ data, question: params.question }, agent.context);
            const variable = await agent.context.variables.save('dataFile', data);
            return {
                outputs: [
                    {
                        type: AgentOutputType.Success,
                        title: `[${agent.config.prompts.name}] ${this.name}`,
                        content: `Data File Stored in Variable: \${${variable}}\nData Summary:\n\`\`\`\n${summary}\n\`\`\``,
                    },
                ],
                messages: [
                    ChatMessageBuilder.functionCall(this.name, params),
                    ChatMessageBuilder.functionCallResult(this.name, `\${${variable}}`),
                    ChatMessageBuilder.functionCallResult(this.name, `Data File Stored in Variable: \${${variable}}\nData Summary:\n\`\`\`\n${summary}\n\`\`\``),
                ],
            };
        };
    }
}
