UNPKG

twilio

Version:
342 lines (341 loc) 14.2 kB
"use strict"; /* * This code was generated by * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ * * Twilio Conversational Intelligence API * The Conversational Intelligence API includes resources to create and manage intelligence configurations, define and run language operators, and retrieve processed conversations and operator results. * Use the Configurations resource to create and manage intelligence configurations and define rules that control how and when language operators analyze and transform conversations. * Use the Operators resource to create custom language operators or retrieve Twilio-author and custom operators. * Use the Conversations resource to retrieve conversations processed with an intelligence configuration, and the OperatorResults resource to retrieve language operator results for those conversations. * * NOTE: This class is auto generated by OpenAPI Generator. * https://openapi-generator.tech * Do not edit the class manually. */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.VersionPage = exports.VersionInstance = exports.VersionContextImpl = exports.OperatorTrainingExample = exports.OperatorParameter = exports.OperatorContextMemory = exports.OperatorContextKnowledge = exports.OperatorContext = void 0; exports.VersionListInstance = VersionListInstance; const util_1 = require("util"); const TokenPage_1 = __importDefault(require("../../../base/TokenPage")); const deserialize = require("../../../base/deserialize"); const serialize = require("../../../base/serialize"); const utility_1 = require("../../../base/utility"); /** * Optionally specifies which contextual data sources (Memory, Knowledge) the operator can access during execution. Context objects will be passed in by the Intelligence Configuration Rule at runtime. **Note**: this simply gives the LLM access to these context objects – ultimately the LLM will determine whether to actually call for context at runtime. */ class OperatorContext { constructor(payload) { this.memory = payload["memory"]; this.knowledge = payload["knowledge"]; } } exports.OperatorContext = OperatorContext; /** * Defines whether the Operator has access to organizational Knowledge Sources (e.g., policies, FAQs, scripts) at runtime. */ class OperatorContextKnowledge { constructor(payload) { this.enabled = payload["enabled"]; } } exports.OperatorContextKnowledge = OperatorContextKnowledge; /** * Defines whether the Operator has access to Memory (past conversational memories and profile traits). */ class OperatorContextMemory { constructor(payload) { this.enabled = payload["enabled"]; } } exports.OperatorContextMemory = OperatorContextMemory; class OperatorParameter { constructor(payload) { this.type = payload["type"]; this._default = payload["default"]; this.required = payload["required"]; this.description = payload["description"]; } } exports.OperatorParameter = OperatorParameter; class OperatorTrainingExample { constructor(payload) { this.input = payload["input"]; this.output = payload["output"]; } } exports.OperatorTrainingExample = OperatorTrainingExample; class VersionContextImpl { constructor(_version, id, versionParam) { this._version = _version; if (!(0, utility_1.isValidPathParam)(id)) { throw new Error("Parameter 'id' is not valid."); } if (!(0, utility_1.isValidPathParam)(versionParam)) { throw new Error("Parameter 'versionParam' is not valid."); } this._solution = { id, versionParam }; this._uri = `/ControlPlane/Operators/${id}/Versions/${versionParam}`; } fetch(callback) { const headers = {}; headers["Accept"] = "application/json"; const instance = this; let operationVersion = instance._version, operationPromise = operationVersion.fetch({ uri: instance._uri, method: "get", headers, }); operationPromise = operationPromise.then((payload) => new VersionInstance(operationVersion, payload, instance._solution.id, instance._solution.versionParam)); operationPromise = instance._version.setPromiseCallback(operationPromise, callback); return operationPromise; } fetchWithHttpInfo(callback) { const headers = {}; headers["Accept"] = "application/json"; const instance = this; let operationVersion = instance._version; // CREATE, FETCH, UPDATE operations let operationPromise = operationVersion .fetchWithResponseInfo({ uri: instance._uri, method: "get", headers, }) .then((response) => ({ ...response, body: new VersionInstance(operationVersion, response.body, instance._solution.id, instance._solution.versionParam), })); operationPromise = instance._version.setPromiseCallback(operationPromise, callback); return operationPromise; } /** * Provide a user-friendly representation * * @returns Object */ toJSON() { return this._solution; } [util_1.inspect.custom](_depth, options) { return (0, util_1.inspect)(this.toJSON(), options); } } exports.VersionContextImpl = VersionContextImpl; /** * Full detail of a specific Language Operator version. */ class VersionInstance { constructor(_version, _payload, id, versionParam) { this._version = _version; const payload = _payload; this.id = payload.id; this.displayName = payload.displayName; this.description = payload.description; this.version = deserialize.integer(payload.version); this.author = payload.author; this.prompt = payload.prompt; this.outputFormat = payload.outputFormat; this.outputSchema = payload.outputSchema; this.trainingExamples = payload.trainingExamples !== null && payload.trainingExamples !== undefined ? payload.trainingExamples.map((payload) => new OperatorTrainingExample(payload)) : null; this.context = payload.context !== null && payload.context !== undefined ? new OperatorContext(payload.context) : null; this.parameters = payload.parameters; this.status = payload.status; this.dateCreated = deserialize.iso8601DateTime(payload.dateCreated); this.dateDeprecated = deserialize.iso8601DateTime(payload.dateDeprecated); this.retirementDate = deserialize.iso8601DateTime(payload.retirementDate); this.dateRetired = deserialize.iso8601DateTime(payload.dateRetired); this._solution = { id, versionParam: versionParam }; } get _proxy() { this._context = this._context || new VersionContextImpl(this._version, this._solution.id, this._solution.versionParam); return this._context; } /** * Fetch a VersionInstance * * @param callback - Callback to handle processed record * * @returns Resolves to processed VersionInstance */ fetch(callback) { return this._proxy.fetch(callback); } /** * Fetch a VersionInstance and return HTTP info * * @param callback - Callback to handle processed record * * @returns Resolves to processed VersionInstance with HTTP metadata */ fetchWithHttpInfo(callback) { return this._proxy.fetchWithHttpInfo(callback); } /** * Provide a user-friendly representation * * @returns Object */ toJSON() { return { id: this.id, displayName: this.displayName, description: this.description, version: this.version, author: this.author, prompt: this.prompt, outputFormat: this.outputFormat, outputSchema: this.outputSchema, trainingExamples: this.trainingExamples, context: this.context, parameters: this.parameters, status: this.status, dateCreated: this.dateCreated, dateDeprecated: this.dateDeprecated, retirementDate: this.retirementDate, dateRetired: this.dateRetired, }; } [util_1.inspect.custom](_depth, options) { return (0, util_1.inspect)(this.toJSON(), options); } } exports.VersionInstance = VersionInstance; function VersionListInstance(version, id) { if (!(0, utility_1.isValidPathParam)(id)) { throw new Error("Parameter 'id' is not valid."); } const instance = ((versionParam) => instance.get(versionParam)); instance.get = function get(versionParam) { return new VersionContextImpl(version, id, versionParam); }; instance._version = version; instance._solution = { id }; instance._uri = `/ControlPlane/Operators/${id}/Versions`; instance.page = function page(params, callback) { if (params instanceof Function) { callback = params; params = {}; } else { params = params || {}; } let data = {}; if (params["pageSize"] !== undefined) data["pageSize"] = params["pageSize"]; if (params["pageToken"] !== undefined) data["pageToken"] = params["pageToken"]; const headers = {}; headers["Accept"] = "application/json"; let operationVersion = version, operationPromise = operationVersion.page({ uri: instance._uri, method: "get", params: data, headers, }); operationPromise = operationPromise.then((payload) => new VersionPage(operationVersion, payload, instance._uri, data, instance._solution)); operationPromise = instance._version.setPromiseCallback(operationPromise, callback); return operationPromise; }; instance.each = instance._version.each; instance.list = instance._version.list; instance.getPage = function getPage(targetUrl, callback) { const operationPromise = instance._version._domain.twilio.request({ method: "get", uri: targetUrl, }); let pagePromise = operationPromise.then((payload) => new VersionPage(instance._version, payload, instance._uri, {}, instance._solution)); pagePromise = instance._version.setPromiseCallback(pagePromise, callback); return pagePromise; }; instance.pageWithHttpInfo = function pageWithHttpInfo(params, callback) { if (params instanceof Function) { callback = params; params = {}; } else { params = params || {}; } let data = {}; if (params["pageSize"] !== undefined) data["pageSize"] = params["pageSize"]; if (params["pageToken"] !== undefined) data["pageToken"] = params["pageToken"]; const headers = {}; headers["Accept"] = "application/json"; let operationVersion = version; // For page operations, use page() directly as it already returns { statusCode, body, headers } // IMPORTANT: Pass full response to Page constructor, not response.body let operationPromise = operationVersion .page({ uri: instance._uri, method: "get", params: data, headers }) .then((response) => ({ statusCode: response.statusCode, headers: response.headers, body: new VersionPage(operationVersion, response, instance._uri, data, instance._solution), })); operationPromise = instance._version.setPromiseCallback(operationPromise, callback); return operationPromise; }; instance.each = instance._version.each; instance.eachWithHttpInfo = instance._version.eachWithHttpInfo; instance.list = instance._version.list; instance.listWithHttpInfo = instance._version.listWithHttpInfo; instance.getPageWithHttpInfo = function getPageWithHttpInfo(targetUrl, callback) { // Use request() directly as it already returns { statusCode, body, headers } const operationPromise = instance._version._domain.twilio.request({ method: "get", uri: targetUrl, }); let pagePromise = operationPromise.then((response) => ({ statusCode: response.statusCode, headers: response.headers, body: new VersionPage(instance._version, response, instance._uri, {}, instance._solution), })); pagePromise = instance._version.setPromiseCallback(pagePromise, callback); return pagePromise; }; instance.toJSON = function toJSON() { return instance._solution; }; instance[util_1.inspect.custom] = function inspectImpl(_depth, options) { return (0, util_1.inspect)(instance.toJSON(), options); }; return instance; } class VersionPage extends TokenPage_1.default { /** * Initialize the VersionPage * * @param version - Version of the resource * @param response - Response from the API * @param uri - URI of the resource * @param params - Query parameters * @param solution - Path solution */ constructor(version, response, uri, params, solution) { super(version, response, uri, params, solution); } /** * Build an instance of VersionInstance * * @param payload - Payload response from the API */ getInstance(payload) { return new VersionInstance(this._version, payload, this._solution.id); } [util_1.inspect.custom](depth, options) { return (0, util_1.inspect)(this.toJSON(), options); } } exports.VersionPage = VersionPage;