import * as fs from "fs";
import * as path from "path";
export const pptReader = {
name: "read_presentation",
description: "Read and extract content from PowerPoint presentations",
parameters: {
type: "object",
properties: {
file_path: {
type: "string",
description: "Path to the PowerPoint file to read"
},
output_format: {
type: "string",
description: "Output format for the content",
enum: ["text", "json", "markdown"],
default: "text"
},
slide_range: {
type: "object",
description: "Range of slides to read (optional)",
properties: {
start: { type: "number", description: "Start slide number (1-based)" },
end: { type: "number", description: "End slide number (1-based)" }
}
},
include_notes: {
type: "boolean",
description: "Whether to include speaker notes",
default: false
}
},
required: ["file_path"]
},
async run(args: { file_path: string; output_format?: string; slide_range?: { start?: number; end?: number }; include_notes?: boolean }) {
try {
// Parameter validation
if (!args.file_path) {
throw new Error("File path is required");
}
if (!fs.existsSync(args.file_path)) {
throw new Error(`File not found: ${args.file_path}`);
}
// Note: PptxGenJS doesn't support reading existing PowerPoint files
// This is a limitation of the library - it's primarily for creation, not reading
// For reading PPT files, we'd need a different library like 'officegen' or 'node-pptx'
const fileStats = fs.statSync(args.file_path);
const fileName = path.basename(args.file_path);
const fileSize = (fileStats.size / 1024).toFixed(2); // KB
return {
content: [{
type: "text",
text: `β οΈ **Read Operation Not Fully Supported**\n\n` +
`Unfortunately, PptxGenJS doesn't support reading existing PowerPoint files. ` +
`This is a current limitation of the library.\n\n` +
`**File Information:**\n` +
`π **Name:** ${fileName}\n` +
`π **Path:** ${args.file_path}\n` +
`π **Size:** ${fileSize} KB\n` +
`π
**Modified:** ${fileStats.mtime.toLocaleString()}\n\n` +
`**Alternative approaches:**\n` +
`β’ Use Microsoft PowerPoint to view the content\n` +
`β’ Convert to PDF and use PDF reading tools\n` +
`β’ Use online PowerPoint viewers\n` +
`β’ Consider using a different library like 'mammoth' for basic text extraction\n\n` +
`**Requested format:** ${args.output_format || 'text'}\n` +
`**Include notes:** ${args.include_notes ? 'Yes' : 'No'}`
}]
};
} catch (error) {
return {
content: [{
type: "text",
text: `β **Failed to read presentation:** ${error instanceof Error ? error.message : String(error)}`
}],
isError: true
};
}
}
};
export const pptAnalyzer = {
name: "analyze_presentation",
description: "Analyze PowerPoint presentation structure, content, and provide insights",
parameters: {
type: "object",
properties: {
file_path: {
type: "string",
description: "Path to the PowerPoint file to analyze"
},
analysis_type: {
type: "string",
description: "Type of analysis to perform",
enum: ["structure", "content", "statistics", "readability", "comprehensive"],
default: "comprehensive"
},
detailed: {
type: "boolean",
description: "Whether to provide detailed analysis",
default: true
}
},
required: ["file_path"]
},
async run(args: { file_path: string; analysis_type?: string; detailed?: boolean }) {
try {
// Parameter validation
if (!args.file_path) {
throw new Error("File path is required");
}
if (!fs.existsSync(args.file_path)) {
throw new Error(`File not found: ${args.file_path}`);
}
const analysisType = args.analysis_type || "comprehensive";
const detailed = args.detailed !== false;
// Basic file analysis
const fileStats = fs.statSync(args.file_path);
const fileName = path.basename(args.file_path);
const fileSize = (fileStats.size / 1024).toFixed(2); // KB
const fileExtension = path.extname(args.file_path).toLowerCase();
// Validate file type
if (!['.pptx', '.ppt'].includes(fileExtension)) {
throw new Error(`Unsupported file type: ${fileExtension}. Only .pptx and .ppt files are supported.`);
}
// Generate mock analysis since we can't actually read the file content
const analysis = generateMockAnalysis(fileName, fileSize, analysisType, detailed);
return {
content: [{
type: "text",
text: `π **Presentation Analysis Report**\n\n` +
`**File Information:**\n` +
`π **Name:** ${fileName}\n` +
`π **Path:** ${args.file_path}\n` +
`π **Size:** ${fileSize} KB\n` +
`π
**Modified:** ${fileStats.mtime.toLocaleString()}\n` +
`π§ **Format:** ${fileExtension.toUpperCase()}\n\n` +
`β οΈ **Note:** This is a basic file system analysis. ` +
`For detailed content analysis, PptxGenJS doesn't support reading existing files.\n\n` +
analysis
}]
};
} catch (error) {
return {
content: [{
type: "text",
text: `β **Analysis failed:** ${error instanceof Error ? error.message : String(error)}`
}],
isError: true
};
}
}
};
// Helper function to generate mock analysis
function generateMockAnalysis(fileName: string, fileSize: string, analysisType: string, detailed: boolean): string {
let analysis = "";
switch (analysisType) {
case "structure":
analysis = `**π Structure Analysis:**\n` +
`β’ File appears to be a valid PowerPoint presentation\n` +
`β’ Size suggests ${estimateSlideCount(fileSize)} slides approximately\n` +
`β’ Standard OOXML format detected\n`;
break;
case "content":
analysis = `**π Content Analysis:**\n` +
`β’ Content analysis requires reading file internals\n` +
`β’ Current library limitation prevents detailed content extraction\n` +
`β’ Recommend using PowerPoint or compatible viewer for content review\n`;
break;
case "statistics":
analysis = `**π File Statistics:**\n` +
`β’ File size: ${fileSize} KB\n` +
`β’ Estimated complexity: ${getComplexityEstimate(fileSize)}\n` +
`β’ Format compatibility: Modern PowerPoint (.pptx)\n`;
break;
case "readability":
analysis = `**ποΈ Readability Analysis:**\n` +
`β’ Readability analysis requires text content extraction\n` +
`β’ Cannot perform without reading slide content\n` +
`β’ Recommend manual review for readability assessment\n`;
break;
default: // comprehensive
analysis = `**π Comprehensive Analysis:**\n\n` +
`**File Properties:**\n` +
`β’ Valid PowerPoint format: β
\n` +
`β’ File size: ${fileSize} KB\n` +
`β’ Estimated slides: ${estimateSlideCount(fileSize)}\n` +
`β’ Complexity level: ${getComplexityEstimate(fileSize)}\n\n` +
`**Limitations:**\n` +
`β’ Content extraction: β (Library limitation)\n` +
`β’ Text analysis: β (Requires content access)\n` +
`β’ Image detection: β (Requires file parsing)\n` +
`β’ Slide structure: β (Requires OOXML parsing)\n\n` +
`**Recommendations:**\n` +
`β’ Use PowerPoint for detailed content review\n` +
`β’ Consider converting to PDF for text extraction\n` +
`β’ Use specialized PPT parsing libraries for advanced analysis\n`;
break;
}
if (detailed) {
analysis += `\n**π§ Technical Details:**\n` +
`β’ Library: PptxGenJS (Creation-focused)\n` +
`β’ Reading capability: Limited\n` +
`β’ Recommended alternatives: mammoth, officegen, or native PowerPoint API\n`;
}
return analysis;
}
// Helper functions
function estimateSlideCount(fileSizeKB: string): string {
const size = parseFloat(fileSizeKB);
if (size < 100) return "1-5";
if (size < 500) return "5-15";
if (size < 1000) return "15-30";
if (size < 2000) return "30-50";
return "50+";
}
function getComplexityEstimate(fileSizeKB: string): string {
const size = parseFloat(fileSizeKB);
if (size < 200) return "Low (mostly text)";
if (size < 1000) return "Medium (text + images)";
if (size < 3000) return "High (rich media)";
return "Very High (complex multimedia)";
}