@adminide-stack/yantra-mobile 12.0.196-alpha.0 → 12.0.196
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/lib/components/CustomDrawer.js +17 -1
- package/lib/components/CustomDrawer.js.map +1 -1
- package/lib/compute.js +57 -1
- package/lib/compute.js.map +1 -1
- package/lib/config/env-config.js +11 -1
- package/lib/config/env-config.js.map +1 -1
- package/lib/features/agent-chat/NativeAgentChat.js +7 -0
- package/lib/features/agent-chat/NativeAgentChat.js.map +1 -1
- package/lib/features/canvas/extendVideo.js +5 -1
- package/lib/features/canvas/extendVideo.js.map +1 -1
- package/lib/features/canvas/workflow/StepSheet.js +18 -1
- package/lib/features/canvas/workflow/StepSheet.js.map +1 -1
- package/lib/features/canvas/workflow/workflowSteps.js +102 -31
- package/lib/features/canvas/workflow/workflowSteps.js.map +1 -1
- package/lib/features/chat/ComposerMicSend.js +35 -0
- package/lib/features/chat/ComposerMicSend.js.map +1 -0
- package/lib/features/chat/ComposerModeSwitch.js +64 -1
- package/lib/features/chat/ComposerModeSwitch.js.map +1 -1
- package/lib/features/chat/askUser.js +6 -1
- package/lib/features/chat/askUser.js.map +1 -1
- package/lib/features/connectors/ConnectorSheet.js +443 -0
- package/lib/features/connectors/ConnectorSheet.js.map +1 -0
- package/lib/features/connectors/ConnectorsPage.js +320 -0
- package/lib/features/connectors/ConnectorsPage.js.map +1 -0
- package/lib/features/connectors/connectConnector.js +278 -0
- package/lib/features/connectors/connectConnector.js.map +1 -0
- package/lib/features/connectors/connectorCatalog.js +222 -0
- package/lib/features/connectors/connectorCatalog.js.map +1 -0
- package/lib/features/connectors/useConnectorCatalog.js +153 -0
- package/lib/features/connectors/useConnectorCatalog.js.map +1 -0
- package/lib/features/home/needsYou/HomeNeedsYou.js +618 -0
- package/lib/features/home/needsYou/HomeNeedsYou.js.map +1 -0
- package/lib/features/home/needsYou/chatFollowUps.js +333 -0
- package/lib/features/home/needsYou/chatFollowUps.js.map +1 -0
- package/lib/features/home/needsYou/format.js +47 -0
- package/lib/features/home/needsYou/format.js.map +1 -0
- package/lib/features/home/needsYou/historyText.js +40 -0
- package/lib/features/home/needsYou/historyText.js.map +1 -0
- package/lib/features/home/needsYou/inboxHighlights.js +152 -0
- package/lib/features/home/needsYou/inboxHighlights.js.map +1 -0
- package/lib/features/home/needsYou/panelsSettings.js +71 -0
- package/lib/features/home/needsYou/panelsSettings.js.map +1 -0
- package/lib/features/home/needsYou/ported/commandConfirmProtocol.js +13 -0
- package/lib/features/home/needsYou/ported/commandConfirmProtocol.js.map +1 -0
- package/lib/features/home/needsYou/ported/paymentApprovalProtocol.js +91 -0
- package/lib/features/home/needsYou/ported/paymentApprovalProtocol.js.map +1 -0
- package/lib/features/home/needsYou/ported/resultCardModels.js +659 -0
- package/lib/features/home/needsYou/ported/resultCardModels.js.map +1 -0
- package/lib/features/home/needsYou/types.js +1 -0
- package/lib/features/home/needsYou/types.js.map +1 -0
- package/lib/features/home/needsYou/useChatFollowUps.js +149 -0
- package/lib/features/home/needsYou/useChatFollowUps.js.map +1 -0
- package/lib/features/home/needsYou/useHomeBriefing.js +68 -0
- package/lib/features/home/needsYou/useHomeBriefing.js.map +1 -0
- package/lib/features/home/needsYou/useInboxHighlights.js +173 -0
- package/lib/features/home/needsYou/useInboxHighlights.js.map +1 -0
- package/lib/features/home/needsYou/usePanelsSettings.js +105 -0
- package/lib/features/home/needsYou/usePanelsSettings.js.map +1 -0
- package/lib/features/shopping/DealCard.js +8 -1
- package/lib/features/shopping/DealCard.js.map +1 -1
- package/lib/features/shopping/DealRails.js +24 -7
- package/lib/features/shopping/DealRails.js.map +1 -1
- package/lib/features/shopping/DealsPanel.js +1 -1
- package/lib/features/shopping/DealsPanel.js.map +1 -1
- package/lib/features/shopping/HolidayDealsPanel.js +529 -0
- package/lib/features/shopping/HolidayDealsPanel.js.map +1 -0
- package/lib/features/shopping/HolidayDealsParts.js +954 -0
- package/lib/features/shopping/HolidayDealsParts.js.map +1 -0
- package/lib/features/shopping/HolidayOffers.js +351 -0
- package/lib/features/shopping/HolidayOffers.js.map +1 -0
- package/lib/features/shopping/ProductCard.js +80 -14
- package/lib/features/shopping/ProductCard.js.map +1 -1
- package/lib/features/shopping/ProductDetailSheet.js +22 -3
- package/lib/features/shopping/ProductDetailSheet.js.map +1 -1
- package/lib/features/shopping/SavedPanel.js +341 -5
- package/lib/features/shopping/SavedPanel.js.map +1 -1
- package/lib/features/shopping/SearchResults.js +8 -2
- package/lib/features/shopping/SearchResults.js.map +1 -1
- package/lib/features/shopping/ShoppingAgentChatPane.js +12 -0
- package/lib/features/shopping/ShoppingAgentChatPane.js.map +1 -1
- package/lib/features/shopping/ShoppingExperience.js +56 -19
- package/lib/features/shopping/ShoppingExperience.js.map +1 -1
- package/lib/features/shopping/TrendingSections.js +13 -4
- package/lib/features/shopping/TrendingSections.js.map +1 -1
- package/lib/features/shopping/WatchlistPanel.js +61 -5
- package/lib/features/shopping/WatchlistPanel.js.map +1 -1
- package/lib/features/shopping/catalog.js +41 -2
- package/lib/features/shopping/catalog.js.map +1 -1
- package/lib/features/shopping/chat/brainRouter.js +14 -0
- package/lib/features/shopping/chat/brainRouter.js.map +1 -1
- package/lib/features/shopping/chat/shoppingTurn.js +88 -16
- package/lib/features/shopping/chat/shoppingTurn.js.map +1 -1
- package/lib/features/shopping/hooks/useHolidayDeals.js +388 -0
- package/lib/features/shopping/hooks/useHolidayDeals.js.map +1 -0
- package/lib/features/shopping/hooks/useProductMedia.js +33 -6
- package/lib/features/shopping/hooks/useProductMedia.js.map +1 -1
- package/lib/features/shopping/hooks/useShoppingHistorySync.js +8 -4
- package/lib/features/shopping/hooks/useShoppingHistorySync.js.map +1 -1
- package/lib/features/shopping/hooks/useTrendingProducts.js +11 -3
- package/lib/features/shopping/hooks/useTrendingProducts.js.map +1 -1
- package/lib/features/shopping/savedProducts.js +76 -6
- package/lib/features/shopping/savedProducts.js.map +1 -1
- package/lib/features/shopping/services/aiRelevance.js +212 -0
- package/lib/features/shopping/services/aiRelevance.js.map +1 -0
- package/lib/features/shopping/services/blackFriday.js +301 -0
- package/lib/features/shopping/services/blackFriday.js.map +1 -0
- package/lib/features/shopping/services/blackFridayBrowserSites.js +137 -0
- package/lib/features/shopping/services/blackFridayBrowserSites.js.map +1 -0
- package/lib/features/shopping/services/catalogProductSearch.js +21 -3
- package/lib/features/shopping/services/catalogProductSearch.js.map +1 -1
- package/lib/features/shopping/services/holidayDeals.js +143 -0
- package/lib/features/shopping/services/holidayDeals.js.map +1 -0
- package/lib/features/shopping/services/mediaShape.js +7 -0
- package/lib/features/shopping/services/mediaShape.js.map +1 -0
- package/lib/features/shopping/services/modelStep.js +95 -0
- package/lib/features/shopping/services/modelStep.js.map +1 -0
- package/lib/features/shopping/services/modelWords.js +14 -0
- package/lib/features/shopping/services/modelWords.js.map +1 -0
- package/lib/features/shopping/services/productAvailability.js +5 -1
- package/lib/features/shopping/services/productAvailability.js.map +1 -1
- package/lib/features/shopping/services/productFilters.js +2 -2
- package/lib/features/shopping/services/productFilters.js.map +1 -1
- package/lib/features/shopping/services/productMedia.js +103 -18
- package/lib/features/shopping/services/productMedia.js.map +1 -1
- package/lib/features/shopping/services/retailerUrl.js +11 -8
- package/lib/features/shopping/services/retailerUrl.js.map +1 -1
- package/lib/features/shopping/services/salesDealsStore.js +3 -2
- package/lib/features/shopping/services/salesDealsStore.js.map +1 -1
- package/lib/features/shopping/services/savedReads.js +82 -0
- package/lib/features/shopping/services/savedReads.js.map +1 -0
- package/lib/features/shopping/services/searchCardFields.js +2 -0
- package/lib/features/shopping/services/searchCardFields.js.map +1 -1
- package/lib/features/shopping/services/searchRelevance.js +154 -24
- package/lib/features/shopping/services/searchRelevance.js.map +1 -1
- package/lib/features/shopping/services/secondHand.js +12 -0
- package/lib/features/shopping/services/secondHand.js.map +1 -0
- package/lib/features/shopping/services/shoppingProductSearch.js +82 -10
- package/lib/features/shopping/services/shoppingProductSearch.js.map +1 -1
- package/lib/features/shopping/services/shoppingSearchConnectorClient.js +14 -1
- package/lib/features/shopping/services/shoppingSearchConnectorClient.js.map +1 -1
- package/lib/features/shopping/services/shoppingSubgraph.js +2 -1
- package/lib/features/shopping/services/shoppingSubgraph.js.map +1 -1
- package/lib/features/shopping/services/storedGalleries.js +130 -0
- package/lib/features/shopping/services/storedGalleries.js.map +1 -0
- package/lib/features/shopping/services/usedSites.js +263 -0
- package/lib/features/shopping/services/usedSites.js.map +1 -0
- package/lib/features/shopping/services/verifyProducts.js +3 -3
- package/lib/features/shopping/services/verifyProducts.js.map +1 -1
- package/lib/features/shopping/services/watchDeal.js +61 -0
- package/lib/features/shopping/services/watchDeal.js.map +1 -0
- package/lib/features/shopping/shoppingRuntime.js +7 -2
- package/lib/features/shopping/shoppingRuntime.js.map +1 -1
- package/lib/features/shopping/state/accountCaches.js +20 -0
- package/lib/features/shopping/state/accountCaches.js.map +1 -0
- package/lib/features/shopping/state/holidayDealsRequest.js +22 -0
- package/lib/features/shopping/state/holidayDealsRequest.js.map +1 -0
- package/lib/features/shopping/tutorials/ShoppingTutorialDock.js +1 -1
- package/lib/features/shopping/tutorials/ShoppingTutorialDock.js.map +1 -1
- package/lib/features/shopping/tutorials/shoppingTutorials.js +2 -0
- package/lib/features/shopping/tutorials/shoppingTutorials.js.map +1 -1
- package/lib/features/shopping/useShoppingSearch.js +74 -18
- package/lib/features/shopping/useShoppingSearch.js.map +1 -1
- package/lib/features/team-chat/TeamChatExperience.js +474 -0
- package/lib/features/team-chat/TeamChatExperience.js.map +1 -0
- package/lib/features/team-chat/api/client.js +198 -0
- package/lib/features/team-chat/api/client.js.map +1 -0
- package/lib/features/team-chat/api/live.js +160 -0
- package/lib/features/team-chat/api/live.js.map +1 -0
- package/lib/features/team-chat/api/ops.js +241 -0
- package/lib/features/team-chat/api/ops.js.map +1 -0
- package/lib/features/team-chat/app.js +12 -0
- package/lib/features/team-chat/app.js.map +1 -0
- package/lib/features/team-chat/components/Avatar.js +107 -0
- package/lib/features/team-chat/components/Avatar.js.map +1 -0
- package/lib/features/team-chat/components/Composer.js +641 -0
- package/lib/features/team-chat/components/Composer.js.map +1 -0
- package/lib/features/team-chat/components/Dialogs.js +598 -0
- package/lib/features/team-chat/components/Dialogs.js.map +1 -0
- package/lib/features/team-chat/components/EmojiPicker.js +165 -0
- package/lib/features/team-chat/components/EmojiPicker.js.map +1 -0
- package/lib/features/team-chat/components/MessageItem.js +658 -0
- package/lib/features/team-chat/components/MessageItem.js.map +1 -0
- package/lib/features/team-chat/components/MessageList.js +248 -0
- package/lib/features/team-chat/components/MessageList.js.map +1 -0
- package/lib/features/team-chat/components/Mrkdwn.js +228 -0
- package/lib/features/team-chat/components/Mrkdwn.js.map +1 -0
- package/lib/features/team-chat/components/QuickSwitcher.js +215 -0
- package/lib/features/team-chat/components/QuickSwitcher.js.map +1 -0
- package/lib/features/team-chat/components/ui.js +662 -0
- package/lib/features/team-chat/components/ui.js.map +1 -0
- package/lib/features/team-chat/nativeTeamChatRegistry.js +15 -0
- package/lib/features/team-chat/nativeTeamChatRegistry.js.map +1 -0
- package/lib/features/team-chat/state/fetched.js +39 -0
- package/lib/features/team-chat/state/fetched.js.map +1 -0
- package/lib/features/team-chat/state/lists.js +230 -0
- package/lib/features/team-chat/state/lists.js.map +1 -0
- package/lib/features/team-chat/state/store.js +1108 -0
- package/lib/features/team-chat/state/store.js.map +1 -0
- package/lib/features/team-chat/state/useChannelDirectory.js +21 -0
- package/lib/features/team-chat/state/useChannelDirectory.js.map +1 -0
- package/lib/features/team-chat/theme.js +77 -0
- package/lib/features/team-chat/theme.js.map +1 -0
- package/lib/features/team-chat/utils/composeText.js +72 -0
- package/lib/features/team-chat/utils/composeText.js.map +1 -0
- package/lib/features/team-chat/utils/emoji.js +369 -0
- package/lib/features/team-chat/utils/emoji.js.map +1 -0
- package/lib/features/team-chat/utils/format.js +109 -0
- package/lib/features/team-chat/utils/format.js.map +1 -0
- package/lib/features/team-chat/utils/messageRows.js +24 -0
- package/lib/features/team-chat/utils/messageRows.js.map +1 -0
- package/lib/features/team-chat/utils/mrkdwn.js +222 -0
- package/lib/features/team-chat/utils/mrkdwn.js.map +1 -0
- package/lib/features/team-chat/utils/notify.js +47 -0
- package/lib/features/team-chat/utils/notify.js.map +1 -0
- package/lib/features/team-chat/utils/pickFiles.js +81 -0
- package/lib/features/team-chat/utils/pickFiles.js.map +1 -0
- package/lib/features/team-chat/views/ActivityView.js +235 -0
- package/lib/features/team-chat/views/ActivityView.js.map +1 -0
- package/lib/features/team-chat/views/BrowseView.js +179 -0
- package/lib/features/team-chat/views/BrowseView.js.map +1 -0
- package/lib/features/team-chat/views/ChannelView.js +475 -0
- package/lib/features/team-chat/views/ChannelView.js.map +1 -0
- package/lib/features/team-chat/views/DetailsPane.js +816 -0
- package/lib/features/team-chat/views/DetailsPane.js.map +1 -0
- package/lib/features/team-chat/views/DraftsView.js +212 -0
- package/lib/features/team-chat/views/DraftsView.js.map +1 -0
- package/lib/features/team-chat/views/FilesView.js +152 -0
- package/lib/features/team-chat/views/FilesView.js.map +1 -0
- package/lib/features/team-chat/views/NewMessageView.js +286 -0
- package/lib/features/team-chat/views/NewMessageView.js.map +1 -0
- package/lib/features/team-chat/views/PeopleView.js +118 -0
- package/lib/features/team-chat/views/PeopleView.js.map +1 -0
- package/lib/features/team-chat/views/ProfilePane.js +220 -0
- package/lib/features/team-chat/views/ProfilePane.js.map +1 -0
- package/lib/features/team-chat/views/SavedView.js +113 -0
- package/lib/features/team-chat/views/SavedView.js.map +1 -0
- package/lib/features/team-chat/views/SearchView.js +307 -0
- package/lib/features/team-chat/views/SearchView.js.map +1 -0
- package/lib/features/team-chat/views/Sidebar.js +368 -0
- package/lib/features/team-chat/views/Sidebar.js.map +1 -0
- package/lib/features/team-chat/views/ThreadPane.js +139 -0
- package/lib/features/team-chat/views/ThreadPane.js.map +1 -0
- package/lib/features/team-chat/views/ThreadsView.js +157 -0
- package/lib/features/team-chat/views/ThreadsView.js.map +1 -0
- package/lib/features/webbuilder/WebBuilderExperience.js +276 -42
- package/lib/features/webbuilder/WebBuilderExperience.js.map +1 -1
- package/lib/features/webbuilder/buildFragments.js +10 -4
- package/lib/features/webbuilder/buildFragments.js.map +1 -1
- package/lib/features/webbuilder/components/AssetChips.js +61 -0
- package/lib/features/webbuilder/components/AssetChips.js.map +1 -0
- package/lib/features/webbuilder/components/AssetSiteChooser.js +100 -0
- package/lib/features/webbuilder/components/AssetSiteChooser.js.map +1 -0
- package/lib/features/webbuilder/components/CommentsLayer.js +485 -0
- package/lib/features/webbuilder/components/CommentsLayer.js.map +1 -0
- package/lib/features/webbuilder/components/Composer.js +16 -2
- package/lib/features/webbuilder/components/Composer.js.map +1 -1
- package/lib/features/webbuilder/components/ComposerModeSwitch.js +71 -0
- package/lib/features/webbuilder/components/ComposerModeSwitch.js.map +1 -0
- package/lib/features/webbuilder/components/MyAssetsPicker.js +500 -0
- package/lib/features/webbuilder/components/MyAssetsPicker.js.map +1 -0
- package/lib/features/webbuilder/components/PlanDocument.js +165 -0
- package/lib/features/webbuilder/components/PlanDocument.js.map +1 -0
- package/lib/features/webbuilder/components/PlanDraftCard.js +205 -0
- package/lib/features/webbuilder/components/PlanDraftCard.js.map +1 -0
- package/lib/features/webbuilder/components/PlanView.js +788 -0
- package/lib/features/webbuilder/components/PlanView.js.map +1 -0
- package/lib/features/webbuilder/components/PreviewConsoleSheet.js +334 -0
- package/lib/features/webbuilder/components/PreviewConsoleSheet.js.map +1 -0
- package/lib/features/webbuilder/components/PreviewFrame.js +45 -3
- package/lib/features/webbuilder/components/PreviewFrame.js.map +1 -1
- package/lib/features/webbuilder/components/PreviewScreen.js +94 -10
- package/lib/features/webbuilder/components/PreviewScreen.js.map +1 -1
- package/lib/features/webbuilder/components/ProjectChat.js +84 -14
- package/lib/features/webbuilder/components/ProjectChat.js.map +1 -1
- package/lib/features/webbuilder/components/StudioHome.js +69 -6
- package/lib/features/webbuilder/components/StudioHome.js.map +1 -1
- package/lib/features/webbuilder/components/StyleDirectionsSheet.js +291 -0
- package/lib/features/webbuilder/components/StyleDirectionsSheet.js.map +1 -0
- package/lib/features/webbuilder/components/VersionChangesView.js +574 -0
- package/lib/features/webbuilder/components/VersionChangesView.js.map +1 -0
- package/lib/features/webbuilder/components/VersionPreviewView.js +186 -0
- package/lib/features/webbuilder/components/VersionPreviewView.js.map +1 -0
- package/lib/features/webbuilder/components/VersionsSheet.js +673 -16
- package/lib/features/webbuilder/components/VersionsSheet.js.map +1 -1
- package/lib/features/webbuilder/connectorTemplates.js +6 -1
- package/lib/features/webbuilder/connectorTemplates.js.map +1 -1
- package/lib/features/webbuilder/myAssets.js +101 -0
- package/lib/features/webbuilder/myAssets.js.map +1 -0
- package/lib/features/webbuilder/planChat.js +146 -0
- package/lib/features/webbuilder/planChat.js.map +1 -0
- package/lib/features/webbuilder/planDocument.js +89 -0
- package/lib/features/webbuilder/planDocument.js.map +1 -0
- package/lib/features/webbuilder/planStore.js +55 -0
- package/lib/features/webbuilder/planStore.js.map +1 -0
- package/lib/features/webbuilder/previewCommentsScript.js +218 -0
- package/lib/features/webbuilder/previewCommentsScript.js.map +1 -0
- package/lib/features/webbuilder/previewConsoleScript.js +39 -0
- package/lib/features/webbuilder/previewConsoleScript.js.map +1 -0
- package/lib/features/webbuilder/styleDirections.js +85 -0
- package/lib/features/webbuilder/styleDirections.js.map +1 -0
- package/lib/features/webbuilder/useCanvasComments.js +335 -0
- package/lib/features/webbuilder/useCanvasComments.js.map +1 -0
- package/lib/features/webbuilder/useCatalogTemplates.js +37 -0
- package/lib/features/webbuilder/useCatalogTemplates.js.map +1 -0
- package/lib/features/webbuilder/usePlanMode.js +145 -0
- package/lib/features/webbuilder/usePlanMode.js.map +1 -0
- package/lib/features/webbuilder/useStyleDirections.js +112 -0
- package/lib/features/webbuilder/useStyleDirections.js.map +1 -0
- package/lib/features/webbuilder/web/assets/assetsApi.js +174 -0
- package/lib/features/webbuilder/web/assets/assetsApi.js.map +1 -0
- package/lib/features/webbuilder/web/assets/assetsApi.ts +173 -0
- package/lib/features/webbuilder/web/assets/myAssets.js +341 -0
- package/lib/features/webbuilder/web/assets/myAssets.js.map +1 -0
- package/lib/features/webbuilder/web/assets/myAssets.ts +396 -0
- package/lib/features/webbuilder/web/canvas/elementName.js +46 -0
- package/lib/features/webbuilder/web/canvas/elementName.js.map +1 -0
- package/lib/features/webbuilder/web/canvas/visualEditorBridge.js +95 -0
- package/lib/features/webbuilder/web/canvas/visualEditorBridge.js.map +1 -0
- package/lib/features/webbuilder/web/chat/agentTurn.js +24 -0
- package/lib/features/webbuilder/web/chat/agentTurn.js.map +1 -0
- package/lib/features/webbuilder/web/chat/planMode.js +164 -0
- package/lib/features/webbuilder/web/chat/planMode.js.map +1 -0
- package/lib/features/webbuilder/web/chat/realPlans.js +66 -0
- package/lib/features/webbuilder/web/chat/realPlans.js.map +1 -0
- package/lib/features/webbuilder/web/comments/comments.js +336 -0
- package/lib/features/webbuilder/web/comments/comments.js.map +1 -0
- package/lib/features/webbuilder/web/comments/commentsApi.js +59 -0
- package/lib/features/webbuilder/web/comments/commentsApi.js.map +1 -0
- package/lib/features/webbuilder/web/components/planView.js +21 -0
- package/lib/features/webbuilder/web/components/planView.js.map +1 -0
- package/lib/features/webbuilder/web/console/consolePanel.js +43 -0
- package/lib/features/webbuilder/web/console/consolePanel.js.map +1 -0
- package/lib/features/webbuilder/web/console/previewConsole.js +256 -0
- package/lib/features/webbuilder/web/console/previewConsole.js.map +1 -0
- package/lib/features/webbuilder/web/console/usePreviewConsole.js +147 -0
- package/lib/features/webbuilder/web/console/usePreviewConsole.js.map +1 -0
- package/lib/features/webbuilder/web/design/directions.js +419 -1
- package/lib/features/webbuilder/web/design/directions.js.map +1 -1
- package/lib/features/webbuilder/web/history/diffActions.js +222 -0
- package/lib/features/webbuilder/web/history/diffActions.js.map +1 -0
- package/lib/features/webbuilder/web/history/diffHighlight.js +18 -0
- package/lib/features/webbuilder/web/history/diffHighlight.js.map +1 -0
- package/lib/features/webbuilder/web/history/versionActions.js +272 -0
- package/lib/features/webbuilder/web/history/versionActions.js.map +1 -0
- package/lib/features/webbuilder/web/history/versionDiff.js +338 -0
- package/lib/features/webbuilder/web/history/versionDiff.js.map +1 -0
- package/lib/features/webbuilder/web/history/versionPreview.js +83 -0
- package/lib/features/webbuilder/web/history/versionPreview.js.map +1 -0
- package/lib/features/webbuilder/web/history/versionPreviewMachine.js +150 -0
- package/lib/features/webbuilder/web/history/versionPreviewMachine.js.map +1 -0
- package/lib/features/webbuilder/web/history/versions.js +326 -1
- package/lib/features/webbuilder/web/history/versions.js.map +1 -1
- package/lib/features/webbuilder/web/hosted/hostedTurn.js +36 -0
- package/lib/features/webbuilder/web/hosted/hostedTurn.js.map +1 -0
- package/lib/features/webbuilder/web/studio/brandKit.js +25 -0
- package/lib/features/webbuilder/web/studio/brandKit.js.map +1 -0
- package/lib/features/webbuilder/web/utils/promptSafe.js +15 -0
- package/lib/features/webbuilder/web/utils/promptSafe.js.map +1 -0
- package/lib/features/webbuilder/web/webServices.js +3 -1
- package/lib/features/webbuilder/web/webServices.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/routes.json +55 -0
- package/lib/screens/Account/index.js +13 -5
- package/lib/screens/Account/index.js.map +1 -1
- package/lib/screens/Chat/index.js +16 -0
- package/lib/screens/Chat/index.js.map +1 -1
- package/lib/screens/Home/HomeScreen.js +202 -39
- package/lib/screens/Home/HomeScreen.js.map +1 -1
- package/lib/screens/Home/components/HomeHero.js +52 -38
- package/lib/screens/Home/components/HomeHero.js.map +1 -1
- package/lib/screens/Home/components/homeCatalog.js +8 -1
- package/lib/screens/Home/components/homeCatalog.js.map +1 -1
- package/lib/screens/TeamChat/index.js +41 -0
- package/lib/screens/TeamChat/index.js.map +1 -0
- package/lib/screens/WebBuilder/nativeWebBuilderRedirect.js +9 -2
- package/lib/screens/WebBuilder/nativeWebBuilderRedirect.js.map +1 -1
- package/lib/screens/WebBuilderNative/index.js +13 -3
- package/lib/screens/WebBuilderNative/index.js.map +1 -1
- package/lib/screens/WebBuilderNative/useConnectorTemplates.js +2 -2
- package/lib/screens/WebBuilderNative/useConnectorTemplates.js.map +1 -1
- package/package.json +4 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {useState,useEffect}from'react';import {DEPARTMENT_SEARCH_PRESETS,searchShoppingProductsRest,mergeShoppingProductSources,searchShoppingProductsFast}from'../services/shoppingProductSearch.js';import {loadStoredTrending,saveTrendingBoard}from'../services/salesDealsStore.js';import {verifyProducts,applyVerifiedRows}from'../services/verifyProducts.js';var __defProp = Object.defineProperty;
|
|
1
|
+
import {useState,useCallback,useEffect}from'react';import {DEPARTMENT_SEARCH_PRESETS,searchShoppingProductsRest,mergeShoppingProductSources,searchShoppingProductsFast}from'../services/shoppingProductSearch.js';import {loadStoredTrending,saveTrendingBoard}from'../services/salesDealsStore.js';import {verifyProducts,applyVerifiedRows}from'../services/verifyProducts.js';import {onAccountChange}from'../state/accountCaches.js';var __defProp = Object.defineProperty;
|
|
2
2
|
var __defProps = Object.defineProperties;
|
|
3
3
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
@@ -82,6 +82,10 @@ function peekTrending(departmentId) {
|
|
|
82
82
|
var _a;
|
|
83
83
|
return (_a = cache.get(cacheKey(departmentId, true))) != null ? _a : cache.get(cacheKey(departmentId, false));
|
|
84
84
|
}
|
|
85
|
+
onAccountChange(() => {
|
|
86
|
+
cache.clear();
|
|
87
|
+
servedFromStore.clear();
|
|
88
|
+
});
|
|
85
89
|
function fetchFast(departmentId, limit) {
|
|
86
90
|
const key = cacheKey(departmentId, false);
|
|
87
91
|
const cached = cache.get(key);
|
|
@@ -162,6 +166,8 @@ function useTrendingProducts(departmentId, options = {}) {
|
|
|
162
166
|
deep = false,
|
|
163
167
|
limit = 12
|
|
164
168
|
} = options;
|
|
169
|
+
const [attempt, setAttempt] = useState(0);
|
|
170
|
+
const retry = useCallback(() => setAttempt((n) => n + 1), []);
|
|
165
171
|
const [state, setState] = useState(() => {
|
|
166
172
|
const cached = departmentId ? peekTrending(departmentId) : void 0;
|
|
167
173
|
return cached ? __spreadProps(__spreadValues({}, EMPTY), {
|
|
@@ -268,6 +274,8 @@ function useTrendingProducts(departmentId, options = {}) {
|
|
|
268
274
|
live = false;
|
|
269
275
|
claim == null ? void 0 : claim.release();
|
|
270
276
|
};
|
|
271
|
-
}, [departmentId, enabled, deep, limit]);
|
|
272
|
-
return state
|
|
277
|
+
}, [departmentId, enabled, deep, limit, attempt]);
|
|
278
|
+
return __spreadProps(__spreadValues({}, state), {
|
|
279
|
+
retry
|
|
280
|
+
});
|
|
273
281
|
}export{peekTrending,useTrendingProducts};//# sourceMappingURL=useTrendingProducts.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTrendingProducts.js","sources":["../../../../src/features/shopping/hooks/useTrendingProducts.ts"],"sourcesContent":["/**\n * Trending rows for one department, fetched live — nothing on the landing page\n * is a fixture. Native port of web `hooks/useTrendingProducts.ts` (0.37.0).\n *\n * Rows come from the same lanes a real search uses, so a trending card is a\n * card the shopper can actually buy:\n * - the FAST lane (typed LemmeBuyIt catalog + the Amazon SERP, via\n * `searchShoppingProductsFast`) always runs;\n * - the REST lane (Walmart / eBay / Target / Shopify / Google + Yantra\n * research, all Parallel-backed) runs only for the department the user\n * actually selected.\n *\n * Web also runs a paired-browser lane for the selected department (hidden tabs\n * in the shopper's desktop Chrome); a phone has no Yantra extension, so it is\n * left out here.\n *\n * Results are cached per department for the life of the app, so switching\n * categories back and forth repaints instantly instead of re-billing every\n * provider.\n *\n * A rail first asks the shopping subgraph for the stored trending board\n * (`loadStoredTrending`): one saved within `STORED_BOARD_FRESH_MS` (12 h) IS the\n * answer, and no provider is called. Every painted batch is then VERIFIED\n * against its product page, exactly as the search grid does (`verifyProducts`):\n * the catalog index goes stale, and a rail that sends a shopper to a delisted\n * Walmart page is worse than a shorter rail. Dead rows leave the rail, the cache\n * and the stored board, and the verified rail is written back for the next\n * visitor.\n */\n\nimport { useEffect, useState } from 'react';\nimport type { Product } from '../catalog';\nimport {\n DEPARTMENT_SEARCH_PRESETS,\n mergeShoppingProductSources,\n searchShoppingProductsFast,\n searchShoppingProductsRest,\n} from '../services/shoppingProductSearch';\nimport { loadStoredTrending, saveTrendingBoard } from '../services/salesDealsStore';\nimport { applyVerifiedRows, verifyProducts } from '../services/verifyProducts';\n\nexport interface TrendingState {\n products: Product[];\n isLoading: boolean;\n /** The slower cross-retailer research lane is still landing rows. */\n isEnriching: boolean;\n error: string | null;\n}\n\nconst EMPTY: TrendingState = { products: [], isLoading: false, isEnriching: false, error: null };\n\n/**\n * Per-department row cache. Keyed by department AND depth, because the deep\n * fetch is a superset: a rail that was painted passively must not stop the\n * selected-category fetch from running the lanes it skipped.\n */\nconst cache = new Map<string, Product[]>();\n\n/**\n * One department's fast lane while it is out, shared by every rail that wants\n * it, so two rails mounting together do not double-fetch.\n *\n * `waiting` counts those rails. When the last one goes away - the shopper ran a\n * search and the landing page unmounted - nobody will ever read the answer, so\n * the fetch is cancelled: whatever it still had queued in the provider lanes\n * leaves them instead of holding up the search the shopper is waiting on.\n */\ninterface RailFetch {\n promise: Promise<Product[]>;\n controller: AbortController;\n waiting: number;\n}\nconst inFlight = new Map<string, RailFetch>();\n\n/** A rail's claim on a {@link RailFetch}. `release` is idempotent and safe after it settles. */\ninterface RailFetchClaim {\n promise: Promise<Product[]>;\n release: () => void;\n}\n\n/**\n * Departments whose rows came from a FRESH store rather than the providers.\n *\n * The slow lane below is gated on this too: serving the fast rows from the\n * store and then running the cross-retailer lane anyway would call the very\n * providers the freshness window exists to avoid.\n */\nconst servedFromStore = new Set<string>();\n\n/**\n * How many rails may be fetching at once. Several rails come into view\n * together, and each is an Amazon SERP call plus a catalog call; fired all at\n * once they trip the providers' rate limits, so the rails queue instead.\n */\nconst RAIL_CONCURRENCY = 2;\nlet railsActive = 0;\nconst railQueue: Array<() => void> = [];\n\n/**\n * Native-only ceiling on one rail's fast lane (web has none): only a request\n * that never ends gives up its rail slot here. It is long on purpose. A rail\n * that gave up while its connector call still ran left that call holding one of\n * the account's execution slots, and the next queued rail started another, until\n * the connector refused everything (\"execution capacity exhausted\", HTTP 429)\n * and every rail showed a loader and then \"timed out\". A slow store is waited\n * for, as on web.\n */\nconst TRENDING_FAST_MS = 90_000;\n\nfunction abortError(signal: AbortSignal): unknown {\n // Hermes has no DOMException; an Error named AbortError is what the lanes test for.\n const reason = (signal as AbortSignal & { reason?: unknown }).reason;\n if (reason) return reason;\n const error = new Error('The operation was aborted.');\n error.name = 'AbortError';\n return error;\n}\n\n/** A slot, or the abort if the rail is cancelled while still queued for one. */\nfunction acquireRailSlot(signal: AbortSignal): Promise<void> {\n if (signal.aborted) return Promise.reject(abortError(signal));\n if (railsActive < RAIL_CONCURRENCY) {\n railsActive += 1;\n return Promise.resolve();\n }\n return new Promise((resolve, reject) => {\n const grant = () => {\n signal.removeEventListener('abort', onAbort);\n railsActive += 1;\n resolve();\n };\n const onAbort = () => {\n const at = railQueue.indexOf(grant);\n if (at >= 0) railQueue.splice(at, 1);\n reject(abortError(signal));\n };\n signal.addEventListener('abort', onAbort);\n railQueue.push(grant);\n });\n}\n\nfunction releaseRailSlot(): void {\n railsActive -= 1;\n railQueue.shift()?.();\n}\n\nfunction withTimeout<T>(promise: Promise<T>, ms: number, label: string): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n const timer = setTimeout(() => reject(new Error(`${label} timed out`)), ms);\n promise.then(\n (value) => {\n clearTimeout(timer);\n resolve(value);\n },\n (err) => {\n clearTimeout(timer);\n reject(err);\n },\n );\n });\n}\n\nfunction cacheKey(departmentId: string, deep: boolean): string {\n return `${departmentId}:${deep ? 'deep' : 'fast'}`;\n}\n\n/** Read what a department already resolved to, at either depth. Deep wins. */\nexport function peekTrending(departmentId: string): Product[] | undefined {\n return cache.get(cacheKey(departmentId, true)) ?? cache.get(cacheKey(departmentId, false));\n}\n\n/** Tests: forget every rail. */\nexport function clearTrendingCacheForTests(): void {\n cache.clear();\n inFlight.clear();\n servedFromStore.clear();\n railsActive = 0;\n railQueue.length = 0;\n}\n\nfunction fetchFast(departmentId: string, limit: number): RailFetchClaim {\n const key = cacheKey(departmentId, false);\n const cached = cache.get(key);\n if (cached) return { promise: Promise.resolve(cached), release: () => {} };\n\n let entry = inFlight.get(key);\n if (!entry) {\n const controller = new AbortController();\n const { signal } = controller;\n const preset = DEPARTMENT_SEARCH_PRESETS[departmentId];\n const promise = (async () => {\n // The STORE first, outside the rail slot: a rail saved within\n // STORED_BOARD_FRESH_MS is the answer, so opening the landing page\n // costs no provider quota at all.\n const stored = await loadStoredTrending(departmentId, limit).catch(() => null);\n if (stored?.fresh && stored.products.length > 0) {\n // Saved verified, but up to a freshness window ago: an item\n // delisted since then must not paint either.\n const live = await verifyProducts(stored.products);\n if (live.length > 0) {\n servedFromStore.add(departmentId);\n return live;\n }\n }\n servedFromStore.delete(departmentId);\n\n await acquireRailSlot(signal);\n const search = fetchFastUnpaced(departmentId, limit, preset, signal);\n // The slot goes back when the connector call really ends - not when\n // the rail stops waiting for it - so at most RAIL_CONCURRENCY rail\n // searches ever run on the account's executor at once.\n search.then(releaseRailSlot, releaseRailSlot);\n // Checked before anything sees them - the rail, the cache every\n // other rail reads, and the store the hook writes the rail to - so\n // a delisted row never paints, here or for the next visitor.\n return verifyProducts(await withTimeout(search, TRENDING_FAST_MS, `Trending ${departmentId}`));\n })();\n const created: RailFetch = { promise, controller, waiting: 0 };\n entry = created;\n inFlight.set(key, created);\n // A cancelled fetch caches nothing, so the next rail to want this\n // department starts a fresh one rather than inheriting the abort. Native\n // also leaves an EMPTY answer uncached: an early answer from the\n // not-yet-wired runtime must not stick for the life of the app.\n promise\n .then(\n (products) => {\n if (!signal.aborted && products.length > 0) cache.set(key, products);\n },\n () => {},\n )\n .finally(() => {\n if (inFlight.get(key) === created) inFlight.delete(key);\n });\n }\n\n const claimed = entry;\n claimed.waiting += 1;\n let released = false;\n return {\n promise: claimed.promise,\n release: () => {\n if (released) return;\n released = true;\n claimed.waiting -= 1;\n if (claimed.waiting > 0) return;\n if (inFlight.get(key) === claimed) inFlight.delete(key);\n claimed.controller.abort();\n },\n };\n}\n\nasync function fetchFastUnpaced(\n departmentId: string,\n limit: number,\n preset: (typeof DEPARTMENT_SEARCH_PRESETS)[string] | undefined,\n signal: AbortSignal,\n): Promise<Product[]> {\n // A department browse has no typed query — the preset IS the query, and no\n // relevance shape is passed, exactly as `useShoppingSearch` does for a chip\n // browse. `background`: a rail is prefetch nobody asked for yet, so its\n // catalog call yields the shared provider lane to anything a shopper is\n // waiting on.\n const fast = await searchShoppingProductsFast({\n query: '',\n departmentId,\n maxResults: limit,\n ...(preset ? { category: preset.category } : {}),\n lane: { priority: 'background', signal },\n });\n return fast.products.slice(0, limit);\n}\n\n/**\n * Rows for one department's rail.\n *\n * @param departmentId which aisle to fill\n * @param options.enabled hold the fetch until the rail is on screen\n * @param options.deep run the slow retailer research lane too — for the\n * department the user explicitly selected\n * @param options.limit how many rows to ask each provider for\n */\nexport function useTrendingProducts(\n departmentId: string | null,\n options: { enabled?: boolean; deep?: boolean; limit?: number } = {},\n): TrendingState {\n const { enabled = true, deep = false, limit = 12 } = options;\n const [state, setState] = useState<TrendingState>(() => {\n const cached = departmentId ? peekTrending(departmentId) : undefined;\n return cached ? { ...EMPTY, products: cached } : EMPTY;\n });\n\n useEffect(() => {\n if (!departmentId || !enabled) return undefined;\n // Repaint from cache synchronously on a department change, so switching\n // tabs does not flash an empty rail at rows we already hold.\n const cached = deep ? cache.get(cacheKey(departmentId, true)) : peekTrending(departmentId);\n if (cached) {\n setState({ products: cached, isLoading: false, isEnriching: deep, error: null });\n } else {\n setState({ ...EMPTY, isLoading: true });\n }\n\n let live = true;\n /** This rail's claim on the shared fast fetch; released on unmount. */\n let claim: RailFetchClaim | null = null;\n const railKey = cacheKey(departmentId, deep);\n let rows: Product[] = cached ?? [];\n const verifications: Promise<void>[] = [];\n /** Page-check a painted batch and fold the verdicts back into the rail. */\n const verifyPainted = (batch: Product[]) => {\n if (batch.length === 0) return;\n verifications.push(\n verifyProducts(batch)\n .then((verified) => {\n if (!live) return;\n rows = applyVerifiedRows(rows, batch, verified);\n if (rows.length > 0) cache.set(railKey, rows);\n setState((prev) => ({ ...prev, products: rows }));\n })\n .catch((err) => console.warn('[shopping] trending verification failed:', err)),\n );\n };\n /**\n * Once every check has landed, the verified rail is what the next visitor\n * inherits. Fire-and-forget: a failed write just means the next visitor\n * sweeps again. A board the store served is not re-saved - the upsert\n * re-stamps it as observed now, and it would never age out.\n */\n const saveVerified = async () => {\n await Promise.allSettled(verifications);\n if (!live || rows.length === 0 || servedFromStore.has(departmentId)) return;\n void saveTrendingBoard(departmentId, rows).catch(() => {});\n };\n\n void (async () => {\n try {\n if (!cached) {\n claim = fetchFast(departmentId, limit);\n rows = await claim.promise;\n if (!live) return;\n setState({ products: rows, isLoading: false, isEnriching: deep, error: null });\n }\n verifyPainted(rows);\n } catch (err) {\n if (!live) return;\n setState({\n ...EMPTY,\n error: err instanceof Error ? err.message : 'Could not load trending products.',\n });\n return;\n }\n\n // A rail the store answered is DONE - running the cross-retailer lane\n // here would spend exactly the provider calls the freshness window is\n // there to save.\n if (!deep || servedFromStore.has(departmentId)) {\n if (live) setState((prev) => ({ ...prev, isLoading: false, isEnriching: false }));\n await saveVerified();\n return;\n }\n\n try {\n const preset = DEPARTMENT_SEARCH_PRESETS[departmentId];\n const rest = await searchShoppingProductsRest({\n query: '',\n departmentId,\n maxResults: limit,\n ...(preset ? { category: preset.category } : {}),\n });\n // Merge the slow lane's rows in once their pages check out — same\n // dedupe the grid uses.\n if (live && rest.products.length > 0) {\n const verified = await verifyProducts(rest.products);\n if (live && verified.length > 0) {\n rows = mergeShoppingProductSources([rows, verified]);\n cache.set(railKey, rows);\n setState((prev) => ({ ...prev, products: rows }));\n }\n }\n } catch (err) {\n // Best-effort: the fast rows already stand.\n console.warn('[shopping] trending cross-retailer lane failed:', err);\n }\n\n if (live) {\n if (rows.length > 0) cache.set(railKey, rows);\n setState((prev) => ({ ...prev, isEnriching: false }));\n }\n // Remember the ENRICHED rail, not just the fast rows: the next\n // reader should inherit the better board this visit paid for.\n await saveVerified();\n })();\n\n return () => {\n live = false;\n claim?.release();\n };\n }, [departmentId, enabled, deep, limit]);\n\n return state;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AA0CA,MAAM,KAAuB,GAAA;AAAA,EAC3B,UAAU,EAAC;AAAA,EACX,SAAW,EAAA,KAAA;AAAA,EACX,WAAa,EAAA,KAAA;AAAA,EACb,KAAO,EAAA;AACT,CAAA;AAOA,MAAM,KAAA,uBAAY,GAAuB,EAAA;AAgBzC,MAAM,QAAA,uBAAe,GAAuB,EAAA;AAe5C,MAAM,eAAA,uBAAsB,GAAY,EAAA;AAOxC,MAAM,gBAAmB,GAAA,CAAA;AACzB,IAAI,WAAc,GAAA,CAAA;AAClB,MAAM,YAA+B,EAAC;AAWtC,MAAM,gBAAmB,GAAA,GAAA;AACzB,SAAS,WAAW,MAA8B,EAAA;AAEhD,EAAA,MAAM,SAAU,MAEb,CAAA,MAAA;AACH,EAAA,IAAI,QAAe,OAAA,MAAA;AACnB,EAAM,MAAA,KAAA,GAAQ,IAAI,KAAA,CAAM,4BAA4B,CAAA;AACpD,EAAA,KAAA,CAAM,IAAO,GAAA,YAAA;AACb,EAAO,OAAA,KAAA;AACT;AAGA,SAAS,gBAAgB,MAAoC,EAAA;AAC3D,EAAA,IAAI,OAAO,OAAS,EAAA,OAAO,QAAQ,MAAO,CAAA,UAAA,CAAW,MAAM,CAAC,CAAA;AAC5D,EAAA,IAAI,cAAc,gBAAkB,EAAA;AAClC,IAAe,WAAA,IAAA,CAAA;AACf,IAAA,OAAO,QAAQ,OAAQ,EAAA;AAAA;AAEzB,EAAA,OAAO,IAAI,OAAA,CAAQ,CAAC,OAAA,EAAS,MAA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AAC5C,QAAS,QAAA,CAAA,CAAA,IAAA,KAAS,iCACb,IADa,CAAA,EAAA;AAAA,UAEhB,WAAa,EAAA;AAAA,SACb,CAAA,CAAA;AAAA;AAIJ,MAAA,MAAM,YAAa,EAAA;AAAA,KAClB,GAAA;AACH,IAAA,OAAO,MAAM;AACX,MAAO,IAAA,GAAA,KAAA;AACP,MAAO,KAAA,IAAA,IAAA,GAAA,MAAA,GAAA,KAAA,CAAA,OAAA,EAAA;AAAA,KACT;AAAA,KACC,CAAC,YAAA,EAAc,OAAS,EAAA,IAAA,EAAM,KAAK,CAAC,CAAA;AACvC,EAAO,OAAA,KAAA;AACT"}
|
|
1
|
+
{"version":3,"file":"useTrendingProducts.js","sources":["../../../../src/features/shopping/hooks/useTrendingProducts.ts"],"sourcesContent":["/**\n * Trending rows for one department, fetched live — nothing on the landing page\n * is a fixture. Native port of web `hooks/useTrendingProducts.ts` (0.49.0).\n *\n * Rows come from the same lanes a real search uses, so a trending card is a\n * card the shopper can actually buy:\n * - the FAST lane (typed LemmeBuyIt catalog + the Amazon SERP, via\n * `searchShoppingProductsFast`) always runs;\n * - the REST lane (Walmart / eBay / Target / Shopify / Google + Yantra\n * research, all Parallel-backed) runs only for the department the user\n * actually selected.\n *\n * Web also runs a paired-browser lane for the selected department (hidden tabs\n * in the shopper's desktop Chrome); a phone has no Yantra extension, so it is\n * left out here.\n *\n * Results are cached per department for the life of the app, so switching\n * categories back and forth repaints instantly instead of re-billing every\n * provider.\n *\n * A rail first asks the shopping subgraph for the stored trending board\n * (`loadStoredTrending`): one saved within `STORED_BOARD_FRESH_MS` (12 h) IS the\n * answer, and no provider is called. Every painted batch is then VERIFIED\n * against its product page, exactly as the search grid does (`verifyProducts`):\n * the catalog index goes stale, and a rail that sends a shopper to a delisted\n * Walmart page is worse than a shorter rail. Dead rows leave the rail, the cache\n * and the stored board, and the verified rail is written back for the next\n * visitor.\n */\n\nimport { useCallback, useEffect, useState } from 'react';\nimport type { Product } from '../catalog';\nimport {\n DEPARTMENT_SEARCH_PRESETS,\n mergeShoppingProductSources,\n searchShoppingProductsFast,\n searchShoppingProductsRest,\n} from '../services/shoppingProductSearch';\nimport { loadStoredTrending, saveTrendingBoard } from '../services/salesDealsStore';\nimport { applyVerifiedRows, verifyProducts } from '../services/verifyProducts';\nimport { onAccountChange } from '../state/accountCaches';\n\nexport interface TrendingState {\n products: Product[];\n isLoading: boolean;\n /** The slower cross-retailer research lane is still landing rows. */\n isEnriching: boolean;\n error: string | null;\n /** Reads the rail again now (its \"Try again\", web 0.49.0). */\n retry: () => void;\n}\n\ntype TrendingRead = Omit<TrendingState, 'retry'>;\nconst EMPTY: TrendingRead = { products: [], isLoading: false, isEnriching: false, error: null };\n\n/**\n * Per-department row cache. Keyed by department AND depth, because the deep\n * fetch is a superset: a rail that was painted passively must not stop the\n * selected-category fetch from running the lanes it skipped.\n */\nconst cache = new Map<string, Product[]>();\n\n/**\n * One department's fast lane while it is out, shared by every rail that wants\n * it, so two rails mounting together do not double-fetch.\n *\n * `waiting` counts those rails. When the last one goes away - the shopper ran a\n * search and the landing page unmounted - nobody will ever read the answer, so\n * the fetch is cancelled: whatever it still had queued in the provider lanes\n * leaves them instead of holding up the search the shopper is waiting on.\n */\ninterface RailFetch {\n promise: Promise<Product[]>;\n controller: AbortController;\n waiting: number;\n}\nconst inFlight = new Map<string, RailFetch>();\n\n/** A rail's claim on a {@link RailFetch}. `release` is idempotent and safe after it settles. */\ninterface RailFetchClaim {\n promise: Promise<Product[]>;\n release: () => void;\n}\n\n/**\n * Departments whose rows came from a FRESH store rather than the providers.\n *\n * The slow lane below is gated on this too: serving the fast rows from the\n * store and then running the cross-retailer lane anyway would call the very\n * providers the freshness window exists to avoid.\n */\nconst servedFromStore = new Set<string>();\n\n/**\n * How many rails may be fetching at once. Several rails come into view\n * together, and each is an Amazon SERP call plus a catalog call; fired all at\n * once they trip the providers' rate limits, so the rails queue instead.\n */\nconst RAIL_CONCURRENCY = 2;\nlet railsActive = 0;\nconst railQueue: Array<() => void> = [];\n\n/**\n * Native-only ceiling on one rail's fast lane (web has none): only a request\n * that never ends gives up its rail slot here. It is long on purpose. A rail\n * that gave up while its connector call still ran left that call holding one of\n * the account's execution slots, and the next queued rail started another, until\n * the connector refused everything (\"execution capacity exhausted\", HTTP 429)\n * and every rail showed a loader and then \"timed out\". A slow store is waited\n * for, as on web.\n */\nconst TRENDING_FAST_MS = 90_000;\n\nfunction abortError(signal: AbortSignal): unknown {\n // Hermes has no DOMException; an Error named AbortError is what the lanes test for.\n const reason = (signal as AbortSignal & { reason?: unknown }).reason;\n if (reason) return reason;\n const error = new Error('The operation was aborted.');\n error.name = 'AbortError';\n return error;\n}\n\n/** A slot, or the abort if the rail is cancelled while still queued for one. */\nfunction acquireRailSlot(signal: AbortSignal): Promise<void> {\n if (signal.aborted) return Promise.reject(abortError(signal));\n if (railsActive < RAIL_CONCURRENCY) {\n railsActive += 1;\n return Promise.resolve();\n }\n return new Promise((resolve, reject) => {\n const grant = () => {\n signal.removeEventListener('abort', onAbort);\n railsActive += 1;\n resolve();\n };\n const onAbort = () => {\n const at = railQueue.indexOf(grant);\n if (at >= 0) railQueue.splice(at, 1);\n reject(abortError(signal));\n };\n signal.addEventListener('abort', onAbort);\n railQueue.push(grant);\n });\n}\n\nfunction releaseRailSlot(): void {\n railsActive -= 1;\n railQueue.shift()?.();\n}\n\nfunction withTimeout<T>(promise: Promise<T>, ms: number, label: string): Promise<T> {\n return new Promise<T>((resolve, reject) => {\n const timer = setTimeout(() => reject(new Error(`${label} timed out`)), ms);\n promise.then(\n (value) => {\n clearTimeout(timer);\n resolve(value);\n },\n (err) => {\n clearTimeout(timer);\n reject(err);\n },\n );\n });\n}\n\nfunction cacheKey(departmentId: string, deep: boolean): string {\n return `${departmentId}:${deep ? 'deep' : 'fast'}`;\n}\n\n/** Read what a department already resolved to, at either depth. Deep wins. */\nexport function peekTrending(departmentId: string): Product[] | undefined {\n return cache.get(cacheKey(departmentId, true)) ?? cache.get(cacheKey(departmentId, false));\n}\n\n// Another account signed in: its rails are read again (web `followAccount` clears the query client).\nonAccountChange(() => {\n cache.clear();\n servedFromStore.clear();\n});\n\n/** Tests: forget every rail. */\nexport function clearTrendingCacheForTests(): void {\n cache.clear();\n inFlight.clear();\n servedFromStore.clear();\n railsActive = 0;\n railQueue.length = 0;\n}\n\nfunction fetchFast(departmentId: string, limit: number): RailFetchClaim {\n const key = cacheKey(departmentId, false);\n const cached = cache.get(key);\n if (cached) return { promise: Promise.resolve(cached), release: () => {} };\n\n let entry = inFlight.get(key);\n if (!entry) {\n const controller = new AbortController();\n const { signal } = controller;\n const preset = DEPARTMENT_SEARCH_PRESETS[departmentId];\n const promise = (async () => {\n // The STORE first, outside the rail slot: a rail saved within\n // STORED_BOARD_FRESH_MS is the answer, so opening the landing page\n // costs no provider quota at all.\n const stored = await loadStoredTrending(departmentId, limit).catch(() => null);\n if (stored?.fresh && stored.products.length > 0) {\n // Saved verified, but up to a freshness window ago: an item\n // delisted since then must not paint either.\n const live = await verifyProducts(stored.products);\n if (live.length > 0) {\n servedFromStore.add(departmentId);\n return live;\n }\n }\n servedFromStore.delete(departmentId);\n\n await acquireRailSlot(signal);\n const search = fetchFastUnpaced(departmentId, limit, preset, signal);\n // The slot goes back when the connector call really ends - not when\n // the rail stops waiting for it - so at most RAIL_CONCURRENCY rail\n // searches ever run on the account's executor at once.\n search.then(releaseRailSlot, releaseRailSlot);\n // Checked before anything sees them - the rail, the cache every\n // other rail reads, and the store the hook writes the rail to - so\n // a delisted row never paints, here or for the next visitor.\n return verifyProducts(await withTimeout(search, TRENDING_FAST_MS, `Trending ${departmentId}`));\n })();\n const created: RailFetch = { promise, controller, waiting: 0 };\n entry = created;\n inFlight.set(key, created);\n // A cancelled fetch caches nothing, so the next rail to want this\n // department starts a fresh one rather than inheriting the abort. Native\n // also leaves an EMPTY answer uncached: an early answer from the\n // not-yet-wired runtime must not stick for the life of the app.\n promise\n .then(\n (products) => {\n if (!signal.aborted && products.length > 0) cache.set(key, products);\n },\n () => {},\n )\n .finally(() => {\n if (inFlight.get(key) === created) inFlight.delete(key);\n });\n }\n\n const claimed = entry;\n claimed.waiting += 1;\n let released = false;\n return {\n promise: claimed.promise,\n release: () => {\n if (released) return;\n released = true;\n claimed.waiting -= 1;\n if (claimed.waiting > 0) return;\n if (inFlight.get(key) === claimed) inFlight.delete(key);\n claimed.controller.abort();\n },\n };\n}\n\nasync function fetchFastUnpaced(\n departmentId: string,\n limit: number,\n preset: (typeof DEPARTMENT_SEARCH_PRESETS)[string] | undefined,\n signal: AbortSignal,\n): Promise<Product[]> {\n // A department browse has no typed query — the preset IS the query, and no\n // relevance shape is passed, exactly as `useShoppingSearch` does for a chip\n // browse. `background`: a rail is prefetch nobody asked for yet, so its\n // catalog call yields the shared provider lane to anything a shopper is\n // waiting on.\n const fast = await searchShoppingProductsFast({\n query: '',\n departmentId,\n maxResults: limit,\n ...(preset ? { category: preset.category } : {}),\n lane: { priority: 'background', signal },\n });\n return fast.products.slice(0, limit);\n}\n\n/**\n * Rows for one department's rail.\n *\n * @param departmentId which aisle to fill\n * @param options.enabled hold the fetch until the rail is on screen\n * @param options.deep run the slow retailer research lane too — for the\n * department the user explicitly selected\n * @param options.limit how many rows to ask each provider for\n */\nexport function useTrendingProducts(\n departmentId: string | null,\n options: { enabled?: boolean; deep?: boolean; limit?: number } = {},\n): TrendingState {\n const { enabled = true, deep = false, limit = 12 } = options;\n /** Bumped by Try again: the effect reads again (a failed fast read cached nothing). */\n const [attempt, setAttempt] = useState(0);\n const retry = useCallback(() => setAttempt((n) => n + 1), []);\n const [state, setState] = useState<TrendingRead>(() => {\n const cached = departmentId ? peekTrending(departmentId) : undefined;\n return cached ? { ...EMPTY, products: cached } : EMPTY;\n });\n\n useEffect(() => {\n if (!departmentId || !enabled) return undefined;\n // Repaint from cache synchronously on a department change, so switching\n // tabs does not flash an empty rail at rows we already hold.\n const cached = deep ? cache.get(cacheKey(departmentId, true)) : peekTrending(departmentId);\n if (cached) {\n setState({ products: cached, isLoading: false, isEnriching: deep, error: null });\n } else {\n setState({ ...EMPTY, isLoading: true });\n }\n\n let live = true;\n /** This rail's claim on the shared fast fetch; released on unmount. */\n let claim: RailFetchClaim | null = null;\n const railKey = cacheKey(departmentId, deep);\n let rows: Product[] = cached ?? [];\n const verifications: Promise<void>[] = [];\n /** Page-check a painted batch and fold the verdicts back into the rail. */\n const verifyPainted = (batch: Product[]) => {\n if (batch.length === 0) return;\n verifications.push(\n verifyProducts(batch)\n .then((verified) => {\n if (!live) return;\n rows = applyVerifiedRows(rows, batch, verified);\n if (rows.length > 0) cache.set(railKey, rows);\n setState((prev) => ({ ...prev, products: rows }));\n })\n .catch((err) => console.warn('[shopping] trending verification failed:', err)),\n );\n };\n /**\n * Once every check has landed, the verified rail is what the next visitor\n * inherits. Fire-and-forget: a failed write just means the next visitor\n * sweeps again. A board the store served is not re-saved - the upsert\n * re-stamps it as observed now, and it would never age out.\n */\n const saveVerified = async () => {\n await Promise.allSettled(verifications);\n if (!live || rows.length === 0 || servedFromStore.has(departmentId)) return;\n void saveTrendingBoard(departmentId, rows).catch(() => {});\n };\n\n void (async () => {\n try {\n if (!cached) {\n claim = fetchFast(departmentId, limit);\n rows = await claim.promise;\n if (!live) return;\n setState({ products: rows, isLoading: false, isEnriching: deep, error: null });\n }\n verifyPainted(rows);\n } catch (err) {\n if (!live) return;\n setState({\n ...EMPTY,\n error: err instanceof Error ? err.message : 'Could not load trending products.',\n });\n return;\n }\n\n // A rail the store answered is DONE - running the cross-retailer lane\n // here would spend exactly the provider calls the freshness window is\n // there to save.\n if (!deep || servedFromStore.has(departmentId)) {\n if (live) setState((prev) => ({ ...prev, isLoading: false, isEnriching: false }));\n await saveVerified();\n return;\n }\n\n try {\n const preset = DEPARTMENT_SEARCH_PRESETS[departmentId];\n const rest = await searchShoppingProductsRest({\n query: '',\n departmentId,\n maxResults: limit,\n ...(preset ? { category: preset.category } : {}),\n });\n // Merge the slow lane's rows in once their pages check out — same\n // dedupe the grid uses.\n if (live && rest.products.length > 0) {\n const verified = await verifyProducts(rest.products);\n if (live && verified.length > 0) {\n rows = mergeShoppingProductSources([rows, verified]);\n cache.set(railKey, rows);\n setState((prev) => ({ ...prev, products: rows }));\n }\n }\n } catch (err) {\n // Best-effort: the fast rows already stand.\n console.warn('[shopping] trending cross-retailer lane failed:', err);\n }\n\n if (live) {\n if (rows.length > 0) cache.set(railKey, rows);\n setState((prev) => ({ ...prev, isEnriching: false }));\n }\n // Remember the ENRICHED rail, not just the fast rows: the next\n // reader should inherit the better board this visit paid for.\n await saveVerified();\n })();\n\n return () => {\n live = false;\n claim?.release();\n };\n }, [departmentId, enabled, deep, limit, attempt]);\n\n return { ...state, retry };\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AA8CA,MAAM,KAAsB,GAAA;AAAA,EAC1B,UAAU,EAAC;AAAA,EACX,SAAW,EAAA,KAAA;AAAA,EACX,WAAa,EAAA,KAAA;AAAA,EACb,KAAO,EAAA;AACT,CAAA;AAOA,MAAM,KAAA,uBAAY,GAAuB,EAAA;AAgBzC,MAAM,QAAA,uBAAe,GAAuB,EAAA;AAe5C,MAAM,eAAA,uBAAsB,GAAY,EAAA;AAOxC,MAAM,gBAAmB,GAAA,CAAA;AACzB,IAAI,WAAc,GAAA,CAAA;AAClB,MAAM,YAA+B,EAAC;AAWtC,MAAM,gBAAmB,GAAA,GAAA;AACzB,SAAS,WAAW,MAA8B,EAAA;AAEhD,EAAA,MAAM,SAAU,MAEb,CAAA,MAAA;AACH,EAAA,IAAI,QAAe,OAAA,MAAA;AACnB,EAAM,MAAA,KAAA,GAAQ,IAAI,KAAA,CAAM,4BAA4B,CAAA;AACpD,EAAA,KAAA,CAAM,IAAO,GAAA,YAAA;AACb,EAAO,OAAA,KAAA;AACT;AAGA,SAAS,gBAAgB,MAAoC,EAAA;AAC3D,EAAA,IAAI,OAAO,OAAS,EAAA,OAAO,QAAQ,MAAO,CAAA,UAAA,CAAW,MAAM,CA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S,CAAG,EAAA;AAC/B,YAAA,IAAA,GAAO,2BAA4B,CAAA,CAAC,IAAM,EAAA,QAAQ,CAAC,CAAA;AACnD,YAAM,KAAA,CAAA,GAAA,CAAI,SAAS,IAAI,CAAA;AACvB,YAAS,QAAA,CAAA,CAAA,IAAA,KAAS,iCACb,IADa,CAAA,EAAA;AAAA,cAEhB,QAAU,EAAA;AAAA,aACV,CAAA,CAAA;AAAA;AACJ;AACF,eACO,GAAK,EAAA;AAEZ,QAAQ,OAAA,CAAA,IAAA,CAAK,mDAAmD,GAAG,CAAA;AAAA;AAErE,MAAA,IAAI,IAAM,EAAA;AACR,QAAA,IAAI,KAAK,MAAS,GAAA,CAAA,EAAS,KAAA,CAAA,GAAA,CAAI,SAAS,IAAI,CAAA;AAC5C,QAAS,QAAA,CAAA,CAAA,IAAA,KAAS,iCACb,IADa,CAAA,EAAA;AAAA,UAEhB,WAAa,EAAA;AAAA,SACb,CAAA,CAAA;AAAA;AAIJ,MAAA,MAAM,YAAa,EAAA;AAAA,KAClB,GAAA;AACH,IAAA,OAAO,MAAM;AACX,MAAO,IAAA,GAAA,KAAA;AACP,MAAO,KAAA,IAAA,IAAA,GAAA,MAAA,GAAA,KAAA,CAAA,OAAA,EAAA;AAAA,KACT;AAAA,KACC,CAAC,YAAA,EAAc,SAAS,IAAM,EAAA,KAAA,EAAO,OAAO,CAAC,CAAA;AAChD,EAAA,OAAO,iCACF,KADE,CAAA,EAAA;AAAA,IAEL;AAAA,GACF,CAAA;AACF"}
|
|
@@ -1,6 +1,30 @@
|
|
|
1
|
-
import {useSyncExternalStore}from'react';var
|
|
1
|
+
import {useSyncExternalStore}from'react';var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var _a;
|
|
2
21
|
const STORAGE_KEY = "yantra.shopping.saved";
|
|
3
22
|
const MAX_ITEMS = 100;
|
|
23
|
+
const MAX_LISTS = 20;
|
|
24
|
+
function isGiftList(value) {
|
|
25
|
+
const list = value;
|
|
26
|
+
return typeof (list == null ? void 0 : list.name) === "string" && list.name.trim().length > 0 && (list.budget === void 0 || typeof list.budget === "number");
|
|
27
|
+
}
|
|
4
28
|
let AsyncStorage = null;
|
|
5
29
|
try {
|
|
6
30
|
AsyncStorage = (_a = require("@react-native-async-storage/async-storage").default) != null ? _a : null;
|
|
@@ -14,9 +38,11 @@ function isSavedProduct(value) {
|
|
|
14
38
|
}
|
|
15
39
|
let _items = [];
|
|
16
40
|
let _updatedAt = 0;
|
|
41
|
+
let _lists = [];
|
|
17
42
|
let _durable = {
|
|
18
43
|
items: _items,
|
|
19
|
-
updatedAt: _updatedAt
|
|
44
|
+
updatedAt: _updatedAt,
|
|
45
|
+
lists: _lists
|
|
20
46
|
};
|
|
21
47
|
let _ids = /* @__PURE__ */ new Set();
|
|
22
48
|
const _listeners = /* @__PURE__ */ new Set();
|
|
@@ -30,9 +56,11 @@ function emit(touched = true) {
|
|
|
30
56
|
_items = _items.slice(0, MAX_ITEMS);
|
|
31
57
|
_ids = new Set(_items.map((e) => e.product.id));
|
|
32
58
|
if (touched) _updatedAt = Date.now();
|
|
59
|
+
_lists = _lists.slice(0, MAX_LISTS);
|
|
33
60
|
_durable = {
|
|
34
61
|
items: _items,
|
|
35
|
-
updatedAt: _updatedAt
|
|
62
|
+
updatedAt: _updatedAt,
|
|
63
|
+
lists: _lists
|
|
36
64
|
};
|
|
37
65
|
persist(_durable);
|
|
38
66
|
_listeners.forEach((l) => l());
|
|
@@ -42,6 +70,7 @@ function mergeDurableSaved(cloud) {
|
|
|
42
70
|
const stamp = typeof cloud.updatedAt === "number" ? cloud.updatedAt : 0;
|
|
43
71
|
if (stamp <= _updatedAt) return false;
|
|
44
72
|
_items = cloud.items.filter(isSavedProduct);
|
|
73
|
+
_lists = Array.isArray(cloud.lists) ? cloud.lists.filter(isGiftList) : [];
|
|
45
74
|
_updatedAt = stamp;
|
|
46
75
|
emit(false);
|
|
47
76
|
return true;
|
|
@@ -65,10 +94,13 @@ function getDurableSaved() {
|
|
|
65
94
|
}
|
|
66
95
|
function saveProduct(product) {
|
|
67
96
|
if (!(product == null ? void 0 : product.id)) return;
|
|
68
|
-
|
|
97
|
+
const kept = _items.find((e) => e.product.id === product.id);
|
|
98
|
+
_items = [__spreadValues({
|
|
69
99
|
product,
|
|
70
100
|
ts: Date.now()
|
|
71
|
-
},
|
|
101
|
+
}, (kept == null ? void 0 : kept.list) ? {
|
|
102
|
+
list: kept.list
|
|
103
|
+
} : {}), ..._items.filter((e) => e.product.id !== product.id)];
|
|
72
104
|
emit();
|
|
73
105
|
}
|
|
74
106
|
function unsaveProduct(productId) {
|
|
@@ -90,10 +122,48 @@ function clearSavedProducts() {
|
|
|
90
122
|
_items = [];
|
|
91
123
|
emit();
|
|
92
124
|
}
|
|
125
|
+
function createGiftList(name, budget) {
|
|
126
|
+
const clean = name.trim().slice(0, 40);
|
|
127
|
+
if (!clean) return null;
|
|
128
|
+
const list = __spreadValues({
|
|
129
|
+
name: clean
|
|
130
|
+
}, budget !== void 0 && Number.isFinite(budget) && budget > 0 ? {
|
|
131
|
+
budget
|
|
132
|
+
} : {});
|
|
133
|
+
const at = _lists.findIndex((l) => l.name.toLowerCase() === clean.toLowerCase());
|
|
134
|
+
_lists = at >= 0 ? _lists.map((l, i) => i === at ? __spreadProps(__spreadValues({}, list), {
|
|
135
|
+
name: l.name
|
|
136
|
+
}) : l) : [..._lists, list];
|
|
137
|
+
emit();
|
|
138
|
+
return at >= 0 ? _lists[at] : list;
|
|
139
|
+
}
|
|
140
|
+
function removeGiftList(name) {
|
|
141
|
+
if (!_lists.some((l) => l.name === name)) return;
|
|
142
|
+
_lists = _lists.filter((l) => l.name !== name);
|
|
143
|
+
_items = _items.map((entry) => entry.list === name ? {
|
|
144
|
+
product: entry.product,
|
|
145
|
+
ts: entry.ts
|
|
146
|
+
} : entry);
|
|
147
|
+
emit();
|
|
148
|
+
}
|
|
149
|
+
function moveToGiftList(productId, name) {
|
|
150
|
+
if (name && !_lists.some((l) => l.name === name)) return;
|
|
151
|
+
_items = _items.map((entry) => entry.product.id !== productId ? entry : name ? __spreadProps(__spreadValues({}, entry), {
|
|
152
|
+
list: name
|
|
153
|
+
}) : {
|
|
154
|
+
product: entry.product,
|
|
155
|
+
ts: entry.ts
|
|
156
|
+
});
|
|
157
|
+
emit();
|
|
158
|
+
}
|
|
159
|
+
const EMPTY_LISTS = [];
|
|
160
|
+
function useGiftLists() {
|
|
161
|
+
return useSyncExternalStore(subscribe, () => _lists, () => EMPTY_LISTS);
|
|
162
|
+
}
|
|
93
163
|
const EMPTY = [];
|
|
94
164
|
function useSavedProducts() {
|
|
95
165
|
return useSyncExternalStore(subscribe, () => _items, () => EMPTY);
|
|
96
166
|
}
|
|
97
167
|
function useIsProductSaved(productId) {
|
|
98
168
|
return useSyncExternalStore(subscribe, () => _ids.has(productId), () => false);
|
|
99
|
-
}export{clearSavedProducts,getDurableSaved,hydrateSaved,mergeDurableSaved,saveProduct,subscribeSaved,toggleSavedProduct,unsaveProduct,useIsProductSaved,useSavedProducts};//# sourceMappingURL=savedProducts.js.map
|
|
169
|
+
}export{clearSavedProducts,createGiftList,getDurableSaved,hydrateSaved,mergeDurableSaved,moveToGiftList,removeGiftList,saveProduct,subscribeSaved,toggleSavedProduct,unsaveProduct,useGiftLists,useIsProductSaved,useSavedProducts};//# sourceMappingURL=savedProducts.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"savedProducts.js","sources":["../../../src/features/shopping/savedProducts.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\nimport type { Product } from './catalog';\n\nexport interface SavedProduct {\n product: Product;\n ts: number;\n}\n\nexport interface DurableSaved {\n items: SavedProduct[];\n updatedAt: number;\n}\n\nconst STORAGE_KEY = 'yantra.shopping.saved';\nconst MAX_ITEMS = 100;\n\ntype StorageLike = { getItem(key: string): Promise<string | null>; setItem(key: string, value: string): Promise<void> };\nlet AsyncStorage: StorageLike | null = null;\ntry {\n // eslint-disable-next-line @typescript-eslint/no-require-imports, global-require\n AsyncStorage = require('@react-native-async-storage/async-storage').default ?? null;\n} catch {\n AsyncStorage = null;\n}\n\nfunction isSavedProduct(value: unknown): value is SavedProduct {\n const entry = value as SavedProduct | null;\n return Boolean(entry?.product?.id) && typeof entry?.ts === 'number';\n}\n\nlet _items: SavedProduct[] = [];\nlet _updatedAt = 0;\n/** Stable object for the durable subscriber; re-created only when the list changes. */\nlet _durable: DurableSaved = { items: _items, updatedAt: _updatedAt };\nlet _ids = new Set<string>();\nconst _listeners = new Set<() => void>();\n\nfunction persist(saved: DurableSaved): void {\n try {\n void AsyncStorage?.setItem(STORAGE_KEY, JSON.stringify(saved));\n } catch {\n /* best-effort */\n }\n}\n\n/**\n * @param touched false for a merge that ADOPTS a remote list - its stamp belongs\n * to the device that made the edit, so re-stamping it here would make this\n * phone look like the newest writer and bounce the value straight back.\n */\nfunction emit(touched = true): void {\n _items = _items.slice(0, MAX_ITEMS);\n _ids = new Set(_items.map((e) => e.product.id));\n if (touched) _updatedAt = Date.now();\n _durable = { items: _items, updatedAt: _updatedAt };\n persist(_durable);\n _listeners.forEach((l) => l());\n}\n\n/**\n * Adopt a list from a durable copy (the account's `account.shopping.saved`, or\n * this phone's own AsyncStorage) when it is strictly newer than the one in\n * memory. Returns true when the local list changed. Last write wins on the whole\n * list - an un-save must not come back from an older copy (web 0.37.0).\n */\nexport function mergeDurableSaved(cloud: DurableSaved | null | undefined): boolean {\n if (!cloud || !Array.isArray(cloud.items)) return false;\n const stamp = typeof cloud.updatedAt === 'number' ? cloud.updatedAt : 0;\n if (stamp <= _updatedAt) return false;\n _items = cloud.items.filter(isSavedProduct);\n _updatedAt = stamp;\n emit(false);\n return true;\n}\n\n/** Read the stored list back, through the last-write-wins gate (a heart given before storage answered stands). */\nexport async function hydrateSaved(): Promise<void> {\n if (!AsyncStorage) return;\n try {\n const raw = await AsyncStorage.getItem(STORAGE_KEY);\n if (!raw) return;\n mergeDurableSaved(JSON.parse(raw) as DurableSaved);\n } catch {\n /* memory-only */\n }\n}\n\nfunction subscribe(listener: () => void): () => void {\n _listeners.add(listener);\n return () => _listeners.delete(listener);\n}\n\n/** Subscribe from outside React (the account sync does). */\nexport const subscribeSaved = subscribe;\n\n/** The list plus its stamp - what gets written to the account's config store. */\nexport function getDurableSaved(): DurableSaved {\n return _durable;\n}\n\n/** Whether this product is hearted, for callers outside React. */\nexport function isProductSaved(productId: string): boolean {\n return _ids.has(productId);\n}\n\nexport function saveProduct(product: Product): void {\n if (!product?.id) return;\n _items = [{ product, ts: Date.now() }, ..._items.filter((e) => e.product.id !== product.id)];\n emit();\n}\n\nexport function unsaveProduct(productId: string): void {\n if (!_ids.has(productId)) return;\n _items = _items.filter((e) => e.product.id !== productId);\n emit();\n}\n\nexport function toggleSavedProduct(product: Product): boolean {\n if (!product?.id) return false;\n if (_ids.has(product.id)) {\n unsaveProduct(product.id);\n return false;\n }\n saveProduct(product);\n return true;\n}\n\nexport function clearSavedProducts(): void {\n if (_items.length === 0) return;\n _items = [];\n emit();\n}\n\nconst EMPTY: SavedProduct[] = [];\n\nexport function useSavedProducts(): SavedProduct[] {\n return useSyncExternalStore(\n subscribe,\n () => _items,\n () => EMPTY,\n );\n}\n\nexport function useIsProductSaved(productId: string): boolean {\n return useSyncExternalStore(\n subscribe,\n () => _ids.has(productId),\n () => false,\n );\n}\n\nexport function __resetSaved(): void {\n _items = [];\n _ids = new Set();\n _updatedAt = 0;\n _durable = { items: _items, updatedAt: 0 };\n persist(_durable);\n _listeners.forEach((l) => l());\n}\n"],"names":["_a"],"mappings":"yCAAA,IAAA,EAAA;AAUA,MAAM,WAAc,GAAA,uBAAA;AACpB,MAAM,SAAY,GAAA,GAAA;AAKlB,IAAI,YAAmC,GAAA,IAAA;AACvC,IAAI;AAEF,EAAA,YAAA,GAAA,CAAe,EAAQ,GAAA,OAAA,CAAA,2CAA2C,CAAE,CAAA,OAAA,KAArD,IAAgE,GAAA,EAAA,GAAA,IAAA;AACjF,CAAQ,CAAA,OAAA,CAAA,EAAA;AACN,EAAe,YAAA,GAAA,IAAA;AACjB;AACA,SAAS,eAAe,KAAuC,EAAA;AAvB/D,EAAAA,IAAAA,GAAAA;AAwBE,EAAA,MAAM,KAAQ,GAAA,KAAA;AACd,EAAO,OAAA,OAAA,CAAA,CAAQA,GAAA,GAAA,KAAA,IAAA,IAAA,GAAA,MAAA,GAAA,KAAA,CAAO,OAAP,KAAA,IAAA,GAAA,MAAA,GAAAA,IAAgB,EAAE,CAAA,IAAK,QAAO,KAAA,IAAA,IAAA,GAAA,MAAA,GAAA,KAAA,CAAO,EAAO,CAAA,KAAA,QAAA;AAC7D;AACA,IAAI,SAAyB,EAAC;AAC9B,IAAI,UAAa,GAAA,CAAA;AAEjB,IAAI,QAAyB,GAAA;AAAA,EAC3B,KAAO,EAAA,MAAA;AAAA,EACP,SAAW,EAAA;AACb,CAAA;AACA,IAAI,IAAA,uBAAW,GAAY,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CAAI,OAAQ,CAAA,EAAE,CAAG,EAAA;AACxB,IAAA,aAAA,CAAc,QAAQ,EAAE,CAAA;AACxB,IAAO,OAAA,KAAA;AAAA;AAET,EAAA,WAAA,CAAY,OAAO,CAAA;AACnB,EAAO,OAAA,IAAA;AACT;AACO,SAAS,kBAA2B,GAAA;AACzC,EAAI,IAAA,MAAA,CAAO,WAAW,CAAG,EAAA;AACzB,EAAA,MAAA,GAAS,EAAC;AACV,EAAK,IAAA,EAAA;AACP;AACA,MAAM,QAAwB,EAAC;AACxB,SAAS,gBAAmC,GAAA;AACjD,EAAA,OAAO,oBAAqB,CAAA,SAAA,EAAW,MAAM,MAAA,EAAQ,MAAM,KAAK,CAAA;AAClE;AACO,SAAS,kBAAkB,SAA4B,EAAA;AAC5D,EAAO,OAAA,oBAAA,CAAqB,WAAW,MAAM,IAAA,CAAK,IAAI,SAAS,CAAA,EAAG,MAAM,KAAK,CAAA;AAC/E"}
|
|
1
|
+
{"version":3,"file":"savedProducts.js","sources":["../../../src/features/shopping/savedProducts.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\nimport type { Product } from './catalog';\n\nexport interface SavedProduct {\n product: Product;\n ts: number;\n /** The gift list it is on (\"Dad\"), when it is on one. */\n list?: string;\n}\n\n/**\n * A gift list: who it is for, and what they mean to spend (web 0.49.0). Gift\n * guides by recipient and budget are what holiday shoppers look for; a list\n * here groups saved products the same way.\n */\nexport interface GiftList {\n name: string;\n /** Dollars, when a budget was set. */\n budget?: number;\n}\n\nexport interface DurableSaved {\n items: SavedProduct[];\n updatedAt: number;\n /** The gift lists, in the order they were made. Saved with the items: one last-write-wins record. */\n lists?: GiftList[];\n}\n\nconst STORAGE_KEY = 'yantra.shopping.saved';\nconst MAX_ITEMS = 100;\nconst MAX_LISTS = 20;\n\nfunction isGiftList(value: unknown): value is GiftList {\n const list = value as GiftList | null;\n return (\n typeof list?.name === 'string' &&\n list.name.trim().length > 0 &&\n (list.budget === undefined || typeof list.budget === 'number')\n );\n}\n\ntype StorageLike = { getItem(key: string): Promise<string | null>; setItem(key: string, value: string): Promise<void> };\nlet AsyncStorage: StorageLike | null = null;\ntry {\n // eslint-disable-next-line @typescript-eslint/no-require-imports, global-require\n AsyncStorage = require('@react-native-async-storage/async-storage').default ?? null;\n} catch {\n AsyncStorage = null;\n}\n\nfunction isSavedProduct(value: unknown): value is SavedProduct {\n const entry = value as SavedProduct | null;\n return Boolean(entry?.product?.id) && typeof entry?.ts === 'number';\n}\n\nlet _items: SavedProduct[] = [];\nlet _updatedAt = 0;\nlet _lists: GiftList[] = [];\n/** Stable object for the durable subscriber; re-created only when the list changes. */\nlet _durable: DurableSaved = { items: _items, updatedAt: _updatedAt, lists: _lists };\nlet _ids = new Set<string>();\nconst _listeners = new Set<() => void>();\n\nfunction persist(saved: DurableSaved): void {\n try {\n void AsyncStorage?.setItem(STORAGE_KEY, JSON.stringify(saved));\n } catch {\n /* best-effort */\n }\n}\n\n/**\n * @param touched false for a merge that ADOPTS a remote list - its stamp belongs\n * to the device that made the edit, so re-stamping it here would make this\n * phone look like the newest writer and bounce the value straight back.\n */\nfunction emit(touched = true): void {\n _items = _items.slice(0, MAX_ITEMS);\n _ids = new Set(_items.map((e) => e.product.id));\n if (touched) _updatedAt = Date.now();\n _lists = _lists.slice(0, MAX_LISTS);\n _durable = { items: _items, updatedAt: _updatedAt, lists: _lists };\n persist(_durable);\n _listeners.forEach((l) => l());\n}\n\n/**\n * Adopt a list from a durable copy (the account's `account.shopping.saved`, or\n * this phone's own AsyncStorage) when it is strictly newer than the one in\n * memory. Returns true when the local list changed. Last write wins on the whole\n * list - an un-save must not come back from an older copy (web 0.37.0).\n */\nexport function mergeDurableSaved(cloud: DurableSaved | null | undefined): boolean {\n if (!cloud || !Array.isArray(cloud.items)) return false;\n const stamp = typeof cloud.updatedAt === 'number' ? cloud.updatedAt : 0;\n if (stamp <= _updatedAt) return false;\n _items = cloud.items.filter(isSavedProduct);\n _lists = Array.isArray(cloud.lists) ? cloud.lists.filter(isGiftList) : [];\n _updatedAt = stamp;\n emit(false);\n return true;\n}\n\n/** Read the stored list back, through the last-write-wins gate (a heart given before storage answered stands). */\nexport async function hydrateSaved(): Promise<void> {\n if (!AsyncStorage) return;\n try {\n const raw = await AsyncStorage.getItem(STORAGE_KEY);\n if (!raw) return;\n mergeDurableSaved(JSON.parse(raw) as DurableSaved);\n } catch {\n /* memory-only */\n }\n}\n\nfunction subscribe(listener: () => void): () => void {\n _listeners.add(listener);\n return () => _listeners.delete(listener);\n}\n\n/** Subscribe from outside React (the account sync does). */\nexport const subscribeSaved = subscribe;\n\n/** The list plus its stamp - what gets written to the account's config store. */\nexport function getDurableSaved(): DurableSaved {\n return _durable;\n}\n\n/** Whether this product is hearted, for callers outside React. */\nexport function isProductSaved(productId: string): boolean {\n return _ids.has(productId);\n}\n\nexport function saveProduct(product: Product): void {\n if (!product?.id) return;\n // Saved again, it keeps the gift list it was on.\n const kept = _items.find((e) => e.product.id === product.id);\n _items = [\n { product, ts: Date.now(), ...(kept?.list ? { list: kept.list } : {}) },\n ..._items.filter((e) => e.product.id !== product.id),\n ];\n emit();\n}\n\nexport function unsaveProduct(productId: string): void {\n if (!_ids.has(productId)) return;\n _items = _items.filter((e) => e.product.id !== productId);\n emit();\n}\n\nexport function toggleSavedProduct(product: Product): boolean {\n if (!product?.id) return false;\n if (_ids.has(product.id)) {\n unsaveProduct(product.id);\n return false;\n }\n saveProduct(product);\n return true;\n}\n\nexport function clearSavedProducts(): void {\n if (_items.length === 0) return;\n _items = [];\n emit();\n}\n\n/** Make a gift list (a name already taken keeps the first, with the new budget). */\nexport function createGiftList(name: string, budget?: number): GiftList | null {\n const clean = name.trim().slice(0, 40);\n if (!clean) return null;\n const list: GiftList = {\n name: clean,\n ...(budget !== undefined && Number.isFinite(budget) && budget > 0 ? { budget } : {}),\n };\n const at = _lists.findIndex((l) => l.name.toLowerCase() === clean.toLowerCase());\n _lists = at >= 0 ? _lists.map((l, i) => (i === at ? { ...list, name: l.name } : l)) : [..._lists, list];\n emit();\n return at >= 0 ? _lists[at] : list;\n}\n\n/** Delete a gift list; its products stay saved, on no list. */\nexport function removeGiftList(name: string): void {\n if (!_lists.some((l) => l.name === name)) return;\n _lists = _lists.filter((l) => l.name !== name);\n _items = _items.map((entry) => (entry.list === name ? { product: entry.product, ts: entry.ts } : entry));\n emit();\n}\n\n/** Put a saved product on a gift list, or (no name) on none. */\nexport function moveToGiftList(productId: string, name?: string): void {\n if (name && !_lists.some((l) => l.name === name)) return;\n _items = _items.map((entry) =>\n entry.product.id !== productId\n ? entry\n : name\n ? { ...entry, list: name }\n : { product: entry.product, ts: entry.ts },\n );\n emit();\n}\n\nconst EMPTY_LISTS: GiftList[] = [];\n\n/** Subscribe a component to the gift lists. */\nexport function useGiftLists(): GiftList[] {\n return useSyncExternalStore(\n subscribe,\n () => _lists,\n () => EMPTY_LISTS,\n );\n}\n\nconst EMPTY: SavedProduct[] = [];\n\nexport function useSavedProducts(): SavedProduct[] {\n return useSyncExternalStore(\n subscribe,\n () => _items,\n () => EMPTY,\n );\n}\n\nexport function useIsProductSaved(productId: string): boolean {\n return useSyncExternalStore(\n subscribe,\n () => _ids.has(productId),\n () => false,\n );\n}\n\nexport function __resetSaved(): void {\n _items = [];\n _ids = new Set();\n _updatedAt = 0;\n _lists = [];\n _durable = { items: _items, updatedAt: 0, lists: _lists };\n persist(_durable);\n _listeners.forEach((l) => l());\n}\n"],"names":["_a"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,IAAA,EAAA;AAyBA,MAAM,WAAc,GAAA,uBAAA;AACpB,MAAM,SAAY,GAAA,GAAA;AAClB,MAAM,SAAY,GAAA,EAAA;AAClB,SAAS,WAAW,KAAmC,EAAA;AACrD,EAAA,MAAM,IAAO,GAAA,KAAA;AACb,EAAA,OAAO,QAAO,IAAA,IAAA,IAAA,GAAA,MAAA,GAAA,IAAA,CAAM,IAAS,CAAA,KAAA,QAAA,IAAY,KAAK,IAAK,CAAA,IAAA,EAAO,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AO,oBAAqB,CAAA,SAAA,EAAW,MAAM,MAAA,EAAQ,MAAM,KAAK,CAAA;AAClE;AACO,SAAS,kBAAkB,SAA4B,EAAA;AAC5D,EAAO,OAAA,oBAAA,CAAqB,WAAW,MAAM,IAAA,CAAK,IAAI,SAAS,CAAA,EAAG,MAAM,KAAK,CAAA;AAC/E"}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import {askModelOneStep,extractJson}from'./modelStep.js';var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
const MODEL = "small";
|
|
21
|
+
const CHUNK = 25;
|
|
22
|
+
const TIMEOUT_MS = 3e4;
|
|
23
|
+
const MAX_CACHED = 3e3;
|
|
24
|
+
const SYSTEM = [
|
|
25
|
+
"You check online-store search results against what a shopper searched for.",
|
|
26
|
+
"For each numbered listing, decide what it IS relative to the search:",
|
|
27
|
+
'- "exact": it is the product searched for. Seller, condition (new, used, renewed, refurbished, open box), color,',
|
|
28
|
+
" storage, memory and any other option the shopper did not name do not matter. A bundle that includes it counts.",
|
|
29
|
+
'- "close": the same product, but it differs from something the shopper DID name: another variant or line of the',
|
|
30
|
+
" same model (the plain or Max chip when they named the Pro chip, Pro Max when they named Pro), or another size",
|
|
31
|
+
' than the one named. Put what differs in "n", at most 6 words ("M3 chip, not M3 Pro").',
|
|
32
|
+
'- "accessory": something FOR the product rather than the product: a case, cover, sleeve, bag, skin, charger,',
|
|
33
|
+
" cable, adapter, hub, dock, stand, mount, screen protector, keyboard cover, replacement part, book, guide,",
|
|
34
|
+
' course, warranty or service plan. When the shopper searched FOR an accessory, that accessory is "exact".',
|
|
35
|
+
'- "other": a different product that only shares words with the search: another product line of the brand',
|
|
36
|
+
" (an iPad or a MacBook Air when they searched a MacBook Pro), another generation or chip than the one named",
|
|
37
|
+
' (an M2 or M4 MacBook for "m3 macbook", an iPhone 14 for "iphone 15"), or something else entirely that',
|
|
38
|
+
' happens to carry the model name (a garment iron called "M3 Pro").',
|
|
39
|
+
"Judge what the listing is, not how many words it shares with the search. A listing that does not say which",
|
|
40
|
+
'variant it is, but is the product line searched, is "exact".',
|
|
41
|
+
`Call report_verdicts with one string per listing, in the listings' order - "e" exact, "c:<what differs>" close,`,
|
|
42
|
+
'"a" accessory, "o" other. For four listings: {"r":["e","c:M3 chip, not M3 Pro","o","a"]}',
|
|
43
|
+
// The router's fast tier can land on a lane that offers no caller tools (measured live 2026-11-19):
|
|
44
|
+
// looking for the tool there costs a step and finds nothing.
|
|
45
|
+
"If report_verdicts is not available to you, do not look for it: reply with only that JSON."
|
|
46
|
+
].join("\n");
|
|
47
|
+
const VERDICT_TOOL = {
|
|
48
|
+
type: "function",
|
|
49
|
+
function: {
|
|
50
|
+
name: "report_verdicts",
|
|
51
|
+
description: "The verdict on every listing, in the order they were listed.",
|
|
52
|
+
parameters: {
|
|
53
|
+
type: "object",
|
|
54
|
+
properties: {
|
|
55
|
+
r: {
|
|
56
|
+
type: "array",
|
|
57
|
+
items: {
|
|
58
|
+
type: "string"
|
|
59
|
+
},
|
|
60
|
+
description: 'One per listing: "e", "c:<what differs>", "a" or "o".'
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
required: ["r"]
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const cache = /* @__PURE__ */ new Map();
|
|
68
|
+
function norm(text) {
|
|
69
|
+
return text.toLowerCase().replace(/\s+/g, " ").trim();
|
|
70
|
+
}
|
|
71
|
+
function cacheKey(query, row) {
|
|
72
|
+
var _a;
|
|
73
|
+
return `${norm(query)}\0${norm(row.name)}\0${norm((_a = row.storeCategory) != null ? _a : "")}`;
|
|
74
|
+
}
|
|
75
|
+
function remember(key, verdict) {
|
|
76
|
+
if (cache.size >= MAX_CACHED) {
|
|
77
|
+
const oldest = cache.keys().next().value;
|
|
78
|
+
if (oldest !== void 0) cache.delete(oldest);
|
|
79
|
+
}
|
|
80
|
+
cache.set(key, verdict);
|
|
81
|
+
}
|
|
82
|
+
function listingLine(row, n) {
|
|
83
|
+
const facts = [row.retailerId || row.source, row.storeCategory ? `filed under "${row.storeCategory.slice(0, 80)}"` : "", row.price > 0 ? `$${row.price.toFixed(2)}` : ""].filter(Boolean);
|
|
84
|
+
return `${n}. ${row.name.replace(/\s+/g, " ").trim().slice(0, 220)}${facts.length ? ` (${facts.join("; ")})` : ""}`;
|
|
85
|
+
}
|
|
86
|
+
const MATCHES = /* @__PURE__ */ new Set(["exact", "close", "accessory", "other"]);
|
|
87
|
+
const CODES = {
|
|
88
|
+
e: "exact",
|
|
89
|
+
c: "close",
|
|
90
|
+
a: "accessory",
|
|
91
|
+
o: "other"
|
|
92
|
+
};
|
|
93
|
+
function codedVerdict(entry) {
|
|
94
|
+
var _a;
|
|
95
|
+
const [head, ...rest] = entry.split(":");
|
|
96
|
+
const word = head.trim().toLowerCase();
|
|
97
|
+
const match = (_a = CODES[word]) != null ? _a : MATCHES.has(word) ? word : null;
|
|
98
|
+
if (!match) return null;
|
|
99
|
+
const note = match === "close" ? rest.join(":").trim().slice(0, 60) : "";
|
|
100
|
+
return __spreadValues({
|
|
101
|
+
match
|
|
102
|
+
}, note ? {
|
|
103
|
+
note
|
|
104
|
+
} : {});
|
|
105
|
+
}
|
|
106
|
+
function parseVerdicts(reply, count) {
|
|
107
|
+
const out = /* @__PURE__ */ new Map();
|
|
108
|
+
let body;
|
|
109
|
+
try {
|
|
110
|
+
body = extractJson(reply);
|
|
111
|
+
} catch (e) {
|
|
112
|
+
return out;
|
|
113
|
+
}
|
|
114
|
+
const list = Array.isArray(body) ? body : body == null ? void 0 : body.r;
|
|
115
|
+
if (!Array.isArray(list)) return out;
|
|
116
|
+
if (list.every((entry) => typeof entry === "string")) {
|
|
117
|
+
if (list.length !== count) return out;
|
|
118
|
+
list.forEach((entry, i) => {
|
|
119
|
+
const verdict = codedVerdict(entry);
|
|
120
|
+
if (verdict) out.set(i + 1, verdict);
|
|
121
|
+
});
|
|
122
|
+
return out;
|
|
123
|
+
}
|
|
124
|
+
for (const entry of list) {
|
|
125
|
+
if (!entry || typeof entry !== "object") continue;
|
|
126
|
+
const {
|
|
127
|
+
i,
|
|
128
|
+
m,
|
|
129
|
+
n
|
|
130
|
+
} = entry;
|
|
131
|
+
const index = typeof i === "number" ? i : typeof i === "string" ? Number(i) : NaN;
|
|
132
|
+
const match = typeof m === "string" ? m.trim().toLowerCase() : "";
|
|
133
|
+
if (!Number.isInteger(index) || index < 1 || index > count || !MATCHES.has(match)) continue;
|
|
134
|
+
const note = match === "close" && typeof n === "string" && n.trim() ? n.trim().slice(0, 60) : void 0;
|
|
135
|
+
out.set(index, __spreadValues({
|
|
136
|
+
match
|
|
137
|
+
}, note ? {
|
|
138
|
+
note
|
|
139
|
+
} : {}));
|
|
140
|
+
}
|
|
141
|
+
return out;
|
|
142
|
+
}
|
|
143
|
+
async function judgeRowsWithAi(query, rows, complete = askModelOneStep) {
|
|
144
|
+
const search = query.trim();
|
|
145
|
+
if (!search || rows.length === 0) return /* @__PURE__ */ new Map();
|
|
146
|
+
const out = /* @__PURE__ */ new Map();
|
|
147
|
+
const unread = [];
|
|
148
|
+
for (const row of rows) {
|
|
149
|
+
const known = cache.get(cacheKey(search, row));
|
|
150
|
+
if (known) out.set(row.id, known);
|
|
151
|
+
else if (row.name.trim()) unread.push(row);
|
|
152
|
+
}
|
|
153
|
+
if (unread.length === 0) return out;
|
|
154
|
+
const chunks = [];
|
|
155
|
+
for (let i = 0; i < unread.length; i += CHUNK) chunks.push(unread.slice(i, i + CHUNK));
|
|
156
|
+
const answers = await Promise.allSettled(chunks.map(async (chunk) => {
|
|
157
|
+
const reply = await complete({
|
|
158
|
+
model: MODEL,
|
|
159
|
+
system: SYSTEM,
|
|
160
|
+
prompt: `Search: "${search.slice(0, 200)}"
|
|
161
|
+
Listings:
|
|
162
|
+
${chunk.map((row, i) => listingLine(row, i + 1)).join("\n")}`,
|
|
163
|
+
tool: VERDICT_TOOL,
|
|
164
|
+
timeoutMs: TIMEOUT_MS
|
|
165
|
+
});
|
|
166
|
+
return {
|
|
167
|
+
chunk,
|
|
168
|
+
verdicts: parseVerdicts(reply, chunk.length)
|
|
169
|
+
};
|
|
170
|
+
}));
|
|
171
|
+
let answered = false;
|
|
172
|
+
for (const answer of answers) {
|
|
173
|
+
if (answer.status !== "fulfilled" || answer.value.verdicts.size === 0) continue;
|
|
174
|
+
answered = true;
|
|
175
|
+
const {
|
|
176
|
+
chunk,
|
|
177
|
+
verdicts
|
|
178
|
+
} = answer.value;
|
|
179
|
+
for (const [index, verdict] of verdicts) {
|
|
180
|
+
const row = chunk[index - 1];
|
|
181
|
+
out.set(row.id, verdict);
|
|
182
|
+
remember(cacheKey(search, row), verdict);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return answered || out.size > 0 ? out : null;
|
|
186
|
+
}
|
|
187
|
+
function applyAiVerdicts(rows, verdicts) {
|
|
188
|
+
if (!verdicts || verdicts.size === 0) return [...rows];
|
|
189
|
+
const out = [];
|
|
190
|
+
for (const row of rows) {
|
|
191
|
+
const verdict = verdicts.get(row.id);
|
|
192
|
+
if (!verdict) {
|
|
193
|
+
out.push(row);
|
|
194
|
+
} else if (verdict.match === "exact") {
|
|
195
|
+
out.push(__spreadProps(__spreadValues({}, row), {
|
|
196
|
+
match: "exact",
|
|
197
|
+
matchNote: void 0
|
|
198
|
+
}));
|
|
199
|
+
} else if (verdict.match === "close") {
|
|
200
|
+
out.push(__spreadValues(__spreadProps(__spreadValues({}, row), {
|
|
201
|
+
match: "close"
|
|
202
|
+
}), verdict.note ? {
|
|
203
|
+
matchNote: verdict.note
|
|
204
|
+
} : {}));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return out;
|
|
208
|
+
}
|
|
209
|
+
function rankByMatch(rows) {
|
|
210
|
+
const close = rows.filter((row) => row.match === "close");
|
|
211
|
+
return close.length === 0 ? [...rows] : [...rows.filter((row) => row.match !== "close"), ...close];
|
|
212
|
+
}export{applyAiVerdicts,askModelOneStep,judgeRowsWithAi,parseVerdicts,rankByMatch};//# sourceMappingURL=aiRelevance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aiRelevance.js","sources":["../../../../src/features/shopping/services/aiRelevance.ts"],"sourcesContent":["/**\n * Native twin of the web surface's `services/aiRelevance.ts` (0.49.0), verbatim\n * but for where `extractJson` lives (services/modelStep here).\n *\n * A second reading of the search's rows, by a language model: is each listing\n * the product the shopper searched for, a close variant of it, something FOR it,\n * or a different product that only shares words?\n *\n * The word rules (searchRelevance) are fast and run everywhere, but words are\n * all they see: a garment iron named \"M3 Pro\", an iPad Pro for \"macbook pro\", a\n * MacBook Air for \"m3 pro macbook\" each carry enough of the query to pass. A\n * model reads the listing the way the shopper does. It runs on every lane's rows\n * before they paint (useShoppingSearch), alongside the product-page check, and\n * only ever takes rows away or ranks them - it never adds one the rules dropped.\n *\n * No answer (the agent unreachable, a reply that is not JSON, too slow) is not a\n * verdict: those rows paint as the rules left them.\n */\n\nimport type { Product } from '../catalog';\nimport { askModelOneStep, extractJson, type AskModel, type ModelTool } from './modelStep';\n\nexport { askModelOneStep, type AskModel } from './modelStep';\n\n/** The model's reading of one listing against the search. */\nexport type AiMatch = 'exact' | 'close' | 'accessory' | 'other';\n\nexport interface AiVerdict {\n match: AiMatch;\n /** For `close`: what differs from the search, in a few words. */\n note?: string;\n}\n\n/** The router's fast tier: sorting short titles needs no more, and it answers in seconds. */\nconst MODEL = 'small';\n/**\n * Listings per request. Requests go one at a time (modelStep) - measured live\n * 2026-11-19, requests sent together waited on one another past their budget -\n * and the reply is a short code per listing, so a lane's rows go out in as few\n * requests as fit.\n */\nconst CHUNK = 25;\n/** The request's own budget; the grid does not wait this long (see AI_PAINT_WAIT_MS in useShoppingSearch). */\nconst TIMEOUT_MS = 30_000;\nconst MAX_CACHED = 3000;\n\nconst SYSTEM = [\n 'You check online-store search results against what a shopper searched for.',\n 'For each numbered listing, decide what it IS relative to the search:',\n '- \"exact\": it is the product searched for. Seller, condition (new, used, renewed, refurbished, open box), color,',\n ' storage, memory and any other option the shopper did not name do not matter. A bundle that includes it counts.',\n '- \"close\": the same product, but it differs from something the shopper DID name: another variant or line of the',\n ' same model (the plain or Max chip when they named the Pro chip, Pro Max when they named Pro), or another size',\n ' than the one named. Put what differs in \"n\", at most 6 words (\"M3 chip, not M3 Pro\").',\n '- \"accessory\": something FOR the product rather than the product: a case, cover, sleeve, bag, skin, charger,',\n ' cable, adapter, hub, dock, stand, mount, screen protector, keyboard cover, replacement part, book, guide,',\n ' course, warranty or service plan. When the shopper searched FOR an accessory, that accessory is \"exact\".',\n '- \"other\": a different product that only shares words with the search: another product line of the brand',\n ' (an iPad or a MacBook Air when they searched a MacBook Pro), another generation or chip than the one named',\n ' (an M2 or M4 MacBook for \"m3 macbook\", an iPhone 14 for \"iphone 15\"), or something else entirely that',\n ' happens to carry the model name (a garment iron called \"M3 Pro\").',\n 'Judge what the listing is, not how many words it shares with the search. A listing that does not say which',\n 'variant it is, but is the product line searched, is \"exact\".',\n 'Call report_verdicts with one string per listing, in the listings\\' order - \"e\" exact, \"c:<what differs>\" close,',\n '\"a\" accessory, \"o\" other. For four listings: {\"r\":[\"e\",\"c:M3 chip, not M3 Pro\",\"o\",\"a\"]}',\n // The router's fast tier can land on a lane that offers no caller tools (measured live 2026-11-19):\n // looking for the tool there costs a step and finds nothing.\n 'If report_verdicts is not available to you, do not look for it: reply with only that JSON.',\n].join('\\n');\n\n/** The tool the model answers through (see modelStep for why a tool at all). */\nconst VERDICT_TOOL: ModelTool = {\n type: 'function',\n function: {\n name: 'report_verdicts',\n description: 'The verdict on every listing, in the order they were listed.',\n parameters: {\n type: 'object',\n properties: {\n r: {\n type: 'array',\n items: { type: 'string' },\n description: 'One per listing: \"e\", \"c:<what differs>\", \"a\" or \"o\".',\n },\n },\n required: ['r'],\n },\n },\n};\n\nconst cache = new Map<string, AiVerdict>();\n\nfunction norm(text: string): string {\n return text.toLowerCase().replace(/\\s+/g, ' ').trim();\n}\n\nfunction cacheKey(query: string, row: Product): string {\n return `${norm(query)}\\u0000${norm(row.name)}\\u0000${norm(row.storeCategory ?? '')}`;\n}\n\nfunction remember(key: string, verdict: AiVerdict): void {\n if (cache.size >= MAX_CACHED) {\n const oldest = cache.keys().next().value;\n if (oldest !== undefined) cache.delete(oldest);\n }\n cache.set(key, verdict);\n}\n\n/** One listing as the model reads it: the title, then where it is sold, filed and priced. */\nfunction listingLine(row: Product, n: number): string {\n const facts = [\n row.retailerId || row.source,\n row.storeCategory ? `filed under \"${row.storeCategory.slice(0, 80)}\"` : '',\n row.price > 0 ? `$${row.price.toFixed(2)}` : '',\n ].filter(Boolean);\n return `${n}. ${row.name.replace(/\\s+/g, ' ').trim().slice(0, 220)}${facts.length ? ` (${facts.join('; ')})` : ''}`;\n}\n\nconst MATCHES: ReadonlySet<string> = new Set(['exact', 'close', 'accessory', 'other']);\nconst CODES: Record<string, AiMatch> = { e: 'exact', c: 'close', a: 'accessory', o: 'other' };\n\n/**\n * One positional answer (\"e\", \"c:M3 chip, not M3 Pro\", \"a\", \"o\", or the word\n * spelled out) as a verdict, or null when it is neither.\n */\nfunction codedVerdict(entry: string): AiVerdict | null {\n const [head, ...rest] = entry.split(':');\n const word = head.trim().toLowerCase();\n const match = CODES[word] ?? (MATCHES.has(word) ? (word as AiMatch) : null);\n if (!match) return null;\n const note = match === 'close' ? rest.join(':').trim().slice(0, 60) : '';\n return { match, ...(note ? { note } : {}) };\n}\n\n/** The verdicts in a reply, by listing number; entries that are not well formed are skipped. */\nexport function parseVerdicts(reply: string, count: number): Map<number, AiVerdict> {\n const out = new Map<number, AiVerdict>();\n let body: unknown;\n try {\n body = extractJson(reply);\n } catch {\n return out;\n }\n const list = Array.isArray(body) ? body : (body as { r?: unknown })?.r;\n if (!Array.isArray(list)) return out;\n // The asked-for shape: one string per listing, in order. A list of another\n // length has lost its place, and every answer in it could be a neighbour's.\n if (list.every((entry) => typeof entry === 'string')) {\n if (list.length !== count) return out;\n list.forEach((entry, i) => {\n const verdict = codedVerdict(entry as string);\n if (verdict) out.set(i + 1, verdict);\n });\n return out;\n }\n for (const entry of list) {\n if (!entry || typeof entry !== 'object') continue;\n const { i, m, n } = entry as { i?: unknown; m?: unknown; n?: unknown };\n const index = typeof i === 'number' ? i : typeof i === 'string' ? Number(i) : NaN;\n const match = typeof m === 'string' ? m.trim().toLowerCase() : '';\n if (!Number.isInteger(index) || index < 1 || index > count || !MATCHES.has(match)) continue;\n const note = match === 'close' && typeof n === 'string' && n.trim() ? n.trim().slice(0, 60) : undefined;\n out.set(index, { match: match as AiMatch, ...(note ? { note } : {}) });\n }\n return out;\n}\n\n/**\n * The model's verdict on each of `rows` for `query`, by row id - or null when it\n * gave none at all (unreachable, unreadable). A row it skipped has no entry, and\n * is left as the word rules left it.\n *\n * Verdicts are kept per query and listing, so a row two lanes return, or the\n * same search run again, is read once.\n */\nexport async function judgeRowsWithAi(\n query: string,\n rows: readonly Product[],\n complete: AskModel = askModelOneStep,\n): Promise<Map<string, AiVerdict> | null> {\n const search = query.trim();\n if (!search || rows.length === 0) return new Map();\n const out = new Map<string, AiVerdict>();\n const unread: Product[] = [];\n for (const row of rows) {\n const known = cache.get(cacheKey(search, row));\n if (known) out.set(row.id, known);\n else if (row.name.trim()) unread.push(row);\n }\n if (unread.length === 0) return out;\n\n const chunks: Product[][] = [];\n for (let i = 0; i < unread.length; i += CHUNK) chunks.push(unread.slice(i, i + CHUNK));\n const answers = await Promise.allSettled(\n chunks.map(async (chunk) => {\n const reply = await complete({\n model: MODEL,\n system: SYSTEM,\n prompt: `Search: \"${search.slice(0, 200)}\"\\nListings:\\n${chunk.map((row, i) => listingLine(row, i + 1)).join('\\n')}`,\n tool: VERDICT_TOOL,\n timeoutMs: TIMEOUT_MS,\n });\n return { chunk, verdicts: parseVerdicts(reply, chunk.length) };\n }),\n );\n let answered = false;\n for (const answer of answers) {\n if (answer.status !== 'fulfilled' || answer.value.verdicts.size === 0) continue;\n answered = true;\n const { chunk, verdicts } = answer.value;\n for (const [index, verdict] of verdicts) {\n const row = chunk[index - 1];\n out.set(row.id, verdict);\n remember(cacheKey(search, row), verdict);\n }\n }\n return answered || out.size > 0 ? out : null;\n}\n\n/**\n * `rows` held to the model's verdicts: accessories and other products go, close\n * variants are marked (and rank after the exact matches - see\n * {@link rankByMatch}), rows it gave no verdict on stay as they were.\n */\nexport function applyAiVerdicts(rows: readonly Product[], verdicts: ReadonlyMap<string, AiVerdict> | null): Product[] {\n if (!verdicts || verdicts.size === 0) return [...rows];\n const out: Product[] = [];\n for (const row of rows) {\n const verdict = verdicts.get(row.id);\n if (!verdict) {\n out.push(row);\n } else if (verdict.match === 'exact') {\n out.push({ ...row, match: 'exact', matchNote: undefined });\n } else if (verdict.match === 'close') {\n out.push({ ...row, match: 'close', ...(verdict.note ? { matchNote: verdict.note } : {}) });\n }\n }\n return out;\n}\n\n/** Close variants after everything else, each group in its own order (the grid sections keep theirs). */\nexport function rankByMatch(rows: readonly Product[]): Product[] {\n const close = rows.filter((row) => row.match === 'close');\n return close.length === 0 ? [...rows] : [...rows.filter((row) => row.match !== 'close'), ...close];\n}\n\n/** Test seam: verdicts are module-level and would otherwise leak across cases. */\nexport function clearAiRelevanceCache(): void {\n cache.clear();\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAgCA,MAAM,KAAQ,GAAA,OAAA;AAOd,MAAM,KAAQ,GAAA,EAAA;AAEd,MAAM,UAAa,GAAA,GAAA;AACnB,MAAM,UAAa,GAAA,GAAA;AACnB,MAAM,MAAS,GAAA;AAAA,EAAC,4EAAA;AAAA,EAA8E,sEAAA;AAAA,EAAwE,kHAAA;AAAA,EAAoH,kHAAA;AAAA,EAAoH,iHAAA;AAAA,EAAmH,iHAAA;AAAA,EAAmH,yFAAA;AAAA,EAA2F,8GAAA;AAAA,EAAgH,6GAAA;AAAA,EAA+G,4GAAA;AAAA,EAA8G,0GAAA;AAAA,EAA4G,8GAAA;AAAA,EAAgH,yGAAA;AAAA,EAA2G,qEAAA;AAAA,EAAuE,4GAAA;AAAA,EAA8G,8DAAA;AAAA,EAAgE,CAAA,+GAAA,CAAA;AAAA,EAAoH,0FAAA;AAAA;AAAA;AAAA,EAG5sD;AAA4F,CAAA,CAAE,KAAK,IAAI,CAAA;AAGvG,MAAM,YAA0B,GAAA;AAAA,EAC9B,IAAM,EAAA,UAAA;AAAA,EACN,QAAU,EAAA;AAAA,IACR,IAAM,EAAA,iBAAA;AAAA,IACN,WAAa,EAAA,8DAAA;AAAA,IACb,UAAY,EAAA;AAAA,MACV,IAAM,EAAA,QAAA;AAAA,MACN,UAAY,EAAA;AAAA,QACV,CAAG,EAAA;AAAA,UACD,IAAM,EAAA,OAAA;AAAA,UACN,KAAO,EAAA;AAAA,YACL,IAAM,EAAA;AAAA,WACR;AAAA,UACA,WAAa,EAAA;AAAA;AACf,OACF;AAAA,MACA,QAAA,EAAU,CAAC,GAAG;AAAA;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