super-agent-sdk 1.0.19 → 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
18
  this.refreshing = null, this.tokenPromise = 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;
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,7 +32,7 @@ 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
36
  *
37
37
  * 已持 token 直接返回缓存;并发调用凭 in-flight promise 合并为一次请求
38
38
  * (多 widget 共享同一 sdk 时,各自 ChatProvider 挂载只打一次签发端点)。
@@ -42,18 +42,22 @@ class $ {
42
42
  if (this.token) return this.token;
43
43
  if (this.tokenPromise) return this.tokenPromise;
44
44
  this.tokenPromise = (async () => {
45
- const i = `${this.isAbsoluteGateway ? this.tokenGateway : `${this.getOrigin()}${this.tokenGateway}`}/v2/token/generate`, n = await fetch(i, {
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, {
46
50
  method: "POST",
47
- headers: { "Content-Type": "application/json" },
48
- body: JSON.stringify({ botId: this.botId })
51
+ headers: n,
52
+ body: JSON.stringify({ botCode: this.botCode })
49
53
  });
50
- if (!n.ok)
51
- throw new Error(`HTTP ${n.status}: ${n.statusText}`);
52
- const d = await n.json();
53
- if (d.code !== "200")
54
- throw new Error(d.message || `API error: ${d.code}`);
55
- const t = f(d.data);
56
- return this.token = t.token, t.appId && !this.appId && (this.appId = t.appId), t.token;
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;
57
61
  })();
58
62
  try {
59
63
  return await this.tokenPromise;
@@ -109,10 +113,10 @@ class $ {
109
113
  }
110
114
  throw new Error(o);
111
115
  }
112
- const s = await t.json();
113
- if (s.code !== "200")
114
- throw new Error(s.message || `API error: ${s.code}`);
115
- 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);
116
120
  }
117
121
  get(e, i) {
118
122
  return this.request("GET", e, { params: i });
@@ -137,18 +141,18 @@ class $ {
137
141
  signal: n
138
142
  });
139
143
  if (t.status === 401) {
140
- const s = await b(t.clone());
141
- if (s.isCookieExpired && typeof (i == null ? void 0 : i.message) == "string") {
142
- S({
143
- 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,
144
148
  message: i.message,
145
149
  sessionId: i.sessionId ?? ""
146
150
  });
147
- const a = s.loginUrl ?? this.loginUrl;
151
+ const a = r.loginUrl ?? this.loginUrl;
148
152
  return this.onAuthExpired ? this.onAuthExpired({
149
153
  loginUrl: a,
150
- sessionId: s.sessionId,
151
- botId: this.botId
154
+ sessionId: r.sessionId,
155
+ botCode: this.botCode
152
156
  }) : a && window.location.replace(a), t;
153
157
  }
154
158
  if (await this.handleTokenRefresh())
@@ -162,18 +166,18 @@ class $ {
162
166
  return t;
163
167
  }
164
168
  }
165
- function u(r) {
166
- 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) => {
167
171
  if (typeof e == "string") return e;
168
172
  if (e && typeof e == "object") {
169
173
  if (typeof e.text == "string") return e.text;
170
174
  if (e.type) return `[${e.type}${e.mime_type ? ": " + e.mime_type : ""}]`;
171
175
  }
172
176
  return "";
173
- }).join("") : r == null ? "" : String(r);
177
+ }).join("") : s == null ? "" : String(s);
174
178
  }
175
- function w(r) {
176
- const e = r.split(`
179
+ function w(s) {
180
+ const e = s.split(`
177
181
  `).map((o) => o.trim()).filter((o) => o.length > 0);
178
182
  let i, n, d;
179
183
  for (const o of e)
@@ -193,7 +197,7 @@ ${a}` : a;
193
197
  } catch {
194
198
  return null;
195
199
  }
196
- 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;
197
201
  switch (t.type) {
198
202
  case "session.start":
199
203
  return {
@@ -229,17 +233,17 @@ ${a}` : a;
229
233
  id: i
230
234
  };
231
235
  case "tool_result": {
232
- const o = s == null ? void 0 : s.result;
236
+ const o = r == null ? void 0 : r.result;
233
237
  let a;
234
- 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 ?? ""), {
235
239
  type: "tool_result",
236
240
  content: a,
237
241
  toolName: t.name,
238
242
  toolCallId: t.id,
239
243
  artifacts: Array.isArray(t.artifacts) ? t.artifacts : void 0,
240
- renderMode: (s == null ? void 0 : s.render_mode) ?? t.render_mode ?? t.renderMode,
241
- html: (s == null ? void 0 : s.html) ?? t.html,
242
- 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,
243
247
  event: n,
244
248
  id: i
245
249
  };
@@ -290,18 +294,18 @@ ${a}` : a;
290
294
  return null;
291
295
  }
292
296
  }
293
- async function T(r, e, i) {
294
- if (!r.body) {
297
+ async function T(s, e, i) {
298
+ if (!s.body) {
295
299
  i(new Error("Response body is null"));
296
300
  return;
297
301
  }
298
- const n = r.body.getReader(), d = new TextDecoder();
302
+ const n = s.body.getReader(), d = new TextDecoder();
299
303
  let t = "";
300
304
  try {
301
305
  for (; ; ) {
302
- const { value: s, done: o } = await n.read();
306
+ const { value: r, done: o } = await n.read();
303
307
  if (o) break;
304
- t += d.decode(s, { stream: !0 });
308
+ t += d.decode(r, { stream: !0 });
305
309
  let a;
306
310
  for (; (a = t.indexOf(`
307
311
 
@@ -313,11 +317,11 @@ async function T(r, e, i) {
313
317
  }
314
318
  }
315
319
  if (t.trim()) {
316
- const s = w(t);
317
- s && e(s);
320
+ const r = w(t);
321
+ r && e(r);
318
322
  }
319
- } catch (s) {
320
- (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)));
321
325
  } finally {
322
326
  try {
323
327
  n.releaseLock();
@@ -325,24 +329,24 @@ async function T(r, e, i) {
325
329
  }
326
330
  }
327
331
  }
328
- function _(r, e) {
332
+ function $(s, e) {
329
333
  var t;
330
- const i = new AbortController(), n = e.signal ? P(e.signal, i.signal) : i.signal, d = {
331
- botId: r.getBotId(),
334
+ const i = new AbortController(), n = e.signal ? _(e.signal, i.signal) : i.signal, d = {
335
+ botCode: s.getBotCode(),
332
336
  message: e.message,
333
337
  sessionId: e.sessionId,
334
338
  stream: e.stream !== !1,
335
339
  // url 仅前端回显(下载/预览),剥离后发送——签名 URL 不进后端
336
340
  ...(t = e.attachments) != null && t.length ? {
337
- attachments: e.attachments.map(({ url: s, ...o }) => o)
341
+ attachments: e.attachments.map(({ url: r, ...o }) => o)
338
342
  } : {}
339
343
  };
340
- return d.stream ? r.streamPost("/chat", d, n).then(async (s) => {
344
+ return d.stream ? s.streamPost("/chat", d, n).then(async (r) => {
341
345
  var o;
342
- if (!s.ok) {
343
- let a = `HTTP ${s.status}`;
346
+ if (!r.ok) {
347
+ let a = `HTTP ${r.status}`;
344
348
  try {
345
- const c = await s.json();
349
+ const c = await r.json();
346
350
  c != null && c.message && (a = c.message);
347
351
  } catch {
348
352
  }
@@ -350,7 +354,7 @@ function _(r, e) {
350
354
  return;
351
355
  }
352
356
  return T(
353
- s,
357
+ r,
354
358
  (a) => {
355
359
  var c, l, h, g, m, y, I, p;
356
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);
@@ -360,104 +364,105 @@ function _(r, e) {
360
364
  return (c = e.onError) == null ? void 0 : c.call(e, a);
361
365
  }
362
366
  );
363
- }).catch((s) => {
367
+ }).catch((r) => {
364
368
  var o;
365
- (s == null ? void 0 : s.name) !== "AbortError" && ((o = e.onError) == null || o.call(e, s instanceof Error ? s : new Error(String(s))));
366
- }) : 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) => {
367
371
  var o;
368
372
  (o = e.onDone) == null || o.call(e, {
369
- sessionId: s.sessionId,
370
- content: s.content ?? "",
371
- messageId: s.messageId
373
+ sessionId: r.sessionId,
374
+ content: r.content ?? "",
375
+ messageId: r.messageId
372
376
  });
373
- }).catch((s) => {
377
+ }).catch((r) => {
374
378
  var o;
375
- (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)));
376
380
  }), i;
377
381
  }
378
- function P(r, e) {
382
+ function _(s, e) {
379
383
  const i = new AbortController(), n = () => i.abort();
380
- 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;
381
385
  }
382
- async function x(r) {
383
- return (await r.post("/chat/sessions", {
384
- botId: r.getBotId()
386
+ async function P(s) {
387
+ return (await s.post("/chat/sessions", {
388
+ botCode: s.getBotCode()
385
389
  })).sessionId;
386
390
  }
387
- function E(r) {
391
+ function x(s) {
388
392
  return {
389
393
  // 后端返回 thread_id,toCamelCase 转为 threadId,映射为 sessionId
390
- sessionId: r.threadId ?? r.sessionId,
391
- botId: r.botId,
392
- title: r.title,
393
- createTime: r.createTime,
394
- 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
395
400
  };
396
401
  }
397
- async function v(r, e) {
398
- const i = await r.get("/chat/conversations", {
399
- botId: r.getBotId(),
402
+ async function E(s, e) {
403
+ const i = await s.get("/chat/conversations", {
404
+ botCode: s.getBotCode(),
400
405
  page: (e == null ? void 0 : e.page) ?? 1,
401
406
  size: (e == null ? void 0 : e.size) ?? 20
402
407
  });
403
408
  return {
404
409
  ...i,
405
- items: i.items.map(E)
410
+ items: i.items.map(x)
406
411
  };
407
412
  }
408
- async function C(r, e, i) {
409
- await r.patch(`/chat/conversations/${e}`, { title: i });
413
+ async function v(s, e, i) {
414
+ await s.patch(`/chat/conversations/${e}`, { title: i });
410
415
  }
411
- async function O(r, e) {
412
- await r.del(`/chat/conversations/${e}`);
416
+ async function O(s, e) {
417
+ await s.del(`/chat/conversations/${e}`);
413
418
  }
414
- async function U(r, e) {
415
- 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`);
416
421
  return N(i);
417
422
  }
418
423
  function k() {
419
424
  return `r_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
420
425
  }
421
- function N(r) {
426
+ function N(s) {
422
427
  var d;
423
- 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 = [];
424
429
  if (e)
425
- for (const t of r)
430
+ for (const t of s)
426
431
  i.push({
427
432
  roundId: t.roundId ?? k(),
428
433
  artifacts: Array.isArray(t.artifacts) && t.artifacts.length ? t.artifacts : void 0,
429
434
  items: Array.isArray(t.data) ? t.data : []
430
435
  });
431
436
  else
432
- i.push({ roundId: k(), items: r });
437
+ i.push({ roundId: k(), items: s });
433
438
  const n = [];
434
439
  for (const t of i) {
435
- const s = D(t.items);
436
- 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;
437
442
  if (t.artifacts) {
438
- const o = s.findLast((a) => a.role === "assistant");
443
+ const o = r.findLast((a) => a.role === "assistant");
439
444
  o && (o.artifacts = t.artifacts);
440
445
  }
441
- n.push(...s);
446
+ n.push(...r);
442
447
  }
443
448
  return n;
444
449
  }
445
- function D(r) {
446
- const e = [...r].sort((s, o) => {
447
- const a = new Date(s.createTime ?? 0).getTime() || 0, c = new Date(o.createTime ?? 0).getTime() || 0;
448
- 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);
449
454
  }), i = /* @__PURE__ */ new Map();
450
- for (const s of e)
451
- s.role === "tool" && s.toolCallId && i.set(s.toolCallId, s.content || "");
452
- 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) => {
453
458
  const c = d[d.length - 1];
454
- (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 });
455
460
  };
456
- for (const s of e) {
457
- if (s.role === "system") continue;
458
- const o = String(s.id ?? s.messageId ?? `msg_${Date.now()}`), a = new Date(s.createTime ?? "").getTime() || Date.now();
459
- if (s.role === "human") {
460
- 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) => ({
461
466
  type: "attachment",
462
467
  attachment: {
463
468
  nosKey: l.nosKey ?? l.attachmentId ?? "",
@@ -472,36 +477,36 @@ function D(r) {
472
477
  d.push({
473
478
  id: o,
474
479
  role: "user",
475
- parts: [...c, { type: "text", content: u(s.content) }],
480
+ parts: [...c, { type: "text", content: u(r.content) }],
476
481
  timestamp: a
477
482
  });
478
483
  continue;
479
484
  }
480
- if (s.role === "ai") {
481
- const c = M(s, i, n);
485
+ if (r.role === "ai") {
486
+ const c = M(r, i, n);
482
487
  c.length > 0 && t(c, o, a);
483
488
  continue;
484
489
  }
485
- if (s.role === "tool") {
486
- if (s.toolCallId && n.has(s.toolCallId)) continue;
487
- 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);
488
493
  }
489
494
  }
490
495
  return d;
491
496
  }
492
- function M(r, e, i) {
497
+ function M(s, e, i) {
493
498
  const n = [];
494
- r.reasoning && n.push({ type: "thinking", content: r.reasoning }), r.content && n.push({ type: "text", content: u(r.content) });
495
- 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 ?? [])
496
501
  d.is_interrupt ?? d.isInterrupt ? (i.add(d.id), n.push(q(d, e))) : n.push(J(d));
497
502
  return n;
498
503
  }
499
- function q(r, e) {
500
- 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 : {};
501
506
  return {
502
507
  type: "interrupt",
503
508
  interrupt: {
504
- interruptId: r.id ?? "",
509
+ interruptId: s.id ?? "",
505
510
  interruptType: n.interruptType ?? "input",
506
511
  content: n.content ?? "",
507
512
  options: n.options,
@@ -513,50 +518,50 @@ function q(r, e) {
513
518
  metadata: n.metadata
514
519
  },
515
520
  resolved: i,
516
- 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
517
522
  };
518
523
  }
519
- function J(r) {
524
+ function J(s) {
520
525
  let e;
521
526
  try {
522
- e = typeof r.args == "string" ? r.args : JSON.stringify(r.args ?? {});
527
+ e = typeof s.args == "string" ? s.args : JSON.stringify(s.args ?? {});
523
528
  } catch {
524
- e = String(r.args ?? "{}");
529
+ e = String(s.args ?? "{}");
525
530
  }
526
- 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 };
527
532
  }
528
- function L(r) {
533
+ function L(s) {
529
534
  var i, n, d, t;
530
- const e = Array.isArray(r.artifacts) ? r.artifacts : void 0;
535
+ const e = Array.isArray(s.artifacts) ? s.artifacts : void 0;
531
536
  return {
532
537
  type: "tool_result",
533
- toolName: r.toolName ?? "",
534
- toolCallId: r.toolCallId ?? "",
538
+ toolName: s.toolName ?? "",
539
+ toolCallId: s.toolCallId ?? "",
535
540
  // tool 行后端 content 即展示摘要(_build_tool_fields 与 SSE 口径一致),直接读 content
536
- content: u(r.content),
541
+ content: u(s.content),
537
542
  artifacts: e,
538
- renderMode: r.renderMode ?? ((i = r.metadata) == null ? void 0 : i.renderMode) ?? ((n = r.metadata) == null ? void 0 : n.render_mode),
539
- html: r.html ?? ((d = r.metadata) == null ? void 0 : d.html),
540
- 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)
541
546
  };
542
547
  }
543
- function j(r) {
544
- if (r != null)
548
+ function j(s) {
549
+ if (s != null)
545
550
  try {
546
- return JSON.parse(r);
551
+ return JSON.parse(s);
547
552
  } catch {
548
- return r;
553
+ return s;
549
554
  }
550
555
  }
551
- async function G(r, e, i, n, d, t, s) {
552
- const o = await r.streamPost(
556
+ async function G(s, e, i, n, d, t, r) {
557
+ const o = await s.streamPost(
553
558
  `/chat/interrupt/${e}/respond`,
554
559
  {
555
560
  sessionId: i,
556
561
  action: n.action,
557
562
  value: n.value
558
563
  },
559
- s
564
+ r
560
565
  );
561
566
  if (!o.ok) {
562
567
  const a = new Error(`HTTP ${o.status}`);
@@ -570,28 +575,28 @@ async function G(r, e, i, n, d, t, s) {
570
575
  (a) => t == null ? void 0 : t(a)
571
576
  );
572
577
  }
573
- async function R(r) {
574
- return r.get(`/chat/bots/${r.getBotId()}/skills`);
578
+ async function R(s) {
579
+ return s.get(`/chat/bots/${s.getBotCode()}/skills`);
575
580
  }
576
- async function B(r, e) {
577
- await r.post("/chat/stop", { sessionId: e });
581
+ async function B(s, e) {
582
+ await s.post("/chat/stop", { sessionId: e });
578
583
  }
579
- function z(r) {
580
- const e = new $(r);
584
+ function z(s) {
585
+ const e = new A(s);
581
586
  return {
582
- botId: e.getBotId(),
587
+ botCode: e.getBotCode(),
583
588
  getToken: () => e.fetchToken(),
584
- createSession: () => x(e),
585
- chat: (n) => _(e, n),
586
- listConversations: (n) => v(e, n),
587
- renameConversation: (n, d) => C(e, n, d),
589
+ createSession: () => P(e),
590
+ chat: (n) => $(e, n),
591
+ listConversations: (n) => E(e, n),
592
+ renameConversation: (n, d) => v(e, n, d),
588
593
  deleteConversation: (n) => O(e, n),
589
594
  getMessages: (n) => U(e, n),
590
- 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),
591
596
  setToken: (n) => e.setToken(n),
592
597
  feedback: async (n, d, t) => {
593
- const s = { type: d };
594
- 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);
595
600
  },
596
601
  cancelFeedback: async (n) => {
597
602
  await e.del(`/chat/messages/${n}/feedback`);