super-agent-sdk 1.0.18 → 1.0.20

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/dist/index.mjs CHANGED
@@ -1,26 +1,26 @@
1
- import { p as b, s as S } from "./nosUploader-CnYDALPr.js";
2
- import { c as W } from "./nosUploader-CnYDALPr.js";
3
- function f(r) {
4
- if (Array.isArray(r)) return r.map((e) => f(e));
5
- if (r && typeof r == "object" && r.constructor === Object) {
1
+ import { p as b, s as C } from "./nosUploader-DjJ7u2B1.js";
2
+ import { c as W } from "./nosUploader-DjJ7u2B1.js";
3
+ function f(s) {
4
+ if (Array.isArray(s)) return s.map((e) => f(e));
5
+ if (s && typeof s == "object" && s.constructor === Object) {
6
6
  const e = {};
7
- for (const [i, n] of Object.entries(r)) {
8
- const d = i.replace(/_([a-z])/g, (t, s) => s.toUpperCase());
7
+ for (const [i, n] of Object.entries(s)) {
8
+ const d = i.replace(/_([a-z])/g, (t, r) => r.toUpperCase());
9
9
  e[d] = f(n);
10
10
  }
11
11
  return e;
12
12
  }
13
- return r;
13
+ return s;
14
14
  }
15
- const A = "/api/agent/runtime/v1";
16
- class $ {
15
+ const S = "/api/agent/runtime/v1";
16
+ class A {
17
17
  constructor(e) {
18
- this.refreshing = null;
19
- const i = e.baseUrl ?? A;
20
- this.baseUrl = i.replace(/\/$/, ""), this.tokenGateway = e.tokenGateway.replace(/\/$/, ""), this.appId = e.appId ?? "", this.token = e.token ?? "", this.botId = e.botId, this.isAbsoluteUrl = /^https?:\/\//.test(this.baseUrl), this.isAbsoluteGateway = /^https?:\/\//.test(this.tokenGateway), this.loginUrl = e.loginUrl, this.onAuthExpired = e.onAuthExpired;
18
+ this.refreshing = null, this.tokenPromise = null;
19
+ const i = e.baseUrl ?? S;
20
+ this.baseUrl = i.replace(/\/$/, ""), this.tokenGateway = e.tokenGateway.replace(/\/$/, ""), this.appId = e.appId ?? "", this.token = e.token ?? "", this.botCode = e.botCode, this.tenantId = e.tenantId, this.isAbsoluteUrl = /^https?:\/\//.test(this.baseUrl), this.isAbsoluteGateway = /^https?:\/\//.test(this.tokenGateway), this.loginUrl = e.loginUrl, this.onAuthExpired = e.onAuthExpired;
21
21
  }
22
- getBotId() {
23
- return this.botId;
22
+ getBotCode() {
23
+ return this.botCode;
24
24
  }
25
25
  getAppKey() {
26
26
  return this.appId;
@@ -32,20 +32,38 @@ class $ {
32
32
  getOrigin() {
33
33
  return typeof window < "u" ? window.location.origin : "";
34
34
  }
35
- /** POST {origin}{tokenGateway}/v2/token/generate — 获取 token + appId */
35
+ /** POST {origin}{tokenGateway}/superagent/v2/token/generate — 获取 token + appId。
36
+ *
37
+ * 已持 token 直接返回缓存;并发调用凭 in-flight promise 合并为一次请求
38
+ * (多 widget 共享同一 sdk 时,各自 ChatProvider 挂载只打一次签发端点)。
39
+ * 401 强刷前须先清 this.token(见 handleTokenRefresh)。
40
+ */
36
41
  async fetchToken() {
37
- const i = `${this.isAbsoluteGateway ? this.tokenGateway : `${this.getOrigin()}${this.tokenGateway}`}/v2/token/generate`, n = await fetch(i, {
38
- method: "POST",
39
- headers: { "Content-Type": "application/json" },
40
- body: JSON.stringify({ botId: this.botId })
41
- });
42
- if (!n.ok)
43
- throw new Error(`HTTP ${n.status}: ${n.statusText}`);
44
- const d = await n.json();
45
- if (d.code !== "200")
46
- throw new Error(d.message || `API error: ${d.code}`);
47
- const t = f(d.data);
48
- return this.token = t.token, t.appId && !this.appId && (this.appId = t.appId), t.token;
42
+ if (this.token) return this.token;
43
+ if (this.tokenPromise) return this.tokenPromise;
44
+ this.tokenPromise = (async () => {
45
+ const i = `${this.isAbsoluteGateway ? this.tokenGateway : `${this.getOrigin()}${this.tokenGateway}`}/superagent/v2/token/generate`, n = {
46
+ "Content-Type": "application/json"
47
+ };
48
+ this.tenantId != null && (n["X-Tenant-Id"] = String(this.tenantId));
49
+ const d = await fetch(i, {
50
+ method: "POST",
51
+ headers: n,
52
+ body: JSON.stringify({ botCode: this.botCode })
53
+ });
54
+ if (!d.ok)
55
+ throw new Error(`HTTP ${d.status}: ${d.statusText}`);
56
+ const t = await d.json();
57
+ if (t.code !== "200")
58
+ throw new Error(t.message || `API error: ${t.code}`);
59
+ const r = f(t.data);
60
+ return this.token = r.token, r.appId && !this.appId && (this.appId = r.appId), r.token;
61
+ })();
62
+ try {
63
+ return await this.tokenPromise;
64
+ } finally {
65
+ this.tokenPromise = null;
66
+ }
49
67
  }
50
68
  headers(e) {
51
69
  return {
@@ -59,7 +77,7 @@ class $ {
59
77
  if (this.refreshing)
60
78
  return await this.refreshing, !0;
61
79
  try {
62
- return this.refreshing = (async () => {
80
+ return this.token = "", this.refreshing = (async () => {
63
81
  await this.fetchToken();
64
82
  })(), await this.refreshing, !0;
65
83
  } catch {
@@ -95,10 +113,10 @@ class $ {
95
113
  }
96
114
  throw new Error(o);
97
115
  }
98
- const s = await t.json();
99
- if (s.code !== "200")
100
- throw new Error(s.message || `API error: ${s.code}`);
101
- return f(s.data);
116
+ const r = await t.json();
117
+ if (r.code !== "200")
118
+ throw new Error(r.message || `API error: ${r.code}`);
119
+ return f(r.data);
102
120
  }
103
121
  get(e, i) {
104
122
  return this.request("GET", e, { params: i });
@@ -123,18 +141,18 @@ class $ {
123
141
  signal: n
124
142
  });
125
143
  if (t.status === 401) {
126
- const s = await b(t.clone());
127
- if (s.isCookieExpired && typeof (i == null ? void 0 : i.message) == "string") {
128
- S({
129
- botId: this.botId,
144
+ const r = await b(t.clone());
145
+ if (r.isCookieExpired && typeof (i == null ? void 0 : i.message) == "string") {
146
+ C({
147
+ botCode: this.botCode,
130
148
  message: i.message,
131
149
  sessionId: i.sessionId ?? ""
132
150
  });
133
- const a = s.loginUrl ?? this.loginUrl;
151
+ const a = r.loginUrl ?? this.loginUrl;
134
152
  return this.onAuthExpired ? this.onAuthExpired({
135
153
  loginUrl: a,
136
- sessionId: s.sessionId,
137
- botId: this.botId
154
+ sessionId: r.sessionId,
155
+ botCode: this.botCode
138
156
  }) : a && window.location.replace(a), t;
139
157
  }
140
158
  if (await this.handleTokenRefresh())
@@ -148,18 +166,18 @@ class $ {
148
166
  return t;
149
167
  }
150
168
  }
151
- function u(r) {
152
- return typeof r == "string" ? r : Array.isArray(r) ? r.map((e) => {
169
+ function u(s) {
170
+ return typeof s == "string" ? s : Array.isArray(s) ? s.map((e) => {
153
171
  if (typeof e == "string") return e;
154
172
  if (e && typeof e == "object") {
155
173
  if (typeof e.text == "string") return e.text;
156
174
  if (e.type) return `[${e.type}${e.mime_type ? ": " + e.mime_type : ""}]`;
157
175
  }
158
176
  return "";
159
- }).join("") : r == null ? "" : String(r);
177
+ }).join("") : s == null ? "" : String(s);
160
178
  }
161
- function w(r) {
162
- const e = r.split(`
179
+ function w(s) {
180
+ const e = s.split(`
163
181
  `).map((o) => o.trim()).filter((o) => o.length > 0);
164
182
  let i, n, d;
165
183
  for (const o of e)
@@ -179,7 +197,7 @@ ${a}` : a;
179
197
  } catch {
180
198
  return null;
181
199
  }
182
- const s = t.type === "tool_result" && typeof t.content == "object" && t.content ? t.content : void 0;
200
+ const r = t.type === "tool_result" && typeof t.content == "object" && t.content ? t.content : void 0;
183
201
  switch (t.type) {
184
202
  case "session.start":
185
203
  return {
@@ -206,18 +224,26 @@ ${a}` : a;
206
224
  event: n,
207
225
  id: i
208
226
  };
227
+ case "tool_delta":
228
+ return {
229
+ type: "tool_delta",
230
+ content: typeof t.content == "string" ? t.content : "",
231
+ toolCallId: t.tool_call_id ?? t.toolCallId ?? "",
232
+ event: n,
233
+ id: i
234
+ };
209
235
  case "tool_result": {
210
- const o = s == null ? void 0 : s.result;
236
+ const o = r == null ? void 0 : r.result;
211
237
  let a;
212
- return typeof o == "string" ? a = o : o != null && typeof o == "object" ? a = JSON.stringify(o) : s && typeof s == "object" && Object.keys(s).length > 0 ? a = JSON.stringify(s) : a = u(t.output ?? ""), {
238
+ return typeof o == "string" ? a = o : o != null && typeof o == "object" ? a = JSON.stringify(o) : r && typeof r == "object" && Object.keys(r).length > 0 ? a = JSON.stringify(r) : a = u(t.output ?? ""), {
213
239
  type: "tool_result",
214
240
  content: a,
215
241
  toolName: t.name,
216
242
  toolCallId: t.id,
217
243
  artifacts: Array.isArray(t.artifacts) ? t.artifacts : void 0,
218
- renderMode: (s == null ? void 0 : s.render_mode) ?? t.render_mode ?? t.renderMode,
219
- html: (s == null ? void 0 : s.html) ?? t.html,
220
- markdown: (s == null ? void 0 : s.markdown) ?? t.markdown,
244
+ renderMode: (r == null ? void 0 : r.render_mode) ?? t.render_mode ?? t.renderMode,
245
+ html: (r == null ? void 0 : r.html) ?? t.html,
246
+ markdown: (r == null ? void 0 : r.markdown) ?? t.markdown,
221
247
  event: n,
222
248
  id: i
223
249
  };
@@ -268,18 +294,18 @@ ${a}` : a;
268
294
  return null;
269
295
  }
270
296
  }
271
- async function T(r, e, i) {
272
- if (!r.body) {
297
+ async function T(s, e, i) {
298
+ if (!s.body) {
273
299
  i(new Error("Response body is null"));
274
300
  return;
275
301
  }
276
- const n = r.body.getReader(), d = new TextDecoder();
302
+ const n = s.body.getReader(), d = new TextDecoder();
277
303
  let t = "";
278
304
  try {
279
305
  for (; ; ) {
280
- const { value: s, done: o } = await n.read();
306
+ const { value: r, done: o } = await n.read();
281
307
  if (o) break;
282
- t += d.decode(s, { stream: !0 });
308
+ t += d.decode(r, { stream: !0 });
283
309
  let a;
284
310
  for (; (a = t.indexOf(`
285
311
 
@@ -291,11 +317,11 @@ async function T(r, e, i) {
291
317
  }
292
318
  }
293
319
  if (t.trim()) {
294
- const s = w(t);
295
- s && e(s);
320
+ const r = w(t);
321
+ r && e(r);
296
322
  }
297
- } catch (s) {
298
- (s == null ? void 0 : s.name) !== "AbortError" && i(s instanceof Error ? s : new Error(String(s)));
323
+ } catch (r) {
324
+ (r == null ? void 0 : r.name) !== "AbortError" && i(r instanceof Error ? r : new Error(String(r)));
299
325
  } finally {
300
326
  try {
301
327
  n.releaseLock();
@@ -303,24 +329,24 @@ async function T(r, e, i) {
303
329
  }
304
330
  }
305
331
  }
306
- function _(r, e) {
332
+ function $(s, e) {
307
333
  var t;
308
- const i = new AbortController(), n = e.signal ? x(e.signal, i.signal) : i.signal, d = {
309
- botId: r.getBotId(),
334
+ const i = new AbortController(), n = e.signal ? _(e.signal, i.signal) : i.signal, d = {
335
+ botCode: s.getBotCode(),
310
336
  message: e.message,
311
337
  sessionId: e.sessionId,
312
338
  stream: e.stream !== !1,
313
339
  // url 仅前端回显(下载/预览),剥离后发送——签名 URL 不进后端
314
340
  ...(t = e.attachments) != null && t.length ? {
315
- attachments: e.attachments.map(({ url: s, ...o }) => o)
341
+ attachments: e.attachments.map(({ url: r, ...o }) => o)
316
342
  } : {}
317
343
  };
318
- return d.stream ? r.streamPost("/chat", d, n).then(async (s) => {
344
+ return d.stream ? s.streamPost("/chat", d, n).then(async (r) => {
319
345
  var o;
320
- if (!s.ok) {
321
- let a = `HTTP ${s.status}`;
346
+ if (!r.ok) {
347
+ let a = `HTTP ${r.status}`;
322
348
  try {
323
- const c = await s.json();
349
+ const c = await r.json();
324
350
  c != null && c.message && (a = c.message);
325
351
  } catch {
326
352
  }
@@ -328,7 +354,7 @@ function _(r, e) {
328
354
  return;
329
355
  }
330
356
  return T(
331
- s,
357
+ r,
332
358
  (a) => {
333
359
  var c, l, h, g, m, y, I, p;
334
360
  a.type === "done" && a.sessionId ? ((c = e.onMessage) == null || c.call(e, a), (l = e.onDone) == null || l.call(e, { sessionId: a.sessionId, content: a.content, messageId: a.messageId, roundId: a.roundId, artifacts: a.artifacts })) : a.type === "done" ? ((h = e.onMessage) == null || h.call(e, a), (g = e.onDone) == null || g.call(e, { sessionId: "", content: a.content, messageId: a.messageId, roundId: a.roundId, artifacts: a.artifacts })) : a.type === "stop" ? ((m = e.onMessage) == null || m.call(e, a), (y = e.onDone) == null || y.call(e, { sessionId: a.sessionId ?? "", content: a.content, messageId: a.messageId, roundId: a.roundId })) : a.type === "error" ? (I = e.onError) == null || I.call(e, new Error(a.content)) : (p = e.onMessage) == null || p.call(e, a);
@@ -338,104 +364,105 @@ function _(r, e) {
338
364
  return (c = e.onError) == null ? void 0 : c.call(e, a);
339
365
  }
340
366
  );
341
- }).catch((s) => {
367
+ }).catch((r) => {
342
368
  var o;
343
- (s == null ? void 0 : s.name) !== "AbortError" && ((o = e.onError) == null || o.call(e, s instanceof Error ? s : new Error(String(s))));
344
- }) : r.post("/chat", d).then((s) => {
369
+ (r == null ? void 0 : r.name) !== "AbortError" && ((o = e.onError) == null || o.call(e, r instanceof Error ? r : new Error(String(r))));
370
+ }) : s.post("/chat", d).then((r) => {
345
371
  var o;
346
372
  (o = e.onDone) == null || o.call(e, {
347
- sessionId: s.sessionId,
348
- content: s.content ?? "",
349
- messageId: s.messageId
373
+ sessionId: r.sessionId,
374
+ content: r.content ?? "",
375
+ messageId: r.messageId
350
376
  });
351
- }).catch((s) => {
377
+ }).catch((r) => {
352
378
  var o;
353
- (o = e.onError) == null || o.call(e, s instanceof Error ? s : new Error(String(s)));
379
+ (o = e.onError) == null || o.call(e, r instanceof Error ? r : new Error(String(r)));
354
380
  }), i;
355
381
  }
356
- function x(r, e) {
382
+ function _(s, e) {
357
383
  const i = new AbortController(), n = () => i.abort();
358
- return r.addEventListener("abort", n, { once: !0 }), e.addEventListener("abort", n, { once: !0 }), (r.aborted || e.aborted) && i.abort(), i.signal;
384
+ return s.addEventListener("abort", n, { once: !0 }), e.addEventListener("abort", n, { once: !0 }), (s.aborted || e.aborted) && i.abort(), i.signal;
359
385
  }
360
- async function E(r) {
361
- return (await r.post("/chat/sessions", {
362
- botId: r.getBotId()
386
+ async function P(s) {
387
+ return (await s.post("/chat/sessions", {
388
+ botCode: s.getBotCode()
363
389
  })).sessionId;
364
390
  }
365
- function O(r) {
391
+ function x(s) {
366
392
  return {
367
393
  // 后端返回 thread_id,toCamelCase 转为 threadId,映射为 sessionId
368
- sessionId: r.threadId ?? r.sessionId,
369
- botId: r.botId,
370
- title: r.title,
371
- createTime: r.createTime,
372
- updateTime: r.updateTime
394
+ sessionId: s.threadId ?? s.sessionId,
395
+ // bot 外部标识统一 botCode(createSuperAgent 入参,全链消费);
396
+ // 后端回传的内部 bot 标识字段 SDK 不消费、不暴露
397
+ title: s.title,
398
+ createTime: s.createTime,
399
+ updateTime: s.updateTime
373
400
  };
374
401
  }
375
- async function v(r, e) {
376
- const i = await r.get("/chat/conversations", {
377
- botId: r.getBotId(),
402
+ async function E(s, e) {
403
+ const i = await s.get("/chat/conversations", {
404
+ botCode: s.getBotCode(),
378
405
  page: (e == null ? void 0 : e.page) ?? 1,
379
406
  size: (e == null ? void 0 : e.size) ?? 20
380
407
  });
381
408
  return {
382
409
  ...i,
383
- items: i.items.map(O)
410
+ items: i.items.map(x)
384
411
  };
385
412
  }
386
- async function C(r, e, i) {
387
- await r.patch(`/chat/conversations/${e}`, { title: i });
413
+ async function v(s, e, i) {
414
+ await s.patch(`/chat/conversations/${e}`, { title: i });
388
415
  }
389
- async function P(r, e) {
390
- await r.del(`/chat/conversations/${e}`);
416
+ async function O(s, e) {
417
+ await s.del(`/chat/conversations/${e}`);
391
418
  }
392
- async function U(r, e) {
393
- const i = await r.get(`/chat/conversations/${e}/messages`);
419
+ async function U(s, e) {
420
+ const i = await s.get(`/chat/conversations/${e}/messages`);
394
421
  return N(i);
395
422
  }
396
423
  function k() {
397
424
  return `r_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
398
425
  }
399
- function N(r) {
426
+ function N(s) {
400
427
  var d;
401
- const e = r.length > 0 && Array.isArray((d = r[0]) == null ? void 0 : d.data), i = [];
428
+ const e = s.length > 0 && Array.isArray((d = s[0]) == null ? void 0 : d.data), i = [];
402
429
  if (e)
403
- for (const t of r)
430
+ for (const t of s)
404
431
  i.push({
405
432
  roundId: t.roundId ?? k(),
406
433
  artifacts: Array.isArray(t.artifacts) && t.artifacts.length ? t.artifacts : void 0,
407
434
  items: Array.isArray(t.data) ? t.data : []
408
435
  });
409
436
  else
410
- i.push({ roundId: k(), items: r });
437
+ i.push({ roundId: k(), items: s });
411
438
  const n = [];
412
439
  for (const t of i) {
413
- const s = D(t.items);
414
- for (const o of s) o.roundId = t.roundId;
440
+ const r = D(t.items);
441
+ for (const o of r) o.roundId = t.roundId;
415
442
  if (t.artifacts) {
416
- const o = s.findLast((a) => a.role === "assistant");
443
+ const o = r.findLast((a) => a.role === "assistant");
417
444
  o && (o.artifacts = t.artifacts);
418
445
  }
419
- n.push(...s);
446
+ n.push(...r);
420
447
  }
421
448
  return n;
422
449
  }
423
- function D(r) {
424
- const e = [...r].sort((s, o) => {
425
- const a = new Date(s.createTime ?? 0).getTime() || 0, c = new Date(o.createTime ?? 0).getTime() || 0;
426
- return a !== c ? a - c : (s.seq ?? 0) - (o.seq ?? 0);
450
+ function D(s) {
451
+ const e = [...s].sort((r, o) => {
452
+ const a = new Date(r.createTime ?? 0).getTime() || 0, c = new Date(o.createTime ?? 0).getTime() || 0;
453
+ return a !== c ? a - c : (r.seq ?? 0) - (o.seq ?? 0);
427
454
  }), i = /* @__PURE__ */ new Map();
428
- for (const s of e)
429
- s.role === "tool" && s.toolCallId && i.set(s.toolCallId, s.content || "");
430
- const n = /* @__PURE__ */ new Set(), d = [], t = (s, o, a) => {
455
+ for (const r of e)
456
+ r.role === "tool" && r.toolCallId && i.set(r.toolCallId, r.content || "");
457
+ const n = /* @__PURE__ */ new Set(), d = [], t = (r, o, a) => {
431
458
  const c = d[d.length - 1];
432
- (c == null ? void 0 : c.role) === "assistant" ? (c.parts.push(...s), c.id = o) : d.push({ id: o, role: "assistant", parts: [...s], timestamp: a });
459
+ (c == null ? void 0 : c.role) === "assistant" ? (c.parts.push(...r), c.id = o) : d.push({ id: o, role: "assistant", parts: [...r], timestamp: a });
433
460
  };
434
- for (const s of e) {
435
- if (s.role === "system") continue;
436
- const o = String(s.id ?? s.messageId ?? `msg_${Date.now()}`), a = new Date(s.createTime ?? "").getTime() || Date.now();
437
- if (s.role === "human") {
438
- const c = (s.attachments ?? []).map((l) => ({
461
+ for (const r of e) {
462
+ if (r.role === "system") continue;
463
+ const o = String(r.id ?? r.messageId ?? `msg_${Date.now()}`), a = new Date(r.createTime ?? "").getTime() || Date.now();
464
+ if (r.role === "human") {
465
+ const c = (r.attachments ?? []).map((l) => ({
439
466
  type: "attachment",
440
467
  attachment: {
441
468
  nosKey: l.nosKey ?? l.attachmentId ?? "",
@@ -450,36 +477,36 @@ function D(r) {
450
477
  d.push({
451
478
  id: o,
452
479
  role: "user",
453
- parts: [...c, { type: "text", content: u(s.content) }],
480
+ parts: [...c, { type: "text", content: u(r.content) }],
454
481
  timestamp: a
455
482
  });
456
483
  continue;
457
484
  }
458
- if (s.role === "ai") {
459
- const c = M(s, i, n);
485
+ if (r.role === "ai") {
486
+ const c = M(r, i, n);
460
487
  c.length > 0 && t(c, o, a);
461
488
  continue;
462
489
  }
463
- if (s.role === "tool") {
464
- if (s.toolCallId && n.has(s.toolCallId)) continue;
465
- t([L(s)], o, a);
490
+ if (r.role === "tool") {
491
+ if (r.toolCallId && n.has(r.toolCallId)) continue;
492
+ t([L(r)], o, a);
466
493
  }
467
494
  }
468
495
  return d;
469
496
  }
470
- function M(r, e, i) {
497
+ function M(s, e, i) {
471
498
  const n = [];
472
- r.reasoning && n.push({ type: "thinking", content: r.reasoning }), r.content && n.push({ type: "text", content: u(r.content) });
473
- for (const d of r.toolCalls ?? [])
499
+ s.reasoning && n.push({ type: "thinking", content: s.reasoning }), s.content && n.push({ type: "text", content: u(s.content) });
500
+ for (const d of s.toolCalls ?? [])
474
501
  d.is_interrupt ?? d.isInterrupt ? (i.add(d.id), n.push(q(d, e))) : n.push(J(d));
475
502
  return n;
476
503
  }
477
- function q(r, e) {
478
- const i = e.has(r.id), n = typeof r.args == "object" ? r.args : {};
504
+ function q(s, e) {
505
+ const i = e.has(s.id), n = typeof s.args == "object" ? s.args : {};
479
506
  return {
480
507
  type: "interrupt",
481
508
  interrupt: {
482
- interruptId: r.id ?? "",
509
+ interruptId: s.id ?? "",
483
510
  interruptType: n.interruptType ?? "input",
484
511
  content: n.content ?? "",
485
512
  options: n.options,
@@ -491,50 +518,50 @@ function q(r, e) {
491
518
  metadata: n.metadata
492
519
  },
493
520
  resolved: i,
494
- response: i ? { action: "submit", value: j(e.get(r.id)) } : void 0
521
+ response: i ? { action: "submit", value: j(e.get(s.id)) } : void 0
495
522
  };
496
523
  }
497
- function J(r) {
524
+ function J(s) {
498
525
  let e;
499
526
  try {
500
- e = typeof r.args == "string" ? r.args : JSON.stringify(r.args ?? {});
527
+ e = typeof s.args == "string" ? s.args : JSON.stringify(s.args ?? {});
501
528
  } catch {
502
- e = String(r.args ?? "{}");
529
+ e = String(s.args ?? "{}");
503
530
  }
504
- return { type: "tool_call", toolName: r.name ?? "", toolCallId: r.id ?? "", args: e };
531
+ return { type: "tool_call", toolName: s.name ?? "", toolCallId: s.id ?? "", args: e };
505
532
  }
506
- function L(r) {
533
+ function L(s) {
507
534
  var i, n, d, t;
508
- const e = Array.isArray(r.artifacts) ? r.artifacts : void 0;
535
+ const e = Array.isArray(s.artifacts) ? s.artifacts : void 0;
509
536
  return {
510
537
  type: "tool_result",
511
- toolName: r.toolName ?? "",
512
- toolCallId: r.toolCallId ?? "",
538
+ toolName: s.toolName ?? "",
539
+ toolCallId: s.toolCallId ?? "",
513
540
  // tool 行后端 content 即展示摘要(_build_tool_fields 与 SSE 口径一致),直接读 content
514
- content: u(r.content),
541
+ content: u(s.content),
515
542
  artifacts: e,
516
- renderMode: r.renderMode ?? ((i = r.metadata) == null ? void 0 : i.renderMode) ?? ((n = r.metadata) == null ? void 0 : n.render_mode),
517
- html: r.html ?? ((d = r.metadata) == null ? void 0 : d.html),
518
- markdown: r.markdown ?? ((t = r.metadata) == null ? void 0 : t.markdown)
543
+ renderMode: s.renderMode ?? ((i = s.metadata) == null ? void 0 : i.renderMode) ?? ((n = s.metadata) == null ? void 0 : n.render_mode),
544
+ html: s.html ?? ((d = s.metadata) == null ? void 0 : d.html),
545
+ markdown: s.markdown ?? ((t = s.metadata) == null ? void 0 : t.markdown)
519
546
  };
520
547
  }
521
- function j(r) {
522
- if (r != null)
548
+ function j(s) {
549
+ if (s != null)
523
550
  try {
524
- return JSON.parse(r);
551
+ return JSON.parse(s);
525
552
  } catch {
526
- return r;
553
+ return s;
527
554
  }
528
555
  }
529
- async function G(r, e, i, n, d, t, s) {
530
- const o = await r.streamPost(
556
+ async function G(s, e, i, n, d, t, r) {
557
+ const o = await s.streamPost(
531
558
  `/chat/interrupt/${e}/respond`,
532
559
  {
533
560
  sessionId: i,
534
561
  action: n.action,
535
562
  value: n.value
536
563
  },
537
- s
564
+ r
538
565
  );
539
566
  if (!o.ok) {
540
567
  const a = new Error(`HTTP ${o.status}`);
@@ -548,28 +575,28 @@ async function G(r, e, i, n, d, t, s) {
548
575
  (a) => t == null ? void 0 : t(a)
549
576
  );
550
577
  }
551
- async function R(r) {
552
- return r.get(`/chat/bots/${r.getBotId()}/skills`);
578
+ async function R(s) {
579
+ return s.get(`/chat/bots/${s.getBotCode()}/skills`);
553
580
  }
554
- async function B(r, e) {
555
- await r.post("/chat/stop", { sessionId: e });
581
+ async function B(s, e) {
582
+ await s.post("/chat/stop", { sessionId: e });
556
583
  }
557
- function z(r) {
558
- const e = new $(r);
584
+ function z(s) {
585
+ const e = new A(s);
559
586
  return {
560
- botId: e.getBotId(),
587
+ botCode: e.getBotCode(),
561
588
  getToken: () => e.fetchToken(),
562
- createSession: () => E(e),
563
- chat: (n) => _(e, n),
564
- listConversations: (n) => v(e, n),
565
- renameConversation: (n, d) => C(e, n, d),
566
- deleteConversation: (n) => P(e, n),
589
+ createSession: () => P(e),
590
+ chat: (n) => $(e, n),
591
+ listConversations: (n) => E(e, n),
592
+ renameConversation: (n, d) => v(e, n, d),
593
+ deleteConversation: (n) => O(e, n),
567
594
  getMessages: (n) => U(e, n),
568
- respondInterrupt: (n, d, t, s, o, a) => G(e, n, d, t, s, o, a),
595
+ respondInterrupt: (n, d, t, r, o, a) => G(e, n, d, t, r, o, a),
569
596
  setToken: (n) => e.setToken(n),
570
597
  feedback: async (n, d, t) => {
571
- const s = { type: d };
572
- d === "dislike" && ((t == null ? void 0 : t.reason) != null && (s.reason = t.reason), t != null && t.remark && (s.remark = t.remark)), await e.post(`/chat/messages/${n}/feedback`, s);
598
+ const r = { type: d };
599
+ d === "dislike" && ((t == null ? void 0 : t.reason) != null && (r.reason = t.reason), t != null && t.remark && (r.remark = t.remark)), await e.post(`/chat/messages/${n}/feedback`, r);
573
600
  },
574
601
  cancelFeedback: async (n) => {
575
602
  await e.del(`/chat/messages/${n}/feedback`);