import { CloseBotClient, err } from "../client.js"; import type { ToolDefinition, ToolResult, FileDto } from "../types.js"; export const tools: ToolDefinition[] = [ { name: "library_manager_app", description: "Knowledge base library viewer showing files with type icons, source attachments, scrape status, and size. Returns HTML visualization.", inputSchema: { type: "object", properties: { fileId: { type: "string", description: "Optional: show detail for a specific file including scrape pages" }, }, }, }, ]; function escapeHtml(s: string): string { return s.replace(/&/g, "&").replace(//g, ">").replace(/"/g, """); } function fileIcon(fileType: string | null | undefined): string { const t = (fileType || "").toLowerCase(); if (t.includes("pdf")) return "๐"; if (t.includes("doc") || t.includes("word")) return "๐"; if (t.includes("csv") || t.includes("excel") || t.includes("spreadsheet")) return "๐"; if (t.includes("image") || t.includes("png") || t.includes("jpg")) return "๐ผ๏ธ"; if (t.includes("webscrape") || t.includes("web") || t.includes("html")) return "๐"; if (t.includes("text") || t.includes("txt")) return "๐"; if (t.includes("json")) return "๐ง"; return "๐"; } function formatSize(bytes: number): string { if (bytes < 1024) return `${bytes} B`; if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`; return `${(bytes / (1024 * 1024)).toFixed(1)} MB`; } function statusBadge(status: string | null | undefined): string { const s = (status || "").toLowerCase(); if (s === "ready" || s === "completed" || s === "processed") return 'โ Ready'; if (s === "processing" || s === "pending") return 'โณ Processing'; if (s === "error" || s === "failed") return 'โ Error'; return `${escapeHtml(status || "Unknown")}`; } function renderFileList(files: FileDto[]): string { const totalSize = files.reduce((sum, f) => sum + (f.fileSize || 0), 0); const rows = files .map((f) => { const icon = fileIcon(f.fileType); const sources = (f.sources || []) .map( (s) => `${escapeHtml(s.name || s.id || "")}` ) .join(" "); const modified = f.lastModified ? new Date(f.lastModified).toLocaleDateString() : "โ"; return `
upload_file to upload, create_web_scrape to scrape websites, attach_file_to_source to connect to sources