import { z } from "zod";
import { getPrefixedLogger } from "../../../../util/logger.js";
import { AttachmentsStore } from "../../../attachments/index.js";
import { getActiveContext } from "../../../llm/context-v2/utils/index.js";
import { createToolFactory, PermissionLevel, ToolCategory } from "../types.js";
export const listAttachmentsToolFactory = createToolFactory("listAttachments", ({ clark, services, }) => {
    return {
        category: ToolCategory.PLAN,
        description: `List all attachments that have been uploaded during this session.

Returns a compact list of attachments with:
- id: Numeric identifier (use this ID in exitPlanMode.attachmentIds to include attachments in plans)
- type: Attachment type (image, pdf, csv, json, yaml, css, txt)
- fileName: Original filename of the uploaded file
- label: Brief 2-3 word description of the content (e.g., "login form mockup", "orders dataset")
- insight: Key observation about the attachment (e.g., "grid layout appears misaligned", "contains 500 order records")
- originalMessage: The original user message that accompanied this attachment (truncated to 300 chars)

Use this tool to see what files the user has uploaded before calling exitPlanMode.
The file content/data is NOT returned - use attachmentIds in exitPlanMode to include attachments in plans.

Example workflow:
1. User uploads files (images, PDFs, CSV, etc.) while chatting
2. Call listAttachments to see available attachments with their IDs, types, and descriptions
3. When creating a plan, pass relevant attachmentIds to exitPlanMode`,
        defaultPermission: PermissionLevel.ALLOW,
        readOnly: true,
        inputSchema: z.object({}),
        execute: async () => {
            const logger = getPrefixedLogger("[listAttachments]");
            const context = getActiveContext(clark, services);
            if (!context) {
                logger.error("Context not loaded");
                return { attachments: [], error: "Context not available" };
            }
            const store = new AttachmentsStore();
            const attachments = store.listAttachments(context);
            logger.info(`Returning ${attachments.length} attachment(s)`);
            return {
                attachments,
                count: attachments.length,
            };
        },
        getSummary: (_input, output) => {
            const count = output.count ?? 0;
            return { output: `${count} attachment${count === 1 ? "" : "s"}` };
        },
    };
});
//# sourceMappingURL=list-attachments.js.map