@glodon-aiot/bot-client-sdk 3.3.0-beta.13

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.
Files changed (37) hide show
  1. package/README.md +157 -0
  2. package/dist/agent-cli-sdk.js +33141 -0
  3. package/dist/agent-cli-sdk.umd.cjs +140 -0
  4. package/dist/es/AgentPlugin.mjs +20 -0
  5. package/dist/es/AgentSession.mjs +285 -0
  6. package/dist/es/BotClient.mjs +250 -0
  7. package/dist/es/Config.mjs +36 -0
  8. package/dist/es/DialogSession.mjs +301 -0
  9. package/dist/es/EventBus.mjs +64 -0
  10. package/dist/es/Logger.mjs +31 -0
  11. package/dist/es/PayloadTypes.mjs +4 -0
  12. package/dist/es/Session.mjs +683 -0
  13. package/dist/es/api/fetchEventSource/fetch.mjs +112 -0
  14. package/dist/es/api/fetchEventSource/parse.mjs +97 -0
  15. package/dist/es/api/index.mjs +41 -0
  16. package/dist/es/index.mjs +11 -0
  17. package/dist/es/utils.mjs +11 -0
  18. package/dist/lib/index.js +4 -0
  19. package/dist/src/AgentPlugin.d.ts +17 -0
  20. package/dist/src/AgentSession.d.ts +13 -0
  21. package/dist/src/BotClient.d.ts +48 -0
  22. package/dist/src/Config.d.ts +46 -0
  23. package/dist/src/DialogSession.d.ts +26 -0
  24. package/dist/src/EventBus.d.ts +23 -0
  25. package/dist/src/Logger.d.ts +12 -0
  26. package/dist/src/PayloadTypes.d.ts +84 -0
  27. package/dist/src/Session.d.ts +222 -0
  28. package/dist/src/__ tests __/AgentClient.spec.d.ts +1 -0
  29. package/dist/src/__ tests __/AgentSession.spec.d.ts +1 -0
  30. package/dist/src/__ tests __/DialogClient.spec.d.ts +1 -0
  31. package/dist/src/api/fetchEventSource/fetch.d.ts +44 -0
  32. package/dist/src/api/fetchEventSource/index.d.ts +1 -0
  33. package/dist/src/api/fetchEventSource/parse.d.ts +36 -0
  34. package/dist/src/api/index.d.ts +2 -0
  35. package/dist/src/index.d.ts +5 -0
  36. package/dist/src/utils.d.ts +4 -0
  37. package/package.json +90 -0
@@ -0,0 +1,20 @@
1
+ var c = Object.defineProperty;
2
+ var a = (e, t, i) => t in e ? c(e, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[t] = i;
3
+ var s = (e, t, i) => (a(e, typeof t != "symbol" ? t + "" : t, i), i);
4
+ class d {
5
+ constructor(t, i = {}, o) {
6
+ s(this, "code");
7
+ s(this, "description", "");
8
+ s(this, "loaded", !1);
9
+ s(this, "functions", {});
10
+ this.code = t, i && (this.functions = i);
11
+ }
12
+ fetchData() {
13
+ this.description = "描述", this.loaded = !0;
14
+ }
15
+ checkFunctions() {
16
+ }
17
+ }
18
+ export {
19
+ d as default
20
+ };
@@ -0,0 +1,285 @@
1
+ var R = Object.defineProperty, b = Object.defineProperties;
2
+ var S = Object.getOwnPropertyDescriptors;
3
+ var _ = Object.getOwnPropertySymbols;
4
+ var A = Object.prototype.hasOwnProperty, E = Object.prototype.propertyIsEnumerable;
5
+ var P = (d, t, n) => t in d ? R(d, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : d[t] = n, h = (d, t) => {
6
+ for (var n in t || (t = {}))
7
+ A.call(t, n) && P(d, n, t[n]);
8
+ if (_)
9
+ for (var n of _(t))
10
+ E.call(t, n) && P(d, n, t[n]);
11
+ return d;
12
+ }, k = (d, t) => b(d, S(t));
13
+ var p = (d, t, n) => new Promise((o, i) => {
14
+ var s = (c) => {
15
+ try {
16
+ r(n.next(c));
17
+ } catch (g) {
18
+ i(g);
19
+ }
20
+ }, e = (c) => {
21
+ try {
22
+ r(n.throw(c));
23
+ } catch (g) {
24
+ i(g);
25
+ }
26
+ }, r = (c) => c.done ? o(c.value) : Promise.resolve(c.value).then(s, e);
27
+ r((n = n.apply(d, t)).next());
28
+ });
29
+ import { ChatMessageRole as I } from "@glodon-aiot/apis";
30
+ import q from "./Logger.mjs";
31
+ import { configuration as v } from "./Config.mjs";
32
+ import { io as x } from "socket.io-client";
33
+ import { UserMode as w } from "./PayloadTypes.mjs";
34
+ import L, { SessionErrors as M } from "./Session.mjs";
35
+ const u = new q("[AgentSession] ");
36
+ class D extends L {
37
+ constructor(t, n = "", o, i, s, e) {
38
+ super(t, n, o, i, s, e);
39
+ }
40
+ prepareConnection() {
41
+ return new Promise((t) => p(this, null, function* () {
42
+ this.socket && t(!0);
43
+ const n = {
44
+ version: "1.0",
45
+ stream: "false",
46
+ appId: this._applicationId,
47
+ sessionId: this.id,
48
+ Authorization: `${this.token}`,
49
+ userMode: v.debug ? w.Debug : w.Normal
50
+ }, o = new URL(v.apiRoot), i = yield x(o.origin, {
51
+ path: o.pathname.replace("api", "socketio") + "/copilot",
52
+ query: n,
53
+ transports: ["websocket"]
54
+ });
55
+ i.on("connect", () => {
56
+ u.log("socket:connect"), this.event.emit("socket:connect"), i.emit("init");
57
+ }), i.on("disconnect", () => {
58
+ u.log("socket:disconnect"), this.event.emit("socket:disconnect");
59
+ }), i.on("ready", (s) => {
60
+ if (s.code === 200) {
61
+ u.log("ready");
62
+ const e = v.debug ? w.Debug : w.Normal;
63
+ e === w.Debug && s.userMode, this._ready || (this._ready = !0, this.event.emit("ready")), this.frozen = !1, this.registerMcpFromClientConfig(), t(!0);
64
+ } else {
65
+ this._ready && (this._ready = !1);
66
+ const e = new Error(
67
+ M.SocketConnectionFailed
68
+ // , {
69
+ // cause: data,
70
+ // }
71
+ );
72
+ u.error("error", e), this.event.emit("error", e), t(!1);
73
+ }
74
+ }), i.on("action", (s, e) => p(this, null, function* () {
75
+ if (this._stopAnswer || !this.id)
76
+ return;
77
+ const {
78
+ type: r,
79
+ data: {
80
+ runnerIsClient: c,
81
+ pluginCode: g,
82
+ funcCode: m,
83
+ parameters: a,
84
+ requestBody: N
85
+ }
86
+ } = s, f = this.messages[this.messages.length - 1];
87
+ if (!f.messageId)
88
+ f.actions || (f.actions = []), f.actions[s.data.step - 1] || (f.actions[s.data.step - 1] = []), f.actions[s.data.step - 1].push(s), this.event.emit("message:action", {
89
+ messageId: f.messageId,
90
+ action: s
91
+ }), this.event.emit("message:updated", f);
92
+ else {
93
+ const l = {
94
+ messageId: "",
95
+ content: "",
96
+ role: I.Robot,
97
+ sessionId: this.id,
98
+ reference: [],
99
+ searchReference: [],
100
+ isLoading: !0,
101
+ messageTime: "",
102
+ actions: [[s]],
103
+ comment: {
104
+ isAgree: 0
105
+ }
106
+ };
107
+ this.pushMessage(l), this.event.emit("message:action", {
108
+ messageId: l.messageId,
109
+ action: s
110
+ });
111
+ }
112
+ if (this.inactivating) {
113
+ const l = new Error(
114
+ M.Inactive
115
+ // {
116
+ // cause: {
117
+ // code: -1,
118
+ // message:
119
+ // 'session is inactive, skipping plugin client function call',
120
+ // },
121
+ // }
122
+ );
123
+ u.warn("error", l), this.event.emit("error", l);
124
+ } else if (r === "FUNCTION_CALL" && c) {
125
+ if (u.log(`calling function ${m} of plugin ${g} with argument:
126
+ ${JSON.stringify(a)}`), !v.plugins[g]) {
127
+ e({
128
+ code: 404,
129
+ message: "对不起,没有找到插件。"
130
+ });
131
+ return;
132
+ }
133
+ const l = v.plugins[g][m];
134
+ typeof l != "function" && e({
135
+ code: 404,
136
+ message: "对不起,没有找到插件方法。"
137
+ });
138
+ let y = a == null ? void 0 : a.query;
139
+ try {
140
+ y = JSON.parse(a == null ? void 0 : a.query);
141
+ } catch (C) {
142
+ }
143
+ l(y, (...C) => {
144
+ this._stopAnswer || e(...C);
145
+ });
146
+ }
147
+ })), i.on("answer", (s) => {
148
+ if (!this._stopAnswer)
149
+ if (s.data.code !== 200 && (s.data.index = -1, this.event.emit("error", s.data)), s.data.index === -1) {
150
+ let e = this.messages[this.messages.length - 1];
151
+ if (e && !e.messageId)
152
+ e = h(h({}, e), s.data), this.event.emit("message:content", e), this.event.emit("message:updated", e), this.event.emit("answer:finish", e);
153
+ else {
154
+ const r = h({
155
+ messageId: "",
156
+ content: "",
157
+ role: I.Robot,
158
+ sessionId: this.id,
159
+ reference: [],
160
+ searchReference: [],
161
+ isLoading: !1,
162
+ messageTime: "",
163
+ actions: [],
164
+ comment: {
165
+ isAgree: 0
166
+ }
167
+ }, s.data);
168
+ this.event.emit("message:content", r), this.pushMessage(r), this.event.emit("answer:finish", r);
169
+ }
170
+ } else {
171
+ let e = this.messages[this.messages.length - 1];
172
+ e && !e.messageId ? (e = h(h({}, e), s.data), this.messages[this.messages.length - 1] = e, this.event.emit("message:content", e), this.event.emit("message:updated", e)) : (this.pushMessage(s.data), this.event.emit("message:content", s.data));
173
+ }
174
+ }), i.on("reference", (s) => p(this, null, function* () {
175
+ if (this._stopAnswer)
176
+ return;
177
+ if (!this.id) {
178
+ const a = new Error(
179
+ M.IdUndefined
180
+ // {
181
+ // cause: SESSION_ERROR_CAUSE[SessionErrors.IdUndefined],
182
+ // }
183
+ );
184
+ u.error(a), this.event.emit("error", a), this.frozen = !1;
185
+ return;
186
+ }
187
+ const {
188
+ type: e,
189
+ data: r,
190
+ requestId: c
191
+ } = s, g = this.messages.findIndex((a) => a.messageId === c && a.role === I.User);
192
+ if (g < 0)
193
+ return;
194
+ const m = g + 1;
195
+ if (m >= this.messages.length) {
196
+ const a = {
197
+ messageId: "",
198
+ content: "",
199
+ role: I.Robot,
200
+ sessionId: this.id,
201
+ reference: [],
202
+ searchReference: [],
203
+ isLoading: !0,
204
+ messageTime: "",
205
+ actions: [],
206
+ comment: {
207
+ isAgree: 0
208
+ }
209
+ };
210
+ this.pushMessage(a);
211
+ }
212
+ e === "KG" ? (this.messages[m] = k(h({}, this.messages[m]), {
213
+ reference: r.knowledgeReference
214
+ }), yield this.fillMessageReference(this.messages[m]), this.event.emit("message:reference", r.knowledgeReference), this.event.emit("message:updated", this.messages[m])) : e === "WEB_SEARCH" && (this.messages[m] = k(h({}, this.messages[m]), {
215
+ searchReference: r.knowledgeReference
216
+ }), this.event.emit("message:searchreference", r.searchReference), this.event.emit("message:updated", this.messages[m]));
217
+ })), this.socket = i, i.open();
218
+ }));
219
+ }
220
+ registerMcpFromClientConfig() {
221
+ return v.mcp ? new Promise((t, n) => {
222
+ if (!this.socket) {
223
+ n("socket is undefined");
224
+ return;
225
+ }
226
+ this.socket.emit("add_mcp_servers", v.mcp, (o) => {
227
+ o.code === 200 ? (Object.keys(o.data).forEach((i) => {
228
+ o.data[i].code !== 200 && console.error(i, "MCP Server 注册失败。", o.data[i]);
229
+ }), t(!0)) : (console.error("MCP Server 注册失败。", o), n(o));
230
+ });
231
+ }) : Promise.resolve(!0);
232
+ }
233
+ addMcpServers(t) {
234
+ return p(this, null, function* () {
235
+ return this.ready ? this.socket ? new Promise((n, o) => {
236
+ this.socket && this.socket.emit("add_mcp_servers", t, (i) => {
237
+ i.code === 200 ? (Object.keys(i.data).forEach((s) => {
238
+ i.data[s].code !== 200 && console.error(s, "MCP Server 注册失败。", i.data[s]);
239
+ }), n(!0)) : (console.error("MCP Server 注册失败。", i), o(i));
240
+ });
241
+ }) : (console.error(" socket is undefined."), Promise.reject("socket is undefined")) : (console.error("session is not avalible."), Promise.reject("session is not avalible"));
242
+ });
243
+ }
244
+ listMcpServers() {
245
+ return p(this, null, function* () {
246
+ return this.ready ? this.socket ? new Promise((t, n) => {
247
+ this.socket && this.socket.emit("list_mcp_servers", (o) => {
248
+ o.code === 200 ? t(o.data) : n(o);
249
+ });
250
+ }) : (console.error(" socket is undefined."), Promise.reject("socket is undefined")) : (console.error("session is not avalible."), Promise.reject("session is not avalible"));
251
+ });
252
+ }
253
+ sendQuestion(t, n) {
254
+ return p(this, null, function* () {
255
+ var i, s, e;
256
+ let o = k(h({}, t), {
257
+ promptVariables: this.promptVariables.reduce((r, c) => k(h({}, r), {
258
+ [c.key]: c.value
259
+ }), {}),
260
+ knowledges: (i = this.knowledges) == null ? void 0 : i.map((r) => r.id)
261
+ });
262
+ if (!this.active) {
263
+ if (yield this.activate(), !this.socket) {
264
+ const r = new Error(
265
+ M.SocketConnectionFailed
266
+ // {
267
+ // cause: { code: -1, message: 'socket is null' },
268
+ // }
269
+ );
270
+ return u.warn("error", r), this.event.emit("error", r), !1;
271
+ }
272
+ (s = this.socket) == null || s.emit("question", o);
273
+ return;
274
+ }
275
+ (e = this.socket) == null || e.emit("question", o);
276
+ });
277
+ }
278
+ stopAnswer() {
279
+ var t;
280
+ (t = this.socket) == null || t.emit("stop_answer");
281
+ }
282
+ }
283
+ export {
284
+ D as default
285
+ };
@@ -0,0 +1,250 @@
1
+ var S = Object.defineProperty, w = Object.defineProperties;
2
+ var k = Object.getOwnPropertyDescriptors;
3
+ var v = Object.getOwnPropertySymbols;
4
+ var A = Object.prototype.hasOwnProperty, x = Object.prototype.propertyIsEnumerable;
5
+ var f = (o, i, e) => i in o ? S(o, i, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[i] = e, _ = (o, i) => {
6
+ for (var e in i || (i = {}))
7
+ A.call(i, e) && f(o, e, i[e]);
8
+ if (v)
9
+ for (var e of v(i))
10
+ x.call(i, e) && f(o, e, i[e]);
11
+ return o;
12
+ }, u = (o, i) => w(o, k(i));
13
+ var p = (o, i, e) => (f(o, typeof i != "symbol" ? i + "" : i, e), e);
14
+ var c = (o, i, e) => new Promise((t, s) => {
15
+ var n = (a) => {
16
+ try {
17
+ r(e.next(a));
18
+ } catch (h) {
19
+ s(h);
20
+ }
21
+ }, l = (a) => {
22
+ try {
23
+ r(e.throw(a));
24
+ } catch (h) {
25
+ s(h);
26
+ }
27
+ }, r = (a) => a.done ? t(a.value) : Promise.resolve(a.value).then(n, l);
28
+ r((e = e.apply(o, i)).next());
29
+ });
30
+ import { parseJWT as g } from "./utils.mjs";
31
+ import I from "./Logger.mjs";
32
+ import { getCVForceService as R } from "./api/index.mjs";
33
+ import { configure as E, configuration as y } from "./Config.mjs";
34
+ import { ApplicationTypes as m } from "@glodon-aiot/apis";
35
+ import L from "./AgentSession.mjs";
36
+ import M from "./DialogSession.mjs";
37
+ import C from "./EventBus.mjs";
38
+ const T = new I("[BotClient] ");
39
+ class z {
40
+ constructor(i, e, t = !0) {
41
+ p(this, "event", new C());
42
+ p(this, "cvforceApi");
43
+ //从token解析出来的用户信息
44
+ p(this, "_applicationId");
45
+ p(this, "_application", null);
46
+ //session列表,被加载过的session将会被缓存到这个列表中
47
+ p(this, "_sessions", []);
48
+ //活跃的session,只支持一个活跃的session
49
+ p(this, "_activeSession");
50
+ p(this, "_ready", !1);
51
+ //问题长度
52
+ p(this, "_questionContextMaxLength", 4e3);
53
+ p(this, "_promptVariables", []);
54
+ if (this._token = i, this.lazyload = t, E(e), this._applicationId = g(i).rid || y.applicationId, !this._applicationId)
55
+ throw "token is not vaild";
56
+ this.cvforceApi = this.getService(), this.loadApplication().then(() => {
57
+ this.event.emit("ready");
58
+ });
59
+ }
60
+ checkReady() {
61
+ if (!this.ready)
62
+ throw Error("client is not ready.");
63
+ }
64
+ get ready() {
65
+ return this._ready;
66
+ }
67
+ set ready(i) {
68
+ this._ready = i;
69
+ }
70
+ get questionContextMaxLength() {
71
+ return this.checkReady(), this._questionContextMaxLength;
72
+ }
73
+ get promptVariables() {
74
+ return this.checkReady(), this._promptVariables;
75
+ }
76
+ get knowledges() {
77
+ var i;
78
+ return this.checkReady(), (i = this._application) == null ? void 0 : i.arrange[0].knowledges;
79
+ }
80
+ get sessions() {
81
+ return this.checkReady(), this._sessions;
82
+ }
83
+ set sessions(i) {
84
+ this.checkReady(), this._sessions = i, this.event.emit("sessions:updated", i);
85
+ }
86
+ loadApplication() {
87
+ return c(this, null, function* () {
88
+ var e, t, s;
89
+ this._application = yield this.cvforceApi.getApplicationId(this._applicationId).then((n) => (typeof n.arrange[0].recommendQuestionOpen != "boolean" && (n.arrange[0].recommendQuestionOpen = !0), u(_({}, n), {
90
+ arrange: [u(_({}, n.arrange[0]), {
91
+ recommendQuestionOpen: y.loadRelatedQuesions && n.arrange[0].recommendQuestionOpen
92
+ })]
93
+ })));
94
+ const i = (s = (t = (e = this._application) == null ? void 0 : e.arrange) == null ? void 0 : t[0]) == null ? void 0 : s.llmModel;
95
+ return i && (this._questionContextMaxLength = yield this.cvforceApi.getBaseModel(i).then((n) => n.maxModelLength)), this._promptVariables = yield this.cvforceApi.getPrompts(this._applicationId), this._ready = !0, this.event.emit("application:loaded"), this._application;
96
+ });
97
+ }
98
+ getService() {
99
+ return this.cvforceApi ? this.cvforceApi : R(y.apiRoot, this.token, (i, e) => T.error(e));
100
+ }
101
+ get token() {
102
+ return this._token;
103
+ }
104
+ set token(i) {
105
+ this.checkReady(), this._token = i, this.ready = !1;
106
+ const e = g(i).rid;
107
+ this._applicationId !== e && (this._applicationId = e, this._application = null, this.loadApplication().then(() => {
108
+ this.event.emit("ready");
109
+ }), this.clean());
110
+ }
111
+ get applicationId() {
112
+ return this._applicationId;
113
+ }
114
+ get application() {
115
+ return this.checkReady(), this._application;
116
+ }
117
+ get activeSession() {
118
+ var i;
119
+ return this.checkReady(), ((i = this._activeSession) == null ? void 0 : i.id) || "";
120
+ }
121
+ set activeSession(i) {
122
+ this.checkReady(), this.loadSession(i).then((e) => {
123
+ this._activeSession && this._activeSession.id !== i && this._activeSession.inactivate(), this._activeSession = e;
124
+ });
125
+ }
126
+ createSession(i, e, t, s, n) {
127
+ return c(this, null, function* () {
128
+ const l = this;
129
+ return new Promise((r, a) => {
130
+ const h = (d) => c(this, null, function* () {
131
+ if (d === m.Agent)
132
+ r(new L(i, e, t, s, n, l));
133
+ else if (d === m.Dialog)
134
+ r(new M(i, e, t, s, n, l));
135
+ else
136
+ throw Error(`不支持的应用类型:${d}`);
137
+ });
138
+ if (this.ready) {
139
+ if (!this._application)
140
+ throw Error("client is not ready");
141
+ h(this._application.type);
142
+ } else
143
+ this.event.on("ready", () => {
144
+ if (!this._application)
145
+ throw Error("_application is null");
146
+ h(this._application.type);
147
+ }, !0);
148
+ });
149
+ });
150
+ }
151
+ getSessions(i) {
152
+ return c(this, null, function* () {
153
+ return new Promise((e, t) => {
154
+ const s = () => this.cvforceApi.listSessions(this._applicationId, i).then((n) => {
155
+ const l = [];
156
+ return n.forEach((r) => c(this, null, function* () {
157
+ const a = this._sessions.find((h) => r.id === h.id);
158
+ if (a)
159
+ a.data = r, this._application ? a.application = this._application : a.loadApplicationInfo(), l.push(a);
160
+ else {
161
+ const h = yield this.createSession(this.token, r.id, r, this.lazyload, this._application || void 0);
162
+ l.push(h);
163
+ }
164
+ })), this.sessions = l, l;
165
+ });
166
+ if (this.ready) {
167
+ if (!this._application)
168
+ throw Error("_application is null");
169
+ e(s());
170
+ } else
171
+ this.event.on("ready", () => {
172
+ if (!this._application)
173
+ throw Error("_application is null");
174
+ e(s());
175
+ }, !0);
176
+ });
177
+ });
178
+ }
179
+ loadSession(i = "", e) {
180
+ return c(this, null, function* () {
181
+ this.checkReady();
182
+ let t = this.sessions.find((s) => s.id === i);
183
+ if (t || (t = yield this.createSession(this.token, i, e), this._sessions.push(t)), this._activeSession) {
184
+ if (this._activeSession === t)
185
+ return t;
186
+ this._activeSession.inactivate();
187
+ }
188
+ return t.id ? (yield t.activate(), this._activeSession = t) : t.addEventListener("data:loaded", () => {
189
+ this._activeSession !== t && (t == null || t.activate(), this._activeSession = t);
190
+ }, !0), t;
191
+ });
192
+ }
193
+ reload() {
194
+ return this.loadApplication().then(() => c(this, null, function* () {
195
+ return yield this.getSessions(), this.event.emit("ready"), this;
196
+ }));
197
+ }
198
+ reloadSession(i) {
199
+ return c(this, null, function* () {
200
+ yield this.reload();
201
+ let e = this._sessions.find((t) => t.id === i) || this._activeSession;
202
+ if (!e) {
203
+ console.warn("reloadSession session failed.");
204
+ return;
205
+ }
206
+ return yield e.reload(), e;
207
+ });
208
+ }
209
+ setTop(i, e, t = "top_time desc, sort_status desc, updated_at desc") {
210
+ return c(this, null, function* () {
211
+ let s = i ? this._sessions.find((n) => n.id === i) : this._activeSession;
212
+ if (!s) {
213
+ console.warn("setTop session failed.");
214
+ return;
215
+ }
216
+ return yield s.setTop(e), this.getSessions({
217
+ order: t
218
+ });
219
+ });
220
+ }
221
+ addEventListener(i, e, t = !1) {
222
+ if (typeof e != "function")
223
+ throw Error("event listener is not a function");
224
+ if (t) {
225
+ this.event.once(i, e);
226
+ return;
227
+ }
228
+ this.event.on(i, e);
229
+ }
230
+ removeEventListener(i, e) {
231
+ this.event.off(i, e);
232
+ }
233
+ removeSession(i, e) {
234
+ return c(this, null, function* () {
235
+ this.checkReady();
236
+ let t = -1;
237
+ if (typeof i == "string" ? t = this._sessions.findIndex((s) => s.id === i) : t = this._sessions.findIndex((s) => s.id === i.id), t > -1) {
238
+ const s = this._sessions[t];
239
+ e && (yield s.delete()), this._sessions.splice(t, 1);
240
+ } else
241
+ console.warn("session delete failed, session is not exist.");
242
+ });
243
+ }
244
+ clean() {
245
+ this._sessions.forEach((i) => i.destroy()), this.sessions = [];
246
+ }
247
+ }
248
+ export {
249
+ z as default
250
+ };
@@ -0,0 +1,36 @@
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
+ mcp: void 0,
25
+ loadRelatedQuesions: !0
26
+ };
27
+ function x(o) {
28
+ d.debug = (o == null ? void 0 : o.debug) || !1, c = l(i(i({}, c), o), {
29
+ apiRoot: (o == null ? void 0 : o.apiRoot) || c.apiRoot || (o != null && o.env ? f[o.env || "prod"] : c.apiRoot)
30
+ }), d.debug && R.log("updated", c);
31
+ }
32
+ export {
33
+ f as ApiUrl,
34
+ c as configuration,
35
+ x as configure
36
+ };