@docbrasil/api-systemmanager 1.1.86 → 1.1.89

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/api/ai/index.js CHANGED
@@ -29,9 +29,13 @@ class MyndAI {
29
29
  _returnData(retData, def = {}) {
30
30
  if (retData.status !== 200) {
31
31
  throw Boom.badRequest(_.get(retData, 'message', 'No error message reported!'))
32
- } else {
33
- return _.get(retData, 'data', def);
34
32
  }
33
+ const body = _.get(retData, 'data', def);
34
+ // Unwrap Akamai response envelope { statusCode, message, data }
35
+ if (body && typeof body === 'object' && body.statusCode !== undefined && body.data !== undefined) {
36
+ return body.data;
37
+ }
38
+ return body;
35
39
  }
36
40
 
37
41
  /**
@@ -26,9 +26,13 @@ class AISession {
26
26
  _returnData(retData, def = {}) {
27
27
  if (retData.status !== 200) {
28
28
  throw Boom.badRequest(_.get(retData, 'message', 'No error message reported!'))
29
- } else {
30
- return _.get(retData, 'data', def);
31
29
  }
30
+ const body = _.get(retData, 'data', def);
31
+ // Unwrap Akamai response envelope { statusCode, message, data }
32
+ if (body && typeof body === 'object' && body.statusCode !== undefined && body.data !== undefined) {
33
+ return body.data;
34
+ }
35
+ return body;
32
36
  }
33
37
 
34
38
  /**
@@ -241,6 +245,89 @@ class AISession {
241
245
  throw ex;
242
246
  }
243
247
  }
248
+ /**
249
+ * @author Myndware <augusto.pissarra@myndware.com>
250
+ * @description Add documents to an existing agent session.
251
+ * The agent will handle the documentIds accordingly.
252
+ * @param {object} params Parameters
253
+ * @param {string} params.sessionId The session ID
254
+ * @param {array<string>} params.documentIds Array of document IDs to add
255
+ * @param {string} authorization Authorization token
256
+ * @return {Promise<object>} data The result from the agent
257
+ * @public
258
+ * @async
259
+ * @example
260
+ *
261
+ * const API = require('@docbrasil/api-systemmanager');
262
+ * const api = new API();
263
+ * const authorization = '...';
264
+ * const params = {
265
+ * sessionId: 'session-abc-123',
266
+ * documentIds: ['doc-123', 'doc-456']
267
+ * };
268
+ * const retData = await api.ai.sessions.addDocuments(params, authorization);
269
+ */
270
+ async addDocuments(params, authorization) {
271
+ const self = this;
272
+
273
+ try {
274
+ Joi.assert(params, Joi.object().required().error(new Error('params is required')));
275
+ Joi.assert(params.sessionId, Joi.string().required().error(new Error('sessionId is required')));
276
+ Joi.assert(params.documentIds, Joi.array().items(Joi.string()).min(1).required().error(new Error('documentIds is required and must be a non-empty array')));
277
+
278
+ const { sessionId, documentIds } = params;
279
+
280
+ const client = self.parent.dispatch.getAkamaiClient();
281
+ const apiCall = client
282
+ .post(`/agents/${sessionId}/documents/add`, { documentIds }, self._setHeader(authorization));
283
+
284
+ return self._returnData(await apiCall);
285
+ } catch (ex) {
286
+ throw ex;
287
+ }
288
+ }
289
+
290
+ /**
291
+ * @author Myndware <augusto.pissarra@myndware.com>
292
+ * @description Remove documents from an existing agent session.
293
+ * The agent will handle the documentIds accordingly.
294
+ * @param {object} params Parameters
295
+ * @param {string} params.sessionId The session ID
296
+ * @param {array<string>} params.documentIds Array of document IDs to remove
297
+ * @param {string} authorization Authorization token
298
+ * @return {Promise<object>} data The result from the agent
299
+ * @public
300
+ * @async
301
+ * @example
302
+ *
303
+ * const API = require('@docbrasil/api-systemmanager');
304
+ * const api = new API();
305
+ * const authorization = '...';
306
+ * const params = {
307
+ * sessionId: 'session-abc-123',
308
+ * documentIds: ['doc-123', 'doc-456']
309
+ * };
310
+ * const retData = await api.ai.sessions.removeDocuments(params, authorization);
311
+ */
312
+ async removeDocuments(params, authorization) {
313
+ const self = this;
314
+
315
+ try {
316
+ Joi.assert(params, Joi.object().required().error(new Error('params is required')));
317
+ Joi.assert(params.sessionId, Joi.string().required().error(new Error('sessionId is required')));
318
+ Joi.assert(params.documentIds, Joi.array().items(Joi.string()).min(1).required().error(new Error('documentIds is required and must be a non-empty array')));
319
+
320
+ const { sessionId, documentIds } = params;
321
+
322
+ const client = self.parent.dispatch.getAkamaiClient();
323
+ const apiCall = client
324
+ .post(`/agents/${sessionId}/documents/remove`, { documentIds }, self._setHeader(authorization));
325
+
326
+ return self._returnData(await apiCall);
327
+ } catch (ex) {
328
+ throw ex;
329
+ }
330
+ }
244
331
  }
245
332
 
246
333
  export default AISession;
package/dist/bundle.cjs CHANGED
@@ -16190,9 +16190,13 @@ class AISession {
16190
16190
  _returnData(retData, def = {}) {
16191
16191
  if (retData.status !== 200) {
16192
16192
  throw Boom__default["default"].badRequest(___default["default"].get(retData, 'message', 'No error message reported!'))
16193
- } else {
16194
- return ___default["default"].get(retData, 'data', def);
16195
16193
  }
16194
+ const body = ___default["default"].get(retData, 'data', def);
16195
+ // Unwrap Akamai response envelope { statusCode, message, data }
16196
+ if (body && typeof body === 'object' && body.statusCode !== undefined && body.data !== undefined) {
16197
+ return body.data;
16198
+ }
16199
+ return body;
16196
16200
  }
16197
16201
 
16198
16202
  /**
@@ -16405,6 +16409,89 @@ class AISession {
16405
16409
  throw ex;
16406
16410
  }
16407
16411
  }
16412
+ /**
16413
+ * @author Myndware <augusto.pissarra@myndware.com>
16414
+ * @description Add documents to an existing agent session.
16415
+ * The agent will handle the documentIds accordingly.
16416
+ * @param {object} params Parameters
16417
+ * @param {string} params.sessionId The session ID
16418
+ * @param {array<string>} params.documentIds Array of document IDs to add
16419
+ * @param {string} authorization Authorization token
16420
+ * @return {Promise<object>} data The result from the agent
16421
+ * @public
16422
+ * @async
16423
+ * @example
16424
+ *
16425
+ * const API = require('@docbrasil/api-systemmanager');
16426
+ * const api = new API();
16427
+ * const authorization = '...';
16428
+ * const params = {
16429
+ * sessionId: 'session-abc-123',
16430
+ * documentIds: ['doc-123', 'doc-456']
16431
+ * };
16432
+ * const retData = await api.ai.sessions.addDocuments(params, authorization);
16433
+ */
16434
+ async addDocuments(params, authorization) {
16435
+ const self = this;
16436
+
16437
+ try {
16438
+ Joi__default["default"].assert(params, Joi__default["default"].object().required().error(new Error('params is required')));
16439
+ Joi__default["default"].assert(params.sessionId, Joi__default["default"].string().required().error(new Error('sessionId is required')));
16440
+ Joi__default["default"].assert(params.documentIds, Joi__default["default"].array().items(Joi__default["default"].string()).min(1).required().error(new Error('documentIds is required and must be a non-empty array')));
16441
+
16442
+ const { sessionId, documentIds } = params;
16443
+
16444
+ const client = self.parent.dispatch.getAkamaiClient();
16445
+ const apiCall = client
16446
+ .post(`/agents/${sessionId}/documents/add`, { documentIds }, self._setHeader(authorization));
16447
+
16448
+ return self._returnData(await apiCall);
16449
+ } catch (ex) {
16450
+ throw ex;
16451
+ }
16452
+ }
16453
+
16454
+ /**
16455
+ * @author Myndware <augusto.pissarra@myndware.com>
16456
+ * @description Remove documents from an existing agent session.
16457
+ * The agent will handle the documentIds accordingly.
16458
+ * @param {object} params Parameters
16459
+ * @param {string} params.sessionId The session ID
16460
+ * @param {array<string>} params.documentIds Array of document IDs to remove
16461
+ * @param {string} authorization Authorization token
16462
+ * @return {Promise<object>} data The result from the agent
16463
+ * @public
16464
+ * @async
16465
+ * @example
16466
+ *
16467
+ * const API = require('@docbrasil/api-systemmanager');
16468
+ * const api = new API();
16469
+ * const authorization = '...';
16470
+ * const params = {
16471
+ * sessionId: 'session-abc-123',
16472
+ * documentIds: ['doc-123', 'doc-456']
16473
+ * };
16474
+ * const retData = await api.ai.sessions.removeDocuments(params, authorization);
16475
+ */
16476
+ async removeDocuments(params, authorization) {
16477
+ const self = this;
16478
+
16479
+ try {
16480
+ Joi__default["default"].assert(params, Joi__default["default"].object().required().error(new Error('params is required')));
16481
+ Joi__default["default"].assert(params.sessionId, Joi__default["default"].string().required().error(new Error('sessionId is required')));
16482
+ Joi__default["default"].assert(params.documentIds, Joi__default["default"].array().items(Joi__default["default"].string()).min(1).required().error(new Error('documentIds is required and must be a non-empty array')));
16483
+
16484
+ const { sessionId, documentIds } = params;
16485
+
16486
+ const client = self.parent.dispatch.getAkamaiClient();
16487
+ const apiCall = client
16488
+ .post(`/agents/${sessionId}/documents/remove`, { documentIds }, self._setHeader(authorization));
16489
+
16490
+ return self._returnData(await apiCall);
16491
+ } catch (ex) {
16492
+ throw ex;
16493
+ }
16494
+ }
16408
16495
  }
16409
16496
 
16410
16497
  /**
@@ -16433,9 +16520,13 @@ class MyndAI {
16433
16520
  _returnData(retData, def = {}) {
16434
16521
  if (retData.status !== 200) {
16435
16522
  throw Boom__default["default"].badRequest(___default["default"].get(retData, 'message', 'No error message reported!'))
16436
- } else {
16437
- return ___default["default"].get(retData, 'data', def);
16438
16523
  }
16524
+ const body = ___default["default"].get(retData, 'data', def);
16525
+ // Unwrap Akamai response envelope { statusCode, message, data }
16526
+ if (body && typeof body === 'object' && body.statusCode !== undefined && body.data !== undefined) {
16527
+ return body.data;
16528
+ }
16529
+ return body;
16439
16530
  }
16440
16531
 
16441
16532
  /**