"use strict";
// =============================================================================
// Pure Agent - Clarify Tool
// Ported from Hermes tools/clarify_tool.py
// Ask the user for clarification with structured options
// =============================================================================
Object.defineProperty(exports, "__esModule", { value: true });
const tool_registry_1 = require("../tool-registry");
const result_types_1 = require("../result-types");
// ---------------------------------------------------------------------------
// Pending clarifications
// ---------------------------------------------------------------------------
const _pendingClarifications = new Map();
// ---------------------------------------------------------------------------
// Handler
// ---------------------------------------------------------------------------
async function clarifyHandler(args, context) {
    const { question, options, timeout_seconds = 120 } = args;
    if (!question)
        return (0, result_types_1.toolError)('Missing required parameter: question');
    // If options provided, format as multiple choice
    let formattedQuestion = question;
    if (options && Array.isArray(options) && options.length > 0) {
        formattedQuestion += '\n\n' + options.map((opt, i) => `${i + 1}. ${opt}`).join('\n');
    }
    // Return the question - the frontend/Gateway will handle presenting it to the user
    // and providing the answer via the tool_approval mechanism
    return (0, result_types_1.toolResult)({
        status: 'question_asked',
        question: formattedQuestion,
        options: options || [],
        timeout_seconds,
        instruction: 'This question should be presented to the user. Wait for their response before continuing.',
    });
}
// ---------------------------------------------------------------------------
// Registration
// ---------------------------------------------------------------------------
tool_registry_1.registry.register({
    name: 'clarify',
    toolset: 'clarify',
    schema: {
        description: 'Ask the user a clarifying question when the task is ambiguous. Use this instead of guessing when the user\'s intent could be interpreted multiple ways. Provide options when possible to make it easy for the user to respond.',
        parameters: {
            type: 'object',
            properties: {
                question: {
                    type: 'string',
                    description: 'The question to ask the user',
                },
                options: {
                    type: 'array',
                    items: { type: 'string' },
                    description: 'Optional list of choices for the user to pick from',
                },
                timeout_seconds: {
                    type: 'number',
                    description: 'How long to wait for a response (default: 120)',
                    default: 120,
                },
            },
            required: ['question'],
        },
    },
    handler: clarifyHandler,
    isAsync: true,
    description: 'Ask user for clarification',
    emoji: '❓',
});
//# sourceMappingURL=clarify.js.map