Skip to content

Commit 800afbe

Browse files
committed
fix: change Object types to custom JsonObject
use node http types for headers
1 parent 289a62b commit 800afbe

24 files changed

Lines changed: 7669 additions & 1371 deletions

File tree

assistant/v1.ts

Lines changed: 304 additions & 248 deletions
Large diffs are not rendered by default.

assistant/v2.ts

Lines changed: 68 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2018 IBM All Rights Reserved.
2+
* Copyright 2019 IBM All Rights Reserved.
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.
@@ -14,8 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { AxiosResponse } from 'axios';
1817
import * as extend from 'extend';
18+
import { IncomingHttpHeaders, OutgoingHttpHeaders } from 'http';
1919
import { BaseService, getMissingParams } from 'ibm-cloud-sdk-core';
2020
import { getSdkHeaders } from '../lib/common';
2121

@@ -40,9 +40,18 @@ class AssistantV2 extends BaseService {
4040
* @param {string} [options.iam_access_token] - An IAM access token fully managed by the application. Responsibility falls on the application to refresh the token, either before it expires or reactively upon receiving a 401 from the service, as any requests made with an expired token will fail.
4141
* @param {string} [options.iam_apikey] - An API key that can be used to request IAM tokens. If this API key is provided, the SDK will manage the token and handle the refreshing.
4242
* @param {string} [options.iam_url] - An optional URL for the IAM service API. Defaults to 'https://iam.cloud.ibm.com/identity/token'.
43-
* @param {boolean} [options.use_unauthenticated] - Set to `true` to avoid including an authorization header. This option may be useful for requests that are proxied.
44-
* @param {Object} [options.headers] - Default headers that shall be included with every request to the service.
45-
* @param {boolean} [options.headers.X-Watson-Learning-Opt-Out] - Set to `true` to opt-out of data collection. By default, all IBM Watson services log requests and their results. Logging is done only to improve the services for future users. The logged data is not shared or made public. If you are concerned with protecting the privacy of users' personal information or otherwise do not want your requests to be logged, you can opt out of logging.
43+
* @param {string} [options.iam_client_id] - client id (username) for request to iam service
44+
* @param {string} [options.iam_client_secret] - client secret (password) for request to iam service
45+
* @param {string} [options.icp4d_access_token] - icp for data access token provided and managed by user
46+
* @param {string} [options.icp4d_url] - icp for data base url - used for authentication
47+
* @param {string} [options.authentication_type] - authentication pattern to be used. can be iam, basic, or icp4d
48+
* @param {boolean} [options.use_unauthenticated] - Set to `true` to avoid including an authorization header. This
49+
* option may be useful for requests that are proxied.
50+
* @param {OutgoingHttpHeaders} [options.headers] - Default headers that shall be included with every request to the service.
51+
* @param {boolean} [options.headers.X-Watson-Learning-Opt-Out] - Set to `true` to opt-out of data collection. By
52+
* default, all IBM Watson services log requests and their results. Logging is done only to improve the services for
53+
* future users. The logged data is not shared or made public. If you are concerned with protecting the privacy of
54+
* users' personal information or otherwise do not want your requests to be logged, you can opt out of logging.
4655
* @constructor
4756
* @returns {AssistantV2}
4857
* @throws {Error}
@@ -67,12 +76,13 @@ class AssistantV2 extends BaseService {
6776
* state of the conversation.
6877
*
6978
* @param {Object} params - The parameters to send to the service.
70-
* @param {string} params.assistant_id - Unique identifier of the assistant. You can find the assistant ID of an
71-
* assistant on the **Assistants** tab of the Watson Assistant tool. For information about creating assistants, see
72-
* the [documentation](https://cloud.ibm.com/docs/services/assistant?topic=assistant-assistant-add#assistant-add-task).
79+
* @param {string} params.assistant_id - Unique identifier of the assistant. To find the assistant ID in the Watson
80+
* Assistant tool, open the assistant settings and click **API Details**. For information about creating assistants,
81+
* see the
82+
* [documentation](https://cloud.ibm.com/docs/services/assistant?topic=assistant-assistant-add#assistant-add-task).
7383
*
7484
* **Note:** Currently, the v2 API does not support creating assistants.
75-
* @param {Object} [params.headers] - Custom request headers
85+
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
7686
* @param {Function} [callback] - The callback that handles the response.
7787
* @returns {Promise<any>|void}
7888
*/
@@ -122,13 +132,14 @@ class AssistantV2 extends BaseService {
122132
* Deletes a session explicitly before it times out.
123133
*
124134
* @param {Object} params - The parameters to send to the service.
125-
* @param {string} params.assistant_id - Unique identifier of the assistant. You can find the assistant ID of an
126-
* assistant on the **Assistants** tab of the Watson Assistant tool. For information about creating assistants, see
127-
* the [documentation](https://cloud.ibm.com/docs/services/assistant?topic=assistant-assistant-add#assistant-add-task).
135+
* @param {string} params.assistant_id - Unique identifier of the assistant. To find the assistant ID in the Watson
136+
* Assistant tool, open the assistant settings and click **API Details**. For information about creating assistants,
137+
* see the
138+
* [documentation](https://cloud.ibm.com/docs/services/assistant?topic=assistant-assistant-add#assistant-add-task).
128139
*
129140
* **Note:** Currently, the v2 API does not support creating assistants.
130141
* @param {string} params.session_id - Unique identifier of the session.
131-
* @param {Object} [params.headers] - Custom request headers
142+
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
132143
* @param {Function} [callback] - The callback that handles the response.
133144
* @returns {Promise<any>|void}
134145
*/
@@ -185,17 +196,18 @@ class AssistantV2 extends BaseService {
185196
* There is no rate limit for this operation.
186197
*
187198
* @param {Object} params - The parameters to send to the service.
188-
* @param {string} params.assistant_id - Unique identifier of the assistant. You can find the assistant ID of an
189-
* assistant on the **Assistants** tab of the Watson Assistant tool. For information about creating assistants, see
190-
* the [documentation](https://cloud.ibm.com/docs/services/assistant?topic=assistant-assistant-add#assistant-add-task).
199+
* @param {string} params.assistant_id - Unique identifier of the assistant. To find the assistant ID in the Watson
200+
* Assistant tool, open the assistant settings and click **API Details**. For information about creating assistants,
201+
* see the
202+
* [documentation](https://cloud.ibm.com/docs/services/assistant?topic=assistant-assistant-add#assistant-add-task).
191203
*
192204
* **Note:** Currently, the v2 API does not support creating assistants.
193205
* @param {string} params.session_id - Unique identifier of the session.
194206
* @param {MessageInput} [params.input] - An input object that includes the input text.
195207
* @param {MessageContext} [params.context] - State information for the conversation. The context is stored by the
196208
* assistant on a per-session basis. You can use this property to set or modify context variables, which can also be
197209
* accessed by dialog nodes.
198-
* @param {Object} [params.headers] - Custom request headers
210+
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
199211
* @param {Function} [callback] - The callback that handles the response.
200212
* @returns {Promise<any>|void}
201213
*/
@@ -265,51 +277,71 @@ namespace AssistantV2 {
265277
iam_access_token?: string;
266278
iam_apikey?: string;
267279
iam_url?: string;
280+
iam_client_id?: string;
281+
iam_client_secret?: string;
282+
icp4d_access_token?: string;
283+
icp4d_url?: string;
268284
username?: string;
269285
password?: string;
286+
token?: string;
287+
authentication_type?: string;
288+
disable_ssl_verification?: boolean;
270289
use_unauthenticated?: boolean;
271-
headers?: object;
290+
headers?: OutgoingHttpHeaders;
291+
}
292+
293+
export interface Response<T = any> {
294+
result: T;
295+
data: T; // for compatibility
296+
status: number;
297+
statusText: string;
298+
headers: IncomingHttpHeaders;
272299
}
273300

274301
/** The callback for a service request. */
275-
export type Callback<T> = (error: any, body?: T, response?: AxiosResponse<T>) => void;
302+
export type Callback<T> = (error: any, body?: T, response?: Response<T>) => void;
276303

277304
/** The body of a service request that returns no response data. */
278305
export interface Empty { }
279306

307+
/** A standard JS object, defined to avoid the limitations of `Object` and `object` */
308+
export interface JsonObject {
309+
[key: string]: any;
310+
}
311+
280312
/*************************
281313
* request interfaces
282314
************************/
283315

284316
/** Parameters for the `createSession` operation. */
285317
export interface CreateSessionParams {
286-
/** Unique identifier of the assistant. You can find the assistant ID of an assistant on the **Assistants** tab of the Watson Assistant tool. For information about creating assistants, see the [documentation](https://cloud.ibm.com/docs/services/assistant?topic=assistant-assistant-add#assistant-add-task). **Note:** Currently, the v2 API does not support creating assistants. */
318+
/** Unique identifier of the assistant. To find the assistant ID in the Watson Assistant tool, open the assistant settings and click **API Details**. For information about creating assistants, see the [documentation](https://cloud.ibm.com/docs/services/assistant?topic=assistant-assistant-add#assistant-add-task). **Note:** Currently, the v2 API does not support creating assistants. */
287319
assistant_id: string;
288-
headers?: Object;
320+
headers?: OutgoingHttpHeaders;
289321
return_response?: boolean;
290322
}
291323

292324
/** Parameters for the `deleteSession` operation. */
293325
export interface DeleteSessionParams {
294-
/** Unique identifier of the assistant. You can find the assistant ID of an assistant on the **Assistants** tab of the Watson Assistant tool. For information about creating assistants, see the [documentation](https://cloud.ibm.com/docs/services/assistant?topic=assistant-assistant-add#assistant-add-task). **Note:** Currently, the v2 API does not support creating assistants. */
326+
/** Unique identifier of the assistant. To find the assistant ID in the Watson Assistant tool, open the assistant settings and click **API Details**. For information about creating assistants, see the [documentation](https://cloud.ibm.com/docs/services/assistant?topic=assistant-assistant-add#assistant-add-task). **Note:** Currently, the v2 API does not support creating assistants. */
295327
assistant_id: string;
296328
/** Unique identifier of the session. */
297329
session_id: string;
298-
headers?: Object;
330+
headers?: OutgoingHttpHeaders;
299331
return_response?: boolean;
300332
}
301333

302334
/** Parameters for the `message` operation. */
303335
export interface MessageParams {
304-
/** Unique identifier of the assistant. You can find the assistant ID of an assistant on the **Assistants** tab of the Watson Assistant tool. For information about creating assistants, see the [documentation](https://cloud.ibm.com/docs/services/assistant?topic=assistant-assistant-add#assistant-add-task). **Note:** Currently, the v2 API does not support creating assistants. */
336+
/** Unique identifier of the assistant. To find the assistant ID in the Watson Assistant tool, open the assistant settings and click **API Details**. For information about creating assistants, see the [documentation](https://cloud.ibm.com/docs/services/assistant?topic=assistant-assistant-add#assistant-add-task). **Note:** Currently, the v2 API does not support creating assistants. */
305337
assistant_id: string;
306338
/** Unique identifier of the session. */
307339
session_id: string;
308340
/** An input object that includes the input text. */
309341
input?: MessageInput;
310342
/** State information for the conversation. The context is stored by the assistant on a per-session basis. You can use this property to set or modify context variables, which can also be accessed by dialog nodes. */
311343
context?: MessageContext;
312-
headers?: Object;
344+
headers?: OutgoingHttpHeaders;
313345
return_response?: boolean;
314346
}
315347

@@ -340,7 +372,7 @@ namespace AssistantV2 {
340372
/** The type of action to invoke. */
341373
action_type?: string;
342374
/** A map of key/value pairs to be provided to the action. */
343-
parameters?: Object;
375+
parameters?: JsonObject;
344376
/** The location in the dialog context where the result of the action is stored. */
345377
result_variable: string;
346378
/** The name of the context variable that the client application will use to pass in credentials for the action. */
@@ -406,7 +438,7 @@ namespace AssistantV2 {
406438
/** An object defining the message input to be sent to the assistant if the user selects the corresponding disambiguation option. */
407439
value: DialogSuggestionValue;
408440
/** The dialog output that will be returned from the Watson Assistant service if the user selects the corresponding option. */
409-
output?: Object;
441+
output?: JsonObject;
410442
}
411443

412444
/** An object defining the message input to be sent to the assistant if the user selects the corresponding disambiguation option. */
@@ -439,6 +471,12 @@ namespace AssistantV2 {
439471
turn_count?: number;
440472
}
441473

474+
/** Contains information specific to a particular skill used by the Assistant. */
475+
export interface MessageContextSkill {
476+
/** Arbitrary variables that can be read and written by a particular skill. */
477+
user_defined?: JsonObject;
478+
}
479+
442480
/** 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. */
443481
export interface MessageContextSkills {
444482
/** MessageContextSkills accepts additional properties. */
@@ -449,7 +487,7 @@ namespace AssistantV2 {
449487
export interface MessageInput {
450488
/** The type of user input. Currently, only text input is supported. */
451489
message_type?: string;
452-
/** The text of the user input. This string cannot contain carriage return, newline, or tab characters, and it must be no longer than 2048 characters. */
490+
/** The text of the user input. This string cannot contain carriage return, newline, or tab characters. */
453491
text?: string;
454492
/** Optional properties that control how the assistant responds. */
455493
options?: MessageInputOptions;
@@ -486,7 +524,7 @@ namespace AssistantV2 {
486524
/** Additional detailed information about a message response and how it was generated. */
487525
debug?: MessageOutputDebug;
488526
/** An object containing any custom properties included in the response. This object includes any arbitrary properties defined in the dialog JSON editor as part of the dialog node output. */
489-
user_defined?: Object;
527+
user_defined?: JsonObject;
490528
}
491529

492530
/** Additional detailed information about a message response and how it was generated. */
@@ -520,7 +558,7 @@ namespace AssistantV2 {
520558
/** A decimal percentage that represents Watson's confidence in the entity. */
521559
confidence?: number;
522560
/** Any metadata for the entity. */
523-
metadata?: Object;
561+
metadata?: JsonObject;
524562
/** The recognized capture groups for the entity, as defined by the entity pattern. */
525563
groups?: CaptureGroup[];
526564
}

0 commit comments

Comments
 (0)