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