@glodon-aiot/bot-client-sdk 3.26.0-alpha.23 → 3.26.0-alpha.24

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 (83) hide show
  1. package/README.md +180 -130
  2. package/dist/es/AgentSession.mjs +148 -129
  3. package/dist/es/BotClient.mjs +154 -136
  4. package/dist/es/Config.mjs +56 -89
  5. package/dist/es/Session.mjs +35 -23
  6. package/dist/es/builtinTools/browserRuntime/BrowserCommandRunner.mjs +201 -0
  7. package/dist/es/builtinTools/browserRuntime/PythonRunner.mjs +356 -0
  8. package/dist/es/builtinTools/browserRuntime/WorkspaceBashFs.mjs +350 -0
  9. package/dist/es/builtinTools/browserRuntime/assets.mjs +9 -0
  10. package/dist/es/builtinTools/browserRuntime/loadBash.mjs +17 -0
  11. package/dist/es/builtinTools/browserRuntime/pyodideRunner.py.mjs +96 -0
  12. package/dist/es/builtinTools/browserRuntime/pyodideWorker.mjs +242 -0
  13. package/dist/es/builtinTools/command.mjs +56 -0
  14. package/dist/es/builtinTools/constants.mjs +10 -0
  15. package/dist/es/builtinTools/createBuiltinToolsPlugin.mjs +262 -0
  16. package/dist/es/builtinTools/overview.mjs +77 -0
  17. package/dist/es/builtinTools/paths.mjs +69 -0
  18. package/dist/es/builtinTools/platformSkills.mjs +210 -0
  19. package/dist/es/builtinTools/schemas.mjs +216 -0
  20. package/dist/es/builtinTools/tools.mjs +494 -0
  21. package/dist/es/index.mjs +66 -64
  22. package/dist/es/localFiles/adapters/FileSnapshotAdapter.mjs +160 -0
  23. package/dist/es/localFiles/adapters/FileSystemAccessAdapter.mjs +185 -113
  24. package/dist/es/localFiles/adapters/HostBridgeAdapter.mjs +127 -137
  25. package/dist/es/localFiles/adapters/MemoryWorkspaceAdapter.mjs +132 -97
  26. package/dist/es/localFiles/adapters/WorkspaceFileAdapter.mjs +32 -28
  27. package/dist/es/localFiles/constants.mjs +24 -29
  28. package/dist/es/localFiles/errors.mjs +21 -19
  29. package/dist/es/localFiles/host/connectHostBridge.mjs +37 -34
  30. package/dist/es/localFiles/host/protocol.mjs +27 -13
  31. package/dist/es/localFiles/host/sandboxClient.mjs +476 -0
  32. package/dist/es/localFiles/host/sandboxFrames.mjs +21 -0
  33. package/dist/es/localFiles/preview.mjs +33 -0
  34. package/dist/es/localFiles/schemas.mjs +40 -86
  35. package/dist/es/localFiles/validate.mjs +37 -37
  36. package/dist/es/localFiles/workspace/LocalWorkspace.mjs +167 -86
  37. package/dist/es/localFiles/workspace/WorkspaceFiles.mjs +246 -0
  38. package/dist/es/localMcp/client.mjs +223 -0
  39. package/dist/es/localMcp/register.mjs +155 -0
  40. package/dist/es/localMcp/registry.mjs +39 -0
  41. package/dist/es/package.json.mjs +38 -29
  42. package/dist/es/sessionUpload.mjs +49 -0
  43. package/dist/lib/index.js +379 -10
  44. package/dist/src/AgentSession.d.ts +2 -0
  45. package/dist/src/Config.d.ts +5 -7
  46. package/dist/src/Session.d.ts +6 -0
  47. package/dist/src/builtinTools/browserRuntime/BrowserCommandRunner.d.ts +26 -0
  48. package/dist/src/builtinTools/browserRuntime/PythonRunner.d.ts +67 -0
  49. package/dist/src/builtinTools/browserRuntime/WorkspaceBashFs.d.ts +51 -0
  50. package/dist/src/builtinTools/browserRuntime/assets.d.ts +13 -0
  51. package/dist/src/builtinTools/browserRuntime/loadBash.d.ts +3 -0
  52. package/dist/src/builtinTools/browserRuntime/pyodideWorker.d.ts +44 -0
  53. package/dist/src/builtinTools/command.d.ts +35 -0
  54. package/dist/src/builtinTools/constants.d.ts +17 -0
  55. package/dist/src/builtinTools/createBuiltinToolsPlugin.d.ts +11 -0
  56. package/dist/src/builtinTools/overview.d.ts +5 -0
  57. package/dist/src/builtinTools/paths.d.ts +16 -0
  58. package/dist/src/builtinTools/platformSkills.d.ts +67 -0
  59. package/dist/src/builtinTools/schemas.d.ts +3 -0
  60. package/dist/src/builtinTools/tools.d.ts +64 -0
  61. package/dist/src/index.d.ts +2 -1
  62. package/dist/src/localFiles/adapters/FileSnapshotAdapter.d.ts +24 -0
  63. package/dist/src/localFiles/adapters/FileSystemAccessAdapter.d.ts +4 -1
  64. package/dist/src/localFiles/adapters/HostBridgeAdapter.d.ts +30 -14
  65. package/dist/src/localFiles/adapters/MemoryWorkspaceAdapter.d.ts +4 -1
  66. package/dist/src/localFiles/adapters/WorkspaceFileAdapter.d.ts +22 -0
  67. package/dist/src/localFiles/adapters/fsaTypes.d.ts +2 -0
  68. package/dist/src/localFiles/constants.d.ts +3 -13
  69. package/dist/src/localFiles/host/protocol.d.ts +34 -16
  70. package/dist/src/localFiles/host/sandboxClient.d.ts +104 -0
  71. package/dist/src/localFiles/host/sandboxFrames.d.ts +9 -0
  72. package/dist/src/localFiles/index.d.ts +11 -6
  73. package/dist/src/localFiles/preview.d.ts +2 -0
  74. package/dist/src/localFiles/schemas.d.ts +2 -5
  75. package/dist/src/localFiles/types.d.ts +16 -23
  76. package/dist/src/localFiles/workspace/LocalWorkspace.d.ts +35 -1
  77. package/dist/src/localFiles/workspace/WorkspaceFiles.d.ts +63 -0
  78. package/dist/src/localMcp/client.d.ts +11 -0
  79. package/dist/src/localMcp/register.d.ts +32 -0
  80. package/dist/src/localMcp/registry.d.ts +26 -0
  81. package/dist/src/sessionUpload.d.ts +14 -0
  82. package/package.json +13 -4
  83. package/dist/es/localFiles/createLocalPythonPlugin.mjs +0 -196
@@ -1,125 +1,127 @@
1
- var q = Object.defineProperty, j = Object.defineProperties;
2
- var L = Object.getOwnPropertyDescriptors;
3
- var b = Object.getOwnPropertySymbols;
1
+ var L = Object.defineProperty, q = Object.defineProperties;
2
+ var j = Object.getOwnPropertyDescriptors;
3
+ var P = Object.getOwnPropertySymbols;
4
4
  var F = Object.prototype.hasOwnProperty, N = Object.prototype.propertyIsEnumerable;
5
- var M = (r, c, e) => c in r ? q(r, c, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[c] = e, m = (r, c) => {
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) => {
6
6
  for (var e in c || (c = {}))
7
- F.call(c, e) && M(r, e, c[e]);
8
- if (b)
9
- for (var e of b(c))
10
- N.call(c, e) && M(r, e, c[e]);
11
- return r;
12
- }, w = (r, c) => j(r, L(c));
13
- var P = (r, c, e) => (M(r, typeof c != "symbol" ? c + "" : c, e), e);
14
- var y = (r, c, e) => new Promise((o, a) => {
7
+ F.call(c, e) && M(o, e, c[e]);
8
+ if (P)
9
+ for (var e of P(c))
10
+ N.call(c, e) && M(o, e, c[e]);
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);
14
+ var y = (o, c, e) => new Promise((r, a) => {
15
15
  var n = (i) => {
16
16
  try {
17
17
  s(e.next(i));
18
- } catch (d) {
19
- a(d);
18
+ } catch (l) {
19
+ a(l);
20
20
  }
21
21
  }, t = (i) => {
22
22
  try {
23
23
  s(e.throw(i));
24
- } catch (d) {
25
- a(d);
24
+ } catch (l) {
25
+ a(l);
26
26
  }
27
- }, s = (i) => i.done ? o(i.value) : Promise.resolve(i.value).then(n, t);
28
- s((e = e.apply(r, c)).next());
27
+ }, s = (i) => i.done ? r(i.value) : Promise.resolve(i.value).then(n, t);
28
+ s((e = e.apply(o, c)).next());
29
29
  });
30
- import { ChatMessageRole as v, PromptVariableType as A } from "@glodon-aiot/apis";
30
+ import { ChatMessageRole as C, PromptVariableType as A } from "@glodon-aiot/apis";
31
31
  import O from "./Logger.mjs";
32
- import { configuration as C } from "./Config.mjs";
32
+ import { configuration as u } from "./Config.mjs";
33
33
  import { io as U } from "socket.io-client";
34
- import { UserMode as I } from "./PayloadTypes.mjs";
35
- import D, { SessionErrors as k } from "./Session.mjs";
34
+ import { UserMode as k } from "./PayloadTypes.mjs";
35
+ import D, { SessionErrors as I } from "./Session.mjs";
36
36
  import V from "dayjs";
37
37
  import { v4 as J } from "uuid";
38
- const f = new O("[AgentSession] ");
39
- function _(r) {
40
- if (typeof r != "string")
41
- return r;
42
- const c = r.trim();
38
+ import { registerLocalMcp as Y } from "./localMcp/register.mjs";
39
+ const m = new O("[AgentSession] ");
40
+ function _(o) {
41
+ if (typeof o != "string")
42
+ return o;
43
+ const c = o.trim();
43
44
  if (c)
44
45
  try {
45
46
  return JSON.parse(c);
46
47
  } catch (e) {
47
- return r;
48
+ return o;
48
49
  }
49
50
  }
50
- function E(r) {
51
- return r == null || r === "" || typeof r == "object" && !Array.isArray(r) && Object.keys(r).length === 0;
51
+ function T(o) {
52
+ return o == null || o === "" || typeof o == "object" && !Array.isArray(o) && Object.keys(o).length === 0;
52
53
  }
53
- function Y(r, c) {
54
- const e = _(r == null ? void 0 : r.query);
55
- if (!E(e))
54
+ function $(o, c) {
55
+ const e = _(o == null ? void 0 : o.query);
56
+ if (!T(e))
56
57
  return e;
57
- const o = _(c);
58
- return E(o) && e != null ? e : o;
58
+ const r = _(c);
59
+ return T(r) && e != null ? e : r;
59
60
  }
60
- class Z extends D {
61
- constructor(e, o = "", a, n, t, s) {
62
- super(e, o, a, n, t, s);
63
- P(this, "inflightCalls", /* @__PURE__ */ new Set());
61
+ class se extends D {
62
+ constructor(e, r = "", a, n, t, s) {
63
+ super(e, r, a, n, t, s);
64
+ R(this, "inflightCalls", /* @__PURE__ */ new Set());
65
+ R(this, "localMcpTicket", 0);
64
66
  }
65
67
  prepareConnection() {
66
68
  return new Promise((e) => y(this, null, function* () {
67
69
  this.socket && e(!0);
68
- const o = {
70
+ const r = {
69
71
  version: "1.0",
70
- stream: JSON.stringify(C.stream),
72
+ stream: JSON.stringify(u.stream),
71
73
  appId: this._applicationId,
72
74
  sessionId: this.id,
73
75
  Authorization: `${this.token}`,
74
- userMode: C.debug ? I.Debug : I.Normal
75
- }, a = new URL(C.apiRoot), n = yield U(a.origin, {
76
+ userMode: u.debug ? k.Debug : k.Normal
77
+ }, a = new URL(u.apiRoot), n = yield U(a.origin, {
76
78
  path: a.pathname.replace("api", "socketio") + "/copilot",
77
- query: o,
79
+ query: r,
78
80
  transports: ["websocket"]
79
81
  });
80
82
  n.on("connect", () => {
81
- f.log("socket:connect"), this.event.emit("socket:connect"), n.emit("init");
83
+ m.log("socket:connect"), this.event.emit("socket:connect"), n.emit("init");
82
84
  }), n.on("disconnect", () => {
83
- f.log("socket:disconnect"), this.event.emit("socket:disconnect"), this._ready = !1;
85
+ m.log("socket:disconnect"), this.event.emit("socket:disconnect"), this._ready = !1;
84
86
  }), n.on("ready", (t) => {
85
87
  if (t.code === 200) {
86
- f.log("ready");
87
- const s = C.debug ? I.Debug : I.Normal;
88
- s === I.Debug && t.userMode, this._ready || (this._ready = !0, this.event.emit("ready")), this.frozen = !1, this.registerMcpFromClientConfig(), e(!0);
88
+ 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);
89
91
  } else {
90
92
  this._ready && (this._ready = !1);
91
93
  const s = new Error(
92
- k.SocketConnectionFailed
94
+ I.SocketConnectionFailed
93
95
  // , {
94
96
  // cause: data,
95
97
  // }
96
98
  );
97
- f.error("error", s), this.event.emit("error", s), e(!1);
99
+ m.error("error", s), this.event.emit("error", s), e(!1);
98
100
  }
99
101
  }), n.on("action", (t, s) => y(this, null, function* () {
100
- var R;
102
+ var S;
101
103
  if (this._stopAnswer || !this.id)
102
104
  return;
103
105
  const {
104
106
  type: i,
105
107
  data: {
106
- runnerIsClient: d,
107
- pluginCode: l,
108
+ runnerIsClient: l,
109
+ pluginCode: d,
108
110
  funcCode: g,
109
- parameters: h,
110
- requestBody: x
111
+ parameters: f,
112
+ requestBody: E
111
113
  }
112
- } = t, u = this.messages[this.messages.length - 1];
113
- if (!u.messageId)
114
- 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", {
115
- messageId: u.messageId,
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
118
  action: t
117
- }), this.event.emit("message:updated", u);
119
+ }), this.event.emit("message:updated", p);
118
120
  else {
119
- const p = {
121
+ const v = {
120
122
  messageId: "",
121
123
  content: "",
122
- role: v.Robot,
124
+ role: C.Robot,
123
125
  sessionId: this.id,
124
126
  reference: [],
125
127
  searchReference: [],
@@ -131,14 +133,14 @@ class Z extends D {
131
133
  },
132
134
  isReplying: !0
133
135
  };
134
- this.pushMessage(p), this.event.emit("message:action", {
135
- messageId: p.messageId,
136
+ this.pushMessage(v), this.event.emit("message:action", {
137
+ messageId: v.messageId,
136
138
  action: t
137
139
  });
138
140
  }
139
141
  if (this.inactivating) {
140
- const p = new Error(
141
- k.Inactive
142
+ const v = new Error(
143
+ I.Inactive
142
144
  // {
143
145
  // cause: {
144
146
  // code: -1,
@@ -147,30 +149,30 @@ class Z extends D {
147
149
  // },
148
150
  // }
149
151
  );
150
- f.warn("error", p), this.event.emit("error", p);
151
- } else if (i === "FUNCTION_CALL" && d) {
152
- f.log(`calling function ${g} of plugin ${l} with argument:
153
- ${JSON.stringify(h)}`);
154
- const p = (R = C.plugins) == null ? void 0 : R[l];
155
- if (!p) {
152
+ m.warn("error", v), this.event.emit("error", v);
153
+ } else if (i === "FUNCTION_CALL" && l) {
154
+ m.log(`calling function ${g} of plugin ${d} with argument:
155
+ ${JSON.stringify(f)}`);
156
+ const v = (S = u.plugins) == null ? void 0 : S[d];
157
+ if (!v) {
156
158
  s({
157
159
  code: 404,
158
160
  message: "没有找到插件。"
159
161
  });
160
162
  return;
161
163
  }
162
- const S = p[g];
163
- if (typeof S != "function") {
164
+ const b = v[g];
165
+ if (typeof b != "function") {
164
166
  s({
165
167
  code: 404,
166
168
  message: "没有找到插件方法。"
167
169
  });
168
170
  return;
169
171
  }
170
- const T = Y(h, x);
171
- this.invokeClientPlugin(S, T, s, {
172
+ const x = $(f, E);
173
+ this.invokeClientPlugin(b, x, s, {
172
174
  requestId: t.requestId,
173
- pluginCode: l,
175
+ pluginCode: d,
174
176
  functionCode: g
175
177
  });
176
178
  }
@@ -178,12 +180,12 @@ class Z extends D {
178
180
  if (!this._stopAnswer)
179
181
  if (t.data.code !== 200 && (t.data.index = -1), t.data.stream || t.data.stream === void 0) {
180
182
  let s = this.messages[this.messages.length - 1];
181
- if (s && s.role === v.Robot)
183
+ if (s && s.role === C.Robot)
182
184
  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));
183
185
  else {
184
186
  const i = {
185
187
  content: "",
186
- role: v.Robot,
188
+ role: C.Robot,
187
189
  reference: [],
188
190
  searchReference: [],
189
191
  messageId: "",
@@ -205,15 +207,15 @@ class Z extends D {
205
207
  };
206
208
  this.handleStreamAnswer(t.data, i), this.pushMessage(i), this.event.emit("message:content", i), i.index === -1 && (i.isReplying = !1, this.event.emit("answer:finish", i));
207
209
  }
208
- } else if (t.data.updateSession && this.data && (this.data = m(m({}, this.data), t.data.updateSession), this.event.emit("data:updated", this.data)), t.data.index === -1) {
210
+ } else if (t.data.updateSession && this.data && (this.data = h(h({}, this.data), t.data.updateSession), this.event.emit("data:updated", this.data)), t.data.index === -1) {
209
211
  let s = this.messages[this.messages.length - 1];
210
212
  if (s && !s.messageId)
211
- s = m(m({}, s), t.data), this.event.emit("message:content", s), this.event.emit("message:updated", s), this.event.emit("answer:finish", s);
213
+ s = h(h({}, s), t.data), this.event.emit("message:content", s), this.event.emit("message:updated", s), this.event.emit("answer:finish", s);
212
214
  else {
213
- const i = m({
215
+ const i = h({
214
216
  messageId: "",
215
217
  content: "",
216
- role: v.Robot,
218
+ role: C.Robot,
217
219
  sessionId: this.id,
218
220
  reference: [],
219
221
  searchReference: [],
@@ -229,10 +231,10 @@ class Z extends D {
229
231
  }
230
232
  } else {
231
233
  let s = this.messages[this.messages.length - 1];
232
- s && !s.messageId ? (s = m(m({}, s), t.data), this.messages[this.messages.length - 1] = s, this.event.emit("message:content", s), this.event.emit("message:updated", s)) : (this.pushMessage(m({
234
+ 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({
233
235
  messageId: "",
234
236
  content: "",
235
- role: v.Robot,
237
+ role: C.Robot,
236
238
  sessionId: this.id,
237
239
  reference: [],
238
240
  searchReference: [],
@@ -249,28 +251,28 @@ class Z extends D {
249
251
  if (this._stopAnswer)
250
252
  return;
251
253
  if (!this.id) {
252
- const h = new Error(
253
- k.IdUndefined
254
+ const f = new Error(
255
+ I.IdUndefined
254
256
  // {
255
257
  // cause: SESSION_ERROR_CAUSE[SessionErrors.IdUndefined],
256
258
  // }
257
259
  );
258
- f.error(h), this.event.emit("error", h), this.frozen = !1;
260
+ m.error(f), this.event.emit("error", f), this.frozen = !1;
259
261
  return;
260
262
  }
261
263
  const {
262
264
  type: s,
263
265
  data: i,
264
- requestId: d
265
- } = t, l = this.messages.findIndex((h) => h.messageId === d && h.role === v.User);
266
- if (l < 0)
266
+ requestId: l
267
+ } = t, d = this.messages.findIndex((f) => f.messageId === l && f.role === C.User);
268
+ if (d < 0)
267
269
  return;
268
- const g = l + 1;
270
+ const g = d + 1;
269
271
  if (g >= this.messages.length) {
270
- const h = {
272
+ const f = {
271
273
  messageId: "",
272
274
  content: "",
273
- role: v.Robot,
275
+ role: C.Robot,
274
276
  sessionId: this.id,
275
277
  reference: [],
276
278
  searchReference: [],
@@ -282,59 +284,76 @@ class Z extends D {
282
284
  },
283
285
  isReplying: !0
284
286
  };
285
- this.pushMessage(h);
287
+ this.pushMessage(f);
286
288
  }
287
- s === "KG" ? (this.messages[g] = w(m({}, this.messages[g]), {
289
+ s === "KG" ? (this.messages[g] = w(h({}, this.messages[g]), {
288
290
  reference: i.knowledgeReference
289
- }), 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(m({}, this.messages[g]), {
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]), {
290
292
  searchReference: i.knowledgeReference
291
293
  }), this.event.emit("message:searchreference", i.searchReference), this.event.emit("message:updated", this.messages[g]));
292
294
  })), this.socket = n, n.open();
293
295
  }));
294
296
  }
295
297
  registerMcpFromClientConfig() {
296
- return C.mcp ? new Promise((e, o) => {
298
+ return u.mcp ? new Promise((e, r) => {
297
299
  if (!this.socket) {
298
- o("socket is undefined");
300
+ r("socket is undefined");
299
301
  return;
300
302
  }
301
- this.socket.emit("add_mcp_servers", C.mcp, (a) => {
303
+ this.socket.emit("add_mcp_servers", u.mcp, (a) => {
302
304
  a.code === 200 ? (Object.keys(a.data).forEach((n) => {
303
305
  a.data[n].code !== 200 && console.error(n, "MCP Server 注册失败。", a.data[n]);
304
- }), e(!0)) : (console.error("MCP Server 注册失败。", a), o(a));
306
+ }), e(!0)) : (console.error("MCP Server 注册失败。", a), r(a));
305
307
  });
306
308
  }) : Promise.resolve(!0);
307
309
  }
310
+ registerLocalMcp() {
311
+ var a, n;
312
+ const e = this.socket;
313
+ if (!e)
314
+ return;
315
+ const r = ++this.localMcpTicket;
316
+ Y({
317
+ arrange: (n = (a = this.application) == null ? void 0 : a.arrange) == null ? void 0 : n[0],
318
+ initMcp: u.mcp,
319
+ apiRoot: u.apiRoot,
320
+ token: this.token,
321
+ socket: e,
322
+ isCurrent: () => r === this.localMcpTicket
323
+ }).catch((t) => {
324
+ m.error("local mcp", t instanceof Error ? t.message : String(t));
325
+ });
326
+ }
308
327
  addMcpServers(e) {
309
328
  return y(this, null, function* () {
310
- return this.ready ? this.socket ? new Promise((o, a) => {
329
+ return this.ready ? this.socket ? new Promise((r, a) => {
311
330
  this.socket && this.socket.emit("add_mcp_servers", e, (n) => {
312
331
  n.code === 200 ? (Object.keys(n.data).forEach((t) => {
313
332
  n.data[t].code !== 200 && console.error(t, "MCP Server 注册失败。", n.data[t]);
314
- }), o(!0)) : (console.error("MCP Server 注册失败。", n), a(n));
333
+ }), r(!0)) : (console.error("MCP Server 注册失败。", n), a(n));
315
334
  });
316
335
  }) : (console.error(" socket is undefined."), Promise.reject("socket is undefined")) : (console.error("session is not avalible."), Promise.reject("session is not avalible"));
317
336
  });
318
337
  }
319
338
  listMcpServers() {
320
339
  return y(this, null, function* () {
321
- return this.ready ? this.socket ? new Promise((e, o) => {
340
+ return this.ready ? this.socket ? new Promise((e, r) => {
322
341
  this.socket && this.socket.emit("list_mcp_servers", (a) => {
323
- a.code === 200 ? e(a.data) : o(a);
342
+ a.code === 200 ? e(a.data) : r(a);
324
343
  });
325
344
  }) : (console.error(" socket is undefined."), Promise.reject("socket is undefined")) : (console.error("session is not avalible."), Promise.reject("session is not avalible"));
326
345
  });
327
346
  }
328
- sendQuestion(e, o) {
347
+ sendQuestion(e, r) {
329
348
  return y(this, null, function* () {
330
349
  var n, t, s;
331
350
  this.convertKnowledgesToChatFormat(this.knowledges);
332
- let a = w(m({}, e), {
333
- promptVariables: this.promptVariables.filter((i) => i.type === A.User).reduce((i, d) => w(m({}, i), {
334
- [d.key]: d.value
351
+ let a = w(h({}, e), {
352
+ promptVariables: this.promptVariables.filter((i) => i.type === A.User).reduce((i, l) => w(h({}, i), {
353
+ [l.key]: l.value
335
354
  }), {}),
336
- systemPromptVariables: this.promptVariables.filter((i) => i.type === A.System).reduce((i, d) => w(m({}, i), {
337
- [d.key]: d.value
355
+ systemPromptVariables: this.promptVariables.filter((i) => i.type === A.System).reduce((i, l) => w(h({}, i), {
356
+ [l.key]: l.value
338
357
  }), {}),
339
358
  knowledges: (n = this.knowledges) == null ? void 0 : n.map((i) => i.id),
340
359
  //agent支持指定文件时再放开
@@ -344,12 +363,12 @@ class Z extends D {
344
363
  if (!this.active) {
345
364
  if (yield this.activate(), !this.socket) {
346
365
  const i = new Error(
347
- k.SocketConnectionFailed
366
+ I.SocketConnectionFailed
348
367
  // {
349
368
  // cause: { code: -1, message: 'socket is null' },
350
369
  // }
351
370
  );
352
- return f.warn("error", i), this.event.emit("error", i), !1;
371
+ return m.warn("error", i), this.event.emit("error", i), !1;
353
372
  }
354
373
  (t = this.socket) == null || t.emit("question", a);
355
374
  return;
@@ -361,13 +380,13 @@ class Z extends D {
361
380
  * 调用客户端插件:传入第三个参数 context(旧插件可忽略),结果最多回传一次,
362
381
  * 停止回答或调用被取消后不再回传。
363
382
  */
364
- invokeClientPlugin(e, o, a, n) {
383
+ invokeClientPlugin(e, r, a, n) {
365
384
  const t = new AbortController();
366
385
  this.inflightCalls.add(t);
367
386
  let s = !1;
368
- const i = (...l) => {
369
- s || (s = !0, this.inflightCalls.delete(t), !(this._stopAnswer || t.signal.aborted) && a(...l));
370
- }, d = {
387
+ const i = (...d) => {
388
+ s || (s = !0, this.inflightCalls.delete(t), !(this._stopAnswer || t.signal.aborted) && a(...d));
389
+ }, l = {
371
390
  requestId: n.requestId || J(),
372
391
  applicationId: this._applicationId,
373
392
  sessionId: this.id,
@@ -376,15 +395,15 @@ class Z extends D {
376
395
  signal: t.signal
377
396
  };
378
397
  try {
379
- const l = e(o, i, d);
380
- l && typeof l.catch == "function" && l.catch((g) => {
381
- f.error("client plugin failed", g), i({
398
+ const d = e(r, i, l);
399
+ d && typeof d.catch == "function" && d.catch((g) => {
400
+ m.error("client plugin failed", g), i({
382
401
  code: 500,
383
402
  message: "客户端插件执行失败。"
384
403
  });
385
404
  });
386
- } catch (l) {
387
- f.error("client plugin failed", l), i({
405
+ } catch (d) {
406
+ m.error("client plugin failed", d), i({
388
407
  code: 500,
389
408
  message: "客户端插件执行失败。"
390
409
  });
@@ -392,7 +411,7 @@ class Z extends D {
392
411
  }
393
412
  abortClientPluginCalls() {
394
413
  const e = Array.from(this.inflightCalls);
395
- this.inflightCalls.clear(), e.forEach((o) => o.abort());
414
+ this.inflightCalls.clear(), e.forEach((r) => r.abort());
396
415
  }
397
416
  stopAnswer() {
398
417
  var e;
@@ -405,12 +424,12 @@ class Z extends D {
405
424
  return this.abortClientPluginCalls(), super.destroy();
406
425
  }
407
426
  convertKnowledgesToChatFormat(e) {
408
- return e ? e.map((o) => o != null && o.fileIds ? {
409
- id: o.id,
410
- fileIds: o.fileIds
411
- } : o.id) : [];
427
+ return e ? e.map((r) => r != null && r.fileIds ? {
428
+ id: r.id,
429
+ fileIds: r.fileIds
430
+ } : r.id) : [];
412
431
  }
413
432
  }
414
433
  export {
415
- Z as default
434
+ se as default
416
435
  };