super-agent-sdk 1.0.6 → 1.0.8
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 +141 -25
- package/dist/index.cjs +4 -4
- package/dist/index.d.ts +19 -3
- package/dist/index.mjs +227 -178
- package/dist/widget.cjs +239 -35
- package/dist/widget.d.ts +51 -12
- package/dist/widget.mjs +1864 -1106
- 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, (a, n) => n.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 a = u(o.data);
|
|
46
|
+
return this.token = a.token, a.appId && !this.appId && (this.appId = a.appId), a.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 a = 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 (a.status === 401 && !(s != null && s.retry) && await this.handleTokenRefresh())
|
|
86
|
+
return this.request(e, t, { ...s, retry: !0 });
|
|
87
|
+
if (!a.ok)
|
|
88
|
+
throw new Error(`HTTP ${a.status}: ${a.statusText}`);
|
|
89
|
+
const n = await a.json();
|
|
90
|
+
if (n.code !== "200")
|
|
91
|
+
throw new Error(n.message || `API error: ${n.code}`);
|
|
92
|
+
return u(n.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}`, a = 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 a.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
|
+
}) : a;
|
|
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,13 @@ 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
|
+
messageId: t.messageId ?? t.message_id
|
|
175
|
+
};
|
|
169
176
|
case "error":
|
|
170
177
|
return { type: "error", content: t.message ?? "Unknown error" };
|
|
171
178
|
case "interrupt":
|
|
@@ -189,216 +196,258 @@ function y(a) {
|
|
|
189
196
|
return null;
|
|
190
197
|
}
|
|
191
198
|
}
|
|
192
|
-
async function m(
|
|
193
|
-
if (!
|
|
199
|
+
async function m(r, e, t) {
|
|
200
|
+
if (!r.body) {
|
|
194
201
|
t(new Error("Response body is null"));
|
|
195
202
|
return;
|
|
196
203
|
}
|
|
197
|
-
const
|
|
198
|
-
let
|
|
204
|
+
const s = r.body.getReader(), o = new TextDecoder();
|
|
205
|
+
let a = "";
|
|
199
206
|
try {
|
|
200
207
|
for (; ; ) {
|
|
201
|
-
const { value:
|
|
208
|
+
const { value: n, done: i } = await s.read();
|
|
202
209
|
if (i) break;
|
|
203
|
-
|
|
210
|
+
a += o.decode(n, { stream: !0 });
|
|
204
211
|
let c;
|
|
205
|
-
for (; (c =
|
|
212
|
+
for (; (c = a.indexOf(`
|
|
206
213
|
|
|
207
214
|
`)) !== -1; ) {
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
const
|
|
211
|
-
|
|
215
|
+
const d = a.slice(0, c);
|
|
216
|
+
a = a.slice(c + 2);
|
|
217
|
+
const l = y(d);
|
|
218
|
+
l && e(l);
|
|
212
219
|
}
|
|
213
220
|
}
|
|
214
|
-
if (
|
|
215
|
-
const
|
|
216
|
-
|
|
221
|
+
if (a.trim()) {
|
|
222
|
+
const n = y(a);
|
|
223
|
+
n && e(n);
|
|
217
224
|
}
|
|
218
|
-
} catch (
|
|
219
|
-
(
|
|
225
|
+
} catch (n) {
|
|
226
|
+
(n == null ? void 0 : n.name) !== "AbortError" && t(n instanceof Error ? n : new Error(String(n)));
|
|
220
227
|
} finally {
|
|
221
228
|
try {
|
|
222
|
-
|
|
229
|
+
s.releaseLock();
|
|
223
230
|
} catch {
|
|
224
231
|
}
|
|
225
232
|
}
|
|
226
233
|
}
|
|
227
|
-
function
|
|
228
|
-
const t = new AbortController(),
|
|
229
|
-
botId:
|
|
234
|
+
function p(r, e) {
|
|
235
|
+
const t = new AbortController(), s = e.signal ? T(e.signal, t.signal) : t.signal, o = {
|
|
236
|
+
botId: r.getBotId(),
|
|
230
237
|
message: e.message,
|
|
231
238
|
sessionId: e.sessionId,
|
|
232
239
|
stream: e.stream !== !1
|
|
233
240
|
};
|
|
234
|
-
return o.stream ?
|
|
235
|
-
var
|
|
236
|
-
if (!
|
|
237
|
-
(
|
|
241
|
+
return o.stream ? r.streamPost("/chat", o, s).then((a) => {
|
|
242
|
+
var n;
|
|
243
|
+
if (!a.ok) {
|
|
244
|
+
(n = e.onError) == null || n.call(e, new Error(`HTTP ${a.status}`));
|
|
238
245
|
return;
|
|
239
246
|
}
|
|
240
247
|
return m(
|
|
241
|
-
|
|
248
|
+
a,
|
|
242
249
|
(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" ? (
|
|
250
|
+
var c, d, l, h, f, g;
|
|
251
|
+
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, messageId: i.messageId })) : i.type === "error" ? (f = e.onError) == null || f.call(e, new Error(i.content)) : (g = e.onMessage) == null || g.call(e, i);
|
|
245
252
|
},
|
|
246
253
|
(i) => {
|
|
247
254
|
var c;
|
|
248
255
|
return (c = e.onError) == null ? void 0 : c.call(e, i);
|
|
249
256
|
}
|
|
250
257
|
);
|
|
251
|
-
}).catch((
|
|
252
|
-
var
|
|
253
|
-
(
|
|
254
|
-
}) :
|
|
255
|
-
var
|
|
256
|
-
(
|
|
257
|
-
sessionId:
|
|
258
|
-
content:
|
|
259
|
-
messageId:
|
|
258
|
+
}).catch((a) => {
|
|
259
|
+
var n;
|
|
260
|
+
(a == null ? void 0 : a.name) !== "AbortError" && ((n = e.onError) == null || n.call(e, a instanceof Error ? a : new Error(String(a))));
|
|
261
|
+
}) : r.post("/chat", o).then((a) => {
|
|
262
|
+
var n;
|
|
263
|
+
(n = e.onDone) == null || n.call(e, {
|
|
264
|
+
sessionId: a.sessionId,
|
|
265
|
+
content: a.content ?? "",
|
|
266
|
+
messageId: a.messageId
|
|
260
267
|
});
|
|
261
|
-
}).catch((
|
|
262
|
-
var
|
|
263
|
-
(
|
|
268
|
+
}).catch((a) => {
|
|
269
|
+
var n;
|
|
270
|
+
(n = e.onError) == null || n.call(e, a instanceof Error ? a : new Error(String(a)));
|
|
264
271
|
}), t;
|
|
265
272
|
}
|
|
266
|
-
function
|
|
267
|
-
const t = new AbortController(),
|
|
268
|
-
return
|
|
273
|
+
function T(r, e) {
|
|
274
|
+
const t = new AbortController(), s = () => t.abort();
|
|
275
|
+
return r.addEventListener("abort", s, { once: !0 }), e.addEventListener("abort", s, { once: !0 }), (r.aborted || e.aborted) && t.abort(), t.signal;
|
|
269
276
|
}
|
|
270
|
-
async function
|
|
271
|
-
return (await
|
|
272
|
-
botId:
|
|
277
|
+
async function b(r) {
|
|
278
|
+
return (await r.post("/chat/sessions", {
|
|
279
|
+
botId: r.getBotId()
|
|
273
280
|
})).sessionId;
|
|
274
281
|
}
|
|
275
|
-
function
|
|
282
|
+
function k(r) {
|
|
276
283
|
return {
|
|
277
284
|
// 后端返回 thread_id,toCamelCase 转为 threadId,映射为 sessionId
|
|
278
|
-
sessionId:
|
|
279
|
-
botId:
|
|
280
|
-
title:
|
|
281
|
-
createTime:
|
|
282
|
-
updateTime:
|
|
285
|
+
sessionId: r.threadId ?? r.sessionId,
|
|
286
|
+
botId: r.botId,
|
|
287
|
+
title: r.title,
|
|
288
|
+
createTime: r.createTime,
|
|
289
|
+
updateTime: r.updateTime
|
|
283
290
|
};
|
|
284
291
|
}
|
|
285
|
-
async function
|
|
286
|
-
const t = await
|
|
287
|
-
botId:
|
|
292
|
+
async function S(r, e) {
|
|
293
|
+
const t = await r.get("/chat/conversations", {
|
|
294
|
+
botId: r.getBotId(),
|
|
288
295
|
page: (e == null ? void 0 : e.page) ?? 1,
|
|
289
296
|
size: (e == null ? void 0 : e.size) ?? 20
|
|
290
297
|
});
|
|
291
298
|
return {
|
|
292
299
|
...t,
|
|
293
|
-
items: t.items.map(
|
|
300
|
+
items: t.items.map(k)
|
|
294
301
|
};
|
|
295
302
|
}
|
|
296
|
-
async function
|
|
297
|
-
await
|
|
303
|
+
async function $(r, e, t) {
|
|
304
|
+
await r.patch(`/chat/conversations/${e}`, { title: t });
|
|
298
305
|
}
|
|
299
|
-
async function
|
|
300
|
-
await
|
|
306
|
+
async function C(r, e) {
|
|
307
|
+
await r.del(`/chat/conversations/${e}`);
|
|
301
308
|
}
|
|
302
|
-
async function
|
|
303
|
-
const t = await
|
|
309
|
+
async function A(r, e) {
|
|
310
|
+
const t = await r.get(`/chat/conversations/${e}/messages`);
|
|
304
311
|
return O(t);
|
|
305
312
|
}
|
|
306
|
-
function O(
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
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
|
-
});
|
|
313
|
+
function O(r) {
|
|
314
|
+
const e = [...r].sort((n, i) => {
|
|
315
|
+
const c = new Date(n.createTime ?? 0).getTime() || 0, d = new Date(i.createTime ?? 0).getTime() || 0;
|
|
316
|
+
return c !== d ? c - d : (n.seq ?? 0) - (i.seq ?? 0);
|
|
317
|
+
}), t = /* @__PURE__ */ new Map();
|
|
318
|
+
for (const n of e)
|
|
319
|
+
n.role === "tool" && n.toolCallId && t.set(n.toolCallId, n.content || "");
|
|
320
|
+
const s = /* @__PURE__ */ new Set(), o = [], a = (n, i, c) => {
|
|
321
|
+
const d = o[o.length - 1];
|
|
322
|
+
(d == null ? void 0 : d.role) === "assistant" ? (d.parts.push(...n), d.id = i) : o.push({ id: i, role: "assistant", parts: [...n], timestamp: c });
|
|
323
|
+
};
|
|
324
|
+
for (const n of e) {
|
|
325
|
+
if (n.role === "system") continue;
|
|
326
|
+
const i = String(n.id ?? n.messageId ?? `msg_${Date.now()}`), c = new Date(n.createTime ?? "").getTime() || Date.now();
|
|
327
|
+
if (n.role === "human") {
|
|
328
|
+
o.push({ id: i, role: "user", parts: [{ type: "text", content: n.content ?? "" }], timestamp: c });
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
if (n.role === "ai") {
|
|
332
|
+
const d = _(n, t, s);
|
|
333
|
+
d.length > 0 && a(d, i, c);
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
336
|
+
if (n.role === "tool") {
|
|
337
|
+
if (n.toolCallId && s.has(n.toolCallId)) continue;
|
|
338
|
+
a([v(n)], i, c);
|
|
356
339
|
}
|
|
357
340
|
}
|
|
358
|
-
return
|
|
341
|
+
return o;
|
|
342
|
+
}
|
|
343
|
+
function _(r, e, t) {
|
|
344
|
+
const s = [];
|
|
345
|
+
r.reasoning && s.push({ type: "thinking", content: r.reasoning }), r.content && s.push({ type: "text", content: r.content });
|
|
346
|
+
for (const o of r.toolCalls ?? [])
|
|
347
|
+
o.is_interrupt ? (t.add(o.id), s.push(P(o, e))) : s.push(E(o));
|
|
348
|
+
return s;
|
|
359
349
|
}
|
|
360
|
-
|
|
361
|
-
const s =
|
|
350
|
+
function P(r, e) {
|
|
351
|
+
const t = e.has(r.id), s = typeof r.args == "object" ? r.args : {};
|
|
352
|
+
return {
|
|
353
|
+
type: "interrupt",
|
|
354
|
+
interrupt: {
|
|
355
|
+
interruptId: r.id ?? "",
|
|
356
|
+
interruptType: s.interruptType ?? "input",
|
|
357
|
+
content: s.content ?? "",
|
|
358
|
+
options: s.options,
|
|
359
|
+
placeholder: s.placeholder,
|
|
360
|
+
inputType: s.inputType,
|
|
361
|
+
maxLength: s.maxLength,
|
|
362
|
+
required: s.required,
|
|
363
|
+
fields: s.fields,
|
|
364
|
+
metadata: s.metadata
|
|
365
|
+
},
|
|
366
|
+
resolved: t,
|
|
367
|
+
response: t ? { action: "submit", value: x(e.get(r.id)) } : void 0
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
function E(r) {
|
|
371
|
+
let e;
|
|
372
|
+
try {
|
|
373
|
+
e = typeof r.args == "string" ? r.args : JSON.stringify(r.args ?? {});
|
|
374
|
+
} catch {
|
|
375
|
+
e = String(r.args ?? "{}");
|
|
376
|
+
}
|
|
377
|
+
return { type: "tool_call", toolName: r.name ?? "", toolCallId: r.id ?? "", args: e };
|
|
378
|
+
}
|
|
379
|
+
function v(r) {
|
|
380
|
+
var t, s, o;
|
|
381
|
+
const e = Array.isArray(r.artifacts) ? r.artifacts : void 0;
|
|
382
|
+
return {
|
|
383
|
+
type: "tool_result",
|
|
384
|
+
toolName: r.toolName ?? "",
|
|
385
|
+
toolCallId: r.toolCallId ?? "",
|
|
386
|
+
content: r.content ?? "",
|
|
387
|
+
artifacts: e,
|
|
388
|
+
renderMode: ((t = r.metadata) == null ? void 0 : t.renderMode) ?? ((s = r.metadata) == null ? void 0 : s.render_mode),
|
|
389
|
+
html: (o = r.metadata) == null ? void 0 : o.html
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
function x(r) {
|
|
393
|
+
if (r != null)
|
|
394
|
+
try {
|
|
395
|
+
return JSON.parse(r);
|
|
396
|
+
} catch {
|
|
397
|
+
return r;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
async function U(r, e, t, s, o, a) {
|
|
401
|
+
const n = await r.streamPost(
|
|
362
402
|
`/chat/interrupt/${e}/respond`,
|
|
363
403
|
{
|
|
364
404
|
sessionId: t,
|
|
365
|
-
action:
|
|
366
|
-
value:
|
|
405
|
+
action: s.action,
|
|
406
|
+
value: s.value
|
|
367
407
|
}
|
|
368
408
|
);
|
|
369
|
-
if (!
|
|
370
|
-
const i = new Error(`HTTP ${
|
|
371
|
-
throw
|
|
409
|
+
if (!n.ok) {
|
|
410
|
+
const i = new Error(`HTTP ${n.status}`);
|
|
411
|
+
throw a == null || a(i), i;
|
|
372
412
|
}
|
|
373
413
|
o && await m(
|
|
374
|
-
|
|
414
|
+
n,
|
|
375
415
|
(i) => {
|
|
376
|
-
i.type === "error" ?
|
|
416
|
+
i.type === "error" ? a == null || a(new Error(i.content)) : o(i);
|
|
377
417
|
},
|
|
378
|
-
(i) =>
|
|
418
|
+
(i) => a == null ? void 0 : a(i)
|
|
379
419
|
);
|
|
380
420
|
}
|
|
381
|
-
function
|
|
382
|
-
|
|
421
|
+
async function D(r) {
|
|
422
|
+
return r.get(`/chat/bots/${r.getBotId()}/skills`);
|
|
423
|
+
}
|
|
424
|
+
async function q(r, e) {
|
|
425
|
+
await r.post("/chat/stop", { sessionId: e });
|
|
426
|
+
}
|
|
427
|
+
function N(r) {
|
|
428
|
+
const e = new w(r);
|
|
383
429
|
return {
|
|
430
|
+
botId: e.getBotId(),
|
|
384
431
|
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" && ((
|
|
432
|
+
createSession: () => b(e),
|
|
433
|
+
chat: (s) => p(e, s),
|
|
434
|
+
listConversations: (s) => S(e, s),
|
|
435
|
+
renameConversation: (s, o) => $(e, s, o),
|
|
436
|
+
deleteConversation: (s) => C(e, s),
|
|
437
|
+
getMessages: (s) => A(e, s),
|
|
438
|
+
respondInterrupt: (s, o, a, n, i) => U(e, s, o, a, n, i),
|
|
439
|
+
setToken: (s) => e.setToken(s),
|
|
440
|
+
feedback: async (s, o, a) => {
|
|
441
|
+
const n = { type: o };
|
|
442
|
+
o === "dislike" && ((a == null ? void 0 : a.reason) != null && (n.reason = a.reason), a != null && a.remark && (n.remark = a.remark)), await e.post(`/chat/messages/${s}/feedback`, n);
|
|
396
443
|
},
|
|
397
|
-
cancelFeedback: async (
|
|
398
|
-
await e.del(`/chat/messages/${
|
|
399
|
-
}
|
|
444
|
+
cancelFeedback: async (s) => {
|
|
445
|
+
await e.del(`/chat/messages/${s}/feedback`);
|
|
446
|
+
},
|
|
447
|
+
listSkills: () => D(e),
|
|
448
|
+
stopGeneration: (s) => q(e, s)
|
|
400
449
|
};
|
|
401
450
|
}
|
|
402
451
|
export {
|
|
403
|
-
|
|
452
|
+
N as createSuperAgent
|
|
404
453
|
};
|