@brainfish-ai/components 0.19.3 → 0.19.5
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/convos.d.ts +4 -0
- package/dist/esm/chunks/{ChatSearch.C6nUXNy4.js → ChatSearch.DOH90EUx.js} +3 -306
- 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 +14 -7
- 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/sidebar.d.ts +56 -0
- package/dist/stats.html +1 -1
- package/package.json +2 -1
- package/tailwind.preset.ts +2 -0
- package/dist/esm/chunks/ChatSearch.C6nUXNy4.js.map +0 -1
package/dist/convos.d.ts
CHANGED
|
@@ -95,6 +95,10 @@ declare enum DiscardReason {
|
|
|
95
95
|
OTHER = "other"
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
+
export declare const EmptyConvos: ({ children }: {
|
|
99
|
+
children: default_2.ReactNode;
|
|
100
|
+
}) => default_2.JSX.Element;
|
|
101
|
+
|
|
98
102
|
declare interface EvidenceFromContext {
|
|
99
103
|
supporting_quote?: string;
|
|
100
104
|
url?: string;
|
|
@@ -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,
|
|
@@ -5682,74 +5447,6 @@ const LoadingConversation = () => {
|
|
|
5682
5447
|
);
|
|
5683
5448
|
};
|
|
5684
5449
|
|
|
5685
|
-
function useDebounce(value, delay) {
|
|
5686
|
-
const [debouncedValue, setDebouncedValue] = useState(value);
|
|
5687
|
-
useEffect(() => {
|
|
5688
|
-
const handler = setTimeout(() => {
|
|
5689
|
-
setDebouncedValue(value);
|
|
5690
|
-
}, delay);
|
|
5691
|
-
return () => {
|
|
5692
|
-
clearTimeout(handler);
|
|
5693
|
-
};
|
|
5694
|
-
}, [value, delay]);
|
|
5695
|
-
return debouncedValue;
|
|
5696
|
-
}
|
|
5697
|
-
function useAutocomplete({
|
|
5698
|
-
query,
|
|
5699
|
-
endpoint,
|
|
5700
|
-
allowedRegions,
|
|
5701
|
-
collectionId,
|
|
5702
|
-
headers,
|
|
5703
|
-
conversationId,
|
|
5704
|
-
delay = 300
|
|
5705
|
-
}) {
|
|
5706
|
-
const [suggestions, setSuggestions] = useState([]);
|
|
5707
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
5708
|
-
const [error, setError] = useState();
|
|
5709
|
-
const debouncedQuery = useDebounce(query, delay);
|
|
5710
|
-
const fetchSuggestions = useCallback(async () => {
|
|
5711
|
-
if (!debouncedQuery.trim()) {
|
|
5712
|
-
setSuggestions([]);
|
|
5713
|
-
return;
|
|
5714
|
-
}
|
|
5715
|
-
setIsLoading(true);
|
|
5716
|
-
setError(void 0);
|
|
5717
|
-
try {
|
|
5718
|
-
const payload = await fetchAutocomplete({
|
|
5719
|
-
endpoint,
|
|
5720
|
-
query: debouncedQuery,
|
|
5721
|
-
collectionId,
|
|
5722
|
-
headers,
|
|
5723
|
-
conversationId,
|
|
5724
|
-
allowedRegions
|
|
5725
|
-
});
|
|
5726
|
-
if (payload?.response?.results) {
|
|
5727
|
-
const lowerCaseQuery = debouncedQuery.toLowerCase();
|
|
5728
|
-
const sortedSuggestions = payload.response.results.sort((a, b) => {
|
|
5729
|
-
const aStartsWithQuery = a.question.toLowerCase().startsWith(lowerCaseQuery);
|
|
5730
|
-
const bStartsWithQuery = b.question.toLowerCase().startsWith(lowerCaseQuery);
|
|
5731
|
-
if (aStartsWithQuery && !bStartsWithQuery) return -1;
|
|
5732
|
-
if (!aStartsWithQuery && bStartsWithQuery) return 1;
|
|
5733
|
-
return 0;
|
|
5734
|
-
});
|
|
5735
|
-
setSuggestions(sortedSuggestions);
|
|
5736
|
-
} else {
|
|
5737
|
-
setSuggestions([]);
|
|
5738
|
-
}
|
|
5739
|
-
} catch (err) {
|
|
5740
|
-
console.error("Error fetching autocomplete suggestions:", err);
|
|
5741
|
-
setError(err instanceof Error ? err.message : "Failed to fetch suggestions");
|
|
5742
|
-
setSuggestions([]);
|
|
5743
|
-
} finally {
|
|
5744
|
-
setIsLoading(false);
|
|
5745
|
-
}
|
|
5746
|
-
}, [debouncedQuery, endpoint, collectionId, headers, conversationId, allowedRegions]);
|
|
5747
|
-
useEffect(() => {
|
|
5748
|
-
void fetchSuggestions();
|
|
5749
|
-
}, [fetchSuggestions]);
|
|
5750
|
-
return { suggestions, isLoading, error };
|
|
5751
|
-
}
|
|
5752
|
-
|
|
5753
5450
|
const markdownRemarkPlugins = [remarkGfm];
|
|
5754
5451
|
const markdownRehypePlugins = [rehypeRaw];
|
|
5755
5452
|
const markdownComponents = {
|
|
@@ -6644,4 +6341,4 @@ const ChatSearch = forwardRef(({ featureFlags, ...props }, ref) => /* @__PURE__
|
|
|
6644
6341
|
ChatSearch.displayName = "ChatSearch";
|
|
6645
6342
|
|
|
6646
6343
|
export { ChatSearch as C, ChatSearchProvider as a, useIsChatSearchDirty as b, useChatSearch as u };
|
|
6647
|
-
//# sourceMappingURL=ChatSearch.
|
|
6344
|
+
//# sourceMappingURL=ChatSearch.DOH90EUx.js.map
|