hataraku
Version:
An autonomous coding agent for building AI-powered development tools. The name "Hataraku" (働く) means "to work" in Japanese.
83 lines • 2.66 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Task = void 0;
exports.createTask = createTask;
exports.createStringTask = createStringTask;
const zod_1 = require("zod");
class Task {
name;
description;
agent;
inputSchema;
outputSchema;
task;
constructor(config) {
this.validateConfig(config);
this.name = config.name;
this.description = config.description;
this.agent = config.agent;
this.inputSchema = config.inputSchema ?? zod_1.z.string();
this.outputSchema = config.outputSchema;
this.task = config.task;
}
validateConfig(config) {
if (!config.name || config.name.trim() === '') {
throw new Error('Task name cannot be empty');
}
if (!config.description || config.description.trim() === '') {
throw new Error('Task description cannot be empty');
}
if (!config.agent) {
throw new Error('Task must have an agent');
}
if (!config.task) {
throw new Error('Task must have a task definition');
}
}
getTaskPrompt(input) {
if (typeof this.task === 'string') {
return this.task;
}
return this.task(input);
}
async run(input, options) {
// Validate input against schema
const validInput = await this.inputSchema.parseAsync(input);
// Generate prompt with validated input
const prompt = this.getTaskPrompt(validInput);
if (options?.stream) {
return this.agent.task(prompt, { stream: true, thread: options.thread, verbose: options.verbose, model: options.model });
}
if (this.outputSchema) {
const result = await this.agent.task(prompt, { schema: this.outputSchema, thread: options?.thread, verbose: options?.verbose, model: options?.model });
return result;
}
return this.agent.task(prompt, { thread: options?.thread, verbose: options?.verbose, model: options?.model });
}
/**
* Get information about the task
*/
getInfo() {
return {
name: this.name,
description: this.description
};
}
}
exports.Task = Task;
function createTask(config) {
return new Task({
...config,
inputSchema: config.inputSchema ?? zod_1.z.string()
});
}
/**
* Helper function to create a task that accepts string input
*/
function createStringTask(config) {
return new Task({
...config,
inputSchema: config.inputSchema ?? zod_1.z.string()
});
}
//# sourceMappingURL=task.js.map