@miso.ai/client-sdk-ui 1.13.1-beta.1 → 1.13.1

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.
@@ -16,6 +16,7 @@ class SessionMaker {
16
16
  const session = Object.freeze({
17
17
  uuid: (0, _commons.uuidv4)(),
18
18
  index: this._sessionIndex++,
19
+ startAt: Date.now(),
19
20
  meta: {}
20
21
  });
21
22
  this._hub.update(fields.session(), session);
@@ -4,4 +4,4 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = exports.default = '1.13.1-beta.1';
7
+ var _default = exports.default = '1.13.1';
@@ -214,6 +214,7 @@ class Workflow extends _commons.Component {
214
214
 
215
215
  // request //
216
216
  _request(options = {}) {
217
+ this._writeRequestTimeToSession(Date.now(), options);
217
218
  const {
218
219
  session
219
220
  } = this;
@@ -226,6 +227,12 @@ class Workflow extends _commons.Component {
226
227
  session
227
228
  }));
228
229
  }
230
+ _writeRequestTimeToSession(timestamp, options) {
231
+ const {
232
+ session
233
+ } = this;
234
+ session.meta.requestAt = timestamp;
235
+ }
229
236
 
230
237
  // data //
231
238
  updateData(data) {
@@ -315,6 +322,7 @@ class Workflow extends _commons.Component {
315
322
  _defaultProcessInteraction(payload, args) {
316
323
  payload = this._writeApiInfoToInteraction(payload, args);
317
324
  payload = this._writeMisoIdToInteraction(payload, args);
325
+ payload = (0, _processors.writeSessionInfoToInteraction)(payload, args);
318
326
  payload = (0, _processors.writeRequestInfoToInteraction)(payload, args);
319
327
  payload = (0, _processors.writeRequestMetadataToInteraction)(payload, args);
320
328
  payload = (0, _processors.writeAffiliationInfoToInteraction)(payload, args);
@@ -31,6 +31,7 @@ exports.writeQuestionSourceToPayload = writeQuestionSourceToPayload;
31
31
  exports.writeRequestFromPreviousData = writeRequestFromPreviousData;
32
32
  exports.writeRequestInfoToInteraction = writeRequestInfoToInteraction;
33
33
  exports.writeRequestMetadataToInteraction = writeRequestMetadataToInteraction;
34
+ exports.writeSessionInfoToInteraction = writeSessionInfoToInteraction;
34
35
  exports.writeUnanswerableToMeta = writeUnanswerableToMeta;
35
36
  var _commons = require("@miso.ai/commons");
36
37
  var _constants = require("../constants.js");
@@ -398,6 +399,22 @@ function carryOverQuestionIdToData(data, oldData) {
398
399
  })
399
400
  });
400
401
  }
402
+ function writeUnanswerableToMeta(data) {
403
+ const {
404
+ value
405
+ } = data;
406
+ if (!value) {
407
+ return data;
408
+ }
409
+ if (!value.finished || value.finish_reason !== 'success' || value.sources && value.sources.length > 0) {
410
+ return data;
411
+ }
412
+ return Object.assign({}, data, {
413
+ meta: Object.assign({}, data.meta, {
414
+ unanswerable: true
415
+ })
416
+ });
417
+ }
401
418
 
402
419
  // interactions //
403
420
  function buildBaseInteraction(args) {
@@ -446,6 +463,24 @@ function buildBaseInteraction(args) {
446
463
  function areProducts(role, items = []) {
447
464
  return (0, _constants.isProductRole)(role) || items.length > 0 && typeof items[0] === 'object' && items[0].product_id;
448
465
  }
466
+ function writeSessionInfoToInteraction(payload, args) {
467
+ const {
468
+ session
469
+ } = args && args.data || {};
470
+ if (!session) {
471
+ return payload;
472
+ }
473
+ const now = args.now || Date.now();
474
+ return (0, _commons.mergeInteractions)(payload, {
475
+ context: {
476
+ custom_context: {
477
+ session_id: session.uuid,
478
+ session_elapsed: now - session.startAt,
479
+ session_request_elapsed: session.meta.requestAt ? now - session.meta.requestAt : undefined
480
+ }
481
+ }
482
+ });
483
+ }
449
484
  function writeRequestMetadataToInteraction(payload, args) {
450
485
  const {
451
486
  data
@@ -569,20 +604,4 @@ function writeEventTargetToInteraction(payload, {
569
604
  }
570
605
  }
571
606
  });
572
- }
573
- function writeUnanswerableToMeta(data) {
574
- const {
575
- value
576
- } = data;
577
- if (!value) {
578
- return data;
579
- }
580
- if (!value.finished || value.finish_reason !== 'success' || value.sources && value.sources.length > 0) {
581
- return data;
582
- }
583
- return Object.assign({}, data, {
584
- meta: Object.assign({}, data.meta, {
585
- unanswerable: true
586
- })
587
- });
588
607
  }
@@ -243,6 +243,12 @@ class SearchBasedWorkflow extends _base.default {
243
243
  exclude
244
244
  });
245
245
  }
246
+ _writeRequestTimeToSession(timestamp, options = {}) {
247
+ if (options.type !== _constants.REQUEST_TYPE.QUERY) {
248
+ return;
249
+ }
250
+ super._writeRequestTimeToSession(timestamp, options);
251
+ }
246
252
 
247
253
  // data //
248
254
  _defaultProcessData(data, oldData) {
package/package.json CHANGED
@@ -30,7 +30,7 @@
30
30
  "url": "https://github.com/MisoAI/miso-client-js-sdk/issues"
31
31
  },
32
32
  "dependencies": {
33
- "@miso.ai/commons": "1.13.1-beta.1"
33
+ "@miso.ai/commons": "1.13.1"
34
34
  },
35
- "version": "1.13.1-beta.1"
35
+ "version": "1.13.1"
36
36
  }
@@ -12,6 +12,7 @@ export default class SessionMaker {
12
12
  const session = Object.freeze({
13
13
  uuid: uuidv4(),
14
14
  index: this._sessionIndex++,
15
+ startAt: Date.now(),
15
16
  meta: {},
16
17
  });
17
18
  this._hub.update(fields.session(), session);
package/src/version.js CHANGED
@@ -1 +1 @@
1
- export default '1.13.1-beta.1';
1
+ export default '1.13.1';
@@ -10,6 +10,7 @@ import {
10
10
  writeDataStatus,
11
11
  writeMisoIdToMeta,
12
12
  buildBaseInteraction,
13
+ writeSessionInfoToInteraction,
13
14
  writeRequestInfoToInteraction,
14
15
  writeRequestMetadataToInteraction,
15
16
  writeAffiliationInfoToInteraction,
@@ -205,12 +206,18 @@ export default class Workflow extends Component {
205
206
 
206
207
  // request //
207
208
  _request(options = {}) {
209
+ this._writeRequestTimeToSession(Date.now(), options);
208
210
  const { session } = this;
209
211
  const request = mergeApiOptions(this._options.resolved.api, options);
210
212
  this.updateData({ session, request });
211
213
  this._hub.update(fields.request(), { ...request, session });
212
214
  }
213
215
 
216
+ _writeRequestTimeToSession(timestamp, options) {
217
+ const { session } = this;
218
+ session.meta.requestAt = timestamp;
219
+ }
220
+
214
221
  // data //
215
222
  updateData(data) {
216
223
  if (!data) {
@@ -302,6 +309,7 @@ export default class Workflow extends Component {
302
309
  _defaultProcessInteraction(payload, args) {
303
310
  payload = this._writeApiInfoToInteraction(payload, args);
304
311
  payload = this._writeMisoIdToInteraction(payload, args);
312
+ payload = writeSessionInfoToInteraction(payload, args);
305
313
  payload = writeRequestInfoToInteraction(payload, args);
306
314
  payload = writeRequestMetadataToInteraction(payload, args);
307
315
  payload = writeAffiliationInfoToInteraction(payload, args);
@@ -300,6 +300,23 @@ export function carryOverQuestionIdToData(data, oldData) {
300
300
  };
301
301
  }
302
302
 
303
+ export function writeUnanswerableToMeta(data) {
304
+ const { value } = data;
305
+ if (!value) {
306
+ return data;
307
+ }
308
+ if (!value.finished || value.finish_reason !== 'success' || (value.sources && value.sources.length > 0)) {
309
+ return data;
310
+ }
311
+ return {
312
+ ...data,
313
+ meta: {
314
+ ...data.meta,
315
+ unanswerable: true,
316
+ },
317
+ };
318
+ }
319
+
303
320
  // interactions //
304
321
  export function buildBaseInteraction(args) {
305
322
  const { role, type, items, ...rest } = args;
@@ -347,6 +364,23 @@ function areProducts(role, items = []) {
347
364
  return isProductRole(role) || (items.length > 0 && typeof items[0] === 'object' && items[0].product_id);
348
365
  }
349
366
 
367
+ export function writeSessionInfoToInteraction(payload, args) {
368
+ const { session } = args && args.data || {};
369
+ if (!session) {
370
+ return payload;
371
+ }
372
+ const now = args.now || Date.now();
373
+ return mergeInteractions(payload, {
374
+ context: {
375
+ custom_context: {
376
+ session_id: session.uuid,
377
+ session_elapsed: now - session.startAt,
378
+ session_request_elapsed: session.meta.requestAt ? now - session.meta.requestAt : undefined,
379
+ },
380
+ },
381
+ });
382
+ }
383
+
350
384
  export function writeRequestMetadataToInteraction(payload, args) {
351
385
  const { data } = args;
352
386
  if (!data) {
@@ -454,20 +488,3 @@ export function writeEventTargetToInteraction(payload, { event_target } = {}) {
454
488
  },
455
489
  });
456
490
  }
457
-
458
- export function writeUnanswerableToMeta(data) {
459
- const { value } = data;
460
- if (!value) {
461
- return data;
462
- }
463
- if (!value.finished || value.finish_reason !== 'success' || (value.sources && value.sources.length > 0)) {
464
- return data;
465
- }
466
- return {
467
- ...data,
468
- meta: {
469
- ...data.meta,
470
- unanswerable: true,
471
- },
472
- };
473
- }
@@ -242,6 +242,13 @@ export default class SearchBasedWorkflow extends Workflow {
242
242
  };
243
243
  }
244
244
 
245
+ _writeRequestTimeToSession(timestamp, options = {}) {
246
+ if (options.type !== REQUEST_TYPE.QUERY) {
247
+ return;
248
+ }
249
+ super._writeRequestTimeToSession(timestamp, options);
250
+ }
251
+
245
252
  // data //
246
253
  _defaultProcessData(data, oldData) {
247
254
  data = super._defaultProcessData(data, oldData);