@glodon-aiot/bot-client-sdk 3.26.0 → 3.26.2

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
@@ -105,6 +105,34 @@ await client.removeSession(id, true);
105
105
 
106
106
  发送开始后 `session.frozen === true`,此时 `send` 会失败;输入框保持禁用直到 `answer:finish`。
107
107
 
108
+ ## 额度校验与用量数据
109
+
110
+ Agent 应用绑定产线用量扣费后,服务端会在本次回答中附带用量换算返回正文 `usageExtension`,并在异常时下发对应错误码:
111
+
112
+ - **消息字段 `message.usageExtension`**:原样保存服务端返回的用量换算正文(`{ code, message, data: { remainingUsage?, ... } }`)。流式来自 `result` 帧的 `payload.usageExtension`,非流式来自回答外层 `data.usageExtension`。未绑定或未做用量换算时该字段不出现(不置 `{}` 或 `null`)。
113
+ - **用量错误码(`UsageErrorCode`)**:
114
+ - `11937`(`UsageErrorCode.InsufficientBalance`):余额不足,未调用模型,无回答正文。
115
+ - `11938`(`UsageErrorCode.ConversionFailed`):用量换算失败;**已生成的回答正文与 `usageExtension` 完整保留,不被改写**。
116
+ - `11939`(`UsageErrorCode.QuotaCheckFailed`):额度校验失败,未调用模型,无回答正文。
117
+ - **错误事件**:上述三类错误会同时触发 `session` 的 `message:error`(完整消息)与 `error` 事件(`error.message === SessionErrors.UsageError`,`error.cause` 为 `{ code, message, usageExtension?, messageId?, sessionId? }`)。
118
+
119
+ ```ts
120
+ import {
121
+ SessionErrors,
122
+ UsageErrorCode,
123
+ type IUsageExtension,
124
+ type UsageErrorCause,
125
+ } from '@glodon-aiot/bot-client-sdk';
126
+
127
+ session.addEventListener('error', (error: Error & { cause?: UsageErrorCause }) => {
128
+ if (error.message === SessionErrors.UsageError && error.cause) {
129
+ if (error.cause.code === UsageErrorCode.InsufficientBalance) {
130
+ // 余额不足处理
131
+ }
132
+ }
133
+ });
134
+ ```
135
+
108
136
  ## 产出物
109
137
 
110
138
  任务结束后可拉取本次会话留下的文件(会话级,不是单条消息附件)。无产出物返回空数组,不抛错。
@@ -2,30 +2,30 @@ var E = Object.defineProperty, x = Object.defineProperties;
2
2
  var j = Object.getOwnPropertyDescriptors;
3
3
  var P = Object.getOwnPropertySymbols;
4
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) => {
6
- for (var e in d || (d = {}))
7
- O.call(d, e) && S(r, e, d[e]);
5
+ var S = (a, l, e) => l in a ? E(a, l, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[l] = e, h = (a, l) => {
6
+ for (var e in l || (l = {}))
7
+ O.call(l, e) && S(a, e, l[e]);
8
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) => {
9
+ for (var e of P(l))
10
+ F.call(l, e) && S(a, e, l[e]);
11
+ return a;
12
+ }, y = (a, l) => x(a, j(l));
13
+ var w = (a, l, e) => (S(a, typeof l != "symbol" ? l + "" : l, e), e);
14
+ var v = (a, l, e) => new Promise((i, c) => {
15
+ var o = (t) => {
16
16
  try {
17
17
  s(e.next(t));
18
- } catch (l) {
19
- a(l);
18
+ } catch (n) {
19
+ c(n);
20
20
  }
21
- }, c = (t) => {
21
+ }, d = (t) => {
22
22
  try {
23
23
  s(e.throw(t));
24
- } catch (l) {
25
- a(l);
24
+ } catch (n) {
25
+ c(n);
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
+ }, s = (t) => t.done ? i(t.value) : Promise.resolve(t.value).then(o, d);
28
+ s((e = e.apply(a, l)).next());
29
29
  });
30
30
  import { ChatMessageRole as C, PromptVariableType as T } from "@glodon-aiot/apis";
31
31
  import N from "./Logger.mjs";
@@ -37,37 +37,37 @@ import V from "dayjs";
37
37
  import { v4 as $ } from "uuid";
38
38
  import { connectLocalMcpBridge as B, subscribeLocalMcpEndpoints as J } from "./localMcp/endpoints.mjs";
39
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();
45
- if (d)
40
+ const r = new N("[AgentSession] ");
41
+ function L(a) {
42
+ if (typeof a != "string")
43
+ return a;
44
+ const l = a.trim();
45
+ if (l)
46
46
  try {
47
- return JSON.parse(d);
47
+ return JSON.parse(l);
48
48
  } catch (e) {
49
- return r;
49
+ return a;
50
50
  }
51
51
  }
52
- function Y(r) {
53
- const d = r.imageContent;
54
- return Array.isArray(d) ? y(h({}, r), {
55
- imageContent: `[${d.length}]`
56
- }) : r;
52
+ function Y(a) {
53
+ const l = a.imageContent;
54
+ return Array.isArray(l) ? y(h({}, a), {
55
+ imageContent: `[${l.length}]`
56
+ }) : a;
57
57
  }
58
- function U(r) {
59
- return r == null || r === "" || typeof r == "object" && !Array.isArray(r) && Object.keys(r).length === 0;
58
+ function U(a) {
59
+ return a == null || a === "" || typeof a == "object" && !Array.isArray(a) && Object.keys(a).length === 0;
60
60
  }
61
- function H(r, d) {
62
- const e = L(r == null ? void 0 : r.query);
61
+ function H(a, l) {
62
+ const e = L(a == null ? void 0 : a.query);
63
63
  if (!U(e))
64
64
  return e;
65
- const i = L(d);
65
+ const i = L(l);
66
66
  return U(i) && e != null ? e : i;
67
67
  }
68
68
  class re extends z {
69
- constructor(e, i = "", a, n, c, s) {
70
- super(e, i, a, n, c, s);
69
+ constructor(e, i = "", c, o, d, s) {
70
+ super(e, i, c, o, d, s);
71
71
  w(this, "inflightCalls", /* @__PURE__ */ new Set());
72
72
  w(this, "localMcpTicket", 0);
73
73
  w(this, "stopLocalMcpUpdates");
@@ -76,9 +76,9 @@ class re extends z {
76
76
  }
77
77
  prepareConnection() {
78
78
  return new Promise((e) => v(this, null, function* () {
79
- var c;
80
- if ((c = this.socket) != null && c.connected) {
81
- o.log("socket:reuse", this.id), e(!0);
79
+ var d;
80
+ if ((d = this.socket) != null && d.connected) {
81
+ r.log("socket:reuse", this.id), e(!0);
82
82
  return;
83
83
  }
84
84
  this.socket && (this.socket.removeAllListeners(), this.socket.close(), this.socket = null);
@@ -89,27 +89,27 @@ class re extends z {
89
89
  sessionId: this.id,
90
90
  Authorization: `${this.requestToken}`,
91
91
  userMode: p.debug ? I.Debug : I.Normal
92
- }, a = new URL(p.apiRoot);
93
- o.log("socket:connecting", {
92
+ }, c = new URL(p.apiRoot);
93
+ r.log("socket:connecting", {
94
94
  sessionId: this.id,
95
- origin: a.origin
95
+ origin: c.origin
96
96
  });
97
- const n = yield D(a.origin, {
98
- path: a.pathname.replace("api", "socketio") + "/copilot",
97
+ const o = yield D(c.origin, {
98
+ path: c.pathname.replace("api", "socketio") + "/copilot",
99
99
  query: i,
100
100
  transports: ["websocket"]
101
101
  });
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) => {
102
+ o.on("connect", () => {
103
+ r.log("socket:connect"), this.event.emit("socket:connect"), o.emit("init");
104
+ }), o.on("disconnect", () => {
105
+ r.log("socket:disconnect"), this.event.emit("socket:disconnect"), this._ready = !1, this.pendingTokenUpdate = !1;
106
+ }), o.on("ready", (s) => {
107
107
  if (this.pendingTokenUpdate) {
108
108
  this.handleResourceTokenUpdateResult(s);
109
109
  return;
110
110
  }
111
111
  if (s.code === 200) {
112
- o.log("ready");
112
+ r.log("ready");
113
113
  const t = p.debug ? I.Debug : I.Normal;
114
114
  t === I.Debug && s.userMode, this._ready || (this._ready = !0, this.event.emit("ready")), this.frozen = !1, this.registerMcpFromClientConfig(), this.registerLocalMcp(), e(!0);
115
115
  } else {
@@ -120,18 +120,18 @@ class re extends z {
120
120
  // cause: data,
121
121
  // }
122
122
  );
123
- o.error("error", t), this.event.emit("error", t), e(!1);
123
+ r.error("error", t), this.event.emit("error", t), e(!1);
124
124
  }
125
- }), n.on("action", (s, t) => v(this, null, function* () {
125
+ }), o.on("action", (s, t) => v(this, null, function* () {
126
126
  var A;
127
127
  if (this._stopAnswer || !this.id)
128
128
  return;
129
129
  const {
130
- type: l,
130
+ type: n,
131
131
  data: {
132
- runnerIsClient: m,
132
+ runnerIsClient: g,
133
133
  pluginCode: f,
134
- funcCode: g,
134
+ funcCode: m,
135
135
  parameters: u,
136
136
  requestBody: _
137
137
  }
@@ -162,20 +162,20 @@ class re extends z {
162
162
  action: s
163
163
  });
164
164
  }
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:
165
+ if (n === "FUNCTION_CALL" && !g && r.log("server function", f, m), n === "FUNCTION_CALL" && g) {
166
+ r.log(`calling function ${m} of plugin ${f} with argument:
167
167
  ${JSON.stringify(u)}`);
168
168
  const M = (A = p.plugins) == null ? void 0 : A[f];
169
169
  if (!M) {
170
- o.error("plugin not found", f, g), t({
170
+ r.error("plugin not found", f, m), t({
171
171
  code: 404,
172
172
  message: "没有找到插件。"
173
173
  });
174
174
  return;
175
175
  }
176
- const b = M[g];
176
+ const b = M[m];
177
177
  if (typeof b != "function") {
178
- o.error("plugin function not found", f, g), t({
178
+ r.error("plugin function not found", f, m), t({
179
179
  code: 404,
180
180
  message: "没有找到插件方法。"
181
181
  });
@@ -185,17 +185,17 @@ class re extends z {
185
185
  this.invokeClientPlugin(b, q, t, {
186
186
  requestId: s.requestId,
187
187
  pluginCode: f,
188
- functionCode: g
188
+ functionCode: m
189
189
  });
190
190
  }
191
- })), n.on("answer", (s) => {
192
- if (o.log("answer", s == null ? void 0 : s.data), !this._stopAnswer)
191
+ })), o.on("answer", (s) => {
192
+ if (r.log("answer", s == null ? void 0 : s.data), !this._stopAnswer)
193
193
  if (s.data.code !== 200 && (s.data.index = -1), s.data.stream || s.data.stream === void 0) {
194
194
  let t = this.messages[this.messages.length - 1];
195
195
  if (t && t.role === C.Robot)
196
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));
197
197
  else {
198
- const l = {
198
+ const n = {
199
199
  content: "",
200
200
  role: C.Robot,
201
201
  reference: [],
@@ -217,14 +217,35 @@ class re extends z {
217
217
  thinkingStatus: "",
218
218
  searchingStatus: ""
219
219
  };
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));
220
+ this.handleStreamAnswer(s.data, n), this.pushMessage(n), this.event.emit("message:content", n), n.index === -1 && (n.isReplying = !1, this.event.emit("answer:finish", n));
221
221
  }
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);
226
- else {
227
- const l = h({
222
+ } else {
223
+ const t = h({}, s.data);
224
+ if (t.usageExtension == null && delete t.usageExtension, t.updateSession && this.data && (this.data = h(h({}, this.data), t.updateSession), this.event.emit("data:updated", this.data)), t.index === -1) {
225
+ let n = this.messages[this.messages.length - 1];
226
+ if (n && !n.messageId)
227
+ n = h(h({}, n), t), this.messages[this.messages.length - 1] = n, this.event.emit("message:content", n), this.event.emit("message:updated", n), this.event.emit("answer:finish", n);
228
+ else {
229
+ const g = h({
230
+ messageId: "",
231
+ content: "",
232
+ role: C.Robot,
233
+ sessionId: this.id,
234
+ reference: [],
235
+ searchReference: [],
236
+ isLoading: !1,
237
+ messageTime: "",
238
+ actions: [],
239
+ comment: {
240
+ isAgree: 0
241
+ },
242
+ isReplying: !0
243
+ }, t);
244
+ this.event.emit("message:content", g), this.pushMessage(g), this.event.emit("answer:finish", g);
245
+ }
246
+ } else {
247
+ let n = this.messages[this.messages.length - 1];
248
+ n && !n.messageId ? (n = h(h({}, n), t), this.messages[this.messages.length - 1] = n, this.event.emit("message:content", n), this.event.emit("message:updated", n)) : (this.pushMessage(h({
228
249
  messageId: "",
229
250
  content: "",
230
251
  role: C.Robot,
@@ -238,28 +259,10 @@ class re extends z {
238
259
  isAgree: 0
239
260
  },
240
261
  isReplying: !0
241
- }, s.data);
242
- this.event.emit("message:content", l), this.pushMessage(l), this.event.emit("answer:finish", l);
262
+ }, t)), this.event.emit("message:content", t));
243
263
  }
244
- } 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({
247
- messageId: "",
248
- content: "",
249
- role: C.Robot,
250
- sessionId: this.id,
251
- reference: [],
252
- searchReference: [],
253
- isLoading: !1,
254
- messageTime: "",
255
- actions: [],
256
- comment: {
257
- isAgree: 0
258
- },
259
- isReplying: !0
260
- }, s.data)), this.event.emit("message:content", s.data));
261
264
  }
262
- }), n.on("reference", (s) => v(this, null, function* () {
265
+ }), o.on("reference", (s) => v(this, null, function* () {
263
266
  if (this._stopAnswer)
264
267
  return;
265
268
  if (!this.id) {
@@ -269,24 +272,24 @@ class re extends z {
269
272
  // cause: SESSION_ERROR_CAUSE[SessionErrors.IdUndefined],
270
273
  // }
271
274
  );
272
- o.error(u), this.event.emit("error", u), this.frozen = !1;
275
+ r.error(u), this.event.emit("error", u), this.frozen = !1;
273
276
  return;
274
277
  }
275
278
  const {
276
279
  type: t,
277
- data: l,
278
- requestId: m
280
+ data: n,
281
+ requestId: g
279
282
  } = s;
280
- o.log("reference", {
283
+ r.log("reference", {
281
284
  type: t,
282
- requestId: m,
283
- data: l
285
+ requestId: g,
286
+ data: n
284
287
  });
285
- const f = this.messages.findIndex((u) => u.messageId === m && u.role === C.User);
288
+ const f = this.messages.findIndex((u) => u.messageId === g && u.role === C.User);
286
289
  if (f < 0)
287
290
  return;
288
- const g = f + 1;
289
- if (g >= this.messages.length) {
291
+ const m = f + 1;
292
+ if (m >= this.messages.length) {
290
293
  const u = {
291
294
  messageId: "",
292
295
  content: "",
@@ -304,12 +307,12 @@ class re extends z {
304
307
  };
305
308
  this.pushMessage(u);
306
309
  }
307
- t === "KG" ? (this.messages[g] = y(h({}, this.messages[g]), {
308
- 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]), {
310
- 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();
310
+ t === "KG" ? (this.messages[m] = y(h({}, this.messages[m]), {
311
+ reference: n.knowledgeReference
312
+ }), yield this.fillMessageReference(this.messages[m]), this.event.emit("message:reference", n.knowledgeReference), this.event.emit("message:updated", this.messages[m])) : t === "WEB_SEARCH" && (this.messages[m] = y(h({}, this.messages[m]), {
313
+ searchReference: n.knowledgeReference
314
+ }), this.event.emit("message:searchreference", n.searchReference), this.event.emit("message:updated", this.messages[m]));
315
+ })), this.socket = o, o.open();
313
316
  }));
314
317
  }
315
318
  registerMcpFromClientConfig() {
@@ -318,86 +321,86 @@ class re extends z {
318
321
  i("socket is undefined");
319
322
  return;
320
323
  }
321
- 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));
324
+ this.socket.emit("add_mcp_servers", p.mcp, (c) => {
325
+ c.code === 200 ? (Object.keys(c.data).forEach((o) => {
326
+ c.data[o].code !== 200 && r.report(o, "MCP Server 注册失败。", c.data[o]);
327
+ }), r.log("mcp:registered", Object.keys(c.data)), e(!0)) : (r.error("MCP Server 注册失败。", c), i(c));
325
328
  });
326
- }) : (o.log("mcp:skip"), Promise.resolve(!0));
329
+ }) : (r.log("mcp:skip"), Promise.resolve(!0));
327
330
  }
328
331
  registerLocalMcp() {
329
- var a, n;
332
+ var c, o;
330
333
  const e = this.socket;
331
334
  if (!e)
332
335
  return;
333
336
  B(), this.stopLocalMcpUpdates || (this.stopLocalMcpUpdates = J(() => this.registerLocalMcp()));
334
337
  const i = ++this.localMcpTicket;
335
338
  Q({
336
- arrange: (n = (a = this.application) == null ? void 0 : a.arrange) == null ? void 0 : n[0],
339
+ arrange: (o = (c = this.application) == null ? void 0 : c.arrange) == null ? void 0 : o[0],
337
340
  initMcp: p.mcp,
338
341
  apiRoot: p.apiRoot,
339
342
  token: this.requestToken,
340
343
  socket: e,
341
344
  isCurrent: () => i === this.localMcpTicket
342
- }).catch((c) => {
343
- o.report("local mcp", c instanceof Error ? c.message : String(c));
345
+ }).catch((d) => {
346
+ r.report("local mcp", d instanceof Error ? d.message : String(d));
344
347
  });
345
348
  }
346
349
  addMcpServers(e) {
347
350
  return v(this, null, function* () {
348
- 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));
351
+ return this.ready ? this.socket ? new Promise((i, c) => {
352
+ this.socket && this.socket.emit("add_mcp_servers", e, (o) => {
353
+ o.code === 200 ? (Object.keys(o.data).forEach((d) => {
354
+ o.data[d].code !== 200 && r.report(d, "MCP Server 注册失败。", o.data[d]);
355
+ }), r.log("mcp:registered", Object.keys(o.data)), i(!0)) : (r.error("MCP Server 注册失败。", o), c(o));
353
356
  });
354
- }) : (o.error("socket is undefined."), Promise.reject("socket is undefined")) : (o.error("session is not avalible."), Promise.reject("session is not avalible"));
357
+ }) : (r.error("socket is undefined."), Promise.reject("socket is undefined")) : (r.error("session is not avalible."), Promise.reject("session is not avalible"));
355
358
  });
356
359
  }
357
360
  listMcpServers() {
358
361
  return v(this, null, function* () {
359
362
  return this.ready ? this.socket ? new Promise((e, i) => {
360
- this.socket && this.socket.emit("list_mcp_servers", (a) => {
361
- a.code === 200 ? e(a.data) : i(a);
363
+ this.socket && this.socket.emit("list_mcp_servers", (c) => {
364
+ c.code === 200 ? e(c.data) : i(c);
362
365
  });
363
- }) : (o.error("socket is undefined."), Promise.reject("socket is undefined")) : (o.error("session is not avalible."), Promise.reject("session is not avalible"));
366
+ }) : (r.error("socket is undefined."), Promise.reject("socket is undefined")) : (r.error("session is not avalible."), Promise.reject("session is not avalible"));
364
367
  });
365
368
  }
366
369
  sendQuestion(e, i) {
367
370
  return v(this, null, function* () {
368
- var n;
371
+ var o;
369
372
  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), {
373
+ let c = y(h({}, e), {
374
+ promptVariables: this.promptVariables.filter((d) => d.type === T.User).reduce((d, s) => y(h({}, d), {
372
375
  [s.key]: s.value
373
376
  }), {}),
374
- systemPromptVariables: this.promptVariables.filter((c) => c.type === T.System).reduce((c, s) => y(h({}, c), {
377
+ systemPromptVariables: this.promptVariables.filter((d) => d.type === T.System).reduce((d, s) => y(h({}, d), {
375
378
  [s.key]: s.value
376
379
  }), {}),
377
- knowledges: (n = this.knowledges) == null ? void 0 : n.map((c) => c.id),
380
+ knowledges: (o = this.knowledges) == null ? void 0 : o.map((d) => d.id),
378
381
  //agent支持指定文件时再放开
379
382
  // knowledges: knowledgesForChat,
380
383
  enableTitleSummary: this.resolveEnableTitleSummary()
381
384
  });
382
385
  if (!this.active) {
383
386
  if (yield this.activate(), !this.socket) {
384
- const c = new Error(
387
+ const d = new Error(
385
388
  R.SocketConnectionFailed
386
389
  // {
387
390
  // cause: { code: -1, message: 'socket is null' },
388
391
  // }
389
392
  );
390
- return o.warn("error", c), this.event.emit("error", c), !1;
393
+ return r.warn("error", d), this.event.emit("error", d), !1;
391
394
  }
392
- this.emitQuestion(a);
395
+ this.emitQuestion(c);
393
396
  return;
394
397
  }
395
- this.emitQuestion(a);
398
+ this.emitQuestion(c);
396
399
  });
397
400
  }
398
401
  emitQuestion(e) {
399
402
  var i;
400
- o.log("question:request", Y(e)), (i = this.socket) == null || i.emit("question", e), o.log("question:sent", {
403
+ r.log("question:request", Y(e)), (i = this.socket) == null || i.emit("question", e), r.log("question:sent", {
401
404
  sessionId: this.id
402
405
  });
403
406
  }
@@ -405,30 +408,30 @@ class re extends z {
405
408
  * 调用客户端插件:传入第三个参数 context(旧插件可忽略),结果最多回传一次,
406
409
  * 停止回答或调用被取消后不再回传。
407
410
  */
408
- invokeClientPlugin(e, i, a, n) {
409
- const c = new AbortController();
410
- this.inflightCalls.add(c);
411
+ invokeClientPlugin(e, i, c, o) {
412
+ const d = new AbortController();
413
+ this.inflightCalls.add(d);
411
414
  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 || $(),
415
+ const t = (...g) => {
416
+ s || (s = !0, this.inflightCalls.delete(d), !(this._stopAnswer || d.signal.aborted) && c(...g));
417
+ }, n = {
418
+ requestId: o.requestId || $(),
416
419
  applicationId: this._applicationId,
417
420
  sessionId: this.id,
418
- pluginCode: n.pluginCode,
419
- functionCode: n.functionCode,
420
- signal: c.signal
421
+ pluginCode: o.pluginCode,
422
+ functionCode: o.functionCode,
423
+ signal: d.signal
421
424
  };
422
425
  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({
426
+ const g = e(i, t, n);
427
+ g && typeof g.catch == "function" && g.catch((f) => {
428
+ r.error("client plugin failed", f), t({
426
429
  code: 500,
427
430
  message: "客户端插件执行失败。"
428
431
  });
429
432
  });
430
- } catch (m) {
431
- o.error("client plugin failed", m), t({
433
+ } catch (g) {
434
+ r.error("client plugin failed", g), t({
432
435
  code: 500,
433
436
  message: "客户端插件执行失败。"
434
437
  });
@@ -447,25 +450,25 @@ class re extends z {
447
450
  if (!this.socket)
448
451
  return;
449
452
  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", {
453
+ i && (i.Authorization = e), this.socket.connected && (this.pendingTokenUpdate = !0, r.log("socket:update", this.id), this.socket.emit("update", {
451
454
  resourceToken: e
452
- }, (a) => {
453
- this.pendingTokenUpdate && this.handleResourceTokenUpdateResult(a);
455
+ }, (c) => {
456
+ this.pendingTokenUpdate && this.handleResourceTokenUpdateResult(c);
454
457
  }));
455
458
  }
456
459
  handleResourceTokenUpdateResult(e) {
457
460
  if (this.pendingTokenUpdate = !1, !e || e.code === 200) {
458
- o.log("socket:update:ok", this.id);
461
+ r.log("socket:update:ok", this.id);
459
462
  return;
460
463
  }
461
464
  const i = new Error(R.SocketConnectionFailed, {
462
465
  cause: e
463
466
  });
464
- o.error("socket:update:failed", e), this.event.emit("error", i);
467
+ r.error("socket:update:failed", e), this.event.emit("error", i);
465
468
  }
466
469
  stopAnswer() {
467
470
  var e;
468
- o.log("stopAnswer", this.id), this.abortClientPluginCalls(), (e = this.socket) == null || e.emit("stop_answer");
471
+ r.log("stopAnswer", this.id), this.abortClientPluginCalls(), (e = this.socket) == null || e.emit("stop_answer");
469
472
  }
470
473
  inactivate(e = !1) {
471
474
  return !e && this.frozen && !!this.socket || this.abortClientPluginCalls(), super.inactivate(e);
@@ -1,4 +1,15 @@
1
- var r = /* @__PURE__ */ ((a) => (a[a.Normal = 0] = "Normal", a[a.Debug = 1] = "Debug", a))(r || {});
1
+ var i = /* @__PURE__ */ ((n) => (n[n.Normal = 0] = "Normal", n[n.Debug = 1] = "Debug", n))(i || {}), a = /* @__PURE__ */ ((n) => (n[n.InsufficientBalance = 11937] = "InsufficientBalance", n[n.ConversionFailed = 11938] = "ConversionFailed", n[n.QuotaCheckFailed = 11939] = "QuotaCheckFailed", n))(a || {});
2
+ const t = {
3
+ 11937: "余额不足",
4
+ 11938: "用量换算失败",
5
+ 11939: "额度校验失败"
6
+ };
7
+ function u(n) {
8
+ return n === 11937 || n === 11938 || n === 11939;
9
+ }
2
10
  export {
3
- r as UserMode
11
+ t as USAGE_ERROR_DEFAULT_MESSAGES,
12
+ a as UsageErrorCode,
13
+ i as UserMode,
14
+ u as isUsageErrorCode
4
15
  };