import { AnalyzeDataFunction } from './AnalyzeData.js';
import { AgentFunctionBase } from './utils/index.js';
import { ChatMessageBuilder } from '../agent-core/index.js';
export class ReadAndAnalyzeFileFunction extends AgentFunctionBase {
    name = 'readAndAnalyzeFile';
    description = 'Read and analyze files to answer questions. Returns a comprehensive summary of all relevant details.';
    parameters = {
        type: 'object',
        properties: {
            path: {
                type: 'string',
                description: 'path to the 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('fileData', data);
            return {
                outputs: [],
                messages: [
                    ChatMessageBuilder.functionCall(this.name, params),
                    ChatMessageBuilder.functionCallResult(this.name, `File Data Stored in Variable: \${${variable}}\nData Summary:\n\`\`\`\n${summary}\n\`\`\``),
                    ChatMessageBuilder.functionCallResult(this.name, `\${${variable}}`),
                ],
            };
        };
    }
}
