research-agent-ui 0.1.354 → 0.1.355

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.
@@ -1,418 +0,0 @@
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 { A as s, C as c, M as ee, O as te, S as ne, T as re, j as l, k as ie, w as ae } from "./src-Czo4Yrd2.js";
4
- import { researchAgentUIConfig as u } from "./config.mjs";
5
- import * as d from "react";
6
- import { useEffect as f, useId as oe, useRef as p, useState as m } from "react";
7
- import { jsx as h, jsxs as g } from "react/jsx-runtime";
8
- import { toast as _ } from "sonner";
9
- import { addFavorite as se, articleFollowups as ce, articleQa as le, getArticle as v, listFavorites as ue, removeFavorite as de, updateArticle as y } from "qwksearch-api-client";
10
- // src/ui/visually-hidden.tsx
11
- var b = d.forwardRef(({ className: e, ...t }, r) => /* @__PURE__ */ h("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
- b.displayName = "VisuallyHidden";
21
- // src/lib/shareArticle.ts
22
- function fe(e) {
23
- return e instanceof Error && e.name === "AbortError";
24
- }
25
- async function pe(e, t) {
26
- if (t.share) try {
27
- return await t.share(e), "shared";
28
- } catch (e) {
29
- if (fe(e)) return "cancelled";
30
- }
31
- return await t.writeText(e.url), "copied";
32
- }
33
- // src/components/ArticleReader/ArticleExtractPanel.tsx
34
- var me = (n) => {
35
- let { isOpen: d, url: fe, searchText: me, suggestQuestions: he, panelWidth: ge, setPanelWidth: x, closePanel: _e } = i(), { isAuthenticated: ve } = a(), { chatModelProvider: S } = o(), C = n.isOpen === void 0 ? d : n.isOpen, w = n.onClose || _e, T = n.url || fe, ye = n.searchText === void 0 ? me : n.searchText, [E, D] = m(null), [O, be] = m([]), [xe, k] = m(!1), [Se, A] = m(!1), [j, M] = m(u.defaultSummarizePrompt), [Ce, N] = m(!1), [P, we] = m(!1), [F, Te] = m(!1), [I, Ee] = m(""), [L, De] = m(""), [Oe, R] = m([]), [ke, Ae] = m(""), [z, B] = m(!1), [je, Me] = m(!1), [V, H] = m(!1), [Ne, Pe] = m(!1), [Fe, Ie] = m(ge), [U, W] = m(!1), [Le, G] = m(!1), [K, q] = m(1), [J, Re] = m("questions"), [ze, Be] = m([]), Y = oe(), X = p(null), Ve = p(null), Z = p({}), He = .5, Ue = 1.8, We = .1;
36
- f(() => {
37
- let e = parseFloat(localStorage.getItem("articleFontScale") || "");
38
- Number.isNaN(e) || q(Math.min(Ue, Math.max(He, e)));
39
- }, []);
40
- let Q = (e) => {
41
- let t = Math.min(Ue, Math.max(He, 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
- }, Ge = (e) => {
49
- Re(e), e === "questions" && X.current?.scrollTo?.({ top: 0 });
50
- }, Ke = () => Q(K + We), qe = () => Q(K - We), Je = () => Q(1);
51
- f(() => {
52
- let e = () => {
53
- Pe(window.innerWidth >= 1024);
54
- };
55
- return e(), window.addEventListener("resize", e), () => window.removeEventListener("resize", e);
56
- }, []), f(() => {
57
- let e = (e) => {
58
- if (!U) return;
59
- let t = window.innerWidth - e.clientX, n = Math.max(400, Math.min(t, window.innerWidth - 100));
60
- Ie(n), x(n);
61
- }, t = () => {
62
- W(!1);
63
- };
64
- return U && (document.addEventListener("mousemove", e), document.addEventListener("mouseup", t), document.body.style.cursor = "ew-resize", document.body.style.userSelect = "none"), () => {
65
- document.removeEventListener("mousemove", e), document.removeEventListener("mouseup", t), document.body.style.cursor = "", document.body.style.userSelect = "";
66
- };
67
- }, [U, x]), f(() => {
68
- C && T ? (G(!1), Ye()) : C || G(!1);
69
- }, [C, T]);
70
- let Ye = async () => {
71
- console.log("[ArticleExtractPanel] Extracting URL:", T);
72
- try {
73
- let e = new URL(T);
74
- if ([
75
- /^https?:\/\/(www\.)?google\.[^/]+\/search/i,
76
- /^https?:\/\/(www\.)?bing\.com\/search/i,
77
- /^https?:\/\/(www\.)?duckduckgo\.com\/\?/i
78
- ].some((e) => e.test(T))) {
79
- _.error("Cannot extract articles from search result pages"), N(!1), G(!0);
80
- return;
81
- }
82
- (e.pathname === "/" || e.pathname === "") && (console.error("[ArticleExtractPanel] URL is domain-only, missing article path:", T), _.error("Invalid article URL - only domain provided"));
83
- } catch (e) {
84
- console.error("[ArticleExtractPanel] Invalid URL format:", T, e);
85
- }
86
- N(!0);
87
- try {
88
- let { data: e } = await v({ query: { url: T } }), t = e?.article, n = t?.html?.replace(/<[^>]*>/g, "").trim() || "";
89
- t?.error || n.length < 20 ? (document.dispatchEvent(new CustomEvent("onInvokeChromeAPI", { detail: {
90
- type: "extractURL",
91
- url: T
92
- } })), await Promise.race([new Promise((e) => {
93
- let t = async (n) => {
94
- window.removeEventListener("onExtractionResult", t);
95
- let { data: r } = await v({ query: { url: T } }), i = r?.article;
96
- i && (D(i), i.followUpQuestions?.length > 0 ? R(i.followUpQuestions) : he && (R([]), $("suggest-followups", { source: i }))), e();
97
- };
98
- window.addEventListener("onExtractionResult", t);
99
- }), new Promise((e) => setTimeout(e, 1e4))])) : (D(t), t?.followUpQuestions && t.followUpQuestions.length > 0 ? R(t.followUpQuestions) : he && t && (R([]), $("suggest-followups", { source: t }))), ve && Xe();
100
- } catch (e) {
101
- console.error("[ArticleExtractPanel] Error extracting URL:", e), _.error("Failed to load article");
102
- } finally {
103
- N(!1), G(!0);
104
- }
105
- }, Xe = async () => {
106
- try {
107
- let { data: e } = await ue(), t = e?.favorites?.some((e) => e.url === T);
108
- B(!!t);
109
- } catch (e) {
110
- console.error("Error checking favorite status:", e);
111
- }
112
- }, Ze = async () => {
113
- if (E) {
114
- Me(!0);
115
- try {
116
- z ? (await de({ query: { url: T } }), B(!1), _.info("Removed from favorites")) : (await se({ body: {
117
- url: E.url || T,
118
- title: E.title,
119
- cite: E.cite,
120
- author: E.author,
121
- author_cite: E.author_cite,
122
- date: E.date,
123
- source: E.source,
124
- word_count: E.word_count,
125
- html: E.html
126
- } }), B(!0), _.success("Added to favorites"));
127
- } catch (e) {
128
- console.error("Error toggling favorite:", e), _.error("Failed to toggle favorite");
129
- } finally {
130
- Me(!1);
131
- }
132
- }
133
- }, Qe = () => {
134
- if (S?.key && S?.providerId) return S;
135
- try {
136
- let e = localStorage.getItem("chatModelKey") || "", t = localStorage.getItem("chatModelProviderId") || "";
137
- if (e && t) return {
138
- key: e,
139
- providerId: t
140
- };
141
- } catch (e) {
142
- console.error("Error reading persisted chat model:", e);
143
- }
144
- return S;
145
- }, $ = async (e, { source: t = E, question: n = j } = {}) => {
146
- if (!t) return;
147
- let r = Qe(), i = t.html?.replace(/<[^>]*>?/g, "").slice(0, u.maxArticleLength), a = e === "question", o = a ? we : Te, s = a ? De : Ae;
148
- o(!0), s("");
149
- try {
150
- if (a) {
151
- let e = [ye, n].filter(Boolean).join("\n");
152
- if (!i || i.length === 0) throw Error("Article content is empty");
153
- let { data: t, error: a } = await le({ body: {
154
- article: i,
155
- question: e,
156
- chatHistory: O.slice(-5),
157
- chatModel: r
158
- } });
159
- if (a) {
160
- let e = a.details || a.error || a.message || "Article QA failed";
161
- throw Error(e);
162
- }
163
- let o = t?.content || "";
164
- Ee(o), be((e) => [
165
- ...e,
166
- {
167
- role: "user",
168
- content: n,
169
- time: (/* @__PURE__ */ new Date()).toISOString()
170
- },
171
- {
172
- role: "assistant",
173
- content: o,
174
- time: (/* @__PURE__ */ new Date()).toISOString()
175
- }
176
- ]);
177
- try {
178
- await y({ body: {
179
- url: T,
180
- question: n,
181
- answer: o
182
- } });
183
- } catch (e) {
184
- console.error("Error storing Q&A in cache:", e);
185
- }
186
- } else {
187
- let e = parseInt(localStorage.getItem("maxFollowupQuestions") || "4");
188
- if (!i || i.length === 0) throw Error("Article content is empty");
189
- let { data: t, error: n } = await ce({ body: {
190
- article: i,
191
- chatHistory: O.slice(-5),
192
- maxQuestions: e,
193
- chatModel: r
194
- } });
195
- if (n) {
196
- let e = n.details || n.error || n.message || "Article followups failed";
197
- throw Error(e);
198
- }
199
- let a = t?.extract || [];
200
- R(a);
201
- try {
202
- await y({ body: {
203
- url: T,
204
- followUpQuestions: a
205
- } });
206
- } catch (e) {
207
- console.error("Error storing follow-up questions in cache:", e);
208
- }
209
- }
210
- } catch (e) {
211
- 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");
212
- } finally {
213
- o(!1);
214
- }
215
- }, $e = (e) => {
216
- M(e), $("question", { question: e });
217
- }, et = async () => {
218
- if (!E) return;
219
- let e = `${I}\n\n\n${E.cite || ""}\n\n\n${E.html}`;
220
- try {
221
- await navigator.clipboard.writeText(e), k(!0), setTimeout(() => k(!1), 2e3);
222
- } catch (e) {
223
- console.error("Failed to copy to clipboard:", e);
224
- }
225
- }, tt = async () => {
226
- let e = E?.url || T;
227
- if (e) try {
228
- await pe({
229
- title: E?.title,
230
- text: E?.cite,
231
- url: e
232
- }, {
233
- share: typeof navigator < "u" && navigator.share ? (e) => navigator.share(e) : void 0,
234
- writeText: (e) => navigator.clipboard.writeText(e)
235
- }) === "copied" && (A(!0), setTimeout(() => A(!1), 2e3));
236
- } catch (e) {
237
- console.error("Failed to share article:", e);
238
- }
239
- };
240
- Z.current = {
241
- ask: () => $("question"),
242
- suggest: () => $("suggest-followups"),
243
- copy: et,
244
- highlight: () => H((e) => !e),
245
- favorite: Ze,
246
- open: () => {
247
- let e = E?.url || T;
248
- e && window.open(e, "_blank", "noopener,noreferrer");
249
- },
250
- zoomIn: Ke,
251
- zoomOut: qe,
252
- zoomReset: Je,
253
- close: w
254
- }, f(() => {
255
- if (!C) return;
256
- let e = (e) => /^[a-z]$/.test(e) ? `Key${e.toUpperCase()}` : /^[0-9]$/.test(e) ? `Digit${e}` : e === "-" ? "Minus" : e === "=" ? "Equal" : e, t = {};
257
- Object.keys(l).forEach((n) => {
258
- let { alt: r, key: i } = l[n];
259
- r && (t[e(i.toLowerCase())] = n);
260
- });
261
- let n = (e) => {
262
- if (e.key === "Escape") {
263
- Z.current.close?.();
264
- return;
265
- }
266
- if (!e.altKey || e.ctrlKey || e.metaKey) return;
267
- let n = e.target;
268
- if (n && (n.tagName === "INPUT" || n.tagName === "TEXTAREA" || n.isContentEditable)) return;
269
- let r = t[e.code];
270
- if (!r) return;
271
- let i = Z.current[r];
272
- i && (e.preventDefault(), i());
273
- };
274
- return window.addEventListener("keydown", n), () => window.removeEventListener("keydown", n);
275
- }, [C]);
276
- let nt = () => /* @__PURE__ */ g("div", {
277
- className: "flex h-full flex-col bg-background shadow-xl",
278
- children: [
279
- /* @__PURE__ */ h("div", {
280
- className: "shrink-0 border-b border-border bg-background/95 px-4 py-3 backdrop-blur supports-[backdrop-filter]:bg-background/80",
281
- children: /* @__PURE__ */ h(ee, {
282
- isLoadingAI: P,
283
- isLoadingFollowups: F,
284
- isLoadingFavorite: je,
285
- isFavorited: z,
286
- isHighlightMode: V,
287
- articleUrl: E?.url || T,
288
- fontScale: K,
289
- onAskClick: () => $("question"),
290
- onSuggestClick: () => $("suggest-followups"),
291
- onCopyClick: et,
292
- onShareClick: tt,
293
- onFavoriteClick: Ze,
294
- onHighlightToggle: () => H(!V),
295
- onZoomIn: Ke,
296
- onZoomOut: qe,
297
- onZoomReset: Je,
298
- onClose: w
299
- })
300
- }),
301
- /* @__PURE__ */ h("div", {
302
- className: "shrink-0 px-4 pt-2",
303
- children: /* @__PURE__ */ h(ne, {
304
- value: J,
305
- onValueChange: Ge,
306
- idBase: Y
307
- })
308
- }),
309
- /* @__PURE__ */ h("div", {
310
- role: "tabpanel",
311
- id: c(Y, "outline").panel,
312
- "aria-labelledby": c(Y, "outline").tab,
313
- hidden: J !== "outline",
314
- className: "flex max-h-[40%] min-h-0 shrink-0 flex-col border-b border-border px-4",
315
- children: J === "outline" && /* @__PURE__ */ h(ae, { items: ze })
316
- }),
317
- /* @__PURE__ */ h("div", {
318
- ref: X,
319
- className: "flex-1 overflow-y-auto",
320
- children: /* @__PURE__ */ g("div", {
321
- className: "p-4 space-y-6",
322
- children: [/* @__PURE__ */ g("div", {
323
- className: "space-y-4",
324
- children: [
325
- xe && /* @__PURE__ */ h("div", {
326
- className: "bg-blue-500 text-white text-sm font-medium px-3 py-2 rounded-md shadow-lg",
327
- children: "Copied!"
328
- }),
329
- Se && /* @__PURE__ */ h("div", {
330
- className: "bg-blue-500 text-white text-sm font-medium px-3 py-2 rounded-md shadow-lg",
331
- children: "Link copied!"
332
- }),
333
- /* @__PURE__ */ g("div", {
334
- role: "tabpanel",
335
- id: c(Y, "questions").panel,
336
- "aria-labelledby": c(Y, "questions").tab,
337
- hidden: J !== "questions",
338
- className: "space-y-4",
339
- children: [/* @__PURE__ */ h(s, {
340
- value: j,
341
- onChange: M,
342
- onSubmit: () => $("question")
343
- }), /* @__PURE__ */ h(ie, {
344
- questions: Oe,
345
- isLoading: F,
346
- error: ke,
347
- onQuestionClick: $e
348
- })]
349
- }),
350
- O.length > 0 && /* @__PURE__ */ h("div", {
351
- className: "space-y-4",
352
- children: O.map((e, t) => /* @__PURE__ */ h("div", {
353
- className: "space-y-2",
354
- children: e.role === "user" ? /* @__PURE__ */ g("div", {
355
- className: "bg-primary/10 border border-primary/20 rounded-lg p-3",
356
- children: [/* @__PURE__ */ h("div", {
357
- className: "text-xs font-semibold text-primary mb-1",
358
- children: "Your Question"
359
- }), /* @__PURE__ */ h("div", {
360
- className: "text-sm text-foreground",
361
- children: e.content
362
- })]
363
- }) : /* @__PURE__ */ g("div", {
364
- className: "bg-muted rounded-lg shadow-md p-4",
365
- children: [/* @__PURE__ */ h("div", {
366
- className: "text-xs font-semibold text-muted-foreground mb-2",
367
- children: "AI Response"
368
- }), /* @__PURE__ */ h("div", {
369
- className: "text-sm",
370
- dangerouslySetInnerHTML: { __html: e.content }
371
- })]
372
- })
373
- }, t))
374
- }),
375
- (P || I && O.length === 0) && /* @__PURE__ */ h(te, {
376
- response: I,
377
- isLoading: P,
378
- error: L
379
- }),
380
- L && !P && /* @__PURE__ */ h("div", {
381
- className: "bg-red-500 text-white p-2 rounded-md text-sm",
382
- children: L
383
- })
384
- ]
385
- }), E && /* @__PURE__ */ h(re, {
386
- article: E,
387
- isHighlightMode: V,
388
- fontScale: K,
389
- onOutlineChange: Be
390
- })]
391
- })
392
- })
393
- ]
394
- });
395
- return !C || !Le ? null : Ne ? /* @__PURE__ */ g("div", {
396
- className: "fixed top-0 right-0 h-screen z-40 transition-all duration-300",
397
- style: { width: `${Fe}px` },
398
- children: [/* @__PURE__ */ h("div", {
399
- ref: Ve,
400
- onMouseDown: () => W(!0),
401
- className: "absolute left-0 top-0 bottom-0 w-1 cursor-ew-resize hover:bg-primary bg-transparent transition-colors z-50",
402
- style: { touchAction: "none" },
403
- children: /* @__PURE__ */ h("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" })
404
- }), nt()]
405
- }) : /* @__PURE__ */ h(r, {
406
- open: C,
407
- onOpenChange: (e) => !e && w(),
408
- children: /* @__PURE__ */ g(t, {
409
- 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",
410
- hideCloseButton: !0,
411
- children: [/* @__PURE__ */ h(b, { children: /* @__PURE__ */ h(e, { children: "Article Details" }) }), /* @__PURE__ */ h("div", {
412
- className: "h-full overflow-y-auto",
413
- children: nt()
414
- })]
415
- })
416
- });
417
- };
418
- export { me as default };
@@ -1,7 +0,0 @@
1
- import React from 'react';
2
- import type { ArticleOutlineItem } from './articleOutline';
3
- interface ArticleOutlineProps {
4
- items: ArticleOutlineItem[];
5
- }
6
- declare const ArticleOutline: React.FC<ArticleOutlineProps>;
7
- export default ArticleOutline;
@@ -1,15 +0,0 @@
1
- import React from 'react';
2
- export type ArticleSidebarTab = 'questions' | 'outline';
3
- /** Ids that tie a tab to its panel (`aria-controls` / `aria-labelledby`). */
4
- export declare function articleTabIds(idBase: string, tab: ArticleSidebarTab): {
5
- tab: string;
6
- panel: string;
7
- };
8
- interface ArticleSidebarTabsProps {
9
- value: ArticleSidebarTab;
10
- onValueChange: (tab: ArticleSidebarTab) => void;
11
- /** Unique per panel instance; feeds {@link articleTabIds}. */
12
- idBase: string;
13
- }
14
- declare const ArticleSidebarTabs: React.FC<ArticleSidebarTabsProps>;
15
- export default ArticleSidebarTabs;
@@ -1,29 +0,0 @@
1
- /**
2
- * @fileoverview Reads the outline (H1–H3 headings) out of an article's HTML and
3
- * gives every heading an `id`, so the outline can link to it and a scroll-spy
4
- * can find it. Shape-compatible with Fumadocs' `TOCItemType`, which is what
5
- * the outline renders.
6
- */
7
- /** One heading in the outline. Same shape as Fumadocs' `TOCItemType`. */
8
- export interface ArticleOutlineItem {
9
- title: string;
10
- /** `#id` of the heading element. */
11
- url: string;
12
- /** 1 for H1, 2 for H2, 3 for H3. */
13
- depth: number;
14
- }
15
- /** Heading levels the outline lists. */
16
- export declare const OUTLINE_HEADING_SELECTOR = "h1, h2, h3";
17
- /**
18
- * Finds every H1, H2 and H3 with text in `html`, in document order.
19
- *
20
- * A heading keeps its own `id` when it has a plain one that no earlier heading
21
- * uses (footnote and in-page links may point at it); otherwise it gets
22
- * `outline-<n>-<slug>`. The returned `html` is `html` with those ids applied —
23
- * render that, so the outline's links resolve. Without headings, or outside a
24
- * browser (no `DOMParser`), `html` comes back untouched with no items.
25
- */
26
- export declare function extractOutline(html: string): {
27
- html: string;
28
- items: ArticleOutlineItem[];
29
- };