@miso.ai/client-sdk-core 1.7.4 → 1.7.5-beta.2
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 +29 -51
- package/dist/cjs/version.js +1 -1
- package/dist/es/api/ask.js +30 -52
- package/dist/es/version.js +1 -1
- package/package.json +2 -2
package/dist/cjs/api/ask.js
CHANGED
|
@@ -6,8 +6,8 @@ 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 = ["
|
|
10
|
-
_excluded2 = ["
|
|
9
|
+
const _excluded = ["signal"],
|
|
10
|
+
_excluded2 = ["pollingInterval"];
|
|
11
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
12
|
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
13
|
class Ask extends _base.default {
|
|
@@ -16,6 +16,11 @@ class Ask extends _base.default {
|
|
|
16
16
|
}
|
|
17
17
|
async questions(payload) {
|
|
18
18
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
19
|
+
if (typeof payload === 'string' && payload.charAt(0) !== '{') {
|
|
20
|
+
return new Answer(this, {
|
|
21
|
+
question_id: payload
|
|
22
|
+
}, options);
|
|
23
|
+
}
|
|
19
24
|
const response = await this._run('questions', payload, options);
|
|
20
25
|
return new Answer(this, response, options);
|
|
21
26
|
}
|
|
@@ -27,59 +32,16 @@ class Ask extends _base.default {
|
|
|
27
32
|
method: 'GET'
|
|
28
33
|
}));
|
|
29
34
|
}
|
|
30
|
-
|
|
31
|
-
// TODO: move impl away
|
|
32
|
-
_iterable(questionId) {
|
|
33
|
-
let _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
34
|
-
let {
|
|
35
|
-
pollingInterval = 1000,
|
|
36
|
-
signal
|
|
37
|
-
} = _ref,
|
|
38
|
-
options = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
39
|
-
if (signal && signal.aborted) {
|
|
40
|
-
return [];
|
|
41
|
-
}
|
|
42
|
-
let apiErrorCount = 0;
|
|
43
|
-
const buffer = new _commons.ValueBuffer();
|
|
44
|
-
const intervalId = setInterval(async () => {
|
|
45
|
-
let response;
|
|
46
|
-
try {
|
|
47
|
-
response = await this._get(questionId, options);
|
|
48
|
-
} catch (error) {
|
|
49
|
-
console.error(error); // TODO
|
|
50
|
-
apiErrorCount++;
|
|
51
|
-
if (apiErrorCount > 10) {
|
|
52
|
-
clearInterval(intervalId);
|
|
53
|
-
buffer.error(error);
|
|
54
|
-
}
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
const {
|
|
58
|
-
finished
|
|
59
|
-
} = response;
|
|
60
|
-
buffer.update(response, finished);
|
|
61
|
-
if (response.finished) {
|
|
62
|
-
clearInterval(intervalId);
|
|
63
|
-
}
|
|
64
|
-
}, pollingInterval);
|
|
65
|
-
if (signal && signal.addEventListener) {
|
|
66
|
-
signal.addEventListener('abort', () => {
|
|
67
|
-
clearInterval(intervalId);
|
|
68
|
-
// TODO: optimize: abort current request as well
|
|
69
|
-
buffer.abort();
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
return buffer;
|
|
73
|
-
}
|
|
74
35
|
}
|
|
75
36
|
exports.default = Ask;
|
|
76
37
|
class Answer {
|
|
77
|
-
constructor(api,
|
|
38
|
+
constructor(api, _ref2) {
|
|
78
39
|
let {
|
|
79
40
|
question_id
|
|
80
|
-
} =
|
|
81
|
-
let
|
|
82
|
-
let options = _objectWithoutPropertiesLoose(
|
|
41
|
+
} = _ref2;
|
|
42
|
+
let _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
43
|
+
let options = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
44
|
+
// TODO: take external singal as well?
|
|
83
45
|
this._api = api;
|
|
84
46
|
this._questionId = question_id;
|
|
85
47
|
this._ac = new AbortController();
|
|
@@ -98,6 +60,22 @@ class Answer {
|
|
|
98
60
|
this._ac.abort();
|
|
99
61
|
}
|
|
100
62
|
[Symbol.asyncIterator]() {
|
|
101
|
-
|
|
63
|
+
var _this = this;
|
|
64
|
+
const fetch = async function () {
|
|
65
|
+
let {
|
|
66
|
+
signal
|
|
67
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
68
|
+
// TODO: pass signal
|
|
69
|
+
const response = await _this.get();
|
|
70
|
+
return [response, response.finished];
|
|
71
|
+
};
|
|
72
|
+
const _this$_options = this._options,
|
|
73
|
+
{
|
|
74
|
+
pollingInterval: interval
|
|
75
|
+
} = _this$_options,
|
|
76
|
+
options = _objectWithoutPropertiesLoose(_this$_options, _excluded2);
|
|
77
|
+
return (0, _commons.polling)(fetch, Object.assign({
|
|
78
|
+
interval
|
|
79
|
+
}, options))[Symbol.asyncIterator]();
|
|
102
80
|
}
|
|
103
81
|
}
|
package/dist/cjs/version.js
CHANGED
package/dist/es/api/ask.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const _excluded = ["
|
|
2
|
-
_excluded2 = ["
|
|
1
|
+
const _excluded = ["signal"],
|
|
2
|
+
_excluded2 = ["pollingInterval"];
|
|
3
3
|
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 {
|
|
4
|
+
import { polling } from '@miso.ai/commons';
|
|
5
5
|
import ApiBase from './base';
|
|
6
6
|
export default class Ask extends ApiBase {
|
|
7
7
|
constructor(api) {
|
|
@@ -9,6 +9,11 @@ export default class Ask extends ApiBase {
|
|
|
9
9
|
}
|
|
10
10
|
async questions(payload) {
|
|
11
11
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
12
|
+
if (typeof payload === 'string' && payload.charAt(0) !== '{') {
|
|
13
|
+
return new Answer(this, {
|
|
14
|
+
question_id: payload
|
|
15
|
+
}, options);
|
|
16
|
+
}
|
|
12
17
|
const response = await this._run('questions', payload, options);
|
|
13
18
|
return new Answer(this, response, options);
|
|
14
19
|
}
|
|
@@ -20,58 +25,15 @@ export default class Ask extends ApiBase {
|
|
|
20
25
|
method: 'GET'
|
|
21
26
|
}));
|
|
22
27
|
}
|
|
23
|
-
|
|
24
|
-
// TODO: move impl away
|
|
25
|
-
_iterable(questionId) {
|
|
26
|
-
let _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
27
|
-
let {
|
|
28
|
-
pollingInterval = 1000,
|
|
29
|
-
signal
|
|
30
|
-
} = _ref,
|
|
31
|
-
options = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
32
|
-
if (signal && signal.aborted) {
|
|
33
|
-
return [];
|
|
34
|
-
}
|
|
35
|
-
let apiErrorCount = 0;
|
|
36
|
-
const buffer = new ValueBuffer();
|
|
37
|
-
const intervalId = setInterval(async () => {
|
|
38
|
-
let response;
|
|
39
|
-
try {
|
|
40
|
-
response = await this._get(questionId, options);
|
|
41
|
-
} catch (error) {
|
|
42
|
-
console.error(error); // TODO
|
|
43
|
-
apiErrorCount++;
|
|
44
|
-
if (apiErrorCount > 10) {
|
|
45
|
-
clearInterval(intervalId);
|
|
46
|
-
buffer.error(error);
|
|
47
|
-
}
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
const {
|
|
51
|
-
finished
|
|
52
|
-
} = response;
|
|
53
|
-
buffer.update(response, finished);
|
|
54
|
-
if (response.finished) {
|
|
55
|
-
clearInterval(intervalId);
|
|
56
|
-
}
|
|
57
|
-
}, pollingInterval);
|
|
58
|
-
if (signal && signal.addEventListener) {
|
|
59
|
-
signal.addEventListener('abort', () => {
|
|
60
|
-
clearInterval(intervalId);
|
|
61
|
-
// TODO: optimize: abort current request as well
|
|
62
|
-
buffer.abort();
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
return buffer;
|
|
66
|
-
}
|
|
67
28
|
}
|
|
68
29
|
class Answer {
|
|
69
|
-
constructor(api,
|
|
30
|
+
constructor(api, _ref2) {
|
|
70
31
|
let {
|
|
71
32
|
question_id
|
|
72
|
-
} =
|
|
73
|
-
let
|
|
74
|
-
let options = _objectWithoutPropertiesLoose(
|
|
33
|
+
} = _ref2;
|
|
34
|
+
let _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
35
|
+
let options = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
36
|
+
// TODO: take external singal as well?
|
|
75
37
|
this._api = api;
|
|
76
38
|
this._questionId = question_id;
|
|
77
39
|
this._ac = new AbortController();
|
|
@@ -90,6 +52,22 @@ class Answer {
|
|
|
90
52
|
this._ac.abort();
|
|
91
53
|
}
|
|
92
54
|
[Symbol.asyncIterator]() {
|
|
93
|
-
|
|
55
|
+
var _this = this;
|
|
56
|
+
const fetch = async function () {
|
|
57
|
+
let {
|
|
58
|
+
signal
|
|
59
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
60
|
+
// TODO: pass signal
|
|
61
|
+
const response = await _this.get();
|
|
62
|
+
return [response, response.finished];
|
|
63
|
+
};
|
|
64
|
+
const _this$_options = this._options,
|
|
65
|
+
{
|
|
66
|
+
pollingInterval: interval
|
|
67
|
+
} = _this$_options,
|
|
68
|
+
options = _objectWithoutPropertiesLoose(_this$_options, _excluded2);
|
|
69
|
+
return polling(fetch, Object.assign({
|
|
70
|
+
interval
|
|
71
|
+
}, options))[Symbol.asyncIterator]();
|
|
94
72
|
}
|
|
95
73
|
}
|
package/dist/es/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '1.7.
|
|
1
|
+
export default '1.7.5-beta.2';
|