import { z } from "zod";
import { sendInteractiveMessageChannel } from "../../../state-machine/helpers/peer.js";
import { createToolFactory, PermissionLevel, ToolCategory } from "../types.js";
export const askSearchableDropdownToolFactory = createToolFactory("askSearchableDropdown", ({ clark, services, }) => {
    const { chatSessionStore } = services;
    return {
        description: `
Present the user with a searchable dropdown when there are many options to choose from.
The user can type to filter and select one option.

Use this instead of askMultiChoice when:
- There are more than 6 options
- The user needs to search/filter a long list (e.g. integration types, database tables)

Do NOT use this for:
- Questions with 2-6 options (use askMultiChoice instead)
- Open-ended questions where the user might want to type a free-form response

The user will select one option, and their selection will be sent back to you as a message.
`,
        category: ToolCategory.GENERAL,
        defaultPermission: PermissionLevel.ALLOW,
        readOnly: true,
        inputSchema: z.object({
            question: z
                .string()
                .describe("The question to ask the user. Supports markdown formatting."),
            options: z
                .array(z.object({
                label: z.string().describe("Display text for the option."),
                value: z
                    .string()
                    .describe("Value identifier returned when selected (e.g. a pluginId)."),
                description: z
                    .string()
                    .optional()
                    .describe("Optional secondary text shown below the label."),
            }))
                .min(2)
                .describe("List of options for the user to search and select from."),
            placeholder: z
                .string()
                .optional()
                .describe('Placeholder text for the search input (e.g. "Search integrations...").'),
        }),
        execute: async ({ question, options, placeholder }) => {
            const sendInteractiveMessage = sendInteractiveMessageChannel(clark, chatSessionStore);
            const result = await sendInteractiveMessage({
                role: "assistant",
                type: "searchable_dropdown",
                content: question,
                group: "clark",
                options: options.map((o) => ({
                    label: o.label,
                    value: o.value,
                    description: o.description,
                })),
                placeholder,
            });
            if (!result.success) {
                return {
                    success: false,
                    message: "Cannot ask question because there is already an active message that requires user input.",
                };
            }
            return {
                success: true,
                message: `Presented ${options.length} options to user. Awaiting their selection.`,
            };
        },
        getSummary: (input, output) => {
            const optionCount = input.options?.length ?? 0;
            const preview = input.question.length > 40
                ? input.question.substring(0, 40) + "..."
                : input.question;
            return {
                input: `"${preview}" (${optionCount} options)`,
                output: output.message ?? "Awaiting user selection",
            };
        },
    };
});
//# sourceMappingURL=ask-searchable-dropdown.js.map