"use strict";
// This file was auto-generated by Fern from our API Definition.
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConversationalAiClient = void 0;
const BaseClient_1 = require("../../../../BaseClient");
const core = __importStar(require("../../../../core"));
const headers_1 = require("../../../../core/headers");
const environments = __importStar(require("../../../../environments"));
const handleNonStatusCodeError_1 = require("../../../../errors/handleNonStatusCodeError");
const errors = __importStar(require("../../../../errors/index"));
const serializers = __importStar(require("../../../../serialization/index"));
const ElevenLabs = __importStar(require("../../../index"));
const Client_1 = require("../resources/agents/client/Client");
const Client_2 = require("../resources/analytics/client/Client");
const Client_3 = require("../resources/batchCalls/client/Client");
const Client_4 = require("../resources/conversations/client/Client");
const Client_5 = require("../resources/dashboard/client/Client");
const Client_6 = require("../resources/knowledgeBase/client/Client");
const Client_7 = require("../resources/llm/client/Client");
const Client_8 = require("../resources/llmUsage/client/Client");
const Client_9 = require("../resources/mcpServers/client/Client");
const Client_10 = require("../resources/phoneNumbers/client/Client");
const Client_11 = require("../resources/secrets/client/Client");
const Client_12 = require("../resources/settings/client/Client");
const Client_13 = require("../resources/sipTrunk/client/Client");
const Client_14 = require("../resources/tests/client/Client");
const Client_15 = require("../resources/tools/client/Client");
const Client_16 = require("../resources/twilio/client/Client");
const Client_17 = require("../resources/users/client/Client");
const Client_18 = require("../resources/whatsapp/client/Client");
const Client_19 = require("../resources/whatsappAccounts/client/Client");
class ConversationalAiClient {
    constructor(options = {}) {
        this._options = (0, BaseClient_1.normalizeClientOptions)(options);
    }
    get conversations() {
        var _a;
        return ((_a = this._conversations) !== null && _a !== void 0 ? _a : (this._conversations = new Client_4.ConversationsClient(this._options)));
    }
    get twilio() {
        var _a;
        return ((_a = this._twilio) !== null && _a !== void 0 ? _a : (this._twilio = new Client_16.TwilioClient(this._options)));
    }
    get whatsapp() {
        var _a;
        return ((_a = this._whatsapp) !== null && _a !== void 0 ? _a : (this._whatsapp = new Client_18.WhatsappClient(this._options)));
    }
    get agents() {
        var _a;
        return ((_a = this._agents) !== null && _a !== void 0 ? _a : (this._agents = new Client_1.AgentsClient(this._options)));
    }
    get tests() {
        var _a;
        return ((_a = this._tests) !== null && _a !== void 0 ? _a : (this._tests = new Client_14.TestsClient(this._options)));
    }
    get users() {
        var _a;
        return ((_a = this._users) !== null && _a !== void 0 ? _a : (this._users = new Client_17.UsersClient(this._options)));
    }
    get phoneNumbers() {
        var _a;
        return ((_a = this._phoneNumbers) !== null && _a !== void 0 ? _a : (this._phoneNumbers = new Client_10.PhoneNumbersClient(this._options)));
    }
    get llmUsage() {
        var _a;
        return ((_a = this._llmUsage) !== null && _a !== void 0 ? _a : (this._llmUsage = new Client_8.LlmUsageClient(this._options)));
    }
    get llm() {
        var _a;
        return ((_a = this._llm) !== null && _a !== void 0 ? _a : (this._llm = new Client_7.LlmClient(this._options)));
    }
    get knowledgeBase() {
        var _a;
        return ((_a = this._knowledgeBase) !== null && _a !== void 0 ? _a : (this._knowledgeBase = new Client_6.KnowledgeBaseClient(this._options)));
    }
    get tools() {
        var _a;
        return ((_a = this._tools) !== null && _a !== void 0 ? _a : (this._tools = new Client_15.ToolsClient(this._options)));
    }
    get settings() {
        var _a;
        return ((_a = this._settings) !== null && _a !== void 0 ? _a : (this._settings = new Client_12.SettingsClient(this._options)));
    }
    get secrets() {
        var _a;
        return ((_a = this._secrets) !== null && _a !== void 0 ? _a : (this._secrets = new Client_11.SecretsClient(this._options)));
    }
    get batchCalls() {
        var _a;
        return ((_a = this._batchCalls) !== null && _a !== void 0 ? _a : (this._batchCalls = new Client_3.BatchCallsClient(this._options)));
    }
    get sipTrunk() {
        var _a;
        return ((_a = this._sipTrunk) !== null && _a !== void 0 ? _a : (this._sipTrunk = new Client_13.SipTrunkClient(this._options)));
    }
    get mcpServers() {
        var _a;
        return ((_a = this._mcpServers) !== null && _a !== void 0 ? _a : (this._mcpServers = new Client_9.McpServersClient(this._options)));
    }
    get whatsappAccounts() {
        var _a;
        return ((_a = this._whatsappAccounts) !== null && _a !== void 0 ? _a : (this._whatsappAccounts = new Client_19.WhatsappAccountsClient(this._options)));
    }
    get analytics() {
        var _a;
        return ((_a = this._analytics) !== null && _a !== void 0 ? _a : (this._analytics = new Client_2.AnalyticsClient(this._options)));
    }
    get dashboard() {
        var _a;
        return ((_a = this._dashboard) !== null && _a !== void 0 ? _a : (this._dashboard = new Client_5.DashboardClient(this._options)));
    }
    /**
     * Upload a file or webpage URL to create a knowledge base document. <br> <Note> After creating the document, update the agent's knowledge base by calling [Update agent](/docs/api-reference/agents/update). </Note>
     *
     * @param {ElevenLabs.BodyAddToKnowledgeBaseV1ConvaiKnowledgeBasePost} request
     * @param {ConversationalAiClient.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @throws {@link ElevenLabs.UnprocessableEntityError}
     *
     * @example
     *     import { createReadStream } from "fs";
     *     await client.conversationalAi.addToKnowledgeBase({
     *         agentId: "agent_id"
     *     })
     */
    addToKnowledgeBase(request, requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__addToKnowledgeBase(request, requestOptions));
    }
    __addToKnowledgeBase(request, requestOptions) {
        return __awaiter(this, void 0, void 0, function* () {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
            const _queryParams = {};
            if (request.agentId != null) {
                _queryParams.agent_id = request.agentId;
            }
            const _request = yield core.newFormData();
            if (request.name != null) {
                _request.append("name", request.name);
            }
            if (request.url != null) {
                _request.append("url", request.url);
            }
            if (request.file != null) {
                yield _request.appendFile("file", request.file);
            }
            const _maybeEncodedRequest = yield _request.getRequest();
            const _headers = (0, headers_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)(Object.assign({ "xi-api-key": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.apiKey) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.apiKey }, _maybeEncodedRequest.headers)), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
            const _response = yield ((_d = this._options.fetcher) !== null && _d !== void 0 ? _d : core.fetcher)({
                url: core.url.join((_f = (_e = (yield core.Supplier.get(this._options.baseUrl))) !== null && _e !== void 0 ? _e : (yield core.Supplier.get(this._options.environment))) !== null && _f !== void 0 ? _f : environments.ElevenLabsEnvironment.Production, "v1/convai/knowledge-base"),
                method: "POST",
                headers: _headers,
                queryParameters: Object.assign(Object.assign({}, _queryParams), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams),
                requestType: "file",
                duplex: _maybeEncodedRequest.duplex,
                body: _maybeEncodedRequest.body,
                timeoutMs: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 240) * 1000,
                maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                logging: this._options.logging,
            });
            if (_response.ok) {
                return {
                    data: serializers.AddKnowledgeBaseResponseModel.parseOrThrow(_response.body, {
                        unrecognizedObjectKeys: "passthrough",
                        allowUnrecognizedUnionMembers: true,
                        allowUnrecognizedEnumValues: true,
                        breadcrumbsPrefix: ["response"],
                    }),
                    rawResponse: _response.rawResponse,
                };
            }
            if (_response.error.reason === "status-code") {
                switch (_response.error.statusCode) {
                    case 422:
                        throw new ElevenLabs.UnprocessableEntityError(_response.error.body, _response.rawResponse);
                    default:
                        throw new errors.ElevenLabsError({
                            statusCode: _response.error.statusCode,
                            body: _response.error.body,
                            rawResponse: _response.rawResponse,
                        });
                }
            }
            return (0, handleNonStatusCodeError_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "POST", "/v1/convai/knowledge-base");
        });
    }
    /**
     * Provides total size and other information of RAG indexes used by knowledgebase documents
     *
     * @param {ConversationalAiClient.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @throws {@link ElevenLabs.UnprocessableEntityError}
     *
     * @example
     *     await client.conversationalAi.ragIndexOverview()
     */
    ragIndexOverview(requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__ragIndexOverview(requestOptions));
    }
    __ragIndexOverview(requestOptions) {
        return __awaiter(this, void 0, void 0, function* () {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
            const _headers = (0, headers_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({ "xi-api-key": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.apiKey) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.apiKey }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
            const _response = yield ((_d = this._options.fetcher) !== null && _d !== void 0 ? _d : core.fetcher)({
                url: core.url.join((_f = (_e = (yield core.Supplier.get(this._options.baseUrl))) !== null && _e !== void 0 ? _e : (yield core.Supplier.get(this._options.environment))) !== null && _f !== void 0 ? _f : environments.ElevenLabsEnvironment.Production, "v1/convai/knowledge-base/rag-index"),
                method: "GET",
                headers: _headers,
                queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
                timeoutMs: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 240) * 1000,
                maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                logging: this._options.logging,
            });
            if (_response.ok) {
                return {
                    data: serializers.RagIndexOverviewResponseModel.parseOrThrow(_response.body, {
                        unrecognizedObjectKeys: "passthrough",
                        allowUnrecognizedUnionMembers: true,
                        allowUnrecognizedEnumValues: true,
                        breadcrumbsPrefix: ["response"],
                    }),
                    rawResponse: _response.rawResponse,
                };
            }
            if (_response.error.reason === "status-code") {
                switch (_response.error.statusCode) {
                    case 422:
                        throw new ElevenLabs.UnprocessableEntityError(_response.error.body, _response.rawResponse);
                    default:
                        throw new errors.ElevenLabsError({
                            statusCode: _response.error.statusCode,
                            body: _response.error.body,
                            rawResponse: _response.rawResponse,
                        });
                }
            }
            return (0, handleNonStatusCodeError_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "GET", "/v1/convai/knowledge-base/rag-index");
        });
    }
    /**
     * Provides information about all RAG indexes of the specified knowledgebase document.
     *
     * @param {string} documentation_id - The id of a document from the knowledge base. This is returned on document addition.
     * @param {ConversationalAiClient.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @throws {@link ElevenLabs.UnprocessableEntityError}
     *
     * @example
     *     await client.conversationalAi.getDocumentRagIndexes("21m00Tcm4TlvDq8ikWAM")
     */
    getDocumentRagIndexes(documentation_id, requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__getDocumentRagIndexes(documentation_id, requestOptions));
    }
    __getDocumentRagIndexes(documentation_id, requestOptions) {
        return __awaiter(this, void 0, void 0, function* () {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
            const _headers = (0, headers_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({ "xi-api-key": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.apiKey) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.apiKey }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
            const _response = yield ((_d = this._options.fetcher) !== null && _d !== void 0 ? _d : core.fetcher)({
                url: core.url.join((_f = (_e = (yield core.Supplier.get(this._options.baseUrl))) !== null && _e !== void 0 ? _e : (yield core.Supplier.get(this._options.environment))) !== null && _f !== void 0 ? _f : environments.ElevenLabsEnvironment.Production, `v1/convai/knowledge-base/${core.url.encodePathParam(documentation_id)}/rag-index`),
                method: "GET",
                headers: _headers,
                queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
                timeoutMs: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 240) * 1000,
                maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                logging: this._options.logging,
            });
            if (_response.ok) {
                return {
                    data: serializers.RagDocumentIndexesResponseModel.parseOrThrow(_response.body, {
                        unrecognizedObjectKeys: "passthrough",
                        allowUnrecognizedUnionMembers: true,
                        allowUnrecognizedEnumValues: true,
                        breadcrumbsPrefix: ["response"],
                    }),
                    rawResponse: _response.rawResponse,
                };
            }
            if (_response.error.reason === "status-code") {
                switch (_response.error.statusCode) {
                    case 422:
                        throw new ElevenLabs.UnprocessableEntityError(_response.error.body, _response.rawResponse);
                    default:
                        throw new errors.ElevenLabsError({
                            statusCode: _response.error.statusCode,
                            body: _response.error.body,
                            rawResponse: _response.rawResponse,
                        });
                }
            }
            return (0, handleNonStatusCodeError_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "GET", "/v1/convai/knowledge-base/{documentation_id}/rag-index");
        });
    }
    /**
     * Delete RAG index for the knowledgebase document.
     *
     * @param {string} documentation_id - The id of a document from the knowledge base. This is returned on document addition.
     * @param {string} rag_index_id - The id of RAG index of document from the knowledge base.
     * @param {ConversationalAiClient.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @throws {@link ElevenLabs.UnprocessableEntityError}
     *
     * @example
     *     await client.conversationalAi.deleteDocumentRagIndex("21m00Tcm4TlvDq8ikWAM", "21m00Tcm4TlvDq8ikWAM")
     */
    deleteDocumentRagIndex(documentation_id, rag_index_id, requestOptions) {
        return core.HttpResponsePromise.fromPromise(this.__deleteDocumentRagIndex(documentation_id, rag_index_id, requestOptions));
    }
    __deleteDocumentRagIndex(documentation_id, rag_index_id, requestOptions) {
        return __awaiter(this, void 0, void 0, function* () {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
            const _headers = (0, headers_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_1.mergeOnlyDefinedHeaders)({ "xi-api-key": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.apiKey) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.apiKey }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
            const _response = yield ((_d = this._options.fetcher) !== null && _d !== void 0 ? _d : core.fetcher)({
                url: core.url.join((_f = (_e = (yield core.Supplier.get(this._options.baseUrl))) !== null && _e !== void 0 ? _e : (yield core.Supplier.get(this._options.environment))) !== null && _f !== void 0 ? _f : environments.ElevenLabsEnvironment.Production, `v1/convai/knowledge-base/${core.url.encodePathParam(documentation_id)}/rag-index/${core.url.encodePathParam(rag_index_id)}`),
                method: "DELETE",
                headers: _headers,
                queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
                timeoutMs: ((_j = (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.timeoutInSeconds) !== null && _j !== void 0 ? _j : 240) * 1000,
                maxRetries: (_k = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _k !== void 0 ? _k : (_l = this._options) === null || _l === void 0 ? void 0 : _l.maxRetries,
                abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
                fetchFn: (_m = this._options) === null || _m === void 0 ? void 0 : _m.fetch,
                logging: this._options.logging,
            });
            if (_response.ok) {
                return {
                    data: serializers.RagDocumentIndexResponseModel.parseOrThrow(_response.body, {
                        unrecognizedObjectKeys: "passthrough",
                        allowUnrecognizedUnionMembers: true,
                        allowUnrecognizedEnumValues: true,
                        breadcrumbsPrefix: ["response"],
                    }),
                    rawResponse: _response.rawResponse,
                };
            }
            if (_response.error.reason === "status-code") {
                switch (_response.error.statusCode) {
                    case 422:
                        throw new ElevenLabs.UnprocessableEntityError(_response.error.body, _response.rawResponse);
                    default:
                        throw new errors.ElevenLabsError({
                            statusCode: _response.error.statusCode,
                            body: _response.error.body,
                            rawResponse: _response.rawResponse,
                        });
                }
            }
            return (0, handleNonStatusCodeError_1.handleNonStatusCodeError)(_response.error, _response.rawResponse, "DELETE", "/v1/convai/knowledge-base/{documentation_id}/rag-index/{rag_index_id}");
        });
    }
}
exports.ConversationalAiClient = ConversationalAiClient;
