ravendb
Version:
RavenDB client for Node.js
74 lines • 2.75 kB
JavaScript
import { RavenCommand } from "../../../../Http/RavenCommand.js";
import { RaftIdGenerator } from "../../../../Utility/RaftIdGenerator.js";
import { throwError } from "../../../../Exceptions/index.js";
import { HeadersBuilder } from "../../../../Utility/HttpUtil.js";
function hasNoSampleObjectAndSchema(configuration) {
return (!configuration.outputSchema || configuration.outputSchema.trim() === "")
&& (!configuration.sampleObject || configuration.sampleObject.trim() === "");
}
export class AddOrUpdateAiAgentOperation {
_configuration;
_sampleObject;
constructor(configuration, sampleObject) {
if (!configuration) {
throwError("InvalidArgumentException", "configuration cannot be null or undefined.");
}
if (hasNoSampleObjectAndSchema(configuration) && !sampleObject) {
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);
}
}
class AddOrUpdateAiAgentCommand extends RavenCommand {
_configuration;
_conventions;
_sampleSchema;
constructor(configuration, sampleSchema, conventions) {
super();
if (hasNoSampleObjectAndSchema(configuration)) {
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.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 = 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