UNPKG

@iucteam/lot-agents

Version:

Agents for lot agentic framework

56 lines 2.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HttpDelete = void 0; const tslib_1 = require("tslib"); const lot_1 = require("@iucteam/lot"); 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"); /** * A tool able to send HTTP DELETE request to a resource using fetch. * Name and description can be customised, by default are respectively set to: * 'httpDelete' and 'allows to execute HTTP DELETE request toward a resource identified via the url property' * * To customise the behaviour override the HttpDelete#use method */ class HttpDelete extends lot_1.Sensor { constructor(sensorConfig, brain = new NoOpBrain_1.NoOpBrain()) { super(sensorConfig.name, sensorConfig.description, brain); } async detect(task) { const inputs = task.getTaskInputs(); const resp = await fetch(inputs.url, { method: 'DELETE', headers: inputs.headers }); const response = await resp.json(); const instruction = new lot_1.Instruction(lot_1.SimpleRequirement.from(response), 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.url])]; } getSchema() { return JSON.stringify((0, zod_to_json_schema_1.default)(zod_1.z.object({ url: zod_1.z.string().describe('The resource URL as specified by RFC 1738').readonly(), headers: zod_1.z.any().describe('the HTTP headers to be sent').readonly().optional() }))); } getAgentCapabilities() { return []; } } exports.HttpDelete = HttpDelete; tslib_1.__decorate([ (0, Validator_1.Validator)({ validator: Validators_1.definedTaskInputValidator, message: 'task inputs must be defined for HttpDelete sensor' }), tslib_1.__metadata("design:type", Function), tslib_1.__metadata("design:paramtypes", [lot_1.Task]), tslib_1.__metadata("design:returntype", Promise) ], HttpDelete.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) ], HttpDelete.prototype, "getSchema", null); //# sourceMappingURL=HttpDelete.js.map