@yuriai/web 0.3.2-beta.15 → 0.3.2-beta.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/dist/assets/{AgentAvatar-BzOcEUoS.js → AgentAvatar-DXNlk9SC.js} +1 -1
  2. package/dist/assets/{AssistantConversationSurface-Uot7OIYk.js → AssistantConversationSurface-B_1meRN3.js} +3 -3
  3. package/dist/assets/{AssistantSessionCard-1TQVLard.js → AssistantSessionCard-CM9eiUQW.js} +2 -2
  4. package/dist/assets/{AssistantUnreadBadge-hL6MbaaH.js → AssistantUnreadBadge-DuqMWEJd.js} +1 -1
  5. package/dist/assets/{AssistantView-Dyv1xxU2.js → AssistantView-CUU_tND6.js} +1 -1
  6. package/dist/assets/{DiagramView-D20kMzCZ.js → DiagramView-CdIerXpI.js} +1 -1
  7. package/dist/assets/{FadeInOnReveal-D3eUin-b.js → FadeInOnReveal--phLJx7J.js} +1 -1
  8. package/dist/assets/{GuiPluginPage-DA4wM2Ev.js → GuiPluginPage-WHqzeYBN.js} +1 -1
  9. package/dist/assets/{GuiPluginSurface-DUD4zzGY.js → GuiPluginSurface-DpON2M0k.js} +1 -1
  10. package/dist/assets/{GuiPluginWindow-DH9PaNLv.js → GuiPluginWindow-Dnr7qMZB.js} +1 -1
  11. package/dist/assets/{Icon-RGzME9hn.js → Icon-W44vi3ut.js} +1 -1
  12. package/dist/assets/{ImageLoadingPlaceholder-DfFaijIL.js → ImageLoadingPlaceholder-DOvReE-u.js} +1 -1
  13. package/dist/assets/{LoadingImage-C81TMCeu.js → LoadingImage-D04t7088.js} +1 -1
  14. package/dist/assets/{MarkdownRenderer-DMo1Znj3.js → MarkdownRenderer-DOaXMFGk.js} +2 -2
  15. package/dist/assets/{MarkdownRendererImpl-CCNOjLII.js → MarkdownRendererImpl-p6ByfX6o.js} +1 -1
  16. package/dist/assets/{MarkstreamRendererImpl-Clgt9ceq.js → MarkstreamRendererImpl-2aGrWpdb.js} +1 -1
  17. package/dist/assets/{MobileDetailNavigation-C4jx-32g.js → MobileDetailNavigation-D9_BtXYp.js} +1 -1
  18. package/dist/assets/{MobileResizableSheet-DrdGceem.js → MobileResizableSheet-BL79ETW4.js} +1 -1
  19. package/dist/assets/{MobileShareBridge-BTY3GYk0.js → MobileShareBridge-Bi7leSxt.js} +1 -1
  20. package/dist/assets/{MobileSurface-DvNuNZh9.js → MobileSurface-DUyIRQ6P.js} +1 -1
  21. package/dist/assets/{MultiRunWindow-WpaJ5PuX.js → MultiRunWindow-CHIDZEfZ.js} +1 -1
  22. package/dist/assets/{OnboardingScreen-CExqFpo7.js → OnboardingScreen-C46Ml9J4.js} +1 -1
  23. package/dist/assets/{OverlayScrollbar-V6sTSoqD.js → OverlayScrollbar-nj_TmhGR.js} +1 -1
  24. package/dist/assets/{RemoteAssistantSessionCard-CElTuysr.js → RemoteAssistantSessionCard-DMnPBDQC.js} +1 -1
  25. package/dist/assets/{SettingsView-C75-tcnH.js → SettingsView-UL7x3KxT.js} +1 -1
  26. package/dist/assets/{SettingsWindow-BCN8jnuO.js → SettingsWindow-xy1sQ4Zl.js} +1 -1
  27. package/dist/assets/{SetupTourDialog-BFccOdFN.js → SetupTourDialog-02ERwBTX.js} +1 -1
  28. package/dist/assets/{TerminalView-DC5D6Tn5.js → TerminalView-CiV6scwa.js} +1 -1
  29. package/dist/assets/{ToolOutputDialog-BOs3HYPC.js → ToolOutputDialog-DDaLqPQn.js} +1 -1
  30. package/dist/assets/{VoiceSettings-DPAqJ2XK.js → VoiceSettings-R6D6PHum.js} +1 -1
  31. package/dist/assets/{capgoAdapter-BvecNhGW.js → capgoAdapter-BMrtvL9D.js} +1 -1
  32. package/dist/assets/{checkbox-Cim5LAVq.js → checkbox-C-z5H4VQ.js} +1 -1
  33. package/dist/assets/{collapsible-D9TTgMWS.js → collapsible-CH_khfRp.js} +1 -1
  34. package/dist/assets/{context-menu-BXng4pmA.js → context-menu-uXRPBDi-.js} +1 -1
  35. package/dist/assets/{diagram-kKbfnx6q.js → diagram-CFO0Q4Br.js} +1 -1
  36. package/dist/assets/{dialog-xzBmheBR.js → dialog-CV8Bzfut.js} +1 -1
  37. package/dist/assets/{fileMentionTouchSelection-BzdQxbUd.js → fileMentionTouchSelection-BSxHcl0u.js} +1 -1
  38. package/dist/assets/{gitApi-DIxtL0wo.js → gitApi-EJZD6Dv_.js} +1 -1
  39. package/dist/assets/{input-2AT-WL0G.js → input-PkgQQFx5.js} +1 -1
  40. package/dist/assets/{insertionBoundaries-C_905LuX.js → insertionBoundaries-u--zEQHs.js} +1 -1
  41. package/dist/assets/{main-B5cE3xWa.js → main-Byy4UtMw.js} +2 -2
  42. package/dist/assets/{main-DMfK7-mV.js → main-IzFchYHG.js} +4 -4
  43. package/dist/assets/{markdownHeightCache-VT58IYRV.js → markdownHeightCache-DnLywwOt.js} +1 -1
  44. package/dist/assets/{mcpQueries-Cy73FieQ.js → mcpQueries-BMTgltyS.js} +1 -1
  45. package/dist/assets/{miniChat-Dx7bni4S.js → miniChat-CAjlEjFd.js} +2 -2
  46. package/dist/assets/{mobile-DPPD4h3P.js → mobile-BtqBvDL5.js} +2 -2
  47. package/dist/assets/{mobileBackNavigation-BSKfSZVx.js → mobileBackNavigation-DYpQc2ct.js} +1 -1
  48. package/dist/assets/{mobileConnections-C-97caJA.js → mobileConnections-B9Arv_oQ.js} +2 -2
  49. package/dist/assets/{multirun-B9dQRCJu.js → multirun-CdOQ8Qe6.js} +1 -1
  50. package/dist/assets/{native-config-DIGFHpiF.js → native-config-Cu_cIlq1.js} +1 -1
  51. package/dist/assets/{navigation-BqH7w8k6.js → navigation-DXpf27Bh.js} +1 -1
  52. package/dist/assets/{openRemoteProjectSession-DEUCz51d.js → openRemoteProjectSession-JQEnH-go.js} +1 -1
  53. package/dist/assets/{projectMeta-n_yR2IfR.js → projectMeta-CqLusEFg.js} +1 -1
  54. package/dist/assets/{pwa-pFzmmDsA.js → pwa-nvcXsAxW.js} +1 -1
  55. package/dist/assets/{queue-abort-optimistic-BKiCeb8W.js → queue-abort-optimistic-DvLlGvxm.js} +1 -1
  56. package/dist/assets/{react-Casi179K.js → react-Ci-oIthn.js} +1 -1
  57. package/dist/assets/{readiness-Cn6GJ2pJ.js → readiness--ecd9RJY.js} +2 -2
  58. package/dist/assets/{reference-history-ByfqEE3k.js → reference-history-bOkSOz0-.js} +1 -1
  59. package/dist/assets/{remoteSessionReference-D56hccpi.js → remoteSessionReference-DU2IVBrK.js} +1 -1
  60. package/dist/assets/{renderElectronMiniChatApp-CFFBlM11.js → renderElectronMiniChatApp-Dy-pJW00.js} +2 -2
  61. package/dist/assets/{renderMobileApp-B_BVk8VQ.js → renderMobileApp-BOHSBeJD.js} +4 -4
  62. package/dist/assets/{runtimeConfig-BskrN2gH.js → runtimeConfig-BecRvZnA.js} +1 -1
  63. package/dist/assets/{runtimeEndpointReset-OJQs3Ji5.js → runtimeEndpointReset-Bc7Jk4mE.js} +3 -3
  64. package/dist/assets/{select-CMPdA7Jz.js → select-CRkoZrUK.js} +1 -1
  65. package/dist/assets/{sessionLookup-DC57HXZJ.js → sessionLookup-aQmLeUeM.js} +1 -1
  66. package/dist/assets/{sortable-tabs-strip-CDuJ3SAL.js → sortable-tabs-strip-BXS9MK0M.js} +1 -1
  67. package/dist/assets/{speechSettingsQueries-Cb01W_rF.js → speechSettingsQueries-Dv68BBlS.js} +1 -1
  68. package/dist/assets/{textarea-Dd1TJka3.js → textarea-CV1fXH_Z.js} +1 -1
  69. package/dist/assets/{tooltip-JnhOGZST.js → tooltip-CRImppy1.js} +1 -1
  70. package/dist/assets/{types-CukQF3zY.js → types-DD4SVksq.js} +1 -1
  71. package/dist/assets/{useAppFontEffects-IARf1foL.js → useAppFontEffects-StA4i2fN.js} +5 -5
  72. package/dist/assets/{useDesktopWindowControlsLayout-qHhxNbBF.js → useDesktopWindowControlsLayout-BO0qb23z.js} +1 -1
  73. package/dist/assets/{useEffectiveDirectory-aRQ3KLec.js → useEffectiveDirectory-DO8VgCTH.js} +1 -1
  74. package/dist/assets/{useMobileNavigationStore-CRoFDKhN.js → useMobileNavigationStore-DW2W2RJB.js} +4 -4
  75. package/dist/assets/{usePluginsStore-Dn9fFq18.js → usePluginsStore-BoT2aCR0.js} +1 -1
  76. package/dist/assets/{useProjectRuntimeAPIs-CaH03MHY.js → useProjectRuntimeAPIs-Dp0d-EFT.js} +1 -1
  77. package/dist/assets/{useStreamingTextThrottle-uA3MhkdT.js → useStreamingTextThrottle-WIQCZqFR.js} +1 -1
  78. package/dist/index.html +5 -5
  79. package/dist/mini-chat.html +5 -5
  80. package/dist/mobile.html +1 -1
  81. package/package.json +1 -1
@@ -1,3 +1,3 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{t}from"./platform-CiUKDeXd.js";import{ot as n,st as r}from"./vendor-base-ui-fom6orB6.js";import{n as i}from"./vendor-react-D5BntRmA.js";import{E as a,V as o}from"./runtime-file-resource-CKQQEwNv.js";import{i as s,m as c,r as l}from"./vendor-reactuses-core-B8s-Rcd-.js";import{r as u}from"./useUIStore-DjizmHAt.js";import{i as d,o as f}from"./useMobileHtmlPreviewStore-DzzgY1eS.js";import{a as p,i as m,n as h,o as g,r as _,t as ee}from"./vendor-markstream-react-Cwc-VXWM.js";import{Cr as v,Rn as y}from"./useMobileNavigationStore-CRoFDKhN.js";import{t as te}from"./useThemeSystem-D2YBbLma.js";import{a as b,t as x}from"./vendor-framer-motion-DiGWHm7K.js";import{i as S,n as C,t as w}from"./tooltip-JnhOGZST.js";import{n as T}from"./useEffectiveDirectory-aRQ3KLec.js";import{o as E}from"./image-loading-Dlh4FIPJ.js";import{t as D}from"./LoadingImage-C81TMCeu.js";import{r as O}from"./FadeInOnReveal-D3eUin-b.js";import{r as ne,t as re}from"./markdownHeightCache-VT58IYRV.js";import{t as k}from"./useStreamingTextThrottle-uA3MhkdT.js";import{r as A,t as j}from"./MarkdownRendererImpl-CCNOjLII.js";import{n as M}from"./fileReferenceParser-1HHDBUum.js";import{a as N,c as P,f as F,h as I,i as ie,l as ae,m as L,o as R,s as oe,t as se}from"./fileReferenceActions-DLTUzjwi.js";var z=e(r(),1),B=i(),V=`img:not([data-md-link-favicon="true"])`,H=e=>e.getAttribute(`data-md-image-source`)??e.getAttribute(`src`)??``,ce=(e,t)=>{if(e.defaultPrevented||e.button!==0||e.altKey||e.shiftKey)return;let n=e.target;if(!(n instanceof Element))return;if(e.metaKey||e.ctrlKey){let e=n.closest(`a[href]`);if(!(e instanceof HTMLAnchorElement)||!I(e.getAttribute(`href`)??``))return}let r=n.closest(V);if(r instanceof HTMLImageElement&&t.onShowPopup){let n=e.currentTarget;if(!(n instanceof HTMLElement))return;let i=Array.from(n.querySelectorAll(V)).map(e=>({url:H(e),filename:e.alt||H(e)||void 0})).filter(e=>e.url),a=H(r),o=i.findIndex(e=>e.url===a);if(!a)return;e.preventDefault(),e.stopPropagation(),t.onShowPopup({open:!0,title:r.alt||a,content:``,previewSource:r,image:{url:a,...t.effectiveDirectory?{directory:t.effectiveDirectory}:{},filename:r.alt||a,gallery:i,index:o>=0?o:0}});return}if(t.fileReference){let r=n.closest(F);if(r instanceof HTMLElement){e.preventDefault(),e.stopPropagation(),R(r,t.fileReference);return}}let i=n.closest(`a[href]`);if(!(i instanceof HTMLAnchorElement))return;let a=i.getAttribute(`href`)??``;if(I(a)){e.preventDefault(),e.stopPropagation(),t.fileReference&&R(i,t.fileReference);return}if(!d(a))return;e.preventDefault(),e.stopPropagation();let o=(t.effectiveDirectory||``).trim();if(!v()&&o&&t.openInAppBrowser){t.openInAppBrowser(o,a);return}f(a)},le=(e,t)=>{if(e.key!==`Enter`&&e.key!==` `||!t.fileReference)return;let n=e.target;if(!(n instanceof Element))return;let r=n.closest(F);!(r instanceof HTMLElement)||r.getAttribute(`data-yuri-file-link`)!==`true`||(e.preventDefault(),e.stopPropagation(),R(r,t.fileReference))},ue=(e,t)=>{let n=t>=2?e.slice(t-2,t):``;return(t>=1?e.charAt(t-1):``)===`:`||n===`:/`},U=e=>{if(!e.includes(`/`)||!e.includes(`.`))return[{kind:`text`,value:e}];M.lastIndex=0;let t=[],n=0,r=M.exec(e);for(;r;){let i=r[0];if(!i||ue(e,r.index)||!L(i)){r=M.exec(e);continue}r.index>n&&t.push({kind:`text`,value:e.slice(n,r.index)}),t.push({kind:`path`,value:i}),n=r.index+i.length,r=M.exec(e)}return n===0?[{kind:`text`,value:e}]:(n<e.length&&t.push({kind:`text`,value:e.slice(n)}),t)},W=z.createContext({messageId:`markstream`,isStreaming:!1,disableStreamAnimation:!1,variant:`assistant`,enableFileReferences:!0}),G=()=>z.useContext(W),K=n(),de=24,q=4,fe=new Intl.Segmenter(void 0,{granularity:`grapheme`});function pe({node:e}){let t=G(),n=x(),r=t.isStreaming&&!t.disableStreamAnimation&&!n,i=e.content??``,a=z.useRef(i),o=z.useRef(i),s=z.useRef(null),c=z.useRef(new Map);return z.useLayoutEffect(()=>{let e=s.current;if(!e)return;let t=t=>{c.current.delete(t),t.parentNode===e&&(t.replaceWith(document.createTextNode(t.textContent??``)),e.normalize())},n=()=>{for(let[e,n]of c.current)n.stop(),t(e)};if(!r||!i.startsWith(o.current)){n(),e.textContent=i,o.current=i;return}let a=i.slice(o.current.length);if(o.current=i,!a)return;let l=Array.from(fe.segment(a),e=>e.segment),u=Math.max(0,l.length-96),d=[];for(let e=u;e<l.length;e+=q)d.push(l.slice(e,e+q).join(``));c.current.size+d.length>de&&n(),u>0&&e.appendChild(document.createTextNode(l.slice(0,u).join(``))),d.forEach((n,r)=>{let i=document.createElement(`span`);i.dataset.motionStreamChunk=``,i.textContent=n,i.style.opacity=`0`,e.appendChild(i);let a=b([i],{opacity:[0,1]},{duration:.16,delay:Math.min(r*.008,.08),ease:`easeOut`});c.current.set(i,a),a.then(()=>t(i))})},[i,r]),z.useLayoutEffect(()=>{let e=c.current;return()=>{for(let t of e.values())t.stop();e.clear()}},[]),(0,K.jsx)(`span`,{ref:s,className:y(`text-node whitespace-pre-wrap break-words`,e.center&&`text-node-center`),children:a.current})}var J=z.createContext({enabled:!1,insideLink:!1,isMobileSurface:!1,effectiveDirectory:``,preferRuntimeEditor:!1,slots:{used:0,limit:0}}),me=e=>{let t=(0,B.c)(14),{enabled:n,effectiveDirectory:r,editor:i,preferRuntimeEditor:a,onShowPopup:o,content:s,children:c}=e,l=n?s:``,u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u=v(),t[0]=u):u=t[0];let d;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(d=ie(),t[1]=d):d=t[1];let f;t[2]===l?f=t[3]:(f={content:l,used:0,limit:d},t[2]=l,t[3]=f);let p;t[4]!==i||t[5]!==r||t[6]!==n||t[7]!==o||t[8]!==a||t[9]!==f?(p={enabled:n,insideLink:!1,isMobileSurface:u,effectiveDirectory:r,editor:i,preferRuntimeEditor:a,onShowPopup:o,slots:f},t[4]=i,t[5]=r,t[6]=n,t[7]=o,t[8]=a,t[9]=f,t[10]=p):p=t[10];let m=p,h;return t[11]!==c||t[12]!==m?(h=(0,K.jsx)(J.Provider,{value:m,children:c}),t[11]=c,t[12]=m,t[13]=h):h=t[13],h},Y=({raw:e,referenceKind:t,children:n})=>{let r=z.useContext(J),i=N(e,r.effectiveDirectory,t),a=z.useRef(!1);r.enabled&&i&&!a.current&&r.slots.used<r.slots.limit&&(r.slots.used+=1,a.current=!0);let[o,s]=z.useState(i?oe(i.resolvedPath,r.effectiveDirectory)??null:null),c=i?.resolvedPath;if(z.useEffect(()=>{if(!r.enabled||!c||!a.current)return;let e=!1;return P(c,r.effectiveDirectory).then(t=>{e||s(t)}).catch(()=>{}),()=>{e=!0}},[r.enabled,r.effectiveDirectory,c]),!i)return n??e;let l=!!(a.current&&o&&ae(i.resolvedPath,o,r.isMobileSurface));return(0,K.jsx)(`span`,{"data-yuri-block-path-token":`true`,...l?{"data-yuri-file-link":`true`,"data-yuri-file-ref":e,"data-yuri-file-path":i.resolvedPath,"data-yuri-file-binary":String(o?.isBinary===!0),title:se,...n?{}:{role:`button`,tabIndex:0}}:{},children:n??e})};function he(e){let t=(0,B.c)(18),n=z.useContext(J),r=G(),i;t[0]===r?i=t[1]:(i=()=>r.isStreaming&&!r.disableStreamAnimation&&r.variant!==`tool`?pe:_,t[0]=r,t[1]=i);let[a]=z.useState(i),o=e.node.content??``;if(!n.enabled||n.insideLink){let n;return t[2]!==a||t[3]!==e?(n=(0,K.jsx)(a,{...e,fade:!1}),t[2]=a,t[3]=e,t[4]=n):n=t[4],n}let s,c;if(t[5]!==a||t[6]!==o||t[7]!==e){c=Symbol.for(`react.early_return_sentinel`);bb0:{let n=U(o);if(n.length===1&&n[0]?.kind!==`path`){let n;t[10]!==a||t[11]!==e?(n=(0,K.jsx)(a,{...e,fade:!1}),t[10]=a,t[11]=e,t[12]=n):n=t[12],c=n;break bb0}let r;t[13]!==a||t[14]!==e?(r=(t,n)=>t.kind===`path`?(0,K.jsx)(Y,{raw:t.value},`path-${n}-${t.value}`):(0,K.jsx)(a,{...e,fade:!1,node:{...e.node,content:t.value}},`text-${n}`),t[13]=a,t[14]=e,t[15]=r):r=t[15],s=n.map(r)}t[5]=a,t[6]=o,t[7]=e,t[8]=s,t[9]=c}else s=t[8],c=t[9];if(c!==Symbol.for(`react.early_return_sentinel`))return c;let l;return t[16]===s?l=t[17]:(l=(0,K.jsx)(K.Fragment,{children:s}),t[16]=s,t[17]=l),l}function ge(e){let t=(0,B.c)(7),n=z.useContext(J),r=e.node.code??``;if(!n.enabled||!L(r)){let n;return t[0]===e?n=t[1]:(n=(0,K.jsx)(m,{...e}),t[0]=e,t[1]=n),n}let i;t[2]===r?i=t[3]:(i=(0,K.jsx)(Y,{raw:r}),t[2]=r,t[3]=i);let a;return t[4]!==e||t[5]!==i?(a=(0,K.jsx)(m,{...e,children:i}),t[4]=e,t[5]=i,t[6]=a):a=t[6],a}function _e(e){let t=(0,B.c)(20),n=z.useContext(J),r=e.node.href??``,i;t[0]!==n.enabled||t[1]!==r?(i=n.enabled&&L(r),t[0]=n.enabled,t[1]=r,t[2]=i):i=t[2];let a=i,o;t[3]===e?o=t[4]:(o=(0,K.jsx)(h,{...e,showTooltip:!1}),t[3]=e,t[4]=o);let s=o,c;t[5]!==n.isMobileSurface||t[6]!==r||t[7]!==s||t[8]!==e.node.title||t[9]!==e.showTooltip?(c=n.isMobileSurface||e.showTooltip===!1?s:(0,K.jsxs)(w,{children:[(0,K.jsx)(S,{asChild:!0,children:(0,K.jsx)(`span`,{children:s})}),(0,K.jsx)(C,{children:e.node.title||r})]}),t[5]=n.isMobileSurface,t[6]=r,t[7]=s,t[8]=e.node.title,t[9]=e.showTooltip,t[10]=c):c=t[10];let l=c,u;t[11]===n?u=t[12]:(u={...n,insideLink:!0},t[11]=n,t[12]=u);let d;t[13]!==l||t[14]!==a||t[15]!==r?(d=a?(0,K.jsx)(Y,{raw:r,referenceKind:`href`,children:l}):l,t[13]=l,t[14]=a,t[15]=r,t[16]=d):d=t[16];let f;return t[17]!==u||t[18]!==d?(f=(0,K.jsx)(J.Provider,{value:u,children:d}),t[17]=u,t[18]=d,t[19]=f):f=t[19],f}var ve=/^[ \t]{0,3}(`{3,}|~{3,})/,ye=e=>{if(typeof e!=`string`||e.length===0)return!1;let t=e.split(/\r?\n/,1)[0]??``;return ve.test(t)},be=e=>{let t=0,n=0,r=e.match(/[`~]+/g)??[];for(let e of r)e[0]==="`"?t=Math.max(t,e.length):n=Math.max(n,e.length);return t>=3?"`".repeat(Math.max(3,t+1)):n>=3&&t===0?"```":n>=3?`~`.repeat(Math.max(3,n+1)):"```"},xe=e=>{let t=typeof e.raw==`string`?e.raw:``;if(ye(t))return t.endsWith(`
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{t}from"./platform-CiUKDeXd.js";import{ot as n,st as r}from"./vendor-base-ui-fom6orB6.js";import{n as i}from"./vendor-react-D5BntRmA.js";import{E as a,V as o}from"./runtime-file-resource-CKQQEwNv.js";import{i as s,m as c,r as l}from"./vendor-reactuses-core-B8s-Rcd-.js";import{r as u}from"./useUIStore-DjizmHAt.js";import{i as d,o as f}from"./useMobileHtmlPreviewStore-DzzgY1eS.js";import{a as p,i as m,n as h,o as g,r as _,t as ee}from"./vendor-markstream-react-Cwc-VXWM.js";import{Cr as v,Rn as y}from"./useMobileNavigationStore-DW2W2RJB.js";import{t as te}from"./useThemeSystem-D2YBbLma.js";import{a as b,t as x}from"./vendor-framer-motion-DiGWHm7K.js";import{i as S,n as C,t as w}from"./tooltip-CRImppy1.js";import{n as T}from"./useEffectiveDirectory-DO8VgCTH.js";import{o as E}from"./image-loading-Dlh4FIPJ.js";import{t as D}from"./LoadingImage-D04t7088.js";import{r as O}from"./FadeInOnReveal--phLJx7J.js";import{r as ne,t as re}from"./markdownHeightCache-DnLywwOt.js";import{t as k}from"./useStreamingTextThrottle-WIQCZqFR.js";import{r as A,t as j}from"./MarkdownRendererImpl-p6ByfX6o.js";import{n as M}from"./fileReferenceParser-1HHDBUum.js";import{a as N,c as P,f as F,h as I,i as ie,l as ae,m as L,o as R,s as oe,t as se}from"./fileReferenceActions-DLTUzjwi.js";var z=e(r(),1),B=i(),V=`img:not([data-md-link-favicon="true"])`,H=e=>e.getAttribute(`data-md-image-source`)??e.getAttribute(`src`)??``,ce=(e,t)=>{if(e.defaultPrevented||e.button!==0||e.altKey||e.shiftKey)return;let n=e.target;if(!(n instanceof Element))return;if(e.metaKey||e.ctrlKey){let e=n.closest(`a[href]`);if(!(e instanceof HTMLAnchorElement)||!I(e.getAttribute(`href`)??``))return}let r=n.closest(V);if(r instanceof HTMLImageElement&&t.onShowPopup){let n=e.currentTarget;if(!(n instanceof HTMLElement))return;let i=Array.from(n.querySelectorAll(V)).map(e=>({url:H(e),filename:e.alt||H(e)||void 0})).filter(e=>e.url),a=H(r),o=i.findIndex(e=>e.url===a);if(!a)return;e.preventDefault(),e.stopPropagation(),t.onShowPopup({open:!0,title:r.alt||a,content:``,previewSource:r,image:{url:a,...t.effectiveDirectory?{directory:t.effectiveDirectory}:{},filename:r.alt||a,gallery:i,index:o>=0?o:0}});return}if(t.fileReference){let r=n.closest(F);if(r instanceof HTMLElement){e.preventDefault(),e.stopPropagation(),R(r,t.fileReference);return}}let i=n.closest(`a[href]`);if(!(i instanceof HTMLAnchorElement))return;let a=i.getAttribute(`href`)??``;if(I(a)){e.preventDefault(),e.stopPropagation(),t.fileReference&&R(i,t.fileReference);return}if(!d(a))return;e.preventDefault(),e.stopPropagation();let o=(t.effectiveDirectory||``).trim();if(!v()&&o&&t.openInAppBrowser){t.openInAppBrowser(o,a);return}f(a)},le=(e,t)=>{if(e.key!==`Enter`&&e.key!==` `||!t.fileReference)return;let n=e.target;if(!(n instanceof Element))return;let r=n.closest(F);!(r instanceof HTMLElement)||r.getAttribute(`data-yuri-file-link`)!==`true`||(e.preventDefault(),e.stopPropagation(),R(r,t.fileReference))},ue=(e,t)=>{let n=t>=2?e.slice(t-2,t):``;return(t>=1?e.charAt(t-1):``)===`:`||n===`:/`},U=e=>{if(!e.includes(`/`)||!e.includes(`.`))return[{kind:`text`,value:e}];M.lastIndex=0;let t=[],n=0,r=M.exec(e);for(;r;){let i=r[0];if(!i||ue(e,r.index)||!L(i)){r=M.exec(e);continue}r.index>n&&t.push({kind:`text`,value:e.slice(n,r.index)}),t.push({kind:`path`,value:i}),n=r.index+i.length,r=M.exec(e)}return n===0?[{kind:`text`,value:e}]:(n<e.length&&t.push({kind:`text`,value:e.slice(n)}),t)},W=z.createContext({messageId:`markstream`,isStreaming:!1,disableStreamAnimation:!1,variant:`assistant`,enableFileReferences:!0}),G=()=>z.useContext(W),K=n(),de=24,q=4,fe=new Intl.Segmenter(void 0,{granularity:`grapheme`});function pe({node:e}){let t=G(),n=x(),r=t.isStreaming&&!t.disableStreamAnimation&&!n,i=e.content??``,a=z.useRef(i),o=z.useRef(i),s=z.useRef(null),c=z.useRef(new Map);return z.useLayoutEffect(()=>{let e=s.current;if(!e)return;let t=t=>{c.current.delete(t),t.parentNode===e&&(t.replaceWith(document.createTextNode(t.textContent??``)),e.normalize())},n=()=>{for(let[e,n]of c.current)n.stop(),t(e)};if(!r||!i.startsWith(o.current)){n(),e.textContent=i,o.current=i;return}let a=i.slice(o.current.length);if(o.current=i,!a)return;let l=Array.from(fe.segment(a),e=>e.segment),u=Math.max(0,l.length-96),d=[];for(let e=u;e<l.length;e+=q)d.push(l.slice(e,e+q).join(``));c.current.size+d.length>de&&n(),u>0&&e.appendChild(document.createTextNode(l.slice(0,u).join(``))),d.forEach((n,r)=>{let i=document.createElement(`span`);i.dataset.motionStreamChunk=``,i.textContent=n,i.style.opacity=`0`,e.appendChild(i);let a=b([i],{opacity:[0,1]},{duration:.16,delay:Math.min(r*.008,.08),ease:`easeOut`});c.current.set(i,a),a.then(()=>t(i))})},[i,r]),z.useLayoutEffect(()=>{let e=c.current;return()=>{for(let t of e.values())t.stop();e.clear()}},[]),(0,K.jsx)(`span`,{ref:s,className:y(`text-node whitespace-pre-wrap break-words`,e.center&&`text-node-center`),children:a.current})}var J=z.createContext({enabled:!1,insideLink:!1,isMobileSurface:!1,effectiveDirectory:``,preferRuntimeEditor:!1,slots:{used:0,limit:0}}),me=e=>{let t=(0,B.c)(14),{enabled:n,effectiveDirectory:r,editor:i,preferRuntimeEditor:a,onShowPopup:o,content:s,children:c}=e,l=n?s:``,u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u=v(),t[0]=u):u=t[0];let d;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(d=ie(),t[1]=d):d=t[1];let f;t[2]===l?f=t[3]:(f={content:l,used:0,limit:d},t[2]=l,t[3]=f);let p;t[4]!==i||t[5]!==r||t[6]!==n||t[7]!==o||t[8]!==a||t[9]!==f?(p={enabled:n,insideLink:!1,isMobileSurface:u,effectiveDirectory:r,editor:i,preferRuntimeEditor:a,onShowPopup:o,slots:f},t[4]=i,t[5]=r,t[6]=n,t[7]=o,t[8]=a,t[9]=f,t[10]=p):p=t[10];let m=p,h;return t[11]!==c||t[12]!==m?(h=(0,K.jsx)(J.Provider,{value:m,children:c}),t[11]=c,t[12]=m,t[13]=h):h=t[13],h},Y=({raw:e,referenceKind:t,children:n})=>{let r=z.useContext(J),i=N(e,r.effectiveDirectory,t),a=z.useRef(!1);r.enabled&&i&&!a.current&&r.slots.used<r.slots.limit&&(r.slots.used+=1,a.current=!0);let[o,s]=z.useState(i?oe(i.resolvedPath,r.effectiveDirectory)??null:null),c=i?.resolvedPath;if(z.useEffect(()=>{if(!r.enabled||!c||!a.current)return;let e=!1;return P(c,r.effectiveDirectory).then(t=>{e||s(t)}).catch(()=>{}),()=>{e=!0}},[r.enabled,r.effectiveDirectory,c]),!i)return n??e;let l=!!(a.current&&o&&ae(i.resolvedPath,o,r.isMobileSurface));return(0,K.jsx)(`span`,{"data-yuri-block-path-token":`true`,...l?{"data-yuri-file-link":`true`,"data-yuri-file-ref":e,"data-yuri-file-path":i.resolvedPath,"data-yuri-file-binary":String(o?.isBinary===!0),title:se,...n?{}:{role:`button`,tabIndex:0}}:{},children:n??e})};function he(e){let t=(0,B.c)(18),n=z.useContext(J),r=G(),i;t[0]===r?i=t[1]:(i=()=>r.isStreaming&&!r.disableStreamAnimation&&r.variant!==`tool`?pe:_,t[0]=r,t[1]=i);let[a]=z.useState(i),o=e.node.content??``;if(!n.enabled||n.insideLink){let n;return t[2]!==a||t[3]!==e?(n=(0,K.jsx)(a,{...e,fade:!1}),t[2]=a,t[3]=e,t[4]=n):n=t[4],n}let s,c;if(t[5]!==a||t[6]!==o||t[7]!==e){c=Symbol.for(`react.early_return_sentinel`);bb0:{let n=U(o);if(n.length===1&&n[0]?.kind!==`path`){let n;t[10]!==a||t[11]!==e?(n=(0,K.jsx)(a,{...e,fade:!1}),t[10]=a,t[11]=e,t[12]=n):n=t[12],c=n;break bb0}let r;t[13]!==a||t[14]!==e?(r=(t,n)=>t.kind===`path`?(0,K.jsx)(Y,{raw:t.value},`path-${n}-${t.value}`):(0,K.jsx)(a,{...e,fade:!1,node:{...e.node,content:t.value}},`text-${n}`),t[13]=a,t[14]=e,t[15]=r):r=t[15],s=n.map(r)}t[5]=a,t[6]=o,t[7]=e,t[8]=s,t[9]=c}else s=t[8],c=t[9];if(c!==Symbol.for(`react.early_return_sentinel`))return c;let l;return t[16]===s?l=t[17]:(l=(0,K.jsx)(K.Fragment,{children:s}),t[16]=s,t[17]=l),l}function ge(e){let t=(0,B.c)(7),n=z.useContext(J),r=e.node.code??``;if(!n.enabled||!L(r)){let n;return t[0]===e?n=t[1]:(n=(0,K.jsx)(m,{...e}),t[0]=e,t[1]=n),n}let i;t[2]===r?i=t[3]:(i=(0,K.jsx)(Y,{raw:r}),t[2]=r,t[3]=i);let a;return t[4]!==e||t[5]!==i?(a=(0,K.jsx)(m,{...e,children:i}),t[4]=e,t[5]=i,t[6]=a):a=t[6],a}function _e(e){let t=(0,B.c)(20),n=z.useContext(J),r=e.node.href??``,i;t[0]!==n.enabled||t[1]!==r?(i=n.enabled&&L(r),t[0]=n.enabled,t[1]=r,t[2]=i):i=t[2];let a=i,o;t[3]===e?o=t[4]:(o=(0,K.jsx)(h,{...e,showTooltip:!1}),t[3]=e,t[4]=o);let s=o,c;t[5]!==n.isMobileSurface||t[6]!==r||t[7]!==s||t[8]!==e.node.title||t[9]!==e.showTooltip?(c=n.isMobileSurface||e.showTooltip===!1?s:(0,K.jsxs)(w,{children:[(0,K.jsx)(S,{asChild:!0,children:(0,K.jsx)(`span`,{children:s})}),(0,K.jsx)(C,{children:e.node.title||r})]}),t[5]=n.isMobileSurface,t[6]=r,t[7]=s,t[8]=e.node.title,t[9]=e.showTooltip,t[10]=c):c=t[10];let l=c,u;t[11]===n?u=t[12]:(u={...n,insideLink:!0},t[11]=n,t[12]=u);let d;t[13]!==l||t[14]!==a||t[15]!==r?(d=a?(0,K.jsx)(Y,{raw:r,referenceKind:`href`,children:l}):l,t[13]=l,t[14]=a,t[15]=r,t[16]=d):d=t[16];let f;return t[17]!==u||t[18]!==d?(f=(0,K.jsx)(J.Provider,{value:u,children:d}),t[17]=u,t[18]=d,t[19]=f):f=t[19],f}var ve=/^[ \t]{0,3}(`{3,}|~{3,})/,ye=e=>{if(typeof e!=`string`||e.length===0)return!1;let t=e.split(/\r?\n/,1)[0]??``;return ve.test(t)},be=e=>{let t=0,n=0,r=e.match(/[`~]+/g)??[];for(let e of r)e[0]==="`"?t=Math.max(t,e.length):n=Math.max(n,e.length);return t>=3?"`".repeat(Math.max(3,t+1)):n>=3&&t===0?"```":n>=3?`~`.repeat(Math.max(3,n+1)):"```"},xe=e=>{let t=typeof e.raw==`string`?e.raw:``;if(ye(t))return t.endsWith(`
2
2
  `)?t:`${t}\n`;let n=(e.language??``).trim(),r=e.code??``,i=be(r),a=r.endsWith(`
3
3
  `)?r:`${r}\n`;return e.loading?`${i}${n}\n${a}`:`${i}${n}\n${a}${i}\n`},Se=e=>{let t=e.partId?`part-${e.partId}`:`body`,n=e.indexKey!==void 0&&e.indexKey!==null&&String(e.indexKey).length>0?String(e.indexKey):e.language&&e.language.length>0?e.language:`code`;return`${e.messageId}:${t}:code:${n}`};function Ce(e,t){let n=5381;for(let e=0;e<t.length;e+=1)n=Math.imul(n,33)^t.charCodeAt(e);return`${e}:${(n>>>0).toString(36)}:${t.length}`}function X(e){let t=(0,B.c)(7),n;if(t[0]!==e.indexKey||t[1]!==e.node.code||t[2]!==e.node.language){let r=(e.node.language??``).trim().toLowerCase()||`diagram`;n=e.indexKey??Ce(r,e.node.code??``),t[0]=e.indexKey,t[1]=e.node.code,t[2]=e.node.language,t[3]=n}else n=t[3];let r=n,i;return t[4]!==r||t[5]!==e?(i=(0,K.jsx)(Z,{...e,indexKey:r}),t[4]=r,t[5]=e,t[6]=i):i=t[6],i}function Z(e){let t=(0,B.c)(21),n=G(),r=e.node.language??``,i=e.node.code??``,a=e.node.raw??``,o=e.node.loading===!0||e.loading===!0,s;t[0]!==i||t[1]!==r||t[2]!==o||t[3]!==a?(s=xe({type:`code_block`,language:r,code:i,raw:a,loading:o}),t[0]=i,t[1]=r,t[2]=o,t[3]=a,t[4]=s):s=t[4];let c=s,l=n.isStreaming||e.loading===!0||e.node.loading===!0,u;t[5]!==n.messageId||t[6]!==n.partId||t[7]!==e.indexKey||t[8]!==e.node.language?(u=Se({messageId:n.messageId,partId:n.partId,indexKey:e.indexKey,language:e.node.language}),t[5]=n.messageId,t[6]=n.partId,t[7]=e.indexKey,t[8]=e.node.language,t[9]=u):u=t[9];let d=u,f=n.enableFileReferences&&!l,p;t[10]!==c||t[11]!==n.disableStreamAnimation||t[12]!==n.onShowPopup||t[13]!==n.variant||t[14]!==d||t[15]!==l||t[16]!==f?(p=(0,K.jsx)(j,{content:c,messageId:d,isAnimated:!1,skipFadeIn:!0,isStreaming:l,disableStreamAnimation:n.disableStreamAnimation,sourceIsPaced:!0,variant:n.variant,onShowPopup:n.onShowPopup,enableFileReferences:f}),t[10]=c,t[11]=n.disableStreamAnimation,t[12]=n.onShowPopup,t[13]=n.variant,t[14]=d,t[15]=l,t[16]=f,t[17]=p):p=t[17];let m;return t[18]!==d||t[19]!==p?(m=(0,K.jsx)(`div`,{className:`yuri-markstream-code-host min-w-0 w-full`,"data-yuri-markstream-code":`markdown-impl`,"data-yuri-markstream-code-id":d,children:p}),t[18]=d,t[19]=p,t[20]=m):m=t[20],m}function we(e){let t=(0,B.c)(9),{node:n}=e,r=T()??``,i=E(n.src,r),{onShowPopup:a}=G(),o=l(Q),s=i.source||void 0,c=n.title??void 0,u=a?`button`:void 0,d=a?0:void 0,f=a?o:void 0,p;return t[0]!==n.alt||t[1]!==n.src||t[2]!==i.error||t[3]!==s||t[4]!==c||t[5]!==u||t[6]!==d||t[7]!==f?(p=(0,K.jsx)(D,{contentFrame:!0,src:s,resourceError:i.error,"data-md-image-source":n.src,alt:n.alt,title:c,className:`rounded-lg`,role:u,tabIndex:d,onKeyDown:f}),t[0]=n.alt,t[1]=n.src,t[2]=i.error,t[3]=s,t[4]=c,t[5]=u,t[6]=d,t[7]=f,t[8]=p):p=t[8],p}function Q(e){(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.currentTarget.click())}function Te(e){let t=(0,B.c)(4);if(e.node.type===`code_block`){let n=e,r;return t[0]===n?r=t[1]:(r=(0,K.jsx)(Z,{...n}),t[0]=n,t[1]=r),r}let n=e,r;return t[2]===n?r=t[3]:(r=(0,K.jsx)(we,{...n}),t[2]=n,t[3]=r),r}var $=!1;function Ee(e){return e.node?.type===`code_block`?z.createElement(Z,e):z.createElement(he,e)}var De=()=>{$||($=!0,p({text:Ee,inline_code:ge,link:_e,image:Te,code_block:g(Z,`block`),mermaid:g(X,`block`),d2:g(X,`block`),d2lang:g(X,`block`),infographic:g(X,`block`)}))},Oe={parseOptions:{reuseStableTopLevelNodes:!0},maxLiveNodes:0,liveNodeBuffer:0,batchRendering:!1,deferNodesUntilVisible:!1,viewportPriority:!1,smoothStreaming:!1,typewriter:!1,fade:!1};De();var ke=e=>(e.inline.ruler.at(`math`,(e,t)=>{let n=e.src.slice(e.pos),r=A(n),i=n.startsWith(`\\(`)?/^\\\(([\s\S]+?)\\\)/.exec(n):null,a=r?.raw??i?.[0],o=r?.text??i?.[1];if(!a||!o)return!1;if(!t){let t=e.push(`math_inline`,`math`,0);t.content=o,t.markup=r?r.display?`$$`:`$`:`\\(\\)`}return e.pos+=a.length,!0}),e),Ae=e=>e===`tool`?`markdown-content markdown-tool yuri-markstream-host`:e===`reasoning`?`markdown-content markdown-reasoning yuri-markstream-host`:`markdown-content leading-relaxed yuri-markstream-host`,je=z.memo(({content:e,part:t,messageId:n,className:r,isStreaming:i=!1,disableStreamAnimation:d=!1,variant:f=`assistant`,onShowPopup:p,enableFileReferences:m=!0})=>{let h=te()?.currentTheme.metadata.variant===`dark`,{editor:g,runtime:_}=o(),v=a(),b=T()??``,x=z.useRef(null),S=t?.id?`yuri-ms-${t.id}`:`yuri-ms-${n}`,C=t?.id,w=!i,E=w?re(e,`markstream:${f}`):``,D=m&&!i,O=D?{effectiveDirectory:b,scope:v?.entry.location.hostId?v.entry:void 0,editor:g,preferRuntimeEditor:_.isVSCode,onShowPopup:p}:void 0,k=z.useMemo(()=>({messageId:n,partId:C,isStreaming:i,disableStreamAnimation:d,variant:f,onShowPopup:p,enableFileReferences:m}),[n,C,i,d,f,p,m]),A=z.useRef(w);A.current=w;let j=z.useRef(E);j.current=E;let M=l(e=>{if(!A.current)return;let t=e[0];if(!t)return;let n=t.borderBoxSize?.[0],r=n?n.blockSize:t.contentRect.height,i=n?n.inlineSize:t.contentRect.width;ne(j.current,r,i)});c(x,M);let N=l((e,t)=>{u.getState().openContextBrowser(e,t)}),P=l(e=>{ce(e,{onShowPopup:p,fileReference:O,effectiveDirectory:b,openInAppBrowser:N})}),F=l(e=>{le(e,{fileReference:O})});return s(`click`,P,x),s(`keydown`,F,x),(0,K.jsx)(`div`,{ref:x,className:y(`relative break-words w-full min-w-0`,Ae(f),r),"data-markdown-ready":`true`,"data-markdown-hydration":`ready`,"data-yuri-markdown-engine":`markstream`,"data-yuri-markstream-virtual":`off`,"data-yuri-markstream-streaming":i?`true`:void 0,children:(0,K.jsx)(W.Provider,{value:k,children:(0,K.jsx)(me,{enabled:D,effectiveDirectory:b,editor:g,preferRuntimeEditor:_.isVSCode,onShowPopup:p,content:e,children:(0,K.jsx)(ee,{content:e,customMarkdownIt:ke,customId:S,final:!i,isDark:h,codeBlockStream:i,...Oe})})})})},(e,t)=>e.content===t.content&&e.isStreaming===t.isStreaming&&e.disableStreamAnimation===t.disableStreamAnimation&&e.variant===t.variant&&e.isAnimated===t.isAnimated&&e.skipFadeIn===t.skipFadeIn&&e.className===t.className&&e.messageId===t.messageId&&e.onShowPopup===t.onShowPopup&&e.enableFileReferences===t.enableFileReferences&&e.part?.id===t.part?.id),Me=e=>{let n=(0,B.c)(7),r=e.content,i=e.isStreaming===!0,a;n[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=O(t()),n[0]=a):a=n[0];let o;n[1]!==e.content||n[2]!==i?(o={text:r,isStreaming:i,throttleMs:a.markdownPaceMs},n[1]=e.content,n[2]=i,n[3]=o):o=n[3];let s=k(o),c=e.isStreaming?s:e.content,l;return n[4]!==e||n[5]!==c?(l=(0,K.jsx)(je,{...e,content:c}),n[4]=e,n[5]=c,n[6]=l):l=n[6],l},Ne=e=>{let t=(0,B.c)(3),n=`${e.messageId}:${e.part?.id??`text`}`,r;return t[0]!==e||t[1]!==n?(r=(0,K.jsx)(Me,{...e},n),t[0]=e,t[1]=n,t[2]=r):r=t[2],r};export{Ne as MarkstreamRenderer};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,n}from"./runtime-switch-DEPKHgdL.js";import{n as r}from"./runtime-fetch-V-iMWR8t.js";import{ot as i,st as a}from"./vendor-base-ui-fom6orB6.js";import{n as o}from"./vendor-react-D5BntRmA.js";import{s}from"./vendor-tanstack-react-query-ChSd65dm.js";import{L as c,q as l}from"./runtime-file-resource-CKQQEwNv.js";import{i as u}from"./store-Dj5cSf8B.js";import{In as d,Rn as f,to as p}from"./useMobileNavigationStore-CRoFDKhN.js";import{n as m}from"./Icon-RGzME9hn.js";var h=e(a(),1),g=o(),_=class extends Error{code;status;resource;constructor(e,t,n,r){super(typeof r==`string`&&r.trim()?r.trim():e),this.code=e,this.status=t,this.resource=n}},v=e=>{if(!e||typeof e!=`object`)return!1;let t=`name`in e?String(e.name):``;return t===`AbortError`||t===`TimeoutError`},y=class extends _{operation;constructor(e,t,n){super(e,t,`share_operation`),this.operation=n}},b=(e,t=200)=>{throw new _(`invalid_${e}_response`,t,e)},x=(e,t)=>e&&typeof e==`object`&&!Array.isArray(e)?e:b(t),S=(e,t)=>typeof e==`string`?e:b(t),C=(e,t)=>e===null||typeof e==`string`?e:b(t),w=(e,t)=>typeof e==`number`&&Number.isFinite(e)?e:b(t),T=(e,t)=>e===null?null:w(e,t),E=(e,t)=>typeof e==`boolean`?e:b(t),D=(e,t,n)=>t.includes(e)?e:b(n),O=e=>{let t=x(e,`capability`);return{supported:E(t.supported,`capability`),enabled:E(t.enabled,`capability`),revision:w(t.revision,`capability`),serverInstanceID:C(t.serverInstanceID,`capability`),sharingAvailable:t.sharingAvailable!==void 0&&E(t.sharingAvailable,`capability`)}},k=e=>{if(e==null)return null;let t=x(e,`assistant`);return{turnID:S(t.turnID,`assistant`),messageID:S(t.messageID,`assistant`),status:D(t.status,[`queued`,`running`],`assistant`),admittedAt:w(t.admittedAt,`assistant`)}},A=e=>{if(e==null)return null;let t=x(e,`assistant_preview`),n=w(t.ordinal,`assistant_preview`);return!Number.isSafeInteger(n)||n<0?b(`assistant_preview`):{...t.createdAt===void 0?{}:{createdAt:w(t.createdAt,`assistant_preview`)},messageID:S(t.messageID,`assistant_preview`),ordinal:n,role:D(t.role,[`user`,`assistant`],`assistant_preview`),text:S(t.text,`assistant_preview`),fallbackKind:t.fallbackKind===null?null:D(t.fallbackKind,[`image`,`file`,`session`,`assistant`,`schedule`],`assistant_preview`)}},j=e=>{let t=w(e,`assistant_read`);return Number.isSafeInteger(t)&&t>=0?t:b(`assistant_read`)},M=e=>{let t=x(e,`assistant_read`);return{generation:j(t.generation),ordinal:j(t.ordinal),messageID:S(t.messageID,`assistant_read`)}},N=e=>({unreadCount:e.unreadCount===void 0?0:j(e.unreadCount),readWatermark:e.readWatermark==null?null:M(e.readWatermark),readTip:e.readTip==null?null:M(e.readTip)}),P=e=>{let t=x(e,`assistant_read`);return{assistantID:S(t.assistantID,`assistant_read`),changed:E(t.changed,`assistant_read`),unreadCount:j(t.unreadCount),readWatermark:M(t.readWatermark),readTip:M(t.readTip),revision:j(t.revision)}},F=e=>{let t=x(e,`assistant`),n=Array.isArray(t.historySessionIDs)?t.historySessionIDs.map(e=>S(e,`assistant`)):[],r=t.historySessionCount===void 0?n.length:w(t.historySessionCount,`assistant`);if(!Number.isSafeInteger(r)||r<n.length)return b(`assistant`);let i=Array.isArray(t.assignedSessionIDs)?t.assignedSessionIDs.map(e=>S(e,`assistant`)):[],a=t.activeContactTurn===void 0?null:k(t.activeContactTurn),o=t.working===void 0?a!=null:E(t.working,`assistant`);return{...N(t),pinnedAt:t.pinnedAt===void 0?void 0:T(t.pinnedAt,`assistant`),latestMessagePreview:A(t.latestMessagePreview),id:S(t.id,`assistant`),avatarSeed:S(t.avatarSeed??t.id,`assistant`),revision:w(t.revision,`assistant`),enabled:E(t.enabled,`assistant`),name:S(t.name,`assistant`),defaultPrompt:S(t.defaultPrompt,`assistant`),workspacePath:C(t.workspacePath,`assistant`),effectiveWorkspacePath:S(t.effectiveWorkspacePath,`assistant`),managedWorkspacePath:C(t.managedWorkspacePath??null,`assistant`),providerID:S(t.providerID,`assistant`),modelID:S(t.modelID,`assistant`),agent:C(t.agent,`assistant`),variant:C(t.variant??null,`assistant`),mode:D(t.mode,[`continuous`,`stateless`],`assistant`),sessionID:C(t.sessionID,`assistant`),sessionGeneration:w(t.sessionGeneration,`assistant`),historySessionIDs:n,historySessionCount:r,assignedSessionIDs:i,working:o,activeContactTurn:a,createdAt:T(t.createdAt,`assistant`),updatedAt:w(t.updatedAt,`assistant`),tombstoneAt:T(t.tombstoneAt,`assistant`)}},I=e=>{let t=x(e,`snapshot`);return{revision:w(t.revision,`snapshot`),enabled:E(t.enabled,`snapshot`),assistants:Array.isArray(t.assistants)?t.assistants.map(F):b(`snapshot`)}},L=e=>{let t=x(e,`binding`);return{sessionID:C(t.sessionID,`binding`),directory:S(t.directory,`binding`),sessionGeneration:w(t.sessionGeneration,`binding`)}},R=e=>{let t=x(e,`message_admission`);if(t.admitted!==!0)return b(`message_admission`);let n=t.revision===void 0||t.revision===null?null:w(t.revision,`message_admission`);return{binding:L(t.binding),messageID:S(t.messageID,`message_admission`),admitted:!0,revision:n,...t.replayed===!0?{replayed:!0}:{}}},z=e=>{let t=x(e,`share_operation`);return{operationID:S(t.operationID,`share_operation`),assistantID:S(t.assistantID,`share_operation`),sessionID:C(t.sessionID,`share_operation`),messageID:C(t.messageID,`share_operation`),state:D(t.state,[`submitting`,`running`,`completed`,`failed`,`unresolved`],`share_operation`),phase:S(t.phase,`share_operation`),attempt:w(t.attempt,`share_operation`),leaseExpiresAt:T(t.leaseExpiresAt,`share_operation`),errorCode:C(t.errorCode,`share_operation`)}},B=e=>{let t=x(e,`assistant_contact_part`);if(t.type===`text`)return{type:`text`,text:S(t.text,`assistant_contact_part`)};if(t.type===`file`){let e=t.filename===void 0||t.filename===null?void 0:S(t.filename,`assistant_contact_part`),n=S(t.mime,`assistant_contact_part`),r=t.url!==void 0&&t.url!==null,i=t.attachmentID!==void 0&&t.attachmentID!==null;if(r&&i)return b(`assistant_contact_part`);if(i){let r=w(t.size,`assistant_contact_part`);return!Number.isSafeInteger(r)||r<0?b(`assistant_contact_part`):{type:`file`,mime:n,attachmentID:S(t.attachmentID,`assistant_contact_part`),sha256:S(t.sha256,`assistant_contact_part`),size:r,...e?{filename:e}:{}}}return r?{type:`file`,mime:n,url:S(t.url,`assistant_contact_part`),...e?{filename:e}:{}}:b(`assistant_contact_part`)}if(t.type===`card`){let e=D(t.cardType,[`session`,`assistant`,`schedule`],`assistant_contact_part`);if(e===`session`){let e;if(t.target!==void 0){let n=x(t.target,`assistant_contact_part`),r=e=>{let t=S(n[e],`assistant_contact_part`);return!t||t!==t.trim()||t.length>512||Array.from(t).some(e=>e.charCodeAt(0)<32)?b(`assistant_contact_part`):t};e={hubId:r(`hubId`),hostId:r(`hostId`),instanceId:r(`instanceId`)}}return{type:`card`,cardType:`session`,sessionID:S(t.sessionID,`assistant_contact_part`),directory:S(t.directory,`assistant_contact_part`),title:C(t.title??null,`assistant_contact_part`),status:C(t.status??null,`assistant_contact_part`),branch:C(t.branch??null,`assistant_contact_part`),...e?{target:e}:{}}}return e===`assistant`?{type:`card`,cardType:`assistant`,assistantID:S(t.assistantID,`assistant_contact_part`),name:S(t.name,`assistant_contact_part`),providerID:S(t.providerID,`assistant_contact_part`),modelID:S(t.modelID,`assistant_contact_part`),mode:D(t.mode??`continuous`,[`continuous`,`stateless`],`assistant_contact_part`)}:{type:`card`,cardType:`schedule`,taskID:S(t.taskID,`assistant_contact_part`),projectID:S(t.projectID,`assistant_contact_part`),name:S(t.name,`assistant_contact_part`),kind:C(t.kind??null,`assistant_contact_part`),time:C(t.time??null,`assistant_contact_part`),timezone:C(t.timezone??null,`assistant_contact_part`),prompt:C(t.prompt??null,`assistant_contact_part`),...t.cron===void 0?{}:{cron:C(t.cron,`assistant_contact_part`)},...t.date===void 0?{}:{date:C(t.date,`assistant_contact_part`)},...t.times===void 0?{}:{times:t.times===null?null:Array.isArray(t.times)?t.times.map(e=>S(e,`assistant_contact_part`)):b(`assistant_contact_part`)},...t.weekdays===void 0?{}:{weekdays:t.weekdays===null?null:Array.isArray(t.weekdays)?t.weekdays.map(e=>{let t=w(e,`assistant_contact_part`);return Number.isInteger(t)&&t>=0&&t<=6?t:b(`assistant_contact_part`)}):b(`assistant_contact_part`)}}}return b(`assistant_contact_part`)},V=e=>{let t=x(e,`assistant_contact`),n=C(t.nextCursor,`assistant_contact`),r=E(t.complete,`assistant_contact`);if(!r&&!n||r&&n||!Array.isArray(t.messages))return b(`assistant_contact`);let i=w(t.generation,`assistant_contact`),a=w(t.revision,`assistant_contact`);return!Number.isSafeInteger(i)||i<0||!Number.isSafeInteger(a)||a<0?b(`assistant_contact`):{messages:t.messages.map(e=>{let t=x(e,`assistant_contact_message`);if(!Array.isArray(t.parts))return b(`assistant_contact_message`);let n=t.parts.map(B);return{messageID:S(t.messageID,`assistant_contact_message`),assistantID:S(t.assistantID,`assistant_contact_message`),role:D(t.role,[`user`,`assistant`,`peer`],`assistant_contact_message`),turnID:S(t.turnID,`assistant_contact_message`),bubbleIndex:w(t.bubbleIndex,`assistant_contact_message`),createdAt:w(t.createdAt,`assistant_contact_message`),ordinal:w(t.ordinal,`assistant_contact_message`),status:S(t.status,`assistant_contact_message`),fromAssistantID:C(t.fromAssistantID??null,`assistant_contact_message`),fromAssistantName:C(t.fromAssistantName??null,`assistant_contact_message`),parts:n,text:typeof t.text==`string`?t.text:n.filter(e=>e.type===`text`).map(e=>e.text).join(``),cards:n.filter(e=>e.type===`card`)}}),nextCursor:n,complete:r,generation:i,revision:a}},ee=e=>{let t=x(e,`assistant_scheduled_tasks`);return Array.isArray(t.tasks)?{tasks:t.tasks.map(e=>{let t=x(e,`assistant_scheduled_task`),n=t.task===null||t.task===void 0?null:x(t.task,`assistant_scheduled_task_live`);return{assistantID:S(t.assistantID,`assistant_scheduled_task`),projectID:S(t.projectID,`assistant_scheduled_task`),taskID:S(t.taskID,`assistant_scheduled_task`),createdAt:w(t.createdAt,`assistant_scheduled_task`),projectPath:C(t.projectPath??null,`assistant_scheduled_task`),projectLabel:C(t.projectLabel??null,`assistant_scheduled_task`),task:n}})}:b(`assistant_scheduled_tasks`)},H=async(e,t)=>{try{let t=await e.json();if(t&&typeof t.error==`string`&&t.error.trim().length>0)return t.error}catch{return t}return t},U=e=>{let t=typeof e==`string`?e.trim():``;if(!t)throw Error(`projectId is required`);return t},te=e=>e===null||typeof e==`string`,ne=e=>e===null||typeof e==`number`&&Number.isFinite(e),re=e=>typeof e==`number`&&Number.isFinite(e)&&e>=0&&e<=864e13,ie=e=>e===null||re(e),ae=e=>{if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return typeof t.id==`string`&&t.id.length>0&&typeof t.projectId==`string`&&t.projectId.length>0&&typeof t.taskId==`string`&&t.taskId.length>0&&typeof t.taskName==`string`&&(t.trigger===`scheduled`||t.trigger===`manual`)&&(t.status===`running`||t.status===`success`||t.status===`error`)&&te(t.sessionId)&&te(t.directory)&&te(t.error)&&re(t.startedAt)&&ie(t.finishedAt)&&ne(t.durationMs)&&(t.durationMs===null||t.durationMs>=0)},oe=e=>{if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`Malformed scheduled task runs response`);let t=e;if(!Array.isArray(t.runs)||!t.runs.every(ae)||!te(t.nextCursor)||typeof t.complete!=`boolean`||t.complete!==(t.nextCursor===null)||t.nextCursor!==null&&t.nextCursor.length===0)throw Error(`Malformed scheduled task runs response`);return{runs:t.runs,nextCursor:t.nextCursor,complete:t.complete}},se=async(e,t)=>{let n=new URLSearchParams;e.before&&n.set(`before`,e.before);let i=e.limit??20;if(!Number.isInteger(i)||i<1)throw Error(`limit must be a positive integer`);n.set(`limit`,String(i)),e.projectId&&n.set(`projectId`,e.projectId),e.taskId&&n.set(`taskId`,e.taskId);let a=await r(`/api/yuri/scheduled-task-runs?${n.toString()}`,{signal:t});if(!a.ok)throw Error(await H(a,`Failed to load scheduled task history`));return oe(await a.json().catch(()=>null))},ce=async({signal:e}={})=>{let t=await r(`/api/yuri/scheduled-tasks`,{signal:e});if(!t.ok)throw Error(await H(t,`Failed to load schedules`));let n=await t.json().catch(()=>null);if(!n||!Array.isArray(n.tasks))throw Error(`Malformed schedules response`);return{tasks:Array.isArray(n?.tasks)?n.tasks:[],failedProjectIds:Array.isArray(n?.failedProjectIds)?n.failedProjectIds.filter(e=>typeof e==`string`):[]}},le=async(e,t)=>{let n=U(e),i=await r(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks`,{method:`PUT`,headers:{"content-type":`application/json`,accept:`application/json`},body:JSON.stringify({task:t})});if(!i.ok)throw Error(await H(i,`Failed to save schedule`));let a=await i.json().catch(()=>null);return!a||!Array.isArray(a.tasks)?[]:a.tasks},ue=async(e,t)=>{let n=U(e),i=U(t),a=await r(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks/${encodeURIComponent(i)}`,{method:`DELETE`,headers:{accept:`application/json`}});if(!a.ok)throw Error(await H(a,`Failed to delete schedule`));let o=await a.json().catch(()=>null);return!o||!Array.isArray(o.tasks)?[]:o.tasks},de=async(e,t)=>{let n=U(e),i=U(t),a=await r(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks/${encodeURIComponent(i)}/run`,{method:`POST`,headers:{accept:`application/json`}});if(!a.ok)throw Error(await H(a,`Failed to run schedule`));let o=await a.json().catch(()=>null);return{sessionId:typeof o?.sessionId==`string`&&o.sessionId.length>0?o.sessionId:void 0}},fe=(e,t)=>e.ordinal===t.ordinal?e.messageID<t.messageID?-1:+(e.messageID>t.messageID):e.ordinal-t.ordinal,pe=e=>{if(e.type===`file`||e.type===`card`)return!0;if(e.type!==`text`)return!1;let t=typeof e.text==`string`?e.text.trim():``;return!!t&&!t.startsWith(`yuri.settle.`)&&!t.startsWith(`oc.settle.`)},me=(e,t)=>{if(!t||!e.readTip||!((e.unreadCount??0)>0))return null;let n=e.readTip;if(t.generation!==n.generation)return null;let r;for(let n=t.messages.length-1;n>=0;--n){let i=t.messages[n];if(i.assistantID===e.id&&(i.status===`complete`||i.status===`error`)&&i.parts.some(pe)){r=i;break}}if(!r)return null;let i=e.readWatermark;return i&&(i.generation>t.generation||i.generation===t.generation&&fe({ordinal:i.ordinal,messageID:i.messageID},{ordinal:r.ordinal,messageID:r.messageID})>=0)?null:{generation:t.generation,ordinal:r.ordinal,messageID:r.messageID}},he=()=>({messages:[],generation:-1,revision:0,olderCursor:null,olderComplete:!0,hasMessageGap:!1,gapCursor:null,gapRequestIDs:null,gapTargetIDs:null,liveWindowIDs:[]}),ge=e=>!!(e&&e.generation>=0),_e=(e,t)=>fe({ordinal:e.ordinal,messageID:e.messageID},{ordinal:t.ordinal,messageID:t.messageID}),W=(e,t,n=`incoming`)=>{let r=new Map;for(let t of e)r.set(t.messageID,t);for(let e of t)(n===`incoming`||!r.has(e.messageID))&&r.set(e.messageID,e);return[...r.values()].sort(_e)},ve=e=>{let t=1/0;for(let n of e)n.ordinal<t&&(t=n.ordinal);return Number.isFinite(t)?t:null},ye=e=>e.map(e=>e.messageID),be=(e,t)=>{for(let n of e)if(t.has(n))return!0;return!1},xe=e=>new Set(e),Se=(e,t)=>!e||!t||e.length!==t.length?!1:e.every((e,n)=>e===t[n]),Ce=e=>({...e,hasMessageGap:!1,gapCursor:null,gapRequestIDs:null,gapTargetIDs:null}),we=e=>({ordinal:e.ordinal,messageID:e.messageID}),Te=(e,t,n)=>{if(n)return[...t];if(t.length===0)return[...e];let r=t[0];return[...e.filter(e=>fe(we(e),we(r))<0),...t]},Ee=(e,t)=>{let n=e??he(),r=ge(n),i=[...t.messages].sort(_e),a=ye(i);if(r&&t.generation<n.generation)return n;if(r&&t.generation>n.generation)return{messages:i,generation:t.generation,revision:t.revision,olderCursor:t.nextCursor,olderComplete:t.complete,hasMessageGap:!1,gapCursor:null,gapRequestIDs:null,gapTargetIDs:null,liveWindowIDs:a};if(!r)return{messages:i,generation:t.generation,revision:t.revision,olderCursor:t.complete?null:t.nextCursor,olderComplete:t.complete,hasMessageGap:!1,gapCursor:null,gapRequestIDs:null,gapTargetIDs:null,liveWindowIDs:a};let o=Math.max(n.revision,t.revision),s=t.revision>=n.revision;if(i.length===0)return s&&t.complete?{messages:[],generation:t.generation,revision:o,olderCursor:null,olderComplete:!0,hasMessageGap:!1,gapCursor:null,gapRequestIDs:null,gapTargetIDs:null,liveWindowIDs:[]}:{...n,generation:t.generation,revision:o,olderCursor:n.olderCursor??t.nextCursor,olderComplete:n.olderComplete&&t.complete,liveWindowIDs:[],hasMessageGap:n.hasMessageGap,gapCursor:n.hasMessageGap?t.nextCursor??n.gapCursor:null,gapRequestIDs:n.hasMessageGap?n.gapRequestIDs:null,gapTargetIDs:n.hasMessageGap?n.gapTargetIDs:null};let c;if(s)c=Te(n.messages,i,t.complete);else{let e=ve(i);c=W(n.messages.filter(t=>t.ordinal<e),W(n.messages.filter(t=>t.ordinal>=e),i,`existing`),`incoming`)}let l=n.liveWindowIDs,u=xe(a),d=l.length>0&&be(l,u),f=n.hasMessageGap,p=n.gapCursor,m=n.gapRequestIDs,h=n.gapTargetIDs;if(!d&&l.length>0&&t.nextCursor){f=!0,p=t.nextCursor;let e=l.filter(e=>!u.has(e));m=e.length>0?e:[...l],h=n.hasMessageGap&&n.gapTargetIDs&&n.gapTargetIDs.length>0?n.gapTargetIDs:m}else n.hasMessageGap?(f=!0,p=n.gapCursor,m=n.gapRequestIDs,h=n.gapTargetIDs):(f=!1,p=null,m=null,h=null);return{messages:c,generation:t.generation,revision:o,olderCursor:n.liveWindowIDs.length===0&&n.messages.length===0?t.complete?null:t.nextCursor:n.olderCursor,olderComplete:!r||n.liveWindowIDs.length===0&&n.messages.length===0?t.complete:n.olderComplete,hasMessageGap:f,gapCursor:f?p:null,gapRequestIDs:f?m:null,gapTargetIDs:f?h:null,liveWindowIDs:a}},De=(e,t)=>{if(!ge(e)||t.generation!==e.generation)return e;let n=t.revision>=e.revision?`incoming`:`existing`,r=W(e.messages,t.messages,n);return{...e,messages:r,revision:Math.max(e.revision,t.revision),olderCursor:t.complete?null:t.nextCursor,olderComplete:t.complete}},Oe=(e,t,n)=>{if(!ge(e)||t.generation!==e.generation)return e;let r=t.revision>=e.revision?`incoming`:`existing`,i=W(e.messages,t.messages,r),a=Math.max(e.revision,t.revision),o=n?.requestIDs??e.gapRequestIDs;if(!(e.hasMessageGap&&o&&e.gapRequestIDs&&Se(o,e.gapRequestIDs)))return{...e,messages:i,revision:a};let s=ye(t.messages),c=e.gapTargetIDs??[],l=xe(c);return c.length>0&&be(s,l)||t.complete||!t.nextCursor?Ce({...e,messages:i,revision:a}):{...e,messages:i,revision:a,hasMessageGap:!0,gapCursor:t.nextCursor??e.gapCursor,gapRequestIDs:e.gapRequestIDs,gapTargetIDs:e.gapTargetIDs}},G={snapshot:(e=t())=>[e,`assistants`,`snapshot`],capability:(e=t())=>[e,`assistants`,`capability`],history:(e,r,i,a=t(),o=n())=>[a,o,`assistants`,`history`,e,r,i],contact:(e,r=t(),i=n())=>[r,i,`assistants`,`contact`,e],scheduledTasks:(e,r=t(),i=n())=>[r,i,`assistants`,`scheduled-tasks`,e],globalScheduledTasks:(e=t())=>[e,`scheduled-tasks`]},K=async(e,t={})=>{let n=await r(e,t),i=await n.json().catch(()=>null);if(!n.ok){let e=i&&typeof i==`object`&&`error`in i&&typeof i.error==`string`?i.error:`request_failed`,t=i&&typeof i==`object`&&`message`in i&&typeof i.message==`string`?i.message:void 0;throw new _(e,n.status,void 0,t)}return i},q=(e,t)=>({method:e,headers:{"Content-Type":`application/json`},body:t===void 0?void 0:JSON.stringify(t)}),J=(e,r)=>{if(t()!==e||n()!==r)throw new _(`runtime_stale`,409)},ke=(e,t,r)=>{l.setQueryData(G.snapshot(r),n=>n&&{...n,assistants:n.assistants.map(n=>n.id!==e||n.sessionGeneration>t.sessionGeneration?n:{...n,sessionID:t.sessionID,sessionGeneration:t.sessionGeneration,effectiveWorkspacePath:t.directory})}),l.invalidateQueries({queryKey:G.snapshot(r)}),l.invalidateQueries({queryKey:[r,n(),`assistants`,`history`,e]})},Ae=(e,t)=>{l.setQueryData(G.snapshot(t),t=>t&&{...t,assistants:t.assistants.some(t=>t.id===e.id)?t.assistants.map(t=>t.id===e.id?e:t):[...t.assistants,e]}),l.invalidateQueries({queryKey:G.snapshot(t)})},je=2500,Me=15e3,Ne=e=>!!e?.assistants.some(e=>e.working||e.activeContactTurn),Pe=(e,t={})=>{if(t.assistantID){let n=e?.assistants.find(e=>e.id===t.assistantID);return n?.working||n?.activeContactTurn?je:Me}return Ne(e)?je:Me},Y=(e=t())=>({queryKey:G.snapshot(e),queryFn:async({signal:e})=>I(await K(`/api/yuri/assistants/snapshot`,{signal:e})),staleTime:0,retry:2,refetchInterval:e=>Pe(e.state.data),refetchIntervalInBackground:!1,refetchOnWindowFocus:!0,refetchOnReconnect:!0}),X=new Map,Fe=e=>{let r=X.get(e);if(r)r.count+=1;else{let r=n(),i=!1,a=!1,o=!1,s=()=>!i&&t()===e&&n()===r,u=async()=>{if(o=!0,!a){a=!0;try{do o=!1,l.getQueryCache().find({queryKey:G.snapshot(e),exact:!0})?.state.fetchStatus===`fetching`&&(o=!0),await l.invalidateQueries({queryKey:G.snapshot(e),exact:!0},{cancelRefetch:!1});while(o&&s())}finally{a=!1}}},d=c(t=>{if(!s())return;let n=l.getQueryData(G.snapshot(e));(t.type===`event-stream-ready`||t.type===`contact-turn-start`||t.type===`contact-turn-end`||t.type===`assistants-changed`&&(!n||t.revision>n.revision))&&u()});X.set(e,{count:1,dispose:()=>{i=!0,d()}})}return()=>{let t=X.get(e);t&&--t.count===0&&(t.dispose(),X.delete(e))}},Ie=e=>{let n=(0,g.c)(7),r,i,a;n[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=t(),i=s,r=Y(a),n[0]=r,n[1]=i,n[2]=a):(r=n[0],i=n[1],a=n[2]);let o;n[3]===e?o=n[4]:(o={...r,select:e},n[3]=e,n[4]=o);let c=i(o),l,u;return n[5]===Symbol.for(`react.memo_cache_sentinel`)?(l=()=>Fe(a),u=[a],n[5]=l,n[6]=u):(l=n[5],u=n[6]),h.useEffect(l,u),c},Le=e=>e.enabled?e.assistants.reduce((e,t)=>e+(t.unreadCount??0),0):0,Re=()=>{let e=(0,g.c)(5),n,r,i;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=t(),n=s,r={...Y(i),select:Le},e[0]=n,e[1]=r,e[2]=i):(n=e[0],r=e[1],i=e[2]);let a=n(r),o,c;return e[3]===Symbol.for(`react.memo_cache_sentinel`)?(o=()=>Fe(i),c=[i],e[3]=o,e[4]=c):(o=e[3],c=e[4]),h.useEffect(o,c),a.data??0},ze=e=>e.enabled&&Ne(e),Be=()=>{let e=(0,g.c)(5),n,r,i;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=t(),n=s,r={...Y(i),select:ze},e[0]=n,e[1]=r,e[2]=i):(n=e[0],r=e[1],i=e[2]);let a=n(r),o,c;return e[3]===Symbol.for(`react.memo_cache_sentinel`)?(o=()=>Fe(i),c=[i],e[3]=o,e[4]=c):(o=e[3],c=e[4]),h.useEffect(o,c),a.data??!1},Ve=(e,t={})=>{let n=new URLSearchParams;return n.set(`limit`,String(t.limit??20)),t.before&&n.set(`before`,t.before),t.messageID&&n.set(`messageID`,t.messageID),`/api/yuri/assistants/${encodeURIComponent(e)}/contact/messages?${n}`},He=async(e,t,n)=>V(await K(Ve(e,t),n?{signal:n}:{})),Ue=(e,t)=>e.generation===t.generation&&e.revision===t.revision&&e.olderCursor===t.olderCursor&&e.olderComplete===t.olderComplete&&e.hasMessageGap===t.hasMessageGap&&e.gapCursor===t.gapCursor&&e.messages===t.messages&&e.liveWindowIDs===t.liveWindowIDs&&e.gapRequestIDs===t.gapRequestIDs&&e.gapTargetIDs===t.gapTargetIDs,Z=new Map,We=new Map,Q=e=>e.join(``),Ge=async(e,t,n,r,i)=>{let a=Q(t),o=We.get(a);if(o)return o;let s=(async()=>{let a=l.getQueryData(t)??n,o=0,s=!1,c=!1,u=a.gapRequestIDs?[...a.gapRequestIDs]:null,d=a.gapCursor;for(;a.hasMessageGap&&a.gapCursor&&o<5&&!i?.aborted;){J(r.transport,r.runtimeGeneration),o+=1;let n=a.gapCursor;try{let o=await He(e,{limit:20,before:n},i);J(r.transport,r.runtimeGeneration);let c=l.getQueryData(t)??a;if(o.generation!==c.generation){a=c;break}let f=!u||!!(c.hasMessageGap&&c.gapRequestIDs&&c.gapRequestIDs.length===u.length&&c.gapRequestIDs.every((e,t)=>e===u[t]));if(a=Oe(c,o,u?{requestIDs:u,cursor:d}:void 0),l.setQueryData(t,a),!f)break;if(!a.hasMessageGap){s=!0;break}if(a.gapCursor&&a.gapCursor!==n)s=!0;else break}catch(e){if(i?.aborted||v(e))break;c=!0,a=l.getQueryData(t)??a;break}}return{view:l.getQueryData(t)??a,failed:c,progressed:s}})();We.set(a,s);try{return await s}finally{We.get(a)===s&&We.delete(a)}},Ke=(e,r=t(),i=n(),a={})=>({queryKey:G.contact(e,r,i),queryFn:async({signal:t})=>{J(r,i),await p(),J(r,i);let n=G.contact(e,r,i),a=l.getQueryData(n),o=await He(e,{limit:20},t);J(r,i);let s=Ee(l.getQueryData(n)??a??null,o);l.setQueryData(n,s);let c=Q(n);if(s.hasMessageGap&&s.gapCursor){Z.delete(c);let a=await Ge(e,n,s,{transport:r,runtimeGeneration:i},t);s=a.view,(a.failed||a.view.hasMessageGap&&!a.progressed)&&a.view.gapCursor&&Z.set(c,a.view.gapCursor)}else Z.delete(c);J(r,i);let u=l.getQueryData(n)??s;return a&&Ue(a,u)?a:u},retry:2,staleTime:0,refetchInterval:()=>a.reconcileInForeground?Pe(l.getQueryData(G.snapshot(r)),{assistantID:e}):!1,refetchIntervalInBackground:!1,refetchOnWindowFocus:!0,refetchOnReconnect:!0,structuralSharing:!0}),qe=(e,r=!0)=>{let i=t(),a=n(),[o,u]=h.useState(!1),[d,f]=h.useState(null),[p,m]=h.useState(!1),g=h.useRef(null),_=h.useRef(null),y=h.useRef(null),b=h.useRef(null),x=h.useRef({assistantID:e,transport:i,runtimeGeneration:a,enabled:r});x.current={assistantID:e,transport:i,runtimeGeneration:a,enabled:r};let S=s({...Ke(e,i,a,{reconcileInForeground:!0}),enabled:r&&!!e});h.useEffect(()=>{!r||!e||l.invalidateQueries({queryKey:G.snapshot(i),exact:!0},{cancelRefetch:!1})},[e,r,a,i]),h.useEffect(()=>c(n=>{t()===i&&(n.type===`assistants-changed`||n.type===`event-stream-ready`||n.type===`contact-turn-end`)&&(n.type===`contact-turn-end`&&`assistantID`in n&&n.assistantID!==e||l.invalidateQueries({queryKey:G.contact(e,i,a),exact:!0}))}),[e,a,i]),h.useEffect(()=>{let t=Q(G.contact(e,i,a));return()=>{y.current?.abort(),b.current?.abort(),y.current=null,b.current=null,g.current=null,_.current=null,Z.delete(t)}},[e,i,a,r]);let C=S.data,w=G.contact(e,i,a),T=async()=>{if(!e||!r)return;if(g.current)return g.current;let t=l.getQueryData(w)??C;if(!t||t.olderComplete||!t.olderCursor)return;f(null),u(!0);let n=new AbortController;b.current?.abort(),b.current=n;let o={transport:i,runtimeGeneration:a,assistantID:e,cursor:t.olderCursor},s=(async()=>{try{J(o.transport,o.runtimeGeneration);let e=await He(o.assistantID,{limit:20,before:o.cursor},n.signal);if(n.signal.aborted||(J(o.transport,o.runtimeGeneration),x.current.assistantID!==o.assistantID||x.current.transport!==o.transport||x.current.runtimeGeneration!==o.runtimeGeneration))return;let r=l.getQueryData(w)??t;if(e.generation!==r.generation)return;l.setQueryData(w,De(r,e))}catch(e){if(n.signal.aborted||v(e))return;let t=e instanceof Error?e:Error(String(e));throw f(t),t}finally{b.current===n&&(b.current=null),u(!1),g.current=null}})();return g.current=s,s},E=async(t=`explicit`)=>{if(!e||!r)return;if(_.current)return _.current;let n=l.getQueryData(w)??C;if(!n?.hasMessageGap||!n.gapCursor)return;let o=Q(w);if(t===`auto`&&Z.get(o)===n.gapCursor)return;t===`explicit`&&Z.delete(o),m(!0);let s=new AbortController;y.current?.abort(),y.current=s;let c={transport:i,runtimeGeneration:a,assistantID:e,cursor:n.gapCursor},u=(async()=>{try{J(c.transport,c.runtimeGeneration);let e=await Ge(c.assistantID,w,n,{transport:c.transport,runtimeGeneration:c.runtimeGeneration},s.signal);if(s.signal.aborted)return;if(J(c.transport,c.runtimeGeneration),e.failed||!e.progressed){e.view.gapCursor&&Z.set(o,e.view.gapCursor);return}e.view.hasMessageGap||Z.delete(o)}catch(e){if(s.signal.aborted||v(e))return;throw Z.set(o,c.cursor),e}finally{y.current===s&&(y.current=null),m(!1),_.current=null}})();return _.current=u,u};return h.useEffect(()=>{if(!r||!e||!C?.hasMessageGap||!C.gapCursor||S.isFetching||p)return;let t=Q(w);Z.get(t)!==C.gapCursor&&E(`auto`).catch(()=>void 0)},[r,e,C?.hasMessageGap,C?.gapCursor,S.isFetching,p,w]),{data:C?{messages:C.messages,generation:C.generation,revision:C.revision,nextCursor:C.olderCursor,complete:C.olderComplete}:void 0,status:S.status,fetchStatus:S.fetchStatus,isError:S.isError,isPending:S.isPending,isFetching:S.isFetching,isSuccess:S.isSuccess,error:S.error instanceof Error?S.error:S.error?Error(String(S.error)):null,refetch:()=>S.refetch(),fetchPreviousPage:T,hasPreviousPage:!!(C&&!C.olderComplete&&C.olderCursor),isFetchingPreviousPage:o,previousPageError:d,hasMessageGap:!!C?.hasMessageGap,isFillingMessageGap:p,retryMessageGap:()=>E(`explicit`)}},Je=async(e,r)=>{let i=t(),a=n();await p(),J(i,a);let o=await He(e,{messageID:r,limit:1});if(J(i,a),!o.messages.some(e=>e.messageID===r&&e.role===`user`))return null;l.invalidateQueries({queryKey:G.contact(e,i,a),exact:!0}),l.invalidateQueries({queryKey:G.snapshot(i),exact:!0});let s=l.getQueryData(G.snapshot(i));return{admitted:!0,messageID:r,revision:o.revision??s?.revision??null}},Ye=(e,r=t(),i=n())=>({queryKey:G.scheduledTasks(e,r,i),queryFn:async({signal:t})=>{J(r,i);let n=ee(await K(`/api/yuri/assistants/${encodeURIComponent(e)}/scheduled-tasks`,{signal:t}));return J(r,i),n},refetchOnMount:`always`,retry:(e,t)=>!(t instanceof _&&t.status===404)&&e<2}),Xe=(e,r)=>{let i=(0,g.c)(6),a=r===void 0||r,o,c;if(i[0]!==e){let r=t(),a=n();c=s,o=Ye(e,r,a),i[0]=e,i[1]=o,i[2]=c}else o=i[1],c=i[2];let l=a&&!!e,u;return i[3]!==o||i[4]!==l?(u={...o,enabled:l},i[3]=o,i[4]=l,i[5]=u):u=i[5],c(u)},Ze=(e=t())=>({queryKey:G.globalScheduledTasks(e),queryFn:ce,refetchOnMount:`always`}),Qe=e=>{let t=(0,g.c)(3),n=e===void 0||e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=Ze(),t[0]=r):r=t[0];let i;return t[1]===n?i=t[2]:(i={...r,enabled:n},t[1]=n,t[2]=i),s(i)},$e=e=>e.tasks.some(({task:e})=>e.state.lastStatus===`running`),et=()=>{let e=(0,g.c)(5),n,r,i;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=t(),n=s,r={...Ze(i),select:$e,staleTime:0,refetchInterval:yt,refetchIntervalInBackground:!1},e[0]=n,e[1]=r,e[2]=i):(n=e[0],r=e[1],i=e[2]);let a=n(r),o,u;return e[3]===Symbol.for(`react.memo_cache_sentinel`)?(o=()=>c(e=>{t()===i&&(e.type===`scheduled-task-ran`||e.type===`event-stream-ready`)&&l.invalidateQueries({queryKey:Ze(i).queryKey,exact:!0})}),u=[i],e[3]=o,e[4]=u):(o=e[3],u=e[4]),h.useEffect(o,u),a.data===!0},tt=(e,r=t())=>{l.invalidateQueries({queryKey:[r,n(),`assistants`,`contact`,e]})},nt=(e=t())=>({queryKey:G.capability(e),queryFn:()=>gt(),retry:!1}),rt=()=>{let e=(0,g.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=nt(),e[0]=t):t=e[0],s(t)},it=(e=l,n=t())=>e.getQueryData(G.snapshot(n)),at=(e=l,n=t())=>e.fetchQuery(Y(n)),ot=async(e=l)=>{let r=t(),i=n();await e.invalidateQueries({queryKey:G.snapshot(r),exact:!0}),J(r,i);let a=await e.fetchQuery(Y(r));return J(r,i),a},st=15e3,ct=e=>{throw e instanceof _?e:v(e)?new _(`admission_timeout`,408):e},lt=async(e,r,i)=>{let a=t(),o=n(),s=typeof i==`string`?[{type:`text`,text:i}]:Array.isArray(i.parts)&&i.parts.length>0?i.parts:[{type:`text`,text:i.text??``}],c=AbortSignal.timeout(st);try{let t=R(await K(`/api/yuri/assistants/${encodeURIComponent(e)}/messages`,{...q(`POST`,{messageID:r,parts:s,language:u.getState().locale}),signal:c}));return J(a,o),ke(e,t.binding,a),tt(e,a),t}catch(e){return ct(e)}},ut=async(e,r,i,a,o)=>{let s=t(),c=n(),l=z(await K(`/api/yuri/assistants/${encodeURIComponent(e)}/share`,q(`POST`,{operationID:r,payload:{messageID:i,parts:a,source:o}})));return J(s,c),l},dt=async(e,r=t(),i=n())=>{J(r,i);let a=z(await K(`/api/yuri/assistants/share-operations/${encodeURIComponent(e)}`));return J(r,i),a},ft=async(e,r=t(),i=n())=>{let a=e;for(let e=0;e<60&&(a.state===`running`||a.state===`submitting`);e+=1)J(r,i),await new Promise(e=>setTimeout(e,750)),a=await dt(a.operationID,r,i);if(J(r,i),a.state===`completed`)return a;throw a.state===`failed`?new y(a.errorCode??`share_failed`,400,a):new y(`share_unresolved`,408,a)},pt=async e=>{let n=t(),r=F(await K(`/api/yuri/assistants`,q(`POST`,{...e,language:u.getState().locale})));return Ae(r,n),r},mt=async(e,r)=>{let i=t(),a=n(),o=F(await K(`/api/yuri/assistants/${encodeURIComponent(e.id)}`,q(`PATCH`,{...r,expectedRevision:e.revision})));return J(i,a),r.pinned===void 0?Ae(o,i):(await l.cancelQueries({queryKey:G.snapshot(i),exact:!0}),J(i,a),await l.fetchQuery(Y(i)),J(i,a)),o},ht=async e=>{await K(`/api/yuri/assistants/${encodeURIComponent(e.id)}`,q(`DELETE`,{expectedRevision:e.revision})),await l.invalidateQueries({queryKey:G.snapshot(t())})},gt=async()=>O(await K(`/api/yuri/assistants/capability`)),_t=async(e,r)=>{let i=t(),a=n(),o=M(r);try{let t=P(await K(`/api/yuri/assistants/${encodeURIComponent(e)}/contact/read`,{...q(`POST`,o),signal:AbortSignal.timeout(15e3)}));if(J(i,a),t.assistantID!==e)throw new _(`invalid_assistant_read_response`,200);return t}finally{t()===i&&n()===a&&l.invalidateQueries({queryKey:G.snapshot(i),exact:!0})}},vt=async e=>{let r=e.assistants.filter(e=>(e.unreadCount??0)>0&&e.readTip).map(e=>({id:e.id,position:{...e.readTip}})),i=t(),a=n(),o=[];for(let e=0;e<r.length;e+=4)o.push(...await Promise.allSettled(r.slice(e,e+4).map(async e=>(J(i,a),_t(e.id,e.position)))));return{failed:o.filter(e=>e.status===`rejected`).length}};function yt(e){return e.state.data&&$e(e.state.data)?2500:15e3}var $=i();function bt(e){let t=(0,g.c)(34),{title:n,className:r,subtitle:i,backAriaLabel:a,onBack:o,backDisabled:s,actions:c,trailing:l,sticky:u,overlay:p,elevated:h,collapsible:_}=e,v=s!==void 0&&s,y;t[0]===c?y=t[1]:(y=c===void 0?[]:c,t[0]=c,t[1]=y);let b=y,x=u!==void 0&&u,S=p!==void 0&&p,C=h!==void 0&&h,w=_!==void 0&&_,T=Array.isArray(l)?l.filter(Boolean).length:+!!l,E=C||b.some(St),D=w?`true`:void 0,O=x&&`yuri-mobile-detail-navigation-sticky`,k=S&&`absolute inset-x-0 top-0`,A=E?`z-[60]`:S?`z-30`:void 0,j;t[2]!==r||t[3]!==k||t[4]!==A||t[5]!==O?(j=f(`yuri-mobile-detail-navigation relative shrink-0 pt-[max(0.25rem,var(--yuri-safe-area-top,0px))]`,O,k,A,r),t[2]=r,t[3]=k,t[4]=A,t[5]=O,t[6]=j):j=t[6];let M=b.length+T>1?`grid-cols-[2.75rem_minmax(0,1fr)_auto]`:`grid-cols-[2.75rem_minmax(0,1fr)_2.75rem]`,N;t[7]===M?N=t[8]:(N=f(`yuri-mobile-detail-navigation-content grid items-center gap-1 px-4`,M),t[7]=M,t[8]=N);let P;t[9]!==a||t[10]!==v||t[11]!==o?(P=o?(0,$.jsx)(d,{type:`button`,variant:`mobileGlass`,size:`mobileIcon`,className:`justify-self-start`,onClick:o,disabled:v,"aria-label":a,children:(0,$.jsx)(m,{name:`arrow-left-s`,className:`size-5`})}):(0,$.jsx)(`span`,{"aria-hidden":`true`}),t[9]=a,t[10]=v,t[11]=o,t[12]=P):P=t[12];let F;t[13]===n?F=t[14]:(F=(0,$.jsx)(`div`,{className:`yuri-mobile-detail-title w-full truncate typography-ui-label font-medium text-foreground`,children:n}),t[13]=n,t[14]=F);let I;t[15]===i?I=t[16]:(I=i?(0,$.jsx)(`div`,{className:`yuri-mobile-detail-subtitle w-full truncate text-muted-foreground`,"aria-live":`polite`,children:i}):null,t[15]=i,t[16]=I);let L;t[17]!==F||t[18]!==I?(L=(0,$.jsxs)(`div`,{className:`flex w-full max-w-72 min-w-0 flex-col items-center justify-center justify-self-center px-1`,children:[F,I]}),t[17]=F,t[18]=I,t[19]=L):L=t[19];let R;t[20]===b?R=t[21]:(R=b.map(xt),t[20]=b,t[21]=R);let z;t[22]!==R||t[23]!==l?(z=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center justify-end gap-2`,children:[l,R]}),t[22]=R,t[23]=l,t[24]=z):z=t[24];let B;t[25]!==N||t[26]!==P||t[27]!==L||t[28]!==z?(B=(0,$.jsxs)(`div`,{className:N,children:[P,L,z]}),t[25]=N,t[26]=P,t[27]=L,t[28]=z,t[29]=B):B=t[29];let V;return t[30]!==j||t[31]!==B||t[32]!==D?(V=(0,$.jsx)(`header`,{"data-yuri-collapsible-header":D,className:j,children:B}),t[30]=j,t[31]=B,t[32]=D,t[33]=V):V=t[33],V}function xt(e,t){return(0,$.jsx)(d,{type:`button`,variant:`mobileGlass`,size:`mobileIcon`,className:f(e.elevated&&`relative z-[60]`),onClick:e.onClick,disabled:e.disabled,"aria-label":e.ariaLabel,"aria-expanded":e.pressed,title:e.title,children:(0,$.jsx)(m,{name:e.icon,className:`size-5`})},`${e.icon}:${t}`)}function St(e){return e.elevated}export{le as A,ft as C,ce as D,ue as E,y as M,v as N,se as O,et as S,pe as T,Xe as _,ht as a,Be as b,ot as c,it as d,lt as f,qe as g,rt as h,pt as i,_ as j,de as k,vt as l,mt as m,Ke as n,at as o,ut as p,Je as r,gt as s,bt as t,_t as u,Ie as v,me as w,Qe as x,Re as y};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,n}from"./runtime-switch-DEPKHgdL.js";import{n as r}from"./runtime-fetch-V-iMWR8t.js";import{ot as i,st as a}from"./vendor-base-ui-fom6orB6.js";import{n as o}from"./vendor-react-D5BntRmA.js";import{s}from"./vendor-tanstack-react-query-ChSd65dm.js";import{L as c,q as l}from"./runtime-file-resource-CKQQEwNv.js";import{i as u}from"./store-Dj5cSf8B.js";import{In as d,Rn as f,to as p}from"./useMobileNavigationStore-DW2W2RJB.js";import{n as m}from"./Icon-W44vi3ut.js";var h=e(a(),1),g=o(),_=class extends Error{code;status;resource;constructor(e,t,n,r){super(typeof r==`string`&&r.trim()?r.trim():e),this.code=e,this.status=t,this.resource=n}},v=e=>{if(!e||typeof e!=`object`)return!1;let t=`name`in e?String(e.name):``;return t===`AbortError`||t===`TimeoutError`},y=class extends _{operation;constructor(e,t,n){super(e,t,`share_operation`),this.operation=n}},b=(e,t=200)=>{throw new _(`invalid_${e}_response`,t,e)},x=(e,t)=>e&&typeof e==`object`&&!Array.isArray(e)?e:b(t),S=(e,t)=>typeof e==`string`?e:b(t),C=(e,t)=>e===null||typeof e==`string`?e:b(t),w=(e,t)=>typeof e==`number`&&Number.isFinite(e)?e:b(t),T=(e,t)=>e===null?null:w(e,t),E=(e,t)=>typeof e==`boolean`?e:b(t),D=(e,t,n)=>t.includes(e)?e:b(n),O=e=>{let t=x(e,`capability`);return{supported:E(t.supported,`capability`),enabled:E(t.enabled,`capability`),revision:w(t.revision,`capability`),serverInstanceID:C(t.serverInstanceID,`capability`),sharingAvailable:t.sharingAvailable!==void 0&&E(t.sharingAvailable,`capability`)}},k=e=>{if(e==null)return null;let t=x(e,`assistant`);return{turnID:S(t.turnID,`assistant`),messageID:S(t.messageID,`assistant`),status:D(t.status,[`queued`,`running`],`assistant`),admittedAt:w(t.admittedAt,`assistant`)}},A=e=>{if(e==null)return null;let t=x(e,`assistant_preview`),n=w(t.ordinal,`assistant_preview`);return!Number.isSafeInteger(n)||n<0?b(`assistant_preview`):{...t.createdAt===void 0?{}:{createdAt:w(t.createdAt,`assistant_preview`)},messageID:S(t.messageID,`assistant_preview`),ordinal:n,role:D(t.role,[`user`,`assistant`],`assistant_preview`),text:S(t.text,`assistant_preview`),fallbackKind:t.fallbackKind===null?null:D(t.fallbackKind,[`image`,`file`,`session`,`assistant`,`schedule`],`assistant_preview`)}},j=e=>{let t=w(e,`assistant_read`);return Number.isSafeInteger(t)&&t>=0?t:b(`assistant_read`)},M=e=>{let t=x(e,`assistant_read`);return{generation:j(t.generation),ordinal:j(t.ordinal),messageID:S(t.messageID,`assistant_read`)}},N=e=>({unreadCount:e.unreadCount===void 0?0:j(e.unreadCount),readWatermark:e.readWatermark==null?null:M(e.readWatermark),readTip:e.readTip==null?null:M(e.readTip)}),P=e=>{let t=x(e,`assistant_read`);return{assistantID:S(t.assistantID,`assistant_read`),changed:E(t.changed,`assistant_read`),unreadCount:j(t.unreadCount),readWatermark:M(t.readWatermark),readTip:M(t.readTip),revision:j(t.revision)}},F=e=>{let t=x(e,`assistant`),n=Array.isArray(t.historySessionIDs)?t.historySessionIDs.map(e=>S(e,`assistant`)):[],r=t.historySessionCount===void 0?n.length:w(t.historySessionCount,`assistant`);if(!Number.isSafeInteger(r)||r<n.length)return b(`assistant`);let i=Array.isArray(t.assignedSessionIDs)?t.assignedSessionIDs.map(e=>S(e,`assistant`)):[],a=t.activeContactTurn===void 0?null:k(t.activeContactTurn),o=t.working===void 0?a!=null:E(t.working,`assistant`);return{...N(t),pinnedAt:t.pinnedAt===void 0?void 0:T(t.pinnedAt,`assistant`),latestMessagePreview:A(t.latestMessagePreview),id:S(t.id,`assistant`),avatarSeed:S(t.avatarSeed??t.id,`assistant`),revision:w(t.revision,`assistant`),enabled:E(t.enabled,`assistant`),name:S(t.name,`assistant`),defaultPrompt:S(t.defaultPrompt,`assistant`),workspacePath:C(t.workspacePath,`assistant`),effectiveWorkspacePath:S(t.effectiveWorkspacePath,`assistant`),managedWorkspacePath:C(t.managedWorkspacePath??null,`assistant`),providerID:S(t.providerID,`assistant`),modelID:S(t.modelID,`assistant`),agent:C(t.agent,`assistant`),variant:C(t.variant??null,`assistant`),mode:D(t.mode,[`continuous`,`stateless`],`assistant`),sessionID:C(t.sessionID,`assistant`),sessionGeneration:w(t.sessionGeneration,`assistant`),historySessionIDs:n,historySessionCount:r,assignedSessionIDs:i,working:o,activeContactTurn:a,createdAt:T(t.createdAt,`assistant`),updatedAt:w(t.updatedAt,`assistant`),tombstoneAt:T(t.tombstoneAt,`assistant`)}},I=e=>{let t=x(e,`snapshot`);return{revision:w(t.revision,`snapshot`),enabled:E(t.enabled,`snapshot`),assistants:Array.isArray(t.assistants)?t.assistants.map(F):b(`snapshot`)}},L=e=>{let t=x(e,`binding`);return{sessionID:C(t.sessionID,`binding`),directory:S(t.directory,`binding`),sessionGeneration:w(t.sessionGeneration,`binding`)}},R=e=>{let t=x(e,`message_admission`);if(t.admitted!==!0)return b(`message_admission`);let n=t.revision===void 0||t.revision===null?null:w(t.revision,`message_admission`);return{binding:L(t.binding),messageID:S(t.messageID,`message_admission`),admitted:!0,revision:n,...t.replayed===!0?{replayed:!0}:{}}},z=e=>{let t=x(e,`share_operation`);return{operationID:S(t.operationID,`share_operation`),assistantID:S(t.assistantID,`share_operation`),sessionID:C(t.sessionID,`share_operation`),messageID:C(t.messageID,`share_operation`),state:D(t.state,[`submitting`,`running`,`completed`,`failed`,`unresolved`],`share_operation`),phase:S(t.phase,`share_operation`),attempt:w(t.attempt,`share_operation`),leaseExpiresAt:T(t.leaseExpiresAt,`share_operation`),errorCode:C(t.errorCode,`share_operation`)}},B=e=>{let t=x(e,`assistant_contact_part`);if(t.type===`text`)return{type:`text`,text:S(t.text,`assistant_contact_part`)};if(t.type===`file`){let e=t.filename===void 0||t.filename===null?void 0:S(t.filename,`assistant_contact_part`),n=S(t.mime,`assistant_contact_part`),r=t.url!==void 0&&t.url!==null,i=t.attachmentID!==void 0&&t.attachmentID!==null;if(r&&i)return b(`assistant_contact_part`);if(i){let r=w(t.size,`assistant_contact_part`);return!Number.isSafeInteger(r)||r<0?b(`assistant_contact_part`):{type:`file`,mime:n,attachmentID:S(t.attachmentID,`assistant_contact_part`),sha256:S(t.sha256,`assistant_contact_part`),size:r,...e?{filename:e}:{}}}return r?{type:`file`,mime:n,url:S(t.url,`assistant_contact_part`),...e?{filename:e}:{}}:b(`assistant_contact_part`)}if(t.type===`card`){let e=D(t.cardType,[`session`,`assistant`,`schedule`],`assistant_contact_part`);if(e===`session`){let e;if(t.target!==void 0){let n=x(t.target,`assistant_contact_part`),r=e=>{let t=S(n[e],`assistant_contact_part`);return!t||t!==t.trim()||t.length>512||Array.from(t).some(e=>e.charCodeAt(0)<32)?b(`assistant_contact_part`):t};e={hubId:r(`hubId`),hostId:r(`hostId`),instanceId:r(`instanceId`)}}return{type:`card`,cardType:`session`,sessionID:S(t.sessionID,`assistant_contact_part`),directory:S(t.directory,`assistant_contact_part`),title:C(t.title??null,`assistant_contact_part`),status:C(t.status??null,`assistant_contact_part`),branch:C(t.branch??null,`assistant_contact_part`),...e?{target:e}:{}}}return e===`assistant`?{type:`card`,cardType:`assistant`,assistantID:S(t.assistantID,`assistant_contact_part`),name:S(t.name,`assistant_contact_part`),providerID:S(t.providerID,`assistant_contact_part`),modelID:S(t.modelID,`assistant_contact_part`),mode:D(t.mode??`continuous`,[`continuous`,`stateless`],`assistant_contact_part`)}:{type:`card`,cardType:`schedule`,taskID:S(t.taskID,`assistant_contact_part`),projectID:S(t.projectID,`assistant_contact_part`),name:S(t.name,`assistant_contact_part`),kind:C(t.kind??null,`assistant_contact_part`),time:C(t.time??null,`assistant_contact_part`),timezone:C(t.timezone??null,`assistant_contact_part`),prompt:C(t.prompt??null,`assistant_contact_part`),...t.cron===void 0?{}:{cron:C(t.cron,`assistant_contact_part`)},...t.date===void 0?{}:{date:C(t.date,`assistant_contact_part`)},...t.times===void 0?{}:{times:t.times===null?null:Array.isArray(t.times)?t.times.map(e=>S(e,`assistant_contact_part`)):b(`assistant_contact_part`)},...t.weekdays===void 0?{}:{weekdays:t.weekdays===null?null:Array.isArray(t.weekdays)?t.weekdays.map(e=>{let t=w(e,`assistant_contact_part`);return Number.isInteger(t)&&t>=0&&t<=6?t:b(`assistant_contact_part`)}):b(`assistant_contact_part`)}}}return b(`assistant_contact_part`)},V=e=>{let t=x(e,`assistant_contact`),n=C(t.nextCursor,`assistant_contact`),r=E(t.complete,`assistant_contact`);if(!r&&!n||r&&n||!Array.isArray(t.messages))return b(`assistant_contact`);let i=w(t.generation,`assistant_contact`),a=w(t.revision,`assistant_contact`);return!Number.isSafeInteger(i)||i<0||!Number.isSafeInteger(a)||a<0?b(`assistant_contact`):{messages:t.messages.map(e=>{let t=x(e,`assistant_contact_message`);if(!Array.isArray(t.parts))return b(`assistant_contact_message`);let n=t.parts.map(B);return{messageID:S(t.messageID,`assistant_contact_message`),assistantID:S(t.assistantID,`assistant_contact_message`),role:D(t.role,[`user`,`assistant`,`peer`],`assistant_contact_message`),turnID:S(t.turnID,`assistant_contact_message`),bubbleIndex:w(t.bubbleIndex,`assistant_contact_message`),createdAt:w(t.createdAt,`assistant_contact_message`),ordinal:w(t.ordinal,`assistant_contact_message`),status:S(t.status,`assistant_contact_message`),fromAssistantID:C(t.fromAssistantID??null,`assistant_contact_message`),fromAssistantName:C(t.fromAssistantName??null,`assistant_contact_message`),parts:n,text:typeof t.text==`string`?t.text:n.filter(e=>e.type===`text`).map(e=>e.text).join(``),cards:n.filter(e=>e.type===`card`)}}),nextCursor:n,complete:r,generation:i,revision:a}},ee=e=>{let t=x(e,`assistant_scheduled_tasks`);return Array.isArray(t.tasks)?{tasks:t.tasks.map(e=>{let t=x(e,`assistant_scheduled_task`),n=t.task===null||t.task===void 0?null:x(t.task,`assistant_scheduled_task_live`);return{assistantID:S(t.assistantID,`assistant_scheduled_task`),projectID:S(t.projectID,`assistant_scheduled_task`),taskID:S(t.taskID,`assistant_scheduled_task`),createdAt:w(t.createdAt,`assistant_scheduled_task`),projectPath:C(t.projectPath??null,`assistant_scheduled_task`),projectLabel:C(t.projectLabel??null,`assistant_scheduled_task`),task:n}})}:b(`assistant_scheduled_tasks`)},H=async(e,t)=>{try{let t=await e.json();if(t&&typeof t.error==`string`&&t.error.trim().length>0)return t.error}catch{return t}return t},U=e=>{let t=typeof e==`string`?e.trim():``;if(!t)throw Error(`projectId is required`);return t},te=e=>e===null||typeof e==`string`,ne=e=>e===null||typeof e==`number`&&Number.isFinite(e),re=e=>typeof e==`number`&&Number.isFinite(e)&&e>=0&&e<=864e13,ie=e=>e===null||re(e),ae=e=>{if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return typeof t.id==`string`&&t.id.length>0&&typeof t.projectId==`string`&&t.projectId.length>0&&typeof t.taskId==`string`&&t.taskId.length>0&&typeof t.taskName==`string`&&(t.trigger===`scheduled`||t.trigger===`manual`)&&(t.status===`running`||t.status===`success`||t.status===`error`)&&te(t.sessionId)&&te(t.directory)&&te(t.error)&&re(t.startedAt)&&ie(t.finishedAt)&&ne(t.durationMs)&&(t.durationMs===null||t.durationMs>=0)},oe=e=>{if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`Malformed scheduled task runs response`);let t=e;if(!Array.isArray(t.runs)||!t.runs.every(ae)||!te(t.nextCursor)||typeof t.complete!=`boolean`||t.complete!==(t.nextCursor===null)||t.nextCursor!==null&&t.nextCursor.length===0)throw Error(`Malformed scheduled task runs response`);return{runs:t.runs,nextCursor:t.nextCursor,complete:t.complete}},se=async(e,t)=>{let n=new URLSearchParams;e.before&&n.set(`before`,e.before);let i=e.limit??20;if(!Number.isInteger(i)||i<1)throw Error(`limit must be a positive integer`);n.set(`limit`,String(i)),e.projectId&&n.set(`projectId`,e.projectId),e.taskId&&n.set(`taskId`,e.taskId);let a=await r(`/api/yuri/scheduled-task-runs?${n.toString()}`,{signal:t});if(!a.ok)throw Error(await H(a,`Failed to load scheduled task history`));return oe(await a.json().catch(()=>null))},ce=async({signal:e}={})=>{let t=await r(`/api/yuri/scheduled-tasks`,{signal:e});if(!t.ok)throw Error(await H(t,`Failed to load schedules`));let n=await t.json().catch(()=>null);if(!n||!Array.isArray(n.tasks))throw Error(`Malformed schedules response`);return{tasks:Array.isArray(n?.tasks)?n.tasks:[],failedProjectIds:Array.isArray(n?.failedProjectIds)?n.failedProjectIds.filter(e=>typeof e==`string`):[]}},le=async(e,t)=>{let n=U(e),i=await r(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks`,{method:`PUT`,headers:{"content-type":`application/json`,accept:`application/json`},body:JSON.stringify({task:t})});if(!i.ok)throw Error(await H(i,`Failed to save schedule`));let a=await i.json().catch(()=>null);return!a||!Array.isArray(a.tasks)?[]:a.tasks},ue=async(e,t)=>{let n=U(e),i=U(t),a=await r(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks/${encodeURIComponent(i)}`,{method:`DELETE`,headers:{accept:`application/json`}});if(!a.ok)throw Error(await H(a,`Failed to delete schedule`));let o=await a.json().catch(()=>null);return!o||!Array.isArray(o.tasks)?[]:o.tasks},de=async(e,t)=>{let n=U(e),i=U(t),a=await r(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks/${encodeURIComponent(i)}/run`,{method:`POST`,headers:{accept:`application/json`}});if(!a.ok)throw Error(await H(a,`Failed to run schedule`));let o=await a.json().catch(()=>null);return{sessionId:typeof o?.sessionId==`string`&&o.sessionId.length>0?o.sessionId:void 0}},fe=(e,t)=>e.ordinal===t.ordinal?e.messageID<t.messageID?-1:+(e.messageID>t.messageID):e.ordinal-t.ordinal,pe=e=>{if(e.type===`file`||e.type===`card`)return!0;if(e.type!==`text`)return!1;let t=typeof e.text==`string`?e.text.trim():``;return!!t&&!t.startsWith(`yuri.settle.`)&&!t.startsWith(`oc.settle.`)},me=(e,t)=>{if(!t||!e.readTip||!((e.unreadCount??0)>0))return null;let n=e.readTip;if(t.generation!==n.generation)return null;let r;for(let n=t.messages.length-1;n>=0;--n){let i=t.messages[n];if(i.assistantID===e.id&&(i.status===`complete`||i.status===`error`)&&i.parts.some(pe)){r=i;break}}if(!r)return null;let i=e.readWatermark;return i&&(i.generation>t.generation||i.generation===t.generation&&fe({ordinal:i.ordinal,messageID:i.messageID},{ordinal:r.ordinal,messageID:r.messageID})>=0)?null:{generation:t.generation,ordinal:r.ordinal,messageID:r.messageID}},he=()=>({messages:[],generation:-1,revision:0,olderCursor:null,olderComplete:!0,hasMessageGap:!1,gapCursor:null,gapRequestIDs:null,gapTargetIDs:null,liveWindowIDs:[]}),ge=e=>!!(e&&e.generation>=0),_e=(e,t)=>fe({ordinal:e.ordinal,messageID:e.messageID},{ordinal:t.ordinal,messageID:t.messageID}),W=(e,t,n=`incoming`)=>{let r=new Map;for(let t of e)r.set(t.messageID,t);for(let e of t)(n===`incoming`||!r.has(e.messageID))&&r.set(e.messageID,e);return[...r.values()].sort(_e)},ve=e=>{let t=1/0;for(let n of e)n.ordinal<t&&(t=n.ordinal);return Number.isFinite(t)?t:null},ye=e=>e.map(e=>e.messageID),be=(e,t)=>{for(let n of e)if(t.has(n))return!0;return!1},xe=e=>new Set(e),Se=(e,t)=>!e||!t||e.length!==t.length?!1:e.every((e,n)=>e===t[n]),Ce=e=>({...e,hasMessageGap:!1,gapCursor:null,gapRequestIDs:null,gapTargetIDs:null}),we=e=>({ordinal:e.ordinal,messageID:e.messageID}),Te=(e,t,n)=>{if(n)return[...t];if(t.length===0)return[...e];let r=t[0];return[...e.filter(e=>fe(we(e),we(r))<0),...t]},Ee=(e,t)=>{let n=e??he(),r=ge(n),i=[...t.messages].sort(_e),a=ye(i);if(r&&t.generation<n.generation)return n;if(r&&t.generation>n.generation)return{messages:i,generation:t.generation,revision:t.revision,olderCursor:t.nextCursor,olderComplete:t.complete,hasMessageGap:!1,gapCursor:null,gapRequestIDs:null,gapTargetIDs:null,liveWindowIDs:a};if(!r)return{messages:i,generation:t.generation,revision:t.revision,olderCursor:t.complete?null:t.nextCursor,olderComplete:t.complete,hasMessageGap:!1,gapCursor:null,gapRequestIDs:null,gapTargetIDs:null,liveWindowIDs:a};let o=Math.max(n.revision,t.revision),s=t.revision>=n.revision;if(i.length===0)return s&&t.complete?{messages:[],generation:t.generation,revision:o,olderCursor:null,olderComplete:!0,hasMessageGap:!1,gapCursor:null,gapRequestIDs:null,gapTargetIDs:null,liveWindowIDs:[]}:{...n,generation:t.generation,revision:o,olderCursor:n.olderCursor??t.nextCursor,olderComplete:n.olderComplete&&t.complete,liveWindowIDs:[],hasMessageGap:n.hasMessageGap,gapCursor:n.hasMessageGap?t.nextCursor??n.gapCursor:null,gapRequestIDs:n.hasMessageGap?n.gapRequestIDs:null,gapTargetIDs:n.hasMessageGap?n.gapTargetIDs:null};let c;if(s)c=Te(n.messages,i,t.complete);else{let e=ve(i);c=W(n.messages.filter(t=>t.ordinal<e),W(n.messages.filter(t=>t.ordinal>=e),i,`existing`),`incoming`)}let l=n.liveWindowIDs,u=xe(a),d=l.length>0&&be(l,u),f=n.hasMessageGap,p=n.gapCursor,m=n.gapRequestIDs,h=n.gapTargetIDs;if(!d&&l.length>0&&t.nextCursor){f=!0,p=t.nextCursor;let e=l.filter(e=>!u.has(e));m=e.length>0?e:[...l],h=n.hasMessageGap&&n.gapTargetIDs&&n.gapTargetIDs.length>0?n.gapTargetIDs:m}else n.hasMessageGap?(f=!0,p=n.gapCursor,m=n.gapRequestIDs,h=n.gapTargetIDs):(f=!1,p=null,m=null,h=null);return{messages:c,generation:t.generation,revision:o,olderCursor:n.liveWindowIDs.length===0&&n.messages.length===0?t.complete?null:t.nextCursor:n.olderCursor,olderComplete:!r||n.liveWindowIDs.length===0&&n.messages.length===0?t.complete:n.olderComplete,hasMessageGap:f,gapCursor:f?p:null,gapRequestIDs:f?m:null,gapTargetIDs:f?h:null,liveWindowIDs:a}},De=(e,t)=>{if(!ge(e)||t.generation!==e.generation)return e;let n=t.revision>=e.revision?`incoming`:`existing`,r=W(e.messages,t.messages,n);return{...e,messages:r,revision:Math.max(e.revision,t.revision),olderCursor:t.complete?null:t.nextCursor,olderComplete:t.complete}},Oe=(e,t,n)=>{if(!ge(e)||t.generation!==e.generation)return e;let r=t.revision>=e.revision?`incoming`:`existing`,i=W(e.messages,t.messages,r),a=Math.max(e.revision,t.revision),o=n?.requestIDs??e.gapRequestIDs;if(!(e.hasMessageGap&&o&&e.gapRequestIDs&&Se(o,e.gapRequestIDs)))return{...e,messages:i,revision:a};let s=ye(t.messages),c=e.gapTargetIDs??[],l=xe(c);return c.length>0&&be(s,l)||t.complete||!t.nextCursor?Ce({...e,messages:i,revision:a}):{...e,messages:i,revision:a,hasMessageGap:!0,gapCursor:t.nextCursor??e.gapCursor,gapRequestIDs:e.gapRequestIDs,gapTargetIDs:e.gapTargetIDs}},G={snapshot:(e=t())=>[e,`assistants`,`snapshot`],capability:(e=t())=>[e,`assistants`,`capability`],history:(e,r,i,a=t(),o=n())=>[a,o,`assistants`,`history`,e,r,i],contact:(e,r=t(),i=n())=>[r,i,`assistants`,`contact`,e],scheduledTasks:(e,r=t(),i=n())=>[r,i,`assistants`,`scheduled-tasks`,e],globalScheduledTasks:(e=t())=>[e,`scheduled-tasks`]},K=async(e,t={})=>{let n=await r(e,t),i=await n.json().catch(()=>null);if(!n.ok){let e=i&&typeof i==`object`&&`error`in i&&typeof i.error==`string`?i.error:`request_failed`,t=i&&typeof i==`object`&&`message`in i&&typeof i.message==`string`?i.message:void 0;throw new _(e,n.status,void 0,t)}return i},q=(e,t)=>({method:e,headers:{"Content-Type":`application/json`},body:t===void 0?void 0:JSON.stringify(t)}),J=(e,r)=>{if(t()!==e||n()!==r)throw new _(`runtime_stale`,409)},ke=(e,t,r)=>{l.setQueryData(G.snapshot(r),n=>n&&{...n,assistants:n.assistants.map(n=>n.id!==e||n.sessionGeneration>t.sessionGeneration?n:{...n,sessionID:t.sessionID,sessionGeneration:t.sessionGeneration,effectiveWorkspacePath:t.directory})}),l.invalidateQueries({queryKey:G.snapshot(r)}),l.invalidateQueries({queryKey:[r,n(),`assistants`,`history`,e]})},Ae=(e,t)=>{l.setQueryData(G.snapshot(t),t=>t&&{...t,assistants:t.assistants.some(t=>t.id===e.id)?t.assistants.map(t=>t.id===e.id?e:t):[...t.assistants,e]}),l.invalidateQueries({queryKey:G.snapshot(t)})},je=2500,Me=15e3,Ne=e=>!!e?.assistants.some(e=>e.working||e.activeContactTurn),Pe=(e,t={})=>{if(t.assistantID){let n=e?.assistants.find(e=>e.id===t.assistantID);return n?.working||n?.activeContactTurn?je:Me}return Ne(e)?je:Me},Y=(e=t())=>({queryKey:G.snapshot(e),queryFn:async({signal:e})=>I(await K(`/api/yuri/assistants/snapshot`,{signal:e})),staleTime:0,retry:2,refetchInterval:e=>Pe(e.state.data),refetchIntervalInBackground:!1,refetchOnWindowFocus:!0,refetchOnReconnect:!0}),X=new Map,Fe=e=>{let r=X.get(e);if(r)r.count+=1;else{let r=n(),i=!1,a=!1,o=!1,s=()=>!i&&t()===e&&n()===r,u=async()=>{if(o=!0,!a){a=!0;try{do o=!1,l.getQueryCache().find({queryKey:G.snapshot(e),exact:!0})?.state.fetchStatus===`fetching`&&(o=!0),await l.invalidateQueries({queryKey:G.snapshot(e),exact:!0},{cancelRefetch:!1});while(o&&s())}finally{a=!1}}},d=c(t=>{if(!s())return;let n=l.getQueryData(G.snapshot(e));(t.type===`event-stream-ready`||t.type===`contact-turn-start`||t.type===`contact-turn-end`||t.type===`assistants-changed`&&(!n||t.revision>n.revision))&&u()});X.set(e,{count:1,dispose:()=>{i=!0,d()}})}return()=>{let t=X.get(e);t&&--t.count===0&&(t.dispose(),X.delete(e))}},Ie=e=>{let n=(0,g.c)(7),r,i,a;n[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=t(),i=s,r=Y(a),n[0]=r,n[1]=i,n[2]=a):(r=n[0],i=n[1],a=n[2]);let o;n[3]===e?o=n[4]:(o={...r,select:e},n[3]=e,n[4]=o);let c=i(o),l,u;return n[5]===Symbol.for(`react.memo_cache_sentinel`)?(l=()=>Fe(a),u=[a],n[5]=l,n[6]=u):(l=n[5],u=n[6]),h.useEffect(l,u),c},Le=e=>e.enabled?e.assistants.reduce((e,t)=>e+(t.unreadCount??0),0):0,Re=()=>{let e=(0,g.c)(5),n,r,i;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=t(),n=s,r={...Y(i),select:Le},e[0]=n,e[1]=r,e[2]=i):(n=e[0],r=e[1],i=e[2]);let a=n(r),o,c;return e[3]===Symbol.for(`react.memo_cache_sentinel`)?(o=()=>Fe(i),c=[i],e[3]=o,e[4]=c):(o=e[3],c=e[4]),h.useEffect(o,c),a.data??0},ze=e=>e.enabled&&Ne(e),Be=()=>{let e=(0,g.c)(5),n,r,i;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=t(),n=s,r={...Y(i),select:ze},e[0]=n,e[1]=r,e[2]=i):(n=e[0],r=e[1],i=e[2]);let a=n(r),o,c;return e[3]===Symbol.for(`react.memo_cache_sentinel`)?(o=()=>Fe(i),c=[i],e[3]=o,e[4]=c):(o=e[3],c=e[4]),h.useEffect(o,c),a.data??!1},Ve=(e,t={})=>{let n=new URLSearchParams;return n.set(`limit`,String(t.limit??20)),t.before&&n.set(`before`,t.before),t.messageID&&n.set(`messageID`,t.messageID),`/api/yuri/assistants/${encodeURIComponent(e)}/contact/messages?${n}`},He=async(e,t,n)=>V(await K(Ve(e,t),n?{signal:n}:{})),Ue=(e,t)=>e.generation===t.generation&&e.revision===t.revision&&e.olderCursor===t.olderCursor&&e.olderComplete===t.olderComplete&&e.hasMessageGap===t.hasMessageGap&&e.gapCursor===t.gapCursor&&e.messages===t.messages&&e.liveWindowIDs===t.liveWindowIDs&&e.gapRequestIDs===t.gapRequestIDs&&e.gapTargetIDs===t.gapTargetIDs,Z=new Map,We=new Map,Q=e=>e.join(``),Ge=async(e,t,n,r,i)=>{let a=Q(t),o=We.get(a);if(o)return o;let s=(async()=>{let a=l.getQueryData(t)??n,o=0,s=!1,c=!1,u=a.gapRequestIDs?[...a.gapRequestIDs]:null,d=a.gapCursor;for(;a.hasMessageGap&&a.gapCursor&&o<5&&!i?.aborted;){J(r.transport,r.runtimeGeneration),o+=1;let n=a.gapCursor;try{let o=await He(e,{limit:20,before:n},i);J(r.transport,r.runtimeGeneration);let c=l.getQueryData(t)??a;if(o.generation!==c.generation){a=c;break}let f=!u||!!(c.hasMessageGap&&c.gapRequestIDs&&c.gapRequestIDs.length===u.length&&c.gapRequestIDs.every((e,t)=>e===u[t]));if(a=Oe(c,o,u?{requestIDs:u,cursor:d}:void 0),l.setQueryData(t,a),!f)break;if(!a.hasMessageGap){s=!0;break}if(a.gapCursor&&a.gapCursor!==n)s=!0;else break}catch(e){if(i?.aborted||v(e))break;c=!0,a=l.getQueryData(t)??a;break}}return{view:l.getQueryData(t)??a,failed:c,progressed:s}})();We.set(a,s);try{return await s}finally{We.get(a)===s&&We.delete(a)}},Ke=(e,r=t(),i=n(),a={})=>({queryKey:G.contact(e,r,i),queryFn:async({signal:t})=>{J(r,i),await p(),J(r,i);let n=G.contact(e,r,i),a=l.getQueryData(n),o=await He(e,{limit:20},t);J(r,i);let s=Ee(l.getQueryData(n)??a??null,o);l.setQueryData(n,s);let c=Q(n);if(s.hasMessageGap&&s.gapCursor){Z.delete(c);let a=await Ge(e,n,s,{transport:r,runtimeGeneration:i},t);s=a.view,(a.failed||a.view.hasMessageGap&&!a.progressed)&&a.view.gapCursor&&Z.set(c,a.view.gapCursor)}else Z.delete(c);J(r,i);let u=l.getQueryData(n)??s;return a&&Ue(a,u)?a:u},retry:2,staleTime:0,refetchInterval:()=>a.reconcileInForeground?Pe(l.getQueryData(G.snapshot(r)),{assistantID:e}):!1,refetchIntervalInBackground:!1,refetchOnWindowFocus:!0,refetchOnReconnect:!0,structuralSharing:!0}),qe=(e,r=!0)=>{let i=t(),a=n(),[o,u]=h.useState(!1),[d,f]=h.useState(null),[p,m]=h.useState(!1),g=h.useRef(null),_=h.useRef(null),y=h.useRef(null),b=h.useRef(null),x=h.useRef({assistantID:e,transport:i,runtimeGeneration:a,enabled:r});x.current={assistantID:e,transport:i,runtimeGeneration:a,enabled:r};let S=s({...Ke(e,i,a,{reconcileInForeground:!0}),enabled:r&&!!e});h.useEffect(()=>{!r||!e||l.invalidateQueries({queryKey:G.snapshot(i),exact:!0},{cancelRefetch:!1})},[e,r,a,i]),h.useEffect(()=>c(n=>{t()===i&&(n.type===`assistants-changed`||n.type===`event-stream-ready`||n.type===`contact-turn-end`)&&(n.type===`contact-turn-end`&&`assistantID`in n&&n.assistantID!==e||l.invalidateQueries({queryKey:G.contact(e,i,a),exact:!0}))}),[e,a,i]),h.useEffect(()=>{let t=Q(G.contact(e,i,a));return()=>{y.current?.abort(),b.current?.abort(),y.current=null,b.current=null,g.current=null,_.current=null,Z.delete(t)}},[e,i,a,r]);let C=S.data,w=G.contact(e,i,a),T=async()=>{if(!e||!r)return;if(g.current)return g.current;let t=l.getQueryData(w)??C;if(!t||t.olderComplete||!t.olderCursor)return;f(null),u(!0);let n=new AbortController;b.current?.abort(),b.current=n;let o={transport:i,runtimeGeneration:a,assistantID:e,cursor:t.olderCursor},s=(async()=>{try{J(o.transport,o.runtimeGeneration);let e=await He(o.assistantID,{limit:20,before:o.cursor},n.signal);if(n.signal.aborted||(J(o.transport,o.runtimeGeneration),x.current.assistantID!==o.assistantID||x.current.transport!==o.transport||x.current.runtimeGeneration!==o.runtimeGeneration))return;let r=l.getQueryData(w)??t;if(e.generation!==r.generation)return;l.setQueryData(w,De(r,e))}catch(e){if(n.signal.aborted||v(e))return;let t=e instanceof Error?e:Error(String(e));throw f(t),t}finally{b.current===n&&(b.current=null),u(!1),g.current=null}})();return g.current=s,s},E=async(t=`explicit`)=>{if(!e||!r)return;if(_.current)return _.current;let n=l.getQueryData(w)??C;if(!n?.hasMessageGap||!n.gapCursor)return;let o=Q(w);if(t===`auto`&&Z.get(o)===n.gapCursor)return;t===`explicit`&&Z.delete(o),m(!0);let s=new AbortController;y.current?.abort(),y.current=s;let c={transport:i,runtimeGeneration:a,assistantID:e,cursor:n.gapCursor},u=(async()=>{try{J(c.transport,c.runtimeGeneration);let e=await Ge(c.assistantID,w,n,{transport:c.transport,runtimeGeneration:c.runtimeGeneration},s.signal);if(s.signal.aborted)return;if(J(c.transport,c.runtimeGeneration),e.failed||!e.progressed){e.view.gapCursor&&Z.set(o,e.view.gapCursor);return}e.view.hasMessageGap||Z.delete(o)}catch(e){if(s.signal.aborted||v(e))return;throw Z.set(o,c.cursor),e}finally{y.current===s&&(y.current=null),m(!1),_.current=null}})();return _.current=u,u};return h.useEffect(()=>{if(!r||!e||!C?.hasMessageGap||!C.gapCursor||S.isFetching||p)return;let t=Q(w);Z.get(t)!==C.gapCursor&&E(`auto`).catch(()=>void 0)},[r,e,C?.hasMessageGap,C?.gapCursor,S.isFetching,p,w]),{data:C?{messages:C.messages,generation:C.generation,revision:C.revision,nextCursor:C.olderCursor,complete:C.olderComplete}:void 0,status:S.status,fetchStatus:S.fetchStatus,isError:S.isError,isPending:S.isPending,isFetching:S.isFetching,isSuccess:S.isSuccess,error:S.error instanceof Error?S.error:S.error?Error(String(S.error)):null,refetch:()=>S.refetch(),fetchPreviousPage:T,hasPreviousPage:!!(C&&!C.olderComplete&&C.olderCursor),isFetchingPreviousPage:o,previousPageError:d,hasMessageGap:!!C?.hasMessageGap,isFillingMessageGap:p,retryMessageGap:()=>E(`explicit`)}},Je=async(e,r)=>{let i=t(),a=n();await p(),J(i,a);let o=await He(e,{messageID:r,limit:1});if(J(i,a),!o.messages.some(e=>e.messageID===r&&e.role===`user`))return null;l.invalidateQueries({queryKey:G.contact(e,i,a),exact:!0}),l.invalidateQueries({queryKey:G.snapshot(i),exact:!0});let s=l.getQueryData(G.snapshot(i));return{admitted:!0,messageID:r,revision:o.revision??s?.revision??null}},Ye=(e,r=t(),i=n())=>({queryKey:G.scheduledTasks(e,r,i),queryFn:async({signal:t})=>{J(r,i);let n=ee(await K(`/api/yuri/assistants/${encodeURIComponent(e)}/scheduled-tasks`,{signal:t}));return J(r,i),n},refetchOnMount:`always`,retry:(e,t)=>!(t instanceof _&&t.status===404)&&e<2}),Xe=(e,r)=>{let i=(0,g.c)(6),a=r===void 0||r,o,c;if(i[0]!==e){let r=t(),a=n();c=s,o=Ye(e,r,a),i[0]=e,i[1]=o,i[2]=c}else o=i[1],c=i[2];let l=a&&!!e,u;return i[3]!==o||i[4]!==l?(u={...o,enabled:l},i[3]=o,i[4]=l,i[5]=u):u=i[5],c(u)},Ze=(e=t())=>({queryKey:G.globalScheduledTasks(e),queryFn:ce,refetchOnMount:`always`}),Qe=e=>{let t=(0,g.c)(3),n=e===void 0||e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=Ze(),t[0]=r):r=t[0];let i;return t[1]===n?i=t[2]:(i={...r,enabled:n},t[1]=n,t[2]=i),s(i)},$e=e=>e.tasks.some(({task:e})=>e.state.lastStatus===`running`),et=()=>{let e=(0,g.c)(5),n,r,i;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=t(),n=s,r={...Ze(i),select:$e,staleTime:0,refetchInterval:yt,refetchIntervalInBackground:!1},e[0]=n,e[1]=r,e[2]=i):(n=e[0],r=e[1],i=e[2]);let a=n(r),o,u;return e[3]===Symbol.for(`react.memo_cache_sentinel`)?(o=()=>c(e=>{t()===i&&(e.type===`scheduled-task-ran`||e.type===`event-stream-ready`)&&l.invalidateQueries({queryKey:Ze(i).queryKey,exact:!0})}),u=[i],e[3]=o,e[4]=u):(o=e[3],u=e[4]),h.useEffect(o,u),a.data===!0},tt=(e,r=t())=>{l.invalidateQueries({queryKey:[r,n(),`assistants`,`contact`,e]})},nt=(e=t())=>({queryKey:G.capability(e),queryFn:()=>gt(),retry:!1}),rt=()=>{let e=(0,g.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=nt(),e[0]=t):t=e[0],s(t)},it=(e=l,n=t())=>e.getQueryData(G.snapshot(n)),at=(e=l,n=t())=>e.fetchQuery(Y(n)),ot=async(e=l)=>{let r=t(),i=n();await e.invalidateQueries({queryKey:G.snapshot(r),exact:!0}),J(r,i);let a=await e.fetchQuery(Y(r));return J(r,i),a},st=15e3,ct=e=>{throw e instanceof _?e:v(e)?new _(`admission_timeout`,408):e},lt=async(e,r,i)=>{let a=t(),o=n(),s=typeof i==`string`?[{type:`text`,text:i}]:Array.isArray(i.parts)&&i.parts.length>0?i.parts:[{type:`text`,text:i.text??``}],c=AbortSignal.timeout(st);try{let t=R(await K(`/api/yuri/assistants/${encodeURIComponent(e)}/messages`,{...q(`POST`,{messageID:r,parts:s,language:u.getState().locale}),signal:c}));return J(a,o),ke(e,t.binding,a),tt(e,a),t}catch(e){return ct(e)}},ut=async(e,r,i,a,o)=>{let s=t(),c=n(),l=z(await K(`/api/yuri/assistants/${encodeURIComponent(e)}/share`,q(`POST`,{operationID:r,payload:{messageID:i,parts:a,source:o}})));return J(s,c),l},dt=async(e,r=t(),i=n())=>{J(r,i);let a=z(await K(`/api/yuri/assistants/share-operations/${encodeURIComponent(e)}`));return J(r,i),a},ft=async(e,r=t(),i=n())=>{let a=e;for(let e=0;e<60&&(a.state===`running`||a.state===`submitting`);e+=1)J(r,i),await new Promise(e=>setTimeout(e,750)),a=await dt(a.operationID,r,i);if(J(r,i),a.state===`completed`)return a;throw a.state===`failed`?new y(a.errorCode??`share_failed`,400,a):new y(`share_unresolved`,408,a)},pt=async e=>{let n=t(),r=F(await K(`/api/yuri/assistants`,q(`POST`,{...e,language:u.getState().locale})));return Ae(r,n),r},mt=async(e,r)=>{let i=t(),a=n(),o=F(await K(`/api/yuri/assistants/${encodeURIComponent(e.id)}`,q(`PATCH`,{...r,expectedRevision:e.revision})));return J(i,a),r.pinned===void 0?Ae(o,i):(await l.cancelQueries({queryKey:G.snapshot(i),exact:!0}),J(i,a),await l.fetchQuery(Y(i)),J(i,a)),o},ht=async e=>{await K(`/api/yuri/assistants/${encodeURIComponent(e.id)}`,q(`DELETE`,{expectedRevision:e.revision})),await l.invalidateQueries({queryKey:G.snapshot(t())})},gt=async()=>O(await K(`/api/yuri/assistants/capability`)),_t=async(e,r)=>{let i=t(),a=n(),o=M(r);try{let t=P(await K(`/api/yuri/assistants/${encodeURIComponent(e)}/contact/read`,{...q(`POST`,o),signal:AbortSignal.timeout(15e3)}));if(J(i,a),t.assistantID!==e)throw new _(`invalid_assistant_read_response`,200);return t}finally{t()===i&&n()===a&&l.invalidateQueries({queryKey:G.snapshot(i),exact:!0})}},vt=async e=>{let r=e.assistants.filter(e=>(e.unreadCount??0)>0&&e.readTip).map(e=>({id:e.id,position:{...e.readTip}})),i=t(),a=n(),o=[];for(let e=0;e<r.length;e+=4)o.push(...await Promise.allSettled(r.slice(e,e+4).map(async e=>(J(i,a),_t(e.id,e.position)))));return{failed:o.filter(e=>e.status===`rejected`).length}};function yt(e){return e.state.data&&$e(e.state.data)?2500:15e3}var $=i();function bt(e){let t=(0,g.c)(34),{title:n,className:r,subtitle:i,backAriaLabel:a,onBack:o,backDisabled:s,actions:c,trailing:l,sticky:u,overlay:p,elevated:h,collapsible:_}=e,v=s!==void 0&&s,y;t[0]===c?y=t[1]:(y=c===void 0?[]:c,t[0]=c,t[1]=y);let b=y,x=u!==void 0&&u,S=p!==void 0&&p,C=h!==void 0&&h,w=_!==void 0&&_,T=Array.isArray(l)?l.filter(Boolean).length:+!!l,E=C||b.some(St),D=w?`true`:void 0,O=x&&`yuri-mobile-detail-navigation-sticky`,k=S&&`absolute inset-x-0 top-0`,A=E?`z-[60]`:S?`z-30`:void 0,j;t[2]!==r||t[3]!==k||t[4]!==A||t[5]!==O?(j=f(`yuri-mobile-detail-navigation relative shrink-0 pt-[max(0.25rem,var(--yuri-safe-area-top,0px))]`,O,k,A,r),t[2]=r,t[3]=k,t[4]=A,t[5]=O,t[6]=j):j=t[6];let M=b.length+T>1?`grid-cols-[2.75rem_minmax(0,1fr)_auto]`:`grid-cols-[2.75rem_minmax(0,1fr)_2.75rem]`,N;t[7]===M?N=t[8]:(N=f(`yuri-mobile-detail-navigation-content grid items-center gap-1 px-4`,M),t[7]=M,t[8]=N);let P;t[9]!==a||t[10]!==v||t[11]!==o?(P=o?(0,$.jsx)(d,{type:`button`,variant:`mobileGlass`,size:`mobileIcon`,className:`justify-self-start`,onClick:o,disabled:v,"aria-label":a,children:(0,$.jsx)(m,{name:`arrow-left-s`,className:`size-5`})}):(0,$.jsx)(`span`,{"aria-hidden":`true`}),t[9]=a,t[10]=v,t[11]=o,t[12]=P):P=t[12];let F;t[13]===n?F=t[14]:(F=(0,$.jsx)(`div`,{className:`yuri-mobile-detail-title w-full truncate typography-ui-label font-medium text-foreground`,children:n}),t[13]=n,t[14]=F);let I;t[15]===i?I=t[16]:(I=i?(0,$.jsx)(`div`,{className:`yuri-mobile-detail-subtitle w-full truncate text-muted-foreground`,"aria-live":`polite`,children:i}):null,t[15]=i,t[16]=I);let L;t[17]!==F||t[18]!==I?(L=(0,$.jsxs)(`div`,{className:`flex w-full max-w-72 min-w-0 flex-col items-center justify-center justify-self-center px-1`,children:[F,I]}),t[17]=F,t[18]=I,t[19]=L):L=t[19];let R;t[20]===b?R=t[21]:(R=b.map(xt),t[20]=b,t[21]=R);let z;t[22]!==R||t[23]!==l?(z=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center justify-end gap-2`,children:[l,R]}),t[22]=R,t[23]=l,t[24]=z):z=t[24];let B;t[25]!==N||t[26]!==P||t[27]!==L||t[28]!==z?(B=(0,$.jsxs)(`div`,{className:N,children:[P,L,z]}),t[25]=N,t[26]=P,t[27]=L,t[28]=z,t[29]=B):B=t[29];let V;return t[30]!==j||t[31]!==B||t[32]!==D?(V=(0,$.jsx)(`header`,{"data-yuri-collapsible-header":D,className:j,children:B}),t[30]=j,t[31]=B,t[32]=D,t[33]=V):V=t[33],V}function xt(e,t){return(0,$.jsx)(d,{type:`button`,variant:`mobileGlass`,size:`mobileIcon`,className:f(e.elevated&&`relative z-[60]`),onClick:e.onClick,disabled:e.disabled,"aria-label":e.ariaLabel,"aria-expanded":e.pressed,title:e.title,children:(0,$.jsx)(m,{name:e.icon,className:`size-5`})},`${e.icon}:${t}`)}function St(e){return e.elevated}export{le as A,ft as C,ce as D,ue as E,y as M,v as N,se as O,et as S,pe as T,Xe as _,ht as a,Be as b,ot as c,it as d,lt as f,qe as g,rt as h,pt as i,_ as j,de as k,vt as l,mt as m,Ke as n,at as o,ut as p,Je as r,gt as s,bt as t,_t as u,Ie as v,me as w,Qe as x,Re as y};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{it as t,ot as n,st as r}from"./vendor-base-ui-fom6orB6.js";import{n as i}from"./vendor-react-D5BntRmA.js";import{r as a}from"./vendor-reactuses-core-B8s-Rcd-.js";import{In as o,Rn as s}from"./useMobileNavigationStore-CRoFDKhN.js";import{a as c,c as l}from"./vendor-framer-motion-DiGWHm7K.js";import{n as u}from"./Icon-RGzME9hn.js";import{t as d}from"./MobileWindowStack-DGLdgoGr.js";var f=e(r(),1),p=i(),m=n(),h=e(t(),1),g=0,_=()=>{g=Date.now()+800},v=()=>Date.now()<g;function y(e){let t=(0,p.c)(9),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=s(`flex cursor-ns-resize touch-none justify-center focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--interactive-focus-ring)]`,n),t[3]=n,t[4]=i);let a;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,m.jsx)(`div`,{className:`pointer-events-none h-1.5 w-11 rounded-full bg-[var(--interactive-border)]`}),t[5]=a):a=t[5];let o;return t[6]!==r||t[7]!==i?(o=(0,m.jsx)(`div`,{role:`separator`,tabIndex:0,"aria-orientation":`horizontal`,className:i,...r,children:a}),t[6]=r,t[7]=i,t[8]=o):o=t[8],o}var b=100,x=.35;function S(e,t,n){let r=e.at(-1),i=e.at(-2);for(r&&i&&Math.abs(t-r.height)>2&&(t-r.height)*(r.height-i.height)<0&&e.splice(0,e.length-1),e.push({height:t,time:n});e.length>2&&(e.length>16||e[1].time<n-b);)e.shift()}function C(e,t){let n=e.at(-1);if(!n||t-n.time>=b)return 0;let r=e.find(e=>e.time>=t-b);return!r||n.time<=r.time?0:Math.max(-4,Math.min(4,(n.height-r.height)/Math.max(1,t-r.time)))}function w(e,t,n,r,i){let a=Math.abs(r)>=x&&Math.abs(i)>=8,o=n+(a?r*180:0),s=e.reduce((e,t)=>Math.abs(t.height-o)<Math.abs(e.height-o)?t:e),c=e.find(e=>e.id===t)??s;return!a||Math.abs(s.height-c.height)>1?s.id:[...e].sort((e,t)=>r>0?e.height-t.height:t.height-e.height).find(e=>r>0?e.height>c.height+1:e.height<c.height-1)?.id??s.id}function T(e,t,n){let r=e<t?t:e>n?n:e,i=e-r;return r+Math.sign(i)*48*(1-1/(1+Math.abs(i)*.55/48))}function E(e){let t=(0,p.c)(82),{surfaceRef:n,initialPoint:r,getPoints:i,minimumHeight:o,onRelease:s,onCommit:u,renderMode:d}=e,m=d===void 0?`height`:d,[h,g]=(0,f.useState)(r),[_,v]=(0,f.useState)(!1),[y,b]=(0,f.useState)(!1),x=(0,f.useRef)(r),E=(0,f.useRef)(null),A=(0,f.useRef)(null),j=(0,f.useRef)(null),M=(0,f.useRef)(null),N=(0,f.useRef)(!1),P=(0,f.useRef)(null),F;t[0]===n?F=t[1]:(F=()=>{let e=n.current;if(!e)return 0;if(!P.current)return e.getBoundingClientRect().height;let t=parseFloat(getComputedStyle(e).translate.split(` `)[1])||0;return P.current.layoutHeight-t},t[0]=n,t[1]=F);let I=a(F),L;t[2]===n?L=t[3]:(L=e=>{let t=n.current;t&&(P.current?t.style.translate=`0 ${P.current.layoutHeight-e}px`:t.style.height=`${e}px`)},t[2]=n,t[3]=L);let R=a(L),z;t[4]!==m||t[5]!==n||t[6]!==R?(z=(e,t)=>{let r=n.current;if(r){if(m===`translate`&&!P.current){let e=Math.max(...t.map(k))+144,{maxHeight:n,position:i,bottom:a,left:o,right:s}=r.style;P.current={layoutHeight:e,styles:{maxHeight:n,position:i,bottom:a,left:o,right:s}},Object.assign(r.style,{position:`absolute`,bottom:`0px`,left:`0px`,right:`0px`}),r.style.maxHeight=`none`,r.style.height=`${e}px`}r.setAttribute(`data-height-snap-active`,``),r.style.willChange=P.current?`translate`:`height`,R(e)}},t[4]=m,t[5]=n,t[6]=R,t[7]=z):z=t[7];let B=a(z),V;t[8]===n?V=t[9]:(V=()=>{let e=n.current;e&&(P.current&&(e.style.translate=``,Object.assign(e.style,P.current.styles),e.style.height=``),e.style.willChange=``,e.removeAttribute(`data-height-snap-active`)),P.current=null},t[8]=n,t[9]=V);let H=a(V),ae;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(ae=()=>{A.current!==null&&cancelAnimationFrame(A.current),A.current=null,j.current=null,M.current?.cancel(),M.current=null},t[10]=ae):ae=t[10];let U=a(ae),W;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(W=()=>{let e=E.current;E.current=null,e?.handle.hasPointerCapture?.(e.pointerId)&&e.handle.releasePointerCapture(e.pointerId)},t[11]=W):W=t[11];let G=a(W),oe;t[12]!==U||t[13]!==H||t[14]!==i||t[15]!==u||t[16]!==B||t[17]!==I||t[18]!==G||t[19]!==n||t[20]!==R?(oe=(e,t,r,a)=>{let o=r===void 0||r,s=a===void 0?0:a,d=n.current;if(!d)return;let f=t??I();U(),R(f);let p=i(),m=p.find(t=>t.id===e);if(!m)return;if(B(f,p),G(),v(!1),b(!1),x.current=e,g(e),R(m.height),u?.(e),!o||Math.abs(f-m.height)<1||typeof d.animate!=`function`||window.matchMedia(`(prefers-reduced-motion: reduce)`).matches){H();return}b(!0);let h=P.current?.layoutHeight,_=m.height-f,y=c([d],h===void 0?{height:[`${f}px`,`${m.height}px`]}:{translate:[`0 ${h-f}px`,`0 ${h-m.height}px`]},{type:l,stiffness:576,damping:48,mass:1,velocity:s*1e3*100/_,restDelta:20/Math.abs(_),restSpeed:500/Math.abs(_)});M.current=y,y.finished.catch(ie).then(()=>{M.current===y&&(M.current=null,H(),b(!1))})},t[12]=U,t[13]=H,t[14]=i,t[15]=u,t[16]=B,t[17]=I,t[18]=G,t[19]=n,t[20]=R,t[21]=oe):oe=t[21];let K=a(oe),se;t[22]!==U||t[23]!==i||t[24]!==o||t[25]!==B||t[26]!==I||t[27]!==n||t[28]!==R?(se=e=>{if(E.current||!e.isPrimary||e.pointerType===`mouse`&&e.button!==0||!n.current)return;let t=I();U(),R(t);let r=i();r.length&&(b(!1),E.current={pointerId:e.pointerId,startY:e.clientY,height:t,point:x.current,points:r,handle:e.currentTarget,minimum:o??Math.min(...r.map(re)),maximum:Math.max(...r.map(O)),samples:[{height:t,time:e.timeStamp}]},N.current=!1,B(t,r),v(!0),e.currentTarget.setPointerCapture(e.pointerId),e.preventDefault())},t[22]=U,t[23]=i,t[24]=o,t[25]=B,t[26]=I,t[27]=n,t[28]=R,t[29]=se):se=t[29];let ce=a(se),le;t[30]!==m||t[31]!==R?(le=e=>{let t=E.current;if(!t||t.pointerId!==e.pointerId)return;let n=t.startY-e.clientY;Math.abs(n)>3&&(N.current=!0),S(t.samples,t.height+n,e.timeStamp);let r=T(t.height+n,t.minimum,t.maximum);j.current=m===`height`?Math.max(t.minimum,r):r,A.current===null&&(A.current=requestAnimationFrame(()=>{A.current=null,j.current!==null&&R(j.current)})),e.preventDefault()},t[30]=m,t[31]=R,t[32]=le):le=t[32];let ue=a(le),de;t[33]!==U||t[34]!==s||t[35]!==I||t[36]!==G||t[37]!==K||t[38]!==n?(de=(e,t)=>{let r=E.current;if(!r||r.pointerId!==e.pointerId)return;let i=j.current??I(),a=r.height+r.startY-e.clientY;t||S(r.samples,a,e.timeStamp);let o=t?0:C(r.samples,e.timeStamp);if(G(),!t&&N.current&&s?.(i,o,r.height))U(),v(!1),n.current&&(n.current.style.willChange=``);else{let e=t||!N.current?r.point:w(r.points,r.point,i,o,a-r.height);K(e,i,!0,o)}e.preventDefault()},t[33]=U,t[34]=s,t[35]=I,t[36]=G,t[37]=K,t[38]=n,t[39]=de):de=t[39];let q=a(de),fe;t[40]!==i||t[41]!==K?(fe=e=>{let t=[...i()].sort(ne),n=t.find(e=>e.id===x.current);if(!n)return;let r=e>0?t.find(e=>e.height>n.height+1):t.sort(D).find(e=>e.height<n.height-1);r&&K(r.id)},t[40]=i,t[41]=K,t[42]=fe):fe=t[42];let J=a(fe),pe;t[43]!==i||t[44]!==K||t[45]!==J?(pe=()=>{if(N.current){N.current=!1;return}let e=[...i()].sort(te);x.current===e.at(-1)?.id?K(e[0].id):J(1)},t[43]=i,t[44]=K,t[45]=J,t[46]=pe):pe=t[46];let me=a(pe),Y;t[47]!==i||t[48]!==me||t[49]!==K||t[50]!==J?(Y=e=>{if(![`ArrowUp`,`ArrowDown`,`Home`,`End`,`Enter`,` `].includes(e.key))return;e.preventDefault();let t=[...i()].sort(ee);t.length&&(e.key===`ArrowUp`?J(1):e.key===`ArrowDown`?J(-1):e.key===`Home`?K(t.at(-1).id):e.key===`End`?K(t[0].id):me())},t[47]=i,t[48]=me,t[49]=K,t[50]=J,t[51]=Y):Y=t[51];let X=a(Y),he;t[52]!==U||t[53]!==H||t[54]!==r||t[55]!==G||t[56]!==n?(he=()=>{U(),G(),H(),x.current=r,g(r),v(!1),b(!1),N.current=!1,n.current&&(n.current.style.height=``,n.current.style.willChange=``)},t[52]=U,t[53]=H,t[54]=r,t[55]=G,t[56]=n,t[57]=he):he=t[57];let Z=a(he),Q,ge;t[58]!==U||t[59]!==H||t[60]!==G?(Q=()=>()=>{U(),G(),H()},ge=[U,G,H],t[58]=U,t[59]=H,t[60]=G,t[61]=Q,t[62]=ge):(Q=t[61],ge=t[62]),(0,f.useLayoutEffect)(Q,ge);let $;t[63]===q?$=t[64]:($=e=>q(e,!1),t[63]=q,t[64]=$);let _e=a($),ve;t[65]===q?ve=t[66]:(ve=e=>q(e,!0),t[65]=q,t[66]=ve);let ye=a(ve),be;t[67]===q?be=t[68]:(be=e=>q(e,!0),t[67]=q,t[68]=be);let xe=a(be),Se;return t[69]!==_||t[70]!==me||t[71]!==X||t[72]!==ce||t[73]!==ue||t[74]!==Z||t[75]!==K||t[76]!==y||t[77]!==h||t[78]!==_e||t[79]!==ye||t[80]!==xe?(Se={snapPoint:h,dragging:_,settling:y,settleAt:K,reset:Z,handlePointerDown:ce,handlePointerMove:ue,handlePointerUp:_e,handlePointerCancel:ye,handleLostPointerCapture:xe,handleClick:me,handleKeyDown:X},t[69]=_,t[70]=me,t[71]=X,t[72]=ce,t[73]=ue,t[74]=Z,t[75]=K,t[76]=y,t[77]=h,t[78]=_e,t[79]=ye,t[80]=xe,t[81]=Se):Se=t[81],Se}function ee(e,t){return e.height-t.height}function te(e,t){return e.height-t.height}function D(e,t){return t.height-e.height}function ne(e,t){return e.height-t.height}function O(e){return e.height}function re(e){return e.height}function ie(){}function k(e){return e.height}var A=.72,j=.98,M=64,N=()=>Math.max(1,window.innerHeight),P=(e,t)=>{let n=Math.max(1,e)*A;return t==null||!Number.isFinite(t)?n:Math.min(n,Math.max(0,t))},F=e=>{let t=(0,p.c)(20),n;t[0]===e?n=t[1]:(n=e===void 0?{}:e,t[0]=e,t[1]=n);let{initialSnapPoint:r,fitContent:i,onDismiss:o,dismissThresholdPx:s}=n,c=r===void 0?A:r,l=i!==void 0&&i,u=s===void 0?M:s,d=f.useRef(null),m=f.useRef(null),h=f.useRef(c),g=o?0:void 0,_;t[2]===l?_=t[3]:(_=()=>{let e=N(),t=d.current?.parentElement?.clientHeight||e;return l&&h.current===.72&&d.current&&!d.current.hasAttribute(`data-height-snap-active`)&&(m.current=P(e,d.current.getBoundingClientRect().height)),[{id:A,height:Math.min(t,P(e,l?m.current:void 0))},{id:j,height:Math.min(t,e*j)}]},t[2]=l,t[3]=_);let v;t[4]!==u||t[5]!==l||t[6]!==o?(v=(e,t,n)=>{let r=d.current?.parentElement?.clientHeight||N(),i=Math.min(r,P(N(),l?m.current:void 0)),a=t<-.55&&n<=i+1&&e<i-8;return!o||!a&&e>i-u?!1:(o(),!0)},t[4]=u,t[5]=l,t[6]=o,t[7]=v):v=t[7];let y;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(y=e=>{h.current=e},t[8]=y):y=t[8];let b;t[9]!==c||t[10]!==g||t[11]!==_||t[12]!==v?(b={surfaceRef:d,initialPoint:c,renderMode:`translate`,minimumHeight:g,getPoints:_,onRelease:v,onCommit:y},t[9]=c,t[10]=g,t[11]=_,t[12]=v,t[13]=b):b=t[13];let x=E(b),S;t[14]!==x||t[15]!==c?(S=()=>{m.current=null,h.current=c,x.reset()},t[14]=x,t[15]=c,t[16]=S):S=t[16];let C=a(S),w;return t[17]!==x||t[18]!==C?(w={...x,surfaceRef:d,reset:C},t[17]=x,t[18]=C,t[19]=w):w=t[19],w},I=e=>{let t=(0,p.c)(13),{controller:n,ariaLabel:r,compact:i}=e,a=i!==void 0&&i,o;t[0]===n.snapPoint?o=t[1]:(o=Math.round(n.snapPoint*100),t[0]=n.snapPoint,t[1]=o);let s=`flex cursor-ns-resize touch-none justify-center focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--interactive-focus-ring)] ${a?`min-h-4 pt-1`:`min-h-8 pt-2.5`}`,c;return t[2]!==r||t[3]!==n.handleClick||t[4]!==n.handleKeyDown||t[5]!==n.handleLostPointerCapture||t[6]!==n.handlePointerCancel||t[7]!==n.handlePointerDown||t[8]!==n.handlePointerMove||t[9]!==n.handlePointerUp||t[10]!==o||t[11]!==s?(c=(0,m.jsx)(y,{"data-mobile-sheet-snap-handle":!0,role:`separator`,tabIndex:0,"aria-label":r,"aria-orientation":`horizontal`,"aria-valuemin":A*100,"aria-valuemax":j*100,"aria-valuenow":o,className:s,onPointerDown:n.handlePointerDown,onPointerMove:n.handlePointerMove,onPointerUp:n.handlePointerUp,onPointerCancel:n.handlePointerCancel,onLostPointerCapture:n.handleLostPointerCapture,onClick:n.handleClick,onKeyDown:n.handleKeyDown}),t[2]=r,t[3]=n.handleClick,t[4]=n.handleKeyDown,t[5]=n.handleLostPointerCapture,t[6]=n.handlePointerCancel,t[7]=n.handlePointerDown,t[8]=n.handlePointerMove,t[9]=n.handlePointerUp,t[10]=o,t[11]=s,t[12]=c):c=t[12],c},L=new WeakMap;function R(e){L.set(e.currentTarget,!0)}function z(e){if(L.delete(e.currentTarget))return!0;if(e.detail!==0)return!1;if(typeof document>`u`)return!0;let t=document.activeElement,n=e.currentTarget;return n instanceof Node&&t instanceof Node&&n.contains(t)}function B(e){e.target===e.currentTarget&&R(e)}function V(e){return e.target===e.currentTarget&&z(e)}var H=(0,f.createContext)(!0),ae=(e,t)=>{let n=`flex min-h-0 flex-col bg-background shadow-none`;if(e===`page`)return`${n} h-full w-full`;let r=`${n} pwa-overlay-panel`;return t===`top`?`${r} mx-auto mb-auto max-h-[calc(100dvh-0.75rem)] w-full max-w-lg rounded-b-xl border-x border-b border-border/50`:t===`left`?`${r} h-full w-[min(86vw,24rem)] rounded-r-xl border-r border-y border-border/50`:t===`right`?`${r} ml-auto h-full w-[min(86vw,24rem)] rounded-l-xl border-l border-y border-border/50`:`${r} mx-auto mt-auto max-h-[calc(100dvh-0.75rem)] w-full max-w-lg rounded-t-2xl border-x border-t border-border/50 pb-[max(0.5rem,var(--yuri-app-bottom-safe,0px),var(--yuri-safe-area-bottom,env(safe-area-inset-bottom,0px)))]`},U=e=>Math.min(1,Math.max(0,Number.isFinite(e)?e:0)),W=(e,t)=>{let n=U(t),r=`${(1-n)*100}%`;return{progress:n,scrimOpacity:n,surfaceOpacity:n,surfaceTransform:e===`left`?`translate3d(-${r}, 0, 0)`:e===`right`?`translate3d(${r}, 0, 0)`:e===`top`?`translate3d(0, -${r}, 0)`:`translate3d(0, ${r}, 0)`}},G=(e,t)=>{let n=U(t);return e===`present`?n:1-n},oe=(e,t)=>e===`present`?+(t===`commit`):t===`commit`?0:1,K=e=>+!!e,se=`mobile-sessions`,ce=new Map,le=e=>ce.get(e)??null,ue=(e,t)=>(ce.set(e,t),()=>{ce.get(e)===t&&ce.delete(e)}),de=`.overlay-scrollbar-container`,q=1,fe=e=>e===`left`||e===`right`?`x`:`y`,J=e=>e===`bottom`||e===`right`?1:-1,pe=(e,t,n)=>{let r=fe(e)===`x`?t:n;return Math.max(0,r*J(e))},me=(e,t,n,r,i)=>{let a=pe(e,t,n),o=Math.abs(fe(e)===`x`?n:t);return Math.hypot(t,n)>r&&a>0&&o<a*i},Y=(e,t)=>Math.min(1,Math.max(0,e/Math.max(1,t))),X=(e,t,n,r)=>Math.min(r,Math.max(n,e*t)),he=(e,t,n,r,i)=>e>=n||e>=i&&t>=r,Z=(e,t,n,r,i)=>t!==0&&n>0?t*i/n:r>80?0:e,Q=(e,t,n=q)=>{if(t===`bottom`)return e.scrollTop<=n;if(t===`top`)return e.scrollTop>=e.scrollHeight-e.clientHeight-n;if(e.matches?.(`:dir(rtl)`)){let r=e.scrollWidth-e.clientWidth;return t===`right`?Math.abs(e.scrollLeft)<=n:Math.abs(e.scrollLeft)>=r-n}return t===`right`?e.scrollLeft<=n:e.scrollLeft>=e.scrollWidth-e.clientWidth-n},ge=(e,t)=>{for(let n=0;n<e.length;n+=1){let r=e.item(n);if(r?.identifier===t)return r}return null},$=(e,t)=>{let n=window.getComputedStyle(e),r=fe(t),i=r===`x`?n.overflowX:n.overflowY,a=r===`x`?e.scrollWidth:e.scrollHeight,o=r===`x`?e.clientWidth:e.clientHeight;return(i===`auto`||i===`scroll`||i===`overlay`)&&a>o},_e=(e,t,n,r)=>{let i=t instanceof Element?t:null,a=i instanceof HTMLElement?i:i?.parentElement??null;for(;a&&e.contains(a);){if($(a,n))return a;if(a===e)break;a=a.parentElement}let o=i?.closest(r)??null;return o&&e.contains(o)&&$(o,n)?o:null},ve=e=>{let t=f.useRef(e),n=f.useRef(null),r=f.useRef(null);return t.current=e,f.useCallback(e=>{if(n.current?.(),n.current=null,!e)return;let i=()=>{let e=r.current;r.current=null,e?.active&&e.controller?.finish(`cancel`)},a=(e,t,n)=>{let r=fe(e.edge)===`x`?t.clientX:t.clientY,i=n-e.lastTime,a=r-e.lastPrimary;e.velocity=Z(e.velocity,a,i,n-e.lastVelocityTime,J(e.edge)),a!==0&&i>0&&(e.lastVelocityTime=n),e.lastPrimary=r,e.lastTime=n,e.distance=pe(e.edge,t.clientX-e.startX,t.clientY-e.startY)},o=n=>{i();let a=t.current;if(a.disabled||n.touches.length!==1)return;let o=n.target instanceof Element?n.target:null,s=a.reservedTargetSelector?o?.closest(a.reservedTargetSelector):null;if(s&&e.contains(s)||o?.closest(`input, textarea, select, [contenteditable=""], [contenteditable="true"], [data-mobile-sheet-no-dismiss]`))return;let c=n.touches[0],l=_e(e,n.target,a.edge,a.scrollContainerSelector??de);if(l&&!Q(l,a.edge))return;let u=e.getBoundingClientRect(),d=fe(a.edge)===`x`?u.width||window.innerWidth:u.height||window.innerHeight;r.current={edge:a.edge,motionId:a.motionId,touchId:c.identifier,startX:c.clientX,startY:c.clientY,lastPrimary:fe(a.edge)===`x`?c.clientX:c.clientY,lastTime:n.timeStamp,lastVelocityTime:n.timeStamp,velocity:0,distance:0,commitDistance:X(d,a.commitDistanceRatio??.1,a.minCommitDistance??40,a.maxCommitDistance??64),motionDistance:d,intentDistance:a.intentDistance??8,maxOffAxisRatio:a.maxOffAxisRatio??1,flingVelocity:a.flingVelocity??.65,flingMinDistance:a.flingMinDistance??12,controller:null,active:!1}},s=e=>{let n=r.current;if(!n)return;if(t.current.disabled||e.touches.length!==1){i();return}let o=ge(e.touches,n.touchId);if(!o){i();return}if(a(n,o,e.timeStamp),!n.active){if(Math.hypot(o.clientX-n.startX,o.clientY-n.startY)<=n.intentDistance)return;if(!me(n.edge,o.clientX-n.startX,o.clientY-n.startY,n.intentDistance,n.maxOffAxisRatio)){r.current=null;return}let e=le(n.motionId);if(!e){r.current=null;return}if(!e.begin(`dismiss`)){r.current=null;return}n.active=!0,n.controller=e}n.controller?.update(Y(n.distance,n.motionDistance)),e.preventDefault()},c=e=>{let t=r.current;if(!t)return;let n=ge(e.changedTouches,t.touchId);if(!n){i();return}if(r.current=null,!t.active)return;a(t,n,e.timeStamp),t.controller?.update(Y(t.distance,t.motionDistance));let o=he(t.distance,t.velocity,t.commitDistance,t.flingVelocity,t.flingMinDistance);t.controller?.finish(o?`commit`:`cancel`),e.preventDefault()},l=()=>i();e.addEventListener(`touchstart`,o,{passive:!0,capture:!0}),e.addEventListener(`touchmove`,s,{passive:!1,capture:!0}),e.addEventListener(`touchend`,c,{passive:!1,capture:!0}),e.addEventListener(`touchcancel`,l,{passive:!0,capture:!0}),n.current=()=>{i(),e.removeEventListener(`touchstart`,o,!0),e.removeEventListener(`touchmove`,s,!0),e.removeEventListener(`touchend`,c,!0),e.removeEventListener(`touchcancel`,l,!0)}},[])},ye=`mobile-overlay-root`,be=200,xe=80,Se=`cubic-bezier(0.32, 0.72, 0, 1)`,Ce=`a[href], button:not(:disabled), input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex="-1"])`,we=()=>{if(typeof document>`u`)return null;let e=document.getElementById(ye);return e||(e=document.createElement(`div`),e.id=ye,document.body.appendChild(e)),e},Te=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,Ee=({id:e,open:t,onOpenChange:n,keepMounted:r=!1,presentation:i=`sheet`,edge:a=`bottom`,children:o,className:c,scrimClassName:l,surfaceClassName:u,surfaceElementRef:p,dismissGesture:g=!1,onExitComplete:_,onPreviewChange:y,ariaLabel:b})=>{let x=f.useRef(null),S=f.useRef(null),C=f.useRef(null),w=f.useRef(null),T=f.useRef(t),E=f.useRef(n),ee=f.useRef(_),te=f.useRef(y),D=f.useRef(0),ne=f.useRef(0),O=f.useRef(null),re=f.useRef([]),ie=f.useRef(null),k=f.useRef(`standard`),A=f.useRef(`present`),j=f.useRef(0),M=f.useRef(!1),N=f.useRef(t),P=f.useRef(!1),F=f.useRef(t),I=f.useRef(null),[L,R]=f.useState(t),[z,U]=f.useState(t),[se,ce]=f.useState(`standard`),[le,de]=f.useState(!1),q=se===`interactive-present`,fe=f.useSyncExternalStore(d.subscribe,d.getSnapshot,d.getSnapshot),J=z&&!q&&fe===e,pe=ve({motionId:e,edge:a,disabled:!g,...typeof g==`object`?g:{}}),me=f.useCallback(e=>{C.current=e,pe(e),typeof p==`function`?p(e):p&&typeof p==`object`&&(p.current=e)},[pe,p]),Y=f.useCallback(()=>{F.current&&(F.current=!1,U(!1),r||R(!1),ee.current?.())},[r]);T.current=t,E.current=n,ee.current=_,te.current=y,f.useLayoutEffect(()=>{te.current?.(z&&q)},[z,q]),typeof document<`u`&&!x.current&&(x.current=we());let X=f.useCallback(e=>{let t=W(a,e);D.current=t.progress,!(!S.current||!C.current)&&(S.current.style.opacity=String(t.scrimOpacity),C.current.style.transform=t.surfaceTransform,C.current.style.opacity=String(t.surfaceOpacity))},[a]),he=f.useCallback(()=>{O.current!==null&&window.cancelAnimationFrame(O.current),O.current=null},[]),Z=f.useCallback(()=>{S.current&&(S.current.style.willChange=``),C.current&&(C.current.style.willChange=``)},[]),Q=f.useCallback((e=re.current)=>{for(let t of e)t.cancel();re.current=[]},[]),ge=f.useCallback(()=>{he();let e=ie.current;if(e){let t=e.animations[1]?.effect?.getComputedTiming().progress;X(typeof t==`number`&&Number.isFinite(t)?e.from+(e.target-e.from)*t:D.current),Q(e.animations),ie.current=null}else Q();Z(),de(!1)},[X,Q,he,Z]),$=f.useCallback((e,t)=>{if(ie.current?.target===e)return;ge();let n=D.current,r=S.current,i=C.current;if(de(!0),!r||!i||Te()||n===e){X(e),Z(),de(!1),t?.();return}let o=W(a,n),s=W(a,e);r.style.willChange=`opacity`,i.style.willChange=`transform, opacity`;let c=Math.max(xe,be*Math.abs(e-n)),l=[r.animate([{opacity:o.scrimOpacity},{opacity:s.scrimOpacity}],{duration:c,easing:Se,fill:`forwards`}),i.animate([{transform:o.surfaceTransform,opacity:o.surfaceOpacity},{transform:s.surfaceTransform,opacity:s.surfaceOpacity}],{duration:c,easing:Se,fill:`forwards`})];re.current=l;let u={from:n,target:e,animations:l};ie.current=u,Promise.all(l.map(e=>e.finished.catch(()=>void 0))).then(()=>{ie.current===u&&(X(e),Q(l),ie.current=null,Z(),de(!1),t?.())})},[X,Q,Z,a,ge]);if(f.useLayoutEffect(()=>{P.current=L,L&&X(ne.current)},[X,L]),f.useLayoutEffect(()=>{F.current=z},[z]),f.useEffect(()=>{t&&!P.current&&(ne.current=D.current,R(!0)),t&&!F.current&&(F.current=!0,U(!0)),P.current&&k.current===`standard`&&$(K(t),()=>{!T.current&&k.current===`standard`&&Y()})},[Y,t,$]),f.useLayoutEffect(()=>{!L||k.current!==`standard`||$(+!!t,()=>{!T.current&&k.current===`standard`&&Y()})},[Y,L,t,$]),f.useEffect(()=>{if(!(!z||q))return window.dispatchEvent(new Event(`yuri:mobile-overlay-opened`)),()=>{window.dispatchEvent(new Event(`yuri:mobile-overlay-closed`))}},[z,q]),f.useEffect(()=>{if(!(!z||q))return d.add({id:e,onClose:()=>E.current(!1)},document.body)},[z,e,q]),f.useEffect(()=>{if(!z||q||!J)return;let e=C.current,t=document.activeElement instanceof HTMLElement?document.activeElement:null;w.current?.focus({preventScroll:!0});let n=t=>{if(t.key===`Escape`&&d.closeTop(),t.key!==`Tab`||!e)return;let n=Array.from(e.querySelectorAll(Ce)).filter(e=>!e.closest(`[data-mobile-sheet-snap-handle]`)),r=n[0]??w.current,i=n.at(-1)??w.current;!r||!i||(t.shiftKey&&document.activeElement===r&&(t.preventDefault(),i.focus({preventScroll:!0})),!t.shiftKey&&document.activeElement===i&&(t.preventDefault(),r.focus({preventScroll:!0})))};return document.addEventListener(`keydown`,n),()=>{document.removeEventListener(`keydown`,n),v()||t?.focus({preventScroll:!0})}},[z,q,J]),I.current={begin:e=>{if(e===`dismiss`&&(!F.current||k.current===`interactive-present`))return!1;ge(),j.current+=1,M.current=!0,A.current=e;let t=e===`present`?`interactive-present`:`interactive-dismiss`;return k.current=t,ce(t),de(!0),e===`present`&&(ne.current=D.current,F.current=!0,U(!0),R(!0)),!0},update:e=>{M.current&&(ne.current=G(A.current,e),O.current===null&&(O.current=window.requestAnimationFrame(()=>{O.current=null,M.current&&X(ne.current)})))},finish:e=>{if(!M.current)return;M.current=!1;let t=j.current,n=A.current,r=oe(n,e);O.current!==null&&(he(),X(ne.current)),$(r,()=>{t===j.current&&(e===`commit`&&E.current(n===`present`),n===`present`&&e===`cancel`&&!T.current&&Y(),k.current=`standard`,ce(`standard`),r===0&&Y())})},interrupt:()=>{j.current+=1,M.current=!1;let e=k.current===`interactive-present`&&!T.current;e||(k.current=`standard`,ce(`standard`)),ge(),$(K(T.current),()=>{T.current||Y(),e&&(k.current=`standard`,ce(`standard`))})}},f.useLayoutEffect(()=>{let e=N.current;N.current=t,e&&!t&&k.current!==`standard`&&I.current?.interrupt()},[t]),f.useEffect(()=>{let t=ue(e,{begin:e=>I.current?.begin(e)??!1,update:e=>I.current?.update(e),finish:e=>I.current?.finish(e),interrupt:()=>I.current?.interrupt()});return()=>{t(),he(),Q(),ie.current=null,Z(),I.current=null}},[Q,he,Z,e]),!L||!x.current)return null;let _e=(0,m.jsx)(`div`,{ref:S,className:s(`yuri-mobile-window-motion yuri-keyboard-inset-surface fixed inset-0 z-[60] flex flex-col bg-[rgb(0_0_0_/_0.45)]`,le&&`yuri-mobile-window-motion-active`,!z&&!q&&`pointer-events-none invisible`,l,c),"data-mobile-overlay-active":String(z),role:q?void 0:`dialog`,"aria-label":q?void 0:b,"aria-modal":z&&J?`true`:void 0,"aria-hidden":q||!z||!J||void 0,inert:q||!z||!J||void 0,onPointerDown:B,onClick:e=>{!z||q||!J||V(e)&&E.current(!1)},children:(0,m.jsxs)(`div`,{ref:me,className:s(`yuri-mobile-floating-shell`,ae(i,a),u),"data-yuri-motion-id":e,style:{contain:`layout paint style`},onClick:e=>e.stopPropagation(),children:[(0,m.jsx)(`span`,{ref:w,tabIndex:-1,className:`sr-only`,role:`group`,"aria-label":b}),(0,m.jsx)(H.Provider,{value:J,children:o})]})});return(0,h.createPortal)(_e,x.current)},De=f.createContext(null),Oe=e=>{let t=(0,p.c)(5),{children:n}=e,r=f.useContext(De);if(!r)return null;let i;t[0]===n?i=t[1]:(i=(0,m.jsx)(`div`,{className:`flex shrink-0 items-center gap-1.5`,children:n}),t[0]=n,t[1]=i);let a;return t[2]!==r||t[3]!==i?(a=(0,h.createPortal)(i,r),t[2]=r,t[3]=i,t[4]=a):a=t[4],a},ke=e=>{let t=(0,p.c)(50),{id:n,open:r,onOpenChange:i,title:a,leading:c,trailing:l,ariaLabel:d,closeAriaLabel:h,showCloseButton:g,compactHeader:_,resizeAriaLabel:v,initiallyExpanded:y,fitContent:b,bodyClassName:x,className:S,children:C}=e,w=g===void 0||g,T=_!==void 0&&_,E=y!==void 0&&y,ee=b!==void 0&&b,te=E?j:void 0,D;t[0]!==i||t[1]!==r?(D=r?()=>i(!1):void 0,t[0]=i,t[1]=r,t[2]=D):D=t[2];let ne;t[3]!==ee||t[4]!==te||t[5]!==D?(ne={initialSnapPoint:te,fitContent:ee,onDismiss:D},t[3]=ee,t[4]=te,t[5]=D,t[6]=ne):ne=t[6];let O=F(ne),[re,ie]=f.useState(null),k=a!=null||c!=null||l!=null,A=O.snapPoint===j,M=A||!ee,N;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(N={reservedTargetSelector:`[data-mobile-sheet-snap-handle]`},t[7]=N):N=t[7];let P=A?`h-[98dvh] max-h-[98dvh]`:ee?`h-auto max-h-[72dvh]`:`h-[72dvh] max-h-[98dvh]`,L=O.surfaceRef,R=O.reset,z=M&&`flex-1`,B;t[8]===z?B=t[9]:(B=s(`flex min-h-0 flex-col`,z),t[8]=z,t[9]=B);let V;t[10]!==T||t[11]!==v||t[12]!==O?(V=(0,m.jsx)(I,{controller:O,ariaLabel:v,compact:T}),t[10]=T,t[11]=v,t[12]=O,t[13]=V):V=t[13];let H;t[14]!==h||t[15]!==T||t[16]!==ee||t[17]!==k||t[18]!==c||t[19]!==i||t[20]!==w||t[21]!==a||t[22]!==l?(H=k?(0,m.jsxs)(`div`,{"data-mobile-sheet-header":!0,className:T?`flex min-h-6 items-center gap-2 px-3 text-xs`:ee?`flex min-h-9 items-center gap-2 px-4 pb-1`:`flex min-h-10 items-center gap-2 px-4 pb-2`,children:[c?(0,m.jsx)(`div`,{className:`flex shrink-0 items-center`,children:c}):null,(0,m.jsx)(`div`,{className:s(`min-w-0 flex-1`,T&&`truncate`),children:a}),l?(0,m.jsx)(`div`,{className:`flex shrink-0 items-center gap-1.5`,children:l}):null,(0,m.jsx)(`div`,{ref:ie,className:`contents`}),w?(0,m.jsx)(o,{type:`button`,variant:`ghost`,size:`icon`,onClick:()=>i(!1),"aria-label":h,className:`shrink-0 text-muted-foreground`,style:{touchAction:`manipulation`},children:(0,m.jsx)(u,{name:`close`,className:`size-5`})}):null]}):null,t[14]=h,t[15]=T,t[16]=ee,t[17]=k,t[18]=c,t[19]=i,t[20]=w,t[21]=a,t[22]=l,t[23]=H):H=t[23];let ae;t[24]!==V||t[25]!==H?(ae=(0,m.jsxs)(`div`,{className:`shrink-0`,children:[V,H]}),t[24]=V,t[25]=H,t[26]=ae):ae=t[26];let U=M&&`flex-1`,W;t[27]!==x||t[28]!==U?(W=s(`flex min-h-0 flex-col overflow-hidden`,U,x),t[27]=x,t[28]=U,t[29]=W):W=t[29];let G;t[30]!==C||t[31]!==W?(G=(0,m.jsx)(`div`,{className:W,"data-page-scroll-lock":`true`,children:C}),t[30]=C,t[31]=W,t[32]=G):G=t[32];let oe;t[33]!==B||t[34]!==ae||t[35]!==G?(oe=(0,m.jsxs)(`div`,{className:B,children:[ae,G]}),t[33]=B,t[34]=ae,t[35]=G,t[36]=oe):oe=t[36];let K;t[37]!==d||t[38]!==S||t[39]!==n||t[40]!==i||t[41]!==r||t[42]!==O.reset||t[43]!==O.surfaceRef||t[44]!==oe||t[45]!==P?(K=(0,m.jsx)(Ee,{id:n,className:S,open:r,onOpenChange:i,presentation:`sheet`,edge:`bottom`,dismissGesture:N,ariaLabel:d,surfaceClassName:P,surfaceElementRef:L,onExitComplete:R,children:oe}),t[37]=d,t[38]=S,t[39]=n,t[40]=i,t[41]=r,t[42]=O.reset,t[43]=O.surfaceRef,t[44]=oe,t[45]=P,t[46]=K):K=t[46];let se;return t[47]!==re||t[48]!==K?(se=(0,m.jsx)(De.Provider,{value:re,children:K}),t[47]=re,t[48]=K,t[49]=se):se=t[49],se};export{_ as C,v as S,I as _,pe as a,E as b,me as c,le as d,H as f,V as g,B as h,X as i,he as l,R as m,Oe as n,Y as o,z as p,Ee as r,Z as s,ke as t,se as u,j as v,y as x,F as y};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{it as t,ot as n,st as r}from"./vendor-base-ui-fom6orB6.js";import{n as i}from"./vendor-react-D5BntRmA.js";import{r as a}from"./vendor-reactuses-core-B8s-Rcd-.js";import{In as o,Rn as s}from"./useMobileNavigationStore-DW2W2RJB.js";import{a as c,c as l}from"./vendor-framer-motion-DiGWHm7K.js";import{n as u}from"./Icon-W44vi3ut.js";import{t as d}from"./MobileWindowStack-DGLdgoGr.js";var f=e(r(),1),p=i(),m=n(),h=e(t(),1),g=0,_=()=>{g=Date.now()+800},v=()=>Date.now()<g;function y(e){let t=(0,p.c)(9),n,r;t[0]===e?(n=t[1],r=t[2]):({className:n,...r}=e,t[0]=e,t[1]=n,t[2]=r);let i;t[3]===n?i=t[4]:(i=s(`flex cursor-ns-resize touch-none justify-center focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--interactive-focus-ring)]`,n),t[3]=n,t[4]=i);let a;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,m.jsx)(`div`,{className:`pointer-events-none h-1.5 w-11 rounded-full bg-[var(--interactive-border)]`}),t[5]=a):a=t[5];let o;return t[6]!==r||t[7]!==i?(o=(0,m.jsx)(`div`,{role:`separator`,tabIndex:0,"aria-orientation":`horizontal`,className:i,...r,children:a}),t[6]=r,t[7]=i,t[8]=o):o=t[8],o}var b=100,x=.35;function S(e,t,n){let r=e.at(-1),i=e.at(-2);for(r&&i&&Math.abs(t-r.height)>2&&(t-r.height)*(r.height-i.height)<0&&e.splice(0,e.length-1),e.push({height:t,time:n});e.length>2&&(e.length>16||e[1].time<n-b);)e.shift()}function C(e,t){let n=e.at(-1);if(!n||t-n.time>=b)return 0;let r=e.find(e=>e.time>=t-b);return!r||n.time<=r.time?0:Math.max(-4,Math.min(4,(n.height-r.height)/Math.max(1,t-r.time)))}function w(e,t,n,r,i){let a=Math.abs(r)>=x&&Math.abs(i)>=8,o=n+(a?r*180:0),s=e.reduce((e,t)=>Math.abs(t.height-o)<Math.abs(e.height-o)?t:e),c=e.find(e=>e.id===t)??s;return!a||Math.abs(s.height-c.height)>1?s.id:[...e].sort((e,t)=>r>0?e.height-t.height:t.height-e.height).find(e=>r>0?e.height>c.height+1:e.height<c.height-1)?.id??s.id}function T(e,t,n){let r=e<t?t:e>n?n:e,i=e-r;return r+Math.sign(i)*48*(1-1/(1+Math.abs(i)*.55/48))}function E(e){let t=(0,p.c)(82),{surfaceRef:n,initialPoint:r,getPoints:i,minimumHeight:o,onRelease:s,onCommit:u,renderMode:d}=e,m=d===void 0?`height`:d,[h,g]=(0,f.useState)(r),[_,v]=(0,f.useState)(!1),[y,b]=(0,f.useState)(!1),x=(0,f.useRef)(r),E=(0,f.useRef)(null),A=(0,f.useRef)(null),j=(0,f.useRef)(null),M=(0,f.useRef)(null),N=(0,f.useRef)(!1),P=(0,f.useRef)(null),F;t[0]===n?F=t[1]:(F=()=>{let e=n.current;if(!e)return 0;if(!P.current)return e.getBoundingClientRect().height;let t=parseFloat(getComputedStyle(e).translate.split(` `)[1])||0;return P.current.layoutHeight-t},t[0]=n,t[1]=F);let I=a(F),L;t[2]===n?L=t[3]:(L=e=>{let t=n.current;t&&(P.current?t.style.translate=`0 ${P.current.layoutHeight-e}px`:t.style.height=`${e}px`)},t[2]=n,t[3]=L);let R=a(L),z;t[4]!==m||t[5]!==n||t[6]!==R?(z=(e,t)=>{let r=n.current;if(r){if(m===`translate`&&!P.current){let e=Math.max(...t.map(k))+144,{maxHeight:n,position:i,bottom:a,left:o,right:s}=r.style;P.current={layoutHeight:e,styles:{maxHeight:n,position:i,bottom:a,left:o,right:s}},Object.assign(r.style,{position:`absolute`,bottom:`0px`,left:`0px`,right:`0px`}),r.style.maxHeight=`none`,r.style.height=`${e}px`}r.setAttribute(`data-height-snap-active`,``),r.style.willChange=P.current?`translate`:`height`,R(e)}},t[4]=m,t[5]=n,t[6]=R,t[7]=z):z=t[7];let B=a(z),V;t[8]===n?V=t[9]:(V=()=>{let e=n.current;e&&(P.current&&(e.style.translate=``,Object.assign(e.style,P.current.styles),e.style.height=``),e.style.willChange=``,e.removeAttribute(`data-height-snap-active`)),P.current=null},t[8]=n,t[9]=V);let H=a(V),ae;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(ae=()=>{A.current!==null&&cancelAnimationFrame(A.current),A.current=null,j.current=null,M.current?.cancel(),M.current=null},t[10]=ae):ae=t[10];let U=a(ae),W;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(W=()=>{let e=E.current;E.current=null,e?.handle.hasPointerCapture?.(e.pointerId)&&e.handle.releasePointerCapture(e.pointerId)},t[11]=W):W=t[11];let G=a(W),oe;t[12]!==U||t[13]!==H||t[14]!==i||t[15]!==u||t[16]!==B||t[17]!==I||t[18]!==G||t[19]!==n||t[20]!==R?(oe=(e,t,r,a)=>{let o=r===void 0||r,s=a===void 0?0:a,d=n.current;if(!d)return;let f=t??I();U(),R(f);let p=i(),m=p.find(t=>t.id===e);if(!m)return;if(B(f,p),G(),v(!1),b(!1),x.current=e,g(e),R(m.height),u?.(e),!o||Math.abs(f-m.height)<1||typeof d.animate!=`function`||window.matchMedia(`(prefers-reduced-motion: reduce)`).matches){H();return}b(!0);let h=P.current?.layoutHeight,_=m.height-f,y=c([d],h===void 0?{height:[`${f}px`,`${m.height}px`]}:{translate:[`0 ${h-f}px`,`0 ${h-m.height}px`]},{type:l,stiffness:576,damping:48,mass:1,velocity:s*1e3*100/_,restDelta:20/Math.abs(_),restSpeed:500/Math.abs(_)});M.current=y,y.finished.catch(ie).then(()=>{M.current===y&&(M.current=null,H(),b(!1))})},t[12]=U,t[13]=H,t[14]=i,t[15]=u,t[16]=B,t[17]=I,t[18]=G,t[19]=n,t[20]=R,t[21]=oe):oe=t[21];let K=a(oe),se;t[22]!==U||t[23]!==i||t[24]!==o||t[25]!==B||t[26]!==I||t[27]!==n||t[28]!==R?(se=e=>{if(E.current||!e.isPrimary||e.pointerType===`mouse`&&e.button!==0||!n.current)return;let t=I();U(),R(t);let r=i();r.length&&(b(!1),E.current={pointerId:e.pointerId,startY:e.clientY,height:t,point:x.current,points:r,handle:e.currentTarget,minimum:o??Math.min(...r.map(re)),maximum:Math.max(...r.map(O)),samples:[{height:t,time:e.timeStamp}]},N.current=!1,B(t,r),v(!0),e.currentTarget.setPointerCapture(e.pointerId),e.preventDefault())},t[22]=U,t[23]=i,t[24]=o,t[25]=B,t[26]=I,t[27]=n,t[28]=R,t[29]=se):se=t[29];let ce=a(se),le;t[30]!==m||t[31]!==R?(le=e=>{let t=E.current;if(!t||t.pointerId!==e.pointerId)return;let n=t.startY-e.clientY;Math.abs(n)>3&&(N.current=!0),S(t.samples,t.height+n,e.timeStamp);let r=T(t.height+n,t.minimum,t.maximum);j.current=m===`height`?Math.max(t.minimum,r):r,A.current===null&&(A.current=requestAnimationFrame(()=>{A.current=null,j.current!==null&&R(j.current)})),e.preventDefault()},t[30]=m,t[31]=R,t[32]=le):le=t[32];let ue=a(le),de;t[33]!==U||t[34]!==s||t[35]!==I||t[36]!==G||t[37]!==K||t[38]!==n?(de=(e,t)=>{let r=E.current;if(!r||r.pointerId!==e.pointerId)return;let i=j.current??I(),a=r.height+r.startY-e.clientY;t||S(r.samples,a,e.timeStamp);let o=t?0:C(r.samples,e.timeStamp);if(G(),!t&&N.current&&s?.(i,o,r.height))U(),v(!1),n.current&&(n.current.style.willChange=``);else{let e=t||!N.current?r.point:w(r.points,r.point,i,o,a-r.height);K(e,i,!0,o)}e.preventDefault()},t[33]=U,t[34]=s,t[35]=I,t[36]=G,t[37]=K,t[38]=n,t[39]=de):de=t[39];let q=a(de),fe;t[40]!==i||t[41]!==K?(fe=e=>{let t=[...i()].sort(ne),n=t.find(e=>e.id===x.current);if(!n)return;let r=e>0?t.find(e=>e.height>n.height+1):t.sort(D).find(e=>e.height<n.height-1);r&&K(r.id)},t[40]=i,t[41]=K,t[42]=fe):fe=t[42];let J=a(fe),pe;t[43]!==i||t[44]!==K||t[45]!==J?(pe=()=>{if(N.current){N.current=!1;return}let e=[...i()].sort(te);x.current===e.at(-1)?.id?K(e[0].id):J(1)},t[43]=i,t[44]=K,t[45]=J,t[46]=pe):pe=t[46];let me=a(pe),Y;t[47]!==i||t[48]!==me||t[49]!==K||t[50]!==J?(Y=e=>{if(![`ArrowUp`,`ArrowDown`,`Home`,`End`,`Enter`,` `].includes(e.key))return;e.preventDefault();let t=[...i()].sort(ee);t.length&&(e.key===`ArrowUp`?J(1):e.key===`ArrowDown`?J(-1):e.key===`Home`?K(t.at(-1).id):e.key===`End`?K(t[0].id):me())},t[47]=i,t[48]=me,t[49]=K,t[50]=J,t[51]=Y):Y=t[51];let X=a(Y),he;t[52]!==U||t[53]!==H||t[54]!==r||t[55]!==G||t[56]!==n?(he=()=>{U(),G(),H(),x.current=r,g(r),v(!1),b(!1),N.current=!1,n.current&&(n.current.style.height=``,n.current.style.willChange=``)},t[52]=U,t[53]=H,t[54]=r,t[55]=G,t[56]=n,t[57]=he):he=t[57];let Z=a(he),Q,ge;t[58]!==U||t[59]!==H||t[60]!==G?(Q=()=>()=>{U(),G(),H()},ge=[U,G,H],t[58]=U,t[59]=H,t[60]=G,t[61]=Q,t[62]=ge):(Q=t[61],ge=t[62]),(0,f.useLayoutEffect)(Q,ge);let $;t[63]===q?$=t[64]:($=e=>q(e,!1),t[63]=q,t[64]=$);let _e=a($),ve;t[65]===q?ve=t[66]:(ve=e=>q(e,!0),t[65]=q,t[66]=ve);let ye=a(ve),be;t[67]===q?be=t[68]:(be=e=>q(e,!0),t[67]=q,t[68]=be);let xe=a(be),Se;return t[69]!==_||t[70]!==me||t[71]!==X||t[72]!==ce||t[73]!==ue||t[74]!==Z||t[75]!==K||t[76]!==y||t[77]!==h||t[78]!==_e||t[79]!==ye||t[80]!==xe?(Se={snapPoint:h,dragging:_,settling:y,settleAt:K,reset:Z,handlePointerDown:ce,handlePointerMove:ue,handlePointerUp:_e,handlePointerCancel:ye,handleLostPointerCapture:xe,handleClick:me,handleKeyDown:X},t[69]=_,t[70]=me,t[71]=X,t[72]=ce,t[73]=ue,t[74]=Z,t[75]=K,t[76]=y,t[77]=h,t[78]=_e,t[79]=ye,t[80]=xe,t[81]=Se):Se=t[81],Se}function ee(e,t){return e.height-t.height}function te(e,t){return e.height-t.height}function D(e,t){return t.height-e.height}function ne(e,t){return e.height-t.height}function O(e){return e.height}function re(e){return e.height}function ie(){}function k(e){return e.height}var A=.72,j=.98,M=64,N=()=>Math.max(1,window.innerHeight),P=(e,t)=>{let n=Math.max(1,e)*A;return t==null||!Number.isFinite(t)?n:Math.min(n,Math.max(0,t))},F=e=>{let t=(0,p.c)(20),n;t[0]===e?n=t[1]:(n=e===void 0?{}:e,t[0]=e,t[1]=n);let{initialSnapPoint:r,fitContent:i,onDismiss:o,dismissThresholdPx:s}=n,c=r===void 0?A:r,l=i!==void 0&&i,u=s===void 0?M:s,d=f.useRef(null),m=f.useRef(null),h=f.useRef(c),g=o?0:void 0,_;t[2]===l?_=t[3]:(_=()=>{let e=N(),t=d.current?.parentElement?.clientHeight||e;return l&&h.current===.72&&d.current&&!d.current.hasAttribute(`data-height-snap-active`)&&(m.current=P(e,d.current.getBoundingClientRect().height)),[{id:A,height:Math.min(t,P(e,l?m.current:void 0))},{id:j,height:Math.min(t,e*j)}]},t[2]=l,t[3]=_);let v;t[4]!==u||t[5]!==l||t[6]!==o?(v=(e,t,n)=>{let r=d.current?.parentElement?.clientHeight||N(),i=Math.min(r,P(N(),l?m.current:void 0)),a=t<-.55&&n<=i+1&&e<i-8;return!o||!a&&e>i-u?!1:(o(),!0)},t[4]=u,t[5]=l,t[6]=o,t[7]=v):v=t[7];let y;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(y=e=>{h.current=e},t[8]=y):y=t[8];let b;t[9]!==c||t[10]!==g||t[11]!==_||t[12]!==v?(b={surfaceRef:d,initialPoint:c,renderMode:`translate`,minimumHeight:g,getPoints:_,onRelease:v,onCommit:y},t[9]=c,t[10]=g,t[11]=_,t[12]=v,t[13]=b):b=t[13];let x=E(b),S;t[14]!==x||t[15]!==c?(S=()=>{m.current=null,h.current=c,x.reset()},t[14]=x,t[15]=c,t[16]=S):S=t[16];let C=a(S),w;return t[17]!==x||t[18]!==C?(w={...x,surfaceRef:d,reset:C},t[17]=x,t[18]=C,t[19]=w):w=t[19],w},I=e=>{let t=(0,p.c)(13),{controller:n,ariaLabel:r,compact:i}=e,a=i!==void 0&&i,o;t[0]===n.snapPoint?o=t[1]:(o=Math.round(n.snapPoint*100),t[0]=n.snapPoint,t[1]=o);let s=`flex cursor-ns-resize touch-none justify-center focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[var(--interactive-focus-ring)] ${a?`min-h-4 pt-1`:`min-h-8 pt-2.5`}`,c;return t[2]!==r||t[3]!==n.handleClick||t[4]!==n.handleKeyDown||t[5]!==n.handleLostPointerCapture||t[6]!==n.handlePointerCancel||t[7]!==n.handlePointerDown||t[8]!==n.handlePointerMove||t[9]!==n.handlePointerUp||t[10]!==o||t[11]!==s?(c=(0,m.jsx)(y,{"data-mobile-sheet-snap-handle":!0,role:`separator`,tabIndex:0,"aria-label":r,"aria-orientation":`horizontal`,"aria-valuemin":A*100,"aria-valuemax":j*100,"aria-valuenow":o,className:s,onPointerDown:n.handlePointerDown,onPointerMove:n.handlePointerMove,onPointerUp:n.handlePointerUp,onPointerCancel:n.handlePointerCancel,onLostPointerCapture:n.handleLostPointerCapture,onClick:n.handleClick,onKeyDown:n.handleKeyDown}),t[2]=r,t[3]=n.handleClick,t[4]=n.handleKeyDown,t[5]=n.handleLostPointerCapture,t[6]=n.handlePointerCancel,t[7]=n.handlePointerDown,t[8]=n.handlePointerMove,t[9]=n.handlePointerUp,t[10]=o,t[11]=s,t[12]=c):c=t[12],c},L=new WeakMap;function R(e){L.set(e.currentTarget,!0)}function z(e){if(L.delete(e.currentTarget))return!0;if(e.detail!==0)return!1;if(typeof document>`u`)return!0;let t=document.activeElement,n=e.currentTarget;return n instanceof Node&&t instanceof Node&&n.contains(t)}function B(e){e.target===e.currentTarget&&R(e)}function V(e){return e.target===e.currentTarget&&z(e)}var H=(0,f.createContext)(!0),ae=(e,t)=>{let n=`flex min-h-0 flex-col bg-background shadow-none`;if(e===`page`)return`${n} h-full w-full`;let r=`${n} pwa-overlay-panel`;return t===`top`?`${r} mx-auto mb-auto max-h-[calc(100dvh-0.75rem)] w-full max-w-lg rounded-b-xl border-x border-b border-border/50`:t===`left`?`${r} h-full w-[min(86vw,24rem)] rounded-r-xl border-r border-y border-border/50`:t===`right`?`${r} ml-auto h-full w-[min(86vw,24rem)] rounded-l-xl border-l border-y border-border/50`:`${r} mx-auto mt-auto max-h-[calc(100dvh-0.75rem)] w-full max-w-lg rounded-t-2xl border-x border-t border-border/50 pb-[max(0.5rem,var(--yuri-app-bottom-safe,0px),var(--yuri-safe-area-bottom,env(safe-area-inset-bottom,0px)))]`},U=e=>Math.min(1,Math.max(0,Number.isFinite(e)?e:0)),W=(e,t)=>{let n=U(t),r=`${(1-n)*100}%`;return{progress:n,scrimOpacity:n,surfaceOpacity:n,surfaceTransform:e===`left`?`translate3d(-${r}, 0, 0)`:e===`right`?`translate3d(${r}, 0, 0)`:e===`top`?`translate3d(0, -${r}, 0)`:`translate3d(0, ${r}, 0)`}},G=(e,t)=>{let n=U(t);return e===`present`?n:1-n},oe=(e,t)=>e===`present`?+(t===`commit`):t===`commit`?0:1,K=e=>+!!e,se=`mobile-sessions`,ce=new Map,le=e=>ce.get(e)??null,ue=(e,t)=>(ce.set(e,t),()=>{ce.get(e)===t&&ce.delete(e)}),de=`.overlay-scrollbar-container`,q=1,fe=e=>e===`left`||e===`right`?`x`:`y`,J=e=>e===`bottom`||e===`right`?1:-1,pe=(e,t,n)=>{let r=fe(e)===`x`?t:n;return Math.max(0,r*J(e))},me=(e,t,n,r,i)=>{let a=pe(e,t,n),o=Math.abs(fe(e)===`x`?n:t);return Math.hypot(t,n)>r&&a>0&&o<a*i},Y=(e,t)=>Math.min(1,Math.max(0,e/Math.max(1,t))),X=(e,t,n,r)=>Math.min(r,Math.max(n,e*t)),he=(e,t,n,r,i)=>e>=n||e>=i&&t>=r,Z=(e,t,n,r,i)=>t!==0&&n>0?t*i/n:r>80?0:e,Q=(e,t,n=q)=>{if(t===`bottom`)return e.scrollTop<=n;if(t===`top`)return e.scrollTop>=e.scrollHeight-e.clientHeight-n;if(e.matches?.(`:dir(rtl)`)){let r=e.scrollWidth-e.clientWidth;return t===`right`?Math.abs(e.scrollLeft)<=n:Math.abs(e.scrollLeft)>=r-n}return t===`right`?e.scrollLeft<=n:e.scrollLeft>=e.scrollWidth-e.clientWidth-n},ge=(e,t)=>{for(let n=0;n<e.length;n+=1){let r=e.item(n);if(r?.identifier===t)return r}return null},$=(e,t)=>{let n=window.getComputedStyle(e),r=fe(t),i=r===`x`?n.overflowX:n.overflowY,a=r===`x`?e.scrollWidth:e.scrollHeight,o=r===`x`?e.clientWidth:e.clientHeight;return(i===`auto`||i===`scroll`||i===`overlay`)&&a>o},_e=(e,t,n,r)=>{let i=t instanceof Element?t:null,a=i instanceof HTMLElement?i:i?.parentElement??null;for(;a&&e.contains(a);){if($(a,n))return a;if(a===e)break;a=a.parentElement}let o=i?.closest(r)??null;return o&&e.contains(o)&&$(o,n)?o:null},ve=e=>{let t=f.useRef(e),n=f.useRef(null),r=f.useRef(null);return t.current=e,f.useCallback(e=>{if(n.current?.(),n.current=null,!e)return;let i=()=>{let e=r.current;r.current=null,e?.active&&e.controller?.finish(`cancel`)},a=(e,t,n)=>{let r=fe(e.edge)===`x`?t.clientX:t.clientY,i=n-e.lastTime,a=r-e.lastPrimary;e.velocity=Z(e.velocity,a,i,n-e.lastVelocityTime,J(e.edge)),a!==0&&i>0&&(e.lastVelocityTime=n),e.lastPrimary=r,e.lastTime=n,e.distance=pe(e.edge,t.clientX-e.startX,t.clientY-e.startY)},o=n=>{i();let a=t.current;if(a.disabled||n.touches.length!==1)return;let o=n.target instanceof Element?n.target:null,s=a.reservedTargetSelector?o?.closest(a.reservedTargetSelector):null;if(s&&e.contains(s)||o?.closest(`input, textarea, select, [contenteditable=""], [contenteditable="true"], [data-mobile-sheet-no-dismiss]`))return;let c=n.touches[0],l=_e(e,n.target,a.edge,a.scrollContainerSelector??de);if(l&&!Q(l,a.edge))return;let u=e.getBoundingClientRect(),d=fe(a.edge)===`x`?u.width||window.innerWidth:u.height||window.innerHeight;r.current={edge:a.edge,motionId:a.motionId,touchId:c.identifier,startX:c.clientX,startY:c.clientY,lastPrimary:fe(a.edge)===`x`?c.clientX:c.clientY,lastTime:n.timeStamp,lastVelocityTime:n.timeStamp,velocity:0,distance:0,commitDistance:X(d,a.commitDistanceRatio??.1,a.minCommitDistance??40,a.maxCommitDistance??64),motionDistance:d,intentDistance:a.intentDistance??8,maxOffAxisRatio:a.maxOffAxisRatio??1,flingVelocity:a.flingVelocity??.65,flingMinDistance:a.flingMinDistance??12,controller:null,active:!1}},s=e=>{let n=r.current;if(!n)return;if(t.current.disabled||e.touches.length!==1){i();return}let o=ge(e.touches,n.touchId);if(!o){i();return}if(a(n,o,e.timeStamp),!n.active){if(Math.hypot(o.clientX-n.startX,o.clientY-n.startY)<=n.intentDistance)return;if(!me(n.edge,o.clientX-n.startX,o.clientY-n.startY,n.intentDistance,n.maxOffAxisRatio)){r.current=null;return}let e=le(n.motionId);if(!e){r.current=null;return}if(!e.begin(`dismiss`)){r.current=null;return}n.active=!0,n.controller=e}n.controller?.update(Y(n.distance,n.motionDistance)),e.preventDefault()},c=e=>{let t=r.current;if(!t)return;let n=ge(e.changedTouches,t.touchId);if(!n){i();return}if(r.current=null,!t.active)return;a(t,n,e.timeStamp),t.controller?.update(Y(t.distance,t.motionDistance));let o=he(t.distance,t.velocity,t.commitDistance,t.flingVelocity,t.flingMinDistance);t.controller?.finish(o?`commit`:`cancel`),e.preventDefault()},l=()=>i();e.addEventListener(`touchstart`,o,{passive:!0,capture:!0}),e.addEventListener(`touchmove`,s,{passive:!1,capture:!0}),e.addEventListener(`touchend`,c,{passive:!1,capture:!0}),e.addEventListener(`touchcancel`,l,{passive:!0,capture:!0}),n.current=()=>{i(),e.removeEventListener(`touchstart`,o,!0),e.removeEventListener(`touchmove`,s,!0),e.removeEventListener(`touchend`,c,!0),e.removeEventListener(`touchcancel`,l,!0)}},[])},ye=`mobile-overlay-root`,be=200,xe=80,Se=`cubic-bezier(0.32, 0.72, 0, 1)`,Ce=`a[href], button:not(:disabled), input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [tabindex]:not([tabindex="-1"])`,we=()=>{if(typeof document>`u`)return null;let e=document.getElementById(ye);return e||(e=document.createElement(`div`),e.id=ye,document.body.appendChild(e)),e},Te=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,Ee=({id:e,open:t,onOpenChange:n,keepMounted:r=!1,presentation:i=`sheet`,edge:a=`bottom`,children:o,className:c,scrimClassName:l,surfaceClassName:u,surfaceElementRef:p,dismissGesture:g=!1,onExitComplete:_,onPreviewChange:y,ariaLabel:b})=>{let x=f.useRef(null),S=f.useRef(null),C=f.useRef(null),w=f.useRef(null),T=f.useRef(t),E=f.useRef(n),ee=f.useRef(_),te=f.useRef(y),D=f.useRef(0),ne=f.useRef(0),O=f.useRef(null),re=f.useRef([]),ie=f.useRef(null),k=f.useRef(`standard`),A=f.useRef(`present`),j=f.useRef(0),M=f.useRef(!1),N=f.useRef(t),P=f.useRef(!1),F=f.useRef(t),I=f.useRef(null),[L,R]=f.useState(t),[z,U]=f.useState(t),[se,ce]=f.useState(`standard`),[le,de]=f.useState(!1),q=se===`interactive-present`,fe=f.useSyncExternalStore(d.subscribe,d.getSnapshot,d.getSnapshot),J=z&&!q&&fe===e,pe=ve({motionId:e,edge:a,disabled:!g,...typeof g==`object`?g:{}}),me=f.useCallback(e=>{C.current=e,pe(e),typeof p==`function`?p(e):p&&typeof p==`object`&&(p.current=e)},[pe,p]),Y=f.useCallback(()=>{F.current&&(F.current=!1,U(!1),r||R(!1),ee.current?.())},[r]);T.current=t,E.current=n,ee.current=_,te.current=y,f.useLayoutEffect(()=>{te.current?.(z&&q)},[z,q]),typeof document<`u`&&!x.current&&(x.current=we());let X=f.useCallback(e=>{let t=W(a,e);D.current=t.progress,!(!S.current||!C.current)&&(S.current.style.opacity=String(t.scrimOpacity),C.current.style.transform=t.surfaceTransform,C.current.style.opacity=String(t.surfaceOpacity))},[a]),he=f.useCallback(()=>{O.current!==null&&window.cancelAnimationFrame(O.current),O.current=null},[]),Z=f.useCallback(()=>{S.current&&(S.current.style.willChange=``),C.current&&(C.current.style.willChange=``)},[]),Q=f.useCallback((e=re.current)=>{for(let t of e)t.cancel();re.current=[]},[]),ge=f.useCallback(()=>{he();let e=ie.current;if(e){let t=e.animations[1]?.effect?.getComputedTiming().progress;X(typeof t==`number`&&Number.isFinite(t)?e.from+(e.target-e.from)*t:D.current),Q(e.animations),ie.current=null}else Q();Z(),de(!1)},[X,Q,he,Z]),$=f.useCallback((e,t)=>{if(ie.current?.target===e)return;ge();let n=D.current,r=S.current,i=C.current;if(de(!0),!r||!i||Te()||n===e){X(e),Z(),de(!1),t?.();return}let o=W(a,n),s=W(a,e);r.style.willChange=`opacity`,i.style.willChange=`transform, opacity`;let c=Math.max(xe,be*Math.abs(e-n)),l=[r.animate([{opacity:o.scrimOpacity},{opacity:s.scrimOpacity}],{duration:c,easing:Se,fill:`forwards`}),i.animate([{transform:o.surfaceTransform,opacity:o.surfaceOpacity},{transform:s.surfaceTransform,opacity:s.surfaceOpacity}],{duration:c,easing:Se,fill:`forwards`})];re.current=l;let u={from:n,target:e,animations:l};ie.current=u,Promise.all(l.map(e=>e.finished.catch(()=>void 0))).then(()=>{ie.current===u&&(X(e),Q(l),ie.current=null,Z(),de(!1),t?.())})},[X,Q,Z,a,ge]);if(f.useLayoutEffect(()=>{P.current=L,L&&X(ne.current)},[X,L]),f.useLayoutEffect(()=>{F.current=z},[z]),f.useEffect(()=>{t&&!P.current&&(ne.current=D.current,R(!0)),t&&!F.current&&(F.current=!0,U(!0)),P.current&&k.current===`standard`&&$(K(t),()=>{!T.current&&k.current===`standard`&&Y()})},[Y,t,$]),f.useLayoutEffect(()=>{!L||k.current!==`standard`||$(+!!t,()=>{!T.current&&k.current===`standard`&&Y()})},[Y,L,t,$]),f.useEffect(()=>{if(!(!z||q))return window.dispatchEvent(new Event(`yuri:mobile-overlay-opened`)),()=>{window.dispatchEvent(new Event(`yuri:mobile-overlay-closed`))}},[z,q]),f.useEffect(()=>{if(!(!z||q))return d.add({id:e,onClose:()=>E.current(!1)},document.body)},[z,e,q]),f.useEffect(()=>{if(!z||q||!J)return;let e=C.current,t=document.activeElement instanceof HTMLElement?document.activeElement:null;w.current?.focus({preventScroll:!0});let n=t=>{if(t.key===`Escape`&&d.closeTop(),t.key!==`Tab`||!e)return;let n=Array.from(e.querySelectorAll(Ce)).filter(e=>!e.closest(`[data-mobile-sheet-snap-handle]`)),r=n[0]??w.current,i=n.at(-1)??w.current;!r||!i||(t.shiftKey&&document.activeElement===r&&(t.preventDefault(),i.focus({preventScroll:!0})),!t.shiftKey&&document.activeElement===i&&(t.preventDefault(),r.focus({preventScroll:!0})))};return document.addEventListener(`keydown`,n),()=>{document.removeEventListener(`keydown`,n),v()||t?.focus({preventScroll:!0})}},[z,q,J]),I.current={begin:e=>{if(e===`dismiss`&&(!F.current||k.current===`interactive-present`))return!1;ge(),j.current+=1,M.current=!0,A.current=e;let t=e===`present`?`interactive-present`:`interactive-dismiss`;return k.current=t,ce(t),de(!0),e===`present`&&(ne.current=D.current,F.current=!0,U(!0),R(!0)),!0},update:e=>{M.current&&(ne.current=G(A.current,e),O.current===null&&(O.current=window.requestAnimationFrame(()=>{O.current=null,M.current&&X(ne.current)})))},finish:e=>{if(!M.current)return;M.current=!1;let t=j.current,n=A.current,r=oe(n,e);O.current!==null&&(he(),X(ne.current)),$(r,()=>{t===j.current&&(e===`commit`&&E.current(n===`present`),n===`present`&&e===`cancel`&&!T.current&&Y(),k.current=`standard`,ce(`standard`),r===0&&Y())})},interrupt:()=>{j.current+=1,M.current=!1;let e=k.current===`interactive-present`&&!T.current;e||(k.current=`standard`,ce(`standard`)),ge(),$(K(T.current),()=>{T.current||Y(),e&&(k.current=`standard`,ce(`standard`))})}},f.useLayoutEffect(()=>{let e=N.current;N.current=t,e&&!t&&k.current!==`standard`&&I.current?.interrupt()},[t]),f.useEffect(()=>{let t=ue(e,{begin:e=>I.current?.begin(e)??!1,update:e=>I.current?.update(e),finish:e=>I.current?.finish(e),interrupt:()=>I.current?.interrupt()});return()=>{t(),he(),Q(),ie.current=null,Z(),I.current=null}},[Q,he,Z,e]),!L||!x.current)return null;let _e=(0,m.jsx)(`div`,{ref:S,className:s(`yuri-mobile-window-motion yuri-keyboard-inset-surface fixed inset-0 z-[60] flex flex-col bg-[rgb(0_0_0_/_0.45)]`,le&&`yuri-mobile-window-motion-active`,!z&&!q&&`pointer-events-none invisible`,l,c),"data-mobile-overlay-active":String(z),role:q?void 0:`dialog`,"aria-label":q?void 0:b,"aria-modal":z&&J?`true`:void 0,"aria-hidden":q||!z||!J||void 0,inert:q||!z||!J||void 0,onPointerDown:B,onClick:e=>{!z||q||!J||V(e)&&E.current(!1)},children:(0,m.jsxs)(`div`,{ref:me,className:s(`yuri-mobile-floating-shell`,ae(i,a),u),"data-yuri-motion-id":e,style:{contain:`layout paint style`},onClick:e=>e.stopPropagation(),children:[(0,m.jsx)(`span`,{ref:w,tabIndex:-1,className:`sr-only`,role:`group`,"aria-label":b}),(0,m.jsx)(H.Provider,{value:J,children:o})]})});return(0,h.createPortal)(_e,x.current)},De=f.createContext(null),Oe=e=>{let t=(0,p.c)(5),{children:n}=e,r=f.useContext(De);if(!r)return null;let i;t[0]===n?i=t[1]:(i=(0,m.jsx)(`div`,{className:`flex shrink-0 items-center gap-1.5`,children:n}),t[0]=n,t[1]=i);let a;return t[2]!==r||t[3]!==i?(a=(0,h.createPortal)(i,r),t[2]=r,t[3]=i,t[4]=a):a=t[4],a},ke=e=>{let t=(0,p.c)(50),{id:n,open:r,onOpenChange:i,title:a,leading:c,trailing:l,ariaLabel:d,closeAriaLabel:h,showCloseButton:g,compactHeader:_,resizeAriaLabel:v,initiallyExpanded:y,fitContent:b,bodyClassName:x,className:S,children:C}=e,w=g===void 0||g,T=_!==void 0&&_,E=y!==void 0&&y,ee=b!==void 0&&b,te=E?j:void 0,D;t[0]!==i||t[1]!==r?(D=r?()=>i(!1):void 0,t[0]=i,t[1]=r,t[2]=D):D=t[2];let ne;t[3]!==ee||t[4]!==te||t[5]!==D?(ne={initialSnapPoint:te,fitContent:ee,onDismiss:D},t[3]=ee,t[4]=te,t[5]=D,t[6]=ne):ne=t[6];let O=F(ne),[re,ie]=f.useState(null),k=a!=null||c!=null||l!=null,A=O.snapPoint===j,M=A||!ee,N;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(N={reservedTargetSelector:`[data-mobile-sheet-snap-handle]`},t[7]=N):N=t[7];let P=A?`h-[98dvh] max-h-[98dvh]`:ee?`h-auto max-h-[72dvh]`:`h-[72dvh] max-h-[98dvh]`,L=O.surfaceRef,R=O.reset,z=M&&`flex-1`,B;t[8]===z?B=t[9]:(B=s(`flex min-h-0 flex-col`,z),t[8]=z,t[9]=B);let V;t[10]!==T||t[11]!==v||t[12]!==O?(V=(0,m.jsx)(I,{controller:O,ariaLabel:v,compact:T}),t[10]=T,t[11]=v,t[12]=O,t[13]=V):V=t[13];let H;t[14]!==h||t[15]!==T||t[16]!==ee||t[17]!==k||t[18]!==c||t[19]!==i||t[20]!==w||t[21]!==a||t[22]!==l?(H=k?(0,m.jsxs)(`div`,{"data-mobile-sheet-header":!0,className:T?`flex min-h-6 items-center gap-2 px-3 text-xs`:ee?`flex min-h-9 items-center gap-2 px-4 pb-1`:`flex min-h-10 items-center gap-2 px-4 pb-2`,children:[c?(0,m.jsx)(`div`,{className:`flex shrink-0 items-center`,children:c}):null,(0,m.jsx)(`div`,{className:s(`min-w-0 flex-1`,T&&`truncate`),children:a}),l?(0,m.jsx)(`div`,{className:`flex shrink-0 items-center gap-1.5`,children:l}):null,(0,m.jsx)(`div`,{ref:ie,className:`contents`}),w?(0,m.jsx)(o,{type:`button`,variant:`ghost`,size:`icon`,onClick:()=>i(!1),"aria-label":h,className:`shrink-0 text-muted-foreground`,style:{touchAction:`manipulation`},children:(0,m.jsx)(u,{name:`close`,className:`size-5`})}):null]}):null,t[14]=h,t[15]=T,t[16]=ee,t[17]=k,t[18]=c,t[19]=i,t[20]=w,t[21]=a,t[22]=l,t[23]=H):H=t[23];let ae;t[24]!==V||t[25]!==H?(ae=(0,m.jsxs)(`div`,{className:`shrink-0`,children:[V,H]}),t[24]=V,t[25]=H,t[26]=ae):ae=t[26];let U=M&&`flex-1`,W;t[27]!==x||t[28]!==U?(W=s(`flex min-h-0 flex-col overflow-hidden`,U,x),t[27]=x,t[28]=U,t[29]=W):W=t[29];let G;t[30]!==C||t[31]!==W?(G=(0,m.jsx)(`div`,{className:W,"data-page-scroll-lock":`true`,children:C}),t[30]=C,t[31]=W,t[32]=G):G=t[32];let oe;t[33]!==B||t[34]!==ae||t[35]!==G?(oe=(0,m.jsxs)(`div`,{className:B,children:[ae,G]}),t[33]=B,t[34]=ae,t[35]=G,t[36]=oe):oe=t[36];let K;t[37]!==d||t[38]!==S||t[39]!==n||t[40]!==i||t[41]!==r||t[42]!==O.reset||t[43]!==O.surfaceRef||t[44]!==oe||t[45]!==P?(K=(0,m.jsx)(Ee,{id:n,className:S,open:r,onOpenChange:i,presentation:`sheet`,edge:`bottom`,dismissGesture:N,ariaLabel:d,surfaceClassName:P,surfaceElementRef:L,onExitComplete:R,children:oe}),t[37]=d,t[38]=S,t[39]=n,t[40]=i,t[41]=r,t[42]=O.reset,t[43]=O.surfaceRef,t[44]=oe,t[45]=P,t[46]=K):K=t[46];let se;return t[47]!==re||t[48]!==K?(se=(0,m.jsx)(De.Provider,{value:re,children:K}),t[47]=re,t[48]=K,t[49]=se):se=t[49],se};export{_ as C,v as S,I as _,pe as a,E as b,me as c,le as d,H as f,V as g,B as h,X as i,he as l,R as m,Oe as n,Y as o,z as p,Ee as r,Z as s,ke as t,se as u,j as v,y as x,F as y};
@@ -1,3 +1,3 @@
1
- import{n as e,r as t}from"./rolldown-runtime-hePW80VL.js";import{c as n,i as r,n as i,r as a}from"./runtime-switch-DEPKHgdL.js";import{n as o}from"./runtime-fetch-V-iMWR8t.js";import{r as s}from"./platform-CiUKDeXd.js";import{ot as c,st as l}from"./vendor-base-ui-fom6orB6.js";import"./brand-storage-bootstrap-D4BW3w-M.js";import{R as u}from"./client-CzjApAA4.js";import{B as d,D as f,E as p}from"./prompt-attachment-upload-Bem87nmm.js";import{n as m}from"./vendor-react-D5BntRmA.js";import{a as h}from"./runtime-file-resource-CKQQEwNv.js";import{r as g}from"./vendor-reactuses-core-B8s-Rcd-.js";import{a as _,n as v}from"./vendor-aparajita-capacitor-secure-storage-xol_6BsB.js";import{t as ee}from"./i18n-BvjeIWrT.js";import{n as y,o as b,s as x}from"./mobileConnections-C-97caJA.js";import{C as te,M as ne,c as S,o as re,p as ie,s as C,t as ae}from"./MobileDetailNavigation-C4jx-32g.js";import{s as oe}from"./useMobileNavigationStore-CRoFDKhN.js";import{i as w,n as se}from"./useAssistantUIStore-CI42fWZh.js";import{n as T}from"./input-store-wWToFdzi.js";import{i as ce,t as le}from"./AgentAvatar-BzOcEUoS.js";import{n as ue}from"./Icon-RGzME9hn.js";import{n as de,t as fe}from"./dialog-xzBmheBR.js";import{t as E}from"./rasterizePng-056Poix7.js";var D=t(l(),1),pe=m(),me=async(e,t=3)=>{let n;for(let r=0;r<t;r+=1)try{await e();return}catch(e){n=e}throw n},he=async(e,t,n=2)=>{let r=[...new Map(e.map(e=>[e.operationID,e])).values()],i=0;await Promise.all(Array.from({length:Math.min(Math.max(1,n),r.length)},async()=>{for(;i<r.length;){let e=r[i++];try{e.cleanupPhase&&e.cleanupPhase!==`files-released`?await t.cleanup(e.operationID):await t.deliver(e.operationID)}catch{}}}))},ge=e=>!!(e.serverInstanceID&&e.assistantID&&e.name&&e.avatarSeed&&e.serverLabel&&e.connectionKey),_e=`yuri.mobile-share.draft-handoff.v1`,ve=`mobile-share-handoff:`,ye=20971520,be=20971520,O=e=>`${ve}${e}`,k=e=>e??(typeof window>`u`?null:window.localStorage),A=e=>{if(!e)return{};try{let t=JSON.parse(e.getItem(`yuri.mobile-share.draft-handoff.v1`)||`{}`);return Object.fromEntries(Object.entries(t).flatMap(([e,t])=>{let n=typeof t.assistantID==`string`?t.assistantID:De(t),r=typeof t.transportIdentity==`string`?t.transportIdentity:t.targetDraftKey?.transportIdentity;if(!n||typeof t.serverInstanceID!=`string`||typeof t.connectionKey!=`string`||!r)return[];let i=t.phase===`cancelled`?`cancelled`:t.phase===`materialized`?`materialized`:`materializing`;return[[e,{...t,draftID:e,assistantID:n,transportIdentity:r,phase:i}]]}))}catch{return{}}},xe=(e,t)=>{if(!e)return!1;try{return e.setItem(_e,JSON.stringify(t)),!0}catch{return!1}},Se=(e,t)=>{let n=A(e);if(delete n[t],e)try{e.setItem(_e,JSON.stringify(n))}catch{return}},j=(e,t)=>xe(e,{...A(e),[t.draftID]:t}),Ce=(e,t)=>`native-share:${e}:${t}`,we=(e,t)=>t?e?`${e}\n\n${t}`:t:e,Te=e=>e.mime.startsWith(`image/`)&&e.byteSize>0&&e.byteSize<=ye,Ee=(e,t)=>!!t?.syntheticParts.some(t=>t.partID===O(e.draftID)&&t.text===``&&t.attachments.length===0&&t.synthetic===!0),De=e=>{let t=e.targetDraftKey?.owner;return t?.kind!==`surface`||typeof t.ownerID!=`string`||!t.ownerID.startsWith(`assistant:`)?null:t.ownerID.slice(10)||null},Oe=e=>({draftID:e.draftID,serverInstanceID:e.serverInstanceID,connectionKey:e.connectionKey,assistantID:e.assistantID,transportIdentity:e.transportIdentity}),ke=async(e,t)=>{let n=k(t),r=[];for(let t of Object.values(A(n))){if(t.phase===`cancelled`){r.push(Oe(t));continue}if(t.phase===`materialized`)try{await e(t.draftID);let i={...t,phase:`cancelled`};if(!j(n,i))continue;r.push(Oe(i))}catch{continue}}return r},Ae=(e,t)=>{let n=k(t),r=A(n)[e.draftID];return!r||r.phase!==`cancelled`||r.serverInstanceID!==e.serverInstanceID||r.connectionKey!==e.connectionKey||r.assistantID!==e.assistantID||r.transportIdentity!==e.transportIdentity?!1:(Se(n,e.draftID),!A(n)[e.draftID])},je=async(e,t)=>{let n=d({transportIdentity:e.transportIdentity},`assistant:${e.assistantID}`),r=t.captureDraftRuntime();if(r.transportIdentity!==e.transportIdentity)return!1;let i=t.getDraft(n),a=O(e.draftID);try{if(!i||!i.syntheticParts.some(e=>e.partID===a)){await t.flushDraftPersistence();let n=t.captureDraftRuntime();return n.transportIdentity===e.transportIdentity&&n.generation===r.generation}let o=await t.commitDraftSnapshot({key:n,expectedRevision:i.revision,runtime:r,values:new Map,snapshot:{text:i.text,attachments:i.attachments,syntheticParts:i.syntheticParts.filter(e=>e.partID!==a),mentions:i.mentions,...i.composerReferences===void 0?{}:{composerReferences:i.composerReferences}}});if(!o.current||!o.durable)return!1;await t.flushDraftPersistence();let s=t.captureDraftRuntime();return s.transportIdentity===e.transportIdentity&&s.generation===r.generation}catch{return!1}},Me=async(e,t)=>{if(e.attachments.length>10||!e.attachments.every(Te)||e.attachments.reduce((e,t)=>e+t.byteSize,0)>be)throw Error(`invalid_share_attachment`);let n=k(t.storage),r=d({transportIdentity:t.transportIdentity},`assistant:${e.assistantID}`),i=A(n)[e.draftID],a=!1;if(!i||p(i.targetDraftKey)!==p(r)){let a=t.input.getDraft(r);if(i={draftID:e.draftID,serverInstanceID:e.serverInstanceID,connectionKey:e.connectionKey,assistantID:e.assistantID,transportIdentity:t.transportIdentity,targetDraftKey:r,baseRevision:a?.revision??`absent`,resultText:we(a?.text??``,e.text),attachmentIDs:e.attachments.map((t,n)=>Ce(e.draftID,n)),phase:`materializing`},!j(n,i))throw Error(`handoff_journal_unavailable`)}if(i.phase===`cancelled`)return{durable:!0,cancelled:!0};(i.phase===`materialized`||Ee(i,t.input.getDraft(r)))&&(a=!0);for(let o=0;!a&&o<3;o++){let o=t.input.getDraft(r),s={...i,baseRevision:o?.revision??`absent`,resultText:we(o?.text??``,e.text),phase:`materializing`};if(!j(n,s))throw Error(`handoff_journal_unavailable`);i=s;let c=new Map,l=[];for(let n=0;n<e.attachments.length;n++){let r=e.attachments[n],a=i.attachmentIDs[n],o=f(a),s=await t.readAttachment(r);if(s.size!==r.byteSize)throw Error(`staged_file_unavailable`);c.set(o,s.type===r.mime?s:new Blob([s],{type:r.mime})),l.push({attachmentID:a,attachmentRefID:o,filename:r.originalName,mimeType:r.mime,size:r.byteSize,locator:{kind:`blob`,blobID:a},source:`local`})}let u={partID:O(e.draftID),text:``,attachments:[],synthetic:!0},d=o?.syntheticParts??[],p=await t.input.commitDraftSnapshot({key:r,expectedRevision:o?.revision??`absent`,runtime:t.input.captureDraftRuntime(),snapshot:{text:i.resultText,attachments:[...o?.attachments??[],...l],syntheticParts:d.some(e=>e.partID===u.partID)?d:[...d,u],mentions:o?.mentions??[],...o?.composerReferences===void 0?{}:{composerReferences:o.composerReferences}},values:c});if(p.durable&&p.current)a=!0;else if(p.status!==`conflict`)throw Error(`draft_handoff_${p.status}`)}if(!a)throw Error(`draft_handoff_conflict`);if(i.phase!==`materialized`&&(i={...i,phase:`materialized`},!j(n,i)))throw Error(`handoff_journal_unavailable`);try{await t.cancelDraft(e.draftID)}catch{return{durable:!0,cancelled:!1}}if(i={...i,phase:`cancelled`},!j(n,i))throw Error(`handoff_journal_unavailable`);return{durable:!0,cancelled:!0}},M=_(`YuriShare`),N=null,Ne=(e,t)=>a()===e&&i()===t,P=e=>{if(s()){se(e);return}let t=oe.getState();t.setActiveTab(`assistant`),t.openAssistant(e)},Pe=async()=>{let e=(await M.pendingAssistantOpen().catch(()=>null))?.request;if(!e)return!1;let t=await y(e.connectionKey);if(t===`missing`)return await M.ackAssistantOpen({requestID:e.requestID}).catch(()=>void 0),!0;if(t!==`connected`)return!0;let n=i();if(!Ne(e.connectionKey,n))return!0;try{let[t,r]=await Promise.all([C(),S()]);if(!Ne(e.connectionKey,n))return!0;let i=r.assistants.some(t=>t.id===e.assistantID&&t.enabled);if(!t.supported||!t.enabled||t.serverInstanceID!==e.serverInstanceID||!i)return await M.ackAssistantOpen({requestID:e.requestID}),!0;P(e.assistantID),await M.ackAssistantOpen({requestID:e.requestID})}catch{}return!0},F=async()=>v.getPlatform()===`android`?N||(N=Pe().finally(()=>{N=null}),N):!1,I=e=>({displayName:e}),L=c();function Fe(e){let t=(0,pe.c)(30),{draft:n,entries:r,busy:i,onSelect:a,onCancel:o}=e,{t:s}=ee(),c;t[0]!==i||t[1]!==n||t[2]!==o?(c=()=>{n&&!i&&o(n)},t[0]=i,t[1]=n,t[2]=o,t[3]=c):c=t[3];let l=g(c),u;t[4]===l?u=t[5]:(u=e=>{e||l()},t[4]=l,t[5]=u);let d=g(u),f;t[6]!==n||t[7]!==a?(f=e=>{n&&a(n,e)},t[6]=n,t[7]=a,t[8]=f):f=t[8];let p=g(f),m=!!n,h;t[9]===s?h=t[10]:(h=s(`assistants.shareWelcome.example.note.title`),t[9]=s,t[10]=h);let _;t[11]===s?_=t[12]:(_=s(`settings.common.actions.cancel`),t[11]=s,t[12]=_);let v;t[13]!==i||t[14]!==l||t[15]!==h||t[16]!==_?(v=(0,L.jsx)(ae,{title:h,backAriaLabel:_,onBack:l,backDisabled:i,overlay:!0}),t[13]=i,t[14]=l,t[15]=h,t[16]=_,t[17]=v):v=t[17];let y;t[18]!==i||t[19]!==r||t[20]!==p||t[21]!==s?(y=r.length?(0,L.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-3 pb-[max(0.75rem,env(safe-area-inset-bottom))] pt-[calc(max(0.25rem,var(--yuri-safe-area-top,0px))+var(--yuri-mobile-detail-navigation-height,3.5rem)+0.75rem)]`,role:`listbox`,"aria-label":s(`assistants.listAria`),children:r.map(e=>{let t=I(e.name).displayName||e.name;return(0,L.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":`false`,disabled:i,className:`flex w-full items-center gap-3 border-b border-border/60 px-3 py-4 text-left text-foreground transition-colors last:border-b-0 hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-60`,onClick:()=>p(e),children:[(0,L.jsx)(le,{kind:`assistant`,name:e.avatarSeed,size:40,label:t,shape:`rounded`,className:`rounded-[0.5rem]`}),(0,L.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,L.jsx)(`span`,{className:`block truncate font-semibold`,children:t}),(0,L.jsx)(`span`,{className:`block truncate typography-small text-muted-foreground`,children:e.serverLabel})]}),(0,L.jsx)(ue,{name:`arrow-right-s`,className:`size-4 shrink-0 text-muted-foreground`})]},`${e.connectionKey}:${e.assistantID}`)})}):(0,L.jsx)(`p`,{className:`px-5 pb-[max(1.25rem,env(safe-area-inset-bottom))] pt-[calc(max(0.25rem,var(--yuri-safe-area-top,0px))+var(--yuri-mobile-detail-navigation-height,3.5rem)+0.75rem)] typography-ui text-muted-foreground`,children:s(`assistants.state.unavailable`)}),t[18]=i,t[19]=r,t[20]=p,t[21]=s,t[22]=y):y=t[22];let b;t[23]!==v||t[24]!==y?(b=(0,L.jsxs)(de,{className:`h-[100dvh] max-h-none w-screen max-w-none gap-0 overflow-hidden rounded-none border-0 bg-background p-0`,containerClassName:`items-stretch p-0`,overlayClassName:`bg-background`,showCloseButton:!1,children:[v,y]}),t[23]=v,t[24]=y,t[25]=b):b=t[25];let x;return t[26]!==d||t[27]!==m||t[28]!==b?(x=(0,L.jsx)(fe,{open:m,onOpenChange:d,children:b}),t[26]=d,t[27]=m,t[28]=b,t[29]=x):x=t[29],x}var Ie=e({MobileShareBridge:()=>at,donateNativeAssistantInteraction:()=>Xe,publishNativeAssistantCatalog:()=>Ye,refreshNativeAssistantCatalog:()=>X}),R=_(`YuriShare`),Le=`yuri.mobile-share.outbox.v1`,z=()=>v.isNativePlatform(),B=()=>{try{return JSON.parse(window.localStorage.getItem(Le)||`{}`)}catch{return{}}},Re=e=>{try{window.localStorage.setItem(Le,JSON.stringify(e))}catch{}},V=e=>{let t=B(),n=t[e.envelope.operationID];n&&n.updatedAt>e.updatedAt||(t[e.envelope.operationID]=e,Re(t))},H=(e,t)=>a()===e&&i()===t,U=new Map,W=null,G=null,K=!1,q=[],ze=0,J=new Set,Y=new Map,Be=1,Ve=e=>{e.map(e=>e.draftID).join(`
1
+ import{n as e,r as t}from"./rolldown-runtime-hePW80VL.js";import{c as n,i as r,n as i,r as a}from"./runtime-switch-DEPKHgdL.js";import{n as o}from"./runtime-fetch-V-iMWR8t.js";import{r as s}from"./platform-CiUKDeXd.js";import{ot as c,st as l}from"./vendor-base-ui-fom6orB6.js";import"./brand-storage-bootstrap-D4BW3w-M.js";import{R as u}from"./client-CzjApAA4.js";import{B as d,D as f,E as p}from"./prompt-attachment-upload-Bem87nmm.js";import{n as m}from"./vendor-react-D5BntRmA.js";import{a as h}from"./runtime-file-resource-CKQQEwNv.js";import{r as g}from"./vendor-reactuses-core-B8s-Rcd-.js";import{a as _,n as v}from"./vendor-aparajita-capacitor-secure-storage-xol_6BsB.js";import{t as ee}from"./i18n-BvjeIWrT.js";import{n as y,o as b,s as x}from"./mobileConnections-B9Arv_oQ.js";import{C as te,M as ne,c as S,o as re,p as ie,s as C,t as ae}from"./MobileDetailNavigation-D9_BtXYp.js";import{s as oe}from"./useMobileNavigationStore-DW2W2RJB.js";import{i as w,n as se}from"./useAssistantUIStore-CI42fWZh.js";import{n as T}from"./input-store-wWToFdzi.js";import{i as ce,t as le}from"./AgentAvatar-DXNlk9SC.js";import{n as ue}from"./Icon-W44vi3ut.js";import{n as de,t as fe}from"./dialog-CV8Bzfut.js";import{t as E}from"./rasterizePng-056Poix7.js";var D=t(l(),1),pe=m(),me=async(e,t=3)=>{let n;for(let r=0;r<t;r+=1)try{await e();return}catch(e){n=e}throw n},he=async(e,t,n=2)=>{let r=[...new Map(e.map(e=>[e.operationID,e])).values()],i=0;await Promise.all(Array.from({length:Math.min(Math.max(1,n),r.length)},async()=>{for(;i<r.length;){let e=r[i++];try{e.cleanupPhase&&e.cleanupPhase!==`files-released`?await t.cleanup(e.operationID):await t.deliver(e.operationID)}catch{}}}))},ge=e=>!!(e.serverInstanceID&&e.assistantID&&e.name&&e.avatarSeed&&e.serverLabel&&e.connectionKey),_e=`yuri.mobile-share.draft-handoff.v1`,ve=`mobile-share-handoff:`,ye=20971520,be=20971520,O=e=>`${ve}${e}`,k=e=>e??(typeof window>`u`?null:window.localStorage),A=e=>{if(!e)return{};try{let t=JSON.parse(e.getItem(`yuri.mobile-share.draft-handoff.v1`)||`{}`);return Object.fromEntries(Object.entries(t).flatMap(([e,t])=>{let n=typeof t.assistantID==`string`?t.assistantID:De(t),r=typeof t.transportIdentity==`string`?t.transportIdentity:t.targetDraftKey?.transportIdentity;if(!n||typeof t.serverInstanceID!=`string`||typeof t.connectionKey!=`string`||!r)return[];let i=t.phase===`cancelled`?`cancelled`:t.phase===`materialized`?`materialized`:`materializing`;return[[e,{...t,draftID:e,assistantID:n,transportIdentity:r,phase:i}]]}))}catch{return{}}},xe=(e,t)=>{if(!e)return!1;try{return e.setItem(_e,JSON.stringify(t)),!0}catch{return!1}},Se=(e,t)=>{let n=A(e);if(delete n[t],e)try{e.setItem(_e,JSON.stringify(n))}catch{return}},j=(e,t)=>xe(e,{...A(e),[t.draftID]:t}),Ce=(e,t)=>`native-share:${e}:${t}`,we=(e,t)=>t?e?`${e}\n\n${t}`:t:e,Te=e=>e.mime.startsWith(`image/`)&&e.byteSize>0&&e.byteSize<=ye,Ee=(e,t)=>!!t?.syntheticParts.some(t=>t.partID===O(e.draftID)&&t.text===``&&t.attachments.length===0&&t.synthetic===!0),De=e=>{let t=e.targetDraftKey?.owner;return t?.kind!==`surface`||typeof t.ownerID!=`string`||!t.ownerID.startsWith(`assistant:`)?null:t.ownerID.slice(10)||null},Oe=e=>({draftID:e.draftID,serverInstanceID:e.serverInstanceID,connectionKey:e.connectionKey,assistantID:e.assistantID,transportIdentity:e.transportIdentity}),ke=async(e,t)=>{let n=k(t),r=[];for(let t of Object.values(A(n))){if(t.phase===`cancelled`){r.push(Oe(t));continue}if(t.phase===`materialized`)try{await e(t.draftID);let i={...t,phase:`cancelled`};if(!j(n,i))continue;r.push(Oe(i))}catch{continue}}return r},Ae=(e,t)=>{let n=k(t),r=A(n)[e.draftID];return!r||r.phase!==`cancelled`||r.serverInstanceID!==e.serverInstanceID||r.connectionKey!==e.connectionKey||r.assistantID!==e.assistantID||r.transportIdentity!==e.transportIdentity?!1:(Se(n,e.draftID),!A(n)[e.draftID])},je=async(e,t)=>{let n=d({transportIdentity:e.transportIdentity},`assistant:${e.assistantID}`),r=t.captureDraftRuntime();if(r.transportIdentity!==e.transportIdentity)return!1;let i=t.getDraft(n),a=O(e.draftID);try{if(!i||!i.syntheticParts.some(e=>e.partID===a)){await t.flushDraftPersistence();let n=t.captureDraftRuntime();return n.transportIdentity===e.transportIdentity&&n.generation===r.generation}let o=await t.commitDraftSnapshot({key:n,expectedRevision:i.revision,runtime:r,values:new Map,snapshot:{text:i.text,attachments:i.attachments,syntheticParts:i.syntheticParts.filter(e=>e.partID!==a),mentions:i.mentions,...i.composerReferences===void 0?{}:{composerReferences:i.composerReferences}}});if(!o.current||!o.durable)return!1;await t.flushDraftPersistence();let s=t.captureDraftRuntime();return s.transportIdentity===e.transportIdentity&&s.generation===r.generation}catch{return!1}},Me=async(e,t)=>{if(e.attachments.length>10||!e.attachments.every(Te)||e.attachments.reduce((e,t)=>e+t.byteSize,0)>be)throw Error(`invalid_share_attachment`);let n=k(t.storage),r=d({transportIdentity:t.transportIdentity},`assistant:${e.assistantID}`),i=A(n)[e.draftID],a=!1;if(!i||p(i.targetDraftKey)!==p(r)){let a=t.input.getDraft(r);if(i={draftID:e.draftID,serverInstanceID:e.serverInstanceID,connectionKey:e.connectionKey,assistantID:e.assistantID,transportIdentity:t.transportIdentity,targetDraftKey:r,baseRevision:a?.revision??`absent`,resultText:we(a?.text??``,e.text),attachmentIDs:e.attachments.map((t,n)=>Ce(e.draftID,n)),phase:`materializing`},!j(n,i))throw Error(`handoff_journal_unavailable`)}if(i.phase===`cancelled`)return{durable:!0,cancelled:!0};(i.phase===`materialized`||Ee(i,t.input.getDraft(r)))&&(a=!0);for(let o=0;!a&&o<3;o++){let o=t.input.getDraft(r),s={...i,baseRevision:o?.revision??`absent`,resultText:we(o?.text??``,e.text),phase:`materializing`};if(!j(n,s))throw Error(`handoff_journal_unavailable`);i=s;let c=new Map,l=[];for(let n=0;n<e.attachments.length;n++){let r=e.attachments[n],a=i.attachmentIDs[n],o=f(a),s=await t.readAttachment(r);if(s.size!==r.byteSize)throw Error(`staged_file_unavailable`);c.set(o,s.type===r.mime?s:new Blob([s],{type:r.mime})),l.push({attachmentID:a,attachmentRefID:o,filename:r.originalName,mimeType:r.mime,size:r.byteSize,locator:{kind:`blob`,blobID:a},source:`local`})}let u={partID:O(e.draftID),text:``,attachments:[],synthetic:!0},d=o?.syntheticParts??[],p=await t.input.commitDraftSnapshot({key:r,expectedRevision:o?.revision??`absent`,runtime:t.input.captureDraftRuntime(),snapshot:{text:i.resultText,attachments:[...o?.attachments??[],...l],syntheticParts:d.some(e=>e.partID===u.partID)?d:[...d,u],mentions:o?.mentions??[],...o?.composerReferences===void 0?{}:{composerReferences:o.composerReferences}},values:c});if(p.durable&&p.current)a=!0;else if(p.status!==`conflict`)throw Error(`draft_handoff_${p.status}`)}if(!a)throw Error(`draft_handoff_conflict`);if(i.phase!==`materialized`&&(i={...i,phase:`materialized`},!j(n,i)))throw Error(`handoff_journal_unavailable`);try{await t.cancelDraft(e.draftID)}catch{return{durable:!0,cancelled:!1}}if(i={...i,phase:`cancelled`},!j(n,i))throw Error(`handoff_journal_unavailable`);return{durable:!0,cancelled:!0}},M=_(`YuriShare`),N=null,Ne=(e,t)=>a()===e&&i()===t,P=e=>{if(s()){se(e);return}let t=oe.getState();t.setActiveTab(`assistant`),t.openAssistant(e)},Pe=async()=>{let e=(await M.pendingAssistantOpen().catch(()=>null))?.request;if(!e)return!1;let t=await y(e.connectionKey);if(t===`missing`)return await M.ackAssistantOpen({requestID:e.requestID}).catch(()=>void 0),!0;if(t!==`connected`)return!0;let n=i();if(!Ne(e.connectionKey,n))return!0;try{let[t,r]=await Promise.all([C(),S()]);if(!Ne(e.connectionKey,n))return!0;let i=r.assistants.some(t=>t.id===e.assistantID&&t.enabled);if(!t.supported||!t.enabled||t.serverInstanceID!==e.serverInstanceID||!i)return await M.ackAssistantOpen({requestID:e.requestID}),!0;P(e.assistantID),await M.ackAssistantOpen({requestID:e.requestID})}catch{}return!0},F=async()=>v.getPlatform()===`android`?N||(N=Pe().finally(()=>{N=null}),N):!1,I=e=>({displayName:e}),L=c();function Fe(e){let t=(0,pe.c)(30),{draft:n,entries:r,busy:i,onSelect:a,onCancel:o}=e,{t:s}=ee(),c;t[0]!==i||t[1]!==n||t[2]!==o?(c=()=>{n&&!i&&o(n)},t[0]=i,t[1]=n,t[2]=o,t[3]=c):c=t[3];let l=g(c),u;t[4]===l?u=t[5]:(u=e=>{e||l()},t[4]=l,t[5]=u);let d=g(u),f;t[6]!==n||t[7]!==a?(f=e=>{n&&a(n,e)},t[6]=n,t[7]=a,t[8]=f):f=t[8];let p=g(f),m=!!n,h;t[9]===s?h=t[10]:(h=s(`assistants.shareWelcome.example.note.title`),t[9]=s,t[10]=h);let _;t[11]===s?_=t[12]:(_=s(`settings.common.actions.cancel`),t[11]=s,t[12]=_);let v;t[13]!==i||t[14]!==l||t[15]!==h||t[16]!==_?(v=(0,L.jsx)(ae,{title:h,backAriaLabel:_,onBack:l,backDisabled:i,overlay:!0}),t[13]=i,t[14]=l,t[15]=h,t[16]=_,t[17]=v):v=t[17];let y;t[18]!==i||t[19]!==r||t[20]!==p||t[21]!==s?(y=r.length?(0,L.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-3 pb-[max(0.75rem,env(safe-area-inset-bottom))] pt-[calc(max(0.25rem,var(--yuri-safe-area-top,0px))+var(--yuri-mobile-detail-navigation-height,3.5rem)+0.75rem)]`,role:`listbox`,"aria-label":s(`assistants.listAria`),children:r.map(e=>{let t=I(e.name).displayName||e.name;return(0,L.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":`false`,disabled:i,className:`flex w-full items-center gap-3 border-b border-border/60 px-3 py-4 text-left text-foreground transition-colors last:border-b-0 hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-60`,onClick:()=>p(e),children:[(0,L.jsx)(le,{kind:`assistant`,name:e.avatarSeed,size:40,label:t,shape:`rounded`,className:`rounded-[0.5rem]`}),(0,L.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,L.jsx)(`span`,{className:`block truncate font-semibold`,children:t}),(0,L.jsx)(`span`,{className:`block truncate typography-small text-muted-foreground`,children:e.serverLabel})]}),(0,L.jsx)(ue,{name:`arrow-right-s`,className:`size-4 shrink-0 text-muted-foreground`})]},`${e.connectionKey}:${e.assistantID}`)})}):(0,L.jsx)(`p`,{className:`px-5 pb-[max(1.25rem,env(safe-area-inset-bottom))] pt-[calc(max(0.25rem,var(--yuri-safe-area-top,0px))+var(--yuri-mobile-detail-navigation-height,3.5rem)+0.75rem)] typography-ui text-muted-foreground`,children:s(`assistants.state.unavailable`)}),t[18]=i,t[19]=r,t[20]=p,t[21]=s,t[22]=y):y=t[22];let b;t[23]!==v||t[24]!==y?(b=(0,L.jsxs)(de,{className:`h-[100dvh] max-h-none w-screen max-w-none gap-0 overflow-hidden rounded-none border-0 bg-background p-0`,containerClassName:`items-stretch p-0`,overlayClassName:`bg-background`,showCloseButton:!1,children:[v,y]}),t[23]=v,t[24]=y,t[25]=b):b=t[25];let x;return t[26]!==d||t[27]!==m||t[28]!==b?(x=(0,L.jsx)(fe,{open:m,onOpenChange:d,children:b}),t[26]=d,t[27]=m,t[28]=b,t[29]=x):x=t[29],x}var Ie=e({MobileShareBridge:()=>at,donateNativeAssistantInteraction:()=>Xe,publishNativeAssistantCatalog:()=>Ye,refreshNativeAssistantCatalog:()=>X}),R=_(`YuriShare`),Le=`yuri.mobile-share.outbox.v1`,z=()=>v.isNativePlatform(),B=()=>{try{return JSON.parse(window.localStorage.getItem(Le)||`{}`)}catch{return{}}},Re=e=>{try{window.localStorage.setItem(Le,JSON.stringify(e))}catch{}},V=e=>{let t=B(),n=t[e.envelope.operationID];n&&n.updatedAt>e.updatedAt||(t[e.envelope.operationID]=e,Re(t))},H=(e,t)=>a()===e&&i()===t,U=new Map,W=null,G=null,K=!1,q=[],ze=0,J=new Set,Y=new Map,Be=1,Ve=e=>{e.map(e=>e.draftID).join(`
2
2
  `)!==q.map(e=>e.draftID).join(`
3
3
  `)&&(q=e,ze+=1,J.forEach(e=>e()))},He=e=>Ve(q.filter(t=>t.draftID!==e)),Ue=e=>(J.add(e),()=>J.delete(e)),We=()=>ze,Ge=async e=>{if(!e.mime.startsWith(`image/`))throw Error(`unsupported_share_attachment`);let t=e.stagedPath.trim();if(!t)throw Error(`staged_file_unavailable`);let n=/^(?:data:|https?:|content:|file:)/i.test(t)?t:`file://${t}`,r=/^(?:data:|https?:)/i.test(n)?n:v.convertFileSrc(n);return h(()=>fetch(r).then(e=>{if(!e.ok)throw Error(`staged_file_unavailable`);return e.blob()}))},Ke=async e=>{let t=await Ge(e);return await new Promise((e,n)=>{let r=new FileReader;r.onerror=()=>n(Error(`staged_file_unavailable`)),r.onload=()=>typeof r.result==`string`?e(r.result):n(Error(`staged_file_unavailable`)),r.readAsDataURL(t)})},qe=async e=>{let t=[];if(e.text?.trim()&&t.push({type:`text`,text:e.text}),e.attachments.length>10)throw Error(`too_many_share_attachments`);for(let n of e.attachments){if(n.byteSize<=0||n.byteSize>20971520)throw Error(`invalid_share_attachment`);t.push({type:`file`,mime:n.mime,url:await Ke(n)})}if(t.length===0)throw Error(`empty_share`);return t},X=async()=>{if(!z())return;let e=a(),t=(await b()).find(t=>x(t)===e);if(!t)return;let n=i();try{let[r,i]=await Promise.all([C(),re()]);if(!H(e,n)||!r.supported||!r.serverInstanceID)return;let a=r.serverInstanceID,o=i.assistants.map(n=>({serverInstanceID:a,assistantID:n.id,name:n.name,avatarSeed:n.avatarSeed??n.id,serverLabel:t.label,connectionKey:e,enabled:r.enabled&&n.enabled,isDefaultShareTarget:!1}));w.getState().replaceCatalogPartition({serverInstanceID:a,connectionKey:e,revision:i.revision,lastLoadedAt:Date.now(),entries:o}),await Ye()}catch{}},Je=0,Ye=async()=>{if(!z())return;let e=++Je,t=[];for(let n of Object.values(w.getState().assistantCatalogByConnection).flatMap(e=>e.entries)){let r=I(n.name),i=await E(ce(`assistant`,n.avatarSeed),128);if(e!==Je)return;t.push({...n,name:r.displayName||n.name,...i?{avatarPng:i}:{}})}await R.updateCatalog({entries:t})},Xe=async e=>{if(v.getPlatform()!==`ios`)return;let t=await E(ce(`assistant`,e.avatarSeed),128);await R.donateAssistantInteraction({...e,...t?{avatarPng:t}:{}})},Ze=e=>{let t=U.get(e.operationID);if(t)return t;let n=Qe(e);return U.set(e.operationID,n),n.finally(()=>{U.get(e.operationID)===n&&U.delete(e.operationID)}).catch(()=>void 0),n},Z=async e=>{e.cleanupPhase!==`files-released`&&(e.cleanupPhase===`server-completed`&&(await me(()=>R.ack({operationID:e.envelope.operationID})),e={...e,state:`delivered`,cleanupPhase:`native-acked`,updatedAt:Date.now()},V(e)),e.cleanupPhase===`native-acked`&&(await me(()=>R.releaseFiles({operationID:e.envelope.operationID})),V({...e,state:`delivered`,cleanupPhase:`files-released`,updatedAt:Date.now()})))},Qe=async e=>{let t=B()[e.operationID];if(t?.cleanupPhase){await Z(t);return}let n=t?.messageID?t:{envelope:e,messageID:u(`msg`),state:t?.state??`pending`,cleanupPhase:t?.cleanupPhase,updatedAt:Date.now(),error:t?.error};V(n),n={...n,state:`resolving-instance`,updatedAt:Date.now()},V(n);let a=Object.values(w.getState().assistantCatalogByConnection).find(t=>t.serverInstanceID===e.serverInstanceID&&t.entries.some(t=>t.assistantID===e.assistantID));if(!a){V({...n,state:`target-stale`,updatedAt:Date.now()});return}n={...n,state:`connecting`,updatedAt:Date.now()},V(n);let s=await y(a.connectionKey);if(s===`auth-required`){V({...n,state:`auth-required`,updatedAt:Date.now()});return}if(s!==`connected`){V({...n,state:`offline`,updatedAt:Date.now()});return}let c=i(),l=null;if(H(a.connectionKey,c)){try{if(await o(`/api/config/settings`).catch(()=>void 0),!H(a.connectionKey,c))return;let[t,i]=await Promise.all([C(),re()]);if(!H(a.connectionKey,c)||!t.supported||t.serverInstanceID!==e.serverInstanceID){V({...n,state:`target-stale`,updatedAt:Date.now()});return}let s=i.assistants.find(t=>t.id===e.assistantID&&t.enabled);if(!t.enabled||!s){V({...n,state:`target-stale`,updatedAt:Date.now()});return}n={...n,state:`dispatching`,updatedAt:Date.now()},V(n);let u=await qe(e);if(!H(a.connectionKey,c))return;n={...n,state:`reconciling`,updatedAt:Date.now()},V(n);let d=await ie(s.id,e.operationID,n.messageID,u,e.source),f=await te(d,r(),c),p=await S().catch(e=>(V({...n,state:`reconciling`,updatedAt:Date.now(),error:e instanceof Error?e.message:`snapshot_refresh_failed`}),null));if(!p)return;if(!H(a.connectionKey,c)){V({...n,state:`reconciling`,updatedAt:Date.now(),error:`runtime_stale`});return}let m=p.assistants.find(e=>e.id===s.id);if(!m||m.sessionID!==f.sessionID){V({...n,state:`reconciling`,updatedAt:Date.now(),error:`assistant_binding_mismatch`});return}l=m.id}catch(e){if(e instanceof ne&&e.code===`share_unresolved`||e instanceof Error&&e.message===`runtime_stale`){V({...n,state:`reconciling`,updatedAt:Date.now(),error:e instanceof Error?e.message:`share_unresolved`});return}V({...n,state:`failed`,updatedAt:Date.now(),error:e instanceof Error?e.message:`dispatch_failed`});return}n={...n,state:`delivered`,cleanupPhase:`server-completed`,updatedAt:Date.now()},V(n),P(l),await Z(n)}},Q=async()=>W||(W=$e().finally(()=>{W=null}),W),$e=async()=>{if(!z())return;let e=await R.listPending().catch(()=>null),t=new Map((e?.envelopes??[]).map(e=>[e.operationID,e])),n=B();await he([...[...t.values()].map(e=>({operationID:e.operationID,cleanupPhase:n[e.operationID]?.cleanupPhase})),...Object.values(n).filter(e=>!t.has(e.envelope.operationID)&&(!!(e.cleanupPhase&&e.cleanupPhase!==`files-released`)||e.state!==`delivered`&&e.state!==`auth-required`&&e.state!==`target-stale`)).map(e=>({operationID:e.envelope.operationID,cleanupPhase:e.cleanupPhase}))],{deliver:async e=>{let r=t.get(e)??n[e]?.envelope;r&&await Ze(r)},cleanup:async e=>{let t=B()[e];t&&await Z(t)}},Be)},$=async()=>(K=!0,G||(G=(async()=>{do K=!1,await it();while(K)})().finally(()=>{G=null,K&&$()}),G)),et=async e=>{if(a()!==e.connectionKey&&await y(e.connectionKey)!==`connected`)return!1;let t=i();if(!H(e.connectionKey,t)||r()!==e.transportIdentity||(await o(`/api/config/settings`).catch(()=>void 0),!H(e.connectionKey,t)||r()!==e.transportIdentity)||!await T.getState().hydrateDraftMetadata(e.transportIdentity)||!H(e.connectionKey,t)||r()!==e.transportIdentity)return!1;let[n,s]=await Promise.all([C(),S()]);return!H(e.connectionKey,t)||r()!==e.transportIdentity||!n.supported||!n.enabled||n.serverInstanceID!==e.serverInstanceID||!s.assistants.some(t=>t.id===e.assistantID&&t.enabled)?!1:(P(e.assistantID),!0)},tt=async e=>{let t=a(),n=i();if(await o(`/api/config/settings`).catch(()=>void 0),!H(t,n))return null;try{let[i,a]=await Promise.all([C(),S()]);return!H(t,n)||!i.supported||!i.enabled||i.serverInstanceID!==e.serverInstanceID||!a.assistants.some(t=>t.id===e.assistantID&&t.enabled)?null:{runtimeKey:t,generation:n,transportIdentity:r()}}catch{return null}},nt=async e=>{let t=Object.values(w.getState().assistantCatalogByConnection).find(t=>t.serverInstanceID===e.serverInstanceID&&t.connectionKey===e.connectionKey&&t.entries.some(t=>t.assistantID===e.assistantID));if(!t)return!1;let n=await tt(e);if(!n&&(await y(t.connectionKey,{transportPreference:`relay`})!==`connected`||(n=await tt(e),!n)))return!1;let{runtimeKey:i,generation:a,transportIdentity:o}=n;if(!await T.getState().hydrateDraftMetadata(o)||!H(i,a)||r()!==o)return!1;let s=await Me(e,{input:T.getState(),transportIdentity:o,cancelDraft:e=>R.cancelDraft({draftID:e}),readAttachment:Ge});if(!s.durable||!s.cancelled||!H(i,a)||r()!==o)return!1;let c={draftID:e.draftID,serverInstanceID:e.serverInstanceID,connectionKey:e.connectionKey,assistantID:e.assistantID,transportIdentity:o};return P(e.assistantID),await je(c,T.getState())&&Ae(c),!0},rt=e=>{let t=Y.get(e.draftID);if(t)return t;let n=nt(e).catch(()=>!1).finally(()=>{Y.get(e.draftID)===n&&Y.delete(e.draftID)});return Y.set(e.draftID,n),n},it=async()=>{if(v.getPlatform()!==`android`)return;let e=await ke(e=>R.cancelDraft({draftID:e}));for(let t of e)try{await et(t)&&await je(t,T.getState())&&Ae(t)}catch{}let t=await R.listDrafts().catch(()=>null);if(!t)return;let n=[...t?.drafts??[]].sort((e,t)=>e.createdAt-t.createdAt);Ve(n.filter(e=>!ge(e)));for(let e of n)ge(e)&&await rt(e)},at=()=>{let e=(0,pe.c)(11);D.useSyncExternalStore(Ue,We,We);let t=w(ot),[n,r]=D.useState(null),i=D.useRef(null),a;e[0]===t?a=e[1]:(a=Object.values(t).flatMap(st).filter(ct).sort(lt),e[0]=t,e[1]=a);let o=a,s=q[0]??null,c;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(c=(e,t)=>{i.current||(i.current=e.draftID,r(e.draftID),rt({...e,serverInstanceID:t.serverInstanceID,assistantID:t.assistantID,name:t.name,avatarSeed:t.avatarSeed,serverLabel:t.serverLabel,connectionKey:t.connectionKey}).then(t=>{t&&He(e.draftID)}).finally(()=>{i.current===e.draftID&&(i.current=null),r(t=>t===e.draftID?null:t)}))},e[2]=c):c=e[2];let l=g(c),u;e[3]===n?u=e[4]:(u=e=>{n!==e.draftID&&(He(e.draftID),R.cancelDraft({draftID:e.draftID}).catch(ut))},e[3]=n,e[4]=u);let d=g(u),f;e[5]===Symbol.for(`react.memo_cache_sentinel`)?(f=[],e[5]=f):f=e[5],D.useEffect(yt,f);let p=n===s?.draftID,m;return e[6]!==d||e[7]!==o||e[8]!==l||e[9]!==p?(m=(0,L.jsx)(Fe,{draft:s,entries:o,busy:p,onSelect:l,onCancel:d}),e[6]=d,e[7]=o,e[8]=l,e[9]=p,e[10]=m):m=e[10],m};function ot(e){return e.assistantCatalogByConnection}function st(e){return e.entries}function ct(e){return e.enabled}function lt(e,t){return Number(t.isDefaultShareTarget)-Number(e.isDefaultShareTarget)||e.serverLabel.localeCompare(t.serverLabel)||e.name.localeCompare(t.name)}function ut(){$()}function dt(){X(),$(),F()}function ft(){X(),Q(),$(),F()}function pt(){Q()}function mt(){}function ht(){$()}function gt(){}function _t(){F()}function vt(){}function yt(){if(!z())return;X(),Q(),$(),F();let e=n(dt),t=ft;window.addEventListener(`yuri:system-resume`,t);let r=!1,i=null,a=null,o=null;return R.addListener(`shareReceived`,pt).then(e=>{r?e.remove():i=e}).catch(mt),R.addListener(`shareDraftReceived`,ht).then(e=>{r?e.remove():a=e}).catch(gt),R.addListener(`assistantOpenRequested`,_t).then(e=>{r?e.remove():o=e}).catch(vt),()=>{r=!0,e(),window.removeEventListener(`yuri:system-resume`,t),i&&i.remove(),a&&a.remove(),o&&o.remove()}}export{I as a,X as i,Ie as n,F as o,Xe as r,at as t};