@glodon-aiot/agent-cli-sdk 3.1.0-beta.16 → 3.2.2-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-cli-sdk.js +33145 -0
- package/dist/agent-cli-sdk.umd.cjs +140 -0
- package/dist/src/AgentSession.d.ts +2 -2
- package/dist/src/BotClient.d.ts +2 -2
- package/dist/src/Config.d.ts +2 -0
- package/dist/src/DialogSession.d.ts +2 -2
- package/dist/src/Session.d.ts +11 -9
- package/dist/src/__ tests __/AgentClient.spec.d.ts +1 -0
- package/dist/src/__ tests __/AgentSession.spec.d.ts +1 -0
- package/dist/src/__ tests __/DialogClient.spec.d.ts +1 -0
- package/dist/src/api/fetchEventSource/fetch.d.ts +1 -1
- package/dist/src/api/fetchEventSource/index.d.ts +1 -1
- package/package.json +20 -16
- package/dist/es/AgentPlugin.mjs +0 -20
- package/dist/es/AgentSession.mjs +0 -246
- package/dist/es/BotClient.mjs +0 -236
- package/dist/es/Config.mjs +0 -34
- package/dist/es/DialogSession.mjs +0 -274
- package/dist/es/EventBus.mjs +0 -64
- package/dist/es/Logger.mjs +0 -31
- package/dist/es/PayloadTypes.mjs +0 -4
- package/dist/es/Session.mjs +0 -690
- package/dist/es/api/fetchEventSource/fetch.mjs +0 -112
- package/dist/es/api/fetchEventSource/parse.mjs +0 -97
- package/dist/es/api/index.mjs +0 -41
- package/dist/es/index.mjs +0 -11
- package/dist/es/utils.mjs +0 -11
- package/dist/lib/index.js +0 -4
package/dist/es/BotClient.mjs
DELETED
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
var v = Object.defineProperty;
|
|
2
|
-
var y = (p, i, t) => i in p ? v(p, i, { enumerable: !0, configurable: !0, writable: !0, value: t }) : p[i] = t;
|
|
3
|
-
var c = (p, i, t) => (y(p, typeof i != "symbol" ? i + "" : i, t), t);
|
|
4
|
-
var a = (p, i, t) => new Promise((e, s) => {
|
|
5
|
-
var l = (n) => {
|
|
6
|
-
try {
|
|
7
|
-
o(t.next(n));
|
|
8
|
-
} catch (r) {
|
|
9
|
-
s(r);
|
|
10
|
-
}
|
|
11
|
-
}, h = (n) => {
|
|
12
|
-
try {
|
|
13
|
-
o(t.throw(n));
|
|
14
|
-
} catch (r) {
|
|
15
|
-
s(r);
|
|
16
|
-
}
|
|
17
|
-
}, o = (n) => n.done ? e(n.value) : Promise.resolve(n.value).then(l, h);
|
|
18
|
-
o((t = t.apply(p, i)).next());
|
|
19
|
-
});
|
|
20
|
-
import { parseJWT as f } from "./utils.mjs";
|
|
21
|
-
import g from "./Logger.mjs";
|
|
22
|
-
import { getCVForceService as S } from "./api/index.mjs";
|
|
23
|
-
import { configure as w, configuration as _ } from "./Config.mjs";
|
|
24
|
-
import { ApplicationTypes as u } from "@glodon-aiot/apis";
|
|
25
|
-
import m from "./AgentSession.mjs";
|
|
26
|
-
import k from "./DialogSession.mjs";
|
|
27
|
-
import A from "./EventBus.mjs";
|
|
28
|
-
const x = new g("[BotClient] ");
|
|
29
|
-
class q {
|
|
30
|
-
constructor(i, t, e = !0) {
|
|
31
|
-
c(this, "event", new A());
|
|
32
|
-
c(this, "cvforceApi");
|
|
33
|
-
//从token解析出来的用户信息
|
|
34
|
-
c(this, "_applicationId");
|
|
35
|
-
c(this, "_application", null);
|
|
36
|
-
//session列表,被加载过的session将会被缓存到这个列表中
|
|
37
|
-
c(this, "_sessions", []);
|
|
38
|
-
//活跃的session,只支持一个活跃的session
|
|
39
|
-
c(this, "_activeSession");
|
|
40
|
-
c(this, "_ready", !1);
|
|
41
|
-
//问题长度
|
|
42
|
-
c(this, "_questionContextMaxLength", 4e3);
|
|
43
|
-
c(this, "_promptVariables", []);
|
|
44
|
-
if (this._token = i, this.lazyload = e, w(t), this._applicationId = f(i).rid || _.applicationId, !this._applicationId)
|
|
45
|
-
throw "token is not vaild";
|
|
46
|
-
this.cvforceApi = this.getService(), this.loadApplication().then(() => {
|
|
47
|
-
this.event.emit("ready");
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
checkReady() {
|
|
51
|
-
if (!this.ready)
|
|
52
|
-
throw Error("client is not ready.");
|
|
53
|
-
}
|
|
54
|
-
get ready() {
|
|
55
|
-
return this._ready;
|
|
56
|
-
}
|
|
57
|
-
set ready(i) {
|
|
58
|
-
this._ready = i;
|
|
59
|
-
}
|
|
60
|
-
get questionContextMaxLength() {
|
|
61
|
-
return this.checkReady(), this._questionContextMaxLength;
|
|
62
|
-
}
|
|
63
|
-
get promptVariables() {
|
|
64
|
-
return this.checkReady(), this._promptVariables;
|
|
65
|
-
}
|
|
66
|
-
get knowledges() {
|
|
67
|
-
var i;
|
|
68
|
-
return this.checkReady(), (i = this._application) == null ? void 0 : i.arrange[0].knowledges;
|
|
69
|
-
}
|
|
70
|
-
get sessions() {
|
|
71
|
-
return this.checkReady(), this._sessions;
|
|
72
|
-
}
|
|
73
|
-
set sessions(i) {
|
|
74
|
-
this.checkReady(), this._sessions = i, this.event.emit("sessions:updated", i);
|
|
75
|
-
}
|
|
76
|
-
loadApplication() {
|
|
77
|
-
return a(this, null, function* () {
|
|
78
|
-
var t, e;
|
|
79
|
-
this._application = yield this.cvforceApi.getApplicationId(this._applicationId);
|
|
80
|
-
const i = (e = (t = this._application.arrange) == null ? void 0 : t[0]) == null ? void 0 : e.llmModel;
|
|
81
|
-
return i && (this._questionContextMaxLength = yield this.cvforceApi.getBaseModel(i).then((s) => s.maxModelLength)), this._promptVariables = yield this.cvforceApi.getPrompts(this._applicationId), this._ready = !0, this.event.emit("application:loaded"), this._application;
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
getService() {
|
|
85
|
-
return this.cvforceApi ? this.cvforceApi : S(_.apiRoot, this.token, (i, t) => x.error(t));
|
|
86
|
-
}
|
|
87
|
-
get token() {
|
|
88
|
-
return this._token;
|
|
89
|
-
}
|
|
90
|
-
set token(i) {
|
|
91
|
-
this.checkReady(), this._token = i, this.ready = !1;
|
|
92
|
-
const t = f(i).rid;
|
|
93
|
-
this._applicationId !== t && (this._applicationId = t, this._application = null, this.loadApplication().then(() => {
|
|
94
|
-
this.event.emit("ready");
|
|
95
|
-
}), this.clean());
|
|
96
|
-
}
|
|
97
|
-
get applicationId() {
|
|
98
|
-
return this._applicationId;
|
|
99
|
-
}
|
|
100
|
-
get application() {
|
|
101
|
-
return this.checkReady(), this._application;
|
|
102
|
-
}
|
|
103
|
-
get activeSession() {
|
|
104
|
-
var i;
|
|
105
|
-
return this.checkReady(), ((i = this._activeSession) == null ? void 0 : i.id) || "";
|
|
106
|
-
}
|
|
107
|
-
set activeSession(i) {
|
|
108
|
-
this.checkReady(), this.loadSession(i).then((t) => {
|
|
109
|
-
this._activeSession && this._activeSession.id !== i && this._activeSession.inactivate(), this._activeSession = t;
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
createSession(i, t, e, s, l) {
|
|
113
|
-
return a(this, null, function* () {
|
|
114
|
-
const h = this;
|
|
115
|
-
return new Promise((o, n) => {
|
|
116
|
-
const r = (d) => a(this, null, function* () {
|
|
117
|
-
if (d === u.Agent)
|
|
118
|
-
o(new m(i, t, e, s, l, h));
|
|
119
|
-
else if (d === u.Dialog)
|
|
120
|
-
o(new k(i, t, e, s, l, h));
|
|
121
|
-
else
|
|
122
|
-
throw Error(`不支持的应用类型:${d}`);
|
|
123
|
-
});
|
|
124
|
-
if (this.ready) {
|
|
125
|
-
if (!this._application)
|
|
126
|
-
throw Error("client is not ready");
|
|
127
|
-
r(this._application.type);
|
|
128
|
-
} else
|
|
129
|
-
this.event.on("ready", () => {
|
|
130
|
-
if (!this._application)
|
|
131
|
-
throw Error("_application is null");
|
|
132
|
-
r(this._application.type);
|
|
133
|
-
}, !0);
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
getSessions(i) {
|
|
138
|
-
return a(this, null, function* () {
|
|
139
|
-
return new Promise((t, e) => {
|
|
140
|
-
const s = () => this.cvforceApi.listSessions(this._applicationId, i).then((l) => {
|
|
141
|
-
const h = [];
|
|
142
|
-
return l.forEach((o) => a(this, null, function* () {
|
|
143
|
-
const n = this._sessions.find((r) => o.id === r.id);
|
|
144
|
-
if (n)
|
|
145
|
-
n.data = o, h.push(n);
|
|
146
|
-
else {
|
|
147
|
-
const r = yield this.createSession(this.token, o.id, o, this.lazyload, this._application || void 0);
|
|
148
|
-
h.push(r);
|
|
149
|
-
}
|
|
150
|
-
})), this.sessions = h, h;
|
|
151
|
-
});
|
|
152
|
-
if (this.ready) {
|
|
153
|
-
if (!this._application)
|
|
154
|
-
throw Error("_application is null");
|
|
155
|
-
t(s());
|
|
156
|
-
} else
|
|
157
|
-
this.event.on("ready", () => {
|
|
158
|
-
if (!this._application)
|
|
159
|
-
throw Error("_application is null");
|
|
160
|
-
t(s());
|
|
161
|
-
}, !0);
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
loadSession(i = "", t) {
|
|
166
|
-
return a(this, null, function* () {
|
|
167
|
-
this.checkReady();
|
|
168
|
-
let e = this.sessions.find((s) => s.id === i);
|
|
169
|
-
if (e || (e = yield this.createSession(this.token, i, t), this._sessions.push(e)), this._activeSession) {
|
|
170
|
-
if (this._activeSession === e)
|
|
171
|
-
return e;
|
|
172
|
-
this._activeSession.inactivate();
|
|
173
|
-
}
|
|
174
|
-
return e.id ? (yield e.activate(), this._activeSession = e) : e.addEventListener("data:loaded", () => {
|
|
175
|
-
this._activeSession !== e && (e == null || e.activate(), this._activeSession = e);
|
|
176
|
-
}, !0), e;
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
reload() {
|
|
180
|
-
return this.loadApplication().then(() => a(this, null, function* () {
|
|
181
|
-
return yield this.getSessions(), this.event.emit("ready"), this;
|
|
182
|
-
}));
|
|
183
|
-
}
|
|
184
|
-
reloadSession(i) {
|
|
185
|
-
return a(this, null, function* () {
|
|
186
|
-
yield this.reload();
|
|
187
|
-
let t = this._sessions.find((e) => e.id === i) || this._activeSession;
|
|
188
|
-
if (!t) {
|
|
189
|
-
console.warn("reloadSession session failed.");
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
return yield t.reload(), t;
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
setTop(i, t, e = "top_time desc, sort_status desc, updated_at desc") {
|
|
196
|
-
return a(this, null, function* () {
|
|
197
|
-
let s = i ? this._sessions.find((l) => l.id === i) : this._activeSession;
|
|
198
|
-
if (!s) {
|
|
199
|
-
console.warn("setTop session failed.");
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
return yield s.setTop(t), this.getSessions({
|
|
203
|
-
order: e
|
|
204
|
-
});
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
addEventListener(i, t, e = !1) {
|
|
208
|
-
if (typeof t != "function")
|
|
209
|
-
throw Error("event listener is not a function");
|
|
210
|
-
if (e) {
|
|
211
|
-
this.event.once(i, t);
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
this.event.on(i, t);
|
|
215
|
-
}
|
|
216
|
-
removeEventListener(i, t) {
|
|
217
|
-
this.event.off(i, t);
|
|
218
|
-
}
|
|
219
|
-
removeSession(i, t) {
|
|
220
|
-
return a(this, null, function* () {
|
|
221
|
-
this.checkReady();
|
|
222
|
-
let e = -1;
|
|
223
|
-
if (typeof i == "string" ? e = this._sessions.findIndex((s) => s.id === i) : e = this._sessions.findIndex((s) => s.id === i.id), e > -1) {
|
|
224
|
-
const s = this._sessions[e];
|
|
225
|
-
t && (yield s.delete()), this._sessions.splice(e, 1);
|
|
226
|
-
} else
|
|
227
|
-
console.warn("session delete failed, session is not exist.");
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
clean() {
|
|
231
|
-
this._sessions.forEach((i) => i.destroy()), this.sessions = [];
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
export {
|
|
235
|
-
q as default
|
|
236
|
-
};
|
package/dist/es/Config.mjs
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
var v = Object.defineProperty, s = Object.defineProperties;
|
|
2
|
-
var u = Object.getOwnPropertyDescriptors;
|
|
3
|
-
var n = Object.getOwnPropertySymbols;
|
|
4
|
-
var p = Object.prototype.hasOwnProperty, h = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var g = (o, t, e) => t in o ? v(o, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[t] = e, i = (o, t) => {
|
|
6
|
-
for (var e in t || (t = {}))
|
|
7
|
-
p.call(t, e) && g(o, e, t[e]);
|
|
8
|
-
if (n)
|
|
9
|
-
for (var e of n(t))
|
|
10
|
-
h.call(t, e) && g(o, e, t[e]);
|
|
11
|
-
return o;
|
|
12
|
-
}, l = (o, t) => s(o, u(t));
|
|
13
|
-
import d from "./Logger.mjs";
|
|
14
|
-
const R = new d("[Config] ");
|
|
15
|
-
var f = /* @__PURE__ */ ((o) => (o.dev = "https://aiot-dev.glodon.com/api/cvforcepd", o.test = "https://aiot-dev.glodon.com/api/cvforce", o.prod = "https://copilot.glodon.com/api/cvforce", o.local = "http://localhost:3000/api/cvforcepd", o))(f || {});
|
|
16
|
-
let c = {
|
|
17
|
-
debug: !1,
|
|
18
|
-
env: "prod",
|
|
19
|
-
//AIoT 环境, 与apiRoot配对使用
|
|
20
|
-
apiRoot: "https://copilot.glodon.com/api/cvforce",
|
|
21
|
-
//https://${hostname}/${PRODUCD_CODE}
|
|
22
|
-
applicationId: "",
|
|
23
|
-
plugins: {}
|
|
24
|
-
};
|
|
25
|
-
function x(o) {
|
|
26
|
-
d.debug = (o == null ? void 0 : o.debug) || !1, c = l(i(i({}, c), o), {
|
|
27
|
-
apiRoot: (o == null ? void 0 : o.apiRoot) || c.apiRoot || (o != null && o.env ? f[o.env || "prod"] : c.apiRoot)
|
|
28
|
-
}), d.debug && R.log("updated", c);
|
|
29
|
-
}
|
|
30
|
-
export {
|
|
31
|
-
f as ApiUrl,
|
|
32
|
-
c as configuration,
|
|
33
|
-
x as configure
|
|
34
|
-
};
|
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
var b = Object.defineProperty, O = Object.defineProperties;
|
|
2
|
-
var $ = Object.getOwnPropertyDescriptors;
|
|
3
|
-
var k = Object.getOwnPropertySymbols;
|
|
4
|
-
var _ = Object.prototype.hasOwnProperty, x = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var M = (m, c, t) => c in m ? b(m, c, { enumerable: !0, configurable: !0, writable: !0, value: t }) : m[c] = t, u = (m, c) => {
|
|
6
|
-
for (var t in c || (c = {}))
|
|
7
|
-
_.call(c, t) && M(m, t, c[t]);
|
|
8
|
-
if (k)
|
|
9
|
-
for (var t of k(c))
|
|
10
|
-
x.call(c, t) && M(m, t, c[t]);
|
|
11
|
-
return m;
|
|
12
|
-
}, S = (m, c) => O(m, $(c));
|
|
13
|
-
var T = (m, c, t) => (M(m, typeof c != "symbol" ? c + "" : c, t), t);
|
|
14
|
-
var y = (m, c, t) => new Promise((o, g) => {
|
|
15
|
-
var h = (e) => {
|
|
16
|
-
try {
|
|
17
|
-
i(t.next(e));
|
|
18
|
-
} catch (l) {
|
|
19
|
-
g(l);
|
|
20
|
-
}
|
|
21
|
-
}, s = (e) => {
|
|
22
|
-
try {
|
|
23
|
-
i(t.throw(e));
|
|
24
|
-
} catch (l) {
|
|
25
|
-
g(l);
|
|
26
|
-
}
|
|
27
|
-
}, i = (e) => e.done ? o(e.value) : Promise.resolve(e.value).then(h, s);
|
|
28
|
-
i((t = t.apply(m, c)).next());
|
|
29
|
-
});
|
|
30
|
-
import { IHistoryRole as I, ChatMessageRole as D } from "@glodon-aiot/apis";
|
|
31
|
-
import J from "./Logger.mjs";
|
|
32
|
-
import N from "./Session.mjs";
|
|
33
|
-
import P from "dayjs";
|
|
34
|
-
import { configuration as v } from "./Config.mjs";
|
|
35
|
-
import { fetchEventSource as w } from "./api/fetchEventSource/fetch.mjs";
|
|
36
|
-
const C = new J("[DialogSession] ");
|
|
37
|
-
class H extends N {
|
|
38
|
-
constructor(t, o = "", g, h, s, i) {
|
|
39
|
-
super(t, o, g, h, s, i);
|
|
40
|
-
T(this, "ctrl", new AbortController());
|
|
41
|
-
}
|
|
42
|
-
prepareConnection() {
|
|
43
|
-
return new Promise((t) => y(this, null, function* () {
|
|
44
|
-
this._ready = !0, this.event.emit("ready"), this.frozen = !1, t(!0);
|
|
45
|
-
}));
|
|
46
|
-
}
|
|
47
|
-
postChatV2EventSource(t, o, g, h, s, i) {
|
|
48
|
-
return y(this, null, function* () {
|
|
49
|
-
const e = {
|
|
50
|
-
code: 0,
|
|
51
|
-
// messageId: uuidv4(),
|
|
52
|
-
content: "",
|
|
53
|
-
role: I.Robot,
|
|
54
|
-
sessionId: o,
|
|
55
|
-
reference: [],
|
|
56
|
-
searchReference: [],
|
|
57
|
-
messageTime: "",
|
|
58
|
-
llmModel: "",
|
|
59
|
-
comment: {
|
|
60
|
-
isAgree: 0
|
|
61
|
-
},
|
|
62
|
-
isReplying: !1
|
|
63
|
-
}, l = S(u({}, g), {
|
|
64
|
-
stream: !0
|
|
65
|
-
});
|
|
66
|
-
w(`${v.apiRoot}/chat/v2/chat?applicationId=${t}&sessionId=${o}`, {
|
|
67
|
-
method: "POST",
|
|
68
|
-
headers: {
|
|
69
|
-
Authorization: `Bearer ${this.token}`,
|
|
70
|
-
"Content-Type": "application/json"
|
|
71
|
-
},
|
|
72
|
-
body: JSON.stringify(l),
|
|
73
|
-
openWhenHidden: !0,
|
|
74
|
-
signal: h,
|
|
75
|
-
onopen(n) {
|
|
76
|
-
return n.ok && s != null && s.onopen && s.onopen(), Promise.resolve();
|
|
77
|
-
},
|
|
78
|
-
onmessage(n) {
|
|
79
|
-
if (!n.data.includes('{"code": ')) {
|
|
80
|
-
let a = {};
|
|
81
|
-
try {
|
|
82
|
-
a = JSON.parse(n.data);
|
|
83
|
-
} catch (f) {
|
|
84
|
-
}
|
|
85
|
-
(a == null ? void 0 : a.mtype) === "search" ? e.searchReference.push(a) : e.content = e.content + n.data;
|
|
86
|
-
const d = {
|
|
87
|
-
content: e.content,
|
|
88
|
-
role: 1,
|
|
89
|
-
reference: e.reference,
|
|
90
|
-
searchReference: e.searchReference,
|
|
91
|
-
messageId: e.messageId,
|
|
92
|
-
sessionId: o,
|
|
93
|
-
messageTime: P(/* @__PURE__ */ new Date()).format("YYYY-MM-DD HH:mm:ss"),
|
|
94
|
-
comment: {
|
|
95
|
-
isAgree: 0
|
|
96
|
-
},
|
|
97
|
-
isReplying: !0
|
|
98
|
-
};
|
|
99
|
-
return (s == null ? void 0 : s.onmessage) && s.onmessage(d);
|
|
100
|
-
}
|
|
101
|
-
const r = JSON.parse(n.data);
|
|
102
|
-
if (e.reference = r.data.reference, e.searchReference = r.data.searchReference, e.messageTime = r.data.messageTime, e.messageId = r.data.messageId, e.llmModel = r.data.llmModel, e.content = r.data.content, e.code = r.code, r.code === 200) {
|
|
103
|
-
const a = {
|
|
104
|
-
code: e.code,
|
|
105
|
-
content: e.content,
|
|
106
|
-
role: 1,
|
|
107
|
-
reference: e.reference,
|
|
108
|
-
searchReference: e.searchReference,
|
|
109
|
-
messageId: e.messageId,
|
|
110
|
-
sessionId: o,
|
|
111
|
-
messageTime: e.messageTime,
|
|
112
|
-
isReplying: !0
|
|
113
|
-
};
|
|
114
|
-
s != null && s.onmessage && s.onmessage(a);
|
|
115
|
-
} else
|
|
116
|
-
return s != null && s.onclose && s.onclose(e), i && i({
|
|
117
|
-
code: e.code,
|
|
118
|
-
message: e.message
|
|
119
|
-
});
|
|
120
|
-
},
|
|
121
|
-
onerror() {
|
|
122
|
-
s != null && s.onerror && s.onerror();
|
|
123
|
-
},
|
|
124
|
-
onclose() {
|
|
125
|
-
const n = {
|
|
126
|
-
code: e.code,
|
|
127
|
-
content: e.content,
|
|
128
|
-
role: 1,
|
|
129
|
-
reference: e.reference,
|
|
130
|
-
searchReference: e.searchReference,
|
|
131
|
-
messageId: e.messageId,
|
|
132
|
-
sessionId: o,
|
|
133
|
-
messageTime: e.messageTime,
|
|
134
|
-
comment: {
|
|
135
|
-
isAgree: 0
|
|
136
|
-
},
|
|
137
|
-
isReplying: !1,
|
|
138
|
-
index: -1
|
|
139
|
-
};
|
|
140
|
-
s != null && s.onclose && s.onclose(n);
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
postChatV3EventSource(t, o, g, h, s, i) {
|
|
146
|
-
return y(this, null, function* () {
|
|
147
|
-
const e = {
|
|
148
|
-
code: 0,
|
|
149
|
-
// messageId: uuidv4(),
|
|
150
|
-
content: "",
|
|
151
|
-
role: I.Robot,
|
|
152
|
-
sessionId: o,
|
|
153
|
-
reference: [],
|
|
154
|
-
searchReference: [],
|
|
155
|
-
messageTime: "",
|
|
156
|
-
llmModel: "",
|
|
157
|
-
comment: {
|
|
158
|
-
isAgree: 0
|
|
159
|
-
},
|
|
160
|
-
isReplying: !1,
|
|
161
|
-
reasoningContent: "",
|
|
162
|
-
thinkingSecs: "",
|
|
163
|
-
thinkingStatus: ""
|
|
164
|
-
}, l = S(u({}, g), {
|
|
165
|
-
stream: !0
|
|
166
|
-
});
|
|
167
|
-
w(`${v.apiRoot}/chat/v3/chat?applicationId=${t}&sessionId=${o}`, {
|
|
168
|
-
method: "POST",
|
|
169
|
-
headers: {
|
|
170
|
-
Authorization: `Bearer ${this.token}`,
|
|
171
|
-
"Content-Type": "application/json"
|
|
172
|
-
},
|
|
173
|
-
body: JSON.stringify(l),
|
|
174
|
-
openWhenHidden: !0,
|
|
175
|
-
signal: h,
|
|
176
|
-
onopen(n) {
|
|
177
|
-
return n.ok && s != null && s.onopen && s.onopen(), Promise.resolve();
|
|
178
|
-
},
|
|
179
|
-
onmessage(n) {
|
|
180
|
-
if (!n.data && !n.event && !n.id && !n.retry)
|
|
181
|
-
return;
|
|
182
|
-
let r = {};
|
|
183
|
-
try {
|
|
184
|
-
r = JSON.parse(n.data);
|
|
185
|
-
} catch (f) {
|
|
186
|
-
console.error("parse eventData to JSON failed. ", n.data);
|
|
187
|
-
}
|
|
188
|
-
if (r.code !== 200)
|
|
189
|
-
return e.index = -1, e.code = r.code, e.message = r.message, s != null && s.onmessage && s.onmessage(e), i && i({
|
|
190
|
-
code: r.code,
|
|
191
|
-
message: r.message
|
|
192
|
-
});
|
|
193
|
-
const a = r.data.type, d = r.data.payload;
|
|
194
|
-
if (e.isReplying = !0, a === "search" && e.searchReference.push(d), a === "thinking") {
|
|
195
|
-
e.thinkingStatus = "start";
|
|
196
|
-
const R = d.choices[0];
|
|
197
|
-
e.reasoningContent = e.reasoningContent + R.delta.reasoningContent;
|
|
198
|
-
}
|
|
199
|
-
if (a === "thinkingOver") {
|
|
200
|
-
e.thinkingStatus = "end";
|
|
201
|
-
const f = d.thinkingSecs;
|
|
202
|
-
e.thinkingSecs = f;
|
|
203
|
-
}
|
|
204
|
-
if (a === "text") {
|
|
205
|
-
const R = d.choices[0];
|
|
206
|
-
e.content = e.content + R.delta.content;
|
|
207
|
-
}
|
|
208
|
-
if (a === "reference" && (e.reference = d), a === "result") {
|
|
209
|
-
const f = d.messageId, R = d.llmModel, A = d.messageTime;
|
|
210
|
-
e.messageId = f, e.llmModel = R, e.messageTime = A, e.sessionId = o;
|
|
211
|
-
}
|
|
212
|
-
a === "over" ? e.index = -1 : (e.code = r.code, e.message = r.message), s != null && s.onmessage && s.onmessage(e);
|
|
213
|
-
},
|
|
214
|
-
onerror() {
|
|
215
|
-
s != null && s.onerror && s.onerror();
|
|
216
|
-
},
|
|
217
|
-
onclose() {
|
|
218
|
-
const n = S(u({}, e), {
|
|
219
|
-
isReplying: !1
|
|
220
|
-
});
|
|
221
|
-
s != null && s.onclose && s.onclose(n);
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
sendQuestion(t, o) {
|
|
227
|
-
return y(this, null, function* () {
|
|
228
|
-
var l;
|
|
229
|
-
const {
|
|
230
|
-
content: g,
|
|
231
|
-
fileIds: h,
|
|
232
|
-
oldMessageId: s
|
|
233
|
-
} = t, {
|
|
234
|
-
stream: i,
|
|
235
|
-
referenceFirst: e
|
|
236
|
-
} = o;
|
|
237
|
-
if (this.active || (yield this.activate()), this._id) {
|
|
238
|
-
let n = {
|
|
239
|
-
content: g,
|
|
240
|
-
fileIds: h,
|
|
241
|
-
referenceFirst: e,
|
|
242
|
-
oldMessageId: s,
|
|
243
|
-
promptVariables: this.promptVariables.reduce((r, a) => S(u({}, r), {
|
|
244
|
-
[a.key]: a.value
|
|
245
|
-
}), {}),
|
|
246
|
-
knowledges: (l = this.knowledges) == null ? void 0 : l.map((r) => r.id)
|
|
247
|
-
};
|
|
248
|
-
this.ctrl = new AbortController(), this.postChatV3EventSource(this._applicationId, this._id, n, this.ctrl.signal, {
|
|
249
|
-
onopen: () => {
|
|
250
|
-
C.log("open", this.ctrl);
|
|
251
|
-
},
|
|
252
|
-
onmessage: (r) => {
|
|
253
|
-
if (this._stopAnswer)
|
|
254
|
-
return;
|
|
255
|
-
let a = this.messages[this.messages.length - 1];
|
|
256
|
-
a && a.role === D.Robot ? (a = u(u({}, a), r), this.messages[this.messages.length - 1] = a, this.event.emit("message:content", a), this.event.emit("message:updated", a)) : (this.pushMessage(r), this.event.emit("message:content", r));
|
|
257
|
-
},
|
|
258
|
-
onclose: (r) => y(this, null, function* () {
|
|
259
|
-
this._stopAnswer || (C.log(r, "onclose"), this.event.emit("answer:finish", r));
|
|
260
|
-
}),
|
|
261
|
-
onerror: () => {
|
|
262
|
-
this._stopAnswer || (this.event.emit("message:error", ""), this.frozen = !1);
|
|
263
|
-
}
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
stopAnswer() {
|
|
269
|
-
this.ctrl.abort();
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
export {
|
|
273
|
-
H as default
|
|
274
|
-
};
|
package/dist/es/EventBus.mjs
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
var u = Object.defineProperty;
|
|
2
|
-
var v = Object.getOwnPropertySymbols;
|
|
3
|
-
var o = Object.prototype.hasOwnProperty, L = Object.prototype.propertyIsEnumerable;
|
|
4
|
-
var l = (s, e, n) => e in s ? u(s, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : s[e] = n, a = (s, e) => {
|
|
5
|
-
for (var n in e || (e = {}))
|
|
6
|
-
o.call(e, n) && l(s, n, e[n]);
|
|
7
|
-
if (v)
|
|
8
|
-
for (var n of v(e))
|
|
9
|
-
L.call(e, n) && l(s, n, e[n]);
|
|
10
|
-
return s;
|
|
11
|
-
};
|
|
12
|
-
var h = (s, e, n) => (l(s, typeof e != "symbol" ? e + "" : e, n), n);
|
|
13
|
-
import M from "./Logger.mjs";
|
|
14
|
-
const i = new M("[EventBus] ");
|
|
15
|
-
class $ {
|
|
16
|
-
constructor(e = !1) {
|
|
17
|
-
h(this, "eventListenerMap", {});
|
|
18
|
-
e && i.disable();
|
|
19
|
-
}
|
|
20
|
-
getEventListenerMap() {
|
|
21
|
-
return a({}, this.eventListenerMap);
|
|
22
|
-
}
|
|
23
|
-
on(e, n, r = !1) {
|
|
24
|
-
this.eventListenerMap[e] || (this.eventListenerMap[e] = []), r ? this.eventListenerMap[e].push({
|
|
25
|
-
fn: n,
|
|
26
|
-
once: !0
|
|
27
|
-
}) : this.eventListenerMap[e].push(n), i.log(`add event ${e} listener ${r ? ", call once" : ""}`);
|
|
28
|
-
}
|
|
29
|
-
once(e, n) {
|
|
30
|
-
this.on(e, n, !0);
|
|
31
|
-
}
|
|
32
|
-
off(e, n) {
|
|
33
|
-
if (this.eventListenerMap[e]) {
|
|
34
|
-
const r = this.eventListenerMap[e].findIndex((t) => {
|
|
35
|
-
if (typeof t == "function" && n === t)
|
|
36
|
-
return !0;
|
|
37
|
-
if (t = t, t.fn === n)
|
|
38
|
-
return !0;
|
|
39
|
-
});
|
|
40
|
-
r < 0 ? i.log(`event ${e} listener ${n.name} is not found`) : (this.eventListenerMap[e].splice(r, 1), i.log(`remove event ${e} listener`));
|
|
41
|
-
} else
|
|
42
|
-
i.log(`event ${e} listeners is empty`);
|
|
43
|
-
}
|
|
44
|
-
emit(e, n) {
|
|
45
|
-
if (!this.eventListenerMap[e]) {
|
|
46
|
-
i.log(`event ${e} listeners is empty`);
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
const r = [];
|
|
50
|
-
for (let t = 0; t < this.eventListenerMap[e].length; t++) {
|
|
51
|
-
const f = this.eventListenerMap[e][t];
|
|
52
|
-
typeof f == "function" ? f(n) : r.push(f);
|
|
53
|
-
}
|
|
54
|
-
r.forEach((t) => {
|
|
55
|
-
t && (t.fn(n), this.off(e, t.fn));
|
|
56
|
-
}), i.log(`event ${e} is fired, has ${this.eventListenerMap[e].length} listeners`);
|
|
57
|
-
}
|
|
58
|
-
removeAllListeners() {
|
|
59
|
-
this.eventListenerMap = {};
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
export {
|
|
63
|
-
$ as default
|
|
64
|
-
};
|
package/dist/es/Logger.mjs
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
var n = Object.defineProperty;
|
|
2
|
-
var f = (s, e, i) => e in s ? n(s, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : s[e] = i;
|
|
3
|
-
var r = (s, e, i) => (f(s, typeof e != "symbol" ? e + "" : e, i), i);
|
|
4
|
-
const o = class o {
|
|
5
|
-
constructor(e, i = !1) {
|
|
6
|
-
this.prefix = e, this.open = i;
|
|
7
|
-
}
|
|
8
|
-
disable() {
|
|
9
|
-
this.open = !1;
|
|
10
|
-
}
|
|
11
|
-
enable() {
|
|
12
|
-
this.open = !0;
|
|
13
|
-
}
|
|
14
|
-
log(...e) {
|
|
15
|
-
!this.open && !o.debug || console.log(this.prefix, ...e);
|
|
16
|
-
}
|
|
17
|
-
info(...e) {
|
|
18
|
-
!this.open && !o.debug || console.info(`%c ${this.prefix} %o`, "color:#0f0;", ...e);
|
|
19
|
-
}
|
|
20
|
-
error(...e) {
|
|
21
|
-
!this.open && !o.debug || console.error(this.prefix, ...e);
|
|
22
|
-
}
|
|
23
|
-
warn(...e) {
|
|
24
|
-
!this.open && !o.debug || console.warn(this.prefix, ...e);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
r(o, "debug", !1);
|
|
28
|
-
let t = o;
|
|
29
|
-
export {
|
|
30
|
-
t as default
|
|
31
|
-
};
|
package/dist/es/PayloadTypes.mjs
DELETED