@glodon-aiot/agent-cli-ui 3.3.2 → 3.3.4-beta.1

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 (58) hide show
  1. package/dist/es/AgentClientUI.mjs +121 -109
  2. package/dist/es/Dialog/AgentChat/HistoryItem/index.mjs +156 -142
  3. package/dist/es/Dialog/AgentChat/PromptSetting/index.mjs +83 -98
  4. package/dist/es/Dialog/AgentChat/index.mjs +330 -313
  5. package/dist/es/Dialog/SessionList/index.mjs +35 -34
  6. package/dist/es/Dialog/index.mjs +101 -94
  7. package/dist/es/ReactTextGenerationUI/components/TextSiders/index.mjs +394 -0
  8. package/dist/es/ReactTextGenerationUI/components/fetchEventSource/fetch.mjs +112 -0
  9. package/dist/es/ReactTextGenerationUI/components/fetchEventSource/parse.mjs +97 -0
  10. package/dist/es/ReactTextGenerationUI/index.mjs +81 -0
  11. package/dist/es/components/FilePreview/index.mjs +26 -25
  12. package/dist/es/index.mjs +402 -217
  13. package/dist/es/node_modules/moment/dist/moment.mjs +2301 -0
  14. package/dist/es/packages/agent-cli-ui/package.json.mjs +162 -0
  15. package/dist/es/packages/react-components/dist/es/components/Markdown/ATag/index.mjs +27 -25
  16. package/dist/es/packages/react-components/dist/es/components/Markdown/Image/index.mjs +29 -27
  17. package/dist/es/packages/react-components/dist/es/components/Markdown/index.mjs +58 -48
  18. package/dist/es/packages/react-components/dist/es/index.mjs +1 -1
  19. package/dist/es/src/style.css +1 -1
  20. package/dist/es/src/style10.css +1 -1
  21. package/dist/es/src/style11.css +1 -1
  22. package/dist/es/src/style12.css +1 -1
  23. package/dist/es/src/style13.css +1 -1
  24. package/dist/es/src/style14.css +1 -1
  25. package/dist/es/src/style15.css +1 -1
  26. package/dist/es/src/style16.css +1 -1
  27. package/dist/es/src/style17.css +1 -1
  28. package/dist/es/src/style18.css +1 -1
  29. package/dist/es/src/style19.css +1 -1
  30. package/dist/es/src/style2.css +1 -1
  31. package/dist/es/src/style20.css +1 -1
  32. package/dist/es/src/style21.css +1 -1
  33. package/dist/es/src/style22.css +1 -1
  34. package/dist/es/src/style23.css +1 -1
  35. package/dist/es/src/style24.css +1 -1
  36. package/dist/es/src/style25.css +1 -1
  37. package/dist/es/src/style26.css +1 -1
  38. package/dist/es/src/style27.css +1 -1
  39. package/dist/es/src/style28.css +1 -1
  40. package/dist/es/src/style29.css +1 -1
  41. package/dist/es/src/style3.css +1 -1
  42. package/dist/es/src/style30.css +1 -0
  43. package/dist/es/src/style31.css +1 -0
  44. package/dist/es/src/style4.css +1 -1
  45. package/dist/es/src/style5.css +1 -1
  46. package/dist/es/src/style6.css +1 -1
  47. package/dist/es/src/style7.css +1 -1
  48. package/dist/es/src/style8.css +1 -1
  49. package/dist/es/src/style9.css +1 -1
  50. package/dist/lib/index.css +1 -1
  51. package/dist/lib/index.js +69 -58
  52. package/dist/src/AgentClientUI.d.ts +10 -2
  53. package/dist/src/Dialog/AgentChat/HistoryItem/index.d.ts +2 -0
  54. package/dist/src/Dialog/SessionList/index.d.ts +1 -0
  55. package/dist/src/Dialog/index.d.ts +9 -1
  56. package/dist/src/index.d.ts +11 -2
  57. package/dist/src/types.d.ts +8 -3
  58. package/package.json +3 -3
package/dist/es/index.mjs CHANGED
@@ -1,128 +1,155 @@
1
- var Z = Object.defineProperty, q = Object.defineProperties;
2
- var ee = Object.getOwnPropertyDescriptors;
3
- var J = Object.getOwnPropertySymbols;
4
- var ie = Object.prototype.hasOwnProperty, te = Object.prototype.propertyIsEnumerable;
5
- var w = (g, i, s) => i in g ? Z(g, i, { enumerable: !0, configurable: !0, writable: !0, value: s }) : g[i] = s, o = (g, i) => {
6
- for (var s in i || (i = {}))
7
- ie.call(i, s) && w(g, s, i[s]);
8
- if (J)
9
- for (var s of J(i))
10
- te.call(i, s) && w(g, s, i[s]);
11
- return g;
12
- }, m = (g, i) => q(g, ee(i));
13
- var a = (g, i, s) => (w(g, typeof i != "symbol" ? i + "" : i, s), s);
14
- import { jsx as Q, Fragment as oe } from "react/jsx-runtime";
15
- import l from "lodash/merge";
16
- import G from "react-dom";
17
- import se from "./AgentClientUI.mjs";
18
- import { notification as K } from "antd";
19
- import ne from "axios";
20
- import { defaultUIConfig as re, defaultApiUrl as he, defaultDovViewerUrl as ae } from "./constant.mjs";
21
- import { ApiUrl as ge } from "./types.mjs";
22
- /* empty css */import { BotClientApi as le } from "@glodon-aiot/apis";
23
- import { JWT as de, isExpired as fe } from "./utils/index.mjs";
24
- const b = {};
25
- class xe {
1
+ var ie = Object.defineProperty, te = Object.defineProperties;
2
+ var se = Object.getOwnPropertyDescriptors;
3
+ var Z = Object.getOwnPropertySymbols;
4
+ var oe = Object.prototype.hasOwnProperty, ne = Object.prototype.propertyIsEnumerable;
5
+ var S = (p, i, n) => i in p ? ie(p, i, { enumerable: !0, configurable: !0, writable: !0, value: n }) : p[i] = n, r = (p, i) => {
6
+ for (var n in i || (i = {}))
7
+ oe.call(i, n) && S(p, n, i[n]);
8
+ if (Z)
9
+ for (var n of Z(i))
10
+ ne.call(i, n) && S(p, n, i[n]);
11
+ return p;
12
+ }, w = (p, i) => te(p, se(i));
13
+ var l = (p, i, n) => (S(p, typeof i != "symbol" ? i + "" : i, n), n);
14
+ var k = (p, i, n) => new Promise((g, f) => {
15
+ var c = (h) => {
16
+ try {
17
+ C(n.next(h));
18
+ } catch (d) {
19
+ f(d);
20
+ }
21
+ }, u = (h) => {
22
+ try {
23
+ C(n.throw(h));
24
+ } catch (d) {
25
+ f(d);
26
+ }
27
+ }, C = (h) => h.done ? g(h.value) : Promise.resolve(h.value).then(c, u);
28
+ C((n = n.apply(p, i)).next());
29
+ });
30
+ import { jsx as U, Fragment as re } from "react/jsx-runtime";
31
+ import ae from "react";
32
+ import b from "lodash/merge";
33
+ import x from "react-dom";
34
+ import he from "./AgentClientUI.mjs";
35
+ import { notification as B } from "antd";
36
+ import ge from "axios";
37
+ import le from "./packages/agent-cli-ui/package.json.mjs";
38
+ import { defaultUIConfig as fe, defaultApiUrl as de, defaultDovViewerUrl as ue } from "./constant.mjs";
39
+ import { ApiUrl as ce } from "./types.mjs";
40
+ /* empty css */import { BotClientApi as pe, ApplicationTypes as q } from "@glodon-aiot/apis";
41
+ import { JWT as me, isExpired as Ce } from "./utils/index.mjs";
42
+ import { configuration as be, configure as ee, BotClient as ve } from "@glodon-aiot/bot-client-sdk";
43
+ import we from "./ReactTextGenerationUI/index.mjs";
44
+ const I = {};
45
+ class Ne {
26
46
  constructor(i) {
27
- a(this, "_token");
28
- a(this, "_activeSession", null);
29
- a(this, "_applicationId");
30
- a(this, "_defaultInputText", "");
31
- a(this, "_inputDisabled", !1);
32
- a(this, "_defatulSessionId", "");
33
- a(this, "apiUrl");
34
- a(this, "docViewerUrl");
35
- a(this, "env", "prod");
36
- a(this, "service");
37
- a(this, "rId", 0);
38
- a(this, "_mode", "float");
39
- a(this, "uiConfig", re);
40
- a(this, "errorHandlers", {});
41
- a(this, "wrapper", document.createElement("div"));
42
- var _, y, x, U, S, B, H, z, L, M, V, A, N, E, F, D, j, T, R, W, $, O, P;
47
+ l(this, "_token");
48
+ l(this, "_activeSession", null);
49
+ l(this, "_applicationId");
50
+ l(this, "_defaultInputText", "");
51
+ l(this, "_inputDisabled", !1);
52
+ l(this, "_defatulSessionId", "");
53
+ l(this, "_agentClientRef", ae.createRef());
54
+ l(this, "apiUrl");
55
+ l(this, "docViewerUrl");
56
+ l(this, "env", "prod");
57
+ l(this, "stream", be.stream);
58
+ l(this, "service");
59
+ l(this, "rId", 0);
60
+ l(this, "_mode", "float");
61
+ l(this, "uiConfig", fe);
62
+ l(this, "errorHandlers", {});
63
+ l(this, "wrapper", document.createElement("div"));
64
+ l(this, "botClient", null);
65
+ var H, z, M, V, E, R, A, N, T, D, j, F, P, W, $, O, J, K, Q, G, X, Y;
43
66
  const {
44
- env: s,
45
- token: d,
67
+ env: n,
68
+ token: g,
46
69
  mode: f = "float",
47
- triggerButton: p,
48
- size: h,
49
- apiUrl: n,
50
- docViewerUrl: t,
51
- errorHandlers: r,
70
+ triggerButton: c,
71
+ size: u,
72
+ apiUrl: C,
73
+ docViewerUrl: h,
74
+ errorHandlers: d,
52
75
  features: e,
53
- sessionId: u,
54
- icon: X,
55
- logo: Y
56
- // greeting,
76
+ sessionId: o,
77
+ icon: t,
78
+ logo: s,
79
+ stream: a
57
80
  } = i;
58
- this.uiConfig.icon = X || this.uiConfig.icon, this.uiConfig.logo = Y || this.uiConfig.logo, (e == null ? void 0 : e.greeting) !== void 0 && (typeof e.greeting == "object" ? this.uiConfig.features = m(o({}, this.uiConfig.features), {
59
- greeting: o(o({}, typeof ((_ = this.uiConfig.features) == null ? void 0 : _.greeting) != "object" ? {} : (y = this.uiConfig.features) == null ? void 0 : y.greeting), e.greeting)
60
- }) : this.uiConfig.features = m(o({}, this.uiConfig.features), {
81
+ this.uiConfig.icon = t || this.uiConfig.icon, this.uiConfig.logo = s || this.uiConfig.logo, (e == null ? void 0 : e.greeting) !== void 0 && (typeof e.greeting == "object" ? this.uiConfig.features = w(r({}, this.uiConfig.features), {
82
+ greeting: r(r({}, typeof ((H = this.uiConfig.features) == null ? void 0 : H.greeting) != "object" ? {} : (z = this.uiConfig.features) == null ? void 0 : z.greeting), e.greeting)
83
+ }) : this.uiConfig.features = w(r({}, this.uiConfig.features), {
61
84
  greeting: e.greeting
62
- })), console.log("this.uiConfig.features?.greeting", (x = this.uiConfig.features) == null ? void 0 : x.greeting), this._token = d, this.rId = 0, this._defatulSessionId = u, this.errorHandlers = o(o({}, this.errorHandlers), r);
63
- const k = {
85
+ })), this._token = g, this.rId = 0, this._defatulSessionId = o, this.errorHandlers = r(r({}, this.errorHandlers), d);
86
+ const m = {
64
87
  sessionOpen: f === "float",
65
88
  sessionList: f === "float"
66
- }, I = (B = (S = (U = e == null ? void 0 : e.botMessageBox) == null ? void 0 : U.footer) == null ? void 0 : S.items) == null ? void 0 : B.find((c) => c.componentName === "AnswerAgain");
67
- (L = (z = (H = e == null ? void 0 : e.botMessageBox) == null ? void 0 : H.footer) == null ? void 0 : z.items) == null || L.find((c) => c.componentName === "Copy");
68
- const C = {
89
+ }, L = (E = (V = (M = e == null ? void 0 : e.botMessageBox) == null ? void 0 : M.footer) == null ? void 0 : V.items) == null ? void 0 : E.find((v) => v.componentName === "AnswerAgain");
90
+ (N = (A = (R = e == null ? void 0 : e.botMessageBox) == null ? void 0 : R.footer) == null ? void 0 : A.items) == null || N.find((v) => v.componentName === "Copy");
91
+ const y = {
69
92
  sessionList: e == null ? void 0 : e.sessionList,
70
93
  sessionOpen: e == null ? void 0 : e.newSession,
71
94
  fileUpload: e == null ? void 0 : e.fileUpload,
72
- userCopy: (M = e == null ? void 0 : e.userMessageBox) == null ? void 0 : M.copy,
73
- userEdit: (V = e == null ? void 0 : e.userMessageBox) == null ? void 0 : V.editAgain,
95
+ userCopy: (T = e == null ? void 0 : e.userMessageBox) == null ? void 0 : T.copy,
96
+ userEdit: (D = e == null ? void 0 : e.userMessageBox) == null ? void 0 : D.editAgain,
74
97
  userPrompt: e == null ? void 0 : e.fileUpload,
75
98
  prompt: e == null ? void 0 : e.prompts,
76
- relate: (A = e == null ? void 0 : e.botMessageBox) == null ? void 0 : A.relatedQuesions,
77
- again: !(I && I.visible === !1),
99
+ relate: (j = e == null ? void 0 : e.botMessageBox) == null ? void 0 : j.relatedQuesions,
100
+ again: !(L && L.visible === !1),
78
101
  reference: {
79
- iconVisible: (E = (N = e == null ? void 0 : e.botMessageBox) == null ? void 0 : N.reference) == null ? void 0 : E.file,
80
- referenceFirst: (F = e == null ? void 0 : e.botMessageBox) == null ? void 0 : F.referenceFirst,
81
- isExpand: (j = (D = e == null ? void 0 : e.botMessageBox) == null ? void 0 : D.reference) == null ? void 0 : j.itemExpanded
102
+ iconVisible: (P = (F = e == null ? void 0 : e.botMessageBox) == null ? void 0 : F.reference) == null ? void 0 : P.file,
103
+ referenceFirst: (W = e == null ? void 0 : e.botMessageBox) == null ? void 0 : W.referenceFirst,
104
+ isExpand: (O = ($ = e == null ? void 0 : e.botMessageBox) == null ? void 0 : $.reference) == null ? void 0 : O.itemExpanded
82
105
  },
83
- searchReference: (T = e == null ? void 0 : e.botMessageBox) == null ? void 0 : T.searchReference,
106
+ searchReference: (J = e == null ? void 0 : e.botMessageBox) == null ? void 0 : J.searchReference,
84
107
  knowledges: !!(e != null && e.knowledges),
85
108
  metadata: e == null ? void 0 : e.metadata,
86
109
  greet: (e == null ? void 0 : e.greeting) !== !1,
87
110
  imageUpload: e == null ? void 0 : e.imageUpload,
88
- promptVariables: (e == null ? void 0 : e.promptVariables) === void 0 ? (R = this.uiConfig.transform) == null ? void 0 : R.promptVariables : (e == null ? void 0 : e.promptVariables) === !0 || typeof (e == null ? void 0 : e.promptVariables) == "object" && ((W = e == null ? void 0 : e.promptVariables) == null ? void 0 : W.visible) !== !1 ? ($ = this.uiConfig.transform) == null ? void 0 : $.promptVariables : !1,
89
- connectNetwork: (e == null ? void 0 : e.connectNetwork) === void 0 ? (O = this.uiConfig.transform) == null ? void 0 : O.connectNetwork : (e == null ? void 0 : e.connectNetwork) === !0 || (typeof (e == null ? void 0 : e.connectNetwork) == "object" && typeof (e == null ? void 0 : e.connectNetwork.visible) == "boolean" ? e == null ? void 0 : e.connectNetwork.visible : (P = this.uiConfig.transform) == null ? void 0 : P.connectNetwork)
90
- }, v = {
111
+ promptVariables: (e == null ? void 0 : e.promptVariables) === void 0 ? (K = this.uiConfig.transform) == null ? void 0 : K.promptVariables : (e == null ? void 0 : e.promptVariables) === !0 || typeof (e == null ? void 0 : e.promptVariables) == "object" && ((Q = e == null ? void 0 : e.promptVariables) == null ? void 0 : Q.visible) !== !1 ? (G = this.uiConfig.transform) == null ? void 0 : G.promptVariables : !1,
112
+ connectNetwork: (e == null ? void 0 : e.connectNetwork) === void 0 ? (X = this.uiConfig.transform) == null ? void 0 : X.connectNetwork : (e == null ? void 0 : e.connectNetwork) === !0 || (typeof (e == null ? void 0 : e.connectNetwork) == "object" && typeof (e == null ? void 0 : e.connectNetwork.visible) == "boolean" ? e == null ? void 0 : e.connectNetwork.visible : (Y = this.uiConfig.transform) == null ? void 0 : Y.connectNetwork)
113
+ }, _ = {
91
114
  sider: f === "inlay"
92
115
  };
93
- if (i.header !== void 0 && (v.showHeader = !!i.header), i.sider !== void 0 && (v.sider = !!i.sider), Object.keys(C).forEach((c) => {
94
- C[c] === void 0 && delete C[c];
116
+ if (i.header !== void 0 && (_.showHeader = !!i.header), i.sider !== void 0 && (_.sider = !!i.sider), Object.keys(y).forEach((v) => {
117
+ y[v] === void 0 && delete y[v];
95
118
  }), f === "inlay") {
96
- const c = {
97
- triggerButton: l({
119
+ const v = {
120
+ triggerButton: b({
98
121
  visible: !1
99
- }, p),
122
+ }, c),
100
123
  open: !0,
101
124
  resizable: !1,
102
- size: l({
125
+ size: b({
103
126
  width: "100%",
104
127
  height: "100%",
105
128
  maxWidth: "100%",
106
129
  maxHeight: "100%",
107
130
  minWidth: "100%"
108
- }, h),
109
- theme: l(this.uiConfig.theme, b),
131
+ }, u),
132
+ theme: b(this.uiConfig.theme, I),
110
133
  history: !0
111
134
  };
112
- this.uiConfig = m(o(o(o(o({}, this.uiConfig), i), c), v), {
113
- transform: o(o(o(o({}, this.uiConfig.transform), k), i.transform), C)
135
+ this.uiConfig = w(r(r(r(r({}, this.uiConfig), i), v), _), {
136
+ transform: r(r(r(r({}, this.uiConfig.transform), m), i.transform), y)
114
137
  }), this.wrapper = this.uiConfig.getContainer();
115
138
  } else {
116
- const c = {
117
- triggerButton: l(this.uiConfig.triggerButton, p),
118
- size: l(this.uiConfig.size, o({}, h)),
119
- theme: l(this.uiConfig.theme, b)
139
+ const v = {
140
+ triggerButton: b(this.uiConfig.triggerButton, c),
141
+ size: b(this.uiConfig.size, r({}, u)),
142
+ theme: b(this.uiConfig.theme, I)
120
143
  };
121
- this.uiConfig = m(o(o(o(o(o({}, this.uiConfig), i), c), v), C), {
122
- transform: o(o(o(o({}, this.uiConfig.transform), k), i.transform), C)
144
+ this.uiConfig = w(r(r(r(r(r({}, this.uiConfig), i), v), _), y), {
145
+ transform: r(r(r(r({}, this.uiConfig.transform), m), i.transform), y)
123
146
  }), this.uiConfig.getContainer().append(this.wrapper);
124
147
  }
125
- this._mode = f, this.env = s || "prod", this._applicationId = de(d).rid, this.apiUrl = n || ge[this.env] || he, this.docViewerUrl = t || ae, this.service = this.setService(), this.render();
148
+ this._mode = f, this.env = n || "prod", this.stream = a, ee({
149
+ stream: this.stream
150
+ }), this._applicationId = me(g).rid, this.apiUrl = C || ce[this.env] || de, this.docViewerUrl = h || ue, this.service = this.setService(), this.createBotClientSDK().then(() => {
151
+ this.render();
152
+ });
126
153
  }
127
154
  get token() {
128
155
  return this._token;
@@ -135,32 +162,32 @@ class xe {
135
162
  }
136
163
  set mode(i) {
137
164
  if (i === "inlay") {
138
- const s = {
139
- triggerButton: l({
165
+ const n = {
166
+ triggerButton: b({
140
167
  visible: !1
141
168
  }, this.uiConfig.triggerButton),
142
169
  open: !0,
143
170
  resizable: !1,
144
- size: l({
171
+ size: b({
145
172
  width: "100%",
146
173
  height: "100%",
147
174
  maxWidth: "100%",
148
175
  maxHeight: "100%",
149
176
  minWidth: "100%"
150
177
  }, this.uiConfig.size),
151
- theme: l(this.uiConfig.theme, b),
178
+ theme: b(this.uiConfig.theme, I),
152
179
  history: !0
153
180
  };
154
- this.uiConfig = o(o({}, this.uiConfig), s), this.wrapper = this.uiConfig.getContainer();
181
+ this.uiConfig = r(r({}, this.uiConfig), n), this.wrapper = this.uiConfig.getContainer();
155
182
  } else {
156
- const s = {
157
- triggerButton: l(this.uiConfig.triggerButton, this.uiConfig.triggerButton),
158
- size: l(this.uiConfig.size, o({}, this.uiConfig.size)),
159
- theme: l(this.uiConfig.theme, b)
183
+ const n = {
184
+ triggerButton: b(this.uiConfig.triggerButton, this.uiConfig.triggerButton),
185
+ size: b(this.uiConfig.size, r({}, this.uiConfig.size)),
186
+ theme: b(this.uiConfig.theme, I)
160
187
  };
161
- this.uiConfig = o(o({}, this.uiConfig), s), this._mode === "inlay" && this.wrapper.remove(), this.uiConfig.getContainer().append(this.wrapper);
188
+ this.uiConfig = r(r({}, this.uiConfig), n), this._mode === "inlay" && this.wrapper.remove(), this.uiConfig.getContainer().append(this.wrapper);
162
189
  }
163
- this._mode = i;
190
+ this._mode = i, this.render();
164
191
  }
165
192
  get activeSession() {
166
193
  return this._activeSession;
@@ -169,35 +196,35 @@ class xe {
169
196
  return this._applicationId;
170
197
  }
171
198
  setService() {
172
- const i = this.apiUrl, s = (t) => {
199
+ const i = this.apiUrl, n = (h) => {
173
200
  var e;
174
- const r = this.token;
175
- if (!r)
176
- return t;
177
- if (fe(r)) {
178
- const u = "token is timeout";
201
+ const d = this.token;
202
+ if (!d)
203
+ return h;
204
+ if (Ce(d)) {
205
+ const o = "token is timeout";
179
206
  this.errorHandlers.token ? typeof this.errorHandlers.token == "function" ? this.errorHandlers.token(
180
207
  // @ts-ignore
181
- new Error(u, {
208
+ new Error(o, {
182
209
  cause: {
183
210
  status: 401,
184
- message: u
211
+ message: o
185
212
  }
186
213
  })
187
- ) : console.error("errorHandlers.token is not a function") : console.error(u);
214
+ ) : console.error("errorHandlers.token is not a function") : console.error(o);
188
215
  }
189
- return t.headers = (e = t.headers) != null ? e : {}, t.headers = m(o({}, t.headers), {
190
- Authorization: r ? `Bearer ${r}` : ""
191
- }), t;
216
+ return h.headers = (e = h.headers) != null ? e : {}, h.headers = w(r({}, h.headers), {
217
+ Authorization: d ? `Bearer ${d}` : ""
218
+ }), h;
192
219
  };
193
- function d(t, r = !0) {
194
- const e = `${i}${t}`, u = ne.create({
220
+ function g(h, d = !0) {
221
+ const e = `${i}${h}`, o = ge.create({
195
222
  baseURL: e
196
223
  });
197
- return r && u.interceptors.request.use(s), u;
224
+ return d && o.interceptors.request.use(n), o;
198
225
  }
199
- const f = (t, r) => {
200
- if (t === 401) {
226
+ const f = (h, d) => {
227
+ if (h === 401) {
201
228
  const e = "token is invalid";
202
229
  this.errorHandlers.token ? typeof this.errorHandlers.token == "function" ? this.errorHandlers.token(
203
230
  // @ts-ignore
@@ -209,16 +236,18 @@ class xe {
209
236
  })
210
237
  ) : console.error("errorHandlers.token is not a function") : console.error(e);
211
238
  }
212
- }, p = (t, r, e) => {
213
- t !== 10001 && t !== 10215 && (e || (K.config({
239
+ }, c = (h, d, e) => {
240
+ h !== 10001 && h !== 10215 && (e || (B.config({
214
241
  getContainer: this.uiConfig.getContainer
215
- }), K.error({
216
- message: r
242
+ }), B.error({
243
+ message: d
244
+ }), B.config({
245
+ getContainer: void 0
217
246
  })));
218
- }, h = d("");
219
- return new le(h, () => this.token, {
247
+ }, u = g("");
248
+ return new pe(u, () => this.token, {
220
249
  onHttpStatusError: f,
221
- onAppStatusError: p
250
+ onAppStatusError: c
222
251
  });
223
252
  }
224
253
  reload() {
@@ -228,8 +257,8 @@ class xe {
228
257
  });
229
258
  }
230
259
  getMessageList(i) {
231
- var s, d;
232
- return i || (i = (s = this.activeSession) == null ? void 0 : s.id), !this.applicationId || !i ? Promise.resolve([]) : (d = this.service) == null ? void 0 : d.getChatHistorySessionId(this.applicationId, i);
260
+ var n, g;
261
+ return i || (i = (n = this.activeSession) == null ? void 0 : n.id), !this.applicationId || !i ? Promise.resolve([]) : (g = this.service) == null ? void 0 : g.getChatHistorySessionId(this.applicationId, i);
233
262
  }
234
263
  input(i) {
235
264
  this._defaultInputText = i, this.render();
@@ -240,108 +269,264 @@ class xe {
240
269
  enable() {
241
270
  this._inputDisabled = !1, this.render();
242
271
  }
272
+ getSessionList() {
273
+ return this._agentClientRef.current ? new Promise((n, g) => {
274
+ var f, c;
275
+ (c = (f = this._agentClientRef.current) == null ? void 0 : f.getSessionList()) == null || c.then((u) => {
276
+ n(u);
277
+ }).catch((u) => {
278
+ g(u);
279
+ });
280
+ }) : Promise.reject(new Error("client is not loaded"));
281
+ }
282
+ sessionCreate(i) {
283
+ return this._agentClientRef.current ? new Promise((g, f) => {
284
+ var c, u;
285
+ (u = (c = this._agentClientRef.current) == null ? void 0 : c.sessionCreate(r({
286
+ name: "新建会话"
287
+ }, i))) == null || u.then((C) => {
288
+ g(C);
289
+ }).catch((C) => {
290
+ f(C);
291
+ });
292
+ }) : Promise.reject(new Error("client is not loaded"));
293
+ }
294
+ createBotClientSDK() {
295
+ return k(this, null, function* () {
296
+ return new Promise((i, n) => {
297
+ if (this.token)
298
+ ee({
299
+ debug: this.uiConfig.debug,
300
+ env: this.uiConfig.env,
301
+ apiRoot: this.apiUrl
302
+ }), this.botClient = new ve(this.token, {
303
+ plugins: this.uiConfig.plugins,
304
+ mcp: this.uiConfig.mcp,
305
+ stream: this.uiConfig.stream
306
+ }, void 0, {
307
+ analytics: {
308
+ enabled: !0
309
+ },
310
+ // 这里记录应用的名称和版本,以便后期数据分析
311
+ ui: {
312
+ name: "bot-client-ui",
313
+ version: le.version
314
+ }
315
+ }), this.botClient.ready ? i(this.botClient) : this.botClient.addEventListener("ready", () => k(this, null, function* () {
316
+ var g;
317
+ this.botClient ? (((g = this.botClient.application) == null ? void 0 : g.type) === q.Text && (this.mode = "inlay"), i(this.botClient)) : n(this.botClient);
318
+ }), !0);
319
+ else
320
+ throw Error("token is required");
321
+ });
322
+ });
323
+ }
243
324
  render() {
244
- var s, d, f, p;
245
- let i = this.wrapper.getBoundingClientRect().height;
246
- this.wrapper.style.height = `${i}px`, G.render(/* @__PURE__ */ Q(se, {
247
- rId: this.rId,
248
- sessionId: this._defatulSessionId,
249
- showHeader: this.uiConfig.showHeader,
250
- apiUrl: this.apiUrl,
251
- env: this.uiConfig.env,
252
- debug: this.uiConfig.debug,
253
- mode: this.mode,
254
- token: this.token,
255
- className: this.mode,
256
- open: this.uiConfig.open,
257
- theme: this.uiConfig.theme,
258
- logo: this.uiConfig.logo,
259
- icon: this.uiConfig.icon,
260
- greeting: this.uiConfig.greeting,
261
- size: this.uiConfig.size,
262
- triggerButton: o({
263
- visible: !0
264
- }, this.uiConfig.triggerButton),
265
- history: this.uiConfig.history,
266
- service: this.service,
267
- docViewerUrl: this.docViewerUrl,
268
- plugins: this.uiConfig.plugins,
269
- mcp: this.uiConfig.mcp,
270
- transform: m(o({}, this.uiConfig.transform), {
271
- knowledges: ((s = this.uiConfig.features) == null ? void 0 : s.knowledges) === !0 || typeof ((d = this.uiConfig.features) == null ? void 0 : d.knowledges) == "object" && ((p = (f = this.uiConfig.features) == null ? void 0 : f.knowledges) == null ? void 0 : p.visible) !== !1
272
- }),
273
- features: this.uiConfig.features,
274
- disabled: this._inputDisabled,
275
- sider: this.uiConfig.sider,
276
- footer: this.uiConfig.footer,
277
- onComment: (h) => {
278
- var n, t;
279
- try {
280
- (t = (n = this.uiConfig.eventListeners) == null ? void 0 : n.comment) == null || t.call(n, h);
281
- } catch (r) {
282
- console.error(r);
283
- }
284
- },
285
- onMessage: (h) => {
286
- var n, t;
287
- if (h.message.messageId)
325
+ return k(this, null, function* () {
326
+ var n, g, f, c, u, C, h, d, e;
327
+ let i = this.wrapper.getBoundingClientRect().height;
328
+ if (this.wrapper.style.height = `${i}px`, !((n = this.botClient) != null && n.application))
329
+ throw Error("application is required");
330
+ this.botClient.application.type === q.Text ? x.render(/* @__PURE__ */ U(we, {
331
+ rId: this.rId,
332
+ application: this.botClient.application,
333
+ sessionId: this._defatulSessionId,
334
+ showHeader: this.uiConfig.showHeader,
335
+ apiUrl: this.apiUrl,
336
+ env: this.uiConfig.env,
337
+ debug: this.uiConfig.debug,
338
+ mode: this.mode,
339
+ token: this.token,
340
+ className: this.mode,
341
+ open: this.uiConfig.open,
342
+ logo: this.uiConfig.logo,
343
+ icon: this.uiConfig.icon,
344
+ theme: this.uiConfig.theme,
345
+ greeting: this.uiConfig.greeting,
346
+ size: this.uiConfig.size,
347
+ triggerButton: r({
348
+ visible: !0
349
+ }, this.uiConfig.triggerButton),
350
+ history: this.uiConfig.history,
351
+ service: this.service,
352
+ docViewerUrl: this.docViewerUrl,
353
+ plugins: this.uiConfig.plugins,
354
+ mcp: this.uiConfig.mcp,
355
+ transform: w(r({}, this.uiConfig.transform), {
356
+ knowledges: ((g = this.uiConfig.features) == null ? void 0 : g.knowledges) === !0 || typeof ((f = this.uiConfig.features) == null ? void 0 : f.knowledges) == "object" && ((u = (c = this.uiConfig.features) == null ? void 0 : c.knowledges) == null ? void 0 : u.visible) !== !1
357
+ }),
358
+ features: this.uiConfig.features,
359
+ disabled: this._inputDisabled,
360
+ sider: this.uiConfig.sider,
361
+ footer: this.uiConfig.footer,
362
+ onComment: (o) => {
363
+ var t, s;
288
364
  try {
289
- (t = (n = this.uiConfig.eventListeners) == null ? void 0 : n.message) == null || t.call(n, h);
290
- } catch (r) {
291
- console.error(r);
365
+ (s = (t = this.uiConfig.eventListeners) == null ? void 0 : t.comment) == null || s.call(t, o);
366
+ } catch (a) {
367
+ console.error(a);
292
368
  }
293
- },
294
- beforeMessageSend: (h) => {
295
- var n, t, r;
296
- if (!((n = this.uiConfig.eventListeners) != null && n.beforemessagesend))
297
- return !0;
298
- try {
299
- return ((r = (t = this.uiConfig.eventListeners) == null ? void 0 : t.beforemessagesend) == null ? void 0 : r.call(t, h)) || !1;
300
- } catch (e) {
301
- return console.error(e), !1;
302
- }
303
- },
304
- onSessionUnload: (h) => {
305
- var n, t;
306
- this._activeSession = null;
307
- try {
308
- (t = (n = this.uiConfig.eventListeners) == null ? void 0 : n.sessionunload) == null || t.call(n, h);
309
- } catch (r) {
310
- console.error(r);
311
- }
312
- },
313
- onSessionLoad: (h) => {
314
- var n, t, r;
315
- if (((n = this._activeSession) == null ? void 0 : n.id) === h.sessionId)
316
- this._activeSession = h.session;
317
- else {
318
- this._activeSession = h.session;
369
+ },
370
+ agentClient: this.botClient,
371
+ onMessage: (o) => {
372
+ var t, s;
373
+ if (o.message.messageId)
374
+ try {
375
+ (s = (t = this.uiConfig.eventListeners) == null ? void 0 : t.message) == null || s.call(t, o);
376
+ } catch (a) {
377
+ console.error(a);
378
+ }
379
+ },
380
+ beforeMessageSend: (o) => {
381
+ var t, s, a;
382
+ if (!((t = this.uiConfig.eventListeners) != null && t.beforemessagesend))
383
+ return !0;
319
384
  try {
320
- (r = (t = this.uiConfig.eventListeners) == null ? void 0 : t.sessionload) == null || r.call(t, h);
321
- } catch (e) {
322
- console.error(e);
385
+ return ((a = (s = this.uiConfig.eventListeners) == null ? void 0 : s.beforemessagesend) == null ? void 0 : a.call(s, o)) || !1;
386
+ } catch (m) {
387
+ return console.error(m), !1;
323
388
  }
324
- }
325
- },
326
- onHistoryLoad: (h) => {
327
- var n, t, r;
328
- if (((n = this._activeSession) == null ? void 0 : n.id) === h.sessionId)
389
+ },
390
+ onSessionUnload: (o) => {
391
+ var t, s;
392
+ this._activeSession = null;
329
393
  try {
330
- (r = (t = this.uiConfig.eventListeners) == null ? void 0 : t.historyload) == null || r.call(t, h);
331
- } catch (e) {
332
- console.error(e);
394
+ (s = (t = this.uiConfig.eventListeners) == null ? void 0 : t.sessionunload) == null || s.call(t, o);
395
+ } catch (a) {
396
+ console.error(a);
333
397
  }
334
- },
335
- defaultInput: this._defaultInputText !== void 0 ? {
336
- text: this._defaultInputText
337
- } : void 0,
338
- bodyStyle: this.uiConfig.bodyStyle
339
- }), this.wrapper), this._defaultInputText = "";
398
+ },
399
+ onSessionLoad: (o) => {
400
+ var t, s, a;
401
+ if (((t = this._activeSession) == null ? void 0 : t.id) === o.sessionId)
402
+ this._activeSession = o.session;
403
+ else {
404
+ this._activeSession = o.session;
405
+ try {
406
+ (a = (s = this.uiConfig.eventListeners) == null ? void 0 : s.sessionload) == null || a.call(s, o);
407
+ } catch (m) {
408
+ console.error(m);
409
+ }
410
+ }
411
+ },
412
+ onHistoryLoad: (o) => {
413
+ var t, s, a;
414
+ if (((t = this._activeSession) == null ? void 0 : t.id) === o.sessionId)
415
+ try {
416
+ (a = (s = this.uiConfig.eventListeners) == null ? void 0 : s.historyload) == null || a.call(s, o);
417
+ } catch (m) {
418
+ console.error(m);
419
+ }
420
+ },
421
+ defaultInput: this._defaultInputText !== void 0 ? {
422
+ text: this._defaultInputText
423
+ } : void 0,
424
+ bodyStyle: this.uiConfig.bodyStyle,
425
+ stream: this.stream
426
+ }), this.wrapper) : x.render(/* @__PURE__ */ U(he, {
427
+ ref: this._agentClientRef,
428
+ rId: this.rId,
429
+ application: this.botClient.application,
430
+ agentClient: this.botClient,
431
+ sessionId: this._defatulSessionId,
432
+ showHeader: this.uiConfig.showHeader,
433
+ apiUrl: this.apiUrl,
434
+ env: this.uiConfig.env,
435
+ debug: this.uiConfig.debug,
436
+ mode: this.mode,
437
+ token: this.token,
438
+ className: this.mode,
439
+ open: this.uiConfig.open,
440
+ logo: this.uiConfig.logo,
441
+ icon: this.uiConfig.icon,
442
+ theme: this.uiConfig.theme,
443
+ greeting: this.uiConfig.greeting,
444
+ size: this.uiConfig.size,
445
+ triggerButton: r({
446
+ visible: !0
447
+ }, this.uiConfig.triggerButton),
448
+ history: this.uiConfig.history,
449
+ service: this.service,
450
+ docViewerUrl: this.docViewerUrl,
451
+ plugins: this.uiConfig.plugins,
452
+ mcp: this.uiConfig.mcp,
453
+ transform: w(r({}, this.uiConfig.transform), {
454
+ knowledges: ((C = this.uiConfig.features) == null ? void 0 : C.knowledges) === !0 || typeof ((h = this.uiConfig.features) == null ? void 0 : h.knowledges) == "object" && ((e = (d = this.uiConfig.features) == null ? void 0 : d.knowledges) == null ? void 0 : e.visible) !== !1
455
+ }),
456
+ features: this.uiConfig.features,
457
+ disabled: this._inputDisabled,
458
+ sider: this.uiConfig.sider,
459
+ footer: this.uiConfig.footer,
460
+ onComment: (o) => {
461
+ var t, s;
462
+ try {
463
+ (s = (t = this.uiConfig.eventListeners) == null ? void 0 : t.comment) == null || s.call(t, o);
464
+ } catch (a) {
465
+ console.error(a);
466
+ }
467
+ },
468
+ onMessage: (o) => {
469
+ var t, s;
470
+ if (o.message.messageId)
471
+ try {
472
+ (s = (t = this.uiConfig.eventListeners) == null ? void 0 : t.message) == null || s.call(t, o);
473
+ } catch (a) {
474
+ console.error(a);
475
+ }
476
+ },
477
+ beforeMessageSend: (o) => {
478
+ var t, s, a;
479
+ if (!((t = this.uiConfig.eventListeners) != null && t.beforemessagesend))
480
+ return !0;
481
+ try {
482
+ return ((a = (s = this.uiConfig.eventListeners) == null ? void 0 : s.beforemessagesend) == null ? void 0 : a.call(s, o)) || !1;
483
+ } catch (m) {
484
+ return console.error(m), !1;
485
+ }
486
+ },
487
+ onSessionUnload: (o) => {
488
+ var t, s;
489
+ this._activeSession = null;
490
+ try {
491
+ (s = (t = this.uiConfig.eventListeners) == null ? void 0 : t.sessionunload) == null || s.call(t, o);
492
+ } catch (a) {
493
+ console.error(a);
494
+ }
495
+ },
496
+ onSessionLoad: (o) => {
497
+ var t, s, a;
498
+ if (((t = this._activeSession) == null ? void 0 : t.id) === o.sessionId)
499
+ this._activeSession = o.session;
500
+ else {
501
+ this._activeSession = o.session;
502
+ try {
503
+ (a = (s = this.uiConfig.eventListeners) == null ? void 0 : s.sessionload) == null || a.call(s, o);
504
+ } catch (m) {
505
+ console.error(m);
506
+ }
507
+ }
508
+ },
509
+ onHistoryLoad: (o) => {
510
+ var t, s, a;
511
+ if (((t = this._activeSession) == null ? void 0 : t.id) === o.sessionId)
512
+ try {
513
+ (a = (s = this.uiConfig.eventListeners) == null ? void 0 : s.historyload) == null || a.call(s, o);
514
+ } catch (m) {
515
+ console.error(m);
516
+ }
517
+ },
518
+ defaultInput: this._defaultInputText !== void 0 ? {
519
+ text: this._defaultInputText
520
+ } : void 0,
521
+ bodyStyle: this.uiConfig.bodyStyle,
522
+ stream: this.stream
523
+ }), this.wrapper), this._defaultInputText = "";
524
+ });
340
525
  }
341
526
  destroy(i) {
342
- G.render(/* @__PURE__ */ Q(oe, {}), this.wrapper, i);
527
+ x.render(/* @__PURE__ */ U(re, {}), this.wrapper, i);
343
528
  }
344
529
  }
345
530
  export {
346
- xe as default
531
+ Ne as default
347
532
  };