@brainfish-ai/components 0.7.1 → 0.8.1
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/esm/chunks/{ChatSearch.D-TNvcdQ.js → ChatSearch.SKfNDI-w.js} +78 -2
- package/dist/esm/chunks/ChatSearch.SKfNDI-w.js.map +1 -0
- package/dist/esm/components/chat-search.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/stats.html +1 -1
- package/package.json +1 -1
- package/dist/esm/chunks/ChatSearch.D-TNvcdQ.js.map +0 -1
|
@@ -5146,6 +5146,37 @@ const defaultTextConfig = {
|
|
|
5146
5146
|
}
|
|
5147
5147
|
};
|
|
5148
5148
|
|
|
5149
|
+
const clientExecutionEventType = "CLIENT_EXECUTION";
|
|
5150
|
+
const clientExecutionResultEventType = "CLIENT_EXECUTION_RESULT";
|
|
5151
|
+
const executeClientAction = (key, inputs) => {
|
|
5152
|
+
return new Promise((resolve) => {
|
|
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
|
+
resolve({
|
|
5173
|
+
success: false,
|
|
5174
|
+
reason: `Client Action handler with key ${key} timed out`
|
|
5175
|
+
});
|
|
5176
|
+
}, 5e3);
|
|
5177
|
+
});
|
|
5178
|
+
};
|
|
5179
|
+
|
|
5149
5180
|
const LoadingConversation = () => {
|
|
5150
5181
|
return /* @__PURE__ */ React__default.createElement(
|
|
5151
5182
|
motion.div,
|
|
@@ -5368,7 +5399,17 @@ const ChatSearchComponent = forwardRef(
|
|
|
5368
5399
|
actionId: event.actionId,
|
|
5369
5400
|
schema: event.schema,
|
|
5370
5401
|
initialValues: event.values,
|
|
5371
|
-
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
|
+
}
|
|
5372
5413
|
return generateAnswerForAction({
|
|
5373
5414
|
searchQueryId,
|
|
5374
5415
|
conversationId,
|
|
@@ -5468,6 +5509,41 @@ const ChatSearchComponent = forwardRef(
|
|
|
5468
5509
|
setIsSearching(false);
|
|
5469
5510
|
}
|
|
5470
5511
|
};
|
|
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
|
+
};
|
|
5471
5547
|
const handleSearchApiCall = async ({
|
|
5472
5548
|
searchQuery,
|
|
5473
5549
|
conversationId,
|
|
@@ -5873,4 +5949,4 @@ const ChatSearch = forwardRef(({ featureFlags, ...props }, ref) => /* @__PURE__
|
|
|
5873
5949
|
ChatSearch.displayName = "ChatSearch";
|
|
5874
5950
|
|
|
5875
5951
|
export { ChatSearch as C, ChatSearchProvider as a, useIsChatSearchDirty as b, useChatSearch as u };
|
|
5876
|
-
//# sourceMappingURL=ChatSearch.
|
|
5952
|
+
//# sourceMappingURL=ChatSearch.SKfNDI-w.js.map
|