ravendb
Version:
RavenDB client for Node.js
78 lines • 3.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AddOrUpdateAiAgentOperation = void 0;
const RavenCommand_js_1 = require("../../../../Http/RavenCommand.js");
const RaftIdGenerator_js_1 = require("../../../../Utility/RaftIdGenerator.js");
const index_js_1 = require("../../../../Exceptions/index.js");
const HttpUtil_js_1 = require("../../../../Utility/HttpUtil.js");
function hasNoSampleObjectAndSchema(configuration) {
return (!configuration.outputSchema || configuration.outputSchema.trim() === "")
&& (!configuration.sampleObject || configuration.sampleObject.trim() === "");
}
class AddOrUpdateAiAgentOperation {
_configuration;
_sampleObject;
constructor(configuration, sampleObject) {
if (!configuration) {
(0, index_js_1.throwError)("InvalidArgumentException", "configuration cannot be null or undefined.");
}
if (hasNoSampleObjectAndSchema(configuration) && !sampleObject) {
(0, index_js_1.throwError)("InvalidArgumentException", "Please provide a non-empty value for either outputSchema or sampleObject.");
}
this._configuration = configuration;
if (sampleObject) {
this._sampleObject = sampleObject;
}
}
get resultType() {
return "CommandResult";
}
getCommand(conventions) {
return new AddOrUpdateAiAgentCommand(this._configuration, this._sampleObject, conventions);
}
}
exports.AddOrUpdateAiAgentOperation = AddOrUpdateAiAgentOperation;
class AddOrUpdateAiAgentCommand extends RavenCommand_js_1.RavenCommand {
_configuration;
_conventions;
_sampleSchema;
constructor(configuration, sampleSchema, conventions) {
super();
if (hasNoSampleObjectAndSchema(configuration)) {
(0, index_js_1.throwError)("InvalidArgumentException", "Please provide a non-empty value for either outputSchema or sampleObject.");
}
this._configuration = configuration;
this._sampleSchema = sampleSchema;
this._conventions = conventions;
}
get isReadRequest() {
return false;
}
getRaftUniqueRequestId() {
return RaftIdGenerator_js_1.RaftIdGenerator.newId();
}
createRequest(node) {
const uri = node.url + "/databases/" + node.database + "/admin/ai/agent";
if (!this._configuration && this._sampleSchema) {
this._configuration.sampleObject = this._sampleSchema;
}
const body = this._serializer.serialize(this._configuration);
const headers = HttpUtil_js_1.HeadersBuilder
.create()
.typeAppJson()
.build();
return {
method: "PUT",
uri,
body,
headers
};
}
async setResponseAsync(bodyStream, fromCache) {
if (!bodyStream) {
this._throwInvalidResponse();
}
return this._parseResponseDefaultAsync(bodyStream);
}
}
//# sourceMappingURL=AddOrUpdateAiAgentOperation.js.map