@miso.ai/client-sdk-core 1.10.3 → 1.10.4-beta.0
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 +35 -59
- package/dist/cjs/api/iterable.js +81 -0
- package/dist/cjs/version.js +1 -1
- package/package.json +2 -2
- package/src/api/ask.js +32 -40
- package/src/api/iterable.js +71 -0
- package/src/version.js +1 -1
package/dist/cjs/api/ask.js
CHANGED
|
@@ -6,9 +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.js"));
|
|
9
|
-
|
|
9
|
+
var _iterable = require("./iterable.js");
|
|
10
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
-
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
|
|
12
11
|
const {
|
|
13
12
|
GROUP,
|
|
14
13
|
NAME
|
|
@@ -19,18 +18,18 @@ class Ask extends _base.default {
|
|
|
19
18
|
}
|
|
20
19
|
async questions(payload) {
|
|
21
20
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
22
|
-
if (
|
|
23
|
-
return new Answer(this,
|
|
24
|
-
question_id: payload
|
|
25
|
-
}, options);
|
|
21
|
+
if (isId(payload)) {
|
|
22
|
+
return new Answer(this, payload, options);
|
|
26
23
|
}
|
|
27
|
-
const
|
|
28
|
-
|
|
24
|
+
const {
|
|
25
|
+
question_id
|
|
26
|
+
} = await this._run(NAME.QUESTIONS, payload, options);
|
|
27
|
+
return new Answer(this, question_id, options);
|
|
29
28
|
}
|
|
30
29
|
async _questions(payload, options) {
|
|
31
30
|
return this._run(NAME.QUESTIONS, payload, options);
|
|
32
31
|
}
|
|
33
|
-
async
|
|
32
|
+
async _questionGet(questionId, options) {
|
|
34
33
|
return this._run(`${NAME.QUESTIONS}/${questionId}/answer`, undefined, Object.assign({}, options, {
|
|
35
34
|
method: 'GET'
|
|
36
35
|
}));
|
|
@@ -39,63 +38,40 @@ class Ask extends _base.default {
|
|
|
39
38
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
40
39
|
return this._run(NAME.RELATED_QUESTIONS, payload, options);
|
|
41
40
|
}
|
|
41
|
+
async search(payload) {
|
|
42
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
43
|
+
const response = await this._run(NAME.SEARCH, payload, options);
|
|
44
|
+
return response.question_id ? new SearchResult(this, response, options) : response;
|
|
45
|
+
}
|
|
46
|
+
async _searchGet(questionId, options) {
|
|
47
|
+
return this._run(`${NAME.SEARCH}/${questionId}/answer`, undefined, Object.assign({}, options, {
|
|
48
|
+
method: 'GET'
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
42
51
|
}
|
|
43
52
|
exports.default = Ask;
|
|
44
|
-
class Answer {
|
|
45
|
-
constructor(api,
|
|
46
|
-
let {
|
|
47
|
-
question_id
|
|
48
|
-
} = _ref;
|
|
53
|
+
class Answer extends _iterable.IdBasedIterableApiStub {
|
|
54
|
+
constructor(api, questionId) {
|
|
49
55
|
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
50
|
-
|
|
51
|
-
this._questionId = question_id;
|
|
52
|
-
this._ac = new AbortController();
|
|
53
|
-
this._options = options;
|
|
56
|
+
super(api, '_questionGet', questionId, options);
|
|
54
57
|
}
|
|
55
58
|
get questionId() {
|
|
56
|
-
return this.
|
|
57
|
-
}
|
|
58
|
-
async get(options) {
|
|
59
|
-
return this._api._get(this._questionId, Object.assign({}, this._options, options));
|
|
59
|
+
return this._id;
|
|
60
60
|
}
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
}
|
|
62
|
+
class SearchResult extends _iterable.IdBasedIterableApiStub {
|
|
63
|
+
constructor(api, response) {
|
|
64
|
+
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
65
|
+
super(api, '_searchGet', response.question_id, options);
|
|
66
|
+
(0, _commons.defineValues)(this, response);
|
|
67
|
+
this._response = response;
|
|
63
68
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const fetch = async function () {
|
|
67
|
-
let {
|
|
68
|
-
signal
|
|
69
|
-
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
70
|
-
// TODO: pass signal
|
|
71
|
-
const response = await _this.get();
|
|
72
|
-
return [response, response.finished, response.revision];
|
|
73
|
-
};
|
|
74
|
-
let _this$_options = this._options,
|
|
75
|
-
{
|
|
76
|
-
pollingInterval: interval,
|
|
77
|
-
signal,
|
|
78
|
-
stallTimeout = 120000
|
|
79
|
-
} = _this$_options,
|
|
80
|
-
options = _objectWithoutPropertiesLoose(_this$_options, _excluded);
|
|
81
|
-
const stac = new _commons.StallTimeoutAbortController(stallTimeout);
|
|
82
|
-
signal = _commons.signals.any(this._ac.signal, stac.signal, signal);
|
|
83
|
-
let prevResponse;
|
|
84
|
-
const onResponse = (response, finished) => {
|
|
85
|
-
if (finished) {
|
|
86
|
-
stac.clear();
|
|
87
|
-
} else if (isUpdated(prevResponse, response)) {
|
|
88
|
-
stac.touch();
|
|
89
|
-
}
|
|
90
|
-
prevResponse = response;
|
|
91
|
-
};
|
|
92
|
-
return (0, _commons.polling)(fetch, Object.assign({
|
|
93
|
-
interval,
|
|
94
|
-
signal,
|
|
95
|
-
onResponse
|
|
96
|
-
}, options))[Symbol.asyncIterator]();
|
|
69
|
+
get questionId() {
|
|
70
|
+
return this._id;
|
|
97
71
|
}
|
|
98
72
|
}
|
|
99
|
-
|
|
100
|
-
|
|
73
|
+
|
|
74
|
+
// helpers //
|
|
75
|
+
function isId(value) {
|
|
76
|
+
return typeof value === 'string' && value.charAt(0) !== '{';
|
|
101
77
|
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.IterableApiStub = exports.IdBasedIterableApiStub = void 0;
|
|
7
|
+
var _commons = require("@miso.ai/commons");
|
|
8
|
+
const _excluded = ["pollingInterval", "signal", "stallTimeout"];
|
|
9
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
|
|
10
|
+
class IterableApiStub {
|
|
11
|
+
constructor() {
|
|
12
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
13
|
+
this._ac = new AbortController();
|
|
14
|
+
this._options = options;
|
|
15
|
+
}
|
|
16
|
+
async get(options) {
|
|
17
|
+
return this._get(Object.assign({}, this._options, options));
|
|
18
|
+
}
|
|
19
|
+
_get(options) {
|
|
20
|
+
throw new Error('Not implemented');
|
|
21
|
+
}
|
|
22
|
+
abort(reason) {
|
|
23
|
+
this._ac.abort(reason);
|
|
24
|
+
}
|
|
25
|
+
[Symbol.asyncIterator]() {
|
|
26
|
+
var _this = this;
|
|
27
|
+
const fetch = async function () {
|
|
28
|
+
let {
|
|
29
|
+
signal
|
|
30
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
31
|
+
// TODO: pass signal
|
|
32
|
+
const response = await _this.get();
|
|
33
|
+
return [response, _this._isFinished(response), _this._revisionOf(response)];
|
|
34
|
+
};
|
|
35
|
+
let _this$_options = this._options,
|
|
36
|
+
{
|
|
37
|
+
pollingInterval: interval,
|
|
38
|
+
signal,
|
|
39
|
+
stallTimeout = 120000
|
|
40
|
+
} = _this$_options,
|
|
41
|
+
options = _objectWithoutPropertiesLoose(_this$_options, _excluded);
|
|
42
|
+
const stac = new _commons.StallTimeoutAbortController(stallTimeout);
|
|
43
|
+
signal = _commons.signals.any(this._ac.signal, stac.signal, signal);
|
|
44
|
+
let prevResponse;
|
|
45
|
+
const onResponse = (response, finished) => {
|
|
46
|
+
if (finished) {
|
|
47
|
+
stac.clear();
|
|
48
|
+
} else if (this._isUpdated(prevResponse, response)) {
|
|
49
|
+
stac.touch();
|
|
50
|
+
}
|
|
51
|
+
prevResponse = response;
|
|
52
|
+
};
|
|
53
|
+
return (0, _commons.polling)(fetch, Object.assign({
|
|
54
|
+
interval,
|
|
55
|
+
signal,
|
|
56
|
+
onResponse
|
|
57
|
+
}, options))[Symbol.asyncIterator]();
|
|
58
|
+
}
|
|
59
|
+
_isFinished(response) {
|
|
60
|
+
return !!(response && response.finished);
|
|
61
|
+
}
|
|
62
|
+
_isUpdated(previousResponse, newResponse) {
|
|
63
|
+
return !previousResponse || previousResponse.answer_stage !== newResponse.answer_stage || previousResponse.answer.length !== newResponse.answer.length;
|
|
64
|
+
}
|
|
65
|
+
_revisionOf(response) {
|
|
66
|
+
return response && response.revision;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.IterableApiStub = IterableApiStub;
|
|
70
|
+
class IdBasedIterableApiStub extends IterableApiStub {
|
|
71
|
+
constructor(api, method, id, options) {
|
|
72
|
+
super(options);
|
|
73
|
+
this._api = api;
|
|
74
|
+
this._method = method;
|
|
75
|
+
this._id = id;
|
|
76
|
+
}
|
|
77
|
+
async _get(options) {
|
|
78
|
+
return this._api[this._method](this._id, options);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.IdBasedIterableApiStub = IdBasedIterableApiStub;
|
package/dist/cjs/version.js
CHANGED
package/package.json
CHANGED
package/src/api/ask.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { API, defineValues, isNullLike } from '@miso.ai/commons';
|
|
2
2
|
import ApiBase from './base.js';
|
|
3
|
+
import { IdBasedIterableApiStub } from './iterable.js';
|
|
3
4
|
|
|
4
5
|
const { GROUP, NAME } = API;
|
|
5
6
|
|
|
@@ -10,18 +11,18 @@ export default class Ask extends ApiBase {
|
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
async questions(payload, options = {}) {
|
|
13
|
-
if (
|
|
14
|
-
return new Answer(this,
|
|
14
|
+
if (isId(payload)) {
|
|
15
|
+
return new Answer(this, payload, options);
|
|
15
16
|
}
|
|
16
|
-
const
|
|
17
|
-
return new Answer(this,
|
|
17
|
+
const { question_id } = await this._run(NAME.QUESTIONS, payload, options);
|
|
18
|
+
return new Answer(this, question_id, options);
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
async _questions(payload, options) {
|
|
21
22
|
return this._run(NAME.QUESTIONS, payload, options);
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
async
|
|
25
|
+
async _questionGet(questionId, options) {
|
|
25
26
|
return this._run(`${NAME.QUESTIONS}/${questionId}/answer`, undefined, { ...options, method: 'GET' });
|
|
26
27
|
}
|
|
27
28
|
|
|
@@ -29,53 +30,44 @@ export default class Ask extends ApiBase {
|
|
|
29
30
|
return this._run(NAME.RELATED_QUESTIONS, payload, options);
|
|
30
31
|
}
|
|
31
32
|
|
|
33
|
+
async search(payload, options = {}) {
|
|
34
|
+
const response = await this._run(NAME.SEARCH, payload, options);
|
|
35
|
+
return response.question_id ? new SearchResult(this, response, options) : response;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async _searchGet(questionId, options) {
|
|
39
|
+
return this._run(`${NAME.SEARCH}/${questionId}/answer`, undefined, { ...options, method: 'GET' });
|
|
40
|
+
}
|
|
41
|
+
|
|
32
42
|
}
|
|
33
43
|
|
|
34
|
-
class Answer {
|
|
44
|
+
class Answer extends IdBasedIterableApiStub {
|
|
35
45
|
|
|
36
|
-
constructor(api,
|
|
37
|
-
|
|
38
|
-
this._questionId = question_id;
|
|
39
|
-
this._ac = new AbortController();
|
|
40
|
-
this._options = options;
|
|
46
|
+
constructor(api, questionId, options = {}) {
|
|
47
|
+
super(api, '_questionGet', questionId, options);
|
|
41
48
|
}
|
|
42
49
|
|
|
43
50
|
get questionId() {
|
|
44
|
-
return this.
|
|
51
|
+
return this._id;
|
|
45
52
|
}
|
|
46
53
|
|
|
47
|
-
|
|
48
|
-
return this._api._get(this._questionId, { ...this._options, ...options });
|
|
49
|
-
}
|
|
54
|
+
}
|
|
50
55
|
|
|
51
|
-
|
|
52
|
-
|
|
56
|
+
class SearchResult extends IdBasedIterableApiStub {
|
|
57
|
+
|
|
58
|
+
constructor(api, response, options = {}) {
|
|
59
|
+
super(api, '_searchGet', response.question_id, options);
|
|
60
|
+
defineValues(this, response);
|
|
61
|
+
this._response = response;
|
|
53
62
|
}
|
|
54
63
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
// TODO: pass signal
|
|
58
|
-
const response = await this.get();
|
|
59
|
-
return [response, response.finished, response.revision];
|
|
60
|
-
};
|
|
61
|
-
let { pollingInterval: interval, signal, stallTimeout = 120000, ...options } = this._options;
|
|
62
|
-
const stac = new StallTimeoutAbortController(stallTimeout);
|
|
63
|
-
signal = signals.any(this._ac.signal, stac.signal, signal);
|
|
64
|
-
|
|
65
|
-
let prevResponse;
|
|
66
|
-
const onResponse = (response, finished) => {
|
|
67
|
-
if (finished) {
|
|
68
|
-
stac.clear();
|
|
69
|
-
} else if (isUpdated(prevResponse, response)) {
|
|
70
|
-
stac.touch();
|
|
71
|
-
}
|
|
72
|
-
prevResponse = response;
|
|
73
|
-
};
|
|
74
|
-
return polling(fetch, { interval, signal, onResponse, ...options })[Symbol.asyncIterator]();
|
|
64
|
+
get questionId() {
|
|
65
|
+
return this._id;
|
|
75
66
|
}
|
|
76
67
|
|
|
77
68
|
}
|
|
78
69
|
|
|
79
|
-
|
|
80
|
-
|
|
70
|
+
// helpers //
|
|
71
|
+
function isId(value) {
|
|
72
|
+
return typeof value === 'string' && value.charAt(0) !== '{';
|
|
81
73
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { polling, signals, StallTimeoutAbortController } from '@miso.ai/commons';
|
|
2
|
+
|
|
3
|
+
export class IterableApiStub {
|
|
4
|
+
|
|
5
|
+
constructor(options = {}) {
|
|
6
|
+
this._ac = new AbortController();
|
|
7
|
+
this._options = options;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async get(options) {
|
|
11
|
+
return this._get({ ...this._options, ...options });
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
_get(options) {
|
|
15
|
+
throw new Error('Not implemented');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
abort(reason) {
|
|
19
|
+
this._ac.abort(reason);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
[Symbol.asyncIterator]() {
|
|
23
|
+
const fetch = async ({ signal } = {}) => {
|
|
24
|
+
// TODO: pass signal
|
|
25
|
+
const response = await this.get();
|
|
26
|
+
return [response, this._isFinished(response), this._revisionOf(response)];
|
|
27
|
+
};
|
|
28
|
+
let { pollingInterval: interval, signal, stallTimeout = 120000, ...options } = this._options;
|
|
29
|
+
const stac = new StallTimeoutAbortController(stallTimeout);
|
|
30
|
+
signal = signals.any(this._ac.signal, stac.signal, signal);
|
|
31
|
+
|
|
32
|
+
let prevResponse;
|
|
33
|
+
const onResponse = (response, finished) => {
|
|
34
|
+
if (finished) {
|
|
35
|
+
stac.clear();
|
|
36
|
+
} else if (this._isUpdated(prevResponse, response)) {
|
|
37
|
+
stac.touch();
|
|
38
|
+
}
|
|
39
|
+
prevResponse = response;
|
|
40
|
+
};
|
|
41
|
+
return polling(fetch, { interval, signal, onResponse, ...options })[Symbol.asyncIterator]();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
_isFinished(response) {
|
|
45
|
+
return !!(response && response.finished);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
_isUpdated(previousResponse, newResponse) {
|
|
49
|
+
return !previousResponse || previousResponse.answer_stage !== newResponse.answer_stage || previousResponse.answer.length !== newResponse.answer.length;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
_revisionOf(response) {
|
|
53
|
+
return response && response.revision;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export class IdBasedIterableApiStub extends IterableApiStub {
|
|
59
|
+
|
|
60
|
+
constructor(api, method, id, options) {
|
|
61
|
+
super(options);
|
|
62
|
+
this._api = api;
|
|
63
|
+
this._method = method;
|
|
64
|
+
this._id = id;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async _get(options) {
|
|
68
|
+
return this._api[this._method](this._id, options);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
}
|
package/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '1.10.
|
|
1
|
+
export default '1.10.4-beta.0';
|