@glodon-aiot/bot-client-sdk 3.26.0-alpha.32 → 3.26.0-alpha.33

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.
@@ -1,16 +1,16 @@
1
- var L = Object.defineProperty, q = Object.defineProperties;
2
- var j = Object.getOwnPropertyDescriptors;
1
+ var U = Object.defineProperty, x = Object.defineProperties;
2
+ var q = Object.getOwnPropertyDescriptors;
3
3
  var P = Object.getOwnPropertySymbols;
4
- var F = Object.prototype.hasOwnProperty, N = Object.prototype.propertyIsEnumerable;
5
- var M = (o, c, e) => c in o ? L(o, c, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[c] = e, h = (o, c) => {
4
+ var j = Object.prototype.hasOwnProperty, F = Object.prototype.propertyIsEnumerable;
5
+ var R = (o, c, e) => c in o ? U(o, c, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[c] = e, h = (o, c) => {
6
6
  for (var e in c || (c = {}))
7
- F.call(c, e) && M(o, e, c[e]);
7
+ j.call(c, e) && R(o, e, c[e]);
8
8
  if (P)
9
9
  for (var e of P(c))
10
- N.call(c, e) && M(o, e, c[e]);
10
+ F.call(c, e) && R(o, e, c[e]);
11
11
  return o;
12
- }, w = (o, c) => q(o, j(c));
13
- var R = (o, c, e) => (M(o, typeof c != "symbol" ? c + "" : c, e), e);
12
+ }, C = (o, c) => x(o, q(c));
13
+ var k = (o, c, e) => (R(o, typeof c != "symbol" ? c + "" : c, e), e);
14
14
  var y = (o, c, e) => new Promise((r, a) => {
15
15
  var n = (i) => {
16
16
  try {
@@ -27,16 +27,17 @@ var y = (o, c, e) => new Promise((r, a) => {
27
27
  }, s = (i) => i.done ? r(i.value) : Promise.resolve(i.value).then(n, t);
28
28
  s((e = e.apply(o, c)).next());
29
29
  });
30
- import { ChatMessageRole as C, PromptVariableType as A } from "@glodon-aiot/apis";
31
- import O from "./Logger.mjs";
32
- import { configuration as u } from "./Config.mjs";
33
- import { io as U } from "socket.io-client";
34
- import { UserMode as k } from "./PayloadTypes.mjs";
30
+ import { ChatMessageRole as M, PromptVariableType as A } from "@glodon-aiot/apis";
31
+ import N from "./Logger.mjs";
32
+ import { configuration as p } from "./Config.mjs";
33
+ import { io as O } from "socket.io-client";
34
+ import { UserMode as w } from "./PayloadTypes.mjs";
35
35
  import D, { SessionErrors as I } from "./Session.mjs";
36
36
  import V from "dayjs";
37
- import { v4 as J } from "uuid";
38
- import { registerLocalMcp as Y } from "./localMcp/register.mjs";
39
- const m = new O("[AgentSession] ");
37
+ import { v4 as B } from "uuid";
38
+ import { connectLocalMcpBridge as J, subscribeLocalMcpEndpoints as Y } from "./localMcp/endpoints.mjs";
39
+ import { registerLocalMcp as $ } from "./localMcp/register.mjs";
40
+ const m = new N("[AgentSession] ");
40
41
  function _(o) {
41
42
  if (typeof o != "string")
42
43
  return o;
@@ -48,33 +49,34 @@ function _(o) {
48
49
  return o;
49
50
  }
50
51
  }
51
- function T(o) {
52
+ function L(o) {
52
53
  return o == null || o === "" || typeof o == "object" && !Array.isArray(o) && Object.keys(o).length === 0;
53
54
  }
54
- function $(o, c) {
55
+ function z(o, c) {
55
56
  const e = _(o == null ? void 0 : o.query);
56
- if (!T(e))
57
+ if (!L(e))
57
58
  return e;
58
59
  const r = _(c);
59
- return T(r) && e != null ? e : r;
60
+ return L(r) && e != null ? e : r;
60
61
  }
61
- class se extends D {
62
+ class ne extends D {
62
63
  constructor(e, r = "", a, n, t, s) {
63
64
  super(e, r, a, n, t, s);
64
- R(this, "inflightCalls", /* @__PURE__ */ new Set());
65
- R(this, "localMcpTicket", 0);
65
+ k(this, "inflightCalls", /* @__PURE__ */ new Set());
66
+ k(this, "localMcpTicket", 0);
67
+ k(this, "stopLocalMcpUpdates");
66
68
  }
67
69
  prepareConnection() {
68
70
  return new Promise((e) => y(this, null, function* () {
69
71
  this.socket && e(!0);
70
72
  const r = {
71
73
  version: "1.0",
72
- stream: JSON.stringify(u.stream),
74
+ stream: JSON.stringify(p.stream),
73
75
  appId: this._applicationId,
74
76
  sessionId: this.id,
75
77
  Authorization: `${this.token}`,
76
- userMode: u.debug ? k.Debug : k.Normal
77
- }, a = new URL(u.apiRoot), n = yield U(a.origin, {
78
+ userMode: p.debug ? w.Debug : w.Normal
79
+ }, a = new URL(p.apiRoot), n = yield O(a.origin, {
78
80
  path: a.pathname.replace("api", "socketio") + "/copilot",
79
81
  query: r,
80
82
  transports: ["websocket"]
@@ -86,8 +88,8 @@ class se extends D {
86
88
  }), n.on("ready", (t) => {
87
89
  if (t.code === 200) {
88
90
  m.log("ready");
89
- const s = u.debug ? k.Debug : k.Normal;
90
- s === k.Debug && t.userMode, this._ready || (this._ready = !0, this.event.emit("ready")), this.frozen = !1, this.registerMcpFromClientConfig(), this.registerLocalMcp(), e(!0);
91
+ const s = p.debug ? w.Debug : w.Normal;
92
+ s === w.Debug && t.userMode, this._ready || (this._ready = !0, this.event.emit("ready")), this.frozen = !1, this.registerMcpFromClientConfig(), this.registerLocalMcp(), e(!0);
91
93
  } else {
92
94
  this._ready && (this._ready = !1);
93
95
  const s = new Error(
@@ -99,7 +101,7 @@ class se extends D {
99
101
  m.error("error", s), this.event.emit("error", s), e(!1);
100
102
  }
101
103
  }), n.on("action", (t, s) => y(this, null, function* () {
102
- var S;
104
+ var b;
103
105
  if (this._stopAnswer || !this.id)
104
106
  return;
105
107
  const {
@@ -111,17 +113,17 @@ class se extends D {
111
113
  parameters: f,
112
114
  requestBody: E
113
115
  }
114
- } = t, p = this.messages[this.messages.length - 1];
115
- if (!p.messageId)
116
- p.actions || (p.actions = []), p.actions[t.data.step - 1] || (p.actions[t.data.step - 1] = []), p.actions[t.data.step - 1].push(t), this.event.emit("message:action", {
117
- messageId: p.messageId,
116
+ } = t, u = this.messages[this.messages.length - 1];
117
+ if (!u.messageId)
118
+ u.actions || (u.actions = []), u.actions[t.data.step - 1] || (u.actions[t.data.step - 1] = []), u.actions[t.data.step - 1].push(t), this.event.emit("message:action", {
119
+ messageId: u.messageId,
118
120
  action: t
119
- }), this.event.emit("message:updated", p);
121
+ }), this.event.emit("message:updated", u);
120
122
  else {
121
123
  const v = {
122
124
  messageId: "",
123
125
  content: "",
124
- role: C.Robot,
126
+ role: M.Robot,
125
127
  sessionId: this.id,
126
128
  reference: [],
127
129
  searchReference: [],
@@ -153,7 +155,7 @@ class se extends D {
153
155
  } else if (i === "FUNCTION_CALL" && l) {
154
156
  m.log(`calling function ${g} of plugin ${d} with argument:
155
157
  ${JSON.stringify(f)}`);
156
- const v = (S = u.plugins) == null ? void 0 : S[d];
158
+ const v = (b = p.plugins) == null ? void 0 : b[d];
157
159
  if (!v) {
158
160
  s({
159
161
  code: 404,
@@ -161,16 +163,16 @@ class se extends D {
161
163
  });
162
164
  return;
163
165
  }
164
- const b = v[g];
165
- if (typeof b != "function") {
166
+ const S = v[g];
167
+ if (typeof S != "function") {
166
168
  s({
167
169
  code: 404,
168
170
  message: "没有找到插件方法。"
169
171
  });
170
172
  return;
171
173
  }
172
- const x = $(f, E);
173
- this.invokeClientPlugin(b, x, s, {
174
+ const T = z(f, E);
175
+ this.invokeClientPlugin(S, T, s, {
174
176
  requestId: t.requestId,
175
177
  pluginCode: d,
176
178
  functionCode: g
@@ -180,12 +182,12 @@ class se extends D {
180
182
  if (!this._stopAnswer)
181
183
  if (t.data.code !== 200 && (t.data.index = -1), t.data.stream || t.data.stream === void 0) {
182
184
  let s = this.messages[this.messages.length - 1];
183
- if (s && s.role === C.Robot)
185
+ if (s && s.role === M.Robot)
184
186
  this.handleStreamAnswer(t.data, s), this.messages[this.messages.length - 1] = s, this.event.emit("message:content", s), this.event.emit("message:updated", s), s.index === -1 && (s.isReplying = !1, this.event.emit("answer:finish", s));
185
187
  else {
186
188
  const i = {
187
189
  content: "",
188
- role: C.Robot,
190
+ role: M.Robot,
189
191
  reference: [],
190
192
  searchReference: [],
191
193
  messageId: "",
@@ -215,7 +217,7 @@ class se extends D {
215
217
  const i = h({
216
218
  messageId: "",
217
219
  content: "",
218
- role: C.Robot,
220
+ role: M.Robot,
219
221
  sessionId: this.id,
220
222
  reference: [],
221
223
  searchReference: [],
@@ -234,7 +236,7 @@ class se extends D {
234
236
  s && !s.messageId ? (s = h(h({}, s), t.data), this.messages[this.messages.length - 1] = s, this.event.emit("message:content", s), this.event.emit("message:updated", s)) : (this.pushMessage(h({
235
237
  messageId: "",
236
238
  content: "",
237
- role: C.Robot,
239
+ role: M.Robot,
238
240
  sessionId: this.id,
239
241
  reference: [],
240
242
  searchReference: [],
@@ -264,7 +266,7 @@ class se extends D {
264
266
  type: s,
265
267
  data: i,
266
268
  requestId: l
267
- } = t, d = this.messages.findIndex((f) => f.messageId === l && f.role === C.User);
269
+ } = t, d = this.messages.findIndex((f) => f.messageId === l && f.role === M.User);
268
270
  if (d < 0)
269
271
  return;
270
272
  const g = d + 1;
@@ -272,7 +274,7 @@ class se extends D {
272
274
  const f = {
273
275
  messageId: "",
274
276
  content: "",
275
- role: C.Robot,
277
+ role: M.Robot,
276
278
  sessionId: this.id,
277
279
  reference: [],
278
280
  searchReference: [],
@@ -286,21 +288,21 @@ class se extends D {
286
288
  };
287
289
  this.pushMessage(f);
288
290
  }
289
- s === "KG" ? (this.messages[g] = w(h({}, this.messages[g]), {
291
+ s === "KG" ? (this.messages[g] = C(h({}, this.messages[g]), {
290
292
  reference: i.knowledgeReference
291
- }), yield this.fillMessageReference(this.messages[g]), this.event.emit("message:reference", i.knowledgeReference), this.event.emit("message:updated", this.messages[g])) : s === "WEB_SEARCH" && (this.messages[g] = w(h({}, this.messages[g]), {
293
+ }), yield this.fillMessageReference(this.messages[g]), this.event.emit("message:reference", i.knowledgeReference), this.event.emit("message:updated", this.messages[g])) : s === "WEB_SEARCH" && (this.messages[g] = C(h({}, this.messages[g]), {
292
294
  searchReference: i.knowledgeReference
293
295
  }), this.event.emit("message:searchreference", i.searchReference), this.event.emit("message:updated", this.messages[g]));
294
296
  })), this.socket = n, n.open();
295
297
  }));
296
298
  }
297
299
  registerMcpFromClientConfig() {
298
- return u.mcp ? new Promise((e, r) => {
300
+ return p.mcp ? new Promise((e, r) => {
299
301
  if (!this.socket) {
300
302
  r("socket is undefined");
301
303
  return;
302
304
  }
303
- this.socket.emit("add_mcp_servers", u.mcp, (a) => {
305
+ this.socket.emit("add_mcp_servers", p.mcp, (a) => {
304
306
  a.code === 200 ? (Object.keys(a.data).forEach((n) => {
305
307
  a.data[n].code !== 200 && console.error(n, "MCP Server 注册失败。", a.data[n]);
306
308
  }), e(!0)) : (console.error("MCP Server 注册失败。", a), r(a));
@@ -312,11 +314,12 @@ class se extends D {
312
314
  const e = this.socket;
313
315
  if (!e)
314
316
  return;
317
+ J(), this.stopLocalMcpUpdates || (this.stopLocalMcpUpdates = Y(() => this.registerLocalMcp()));
315
318
  const r = ++this.localMcpTicket;
316
- Y({
319
+ $({
317
320
  arrange: (n = (a = this.application) == null ? void 0 : a.arrange) == null ? void 0 : n[0],
318
- initMcp: u.mcp,
319
- apiRoot: u.apiRoot,
321
+ initMcp: p.mcp,
322
+ apiRoot: p.apiRoot,
320
323
  token: this.token,
321
324
  socket: e,
322
325
  isCurrent: () => r === this.localMcpTicket
@@ -348,11 +351,11 @@ class se extends D {
348
351
  return y(this, null, function* () {
349
352
  var n, t, s;
350
353
  this.convertKnowledgesToChatFormat(this.knowledges);
351
- let a = w(h({}, e), {
352
- promptVariables: this.promptVariables.filter((i) => i.type === A.User).reduce((i, l) => w(h({}, i), {
354
+ let a = C(h({}, e), {
355
+ promptVariables: this.promptVariables.filter((i) => i.type === A.User).reduce((i, l) => C(h({}, i), {
353
356
  [l.key]: l.value
354
357
  }), {}),
355
- systemPromptVariables: this.promptVariables.filter((i) => i.type === A.System).reduce((i, l) => w(h({}, i), {
358
+ systemPromptVariables: this.promptVariables.filter((i) => i.type === A.System).reduce((i, l) => C(h({}, i), {
356
359
  [l.key]: l.value
357
360
  }), {}),
358
361
  knowledges: (n = this.knowledges) == null ? void 0 : n.map((i) => i.id),
@@ -387,7 +390,7 @@ class se extends D {
387
390
  const i = (...d) => {
388
391
  s || (s = !0, this.inflightCalls.delete(t), !(this._stopAnswer || t.signal.aborted) && a(...d));
389
392
  }, l = {
390
- requestId: n.requestId || J(),
393
+ requestId: n.requestId || B(),
391
394
  applicationId: this._applicationId,
392
395
  sessionId: this.id,
393
396
  pluginCode: n.pluginCode,
@@ -421,7 +424,8 @@ class se extends D {
421
424
  return this.abortClientPluginCalls(), super.inactivate(e);
422
425
  }
423
426
  destroy() {
424
- return this.abortClientPluginCalls(), super.destroy();
427
+ var e;
428
+ return (e = this.stopLocalMcpUpdates) == null || e.call(this), this.stopLocalMcpUpdates = void 0, this.abortClientPluginCalls(), super.destroy();
425
429
  }
426
430
  convertKnowledgesToChatFormat(e) {
427
431
  return e ? e.map((r) => r != null && r.fileIds ? {
@@ -431,5 +435,5 @@ class se extends D {
431
435
  }
432
436
  }
433
437
  export {
434
- se as default
438
+ ne as default
435
439
  };
@@ -1,15 +1,15 @@
1
1
  var x = Object.defineProperty, b = Object.defineProperties;
2
2
  var R = Object.getOwnPropertyDescriptors;
3
3
  var v = Object.getOwnPropertySymbols;
4
- var E = Object.prototype.hasOwnProperty, L = Object.prototype.propertyIsEnumerable;
4
+ var L = Object.prototype.hasOwnProperty, E = Object.prototype.propertyIsEnumerable;
5
5
  var m = (h, i, e) => i in h ? x(h, i, { enumerable: !0, configurable: !0, writable: !0, value: e }) : h[i] = e, _ = (h, i) => {
6
6
  for (var e in i || (i = {}))
7
- E.call(i, e) && m(h, e, i[e]);
7
+ L.call(i, e) && m(h, e, i[e]);
8
8
  if (v)
9
9
  for (var e of v(i))
10
- L.call(i, e) && m(h, e, i[e]);
10
+ E.call(i, e) && m(h, e, i[e]);
11
11
  return h;
12
- }, u = (h, i) => b(h, R(i));
12
+ }, g = (h, i) => b(h, R(i));
13
13
  var l = (h, i, e) => (m(h, typeof i != "symbol" ? i + "" : i, e), e);
14
14
  var p = (h, i, e) => new Promise((t, o) => {
15
15
  var n = (a) => {
@@ -31,25 +31,26 @@ import { parseJWT as y } from "./utils.mjs";
31
31
  import W from "./Logger.mjs";
32
32
  import { getAIShopService as M, getCVForceService as T } from "./api/index.mjs";
33
33
  import { configure as k, configuration as f, setActiveLocalWorkspace as S, refreshBuiltinPlugins as w } from "./Config.mjs";
34
- import { PlatformSkillSync as C } from "./builtinTools/platformSkills.mjs";
35
- import { HostBridgeAdapter as B } from "./localFiles/adapters/HostBridgeAdapter.mjs";
34
+ import { PlatformSkillSync as B } from "./builtinTools/platformSkills.mjs";
35
+ import { HostBridgeAdapter as C } from "./localFiles/adapters/HostBridgeAdapter.mjs";
36
36
  import { connectHostBridge as V } from "./localFiles/host/connectHostBridge.mjs";
37
- import { LocalWorkspace as O } from "./localFiles/workspace/LocalWorkspace.mjs";
38
- import { createIndexedDbStore as H } from "./localFiles/workspace/handleStore.mjs";
39
- import { createDefaultSessionFileTransfer as P } from "./localFiles/transfer/SessionFileTransfer.mjs";
40
- import { ApplicationTypes as g, PromptVariableType as A } from "@glodon-aiot/apis";
41
- import D from "./AgentSession.mjs";
42
- import F from "./DialogSession.mjs";
43
- import j from "./EventBus.mjs";
44
- import Q from "./package.json.mjs";
37
+ import { connectLocalMcpBridge as O } from "./localMcp/endpoints.mjs";
38
+ import { LocalWorkspace as H } from "./localFiles/workspace/LocalWorkspace.mjs";
39
+ import { createIndexedDbStore as P } from "./localFiles/workspace/handleStore.mjs";
40
+ import { createDefaultSessionFileTransfer as D } from "./localFiles/transfer/SessionFileTransfer.mjs";
41
+ import { ApplicationTypes as u, PromptVariableType as A } from "@glodon-aiot/apis";
42
+ import F from "./AgentSession.mjs";
43
+ import j from "./DialogSession.mjs";
44
+ import Q from "./EventBus.mjs";
45
+ import z from "./package.json.mjs";
45
46
  const I = new W("[BotClient] ");
46
- class ni {
47
+ class ri {
47
48
  constructor(i, e, t = !0, o = {
48
49
  analytics: {
49
50
  enabled: !1
50
51
  }
51
52
  }) {
52
- l(this, "event", new j());
53
+ l(this, "event", new Q());
53
54
  l(this, "cvforceApi");
54
55
  //从token解析出来的用户信息
55
56
  l(this, "_applicationId");
@@ -68,9 +69,9 @@ class ni {
68
69
  refreshBuiltinPlugins: !1
69
70
  }), this._applicationId = y(i).rid || f.applicationId, !this._applicationId)
70
71
  throw "token is not vaild";
71
- this.cvforceApi = this.getService(), this.setupLocalWorkspace(), this.loadApplication().then((n) => {
72
- k(u(_({}, e), {
73
- stream: e.stream === void 0 ? (n == null ? void 0 : n.type) === g.Dialog || (n == null ? void 0 : n.type) === g.Agent : e.stream
72
+ this.cvforceApi = this.getService(), O(), this.setupLocalWorkspace(), this.loadApplication().then((n) => {
73
+ k(g(_({}, e), {
74
+ stream: e.stream === void 0 ? (n == null ? void 0 : n.type) === u.Dialog || (n == null ? void 0 : n.type) === u.Agent : e.stream
74
75
  })), this.event.emit("ready");
75
76
  });
76
77
  }
@@ -86,13 +87,13 @@ class ni {
86
87
  e.push(new Error(`[LocalFiles] 不支持的 backend:${i.backend}`));
87
88
  else {
88
89
  const r = M(f.apiRoot, this.token, (s, a) => I.error(a));
89
- this._localWorkspace = new O({
90
+ this._localWorkspace = new H({
90
91
  applicationId: this._applicationId,
91
92
  config: i,
92
- store: H(),
93
+ store: P(),
93
94
  picker: t === "host-bridge" ? null : void 0,
94
- transfer: P(() => this.cvforceApi, () => r)
95
- }), S(this._localWorkspace), this._localWorkspace.platformSkills = new C({
95
+ transfer: D(() => this.cvforceApi, () => r)
96
+ }), S(this._localWorkspace), this._localWorkspace.platformSkills = new B({
96
97
  applicationId: () => this._applicationId,
97
98
  getToken: () => this.token,
98
99
  getSkills: () => {
@@ -103,7 +104,7 @@ class ni {
103
104
  getSandbox: () => {
104
105
  var a;
105
106
  const s = (a = this._localWorkspace) == null ? void 0 : a.adapter;
106
- return s instanceof B ? s.sandbox : void 0;
107
+ return s instanceof C ? s.sandbox : void 0;
107
108
  }
108
109
  }), t === "host-bridge" ? this._disconnectHost = V(this._localWorkspace) : this._localWorkspace.restore();
109
110
  }
@@ -148,10 +149,10 @@ class ni {
148
149
  {
149
150
  ui: (e = this.sdkConfigs.ui) == null ? void 0 : e.name,
150
151
  uiVersion: (t = this.sdkConfigs.ui) == null ? void 0 : t.version,
151
- sdkVersion: Q.version
152
+ sdkVersion: z.version
152
153
  }
153
- ).then((s) => (typeof s.arrange[0].thinkingModeOpen != "boolean" && (s.arrange[0].thinkingModeOpen = !0), typeof s.arrange[0].thinkingTextOpen != "boolean" && (s.arrange[0].thinkingTextOpen = !0), u(_({}, s), {
154
- arrange: [u(_({}, s.arrange[0]), {
154
+ ).then((s) => (typeof s.arrange[0].thinkingModeOpen != "boolean" && (s.arrange[0].thinkingModeOpen = !0), typeof s.arrange[0].thinkingTextOpen != "boolean" && (s.arrange[0].thinkingTextOpen = !0), g(_({}, s), {
155
+ arrange: [g(_({}, s.arrange[0]), {
155
156
  recommendQuestionOpen: f.loadRelatedQuesions && s.arrange[0].recommendQuestionOpen
156
157
  })]
157
158
  })));
@@ -196,10 +197,10 @@ class ni {
196
197
  const r = this;
197
198
  return new Promise((s, a) => {
198
199
  const c = (d) => p(this, null, function* () {
199
- if (d === g.Agent)
200
- s(new D(i, e, t, o, n, r));
201
- else if (d === g.Dialog)
200
+ if (d === u.Agent)
202
201
  s(new F(i, e, t, o, n, r));
202
+ else if (d === u.Dialog)
203
+ s(new j(i, e, t, o, n, r));
203
204
  else
204
205
  throw Error(`不支持的应用类型:${d}`);
205
206
  });
@@ -340,5 +341,5 @@ class ni {
340
341
  }
341
342
  }
342
343
  export {
343
- ni as default
344
+ ri as default
344
345
  };