@miso.ai/client-sdk-core 1.7.2 → 1.7.3-beta.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.
- package/dist/cjs/api/ask.js +59 -58
- package/dist/cjs/version.js +1 -1
- package/dist/es/api/ask.js +58 -57
- package/dist/es/version.js +1 -1
- package/package.json +2 -2
package/dist/cjs/api/ask.js
CHANGED
|
@@ -6,78 +6,79 @@ 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 = ["pollingInternal"];
|
|
9
|
+
const _excluded = ["pollingInternal"];
|
|
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 {
|
|
14
13
|
constructor(api) {
|
|
15
14
|
super(api, 'ask');
|
|
16
15
|
}
|
|
17
|
-
questions(payload) {
|
|
18
|
-
let
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
} = _ref,
|
|
22
|
-
options = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
23
|
-
// TODO: it's possible to merge _iterator and _answer
|
|
24
|
-
return typeof payload === 'string' ? this._get(payload, options) : iterable ? this._iterator(payload, options) : this._questions(payload, options);
|
|
16
|
+
async questions(payload) {
|
|
17
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
18
|
+
const response = await this._run('questions', payload, options);
|
|
19
|
+
return new Answer(this, response);
|
|
25
20
|
}
|
|
26
21
|
async _questions(payload, options) {
|
|
27
22
|
return this._run('questions', payload, options);
|
|
28
23
|
}
|
|
29
|
-
async _get(
|
|
30
|
-
return this._run(`questions/${
|
|
24
|
+
async _get(questionId, options) {
|
|
25
|
+
return this._run(`questions/${questionId}/answer`, undefined, Object.assign({}, options, {
|
|
31
26
|
method: 'GET'
|
|
32
27
|
}));
|
|
33
28
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (
|
|
50
|
-
|
|
29
|
+
_iterable(questionId) {
|
|
30
|
+
let _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
31
|
+
let {
|
|
32
|
+
pollingInternal = 500
|
|
33
|
+
} = _ref,
|
|
34
|
+
options = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
35
|
+
// TODO: abort signal
|
|
36
|
+
let apiErrorCount = 0;
|
|
37
|
+
const buffer = new _commons.ValueBuffer();
|
|
38
|
+
const intervalId = setInterval(async () => {
|
|
39
|
+
let response;
|
|
40
|
+
try {
|
|
41
|
+
response = await this._get(questionId, options);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
apiErrorCount++;
|
|
44
|
+
if (apiErrorCount > 10) {
|
|
45
|
+
clearInterval(intervalId);
|
|
46
|
+
// TODO: cascade to buffer and user
|
|
51
47
|
}
|
|
52
|
-
let apiErrorCount = 0;
|
|
53
|
-
const buffer = new _commons.ValueBuffer();
|
|
54
|
-
const intervalId = setInterval(async () => {
|
|
55
|
-
let response;
|
|
56
|
-
try {
|
|
57
|
-
response = await _this._get(question_id, options);
|
|
58
|
-
} catch (error) {
|
|
59
|
-
apiErrorCount++;
|
|
60
|
-
if (apiErrorCount > 10) {
|
|
61
|
-
clearInterval(intervalId);
|
|
62
|
-
// TODO: cascade to buffer and user
|
|
63
|
-
}
|
|
64
48
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}();
|
|
78
|
-
} catch (e) {
|
|
79
|
-
return Promise.reject(e);
|
|
80
|
-
}
|
|
49
|
+
console.error(error); // TODO
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const {
|
|
53
|
+
finished
|
|
54
|
+
} = response;
|
|
55
|
+
buffer.update(response, finished);
|
|
56
|
+
if (response.finished) {
|
|
57
|
+
clearInterval(intervalId);
|
|
58
|
+
}
|
|
59
|
+
}, pollingInternal);
|
|
60
|
+
return buffer;
|
|
81
61
|
}
|
|
82
62
|
}
|
|
83
|
-
exports.default = Ask;
|
|
63
|
+
exports.default = Ask;
|
|
64
|
+
class Answer {
|
|
65
|
+
constructor(api, _ref2) {
|
|
66
|
+
let {
|
|
67
|
+
question_id
|
|
68
|
+
} = _ref2;
|
|
69
|
+
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
70
|
+
this._api = api;
|
|
71
|
+
this._id = question_id;
|
|
72
|
+
this._options = options;
|
|
73
|
+
}
|
|
74
|
+
get id() {
|
|
75
|
+
return this._id;
|
|
76
|
+
}
|
|
77
|
+
async get(options) {
|
|
78
|
+
options = Object.assign({}, this._options, options);
|
|
79
|
+
return this._api._get(this._id, options);
|
|
80
|
+
}
|
|
81
|
+
[Symbol.asyncIterator]() {
|
|
82
|
+
return this._api._iterable(this._id, this._options)[Symbol.asyncIterator]();
|
|
83
|
+
}
|
|
84
|
+
}
|
package/dist/cjs/version.js
CHANGED
package/dist/es/api/ask.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
const _excluded = ["
|
|
2
|
-
_excluded2 = ["pollingInternal"];
|
|
1
|
+
const _excluded = ["pollingInternal"];
|
|
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
3
|
import { ValueBuffer } from '@miso.ai/commons';
|
|
5
4
|
import ApiBase from './base';
|
|
@@ -7,69 +6,71 @@ export default class Ask extends ApiBase {
|
|
|
7
6
|
constructor(api) {
|
|
8
7
|
super(api, 'ask');
|
|
9
8
|
}
|
|
10
|
-
questions(payload) {
|
|
11
|
-
let
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
} = _ref,
|
|
15
|
-
options = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
16
|
-
// TODO: it's possible to merge _iterator and _answer
|
|
17
|
-
return typeof payload === 'string' ? this._get(payload, options) : iterable ? this._iterator(payload, options) : this._questions(payload, options);
|
|
9
|
+
async questions(payload) {
|
|
10
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
11
|
+
const response = await this._run('questions', payload, options);
|
|
12
|
+
return new Answer(this, response);
|
|
18
13
|
}
|
|
19
14
|
async _questions(payload, options) {
|
|
20
15
|
return this._run('questions', payload, options);
|
|
21
16
|
}
|
|
22
|
-
async _get(
|
|
23
|
-
return this._run(`questions/${
|
|
17
|
+
async _get(questionId, options) {
|
|
18
|
+
return this._run(`questions/${questionId}/answer`, undefined, Object.assign({}, options, {
|
|
24
19
|
method: 'GET'
|
|
25
20
|
}));
|
|
26
21
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (
|
|
43
|
-
|
|
22
|
+
_iterable(questionId) {
|
|
23
|
+
let _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
24
|
+
let {
|
|
25
|
+
pollingInternal = 500
|
|
26
|
+
} = _ref,
|
|
27
|
+
options = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
28
|
+
// TODO: abort signal
|
|
29
|
+
let apiErrorCount = 0;
|
|
30
|
+
const buffer = new ValueBuffer();
|
|
31
|
+
const intervalId = setInterval(async () => {
|
|
32
|
+
let response;
|
|
33
|
+
try {
|
|
34
|
+
response = await this._get(questionId, options);
|
|
35
|
+
} catch (error) {
|
|
36
|
+
apiErrorCount++;
|
|
37
|
+
if (apiErrorCount > 10) {
|
|
38
|
+
clearInterval(intervalId);
|
|
39
|
+
// TODO: cascade to buffer and user
|
|
44
40
|
}
|
|
45
|
-
let apiErrorCount = 0;
|
|
46
|
-
const buffer = new ValueBuffer();
|
|
47
|
-
const intervalId = setInterval(async () => {
|
|
48
|
-
let response;
|
|
49
|
-
try {
|
|
50
|
-
response = await _this._get(question_id, options);
|
|
51
|
-
} catch (error) {
|
|
52
|
-
apiErrorCount++;
|
|
53
|
-
if (apiErrorCount > 10) {
|
|
54
|
-
clearInterval(intervalId);
|
|
55
|
-
// TODO: cascade to buffer and user
|
|
56
|
-
}
|
|
57
41
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
42
|
+
console.error(error); // TODO
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const {
|
|
46
|
+
finished
|
|
47
|
+
} = response;
|
|
48
|
+
buffer.update(response, finished);
|
|
49
|
+
if (response.finished) {
|
|
50
|
+
clearInterval(intervalId);
|
|
51
|
+
}
|
|
52
|
+
}, pollingInternal);
|
|
53
|
+
return buffer;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
class Answer {
|
|
57
|
+
constructor(api, _ref2) {
|
|
58
|
+
let {
|
|
59
|
+
question_id
|
|
60
|
+
} = _ref2;
|
|
61
|
+
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
62
|
+
this._api = api;
|
|
63
|
+
this._id = question_id;
|
|
64
|
+
this._options = options;
|
|
65
|
+
}
|
|
66
|
+
get id() {
|
|
67
|
+
return this._id;
|
|
68
|
+
}
|
|
69
|
+
async get(options) {
|
|
70
|
+
options = Object.assign({}, this._options, options);
|
|
71
|
+
return this._api._get(this._id, options);
|
|
72
|
+
}
|
|
73
|
+
[Symbol.asyncIterator]() {
|
|
74
|
+
return this._api._iterable(this._id, this._options)[Symbol.asyncIterator]();
|
|
74
75
|
}
|
|
75
76
|
}
|
package/dist/es/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '1.7.
|
|
1
|
+
export default '1.7.3-beta.1';
|