super-agent-sdk 1.0.15 → 1.0.17
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 +20 -5
- package/dist/index.cjs +4 -4
- package/dist/index.d.ts +16 -1
- package/dist/index.mjs +275 -179
- package/dist/{mammoth.browser-CmEXxaIp.js → mammoth.browser-BmR8YfeV.js} +1 -1
- package/dist/{mammoth.browser-BX8glWVC.cjs → mammoth.browser-ClkRBm1A.cjs} +1 -1
- package/dist/{nosUploader-KkzFK5EW.cjs → nosUploader-CgVOa1Lz.cjs} +5 -5
- package/dist/{nosUploader-BkBtdrMs.js → nosUploader-CnYDALPr.js} +732 -699
- package/dist/widget.cjs +31 -31
- package/dist/widget.d.ts +13 -3
- package/dist/widget.mjs +2844 -2762
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
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));
|
|
4
5
|
if (r && typeof r == "object" && r.constructor === Object) {
|
|
5
6
|
const e = {};
|
|
6
|
-
for (const [
|
|
7
|
-
const
|
|
8
|
-
e[
|
|
7
|
+
for (const [i, n] of Object.entries(r)) {
|
|
8
|
+
const d = i.replace(/_([a-z])/g, (t, s) => s.toUpperCase());
|
|
9
|
+
e[d] = f(n);
|
|
9
10
|
}
|
|
10
11
|
return e;
|
|
11
12
|
}
|
|
12
13
|
return r;
|
|
13
14
|
}
|
|
14
|
-
const
|
|
15
|
-
class
|
|
15
|
+
const A = "/api/agent/runtime/v1";
|
|
16
|
+
class $ {
|
|
16
17
|
constructor(e) {
|
|
17
18
|
this.refreshing = null;
|
|
18
|
-
const
|
|
19
|
-
this.baseUrl =
|
|
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;
|
|
20
21
|
}
|
|
21
22
|
getBotId() {
|
|
22
23
|
return this.botId;
|
|
@@ -33,18 +34,18 @@ class T {
|
|
|
33
34
|
}
|
|
34
35
|
/** POST {origin}{tokenGateway}/v1/token — 获取 token + appId */
|
|
35
36
|
async fetchToken() {
|
|
36
|
-
const
|
|
37
|
+
const i = `${this.isAbsoluteGateway ? this.tokenGateway : `${this.getOrigin()}${this.tokenGateway}`}/v1/token`, n = await fetch(i, {
|
|
37
38
|
method: "POST",
|
|
38
39
|
headers: { "Content-Type": "application/json" },
|
|
39
40
|
body: JSON.stringify({ botId: this.botId })
|
|
40
41
|
});
|
|
41
42
|
if (!n.ok)
|
|
42
43
|
throw new Error(`HTTP ${n.status}: ${n.statusText}`);
|
|
43
|
-
const
|
|
44
|
-
if (
|
|
45
|
-
throw new Error(
|
|
46
|
-
const
|
|
47
|
-
return this.token =
|
|
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;
|
|
48
49
|
}
|
|
49
50
|
headers(e) {
|
|
50
51
|
return {
|
|
@@ -67,59 +68,84 @@ class T {
|
|
|
67
68
|
this.refreshing = null;
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
|
-
async request(e,
|
|
71
|
+
async request(e, i, n) {
|
|
71
72
|
if (!this.token && !await this.handleTokenRefresh())
|
|
72
73
|
throw new Error("SDK token not available: POST /token failed");
|
|
73
|
-
let
|
|
74
|
+
let d = this.isAbsoluteUrl ? `${this.baseUrl}${i}` : `${this.getOrigin()}${this.baseUrl}${i}`;
|
|
74
75
|
if (n != null && n.params) {
|
|
75
|
-
const
|
|
76
|
-
for (const [
|
|
77
|
-
l != null &&
|
|
78
|
-
const
|
|
79
|
-
|
|
76
|
+
const o = new URLSearchParams();
|
|
77
|
+
for (const [c, l] of Object.entries(n.params))
|
|
78
|
+
l != null && o.set(c, String(l));
|
|
79
|
+
const a = o.toString();
|
|
80
|
+
a && (d += `?${a}`);
|
|
80
81
|
}
|
|
81
|
-
const
|
|
82
|
+
const t = await fetch(d, {
|
|
82
83
|
method: e,
|
|
83
84
|
headers: this.headers(),
|
|
84
85
|
body: n != null && n.body ? JSON.stringify(n.body) : void 0
|
|
85
86
|
});
|
|
86
|
-
if (
|
|
87
|
-
return this.request(e,
|
|
88
|
-
if (!
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
if (t.status === 401 && !(n != null && n.retry) && await this.handleTokenRefresh())
|
|
88
|
+
return this.request(e, i, { ...n, retry: !0 });
|
|
89
|
+
if (!t.ok) {
|
|
90
|
+
let o = `HTTP ${t.status}: ${t.statusText}`;
|
|
91
|
+
try {
|
|
92
|
+
const a = await t.json();
|
|
93
|
+
a != null && a.message && (o = a.message);
|
|
94
|
+
} catch {
|
|
95
|
+
}
|
|
96
|
+
throw new Error(o);
|
|
97
|
+
}
|
|
98
|
+
const s = await t.json();
|
|
91
99
|
if (s.code !== "200")
|
|
92
100
|
throw new Error(s.message || `API error: ${s.code}`);
|
|
93
|
-
return
|
|
101
|
+
return f(s.data);
|
|
94
102
|
}
|
|
95
|
-
get(e,
|
|
96
|
-
return this.request("GET", e, { params:
|
|
103
|
+
get(e, i) {
|
|
104
|
+
return this.request("GET", e, { params: i });
|
|
97
105
|
}
|
|
98
|
-
post(e,
|
|
99
|
-
return this.request("POST", e, { body:
|
|
106
|
+
post(e, i) {
|
|
107
|
+
return this.request("POST", e, { body: i });
|
|
100
108
|
}
|
|
101
|
-
patch(e,
|
|
102
|
-
return this.request("PATCH", e, { body:
|
|
109
|
+
patch(e, i) {
|
|
110
|
+
return this.request("PATCH", e, { body: i });
|
|
103
111
|
}
|
|
104
112
|
del(e) {
|
|
105
113
|
return this.request("DELETE", e);
|
|
106
114
|
}
|
|
107
115
|
/** For SSE streaming — returns raw Response (no envelope unwrap) */
|
|
108
|
-
async streamPost(e,
|
|
116
|
+
async streamPost(e, i, n) {
|
|
109
117
|
if (!this.token && !await this.handleTokenRefresh())
|
|
110
118
|
throw new Error("SDK token not available: POST /token failed");
|
|
111
|
-
const
|
|
119
|
+
const d = this.isAbsoluteUrl ? `${this.baseUrl}${e}` : `${this.getOrigin()}${this.baseUrl}${e}`, t = await fetch(d, {
|
|
112
120
|
method: "POST",
|
|
113
121
|
headers: this.headers(),
|
|
114
|
-
body: JSON.stringify(
|
|
122
|
+
body: JSON.stringify(i),
|
|
115
123
|
signal: n
|
|
116
124
|
});
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
125
|
+
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,
|
|
130
|
+
message: i.message,
|
|
131
|
+
sessionId: i.sessionId ?? ""
|
|
132
|
+
});
|
|
133
|
+
const a = s.loginUrl ?? this.loginUrl;
|
|
134
|
+
return this.onAuthExpired ? this.onAuthExpired({
|
|
135
|
+
loginUrl: a,
|
|
136
|
+
sessionId: s.sessionId,
|
|
137
|
+
botId: this.botId
|
|
138
|
+
}) : a && window.location.replace(a), t;
|
|
139
|
+
}
|
|
140
|
+
if (await this.handleTokenRefresh())
|
|
141
|
+
return fetch(d, {
|
|
142
|
+
method: "POST",
|
|
143
|
+
headers: this.headers(),
|
|
144
|
+
body: JSON.stringify(i),
|
|
145
|
+
signal: n
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
return t;
|
|
123
149
|
}
|
|
124
150
|
}
|
|
125
151
|
function u(r) {
|
|
@@ -132,60 +158,93 @@ function u(r) {
|
|
|
132
158
|
return "";
|
|
133
159
|
}).join("") : r == null ? "" : String(r);
|
|
134
160
|
}
|
|
135
|
-
function
|
|
161
|
+
function w(r) {
|
|
136
162
|
const e = r.split(`
|
|
137
|
-
`).map((
|
|
138
|
-
|
|
163
|
+
`).map((o) => o.trim()).filter((o) => o.length > 0);
|
|
164
|
+
let i, n, d;
|
|
165
|
+
for (const o of e)
|
|
166
|
+
if (o.startsWith("id:"))
|
|
167
|
+
i = o.slice(3).trim();
|
|
168
|
+
else if (o.startsWith("event:"))
|
|
169
|
+
n = o.slice(6).trim();
|
|
170
|
+
else if (o.startsWith("data:")) {
|
|
171
|
+
const a = o.slice(5).trim();
|
|
172
|
+
d = d ? `${d}
|
|
173
|
+
${a}` : a;
|
|
174
|
+
}
|
|
175
|
+
if (d === void 0) return null;
|
|
139
176
|
let t;
|
|
140
177
|
try {
|
|
141
|
-
t = JSON.parse(
|
|
142
|
-
`));
|
|
178
|
+
t = JSON.parse(d);
|
|
143
179
|
} catch {
|
|
144
180
|
return null;
|
|
145
181
|
}
|
|
182
|
+
const s = t.type === "tool_result" && typeof t.content == "object" && t.content ? t.content : void 0;
|
|
146
183
|
switch (t.type) {
|
|
184
|
+
case "session.start":
|
|
185
|
+
return {
|
|
186
|
+
type: "session.start",
|
|
187
|
+
content: "",
|
|
188
|
+
sessionId: t.sessionId ?? t.session_id ?? "",
|
|
189
|
+
roundId: t.roundId ?? t.round_id,
|
|
190
|
+
event: n,
|
|
191
|
+
id: i
|
|
192
|
+
};
|
|
147
193
|
case "user":
|
|
148
|
-
return { type: "user", content: u(t.content) };
|
|
194
|
+
return { type: "user", content: u(t.content), event: n, id: i };
|
|
149
195
|
case "thinking":
|
|
150
|
-
return { type: "thinking", content: u(t.content) };
|
|
196
|
+
return { type: "thinking", content: u(t.content), event: n, id: i };
|
|
151
197
|
case "ai":
|
|
152
|
-
return { type: "ai", content: u(t.content) };
|
|
198
|
+
return { type: "ai", content: u(t.content), event: n, id: i };
|
|
153
199
|
case "tool_call":
|
|
154
200
|
return {
|
|
155
201
|
type: "tool_call",
|
|
156
202
|
content: t.name ?? "",
|
|
157
203
|
toolName: t.name,
|
|
158
204
|
toolCallId: t.id,
|
|
159
|
-
args: typeof t.args == "string" ? t.args : JSON.stringify(t.args ?? {})
|
|
205
|
+
args: typeof t.args == "string" ? t.args : JSON.stringify(t.args ?? {}),
|
|
206
|
+
event: n,
|
|
207
|
+
id: i
|
|
160
208
|
};
|
|
161
|
-
case "tool_result":
|
|
162
|
-
|
|
209
|
+
case "tool_result": {
|
|
210
|
+
const o = s == null ? void 0 : s.result;
|
|
211
|
+
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 ?? ""), {
|
|
163
213
|
type: "tool_result",
|
|
164
|
-
content:
|
|
214
|
+
content: a,
|
|
165
215
|
toolName: t.name,
|
|
166
216
|
toolCallId: t.id,
|
|
167
|
-
// 通用 artifacts(type + data),原样透传
|
|
168
217
|
artifacts: Array.isArray(t.artifacts) ? t.artifacts : void 0,
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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,
|
|
221
|
+
event: n,
|
|
222
|
+
id: i
|
|
172
223
|
};
|
|
224
|
+
}
|
|
173
225
|
case "done":
|
|
174
226
|
return {
|
|
175
227
|
type: "done",
|
|
176
228
|
content: u(t.content),
|
|
177
229
|
sessionId: t.sessionId ?? t.session_id ?? "",
|
|
178
|
-
messageId: t.messageId ?? t.message_id
|
|
230
|
+
messageId: t.messageId ?? t.message_id,
|
|
231
|
+
roundId: t.roundId ?? t.round_id,
|
|
232
|
+
artifacts: Array.isArray(t.artifacts) ? t.artifacts : void 0,
|
|
233
|
+
event: n,
|
|
234
|
+
id: i
|
|
179
235
|
};
|
|
180
236
|
case "stop":
|
|
181
237
|
return {
|
|
182
238
|
type: "stop",
|
|
183
239
|
content: u(t.content),
|
|
184
240
|
sessionId: t.sessionId ?? t.session_id ?? "",
|
|
185
|
-
messageId: t.messageId ?? t.message_id
|
|
241
|
+
messageId: t.messageId ?? t.message_id,
|
|
242
|
+
roundId: t.roundId ?? t.round_id,
|
|
243
|
+
event: n,
|
|
244
|
+
id: i
|
|
186
245
|
};
|
|
187
246
|
case "error":
|
|
188
|
-
return { type: "error", content: t.message ?? "Unknown error" };
|
|
247
|
+
return { type: "error", content: t.message ?? "Unknown error", event: n, id: i };
|
|
189
248
|
case "interrupt":
|
|
190
249
|
return {
|
|
191
250
|
type: "interrupt",
|
|
@@ -201,40 +260,42 @@ function I(r) {
|
|
|
201
260
|
required: t.required,
|
|
202
261
|
fields: t.fields,
|
|
203
262
|
metadata: t.metadata
|
|
204
|
-
}
|
|
263
|
+
},
|
|
264
|
+
event: n,
|
|
265
|
+
id: i
|
|
205
266
|
};
|
|
206
267
|
default:
|
|
207
268
|
return null;
|
|
208
269
|
}
|
|
209
270
|
}
|
|
210
|
-
async function
|
|
271
|
+
async function T(r, e, i) {
|
|
211
272
|
if (!r.body) {
|
|
212
|
-
|
|
273
|
+
i(new Error("Response body is null"));
|
|
213
274
|
return;
|
|
214
275
|
}
|
|
215
|
-
const n = r.body.getReader(),
|
|
216
|
-
let
|
|
276
|
+
const n = r.body.getReader(), d = new TextDecoder();
|
|
277
|
+
let t = "";
|
|
217
278
|
try {
|
|
218
279
|
for (; ; ) {
|
|
219
|
-
const { value: s, done:
|
|
220
|
-
if (
|
|
221
|
-
|
|
222
|
-
let
|
|
223
|
-
for (; (
|
|
280
|
+
const { value: s, done: o } = await n.read();
|
|
281
|
+
if (o) break;
|
|
282
|
+
t += d.decode(s, { stream: !0 });
|
|
283
|
+
let a;
|
|
284
|
+
for (; (a = t.indexOf(`
|
|
224
285
|
|
|
225
286
|
`)) !== -1; ) {
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
const l =
|
|
287
|
+
const c = t.slice(0, a);
|
|
288
|
+
t = t.slice(a + 2);
|
|
289
|
+
const l = w(c);
|
|
229
290
|
l && e(l);
|
|
230
291
|
}
|
|
231
292
|
}
|
|
232
|
-
if (
|
|
233
|
-
const s =
|
|
293
|
+
if (t.trim()) {
|
|
294
|
+
const s = w(t);
|
|
234
295
|
s && e(s);
|
|
235
296
|
}
|
|
236
297
|
} catch (s) {
|
|
237
|
-
(s == null ? void 0 : s.name) !== "AbortError" &&
|
|
298
|
+
(s == null ? void 0 : s.name) !== "AbortError" && i(s instanceof Error ? s : new Error(String(s)));
|
|
238
299
|
} finally {
|
|
239
300
|
try {
|
|
240
301
|
n.releaseLock();
|
|
@@ -242,60 +303,66 @@ async function p(r, e, t) {
|
|
|
242
303
|
}
|
|
243
304
|
}
|
|
244
305
|
}
|
|
245
|
-
function
|
|
246
|
-
var
|
|
247
|
-
const
|
|
306
|
+
function _(r, e) {
|
|
307
|
+
var t;
|
|
308
|
+
const i = new AbortController(), n = e.signal ? x(e.signal, i.signal) : i.signal, d = {
|
|
248
309
|
botId: r.getBotId(),
|
|
249
310
|
message: e.message,
|
|
250
311
|
sessionId: e.sessionId,
|
|
251
312
|
stream: e.stream !== !1,
|
|
252
313
|
// url 仅前端回显(下载/预览),剥离后发送——签名 URL 不进后端
|
|
253
|
-
...(
|
|
254
|
-
attachments: e.attachments.map(({ url: s, ...
|
|
314
|
+
...(t = e.attachments) != null && t.length ? {
|
|
315
|
+
attachments: e.attachments.map(({ url: s, ...o }) => o)
|
|
255
316
|
} : {}
|
|
256
317
|
};
|
|
257
|
-
return
|
|
258
|
-
var
|
|
318
|
+
return d.stream ? r.streamPost("/chat", d, n).then(async (s) => {
|
|
319
|
+
var o;
|
|
259
320
|
if (!s.ok) {
|
|
260
|
-
|
|
321
|
+
let a = `HTTP ${s.status}`;
|
|
322
|
+
try {
|
|
323
|
+
const c = await s.json();
|
|
324
|
+
c != null && c.message && (a = c.message);
|
|
325
|
+
} catch {
|
|
326
|
+
}
|
|
327
|
+
(o = e.onError) == null || o.call(e, new Error(a));
|
|
261
328
|
return;
|
|
262
329
|
}
|
|
263
|
-
return
|
|
330
|
+
return T(
|
|
264
331
|
s,
|
|
265
|
-
(
|
|
266
|
-
var
|
|
267
|
-
|
|
332
|
+
(a) => {
|
|
333
|
+
var c, l, h, g, m, y, I, p;
|
|
334
|
+
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);
|
|
268
335
|
},
|
|
269
|
-
(
|
|
270
|
-
var
|
|
271
|
-
return (
|
|
336
|
+
(a) => {
|
|
337
|
+
var c;
|
|
338
|
+
return (c = e.onError) == null ? void 0 : c.call(e, a);
|
|
272
339
|
}
|
|
273
340
|
);
|
|
274
341
|
}).catch((s) => {
|
|
275
|
-
var
|
|
276
|
-
(s == null ? void 0 : s.name) !== "AbortError" && ((
|
|
277
|
-
}) : r.post("/chat",
|
|
278
|
-
var
|
|
279
|
-
(
|
|
342
|
+
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) => {
|
|
345
|
+
var o;
|
|
346
|
+
(o = e.onDone) == null || o.call(e, {
|
|
280
347
|
sessionId: s.sessionId,
|
|
281
348
|
content: s.content ?? "",
|
|
282
349
|
messageId: s.messageId
|
|
283
350
|
});
|
|
284
351
|
}).catch((s) => {
|
|
285
|
-
var
|
|
286
|
-
(
|
|
287
|
-
}),
|
|
352
|
+
var o;
|
|
353
|
+
(o = e.onError) == null || o.call(e, s instanceof Error ? s : new Error(String(s)));
|
|
354
|
+
}), i;
|
|
288
355
|
}
|
|
289
|
-
function
|
|
290
|
-
const
|
|
291
|
-
return r.addEventListener("abort", n, { once: !0 }), e.addEventListener("abort", n, { once: !0 }), (r.aborted || e.aborted) &&
|
|
356
|
+
function x(r, e) {
|
|
357
|
+
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;
|
|
292
359
|
}
|
|
293
|
-
async function
|
|
360
|
+
async function E(r) {
|
|
294
361
|
return (await r.post("/chat/sessions", {
|
|
295
362
|
botId: r.getBotId()
|
|
296
363
|
})).sessionId;
|
|
297
364
|
}
|
|
298
|
-
function
|
|
365
|
+
function O(r) {
|
|
299
366
|
return {
|
|
300
367
|
// 后端返回 thread_id,toCamelCase 转为 threadId,映射为 sessionId
|
|
301
368
|
sessionId: r.threadId ?? r.sessionId,
|
|
@@ -305,43 +372,70 @@ function $(r) {
|
|
|
305
372
|
updateTime: r.updateTime
|
|
306
373
|
};
|
|
307
374
|
}
|
|
308
|
-
async function
|
|
309
|
-
const
|
|
375
|
+
async function v(r, e) {
|
|
376
|
+
const i = await r.get("/chat/conversations", {
|
|
310
377
|
botId: r.getBotId(),
|
|
311
378
|
page: (e == null ? void 0 : e.page) ?? 1,
|
|
312
379
|
size: (e == null ? void 0 : e.size) ?? 20
|
|
313
380
|
});
|
|
314
381
|
return {
|
|
315
|
-
...
|
|
316
|
-
items:
|
|
382
|
+
...i,
|
|
383
|
+
items: i.items.map(O)
|
|
317
384
|
};
|
|
318
385
|
}
|
|
319
|
-
async function C(r, e,
|
|
320
|
-
await r.patch(`/chat/conversations/${e}`, { title:
|
|
386
|
+
async function C(r, e, i) {
|
|
387
|
+
await r.patch(`/chat/conversations/${e}`, { title: i });
|
|
321
388
|
}
|
|
322
|
-
async function
|
|
389
|
+
async function P(r, e) {
|
|
323
390
|
await r.del(`/chat/conversations/${e}`);
|
|
324
391
|
}
|
|
325
|
-
async function
|
|
326
|
-
const
|
|
327
|
-
return
|
|
392
|
+
async function U(r, e) {
|
|
393
|
+
const i = await r.get(`/chat/conversations/${e}/messages`);
|
|
394
|
+
return N(i);
|
|
395
|
+
}
|
|
396
|
+
function k() {
|
|
397
|
+
return `r_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
|
|
398
|
+
}
|
|
399
|
+
function N(r) {
|
|
400
|
+
var d;
|
|
401
|
+
const e = r.length > 0 && Array.isArray((d = r[0]) == null ? void 0 : d.data), i = [];
|
|
402
|
+
if (e)
|
|
403
|
+
for (const t of r)
|
|
404
|
+
i.push({
|
|
405
|
+
roundId: t.roundId ?? k(),
|
|
406
|
+
artifacts: Array.isArray(t.artifacts) && t.artifacts.length ? t.artifacts : void 0,
|
|
407
|
+
items: Array.isArray(t.data) ? t.data : []
|
|
408
|
+
});
|
|
409
|
+
else
|
|
410
|
+
i.push({ roundId: k(), items: r });
|
|
411
|
+
const n = [];
|
|
412
|
+
for (const t of i) {
|
|
413
|
+
const s = D(t.items);
|
|
414
|
+
for (const o of s) o.roundId = t.roundId;
|
|
415
|
+
if (t.artifacts) {
|
|
416
|
+
const o = s.findLast((a) => a.role === "assistant");
|
|
417
|
+
o && (o.artifacts = t.artifacts);
|
|
418
|
+
}
|
|
419
|
+
n.push(...s);
|
|
420
|
+
}
|
|
421
|
+
return n;
|
|
328
422
|
}
|
|
329
|
-
function
|
|
330
|
-
const e = [...r].sort((s,
|
|
331
|
-
const
|
|
332
|
-
return
|
|
333
|
-
}),
|
|
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);
|
|
427
|
+
}), i = /* @__PURE__ */ new Map();
|
|
334
428
|
for (const s of e)
|
|
335
|
-
s.role === "tool" && s.toolCallId &&
|
|
336
|
-
const n = /* @__PURE__ */ new Set(),
|
|
337
|
-
const
|
|
338
|
-
(
|
|
429
|
+
s.role === "tool" && s.toolCallId && i.set(s.toolCallId, s.content || "");
|
|
430
|
+
const n = /* @__PURE__ */ new Set(), d = [], t = (s, o, a) => {
|
|
431
|
+
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 });
|
|
339
433
|
};
|
|
340
434
|
for (const s of e) {
|
|
341
435
|
if (s.role === "system") continue;
|
|
342
|
-
const
|
|
436
|
+
const o = String(s.id ?? s.messageId ?? `msg_${Date.now()}`), a = new Date(s.createTime ?? "").getTime() || Date.now();
|
|
343
437
|
if (s.role === "human") {
|
|
344
|
-
const
|
|
438
|
+
const c = (s.attachments ?? []).map((l) => ({
|
|
345
439
|
type: "attachment",
|
|
346
440
|
attachment: {
|
|
347
441
|
nosKey: l.nosKey ?? l.attachmentId ?? "",
|
|
@@ -353,35 +447,35 @@ function P(r) {
|
|
|
353
447
|
// 公开读桶下载链接(有则 chip 可点击下载)
|
|
354
448
|
}
|
|
355
449
|
}));
|
|
356
|
-
|
|
357
|
-
id:
|
|
450
|
+
d.push({
|
|
451
|
+
id: o,
|
|
358
452
|
role: "user",
|
|
359
|
-
parts: [...
|
|
360
|
-
timestamp:
|
|
453
|
+
parts: [...c, { type: "text", content: u(s.content) }],
|
|
454
|
+
timestamp: a
|
|
361
455
|
});
|
|
362
456
|
continue;
|
|
363
457
|
}
|
|
364
458
|
if (s.role === "ai") {
|
|
365
|
-
const
|
|
366
|
-
|
|
459
|
+
const c = M(s, i, n);
|
|
460
|
+
c.length > 0 && t(c, o, a);
|
|
367
461
|
continue;
|
|
368
462
|
}
|
|
369
463
|
if (s.role === "tool") {
|
|
370
464
|
if (s.toolCallId && n.has(s.toolCallId)) continue;
|
|
371
|
-
|
|
465
|
+
t([L(s)], o, a);
|
|
372
466
|
}
|
|
373
467
|
}
|
|
374
|
-
return
|
|
468
|
+
return d;
|
|
375
469
|
}
|
|
376
|
-
function
|
|
470
|
+
function M(r, e, i) {
|
|
377
471
|
const n = [];
|
|
378
472
|
r.reasoning && n.push({ type: "thinking", content: r.reasoning }), r.content && n.push({ type: "text", content: u(r.content) });
|
|
379
|
-
for (const
|
|
380
|
-
|
|
473
|
+
for (const d of r.toolCalls ?? [])
|
|
474
|
+
d.is_interrupt ?? d.isInterrupt ? (i.add(d.id), n.push(q(d, e))) : n.push(J(d));
|
|
381
475
|
return n;
|
|
382
476
|
}
|
|
383
|
-
function
|
|
384
|
-
const
|
|
477
|
+
function q(r, e) {
|
|
478
|
+
const i = e.has(r.id), n = typeof r.args == "object" ? r.args : {};
|
|
385
479
|
return {
|
|
386
480
|
type: "interrupt",
|
|
387
481
|
interrupt: {
|
|
@@ -396,11 +490,11 @@ function E(r, e) {
|
|
|
396
490
|
fields: n.fields,
|
|
397
491
|
metadata: n.metadata
|
|
398
492
|
},
|
|
399
|
-
resolved:
|
|
400
|
-
response:
|
|
493
|
+
resolved: i,
|
|
494
|
+
response: i ? { action: "submit", value: j(e.get(r.id)) } : void 0
|
|
401
495
|
};
|
|
402
496
|
}
|
|
403
|
-
function
|
|
497
|
+
function J(r) {
|
|
404
498
|
let e;
|
|
405
499
|
try {
|
|
406
500
|
e = typeof r.args == "string" ? r.args : JSON.stringify(r.args ?? {});
|
|
@@ -409,20 +503,22 @@ function U(r) {
|
|
|
409
503
|
}
|
|
410
504
|
return { type: "tool_call", toolName: r.name ?? "", toolCallId: r.id ?? "", args: e };
|
|
411
505
|
}
|
|
412
|
-
function
|
|
413
|
-
var
|
|
506
|
+
function L(r) {
|
|
507
|
+
var i, n, d, t;
|
|
414
508
|
const e = Array.isArray(r.artifacts) ? r.artifacts : void 0;
|
|
415
509
|
return {
|
|
416
510
|
type: "tool_result",
|
|
417
511
|
toolName: r.toolName ?? "",
|
|
418
512
|
toolCallId: r.toolCallId ?? "",
|
|
513
|
+
// tool 行后端 content 即展示摘要(_build_tool_fields 与 SSE 口径一致),直接读 content
|
|
419
514
|
content: u(r.content),
|
|
420
515
|
artifacts: e,
|
|
421
|
-
renderMode: ((
|
|
422
|
-
html: (
|
|
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)
|
|
423
519
|
};
|
|
424
520
|
}
|
|
425
|
-
function
|
|
521
|
+
function j(r) {
|
|
426
522
|
if (r != null)
|
|
427
523
|
try {
|
|
428
524
|
return JSON.parse(r);
|
|
@@ -430,59 +526,59 @@ function D(r) {
|
|
|
430
526
|
return r;
|
|
431
527
|
}
|
|
432
528
|
}
|
|
433
|
-
async function
|
|
434
|
-
const
|
|
529
|
+
async function G(r, e, i, n, d, t, s) {
|
|
530
|
+
const o = await r.streamPost(
|
|
435
531
|
`/chat/interrupt/${e}/respond`,
|
|
436
532
|
{
|
|
437
|
-
sessionId:
|
|
533
|
+
sessionId: i,
|
|
438
534
|
action: n.action,
|
|
439
535
|
value: n.value
|
|
440
536
|
},
|
|
441
537
|
s
|
|
442
538
|
);
|
|
443
|
-
if (!
|
|
444
|
-
const
|
|
445
|
-
throw
|
|
539
|
+
if (!o.ok) {
|
|
540
|
+
const a = new Error(`HTTP ${o.status}`);
|
|
541
|
+
throw t == null || t(a), a;
|
|
446
542
|
}
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
(
|
|
450
|
-
|
|
543
|
+
d && await T(
|
|
544
|
+
o,
|
|
545
|
+
(a) => {
|
|
546
|
+
a.type === "error" ? t == null || t(new Error(a.content)) : d(a);
|
|
451
547
|
},
|
|
452
|
-
(
|
|
548
|
+
(a) => t == null ? void 0 : t(a)
|
|
453
549
|
);
|
|
454
550
|
}
|
|
455
|
-
async function
|
|
551
|
+
async function R(r) {
|
|
456
552
|
return r.get(`/chat/bots/${r.getBotId()}/skills`);
|
|
457
553
|
}
|
|
458
|
-
async function
|
|
554
|
+
async function B(r, e) {
|
|
459
555
|
await r.post("/chat/stop", { sessionId: e });
|
|
460
556
|
}
|
|
461
|
-
function
|
|
462
|
-
const e = new
|
|
557
|
+
function z(r) {
|
|
558
|
+
const e = new $(r);
|
|
463
559
|
return {
|
|
464
560
|
botId: e.getBotId(),
|
|
465
561
|
getToken: () => e.fetchToken(),
|
|
466
|
-
createSession: () =>
|
|
467
|
-
chat: (n) =>
|
|
468
|
-
listConversations: (n) =>
|
|
469
|
-
renameConversation: (n,
|
|
470
|
-
deleteConversation: (n) =>
|
|
471
|
-
getMessages: (n) =>
|
|
472
|
-
respondInterrupt: (n,
|
|
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),
|
|
567
|
+
getMessages: (n) => U(e, n),
|
|
568
|
+
respondInterrupt: (n, d, t, s, o, a) => G(e, n, d, t, s, o, a),
|
|
473
569
|
setToken: (n) => e.setToken(n),
|
|
474
|
-
feedback: async (n,
|
|
475
|
-
const s = { type:
|
|
476
|
-
|
|
570
|
+
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);
|
|
477
573
|
},
|
|
478
574
|
cancelFeedback: async (n) => {
|
|
479
575
|
await e.del(`/chat/messages/${n}/feedback`);
|
|
480
576
|
},
|
|
481
|
-
listSkills: () =>
|
|
482
|
-
stopGeneration: (n) =>
|
|
577
|
+
listSkills: () => R(e),
|
|
578
|
+
stopGeneration: (n) => B(e, n)
|
|
483
579
|
};
|
|
484
580
|
}
|
|
485
581
|
export {
|
|
486
|
-
|
|
487
|
-
|
|
582
|
+
W as createNosUploader,
|
|
583
|
+
z as createSuperAgent
|
|
488
584
|
};
|