Skip to content

Commit 964e9e1

Browse files
committed
feat: add serviceName parameter for all services
this allows for configuring what external credentials are read other changes: * (NLU) optional property `model` removed from `CategoriesOptions` interface * (TTS) new constants added to `Voice` enum
1 parent c3f1ead commit 964e9e1

27 files changed

Lines changed: 2505 additions & 8874 deletions

assistant/v1.ts

Lines changed: 150 additions & 190 deletions
Large diffs are not rendered by default.

assistant/v2.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* (C) Copyright IBM Corp. 2018, 2019.
2+
* (C) Copyright IBM Corp. 2018, 2020.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,8 +16,7 @@
1616

1717
import * as extend from 'extend';
1818
import { IncomingHttpHeaders, OutgoingHttpHeaders } from 'http';
19-
import { Authenticator, BaseService, getMissingParams, UserOptions } from 'ibm-cloud-sdk-core';
20-
import { getAuthenticatorFromEnvironment } from 'ibm-cloud-sdk-core';
19+
import { Authenticator, BaseService, getAuthenticatorFromEnvironment, getMissingParams, UserOptions } from 'ibm-cloud-sdk-core';
2120
import { getSdkHeaders } from '../lib/common';
2221

2322
/**
@@ -30,9 +29,8 @@ import { getSdkHeaders } from '../lib/common';
3029

3130
class AssistantV2 extends BaseService {
3231

33-
static URL: string = 'https://gateway.watsonplatform.net/assistant/api';
34-
name: string; // set by prototype to 'conversation'
35-
serviceVersion: string; // set by prototype to 'v2'
32+
static DEFAULT_SERVICE_URL: string = 'https://gateway.watsonplatform.net/assistant/api';
33+
static DEFAULT_SERVICE_NAME: string = 'conversation';
3634

3735
/**
3836
* Construct a AssistantV2 object.
@@ -46,17 +44,25 @@ class AssistantV2 extends BaseService {
4644
* application is ready for a later version.
4745
* @param {string} [options.serviceUrl] - The base url to use when contacting the service (e.g. 'https://gateway.watsonplatform.net/assistant/api'). The base url may differ between IBM Cloud regions.
4846
* @param {OutgoingHttpHeaders} [options.headers] - Default headers that shall be included with every request to the service.
47+
* @param {string} [options.serviceName] - The name of the service to configure
4948
* @param {Authenticator} [options.authenticator] - The Authenticator object used to authenticate requests to the service. Defaults to environment if not set
5049
* @constructor
5150
* @returns {AssistantV2}
5251
* @throws {Error}
5352
*/
5453
constructor(options: UserOptions) {
54+
if (!options.serviceName) {
55+
options.serviceName = AssistantV2.DEFAULT_SERVICE_NAME;
56+
}
5557
// If the caller didn't supply an authenticator, construct one from external configuration.
5658
if (!options.authenticator) {
57-
options.authenticator = getAuthenticatorFromEnvironment('conversation');
59+
options.authenticator = getAuthenticatorFromEnvironment(options.serviceName);
5860
}
5961
super(options);
62+
this.configureService(options.serviceName);
63+
if (options.serviceUrl) {
64+
this.setServiceUrl(options.serviceUrl);
65+
}
6066
// check if 'version' was provided
6167
if (typeof this.baseOptions.version === 'undefined') {
6268
throw new Error('Argument error: version was not specified');
@@ -84,16 +90,15 @@ class AssistantV2 extends BaseService {
8490
*
8591
* **Note:** Currently, the v2 API does not support creating assistants.
8692
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
87-
* @param {Function} [callback] - The callback that handles the response.
88-
* @returns {Promise<any>|void}
93+
* @param {Function} [callback] - The callback that handles the response
94+
* @returns {Promise<AssistantV2.Response<AssistantV2.SessionResponse>>}
8995
*/
9096
public createSession(params: AssistantV2.CreateSessionParams, callback?: AssistantV2.Callback<AssistantV2.SessionResponse>): Promise<AssistantV2.Response<AssistantV2.SessionResponse>> {
9197
const _params = extend({}, params);
9298
const _callback = callback;
9399
const requiredParams = ['assistantId'];
94100

95101
return new Promise((resolve, reject) => {
96-
97102
const missingParams = getMissingParams(_params, requiredParams);
98103
if (missingParams) {
99104
if (_callback) {
@@ -107,7 +112,7 @@ class AssistantV2 extends BaseService {
107112
'assistant_id': _params.assistantId
108113
};
109114

110-
const sdkHeaders = getSdkHeaders('conversation', 'v2', 'createSession');
115+
const sdkHeaders = getSdkHeaders(AssistantV2.DEFAULT_SERVICE_NAME, 'v2', 'createSession');
111116

112117
const parameters = {
113118
options: {
@@ -155,16 +160,15 @@ class AssistantV2 extends BaseService {
155160
* **Note:** Currently, the v2 API does not support creating assistants.
156161
* @param {string} params.sessionId - Unique identifier of the session.
157162
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
158-
* @param {Function} [callback] - The callback that handles the response.
159-
* @returns {Promise<any>|void}
163+
* @param {Function} [callback] - The callback that handles the response
164+
* @returns {Promise<AssistantV2.Response<AssistantV2.Empty>>}
160165
*/
161166
public deleteSession(params: AssistantV2.DeleteSessionParams, callback?: AssistantV2.Callback<AssistantV2.Empty>): Promise<AssistantV2.Response<AssistantV2.Empty>> {
162167
const _params = extend({}, params);
163168
const _callback = callback;
164169
const requiredParams = ['assistantId', 'sessionId'];
165170

166171
return new Promise((resolve, reject) => {
167-
168172
const missingParams = getMissingParams(_params, requiredParams);
169173
if (missingParams) {
170174
if (_callback) {
@@ -179,7 +183,7 @@ class AssistantV2 extends BaseService {
179183
'session_id': _params.sessionId
180184
};
181185

182-
const sdkHeaders = getSdkHeaders('conversation', 'v2', 'deleteSession');
186+
const sdkHeaders = getSdkHeaders(AssistantV2.DEFAULT_SERVICE_NAME, 'v2', 'deleteSession');
183187

184188
const parameters = {
185189
options: {
@@ -236,16 +240,15 @@ class AssistantV2 extends BaseService {
236240
* assistant on a per-session basis. You can use this property to set or modify context variables, which can also be
237241
* accessed by dialog nodes.
238242
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
239-
* @param {Function} [callback] - The callback that handles the response.
240-
* @returns {Promise<any>|void}
243+
* @param {Function} [callback] - The callback that handles the response
244+
* @returns {Promise<AssistantV2.Response<AssistantV2.MessageResponse>>}
241245
*/
242246
public message(params: AssistantV2.MessageParams, callback?: AssistantV2.Callback<AssistantV2.MessageResponse>): Promise<AssistantV2.Response<AssistantV2.MessageResponse>> {
243247
const _params = extend({}, params);
244248
const _callback = callback;
245249
const requiredParams = ['assistantId', 'sessionId'];
246250

247251
return new Promise((resolve, reject) => {
248-
249252
const missingParams = getMissingParams(_params, requiredParams);
250253
if (missingParams) {
251254
if (_callback) {
@@ -265,7 +268,7 @@ class AssistantV2 extends BaseService {
265268
'session_id': _params.sessionId
266269
};
267270

268-
const sdkHeaders = getSdkHeaders('conversation', 'v2', 'message');
271+
const sdkHeaders = getSdkHeaders(AssistantV2.DEFAULT_SERVICE_NAME, 'v2', 'message');
269272

270273
const parameters = {
271274
options: {
@@ -302,9 +305,6 @@ class AssistantV2 extends BaseService {
302305

303306
}
304307

305-
AssistantV2.prototype.name = 'conversation';
306-
AssistantV2.prototype.serviceVersion = 'v2';
307-
308308
/*************************
309309
* interfaces
310310
************************/
@@ -501,6 +501,8 @@ namespace AssistantV2 {
501501
export interface MessageContextSkill {
502502
/** Arbitrary variables that can be read and written by a particular skill. */
503503
user_defined?: JsonObject;
504+
/** For internal use only. */
505+
system?: JsonObject;
504506
}
505507

506508
/** Information specific to particular skills used by the Assistant. **Note:** Currently, only a single property named `main skill` is supported. This object contains variables that apply to the dialog skill used by the assistant. */

0 commit comments

Comments
 (0)