@brainfish-ai/components 0.19.1 → 0.19.4
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/chat-search.d.ts +1 -0
- package/dist/esm/chunks/{ChatSearch.g9-_lvsz.js → ChatSearch.DOH90EUx.js} +8 -308
- package/dist/esm/chunks/ChatSearch.DOH90EUx.js.map +1 -0
- package/dist/esm/chunks/blue.CNWYlAkf.js +17 -0
- package/dist/esm/chunks/blue.CNWYlAkf.js.map +1 -0
- package/dist/esm/chunks/{generating-star.CozjECmM.js → generating-star.BMQgTqs7.js} +13 -5
- package/dist/esm/chunks/{generating-star.CozjECmM.js.map → generating-star.BMQgTqs7.js.map} +1 -1
- package/dist/esm/chunks/hooks.B9tkXVNJ.js +309 -0
- package/dist/esm/chunks/hooks.B9tkXVNJ.js.map +1 -0
- package/dist/esm/colors.js +1 -15
- package/dist/esm/colors.js.map +1 -1
- package/dist/esm/components/chat-search.js +1 -1
- package/dist/esm/components/convos.js +9 -6
- package/dist/esm/components/convos.js.map +1 -1
- package/dist/esm/components/generating-star.js +1 -1
- package/dist/esm/components/metric-card.js +3 -1
- package/dist/esm/components/metric-card.js.map +1 -1
- package/dist/esm/components/sidebar.js +380 -0
- package/dist/esm/components/sidebar.js.map +1 -0
- package/dist/esm/components/ui/accordion.js +1 -1
- package/dist/esm/components/ui/accordion.js.map +1 -1
- package/dist/esm/convos.css +1 -1
- package/dist/esm/global.css +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/tailwind.preset.js +3 -1
- package/dist/esm/tailwind.preset.js.map +1 -1
- package/dist/generating-star.d.ts +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/sidebar.d.ts +56 -0
- package/dist/stats.html +1 -1
- package/package.json +2 -1
- package/tailwind.config.js +6 -1
- package/tailwind.preset.ts +2 -0
- package/dist/esm/chunks/ChatSearch.g9-_lvsz.js.map +0 -1
package/dist/chat-search.d.ts
CHANGED
|
@@ -22,11 +22,12 @@ import { useSearchParam, useEffectOnce } from 'react-use';
|
|
|
22
22
|
import { MemoizedIcon } from '../components/ui/icon.js';
|
|
23
23
|
import { Collapsible, CollapsibleTrigger, CollapsibleContent } from '../components/ui/collapsible.js';
|
|
24
24
|
import { F as Feedback } from './feedback.D139-1Wr.js';
|
|
25
|
-
import { G as GeneratingStar } from './generating-star.
|
|
25
|
+
import { G as GeneratingStar } from './generating-star.BMQgTqs7.js';
|
|
26
26
|
import { getCountry } from 'countries-and-timezones';
|
|
27
27
|
import { Switch } from '../components/ui/switch.js';
|
|
28
28
|
import { C as Combobox } from './combobox.DNYCWyub.js';
|
|
29
29
|
import { T as TwoLevelCombobox } from './two-level-combobox.DsWPDcI6.js';
|
|
30
|
+
import { l as loadConversation, c as createConversationId, a as useAutocomplete, s as sendFeedbackReason, b as sendFeedback, d as searchApi, f as fetchAnswerStream, e as fetchFollowUpQuestions } from './hooks.B9tkXVNJ.js';
|
|
30
31
|
import { ScrollArea } from '../components/ui/scroll-area.js';
|
|
31
32
|
|
|
32
33
|
import '../ChatSearch.css';function Suggestions({ suggestions, onQuestionClick, title = "Suggested questions" }) {
|
|
@@ -4295,242 +4296,6 @@ const useScrollManager = (answerRefs, containerRef, bottomRef) => {
|
|
|
4295
4296
|
return { scrollToLastAnswer, scrollToAnswer, scrollToBottom };
|
|
4296
4297
|
};
|
|
4297
4298
|
|
|
4298
|
-
const defaultRetryOptions = {
|
|
4299
|
-
maxRetries: 3,
|
|
4300
|
-
baseDelay: 1e3,
|
|
4301
|
-
shouldRetry: (error) => {
|
|
4302
|
-
if (error instanceof TypeError) {
|
|
4303
|
-
return true;
|
|
4304
|
-
}
|
|
4305
|
-
const apiError = error;
|
|
4306
|
-
return apiError.status ? apiError.status >= 500 : false;
|
|
4307
|
-
}
|
|
4308
|
-
};
|
|
4309
|
-
const defaultFallbackConfig = {
|
|
4310
|
-
emptyResponse: "I apologize, but I couldn't generate an answer at this time. Please try again.",
|
|
4311
|
-
errorResponse: "I encountered an error while processing your request. Please try again."
|
|
4312
|
-
};
|
|
4313
|
-
let globalRetryOptions = { ...defaultRetryOptions };
|
|
4314
|
-
let globalFallbackConfig = { ...defaultFallbackConfig };
|
|
4315
|
-
async function delay(ms) {
|
|
4316
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
4317
|
-
}
|
|
4318
|
-
async function makeRequest(url, config = {}) {
|
|
4319
|
-
const { retry = {}, headers = {}, body, isStream = false, fallback = {}, ...fetchConfig } = config;
|
|
4320
|
-
const retryOptions = {
|
|
4321
|
-
...globalRetryOptions,
|
|
4322
|
-
...retry
|
|
4323
|
-
};
|
|
4324
|
-
const fallbackOptions = {
|
|
4325
|
-
...globalFallbackConfig,
|
|
4326
|
-
...fallback
|
|
4327
|
-
};
|
|
4328
|
-
let attempt = 1;
|
|
4329
|
-
while (true) {
|
|
4330
|
-
try {
|
|
4331
|
-
const response = await fetch(url, {
|
|
4332
|
-
...fetchConfig,
|
|
4333
|
-
headers: {
|
|
4334
|
-
"Content-Type": "application/json",
|
|
4335
|
-
...headers
|
|
4336
|
-
},
|
|
4337
|
-
body: body ? JSON.stringify(body) : void 0
|
|
4338
|
-
});
|
|
4339
|
-
if (response.ok) {
|
|
4340
|
-
if (isStream) {
|
|
4341
|
-
if (!response.ok) {
|
|
4342
|
-
throw new Error("Failed to fetch answer");
|
|
4343
|
-
}
|
|
4344
|
-
return response;
|
|
4345
|
-
}
|
|
4346
|
-
const data = await response.json();
|
|
4347
|
-
if (!data || typeof data === "object" && Object.keys(data).length === 0) {
|
|
4348
|
-
const emptyError = new Error(fallbackOptions.emptyResponse);
|
|
4349
|
-
emptyError.name = "EmptyResponseError";
|
|
4350
|
-
throw emptyError;
|
|
4351
|
-
}
|
|
4352
|
-
return data;
|
|
4353
|
-
}
|
|
4354
|
-
const error = new Error(fallbackOptions.errorResponse);
|
|
4355
|
-
error.status = response.status;
|
|
4356
|
-
error.data = await response.json().catch(() => void 0);
|
|
4357
|
-
throw error;
|
|
4358
|
-
} catch (error) {
|
|
4359
|
-
const shouldAttemptRetry = await Promise.resolve(retryOptions.shouldRetry(error, attempt));
|
|
4360
|
-
if (attempt >= retryOptions.maxRetries || !shouldAttemptRetry) {
|
|
4361
|
-
if (error instanceof Error && error.name === "EmptyResponseError") {
|
|
4362
|
-
return { message: error.message };
|
|
4363
|
-
}
|
|
4364
|
-
throw error;
|
|
4365
|
-
}
|
|
4366
|
-
console.warn(`Request failed, attempt ${attempt} of ${retryOptions.maxRetries}. Retrying...`);
|
|
4367
|
-
const jitter = Math.random() * 0.3 + 0.85;
|
|
4368
|
-
await delay(retryOptions.baseDelay * Math.pow(2, attempt - 1) * jitter);
|
|
4369
|
-
attempt++;
|
|
4370
|
-
}
|
|
4371
|
-
}
|
|
4372
|
-
}
|
|
4373
|
-
|
|
4374
|
-
const searchRetryConfig = {
|
|
4375
|
-
maxRetries: 3,
|
|
4376
|
-
baseDelay: 300,
|
|
4377
|
-
// Start with 300ms delay
|
|
4378
|
-
shouldRetry: (error) => {
|
|
4379
|
-
if (error instanceof TypeError) {
|
|
4380
|
-
return true;
|
|
4381
|
-
}
|
|
4382
|
-
const apiError = error;
|
|
4383
|
-
return apiError.status ? apiError.status >= 500 || apiError.status === 429 : false;
|
|
4384
|
-
}
|
|
4385
|
-
};
|
|
4386
|
-
const answerRetryConfig = {
|
|
4387
|
-
maxRetries: 3,
|
|
4388
|
-
baseDelay: 500,
|
|
4389
|
-
// Start with 500ms delay for streaming responses
|
|
4390
|
-
shouldRetry: (error) => {
|
|
4391
|
-
if (error instanceof TypeError) {
|
|
4392
|
-
return true;
|
|
4393
|
-
}
|
|
4394
|
-
const apiError = error;
|
|
4395
|
-
return apiError.status ? apiError.status >= 500 : false;
|
|
4396
|
-
}
|
|
4397
|
-
};
|
|
4398
|
-
async function searchApi({
|
|
4399
|
-
endpoint,
|
|
4400
|
-
query,
|
|
4401
|
-
collectionId,
|
|
4402
|
-
headers,
|
|
4403
|
-
conversationId,
|
|
4404
|
-
attributes,
|
|
4405
|
-
secretAttributes,
|
|
4406
|
-
allowedRegions,
|
|
4407
|
-
source
|
|
4408
|
-
}) {
|
|
4409
|
-
const payload = await makeRequest(endpoint, {
|
|
4410
|
-
method: "POST",
|
|
4411
|
-
headers,
|
|
4412
|
-
retry: searchRetryConfig,
|
|
4413
|
-
body: {
|
|
4414
|
-
query,
|
|
4415
|
-
limit: 5,
|
|
4416
|
-
...collectionId && collectionId !== "all" && { collectionId },
|
|
4417
|
-
...conversationId && { conversationId },
|
|
4418
|
-
...attributes && { attributes },
|
|
4419
|
-
...secretAttributes && { secretAttributes },
|
|
4420
|
-
...allowedRegions && { allowedRegions },
|
|
4421
|
-
...source && { source }
|
|
4422
|
-
}
|
|
4423
|
-
});
|
|
4424
|
-
return {
|
|
4425
|
-
results: payload?.data,
|
|
4426
|
-
searchQueryId: payload?.searchQuery?.id,
|
|
4427
|
-
isAgenticResponse: payload?.isAgenticResponse
|
|
4428
|
-
};
|
|
4429
|
-
}
|
|
4430
|
-
async function fetchAnswerStream({
|
|
4431
|
-
endpoint,
|
|
4432
|
-
headers,
|
|
4433
|
-
body
|
|
4434
|
-
}) {
|
|
4435
|
-
return makeRequest(endpoint, {
|
|
4436
|
-
method: "POST",
|
|
4437
|
-
headers,
|
|
4438
|
-
retry: answerRetryConfig,
|
|
4439
|
-
isStream: true,
|
|
4440
|
-
fallback: {
|
|
4441
|
-
emptyResponse: "I apologize, but I couldn't generate an answer for your query. Please try rephrasing your question.",
|
|
4442
|
-
errorResponse: "I encountered an issue while generating the answer. Please try again in a moment."
|
|
4443
|
-
},
|
|
4444
|
-
body
|
|
4445
|
-
});
|
|
4446
|
-
}
|
|
4447
|
-
function createConversationId() {
|
|
4448
|
-
return createId();
|
|
4449
|
-
}
|
|
4450
|
-
async function sendFeedback({
|
|
4451
|
-
endpoint,
|
|
4452
|
-
searchQueryId,
|
|
4453
|
-
response,
|
|
4454
|
-
headers,
|
|
4455
|
-
conversationId
|
|
4456
|
-
}) {
|
|
4457
|
-
await makeRequest(endpoint, {
|
|
4458
|
-
method: "POST",
|
|
4459
|
-
headers,
|
|
4460
|
-
body: {
|
|
4461
|
-
searchQueryId,
|
|
4462
|
-
response,
|
|
4463
|
-
...conversationId && { conversationId }
|
|
4464
|
-
}
|
|
4465
|
-
});
|
|
4466
|
-
}
|
|
4467
|
-
async function sendFeedbackReason({
|
|
4468
|
-
endpoint,
|
|
4469
|
-
searchQueryId,
|
|
4470
|
-
reason,
|
|
4471
|
-
headers
|
|
4472
|
-
}) {
|
|
4473
|
-
await makeRequest(endpoint, {
|
|
4474
|
-
method: "POST",
|
|
4475
|
-
headers,
|
|
4476
|
-
body: {
|
|
4477
|
-
searchQueryId,
|
|
4478
|
-
reason
|
|
4479
|
-
}
|
|
4480
|
-
});
|
|
4481
|
-
}
|
|
4482
|
-
async function loadConversation({
|
|
4483
|
-
endpoint,
|
|
4484
|
-
conversationId,
|
|
4485
|
-
headers,
|
|
4486
|
-
signal
|
|
4487
|
-
}) {
|
|
4488
|
-
const payload = await makeRequest(endpoint, {
|
|
4489
|
-
method: "POST",
|
|
4490
|
-
headers,
|
|
4491
|
-
body: { conversationId },
|
|
4492
|
-
signal
|
|
4493
|
-
});
|
|
4494
|
-
return { data: payload.data };
|
|
4495
|
-
}
|
|
4496
|
-
async function fetchFollowUpQuestions({
|
|
4497
|
-
endpoint,
|
|
4498
|
-
searchQueryId,
|
|
4499
|
-
headers,
|
|
4500
|
-
conversationId
|
|
4501
|
-
}) {
|
|
4502
|
-
const data = await makeRequest(endpoint, {
|
|
4503
|
-
method: "POST",
|
|
4504
|
-
headers,
|
|
4505
|
-
body: {
|
|
4506
|
-
searchQueryId,
|
|
4507
|
-
...conversationId
|
|
4508
|
-
}
|
|
4509
|
-
});
|
|
4510
|
-
return data.questions;
|
|
4511
|
-
}
|
|
4512
|
-
async function fetchAutocomplete({
|
|
4513
|
-
endpoint,
|
|
4514
|
-
query,
|
|
4515
|
-
collectionId,
|
|
4516
|
-
headers,
|
|
4517
|
-
conversationId,
|
|
4518
|
-
allowedRegions
|
|
4519
|
-
}) {
|
|
4520
|
-
const data = await makeRequest(endpoint, {
|
|
4521
|
-
method: "POST",
|
|
4522
|
-
headers,
|
|
4523
|
-
retry: searchRetryConfig,
|
|
4524
|
-
body: {
|
|
4525
|
-
query,
|
|
4526
|
-
...collectionId && collectionId !== "all" && { collectionId },
|
|
4527
|
-
...conversationId && { conversationId },
|
|
4528
|
-
...allowedRegions && { allowedRegions }
|
|
4529
|
-
}
|
|
4530
|
-
});
|
|
4531
|
-
return data;
|
|
4532
|
-
}
|
|
4533
|
-
|
|
4534
4299
|
const useConversationLoader = ({ loadConversationEndpoint, headers, mergedTextConfig }) => {
|
|
4535
4300
|
const {
|
|
4536
4301
|
setIsLoadingConversation,
|
|
@@ -4772,6 +4537,7 @@ function Answer({
|
|
|
4772
4537
|
state = "completed",
|
|
4773
4538
|
searchQueryId,
|
|
4774
4539
|
searchIntentId,
|
|
4540
|
+
hideCitations = false,
|
|
4775
4541
|
feedback,
|
|
4776
4542
|
onFeedback,
|
|
4777
4543
|
disableFeedback = false,
|
|
@@ -4866,7 +4632,7 @@ function Answer({
|
|
|
4866
4632
|
feedbackReasonThankYouText: "Thank you for your feedback!"
|
|
4867
4633
|
}
|
|
4868
4634
|
)),
|
|
4869
|
-
searchResults && searchResults.length > 0 && /* @__PURE__ */ React__default.createElement("div", { className: "overflow-hidden bg-card border-dashed border-0 border-t-2" }, /* @__PURE__ */ React__default.createElement(Collapsible, { open: isExpanded, onOpenChange: setIsExpanded, className: "w-full" }, /* @__PURE__ */ React__default.createElement("div", null, /* @__PURE__ */ React__default.createElement(CollapsibleTrigger, { asChild: true }, /* @__PURE__ */ React__default.createElement(Button, { variant: "secondary", className: "w-full justify-between h-11", "data-name": "RelatedSources" }, /* @__PURE__ */ React__default.createElement("div", { className: "flex items-center gap-2" }, /* @__PURE__ */ React__default.createElement("span", { className: "font-medium truncate text-base" }, "Sources")), /* @__PURE__ */ React__default.createElement(
|
|
4635
|
+
!hideCitations && searchResults && searchResults.length > 0 && /* @__PURE__ */ React__default.createElement("div", { className: "overflow-hidden bg-card border-dashed border-0 border-t-2" }, /* @__PURE__ */ React__default.createElement(Collapsible, { open: isExpanded, onOpenChange: setIsExpanded, className: "w-full" }, /* @__PURE__ */ React__default.createElement("div", null, /* @__PURE__ */ React__default.createElement(CollapsibleTrigger, { asChild: true }, /* @__PURE__ */ React__default.createElement(Button, { variant: "secondary", className: "w-full justify-between h-11", "data-name": "RelatedSources" }, /* @__PURE__ */ React__default.createElement("div", { className: "flex items-center gap-2" }, /* @__PURE__ */ React__default.createElement("span", { className: "font-medium truncate text-base" }, "Sources")), /* @__PURE__ */ React__default.createElement(
|
|
4870
4636
|
CaretDown,
|
|
4871
4637
|
{
|
|
4872
4638
|
className: `size-4 flex-shrink-0 transition-transform duration-200 text-secondary-foreground ${isExpanded ? "rotate-180" : ""}`,
|
|
@@ -5681,74 +5447,6 @@ const LoadingConversation = () => {
|
|
|
5681
5447
|
);
|
|
5682
5448
|
};
|
|
5683
5449
|
|
|
5684
|
-
function useDebounce(value, delay) {
|
|
5685
|
-
const [debouncedValue, setDebouncedValue] = useState(value);
|
|
5686
|
-
useEffect(() => {
|
|
5687
|
-
const handler = setTimeout(() => {
|
|
5688
|
-
setDebouncedValue(value);
|
|
5689
|
-
}, delay);
|
|
5690
|
-
return () => {
|
|
5691
|
-
clearTimeout(handler);
|
|
5692
|
-
};
|
|
5693
|
-
}, [value, delay]);
|
|
5694
|
-
return debouncedValue;
|
|
5695
|
-
}
|
|
5696
|
-
function useAutocomplete({
|
|
5697
|
-
query,
|
|
5698
|
-
endpoint,
|
|
5699
|
-
allowedRegions,
|
|
5700
|
-
collectionId,
|
|
5701
|
-
headers,
|
|
5702
|
-
conversationId,
|
|
5703
|
-
delay = 300
|
|
5704
|
-
}) {
|
|
5705
|
-
const [suggestions, setSuggestions] = useState([]);
|
|
5706
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
5707
|
-
const [error, setError] = useState();
|
|
5708
|
-
const debouncedQuery = useDebounce(query, delay);
|
|
5709
|
-
const fetchSuggestions = useCallback(async () => {
|
|
5710
|
-
if (!debouncedQuery.trim()) {
|
|
5711
|
-
setSuggestions([]);
|
|
5712
|
-
return;
|
|
5713
|
-
}
|
|
5714
|
-
setIsLoading(true);
|
|
5715
|
-
setError(void 0);
|
|
5716
|
-
try {
|
|
5717
|
-
const payload = await fetchAutocomplete({
|
|
5718
|
-
endpoint,
|
|
5719
|
-
query: debouncedQuery,
|
|
5720
|
-
collectionId,
|
|
5721
|
-
headers,
|
|
5722
|
-
conversationId,
|
|
5723
|
-
allowedRegions
|
|
5724
|
-
});
|
|
5725
|
-
if (payload?.response?.results) {
|
|
5726
|
-
const lowerCaseQuery = debouncedQuery.toLowerCase();
|
|
5727
|
-
const sortedSuggestions = payload.response.results.sort((a, b) => {
|
|
5728
|
-
const aStartsWithQuery = a.question.toLowerCase().startsWith(lowerCaseQuery);
|
|
5729
|
-
const bStartsWithQuery = b.question.toLowerCase().startsWith(lowerCaseQuery);
|
|
5730
|
-
if (aStartsWithQuery && !bStartsWithQuery) return -1;
|
|
5731
|
-
if (!aStartsWithQuery && bStartsWithQuery) return 1;
|
|
5732
|
-
return 0;
|
|
5733
|
-
});
|
|
5734
|
-
setSuggestions(sortedSuggestions);
|
|
5735
|
-
} else {
|
|
5736
|
-
setSuggestions([]);
|
|
5737
|
-
}
|
|
5738
|
-
} catch (err) {
|
|
5739
|
-
console.error("Error fetching autocomplete suggestions:", err);
|
|
5740
|
-
setError(err instanceof Error ? err.message : "Failed to fetch suggestions");
|
|
5741
|
-
setSuggestions([]);
|
|
5742
|
-
} finally {
|
|
5743
|
-
setIsLoading(false);
|
|
5744
|
-
}
|
|
5745
|
-
}, [debouncedQuery, endpoint, collectionId, headers, conversationId, allowedRegions]);
|
|
5746
|
-
useEffect(() => {
|
|
5747
|
-
void fetchSuggestions();
|
|
5748
|
-
}, [fetchSuggestions]);
|
|
5749
|
-
return { suggestions, isLoading, error };
|
|
5750
|
-
}
|
|
5751
|
-
|
|
5752
5450
|
const markdownRemarkPlugins = [remarkGfm];
|
|
5753
5451
|
const markdownRehypePlugins = [rehypeRaw];
|
|
5754
5452
|
const markdownComponents = {
|
|
@@ -5792,7 +5490,8 @@ const ChatSearchComponent = forwardRef(
|
|
|
5792
5490
|
allowedRegions,
|
|
5793
5491
|
style,
|
|
5794
5492
|
isSearchWidget = false,
|
|
5795
|
-
isAgentAssist = false
|
|
5493
|
+
isAgentAssist = false,
|
|
5494
|
+
hideCitations = false
|
|
5796
5495
|
}, ref) => {
|
|
5797
5496
|
const {
|
|
5798
5497
|
answers,
|
|
@@ -6564,6 +6263,7 @@ const ChatSearchComponent = forwardRef(
|
|
|
6564
6263
|
searchResults: answer.searchResults,
|
|
6565
6264
|
searchQueryId: answer.searchQueryId,
|
|
6566
6265
|
searchIntentId: answer.searchIntentId,
|
|
6266
|
+
hideCitations,
|
|
6567
6267
|
feedback: answer.feedback,
|
|
6568
6268
|
onFeedback: (response) => void handleFeedback(response, answer.searchQueryId, i),
|
|
6569
6269
|
disableFeedback,
|
|
@@ -6641,4 +6341,4 @@ const ChatSearch = forwardRef(({ featureFlags, ...props }, ref) => /* @__PURE__
|
|
|
6641
6341
|
ChatSearch.displayName = "ChatSearch";
|
|
6642
6342
|
|
|
6643
6343
|
export { ChatSearch as C, ChatSearchProvider as a, useIsChatSearchDirty as b, useChatSearch as u };
|
|
6644
|
-
//# sourceMappingURL=ChatSearch.
|
|
6344
|
+
//# sourceMappingURL=ChatSearch.DOH90EUx.js.map
|