UNPKG

@glodon-aiot/apis

Version:

aiot apis

424 lines (423 loc) 13.1 kB
var v = Object.defineProperty, S = Object.defineProperties; var w = Object.getOwnPropertyDescriptors; var g = Object.getOwnPropertySymbols; var A = Object.prototype.hasOwnProperty, R = Object.prototype.propertyIsEnumerable; var y = (l, e, t) => e in l ? v(l, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[e] = t, f = (l, e) => { for (var t in e || (e = {})) A.call(e, t) && y(l, t, e[t]); if (g) for (var t of g(e)) R.call(e, t) && y(l, t, e[t]); return l; }, $ = (l, e) => S(l, w(e)); var s = (l, e, t) => new Promise((a, i) => { var n = (c) => { try { r(t.next(c)); } catch (p) { i(p); } }, h = (c) => { try { r(t.throw(c)); } catch (p) { i(p); } }, r = (c) => c.done ? a(c.value) : Promise.resolve(c.value).then(n, h); r((t = t.apply(l, e)).next()); }); import T from "axios"; import { BaseApi as K } from "../base/index.mjs"; import { initMinio as k, putObjectBuffer as P } from "@glodon-aiot/minio"; import { IHistoryRole as F, AecKnowledgeFileStatus as I } from "../aecpilot/model.mjs"; import { v4 as M } from "uuid"; import b from "dayjs"; import { Buffer as B } from "buffer"; import { PROMPT_SEARCH_MAX_LENGTH as E } from "../aecpilot/cosntant.mjs"; import { fetchEventSource as H } from "../utils/fetchEventSource/fetch.mjs"; window.Buffer = B; class x extends K { constructor(e, t, a) { super(e != null ? e : T.create(), a), this.axiosInstance = e, this.getToken = t; } getApplicationIdSessions(e) { return s(this, null, function* () { return this.get(`/data/v1/application/${e}/session`); }); } getApplicationId(e, t) { return s(this, null, function* () { return this.get(`/data/v1/applications/${e}`, t); }); } postApplicationIdSession(e) { return s(this, null, function* () { return this.post(`/data/v1/application/${e.applicationId}/sessions`, e); }); } getApplicationIdSessionsId(e, t) { return s(this, null, function* () { return this.get(`/data/v1/application/${e}/sessions/${t}`); }); } patchApplicationIdSessionsId(e, t, a) { return s(this, null, function* () { return this.patch(`/data/v1/application/${e}/sessions/${t}`, a); }); } patchApplicationIdSessionsIdContext(e, t) { return s(this, null, function* () { return this.patch(`/data/v1/application/${e}/sessions/${t}/context`, {}); }); } delApplicationIdSessionsId(e, t) { return s(this, null, function* () { return this.delete(`/data/v1/application/${e}/sessions/${t}`); }); } postComments(e, t, a) { return s(this, null, function* () { return this.post(`/data/v1/application/${e}/sessions/${t}/comments`, a); }); } getChatHistorySessionId(e, t) { return s(this, null, function* () { return this.get(`/data/v1/application/${e}/chatHistory/${t}`); }); } postChatV2EventSource(e, t, a, i, n, h) { return s(this, null, function* () { const r = { code: 0, messageId: M(), content: "", role: F.Robot, sessionId: "", reference: [], searchReference: [], messageTime: "", llmModel: "", comment: { isAgree: 0 }, isReplying: !1 }, c = yield this.getToken(), p = $(f({}, a), { stream: !0 }); H(`https://aiot-dev.glodon.com/api/cvforcepd/chat/v2/chat?applicationId=${e}&sessionId=${t}`, { method: "POST", headers: { Authorization: `Bearer ${c}`, "Content-Type": "application/json" }, body: JSON.stringify(p), openWhenHidden: !0, signal: i, onopen(d) { return d.ok && n != null && n.onopen && n.onopen(), Promise.resolve(); }, onmessage(d) { if (!d.data.includes('{"code": ')) { let o = {}; try { o = JSON.parse(d.data); } catch (V) { } (o == null ? void 0 : o.mtype) === "search" ? r.searchReference.push(o) : r.content = r.content + d.data; const u = { content: r.content, role: 1, reference: r.reference, searchReference: r.searchReference, messageId: r.messageId, sessionId: t, messageTime: b(/* @__PURE__ */ new Date()).format("YYYY-MM-DD HH:mm:ss"), comment: { isAgree: 0 }, isReplying: !0 }; return (n == null ? void 0 : n.onmessage) && n.onmessage(u); } const m = JSON.parse(d.data); if (r.reference = m.data.reference, r.searchReference = m.data.searchReference, r.messageTime = m.data.messageTime, r.messageId = m.data.messageId, r.llmModel = m.data.llmModel, r.content = m.data.content, r.code = m.code, m.code === 200) { const o = { code: r.code, content: r.content, role: 1, reference: r.reference, searchReference: r.searchReference, messageId: r.messageId, sessionId: t, messageTime: r.messageTime, isReplying: !0 }; n != null && n.onmessage && n.onmessage(o); } else return h && h({ code: m.code, message: m.message }); }, onerror() { n != null && n.onerror && n.onerror(); }, onclose() { const d = { code: r.code, content: r.content, role: 1, reference: r.reference, searchReference: r.searchReference, messageId: r.messageId, sessionId: t, messageTime: r.messageTime, comment: { isAgree: 0 }, isReplying: !1 }; n != null && n.onclose && n.onclose(d); } }); }); } getKnowledgeIdFileIdData(e, t, a) { return s(this, null, function* () { return this.get(`/data/v1/knowledge/${e}/file/${t}/data/${a}`); }); } getKnowledgeIdFileId(e, t) { return s(this, null, function* () { return this.get(`/data/v1/knowledge/${e}/file/${t}`); }); } getKnowledgeId(e) { return s(this, null, function* () { return this.get(`/data/v1/knowledge/${e}`); }); } getSessionKnowledgeFile(e, t) { return s(this, null, function* () { return this.get(`/data/v1/chatSession/${e}/file/${t}`); }); } sleep(e) { return s(this, null, function* () { return new Promise((t) => { setTimeout(() => { t(""); }, e); }); }); } getBaseModelInfo(e) { return s(this, null, function* () { return this.get("/data/v1/baseModelInfo", { serviceId: e }); }); } uploadFiles(e, t) { return s(this, null, function* () { const a = { files: t.map((i) => i.name), isv: "minio", knowledgeId: e }; return this.postTicket(a).then((i) => Promise.all(t.map((n) => this.uploadMinioFile(i.minio, n)))).catch((i) => { throw Error(i); }); }); } postFile(e, t, a) { return s(this, null, function* () { const i = { files: [t.name], isv: "minio", knowledgeId: e, type: a }; return this.postTicket(i).then((n) => this.uploadMinioFile(n.minio, t)).catch((n) => { throw Error(n); }); }); } postTicket(e) { return s(this, null, function* () { return this.post("/data/v1/ticket", e); }); } uploadFile(e, t) { return s(this, null, function* () { const a = { files: [t.name], isv: "minio", knowledgeId: e }; return this.postTicket(a).then((i) => this.uploadMinioFile(i.minio, t)).catch((i) => { throw Error(i); }); }); } // async postUploadTicket(params: IUploadParam) { // return this.post<IUploadTicket>(`/data/v1/upload/ticket`, params); // } uploadMinioFile(e, t) { return s(this, null, function* () { return new Promise((a, i) => { const n = new FileReader(); n.readAsArrayBuffer(t), n.onload = (h) => { k({ endPoint: e.endpoints[0], useSSL: e.useSSL, accessKey: e.accessKey, secretKey: e.secretKey }); const r = Buffer.from(h.target.result), c = { "Content-Type": "application/octet-stream" }; P(e.bucket, e.fileKeys[0], r, c, (p) => { if (p) throw console.error(p), Error(p); a(e.fileKeys[0]); }); }; }); }); } getRecommendQues(e) { return s(this, null, function* () { return this.get(`/data/v1/application/${e}/recommendQues`); }); } //常用提示词 postPrompts(e, t) { return s(this, null, function* () { return this.post(`/data/v1/application/${e}/prompts`, t); }); } listPrompt(e, t) { return s(this, null, function* () { return t != null && t.title && t.title.length > E ? [] : this.get(`/data/v1/application/${e}/prompts`, t); }); } getPrompt(e, t) { return s(this, null, function* () { return this.get(`/data/v1/application/${e}/prompts/${t}`); }); } updatePrompt(e, t, a) { return s(this, null, function* () { return this.put(`/data/v1/application/${e}/prompts/${t}`, a); }); } deletePrompt(e, t) { return s(this, null, function* () { return this.delete(`/data/v1/application/${e}/prompts/${t}`); }); } postGeneques(e, t) { return s(this, null, function* () { return this.post("/data/v1/geneques", e, {}, t); }); } getApplicationIdSessionKnowledgeFiles(e, t, a) { return s(this, null, function* () { return this.get(`/data/v1/application/${e}/session/${t}/file`, a); }); } checkFileReady(e, t, a, i = () => !0, n = 1e4, h) { return s(this, null, function* () { return new Promise((r, c) => { const p = () => { if (!i()) { clearInterval(d); return; } a ? this.getApplicationIdSessionKnowledgeFileId(e, t, a, {}, !0).then((o) => { if (h == null || h(o), o.status === I.Success && (clearInterval(d), r(o)), o.status === I.Failed) { clearInterval(d); const u = "该文件无法读取,请上传可编辑pdf,doc,docx文档"; c(Error(u, { cause: { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore code: -101, message: u, data: o } })); } }).catch((o) => { clearInterval(d), c(o); }) : r(null); }, d = setInterval(p, n); p(); }); }); } getApplicationIdSessionKnowledgeFileId(e, t, a, i, n) { return s(this, null, function* () { return this.get(`/data/v1/application/${e}/session/${t}/file/${a}`, i, n); }); } delApplicationIdSessionKnowledgeFileId(e, t, a) { return s(this, null, function* () { return this.delete(`/data/v1/application/${e}/session/${t}/file/${a}`); }); } postApplicationIdSessionKnowledgeSessionFile(e, t, a, i, n) { return s(this, null, function* () { return this.post(`/data/v1/application/${e}/session/${t}/sessionfile`, a, i, n); }); } delApplicationIdSessionKnowledgeFile(e, t, a) { return s(this, null, function* () { return this.delete(`/data/v1/application/${e}/session/${t}/file`, a); }); } deleteSessionKnowledgeFiles(e, t) { return s(this, null, function* () { return this.delete(`/data/v1/chatSession/${e}/file`, t); }); } patchApplicationIdKnowledgeIdFileId(e, t, a, i) { return s(this, null, function* () { return this.patch(`/data/v1/application/${e}/session/${t}/file/${a}`, i); }); } getApplicationIdSessionIdPromptVariables(e, t) { return s(this, null, function* () { return this.get(`/data/v1/application/${e}/session/${t}/promptVariables`); }); } getApplicationIdPromptVariables(e, t) { return s(this, null, function* () { return this.get(`/data/v1/application/${e}/promptVariables`, t); }); } patchApplicationIdSessionpromptVariablesId(e, t, a, i) { return s(this, null, function* () { return this.patch(`/data/v1/application/${e}/session/${t}/promptVariables/${a}`, i); }); } updateSession(e, t, a) { return s(this, null, function* () { return this.patch(`/data/v1/application/${e}/sessions/${t}`, a); }); } getSession(e, t) { return s(this, null, function* () { return this.get(`/data/v1/application/${e}/sessions/${t}`); }); } getSilenceDuration() { return s(this, null, function* () { return this.get("/data/v1/silenceDuration"); }); } } export { x as BotClientApi };