super-agent-sdk 1.0.3 → 1.0.5
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 +180 -65
- package/dist/index.cjs +4 -4
- package/dist/index.d.ts +83 -10
- package/dist/index.mjs +260 -202
- package/dist/mammoth.browser-COPV53yV.js +14917 -0
- package/dist/mammoth.browser-DiAPPO3x.cjs +230 -0
- package/dist/purify.es-C-6FFqDW.js +898 -0
- package/dist/purify.es-Dsdnkgrg.cjs +3 -0
- package/dist/widget.cjs +399 -5
- package/dist/widget.d.ts +119 -16
- package/dist/widget.mjs +1729 -637
- package/package.json +8 -3
package/dist/index.mjs
CHANGED
|
@@ -1,38 +1,49 @@
|
|
|
1
|
-
function
|
|
2
|
-
if (Array.isArray(
|
|
3
|
-
if (
|
|
1
|
+
function f(a) {
|
|
2
|
+
if (Array.isArray(a)) return a.map((e) => f(e));
|
|
3
|
+
if (a && typeof a == "object" && a.constructor === Object) {
|
|
4
4
|
const e = {};
|
|
5
|
-
for (const [
|
|
6
|
-
const o =
|
|
7
|
-
e[o] =
|
|
5
|
+
for (const [t, n] of Object.entries(a)) {
|
|
6
|
+
const o = t.replace(/_([a-z])/g, (r, s) => s.toUpperCase());
|
|
7
|
+
e[o] = f(n);
|
|
8
8
|
}
|
|
9
9
|
return e;
|
|
10
10
|
}
|
|
11
|
-
return
|
|
11
|
+
return a;
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
const w = "/api/agent/runtime/v1";
|
|
14
|
+
class I {
|
|
14
15
|
constructor(e) {
|
|
15
|
-
this.refreshing = null
|
|
16
|
+
this.refreshing = null;
|
|
17
|
+
const t = e.baseUrl ?? w;
|
|
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);
|
|
16
19
|
}
|
|
17
20
|
getBotId() {
|
|
18
21
|
return this.botId;
|
|
19
22
|
}
|
|
20
|
-
|
|
21
|
-
this.appId
|
|
23
|
+
getAppKey() {
|
|
24
|
+
return this.appId;
|
|
22
25
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
setToken(e) {
|
|
27
|
+
this.token = e;
|
|
28
|
+
}
|
|
29
|
+
/** Derive browser origin (for relative URL resolution) */
|
|
30
|
+
getOrigin() {
|
|
31
|
+
return typeof window < "u" ? window.location.origin : "";
|
|
32
|
+
}
|
|
33
|
+
/** POST {origin}{tokenGateway}/v1/token — 获取 token + appId */
|
|
34
|
+
async fetchToken() {
|
|
35
|
+
const t = `${this.isAbsoluteGateway ? this.tokenGateway : `${this.getOrigin()}${this.tokenGateway}`}/v1/token`, n = await fetch(t, {
|
|
26
36
|
method: "POST",
|
|
27
37
|
headers: { "Content-Type": "application/json" },
|
|
28
|
-
body:
|
|
38
|
+
body: JSON.stringify({ botId: this.botId })
|
|
29
39
|
});
|
|
30
|
-
if (!
|
|
31
|
-
throw new Error(`HTTP ${
|
|
32
|
-
const
|
|
33
|
-
if (
|
|
34
|
-
throw new Error(
|
|
35
|
-
|
|
40
|
+
if (!n.ok)
|
|
41
|
+
throw new Error(`HTTP ${n.status}: ${n.statusText}`);
|
|
42
|
+
const o = await n.json();
|
|
43
|
+
if (o.code !== "200")
|
|
44
|
+
throw new Error(o.message || `API error: ${o.code}`);
|
|
45
|
+
const r = f(o.data);
|
|
46
|
+
return this.token = r.token, r.appId && !this.appId && (this.appId = r.appId), r.token;
|
|
36
47
|
}
|
|
37
48
|
headers(e) {
|
|
38
49
|
return {
|
|
@@ -47,8 +58,7 @@ class g {
|
|
|
47
58
|
return await this.refreshing, !0;
|
|
48
59
|
try {
|
|
49
60
|
return this.refreshing = (async () => {
|
|
50
|
-
|
|
51
|
-
this.appId = e.appId, this.token = e.token;
|
|
61
|
+
await this.fetchToken();
|
|
52
62
|
})(), await this.refreshing, !0;
|
|
53
63
|
} catch {
|
|
54
64
|
return !1;
|
|
@@ -56,290 +66,338 @@ class g {
|
|
|
56
66
|
this.refreshing = null;
|
|
57
67
|
}
|
|
58
68
|
}
|
|
59
|
-
async request(e,
|
|
60
|
-
if (
|
|
69
|
+
async request(e, t, n) {
|
|
70
|
+
if (!this.token && !await this.handleTokenRefresh())
|
|
61
71
|
throw new Error("SDK token not available: POST /token failed");
|
|
62
|
-
let o = `${this.baseUrl}${
|
|
63
|
-
if (
|
|
64
|
-
const
|
|
65
|
-
for (const [l, d] of Object.entries(
|
|
66
|
-
d != null &&
|
|
67
|
-
const
|
|
68
|
-
|
|
72
|
+
let o = this.isAbsoluteUrl ? `${this.baseUrl}${t}` : `${this.getOrigin()}${this.baseUrl}${t}`;
|
|
73
|
+
if (n != null && n.params) {
|
|
74
|
+
const i = new URLSearchParams();
|
|
75
|
+
for (const [l, d] of Object.entries(n.params))
|
|
76
|
+
d != null && i.set(l, String(d));
|
|
77
|
+
const c = i.toString();
|
|
78
|
+
c && (o += `?${c}`);
|
|
69
79
|
}
|
|
70
|
-
const
|
|
80
|
+
const r = await fetch(o, {
|
|
71
81
|
method: e,
|
|
72
82
|
headers: this.headers(),
|
|
73
|
-
body:
|
|
83
|
+
body: n != null && n.body ? JSON.stringify(n.body) : void 0
|
|
74
84
|
});
|
|
75
|
-
if (
|
|
76
|
-
return this.request(e,
|
|
77
|
-
if (!
|
|
78
|
-
throw new Error(`HTTP ${
|
|
79
|
-
const
|
|
80
|
-
if (
|
|
81
|
-
throw new Error(
|
|
82
|
-
return
|
|
85
|
+
if (r.status === 401 && !(n != null && n.retry) && await this.handleTokenRefresh())
|
|
86
|
+
return this.request(e, t, { ...n, retry: !0 });
|
|
87
|
+
if (!r.ok)
|
|
88
|
+
throw new Error(`HTTP ${r.status}: ${r.statusText}`);
|
|
89
|
+
const s = await r.json();
|
|
90
|
+
if (s.code !== "200")
|
|
91
|
+
throw new Error(s.message || `API error: ${s.code}`);
|
|
92
|
+
return f(s.data);
|
|
83
93
|
}
|
|
84
|
-
get(e,
|
|
85
|
-
return this.request("GET", e, { params:
|
|
94
|
+
get(e, t) {
|
|
95
|
+
return this.request("GET", e, { params: t });
|
|
86
96
|
}
|
|
87
|
-
post(e,
|
|
88
|
-
return this.request("POST", e, { body:
|
|
97
|
+
post(e, t) {
|
|
98
|
+
return this.request("POST", e, { body: t });
|
|
89
99
|
}
|
|
90
|
-
patch(e,
|
|
91
|
-
return this.request("PATCH", e, { body:
|
|
100
|
+
patch(e, t) {
|
|
101
|
+
return this.request("PATCH", e, { body: t });
|
|
92
102
|
}
|
|
93
103
|
del(e) {
|
|
94
104
|
return this.request("DELETE", e);
|
|
95
105
|
}
|
|
96
106
|
/** For SSE streaming — returns raw Response (no envelope unwrap) */
|
|
97
|
-
async streamPost(e,
|
|
98
|
-
if (
|
|
107
|
+
async streamPost(e, t, n) {
|
|
108
|
+
if (!this.token && !await this.handleTokenRefresh())
|
|
99
109
|
throw new Error("SDK token not available: POST /token failed");
|
|
100
|
-
const o = `${this.baseUrl}${e}`,
|
|
110
|
+
const o = this.isAbsoluteUrl ? `${this.baseUrl}${e}` : `${this.getOrigin()}${this.baseUrl}${e}`, r = await fetch(o, {
|
|
101
111
|
method: "POST",
|
|
102
112
|
headers: this.headers(),
|
|
103
|
-
body: JSON.stringify(
|
|
104
|
-
signal:
|
|
113
|
+
body: JSON.stringify(t),
|
|
114
|
+
signal: n
|
|
105
115
|
});
|
|
106
|
-
return
|
|
116
|
+
return r.status === 401 && await this.handleTokenRefresh() ? fetch(o, {
|
|
107
117
|
method: "POST",
|
|
108
118
|
headers: this.headers(),
|
|
109
|
-
body: JSON.stringify(
|
|
110
|
-
signal:
|
|
111
|
-
}) :
|
|
119
|
+
body: JSON.stringify(t),
|
|
120
|
+
signal: n
|
|
121
|
+
}) : r;
|
|
112
122
|
}
|
|
113
123
|
}
|
|
114
|
-
function
|
|
115
|
-
const e =
|
|
116
|
-
`).map((
|
|
124
|
+
function y(a) {
|
|
125
|
+
const e = a.split(`
|
|
126
|
+
`).map((n) => n.trim()).filter((n) => n.startsWith("data:")).map((n) => n.slice(5).trim());
|
|
117
127
|
if (!e.length) return null;
|
|
118
|
-
let
|
|
128
|
+
let t;
|
|
119
129
|
try {
|
|
120
|
-
|
|
130
|
+
t = JSON.parse(e.join(`
|
|
121
131
|
`));
|
|
122
132
|
} catch {
|
|
123
133
|
return null;
|
|
124
134
|
}
|
|
125
|
-
switch (
|
|
135
|
+
switch (t.type) {
|
|
126
136
|
case "user":
|
|
127
|
-
return { type: "user", content:
|
|
137
|
+
return { type: "user", content: t.content ?? "" };
|
|
128
138
|
case "thinking":
|
|
129
|
-
return { type: "thinking", content:
|
|
139
|
+
return { type: "thinking", content: t.content ?? "" };
|
|
130
140
|
case "ai":
|
|
131
|
-
return { type: "ai", content:
|
|
141
|
+
return { type: "ai", content: t.content ?? "" };
|
|
132
142
|
case "tool_call":
|
|
133
143
|
return {
|
|
134
144
|
type: "tool_call",
|
|
135
|
-
content:
|
|
136
|
-
toolName:
|
|
137
|
-
toolCallId:
|
|
138
|
-
args: typeof
|
|
145
|
+
content: t.name ?? "",
|
|
146
|
+
toolName: t.name,
|
|
147
|
+
toolCallId: t.id,
|
|
148
|
+
args: typeof t.args == "string" ? t.args : JSON.stringify(t.args ?? {})
|
|
139
149
|
};
|
|
140
150
|
case "tool_result":
|
|
141
151
|
return {
|
|
142
152
|
type: "tool_result",
|
|
143
|
-
content:
|
|
144
|
-
toolName:
|
|
145
|
-
toolCallId:
|
|
153
|
+
content: t.output ?? "",
|
|
154
|
+
toolName: t.name,
|
|
155
|
+
toolCallId: t.id,
|
|
156
|
+
// 通用 artifacts(type + data),原样透传
|
|
157
|
+
artifacts: Array.isArray(t.artifacts) ? t.artifacts : void 0,
|
|
158
|
+
// fill_html_template 的 render_mode + html
|
|
159
|
+
renderMode: t.render_mode ?? t.renderMode,
|
|
160
|
+
html: t.html
|
|
146
161
|
};
|
|
147
162
|
case "done":
|
|
148
163
|
return {
|
|
149
164
|
type: "done",
|
|
150
|
-
content:
|
|
151
|
-
|
|
152
|
-
|
|
165
|
+
content: t.content ?? "",
|
|
166
|
+
sessionId: t.sessionId ?? t.session_id ?? "",
|
|
167
|
+
messageId: t.messageId ?? t.message_id
|
|
153
168
|
};
|
|
154
169
|
case "error":
|
|
155
|
-
return { type: "error", content:
|
|
170
|
+
return { type: "error", content: t.message ?? "Unknown error" };
|
|
171
|
+
case "interrupt":
|
|
172
|
+
return {
|
|
173
|
+
type: "interrupt",
|
|
174
|
+
content: t.content ?? "",
|
|
175
|
+
interrupt: {
|
|
176
|
+
interruptId: t.interruptId ?? t.interrupt_id ?? "",
|
|
177
|
+
interruptType: t.interruptType ?? t.interrupt_type ?? "confirm",
|
|
178
|
+
content: t.content ?? "",
|
|
179
|
+
options: t.options,
|
|
180
|
+
placeholder: t.placeholder,
|
|
181
|
+
inputType: t.inputType ?? t.input_type,
|
|
182
|
+
maxLength: t.maxLength ?? t.max_length,
|
|
183
|
+
required: t.required,
|
|
184
|
+
fields: t.fields,
|
|
185
|
+
metadata: t.metadata
|
|
186
|
+
}
|
|
187
|
+
};
|
|
156
188
|
default:
|
|
157
189
|
return null;
|
|
158
190
|
}
|
|
159
191
|
}
|
|
160
|
-
async function
|
|
161
|
-
if (!
|
|
162
|
-
|
|
192
|
+
async function m(a, e, t) {
|
|
193
|
+
if (!a.body) {
|
|
194
|
+
t(new Error("Response body is null"));
|
|
163
195
|
return;
|
|
164
196
|
}
|
|
165
|
-
const
|
|
166
|
-
let
|
|
197
|
+
const n = a.body.getReader(), o = new TextDecoder();
|
|
198
|
+
let r = "";
|
|
167
199
|
try {
|
|
168
200
|
for (; ; ) {
|
|
169
|
-
const { value:
|
|
170
|
-
if (
|
|
171
|
-
|
|
172
|
-
let
|
|
173
|
-
for (; (
|
|
201
|
+
const { value: s, done: i } = await n.read();
|
|
202
|
+
if (i) break;
|
|
203
|
+
r += o.decode(s, { stream: !0 });
|
|
204
|
+
let c;
|
|
205
|
+
for (; (c = r.indexOf(`
|
|
174
206
|
|
|
175
207
|
`)) !== -1; ) {
|
|
176
|
-
const l =
|
|
177
|
-
|
|
178
|
-
const d =
|
|
208
|
+
const l = r.slice(0, c);
|
|
209
|
+
r = r.slice(c + 2);
|
|
210
|
+
const d = y(l);
|
|
179
211
|
d && e(d);
|
|
180
212
|
}
|
|
181
213
|
}
|
|
182
|
-
if (
|
|
183
|
-
const
|
|
184
|
-
|
|
214
|
+
if (r.trim()) {
|
|
215
|
+
const s = y(r);
|
|
216
|
+
s && e(s);
|
|
185
217
|
}
|
|
186
|
-
} catch (
|
|
187
|
-
(
|
|
218
|
+
} catch (s) {
|
|
219
|
+
(s == null ? void 0 : s.name) !== "AbortError" && t(s instanceof Error ? s : new Error(String(s)));
|
|
188
220
|
} finally {
|
|
189
221
|
try {
|
|
190
|
-
|
|
222
|
+
n.releaseLock();
|
|
191
223
|
} catch {
|
|
192
224
|
}
|
|
193
225
|
}
|
|
194
226
|
}
|
|
195
|
-
function
|
|
196
|
-
const
|
|
197
|
-
botId:
|
|
227
|
+
function k(a, e) {
|
|
228
|
+
const t = new AbortController(), n = e.signal ? b(e.signal, t.signal) : t.signal, o = {
|
|
229
|
+
botId: a.getBotId(),
|
|
198
230
|
message: e.message,
|
|
199
231
|
sessionId: e.sessionId,
|
|
200
232
|
stream: e.stream !== !1
|
|
201
233
|
};
|
|
202
|
-
return o.stream ?
|
|
203
|
-
var
|
|
204
|
-
if (!
|
|
205
|
-
(
|
|
234
|
+
return o.stream ? a.streamPost("/chat", o, n).then((r) => {
|
|
235
|
+
var s;
|
|
236
|
+
if (!r.ok) {
|
|
237
|
+
(s = e.onError) == null || s.call(e, new Error(`HTTP ${r.status}`));
|
|
206
238
|
return;
|
|
207
239
|
}
|
|
208
|
-
return
|
|
209
|
-
|
|
210
|
-
(
|
|
211
|
-
var
|
|
212
|
-
|
|
240
|
+
return m(
|
|
241
|
+
r,
|
|
242
|
+
(i) => {
|
|
243
|
+
var c, l, d, h;
|
|
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" ? (l = e.onDone) == null || l.call(e, { sessionId: "", content: i.content, messageId: i.messageId }) : i.type === "error" ? (d = e.onError) == null || d.call(e, new Error(i.content)) : (h = e.onMessage) == null || h.call(e, i);
|
|
213
245
|
},
|
|
214
|
-
(
|
|
215
|
-
var
|
|
216
|
-
return (
|
|
246
|
+
(i) => {
|
|
247
|
+
var c;
|
|
248
|
+
return (c = e.onError) == null ? void 0 : c.call(e, i);
|
|
217
249
|
}
|
|
218
250
|
);
|
|
219
|
-
}).catch((
|
|
220
|
-
var
|
|
221
|
-
(
|
|
222
|
-
}) :
|
|
223
|
-
var
|
|
224
|
-
(
|
|
225
|
-
sessionId:
|
|
226
|
-
content:
|
|
251
|
+
}).catch((r) => {
|
|
252
|
+
var s;
|
|
253
|
+
(r == null ? void 0 : r.name) !== "AbortError" && ((s = e.onError) == null || s.call(e, r instanceof Error ? r : new Error(String(r))));
|
|
254
|
+
}) : a.post("/chat", o).then((r) => {
|
|
255
|
+
var s;
|
|
256
|
+
(s = e.onDone) == null || s.call(e, {
|
|
257
|
+
sessionId: r.sessionId,
|
|
258
|
+
content: r.content ?? ""
|
|
227
259
|
});
|
|
228
|
-
}).catch((
|
|
229
|
-
var
|
|
230
|
-
(
|
|
231
|
-
}),
|
|
260
|
+
}).catch((r) => {
|
|
261
|
+
var s;
|
|
262
|
+
(s = e.onError) == null || s.call(e, r instanceof Error ? r : new Error(String(r)));
|
|
263
|
+
}), t;
|
|
232
264
|
}
|
|
233
|
-
function
|
|
234
|
-
const
|
|
235
|
-
return
|
|
265
|
+
function b(a, e) {
|
|
266
|
+
const t = new AbortController(), n = () => t.abort();
|
|
267
|
+
return a.addEventListener("abort", n, { once: !0 }), e.addEventListener("abort", n, { once: !0 }), (a.aborted || e.aborted) && t.abort(), t.signal;
|
|
236
268
|
}
|
|
237
|
-
async function
|
|
238
|
-
return (await
|
|
239
|
-
botId:
|
|
269
|
+
async function T(a) {
|
|
270
|
+
return (await a.post("/chat/sessions", {
|
|
271
|
+
botId: a.getBotId()
|
|
240
272
|
})).sessionId;
|
|
241
273
|
}
|
|
242
|
-
function
|
|
274
|
+
function S(a) {
|
|
243
275
|
return {
|
|
244
276
|
// 后端返回 thread_id,toCamelCase 转为 threadId,映射为 sessionId
|
|
245
|
-
sessionId:
|
|
246
|
-
botId:
|
|
247
|
-
title:
|
|
248
|
-
createTime:
|
|
249
|
-
updateTime:
|
|
277
|
+
sessionId: a.threadId ?? a.sessionId,
|
|
278
|
+
botId: a.botId,
|
|
279
|
+
title: a.title,
|
|
280
|
+
createTime: a.createTime,
|
|
281
|
+
updateTime: a.updateTime
|
|
250
282
|
};
|
|
251
283
|
}
|
|
252
|
-
async function
|
|
253
|
-
const
|
|
254
|
-
botId:
|
|
284
|
+
async function $(a, e) {
|
|
285
|
+
const t = await a.get("/chat/conversations", {
|
|
286
|
+
botId: a.getBotId(),
|
|
255
287
|
page: (e == null ? void 0 : e.page) ?? 1,
|
|
256
288
|
size: (e == null ? void 0 : e.size) ?? 20
|
|
257
289
|
});
|
|
258
290
|
return {
|
|
259
|
-
...
|
|
260
|
-
items:
|
|
291
|
+
...t,
|
|
292
|
+
items: t.items.map(S)
|
|
261
293
|
};
|
|
262
294
|
}
|
|
263
|
-
async function
|
|
264
|
-
await
|
|
295
|
+
async function p(a, e, t) {
|
|
296
|
+
await a.patch(`/chat/conversations/${e}`, { title: t });
|
|
265
297
|
}
|
|
266
|
-
async function
|
|
267
|
-
await
|
|
298
|
+
async function A(a, e) {
|
|
299
|
+
await a.del(`/chat/conversations/${e}`);
|
|
268
300
|
}
|
|
269
|
-
async function
|
|
270
|
-
const
|
|
271
|
-
return
|
|
301
|
+
async function C(a, e) {
|
|
302
|
+
const t = await a.get(`/chat/conversations/${e}/messages`);
|
|
303
|
+
return O(t);
|
|
272
304
|
}
|
|
273
|
-
function
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
305
|
+
function O(a) {
|
|
306
|
+
var n, o, r;
|
|
307
|
+
const e = [], t = [...a].sort((s, i) => (s.seq ?? 0) - (i.seq ?? 0));
|
|
308
|
+
for (const s of t) {
|
|
309
|
+
const i = s.role;
|
|
310
|
+
if (i === "system") continue;
|
|
311
|
+
const c = s.messageId ?? `msg_${s.id}`, l = new Date(s.createTime ?? "").getTime() || Date.now();
|
|
312
|
+
if (i === "human")
|
|
280
313
|
e.push({
|
|
281
|
-
id:
|
|
314
|
+
id: c,
|
|
282
315
|
role: "user",
|
|
283
|
-
parts: [{ type: "text", content:
|
|
284
|
-
timestamp:
|
|
316
|
+
parts: [{ type: "text", content: s.content ?? "" }],
|
|
317
|
+
timestamp: l
|
|
285
318
|
});
|
|
286
|
-
else if (
|
|
287
|
-
const
|
|
288
|
-
|
|
289
|
-
const
|
|
290
|
-
if (
|
|
291
|
-
for (const
|
|
292
|
-
let
|
|
319
|
+
else if (i === "ai") {
|
|
320
|
+
const d = [];
|
|
321
|
+
s.reasoning && d.push({ type: "thinking", content: s.reasoning }), s.content && d.push({ type: "text", content: s.content });
|
|
322
|
+
const h = s.toolCalls;
|
|
323
|
+
if (h && Array.isArray(h))
|
|
324
|
+
for (const u of h) {
|
|
325
|
+
let g;
|
|
293
326
|
try {
|
|
294
|
-
|
|
327
|
+
g = typeof u.args == "string" ? u.args : JSON.stringify(u.args ?? {});
|
|
295
328
|
} catch {
|
|
296
|
-
|
|
329
|
+
g = String(u.args ?? "{}");
|
|
297
330
|
}
|
|
298
|
-
|
|
331
|
+
d.push({
|
|
299
332
|
type: "tool_call",
|
|
300
|
-
toolName:
|
|
301
|
-
toolCallId:
|
|
302
|
-
args:
|
|
333
|
+
toolName: u.name ?? "",
|
|
334
|
+
toolCallId: u.id ?? "",
|
|
335
|
+
args: g
|
|
303
336
|
});
|
|
304
337
|
}
|
|
305
|
-
e.push({ id:
|
|
306
|
-
} else
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
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
|
+
});
|
|
355
|
+
}
|
|
317
356
|
}
|
|
318
357
|
return e;
|
|
319
358
|
}
|
|
320
|
-
function
|
|
321
|
-
const
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
359
|
+
async function _(a, e, t, n, o, r) {
|
|
360
|
+
const s = await a.streamPost(
|
|
361
|
+
`/chat/interrupt/${e}/respond`,
|
|
362
|
+
{
|
|
363
|
+
sessionId: t,
|
|
364
|
+
action: n.action,
|
|
365
|
+
value: n.value
|
|
366
|
+
}
|
|
367
|
+
);
|
|
368
|
+
if (!s.ok) {
|
|
369
|
+
const i = new Error(`HTTP ${s.status}`);
|
|
370
|
+
throw r == null || r(i), i;
|
|
371
|
+
}
|
|
372
|
+
o && await m(
|
|
373
|
+
s,
|
|
374
|
+
(i) => {
|
|
375
|
+
i.type === "error" ? r == null || r(new Error(i.content)) : o(i);
|
|
376
|
+
},
|
|
377
|
+
(i) => r == null ? void 0 : r(i)
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
function E(a) {
|
|
381
|
+
const e = new I(a);
|
|
382
|
+
return {
|
|
383
|
+
getToken: () => e.fetchToken(),
|
|
384
|
+
createSession: () => T(e),
|
|
385
|
+
chat: (n) => k(e, n),
|
|
386
|
+
listConversations: (n) => $(e, n),
|
|
387
|
+
renameConversation: (n, o) => p(e, n, o),
|
|
388
|
+
deleteConversation: (n) => A(e, n),
|
|
389
|
+
getMessages: (n) => C(e, n),
|
|
390
|
+
respondInterrupt: (n, o, r, s, i) => _(e, n, o, r, s, i),
|
|
391
|
+
setToken: (n) => e.setToken(n),
|
|
392
|
+
feedback: async (n, o, r) => {
|
|
393
|
+
const s = { type: o };
|
|
394
|
+
o === "dislike" && ((r == null ? void 0 : r.reason) != null && (s.reason = r.reason), r != null && r.remark && (s.remark = r.remark)), await e.post(`/chat/messages/${n}/feedback`, s);
|
|
328
395
|
},
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
listConversations: (t) => k(e, t),
|
|
332
|
-
renameConversation: (t, o) => T(e, t, o),
|
|
333
|
-
deleteConversation: (t) => S(e, t),
|
|
334
|
-
getMessages: (t) => E(e, t),
|
|
335
|
-
setToken: (t, o) => e.setToken(t, o),
|
|
336
|
-
feedback: (t, o) => {
|
|
337
|
-
var n;
|
|
338
|
-
(n = r.onFeedback) == null || n.call(r, t, o);
|
|
396
|
+
cancelFeedback: async (n) => {
|
|
397
|
+
await e.del(`/chat/messages/${n}/feedback`);
|
|
339
398
|
}
|
|
340
399
|
};
|
|
341
|
-
return r;
|
|
342
400
|
}
|
|
343
401
|
export {
|
|
344
|
-
|
|
402
|
+
E as createSuperAgent
|
|
345
403
|
};
|