@retrivora-ai/rag-engine 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/DocumentChunker-Dh9TvmGG.d.mts +45 -0
- package/dist/DocumentChunker-Dh9TvmGG.d.ts +45 -0
- package/dist/{RagConfig-DRJO4hGU.d.mts → RagConfig-BjC6zSTV.d.mts} +62 -1
- package/dist/{RagConfig-DRJO4hGU.d.ts → RagConfig-BjC6zSTV.d.ts} +62 -1
- package/dist/{chunk-6MLZHQZT.mjs → chunk-ZCDJSGUW.mjs} +237 -104
- package/dist/handlers/index.d.mts +2 -2
- package/dist/handlers/index.d.ts +2 -2
- package/dist/handlers/index.js +239 -106
- package/dist/handlers/index.mjs +11 -3
- package/dist/index-C3bLmWcR.d.ts +206 -0
- package/dist/index-CU_fQq__.d.mts +206 -0
- package/dist/index.d.mts +3 -4
- package/dist/index.d.ts +3 -4
- package/dist/index.js +103 -89
- package/dist/index.mjs +91 -95
- package/dist/server.d.mts +45 -97
- package/dist/server.d.ts +45 -97
- package/dist/server.js +319 -221
- package/dist/server.mjs +78 -167
- package/package.json +12 -10
- package/src/components/ChatWindow.tsx +2 -2
- package/src/components/ConfigProvider.tsx +2 -2
- package/src/components/MessageBubble.tsx +2 -2
- package/src/components/SourceCard.tsx +1 -1
- package/src/components/ThemeToggle.tsx +1 -1
- package/src/config/ConfigBuilder.ts +86 -211
- package/src/config/RagConfig.ts +4 -0
- package/src/config/uiConstants.ts +23 -0
- package/src/core/ConfigResolver.ts +57 -29
- package/src/core/LangChainAgent.ts +73 -40
- package/src/core/Pipeline.ts +64 -8
- package/src/core/ProviderRegistry.ts +2 -2
- package/src/core/QueryProcessor.ts +45 -12
- package/src/handlers/index.ts +138 -49
- package/src/hooks/useRagChat.ts +71 -32
- package/src/server.ts +12 -2
- package/dist/DocumentChunker-C-sCZPhi.d.mts +0 -102
- package/dist/DocumentChunker-C-sCZPhi.d.ts +0 -102
- package/dist/index-B2mutkgp.d.ts +0 -116
- package/dist/index-Bjy0es5a.d.mts +0 -116
package/dist/index.js
CHANGED
|
@@ -59,13 +59,13 @@ __export(index_exports, {
|
|
|
59
59
|
module.exports = __toCommonJS(index_exports);
|
|
60
60
|
|
|
61
61
|
// src/components/ChatWidget.tsx
|
|
62
|
-
var import_react7 = __toESM(require("react"));
|
|
63
|
-
var import_lucide_react5 = require("lucide-react");
|
|
64
|
-
|
|
65
|
-
// src/components/ChatWindow.tsx
|
|
66
62
|
var import_react6 = __toESM(require("react"));
|
|
67
63
|
var import_lucide_react4 = require("lucide-react");
|
|
68
64
|
|
|
65
|
+
// src/components/ChatWindow.tsx
|
|
66
|
+
var import_react5 = __toESM(require("react"));
|
|
67
|
+
var import_lucide_react3 = require("lucide-react");
|
|
68
|
+
|
|
69
69
|
// src/components/MessageBubble.tsx
|
|
70
70
|
var import_react2 = __toESM(require("react"));
|
|
71
71
|
var import_lucide_react2 = require("lucide-react");
|
|
@@ -220,6 +220,22 @@ function useStoredMessages(storageKey, persist) {
|
|
|
220
220
|
}
|
|
221
221
|
|
|
222
222
|
// src/hooks/useRagChat.ts
|
|
223
|
+
function parseSseChunk(raw) {
|
|
224
|
+
const frames = [];
|
|
225
|
+
for (const block of raw.split("\n\n")) {
|
|
226
|
+
for (const line of block.split("\n")) {
|
|
227
|
+
if (!line.startsWith("data: ")) continue;
|
|
228
|
+
try {
|
|
229
|
+
const frame = JSON.parse(line.slice(6));
|
|
230
|
+
if (frame && typeof frame === "object" && "type" in frame) {
|
|
231
|
+
frames.push(frame);
|
|
232
|
+
}
|
|
233
|
+
} catch (e) {
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return frames;
|
|
238
|
+
}
|
|
223
239
|
function useRagChat(projectId, options = {}) {
|
|
224
240
|
const {
|
|
225
241
|
apiUrl = "/api/chat",
|
|
@@ -238,11 +254,12 @@ function useRagChat(projectId, options = {}) {
|
|
|
238
254
|
messagesRef.current = messages;
|
|
239
255
|
}, [messages]);
|
|
240
256
|
const sendMessage = (0, import_react4.useCallback)(
|
|
241
|
-
async (text,
|
|
257
|
+
async (text, opts) => {
|
|
258
|
+
var _a, _b;
|
|
242
259
|
const trimmed = text.trim();
|
|
243
260
|
if (!trimmed || isLoading) return;
|
|
244
261
|
lastInputRef.current = trimmed;
|
|
245
|
-
if (!(
|
|
262
|
+
if (!(opts == null ? void 0 : opts.skipUserMessage)) {
|
|
246
263
|
const userMessage = {
|
|
247
264
|
id: `user_${Date.now()}`,
|
|
248
265
|
role: "user",
|
|
@@ -275,6 +292,7 @@ function useRagChat(projectId, options = {}) {
|
|
|
275
292
|
const decoder = new TextDecoder();
|
|
276
293
|
let assistantContent = "";
|
|
277
294
|
let sources = [];
|
|
295
|
+
let buffer = "";
|
|
278
296
|
const assistantMessageId = `assistant_${Date.now()}`;
|
|
279
297
|
setMessages((prev) => [
|
|
280
298
|
...prev,
|
|
@@ -288,27 +306,19 @@ function useRagChat(projectId, options = {}) {
|
|
|
288
306
|
while (true) {
|
|
289
307
|
const { done, value } = await reader.read();
|
|
290
308
|
if (done) break;
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
309
|
+
buffer += decoder.decode(value, { stream: true });
|
|
310
|
+
const lastBoundary = buffer.lastIndexOf("\n\n");
|
|
311
|
+
if (lastBoundary === -1) continue;
|
|
312
|
+
const complete = buffer.slice(0, lastBoundary + 2);
|
|
313
|
+
buffer = buffer.slice(lastBoundary + 2);
|
|
314
|
+
for (const frame of parseSseChunk(complete)) {
|
|
315
|
+
if (frame.type === "text") {
|
|
316
|
+
assistantContent += frame.text;
|
|
317
|
+
} else if (frame.type === "metadata") {
|
|
318
|
+
sources = (_a = frame.sources) != null ? _a : [];
|
|
319
|
+
} else if (frame.type === "error") {
|
|
320
|
+
setError(frame.error || "Stream error");
|
|
300
321
|
}
|
|
301
|
-
} else if (chunk.includes("__ERROR__")) {
|
|
302
|
-
const [text2, errorStr] = chunk.split("__ERROR__");
|
|
303
|
-
if (text2) assistantContent += text2;
|
|
304
|
-
try {
|
|
305
|
-
const err = JSON.parse(errorStr);
|
|
306
|
-
setError(err.error || "Stream error");
|
|
307
|
-
} catch (e) {
|
|
308
|
-
setError("An error occurred during streaming");
|
|
309
|
-
}
|
|
310
|
-
} else {
|
|
311
|
-
assistantContent += chunk;
|
|
312
322
|
}
|
|
313
323
|
setMessages(
|
|
314
324
|
(prev) => prev.map(
|
|
@@ -316,6 +326,12 @@ function useRagChat(projectId, options = {}) {
|
|
|
316
326
|
)
|
|
317
327
|
);
|
|
318
328
|
}
|
|
329
|
+
if (buffer.trim()) {
|
|
330
|
+
for (const frame of parseSseChunk(buffer)) {
|
|
331
|
+
if (frame.type === "text") assistantContent += frame.text;
|
|
332
|
+
else if (frame.type === "metadata") sources = (_b = frame.sources) != null ? _b : [];
|
|
333
|
+
}
|
|
334
|
+
}
|
|
319
335
|
const finalAssistantMessage = {
|
|
320
336
|
id: assistantMessageId,
|
|
321
337
|
role: "assistant",
|
|
@@ -358,14 +374,7 @@ function useRagChat(projectId, options = {}) {
|
|
|
358
374
|
};
|
|
359
375
|
}
|
|
360
376
|
|
|
361
|
-
// src/
|
|
362
|
-
var import_react5 = __toESM(require("react"));
|
|
363
|
-
var import_lucide_react3 = require("lucide-react");
|
|
364
|
-
var CHAT_SUGGESTIONS = [
|
|
365
|
-
"What can you help me with?",
|
|
366
|
-
"Summarise the key topics",
|
|
367
|
-
"Show me an example"
|
|
368
|
-
];
|
|
377
|
+
// src/config/uiConstants.ts
|
|
369
378
|
var BORDER_RADIUS_MAP = {
|
|
370
379
|
none: "rounded-none",
|
|
371
380
|
sm: "rounded-sm",
|
|
@@ -374,28 +383,33 @@ var BORDER_RADIUS_MAP = {
|
|
|
374
383
|
xl: "rounded-xl",
|
|
375
384
|
full: "rounded-3xl"
|
|
376
385
|
};
|
|
386
|
+
var CHAT_SUGGESTIONS = [
|
|
387
|
+
"What can you help me with?",
|
|
388
|
+
"Summarise the key topics",
|
|
389
|
+
"Show me an example"
|
|
390
|
+
];
|
|
377
391
|
|
|
378
392
|
// src/components/ChatWindow.tsx
|
|
379
393
|
function ChatWindow({ className = "", style, onClose, showClose = false }) {
|
|
380
394
|
var _a;
|
|
381
395
|
const { ui, projectId } = useConfig();
|
|
382
|
-
const [input, setInput] = (0,
|
|
383
|
-
const [mounted, setMounted] = (0,
|
|
384
|
-
const bottomRef = (0,
|
|
385
|
-
const inputRef = (0,
|
|
396
|
+
const [input, setInput] = (0, import_react5.useState)("");
|
|
397
|
+
const [mounted, setMounted] = (0, import_react5.useState)(false);
|
|
398
|
+
const bottomRef = (0, import_react5.useRef)(null);
|
|
399
|
+
const inputRef = (0, import_react5.useRef)(null);
|
|
386
400
|
const { messages, send, clear, isLoading, error } = useRagChat(projectId, {
|
|
387
401
|
namespace: projectId
|
|
388
402
|
});
|
|
389
|
-
(0,
|
|
403
|
+
(0, import_react5.useEffect)(() => {
|
|
390
404
|
setMounted(true);
|
|
391
405
|
}, []);
|
|
392
|
-
(0,
|
|
406
|
+
(0, import_react5.useEffect)(() => {
|
|
393
407
|
var _a2;
|
|
394
408
|
if (messages.length > 0 || isLoading) {
|
|
395
409
|
(_a2 = bottomRef.current) == null ? void 0 : _a2.scrollIntoView({ behavior: "smooth" });
|
|
396
410
|
}
|
|
397
411
|
}, [messages, isLoading]);
|
|
398
|
-
const sendMessage = (0,
|
|
412
|
+
const sendMessage = (0, import_react5.useCallback)(async () => {
|
|
399
413
|
const text = input.trim();
|
|
400
414
|
if (!text || isLoading) return;
|
|
401
415
|
setInput("");
|
|
@@ -417,58 +431,58 @@ function ChatWindow({ className = "", style, onClose, showClose = false }) {
|
|
|
417
431
|
const isEmpty = messages.length === 0;
|
|
418
432
|
const currentRadius = BORDER_RADIUS_MAP[ui.borderRadius || "xl"];
|
|
419
433
|
const isGlass = ui.visualStyle !== "solid";
|
|
420
|
-
return /* @__PURE__ */
|
|
434
|
+
return /* @__PURE__ */ import_react5.default.createElement(
|
|
421
435
|
"div",
|
|
422
436
|
{
|
|
423
437
|
className: `flex flex-col border border-slate-200 dark:border-white/10 shadow-2xl transition-all duration-300 ${currentRadius} ${isGlass ? "bg-white/90 dark:bg-[#0f0f1a]/90 backdrop-blur-xl" : "bg-white dark:bg-[#0f0f1a]"} ${className}`,
|
|
424
438
|
style: __spreadValues({ "--primary": ui.primaryColor, "--accent": ui.accentColor }, style)
|
|
425
439
|
},
|
|
426
|
-
/* @__PURE__ */
|
|
440
|
+
/* @__PURE__ */ import_react5.default.createElement(
|
|
427
441
|
"div",
|
|
428
442
|
{
|
|
429
443
|
className: "flex items-center justify-between px-5 py-4 border-b border-slate-200 dark:border-white/10",
|
|
430
444
|
style: { background: `linear-gradient(135deg, ${ui.primaryColor}15, ${ui.accentColor}10)` }
|
|
431
445
|
},
|
|
432
|
-
/* @__PURE__ */
|
|
446
|
+
/* @__PURE__ */ import_react5.default.createElement("div", { className: "flex items-center gap-3" }, ui.logoUrl ? (
|
|
433
447
|
// eslint-disable-next-line @next/next/no-img-element
|
|
434
|
-
/* @__PURE__ */
|
|
435
|
-
) : /* @__PURE__ */
|
|
448
|
+
/* @__PURE__ */ import_react5.default.createElement("img", { src: ui.logoUrl, alt: "logo", className: "w-8 h-8 rounded-lg object-cover" })
|
|
449
|
+
) : /* @__PURE__ */ import_react5.default.createElement(
|
|
436
450
|
"div",
|
|
437
451
|
{
|
|
438
452
|
className: `w-9 h-9 flex items-center justify-center shadow-md ${ui.borderRadius === "full" ? "rounded-full" : "rounded-xl"}`,
|
|
439
453
|
style: { background: `linear-gradient(135deg, ${ui.primaryColor}, ${ui.accentColor})` }
|
|
440
454
|
},
|
|
441
|
-
/* @__PURE__ */
|
|
442
|
-
), /* @__PURE__ */
|
|
443
|
-
/* @__PURE__ */
|
|
455
|
+
/* @__PURE__ */ import_react5.default.createElement(import_lucide_react3.Bot, { className: "w-5 h-5 text-white" })
|
|
456
|
+
), /* @__PURE__ */ import_react5.default.createElement("div", null, /* @__PURE__ */ import_react5.default.createElement("h2", { className: "text-slate-900 dark:text-white font-semibold text-sm leading-tight" }, ui.title), ui.poweredBy && /* @__PURE__ */ import_react5.default.createElement("p", { className: "text-slate-500 dark:text-white/40 text-[11px] leading-tight" }, `Powered by ${ui.poweredBy}`))),
|
|
457
|
+
/* @__PURE__ */ import_react5.default.createElement("div", { className: "flex items-center gap-2" }, /* @__PURE__ */ import_react5.default.createElement("span", { className: "flex items-center gap-1 text-[10px] text-emerald-500 dark:text-emerald-400" }, /* @__PURE__ */ import_react5.default.createElement("span", { className: "w-1.5 h-1.5 rounded-full bg-emerald-500 dark:bg-emerald-400 animate-pulse" }), "Online"), mounted && messages.length > 0 && /* @__PURE__ */ import_react5.default.createElement(
|
|
444
458
|
"button",
|
|
445
459
|
{
|
|
446
460
|
onClick: clearHistory,
|
|
447
461
|
title: "Clear conversation",
|
|
448
462
|
className: "w-7 h-7 rounded-lg flex items-center justify-center text-slate-400 hover:text-slate-600 dark:text-white/40 dark:hover:text-white/70 hover:bg-slate-100 dark:hover:bg-white/10 transition-all cursor-pointer"
|
|
449
463
|
},
|
|
450
|
-
/* @__PURE__ */
|
|
451
|
-
), showClose && onClose && /* @__PURE__ */
|
|
464
|
+
/* @__PURE__ */ import_react5.default.createElement(import_lucide_react3.Trash2, { className: "w-3.5 h-3.5" })
|
|
465
|
+
), showClose && onClose && /* @__PURE__ */ import_react5.default.createElement(
|
|
452
466
|
"button",
|
|
453
467
|
{
|
|
454
468
|
onClick: onClose,
|
|
455
469
|
title: "Close chat",
|
|
456
470
|
className: "w-7 h-7 rounded-lg flex items-center justify-center text-slate-400 hover:text-slate-600 dark:text-white/40 dark:hover:text-white/70 hover:bg-slate-100 dark:hover:bg-white/10 transition-all cursor-pointer"
|
|
457
471
|
},
|
|
458
|
-
/* @__PURE__ */
|
|
472
|
+
/* @__PURE__ */ import_react5.default.createElement(import_lucide_react3.X, { className: "w-4 h-4" })
|
|
459
473
|
))
|
|
460
474
|
),
|
|
461
|
-
/* @__PURE__ */
|
|
475
|
+
/* @__PURE__ */ import_react5.default.createElement("div", { className: "flex-1 overflow-y-auto px-4 py-4 space-y-5 scrollbar-thin scrollbar-thumb-slate-200 dark:scrollbar-thumb-white/10 scrollbar-track-transparent min-h-0 bg-slate-50 dark:bg-transparent" }, !mounted || isEmpty ? (
|
|
462
476
|
/* Welcome state */
|
|
463
|
-
/* @__PURE__ */
|
|
477
|
+
/* @__PURE__ */ import_react5.default.createElement("div", { className: "h-full flex flex-col items-center justify-center text-center gap-4 px-6 py-12" }, /* @__PURE__ */ import_react5.default.createElement(
|
|
464
478
|
"div",
|
|
465
479
|
{
|
|
466
480
|
className: `w-16 h-16 flex items-center justify-center shadow-lg ${ui.borderRadius === "full" ? "rounded-full" : "rounded-2xl"}`,
|
|
467
481
|
style: { background: `linear-gradient(135deg, ${ui.primaryColor}, ${ui.accentColor})` }
|
|
468
482
|
},
|
|
469
|
-
/* @__PURE__ */
|
|
470
|
-
), /* @__PURE__ */
|
|
471
|
-
(suggestion) => /* @__PURE__ */
|
|
483
|
+
/* @__PURE__ */ import_react5.default.createElement(import_lucide_react3.Sparkles, { className: "w-8 h-8 text-white" })
|
|
484
|
+
), /* @__PURE__ */ import_react5.default.createElement("div", null, /* @__PURE__ */ import_react5.default.createElement("p", { className: "text-slate-800 dark:text-white/80 font-medium leading-relaxed" }, ui.welcomeMessage), /* @__PURE__ */ import_react5.default.createElement("p", { className: "text-slate-500 dark:text-white/30 text-sm mt-2" }, "Ask a question to get started")), /* @__PURE__ */ import_react5.default.createElement("div", { className: "flex flex-wrap gap-2 justify-center mt-2" }, CHAT_SUGGESTIONS.map(
|
|
485
|
+
(suggestion) => /* @__PURE__ */ import_react5.default.createElement(
|
|
472
486
|
"button",
|
|
473
487
|
{
|
|
474
488
|
key: suggestion,
|
|
@@ -482,7 +496,7 @@ function ChatWindow({ className = "", style, onClose, showClose = false }) {
|
|
|
482
496
|
suggestion
|
|
483
497
|
)
|
|
484
498
|
)))
|
|
485
|
-
) : messages.map((msg, index) => /* @__PURE__ */
|
|
499
|
+
) : messages.map((msg, index) => /* @__PURE__ */ import_react5.default.createElement(
|
|
486
500
|
MessageBubble,
|
|
487
501
|
{
|
|
488
502
|
key: msg.id,
|
|
@@ -492,7 +506,7 @@ function ChatWindow({ className = "", style, onClose, showClose = false }) {
|
|
|
492
506
|
primaryColor: ui.primaryColor,
|
|
493
507
|
accentColor: ui.accentColor
|
|
494
508
|
}
|
|
495
|
-
)), isLoading && ((_a = messages[messages.length - 1]) == null ? void 0 : _a.role) !== "assistant" && /* @__PURE__ */
|
|
509
|
+
)), isLoading && ((_a = messages[messages.length - 1]) == null ? void 0 : _a.role) !== "assistant" && /* @__PURE__ */ import_react5.default.createElement(
|
|
496
510
|
MessageBubble,
|
|
497
511
|
{
|
|
498
512
|
message: { role: "assistant", content: "" },
|
|
@@ -500,8 +514,8 @@ function ChatWindow({ className = "", style, onClose, showClose = false }) {
|
|
|
500
514
|
primaryColor: ui.primaryColor,
|
|
501
515
|
accentColor: ui.accentColor
|
|
502
516
|
}
|
|
503
|
-
), error && /* @__PURE__ */
|
|
504
|
-
/* @__PURE__ */
|
|
517
|
+
), error && /* @__PURE__ */ import_react5.default.createElement("div", { className: "flex items-center gap-2 text-rose-500 dark:text-rose-400 text-sm bg-rose-50 dark:bg-rose-400/10 border border-rose-200 dark:border-rose-400/20 rounded-xl px-4 py-3" }, /* @__PURE__ */ import_react5.default.createElement(import_lucide_react3.TriangleAlert, { className: "w-4 h-4 flex-shrink-0" }), /* @__PURE__ */ import_react5.default.createElement("span", null, error)), /* @__PURE__ */ import_react5.default.createElement("div", { ref: bottomRef })),
|
|
518
|
+
/* @__PURE__ */ import_react5.default.createElement("div", { className: `px-4 pb-4 pt-2 border-t border-slate-200 dark:border-white/10 ${isGlass ? "bg-transparent" : "bg-white dark:bg-[#0f0f1a]"}` }, /* @__PURE__ */ import_react5.default.createElement("div", { className: `flex items-end gap-2 bg-slate-50 dark:bg-white/5 border border-slate-200 dark:border-white/10 p-2 focus-within:border-slate-300 dark:focus-within:border-white/20 transition-all ${ui.borderRadius === "full" ? "rounded-3xl" : "rounded-2xl"}` }, /* @__PURE__ */ import_react5.default.createElement(
|
|
505
519
|
"textarea",
|
|
506
520
|
{
|
|
507
521
|
ref: inputRef,
|
|
@@ -514,7 +528,7 @@ function ChatWindow({ className = "", style, onClose, showClose = false }) {
|
|
|
514
528
|
className: "flex-1 bg-transparent text-slate-900 dark:text-white/90 placeholder-slate-400 dark:placeholder-white/30 text-sm resize-none outline-none py-1.5 px-2 max-h-32 leading-relaxed disabled:opacity-50",
|
|
515
529
|
style: { scrollbarWidth: "none" }
|
|
516
530
|
}
|
|
517
|
-
), /* @__PURE__ */
|
|
531
|
+
), /* @__PURE__ */ import_react5.default.createElement(
|
|
518
532
|
"button",
|
|
519
533
|
{
|
|
520
534
|
onClick: sendMessage,
|
|
@@ -525,16 +539,16 @@ function ChatWindow({ className = "", style, onClose, showClose = false }) {
|
|
|
525
539
|
// slate-400/20 for light mode disabled
|
|
526
540
|
}
|
|
527
541
|
},
|
|
528
|
-
/* @__PURE__ */
|
|
529
|
-
)), /* @__PURE__ */
|
|
542
|
+
/* @__PURE__ */ import_react5.default.createElement(import_lucide_react3.ArrowUp, { className: "w-4 h-4 text-white" })
|
|
543
|
+
)), /* @__PURE__ */ import_react5.default.createElement("p", { className: "text-center text-[10px] text-slate-400 dark:text-white/20 mt-2" }, "Press Enter to send \xB7 Shift+Enter for new line"))
|
|
530
544
|
);
|
|
531
545
|
}
|
|
532
546
|
|
|
533
547
|
// src/components/ChatWidget.tsx
|
|
534
548
|
function ChatWidget({ position = "bottom-right" }) {
|
|
535
549
|
const { ui } = useConfig();
|
|
536
|
-
const [isOpen, setIsOpen] = (0,
|
|
537
|
-
const [hasUnread, setHasUnread] = (0,
|
|
550
|
+
const [isOpen, setIsOpen] = (0, import_react6.useState)(false);
|
|
551
|
+
const [hasUnread, setHasUnread] = (0, import_react6.useState)(false);
|
|
538
552
|
if (ui.showWidget === false) return null;
|
|
539
553
|
const positionClass = position === "bottom-left" ? "bottom-6 left-6" : "bottom-6 right-6";
|
|
540
554
|
const windowPositionClass = position === "bottom-left" ? "bottom-20 left-6" : "bottom-20 right-6";
|
|
@@ -543,13 +557,13 @@ function ChatWidget({ position = "bottom-right" }) {
|
|
|
543
557
|
setIsOpen(true);
|
|
544
558
|
setHasUnread(false);
|
|
545
559
|
};
|
|
546
|
-
return /* @__PURE__ */
|
|
560
|
+
return /* @__PURE__ */ import_react6.default.createElement(import_react6.default.Fragment, null, /* @__PURE__ */ import_react6.default.createElement(
|
|
547
561
|
"div",
|
|
548
562
|
{
|
|
549
563
|
className: `fixed z-[9998] w-[380px] max-w-[calc(100vw-3rem)] transition-all duration-300 ease-in-out ${windowPositionClass} ${isOpen ? "opacity-100 translate-y-0 pointer-events-auto" : "opacity-0 translate-y-4 pointer-events-none"}`,
|
|
550
564
|
style: { height: "600px", maxHeight: "calc(100vh - 6rem)" }
|
|
551
565
|
},
|
|
552
|
-
/* @__PURE__ */
|
|
566
|
+
/* @__PURE__ */ import_react6.default.createElement(
|
|
553
567
|
ChatWindow,
|
|
554
568
|
{
|
|
555
569
|
className: "h-full relative z-10",
|
|
@@ -557,13 +571,13 @@ function ChatWidget({ position = "bottom-right" }) {
|
|
|
557
571
|
onClose: () => setIsOpen(false)
|
|
558
572
|
}
|
|
559
573
|
),
|
|
560
|
-
/* @__PURE__ */
|
|
574
|
+
/* @__PURE__ */ import_react6.default.createElement(
|
|
561
575
|
"div",
|
|
562
576
|
{
|
|
563
577
|
className: `absolute -bottom-1.5 w-4 h-4 rotate-45 border-r border-b border-slate-200 dark:border-white/10 z-0 ${ui.visualStyle === "solid" ? "bg-white dark:bg-[#0f0f1a]" : "bg-white/90 dark:bg-[#0f0f1a]/90 backdrop-blur-xl"} ${position === "bottom-left" ? "left-5" : "right-5"}`
|
|
564
578
|
}
|
|
565
579
|
)
|
|
566
|
-
), /* @__PURE__ */
|
|
580
|
+
), /* @__PURE__ */ import_react6.default.createElement(
|
|
567
581
|
"button",
|
|
568
582
|
{
|
|
569
583
|
onClick: isOpen ? () => setIsOpen(false) : handleOpen,
|
|
@@ -571,32 +585,32 @@ function ChatWidget({ position = "bottom-right" }) {
|
|
|
571
585
|
style: { background: `linear-gradient(135deg, ${ui.primaryColor}, ${ui.accentColor})` },
|
|
572
586
|
"aria-label": "Open chat"
|
|
573
587
|
},
|
|
574
|
-
/* @__PURE__ */
|
|
588
|
+
/* @__PURE__ */ import_react6.default.createElement(
|
|
575
589
|
"span",
|
|
576
590
|
{
|
|
577
591
|
className: "absolute inset-0 rounded-full animate-ping opacity-20",
|
|
578
592
|
style: { background: ui.primaryColor }
|
|
579
593
|
}
|
|
580
594
|
),
|
|
581
|
-
/* @__PURE__ */
|
|
595
|
+
/* @__PURE__ */ import_react6.default.createElement(
|
|
582
596
|
"span",
|
|
583
597
|
{
|
|
584
598
|
className: `transition-transform duration-300 ${isOpen ? "rotate-90 scale-90" : "rotate-0 scale-100"}`
|
|
585
599
|
},
|
|
586
|
-
isOpen ? /* @__PURE__ */
|
|
600
|
+
isOpen ? /* @__PURE__ */ import_react6.default.createElement(import_lucide_react4.X, { className: "w-6 h-6 text-white" }) : /* @__PURE__ */ import_react6.default.createElement(import_lucide_react4.MessageSquare, { className: "w-6 h-6 text-white" })
|
|
587
601
|
),
|
|
588
|
-
hasUnread && !isOpen && /* @__PURE__ */
|
|
602
|
+
hasUnread && !isOpen && /* @__PURE__ */ import_react6.default.createElement("span", { className: "absolute top-0 right-0 w-4 h-4 bg-rose-500 rounded-full border-2 border-white flex items-center justify-center text-[9px] font-bold text-white" }, "1")
|
|
589
603
|
));
|
|
590
604
|
}
|
|
591
605
|
|
|
592
606
|
// src/components/DocumentUpload.tsx
|
|
593
|
-
var
|
|
594
|
-
var
|
|
607
|
+
var import_react7 = __toESM(require("react"));
|
|
608
|
+
var import_lucide_react5 = require("lucide-react");
|
|
595
609
|
function DocumentUpload({ namespace, onUploadComplete, className = "" }) {
|
|
596
610
|
const { ui } = useConfig();
|
|
597
|
-
const [fileStates, setFileStates] = (0,
|
|
598
|
-
const [isDragging, setIsDragging] = (0,
|
|
599
|
-
const fileInputRef = (0,
|
|
611
|
+
const [fileStates, setFileStates] = (0, import_react7.useState)([]);
|
|
612
|
+
const [isDragging, setIsDragging] = (0, import_react7.useState)(false);
|
|
613
|
+
const fileInputRef = (0, import_react7.useRef)(null);
|
|
600
614
|
const addFiles = (files) => {
|
|
601
615
|
const newStates = files.map((file) => ({ file, status: "idle" }));
|
|
602
616
|
setFileStates((prev) => [...prev, ...newStates]);
|
|
@@ -646,7 +660,7 @@ function DocumentUpload({ namespace, onUploadComplete, className = "" }) {
|
|
|
646
660
|
};
|
|
647
661
|
const isUploading = fileStates.some((s) => s.status === "uploading");
|
|
648
662
|
const hasIdle = fileStates.some((s) => s.status === "idle");
|
|
649
|
-
return /* @__PURE__ */
|
|
663
|
+
return /* @__PURE__ */ import_react7.default.createElement(
|
|
650
664
|
"div",
|
|
651
665
|
{
|
|
652
666
|
className: `p-6 border-2 border-dashed transition-all duration-300 rounded-2xl ${isDragging ? "border-emerald-500 bg-emerald-50/50 dark:bg-emerald-500/5" : "border-slate-200 dark:border-white/10 bg-white dark:bg-white/5"} ${className}`,
|
|
@@ -654,14 +668,14 @@ function DocumentUpload({ namespace, onUploadComplete, className = "" }) {
|
|
|
654
668
|
onDragLeave,
|
|
655
669
|
onDrop
|
|
656
670
|
},
|
|
657
|
-
/* @__PURE__ */
|
|
671
|
+
/* @__PURE__ */ import_react7.default.createElement("div", { className: "flex flex-col items-center justify-center text-center" }, /* @__PURE__ */ import_react7.default.createElement(
|
|
658
672
|
"div",
|
|
659
673
|
{
|
|
660
674
|
className: "w-12 h-12 rounded-full flex items-center justify-center mb-4 shadow-sm",
|
|
661
675
|
style: { background: `linear-gradient(135deg, ${ui.primaryColor}20, ${ui.accentColor}20)` }
|
|
662
676
|
},
|
|
663
|
-
/* @__PURE__ */
|
|
664
|
-
), /* @__PURE__ */
|
|
677
|
+
/* @__PURE__ */ import_react7.default.createElement(import_lucide_react5.Upload, { className: "w-6 h-6", style: { color: ui.primaryColor } })
|
|
678
|
+
), /* @__PURE__ */ import_react7.default.createElement("h3", { className: "text-slate-900 dark:text-white font-semibold mb-1" }, "Upload Documents"), /* @__PURE__ */ import_react7.default.createElement("p", { className: "text-slate-500 dark:text-white/40 text-sm mb-6 max-w-xs" }, "Drag and drop PDF, DOCX, TXT, or JSON files to train your AI on your own data."), /* @__PURE__ */ import_react7.default.createElement(
|
|
665
679
|
"button",
|
|
666
680
|
{
|
|
667
681
|
onClick: () => {
|
|
@@ -677,7 +691,7 @@ function DocumentUpload({ namespace, onUploadComplete, className = "" }) {
|
|
|
677
691
|
}
|
|
678
692
|
},
|
|
679
693
|
"Select Files"
|
|
680
|
-
), /* @__PURE__ */
|
|
694
|
+
), /* @__PURE__ */ import_react7.default.createElement(
|
|
681
695
|
"input",
|
|
682
696
|
{
|
|
683
697
|
ref: fileInputRef,
|
|
@@ -688,22 +702,22 @@ function DocumentUpload({ namespace, onUploadComplete, className = "" }) {
|
|
|
688
702
|
accept: ".pdf,.docx,.txt,.md,.json,.csv"
|
|
689
703
|
}
|
|
690
704
|
)),
|
|
691
|
-
fileStates.length > 0 && /* @__PURE__ */
|
|
705
|
+
fileStates.length > 0 && /* @__PURE__ */ import_react7.default.createElement("div", { className: "mt-8 space-y-3" }, fileStates.map((state, i) => /* @__PURE__ */ import_react7.default.createElement(
|
|
692
706
|
"div",
|
|
693
707
|
{
|
|
694
708
|
key: i,
|
|
695
709
|
className: "flex items-center justify-between p-3 rounded-xl bg-slate-50 dark:bg-white/5 border border-slate-100 dark:border-white/10"
|
|
696
710
|
},
|
|
697
|
-
/* @__PURE__ */
|
|
698
|
-
/* @__PURE__ */
|
|
711
|
+
/* @__PURE__ */ import_react7.default.createElement("div", { className: "flex items-center gap-3 overflow-hidden" }, /* @__PURE__ */ import_react7.default.createElement("div", { className: "w-8 h-8 rounded-lg bg-white dark:bg-white/10 flex items-center justify-center shadow-sm" }, /* @__PURE__ */ import_react7.default.createElement(import_lucide_react5.File, { className: "w-4 h-4 text-slate-400" })), /* @__PURE__ */ import_react7.default.createElement("div", { className: "truncate" }, /* @__PURE__ */ import_react7.default.createElement("p", { className: "text-xs font-medium text-slate-700 dark:text-white/80 truncate" }, state.file.name), /* @__PURE__ */ import_react7.default.createElement("p", { className: "text-[10px] text-slate-400" }, (state.file.size / 1024).toFixed(1), " KB"))),
|
|
712
|
+
/* @__PURE__ */ import_react7.default.createElement("div", { className: "flex items-center gap-2" }, state.status === "uploading" && /* @__PURE__ */ import_react7.default.createElement(import_lucide_react5.Loader2, { className: "w-4 h-4 text-slate-400 animate-spin" }), state.status === "success" && /* @__PURE__ */ import_react7.default.createElement(import_lucide_react5.CheckCircle, { className: "w-4 h-4 text-emerald-500" }), state.status === "error" && /* @__PURE__ */ import_react7.default.createElement("div", { title: state.error }, /* @__PURE__ */ import_react7.default.createElement(import_lucide_react5.AlertCircle, { className: "w-4 h-4 text-rose-500" })), state.status !== "uploading" && /* @__PURE__ */ import_react7.default.createElement(
|
|
699
713
|
"button",
|
|
700
714
|
{
|
|
701
715
|
onClick: () => removeFile(i),
|
|
702
716
|
className: "p-1 rounded-md hover:bg-slate-200 dark:hover:bg-white/10 transition-colors"
|
|
703
717
|
},
|
|
704
|
-
/* @__PURE__ */
|
|
718
|
+
/* @__PURE__ */ import_react7.default.createElement(import_lucide_react5.X, { className: "w-3.5 h-3.5 text-slate-400" })
|
|
705
719
|
))
|
|
706
|
-
)), hasIdle && !isUploading && /* @__PURE__ */
|
|
720
|
+
)), hasIdle && !isUploading && /* @__PURE__ */ import_react7.default.createElement(
|
|
707
721
|
"button",
|
|
708
722
|
{
|
|
709
723
|
onClick: uploadFiles,
|