@brainfish-ai/components 0.7.0 → 0.8.0
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.BD2RqFhC.js → ChatSearch.D0xl3Epm.js} +109 -12
- package/dist/esm/chunks/ChatSearch.D0xl3Epm.js.map +1 -0
- package/dist/esm/components/chat-search.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/stats.html +1 -1
- package/package.json +1 -1
- package/dist/esm/chunks/ChatSearch.BD2RqFhC.js.map +0 -1
package/dist/chat-search.d.ts
CHANGED
|
@@ -221,6 +221,7 @@ export declare interface ChatSearchProps {
|
|
|
221
221
|
userData?: Record<string, unknown> | null;
|
|
222
222
|
redirectRules?: RedirectRule[];
|
|
223
223
|
secretAttributes?: string;
|
|
224
|
+
allowedRegions?: string[];
|
|
224
225
|
}
|
|
225
226
|
|
|
226
227
|
export declare const ChatSearchProvider: default_2.FC<{
|
|
@@ -4230,7 +4230,8 @@ async function searchApi({
|
|
|
4230
4230
|
headers,
|
|
4231
4231
|
conversationId,
|
|
4232
4232
|
attributes,
|
|
4233
|
-
secretAttributes
|
|
4233
|
+
secretAttributes,
|
|
4234
|
+
allowedRegions
|
|
4234
4235
|
}) {
|
|
4235
4236
|
const payload = await makeRequest(endpoint, {
|
|
4236
4237
|
method: "POST",
|
|
@@ -4242,7 +4243,8 @@ async function searchApi({
|
|
|
4242
4243
|
...collectionId && collectionId !== "all" && { collectionId },
|
|
4243
4244
|
...conversationId && { conversationId },
|
|
4244
4245
|
...attributes && { attributes },
|
|
4245
|
-
...secretAttributes && { secretAttributes }
|
|
4246
|
+
...secretAttributes && { secretAttributes },
|
|
4247
|
+
...allowedRegions && { allowedRegions }
|
|
4246
4248
|
}
|
|
4247
4249
|
});
|
|
4248
4250
|
return {
|
|
@@ -4337,7 +4339,8 @@ async function fetchAutocomplete({
|
|
|
4337
4339
|
query,
|
|
4338
4340
|
collectionId,
|
|
4339
4341
|
headers,
|
|
4340
|
-
conversationId
|
|
4342
|
+
conversationId,
|
|
4343
|
+
allowedRegions
|
|
4341
4344
|
}) {
|
|
4342
4345
|
const data = await makeRequest(endpoint, {
|
|
4343
4346
|
method: "POST",
|
|
@@ -4346,7 +4349,8 @@ async function fetchAutocomplete({
|
|
|
4346
4349
|
body: {
|
|
4347
4350
|
query,
|
|
4348
4351
|
...collectionId && collectionId !== "all" && { collectionId },
|
|
4349
|
-
...conversationId && { conversationId }
|
|
4352
|
+
...conversationId && { conversationId },
|
|
4353
|
+
...allowedRegions && { allowedRegions }
|
|
4350
4354
|
}
|
|
4351
4355
|
});
|
|
4352
4356
|
return data;
|
|
@@ -5142,6 +5146,37 @@ const defaultTextConfig = {
|
|
|
5142
5146
|
}
|
|
5143
5147
|
};
|
|
5144
5148
|
|
|
5149
|
+
const clientExecutionEventType = "CLIENT_EXECUTION";
|
|
5150
|
+
const clientExecutionResultEventType = "CLIENT_EXECUTION_RESULT";
|
|
5151
|
+
const executeClientAction = (key, inputs) => {
|
|
5152
|
+
return new Promise((resolve, reject) => {
|
|
5153
|
+
const messageId = crypto.randomUUID();
|
|
5154
|
+
const handleResponse = (event) => {
|
|
5155
|
+
if (event.data.messageId === messageId && event.data.type === clientExecutionResultEventType) {
|
|
5156
|
+
window.removeEventListener("message", handleResponse);
|
|
5157
|
+
resolve(event.data.result);
|
|
5158
|
+
}
|
|
5159
|
+
};
|
|
5160
|
+
window.addEventListener("message", handleResponse);
|
|
5161
|
+
window.parent.postMessage(
|
|
5162
|
+
{
|
|
5163
|
+
type: clientExecutionEventType,
|
|
5164
|
+
messageId,
|
|
5165
|
+
actionKey: key,
|
|
5166
|
+
inputs
|
|
5167
|
+
},
|
|
5168
|
+
"*"
|
|
5169
|
+
);
|
|
5170
|
+
setTimeout(() => {
|
|
5171
|
+
window.removeEventListener("message", handleResponse);
|
|
5172
|
+
reject({
|
|
5173
|
+
success: false,
|
|
5174
|
+
reason: `Client Action handler with key ${key} timed out`
|
|
5175
|
+
});
|
|
5176
|
+
}, 5e3);
|
|
5177
|
+
});
|
|
5178
|
+
};
|
|
5179
|
+
|
|
5145
5180
|
const LoadingConversation = () => {
|
|
5146
5181
|
return /* @__PURE__ */ React__default.createElement(
|
|
5147
5182
|
motion.div,
|
|
@@ -5177,6 +5212,7 @@ function useDebounce(value, delay) {
|
|
|
5177
5212
|
function useAutocomplete({
|
|
5178
5213
|
query,
|
|
5179
5214
|
endpoint,
|
|
5215
|
+
allowedRegions,
|
|
5180
5216
|
collectionId,
|
|
5181
5217
|
headers,
|
|
5182
5218
|
conversationId,
|
|
@@ -5199,7 +5235,8 @@ function useAutocomplete({
|
|
|
5199
5235
|
query: debouncedQuery,
|
|
5200
5236
|
collectionId,
|
|
5201
5237
|
headers,
|
|
5202
|
-
conversationId
|
|
5238
|
+
conversationId,
|
|
5239
|
+
allowedRegions
|
|
5203
5240
|
});
|
|
5204
5241
|
setSuggestions(payload?.response?.results);
|
|
5205
5242
|
} catch (err) {
|
|
@@ -5209,7 +5246,7 @@ function useAutocomplete({
|
|
|
5209
5246
|
} finally {
|
|
5210
5247
|
setIsLoading(false);
|
|
5211
5248
|
}
|
|
5212
|
-
}, [debouncedQuery, endpoint, collectionId, headers, conversationId]);
|
|
5249
|
+
}, [debouncedQuery, endpoint, collectionId, headers, conversationId, allowedRegions]);
|
|
5213
5250
|
useEffect(() => {
|
|
5214
5251
|
void fetchSuggestions();
|
|
5215
5252
|
}, [fetchSuggestions]);
|
|
@@ -5246,7 +5283,8 @@ const ChatSearchComponent = forwardRef(
|
|
|
5246
5283
|
onNextBestActionClick,
|
|
5247
5284
|
userData,
|
|
5248
5285
|
redirectRules,
|
|
5249
|
-
secretAttributes
|
|
5286
|
+
secretAttributes,
|
|
5287
|
+
allowedRegions
|
|
5250
5288
|
}, ref) => {
|
|
5251
5289
|
const {
|
|
5252
5290
|
answers,
|
|
@@ -5281,6 +5319,7 @@ const ChatSearchComponent = forwardRef(
|
|
|
5281
5319
|
const { suggestions: autocompleteSuggestions } = useAutocomplete({
|
|
5282
5320
|
query,
|
|
5283
5321
|
endpoint: autocompleteEndpoint || "",
|
|
5322
|
+
allowedRegions,
|
|
5284
5323
|
collectionId: currentCollectionId,
|
|
5285
5324
|
headers,
|
|
5286
5325
|
conversationId: currentConversationId,
|
|
@@ -5360,7 +5399,17 @@ const ChatSearchComponent = forwardRef(
|
|
|
5360
5399
|
actionId: event.actionId,
|
|
5361
5400
|
schema: event.schema,
|
|
5362
5401
|
initialValues: event.values,
|
|
5363
|
-
onSubmit: (parameters) => {
|
|
5402
|
+
onSubmit: async (parameters) => {
|
|
5403
|
+
if (event.actionType === "client_execution") {
|
|
5404
|
+
const results = await executeClientAction(event.actionKey, parameters);
|
|
5405
|
+
return generateAnswerForClientAction({
|
|
5406
|
+
searchQueryId,
|
|
5407
|
+
conversationId,
|
|
5408
|
+
searchIntentId: event.searchIntentId,
|
|
5409
|
+
actionId: event.actionId,
|
|
5410
|
+
results
|
|
5411
|
+
});
|
|
5412
|
+
}
|
|
5364
5413
|
return generateAnswerForAction({
|
|
5365
5414
|
searchQueryId,
|
|
5366
5415
|
conversationId,
|
|
@@ -5460,7 +5509,48 @@ const ChatSearchComponent = forwardRef(
|
|
|
5460
5509
|
setIsSearching(false);
|
|
5461
5510
|
}
|
|
5462
5511
|
};
|
|
5463
|
-
const
|
|
5512
|
+
const generateAnswerForClientAction = async ({
|
|
5513
|
+
searchQueryId,
|
|
5514
|
+
searchIntentId,
|
|
5515
|
+
conversationId,
|
|
5516
|
+
actionId,
|
|
5517
|
+
results
|
|
5518
|
+
}) => {
|
|
5519
|
+
answerListDispatch(invokeAction());
|
|
5520
|
+
try {
|
|
5521
|
+
const response = await fetchAnswerStream({
|
|
5522
|
+
endpoint: answerStreamEndpoint,
|
|
5523
|
+
headers,
|
|
5524
|
+
body: {
|
|
5525
|
+
type: "client-execution-result",
|
|
5526
|
+
conversationId,
|
|
5527
|
+
searchQueryId,
|
|
5528
|
+
searchIntentId,
|
|
5529
|
+
actionId,
|
|
5530
|
+
results
|
|
5531
|
+
}
|
|
5532
|
+
});
|
|
5533
|
+
const reader = response.body?.getReader();
|
|
5534
|
+
if (!reader) return;
|
|
5535
|
+
await processAnswerStream({
|
|
5536
|
+
reader,
|
|
5537
|
+
searchQueryId
|
|
5538
|
+
});
|
|
5539
|
+
} catch (e) {
|
|
5540
|
+
console.error("Error generating answer for action:", e);
|
|
5541
|
+
answerListDispatch(setAnswerError({ error: mergedTextConfig.errorText || "An error occurred." }));
|
|
5542
|
+
} finally {
|
|
5543
|
+
answerListDispatch(completeAnswer());
|
|
5544
|
+
setIsSearching(false);
|
|
5545
|
+
}
|
|
5546
|
+
};
|
|
5547
|
+
const handleSearchApiCall = async ({
|
|
5548
|
+
searchQuery,
|
|
5549
|
+
conversationId,
|
|
5550
|
+
attributes,
|
|
5551
|
+
secretAttributes: secretAttributes2,
|
|
5552
|
+
allowedRegions: allowedRegions2
|
|
5553
|
+
}) => {
|
|
5464
5554
|
const searchResponse = await searchApi({
|
|
5465
5555
|
endpoint: searchEndpoint,
|
|
5466
5556
|
query: searchQuery,
|
|
@@ -5468,7 +5558,8 @@ const ChatSearchComponent = forwardRef(
|
|
|
5468
5558
|
headers,
|
|
5469
5559
|
conversationId,
|
|
5470
5560
|
attributes,
|
|
5471
|
-
secretAttributes: secretAttributes2
|
|
5561
|
+
secretAttributes: secretAttributes2,
|
|
5562
|
+
allowedRegions: allowedRegions2
|
|
5472
5563
|
});
|
|
5473
5564
|
if (searchResponse.results.length === 0) {
|
|
5474
5565
|
trackEvent?.("No Articles Found", { conversationId, searchQuery });
|
|
@@ -5498,7 +5589,13 @@ const ChatSearchComponent = forwardRef(
|
|
|
5498
5589
|
followUpSearchRef.current?.focus();
|
|
5499
5590
|
try {
|
|
5500
5591
|
const attributes = { ...userData };
|
|
5501
|
-
const searchQueryId = await handleSearchApiCall(
|
|
5592
|
+
const searchQueryId = await handleSearchApiCall({
|
|
5593
|
+
searchQuery,
|
|
5594
|
+
conversationId,
|
|
5595
|
+
attributes,
|
|
5596
|
+
secretAttributes,
|
|
5597
|
+
allowedRegions
|
|
5598
|
+
});
|
|
5502
5599
|
event && trackEvent?.(event.name, {
|
|
5503
5600
|
conversationId,
|
|
5504
5601
|
searchQuery,
|
|
@@ -5852,4 +5949,4 @@ const ChatSearch = forwardRef(({ featureFlags, ...props }, ref) => /* @__PURE__
|
|
|
5852
5949
|
ChatSearch.displayName = "ChatSearch";
|
|
5853
5950
|
|
|
5854
5951
|
export { ChatSearch as C, ChatSearchProvider as a, useIsChatSearchDirty as b, useChatSearch as u };
|
|
5855
|
-
//# sourceMappingURL=ChatSearch.
|
|
5952
|
+
//# sourceMappingURL=ChatSearch.D0xl3Epm.js.map
|