@core-pilot/sdk 0.0.0-beta.9 → 0.1.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.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createApp, createVNode, defineComponent, onBeforeUnmount, ref, watch } from "vue";
1
+ import { createApp, createVNode, defineComponent, onBeforeUnmount, ref, useTemplateRef, watch } from "vue";
2
2
  import { BubbleList, EditorSender } from "@core-pilot/client-vue";
3
3
  import { fetchEventSource } from "@microsoft/fetch-event-source";
4
4
  import axios from "axios";
@@ -13,153 +13,193 @@ function formatArgs(e) {
13
13
  }
14
14
  }).join(" ");
15
15
  }
16
- function createLogger(e, s, c) {
17
- let l = "[CorePilot]", u = [], d = null, f = c?.batchSize ?? 20, p = c?.flushInterval ?? 15e3, m = () => {
18
- if (!c || u.length === 0) return;
19
- let s = [...u];
20
- u = [], e && console.log(`${l} Uploading ${s.length} log(s) to ${c.url}`);
21
- let d = JSON.stringify(s);
22
- navigator.sendBeacon ? navigator.sendBeacon(c.url, d) : fetch(c.url, {
16
+ function createLogger(e, o, s) {
17
+ let c = "[CorePilot]", l = [], u = null, d = s?.batchSize ?? 20, f = s?.flushInterval ?? 15e3, p = () => {
18
+ if (!s || l.length === 0) return;
19
+ let o = [...l];
20
+ l = [], e && console.log(`${c} Uploading ${o.length} log(s) to ${s.url}`);
21
+ let u = JSON.stringify(o);
22
+ navigator.sendBeacon ? navigator.sendBeacon(s.url, u) : fetch(s.url, {
23
23
  method: "POST",
24
- body: d,
24
+ body: u,
25
25
  headers: { "Content-Type": "application/json" },
26
26
  keepalive: !0
27
- }).catch((c) => {
28
- e && (console.error(`${l} Log upload failed:`, c), u.unshift(...s));
27
+ }).catch((s) => {
28
+ e && (console.error(`${c} Log upload failed:`, s), l.unshift(...o));
29
29
  });
30
- }, h = (e, ...l) => {
31
- c && (u.push({
30
+ }, m = (e, ...c) => {
31
+ s && (l.push({
32
32
  level: e,
33
33
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
34
- message: formatArgs(l),
35
- appId: s
36
- }), u.length >= f && (d && clearTimeout(d), m(), d = window.setTimeout(m, p)));
34
+ message: formatArgs(c),
35
+ appId: o
36
+ }), l.length >= d && (u && clearTimeout(u), p(), u = window.setTimeout(p, f)));
37
37
  };
38
- return c && (d = window.setTimeout(m, p)), {
39
- log(...s) {
40
- e && console.log(l, ...s), h("log", ...s);
38
+ return s && (u = window.setTimeout(p, f)), {
39
+ log(...o) {
40
+ e && console.log(c, ...o), m("log", ...o);
41
41
  },
42
- error(...s) {
43
- e && console.error(l, ...s), h("error", ...s);
42
+ error(...o) {
43
+ e && console.error(c, ...o), m("error", ...o);
44
44
  },
45
45
  destroy() {
46
- d && clearTimeout(d), m();
46
+ u && clearTimeout(u), p();
47
47
  }
48
48
  };
49
49
  }
50
- function createAuthManager(e, s) {
51
- let c = "";
52
- return { async getToken() {
53
- if (e.mode === "client") {
54
- if (!e.token) throw Error("AuthManager: Missing token in client mode");
55
- return c = e.token, c;
50
+ function createAuthManager(e, o) {
51
+ let s = e.token || "", c = null;
52
+ return {
53
+ async getToken() {
54
+ if (!s) throw Error("AuthManager: Missing token");
55
+ return s;
56
+ },
57
+ async setToken(e) {
58
+ return e ? (s = e, c && c(), !0) : !1;
59
+ },
60
+ onTokenRefreshed(e) {
61
+ c = e;
62
+ },
63
+ isServerMode() {
64
+ return e.mode === "server";
65
+ },
66
+ getAppId() {
67
+ if (!o) throw Error("AuthManager: Missing appId");
68
+ return o;
56
69
  }
57
- if (e.mode === "server") return c ||= await new Promise((e) => setTimeout(() => {
58
- e("9269ca5c-5b35-46de-915f-b2e3ff41da13");
59
- }, 1e3)), c;
60
- throw Error("AuthManager: Invalid configuration or missing token.");
61
- } };
70
+ };
62
71
  }
63
72
  var createStoreImpl = (e) => {
64
- let s, c = /* @__PURE__ */ new Set(), l = (e, l) => {
65
- let u = typeof e == "function" ? e(s) : e;
66
- if (!Object.is(u, s)) {
67
- let e = s;
68
- s = l ?? (typeof u != "object" || !u) ? u : Object.assign({}, s, u), c.forEach((c) => c(s, e));
73
+ let o, s = /* @__PURE__ */ new Set(), c = (e, c) => {
74
+ let l = typeof e == "function" ? e(o) : e;
75
+ if (!Object.is(l, o)) {
76
+ let e = o;
77
+ o = c ?? (typeof l != "object" || !l) ? l : Object.assign({}, o, l), s.forEach((s) => s(o, e));
69
78
  }
70
- }, u = () => s, d = {
71
- setState: l,
72
- getState: u,
73
- getInitialState: () => f,
74
- subscribe: (e) => (c.add(e), () => c.delete(e))
75
- }, f = s = e(l, u, d);
76
- return d;
79
+ }, l = () => o, u = {
80
+ setState: c,
81
+ getState: l,
82
+ getInitialState: () => d,
83
+ subscribe: (e) => (s.add(e), () => s.delete(e))
84
+ }, d = o = e(c, l, u);
85
+ return u;
77
86
  };
78
87
  const pilotStore = ((e) => e ? createStoreImpl(e) : createStoreImpl)((e) => ({
79
88
  currentMessage: void 0,
80
89
  isLoading: !1,
81
90
  messageHistory: [],
82
91
  activeScence: "ANC",
83
- setActiveScence: (s) => e({ activeScence: s }),
84
- updateMessage: (s) => e((e) => {
85
- let c = {
86
- ...s,
92
+ pendingRetryRequest: null,
93
+ setActiveScence: (o) => e({ activeScence: o }),
94
+ updateMessage: (o) => e((e) => {
95
+ let s = {
96
+ ...o,
87
97
  role: "ai",
88
98
  showActions: !1,
89
99
  maxWidth: "100%"
90
- }, l = [...e.messageHistory];
91
- if (l.forEach((e) => {
100
+ }, c = [...e.messageHistory];
101
+ if (c.forEach((e) => {
92
102
  e.isHistoryMessage = !0;
93
103
  }), e.currentMessage) {
94
- let u = {
95
- ...c,
96
- content: e.currentMessage.content + (s.content || "")
104
+ let l = {
105
+ ...s,
106
+ content: e.currentMessage.content + (o.content || "")
97
107
  };
98
- return l.pop(), l.push(u), {
99
- currentMessage: u,
100
- messageHistory: l
108
+ return c.pop(), c.push(l), {
109
+ currentMessage: l,
110
+ messageHistory: c
101
111
  };
102
112
  }
103
- return l.push(c), {
104
- currentMessage: c,
105
- messageHistory: l
113
+ return c.push(s), {
114
+ currentMessage: s,
115
+ messageHistory: c
106
116
  };
107
117
  }),
108
- setLoading: (s) => e({ isLoading: s }),
118
+ setLoading: (o) => e({ isLoading: o }),
109
119
  resetCurrentMessage: () => e({ currentMessage: void 0 }),
110
- resetMessageHistory: (s) => e({ messageHistory: s || [] }),
111
- updateMessageHistory: (s) => e((e) => {
112
- let c = [...e.messageHistory];
113
- return c.forEach((e) => {
114
- e.isHistoryMessage = !0;
115
- }), Array.isArray(s) ? { messageHistory: [...c, ...s] } : { messageHistory: [...c, s] };
116
- })
120
+ resetMessageHistory: (o) => e({ messageHistory: o || [] }),
121
+ resetQuestions: () => e((e) => {
122
+ let o = [...e.messageHistory];
123
+ return o.forEach((e) => {
124
+ e.questions = [];
125
+ }), { messageHistory: o };
126
+ }),
127
+ updateMessageHistory: (o) => e((e) => {
128
+ let s = [...e.messageHistory];
129
+ return s.forEach((e) => {
130
+ e.isHistoryMessage = !0, e.questions = [];
131
+ }), Array.isArray(o) ? { messageHistory: [...s, ...o] } : { messageHistory: [...s, o] };
132
+ }),
133
+ updateSuggestionQuestions: (o) => e((e) => {
134
+ let s = [...e.messageHistory];
135
+ return s[s.length - 1].questions = o, { messageHistory: s };
136
+ }),
137
+ setPendingRetryRequest: (o) => {
138
+ e({ pendingRetryRequest: o });
139
+ },
140
+ clearPendingRetryRequest: () => {
141
+ e({ pendingRetryRequest: null });
142
+ }
117
143
  }));
118
- var MAX_RETRY_TIME = 0, EventStreamContentType = "text/event-stream", FatalError = class extends Error {
144
+ var MAX_RETRY_TIME = 0, FatalError = class extends Error {
119
145
  constructor(e) {
120
146
  super(e), this.name = "FatalError";
121
147
  }
122
148
  };
123
- const sseRequester = function(e, s) {
124
- let { url: c, config: l = {} } = e, u = new AbortController();
125
- function d() {
126
- s.onCancel(pilotStore.getState().currentMessage, u), pilotStore.getState().setLoading(!1), pilotStore.getState().resetCurrentMessage();
149
+ const sseRequester = function(e, o, s) {
150
+ let { url: c, config: l = {} } = e, u = new AbortController(), d = !1, f = !1;
151
+ function p() {
152
+ u.abort(), o.onCancel(pilotStore.getState().currentMessage, u), pilotStore.getState().setLoading(!1), pilotStore.getState().resetCurrentMessage();
127
153
  }
128
- function f(e) {
129
- let c = s.onMessage(e);
130
- c.event === "message" && pilotStore.getState().updateMessage({
131
- taskId: c.task_id,
132
- messageId: c.message_id,
133
- conversationId: c.conversation_id,
134
- role: "ai",
135
- content: c.answer
136
- });
154
+ function h(e) {
155
+ try {
156
+ let s = o.onMessage(e);
157
+ if (!s) return;
158
+ s.event === "message" && (pilotStore.getState().updateMessage({
159
+ taskId: s.task_id,
160
+ messageId: s.message_id,
161
+ conversationId: s.conversation_id,
162
+ role: "ai",
163
+ content: s.answer
164
+ }), pilotStore.getState().resetQuestions());
165
+ } catch (e) {
166
+ throw _(), e;
167
+ }
137
168
  }
138
- function p() {
139
- pilotStore.getState().setLoading(!0), s.onOpen();
169
+ async function g(e) {
170
+ try {
171
+ await o.onOpen(e), pilotStore.getState().setLoading(!0);
172
+ } catch (o) {
173
+ throw (e.status === 500 || o instanceof Error && o.message === "Token expired") && await _(), o;
174
+ }
175
+ }
176
+ async function _() {
177
+ d || (d = !0, pilotStore.getState().setLoading(!1), await o.onClose());
140
178
  }
141
- function h() {
142
- pilotStore.getState().setLoading(!1), pilotStore.getState().resetCurrentMessage(), s.onClose();
179
+ async function v(e) {
180
+ f || (f = !0, d || await o.onError(e));
143
181
  }
144
- let g = Math.max(MAX_RETRY_TIME - 1, 0);
145
- return fetchEventSource(c, {
182
+ let y = MAX_RETRY_TIME, S = {
146
183
  ...l,
147
184
  signal: u.signal,
148
185
  openWhenHidden: !0,
149
- onmessage: f,
150
- onclose: h,
186
+ onmessage: h,
187
+ onclose: async () => await _(),
151
188
  onopen: async (e) => {
152
- let s = e.headers.get("content-type");
153
- if (!s || !s.includes(EventStreamContentType)) throw Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${s}`);
154
- p();
189
+ await g(e);
155
190
  },
156
191
  onerror: (e) => {
157
- if (g--, g < 0 && (h(), e instanceof TypeError)) throw new FatalError(e.message);
158
- s.onError(e);
192
+ if (e instanceof FatalError) throw _(), e;
193
+ if (y--, y < 0) {
194
+ if (_(), e instanceof TypeError) throw new FatalError(e.message);
195
+ return;
196
+ }
197
+ v(e);
159
198
  }
160
- }).catch((e) => {
161
- h(), s.onError(e);
162
- }), { cancel: d };
199
+ };
200
+ return s?.fetchFn && (S.fetch = s.fetchFn), fetchEventSource(c, S).catch((e) => {
201
+ _(), v(e);
202
+ }), { cancel: p };
163
203
  }, CorePilotHost = /* @__PURE__ */ defineComponent({
164
204
  props: {
165
205
  adapter: {
@@ -177,82 +217,133 @@ const sseRequester = function(e, s) {
177
217
  provider: {
178
218
  type: Object,
179
219
  required: !0
220
+ },
221
+ authManager: {
222
+ type: Object,
223
+ required: !0
224
+ },
225
+ appId: {
226
+ type: String,
227
+ required: !0
180
228
  }
181
229
  },
182
230
  setup(e) {
183
- let s = ref([]), c = ref([]), f = ref(!1), p = ref(), m = ref("ANC"), h = ref(), g = pilotStore.subscribe((e) => {
184
- let { isLoading: s, messageHistory: l } = e;
185
- c.value = l, f.value = s, m.value = e.activeScence;
231
+ let o = useTemplateRef("bubbleList"), s = ref([]), f = ref([]), p = ref(!1), m = ref(), h = ref("ANC"), g = ref(), _ = ref("");
232
+ watch(() => e.authManager, async (e) => {
233
+ _.value = await e.getToken();
234
+ }, { immediate: !0 });
235
+ let v = pilotStore.subscribe((e) => {
236
+ let { isLoading: o, messageHistory: s } = e;
237
+ f.value = s, p.value = o, h.value = e.activeScence;
186
238
  });
187
- return watch(() => f.value, (e) => {
188
- e && (h.value = void 0);
189
- }), watch(() => h.value, (s, l) => {
190
- s && c.value[c.value.length - 1]?.role === "ai" && e.hitlManager.submit({ hitlData: {
239
+ watch(() => p.value, (o) => {
240
+ o && (g.value = void 0, e.hitlManager.submit({ hitlData: {
241
+ action: "cust_ai_output_start",
242
+ payload: {}
243
+ } }));
244
+ }), watch(() => g.value, (o, s) => {
245
+ o && f.value[f.value.length - 1]?.role === "ai" && e.hitlManager.submit({ hitlData: {
191
246
  action: "cust_ai_output_finish",
192
247
  payload: {
193
- refConfig: h.value,
194
- conversationId: c.value[c.value.length - 1]?.conversationId
248
+ refConfig: g.value,
249
+ conversationId: f.value[f.value.length - 1]?.conversationId,
250
+ messageId: [...f.value].reverse().find((e) => e.messageId)?.messageId
195
251
  }
196
252
  } });
197
- }), onBeforeUnmount(() => {
198
- g?.();
253
+ });
254
+ let y = async (o, s = !1) => {
255
+ let c = {
256
+ messageId: void 0,
257
+ content: o.text,
258
+ role: "user",
259
+ placement: "end",
260
+ showActions: !1,
261
+ maxWidth: "100%"
262
+ };
263
+ C();
264
+ let l = f.value[f.value.length - 1];
265
+ s || (pilotStore.getState().updateMessageHistory([c]), pilotStore.getState().setPendingRetryRequest({
266
+ type: "submit_message",
267
+ payload: {
268
+ text: o.text,
269
+ inputs: { scence: h.value },
270
+ file: o.file?.[0]
271
+ }
272
+ })), pilotStore.getState().resetCurrentMessage();
273
+ let u = await e.adapter.formatRequest({
274
+ text: o.text,
275
+ prevMessage: l,
276
+ inputs: { scence: h.value },
277
+ files: o.file
278
+ }), d = e.authManager.isServerMode() ? e.adapter.createSseFetch?.() : void 0;
279
+ m.value = sseRequester(u, e.adapter, {
280
+ fetchFn: d,
281
+ isRetry: s
282
+ }).cancel;
283
+ }, b = () => {
284
+ e.logger.log("Cancel handler called"), m.value?.(), pilotStore.getState().resetCurrentMessage();
285
+ }, x = async (o, s) => {
286
+ pilotStore.getState().resetCurrentMessage(), pilotStore.getState().updateMessageHistory([]), C(), await e.hitlManager.submit({
287
+ hitlData: o,
288
+ prevMessage: s,
289
+ inputs: { scence: h.value }
290
+ });
291
+ }, C = () => {
292
+ o.value?.scrollToBottom();
293
+ };
294
+ return onBeforeUnmount(() => {
295
+ v?.();
199
296
  }), {
200
- messages: c,
201
- isLoading: f,
202
- handleSendMessage: async (s) => {
203
- let l = {
204
- messageId: void 0,
205
- content: s.text,
206
- role: "user",
207
- placement: "end",
208
- showActions: !1,
209
- maxWidth: "100%"
210
- }, u = c.value[c.value.length - 1];
211
- pilotStore.getState().updateMessageHistory([l]), pilotStore.getState().resetCurrentMessage(), p.value = sseRequester(await e.adapter.formatReuqest({
212
- text: s.text,
213
- prevMessage: u,
214
- inputs: { scence: m.value }
215
- }), e.adapter).cancel;
216
- },
217
- cancelHandler: () => {
218
- e.logger.log("Cancel handler called"), p.value?.(), pilotStore.getState().resetCurrentMessage();
219
- },
220
- handleScenceChange: (s) => {
297
+ messages: f,
298
+ isLoading: p,
299
+ authToken: _,
300
+ activeScence: h,
301
+ tagList: s,
302
+ handleSendMessage: y,
303
+ cancelHandler: b,
304
+ handleScenceChange: (o) => {
221
305
  e.hitlManager.submit({ hitlData: {
222
306
  action: "cust_scence_change",
223
- payload: { scence: s.id }
307
+ payload: { scence: o.id }
224
308
  } });
225
309
  },
226
- tagList: s,
227
- coreSubmit: async (s, c) => {
228
- pilotStore.getState().resetCurrentMessage(), await e.hitlManager.submit({
229
- hitlData: s,
230
- prevMessage: c,
231
- inputs: { scence: m.value }
232
- });
233
- },
310
+ coreSubmit: x,
234
311
  handleRefConfigUpdate: (e) => {
235
- h.value = e;
312
+ g.value = e;
236
313
  },
237
- activeScence: m,
238
314
  handleSceneUpdate: (e) => {
239
315
  pilotStore.getState().setActiveScence(e);
316
+ },
317
+ handleQuestionClick: (e) => {
318
+ y({
319
+ text: e,
320
+ file: []
321
+ });
240
322
  }
241
323
  };
242
324
  },
243
325
  render() {
244
326
  return createVNode("div", { class: "core-pilot-host" }, [createVNode(BubbleList, {
327
+ ref: "bubbleList",
245
328
  class: "bubble-list",
246
329
  list: this.messages,
247
330
  maxHeight: "100%",
331
+ user: this.provider.extensions.user,
332
+ authToken: this.authManager.getToken(),
333
+ appId: this.appId,
248
334
  btnLoading: this.isLoading,
249
335
  onCoreSubmit: this.coreSubmit,
250
- onRefConfigUpdate: this.handleRefConfigUpdate
336
+ onRefConfigUpdate: this.handleRefConfigUpdate,
337
+ onQuestionClick: this.handleQuestionClick
251
338
  }, null), createVNode(EditorSender, {
252
339
  tagList: this.tagList,
253
340
  loading: this.isLoading,
254
341
  agentName: "",
255
342
  scene: this.activeScence,
343
+ user: this.provider.extensions.user,
344
+ authToken: this.authToken,
345
+ appId: this.appId,
346
+ showUpload: !1,
256
347
  onSubmit: this.handleSendMessage,
257
348
  onCancel: this.cancelHandler,
258
349
  onSceneChange: this.handleScenceChange,
@@ -260,36 +351,38 @@ const sseRequester = function(e, s) {
260
351
  }, null)]);
261
352
  }
262
353
  });
263
- function createMountManager(s, c, l, u, d) {
264
- let f = null, p = null, m = () => {
265
- let e = (s.container || document).querySelector(s.selector);
354
+ function createMountManager(o, s, c, l, u) {
355
+ let d = null, f = null, p = { ...o.mount }, m = { ...o.provider }, h = o.appId, g = () => {
356
+ let e = (p.container || document).querySelector(p.selector);
266
357
  if (e && !e.querySelector("[data-corepilot-host]")) {
267
- let s = document.createElement("div");
268
- return s.setAttribute("data-corepilot-host", "true"), s.style.width = "100%", s.style.height = "100%", e.appendChild(s), s;
358
+ let o = document.createElement("div");
359
+ return o.setAttribute("data-corepilot-host", "true"), o.style.width = "100%", o.style.height = "100%", e.appendChild(o), o;
269
360
  }
270
361
  return e?.querySelector("[data-corepilot-host]");
271
362
  };
272
363
  return {
273
364
  mount() {
274
- if (p = m(), !p) {
275
- u.error(`Mount point "${s.selector}" not found or already in use.`);
365
+ if (f = g(), !f) {
366
+ l.error(`Mount point "${p.selector}" not found or already in use.`);
276
367
  return;
277
368
  }
278
- f && (u.log("An app instance already exists. Unmounting first."), this.unmount()), f = createApp(CorePilotHost, {
279
- adapter: c,
280
- hitlManager: l,
281
- logger: u,
282
- provider: d
283
- }), f.mount(p), u.log("Vue CorePilotHost mounted.");
369
+ d && (l.log("An app instance already exists. Unmounting first."), this.unmount()), d = createApp(CorePilotHost, {
370
+ adapter: s,
371
+ hitlManager: c,
372
+ logger: l,
373
+ provider: m,
374
+ authManager: u,
375
+ appId: h
376
+ }), d.mount(f), l.log("Vue CorePilotHost mounted.");
284
377
  },
285
378
  unmount() {
286
- f && (f.unmount(), f = null, u.log("Vue CorePilotHost unmounted.")), p && p.parentElement && (p.parentElement.innerHTML = "");
379
+ d && (d.unmount(), d = null, l.log("Vue CorePilotHost unmounted.")), f && f.parentElement && (f.parentElement.innerHTML = "");
287
380
  }
288
381
  };
289
382
  }
290
383
  var HttpError = class extends Error {
291
- constructor(e, s, c, l) {
292
- super(e), this.name = "HttpError", this.code = s, this.data = c, this.originalError = l;
384
+ constructor(e, o, s, c) {
385
+ super(e), this.name = "HttpError", this.code = o, this.data = s, this.originalError = c;
293
386
  }
294
387
  }, axios_default = new class {
295
388
  constructor(e) {
@@ -304,72 +397,72 @@ var HttpError = class extends Error {
304
397
  this.instance.interceptors.response.use((e) => e.data, (e) => Promise.reject(this.handleError(e)));
305
398
  }
306
399
  handleError(e) {
307
- let s = "请求失败,请稍后重试", c = -1, l = null;
308
- if (axios.isAxiosError(e)) if (e.response) switch (c = e.response.status, l = e.response.data, c) {
400
+ let o = "请求失败,请稍后重试", s = -1, c = null;
401
+ if (axios.isAxiosError(e)) if (e.response) switch (s = e.response.status, c = e.response.data, s) {
309
402
  case 400:
310
- s = "请求参数错误";
403
+ o = "请求参数错误";
311
404
  break;
312
405
  case 401:
313
- s = "未授权,请重新登录";
406
+ o = "未授权,请重新登录";
314
407
  break;
315
408
  case 403:
316
- s = "拒绝访问";
409
+ o = "拒绝访问";
317
410
  break;
318
411
  case 404:
319
- s = "请求资源不存在";
412
+ o = "请求资源不存在";
320
413
  break;
321
414
  case 405:
322
- s = "请求方法不允许";
415
+ o = "请求方法不允许";
323
416
  break;
324
417
  case 408:
325
- s = "请求超时";
418
+ o = "请求超时";
326
419
  break;
327
420
  case 500:
328
- s = "服务器内部错误";
421
+ o = "服务器内部错误";
329
422
  break;
330
423
  case 501:
331
- s = "服务未实现";
424
+ o = "服务未实现";
332
425
  break;
333
426
  case 502:
334
- s = "网关错误";
427
+ o = "网关错误";
335
428
  break;
336
429
  case 503:
337
- s = "服务不可用";
430
+ o = "服务不可用";
338
431
  break;
339
432
  case 504:
340
- s = "网关超时";
433
+ o = "网关超时";
341
434
  break;
342
- default: s = e.response.statusText || `连接错误 ${c}`;
435
+ default: o = e.response.statusText || `连接错误 ${s}`;
343
436
  }
344
- else e.request ? (s = "网络连接失败,请检查网络设置", c = 0) : s = e.message;
345
- else s = e.message || "未知错误";
346
- return console.error(`[HttpClient] Error: ${s}`, {
347
- code: c,
348
- data: l,
437
+ else e.request ? (o = "网络连接失败,请检查网络设置", s = 0) : o = e.message;
438
+ else o = e.message || "未知错误";
439
+ return console.error(`[HttpClient] Error: ${o}`, {
440
+ code: s,
441
+ data: c,
349
442
  original: e
350
- }), new HttpError(s, c, l, e);
443
+ }), new HttpError(o, s, c, e);
351
444
  }
352
- get(e, s) {
353
- return this.instance.get(e, s);
445
+ get(e, o) {
446
+ return this.instance.get(e, o);
354
447
  }
355
- post(e, s, c) {
356
- return this.instance.post(e, s, c);
448
+ post(e, o, s) {
449
+ return this.instance.post(e, o, s);
357
450
  }
358
- put(e, s, c) {
359
- return this.instance.put(e, s, c);
451
+ put(e, o, s) {
452
+ return this.instance.put(e, o, s);
360
453
  }
361
- delete(e, s) {
362
- return this.instance.delete(e, s);
454
+ delete(e, o) {
455
+ return this.instance.delete(e, o);
363
456
  }
364
- patch(e, s, c) {
365
- return this.instance.patch(e, s, c);
457
+ patch(e, o, s) {
458
+ return this.instance.patch(e, o, s);
366
459
  }
367
- upload(e, s, c = "file", l) {
368
- let u = new FormData();
369
- return u.append(c, s), this.instance.post(e, u, {
370
- ...l,
460
+ upload(e, o, s = "file", c) {
461
+ let l = new FormData();
462
+ return l.append(s, o), this.instance.post(e, l, {
463
+ ...c,
371
464
  headers: {
372
- ...l?.headers,
465
+ ...c?.headers,
373
466
  "Content-Type": "multipart/form-data"
374
467
  }
375
468
  });
@@ -378,84 +471,181 @@ var HttpError = class extends Error {
378
471
  return this.instance;
379
472
  }
380
473
  }({});
381
- function createCoreAgentAdapter(e, s, c) {
382
- let { appId: l, provider: u } = e, { extensions: d } = u, { user: f = "default" } = d || {}, p = async (e, c) => {
383
- let u = e.taskId, d = await s.getToken();
384
- return await axios_default.post(`/openapi/v1/app/chat-messages/${u}/stop`, { user: f }, { headers: {
385
- Authorization: `Bearer ${d}`,
386
- appId: l
387
- } }), Promise.resolve();
388
- }, m = async (e) => {
389
- let c = e.messageId, u = await s.getToken(), d = await axios_default.post(`/openapi/v1/app/chat-messages/${c}/suggested`, { user: f }, { headers: {
390
- Authorization: `Bearer ${u}`,
391
- appId: l
392
- } });
393
- return d.result === "success" ? d.data : [];
394
- }, h = async (e) => {
395
- let c = await s.getToken();
396
- return await axios_default.get(`/openapi/v1/app/conversations?${new URLSearchParams(e).toString()}`, { headers: {
397
- Authorization: `Bearer ${c}`,
398
- appId: l
399
- } });
400
- }, g = async (e) => {
401
- let c = await s.getToken();
402
- return await axios_default.get(`/openapi/v1/app/messages?${new URLSearchParams(e).toString()}`, { headers: {
403
- Authorization: `Bearer ${c}`,
404
- appId: l
405
- } });
406
- }, _ = async (e) => {
407
- let { hitlData: c, prevMessage: u, text: d, inputs: p } = e, m = {
408
- query: d || JSON.stringify(c || {}),
409
- inputs: p || {},
410
- response_mode: "streaming",
411
- conversation_id: u?.conversationId || null,
412
- parent_message_id: u?.messageId || null,
474
+ const eventHub = new class {
475
+ constructor() {
476
+ this.listeners = [];
477
+ }
478
+ subscribeEvent(e) {
479
+ this.listeners.includes(e) || this.listeners.push(e);
480
+ }
481
+ unsubscribeEvent(e) {
482
+ let o = this.listeners.indexOf(e);
483
+ o > -1 && this.listeners.splice(o, 1);
484
+ }
485
+ emitEvent(e) {
486
+ this.listeners.forEach((o) => {
487
+ try {
488
+ o(e);
489
+ } catch (e) {
490
+ console.error("[EventHub] Event callback error:", e);
491
+ }
492
+ });
493
+ }
494
+ }();
495
+ var TOKEN_EXPIRED_CODE = 40100, APPID_INVALID_CODE = 403;
496
+ function createCoreAgentAdapter(e, o, s) {
497
+ let { appId: c, provider: l, baseUrl: u } = e, { extensions: d } = l, { user: f = "default", accessToken: p = "" } = d || {}, m = () => {
498
+ eventHub.emitEvent({
499
+ action: "cust_token_expired",
500
+ code: TOKEN_EXPIRED_CODE,
501
+ message: "凭证已过期"
502
+ });
503
+ }, h = (e) => {
504
+ eventHub.emitEvent({
505
+ action: "cust_request_error",
506
+ code: e.code,
507
+ message: e.message || "请求失败"
508
+ });
509
+ }, g = () => o.isServerMode() ? u + "/api/proxy/ca" : u, _ = async () => ({
510
+ Authorization: `Bearer ${await o.getToken()}`,
511
+ appId: c
512
+ }), v = async (e, o) => {
513
+ let s = e.taskId, c = g(), l = await _();
514
+ return await axios_default.post(`${c}/openapi/v1/app/chat-messages/${s}/stop`, { user: f }, { headers: l }), Promise.resolve();
515
+ }, y = async (e, s, c) => {
516
+ e.messageId;
517
+ let l = g(), u = await o.getToken(), d = {
518
+ query: JSON.stringify(s || []),
519
+ inputs: { scence: c },
520
+ response_mode: "blocking",
521
+ conversation_id: null,
522
+ parent_message_id: null,
413
523
  user: f,
414
524
  files: []
415
- }, h = await s.getToken();
525
+ }, p = { Authorization: `Bearer ${u}` };
526
+ p.appId = "b7886345-d200-486d-8318-8c234a19ccb9";
527
+ let m = await axios_default.post(`${l}/openapi/v1/app/chat-messages`, d, { headers: p });
528
+ try {
529
+ let e = JSON.parse(m.answer || "[]");
530
+ return console.log("data", e), e;
531
+ } catch {
532
+ return [];
533
+ }
534
+ }, b = async (e) => {
535
+ let o = g(), s = await _();
536
+ try {
537
+ return await axios_default.get(`${o}/openapi/v1/app/conversations?${new URLSearchParams(e).toString()}`, { headers: s });
538
+ } catch (e) {
539
+ throw e;
540
+ }
541
+ }, x = async (e) => {
542
+ let o = g(), s = await _();
543
+ try {
544
+ return await axios_default.get(`${o}/openapi/v1/app/messages?${new URLSearchParams(e).toString()}`, { headers: s });
545
+ } catch (e) {
546
+ throw e;
547
+ }
548
+ }, C = (e) => {
549
+ switch (e.toLowerCase()) {
550
+ case "txt":
551
+ case "doc":
552
+ case "docx":
553
+ case "pdf":
554
+ case "ppt":
555
+ case "pptx":
556
+ case "xls":
557
+ case "xlsx":
558
+ case "csv": return "document";
559
+ case "jpg":
560
+ case "jpeg":
561
+ case "png":
562
+ case "gif":
563
+ case "webp":
564
+ case "svg": return "image";
565
+ case "mp3":
566
+ case "wav": return "audio";
567
+ case "mp4":
568
+ case "mov":
569
+ case "ogg": return "video";
570
+ default: return "custom";
571
+ }
572
+ }, w = async (e) => {
573
+ let { hitlData: o, prevMessage: s, text: c, inputs: l, files: u } = e, d = o?.payload?.__files__ || {}, m = [];
574
+ Object.values(d).flat().forEach((e) => {
575
+ m.push({
576
+ transfer_method: "local_file",
577
+ type: C(e.extension || ""),
578
+ upload_file_id: e.id,
579
+ url: e.url || ""
580
+ });
581
+ }), u?.forEach((e) => {
582
+ m.push({
583
+ transfer_method: "local_file",
584
+ type: C(e.extension || ""),
585
+ upload_file_id: e.id,
586
+ url: e.url || ""
587
+ });
588
+ });
589
+ let h = {
590
+ query: c || JSON.stringify(o || {}),
591
+ inputs: {
592
+ ...l || {},
593
+ accessToken: p
594
+ },
595
+ response_mode: "streaming",
596
+ conversation_id: s?.conversationId || null,
597
+ parent_message_id: s?.messageId || null,
598
+ user: f,
599
+ files: m
600
+ }, v = g(), y = await _();
416
601
  return {
417
- url: "/openapi/v1/app/chat-messages",
602
+ url: `${v}/openapi/v1/app/chat-messages`,
418
603
  config: {
419
604
  method: "POST",
420
605
  headers: {
421
606
  "Content-Type": "application/json",
422
- Authorization: `Bearer ${h}`,
423
- appId: l
607
+ ...y
424
608
  },
425
- body: JSON.stringify(m)
609
+ body: JSON.stringify(h)
426
610
  }
427
611
  };
428
- }, v = (e) => {
429
- let { data: s } = e;
430
- return JSON.parse(s || "{}");
431
- }, y = async () => {
432
- c.log("onClose");
433
- }, b = async (e) => {
434
- c.log("onError", e);
435
- }, x = async () => {
436
- c.log("onOpen");
437
- }, S = (e) => {
612
+ }, T = (e) => {
613
+ let { data: o } = e, s = JSON.parse(o || "{}");
614
+ return s.code === TOKEN_EXPIRED_CODE ? (m(), null) : s.code === APPID_INVALID_CODE ? (h(s), null) : s;
615
+ }, E = async () => {
616
+ s.log("onClose");
617
+ }, D = async (e) => {
618
+ s.log("onError", e);
619
+ }, O = async (e) => {
620
+ s.log("onOpen");
621
+ }, k = (e) => {
438
622
  try {
439
623
  return JSON.parse(e || "{}")?.action?.startsWith("core_") || !1;
440
624
  } catch {
441
625
  return !1;
442
626
  }
443
- }, C = async (e) => {
444
- sseRequester(await _(e), {
445
- formatReuqest: _,
446
- getSuggestionQuestions: m,
447
- getConversationList: h,
448
- getMessageHistory: g,
449
- onMessage: v,
450
- onClose: y,
451
- onError: b,
452
- onOpen: x,
453
- onCancel: p
627
+ }, A = async (e, s = !1) => {
628
+ let { inputs: c } = e, l = c?.scence;
629
+ l && pilotStore.getState().setActiveScence(l);
630
+ let u = await w(e), d = o.isServerMode() ? N() : void 0;
631
+ sseRequester(u, {
632
+ formatRequest: w,
633
+ getSuggestionQuestions: y,
634
+ getConversationList: b,
635
+ getMessageHistory: x,
636
+ onMessage: T,
637
+ onClose: E,
638
+ onError: D,
639
+ onOpen: O,
640
+ onCancel: v
641
+ }, {
642
+ fetchFn: d,
643
+ isRetry: s
454
644
  });
455
- }, w = async (e) => {
456
- let s = [], c;
645
+ }, j = async (e) => {
646
+ let o = [], s;
457
647
  if (e.data.forEach((e) => {
458
- if (e.parent_message_id === c) s.pop(), s.push({
648
+ if (e.parent_message_id === s) o.pop(), o.push({
459
649
  role: "ai",
460
650
  showActions: !1,
461
651
  content: e.answer,
@@ -465,26 +655,29 @@ function createCoreAgentAdapter(e, s, c) {
465
655
  extension: e.type,
466
656
  name: e.filename
467
657
  })),
468
- placement: "start"
658
+ placement: "start",
659
+ conversationId: e.conversation_id,
660
+ messageId: e.id
469
661
  });
470
662
  else {
471
- if (c = e.parent_message_id, !S(e.query)) s.push({
663
+ if (s = e.parent_message_id, !k(e.query)) o.push({
472
664
  role: "user",
473
665
  messageId: e.id,
474
666
  content: e.query,
475
667
  showActions: !1,
476
668
  maxWidth: "100%",
477
669
  placement: "end",
478
- isHistoryMessage: !0
670
+ isHistoryMessage: !0,
671
+ conversationId: e.conversation_id
479
672
  });
480
673
  else {
481
- let c = JSON.parse(e.query || "{}");
482
- if (c?.payload) {
483
- let e = s[s.length - 1];
484
- e && (e.historyInputs = c.payload);
674
+ let s = JSON.parse(e.query || "{}");
675
+ if (s?.payload) {
676
+ let e = o[o.length - 1];
677
+ e && (e.historyInputs = s.payload);
485
678
  }
486
679
  }
487
- s.push({
680
+ o.push({
488
681
  role: "ai",
489
682
  content: e.answer,
490
683
  showActions: !1,
@@ -495,23 +688,35 @@ function createCoreAgentAdapter(e, s, c) {
495
688
  extension: e.type,
496
689
  name: e.filename
497
690
  })),
498
- isHistoryMessage: !0
691
+ isHistoryMessage: !0,
692
+ conversationId: e.conversation_id,
693
+ messageId: e.id
499
694
  });
500
695
  }
501
696
  }), e.has_more) {
502
- let e = await g({
503
- conversation_id: s[s.length - 1].conversationId,
697
+ let e = await x({
698
+ conversation_id: o[o.length - 1].conversationId,
504
699
  user: f,
505
- first_id: s[0].messageId
700
+ first_id: o[0].messageId
506
701
  });
507
702
  if (e.data) {
508
- let c = await w(e);
509
- s.unshift(...c);
703
+ let s = await j(e);
704
+ o.unshift(...s);
510
705
  }
511
706
  }
512
- return s;
513
- }, T = async () => (pilotStore.getState().resetMessageHistory(), !0), E = async (e) => {
514
- let s = {
707
+ return o;
708
+ }, M = async () => (pilotStore.getState().resetMessageHistory(), !0), N = () => async (e, s) => {
709
+ let c = await o.getToken(), l = o.getAppId(), u = {
710
+ ...s?.headers || {},
711
+ Authorization: `Bearer ${c}`,
712
+ ...l ? { appId: l } : {}
713
+ };
714
+ return await fetch(e, {
715
+ ...s,
716
+ headers: u
717
+ });
718
+ }, P = async (e, s = !1) => {
719
+ let c = {
515
720
  messageId: void 0,
516
721
  content: e.text,
517
722
  role: "user",
@@ -519,125 +724,175 @@ function createCoreAgentAdapter(e, s, c) {
519
724
  showActions: !1,
520
725
  maxWidth: "100%"
521
726
  };
522
- pilotStore.getState().updateMessageHistory([s]), pilotStore.getState().resetCurrentMessage();
523
- let c = await _({
727
+ s || pilotStore.getState().updateMessageHistory([c]), pilotStore.getState().resetCurrentMessage();
728
+ let l = await w({
524
729
  text: e.text,
525
730
  prevMessage: void 0,
526
731
  inputs: e.inputs
527
732
  });
528
- return pilotStore.getState().setActiveScence(e.inputs?.scence), sseRequester(c, {
529
- formatReuqest: _,
530
- getSuggestionQuestions: m,
531
- getConversationList: h,
532
- getMessageHistory: g,
533
- onMessage: v,
534
- onClose: y,
535
- onError: b,
536
- onOpen: x,
537
- onCancel: p
733
+ pilotStore.getState().setActiveScence(e.inputs?.scence);
734
+ let u = o.isServerMode() ? N() : void 0;
735
+ return sseRequester(l, {
736
+ formatRequest: w,
737
+ getSuggestionQuestions: y,
738
+ getConversationList: b,
739
+ getMessageHistory: x,
740
+ onMessage: T,
741
+ onClose: E,
742
+ onError: D,
743
+ onOpen: O,
744
+ onCancel: v
745
+ }, {
746
+ fetchFn: u,
747
+ isRetry: s
538
748
  });
749
+ }, F = async () => {
750
+ let e = pilotStore.getState().pendingRetryRequest;
751
+ if (!e) return;
752
+ pilotStore.getState().clearPendingRetryRequest();
753
+ let s = o.isServerMode() ? N() : void 0;
754
+ if (e.type === "submit_message") {
755
+ let o = e.payload;
756
+ sseRequester(await w({
757
+ text: o.text,
758
+ prevMessage: void 0,
759
+ inputs: o.inputs
760
+ }), {
761
+ formatRequest: w,
762
+ getSuggestionQuestions: y,
763
+ getConversationList: b,
764
+ getMessageHistory: x,
765
+ onMessage: T,
766
+ onClose: E,
767
+ onError: D,
768
+ onOpen: O,
769
+ onCancel: v
770
+ }, {
771
+ fetchFn: s,
772
+ isRetry: !0
773
+ });
774
+ } else e.type === "submit_core_action" && await A(e.payload, !0);
539
775
  };
540
- return {
541
- formatReuqest: _,
542
- getSuggestionQuestions: m,
543
- getConversationList: h,
544
- getMessageHistory: g,
545
- onMessage: v,
546
- onClose: y,
547
- onError: b,
548
- onOpen: x,
549
- onCancel: p,
776
+ return o.onTokenRefreshed(() => {
777
+ setTimeout(() => {
778
+ F();
779
+ }, 0);
780
+ }), {
781
+ formatRequest: w,
782
+ getSuggestionQuestions: y,
783
+ getConversationList: b,
784
+ getMessageHistory: x,
785
+ onMessage: T,
786
+ onClose: E,
787
+ onError: D,
788
+ onOpen: O,
789
+ onCancel: v,
550
790
  triggerEvent: async (e) => {
551
791
  switch (e.action) {
552
- case "get_suggestion_questions": return await m(e.payload);
553
- case "get_conversation_list": return await h(e.payload);
792
+ case "get_suggestion_questions": return await y(e.payload);
793
+ case "get_conversation_list": return await b(e.payload);
554
794
  case "get_message_history":
555
- let s = await w(await g(e.payload));
556
- return pilotStore.getState().resetMessageHistory(s), s;
557
- case "submit_core_action": return await C(e.payload);
558
- case "new_message": return await T();
559
- case "submit_message": return await E(e.payload);
795
+ let o = await j(await x(e.payload));
796
+ return pilotStore.getState().resetMessageHistory(o), o;
797
+ case "submit_core_action": return pilotStore.getState().setPendingRetryRequest({
798
+ type: "submit_core_action",
799
+ payload: e.payload
800
+ }), await A(e.payload);
801
+ case "new_message": return await M();
802
+ case "submit_message": return pilotStore.getState().setPendingRetryRequest({
803
+ type: "submit_message",
804
+ payload: e.payload
805
+ }), await P(e.payload);
560
806
  default: throw Error("Invalid event action.");
561
807
  }
562
- }
808
+ },
809
+ createSseFetch: N
563
810
  };
564
811
  }
565
- function createProtocolAdapter(e, s, c, l) {
566
- switch (l.log(`Creating adapter for provider: ${s}`), s.name) {
567
- case "coreagent": return createCoreAgentAdapter(e, c, l);
568
- default: throw Error(`Unsupported provider: ${s.name}`);
812
+ function createProtocolAdapter(e, o, s, c) {
813
+ switch (c.log(`Creating adapter for provider: ${o}`), o.name) {
814
+ case "coreagent": return createCoreAgentAdapter(e, s, c);
815
+ default: throw Error(`Unsupported provider: ${o.name}`);
569
816
  }
570
817
  }
571
- function createHitlManager(e, s, c) {
572
- let l = (e) => e.split("_")[0], u = [], d = async (s) => {
573
- let l = await e.formatReuqest(s);
818
+ function createHitlManager(e, o, s) {
819
+ let c = (e) => e.split("_")[0], l = [], u = async (o) => {
820
+ let c = await e.formatRequest(o);
574
821
  sseRequester({
575
- url: l.url,
576
- config: l.config
577
- }, e), c.log("HITL data submitted successfully.");
578
- }, f = async (e) => {
579
- u.forEach((s) => s(e.hitlData));
580
- }, p = async (e) => {};
822
+ url: c.url,
823
+ config: c.config
824
+ }, e), s.log("HITL data submitted successfully.");
825
+ }, d = async (e) => {
826
+ l.forEach((o) => o(e.hitlData));
827
+ }, f = async (e) => {};
581
828
  return {
582
829
  async submit(e) {
583
830
  try {
584
- let s = l(e.hitlData?.action ?? "");
585
- switch (c.log("[HITL] Submitting HITL data...", e), s) {
831
+ let o = c(e.hitlData?.action ?? "");
832
+ switch (s.log("[HITL] Submitting HITL data...", e), o) {
586
833
  case "core":
587
- await d(e);
834
+ await u(e);
588
835
  break;
589
836
  case "cust":
590
- await f(e);
837
+ await d(e);
591
838
  break;
592
839
  case "inner":
593
- await p(e);
840
+ await f(e);
594
841
  break;
595
842
  default: throw Error("Invalid action type.");
596
843
  }
597
844
  } catch (e) {
598
- throw c.error("Error submitting HITL data:", e), e;
845
+ throw s.error("Error submitting HITL data:", e), e;
599
846
  }
600
847
  },
601
848
  subscribeEvent(e) {
602
- u.includes(e) || u.push(e);
849
+ l.includes(e) || l.push(e);
603
850
  },
604
851
  unsubscribeEvent(e) {
605
- u.splice(u.indexOf(e), 1);
852
+ l.splice(l.indexOf(e), 1);
606
853
  }
607
854
  };
608
855
  }
609
856
  function createCorePilot(e) {
610
- if (!e.appId) throw Error("CorePilot SDK: `appId` is required.");
857
+ if (e.auth.mode, !e.appId) throw Error("CorePilot SDK: `appId` is required.");
611
858
  if (!e.mount.selector) throw Error("CorePilot SDK: `mount.selector` is required.");
612
- let s = createLogger(e.debug ?? !1, e.appId, e.eventTracker);
613
- s.log("CorePilot SDK Initializing...", e);
614
- let c = { ...e }, l = createAuthManager(c.auth, c.baseUrl), u = createProtocolAdapter(c, c.provider, l, s), d = createHitlManager(u, l, s), f = createMountManager(c.mount, u, d, s, c.provider);
859
+ let o = createLogger(e.debug ?? !1, e.appId || "", e.eventTracker);
860
+ o.log("CorePilot SDK Initializing...", e);
861
+ let s = { ...e }, c = createAuthManager(s.auth, s.appId), l = createProtocolAdapter(s, s.provider, c, o), u = createHitlManager(l, c, o), d = createMountManager(s, l, u, o, c), f = {
862
+ inner_set_token: async (e) => (await c.setToken(e), !0),
863
+ inner_get_token: async () => await c.getToken()
864
+ };
615
865
  return {
616
866
  mount() {
617
- s.log("Mounting CorePilot UI..."), f.mount();
867
+ o.log("Mounting CorePilot UI..."), d.mount();
618
868
  },
619
869
  unmount() {
620
- s.log("Unmounting CorePilot UI..."), f.unmount();
870
+ o.log("Unmounting CorePilot UI..."), d.unmount();
621
871
  },
622
872
  reload(e) {
623
- s.log("Reloading CorePilot instance...", e), f.unmount(), c = {
624
- ...c,
873
+ o.log("Reloading CorePilot instance...", e), d.unmount(), s = {
874
+ ...s,
625
875
  ...e
626
- }, u = createProtocolAdapter(c, c.provider, l, s);
627
- let p = createMountManager(c.mount, u, d, s, c.provider);
628
- f.mount = p.mount, f.unmount = p.unmount, s.log("CorePilot reloaded. Remounting UI..."), f.mount();
876
+ }, l = createProtocolAdapter(s, s.provider, c, o);
877
+ let f = createMountManager(s, l, u, o, c);
878
+ d.mount = f.mount, d.unmount = f.unmount, o.log("CorePilot reloaded. Remounting UI..."), d.mount();
629
879
  },
630
880
  destroy() {
631
- s.log("Destroying CorePilot instance..."), f.unmount(), s.destroy();
881
+ o.log("Destroying CorePilot instance..."), d.unmount(), o.destroy();
632
882
  },
633
883
  async triggerEvent(e) {
634
- return await u.triggerEvent(e);
884
+ let o = f[e.action];
885
+ if (o) {
886
+ let s = e.payload;
887
+ return await o(s);
888
+ }
889
+ return await l.triggerEvent(e);
635
890
  },
636
891
  subscribeEvent(e) {
637
- d.subscribeEvent(e);
892
+ u.subscribeEvent(e), eventHub.subscribeEvent(e);
638
893
  },
639
894
  unsubscribeEvent(e) {
640
- d.unsubscribeEvent(e);
895
+ u.unsubscribeEvent(e), eventHub.unsubscribeEvent(e);
641
896
  }
642
897
  };
643
898
  }