UNPKG

ravendb

Version:
61 lines 2.31 kB
import { AddOrUpdateAiAgentOperation, DeleteAiAgentOperation, GetAiAgentsOperation } from "./Agents/index.js"; import { StringUtil } from "../../../Utility/StringUtil.js"; import { AiConversation } from "./AiConversation.js"; export class AiOperations { _store; _databaseName; _executor; /** * Initializes a new instance of AiOperations for a given document store and optional database name. */ constructor(store, databaseName) { this._store = store; this._databaseName = databaseName || store.database; this._executor = this._store.maintenance.forDatabase(this._databaseName); } /** * Returns an AiOperations instance for a different database. */ forDatabase(databaseName) { if (StringUtil.equalsIgnoreCase(this._databaseName, databaseName)) { return this; } return new AiOperations(this._store, databaseName); } /** * Creates or updates an AI agent configuration (with the given schema) on the database. */ async createAgent(configuration, sampleObject) { const operation = new AddOrUpdateAiAgentOperation(configuration, sampleObject); return await this._executor.send(operation); } /** * Retrieves the AI agent configuration for a specific agent. */ async getAgent(agentId) { const operation = new GetAiAgentsOperation(agentId); const response = await this._executor.send(operation); return response.aiAgents && response.aiAgents.length > 0 ? response.aiAgents[0] : null; } /** * Retrieves all AI agents and their configurations. */ async getAgents() { const operation = new GetAiAgentsOperation(); return await this._executor.send(operation); } /** * Deletes an AI agent configuration. */ async deleteAgent(identifier) { const operation = new DeleteAiAgentOperation(identifier); return await this._executor.send(operation); } /** * Opens an AI conversation for an agent. */ conversation(agentId, conversationId, creationOptions, changeVector) { return new AiConversation(this._store, this._databaseName, agentId, conversationId, creationOptions, changeVector); } } //# sourceMappingURL=AiOperations.js.map