super-agent-sdk 1.0.19 → 1.0.21
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 +41 -26
- package/dist/index.cjs +3 -3
- package/dist/index.d.ts +7 -6
- package/dist/index.mjs +166 -161
- package/dist/{mammoth.browser-ClkRBm1A.cjs → mammoth.browser-BWTaSUmQ.cjs} +63 -63
- package/dist/{mammoth.browser-BmR8YfeV.js → mammoth.browser-DFPCY35d.js} +3725 -3708
- package/dist/{nosUploader-CgVOa1Lz.cjs → nosUploader-DLX7JsnR.cjs} +5 -5
- package/dist/{nosUploader-CnYDALPr.js → nosUploader-DjJ7u2B1.js} +137 -137
- package/dist/purify.es-BnmCBz16.cjs +3 -0
- package/dist/{purify.es-C-6FFqDW.js → purify.es-CImoWRjX.js} +214 -205
- package/dist/widget.cjs +47 -21
- package/dist/widget.d.ts +49 -10
- package/dist/widget.mjs +3457 -3329
- package/package.json +1 -1
- package/dist/purify.es-Dsdnkgrg.cjs +0 -3
package/dist/index.mjs
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import { p as b, s as
|
|
2
|
-
import { c as W } from "./nosUploader-
|
|
3
|
-
function f(
|
|
4
|
-
if (Array.isArray(
|
|
5
|
-
if (
|
|
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(
|
|
8
|
-
const d = i.replace(/_([a-z])/g, (t,
|
|
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
|
|
13
|
+
return s;
|
|
14
14
|
}
|
|
15
|
-
const
|
|
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 ??
|
|
20
|
-
this.baseUrl = i.replace(/\/$/, ""), this.tokenGateway = e.tokenGateway.replace(/\/$/, ""), this.appId = e.appId ?? "", this.token = e.token ?? "", this.
|
|
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
|
-
|
|
23
|
-
return this.
|
|
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 =
|
|
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:
|
|
48
|
-
body: JSON.stringify({
|
|
51
|
+
headers: n,
|
|
52
|
+
body: JSON.stringify({ botCode: this.botCode })
|
|
49
53
|
});
|
|
50
|
-
if (!
|
|
51
|
-
throw new Error(`HTTP ${
|
|
52
|
-
const
|
|
53
|
-
if (
|
|
54
|
-
throw new Error(
|
|
55
|
-
const
|
|
56
|
-
return this.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
|
|
113
|
-
if (
|
|
114
|
-
throw new Error(
|
|
115
|
-
return f(
|
|
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
|
|
141
|
-
if (
|
|
142
|
-
|
|
143
|
-
|
|
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 =
|
|
151
|
+
const a = r.loginUrl ?? this.loginUrl;
|
|
148
152
|
return this.onAuthExpired ? this.onAuthExpired({
|
|
149
153
|
loginUrl: a,
|
|
150
|
-
sessionId:
|
|
151
|
-
|
|
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(
|
|
166
|
-
return typeof
|
|
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("") :
|
|
177
|
+
}).join("") : s == null ? "" : String(s);
|
|
174
178
|
}
|
|
175
|
-
function w(
|
|
176
|
-
const e =
|
|
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
|
|
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 =
|
|
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) :
|
|
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: (
|
|
241
|
-
html: (
|
|
242
|
-
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(
|
|
294
|
-
if (!
|
|
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 =
|
|
302
|
+
const n = s.body.getReader(), d = new TextDecoder();
|
|
299
303
|
let t = "";
|
|
300
304
|
try {
|
|
301
305
|
for (; ; ) {
|
|
302
|
-
const { value:
|
|
306
|
+
const { value: r, done: o } = await n.read();
|
|
303
307
|
if (o) break;
|
|
304
|
-
t += d.decode(
|
|
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
|
|
317
|
-
|
|
320
|
+
const r = w(t);
|
|
321
|
+
r && e(r);
|
|
318
322
|
}
|
|
319
|
-
} catch (
|
|
320
|
-
(
|
|
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
|
|
332
|
+
function $(s, e) {
|
|
329
333
|
var t;
|
|
330
|
-
const i = new AbortController(), n = e.signal ?
|
|
331
|
-
|
|
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:
|
|
341
|
+
attachments: e.attachments.map(({ url: r, ...o }) => o)
|
|
338
342
|
} : {}
|
|
339
343
|
};
|
|
340
|
-
return d.stream ?
|
|
344
|
+
return d.stream ? s.streamPost("/chat", d, n).then(async (r) => {
|
|
341
345
|
var o;
|
|
342
|
-
if (!
|
|
343
|
-
let a = `HTTP ${
|
|
346
|
+
if (!r.ok) {
|
|
347
|
+
let a = `HTTP ${r.status}`;
|
|
344
348
|
try {
|
|
345
|
-
const c = await
|
|
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
|
-
|
|
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((
|
|
367
|
+
}).catch((r) => {
|
|
364
368
|
var o;
|
|
365
|
-
(
|
|
366
|
-
}) :
|
|
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:
|
|
370
|
-
content:
|
|
371
|
-
messageId:
|
|
373
|
+
sessionId: r.sessionId,
|
|
374
|
+
content: r.content ?? "",
|
|
375
|
+
messageId: r.messageId
|
|
372
376
|
});
|
|
373
|
-
}).catch((
|
|
377
|
+
}).catch((r) => {
|
|
374
378
|
var o;
|
|
375
|
-
(o = e.onError) == null || o.call(e,
|
|
379
|
+
(o = e.onError) == null || o.call(e, r instanceof Error ? r : new Error(String(r)));
|
|
376
380
|
}), i;
|
|
377
381
|
}
|
|
378
|
-
function
|
|
382
|
+
function _(s, e) {
|
|
379
383
|
const i = new AbortController(), n = () => i.abort();
|
|
380
|
-
return
|
|
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
|
|
383
|
-
return (await
|
|
384
|
-
|
|
386
|
+
async function P(s) {
|
|
387
|
+
return (await s.post("/chat/sessions", {
|
|
388
|
+
botCode: s.getBotCode()
|
|
385
389
|
})).sessionId;
|
|
386
390
|
}
|
|
387
|
-
function
|
|
391
|
+
function x(s) {
|
|
388
392
|
return {
|
|
389
393
|
// 后端返回 thread_id,toCamelCase 转为 threadId,映射为 sessionId
|
|
390
|
-
sessionId:
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
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
|
|
398
|
-
const i = await
|
|
399
|
-
|
|
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(
|
|
410
|
+
items: i.items.map(x)
|
|
406
411
|
};
|
|
407
412
|
}
|
|
408
|
-
async function
|
|
409
|
-
await
|
|
413
|
+
async function v(s, e, i) {
|
|
414
|
+
await s.patch(`/chat/conversations/${e}`, { title: i });
|
|
410
415
|
}
|
|
411
|
-
async function O(
|
|
412
|
-
await
|
|
416
|
+
async function O(s, e) {
|
|
417
|
+
await s.del(`/chat/conversations/${e}`);
|
|
413
418
|
}
|
|
414
|
-
async function U(
|
|
415
|
-
const i = await
|
|
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(
|
|
426
|
+
function N(s) {
|
|
422
427
|
var d;
|
|
423
|
-
const e =
|
|
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
|
|
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:
|
|
437
|
+
i.push({ roundId: k(), items: s });
|
|
433
438
|
const n = [];
|
|
434
439
|
for (const t of i) {
|
|
435
|
-
const
|
|
436
|
-
for (const o of
|
|
440
|
+
const r = D(t.items);
|
|
441
|
+
for (const o of r) o.roundId = t.roundId;
|
|
437
442
|
if (t.artifacts) {
|
|
438
|
-
const o =
|
|
443
|
+
const o = r.findLast((a) => a.role === "assistant");
|
|
439
444
|
o && (o.artifacts = t.artifacts);
|
|
440
445
|
}
|
|
441
|
-
n.push(...
|
|
446
|
+
n.push(...r);
|
|
442
447
|
}
|
|
443
448
|
return n;
|
|
444
449
|
}
|
|
445
|
-
function D(
|
|
446
|
-
const e = [...
|
|
447
|
-
const a = new Date(
|
|
448
|
-
return a !== c ? a - c : (
|
|
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
|
|
451
|
-
|
|
452
|
-
const n = /* @__PURE__ */ new Set(), d = [], t = (
|
|
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(...
|
|
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
|
|
457
|
-
if (
|
|
458
|
-
const o = String(
|
|
459
|
-
if (
|
|
460
|
-
const c = (
|
|
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(
|
|
480
|
+
parts: [...c, { type: "text", content: u(r.content) }],
|
|
476
481
|
timestamp: a
|
|
477
482
|
});
|
|
478
483
|
continue;
|
|
479
484
|
}
|
|
480
|
-
if (
|
|
481
|
-
const c = M(
|
|
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 (
|
|
486
|
-
if (
|
|
487
|
-
t([L(
|
|
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(
|
|
497
|
+
function M(s, e, i) {
|
|
493
498
|
const n = [];
|
|
494
|
-
|
|
495
|
-
for (const d of
|
|
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(
|
|
500
|
-
const i = e.has(
|
|
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:
|
|
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(
|
|
521
|
+
response: i ? { action: "submit", value: j(e.get(s.id)) } : void 0
|
|
517
522
|
};
|
|
518
523
|
}
|
|
519
|
-
function J(
|
|
524
|
+
function J(s) {
|
|
520
525
|
let e;
|
|
521
526
|
try {
|
|
522
|
-
e = typeof
|
|
527
|
+
e = typeof s.args == "string" ? s.args : JSON.stringify(s.args ?? {});
|
|
523
528
|
} catch {
|
|
524
|
-
e = String(
|
|
529
|
+
e = String(s.args ?? "{}");
|
|
525
530
|
}
|
|
526
|
-
return { type: "tool_call", toolName:
|
|
531
|
+
return { type: "tool_call", toolName: s.name ?? "", toolCallId: s.id ?? "", args: e };
|
|
527
532
|
}
|
|
528
|
-
function L(
|
|
533
|
+
function L(s) {
|
|
529
534
|
var i, n, d, t;
|
|
530
|
-
const e = Array.isArray(
|
|
535
|
+
const e = Array.isArray(s.artifacts) ? s.artifacts : void 0;
|
|
531
536
|
return {
|
|
532
537
|
type: "tool_result",
|
|
533
|
-
toolName:
|
|
534
|
-
toolCallId:
|
|
538
|
+
toolName: s.toolName ?? "",
|
|
539
|
+
toolCallId: s.toolCallId ?? "",
|
|
535
540
|
// tool 行后端 content 即展示摘要(_build_tool_fields 与 SSE 口径一致),直接读 content
|
|
536
|
-
content: u(
|
|
541
|
+
content: u(s.content),
|
|
537
542
|
artifacts: e,
|
|
538
|
-
renderMode:
|
|
539
|
-
html:
|
|
540
|
-
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(
|
|
544
|
-
if (
|
|
548
|
+
function j(s) {
|
|
549
|
+
if (s != null)
|
|
545
550
|
try {
|
|
546
|
-
return JSON.parse(
|
|
551
|
+
return JSON.parse(s);
|
|
547
552
|
} catch {
|
|
548
|
-
return
|
|
553
|
+
return s;
|
|
549
554
|
}
|
|
550
555
|
}
|
|
551
|
-
async function G(
|
|
552
|
-
const o = await
|
|
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
|
-
|
|
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(
|
|
574
|
-
return
|
|
578
|
+
async function R(s) {
|
|
579
|
+
return s.get(`/chat/bots/${s.getBotCode()}/skills`);
|
|
575
580
|
}
|
|
576
|
-
async function B(
|
|
577
|
-
await
|
|
581
|
+
async function B(s, e) {
|
|
582
|
+
await s.post("/chat/stop", { sessionId: e });
|
|
578
583
|
}
|
|
579
|
-
function z(
|
|
580
|
-
const e = new
|
|
584
|
+
function z(s) {
|
|
585
|
+
const e = new A(s);
|
|
581
586
|
return {
|
|
582
|
-
|
|
587
|
+
botCode: e.getBotCode(),
|
|
583
588
|
getToken: () => e.fetchToken(),
|
|
584
|
-
createSession: () =>
|
|
585
|
-
chat: (n) =>
|
|
586
|
-
listConversations: (n) =>
|
|
587
|
-
renameConversation: (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,
|
|
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
|
|
594
|
-
d === "dislike" && ((t == null ? void 0 : t.reason) != null && (
|
|
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`);
|