vdb-ai-chat 1.0.91 → 1.0.93
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-widget.js +1 -1
- package/dist/chat-widget.js.LICENSE.txt +1 -1
- package/lib/commonjs/api.js +72 -65
- package/lib/commonjs/api.js.map +1 -1
- package/lib/commonjs/components/ButtonContent.js +54 -0
- package/lib/commonjs/components/ButtonContent.js.map +1 -0
- package/lib/commonjs/components/ChatInput.js +2 -10
- package/lib/commonjs/components/ChatInput.js.map +1 -1
- package/lib/commonjs/components/ChatWidget.js +104 -56
- package/lib/commonjs/components/ChatWidget.js.map +1 -1
- package/lib/commonjs/components/FloatingChatButton.js +197 -0
- package/lib/commonjs/components/FloatingChatButton.js.map +1 -0
- package/lib/commonjs/components/LazyProductsFetcher.js +4 -3
- package/lib/commonjs/components/LazyProductsFetcher.js.map +1 -1
- package/lib/commonjs/components/MessageBubble.js +8 -5
- package/lib/commonjs/components/MessageBubble.js.map +1 -1
- package/lib/commonjs/components/ProductsListView.js +133 -18
- package/lib/commonjs/components/ProductsListView.js.map +1 -1
- package/lib/commonjs/components/utils.js +5 -463
- package/lib/commonjs/components/utils.js.map +1 -1
- package/lib/commonjs/config/index.js +118 -0
- package/lib/commonjs/config/index.js.map +1 -0
- package/lib/commonjs/config/requestBuilder.js +553 -0
- package/lib/commonjs/config/requestBuilder.js.map +1 -0
- package/lib/commonjs/config/storeConfigLoader.js +216 -0
- package/lib/commonjs/config/storeConfigLoader.js.map +1 -0
- package/lib/commonjs/config/stores/gabrieledward.json +112 -0
- package/lib/commonjs/config/stores/index.js +49 -0
- package/lib/commonjs/config/stores/index.js.map +1 -0
- package/lib/commonjs/config/types.js +191 -0
- package/lib/commonjs/config/types.js.map +1 -0
- package/lib/commonjs/contexts/ThemeProvider.js +44 -21
- package/lib/commonjs/contexts/ThemeProvider.js.map +1 -1
- package/lib/commonjs/i18n/translations/en.json +4 -87
- package/lib/commonjs/index.web.js +16 -5
- package/lib/commonjs/index.web.js.map +1 -1
- package/lib/commonjs/routes.js +0 -1
- package/lib/commonjs/routes.js.map +1 -1
- package/lib/commonjs/storage.js +14 -4
- package/lib/commonjs/storage.js.map +1 -1
- package/lib/commonjs/theme.js +229 -1
- package/lib/commonjs/theme.js.map +1 -1
- package/lib/commonjs/utils/pluginUrlBuilder.js +493 -0
- package/lib/commonjs/utils/pluginUrlBuilder.js.map +1 -0
- package/lib/module/api.js +71 -66
- package/lib/module/api.js.map +1 -1
- package/lib/module/components/ButtonContent.js +48 -0
- package/lib/module/components/ButtonContent.js.map +1 -0
- package/lib/module/components/ChatInput.js +1 -10
- package/lib/module/components/ChatInput.js.map +1 -1
- package/lib/module/components/ChatWidget.js +106 -58
- package/lib/module/components/ChatWidget.js.map +1 -1
- package/lib/module/components/FloatingChatButton.js +190 -0
- package/lib/module/components/FloatingChatButton.js.map +1 -0
- package/lib/module/components/LazyProductsFetcher.js +4 -3
- package/lib/module/components/LazyProductsFetcher.js.map +1 -1
- package/lib/module/components/MessageBubble.js +9 -6
- package/lib/module/components/MessageBubble.js.map +1 -1
- package/lib/module/components/ProductsListView.js +135 -20
- package/lib/module/components/ProductsListView.js.map +1 -1
- package/lib/module/components/utils.js +3 -454
- package/lib/module/components/utils.js.map +1 -1
- package/lib/module/config/index.js +20 -0
- package/lib/module/config/index.js.map +1 -0
- package/lib/module/config/requestBuilder.js +544 -0
- package/lib/module/config/requestBuilder.js.map +1 -0
- package/lib/module/config/storeConfigLoader.js +206 -0
- package/lib/module/config/storeConfigLoader.js.map +1 -0
- package/lib/module/config/stores/gabrieledward.json +112 -0
- package/lib/module/config/stores/index.js +41 -0
- package/lib/module/config/stores/index.js.map +1 -0
- package/lib/module/config/types.js +182 -0
- package/lib/module/config/types.js.map +1 -0
- package/lib/module/contexts/ThemeProvider.js +39 -16
- package/lib/module/contexts/ThemeProvider.js.map +1 -1
- package/lib/module/i18n/translations/en.json +4 -87
- package/lib/module/index.web.js +16 -5
- package/lib/module/index.web.js.map +1 -1
- package/lib/module/routes.js +0 -1
- package/lib/module/routes.js.map +1 -1
- package/lib/module/storage.js +14 -4
- package/lib/module/storage.js.map +1 -1
- package/lib/module/theme.js +228 -0
- package/lib/module/theme.js.map +1 -1
- package/lib/module/utils/pluginUrlBuilder.js +482 -0
- package/lib/module/utils/pluginUrlBuilder.js.map +1 -0
- package/lib/typescript/api.d.ts +13 -3
- package/lib/typescript/api.d.ts.map +1 -1
- package/lib/typescript/components/BetaNotice.d.ts +1 -2
- package/lib/typescript/components/BetaNotice.d.ts.map +1 -1
- package/lib/typescript/components/ButtonContent.d.ts +5 -0
- package/lib/typescript/components/ButtonContent.d.ts.map +1 -0
- package/lib/typescript/components/ChatInput.d.ts +0 -2
- package/lib/typescript/components/ChatInput.d.ts.map +1 -1
- package/lib/typescript/components/ChatWidget.d.ts.map +1 -1
- package/lib/typescript/components/FloatingChatButton.d.ts +8 -0
- package/lib/typescript/components/FloatingChatButton.d.ts.map +1 -0
- package/lib/typescript/components/LazyProductsFetcher.d.ts +3 -2
- package/lib/typescript/components/LazyProductsFetcher.d.ts.map +1 -1
- package/lib/typescript/components/MessageBubble.d.ts.map +1 -1
- package/lib/typescript/components/ProductsListView.d.ts.map +1 -1
- package/lib/typescript/components/utils.d.ts +0 -46
- package/lib/typescript/components/utils.d.ts.map +1 -1
- package/lib/typescript/config/index.d.ts +11 -0
- package/lib/typescript/config/index.d.ts.map +1 -0
- package/lib/typescript/config/requestBuilder.d.ts +44 -0
- package/lib/typescript/config/requestBuilder.d.ts.map +1 -0
- package/lib/typescript/config/storeConfigLoader.d.ts +52 -0
- package/lib/typescript/config/storeConfigLoader.d.ts.map +1 -0
- package/lib/typescript/config/stores/index.d.ts +27 -0
- package/lib/typescript/config/stores/index.d.ts.map +1 -0
- package/lib/typescript/config/types.d.ts +230 -0
- package/lib/typescript/config/types.d.ts.map +1 -0
- package/lib/typescript/contexts/AnalyticsClientContext.d.ts +1 -1
- package/lib/typescript/contexts/AnalyticsClientContext.d.ts.map +1 -1
- package/lib/typescript/contexts/ThemeProvider.d.ts +1 -1
- package/lib/typescript/contexts/ThemeProvider.d.ts.map +1 -1
- package/lib/typescript/index.web.d.ts +23 -1
- package/lib/typescript/index.web.d.ts.map +1 -1
- package/lib/typescript/routes.d.ts +0 -1
- package/lib/typescript/routes.d.ts.map +1 -1
- package/lib/typescript/storage.d.ts.map +1 -1
- package/lib/typescript/theme.d.ts +228 -0
- package/lib/typescript/theme.d.ts.map +1 -1
- package/lib/typescript/types.d.ts +6 -3
- package/lib/typescript/types.d.ts.map +1 -1
- package/lib/typescript/utils/pluginUrlBuilder.d.ts +74 -0
- package/lib/typescript/utils/pluginUrlBuilder.d.ts.map +1 -0
- package/package.json +2 -1
- package/src/api.ts +90 -86
- package/src/components/ButtonContent.tsx +54 -0
- package/src/components/ChatInput.tsx +7 -11
- package/src/components/ChatWidget.tsx +149 -158
- package/src/components/FloatingChatButton.tsx +204 -0
- package/src/components/LazyProductsFetcher.tsx +7 -5
- package/src/components/MessageBubble.tsx +23 -9
- package/src/components/ProductsListView.tsx +293 -30
- package/src/components/utils.ts +3 -690
- package/src/config/index.ts +65 -0
- package/src/config/requestBuilder.ts +668 -0
- package/src/config/storeConfigLoader.ts +235 -0
- package/src/config/stores/gabrieledward.json +112 -0
- package/src/config/stores/index.ts +41 -0
- package/src/config/types.ts +408 -0
- package/src/contexts/ThemeProvider.tsx +32 -10
- package/src/i18n/translations/en.json +4 -87
- package/src/index.web.tsx +60 -14
- package/src/routes.ts +0 -1
- package/src/storage.ts +14 -4
- package/src/theme.ts +230 -0
- package/src/types.ts +6 -3
- package/src/utils/pluginUrlBuilder.ts +752 -0
- package/lib/commonjs/components/ListItemDiamond.js +0 -150
- package/lib/commonjs/components/ListItemDiamond.js.map +0 -1
- package/lib/commonjs/components/ListItemJewelry.js +0 -105
- package/lib/commonjs/components/ListItemJewelry.js.map +0 -1
- package/lib/module/components/ListItemDiamond.js +0 -142
- package/lib/module/components/ListItemDiamond.js.map +0 -1
- package/lib/module/components/ListItemJewelry.js +0 -96
- package/lib/module/components/ListItemJewelry.js.map +0 -1
- package/lib/typescript/components/ListItemDiamond.d.ts +0 -10
- package/lib/typescript/components/ListItemDiamond.d.ts.map +0 -1
- package/lib/typescript/components/ListItemJewelry.d.ts +0 -10
- package/lib/typescript/components/ListItemJewelry.d.ts.map +0 -1
- package/src/components/ListItemDiamond.tsx +0 -288
- package/src/components/ListItemJewelry.tsx +0 -133
|
@@ -24,6 +24,9 @@ var _native = _interopRequireWildcard(require("styled-components/native"));
|
|
|
24
24
|
var _i18n = require("../i18n");
|
|
25
25
|
var _useGlobalData = require("../hooks/useGlobalData");
|
|
26
26
|
var _WelcomeScreen = _interopRequireDefault(require("./WelcomeScreen"));
|
|
27
|
+
var _pluginUrlBuilder = require("../utils/pluginUrlBuilder");
|
|
28
|
+
var _types = require("../config/types");
|
|
29
|
+
var _storeConfigLoader = require("../config/storeConfigLoader");
|
|
27
30
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
28
31
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
29
32
|
const ChatWidget = exports.ChatWidget = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
@@ -40,7 +43,8 @@ const ChatWidget = exports.ChatWidget = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
40
43
|
onViewAllPress,
|
|
41
44
|
onItemPress: onItemPressProp,
|
|
42
45
|
isBetaMode: isBetaModeProp,
|
|
43
|
-
|
|
46
|
+
useAsPlugin,
|
|
47
|
+
activeProductType,
|
|
44
48
|
trackAnalyticsEvent,
|
|
45
49
|
fromFilterScreen,
|
|
46
50
|
fromFilterSplitScreen,
|
|
@@ -54,6 +58,7 @@ const ChatWidget = exports.ChatWidget = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
54
58
|
const {
|
|
55
59
|
t
|
|
56
60
|
} = (0, _i18n.useTranslation)();
|
|
61
|
+
const [storeConfig, setStoreConfig] = (0, _react.useState)(null);
|
|
57
62
|
const [messages, setMessages] = (0, _react.useState)(initialMessages);
|
|
58
63
|
const [input, setInput] = (0, _react.useState)("");
|
|
59
64
|
const [loading, setLoading] = (0, _react.useState)(false);
|
|
@@ -100,7 +105,6 @@ const ChatWidget = exports.ChatWidget = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
100
105
|
const {
|
|
101
106
|
globalData
|
|
102
107
|
} = (0, _useGlobalData.useGlobalData)();
|
|
103
|
-
const productType = (0, _utils.getProductTypeFromExternalContext)(activeProductType);
|
|
104
108
|
|
|
105
109
|
// Initialize i18n on mount and update when props change
|
|
106
110
|
(0, _react.useEffect)(() => {
|
|
@@ -109,6 +113,17 @@ const ChatWidget = exports.ChatWidget = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
109
113
|
translations
|
|
110
114
|
});
|
|
111
115
|
}, []);
|
|
116
|
+
|
|
117
|
+
// Load store config when in plugin mode
|
|
118
|
+
(0, _react.useEffect)(() => {
|
|
119
|
+
if (useAsPlugin) {
|
|
120
|
+
(0, _storeConfigLoader.loadStoreConfig)().then(config => {
|
|
121
|
+
if (config) {
|
|
122
|
+
setStoreConfig(config);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}, [useAsPlugin]);
|
|
112
127
|
(0, _react.useEffect)(() => {
|
|
113
128
|
(0, _api.getChatHasInitialized)().then(setChatHasInitializedState);
|
|
114
129
|
}, []);
|
|
@@ -118,7 +133,13 @@ const ChatWidget = exports.ChatWidget = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
118
133
|
(0, _react.useEffect)(() => {
|
|
119
134
|
const loadAuthData = async () => {
|
|
120
135
|
try {
|
|
121
|
-
if (
|
|
136
|
+
if (userTokenProp) {
|
|
137
|
+
// If token is provided via props, set the override so API calls use it
|
|
138
|
+
(0, _api.setTokenOverride)(userTokenProp);
|
|
139
|
+
setUserToken(userTokenProp);
|
|
140
|
+
} else {
|
|
141
|
+
// Clear any token override so API calls use storage
|
|
142
|
+
(0, _api.setTokenOverride)(null);
|
|
122
143
|
const userInfo = await _storage.Storage.getJSON("persist:userInfo", {});
|
|
123
144
|
const userData = JSON.parse(userInfo?.user || "{}");
|
|
124
145
|
const token = userData?.token || "";
|
|
@@ -131,6 +152,11 @@ const ChatWidget = exports.ChatWidget = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
131
152
|
}
|
|
132
153
|
};
|
|
133
154
|
loadAuthData();
|
|
155
|
+
|
|
156
|
+
// Cleanup: clear token override when component unmounts
|
|
157
|
+
return () => {
|
|
158
|
+
(0, _api.setTokenOverride)(null);
|
|
159
|
+
};
|
|
134
160
|
}, [userTokenProp]);
|
|
135
161
|
const setActiveProduct = async () => {
|
|
136
162
|
if (activeProductType) {
|
|
@@ -145,26 +171,41 @@ const ChatWidget = exports.ChatWidget = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
145
171
|
}, [activeProductType]);
|
|
146
172
|
const onViewAll = (0, _react.useCallback)(item => {
|
|
147
173
|
let searchPayload = item?.search_payload;
|
|
148
|
-
const productType = item?.product_type;
|
|
149
174
|
const stringifiedSearchPayload = JSON.stringify(searchPayload);
|
|
150
175
|
const payload = item?.search_payload;
|
|
151
176
|
if (!payload) return;
|
|
152
|
-
|
|
153
|
-
|
|
177
|
+
let deepLinkUrl;
|
|
178
|
+
if (useAsPlugin) {
|
|
179
|
+
// Use new storefront URL builder for Shopify stores
|
|
180
|
+
deepLinkUrl = (0, _pluginUrlBuilder.buildStorefrontSearchUrl)(payload, storeConfig, {
|
|
181
|
+
viewType: "grid",
|
|
182
|
+
inJourney: true
|
|
183
|
+
});
|
|
184
|
+
window.open(deepLinkUrl, "_parent");
|
|
185
|
+
} else {
|
|
186
|
+
const isLabgrown = typeof payload.lab_grown === "string" ? payload.lab_grown === "true" : typeof payload.lab_grown === "boolean" ? payload.lab_grown : false;
|
|
187
|
+
deepLinkUrl = `${apiUrl}webapp/${isLabgrown ? "lab-grown-diamonds" : "natural-diamonds"}/search?priceMode=${priceMode}&productType=${isLabgrown ? _utils.ProductCategory.LAB_GROWN_DIAMOND : _utils.ProductCategory.DIAMOND}&fromNewFilterScreen=false&filterSplitStep=1§ionName=${searchPayload.pair === "pair" ? "Pairs" : "Single Stones"}&breadCrumbLabel=Stone%20Search&enterSecondFlow=false&saved_search=${encodeURIComponent(stringifiedSearchPayload)}`;
|
|
188
|
+
}
|
|
154
189
|
if (onViewAllPress) {
|
|
155
190
|
onViewAllPress(deepLinkUrl, payload);
|
|
156
191
|
} else if (_reactNative.Platform.OS === "web") {
|
|
157
192
|
window.open(deepLinkUrl, "_parent");
|
|
158
193
|
}
|
|
159
|
-
}, [apiUrl, priceMode, onViewAllPress]);
|
|
194
|
+
}, [apiUrl, priceMode, onViewAllPress, useAsPlugin, storeConfig]);
|
|
160
195
|
const onItemPress = (0, _react.useCallback)(item => {
|
|
161
|
-
|
|
196
|
+
let deepLinkUrl;
|
|
197
|
+
if (useAsPlugin) {
|
|
198
|
+
deepLinkUrl = (0, _pluginUrlBuilder.buildPluginItemUrl)(item.id, (0, _types.getPdpLinkTemplate)(storeConfig));
|
|
199
|
+
window.open(deepLinkUrl, "_parent");
|
|
200
|
+
} else {
|
|
201
|
+
deepLinkUrl = `${apiUrl}webapp/${item.type === _utils.ProductCategory.LAB_GROWN_DIAMOND ? "lab-grown-diamonds" : "natural-diamonds"}/item-detail/${item.id}?productType=${item.type}&priceMode=${priceMode}&breadCrumbLabel=Stone%20Details`;
|
|
202
|
+
}
|
|
162
203
|
if (onItemPressProp) {
|
|
163
204
|
onItemPressProp(deepLinkUrl, item);
|
|
164
205
|
} else if (_reactNative.Platform.OS === "web") {
|
|
165
206
|
window.open(deepLinkUrl, "_parent");
|
|
166
207
|
}
|
|
167
|
-
}, [apiUrl, priceMode, onItemPressProp]);
|
|
208
|
+
}, [apiUrl, priceMode, onItemPressProp, useAsPlugin, storeConfig]);
|
|
168
209
|
const hasAuth = (0, _react.useMemo)(() => Boolean(userToken), [userToken]);
|
|
169
210
|
const apiParams = (0, _react.useMemo)(() => ({
|
|
170
211
|
conversationId: userToken
|
|
@@ -214,13 +255,12 @@ const ChatWidget = exports.ChatWidget = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
214
255
|
const initialAssistant = {
|
|
215
256
|
id: "",
|
|
216
257
|
role: "assistant",
|
|
217
|
-
text:
|
|
258
|
+
text: t("chat.welcome.message.text", 'Describe the diamond you\'re looking for — for example, "2ct F VS2 under $10,000" or "1–2ct D–F VS pear" — and I\'ll take it from there.'),
|
|
218
259
|
createdAt: Date.now(),
|
|
219
260
|
isLoading: false,
|
|
220
261
|
suggestions: [],
|
|
221
262
|
search_payload: {},
|
|
222
|
-
reaction: "0"
|
|
223
|
-
product_type: _utils.ProductCategory.DIAMOND
|
|
263
|
+
reaction: "0"
|
|
224
264
|
};
|
|
225
265
|
setMessages([initialAssistant]);
|
|
226
266
|
setHasMoreMessages(false);
|
|
@@ -412,10 +452,8 @@ const ChatWidget = exports.ChatWidget = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
412
452
|
const normalised = await (0, _api.normaliseMessages)(updatedMessages, priceMode);
|
|
413
453
|
const latestAssistant = normalised.find(m => m.role === "assistant");
|
|
414
454
|
if (latestAssistant?.text) {
|
|
415
|
-
const productType = latestAssistant.product_type ?? _utils.ProductCategory.DIAMOND;
|
|
416
455
|
if (latestAssistant?.search_payload && typeof latestAssistant.search_payload === "object" && Object.keys(latestAssistant.search_payload).length > 0) {
|
|
417
|
-
const productsResult = await (0, _api.getProducts)(apiUrl, latestAssistant.search_payload,
|
|
418
|
-
const bodyType = [_utils.ProductCategory.DIAMOND, _utils.ProductCategory.LAB_GROWN_DIAMOND].includes(productType) ? "diamonds" : "jewelries";
|
|
456
|
+
const productsResult = await (0, _api.getProducts)(apiUrl, latestAssistant.search_payload, useAsPlugin, storeConfig);
|
|
419
457
|
trackAnalyticsEvent?.(_utils.AIEventNames.AI_CHAT_WIDGET, {
|
|
420
458
|
action: _utils.AIEventTypes.SEARCH_INITIATED,
|
|
421
459
|
search_payload: latestAssistant.search_payload
|
|
@@ -426,8 +464,8 @@ const ChatWidget = exports.ChatWidget = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
426
464
|
classic_search_filters: classic_search_filters
|
|
427
465
|
});
|
|
428
466
|
}
|
|
429
|
-
const
|
|
430
|
-
if (!
|
|
467
|
+
const hasDiamonds = productsResult && productsResult.response && productsResult.response.body && Array.isArray(productsResult.response.body.diamonds) && productsResult.response.body.diamonds.length > 0;
|
|
468
|
+
if (!hasDiamonds) {
|
|
431
469
|
// setLoadingMessageId(null);
|
|
432
470
|
// setTypingMessageId(null);
|
|
433
471
|
// setTypingFullText("");
|
|
@@ -452,10 +490,9 @@ const ChatWidget = exports.ChatWidget = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
452
490
|
action: _utils.AIEventTypes.NO_RESULTS_FOUND,
|
|
453
491
|
search_payload: latestAssistant.search_payload
|
|
454
492
|
});
|
|
455
|
-
} else if (fromFilterScreen &&
|
|
493
|
+
} else if (fromFilterScreen && hasDiamonds) {
|
|
456
494
|
onViewAll({
|
|
457
|
-
search_payload: latestAssistant.search_payload
|
|
458
|
-
product_type: productType
|
|
495
|
+
search_payload: latestAssistant.search_payload
|
|
459
496
|
});
|
|
460
497
|
}
|
|
461
498
|
setProductsByMsg(prev => ({
|
|
@@ -470,8 +507,7 @@ const ChatWidget = exports.ChatWidget = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
470
507
|
text: "",
|
|
471
508
|
isLoading: false,
|
|
472
509
|
suggestions: latestAssistant.suggestions,
|
|
473
|
-
search_payload: latestAssistant.search_payload ?? {}
|
|
474
|
-
product_type: productType
|
|
510
|
+
search_payload: latestAssistant.search_payload ?? {}
|
|
475
511
|
} : msg));
|
|
476
512
|
setTimeout(() => {
|
|
477
513
|
setTypingMessageId(latestAssistant.id);
|
|
@@ -528,7 +564,7 @@ const ChatWidget = exports.ChatWidget = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
528
564
|
setReloadLoadingIds(prev => new Set(prev).add(id));
|
|
529
565
|
const payload = msg?.search_payload;
|
|
530
566
|
if (!payload || Object.keys(payload).length === 0) return;
|
|
531
|
-
const productsResult = await (0, _api.getProducts)(apiUrl, payload,
|
|
567
|
+
const productsResult = await (0, _api.getProducts)(apiUrl, payload, useAsPlugin, storeConfig);
|
|
532
568
|
setProductsByMsg(prev => ({
|
|
533
569
|
...prev,
|
|
534
570
|
[id]: productsResult
|
|
@@ -542,22 +578,21 @@ const ChatWidget = exports.ChatWidget = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
542
578
|
return next;
|
|
543
579
|
});
|
|
544
580
|
}
|
|
545
|
-
}, []);
|
|
546
|
-
const handleShowMoreResults = (0, _react.useCallback)(async (messageId, searchPayload
|
|
581
|
+
}, [apiUrl, useAsPlugin, storeConfig]);
|
|
582
|
+
const handleShowMoreResults = (0, _react.useCallback)(async (messageId, searchPayload) => {
|
|
547
583
|
if (loadingMoreResults.has(messageId)) return;
|
|
548
584
|
const currentPageForMessage = searchResultsPages[messageId] || 1;
|
|
549
585
|
const nextPage = currentPageForMessage + 1;
|
|
550
586
|
if (nextPage > 6) return;
|
|
551
587
|
try {
|
|
552
588
|
setLoadingMoreResults(prev => new Set(prev).add(messageId));
|
|
553
|
-
const
|
|
554
|
-
|
|
555
|
-
if (results?.response?.body?.[bodyType]) {
|
|
589
|
+
const newResults = await (0, _api.getProductsPaginated)(apiUrl, searchPayload, nextPage, useAsPlugin, storeConfig);
|
|
590
|
+
if (newResults?.response?.body?.diamonds) {
|
|
556
591
|
setProductsByMsg(prev => {
|
|
557
592
|
const currentData = prev[messageId];
|
|
558
593
|
if (!currentData) return prev;
|
|
559
|
-
const
|
|
560
|
-
const
|
|
594
|
+
const existingDiamonds = currentData.response?.body?.diamonds || [];
|
|
595
|
+
const newDiamonds = newResults.response.body.diamonds;
|
|
561
596
|
return {
|
|
562
597
|
...prev,
|
|
563
598
|
[messageId]: {
|
|
@@ -566,7 +601,7 @@ const ChatWidget = exports.ChatWidget = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
566
601
|
...currentData.response,
|
|
567
602
|
body: {
|
|
568
603
|
...currentData.response.body,
|
|
569
|
-
|
|
604
|
+
diamonds: [...existingDiamonds, ...newDiamonds]
|
|
570
605
|
}
|
|
571
606
|
}
|
|
572
607
|
}
|
|
@@ -586,11 +621,11 @@ const ChatWidget = exports.ChatWidget = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
586
621
|
return next;
|
|
587
622
|
});
|
|
588
623
|
}
|
|
589
|
-
}, [apiUrl, loadingMoreResults, searchResultsPages]);
|
|
590
|
-
const handleShowLessResults = (0, _react.useCallback)(async (messageId, searchPayload
|
|
624
|
+
}, [apiUrl, loadingMoreResults, searchResultsPages, useAsPlugin, storeConfig]);
|
|
625
|
+
const handleShowLessResults = (0, _react.useCallback)(async (messageId, searchPayload) => {
|
|
591
626
|
try {
|
|
592
|
-
const initialResults = await (0, _api.getProducts)(apiUrl, searchPayload,
|
|
593
|
-
if (initialResults?.response?.body?.diamonds
|
|
627
|
+
const initialResults = await (0, _api.getProducts)(apiUrl, searchPayload, useAsPlugin, storeConfig);
|
|
628
|
+
if (initialResults?.response?.body?.diamonds) {
|
|
594
629
|
setProductsByMsg(prev => ({
|
|
595
630
|
...prev,
|
|
596
631
|
[messageId]: initialResults
|
|
@@ -603,7 +638,7 @@ const ChatWidget = exports.ChatWidget = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
603
638
|
} catch (error) {
|
|
604
639
|
console.error("Failed to show less results:", error);
|
|
605
640
|
}
|
|
606
|
-
}, [apiUrl]);
|
|
641
|
+
}, [apiUrl, useAsPlugin, storeConfig]);
|
|
607
642
|
const handleRecommendationRequest = (0, _react.useCallback)(async messageId => {
|
|
608
643
|
const diamonds = productsByMsg[messageId]?.response?.body?.diamonds;
|
|
609
644
|
if (!diamonds || diamonds.length === 0) return;
|
|
@@ -847,7 +882,7 @@ const ChatWidget = exports.ChatWidget = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
847
882
|
const initialAssistant = {
|
|
848
883
|
id: "",
|
|
849
884
|
role: "assistant",
|
|
850
|
-
text:
|
|
885
|
+
text: t("chat.welcome.message.text", 'Describe the diamond you\'re looking for — for example, "2ct F VS2 under $10,000" or "1–2ct D–F VS pear" — and I\'ll take it from there.'),
|
|
851
886
|
createdAt: Date.now(),
|
|
852
887
|
isLoading: false,
|
|
853
888
|
suggestions: [],
|
|
@@ -964,7 +999,6 @@ const ChatWidget = exports.ChatWidget = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
964
999
|
inputRef: inputRef,
|
|
965
1000
|
apiUrl: apiUrl,
|
|
966
1001
|
priceMode: priceMode,
|
|
967
|
-
activeProductType: activeProductType,
|
|
968
1002
|
enableAiAudioRecording: enableAiAudioRecording
|
|
969
1003
|
}), /*#__PURE__*/_react.default.createElement(_BetaNotice.default, {
|
|
970
1004
|
active: betaActive
|
|
@@ -981,7 +1015,7 @@ const ChatWidget = exports.ChatWidget = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
981
1015
|
}, fromFilterScreen && !fromFilterSplitScreen && chatHasInitialized === false ? /*#__PURE__*/_react.default.createElement(_WelcomeScreen.default, {
|
|
982
1016
|
username: userNameProp || "",
|
|
983
1017
|
theme: theme,
|
|
984
|
-
productType:
|
|
1018
|
+
productType: activeProductType
|
|
985
1019
|
}) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, messages?.[0]?.createdAt && /*#__PURE__*/_react.default.createElement(EmptyContainer, {
|
|
986
1020
|
theme: theme
|
|
987
1021
|
}, /*#__PURE__*/_react.default.createElement(ClearChatContainer, {
|
|
@@ -1057,12 +1091,12 @@ const ChatWidget = exports.ChatWidget = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
1057
1091
|
theme: theme
|
|
1058
1092
|
}, t("chat.loadingOlder.text", "Loading older messages..."))), (() => {
|
|
1059
1093
|
const ordered = [...messages];
|
|
1060
|
-
// Find the latest result message (last assistant with search_payload that has
|
|
1094
|
+
// Find the latest result message (last assistant with search_payload that has diamonds)
|
|
1061
1095
|
let latestResultMsgId = null;
|
|
1062
1096
|
for (let i = ordered.length - 1; i >= 0; i--) {
|
|
1063
1097
|
const msg = ordered[i];
|
|
1064
|
-
const
|
|
1065
|
-
if (msg.role === "assistant" && msg.search_payload && Object.keys(msg.search_payload).length > 0 &&
|
|
1098
|
+
const msgHasDiamonds = Boolean(productsByMsg[msg.id]?.response?.body?.diamonds?.length > 0);
|
|
1099
|
+
if (msg.role === "assistant" && msg.search_payload && Object.keys(msg.search_payload).length > 0 && msgHasDiamonds) {
|
|
1066
1100
|
latestResultMsgId = msg.id;
|
|
1067
1101
|
break;
|
|
1068
1102
|
}
|
|
@@ -1070,10 +1104,6 @@ const ChatWidget = exports.ChatWidget = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
1070
1104
|
return ordered.map((item, index) => {
|
|
1071
1105
|
const isLatest = index === ordered.length - 1;
|
|
1072
1106
|
const isLatestResultMsg = item.id === latestResultMsgId;
|
|
1073
|
-
const productType = item?.product_type || (0, _utils.getProductTypeFromExternalContext)(activeProductType);
|
|
1074
|
-
const bodyType = [_utils.ProductCategory.DIAMOND, _utils.ProductCategory.LAB_GROWN_DIAMOND].includes(productType) ? "diamonds" : "jewelries";
|
|
1075
|
-
const totalResultsKey = [_utils.ProductCategory.JEWELRY, _utils.ProductCategory.LABGROWN_JEWELRY].includes(productType) ? "total_stones_found" : "total_diamonds_found";
|
|
1076
|
-
const hasResults = Boolean(productsByMsg[item.id]?.response?.body?.diamonds && productsByMsg[item.id]?.response?.body?.diamonds.length > 0 || productsByMsg[item.id]?.response?.body?.jewelries && productsByMsg[item.id]?.response?.body?.jewelries.length > 0);
|
|
1077
1107
|
const hasDiamonds = Boolean(productsByMsg[item.id]?.response?.body?.diamonds && productsByMsg[item.id]?.response?.body?.diamonds.length > 0);
|
|
1078
1108
|
return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
|
|
1079
1109
|
key: item.id + index,
|
|
@@ -1087,9 +1117,9 @@ const ChatWidget = exports.ChatWidget = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
1087
1117
|
handleFeedbackAction: handleFeedbackAction,
|
|
1088
1118
|
onReloadResults: handleReloadResults,
|
|
1089
1119
|
reloading: reloadLoadingIds.has(item.id),
|
|
1090
|
-
hasResults:
|
|
1091
|
-
totalResults: productsByMsg[item.id]?.response?.header ? productsByMsg[item.id].response.header?.
|
|
1092
|
-
shownResults: productsByMsg[item.id]?.response?.body?.
|
|
1120
|
+
hasResults: hasDiamonds,
|
|
1121
|
+
totalResults: productsByMsg[item.id]?.response?.header ? productsByMsg[item.id].response.header?.total_diamonds_found ?? 0 : null,
|
|
1122
|
+
shownResults: productsByMsg[item.id]?.response?.body?.diamonds.length || 0,
|
|
1093
1123
|
onSuggestionSelect: handleSuggestionSelect,
|
|
1094
1124
|
isLatest: isLatest,
|
|
1095
1125
|
isTyping: typingMessageId === item.id,
|
|
@@ -1100,22 +1130,40 @@ const ChatWidget = exports.ChatWidget = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
1100
1130
|
priceMode: priceMode,
|
|
1101
1131
|
messageId: item.id,
|
|
1102
1132
|
payload: item.search_payload,
|
|
1103
|
-
|
|
1133
|
+
useAsPlugin: useAsPlugin,
|
|
1134
|
+
storeConfig: storeConfig,
|
|
1104
1135
|
onFetched: (id, result) => {
|
|
1105
1136
|
setProductsByMsg(prev => ({
|
|
1106
1137
|
...prev,
|
|
1107
1138
|
[id]: result
|
|
1108
1139
|
}));
|
|
1140
|
+
// const diamonds = result?.response?.body?.diamonds;
|
|
1141
|
+
// const hasAny =
|
|
1142
|
+
// Array.isArray(diamonds) && diamonds.length > 0;
|
|
1143
|
+
// if (!hasAny) {
|
|
1144
|
+
// setMessages((prev) =>
|
|
1145
|
+
// prev.map((msg) =>
|
|
1146
|
+
// msg.id === id
|
|
1147
|
+
// ? {
|
|
1148
|
+
// ...msg,
|
|
1149
|
+
// id: msg.id,
|
|
1150
|
+
// text: noResultsText,
|
|
1151
|
+
// isLoading: false,
|
|
1152
|
+
// }
|
|
1153
|
+
// : msg
|
|
1154
|
+
// )
|
|
1155
|
+
// );
|
|
1156
|
+
// }
|
|
1109
1157
|
// Let onContentSizeChange handle scrolling naturally
|
|
1110
1158
|
}
|
|
1111
|
-
}), item.role === "assistant" &&
|
|
1112
|
-
data: (productsByMsg[item.id]?.response?.body?.
|
|
1113
|
-
totalResults: productsByMsg[item.id]?.response?.header?.
|
|
1159
|
+
}), item.role === "assistant" && hasDiamonds && !fromFilterScreen && /*#__PURE__*/_react.default.createElement(_ProductsList.default, {
|
|
1160
|
+
data: (productsByMsg[item.id]?.response?.body?.diamonds || []).slice(0, (searchResultsPages[item.id] || 1) * 5),
|
|
1161
|
+
totalResults: productsByMsg[item.id]?.response?.header?.total_diamonds_found || 0,
|
|
1114
1162
|
onViewAll: onViewAll,
|
|
1115
1163
|
onItemPress: onItemPress,
|
|
1116
1164
|
item: item,
|
|
1117
|
-
showMoreResults: () => handleShowMoreResults(item.id, item.search_payload
|
|
1118
|
-
showLessResults: () => handleShowLessResults(item.id, item.search_payload
|
|
1165
|
+
showMoreResults: () => handleShowMoreResults(item.id, item.search_payload),
|
|
1166
|
+
showLessResults: () => handleShowLessResults(item.id, item.search_payload),
|
|
1119
1167
|
trackAnalyticsEvent: trackAnalyticsEvent,
|
|
1120
1168
|
currentPage: searchResultsPages[item.id] || 1,
|
|
1121
1169
|
isLoadingMore: loadingMoreResults.has(item.id)
|
|
@@ -1131,7 +1179,7 @@ const ChatWidget = exports.ChatWidget = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
1131
1179
|
handleFeedbackAction: handleFeedbackAction,
|
|
1132
1180
|
onReloadResults: handleReloadResults,
|
|
1133
1181
|
reloading: reloadLoadingIds.has(item.id),
|
|
1134
|
-
hasResults:
|
|
1182
|
+
hasResults: hasDiamonds
|
|
1135
1183
|
}));
|
|
1136
1184
|
});
|
|
1137
1185
|
})()), /*#__PURE__*/_react.default.createElement(LineView, null)), renderBottomContainer())));
|