@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/docs/MyndAI.html CHANGED
@@ -632,7 +632,7 @@
632
632
  <p class="tag-source">
633
633
  <a href="ai_index.js.html" class="button">View Source</a>
634
634
  <span>
635
- <a href="ai_index.js.html">ai/index.js</a>, <a href="ai_index.js.html#line87">line 87</a>
635
+ <a href="ai_index.js.html">ai/index.js</a>, <a href="ai_index.js.html#line91">line 91</a>
636
636
  </span>
637
637
  </p>
638
638
 
@@ -116,9 +116,13 @@ class MyndAI {
116
116
  _returnData(retData, def = {}) {
117
117
  if (retData.status !== 200) {
118
118
  throw Boom.badRequest(_.get(retData, 'message', 'No error message reported!'))
119
- } else {
120
- return _.get(retData, 'data', def);
121
119
  }
120
+ const body = _.get(retData, 'data', def);
121
+ // Unwrap Akamai response envelope { statusCode, message, data }
122
+ if (body &amp;&amp; typeof body === 'object' &amp;&amp; body.statusCode !== undefined &amp;&amp; body.data !== undefined) {
123
+ return body.data;
124
+ }
125
+ return body;
122
126
  }
123
127
 
124
128
  /**
@@ -113,9 +113,13 @@ class AISession {
113
113
  _returnData(retData, def = {}) {
114
114
  if (retData.status !== 200) {
115
115
  throw Boom.badRequest(_.get(retData, 'message', 'No error message reported!'))
116
- } else {
117
- return _.get(retData, 'data', def);
118
116
  }
117
+ const body = _.get(retData, 'data', def);
118
+ // Unwrap Akamai response envelope { statusCode, message, data }
119
+ if (body &amp;&amp; typeof body === 'object' &amp;&amp; body.statusCode !== undefined &amp;&amp; body.data !== undefined) {
120
+ return body.data;
121
+ }
122
+ return body;
119
123
  }
120
124
 
121
125
  /**
@@ -328,6 +332,89 @@ class AISession {
328
332
  throw ex;
329
333
  }
330
334
  }
335
+ /**
336
+ * @author Myndware &lt;augusto.pissarra@myndware.com>
337
+ * @description Add documents to an existing agent session.
338
+ * The agent will handle the documentIds accordingly.
339
+ * @param {object} params Parameters
340
+ * @param {string} params.sessionId The session ID
341
+ * @param {array&lt;string>} params.documentIds Array of document IDs to add
342
+ * @param {string} authorization Authorization token
343
+ * @return {Promise&lt;object>} data The result from the agent
344
+ * @public
345
+ * @async
346
+ * @example
347
+ *
348
+ * const API = require('@docbrasil/api-systemmanager');
349
+ * const api = new API();
350
+ * const authorization = '...';
351
+ * const params = {
352
+ * sessionId: 'session-abc-123',
353
+ * documentIds: ['doc-123', 'doc-456']
354
+ * };
355
+ * const retData = await api.ai.sessions.addDocuments(params, authorization);
356
+ */
357
+ async addDocuments(params, authorization) {
358
+ const self = this;
359
+
360
+ try {
361
+ Joi.assert(params, Joi.object().required().error(new Error('params is required')));
362
+ Joi.assert(params.sessionId, Joi.string().required().error(new Error('sessionId is required')));
363
+ 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')));
364
+
365
+ const { sessionId, documentIds } = params;
366
+
367
+ const client = self.parent.dispatch.getAkamaiClient();
368
+ const apiCall = client
369
+ .post(`/agents/${sessionId}/documents/add`, { documentIds }, self._setHeader(authorization));
370
+
371
+ return self._returnData(await apiCall);
372
+ } catch (ex) {
373
+ throw ex;
374
+ }
375
+ }
376
+
377
+ /**
378
+ * @author Myndware &lt;augusto.pissarra@myndware.com>
379
+ * @description Remove documents from an existing agent session.
380
+ * The agent will handle the documentIds accordingly.
381
+ * @param {object} params Parameters
382
+ * @param {string} params.sessionId The session ID
383
+ * @param {array&lt;string>} params.documentIds Array of document IDs to remove
384
+ * @param {string} authorization Authorization token
385
+ * @return {Promise&lt;object>} data The result from the agent
386
+ * @public
387
+ * @async
388
+ * @example
389
+ *
390
+ * const API = require('@docbrasil/api-systemmanager');
391
+ * const api = new API();
392
+ * const authorization = '...';
393
+ * const params = {
394
+ * sessionId: 'session-abc-123',
395
+ * documentIds: ['doc-123', 'doc-456']
396
+ * };
397
+ * const retData = await api.ai.sessions.removeDocuments(params, authorization);
398
+ */
399
+ async removeDocuments(params, authorization) {
400
+ const self = this;
401
+
402
+ try {
403
+ Joi.assert(params, Joi.object().required().error(new Error('params is required')));
404
+ Joi.assert(params.sessionId, Joi.string().required().error(new Error('sessionId is required')));
405
+ 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')));
406
+
407
+ const { sessionId, documentIds } = params;
408
+
409
+ const client = self.parent.dispatch.getAkamaiClient();
410
+ const apiCall = client
411
+ .post(`/agents/${sessionId}/documents/remove`, { documentIds }, self._setHeader(authorization));
412
+
413
+ return self._returnData(await apiCall);
414
+ } catch (ex) {
415
+ throw ex;
416
+ }
417
+ }
331
418
  }
332
419
 
333
420
  export default AISession;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@docbrasil/api-systemmanager",
3
3
  "description": "Module API System Manager",
4
- "version": "1.1.86",
4
+ "version": "1.1.89",
5
5
  "scripts": {
6
6
  "htmldoc": "rm -rf docs && jsdoc api/** -d docs -t ./node_modules/better-docs",
7
7
  "doc": "rm -rf doc && mkdir doc && jsdoc2md api/**/* api/* > doc/api.md",