UNPKG

@gaiot/apis

Version:

aiot apis

419 lines (418 loc) 13.1 kB
var S = Object.defineProperty, w = Object.defineProperties; var A = Object.getOwnPropertyDescriptors; var u = Object.getOwnPropertySymbols; var R = Object.prototype.hasOwnProperty, T = Object.prototype.propertyIsEnumerable; var f = (l, e, t) => e in l ? S(l, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[e] = t, y = (l, e) => { for (var t in e || (e = {})) R.call(e, t) && f(l, t, e[t]); if (u) for (var t of u(e)) T.call(e, t) && f(l, t, e[t]); return l; }, $ = (l, e) => w(l, A(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 K from "axios"; import { BaseApi as k } from "../base/index.mjs"; import { m as I } from "../node_modules/@gaiot/minio/dist/minio-zj.mjs"; import { IHistoryRole as P, AecKnowledgeFileStatus as v } from "../aecpilot/model.mjs"; import { fetchEventSource as F } from "../utils/fetchEventSource/fetch.mjs"; import M from "dayjs"; import { Buffer as b } from "buffer"; import { PROMPT_SEARCH_MAX_LENGTH as B } from "../aecpilot/cosntant.mjs"; import E from "../node_modules/uuid/dist/esm-browser/v4.mjs"; window.Buffer = b; class _ extends k { constructor(e, t, a) { super(e != null ? e : K.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) { return s(this, null, function* () { return this.get(`/data/v1/applications/${e}`); }); } 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: E(), content: "", role: P.Robot, sessionId: "", reference: [], searchReference: [], messageTime: "", llmModel: "", comment: { isAgree: 0 }, isReplying: !1 }, c = yield this.getToken(), p = $(y({}, a), { stream: !0 }); F(`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 console.log("onopen"), 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 (H) { } (o == null ? void 0 : o.mtype) === "search" ? r.searchReference.push(o) : r.content = r.content + d.data; const g = { content: r.content, role: 1, reference: r.reference, searchReference: r.searchReference, messageId: r.messageId, sessionId: t, messageTime: M(/* @__PURE__ */ new Date()).format("YYYY-MM-DD HH:mm:ss"), comment: { isAgree: 0 }, isReplying: !0 }; return (n == null ? void 0 : n.onmessage) && n.onmessage(g); } 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) => { I.initMinio({ 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" }; I.putObjectBuffer(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 > B ? [] : 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 === v.Success && (clearInterval(d), r(o)), o.status === v.Failed) { clearInterval(d); const g = "该文件无法读取,请上传可编辑pdf,doc,docx文档"; c(Error(g, { cause: { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore code: -101, message: g, 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}`); }); } } export { _ as AgentClientUIApi };