@burdenoff/website-sdk 2026.1101.1 → 2026.1101.2

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.
Files changed (276) hide show
  1. package/README.md +42 -8
  2. package/dist/analytics/index.js +19 -69
  3. package/dist/analytics/index.js.map +1 -1
  4. package/dist/analytics/index.mjs +3 -69
  5. package/dist/analytics/index.mjs.map +1 -1
  6. package/dist/avatar-live/index.js +1 -0
  7. package/dist/avatar-live/index.js.map +1 -1
  8. package/dist/avatar-live/index.mjs +1 -0
  9. package/dist/avatar-live/index.mjs.map +1 -1
  10. package/dist/avatar-live-view/index.js +10 -30
  11. package/dist/avatar-live-view/index.js.map +1 -1
  12. package/dist/avatar-live-view/index.mjs +4 -24
  13. package/dist/avatar-live-view/index.mjs.map +1 -1
  14. package/dist/chunk-23H4JUL4.js +41 -0
  15. package/dist/chunk-23H4JUL4.js.map +1 -0
  16. package/dist/chunk-34RX5P75.mjs +25 -0
  17. package/dist/chunk-34RX5P75.mjs.map +1 -0
  18. package/dist/chunk-3LFFY7AZ.js +184 -0
  19. package/dist/chunk-3LFFY7AZ.js.map +1 -0
  20. package/dist/chunk-3X26GE4S.js +2794 -0
  21. package/dist/chunk-3X26GE4S.js.map +1 -0
  22. package/dist/chunk-45GCA4GG.js +85 -0
  23. package/dist/chunk-45GCA4GG.js.map +1 -0
  24. package/dist/chunk-4SAGVLHN.js +876 -0
  25. package/dist/chunk-4SAGVLHN.js.map +1 -0
  26. package/dist/chunk-4U6YAII5.js +218 -0
  27. package/dist/chunk-4U6YAII5.js.map +1 -0
  28. package/dist/chunk-5GMTBOO6.js +21 -0
  29. package/dist/chunk-5GMTBOO6.js.map +1 -0
  30. package/dist/chunk-5JRJ57CL.mjs +329 -0
  31. package/dist/chunk-5JRJ57CL.mjs.map +1 -0
  32. package/dist/chunk-6C2DKIC7.js +4 -0
  33. package/dist/chunk-6C2DKIC7.js.map +1 -0
  34. package/dist/chunk-6IBFBWC5.mjs +17 -0
  35. package/dist/chunk-6IBFBWC5.mjs.map +1 -0
  36. package/dist/chunk-6KY2ZRVI.js +116 -0
  37. package/dist/chunk-6KY2ZRVI.js.map +1 -0
  38. package/dist/chunk-6VJT3SM4.mjs +182 -0
  39. package/dist/chunk-6VJT3SM4.mjs.map +1 -0
  40. package/dist/chunk-6YZUFMK2.mjs +40 -0
  41. package/dist/chunk-6YZUFMK2.mjs.map +1 -0
  42. package/dist/chunk-7A6R7CGG.js +47 -0
  43. package/dist/chunk-7A6R7CGG.js.map +1 -0
  44. package/dist/chunk-7PWL4V2R.js +4 -0
  45. package/dist/chunk-7PWL4V2R.js.map +1 -0
  46. package/dist/chunk-AA33WDYS.js +161 -0
  47. package/dist/chunk-AA33WDYS.js.map +1 -0
  48. package/dist/chunk-AHRGFXV2.js +525 -0
  49. package/dist/chunk-AHRGFXV2.js.map +1 -0
  50. package/dist/chunk-B63XLDZH.mjs +109 -0
  51. package/dist/chunk-B63XLDZH.mjs.map +1 -0
  52. package/dist/chunk-BX2USEWF.mjs +35 -0
  53. package/dist/chunk-BX2USEWF.mjs.map +1 -0
  54. package/dist/chunk-BYSZT35R.js +150 -0
  55. package/dist/chunk-BYSZT35R.js.map +1 -0
  56. package/dist/chunk-C6OJIHNO.js +12 -0
  57. package/dist/chunk-C6OJIHNO.js.map +1 -0
  58. package/dist/chunk-COOELBX7.mjs +63 -0
  59. package/dist/chunk-COOELBX7.mjs.map +1 -0
  60. package/dist/chunk-D2TW7MNC.mjs +2771 -0
  61. package/dist/chunk-D2TW7MNC.mjs.map +1 -0
  62. package/dist/chunk-D5KEZ6V6.mjs +3 -0
  63. package/dist/chunk-D5KEZ6V6.mjs.map +1 -0
  64. package/dist/chunk-E3GUGJMY.js +46 -0
  65. package/dist/chunk-E3GUGJMY.js.map +1 -0
  66. package/dist/chunk-EBZ2HGJ2.mjs +52 -0
  67. package/dist/chunk-EBZ2HGJ2.mjs.map +1 -0
  68. package/dist/chunk-EDLTUOIA.mjs +210 -0
  69. package/dist/chunk-EDLTUOIA.mjs.map +1 -0
  70. package/dist/chunk-EJQSOT4X.js +4 -0
  71. package/dist/chunk-EJQSOT4X.js.map +1 -0
  72. package/dist/chunk-EUPFS6MZ.mjs +2019 -0
  73. package/dist/chunk-EUPFS6MZ.mjs.map +1 -0
  74. package/dist/chunk-F3XWDC3B.js +77 -0
  75. package/dist/chunk-F3XWDC3B.js.map +1 -0
  76. package/dist/chunk-FFADMVIK.mjs +5127 -0
  77. package/dist/chunk-FFADMVIK.mjs.map +1 -0
  78. package/dist/chunk-FJWS7BKT.mjs +3 -0
  79. package/dist/chunk-FJWS7BKT.mjs.map +1 -0
  80. package/dist/chunk-FJZJDUOR.mjs +3 -0
  81. package/dist/chunk-FJZJDUOR.mjs.map +1 -0
  82. package/dist/chunk-GCFLCO2Z.mjs +145 -0
  83. package/dist/chunk-GCFLCO2Z.mjs.map +1 -0
  84. package/dist/chunk-GEXC4LRP.js +61 -0
  85. package/dist/chunk-GEXC4LRP.js.map +1 -0
  86. package/dist/chunk-GTRAXQGC.mjs +3 -0
  87. package/dist/chunk-GTRAXQGC.mjs.map +1 -0
  88. package/dist/chunk-IKOIRUKW.js +270 -0
  89. package/dist/chunk-IKOIRUKW.js.map +1 -0
  90. package/dist/chunk-IXTWOPRN.js +45 -0
  91. package/dist/chunk-IXTWOPRN.js.map +1 -0
  92. package/dist/chunk-JDXOXGOK.js +547 -0
  93. package/dist/chunk-JDXOXGOK.js.map +1 -0
  94. package/dist/chunk-JSLDWYV7.mjs +558 -0
  95. package/dist/chunk-JSLDWYV7.mjs.map +1 -0
  96. package/dist/chunk-JXLSTVBK.js +336 -0
  97. package/dist/chunk-JXLSTVBK.js.map +1 -0
  98. package/dist/chunk-KHYXK7FG.mjs +49 -0
  99. package/dist/chunk-KHYXK7FG.mjs.map +1 -0
  100. package/dist/chunk-KSMBOWQQ.js +2034 -0
  101. package/dist/chunk-KSMBOWQQ.js.map +1 -0
  102. package/dist/chunk-KU2PXHGB.mjs +83 -0
  103. package/dist/chunk-KU2PXHGB.mjs.map +1 -0
  104. package/dist/chunk-KZANIV3S.mjs +37 -0
  105. package/dist/chunk-KZANIV3S.mjs.map +1 -0
  106. package/dist/chunk-L4BP6YOB.js +20 -0
  107. package/dist/chunk-L4BP6YOB.js.map +1 -0
  108. package/dist/chunk-MRKA2OAF.mjs +75 -0
  109. package/dist/chunk-MRKA2OAF.mjs.map +1 -0
  110. package/dist/chunk-N5EC53MH.mjs +80 -0
  111. package/dist/chunk-N5EC53MH.mjs.map +1 -0
  112. package/dist/chunk-NZANQGDM.mjs +34 -0
  113. package/dist/chunk-NZANQGDM.mjs.map +1 -0
  114. package/dist/chunk-O4GS3XPZ.js +10 -0
  115. package/dist/chunk-O4GS3XPZ.js.map +1 -0
  116. package/dist/chunk-O76QDGRM.js +5154 -0
  117. package/dist/chunk-O76QDGRM.js.map +1 -0
  118. package/dist/chunk-OYEUNZJY.js +114 -0
  119. package/dist/chunk-OYEUNZJY.js.map +1 -0
  120. package/dist/chunk-PHXAGQNB.js +74 -0
  121. package/dist/chunk-PHXAGQNB.js.map +1 -0
  122. package/dist/chunk-PIHHPP7J.mjs +16 -0
  123. package/dist/chunk-PIHHPP7J.mjs.map +1 -0
  124. package/dist/chunk-PXRHVVOU.mjs +499 -0
  125. package/dist/chunk-PXRHVVOU.mjs.map +1 -0
  126. package/dist/chunk-QMA6U6AU.js +36 -0
  127. package/dist/chunk-QMA6U6AU.js.map +1 -0
  128. package/dist/chunk-R6J7IULF.js +44 -0
  129. package/dist/chunk-R6J7IULF.js.map +1 -0
  130. package/dist/chunk-R7G6TWIS.mjs +10 -0
  131. package/dist/chunk-R7G6TWIS.mjs.map +1 -0
  132. package/dist/chunk-RUMGFI6L.mjs +544 -0
  133. package/dist/chunk-RUMGFI6L.mjs.map +1 -0
  134. package/dist/chunk-S54JWSJF.js +565 -0
  135. package/dist/chunk-S54JWSJF.js.map +1 -0
  136. package/dist/chunk-SK5UGG6A.js +2041 -0
  137. package/dist/chunk-SK5UGG6A.js.map +1 -0
  138. package/dist/chunk-SKIYDKIS.mjs +70 -0
  139. package/dist/chunk-SKIYDKIS.mjs.map +1 -0
  140. package/dist/chunk-SZNS5IK6.mjs +322 -0
  141. package/dist/chunk-SZNS5IK6.mjs.map +1 -0
  142. package/dist/chunk-T7JIPZAC.js +66 -0
  143. package/dist/chunk-T7JIPZAC.js.map +1 -0
  144. package/dist/chunk-TGYQHO2E.mjs +864 -0
  145. package/dist/chunk-TGYQHO2E.mjs.map +1 -0
  146. package/dist/chunk-TT3MHN42.mjs +8 -0
  147. package/dist/chunk-TT3MHN42.mjs.map +1 -0
  148. package/dist/chunk-UM55U65W.mjs +268 -0
  149. package/dist/chunk-UM55U65W.mjs.map +1 -0
  150. package/dist/chunk-UQ2HALUD.js +72 -0
  151. package/dist/chunk-UQ2HALUD.js.map +1 -0
  152. package/dist/chunk-UXWT7G77.js +82 -0
  153. package/dist/chunk-UXWT7G77.js.map +1 -0
  154. package/dist/chunk-VNS5WDWO.mjs +7 -0
  155. package/dist/chunk-VNS5WDWO.mjs.map +1 -0
  156. package/dist/chunk-VRWZLGR7.js +4 -0
  157. package/dist/chunk-VRWZLGR7.js.map +1 -0
  158. package/dist/chunk-VZLDSNH4.mjs +22 -0
  159. package/dist/chunk-VZLDSNH4.mjs.map +1 -0
  160. package/dist/chunk-W6P3YETJ.js +92 -0
  161. package/dist/chunk-W6P3YETJ.js.map +1 -0
  162. package/dist/chunk-WPKFFQCR.mjs +90 -0
  163. package/dist/chunk-WPKFFQCR.mjs.map +1 -0
  164. package/dist/chunk-WTVTI5TO.mjs +22 -0
  165. package/dist/chunk-WTVTI5TO.mjs.map +1 -0
  166. package/dist/chunk-XJOBZ4RJ.js +44 -0
  167. package/dist/chunk-XJOBZ4RJ.js.map +1 -0
  168. package/dist/chunk-XP2JDNDU.js +325 -0
  169. package/dist/chunk-XP2JDNDU.js.map +1 -0
  170. package/dist/chunk-Y4V5CEWD.mjs +112 -0
  171. package/dist/chunk-Y4V5CEWD.mjs.map +1 -0
  172. package/dist/chunk-YERN2UWM.js +116 -0
  173. package/dist/chunk-YERN2UWM.js.map +1 -0
  174. package/dist/chunk-ZKJQWFAA.mjs +114 -0
  175. package/dist/chunk-ZKJQWFAA.mjs.map +1 -0
  176. package/dist/chunk-ZOON3S3Y.mjs +138 -0
  177. package/dist/chunk-ZOON3S3Y.mjs.map +1 -0
  178. package/dist/chunk-ZP6QRAYC.mjs +2024 -0
  179. package/dist/chunk-ZP6QRAYC.mjs.map +1 -0
  180. package/dist/chunk-ZSTFX7FV.js +9 -0
  181. package/dist/chunk-ZSTFX7FV.js.map +1 -0
  182. package/dist/client/index.js +23 -331
  183. package/dist/client/index.js.map +1 -1
  184. package/dist/client/index.mjs +3 -330
  185. package/dist/client/index.mjs.map +1 -1
  186. package/dist/comparison/index.js +28 -111
  187. package/dist/comparison/index.js.map +1 -1
  188. package/dist/comparison/index.mjs +2 -107
  189. package/dist/comparison/index.mjs.map +1 -1
  190. package/dist/components/contact.js +21 -931
  191. package/dist/components/contact.js.map +1 -1
  192. package/dist/components/contact.mjs +12 -909
  193. package/dist/components/contact.mjs.map +1 -1
  194. package/dist/components/electron-download.js +12 -124
  195. package/dist/components/electron-download.js.map +1 -1
  196. package/dist/components/electron-download.mjs +4 -106
  197. package/dist/components/electron-download.mjs.map +1 -1
  198. package/dist/components/explore-cta.js +8 -112
  199. package/dist/components/explore-cta.js.map +1 -1
  200. package/dist/components/explore-cta.mjs +3 -114
  201. package/dist/components/explore-cta.mjs.map +1 -1
  202. package/dist/components/explore.js +62 -7833
  203. package/dist/components/explore.js.map +1 -1
  204. package/dist/components/explore.mjs +13 -7800
  205. package/dist/components/explore.mjs.map +1 -1
  206. package/dist/components/launch-countdown.js +8 -83
  207. package/dist/components/launch-countdown.js.map +1 -1
  208. package/dist/components/launch-countdown.mjs +3 -85
  209. package/dist/components/launch-countdown.mjs.map +1 -1
  210. package/dist/components/newsletter.js +20 -993
  211. package/dist/components/newsletter.js.map +1 -1
  212. package/dist/components/newsletter.mjs +11 -971
  213. package/dist/components/newsletter.mjs.map +1 -1
  214. package/dist/components/partners.js +24 -1302
  215. package/dist/components/partners.js.map +1 -1
  216. package/dist/components/partners.mjs +15 -1276
  217. package/dist/components/partners.mjs.map +1 -1
  218. package/dist/components/pricing.js +49 -1249
  219. package/dist/components/pricing.js.map +1 -1
  220. package/dist/components/pricing.mjs +8 -1226
  221. package/dist/components/pricing.mjs.map +1 -1
  222. package/dist/components/problems-solved.js +8 -150
  223. package/dist/components/problems-solved.js.map +1 -1
  224. package/dist/components/problems-solved.mjs +4 -133
  225. package/dist/components/problems-solved.mjs.map +1 -1
  226. package/dist/components/resource-links.js +8 -304
  227. package/dist/components/resource-links.js.map +1 -1
  228. package/dist/components/resource-links.mjs +5 -308
  229. package/dist/components/resource-links.mjs.map +1 -1
  230. package/dist/components/social-links.js +8 -343
  231. package/dist/components/social-links.js.map +1 -1
  232. package/dist/components/social-links.mjs +5 -347
  233. package/dist/components/social-links.mjs.map +1 -1
  234. package/dist/components/unsubscribe.js +10 -627
  235. package/dist/components/unsubscribe.js.map +1 -1
  236. package/dist/components/unsubscribe.mjs +6 -611
  237. package/dist/components/unsubscribe.mjs.map +1 -1
  238. package/dist/components/waitlist.js +21 -1001
  239. package/dist/components/waitlist.js.map +1 -1
  240. package/dist/components/waitlist.mjs +12 -982
  241. package/dist/components/waitlist.mjs.map +1 -1
  242. package/dist/components/website-switcher.js +12 -175
  243. package/dist/components/website-switcher.js.map +1 -1
  244. package/dist/components/website-switcher.mjs +4 -157
  245. package/dist/components/website-switcher.mjs.map +1 -1
  246. package/dist/content/index.js +118 -3616
  247. package/dist/content/index.js.map +1 -1
  248. package/dist/content/index.mjs +12 -3567
  249. package/dist/content/index.mjs.map +1 -1
  250. package/dist/hooks/index.js +37 -2321
  251. package/dist/hooks/index.js.map +1 -1
  252. package/dist/hooks/index.mjs +6 -2318
  253. package/dist/hooks/index.mjs.map +1 -1
  254. package/dist/index.d.mts +1 -1
  255. package/dist/index.d.ts +1 -1
  256. package/dist/index.js +4145 -20599
  257. package/dist/index.js.map +1 -1
  258. package/dist/index.mjs +3766 -20567
  259. package/dist/index.mjs.map +1 -1
  260. package/dist/product/index.js +20 -393
  261. package/dist/product/index.js.map +1 -1
  262. package/dist/product/index.mjs +5 -394
  263. package/dist/product/index.mjs.map +1 -1
  264. package/dist/seo/index.js +8 -76
  265. package/dist/seo/index.js.map +1 -1
  266. package/dist/seo/index.mjs +3 -78
  267. package/dist/seo/index.mjs.map +1 -1
  268. package/dist/store/index.js +51 -2650
  269. package/dist/store/index.js.map +1 -1
  270. package/dist/store/index.mjs +13 -2619
  271. package/dist/store/index.mjs.map +1 -1
  272. package/dist/utils/index.js +69 -134
  273. package/dist/utils/index.js.map +1 -1
  274. package/dist/utils/index.mjs +5 -122
  275. package/dist/utils/index.mjs.map +1 -1
  276. package/package.json +2 -1
@@ -0,0 +1,2019 @@
1
+ import { getRecaptchaV3Token } from './chunk-SKIYDKIS.mjs';
2
+ import { emitProductSlug } from './chunk-KZANIV3S.mjs';
3
+ import { useWebSDK, useWebSDKConfig } from './chunk-5JRJ57CL.mjs';
4
+ import { useMemo, useState, useRef, useCallback, useEffect } from 'react';
5
+
6
+ // src/data/products.ts
7
+ var ECOSYSTEM_PRODUCTS = [
8
+ {
9
+ slug: "workspaces",
10
+ name: "Workspaces",
11
+ websiteUrl: "https://burdenoff.com"
12
+ },
13
+ {
14
+ slug: "vibecontrols",
15
+ name: "VibeControls",
16
+ websiteUrl: "https://vibecontrols.com"
17
+ },
18
+ // FluidGrids ships on www.fluidgrids.ai — fluidgrids.com only redirects there. The explore
19
+ // catalog and the site's own sitemap use this origin, and so must the fallback catalog
20
+ // built from this list, or /explore rejects FluidGrids concept images until it loads.
21
+ {
22
+ slug: "fluidgrids",
23
+ name: "FluidGrids",
24
+ websiteUrl: "https://www.fluidgrids.ai"
25
+ },
26
+ // BotManor ships on www.botmanor.com (the apex redirects there; the old botlit.ai domain
27
+ // still serves the same site but is no longer the name we link to).
28
+ // The slug follows the botlit → botmanor rename switch (utils/product-slug.ts).
29
+ {
30
+ slug: emitProductSlug("botmanor"),
31
+ name: "BotManor",
32
+ websiteUrl: "https://www.botmanor.com"
33
+ },
34
+ {
35
+ slug: "bigconsole",
36
+ name: "BigConsole",
37
+ websiteUrl: "https://bigconsole.com"
38
+ },
39
+ {
40
+ slug: "semanticfed",
41
+ name: "SemanticFed",
42
+ websiteUrl: "https://semanticfed.com"
43
+ },
44
+ {
45
+ slug: "intelwatchtower",
46
+ name: "IntelWatchtower",
47
+ websiteUrl: "https://intelwatchtower.com"
48
+ },
49
+ { slug: "buildmyiq", name: "BuildMyIQ", websiteUrl: "https://buildmyiq.com" },
50
+ {
51
+ slug: "assethandler",
52
+ name: "AssetHandler",
53
+ websiteUrl: "https://assethandler.com"
54
+ },
55
+ {
56
+ slug: "crewfoundry",
57
+ name: "CrewFoundry",
58
+ websiteUrl: "https://crewfoundry.com"
59
+ },
60
+ {
61
+ slug: "planmagnet",
62
+ name: "PlanMagnet",
63
+ websiteUrl: "https://planmagnet.com"
64
+ },
65
+ {
66
+ slug: "eventfullymanaged",
67
+ name: "EventfullyManaged",
68
+ websiteUrl: "https://eventfullymanaged.com"
69
+ },
70
+ {
71
+ slug: "headshotmarketing",
72
+ name: "HeadshotMarketing",
73
+ websiteUrl: "https://headshotmarketing.com"
74
+ },
75
+ {
76
+ slug: "technospam",
77
+ name: "TechnoSpam",
78
+ websiteUrl: "https://technospam.com"
79
+ },
80
+ { slug: "kadaikodi", name: "Kadaikodi", websiteUrl: "https://kadaikodi.com" },
81
+ {
82
+ slug: "movethewheels",
83
+ name: "MoveTheWheels",
84
+ websiteUrl: "https://movethewheels.com"
85
+ },
86
+ {
87
+ slug: "healthybowl",
88
+ name: "Healthy Bowl",
89
+ websiteUrl: "https://gethealthybowl.com"
90
+ },
91
+ { slug: "ggnomad", name: "GGNomad", websiteUrl: "https://ggnomad.com" },
92
+ {
93
+ slug: "timecampus",
94
+ name: "TimeCampus",
95
+ websiteUrl: "https://timecampus.com"
96
+ },
97
+ {
98
+ slug: "manufacturedops",
99
+ name: "ManufacturedOps",
100
+ websiteUrl: "https://manufacturedops.com"
101
+ },
102
+ {
103
+ slug: "theglobalfuel",
104
+ name: "TheGlobalFuel",
105
+ websiteUrl: "https://theglobalfuel.com"
106
+ },
107
+ {
108
+ slug: "housingvista",
109
+ name: "HousingVista",
110
+ websiteUrl: "https://housingvista.com"
111
+ },
112
+ {
113
+ slug: "proserviceworld",
114
+ name: "ProServiceWorld",
115
+ websiteUrl: "https://proserviceworld.com"
116
+ },
117
+ {
118
+ slug: "mybodyshield",
119
+ name: "MyBodyShield",
120
+ websiteUrl: "https://mybodyshield.com"
121
+ },
122
+ {
123
+ slug: "artistrybase",
124
+ name: "ArtistryBase",
125
+ websiteUrl: "https://artistrybase.com"
126
+ },
127
+ {
128
+ slug: "theculturepost",
129
+ name: "TheCulturePost",
130
+ websiteUrl: "https://theculturepost.com"
131
+ },
132
+ { slug: "collabkin", name: "CollabKin", websiteUrl: "https://collabkin.com" },
133
+ {
134
+ slug: "comradecircle",
135
+ name: "ComradeCircle",
136
+ websiteUrl: "https://comradecircle.com"
137
+ },
138
+ {
139
+ slug: "brainyrich",
140
+ name: "BrainyRich",
141
+ websiteUrl: "https://brainyrich.com"
142
+ },
143
+ {
144
+ slug: "cosmicintersection",
145
+ name: "CosmicIntersection",
146
+ websiteUrl: "https://cosmicintersection.com"
147
+ },
148
+ {
149
+ slug: "govcitizenhub",
150
+ name: "GovCitizenHub",
151
+ websiteUrl: "https://govcitizenhub.com"
152
+ },
153
+ {
154
+ slug: "adaptercloud",
155
+ name: "AdapterCloud",
156
+ websiteUrl: "https://adaptercloud.com"
157
+ },
158
+ {
159
+ slug: "subscriberbot",
160
+ name: "Subscriber Bot",
161
+ websiteUrl: "https://subscriberbot.com"
162
+ },
163
+ {
164
+ slug: "hookmovies",
165
+ name: "HookMovies",
166
+ websiteUrl: "https://hookmovies.com"
167
+ },
168
+ {
169
+ slug: "coolandlovely",
170
+ name: "CoolAndLovely",
171
+ websiteUrl: "https://coolandlovely.com"
172
+ },
173
+ {
174
+ slug: "atheletebridge",
175
+ name: "AthleteBridge",
176
+ websiteUrl: "https://atheletebridge.com"
177
+ },
178
+ {
179
+ slug: "labsofscience",
180
+ name: "LabsOfScience",
181
+ websiteUrl: "https://labsofscience.com"
182
+ },
183
+ {
184
+ slug: "ecoimpacthub",
185
+ name: "EcoImpactHub",
186
+ websiteUrl: "https://ecoimpacthub.com"
187
+ }
188
+ ];
189
+
190
+ // src/components/explore-types.ts
191
+ var EXPLORE_FEEDBACK_REASONS = [
192
+ "INACCURATE",
193
+ "INCOMPLETE",
194
+ "OFF_TOPIC",
195
+ "HARD_TO_FOLLOW",
196
+ "OTHER"
197
+ ];
198
+ var EXPLORE_MESSAGE_FIELDS = (
199
+ /* GraphQL */
200
+ `
201
+ id
202
+ conversationId
203
+ role
204
+ status
205
+ content
206
+ partialContent
207
+ activity
208
+ references {
209
+ url
210
+ title
211
+ description
212
+ product
213
+ imageUrl
214
+ index
215
+ }
216
+ ctas {
217
+ kind
218
+ label
219
+ url
220
+ product
221
+ }
222
+ followUps
223
+ answered
224
+ attachments {
225
+ name
226
+ mimeType
227
+ size
228
+ textExtracted
229
+ }
230
+ errorCode
231
+ createdAt
232
+ completedAt
233
+ `
234
+ );
235
+ var EXPLORE_OWN_MESSAGE_FIELDS = (
236
+ /* GraphQL */
237
+ `
238
+ ${EXPLORE_MESSAGE_FIELDS}
239
+ feedback {
240
+ rating
241
+ reason
242
+ comment
243
+ createdAt
244
+ }
245
+ `
246
+ );
247
+ var EXPLORE_CATALOG_ESTABLISHED_FIELDS = (
248
+ /* GraphQL */
249
+ `
250
+ enabled
251
+ products {
252
+ slug
253
+ name
254
+ tagline
255
+ website
256
+ }
257
+ examplePrompts
258
+ welcomeTitle
259
+ welcomeBody
260
+ limits {
261
+ maxMessageLength
262
+ maxTurnsPerConversation
263
+ messagesPerDay
264
+ historyTurns
265
+ }
266
+ captchaRequired
267
+ recaptchaSiteKey`
268
+ );
269
+ var EXPLORE_CATALOG_HIGHLIGHT_FIELD = (
270
+ /* GraphQL */
271
+ `
272
+ conceptHighlights {
273
+ product
274
+ productName
275
+ title
276
+ url
277
+ imageUrl
278
+ alt
279
+ }`
280
+ );
281
+ function exploreCatalogDocument(extraFields) {
282
+ return (
283
+ /* GraphQL */
284
+ `
285
+ query ExploreCatalog($productSlug: String) {
286
+ exploreCatalog(productSlug: $productSlug) {${EXPLORE_CATALOG_ESTABLISHED_FIELDS}${extraFields}
287
+ }
288
+ }
289
+ `
290
+ );
291
+ }
292
+ var EXPLORE_CATALOG_QUERY = exploreCatalogDocument(
293
+ EXPLORE_CATALOG_HIGHLIGHT_FIELD
294
+ );
295
+ var EXPLORE_CATALOG_QUERY_WITHOUT_HIGHLIGHTS = exploreCatalogDocument("");
296
+ var EXPLORE_MESSAGE_QUERY = (
297
+ /* GraphQL */
298
+ `
299
+ query ExploreMessage($conversationToken: String!, $id: ID!) {
300
+ exploreMessage(conversationToken: $conversationToken, id: $id) {
301
+ ${EXPLORE_OWN_MESSAGE_FIELDS}
302
+ }
303
+ }
304
+ `
305
+ );
306
+ var SEND_EXPLORE_MESSAGE_MUTATION = (
307
+ /* GraphQL */
308
+ `
309
+ mutation SendExploreMessage($input: SendExploreMessageInput!) {
310
+ sendExploreMessage(input: $input) {
311
+ conversation {
312
+ id
313
+ token
314
+ productSlug
315
+ turnCount
316
+ createdAt
317
+ }
318
+ userMessage {
319
+ ${EXPLORE_OWN_MESSAGE_FIELDS}
320
+ }
321
+ assistantMessage {
322
+ ${EXPLORE_OWN_MESSAGE_FIELDS}
323
+ }
324
+ remainingToday
325
+ }
326
+ }
327
+ `
328
+ );
329
+ var RECORD_EXPLORE_CLICK_MUTATION = (
330
+ /* GraphQL */
331
+ `
332
+ mutation RecordExploreClick($input: RecordExploreClickInput!) {
333
+ recordExploreClick(input: $input) {
334
+ recorded
335
+ }
336
+ }
337
+ `
338
+ );
339
+ var SUBMIT_EXPLORE_FEEDBACK_MUTATION = (
340
+ /* GraphQL */
341
+ `
342
+ mutation SubmitExploreFeedback($input: SubmitExploreFeedbackInput!) {
343
+ submitExploreFeedback(input: $input) {
344
+ recorded
345
+ feedback {
346
+ rating
347
+ reason
348
+ comment
349
+ createdAt
350
+ }
351
+ }
352
+ }
353
+ `
354
+ );
355
+ var EXPLORE_FEEDBACK_COMMENT_SOFT_MAX = 500;
356
+ var ESCALATE_EXPLORE_CONVERSATION_MUTATION = (
357
+ /* GraphQL */
358
+ `
359
+ mutation EscalateExploreConversation(
360
+ $input: EscalateExploreConversationInput!
361
+ ) {
362
+ escalateExploreConversation(input: $input) {
363
+ created
364
+ escalation {
365
+ email
366
+ createdAt
367
+ }
368
+ }
369
+ }
370
+ `
371
+ );
372
+ var EXPLORE_ESCALATION_NOTE_SOFT_MAX = 2e3;
373
+ var DELIVERABLE_EMAIL = /^[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\.)+[A-Za-z]{2,}$/;
374
+ function looksLikeDeliverableEmail(value) {
375
+ const trimmed = value.trim();
376
+ if (trimmed.length === 0 || trimmed.length > 254) return false;
377
+ return DELIVERABLE_EMAIL.test(trimmed);
378
+ }
379
+ var CREATE_EXPLORE_SHARE_LINK_MUTATION = (
380
+ /* GraphQL */
381
+ `
382
+ mutation CreateExploreShareLink($conversationToken: String!) {
383
+ createExploreShareLink(conversationToken: $conversationToken) {
384
+ shareToken
385
+ }
386
+ }
387
+ `
388
+ );
389
+ var EXPLORE_SHARED_CONVERSATION_QUERY = (
390
+ /* GraphQL */
391
+ `
392
+ query ExploreSharedConversation($shareToken: String!) {
393
+ exploreSharedConversation(shareToken: $shareToken) {
394
+ ${EXPLORE_MESSAGE_FIELDS}
395
+ }
396
+ }
397
+ `
398
+ );
399
+ var DEFAULT_STORAGE_KEY = "boff.explore.v1";
400
+ var HISTORY_SUFFIX = ".history";
401
+ var MAX_ARCHIVED_CONVERSATIONS = 15;
402
+ var DEFAULT_POLL_INTERVAL_MS = 1500;
403
+ var DEFAULT_POLL_TIMEOUT_MS = 9e4;
404
+ var POLL_REQUEST_TIMEOUT_MS = 1e4;
405
+ var SEND_REQUEST_TIMEOUT_MS = 18e3;
406
+ var MAX_CONSECUTIVE_POLL_FAILURES = 4;
407
+ var MAX_PERSISTED_MESSAGES = 40;
408
+ var FALLBACK_EXPLORE_LIMITS = {
409
+ maxMessageLength: 2e3,
410
+ maxTurnsPerConversation: 20,
411
+ messagesPerDay: 100,
412
+ historyTurns: 6
413
+ };
414
+ var DEFAULT_EXPLORE_EXAMPLE_PROMPTS = [
415
+ "Every course we run lives in a different spreadsheet.",
416
+ "We only hear a machine is down after the line has stopped.",
417
+ "Members quietly stop showing up and we never know why.",
418
+ "Which of your products fits a problem like mine?"
419
+ ];
420
+ var FALLBACK_WELCOME_TITLE = "What problem are you trying to solve?";
421
+ var FALLBACK_WELCOME_BODY = "Describe the problem, in your own words. You can also ask about a specific product or compare a few. Every answer comes straight from our documentation.";
422
+ function buildFallbackCatalog(examplePrompts, welcome) {
423
+ return {
424
+ enabled: true,
425
+ products: ECOSYSTEM_PRODUCTS.map((p) => ({
426
+ slug: p.slug,
427
+ name: p.name,
428
+ tagline: null,
429
+ website: p.websiteUrl
430
+ })),
431
+ examplePrompts: examplePrompts?.length ? examplePrompts : DEFAULT_EXPLORE_EXAMPLE_PROMPTS,
432
+ welcomeTitle: welcome?.title ?? FALLBACK_WELCOME_TITLE,
433
+ welcomeBody: welcome?.body ?? FALLBACK_WELCOME_BODY,
434
+ limits: FALLBACK_EXPLORE_LIMITS,
435
+ captchaRequired: false,
436
+ recaptchaSiteKey: null,
437
+ // Empty, and deliberately not synthesised from `ECOSYSTEM_PRODUCTS`: a concept highlight
438
+ // needs a real published illustration URL, and this SDK has no registry of them. An
439
+ // invented path would render 38 broken frames on the one screen every prerender captures.
440
+ // The strip renders nothing at all when the list is empty, which is the honest fallback.
441
+ conceptHighlights: []
442
+ };
443
+ }
444
+ var BAKED_CATALOG_ELEMENT_ID = "boff-explore-catalog";
445
+ function bakedCatalogLocale() {
446
+ if (typeof navigator === "undefined") return "";
447
+ return (navigator.language || "").toLowerCase().split("-")[0] ?? "";
448
+ }
449
+ function snapshotBakedElement() {
450
+ if (typeof document === "undefined") return null;
451
+ const el = document.getElementById(BAKED_CATALOG_ELEMENT_ID);
452
+ if (!el || el.tagName !== "SCRIPT" || el.getAttribute("type") !== "application/json")
453
+ return null;
454
+ return {
455
+ product: el.getAttribute("data-product") ?? "",
456
+ locale: el.getAttribute("data-locale") ?? "",
457
+ text: el.textContent ?? ""
458
+ };
459
+ }
460
+ var BAKED_AT_LOAD = snapshotBakedElement();
461
+ function isCatalogShape(value) {
462
+ if (!value || typeof value !== "object") return false;
463
+ const c = value;
464
+ const listOrAbsent = (v) => v === void 0 || v === null || Array.isArray(v);
465
+ const textOrAbsent = (v) => v === void 0 || v === null || typeof v === "string";
466
+ return (c["enabled"] === void 0 || typeof c["enabled"] === "boolean") && listOrAbsent(c["products"]) && listOrAbsent(c["examplePrompts"]) && listOrAbsent(c["conceptHighlights"]) && textOrAbsent(c["welcomeTitle"]) && textOrAbsent(c["welcomeBody"]);
467
+ }
468
+ function readBakedCatalog(productSlug) {
469
+ const baked = snapshotBakedElement() ?? BAKED_AT_LOAD;
470
+ if (!baked) return null;
471
+ if (baked.product !== (productSlug ?? "")) return null;
472
+ if (baked.locale && baked.locale !== bakedCatalogLocale()) return null;
473
+ try {
474
+ const parsed = JSON.parse(baked.text);
475
+ return isCatalogShape(parsed) ? parsed : null;
476
+ } catch {
477
+ return null;
478
+ }
479
+ }
480
+ function serializeBakedCatalog(raw) {
481
+ return JSON.stringify(raw).replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
482
+ }
483
+ function normalizeCatalog(raw, fallback) {
484
+ return {
485
+ enabled: raw.enabled !== false,
486
+ products: raw.products?.length ? raw.products : fallback.products,
487
+ examplePrompts: raw.examplePrompts?.length ? raw.examplePrompts : fallback.examplePrompts,
488
+ welcomeTitle: raw.welcomeTitle || fallback.welcomeTitle,
489
+ welcomeBody: raw.welcomeBody || fallback.welcomeBody,
490
+ limits: {
491
+ maxMessageLength: raw.limits?.maxMessageLength || fallback.limits.maxMessageLength,
492
+ maxTurnsPerConversation: raw.limits?.maxTurnsPerConversation || fallback.limits.maxTurnsPerConversation,
493
+ messagesPerDay: raw.limits?.messagesPerDay || fallback.limits.messagesPerDay,
494
+ historyTurns: raw.limits?.historyTurns || fallback.limits.historyTurns
495
+ },
496
+ captchaRequired: raw.captchaRequired === true,
497
+ recaptchaSiteKey: raw.recaptchaSiteKey ?? null,
498
+ // `[ExploreConceptHighlight!]!` on the wire, so a gateway that KNOWS the field always
499
+ // sends an array. The one response that arrives without it is the retry against an older
500
+ // supergraph (`EXPLORE_CATALOG_QUERY_WITHOUT_HIGHLIGHTS`) — that gateway does not answer
501
+ // the full document at all, it refuses it. Either way
502
+ // `catalog.conceptHighlights.filter(...)` on `undefined` would throw inside render,
503
+ // blanking the welcome screen over a decorative strip.
504
+ conceptHighlights: raw.conceptHighlights?.length ? raw.conceptHighlights : fallback.conceptHighlights
505
+ };
506
+ }
507
+ var CATALOG_DOCUMENT_REJECTED_CODES = /* @__PURE__ */ new Set([
508
+ "GRAPHQL_VALIDATION_FAILED",
509
+ "HTTP_400"
510
+ ]);
511
+ function catalogRejectedTheHighlightField(res) {
512
+ if (res.data?.exploreCatalog) return false;
513
+ return (res.errors ?? []).some((error) => {
514
+ const code = error.extensions?.code;
515
+ return typeof code === "string" && CATALOG_DOCUMENT_REJECTED_CODES.has(code) || error.message.includes("conceptHighlights");
516
+ });
517
+ }
518
+ var RATE_LIMIT_CODES = /* @__PURE__ */ new Set([
519
+ "RATE_LIMITED",
520
+ "HTTP_429",
521
+ "EXPLORE_GLOBAL_LIMIT"
522
+ ]);
523
+ var CAPTCHA_CODES = /* @__PURE__ */ new Set(["CAPTCHA_FAILED", "CAPTCHA_REQUIRED"]);
524
+ var NETWORK_CODES = /* @__PURE__ */ new Set([
525
+ "NETWORK_ERROR",
526
+ "UPSTREAM_UNAVAILABLE",
527
+ "CONVERSATION_BUSY",
528
+ "PROVIDER_ERROR",
529
+ "QUEUE_FULL"
530
+ ]);
531
+ var VALIDATION_CODES = /* @__PURE__ */ new Set([
532
+ "MESSAGE_TOO_LONG",
533
+ "MESSAGE_EMPTY",
534
+ "CONVERSATION_LIMIT",
535
+ "INVALID_INPUT"
536
+ ]);
537
+ function escalateOutcomeForCode(code) {
538
+ switch (code) {
539
+ case "INVALID_EMAIL":
540
+ return "invalid-email";
541
+ case "RATE_LIMITED":
542
+ case "HTTP_429":
543
+ return "rate-limited";
544
+ case "CAPTCHA_REQUIRED":
545
+ case "CAPTCHA_FAILED":
546
+ return "captcha";
547
+ // The token owns nothing, or owns a different conversation. The server answers NOT_FOUND
548
+ // rather than FORBIDDEN so the endpoint is not an oracle for whether a thread exists;
549
+ // either way there is nothing this visitor can do about it, so it reads as a failure.
550
+ case "NOT_FOUND":
551
+ return "failed";
552
+ default:
553
+ return "failed";
554
+ }
555
+ }
556
+ function classifyExploreError(code, serverMessage) {
557
+ const c = code ?? "UNKNOWN";
558
+ if (RATE_LIMIT_CODES.has(c)) {
559
+ return {
560
+ kind: "rate-limit",
561
+ code: c,
562
+ message: "You've reached the message limit for now. Please try again later.",
563
+ retryable: false
564
+ };
565
+ }
566
+ if (CAPTCHA_CODES.has(c)) {
567
+ return {
568
+ kind: "captcha",
569
+ code: c,
570
+ message: "We couldn't verify that you're human. Please try sending that again.",
571
+ retryable: true
572
+ };
573
+ }
574
+ if (c === "TOOL_BUDGET") {
575
+ return {
576
+ kind: "scope",
577
+ code: c,
578
+ message: "That question spans more of our products than I can look through in one go. Try asking about two or three specific products.",
579
+ retryable: false
580
+ };
581
+ }
582
+ if (c === "TIMEOUT") {
583
+ return {
584
+ kind: "timeout",
585
+ code: c,
586
+ message: "That answer took too long to come back. Try asking again.",
587
+ retryable: true
588
+ };
589
+ }
590
+ if (NETWORK_CODES.has(c)) {
591
+ return {
592
+ kind: "network",
593
+ code: c,
594
+ message: "We couldn't reach the assistant just now. Check your connection and try again.",
595
+ retryable: true
596
+ };
597
+ }
598
+ if (c === "EXPLORE_DISABLED") {
599
+ return {
600
+ kind: "disabled",
601
+ code: c,
602
+ message: "Explore is unavailable at the moment. Please check back soon.",
603
+ retryable: false
604
+ };
605
+ }
606
+ if (VALIDATION_CODES.has(c)) {
607
+ return {
608
+ kind: "validation",
609
+ code: c,
610
+ message: serverMessage || "That message couldn't be sent.",
611
+ retryable: false
612
+ };
613
+ }
614
+ if (c === "EMPTY_ANSWER") {
615
+ return {
616
+ kind: "unknown",
617
+ code: c,
618
+ message: "No answer came back for that one. Try rephrasing, or ask something more specific.",
619
+ retryable: true
620
+ };
621
+ }
622
+ return {
623
+ kind: "unknown",
624
+ code: c,
625
+ message: serverMessage || "Something went wrong. Please try again.",
626
+ retryable: true
627
+ };
628
+ }
629
+ function historyKey(key) {
630
+ return `${key}${HISTORY_SUFFIX}`;
631
+ }
632
+ function readArchive(key) {
633
+ if (typeof window === "undefined") return [];
634
+ try {
635
+ const raw = window.localStorage.getItem(historyKey(key));
636
+ if (!raw) return [];
637
+ const parsed = JSON.parse(raw);
638
+ if (!Array.isArray(parsed)) return [];
639
+ return parsed.filter(
640
+ (entry) => typeof entry === "object" && entry !== null && typeof entry.token === "string" && Array.isArray(entry.messages)
641
+ );
642
+ } catch {
643
+ return [];
644
+ }
645
+ }
646
+ function writeArchive(key, entries) {
647
+ if (typeof window === "undefined") return;
648
+ try {
649
+ if (entries.length === 0) {
650
+ window.localStorage.removeItem(historyKey(key));
651
+ return;
652
+ }
653
+ window.localStorage.setItem(historyKey(key), JSON.stringify(entries));
654
+ } catch {
655
+ }
656
+ }
657
+ function upsertArchive(key, thread) {
658
+ if (!thread.token) return readArchive(key);
659
+ const real = thread.messages.filter(
660
+ (m) => m.content.trim() !== "" || m.role === "USER"
661
+ );
662
+ if (real.length === 0) return readArchive(key);
663
+ const firstUser = real.find((m) => m.role === "USER");
664
+ const entry = {
665
+ token: thread.token,
666
+ title: (firstUser?.content ?? "Conversation").trim().slice(0, 80),
667
+ updatedAt: real[real.length - 1]?.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
668
+ messageCount: real.length,
669
+ focusProduct: thread.focusProduct,
670
+ messages: real.slice(-20)
671
+ };
672
+ const rest = readArchive(key).filter((e) => e.token !== entry.token);
673
+ const next = [entry, ...rest].slice(0, MAX_ARCHIVED_CONVERSATIONS);
674
+ writeArchive(key, next);
675
+ return next;
676
+ }
677
+ function readPersisted(key) {
678
+ if (typeof window === "undefined") return null;
679
+ try {
680
+ const raw = window.localStorage.getItem(key);
681
+ if (!raw) return null;
682
+ const parsed = JSON.parse(raw);
683
+ if (!parsed || typeof parsed !== "object") return null;
684
+ const record = parsed;
685
+ return {
686
+ conversationToken: typeof record.conversationToken === "string" ? record.conversationToken : null,
687
+ messages: Array.isArray(record.messages) ? record.messages.slice(-MAX_PERSISTED_MESSAGES) : [],
688
+ focusProduct: typeof record.focusProduct === "string" ? record.focusProduct : null
689
+ };
690
+ } catch {
691
+ return null;
692
+ }
693
+ }
694
+ function readShareToken() {
695
+ if (typeof window === "undefined") return null;
696
+ try {
697
+ return new URL(window.location.href).searchParams.get("c");
698
+ } catch {
699
+ return null;
700
+ }
701
+ }
702
+ function visibleText(message) {
703
+ return message.content || message.partialContent || "";
704
+ }
705
+ function countUserTurns(messages) {
706
+ return messages.filter((m) => m.role === "USER").length;
707
+ }
708
+ function useExploreChat(options = {}) {
709
+ const {
710
+ productSlug,
711
+ pageUrl,
712
+ locale,
713
+ examplePrompts,
714
+ fallbackWelcome,
715
+ pollIntervalMs = DEFAULT_POLL_INTERVAL_MS,
716
+ pollTimeoutMs = DEFAULT_POLL_TIMEOUT_MS,
717
+ storageKey = DEFAULT_STORAGE_KEY,
718
+ persist = true,
719
+ onSend,
720
+ enabled = true,
721
+ shareToken: shareTokenOption
722
+ } = options;
723
+ const client = useWebSDK();
724
+ const { productId } = useWebSDKConfig();
725
+ const promptKey = JSON.stringify(examplePrompts ?? []);
726
+ const welcomeKey = JSON.stringify(fallbackWelcome ?? null);
727
+ const fallbackCatalog = useMemo(
728
+ () => buildFallbackCatalog(
729
+ JSON.parse(promptKey),
730
+ JSON.parse(welcomeKey) ?? void 0
731
+ ),
732
+ [promptKey, welcomeKey]
733
+ );
734
+ const [bakedRaw] = useState(
735
+ () => readBakedCatalog(productSlug)
736
+ );
737
+ const [catalog, setCatalog] = useState(
738
+ () => bakedRaw ? normalizeCatalog(bakedRaw, fallbackCatalog) : fallbackCatalog
739
+ );
740
+ const [serverCatalogRaw, setServerCatalogRaw] = useState(bakedRaw);
741
+ const [messages, setMessages] = useState([]);
742
+ const [phase, setPhase] = useState(
743
+ () => bakedRaw ? bakedRaw.enabled === false ? "disabled" : "ready" : "loading"
744
+ );
745
+ const [error, setError] = useState(null);
746
+ const [remainingToday, setRemainingToday] = useState(null);
747
+ const [focusProduct, setFocusProductState] = useState(null);
748
+ const [turnCount, setTurnCount] = useState(0);
749
+ const messagesRef = useRef([]);
750
+ const [archive, setArchive] = useState([]);
751
+ const [hydrated, setHydrated] = useState(false);
752
+ const mountedRef = useRef(true);
753
+ const pollGenerationRef = useRef(0);
754
+ const pollTimerRef = useRef(null);
755
+ const conversationTokenRef = useRef(null);
756
+ const [hasConversation, setHasConversation] = useState(false);
757
+ const shareTokenRef = useRef(void 0);
758
+ if (shareTokenRef.current === void 0) {
759
+ shareTokenRef.current = shareTokenOption === void 0 ? readShareToken() : shareTokenOption;
760
+ }
761
+ const isSharedView = shareTokenRef.current !== null;
762
+ const catalogRef = useRef(catalog);
763
+ const turnCountRef = useRef(0);
764
+ const focusProductRef = useRef(null);
765
+ const lastSentTextRef = useRef(null);
766
+ const lastSentAttachmentsRef = useRef(
767
+ []
768
+ );
769
+ const inFlightRef = useRef(false);
770
+ catalogRef.current = catalog;
771
+ const rememberConversationToken = useCallback((token) => {
772
+ conversationTokenRef.current = token;
773
+ setHasConversation(token !== null);
774
+ }, []);
775
+ const clearPollTimer = useCallback(() => {
776
+ if (pollTimerRef.current !== null) {
777
+ clearTimeout(pollTimerRef.current);
778
+ pollTimerRef.current = null;
779
+ }
780
+ }, []);
781
+ const cancelPolling = useCallback(() => {
782
+ pollGenerationRef.current += 1;
783
+ clearPollTimer();
784
+ }, [clearPollTimer]);
785
+ useEffect(() => {
786
+ mountedRef.current = true;
787
+ return () => {
788
+ mountedRef.current = false;
789
+ pollGenerationRef.current += 1;
790
+ if (pollTimerRef.current !== null) {
791
+ clearTimeout(pollTimerRef.current);
792
+ pollTimerRef.current = null;
793
+ }
794
+ };
795
+ }, []);
796
+ useEffect(() => {
797
+ if (!enabled) return;
798
+ const shareToken = shareTokenRef.current;
799
+ if (!shareToken) return;
800
+ let cancelled = false;
801
+ setHydrated(true);
802
+ void client.query(
803
+ EXPLORE_SHARED_CONVERSATION_QUERY,
804
+ { shareToken },
805
+ { cache: false }
806
+ ).then((res) => {
807
+ if (cancelled || !mountedRef.current) return;
808
+ const shared = res?.data?.exploreSharedConversation;
809
+ if (shared && shared.length > 0) {
810
+ setMessages(shared);
811
+ return;
812
+ }
813
+ setError({
814
+ kind: "unknown",
815
+ code: "SHARE_NOT_FOUND",
816
+ message: "That shared conversation could not be found. The link may have expired.",
817
+ // Nothing to retry: a bad token will stay bad.
818
+ retryable: false
819
+ });
820
+ }).catch(() => {
821
+ if (cancelled || !mountedRef.current) return;
822
+ setError({
823
+ kind: "unknown",
824
+ code: "SHARE_NOT_FOUND",
825
+ message: "That shared conversation could not be loaded.",
826
+ retryable: true
827
+ });
828
+ });
829
+ return () => {
830
+ cancelled = true;
831
+ };
832
+ }, [client, enabled]);
833
+ useEffect(() => {
834
+ if (!enabled) return;
835
+ if (shareTokenRef.current !== null) return;
836
+ if (!persist) {
837
+ setHydrated(true);
838
+ return;
839
+ }
840
+ setArchive(readArchive(storageKey));
841
+ const stored = readPersisted(storageKey);
842
+ if (stored) {
843
+ rememberConversationToken(stored.conversationToken);
844
+ focusProductRef.current = stored.focusProduct;
845
+ const settled = stored.messages.flatMap((m) => {
846
+ if (m.role !== "ASSISTANT") return [m];
847
+ if (m.status !== "PENDING" && m.status !== "RUNNING") return [m];
848
+ const text = visibleText(m);
849
+ if (!text) return [];
850
+ return [{ ...m, status: "COMPLETED", content: text }];
851
+ });
852
+ setMessages(settled);
853
+ setFocusProductState(stored.focusProduct);
854
+ const turns = countUserTurns(settled);
855
+ turnCountRef.current = turns;
856
+ setTurnCount(turns);
857
+ }
858
+ setHydrated(true);
859
+ }, [persist, rememberConversationToken, storageKey, enabled]);
860
+ useEffect(() => {
861
+ if (!persist || !hydrated || isSharedView || typeof window === "undefined")
862
+ return;
863
+ try {
864
+ const payload = {
865
+ conversationToken: conversationTokenRef.current,
866
+ messages: messages.slice(-MAX_PERSISTED_MESSAGES),
867
+ focusProduct
868
+ };
869
+ if (!payload.conversationToken && payload.messages.length === 0 && !payload.focusProduct) {
870
+ window.localStorage.removeItem(storageKey);
871
+ return;
872
+ }
873
+ window.localStorage.setItem(storageKey, JSON.stringify(payload));
874
+ } catch {
875
+ }
876
+ }, [persist, hydrated, isSharedView, storageKey, messages, focusProduct]);
877
+ useEffect(() => {
878
+ messagesRef.current = messages;
879
+ if (!persist || !hydrated || isSharedView) return;
880
+ const settled = messages.some(
881
+ (m) => m.role === "ASSISTANT" && (m.status === "COMPLETED" || m.status === "FAILED")
882
+ );
883
+ if (!settled) return;
884
+ setArchive(
885
+ upsertArchive(storageKey, {
886
+ token: conversationTokenRef.current,
887
+ messages,
888
+ focusProduct: focusProductRef.current
889
+ })
890
+ );
891
+ }, [messages, persist, hydrated, isSharedView, storageKey]);
892
+ useEffect(() => {
893
+ if (!enabled) return;
894
+ let cancelled = false;
895
+ const load = async () => {
896
+ const variables = { productSlug: productSlug ?? null };
897
+ let res = await client.query(
898
+ EXPLORE_CATALOG_QUERY,
899
+ variables
900
+ );
901
+ if (cancelled || !mountedRef.current) return;
902
+ if (catalogRejectedTheHighlightField(res)) {
903
+ res = await client.query(
904
+ EXPLORE_CATALOG_QUERY_WITHOUT_HIGHLIGHTS,
905
+ variables
906
+ );
907
+ if (cancelled || !mountedRef.current) return;
908
+ }
909
+ const raw = res.data?.exploreCatalog;
910
+ if (res.errors?.length || !raw) {
911
+ console.warn(
912
+ "[WebSDK] exploreCatalog unavailable \u2014 keeping the catalog the page started with",
913
+ res.errors?.[0]?.message
914
+ );
915
+ setPhase((prev) => prev === "loading" ? "ready" : prev);
916
+ return;
917
+ }
918
+ const next = normalizeCatalog(
919
+ raw,
920
+ bakedRaw ? normalizeCatalog(bakedRaw, fallbackCatalog) : fallbackCatalog
921
+ );
922
+ setCatalog(next);
923
+ setServerCatalogRaw(raw);
924
+ catalogRef.current = next;
925
+ setPhase((prev) => {
926
+ if (!next.enabled) return "disabled";
927
+ return prev === "loading" || prev === "disabled" ? "ready" : prev;
928
+ });
929
+ };
930
+ void load();
931
+ return () => {
932
+ cancelled = true;
933
+ };
934
+ }, [client, productSlug, fallbackCatalog, bakedRaw, enabled]);
935
+ const startPolling = useCallback(
936
+ (conversationToken, messageId) => {
937
+ pollGenerationRef.current += 1;
938
+ const generation = pollGenerationRef.current;
939
+ const startedAt = Date.now();
940
+ let consecutiveFailures = 0;
941
+ const isStale = () => !mountedRef.current || generation !== pollGenerationRef.current;
942
+ const finishWithError = (chatError) => {
943
+ inFlightRef.current = false;
944
+ setMessages(
945
+ (prev) => prev.flatMap((m) => {
946
+ if (m.id !== messageId) return [m];
947
+ const text = visibleText(m);
948
+ if (!text) return [];
949
+ return [{ ...m, status: "FAILED", content: text }];
950
+ })
951
+ );
952
+ setError(chatError);
953
+ setPhase(chatError.kind === "rate-limit" ? "limited" : "error");
954
+ };
955
+ const tick = async () => {
956
+ if (isStale()) return;
957
+ if (Date.now() - startedAt > pollTimeoutMs) {
958
+ finishWithError(classifyExploreError("TIMEOUT"));
959
+ return;
960
+ }
961
+ const res = await client.query(
962
+ EXPLORE_MESSAGE_QUERY,
963
+ { conversationToken, id: messageId },
964
+ { cache: false, timeoutMs: POLL_REQUEST_TIMEOUT_MS }
965
+ );
966
+ if (isStale()) return;
967
+ const first = res.errors?.[0];
968
+ if (first) {
969
+ const code = typeof first.extensions?.code === "string" ? first.extensions.code : void 0;
970
+ const classified = classifyExploreError(code, first.message);
971
+ if (!classified.retryable) {
972
+ finishWithError(classified);
973
+ return;
974
+ }
975
+ consecutiveFailures += 1;
976
+ if (consecutiveFailures >= MAX_CONSECUTIVE_POLL_FAILURES) {
977
+ finishWithError(classified);
978
+ return;
979
+ }
980
+ pollTimerRef.current = setTimeout(() => void tick(), pollIntervalMs);
981
+ return;
982
+ }
983
+ const message = res.data?.exploreMessage;
984
+ if (!message) {
985
+ consecutiveFailures += 1;
986
+ if (consecutiveFailures >= MAX_CONSECUTIVE_POLL_FAILURES) {
987
+ finishWithError(classifyExploreError("NOT_FOUND"));
988
+ return;
989
+ }
990
+ pollTimerRef.current = setTimeout(() => void tick(), pollIntervalMs);
991
+ return;
992
+ }
993
+ consecutiveFailures = 0;
994
+ setMessages(
995
+ (prev) => prev.map((m) => m.id === messageId ? message : m)
996
+ );
997
+ if (message.status === "COMPLETED") {
998
+ inFlightRef.current = false;
999
+ setError(null);
1000
+ setPhase("ready");
1001
+ return;
1002
+ }
1003
+ if (message.status === "FAILED") {
1004
+ finishWithError(
1005
+ classifyExploreError(message.errorCode ?? "UPSTREAM_UNAVAILABLE")
1006
+ );
1007
+ return;
1008
+ }
1009
+ setPhase("streaming");
1010
+ pollTimerRef.current = setTimeout(() => void tick(), pollIntervalMs);
1011
+ };
1012
+ pollTimerRef.current = setTimeout(() => void tick(), pollIntervalMs);
1013
+ },
1014
+ [client, pollIntervalMs, pollTimeoutMs]
1015
+ );
1016
+ const submit = useCallback(
1017
+ async (text, optimisticId, captchaAttempt, attachments) => {
1018
+ const activeCatalog = catalogRef.current;
1019
+ let recaptchaToken;
1020
+ if (activeCatalog.captchaRequired && activeCatalog.recaptchaSiteKey) {
1021
+ try {
1022
+ recaptchaToken = await getRecaptchaV3Token(
1023
+ activeCatalog.recaptchaSiteKey
1024
+ );
1025
+ } catch (err) {
1026
+ console.warn("[WebSDK] reCAPTCHA v3 token could not be minted", err);
1027
+ }
1028
+ }
1029
+ const input = {
1030
+ message: text,
1031
+ ...conversationTokenRef.current ? { conversationToken: conversationTokenRef.current } : {},
1032
+ ...focusProductRef.current || productSlug ? { productSlug: focusProductRef.current ?? productSlug } : {},
1033
+ ...recaptchaToken ? { recaptchaToken } : {},
1034
+ ...locale ? { locale } : {},
1035
+ ...pageUrl ? { pageUrl } : {},
1036
+ ...attachments.length > 0 ? { attachments: [...attachments] } : {}
1037
+ };
1038
+ const res = await client.mutate(
1039
+ SEND_EXPLORE_MESSAGE_MUTATION,
1040
+ { input },
1041
+ { timeoutMs: SEND_REQUEST_TIMEOUT_MS }
1042
+ );
1043
+ if (!mountedRef.current) return;
1044
+ const first = res.errors?.[0];
1045
+ const result = res.data?.sendExploreMessage;
1046
+ if (first || !result) {
1047
+ const code = typeof first?.extensions?.code === "string" ? first.extensions.code : void 0;
1048
+ const classified = classifyExploreError(code, first?.message);
1049
+ if (classified.kind === "captcha" && captchaAttempt === 0) {
1050
+ await submit(text, optimisticId, 1, attachments);
1051
+ return;
1052
+ }
1053
+ inFlightRef.current = false;
1054
+ setError(classified);
1055
+ setPhase(classified.kind === "rate-limit" ? "limited" : "error");
1056
+ return;
1057
+ }
1058
+ rememberConversationToken(result.conversation.token);
1059
+ turnCountRef.current = result.conversation.turnCount;
1060
+ setTurnCount(result.conversation.turnCount);
1061
+ setRemainingToday(result.remainingToday ?? null);
1062
+ const userMessage = result.userMessage;
1063
+ const assistantMessage = result.assistantMessage;
1064
+ setMessages((prev) => {
1065
+ const replaced = prev.some((m) => m.id === optimisticId) ? prev.map((m) => m.id === optimisticId ? userMessage : m) : [...prev, userMessage];
1066
+ return [...replaced, assistantMessage];
1067
+ });
1068
+ if (assistantMessage.status === "COMPLETED" || assistantMessage.status === "FAILED") {
1069
+ inFlightRef.current = false;
1070
+ if (assistantMessage.status === "FAILED") {
1071
+ const classified = classifyExploreError(
1072
+ assistantMessage.errorCode ?? "UPSTREAM_UNAVAILABLE"
1073
+ );
1074
+ setError(classified);
1075
+ setPhase("error");
1076
+ } else {
1077
+ setPhase("ready");
1078
+ }
1079
+ return;
1080
+ }
1081
+ setPhase("streaming");
1082
+ startPolling(result.conversation.token, assistantMessage.id);
1083
+ },
1084
+ [
1085
+ client,
1086
+ locale,
1087
+ pageUrl,
1088
+ productSlug,
1089
+ rememberConversationToken,
1090
+ startPolling
1091
+ ]
1092
+ );
1093
+ const send = useCallback(
1094
+ async (message, attachments = []) => {
1095
+ const text = message.trim();
1096
+ if (!text) return;
1097
+ if (inFlightRef.current) return;
1098
+ const activeCatalog = catalogRef.current;
1099
+ if (!activeCatalog.enabled) {
1100
+ setError(classifyExploreError("EXPLORE_DISABLED"));
1101
+ setPhase("disabled");
1102
+ return;
1103
+ }
1104
+ if (text.length > activeCatalog.limits.maxMessageLength) {
1105
+ setError({
1106
+ kind: "validation",
1107
+ code: "MESSAGE_TOO_LONG",
1108
+ message: `That message is ${text.length} characters \u2014 the limit is ${activeCatalog.limits.maxMessageLength}.`,
1109
+ retryable: false
1110
+ });
1111
+ return;
1112
+ }
1113
+ if (turnCountRef.current >= activeCatalog.limits.maxTurnsPerConversation) {
1114
+ setError({
1115
+ kind: "validation",
1116
+ code: "CONVERSATION_LIMIT",
1117
+ message: `This conversation has reached its ${activeCatalog.limits.maxTurnsPerConversation}-message limit. Start a new chat to keep going.`,
1118
+ retryable: false
1119
+ });
1120
+ return;
1121
+ }
1122
+ inFlightRef.current = true;
1123
+ lastSentTextRef.current = text;
1124
+ lastSentAttachmentsRef.current = attachments;
1125
+ setError(null);
1126
+ setPhase("sending");
1127
+ cancelPolling();
1128
+ const optimistic = {
1129
+ id: makeOptimisticId(),
1130
+ conversationId: conversationTokenRef.current ?? "pending",
1131
+ role: "USER",
1132
+ status: "COMPLETED",
1133
+ content: text,
1134
+ partialContent: null,
1135
+ activity: [],
1136
+ references: [],
1137
+ ctas: [],
1138
+ errorCode: null,
1139
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
1140
+ completedAt: (/* @__PURE__ */ new Date()).toISOString()
1141
+ };
1142
+ setMessages((prev) => [...prev, optimistic]);
1143
+ turnCountRef.current += 1;
1144
+ setTurnCount(turnCountRef.current);
1145
+ onSend?.(text);
1146
+ try {
1147
+ await submit(text, optimistic.id, 0, attachments);
1148
+ } catch (err) {
1149
+ if (!mountedRef.current) return;
1150
+ console.error("[WebSDK] Explore send failed", err);
1151
+ inFlightRef.current = false;
1152
+ setError(classifyExploreError("NETWORK_ERROR"));
1153
+ setPhase("error");
1154
+ }
1155
+ },
1156
+ [cancelPolling, onSend, submit]
1157
+ );
1158
+ const stop = useCallback(() => {
1159
+ cancelPolling();
1160
+ inFlightRef.current = false;
1161
+ setMessages(
1162
+ (prev) => prev.flatMap((m) => {
1163
+ if (m.role !== "ASSISTANT") return [m];
1164
+ if (m.status !== "PENDING" && m.status !== "RUNNING") return [m];
1165
+ const text = visibleText(m);
1166
+ if (!text) return [];
1167
+ return [
1168
+ {
1169
+ ...m,
1170
+ status: "COMPLETED",
1171
+ content: text,
1172
+ completedAt: (/* @__PURE__ */ new Date()).toISOString()
1173
+ }
1174
+ ];
1175
+ })
1176
+ );
1177
+ setPhase(
1178
+ (prev) => prev === "sending" || prev === "streaming" ? "ready" : prev
1179
+ );
1180
+ }, [cancelPolling]);
1181
+ const retry = useCallback(() => {
1182
+ const text = lastSentTextRef.current;
1183
+ if (!text) return;
1184
+ cancelPolling();
1185
+ inFlightRef.current = false;
1186
+ setMessages((prev) => {
1187
+ const next = [...prev];
1188
+ const last = next[next.length - 1];
1189
+ if (last?.role === "ASSISTANT" && last.status === "FAILED") next.pop();
1190
+ const prior = next[next.length - 1];
1191
+ if (prior?.role === "USER" && prior.content === text) next.pop();
1192
+ return next;
1193
+ });
1194
+ turnCountRef.current = Math.max(0, turnCountRef.current - 1);
1195
+ setTurnCount(turnCountRef.current);
1196
+ void send(text, lastSentAttachmentsRef.current);
1197
+ }, [cancelPolling, send]);
1198
+ const reset = useCallback(() => {
1199
+ setArchive(
1200
+ upsertArchive(storageKey, {
1201
+ token: conversationTokenRef.current,
1202
+ messages: messagesRef.current,
1203
+ focusProduct: focusProductRef.current
1204
+ })
1205
+ );
1206
+ cancelPolling();
1207
+ inFlightRef.current = false;
1208
+ rememberConversationToken(null);
1209
+ lastSentTextRef.current = null;
1210
+ lastSentAttachmentsRef.current = [];
1211
+ turnCountRef.current = 0;
1212
+ setTurnCount(0);
1213
+ setMessages([]);
1214
+ setError(null);
1215
+ setRemainingToday(null);
1216
+ setPhase(catalogRef.current.enabled ? "ready" : "disabled");
1217
+ if (typeof window !== "undefined") {
1218
+ try {
1219
+ window.localStorage.removeItem(storageKey);
1220
+ } catch {
1221
+ }
1222
+ }
1223
+ }, [cancelPolling, rememberConversationToken, storageKey]);
1224
+ const openConversation = useCallback(
1225
+ (token) => {
1226
+ const entry = readArchive(storageKey).find((e) => e.token === token);
1227
+ if (!entry) return;
1228
+ upsertArchive(storageKey, {
1229
+ token: conversationTokenRef.current,
1230
+ messages: messagesRef.current,
1231
+ focusProduct: focusProductRef.current
1232
+ });
1233
+ cancelPolling();
1234
+ inFlightRef.current = false;
1235
+ rememberConversationToken(entry.token);
1236
+ turnCountRef.current = entry.messages.filter(
1237
+ (m) => m.role === "USER"
1238
+ ).length;
1239
+ setTurnCount(turnCountRef.current);
1240
+ setMessages(entry.messages);
1241
+ focusProductRef.current = entry.focusProduct;
1242
+ setFocusProductState(entry.focusProduct);
1243
+ setError(null);
1244
+ setPhase(catalogRef.current.enabled ? "ready" : "disabled");
1245
+ setArchive(readArchive(storageKey));
1246
+ },
1247
+ [cancelPolling, rememberConversationToken, storageKey]
1248
+ );
1249
+ const deleteConversation = useCallback(
1250
+ (token) => {
1251
+ const next = readArchive(storageKey).filter((e) => e.token !== token);
1252
+ writeArchive(storageKey, next);
1253
+ setArchive(next);
1254
+ },
1255
+ [storageKey]
1256
+ );
1257
+ const clearHistory = useCallback(() => {
1258
+ writeArchive(storageKey, []);
1259
+ setArchive([]);
1260
+ }, [storageKey]);
1261
+ const setFocusProduct = useCallback((slug) => {
1262
+ focusProductRef.current = slug;
1263
+ setFocusProductState(slug);
1264
+ }, []);
1265
+ const activity = useMemo(() => {
1266
+ for (let i = messages.length - 1; i >= 0; i -= 1) {
1267
+ const m = messages[i];
1268
+ if (!m || m.role !== "ASSISTANT") continue;
1269
+ if (m.status !== "PENDING" && m.status !== "RUNNING") return null;
1270
+ const lines = m.activity ?? [];
1271
+ return lines.length ? lines[lines.length - 1] ?? null : null;
1272
+ }
1273
+ return null;
1274
+ }, [messages]);
1275
+ const canSend = (phase === "ready" || phase === "error") && catalog.enabled && turnCount < catalog.limits.maxTurnsPerConversation;
1276
+ const createShareLink = useCallback(async () => {
1277
+ const token = conversationTokenRef.current;
1278
+ if (!token) return null;
1279
+ try {
1280
+ const result = await client.mutate(CREATE_EXPLORE_SHARE_LINK_MUTATION, { conversationToken: token });
1281
+ return result?.data?.createExploreShareLink?.shareToken ?? null;
1282
+ } catch {
1283
+ return null;
1284
+ }
1285
+ }, [client]);
1286
+ const recordClick = useCallback(
1287
+ (messageId, kind, url) => {
1288
+ const token = conversationTokenRef.current;
1289
+ if (!token) return;
1290
+ try {
1291
+ void client.mutate(RECORD_EXPLORE_CLICK_MUTATION, {
1292
+ input: { conversationToken: token, messageId, kind, url }
1293
+ }).catch(() => {
1294
+ });
1295
+ } catch {
1296
+ }
1297
+ },
1298
+ [client]
1299
+ );
1300
+ const submitFeedback = useCallback(
1301
+ async (messageId, rating, detail) => {
1302
+ const token = conversationTokenRef.current;
1303
+ if (!token) return false;
1304
+ const comment = detail?.comment?.trim();
1305
+ const input = {
1306
+ conversationToken: token,
1307
+ messageId,
1308
+ rating,
1309
+ // Only meaningful with NOT_HELPFUL. The server stores null for HELPFUL either
1310
+ // way; sending it would just be noise the backend has to defend against.
1311
+ reason: rating === "NOT_HELPFUL" ? detail?.reason ?? null : null,
1312
+ comment: comment ? comment : null
1313
+ };
1314
+ try {
1315
+ const res = await client.mutate(
1316
+ SUBMIT_EXPLORE_FEEDBACK_MUTATION,
1317
+ { input }
1318
+ );
1319
+ const result = res?.data?.submitExploreFeedback;
1320
+ if (!result?.recorded) return false;
1321
+ const recorded = result.feedback;
1322
+ if (recorded && mountedRef.current) {
1323
+ setMessages(
1324
+ (current) => current.map(
1325
+ (message) => message.id === messageId ? { ...message, feedback: recorded } : message
1326
+ )
1327
+ );
1328
+ }
1329
+ return true;
1330
+ } catch {
1331
+ return false;
1332
+ }
1333
+ },
1334
+ [client]
1335
+ );
1336
+ const escalate = useCallback(
1337
+ async (email, note) => {
1338
+ const token = conversationTokenRef.current;
1339
+ if (!token) {
1340
+ return { outcome: "no-conversation", email: null, createdAt: null };
1341
+ }
1342
+ const attempt = async (captchaAttempt) => {
1343
+ const activeCatalog = catalogRef.current;
1344
+ let recaptchaToken;
1345
+ if (activeCatalog.captchaRequired && activeCatalog.recaptchaSiteKey) {
1346
+ try {
1347
+ recaptchaToken = await getRecaptchaV3Token(
1348
+ activeCatalog.recaptchaSiteKey
1349
+ );
1350
+ } catch (err) {
1351
+ console.warn(
1352
+ "[WebSDK] reCAPTCHA v3 token could not be minted",
1353
+ err
1354
+ );
1355
+ }
1356
+ }
1357
+ const input = {
1358
+ conversationToken: token,
1359
+ email: email.trim(),
1360
+ note: note?.trim() ? note.trim() : null,
1361
+ ...recaptchaToken ? { recaptchaToken } : {},
1362
+ ...productId ? { productId } : {}
1363
+ };
1364
+ try {
1365
+ const res = await client.mutate(
1366
+ ESCALATE_EXPLORE_CONVERSATION_MUTATION,
1367
+ { input }
1368
+ );
1369
+ const first = res?.errors?.[0];
1370
+ const result = res?.data?.escalateExploreConversation;
1371
+ if (first || !result) {
1372
+ const code = typeof first?.extensions?.code === "string" ? first.extensions.code : "ESCALATION_FAILED";
1373
+ if (code === "CAPTCHA_FAILED" && captchaAttempt === 0) {
1374
+ return attempt(1);
1375
+ }
1376
+ return {
1377
+ outcome: escalateOutcomeForCode(code),
1378
+ email: null,
1379
+ createdAt: null
1380
+ };
1381
+ }
1382
+ return {
1383
+ // `created: false` is the double-click, the retry, the reload. The handover
1384
+ // exists, so this is a success — and the address comes from the SERVER, because
1385
+ // on a repeat submit the reply goes to whatever the FIRST handover used.
1386
+ outcome: result.created ? "sent" : "already-handed-over",
1387
+ email: result.escalation?.email ?? null,
1388
+ createdAt: result.escalation?.createdAt ?? null
1389
+ };
1390
+ } catch {
1391
+ return { outcome: "failed", email: null, createdAt: null };
1392
+ }
1393
+ };
1394
+ return attempt(0);
1395
+ },
1396
+ [client, productId]
1397
+ );
1398
+ const canEscalate = hasConversation && !isSharedView;
1399
+ const getConversationToken = useCallback(
1400
+ () => conversationTokenRef.current,
1401
+ []
1402
+ );
1403
+ return {
1404
+ phase,
1405
+ catalog,
1406
+ serverCatalogRaw,
1407
+ messages,
1408
+ activity,
1409
+ remainingToday,
1410
+ error,
1411
+ focusProduct,
1412
+ setFocusProduct,
1413
+ send,
1414
+ stop,
1415
+ retry,
1416
+ reset,
1417
+ canSend,
1418
+ history: archive,
1419
+ openConversation,
1420
+ deleteConversation,
1421
+ clearHistory,
1422
+ recordClick,
1423
+ submitFeedback,
1424
+ escalate,
1425
+ canEscalate,
1426
+ createShareLink,
1427
+ isSharedView,
1428
+ getConversationToken
1429
+ };
1430
+ }
1431
+ var optimisticCounter = 0;
1432
+ function makeOptimisticId() {
1433
+ optimisticCounter += 1;
1434
+ return `boff-explore-local-${Date.now()}-${optimisticCounter}`;
1435
+ }
1436
+ var DRAIN_TARGET_MS = 1200;
1437
+ var MIN_CHARS_PER_SECOND = 90;
1438
+ var MAX_CHARS_PER_SECOND = 2200;
1439
+ var MAX_STEP_MS = 250;
1440
+ var COMMIT_INTERVAL_MS = 45;
1441
+ var FALLBACK_STEP_MS = 50;
1442
+ var FENCE = /^ {0,3}(?:```|~~~)/;
1443
+ var TABLE_ROW = /^ {0,3}\|/;
1444
+ var EMPTY_BLOCK_MARKER = /^ {0,3}(?:[-+>]|#{1,6}|\d{1,9}[.)])\s*$/;
1445
+ function isWordCharacter(char) {
1446
+ return char !== void 0 && /[\p{L}\p{N}]/u.test(char);
1447
+ }
1448
+ function clamp(value, min, max) {
1449
+ return Math.min(Math.max(value, min), max);
1450
+ }
1451
+ function now() {
1452
+ return typeof performance !== "undefined" && typeof performance.now === "function" ? performance.now() : Date.now();
1453
+ }
1454
+ function isHighSurrogate(code) {
1455
+ return code >= 55296 && code <= 56319;
1456
+ }
1457
+ function safeInlineEnd(line) {
1458
+ let codeSpan = null;
1459
+ const links = [];
1460
+ const emphasis = [];
1461
+ let at = 0;
1462
+ while (at < line.length) {
1463
+ const char = line[at] ?? "";
1464
+ if (char === "\\") {
1465
+ at += 2;
1466
+ continue;
1467
+ }
1468
+ const innermost = links[links.length - 1];
1469
+ if (innermost !== void 0 && innermost.kind !== "label") {
1470
+ if (char === "(") links.push({ kind: "paren", start: innermost.start });
1471
+ else if (char === ")") links.pop();
1472
+ at += 1;
1473
+ continue;
1474
+ }
1475
+ if (char === "`") {
1476
+ let run = 1;
1477
+ while (line[at + run] === "`") run += 1;
1478
+ codeSpan = codeSpan === null ? at : null;
1479
+ at += run;
1480
+ continue;
1481
+ }
1482
+ if (codeSpan !== null) {
1483
+ at += 1;
1484
+ continue;
1485
+ }
1486
+ if (char === "[") {
1487
+ links.push({ kind: "label", start: line[at - 1] === "!" ? at - 1 : at });
1488
+ at += 1;
1489
+ continue;
1490
+ }
1491
+ if (char === "]" && innermost !== void 0) {
1492
+ links.pop();
1493
+ if (line[at + 1] === "(") {
1494
+ links.push({ kind: "destination", start: innermost.start });
1495
+ at += 2;
1496
+ continue;
1497
+ }
1498
+ at += 1;
1499
+ continue;
1500
+ }
1501
+ if (char === "*" || char === "_" || char === "~") {
1502
+ let run = 1;
1503
+ while (line[at + run] === char) run += 1;
1504
+ const start = at;
1505
+ at += run;
1506
+ const before = line[start - 1];
1507
+ const after = line[start + run];
1508
+ if (run < 2) continue;
1509
+ if (char === "_" && isWordCharacter(before) && isWordCharacter(after)) {
1510
+ continue;
1511
+ }
1512
+ const marker = char.repeat(run);
1513
+ const open2 = emphasis.findIndex((entry) => entry.marker === marker);
1514
+ if (open2 !== -1) {
1515
+ emphasis.splice(open2, 1);
1516
+ continue;
1517
+ }
1518
+ if (after !== void 0 && /\s/.test(after)) continue;
1519
+ emphasis.push({ marker, start });
1520
+ continue;
1521
+ }
1522
+ at += 1;
1523
+ }
1524
+ const open = [
1525
+ codeSpan,
1526
+ links[0]?.start ?? null,
1527
+ emphasis[0]?.start ?? null
1528
+ ].filter((value) => value !== null);
1529
+ return open.length === 0 ? line.length : Math.min(...open);
1530
+ }
1531
+ function revealBoundary(text, limit) {
1532
+ if (limit <= 0) return 0;
1533
+ const caughtUp = limit >= text.length;
1534
+ const head = caughtUp ? text : text.slice(0, limit);
1535
+ const lineStart = head.lastIndexOf("\n") + 1;
1536
+ const line = head.slice(lineStart);
1537
+ let fenceStart = null;
1538
+ let tableStart = null;
1539
+ let tableRows = 0;
1540
+ let at = 0;
1541
+ while (at < lineStart) {
1542
+ const breakAt = head.indexOf("\n", at);
1543
+ const end = breakAt === -1 ? lineStart : breakAt;
1544
+ const row = head.slice(at, end);
1545
+ if (fenceStart !== null) {
1546
+ if (FENCE.test(row)) fenceStart = null;
1547
+ } else if (FENCE.test(row)) {
1548
+ fenceStart = at;
1549
+ } else if (TABLE_ROW.test(row)) {
1550
+ if (tableStart === null) {
1551
+ tableStart = at;
1552
+ tableRows = 0;
1553
+ }
1554
+ tableRows += 1;
1555
+ } else if (tableStart !== null) {
1556
+ tableStart = null;
1557
+ tableRows = 0;
1558
+ }
1559
+ at = end + 1;
1560
+ }
1561
+ if (fenceStart === null) {
1562
+ const lastIsRow = TABLE_ROW.test(line);
1563
+ if (lastIsRow && tableStart === null) {
1564
+ tableStart = lineStart;
1565
+ tableRows = 0;
1566
+ } else if (!lastIsRow && line !== "") {
1567
+ tableStart = null;
1568
+ tableRows = 0;
1569
+ }
1570
+ if (tableStart !== null && tableRows < 2) return tableStart;
1571
+ }
1572
+ if (caughtUp) return text.length;
1573
+ if (fenceStart !== null) return fenceStart;
1574
+ if (TABLE_ROW.test(line)) return lineStart;
1575
+ if (EMPTY_BLOCK_MARKER.test(line)) return lineStart;
1576
+ const cut = lineStart + safeInlineEnd(line);
1577
+ return isHighSurrogate(text.charCodeAt(cut - 1)) ? cut - 1 : cut;
1578
+ }
1579
+ function prefersReducedMotion() {
1580
+ if (typeof window === "undefined") return true;
1581
+ try {
1582
+ return window.matchMedia?.("(prefers-reduced-motion: reduce)").matches === true;
1583
+ } catch {
1584
+ return false;
1585
+ }
1586
+ }
1587
+ function useProgressiveReveal(text, settled) {
1588
+ const [, setFrame] = useState(0);
1589
+ const [reduced] = useState(prefersReducedMotion);
1590
+ const immediate = settled || reduced;
1591
+ const textRef = useRef(text);
1592
+ const cursorRef = useRef(immediate ? text.length : 0);
1593
+ const cutRef = useRef(immediate ? text.length : 0);
1594
+ const committedRef = useRef(0);
1595
+ if (text !== textRef.current) {
1596
+ const revealed = textRef.current.slice(0, Math.floor(cursorRef.current));
1597
+ if (revealed !== "" && !text.startsWith(revealed)) {
1598
+ cursorRef.current = text.length;
1599
+ }
1600
+ cursorRef.current = Math.min(cursorRef.current, text.length);
1601
+ cutRef.current = Math.min(cutRef.current, text.length);
1602
+ textRef.current = text;
1603
+ }
1604
+ if (immediate) cursorRef.current = text.length;
1605
+ const cut = immediate ? text.length : Math.max(
1606
+ cutRef.current,
1607
+ revealBoundary(text, Math.floor(cursorRef.current))
1608
+ );
1609
+ cutRef.current = cut;
1610
+ useEffect(() => {
1611
+ if (immediate) return;
1612
+ if (cursorRef.current >= text.length) return;
1613
+ let cancelled = false;
1614
+ let cancelStep = null;
1615
+ let previous = now();
1616
+ const commit = (at, force) => {
1617
+ if (!force && at - committedRef.current < COMMIT_INTERVAL_MS) return;
1618
+ committedRef.current = at;
1619
+ setFrame((value) => value + 1);
1620
+ };
1621
+ const step = () => {
1622
+ cancelStep = null;
1623
+ if (cancelled) return;
1624
+ const at = now();
1625
+ const elapsed = clamp(at - previous, 0, MAX_STEP_MS);
1626
+ previous = at;
1627
+ const length = textRef.current.length;
1628
+ const pending = length - cursorRef.current;
1629
+ if (pending <= 0) {
1630
+ commit(at, true);
1631
+ return;
1632
+ }
1633
+ const perSecond = clamp(
1634
+ pending / (DRAIN_TARGET_MS / 1e3),
1635
+ MIN_CHARS_PER_SECOND,
1636
+ MAX_CHARS_PER_SECOND
1637
+ );
1638
+ cursorRef.current = Math.min(
1639
+ length,
1640
+ cursorRef.current + perSecond * elapsed / 1e3
1641
+ );
1642
+ const done = cursorRef.current >= length;
1643
+ commit(at, done);
1644
+ if (!done) schedule();
1645
+ };
1646
+ const schedule = () => {
1647
+ if (typeof window.requestAnimationFrame === "function") {
1648
+ const id2 = window.requestAnimationFrame(step);
1649
+ cancelStep = () => window.cancelAnimationFrame(id2);
1650
+ return;
1651
+ }
1652
+ const id = setTimeout(step, FALLBACK_STEP_MS);
1653
+ cancelStep = () => clearTimeout(id);
1654
+ };
1655
+ schedule();
1656
+ return () => {
1657
+ cancelled = true;
1658
+ cancelStep?.();
1659
+ };
1660
+ }, [text, immediate]);
1661
+ return text.slice(0, cut);
1662
+ }
1663
+ function getRecognitionCtor() {
1664
+ if (typeof window === "undefined") return null;
1665
+ const w = window;
1666
+ return w.SpeechRecognition ?? w.webkitSpeechRecognition ?? null;
1667
+ }
1668
+ function isTouchDevice() {
1669
+ if (typeof window === "undefined" || !window.matchMedia) return false;
1670
+ try {
1671
+ return window.matchMedia("(pointer: coarse)").matches;
1672
+ } catch {
1673
+ return false;
1674
+ }
1675
+ }
1676
+ var MIC_DENIED_MESSAGE = "Microphone access was blocked. Allow it in your browser's site settings to dictate.";
1677
+ var MIC_UNAVAILABLE_MESSAGE = "Dictation isn't available in this browser. You can type instead.";
1678
+ var RELEASE_SETTLE_MS = 250;
1679
+ var RETRY_DELAY_MS = 350;
1680
+ var sleep = (ms) => new Promise((resolve) => {
1681
+ setTimeout(resolve, ms);
1682
+ });
1683
+ async function ensureMicrophoneAccess() {
1684
+ const media = typeof navigator === "undefined" ? void 0 : navigator.mediaDevices;
1685
+ if (!media?.getUserMedia)
1686
+ return { ok: true, confirmed: false, primed: false };
1687
+ try {
1688
+ const status = await navigator.permissions?.query({
1689
+ name: "microphone"
1690
+ });
1691
+ if (status?.state === "granted")
1692
+ return { ok: true, confirmed: true, primed: false };
1693
+ } catch {
1694
+ }
1695
+ try {
1696
+ const stream = await media.getUserMedia({ audio: true });
1697
+ for (const track of stream.getTracks()) track.stop();
1698
+ return { ok: true, confirmed: true, primed: true };
1699
+ } catch (error) {
1700
+ const name = typeof error === "object" && error !== null && "name" in error ? String(error.name) : "";
1701
+ if (name === "NotAllowedError" || name === "SecurityError") {
1702
+ return { ok: false, message: MIC_DENIED_MESSAGE };
1703
+ }
1704
+ if (name === "NotFoundError" || name === "DevicesNotFoundError") {
1705
+ return { ok: false, message: "No microphone was found." };
1706
+ }
1707
+ return {
1708
+ ok: false,
1709
+ message: "Dictation could not start. You can type instead."
1710
+ };
1711
+ }
1712
+ }
1713
+ function describeError(code) {
1714
+ switch (code) {
1715
+ case "not-allowed":
1716
+ case "service-not-allowed":
1717
+ return MIC_DENIED_MESSAGE;
1718
+ case "no-speech":
1719
+ return "I didn't catch anything \u2014 try again a little closer to the mic.";
1720
+ case "audio-capture":
1721
+ return "No microphone was found.";
1722
+ case "network":
1723
+ return "Speech recognition needs a network connection.";
1724
+ case "aborted":
1725
+ return "";
1726
+ default:
1727
+ return "Dictation stopped unexpectedly. You can type instead.";
1728
+ }
1729
+ }
1730
+ function useSpeechInput({
1731
+ onFinalTranscript,
1732
+ lang,
1733
+ onError
1734
+ }) {
1735
+ const [supported] = useState(() => getRecognitionCtor() !== null);
1736
+ const [listening, setListening] = useState(false);
1737
+ const [interim, setInterim] = useState("");
1738
+ const [error, setError] = useState(null);
1739
+ const recognitionRef = useRef(null);
1740
+ const startTokenRef = useRef(0);
1741
+ const micConfirmedRef = useRef(false);
1742
+ const wantsListeningRef = useRef(false);
1743
+ const retriedRef = useRef(false);
1744
+ const finalRef = useRef(onFinalTranscript);
1745
+ const errorRef = useRef(onError);
1746
+ finalRef.current = onFinalTranscript;
1747
+ errorRef.current = onError;
1748
+ const langRef = useRef(lang);
1749
+ langRef.current = lang;
1750
+ const stop = useCallback(() => {
1751
+ startTokenRef.current += 1;
1752
+ wantsListeningRef.current = false;
1753
+ setListening(false);
1754
+ setInterim("");
1755
+ const recognition = recognitionRef.current;
1756
+ if (!recognition) return;
1757
+ try {
1758
+ recognition.stop();
1759
+ } catch {
1760
+ }
1761
+ }, []);
1762
+ const openSession = useCallback((token) => {
1763
+ const Ctor = getRecognitionCtor();
1764
+ if (!Ctor || token !== startTokenRef.current) return;
1765
+ const recognition = new Ctor();
1766
+ recognition.lang = langRef.current ?? (typeof navigator === "undefined" ? "en-US" : navigator.language || "en-US");
1767
+ recognition.continuous = !isTouchDevice();
1768
+ recognition.interimResults = true;
1769
+ recognition.maxAlternatives = 1;
1770
+ recognition.onstart = () => {
1771
+ if (token !== startTokenRef.current) return;
1772
+ setError(null);
1773
+ setListening(true);
1774
+ };
1775
+ recognition.onresult = (event) => {
1776
+ if (token !== startTokenRef.current) return;
1777
+ let settled = "";
1778
+ let pending = "";
1779
+ for (let i = event.resultIndex; i < event.results.length; i += 1) {
1780
+ const result = event.results[i];
1781
+ if (!result) continue;
1782
+ const text = result[0]?.transcript ?? "";
1783
+ if (result.isFinal) settled += text;
1784
+ else pending += text;
1785
+ }
1786
+ setInterim(pending);
1787
+ if (settled.trim() !== "") finalRef.current(settled);
1788
+ };
1789
+ recognition.onerror = (event) => {
1790
+ if (token !== startTokenRef.current) return;
1791
+ if ((event.error === "not-allowed" || event.error === "service-not-allowed") && micConfirmedRef.current && !retriedRef.current) {
1792
+ retriedRef.current = true;
1793
+ void sleep(RETRY_DELAY_MS).then(() => {
1794
+ if (token !== startTokenRef.current || !wantsListeningRef.current)
1795
+ return;
1796
+ openSessionRef.current?.(token);
1797
+ });
1798
+ return;
1799
+ }
1800
+ const message = micConfirmedRef.current && (event.error === "not-allowed" || event.error === "service-not-allowed") ? MIC_UNAVAILABLE_MESSAGE : describeError(event.error);
1801
+ wantsListeningRef.current = false;
1802
+ setListening(false);
1803
+ setInterim("");
1804
+ if (message !== "") {
1805
+ setError(message);
1806
+ errorRef.current?.(message);
1807
+ }
1808
+ };
1809
+ recognition.onend = () => {
1810
+ if (token !== startTokenRef.current) return;
1811
+ setInterim("");
1812
+ if (wantsListeningRef.current && isTouchDevice()) {
1813
+ void sleep(120).then(() => {
1814
+ if (token !== startTokenRef.current || !wantsListeningRef.current)
1815
+ return;
1816
+ openSessionRef.current?.(token);
1817
+ });
1818
+ return;
1819
+ }
1820
+ setListening(false);
1821
+ };
1822
+ recognitionRef.current = recognition;
1823
+ try {
1824
+ recognition.start();
1825
+ } catch {
1826
+ wantsListeningRef.current = false;
1827
+ setListening(false);
1828
+ }
1829
+ }, []);
1830
+ const openSessionRef = useRef(null);
1831
+ openSessionRef.current = openSession;
1832
+ const start = useCallback(() => {
1833
+ if (!getRecognitionCtor()) return;
1834
+ startTokenRef.current += 1;
1835
+ const token = startTokenRef.current;
1836
+ wantsListeningRef.current = true;
1837
+ retriedRef.current = false;
1838
+ micConfirmedRef.current = false;
1839
+ setError(null);
1840
+ setListening(true);
1841
+ void ensureMicrophoneAccess().then(async (access) => {
1842
+ if (token !== startTokenRef.current) return;
1843
+ if (!access.ok) {
1844
+ wantsListeningRef.current = false;
1845
+ setListening(false);
1846
+ setError(access.message);
1847
+ errorRef.current?.(access.message);
1848
+ return;
1849
+ }
1850
+ micConfirmedRef.current = access.confirmed;
1851
+ if (access.primed) {
1852
+ await sleep(RELEASE_SETTLE_MS);
1853
+ if (token !== startTokenRef.current) return;
1854
+ }
1855
+ openSessionRef.current?.(token);
1856
+ });
1857
+ }, []);
1858
+ const toggle = useCallback(() => {
1859
+ if (listening) stop();
1860
+ else start();
1861
+ }, [listening, start, stop]);
1862
+ useEffect(
1863
+ () => () => {
1864
+ startTokenRef.current += 1;
1865
+ wantsListeningRef.current = false;
1866
+ const recognition = recognitionRef.current;
1867
+ if (!recognition) return;
1868
+ recognition.onresult = null;
1869
+ recognition.onerror = null;
1870
+ recognition.onend = null;
1871
+ recognition.onstart = null;
1872
+ try {
1873
+ recognition.abort();
1874
+ } catch {
1875
+ }
1876
+ },
1877
+ []
1878
+ );
1879
+ return { supported, listening, interim, error, start, stop, toggle };
1880
+ }
1881
+ var SILENT_FAILURE_MS = 1500;
1882
+ function speechPlatform() {
1883
+ if (typeof window === "undefined") return null;
1884
+ const scope = window;
1885
+ const synth = scope.speechSynthesis;
1886
+ const Utterance = scope.SpeechSynthesisUtterance;
1887
+ if (!synth || typeof synth.speak !== "function") return null;
1888
+ if (typeof Utterance !== "function") return null;
1889
+ return { synth, Utterance };
1890
+ }
1891
+ function normaliseTag(tag) {
1892
+ return tag.trim().toLowerCase().replace(/_/g, "-");
1893
+ }
1894
+ function primaryOf(tag) {
1895
+ return normaliseTag(tag).split("-")[0] ?? "";
1896
+ }
1897
+ function pickVoice(voices, lang) {
1898
+ const wanted = normaliseTag(lang);
1899
+ if (wanted === "") return null;
1900
+ const primary = primaryOf(wanted);
1901
+ const exact = voices.filter((voice) => normaliseTag(voice.lang) === wanted);
1902
+ const related = voices.filter((voice) => primaryOf(voice.lang) === primary);
1903
+ return exact.find((voice) => voice.default) ?? exact[0] ?? related.find((voice) => voice.default) ?? related[0] ?? null;
1904
+ }
1905
+ var activeOwner = null;
1906
+ var activeStop = null;
1907
+ function stopSpeaking() {
1908
+ activeStop?.();
1909
+ }
1910
+ function useSpeechOutput({
1911
+ lang
1912
+ } = {}) {
1913
+ const [available, setAvailable] = useState(() => speechPlatform() !== null);
1914
+ const [speaking, setSpeaking] = useState(false);
1915
+ const utteranceRef = useRef(null);
1916
+ const watchdogRef = useRef(null);
1917
+ const ownerRef = useRef({});
1918
+ const stopRef = useRef(() => void 0);
1919
+ const langRef = useRef(lang);
1920
+ langRef.current = lang;
1921
+ const clearWatchdog = useCallback(() => {
1922
+ if (watchdogRef.current === null) return;
1923
+ clearTimeout(watchdogRef.current);
1924
+ watchdogRef.current = null;
1925
+ }, []);
1926
+ const settle = useCallback(() => {
1927
+ clearWatchdog();
1928
+ utteranceRef.current = null;
1929
+ if (activeOwner === ownerRef.current) {
1930
+ activeOwner = null;
1931
+ activeStop = null;
1932
+ }
1933
+ setSpeaking(false);
1934
+ }, [clearWatchdog]);
1935
+ const stop = useCallback(() => {
1936
+ const owned = utteranceRef.current !== null;
1937
+ settle();
1938
+ if (owned) speechPlatform()?.synth.cancel();
1939
+ }, [settle]);
1940
+ stopRef.current = stop;
1941
+ const speak = useCallback(
1942
+ (text) => {
1943
+ const platform = speechPlatform();
1944
+ if (!platform) {
1945
+ setAvailable(false);
1946
+ return;
1947
+ }
1948
+ const spoken = text.trim();
1949
+ if (spoken === "") return;
1950
+ if (activeStop && activeOwner !== ownerRef.current) activeStop();
1951
+ platform.synth.cancel();
1952
+ const utterance = new platform.Utterance(spoken);
1953
+ const wanted = langRef.current;
1954
+ if (wanted !== void 0 && wanted !== "") {
1955
+ const voice = pickVoice(platform.synth.getVoices(), wanted);
1956
+ utterance.lang = voice?.lang ?? wanted;
1957
+ if (voice) utterance.voice = voice;
1958
+ }
1959
+ const mine = () => utteranceRef.current === utterance;
1960
+ utterance.onstart = () => {
1961
+ if (!mine()) return;
1962
+ clearWatchdog();
1963
+ setSpeaking(true);
1964
+ };
1965
+ utterance.onend = () => {
1966
+ if (!mine()) return;
1967
+ settle();
1968
+ };
1969
+ utterance.onerror = (event) => {
1970
+ if (!mine()) return;
1971
+ const code = typeof event?.error === "string" ? event.error : "";
1972
+ settle();
1973
+ if (code !== "interrupted" && code !== "canceled") setAvailable(false);
1974
+ };
1975
+ utteranceRef.current = utterance;
1976
+ activeOwner = ownerRef.current;
1977
+ activeStop = () => {
1978
+ stopRef.current();
1979
+ };
1980
+ setSpeaking(true);
1981
+ platform.synth.speak(utterance);
1982
+ clearWatchdog();
1983
+ watchdogRef.current = setTimeout(() => {
1984
+ watchdogRef.current = null;
1985
+ if (!mine()) return;
1986
+ if (platform.synth.speaking) return;
1987
+ settle();
1988
+ setAvailable(false);
1989
+ }, SILENT_FAILURE_MS);
1990
+ },
1991
+ [clearWatchdog, settle]
1992
+ );
1993
+ const toggle = useCallback(
1994
+ (text) => {
1995
+ if (speaking) stop();
1996
+ else speak(text);
1997
+ },
1998
+ [speak, speaking, stop]
1999
+ );
2000
+ useEffect(() => {
2001
+ if (!speaking || typeof window === "undefined") return;
2002
+ const onHide = () => {
2003
+ stopRef.current();
2004
+ };
2005
+ window.addEventListener("pagehide", onHide);
2006
+ return () => window.removeEventListener("pagehide", onHide);
2007
+ }, [speaking]);
2008
+ useEffect(
2009
+ () => () => {
2010
+ stopRef.current();
2011
+ },
2012
+ []
2013
+ );
2014
+ return { supported: available, speaking, speak, stop, toggle };
2015
+ }
2016
+
2017
+ export { BAKED_CATALOG_ELEMENT_ID, DEFAULT_EXPLORE_EXAMPLE_PROMPTS, ECOSYSTEM_PRODUCTS, ESCALATE_EXPLORE_CONVERSATION_MUTATION, EXPLORE_CATALOG_QUERY, EXPLORE_CATALOG_QUERY_WITHOUT_HIGHLIGHTS, EXPLORE_ESCALATION_NOTE_SOFT_MAX, EXPLORE_FEEDBACK_COMMENT_SOFT_MAX, EXPLORE_FEEDBACK_REASONS, EXPLORE_MESSAGE_QUERY, FALLBACK_EXPLORE_LIMITS, SEND_EXPLORE_MESSAGE_MUTATION, bakedCatalogLocale, classifyExploreError, looksLikeDeliverableEmail, serializeBakedCatalog, stopSpeaking, useExploreChat, useProgressiveReveal, useSpeechInput, useSpeechOutput };
2018
+ //# sourceMappingURL=chunk-EUPFS6MZ.mjs.map
2019
+ //# sourceMappingURL=chunk-EUPFS6MZ.mjs.map