@n1k1t/unit-generator
Version:
Coverage based unit tests AI generator
75 lines • 2.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LlmToolCompiler = exports.LlmToolExecutionError = exports.LlmToolCompilationError = void 0;
const ai_1 = require("ai");
const bash_1 = require("../../bash");
class LlmToolCompilationError extends Error {
constructor(property) {
super(`Cannot compile without [${property}] property`);
this.property = property;
}
}
exports.LlmToolCompilationError = LlmToolCompilationError;
class LlmToolExecutionError extends Error {
constructor(name, reason) {
super(`Execution of [${name}] has failed: ${reason}`);
this.name = name;
}
static build(name, source) {
const reason = source instanceof bash_1.BashExecError
? source.stderr
: source instanceof Error
? source.message
: Array.isArray(source)
? source.join('. ')
: String(source);
return new LlmToolExecutionError(name, reason);
}
}
exports.LlmToolExecutionError = LlmToolExecutionError;
class LlmToolCompiler {
constructor(description, provided) {
this.description = description;
this.provided = provided;
}
input(schema) {
this.provided.schema.input = schema;
return this;
}
output(schema) {
this.provided.schema.output = schema;
return this;
}
/** Provides options to tool (makes clone of this instance) */
options(payload) {
const clone = new LlmToolCompiler(this.description, {
executor: this.provided.executor,
schema: this.provided.schema,
options: payload,
});
return clone;
}
execute(executor) {
this.provided.executor = executor;
return this;
}
compile(parameters) {
if (!this.provided.executor) {
throw new LlmToolCompilationError('executor');
}
return (0, ai_1.tool)({
description: this.description,
execute: this.provided.executor({
options: this.provided.options ?? {},
project: parameters.project,
}),
inputSchema: this.provided.schema.input,
outputSchema: this.provided.schema.output,
});
}
static build(description) {
return new LlmToolCompiler(description, { schema: {} });
}
}
exports.LlmToolCompiler = LlmToolCompiler;
//# sourceMappingURL=model.js.map