@glodon-aiot/bot-client-sdk 3.26.0 → 3.27.0-alpha.0

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/README.md CHANGED
@@ -50,6 +50,7 @@ const client = new BotClient(token, {
50
50
  env: 'dev', // 'dev' | 'test' | 'prod' | 'local',决定默认 API 地址
51
51
  // apiRoot: 'https://example.com/api/cvforce', // 传入后覆盖 env
52
52
  stream: true, // 省略时 Agent / 对话型默认流式
53
+ // appVersion: 'v1', // 编排版本:draft | latest | v1/v2…;省略时默认传 latest
53
54
  // plugins、builtinPlugins 见「Agent 插件」
54
55
  });
55
56
 
@@ -65,6 +66,8 @@ client.addEventListener('ready', () => {
65
66
 
66
67
  应用类型由平台应用决定,`loadSession` 按类型创建对应会话。
67
68
 
69
+ `appVersion` 只作用于 Agent 的 WebSocket 建连。`draft` 使用草稿,`v1` / `v2` 等指定已发布版本(大小写不敏感),`latest` 始终使用最新版本。不传或传空白时 SDK 默认传 `latest`。其他值不会导致连接失败,服务端会改用最新版本。ready 带回的版本与请求不一致时,SDK 输出告警。
70
+
68
71
  ## 对话界面
69
72
 
70
73
  界面自管渲染状态,数据以 `session.messages` 为准。事件都带当前消息或列表,收到后重绘即可。
@@ -1,84 +1,90 @@
1
- var E = Object.defineProperty, x = Object.defineProperties;
2
- var j = Object.getOwnPropertyDescriptors;
3
- var P = Object.getOwnPropertySymbols;
4
- var O = Object.prototype.hasOwnProperty, F = Object.prototype.propertyIsEnumerable;
5
- var S = (r, d, e) => d in r ? E(r, d, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[d] = e, h = (r, d) => {
1
+ var x = Object.defineProperty, j = Object.defineProperties;
2
+ var O = Object.getOwnPropertyDescriptors;
3
+ var T = Object.getOwnPropertySymbols;
4
+ var V = Object.prototype.hasOwnProperty, F = Object.prototype.propertyIsEnumerable;
5
+ var S = (n, d, e) => d in n ? x(n, d, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[d] = e, m = (n, d) => {
6
6
  for (var e in d || (d = {}))
7
- O.call(d, e) && S(r, e, d[e]);
8
- if (P)
9
- for (var e of P(d))
10
- F.call(d, e) && S(r, e, d[e]);
11
- return r;
12
- }, y = (r, d) => x(r, j(d));
13
- var w = (r, d, e) => (S(r, typeof d != "symbol" ? d + "" : d, e), e);
14
- var v = (r, d, e) => new Promise((i, a) => {
15
- var n = (t) => {
7
+ V.call(d, e) && S(n, e, d[e]);
8
+ if (T)
9
+ for (var e of T(d))
10
+ F.call(d, e) && S(n, e, d[e]);
11
+ return n;
12
+ }, C = (n, d) => j(n, O(d));
13
+ var I = (n, d, e) => (S(n, typeof d != "symbol" ? d + "" : d, e), e);
14
+ var v = (n, d, e) => new Promise((i, a) => {
15
+ var o = (t) => {
16
16
  try {
17
- s(e.next(t));
18
- } catch (l) {
19
- a(l);
17
+ g(e.next(t));
18
+ } catch (s) {
19
+ a(s);
20
20
  }
21
21
  }, c = (t) => {
22
22
  try {
23
- s(e.throw(t));
24
- } catch (l) {
25
- a(l);
23
+ g(e.throw(t));
24
+ } catch (s) {
25
+ a(s);
26
26
  }
27
- }, s = (t) => t.done ? i(t.value) : Promise.resolve(t.value).then(n, c);
28
- s((e = e.apply(r, d)).next());
27
+ }, g = (t) => t.done ? i(t.value) : Promise.resolve(t.value).then(o, c);
28
+ g((e = e.apply(n, d)).next());
29
29
  });
30
- import { ChatMessageRole as C, PromptVariableType as T } from "@glodon-aiot/apis";
30
+ import { ChatMessageRole as w, PromptVariableType as L } from "@glodon-aiot/apis";
31
31
  import N from "./Logger.mjs";
32
32
  import { configuration as p } from "./Config.mjs";
33
- import { io as D } from "socket.io-client";
34
- import { UserMode as I } from "./PayloadTypes.mjs";
35
- import z, { SessionErrors as R } from "./Session.mjs";
36
- import V from "dayjs";
37
- import { v4 as $ } from "uuid";
38
- import { connectLocalMcpBridge as B, subscribeLocalMcpEndpoints as J } from "./localMcp/endpoints.mjs";
39
- import { registerLocalMcp as Q } from "./localMcp/register.mjs";
40
- const o = new N("[AgentSession] ");
41
- function L(r) {
42
- if (typeof r != "string")
43
- return r;
44
- const d = r.trim();
33
+ import { io as $ } from "socket.io-client";
34
+ import { UserMode as R } from "./PayloadTypes.mjs";
35
+ import D, { SessionErrors as A } from "./Session.mjs";
36
+ import z from "dayjs";
37
+ import { v4 as B } from "uuid";
38
+ import { connectLocalMcpBridge as J, subscribeLocalMcpEndpoints as Q } from "./localMcp/endpoints.mjs";
39
+ import { registerLocalMcp as Y } from "./localMcp/register.mjs";
40
+ const r = new N("[AgentSession] ");
41
+ function U(n) {
42
+ if (typeof n != "string")
43
+ return n;
44
+ const d = n.trim();
45
45
  if (d)
46
46
  try {
47
47
  return JSON.parse(d);
48
48
  } catch (e) {
49
- return r;
49
+ return n;
50
50
  }
51
51
  }
52
- function Y(r) {
53
- const d = r.imageContent;
54
- return Array.isArray(d) ? y(h({}, r), {
52
+ function H(n) {
53
+ const d = n.imageContent;
54
+ return Array.isArray(d) ? C(m({}, n), {
55
55
  imageContent: `[${d.length}]`
56
- }) : r;
56
+ }) : n;
57
57
  }
58
- function U(r) {
59
- return r == null || r === "" || typeof r == "object" && !Array.isArray(r) && Object.keys(r).length === 0;
58
+ function K(n, d) {
59
+ if (typeof d != "string")
60
+ return;
61
+ const e = d.trim();
62
+ !e || n.trim().toLowerCase() === e.toLowerCase() || console.warn(`[AgentSession] 应用版本「${n}」未生效,服务端已改用「${e}」。`);
60
63
  }
61
- function H(r, d) {
62
- const e = L(r == null ? void 0 : r.query);
63
- if (!U(e))
64
+ function _(n) {
65
+ return n == null || n === "" || typeof n == "object" && !Array.isArray(n) && Object.keys(n).length === 0;
66
+ }
67
+ function G(n, d) {
68
+ const e = U(n == null ? void 0 : n.query);
69
+ if (!_(e))
64
70
  return e;
65
- const i = L(d);
66
- return U(i) && e != null ? e : i;
71
+ const i = U(d);
72
+ return _(i) && e != null ? e : i;
67
73
  }
68
- class re extends z {
69
- constructor(e, i = "", a, n, c, s) {
70
- super(e, i, a, n, c, s);
71
- w(this, "inflightCalls", /* @__PURE__ */ new Set());
72
- w(this, "localMcpTicket", 0);
73
- w(this, "stopLocalMcpUpdates");
74
+ class ce extends D {
75
+ constructor(e, i = "", a, o, c, g) {
76
+ super(e, i, a, o, c, g);
77
+ I(this, "inflightCalls", /* @__PURE__ */ new Set());
78
+ I(this, "localMcpTicket", 0);
79
+ I(this, "stopLocalMcpUpdates");
74
80
  /** 已发出 `update`、尚未收到结果;下一条 ready / ack 按换票结果处理,不拆连接。 */
75
- w(this, "pendingTokenUpdate", !1);
81
+ I(this, "pendingTokenUpdate", !1);
76
82
  }
77
83
  prepareConnection() {
78
84
  return new Promise((e) => v(this, null, function* () {
79
- var c;
85
+ var c, g;
80
86
  if ((c = this.socket) != null && c.connected) {
81
- o.log("socket:reuse", this.id), e(!0);
87
+ r.log("socket:reuse", this.id), e(!0);
82
88
  return;
83
89
  }
84
90
  this.socket && (this.socket.removeAllListeners(), this.socket.close(), this.socket = null);
@@ -88,70 +94,72 @@ class re extends z {
88
94
  appId: this._applicationId,
89
95
  sessionId: this.id,
90
96
  Authorization: `${this.requestToken}`,
91
- userMode: p.debug ? I.Debug : I.Normal
92
- }, a = new URL(p.apiRoot);
93
- o.log("socket:connecting", {
97
+ userMode: p.debug ? R.Debug : R.Normal
98
+ };
99
+ i.appVersion = ((g = p.appVersion) == null ? void 0 : g.trim()) || "latest";
100
+ const a = new URL(p.apiRoot);
101
+ r.log("socket:connecting", {
94
102
  sessionId: this.id,
95
103
  origin: a.origin
96
104
  });
97
- const n = yield D(a.origin, {
105
+ const o = yield $(a.origin, {
98
106
  path: a.pathname.replace("api", "socketio") + "/copilot",
99
107
  query: i,
100
108
  transports: ["websocket"]
101
109
  });
102
- n.on("connect", () => {
103
- o.log("socket:connect"), this.event.emit("socket:connect"), n.emit("init");
104
- }), n.on("disconnect", () => {
105
- o.log("socket:disconnect"), this.event.emit("socket:disconnect"), this._ready = !1, this.pendingTokenUpdate = !1;
106
- }), n.on("ready", (s) => {
110
+ o.on("connect", () => {
111
+ r.log("socket:connect"), this.event.emit("socket:connect"), o.emit("init");
112
+ }), o.on("disconnect", () => {
113
+ r.log("socket:disconnect"), this.event.emit("socket:disconnect"), this._ready = !1, this.pendingTokenUpdate = !1;
114
+ }), o.on("ready", (t) => {
107
115
  if (this.pendingTokenUpdate) {
108
- this.handleResourceTokenUpdateResult(s);
116
+ this.handleResourceTokenUpdateResult(t);
109
117
  return;
110
118
  }
111
- if (s.code === 200) {
112
- o.log("ready");
113
- const t = p.debug ? I.Debug : I.Normal;
114
- t === I.Debug && s.userMode, this._ready || (this._ready = !0, this.event.emit("ready")), this.frozen = !1, this.registerMcpFromClientConfig(), this.registerLocalMcp(), e(!0);
119
+ if (t.code === 200) {
120
+ r.log("ready"), K(i.appVersion, t.appVersion);
121
+ const s = p.debug ? R.Debug : R.Normal;
122
+ s === R.Debug && t.userMode, this._ready || (this._ready = !0, this.event.emit("ready")), this.frozen = !1, this.registerMcpFromClientConfig(), this.registerLocalMcp(), e(!0);
115
123
  } else {
116
124
  this._ready && (this._ready = !1);
117
- const t = new Error(
118
- R.SocketConnectionFailed
125
+ const s = new Error(
126
+ A.SocketConnectionFailed
119
127
  // , {
120
128
  // cause: data,
121
129
  // }
122
130
  );
123
- o.error("error", t), this.event.emit("error", t), e(!1);
131
+ r.error("error", s), this.event.emit("error", s), e(!1);
124
132
  }
125
- }), n.on("action", (s, t) => v(this, null, function* () {
126
- var A;
133
+ }), o.on("action", (t, s) => v(this, null, function* () {
134
+ var b;
127
135
  if (this._stopAnswer || !this.id)
128
136
  return;
129
137
  const {
130
138
  type: l,
131
139
  data: {
132
- runnerIsClient: m,
133
- pluginCode: f,
134
- funcCode: g,
135
- parameters: u,
136
- requestBody: _
140
+ runnerIsClient: y,
141
+ pluginCode: u,
142
+ funcCode: h,
143
+ parameters: f,
144
+ requestBody: q
137
145
  }
138
- } = s, k = this.messages[this.messages.length - 1];
146
+ } = t, k = this.messages[this.messages.length - 1];
139
147
  if (!k.messageId)
140
- k.actions || (k.actions = []), k.actions[s.data.step - 1] || (k.actions[s.data.step - 1] = []), k.actions[s.data.step - 1].push(s), this.event.emit("message:action", {
148
+ k.actions || (k.actions = []), k.actions[t.data.step - 1] || (k.actions[t.data.step - 1] = []), k.actions[t.data.step - 1].push(t), this.event.emit("message:action", {
141
149
  messageId: k.messageId,
142
- action: s
150
+ action: t
143
151
  }), this.event.emit("message:updated", k);
144
152
  else {
145
153
  const M = {
146
154
  messageId: "",
147
155
  content: "",
148
- role: C.Robot,
156
+ role: w.Robot,
149
157
  sessionId: this.id,
150
158
  reference: [],
151
159
  searchReference: [],
152
160
  isLoading: !0,
153
161
  messageTime: "",
154
- actions: [[s]],
162
+ actions: [[t]],
155
163
  comment: {
156
164
  isAgree: 0
157
165
  },
@@ -159,50 +167,50 @@ class re extends z {
159
167
  };
160
168
  this.pushMessage(M), this.event.emit("message:action", {
161
169
  messageId: M.messageId,
162
- action: s
170
+ action: t
163
171
  });
164
172
  }
165
- if (l === "FUNCTION_CALL" && !m && o.log("server function", f, g), l === "FUNCTION_CALL" && m) {
166
- o.log(`calling function ${g} of plugin ${f} with argument:
167
- ${JSON.stringify(u)}`);
168
- const M = (A = p.plugins) == null ? void 0 : A[f];
173
+ if (l === "FUNCTION_CALL" && !y && r.log("server function", u, h), l === "FUNCTION_CALL" && y) {
174
+ r.log(`calling function ${h} of plugin ${u} with argument:
175
+ ${JSON.stringify(f)}`);
176
+ const M = (b = p.plugins) == null ? void 0 : b[u];
169
177
  if (!M) {
170
- o.error("plugin not found", f, g), t({
178
+ r.error("plugin not found", u, h), s({
171
179
  code: 404,
172
180
  message: "没有找到插件。"
173
181
  });
174
182
  return;
175
183
  }
176
- const b = M[g];
177
- if (typeof b != "function") {
178
- o.error("plugin function not found", f, g), t({
184
+ const P = M[h];
185
+ if (typeof P != "function") {
186
+ r.error("plugin function not found", u, h), s({
179
187
  code: 404,
180
188
  message: "没有找到插件方法。"
181
189
  });
182
190
  return;
183
191
  }
184
- const q = H(u, _);
185
- this.invokeClientPlugin(b, q, t, {
186
- requestId: s.requestId,
187
- pluginCode: f,
188
- functionCode: g
192
+ const E = G(f, q);
193
+ this.invokeClientPlugin(P, E, s, {
194
+ requestId: t.requestId,
195
+ pluginCode: u,
196
+ functionCode: h
189
197
  });
190
198
  }
191
- })), n.on("answer", (s) => {
192
- if (o.log("answer", s == null ? void 0 : s.data), !this._stopAnswer)
193
- if (s.data.code !== 200 && (s.data.index = -1), s.data.stream || s.data.stream === void 0) {
194
- let t = this.messages[this.messages.length - 1];
195
- if (t && t.role === C.Robot)
196
- this.handleStreamAnswer(s.data, t), this.messages[this.messages.length - 1] = t, this.event.emit("message:content", t), this.event.emit("message:updated", t), t.index === -1 && (t.isReplying = !1, this.event.emit("answer:finish", t));
199
+ })), o.on("answer", (t) => {
200
+ if (r.log("answer", t == null ? void 0 : t.data), !this._stopAnswer)
201
+ if (t.data.code !== 200 && (t.data.index = -1), t.data.stream || t.data.stream === void 0) {
202
+ let s = this.messages[this.messages.length - 1];
203
+ if (s && s.role === w.Robot)
204
+ 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));
197
205
  else {
198
206
  const l = {
199
207
  content: "",
200
- role: C.Robot,
208
+ role: w.Robot,
201
209
  reference: [],
202
210
  searchReference: [],
203
211
  messageId: "",
204
212
  sessionId: this.id,
205
- messageTime: V(/* @__PURE__ */ new Date()).format("YYYY-MM-DD HH:mm:ss"),
213
+ messageTime: z(/* @__PURE__ */ new Date()).format("YYYY-MM-DD HH:mm:ss"),
206
214
  comment: {
207
215
  isAgree: 0
208
216
  },
@@ -217,17 +225,17 @@ class re extends z {
217
225
  thinkingStatus: "",
218
226
  searchingStatus: ""
219
227
  };
220
- this.handleStreamAnswer(s.data, l), this.pushMessage(l), this.event.emit("message:content", l), l.index === -1 && (l.isReplying = !1, this.event.emit("answer:finish", l));
228
+ this.handleStreamAnswer(t.data, l), this.pushMessage(l), this.event.emit("message:content", l), l.index === -1 && (l.isReplying = !1, this.event.emit("answer:finish", l));
221
229
  }
222
- } else if (s.data.updateSession && this.data && (this.data = h(h({}, this.data), s.data.updateSession), this.event.emit("data:updated", this.data)), s.data.index === -1) {
223
- let t = this.messages[this.messages.length - 1];
224
- if (t && !t.messageId)
225
- t = h(h({}, t), s.data), this.event.emit("message:content", t), this.event.emit("message:updated", t), this.event.emit("answer:finish", t);
230
+ } 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) {
231
+ let s = this.messages[this.messages.length - 1];
232
+ if (s && !s.messageId)
233
+ s = m(m({}, s), t.data), this.event.emit("message:content", s), this.event.emit("message:updated", s), this.event.emit("answer:finish", s);
226
234
  else {
227
- const l = h({
235
+ const l = m({
228
236
  messageId: "",
229
237
  content: "",
230
- role: C.Robot,
238
+ role: w.Robot,
231
239
  sessionId: this.id,
232
240
  reference: [],
233
241
  searchReference: [],
@@ -238,15 +246,15 @@ class re extends z {
238
246
  isAgree: 0
239
247
  },
240
248
  isReplying: !0
241
- }, s.data);
249
+ }, t.data);
242
250
  this.event.emit("message:content", l), this.pushMessage(l), this.event.emit("answer:finish", l);
243
251
  }
244
252
  } else {
245
- let t = this.messages[this.messages.length - 1];
246
- t && !t.messageId ? (t = h(h({}, t), s.data), this.messages[this.messages.length - 1] = t, this.event.emit("message:content", t), this.event.emit("message:updated", t)) : (this.pushMessage(h({
253
+ let s = this.messages[this.messages.length - 1];
254
+ 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({
247
255
  messageId: "",
248
256
  content: "",
249
- role: C.Robot,
257
+ role: w.Robot,
250
258
  sessionId: this.id,
251
259
  reference: [],
252
260
  searchReference: [],
@@ -257,40 +265,40 @@ class re extends z {
257
265
  isAgree: 0
258
266
  },
259
267
  isReplying: !0
260
- }, s.data)), this.event.emit("message:content", s.data));
268
+ }, t.data)), this.event.emit("message:content", t.data));
261
269
  }
262
- }), n.on("reference", (s) => v(this, null, function* () {
270
+ }), o.on("reference", (t) => v(this, null, function* () {
263
271
  if (this._stopAnswer)
264
272
  return;
265
273
  if (!this.id) {
266
- const u = new Error(
267
- R.IdUndefined
274
+ const f = new Error(
275
+ A.IdUndefined
268
276
  // {
269
277
  // cause: SESSION_ERROR_CAUSE[SessionErrors.IdUndefined],
270
278
  // }
271
279
  );
272
- o.error(u), this.event.emit("error", u), this.frozen = !1;
280
+ r.error(f), this.event.emit("error", f), this.frozen = !1;
273
281
  return;
274
282
  }
275
283
  const {
276
- type: t,
284
+ type: s,
277
285
  data: l,
278
- requestId: m
279
- } = s;
280
- o.log("reference", {
281
- type: t,
282
- requestId: m,
286
+ requestId: y
287
+ } = t;
288
+ r.log("reference", {
289
+ type: s,
290
+ requestId: y,
283
291
  data: l
284
292
  });
285
- const f = this.messages.findIndex((u) => u.messageId === m && u.role === C.User);
286
- if (f < 0)
293
+ const u = this.messages.findIndex((f) => f.messageId === y && f.role === w.User);
294
+ if (u < 0)
287
295
  return;
288
- const g = f + 1;
289
- if (g >= this.messages.length) {
290
- const u = {
296
+ const h = u + 1;
297
+ if (h >= this.messages.length) {
298
+ const f = {
291
299
  messageId: "",
292
300
  content: "",
293
- role: C.Robot,
301
+ role: w.Robot,
294
302
  sessionId: this.id,
295
303
  reference: [],
296
304
  searchReference: [],
@@ -302,14 +310,14 @@ class re extends z {
302
310
  },
303
311
  isReplying: !0
304
312
  };
305
- this.pushMessage(u);
313
+ this.pushMessage(f);
306
314
  }
307
- t === "KG" ? (this.messages[g] = y(h({}, this.messages[g]), {
315
+ s === "KG" ? (this.messages[h] = C(m({}, this.messages[h]), {
308
316
  reference: l.knowledgeReference
309
- }), yield this.fillMessageReference(this.messages[g]), this.event.emit("message:reference", l.knowledgeReference), this.event.emit("message:updated", this.messages[g])) : t === "WEB_SEARCH" && (this.messages[g] = y(h({}, this.messages[g]), {
317
+ }), yield this.fillMessageReference(this.messages[h]), this.event.emit("message:reference", l.knowledgeReference), this.event.emit("message:updated", this.messages[h])) : s === "WEB_SEARCH" && (this.messages[h] = C(m({}, this.messages[h]), {
310
318
  searchReference: l.knowledgeReference
311
- }), this.event.emit("message:searchreference", l.searchReference), this.event.emit("message:updated", this.messages[g]));
312
- })), this.socket = n, n.open();
319
+ }), this.event.emit("message:searchreference", l.searchReference), this.event.emit("message:updated", this.messages[h]));
320
+ })), this.socket = o, o.open();
313
321
  }));
314
322
  }
315
323
  registerMcpFromClientConfig() {
@@ -319,39 +327,39 @@ class re extends z {
319
327
  return;
320
328
  }
321
329
  this.socket.emit("add_mcp_servers", p.mcp, (a) => {
322
- a.code === 200 ? (Object.keys(a.data).forEach((n) => {
323
- a.data[n].code !== 200 && o.report(n, "MCP Server 注册失败。", a.data[n]);
324
- }), o.log("mcp:registered", Object.keys(a.data)), e(!0)) : (o.error("MCP Server 注册失败。", a), i(a));
330
+ a.code === 200 ? (Object.keys(a.data).forEach((o) => {
331
+ a.data[o].code !== 200 && r.report(o, "MCP Server 注册失败。", a.data[o]);
332
+ }), r.log("mcp:registered", Object.keys(a.data)), e(!0)) : (r.error("MCP Server 注册失败。", a), i(a));
325
333
  });
326
- }) : (o.log("mcp:skip"), Promise.resolve(!0));
334
+ }) : (r.log("mcp:skip"), Promise.resolve(!0));
327
335
  }
328
336
  registerLocalMcp() {
329
- var a, n;
337
+ var a, o;
330
338
  const e = this.socket;
331
339
  if (!e)
332
340
  return;
333
- B(), this.stopLocalMcpUpdates || (this.stopLocalMcpUpdates = J(() => this.registerLocalMcp()));
341
+ J(), this.stopLocalMcpUpdates || (this.stopLocalMcpUpdates = Q(() => this.registerLocalMcp()));
334
342
  const i = ++this.localMcpTicket;
335
- Q({
336
- arrange: (n = (a = this.application) == null ? void 0 : a.arrange) == null ? void 0 : n[0],
343
+ Y({
344
+ arrange: (o = (a = this.application) == null ? void 0 : a.arrange) == null ? void 0 : o[0],
337
345
  initMcp: p.mcp,
338
346
  apiRoot: p.apiRoot,
339
347
  token: this.requestToken,
340
348
  socket: e,
341
349
  isCurrent: () => i === this.localMcpTicket
342
350
  }).catch((c) => {
343
- o.report("local mcp", c instanceof Error ? c.message : String(c));
351
+ r.report("local mcp", c instanceof Error ? c.message : String(c));
344
352
  });
345
353
  }
346
354
  addMcpServers(e) {
347
355
  return v(this, null, function* () {
348
356
  return this.ready ? this.socket ? new Promise((i, a) => {
349
- this.socket && this.socket.emit("add_mcp_servers", e, (n) => {
350
- n.code === 200 ? (Object.keys(n.data).forEach((c) => {
351
- n.data[c].code !== 200 && o.report(c, "MCP Server 注册失败。", n.data[c]);
352
- }), o.log("mcp:registered", Object.keys(n.data)), i(!0)) : (o.error("MCP Server 注册失败。", n), a(n));
357
+ this.socket && this.socket.emit("add_mcp_servers", e, (o) => {
358
+ o.code === 200 ? (Object.keys(o.data).forEach((c) => {
359
+ o.data[c].code !== 200 && r.report(c, "MCP Server 注册失败。", o.data[c]);
360
+ }), r.log("mcp:registered", Object.keys(o.data)), i(!0)) : (r.error("MCP Server 注册失败。", o), a(o));
353
361
  });
354
- }) : (o.error("socket is undefined."), Promise.reject("socket is undefined")) : (o.error("session is not avalible."), Promise.reject("session is not avalible"));
362
+ }) : (r.error("socket is undefined."), Promise.reject("socket is undefined")) : (r.error("session is not avalible."), Promise.reject("session is not avalible"));
355
363
  });
356
364
  }
357
365
  listMcpServers() {
@@ -360,21 +368,21 @@ class re extends z {
360
368
  this.socket && this.socket.emit("list_mcp_servers", (a) => {
361
369
  a.code === 200 ? e(a.data) : i(a);
362
370
  });
363
- }) : (o.error("socket is undefined."), Promise.reject("socket is undefined")) : (o.error("session is not avalible."), Promise.reject("session is not avalible"));
371
+ }) : (r.error("socket is undefined."), Promise.reject("socket is undefined")) : (r.error("session is not avalible."), Promise.reject("session is not avalible"));
364
372
  });
365
373
  }
366
374
  sendQuestion(e, i) {
367
375
  return v(this, null, function* () {
368
- var n;
376
+ var o;
369
377
  this.convertKnowledgesToChatFormat(this.knowledges);
370
- let a = y(h({}, e), {
371
- promptVariables: this.promptVariables.filter((c) => c.type === T.User).reduce((c, s) => y(h({}, c), {
372
- [s.key]: s.value
378
+ let a = C(m({}, e), {
379
+ promptVariables: this.promptVariables.filter((c) => c.type === L.User).reduce((c, g) => C(m({}, c), {
380
+ [g.key]: g.value
373
381
  }), {}),
374
- systemPromptVariables: this.promptVariables.filter((c) => c.type === T.System).reduce((c, s) => y(h({}, c), {
375
- [s.key]: s.value
382
+ systemPromptVariables: this.promptVariables.filter((c) => c.type === L.System).reduce((c, g) => C(m({}, c), {
383
+ [g.key]: g.value
376
384
  }), {}),
377
- knowledges: (n = this.knowledges) == null ? void 0 : n.map((c) => c.id),
385
+ knowledges: (o = this.knowledges) == null ? void 0 : o.map((c) => c.id),
378
386
  //agent支持指定文件时再放开
379
387
  // knowledges: knowledgesForChat,
380
388
  enableTitleSummary: this.resolveEnableTitleSummary()
@@ -382,12 +390,12 @@ class re extends z {
382
390
  if (!this.active) {
383
391
  if (yield this.activate(), !this.socket) {
384
392
  const c = new Error(
385
- R.SocketConnectionFailed
393
+ A.SocketConnectionFailed
386
394
  // {
387
395
  // cause: { code: -1, message: 'socket is null' },
388
396
  // }
389
397
  );
390
- return o.warn("error", c), this.event.emit("error", c), !1;
398
+ return r.warn("error", c), this.event.emit("error", c), !1;
391
399
  }
392
400
  this.emitQuestion(a);
393
401
  return;
@@ -397,7 +405,7 @@ class re extends z {
397
405
  }
398
406
  emitQuestion(e) {
399
407
  var i;
400
- o.log("question:request", Y(e)), (i = this.socket) == null || i.emit("question", e), o.log("question:sent", {
408
+ r.log("question:request", H(e)), (i = this.socket) == null || i.emit("question", e), r.log("question:sent", {
401
409
  sessionId: this.id
402
410
  });
403
411
  }
@@ -405,30 +413,30 @@ class re extends z {
405
413
  * 调用客户端插件:传入第三个参数 context(旧插件可忽略),结果最多回传一次,
406
414
  * 停止回答或调用被取消后不再回传。
407
415
  */
408
- invokeClientPlugin(e, i, a, n) {
416
+ invokeClientPlugin(e, i, a, o) {
409
417
  const c = new AbortController();
410
418
  this.inflightCalls.add(c);
411
- let s = !1;
412
- const t = (...m) => {
413
- s || (s = !0, this.inflightCalls.delete(c), !(this._stopAnswer || c.signal.aborted) && a(...m));
414
- }, l = {
415
- requestId: n.requestId || $(),
419
+ let g = !1;
420
+ const t = (...l) => {
421
+ g || (g = !0, this.inflightCalls.delete(c), !(this._stopAnswer || c.signal.aborted) && a(...l));
422
+ }, s = {
423
+ requestId: o.requestId || B(),
416
424
  applicationId: this._applicationId,
417
425
  sessionId: this.id,
418
- pluginCode: n.pluginCode,
419
- functionCode: n.functionCode,
426
+ pluginCode: o.pluginCode,
427
+ functionCode: o.functionCode,
420
428
  signal: c.signal
421
429
  };
422
430
  try {
423
- const m = e(i, t, l);
424
- m && typeof m.catch == "function" && m.catch((f) => {
425
- o.error("client plugin failed", f), t({
431
+ const l = e(i, t, s);
432
+ l && typeof l.catch == "function" && l.catch((y) => {
433
+ r.error("client plugin failed", y), t({
426
434
  code: 500,
427
435
  message: "客户端插件执行失败。"
428
436
  });
429
437
  });
430
- } catch (m) {
431
- o.error("client plugin failed", m), t({
438
+ } catch (l) {
439
+ r.error("client plugin failed", l), t({
432
440
  code: 500,
433
441
  message: "客户端插件执行失败。"
434
442
  });
@@ -447,7 +455,7 @@ class re extends z {
447
455
  if (!this.socket)
448
456
  return;
449
457
  const i = this.socket.io.opts.query;
450
- i && (i.Authorization = e), this.socket.connected && (this.pendingTokenUpdate = !0, o.log("socket:update", this.id), this.socket.emit("update", {
458
+ i && (i.Authorization = e), this.socket.connected && (this.pendingTokenUpdate = !0, r.log("socket:update", this.id), this.socket.emit("update", {
451
459
  resourceToken: e
452
460
  }, (a) => {
453
461
  this.pendingTokenUpdate && this.handleResourceTokenUpdateResult(a);
@@ -455,17 +463,17 @@ class re extends z {
455
463
  }
456
464
  handleResourceTokenUpdateResult(e) {
457
465
  if (this.pendingTokenUpdate = !1, !e || e.code === 200) {
458
- o.log("socket:update:ok", this.id);
466
+ r.log("socket:update:ok", this.id);
459
467
  return;
460
468
  }
461
- const i = new Error(R.SocketConnectionFailed, {
469
+ const i = new Error(A.SocketConnectionFailed, {
462
470
  cause: e
463
471
  });
464
- o.error("socket:update:failed", e), this.event.emit("error", i);
472
+ r.error("socket:update:failed", e), this.event.emit("error", i);
465
473
  }
466
474
  stopAnswer() {
467
475
  var e;
468
- o.log("stopAnswer", this.id), this.abortClientPluginCalls(), (e = this.socket) == null || e.emit("stop_answer");
476
+ r.log("stopAnswer", this.id), this.abortClientPluginCalls(), (e = this.socket) == null || e.emit("stop_answer");
469
477
  }
470
478
  inactivate(e = !1) {
471
479
  return !e && this.frozen && !!this.socket || this.abortClientPluginCalls(), super.inactivate(e);
@@ -482,5 +490,5 @@ class re extends z {
482
490
  }
483
491
  }
484
492
  export {
485
- re as default
493
+ ce as default
486
494
  };