@glodon-aiot/agent-cli-sdk 2.4.7 → 3.0.4

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 (96) hide show
  1. package/README.md +128 -41
  2. package/dist/agent-cli-sdk.js +28505 -30335
  3. package/dist/agent-cli-sdk.umd.cjs +113 -123
  4. package/dist/src/AgentSession.d.ts +4 -3
  5. package/dist/src/BotClient.d.ts +7 -5
  6. package/dist/src/DialogSession.d.ts +4 -3
  7. package/dist/src/Session.d.ts +70 -16
  8. package/dist/src/api/fetchEventSource/fetch.d.ts +1 -1
  9. package/dist/src/api/fetchEventSource/index.d.ts +1 -1
  10. package/package.json +13 -22
  11. package/dist/cdn/agent-cli-sdk.js +0 -32945
  12. package/dist/cdn/agent-cli-sdk.umd.cjs +0 -140
  13. package/dist/cdn/src/AgentPlugin.d.ts +0 -17
  14. package/dist/cdn/src/AgentSession.d.ts +0 -8
  15. package/dist/cdn/src/BotClient.d.ts +0 -46
  16. package/dist/cdn/src/Config.d.ts +0 -32
  17. package/dist/cdn/src/DialogSession.d.ts +0 -21
  18. package/dist/cdn/src/EventBus.d.ts +0 -23
  19. package/dist/cdn/src/Logger.d.ts +0 -12
  20. package/dist/cdn/src/PayloadTypes.d.ts +0 -84
  21. package/dist/cdn/src/Session.d.ts +0 -156
  22. package/dist/cdn/src/__ tests __/AgentClient.spec.d.ts +0 -1
  23. package/dist/cdn/src/__ tests __/AgentSession.spec.d.ts +0 -1
  24. package/dist/cdn/src/__ tests __/DialogClient.spec.d.ts +0 -1
  25. package/dist/cdn/src/api/fetchEventSource/fetch.d.ts +0 -44
  26. package/dist/cdn/src/api/fetchEventSource/index.d.ts +0 -1
  27. package/dist/cdn/src/api/fetchEventSource/parse.d.ts +0 -36
  28. package/dist/cdn/src/api/index.d.ts +0 -2
  29. package/dist/cdn/src/index.d.ts +0 -5
  30. package/dist/cdn/src/utils.d.ts +0 -4
  31. package/dist/es/AgentPlugin.mjs +0 -20
  32. package/dist/es/AgentSession.mjs +0 -243
  33. package/dist/es/BotClient.mjs +0 -242
  34. package/dist/es/Config.mjs +0 -34
  35. package/dist/es/DialogSession.mjs +0 -281
  36. package/dist/es/EventBus.mjs +0 -64
  37. package/dist/es/Logger.mjs +0 -31
  38. package/dist/es/PayloadTypes.mjs +0 -4
  39. package/dist/es/Session.mjs +0 -527
  40. package/dist/es/_virtual/_commonjsHelpers.mjs +0 -4
  41. package/dist/es/_virtual/index.mjs +0 -4
  42. package/dist/es/_virtual/index2.mjs +0 -4
  43. package/dist/es/_virtual/index3.mjs +0 -4
  44. package/dist/es/_virtual/minio-zj.mjs +0 -4
  45. package/dist/es/api/fetchEventSource/fetch.mjs +0 -112
  46. package/dist/es/api/fetchEventSource/parse.mjs +0 -97
  47. package/dist/es/api/index.mjs +0 -48
  48. package/dist/es/index.mjs +0 -11
  49. package/dist/es/node_modules/@glodon-aiot/minio/dist/minio-zj.mjs +0 -26485
  50. package/dist/es/node_modules/@socket.io/component-emitter/lib/esm/index.mjs +0 -54
  51. package/dist/es/node_modules/base64-js/index.mjs +0 -47
  52. package/dist/es/node_modules/buffer/index.mjs +0 -927
  53. package/dist/es/node_modules/engine.io-client/build/esm/contrib/has-cors.mjs +0 -9
  54. package/dist/es/node_modules/engine.io-client/build/esm/contrib/parseqs.mjs +0 -18
  55. package/dist/es/node_modules/engine.io-client/build/esm/contrib/parseuri.mjs +0 -24
  56. package/dist/es/node_modules/engine.io-client/build/esm/contrib/yeast.mjs +0 -19
  57. package/dist/es/node_modules/engine.io-client/build/esm/globalThis.browser.mjs +0 -4
  58. package/dist/es/node_modules/engine.io-client/build/esm/socket.mjs +0 -317
  59. package/dist/es/node_modules/engine.io-client/build/esm/transport.mjs +0 -113
  60. package/dist/es/node_modules/engine.io-client/build/esm/transports/index.mjs +0 -11
  61. package/dist/es/node_modules/engine.io-client/build/esm/transports/polling.mjs +0 -273
  62. package/dist/es/node_modules/engine.io-client/build/esm/transports/websocket-constructor.browser.mjs +0 -8
  63. package/dist/es/node_modules/engine.io-client/build/esm/transports/websocket.mjs +0 -87
  64. package/dist/es/node_modules/engine.io-client/build/esm/transports/webtransport.mjs +0 -52
  65. package/dist/es/node_modules/engine.io-client/build/esm/transports/xmlhttprequest.browser.mjs +0 -21
  66. package/dist/es/node_modules/engine.io-client/build/esm/util.mjs +0 -23
  67. package/dist/es/node_modules/engine.io-parser/build/esm/commons.mjs +0 -21
  68. package/dist/es/node_modules/engine.io-parser/build/esm/contrib/base64-arraybuffer.mjs +0 -14
  69. package/dist/es/node_modules/engine.io-parser/build/esm/decodePacket.browser.mjs +0 -39
  70. package/dist/es/node_modules/engine.io-parser/build/esm/encodePacket.browser.mjs +0 -28
  71. package/dist/es/node_modules/engine.io-parser/build/esm/index.mjs +0 -105
  72. package/dist/es/node_modules/ieee754/index.mjs +0 -28
  73. package/dist/es/node_modules/js-base64/base64.mjs +0 -31
  74. package/dist/es/node_modules/socket.io-client/build/esm/contrib/backo2.mjs +0 -26
  75. package/dist/es/node_modules/socket.io-client/build/esm/index.mjs +0 -25
  76. package/dist/es/node_modules/socket.io-client/build/esm/manager.mjs +0 -242
  77. package/dist/es/node_modules/socket.io-client/build/esm/on.mjs +0 -8
  78. package/dist/es/node_modules/socket.io-client/build/esm/socket.mjs +0 -608
  79. package/dist/es/node_modules/socket.io-client/build/esm/url.mjs +0 -19
  80. package/dist/es/node_modules/socket.io-parser/build/esm/binary.mjs +0 -52
  81. package/dist/es/node_modules/socket.io-parser/build/esm/index.mjs +0 -203
  82. package/dist/es/node_modules/socket.io-parser/build/esm/is-binary.mjs +0 -26
  83. package/dist/es/node_modules/uuid/dist/esm-browser/native.mjs +0 -6
  84. package/dist/es/node_modules/uuid/dist/esm-browser/rng.mjs +0 -10
  85. package/dist/es/node_modules/uuid/dist/esm-browser/stringify.mjs +0 -9
  86. package/dist/es/node_modules/uuid/dist/esm-browser/v4.mjs +0 -19
  87. package/dist/es/packages/apis/dist/es/aecpilot/model.mjs +0 -4
  88. package/dist/es/packages/apis/dist/es/aecpilotui/index.mjs +0 -8
  89. package/dist/es/packages/apis/dist/es/agentcliui/index.mjs +0 -8
  90. package/dist/es/packages/apis/dist/es/base/index.mjs +0 -154
  91. package/dist/es/packages/apis/dist/es/cvforce/index.mjs +0 -431
  92. package/dist/es/packages/apis/dist/es/cvforce/model.mjs +0 -5
  93. package/dist/es/packages/apis/dist/es/node_modules/uuid/dist/esm-browser/native.mjs +0 -1
  94. package/dist/es/packages/apis/dist/es/node_modules/uuid/dist/esm-browser/stringify.mjs +0 -3
  95. package/dist/es/utils.mjs +0 -11
  96. package/dist/lib/index.js +0 -126
@@ -1,527 +0,0 @@
1
- var x = Object.defineProperty, b = Object.defineProperties;
2
- var E = Object.getOwnPropertyDescriptors;
3
- var M = Object.getOwnPropertySymbols;
4
- var z = Object.prototype.hasOwnProperty, Q = Object.prototype.propertyIsEnumerable;
5
- var A = (c, e, t) => e in c ? x(c, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : c[e] = t, f = (c, e) => {
6
- for (var t in e || (e = {}))
7
- z.call(e, t) && A(c, t, e[t]);
8
- if (M)
9
- for (var t of M(e))
10
- Q.call(e, t) && A(c, t, e[t]);
11
- return c;
12
- }, m = (c, e) => b(c, E(e));
13
- var l = (c, e, t) => (A(c, typeof e != "symbol" ? e + "" : e, t), t);
14
- var h = (c, e, t) => new Promise((a, o) => {
15
- var r = (i) => {
16
- try {
17
- n(t.next(i));
18
- } catch (p) {
19
- o(p);
20
- }
21
- }, d = (i) => {
22
- try {
23
- n(t.throw(i));
24
- } catch (p) {
25
- o(p);
26
- }
27
- }, n = (i) => i.done ? a(i.value) : Promise.resolve(i.value).then(r, d);
28
- n((t = t.apply(c, e)).next());
29
- });
30
- import { parseJWT as R, removeNewlines as T, removeLeadingAndTrailingBackslashes as V } from "./utils.mjs";
31
- import "axios";
32
- import "./node_modules/@glodon-aiot/minio/dist/minio-zj.mjs";
33
- import C from "dayjs";
34
- import "./packages/apis/dist/es/node_modules/uuid/dist/esm-browser/native.mjs";
35
- import "./packages/apis/dist/es/node_modules/uuid/dist/esm-browser/stringify.mjs";
36
- import "./packages/apis/dist/es/agentcliui/index.mjs";
37
- import "./packages/apis/dist/es/aecpilotui/index.mjs";
38
- import { ChatMessageRole as w } from "./packages/apis/dist/es/cvforce/model.mjs";
39
- import q from "./Logger.mjs";
40
- import { configuration as S } from "./Config.mjs";
41
- import F from "./EventBus.mjs";
42
- import { getCVForceService as P } from "./api/index.mjs";
43
- import k from "./node_modules/uuid/dist/esm-browser/v4.mjs";
44
- const u = new q("[AgentClient] ");
45
- var B = /* @__PURE__ */ ((c) => (c.DataRequestFailed = "data request error", c.SocketConnectionFailed = "socket error", c.IdUndefined = "session id is not defined", c.SendingEmptyContent = "failed at sending empty content", c.Frozen = "session is frozen", c.UserModeError = "failed at setting socket user mode", c.Inactive = "session is inactive", c))(B || {});
46
- class te {
47
- constructor(e, t = "", a, o) {
48
- l(this, "_id");
49
- l(this, "_frozen", !1);
50
- //是否可发送新问题
51
- l(this, "inactivating", !1);
52
- l(this, "_ready", !1);
53
- // ready = false;
54
- l(this, "event", new F());
55
- //从token解析出来的用户信息
56
- l(this, "_applicationId");
57
- l(this, "data", null);
58
- // _knowledges: IKnowledge[] = [];
59
- l(this, "messages", []);
60
- l(this, "_loadingMessages", !1);
61
- l(this, "_loadingMessagesSize", 10);
62
- l(this, "cvforceApi");
63
- l(this, "socket", null);
64
- l(this, "_promptVariables", []);
65
- l(this, "active", !1);
66
- l(this, "_stopAnswer", !1);
67
- l(this, "_dataLoading", !1);
68
- l(this, "_dataLoaded", !1);
69
- var r;
70
- if (this.token = e, this.lazyload = o, this._applicationId = R(e).rid || S.applicationId, this.cvforceApi = this.getService(), this.event.emit("init", {
71
- applicationId: this._applicationId,
72
- sessionId: t
73
- }), t)
74
- this._id = t, this.event.emit("data:loading"), a ? (this.data = a, o || (this._dataLoading = !0, this.cvforceApi.getSession(this.applicationId, t).then((d) => h(this, null, function* () {
75
- this.data = d, this._promptVariables = yield this.cvforceApi.getApplicationIdSessionIdPromptVariables(this.applicationId, t), this.event.emit("data:loaded", this.data), this.event.emit("data:updated", this.data), this._ready = !0, this.event.emit("ready");
76
- })).then(() => h(this, null, function* () {
77
- yield this.fetchMessages(), this._dataLoaded = !0;
78
- })))) : (this._dataLoading = !0, this.cvforceApi.getSession(this.applicationId, t).then((d) => h(this, null, function* () {
79
- this.data = d, this._promptVariables = yield this.cvforceApi.getApplicationIdSessionIdPromptVariables(this.applicationId, t), this.event.emit("data:loaded", this.data), this._ready = !0, this.event.emit("ready");
80
- })).then(() => h(this, null, function* () {
81
- o || (yield this.fetchMessages(), this._dataLoaded = !0);
82
- })));
83
- else {
84
- const d = (a == null ? void 0 : a.name) || "新建会话";
85
- this.event.emit("data:creating", {
86
- applicationId: this._applicationId,
87
- name: d
88
- }), this.event.emit("data:loading"), this.cvforceApi.postSession(this.applicationId, {
89
- name: d,
90
- // @ts-ignore
91
- netOpen: a == null ? void 0 : a.netOpen,
92
- knowledgeList: (r = a == null ? void 0 : a.knowledges) == null ? void 0 : r.map((n) => n.id),
93
- applicationId: this._applicationId
94
- }).then((n) => h(this, null, function* () {
95
- this._id = n.id, this.data = n, this._promptVariables = yield this.cvforceApi.getApplicationIdSessionIdPromptVariables(this.applicationId, this._id), this.event.emit("data:created", this.data), this.event.emit("data:loaded", this.data), this.event.emit("data:updated", this.data), this._ready = !0, this.event.emit("ready");
96
- }));
97
- }
98
- }
99
- get id() {
100
- return this._id;
101
- }
102
- get applicationId() {
103
- return this._applicationId;
104
- }
105
- get ready() {
106
- return this._ready;
107
- }
108
- get frozen() {
109
- return this._frozen;
110
- }
111
- set frozen(e) {
112
- e === !1 && this.inactivating && this.socket && (console.log("[frozen] socket disconnect", this._id), this.socket.disconnect(), this.socket = null, this.event.emit("inactivated")), this._frozen = e, this.event.emit("frozen", e);
113
- }
114
- get knowledges() {
115
- if (!this.data)
116
- throw Error("session data is not loaded");
117
- return this.data.knowledges || [];
118
- }
119
- setKnowledges(e) {
120
- return h(this, null, function* () {
121
- if (!this.data)
122
- throw Error("session data is not loaded");
123
- return yield this.cvforceApi.patchSessionsId(this._applicationId, this.data.id, {
124
- knowledges: e
125
- }), this.data.knowledges = e, this.event.emit("data:updated", this.data), this.event.emit("data:updated:knowledges", {
126
- knowledges: e
127
- }), e;
128
- });
129
- }
130
- get promptVariables() {
131
- return this._promptVariables.filter((e) => e.key !== "query");
132
- }
133
- setPromptVariables(e) {
134
- return h(this, null, function* () {
135
- return yield Promise.all(e.filter((t) => t.key !== "query").map((t) => {
136
- if (!this.data)
137
- throw Error("session data is not loaded");
138
- if (!(!t.id || !t.key))
139
- return this.cvforceApi.patchApplicationIdSessionpromptVariablesId(this._applicationId, this.data.id, t.id, {
140
- value: t.value
141
- });
142
- })), !0;
143
- });
144
- }
145
- getService() {
146
- return P(S.apiRoot, this.token, (e, t) => {
147
- const a = new Error(
148
- "data request error"
149
- /* DataRequestFailed */
150
- // {
151
- // cause: { status, message },
152
- // }
153
- );
154
- u.error(a), this.event.emit("error", a);
155
- });
156
- }
157
- addEventListener(e, t, a = !1) {
158
- if (typeof t != "function")
159
- throw Error("event listener is not a function");
160
- if (a) {
161
- this.event.once(e, t);
162
- return;
163
- }
164
- this.event.on(e, t);
165
- }
166
- removeEventListener(e, t) {
167
- this.event.off(e, t);
168
- }
169
- /**
170
- * 获取对话记录
171
- * @param params ChatHistoryParams
172
- * @returns Promise<false|Message[]>
173
- */
174
- fetchMessages() {
175
- return h(this, arguments, function* (e = {}) {
176
- var a;
177
- const t = {
178
- pageSize: this._loadingMessagesSize
179
- };
180
- if (this._id) {
181
- e = f(f({}, t), e), this.event.emit("history:loading"), u.log("history:loading"), (e.endTime || e.startTime) && (this.event.emit("history:moreloading", e), u.log("history:moreloading", e)), this._loadingMessages = !0;
182
- const o = yield this.cvforceApi.getChatHistorySessionId(this._applicationId, this._id, e), r = o.map((n, i) => {
183
- var I, y;
184
- let p = [], _;
185
- return typeof ((I = n.agentHistoryList) == null ? void 0 : I.agentList) == "string" && (p = JSON.parse(n.agentHistoryList.agentList).reduce((v, g) => (v[g.data.step - 1] || (v[g.data.step - 1] = []), v[g.data.step - 1].push(g), v), [])), i === o.length - 1 && (_ = (y = this.data) == null ? void 0 : y.lastRelatedQuestion), m(f({}, n), {
186
- actions: p,
187
- relatedQuesion: _
188
- });
189
- });
190
- if (!e.endTime && !e.startTime)
191
- this.messages = r;
192
- else if (e.endTime && !e.startTime) {
193
- const n = this.messages.findIndex((i) => i.ts === e.endTime);
194
- this.messages.splice(0, n + 1), this.messages = [...r, ...this.messages];
195
- } else if (!e.endTime && e.startTime) {
196
- const n = this.messages.findLastIndex((i) => i.ts === e.endTime);
197
- this.messages.splice(n, this.messages.length - n - 1), this.messages = [...this.messages, ...r];
198
- } else {
199
- const n = this.messages.findIndex((p) => p.ts === e.endTime), i = this.messages.findLastIndex((p) => p.ts === e.endTime);
200
- this.messages.splice(n, i - n + 1, ...r);
201
- }
202
- const d = this.messages[this.messages.length - 1];
203
- return d && !d.relatedQuesion && (d.relatedQuesion = (a = this.data) == null ? void 0 : a.lastRelatedQuestion), this.event.emit("history:moreloaded", r), u.log("history:loaded", this.messages), this.event.emit("history:loaded", this.messages), this._loadingMessages = !1, r;
204
- } else {
205
- const o = new Error(
206
- "session id is not defined"
207
- /* IdUndefined */
208
- // {
209
- // cause: SESSION_ERROR_CAUSE[SessionErrors.IdUndefined],
210
- // }
211
- );
212
- return u.error(o), this.event.emit("error", o), !1;
213
- }
214
- });
215
- }
216
- rename(e) {
217
- return h(this, null, function* () {
218
- if (!this._id)
219
- throw Error("session is not created yet");
220
- if (e.trim() === "")
221
- throw Error("name is empty");
222
- return this.data = yield this.cvforceApi.patchSessionsId(this.applicationId, this._id, {
223
- name: e
224
- }), this.event.emit("data:updated", this.data), this.event.emit("data:updated:name", {
225
- name: e
226
- }), !0;
227
- });
228
- }
229
- pushMessage(e) {
230
- return h(this, null, function* () {
231
- this.messages.push(e), u.log("history:add", e), this.event.emit("history:add", e), this.event.emit("message:new", e), this.event.emit("message:updated", e);
232
- });
233
- }
234
- reloadSessionInfo() {
235
- if (!this._id)
236
- throw Error("session is not created yet");
237
- return this._dataLoading = !0, this.cvforceApi.getSession(this.applicationId, this._id).then((e) => h(this, null, function* () {
238
- if (this.data = e, !this._id)
239
- throw Error("session is not created yet");
240
- this._promptVariables = yield this.cvforceApi.getApplicationIdSessionIdPromptVariables(this.applicationId, this._id), this.event.emit("data:loaded", this.data), this.event.emit("data:updated", this.data), this._ready = !0, this.event.emit("ready");
241
- })).then(() => h(this, null, function* () {
242
- yield this.fetchMessages(), this._dataLoaded = !0;
243
- }));
244
- }
245
- reload() {
246
- return h(this, null, function* () {
247
- return yield this.reloadSessionInfo(), this.socket ? (this.inactivate(!0), this.activate()) : this.activate();
248
- });
249
- }
250
- delete() {
251
- return h(this, null, function* () {
252
- if (!this.id) {
253
- const e = new Error(
254
- "session id is not defined"
255
- /* IdUndefined */
256
- // {
257
- // cause: SESSION_ERROR_CAUSE[SessionErrors.IdUndefined],
258
- // }
259
- );
260
- return u.error(e), this.event.emit("error", e), !1;
261
- }
262
- return this.event.emit("data:deleting"), yield this.cvforceApi.delSessionsId(this.applicationId, this.id), this.event.emit("data:deleted"), this.destroy();
263
- });
264
- }
265
- activate() {
266
- return h(this, null, function* () {
267
- if (!this._id)
268
- throw Error("session is not avalible. id is undefined");
269
- const e = this._id;
270
- !this._dataLoading && !this._dataLoaded && (this._dataLoading = !0, yield this.cvforceApi.getSession(this.applicationId, e).then((t) => h(this, null, function* () {
271
- this.data = t, this._promptVariables = yield this.cvforceApi.getApplicationIdSessionIdPromptVariables(this.applicationId, e), this.event.emit("data:loaded", this.data), this.event.emit("data:updated", this.data), this._ready = !0, this.event.emit("ready");
272
- })), yield this.fetchMessages(), this._dataLoaded = !0), this.inactivating = !1, this.frozen = !0, yield this.prepareConnection(), this.event.emit("activated", this.socket), this.active = !0;
273
- });
274
- }
275
- inactivate(e = !1) {
276
- return console.log("[inactivate]"), console.log("last message: ", this.messages[this.messages.length - 1]), this.socket ? this._frozen ? (e || (this.inactivating = !0), console.log("this._frozen: ", this._frozen), console.log("immediately: ", e), console.log("inactivating: ", this.inactivating), !0) : (console.log("[inactivate] socket disconnect", this._id), this.socket.close(), this.socket = null, this.event.emit("inactivated"), this.active = !1, !0) : !0;
277
- }
278
- send(a) {
279
- return h(this, arguments, function* (e, t = {
280
- stream: !1
281
- }) {
282
- var y;
283
- const {
284
- stream: o = !1,
285
- referenceFirst: r = !1
286
- } = t, d = e.uuid || k(), n = ((y = e.text) == null ? void 0 : y.trim()) || "", i = e.fileIds;
287
- if (!n && /*!files.length &&*/
288
- !(i != null && i.length)) {
289
- const s = new Error(
290
- "failed at sending empty content"
291
- /* SendingEmptyContent */
292
- // {
293
- // cause: SESSION_ERROR_CAUSE[SessionErrors.SendingEmptyContent],
294
- // }
295
- );
296
- return u.error(s), this.event.emit("error", s), !1;
297
- }
298
- if (!this._id) {
299
- const s = new Error(
300
- "session id is not defined"
301
- /* IdUndefined */
302
- // {
303
- // cause: SESSION_ERROR_CAUSE[SessionErrors.IdUndefined],
304
- // }
305
- );
306
- return u.error(s), this.event.emit("error", s), !1;
307
- }
308
- if (this.frozen) {
309
- const s = new Error(
310
- "session is frozen"
311
- /* Frozen */
312
- // {
313
- // cause: { code: -1, message: 'session is frozen.' },
314
- // }
315
- );
316
- return u.error(s), this.event.emit("error", s), !1;
317
- }
318
- this.frozen = !0, this._stopAnswer = !1;
319
- const p = {
320
- sessionId: this._id,
321
- role: 2,
322
- content: n,
323
- messageId: d,
324
- reference: [],
325
- searchReference: [],
326
- messageTime: ""
327
- }, _ = {
328
- content: n,
329
- stream: o,
330
- requestId: d,
331
- fileIds: i,
332
- referenceFirst: r
333
- };
334
- this.pushMessage(p), this.event.emit("question:content", n);
335
- const I = (s) => h(this, null, function* () {
336
- if (s.role !== w.Robot)
337
- return;
338
- switch (this.removeEventListener("answer:finish", I), this._id && s.content && s.index && s.index < 0 && (this.data = yield this.cvforceApi.patchSessionsId(this.applicationId, this._id, {
339
- finialMessage: s.content
340
- }), this.event.emit("data:updated", this.data), this.event.emit("data:updated:finialMessage", {
341
- finialMessage: s.content
342
- })), yield this.fillMessageReference(s), s.code) {
343
- case 11915:
344
- s.content = "请您换个问题问我吧~", s.index = -1, s.isSensitive = !0, s.isLoading = !1, s.sessionId = this._id || "", this.event.emit("message:error", s);
345
- break;
346
- case 200:
347
- s.index = -1, s.isLoading = !1;
348
- break;
349
- default:
350
- s.content = s.message || "未知错误", s.isLoading = !1, s.index = -1, this.event.emit("message:error", s);
351
- }
352
- const v = yield this.getRelatedQuesion(s);
353
- s = f(f({}, s), v), s.isLoading = !1;
354
- let g = this.messages[this.messages.length - 1];
355
- if (g && g.role === w.Robot) {
356
- const L = f(f({}, g), s);
357
- this.messages[this.messages.length - 1] = L, this.event.emit("message:updated", L);
358
- } else
359
- this.pushMessage(s);
360
- this.frozen = !1;
361
- });
362
- return this.addEventListener("answer:finish", I), this.sendQuestion(_, m(f({}, t), {
363
- stream: o,
364
- referenceFirst: r
365
- })), p;
366
- });
367
- }
368
- getRelatedQuesion(e) {
369
- return h(this, null, function* () {
370
- var r;
371
- if (!e.content || e.isSensitive || e.code !== 200)
372
- return e;
373
- this.event.emit("message:relatedQuesion:loading", e);
374
- const t = yield this.cvforceApi.postGeneques({
375
- content: e.content
376
- }).catch((d) => null);
377
- if (!t) {
378
- const d = [], n = m(f({}, e), {
379
- relatedQuesion: d,
380
- index: -3,
381
- isLoading: !1
382
- });
383
- return this.event.emit("message:relatedQuesion:loaded", {
384
- relatedQuesion: d
385
- }), n;
386
- }
387
- const a = (r = t.content) == null ? void 0 : r.split("*").map(T).map(V).filter((d) => !!d), o = m(f({}, e), {
388
- relatedQuesion: a,
389
- index: -3,
390
- isLoading: !1
391
- });
392
- return this.event.emit("message:relatedQuesion:loaded", o), this._id && this.cvforceApi.patchSessionsId(this._applicationId, this._id, {
393
- lastRelatedQuestion: a
394
- }), o;
395
- });
396
- }
397
- fillMessageReference(e) {
398
- return h(this, null, function* () {
399
- var t;
400
- return (t = e.reference) == null || t.forEach((a, o) => h(this, null, function* () {
401
- const r = yield this.cvforceApi.getKnowledgeIdFileId(a.knowledgeId, a.docId);
402
- e.reference[o] = f(f({}, a), r);
403
- })), e;
404
- });
405
- }
406
- answerAgain() {
407
- return h(this, arguments, function* (e = {
408
- stream: !1
409
- }) {
410
- const t = this.messages[this.messages.length - 1];
411
- if (!t)
412
- throw Error("message list is empty");
413
- this._stopAnswer = !1;
414
- const {
415
- stream: a = !1
416
- } = e;
417
- let o;
418
- t.role !== w.User && (o = e.oldMessageId || t.messageId, this.messages.splice(this.messages.length - 1, 1), this.event.emit("message:remove", t), this.event.emit("history:remove", t));
419
- const r = this.messages[this.messages.length - 1], d = {
420
- content: r.content,
421
- fileIds: r.fileIds,
422
- requestId: r.messageId,
423
- stream: a,
424
- oldMessageId: o
425
- }, n = (i) => h(this, null, function* () {
426
- if (console.log("handleAnswerFinish", i), i.role === w.Robot && i.index === -1) {
427
- switch (this._id && i.content && i.index && i.index < 0 && (this.data = yield this.cvforceApi.patchSessionsId(this.applicationId, this._id, {
428
- finialMessage: i.content
429
- }), this.event.emit("data:updated", this.data), this.event.emit("data:updated:finialMessage", {
430
- finialMessage: i.content
431
- })), yield this.fillMessageReference(i), i.code) {
432
- case 11915:
433
- i.content = "请您换个问题问我吧~", i.index = -1, i.isSensitive = !0, i.isLoading = !1, i.sessionId = this._id || "", this.event.emit("message:error", i);
434
- break;
435
- case 200:
436
- i.index = -1, i.isLoading = !1;
437
- break;
438
- default:
439
- i.content = i.message || "未知错误", i.isLoading = !1, i.index = -1, this.event.emit("message:error", i);
440
- }
441
- const p = yield this.getRelatedQuesion(i);
442
- this.event.emit("message:updated", p), this.removeEventListener("message:content", n);
443
- }
444
- });
445
- this.addEventListener("message:content", n), this.sendQuestion(d, m(f({}, e), {
446
- stream: a
447
- }));
448
- });
449
- }
450
- setTop(e) {
451
- return h(this, null, function* () {
452
- if (!this._id)
453
- throw Error("session is not avalible. id is undefined");
454
- this.data = yield this.cvforceApi.patchSessionsId(this._applicationId, this._id, {
455
- top: e
456
- }), this.event.emit("data:updated", this.data), this.event.emit("data:updated:top", {
457
- top: e
458
- });
459
- });
460
- }
461
- suspend() {
462
- var a;
463
- this.stopAnswer(), this.frozen = !1, this._stopAnswer = !0;
464
- let e = this.messages[this.messages.length - 1];
465
- const t = {
466
- messageId: k(),
467
- isLoading: !1,
468
- index: -2,
469
- messageTime: C(/* @__PURE__ */ new Date()).format("YYYY-MM-DD HH:ss:mm"),
470
- content: "",
471
- role: w.System,
472
- sessionId: "",
473
- reference: [],
474
- searchReference: []
475
- };
476
- if (e && !e.messageId) {
477
- if (e.index === -2)
478
- return;
479
- if (e.actions) {
480
- const o = e.actions[((a = e.actions) == null ? void 0 : a.length) - 1];
481
- if (o) {
482
- const r = o[o.length - 1];
483
- if (r && (r.type === "BEFORE_CALL" || r.type === "FUNCTION_CALL")) {
484
- const {
485
- pluginName: d,
486
- pluginCode: n,
487
- funcCode: i,
488
- funcName: p
489
- } = r.data;
490
- o.push({
491
- data: {
492
- pluginName: d,
493
- pluginCode: n,
494
- funcCode: i,
495
- funcName: p,
496
- step: r.data.step + 1
497
- },
498
- type: "ABORT"
499
- }), this.event.emit("message:action", {
500
- messageId: e.messageId,
501
- action: o
502
- });
503
- }
504
- }
505
- }
506
- e = f(f({}, e), t), this.event.emit("message:content", e), this.event.emit("message:updated", e);
507
- } else
508
- this.pushMessage(t), this.event.emit("message:content", t);
509
- return this;
510
- }
511
- clear() {
512
- if (!this._id)
513
- throw Error("session is not avalible. id is undefined");
514
- return this.cvforceApi.patchApplicationIdSessionsIdContext(this._applicationId, this._id).then(() => (this.event.emit("context:clear"), !0));
515
- }
516
- destroy() {
517
- var e;
518
- return this._ready = !1, this.event.removeAllListeners(), console.log("[destroy] socket disconnect", this._id), (e = this.socket) == null || e.disconnect(), this.socket = null, this.event.emit("destroy", {
519
- applicationId: this._applicationId,
520
- sessionId: this._id
521
- }), this._id || "";
522
- }
523
- }
524
- export {
525
- B as SessionErrors,
526
- te as default
527
- };
@@ -1,4 +0,0 @@
1
- var e = typeof globalThis != "undefined" ? globalThis : typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : {};
2
- export {
3
- e as commonjsGlobal
4
- };
@@ -1,4 +0,0 @@
1
- var r = {};
2
- export {
3
- r as __exports
4
- };
@@ -1,4 +0,0 @@
1
- var s = {};
2
- export {
3
- s as __exports
4
- };
@@ -1,4 +0,0 @@
1
- var e = {};
2
- export {
3
- e as __exports
4
- };
@@ -1,4 +0,0 @@
1
- var o = { exports: {} };
2
- export {
3
- o as __module
4
- };
@@ -1,112 +0,0 @@
1
- var W = Object.defineProperty, j = Object.defineProperties;
2
- var k = Object.getOwnPropertyDescriptors;
3
- var v = Object.getOwnPropertySymbols;
4
- var A = Object.prototype.hasOwnProperty, R = Object.prototype.propertyIsEnumerable;
5
- var I = (t, e, a) => e in t ? W(t, e, { enumerable: !0, configurable: !0, writable: !0, value: a }) : t[e] = a, E = (t, e) => {
6
- for (var a in e || (e = {}))
7
- A.call(e, a) && I(t, a, e[a]);
8
- if (v)
9
- for (var a of v(e))
10
- R.call(e, a) && I(t, a, e[a]);
11
- return t;
12
- }, $ = (t, e) => j(t, k(e));
13
- var q = (t, e) => {
14
- var a = {};
15
- for (var n in t)
16
- A.call(t, n) && e.indexOf(n) < 0 && (a[n] = t[n]);
17
- if (t != null && v)
18
- for (var n of v(t))
19
- e.indexOf(n) < 0 && R.call(t, n) && (a[n] = t[n]);
20
- return a;
21
- };
22
- var B = (t, e, a) => new Promise((n, w) => {
23
- var o = (r) => {
24
- try {
25
- c(a.next(r));
26
- } catch (d) {
27
- w(d);
28
- }
29
- }, i = (r) => {
30
- try {
31
- c(a.throw(r));
32
- } catch (d) {
33
- w(d);
34
- }
35
- }, c = (r) => r.done ? n(r.value) : Promise.resolve(r.value).then(o, i);
36
- c((a = a.apply(t, e)).next());
37
- });
38
- import { getBytes as z, getLines as G, getMessages as H } from "./parse.mjs";
39
- const g = "text/event-stream", J = 1e3, D = "last-event-id";
40
- function X(t, N) {
41
- var u = N, {
42
- signal: e,
43
- headers: a,
44
- onopen: n,
45
- onmessage: w,
46
- onclose: o,
47
- onerror: i,
48
- openWhenHidden: c,
49
- fetch: r
50
- } = u, d = q(u, [
51
- "signal",
52
- "headers",
53
- "onopen",
54
- "onmessage",
55
- "onclose",
56
- "onerror",
57
- "openWhenHidden",
58
- "fetch"
59
- ]);
60
- return new Promise((L, M) => {
61
- const f = E({}, a);
62
- f.accept || (f.accept = g);
63
- let l;
64
- function C() {
65
- l.abort(), document.hidden || b();
66
- }
67
- c || document.addEventListener("visibilitychange", C);
68
- let T = J, y = 0;
69
- function h() {
70
- document.removeEventListener("visibilitychange", C), window.clearTimeout(y), l.abort();
71
- }
72
- e == null || e.addEventListener("abort", () => {
73
- h(), L();
74
- });
75
- const P = r != null ? r : window.fetch, V = n != null ? n : K;
76
- function b() {
77
- return B(this, null, function* () {
78
- var x;
79
- l = new AbortController();
80
- try {
81
- const m = yield P(t, $(E({}, d), {
82
- headers: f,
83
- signal: l.signal
84
- }));
85
- yield V(m), yield z(m.body, G(H((s) => {
86
- s ? f[D] = s : delete f[D];
87
- }, (s) => {
88
- T = s;
89
- }, w))), o == null || o(), h(), L();
90
- } catch (m) {
91
- if (!l.signal.aborted)
92
- try {
93
- const s = (x = i == null ? void 0 : i(m)) != null ? x : T;
94
- window.clearTimeout(y), y = window.setTimeout(b, s);
95
- } catch (s) {
96
- h(), M(s);
97
- }
98
- }
99
- });
100
- }
101
- b();
102
- });
103
- }
104
- function K(t) {
105
- const e = t.headers.get("content-type");
106
- if (!(e != null && e.startsWith(g)))
107
- throw new Error(`Expected content-type to be ${g}, Actual: ${e}`);
108
- }
109
- export {
110
- g as EventStreamContentType,
111
- X as fetchEventSource
112
- };