ze-react-component-library
Version:
ZeroETP React Component Library
943 lines (825 loc) • 22.2 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.request = request;
exports.requestAsk = requestAsk;
exports.requestLogicform = requestLogicform;
exports.requestGuessSchema = requestGuessSchema;
exports.requestRecommend = requestRecommend;
exports.requestSuggest = requestSuggest;
exports.requestSuggestByVoice = requestSuggestByVoice;
exports.requestSimilarWords = requestSimilarWords;
exports.requestKeywords = requestKeywords;
exports.requestGuess = requestGuess;
exports.requestSetting = requestSetting;
exports.requestConfig = requestConfig;
exports.requestLLMChat = requestLLMChat;
exports.requestLLMErrorSuggestion = requestLLMErrorSuggestion;
exports.requestPollingMicrophoneText = requestPollingMicrophoneText;
exports.requestHot = requestHot;
exports.requestHistory = requestHistory;
exports.getRoles = getRoles;
exports.createRole = createRole;
exports.updateRole = updateRole;
exports.deleteRole = deleteRole;
exports.getAccounts = getAccounts;
exports.createAccount = createAccount;
exports.updateAccount = updateAccount;
exports.deleteAccount = deleteAccount;
exports.requestMeasurementsGuide = requestMeasurementsGuide;
exports.analyze = analyze;
exports.postFeedbacks = postFeedbacks;
exports.deleteFeedbacksById = deleteFeedbacksById;
require("antd/lib/message/style");
var _message2 = _interopRequireDefault(require("antd/lib/message"));
var _zeroetpApiSdk = require("zeroetp-api-sdk");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var __assign = void 0 && (void 0).__assign || function () {
__assign = Object.assign || function (t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) {
if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
function adopt(value) {
return value instanceof P ? value : new P(function (resolve) {
resolve(value);
});
}
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
}
function rejected(value) {
try {
step(generator["throw"](value));
} catch (e) {
reject(e);
}
}
function step(result) {
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
}
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = void 0 && (void 0).__generator || function (thisArg, body) {
var _ = {
label: 0,
sent: function sent() {
if (t[0] & 1) throw t[1];
return t[1];
},
trys: [],
ops: []
},
f,
y,
t,
g;
return g = {
next: verb(0),
"throw": verb(1),
"return": verb(2)
}, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
return this;
}), g;
function verb(n) {
return function (v) {
return step([n, v]);
};
}
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) {
try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0:
case 1:
t = op;
break;
case 4:
_.label++;
return {
value: op[1],
done: false
};
case 5:
_.label++;
y = op[1];
op = [0];
continue;
case 7:
op = _.ops.pop();
_.trys.pop();
continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
_ = 0;
continue;
}
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
_.label = op[1];
break;
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1];
t = op;
break;
}
if (t && _.label < t[2]) {
_.label = t[2];
_.ops.push(op);
break;
}
if (t[2]) _.ops.pop();
_.trys.pop();
continue;
}
op = body.call(thisArg, _);
} catch (e) {
op = [6, e];
y = 0;
} finally {
f = t = 0;
}
}
if (op[0] & 5) throw op[1];
return {
value: op[0] ? op[1] : void 0,
done: true
};
}
};
var __rest = void 0 && (void 0).__rest || function (s, e) {
var t = {};
for (var p in s) {
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
}
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
}
return t;
};
function request(func) {
return __awaiter(this, void 0, void 0, function () {
var error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2,, 3]);
return [4
/*yield*/
, func];
case 1:
return [2
/*return*/
, _a.sent()];
case 2:
error_1 = _a.sent();
_message2.default.error(error_1.message);
return [2
/*return*/
, Promise.reject(error_1)];
case 3:
return [2
/*return*/
];
}
});
});
}
function requestAsk(question, logicform_only, context) {
return __awaiter(this, void 0, void 0, function () {
var ret;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
return [4
/*yield*/
, request((0, _zeroetpApiSdk.ask)(question, logicform_only, context))];
case 1:
ret = _a.sent();
return [2
/*return*/
, ret];
}
});
});
}
function requestLogicform(logicform, silent) {
return __awaiter(this, void 0, void 0, function () {
var ret;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
return [4
/*yield*/
, request((0, _zeroetpApiSdk.execLogicform)(logicform))];
case 1:
ret = _a.sent();
if (!silent && ret.error && !ret.logicform) {
_message2.default.error(ret.error);
return [2
/*return*/
, null];
}
return [2
/*return*/
, ret];
}
});
});
}
function requestGuessSchema(schemaType, table) {
return __awaiter(this, void 0, void 0, function () {
var ret;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
return [4
/*yield*/
, request((0, _zeroetpApiSdk.commonRequest)("/schema/guess?schemaType=" + schemaType + "&table=" + table))];
case 1:
ret = _a.sent();
return [2
/*return*/
, ret];
}
});
});
}
function requestRecommend(logicform) {
return __awaiter(this, void 0, void 0, function () {
var ret;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
return [4
/*yield*/
, request((0, _zeroetpApiSdk.commonRequest)("/logicform/recommend", {
method: "POST",
data: {
logicform: logicform
}
}))];
case 1:
ret = _a.sent();
return [2
/*return*/
, ret];
}
});
});
}
function requestSuggest(s) {
return __awaiter(this, void 0, void 0, function () {
var ret;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
return [4
/*yield*/
, request((0, _zeroetpApiSdk.commonRequest)("/suggest?s=" + encodeURIComponent(s)))];
case 1:
ret = _a.sent();
return [2
/*return*/
, ret];
}
});
});
}
function requestSuggestByVoice(formData) {
return __awaiter(this, void 0, void 0, function () {
var ret;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
return [4
/*yield*/
, request((0, _zeroetpApiSdk.commonRequest)("/nlq/voice", {
method: "POST",
data: formData
}))];
case 1:
ret = _a.sent();
return [2
/*return*/
, ret];
}
});
});
}
function requestSimilarWords(w) {
return __awaiter(this, void 0, void 0, function () {
var ret;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
return [4
/*yield*/
, request((0, _zeroetpApiSdk.commonRequest)("/nlq/similarWords?w=" + encodeURIComponent(w)))];
case 1:
ret = _a.sent();
return [2
/*return*/
, ret];
}
});
});
}
function requestKeywords(question) {
return __awaiter(this, void 0, void 0, function () {
var ret;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
return [4
/*yield*/
, request((0, _zeroetpApiSdk.commonRequest)("/nlq/complete?question=" + encodeURIComponent(question)))];
case 1:
ret = _a.sent();
return [2
/*return*/
, ret];
}
});
});
}
function requestGuess(question) {
return __awaiter(this, void 0, void 0, function () {
var ret;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
return [4
/*yield*/
, request((0, _zeroetpApiSdk.commonRequest)("/nlq/guess?question=" + encodeURIComponent(question)))];
case 1:
ret = _a.sent();
return [2
/*return*/
, ret];
}
});
});
}
function requestSetting(id) {
return __awaiter(this, void 0, void 0, function () {
var ret;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
return [4
/*yield*/
, request((0, _zeroetpApiSdk.commonRequest)("/settings/" + id))];
case 1:
ret = _a.sent();
return [2
/*return*/
, ret];
}
});
});
}
function requestConfig(id) {
return __awaiter(this, void 0, void 0, function () {
var ret;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
return [4
/*yield*/
, request((0, _zeroetpApiSdk.commonRequest)("/config/" + id))];
case 1:
ret = _a.sent();
return [2
/*return*/
, ret];
}
});
});
}
function requestLLMChat(body, callback, onFinish) {
return __awaiter(this, void 0, void 0, function () {
var response, reader, _a, value, done;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
console.log("DEV_API", localStorage.getItem("DEV_PROXY_API_URL"));
console.log("API_URL", _zeroetpApiSdk.config.API_URL);
console.log("FINAL URL", "" + (localStorage.getItem("DEV_PROXY_API_URL") || _zeroetpApiSdk.config.API_URL) + (window.publicPath || "/") + "api/v1/llm/chat");
return [4
/*yield*/
, fetch("" + (localStorage.getItem("DEV_PROXY_API_URL") || _zeroetpApiSdk.config.API_URL) + (window.publicPath || "/") + "api/v1/llm/chat", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + localStorage.getItem("chatbi-token")
},
body: JSON.stringify(body)
})];
case 1:
response = _b.sent();
reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
if (response.status !== 200) {
callback("啊哦,大语言模型连接错误,请检查!");
return [2
/*return*/
];
}
_b.label = 2;
case 2:
if (!true) return [3
/*break*/
, 4];
return [4
/*yield*/
, reader.read()];
case 3:
_a = _b.sent(), value = _a.value, done = _a.done;
if (done) {
onFinish === null || onFinish === void 0 ? void 0 : onFinish(true);
return [3
/*break*/
, 4];
}
try {
// console.log(value);
callback(value);
} catch (error) {
console.log(error);
return [3
/*break*/
, 4];
}
return [3
/*break*/
, 2];
case 4:
return [2
/*return*/
];
}
});
});
}
function requestLLMErrorSuggestion(ask, callback) {
return __awaiter(this, void 0, void 0, function () {
var response, reader, _a, value, done;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
return [4
/*yield*/
, fetch("" + (localStorage.getItem("DEV_PROXY_API_URL") || _zeroetpApiSdk.config.API_URL) + (window.publicPath || "/") + "api/v1/llm/errorSuggestion", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + localStorage.getItem("chatbi-token")
},
body: JSON.stringify({
ask: ask
})
})];
case 1:
response = _b.sent();
reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
_b.label = 2;
case 2:
if (!true) return [3
/*break*/
, 4];
return [4
/*yield*/
, reader.read()];
case 3:
_a = _b.sent(), value = _a.value, done = _a.done;
if (done) return [3
/*break*/
, 4];
try {
// console.log(value);
callback(value);
} catch (error) {
console.log(error);
return [3
/*break*/
, 4];
}
return [3
/*break*/
, 2];
case 4:
return [2
/*return*/
];
}
});
});
} // 获取微信小程序端的问答
function requestPollingMicrophoneText() {
return __awaiter(this, void 0, void 0, function () {
var ret;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
return [4
/*yield*/
, request((0, _zeroetpApiSdk.commonRequest)("/nlq/microphoneQuestion"))];
case 1:
ret = _a.sent();
return [2
/*return*/
, ret];
}
});
});
}
function requestHot() {
return __awaiter(this, void 0, void 0, function () {
var ret;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
return [4
/*yield*/
, request((0, _zeroetpApiSdk.commonRequest)("/hot"))];
case 1:
ret = _a.sent();
return [2
/*return*/
, ret];
}
});
});
}
function requestHistory() {
return __awaiter(this, void 0, void 0, function () {
var ret;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
return [4
/*yield*/
, request((0, _zeroetpApiSdk.commonRequest)("/history"))];
case 1:
ret = _a.sent();
return [2
/*return*/
, ret];
}
});
});
}
function getRoles() {
return __awaiter(this, void 0, void 0, function () {
var ret;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
return [4
/*yield*/
, request((0, _zeroetpApiSdk.commonRequest)("/roles"))];
case 1:
ret = _a.sent();
return [2
/*return*/
, ret];
}
});
});
}
function createRole(payload) {
return __awaiter(this, void 0, void 0, function () {
var ret;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
return [4
/*yield*/
, request((0, _zeroetpApiSdk.commonRequest)("/roles", {
method: "POST",
data: payload
}))];
case 1:
ret = _a.sent();
return [2
/*return*/
, ret];
}
});
});
}
function updateRole(id, payload) {
return __awaiter(this, void 0, void 0, function () {
var ret;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
return [4
/*yield*/
, request((0, _zeroetpApiSdk.commonRequest)("/roles/" + id, {
method: "PUT",
data: payload
}))];
case 1:
ret = _a.sent();
return [2
/*return*/
, ret];
}
});
});
}
function deleteRole(id) {
return __awaiter(this, void 0, void 0, function () {
var ret;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
return [4
/*yield*/
, request((0, _zeroetpApiSdk.commonRequest)("/roles/" + id, {
method: "DELETE"
}))];
case 1:
ret = _a.sent();
return [2
/*return*/
, ret];
}
});
});
}
function getAccounts(params) {
return __awaiter(this, void 0, void 0, function () {
var ret;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
return [4
/*yield*/
, request((0, _zeroetpApiSdk.commonRequest)("/accounts", {
method: "GET",
params: params
}))];
case 1:
ret = _a.sent();
return [2
/*return*/
, ret];
}
});
});
}
function createAccount(payload) {
return __awaiter(this, void 0, void 0, function () {
var ret;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
return [4
/*yield*/
, request((0, _zeroetpApiSdk.commonRequest)("/accounts", {
method: "POST",
data: payload
}))];
case 1:
ret = _a.sent();
return [2
/*return*/
, ret];
}
});
});
}
function updateAccount(id, payload) {
return __awaiter(this, void 0, void 0, function () {
var ret;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
return [4
/*yield*/
, request((0, _zeroetpApiSdk.commonRequest)("/accounts/" + id, {
method: "PUT",
data: payload
}))];
case 1:
ret = _a.sent();
return [2
/*return*/
, ret];
}
});
});
}
function deleteAccount(id) {
return __awaiter(this, void 0, void 0, function () {
var ret;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
return [4
/*yield*/
, request((0, _zeroetpApiSdk.commonRequest)("/accounts/" + id, {
method: "DELETE"
}))];
case 1:
ret = _a.sent();
return [2
/*return*/
, ret];
}
});
});
}
function requestMeasurementsGuide(params) {
return __awaiter(this, void 0, void 0, function () {
var ret;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
return [4
/*yield*/
, request((0, _zeroetpApiSdk.commonRequest)("/measurements/guide", {
params: params
}))];
case 1:
ret = _a.sent();
return [2
/*return*/
, ret];
}
});
});
}
function analyze(logicform, operator) {
return __awaiter(this, void 0, void 0, function () {
var ret;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
return [4
/*yield*/
, request((0, _zeroetpApiSdk.commonRequest)("/analyzer/analyze", {
method: "POST",
data: {
logicform: logicform,
operator: operator
}
}))];
case 1:
ret = _a.sent();
return [2
/*return*/
, ret];
}
});
});
}
function postFeedbacks(body, options) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2
/*return*/
, request((0, _zeroetpApiSdk.commonRequest)("/feedbacks", __assign({
method: "POST",
headers: {
"Content-Type": "application/json"
},
data: body
}, options || {})))];
});
});
}
function deleteFeedbacksById( // 叠加生成的Param类型 (非body参数swagger默认没有生成对象)
params, options) {
return __awaiter(this, void 0, void 0, function () {
var param0, queryParams;
return __generator(this, function (_a) {
param0 = params.id, queryParams = __rest(params, ["id"]);
return [2
/*return*/
, request((0, _zeroetpApiSdk.commonRequest)("/feedbacks/" + param0, __assign({
method: "DELETE",
params: __assign({}, queryParams)
}, options || {})))];
});
});
}