@miso.ai/client-sdk-core 1.7.5 → 1.7.6
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/dist/cjs/api/ask.js +30 -18
- package/dist/cjs/version.js +1 -1
- package/dist/es/api/ask.js +31 -19
- package/dist/es/version.js +1 -1
- package/package.json +2 -2
package/dist/cjs/api/ask.js
CHANGED
|
@@ -6,8 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _commons = require("@miso.ai/commons");
|
|
8
8
|
var _base = _interopRequireDefault(require("./base"));
|
|
9
|
-
const _excluded = ["signal"]
|
|
10
|
-
_excluded2 = ["pollingInterval"];
|
|
9
|
+
const _excluded = ["pollingInterval", "signal", "stallTimeout"];
|
|
11
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
11
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
13
12
|
class Ask extends _base.default {
|
|
@@ -35,29 +34,24 @@ class Ask extends _base.default {
|
|
|
35
34
|
}
|
|
36
35
|
exports.default = Ask;
|
|
37
36
|
class Answer {
|
|
38
|
-
constructor(api,
|
|
37
|
+
constructor(api, _ref) {
|
|
39
38
|
let {
|
|
40
39
|
question_id
|
|
41
|
-
} =
|
|
42
|
-
let
|
|
43
|
-
let options = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
44
|
-
// TODO: take external singal as well?
|
|
40
|
+
} = _ref;
|
|
41
|
+
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
45
42
|
this._api = api;
|
|
46
43
|
this._questionId = question_id;
|
|
47
44
|
this._ac = new AbortController();
|
|
48
|
-
this._options =
|
|
49
|
-
signal: this._ac.signal
|
|
50
|
-
});
|
|
45
|
+
this._options = options;
|
|
51
46
|
}
|
|
52
47
|
get questionId() {
|
|
53
48
|
return this._questionId;
|
|
54
49
|
}
|
|
55
50
|
async get(options) {
|
|
56
|
-
|
|
57
|
-
return this._api._get(this._questionId, options);
|
|
51
|
+
return this._api._get(this._questionId, Object.assign({}, this._options, options));
|
|
58
52
|
}
|
|
59
|
-
abort() {
|
|
60
|
-
this._ac.abort();
|
|
53
|
+
abort(reason) {
|
|
54
|
+
this._ac.abort(reason);
|
|
61
55
|
}
|
|
62
56
|
[Symbol.asyncIterator]() {
|
|
63
57
|
var _this = this;
|
|
@@ -69,13 +63,31 @@ class Answer {
|
|
|
69
63
|
const response = await _this.get();
|
|
70
64
|
return [response, response.finished];
|
|
71
65
|
};
|
|
72
|
-
|
|
66
|
+
let _this$_options = this._options,
|
|
73
67
|
{
|
|
74
|
-
pollingInterval: interval
|
|
68
|
+
pollingInterval: interval,
|
|
69
|
+
signal,
|
|
70
|
+
stallTimeout = 30000
|
|
75
71
|
} = _this$_options,
|
|
76
|
-
options = _objectWithoutPropertiesLoose(_this$_options,
|
|
72
|
+
options = _objectWithoutPropertiesLoose(_this$_options, _excluded);
|
|
73
|
+
const stac = new _commons.StallTimeoutAbortController(stallTimeout);
|
|
74
|
+
signal = _commons.signals.any(this._ac.signal, stac.signal, signal);
|
|
75
|
+
let prevResponse;
|
|
76
|
+
const onResponse = (response, finished) => {
|
|
77
|
+
if (finished) {
|
|
78
|
+
stac.clear();
|
|
79
|
+
} else if (isUpdated(prevResponse, response)) {
|
|
80
|
+
stac.touch();
|
|
81
|
+
}
|
|
82
|
+
prevResponse = response;
|
|
83
|
+
};
|
|
77
84
|
return (0, _commons.polling)(fetch, Object.assign({
|
|
78
|
-
interval
|
|
85
|
+
interval,
|
|
86
|
+
signal,
|
|
87
|
+
onResponse
|
|
79
88
|
}, options))[Symbol.asyncIterator]();
|
|
80
89
|
}
|
|
90
|
+
}
|
|
91
|
+
function isUpdated(prev, curr) {
|
|
92
|
+
return !prev || prev.answer_stage !== curr.answer_stage || prev.answer.length !== curr.answer.length;
|
|
81
93
|
}
|
package/dist/cjs/version.js
CHANGED
package/dist/es/api/ask.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
const _excluded = ["signal"]
|
|
2
|
-
_excluded2 = ["pollingInterval"];
|
|
1
|
+
const _excluded = ["pollingInterval", "signal", "stallTimeout"];
|
|
3
2
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
4
|
-
import { polling } from '@miso.ai/commons';
|
|
3
|
+
import { polling, signals, StallTimeoutAbortController } from '@miso.ai/commons';
|
|
5
4
|
import ApiBase from './base';
|
|
6
5
|
export default class Ask extends ApiBase {
|
|
7
6
|
constructor(api) {
|
|
@@ -27,29 +26,24 @@ export default class Ask extends ApiBase {
|
|
|
27
26
|
}
|
|
28
27
|
}
|
|
29
28
|
class Answer {
|
|
30
|
-
constructor(api,
|
|
29
|
+
constructor(api, _ref) {
|
|
31
30
|
let {
|
|
32
31
|
question_id
|
|
33
|
-
} =
|
|
34
|
-
let
|
|
35
|
-
let options = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
36
|
-
// TODO: take external singal as well?
|
|
32
|
+
} = _ref;
|
|
33
|
+
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
37
34
|
this._api = api;
|
|
38
35
|
this._questionId = question_id;
|
|
39
36
|
this._ac = new AbortController();
|
|
40
|
-
this._options =
|
|
41
|
-
signal: this._ac.signal
|
|
42
|
-
});
|
|
37
|
+
this._options = options;
|
|
43
38
|
}
|
|
44
39
|
get questionId() {
|
|
45
40
|
return this._questionId;
|
|
46
41
|
}
|
|
47
42
|
async get(options) {
|
|
48
|
-
|
|
49
|
-
return this._api._get(this._questionId, options);
|
|
43
|
+
return this._api._get(this._questionId, Object.assign({}, this._options, options));
|
|
50
44
|
}
|
|
51
|
-
abort() {
|
|
52
|
-
this._ac.abort();
|
|
45
|
+
abort(reason) {
|
|
46
|
+
this._ac.abort(reason);
|
|
53
47
|
}
|
|
54
48
|
[Symbol.asyncIterator]() {
|
|
55
49
|
var _this = this;
|
|
@@ -61,13 +55,31 @@ class Answer {
|
|
|
61
55
|
const response = await _this.get();
|
|
62
56
|
return [response, response.finished];
|
|
63
57
|
};
|
|
64
|
-
|
|
58
|
+
let _this$_options = this._options,
|
|
65
59
|
{
|
|
66
|
-
pollingInterval: interval
|
|
60
|
+
pollingInterval: interval,
|
|
61
|
+
signal,
|
|
62
|
+
stallTimeout = 30000
|
|
67
63
|
} = _this$_options,
|
|
68
|
-
options = _objectWithoutPropertiesLoose(_this$_options,
|
|
64
|
+
options = _objectWithoutPropertiesLoose(_this$_options, _excluded);
|
|
65
|
+
const stac = new StallTimeoutAbortController(stallTimeout);
|
|
66
|
+
signal = signals.any(this._ac.signal, stac.signal, signal);
|
|
67
|
+
let prevResponse;
|
|
68
|
+
const onResponse = (response, finished) => {
|
|
69
|
+
if (finished) {
|
|
70
|
+
stac.clear();
|
|
71
|
+
} else if (isUpdated(prevResponse, response)) {
|
|
72
|
+
stac.touch();
|
|
73
|
+
}
|
|
74
|
+
prevResponse = response;
|
|
75
|
+
};
|
|
69
76
|
return polling(fetch, Object.assign({
|
|
70
|
-
interval
|
|
77
|
+
interval,
|
|
78
|
+
signal,
|
|
79
|
+
onResponse
|
|
71
80
|
}, options))[Symbol.asyncIterator]();
|
|
72
81
|
}
|
|
82
|
+
}
|
|
83
|
+
function isUpdated(prev, curr) {
|
|
84
|
+
return !prev || prev.answer_stage !== curr.answer_stage || prev.answer.length !== curr.answer.length;
|
|
73
85
|
}
|
package/dist/es/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '1.7.
|
|
1
|
+
export default '1.7.6';
|