super-agent-sdk 1.0.9 → 1.0.11
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 +170 -6
- package/dist/index.cjs +4 -4
- package/dist/index.d.ts +40 -0
- package/dist/index.mjs +204 -170
- package/dist/{mammoth.browser-DiAPPO3x.cjs → mammoth.browser-BX8glWVC.cjs} +24 -24
- package/dist/{mammoth.browser-COPV53yV.js → mammoth.browser-Czw2m8xL.js} +133 -139
- package/dist/nosUploader-C94D61NK.js +4712 -0
- package/dist/nosUploader-KkzFK5EW.cjs +13 -0
- package/dist/widget.cjs +52 -28
- package/dist/widget.d.ts +126 -8
- package/dist/widget.mjs +1678 -1401
- package/package.json +5 -1
package/dist/index.mjs
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { c as J } from "./nosUploader-C94D61NK.js";
|
|
2
|
+
function h(r) {
|
|
3
|
+
if (Array.isArray(r)) return r.map((e) => h(e));
|
|
3
4
|
if (r && typeof r == "object" && r.constructor === Object) {
|
|
4
5
|
const e = {};
|
|
5
|
-
for (const [t,
|
|
6
|
-
const
|
|
7
|
-
e[
|
|
6
|
+
for (const [t, n] of Object.entries(r)) {
|
|
7
|
+
const i = t.replace(/_([a-z])/g, (a, s) => s.toUpperCase());
|
|
8
|
+
e[i] = h(n);
|
|
8
9
|
}
|
|
9
10
|
return e;
|
|
10
11
|
}
|
|
11
12
|
return r;
|
|
12
13
|
}
|
|
13
|
-
const
|
|
14
|
-
class
|
|
14
|
+
const w = "/api/agent/runtime/v1";
|
|
15
|
+
class T {
|
|
15
16
|
constructor(e) {
|
|
16
17
|
this.refreshing = null;
|
|
17
|
-
const t = e.baseUrl ??
|
|
18
|
+
const t = e.baseUrl ?? w;
|
|
18
19
|
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
20
|
}
|
|
20
21
|
getBotId() {
|
|
@@ -32,17 +33,17 @@ class w {
|
|
|
32
33
|
}
|
|
33
34
|
/** POST {origin}{tokenGateway}/v1/token — 获取 token + appId */
|
|
34
35
|
async fetchToken() {
|
|
35
|
-
const t = `${this.isAbsoluteGateway ? this.tokenGateway : `${this.getOrigin()}${this.tokenGateway}`}/v1/token`,
|
|
36
|
+
const t = `${this.isAbsoluteGateway ? this.tokenGateway : `${this.getOrigin()}${this.tokenGateway}`}/v1/token`, n = await fetch(t, {
|
|
36
37
|
method: "POST",
|
|
37
38
|
headers: { "Content-Type": "application/json" },
|
|
38
39
|
body: JSON.stringify({ botId: this.botId })
|
|
39
40
|
});
|
|
40
|
-
if (!
|
|
41
|
-
throw new Error(`HTTP ${
|
|
42
|
-
const
|
|
43
|
-
if (
|
|
44
|
-
throw new Error(
|
|
45
|
-
const a =
|
|
41
|
+
if (!n.ok)
|
|
42
|
+
throw new Error(`HTTP ${n.status}: ${n.statusText}`);
|
|
43
|
+
const i = await n.json();
|
|
44
|
+
if (i.code !== "200")
|
|
45
|
+
throw new Error(i.message || `API error: ${i.code}`);
|
|
46
|
+
const a = h(i.data);
|
|
46
47
|
return this.token = a.token, a.appId && !this.appId && (this.appId = a.appId), a.token;
|
|
47
48
|
}
|
|
48
49
|
headers(e) {
|
|
@@ -66,30 +67,30 @@ class w {
|
|
|
66
67
|
this.refreshing = null;
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
|
-
async request(e, t,
|
|
70
|
+
async request(e, t, n) {
|
|
70
71
|
if (!this.token && !await this.handleTokenRefresh())
|
|
71
72
|
throw new Error("SDK token not available: POST /token failed");
|
|
72
|
-
let
|
|
73
|
-
if (
|
|
74
|
-
const
|
|
75
|
-
for (const [d, l] of Object.entries(
|
|
76
|
-
l != null &&
|
|
77
|
-
const c =
|
|
78
|
-
c && (
|
|
73
|
+
let i = this.isAbsoluteUrl ? `${this.baseUrl}${t}` : `${this.getOrigin()}${this.baseUrl}${t}`;
|
|
74
|
+
if (n != null && n.params) {
|
|
75
|
+
const o = new URLSearchParams();
|
|
76
|
+
for (const [d, l] of Object.entries(n.params))
|
|
77
|
+
l != null && o.set(d, String(l));
|
|
78
|
+
const c = o.toString();
|
|
79
|
+
c && (i += `?${c}`);
|
|
79
80
|
}
|
|
80
|
-
const a = await fetch(
|
|
81
|
+
const a = await fetch(i, {
|
|
81
82
|
method: e,
|
|
82
83
|
headers: this.headers(),
|
|
83
|
-
body:
|
|
84
|
+
body: n != null && n.body ? JSON.stringify(n.body) : void 0
|
|
84
85
|
});
|
|
85
|
-
if (a.status === 401 && !(
|
|
86
|
-
return this.request(e, t, { ...
|
|
86
|
+
if (a.status === 401 && !(n != null && n.retry) && await this.handleTokenRefresh())
|
|
87
|
+
return this.request(e, t, { ...n, retry: !0 });
|
|
87
88
|
if (!a.ok)
|
|
88
89
|
throw new Error(`HTTP ${a.status}: ${a.statusText}`);
|
|
89
|
-
const
|
|
90
|
-
if (
|
|
91
|
-
throw new Error(
|
|
92
|
-
return
|
|
90
|
+
const s = await a.json();
|
|
91
|
+
if (s.code !== "200")
|
|
92
|
+
throw new Error(s.message || `API error: ${s.code}`);
|
|
93
|
+
return h(s.data);
|
|
93
94
|
}
|
|
94
95
|
get(e, t) {
|
|
95
96
|
return this.request("GET", e, { params: t });
|
|
@@ -104,26 +105,36 @@ class w {
|
|
|
104
105
|
return this.request("DELETE", e);
|
|
105
106
|
}
|
|
106
107
|
/** For SSE streaming — returns raw Response (no envelope unwrap) */
|
|
107
|
-
async streamPost(e, t,
|
|
108
|
+
async streamPost(e, t, n) {
|
|
108
109
|
if (!this.token && !await this.handleTokenRefresh())
|
|
109
110
|
throw new Error("SDK token not available: POST /token failed");
|
|
110
|
-
const
|
|
111
|
+
const i = this.isAbsoluteUrl ? `${this.baseUrl}${e}` : `${this.getOrigin()}${this.baseUrl}${e}`, a = await fetch(i, {
|
|
111
112
|
method: "POST",
|
|
112
113
|
headers: this.headers(),
|
|
113
114
|
body: JSON.stringify(t),
|
|
114
|
-
signal:
|
|
115
|
+
signal: n
|
|
115
116
|
});
|
|
116
|
-
return a.status === 401 && await this.handleTokenRefresh() ? fetch(
|
|
117
|
+
return a.status === 401 && await this.handleTokenRefresh() ? fetch(i, {
|
|
117
118
|
method: "POST",
|
|
118
119
|
headers: this.headers(),
|
|
119
120
|
body: JSON.stringify(t),
|
|
120
|
-
signal:
|
|
121
|
+
signal: n
|
|
121
122
|
}) : a;
|
|
122
123
|
}
|
|
123
124
|
}
|
|
124
|
-
function
|
|
125
|
+
function u(r) {
|
|
126
|
+
return typeof r == "string" ? r : Array.isArray(r) ? r.map((e) => {
|
|
127
|
+
if (typeof e == "string") return e;
|
|
128
|
+
if (e && typeof e == "object") {
|
|
129
|
+
if (typeof e.text == "string") return e.text;
|
|
130
|
+
if (e.type) return `[${e.type}${e.mime_type ? ": " + e.mime_type : ""}]`;
|
|
131
|
+
}
|
|
132
|
+
return "";
|
|
133
|
+
}).join("") : r == null ? "" : String(r);
|
|
134
|
+
}
|
|
135
|
+
function I(r) {
|
|
125
136
|
const e = r.split(`
|
|
126
|
-
`).map((
|
|
137
|
+
`).map((n) => n.trim()).filter((n) => n.startsWith("data:")).map((n) => n.slice(5).trim());
|
|
127
138
|
if (!e.length) return null;
|
|
128
139
|
let t;
|
|
129
140
|
try {
|
|
@@ -134,11 +145,11 @@ function y(r) {
|
|
|
134
145
|
}
|
|
135
146
|
switch (t.type) {
|
|
136
147
|
case "user":
|
|
137
|
-
return { type: "user", content: t.content
|
|
148
|
+
return { type: "user", content: u(t.content) };
|
|
138
149
|
case "thinking":
|
|
139
|
-
return { type: "thinking", content: t.content
|
|
150
|
+
return { type: "thinking", content: u(t.content) };
|
|
140
151
|
case "ai":
|
|
141
|
-
return { type: "ai", content: t.content
|
|
152
|
+
return { type: "ai", content: u(t.content) };
|
|
142
153
|
case "tool_call":
|
|
143
154
|
return {
|
|
144
155
|
type: "tool_call",
|
|
@@ -150,7 +161,7 @@ function y(r) {
|
|
|
150
161
|
case "tool_result":
|
|
151
162
|
return {
|
|
152
163
|
type: "tool_result",
|
|
153
|
-
content: t.output
|
|
164
|
+
content: u(t.output),
|
|
154
165
|
toolName: t.name,
|
|
155
166
|
toolCallId: t.id,
|
|
156
167
|
// 通用 artifacts(type + data),原样透传
|
|
@@ -162,14 +173,14 @@ function y(r) {
|
|
|
162
173
|
case "done":
|
|
163
174
|
return {
|
|
164
175
|
type: "done",
|
|
165
|
-
content: t.content
|
|
176
|
+
content: u(t.content),
|
|
166
177
|
sessionId: t.sessionId ?? t.session_id ?? "",
|
|
167
178
|
messageId: t.messageId ?? t.message_id
|
|
168
179
|
};
|
|
169
180
|
case "stop":
|
|
170
181
|
return {
|
|
171
182
|
type: "stop",
|
|
172
|
-
content: t.content
|
|
183
|
+
content: u(t.content),
|
|
173
184
|
sessionId: t.sessionId ?? t.session_id ?? "",
|
|
174
185
|
messageId: t.messageId ?? t.message_id
|
|
175
186
|
};
|
|
@@ -196,90 +207,95 @@ function y(r) {
|
|
|
196
207
|
return null;
|
|
197
208
|
}
|
|
198
209
|
}
|
|
199
|
-
async function
|
|
210
|
+
async function p(r, e, t) {
|
|
200
211
|
if (!r.body) {
|
|
201
212
|
t(new Error("Response body is null"));
|
|
202
213
|
return;
|
|
203
214
|
}
|
|
204
|
-
const
|
|
215
|
+
const n = r.body.getReader(), i = new TextDecoder();
|
|
205
216
|
let a = "";
|
|
206
217
|
try {
|
|
207
218
|
for (; ; ) {
|
|
208
|
-
const { value:
|
|
209
|
-
if (
|
|
210
|
-
a +=
|
|
219
|
+
const { value: s, done: o } = await n.read();
|
|
220
|
+
if (o) break;
|
|
221
|
+
a += i.decode(s, { stream: !0 });
|
|
211
222
|
let c;
|
|
212
223
|
for (; (c = a.indexOf(`
|
|
213
224
|
|
|
214
225
|
`)) !== -1; ) {
|
|
215
226
|
const d = a.slice(0, c);
|
|
216
227
|
a = a.slice(c + 2);
|
|
217
|
-
const l =
|
|
228
|
+
const l = I(d);
|
|
218
229
|
l && e(l);
|
|
219
230
|
}
|
|
220
231
|
}
|
|
221
232
|
if (a.trim()) {
|
|
222
|
-
const
|
|
223
|
-
|
|
233
|
+
const s = I(a);
|
|
234
|
+
s && e(s);
|
|
224
235
|
}
|
|
225
|
-
} catch (
|
|
226
|
-
(
|
|
236
|
+
} catch (s) {
|
|
237
|
+
(s == null ? void 0 : s.name) !== "AbortError" && t(s instanceof Error ? s : new Error(String(s)));
|
|
227
238
|
} finally {
|
|
228
239
|
try {
|
|
229
|
-
|
|
240
|
+
n.releaseLock();
|
|
230
241
|
} catch {
|
|
231
242
|
}
|
|
232
243
|
}
|
|
233
244
|
}
|
|
234
|
-
function
|
|
235
|
-
|
|
245
|
+
function k(r, e) {
|
|
246
|
+
var a;
|
|
247
|
+
const t = new AbortController(), n = e.signal ? b(e.signal, t.signal) : t.signal, i = {
|
|
236
248
|
botId: r.getBotId(),
|
|
237
249
|
message: e.message,
|
|
238
250
|
sessionId: e.sessionId,
|
|
239
|
-
stream: e.stream !== !1
|
|
251
|
+
stream: e.stream !== !1,
|
|
252
|
+
// url 仅前端回显(下载/预览),剥离后发送——签名 URL 不进后端
|
|
253
|
+
...(a = e.attachments) != null && a.length ? {
|
|
254
|
+
attachments: e.attachments.map(({ url: s, ...o }) => o)
|
|
255
|
+
} : {}
|
|
240
256
|
};
|
|
241
|
-
return
|
|
242
|
-
var
|
|
243
|
-
if (!
|
|
244
|
-
(
|
|
257
|
+
return i.stream ? r.streamPost("/chat", i, n).then((s) => {
|
|
258
|
+
var o;
|
|
259
|
+
if (!s.ok) {
|
|
260
|
+
(o = e.onError) == null || o.call(e, new Error(`HTTP ${s.status}`));
|
|
245
261
|
return;
|
|
246
262
|
}
|
|
247
|
-
return
|
|
248
|
-
|
|
249
|
-
(
|
|
250
|
-
var
|
|
251
|
-
|
|
263
|
+
return p(
|
|
264
|
+
s,
|
|
265
|
+
(c) => {
|
|
266
|
+
var d, l, f, g, y, m;
|
|
267
|
+
c.type === "done" && c.sessionId ? (d = e.onDone) == null || d.call(e, { sessionId: c.sessionId, content: c.content, messageId: c.messageId }) : c.type === "done" ? (l = e.onDone) == null || l.call(e, { sessionId: "", content: c.content, messageId: c.messageId }) : c.type === "stop" ? ((f = e.onMessage) == null || f.call(e, c), (g = e.onDone) == null || g.call(e, { sessionId: c.sessionId ?? "", content: c.content, messageId: c.messageId })) : c.type === "error" ? (y = e.onError) == null || y.call(e, new Error(c.content)) : (m = e.onMessage) == null || m.call(e, c);
|
|
252
268
|
},
|
|
253
|
-
(
|
|
254
|
-
var
|
|
255
|
-
return (
|
|
269
|
+
(c) => {
|
|
270
|
+
var d;
|
|
271
|
+
return (d = e.onError) == null ? void 0 : d.call(e, c);
|
|
256
272
|
}
|
|
257
273
|
);
|
|
258
|
-
}).catch((
|
|
259
|
-
var
|
|
260
|
-
(
|
|
261
|
-
}) : r.post("/chat",
|
|
262
|
-
var
|
|
263
|
-
(
|
|
264
|
-
sessionId:
|
|
265
|
-
content:
|
|
266
|
-
messageId:
|
|
274
|
+
}).catch((s) => {
|
|
275
|
+
var o;
|
|
276
|
+
(s == null ? void 0 : s.name) !== "AbortError" && ((o = e.onError) == null || o.call(e, s instanceof Error ? s : new Error(String(s))));
|
|
277
|
+
}) : r.post("/chat", i).then((s) => {
|
|
278
|
+
var o;
|
|
279
|
+
(o = e.onDone) == null || o.call(e, {
|
|
280
|
+
sessionId: s.sessionId,
|
|
281
|
+
content: s.content ?? "",
|
|
282
|
+
messageId: s.messageId
|
|
267
283
|
});
|
|
268
|
-
}).catch((
|
|
269
|
-
var
|
|
270
|
-
(
|
|
284
|
+
}).catch((s) => {
|
|
285
|
+
var o;
|
|
286
|
+
(o = e.onError) == null || o.call(e, s instanceof Error ? s : new Error(String(s)));
|
|
271
287
|
}), t;
|
|
272
288
|
}
|
|
273
|
-
function
|
|
274
|
-
const t = new AbortController(),
|
|
275
|
-
return r.addEventListener("abort",
|
|
289
|
+
function b(r, e) {
|
|
290
|
+
const t = new AbortController(), n = () => t.abort();
|
|
291
|
+
return r.addEventListener("abort", n, { once: !0 }), e.addEventListener("abort", n, { once: !0 }), (r.aborted || e.aborted) && t.abort(), t.signal;
|
|
276
292
|
}
|
|
277
|
-
async function
|
|
293
|
+
async function S(r) {
|
|
278
294
|
return (await r.post("/chat/sessions", {
|
|
279
295
|
botId: r.getBotId()
|
|
280
296
|
})).sessionId;
|
|
281
297
|
}
|
|
282
|
-
function
|
|
298
|
+
function $(r) {
|
|
283
299
|
return {
|
|
284
300
|
// 后端返回 thread_id,toCamelCase 转为 threadId,映射为 sessionId
|
|
285
301
|
sessionId: r.threadId ?? r.sessionId,
|
|
@@ -289,7 +305,7 @@ function k(r) {
|
|
|
289
305
|
updateTime: r.updateTime
|
|
290
306
|
};
|
|
291
307
|
}
|
|
292
|
-
async function
|
|
308
|
+
async function A(r, e) {
|
|
293
309
|
const t = await r.get("/chat/conversations", {
|
|
294
310
|
botId: r.getBotId(),
|
|
295
311
|
page: (e == null ? void 0 : e.page) ?? 1,
|
|
@@ -297,77 +313,94 @@ async function S(r, e) {
|
|
|
297
313
|
});
|
|
298
314
|
return {
|
|
299
315
|
...t,
|
|
300
|
-
items: t.items.map(
|
|
316
|
+
items: t.items.map($)
|
|
301
317
|
};
|
|
302
318
|
}
|
|
303
|
-
async function
|
|
319
|
+
async function C(r, e, t) {
|
|
304
320
|
await r.patch(`/chat/conversations/${e}`, { title: t });
|
|
305
321
|
}
|
|
306
|
-
async function
|
|
322
|
+
async function _(r, e) {
|
|
307
323
|
await r.del(`/chat/conversations/${e}`);
|
|
308
324
|
}
|
|
309
|
-
async function
|
|
325
|
+
async function O(r, e) {
|
|
310
326
|
const t = await r.get(`/chat/conversations/${e}/messages`);
|
|
311
|
-
return
|
|
327
|
+
return P(t);
|
|
312
328
|
}
|
|
313
|
-
function
|
|
314
|
-
const e = [...r].sort((
|
|
315
|
-
const c = new Date(
|
|
316
|
-
return c !== d ? c - d : (
|
|
329
|
+
function P(r) {
|
|
330
|
+
const e = [...r].sort((s, o) => {
|
|
331
|
+
const c = new Date(s.createTime ?? 0).getTime() || 0, d = new Date(o.createTime ?? 0).getTime() || 0;
|
|
332
|
+
return c !== d ? c - d : (s.seq ?? 0) - (o.seq ?? 0);
|
|
317
333
|
}), t = /* @__PURE__ */ new Map();
|
|
318
|
-
for (const
|
|
319
|
-
|
|
320
|
-
const
|
|
321
|
-
const d =
|
|
322
|
-
(d == null ? void 0 : d.role) === "assistant" ? (d.parts.push(...
|
|
334
|
+
for (const s of e)
|
|
335
|
+
s.role === "tool" && s.toolCallId && t.set(s.toolCallId, s.content || "");
|
|
336
|
+
const n = /* @__PURE__ */ new Set(), i = [], a = (s, o, c) => {
|
|
337
|
+
const d = i[i.length - 1];
|
|
338
|
+
(d == null ? void 0 : d.role) === "assistant" ? (d.parts.push(...s), d.id = o) : i.push({ id: o, role: "assistant", parts: [...s], timestamp: c });
|
|
323
339
|
};
|
|
324
|
-
for (const
|
|
325
|
-
if (
|
|
326
|
-
const
|
|
327
|
-
if (
|
|
328
|
-
|
|
340
|
+
for (const s of e) {
|
|
341
|
+
if (s.role === "system") continue;
|
|
342
|
+
const o = String(s.id ?? s.messageId ?? `msg_${Date.now()}`), c = new Date(s.createTime ?? "").getTime() || Date.now();
|
|
343
|
+
if (s.role === "human") {
|
|
344
|
+
const d = (s.attachments ?? []).map((l) => ({
|
|
345
|
+
type: "attachment",
|
|
346
|
+
attachment: {
|
|
347
|
+
nosKey: l.nosKey ?? l.attachmentId ?? "",
|
|
348
|
+
// 历史回显后端不带 nosKey,占位空串
|
|
349
|
+
filename: l.filename ?? "file",
|
|
350
|
+
size: l.size ?? void 0,
|
|
351
|
+
mime: l.mime ?? void 0,
|
|
352
|
+
url: l.url ?? void 0
|
|
353
|
+
// 公开读桶下载链接(有则 chip 可点击下载)
|
|
354
|
+
}
|
|
355
|
+
}));
|
|
356
|
+
i.push({
|
|
357
|
+
id: o,
|
|
358
|
+
role: "user",
|
|
359
|
+
parts: [...d, { type: "text", content: u(s.content) }],
|
|
360
|
+
timestamp: c
|
|
361
|
+
});
|
|
329
362
|
continue;
|
|
330
363
|
}
|
|
331
|
-
if (
|
|
332
|
-
const d =
|
|
333
|
-
d.length > 0 && a(d,
|
|
364
|
+
if (s.role === "ai") {
|
|
365
|
+
const d = x(s, t, n);
|
|
366
|
+
d.length > 0 && a(d, o, c);
|
|
334
367
|
continue;
|
|
335
368
|
}
|
|
336
|
-
if (
|
|
337
|
-
if (
|
|
338
|
-
a([v(
|
|
369
|
+
if (s.role === "tool") {
|
|
370
|
+
if (s.toolCallId && n.has(s.toolCallId)) continue;
|
|
371
|
+
a([v(s)], o, c);
|
|
339
372
|
}
|
|
340
373
|
}
|
|
341
|
-
return
|
|
374
|
+
return i;
|
|
342
375
|
}
|
|
343
|
-
function
|
|
344
|
-
const
|
|
345
|
-
r.reasoning &&
|
|
346
|
-
for (const
|
|
347
|
-
|
|
348
|
-
return
|
|
376
|
+
function x(r, e, t) {
|
|
377
|
+
const n = [];
|
|
378
|
+
r.reasoning && n.push({ type: "thinking", content: r.reasoning }), r.content && n.push({ type: "text", content: u(r.content) });
|
|
379
|
+
for (const i of r.toolCalls ?? [])
|
|
380
|
+
i.is_interrupt ? (t.add(i.id), n.push(E(i, e))) : n.push(U(i));
|
|
381
|
+
return n;
|
|
349
382
|
}
|
|
350
|
-
function
|
|
351
|
-
const t = e.has(r.id),
|
|
383
|
+
function E(r, e) {
|
|
384
|
+
const t = e.has(r.id), n = typeof r.args == "object" ? r.args : {};
|
|
352
385
|
return {
|
|
353
386
|
type: "interrupt",
|
|
354
387
|
interrupt: {
|
|
355
388
|
interruptId: r.id ?? "",
|
|
356
|
-
interruptType:
|
|
357
|
-
content:
|
|
358
|
-
options:
|
|
359
|
-
placeholder:
|
|
360
|
-
inputType:
|
|
361
|
-
maxLength:
|
|
362
|
-
required:
|
|
363
|
-
fields:
|
|
364
|
-
metadata:
|
|
389
|
+
interruptType: n.interruptType ?? "input",
|
|
390
|
+
content: n.content ?? "",
|
|
391
|
+
options: n.options,
|
|
392
|
+
placeholder: n.placeholder,
|
|
393
|
+
inputType: n.inputType,
|
|
394
|
+
maxLength: n.maxLength,
|
|
395
|
+
required: n.required,
|
|
396
|
+
fields: n.fields,
|
|
397
|
+
metadata: n.metadata
|
|
365
398
|
},
|
|
366
399
|
resolved: t,
|
|
367
|
-
response: t ? { action: "submit", value:
|
|
400
|
+
response: t ? { action: "submit", value: D(e.get(r.id)) } : void 0
|
|
368
401
|
};
|
|
369
402
|
}
|
|
370
|
-
function
|
|
403
|
+
function U(r) {
|
|
371
404
|
let e;
|
|
372
405
|
try {
|
|
373
406
|
e = typeof r.args == "string" ? r.args : JSON.stringify(r.args ?? {});
|
|
@@ -377,19 +410,19 @@ function E(r) {
|
|
|
377
410
|
return { type: "tool_call", toolName: r.name ?? "", toolCallId: r.id ?? "", args: e };
|
|
378
411
|
}
|
|
379
412
|
function v(r) {
|
|
380
|
-
var t,
|
|
413
|
+
var t, n, i;
|
|
381
414
|
const e = Array.isArray(r.artifacts) ? r.artifacts : void 0;
|
|
382
415
|
return {
|
|
383
416
|
type: "tool_result",
|
|
384
417
|
toolName: r.toolName ?? "",
|
|
385
418
|
toolCallId: r.toolCallId ?? "",
|
|
386
|
-
content: r.content
|
|
419
|
+
content: u(r.content),
|
|
387
420
|
artifacts: e,
|
|
388
|
-
renderMode: ((t = r.metadata) == null ? void 0 : t.renderMode) ?? ((
|
|
389
|
-
html: (
|
|
421
|
+
renderMode: ((t = r.metadata) == null ? void 0 : t.renderMode) ?? ((n = r.metadata) == null ? void 0 : n.render_mode),
|
|
422
|
+
html: (i = r.metadata) == null ? void 0 : i.html
|
|
390
423
|
};
|
|
391
424
|
}
|
|
392
|
-
function
|
|
425
|
+
function D(r) {
|
|
393
426
|
if (r != null)
|
|
394
427
|
try {
|
|
395
428
|
return JSON.parse(r);
|
|
@@ -397,57 +430,58 @@ function x(r) {
|
|
|
397
430
|
return r;
|
|
398
431
|
}
|
|
399
432
|
}
|
|
400
|
-
async function
|
|
401
|
-
const
|
|
433
|
+
async function N(r, e, t, n, i, a) {
|
|
434
|
+
const s = await r.streamPost(
|
|
402
435
|
`/chat/interrupt/${e}/respond`,
|
|
403
436
|
{
|
|
404
437
|
sessionId: t,
|
|
405
|
-
action:
|
|
406
|
-
value:
|
|
438
|
+
action: n.action,
|
|
439
|
+
value: n.value
|
|
407
440
|
}
|
|
408
441
|
);
|
|
409
|
-
if (!
|
|
410
|
-
const
|
|
411
|
-
throw a == null || a(
|
|
442
|
+
if (!s.ok) {
|
|
443
|
+
const o = new Error(`HTTP ${s.status}`);
|
|
444
|
+
throw a == null || a(o), o;
|
|
412
445
|
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
(
|
|
416
|
-
|
|
446
|
+
i && await p(
|
|
447
|
+
s,
|
|
448
|
+
(o) => {
|
|
449
|
+
o.type === "error" ? a == null || a(new Error(o.content)) : i(o);
|
|
417
450
|
},
|
|
418
|
-
(
|
|
451
|
+
(o) => a == null ? void 0 : a(o)
|
|
419
452
|
);
|
|
420
453
|
}
|
|
421
|
-
async function
|
|
454
|
+
async function q(r) {
|
|
422
455
|
return r.get(`/chat/bots/${r.getBotId()}/skills`);
|
|
423
456
|
}
|
|
424
|
-
async function
|
|
457
|
+
async function L(r, e) {
|
|
425
458
|
await r.post("/chat/stop", { sessionId: e });
|
|
426
459
|
}
|
|
427
|
-
function
|
|
428
|
-
const e = new
|
|
460
|
+
function G(r) {
|
|
461
|
+
const e = new T(r);
|
|
429
462
|
return {
|
|
430
463
|
botId: e.getBotId(),
|
|
431
464
|
getToken: () => e.fetchToken(),
|
|
432
|
-
createSession: () =>
|
|
433
|
-
chat: (
|
|
434
|
-
listConversations: (
|
|
435
|
-
renameConversation: (
|
|
436
|
-
deleteConversation: (
|
|
437
|
-
getMessages: (
|
|
438
|
-
respondInterrupt: (
|
|
439
|
-
setToken: (
|
|
440
|
-
feedback: async (
|
|
441
|
-
const
|
|
442
|
-
|
|
465
|
+
createSession: () => S(e),
|
|
466
|
+
chat: (n) => k(e, n),
|
|
467
|
+
listConversations: (n) => A(e, n),
|
|
468
|
+
renameConversation: (n, i) => C(e, n, i),
|
|
469
|
+
deleteConversation: (n) => _(e, n),
|
|
470
|
+
getMessages: (n) => O(e, n),
|
|
471
|
+
respondInterrupt: (n, i, a, s, o) => N(e, n, i, a, s, o),
|
|
472
|
+
setToken: (n) => e.setToken(n),
|
|
473
|
+
feedback: async (n, i, a) => {
|
|
474
|
+
const s = { type: i };
|
|
475
|
+
i === "dislike" && ((a == null ? void 0 : a.reason) != null && (s.reason = a.reason), a != null && a.remark && (s.remark = a.remark)), await e.post(`/chat/messages/${n}/feedback`, s);
|
|
443
476
|
},
|
|
444
|
-
cancelFeedback: async (
|
|
445
|
-
await e.del(`/chat/messages/${
|
|
477
|
+
cancelFeedback: async (n) => {
|
|
478
|
+
await e.del(`/chat/messages/${n}/feedback`);
|
|
446
479
|
},
|
|
447
|
-
listSkills: () =>
|
|
448
|
-
stopGeneration: (
|
|
480
|
+
listSkills: () => q(e),
|
|
481
|
+
stopGeneration: (n) => L(e, n)
|
|
449
482
|
};
|
|
450
483
|
}
|
|
451
484
|
export {
|
|
452
|
-
|
|
485
|
+
J as createNosUploader,
|
|
486
|
+
G as createSuperAgent
|
|
453
487
|
};
|