UNPKG

ze-react-component-library

Version:
876 lines (791 loc) 20.4 kB
import "antd/es/message/style"; import _message from "antd/es/message"; var __assign = this && this.__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 = this && this.__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 = this && this.__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 = this && this.__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; }; import { execLogicform, ask, commonRequest, config } from "zeroetp-api-sdk"; export 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(); _message.error(error_1.message); return [2 /*return*/ , Promise.reject(error_1)]; case 3: return [2 /*return*/ ]; } }); }); } export 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(ask(question, logicform_only, context))]; case 1: ret = _a.sent(); return [2 /*return*/ , ret]; } }); }); } export 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(execLogicform(logicform))]; case 1: ret = _a.sent(); if (!silent && ret.error && !ret.logicform) { _message.error(ret.error); return [2 /*return*/ , null]; } return [2 /*return*/ , ret]; } }); }); } export 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(commonRequest("/schema/guess?schemaType=" + schemaType + "&table=" + table))]; case 1: ret = _a.sent(); return [2 /*return*/ , ret]; } }); }); } export 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(commonRequest("/logicform/recommend", { method: "POST", data: { logicform: logicform } }))]; case 1: ret = _a.sent(); return [2 /*return*/ , ret]; } }); }); } export 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(commonRequest("/suggest?s=" + encodeURIComponent(s)))]; case 1: ret = _a.sent(); return [2 /*return*/ , ret]; } }); }); } export 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(commonRequest("/nlq/voice", { method: "POST", data: formData }))]; case 1: ret = _a.sent(); return [2 /*return*/ , ret]; } }); }); } export 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(commonRequest("/nlq/similarWords?w=" + encodeURIComponent(w)))]; case 1: ret = _a.sent(); return [2 /*return*/ , ret]; } }); }); } export 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(commonRequest("/nlq/complete?question=" + encodeURIComponent(question)))]; case 1: ret = _a.sent(); return [2 /*return*/ , ret]; } }); }); } export 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(commonRequest("/nlq/guess?question=" + encodeURIComponent(question)))]; case 1: ret = _a.sent(); return [2 /*return*/ , ret]; } }); }); } export 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(commonRequest("/settings/" + id))]; case 1: ret = _a.sent(); return [2 /*return*/ , ret]; } }); }); } export 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(commonRequest("/config/" + id))]; case 1: ret = _a.sent(); return [2 /*return*/ , ret]; } }); }); } export 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", config.API_URL); console.log("FINAL URL", "" + (localStorage.getItem("DEV_PROXY_API_URL") || config.API_URL) + (window.publicPath || "/") + "api/v1/llm/chat"); return [4 /*yield*/ , fetch("" + (localStorage.getItem("DEV_PROXY_API_URL") || 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*/ ]; } }); }); } export 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") || 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*/ ]; } }); }); } // 获取微信小程序端的问答 export 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(commonRequest("/nlq/microphoneQuestion"))]; case 1: ret = _a.sent(); return [2 /*return*/ , ret]; } }); }); } export 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(commonRequest("/hot"))]; case 1: ret = _a.sent(); return [2 /*return*/ , ret]; } }); }); } export 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(commonRequest("/history"))]; case 1: ret = _a.sent(); return [2 /*return*/ , ret]; } }); }); } export 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(commonRequest("/roles"))]; case 1: ret = _a.sent(); return [2 /*return*/ , ret]; } }); }); } export 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(commonRequest("/roles", { method: "POST", data: payload }))]; case 1: ret = _a.sent(); return [2 /*return*/ , ret]; } }); }); } export 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(commonRequest("/roles/" + id, { method: "PUT", data: payload }))]; case 1: ret = _a.sent(); return [2 /*return*/ , ret]; } }); }); } export 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(commonRequest("/roles/" + id, { method: "DELETE" }))]; case 1: ret = _a.sent(); return [2 /*return*/ , ret]; } }); }); } export 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(commonRequest("/accounts", { method: "GET", params: params }))]; case 1: ret = _a.sent(); return [2 /*return*/ , ret]; } }); }); } export 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(commonRequest("/accounts", { method: "POST", data: payload }))]; case 1: ret = _a.sent(); return [2 /*return*/ , ret]; } }); }); } export 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(commonRequest("/accounts/" + id, { method: "PUT", data: payload }))]; case 1: ret = _a.sent(); return [2 /*return*/ , ret]; } }); }); } export 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(commonRequest("/accounts/" + id, { method: "DELETE" }))]; case 1: ret = _a.sent(); return [2 /*return*/ , ret]; } }); }); } export 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(commonRequest("/measurements/guide", { params: params }))]; case 1: ret = _a.sent(); return [2 /*return*/ , ret]; } }); }); } export 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(commonRequest("/analyzer/analyze", { method: "POST", data: { logicform: logicform, operator: operator } }))]; case 1: ret = _a.sent(); return [2 /*return*/ , ret]; } }); }); } export function postFeedbacks(body, options) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/ , request(commonRequest("/feedbacks", __assign({ method: "POST", headers: { "Content-Type": "application/json" }, data: body }, options || {})))]; }); }); } export 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(commonRequest("/feedbacks/" + param0, __assign({ method: "DELETE", params: __assign({}, queryParams) }, options || {})))]; }); }); }