UNPKG

hataraku

Version:

An autonomous coding agent for building AI-powered development tools. The name "Hataraku" (働く) means "to work" in Japanese.

144 lines 5.4 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.showImageTool = void 0; const zod_1 = require("zod"); const path = __importStar(require("path")); const fs = __importStar(require("fs/promises")); const os_1 = require("os"); const child_process_1 = require("child_process"); // Supported image formats const SUPPORTED_FORMATS = ['.png', '.jpg', '.jpeg', '.gif', '.bmp', '.webp']; // Platform-specific open command /** * Returns the platform-specific command to open an image file * * @param imagePath - The absolute path to the image file * @returns The command string to execute for opening the image * @throws Will throw an error if the current platform is not supported */ function getOpenCommand(imagePath) { switch ((0, os_1.platform)()) { case 'win32': return `start "" "${imagePath}"`; case 'darwin': return `open "${imagePath}"`; case 'linux': return `xdg-open "${imagePath}"`; default: throw new Error(`Unsupported platform: ${(0, os_1.platform)()}`); } } /** * Tool for displaying image files using the system's default image viewer. * * @example * ```typescript * // Display an image file * await showImageTool.execute({ path: './images/example.png' }); * ``` * * @throws Will throw an error if the platform is not supported * @throws Will return an error object if the file doesn't exist or has an unsupported format */ exports.showImageTool = { description: "Display an image file using the system's default image viewer.", parameters: zod_1.z.object({ path: zod_1.z.string().describe('The path to the image file to display') }), execute: async ({ path: imagePath }) => { try { const absolutePath = path.resolve(process.cwd(), imagePath); // Check if file exists try { await fs.access(absolutePath); } catch { return { isError: true, content: [{ type: "text", text: `Image file not found at path: ${imagePath}` }] }; } // Check file format const ext = path.extname(absolutePath).toLowerCase(); if (!SUPPORTED_FORMATS.includes(ext)) { return { isError: true, content: [{ type: "text", text: `Unsupported image format: ${ext}. Supported formats: ${SUPPORTED_FORMATS.join(', ')}` }] }; } // Get the platform-specific open command const command = getOpenCommand(absolutePath); // Execute the command return new Promise((resolve) => { (0, child_process_1.exec)(command, (error) => { if (error) { resolve({ isError: true, content: [{ type: "text", text: `Error displaying image: ${error.message}` }] }); } else { resolve({ content: [{ type: "text", text: `Displaying image: ${imagePath}` }] }); } }); }); } catch (error) { return { isError: true, content: [{ type: "text", text: `Error displaying image: ${error instanceof Error ? error.message : String(error)}` }] }; } } }; //# sourceMappingURL=show-image.js.map