PageSourceSearch

https://myechoboard.com/assets/ExploreFeed2-CEIojYjh.js

js myechoboard.com collected 2026-09-24 13:50:00 UTC 113,572 bytes, 2 lines download raw bytes

1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/PageHeader-Dt7JKE_V.js","assets/runtime-preload-CFP917pd.js","assets/vendor-react-C9yDzYQD.js","assets/runtime-utils-GN4cODRt.js","assets/UserMenu-Q9d71qTh.js","assets/vendor-query-DpPswXvj.js","assets/useAuth-Dz3EPsxs.js","assets/useUserSettings-COPNty3J.js","assets/supabase-client-_h80EYw_.js","assets/vendor-supabase-BL1taoPA.js","assets/startup-platform-OWIpYyjW.js","assets/supabase-config-Bge368iX.js","assets/startup-core-CGeUO7uJ.js","assets/startup-diagnostics-bridge-CKNiHJ_f.js","assets/app-BhliLHoU.js","assets/vendor-capacitor-8exTJy5k.js","assets/documentVisibilitySubscriptions-CqVNm4Da.js","assets/nativeAppStateSubscriptions-Cv_2m-ZS.js","assets/perfConfig-DEgIskwG.js","assets/ThemeContext-jMT4gQSB.js","assets/mediaQueryStore-DwN5Dqg0.js","assets/idleStorage-BGANA5qp.js","assets/echoReview-DxeV6pFI.js","assets/appStore-CvVedgBE.js","assets/chromeExtension-Ba1XSCfq.js","assets/use-mobile-D5Xf5BKb.js","assets/navigationPlacement-DOicjMCP.js","assets/image-utils-AdRSPECl.js","assets/dropdown-menu-BEBSGtMc.js","assets/index-CuooO_kK.js","assets/index-BrpnBk_C.js","assets/index-DyIfOVK5.js","assets/index-Bf_lj5FF.js","assets/index-CfYZuMWu.js","assets/Combination-DIDwI44r.js","assets/index-C_zeqDvy.js","assets/index-6bR26fvg.js","assets/index-gOewhWoM.js","assets/check-MQhLD6FV.js","assets/createLucideIcon-DNcTU-zM.js","assets/circle-CkfN9-i9.js","assets/dialog-DHNNRuDw.js","assets/index-BLLe0eFp.js","assets/x-lNdY5pWw.js","assets/feedBatchMonitorVisibility-BVapLDZ4.js","assets/routeModulePrefetch-CXa9VU96.js","assets/vendor-router-X7RJKav4.js","assets/user-DrHqDh0A.js","assets/flame-CC1HVkaC.js","assets/clock-3-SOj_j4bA.js","assets/bell-BfXb5drb.js","assets/star-PkyT3oQ1.js","assets/heart-DTG6gDEx.js","assets/sparkles-COPkKMBj.js","assets/list-filter-CTkrhYiD.js","assets/trash-2-B7zVZuh_.js","assets/palette-C1bQO_bH.js","assets/settings-CwBkSc_i.js","assets/chevron-down-BFi_I8Zn.js","assets/shield-CcxAGV9V.js","assets/activity-DQtDwZfv.js","assets/log-out-EKNp0o3i.js","assets/keyboard-C3NoqUai.js","assets/external-link-n2tXYKjz.js","assets/eye-Dkh28JiF.js","assets/PublicNavbar-B_1O9y3a.js","assets/button-CcIRk75H.js","assets/index-nwDrq1j8.js","assets/AnimatedLogo-BHNlQQ7J.js","assets/passiveScrollSubscriptions-CS-jkkI4.js","assets/users-DC2VReCB.js","assets/ActiveBoardContext-BjVE_FWv.js","assets/likedPrefetch-D99g-XFi.js","assets/exploreRoutePrefetch-DN_a1V5P.js","assets/directExploreWarmup-CQGnUogR.js","assets/popover-BqNd_ntB.js","assets/layout-grid-DgmnG2AD.js","assets/compass-CZ-nBr9j.js","assets/plus-CNl86JwM.js","assets/log-in-Dmz1RtMa.js","assets/SEOHead-DUUd-RUG.js","assets/MemoryFeed-CBvj8dmC.js","assets/exploreExposureOutbox-NybhlhYP.js","assets/exploreSeenStorage-D_DH2XtR.js","assets/exploreContentIdentity-D-Otu-po.js","assets/exploreViewportExposure-p9xfc4T3.js","assets/feedMotion-BhgUIjw7.js","assets/userFilters-Bp32kBo8.js","assets/imageLoadFailurePolicy-DJD2yr3u.js","assets/memory-CJrksfzy.js","assets/exploreFilterSemantics-DQb3RKye.js","assets/memoryBoardContext-vG9PRs0o.js","assets/collectionNavigation-Dty1iP6Q.js","assets/feedMutationCoordinator-BvkdZE4y.js","assets/boundedRequest-B4Q3Iimu.js","assets/feedPageRetention-yNIfWPHZ.js","assets/viewportLoadMoreObserver-CThDFSVJ.js","assets/MemoryCard-DJDOd9Hn.js","assets/useHaptics-BI0pxz1a.js","assets/useOfflineSource-1vy8u9R8.js","assets/offline-C2kw-B3Y.js","assets/useNetworkStatus-pTwuOFZz.js","assets/asyncSemaphore-KO0g8gsf.js","assets/boardViewSettings-CdKftBZg.js","assets/boardCardSize-DMpJ9b3m.js","assets/usePerfBudget-B6X6q34-.js","assets/performanceTier-CE8N6__E.js","assets/VideoPreview-smtYi5cl.js","assets/VideoPosterOnly-CNeQsWm2.js","assets/videoUtils-CgPXwgg1.js","assets/loader-circle-CWK_zhHB.js","assets/video-DibMJbQh.js","assets/memoryDisplayTitle-BcAkzk0a.js","assets/displayText-DVC6GTMU.js","assets/shareUrls-BBmEIcFl.js","assets/echoTypePolicy-DA-PDKiE.js","assets/MoodContext-C8nY2rn-.js","assets/useSubscription-CEwnjYgb.js","assets/music-B4uV8cIM.js","assets/file-text-B2HnMzWj.js","assets/mic-Bff93sKD.js","assets/link-CmL3GRNv.js","assets/image-Bt9rnFUc.js","assets/wifi-off-DgTu9GsA.js","assets/chevron-left-VZH14zeF.js","assets/ellipsis-D4MBwnVX.js","assets/share-2-CXQVLp8U.js","assets/ban-qJhRe8dJ.js","assets/flag-DV5vL-V-.js","assets/bookmark-DJkUOsn5.js","assets/folder-oSdBhNiA.js","assets/MemoryCardSkeleton-Ct5cNSA5.js","assets/memoryNoteEchoPages-D4iGhN4E.js","assets/dailyHearts-Dpst4P7w.js","assets/useAiContentVisibility-C0IxXYx6.js","assets/windowResizeSubscriptions-C3xwW4pN.js","assets/feedSettingsSub
1scriptions-BbSMaSgy.js","assets/searchGateway-ChZYX3l1.js","assets/circle-alert-CTzjEn3-.js"])))=>i.map(i=>d[i]);
2import{_ as e}from"./runtime-preload-CFP917pd.js";import{r,R as t,j as n}from"./vendor-react-C9yDzYQD.js";import{P as o}from"./PullToRefresh-Bdgv1uUx.js";import{a,b as l}from"./exploreFeed2SemanticWarm-lx-dE550.js";import{E as u}from"./ExploreOnboardingDialog-CXkmXWAO.js";import{s as i}from"./documentVisibilitySubscriptions-CqVNm4Da.js";import{s,g as c}from"./nativeAppStateSubscriptions-Cv_2m-ZS.js";import{g as d}from"./exploreContentIdentity-D-Otu-po.js";import{u as m}from"./vendor-query-DpPswXvj.js";import{B as f}from"./button-CcIRk75H.js";import{a as _,u as p}from"./useAuth-Dz3EPsxs.js";import{supabase as h}from"./supabase-client-_h80EYw_.js";import{a as b,S as g}from"./supabase-config-Bge368iX.js";import{f as v}from"./exploreFilterSemantics-DQb3RKye.js";import{p as w,b as y,d as x,g as S,h as M,c as A}from"./feedBatchMonitorDebug-BCAjn03I.js";import{a as C}from"./exploreMatchReason-Cmjn9lSR.js";import{r as E,b as R,a as k}from"./exploreSeenStorage-D_DH2XtR.js";import{a as I}from"./runtime-utils-GN4cODRt.js";import{a as N}from"./lazyWithRetry-DtO62p5Q.js";import{g as j}from"./mediaQueryStore-DwN5Dqg0.js";import{i as P,s as B}from"./searchGateway-ChZYX3l1.js";import{b as $,s as T}from"./idleStorage-BGANA5qp.js";import{i as L,c as D}from"./rpcCapabilityCache-CVP6KxZ_.js";import{a as F}from"./echoTypePolicy-DA-PDKiE.js";import{getDirectExploreWarmupPromise as O}from"./directExploreWarmup-CQGnUogR.js";import{B as q,g as z,b as G,a as J,c as H,e as W}from"./exploreFeed2CacheContract-BQgUzTx1.js";import{s as U}from"./useUserSettings-COPNty3J.js";import{u as Q,a as V,f as Y}from"./vendor-router-X7RJKav4.js";import{S as K}from"./sparkles-COPkKMBj.js";import{R as X}from"./refresh-cw-Bjlnjg0v.js";const Z=new Map,ee=async(e,r)=>{try{const t=await r;return{source:e,rows:Array.isArray(t)?t:[],error:null}}catch(t){return{source:e,rows:[],error:t}}},re=(e,r,t)=>new Promise((n,o)=>{const a=[];let l=!1;const u=()=>{clearTimeout(c),null==t||t.removeEventListener("abort",s)},i=e=>{l||(l=!0,u(),n({useful:e,outcomes:a}))},s=()=>
2{if(l)return;l=!0,u();const e=null==t?void 0:t.reason;o(e instanceof Error?e:new DOMException("Explore first paint cancelled","AbortError"))},c=setTimeout(()=>i(null),Math.max(0,r));(null==t?void 0:t.aborted)?s():(null==t||t.addEventListener("abort",s,{once:!0}),e.forEach(r=>{r.then(r=>{l||(a.push(r),r.rows.length>0?i(r):a.length===e.length&&i(null))})}))}),te=(e,r)=>Boolean(e)&&Boolean(r)&&(null==e?void 0:e.createdAt)===(null==r?void 0:r.createdAt)&&(null==e?void 0:e.id)===(null==r?void 0:r.id),ne=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,oe=e=>{if(!e.createdAt||!Number.isFinite(Date.parse(e.createdAt)))throw new TypeError("Public Explore cursor createdAt must be a valid timestamp.");if(!ne.test(e.id))throw new TypeError("Public Explore cursor id must be a UUID.");return{createdAt:e.createdAt,id:e.id}},ae=e=>{if("string"!=typeof e.next_cursor_created_at||"string"!=typeof e.next_cursor_id)throw new TypeError("Public Explore page is missing its authoritative cursor.");return oe({createdAt:e.next_cursor_created_at,id:e.next_cursor_id})},le=e=>{if(!Array.isArray(e))throw new TypeError("Public Explore keyset RPC must return an array.");if(0===e.length)return{items:[],nextCursor:null,hasMore:!1};const r=e.map(e=>{if(!(e=>"object"==typeof e&&null!==e&&!Array.isArray(e))(e)||"string"!=typeof e.id||!ne.test(e.id))throw new TypeError("Public Explore page contains an invalid Echo row.");if("boolean"!=typeof e.has_more)throw new TypeError("Public Explore page is missing has_more metadata.");return e}),t=ae(r[r.length-1]),n=r[r.length-1].has_more;return r.forEach(e=>{const r=ae(e);if(r.createdAt!==t.createdAt||r.id!==t.id||e.has_more!==n)throw new TypeError("Public Explore page contains inconsistent pagination metadata.")}),{items:r,nextCursor:t,hasMore:n}},ue=(e,r,{getId:t,getContentIdentity:n,shouldReplace:o=()=>!1})=>{const a=new Map,l=new Map;e.forEach((e,r)=>{const o=t(e);o&&!a.has(o)&&a.set(o,r);const u=null==n?void 0:n(e);o&&u&&!l.has(u)&&l.set(u,o)});let u=e,i=0;const s=new Set;return r.forEach(r=>{const c=t(r);if(!c)return;const d=null==n?void 0:n(r),m=d?l.get(d):void 0;if(m&&m!==c)return;const f=a.get(c);if(void 0===f)return u===e&&(u=e.slice()),a.set(c,u.length),u.push(r),d&&l.set(d,c),void(i+=1);const _=u[f];if(_===r||!o(_,r))return;u===e&&(u=e.slice());const p=null==n?void 0:n(_);p&&l.get(p)===c&&l.delete(p),d&&l.set(d,c),u[f]=r,f<e.length&&s.add(c)}),{items:u,insertedCount:i,replacedCount:s.size,changed:u!==e}},ie=(e,r)=>JSON.stringify([e.epoch,e.batchId,e.mode,r]),se=(e,r)=>e.epoch===r.epoch&&e.batchId===r.batchId&&e.mode===r.mode,ce=({mode:e,sourceHasMore:r,nextCursor:t,hasOwnedBufferedPage:n,canTransitionToPublic:o=!1,canRefillQueue:a=!1,queueLowWatermarkPaused:l=!1})=>n?"consume-buffer":"semantic"===e?r&&null!==t?"load-page":o?"transition-to-public":null:"public"===e?r&&null!==t?"load-page":null:r?"load-page":a&&!l?"refill-queue":null,de=e=>"number"==typeof e&&Number.isFinite(e)?e:null,me=(e,r)=>((e,r)=>{if(0===e.length)return{nextCursor:null,source:"exhausted",rawCount:0};const t=de(r)??0,n=e[e.length-1],o=[["next_cursor",de(n.next_cursor)],["feed_position",de(n.feed_position)]];for(const[a,l]of o)if(null!==l&&l>t)return{nextCursor:l,source:a,rawCount:e.length};return{nextCursor:t+e.length,source:"raw_count",rawCount:e.length}})(e,r).nextCursor,fe=N("ExploreFeedPageHeader",()=>e(()=>import("./PageHeader-Dt7JKE_V.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79])),"PageHeader"),_e=N("ExploreFeedPublicNavbar",()=>e(()=>import("./PublicNavbar-B_1O9y3a.js"),__vite__mapDeps([65,2,66,31,67,3,68,15,1,20,24,69,46,70,39])),"PublicNavbar"),pe=N("ExploreFeedSEOHead",()=>e(()=>import("./SEOHead-DUUd-RUG.js").then(e=>e.a),__vite__mapDeps([80,2])),"SEOHead"),he=N("ExploreFeedMemoryFeed",()=>e(()=>import("./MemoryFeed-CBvj8dmC.js").then(e=>e.a),__vite__mapDeps([81,1,2,82,21,18,17,10,16,83,84,85,86,69,87,39,12,3,7,8,9,11,5,13,14,15,88,6,89,90,91,92,93,94,95,96,97,28,29,30,31,32,33,34,35,36,37,38,40,98,99,100,101,102,103,104,27,105,106,20,25,107,108,109,110,111,112,113,114,115,116,117,19,118,119,120,121,122,123,124,64,52,78,125,126,127,55,128,53,129,130,46,131,66,67,132,133,134,135,136,137,138,43])),"MemoryFeed"),be=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,ge=20,ve=20,we=20,ye=1e3,xe=15e3,Se=5200,Me=27e5,Ae=18e5,Ce=9e5,Ee=864e5,Re=5e3,ke=new Map,Ie=new Map,Ne=new Map,je=D(),Pe="get_explore_semantic_runway_page_v2",Be="get_public_explore_echo_feed_keyset_v2",$e=300,Te=(e,r,t)=>"keyset-v2"!==(r||e.publicSource||null)||"keyset-v2"===e.publicSource&&te(e.publicCursor,t),Le=(e,r,t,n,o,a,l,u)=>{if(!r||"number"!=typeof t)return[];const i=e.filter(e=>!(e.batchId!==r||n&&e.mode&&e.mode!==n||"semantic"===n&&o&&e.semanticSource!==o||"semantic"===n&&"runway-v2"===o&&a&&e.semanticGenerationId!==a||"public"===n&&l&&e.publicSource!==l||"number"!=typeof e.cursor||!(Number(e.cursor)>=t))).sort((e,r)=>Number(e.cursor||0)-Number(r.cursor||0)),s=[];let c=t,d=u||null;for(;s.length<8;){const e=i.find(e=>Number(e.cursor)===c&&("public"!==n||Te(e,l,d)));if(!e)break;if("public"===n&&"keyset-v2"===(l||e.publicSource)&&e.hasMore&&!e.nextPublicCursor)break;
2if(s.push(e),"public"===n&&"keyset-v2"===(l||e.publicSource)&&(d=e.nextPublicCursor||null),"number"!=typeof e.nextCursor||e.nextCursor<=c)break;c=e.nextCursor}return s},De=e=>e?e instanceof Error?e.message:String((null==e?void 0:e.message)||e||"Unknown error"):null,Fe=e=>Boolean(e&&/statement timeout|timed out|deadline exceeded|57014/i.test(e)),Oe=async(e,r,t)=>{let n=null;try{return await Promise.race([e,new Promise((e,o)=>{n=setTimeout(()=>o(new Error(`${t} timed out`)),r)})])}finally{n&&clearTimeout(n)}},qe=async(e,r,t,n,o)=>{const a=new AbortController;let l=!1;const u=()=>a.abort(null==o?void 0:o.reason);(null==o?void 0:o.aborted)?u():null==o||o.addEventListener("abort",u,{once:!0});const i=setTimeout(()=>{l=!0,a.abort(new DOMException(`${n} timed out`,"TimeoutError"))},t);try{const t=h.rpc(e,r).abortSignal(a.signal);return await t}catch(s){if(l)throw new Error(`${n} timed out`);throw s}finally{clearTimeout(i),null==o||o.removeEventListener("abort",u)}},ze=e=>`echo:explore-feed-v2:pool-warm:${e||"anon"}`,Ge=e=>`echo:explore-feed-v2:top-tags:${e||"anon"}`,Je=e=>`echo:explore-feed-v2:unavailable-media:${e||"anon"}`,He=e=>`echo:explore-feed-v2:suppressed-boards:${e||"anon"}`,We=()=>{if("undefined"==typeof window)return null;try{if(window.localStorage)return window.localStorage}catch{}try{return window.sessionStorage||null}catch{return null}},Ue={tags:"tag",styles:"style",aesthetics:"aesthetic",moods:"mood",subjects:"subject",objects:"object",materials:"material",compositions:"composition",colors:"color",dominant_colors:"dominant_color",primary_colors:"primary_color",secondary_colors:"secondary_color",palettes:"palette",categories:"category"},Qe=(e,r,t)=>e.filter(e=>{var r;return Boolean(e.id||e.memory_id)||!0===(null==(r=e.metadata)?void 0:r._explore_pagination_meta)}).map((e,n)=>{const o=e.metadata&&"object"==typeof e.metadata&&!Array.isArray(e.metadata)?e.metadata:{};if(!0===o._explore_pagination_meta)return{...e,feed_position:r,next_cursor:"number"==typeof e.next_cursor?e.next_cursor:r,has_more:!1,metadata:{...o,_explore_cursor_source:t}};const a=o._explore_feed_v2&&"object"==typeof o._explore_feed_v2?o._explore_feed_v2:{},l=o._explore_match&&"object"==typeof o._explore_match?o._explore_match:{},u=l.evidence&&"object"==typeof l.evidence?l.evidence:{},i=Array.isArray(u.anchor_samples)?u.anchor_samples:[],s=Number(u.manual_preference_score||0)>0,c=Number(u.matched_anchor_count||0)>0,d=s?"because_explicit_interest":c?"because_semantic_anchor":"because_taste_match",m=s?"Matches My Algorithm":c?"Similar to echoes you engaged with":"Matches your interests",f=Number(e.feed_position??a.position??e.next_cursor),_="runway-v2"===t&&Number.isFinite(f)&&f>0?f:r+n+1;return{...e,source_board_id:e.source_board_id||e.board_id||null,source_board_name:e.source_board_name||e.board_name||null,source_board_owner_id:e.source_board_owner_id||e.added_by||e.curator_id||null,source_board_owner:e.source_board_owner||e.added_by_username||e.curator_username||null,source_board_owner_full_name:e.source_board_owner_full_name||e.added_by_full_name||e.curator_full_name||null,source_board_owner_avatar:e.source_board_owner_avatar||e.added_by_avatar||e.curator_avatar||null,feed_position:_,next_cursor:"runway-v2"!==t&&"live"!==t||"number"!=typeof e.next_cursor?_:e.next_cursor,has_more:"boolean"==typeof e.has_more?e.has_more:null,bucket:"semantic_anchor",metadata:{...o,_explore_retrieval_source:"semantic_anchor",_explore_cursor_source:t,_explore_match:{...l,label:m,evidence:{...u,reason_code:d,reason_label:m,algorithm_seed_ids:i.map(e=>null==e?void 0:e.anchor_id).filter(e=>"string"==typeof e&&e.length>0),algorithm_seed_weights:i.map(e=>Number((null==e?void 0:e.similarity)||0)).filter(e=>Number.isFinite(e)&&e>0)}},_explore_feed_v2:{...a,batch_id:a.batch_id||"semantic-anchor",position:_,bucket:"semantic_anchor",card_data_source:"semantic_anchor",reason_code:d,reason_label:m}}}}),Ve=(e,r)=>{const t=e[e.length-1];return"boolean"==typeof(null==t?void 0:t.has_more)?t.has_more:e.length>=Math.max(1,r)},Ye=e=>{for(const r of e){const e=r.metadata&&"object"==typeof r.metadata?r.metadata:null,t=null==e?void 0:e._explore_cursor_source;if("typesense"===t||"runway-v2"===t||"runway-legacy"===t||"live"===t)return t;if("typesense_algorithm"===(null==e?void 0:e._explore_retrieval_source)||"typesense_algorithm"===r.bucket)return"typesense"}return null},Ke=e=>Ye(e.map(e=>({metadata:e.metadata}))),Xe=e=>{var r;return(null==(r=e.find(e=>"string"==typeof e.generation_id))?void 0:r.generation_id)||null},Ze=(e,r,t)=>e.filter(e=>Boolean(e.id||e.memory_id)).map((n,o)=>{const a=n.metadata&&"object"==typeof n.metadata&&!Array.isArray(n.metadata)?n.metadata:{},l=t+o+1,u=a._explore_feed_v2&&"object"==typeof a._explore_feed_v2?a._explore_feed_v2:{},i=a._explore_match&&"object"==typeof a._explore_match?a._explore_match:{},s=i.evidence&&"object"==typeof i.evidence?i.evidence:{},c=Array.isArray(i.source_reasons)?i.source_reasons.map(e=>String(e)):[],d="public-cold-start"===r;return{...n,source_board_id:n.source_board_id||n.board_id||null,source_board_name:n.source_board_name||n.board_name||null,source_board_owner_id:n.source_board_owner_id||n.added_by||n.curator_id||null,source_board_owner:n.source_board_owner||n.added_by_username||n.curator_username||null,source_board_owner_full_name:n.source_board_owner_full_name||n.added_by_full_name||n.curator_full_name||null,source_board_owner_avatar:n.source_board_owner_avatar||n.added_by_avatar||n.curator_avatar||null,feed_position:l,next_cursor:l,has_more:"boolean"==typeof n.has_more?n.has_more:e.length>0,bucket:d?"public_cold_start":"first_paint_fallback",metadata:{...a,_explore_retrieval_source:r,_explore_match:{...i,candidate_source:d?"public_cold_start":"algorithm",source_reasons:Array.from(new Set([...d?["public_cold_start"]:["algorithm","first_paint_fallback"],r,...c])),evidence:{...s,personalized_pool:!d&&r.includes("for-you"),fallback_first_paint:!d,feed_rank:n.feed_rank||s.feed_rank||null}},_explore_feed_v2:{...u,batch_id:d?"public-cold-start":"first-paint-fallback",position:l,bucket:
2d?"public_cold_start":"first_paint_fallback",card_data_source:d?"public_cold_start":"fallback_join",reason_code:d?"public_cold_start":"because_first_paint_fallback",reason_label:d?"Newest on Explore":r.includes("for-you")?"Picked for you":"Popular on Explore"}}}}),er=(e,r,t)=>Ze(e,"public-cold-start",t).map(e=>({...e,metadata:{...e.metadata||{},_explore_public_cursor_source:r}})),rr=async(e,r,t,n={})=>async function({initialCursor:e,read:r,isFresh:t,next:n,signal:o,maxPages:a=4}){let l=e,u=[];const i=new Set;for(let s=0;s<a;s+=1){null==o||o.throwIfAborted();const e=JSON.stringify(l);if(i.has(e))break;if(i.add(e),u=await r(l),null==o||o.throwIfAborted(),0===u.length||t(u))return u;const a=n(u,l);if(null===a)break;l=a}return u}({initialCursor:{offset:e,options:n},signal:n.signal,read:e=>(async(e,r,t,n={})=>{var o,a,l;const u=()=>{var e;if(null==(e=n.signal)?void 0:e.aborted)throw n.signal.reason instanceof Error?n.signal.reason:new DOMException("Explore public feed cancelled","AbortError")};if(u(),"legacy-offset"!==n.preferredSource)if(je.shouldProbe(Be))try{const t=await qe(Be,((e,r=null)=>{const t=Number.isFinite(e)?Math.max(1,Math.min(80,Math.trunc(e))):20,n=r?oe(r):null;return{p_limit:t,p_after_created_at:(null==n?void 0:n.createdAt)??null,p_after_id:(null==n?void 0:n.id)??null}})(r,n.cursor||null),Se,"Explore public keyset page",n.signal);if(!t.error){je.markAvailable(Be);const r=le(t.data||[]);if(r.items.length>
20||"keyset-v2"===n.preferredSource)return er(r.items,"keyset-v2",e)}if(L(t.error,Be)){if(je.markMissing(Be),"keyset-v2"===n.preferredSource)throw t.error}else if("keyset-v2"===n.preferredSource)throw t.error}catch(f){if("keyset-v2"===n.preferredSource)throw f}else if("keyset-v2"===n.preferredSource)throw new Error("The pinned public Explore keyset source is temporarily unavailable.");const i=new AbortController;let s=!1;const c=()=>{var e;return i.abort(null==(e=n.signal)?void 0:e.reason)};(null==(o=n.signal)?void 0:o.aborted)?c():null==(a=n.signal)||a.addEventListener("abort",c,{once:!0});const d=window.setTimeout(()=>{s=!0,i.abort()},Se);let m;try{const t=await fetch(`${b}/rest/v1/rpc/get_public_explore_echo_feed_new_fast`,{method:"POST",headers:{apikey:g,Authorization:`Bearer ${g}`,"Content-Type":"application/json"},body:JSON.stringify({limit_count:r,p_offset:Math.max(0,e),p_after_created_at:null,p_after_id:null,p_time_range:"all_time",p_query:null,p_ai_filters:{},p_type_filter:null}),signal:i.signal});if(!t.ok)throw new Error(`Explore public cold start failed: ${t.status}`);m=await t.json()}catch(f){if(s)throw new Error("Explore public cold start timed out");throw u(),f}finally{window.clearTimeout(d),null==(l=n.signal)||l.removeEventListener("abort",c)}return er(Array.isArray(m)?m:[],"legacy-offset",e)})(e.offset,r,0,e.options),isFresh:e=>gr(e,t,Cr(t)).length>0,next:(e,t)=>{var o;const a=tr(e),l=me(e,t.offset),u=or(e);return!("keyset-v2"===a?Boolean(null==(o=e.at(-1))?void 0:o.has_more)&&Boolean(u):e.length>=r)||null===l||l<=t.offset?null:{offset:l,options:{...n,preferredSource:a,cursor:u}}}}),tr=e=>{for(const r of e){const e=r.metadata&&"object"==typeof r.metadata?r.metadata._explore_public_cursor_source:null;if("keyset-v2"===e||"legacy-offset"===e)return e}return null},nr=e=>tr(e.map(e=>({metadata:e.metadata}))),or=e=>{if("keyset-v2"!==tr(e)||0===e.length)return null;try{return le(e).nextCursor}catch{return null}},ar=e=>{var r;const t=e.metadata&&"object"==typeof e.metadata&&!Array.isArray(e.metadata)?e.metadata:{},n=e.source_board_id||e.board_id||null,o=e.source_board_name||e.board_name||null,a=e.source_board_owner_id||e.added_by||e.curator_id||null,l=e.source_board_owner||e.added_by_username||e.curator_username||null,u=e.source_board_owner_full_name||e.added_by_full_name||e.curator_full_name||null,i=e.source_board_owner_avatar||e.added_by_avatar||e.curator_avatar||null,s="semantic_anchor"===String((null==t?void 0:t._explore_retrieval_source)||"")||"semantic_anchor"===String((null==(r=null==t?void 0:t._explore_match)?void 0:r.candidate_source)||""),c=Number(e.feed_position||e.feed_rank||0),d=(null==t?void 0:t._explore_feed_v2)&&"object"==typeof t._explore_feed_v2?t._explore_feed_v2:s?{batch_id:"semantic-anchor",position:Number.isFinite(c)&&c>0?c:0,bucket:"semantic_anchor",card_data_source:"semantic_anchor",reason_code:"because_semantic_anchor",reason_label:"Similar to your echoes"}:null;return{id:String(e.id||e.memory_id),type:e.type||"image",title:e.title||null,ai_title:e.ai_title||null,content:e.content||"",description:e.description||null,html_content:e.html_content||null,image_url:e.image_url||null,video_url:e.video_url||null,audio_url:e.audio_url||null,source_url:e.source_url||null,ai_description:e.ai_description||null,metadata:{...t,...d?{_explore_feed_v2:d}:{}},hearts:Number(e.hearts||0),watch_count:Number(e.watch_count||0),created_at:e.created_at||(new Date).toISOString(),deleted_at:e.deleted_at||null,source_board_id:n,source_board_name:o,source_board_owner_id:a,source_board_owner:l,source_board_owner_full_name:u,source_board_owner_avatar:i,added_by:e.added_by||null,added_by_id:e.added_by||null,added_by_username:e.added_by_username||e.curator_username||null,added_by_full_name:e.added_by_full_name||e.curator_full_name||null,added_by_avatar:e.added_by_avatar||e.curator_avatar||e.owner_avatar||null,owner_username:l,owner_full_name:u,owner_avatar:i,feed_rank:e.feed_rank||String(e.feed_position||"")}},lr=(e,r)=>{const t=e.metadata&&"object"==typeof e.metadata&&!Array.isArray(e.metadata)?e.metadata:{},n=r+1;return{id:e.id,memory_id:e.id,type:e.type,title:e.title,ai_title:e.ai_title,content:e.content,description:e.description,html_content:e.html_content,image_url:e.image_url,video_url:e.video_url,audio_url:e.audio_url,source_url:e.source_url,ai_description:e.ai_description,metadata:t,hearts:e.hearts,watch_count:e.watch_count,created_at:e.created_at,deleted_at:e.deleted_at,source_board_id:e.source_board_id,source_board_name:e.source_board_name,source_board_owner:e.source_board_owner,source_board_owner_id:e.source_board_owner_id,source_board_owner_full_name:e.source_board_owner_full_name,source_board_owner_avatar:e.source_board_owner_avatar,added_by:e.added_by,added_by_username:e.added_by_username,added_by_full_name:e.added_by_full_name,added_by_avatar:e.added_by_avatar,feed_position:n,next_cursor:n,has_more:!0,bucket:"semantic_anchor"}},ur=e=>{var r,t;return F(e)&&Boolean(null==(t=null==(r=e.metadata)?void 0:r._explore_feed_v2)?void 0:t.batch_id)},ir=e=>{var r,t;return String((null==(t=null==(r=e.metadata)?void 0:r._explore_feed_v2)?void 0:t.card_data_source)||"unknown")},sr=e=>{const r=ir(e);return"queue"===r||"fallback_join"===r||"public_cold_start"===r},cr=e=>"semantic_anchor"===ir(e)&&(e=>{var r,t;const n=null==(t=null==(r=e.metadata)?void 0:r._explore_match)?void 0:t.evidence;if(!n||"object"!=typeof n)return!1;const o=Number(n.best_similarity||0),a=Number(n.matched_anchor_count||0),l=Number(n.semantic_tier??1),u=Array.isArray(n.anchor_samples)?n.anchor_samples:[];return 0===l&&Number.isFinite(o)&&o>0&&Number.isFinite(a)&&a>0&&u.some(e=>Number((null==e?void 0:e.similarity)||0)>0)})(e),dr=e=>e.filter(cr),mr=(e,r)=>r?dr(e):e,fr=e=>(e=>C(e).length>0)(e)||sr(e)||cr(e),_r=(e,r)=>{if(!e)return!0;const t=ir(e),n=ir(r);return"semantic_anchor"===n&&"semantic_anchor"!==t||"queue"===n&&"queue"!==t||"typesense_algorithm"===n&&"typesense_algorithm"!==t&&"semantic_anchor"!==t&&"queue"!==t||"fallback_join"===n&&"client_tag_lane"===t},pr=(e,r)=>{if(!r)return!1;const t=e;return t.user_id===r||t.added_by_id===r||t.source_board_owner_id===r},hr=(e,r,t=E(r),n=Br(r))=>{const o=new Map,a=new Map,l=new Set,u=k(r);return e.filter(e=>{const i=d(e);if(i&&(u.has(i)||l.has(i)))return!1;const s=e.source_board_id||null,c=e.source_board_owner_id||e.source_board_owner||e.owner_username||e.added_by_username||null;if(!ur(e)||!fr(e)||pr(e,r)||t.has(e.id)||s&&n.has(s))return!1;if(s){const e=o.get(s)||0;if(e>=2)return!1;o.set(s,e+1)}if(c){const e=a.get(c)||0;if(e>=6)return!1;a.set(c,e+1)}return i&&l.add(i),!0})},br=(e,r,t=E(r),n=Br(r))=>e.reduce((e,o)=>(ur(o)||(e.missingRenderable+=1),fr(o)||(e.missingMatch+=1),pr(o,r)&&(e.own+=1),t.has(o.id)&&(e.seen+=1),o.source_board_id&&n.has(o.source_board_id)&&(e.suppressedBoard+=1),e.sampleIds.length<8&&e.sampleIds.push(o.id),e),{missingRenderable:0,missingMatch:0,own:0,seen:0,suppressedBoard:0,sampleIds:[]}),gr=(e,r,t=E(r),n=Br(r))=>hr(e.map(ar),r,t,n),vr=(e,r)=>{const t=e[e.length-1];return t?"number"==typeof t.next_cursor?t.next_cursor:t.feed_position??r:r},wr=(e,r,t=!1)=>{const n=Br(r),o=new Map,a=new Map,l=t?new Set:E(r),u=t?new Set:k(r);return e.filter(e=>{const t=d(e);if(l.has(e.id)||t&&u.has(t))return!1;const i=e.source_board_id||null,s=e.source_board_owner_id||e.source_board_owner||e.owner_username||e.added_by_username||null,c=ir
2(e);if(!ur(e)||!fr(e)||pr(e,r)||i&&n.has(i)||!sr(e)&&!cr(e)&&"fallback_join"!==c)return!1;if(i){const e=o.get(i)||0;if(e>=2)return!1;o.set(i,e+1)}if(s){const e=a.get(s)||0;if(e>=6)return!1;a.set(s,e+1)}return!0})},yr=(e,r,t="")=>{if(e.length<=1)return e;const n=We();if(!n)return e;try{const o=`${(e=>`echo:explore-feed-v2:first-paint-rotation:${e||"anon"}`)(r)}:${t||"default"}`,a=Number(n.getItem(o)||0);n.setItem(o,String((a+1)%1e5));const l=a*Math.max(1,Math.floor(e.length/5))%e.length,u=0===l?e:[...e.slice(l),...e.slice(0,l)],i=`${(e=>`echo:explore-feed-v2:first-paint-signature:${e||"anon"}`)(r)}:${t||"default"}`,s=n.getItem(i)||"";let c=u;for(let r=0;r<e.length;r+=1){const e=c.slice(0,12).map(e=>e.id).join("|");if(e&&e!==s)return n.setItem(i,e),c;c=[...c.slice(1),c[0]]}return n.setItem(i,c.slice(0,12).map(e=>e.id).join("|")),c}catch{return e}},xr=e=>{const r=We();if(!r)return[];try{const t=r.getItem(z(e));if(!t)return[];const n=JSON.parse(t);return!(null==n?void 0:n.savedAt)||Date.now()-n.savedAt>Me?[]:yr(Array.isArray(n.memories)?n.memories:[],e,"last-good").slice(0,ge)}catch{return[]}},Sr=e=>{const r=W(e),t=Date.now(),n=ke.get(r);if(n&&n.expiresAt>t)return new Set(n.ids);n&&ke.delete(r);const o=We(),a=(()=>{if("undefined"==typeof document)return null;try{const e=`${r}=`,n=document.cookie.split("; ").find(r=>r.startsWith(e));if(!n)return null;const o=JSON.parse(decodeURIComponent(n.slice(e.length)));return!(null==o?void 0:o.savedAt)||t-o.savedAt>Ce?null:{savedAt:o.savedAt,ids:Array.isArray(o.ids)?o.ids.filter(Boolean):[]}}catch{return null}})(),l=(null==a?void 0:a.ids)||[];if(!o)return ke.set(r,{expiresAt:a?a.savedAt+Ce:t+Re,ids:l}),new Set(l);try{const e=o.getItem(r);if(!e)return ke.set(r,{expiresAt:a?a.savedAt+Ce:t+Re,ids:l}),new Set(l);const n=JSON.parse(e),u=Boolean((null==n?void 0:n.savedAt)&&t-n.savedAt<=Ce),i=Array.from(new Set([...l,...(u&&Array.isArray(n.ids)?n.ids:[]).filter(Boolean)])),s=Math.max((null==a?void 0:a.savedAt)||
20,u?Number(n.savedAt):0);return ke.set(r,{expiresAt:s?s+Ce:t+Re,ids:i}),new Set(i)}catch{return ke.set(r,{expiresAt:a?a.savedAt+Ce:t+Re,ids:l}),new Set(l)}},Mr=(e,r)=>{const t=We();if(!e||0===r.length)return;const n="undefined"!=typeof window&&j("(max-width: 768px)")?2:4;try{const o=r.map(e=>e.id).filter(Boolean).slice(0,n),a=Array.from(Sr(e)),l={savedAt:Date.now(),ids:Array.from(new Set([...o,...a])).slice(0,240)},u=W(e);ke.set(u,{expiresAt:l.savedAt+Ce,ids:l.ids}),t===window.localStorage?T(u,l):null==t||t.setItem(u,JSON.stringify(l))}catch{}},Ar=e=>{const r=Je(e),t=Date.now(),n=Ie.get(r);if(n&&n.expiresAt>t)return new Set(n.ids);n&&Ie.delete(r);const o=We();if(!o)return Ie.set(r,{expiresAt:t+Re,ids:[]}),new Set;try{const e=o.getItem(r);if(!e)return Ie.set(r,{expiresAt:t+Re,ids:[]}),new Set;const n=JSON.parse(e);if(!(null==n?void 0:n.savedAt)||t-n.savedAt>Ee)return Ie.set(r,{expiresAt:t+Re,ids:[]}),new Set;const a=Array.isArray(n.ids)?n.ids.filter(Boolean):[];return Ie.set(r,{expiresAt:n.savedAt+Ee,ids:a}),new Set(a)}catch{return Ie.set(r,{expiresAt:t+Re,ids:[]}),new Set}},Cr=e=>new Set([...Array.from(E(e)),...Array.from(Sr(e)),...Array.from(Ar(e))]),Er=e=>new Set([...Array.from(Ar(e))]),Rr=e=>new Set([...Array.from(E(e)),...Array.from(Sr(e)),...Array.from(Ar(e))]),kr=(e,r,t)=>{const n="public"===t?Cr(r):Rr(r);return gr(e,r,n).length>=("semantic"===t?4:1)?e:[]},Ir=(e,r=[],t={})=>Array.from(new Set([...r.map(e=>e.id),...t.includeSeenHistory?Array.from(Rr(e)):Array.from(Ar(e))])).filter(e=>"string"==typeof e&&/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(e)).slice(0,120),Nr=(e,r,t)=>e.map((e,n)=>{const o=lr(e,r+n),a=e.metadata&&"object"==typeof e.metadata&&!Array.isArray(e.metadata)?e.metadata:{},l=a._explore_match&&"object"==typeof a._explore_match?a._explore_match:{},u=l.evidence&&"object"==typeof l.evidence?l.evidence:{};return{...o,bucket:"typesense_algorithm",metadata:{...a,_explore_retrieval_source:"typesense_algorithm",_explore_cursor_source:"typesense",_explore_match:{...l,candidate_source:"algorithm",source_reasons:["algorithm","typesense_candidate_retrieval"],evidence:{...u,personalized_pool:!0,typesense_candidate_retrieval:!0,algorithm_seed_ids:t.map(e=>e.id),algorithm_seed_weights:t.map(e=>e.weight)}},_explore_feed_v2:{batch_id:"typesense-algorithm",position:r+n+1,bucket:"typesense_algorithm",card_data_source:"typesense_algorithm",reason_code:"because_my_algorithm",reason_label:"Picked for you"}}}}),jr=async({offset:e,limit:r,userId:t,viewerIsInternal:n,timeoutMs:o,signal:a})=>{if(!t||!P(n))return[];(()=>{const e=Date.now();for(Ne.forEach((r,t)=>{r.expiresAt<=e&&Ne.delete(t)});Ne.size>80;){const e=Ne.keys().next().value;if(void 0===e)break;Ne.delete(e)}})();const l=`my-algorithm:${t}`,u=Math.max(0,e),i=Math.floor(u/60),s=u%60;let c,d=null;for(let f=0;f<=i;f+=1){const t=`${l}:${f}`,u=Ne.get(t);if(u&&u.expiresAt>Date.now())d=u;else{const l=await B({resource:"echoes",mode:"public",myAlgorithm:!0,cursor:c,limit:60},{viewerIsInternal:n,timeoutMs:Math.min(o,12e3),signal:a}),u=(l.meta.algorithmSeedIds||[]).map((e,r)=>{var t;return{id:e,weight:Number((null==(t=l.meta.algorithmSeedWeights)?void 0:t[r])||1)}});if(d={expiresAt:Date.now()+3e5,hits:l.hits,nextCursor:l.nextCursor,algorithmSeeds:u},Ne.set(t,d),f===i){const t=d.hits.slice(s,s+r);return Nr(t,e,u)}}if(f<i){if(!d.nextCursor)return[];c=d.nextCursor}}if(!d)return[];const m=d.hits.slice(s,s+r);return Nr(m,e,d.algorithmSeeds)},Pr=async({offset:e,limit:r,userId:t,currentMemories:n=[],includeSeenHistory:o=!1,ignoreExcludes:a=!1,viewerIsInternal:u=!1,allowNonParityTypesenseFallback:i=!1,preferredSource:s=null,generationId:c=null,allowRunwayRefresh:d=!0,timeoutMs:m,signal:f,label:_})=>{const p=Date.now()+Math.max(1,m),h=()=>{if(!(null==f?void 0:f.aborted))return;const e=f.reason;throw e instanceof Error?e:new DOMException("Explore personalization cancelled","AbortError")},b=()=>{h();const e=p-Date.now();if(e<=0)throw new Error(`${_} timed out`);return e};if(h(),"typesense"===s)try{return await jr({offset:e,limit:r,userId:t,viewerIsInternal:u,timeoutMs:b(),signal:f})}catch(v){if(h(),"typesense"===s)throw v}h();const g=()=>
2Math.min(720,Math.max(240,e+r+240));if(!(a||s&&"runway-v2"!==s&&"runway-legacy"!==s)){const t=async()=>{if(h(),"runway-legacy"!==s&&je.shouldProbe(Pe)){const t=await qe(Pe,{p_limit:r,p_after_position:Math.max(0,e),p_generation_id:c},Math.min(b(),5e3),`${_} keyset runway`,f);if(h(),!t.error){je.markAvailable(Pe);let n=Array.isArray(t.data)?t.data:[];if(0===n.length&&c){const t=await qe("get_explore_semantic_runway_generation_v2",{p_generation_id:c},Math.min(b(),5e3),`${_} generation probe`,f);if(h(),t.error)throw t.error;const o=Array.isArray(t.data)?t.data[0]:null;if((null==o?void 0:o.reset_required)&&o.generation_id){const e=await qe(Pe,{p_limit:r,p_after_position:0,p_generation_id:o.generation_id},Math.min(b(),5e3),`${_} reset generation page`,f);if(h(),e.error)throw e.error;n=(Array.isArray(e.data)?e.data:[]).map((e,r)=>0===r?{...e,reset_required:!0}:e)}else o&&(n=[{next_cursor:Math.max(0,e),has_more:!1,generation_id:o.generation_id||null,reset_required:!0===o.reset_required,metadata:{_explore_pagination_meta:!0,_explore_cursor_source:"runway-v2"}}])}return{rows:n,source:"runway-v2"}}if(!L(t.error,Pe))throw t.error;if(je.markMissing(Pe),"runway-v2"===s)throw t.error}if("runway-v2"===s)throw new Error("The pinned semantic runway source is temporarily unavailable.");const t=await qe("get_explore_semantic_runway_page",{p_limit:r,p_offset:e},Math.min(b(),5e3),`${_} runway`,f);if(h(),t.error)throw t.error;return{rows:Array.isArray(t.data)?t.data:[],source:"runway-legacy"}};try{const n=await t();h();const o=n.rows;if(o.length>0){if(!Ve(o,r)&&d){const n=await qe("refresh_explore_semantic_runway",{p_target:g(),p_force:!1},b(),`${_} terminal runway top-up`,f);if(h(),!n.error){const n=await t();if(n.rows.length>o.length||Ve(n.rows,r))return Qe(n.rows,e,n.source).slice(0,r)}}else e+r+80>=240&&qe("refresh_explore_semantic_runway",{p_target:g(),p_force:!1},b(),`${_} background runway top-up`,f).catch(e=>{});return Qe(o,e,n.source).slice(0,r)}if(d){await qe("refresh_explore_semantic_runway",{p_target:g(),p_force:!1},b(),`${_} runway refresh`,f),h();const n=await t();if(n.rows.length>0)return Qe(n.rows,e,n.source).slice(0,r)}if("runway-v2"===s||"runway-legacy"===s)return[]}catch(w){if(h(),"runway-v2"===s||"runway-legacy"===s)throw w}}if(!s&&i)try{const n=await jr({offset:e,limit:r,userId:t,viewerIsInternal:u,timeoutMs:b(),signal:f});if(n.length>0)return n}catch(v){h()}if(s&&"live"!==s)return[];h();try{const u="live"===s?e:0,i=await l(u,async e=>{h();const l=await qe("get_explore_semantic_anchor_feed_candidates_fast",{p_limit:Math.min(r,40),p_offset:e,p_exclude_memory_ids:a?[]:Ir(t,n,{includeSeenHistory:o})},b(),`${_} fast`,f);if(h(),l.error)throw l.error;return Array.isArray(l.data)?l.data:[]});return Qe(i.rows.map(e=>({...e,next_cursor:i.nextCursor,has_more:i.hasMore})),e,"live").slice(0,r)}catch(v){throw h(),v}},Br=e=>{const r=We();if(!r)return new Set;try{const t=r.getItem(He(e));if(!t)return new Set;const n=JSON.parse(t);return new Set(Array.isArray(n.boardIds)?n.boardIds.filter(Boolean):[])}catch{return new Set}},$r=(e,r)=>{const t=We();if(t&&e)try{t.setItem(He(e),JSON.stringify({savedAt:Date.now(),boardIds:Array.from(r).filter(Boolean)}))}catch{}},Tr=(e,r,t=null,n=null)=>{const o=We();if(o&&e&&Number.isFinite(r)&&!(r<=0))try{o.setItem(H(e),JSON.stringify({savedAt:Date.now(),cursor:Math.max(0,Math.floor(r)),semanticSource:t,semanticGenerationId:"runway-v2"===t?n:null}))}catch{}},Lr=e=>{const r=We();if(!r)return[];try{const t=r.getItem((e=>`echo:explore-feed-v2:manual-tag-preferences:${e||"anon"}`)(e));if(!t)return[];const n=JSON.parse(t);if(!n||"object"!=typeof n||Array.isArray(n))return[];const o=n;return Array.isArray(o.tags)?o.tags.map((e,r)=>{const t=v(String(e||""));return t?{value:t,rank:r+1,weight:Math.max(1,$e-r)}:null}).filter(e=>Boolean(e)).slice(0,$e):[]}catch{return[]}},Dr=(e,r)=>{const t=We();if(!t||!r)return[];try{const n=t.getItem(G(e));if(!n)return[];const o=JSON.parse(n);if(!Array.isArray(o))return[];const a=Date.now(),l=Cr(e);return o.filter(e=>e&&"object"==typeof e&&e.batchId===r&&Array.isArray(e.memories)&&a-Number(e.savedAt||0)<Ae).map(t=>({...t,mode:t.mode||(Jr(r)?t.memories.some(e=>"public_cold_start"===ir(e))?"public":"semantic":"queue"),semanticSource:t.semanticSource||Ke(t.memories),publicSource:t.publicSource||nr(t.memories),memories:hr(t.memories,e,l)})).filter(e=>"semantic"!==e.mode||Boolean(e.semanticSource)).filter(e=>"runway-v2"!==e.semanticSource||Boolean(e.semanticGenerationId)).filter(e=>"public"!==e.mode||Boolean(e.publicSource)).filter(e=>"keyset-v2"!==e.publicSource||Boolean(e.publicCursor)&&Boolean(e.nextPublicCursor)).filter(e=>e.memories.length>0).slice(0,6)}catch{return[]}},Fr=e=>{const r=We();if(!r)return[];try{const t=r.getItem(G(e));if(!t)return[];const n=JSON.parse(t);if(!Array.isArray(n))return[];const o=Date.now(),a=new Map;return n.filter(e=>e&&"object"==typeof e&&Array.isArray(e.memories)&&o-Number(e.savedAt||0)<Ae).sort((e,r)=>Number(e.cursor||0)-Number(r.cursor||0)).flatMap(r=>
2wr(r.memories,e)).forEach(e=>{a.has(e.id)||a.set(e.id,e)}),Array.from(a.values()).slice(0,ge)}catch{return[]}},Or=e=>{var r;const t=Wr(e),n=Dr(e,t);if(0===n.length)return null;const[o]=n.sort((e,r)=>Number(e.cursor||0)-Number(r.cursor||0)),a=o.memories.slice(0,ge);if(0===a.length)return null;const l=o.mode||(o.memories.some(e=>"public_cold_start"===ir(e))?"public":"semantic"),u="semantic"===l?o.semanticSource||Ke(o.memories):null;if("semantic"===l&&!u)return null;const i="runway-v2"===u&&o.semanticGenerationId||null;if("runway-v2"===u&&!i)return null;const s="public"===l?o.publicSource||nr(o.memories):null,c="public"===l&&o.nextPublicCursor||null;if("public"===l&&!s)return null;if("keyset-v2"===s&&!c)return null;const d="number"==typeof o.nextCursor?Le(n.filter(e=>e!==o),t,o.nextCursor,l,u,i,s,c).slice(0,6):[],m=null==(r=d.find(e=>"number"==typeof e.cursor))?void 0:r.cursor;return{userId:e||null,memories:a.slice(0,ge),source:"buffered",mode:l,semanticSource:u,semanticGenerationId:i,publicSource:s,publicCursor:c,nextCursor:"number"==typeof m?m:o.nextCursor,hasMore:o.hasMore,remainingBufferedPages:d.slice(0,6)}},qr=(e,r)=>e.filter(e=>e.batchId===r).flatMap(e=>e.memories),zr=e=>{const r=Or(e);if(null==r?void 0:r.memories.length)return r.memories;const t=(e=>{const r=We();if(!r)return[];const t=J(e);try{const n=r.getItem(t);if(!n)return[];const o=JSON.parse(n);return!(null==o?void 0:o.savedAt)||Date.now()-o.savedAt>Ae?[]:yr(wr(Array.isArray(o.memories)?o.memories:[],e),e,"prepared").slice(0,ge)}catch{return[]}})(e);if(t.length>0)return t.slice(0,ge);const n=wr(xr(e),e);return n.length>0?n.slice(0,ge):Fr(e).slice(0,ge)},Gr=(e,r)=>{const t=We();if(t&&e)try{if(0===r.length)return void(t===window.localStorage?$(G(e)):t.removeItem(G(e)));const n=r.filter(e=>e.memories.length>0).slice(0,6);t===window.localStorage?T(G(e),n):t.setItem(G(e),JSON.stringify(n))}catch{}},Jr=e=>Boolean(e&&e.startsWith("semantic-anchor")),Hr=(e,r)=>Jr(e)?r?"public":"semantic":"queue",Wr=e=>`semantic-anchor-${e||"anon"}`,Ur=e=>{var r;const t=null==(r=e.metadata)?void 0:r._explore_match,n=(null==t?void 0:t.evidence)&&"object"==typeof t.evidence?t.evidence:{};return("string"==typeof n.reason_label?n.reason_label:"string"==typeof(null==t?void 0:t.label)?t.label:"")||"For You"},Qr=e=>"string"==typeof e&&/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(e),Vr=e=>{var r,t;const n=null==(t=null==(r=e.metadata)?void 0:r._explore_match)?void 0:t.evidence,o=n&&"object"==typeof n?n.reason_code:null;return"string"==typeof o&&o.trim()?o:"unknown"},Yr=()=>{const[e,t]=r.useState(!1);return r.useEffect(()=>{const e=window.setTimeout(()=>t(!0),160);return()=>window.clearTimeout(e)},[]),n.jsxs("div",{className:"mx-auto max-w-[1600px] px-4 pb-16 md:px-6",role:"status","aria-label":"Loading Explore feed","aria-busy":"true",children:[n.jsx("span",{className:"sr-only",children:"Loading Explore feed"}),n.jsx("div",{className:I("grid grid-cols-2 gap-3 transition-opacity duration-300 motion-reduce:transition-none sm:grid-cols-3 md:gap-4 lg:grid-cols-4",e?"opacity-100":"opacity-0"),"aria-hidden":"true",children:[360,260,420,300,460,340,280,390,320,440,300,360].map((e,r)=>n.jsx("div",{className:"break-inside-avoid bg-muted/20",style:{height:e+86,borderRadius:"var(--card-radius, 1.5rem)"}},r))})]})},Kr=Object.freeze({}),Xr=Object.freeze([]),Zr=new Set,et=Object.freeze({consumedPosition:0,preparedCount:0,queueRemaining:0,readyAheadCount:0,nextBatchStatus:"not loaded",queueBackedRendered:0,queueCardCount:0,fallbackJoinCount:0,semanticAnchorCount:0,bufferedReadyCount:0,bufferedPageCount:0,bufferedPageCursors:[],cacheRestoredCount:0,firstPaintCacheReadyCount:0,duplicateCount:0,invalidCount:0,localSeenRenderedCount:0,hiddenTotalCount:0,skippedLastFetchCount:0,lastRowsReturned:0,lastRowsAccepted:0,lastRowsDropped:0,batchMs:null,pageMs:null,refillMs:null});function rt({embedded:e=!1,requireAdmin:l=!0,showLabHeader:b=!0,freshBatchOnMount:g=!e}={}){const{user:k,profile:N,isLoading:j,isAdmin:B}=_(),{toast:L}=p(),D=r.useRef(null),F=r.useRef(null),W=Q(),ne=V(),oe=Y(),ae=r.useRef(function(e,r,t){const n=Z.get(e);return"POP"===t&&n&&n.owner===r?Date.now()-n.savedAt>18e5?(Z.delete(e),null):n.snapshot:null}(ne.key,(null==k?void 0:k.id)||null,oe)),le=!l||Boolean(B||(null==N?void 0:N.is_admin)),de=b||Boolean(B||(null==N?void 0:N.is_admin)),Ce=P(Boolean(B||(null==N?void 0:N.is_admin))),Re=r.useRef(!ae.current&&g&&!0),
2ke=r.useRef(new Set),je=r.useRef(new Set),Pe=r.useRef(null),Be=r.useRef(null),qe=r.useRef(null),He=r.useRef(null),Qe=r.useRef(null),Ke=r.useRef(null),nr=r.useRef(!1),Sr=r.useRef(!1),Ir=r.useRef(Re.current),Nr=r.useRef(null),jr=r.useRef(Math.floor(1e5*Math.random())),rt=r.useRef({}),tt=r.useRef(null),nt=r.useRef(null),ot=r.useRef(new Set),at=r.useRef(new Map),lt=r.useRef(new Map),ut=r.useRef(new Map),it=r.useRef(!0),st=r.useRef(null),ct=r.useRef(0),dt=r.useRef(new Set),mt=r.useRef((null==k?void 0:k.id)||null),ft=r.useRef(!0),_t=r.useRef(null),pt=r.useRef(null),ht=r.useRef(0),[bt,gt]=r.useState(0),vt=r.useRef(0),wt=r.useRef([]),yt=r.useRef(0),xt=r.useRef(new Set),St=r.useRef(!1),Mt=r.useRef(null),At=r.useRef(null),Ct=r.useRef(0),Et=r.useRef(null),Rt=r.useRef((null==k?void 0:k.id)||null);Rt.current=(null==k?void 0:k.id)||null;const kt=r.useRef(j?void 0:(null==k?void 0:k.id)||null),It=r.useRef(null),Nt=r.useRef(null),jt=r.useRef(0),Pt=r.useRef(null),Bt=r.useRef(new Set),$t=r.useRef(Re.current),Tt=r.useRef(null),Lt=r.useRef(null);if(null===Lt.current){const e=j&&!(null==k?void 0:k.id)?null:ae.current||Or((null==k?void 0:k.id)||null),r=!e||(null==k?void 0:k.id)&&"semantic"!==e.mode?null:e,t=r?{...r,memories:mr(r.memories,Boolean((null==k?void 0:k.id)||j)),remainingBufferedPages:r.remainingBufferedPages.map(e=>({...e,memories:mr(e.memories,Boolean((null==k?void 0:k.id)||j))})).filter(e=>e.memories.length>0)}:null,n=(null==t?void 0:t.memories.length)?t:null;n&&(St.current="public"===n.mode,Mt.current=n.semanticSource,At.current=n.semanticGenerationId,It.current=n.publicSource,Nt.current=n.publicCursor),Lt.current=n||{userId:(null==k?void 0:k.id)||null,memories:mr(j&&!(null==k?void 0:k.id)?[]:zr((null==k?void 0:k.id)||null),Boolean((null==k?void 0:k.id)||j)),source:"none",mode:null,semanticSource:null,semanticGenerationId:null,publicSource:null,publicCursor:null,nextCursor:null,hasMore:!0,remainingBufferedPages:[]}}const[Dt,Ft]=r.useState(()=>{var e;return(null==(e=Lt.current)?void 0:e.memories)||[]}),Ot=r.useRef(Dt);Ot.current=Dt,r.useEffect(()=>{ft.current=!0;const e=()=>{"visible"===document.visibilityState&&c()&&gt(e=>e+1)},r=i(e),t=s(e);return()=>{var e;ft.current=!1,r(),t(),null==(e=_t.current)||e.abort(),_t.current=null,null!==pt.current&&window.clearTimeout(pt.current)}},[]),r.useEffect(()=>{var e;const r=(null==k?void 0:k.id)||null;if(mt.current!==r&&(mt.current=r,dt.current=new Set,null==(e=_t.current)||e.abort(),_t.current=null,ht.current=0),!r||0===Dt.length||_t.current||"visible"!==document.visibilityState||!c())return;const t=Dt.map(e=>e.id).filter(e=>be.test(e)&&!dt.current.has(e)).slice(0,80);if(0===t.length)return;const n=new AbortController;_t.current=n,U(()=>{Rt.current===r&&ft.current&&!n.signal.aborted&&("visible"===document.visibilityState&&c()?h.rpc("record_explore_feed_served_batch",{p_memory_ids:t,p_feed_context:"for_you"}).abortSignal(n.signal).then(({error:e})=>{if(e)throw e;Rt.current===r&&(t.forEach(e=>R(dt.current,e,2400)),ht.current=0)}).catch(e=>{n.signal.aborted||(ht.current+=1)}).finally(()=>{_t.current===n&&(_t.current=null,ft.current&&Rt.current===r&&(null!==pt.current&&window.clearTimeout(pt.current),pt.current=window.setTimeout(()=>{pt.current=null,gt(e=>e+1)},ht.current>0?Math.min(6e4,5e3*2**Math.min(ht.current-1,4)):250)))}):_t.current===n&&(_t.current=null))},{waitForFirstFrame:!0,idleTimeoutMs:2500,nativeDelayMs:350})},[Dt,bt,null==k?void 0:k.id]);const[qt,zt]=r.useState([]),[Gt,Jt]=r.useState(null),Ht=r.useRef(null),[Wt,Ut]=r.useState(!0),[Qt,Vt]=r.useState(!1),[Yt,Kt]=r.useState(!1),[Xt,Zt]=r.useState(!1),[en,rn]=r.useState(!1),[tn,nn]=r.useState(null),[on,an]=r.useState(()=>Re.current?Date.now():0),[ln,un]=r.useState(0),[sn,cn]=r.useState(0),[dn,mn]=r.useState([]),[fn,_n]=r.useState(null),[pn,hn]=r.useState(null),[bn,gn]=r.useState({missingRenderable:0,missingMatch:0,own:0,seen:0,suppressedBoard:0,sampleIds:[]}),[vn,wn]=r.useState(!1),[yn,xn]=r.useState({triggerCount:0,lastAt:null,lastProgress:0,lastDistanceToBottom:null,lastReason:null}),[Sn,Mn]=r.useState({batchMs:null,profileMs:null,pageMs:null,refillMs:null,poolWarmMs:null,lastRowsReturned:0,lastRowsAccepted:0,lastRowsDropped:0}),[An,Cn]=r.useState(0),[En,Rn]=r.useState(0);r.useEffect(()=>(it.current=!0,()=>{it.current=!1,null!==st.current&&(window.clearTimeout(st.current),st.current=null),jt.current+=1,Pt.current=null}),[]),r.useEffect(()=>{if(j)return;const e=(null==k?void 0:k.id)||null,r=kt.current;void 0!==r?r!==e&&(kt.current=e,jt.current+=1,Be.current=null,Pt.current=null,ke.current=ne
2w Set,Bt.current=new Set,nt.current=null,Et.current=null,Mt.current=null,At.current=null,Ct.current=0,St.current=!1,It.current=null,Nt.current=null,Tt.current=null,Ot.current=[],Ft([]),mn([]),zt([]),Jt(null),Ht.current=null,Ut(!0),Vt(!1),Kt(!1),Zt(!1),nn(null),un(0),cn(0),an(Date.now())):kt.current=e},[j,null==k?void 0:k.id]),r.useEffect(()=>{(null==k?void 0:k.id)&&(St.current=!1,It.current=null,Nt.current=null,Ft(e=>{const r=dr(e);return r.length===e.length?e:(Ot.current=r,r)}),mn(e=>{const r=e.filter(e=>"semantic"===e.mode).map(e=>({...e,memories:dr(e.memories)})).filter(e=>e.memories.length>0);return r.length===e.length&&r.every((r,t)=>r===e[t])?e:(Gr(k.id,r),r)}))},[null==k?void 0:k.id]),r.useEffect(()=>{if(!(null==k?void 0:k.id)||0===Dt.length)return;let e=!1,r=null;const t=U(()=>{if(e)return;const t=()=>{e||a(k.id).catch(e=>{})};r="function"==typeof window.requestIdleCallback?window.requestIdleCallback(t,{timeout:4e3}):window.setTimeout(t,2e3)},{nativeDelayMs:1500});return()=>{e=!0,t(),null!==r&&("function"==typeof window.cancelIdleCallback?window.cancelIdleCallback(r):window.clearTimeout(r))}},[Dt.length,null==k?void 0:k.id]);const kn=["explore-feed-v2","bootstrap-page",q,null==k?void 0:k.id,on,Ce],In=m({queryKey:kn,enabled:Boolean(le&&!j&&(k||e)),queryFn:async({signal:e})=>{const r=performance.now(),t=Nr.current;Nr.current=null;const n=(null==k?void 0:k.id)?(e=>{const r=We();if(!r||!e)return null;try{const t=r.getItem(H(e));if(!t)return null;const n=JSON.parse(t);if(!n.savedAt||Date.now()-n.savedAt>Ae)return null;if(!Number.isFinite(n.cursor)||Number(n.cursor)<=0)return null;const o="runway-v2"===n.semanticSource||"runway-legacy"===n.semanticSource||"live"===n.semanticSource||"typesense"===n.semanticSource?n.semanticSource:null,a="runway-v2"===o&&"string"==typeof n.semanticGenerationId?n.semanticGenerationId:null;return"runway-v2"!==o||a?{cursor:Math.max(0,Math.floor(Number(n.cursor))),semanticSource:o,semanticGenerationId:a}:null}catch{return null}})(k.id):null;Ir.current=!1;try{const r=performance.now();_n("semantic:start");let o=t??(null==n?void 0:n.cursor)??0,a=[],l="semantic";const u=new AbortController,i=new AbortController,s=()=>{u.abort(e.reason),i.abort(e.reason)};e.aborted?s():e.addEventListener("abort",s,{once:!0});const c=(null==k?void 0:k.id)?Promise.resolve([]):(async()=>{const e=O();if(e)try{const r=await e;if(i.signal.aborted)throw i.signal.reason;if(Array.isArray(r)&&r.length>0&&gr(r,null==k?void 0:k.id,Cr(null==k?void 0:k.id)).length>0)return er(r,"keyset-v2",0)}catch{}return rr(0,we,null==k?void 0:k.id,{signal:i.signal})})().then(e=>kr(e,null==k?void 0:k.id,"public")),d=(null==k?void 0:k.id)?(async()=>{const e=Date.now()+15e3,r=(r,t)=>Pr({offset:r,limit:we,userId:k.id,includeSeenHistory:!0,viewerIsInternal:Ce,preferredSource:t&&(null==n?void 0:n.semanticSource)||null,generationId:t&&(null==n?void 0:n.semanticGenerationId)||null,allowRunwayRefresh:!1,timeoutMs:Math.max(1,e-Date.now()),signal:u.signal,label:"Explore Feed v2 My Algorithm"});let a=await r(o,o>0&&null===t),l=kr(a,k.id,"semantic");return 0===l.length&&o>0&&(o=0,a=await r(0,!1),l=kr(a,k.id,"semantic")),l})():Promise.resolve([]),m=await(async()=>{if(null==k?void 0:k.id)try{const e=await d;return e.length>0?{source:"personalized",rows:e,errors:[]}:{source:"none",rows:[],errors:[]}}catch(r){return{source:"none",rows:[],errors:[r]}}try{return await async function({personalized:e,discovery:r,personalizationBudgetMs:t,totalBudgetMs:n,signal:o}){const a=Date.now(),l=ee("personalized",e),u=ee("discovery",r),i=await re([l],Math.min(t,n),o);if(i.useful)return{source:i.useful.source,rows:i.useful.rows,errors:[]};const s=Date.now()-a,c=Math.max(0,n-s),d=await re([l,u],c,o);return d.useful?{source:d.useful.source,rows:d.useful.rows,errors:d.outcomes.flatMap(e=>e.error?[e.error]:[])}:{source:"empty",rows:[],errors:d.outcomes.flatMap(e=>e.error?[e.error]:[])}}({personalized:d,discovery:c,personalizationBudgetMs:300,totalBudgetMs:2e3,signal:e})}catch(r){throw u.abort(r),i.abort(r),e.removeEventListener("abort",s),r}})();
2if("personalized"===m.source?(i.abort(new DOMException("Explore personalized first paint won","AbortError")),e.removeEventListener("abort",s)):"discovery"===m.source?(i.abort(new DOMException("Explore discovery first paint returned","AbortError")),u.abort(),e.removeEventListener("abort",s)):(u.abort(new DOMException("Explore first paint deadline exceeded","TimeoutError")),i.abort(new DOMException("Explore first paint deadline exceeded","TimeoutError")),e.removeEventListener("abort",s)),e.aborted)throw e.reason;if("personalized"===m.source)a=m.rows,_n("semantic:returned");else if("discovery"===m.source)l="public",a=m.rows,_n("semantic:discovery-fallback");else{const e=mr(wr(xr(null==k?void 0:k.id),null==k?void 0:k.id),Boolean(null==k?void 0:k.id)),r=mr(Fr(null==k?void 0:k.id),Boolean(null==k?void 0:k.id)),t=e.length>0?e:r;if(t.length>0)a=t.map(lr),l=t.some(e=>"public_cold_start"===ir(e))?"public":"semantic",_n("semantic:timeout-cache");else{if(m.errors.length>0)throw new Error(`Explore first paint timed out: ${De(m.errors[0])||"no feed source responded"}`);l=(null==k?void 0:k.id)?"semantic":"public",_n("semantic:empty")}}return{batch_id:Wr(null==k?void 0:k.id),seed:"semantic-anchor",expires_at:null,item_count:a.length,initial_rows:a,initial_mode:l,initial_cursor_floor:"semantic"===l?o:0,initial_page_ms:Math.round(performance.now()-r)}}finally{_n("done"),Mn(e=>({...e,batchMs:Math.round(performance.now()-r)}))}},staleTime:e=>{var r;return"public"===(null==(r=e.state.data)?void 0:r.initial_mode)?2e4:3e5},retry:(e,r)=>e<1&&Fe(De(r)),retryDelay:300,networkMode:"always",refetchOnMount:!0,refetchOnWindowFocus:!1,refetchOnReconnect:!0}),Nn=r.useRef(null);Nn.current=Dt.length>0?{userId:(null==k?void 0:k.id)||null,memories:Dt,source:"buffered",mode:St.current?"public":"semantic",semanticSource:Mt.current,semanticGenerationId:At.current,publicSource:It.current,publicCursor:Nt.current,nextCursor:Gt,hasMore:Wt,remainingBufferedPages:dn}:null,r.useEffect(()=>{const e=(null==k?void 0:k.id)||null;return()=>{const r=Nn.current;(null==r?void 0:r.userId)===e&&r.memories.length>0&&function(e,r,t){for(Z.delete(e),Z.set(e,{owner:r,savedAt:Date.now(),snapshot:t});Z.size>4;)Z.delete(Z.keys().next().value)}(ne.key,e,r)}},[ne.key,null==k?void 0:k.id]);const jn=In.data||null,Pn=(null==jn?void 0:jn.batch_id)||null,Bn=r.useCallback((e=Pn)=>({epoch:jt.current,batchId:Be.current||e||"",mode:Hr(e,St.current)}),[Pn]);r.useEffect(()=>{var e;if(!(null==k?void 0:k.id))return;if("buffered"===(null==(e=Lt.current)?void 0:e.source)&&Lt.current.userId===k.id)return;const r=Or(k.id);if(!(null==r?void 0:r.memories.length))return;const t=mr(r.memories,!0);if(0===t.length)return;const n=r.remainingBufferedPages.map(e=>({...e,memories:mr(e.memories,!0)})).filter(e=>e.memories.length>0);Lt.current={...r,memories:t,remainingBufferedPages:n},St.current=!1,Mt.current=r.semanticSource,At.current=r.semanticGenerationId,It.current=r.publicSource,Nt.current=r.publicCursor,Ft(e=>{const r=e.every(cr),n=e.length>0&&r?ue(e,t,{getId:e=>e.id,getContentIdentity:e=>d(e),shouldReplace:(e,r)=>_r(e,r)}).items:t;return Ot.current=n,n}),Jt(r.nextCursor),Ut(r.hasMore),mn(n),Gr(k.id,n)},[Ce,null==k?void 0:k.id]),r.useEffect(()=>{if(!(null==k?void 0:k.id)||Dt.length>0)return;const e=zr(k.id),r=mr(e,!0);0!==r.length&&(Ft(r),cn(r.length))},[Ce,Dt.length,null==k?void 0:k.id]),r.useEffect(()=>{Ht.current=Gt},[Gt]),r.useEffect(()=>{if(!Pn||"number"!=typeof Gt)return;const e=Hr(Pn,St.current);mn(r=>{const t=[...r.filter(e=>e.batchId!==Pn),...Le(r,Pn,Gt,e,"semantic"===e?Mt.current:null,"semantic"===e?At.current:null,"public"===e?It.current:null,"public"===e?Nt.current:null)];return t.length===r.length&&t.every((e,t)=>e===r[t])?r:(Gr(null==k?void 0:k.id,t),t)})},[Pn,Gt,null==k?void 0:k.id]),r.useEffect(()=>{if(!(null==k?void 0:k.id)||Dt.length>0)return;const e=De(In.error);if(!Fe(e))return;const r=wr(xr(k.id),k.id),t=Fr(k.id),n=mr(r,!0),o=mr(t,!0),a=n.length>0?n:o;a.length<Math.min(20,we)||(Ft(a),cn(a.length),nn(null),Ut(!0))},[In.error,In.isLoading,Ce,Dt.length,null==k?void 0:k.id]);const $n=r.useCallback((e={})=>
2{jt.current+=1,Pt.current=null,Bt.current=new Set,$t.current=!0===e.clearRendered,ke.current=new Set,je.current=new Set,xt.current=new Set,nt.current=null,Be.current=null,Tt.current=null,yt.current=0,vt.current=0,St.current=!1,Mt.current=null,At.current=null,Ct.current=0,Et.current=null,Vt(!1),It.current=null,Nt.current=null,Sr.current=!1,mn([]),Jt(null),Ut(!0),un(0),nn(null),Kt(!1),e.clearRendered&&(Ft([]),Pe.current=null),Ir.current=!0,an(Date.now())},[]),Tn=r.useCallback(()=>{const e=Math.max(0,Number(Ht.current||0),Number(Ct.current||0));Nr.current=e>0?e:null,((e,r={})=>{const t=We();if(t&&e)try{const n=[J(e),J(null),G(e),H(e),ze(e)];r.preserveLastGood||n.push(z(e),z(null)),t===window.localStorage?n.forEach(e=>{$(e),t.removeItem(e)}):n.forEach(e=>t.removeItem(e))}catch{}})(null==k?void 0:k.id,{preserveLastGood:!0}),(e=>{const r=`my-algorithm:${e||""}:`;Array.from(Ne.keys()).forEach(t=>{e&&!t.startsWith(r)||Ne.delete(t)})})(null==k?void 0:k.id),jt.current+=1,Pt.current=null,Bt.current=new Set,$t.current=!0,Lt.current={userId:(null==k?void 0:k.id)||null,memories:[],source:"none",mode:null,semanticSource:null,semanticGenerationId:null,publicSource:null,publicCursor:null,nextCursor:null,hasMore:!0,remainingBufferedPages:[]},ke.current=new Set,je.current=new Set,xt.current=new Set,nt.current=null,vt.current=0,St.current=!1,Mt.current=null,At.current=null,Ct.current=0,Et.current=null,Vt(!1),It.current=null,Nt.current=null,rt.current={},Sr.current=!1,Be.current=null,Tt.current=null,yt.current=0,mn([]),Jt(null),Ut(!0),un(0),cn(0),nn(null),Kt(!1),Ir.current=!0,an(e=>Math.max(Date.now(),e+1))},[null==k?void 0:k.id]),Ln=r.useCallback(()=>new Promise((e,r)=>{if(F.current)return void e();const t=setTimeout(()=>{F.current=null,r(new Error("Explore refresh timed out. Please try again."))},35e3);F.current={startedAt:Date.now(),resolve:e,reject:r,timer:t},Tn()}),[Tn]);r.useEffect(()=>{const e=F.current;e&&!In.isFetching&&(In.errorUpdatedAt>=e.startedAt&&In.isError?(clearTimeout(e.timer),F.current=null,e.reject(new Error("Explore couldn’t refresh. Please try again."))):In.dataUpdatedAt>=e.startedAt&&In.isSuccess&&(clearTimeout(e.timer),F.current=null,e.resolve()))},[In.isFetching,In.isError,In.isSuccess,In.errorUpdatedAt,In.dataUpdatedAt]),r.useEffect(()=>()=>{const e=F.current;e&&(clearTimeout(e.timer),e.reject(new Error("Explore closed")),F.current=null)},[]),r.useEffect(()=>{var e;if(!jn)return;const r=`${(null==k?void 0:k.id)||"anon"}:${Pn||"none"}:${on}`;if(Tt.current===r)return;Tt.current=r,jt.current+=1,Pt.current=null,Bt.current=new Set,Kt(!1),Be.current=Pn;const t=$t.current;$t.current=!1;const n=!Jr(Pn),o=n?wr(xr(null==k?void 0:k.id),null==k?void 0:k.id):[],a=n?Fr(null==k?void 0:k.id):[],l=o.length>0?o:a,u=(null==jn?void 0:jn.initial_rows)||[],i=(e=>{const r=We();if(!r)return[];try{const t=r.getItem(Ge(e));if(!t)return[];const n=JSON.parse(t);if(!n||"object"!=typeof n||Array.isArray(n))return[];const o=n;return!o.savedAt||Date.now()-o.savedAt>Me?[]:Array.isArray(o.tags)?o.tags.filter(e=>Boolean(null==e?void 0:e.value)).slice(0,$e):[]}catch{return[]}})(null==k?void 0:k.id),s=Lr(null==k?void 0:k.id),c=s.length>0?s:i,m=u.map(ar),f="public"===(null==jn?void 0:jn.initial_mode)||m.some(e=>"public_cold_start"===ir(e)),_=f?"public":"semantic",p="semantic"===_?Ye(u):null,b="runway-v2"===p?Xe(u):null,g="public"===_?tr(u):null,v="buffered"===(null==(e=Lt.current)?void 0:e.source)?Lt.current:null,w=v&&!t&&v.mode===_&&("semantic"!==_||Boolean(p)&&v.semanticSource===p&&("runway-v2"!==p||Boolean(b)&&v.semanticGenerationId===b))&&("public"!==_||Boolean(g)&&v.publicSource===g)?v:null,y=w?"public"===w.mode:f;St.current=y,Mt.current=y?null:(null==w?void 0:w.semanticSource)||Ye(u),At.current="runway-v2"===Mt.current?(null==w?void 0:w.semanticGenerationId)||Xe(u):null,It.current=y?(null==w?void 0:w.publicSource)||tr(u):null,Nt.current=y?(null==w?void 0:w.publicCursor)||or(u):null;const x=y||m.some(e=>"fallback_join"===ir(e)),S=y?Cr(null==k?void 0:k.id):x?E(null==k?void 0:k.id):Rr(null==k?void 0:k.id),M=hr(m,null==k?void 0:k.id,S),A=(null==k?void 0:k.id)&&"semantic"===_?M.filter(cr):M,C=n&&(0===u.length||0===A.length),R=A.length>0?A:C?l:[],I=!(A.length>0&&!x),N=(null==w?void 0:w.memories.length)?w.memories:I?yr(R,null==k?void 0:k.id,"batch"):R,j=t?N.length:Math.max(Dt.length,N.length);Jr(Pn)&&N.length>0&&Mr(null==k?void 0:k.id,N);const P=u[u.length-1],B=y||Jr(Pn)?me(u,Number((null==jn?void 0:jn.initial_cursor_floor)||0)):P?"number"==typeof P.next_cursor?P.next_cursor:P.feed_position??null:null;Ft(e=>{if(0===N.length)return t?(Ot.current=[],[]):e.length>0?e:[];const r=Boolean(null==k?void 0:k.id)&&e.some(e=>!cr(e));if(t||r)return Ot.current=N,N;if(e.length>0){const r=ue(e,N,{getId:e=>e.id,getContentIdentity:e=>d(e),shouldReplace:(e,r)=>_r(e,r)}).items;return Ot.current=r,r}return Ot.current=N,N}),cn(A.length>0?0:l.length),Jt((null==w?void 0:w.nextCursor)??B),Ut((null==w?void 0:w.hasMore)??!0),nn(null),un(Number((null==jn?void 0:jn.item_count)||0)),ke.current=ne
2w Set,je.current=new Set,xt.current=new Set,Pe.current=null,qe.current=null,He.current=null,jr.current=Math.floor(1e5*Math.random()),rt.current={},tt.current=null,Ke.current=null,nr.current=!1,nt.current=null,vt.current=0,wt.current=c,yt.current=0,xn({triggerCount:0,lastAt:null,lastProgress:0,lastDistanceToBottom:null,lastReason:null}),zt(c),gn(br(m,null==k?void 0:k.id,S)),rn(!1),wn(!1);const $=Dr(null==k?void 0:k.id,Pn),T=Hr(Pn,St.current),L=w?w.remainingBufferedPages:Le($,Pn,B,T,"semantic"===T?Mt.current:null,"semantic"===T?At.current:null,"public"===T?It.current:null,"public"===T?Nt.current:null);if(mn(L),w&&Gr(null==k?void 0:k.id,L),Sr.current=!1,t&&N.length>0&&window.dispatchEvent(new CustomEvent("echo-feed-explicit-refresh",{detail:{surfaceId:"explore-feed"}})),Mn(e=>({...e,profileMs:null,poolWarmMs:null,pageMs:"number"==typeof(null==jn?void 0:jn.initial_page_ms)&&jn.initial_page_ms||null,refillMs:null,lastRowsReturned:u.length,lastRowsAccepted:A.length,lastRowsDropped:Math.max(0,u.length-A.length)})),u.length>0&&!w&&(Jt(B),"number"==typeof B&&(un(e=>Math.max(e,B,Number((null==jn?void 0:jn.item_count)||0))),Jr(Pn)&&!y&&(Ct.current=B,Tr(null==k?void 0:k.id,B,Mt.current,At.current))),Ut(y?"keyset-v2"===It.current?Boolean(null==P?void 0:P.has_more)&&null!==Nt.current:u.length>=ge&&null!==B:Jr(Pn)?Ve(u,we):Boolean(null==P?void 0:P.has_more)),Pn&&ke.current.add(`${Pn}:0`)),Jr(Pn)&&0===u.length&&(Ut(!0),w||(Jt(0),un(0)),Kt(!1)),j<20){const e="number"==typeof B?B:0,r=Bn(Pn),t=()=>
2se(r,Bn(Pn));Kt(!0),(y?rr(e,ve,null==k?void 0:k.id,{preferredSource:It.current,cursor:Nt.current}):Jr(Pn)?Pr({offset:e,limit:we,userId:null==k?void 0:k.id,currentMemories:N,includeSeenHistory:!0,viewerIsInternal:Ce,preferredSource:Mt.current,generationId:At.current,timeoutMs:xe,label:"Explore Feed v2 initial semantic recovery"}):(async(e,r,t,n={})=>{const o=Math.random(),a=Array.from({length:4},(t,n)=>e+n*r),l=[{source:"for-you-fast-pool",offset:e,request:Oe(h.rpc("get_dashboard_explore_echo_feed_fast_pool",{limit_count:r,p_offset:e,p_seed:o,p_after_rank:null,p_after_id:null}),Se,"Explore Feed v2 For You first paint")},{source:"authenticated-new-snapshot",offset:e,request:Oe(h.rpc("get_authenticated_explore_feed_pool_snapshot",{p_mode:"new",p_time_range:"all_time",p_type_filter:null,p_limit:r,p_offset:e}),Se,"Explore Feed v2 authenticated first paint")},...a.map(e=>({source:"public-new-fast",offset:e,request:Oe(h.rpc("get_public_explore_echo_feed_new_fast",{limit_count:r,p_offset:e,p_after_created_at:null,p_after_id:null,p_time_range:"all_time",p_query:null,p_ai_filters:{},p_type_filter:null}),Se,"Explore Feed v2 public first paint")}))],u=e=>{const t=new Set(e.map(e=>e.source_board_id||e.board_id||"").filter(Boolean)),n=new Set(e.map(e=>e.source_board_owner_id||e.source_board_owner||e.curator_username||"").filter(Boolean));return 100*t.size+25*n.size+Math.min(e.length,r)},i=l.map(async({source:r,offset:o,request:a})=>{try{const{data:l,error:i}=await a;if(i||!Array.isArray(l)||0===l.length)return null;const s=(e=>{const r=n.allowRecentlyRendered?E(t):Cr(t),o=Br(t),a=new Set(hr(e.map(ar),t,r,o).map(e=>e.id));return e.filter(e=>a.has(String(e.id||e.memory_id||"")))})(Ze(l,r,o));return 0===s.length?null:{rows:s,score:u(s)-.001*Math.max(0,o-e)}}catch{return null}}),s=await new Promise(e=>{let r=0;i.forEach(t=>{t.then(t=>{r+=1,(null==t?void 0:t.rows.length)?e(t):r===i.length&&e(null)})})}),c=Math.min(r,ve);if(s&&s.rows.length>=c)return s.rows;const d=(await Promise.all(i)).filter(e=>Boolean(e)).sort((e,r)=>r.score-e.score),m=[],f=new Set;if(d.forEach(e=>{e.rows.forEach(e=>{const t=String(e.id||e.memory_id||"");!t||f.has(t)||m.length>=r||(f.add(t),m.push(e))})}),m.length>0)return m;const _=d[0];return(null==_?void 0:_.rows)||[]})(e,240,null==k?void 0:k.id,{allowRecentlyRendered:!0})).then(r=>{var n;if(!t())return;St.current&&(It.current=tr(r)||It.current,Nt.current=or(r)),St.current||Mt.current||(Mt.current=Ye(r));const o=r.some(e=>!0===e.reset_required);if("runway-v2"===Mt.current){const e=Xe(r);(o||e)&&(At.current=e)}const a=r.map(ar),l=St.current?Cr(null==k?void 0:k.id):Jr(Pn)?Rr(null==k?void 0:k.id):Cr(null==k?void 0:k.id),u=hr(a,null==k?void 0:k.id,l),i=Jr(Pn)&&!St.current?u.filter(cr):u;gn(br(a,null==k?void 0:k.id,l)),Mn(e=>({...e,lastRowsReturned:r.length,lastRowsAccepted:i.length,lastRowsDropped:Math.max(0,a.length-i.length)}));const s=me(r,e),c=St.current?"keyset-v2"===It.current?Boolean(null==(n=r[r.length-1])?void 0:n.has_more)&&null!==Nt.current:r.length>=ve&&null!==s:Ve(r,we);o&&(jt.current+=1,Pt.current=null,nt.current=null,ke.current=new Set,Bt.current=new Set,mn([]),Gr(null==k?void 0:k.id,[]),wn(!1),Kt(!1)),(o||i.length>0)&&Ft(e=>{const r=ue(e,i,{getId:e=>e.id,getContentIdentity:e=>d(e),shouldReplace:(e,r)=>_r(e,r)}).items;return Ot.current=r,r}),Jt(c?s:null),"number"==typeof s&&un(e=>Math.max(e,s)),Jr(Pn)&&!St.current&&"number"==typeof s&&(Ct.current=s,Tr(null==k?void 0:k.id,s,Mt.current,At.current)),Ut(c),nn(null)}).catch(e=>{if(!t())return;const r=De(e)||"Explore could not load the next echoes.";nn(r),Ut(!0)}).finally(()=>{t()&&Kt(!1)})}},[jn,Pn,on,Ce,Bn,Dt.length,null==k?void 0:k.id]),r.useEffect(()=>{if(!(null==k?void 0:k.id))return;let e=!1;return(async()=>{const{data:r,error:t}=await h.from("explore_board_feedback").select("board_id").eq("user_id",k.id).eq("feedback_type","not_interested");if(e||t||!Array.isArray(r)||0===r.length)return;const n=new Set(r.map(e=>String(e.board_id||"")).filter(Boolean));0!==n.size&&($r(k.id,n),mn(e=>{const r=e.map(e=>({...e,memories:hr(e.memories,k.id,Cr(k.id),n)})).filter(e=>e.memories.length>0);return r.length!==e.length&&Gr(k.id,r),r}))})(),()=>{e=!0}},[null==k?void 0:k.id]);const Dn=r.useCallback(async function e(r,t={}){var n;if(!Pn)return;const o=void 0===r?Gt:r;if(!t.force&&!Wt&&null!==o)return;const a=Bn(Pn),l=ie(a,o),u=`${Pn}:${o??0}`;if(Pt.current)return;if(!t.force&&ke.current.has(u))return;Pt.current=l,ke.current.add(u),Kt(!0),nn(null);const i=()=>se(a,Bn(Pn)),s=e=>{const r=ue(Ot.current,e,{getId:e=>e.id,getContentIdentity:e=>d(e),shouldReplace:(e,r)=>_r(e,r)});return r.changed?(Ot.current=r.items,Ft(r=>{const t=ue(r,e,{getId:e=>e.id,getContentIdentity:e=>d(e),shouldReplace:(e,r)=>_r(e,r)});return t.changed&&(Ot.current=t.items),t.items}),r):r},c=(r,n,o,a)=>{const l=t.duplicateScanAttempt||0,u=(({insertedCount:e,sourceHasMore:r,currentCursor:t,nextCursor:n,attempt:o,maxAttempts:a})=>e>0||!r||null===n||!Number.isFinite(n)||n<=t||o+1>=Math.max(1,a)?null:n)({insertedCount:r,sourceHasMore:n,currentCursor:a,nextCursor:o,attempt:l,maxAttempts:4});return null===u?null:(Pt.current=null,e(u,{force:!0,duplicateScanAttempt:l+1}))};try{const e=performance.now();if("public"===a.mode){const r=Math.max(0,Number(o||0)),t=await rr(r,ve,null==k?void 0:k.id,{preferredSource:It.current,cursor:Nt.current});if(!i())return;const a=tr(t)||It.current||"legacy-offset",l=or(t);if("keyset-v2"===a&&t.length>0&&!l)throw new Error("Explore public keyset response did not include a usable cursor.");It.current=a,Nt.current=l;const u=t.map(ar),d=Cr(null==k?void 0:k.id),m=hr(u,null==k?void 0:k.id,d),f=me(t,r),_="keyset-v2"===a?Boolean(null==(n=t[t.length-1])?void 0:n.has_more)&&null!==l:t.length>=ve&&null!==f;gn(br(u,null==k?void 0:k.id,d)),Mn(r=>({...r,pageMs:Math.round(performance.now()-e),lastRowsReturned:t.length,lastRowsAccepted:m.length,lastRowsDropped:Math.max(0,u.length-m.length)}));const p=s(m);return m.length>0&&Zt(!1),Jt(_?f:null),"number"==typeof f&&un(e=>Math.max(e,f)),Ut(_),nn(null),c(p.insertedCount,_,f,r)||void 0}if("semantic"===a.mode){const r=Math.max(0,Number(o||0)),t=await Pr({offset:r,limit:20,userId:null==k?void 0:k.id,currentMemories:Ot.current,includeSeenHistory:!0,viewerIsInternal:Ce,preferredSource:Mt.current,generationId:At.current,timeoutMs:xe,label:"Explore Feed v2 semantic page"});if(!i())return;Mt.current||(Mt.current=Ye(t));const n=t.map(ar),a=Cr(null==k?void 0:k.id),l=hr(n,null==k?void 0:k.id,a).filter(cr),u=Ve(t,20),m=me(t,r),f=Xe(t),_=t.some(e=>!0===e.reset_required);if("runway-v2"===Mt.current){if(t.length>0&&!f)throw new Error("Explore semantic runway response did not include its generation.");
2if(At.current&&f&&At.current!==f&&!_)throw new Error("Explore semantic runway changed generation without a reset signal.");(_||f)&&(At.current=f)}if(gn(br(n,null==k?void 0:k.id,a)),Mn(r=>({...r,pageMs:Math.round(performance.now()-e),lastRowsReturned:t.length,lastRowsAccepted:l.length,lastRowsDropped:Math.max(0,n.length-l.length)})),_){jt.current+=1,Pt.current=null,nt.current=null,ke.current=new Set,Bt.current=new Set,mn([]),Gr(null==k?void 0:k.id,[]);const e=ue(Ot.current,l,{getId:e=>e.id,getContentIdentity:e=>d(e),shouldReplace:(e,r)=>_r(e,r)}).items;return Ot.current=e,Ft(e),Ct.current=m||0,un(m||0),Jt(u?m:null),Ut(u),nn(null),void Kt(!1)}const p=s(l);return l.length>0&&(Vt(!1),hn(null),Zt(!1)),"number"==typeof m&&(Ct.current=m,Tr(null==k?void 0:k.id,m,Mt.current,At.current),un(e=>Math.max(e,m))),Jt(u?m:null),Ut(u),c(p.insertedCount,u,m,r)||void 0}const{data:r,error:t}=await Oe(h.rpc("get_explore_feed_v2_page",{p_batch_id:Pn,p_after_position:o,p_limit:ve}),xe,"Explore Feed v2 page");if(t)throw t;if(!i())return;const l=Array.isArray(r)?r:[];if(0===l.length&&null===o&&Math.max(ln,Number((null==jn?void 0:jn.item_count)||0))>0)return ke.current.delete(u),Ut(!0),Jt(null),void(je.current=new Set);const m=l.map(ar),f=Cr(null==k?void 0:k.id),_=hr(m,null==k?void 0:k.id,f);gn(br(m,null==k?void 0:k.id,f)),Mn(r=>({...r,pageMs:Math.round(performance.now()-e),lastRowsReturned:l.length,lastRowsAccepted:_.length,lastRowsDropped:Math.max(0,m.length-_.length)}));const p=s(_);_.length>0&&Zt(!1);const b=l[l.length-1];if(b){const e=vr(l,o??null);Jt(r=>{const t=yt.current;return"number"!=typeof e?"number"==typeof r?Math.max(r,t):t||r:"number"!=typeof r?Math.max(e,t):Math.max(r,e,t)}),"number"==typeof e&&un(r=>Math.max(r,e)),Ut(Boolean(b.has_more));const r=c(p.insertedCount,Boolean(b.has_more),e,Math.max(0,Number(o||0)));if(r)return r}else Ut(!1)}catch(m){if(!i())return;ke.current.delete(u);const r=De(m);if(r&&/batch not found/i.test(r))return void $n({clearRendered:0===Ot.current.length});if("semantic"===a.mode&&!(null==k?void 0:k.id)&&Fe(r))return jt.current+=1,Pt.current=null,ke.current=new Set,Bt.current=new Set,nt.current=null,St.current=!0,Mt.current=null,At.current=null,It.current=null,Nt.current=null,mn([]),Gr(null==k?void 0:k.id,[]),Jt(0),Ut(!0),nn(null),Kt(!1),e(0,{force:!0});if(Fe(r))return nn(r||"Explore took too long to load the next echoes."),void Ut(!0);Ot.current.length>0&&r&&/statement timeout|timed out/i.test(r)||nn(r)}finally{Pt.current===l&&(Pt.current=null,Kt(!1))}},[null==jn?void 0:jn.item_count,Pn,Ce,Bn,Wt,ln,Gt,$n,null==k?void 0:k.id]),Fn=r.useCallback(()=>{if(!(null==k?void 0:k.id)||!Pn)return Promise.resolve();const e=k.id,r=Et.current;if(r)return r;Vt(!0),Zt(!0),nn(null);const t=(async()=>{const r=await Oe(h.rpc("refresh_explore_semantic_runway",{p_target:240,p_force:!0}),4e4,"Explore personalized runway rotation");if(Rt.current!==e)return;if(r.error)throw r.error;const t=Array.isArray(r.data)?r.data[0]:null,n=Number((null==t?void 0:t.available_count)||0);if(n<=0)throw new Error("Explore could not find another personalized runway yet.");jt.current+=1,Pt.current=null,ke.current=new Set,Bt.current=new Set,nt.current=null,Mt.current="runway-v2",At.current=null,Ct.current=0,mn([]),Gr(k.id,[]),wn(!1),Jt(0),Ht.current=0,Ut(!0),un(n);const o=Ot.current.length;if(await Dn(0,{force:!0}),Rt.current===e){if(Ot.current.length<=o)throw new Error("Explore prepared a new runway but did not find unseen echoes to append.");Vt(!1)}})().catch(r=>{if(Rt.current!==e)return;const t=De(r)||"Explore could not prepare more echoes.";nn(t),Ut(!1)}).finally(()=>{Et.current=null,Zt(!1)});return Et.current=t,t},[Pn,Dn,null==k?void 0:k.id]),On=r.useCallback(e=>{if(!Pn||e.batchId!==Pn)return 0;const r=Bn(Pn);if(e.mode&&e.mode!==r.mode)return 0;if("semantic"===r.mode&&e.semanticSource!==Mt.current)return 0;if("semantic"===r.mode&&"runway-v2"===Mt.current&&At.current&&e.semanticGenerationId!==At.current)return 0;if("public"===r.mode&&It.current&&e.publicSource!==It.current)return 0;if("public"===r.mode&&!Te(e,It.current,Nt.current))return 0;const t=ie(r,e.cursor);if(Bt.current.has(t))return 0;Bt.current.add(t);const n=hr(e.memories,null==k?void 0:k.id,Cr(null==k?void 0:k.id));mn(r=>{const t=r.filter(r=>
2!(r.batchId===e.batchId&&r.cursor===e.cursor));return Gr(null==k?void 0:k.id,t),t}),Jt(e.hasMore&&"number"==typeof e.nextCursor?e.nextCursor:null),"number"==typeof e.nextCursor&&(un(r=>Math.max(r,e.nextCursor||0)),"semantic"===r.mode&&(Ct.current=e.nextCursor,Tr(null==k?void 0:k.id,e.nextCursor,e.semanticSource||Mt.current,e.semanticGenerationId||At.current))),Ut(e.hasMore),"public"===r.mode&&(It.current=e.publicSource||It.current,Nt.current=e.nextPublicCursor||null),"semantic"===r.mode&&"runway-v2"===e.semanticSource&&(At.current=e.semanticGenerationId||At.current),"semantic"===r.mode&&n.length>0&&Vt(!1),Mn(r=>({...r,lastRowsReturned:e.memories.length,lastRowsAccepted:n.length,lastRowsDropped:Math.max(0,e.memories.length-n.length)}));const o=ue(Ot.current,n,{getId:e=>e.id,getContentIdentity:e=>d(e),shouldReplace:(e,r)=>_r(e,r)});return o.changed&&(Ot.current=o.items),Ft(e=>ue(e,n,{getId:e=>e.id,getContentIdentity:e=>d(e),shouldReplace:(e,r)=>_r(e,r)}).items),o.insertedCount},[Pn,Bn,null==k?void 0:k.id]);r.useEffect(()=>{if(!Pn||Dt.length>0||tn)return;if(Yt)return;if(Sn.lastRowsReturned<=0||Sn.lastRowsAccepted>0)return;if(!Wt||null===Gt)return;const e=Hr(Pn,St.current),r=dn.find(r=>r.batchId===Pn&&(!r.mode||r.mode===e)&&("semantic"!==e||r.semanticSource===Mt.current)&&("semantic"!==e||"runway-v2"!==Mt.current||r.semanticGenerationId===At.current)&&("public"!==e||!It.current||r.publicSource===It.current)&&("public"!==e||Te(r,It.current,Nt.current))&&r.cursor===Gt);if(!(r&&On(r)>0)){if(r&&"number"==typeof r.nextCursor&&r.hasMore)return ke.current.delete(`${Pn}:${r.nextCursor}`),void Dn(r.nextCursor);ke.current.delete(`${Pn}:${Gt}`),Dn(Gt)}},[Pn,On,Wt,Yt,Dn,Dt.length,Gt,tn,dn,Sn.lastRowsAccepted,Sn.lastRowsReturned]),r.useEffect(()=>{if(!Pn||Yt||tn)return;if(!Wt||null===Gt)return;if(Dt.length<=0||Dt.length>=20)return;const e=`${Pn}:${Gt}`;ke.current.has(e)||Dn(Gt)},[Pn,Wt,Yt,Dn,Dt.length,Gt,tn]);const qn=r.useCallback(async()=>{if(!Pn)return;if(He.current)return He.current;qe.current=Pn;const e=performance.now(),r=(async()=>{const{data:r,error:t}=await Oe(h.rpc("refresh_explore_feed_v2_taste_profile"),18e3,"Explore Feed v2 taste profile");if(Mn(r=>({...r,profileMs:Math.round(performance.now()-e)})),t)throw qe.current=null,t;const n=(e=>{const r=Array.isArray(e)?e[0]:e;if(!r||"object"!=typeof r)return null;const t=r;return t.top_positive_facets||t.refresh_explore_feed_v2_taste_profile||t.result||null})(r),o=(a=n&&"object"==typeof n&&!Array.isArray(n)?n.top_positive_facets:n,Array.isArray(a)?a.map((e,r)=>{if(!e||"object"!=typeof e)return null;const t=e,n=String(t.group||t.group_name||"").trim().toLowerCase(),o=String(t.value||"").trim();return"tags"===n&&o?{value:o,rank:r+1,weight:Number(t.weight||0)}:null}).filter(e=>Boolean(e)):[]);var a;const l=Lr(null==k?void 0:k.id),u=l.length>0?l:o;u.length>0&&(wt.current=u,zt(u),((e,r)=>{const t=We();if(t&&e&&0!==r.length)try{t.setItem(Ge(e),JSON.stringify({savedAt:Date.now(),tags:r.slice(0,$e)}))}catch{}})(null==k?void 0:k.id,u))})().finally(()=>{He.current=null});return He.current=r,r},[Pn,null==k?void 0:k.id]),zn=r.useCallback(async e=>{if(!(null==k?void 0:k.id))return 0;if(Qe.current)return Qe.current;const r=ze(k.id),t=Number(window.localStorage.getItem(r)||0);if("manual"!==e&&"low_watermark"!==e&&Date.now()-t<6e5)return 0;const n=performance.now(),o=Oe(h.rpc("refresh_user_explore_for_you_pool",{p_limit:1500}),25e3,"Explore Feed v2 pool warm").then(({data:e,error:t})=>{if(t)throw t;return window.localStorage.setItem(r,String(Date.now())),Math.max(0,Number(e||0))}).finally(()=>{Mn(e=>({...e,poolWarmMs:Math.round(performance.now()-n)})),Qe.current=null});return Qe.current=o,o},[null==k?void 0:k.id]),Gn=r.useCallback(async(e,r)=>{if(!Pn)return 0;if(Jr(Pn))return 0;if(Ke.current)return Ke.current;const t=(async()=>{const e=performance.now();try{const{data:t,error:n}=await Oe(h.rpc("refill_explore_feed_v2_tag_lanes",{p_batch_id:Pn,p_target_count:r}),18e3,"Explore Feed v2 tag lane queue refill");if(Mn(r=>({...r,refillMs:Math.max(r.refillMs||0,Math.round(performance.now()-e))})),n)throw n;return Math.max(0,Number(t||0))}catch(t){return De(t),0}})().finally(()=>{Ke.current=null});return Ke.current=t,t},[Pn]);r.useEffect(()=>
2{Pn&&(Jr(Pn)||qn().catch(e=>{}))},[Pn,qn]),r.useCallback(async e=>{if(tt.current)return tt.current;const r=(async()=>{rn(!0);let r=(wt.current.length>0?wt.current:qt).slice(0,8);if(0===r.length&&(await qn().catch(e=>{}),r=(wt.current.length>0?wt.current:qt).slice(0,8)),0===r.length)return 0;return(await Promise.all(r.map(async r=>{const t=rt.current[r.value]??(jr.current+37*r.rank)%8*24;try{const{data:n,error:o}=await Oe(h.rpc("search_public_explore_echoes_single_filter_fast",{p_group_name:"tags",p_value:r.value,p_limit:24,p_offset:t,p_time_range:"all_time",p_type_filter:null,p_search_sort:"manual"===e||"initial"===e?"relevant":"recent"}),3200,`Explore Feed v2 tag lane ${r.value}`);if(o)throw o;const a=Array.isArray(n)?n:[];return rt.current[r.value]=t+24,((e,r,t)=>{const n=hr(e.map((e,n)=>((e,r,t)=>{const n=e.metadata&&"object"==typeof e.metadata&&!Array.isArray(e.metadata)?e.metadata:{},o=r.value.replace(/[_-]+/g," ").replace(/\s+/g," ").trim(),a=[{group_name:"tags",group:"tags",value:r.value,rank:r.rank,score:r.weight,weight:r.weight}],l=e.source_board_owner||e.added_by_username||e.curator_username||null,u=e.source_board_owner_full_name||e.added_by_full_name||e.curator_full_name||null,i=e.source_board_owner_avatar||e.added_by_avatar||e.curator_avatar||null;return{id:String(e.id||e.memory_id),type:e.type||"image",title:e.title||null,ai_title:e.ai_title||null,content:e.content||"",description:e.description||null,html_content:e.html_content||null,image_url:e.image_url||null,video_url:e.video_url||null,audio_url:e.audio_url||null,source_url:e.source_url||null,ai_description:e.ai_description||null,metadata:{...n,_explore_match:{candidate_source:"algorithm_v2_tag_lane",source_reasons:["algorithm_v2","tag_lane","taste"],label:o,evidence:{reason_code:"because_taste_match",reason_label:o,primary_label:o,primary_group:"tags",primary_value:r.value,matched_facets:a,support_matches:a,top_match:a[0],source:"search_public_explore_echoes",result_origin:e.result_origin||"tag_lane",feed_position:t,bucket:"taste"}},_explore_feed_v2:{batch_id:"tag-lane-fallback",position:t,bucket:"taste",score:r.weight,freshness_bucket:"tag_lane",reason_code:"because_taste_match",reason_label:o,card_data_source:"client_tag_lane"}},hearts:Number(e.hearts||0),watch_count:Number(e.watch_count||0),created_at:e.created_at||(new Date).toISOString(),deleted_at:e.deleted_at||null,source_board_id:e.source_board_id||e.board_id||null,source_board_name:e.source_board_name||e.board_name||null,source_board_owner_id:e.source_board_owner_id||e.added_by||e.curator_id||null,source_board_owner:l,source_board_owner_full_name:u,source_board_owner_avatar:i,added_by:e.added_by||e.curator_id||null,added_by_id:e.added_by||e.curator_id||null,added_by_username:e.added_by_username||e.curator_username||null,added_by_full_name:e.added_by_full_name||e.curator_full_name||null,added_by_avatar:e.added_by_avatar||e.curator_avatar||e.owner_avatar||null,owner_username:l,owner_full_name:u,owner_avatar:i,feed_rank:`tag-lane-${String(t).padStart(8,"0")}`}})(e,r,Dt.length+t+n+1)),null==k?void 0:k.id,Cr(null==k?void 0:k.id));let o=0;return 0===n.length?0:(Ft(e=>{const r=new Map(e.map(e=>[e.id,e]));return n.forEach(e=>{_r(r.get(e.id),e)&&(r.set(e.id,e),o+=1)}),Array.from(r.values())}),o>0&&(Ut(!0),nn(null),Sr.current=!1),o)})(a,r,t)}catch(n){return rt.current[r.value]=t+24,0}}))).reduce((e,r)=>e+r,0)})().finally(()=>{rn(!1),tt.current=null});return tt.current=r,r},[Dt.length,qn,qt,null==k?void 0:k.id]);const Jn=r.useCallback(async e=>{const r="low_watermark"!==e;if(!Pn||r&&Xt)return;if(Jr(Pn))return;if(nr.current)return;const t=`${Pn}:${e}:${Dt.length}`;if("manual"!==e&&"low_watermark"!==e&&je.current.has(t))return;nr.current=!0,R(je.current,t,64),r&&Zt(!0),nn(null);const n=window.setTimeout(()=>{"low_watermark"===e&&(Sr.current=!0),r&&Zt(!1)},22500);try{"initial"!==e&&"manual"!==e||await qn().catch(e=>{});const r=Math.max(ln,Number((null==jn?void 0:jn.item_count)||0),yt.current,Gt||0),t="low_watermark"===e||"empty_page"===e?r+ye:Math.max(180,r+ve);let n=0;if("initial"!==e&&"manual"!==e&&"empty_page"!==e||(n=await Gn(e,t)),n<ve&&await zn(e).catch(e=>0),n<ve){const e=performance.now(),{data:r,error:o}=await Oe(h.rpc("refill_explore_feed_v2_batch",{p_batch_id:Pn,p_target_count:t}),2e4,"Explore Feed v2 refill");if(Mn(r=>({...r,refillMs:Math.round(performance.now()-e)})),o)throw o;if(Be.current!==Pn)return;n+=Math.max(0,Number(r||0))}un(e=>Math.max(e,r+n,e+n,Dt.length+n)),"manual"===e||n>=ve?Sr.current=!1:"low_watermark"===e&&0===n&&(Sr.current=!0),Ut(n>0||Dt.length>
20),ke.current.delete(`${Pn}:0`),0===Dt.length&&(Jt(null),Dn(null)),n<ve&&0===Dt.length&&0===Math.max(ln,Number((null==jn?void 0:jn.item_count)||0))&&(Sr.current=!1,Gn(e,ye).then(e=>{e>0&&(Ut(!0),un(r=>Math.max(r,e)),ke.current.delete(`${Pn}:0`),Dn(null))}))}catch(o){const e=De(o);if(e&&/batch not found/i.test(e))return void $n({clearRendered:0===Dt.length});if(Fe(e)){nn(null),Ut(!0);const e=Gt??null;return Pn&&ke.current.delete(`${Pn}:${e??0}`),void window.setTimeout(()=>{Dn(e)},250)}Dt.length>0&&e&&/statement timeout|timed out/i.test(e)||nn(e)}finally{nr.current=!1,window.clearTimeout(n),r&&Zt(!1)}},[null==jn?void 0:jn.item_count,Pn,Xt,ln,Dn,Dt.length,Gt,$n,qn,Gn,zn]);r.useEffect(()=>{!Pn||In.isLoading||In.error||Jr(Pn)||(0!==Number((null==jn?void 0:jn.item_count)||0)||0!==Dt.length?0!==Dt.length||Yt||Dn(null):Jn("initial"))},[null==jn?void 0:jn.item_count,Pn,In.error,In.isLoading,Yt,Dn,Dt.length,Jn]),r.useEffect(()=>{if(!Pn||Yt||null!==Gt)return;if(Jr(Pn))return;if(Math.max(ln,Number((null==jn?void 0:jn.item_count)||0))<=0||0===Dt.length)return;const e=`${Pn}:0`;ke.current.has(e)||Dn(null)},[null==jn?void 0:jn.item_count,Pn,Yt,ln,Dn,Dt.length,Gt]),r.useEffect(()=>{if(!Pn||Xt||Sr.current)return;if(Jr(Pn))return;const e=Math.max(Gt||0,yt.current,Dt.length),r=Math.max(ln,Number((null==jn?void 0:jn.item_count)||0),e),t=Math.max(0,r-e);Dt.length>0&&(t<500||!Wt)&&Jn("low_watermark")},[null==jn?void 0:jn.item_count,Pn,Wt,Xt,ln,Dt.length,Gt,Jn]),r.useEffect(()=>{if(!Pn||!Wt||null===Gt)return;if(Yt||nt.current)return;const e=Bn(Pn),r=()=>se(e,Bn(Pn)),n=Le(dn,Pn,Gt,e.mode,"semantic"===e.mode?Mt.current:null,"semantic"===e.mode?At.current:null,"public"===e.mode?It.current:null,"public"===e.mode?Nt.current:null);if(n.filter(e=>e.memories.length>0).length>=6||n.length>=8)return;const o=n[n.length-1];if(o&&!o.hasMore)return;const a="number"==typeof(null==o?void 0:o.nextCursor)?o.nextCursor:Gt;if(null===a)return;const l=ie(e,a);if(nt.current===l)return;if(n.some(e=>e.cursor===a))return;const u=[...Dt,...qr(n,Pn)],i="public"===e.mode?(null==o?void 0:o.nextPublicCursor)||Nt.current:null;let s=!1;const c=window.setTimeout(()=>{s=!0,nt.current=l,t.startTransition(()=>{wn(!0),hn(null)});const o="public"===e.mode?(async()=>{const e=await rr(Number(a||0),ve,null==k?void 0:k.id,{preferredSource:It.current,cursor:i}),r=new Set([...Array.from(Er(null==k?void 0:k.id)),...u.map(e=>e.id)]);return{rows:e,memories:gr(e,null==k?void 0:k.id,r)}})():"semantic"===e.mode?(async()=>{const e=await Pr({offset:Number(a||0),limit:20,userId:null==k?void 0:k.id,currentMemories:u,includeSeenHistory:!0,viewerIsInternal:Ce,preferredSource:Mt.current,generationId:At.current,timeoutMs:xe,label:"Explore Feed v2 buffered semantic page"}),r=Cr(null==k?void 0:k.id);return{rows:e,memories:gr(e,null==k?void 0:k.id,r)}})():(async()=>{const e=await Oe(h.rpc("get_explore_feed_v2_page",{p_batch_id:Pn,p_after_position:a,p_limit:ve}),xe,"Explore Feed v2 buffered page");if(null==e?void 0:e.error)throw e.error;const r=Array.isArray(null==e?void 0:e.data)?e.data:[];return{rows:r,memories:gr(r,null==k?void 0:k.id,Cr(null==k?void 0:k.id))}})();Promise.resolve(o).then(o=>{var l,u;if(!r())return;const s=o.rows,c=o.memories;if("semantic"===e.mode&&s.some(e=>!0===e.reset_required))return nt.current=null,wn(!1),ke.current.delete(`${Pn}:${a??0}`),void Dn(a,{force:!0});const d="queue"===e.mode?vr(s,a):me(s,Number(a||0)),m="public"===e.mode?"keyset-v2"===tr(s)?Boolean(null==(l=s[s.length-1])?void 0:l.has_more)&&null!==or(s):s.length>=ve&&null!==d:"semantic"===e.mode?Ve(s,20):Boolean(null==(u=s[s.length-1])?void 0:u.has_more),f="semantic"===e.mode?Ye(s)||Mt.current:null,_="semantic"===e.mode?Xe(s)||At.current:null,p={batchId:Pn,mode:e.mode,semanticSource:f,semanticGenerationId:_,publicSource:"public"===e.mode?tr(s)||It.current:null,publicCursor:"public"===e.mode?i:null,nextPublicCursor:"public"===e.mode?or(s):null,cursor:a,nextCursor:d,hasMore:m,memories:c,savedAt:Date.now()};t.startTransition(()=>{mn(r=>{const t=Ht.current;if("number"==typeof t&&Number(a||0)<t)return r;if(r.some(r=>r.batchId===Pn&&r.mode===e.mode&&("semantic"!==e.mode||r.semanticSource===p.semanticSource)&&("semantic"!==e.mode||"runway-v2"!==p.semanticSource||r.semanticGenerationId===p.semanticGenerationId)&&("public"!==e.mode||r.publicSource===p.publicSource)&&("public"!==e.mode||"ke
2yset-v2"!==p.publicSource||te(r.publicCursor,p.publicCursor))&&r.cursor===a))return r;const o=[...r.filter(e=>e.batchId!==Pn),...n.filter(e=>e.cursor!==a),p].sort((e,r)=>Number(e.cursor||0)-Number(r.cursor||0)).slice(0,8);return Gr(null==k?void 0:k.id,o),o})})}).catch(e=>{if(!r())return;const n=De(e)||"Prefetch failed";t.startTransition(()=>hn(n))}).finally(()=>{nt.current===l&&(nt.current=null,t.startTransition(()=>wn(!1)))})},"queue"===e.mode?250:0);return()=>{window.clearTimeout(c),s||nt.current!==l||(nt.current=null,wn(!1))}},[Pn,Ce,Bn,Wt,Yt,vn,Dn,Dt,Gt,dn,null==k?void 0:k.id]),r.useEffect(()=>{if(!Pn||0===Dt.length||Xt||Sr.current)return;if(Jr(Pn))return;const e=Math.max(Gt||0,yt.current,Dt.length),r=Math.max(ln,Number((null==jn?void 0:jn.item_count)||0),e);Math.max(0,r-e)>=ye||Gn("low_watermark",e+ye).then(r=>{r>0&&(Ut(!0),un(t=>Math.max(t,e+r)))})},[null==jn?void 0:jn.item_count,Pn,Xt,ln,Dt.length,Gt,Gn]),r.useEffect(()=>{!Pn||Xt||Yt||Wt||0===Dt.length||Jr(Pn)||(Sr.current=!1,Jn("low_watermark"))},[Pn,Wt,Yt,Xt,Dt.length,Jn]),r.useEffect(()=>{if(!Pn||Xt||Yt||Wt||0===Dt.length)return;if(Jr(Pn))return;if(Dt.length>=1e3)return;const e=Gt??yt.current,r=Math.max(ln,Number((null==jn?void 0:jn.item_count)||0),e)+ye,t=`${Pn}:${e}:${r}:${Dt.length}`;xt.current.has(t)||(R(xt.current,t,96),Sr.current=!1,Gn("low_watermark",r).then(r=>{if(r>0)return Ut(!0),nn(null),Pn&&ke.current.delete(`${Pn}:${e??0}`),void Dn(e);Jn("low_watermark")}))},[null==jn?void 0:jn.item_count,Pn,Wt,Yt,Xt,ln,Dn,Dt.length,Gt,Jn,Gn]),r.useEffect(()=>{!Pn||Xt||Yt||tn||Jr(Pn)||Dt.length>0||null===Sn.pageMs||Sn.lastRowsReturned>0||Jn("empty_page")},[Pn,Yt,Xt,Dt.length,tn,Jn,Sn.lastRowsReturned,Sn.pageMs]),r.useEffect(()=>{if(!Pn||Xt||Yt||tn)return;if(Jr(Pn))return;if(Dt.length>0)return;if(null===Sn.pageMs||0===Sn.lastRowsReturned||Sn.lastRowsAccepted>0)return;if(Wt&&null!==Gt)return void Dn(Gt);Sr.current=!1;const e=Math.max(ln,Number((null==jn?void 0:jn.item_count)||0),yt.current,Gt||0)+ye;Gn("empty_page",e).then(e=>{if(e>0)return Ut(!0),nn(null),Pn&&ke.current.delete(`${Pn}:${Gt??0}`),void Dn(Gt);Jn("empty_page")})},[null==jn?void 0:jn.item_count,Pn,Wt,Yt,Xt,ln,Dn,Dt.length,Gt,tn,Jn,Gn,Sn.lastRowsAccepted,Sn.lastRowsReturned,Sn.pageMs,qt.length]),r.useEffect(()=>{const e=ot.current,r=at.current,t=lt.current,n=ut.current,o=()=>{if(!it.current||null!==st.current||ct.current>=3)return;const e=500*2**ct.current;ct.current+=1,st.current=window.setTimeout(()=>{st.current=null,it.current&&Rn(e=>e+1)},e)},a=()=>{it.current&&Ft(e=>{const o=((e,r,t,n)=>{let o=!1;const a=e.map(e=>{const a="string"==typeof e.source_board_owner?e.source_board_owner.trim():"",l="string"==typeof e.owner_username?e.owner_username.trim():"",u="string"==typeof e.added_by_username?e.added_by_username.trim():"",i=e.source_board_id&&r.get(e.source_board_id)||null,s=(i?t.get(i):null)||(e.source_board_owner_id&&Qr(e.source_board_owner_id)?t.get(e.source_board_owner_id):null)||(a?n.get(a.toLowerCase()):null)||null,c=(e.user_id&&Qr(e.user_id)?t.get(e.user_id):null)||(l?n.get(l.toLowerCase()):null)||null,d=(e.added_by_id&&Qr(e.added_by_id)?t.get(e.added_by_id):null)||(e.added_by&&Qr(e.added_by)?t.get(e.added_by):null)||(u?n.get(u.toLowerCase()):null)||null;if(!s&&!c&&!d)return e;const m={source_board_owner_id:(null==s?void 0:s.id)||e.source_board_owner_id||null,source_board_owner:(null==s?void 0:s.username)||e.source_board_owner||null,source_board_owner_full_name:(null==s?void 0:s.fullName)||e.source_board_owner_full_name||null,source_board_owner_avatar:(null==s?void 0:s.avatarUrl)||e.source_board_owner_avatar||null,owner_username:(null==c?void 0:c.username)||e.owner_username||null,owner_full_name:(null==c?void 0:c.fullName)||e.owner_full_name||null,owner_avatar:(null==c?void 0:c.avatarUrl)||e.owner_avatar||null,added_by_username:(null==d?void 0:d.username)||e.added_by_username||null,added_by_full_name:(null==d?void 0:d.fullName)||e.added_by_full_name||null,added_by_avatar:(null==d?void 0:d.avatarUrl)||e.added_by_avatar||null};return Object.entries(m).some(([r,t])=>e[r]!==t)?(o=!0,{...e,...m}):e});return o?a:e})(e,r,t,n);return o!==e&&(Ot.current=o),o})};a();const l=Array.from(new Set(Dt.filter(e=>!Qr(e.source_board_owner_id)).map(e=>e.source_board_id).filter(e=>Qr(e)))),u=l.filter(t=>!r.has(t)&&!e.has(`board:${t}`)),i=Array.from(new Set([...Dt.flatMap(e=>[e.source_board_owner&&e.source_board_owner_avatar?null:e.source_board_owner_id,e.added_by_username&&e.added_by_avatar?null:e.added_by_id||e.added_by,e.owner_username&&e.owner_avatar?null:e.user_id]),...l.map(e=>r.get(e)||null)].filter(e=>Qr(e)))).filter(r=>!t.has(r)&&!e.has(`profile-id:${r}`)),s=Array.from(new Set(Dt.flatMap(e=>[e.source_board_owner_avatar?null:e.source_board_owner,e.owner_avatar?null:e.owner_username,e.added_by_avatar?null:e.added_by_username]).map(e=>
2"string"==typeof e?e.trim():"").filter(Boolean))).filter(r=>!n.has(r.toLowerCase())&&!e.has(`profile-username:${r.toLowerCase()}`));0===u.length&&0===i.length&&0===s.length||(u.forEach(r=>e.add(`board:${r}`)),(async()=>{let c=!1;if(u.length>0){const{data:t,error:n}=await h.from("boards").select("id, user_id").in("id",u);!n&&Array.isArray(t)?t.forEach(e=>{Qr(null==e?void 0:e.id)&&Qr(null==e?void 0:e.user_id)&&r.set(String(e.id),String(e.user_id))}):n&&(c=!0,u.forEach(r=>e.delete(`board:${r}`)))}const d=Array.from(new Set([...i,...l.map(e=>r.get(e)||null)].filter(e=>Qr(e)))).filter(r=>!t.has(r)&&!e.has(`profile-id:${r}`)),m=s.filter(r=>!n.has(r.toLowerCase())&&!e.has(`profile-username:${r.toLowerCase()}`)),f=[];if(d.length>0){const r=d.map(e=>`profile-id:${e}`);r.forEach(r=>e.add(r)),f.push({keys:r,request:h.from("profiles").select("id, username, full_name, avatar_url").in("id",d)})}if(m.length>0){const r=m.map(e=>`profile-username:${e.toLowerCase()}`);r.forEach(r=>e.add(r)),f.push({keys:r,request:h.from("profiles").select("id, username, full_name, avatar_url").in("username",m)})}const _=await Promise.all(f.map(async({keys:r,request:t})=>{const n=await Promise.resolve(t).catch(e=>({data:null,error:e}));return n.error&&(c=!0,r.forEach(r=>e.delete(r))),n}));it.current&&(_.flatMap(e=>Array.isArray(e.data)&&!e.error?e.data:[]).forEach(e=>{const r={id:e.id||null,username:e.username||null,fullName:e.full_name||null,avatarUrl:e.avatar_url||null};r.id&&t.set(r.id,r),r.username&&n.set(r.username.toLowerCase(),r)}),a(),c?o():ct.current=0)})().catch(r=>{e.clear(),o()}))},[En,Dt]),r.useEffect(()=>{if(!Pn||0===Dt.length||Dt.length>=ge)return;if(Yt||Xt||en)return;if(vt.current>=4)return;vt.current+=1;const e=Hr(Pn,St.current),r=dn.find(r=>r.batchId===Pn&&(!r.mode||r.mode===e)&&("semantic"!==e||r.semanticSource===Mt.current)&&("semantic"!==e||"runway-v2"!==Mt.current||r.semanticGenerationId===At.current)&&("public"!==e||!It.current||r.publicSource===It.current)&&("public"!==e||Te(r,It.current,Nt.current))&&r.cursor===Gt);if(r&&On(r)>0)return;if(Wt&&null!==Gt)return void Dn(Gt);if(Jr(Pn))return;const t=Math.max(ln,Number((null==jn?void 0:jn.item_count)||0),yt.current,Gt||0)+ye;Gn("low_watermark",t).then(e=>{if(e>0)return Ut(!0),Pn&&ke.current.delete(`${Pn}:${Gt??0}`),void Dn(Gt);Jn("low_watermark")})},[null==jn?void 0:jn.item_count,Pn,On,Wt,Yt,Xt,en,ln,Dn,Dt.length,Gt,dn,Jn,Gn]),r.useEffect(()=>{if(!(null==k?void 0:k.id)||0===Dt.length||$t.current)return;const e=((e,r)=>hr(e,r).filter(cr))(Dt,k.id),r=e.length>0?e:wr(Dt,k.id,!0);0!==r.length&&(Mr(k.id,r),r.length<Math.min(20,we)||((e,r)=>{const t=We();if(t&&0!==r.length)try{const n={savedAt:Date.now(),memories:r.slice(0,20)};if(t===window.localStorage)return void T(z(e||null),n);const o=JSON.stringify(n);e?t.setItem(z(e),o):t.setItem(z(null),o)}catch{}})(k.id,r))},[Dt,null==k?void 0:k.id]);const Hn=r.useMemo(()=>Dt.reduce((e,r)=>{const t=(e=>{var r,t;if(!sr(e))return 0;const n=Number((null==(t=null==(r=e.metadata)?void 0:r._explore_feed_v2)?void 0:t.position)||0);return Number.isFinite(n)?n:0})(r);return Math.max(e,t)},0),[Dt]);r.useEffect(()=>{!Pe.current&&Dt.length>=24&&(Pe.current=Dt.slice(0,24).map(e=>e.id))},[Dt]),r.useEffect(()=>{!Pn||Hn<=0||(yt.current=Hn,Jr(Pn)||(Jt(e=>"number"==typeof e?Math.max(e,Hn):Hn),un(e=>Math.max(e,Hn))))},[Pn,Hn]);const Wn=r.useMemo(()=>de?Dt.reduce((e,r)=>{var t,n;const o=String((null==(n=null==(t=r.metadata)?void 0:t._explore_feed_v2)?void 0:n.bucket)||"unknown");return e[o]=(e[o]||0)+1,e},{}):Kr,[Dt,de]),Un=r.useMemo(()=>de?Dt.slice(0,60).reduce((e,r)=>{const t=Ur(r);return e[t]=(e[t]||0)+1,e},{}):Kr,[Dt,de]),Qn=r.useMemo(()=>de?Dt.slice(0,120).reduce((e,r)=>{const t=Vr(r);return e[t]=(e[t]||0)+1,e},{}):Kr,[Dt,de]),Vn=r.useMemo(()=>de?Dt.slice(0,120).reduce((e,r)=>{var t,n,o;const a=null==(o=null==(n=null==(t=r.metadata)?void 0:t._explore_match)?void 0:n.evidence)?void 0:o.matched_facets;return Array.isArray(a)?(a.forEach(r=>{const t="string"==typeof(null==r?void 0:r.group)&&r.group?r.group:"unknown";e[t]=(e[t]||0)+1}),e):e},{}):Kr,[Dt,de]),Yn=r.useMemo(()=>de?Dt.slice(0,120).reduce((e,r)=>{var t,n,o;const a=null==(o=null==(n=null==(t=r.metadata)?void 0:t._explore_match)?void 0:n.evidence)?void 0:o.penalties;
2return a&&"object"==typeof a?(Object.entries(a).forEach(([r,t])=>{(!0===t||"number"==typeof t&&t>0)&&(e[r]=(e[r]||0)+1)}),e):e},{}):Kr,[Dt,de]),Kn=r.useMemo(()=>de?Dt.slice(0,120).reduce((e,r)=>{var t,n,o;const a=null==(o=null==(n=null==(t=r.metadata)?void 0:t._explore_match)?void 0:n.evidence)?void 0:o.score_breakdown;if(!a||"object"!=typeof a)return e;const l=Number(a.profile_match_score||0)>0,u=Number(a.semantic_profile_score||0)>0,i=Number(a.quality_score||0)>=.45,s=String(a.freshness_bucket||"");return l&&(e.profile=(e.profile||0)+1),u&&(e.semantic=(e.semantic||0)+1),i&&(e.quality=(e.quality||0)+1),"fresh_24h"!==s&&"fresh_7d"!==s||(e.fresh=(e.fresh||0)+1),e},{}):Kr,[Dt,de]),Xn=r.useMemo(()=>de?Dt.reduce((e,r)=>{var t,n;const o=String((null==(n=null==(t=r.metadata)?void 0:t._explore_feed_v2)?void 0:n.card_data_source)||"unknown");return e[o]=(e[o]||0)+1,e},{}):Kr,[Dt,de]),Zn=r.useMemo(()=>{var e,r,t;if(!de)return{ids:Xr,weights:Xr};const n=null==(t=null==(r=null==(e=Dt[0])?void 0:e.metadata)?void 0:r._explore_match)?void 0:t.evidence;return{ids:Array.isArray(null==n?void 0:n.algorithm_seed_ids)?n.algorithm_seed_ids:[],weights:Array.isArray(null==n?void 0:n.algorithm_seed_weights)?n.algorithm_seed_weights:[]}},[Dt,de]),eo=r.useMemo(()=>de?Dt.slice(0,120).filter(e=>{const r=Ur(e).toLowerCase();return"unknown"===Vr(e)||"facet match"===r||"for you"===r}).length:0,[Dt,de]),ro=!Pe.current||Pe.current.every((e,r)=>{var t;return(null==(t=Dt[r])?void 0:t.id)===e}),to=r.useMemo(()=>de?E(null==k?void 0:k.id):Zr,[An,de,null==k?void 0:k.id]);r.useEffect(()=>{if(!de)return;const e=()=>Cn(e=>e+1);return window.addEventListener("echoExploreViewed",e),window.addEventListener("storage",e),()=>{window.removeEventListener("echoExploreViewed",e),window.removeEventListener("storage",e)}},[de]);const no=0===Dt.length&&Boolean(Pn)&&!tn&&(Yt||Xt||en||null!==Sn.pageMs&&0===Sn.lastRowsAccepted&&null===Sn.refillMs||Wt&&null!==Sn.pageMs&&0===Sn.lastRowsAccepted),oo=Jr(Pn),ao=In.isLoading||no,lo=tn||De(In.error),uo=Fe(lo),io=Boolean(lo)&&0===Dt.length,so=Boolean(oo&&!lo&&In.isSuccess&&!In.isFetching&&!Yt&&!Xt&&0===Dt.length&&(0===Number((null==jn?void 0:jn.item_count)||0)||0===Sn.lastRowsAccepted)),[co,mo]=r.useState(!1),fo=0===Dt.length&&!io&&!so,_o=r.useMemo(()=>{if(!de)return et;const e=oo?Math.max(Gt||0,0):Math.max(Gt||0,Hn,Dt.length),r=oo?Math.max(ln,e):Math.max(ln,Number((null==jn?void 0:jn.item_count)||0),e),t=Number(Xn.queue||0),n=Number(Xn.fallback_join||0),o=Number(Xn.semantic_anchor||0),a=Dt.filter(sr).length,l=Le(dn,Pn,Gt,Hr(Pn,St.current),"semantic"===Hr(Pn,St.current)?Mt.current:null,"semantic"===Hr(Pn,St.current)?At.current:null,"public"===Hr(Pn,St.current)?It.current:null,"public"===Hr(Pn,St.current)?Nt.current:null),u=l.reduce((e,r)=>e+r.memories.length,0),i=Math.max(0,r-e),s=Dt.length-new Set(Dt.map(e=>e.id)).size,c=Dt.filter(e=>!ur(e)||!fr(e)||pr(e,null==k?void 0:k.id)).length,d=Dt.filter(e=>to.has(e.id)).length,m=to.size,f=Math.max(0,Number(bn.seen||0),Number(Sn.lastRowsDropped||0));return{consumedPosition:e,preparedCount:r,queueRemaining:i,readyAheadCount:i+u,nextBatchStatus:vn?"loading":u>0?`${u} ready`:pn?"retrying":Wt&&null!==Gt?"not loaded":"not ready",queueBackedRendered:a,queueCardCount:t,fallbackJoinCount:n,semanticAnchorCount:o,bufferedReadyCount:u,bufferedPageCount:l.length,bufferedPageCursors:l.map(e=>e.cursor),cacheRestoredCount:sn,firstPaintCacheReadyCount:Math.min(20,Math.max(Dt.length,sn)),duplicateCount:s,invalidCount:c,localSeenRenderedCount:d,hiddenTotalCount:m,skippedLastFetchCount:f,lastRowsReturned:Sn.lastRowsReturned,lastRowsAccepted:Sn.lastRowsAccepted,lastRowsDropped:Sn.lastRowsDropped,batchMs:Sn.batchMs,pageMs:Sn.pageMs,refillMs:Sn.refillMs}},[null==jn?void 0:jn.item_count,sn,Xn,bn.seen,ln,to,Hn,Dt,Pn,Gt,dn,Wt,vn,oo,pn,Sn.batchMs,Sn.lastRowsAccepted,Sn.lastRowsDropped,Sn.lastRowsReturned,Sn.pageMs,Sn.refillMs,null==k?void 0:k.id,de]),po=r.useMemo(()=>{const e=_o.bufferedReadyCount>0,r=In.isLoading||Yt||vn||Xt;return{statusLabel:e?"Next page ready":vn?"Warming next page":In.isLoading?"Loading first page":Wt&&null!==Gt?"Next page not ready":"No next page",activelyLoading:r,nextReady:e}},[In.isLoading,Wt,_o.bufferedReadyCount,Yt,vn,Xt,Gt]);r.useEffect(()=>{if(!de)return;const e=Jr(Pn),r=e?Math.max(Gt||0,0):Math.max(Gt||0,Hn,Dt.length),t=e?Math.max(ln,r):Math.max(ln,Number((null==jn?void 0:jn.item_count)||0),r),n={monitor:{activelyLoading:po.activelyLoading,displayedCount:Dt.length,hasMore:Wt,nextCursor:Gt,pageCount:_o.bufferedPageCount,readyCount:_o.bufferedReadyCount,route:"/explorefeed2",source:"explorefeed2",status:po.nextReady?"ready":po.activelyLoading?"warming":Wt&&null!==Gt?"idle":"unavailable",statusLabel:po.statusLabel},route:"/explorefeed2",batchId:Pn,batchItemCount:t,queueRemainingEstimate:Math.max(0,t-r),queueConsumedPosition:r,refillLowWatermark:500,refillRunwaySize:ye,memoryCount:Dt.length,maxRenderedFeedPosition:Hn,nextCursor:Gt,hasMore:Wt,isLoadingBatch:In.isLoading,batchQueryStatus:In.status,batchQueryFetchStatus:In.fetchStatus,batchQueryEnabled:Boolean(k&&le),bootstrapStage:fn,dropDebug:bn,hasUser:Boolean(null==k?void 0:k.id),isAdminUser:Boolean(B||(null==N?void 0:N.is_admin)),isLoadingPage:Yt,isRefilling:Xt,isTagLaneLoading:en,isPrefetchingBufferedPage:vn,bufferedPageCount:dn.length,bufferedPageCursors:dn.map(e=>e.cursor),bufferedPageSizes:dn.map(e=>e.memories.length),lowWatermarkPaused:Sr.current,pageError:tn||De(In.error),bucketCounts:Wn,reasonCodeCounts:Qn,first120MatchedFacetCounts:Vn,first120PenaltyCounts:Yn,first120ScoreBreakdownCounts:Kn,cardDataSourceCounts:Xn,algorithmSeedIds:Zn.ids,algorithmSeedWeights:Zn.weights,first60LabelCounts:Un,topTagLanes:qt.slice(0,20),cacheRestoredCount:sn,passiveViewTracking:!0,impressionSource:"MemoryFeed viewport observer",prefetchTriggerCount:yn.triggerCount,lastPrefetchAt:yn.lastAt,lastPrefetchProgress:yn.lastProgress,lastPrefetchDistanceToBottom:yn.lastDistanceToBottom,lastPrefetchReason:yn.lastReason,lastPrefetchError:pn,genericReasonCount:eo,first24Ids:Dt.slice(0,24).map(e=>e.id),topIdsStable:ro,duplicateCount:Dt.length-new Set(Dt.map(e=>e.id)).size,ownMemoryCount:Dt.filter(e=>pr(e,null==k?void 0:k.id)).length,sourceBoardIdCount:Dt.filter(e=>Boolean(e.source_board_id)).length,localSeenRenderedCount:Dt.filter(e=>to.has(e.id)).length,invalidCount:Dt.filter(e=>!ur(e)||!fr(e)||pr(e,null==k?void 0:k.id)).length,timings:Sn,freshBatchOnReload:Re.current,batchRequestToken:on};return w(M,S,n),(_o.bufferedReadyCount>0||po.nextReady)&&y(A,n),()=>{x(M)}},[po.activelyLoading,po.nextReady,po.statusLabel,null==jn?void 0:jn.item_count,Pn,In.error,In.fetchStatus,In.isLoading,In.status,Wn,sn,Xn,Zn,Qn,eo,Wt,Yt,vn,Xt,en,ln,pn,Un,to,Vn,Hn,Dt,Gt,tn,Yn,Kn,Sn,qt,ro,on,fn,bn,yn,dn,le,B,null==N?void 0:N.is_admin,k,null==k?void 0:k.id,_o.bufferedPageCount,_o.bufferedReadyCount,de]);const ho=r.useCallback((e,r)=>{const t=new URLSearchParams;
2(r?[r]:C(e).slice(0,4)).forEach(e=>{const r=Ue[e.group],n=v(e.value);if(!r||!n)return;const o=t.get(r);t.set(r,o?`${o},${n}`:n)}),t.toString()&&W(`/explore?${t.toString()}`)},[W]),bo=r.useCallback(async e=>{try{const{error:r}=await h.rpc("set_explore_memory_feedback",{p_memory_id:e.id,p_board_id:e.source_board_id??null,p_feedback:"more_like_this"});if(r)throw r;L({title:"Explore will lean into this",description:"Echo will look for more results with this feel."}),qn().then(()=>Fn()).catch(e=>{})}catch(r){L({title:"Could not update Explore",description:"Try again in a moment.",variant:"destructive"})}},[qn,Fn,L]),go=r.useCallback(async e=>{try{const{error:r}=await h.rpc("set_explore_memory_feedback",{p_memory_id:e.id,p_board_id:e.source_board_id??null,p_feedback:"not_interested"});if(r)throw r;Mr(null==k?void 0:k.id,[e]),window.dispatchEvent(new CustomEvent("echo-feed-preserve-scroll",{detail:{excludeMemoryIds:[e.id],scope:{type:"surface",surfaceId:"explore-feed"}}})),Ft(r=>{const t=r.filter(r=>r.id!==e.id);return Ot.current=t,t}),L({title:"We’ll tune Explore",description:"Echo will show fewer results like this one."}),mn([]),Gr(null==k?void 0:k.id,[]),qn().then(()=>Fn()).catch(e=>{})}catch(r){L({title:"Could not update Explore",description:"Try again in a moment.",variant:"destructive"})}},[qn,Fn,L,null==k?void 0:k.id]),vo=r.useCallback(async e=>{try{((e,r)=>{const t=Br(e);t.add(r),$r(e,t)})(null==k?void 0:k.id,e);const r=We();null==r||r.removeItem(z(null==k?void 0:k.id)),null==r||r.removeItem(G(null==k?void 0:k.id)),mn([]);const t=Er(null==k?void 0:k.id),n=Ot.current.filter(r=>r.source_board_id===e||t.has(r.id)).map(e=>e.id);window.dispatchEvent(new CustomEvent("echo-feed-preserve-scroll",{detail:{excludeMemoryIds:n,scope:{type:"surface",surfaceId:"explore-feed"}}})),Ft(r=>{const n=r.filter(r=>r.source_board_id!==e&&!t.has(r.id));return Ot.current=n,n}),ke.current=new Set,Sr.current=!1;const{error:o}=await h.rpc("set_explore_board_feedback",{p_board_id:e,p_feedback:"not_interested"});if(o)throw o;L({title:"We’ll show less like this",description:"This board will be suppressed from your Explore feed."}),qn().then(()=>Fn()).catch(e=>{})}catch(r){L({title:"Could not update Explore",description:"Try again in a moment.",variant:"destructive"})}},[qn,Fn,L,null==k?void 0:k.id]),wo=r.useCallback(e=>{},[]),yo=r.useCallback(e=>{((e,r)=>{if(!r)return;const t=We();if(t)try{const n=[r,...Array.from(Ar(e)).filter(e=>e!==r)].slice(0,300),o=Je(e),a=Date.now(),l={savedAt:a,ids:n};Ie.set(o,{expiresAt:a+Ee,ids:n}),t===window.localStorage?T(o,l):t.setItem(o,JSON.stringify(l))}catch{}})(null==k?void 0:k.id,e.id),mn(r=>{const t=r.map(r=>({...r,memories:r.memories.filter(r=>r.id!==e.id)})).filter(e=>e.memories.length>0);return Gr(null==k?void 0:k.id,t),t})},[null==k?void 0:k.id]),xo=r.useCallback(()=>!Pn||(null==k?void 0:k.id)?Promise.resolve():(jt.current+=1,Pt.current=null,ke.current=new Set,Bt.current=new Set,nt.current=null,St.current=!0,Mt.current=null,At.current=null,It.current=null,Nt.current=null,mn([]),Gr(null==k?void 0:k.id,[]),wn(!1),Kt(!1),nn(null),Ut(!0),Jt(0),Ht.current=0,Dn(0,{force:!0}).then(()=>{})),[Pn,Dn,null==k?void 0:k.id]),So=r.useCallback(()=>{const e=Hr(Pn,St.current);if(tn)return nn(null),"semantic"===e&&(null==k?void 0:k.id)&&Qt?(Vt(!1),Fn()):(Pn&&ke.current.delete(`${Pn}:${Gt??0}`),Dn(Gt,{force:!0}).then(()=>{}));const r=r=>dn.find(t=>t.batchId===Pn&&(!t.mode||t.mode===e)&&("semantic"!==e||t.semanticSource===Mt.current)&&("semantic"!==e||"runway-v2"!==Mt.current||t.semanticGenerationId===At.current)&&("public"!==e||!It.current||t.publicSource===It.current)&&("public"!==e||Te(t,It.current,Nt.current))&&t.cursor===r);let t=Wt,n=Gt,o=0,a=r(n);for(;a&&o<8;){if(o+=1,On(a)>0)return Promise.resolve();t=a.hasMore,n=a.hasMore?a.nextCursor:null,a=t&&null!==n?r(n):void 0}if("semantic"===e&&(null==k?void 0:k.id)&&!t)return Qt?Promise.resolve():Fn();const l=ce({mode:e,sourceHasMore:t,nextCursor:n,hasOwnedBufferedPage:!1,canTransitionToPublic:"semantic"===e&&!(null==k?void 0:k.id),canRefillQueue:"queue"===e,queueLowWatermarkPaused:Sr.current});if("load-page"===l)return Pn&&ke.current.delete(`${Pn}:${n??0}`),Dn(n).then(()=>{});if("transition-to-public"===l)return xo();if("refill-queue"!==l)return Promise.resolve();Sr.current=!1;const u=n,i=Math.max(ln,Number((null==jn?void 0:jn.item_count)||0),yt.current,Gt||0)+ye;return Gn("low_watermark",i).then(e=>e>0?(Ut(!0),Pn&&ke.current.delete(`${Pn}:${u??0}`),Dn(u).then(()=>{})):Jn("low_watermark").then(()=>{}))},[null==jn?void 0:jn.item_count,Pn,On,Wt,ln,Dn,Gt,tn,dn,Jn,Gn,Fn,Qt,xo,null==k?void 0:k.id]),Mo=Hr(Pn,St.current),Ao=dn.some(e=>e.batchId===Pn&&(!e.mode||e.mode===Mo)&&("semantic"!==Mo||e.semanticSource===Mt.current)&&("semantic"!==Mo||"runway-v2"!==Mt.current||e.semanticGenerationId===At.current)&&("public"!==Mo||!It.current||e.publicSource===It.current)&&("public"!==Mo||Te(e,It.current,Nt.current))&&e.cursor===Gt),Co=Boolean(Pn)&&!tn&&!lo&&(Eo={mode:Mo,sourceHasMore:Wt,nextCursor:Gt,hasOwnedBufferedPage:Ao,canTransitionToPublic:"semantic"===Mo&&!(null==k?void 0:k.id),canRefillQueue:"queue"===Mo,queueLowWatermarkPaused:Sr.current},null!==ce(Eo)||Boolean((null==k?void 0:k.id)&&"semantic"===Mo&&!Qt));var Eo;const Ro=r.useCallback(()=>{So()},[So]);return r.useEffect(()=>{!Pn||lo||ao||Dt.length>0||Jr(Pn)||Yt||Xt||en||(Ut(!0),Jn("empty_page"))},[Pn,lo,ao,Yt,Xt,en,Dt.length,Jn]),le?n.jsxs(n.Fragment,{children:[e?null:n.jsx(pe,{title:"Explore Feed v2",noindex:!0}),n.jsxs("div",{className:e?"contents":"app-screen min-h-screen bg-background pb-24",children:[!e&&k?n.jsx("div",{className:"pointer-events-none fixed left-0 right-0 top-0 z-50",children:n.jsx(fe,{className:"pointer-events-auto"})}):e?null:n.jsx(_e,{subtitle:"Explore v2"}),n.jsxs("main",{ref:D,className:I("relative space-y-5",!e&&(k?"pt-[calc(6rem+env(safe-area-inset-top))]":"pt-[calc(8rem+env(safe-area-inset-top))]")),children:[n.jsx(o,{targetRef
2:D,onRefresh:Ln,timeoutMs:35e3,disabled:j||In.isFetching||Yt||Xt}),b?n.jsx("section",{className:"px-4 md:px-6",children:n.jsxs("div",{className:"mx-auto flex max-w-[1500px] flex-wrap items-center justify-between gap-3 rounded-lg border border-border/70 bg-background/85 px-4 py-3 shadow-sm backdrop-blur",children:[n.jsxs("div",{className:"flex min-w-fit items-center gap-2 text-sm font-semibold text-foreground",children:[n.jsx(K,{className:"h-4 w-4 text-primary"}),"For You v2"]}),n.jsxs("div",{className:"flex flex-1 flex-wrap items-center justify-center gap-1.5 text-[11px] font-medium text-muted-foreground",children:[n.jsxs("span",{className:"rounded-full border border-emerald-500/20 bg-emerald-500/10 px-2.5 py-1 text-emerald-700",children:["now ",Dt.length," cards · ",_o.semanticAnchorCount," semantic"]}),n.jsxs("span",{className:I("rounded-full border px-2.5 py-1",_o.bufferedReadyCount>0||vn?"border-violet-500/30 bg-violet-500/10 text-violet-700":"border-border/70 bg-muted/30"),children:["next ",_o.nextBatchStatus,_o.bufferedPageCount>0?` · ${_o.bufferedPageCount} page${1===_o.bufferedPageCount?"":"s"}`:""]}),n.jsxs("span",{className:"rounded-full border border-border/70 bg-muted/30 px-2.5 py-1",children:["cursor ",Gt??0]}),n.jsxs("span",{className:I("rounded-full border px-2.5 py-1",_o.hiddenTotalCount?"border-sky-500/30 bg-sky-500/10 text-sky-700":"border-border/70 bg-muted/30"),children:["hidden 90d ",_o.hiddenTotalCount]}),n.jsxs("span",{className:I("rounded-full border px-2.5 py-1",_o.skippedLastFetchCount?"border-amber-500/30 bg-amber-500/10 text-amber-700":"border-border/70 bg-muted/30"),children:["last fetch ",_o.lastRowsAccepted,"/",_o.lastRowsReturned," used",_o.skippedLastFetchCount?` · ${_o.skippedLastFetchCount} hidden/skipped`:""]}),n.jsxs("span",{className:I("rounded-full border px-2.5 py-1",_o.invalidCount||_o.duplicateCount||_o.localSeenRenderedCount?"border-rose-500/30 bg-rose-500/10 text-rose-700":"border-border/70 bg-muted/30"),children:["on page ",_o.invalidCount," invalid · ",_o.duplicateCount," dupes · ",_o.localSeenRenderedCount," viewed"]}),n.jsxs("span",{className:"rounded-full border border-border/70 bg-muted/30 px-2.5 py-1",children:["fetch ",_o.pageMs??_o.batchMs??"-","ms",null!==_o.refillMs?` · refill ${_o.refillMs}ms`:""]})]}),n.jsxs(f,{size:"sm",variant:"outline",className:"h-8 rounded-full",onClick:()=>{Tn()},children:[n.jsx(X,{className:"mr-1.5 h-3.5 w-3.5"}),"Fresh feed"]})]})}):null,fo?n.jsx(Yr,{}):so?n.jsxs("div",{className:"mx-auto flex max-w-lg flex-col items-center rounded-lg border border-border/70 bg-background px-6 py-10 text-center shadow-sm",children:[n.jsx("h2",{className:"text-lg font-semibold",children:"No new matches right now"}),n.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"Try again for more matches, or choose interests to guide your feed. Your saved preferences and viewed history stay in place."}),n.jsx(f,{className:"mt-5",onClick:Tn,children:"Try again"}),n.jsx(f,{variant:"outline",className:"mt-3",onClick:()=>{mo(!0)},children:"Choose interests"}),n.jsx(f,{variant:"outline",className:"mt-3",onClick:()=>W("/profile?tab=taste"),children:"My Algorithm"}),n.jsx(f,{variant:"ghost",className:"mt-2",onClick:()=>W("/explore?mode=new",{replace:!0}),children:"Browse New"}),co&&n.jsx(u,{enabled:!0,forceOpen:!0,userId:null==k?void 0:k.id,onDismiss:()=>mo(!1),onComplete:()=>{mo(!1),Tn()}})]}):io?n.jsxs("div",{className:"mx-auto flex max-w-lg flex-col items-center rounded-lg border border-destructive/20 bg-background px-6 py-10 text-center shadow-sm",children:[n.jsx("h2",{className:"text-lg font-semibold",children:uo?"Explore is taking a while":"Explore couldn’t load"}),n.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:uo?"Your personalized feed is taking longer than usual. You can try it again or browse New.":"Please try again. Your preferences and viewed history are safe."}),n.jsxs("div",{className:"mt-5 flex flex-wrap items-center justify-center gap-3",children:[n.jsx(f,{onClick:()=>{Tn()},children:"Try again"}),uo&&(null==k?void 0:k.id)?n.jsx(f,{variant:"outline",onClick:()=>{W("/explore?mode=new",{replace:!0})},children:"Browse New"}):null]})]}):n.jsx(t.Suspense,{fallback:n.jsx(Yr,{}),children:n.jsx(he,{memories:Dt,searchQuery:"",isLoading:!1,hasInitiallyLoaded:!0,onRetry:Ro,onLoadMore:So,hasMore:Co,isLoadingMore:Yt||Xt,loadingMoreIndicatorDelayMs:900,loadMoreError:tn,showEmptyState:!1,showFeedSettingsTrigger:!1,mutationSurfaceId:"explore-feed",applyOwnEch
2oExplorePreference:!0,performanceSurface:"explore_feed",waitForScrollBeforeAutoLoadMore:!0,hydrateOnOpen:"always",showAuthorAttribution:!0,showExploreMatchChips:!0,aiContentPreferenceAlreadyApplied:!0,columnPlacement:"balanced",onExploreMatchFilterClick:ho,onMemoryMoreLikeThis:k?bo:void 0,onMemoryNotInterested:k?go:void 0,onMemoryMediaUnavailable:yo,onNotInterested:k?vo:void 0,onReportMemory:k?wo:void 0})})]})]})]}):n.jsxs(n.Fragment,{children:[e?null:n.jsx(pe,{title:"Explore Feed v2",noindex:!0}),n.jsx("div",{className:I("px-4 py-16 text-center md:px-6",!e&&"app-screen min-h-screen bg-background"),children:n.jsxs("div",{className:"mx-auto max-w-md rounded-lg border border-border/70 bg-background/85 px-6 py-8 shadow-sm",children:[n.jsx("h1",{className:"text-lg font-semibold text-foreground",children:"Internal feed lab"}),n.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"This page is only available to admins."})]})})]})}export{rt as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.