ibm-watson
Version:
Client library to use the IBM Watson Services
1,005 lines • 152 kB
JavaScript
"use strict";
/**
* (C) Copyright IBM Corp. 2024.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
/**
* IBM OpenAPI SDK Code Generator Version: 3.96.1-5136e54a-20241108-203028
*/
var extend = require("extend");
var ibm_cloud_sdk_core_1 = require("ibm-cloud-sdk-core");
var common_1 = require("../lib/common");
/**
* The IBM® watsonx™ Assistant service combines machine learning, natural language understanding, and an
* integrated dialog editor to create conversation flows between your apps and your users.
*
* The Assistant v2 API provides runtime methods your client application can use to send user input to an assistant and
* receive a response.
*
* You need a paid Plus plan or higher to use the watsonx Assistant v2 API.
*
* API Version: 2.0
* See: https://cloud.ibm.com/docs/assistant
*/
var AssistantV2 = /** @class */ (function (_super) {
__extends(AssistantV2, _super);
/**
* Construct a AssistantV2 object.
*
* @param {Object} options - Options for the service.
* @param {string} options.version - Release date of the API version you want to use. Specify dates in YYYY-MM-DD
* format. The current version is `2023-06-15`.
* @param {string} [options.serviceUrl] - The base URL for the service
* @param {OutgoingHttpHeaders} [options.headers] - Default headers that shall be included with every request to the service.
* @param {string} [options.serviceName] - The name of the service to configure
* @param {Authenticator} [options.authenticator] - The Authenticator object used to authenticate requests to the service. Defaults to environment if not set
* @constructor
* @returns {AssistantV2}
*/
function AssistantV2(options) {
var _this = this;
options = options || {};
var _requiredParams = ['version'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(options, _requiredParams, null);
if (_validationErrors) {
throw _validationErrors;
}
if (!options.serviceName) {
options.serviceName = AssistantV2.DEFAULT_SERVICE_NAME;
}
// If the caller didn't supply an authenticator, construct one from external configuration.
if (!options.authenticator) {
options.authenticator = (0, ibm_cloud_sdk_core_1.getAuthenticatorFromEnvironment)(options.serviceName);
}
_this = _super.call(this, options) || this;
_this.configureService(options.serviceName);
if (options.serviceUrl) {
_this.setServiceUrl(options.serviceUrl);
}
_this.version = options.version;
return _this;
}
/*************************
* conversationalSkillProviders
************************/
/**
* Create a conversational skill provider.
*
* Create a new conversational skill provider.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.providerId - The unique identifier of the provider.
* @param {ProviderSpecification} params.specification - The specification of the provider.
* @param {ProviderPrivate} params._private - Private information of the provider.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<AssistantV2.Response<AssistantV2.ProviderResponse>>}
*/
AssistantV2.prototype.createProvider = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['providerId', 'specification', '_private'];
var _validParams = ['providerId', 'specification', '_private', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var body = {
'provider_id': _params.providerId,
'specification': _params.specification,
'private': _params._private,
};
var query = {
'version': this.version,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(AssistantV2.DEFAULT_SERVICE_NAME, 'v2', 'createProvider');
var parameters = {
options: {
url: '/v2/providers',
method: 'POST',
body: body,
qs: query,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* List conversational skill providers.
*
* List the conversational skill providers associated with a Watson Assistant service instance.
*
* @param {Object} [params] - The parameters to send to the service.
* @param {number} [params.pageLimit] - The number of records to return in each page of results.
* @param {boolean} [params.includeCount] - Whether to include information about the number of records that satisfy
* the request, regardless of the page limit. If this parameter is `true`, the `pagination` object in the response
* includes the `total` property.
* @param {string} [params.sort] - The attribute by which returned conversational skill providers will be sorted. To
* reverse the sort order, prefix the value with a minus sign (`-`).
* @param {string} [params.cursor] - A token identifying the page of results to retrieve.
* @param {boolean} [params.includeAudit] - Whether to include the audit properties (`created` and `updated`
* timestamps) in the response.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<AssistantV2.Response<AssistantV2.ProviderCollection>>}
*/
AssistantV2.prototype.listProviders = function (params) {
var _params = __assign({}, params);
var _requiredParams = [];
var _validParams = ['pageLimit', 'includeCount', 'sort', 'cursor', 'includeAudit', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var query = {
'version': this.version,
'page_limit': _params.pageLimit,
'include_count': _params.includeCount,
'sort': _params.sort,
'cursor': _params.cursor,
'include_audit': _params.includeAudit,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(AssistantV2.DEFAULT_SERVICE_NAME, 'v2', 'listProviders');
var parameters = {
options: {
url: '/v2/providers',
method: 'GET',
qs: query,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Update a conversational skill provider.
*
* Update a new conversational skill provider.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.providerId - Unique identifier of the conversational skill provider.
* @param {ProviderSpecification} params.specification - The specification of the provider.
* @param {ProviderPrivate} params._private - Private information of the provider.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<AssistantV2.Response<AssistantV2.ProviderResponse>>}
*/
AssistantV2.prototype.updateProvider = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['providerId', 'specification', '_private'];
var _validParams = ['providerId', 'specification', '_private', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var body = {
'specification': _params.specification,
'private': _params._private,
};
var query = {
'version': this.version,
};
var path = {
'provider_id': _params.providerId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(AssistantV2.DEFAULT_SERVICE_NAME, 'v2', 'updateProvider');
var parameters = {
options: {
url: '/v2/providers/{provider_id}',
method: 'POST',
body: body,
qs: query,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/*************************
* assistants
************************/
/**
* Create an assistant.
*
* Create a new assistant.
*
* @param {Object} [params] - The parameters to send to the service.
* @param {string} [params.language] - The language of the assistant.
* @param {string} [params.name] - The name of the assistant. This string cannot contain carriage return, newline, or
* tab characters.
* @param {string} [params.description] - The description of the assistant. This string cannot contain carriage
* return, newline, or tab characters.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<AssistantV2.Response<AssistantV2.AssistantData>>}
*/
AssistantV2.prototype.createAssistant = function (params) {
var _params = __assign({}, params);
var _requiredParams = [];
var _validParams = ['language', 'name', 'description', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var body = {
'language': _params.language,
'name': _params.name,
'description': _params.description,
};
var query = {
'version': this.version,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(AssistantV2.DEFAULT_SERVICE_NAME, 'v2', 'createAssistant');
var parameters = {
options: {
url: '/v2/assistants',
method: 'POST',
body: body,
qs: query,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* List assistants.
*
* List the assistants associated with a watsonx Assistant service instance.
*
* @param {Object} [params] - The parameters to send to the service.
* @param {number} [params.pageLimit] - The number of records to return in each page of results.
* @param {boolean} [params.includeCount] - Whether to include information about the number of records that satisfy
* the request, regardless of the page limit. If this parameter is `true`, the `pagination` object in the response
* includes the `total` property.
* @param {string} [params.sort] - The attribute by which returned assistants will be sorted. To reverse the sort
* order, prefix the value with a minus sign (`-`).
* @param {string} [params.cursor] - A token identifying the page of results to retrieve.
* @param {boolean} [params.includeAudit] - Whether to include the audit properties (`created` and `updated`
* timestamps) in the response.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<AssistantV2.Response<AssistantV2.AssistantCollection>>}
*/
AssistantV2.prototype.listAssistants = function (params) {
var _params = __assign({}, params);
var _requiredParams = [];
var _validParams = ['pageLimit', 'includeCount', 'sort', 'cursor', 'includeAudit', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var query = {
'version': this.version,
'page_limit': _params.pageLimit,
'include_count': _params.includeCount,
'sort': _params.sort,
'cursor': _params.cursor,
'include_audit': _params.includeAudit,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(AssistantV2.DEFAULT_SERVICE_NAME, 'v2', 'listAssistants');
var parameters = {
options: {
url: '/v2/assistants',
method: 'GET',
qs: query,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Delete assistant.
*
* Delete an assistant.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.assistantId - The assistant ID or the environment ID of the environment where the assistant
* is deployed, depending on the type of request:
* - For message, session, and log requests, specify the environment ID of the environment where the assistant is
* deployed.
* - For all other requests, specify the assistant ID of the assistant.
*
* To find the environment ID or assistant ID in the watsonx Assistant user interface, open the assistant settings
* and scroll to the **Environments** section.
*
* **Note:** If you are using the classic Watson Assistant experience, always use the assistant ID. To find the
* assistant ID in the user interface, open the assistant settings and click API Details.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<AssistantV2.Response<AssistantV2.EmptyObject>>}
*/
AssistantV2.prototype.deleteAssistant = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['assistantId'];
var _validParams = ['assistantId', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var query = {
'version': this.version,
};
var path = {
'assistant_id': _params.assistantId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(AssistantV2.DEFAULT_SERVICE_NAME, 'v2', 'deleteAssistant');
var parameters = {
options: {
url: '/v2/assistants/{assistant_id}',
method: 'DELETE',
qs: query,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/*************************
* sessions
************************/
/**
* Create a session.
*
* Create a new session. A session is used to send user input to a skill and receive responses. It also maintains the
* state of the conversation. A session persists until it is deleted, or until it times out because of inactivity.
* (For more information, see the
* [documentation](https://cloud.ibm.com/docs/assistant?topic=assistant-assistant-settings).).
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.assistantId - The assistant ID or the environment ID of the environment where the assistant
* is deployed, depending on the type of request:
* - For message, session, and log requests, specify the environment ID of the environment where the assistant is
* deployed.
* - For all other requests, specify the assistant ID of the assistant.
*
* To find the environment ID or assistant ID in the watsonx Assistant user interface, open the assistant settings
* and scroll to the **Environments** section.
*
* **Note:** If you are using the classic Watson Assistant experience, always use the assistant ID. To find the
* assistant ID in the user interface, open the assistant settings and click API Details.
* @param {RequestAnalytics} [params.analytics] - An optional object containing analytics data. Currently, this data
* is used only for events sent to the Segment extension.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<AssistantV2.Response<AssistantV2.SessionResponse>>}
*/
AssistantV2.prototype.createSession = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['assistantId'];
var _validParams = ['assistantId', 'analytics', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var body = {
'analytics': _params.analytics,
};
var query = {
'version': this.version,
};
var path = {
'assistant_id': _params.assistantId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(AssistantV2.DEFAULT_SERVICE_NAME, 'v2', 'createSession');
var parameters = {
options: {
url: '/v2/assistants/{assistant_id}/sessions',
method: 'POST',
body: body,
qs: query,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Delete session.
*
* Deletes a session explicitly before it times out. (For more information about the session inactivity timeout, see
* the [documentation](https://cloud.ibm.com/docs/assistant?topic=assistant-assistant-settings)).
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.assistantId - The assistant ID or the environment ID of the environment where the assistant
* is deployed, depending on the type of request:
* - For message, session, and log requests, specify the environment ID of the environment where the assistant is
* deployed.
* - For all other requests, specify the assistant ID of the assistant.
*
* To find the environment ID or assistant ID in the watsonx Assistant user interface, open the assistant settings
* and scroll to the **Environments** section.
*
* **Note:** If you are using the classic Watson Assistant experience, always use the assistant ID. To find the
* assistant ID in the user interface, open the assistant settings and click API Details.
* @param {string} params.sessionId - Unique identifier of the session.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<AssistantV2.Response<AssistantV2.EmptyObject>>}
*/
AssistantV2.prototype.deleteSession = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['assistantId', 'sessionId'];
var _validParams = ['assistantId', 'sessionId', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var query = {
'version': this.version,
};
var path = {
'assistant_id': _params.assistantId,
'session_id': _params.sessionId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(AssistantV2.DEFAULT_SERVICE_NAME, 'v2', 'deleteSession');
var parameters = {
options: {
url: '/v2/assistants/{assistant_id}/sessions/{session_id}',
method: 'DELETE',
qs: query,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/*************************
* message
************************/
/**
* Send user input to assistant (stateful).
*
* Send user input to an assistant and receive a response, with conversation state (including context data) stored by
* watsonx Assistant for the duration of the session.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.assistantId - The assistant ID or the environment ID of the environment where the assistant
* is deployed, depending on the type of request:
* - For message, session, and log requests, specify the environment ID of the environment where the assistant is
* deployed.
* - For all other requests, specify the assistant ID of the assistant.
*
* To find the environment ID or assistant ID in the watsonx Assistant user interface, open the assistant settings
* and scroll to the **Environments** section.
*
* **Note:** If you are using the classic Watson Assistant experience, always use the assistant ID. To find the
* assistant ID in the user interface, open the assistant settings and click API Details.
* @param {string} params.environmentId - Unique identifier of the environment. To find the environment ID in the
* watsonx Assistant user interface, open the environment settings and click **API Details**. **Note:** Currently, the
* API does not support creating environments.
* @param {string} params.sessionId - Unique identifier of the session.
* @param {MessageInput} [params.input] - An input object that includes the input text.
* @param {MessageContext} [params.context] - Context data for the conversation. You can use this property to set or
* modify context variables, which can also be accessed by dialog nodes. The context is stored by the assistant on a
* per-session basis.
*
* **Note:** The total size of the context data stored for a stateful session cannot exceed 100KB.
* @param {string} [params.userId] - A string value that identifies the user who is interacting with the assistant.
* The client must provide a unique identifier for each individual end user who accesses the application. For
* user-based plans, this user ID is used to identify unique users for billing purposes. This string cannot contain
* carriage return, newline, or tab characters. If no value is specified in the input, **user_id** is automatically
* set to the value of **context.global.session_id**.
*
* **Note:** This property is the same as the **user_id** property in the global system context. If **user_id** is
* specified in both locations, the value specified at the root is used.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<AssistantV2.Response<AssistantV2.StatefulMessageResponse>>}
*/
AssistantV2.prototype.message = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['assistantId', 'environmentId', 'sessionId'];
var _validParams = ['assistantId', 'environmentId', 'sessionId', 'input', 'context', 'userId', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var body = {
'input': _params.input,
'context': _params.context,
'user_id': _params.userId,
};
var query = {
'version': this.version,
};
var path = {
'assistant_id': _params.assistantId,
'environment_id': _params.environmentId,
'session_id': _params.sessionId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(AssistantV2.DEFAULT_SERVICE_NAME, 'v2', 'message');
var parameters = {
options: {
url: '/v2/assistants/{assistant_id}/sessions/{session_id}/message',
method: 'POST',
body: body,
qs: query,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Send user input to assistant (stateless).
*
* Send user input to an assistant and receive a response, with conversation state (including context data) managed by
* your application.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.assistantId - The assistant ID or the environment ID of the environment where the assistant
* is deployed, depending on the type of request:
* - For message, session, and log requests, specify the environment ID of the environment where the assistant is
* deployed.
* - For all other requests, specify the assistant ID of the assistant.
*
* To find the environment ID or assistant ID in the watsonx Assistant user interface, open the assistant settings
* and scroll to the **Environments** section.
*
* **Note:** If you are using the classic Watson Assistant experience, always use the assistant ID. To find the
* assistant ID in the user interface, open the assistant settings and click API Details.
* @param {string} params.environmentId - Unique identifier of the environment. To find the environment ID in the
* watsonx Assistant user interface, open the environment settings and click **API Details**. **Note:** Currently, the
* API does not support creating environments.
* @param {StatelessMessageInput} [params.input] - An input object that includes the input text.
* @param {StatelessMessageContext} [params.context] - Context data for the conversation. You can use this property to
* set or modify context variables, which can also be accessed by dialog nodes. The context is not stored by the
* assistant. To maintain session state, include the context from the previous response.
*
* **Note:** The total size of the context data for a stateless session cannot exceed 250KB.
* @param {string} [params.userId] - A string value that identifies the user who is interacting with the assistant.
* The client must provide a unique identifier for each individual end user who accesses the application. For
* user-based plans, this user ID is used to identify unique users for billing purposes. This string cannot contain
* carriage return, newline, or tab characters. If no value is specified in the input, **user_id** is automatically
* set to the value of **context.global.session_id**.
*
* **Note:** This property is the same as the **user_id** property in the global system context. If **user_id** is
* specified in both locations in a message request, the value specified at the root is used.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<AssistantV2.Response<AssistantV2.StatelessMessageResponse>>}
*/
AssistantV2.prototype.messageStateless = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['assistantId', 'environmentId'];
var _validParams = ['assistantId', 'environmentId', 'input', 'context', 'userId', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var body = {
'input': _params.input,
'context': _params.context,
'user_id': _params.userId,
};
var query = {
'version': this.version,
};
var path = {
'assistant_id': _params.assistantId,
'environment_id': _params.environmentId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(AssistantV2.DEFAULT_SERVICE_NAME, 'v2', 'messageStateless');
var parameters = {
options: {
url: '/v2/assistants/{assistant_id}/message',
method: 'POST',
body: body,
qs: query,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/*************************
* messageStream
************************/
/**
* Send user input to assistant (stateful).
*
* Send user input to an assistant and receive a streamed response, with conversation state (including context data)
* stored by watsonx Assistant for the duration of the session.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.assistantId - The assistant ID or the environment ID of the environment where the assistant
* is deployed, depending on the type of request:
* - For message, session, and log requests, specify the environment ID of the environment where the assistant is
* deployed.
* - For all other requests, specify the assistant ID of the assistant.
*
* To find the environment ID or assistant ID in the watsonx Assistant user interface, open the assistant settings
* and scroll to the **Environments** section.
*
* **Note:** If you are using the classic Watson Assistant experience, always use the assistant ID. To find the
* assistant ID in the user interface, open the assistant settings and click API Details.
* @param {string} params.environmentId - Unique identifier of the environment. To find the environment ID in the
* watsonx Assistant user interface, open the environment settings and click **API Details**. **Note:** Currently, the
* API does not support creating environments.
* @param {string} params.sessionId - Unique identifier of the session.
* @param {MessageInput} [params.input] - An input object that includes the input text.
* @param {MessageContext} [params.context] - Context data for the conversation. You can use this property to set or
* modify context variables, which can also be accessed by dialog nodes. The context is stored by the assistant on a
* per-session basis.
*
* **Note:** The total size of the context data stored for a stateful session cannot exceed 100KB.
* @param {string} [params.userId] - A string value that identifies the user who is interacting with the assistant.
* The client must provide a unique identifier for each individual end user who accesses the application. For
* user-based plans, this user ID is used to identify unique users for billing purposes. This string cannot contain
* carriage return, newline, or tab characters. If no value is specified in the input, **user_id** is automatically
* set to the value of **context.global.session_id**.
*
* **Note:** This property is the same as the **user_id** property in the global system context. If **user_id** is
* specified in both locations, the value specified at the root is used.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<AssistantV2.Response<NodeJS.ReadableStream>>}
*/
AssistantV2.prototype.messageStream = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['assistantId', 'environmentId', 'sessionId'];
var _validParams = ['assistantId', 'environmentId', 'sessionId', 'input', 'context', 'userId', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var body = {
'input': _params.input,
'context': _params.context,
'user_id': _params.userId,
};
var query = {
'version': this.version,
};
var path = {
'assistant_id': _params.assistantId,
'environment_id': _params.environmentId,
'session_id': _params.sessionId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(AssistantV2.DEFAULT_SERVICE_NAME, 'v2', 'messageStream');
var parameters = {
options: {
url: '/v2/assistants/{assistant_id}/environments/{environment_id}/sessions/{session_id}/message_stream',
method: 'POST',
body: body,
qs: query,
path: path,
responseType: 'stream',
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'text/event-stream',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/**
* Send user input to assistant (stateless).
*
* Send user input to an assistant and receive a response, with conversation state (including context data) managed by
* your application.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.assistantId - The assistant ID or the environment ID of the environment where the assistant
* is deployed, depending on the type of request:
* - For message, session, and log requests, specify the environment ID of the environment where the assistant is
* deployed.
* - For all other requests, specify the assistant ID of the assistant.
*
* To find the environment ID or assistant ID in the watsonx Assistant user interface, open the assistant settings
* and scroll to the **Environments** section.
*
* **Note:** If you are using the classic Watson Assistant experience, always use the assistant ID. To find the
* assistant ID in the user interface, open the assistant settings and click API Details.
* @param {string} params.environmentId - Unique identifier of the environment. To find the environment ID in the
* watsonx Assistant user interface, open the environment settings and click **API Details**. **Note:** Currently, the
* API does not support creating environments.
* @param {MessageInput} [params.input] - An input object that includes the input text.
* @param {MessageContext} [params.context] - Context data for the conversation. You can use this property to set or
* modify context variables, which can also be accessed by dialog nodes. The context is stored by the assistant on a
* per-session basis.
*
* **Note:** The total size of the context data stored for a stateful session cannot exceed 100KB.
* @param {string} [params.userId] - A string value that identifies the user who is interacting with the assistant.
* The client must provide a unique identifier for each individual end user who accesses the application. For
* user-based plans, this user ID is used to identify unique users for billing purposes. This string cannot contain
* carriage return, newline, or tab characters. If no value is specified in the input, **user_id** is automatically
* set to the value of **context.global.session_id**.
*
* **Note:** This property is the same as the **user_id** property in the global system context. If **user_id** is
* specified in both locations, the value specified at the root is used.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<AssistantV2.Response<NodeJS.ReadableStream>>}
*/
AssistantV2.prototype.messageStreamStateless = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['assistantId', 'environmentId'];
var _validParams = ['assistantId', 'environmentId', 'input', 'context', 'userId', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var body = {
'input': _params.input,
'context': _params.context,
'user_id': _params.userId,
};
var query = {
'version': this.version,
};
var path = {
'assistant_id': _params.assistantId,
'environment_id': _params.environmentId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(AssistantV2.DEFAULT_SERVICE_NAME, 'v2', 'messageStreamStateless');
var parameters = {
options: {
url: '/v2/assistants/{assistant_id}/environments/{environment_id}/message_stream',
method: 'POST',
body: body,
qs: query,
path: path,
responseType: 'stream',
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'text/event-stream',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/*************************
* bulkClassify
************************/
/**
* Identify intents and entities in multiple user utterances.
*
* Send multiple user inputs to a dialog skill in a single request and receive information about the intents and
* entities recognized in each input. This method is useful for testing and comparing the performance of different
* skills or skill versions.
*
* This method is available only with Enterprise with Data Isolation plans.
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.skillId - Unique identifier of the skill. To find the skill ID in the watsonx Assistant user
* interface, open the skill settings and click **API Details**.
* @param {BulkClassifyUtterance[]} params.input - An array of input utterances to classify.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<AssistantV2.Response<AssistantV2.BulkClassifyResponse>>}
*/
AssistantV2.prototype.bulkClassify = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['skillId', 'input'];
var _validParams = ['skillId', 'input', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var body = {
'input': _params.input,
};
var query = {
'version': this.version,
};
var path = {
'skill_id': _params.skillId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(AssistantV2.DEFAULT_SERVICE_NAME, 'v2', 'bulkClassify');
var parameters = {
options: {
url: '/v2/skills/{skill_id}/workspace/bulk_classify',
method: 'POST',
body: body,
qs: query,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
'Content-Type': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/*************************
* logs
************************/
/**
* List log events for an assistant.
*
* List the events from the log of an assistant.
*
* This method requires Manager access.
*
* **Note:** If you use the **cursor** parameter to retrieve results one page at a time, subsequent requests must be
* no more than 5 minutes apart. Any returned value for the **cursor** parameter becomes invalid after 5 minutes. For
* more information about using pagination, see [Pagination](#pagination).
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.assistantId - The assistant ID or the environment ID of the environment where the assistant
* is deployed, depending on the type of request:
* - For message, session, and log requests, specify the environment ID of the environment where the assistant is
* deployed.
* - For all other requests, specify the assistant ID of the assistant.
*
* To find the environment ID or assistant ID in the watsonx Assistant user interface, open the assistant settings
* and scroll to the **Environments** section.
*
* **Note:** If you are using the classic Watson Assistant experience, always use the assistant ID. To find the
* assistant ID in the user interface, open the assistant settings and click API Details.
* @param {string} [params.sort] - How to sort the returned log events. You can sort by **request_timestamp**. To
* reverse the sort order, prefix the parameter value with a minus sign (`-`).
* @param {string} [params.filter] - A cacheable parameter that limits the results to those matching the specified
* filter. For more information, see the
* [documentation](https://cloud.ibm.com/docs/assistant?topic=assistant-filter-reference#filter-reference).
* @param {number} [params.pageLimit] - The number of records to return in each page of results.
*
* **Note:** If the API is not returning your data, try lowering the page_limit value.
* @param {string} [params.cursor] - A token identifying the page of results to retrieve.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<AssistantV2.Response<AssistantV2.LogCollection>>}
*/
AssistantV2.prototype.listLogs = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['assistantId'];
var _validParams = ['assistantId', 'sort', 'filter', 'pageLimit', 'cursor', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var query = {
'version': this.version,
'sort': _params.sort,
'filter': _params.filter,
'page_limit': _params.pageLimit,
'cursor': _params.cursor,
};
var path = {
'assistant_id': _params.assistantId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(AssistantV2.DEFAULT_SERVICE_NAME, 'v2', 'listLogs');
var parameters = {
options: {
url: '/v2/assistants/{assistant_id}/logs',
method: 'GET',
qs: query,
path: path,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/*************************
* userData
************************/
/**
* Delete labeled data.
*
* Deletes all data associated with a specified customer ID. The method has no effect if no data is associated with
* the customer ID.
*
* You associate a customer ID with data by passing the `X-Watson-Metadata` header with a request that passes data.
* For more information about personal data and customer IDs, see [Information
* security](https://cloud.ibm.com/docs/assistant?topic=assistant-information-security#information-security).
*
* **Note:** This operation is intended only for deleting data associated with a single specific customer, not for
* deleting data associated with multiple customers or for any other purpose. For more information, see [Labeling and
* deleting data in watsonx
* Assistant](https://cloud.ibm.com/docs/assistant?topic=assistant-information-security#information-security-gdpr-wa).
*
* @param {Object} params - The parameters to send to the service.
* @param {string} params.customerId - The customer ID for which all data is to be deleted.
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
* @returns {Promise<AssistantV2.Response<AssistantV2.EmptyObject>>}
*/
AssistantV2.prototype.deleteUserData = function (params) {
var _params = __assign({}, params);
var _requiredParams = ['customerId'];
var _validParams = ['customerId', 'headers'];
var _validationErrors = (0, ibm_cloud_sdk_core_1.validateParams)(_params, _requiredParams, _validParams);
if (_validationErrors) {
return Promise.reject(_validationErrors);
}
var query = {
'version': this.version,
'customer_id': _params.customerId,
};
var sdkHeaders = (0, common_1.getSdkHeaders)(AssistantV2.DEFAULT_SERVICE_NAME, 'v2', 'deleteUserData');
var parameters = {
options: {
url: '/v2/user_data',
method: 'DELETE',
qs: query,
},
defaultOptions: extend(true, {}, this.baseOptions, {
headers: extend(true, sdkHeaders, {
'Accept': 'application/json',
}, _params.headers),
}),
};
return this.createRequest(parameters);
};
/*************************
* environments
************************/
/**
*