@docbrasil/api-systemmanager 1.1.80 → 1.1.81

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.
Files changed (86) hide show
  1. package/api/{ai.js → ai/index.js} +3 -0
  2. package/api/ai/sessions.js +153 -0
  3. package/dist/bundle.cjs +150 -0
  4. package/dist/bundle.mjs +1 -1
  5. package/doc/api.md +134 -47
  6. package/docs/AISession.html +1370 -0
  7. package/docs/Admin.html +1 -1
  8. package/docs/AdminDocuments.html +1 -1
  9. package/docs/AdminForm.html +1 -1
  10. package/docs/AdminLists.html +1 -1
  11. package/docs/AdminMessage.html +1 -1
  12. package/docs/AdminNotification.html +1 -1
  13. package/docs/AdminPlugin.html +1 -1
  14. package/docs/AdminPolicy.html +1 -1
  15. package/docs/AdminProcesses.html +1 -1
  16. package/docs/AdminTask.html +1 -1
  17. package/docs/AdminUser.html +1 -1
  18. package/docs/Application.html +1 -1
  19. package/docs/Chart.html +1 -1
  20. package/docs/Dashboard.html +1 -1
  21. package/docs/Datasource.html +1 -1
  22. package/docs/Dispatch.html +1 -1
  23. package/docs/Documents.html +1 -1
  24. package/docs/External.html +1 -1
  25. package/docs/GeoLocation.html +1 -1
  26. package/docs/Help.html +1 -1
  27. package/docs/Kanban.html +1 -1
  28. package/docs/Login.html +1 -1
  29. package/docs/MyTasks.html +1 -1
  30. package/docs/MyndAI.html +5 -5
  31. package/docs/Notification.html +1 -1
  32. package/docs/Organization.html +1 -1
  33. package/docs/Page.html +1 -1
  34. package/docs/Process.html +1 -1
  35. package/docs/Register.html +1 -1
  36. package/docs/Report.html +1 -1
  37. package/docs/Session.html +1 -1
  38. package/docs/Settings.html +1 -1
  39. package/docs/Task.html +1 -1
  40. package/docs/TaskAvailable.html +1 -1
  41. package/docs/Updates.html +1 -1
  42. package/docs/User.html +1 -1
  43. package/docs/Users.html +1 -1
  44. package/docs/admin_doctypes.js.html +1 -1
  45. package/docs/admin_document.js.html +1 -1
  46. package/docs/admin_form.js.html +1 -1
  47. package/docs/admin_index.js.html +1 -1
  48. package/docs/admin_list.js.html +1 -1
  49. package/docs/admin_message.js.html +1 -1
  50. package/docs/admin_notification.js.html +1 -1
  51. package/docs/admin_organization.js.html +1 -1
  52. package/docs/admin_plugin.js.html +1 -1
  53. package/docs/admin_policy.js.html +1 -1
  54. package/docs/admin_processes.js.html +1 -1
  55. package/docs/admin_task.js.html +1 -1
  56. package/docs/admin_user.js.html +1 -1
  57. package/docs/{ai.js.html → ai_index.js.html} +6 -3
  58. package/docs/ai_sessions.js.html +270 -0
  59. package/docs/dispatch.js.html +1 -1
  60. package/docs/external.js.html +1 -1
  61. package/docs/general_geoLocation.js.html +1 -1
  62. package/docs/general_index.js.html +1 -1
  63. package/docs/index.html +1 -1
  64. package/docs/login.js.html +1 -1
  65. package/docs/session.js.html +1 -1
  66. package/docs/user_application.js.html +1 -1
  67. package/docs/user_dashboard.js.html +1 -1
  68. package/docs/user_datasource.js.html +1 -1
  69. package/docs/user_document.js.html +1 -1
  70. package/docs/user_help.js.html +1 -1
  71. package/docs/user_index.js.html +1 -1
  72. package/docs/user_kanban.js.html +1 -1
  73. package/docs/user_my_tasks.js.html +1 -1
  74. package/docs/user_notification.js.html +1 -1
  75. package/docs/user_organization.js.html +1 -1
  76. package/docs/user_page.js.html +1 -1
  77. package/docs/user_process.js.html +1 -1
  78. package/docs/user_register.js.html +1 -1
  79. package/docs/user_settings.js.html +1 -1
  80. package/docs/user_task.js.html +1 -1
  81. package/docs/user_task_available.js.html +1 -1
  82. package/docs/user_updates.js.html +1 -1
  83. package/docs/user_user.js.html +1 -1
  84. package/docs/utils_promises.js.html +1 -1
  85. package/index.js +1 -1
  86. package/package.json +1 -1
@@ -1,6 +1,7 @@
1
1
  import _ from 'lodash';
2
2
  import Boom from '@hapi/boom';
3
3
  import Joi from 'joi';
4
+ import AISession from './sessions.js';
4
5
 
5
6
  /**
6
7
  * Class using AI
@@ -15,6 +16,8 @@ class MyndAI {
15
16
  const self = this;
16
17
  self.parent = options.parent;
17
18
  self._client = self.parent.dispatch.getClient();
19
+
20
+ self.sessions = new AISession(options);
18
21
  }
19
22
 
20
23
  /**
@@ -0,0 +1,153 @@
1
+ import _ from 'lodash';
2
+ import Boom from '@hapi/boom';
3
+ import Joi from 'joi';
4
+
5
+ /**
6
+ * Class for AI Session management
7
+ * @class
8
+ */
9
+ class AISession {
10
+
11
+ constructor(options) {
12
+ Joi.assert(options, Joi.object().required());
13
+ Joi.assert(options.parent, Joi.object().required());
14
+
15
+ const self = this;
16
+ self.parent = options.parent;
17
+ self._client = self.parent.dispatch.getClient();
18
+ }
19
+
20
+ /**
21
+ * @author Augusto Pissarra <abernardo.br@gmail.com>
22
+ * @description Get the return data and check for errors
23
+ * @param {object} retData Response HTTP
24
+ * @return {*}
25
+ * @private
26
+ */
27
+ _returnData(retData, def = {}) {
28
+ if (retData.status !== 200) {
29
+ throw Boom.badRequest(_.get(retData, 'message', 'No error message reported!'))
30
+ } else {
31
+ return _.get(retData, 'data', def);
32
+ }
33
+ }
34
+
35
+ /**
36
+ * @author Myndware <augusto.pissarra@myndware.com>
37
+ * @description Set header with new session
38
+ * @param {string} session Session, token JWT
39
+ * @return {object} header with new session
40
+ * @private
41
+ */
42
+ _setHeader(authorization) {
43
+ return {
44
+ headers: {
45
+ Authorization: authorization,
46
+ }
47
+ };
48
+ }
49
+
50
+ /**
51
+ * @author Myndware <augusto.pissarra@myndware.com>
52
+ * @description Get full session data by document ID.
53
+ * Returns session, execution, activities, pages, triples and summary.
54
+ * @param {object} params Parameters
55
+ * @param {string} params.documentId The document ID to look up the session for
56
+ * @param {string} authorization Authorization token
57
+ * @return {Promise<object>} data The full session data
58
+ * @return {object} data.session The session object
59
+ * @return {object} data.execution The latest execution or null
60
+ * @return {array<object>} data.activities Activity log entries
61
+ * @return {array<object>} data.pages Extracted page objects
62
+ * @return {array<object>} data.triples Ontology triple objects
63
+ * @return {object} data.summary Document summary or null
64
+ * @public
65
+ * @async
66
+ * @example
67
+ *
68
+ * const API = require('@docbrasil/api-systemmanager');
69
+ * const api = new API();
70
+ * const authorization = '...';
71
+ * const params = { documentId: 'doc-123' };
72
+ * const retData = await api.ai.sessions.getByDocument(params, authorization);
73
+ */
74
+ async getByDocument(params, authorization) {
75
+ const self = this;
76
+
77
+ try {
78
+ Joi.assert(params, Joi.object().required().error(new Error('params is required')));
79
+ Joi.assert(params.documentId, Joi.string().required().error(new Error('documentId is required')));
80
+
81
+ const apiCall = self._client
82
+ .get(`/akamai/agents/session/document/${params.documentId}`, self._setHeader(authorization));
83
+
84
+ return self._returnData(await apiCall);
85
+ } catch (ex) {
86
+ throw ex;
87
+ }
88
+ }
89
+
90
+ /**
91
+ * @author Myndware <augusto.pissarra@myndware.com>
92
+ * @description Update session document data (pages, triples, summary).
93
+ * Used by Scarface to push corrections or enrichments for a document.
94
+ * @param {object} params Parameters
95
+ * @param {string} params.documentId The document ID
96
+ * @param {array<object>} [params.pages] Page updates
97
+ * @param {number} params.pages.pageNumber 1-based page number
98
+ * @param {string} [params.pages.markdown] Updated markdown text
99
+ * @param {array<object>} [params.pages.entities] Updated entities
100
+ * @param {array<object>} [params.triples] New triples to add
101
+ * @param {number} params.triples.pageNumber Source page number
102
+ * @param {string} params.triples.subject Subject entity text
103
+ * @param {string} params.triples.predicate Relationship predicate
104
+ * @param {string} params.triples.object Object entity text
105
+ * @param {object} [params.summary] Summary field updates
106
+ * @param {string} [params.summary.documentName] Document name
107
+ * @param {number} [params.summary.entityCount] Total entity count
108
+ * @param {number} [params.summary.tripleCount] Total triple count
109
+ * @param {string} authorization Authorization token
110
+ * @return {Promise<object>} data The update results
111
+ * @return {array<object>} data.pages Page update results [{pageNumber, updated}]
112
+ * @return {object} data.triples Triple insert results {added: number}
113
+ * @return {object} data.summary Applied summary updates
114
+ * @public
115
+ * @async
116
+ * @example
117
+ *
118
+ * const API = require('@docbrasil/api-systemmanager');
119
+ * const api = new API();
120
+ * const authorization = '...';
121
+ * const params = {
122
+ * documentId: 'doc-123',
123
+ * pages: [
124
+ * { pageNumber: 1, markdown: '# Updated page content' }
125
+ * ],
126
+ * summary: {
127
+ * documentName: 'Patient Report.pdf',
128
+ * entityCount: 42,
129
+ * tripleCount: 15
130
+ * }
131
+ * };
132
+ * const retData = await api.ai.sessions.updateData(params, authorization);
133
+ */
134
+ async updateData(params, authorization) {
135
+ const self = this;
136
+
137
+ try {
138
+ Joi.assert(params, Joi.object().required().error(new Error('params is required')));
139
+ Joi.assert(params.documentId, Joi.string().required().error(new Error('documentId is required')));
140
+
141
+ const { documentId, ...payload } = params;
142
+
143
+ const apiCall = self._client
144
+ .patch(`/akamai/agents/session/document/${documentId}`, payload, self._setHeader(authorization));
145
+
146
+ return self._returnData(await apiCall);
147
+ } catch (ex) {
148
+ throw ex;
149
+ }
150
+ }
151
+ }
152
+
153
+ export default AISession;
package/dist/bundle.cjs CHANGED
@@ -16117,6 +16117,154 @@ class External {
16117
16117
 
16118
16118
  }
16119
16119
 
16120
+ /**
16121
+ * Class for AI Session management
16122
+ * @class
16123
+ */
16124
+ class AISession {
16125
+
16126
+ constructor(options) {
16127
+ Joi__default["default"].assert(options, Joi__default["default"].object().required());
16128
+ Joi__default["default"].assert(options.parent, Joi__default["default"].object().required());
16129
+
16130
+ const self = this;
16131
+ self.parent = options.parent;
16132
+ self._client = self.parent.dispatch.getClient();
16133
+ }
16134
+
16135
+ /**
16136
+ * @author Augusto Pissarra <abernardo.br@gmail.com>
16137
+ * @description Get the return data and check for errors
16138
+ * @param {object} retData Response HTTP
16139
+ * @return {*}
16140
+ * @private
16141
+ */
16142
+ _returnData(retData, def = {}) {
16143
+ if (retData.status !== 200) {
16144
+ throw Boom__default["default"].badRequest(___default["default"].get(retData, 'message', 'No error message reported!'))
16145
+ } else {
16146
+ return ___default["default"].get(retData, 'data', def);
16147
+ }
16148
+ }
16149
+
16150
+ /**
16151
+ * @author Myndware <augusto.pissarra@myndware.com>
16152
+ * @description Set header with new session
16153
+ * @param {string} session Session, token JWT
16154
+ * @return {object} header with new session
16155
+ * @private
16156
+ */
16157
+ _setHeader(authorization) {
16158
+ return {
16159
+ headers: {
16160
+ Authorization: authorization,
16161
+ }
16162
+ };
16163
+ }
16164
+
16165
+ /**
16166
+ * @author Myndware <augusto.pissarra@myndware.com>
16167
+ * @description Get full session data by document ID.
16168
+ * Returns session, execution, activities, pages, triples and summary.
16169
+ * @param {object} params Parameters
16170
+ * @param {string} params.documentId The document ID to look up the session for
16171
+ * @param {string} authorization Authorization token
16172
+ * @return {Promise<object>} data The full session data
16173
+ * @return {object} data.session The session object
16174
+ * @return {object} data.execution The latest execution or null
16175
+ * @return {array<object>} data.activities Activity log entries
16176
+ * @return {array<object>} data.pages Extracted page objects
16177
+ * @return {array<object>} data.triples Ontology triple objects
16178
+ * @return {object} data.summary Document summary or null
16179
+ * @public
16180
+ * @async
16181
+ * @example
16182
+ *
16183
+ * const API = require('@docbrasil/api-systemmanager');
16184
+ * const api = new API();
16185
+ * const authorization = '...';
16186
+ * const params = { documentId: 'doc-123' };
16187
+ * const retData = await api.ai.sessions.getByDocument(params, authorization);
16188
+ */
16189
+ async getByDocument(params, authorization) {
16190
+ const self = this;
16191
+
16192
+ try {
16193
+ Joi__default["default"].assert(params, Joi__default["default"].object().required().error(new Error('params is required')));
16194
+ Joi__default["default"].assert(params.documentId, Joi__default["default"].string().required().error(new Error('documentId is required')));
16195
+
16196
+ const apiCall = self._client
16197
+ .get(`/akamai/agents/session/document/${params.documentId}`, self._setHeader(authorization));
16198
+
16199
+ return self._returnData(await apiCall);
16200
+ } catch (ex) {
16201
+ throw ex;
16202
+ }
16203
+ }
16204
+
16205
+ /**
16206
+ * @author Myndware <augusto.pissarra@myndware.com>
16207
+ * @description Update session document data (pages, triples, summary).
16208
+ * Used by Scarface to push corrections or enrichments for a document.
16209
+ * @param {object} params Parameters
16210
+ * @param {string} params.documentId The document ID
16211
+ * @param {array<object>} [params.pages] Page updates
16212
+ * @param {number} params.pages.pageNumber 1-based page number
16213
+ * @param {string} [params.pages.markdown] Updated markdown text
16214
+ * @param {array<object>} [params.pages.entities] Updated entities
16215
+ * @param {array<object>} [params.triples] New triples to add
16216
+ * @param {number} params.triples.pageNumber Source page number
16217
+ * @param {string} params.triples.subject Subject entity text
16218
+ * @param {string} params.triples.predicate Relationship predicate
16219
+ * @param {string} params.triples.object Object entity text
16220
+ * @param {object} [params.summary] Summary field updates
16221
+ * @param {string} [params.summary.documentName] Document name
16222
+ * @param {number} [params.summary.entityCount] Total entity count
16223
+ * @param {number} [params.summary.tripleCount] Total triple count
16224
+ * @param {string} authorization Authorization token
16225
+ * @return {Promise<object>} data The update results
16226
+ * @return {array<object>} data.pages Page update results [{pageNumber, updated}]
16227
+ * @return {object} data.triples Triple insert results {added: number}
16228
+ * @return {object} data.summary Applied summary updates
16229
+ * @public
16230
+ * @async
16231
+ * @example
16232
+ *
16233
+ * const API = require('@docbrasil/api-systemmanager');
16234
+ * const api = new API();
16235
+ * const authorization = '...';
16236
+ * const params = {
16237
+ * documentId: 'doc-123',
16238
+ * pages: [
16239
+ * { pageNumber: 1, markdown: '# Updated page content' }
16240
+ * ],
16241
+ * summary: {
16242
+ * documentName: 'Patient Report.pdf',
16243
+ * entityCount: 42,
16244
+ * tripleCount: 15
16245
+ * }
16246
+ * };
16247
+ * const retData = await api.ai.sessions.updateData(params, authorization);
16248
+ */
16249
+ async updateData(params, authorization) {
16250
+ const self = this;
16251
+
16252
+ try {
16253
+ Joi__default["default"].assert(params, Joi__default["default"].object().required().error(new Error('params is required')));
16254
+ Joi__default["default"].assert(params.documentId, Joi__default["default"].string().required().error(new Error('documentId is required')));
16255
+
16256
+ const { documentId, ...payload } = params;
16257
+
16258
+ const apiCall = self._client
16259
+ .patch(`/akamai/agents/session/document/${documentId}`, payload, self._setHeader(authorization));
16260
+
16261
+ return self._returnData(await apiCall);
16262
+ } catch (ex) {
16263
+ throw ex;
16264
+ }
16265
+ }
16266
+ }
16267
+
16120
16268
  /**
16121
16269
  * Class using AI
16122
16270
  * @class
@@ -16130,6 +16278,8 @@ class MyndAI {
16130
16278
  const self = this;
16131
16279
  self.parent = options.parent;
16132
16280
  self._client = self.parent.dispatch.getClient();
16281
+
16282
+ self.sessions = new AISession(options);
16133
16283
  }
16134
16284
 
16135
16285
  /**