Skip to content

Commit 15a4c7f

Browse files
committed
feat: add model MessageContextSkill
1 parent f7037af commit 15a4c7f

2 files changed

Lines changed: 72 additions & 10 deletions

File tree

assistant/v2.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class AssistantV2 extends BaseService {
7979
public createSession(params: AssistantV2.CreateSessionParams, callback?: AssistantV2.Callback<AssistantV2.SessionResponse>): NodeJS.ReadableStream | Promise<any> | void {
8080
const _params = extend({}, params);
8181
const _callback = callback;
82+
const requiredParams = ['assistant_id'];
8283

8384
if (!_callback) {
8485
return new Promise((resolve, reject) => {
@@ -88,7 +89,6 @@ class AssistantV2 extends BaseService {
8889
});
8990
}
9091

91-
const requiredParams = ['assistant_id'];
9292
const missingParams = getMissingParams(_params, requiredParams);
9393
if (missingParams) {
9494
return _callback(missingParams);
@@ -134,16 +134,16 @@ class AssistantV2 extends BaseService {
134134
public deleteSession(params: AssistantV2.DeleteSessionParams, callback?: AssistantV2.Callback<AssistantV2.Empty>): NodeJS.ReadableStream | Promise<any> | void {
135135
const _params = extend({}, params);
136136
const _callback = callback;
137+
const requiredParams = ['assistant_id', 'session_id'];
137138

138-
if (_callback === undefined) {
139+
if (!_callback) {
139140
return new Promise((resolve, reject) => {
140141
this.deleteSession(params, (err, bod, res) => {
141142
err ? reject(err) : _params.return_response ? resolve(res) : resolve(bod);
142143
});
143144
});
144145
}
145146

146-
const requiredParams = ['assistant_id', 'session_id'];
147147
const missingParams = getMissingParams(_params, requiredParams);
148148
if (missingParams) {
149149
return _callback(missingParams);
@@ -188,7 +188,7 @@ class AssistantV2 extends BaseService {
188188
*
189189
* **Note:** Currently, the v2 API does not support creating assistants.
190190
* @param {string} params.session_id - Unique identifier of the session.
191-
* @param {MessageInput} [params.input] - An input object that includes the input text.
191+
* @param {MessageInput} [params.input] - The user input.
192192
* @param {MessageContext} [params.context] - State information for the conversation.
193193
* @param {Object} [params.headers] - Custom request headers
194194
* @param {Function} [callback] - The callback that handles the response.
@@ -199,7 +199,7 @@ class AssistantV2 extends BaseService {
199199
const _callback = callback;
200200
const requiredParams = ['assistant_id', 'session_id'];
201201

202-
if (_callback === undefined) {
202+
if (!_callback) {
203203
return new Promise((resolve, reject) => {
204204
this.message(params, (err, bod, res) => {
205205
err ? reject(err) : _params.return_response ? resolve(res) : resolve(bod);
@@ -299,7 +299,7 @@ namespace AssistantV2 {
299299
assistant_id: string;
300300
/** Unique identifier of the session. */
301301
session_id: string;
302-
/** An input object that includes the input text. */
302+
/** The user input. */
303303
input?: MessageInput;
304304
/** State information for the conversation. */
305305
context?: MessageContext;
@@ -419,20 +419,26 @@ namespace AssistantV2 {
419419

420420
/** Contains information that can be shared by all skills within the Assistant. */
421421
export interface MessageContextGlobal {
422-
/** Properties interpreted by the Assistant that are shared across all skills within the Assistant. */
422+
/** Properties that are shared by all skills used by the assistant. */
423423
system?: MessageContextGlobalSystem;
424424
}
425425

426426
/** Properties that are shared by all skills used by the assistant. */
427427
export interface MessageContextGlobalSystem {
428428
/** The user time zone. The assistant uses the time zone to correctly resolve relative time references. */
429429
timezone?: string;
430-
/** 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. This user ID may be used for billing and other purposes. */
430+
/** 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 Plus and Premium plans, this user ID is used to identify unique users for billing purposes. This string cannot contain carriage return, newline, or tab characters. */
431431
user_id?: string;
432432
/** A counter that is automatically incremented with each turn of the conversation. A value of 1 indicates that this is the the first turn of a new conversation, which can affect the behavior of some skills. */
433433
turn_count?: number;
434434
}
435435

436+
/** Contains information specific to a particular skill within the Assistant. */
437+
export interface MessageContextSkill {
438+
/** Arbitrary variables that can be read and written to by a particular skill within the Assistant. */
439+
user_defined?: string;
440+
}
441+
436442
/** Contains information specific to particular skills within the Assistant. */
437443
export interface MessageContextSkills {
438444
/** MessageContextSkills accepts additional properties. */
@@ -445,7 +451,7 @@ namespace AssistantV2 {
445451
message_type?: string;
446452
/** 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. */
447453
text?: string;
448-
/** Properties that control how the assistant responds. */
454+
/** Optional properties that control how the assistant responds. */
449455
options?: MessageInputOptions;
450456
/** Intents to use when evaluating the user input. Include intents from the previous response to continue using those intents rather than trying to recognize intents in the new input. */
451457
intents?: RuntimeIntent[];
@@ -497,7 +503,7 @@ namespace AssistantV2 {
497503
export interface MessageResponse {
498504
/** Assistant output to be rendered or processed by the client. */
499505
output: MessageOutput;
500-
/** The current session context. Included in the response if the `return_context` property of the message input was set to `true`. */
506+
/** State information for the conversation. */
501507
context?: MessageContext;
502508
}
503509

test/unit/assistant.v2.test.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,21 @@ describe('deleteSession', () => {
176176
conversation.deleteSession(params, noop);
177177
checkMediaHeaders(createRequestMock, accept, contentType);
178178
});
179+
180+
test('should return a promise when no callback is given', () => {
181+
// parameters
182+
const assistant_id = 'fake_assistant_id';
183+
const params = {
184+
assistant_id,
185+
};
186+
187+
// invoke method
188+
const deleteSessionPromise = conversation.createSession(params);
189+
expectToBePromise(deleteSessionPromise);
190+
191+
// assert that create request was called
192+
expect(createRequestMock).toHaveBeenCalledTimes(1);
193+
});
179194
});
180195
describe('negative tests', () => {
181196
beforeAll(() => {
@@ -198,6 +213,19 @@ describe('deleteSession', () => {
198213
done();
199214
});
200215
});
216+
217+
test('should reject promise when required params are not given', done => {
218+
// required parameters for this method
219+
const requiredParams = ['assistant_id'];
220+
221+
const deleteSessionPromise = conversation.createSession();
222+
expectToBePromise(deleteSessionPromise);
223+
224+
deleteSessionPromise.catch(err => {
225+
checkRequiredParamsHandling(requiredParams, err, missingParamsMock, createRequestMock);
226+
done();
227+
});
228+
});
201229
});
202230
});
203231
describe('message', () => {
@@ -260,6 +288,21 @@ describe('message', () => {
260288
conversation.message(params, noop);
261289
checkMediaHeaders(createRequestMock, accept, contentType);
262290
});
291+
292+
test('should return a promise when no callback is given', () => {
293+
// parameters
294+
const assistant_id = 'fake_assistant_id';
295+
const params = {
296+
assistant_id,
297+
};
298+
299+
// invoke method
300+
const messagePromise = conversation.createSession(params);
301+
expectToBePromise(messagePromise);
302+
303+
// assert that create request was called
304+
expect(createRequestMock).toHaveBeenCalledTimes(1);
305+
});
263306
});
264307
describe('negative tests', () => {
265308
beforeAll(() => {
@@ -282,5 +325,18 @@ describe('message', () => {
282325
done();
283326
});
284327
});
328+
329+
test('should reject promise when required params are not given', done => {
330+
// required parameters for this method
331+
const requiredParams = ['assistant_id'];
332+
333+
const messagePromise = conversation.createSession();
334+
expectToBePromise(messagePromise);
335+
336+
messagePromise.catch(err => {
337+
checkRequiredParamsHandling(requiredParams, err, missingParamsMock, createRequestMock);
338+
done();
339+
});
340+
});
285341
});
286342
});

0 commit comments

Comments
 (0)