hataraku
Version:
An autonomous coding agent for building AI-powered development tools. The name "Hataraku" (働く) means "to work" in Japanese.
111 lines • 4.43 kB
JavaScript
;
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.playAudioTool = void 0;
const zod_1 = require("zod");
const path = __importStar(require("path"));
const fs = __importStar(require("fs/promises"));
const sound = __importStar(require("sound-play"));
// Supported audio formats
const SUPPORTED_FORMATS = ['.mp3', '.wav', '.ogg', '.aac', '.m4a'];
exports.playAudioTool = {
description: "Play an audio file or speak text using text-to-speech.",
parameters: zod_1.z.object({
path: zod_1.z.string().describe('The path to the audio file to play'),
}),
execute: async ({ path: audioPath }) => {
try {
// Handle audio file playback
if (audioPath) {
const absolutePath = path.resolve(process.cwd(), audioPath);
// Check if file exists
try {
await fs.access(absolutePath);
}
catch {
return {
isError: true,
content: [{
type: "text",
text: `Audio file not found at path: ${audioPath}`
}]
};
}
// Check file format
const ext = path.extname(absolutePath).toLowerCase();
if (!SUPPORTED_FORMATS.includes(ext)) {
return {
isError: true,
content: [{
type: "text",
text: `Unsupported audio format: ${ext}. Supported formats: ${SUPPORTED_FORMATS.join(', ')}`
}]
};
}
// Play the audio file
const soundPromise = sound.play(absolutePath);
// Set a timeout to ensure the sound handle is cleaned up
const timeoutPromise = new Promise((resolve) => {
setTimeout(resolve, 1000); // Wait 1 second for the sound to start
});
// Wait for either the sound to finish or the timeout
await Promise.race([soundPromise, timeoutPromise]);
return {
content: [{
type: "text",
text: `Playing audio file: ${audioPath}`
}]
};
}
return {
isError: true,
content: [{
type: "text",
text: "Either path or text must be provided"
}]
};
}
catch (error) {
return {
isError: true,
content: [{
type: "text",
text: `Error playing audio: ${error instanceof Error ? error.message : String(error)}`
}]
};
}
}
};
//# sourceMappingURL=play-audio.js.map