@schmitech/chatbot-api 2.1.5 → 2.2.0
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/dist/api.cjs +2 -2
- package/dist/api.cjs.map +1 -1
- package/dist/api.d.ts +36 -5
- package/dist/api.mjs +401 -404
- package/dist/api.mjs.map +1 -1
- package/package.json +5 -4
package/dist/api.mjs
CHANGED
|
@@ -1,40 +1,88 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
let
|
|
1
|
+
var x = Object.defineProperty;
|
|
2
|
+
var M = (o, e, t) => e in o ? x(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
|
|
3
|
+
var g = (o, e, t) => M(o, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
let b = null, $ = null;
|
|
5
5
|
typeof window > "u" && Promise.all([
|
|
6
6
|
// @ts-expect-error - Dynamic import of Node.js built-in module (only available in Node.js runtime)
|
|
7
7
|
import("http").catch(() => null),
|
|
8
8
|
// @ts-expect-error - Dynamic import of Node.js built-in module (only available in Node.js runtime)
|
|
9
9
|
import("https").catch(() => null)
|
|
10
|
-
]).then(([
|
|
11
|
-
var
|
|
12
|
-
(
|
|
13
|
-
}).catch((
|
|
14
|
-
console.warn("Failed to initialize HTTP agents:",
|
|
10
|
+
]).then(([o, e]) => {
|
|
11
|
+
var t, s;
|
|
12
|
+
(t = o == null ? void 0 : o.default) != null && t.Agent ? b = new o.default.Agent({ keepAlive: !0 }) : o != null && o.Agent && (b = new o.Agent({ keepAlive: !0 })), (s = e == null ? void 0 : e.default) != null && s.Agent ? $ = new e.default.Agent({ keepAlive: !0 }) : e != null && e.Agent && ($ = new e.Agent({ keepAlive: !0 }));
|
|
13
|
+
}).catch((o) => {
|
|
14
|
+
console.warn("Failed to initialize HTTP agents:", o.message);
|
|
15
15
|
});
|
|
16
|
-
|
|
16
|
+
const T = "Could not connect to the server. Please check if the server is running.", J = 6e4, D = 1e6, H = 5e5;
|
|
17
|
+
class B {
|
|
17
18
|
// Session ID can be mutable
|
|
18
|
-
constructor(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
constructor(e) {
|
|
20
|
+
g(this, "apiUrl");
|
|
21
|
+
g(this, "apiKey");
|
|
22
|
+
g(this, "adapterName");
|
|
23
|
+
g(this, "middlewareBaseUrl");
|
|
24
|
+
g(this, "middlewareMode");
|
|
25
|
+
g(this, "sessionId");
|
|
26
|
+
if (!e.apiUrl || typeof e.apiUrl != "string")
|
|
23
27
|
throw new Error("API URL must be a valid string");
|
|
24
|
-
if (
|
|
28
|
+
if (e.apiKey !== void 0 && e.apiKey !== null && typeof e.apiKey != "string")
|
|
25
29
|
throw new Error("API key must be a valid string or null");
|
|
26
|
-
if (
|
|
30
|
+
if (e.sessionId !== void 0 && e.sessionId !== null && typeof e.sessionId != "string")
|
|
27
31
|
throw new Error("Session ID must be a valid string or null");
|
|
28
|
-
|
|
32
|
+
if (e.adapterName !== void 0 && e.adapterName !== null && typeof e.adapterName != "string")
|
|
33
|
+
throw new Error("Adapter name must be a valid string or null");
|
|
34
|
+
if (e.middlewareBaseUrl !== void 0 && e.middlewareBaseUrl !== null && typeof e.middlewareBaseUrl != "string")
|
|
35
|
+
throw new Error("Middleware base URL must be a valid string or null");
|
|
36
|
+
this.apiUrl = e.apiUrl, this.apiKey = e.apiKey ?? null, this.sessionId = e.sessionId ?? null;
|
|
37
|
+
const t = typeof e.adapterName == "string" ? e.adapterName.trim() : "";
|
|
38
|
+
this.adapterName = t && t.length > 0 ? t : null;
|
|
39
|
+
const s = typeof e.middlewareBaseUrl == "string" ? e.middlewareBaseUrl.trim() : "";
|
|
40
|
+
this.middlewareBaseUrl = s.endsWith("/") ? s.slice(0, -1) : s;
|
|
41
|
+
const i = e.useMiddleware ?? (!this.apiKey && !!this.adapterName);
|
|
42
|
+
this.middlewareMode = !!(this.adapterName && i);
|
|
29
43
|
}
|
|
30
|
-
setSessionId(
|
|
31
|
-
if (
|
|
44
|
+
setSessionId(e) {
|
|
45
|
+
if (e !== null && typeof e != "string")
|
|
32
46
|
throw new Error("Session ID must be a valid string or null");
|
|
33
|
-
this.sessionId =
|
|
47
|
+
this.sessionId = e;
|
|
34
48
|
}
|
|
35
49
|
getSessionId() {
|
|
36
50
|
return this.sessionId;
|
|
37
51
|
}
|
|
52
|
+
hasFailedToFetch(e) {
|
|
53
|
+
var t;
|
|
54
|
+
return (e == null ? void 0 : e.name) === "TypeError" && ((t = e == null ? void 0 : e.message) == null ? void 0 : t.includes("Failed to fetch"));
|
|
55
|
+
}
|
|
56
|
+
rethrowNetworkError(e) {
|
|
57
|
+
if (this.hasFailedToFetch(e))
|
|
58
|
+
throw new Error(T);
|
|
59
|
+
}
|
|
60
|
+
async fetchWithNetworkErrorHandling(e, t) {
|
|
61
|
+
try {
|
|
62
|
+
return await fetch(e, t);
|
|
63
|
+
} catch (s) {
|
|
64
|
+
throw this.rethrowNetworkError(s), s;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async requestJsonOrThrow(e, t, s) {
|
|
68
|
+
try {
|
|
69
|
+
const i = await fetch(e, {
|
|
70
|
+
...this.getFetchOptions(t)
|
|
71
|
+
});
|
|
72
|
+
if (!i.ok) {
|
|
73
|
+
const r = await i.text();
|
|
74
|
+
throw new Error(`${s}: ${i.status} ${r}`);
|
|
75
|
+
}
|
|
76
|
+
return await i.json();
|
|
77
|
+
} catch (i) {
|
|
78
|
+
throw this.rethrowNetworkError(i), i;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
getRequiredApiKey(e) {
|
|
82
|
+
if (!this.apiKey)
|
|
83
|
+
throw new Error(e);
|
|
84
|
+
return this.apiKey;
|
|
85
|
+
}
|
|
38
86
|
/**
|
|
39
87
|
* Validate that the API key exists and is active.
|
|
40
88
|
*
|
|
@@ -42,63 +90,59 @@ class N {
|
|
|
42
90
|
* @throws Error if API key is not provided, invalid, inactive, or validation fails
|
|
43
91
|
*/
|
|
44
92
|
async validateApiKey() {
|
|
45
|
-
|
|
46
|
-
if (!this.apiKey)
|
|
47
|
-
throw new Error("API key is required for validation");
|
|
93
|
+
const e = this.getRequiredApiKey("API key is required for validation");
|
|
48
94
|
try {
|
|
49
|
-
const
|
|
95
|
+
const t = await this.fetchWithNetworkErrorHandling(`${this.apiUrl}/admin/api-keys/${e}/status`, {
|
|
50
96
|
...this.getFetchOptions({
|
|
51
97
|
method: "GET"
|
|
52
98
|
})
|
|
53
|
-
}).catch((s) => {
|
|
54
|
-
throw s.name === "TypeError" && s.message.includes("Failed to fetch") ? new Error("Could not connect to the server. Please check if the server is running.") : s;
|
|
55
99
|
});
|
|
56
|
-
if (!
|
|
57
|
-
let
|
|
100
|
+
if (!t.ok) {
|
|
101
|
+
let i = "";
|
|
58
102
|
try {
|
|
59
|
-
|
|
103
|
+
i = await t.text();
|
|
60
104
|
} catch {
|
|
61
|
-
|
|
105
|
+
i = `HTTP ${t.status}`;
|
|
62
106
|
}
|
|
63
|
-
let
|
|
107
|
+
let r, a;
|
|
64
108
|
try {
|
|
65
|
-
const
|
|
66
|
-
|
|
109
|
+
const d = JSON.parse(i);
|
|
110
|
+
r = d.detail || d.message || i;
|
|
67
111
|
} catch {
|
|
68
|
-
|
|
112
|
+
r = i || `HTTP ${t.status}`;
|
|
69
113
|
}
|
|
70
|
-
switch (
|
|
114
|
+
switch (t.status) {
|
|
71
115
|
case 401:
|
|
72
|
-
|
|
116
|
+
a = "API key is invalid or expired";
|
|
73
117
|
break;
|
|
74
118
|
case 403:
|
|
75
|
-
|
|
119
|
+
a = "Access denied: API key does not have required permissions";
|
|
76
120
|
break;
|
|
77
121
|
case 404:
|
|
78
|
-
|
|
122
|
+
a = "API key not found";
|
|
79
123
|
break;
|
|
80
124
|
case 503:
|
|
81
|
-
|
|
125
|
+
a = "API key management is not available in inference-only mode";
|
|
82
126
|
break;
|
|
83
127
|
default:
|
|
84
|
-
|
|
128
|
+
a = `Failed to validate API key: ${r}`;
|
|
85
129
|
break;
|
|
86
130
|
}
|
|
87
|
-
throw new Error(
|
|
131
|
+
throw new Error(a);
|
|
88
132
|
}
|
|
89
|
-
const
|
|
90
|
-
if (!
|
|
91
|
-
const
|
|
92
|
-
throw new Error(
|
|
133
|
+
const s = await t.json();
|
|
134
|
+
if (!s.exists) {
|
|
135
|
+
const i = "API key does not exist";
|
|
136
|
+
throw new Error(i);
|
|
93
137
|
}
|
|
94
|
-
if (!
|
|
95
|
-
const
|
|
96
|
-
throw new Error(
|
|
138
|
+
if (!s.active) {
|
|
139
|
+
const i = "API key is inactive";
|
|
140
|
+
throw new Error(i);
|
|
97
141
|
}
|
|
98
|
-
return
|
|
99
|
-
} catch (
|
|
100
|
-
let
|
|
101
|
-
throw
|
|
142
|
+
return s;
|
|
143
|
+
} catch (t) {
|
|
144
|
+
let s;
|
|
145
|
+
throw t instanceof Error && t.message ? t.message.includes("API key") || t.message.includes("Access denied") || t.message.includes("invalid") || t.message.includes("expired") || t.message.includes("inactive") || t.message.includes("not found") || t.message.includes("Could not connect") ? s = t.message : s = `API key validation failed: ${t.message}` : this.hasFailedToFetch(t) ? s = T : s = "API key validation failed. Please check your API key and try again.", console.warn(`[ApiClient] ${s}`), new Error(s);
|
|
102
146
|
}
|
|
103
147
|
}
|
|
104
148
|
/**
|
|
@@ -111,16 +155,12 @@ class N {
|
|
|
111
155
|
* @throws Error if API key is not provided, invalid, disabled, or request fails
|
|
112
156
|
*/
|
|
113
157
|
async getAdapterInfo() {
|
|
114
|
-
|
|
115
|
-
if (!this.apiKey)
|
|
116
|
-
throw new Error("API key is required to get adapter information");
|
|
158
|
+
this.getRequiredApiKey("API key is required to get adapter information");
|
|
117
159
|
try {
|
|
118
|
-
const e = await
|
|
160
|
+
const e = await this.fetchWithNetworkErrorHandling(`${this.apiUrl}/admin/adapters/info`, {
|
|
119
161
|
...this.getFetchOptions({
|
|
120
162
|
method: "GET"
|
|
121
163
|
})
|
|
122
|
-
}).catch((s) => {
|
|
123
|
-
throw s.name === "TypeError" && s.message.includes("Failed to fetch") ? new Error("Could not connect to the server. Please check if the server is running.") : s;
|
|
124
164
|
});
|
|
125
165
|
if (!e.ok) {
|
|
126
166
|
let s = "";
|
|
@@ -129,185 +169,231 @@ class N {
|
|
|
129
169
|
} catch {
|
|
130
170
|
s = `HTTP ${e.status}`;
|
|
131
171
|
}
|
|
132
|
-
let i,
|
|
172
|
+
let i, r;
|
|
133
173
|
try {
|
|
134
|
-
const
|
|
135
|
-
i =
|
|
174
|
+
const a = JSON.parse(s);
|
|
175
|
+
i = a.detail || a.message || s;
|
|
136
176
|
} catch {
|
|
137
177
|
i = s || `HTTP ${e.status}`;
|
|
138
178
|
}
|
|
139
179
|
switch (e.status) {
|
|
140
180
|
case 401:
|
|
141
|
-
|
|
181
|
+
r = "API key is invalid, disabled, or has no associated adapter";
|
|
142
182
|
break;
|
|
143
183
|
case 404:
|
|
144
|
-
|
|
184
|
+
r = "Adapter configuration not found";
|
|
145
185
|
break;
|
|
146
186
|
case 503:
|
|
147
|
-
|
|
187
|
+
r = "Service is not available";
|
|
148
188
|
break;
|
|
149
189
|
default:
|
|
150
|
-
|
|
190
|
+
r = `Failed to get adapter info: ${i}`;
|
|
151
191
|
break;
|
|
152
192
|
}
|
|
153
|
-
throw new Error(
|
|
193
|
+
throw new Error(r);
|
|
154
194
|
}
|
|
155
195
|
return await e.json();
|
|
156
196
|
} catch (e) {
|
|
157
197
|
let t;
|
|
158
|
-
throw e instanceof Error && e.message ? e.message.includes("API key") || e.message.includes("Adapter") || e.message.includes("invalid") || e.message.includes("disabled") || e.message.includes("not found") || e.message.includes("Could not connect") ? t = e.message : t = `Failed to get adapter info: ${e.message}` :
|
|
198
|
+
throw e instanceof Error && e.message ? e.message.includes("API key") || e.message.includes("Adapter") || e.message.includes("invalid") || e.message.includes("disabled") || e.message.includes("not found") || e.message.includes("Could not connect") ? t = e.message : t = `Failed to get adapter info: ${e.message}` : this.hasFailedToFetch(e) ? t = T : t = "Failed to get adapter information. Please try again.", console.warn(`[ApiClient] ${t}`), new Error(t);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Get autocomplete suggestions based on query prefix.
|
|
203
|
+
*
|
|
204
|
+
* Returns query suggestions based on nl_examples from intent adapter templates.
|
|
205
|
+
* This is useful for helping users discover available queries.
|
|
206
|
+
*
|
|
207
|
+
* @param query - The query prefix (minimum 3 characters)
|
|
208
|
+
* @param limit - Maximum number of suggestions (default: 5)
|
|
209
|
+
* @returns Promise resolving to autocomplete suggestions
|
|
210
|
+
*/
|
|
211
|
+
async getAutocompleteSuggestions(e, t = 5) {
|
|
212
|
+
if (e.length < 3)
|
|
213
|
+
return { suggestions: [], query: e };
|
|
214
|
+
const s = this.middlewareMode && !!this.adapterName;
|
|
215
|
+
if (!s && !this.apiKey)
|
|
216
|
+
return { suggestions: [], query: e };
|
|
217
|
+
try {
|
|
218
|
+
const i = new URLSearchParams();
|
|
219
|
+
i.set("q", e), i.set("limit", String(t));
|
|
220
|
+
let r, a;
|
|
221
|
+
if (s) {
|
|
222
|
+
if (!this.middlewareBaseUrl && typeof window > "u")
|
|
223
|
+
throw new Error("middlewareBaseUrl must be set when using middleware outside the browser environment.");
|
|
224
|
+
r = `${this.middlewareBaseUrl ? this.middlewareBaseUrl : ""}/api/v1/autocomplete?${i.toString()}`;
|
|
225
|
+
const u = {
|
|
226
|
+
"X-Adapter-Name": this.adapterName,
|
|
227
|
+
"X-Request-ID": Date.now().toString(36) + Math.random().toString(36).substring(2)
|
|
228
|
+
};
|
|
229
|
+
this.sessionId && (u["X-Session-ID"] = this.sessionId), a = {
|
|
230
|
+
method: "GET",
|
|
231
|
+
headers: u
|
|
232
|
+
};
|
|
233
|
+
} else {
|
|
234
|
+
const l = new URL(`${this.apiUrl}/v1/autocomplete`);
|
|
235
|
+
l.searchParams.set("q", e), l.searchParams.set("limit", String(t)), r = l.toString(), a = {
|
|
236
|
+
...this.getFetchOptions({
|
|
237
|
+
method: "GET"
|
|
238
|
+
})
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
const d = await fetch(r, a);
|
|
242
|
+
return d.ok ? await d.json() : (console.warn("[ApiClient] Autocomplete request failed:", d.status), { suggestions: [], query: e });
|
|
243
|
+
} catch (i) {
|
|
244
|
+
return console.warn("[ApiClient] Autocomplete error:", i.message), { suggestions: [], query: e };
|
|
159
245
|
}
|
|
160
246
|
}
|
|
161
247
|
// Helper to get fetch options with connection pooling if available
|
|
162
|
-
getFetchOptions(
|
|
163
|
-
const
|
|
248
|
+
getFetchOptions(e = {}) {
|
|
249
|
+
const t = {};
|
|
164
250
|
if (typeof window > "u") {
|
|
165
|
-
const
|
|
166
|
-
|
|
251
|
+
const r = this.apiUrl.startsWith("https:") ? $ : b;
|
|
252
|
+
r && (t.agent = r);
|
|
167
253
|
} else
|
|
168
|
-
|
|
169
|
-
const
|
|
254
|
+
t.headers = { Connection: "keep-alive" };
|
|
255
|
+
const s = {
|
|
170
256
|
"X-Request-ID": Date.now().toString(36) + Math.random().toString(36).substring(2)
|
|
171
257
|
};
|
|
172
|
-
if (
|
|
173
|
-
const
|
|
174
|
-
for (const [
|
|
175
|
-
(
|
|
258
|
+
if (t.headers && Object.assign(s, t.headers), e.headers) {
|
|
259
|
+
const i = e.headers;
|
|
260
|
+
for (const [r, a] of Object.entries(i))
|
|
261
|
+
(r.toLowerCase() !== "x-api-key" || !this.apiKey) && (s[r] = a);
|
|
176
262
|
}
|
|
177
|
-
return this.apiKey && (
|
|
178
|
-
...r,
|
|
263
|
+
return this.apiKey && (s["X-API-Key"] = this.apiKey), this.sessionId && (s["X-Session-ID"] = this.sessionId), {
|
|
179
264
|
...e,
|
|
180
|
-
|
|
265
|
+
...t,
|
|
266
|
+
headers: s
|
|
181
267
|
};
|
|
182
268
|
}
|
|
183
269
|
// Create Chat request
|
|
184
|
-
createChatRequest(
|
|
270
|
+
createChatRequest(e, t = !0, s, i, r, a, d, l, w, u, m) {
|
|
185
271
|
const c = {
|
|
186
272
|
messages: [
|
|
187
|
-
{ role: "user", content:
|
|
273
|
+
{ role: "user", content: e }
|
|
188
274
|
],
|
|
189
|
-
stream:
|
|
275
|
+
stream: t
|
|
190
276
|
};
|
|
191
|
-
return
|
|
277
|
+
return s && s.length > 0 && (c.file_ids = s), i && (c.thread_id = i), r && (c.audio_input = r), a && (c.audio_format = a), d && (c.language = d), l !== void 0 && (c.return_audio = l), w && (c.tts_voice = w), u && (c.source_language = u), m && (c.target_language = m), c;
|
|
192
278
|
}
|
|
193
|
-
async *streamChat(
|
|
194
|
-
var
|
|
279
|
+
async *streamChat(e, t = !0, s, i, r, a, d, l, w, u, m, c) {
|
|
280
|
+
var q, U, K;
|
|
195
281
|
try {
|
|
196
|
-
const
|
|
197
|
-
c && c.addEventListener("abort", () =>
|
|
198
|
-
const
|
|
282
|
+
const y = new AbortController(), S = setTimeout(() => y.abort(), J);
|
|
283
|
+
c && c.addEventListener("abort", () => y.abort());
|
|
284
|
+
const A = await fetch(`${this.apiUrl}/v1/chat`, {
|
|
199
285
|
...this.getFetchOptions({
|
|
200
286
|
method: "POST",
|
|
201
287
|
headers: {
|
|
202
288
|
"Content-Type": "application/json",
|
|
203
|
-
Accept:
|
|
289
|
+
Accept: t ? "text/event-stream" : "application/json"
|
|
204
290
|
},
|
|
205
291
|
body: JSON.stringify(this.createChatRequest(
|
|
206
|
-
r,
|
|
207
292
|
e,
|
|
208
293
|
t,
|
|
209
294
|
s,
|
|
210
295
|
i,
|
|
211
|
-
|
|
212
|
-
|
|
296
|
+
r,
|
|
297
|
+
a,
|
|
213
298
|
d,
|
|
299
|
+
l,
|
|
300
|
+
w,
|
|
214
301
|
u,
|
|
215
|
-
|
|
216
|
-
g
|
|
302
|
+
m
|
|
217
303
|
))
|
|
218
304
|
}),
|
|
219
|
-
signal:
|
|
305
|
+
signal: y.signal
|
|
220
306
|
});
|
|
221
|
-
if (clearTimeout(S), !
|
|
222
|
-
const
|
|
223
|
-
throw new Error(`Network response was not ok: ${
|
|
307
|
+
if (clearTimeout(S), !A.ok) {
|
|
308
|
+
const f = await A.text();
|
|
309
|
+
throw new Error(`Network response was not ok: ${A.status} ${f}`);
|
|
224
310
|
}
|
|
225
|
-
if (!
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
text:
|
|
311
|
+
if (!t) {
|
|
312
|
+
const f = await A.json();
|
|
313
|
+
f.response && (yield {
|
|
314
|
+
text: f.response,
|
|
229
315
|
done: !0,
|
|
230
|
-
audio:
|
|
231
|
-
audioFormat:
|
|
316
|
+
audio: f.audio,
|
|
317
|
+
audioFormat: f.audio_format
|
|
232
318
|
});
|
|
233
319
|
return;
|
|
234
320
|
}
|
|
235
|
-
const
|
|
236
|
-
if (!
|
|
237
|
-
const
|
|
238
|
-
let
|
|
321
|
+
const P = (q = A.body) == null ? void 0 : q.getReader();
|
|
322
|
+
if (!P) throw new Error("No reader available");
|
|
323
|
+
const N = new TextDecoder();
|
|
324
|
+
let p = "", E = !1;
|
|
239
325
|
try {
|
|
240
326
|
for (; ; ) {
|
|
241
|
-
const { done:
|
|
242
|
-
if (
|
|
327
|
+
const { done: f, value: _ } = await P.read();
|
|
328
|
+
if (f)
|
|
243
329
|
break;
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
let
|
|
247
|
-
for (; (F =
|
|
248
|
-
`,
|
|
249
|
-
const
|
|
250
|
-
if (
|
|
251
|
-
const h =
|
|
330
|
+
const R = N.decode(_, { stream: !0 });
|
|
331
|
+
p += R;
|
|
332
|
+
let k = 0, F;
|
|
333
|
+
for (; (F = p.indexOf(`
|
|
334
|
+
`, k)) !== -1; ) {
|
|
335
|
+
const I = p.slice(k, F).trim();
|
|
336
|
+
if (k = F + 1, I && I.startsWith("data: ")) {
|
|
337
|
+
const h = I.slice(6).trim();
|
|
252
338
|
if (!h || h === "[DONE]") {
|
|
253
339
|
yield { text: "", done: !0 };
|
|
254
340
|
return;
|
|
255
341
|
}
|
|
256
342
|
try {
|
|
257
|
-
const
|
|
258
|
-
if (
|
|
259
|
-
const
|
|
260
|
-
throw console.warn(`[ApiClient] ${
|
|
343
|
+
const n = JSON.parse(h);
|
|
344
|
+
if (n.error) {
|
|
345
|
+
const C = `Server error: ${((U = n.error) == null ? void 0 : U.message) || n.error || "Unknown server error"}`;
|
|
346
|
+
throw console.warn(`[ApiClient] ${C}`), new Error(C);
|
|
261
347
|
}
|
|
262
|
-
if (
|
|
348
|
+
if (n.request_id && !n.response && !n.done) {
|
|
263
349
|
yield {
|
|
264
350
|
text: "",
|
|
265
351
|
done: !1,
|
|
266
|
-
request_id:
|
|
352
|
+
request_id: n.request_id
|
|
267
353
|
};
|
|
268
354
|
continue;
|
|
269
355
|
}
|
|
270
|
-
if (
|
|
271
|
-
|
|
356
|
+
if (n.done === !0) {
|
|
357
|
+
E = !0, yield {
|
|
272
358
|
text: "",
|
|
273
359
|
done: !0,
|
|
274
|
-
audio:
|
|
275
|
-
audioFormat:
|
|
276
|
-
threading:
|
|
360
|
+
audio: n.audio,
|
|
361
|
+
audioFormat: n.audio_format || n.audioFormat,
|
|
362
|
+
threading: n.threading
|
|
277
363
|
// Pass through threading metadata
|
|
278
364
|
};
|
|
279
365
|
return;
|
|
280
366
|
}
|
|
281
|
-
const O =
|
|
282
|
-
|
|
367
|
+
const O = n.response || "";
|
|
368
|
+
n.audio_chunk !== void 0 && (yield {
|
|
283
369
|
text: "",
|
|
284
370
|
done: !1,
|
|
285
|
-
audio_chunk:
|
|
286
|
-
audioFormat:
|
|
287
|
-
chunk_index:
|
|
288
|
-
}), (O ||
|
|
371
|
+
audio_chunk: n.audio_chunk,
|
|
372
|
+
audioFormat: n.audioFormat || n.audio_format || "opus",
|
|
373
|
+
chunk_index: n.chunk_index ?? 0
|
|
374
|
+
}), (O || n.audio) && (E = !0, yield {
|
|
289
375
|
text: O,
|
|
290
|
-
done:
|
|
291
|
-
audio:
|
|
292
|
-
audioFormat:
|
|
293
|
-
threading:
|
|
376
|
+
done: n.done || !1,
|
|
377
|
+
audio: n.audio,
|
|
378
|
+
audioFormat: n.audio_format || n.audioFormat,
|
|
379
|
+
threading: n.threading
|
|
294
380
|
// Include threading if present
|
|
295
381
|
});
|
|
296
|
-
} catch (
|
|
297
|
-
if ((
|
|
298
|
-
throw
|
|
299
|
-
console.warn("[ApiClient] Unable to parse server response. This may be a temporary issue."), console.warn("[ApiClient] Parse error details:",
|
|
382
|
+
} catch (n) {
|
|
383
|
+
if ((K = n == null ? void 0 : n.message) != null && K.startsWith("Server error:"))
|
|
384
|
+
throw n;
|
|
385
|
+
console.warn("[ApiClient] Unable to parse server response. This may be a temporary issue."), console.warn("[ApiClient] Parse error details:", n == null ? void 0 : n.message), console.warn("[ApiClient] JSON text length:", h == null ? void 0 : h.length), console.warn("[ApiClient] JSON text preview (first 200 chars):", h == null ? void 0 : h.substring(0, 200)), console.warn("[ApiClient] JSON text preview (last 200 chars):", h == null ? void 0 : h.substring(h.length - 200));
|
|
300
386
|
}
|
|
301
|
-
} else
|
|
387
|
+
} else I && (E = !0, yield { text: I, done: !1 });
|
|
302
388
|
}
|
|
303
|
-
|
|
389
|
+
p = p.slice(k), p.length > D && (console.warn("[ApiClient] Buffer too large, truncating..."), p = p.slice(-H));
|
|
304
390
|
}
|
|
305
|
-
|
|
391
|
+
E && (yield { text: "", done: !0 });
|
|
306
392
|
} finally {
|
|
307
|
-
|
|
393
|
+
P.releaseLock();
|
|
308
394
|
}
|
|
309
|
-
} catch (
|
|
310
|
-
throw
|
|
395
|
+
} catch (y) {
|
|
396
|
+
throw y.name === "AbortError" ? c != null && c.aborted ? new Error("Stream cancelled by user") : new Error("Connection timed out. Please check if the server is running.") : this.hasFailedToFetch(y) ? new Error(T) : y;
|
|
311
397
|
}
|
|
312
398
|
}
|
|
313
399
|
/**
|
|
@@ -317,107 +403,82 @@ class N {
|
|
|
317
403
|
* @param requestId - The request identifier (from first stream chunk)
|
|
318
404
|
* @returns Promise resolving to true if stream was cancelled, false otherwise
|
|
319
405
|
*/
|
|
320
|
-
async stopChat(
|
|
406
|
+
async stopChat(e, t) {
|
|
321
407
|
try {
|
|
322
|
-
const
|
|
408
|
+
const s = await fetch(`${this.apiUrl}/v1/chat/stop`, {
|
|
323
409
|
...this.getFetchOptions({
|
|
324
410
|
method: "POST",
|
|
325
411
|
headers: {
|
|
326
412
|
"Content-Type": "application/json"
|
|
327
413
|
},
|
|
328
414
|
body: JSON.stringify({
|
|
329
|
-
session_id:
|
|
330
|
-
request_id:
|
|
415
|
+
session_id: e,
|
|
416
|
+
request_id: t
|
|
331
417
|
})
|
|
332
418
|
})
|
|
333
419
|
});
|
|
334
|
-
return
|
|
335
|
-
} catch (
|
|
336
|
-
return console.error("[ApiClient] Error stopping stream:",
|
|
420
|
+
return s.ok ? (await s.json()).status === "cancelled" : (console.warn("[ApiClient] Failed to stop stream:", s.status), !1);
|
|
421
|
+
} catch (s) {
|
|
422
|
+
return console.error("[ApiClient] Error stopping stream:", s), !1;
|
|
337
423
|
}
|
|
338
424
|
}
|
|
339
|
-
async getConversationHistory(
|
|
340
|
-
const
|
|
341
|
-
if (!
|
|
425
|
+
async getConversationHistory(e, t) {
|
|
426
|
+
const s = e || this.sessionId;
|
|
427
|
+
if (!s)
|
|
342
428
|
throw new Error("No session ID provided and no current session available");
|
|
343
|
-
const
|
|
344
|
-
this.apiKey && (
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
session_id: (o == null ? void 0 : o.session_id) || t,
|
|
361
|
-
messages: d,
|
|
362
|
-
count: u
|
|
363
|
-
};
|
|
364
|
-
} catch (i) {
|
|
365
|
-
throw i.name === "TypeError" && i.message.includes("Failed to fetch") ? new Error("Could not connect to the server. Please check if the server is running.") : i;
|
|
366
|
-
}
|
|
429
|
+
const i = {};
|
|
430
|
+
this.apiKey && (i["X-API-Key"] = this.apiKey);
|
|
431
|
+
const r = new URL(`${this.apiUrl}/admin/chat-history/${s}`);
|
|
432
|
+
typeof t == "number" && Number.isFinite(t) && t > 0 && r.searchParams.set("limit", String(Math.floor(t)));
|
|
433
|
+
const a = await this.requestJsonOrThrow(
|
|
434
|
+
r.toString(),
|
|
435
|
+
{
|
|
436
|
+
method: "GET",
|
|
437
|
+
headers: i
|
|
438
|
+
},
|
|
439
|
+
"Failed to fetch conversation history"
|
|
440
|
+
), d = Array.isArray(a == null ? void 0 : a.messages) ? a.messages : [], l = typeof (a == null ? void 0 : a.count) == "number" ? a.count : d.length;
|
|
441
|
+
return {
|
|
442
|
+
session_id: (a == null ? void 0 : a.session_id) || s,
|
|
443
|
+
messages: d,
|
|
444
|
+
count: l
|
|
445
|
+
};
|
|
367
446
|
}
|
|
368
|
-
async clearConversationHistory(
|
|
369
|
-
const
|
|
370
|
-
if (!
|
|
447
|
+
async clearConversationHistory(e) {
|
|
448
|
+
const t = e || this.sessionId;
|
|
449
|
+
if (!t)
|
|
371
450
|
throw new Error("No session ID provided and no current session available");
|
|
372
|
-
|
|
373
|
-
throw new Error("API key is required for clearing conversation history");
|
|
374
|
-
const t = {
|
|
451
|
+
const s = this.getRequiredApiKey("API key is required for clearing conversation history"), i = {
|
|
375
452
|
"Content-Type": "application/json",
|
|
376
|
-
"X-Session-ID":
|
|
377
|
-
"X-API-Key":
|
|
453
|
+
"X-Session-ID": t,
|
|
454
|
+
"X-API-Key": s
|
|
378
455
|
};
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
const n = await s.text();
|
|
388
|
-
throw new Error(`Failed to clear conversation history: ${s.status} ${n}`);
|
|
389
|
-
}
|
|
390
|
-
return await s.json();
|
|
391
|
-
} catch (s) {
|
|
392
|
-
throw s.name === "TypeError" && s.message.includes("Failed to fetch") ? new Error("Could not connect to the server. Please check if the server is running.") : s;
|
|
393
|
-
}
|
|
456
|
+
return await this.requestJsonOrThrow(
|
|
457
|
+
`${this.apiUrl}/admin/chat-history/${t}`,
|
|
458
|
+
{
|
|
459
|
+
method: "DELETE",
|
|
460
|
+
headers: i
|
|
461
|
+
},
|
|
462
|
+
"Failed to clear conversation history"
|
|
463
|
+
);
|
|
394
464
|
}
|
|
395
|
-
async deleteConversationWithFiles(
|
|
396
|
-
const
|
|
397
|
-
if (!
|
|
465
|
+
async deleteConversationWithFiles(e, t) {
|
|
466
|
+
const s = e || this.sessionId;
|
|
467
|
+
if (!s)
|
|
398
468
|
throw new Error("No session ID provided and no current session available");
|
|
399
|
-
|
|
400
|
-
throw new Error("API key is required for deleting conversation");
|
|
401
|
-
const s = {
|
|
469
|
+
const i = this.getRequiredApiKey("API key is required for deleting conversation"), r = {
|
|
402
470
|
"Content-Type": "application/json",
|
|
403
|
-
"X-Session-ID":
|
|
404
|
-
"X-API-Key":
|
|
405
|
-
},
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
const u = await o.text();
|
|
415
|
-
throw new Error(`Failed to delete conversation: ${o.status} ${u}`);
|
|
416
|
-
}
|
|
417
|
-
return await o.json();
|
|
418
|
-
} catch (o) {
|
|
419
|
-
throw o.name === "TypeError" && o.message.includes("Failed to fetch") ? new Error("Could not connect to the server. Please check if the server is running.") : o;
|
|
420
|
-
}
|
|
471
|
+
"X-Session-ID": s,
|
|
472
|
+
"X-API-Key": i
|
|
473
|
+
}, a = t && t.length > 0 ? `?file_ids=${t.join(",")}` : "", d = `${this.apiUrl}/admin/conversations/${s}${a}`;
|
|
474
|
+
return await this.requestJsonOrThrow(
|
|
475
|
+
d,
|
|
476
|
+
{
|
|
477
|
+
method: "DELETE",
|
|
478
|
+
headers: r
|
|
479
|
+
},
|
|
480
|
+
"Failed to delete conversation"
|
|
481
|
+
);
|
|
421
482
|
}
|
|
422
483
|
/**
|
|
423
484
|
* Create a conversation thread from a parent message.
|
|
@@ -427,32 +488,23 @@ class N {
|
|
|
427
488
|
* @returns Promise resolving to thread information
|
|
428
489
|
* @throws Error if the operation fails
|
|
429
490
|
*/
|
|
430
|
-
async createThread(
|
|
431
|
-
|
|
432
|
-
throw new Error("API key is required for creating threads");
|
|
433
|
-
const t = {
|
|
491
|
+
async createThread(e, t) {
|
|
492
|
+
const i = {
|
|
434
493
|
"Content-Type": "application/json",
|
|
435
|
-
"X-API-Key": this.
|
|
494
|
+
"X-API-Key": this.getRequiredApiKey("API key is required for creating threads")
|
|
436
495
|
};
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
})
|
|
496
|
+
return await this.requestJsonOrThrow(
|
|
497
|
+
`${this.apiUrl}/api/threads`,
|
|
498
|
+
{
|
|
499
|
+
method: "POST",
|
|
500
|
+
headers: i,
|
|
501
|
+
body: JSON.stringify({
|
|
502
|
+
message_id: e,
|
|
503
|
+
session_id: t
|
|
446
504
|
})
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
throw new Error(`Failed to create thread: ${s.status} ${n}`);
|
|
451
|
-
}
|
|
452
|
-
return await s.json();
|
|
453
|
-
} catch (s) {
|
|
454
|
-
throw s.name === "TypeError" && s.message.includes("Failed to fetch") ? new Error("Could not connect to the server. Please check if the server is running.") : s;
|
|
455
|
-
}
|
|
505
|
+
},
|
|
506
|
+
"Failed to create thread"
|
|
507
|
+
);
|
|
456
508
|
}
|
|
457
509
|
/**
|
|
458
510
|
* Get thread information by thread ID.
|
|
@@ -461,27 +513,18 @@ class N {
|
|
|
461
513
|
* @returns Promise resolving to thread information
|
|
462
514
|
* @throws Error if the operation fails
|
|
463
515
|
*/
|
|
464
|
-
async getThreadInfo(
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
const e = {
|
|
468
|
-
"X-API-Key": this.apiKey
|
|
516
|
+
async getThreadInfo(e) {
|
|
517
|
+
const s = {
|
|
518
|
+
"X-API-Key": this.getRequiredApiKey("API key is required for getting thread info")
|
|
469
519
|
};
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
const i = await t.text();
|
|
479
|
-
throw new Error(`Failed to get thread info: ${t.status} ${i}`);
|
|
480
|
-
}
|
|
481
|
-
return await t.json();
|
|
482
|
-
} catch (t) {
|
|
483
|
-
throw t.name === "TypeError" && t.message.includes("Failed to fetch") ? new Error("Could not connect to the server. Please check if the server is running.") : t;
|
|
484
|
-
}
|
|
520
|
+
return await this.requestJsonOrThrow(
|
|
521
|
+
`${this.apiUrl}/api/threads/${e}`,
|
|
522
|
+
{
|
|
523
|
+
method: "GET",
|
|
524
|
+
headers: s
|
|
525
|
+
},
|
|
526
|
+
"Failed to get thread info"
|
|
527
|
+
);
|
|
485
528
|
}
|
|
486
529
|
/**
|
|
487
530
|
* Delete a thread and its associated dataset.
|
|
@@ -490,27 +533,18 @@ class N {
|
|
|
490
533
|
* @returns Promise resolving to deletion result
|
|
491
534
|
* @throws Error if the operation fails
|
|
492
535
|
*/
|
|
493
|
-
async deleteThread(
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
const e = {
|
|
497
|
-
"X-API-Key": this.apiKey
|
|
536
|
+
async deleteThread(e) {
|
|
537
|
+
const s = {
|
|
538
|
+
"X-API-Key": this.getRequiredApiKey("API key is required for deleting threads")
|
|
498
539
|
};
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
const i = await t.text();
|
|
508
|
-
throw new Error(`Failed to delete thread: ${t.status} ${i}`);
|
|
509
|
-
}
|
|
510
|
-
return await t.json();
|
|
511
|
-
} catch (t) {
|
|
512
|
-
throw t.name === "TypeError" && t.message.includes("Failed to fetch") ? new Error("Could not connect to the server. Please check if the server is running.") : t;
|
|
513
|
-
}
|
|
540
|
+
return await this.requestJsonOrThrow(
|
|
541
|
+
`${this.apiUrl}/api/threads/${e}`,
|
|
542
|
+
{
|
|
543
|
+
method: "DELETE",
|
|
544
|
+
headers: s
|
|
545
|
+
},
|
|
546
|
+
"Failed to delete thread"
|
|
547
|
+
);
|
|
514
548
|
}
|
|
515
549
|
/**
|
|
516
550
|
* Upload a file for processing and indexing.
|
|
@@ -519,26 +553,17 @@ class N {
|
|
|
519
553
|
* @returns Promise resolving to upload response with file_id
|
|
520
554
|
* @throws Error if upload fails
|
|
521
555
|
*/
|
|
522
|
-
async uploadFile(
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
});
|
|
534
|
-
if (!t.ok) {
|
|
535
|
-
const s = await t.text();
|
|
536
|
-
throw new Error(`Failed to upload file: ${t.status} ${s}`);
|
|
537
|
-
}
|
|
538
|
-
return await t.json();
|
|
539
|
-
} catch (t) {
|
|
540
|
-
throw t.name === "TypeError" && t.message.includes("Failed to fetch") ? new Error("Could not connect to the server. Please check if the server is running.") : t;
|
|
541
|
-
}
|
|
556
|
+
async uploadFile(e) {
|
|
557
|
+
this.getRequiredApiKey("API key is required for file upload");
|
|
558
|
+
const t = new FormData();
|
|
559
|
+
return t.append("file", e), await this.requestJsonOrThrow(
|
|
560
|
+
`${this.apiUrl}/api/files/upload`,
|
|
561
|
+
{
|
|
562
|
+
method: "POST",
|
|
563
|
+
body: t
|
|
564
|
+
},
|
|
565
|
+
"Failed to upload file"
|
|
566
|
+
);
|
|
542
567
|
}
|
|
543
568
|
/**
|
|
544
569
|
* List all files for the current API key.
|
|
@@ -547,22 +572,13 @@ class N {
|
|
|
547
572
|
* @throws Error if request fails
|
|
548
573
|
*/
|
|
549
574
|
async listFiles() {
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
});
|
|
558
|
-
if (!r.ok) {
|
|
559
|
-
const e = await r.text();
|
|
560
|
-
throw new Error(`Failed to list files: ${r.status} ${e}`);
|
|
561
|
-
}
|
|
562
|
-
return await r.json();
|
|
563
|
-
} catch (r) {
|
|
564
|
-
throw r.name === "TypeError" && r.message.includes("Failed to fetch") ? new Error("Could not connect to the server. Please check if the server is running.") : r;
|
|
565
|
-
}
|
|
575
|
+
return this.getRequiredApiKey("API key is required for listing files"), await this.requestJsonOrThrow(
|
|
576
|
+
`${this.apiUrl}/api/files`,
|
|
577
|
+
{
|
|
578
|
+
method: "GET"
|
|
579
|
+
},
|
|
580
|
+
"Failed to list files"
|
|
581
|
+
);
|
|
566
582
|
}
|
|
567
583
|
/**
|
|
568
584
|
* Get information about a specific file.
|
|
@@ -571,23 +587,14 @@ class N {
|
|
|
571
587
|
* @returns Promise resolving to file information
|
|
572
588
|
* @throws Error if file not found or request fails
|
|
573
589
|
*/
|
|
574
|
-
async getFileInfo(
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
});
|
|
583
|
-
if (!e.ok) {
|
|
584
|
-
const t = await e.text();
|
|
585
|
-
throw new Error(`Failed to get file info: ${e.status} ${t}`);
|
|
586
|
-
}
|
|
587
|
-
return await e.json();
|
|
588
|
-
} catch (e) {
|
|
589
|
-
throw e.name === "TypeError" && e.message.includes("Failed to fetch") ? new Error("Could not connect to the server. Please check if the server is running.") : e;
|
|
590
|
-
}
|
|
590
|
+
async getFileInfo(e) {
|
|
591
|
+
return this.getRequiredApiKey("API key is required for getting file info"), await this.requestJsonOrThrow(
|
|
592
|
+
`${this.apiUrl}/api/files/${e}`,
|
|
593
|
+
{
|
|
594
|
+
method: "GET"
|
|
595
|
+
},
|
|
596
|
+
"Failed to get file info"
|
|
597
|
+
);
|
|
591
598
|
}
|
|
592
599
|
/**
|
|
593
600
|
* Query a specific file using semantic search.
|
|
@@ -598,27 +605,18 @@ class N {
|
|
|
598
605
|
* @returns Promise resolving to query results
|
|
599
606
|
* @throws Error if query fails
|
|
600
607
|
*/
|
|
601
|
-
async queryFile(
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
});
|
|
614
|
-
if (!s.ok) {
|
|
615
|
-
const i = await s.text();
|
|
616
|
-
throw new Error(`Failed to query file: ${s.status} ${i}`);
|
|
617
|
-
}
|
|
618
|
-
return await s.json();
|
|
619
|
-
} catch (s) {
|
|
620
|
-
throw s.name === "TypeError" && s.message.includes("Failed to fetch") ? new Error("Could not connect to the server. Please check if the server is running.") : s;
|
|
621
|
-
}
|
|
608
|
+
async queryFile(e, t, s = 10) {
|
|
609
|
+
return this.getRequiredApiKey("API key is required for querying files"), await this.requestJsonOrThrow(
|
|
610
|
+
`${this.apiUrl}/api/files/${e}/query`,
|
|
611
|
+
{
|
|
612
|
+
method: "POST",
|
|
613
|
+
headers: {
|
|
614
|
+
"Content-Type": "application/json"
|
|
615
|
+
},
|
|
616
|
+
body: JSON.stringify({ query: t, max_results: s })
|
|
617
|
+
},
|
|
618
|
+
"Failed to query file"
|
|
619
|
+
);
|
|
622
620
|
}
|
|
623
621
|
/**
|
|
624
622
|
* Delete a specific file.
|
|
@@ -627,63 +625,62 @@ class N {
|
|
|
627
625
|
* @returns Promise resolving to deletion result
|
|
628
626
|
* @throws Error if deletion fails
|
|
629
627
|
*/
|
|
630
|
-
async deleteFile(
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
const e = `${this.apiUrl}/api/files/${r}`, t = this.getFetchOptions({
|
|
628
|
+
async deleteFile(e) {
|
|
629
|
+
this.getRequiredApiKey("API key is required for deleting files");
|
|
630
|
+
const t = `${this.apiUrl}/api/files/${e}`, s = this.getFetchOptions({
|
|
634
631
|
method: "DELETE"
|
|
635
632
|
});
|
|
636
633
|
try {
|
|
637
|
-
const
|
|
638
|
-
if (!
|
|
639
|
-
const
|
|
640
|
-
let
|
|
634
|
+
const i = await fetch(t, s);
|
|
635
|
+
if (!i.ok) {
|
|
636
|
+
const a = await i.text();
|
|
637
|
+
let d;
|
|
641
638
|
try {
|
|
642
|
-
const
|
|
643
|
-
|
|
639
|
+
const l = JSON.parse(a);
|
|
640
|
+
d = l.detail || l.message || `Failed to delete file (HTTP ${i.status})`;
|
|
644
641
|
} catch {
|
|
645
|
-
|
|
642
|
+
d = `Failed to delete file (HTTP ${i.status})`;
|
|
646
643
|
}
|
|
647
|
-
throw console.warn(`[ApiClient] ${
|
|
644
|
+
throw console.warn(`[ApiClient] ${d}`), new Error(d);
|
|
648
645
|
}
|
|
649
|
-
return await
|
|
650
|
-
} catch (
|
|
651
|
-
let
|
|
652
|
-
throw
|
|
646
|
+
return await i.json();
|
|
647
|
+
} catch (i) {
|
|
648
|
+
let r;
|
|
649
|
+
throw this.hasFailedToFetch(i) ? r = T : i.message && !i.message.includes("Failed to delete file") ? r = i.message : r = "Failed to delete file. Please try again.", console.warn(`[ApiClient] ${r}`), new Error(r);
|
|
653
650
|
}
|
|
654
651
|
}
|
|
655
652
|
}
|
|
656
|
-
let
|
|
657
|
-
const
|
|
658
|
-
|
|
653
|
+
let v = null;
|
|
654
|
+
const j = (o, e = null, t = null) => {
|
|
655
|
+
v = new B({ apiUrl: o, apiKey: e, sessionId: t });
|
|
659
656
|
};
|
|
660
|
-
async function*
|
|
661
|
-
if (!
|
|
657
|
+
async function* G(o, e = !0, t, s, i, r, a, d, l, w, u, m) {
|
|
658
|
+
if (!v)
|
|
662
659
|
throw new Error("API not configured. Please call configureApi() with your server URL before using any API functions.");
|
|
663
|
-
yield*
|
|
664
|
-
|
|
665
|
-
r,
|
|
660
|
+
yield* v.streamChat(
|
|
661
|
+
o,
|
|
666
662
|
e,
|
|
667
663
|
t,
|
|
668
664
|
s,
|
|
669
665
|
i,
|
|
670
|
-
|
|
671
|
-
|
|
666
|
+
r,
|
|
667
|
+
a,
|
|
672
668
|
d,
|
|
669
|
+
l,
|
|
670
|
+
w,
|
|
673
671
|
u,
|
|
674
|
-
|
|
675
|
-
g
|
|
672
|
+
m
|
|
676
673
|
);
|
|
677
674
|
}
|
|
678
|
-
async function
|
|
679
|
-
if (!
|
|
675
|
+
async function W(o, e) {
|
|
676
|
+
if (!v)
|
|
680
677
|
throw new Error("API not configured. Please call configureApi() with your server URL before using any API functions.");
|
|
681
|
-
return
|
|
678
|
+
return v.stopChat(o, e);
|
|
682
679
|
}
|
|
683
680
|
export {
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
681
|
+
B as ApiClient,
|
|
682
|
+
j as configureApi,
|
|
683
|
+
W as stopChat,
|
|
684
|
+
G as streamChat
|
|
688
685
|
};
|
|
689
686
|
//# sourceMappingURL=api.mjs.map
|