UNPKG

@iucteam/lot-agents

Version:

Agents for lot agentic framework

54 lines 2.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FileReader = void 0; const tslib_1 = require("tslib"); const lot_1 = require("@iucteam/lot"); const node_fs_1 = tslib_1.__importDefault(require("node:fs")); const zod_1 = require("zod"); const zod_to_json_schema_1 = tslib_1.__importDefault(require("zod-to-json-schema")); const NoOpBrain_1 = require("../../brains/NoOpBrain"); const Validator_1 = require("../../decorators/Validator"); const Validators_1 = require("../../Validators"); class FileReader extends lot_1.Sensor { constructor(config, brain = new NoOpBrain_1.NoOpBrain()) { // name: string = 'fileReader', description: string = 'Allows to read files from the local file system', brain: Brain = new NoOpBrain() super(config.name, config.description, brain); } /** * Allows to read a file from the local file-systems using its absolute path * @param input the path of the file to read as a {path: 'absolute file path'} * @returns the content of the read file as {'content': 'the content'} */ async detect(task) { const inputs = task.getTaskInputs(); const content = node_fs_1.default.readFileSync(inputs.path).toString(); const instruction = new lot_1.Instruction(lot_1.SimpleRequirement.from(content), new lot_1.Context(), {}, this.getExpectation(), this.getDescriptor()); const thought = await this.brain.evaluate(instruction); return [new lot_1.Inference(thought.getContent(), 1).addSources([inputs.path])]; } getSchema() { return JSON.stringify((0, zod_to_json_schema_1.default)(zod_1.z.object({ path: zod_1.z.string().describe('the absolute file-system path of the file that need to be read. Must be provided!') }))); } getAgentCapabilities() { return []; } } exports.FileReader = FileReader; tslib_1.__decorate([ (0, Validator_1.Validator)({ validator: Validators_1.definedTaskInputValidator, message: 'task inputs must be defined for FileReader sensor' }), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", [lot_1.Task]), tslib_1.__metadata("design:returntype", Promise) ], FileReader.prototype, "detect", null); tslib_1.__decorate([ (0, lot_1.Cacheable)({ key: 'httpGetSchema', ttl: Infinity }), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", []), tslib_1.__metadata("design:returntype", String) ], FileReader.prototype, "getSchema", null); //# sourceMappingURL=FileReader.js.map