super-agent-sdk 1.0.5 → 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 +84 -31
- package/dist/index.cjs +4 -4
- package/dist/index.d.ts +12 -1
- package/dist/index.mjs +222 -177
- package/dist/widget.cjs +197 -36
- package/dist/widget.d.ts +40 -8
- package/dist/widget.mjs +1712 -1135
- package/package.json +3 -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,215 +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:
|
|
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
|
|
259
266
|
});
|
|
260
|
-
}).catch((
|
|
261
|
-
var
|
|
262
|
-
(
|
|
267
|
+
}).catch((n) => {
|
|
268
|
+
var a;
|
|
269
|
+
(a = e.onError) == null || a.call(e, n instanceof Error ? n : new Error(String(n)));
|
|
263
270
|
}), t;
|
|
264
271
|
}
|
|
265
|
-
function
|
|
266
|
-
const t = new AbortController(),
|
|
267
|
-
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;
|
|
268
275
|
}
|
|
269
|
-
async function
|
|
270
|
-
return (await
|
|
271
|
-
botId:
|
|
276
|
+
async function b(r) {
|
|
277
|
+
return (await r.post("/chat/sessions", {
|
|
278
|
+
botId: r.getBotId()
|
|
272
279
|
})).sessionId;
|
|
273
280
|
}
|
|
274
|
-
function
|
|
281
|
+
function T(r) {
|
|
275
282
|
return {
|
|
276
283
|
// 后端返回 thread_id,toCamelCase 转为 threadId,映射为 sessionId
|
|
277
|
-
sessionId:
|
|
278
|
-
botId:
|
|
279
|
-
title:
|
|
280
|
-
createTime:
|
|
281
|
-
updateTime:
|
|
284
|
+
sessionId: r.threadId ?? r.sessionId,
|
|
285
|
+
botId: r.botId,
|
|
286
|
+
title: r.title,
|
|
287
|
+
createTime: r.createTime,
|
|
288
|
+
updateTime: r.updateTime
|
|
282
289
|
};
|
|
283
290
|
}
|
|
284
|
-
async function
|
|
285
|
-
const t = await
|
|
286
|
-
botId:
|
|
291
|
+
async function S(r, e) {
|
|
292
|
+
const t = await r.get("/chat/conversations", {
|
|
293
|
+
botId: r.getBotId(),
|
|
287
294
|
page: (e == null ? void 0 : e.page) ?? 1,
|
|
288
295
|
size: (e == null ? void 0 : e.size) ?? 20
|
|
289
296
|
});
|
|
290
297
|
return {
|
|
291
298
|
...t,
|
|
292
|
-
items: t.items.map(
|
|
299
|
+
items: t.items.map(T)
|
|
293
300
|
};
|
|
294
301
|
}
|
|
295
|
-
async function
|
|
296
|
-
await
|
|
302
|
+
async function $(r, e, t) {
|
|
303
|
+
await r.patch(`/chat/conversations/${e}`, { title: t });
|
|
297
304
|
}
|
|
298
|
-
async function
|
|
299
|
-
await
|
|
305
|
+
async function C(r, e) {
|
|
306
|
+
await r.del(`/chat/conversations/${e}`);
|
|
300
307
|
}
|
|
301
|
-
async function
|
|
302
|
-
const t = await
|
|
308
|
+
async function A(r, e) {
|
|
309
|
+
const t = await r.get(`/chat/conversations/${e}/messages`);
|
|
303
310
|
return O(t);
|
|
304
311
|
}
|
|
305
|
-
function O(
|
|
306
|
-
|
|
307
|
-
const
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
} catch {
|
|
329
|
-
g = String(u.args ?? "{}");
|
|
330
|
-
}
|
|
331
|
-
d.push({
|
|
332
|
-
type: "tool_call",
|
|
333
|
-
toolName: u.name ?? "",
|
|
334
|
-
toolCallId: u.id ?? "",
|
|
335
|
-
args: g
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
e.push({ id: c, role: "assistant", parts: d, timestamp: l });
|
|
339
|
-
} else if (i === "tool") {
|
|
340
|
-
const d = Array.isArray(s.artifacts) ? s.artifacts : void 0;
|
|
341
|
-
e.push({
|
|
342
|
-
id: c,
|
|
343
|
-
role: "assistant",
|
|
344
|
-
parts: [{
|
|
345
|
-
type: "tool_result",
|
|
346
|
-
toolName: s.toolName ?? "",
|
|
347
|
-
toolCallId: s.toolCallId ?? "",
|
|
348
|
-
content: s.content ?? "",
|
|
349
|
-
artifacts: d,
|
|
350
|
-
renderMode: ((n = s.metadata) == null ? void 0 : n.renderMode) ?? ((o = s.metadata) == null ? void 0 : o.render_mode),
|
|
351
|
-
html: (r = s.metadata) == null ? void 0 : r.html
|
|
352
|
-
}],
|
|
353
|
-
timestamp: l
|
|
354
|
-
});
|
|
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);
|
|
355
335
|
}
|
|
356
336
|
}
|
|
357
|
-
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
|
+
};
|
|
358
365
|
}
|
|
359
|
-
|
|
360
|
-
|
|
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(
|
|
361
398
|
`/chat/interrupt/${e}/respond`,
|
|
362
399
|
{
|
|
363
400
|
sessionId: t,
|
|
364
|
-
action:
|
|
365
|
-
value:
|
|
401
|
+
action: s.action,
|
|
402
|
+
value: s.value
|
|
366
403
|
}
|
|
367
404
|
);
|
|
368
|
-
if (!
|
|
369
|
-
const i = new Error(`HTTP ${
|
|
370
|
-
throw
|
|
405
|
+
if (!a.ok) {
|
|
406
|
+
const i = new Error(`HTTP ${a.status}`);
|
|
407
|
+
throw n == null || n(i), i;
|
|
371
408
|
}
|
|
372
409
|
o && await m(
|
|
373
|
-
|
|
410
|
+
a,
|
|
374
411
|
(i) => {
|
|
375
|
-
i.type === "error" ?
|
|
412
|
+
i.type === "error" ? n == null || n(new Error(i.content)) : o(i);
|
|
376
413
|
},
|
|
377
|
-
(i) =>
|
|
414
|
+
(i) => n == null ? void 0 : n(i)
|
|
378
415
|
);
|
|
379
416
|
}
|
|
380
|
-
function
|
|
381
|
-
|
|
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);
|
|
382
425
|
return {
|
|
383
426
|
getToken: () => e.fetchToken(),
|
|
384
|
-
createSession: () =>
|
|
385
|
-
chat: (
|
|
386
|
-
listConversations: (
|
|
387
|
-
renameConversation: (
|
|
388
|
-
deleteConversation: (
|
|
389
|
-
getMessages: (
|
|
390
|
-
respondInterrupt: (
|
|
391
|
-
setToken: (
|
|
392
|
-
feedback: async (
|
|
393
|
-
const
|
|
394
|
-
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);
|
|
395
438
|
},
|
|
396
|
-
cancelFeedback: async (
|
|
397
|
-
await e.del(`/chat/messages/${
|
|
398
|
-
}
|
|
439
|
+
cancelFeedback: async (s) => {
|
|
440
|
+
await e.del(`/chat/messages/${s}/feedback`);
|
|
441
|
+
},
|
|
442
|
+
listSkills: () => q(e),
|
|
443
|
+
stopGeneration: (s) => N(e, s)
|
|
399
444
|
};
|
|
400
445
|
}
|
|
401
446
|
export {
|
|
402
|
-
|
|
447
|
+
L as createSuperAgent
|
|
403
448
|
};
|