@docbrasil/api-systemmanager 1.1.81 → 1.1.83

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
@@ -15,7 +15,6 @@ class MyndAI {
15
15
 
16
16
  const self = this;
17
17
  self.parent = options.parent;
18
- self._client = self.parent.dispatch.getClient();
19
18
 
20
19
  self.sessions = new AISession(options);
21
20
  }
@@ -92,7 +91,8 @@ class MyndAI {
92
91
  Joi.assert(params, Joi.object().required().error(new Error('params is required')));
93
92
  Joi.assert(params.prompt, Joi.string().required().error(new Error('Provide a prompt')));
94
93
 
95
- const apiCall = self._client
94
+ const client = self.parent.dispatch.getAkamaiClient();
95
+ const apiCall = client
96
96
  .post('/agents/explain', params, self._setHeader(authorization));
97
97
 
98
98
  return self._returnData(await apiCall);
@@ -14,7 +14,6 @@ class AISession {
14
14
 
15
15
  const self = this;
16
16
  self.parent = options.parent;
17
- self._client = self.parent.dispatch.getClient();
18
17
  }
19
18
 
20
19
  /**
@@ -78,8 +77,9 @@ class AISession {
78
77
  Joi.assert(params, Joi.object().required().error(new Error('params is required')));
79
78
  Joi.assert(params.documentId, Joi.string().required().error(new Error('documentId is required')));
80
79
 
81
- const apiCall = self._client
82
- .get(`/akamai/agents/session/document/${params.documentId}`, self._setHeader(authorization));
80
+ const client = self.parent.dispatch.getAkamaiClient();
81
+ const apiCall = client
82
+ .get(`/agents/session/document/${params.documentId}`, self._setHeader(authorization));
83
83
 
84
84
  return self._returnData(await apiCall);
85
85
  } catch (ex) {
@@ -140,8 +140,101 @@ class AISession {
140
140
 
141
141
  const { documentId, ...payload } = params;
142
142
 
143
- const apiCall = self._client
144
- .patch(`/akamai/agents/session/document/${documentId}`, payload, self._setHeader(authorization));
143
+ const client = self.parent.dispatch.getAkamaiClient();
144
+ const apiCall = client
145
+ .patch(`/agents/session/document/${documentId}`, payload, self._setHeader(authorization));
146
+
147
+ return self._returnData(await apiCall);
148
+ } catch (ex) {
149
+ throw ex;
150
+ }
151
+ }
152
+
153
+ /**
154
+ * @author Myndware <augusto.pissarra@myndware.com>
155
+ * @description Create a new agent session.
156
+ * Use this to create a session with full metadata before triggering execution.
157
+ * @param {object} params Parameters
158
+ * @param {string} params.agentType The agent type (e.g., 'doc-rlm-ingest')
159
+ * @param {object} [params.config] Agent configuration options
160
+ * @param {object} [params.metadata] Session metadata (documentId, pipelineVariant, analysisMode, etc.)
161
+ * @param {string} authorization Authorization token
162
+ * @return {Promise<object>} data The created session
163
+ * @return {string} data.sessionId The session ID
164
+ * @return {string} data.status The session status
165
+ * @public
166
+ * @async
167
+ * @example
168
+ *
169
+ * const API = require('@docbrasil/api-systemmanager');
170
+ * const api = new API();
171
+ * const authorization = '...';
172
+ * const params = {
173
+ * agentType: 'doc-rlm-ingest',
174
+ * metadata: {
175
+ * documentId: 'doc-123',
176
+ * documentName: 'Patient Report.pdf',
177
+ * pipelineVariant: 'A',
178
+ * analysisMode: 'full'
179
+ * }
180
+ * };
181
+ * const retData = await api.ai.sessions.create(params, authorization);
182
+ */
183
+ async create(params, authorization) {
184
+ const self = this;
185
+
186
+ try {
187
+ Joi.assert(params, Joi.object().required().error(new Error('params is required')));
188
+ Joi.assert(params.agentType, Joi.string().required().error(new Error('agentType is required')));
189
+
190
+ const client = self.parent.dispatch.getAkamaiClient();
191
+ const apiCall = client
192
+ .post('/agents/create', params, self._setHeader(authorization));
193
+
194
+ return self._returnData(await apiCall);
195
+ } catch (ex) {
196
+ throw ex;
197
+ }
198
+ }
199
+
200
+ /**
201
+ * @author Myndware <augusto.pissarra@myndware.com>
202
+ * @description Start execution on an existing agent session.
203
+ * @param {object} params Parameters
204
+ * @param {string} params.sessionId The session ID to execute
205
+ * @param {object} [params.input] Execution input (documentId, options, etc.)
206
+ * @param {string} authorization Authorization token
207
+ * @return {Promise<object>} data The execution data
208
+ * @return {string} data.executionId The execution ID
209
+ * @return {string} data.status The execution status
210
+ * @public
211
+ * @async
212
+ * @example
213
+ *
214
+ * const API = require('@docbrasil/api-systemmanager');
215
+ * const api = new API();
216
+ * const authorization = '...';
217
+ * const params = {
218
+ * sessionId: 'session-abc-123',
219
+ * input: {
220
+ * documentId: 'doc-123',
221
+ * options: { pipelineVariant: 'A', analysisMode: 'full' }
222
+ * }
223
+ * };
224
+ * const retData = await api.ai.sessions.execute(params, authorization);
225
+ */
226
+ async execute(params, authorization) {
227
+ const self = this;
228
+
229
+ try {
230
+ Joi.assert(params, Joi.object().required().error(new Error('params is required')));
231
+ Joi.assert(params.sessionId, Joi.string().required().error(new Error('sessionId is required')));
232
+
233
+ const { sessionId, ...payload } = params;
234
+
235
+ const client = self.parent.dispatch.getAkamaiClient();
236
+ const apiCall = client
237
+ .post(`/agents/${sessionId}/execute`, payload, self._setHeader(authorization));
145
238
 
146
239
  return self._returnData(await apiCall);
147
240
  } catch (ex) {
package/api/dispatch.js CHANGED
@@ -198,6 +198,30 @@ class Dispatch {
198
198
  getClient() {
199
199
  return this._client;
200
200
  }
201
+
202
+ /**
203
+ * @description Create a dedicated Axios client for Akamai routes.
204
+ * @param {string} url The Akamai base URL (e.g., http://localhost:9008 in DEV).
205
+ * @public
206
+ */
207
+ setAkamaiBaseUrl(url) {
208
+ Joi.assert(url, Joi.string().required());
209
+
210
+ this._akamaiClient = Axios.create({
211
+ baseURL: url,
212
+ withCredentials: true
213
+ });
214
+ }
215
+
216
+ /**
217
+ * @description Get the Akamai Axios client. Falls back to the default client
218
+ * for backward compatibility (e.g., PROD where NGiNX proxies all routes).
219
+ * @return {AxiosInstance} The Akamai client or default client.
220
+ * @public
221
+ */
222
+ getAkamaiClient() {
223
+ return this._akamaiClient || this._client;
224
+ }
201
225
  }
202
226
 
203
227
  export default Dispatch;
package/dist/bundle.cjs CHANGED
@@ -210,6 +210,30 @@ class Dispatch {
210
210
  getClient() {
211
211
  return this._client;
212
212
  }
213
+
214
+ /**
215
+ * @description Create a dedicated Axios client for Akamai routes.
216
+ * @param {string} url The Akamai base URL (e.g., http://localhost:9008 in DEV).
217
+ * @public
218
+ */
219
+ setAkamaiBaseUrl(url) {
220
+ Joi__default["default"].assert(url, Joi__default["default"].string().required());
221
+
222
+ this._akamaiClient = Axios__default["default"].create({
223
+ baseURL: url,
224
+ withCredentials: true
225
+ });
226
+ }
227
+
228
+ /**
229
+ * @description Get the Akamai Axios client. Falls back to the default client
230
+ * for backward compatibility (e.g., PROD where NGiNX proxies all routes).
231
+ * @return {AxiosInstance} The Akamai client or default client.
232
+ * @public
233
+ */
234
+ getAkamaiClient() {
235
+ return this._akamaiClient || this._client;
236
+ }
213
237
  }
214
238
 
215
239
  /**
@@ -16129,7 +16153,6 @@ class AISession {
16129
16153
 
16130
16154
  const self = this;
16131
16155
  self.parent = options.parent;
16132
- self._client = self.parent.dispatch.getClient();
16133
16156
  }
16134
16157
 
16135
16158
  /**
@@ -16193,8 +16216,9 @@ class AISession {
16193
16216
  Joi__default["default"].assert(params, Joi__default["default"].object().required().error(new Error('params is required')));
16194
16217
  Joi__default["default"].assert(params.documentId, Joi__default["default"].string().required().error(new Error('documentId is required')));
16195
16218
 
16196
- const apiCall = self._client
16197
- .get(`/akamai/agents/session/document/${params.documentId}`, self._setHeader(authorization));
16219
+ const client = self.parent.dispatch.getAkamaiClient();
16220
+ const apiCall = client
16221
+ .get(`/agents/session/document/${params.documentId}`, self._setHeader(authorization));
16198
16222
 
16199
16223
  return self._returnData(await apiCall);
16200
16224
  } catch (ex) {
@@ -16255,8 +16279,101 @@ class AISession {
16255
16279
 
16256
16280
  const { documentId, ...payload } = params;
16257
16281
 
16258
- const apiCall = self._client
16259
- .patch(`/akamai/agents/session/document/${documentId}`, payload, self._setHeader(authorization));
16282
+ const client = self.parent.dispatch.getAkamaiClient();
16283
+ const apiCall = client
16284
+ .patch(`/agents/session/document/${documentId}`, payload, self._setHeader(authorization));
16285
+
16286
+ return self._returnData(await apiCall);
16287
+ } catch (ex) {
16288
+ throw ex;
16289
+ }
16290
+ }
16291
+
16292
+ /**
16293
+ * @author Myndware <augusto.pissarra@myndware.com>
16294
+ * @description Create a new agent session.
16295
+ * Use this to create a session with full metadata before triggering execution.
16296
+ * @param {object} params Parameters
16297
+ * @param {string} params.agentType The agent type (e.g., 'doc-rlm-ingest')
16298
+ * @param {object} [params.config] Agent configuration options
16299
+ * @param {object} [params.metadata] Session metadata (documentId, pipelineVariant, analysisMode, etc.)
16300
+ * @param {string} authorization Authorization token
16301
+ * @return {Promise<object>} data The created session
16302
+ * @return {string} data.sessionId The session ID
16303
+ * @return {string} data.status The session status
16304
+ * @public
16305
+ * @async
16306
+ * @example
16307
+ *
16308
+ * const API = require('@docbrasil/api-systemmanager');
16309
+ * const api = new API();
16310
+ * const authorization = '...';
16311
+ * const params = {
16312
+ * agentType: 'doc-rlm-ingest',
16313
+ * metadata: {
16314
+ * documentId: 'doc-123',
16315
+ * documentName: 'Patient Report.pdf',
16316
+ * pipelineVariant: 'A',
16317
+ * analysisMode: 'full'
16318
+ * }
16319
+ * };
16320
+ * const retData = await api.ai.sessions.create(params, authorization);
16321
+ */
16322
+ async create(params, authorization) {
16323
+ const self = this;
16324
+
16325
+ try {
16326
+ Joi__default["default"].assert(params, Joi__default["default"].object().required().error(new Error('params is required')));
16327
+ Joi__default["default"].assert(params.agentType, Joi__default["default"].string().required().error(new Error('agentType is required')));
16328
+
16329
+ const client = self.parent.dispatch.getAkamaiClient();
16330
+ const apiCall = client
16331
+ .post('/agents/create', params, self._setHeader(authorization));
16332
+
16333
+ return self._returnData(await apiCall);
16334
+ } catch (ex) {
16335
+ throw ex;
16336
+ }
16337
+ }
16338
+
16339
+ /**
16340
+ * @author Myndware <augusto.pissarra@myndware.com>
16341
+ * @description Start execution on an existing agent session.
16342
+ * @param {object} params Parameters
16343
+ * @param {string} params.sessionId The session ID to execute
16344
+ * @param {object} [params.input] Execution input (documentId, options, etc.)
16345
+ * @param {string} authorization Authorization token
16346
+ * @return {Promise<object>} data The execution data
16347
+ * @return {string} data.executionId The execution ID
16348
+ * @return {string} data.status The execution status
16349
+ * @public
16350
+ * @async
16351
+ * @example
16352
+ *
16353
+ * const API = require('@docbrasil/api-systemmanager');
16354
+ * const api = new API();
16355
+ * const authorization = '...';
16356
+ * const params = {
16357
+ * sessionId: 'session-abc-123',
16358
+ * input: {
16359
+ * documentId: 'doc-123',
16360
+ * options: { pipelineVariant: 'A', analysisMode: 'full' }
16361
+ * }
16362
+ * };
16363
+ * const retData = await api.ai.sessions.execute(params, authorization);
16364
+ */
16365
+ async execute(params, authorization) {
16366
+ const self = this;
16367
+
16368
+ try {
16369
+ Joi__default["default"].assert(params, Joi__default["default"].object().required().error(new Error('params is required')));
16370
+ Joi__default["default"].assert(params.sessionId, Joi__default["default"].string().required().error(new Error('sessionId is required')));
16371
+
16372
+ const { sessionId, ...payload } = params;
16373
+
16374
+ const client = self.parent.dispatch.getAkamaiClient();
16375
+ const apiCall = client
16376
+ .post(`/agents/${sessionId}/execute`, payload, self._setHeader(authorization));
16260
16377
 
16261
16378
  return self._returnData(await apiCall);
16262
16379
  } catch (ex) {
@@ -16277,7 +16394,6 @@ class MyndAI {
16277
16394
 
16278
16395
  const self = this;
16279
16396
  self.parent = options.parent;
16280
- self._client = self.parent.dispatch.getClient();
16281
16397
 
16282
16398
  self.sessions = new AISession(options);
16283
16399
  }
@@ -16354,7 +16470,8 @@ class MyndAI {
16354
16470
  Joi__default["default"].assert(params, Joi__default["default"].object().required().error(new Error('params is required')));
16355
16471
  Joi__default["default"].assert(params.prompt, Joi__default["default"].string().required().error(new Error('Provide a prompt')));
16356
16472
 
16357
- const apiCall = self._client
16473
+ const client = self.parent.dispatch.getAkamaiClient();
16474
+ const apiCall = client
16358
16475
  .post('/agents/explain', params, self._setHeader(authorization));
16359
16476
 
16360
16477
  return self._returnData(await apiCall);
@@ -16421,6 +16538,7 @@ class API {
16421
16538
  }
16422
16539
  },
16423
16540
  uri: 'http://localhost:8080',
16541
+ akamaiUri: null,
16424
16542
  attemptsRetry: 3,
16425
16543
  httpStatusToRetry: [401],
16426
16544
  debug: {success: true, error: true}
@@ -16436,6 +16554,20 @@ class API {
16436
16554
  self.admin = new Admin({parent: self});
16437
16555
  self.external = new External({parent: self});
16438
16556
  self.ai = new MyndAI({parent: self});
16557
+
16558
+ // If akamaiUri was provided in options, configure the Akamai client
16559
+ if (self.options.akamaiUri) {
16560
+ self.dispatch.setAkamaiBaseUrl(self.options.akamaiUri);
16561
+ }
16562
+ }
16563
+
16564
+ /**
16565
+ * @description Set the Akamai base URL for agent/AI routes.
16566
+ * @param {string} url The Akamai base URL.
16567
+ * @public
16568
+ */
16569
+ setAkamaiBaseUrl(url) {
16570
+ this.dispatch.setAkamaiBaseUrl(url);
16439
16571
  }
16440
16572
  }
16441
16573