Skip to content

Commit ff6b79c

Browse files
feat(assistant-v2): new method: listLogs
1 parent 6afcb0f commit ff6b79c

File tree

2 files changed

+421
-20
lines changed

2 files changed

+421
-20
lines changed

assistant/v2.ts

Lines changed: 260 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { getSdkHeaders } from '../lib/common';
2929

3030
class AssistantV2 extends BaseService {
3131

32-
static DEFAULT_SERVICE_URL: string = 'https://gateway.watsonplatform.net/assistant/api';
32+
static DEFAULT_SERVICE_URL: string = 'https://api.us-south.assistant.watson.cloud.ibm.com';
3333
static DEFAULT_SERVICE_NAME: string = 'conversation';
3434

3535
/**
@@ -42,7 +42,7 @@ class AssistantV2 extends BaseService {
4242
* programmatically specify the current date at runtime, in case the API has been updated since your application's
4343
* release. Instead, specify a version date that is compatible with your application, and don't change it until your
4444
* application is ready for a later version.
45-
* @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.
45+
* @param {string} [options.serviceUrl] - The base url to use when contacting the service (e.g. 'https://gateway.watsonplatform.net'). The base url may differ between IBM Cloud regions.
4646
* @param {OutgoingHttpHeaders} [options.headers] - Default headers that shall be included with every request to the service.
4747
* @param {string} [options.serviceName] - The name of the service to configure
4848
* @param {Authenticator} [options.authenticator] - The Authenticator object used to authenticate requests to the service. Defaults to environment if not set
@@ -226,8 +226,6 @@ class AssistantV2 extends BaseService {
226226
* Send user input to an assistant and receive a response, with conversation state (including context data) stored by
227227
* Watson Assistant for the duration of the session.
228228
*
229-
* There is no rate limit for this operation.
230-
*
231229
* @param {Object} params - The parameters to send to the service.
232230
* @param {string} params.assistantId - Unique identifier of the assistant. To find the assistant ID in the Watson
233231
* Assistant user interface, open the assistant settings and click **API Details**. For information about creating
@@ -312,8 +310,6 @@ class AssistantV2 extends BaseService {
312310
* Send user input to an assistant and receive a response, with conversation state (including context data) managed by
313311
* your application.
314312
*
315-
* There is no rate limit for this operation.
316-
*
317313
* @param {Object} params - The parameters to send to the service.
318314
* @param {string} params.assistantId - Unique identifier of the assistant. To find the assistant ID in the Watson
319315
* Assistant user interface, open the assistant settings and click **API Details**. For information about creating
@@ -390,6 +386,170 @@ class AssistantV2 extends BaseService {
390386
});
391387
};
392388

389+
/*************************
390+
* logs
391+
************************/
392+
393+
/**
394+
* List log events for an assistant.
395+
*
396+
* List the events from the log of an assistant.
397+
*
398+
* If **cursor** is not specified, this operation is limited to 40 requests per 30 minutes. If **cursor** is
399+
* specified, the limit is 120 requests per minute. For more information, see **Rate limiting**.
400+
*
401+
* @param {Object} params - The parameters to send to the service.
402+
* @param {string} params.assistantId - Unique identifier of the assistant. To find the assistant ID in the Watson
403+
* Assistant user interface, open the assistant settings and click **API Details**. For information about creating
404+
* assistants, see the
405+
* [documentation](https://cloud.ibm.com/docs/assistant?topic=assistant-assistant-add#assistant-add-task).
406+
*
407+
* **Note:** Currently, the v2 API does not support creating assistants.
408+
* @param {string} [params.sort] - How to sort the returned log events. You can sort by **request_timestamp**. To
409+
* reverse the sort order, prefix the parameter value with a minus sign (`-`).
410+
* @param {string} [params.filter] - A cacheable parameter that limits the results to those matching the specified
411+
* filter. For more information, see the
412+
* [documentation](https://cloud.ibm.com/docs/assistant?topic=assistant-filter-reference#filter-reference).
413+
* @param {number} [params.pageLimit] - The number of records to return in each page of results.
414+
* @param {string} [params.cursor] - A token identifying the page of results to retrieve.
415+
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
416+
* @param {Function} [callback] - The callback that handles the response
417+
* @returns {Promise<AssistantV2.Response<AssistantV2.LogCollection>>}
418+
*/
419+
public listLogs(params: AssistantV2.ListLogsParams, callback?: AssistantV2.Callback<AssistantV2.LogCollection>): Promise<AssistantV2.Response<AssistantV2.LogCollection>> {
420+
const _params = extend({}, params);
421+
const _callback = callback;
422+
const requiredParams = ['assistantId'];
423+
424+
return new Promise((resolve, reject) => {
425+
const missingParams = getMissingParams(_params, requiredParams);
426+
if (missingParams) {
427+
if (_callback) {
428+
_callback(missingParams);
429+
return resolve();
430+
}
431+
return reject(missingParams);
432+
}
433+
434+
const query = {
435+
'sort': _params.sort,
436+
'filter': _params.filter,
437+
'page_limit': _params.pageLimit,
438+
'cursor': _params.cursor
439+
};
440+
441+
const path = {
442+
'assistant_id': _params.assistantId
443+
};
444+
445+
const sdkHeaders = getSdkHeaders(AssistantV2.DEFAULT_SERVICE_NAME, 'v2', 'listLogs');
446+
447+
const parameters = {
448+
options: {
449+
url: '/v2/assistants/{assistant_id}/logs',
450+
method: 'GET',
451+
qs: query,
452+
path,
453+
},
454+
defaultOptions: extend(true, {}, this.baseOptions, {
455+
headers: extend(true, sdkHeaders, {
456+
'Accept': 'application/json',
457+
}, _params.headers),
458+
}),
459+
};
460+
461+
return this.createRequest(parameters).then(
462+
res => {
463+
if (_callback) {
464+
_callback(null, res);
465+
}
466+
return resolve(res);
467+
},
468+
err => {
469+
if (_callback) {
470+
_callback(err)
471+
return resolve();
472+
}
473+
return reject(err);
474+
}
475+
);
476+
});
477+
};
478+
479+
/*************************
480+
* userData
481+
************************/
482+
483+
/**
484+
* Delete labeled data.
485+
*
486+
* Deletes all data associated with a specified customer ID. The method has no effect if no data is associated with
487+
* the customer ID.
488+
*
489+
* You associate a customer ID with data by passing the `X-Watson-Metadata` header with a request that passes data.
490+
* For more information about personal data and customer IDs, see [Information
491+
* security](https://cloud.ibm.com/docs/assistant?topic=assistant-information-security#information-security).
492+
*
493+
* This operation is limited to 4 requests per minute. For more information, see **Rate limiting**.
494+
*
495+
* @param {Object} params - The parameters to send to the service.
496+
* @param {string} params.customerId - The customer ID for which all data is to be deleted.
497+
* @param {OutgoingHttpHeaders} [params.headers] - Custom request headers
498+
* @param {Function} [callback] - The callback that handles the response
499+
* @returns {Promise<AssistantV2.Response<AssistantV2.Empty>>}
500+
*/
501+
public deleteUserData(params: AssistantV2.DeleteUserDataParams, callback?: AssistantV2.Callback<AssistantV2.Empty>): Promise<AssistantV2.Response<AssistantV2.Empty>> {
502+
const _params = extend({}, params);
503+
const _callback = callback;
504+
const requiredParams = ['customerId'];
505+
506+
return new Promise((resolve, reject) => {
507+
const missingParams = getMissingParams(_params, requiredParams);
508+
if (missingParams) {
509+
if (_callback) {
510+
_callback(missingParams);
511+
return resolve();
512+
}
513+
return reject(missingParams);
514+
}
515+
516+
const query = {
517+
'customer_id': _params.customerId
518+
};
519+
520+
const sdkHeaders = getSdkHeaders(AssistantV2.DEFAULT_SERVICE_NAME, 'v2', 'deleteUserData');
521+
522+
const parameters = {
523+
options: {
524+
url: '/v2/user_data',
525+
method: 'DELETE',
526+
qs: query,
527+
},
528+
defaultOptions: extend(true, {}, this.baseOptions, {
529+
headers: extend(true, sdkHeaders, {
530+
'Accept': 'application/json',
531+
}, _params.headers),
532+
}),
533+
};
534+
535+
return this.createRequest(parameters).then(
536+
res => {
537+
if (_callback) {
538+
_callback(null, res);
539+
}
540+
return resolve(res);
541+
},
542+
err => {
543+
if (_callback) {
544+
_callback(err)
545+
return resolve();
546+
}
547+
return reject(err);
548+
}
549+
);
550+
});
551+
};
552+
393553
}
394554

395555
/*************************
@@ -490,6 +650,37 @@ namespace AssistantV2 {
490650
headers?: OutgoingHttpHeaders;
491651
}
492652

653+
/** Parameters for the `listLogs` operation. */
654+
export interface ListLogsParams {
655+
/** Unique identifier of the assistant. To find the assistant ID in the Watson Assistant user interface, open
656+
* the assistant settings and click **API Details**. For information about creating assistants, see the
657+
* [documentation](https://cloud.ibm.com/docs/assistant?topic=assistant-assistant-add#assistant-add-task).
658+
*
659+
* **Note:** Currently, the v2 API does not support creating assistants.
660+
*/
661+
assistantId: string;
662+
/** How to sort the returned log events. You can sort by **request_timestamp**. To reverse the sort order,
663+
* prefix the parameter value with a minus sign (`-`).
664+
*/
665+
sort?: string;
666+
/** A cacheable parameter that limits the results to those matching the specified filter. For more information,
667+
* see the [documentation](https://cloud.ibm.com/docs/assistant?topic=assistant-filter-reference#filter-reference).
668+
*/
669+
filter?: string;
670+
/** The number of records to return in each page of results. */
671+
pageLimit?: number;
672+
/** A token identifying the page of results to retrieve. */
673+
cursor?: string;
674+
headers?: OutgoingHttpHeaders;
675+
}
676+
677+
/** Parameters for the `deleteUserData` operation. */
678+
export interface DeleteUserDataParams {
679+
/** The customer ID for which all data is to be deleted. */
680+
customerId: string;
681+
headers?: OutgoingHttpHeaders;
682+
}
683+
493684
/*************************
494685
* model interfaces
495686
************************/
@@ -552,8 +743,8 @@ namespace AssistantV2 {
552743

553744
/** DialogSuggestion. */
554745
export interface DialogSuggestion {
555-
/** The user-facing label for the disambiguation option. This label is taken from the **title** or
556-
* **user_label** property of the corresponding dialog node, depending on the disambiguation options.
746+
/** The user-facing label for the suggestion. This label is taken from the **title** or **user_label** property
747+
* of the corresponding dialog node, depending on the disambiguation options.
557748
*/
558749
label: string;
559750
/** An object defining the message input to be sent to the assistant if the user selects the corresponding
@@ -572,6 +763,50 @@ namespace AssistantV2 {
572763
input?: MessageInput;
573764
}
574765

766+
/** Log. */
767+
export interface Log {
768+
/** A unique identifier for the logged event. */
769+
log_id: string;
770+
/** A stateful message request formatted for the Watson Assistant service. */
771+
request: MessageRequest;
772+
/** A response from the Watson Assistant service. */
773+
response: MessageResponse;
774+
/** Unique identifier of the assistant. */
775+
assistant_id: string;
776+
/** The ID of the session the message was part of. */
777+
session_id: string;
778+
/** The unique identifier of the skill that responded to the message. */
779+
skill_id: string;
780+
/** The name of the snapshot (dialog skill version) that responded to the message (for example, `draft`). */
781+
snapshot: string;
782+
/** The timestamp for receipt of the message. */
783+
request_timestamp: string;
784+
/** The timestamp for the system response to the message. */
785+
response_timestamp: string;
786+
/** The language of the assistant to which the message request was made. */
787+
language: string;
788+
/** The customer ID specified for the message, if any. */
789+
customer_id?: string;
790+
}
791+
792+
/** LogCollection. */
793+
export interface LogCollection {
794+
/** An array of objects describing log events. */
795+
logs: Log[];
796+
/** The pagination data for the returned objects. */
797+
pagination: LogPagination;
798+
}
799+
800+
/** The pagination data for the returned objects. */
801+
export interface LogPagination {
802+
/** The URL that will return the next page of results, if any. */
803+
next_url?: string;
804+
/** Reserved for future use. */
805+
matched?: number;
806+
/** A token identifying the next page of results. */
807+
next_cursor?: string;
808+
}
809+
575810
/** MessageContext. */
576811
export interface MessageContext {
577812
/** Session context data that is shared by all skills used by the Assistant. */
@@ -640,7 +875,7 @@ namespace AssistantV2 {
640875
/** Arbitrary variables that can be read and written by a particular skill. */
641876
user_defined?: JsonObject;
642877
/** System context data used by the skill. */
643-
system?: JsonObject;
878+
system?: MessageContextSkillSystem;
644879
}
645880

646881
/** System context data used by the skill. */
@@ -833,6 +1068,18 @@ namespace AssistantV2 {
8331068
suggested_text?: string;
8341069
}
8351070

1071+
/** A stateful message request formatted for the Watson Assistant service. */
1072+
export interface MessageRequest {
1073+
/** An input object that includes the input text. */
1074+
input?: MessageInput;
1075+
/** Context data for the conversation. You can use this property to set or modify context variables, which can
1076+
* also be accessed by dialog nodes. The context is stored by the assistant on a per-session basis.
1077+
*
1078+
* **Note:** The total size of the context data stored for a stateful session cannot exceed 100KB.
1079+
*/
1080+
context?: MessageContext;
1081+
}
1082+
8361083
/** A response from the Watson Assistant service. */
8371084
export interface MessageResponse {
8381085
/** Assistant output to be rendered or processed by the client. */
@@ -841,6 +1088,7 @@ namespace AssistantV2 {
8411088
* stored by the assistant on a per-session basis.
8421089
*
8431090
* **Note:** The context is included in message responses only if **return_context**=`true` in the message request.
1091+
* Full context is always included in logs.
8441092
*/
8451093
context?: MessageContext;
8461094
}
@@ -1006,9 +1254,6 @@ namespace AssistantV2 {
10061254
export interface RuntimeResponseGeneric {
10071255
/** The type of response returned by the dialog node. The specified response type must be supported by the
10081256
* client application or channel.
1009-
*
1010-
* **Note:** The **suggestion** response type is part of the disambiguation feature, which is only available for
1011-
* Premium users.
10121257
*/
10131258
response_type: string;
10141259
/** The text of the response. */
@@ -1033,11 +1278,7 @@ namespace AssistantV2 {
10331278
* node.
10341279
*/
10351280
topic?: string;
1036-
/** An array of objects describing the possible matching dialog nodes from which the user can choose.
1037-
*
1038-
* **Note:** The **suggestions** property is part of the disambiguation feature, which is only available for
1039-
* Premium users.
1040-
*/
1281+
/** An array of objects describing the possible matching dialog nodes from which the user can choose. */
10411282
suggestions?: DialogSuggestion[];
10421283
/** The title or introductory text to show before the response. This text is defined in the search skill
10431284
* configuration.
@@ -1051,8 +1292,8 @@ namespace AssistantV2 {
10511292
export interface SearchResult {
10521293
/** The unique identifier of the document in the Discovery service collection.
10531294
*
1054-
* This property is included in responses from search skills, which are a beta feature available only to Plus or
1055-
* Premium plan users.
1295+
* This property is included in responses from search skills, which are available only to Plus or Premium plan
1296+
* users.
10561297
*/
10571298
id: string;
10581299
/** An object containing search result metadata from the Discovery service. */

0 commit comments

Comments
 (0)