@envive-ai/react-hooks 0.1.2 → 0.1.3
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/adapters/amplitude/index.cjs +13 -13
- package/dist/adapters/amplitude/index.js +10 -10
- package/dist/{api-B2euFL-5.cjs → api-BtzLHcfU.cjs} +27 -27
- package/dist/{api-XRr_lAG6.js → api-kpPTZhV9.js} +27 -27
- package/dist/application/config/index.cjs +1 -1
- package/dist/application/config/index.js +1 -1
- package/dist/application/models/graphql/index.cjs +12 -12
- package/dist/application/models/graphql/index.js +10 -10
- package/dist/application/models/guards/api/index.cjs +2 -2
- package/dist/application/models/guards/api/index.js +2 -2
- package/dist/application/models/index.cjs +54 -54
- package/dist/application/models/index.js +10 -10
- package/dist/application/models/utilityTypes/index.cjs +1 -1
- package/dist/application/models/utilityTypes/index.js +1 -1
- package/dist/application/models/variantInfo/index.cjs +1 -1
- package/dist/application/models/variantInfo/index.js +1 -1
- package/dist/application/service/customerService/index.cjs +2 -2
- package/dist/application/service/customerService/index.js +2 -2
- package/dist/application/service/index.cjs +82 -82
- package/dist/application/service/index.d.cts +1 -1
- package/dist/application/service/index.d.ts +1 -1
- package/dist/application/service/index.js +16 -16
- package/dist/application/utils/index.cjs +37 -37
- package/dist/application/utils/index.d.ts +1 -1
- package/dist/application/utils/index.js +10 -10
- package/dist/atoms/app/index.cjs +16 -16
- package/dist/atoms/app/index.d.cts +1 -1
- package/dist/atoms/app/index.d.ts +2 -2
- package/dist/atoms/app/index.js +10 -10
- package/dist/atoms/atomStore/index.cjs +1 -1
- package/dist/atoms/atomStore/index.js +1 -1
- package/dist/atoms/chat/index.cjs +40 -40
- package/dist/atoms/chat/index.d.cts +26 -26
- package/dist/atoms/chat/index.d.ts +28 -28
- package/dist/atoms/chat/index.js +10 -10
- package/dist/atoms/globalSearch/index.d.cts +5 -5
- package/dist/atoms/globalSearch/index.d.ts +5 -5
- package/dist/atoms/org/index.cjs +33 -33
- package/dist/atoms/org/index.d.cts +26 -26
- package/dist/atoms/org/index.d.ts +26 -26
- package/dist/atoms/org/index.js +11 -11
- package/dist/atoms/search/index.cjs +12 -12
- package/dist/atoms/search/index.d.cts +1 -1
- package/dist/atoms/search/index.d.ts +1 -1
- package/dist/atoms/search/index.js +12 -12
- package/dist/{bandolier-oMkFDJMF.cjs → bandolier-CQrxBHsk.cjs} +37 -37
- package/dist/{bandolier-C7PAIw02.js → bandolier-Di9DpZ8e.js} +12 -12
- package/dist/{carpe-C0ccKuR9.cjs → carpe-3NJOR-Rj.cjs} +23 -23
- package/dist/{carpe-DFc78_lJ.js → carpe-DmWKaIQq.js} +12 -12
- package/dist/{cdnService-DvDSpfVJ.js → cdnService-BNreZjqy.js} +1 -1
- package/dist/{cdnService-dJU3sHpF.cjs → cdnService-vLxePdrU.cjs} +1 -1
- package/dist/{api-CxGedDxj.cjs → chat-CCQMmhc1.cjs} +2807 -2807
- package/dist/{api-NJEaveju.js → chat-H6YcCS4I.js} +2774 -2774
- package/dist/contexts/index.cjs +19 -19
- package/dist/contexts/index.d.cts +3 -3
- package/dist/contexts/index.js +14 -14
- package/dist/{coterie-Cp9FAJTQ.cjs → coterie-D0UFsFC5.cjs} +17 -17
- package/dist/{coterie-BGT8hqFR.js → coterie-JblRmIZL.js} +12 -12
- package/dist/{customerService-CUyZzowx.js → customerService-C4wc0glQ.js} +1 -1
- package/dist/{customerService-DqPw_XKf.cjs → customerService-zsDlp7g2.cjs} +1 -1
- package/dist/default-C5ZTV8HA.cjs +4 -0
- package/dist/{default-wf_IORgo.js → default-DPv8m-eQ.js} +1 -1
- package/dist/{default-BAXPatxf.cjs → default-DRKBosow.cjs} +1 -1
- package/dist/default-ao0vRl0W.js +4 -0
- package/dist/{dreamlandBaby-DZvM81LQ.js → dreamlandBaby-CyS8oW8X.js} +12 -12
- package/dist/{dreamlandBaby-BzuMvUFS.cjs → dreamlandBaby-y7kSvwH2.cjs} +19 -19
- package/dist/events/index.cjs +1 -1
- package/dist/events/index.js +1 -1
- package/dist/{fiveCbd-DE-tDY3d.cjs → fiveCbd-CXVuIBiZ.cjs} +24 -24
- package/dist/{fiveCbd-HNBPqPtX.js → fiveCbd-Cyc3-Ab9.js} +12 -12
- package/dist/{forLoveAndLemons-BeVEBOiu.cjs → forLoveAndLemons-CxQS0USq.cjs} +14 -14
- package/dist/{forLoveAndLemons-BKmJJ9pq.js → forLoveAndLemons-D8mcgmdk.js} +12 -12
- package/dist/{greenpan-BX1viAZB.js → greenpan-JM6SHcqO.js} +12 -12
- package/dist/{greenpan-chd3aa5I.cjs → greenpan-eIzyxVsn.cjs} +21 -21
- package/dist/{grooveLife-CHot3rZw.js → grooveLife-BmsUc2cD.js} +12 -12
- package/dist/{grooveLife-DEob7rK0.cjs → grooveLife-KdTizVUn.cjs} +19 -19
- package/dist/{homegrownCannabis-CoIjcehi.cjs → homegrownCannabis-C0GDai4r.cjs} +18 -18
- package/dist/{homegrownCannabis-CwkS1qDA.js → homegrownCannabis-a9udocBT.js} +12 -12
- package/dist/hooks/index.cjs +36 -36
- package/dist/hooks/index.d.cts +7 -7
- package/dist/hooks/index.d.ts +4 -4
- package/dist/hooks/index.js +14 -14
- package/dist/{contexts-iAzSvZjb.cjs → hooks-DjOa7ihH.cjs} +195 -195
- package/dist/{contexts-DO75-Kmx.js → hooks-fneW8SWw.js} +93 -93
- package/dist/{index-BkhvV8RZ.d.cts → index-BQErGgfM.d.cts} +29 -29
- package/dist/{index-CzMrMKx-.d.ts → index-CnqHN_jz.d.ts} +29 -29
- package/dist/interceptors/index.cjs +11 -11
- package/dist/interceptors/index.js +11 -11
- package/dist/{jackArcher-bewC0q1T.cjs → jackArcher-B6OJ0N3a.cjs} +25 -25
- package/dist/{jackArcher-BA-pkB4A.js → jackArcher-B9fe4Hv8.js} +12 -12
- package/dist/{jordanCraig-B5k9nlAw.cjs → jordanCraig-0CB_m_ts.cjs} +65 -65
- package/dist/{jordanCraig-BsQ1mYbt.js → jordanCraig-DNm1iw1L.js} +12 -12
- package/dist/{kindredBravely-BxYkCpGY.js → kindredBravely-CZgt7DJA.js} +12 -12
- package/dist/{kindredBravely-DsN0fo3s.cjs → kindredBravely-KvYPbckZ.cjs} +19 -19
- package/dist/{kutFromTheKloth-BQTCu3ct.cjs → kutFromTheKloth-BxgtWZs9.cjs} +19 -19
- package/dist/{kutFromTheKloth-bukOQM3P.js → kutFromTheKloth-SmteSZjk.js} +12 -12
- package/dist/{larryAndSerges-bj7fgy9b.cjs → larryAndSerges-6O_u3L90.cjs} +15 -15
- package/dist/{larryAndSerges-D1ecaT5a.js → larryAndSerges-DO-zG8ES.js} +11 -11
- package/dist/{leapsAndRebounds-DhNpZETg.js → leapsAndRebounds-BK62AmXw.js} +12 -12
- package/dist/{leapsAndRebounds-BfneG_0c.cjs → leapsAndRebounds-gPsWVUmQ.cjs} +20 -20
- package/dist/{longevityrx-D0goIuX0.cjs → longevityrx-DjKbwJo3.cjs} +17 -17
- package/dist/{longevityrx-CnoGcw0w.js → longevityrx-eq5TeUcy.js} +12 -12
- package/dist/{lookOptic-C4afLPZP.cjs → lookOptic-BPPqms_j.cjs} +17 -17
- package/dist/{lookOptic-uJWIKpER.js → lookOptic-jRpBXQCN.js} +12 -12
- package/dist/{mantraBrand-DuwKHM26.js → mantraBrand-BZOZfkUK.js} +12 -12
- package/dist/{mantraBrand-8JUlYtCE.cjs → mantraBrand-Cp8zptkj.cjs} +30 -30
- package/dist/{medterra-DH067P-V.cjs → medterra-BHYCBgvQ.cjs} +27 -27
- package/dist/{medterra-BQec8rzn.js → medterra-CShe6CLY.js} +12 -12
- package/dist/{modells-DUFnLmAz.cjs → modells-DE7-gmjK.cjs} +23 -23
- package/dist/{modells-DAgLE2xo.js → modells-DFyJxNwT.js} +12 -12
- package/dist/{org-CnHL2I9B.cjs → org-Bkn6fl6I.cjs} +22 -22
- package/dist/{org-C11APG3v.js → org-CX8HFbc9.js} +20 -20
- package/dist/{pressedFloral-DVZVfOSQ.cjs → pressedFloral-BMkCVs8c.cjs} +26 -26
- package/dist/{pressedFloral-MdbuoRyA.js → pressedFloral-aK9br-LF.js} +12 -12
- package/dist/{search-bSYdOBhY.cjs → search-DtIFZeMA.cjs} +28 -28
- package/dist/{search-CvHb1M3S.js → search-eWwg8pNn.js} +5 -5
- package/dist/{search-filter-types-BsJjrxk0.d.ts → search-filter-types-ByJnFPc4.d.cts} +8 -8
- package/dist/{search-filter-types-CqaGK3nM.d.cts → search-filter-types-DPgeG8FS.d.ts} +8 -8
- package/dist/{skinPerfection-bGiYxq1i.js → skinPerfection-B9G6yLM2.js} +12 -12
- package/dist/{skinPerfection-BcEWICQN.cjs → skinPerfection-BBC1q65Z.cjs} +17 -17
- package/dist/{snapSupplements-BXSXTjqF.cjs → snapSupplements-D7hx6Kgj.cjs} +17 -17
- package/dist/{snapSupplements-D7hHhdC9.js → snapSupplements-DKvJl__T.js} +12 -12
- package/dist/{spanx-lUzP6Lva.cjs → spanx-D-ZKkxjM.cjs} +20 -20
- package/dist/{spanx-5-0yX3iK.js → spanx-yl7YfVrf.js} +12 -12
- package/dist/{spanxStaging-hreMR0MS.cjs → spanxStaging-CXeIg6zI.cjs} +26 -26
- package/dist/{spanxStaging-HglCMJag.js → spanxStaging-DzGXL9wD.js} +12 -12
- package/dist/{supergoop-CkjtuRck.cjs → supergoop-CSpDPOpl.cjs} +18 -18
- package/dist/{supergoop-C9DDT3lY.js → supergoop-D0UkuRiA.js} +11 -11
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.ts +2 -2
- package/dist/{types-BVsTRyxL.js → types-C3S1H4hl.js} +33 -33
- package/dist/{types-BUjohkXp.cjs → types-lcjuhDBt.cjs} +33 -33
- package/dist/{uniqueVintage-DIMGtYAU.cjs → uniqueVintage-DygVpCqU.cjs} +36 -36
- package/dist/{uniqueVintage-DPWA5Ed6.js → uniqueVintage-_n0FZFVj.js} +12 -12
- package/dist/{useMessageInterceptor-C2RZM-fo.js → useMessageInterceptor-BP6gzo8a.js} +3 -3
- package/dist/{useMessageInterceptor-B-P_rw73.cjs → useMessageInterceptor-BnUG2Pzt.cjs} +9 -9
- package/dist/{variant-XITncuI3.d.ts → variant-DH4zusMi.d.cts} +1 -1
- package/dist/{variant-BGjOVpY3.d.cts → variant-DTEqSBHd.d.ts} +3 -3
- package/dist/{venaCbd-B-znfAsl.js → venaCbd-BS0dvdBm.js} +12 -12
- package/dist/{venaCbd-BOwOtpOz.cjs → venaCbd-Pqg0bj-P.cjs} +21 -21
- package/dist/{westonJonBoucher-DCRagGu3.js → westonJonBoucher-CLw8Hy6u.js} +12 -12
- package/dist/{westonJonBoucher-CraTzRVt.cjs → westonJonBoucher-CeA0jwxe.cjs} +20 -20
- package/dist/{wineEnthusiast-Bv7umajk.js → wineEnthusiast-M9P18d1w.js} +12 -12
- package/dist/{wineEnthusiast-sVuATrq6.cjs → wineEnthusiast-gHBaQMbe.cjs} +20 -20
- package/dist/{wolfMattress-BUH-Rhov.js → wolfMattress-BQHjoQYu.js} +12 -12
- package/dist/{wolfMattress-DpVHIEnJ.cjs → wolfMattress-CdmN-Evm.cjs} +19 -19
- package/dist/{wolfTactical-Q14A1fpw.js → wolfTactical-Cc2ZLBRh.js} +12 -12
- package/dist/{wolfTactical-BcvF_sy-.cjs → wolfTactical-dObnPgAG.cjs} +20 -20
- package/package.json +1 -1
- package/src/contexts/systemSettingsContext.tsx +21 -8
- package/src/hooks/useSearch.tsx +6 -3
- package/src/types/search-filter-types.ts +7 -7
- package/dist/default-BR3225LZ.js +0 -4
- package/dist/default-DR6YjE9B.cjs +0 -4
- /package/dist/{atomStore-CeJm9Llb.cjs → atomStore-BNQyGmU_.cjs} +0 -0
- /package/dist/{atomStore-BFtpknLM.js → atomStore-TnLPtYns.js} +0 -0
- /package/dist/{enviveConfigContext-Dfr2VH6u.cjs → enviveConfigContext-Bs8kepnO.cjs} +0 -0
- /package/dist/{enviveConfigContext-CUGLpPGU.js → enviveConfigContext-CWVdVWKW.js} +0 -0
- /package/dist/{events-ClCDFK7t.js → events-DgFzlVJR.js} +0 -0
- /package/dist/{events-Da7gpmGv.cjs → events-bH-24eRW.cjs} +0 -0
- /package/dist/{logger-Dln20ans.cjs → logger-Be0NyKaY.cjs} +0 -0
- /package/dist/{logger-pdEEY8T2.js → logger-BexDfK3W.js} +0 -0
- /package/dist/{utilityTypes-C4h2wgAK.cjs → utilityTypes-DMdsI0DG.cjs} +0 -0
- /package/dist/{utilityTypes-BVikejDo.js → utilityTypes-UWdNHElu.js} +0 -0
- /package/dist/{variantInfo-CzhR5W6h.js → variantInfo-BTvC6CQh.js} +0 -0
- /package/dist/{variantInfo-CNRTY0gH.cjs → variantInfo-Cz2YXraO.cjs} +0 -0
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
-
const require_logger = require('./logger-
|
|
3
|
-
const
|
|
4
|
-
const require_types = require('./types-
|
|
5
|
-
const require_atomStore = require('./atomStore-
|
|
6
|
-
const require_org = require('./org-
|
|
7
|
-
const require_search = require('./search-
|
|
2
|
+
const require_logger = require('./logger-Be0NyKaY.cjs');
|
|
3
|
+
const require_chat = require('./chat-CCQMmhc1.cjs');
|
|
4
|
+
const require_types = require('./types-lcjuhDBt.cjs');
|
|
5
|
+
const require_atomStore = require('./atomStore-BNQyGmU_.cjs');
|
|
6
|
+
const require_org = require('./org-Bkn6fl6I.cjs');
|
|
7
|
+
const require_search = require('./search-DtIFZeMA.cjs');
|
|
8
8
|
const require_globalSearch = require('./globalSearch-hxbXekus.cjs');
|
|
9
|
-
const require_useMessageInterceptor = require('./useMessageInterceptor-
|
|
10
|
-
let __spiffy_ai_commerce_api_client = require("@spiffy-ai/commerce-api-client");
|
|
11
|
-
__spiffy_ai_commerce_api_client = require_chunk.__toESM(__spiffy_ai_commerce_api_client);
|
|
12
|
-
let jotai = require("jotai");
|
|
13
|
-
jotai = require_chunk.__toESM(jotai);
|
|
9
|
+
const require_useMessageInterceptor = require('./useMessageInterceptor-BnUG2Pzt.cjs');
|
|
14
10
|
let react = require("react");
|
|
15
11
|
react = require_chunk.__toESM(react);
|
|
12
|
+
let jotai = require("jotai");
|
|
13
|
+
jotai = require_chunk.__toESM(jotai);
|
|
14
|
+
let __spiffy_ai_commerce_api_client = require("@spiffy-ai/commerce-api-client");
|
|
15
|
+
__spiffy_ai_commerce_api_client = require_chunk.__toESM(__spiffy_ai_commerce_api_client);
|
|
16
16
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
17
17
|
react_jsx_runtime = require_chunk.__toESM(react_jsx_runtime);
|
|
18
18
|
let uuid = require("uuid");
|
|
@@ -43,18 +43,18 @@ const useBlockBackButton = (enabled, callback) => {
|
|
|
43
43
|
//#endregion
|
|
44
44
|
//#region src/hooks/useChatToggle.ts
|
|
45
45
|
const useChatToggle = () => {
|
|
46
|
-
const onToggle = (0, jotai.useSetAtom)(
|
|
47
|
-
const { isOpen } = (0, jotai.useAtomValue)(
|
|
46
|
+
const onToggle = (0, jotai.useSetAtom)(require_chat.chatOnToggleAtom);
|
|
47
|
+
const { isOpen } = (0, jotai.useAtomValue)(require_chat.chatAtom);
|
|
48
48
|
const toggle = (triggerLocation, triggerId) => {
|
|
49
|
-
if (!isOpen)
|
|
50
|
-
eventName:
|
|
49
|
+
if (!isOpen) require_chat.AmplitudeAdapter.trackEvent({
|
|
50
|
+
eventName: require_chat.SpiffyMetricsEventName.ChatComponentExpanded,
|
|
51
51
|
eventProps: { message_metadata: {
|
|
52
52
|
trigger_location: triggerLocation,
|
|
53
53
|
trigger_id: triggerId
|
|
54
54
|
} }
|
|
55
55
|
});
|
|
56
|
-
else
|
|
57
|
-
eventName:
|
|
56
|
+
else require_chat.AmplitudeAdapter.trackEvent({
|
|
57
|
+
eventName: require_chat.SpiffyMetricsEventName.ChatComponentCollapsed,
|
|
58
58
|
eventProps: { message_metadata: {
|
|
59
59
|
trigger_location: triggerLocation,
|
|
60
60
|
trigger_id: triggerId
|
|
@@ -189,7 +189,7 @@ var ShopifyUrlService = class ShopifyUrlService {
|
|
|
189
189
|
*/
|
|
190
190
|
static getPlpOrPdpId(extractor) {
|
|
191
191
|
if (extractor === "shopify-product-variant-id") {
|
|
192
|
-
const variantId =
|
|
192
|
+
const variantId = require_chat.parseHref(window.location.href)?.urlSearchParams?.get("variant");
|
|
193
193
|
if (!variantId) return ShopifyUrlService.getPlpOrPdpId("shopify-product-id");
|
|
194
194
|
return variantId;
|
|
195
195
|
}
|
|
@@ -285,10 +285,10 @@ var PageVariantService = class PageVariantService {
|
|
|
285
285
|
static {
|
|
286
286
|
this.getCachedUrlResolver = async (url) => {
|
|
287
287
|
const atomStore = require_atomStore.getAtomStore();
|
|
288
|
-
const cachedUrlResolver = atomStore.get(
|
|
288
|
+
const cachedUrlResolver = atomStore.get(require_chat.urlResolverAtom)?.[url];
|
|
289
289
|
if (cachedUrlResolver) return cachedUrlResolver;
|
|
290
|
-
const response = await
|
|
291
|
-
atomStore.set(
|
|
290
|
+
const response = await require_chat.api_default.resolveUrl(url);
|
|
291
|
+
atomStore.set(require_chat.urlResolverAtom, {
|
|
292
292
|
url,
|
|
293
293
|
response
|
|
294
294
|
});
|
|
@@ -332,28 +332,28 @@ var PageVariantService = class PageVariantService {
|
|
|
332
332
|
}
|
|
333
333
|
static {
|
|
334
334
|
this.userHasInteracted = (msgs) => {
|
|
335
|
-
if (msgs) return msgs.some((m) => m.some((msg) => msg.role ===
|
|
336
|
-
const { messages } = require_atomStore.getAtomStore().get(
|
|
337
|
-
return messages.some((m) => m.some((msg) => msg.role ===
|
|
335
|
+
if (msgs) return msgs.some((m) => m.some((msg) => msg.role === require_chat.MessageRole.User));
|
|
336
|
+
const { messages } = require_atomStore.getAtomStore().get(require_chat.chatAtom);
|
|
337
|
+
return messages.some((m) => m.some((msg) => msg.role === require_chat.MessageRole.User));
|
|
338
338
|
};
|
|
339
339
|
}
|
|
340
340
|
static {
|
|
341
341
|
this.userHasNotInteracted = (msgs) => {
|
|
342
|
-
if (msgs) return !msgs.some((m) => m.some((msg) => msg.role ===
|
|
343
|
-
return !require_atomStore.getAtomStore().get(
|
|
342
|
+
if (msgs) return !msgs.some((m) => m.some((msg) => msg.role === require_chat.MessageRole.User));
|
|
343
|
+
return !require_atomStore.getAtomStore().get(require_chat.chatAtom).messages.some((m) => m.some((msg) => msg.role === require_chat.MessageRole.User));
|
|
344
344
|
};
|
|
345
345
|
}
|
|
346
346
|
static {
|
|
347
347
|
this.isLoading = (msgs, responseStream) => {
|
|
348
348
|
if (msgs) return responseStream || !responseStream && msgs.length === 0;
|
|
349
|
-
const { responseStreaming, messages } = require_atomStore.getAtomStore().get(
|
|
349
|
+
const { responseStreaming, messages } = require_atomStore.getAtomStore().get(require_chat.chatAtom);
|
|
350
350
|
return responseStreaming || !responseStreaming && messages.length === 0;
|
|
351
351
|
};
|
|
352
352
|
}
|
|
353
353
|
static {
|
|
354
354
|
this.isProductComparison = (lastMsg) => {
|
|
355
|
-
if (lastMsg) return lastMsg?.filter((msg) => msg.type ===
|
|
356
|
-
return require_atomStore.getAtomStore().get(
|
|
355
|
+
if (lastMsg) return lastMsg?.filter((msg) => msg.type === require_chat.MessageType.Product).length === 2;
|
|
356
|
+
return require_atomStore.getAtomStore().get(require_chat.lastAssistantMessageAtom)?.filter((msg) => msg.type === require_chat.MessageType.Product).length === 2;
|
|
357
357
|
};
|
|
358
358
|
}
|
|
359
359
|
static {
|
|
@@ -378,13 +378,13 @@ var PageVariantService = class PageVariantService {
|
|
|
378
378
|
};
|
|
379
379
|
}
|
|
380
380
|
static checkFeatureGate(featureGate) {
|
|
381
|
-
return require_atomStore.getAtomStore().get(
|
|
381
|
+
return require_atomStore.getAtomStore().get(require_chat.featureFlagServiceAtom).isFeatureGateEnabled(featureGate);
|
|
382
382
|
}
|
|
383
383
|
static getCategory(extractor) {
|
|
384
384
|
if (extractor.type === require_types.CategoryExtractorType.VisitCategoryDefault) return extractor.value;
|
|
385
385
|
if (extractor.type === require_types.CategoryExtractorType.VisitCategoryMap) {
|
|
386
386
|
const matched = Object.entries(extractor.map).find(([, urls]) => {
|
|
387
|
-
const hostMatched =
|
|
387
|
+
const hostMatched = require_chat.StringUtils.findMatchingPattern(urls, window.location);
|
|
388
388
|
if (hostMatched) return hostMatched;
|
|
389
389
|
return urls.find((url) => window.location.pathname.includes(url));
|
|
390
390
|
});
|
|
@@ -446,13 +446,13 @@ var PageVariantService = class PageVariantService {
|
|
|
446
446
|
const variantInfo = await this.parsePageVariantConfig(pageVariantConfig, window.location.href);
|
|
447
447
|
const usesURLResolver = pageVariantConfig.variantTests.some((test$1) => test$1.testType === require_types.PageVariantTestType.UrlResolver);
|
|
448
448
|
if (!variantInfo || variantInfo.variant === "plp" && !variantInfo.plpId || variantInfo.variant === "pdp" && !variantInfo.productId || variantInfo.variant === "page_visit" && !variantInfo.url) return;
|
|
449
|
-
const appDetails = require_atomStore.getAtomStore().get(
|
|
449
|
+
const appDetails = require_atomStore.getAtomStore().get(require_chat.appDetailsAtom);
|
|
450
450
|
const visitEvent = createVisitUserEvent({ variantInfo });
|
|
451
451
|
if (!visitEvent) {
|
|
452
452
|
require_logger.logger_default.logWarn("spiffy-ai] no visitEvent found", variantInfo);
|
|
453
453
|
return;
|
|
454
454
|
}
|
|
455
|
-
if (!usesURLResolver) return await
|
|
455
|
+
if (!usesURLResolver) return await require_chat.api_default.isSupportedEvent({
|
|
456
456
|
id: (0, uuid.v4)(),
|
|
457
457
|
context: appDetails,
|
|
458
458
|
userEvent: visitEvent
|
|
@@ -566,15 +566,15 @@ const isUserEventEqual = (event1, event2) => {
|
|
|
566
566
|
return false;
|
|
567
567
|
};
|
|
568
568
|
const useDynamicVariants = () => {
|
|
569
|
-
const orgUIConfig = (0, jotai.useAtomValue)(
|
|
569
|
+
const orgUIConfig = (0, jotai.useAtomValue)(require_chat.orgUIConfigAtom);
|
|
570
570
|
const locationHrefRef = (0, react.useRef)(window.location.href);
|
|
571
|
-
const setVariantInfo = (0, jotai.useSetAtom)(
|
|
572
|
-
const setSupportedEvent = (0, jotai.useSetAtom)(
|
|
573
|
-
const queueUserEvent = (0, jotai.useSetAtom)(
|
|
571
|
+
const setVariantInfo = (0, jotai.useSetAtom)(require_chat.variantInfoAtom);
|
|
572
|
+
const setSupportedEvent = (0, jotai.useSetAtom)(require_chat.supportedEventAtom);
|
|
573
|
+
const queueUserEvent = (0, jotai.useSetAtom)(require_chat.queueUserEventAtom);
|
|
574
574
|
const [mostRecentUserEvent, setMostRecentUserEvent] = (0, react.useState)(null);
|
|
575
575
|
const orgPageConfig = (0, jotai.useAtomValue)(require_org.orgPageConfigAtom);
|
|
576
576
|
const debouncedFunc = (0, react.useRef)(null);
|
|
577
|
-
const [hasParsedVariantInfo, setHasParsedVariantInfo] = (0, jotai.useAtom)(
|
|
577
|
+
const [hasParsedVariantInfo, setHasParsedVariantInfo] = (0, jotai.useAtom)(require_chat.hasParsedVariantInfoAtom);
|
|
578
578
|
const animationFrameRef = (0, react.useRef)(null);
|
|
579
579
|
const isBeforeUnload = (0, react.useRef)(false);
|
|
580
580
|
const handleLocationChange = () => {
|
|
@@ -604,8 +604,8 @@ const useDynamicVariants = () => {
|
|
|
604
604
|
const supportedEvent = await PageVariantService.checkSupportedEvent(pageVariantConfig);
|
|
605
605
|
console.log("useDynamicVariants - supportedEvent", supportedEvent);
|
|
606
606
|
setSupportedEvent(supportedEvent);
|
|
607
|
-
|
|
608
|
-
eventName:
|
|
607
|
+
require_chat.AmplitudeAdapter.trackEvent({
|
|
608
|
+
eventName: require_chat.SpiffyMetricsEventName.SupportedEvent,
|
|
609
609
|
eventProps: { ...supportedEvent }
|
|
610
610
|
});
|
|
611
611
|
} else setHasParsedVariantInfo(false);
|
|
@@ -664,7 +664,7 @@ const useDynamicVariants = () => {
|
|
|
664
664
|
//#region src/hooks/useElementObserver.ts
|
|
665
665
|
const useElementObserver = (selector) => {
|
|
666
666
|
const INITIAL_RENDER_STATE = true;
|
|
667
|
-
const eoRef = (0, react.useRef)(
|
|
667
|
+
const eoRef = (0, react.useRef)(require_chat.DOMObserver.add(selector));
|
|
668
668
|
const [renderBlocked, setRenderBlocked] = (0, react.useState)(INITIAL_RENDER_STATE);
|
|
669
669
|
/**
|
|
670
670
|
* Fired every time the HTML element changes.
|
|
@@ -806,8 +806,8 @@ const useElementObserver = (selector) => {
|
|
|
806
806
|
(0, react.useEffect)(() => {
|
|
807
807
|
eoRef.current.init();
|
|
808
808
|
eoRef.current.registerOnReset(() => setRenderBlocked(INITIAL_RENDER_STATE));
|
|
809
|
-
|
|
810
|
-
return () =>
|
|
809
|
+
require_chat.DOMObserver.observe();
|
|
810
|
+
return () => require_chat.DOMObserver.remove(selector);
|
|
811
811
|
}, [selector.getPattern()]);
|
|
812
812
|
return {
|
|
813
813
|
targetNode: eoRef.current.getNode(),
|
|
@@ -837,7 +837,7 @@ const useElementObserver = (selector) => {
|
|
|
837
837
|
const useFileUpload = () => {
|
|
838
838
|
const fileInputRef = (0, react.useRef)(null);
|
|
839
839
|
const [attachment, setAttachment] = (0, jotai.useAtom)(require_org.customerServiceAttachment);
|
|
840
|
-
const customerServiceImpl = (0, jotai.useAtomValue)(
|
|
840
|
+
const customerServiceImpl = (0, jotai.useAtomValue)(require_chat.orgCustomerServiceService);
|
|
841
841
|
const [error, setError] = (0, react.useState)("");
|
|
842
842
|
const isValidFile = (file) => {
|
|
843
843
|
const maxSize = customerServiceImpl.maxfileUploadSize;
|
|
@@ -981,7 +981,7 @@ const useGrabAndScroll = (enabled, chunkWidth, speed = 400, offset = 0) => {
|
|
|
981
981
|
* This hook hides/shows elements that could overlap with the chat when the chat is opened/closed.
|
|
982
982
|
*/
|
|
983
983
|
const useHideElements = () => {
|
|
984
|
-
const orgUIConfig = (0, jotai.useAtomValue)(
|
|
984
|
+
const orgUIConfig = (0, jotai.useAtomValue)(require_chat.orgUIConfigAtom);
|
|
985
985
|
const [hasRegisteredEventListeners, setHasRegisteredEventListeners] = (0, react.useState)(false);
|
|
986
986
|
const elementObservers = (0, react.useRef)([]);
|
|
987
987
|
const hideElements = (elements) => {
|
|
@@ -997,12 +997,12 @@ const useHideElements = () => {
|
|
|
997
997
|
(0, react.useEffect)(() => {
|
|
998
998
|
elementObservers.current = [];
|
|
999
999
|
orgUIConfig.hiddenElementSelectors?.forEach((selector) => {
|
|
1000
|
-
elementObservers.current.push(
|
|
1000
|
+
elementObservers.current.push(require_chat.DOMObserver.add(require_chat.SelectorFactory.query(selector)));
|
|
1001
1001
|
});
|
|
1002
1002
|
elementObservers.current.forEach((element) => {
|
|
1003
1003
|
element.init();
|
|
1004
1004
|
});
|
|
1005
|
-
|
|
1005
|
+
require_chat.DOMObserver.observe();
|
|
1006
1006
|
return () => {
|
|
1007
1007
|
elementObservers.current.forEach((element) => {
|
|
1008
1008
|
element.destroy();
|
|
@@ -1012,16 +1012,16 @@ const useHideElements = () => {
|
|
|
1012
1012
|
}, [orgUIConfig.hiddenElementSelectors]);
|
|
1013
1013
|
(0, react.useEffect)(() => {
|
|
1014
1014
|
if (elementObservers.current.length > 0 && !hasRegisteredEventListeners) {
|
|
1015
|
-
require_logger.logger_default.logDebug(`Registering ${
|
|
1016
|
-
window.addEventListener(
|
|
1017
|
-
require_logger.logger_default.logDebug(`Registering ${
|
|
1018
|
-
window.addEventListener(
|
|
1015
|
+
require_logger.logger_default.logDebug(`Registering ${require_chat.SpiffyEventName.WidgetOpen} event for ${elementObservers.current.length} elements`);
|
|
1016
|
+
window.addEventListener(require_chat.SpiffyEventName.WidgetOpen, () => hideElements(elementObservers.current));
|
|
1017
|
+
require_logger.logger_default.logDebug(`Registering ${require_chat.SpiffyEventName.WidgetClose} event for ${elementObservers.current.length} elements`);
|
|
1018
|
+
window.addEventListener(require_chat.SpiffyEventName.WidgetClose, () => showElements(elementObservers.current));
|
|
1019
1019
|
setHasRegisteredEventListeners(true);
|
|
1020
1020
|
}
|
|
1021
1021
|
return () => {
|
|
1022
1022
|
if (elementObservers.current.length > 0 && hasRegisteredEventListeners) {
|
|
1023
|
-
window.removeEventListener(
|
|
1024
|
-
window.removeEventListener(
|
|
1023
|
+
window.removeEventListener(require_chat.SpiffyEventName.WidgetOpen, () => hideElements(elementObservers.current));
|
|
1024
|
+
window.removeEventListener(require_chat.SpiffyEventName.WidgetClose, () => showElements(elementObservers.current));
|
|
1025
1025
|
setHasRegisteredEventListeners(false);
|
|
1026
1026
|
}
|
|
1027
1027
|
};
|
|
@@ -6274,7 +6274,7 @@ var ShopifyImageResolver = class extends ImageResolver {
|
|
|
6274
6274
|
}
|
|
6275
6275
|
};
|
|
6276
6276
|
const useImageResolver = () => {
|
|
6277
|
-
const orgUIConfig = (0, jotai.useAtomValue)(
|
|
6277
|
+
const orgUIConfig = (0, jotai.useAtomValue)(require_chat.orgUIConfigAtom);
|
|
6278
6278
|
const resolve = (image, size) => {
|
|
6279
6279
|
if (image && size) return MerchantImageResolver.get(orgUIConfig.shortName)?.resolve(image, size) || image;
|
|
6280
6280
|
return image;
|
|
@@ -6343,7 +6343,7 @@ const useMessageFilter = () => {
|
|
|
6343
6343
|
if (!skipFilter) {
|
|
6344
6344
|
const idx = findMessageIndex({
|
|
6345
6345
|
msgs: deduplicatedMsgs,
|
|
6346
|
-
type:
|
|
6346
|
+
type: require_chat.MessageType.Separator
|
|
6347
6347
|
});
|
|
6348
6348
|
return removePreviousDiscussions(deduplicatedMsgs, idx);
|
|
6349
6349
|
}
|
|
@@ -6389,7 +6389,7 @@ const useMessageScrollObserver = (boxRef, scrollRef, onScrollChange) => {
|
|
|
6389
6389
|
//#endregion
|
|
6390
6390
|
//#region src/hooks/useSearch.tsx
|
|
6391
6391
|
const useSearch = () => {
|
|
6392
|
-
const orgUIConfig = (0, jotai.useAtomValue)(
|
|
6392
|
+
const orgUIConfig = (0, jotai.useAtomValue)(require_chat.orgUIConfigAtom);
|
|
6393
6393
|
const { data: searchData, loading: isLoadingSearch } = (0, jotai.useAtomValue)(require_search.searchAtom);
|
|
6394
6394
|
const productList = (0, jotai.useAtomValue)(require_search.filteredSearchProductsAtom);
|
|
6395
6395
|
const performSearch = (0, jotai.useSetAtom)(require_search.performSearchAtom);
|
|
@@ -6452,8 +6452,8 @@ const useSearch = () => {
|
|
|
6452
6452
|
return `Filter & Sort (${selectedCount})`;
|
|
6453
6453
|
}, [filters]);
|
|
6454
6454
|
const handleToggleDynamicFilter = (0, react.useCallback)(({ filter: filter$1, dynamicFilterDisplayName }) => {
|
|
6455
|
-
|
|
6456
|
-
eventName:
|
|
6455
|
+
require_chat.AmplitudeAdapter.trackEvent({
|
|
6456
|
+
eventName: require_chat.SpiffyMetricsEventName.SearchFilterClicked,
|
|
6457
6457
|
eventProps: {
|
|
6458
6458
|
filterType: "Dynamic",
|
|
6459
6459
|
filterValue: filter$1,
|
|
@@ -6467,10 +6467,10 @@ const useSearch = () => {
|
|
|
6467
6467
|
}, [removeFilter]);
|
|
6468
6468
|
const handleSubmitSearch = (0, react.useCallback)(async () => {
|
|
6469
6469
|
if (searchText.trim()) {
|
|
6470
|
-
|
|
6471
|
-
eventName:
|
|
6470
|
+
require_chat.AmplitudeAdapter.trackEvent({
|
|
6471
|
+
eventName: require_chat.SpiffyMetricsEventName.SearchQuerySubmitted,
|
|
6472
6472
|
eventProps: {
|
|
6473
|
-
searchOrigin:
|
|
6473
|
+
searchOrigin: require_chat.SpiffyWidgets.SearchResults,
|
|
6474
6474
|
queryText: searchText.trim()
|
|
6475
6475
|
},
|
|
6476
6476
|
alsoSendToGoogleAnalytics: true
|
|
@@ -6516,9 +6516,9 @@ const useSearch = () => {
|
|
|
6516
6516
|
handleSubmitSearch
|
|
6517
6517
|
]);
|
|
6518
6518
|
const handleSearchInputChange = (newValue) => {
|
|
6519
|
-
if (newValue.length === 1)
|
|
6520
|
-
eventName:
|
|
6521
|
-
eventProps: { searchOrigin:
|
|
6519
|
+
if (newValue.length === 1) require_chat.AmplitudeAdapter.trackEvent({
|
|
6520
|
+
eventName: require_chat.SpiffyMetricsEventName.SearchInputStarted,
|
|
6521
|
+
eventProps: { searchOrigin: require_chat.SpiffyWidgets.SearchResults }
|
|
6522
6522
|
});
|
|
6523
6523
|
setSearchText(newValue);
|
|
6524
6524
|
setIsDirty(true);
|
|
@@ -6526,8 +6526,8 @@ const useSearch = () => {
|
|
|
6526
6526
|
const handleSelectFilterItem = (0, react.useCallback)(({ filterId, filterItemId, isSelected, displayName }) => {
|
|
6527
6527
|
if (filterId === "sort") {
|
|
6528
6528
|
const newSort = filterItemId;
|
|
6529
|
-
|
|
6530
|
-
eventName:
|
|
6529
|
+
require_chat.AmplitudeAdapter.trackEvent({
|
|
6530
|
+
eventName: require_chat.SpiffyMetricsEventName.SearchSortClicked,
|
|
6531
6531
|
eventProps: {
|
|
6532
6532
|
sortType: newSort,
|
|
6533
6533
|
queryText: searchText
|
|
@@ -6536,8 +6536,8 @@ const useSearch = () => {
|
|
|
6536
6536
|
setProductSorting(newSort);
|
|
6537
6537
|
} else if (!isSelected) removeFilter(`${filterId}:${filterItemId}`);
|
|
6538
6538
|
else {
|
|
6539
|
-
|
|
6540
|
-
eventName:
|
|
6539
|
+
require_chat.AmplitudeAdapter.trackEvent({
|
|
6540
|
+
eventName: require_chat.SpiffyMetricsEventName.SearchFilterClicked,
|
|
6541
6541
|
eventProps: {
|
|
6542
6542
|
filterType: "Static",
|
|
6543
6543
|
filterCategory: filterId,
|
|
@@ -6557,10 +6557,10 @@ const useSearch = () => {
|
|
|
6557
6557
|
setProductSorting(require_search.ProductSorting.FEATURED);
|
|
6558
6558
|
clearFilters();
|
|
6559
6559
|
}, [setProductSorting, clearFilters]);
|
|
6560
|
-
useTrackComponentVisibleEvent(
|
|
6560
|
+
useTrackComponentVisibleEvent(require_chat.SpiffyWidgets.SearchResults, searchResultsRef, {}, require_chat.SpiffyMetricsEventName.SearchComponentVisible);
|
|
6561
6561
|
(0, react.useEffect)(() => {
|
|
6562
|
-
if (productList.length > 0)
|
|
6563
|
-
eventName:
|
|
6562
|
+
if (productList.length > 0) require_chat.AmplitudeAdapter.trackEvent({
|
|
6563
|
+
eventName: require_chat.SpiffyMetricsEventName.SearchResultsViewed,
|
|
6564
6564
|
eventProps: {
|
|
6565
6565
|
queryText: searchText,
|
|
6566
6566
|
resultsCount: productList.length
|
|
@@ -6757,90 +6757,6 @@ const useSnapControl = ({ animationKey, animation, height, unit, snaps, initSnap
|
|
|
6757
6757
|
};
|
|
6758
6758
|
};
|
|
6759
6759
|
|
|
6760
|
-
//#endregion
|
|
6761
|
-
//#region src/hooks/useSystemSettingsContext.ts
|
|
6762
|
-
const useSystemSettingsContext = () => {
|
|
6763
|
-
const context = (0, react.useContext)(SystemSettingsContext);
|
|
6764
|
-
if (!context) throw new Error("useSystemSettingsContext must be used within a SystemSettingsContextProvider");
|
|
6765
|
-
return { ...context };
|
|
6766
|
-
};
|
|
6767
|
-
|
|
6768
|
-
//#endregion
|
|
6769
|
-
//#region src/hooks/useTrackComponentVisibleEvent.ts
|
|
6770
|
-
/**
|
|
6771
|
-
* Tracks a component and logs an event to Amplitude when the component is visible.
|
|
6772
|
-
*
|
|
6773
|
-
* @param component - The component to track.
|
|
6774
|
-
* @param element - The element to track visibility of.
|
|
6775
|
-
* @param eventProps - Additional properties to include with the event.
|
|
6776
|
-
* @param eventName - The Amplitude event name to track (defaults to ChatComponentVisible).
|
|
6777
|
-
*/
|
|
6778
|
-
const useTrackComponentVisibleEvent = (component, element, eventProps, eventName = require_api.SpiffyMetricsEventName.ChatComponentVisible) => {
|
|
6779
|
-
const isVisible = useIntersection(element, "0px");
|
|
6780
|
-
const hasTrackedEvent = (0, react.useRef)(false);
|
|
6781
|
-
const componentProps = (() => {
|
|
6782
|
-
if (eventName === require_api.SpiffyMetricsEventName.ChatComponentVisible) return {
|
|
6783
|
-
chat_component: component,
|
|
6784
|
-
...eventProps
|
|
6785
|
-
};
|
|
6786
|
-
if (eventName === require_api.SpiffyMetricsEventName.SearchComponentVisible) return {
|
|
6787
|
-
search_component: component,
|
|
6788
|
-
...eventProps
|
|
6789
|
-
};
|
|
6790
|
-
return {
|
|
6791
|
-
component,
|
|
6792
|
-
...eventProps
|
|
6793
|
-
};
|
|
6794
|
-
})();
|
|
6795
|
-
(0, react.useEffect)(() => {
|
|
6796
|
-
if (isVisible && !hasTrackedEvent.current) {
|
|
6797
|
-
require_api.AmplitudeAdapter.trackEvent({
|
|
6798
|
-
eventName,
|
|
6799
|
-
eventProps: componentProps
|
|
6800
|
-
});
|
|
6801
|
-
hasTrackedEvent.current = true;
|
|
6802
|
-
}
|
|
6803
|
-
}, [
|
|
6804
|
-
isVisible,
|
|
6805
|
-
component,
|
|
6806
|
-
eventProps,
|
|
6807
|
-
eventName,
|
|
6808
|
-
componentProps
|
|
6809
|
-
]);
|
|
6810
|
-
};
|
|
6811
|
-
|
|
6812
|
-
//#endregion
|
|
6813
|
-
//#region src/hooks/useUpdateAnalyticsProps.ts
|
|
6814
|
-
/**
|
|
6815
|
-
* Updates the default analytics properties whenever the variant info changes. This hook also
|
|
6816
|
-
* triggers any events that should be sent once per page visit.
|
|
6817
|
-
*/
|
|
6818
|
-
const useUpdateAnalyticsProps = () => {
|
|
6819
|
-
const variantInfo = (0, jotai.useAtomValue)(require_api.variantInfoAtom);
|
|
6820
|
-
const amplitudeAdapterRef = (0, react.useRef)(null);
|
|
6821
|
-
const hasInitialized = (0, react.useRef)(false);
|
|
6822
|
-
const hasParsedVariantInfo = (0, jotai.useAtomValue)(require_api.hasParsedVariantInfoAtom);
|
|
6823
|
-
(0, react.useEffect)(() => {
|
|
6824
|
-
if (!amplitudeAdapterRef.current) amplitudeAdapterRef.current = require_api.AmplitudeAdapter.getSingletonInstanceOf();
|
|
6825
|
-
const variantInfoWithPrefix = Object.fromEntries(Object.entries(variantInfo).map(([key, value]) => [`variantInfo.${key}`, value]));
|
|
6826
|
-
const defaultEventProperties = {
|
|
6827
|
-
page_variant: variantInfo.variant,
|
|
6828
|
-
...variantInfoWithPrefix
|
|
6829
|
-
};
|
|
6830
|
-
if (variantInfo.variant === "pdp") defaultEventProperties.product_id = variantInfo.productId;
|
|
6831
|
-
if (variantInfo.variant === "plp") defaultEventProperties.plp_id = variantInfo.plpId;
|
|
6832
|
-
if (variantInfo.variant === "page_visit") {
|
|
6833
|
-
defaultEventProperties.page_visit_category = variantInfo.pageVisitCategory;
|
|
6834
|
-
defaultEventProperties.page_visit_url = variantInfo.url;
|
|
6835
|
-
}
|
|
6836
|
-
amplitudeAdapterRef.current?.setSupplementalDefaultProps(defaultEventProperties);
|
|
6837
|
-
if (!hasInitialized.current && hasParsedVariantInfo) {
|
|
6838
|
-
require_api.AmplitudeAdapter.trackEvent({ eventName: require_api.SpiffyMetricsEventName.BundleLoaded });
|
|
6839
|
-
hasInitialized.current = true;
|
|
6840
|
-
}
|
|
6841
|
-
}, [variantInfo, hasParsedVariantInfo]);
|
|
6842
|
-
};
|
|
6843
|
-
|
|
6844
6760
|
//#endregion
|
|
6845
6761
|
//#region src/contexts/chatContext.tsx
|
|
6846
6762
|
/**
|
|
@@ -6851,7 +6767,7 @@ const useUpdateAnalyticsProps = () => {
|
|
|
6851
6767
|
*/
|
|
6852
6768
|
const recordAssistantResponse = (startTimeMs, payload) => {
|
|
6853
6769
|
const atomStore = require_atomStore.getAtomStore();
|
|
6854
|
-
const chatState = atomStore.get(
|
|
6770
|
+
const chatState = atomStore.get(require_chat.chatAtom);
|
|
6855
6771
|
const chatSearchState = atomStore.get(require_search.chatSearchStateAtom);
|
|
6856
6772
|
const searchProducts = atomStore.get(require_search.chatSearchProducts);
|
|
6857
6773
|
const searchProductsSort = atomStore.get(require_search.chatSearchProductSortingAtom);
|
|
@@ -6868,9 +6784,9 @@ const recordAssistantResponse = (startTimeMs, payload) => {
|
|
|
6868
6784
|
user_query: userQueryProperty
|
|
6869
6785
|
};
|
|
6870
6786
|
if (chatState.replyEventCategory === __spiffy_ai_commerce_api_client.UserEventCategory.FormSubmitted) {
|
|
6871
|
-
const lastAssistantTurn = chatState.messages.filter((turn) => turn.length > 0 && turn[0].role ===
|
|
6787
|
+
const lastAssistantTurn = chatState.messages.filter((turn) => turn.length > 0 && turn[0].role === require_chat.MessageRole.Assistant).pop();
|
|
6872
6788
|
const formType = payload.userEvents?.find((event) => event.category === __spiffy_ai_commerce_api_client.UserEventCategory.FormSubmitted)?.attributes.formType;
|
|
6873
|
-
const formStatus = lastAssistantTurn?.some((response) => response.type ===
|
|
6789
|
+
const formStatus = lastAssistantTurn?.some((response) => response.type === require_chat.MessageType.Order);
|
|
6874
6790
|
eventProps.form_submitted_attributes = {
|
|
6875
6791
|
form_type: formType,
|
|
6876
6792
|
status: formStatus ? "success" : "failed"
|
|
@@ -6880,8 +6796,8 @@ const recordAssistantResponse = (startTimeMs, payload) => {
|
|
|
6880
6796
|
eventProps.search_products_returned = searchProducts.length;
|
|
6881
6797
|
eventProps.search_products_sort_type = searchProductsSort;
|
|
6882
6798
|
}
|
|
6883
|
-
|
|
6884
|
-
eventName:
|
|
6799
|
+
require_chat.AmplitudeAdapter.trackEvent({
|
|
6800
|
+
eventName: require_chat.SpiffyMetricsEventName.ChatAssistantResponse,
|
|
6885
6801
|
eventProps
|
|
6886
6802
|
});
|
|
6887
6803
|
};
|
|
@@ -6891,7 +6807,7 @@ const updateMessageState = (message, lastMessage, setMessages) => {
|
|
|
6891
6807
|
setMessages((prev) => [...prev, [message]]);
|
|
6892
6808
|
return message;
|
|
6893
6809
|
}
|
|
6894
|
-
if (lastMessage.type ===
|
|
6810
|
+
if (lastMessage.type === require_chat.MessageType.Text && message.type === require_chat.MessageType.Text) {
|
|
6895
6811
|
const newMessage = {
|
|
6896
6812
|
...lastMessage,
|
|
6897
6813
|
metadata: {
|
|
@@ -6912,8 +6828,8 @@ const handleStreamingError = (_error, setRequestFailure, setMessages) => {
|
|
|
6912
6828
|
setRequestFailure(true);
|
|
6913
6829
|
setMessages((prev) => [...prev, [{
|
|
6914
6830
|
id: (0, uuid.v4)(),
|
|
6915
|
-
role:
|
|
6916
|
-
type:
|
|
6831
|
+
role: require_chat.MessageRole.Assistant,
|
|
6832
|
+
type: require_chat.MessageType.Text,
|
|
6917
6833
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
6918
6834
|
metadata: { content: "I'm sorry! I'm having trouble right now. Please refresh the page or try again in a moment." }
|
|
6919
6835
|
}]]);
|
|
@@ -6923,9 +6839,9 @@ const processStreamingResponse = async (stream, messageInterceptor, handleSearch
|
|
|
6923
6839
|
let hasSearchResults = false;
|
|
6924
6840
|
for await (const response of stream) try {
|
|
6925
6841
|
if (messageInterceptor.intercept(response)) return { hasSearchResults };
|
|
6926
|
-
const message =
|
|
6842
|
+
const message = require_chat.messageFromResponse(response);
|
|
6927
6843
|
if (!message) throw new Error("Failed to transform API response to client message");
|
|
6928
|
-
if (message.type ===
|
|
6844
|
+
if (message.type === require_chat.MessageType.ProductSearch) {
|
|
6929
6845
|
handleSearchResults(message);
|
|
6930
6846
|
hasSearchResults = true;
|
|
6931
6847
|
setSearchIsLoading(false);
|
|
@@ -6940,31 +6856,31 @@ const processStreamingResponse = async (stream, messageInterceptor, handleSearch
|
|
|
6940
6856
|
return { hasSearchResults };
|
|
6941
6857
|
};
|
|
6942
6858
|
const ChatContextProvider = ({ children }) => {
|
|
6943
|
-
const logPerfMetric = (0, jotai.useSetAtom)(
|
|
6859
|
+
const logPerfMetric = (0, jotai.useSetAtom)(require_chat.logPerfMetricAtom);
|
|
6944
6860
|
const [widgetInitialized, setWidgetInitialized] = (0, react.useState)(false);
|
|
6945
|
-
const setUserHasReplied = (0, jotai.useSetAtom)(
|
|
6946
|
-
const [messages, setMessages] = (0, jotai.useAtom)(
|
|
6947
|
-
const setUserEvents = (0, jotai.useSetAtom)(
|
|
6948
|
-
const setSuggestions = (0, jotai.useSetAtom)(
|
|
6949
|
-
const [suggestionsLoading, setSuggestionsLoading] = (0, jotai.useAtom)(
|
|
6950
|
-
const [responseStreaming, setResponseStreaming] = (0, jotai.useAtom)(
|
|
6951
|
-
const setRequestFailure = (0, jotai.useSetAtom)(
|
|
6952
|
-
const userEvents = (0, jotai.useAtomValue)(
|
|
6953
|
-
const userQueueEventCount = (0, jotai.useAtomValue)(
|
|
6954
|
-
const markUserEventsProcessed = (0, jotai.useSetAtom)(
|
|
6955
|
-
const clearUserEventQueue = (0, jotai.useSetAtom)(
|
|
6956
|
-
const userId = (0, jotai.useAtomValue)(
|
|
6957
|
-
const chatId = (0, jotai.useAtomValue)(
|
|
6958
|
-
const supportedEvent = (0, jotai.useAtomValue)(
|
|
6959
|
-
const orgId = (0, jotai.useAtomValue)(
|
|
6960
|
-
const variantInfo = (0, jotai.useAtomValue)(
|
|
6861
|
+
const setUserHasReplied = (0, jotai.useSetAtom)(require_chat.userHasRepliedAtom);
|
|
6862
|
+
const [messages, setMessages] = (0, jotai.useAtom)(require_chat.messagesAtom);
|
|
6863
|
+
const setUserEvents = (0, jotai.useSetAtom)(require_chat.userEventsAtom);
|
|
6864
|
+
const setSuggestions = (0, jotai.useSetAtom)(require_chat.suggestionsAtom);
|
|
6865
|
+
const [suggestionsLoading, setSuggestionsLoading] = (0, jotai.useAtom)(require_chat.suggestionsLoadingAtom);
|
|
6866
|
+
const [responseStreaming, setResponseStreaming] = (0, jotai.useAtom)(require_chat.responseStreamingAtom);
|
|
6867
|
+
const setRequestFailure = (0, jotai.useSetAtom)(require_chat.requestFailureAtom);
|
|
6868
|
+
const userEvents = (0, jotai.useAtomValue)(require_chat.userEventQueueAtom);
|
|
6869
|
+
const userQueueEventCount = (0, jotai.useAtomValue)(require_chat.userQueueEventCountAtom);
|
|
6870
|
+
const markUserEventsProcessed = (0, jotai.useSetAtom)(require_chat.processUserEventAtom);
|
|
6871
|
+
const clearUserEventQueue = (0, jotai.useSetAtom)(require_chat.clearUserEventAtom);
|
|
6872
|
+
const userId = (0, jotai.useAtomValue)(require_chat.userIdAtom);
|
|
6873
|
+
const chatId = (0, jotai.useAtomValue)(require_chat.chatIdAtom);
|
|
6874
|
+
const supportedEvent = (0, jotai.useAtomValue)(require_chat.supportedEventAtom);
|
|
6875
|
+
const orgId = (0, jotai.useAtomValue)(require_chat.orgIdAtom);
|
|
6876
|
+
const variantInfo = (0, jotai.useAtomValue)(require_chat.variantInfoAtom);
|
|
6961
6877
|
const settingsContext = useSystemSettingsContext();
|
|
6962
6878
|
const messageInterceptor = require_useMessageInterceptor.useMessageInterceptor();
|
|
6963
6879
|
const handleSearchResults = (0, jotai.useSetAtom)(require_search.handleSearchResultsAtom);
|
|
6964
6880
|
const setSearchIsLoading = (0, jotai.useSetAtom)(require_search.chatSearchIsLoadingAtom);
|
|
6965
6881
|
const getStreamingResponses = (0, react.useCallback)(async (payload) => {
|
|
6966
|
-
logPerfMetric(
|
|
6967
|
-
const stream =
|
|
6882
|
+
logPerfMetric(require_chat.PerfMetricsEvents.FirstResponseStarted);
|
|
6883
|
+
const stream = require_chat.api_default.getNextResponseStreaming(payload);
|
|
6968
6884
|
try {
|
|
6969
6885
|
setRequestFailure(false);
|
|
6970
6886
|
const { hasSearchResults } = await processStreamingResponse(stream, messageInterceptor, handleSearchResults, setMessages, setSearchIsLoading, chatId);
|
|
@@ -6973,7 +6889,7 @@ const ChatContextProvider = ({ children }) => {
|
|
|
6973
6889
|
handleStreamingError(e, setRequestFailure, setMessages);
|
|
6974
6890
|
throw e;
|
|
6975
6891
|
} finally {
|
|
6976
|
-
logPerfMetric(
|
|
6892
|
+
logPerfMetric(require_chat.PerfMetricsEvents.FirstResponseCompleted);
|
|
6977
6893
|
}
|
|
6978
6894
|
}, [
|
|
6979
6895
|
logPerfMetric,
|
|
@@ -6985,17 +6901,17 @@ const ChatContextProvider = ({ children }) => {
|
|
|
6985
6901
|
chatId
|
|
6986
6902
|
]);
|
|
6987
6903
|
const getSuggestions = (0, react.useCallback)(async () => {
|
|
6988
|
-
logPerfMetric(
|
|
6904
|
+
logPerfMetric(require_chat.PerfMetricsEvents.FirstSuggestionsStarted);
|
|
6989
6905
|
setSuggestionsLoading(true);
|
|
6990
6906
|
setSuggestions([]);
|
|
6991
|
-
const payloadWithoutAppLoaded =
|
|
6907
|
+
const payloadWithoutAppLoaded = require_chat.createResponsePayload({
|
|
6992
6908
|
userEvents: [],
|
|
6993
6909
|
generationParams: settingsContext.generationParams
|
|
6994
6910
|
});
|
|
6995
|
-
const response = await
|
|
6911
|
+
const response = await require_chat.api_default.getNextSuggestions(payloadWithoutAppLoaded);
|
|
6996
6912
|
setSuggestions(response.sort((a, b) => a.content.length - b.content.length));
|
|
6997
6913
|
setSuggestionsLoading(false);
|
|
6998
|
-
logPerfMetric(
|
|
6914
|
+
logPerfMetric(require_chat.PerfMetricsEvents.FirstSuggestionsCompleted);
|
|
6999
6915
|
}, [
|
|
7000
6916
|
logPerfMetric,
|
|
7001
6917
|
setSuggestionsLoading,
|
|
@@ -7004,7 +6920,7 @@ const ChatContextProvider = ({ children }) => {
|
|
|
7004
6920
|
]);
|
|
7005
6921
|
const getResponses = (0, react.useCallback)(async (payload) => {
|
|
7006
6922
|
try {
|
|
7007
|
-
const requestPayload = payload ??
|
|
6923
|
+
const requestPayload = payload ?? require_chat.createResponsePayload({
|
|
7008
6924
|
userEvents,
|
|
7009
6925
|
generationParams: settingsContext.generationParams
|
|
7010
6926
|
});
|
|
@@ -7066,19 +6982,19 @@ const ChatContextProvider = ({ children }) => {
|
|
|
7066
6982
|
const hydrateChat = async () => {
|
|
7067
6983
|
try {
|
|
7068
6984
|
require_logger.logger_default.logDebug(`[spiffy-ai] initializeWidget is_currently_streaming=${responseStreaming} is_initialized=${widgetInitialized}`);
|
|
7069
|
-
const { messages: existingMessages, userEvents: userEvents$1 } = await
|
|
6985
|
+
const { messages: existingMessages, userEvents: userEvents$1 } = await require_chat.api_default.getResponses(orgId, chatId, userId);
|
|
7070
6986
|
setMessages([...existingMessages]);
|
|
7071
6987
|
setUserEvents([...userEvents$1]);
|
|
7072
6988
|
getResponses();
|
|
7073
6989
|
} catch (error) {
|
|
7074
6990
|
require_logger.logger_default.logInfo(`Init chat [exception] chat_id=${chatId} error=${error}`, error);
|
|
7075
|
-
if (error instanceof
|
|
6991
|
+
if (error instanceof require_chat.SessionRestartRequired) {
|
|
7076
6992
|
const appLoadedEvent = createAppLoadedEvent();
|
|
7077
6993
|
const visitEvent = createVisitUserEvent({ variantInfo });
|
|
7078
6994
|
setMessages([]);
|
|
7079
6995
|
clearUserEventQueue();
|
|
7080
6996
|
if (visitEvent) {
|
|
7081
|
-
const payload =
|
|
6997
|
+
const payload = require_chat.createResponsePayload({
|
|
7082
6998
|
userEvents: [appLoadedEvent, visitEvent],
|
|
7083
6999
|
generationParams: settingsContext.generationParams
|
|
7084
7000
|
});
|
|
@@ -7094,7 +7010,7 @@ const ChatContextProvider = ({ children }) => {
|
|
|
7094
7010
|
const onFocus = (0, react.useCallback)(async () => {
|
|
7095
7011
|
try {
|
|
7096
7012
|
if (!responseStreaming && !suggestionsLoading) {
|
|
7097
|
-
const { messages: existingMessages } = await
|
|
7013
|
+
const { messages: existingMessages } = await require_chat.api_default.getResponses(orgId, chatId, userId);
|
|
7098
7014
|
if (existingMessages.length > messages.length) setMessages([...existingMessages]);
|
|
7099
7015
|
}
|
|
7100
7016
|
} catch (error) {
|
|
@@ -7137,7 +7053,7 @@ const defaultGenerationParams = {
|
|
|
7137
7053
|
const SystemSettingsContext = (0, react.createContext)(void 0);
|
|
7138
7054
|
const SystemSettingsContextProvider = ({ children, generationParams, showDebugBar }) => {
|
|
7139
7055
|
const [params, setParams] = (0, react.useState)(() => generationParams ?? defaultGenerationParams);
|
|
7140
|
-
const endpointURL = (0, jotai.useAtomValue)(
|
|
7056
|
+
const endpointURL = (0, jotai.useAtomValue)(require_chat.endpointURLAtom);
|
|
7141
7057
|
const settingsContextValues = (0, react.useMemo)(() => ({
|
|
7142
7058
|
generationParams: params,
|
|
7143
7059
|
showDebugBar,
|
|
@@ -7154,6 +7070,90 @@ const SystemSettingsContextProvider = ({ children, generationParams, showDebugBa
|
|
|
7154
7070
|
});
|
|
7155
7071
|
};
|
|
7156
7072
|
|
|
7073
|
+
//#endregion
|
|
7074
|
+
//#region src/hooks/useSystemSettingsContext.ts
|
|
7075
|
+
const useSystemSettingsContext = () => {
|
|
7076
|
+
const context = (0, react.useContext)(SystemSettingsContext);
|
|
7077
|
+
if (!context) throw new Error("useSystemSettingsContext must be used within a SystemSettingsContextProvider");
|
|
7078
|
+
return { ...context };
|
|
7079
|
+
};
|
|
7080
|
+
|
|
7081
|
+
//#endregion
|
|
7082
|
+
//#region src/hooks/useTrackComponentVisibleEvent.ts
|
|
7083
|
+
/**
|
|
7084
|
+
* Tracks a component and logs an event to Amplitude when the component is visible.
|
|
7085
|
+
*
|
|
7086
|
+
* @param component - The component to track.
|
|
7087
|
+
* @param element - The element to track visibility of.
|
|
7088
|
+
* @param eventProps - Additional properties to include with the event.
|
|
7089
|
+
* @param eventName - The Amplitude event name to track (defaults to ChatComponentVisible).
|
|
7090
|
+
*/
|
|
7091
|
+
const useTrackComponentVisibleEvent = (component, element, eventProps, eventName = require_chat.SpiffyMetricsEventName.ChatComponentVisible) => {
|
|
7092
|
+
const isVisible = useIntersection(element, "0px");
|
|
7093
|
+
const hasTrackedEvent = (0, react.useRef)(false);
|
|
7094
|
+
const componentProps = (() => {
|
|
7095
|
+
if (eventName === require_chat.SpiffyMetricsEventName.ChatComponentVisible) return {
|
|
7096
|
+
chat_component: component,
|
|
7097
|
+
...eventProps
|
|
7098
|
+
};
|
|
7099
|
+
if (eventName === require_chat.SpiffyMetricsEventName.SearchComponentVisible) return {
|
|
7100
|
+
search_component: component,
|
|
7101
|
+
...eventProps
|
|
7102
|
+
};
|
|
7103
|
+
return {
|
|
7104
|
+
component,
|
|
7105
|
+
...eventProps
|
|
7106
|
+
};
|
|
7107
|
+
})();
|
|
7108
|
+
(0, react.useEffect)(() => {
|
|
7109
|
+
if (isVisible && !hasTrackedEvent.current) {
|
|
7110
|
+
require_chat.AmplitudeAdapter.trackEvent({
|
|
7111
|
+
eventName,
|
|
7112
|
+
eventProps: componentProps
|
|
7113
|
+
});
|
|
7114
|
+
hasTrackedEvent.current = true;
|
|
7115
|
+
}
|
|
7116
|
+
}, [
|
|
7117
|
+
isVisible,
|
|
7118
|
+
component,
|
|
7119
|
+
eventProps,
|
|
7120
|
+
eventName,
|
|
7121
|
+
componentProps
|
|
7122
|
+
]);
|
|
7123
|
+
};
|
|
7124
|
+
|
|
7125
|
+
//#endregion
|
|
7126
|
+
//#region src/hooks/useUpdateAnalyticsProps.ts
|
|
7127
|
+
/**
|
|
7128
|
+
* Updates the default analytics properties whenever the variant info changes. This hook also
|
|
7129
|
+
* triggers any events that should be sent once per page visit.
|
|
7130
|
+
*/
|
|
7131
|
+
const useUpdateAnalyticsProps = () => {
|
|
7132
|
+
const variantInfo = (0, jotai.useAtomValue)(require_chat.variantInfoAtom);
|
|
7133
|
+
const amplitudeAdapterRef = (0, react.useRef)(null);
|
|
7134
|
+
const hasInitialized = (0, react.useRef)(false);
|
|
7135
|
+
const hasParsedVariantInfo = (0, jotai.useAtomValue)(require_chat.hasParsedVariantInfoAtom);
|
|
7136
|
+
(0, react.useEffect)(() => {
|
|
7137
|
+
if (!amplitudeAdapterRef.current) amplitudeAdapterRef.current = require_chat.AmplitudeAdapter.getSingletonInstanceOf();
|
|
7138
|
+
const variantInfoWithPrefix = Object.fromEntries(Object.entries(variantInfo).map(([key, value]) => [`variantInfo.${key}`, value]));
|
|
7139
|
+
const defaultEventProperties = {
|
|
7140
|
+
page_variant: variantInfo.variant,
|
|
7141
|
+
...variantInfoWithPrefix
|
|
7142
|
+
};
|
|
7143
|
+
if (variantInfo.variant === "pdp") defaultEventProperties.product_id = variantInfo.productId;
|
|
7144
|
+
if (variantInfo.variant === "plp") defaultEventProperties.plp_id = variantInfo.plpId;
|
|
7145
|
+
if (variantInfo.variant === "page_visit") {
|
|
7146
|
+
defaultEventProperties.page_visit_category = variantInfo.pageVisitCategory;
|
|
7147
|
+
defaultEventProperties.page_visit_url = variantInfo.url;
|
|
7148
|
+
}
|
|
7149
|
+
amplitudeAdapterRef.current?.setSupplementalDefaultProps(defaultEventProperties);
|
|
7150
|
+
if (!hasInitialized.current && hasParsedVariantInfo) {
|
|
7151
|
+
require_chat.AmplitudeAdapter.trackEvent({ eventName: require_chat.SpiffyMetricsEventName.BundleLoaded });
|
|
7152
|
+
hasInitialized.current = true;
|
|
7153
|
+
}
|
|
7154
|
+
}, [variantInfo, hasParsedVariantInfo]);
|
|
7155
|
+
};
|
|
7156
|
+
|
|
7157
7157
|
//#endregion
|
|
7158
7158
|
Object.defineProperty(exports, 'ChatContext', {
|
|
7159
7159
|
enumerable: true,
|