research-agent-ui 0.1.82 → 0.1.84
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/handlers/chat-title.d.ts +9 -0
- package/dist/api/index.d.ts +1 -0
- package/dist/api.cjs +4 -4
- package/dist/api.mjs +114 -86
- package/dist/index.cjs +13 -13
- package/dist/index.mjs +1478 -1390
- package/dist/lib/chatTitle.d.ts +8 -0
- package/dist/lib/relative-time.d.ts +6 -0
- package/dist/types/research.d.ts +2 -0
- package/package.json +6 -6
package/dist/api.mjs
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import e from "chat-agent-toolkit/models/registry";
|
|
2
|
-
import { and as t, count as n, eq as r, inArray as i, like as a,
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
2
|
+
import { and as t, count as n, eq as r, inArray as i, like as a, max as o, or as s, sql as c } from "drizzle-orm";
|
|
3
|
+
import l from "chat-agent-toolkit/tools/search/titleGeneratorAgent";
|
|
4
|
+
import { searchSearxng as u, searchWeb as d } from "search-web-api/search/public-searxng";
|
|
5
|
+
import { searchAutocompleteMulti as f } from "extract-webpage/suggest-next-words/autocomplete-search-engines";
|
|
6
|
+
import p from "fuse.js";
|
|
7
|
+
import m from "domain-rank/data/domain-rank-merged.json";
|
|
8
|
+
import h from "chat-agent-toolkit/tools/search/suggestionGeneratorAgent";
|
|
9
|
+
import { testProviderModels as g } from "chat-agent-toolkit/config/model-tester";
|
|
10
|
+
import { LANGUAGE_MODELS as _ } from "chat-agent-toolkit/config/language-models-database";
|
|
10
11
|
//#region src/api/handlers/article-followups.ts
|
|
11
|
-
function
|
|
12
|
+
function v(t) {
|
|
12
13
|
return async (t) => {
|
|
13
14
|
try {
|
|
14
15
|
let { article: n, chatHistory: r = [], maxQuestions: i = 5, chatModel: a } = await t.json();
|
|
@@ -49,7 +50,7 @@ Generate ${i} follow-up questions that would help readers dive deeper into this
|
|
|
49
50
|
}
|
|
50
51
|
//#endregion
|
|
51
52
|
//#region src/api/handlers/article-qa.ts
|
|
52
|
-
function
|
|
53
|
+
function y(t) {
|
|
53
54
|
return async (t) => {
|
|
54
55
|
try {
|
|
55
56
|
let { article: n, question: r, chatHistory: i = [], chatModel: a } = await t.json();
|
|
@@ -89,34 +90,35 @@ Please provide a helpful answer based on the article content above.`, u = await
|
|
|
89
90
|
}
|
|
90
91
|
//#endregion
|
|
91
92
|
//#region src/api/handlers/chats.ts
|
|
92
|
-
function
|
|
93
|
-
let { chats: a, messages:
|
|
93
|
+
function b(e) {
|
|
94
|
+
let { chats: a, messages: s } = e.schema;
|
|
94
95
|
return {
|
|
95
96
|
GET: async (i) => {
|
|
96
97
|
try {
|
|
97
|
-
let i = e.getDB(),
|
|
98
|
+
let i = e.getDB(), l = await e.requireUserId(), u = await i.select({
|
|
98
99
|
id: a.id,
|
|
99
100
|
title: a.title,
|
|
100
101
|
createdAt: a.createdAt,
|
|
101
102
|
focusMode: a.focusMode,
|
|
102
103
|
userId: a.userId,
|
|
103
104
|
files: a.files,
|
|
104
|
-
messageCount: n(
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
messageCount: n(s.id),
|
|
106
|
+
lastMessageAt: o(s.createdAt)
|
|
107
|
+
}).from(a).leftJoin(s, t(r(s.chatId, a.id), r(s.role, "user"))).where(r(a.userId, l)).groupBy(a.id, a.title, a.createdAt, a.focusMode, a.userId, a.files).orderBy(c`${a.createdAt} DESC`);
|
|
108
|
+
return Response.json({ chats: u }, { status: 200 });
|
|
107
109
|
} catch (e) {
|
|
108
110
|
return e instanceof Error && e.message === "Unauthorized" ? Response.json({ message: "Authentication required" }, { status: 401 }) : (console.error("Error in getting chats: ", e), Response.json({ message: "An error has occurred." }, { status: 500 }));
|
|
109
111
|
}
|
|
110
112
|
},
|
|
111
113
|
DELETE: async (t) => {
|
|
112
114
|
try {
|
|
113
|
-
let t = e.getDB(), n = await e.requireUserId(),
|
|
115
|
+
let t = e.getDB(), n = await e.requireUserId(), o = await t.query.chats.findMany({
|
|
114
116
|
where: r(a.userId, n),
|
|
115
117
|
columns: { id: !0 }
|
|
116
118
|
});
|
|
117
|
-
if (
|
|
118
|
-
let e =
|
|
119
|
-
await t.delete(
|
|
119
|
+
if (o.length > 0) {
|
|
120
|
+
let e = o.map((e) => e.id);
|
|
121
|
+
await t.delete(s).where(i(s.chatId, e)), await t.delete(a).where(r(a.userId, n));
|
|
120
122
|
}
|
|
121
123
|
return Response.json({ message: "All chats deleted" }, { status: 200 });
|
|
122
124
|
} catch (e) {
|
|
@@ -125,7 +127,7 @@ function v(e) {
|
|
|
125
127
|
}
|
|
126
128
|
};
|
|
127
129
|
}
|
|
128
|
-
function
|
|
130
|
+
function x(e) {
|
|
129
131
|
let { chats: n, messages: i } = e.schema;
|
|
130
132
|
return {
|
|
131
133
|
GET: async (t, { params: a }) => {
|
|
@@ -158,11 +160,11 @@ function y(e) {
|
|
|
158
160
|
}
|
|
159
161
|
};
|
|
160
162
|
}
|
|
161
|
-
function
|
|
163
|
+
function S(e) {
|
|
162
164
|
let { chats: n, messages: i } = e.schema;
|
|
163
|
-
return { GET: async (
|
|
165
|
+
return { GET: async (o) => {
|
|
164
166
|
try {
|
|
165
|
-
let l = e.getDB(), u = await e.requireUserId(), { searchParams: d } = new URL(
|
|
167
|
+
let l = e.getDB(), u = await e.requireUserId(), { searchParams: d } = new URL(o.url), f = d.get("q");
|
|
166
168
|
if (!f || f.trim().length === 0) return Response.json({ chats: [] }, { status: 200 });
|
|
167
169
|
let p = `%${f.trim()}%`, m = await l.select({
|
|
168
170
|
id: n.id,
|
|
@@ -171,17 +173,17 @@ function b(e) {
|
|
|
171
173
|
focusMode: n.focusMode,
|
|
172
174
|
userId: n.userId,
|
|
173
175
|
files: n.files
|
|
174
|
-
}).from(n).where(t(r(n.userId, u), a(n.title, p))).orderBy(
|
|
176
|
+
}).from(n).where(t(r(n.userId, u), a(n.title, p))).orderBy(c`${n.createdAt} DESC`), h = await l.selectDistinct({
|
|
175
177
|
id: n.id,
|
|
176
178
|
title: n.title,
|
|
177
179
|
createdAt: n.createdAt,
|
|
178
180
|
focusMode: n.focusMode,
|
|
179
181
|
userId: n.userId,
|
|
180
182
|
files: n.files
|
|
181
|
-
}).from(i).innerJoin(n, r(i.chatId, n.id)).where(t(r(n.userId, u),
|
|
183
|
+
}).from(i).innerJoin(n, r(i.chatId, n.id)).where(t(r(n.userId, u), s(a(i.content, p)))).orderBy(c`${n.createdAt} DESC`), g = [...m, ...h], _ = Array.from(new Map(g.map((e) => [e.id, e])).values()), v = _.map((e) => e.id), y = v.length ? await l.select({
|
|
182
184
|
chatId: i.chatId,
|
|
183
|
-
count:
|
|
184
|
-
}).from(i).where(t(
|
|
185
|
+
count: c`count(*)`
|
|
186
|
+
}).from(i).where(t(c`${i.chatId} IN (${c.join(v.map((e) => c`${e}`), c`, `)})`, r(i.role, "user"))).groupBy(i.chatId) : [], b = new Map(y.map((e) => [e.chatId, Number(e.count)])), x = _.map((e) => ({
|
|
185
187
|
...e,
|
|
186
188
|
messageCount: b.get(e.id) || 0
|
|
187
189
|
}));
|
|
@@ -191,7 +193,7 @@ function b(e) {
|
|
|
191
193
|
}
|
|
192
194
|
} };
|
|
193
195
|
}
|
|
194
|
-
function
|
|
196
|
+
function C(e) {
|
|
195
197
|
let { chats: t } = e.schema;
|
|
196
198
|
return { POST: async (n) => {
|
|
197
199
|
try {
|
|
@@ -230,23 +232,49 @@ function x(e) {
|
|
|
230
232
|
} };
|
|
231
233
|
}
|
|
232
234
|
//#endregion
|
|
235
|
+
//#region src/api/handlers/chat-title.ts
|
|
236
|
+
function w(t) {
|
|
237
|
+
let { chats: n } = t.schema;
|
|
238
|
+
return { POST: async (i) => {
|
|
239
|
+
try {
|
|
240
|
+
let a = await i.json(), o = a.chatHistory.filter((e) => e.role === "user" || e.role === "assistant").map((e) => ({
|
|
241
|
+
role: e.role,
|
|
242
|
+
content: String(e.content ?? "")
|
|
243
|
+
}));
|
|
244
|
+
if (o.length === 0) return Response.json({ message: "No conversation content" }, { status: 400 });
|
|
245
|
+
let s = await new e().loadChatModel(a.chatModel.providerId, a.chatModel.key), c = await l({ chat_history: o }, s);
|
|
246
|
+
if (!c) return Response.json({ message: "Failed to generate title" }, { status: 500 });
|
|
247
|
+
let u = t.getUserId ? await t.getUserId() : null;
|
|
248
|
+
if (u && a.chatId) try {
|
|
249
|
+
let e = t.getDB(), i = await e.query.chats.findFirst({ where: r(n.id, a.chatId) });
|
|
250
|
+
i && i.userId === u && await e.update(n).set({ title: c }).where(r(n.id, a.chatId)).execute();
|
|
251
|
+
} catch (e) {
|
|
252
|
+
console.error("Failed to persist chat title:", e);
|
|
253
|
+
}
|
|
254
|
+
return Response.json({ title: c }, { status: 200 });
|
|
255
|
+
} catch (e) {
|
|
256
|
+
return console.error("Error generating chat title:", e), Response.json({ message: "Failed to generate title" }, { status: 500 });
|
|
257
|
+
}
|
|
258
|
+
} };
|
|
259
|
+
}
|
|
260
|
+
//#endregion
|
|
233
261
|
//#region src/api/handlers/messages.ts
|
|
234
|
-
var
|
|
262
|
+
var ee = [
|
|
235
263
|
"assistant",
|
|
236
264
|
"user",
|
|
237
265
|
"source",
|
|
238
266
|
"suggestion"
|
|
239
267
|
];
|
|
240
|
-
function
|
|
268
|
+
function T(e) {
|
|
241
269
|
let t = [], n = e;
|
|
242
270
|
for (let e = 0; n != null && e < 5; e++) t.push(n instanceof Error ? n.message : String(n)), n = n instanceof Error ? n.cause : void 0;
|
|
243
271
|
return t.join(" <- caused by: ");
|
|
244
272
|
}
|
|
245
|
-
function
|
|
273
|
+
function E(e) {
|
|
246
274
|
return { POST: async (t) => {
|
|
247
275
|
try {
|
|
248
276
|
let n = e.getDB(), r = await e.requireUserId(), { chatId: i, messageId: a, role: o, suggestions: s, content: c, sources: l } = await t.json();
|
|
249
|
-
return !i || !a || !o ? Response.json({ message: "Missing required fields" }, { status: 400 }) :
|
|
277
|
+
return !i || !a || !o ? Response.json({ message: "Missing required fields" }, { status: 400 }) : ee.includes(o) ? (await n.insert(e.messagesSchema).values({
|
|
250
278
|
chatId: i,
|
|
251
279
|
userId: r,
|
|
252
280
|
messageId: a,
|
|
@@ -257,13 +285,13 @@ function w(e) {
|
|
|
257
285
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
258
286
|
}), Response.json({ message: "Message saved successfully" }, { status: 200 })) : Response.json({ message: `Invalid role: ${o}` }, { status: 400 });
|
|
259
287
|
} catch (e) {
|
|
260
|
-
return console.error("Error saving message:",
|
|
288
|
+
return console.error("Error saving message:", T(e)), Response.json({ message: "Failed to save message" }, { status: 500 });
|
|
261
289
|
}
|
|
262
290
|
} };
|
|
263
291
|
}
|
|
264
292
|
//#endregion
|
|
265
293
|
//#region src/api/handlers/providers.ts
|
|
266
|
-
function
|
|
294
|
+
function D(t) {
|
|
267
295
|
return {
|
|
268
296
|
GET: async (n) => {
|
|
269
297
|
try {
|
|
@@ -293,7 +321,7 @@ function T(t) {
|
|
|
293
321
|
}
|
|
294
322
|
};
|
|
295
323
|
}
|
|
296
|
-
function
|
|
324
|
+
function O() {
|
|
297
325
|
return {
|
|
298
326
|
DELETE: async (t, { params: n }) => {
|
|
299
327
|
try {
|
|
@@ -315,7 +343,7 @@ function E() {
|
|
|
315
343
|
}
|
|
316
344
|
};
|
|
317
345
|
}
|
|
318
|
-
function
|
|
346
|
+
function k() {
|
|
319
347
|
return {
|
|
320
348
|
POST: async (t, { params: n }) => {
|
|
321
349
|
try {
|
|
@@ -337,7 +365,7 @@ function D() {
|
|
|
337
365
|
}
|
|
338
366
|
//#endregion
|
|
339
367
|
//#region src/api/handlers/mcpservers.ts
|
|
340
|
-
function
|
|
368
|
+
function A(e) {
|
|
341
369
|
return {
|
|
342
370
|
GET: async (t) => {
|
|
343
371
|
try {
|
|
@@ -359,7 +387,7 @@ function O(e) {
|
|
|
359
387
|
}
|
|
360
388
|
};
|
|
361
389
|
}
|
|
362
|
-
function
|
|
390
|
+
function j(e) {
|
|
363
391
|
return {
|
|
364
392
|
DELETE: async (t, { params: n }) => {
|
|
365
393
|
try {
|
|
@@ -381,7 +409,7 @@ function k(e) {
|
|
|
381
409
|
}
|
|
382
410
|
};
|
|
383
411
|
}
|
|
384
|
-
function
|
|
412
|
+
function M(e) {
|
|
385
413
|
return { POST: async (t, { params: n }) => {
|
|
386
414
|
try {
|
|
387
415
|
let { enabled: r } = await t.json(), { id: i } = await n;
|
|
@@ -395,7 +423,7 @@ function A(e) {
|
|
|
395
423
|
}
|
|
396
424
|
//#endregion
|
|
397
425
|
//#region src/api/handlers/search.ts
|
|
398
|
-
var
|
|
426
|
+
var N = {
|
|
399
427
|
tech: {
|
|
400
428
|
query: [
|
|
401
429
|
"technology news",
|
|
@@ -461,24 +489,24 @@ var j = {
|
|
|
461
489
|
]
|
|
462
490
|
}
|
|
463
491
|
};
|
|
464
|
-
function
|
|
492
|
+
function P(e = {}) {
|
|
465
493
|
let t = e.searxngDomain ?? "https://search.qwksearch.com";
|
|
466
494
|
return { GET: async (e) => {
|
|
467
|
-
let n = new URL(e.url).searchParams, r = n.get("q"), i = n.get("cat") || "general", a = parseInt(n.get("page") || "1", 10), o = n.get("lang") || "en-US", s = n.get("safesearch") === "true", c = n.get("recency") || void 0,
|
|
495
|
+
let n = new URL(e.url).searchParams, r = n.get("q"), i = n.get("cat") || "general", a = parseInt(n.get("page") || "1", 10), o = n.get("lang") || "en-US", s = n.get("safesearch") === "true", c = n.get("recency") || void 0, l = n.get("publicInstances") === "true";
|
|
468
496
|
if (!r) return Response.json({ error: "Query parameter is required" }, { status: 400 });
|
|
469
|
-
let
|
|
497
|
+
let u = Date.now();
|
|
470
498
|
try {
|
|
471
|
-
let e = await
|
|
499
|
+
let e = await d(r, {
|
|
472
500
|
category: i,
|
|
473
501
|
recency: c,
|
|
474
502
|
safesearch: s,
|
|
475
503
|
maxRetries: 6,
|
|
476
|
-
privateSearxng: !
|
|
504
|
+
privateSearxng: !l && t,
|
|
477
505
|
proxy: "",
|
|
478
506
|
lang: o,
|
|
479
507
|
page: a
|
|
480
508
|
});
|
|
481
|
-
e && (Array.isArray(e) ? e.length > 0 : e.results && e.results.length > 0) || (e = await
|
|
509
|
+
e && (Array.isArray(e) ? e.length > 0 : e.results && e.results.length > 0) || (e = await d(r, {
|
|
482
510
|
category: i,
|
|
483
511
|
recency: c,
|
|
484
512
|
safesearch: s,
|
|
@@ -488,7 +516,7 @@ function M(e = {}) {
|
|
|
488
516
|
lang: o,
|
|
489
517
|
page: a
|
|
490
518
|
}));
|
|
491
|
-
let n = Date.now() -
|
|
519
|
+
let n = Date.now() - u;
|
|
492
520
|
return e ? Array.isArray(e) ? Response.json({
|
|
493
521
|
results: e,
|
|
494
522
|
elapsedTime: n
|
|
@@ -508,13 +536,13 @@ function M(e = {}) {
|
|
|
508
536
|
}
|
|
509
537
|
} };
|
|
510
538
|
}
|
|
511
|
-
function
|
|
539
|
+
function F() {
|
|
512
540
|
return { GET: async (e) => {
|
|
513
541
|
try {
|
|
514
|
-
let t = new URL(e.url).searchParams, n = t.get("mode") || "normal", r =
|
|
542
|
+
let t = new URL(e.url).searchParams, n = t.get("mode") || "normal", r = N[t.get("topic") || "tech"], i = [];
|
|
515
543
|
if (n === "normal") {
|
|
516
544
|
let e = /* @__PURE__ */ new Set();
|
|
517
|
-
i = (await Promise.all(r.links.flatMap((e) => r.query.map(async (t) => (await
|
|
545
|
+
i = (await Promise.all(r.links.flatMap((e) => r.query.map(async (t) => (await u(`site:${e} ${t}`, {
|
|
518
546
|
engines: ["bing news"],
|
|
519
547
|
pageno: 1,
|
|
520
548
|
language: "en"
|
|
@@ -522,7 +550,7 @@ function N() {
|
|
|
522
550
|
let n = t.url?.toLowerCase().trim();
|
|
523
551
|
return e.has(n) ? !1 : (e.add(n), !0);
|
|
524
552
|
}).sort(() => Math.random() - .5);
|
|
525
|
-
} else i = (await
|
|
553
|
+
} else i = (await u(`site:${r.links[Math.floor(Math.random() * r.links.length)]} ${r.query[Math.floor(Math.random() * r.query.length)]}`, {
|
|
526
554
|
engines: ["bing news"],
|
|
527
555
|
pageno: 1,
|
|
528
556
|
language: "en"
|
|
@@ -535,17 +563,17 @@ function N() {
|
|
|
535
563
|
}
|
|
536
564
|
//#endregion
|
|
537
565
|
//#region src/api/handlers/autocomplete.ts
|
|
538
|
-
var
|
|
566
|
+
var I = [
|
|
539
567
|
"google",
|
|
540
568
|
"duckduckgo",
|
|
541
569
|
"wikipedia"
|
|
542
|
-
],
|
|
570
|
+
], L = 3, R = 3, z = Object.entries(m).map(([e, t]) => ({
|
|
543
571
|
domain: e,
|
|
544
572
|
name: typeof t?.[0] == "string" ? t[0] : "",
|
|
545
573
|
rank: typeof t?.[1] == "number" ? t[1] : 2 ** 53 - 1
|
|
546
|
-
})),
|
|
547
|
-
function
|
|
548
|
-
return
|
|
574
|
+
})), B = null;
|
|
575
|
+
function V() {
|
|
576
|
+
return B ||= new p(z, {
|
|
549
577
|
keys: [{
|
|
550
578
|
name: "name",
|
|
551
579
|
weight: .6
|
|
@@ -557,22 +585,22 @@ function z() {
|
|
|
557
585
|
ignoreLocation: !0,
|
|
558
586
|
includeScore: !0,
|
|
559
587
|
minMatchCharLength: 3
|
|
560
|
-
}),
|
|
588
|
+
}), B;
|
|
561
589
|
}
|
|
562
|
-
function
|
|
590
|
+
function H(e) {
|
|
563
591
|
let t = e.split(/\s+/).filter(Boolean), n = t[t.length - 1] || "";
|
|
564
|
-
return n.length < 3 ? [] :
|
|
592
|
+
return n.length < 3 ? [] : V().search(n, { limit: 12 }).sort((e, t) => Math.round((e.score ?? 1) * 10) - Math.round((t.score ?? 1) * 10) || e.item.rank - t.item.rank).slice(0, R).map(({ item: e }) => ({
|
|
565
593
|
domain: e.domain,
|
|
566
594
|
name: e.name,
|
|
567
595
|
favicon: `https://www.google.com/s2/favicons?domain=${encodeURIComponent(e.domain)}&sz=64`
|
|
568
596
|
}));
|
|
569
597
|
}
|
|
570
|
-
async function
|
|
571
|
-
let r = await
|
|
598
|
+
async function U(e, t, n) {
|
|
599
|
+
let r = await f(e, t, n);
|
|
572
600
|
if (r.length > 0) return r;
|
|
573
|
-
let i = t.split(/\s+/).filter(Boolean), a = Math.min(
|
|
601
|
+
let i = t.split(/\s+/).filter(Boolean), a = Math.min(L, i.length - 1);
|
|
574
602
|
for (let r = a; r >= 1; r--) {
|
|
575
|
-
let a = i.slice(-r).join(" "), o = i.slice(0, -r).join(" "), s = await
|
|
603
|
+
let a = i.slice(-r).join(" "), o = i.slice(0, -r).join(" "), s = await f(e, a, n);
|
|
576
604
|
if (s.length > 0) {
|
|
577
605
|
let e = /* @__PURE__ */ new Set();
|
|
578
606
|
for (let n of s) {
|
|
@@ -584,16 +612,16 @@ async function V(e, t, n) {
|
|
|
584
612
|
}
|
|
585
613
|
return [];
|
|
586
614
|
}
|
|
587
|
-
function
|
|
615
|
+
function W() {
|
|
588
616
|
return { GET: async (e) => {
|
|
589
617
|
let { searchParams: t } = new URL(e.url), n = t.get("q")?.trim(), r = t.get("locale") || "en-US", i = t.get("backends"), a = parseInt(t.get("limit") || "8", 10);
|
|
590
618
|
if (!n) return Response.json({
|
|
591
619
|
suggestions: [],
|
|
592
620
|
domains: []
|
|
593
621
|
});
|
|
594
|
-
let o = i ? i.split(",").map((e) => e.trim()).filter(Boolean) :
|
|
622
|
+
let o = i ? i.split(",").map((e) => e.trim()).filter(Boolean) : I;
|
|
595
623
|
try {
|
|
596
|
-
let e = await
|
|
624
|
+
let e = await U(o, n, r), t = H(n);
|
|
597
625
|
return Response.json({
|
|
598
626
|
suggestions: e.slice(0, a),
|
|
599
627
|
domains: t
|
|
@@ -608,12 +636,12 @@ function H() {
|
|
|
608
636
|
}
|
|
609
637
|
//#endregion
|
|
610
638
|
//#region src/api/handlers/suggestions.ts
|
|
611
|
-
function
|
|
639
|
+
function G() {
|
|
612
640
|
return { POST: async (t) => {
|
|
613
641
|
let n = await t.json(), r = n.chatHistory.filter((e) => e.role === "user" || e.role === "assistant").map((e) => ({
|
|
614
642
|
role: e.role,
|
|
615
643
|
content: String(e.content ?? "")
|
|
616
|
-
})), i = await new e().loadChatModel(n.chatModel.providerId, n.chatModel.key), a = (await
|
|
644
|
+
})), i = await new e().loadChatModel(n.chatModel.providerId, n.chatModel.key), a = (await h({
|
|
617
645
|
chat_history: r,
|
|
618
646
|
maxQuestions: n.maxQuestions
|
|
619
647
|
}, i)).flatMap((e) => (e.match(/\?/g) || []).length > 1 ? e.split(/\?/).map((e) => e.trim()).filter((e) => e.length > 0).map((e) => e + "?") : [e]);
|
|
@@ -622,7 +650,7 @@ function U() {
|
|
|
622
650
|
}
|
|
623
651
|
//#endregion
|
|
624
652
|
//#region src/api/handlers/agents.ts
|
|
625
|
-
function
|
|
653
|
+
function K(e) {
|
|
626
654
|
return { POST: async (t) => {
|
|
627
655
|
let n;
|
|
628
656
|
try {
|
|
@@ -637,7 +665,7 @@ function W(e) {
|
|
|
637
665
|
}
|
|
638
666
|
//#endregion
|
|
639
667
|
//#region src/api/handlers/rewrite.ts
|
|
640
|
-
function
|
|
668
|
+
function q(e) {
|
|
641
669
|
return { POST: async (t) => {
|
|
642
670
|
try {
|
|
643
671
|
let { text: n, prompt: r } = await t.json();
|
|
@@ -659,7 +687,7 @@ ${n}`, s = (await e.generateText({
|
|
|
659
687
|
}
|
|
660
688
|
//#endregion
|
|
661
689
|
//#region src/api/handlers/voice.ts
|
|
662
|
-
function
|
|
690
|
+
function J(e) {
|
|
663
691
|
return { POST: async (t) => {
|
|
664
692
|
let n, r, i;
|
|
665
693
|
try {
|
|
@@ -694,15 +722,15 @@ function K(e) {
|
|
|
694
722
|
}
|
|
695
723
|
//#endregion
|
|
696
724
|
//#region src/api/handlers/transcript.ts
|
|
697
|
-
function
|
|
725
|
+
function Y(e) {
|
|
698
726
|
return e === "small" || e === "fast" ? "@cf/openai/whisper-tiny-en" : e === "medium" || e === "turbo" ? "@cf/openai/whisper-large-v3-turbo" : e === "large" ? "@cf/openai/whisper-large-v3" : "@cf/openai/whisper-large-v3-turbo";
|
|
699
727
|
}
|
|
700
|
-
function
|
|
728
|
+
function X(e) {
|
|
701
729
|
return { POST: async (t) => {
|
|
702
730
|
try {
|
|
703
731
|
let n = await t.formData(), r = n.get("file");
|
|
704
732
|
if (!r || !(r instanceof File)) return Response.json({ error: "file is required" }, { status: 400 });
|
|
705
|
-
let i =
|
|
733
|
+
let i = Y(n.get("model")), a;
|
|
706
734
|
try {
|
|
707
735
|
a = e.getCloudflareContext().env?.AI;
|
|
708
736
|
} catch {}
|
|
@@ -719,15 +747,15 @@ function J(e) {
|
|
|
719
747
|
}
|
|
720
748
|
//#endregion
|
|
721
749
|
//#region src/api/handlers/test-models.ts
|
|
722
|
-
function
|
|
750
|
+
function Z() {
|
|
723
751
|
return { POST: async (e) => {
|
|
724
752
|
try {
|
|
725
753
|
let { providerType: t, apiKey: n, onlyFree: r = !0 } = await e.json();
|
|
726
754
|
if (!t) return Response.json({ error: "Provider type is required" }, { status: 400 });
|
|
727
755
|
if (!n) return Response.json({ error: "API key is required" }, { status: 400 });
|
|
728
|
-
let i =
|
|
756
|
+
let i = _.find((e) => e.provider.toLowerCase() === t.toLowerCase());
|
|
729
757
|
if (!i) return Response.json({ error: `Provider ${t} not found` }, { status: 404 });
|
|
730
|
-
let a = await
|
|
758
|
+
let a = await g(t, n, i.models, {
|
|
731
759
|
onlyFree: r,
|
|
732
760
|
concurrency: 3,
|
|
733
761
|
timeout: 15e3
|
|
@@ -740,19 +768,19 @@ function Y() {
|
|
|
740
768
|
}
|
|
741
769
|
//#endregion
|
|
742
770
|
//#region src/api/handlers/validate-openrouter.ts
|
|
743
|
-
var
|
|
744
|
-
function
|
|
771
|
+
var Q = 1440 * 60 * 1e3, $ = null;
|
|
772
|
+
function te(e) {
|
|
745
773
|
return {
|
|
746
774
|
GET: async (t) => {
|
|
747
775
|
try {
|
|
748
776
|
let t = Date.now();
|
|
749
|
-
if (
|
|
750
|
-
|
|
777
|
+
if ($ && t - $.timestamp < Q) return Response.json({
|
|
778
|
+
...$.result,
|
|
751
779
|
cached: !0,
|
|
752
|
-
cacheAge: t -
|
|
780
|
+
cacheAge: t - $.timestamp
|
|
753
781
|
});
|
|
754
782
|
let n = await e.validateOpenRouterModels();
|
|
755
|
-
return
|
|
783
|
+
return $ = {
|
|
756
784
|
result: n,
|
|
757
785
|
timestamp: t
|
|
758
786
|
}, Response.json({
|
|
@@ -766,7 +794,7 @@ function Q(e) {
|
|
|
766
794
|
POST: async (t) => {
|
|
767
795
|
try {
|
|
768
796
|
let { concurrency: n = 3, timeout: r = 15e3 } = await t.json().catch(() => ({})), i = await e.validateOpenRouterModels(n, r);
|
|
769
|
-
return
|
|
797
|
+
return $ = {
|
|
770
798
|
result: i,
|
|
771
799
|
timestamp: Date.now()
|
|
772
800
|
}, Response.json({
|
|
@@ -780,4 +808,4 @@ function Q(e) {
|
|
|
780
808
|
};
|
|
781
809
|
}
|
|
782
810
|
//#endregion
|
|
783
|
-
export {
|
|
811
|
+
export { K as createAgentsHandler, v as createArticleFollowupsHandler, y as createArticleQAHandler, W as createAutocompleteHandler, x as createChatByIdHandler, w as createChatTitleHandler, b as createChatsHandler, S as createChatsSearchHandler, C as createChatsShareHandler, F as createDiscoverHandler, j as createMCPServerByIdHandler, M as createMCPServerToggleHandler, A as createMCPServersHandler, E as createMessagesHandler, O as createProviderByIdHandler, k as createProviderModelsHandler, D as createProvidersHandler, q as createRewriteHandler, P as createSearchHandler, G as createSuggestionsHandler, Z as createTestModelsHandler, X as createTranscriptHandler, te as createValidateOpenRouterHandler, J as createVoiceHandler, T as describeError };
|