@iucteam/lot-agents
Version:
Agents for lot agentic framework
57 lines • 2.75 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.HttpPost = 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 POST request to a resource using fetch.
* Name and description can be customised, by default are respectively set to:
* 'httpPost' and 'allows to execute HTTP POST request toward a resource identified via the url property'
*
* To customise the behaviour override the HttpPost#use method
*/
class HttpPost 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: 'POST', body: JSON.stringify(inputs.body), 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(),
body: zod_1.z.any().describe('the payload to be sent as part of the HTTP request').readonly(),
headers: zod_1.z.any().describe('the HTTP headers to be sent').readonly().optional()
})));
}
getAgentCapabilities() {
return [];
}
}
exports.HttpPost = HttpPost;
tslib_1.__decorate([
(0, Validator_1.Validator)({
validator: Validators_1.definedTaskInputValidator,
message: 'task inputs must be defined for HttpPost sensor'
}),
tslib_1.__metadata("design:type", Function),
tslib_1.__metadata("design:paramtypes", [lot_1.Task]),
tslib_1.__metadata("design:returntype", Promise)
], HttpPost.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)
], HttpPost.prototype, "getSchema", null);
//# sourceMappingURL=HttpPost.js.map