diff --git a/src/tools/image.ts b/src/tools/image.ts index 8b0be60..8cb85b4 100644 --- a/src/tools/image.ts +++ b/src/tools/image.ts @@ -31,7 +31,7 @@ export async function imageToolHandler( // Check if this is a screen capture const isScreenCapture = !input.app_target || input.app_target.startsWith("screen:"); let formatWarning: string | undefined; - + // Validate format - if invalid, fall back to PNG const validFormats = ["png", "jpg", "data"]; let effectiveFormat = input.format; @@ -39,7 +39,7 @@ export async function imageToolHandler( logger.warn(`Invalid format '${effectiveFormat}' provided, falling back to PNG`); effectiveFormat = "png"; } - + // Auto-fallback to PNG for screen captures with format 'data' if (isScreenCapture && effectiveFormat === "data") { logger.warn("Screen capture with format 'data' auto-fallback to PNG due to size constraints"); @@ -65,10 +65,10 @@ export async function imageToolHandler( ); const errorMessage = swiftResponse.error?.message || "Unknown error"; const errorDetails = swiftResponse.error?.details; - const fullErrorMessage = errorDetails + const fullErrorMessage = errorDetails ? `${errorMessage}\n${errorDetails}` : errorMessage; - + return { content: [ { @@ -204,7 +204,7 @@ export async function imageToolHandler( summary += `\nAnalysis ${analysisSucceeded ? "succeeded" : "failed/skipped"}.`; } content.push({ type: "text", text: summary }); - + // Add format warning if applicable if (formatWarning) { content.push({ type: "text", text: formatWarning }); diff --git a/src/tools/list.ts b/src/tools/list.ts index 94de8cc..dfd2d41 100644 --- a/src/tools/list.ts +++ b/src/tools/list.ts @@ -121,10 +121,10 @@ export async function listToolHandler( logger.error({ error: swiftResponse.error }, "Swift CLI returned error"); const errorMessage = swiftResponse.error?.message || "Unknown error"; const errorDetails = swiftResponse.error?.details; - const fullErrorMessage = errorDetails + const fullErrorMessage = errorDetails ? `${errorMessage}\n${errorDetails}` : errorMessage; - + return { content: [ { diff --git a/src/types/index.ts b/src/types/index.ts index 66d2fcf..446e5b3 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -138,7 +138,9 @@ export const imageToolSchema = z.object({ format: z.preprocess( (val) => { // Handle null, undefined, or empty string by returning undefined (will use default) - if (val === null || val === undefined || val === "") return undefined; + if (val === null || val === undefined || val === "") { + return undefined; + } // If the value is not a valid format, fall back to 'png' const validFormats = ["png", "jpg", "data"]; return validFormats.includes(val as string) ? val : "png";