research-agent-ui 0.1.293 → 0.1.295
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 +42 -1
- package/dist/ArticleExtractPanel-BPNXuezE.js +389 -0
- package/dist/ArticleExtractPanel-DAPLUpyx.cjs +2 -0
- package/dist/ChatConversationThread-D1RR0Bcx.cjs +17 -0
- package/dist/ChatConversationThread-DMPdu2sr.js +1428 -0
- package/dist/DownloadsDialog-CCPj0hA8.cjs +1 -0
- package/dist/{DownloadsDialog-bTEDe2DI.js → DownloadsDialog-DvS23Dh-.js} +8 -9
- package/dist/api/handlers/autocomplete.d.ts +6 -9
- package/dist/api/handlers/openai-transcription.d.ts +53 -0
- package/dist/api/handlers/transcript.d.ts +33 -0
- package/dist/api/index.d.ts +1 -0
- package/dist/api.cjs +10 -10
- package/dist/api.mjs +373 -182
- package/dist/app/index.d.ts +1 -1
- package/dist/app/useChunkErrorReload.d.ts +13 -2
- package/dist/components/ArticleReader/ArticleReaderMount.d.ts +5 -0
- package/dist/components/ArticleReader/ExtractPanelContext.d.ts +17 -1
- package/dist/components/ChatConversation/MessageBubble/AssistantMessageActions.d.ts +2 -1
- package/dist/components/ChatConversation/background-art.d.ts +3 -1
- package/dist/components/ChatConversation/background-cache.d.ts +41 -0
- package/dist/components/Footer.d.ts +5 -4
- package/dist/components/Footer.stories.d.ts +3 -3
- package/dist/config.cjs +1 -1
- package/dist/config.d.ts +9 -0
- package/dist/config.mjs +4 -3
- package/dist/dialog-7GDz0sWx.cjs +1 -0
- package/dist/dialog-Cufn2u50.js +80 -0
- package/dist/hooks/voice/useKokoroTTS.d.ts +2 -0
- package/dist/hooks/voice/useTextToVoice.d.ts +2 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.mjs +4 -2
- package/dist/lib/file-sources.d.ts +8 -0
- package/dist/lib/google-drive-source.d.ts +100 -0
- package/dist/lib/kokoro.d.ts +14 -2
- package/dist/lib/qwksearch-connect.d.ts +79 -0
- package/dist/settings/index.d.ts +15 -0
- package/dist/src-BqV2Vwpv.js +6375 -0
- package/dist/src-Ckb1ciEL.cjs +34 -0
- package/dist/tooltip-Bl3IdX-I.js +179 -0
- package/dist/tooltip-DmUO6ZUz.cjs +1 -0
- package/dist/types/fileSource.d.ts +9 -0
- package/dist/workspace/QwkSearchWorkspaceApp.d.ts +9 -2
- package/dist/workspace/ResearchWorkspaceView.d.ts +18 -4
- package/dist/workspace.cjs +1 -1
- package/dist/workspace.d.ts +1 -1
- package/dist/workspace.mjs +234 -91
- package/package.json +53 -50
- package/src/app/useChunkErrorReload.ts +92 -0
- package/src/settings/index.ts +23 -0
- package/src/settings/search.json +19 -1
- package/dist/DownloadsDialog-Ca6aRRcP.cjs +0 -1
- package/dist/src-HL9JjPc-.js +0 -8218
- package/dist/src-r4BsCIB4.cjs +0 -51
package/README.md
CHANGED
|
@@ -20,6 +20,10 @@
|
|
|
20
20
|
</p>
|
|
21
21
|
<!-- template-git-repo:badges:end -->
|
|
22
22
|
|
|
23
|
+
<!-- skills:install:start -->
|
|
24
|
+
**🤖 Agent skill** — `npx skills@latest add https://github.com/OpenSourceAGI/qwksearch-research-agent --skill research-agent-ui` ([what it covers](../../skills/research-agent-ui/SKILL.md))
|
|
25
|
+
<!-- skills:install:end -->
|
|
26
|
+
|
|
23
27
|
# research-agent-ui
|
|
24
28
|
|
|
25
29
|
|
|
@@ -70,7 +74,7 @@ import { QwkSearchProviders, openSpotlight } from 'research-agent-ui';
|
|
|
70
74
|
</QwkSearchProviders>;
|
|
71
75
|
|
|
72
76
|
// …and from a button somewhere in your own chrome:
|
|
73
|
-
<button onClick={() => openSpotlight()}>Search
|
|
77
|
+
<button onClick={() => openSpotlight()}>Search </button>;
|
|
74
78
|
```
|
|
75
79
|
|
|
76
80
|
Rows that open a chat or a settings section go through `onOpenChat` /
|
|
@@ -296,6 +300,43 @@ export const dynamic = "force-dynamic";
|
|
|
296
300
|
export const POST = handleChatRequest;
|
|
297
301
|
```
|
|
298
302
|
|
|
303
|
+
## Embedding on another site: "Sign in with QwkSearch"
|
|
304
|
+
|
|
305
|
+
A site that embeds the research agent has no QwkSearch session cookie, so by
|
|
306
|
+
default the embed runs as a guest. `createQwkSearchConnectAuthClient` makes the
|
|
307
|
+
login button go through QwkSearch's OAuth-style consent screen
|
|
308
|
+
(`https://qwksearch.com/connect`, authorization code + PKCE) instead. Your
|
|
309
|
+
server finishes the exchange at `POST https://qwksearch.com/api/connect/token`,
|
|
310
|
+
stores the returned API key against your own user, and hands it back to the
|
|
311
|
+
embed; every request the embed then makes to `qwksearch.com/api/` carries it as
|
|
312
|
+
`X-API-Key`, so chats, history and the user's QwkSearch plan work in the embed.
|
|
313
|
+
|
|
314
|
+
```tsx
|
|
315
|
+
import { SessionProvider, createQwkSearchConnectAuthClient } from 'research-agent-ui';
|
|
316
|
+
|
|
317
|
+
const authClient = createQwkSearchConnectAuthClient({
|
|
318
|
+
sessionUrl: '/api/qwksearch/session', // GET -> { connected, user, apiKey, plan, upgradeUrl }
|
|
319
|
+
connectUrl: '/api/qwksearch/connect', // GET -> PKCE + redirect to qwksearch.com/connect
|
|
320
|
+
disconnectUrl: '/api/qwksearch/disconnect' // POST -> forget the stored key
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
<SessionProvider authClient={authClient} enableGoogleOneTap={false}>…</SessionProvider>
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
The flow, from your server's side:
|
|
327
|
+
|
|
328
|
+
1. Make a PKCE verifier, keep it (an httpOnly cookie), and redirect to
|
|
329
|
+
`https://qwksearch.com/connect?redirect_uri=<your callback>&state=<random>&code_challenge=<S256>&code_challenge_method=S256`.
|
|
330
|
+
2. QwkSearch signs the user in if needed and asks them to allow the link, then
|
|
331
|
+
redirects to `redirect_uri?code=…&state=…` (or `?error=access_denied`).
|
|
332
|
+
3. `POST /api/connect/token` with `{ code, redirect_uri, code_verifier }` →
|
|
333
|
+
`{ api_key, user, plan, upgrade_url }`.
|
|
334
|
+
4. `GET /api/connect/me` with the key as `X-API-Key` refreshes the profile and
|
|
335
|
+
plan later — e.g. after the user follows `upgrade_url` to upgrade.
|
|
336
|
+
|
|
337
|
+
`redirect_uri` must be on QwkSearch's allowlist (debate-ai.com, ebate.app and localhost
|
|
338
|
+
by default; more via the `QWKSEARCH_CONNECT_ORIGINS` env var on qwksearch-web).
|
|
339
|
+
|
|
299
340
|
## Configuration
|
|
300
341
|
|
|
301
342
|
`configureResearchAgentUI` overrides app-specific values (branding strings,
|
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
import { i as e, n as t, o as n, t as r } from "./dialog-Cufn2u50.js";
|
|
2
|
+
import { a as i, c as a, u as o } from "./tooltip-Bl3IdX-I.js";
|
|
3
|
+
import { D as s, E as ee, O as te, S as ne, T as re, w as ie } from "./src-BqV2Vwpv.js";
|
|
4
|
+
import { researchAgentUIConfig as ae } from "./config.mjs";
|
|
5
|
+
import * as c from "react";
|
|
6
|
+
import { useEffect as l, useRef as u, useState as d } from "react";
|
|
7
|
+
import { jsx as f, jsxs as p } from "react/jsx-runtime";
|
|
8
|
+
import { toast as m } from "sonner";
|
|
9
|
+
import { addFavorite as oe, articleFollowups as se, articleQa as ce, getArticle as h, listFavorites as le, removeFavorite as ue, updateArticle as g } from "qwksearch-api-client";
|
|
10
|
+
// src/ui/visually-hidden.tsx
|
|
11
|
+
var _ = c.forwardRef(({ className: e, ...t }, r) => /* @__PURE__ */ f("span", {
|
|
12
|
+
ref: r,
|
|
13
|
+
className: n("absolute w-px h-px p-0 -m-px overflow-hidden whitespace-nowrap border-0", e),
|
|
14
|
+
style: {
|
|
15
|
+
clip: "rect(0, 0, 0, 0)",
|
|
16
|
+
clipPath: "inset(50%)"
|
|
17
|
+
},
|
|
18
|
+
...t
|
|
19
|
+
}));
|
|
20
|
+
_.displayName = "VisuallyHidden";
|
|
21
|
+
// src/lib/shareArticle.ts
|
|
22
|
+
function v(e) {
|
|
23
|
+
return e instanceof Error && e.name === "AbortError";
|
|
24
|
+
}
|
|
25
|
+
async function de(e, t) {
|
|
26
|
+
if (t.share) try {
|
|
27
|
+
return await t.share(e), "shared";
|
|
28
|
+
} catch (e) {
|
|
29
|
+
if (v(e)) return "cancelled";
|
|
30
|
+
}
|
|
31
|
+
return await t.writeText(e.url), "copied";
|
|
32
|
+
}
|
|
33
|
+
// src/components/ArticleReader/ArticleExtractPanel.tsx
|
|
34
|
+
var y = (n) => {
|
|
35
|
+
let { isOpen: c, url: v, searchText: y, suggestQuestions: fe, panelWidth: pe, setPanelWidth: b, closePanel: me } = i(), { isAuthenticated: he } = a(), { chatModelProvider: x } = o(), S = n.isOpen === void 0 ? c : n.isOpen, C = n.onClose || me, w = n.url || v, ge = n.searchText === void 0 ? y : n.searchText, [T, E] = d(null), [D, _e] = d([]), [ve, O] = d(!1), [ye, k] = d(!1), [A, j] = d(ae.defaultSummarizePrompt), [be, M] = d(!1), [N, xe] = d(!1), [P, Se] = d(!1), [F, Ce] = d(""), [I, we] = d(""), [Te, L] = d([]), [Ee, De] = d(""), [R, z] = d(!1), [Oe, B] = d(!1), [V, H] = d(!1), [ke, Ae] = d(!1), [je, Me] = d(pe), [U, W] = d(!1), [Ne, G] = d(!1), [K, q] = d(1), Pe = u(null), J = u({}), Y = .5, X = 1.8, Z = .1;
|
|
36
|
+
l(() => {
|
|
37
|
+
let e = parseFloat(localStorage.getItem("articleFontScale") || "");
|
|
38
|
+
Number.isNaN(e) || q(Math.min(X, Math.max(Y, e)));
|
|
39
|
+
}, []);
|
|
40
|
+
let Q = (e) => {
|
|
41
|
+
let t = Math.min(X, Math.max(Y, Math.round(e * 100) / 100));
|
|
42
|
+
q(t);
|
|
43
|
+
try {
|
|
44
|
+
localStorage.setItem("articleFontScale", String(t));
|
|
45
|
+
} catch (e) {
|
|
46
|
+
console.error("Error storing article font scale:", e);
|
|
47
|
+
}
|
|
48
|
+
}, Fe = () => Q(K + Z), Ie = () => Q(K - Z), Le = () => Q(1);
|
|
49
|
+
l(() => {
|
|
50
|
+
let e = () => {
|
|
51
|
+
Ae(window.innerWidth >= 1024);
|
|
52
|
+
};
|
|
53
|
+
return e(), window.addEventListener("resize", e), () => window.removeEventListener("resize", e);
|
|
54
|
+
}, []), l(() => {
|
|
55
|
+
let e = (e) => {
|
|
56
|
+
if (!U) return;
|
|
57
|
+
let t = window.innerWidth - e.clientX, n = Math.max(400, Math.min(t, window.innerWidth - 100));
|
|
58
|
+
Me(n), b(n);
|
|
59
|
+
}, t = () => {
|
|
60
|
+
W(!1);
|
|
61
|
+
};
|
|
62
|
+
return U && (document.addEventListener("mousemove", e), document.addEventListener("mouseup", t), document.body.style.cursor = "ew-resize", document.body.style.userSelect = "none"), () => {
|
|
63
|
+
document.removeEventListener("mousemove", e), document.removeEventListener("mouseup", t), document.body.style.cursor = "", document.body.style.userSelect = "";
|
|
64
|
+
};
|
|
65
|
+
}, [U, b]), l(() => {
|
|
66
|
+
S && w ? (G(!1), Re()) : S || G(!1);
|
|
67
|
+
}, [S, w]);
|
|
68
|
+
let Re = async () => {
|
|
69
|
+
console.log("[ArticleExtractPanel] Extracting URL:", w);
|
|
70
|
+
try {
|
|
71
|
+
let e = new URL(w);
|
|
72
|
+
if ([
|
|
73
|
+
/^https?:\/\/(www\.)?google\.[^/]+\/search/i,
|
|
74
|
+
/^https?:\/\/(www\.)?bing\.com\/search/i,
|
|
75
|
+
/^https?:\/\/(www\.)?duckduckgo\.com\/\?/i
|
|
76
|
+
].some((e) => e.test(w))) {
|
|
77
|
+
m.error("Cannot extract articles from search result pages"), M(!1), G(!0);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
(e.pathname === "/" || e.pathname === "") && (console.error("[ArticleExtractPanel] URL is domain-only, missing article path:", w), m.error("Invalid article URL - only domain provided"));
|
|
81
|
+
} catch (e) {
|
|
82
|
+
console.error("[ArticleExtractPanel] Invalid URL format:", w, e);
|
|
83
|
+
}
|
|
84
|
+
M(!0);
|
|
85
|
+
try {
|
|
86
|
+
let { data: e } = await h({ query: { url: w } }), t = e?.article, n = t?.html?.replace(/<[^>]*>/g, "").trim() || "";
|
|
87
|
+
t?.error || n.length < 20 ? (document.dispatchEvent(new CustomEvent("onInvokeChromeAPI", { detail: {
|
|
88
|
+
type: "extractURL",
|
|
89
|
+
url: w
|
|
90
|
+
} })), await Promise.race([new Promise((e) => {
|
|
91
|
+
let t = async (n) => {
|
|
92
|
+
window.removeEventListener("onExtractionResult", t);
|
|
93
|
+
let { data: r } = await h({ query: { url: w } }), i = r?.article;
|
|
94
|
+
i && (E(i), i.followUpQuestions?.length > 0 ? L(i.followUpQuestions) : fe && (L([]), $("suggest-followups", { source: i }))), e();
|
|
95
|
+
};
|
|
96
|
+
window.addEventListener("onExtractionResult", t);
|
|
97
|
+
}), new Promise((e) => setTimeout(e, 1e4))])) : (E(t), t?.followUpQuestions && t.followUpQuestions.length > 0 ? L(t.followUpQuestions) : fe && t && (L([]), $("suggest-followups", { source: t }))), he && ze();
|
|
98
|
+
} catch (e) {
|
|
99
|
+
console.error("[ArticleExtractPanel] Error extracting URL:", e), m.error("Failed to load article");
|
|
100
|
+
} finally {
|
|
101
|
+
M(!1), G(!0);
|
|
102
|
+
}
|
|
103
|
+
}, ze = async () => {
|
|
104
|
+
try {
|
|
105
|
+
let { data: e } = await le(), t = e?.favorites?.some((e) => e.url === w);
|
|
106
|
+
z(!!t);
|
|
107
|
+
} catch (e) {
|
|
108
|
+
console.error("Error checking favorite status:", e);
|
|
109
|
+
}
|
|
110
|
+
}, Be = async () => {
|
|
111
|
+
if (T) {
|
|
112
|
+
B(!0);
|
|
113
|
+
try {
|
|
114
|
+
R ? (await ue({ query: { url: w } }), z(!1), m.info("Removed from favorites")) : (await oe({ body: {
|
|
115
|
+
url: T.url || w,
|
|
116
|
+
title: T.title,
|
|
117
|
+
cite: T.cite,
|
|
118
|
+
author: T.author,
|
|
119
|
+
author_cite: T.author_cite,
|
|
120
|
+
date: T.date,
|
|
121
|
+
source: T.source,
|
|
122
|
+
word_count: T.word_count,
|
|
123
|
+
html: T.html
|
|
124
|
+
} }), z(!0), m.success("Added to favorites"));
|
|
125
|
+
} catch (e) {
|
|
126
|
+
console.error("Error toggling favorite:", e), m.error("Failed to toggle favorite");
|
|
127
|
+
} finally {
|
|
128
|
+
B(!1);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}, Ve = () => {
|
|
132
|
+
if (x?.key && x?.providerId) return x;
|
|
133
|
+
try {
|
|
134
|
+
let e = localStorage.getItem("chatModelKey") || "", t = localStorage.getItem("chatModelProviderId") || "";
|
|
135
|
+
if (e && t) return {
|
|
136
|
+
key: e,
|
|
137
|
+
providerId: t
|
|
138
|
+
};
|
|
139
|
+
} catch (e) {
|
|
140
|
+
console.error("Error reading persisted chat model:", e);
|
|
141
|
+
}
|
|
142
|
+
return x;
|
|
143
|
+
}, $ = async (e, { source: t = T, question: n = A } = {}) => {
|
|
144
|
+
if (!t) return;
|
|
145
|
+
let r = Ve(), i = t.html?.replace(/<[^>]*>?/g, "").slice(0, ae.maxArticleLength), a = e === "question", o = a ? xe : Se, s = a ? we : De;
|
|
146
|
+
o(!0), s("");
|
|
147
|
+
try {
|
|
148
|
+
if (a) {
|
|
149
|
+
let e = [ge, n].filter(Boolean).join("\n");
|
|
150
|
+
if (!i || i.length === 0) throw Error("Article content is empty");
|
|
151
|
+
let { data: t, error: a } = await ce({ body: {
|
|
152
|
+
article: i,
|
|
153
|
+
question: e,
|
|
154
|
+
chatHistory: D.slice(-5),
|
|
155
|
+
chatModel: r
|
|
156
|
+
} });
|
|
157
|
+
if (a) {
|
|
158
|
+
let e = a.details || a.error || a.message || "Article QA failed";
|
|
159
|
+
throw Error(e);
|
|
160
|
+
}
|
|
161
|
+
let o = t?.content || "";
|
|
162
|
+
Ce(o), _e((e) => [
|
|
163
|
+
...e,
|
|
164
|
+
{
|
|
165
|
+
role: "user",
|
|
166
|
+
content: n,
|
|
167
|
+
time: (/* @__PURE__ */ new Date()).toISOString()
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
role: "assistant",
|
|
171
|
+
content: o,
|
|
172
|
+
time: (/* @__PURE__ */ new Date()).toISOString()
|
|
173
|
+
}
|
|
174
|
+
]);
|
|
175
|
+
try {
|
|
176
|
+
await g({ body: {
|
|
177
|
+
url: w,
|
|
178
|
+
question: n,
|
|
179
|
+
answer: o
|
|
180
|
+
} });
|
|
181
|
+
} catch (e) {
|
|
182
|
+
console.error("Error storing Q&A in cache:", e);
|
|
183
|
+
}
|
|
184
|
+
} else {
|
|
185
|
+
let e = parseInt(localStorage.getItem("maxFollowupQuestions") || "4");
|
|
186
|
+
if (!i || i.length === 0) throw Error("Article content is empty");
|
|
187
|
+
let { data: t, error: n } = await se({ body: {
|
|
188
|
+
article: i,
|
|
189
|
+
chatHistory: D.slice(-5),
|
|
190
|
+
maxQuestions: e,
|
|
191
|
+
chatModel: r
|
|
192
|
+
} });
|
|
193
|
+
if (n) {
|
|
194
|
+
let e = n.details || n.error || n.message || "Article followups failed";
|
|
195
|
+
throw Error(e);
|
|
196
|
+
}
|
|
197
|
+
let a = t?.extract || [];
|
|
198
|
+
L(a);
|
|
199
|
+
try {
|
|
200
|
+
await g({ body: {
|
|
201
|
+
url: w,
|
|
202
|
+
followUpQuestions: a
|
|
203
|
+
} });
|
|
204
|
+
} catch (e) {
|
|
205
|
+
console.error("Error storing follow-up questions in cache:", e);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
} catch (e) {
|
|
209
|
+
console.error("Error calling language API:", e), s(e instanceof Error || typeof e == "object" && e && "message" in e ? e.message : "Failed to get AI response");
|
|
210
|
+
} finally {
|
|
211
|
+
o(!1);
|
|
212
|
+
}
|
|
213
|
+
}, He = (e) => {
|
|
214
|
+
j(e), $("question", { question: e });
|
|
215
|
+
}, Ue = async () => {
|
|
216
|
+
if (!T) return;
|
|
217
|
+
let e = `${F}\n\n\n${T.cite || ""}\n\n\n${T.html}`;
|
|
218
|
+
try {
|
|
219
|
+
await navigator.clipboard.writeText(e), O(!0), setTimeout(() => O(!1), 2e3);
|
|
220
|
+
} catch (e) {
|
|
221
|
+
console.error("Failed to copy to clipboard:", e);
|
|
222
|
+
}
|
|
223
|
+
}, We = async () => {
|
|
224
|
+
let e = T?.url || w;
|
|
225
|
+
if (e) try {
|
|
226
|
+
await de({
|
|
227
|
+
title: T?.title,
|
|
228
|
+
text: T?.cite,
|
|
229
|
+
url: e
|
|
230
|
+
}, {
|
|
231
|
+
share: typeof navigator < "u" && navigator.share ? (e) => navigator.share(e) : void 0,
|
|
232
|
+
writeText: (e) => navigator.clipboard.writeText(e)
|
|
233
|
+
}) === "copied" && (k(!0), setTimeout(() => k(!1), 2e3));
|
|
234
|
+
} catch (e) {
|
|
235
|
+
console.error("Failed to share article:", e);
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
J.current = {
|
|
239
|
+
ask: () => $("question"),
|
|
240
|
+
suggest: () => $("suggest-followups"),
|
|
241
|
+
copy: Ue,
|
|
242
|
+
highlight: () => H((e) => !e),
|
|
243
|
+
favorite: Be,
|
|
244
|
+
open: () => {
|
|
245
|
+
let e = T?.url || w;
|
|
246
|
+
e && window.open(e, "_blank", "noopener,noreferrer");
|
|
247
|
+
},
|
|
248
|
+
zoomIn: Fe,
|
|
249
|
+
zoomOut: Ie,
|
|
250
|
+
zoomReset: Le,
|
|
251
|
+
close: C
|
|
252
|
+
}, l(() => {
|
|
253
|
+
if (!S) return;
|
|
254
|
+
let e = (e) => /^[a-z]$/.test(e) ? `Key${e.toUpperCase()}` : /^[0-9]$/.test(e) ? `Digit${e}` : e === "-" ? "Minus" : e === "=" ? "Equal" : e, t = {};
|
|
255
|
+
Object.keys(s).forEach((n) => {
|
|
256
|
+
let { alt: r, key: i } = s[n];
|
|
257
|
+
r && (t[e(i.toLowerCase())] = n);
|
|
258
|
+
});
|
|
259
|
+
let n = (e) => {
|
|
260
|
+
if (e.key === "Escape") {
|
|
261
|
+
J.current.close?.();
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
if (!e.altKey || e.ctrlKey || e.metaKey) return;
|
|
265
|
+
let n = e.target;
|
|
266
|
+
if (n && (n.tagName === "INPUT" || n.tagName === "TEXTAREA" || n.isContentEditable)) return;
|
|
267
|
+
let r = t[e.code];
|
|
268
|
+
if (!r) return;
|
|
269
|
+
let i = J.current[r];
|
|
270
|
+
i && (e.preventDefault(), i());
|
|
271
|
+
};
|
|
272
|
+
return window.addEventListener("keydown", n), () => window.removeEventListener("keydown", n);
|
|
273
|
+
}, [S]);
|
|
274
|
+
let Ge = () => /* @__PURE__ */ p("div", {
|
|
275
|
+
className: "flex h-full flex-col bg-background shadow-xl",
|
|
276
|
+
children: [/* @__PURE__ */ f("div", {
|
|
277
|
+
className: "shrink-0 border-b border-border bg-background/95 px-4 py-3 backdrop-blur supports-[backdrop-filter]:bg-background/80",
|
|
278
|
+
children: /* @__PURE__ */ f(te, {
|
|
279
|
+
isLoadingAI: N,
|
|
280
|
+
isLoadingFollowups: P,
|
|
281
|
+
isLoadingFavorite: Oe,
|
|
282
|
+
isFavorited: R,
|
|
283
|
+
isHighlightMode: V,
|
|
284
|
+
articleUrl: T?.url || w,
|
|
285
|
+
fontScale: K,
|
|
286
|
+
onAskClick: () => $("question"),
|
|
287
|
+
onSuggestClick: () => $("suggest-followups"),
|
|
288
|
+
onCopyClick: Ue,
|
|
289
|
+
onShareClick: We,
|
|
290
|
+
onFavoriteClick: Be,
|
|
291
|
+
onHighlightToggle: () => H(!V),
|
|
292
|
+
onZoomIn: Fe,
|
|
293
|
+
onZoomOut: Ie,
|
|
294
|
+
onZoomReset: Le,
|
|
295
|
+
onClose: C
|
|
296
|
+
})
|
|
297
|
+
}), /* @__PURE__ */ f("div", {
|
|
298
|
+
className: "flex-1 overflow-y-auto",
|
|
299
|
+
children: /* @__PURE__ */ p("div", {
|
|
300
|
+
className: "p-4 space-y-6",
|
|
301
|
+
children: [/* @__PURE__ */ p("div", {
|
|
302
|
+
className: "space-y-4",
|
|
303
|
+
children: [
|
|
304
|
+
ve && /* @__PURE__ */ f("div", {
|
|
305
|
+
className: "bg-blue-500 text-white text-sm font-medium px-3 py-2 rounded-md shadow-lg",
|
|
306
|
+
children: "Copied!"
|
|
307
|
+
}),
|
|
308
|
+
ye && /* @__PURE__ */ f("div", {
|
|
309
|
+
className: "bg-blue-500 text-white text-sm font-medium px-3 py-2 rounded-md shadow-lg",
|
|
310
|
+
children: "Link copied!"
|
|
311
|
+
}),
|
|
312
|
+
/* @__PURE__ */ f(ee, {
|
|
313
|
+
value: A,
|
|
314
|
+
onChange: j,
|
|
315
|
+
onSubmit: () => $("question")
|
|
316
|
+
}),
|
|
317
|
+
/* @__PURE__ */ f(re, {
|
|
318
|
+
questions: Te,
|
|
319
|
+
isLoading: P,
|
|
320
|
+
error: Ee,
|
|
321
|
+
onQuestionClick: He
|
|
322
|
+
}),
|
|
323
|
+
D.length > 0 && /* @__PURE__ */ f("div", {
|
|
324
|
+
className: "space-y-4",
|
|
325
|
+
children: D.map((e, t) => /* @__PURE__ */ f("div", {
|
|
326
|
+
className: "space-y-2",
|
|
327
|
+
children: e.role === "user" ? /* @__PURE__ */ p("div", {
|
|
328
|
+
className: "bg-primary/10 border border-primary/20 rounded-lg p-3",
|
|
329
|
+
children: [/* @__PURE__ */ f("div", {
|
|
330
|
+
className: "text-xs font-semibold text-primary mb-1",
|
|
331
|
+
children: "Your Question"
|
|
332
|
+
}), /* @__PURE__ */ f("div", {
|
|
333
|
+
className: "text-sm text-foreground",
|
|
334
|
+
children: e.content
|
|
335
|
+
})]
|
|
336
|
+
}) : /* @__PURE__ */ p("div", {
|
|
337
|
+
className: "bg-muted rounded-lg shadow-md p-4",
|
|
338
|
+
children: [/* @__PURE__ */ f("div", {
|
|
339
|
+
className: "text-xs font-semibold text-muted-foreground mb-2",
|
|
340
|
+
children: "AI Response"
|
|
341
|
+
}), /* @__PURE__ */ f("div", {
|
|
342
|
+
className: "text-sm",
|
|
343
|
+
dangerouslySetInnerHTML: { __html: e.content }
|
|
344
|
+
})]
|
|
345
|
+
})
|
|
346
|
+
}, t))
|
|
347
|
+
}),
|
|
348
|
+
(N || F && D.length === 0) && /* @__PURE__ */ f(ie, {
|
|
349
|
+
response: F,
|
|
350
|
+
isLoading: N,
|
|
351
|
+
error: I
|
|
352
|
+
}),
|
|
353
|
+
I && !N && /* @__PURE__ */ f("div", {
|
|
354
|
+
className: "bg-red-500 text-white p-2 rounded-md text-sm",
|
|
355
|
+
children: I
|
|
356
|
+
})
|
|
357
|
+
]
|
|
358
|
+
}), T && /* @__PURE__ */ f(ne, {
|
|
359
|
+
article: T,
|
|
360
|
+
isHighlightMode: V,
|
|
361
|
+
fontScale: K
|
|
362
|
+
})]
|
|
363
|
+
})
|
|
364
|
+
})]
|
|
365
|
+
});
|
|
366
|
+
return !S || !Ne ? null : ke ? /* @__PURE__ */ p("div", {
|
|
367
|
+
className: "fixed top-0 right-0 h-screen z-40 transition-all duration-300",
|
|
368
|
+
style: { width: `${je}px` },
|
|
369
|
+
children: [/* @__PURE__ */ f("div", {
|
|
370
|
+
ref: Pe,
|
|
371
|
+
onMouseDown: () => W(!0),
|
|
372
|
+
className: "absolute left-0 top-0 bottom-0 w-1 cursor-ew-resize hover:bg-primary bg-transparent transition-colors z-50",
|
|
373
|
+
style: { touchAction: "none" },
|
|
374
|
+
children: /* @__PURE__ */ f("div", { className: "absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-1 h-12 rounded-full bg-muted-foreground opacity-50 hover:opacity-100 transition-opacity" })
|
|
375
|
+
}), Ge()]
|
|
376
|
+
}) : /* @__PURE__ */ f(r, {
|
|
377
|
+
open: S,
|
|
378
|
+
onOpenChange: (e) => !e && C(),
|
|
379
|
+
children: /* @__PURE__ */ p(t, {
|
|
380
|
+
className: "pointer-events-auto fixed inset-0 !top-0 !left-0 !translate-x-0 !translate-y-0 h-full w-full max-w-none p-0 m-0 rounded-none border-0 overflow-hidden data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right",
|
|
381
|
+
hideCloseButton: !0,
|
|
382
|
+
children: [/* @__PURE__ */ f(_, { children: /* @__PURE__ */ f(e, { children: "Article Details" }) }), /* @__PURE__ */ f("div", {
|
|
383
|
+
className: "h-full overflow-y-auto",
|
|
384
|
+
children: Ge()
|
|
385
|
+
})]
|
|
386
|
+
})
|
|
387
|
+
});
|
|
388
|
+
};
|
|
389
|
+
export { y as default };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("./rolldown-runtime-BocRIvOZ.cjs"),t=require("./dialog-7GDz0sWx.cjs"),n=require("./tooltip-DmUO6ZUz.cjs"),r=require("./src-Ckb1ciEL.cjs"),i=require("./config.cjs");let a=require("react");a=e.t(a,1);let o=require("react/jsx-runtime"),s=require("sonner"),c=require("qwksearch-api-client");var l=a.forwardRef(({className:e,...n},r)=>(0,o.jsx)(`span`,{ref:r,className:t.o(`absolute w-px h-px p-0 -m-px overflow-hidden whitespace-nowrap border-0`,e),style:{clip:`rect(0, 0, 0, 0)`,clipPath:`inset(50%)`},...n}));l.displayName=`VisuallyHidden`;function u(e){return e instanceof Error&&e.name===`AbortError`}async function ee(e,t){if(t.share)try{return await t.share(e),`shared`}catch(e){if(u(e))return`cancelled`}return await t.writeText(e.url),`copied`}var d=e=>{let{isOpen:u,url:d,searchText:te,suggestQuestions:f,panelWidth:ne,setPanelWidth:p,closePanel:re}=n.a(),{isAuthenticated:ie}=n.c(),{chatModelProvider:m}=n.u(),h=e.isOpen===void 0?u:e.isOpen,g=e.onClose||re,_=e.url||d,ae=e.searchText===void 0?te:e.searchText,[v,y]=(0,a.useState)(null),[b,oe]=(0,a.useState)([]),[se,x]=(0,a.useState)(!1),[ce,S]=(0,a.useState)(!1),[C,w]=(0,a.useState)(i.researchAgentUIConfig.defaultSummarizePrompt),[le,T]=(0,a.useState)(!1),[E,ue]=(0,a.useState)(!1),[D,de]=(0,a.useState)(!1),[O,fe]=(0,a.useState)(``),[k,pe]=(0,a.useState)(``),[me,A]=(0,a.useState)([]),[he,ge]=(0,a.useState)(``),[j,M]=(0,a.useState)(!1),[_e,N]=(0,a.useState)(!1),[P,F]=(0,a.useState)(!1),[I,ve]=(0,a.useState)(!1),[ye,be]=(0,a.useState)(ne),[L,R]=(0,a.useState)(!1),[xe,z]=(0,a.useState)(!1),[B,V]=(0,a.useState)(1),Se=(0,a.useRef)(null),H=(0,a.useRef)({}),U=.5,W=1.8,G=.1;(0,a.useEffect)(()=>{let e=parseFloat(localStorage.getItem(`articleFontScale`)||``);Number.isNaN(e)||V(Math.min(W,Math.max(U,e)))},[]);let K=e=>{let t=Math.min(W,Math.max(U,Math.round(e*100)/100));V(t);try{localStorage.setItem(`articleFontScale`,String(t))}catch(e){console.error(`Error storing article font scale:`,e)}},q=()=>K(B+G),J=()=>K(B-G),Y=()=>K(1);(0,a.useEffect)(()=>{let e=()=>{ve(window.innerWidth>=1024)};return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]),(0,a.useEffect)(()=>{let e=e=>{if(!L)return;let t=window.innerWidth-e.clientX,n=Math.max(400,Math.min(t,window.innerWidth-100));be(n),p(n)},t=()=>{R(!1)};return L&&(document.addEventListener(`mousemove`,e),document.addEventListener(`mouseup`,t),document.body.style.cursor=`ew-resize`,document.body.style.userSelect=`none`),()=>{document.removeEventListener(`mousemove`,e),document.removeEventListener(`mouseup`,t),document.body.style.cursor=``,document.body.style.userSelect=``}},[L,p]),(0,a.useEffect)(()=>{h&&_?(z(!1),Ce()):h||z(!1)},[h,_]);let Ce=async()=>{console.log(`[ArticleExtractPanel] Extracting URL:`,_);try{let e=new URL(_);if([/^https?:\/\/(www\.)?google\.[^/]+\/search/i,/^https?:\/\/(www\.)?bing\.com\/search/i,/^https?:\/\/(www\.)?duckduckgo\.com\/\?/i].some(e=>e.test(_))){s.toast.error(`Cannot extract articles from search result pages`),T(!1),z(!0);return}(e.pathname===`/`||e.pathname===``)&&(console.error(`[ArticleExtractPanel] URL is domain-only, missing article path:`,_),s.toast.error(`Invalid article URL - only domain provided`))}catch(e){console.error(`[ArticleExtractPanel] Invalid URL format:`,_,e)}T(!0);try{let{data:e}=await(0,c.getArticle)({query:{url:_}}),t=e?.article,n=t?.html?.replace(/<[^>]*>/g,``).trim()||``;t?.error||n.length<20?(document.dispatchEvent(new CustomEvent(`onInvokeChromeAPI`,{detail:{type:`extractURL`,url:_}})),await Promise.race([new Promise(e=>{let t=async n=>{window.removeEventListener(`onExtractionResult`,t);let{data:r}=await(0,c.getArticle)({query:{url:_}}),i=r?.article;i&&(y(i),i.followUpQuestions?.length>0?A(i.followUpQuestions):f&&(A([]),Z(`suggest-followups`,{source:i}))),e()};window.addEventListener(`onExtractionResult`,t)}),new Promise(e=>setTimeout(e,1e4))])):(y(t),t?.followUpQuestions&&t.followUpQuestions.length>0?A(t.followUpQuestions):f&&t&&(A([]),Z(`suggest-followups`,{source:t}))),ie&&we()}catch(e){console.error(`[ArticleExtractPanel] Error extracting URL:`,e),s.toast.error(`Failed to load article`)}finally{T(!1),z(!0)}},we=async()=>{try{let{data:e}=await(0,c.listFavorites)(),t=e?.favorites?.some(e=>e.url===_);M(!!t)}catch(e){console.error(`Error checking favorite status:`,e)}},X=async()=>{if(v){N(!0);try{j?(await(0,c.removeFavorite)({query:{url:_}}),M(!1),s.toast.info(`Removed from favorites`)):(await(0,c.addFavorite)({body:{url:v.url||_,title:v.title,cite:v.cite,author:v.author,author_cite:v.author_cite,date:v.date,source:v.source,word_count:v.word_count,html:v.html}}),M(!0),s.toast.success(`Added to favorites`))}catch(e){console.error(`Error toggling favorite:`,e),s.toast.error(`Failed to toggle favorite`)}finally{N(!1)}}},Te=()=>{if(m?.key&&m?.providerId)return m;try{let e=localStorage.getItem(`chatModelKey`)||``,t=localStorage.getItem(`chatModelProviderId`)||``;if(e&&t)return{key:e,providerId:t}}catch(e){console.error(`Error reading persisted chat model:`,e)}return m},Z=async(e,{source:t=v,question:n=C}={})=>{if(!t)return;let r=Te(),a=t.html?.replace(/<[^>]*>?/g,``).slice(0,i.researchAgentUIConfig.maxArticleLength),o=e===`question`,s=o?ue:de,l=o?pe:ge;s(!0),l(``);try{if(o){let e=[ae,n].filter(Boolean).join(`
|
|
2
|
+
`);if(!a||a.length===0)throw Error(`Article content is empty`);let{data:t,error:i}=await(0,c.articleQa)({body:{article:a,question:e,chatHistory:b.slice(-5),chatModel:r}});if(i){let e=i.details||i.error||i.message||`Article QA failed`;throw Error(e)}let o=t?.content||``;fe(o),oe(e=>[...e,{role:`user`,content:n,time:new Date().toISOString()},{role:`assistant`,content:o,time:new Date().toISOString()}]);try{await(0,c.updateArticle)({body:{url:_,question:n,answer:o}})}catch(e){console.error(`Error storing Q&A in cache:`,e)}}else{let e=parseInt(localStorage.getItem(`maxFollowupQuestions`)||`4`);if(!a||a.length===0)throw Error(`Article content is empty`);let{data:t,error:n}=await(0,c.articleFollowups)({body:{article:a,chatHistory:b.slice(-5),maxQuestions:e,chatModel:r}});if(n){let e=n.details||n.error||n.message||`Article followups failed`;throw Error(e)}let i=t?.extract||[];A(i);try{await(0,c.updateArticle)({body:{url:_,followUpQuestions:i}})}catch(e){console.error(`Error storing follow-up questions in cache:`,e)}}}catch(e){console.error(`Error calling language API:`,e),l(e instanceof Error||typeof e==`object`&&e&&`message`in e?e.message:`Failed to get AI response`)}finally{s(!1)}},Ee=e=>{w(e),Z(`question`,{question:e})},Q=async()=>{if(!v)return;let e=`${O}\n\n\n${v.cite||``}\n\n\n${v.html}`;try{await navigator.clipboard.writeText(e),x(!0),setTimeout(()=>x(!1),2e3)}catch(e){console.error(`Failed to copy to clipboard:`,e)}},De=async()=>{let e=v?.url||_;if(e)try{await ee({title:v?.title,text:v?.cite,url:e},{share:typeof navigator<`u`&&navigator.share?e=>navigator.share(e):void 0,writeText:e=>navigator.clipboard.writeText(e)})===`copied`&&(S(!0),setTimeout(()=>S(!1),2e3))}catch(e){console.error(`Failed to share article:`,e)}};H.current={ask:()=>Z(`question`),suggest:()=>Z(`suggest-followups`),copy:Q,highlight:()=>F(e=>!e),favorite:X,open:()=>{let e=v?.url||_;e&&window.open(e,`_blank`,`noopener,noreferrer`)},zoomIn:q,zoomOut:J,zoomReset:Y,close:g},(0,a.useEffect)(()=>{if(!h)return;let e=e=>/^[a-z]$/.test(e)?`Key${e.toUpperCase()}`:/^[0-9]$/.test(e)?`Digit${e}`:e===`-`?`Minus`:e===`=`?`Equal`:e,t={};Object.keys(r.D).forEach(n=>{let{alt:i,key:a}=r.D[n];i&&(t[e(a.toLowerCase())]=n)});let n=e=>{if(e.key===`Escape`){H.current.close?.();return}if(!e.altKey||e.ctrlKey||e.metaKey)return;let n=e.target;if(n&&(n.tagName===`INPUT`||n.tagName===`TEXTAREA`||n.isContentEditable))return;let r=t[e.code];if(!r)return;let i=H.current[r];i&&(e.preventDefault(),i())};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[h]);let $=()=>(0,o.jsxs)(`div`,{className:`flex h-full flex-col bg-background shadow-xl`,children:[(0,o.jsx)(`div`,{className:`shrink-0 border-b border-border bg-background/95 px-4 py-3 backdrop-blur supports-[backdrop-filter]:bg-background/80`,children:(0,o.jsx)(r.O,{isLoadingAI:E,isLoadingFollowups:D,isLoadingFavorite:_e,isFavorited:j,isHighlightMode:P,articleUrl:v?.url||_,fontScale:B,onAskClick:()=>Z(`question`),onSuggestClick:()=>Z(`suggest-followups`),onCopyClick:Q,onShareClick:De,onFavoriteClick:X,onHighlightToggle:()=>F(!P),onZoomIn:q,onZoomOut:J,onZoomReset:Y,onClose:g})}),(0,o.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:(0,o.jsxs)(`div`,{className:`p-4 space-y-6`,children:[(0,o.jsxs)(`div`,{className:`space-y-4`,children:[se&&(0,o.jsx)(`div`,{className:`bg-blue-500 text-white text-sm font-medium px-3 py-2 rounded-md shadow-lg`,children:`Copied!`}),ce&&(0,o.jsx)(`div`,{className:`bg-blue-500 text-white text-sm font-medium px-3 py-2 rounded-md shadow-lg`,children:`Link copied!`}),(0,o.jsx)(r.E,{value:C,onChange:w,onSubmit:()=>Z(`question`)}),(0,o.jsx)(r.T,{questions:me,isLoading:D,error:he,onQuestionClick:Ee}),b.length>0&&(0,o.jsx)(`div`,{className:`space-y-4`,children:b.map((e,t)=>(0,o.jsx)(`div`,{className:`space-y-2`,children:e.role===`user`?(0,o.jsxs)(`div`,{className:`bg-primary/10 border border-primary/20 rounded-lg p-3`,children:[(0,o.jsx)(`div`,{className:`text-xs font-semibold text-primary mb-1`,children:`Your Question`}),(0,o.jsx)(`div`,{className:`text-sm text-foreground`,children:e.content})]}):(0,o.jsxs)(`div`,{className:`bg-muted rounded-lg shadow-md p-4`,children:[(0,o.jsx)(`div`,{className:`text-xs font-semibold text-muted-foreground mb-2`,children:`AI Response`}),(0,o.jsx)(`div`,{className:`text-sm`,dangerouslySetInnerHTML:{__html:e.content}})]})},t))}),(E||O&&b.length===0)&&(0,o.jsx)(r.w,{response:O,isLoading:E,error:k}),k&&!E&&(0,o.jsx)(`div`,{className:`bg-red-500 text-white p-2 rounded-md text-sm`,children:k})]}),v&&(0,o.jsx)(r.S,{article:v,isHighlightMode:P,fontScale:B})]})})]});return!h||!xe?null:I?(0,o.jsxs)(`div`,{className:`fixed top-0 right-0 h-screen z-40 transition-all duration-300`,style:{width:`${ye}px`},children:[(0,o.jsx)(`div`,{ref:Se,onMouseDown:()=>R(!0),className:`absolute left-0 top-0 bottom-0 w-1 cursor-ew-resize hover:bg-primary bg-transparent transition-colors z-50`,style:{touchAction:`none`},children:(0,o.jsx)(`div`,{className:`absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-1 h-12 rounded-full bg-muted-foreground opacity-50 hover:opacity-100 transition-opacity`})}),$()]}):(0,o.jsx)(t.t,{open:h,onOpenChange:e=>!e&&g(),children:(0,o.jsxs)(t.n,{className:`pointer-events-auto fixed inset-0 !top-0 !left-0 !translate-x-0 !translate-y-0 h-full w-full max-w-none p-0 m-0 rounded-none border-0 overflow-hidden data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right`,hideCloseButton:!0,children:[(0,o.jsx)(l,{children:(0,o.jsx)(t.i,{children:`Article Details`})}),(0,o.jsx)(`div`,{className:`h-full overflow-y-auto`,children:$()})]})})};exports.default=d;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const e=require("./rolldown-runtime-BocRIvOZ.cjs"),t=require("./dialog-7GDz0sWx.cjs"),n=require("./tooltip-DmUO6ZUz.cjs"),r=require("./src-Ckb1ciEL.cjs"),i=require("./config.cjs");let a=require("react");a=e.t(a,1);let o=require("react/jsx-runtime"),s=require("motion/react"),c=require("lucide-react"),l=require("qwksearch-api-client"),u=require("quantum-sphere-loading-icon/react");u=e.t(u,1);let d=require("markdown-to-jsx");d=e.t(d,1);let f=require("extract-webpage/html-to-content/html-utils"),p=require("@radix-ui/react-popover");p=e.t(p,1);let m=require("grab-url/animations");m=e.t(m,1);var h=(0,a.memo)(({blur:e=0,inactiveZone:n=.7,proximity:r=0,spread:i=20,variant:c=`default`,glow:l=!1,className:u,movementDuration:d=2,borderWidth:f=1,disabled:p=!0})=>{let m=(0,a.useRef)(null),h=(0,a.useRef)({x:0,y:0}),g=(0,a.useRef)(0),_=(0,a.useCallback)(e=>{m.current&&(g.current&&cancelAnimationFrame(g.current),g.current=requestAnimationFrame(()=>{let t=m.current;if(!t)return;let{left:i,top:a,width:o,height:c}=t.getBoundingClientRect(),l=e?.x??h.current.x,u=e?.y??h.current.y;e&&(h.current={x:l,y:u});let f=[i+o*.5,a+c*.5];if(Math.hypot(l-f[0],u-f[1])<.5*Math.min(o,c)*n){t.style.setProperty(`--active`,`0`);return}let p=l>i-r&&l<i+o+r&&u>a-r&&u<a+c+r;if(t.style.setProperty(`--active`,p?`1`:`0`),!p)return;let g=parseFloat(t.style.getPropertyValue(`--start`))||0,_=g+((180*Math.atan2(u-f[1],l-f[0])/Math.PI+90-g+180)%360-180);(0,s.animate)(g,_,{duration:d,ease:[.16,1,.3,1],onUpdate:e=>{t.style.setProperty(`--start`,String(e))}})}))},[n,r,d]);return(0,a.useEffect)(()=>{if(p)return;let e=()=>_(),t=e=>_(e);return window.addEventListener(`scroll`,e,{passive:!0}),document.body.addEventListener(`pointermove`,t,{passive:!0}),()=>{g.current&&cancelAnimationFrame(g.current),window.removeEventListener(`scroll`,e),document.body.removeEventListener(`pointermove`,t)}},[_,p]),(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(`div`,{className:t.o(`pointer-events-none absolute -inset-px hidden rounded-[inherit] border opacity-0 transition-opacity`,l&&`opacity-100`,c===`white`&&`border-white`,p&&`!block`)}),(0,o.jsx)(`div`,{ref:m,style:{"--blur":`${e}px`,"--spread":i,"--start":`0`,"--active":`0`,"--glowingeffect-border-width":`${f}px`,"--repeating-conic-gradient-times":`5`,"--gradient":c===`white`?`repeating-conic-gradient(
|
|
2
|
+
from 236.84deg at 50% 50%,
|
|
3
|
+
var(--black),
|
|
4
|
+
var(--black) calc(25% / var(--repeating-conic-gradient-times))
|
|
5
|
+
)`:`radial-gradient(circle, #dd7bbb 10%, #dd7bbb00 20%),
|
|
6
|
+
radial-gradient(circle at 40% 40%, #d79f1e 5%, #d79f1e00 15%),
|
|
7
|
+
radial-gradient(circle at 60% 60%, #5a922c 10%, #5a922c00 20%),
|
|
8
|
+
radial-gradient(circle at 40% 60%, #4c7894 10%, #4c789400 20%),
|
|
9
|
+
repeating-conic-gradient(
|
|
10
|
+
from 236.84deg at 50% 50%,
|
|
11
|
+
#dd7bbb 0%,
|
|
12
|
+
#d79f1e calc(25% / var(--repeating-conic-gradient-times)),
|
|
13
|
+
#5a922c calc(50% / var(--repeating-conic-gradient-times)),
|
|
14
|
+
#4c7894 calc(75% / var(--repeating-conic-gradient-times)),
|
|
15
|
+
#dd7bbb calc(100% / var(--repeating-conic-gradient-times))
|
|
16
|
+
)`},className:t.o(`pointer-events-none absolute inset-0 rounded-[inherit] opacity-100 transition-opacity`,l&&`opacity-100`,e>0&&`blur-[var(--blur)] `,u,p&&`!hidden`),children:(0,o.jsx)(`div`,{className:t.o(`glow`,`rounded-[inherit]`,`after:content-[""] after:rounded-[inherit] after:absolute after:inset-[calc(-1*var(--glowingeffect-border-width))]`,`after:[border:var(--glowingeffect-border-width)_solid_transparent]`,`after:[background:var(--gradient)] after:[background-attachment:fixed]`,`after:opacity-[var(--active)] after:transition-opacity after:duration-300`,`after:[mask-clip:padding-box,border-box]`,`after:[mask-composite:intersect]`,`after:[mask-image:linear-gradient(#0000,#0000),conic-gradient(from_calc((var(--start)-var(--spread))*1deg),#00000000_0deg,#fff,#00000000_calc(var(--spread)*2deg))]`)})})]})});h.displayName=`GlowingEffect`;function g(e){try{let t=new URL(e);return t.protocol===`https:`||t.protocol===`http:`}catch{return!1}}function _(e){return e.iframe_src&&g(e.iframe_src)?{type:`inline`,src:e.iframe_src}:{type:`external`,url:e.url||``}}function v(e){return{pageContent:e.snippet||e.content||``,metadata:{title:e.title||``,source:e.source||``,thumbnail:e.thumbnail||``,url:e.url||``,...e.img_src&&{img_src:e.img_src},...e.iframe_src&&{iframe_src:e.iframe_src}}}}var y=r.J.filter(e=>[`general`,`news`,`videos`,`images`,`science`,`files`].includes(e.code)),b=({sources:e,query:r})=>{let[i,s]=(0,a.useState)(`general`),[u,d]=(0,a.useState)(e),[p,m]=(0,a.useState)(!1),[g,b]=(0,a.useState)(!1),[x,S]=(0,a.useState)(1),[C,w]=(0,a.useState)(!0),[T,E]=(0,a.useState)(!1),[D,O]=(0,a.useState)(!1),[k,A]=(0,a.useState)(null),j=(0,a.useRef)(null),M=(0,a.useRef)(!1),N=(0,a.useRef)(!1),{openPanel:P,isOpen:F}=n.a();(0,a.useEffect)(()=>{let e=()=>{O(localStorage.getItem(`searchResultGlow`)===`true`)};return e(),window.addEventListener(`client-config-changed`,e),window.addEventListener(`storage`,e),()=>{window.removeEventListener(`client-config-changed`,e),window.removeEventListener(`storage`,e)}},[]);let[I,L]=(0,a.useState)({});(0,a.useEffect)(()=>{let e=()=>{E(window.innerWidth>=1024)};return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]),(0,a.useEffect)(()=>{d(e),s(`general`),S(1),w(!0),L({}),R(e)},[e]);let R=(0,a.useCallback)(async e=>{let t=e.filter(e=>e.metadata.url&&e.metadata.url!==`File`&&!e.metadata.iframe_src);for(let e of t)try{let{data:t}=await(0,l.getArticle)({query:{url:e.metadata.url}});t?.cached&&t?.article?.html&&L(t=>({...t,[e.metadata.url]:`loaded`}))}catch{}},[]);(0,a.useEffect)(()=>{if(typeof window<`u`){let e=new URLSearchParams(window.location.search).get(`extract`);e&&(P(decodeURIComponent(e),``),N.current=!1)}},[P]),(0,a.useEffect)(()=>{N.current=!1},[e]),(0,a.useEffect)(()=>{M.current&&!F&&(N.current=!0),M.current=F},[F]),(0,a.useEffect)(()=>{if(T&&u&&u.length>0&&!F&&!N.current){let e=u[0];e?.metadata?.url&&P(e.metadata.url,``)}},[u,T]);let z=async(e,t)=>{e.preventDefault(),N.current=!1,L(e=>({...e,[t]:`loading`})),P(t,``);try{await(0,l.getArticle)({query:{url:t}}),L(e=>({...e,[t]:`loaded`}))}catch{L(e=>({...e,[t]:`loaded`}))}},B=(0,a.useCallback)(async()=>{if(!r||g||!C)return;b(!0);let e=x+1,{data:t}=await(0,l.agentSearch)({query:{q:r,cat:i,page:e}}),n=t?.results??[];if(n.length===0){w(!1),b(!1);return}let a=n.map(e=>{if(e.url)try{let t=new URL(e.url);(t.pathname===`/`||t.pathname===``)&&console.warn(`[MessageSources] Search result URL is domain-only:`,e.url,`Title:`,e.title)}catch{console.error(`[MessageSources] Invalid URL in search result:`,e.url)}return v(e)});d(e=>[...e,...a]),S(e),b(!1)},[r,i,x,g,C]),V=async e=>{if(e!==i&&r){s(e),m(!0),S(1),w(!0);try{let{data:t}=await(0,l.agentSearch)({query:{q:r,cat:e,page:1}}),n=(t?.results??[]).map(e=>{if(e.url)try{let t=new URL(e.url);(t.pathname===`/`||t.pathname===``)&&console.warn(`[MessageSources] Category search result URL is domain-only:`,e.url,`Title:`,e.title)}catch{console.error(`[MessageSources] Invalid URL in category search result:`,e.url)}return v(e)});d(n)}catch(e){console.error(`Error searching:`,e)}finally{m(!1)}}};(0,a.useEffect)(()=>{let e=j.current;if(!e)return;let t=()=>{let{scrollTop:t,scrollHeight:n,clientHeight:r}=e;n-t-r<100&&B()};return e.addEventListener(`scroll`,t),()=>e.removeEventListener(`scroll`,t)},[B]);let H=(e,t)=>{let n=i===`images`,r=i===`videos`,a=e.metadata.img_src||e.metadata.thumbnail;if(n&&a)return(0,o.jsx)(`div`,{className:`relative rounded-lg group`,children:(0,o.jsxs)(`a`,{className:`relative block overflow-hidden rounded-lg cursor-pointer`,href:e.metadata.url,onClick:t=>z(t,e.metadata.url),children:[(0,o.jsx)(`img`,{src:a,alt:e.metadata.title,className:`w-full h-auto object-cover rounded-lg hover:scale-105 transition-transform duration-200`,loading:`lazy`}),(0,o.jsxs)(`div`,{className:`absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/70 to-transparent p-2 opacity-0 group-hover:opacity-100 transition-opacity duration-200`,children:[(0,o.jsx)(`p`,{className:`text-xs text-white line-clamp-2`,children:(0,f.convertURLSafeHTMLToHTML)(e.metadata.title)}),(0,o.jsx)(`p`,{className:`text-[10px] text-white/70 truncate mt-0.5`,children:e.metadata.source})]})]})},t);if(r&&a){let n=_(e.metadata),r=(0,o.jsxs)(`div`,{className:`relative`,children:[(0,o.jsx)(`img`,{src:a,alt:e.metadata.title,className:`w-full h-24 object-cover`}),(0,o.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,o.jsx)(`div`,{className:`w-10 h-10 bg-black/60 rounded-full flex items-center justify-center`,children:(0,o.jsx)(c.Video,{size:18,className:`text-white ml-0.5`})})})]}),i=(0,o.jsx)(`p`,{className:`text-xs line-clamp-2 p-2 text-muted-foreground`,children:(0,f.convertURLSafeHTMLToHTML)(e.metadata.title)});return(0,o.jsxs)(`div`,{className:`relative rounded-xl`,children:[(0,o.jsx)(h,{spread:40,glow:!0,disabled:!D,proximity:64,inactiveZone:.01,borderWidth:2}),n.type===`inline`?(0,o.jsxs)(`button`,{type:`button`,className:`relative w-full text-left bg-card text-card-foreground border border-border rounded-xl overflow-hidden flex flex-col cursor-pointer shadow-sm hover:shadow-md transition-all duration-200`,onClick:()=>A({src:n.src,title:e.metadata.title}),children:[r,i]}):(0,o.jsxs)(`a`,{className:`relative bg-card text-card-foreground border border-border rounded-xl overflow-hidden flex flex-col cursor-pointer shadow-sm hover:shadow-md transition-all duration-200`,href:n.url,target:`_blank`,rel:`noopener noreferrer`,children:[r,i]})]},t)}let s=I[e.metadata.url];return(0,o.jsxs)(`div`,{className:`relative rounded-xl group h-full`,children:[(0,o.jsx)(h,{spread:40,glow:!0,disabled:!D,proximity:64,inactiveZone:.01,borderWidth:2}),(0,o.jsxs)(`div`,{className:`relative bg-card text-card-foreground border border-border rounded-xl p-2.5 flex flex-col font-medium cursor-pointer shadow-sm hover:shadow-md transition-all duration-200 h-full`,onClick:t=>z(t,e.metadata.url),children:[s&&(0,o.jsx)(`div`,{className:`absolute top-1.5 left-1.5 p-1 rounded-md bg-background/80 backdrop-blur-sm z-[5]`,children:s===`loading`?(0,o.jsx)(c.Loader2,{size:14,className:`text-primary animate-spin`}):(0,o.jsx)(c.FileText,{size:14,className:`text-green-500`})}),(0,o.jsx)(`a`,{href:e.metadata.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`absolute top-1.5 right-1.5 p-1 rounded-md bg-secondary/50 opacity-0 group-hover:opacity-100 transition-opacity hover:bg-secondary z-10`,title:`Open in new tab`,children:(0,o.jsx)(c.ExternalLink,{size:12,className:`text-muted-foreground`})}),(0,o.jsxs)(`p`,{className:`text-xs line-clamp-4 text-muted-foreground`,children:[(0,o.jsxs)(`span`,{className:`inline-flex items-center gap-1 font-semibold text-foreground/70 align-middle`,children:[e.metadata.url===`File`?(0,o.jsx)(`span`,{className:`inline-flex items-center justify-center w-3.5 h-3.5 rounded-full bg-secondary flex-shrink-0`,children:(0,o.jsx)(c.File,{size:10,className:`text-muted-foreground`})}):(0,o.jsx)(`img`,{src:`https://s2.googleusercontent.com/s2/favicons?domain_url=${e.metadata.url}`,width:20,height:20,alt:`favicon`,className:`inline rounded h-5 w-5 flex-shrink-0`}),e.metadata.source]}),` `,(0,o.jsx)(`span`,{className:`align-middle`,children:(0,f.convertURLSafeHTMLToHTML)(e.metadata.title)})]})]})]},t)};return(0,o.jsxs)(o.Fragment,{children:[r&&(0,o.jsx)(`div`,{className:`flex items-center gap-1 mb-3 overflow-x-auto pb-1`,children:y.map(e=>(0,o.jsxs)(`button`,{onClick:()=>V(e.code),disabled:p,className:t.o(`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-sm font-medium transition-all duration-200 whitespace-nowrap`,i===e.code?`bg-primary text-primary-foreground`:`bg-secondary/50 text-muted-foreground hover:bg-secondary hover:text-foreground`),children:[(0,o.jsx)(e.icon,{className:`w-4 h-4 flex-shrink-0`}),(0,o.jsx)(`span`,{children:e.name})]},e.code))}),(0,o.jsx)(`div`,{ref:j,className:t.o(`overflow-y-auto pb-2 pr-1`,i===`images`?`max-h-[400px] lg:max-h-[500px]`:`max-h-[180px] lg:max-h-[280px]`),children:p?(0,o.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,o.jsx)(c.Loader2,{className:`w-6 h-6 animate-spin text-muted-foreground`})}):u.length>0?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(`div`,{className:t.o(i===`images`?`columns-2 sm:columns-3 lg:columns-4 gap-2 [&>div]:mb-2 [&>div]:break-inside-avoid`:t.o(`grid gap-3 auto-rows-fr`,F&&T?`grid-cols-2`:`grid-cols-3`)),children:u.map((e,t)=>H(e,t))}),g&&(0,o.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,o.jsx)(c.Loader2,{className:`w-5 h-5 animate-spin text-muted-foreground`})}),!C&&u.length>0&&(0,o.jsx)(`div`,{className:`flex items-center justify-center py-4 text-muted-foreground text-xs`,children:`No more results`})]}):(0,o.jsx)(`div`,{className:`flex items-center justify-center py-8 text-muted-foreground text-sm`,children:`No results found`})}),(0,o.jsx)(t.t,{open:k!==null,onOpenChange:e=>!e&&A(null),children:(0,o.jsxs)(t.n,{className:`max-w-3xl p-0 overflow-hidden gap-0`,children:[(0,o.jsx)(t.i,{className:`sr-only`,children:k?.title||`Video player`}),k&&(0,o.jsx)(`iframe`,{src:k.src,title:k.title||`Video player`,className:`w-full aspect-video`,allow:`accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture`,allowFullScreen:!0})]})})]})},x={extract:`Extract`,arxiv:`ArXiv`,"google scholar":`Scholar`,pubmed:`PubMed`,wolframalpha:`Wolfram`,youtube:`YouTube`,Web:`Web`};function S(e){return e?x[e]??e:`Web`}function C({queries:e,loading:n}){let r=e.filter(e=>e.status===`done`).length,i=e.length,a=n&&e.some(e=>e.status===`running`);return n?(0,o.jsxs)(`div`,{className:`rounded-xl border border-border bg-secondary/20 overflow-hidden text-sm`,children:[(0,o.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border/50`,children:[(0,o.jsxs)(`div`,{className:`flex items-center gap-2 text-muted-foreground`,children:[a?(0,o.jsx)(c.Loader2,{className:`w-3.5 h-3.5 animate-spin`}):(0,o.jsx)(c.Search,{className:`w-3.5 h-3.5`}),(0,o.jsx)(`span`,{className:`font-medium text-foreground`,children:a?`Running analysis…`:`Analysis complete`})]}),i>0&&(0,o.jsxs)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:[r,`/`,i,` searches`]})]}),e.length>0&&(0,o.jsx)(`div`,{className:`divide-y divide-border/40`,children:e.map((e,n)=>(0,o.jsxs)(`div`,{className:`flex items-center gap-2.5 px-3 py-2`,children:[e.status===`running`?(0,o.jsx)(c.Loader2,{className:`w-3.5 h-3.5 text-muted-foreground animate-spin flex-shrink-0`}):(0,o.jsx)(c.Search,{className:t.o(`w-3.5 h-3.5 flex-shrink-0`,e.status===`done`?`text-muted-foreground`:`text-muted-foreground/40`)}),(0,o.jsxs)(`div`,{className:`flex items-baseline gap-1.5 min-w-0 flex-1`,children:[(0,o.jsxs)(`span`,{className:`text-xs text-muted-foreground whitespace-nowrap flex-shrink-0`,children:[S(e.category),` ·`]}),(0,o.jsx)(`span`,{className:`text-foreground/80 truncate`,children:e.query})]})]},n))})]}):null}var w=({href:e,children:t,sources:r})=>{let{openPanel:i}=n.a(),s=(0,a.useMemo)(()=>!r||!e?null:r.find(t=>t.metadata?.url===e)??null,[r,e]),c=(0,a.useMemo)(()=>{try{return new URL(e).hostname.replace(`www.`,``)}catch{return s?.metadata?.source||``}},[e,s]),l=s?.metadata?.title||``,u=`https://s2.googleusercontent.com/s2/favicons?domain_url=${e}`;return(0,o.jsxs)(n.t,{children:[(0,o.jsx)(n.r,{asChild:!0,children:(0,o.jsx)(`a`,{href:e,onClick:t=>{t.preventDefault(),i(e,``)},className:`bg-light-secondary dark:bg-dark-secondary px-1 rounded ml-1 no-underline text-xs text-black/70 dark:text-white/70 relative cursor-pointer hover:bg-black/10 dark:hover:bg-white/20 transition-colors`,children:t})}),(0,o.jsx)(n.n,{side:`top`,className:`max-w-72 p-2.5`,children:(0,o.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,o.jsx)(`img`,{src:u,alt:``,width:16,height:16,className:`rounded flex-shrink-0 mt-0.5`}),(0,o.jsxs)(`div`,{className:`min-w-0`,children:[(0,o.jsx)(`p`,{className:`text-xs font-medium leading-snug line-clamp-2`,children:l||c}),l&&(0,o.jsx)(`p`,{className:`text-[10px] opacity-70 truncate mt-0.5`,children:c})]})]})})]})},T=({content:e,thinkingEnded:t})=>{let[n,r]=(0,a.useState)(!0);return(0,a.useEffect)(()=>{r(!t)},[t]),(0,o.jsxs)(`div`,{className:`my-4 bg-secondary/50 rounded-xl border border-border overflow-hidden`,children:[(0,o.jsxs)(`button`,{onClick:()=>r(!n),className:`w-full flex items-center justify-between px-4 py-1 text-foreground/90 hover:bg-secondary transition duration-200`,children:[(0,o.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,o.jsx)(c.BrainCircuit,{size:20,className:`text-accent-foreground`}),(0,o.jsx)(`p`,{className:`font-medium text-sm`,children:`Thinking Process`})]}),n?(0,o.jsx)(c.ChevronUp,{size:18,className:`text-muted-foreground`}):(0,o.jsx)(c.ChevronDown,{size:18,className:`text-muted-foreground`})]}),n&&(0,o.jsx)(`div`,{className:`px-4 py-3 text-foreground/80 text-sm border-t border-border bg-muted/50 whitespace-pre-wrap`,children:e})]})},E=({children:e,thinkingEnded:t})=>(0,o.jsx)(T,{content:e,thinkingEnded:t}),D=[`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`bmp`,`avif`],O=e=>{let t=(e||``).toLowerCase();return D.includes(t)?(0,o.jsx)(c.Image,{size:15}):t===`url`?(0,o.jsx)(c.Link2,{size:15}):(0,o.jsx)(c.FileText,{size:15})},k=({file:e})=>{let{deleteAttachedFile:r}=n.u(),[i,s]=(0,a.useState)(!1),[l,u]=(0,a.useState)(!1);return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(`div`,{className:`group inline-flex max-w-full items-center gap-2 rounded-lg border border-border bg-secondary/40 py-1.5 pl-2.5 pr-1.5 text-sm`,children:[(0,o.jsx)(`span`,{className:`text-muted-foreground`,children:O(e.fileExtension)}),(0,o.jsx)(`span`,{className:`min-w-0 truncate font-medium text-foreground`,title:e.fileName,children:e.fileName}),e.fileExtension&&e.fileExtension!==`url`&&(0,o.jsx)(`span`,{className:`hidden shrink-0 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground sm:inline`,children:e.fileExtension}),(0,o.jsx)(`button`,{type:`button`,"aria-label":`Delete ${e.fileName}`,onClick:()=>s(!0),className:`shrink-0 rounded-md p-1 text-muted-foreground transition-colors hover:bg-red-500/10 hover:text-red-500`,children:(0,o.jsx)(c.Trash2,{size:14})})]}),(0,o.jsx)(t.t,{open:i,onOpenChange:e=>{l||s(e)},children:(0,o.jsxs)(t.n,{className:`w-full max-w-md rounded-2xl`,children:[(0,o.jsx)(t.i,{className:`text-lg font-medium leading-6`,children:`Delete file`}),(0,o.jsxs)(t.r,{className:`text-sm text-muted-foreground`,children:[`Are you sure you want to delete`,` `,(0,o.jsx)(`span`,{className:`font-medium text-foreground`,children:e.fileName}),`? This removes it from the conversation and permanently deletes the upload.`]}),(0,o.jsxs)(`div`,{className:`mt-6 flex flex-row items-center justify-end gap-4`,children:[(0,o.jsx)(`button`,{type:`button`,onClick:()=>!l&&s(!1),className:`text-sm text-muted-foreground transition-colors hover:text-foreground`,children:`Cancel`}),(0,o.jsxs)(`button`,{type:`button`,onClick:async()=>{u(!0);try{await r(e.fileId),s(!1)}finally{u(!1)}},disabled:l,className:`inline-flex items-center gap-1.5 text-sm text-red-500 transition-colors hover:text-red-600 disabled:opacity-60`,children:[l&&(0,o.jsx)(c.Loader2,{size:14,className:`animate-spin`}),`Delete`]})]})]})})]})},A=({files:e})=>!e||e.length===0?null:(0,o.jsx)(`div`,{className:`ml-10 mt-2 flex flex-wrap gap-2`,children:e.map(e=>(0,o.jsx)(k,{file:e},e.fileId))}),j=({section:e,isExpanded:r,setIsExpanded:i,isEditing:s,setIsEditing:l,editText:u,setEditText:d,handleEditSubmit:f,copiedUserMsg:p,handleCopyUserMsg:m})=>{let h=(0,a.useRef)(null);return(0,o.jsxs)(`div`,{className:`w-full pt-8 break-words`,children:[(0,o.jsxs)(`button`,{onClick:()=>i(!r),className:`flex items-center gap-3 group text-left w-full`,children:[(0,o.jsx)(`div`,{className:`flex-shrink-0 p-1.5 rounded-lg bg-secondary/50 group-hover:bg-secondary transition-colors duration-200`,children:r?(0,o.jsx)(c.ChevronDown,{size:18,className:`text-muted-foreground group-hover:text-foreground transition-colors`}):(0,o.jsx)(c.ChevronRight,{size:18,className:`text-muted-foreground group-hover:text-foreground transition-colors`})}),(0,o.jsx)(`h2`,{className:`text-foreground font-medium text-lg lg:text-3xl lg:w-9/12 group-hover:text-foreground/80 transition-colors line-clamp-3 lg:line-clamp-none`,children:e.userMessage.content})]}),(0,o.jsxs)(`div`,{className:`flex items-center gap-0.5 mt-1 ml-10`,children:[(()=>{let n=t.s(e.userMessage.createdAt);return n?(0,o.jsx)(`time`,{dateTime:new Date(e.userMessage.createdAt).toISOString(),className:`mr-1.5 text-xs text-muted-foreground tabular-nums select-none`,children:n}):null})(),(0,o.jsxs)(n.t,{children:[(0,o.jsx)(n.r,{asChild:!0,children:(0,o.jsx)(`button`,{onClick:m,className:`p-1.5 text-muted-foreground rounded-lg hover:bg-secondary transition-all duration-200 hover:text-foreground`,children:(0,o.jsx)(`span`,{className:t.o(`flex items-center transition-all duration-300`,p?`scale-110`:`scale-100`),children:p?(0,o.jsx)(c.Check,{size:14,className:`text-green-500`}):(0,o.jsx)(c.ClipboardList,{size:14})})})}),(0,o.jsx)(n.n,{side:`bottom`,children:p?`Copied!`:`Copy prompt`})]}),(0,o.jsxs)(n.t,{children:[(0,o.jsx)(n.r,{asChild:!0,children:(0,o.jsx)(`button`,{onClick:()=>{d(e.userMessage.content),l(!0),setTimeout(()=>h.current?.focus(),50)},className:`p-1.5 text-muted-foreground rounded-lg hover:bg-secondary transition-all duration-200 hover:text-foreground`,children:(0,o.jsx)(c.Pencil,{size:14})})}),(0,o.jsx)(n.n,{side:`bottom`,children:`Edit & resubmit`})]})]}),(0,o.jsx)(A,{files:e.userMessage.files}),s&&(0,o.jsxs)(`div`,{className:`mt-3 ml-10 flex flex-col gap-2`,children:[(0,o.jsx)(`textarea`,{ref:h,value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),f()),e.key===`Escape`&&l(!1)},rows:3,className:`w-full rounded-xl border border-border bg-background p-3 text-sm resize-none focus:outline-none focus:ring-2 focus:ring-primary/30 transition-colors`}),(0,o.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,o.jsx)(`button`,{onClick:()=>l(!1),className:`px-3 py-1.5 text-sm text-muted-foreground rounded-lg hover:bg-secondary transition-colors duration-200`,children:`Cancel`}),(0,o.jsx)(`button`,{onClick:f,disabled:!u.trim(),className:`px-3 py-1.5 text-sm bg-primary text-primary-foreground rounded-lg hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors duration-200`,children:`Resubmit`})]})]})]})},M=({section:e,initialMessage:t})=>{let[r,i]=(0,a.useState)(!1);return(0,o.jsxs)(n.t,{children:[(0,o.jsx)(n.r,{asChild:!0,children:(0,o.jsx)(`button`,{onClick:()=>{let n=`${t}${e?.sourceMessage?.sources&&e.sourceMessage.sources.length>0&&`\n\nCitations:\n${e.sourceMessage.sources?.map((e,t)=>`[${t+1}] ${e.metadata.url}`).join(`
|
|
17
|
+
`)}`}`;navigator.clipboard.writeText(n),i(!0),setTimeout(()=>i(!1),1e3)},className:`p-2 text-muted-foreground rounded-full backdrop-blur-md bg-white/10 dark:bg-black/10 hover:bg-white/20 dark:hover:bg-black/20 transition duration-200 hover:text-foreground`,children:r?(0,o.jsx)(c.Check,{size:18}):(0,o.jsx)(c.ClipboardList,{size:18})})}),(0,o.jsx)(n.n,{side:`bottom`,children:r?`Copied!`:`Copy`})]})};function N({...e}){return(0,o.jsx)(p.Root,{"data-slot":`popover`,...e})}function P({...e}){return(0,o.jsx)(p.Trigger,{"data-slot":`popover-trigger`,...e})}function F({className:e,align:n=`center`,sideOffset:r=4,container:i,...a}){return(0,o.jsx)(p.Portal,{container:i,children:(0,o.jsx)(p.Content,{"data-slot":`popover-content`,align:n,sideOffset:r,className:t.o(`bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-2xl border p-4 shadow-md outline-hidden`,e),...a})})}var I=({messageId:e})=>{let{rewrite:i,chatModelProvider:s,setChatModelProvider:u}=n.u(),[d,f]=(0,a.useState)([]),[p,m]=(0,a.useState)(!0),[h,g]=(0,a.useState)(``),[_,v]=(0,a.useState)(!1);(0,a.useEffect)(()=>{_&&(async()=>{try{m(!0);let{data:e}=await(0,l.listProviders)();f(e?.providers??[])}catch(e){console.error(`Error loading providers:`,e)}finally{m(!1)}})()},[_]);let y=(0,a.useMemo)(()=>{if(!s?.providerId)return d;let e=d.findIndex(e=>e.id===s.providerId);return e===-1?d:[d[e],...d.filter((t,n)=>n!==e)]},[d,s]).map(e=>({...e,chatModels:(e.chatModels??[]).filter(t=>t.name.toLowerCase().includes(h.toLowerCase())||e.name.toLowerCase().includes(h.toLowerCase()))})).filter(e=>e.chatModels.length>0),b=(0,a.useMemo)(()=>{if(!s.key)return`Rewrite`;for(let e of d){let t=e.chatModels.find(e=>e.key===s.key);if(t)return t.name}return s.key},[d,s.key]),x=(t,n)=>{u({providerId:t,key:n}),localStorage.setItem(`chatModelProviderId`,t),localStorage.setItem(`chatModelKey`,n),v(!1),i(e)};return(0,o.jsxs)(N,{open:_,onOpenChange:v,children:[(0,o.jsxs)(n.t,{children:[(0,o.jsx)(n.r,{asChild:!0,children:(0,o.jsx)(P,{asChild:!0,children:(0,o.jsx)(`button`,{className:`p-2 text-muted-foreground rounded-full backdrop-blur-md bg-white/10 dark:bg-black/10 hover:bg-white/20 dark:hover:bg-black/20 transition duration-200 hover:text-foreground`,children:(0,o.jsx)(c.ArrowLeftRight,{size:18})})})}),(0,o.jsxs)(n.n,{side:`bottom`,children:[`Rewrite with `,b]})]}),(0,o.jsx)(F,{className:`w-[280px] p-0`,align:`start`,side:`top`,sideOffset:8,children:(0,o.jsxs)(`div`,{className:`bg-white dark:bg-[#212121] max-h-[400px] border rounded-2xl border-[#DDDDDD] dark:border-[#30302E] w-full flex flex-col shadow-2xl overflow-hidden`,children:[(0,o.jsx)(`div`,{className:`p-3 border-b border-[#EEEEEE] dark:border-[#30302E]`,children:(0,o.jsxs)(`div`,{className:`relative`,children:[(0,o.jsx)(c.Search,{size:14,className:`absolute left-3 top-1/2 -translate-y-1/2 text-text-400 dark:text-[#999999]`}),(0,o.jsx)(`input`,{type:`text`,placeholder:`Search models...`,value:h,onChange:e=>g(e.target.value),className:`w-full pl-9 pr-3 py-2 text-[13px] bg-bg-100 dark:bg-[#30302E] border border-bg-300 dark:border-[#404040] rounded-lg text-text-100 dark:text-[#ECECEC] placeholder:text-text-400 dark:placeholder:text-[#999999] focus:outline-none focus:ring-2 focus:ring-sky-500/20 focus:border-sky-500/30 transition-all`})]})}),(0,o.jsx)(`div`,{className:`max-h-[320px] overflow-y-auto`,children:p?(0,o.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,o.jsx)(r.tt.Loader2,{className:`animate-spin text-text-400 dark:text-[#999999]`,size:20})}):y.length===0?(0,o.jsx)(`div`,{className:`text-center py-12 px-4 text-text-400 dark:text-[#999999] text-sm`,children:h?`No models found`:`No chat models configured`}):(0,o.jsx)(`div`,{className:`flex flex-col`,children:y.map((e,n)=>(0,o.jsxs)(`div`,{children:[(0,o.jsx)(`div`,{className:`px-4 py-2 sticky top-0 bg-white dark:bg-[#212121] border-b border-[#EEEEEE]/50 dark:border-[#30302E]/50`,children:(0,o.jsx)(`p`,{className:`text-[11px] text-text-400 dark:text-[#999999] uppercase tracking-wider font-medium`,children:e.name})}),(0,o.jsx)(`div`,{className:`flex flex-col px-1.5 py-1.5 space-y-0.5`,children:e.chatModels.map(n=>(0,o.jsxs)(`button`,{onClick:()=>x(e.id,n.key),type:`button`,className:t.o(`px-3 py-2 flex items-center justify-between text-start duration-200 cursor-pointer transition rounded-xl group`,s?.providerId===e.id&&s?.key===n.key?`bg-sky-50 dark:bg-sky-500/10`:`hover:bg-bg-100 dark:hover:bg-[#30302E]`),children:[(0,o.jsxs)(`div`,{className:`flex items-center space-x-2.5 min-w-0 flex-1`,children:[(0,o.jsx)(c.Cpu,{size:14,className:t.o(`shrink-0`,s?.providerId===e.id&&s?.key===n.key?`text-sky-500`:`text-text-400 dark:text-[#999999] group-hover:text-text-300 dark:group-hover:text-[#B4B4B4]`)}),(0,o.jsx)(`p`,{className:t.o(`text-[13px] truncate`,s?.providerId===e.id&&s?.key===n.key?`text-sky-600 dark:text-sky-400 font-medium`:`text-text-200 dark:text-[#ECECEC] group-hover:text-text-100 dark:group-hover:text-white`),children:n.name})]}),s?.providerId===e.id&&s?.key===n.key&&(0,o.jsx)(r.tt.Check,{className:`w-4 h-4 text-sky-500 shrink-0`})]},n.key))}),n<y.length-1&&(0,o.jsx)(`div`,{className:`h-px bg-[#EEEEEE] dark:bg-[#30302E] mx-2`})]},e.id))})})]})})]})},L=({section:e,speechStatus:t,isLoadingTTS:i=!1,start:a,stop:s,handleOpenInLLM:l})=>e.assistantMessage?(0,o.jsx)(`div`,{className:`flex flex-row items-center justify-end w-full text-foreground py-4 -mx-2`,children:(0,o.jsxs)(`div`,{className:`flex flex-row items-center space-x-1`,children:[(0,o.jsx)(I,{messageId:e.assistantMessage.messageId}),(0,o.jsx)(M,{initialMessage:e.assistantMessage.content,section:e}),(0,o.jsxs)(n.t,{children:[(0,o.jsx)(n.r,{asChild:!0,children:(0,o.jsx)(`button`,{onClick:()=>{t===`started`?s():a()},disabled:i,className:`p-2 text-muted-foreground rounded-full backdrop-blur-md bg-white/10 dark:bg-black/10 hover:bg-white/20 dark:hover:bg-black/20 transition duration-200 hover:text-foreground disabled:opacity-50 disabled:cursor-not-allowed`,children:i?(0,o.jsx)(c.Loader2,{size:18,className:`animate-spin`}):t===`started`?(0,o.jsx)(c.StopCircle,{size:18}):(0,o.jsx)(c.Volume2,{size:18})})}),(0,o.jsx)(n.n,{side:`bottom`,children:i?`Loading TTS...`:t===`started`?`Stop`:`Read aloud`})]}),(0,o.jsxs)(r.Y,{children:[(0,o.jsxs)(n.t,{children:[(0,o.jsx)(n.r,{asChild:!0,children:(0,o.jsx)(r.Q,{asChild:!0,children:(0,o.jsx)(`button`,{className:`p-2 text-muted-foreground rounded-full backdrop-blur-md bg-white/10 dark:bg-black/10 hover:bg-white/20 dark:hover:bg-black/20 transition duration-200 hover:text-foreground`,children:(0,o.jsx)(c.Download,{size:18})})})}),(0,o.jsx)(n.n,{side:`bottom`,children:`Export`})]}),(0,o.jsxs)(r.X,{align:`end`,side:`top`,children:[(0,o.jsxs)(r.Z,{onClick:()=>r.G(e.userMessage.content,e.assistantMessage.content),children:[(0,o.jsx)(c.FileText,{size:16}),`Markdown`]}),(0,o.jsxs)(r.Z,{onClick:()=>r.K(e.userMessage.content,e.assistantMessage.content),children:[(0,o.jsx)(c.FileType,{size:16}),`PDF`]}),(0,o.jsxs)(r.Z,{onClick:()=>r.W(e.userMessage.content,e.assistantMessage.content),children:[(0,o.jsx)(c.FileDown,{size:16}),`DOCX`]}),(0,o.jsxs)(r.Z,{onClick:()=>r.q(e.userMessage.content,e.assistantMessage.content),children:[(0,o.jsx)(c.FileSpreadsheet,{size:16}),`Google Docs`]})]})]}),(0,o.jsxs)(r.Y,{children:[(0,o.jsxs)(n.t,{children:[(0,o.jsx)(n.r,{asChild:!0,children:(0,o.jsx)(r.Q,{asChild:!0,children:(0,o.jsx)(`button`,{className:`p-2 text-muted-foreground rounded-full backdrop-blur-md bg-white/10 dark:bg-black/10 hover:bg-white/20 dark:hover:bg-black/20 transition duration-200 hover:text-foreground`,children:(0,o.jsx)(c.ExternalLink,{size:18})})})}),(0,o.jsx)(n.n,{side:`bottom`,children:`Open in LLM`})]}),(0,o.jsxs)(r.X,{align:`end`,side:`top`,children:[(0,o.jsx)(r.Z,{onClick:()=>l(`qwksearch`),children:`QwkSearch`}),(0,o.jsx)(r.Z,{onClick:()=>l(`claude`),children:`Claude`}),(0,o.jsx)(r.Z,{onClick:()=>l(`perplexity`),children:`Perplexity`}),(0,o.jsx)(r.Z,{onClick:()=>l(`gemini`),children:`Google Gemini`}),(0,o.jsx)(r.Z,{onClick:()=>l(`chatgpt`),children:`ChatGPT`})]})]})]})}):null,R=({section:e,isLast:t,loading:n,sendMessage:i})=>{let s=(0,a.useRef)([]);return(0,a.useEffect)(()=>{e.suggestions&&e.suggestions.length>0&&(s.current=e.suggestions.slice(0,5))},[e.suggestions]),(0,a.useEffect)(()=>{let e=e=>{let t=e.target;if(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable)return;let n=e.key,r=parseInt(n);r>=1&&r<=5&&s.current.length>=r&&(e.preventDefault(),i(s.current[r-1]))};if(t&&s.current.length>0)return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,i]),!e.suggestions||e.suggestions.length===0||!e.assistantMessage?null:(0,o.jsx)(`div`,{className:`mt-8 pt-6 border-t border-border/50`,children:(0,o.jsx)(`div`,{className:`space-y-2`,children:e.suggestions?.slice(0,5).map((e,t)=>(0,o.jsx)(`button`,{onClick:()=>i(e),className:`group w-full px-4 py-4 text-left transition-all duration-200 cursor-pointer rounded-lg border border-border/50 hover:border-primary/30 hover:bg-accent/50 hover:shadow-sm`,children:(0,o.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,o.jsx)(r.V,{variant:`secondary`,className:`flex-shrink-0 h-6 w-6 p-0 flex items-center justify-center rounded-full text-sm font-semibold`,children:t+1}),(0,o.jsx)(`p`,{className:`flex-1 text-base font-medium text-muted-foreground group-hover:text-primary transition-colors duration-200 leading-relaxed`,children:e}),(0,o.jsx)(c.Plus,{size:18,className:`text-muted-foreground/60 group-hover:text-primary transition-colors duration-200 flex-shrink-0`})]})},t))})})},z=({section:e,dividerRef:i,isLast:s})=>{let{loading:c,sendMessage:l}=n.u(),[u,f]=(0,a.useState)(!0),[p,m]=(0,a.useState)(!1),[h,g]=(0,a.useState)(!1),[_,v]=(0,a.useState)(e.userMessage.content),y=()=>{navigator.clipboard.writeText(e.userMessage.content),m(!0),setTimeout(()=>m(!1),1500)},x=()=>{_.trim()&&(l(_.trim()),g(!1))},S=e.parsedAssistantMessage||``,T=e.speechMessage||``,D=e.thinkingEnded,{speechStatus:O,start:k,stop:A,isLoading:M}=r.d(T,{enableInterrupt:!0}),N=t=>{if(!e.assistantMessage)return;let n=`${e.userMessage.content}\n\n${e.assistantMessage.content}`;navigator.clipboard.writeText(n);let r={qwksearch:`https://qwksearch.com/?q=`,claude:`https://claude.ai/new?q=`,perplexity:`https://www.perplexity.ai/?q=`,gemini:`https://gemini.google.com/?q=`,chatgpt:`https://chat.openai.com/?q=`}[t];r&&window.open(`${r}${encodeURIComponent(n)}`,`_blank`)},P={overrides:{think:{component:E,props:{thinkingEnded:D}},citation:{component:w,props:{sources:e.sourceMessage?.sources||[]}},table:{component:({children:e,...t})=>(0,o.jsx)(`div`,{className:`not-prose -mx-2 my-4 max-w-full overflow-x-auto sm:mx-0`,children:(0,o.jsx)(`table`,{...t,className:`w-max min-w-full border-collapse text-sm`,children:e})})}}};return(0,o.jsxs)(`div`,{className:`space-y-3`,children:[(0,o.jsx)(j,{section:e,isExpanded:u,setIsExpanded:f,isEditing:h,setIsEditing:g,editText:_,setEditText:v,handleEditSubmit:x,copiedUserMsg:p,handleCopyUserMsg:y}),(0,o.jsx)(`div`,{className:t.o(`flex flex-col space-y-3 overflow-hidden transition-all duration-300 ease-in-out`,u?`max-h-[100000px] opacity-100`:`max-h-0 opacity-0`),children:(0,o.jsxs)(`div`,{ref:i,className:`flex flex-col space-y-6 w-full`,children:[e.searchingMessage&&e.searchingMessage.queries.length>0&&(0,o.jsx)(C,{queries:e.searchingMessage.queries,loading:c&&s}),e.sourceMessage&&e.sourceMessage.sources.length>0&&(0,o.jsx)(`div`,{className:`flex flex-col space-y-2`,children:(0,o.jsx)(b,{sources:e.sourceMessage.sources,query:e.userMessage.content})}),(0,o.jsx)(`div`,{className:`flex min-w-0 flex-col space-y-2`,children:e.assistantMessage&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(d.default,{className:t.o(`prose prose-lg prose-h1:mb-3 prose-h2:mb-2 prose-h2:mt-6 prose-h2:font-[800] prose-h3:mt-4 prose-h3:mb-1.5 prose-h3:font-[600] dark:prose-invert prose-p:leading-loose prose-pre:p-0 font-[400]`,`min-w-0 max-w-none break-words text-foreground font-inter`),options:P,children:S}),c&&s?null:(0,o.jsx)(L,{section:e,speechStatus:O,isLoadingTTS:M,start:k,stop:A,handleOpenInLLM:N}),(0,o.jsx)(R,{section:e,isLast:s,loading:c,sendMessage:l})]})})]})})]})},B=[`default`,`circle`,`pinwheel`,`circle-filled`,`ellipsis`,`ring`,`bars`,`infinite`],V=`M12 12c-2-2.67-4-4-6-4a4 4 0 1 0 0 8c2 0 4-1.33 6-4Zm0 0c2 2.67 4 4 6 4a4 4 0 0 0 0-8c-2 0-4 1.33-6 4Z`,H={transformBox:`view-box`,transformOrigin:`center`},U=[[12,2,12,6],[16.24,7.76,19.07,4.93],[18,12,22,12],[16.24,16.24,19.07,19.07],[12,18,12,22],[4.93,19.07,7.76,16.24],[2,12,6,12],[4.93,4.93,7.76,7.76]],W=e=>{switch(e){case`circle`:return(0,o.jsx)(`g`,{className:`animate-spin`,style:H,children:(0,o.jsx)(`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`})});case`pinwheel`:return(0,o.jsxs)(`g`,{className:`animate-spin`,style:H,children:[(0,o.jsx)(`path`,{d:`M22 12a1 1 0 0 1-10 0 1 1 0 0 0-10 0`}),(0,o.jsx)(`path`,{d:`M7 20.7a1 1 0 1 1 5-8.7 1 1 0 1 0 5-8.6`}),(0,o.jsx)(`path`,{d:`M7 3.3a1 1 0 1 1 5 8.6 1 1 0 1 0 5 8.6`}),(0,o.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`})]});case`circle-filled`:return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`,opacity:`0.2`}),(0,o.jsx)(`g`,{className:`animate-spin`,style:H,children:(0,o.jsx)(`path`,{d:`M21 12a9 9 0 0 0-9-9`})})]});case`ellipsis`:return(0,o.jsx)(`g`,{fill:`currentColor`,stroke:`none`,children:[4,12,20].map((e,t)=>(0,o.jsx)(`circle`,{cx:e,cy:`12`,r:`2.5`,children:(0,o.jsx)(`animate`,{attributeName:`cy`,values:`12;7.5;12`,keyTimes:`0;0.5;1`,dur:`1.2s`,begin:`${t*.16}s`,repeatCount:`indefinite`})},e))});case`ring`:return(0,o.jsx)(o.Fragment,{children:[0,-.8].map(e=>(0,o.jsxs)(`circle`,{cx:`12`,cy:`12`,r:`2`,children:[(0,o.jsx)(`animate`,{attributeName:`r`,values:`2;11`,dur:`1.6s`,begin:`${e}s`,repeatCount:`indefinite`}),(0,o.jsx)(`animate`,{attributeName:`opacity`,values:`1;0`,dur:`1.6s`,begin:`${e}s`,repeatCount:`indefinite`})]},e))});case`bars`:return(0,o.jsx)(`g`,{fill:`currentColor`,stroke:`none`,children:[2.5,10,17.5].map((e,t)=>(0,o.jsxs)(`rect`,{x:e,y:`8`,width:`4`,height:`8`,rx:`1.5`,children:[(0,o.jsx)(`animate`,{attributeName:`height`,values:`8;18;8`,keyTimes:`0;0.5;1`,dur:`1.1s`,begin:`${t*.18}s`,repeatCount:`indefinite`}),(0,o.jsx)(`animate`,{attributeName:`y`,values:`8;3;8`,keyTimes:`0;0.5;1`,dur:`1.1s`,begin:`${t*.18}s`,repeatCount:`indefinite`})]},e))});case`infinite`:return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(`path`,{d:V,opacity:`0.2`}),(0,o.jsx)(`path`,{d:V,pathLength:`100`,strokeDasharray:`25 75`,children:(0,o.jsx)(`animate`,{attributeName:`stroke-dashoffset`,values:`100;0`,dur:`1.5s`,repeatCount:`indefinite`})})]});default:return(0,o.jsx)(`g`,{className:`animate-spin`,style:H,children:U.map(([e,t,n,r],i)=>(0,o.jsx)(`line`,{x1:e,y1:t,x2:n,y2:r,opacity:1-i*.1},`${e}-${t}`))})}},G=({variant:e=`default`,size:n=24,className:r,...i})=>(0,o.jsx)(`svg`,{"aria-hidden":`true`,xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,width:n,height:n,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,className:t.o(`shrink-0`,r),...i,children:W(e)}),K=`quantumSphere`,q=`spinner:`,J=new Set([`loadingSpokes`,`loadingCircleNotch`,`loadingPinwheel`,`loadingCircleTrack`,`loadingDotsBounce`,`loadingPulseRing`,`loadingEqualizerBars`,`loadingInfiniteDash`]),Y=Object.fromEntries(Object.entries(m).filter(([e,t])=>typeof t==`function`&&e.startsWith(`loading`)&&!J.has(e))),X=[K,...B.map(e=>`${q}${e}`),...Object.keys(Y).sort()],Z;function Q(){let e=X.filter(e=>e!==Z),t=e.length>0?e:X;return Z=t[Math.floor(Math.random()*t.length)],Z}function $(e){if(!e.startsWith(`spinner:`))return;let t=e.slice(8);return B.find(e=>e===t)}function ee(e,t){let n=Y[e];return n?n({size:t,raw:!0}):``}var te=({size:e=140,className:n})=>{let[r,i]=(0,a.useState)(null);(0,a.useEffect)(()=>{i(Q())},[]);let s=r?$(r):void 0;return(0,o.jsx)(`div`,{role:`status`,"aria-label":`Loading`,className:t.o(`flex items-center justify-center w-full h-[200px]`,n),children:r===`quantumSphere`?(0,o.jsx)(u.default,{autoRandomize:!0}):s?(0,o.jsx)(G,{variant:s,size:e,className:`text-muted-foreground`}):r?(0,o.jsx)(`div`,{className:`flex items-center justify-center`,dangerouslySetInnerHTML:{__html:ee(r,e)}}):null})},ne=(0,a.lazy)(()=>Promise.resolve().then(()=>require("./ArticleExtractPanel-DAPLUpyx.cjs"))),re=()=>{let{sections:e,chatTurns:t,loading:s,messageAppeared:c,newChat:l,chatId:u}=n.u(),{isOpen:d,panelWidth:f}=n.a(),{isAuthenticated:p}=n.c(),[m,h]=(0,a.useState)(!1);(0,a.useEffect)(()=>{d&&h(!0)},[d]);let[g,_]=(0,a.useState)(!1),v=(0,a.useRef)(null),y=(0,a.useRef)(null),b=(0,a.useRef)(!1);(0,a.useEffect)(()=>{let e=()=>{_(window.innerWidth>=1024)};return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]),(0,a.useEffect)(()=>{t.length===1&&(document.title=`${t[0].content.substring(0,30)} - ${i.researchAgentUIConfig.appName}`),t[t.length-1]?.role===`user`&&(b.current=!0,y.current?.scrollIntoView({behavior:`auto`}),setTimeout(()=>{b.current=!1},100))},[t]);let x=g&&d?{width:`calc(100% - ${f}px)`}:{};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)(`div`,{className:`flex flex-col min-h-full transition-all duration-300`,style:x,children:[(0,o.jsxs)(`div`,{className:`flex-1 flex flex-col space-y-3 pb-48 ${g&&!d?`px-0 max-w-[800px] mx-auto w-full`:`px-4 lg:px-8`}`,children:[e.map((t,n)=>{let r=n===e.length-1;return(0,o.jsxs)(a.Fragment,{children:[(0,o.jsx)(z,{section:t,sectionIndex:n,dividerRef:r?v:void 0,isLast:r}),!r&&(0,o.jsx)(`div`,{className:`h-px w-full bg-light-secondary dark:bg-dark-secondary`})]},t.userMessage.messageId)}),s&&!c&&(0,o.jsx)(te,{}),(0,o.jsx)(`div`,{ref:y,className:`h-0`})]}),(0,o.jsx)(`div`,{className:`sticky bottom-[60px] md:bottom-0 z-40 bg-gradient-to-t from-background via-background to-transparent pt-4 pb-2`,children:(0,o.jsx)(r.U,{})})]}),(m||d)&&(0,o.jsx)(a.Suspense,{fallback:null,children:(0,o.jsx)(ne,{})})]})};exports.default=re;
|