@glodon-aiot/bot-client-sdk 3.26.0-alpha.5 → 3.26.0-alpha.9

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
@@ -464,11 +464,11 @@ function openApprovalDialog(request: ApprovalRequest): Promise<boolean> {
464
464
  ### 执行器选择顺序
465
465
 
466
466
  1. **注入的** `LocalWorkspace.commandRunner`(测试 / 自定义)
467
- 2. **宿主沙箱**:`backend: 'host-bridge'`,且 `workspace` 消息声明 `capabilities` 含 `sandbox-exec`,且 `sandboxProtocol === 1` → 经宿主转发 `@glodon-aiot/workspace-sandbox`(MXC 隔离)
468
- 3. **浏览器运行时**:`commandRuntime.browser.enabled` 默认为 `true` → just-bash + Pyodide Worker
467
+ 2. **沙箱直连**:宿主工作区已授权,且 `sandbox.state` 为 `ready`、`protocol` 为 `2` → 页面对 `ws://127.0.0.1` 发 WebSocket,不经宿主转发文件和命令
468
+ 3. **浏览器运行时**:没有宿主 WebView 时,`commandRuntime.browser.enabled` 默认为 `true` → just-bash + Pyodide Worker
469
469
  4. 以上皆不可用 → **501**
470
470
 
471
- 协议版本不一致时:记一次 `error` 事件日志,**回退浏览器运行时**,不硬失败。未声明 `sandbox-exec` 的旧宿主不再使用其裸 `exec`。
471
+ 宿主工作区已经授权时,沙箱没就绪不会改走浏览器运行时。`starting` 时说明正在启动;失败说明用 `sandbox.message`。协议不是 2 时另记一次 `error`。没有宿主 WebView 时才用注入的 `commandRunner` 或浏览器运行时。
472
472
 
473
473
  参照宿主:`examples/qt-workspace-host`。
474
474
 
@@ -496,7 +496,13 @@ function openApprovalDialog(request: ApprovalRequest): Promise<boolean> {
496
496
 
497
497
  ### 宿主沙箱(摘要)
498
498
 
499
- - 宿主启动一次 `workspace-sandbox --serve`,每请求一行 JSON;文件 IO 在该进程直读写,命令进 MXC
499
+ - 宿主把沙箱放进独立进程组,启动 `workspace-sandbox --listen --root <工程绝对路径> --origin <页面来源>`
500
+ - 宿主只做五件事:启动、读 ready、需要时问 status、shutdown(3 秒后结束进程组)、把退出告诉页面
501
+ - 页面从 `sandbox.url` / `sandbox.token` 直连。HTTPS 页面仍连 `ws://127.0.0.1`,不提供 `wss://`
502
+ - CSP 的 `connect-src` 要放行 `ws://127.0.0.1:*`。SDK 只加载在可信页面上,同页脚本能读到令牌
503
+ - 启动失败的 `reason` 对应固定说明,例如 `listen-failed` 是「沙箱没有监听到端口。」消息里没有令牌和绝对路径
504
+ - 运行中崩溃时推送 `sandbox.state: "exited"`。同一次打开最多自动重启一次
505
+ - 文件被其他程序占用时原文件保持不变,错误是「文件正在被占用,没有写入。」
500
506
  - 随安装包分发:`Resources/node/`(Node 24)+ `Resources/workspace-sandbox/`(`yarn bundle --platform …` 产物),可选 `python/`
501
507
  - 输出做路径反向替换,页面看不到工程绝对路径
502
508
  - 细节与 Windows 步骤见 [`local-workspace-windows-host.md`](../bot-client-ui/docs/local-workspace-windows-host.md)
@@ -522,17 +528,17 @@ function openApprovalDialog(request: ApprovalRequest): Promise<boolean> {
522
528
  "granted": true,
523
529
  "displayName": "sample-project",
524
530
  "capabilities": ["fs-mutate", "sandbox-exec"],
525
- "sandboxVersion": "0.1.0",
526
- "sandboxProtocol": 1
531
+ "sandboxVersion": "0.2.0-alpha.1",
532
+ "sandbox": {
533
+ "state": "ready",
534
+ "url": "ws://127.0.0.1:53124",
535
+ "token": "<32 字节十六进制>",
536
+ "protocol": 2
537
+ }
527
538
  }
528
539
  ```
529
540
 
530
- `granted` 为 `false` 时页面断开工作区。`displayName` 只放文件夹名。找不到 Node / 沙箱包时 **不要** 声明 `fs-mutate` / `sandbox-exec`。
531
-
532
- | capability | 含义 |
533
- | --- | --- |
534
- | `sandbox-exec` | 支持 `exec`(经 workspace-sandbox);须同时带 `sandboxProtocol: 1` |
535
- | `fs-mutate` | 支持 `mkdir` / `remove` / `move` |
541
+ `granted` 为 `false` 时页面断开工作区。`displayName` 只放文件夹名。`sandbox.state` 还可以是 `starting`、`failed`、`exited`。`failed` 带固定 `message`,不带令牌和绝对路径。页面不向宿主发送文件或命令操作。
536
542
 
537
543
  目录有增删时再推一条。`paths` 是发生变化的目录,相对工程根,根目录用 `""`。空数组表示让页面重读已展开的全部目录。短时间内多次变化可以合成一条。
538
544
 
@@ -542,32 +548,9 @@ function openApprovalDialog(request: ApprovalRequest): Promise<boolean> {
542
548
 
543
549
  脚本跑完、用户在资源管理器里改文件,都应推送。Qt 示例用目录监视做这件事,默认不监视 `.git`、`node_modules`、`__pycache__` 内部。
544
550
 
545
- 其余请求都带 `id` 和 `op`。路径用 `/`,不能含 `..`、盘符、反斜杠或绝对路径。不合法时回 `{ "id", "ok": false, "name": "SecurityError" }`,不要访问磁盘。宿主补上本地 `root` 后转发给 `workspace-sandbox --serve`,按 `id` 回传。
551
+ 文件和命令不经过宿主。页面连上沙箱后发协议 2 的文本帧和二进制分片:`read` 按 `offset` / `maxBytes` 取窗口,`write` 按偏移写入临时文件再改名。占用时原文件不变。命令输出流式返回,SDK 每个流只保留最后 16000 字符;若有 `logPath`,截断说明里带上 `tmp/sandbox-exec/<id>.log`。
546
552
 
547
- | op | 页面发来的字段 | 成功时宿主回 |
548
- | --- | --- | --- |
549
- | `list` | `path`,根目录是 `""` 或 `"."` | `entries`: `{ name, kind: "file" \| "directory", size?, lastModified? }[]` |
550
- | `stat` | `path` | `entry`:同样的字段 |
551
- | `read` | `path` | `contentBase64`。单文件不超过 50 MB |
552
- | `write` | `path`、`contentBase64`、`createDirectories` | `{ "ok": true }`。父目录不存在且 `createDirectories` 不是 `true` 时回 `NotFoundError` |
553
- | `mkdir` / `remove` / `move` | 路径规则同 write;`move` 用 `from`/`to`;需 `fs-mutate` | `{ "ok": true }` |
554
- | `exec` | `protocol`(当前为 1)、`cwd`(工作区相对目录)、`command` 或 `argv`、`timeoutMs` | `exitCode`、`stdout`、`stderr`、`cwd?`、`timedOut?` |
555
- | `run_python` | `path`、`args`、`timeoutMs` | `exitCode`、`timedOut`、`stdout`、`stderr` |
556
-
557
- 失败时统一 `{ "id", "ok": false, "name" }`:
558
-
559
- | name | 何时 |
560
- | --- | --- |
561
- | `NotAllowedError` | 还没有工程目录,或文件打不开 |
562
- | `SecurityError` | 路径越出工程目录 |
563
- | `NotFoundError` | 目标不存在 |
564
- | `TypeMismatchError` | 把文件当目录,或脚本不是 `.py` |
565
- | `QuotaExceededError` | 读写超过 50 MB |
566
- | `NoModificationAllowedError` | 写入没有完成 |
567
- | `AbortError` | 已经有一个脚本在跑,或调用超时 |
568
- | `InvalidModificationError` | 非空目录删除未带 `recursive` 等 |
569
-
570
- `lastModified` 用 Unix 毫秒。`size` 用字节数。搜索、按行修改、上传、下载仍由页面完成,底层落到上面的 `list` / `read` / `write`。宿主不要自己实现那些工具名。文件 op 可并发;命令类同一时间只跑一个。
553
+ 取消命令只发 `{ "op": "cancel", "id" }`,不关闭套接字。收到 `bye`、`exited` 或 `failed` 时,在途调用失败且不重放。下一次 `ready` 使用新令牌再连。
571
554
 
572
555
  ## 安全与限额
573
556
 
@@ -1,16 +1,16 @@
1
- var T = Object.defineProperty, j = Object.defineProperties;
1
+ var q = Object.defineProperty, j = Object.defineProperties;
2
2
  var L = Object.getOwnPropertyDescriptors;
3
- var S = Object.getOwnPropertySymbols;
3
+ var b = Object.getOwnPropertySymbols;
4
4
  var F = Object.prototype.hasOwnProperty, N = Object.prototype.propertyIsEnumerable;
5
- var M = (r, c, e) => c in r ? T(r, c, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[c] = e, h = (r, c) => {
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) => {
6
6
  for (var e in c || (c = {}))
7
7
  F.call(c, e) && M(r, e, c[e]);
8
- if (S)
9
- for (var e of S(c))
8
+ if (b)
9
+ for (var e of b(c))
10
10
  N.call(c, e) && M(r, e, c[e]);
11
11
  return r;
12
12
  }, w = (r, c) => j(r, L(c));
13
- var b = (r, c, e) => (M(r, typeof c != "symbol" ? c + "" : c, e), e);
13
+ var P = (r, c, e) => (M(r, typeof c != "symbol" ? c + "" : c, e), e);
14
14
  var y = (r, c, e) => new Promise((o, a) => {
15
15
  var n = (i) => {
16
16
  try {
@@ -47,20 +47,20 @@ function _(r) {
47
47
  return r;
48
48
  }
49
49
  }
50
- function x(r) {
50
+ function E(r) {
51
51
  return r == null || r === "" || typeof r == "object" && !Array.isArray(r) && Object.keys(r).length === 0;
52
52
  }
53
53
  function Y(r, c) {
54
54
  const e = _(r == null ? void 0 : r.query);
55
- if (!x(e))
55
+ if (!E(e))
56
56
  return e;
57
57
  const o = _(c);
58
- return x(o) && e != null ? e : o;
58
+ return E(o) && e != null ? e : o;
59
59
  }
60
60
  class Z extends D {
61
61
  constructor(e, o = "", a, n, t, s) {
62
62
  super(e, o, a, n, t, s);
63
- b(this, "inflightCalls", /* @__PURE__ */ new Set());
63
+ P(this, "inflightCalls", /* @__PURE__ */ new Set());
64
64
  }
65
65
  prepareConnection() {
66
66
  return new Promise((e) => y(this, null, function* () {
@@ -106,8 +106,8 @@ class Z extends D {
106
106
  runnerIsClient: d,
107
107
  pluginCode: l,
108
108
  funcCode: g,
109
- parameters: m,
110
- requestBody: E
109
+ parameters: h,
110
+ requestBody: x
111
111
  }
112
112
  } = t, u = this.messages[this.messages.length - 1];
113
113
  if (!u.messageId)
@@ -150,7 +150,7 @@ class Z extends D {
150
150
  f.warn("error", p), this.event.emit("error", p);
151
151
  } else if (i === "FUNCTION_CALL" && d) {
152
152
  f.log(`calling function ${g} of plugin ${l} with argument:
153
- ${JSON.stringify(m)}`);
153
+ ${JSON.stringify(h)}`);
154
154
  const p = (R = C.plugins) == null ? void 0 : R[l];
155
155
  if (!p) {
156
156
  s({
@@ -159,16 +159,16 @@ class Z extends D {
159
159
  });
160
160
  return;
161
161
  }
162
- const P = p[g];
163
- if (typeof P != "function") {
162
+ const S = p[g];
163
+ if (typeof S != "function") {
164
164
  s({
165
165
  code: 404,
166
166
  message: "没有找到插件方法。"
167
167
  });
168
168
  return;
169
169
  }
170
- const q = Y(m, E);
171
- this.invokeClientPlugin(P, q, s, {
170
+ const T = Y(h, x);
171
+ this.invokeClientPlugin(S, T, s, {
172
172
  requestId: t.requestId,
173
173
  pluginCode: l,
174
174
  functionCode: g
@@ -205,12 +205,12 @@ class Z extends D {
205
205
  };
206
206
  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
207
  }
208
- } 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) {
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) {
209
209
  let s = this.messages[this.messages.length - 1];
210
210
  if (s && !s.messageId)
211
- s = h(h({}, s), t.data), this.event.emit("message:content", s), this.event.emit("message:updated", s), this.event.emit("answer:finish", s);
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);
212
212
  else {
213
- const i = h({
213
+ const i = m({
214
214
  messageId: "",
215
215
  content: "",
216
216
  role: v.Robot,
@@ -229,7 +229,7 @@ class Z extends D {
229
229
  }
230
230
  } else {
231
231
  let s = this.messages[this.messages.length - 1];
232
- 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({
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({
233
233
  messageId: "",
234
234
  content: "",
235
235
  role: v.Robot,
@@ -249,25 +249,25 @@ class Z extends D {
249
249
  if (this._stopAnswer)
250
250
  return;
251
251
  if (!this.id) {
252
- const m = new Error(
252
+ const h = new Error(
253
253
  k.IdUndefined
254
254
  // {
255
255
  // cause: SESSION_ERROR_CAUSE[SessionErrors.IdUndefined],
256
256
  // }
257
257
  );
258
- f.error(m), this.event.emit("error", m), this.frozen = !1;
258
+ f.error(h), this.event.emit("error", h), this.frozen = !1;
259
259
  return;
260
260
  }
261
261
  const {
262
262
  type: s,
263
263
  data: i,
264
264
  requestId: d
265
- } = t, l = this.messages.findIndex((m) => m.messageId === d && m.role === v.User);
265
+ } = t, l = this.messages.findIndex((h) => h.messageId === d && h.role === v.User);
266
266
  if (l < 0)
267
267
  return;
268
268
  const g = l + 1;
269
269
  if (g >= this.messages.length) {
270
- const m = {
270
+ const h = {
271
271
  messageId: "",
272
272
  content: "",
273
273
  role: v.Robot,
@@ -282,11 +282,11 @@ class Z extends D {
282
282
  },
283
283
  isReplying: !0
284
284
  };
285
- this.pushMessage(m);
285
+ this.pushMessage(h);
286
286
  }
287
- s === "KG" ? (this.messages[g] = w(h({}, this.messages[g]), {
287
+ s === "KG" ? (this.messages[g] = w(m({}, this.messages[g]), {
288
288
  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(h({}, this.messages[g]), {
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]), {
290
290
  searchReference: i.knowledgeReference
291
291
  }), this.event.emit("message:searchreference", i.searchReference), this.event.emit("message:updated", this.messages[g]));
292
292
  })), this.socket = n, n.open();
@@ -329,18 +329,17 @@ class Z extends D {
329
329
  return y(this, null, function* () {
330
330
  var n, t, s;
331
331
  this.convertKnowledgesToChatFormat(this.knowledges);
332
- let a = w(h({}, e), {
333
- promptVariables: this.promptVariables.filter((i) => i.type === A.User).reduce((i, d) => w(h({}, i), {
332
+ let a = w(m({}, e), {
333
+ promptVariables: this.promptVariables.filter((i) => i.type === A.User).reduce((i, d) => w(m({}, i), {
334
334
  [d.key]: d.value
335
335
  }), {}),
336
- systemPromptVariables: this.promptVariables.filter((i) => i.type === A.System).reduce((i, d) => w(h({}, i), {
336
+ systemPromptVariables: this.promptVariables.filter((i) => i.type === A.System).reduce((i, d) => w(m({}, i), {
337
337
  [d.key]: d.value
338
338
  }), {}),
339
339
  knowledges: (n = this.knowledges) == null ? void 0 : n.map((i) => i.id),
340
340
  //agent支持指定文件时再放开
341
341
  // knowledges: knowledgesForChat,
342
- //开启内容摘要
343
- enableTitleSummary: !0
342
+ enableTitleSummary: this.resolveEnableTitleSummary()
344
343
  });
345
344
  if (!this.active) {
346
345
  if (yield this.activate(), !this.socket) {
@@ -11,7 +11,7 @@ var R = (l, c, s) => c in l ? I(l, c, { enumerable: !0, configurable: !0, writab
11
11
  return l;
12
12
  }, y = (l, c) => A(l, P(c));
13
13
  var M = (l, c, s) => (R(l, typeof c != "symbol" ? c + "" : c, s), s);
14
- var f = (l, c, s) => new Promise((a, d) => {
14
+ var f = (l, c, s) => new Promise((t, d) => {
15
15
  var h = (r) => {
16
16
  try {
17
17
  i(s.next(r));
@@ -24,7 +24,7 @@ var f = (l, c, s) => new Promise((a, d) => {
24
24
  } catch (m) {
25
25
  d(m);
26
26
  }
27
- }, i = (r) => r.done ? a(r.value) : Promise.resolve(r.value).then(h, e);
27
+ }, i = (r) => r.done ? t(r.value) : Promise.resolve(r.value).then(h, e);
28
28
  i((s = s.apply(l, c)).next());
29
29
  });
30
30
  import { IHistoryRole as C, PromptVariableType as v, ChatMessageRole as O } from "@glodon-aiot/apis";
@@ -35,8 +35,8 @@ import { configuration as S } from "./Config.mjs";
35
35
  import { fetchEventSource as T } from "./api/fetchEventSource/fetch.mjs";
36
36
  const p = new V("[DialogSession] ");
37
37
  class k extends $ {
38
- constructor(s, a = "", d, h, e, i) {
39
- super(s, a, d, h, e, i);
38
+ constructor(s, t = "", d, h, e, i) {
39
+ super(s, t, d, h, e, i);
40
40
  M(this, "ctrl", new AbortController());
41
41
  }
42
42
  prepareConnection() {
@@ -44,14 +44,14 @@ class k extends $ {
44
44
  this._ready = !0, this.event.emit("ready"), this.frozen = !1, s(!0);
45
45
  }));
46
46
  }
47
- postChatV2EventSource(s, a, d, h, e, i) {
47
+ postChatV2EventSource(s, t, d, h, e, i) {
48
48
  return f(this, null, function* () {
49
49
  const r = {
50
50
  code: 0,
51
51
  // messageId: uuidv4(),
52
52
  content: "",
53
53
  role: C.Robot,
54
- sessionId: a,
54
+ sessionId: t,
55
55
  reference: [],
56
56
  searchReference: [],
57
57
  messageTime: "",
@@ -63,7 +63,7 @@ class k extends $ {
63
63
  }, m = y(u({}, d), {
64
64
  stream: S.stream
65
65
  });
66
- T(`${S.apiRoot}/chat/v2/chat?applicationId=${s}&sessionId=${a}`, {
66
+ T(`${S.apiRoot}/chat/v2/chat?applicationId=${s}&sessionId=${t}`, {
67
67
  method: "POST",
68
68
  headers: {
69
69
  Authorization: `Bearer ${this.token}`,
@@ -77,19 +77,19 @@ class k extends $ {
77
77
  },
78
78
  onmessage(g) {
79
79
  if (!g.data.includes('{"code": ')) {
80
- let t = {};
80
+ let a = {};
81
81
  try {
82
- t = JSON.parse(g.data);
83
- } catch (J) {
82
+ a = JSON.parse(g.data);
83
+ } catch (E) {
84
84
  }
85
- (t == null ? void 0 : t.mtype) === "search" ? r.searchReference.push(t) : r.content = r.content + g.data;
85
+ (a == null ? void 0 : a.mtype) === "search" ? r.searchReference.push(a) : r.content = r.content + g.data;
86
86
  const o = {
87
87
  content: r.content,
88
88
  role: 1,
89
89
  reference: r.reference,
90
90
  searchReference: r.searchReference,
91
91
  messageId: r.messageId,
92
- sessionId: a,
92
+ sessionId: t,
93
93
  messageTime: _(/* @__PURE__ */ new Date()).format("YYYY-MM-DD HH:mm:ss"),
94
94
  comment: {
95
95
  isAgree: 0
@@ -100,18 +100,18 @@ class k extends $ {
100
100
  }
101
101
  const n = JSON.parse(g.data);
102
102
  if (r.reference = n.data.reference, r.searchReference = n.data.searchReference, r.messageTime = n.data.messageTime, r.messageId = n.data.messageId, r.llmModel = n.data.llmModel, r.content = n.data.content, r.code = n.code, n.code === 200) {
103
- const t = {
103
+ const a = {
104
104
  code: r.code,
105
105
  content: r.content,
106
106
  role: 1,
107
107
  reference: r.reference,
108
108
  searchReference: r.searchReference,
109
109
  messageId: r.messageId,
110
- sessionId: a,
110
+ sessionId: t,
111
111
  messageTime: r.messageTime,
112
112
  isReplying: !0
113
113
  };
114
- e != null && e.onmessage && e.onmessage(t);
114
+ e != null && e.onmessage && e.onmessage(a);
115
115
  } else
116
116
  return e != null && e.onclose && e.onclose(r), i && i({
117
117
  code: r.code,
@@ -129,7 +129,7 @@ class k extends $ {
129
129
  reference: r.reference,
130
130
  searchReference: r.searchReference,
131
131
  messageId: r.messageId,
132
- sessionId: a,
132
+ sessionId: t,
133
133
  messageTime: r.messageTime,
134
134
  comment: {
135
135
  isAgree: 0
@@ -142,14 +142,14 @@ class k extends $ {
142
142
  });
143
143
  });
144
144
  }
145
- postChatV3EventSource(s, a, d, h, e, i) {
145
+ postChatV3EventSource(s, t, d, h, e, i) {
146
146
  return f(this, null, function* () {
147
147
  const r = this, m = {
148
148
  code: 0,
149
149
  // messageId: uuidv4(),
150
150
  content: "",
151
151
  role: C.Robot,
152
- sessionId: a,
152
+ sessionId: t,
153
153
  reference: [],
154
154
  searchReference: [],
155
155
  messageTime: "",
@@ -165,7 +165,7 @@ class k extends $ {
165
165
  }, g = y(u({}, d), {
166
166
  stream: S.stream
167
167
  });
168
- T(`${S.apiRoot}/chat/v3/chat?applicationId=${s}&sessionId=${a}`, {
168
+ T(`${S.apiRoot}/chat/v3/chat?applicationId=${s}&sessionId=${t}`, {
169
169
  method: "POST",
170
170
  headers: {
171
171
  Authorization: `Bearer ${this.token}`,
@@ -180,18 +180,18 @@ class k extends $ {
180
180
  onmessage(n) {
181
181
  if (!n.data && !n.event && !n.id && !n.retry)
182
182
  return;
183
- let t = {};
183
+ let a = {};
184
184
  try {
185
- t = JSON.parse(n.data);
185
+ a = JSON.parse(n.data);
186
186
  } catch (o) {
187
187
  console.error("parse eventData to JSON failed. ", n.data);
188
188
  }
189
- if (t.code !== 200)
190
- return m.index = -1, m.code = t.code, m.message = t.message, e != null && e.onmessage && e.onmessage(m), i && i({
191
- code: t.code,
192
- message: t.message
189
+ if (a.code !== 200)
190
+ return m.index = -1, m.code = a.code, m.message = a.message, e != null && e.onmessage && e.onmessage(m), i && i({
191
+ code: a.code,
192
+ message: a.message
193
193
  });
194
- r.handleStreamAnswer(t, m), e != null && e.onmessage && e.onmessage(m);
194
+ r.handleStreamAnswer(a, m), e != null && e.onmessage && e.onmessage(m);
195
195
  },
196
196
  onerror() {
197
197
  e != null && e.onerror && e.onerror();
@@ -205,7 +205,7 @@ class k extends $ {
205
205
  });
206
206
  });
207
207
  }
208
- sendQuestion(s, a) {
208
+ sendQuestion(s, t) {
209
209
  return f(this, null, function* () {
210
210
  const {
211
211
  content: d,
@@ -215,7 +215,7 @@ class k extends $ {
215
215
  } = s, {
216
216
  stream: r,
217
217
  referenceFirst: m
218
- } = a;
218
+ } = t;
219
219
  if (this.active || (yield this.activate()), this._id) {
220
220
  const g = this.convertKnowledgesToChatFormat(this.knowledges);
221
221
  let n = {
@@ -223,29 +223,28 @@ class k extends $ {
223
223
  fileIds: h,
224
224
  referenceFirst: m,
225
225
  oldMessageId: e,
226
- promptVariables: this.promptVariables.filter((t) => t.type === v.User).reduce((t, o) => y(u({}, t), {
226
+ promptVariables: this.promptVariables.filter((a) => a.type === v.User).reduce((a, o) => y(u({}, a), {
227
227
  [o.key]: o.value
228
228
  }), {}),
229
- systemPromptVariables: this.promptVariables.filter((t) => t.type === v.System).reduce((t, o) => y(u({}, t), {
229
+ systemPromptVariables: this.promptVariables.filter((a) => a.type === v.System).reduce((a, o) => y(u({}, a), {
230
230
  [o.key]: o.value
231
231
  }), {}),
232
232
  knowledges: g,
233
- //开启内容摘要
234
- enableTitleSummary: !0,
233
+ enableTitleSummary: this.resolveEnableTitleSummary(),
235
234
  imageContent: i
236
235
  };
237
236
  this.ctrl = new AbortController(), this.postChatV3EventSource(this._applicationId, this._id, n, this.ctrl.signal, {
238
237
  onopen: () => {
239
238
  p.log("open", this.ctrl);
240
239
  },
241
- onmessage: (t) => {
240
+ onmessage: (a) => {
242
241
  if (this._stopAnswer)
243
242
  return;
244
243
  let o = this.messages[this.messages.length - 1];
245
- o && o.role === O.Robot ? (o = u(u({}, o), t), this.messages[this.messages.length - 1] = o, this.event.emit("message:content", o), this.event.emit("message:updated", o)) : (this.pushMessage(t), this.event.emit("message:content", t));
244
+ o && o.role === O.Robot ? (o = u(u({}, o), a), this.messages[this.messages.length - 1] = o, this.event.emit("message:content", o), this.event.emit("message:updated", o)) : (this.pushMessage(a), this.event.emit("message:content", a));
246
245
  },
247
- onclose: (t) => f(this, null, function* () {
248
- this._stopAnswer || (p.log(t, "onclose"), this.event.emit("answer:finish", t));
246
+ onclose: (a) => f(this, null, function* () {
247
+ this._stopAnswer || (p.log(a, "onclose"), this.event.emit("answer:finish", a));
249
248
  }),
250
249
  onerror: () => {
251
250
  this._stopAnswer || (this.event.emit("message:error", ""), this.frozen = !1);
@@ -273,10 +272,10 @@ class k extends $ {
273
272
  });
274
273
  }
275
274
  convertKnowledgesToChatFormat(s) {
276
- return s ? s.map((a) => a != null && a.fileIds ? {
277
- id: a.id,
278
- fileIds: a.fileIds
279
- } : a.id) : [];
275
+ return s ? s.map((t) => t != null && t.fileIds ? {
276
+ id: t.id,
277
+ fileIds: t.fileIds
278
+ } : t.id) : [];
280
279
  }
281
280
  }
282
281
  export {