super-agent-sdk 1.0.6 → 1.0.7
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 +62 -7
- package/dist/index.cjs +4 -4
- package/dist/index.d.ts +12 -1
- package/dist/index.mjs +222 -178
- package/dist/widget.cjs +195 -34
- package/dist/widget.d.ts +41 -9
- package/dist/widget.mjs +1744 -1177
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
function
|
|
2
|
-
if (Array.isArray(
|
|
3
|
-
if (
|
|
1
|
+
function u(r) {
|
|
2
|
+
if (Array.isArray(r)) return r.map((e) => u(e));
|
|
3
|
+
if (r && typeof r == "object" && r.constructor === Object) {
|
|
4
4
|
const e = {};
|
|
5
|
-
for (const [t,
|
|
6
|
-
const o = t.replace(/_([a-z])/g, (
|
|
7
|
-
e[o] =
|
|
5
|
+
for (const [t, s] of Object.entries(r)) {
|
|
6
|
+
const o = t.replace(/_([a-z])/g, (n, a) => a.toUpperCase());
|
|
7
|
+
e[o] = u(s);
|
|
8
8
|
}
|
|
9
9
|
return e;
|
|
10
10
|
}
|
|
11
|
-
return
|
|
11
|
+
return r;
|
|
12
12
|
}
|
|
13
|
-
const
|
|
14
|
-
class
|
|
13
|
+
const I = "/api/agent/runtime/v1";
|
|
14
|
+
class w {
|
|
15
15
|
constructor(e) {
|
|
16
16
|
this.refreshing = null;
|
|
17
|
-
const t = e.baseUrl ??
|
|
17
|
+
const t = e.baseUrl ?? I;
|
|
18
18
|
this.baseUrl = t.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);
|
|
19
19
|
}
|
|
20
20
|
getBotId() {
|
|
@@ -32,18 +32,18 @@ class I {
|
|
|
32
32
|
}
|
|
33
33
|
/** POST {origin}{tokenGateway}/v1/token — 获取 token + appId */
|
|
34
34
|
async fetchToken() {
|
|
35
|
-
const t = `${this.isAbsoluteGateway ? this.tokenGateway : `${this.getOrigin()}${this.tokenGateway}`}/v1/token`,
|
|
35
|
+
const t = `${this.isAbsoluteGateway ? this.tokenGateway : `${this.getOrigin()}${this.tokenGateway}`}/v1/token`, s = await fetch(t, {
|
|
36
36
|
method: "POST",
|
|
37
37
|
headers: { "Content-Type": "application/json" },
|
|
38
38
|
body: JSON.stringify({ botId: this.botId })
|
|
39
39
|
});
|
|
40
|
-
if (!
|
|
41
|
-
throw new Error(`HTTP ${
|
|
42
|
-
const o = await
|
|
40
|
+
if (!s.ok)
|
|
41
|
+
throw new Error(`HTTP ${s.status}: ${s.statusText}`);
|
|
42
|
+
const o = await s.json();
|
|
43
43
|
if (o.code !== "200")
|
|
44
44
|
throw new Error(o.message || `API error: ${o.code}`);
|
|
45
|
-
const
|
|
46
|
-
return this.token =
|
|
45
|
+
const n = u(o.data);
|
|
46
|
+
return this.token = n.token, n.appId && !this.appId && (this.appId = n.appId), n.token;
|
|
47
47
|
}
|
|
48
48
|
headers(e) {
|
|
49
49
|
return {
|
|
@@ -66,30 +66,30 @@ class I {
|
|
|
66
66
|
this.refreshing = null;
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
async request(e, t,
|
|
69
|
+
async request(e, t, s) {
|
|
70
70
|
if (!this.token && !await this.handleTokenRefresh())
|
|
71
71
|
throw new Error("SDK token not available: POST /token failed");
|
|
72
72
|
let o = this.isAbsoluteUrl ? `${this.baseUrl}${t}` : `${this.getOrigin()}${this.baseUrl}${t}`;
|
|
73
|
-
if (
|
|
73
|
+
if (s != null && s.params) {
|
|
74
74
|
const i = new URLSearchParams();
|
|
75
|
-
for (const [
|
|
76
|
-
|
|
75
|
+
for (const [d, l] of Object.entries(s.params))
|
|
76
|
+
l != null && i.set(d, String(l));
|
|
77
77
|
const c = i.toString();
|
|
78
78
|
c && (o += `?${c}`);
|
|
79
79
|
}
|
|
80
|
-
const
|
|
80
|
+
const n = await fetch(o, {
|
|
81
81
|
method: e,
|
|
82
82
|
headers: this.headers(),
|
|
83
|
-
body:
|
|
83
|
+
body: s != null && s.body ? JSON.stringify(s.body) : void 0
|
|
84
84
|
});
|
|
85
|
-
if (
|
|
86
|
-
return this.request(e, t, { ...
|
|
87
|
-
if (!
|
|
88
|
-
throw new Error(`HTTP ${
|
|
89
|
-
const
|
|
90
|
-
if (
|
|
91
|
-
throw new Error(
|
|
92
|
-
return
|
|
85
|
+
if (n.status === 401 && !(s != null && s.retry) && await this.handleTokenRefresh())
|
|
86
|
+
return this.request(e, t, { ...s, retry: !0 });
|
|
87
|
+
if (!n.ok)
|
|
88
|
+
throw new Error(`HTTP ${n.status}: ${n.statusText}`);
|
|
89
|
+
const a = await n.json();
|
|
90
|
+
if (a.code !== "200")
|
|
91
|
+
throw new Error(a.message || `API error: ${a.code}`);
|
|
92
|
+
return u(a.data);
|
|
93
93
|
}
|
|
94
94
|
get(e, t) {
|
|
95
95
|
return this.request("GET", e, { params: t });
|
|
@@ -104,26 +104,26 @@ class I {
|
|
|
104
104
|
return this.request("DELETE", e);
|
|
105
105
|
}
|
|
106
106
|
/** For SSE streaming — returns raw Response (no envelope unwrap) */
|
|
107
|
-
async streamPost(e, t,
|
|
107
|
+
async streamPost(e, t, s) {
|
|
108
108
|
if (!this.token && !await this.handleTokenRefresh())
|
|
109
109
|
throw new Error("SDK token not available: POST /token failed");
|
|
110
|
-
const o = this.isAbsoluteUrl ? `${this.baseUrl}${e}` : `${this.getOrigin()}${this.baseUrl}${e}`,
|
|
110
|
+
const o = this.isAbsoluteUrl ? `${this.baseUrl}${e}` : `${this.getOrigin()}${this.baseUrl}${e}`, n = await fetch(o, {
|
|
111
111
|
method: "POST",
|
|
112
112
|
headers: this.headers(),
|
|
113
113
|
body: JSON.stringify(t),
|
|
114
|
-
signal:
|
|
114
|
+
signal: s
|
|
115
115
|
});
|
|
116
|
-
return
|
|
116
|
+
return n.status === 401 && await this.handleTokenRefresh() ? fetch(o, {
|
|
117
117
|
method: "POST",
|
|
118
118
|
headers: this.headers(),
|
|
119
119
|
body: JSON.stringify(t),
|
|
120
|
-
signal:
|
|
121
|
-
}) :
|
|
120
|
+
signal: s
|
|
121
|
+
}) : n;
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
|
-
function y(
|
|
125
|
-
const e =
|
|
126
|
-
`).map((
|
|
124
|
+
function y(r) {
|
|
125
|
+
const e = r.split(`
|
|
126
|
+
`).map((s) => s.trim()).filter((s) => s.startsWith("data:")).map((s) => s.slice(5).trim());
|
|
127
127
|
if (!e.length) return null;
|
|
128
128
|
let t;
|
|
129
129
|
try {
|
|
@@ -166,6 +166,12 @@ function y(a) {
|
|
|
166
166
|
sessionId: t.sessionId ?? t.session_id ?? "",
|
|
167
167
|
messageId: t.messageId ?? t.message_id
|
|
168
168
|
};
|
|
169
|
+
case "stop":
|
|
170
|
+
return {
|
|
171
|
+
type: "stop",
|
|
172
|
+
content: t.content ?? "",
|
|
173
|
+
sessionId: t.sessionId ?? t.session_id ?? ""
|
|
174
|
+
};
|
|
169
175
|
case "error":
|
|
170
176
|
return { type: "error", content: t.message ?? "Unknown error" };
|
|
171
177
|
case "interrupt":
|
|
@@ -189,216 +195,254 @@ function y(a) {
|
|
|
189
195
|
return null;
|
|
190
196
|
}
|
|
191
197
|
}
|
|
192
|
-
async function m(
|
|
193
|
-
if (!
|
|
198
|
+
async function m(r, e, t) {
|
|
199
|
+
if (!r.body) {
|
|
194
200
|
t(new Error("Response body is null"));
|
|
195
201
|
return;
|
|
196
202
|
}
|
|
197
|
-
const
|
|
198
|
-
let
|
|
203
|
+
const s = r.body.getReader(), o = new TextDecoder();
|
|
204
|
+
let n = "";
|
|
199
205
|
try {
|
|
200
206
|
for (; ; ) {
|
|
201
|
-
const { value:
|
|
207
|
+
const { value: a, done: i } = await s.read();
|
|
202
208
|
if (i) break;
|
|
203
|
-
|
|
209
|
+
n += o.decode(a, { stream: !0 });
|
|
204
210
|
let c;
|
|
205
|
-
for (; (c =
|
|
211
|
+
for (; (c = n.indexOf(`
|
|
206
212
|
|
|
207
213
|
`)) !== -1; ) {
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
const
|
|
211
|
-
|
|
214
|
+
const d = n.slice(0, c);
|
|
215
|
+
n = n.slice(c + 2);
|
|
216
|
+
const l = y(d);
|
|
217
|
+
l && e(l);
|
|
212
218
|
}
|
|
213
219
|
}
|
|
214
|
-
if (
|
|
215
|
-
const
|
|
216
|
-
|
|
220
|
+
if (n.trim()) {
|
|
221
|
+
const a = y(n);
|
|
222
|
+
a && e(a);
|
|
217
223
|
}
|
|
218
|
-
} catch (
|
|
219
|
-
(
|
|
224
|
+
} catch (a) {
|
|
225
|
+
(a == null ? void 0 : a.name) !== "AbortError" && t(a instanceof Error ? a : new Error(String(a)));
|
|
220
226
|
} finally {
|
|
221
227
|
try {
|
|
222
|
-
|
|
228
|
+
s.releaseLock();
|
|
223
229
|
} catch {
|
|
224
230
|
}
|
|
225
231
|
}
|
|
226
232
|
}
|
|
227
|
-
function
|
|
228
|
-
const t = new AbortController(),
|
|
229
|
-
botId:
|
|
233
|
+
function p(r, e) {
|
|
234
|
+
const t = new AbortController(), s = e.signal ? k(e.signal, t.signal) : t.signal, o = {
|
|
235
|
+
botId: r.getBotId(),
|
|
230
236
|
message: e.message,
|
|
231
237
|
sessionId: e.sessionId,
|
|
232
238
|
stream: e.stream !== !1
|
|
233
239
|
};
|
|
234
|
-
return o.stream ?
|
|
235
|
-
var
|
|
236
|
-
if (!
|
|
237
|
-
(
|
|
240
|
+
return o.stream ? r.streamPost("/chat", o, s).then((n) => {
|
|
241
|
+
var a;
|
|
242
|
+
if (!n.ok) {
|
|
243
|
+
(a = e.onError) == null || a.call(e, new Error(`HTTP ${n.status}`));
|
|
238
244
|
return;
|
|
239
245
|
}
|
|
240
246
|
return m(
|
|
241
|
-
|
|
247
|
+
n,
|
|
242
248
|
(i) => {
|
|
243
|
-
var c, l,
|
|
244
|
-
i.type === "done" && i.sessionId ? (c = e.onDone) == null || c.call(e, { sessionId: i.sessionId, content: i.content, messageId: i.messageId }) : i.type === "done" ? (
|
|
249
|
+
var c, d, l, h, f, g;
|
|
250
|
+
i.type === "done" && i.sessionId ? (c = e.onDone) == null || c.call(e, { sessionId: i.sessionId, content: i.content, messageId: i.messageId }) : i.type === "done" ? (d = e.onDone) == null || d.call(e, { sessionId: "", content: i.content, messageId: i.messageId }) : i.type === "stop" ? ((l = e.onMessage) == null || l.call(e, i), (h = e.onDone) == null || h.call(e, { sessionId: i.sessionId ?? "", content: i.content })) : i.type === "error" ? (f = e.onError) == null || f.call(e, new Error(i.content)) : (g = e.onMessage) == null || g.call(e, i);
|
|
245
251
|
},
|
|
246
252
|
(i) => {
|
|
247
253
|
var c;
|
|
248
254
|
return (c = e.onError) == null ? void 0 : c.call(e, i);
|
|
249
255
|
}
|
|
250
256
|
);
|
|
251
|
-
}).catch((
|
|
252
|
-
var
|
|
253
|
-
(
|
|
254
|
-
}) :
|
|
255
|
-
var
|
|
256
|
-
(
|
|
257
|
-
sessionId:
|
|
258
|
-
content:
|
|
259
|
-
messageId:
|
|
257
|
+
}).catch((n) => {
|
|
258
|
+
var a;
|
|
259
|
+
(n == null ? void 0 : n.name) !== "AbortError" && ((a = e.onError) == null || a.call(e, n instanceof Error ? n : new Error(String(n))));
|
|
260
|
+
}) : r.post("/chat", o).then((n) => {
|
|
261
|
+
var a;
|
|
262
|
+
(a = e.onDone) == null || a.call(e, {
|
|
263
|
+
sessionId: n.sessionId,
|
|
264
|
+
content: n.content ?? "",
|
|
265
|
+
messageId: n.messageId
|
|
260
266
|
});
|
|
261
|
-
}).catch((
|
|
262
|
-
var
|
|
263
|
-
(
|
|
267
|
+
}).catch((n) => {
|
|
268
|
+
var a;
|
|
269
|
+
(a = e.onError) == null || a.call(e, n instanceof Error ? n : new Error(String(n)));
|
|
264
270
|
}), t;
|
|
265
271
|
}
|
|
266
|
-
function
|
|
267
|
-
const t = new AbortController(),
|
|
268
|
-
return
|
|
272
|
+
function k(r, e) {
|
|
273
|
+
const t = new AbortController(), s = () => t.abort();
|
|
274
|
+
return r.addEventListener("abort", s, { once: !0 }), e.addEventListener("abort", s, { once: !0 }), (r.aborted || e.aborted) && t.abort(), t.signal;
|
|
269
275
|
}
|
|
270
|
-
async function
|
|
271
|
-
return (await
|
|
272
|
-
botId:
|
|
276
|
+
async function b(r) {
|
|
277
|
+
return (await r.post("/chat/sessions", {
|
|
278
|
+
botId: r.getBotId()
|
|
273
279
|
})).sessionId;
|
|
274
280
|
}
|
|
275
|
-
function
|
|
281
|
+
function T(r) {
|
|
276
282
|
return {
|
|
277
283
|
// 后端返回 thread_id,toCamelCase 转为 threadId,映射为 sessionId
|
|
278
|
-
sessionId:
|
|
279
|
-
botId:
|
|
280
|
-
title:
|
|
281
|
-
createTime:
|
|
282
|
-
updateTime:
|
|
284
|
+
sessionId: r.threadId ?? r.sessionId,
|
|
285
|
+
botId: r.botId,
|
|
286
|
+
title: r.title,
|
|
287
|
+
createTime: r.createTime,
|
|
288
|
+
updateTime: r.updateTime
|
|
283
289
|
};
|
|
284
290
|
}
|
|
285
|
-
async function
|
|
286
|
-
const t = await
|
|
287
|
-
botId:
|
|
291
|
+
async function S(r, e) {
|
|
292
|
+
const t = await r.get("/chat/conversations", {
|
|
293
|
+
botId: r.getBotId(),
|
|
288
294
|
page: (e == null ? void 0 : e.page) ?? 1,
|
|
289
295
|
size: (e == null ? void 0 : e.size) ?? 20
|
|
290
296
|
});
|
|
291
297
|
return {
|
|
292
298
|
...t,
|
|
293
|
-
items: t.items.map(
|
|
299
|
+
items: t.items.map(T)
|
|
294
300
|
};
|
|
295
301
|
}
|
|
296
|
-
async function
|
|
297
|
-
await
|
|
302
|
+
async function $(r, e, t) {
|
|
303
|
+
await r.patch(`/chat/conversations/${e}`, { title: t });
|
|
298
304
|
}
|
|
299
|
-
async function
|
|
300
|
-
await
|
|
305
|
+
async function C(r, e) {
|
|
306
|
+
await r.del(`/chat/conversations/${e}`);
|
|
301
307
|
}
|
|
302
|
-
async function
|
|
303
|
-
const t = await
|
|
308
|
+
async function A(r, e) {
|
|
309
|
+
const t = await r.get(`/chat/conversations/${e}/messages`);
|
|
304
310
|
return O(t);
|
|
305
311
|
}
|
|
306
|
-
function O(
|
|
307
|
-
|
|
308
|
-
const
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
} catch {
|
|
330
|
-
g = String(u.args ?? "{}");
|
|
331
|
-
}
|
|
332
|
-
d.push({
|
|
333
|
-
type: "tool_call",
|
|
334
|
-
toolName: u.name ?? "",
|
|
335
|
-
toolCallId: u.id ?? "",
|
|
336
|
-
args: g
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
e.push({ id: c, role: "assistant", parts: d, timestamp: l });
|
|
340
|
-
} else if (i === "tool") {
|
|
341
|
-
const d = Array.isArray(s.artifacts) ? s.artifacts : void 0;
|
|
342
|
-
e.push({
|
|
343
|
-
id: c,
|
|
344
|
-
role: "assistant",
|
|
345
|
-
parts: [{
|
|
346
|
-
type: "tool_result",
|
|
347
|
-
toolName: s.toolName ?? "",
|
|
348
|
-
toolCallId: s.toolCallId ?? "",
|
|
349
|
-
content: s.content ?? "",
|
|
350
|
-
artifacts: d,
|
|
351
|
-
renderMode: ((n = s.metadata) == null ? void 0 : n.renderMode) ?? ((o = s.metadata) == null ? void 0 : o.render_mode),
|
|
352
|
-
html: (r = s.metadata) == null ? void 0 : r.html
|
|
353
|
-
}],
|
|
354
|
-
timestamp: l
|
|
355
|
-
});
|
|
312
|
+
function O(r) {
|
|
313
|
+
const e = [...r].sort((a, i) => (a.seq ?? 0) - (i.seq ?? 0)), t = /* @__PURE__ */ new Map();
|
|
314
|
+
for (const a of e)
|
|
315
|
+
a.role === "tool" && a.toolCallId && t.set(a.toolCallId, a.content || "");
|
|
316
|
+
const s = /* @__PURE__ */ new Set(), o = [], n = (a, i, c) => {
|
|
317
|
+
const d = o[o.length - 1];
|
|
318
|
+
(d == null ? void 0 : d.role) === "assistant" ? (d.parts.push(...a), d.id = i) : o.push({ id: i, role: "assistant", parts: [...a], timestamp: c });
|
|
319
|
+
};
|
|
320
|
+
for (const a of e) {
|
|
321
|
+
if (a.role === "system") continue;
|
|
322
|
+
const i = a.messageId ?? `msg_${a.id}`, c = new Date(a.createTime ?? "").getTime() || Date.now();
|
|
323
|
+
if (a.role === "human") {
|
|
324
|
+
o.push({ id: i, role: "user", parts: [{ type: "text", content: a.content ?? "" }], timestamp: c });
|
|
325
|
+
continue;
|
|
326
|
+
}
|
|
327
|
+
if (a.role === "ai") {
|
|
328
|
+
const d = P(a, t, s);
|
|
329
|
+
d.length > 0 && n(d, i, c);
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
if (a.role === "tool") {
|
|
333
|
+
if (a.toolCallId && s.has(a.toolCallId)) continue;
|
|
334
|
+
n([v(a)], i, c);
|
|
356
335
|
}
|
|
357
336
|
}
|
|
358
|
-
return
|
|
337
|
+
return o;
|
|
338
|
+
}
|
|
339
|
+
function P(r, e, t) {
|
|
340
|
+
const s = [];
|
|
341
|
+
r.reasoning && s.push({ type: "thinking", content: r.reasoning }), r.content && s.push({ type: "text", content: r.content });
|
|
342
|
+
for (const o of r.toolCalls ?? [])
|
|
343
|
+
o.is_interrupt ? (t.add(o.id), s.push(_(o, e))) : s.push(E(o));
|
|
344
|
+
return s;
|
|
345
|
+
}
|
|
346
|
+
function _(r, e) {
|
|
347
|
+
const t = e.has(r.id), s = typeof r.args == "object" ? r.args : {};
|
|
348
|
+
return {
|
|
349
|
+
type: "interrupt",
|
|
350
|
+
interrupt: {
|
|
351
|
+
interruptId: r.id ?? "",
|
|
352
|
+
interruptType: s.interruptType ?? "input",
|
|
353
|
+
content: s.content ?? "",
|
|
354
|
+
options: s.options,
|
|
355
|
+
placeholder: s.placeholder,
|
|
356
|
+
inputType: s.inputType,
|
|
357
|
+
maxLength: s.maxLength,
|
|
358
|
+
required: s.required,
|
|
359
|
+
fields: s.fields,
|
|
360
|
+
metadata: s.metadata
|
|
361
|
+
},
|
|
362
|
+
resolved: t,
|
|
363
|
+
response: t ? { action: "submit", value: x(e.get(r.id)) } : void 0
|
|
364
|
+
};
|
|
359
365
|
}
|
|
360
|
-
|
|
361
|
-
|
|
366
|
+
function E(r) {
|
|
367
|
+
let e;
|
|
368
|
+
try {
|
|
369
|
+
e = typeof r.args == "string" ? r.args : JSON.stringify(r.args ?? {});
|
|
370
|
+
} catch {
|
|
371
|
+
e = String(r.args ?? "{}");
|
|
372
|
+
}
|
|
373
|
+
return { type: "tool_call", toolName: r.name ?? "", toolCallId: r.id ?? "", args: e };
|
|
374
|
+
}
|
|
375
|
+
function v(r) {
|
|
376
|
+
var t, s, o;
|
|
377
|
+
const e = Array.isArray(r.artifacts) ? r.artifacts : void 0;
|
|
378
|
+
return {
|
|
379
|
+
type: "tool_result",
|
|
380
|
+
toolName: r.toolName ?? "",
|
|
381
|
+
toolCallId: r.toolCallId ?? "",
|
|
382
|
+
content: r.content ?? "",
|
|
383
|
+
artifacts: e,
|
|
384
|
+
renderMode: ((t = r.metadata) == null ? void 0 : t.renderMode) ?? ((s = r.metadata) == null ? void 0 : s.render_mode),
|
|
385
|
+
html: (o = r.metadata) == null ? void 0 : o.html
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
function x(r) {
|
|
389
|
+
if (r != null)
|
|
390
|
+
try {
|
|
391
|
+
return JSON.parse(r);
|
|
392
|
+
} catch {
|
|
393
|
+
return r;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
async function U(r, e, t, s, o, n) {
|
|
397
|
+
const a = await r.streamPost(
|
|
362
398
|
`/chat/interrupt/${e}/respond`,
|
|
363
399
|
{
|
|
364
400
|
sessionId: t,
|
|
365
|
-
action:
|
|
366
|
-
value:
|
|
401
|
+
action: s.action,
|
|
402
|
+
value: s.value
|
|
367
403
|
}
|
|
368
404
|
);
|
|
369
|
-
if (!
|
|
370
|
-
const i = new Error(`HTTP ${
|
|
371
|
-
throw
|
|
405
|
+
if (!a.ok) {
|
|
406
|
+
const i = new Error(`HTTP ${a.status}`);
|
|
407
|
+
throw n == null || n(i), i;
|
|
372
408
|
}
|
|
373
409
|
o && await m(
|
|
374
|
-
|
|
410
|
+
a,
|
|
375
411
|
(i) => {
|
|
376
|
-
i.type === "error" ?
|
|
412
|
+
i.type === "error" ? n == null || n(new Error(i.content)) : o(i);
|
|
377
413
|
},
|
|
378
|
-
(i) =>
|
|
414
|
+
(i) => n == null ? void 0 : n(i)
|
|
379
415
|
);
|
|
380
416
|
}
|
|
381
|
-
function
|
|
382
|
-
|
|
417
|
+
async function q(r) {
|
|
418
|
+
return r.get(`/chat/bots/${r.getBotId()}/skills`);
|
|
419
|
+
}
|
|
420
|
+
async function N(r, e) {
|
|
421
|
+
await r.post("/chat/stop", { sessionId: e });
|
|
422
|
+
}
|
|
423
|
+
function L(r) {
|
|
424
|
+
const e = new w(r);
|
|
383
425
|
return {
|
|
384
426
|
getToken: () => e.fetchToken(),
|
|
385
|
-
createSession: () =>
|
|
386
|
-
chat: (
|
|
387
|
-
listConversations: (
|
|
388
|
-
renameConversation: (
|
|
389
|
-
deleteConversation: (
|
|
390
|
-
getMessages: (
|
|
391
|
-
respondInterrupt: (
|
|
392
|
-
setToken: (
|
|
393
|
-
feedback: async (
|
|
394
|
-
const
|
|
395
|
-
o === "dislike" && ((
|
|
427
|
+
createSession: () => b(e),
|
|
428
|
+
chat: (s) => p(e, s),
|
|
429
|
+
listConversations: (s) => S(e, s),
|
|
430
|
+
renameConversation: (s, o) => $(e, s, o),
|
|
431
|
+
deleteConversation: (s) => C(e, s),
|
|
432
|
+
getMessages: (s) => A(e, s),
|
|
433
|
+
respondInterrupt: (s, o, n, a, i) => U(e, s, o, n, a, i),
|
|
434
|
+
setToken: (s) => e.setToken(s),
|
|
435
|
+
feedback: async (s, o, n) => {
|
|
436
|
+
const a = { type: o };
|
|
437
|
+
o === "dislike" && ((n == null ? void 0 : n.reason) != null && (a.reason = n.reason), n != null && n.remark && (a.remark = n.remark)), await e.post(`/chat/messages/${s}/feedback`, a);
|
|
396
438
|
},
|
|
397
|
-
cancelFeedback: async (
|
|
398
|
-
await e.del(`/chat/messages/${
|
|
399
|
-
}
|
|
439
|
+
cancelFeedback: async (s) => {
|
|
440
|
+
await e.del(`/chat/messages/${s}/feedback`);
|
|
441
|
+
},
|
|
442
|
+
listSkills: () => q(e),
|
|
443
|
+
stopGeneration: (s) => N(e, s)
|
|
400
444
|
};
|
|
401
445
|
}
|
|
402
446
|
export {
|
|
403
|
-
|
|
447
|
+
L as createSuperAgent
|
|
404
448
|
};
|