Peekaboo/src/utils/image-summary.ts
Peter Steinberger 44364221d6 Complete MCP best practices compliance and code cleanup
- Fix all critical ESLint errors (unused variables, wrong types)
- Split image.ts into smaller modules for better maintainability:
  - image-analysis.ts: AI provider analysis logic
  - image-summary.ts: Summary text generation
  - image-cli-args.ts: Swift CLI argument building
- Reduce image.ts from 472 to 246 lines
- Add proper TypeScript types throughout (reduce 'any' usage)
- Fix logger type imports and use proper Pino Logger type
- Update ESLint to ignore test files (handled by vitest)
- Clean up all trailing spaces and formatting issues
- Export buildSwiftCliArgs for test compatibility

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-05-27 00:32:54 +02:00

64 lines
No EOL
2 KiB
TypeScript

import { ImageInput, ImageCaptureData } from "../types/index.js";
export function buildImageSummary(
input: ImageInput,
data: ImageCaptureData,
question?: string,
): string {
if (
!data.saved_files ||
data.saved_files.length === 0 ||
!(input.question && data.saved_files && data.saved_files.length > 0)
) {
return "Image capture completed but no files were saved or available for analysis.";
}
// Determine mode and target from app_target
let mode = "screen";
let target = "screen";
if (input.app_target) {
if (input.app_target.startsWith("screen:")) {
mode = "screen";
target = input.app_target;
} else if (input.app_target === "frontmost") {
mode = "screen"; // defaulted to screen
target = "frontmost application";
} else if (input.app_target.includes(":")) {
// Contains window specifier
const parts = input.app_target.split(":");
target = parts[0]; // app name
mode = "window";
} else {
// Just app name, all windows
target = input.app_target;
mode = "all windows";
}
}
let summary = `Image captured successfully for ${target}`;
if (mode !== "screen") {
summary += ` (${mode})`;
}
if (data.saved_files.length === 1) {
if (!question || (question && input.path)) {
// Show path if no question or if question with explicit path
summary += `\nImage saved to: ${data.saved_files[0].path}`;
}
} else if (data.saved_files.length > 1) {
summary += `\n${data.saved_files.length} images saved:`;
data.saved_files.forEach((file, index) => {
summary += `\n${index + 1}. ${file.path}`;
if (file.item_label) {
summary += ` (${file.item_label})`;
}
});
} else if (input.question && input.path && data.saved_files?.length) {
summary += `\nImage saved to: ${data.saved_files[0].path}`;
} else if (input.question && data.saved_files?.length) {
summary += "\nImage captured to temporary location for analysis.";
}
return summary;
}