super-agent-sdk 1.0.21 → 1.0.23
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 +14 -10
- package/dist/index.cjs +4 -4
- package/dist/index.d.ts +24 -2
- package/dist/index.mjs +306 -285
- package/dist/{mammoth.browser-BWTaSUmQ.cjs → mammoth.browser-CKp13R4W.cjs} +63 -63
- package/dist/{mammoth.browser-DFPCY35d.js → mammoth.browser-_e1UoKEX.js} +3708 -3725
- package/dist/{nosUploader-DjJ7u2B1.js → nosUploader-2VXYPLap.js} +2 -1
- package/dist/{nosUploader-DLX7JsnR.cjs → nosUploader-Dk2GyRpT.cjs} +4 -4
- package/dist/{purify.es-CImoWRjX.js → purify.es-C-6FFqDW.js} +205 -214
- package/dist/purify.es-Dsdnkgrg.cjs +3 -0
- package/dist/widget.cjs +323 -29
- package/dist/widget.d.ts +56 -11
- package/dist/widget.mjs +27999 -5544
- package/package.json +3 -1
- package/dist/purify.es-BnmCBz16.cjs +0 -3
package/dist/index.mjs
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { p as b, s as C } from "./nosUploader-
|
|
2
|
-
import { c as W } from "./nosUploader-
|
|
3
|
-
function
|
|
4
|
-
if (Array.isArray(
|
|
5
|
-
if (
|
|
1
|
+
import { p as b, s as C } from "./nosUploader-2VXYPLap.js";
|
|
2
|
+
import { c as W } from "./nosUploader-2VXYPLap.js";
|
|
3
|
+
function g(r) {
|
|
4
|
+
if (Array.isArray(r)) return r.map((e) => g(e));
|
|
5
|
+
if (r && typeof r == "object" && r.constructor === Object) {
|
|
6
6
|
const e = {};
|
|
7
|
-
for (const [
|
|
8
|
-
const d =
|
|
9
|
-
e[d] =
|
|
7
|
+
for (const [o, s] of Object.entries(r)) {
|
|
8
|
+
const d = o.replace(/_([a-z])/g, (t, n) => n.toUpperCase());
|
|
9
|
+
e[d] = g(s);
|
|
10
10
|
}
|
|
11
11
|
return e;
|
|
12
12
|
}
|
|
13
|
-
return
|
|
13
|
+
return r;
|
|
14
14
|
}
|
|
15
15
|
const S = "/api/agent/runtime/v1";
|
|
16
16
|
class A {
|
|
17
17
|
constructor(e) {
|
|
18
18
|
this.refreshing = null, this.tokenPromise = null;
|
|
19
|
-
const
|
|
20
|
-
this.baseUrl =
|
|
19
|
+
const o = e.baseUrl ?? S;
|
|
20
|
+
this.baseUrl = o.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
22
|
getBotCode() {
|
|
23
23
|
return this.botCode;
|
|
@@ -42,13 +42,13 @@ class A {
|
|
|
42
42
|
if (this.token) return this.token;
|
|
43
43
|
if (this.tokenPromise) return this.tokenPromise;
|
|
44
44
|
this.tokenPromise = (async () => {
|
|
45
|
-
const
|
|
45
|
+
const o = `${this.isAbsoluteGateway ? this.tokenGateway : `${this.getOrigin()}${this.tokenGateway}`}/superagent/v2/token/generate`, s = {
|
|
46
46
|
"Content-Type": "application/json"
|
|
47
47
|
};
|
|
48
|
-
this.tenantId != null && (
|
|
49
|
-
const d = await fetch(
|
|
48
|
+
this.tenantId != null && (s["X-Tenant-Id"] = String(this.tenantId));
|
|
49
|
+
const d = await fetch(o, {
|
|
50
50
|
method: "POST",
|
|
51
|
-
headers:
|
|
51
|
+
headers: s,
|
|
52
52
|
body: JSON.stringify({ botCode: this.botCode })
|
|
53
53
|
});
|
|
54
54
|
if (!d.ok)
|
|
@@ -56,8 +56,8 @@ class A {
|
|
|
56
56
|
const t = await d.json();
|
|
57
57
|
if (t.code !== "200")
|
|
58
58
|
throw new Error(t.message || `API error: ${t.code}`);
|
|
59
|
-
const
|
|
60
|
-
return this.token =
|
|
59
|
+
const n = g(t.data);
|
|
60
|
+
return this.token = n.token, n.appId && !this.appId && (this.appId = n.appId), n.token;
|
|
61
61
|
})();
|
|
62
62
|
try {
|
|
63
63
|
return await this.tokenPromise;
|
|
@@ -86,109 +86,109 @@ class A {
|
|
|
86
86
|
this.refreshing = null;
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
-
async request(e,
|
|
89
|
+
async request(e, o, s) {
|
|
90
90
|
if (!this.token && !await this.handleTokenRefresh())
|
|
91
91
|
throw new Error("SDK token not available: POST /token failed");
|
|
92
|
-
let d = this.isAbsoluteUrl ? `${this.baseUrl}${
|
|
93
|
-
if (
|
|
94
|
-
const
|
|
95
|
-
for (const [c, l] of Object.entries(
|
|
96
|
-
l != null &&
|
|
97
|
-
const
|
|
98
|
-
|
|
92
|
+
let d = this.isAbsoluteUrl ? `${this.baseUrl}${o}` : `${this.getOrigin()}${this.baseUrl}${o}`;
|
|
93
|
+
if (s != null && s.params) {
|
|
94
|
+
const a = new URLSearchParams();
|
|
95
|
+
for (const [c, l] of Object.entries(s.params))
|
|
96
|
+
l != null && a.set(c, String(l));
|
|
97
|
+
const i = a.toString();
|
|
98
|
+
i && (d += `?${i}`);
|
|
99
99
|
}
|
|
100
100
|
const t = await fetch(d, {
|
|
101
101
|
method: e,
|
|
102
102
|
headers: this.headers(),
|
|
103
|
-
body:
|
|
103
|
+
body: s != null && s.body ? JSON.stringify(s.body) : void 0
|
|
104
104
|
});
|
|
105
|
-
if (t.status === 401 && !(
|
|
106
|
-
return this.request(e,
|
|
105
|
+
if (t.status === 401 && !(s != null && s.retry) && await this.handleTokenRefresh())
|
|
106
|
+
return this.request(e, o, { ...s, retry: !0 });
|
|
107
107
|
if (!t.ok) {
|
|
108
|
-
let
|
|
108
|
+
let a = `HTTP ${t.status}: ${t.statusText}`;
|
|
109
109
|
try {
|
|
110
|
-
const
|
|
111
|
-
|
|
110
|
+
const i = await t.json();
|
|
111
|
+
i != null && i.message && (a = i.message);
|
|
112
112
|
} catch {
|
|
113
113
|
}
|
|
114
|
-
throw new Error(
|
|
114
|
+
throw new Error(a);
|
|
115
115
|
}
|
|
116
|
-
const
|
|
117
|
-
if (
|
|
118
|
-
throw new Error(
|
|
119
|
-
return
|
|
116
|
+
const n = await t.json();
|
|
117
|
+
if (n.code !== "200")
|
|
118
|
+
throw new Error(n.message || `API error: ${n.code}`);
|
|
119
|
+
return g(n.data);
|
|
120
120
|
}
|
|
121
|
-
get(e,
|
|
122
|
-
return this.request("GET", e, { params:
|
|
121
|
+
get(e, o) {
|
|
122
|
+
return this.request("GET", e, { params: o });
|
|
123
123
|
}
|
|
124
|
-
post(e,
|
|
125
|
-
return this.request("POST", e, { body:
|
|
124
|
+
post(e, o) {
|
|
125
|
+
return this.request("POST", e, { body: o });
|
|
126
126
|
}
|
|
127
|
-
patch(e,
|
|
128
|
-
return this.request("PATCH", e, { body:
|
|
127
|
+
patch(e, o) {
|
|
128
|
+
return this.request("PATCH", e, { body: o });
|
|
129
129
|
}
|
|
130
130
|
del(e) {
|
|
131
131
|
return this.request("DELETE", e);
|
|
132
132
|
}
|
|
133
133
|
/** For SSE streaming — returns raw Response (no envelope unwrap) */
|
|
134
|
-
async streamPost(e,
|
|
134
|
+
async streamPost(e, o, s) {
|
|
135
135
|
if (!this.token && !await this.handleTokenRefresh())
|
|
136
136
|
throw new Error("SDK token not available: POST /token failed");
|
|
137
137
|
const d = this.isAbsoluteUrl ? `${this.baseUrl}${e}` : `${this.getOrigin()}${this.baseUrl}${e}`, t = await fetch(d, {
|
|
138
138
|
method: "POST",
|
|
139
139
|
headers: this.headers(),
|
|
140
|
-
body: JSON.stringify(
|
|
141
|
-
signal:
|
|
140
|
+
body: JSON.stringify(o),
|
|
141
|
+
signal: s
|
|
142
142
|
});
|
|
143
143
|
if (t.status === 401) {
|
|
144
|
-
const
|
|
145
|
-
if (
|
|
144
|
+
const n = await b(t.clone());
|
|
145
|
+
if (n.isCookieExpired && typeof (o == null ? void 0 : o.message) == "string") {
|
|
146
146
|
C({
|
|
147
147
|
botCode: this.botCode,
|
|
148
|
-
message:
|
|
149
|
-
sessionId:
|
|
148
|
+
message: o.message,
|
|
149
|
+
sessionId: o.sessionId ?? ""
|
|
150
150
|
});
|
|
151
|
-
const
|
|
151
|
+
const i = n.loginUrl ?? this.loginUrl;
|
|
152
152
|
return this.onAuthExpired ? this.onAuthExpired({
|
|
153
|
-
loginUrl:
|
|
154
|
-
sessionId:
|
|
153
|
+
loginUrl: i,
|
|
154
|
+
sessionId: n.sessionId,
|
|
155
155
|
botCode: this.botCode
|
|
156
|
-
}) :
|
|
156
|
+
}) : i && window.location.replace(i), t;
|
|
157
157
|
}
|
|
158
158
|
if (await this.handleTokenRefresh())
|
|
159
159
|
return fetch(d, {
|
|
160
160
|
method: "POST",
|
|
161
161
|
headers: this.headers(),
|
|
162
|
-
body: JSON.stringify(
|
|
163
|
-
signal:
|
|
162
|
+
body: JSON.stringify(o),
|
|
163
|
+
signal: s
|
|
164
164
|
});
|
|
165
165
|
}
|
|
166
166
|
return t;
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
|
-
function
|
|
170
|
-
return typeof
|
|
169
|
+
function h(r) {
|
|
170
|
+
return typeof r == "string" ? r : Array.isArray(r) ? r.map((e) => {
|
|
171
171
|
if (typeof e == "string") return e;
|
|
172
172
|
if (e && typeof e == "object") {
|
|
173
173
|
if (typeof e.text == "string") return e.text;
|
|
174
174
|
if (e.type) return `[${e.type}${e.mime_type ? ": " + e.mime_type : ""}]`;
|
|
175
175
|
}
|
|
176
176
|
return "";
|
|
177
|
-
}).join("") :
|
|
177
|
+
}).join("") : r == null ? "" : String(r);
|
|
178
178
|
}
|
|
179
|
-
function w(
|
|
180
|
-
const e =
|
|
181
|
-
`).map((
|
|
182
|
-
let
|
|
183
|
-
for (const
|
|
184
|
-
if (
|
|
185
|
-
|
|
186
|
-
else if (
|
|
187
|
-
|
|
188
|
-
else if (
|
|
189
|
-
const
|
|
179
|
+
function w(r) {
|
|
180
|
+
const e = r.split(`
|
|
181
|
+
`).map((a) => a.trim()).filter((a) => a.length > 0);
|
|
182
|
+
let o, s, d;
|
|
183
|
+
for (const a of e)
|
|
184
|
+
if (a.startsWith("id:"))
|
|
185
|
+
o = a.slice(3).trim();
|
|
186
|
+
else if (a.startsWith("event:"))
|
|
187
|
+
s = a.slice(6).trim();
|
|
188
|
+
else if (a.startsWith("data:")) {
|
|
189
|
+
const i = a.slice(5).trim();
|
|
190
190
|
d = d ? `${d}
|
|
191
|
-
${
|
|
191
|
+
${i}` : i;
|
|
192
192
|
}
|
|
193
193
|
if (d === void 0) return null;
|
|
194
194
|
let t;
|
|
@@ -197,7 +197,7 @@ ${a}` : a;
|
|
|
197
197
|
} catch {
|
|
198
198
|
return null;
|
|
199
199
|
}
|
|
200
|
-
const
|
|
200
|
+
const n = t.type === "tool_result" && typeof t.content == "object" && t.content ? t.content : void 0;
|
|
201
201
|
switch (t.type) {
|
|
202
202
|
case "session.start":
|
|
203
203
|
return {
|
|
@@ -205,15 +205,15 @@ ${a}` : a;
|
|
|
205
205
|
content: "",
|
|
206
206
|
sessionId: t.sessionId ?? t.session_id ?? "",
|
|
207
207
|
roundId: t.roundId ?? t.round_id,
|
|
208
|
-
event:
|
|
209
|
-
id:
|
|
208
|
+
event: s,
|
|
209
|
+
id: o
|
|
210
210
|
};
|
|
211
211
|
case "user":
|
|
212
|
-
return { type: "user", content:
|
|
212
|
+
return { type: "user", content: h(t.content), event: s, id: o };
|
|
213
213
|
case "thinking":
|
|
214
|
-
return { type: "thinking", content:
|
|
214
|
+
return { type: "thinking", content: h(t.content), event: s, id: o };
|
|
215
215
|
case "ai":
|
|
216
|
-
return { type: "ai", content:
|
|
216
|
+
return { type: "ai", content: h(t.content), event: s, id: o };
|
|
217
217
|
case "tool_call":
|
|
218
218
|
return {
|
|
219
219
|
type: "tool_call",
|
|
@@ -221,56 +221,57 @@ ${a}` : a;
|
|
|
221
221
|
toolName: t.name,
|
|
222
222
|
toolCallId: t.id,
|
|
223
223
|
args: typeof t.args == "string" ? t.args : JSON.stringify(t.args ?? {}),
|
|
224
|
-
event:
|
|
225
|
-
id:
|
|
224
|
+
event: s,
|
|
225
|
+
id: o
|
|
226
226
|
};
|
|
227
227
|
case "tool_delta":
|
|
228
228
|
return {
|
|
229
229
|
type: "tool_delta",
|
|
230
230
|
content: typeof t.content == "string" ? t.content : "",
|
|
231
231
|
toolCallId: t.tool_call_id ?? t.toolCallId ?? "",
|
|
232
|
-
event:
|
|
233
|
-
id:
|
|
232
|
+
event: s,
|
|
233
|
+
id: o
|
|
234
234
|
};
|
|
235
235
|
case "tool_result": {
|
|
236
|
-
const
|
|
237
|
-
let
|
|
238
|
-
return typeof
|
|
236
|
+
const a = n == null ? void 0 : n.result;
|
|
237
|
+
let i;
|
|
238
|
+
return typeof a == "string" ? i = a : a != null && typeof a == "object" ? i = JSON.stringify(a) : n && typeof n == "object" && Object.keys(n).length > 0 ? i = JSON.stringify(n) : i = h(t.output ?? ""), {
|
|
239
239
|
type: "tool_result",
|
|
240
|
-
content:
|
|
240
|
+
content: i,
|
|
241
241
|
toolName: t.name,
|
|
242
242
|
toolCallId: t.id,
|
|
243
243
|
artifacts: Array.isArray(t.artifacts) ? t.artifacts : void 0,
|
|
244
|
-
renderMode: (
|
|
245
|
-
html: (
|
|
246
|
-
markdown: (
|
|
247
|
-
|
|
248
|
-
|
|
244
|
+
renderMode: (n == null ? void 0 : n.render_mode) ?? t.render_mode ?? t.renderMode,
|
|
245
|
+
html: (n == null ? void 0 : n.html) ?? t.html,
|
|
246
|
+
markdown: (n == null ? void 0 : n.markdown) ?? t.markdown,
|
|
247
|
+
defaultExpanded: t.default_expanded ?? t.defaultExpanded,
|
|
248
|
+
event: s,
|
|
249
|
+
id: o
|
|
249
250
|
};
|
|
250
251
|
}
|
|
251
252
|
case "done":
|
|
252
253
|
return {
|
|
253
254
|
type: "done",
|
|
254
|
-
content:
|
|
255
|
+
content: h(t.content),
|
|
255
256
|
sessionId: t.sessionId ?? t.session_id ?? "",
|
|
256
257
|
messageId: t.messageId ?? t.message_id,
|
|
257
258
|
roundId: t.roundId ?? t.round_id,
|
|
258
259
|
artifacts: Array.isArray(t.artifacts) ? t.artifacts : void 0,
|
|
259
|
-
event:
|
|
260
|
-
id:
|
|
260
|
+
event: s,
|
|
261
|
+
id: o
|
|
261
262
|
};
|
|
262
263
|
case "stop":
|
|
263
264
|
return {
|
|
264
265
|
type: "stop",
|
|
265
|
-
content:
|
|
266
|
+
content: h(t.content),
|
|
266
267
|
sessionId: t.sessionId ?? t.session_id ?? "",
|
|
267
268
|
messageId: t.messageId ?? t.message_id,
|
|
268
269
|
roundId: t.roundId ?? t.round_id,
|
|
269
|
-
event:
|
|
270
|
-
id:
|
|
270
|
+
event: s,
|
|
271
|
+
id: o
|
|
271
272
|
};
|
|
272
273
|
case "error":
|
|
273
|
-
return { type: "error", content: t.message ?? "Unknown error", event:
|
|
274
|
+
return { type: "error", content: t.message ?? "Unknown error", event: s, id: o };
|
|
274
275
|
case "interrupt":
|
|
275
276
|
return {
|
|
276
277
|
type: "interrupt",
|
|
@@ -287,322 +288,342 @@ ${a}` : a;
|
|
|
287
288
|
fields: t.fields,
|
|
288
289
|
metadata: t.metadata
|
|
289
290
|
},
|
|
290
|
-
event:
|
|
291
|
-
id:
|
|
291
|
+
event: s,
|
|
292
|
+
id: o
|
|
292
293
|
};
|
|
293
294
|
default:
|
|
294
295
|
return null;
|
|
295
296
|
}
|
|
296
297
|
}
|
|
297
|
-
async function T(
|
|
298
|
-
if (!
|
|
299
|
-
|
|
298
|
+
async function T(r, e, o) {
|
|
299
|
+
if (!r.body) {
|
|
300
|
+
o(new Error("Response body is null"));
|
|
300
301
|
return;
|
|
301
302
|
}
|
|
302
|
-
const
|
|
303
|
+
const s = r.body.getReader(), d = new TextDecoder();
|
|
303
304
|
let t = "";
|
|
304
305
|
try {
|
|
305
306
|
for (; ; ) {
|
|
306
|
-
const { value:
|
|
307
|
-
if (
|
|
308
|
-
t += d.decode(
|
|
309
|
-
let
|
|
310
|
-
for (; (
|
|
307
|
+
const { value: n, done: a } = await s.read();
|
|
308
|
+
if (a) break;
|
|
309
|
+
t += d.decode(n, { stream: !0 });
|
|
310
|
+
let i;
|
|
311
|
+
for (; (i = t.indexOf(`
|
|
311
312
|
|
|
312
313
|
`)) !== -1; ) {
|
|
313
|
-
const c = t.slice(0,
|
|
314
|
-
t = t.slice(
|
|
314
|
+
const c = t.slice(0, i);
|
|
315
|
+
t = t.slice(i + 2);
|
|
315
316
|
const l = w(c);
|
|
316
317
|
l && e(l);
|
|
317
318
|
}
|
|
318
319
|
}
|
|
319
320
|
if (t.trim()) {
|
|
320
|
-
const
|
|
321
|
-
|
|
321
|
+
const n = w(t);
|
|
322
|
+
n && e(n);
|
|
322
323
|
}
|
|
323
|
-
} catch (
|
|
324
|
-
(
|
|
324
|
+
} catch (n) {
|
|
325
|
+
(n == null ? void 0 : n.name) !== "AbortError" && o(n instanceof Error ? n : new Error(String(n)));
|
|
325
326
|
} finally {
|
|
326
327
|
try {
|
|
327
|
-
|
|
328
|
+
s.releaseLock();
|
|
328
329
|
} catch {
|
|
329
330
|
}
|
|
330
331
|
}
|
|
331
332
|
}
|
|
332
|
-
function
|
|
333
|
+
function _(r, e) {
|
|
333
334
|
var t;
|
|
334
|
-
const
|
|
335
|
-
botCode:
|
|
335
|
+
const o = new AbortController(), s = e.signal ? $(e.signal, o.signal) : o.signal, d = {
|
|
336
|
+
botCode: r.getBotCode(),
|
|
336
337
|
message: e.message,
|
|
337
338
|
sessionId: e.sessionId,
|
|
338
339
|
stream: e.stream !== !1,
|
|
339
340
|
// url 仅前端回显(下载/预览),剥离后发送——签名 URL 不进后端
|
|
340
341
|
...(t = e.attachments) != null && t.length ? {
|
|
341
|
-
attachments: e.attachments.map(({ url:
|
|
342
|
+
attachments: e.attachments.map(({ url: n, ...a }) => a)
|
|
342
343
|
} : {}
|
|
343
344
|
};
|
|
344
|
-
return d.stream ?
|
|
345
|
-
var
|
|
346
|
-
if (!
|
|
347
|
-
let
|
|
345
|
+
return d.stream ? r.streamPost("/chat", d, s).then(async (n) => {
|
|
346
|
+
var a;
|
|
347
|
+
if (!n.ok) {
|
|
348
|
+
let i = `HTTP ${n.status}`;
|
|
348
349
|
try {
|
|
349
|
-
const c = await
|
|
350
|
-
c != null && c.message && (
|
|
350
|
+
const c = await n.json();
|
|
351
|
+
c != null && c.message && (i = c.message);
|
|
351
352
|
} catch {
|
|
352
353
|
}
|
|
353
|
-
(
|
|
354
|
+
(a = e.onError) == null || a.call(e, new Error(i));
|
|
354
355
|
return;
|
|
355
356
|
}
|
|
356
357
|
return T(
|
|
357
|
-
|
|
358
|
-
(
|
|
359
|
-
var c, l,
|
|
360
|
-
|
|
358
|
+
n,
|
|
359
|
+
(i) => {
|
|
360
|
+
var c, l, f, u, m, y, I, p;
|
|
361
|
+
i.type === "done" && i.sessionId ? ((c = e.onMessage) == null || c.call(e, i), (l = e.onDone) == null || l.call(e, { sessionId: i.sessionId, content: i.content, messageId: i.messageId, roundId: i.roundId, artifacts: i.artifacts })) : i.type === "done" ? ((f = e.onMessage) == null || f.call(e, i), (u = e.onDone) == null || u.call(e, { sessionId: "", content: i.content, messageId: i.messageId, roundId: i.roundId, artifacts: i.artifacts })) : i.type === "stop" ? ((m = e.onMessage) == null || m.call(e, i), (y = e.onDone) == null || y.call(e, { sessionId: i.sessionId ?? "", content: i.content, messageId: i.messageId, roundId: i.roundId })) : i.type === "error" ? (I = e.onError) == null || I.call(e, new Error(i.content)) : (p = e.onMessage) == null || p.call(e, i);
|
|
361
362
|
},
|
|
362
|
-
(
|
|
363
|
+
(i) => {
|
|
363
364
|
var c;
|
|
364
|
-
return (c = e.onError) == null ? void 0 : c.call(e,
|
|
365
|
+
return (c = e.onError) == null ? void 0 : c.call(e, i);
|
|
365
366
|
}
|
|
366
367
|
);
|
|
367
|
-
}).catch((
|
|
368
|
-
var
|
|
369
|
-
(
|
|
370
|
-
}) :
|
|
371
|
-
var
|
|
372
|
-
(
|
|
373
|
-
sessionId:
|
|
374
|
-
content:
|
|
375
|
-
messageId:
|
|
368
|
+
}).catch((n) => {
|
|
369
|
+
var a;
|
|
370
|
+
(n == null ? void 0 : n.name) !== "AbortError" && ((a = e.onError) == null || a.call(e, n instanceof Error ? n : new Error(String(n))));
|
|
371
|
+
}) : r.post("/chat", d).then((n) => {
|
|
372
|
+
var a;
|
|
373
|
+
(a = e.onDone) == null || a.call(e, {
|
|
374
|
+
sessionId: n.sessionId,
|
|
375
|
+
content: n.content ?? "",
|
|
376
|
+
messageId: n.messageId
|
|
376
377
|
});
|
|
377
|
-
}).catch((
|
|
378
|
-
var
|
|
379
|
-
(
|
|
380
|
-
}),
|
|
378
|
+
}).catch((n) => {
|
|
379
|
+
var a;
|
|
380
|
+
(a = e.onError) == null || a.call(e, n instanceof Error ? n : new Error(String(n)));
|
|
381
|
+
}), o;
|
|
381
382
|
}
|
|
382
|
-
function
|
|
383
|
-
const
|
|
384
|
-
return
|
|
383
|
+
function $(r, e) {
|
|
384
|
+
const o = new AbortController(), s = () => o.abort();
|
|
385
|
+
return r.addEventListener("abort", s, { once: !0 }), e.addEventListener("abort", s, { once: !0 }), (r.aborted || e.aborted) && o.abort(), o.signal;
|
|
385
386
|
}
|
|
386
|
-
async function
|
|
387
|
-
return (await
|
|
388
|
-
botCode:
|
|
387
|
+
async function x(r) {
|
|
388
|
+
return (await r.post("/chat/sessions", {
|
|
389
|
+
botCode: r.getBotCode()
|
|
389
390
|
})).sessionId;
|
|
390
391
|
}
|
|
391
|
-
function
|
|
392
|
+
function E(r) {
|
|
392
393
|
return {
|
|
393
394
|
// 后端返回 thread_id,toCamelCase 转为 threadId,映射为 sessionId
|
|
394
|
-
sessionId:
|
|
395
|
+
sessionId: r.threadId ?? r.sessionId,
|
|
395
396
|
// bot 外部标识统一 botCode(createSuperAgent 入参,全链消费);
|
|
396
397
|
// 后端回传的内部 bot 标识字段 SDK 不消费、不暴露
|
|
397
|
-
title:
|
|
398
|
-
createTime:
|
|
399
|
-
updateTime:
|
|
398
|
+
title: r.title,
|
|
399
|
+
createTime: r.createTime,
|
|
400
|
+
updateTime: r.updateTime
|
|
400
401
|
};
|
|
401
402
|
}
|
|
402
|
-
async function
|
|
403
|
-
const
|
|
404
|
-
botCode:
|
|
403
|
+
async function P(r, e) {
|
|
404
|
+
const o = await r.get("/chat/conversations", {
|
|
405
|
+
botCode: r.getBotCode(),
|
|
405
406
|
page: (e == null ? void 0 : e.page) ?? 1,
|
|
406
407
|
size: (e == null ? void 0 : e.size) ?? 20
|
|
407
408
|
});
|
|
408
409
|
return {
|
|
409
|
-
...
|
|
410
|
-
items:
|
|
410
|
+
...o,
|
|
411
|
+
items: o.items.map(E)
|
|
411
412
|
};
|
|
412
413
|
}
|
|
413
|
-
async function v(
|
|
414
|
-
await
|
|
414
|
+
async function v(r, e, o) {
|
|
415
|
+
await r.patch(`/chat/conversations/${e}`, { title: o });
|
|
415
416
|
}
|
|
416
|
-
async function O(
|
|
417
|
-
await
|
|
417
|
+
async function O(r, e) {
|
|
418
|
+
await r.del(`/chat/conversations/${e}`);
|
|
418
419
|
}
|
|
419
|
-
async function U(
|
|
420
|
-
const
|
|
421
|
-
|
|
420
|
+
async function U(r, e) {
|
|
421
|
+
const o = await r.get(
|
|
422
|
+
`/chat/conversations/${e}/messages`
|
|
423
|
+
);
|
|
424
|
+
return M(o);
|
|
422
425
|
}
|
|
423
426
|
function k() {
|
|
424
427
|
return `r_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
|
|
425
428
|
}
|
|
426
|
-
function
|
|
429
|
+
function M(r) {
|
|
427
430
|
var d;
|
|
428
|
-
const e =
|
|
431
|
+
const e = r.length > 0 && Array.isArray((d = r[0]) == null ? void 0 : d.data), o = [];
|
|
429
432
|
if (e)
|
|
430
|
-
for (const t of
|
|
431
|
-
|
|
433
|
+
for (const t of r)
|
|
434
|
+
o.push({
|
|
432
435
|
roundId: t.roundId ?? k(),
|
|
433
436
|
artifacts: Array.isArray(t.artifacts) && t.artifacts.length ? t.artifacts : void 0,
|
|
434
437
|
items: Array.isArray(t.data) ? t.data : []
|
|
435
438
|
});
|
|
436
439
|
else
|
|
437
|
-
|
|
438
|
-
const
|
|
439
|
-
for (const t of
|
|
440
|
-
const
|
|
441
|
-
for (const
|
|
440
|
+
o.push({ roundId: k(), items: r });
|
|
441
|
+
const s = [];
|
|
442
|
+
for (const t of o) {
|
|
443
|
+
const n = N(t.items);
|
|
444
|
+
for (const a of n) a.roundId = t.roundId;
|
|
442
445
|
if (t.artifacts) {
|
|
443
|
-
const
|
|
444
|
-
|
|
446
|
+
const a = n.findLast((i) => i.role === "assistant");
|
|
447
|
+
a && (a.artifacts = t.artifacts);
|
|
445
448
|
}
|
|
446
|
-
|
|
449
|
+
s.push(...n);
|
|
447
450
|
}
|
|
448
|
-
return
|
|
451
|
+
return s;
|
|
449
452
|
}
|
|
450
|
-
function
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
453
|
+
function N(r) {
|
|
454
|
+
var n;
|
|
455
|
+
const e = [...r].sort((a, i) => {
|
|
456
|
+
const c = new Date(a.createTime ?? 0).getTime() || 0, l = new Date(i.createTime ?? 0).getTime() || 0;
|
|
457
|
+
return c !== l ? c - l : (a.seq ?? 0) - (i.seq ?? 0);
|
|
458
|
+
}), o = /* @__PURE__ */ new Map();
|
|
459
|
+
for (const a of e)
|
|
460
|
+
a.role === "tool" && a.toolCallId && o.set(a.toolCallId, a.content || "");
|
|
461
|
+
const s = /* @__PURE__ */ new Set(), d = [], t = (a, i, c, l, f) => {
|
|
462
|
+
const u = d[d.length - 1];
|
|
463
|
+
(u == null ? void 0 : u.role) === "assistant" ? (u.parts.push(...a), u.id = i, l && (u.messageId = l, u.feedback = f ?? null)) : d.push({
|
|
464
|
+
id: i,
|
|
465
|
+
role: "assistant",
|
|
466
|
+
parts: [...a],
|
|
467
|
+
timestamp: c,
|
|
468
|
+
messageId: l,
|
|
469
|
+
feedback: f ?? null
|
|
470
|
+
});
|
|
460
471
|
};
|
|
461
|
-
for (const
|
|
462
|
-
if (
|
|
463
|
-
const
|
|
464
|
-
if (
|
|
465
|
-
const
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
472
|
+
for (const a of e) {
|
|
473
|
+
if (a.role === "system") continue;
|
|
474
|
+
const i = String(a.id ?? a.messageId ?? `msg_${Date.now()}`), c = new Date(a.createTime ?? "").getTime() || Date.now();
|
|
475
|
+
if (a.role === "human") {
|
|
476
|
+
const l = (a.attachments ?? []).map(
|
|
477
|
+
(u) => ({
|
|
478
|
+
type: "attachment",
|
|
479
|
+
attachment: {
|
|
480
|
+
nosKey: u.nosKey ?? u.attachmentId ?? "",
|
|
481
|
+
// 历史回显后端不带 nosKey,占位空串
|
|
482
|
+
filename: u.filename ?? "file",
|
|
483
|
+
size: u.size ?? void 0,
|
|
484
|
+
mime: u.mime ?? void 0,
|
|
485
|
+
url: u.url ?? void 0
|
|
486
|
+
// 公开读桶下载链接(有则 chip 可点击下载)
|
|
487
|
+
}
|
|
488
|
+
})
|
|
489
|
+
), f = (n = a.metadata) == null ? void 0 : n.raw_message;
|
|
477
490
|
d.push({
|
|
478
|
-
id:
|
|
491
|
+
id: i,
|
|
479
492
|
role: "user",
|
|
480
|
-
parts: [...
|
|
481
|
-
timestamp:
|
|
493
|
+
parts: [...l, { type: "text", content: h(a.content) }],
|
|
494
|
+
timestamp: c,
|
|
495
|
+
messageId: a.messageId,
|
|
496
|
+
rawContent: typeof f == "string" && f ? f : void 0
|
|
482
497
|
});
|
|
483
498
|
continue;
|
|
484
499
|
}
|
|
485
|
-
if (
|
|
486
|
-
const
|
|
487
|
-
|
|
500
|
+
if (a.role === "ai") {
|
|
501
|
+
const l = D(a, o, s);
|
|
502
|
+
l.length > 0 && t(l, i, c, a.messageId, a.feedback);
|
|
488
503
|
continue;
|
|
489
504
|
}
|
|
490
|
-
if (
|
|
491
|
-
if (
|
|
492
|
-
t([L(
|
|
505
|
+
if (a.role === "tool") {
|
|
506
|
+
if (a.toolCallId && s.has(a.toolCallId)) continue;
|
|
507
|
+
t([L(a)], i, c);
|
|
493
508
|
}
|
|
494
509
|
}
|
|
495
510
|
return d;
|
|
496
511
|
}
|
|
497
|
-
function
|
|
498
|
-
const
|
|
499
|
-
|
|
500
|
-
for (const d of
|
|
501
|
-
d.is_interrupt ?? d.isInterrupt ? (
|
|
502
|
-
return
|
|
512
|
+
function D(r, e, o) {
|
|
513
|
+
const s = [];
|
|
514
|
+
r.reasoning && s.push({ type: "thinking", content: r.reasoning }), r.content && s.push({ type: "text", content: h(r.content) });
|
|
515
|
+
for (const d of r.toolCalls ?? [])
|
|
516
|
+
d.is_interrupt ?? d.isInterrupt ? (o.add(d.id), s.push(q(d, e))) : s.push(J(d));
|
|
517
|
+
return s;
|
|
503
518
|
}
|
|
504
|
-
function q(
|
|
505
|
-
const
|
|
519
|
+
function q(r, e) {
|
|
520
|
+
const o = e.has(r.id), s = typeof r.args == "object" ? r.args : {};
|
|
506
521
|
return {
|
|
507
522
|
type: "interrupt",
|
|
508
523
|
interrupt: {
|
|
509
|
-
interruptId:
|
|
510
|
-
interruptType:
|
|
511
|
-
content:
|
|
512
|
-
options:
|
|
513
|
-
placeholder:
|
|
514
|
-
inputType:
|
|
515
|
-
maxLength:
|
|
516
|
-
required:
|
|
517
|
-
fields:
|
|
518
|
-
metadata:
|
|
524
|
+
interruptId: r.id ?? "",
|
|
525
|
+
interruptType: s.interruptType ?? "input",
|
|
526
|
+
content: s.content ?? "",
|
|
527
|
+
options: s.options,
|
|
528
|
+
placeholder: s.placeholder,
|
|
529
|
+
inputType: s.inputType,
|
|
530
|
+
maxLength: s.maxLength,
|
|
531
|
+
required: s.required,
|
|
532
|
+
fields: s.fields,
|
|
533
|
+
metadata: s.metadata
|
|
519
534
|
},
|
|
520
|
-
resolved:
|
|
521
|
-
response:
|
|
535
|
+
resolved: o,
|
|
536
|
+
response: o ? { action: "submit", value: j(e.get(r.id)) } : void 0
|
|
522
537
|
};
|
|
523
538
|
}
|
|
524
|
-
function J(
|
|
539
|
+
function J(r) {
|
|
525
540
|
let e;
|
|
526
541
|
try {
|
|
527
|
-
e = typeof
|
|
542
|
+
e = typeof r.args == "string" ? r.args : JSON.stringify(r.args ?? {});
|
|
528
543
|
} catch {
|
|
529
|
-
e = String(
|
|
544
|
+
e = String(r.args ?? "{}");
|
|
530
545
|
}
|
|
531
|
-
return {
|
|
546
|
+
return {
|
|
547
|
+
type: "tool_call",
|
|
548
|
+
toolName: r.name ?? "",
|
|
549
|
+
toolCallId: r.id ?? "",
|
|
550
|
+
args: e
|
|
551
|
+
};
|
|
532
552
|
}
|
|
533
|
-
function L(
|
|
534
|
-
var
|
|
535
|
-
const e = Array.isArray(
|
|
553
|
+
function L(r) {
|
|
554
|
+
var o, s, d, t, n;
|
|
555
|
+
const e = Array.isArray(r.artifacts) ? r.artifacts : void 0;
|
|
536
556
|
return {
|
|
537
557
|
type: "tool_result",
|
|
538
|
-
toolName:
|
|
539
|
-
toolCallId:
|
|
558
|
+
toolName: r.toolName ?? "",
|
|
559
|
+
toolCallId: r.toolCallId ?? "",
|
|
540
560
|
// tool 行后端 content 即展示摘要(_build_tool_fields 与 SSE 口径一致),直接读 content
|
|
541
|
-
content:
|
|
561
|
+
content: h(r.content),
|
|
542
562
|
artifacts: e,
|
|
543
|
-
renderMode:
|
|
544
|
-
html:
|
|
545
|
-
markdown:
|
|
563
|
+
renderMode: r.renderMode ?? ((o = r.metadata) == null ? void 0 : o.renderMode) ?? ((s = r.metadata) == null ? void 0 : s.render_mode),
|
|
564
|
+
html: r.html ?? ((d = r.metadata) == null ? void 0 : d.html),
|
|
565
|
+
markdown: r.markdown ?? ((t = r.metadata) == null ? void 0 : t.markdown),
|
|
566
|
+
defaultExpanded: r.defaultExpanded ?? ((n = r.metadata) == null ? void 0 : n.default_expanded)
|
|
546
567
|
};
|
|
547
568
|
}
|
|
548
|
-
function j(
|
|
549
|
-
if (
|
|
569
|
+
function j(r) {
|
|
570
|
+
if (r != null)
|
|
550
571
|
try {
|
|
551
|
-
return JSON.parse(
|
|
572
|
+
return JSON.parse(r);
|
|
552
573
|
} catch {
|
|
553
|
-
return
|
|
574
|
+
return r;
|
|
554
575
|
}
|
|
555
576
|
}
|
|
556
|
-
async function G(
|
|
557
|
-
const
|
|
577
|
+
async function G(r, e, o, s, d, t, n) {
|
|
578
|
+
const a = await r.streamPost(
|
|
558
579
|
`/chat/interrupt/${e}/respond`,
|
|
559
580
|
{
|
|
560
|
-
sessionId:
|
|
561
|
-
action:
|
|
562
|
-
value:
|
|
581
|
+
sessionId: o,
|
|
582
|
+
action: s.action,
|
|
583
|
+
value: s.value
|
|
563
584
|
},
|
|
564
|
-
|
|
585
|
+
n
|
|
565
586
|
);
|
|
566
|
-
if (!
|
|
567
|
-
const
|
|
568
|
-
throw t == null || t(
|
|
587
|
+
if (!a.ok) {
|
|
588
|
+
const i = new Error(`HTTP ${a.status}`);
|
|
589
|
+
throw t == null || t(i), i;
|
|
569
590
|
}
|
|
570
591
|
d && await T(
|
|
571
|
-
|
|
572
|
-
(
|
|
573
|
-
|
|
592
|
+
a,
|
|
593
|
+
(i) => {
|
|
594
|
+
i.type === "error" ? t == null || t(new Error(i.content)) : d(i);
|
|
574
595
|
},
|
|
575
|
-
(
|
|
596
|
+
(i) => t == null ? void 0 : t(i)
|
|
576
597
|
);
|
|
577
598
|
}
|
|
578
|
-
async function R(
|
|
579
|
-
return
|
|
599
|
+
async function R(r) {
|
|
600
|
+
return r.get(`/chat/bots/${r.getBotCode()}/skills`);
|
|
580
601
|
}
|
|
581
|
-
async function B(
|
|
582
|
-
await
|
|
602
|
+
async function B(r, e) {
|
|
603
|
+
await r.post("/chat/stop", { sessionId: e });
|
|
583
604
|
}
|
|
584
|
-
function z(
|
|
585
|
-
const e = new A(
|
|
605
|
+
function z(r) {
|
|
606
|
+
const e = new A(r);
|
|
586
607
|
return {
|
|
587
608
|
botCode: e.getBotCode(),
|
|
588
609
|
getToken: () => e.fetchToken(),
|
|
589
|
-
createSession: () =>
|
|
590
|
-
chat: (
|
|
591
|
-
listConversations: (
|
|
592
|
-
renameConversation: (
|
|
593
|
-
deleteConversation: (
|
|
594
|
-
getMessages: (
|
|
595
|
-
respondInterrupt: (
|
|
596
|
-
setToken: (
|
|
597
|
-
feedback: async (
|
|
598
|
-
const
|
|
599
|
-
d === "dislike" && ((t == null ? void 0 : t.reason) != null && (
|
|
610
|
+
createSession: () => x(e),
|
|
611
|
+
chat: (s) => _(e, s),
|
|
612
|
+
listConversations: (s) => P(e, s),
|
|
613
|
+
renameConversation: (s, d) => v(e, s, d),
|
|
614
|
+
deleteConversation: (s) => O(e, s),
|
|
615
|
+
getMessages: (s) => U(e, s),
|
|
616
|
+
respondInterrupt: (s, d, t, n, a, i) => G(e, s, d, t, n, a, i),
|
|
617
|
+
setToken: (s) => e.setToken(s),
|
|
618
|
+
feedback: async (s, d, t) => {
|
|
619
|
+
const n = { type: d };
|
|
620
|
+
d === "dislike" && ((t == null ? void 0 : t.reason) != null && (n.reason = t.reason), t != null && t.remark && (n.remark = t.remark)), await e.post(`/chat/messages/${s}/feedback`, n);
|
|
600
621
|
},
|
|
601
|
-
cancelFeedback: async (
|
|
602
|
-
await e.del(`/chat/messages/${
|
|
622
|
+
cancelFeedback: async (s) => {
|
|
623
|
+
await e.del(`/chat/messages/${s}/feedback`);
|
|
603
624
|
},
|
|
604
625
|
listSkills: () => R(e),
|
|
605
|
-
stopGeneration: (
|
|
626
|
+
stopGeneration: (s) => B(e, s)
|
|
606
627
|
};
|
|
607
628
|
}
|
|
608
629
|
export {
|