From 4be8c69e770ca64f9a3644228529a9cb58292cab Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 27 May 2025 01:10:35 +0200 Subject: [PATCH] Fix TypeScript compilation errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added missing imports for ToolResponse and z in index.ts - Added missing imports for WindowInfo and TargetApplicationInfo in list.ts - Fixed type casting for ImageCaptureData in image.ts - Added proper return type annotations to handlers - Fixed content array metadata type to Record - Added const assertions for all 'text' type literals - Fixed return types for helper functions in list.ts - Added minItems and maxItems to JSONSchema interface All TypeScript compilation errors resolved 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/index.ts | 6 ++++-- src/tools/analyze.ts | 22 +++++++++++----------- src/tools/image.ts | 11 ++++++----- src/tools/list.ts | 27 +++++++++++++++------------ src/utils/zod-to-json-schema.ts | 2 ++ 5 files changed, 38 insertions(+), 30 deletions(-) diff --git a/src/index.ts b/src/index.ts index 65becc9..caef1d3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -23,6 +23,8 @@ import { import { generateServerStatusString } from "./utils/server-status.js"; import { initializeSwiftCliPath } from "./utils/peekaboo-cli.js"; import { zodToJsonSchema } from "./utils/zod-to-json-schema.js"; +import { ToolResponse } from "./types/index.js"; +import { z } from "zod"; // Get package version and determine package root const __filename = fileURLToPath(import.meta.url); @@ -215,12 +217,12 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => { return { content: [ { - type: "text", + type: "text" as const, text: `Invalid arguments: ${(error as z.ZodError).issues.map((issue) => issue.message).join(", ")}`, }, ], isError: true, - }; + } as ToolResponse; } throw error; diff --git a/src/tools/analyze.ts b/src/tools/analyze.ts index bcb0307..f45c374 100644 --- a/src/tools/analyze.ts +++ b/src/tools/analyze.ts @@ -1,6 +1,6 @@ import { z } from "zod"; import path from "path"; -import { ToolContext } from "../types/index.js"; +import { ToolContext, ToolResponse } from "../types/index.js"; import { readImageAsBase64 } from "../utils/peekaboo-cli.js"; import { parseAIProviders, @@ -43,7 +43,7 @@ export type AnalyzeToolInput = z.infer; export async function analyzeToolHandler( input: AnalyzeToolInput, context: ToolContext, -) { +): Promise { const { logger } = context; try { @@ -58,7 +58,7 @@ export async function analyzeToolHandler( return { content: [ { - type: "text", + type: "text" as const, text: `Unsupported image format: ${ext}. Supported formats: .png, .jpg, .jpeg, .webp`, }, ], @@ -73,7 +73,7 @@ export async function analyzeToolHandler( return { content: [ { - type: "text", + type: "text" as const, text: "AI analysis not configured on this server. Set the PEEKABOO_AI_PROVIDERS environment variable.", }, ], @@ -87,7 +87,7 @@ export async function analyzeToolHandler( return { content: [ { - type: "text", + type: "text" as const, text: "No valid AI providers found in PEEKABOO_AI_PROVIDERS configuration.", }, ], @@ -106,7 +106,7 @@ export async function analyzeToolHandler( return { content: [ { - type: "text", + type: "text" as const, text: "No configured AI providers are currently operational.", }, ], @@ -126,7 +126,7 @@ export async function analyzeToolHandler( return { content: [ { - type: "text", + type: "text" as const, text: `Failed to read image file: ${error instanceof Error ? error.message : "Unknown error"}`, }, ], @@ -150,7 +150,7 @@ export async function analyzeToolHandler( return { content: [ { - type: "text", + type: "text" as const, text: `AI analysis failed: ${error instanceof Error ? error.message : "Unknown error"}`, }, ], @@ -170,11 +170,11 @@ export async function analyzeToolHandler( return { content: [ { - type: "text", + type: "text" as const, text: analysisResult, }, { - type: "text", + type: "text" as const, text: analysisTimeMessage, // Add the timing message }, ], @@ -186,7 +186,7 @@ export async function analyzeToolHandler( return { content: [ { - type: "text", + type: "text" as const, text: `Unexpected error: ${error instanceof Error ? error.message : "Unknown error"}`, }, ], diff --git a/src/tools/image.ts b/src/tools/image.ts index 34b9823..cc0b161 100644 --- a/src/tools/image.ts +++ b/src/tools/image.ts @@ -73,10 +73,11 @@ export async function imageToolHandler( }; } + const imageData = swiftResponse.data as ImageCaptureData | undefined; if ( - !swiftResponse.data || - !swiftResponse.data.saved_files || - swiftResponse.data.saved_files.length === 0 + !imageData || + !imageData.saved_files || + imageData.saved_files.length === 0 ) { logger.error( "Swift CLI reported success but no data/saved_files were returned.", @@ -93,7 +94,7 @@ export async function imageToolHandler( }; } - const captureData = swiftResponse.data as ImageCaptureData; + const captureData = imageData; const imagePathForAnalysis = captureData.saved_files[0].path; // Determine which files to report as saved @@ -150,7 +151,7 @@ export async function imageToolHandler( } } - const content: Array<{ type: "text" | "image"; text?: string; data?: string; mimeType?: string; metadata?: unknown }> = []; + const content: Array<{ type: "text" | "image"; text?: string; data?: string; mimeType?: string; metadata?: Record }> = []; let summary = buildImageSummary(input, captureData, input.question); if (analysisAttempted) { summary += `\nAnalysis ${analysisSucceeded ? "succeeded" : "failed/skipped"}.`; diff --git a/src/tools/list.ts b/src/tools/list.ts index bc2d10d..11cb238 100644 --- a/src/tools/list.ts +++ b/src/tools/list.ts @@ -4,7 +4,10 @@ import { ApplicationListData, WindowListData, ApplicationInfo, + WindowInfo, + TargetApplicationInfo, SwiftCliResponse, + ToolResponse, } from "../types/index.js"; import { executeSwiftCli, execPeekaboo } from "../utils/peekaboo-cli.js"; import { generateServerStatusString } from "../utils/server-status.js"; @@ -83,7 +86,7 @@ export type ListToolInput = z.infer; export async function listToolHandler( input: ListToolInput, context: ToolContext, -) { +): Promise { const { logger } = context; try { @@ -114,7 +117,7 @@ export async function listToolHandler( return { content: [ { - type: "text", + type: "text" as const, text: `List operation failed: ${swiftResponse.error?.message || "Unknown error"}`, }, ], @@ -131,7 +134,7 @@ export async function listToolHandler( return { content: [ { - type: "text", + type: "text" as const, text: "List operation failed: Invalid response from list utility (no data).", }, ], @@ -160,7 +163,7 @@ export async function listToolHandler( return { content: [ { - type: "text", + type: "text" as const, text: "List operation completed with unknown item type.", }, ], @@ -170,7 +173,7 @@ export async function listToolHandler( return { content: [ { - type: "text", + type: "text" as const, text: `Unexpected error: ${error instanceof Error ? error.message : "Unknown error"}`, }, ], @@ -183,7 +186,7 @@ async function handleServerStatus( version: string, packageRootDir: string, logger: Logger, -): Promise<{ content: { type: string; text: string }[] }> { +): Promise { const statusSections: string[] = []; // 1. Server version and AI providers @@ -327,7 +330,7 @@ async function handleServerStatus( return { content: [ { - type: "text", + type: "text" as const, text: fullStatus, }, ], @@ -357,7 +360,7 @@ export function buildSwiftCliArgs(input: ListToolInput): string[] { function handleApplicationsList( data: ApplicationListData, swiftResponse: SwiftCliResponse, -): { content: { type: string; text: string }[]; application_list: ApplicationInfo[] } { +): ToolResponse & { application_list: ApplicationInfo[] } { const apps = data.applications || []; let summary = `Found ${apps.length} running application${apps.length !== 1 ? "s" : ""}`; @@ -385,7 +388,7 @@ function handleApplicationsList( return { content: [ { - type: "text", + type: "text" as const, text: summary, }, ], @@ -399,7 +402,7 @@ function handleWindowsList( swiftResponse: SwiftCliResponse, ): ToolResponse & { window_list?: WindowInfo[]; - target_application_info?: ApplicationInfo; + target_application_info?: TargetApplicationInfo; } { const windows = data.windows || []; const appInfo = data.target_application_info; @@ -409,7 +412,7 @@ function handleWindowsList( return { content: [ { - type: "text", + type: "text" as const, text: "List operation failed: Invalid response from list utility (missing application info).", }, ], @@ -456,7 +459,7 @@ function handleWindowsList( return { content: [ { - type: "text", + type: "text" as const, text: summary, }, ], diff --git a/src/utils/zod-to-json-schema.ts b/src/utils/zod-to-json-schema.ts index 600fcd4..aa5d7d8 100644 --- a/src/utils/zod-to-json-schema.ts +++ b/src/utils/zod-to-json-schema.ts @@ -34,6 +34,8 @@ interface JSONSchema { maximum?: number; minLength?: number; maxLength?: number; + minItems?: number; + maxItems?: number; pattern?: string; format?: string; $ref?: string;