@yuriai/web 0.2.31-beta.4 → 0.2.31

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 (85) hide show
  1. package/dist/assets/{AgentAvatar-C3ydMP90.js → AgentAvatar-DLAQkFQe.js} +1 -1
  2. package/dist/assets/{AssistantContactStatus-CsDyIckA.js → AssistantContactStatus-DZGGspw4.js} +3 -3
  3. package/dist/assets/{AssistantUnreadBadge-BMqANfEi.js → AssistantUnreadBadge-BynxNQMk.js} +1 -1
  4. package/dist/assets/{AssistantView-Bgz6Qg_n.js → AssistantView-CDZyA9ft.js} +1 -1
  5. package/dist/assets/{DiagramView-BYrjA5kG.js → DiagramView-DdVFGHQQ.js} +1 -1
  6. package/dist/assets/{FadeInOnReveal-GH4O857L.js → FadeInOnReveal-C9a7XnAh.js} +1 -1
  7. package/dist/assets/{GuiPluginSurface-BPAdeYGQ.js → GuiPluginSurface-v8r-Hex5.js} +1 -1
  8. package/dist/assets/{GuiPluginWindow-D3JsxPrT.js → GuiPluginWindow-Ba1HfrjQ.js} +1 -1
  9. package/dist/assets/{Icon-0kSL3zYJ.js → Icon-Bh3TaKoN.js} +1 -1
  10. package/dist/assets/{ImageLoadingPlaceholder-Cwd4MCPX.js → ImageLoadingPlaceholder-Dcy5lc7F.js} +1 -1
  11. package/dist/assets/{LoadingImage-qXDbd77i.js → LoadingImage-BxjJ_Xyj.js} +1 -1
  12. package/dist/assets/MarkdownRenderer-CS6Pia5D.js +2 -0
  13. package/dist/assets/{MarkdownRendererImpl-BEO0mmTl.js → MarkdownRendererImpl-Bdwe3qUr.js} +1 -1
  14. package/dist/assets/{MarkstreamRendererImpl-BTwy_9_a.js → MarkstreamRendererImpl-CCQj9IkL.js} +1 -1
  15. package/dist/assets/{MobileDetailNavigation-Cw7Xc_3T.js → MobileDetailNavigation-o54juFXD.js} +1 -1
  16. package/dist/assets/{MobileResizableSheet-Du6rTvgU.js → MobileResizableSheet-sV9XR-0k.js} +1 -1
  17. package/dist/assets/{MobileShareBridge-Lr8uenO_.js → MobileShareBridge-oqBZ_f6M.js} +2 -2
  18. package/dist/assets/{MobileTabPageHeader-CtPwljra.js → MobileTabPageHeader-CptcDWNS.js} +1 -1
  19. package/dist/assets/{MultiRunWindow-CWM76eV8.js → MultiRunWindow-7W_86vL6.js} +1 -1
  20. package/dist/assets/{OnboardingScreen-CTkprkiv.js → OnboardingScreen-CnkijSLE.js} +1 -1
  21. package/dist/assets/{OverlayScrollbar-B7sVHXnC.js → OverlayScrollbar-CCtBTJQj.js} +1 -1
  22. package/dist/assets/{SettingsView-yHOoYleA.js → SettingsView-CkJpYIMe.js} +1 -1
  23. package/dist/assets/{SettingsWindow-ByEjL6Nw.js → SettingsWindow-C0HiNvXh.js} +1 -1
  24. package/dist/assets/{SetupTourDialog-CUvxcejj.js → SetupTourDialog-BcEbaEO3.js} +1 -1
  25. package/dist/assets/{TerminalView-D1GkcJE3.js → TerminalView-y36H_fIe.js} +1 -1
  26. package/dist/assets/{ToolOutputDialog-CcPSvHT6.js → ToolOutputDialog-BfjBeqGS.js} +1 -1
  27. package/dist/assets/{VoiceSettings--5_ayrgo.js → VoiceSettings-BONwzGgR.js} +1 -1
  28. package/dist/assets/{YuriLogo-CBA_JITn.js → YuriLogo-BA5FWp-g.js} +1 -1
  29. package/dist/assets/{YuriWordmark-Bkpex8se.js → YuriWordmark-Cr1vkcue.js} +1 -1
  30. package/dist/assets/{appThemeRegistry-9XjDBpox.js → appThemeRegistry-BsLMp3bc.js} +1 -1
  31. package/dist/assets/{bootstrap-DGkBnhNP.js → bootstrap-C8paoQ0j.js} +1 -1
  32. package/dist/assets/{button-1hulrRFb.js → button-CBjOhOI0.js} +1 -1
  33. package/dist/assets/{capgoAdapter-BXVNgGXT.js → capgoAdapter-DjlyVxy_.js} +1 -1
  34. package/dist/assets/{collapsible-1ZF6oX1u.js → collapsible-B0j5IQ0T.js} +1 -1
  35. package/dist/assets/{context-menu-22yntREv.js → context-menu-C4e_bpls.js} +1 -1
  36. package/dist/assets/{diagram-DOJPiCy7.js → diagram-WPmk0Qh6.js} +1 -1
  37. package/dist/assets/{dialog-CQVu4teR.js → dialog-Dx3IT7dQ.js} +1 -1
  38. package/dist/assets/{fileMentionTouchSelection-DC_Tjhr4.js → fileMentionTouchSelection-Bizsisaj.js} +1 -1
  39. package/dist/assets/{fileReferenceActions-BhbJNduq.js → fileReferenceActions-COS3jfbf.js} +1 -1
  40. package/dist/assets/{gitApi-CzQwUwvd.js → gitApi-CNgEj6X5.js} +1 -1
  41. package/dist/assets/{gitApiHttp-CIkpp8g-.js → gitApiHttp-MWsHNHuo.js} +1 -1
  42. package/dist/assets/{input-DRV16AFd.js → input-CEJGM-TS.js} +1 -1
  43. package/dist/assets/{insertionBoundaries-C7FBNvk1.js → insertionBoundaries-CgYf6gys.js} +1 -1
  44. package/dist/assets/{main-Cef8gzbX.js → main-B8FcBwPM.js} +4 -4
  45. package/dist/assets/{main-CR1Jc44L.js → main-DrqtyqDc.js} +2 -2
  46. package/dist/assets/{markdownHeightCache-DiVswDYm.js → markdownHeightCache-D6iSNJG2.js} +1 -1
  47. package/dist/assets/{mcpQueries-DukxUVzd.js → mcpQueries-DVSsZeuk.js} +1 -1
  48. package/dist/assets/{miniChat-C93_bSRK.js → miniChat-CgeCl4RY.js} +2 -2
  49. package/dist/assets/{mobile-DF9tY4EV.js → mobile-DAhJKHUq.js} +2 -2
  50. package/dist/assets/{mobileBackNavigation-BgHWEzyW.js → mobileBackNavigation-Dmbf0kw1.js} +1 -1
  51. package/dist/assets/{multirun-hYvBoS0d.js → multirun-BbWnHeaY.js} +1 -1
  52. package/dist/assets/{native-config-CbYntrYO.js → native-config-BaRHaY4y.js} +1 -1
  53. package/dist/assets/{projectMeta-C8UBKLh9.js → projectMeta-rrpZdm8D.js} +1 -1
  54. package/dist/assets/{pwa-Dt9uU0i9.js → pwa-Dm_DJEr9.js} +1 -1
  55. package/dist/assets/{queue-abort-optimistic-D_SsLJLd.js → queue-abort-optimistic-CSkERbr4.js} +1 -1
  56. package/dist/assets/{readiness-n9XOjS8O.js → readiness-BnO7IaZV.js} +1 -1
  57. package/dist/assets/{renderElectronMiniChatApp-CVtfpdY-.js → renderElectronMiniChatApp-Bq3iNKtr.js} +2 -2
  58. package/dist/assets/{renderMobileApp-BPgoSEJm.js → renderMobileApp-DiNeMgwp.js} +4 -4
  59. package/dist/assets/{runtimeConfig-Cx9RXogi.js → runtimeConfig-BHOiBANF.js} +1 -1
  60. package/dist/assets/{runtimeEndpointReset-T6F3Ii6E.js → runtimeEndpointReset-DGxT24oE.js} +3 -3
  61. package/dist/assets/{scheduledTaskNavigation-Bp5rGr3m.js → scheduledTaskNavigation-Cq5yavoC.js} +1 -1
  62. package/dist/assets/{select-zok-B3g0.js → select-bKMw5JE8.js} +1 -1
  63. package/dist/assets/{sessionLookup-BsUFQTxv.js → sessionLookup-DGNxfDsP.js} +1 -1
  64. package/dist/assets/{sortable-tabs-strip-4bXSWYDe.js → sortable-tabs-strip-3sKiA7T1.js} +1 -1
  65. package/dist/assets/{speechSettingsQueries-C6dYJclL.js → speechSettingsQueries-BDDxw8LP.js} +1 -1
  66. package/dist/assets/{terminalApi-bbnqBofP.js → terminalApi-BMWW_0wH.js} +1 -1
  67. package/dist/assets/{textarea-5Kh0UllD.js → textarea-EsaDD051.js} +1 -1
  68. package/dist/assets/{tooltip-BOFwKQWM.js → tooltip-LLDL5nIZ.js} +1 -1
  69. package/dist/assets/types-Cl7nTpsb.js +2 -0
  70. package/dist/assets/{useAppFontEffects-CoFlWq69.js → useAppFontEffects-wIWWE59b.js} +5 -5
  71. package/dist/assets/{useAssistantUIStore-BI_dAUjx.js → useAssistantUIStore-D25VqrpK.js} +1 -1
  72. package/dist/assets/{useDesktopWindowControlsLayout-fOeDBr7J.js → useDesktopWindowControlsLayout-CdUr9mCZ.js} +1 -1
  73. package/dist/assets/{useDictation-cnIIE7Zs.js → useDictation-DlEHSN6P.js} +1 -1
  74. package/dist/assets/{useEffectiveDirectory-385Vh00v.js → useEffectiveDirectory-DzqpWUC3.js} +1 -1
  75. package/dist/assets/{useFontPreferences-BfzbDU0G.js → useFontPreferences-CEK8G_Ps.js} +1 -1
  76. package/dist/assets/{useMobileNavigationStore-D-EPMP4q.js → useMobileNavigationStore-BWLhXqci.js} +5 -5
  77. package/dist/assets/{usePluginsStore-Bh4mG19B.js → usePluginsStore-aZl0WTK8.js} +1 -1
  78. package/dist/assets/{useUIStore-CoWJ3ROq.js → useUIStore-BerIUSLP.js} +1 -1
  79. package/dist/assets/{useWorkerHighlightedLines-uRFLMeII.js → useWorkerHighlightedLines-DMS69wKa.js} +1 -1
  80. package/dist/index.html +9 -9
  81. package/dist/mini-chat.html +9 -9
  82. package/dist/mobile.html +9 -9
  83. package/package.json +1 -1
  84. package/dist/assets/MarkdownRenderer-DIQeWdJJ.js +0 -2
  85. package/dist/assets/types-CDpG4h8_.js +0 -2
@@ -1 +1 @@
1
- import{n as e}from"./rolldown-runtime-hePW80VL.js";import{i as t}from"./runtime-switch-DEZ1K7qW.js";import{n}from"./runtime-fetch-D0YWp3FJ.js";import{S as r,T as i,b as a,x as o}from"./desktop-BAmoc_34.js";import{r as s}from"./useUIStore-CoWJ3ROq.js";import{i as c,o as l,t as u}from"./path-utils-jGozTg9d.js";import{c as d,i as f,s as p}from"./toolHelpers-iEHVHQ9p.js";import{a as m,i as h,n as g,o as _,r as ee,t as v}from"./fileReferenceParser-1HHDBUum.js";var y=`data-yuri-block-path-token`,b=`[${y}]`,x=`data-yuri-file-link`,S=`[${x}="true"]`,C=[x,`data-yuri-file-ref`,`data-yuri-file-path`,`data-yuri-file-binary`,`title`,`role`,`tabindex`],w=`data-yuri-block-paths-scanned`,T=`data-yuri-paragraph-paths-scanned`,E=`pre, code, a, script, style, button, [${x}], ${b}`,D=2e5,O=e=>{let t=_(e);return t?h(t.path):!1},te=e=>{let t=e.trim();return!t||t.startsWith(`#`)||t.startsWith(`?`)||t.startsWith(`//`)?!1:/^[A-Za-z]:[\\/]/.test(t)||/^file:/i.test(t)||O(t)&&/:\d+(?:-\d+|:\d+)?$/.test(t)?!0:!/^[A-Za-z][A-Za-z0-9+.-]*:/.test(t)},k=(e,t)=>{let n=0;for(let r of e){let e=n+r.data.length;if(t<=e)return{node:r,offset:Math.max(0,t-n)};n=e}let r=e.at(-1);return r?{node:r,offset:r.data.length}:null},A=e=>{let t=e.querySelectorAll(`pre code`);if(t.length===0)return;let n=e.ownerDocument;if(n)for(let e of Array.from(t)){if(e.getAttribute(w)===`true`)continue;if((e.textContent??``).length>D){e.setAttribute(w,`true`);continue}let t=n.createTreeWalker(e,NodeFilter.SHOW_TEXT),r=[],i=t.nextNode();for(;i;)r.push(i),i=t.nextNode();let a=e.textContent??``;if(!a.includes(`.`)){e.setAttribute(w,`true`);continue}v.lastIndex=0;let o=[],s=v.exec(a);for(;s;){let e=s[0];e&&O(e)&&o.push({start:s.index,end:s.index+e.length,raw:e}),s=v.exec(a)}for(let{start:e,end:t,raw:i}of o.reverse()){let a=k(r,e),o=k(r,t);if(!a||!o)continue;let s=n.createRange();s.setStart(a.node,a.offset),s.setEnd(o.node,o.offset);let c=n.createElement(`span`);c.setAttribute(y,`true`),c.textContent=i,s.deleteContents(),s.insertNode(c)}e.setAttribute(w,`true`)}},j=e=>{let t=e.ownerDocument;if(!t)return;let n=e.querySelectorAll(`p, li, blockquote, h1, h2, h3, h4, h5, h6, td, th`);if(n.length!==0)for(let e of Array.from(n)){if(e.getAttribute(T)===`true`)continue;if(e.closest(E)){e.setAttribute(T,`true`);continue}let n=t.createTreeWalker(e,NodeFilter.SHOW_TEXT,{acceptNode:e=>{let t=e.parentElement;return!t||t.closest(E)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),r=[],i=n.nextNode();for(;i;)r.push(i),i=n.nextNode();if(r.length===0){e.setAttribute(T,`true`);continue}let a=r.map(e=>e.data).join(``);if(!a.includes(`/`)||!a.includes(`.`)){e.setAttribute(T,`true`);continue}g.lastIndex=0;let o=[],s=g.exec(a);for(;s;){let e=s[0];if(!e){s=g.exec(a);continue}let t=s.index>=2?a.slice(s.index-2,s.index):``;if((s.index>=1?a.charAt(s.index-1):``)===`:`||t===`:/`){s=g.exec(a);continue}O(e)&&o.push({start:s.index,end:s.index+e.length,raw:e}),s=g.exec(a)}for(let{start:e,end:n,raw:i}of o.reverse()){let a=k(r,e),o=k(r,n);if(!a||!o)continue;let s=t.createRange();s.setStart(a.node,a.offset),s.setEnd(o.node,o.offset);let c=t.createElement(`span`);c.setAttribute(y,`true`),c.textContent=i,s.deleteContents(),s.insertNode(c)}e.setAttribute(T,`true`)}},M=e=>{A(e),j(e)},N=(e,t)=>{if(e.getAttribute(`data-yuri-file-link`)!==`true`)return;let n=(e.getAttribute(`data-yuri-file-ref`)||e.textContent||``).trim(),r=(t.textContent||``).trim();if(!(!n||n!==r))for(let n of C){let r=e.getAttribute(n);r===null?t.removeAttribute(n):t.setAttribute(n,r)}},P=e({FILE_REFERENCE_OPEN_TITLE:()=>F,extractPathCandidateFromElement:()=>q,getFileReferenceInfo:()=>Y,getFileReferenceLinkLimit:()=>H,getResolvedReference:()=>J,openFileReference:()=>Q,openFileReferenceFromElement:()=>$,peekFileReferenceInfo:()=>K,probeFileReference:()=>X,resetFileReferenceStatCacheForTests:()=>ce,shouldOfferFileReference:()=>Z}),F=`Open file`,ne=4,re=1e3,ie=200,ae=80,oe=40,I=new Map,L=new Map,R=(e,n)=>JSON.stringify([t(),n,e]),z=0,B=[],V=()=>i()?ie:re,H=()=>i()?oe:ae,U=(e,t)=>{L.set(e,t)},W=()=>{let e=I.keys().next().value;typeof e==`string`&&(I.delete(e),L.delete(e))},G=(e,t)=>{let n=V();for(;I.size>=n;)W();I.set(e,t)},K=(e,t=``)=>{let n=m(e);if(n)return L.get(R(n,t))},q=e=>{if(e.tagName.toLowerCase()===`a`){let t=e.getAttribute(`href`)?.trim();if(t&&O(t))return t}return(e.textContent||``).trim()},J=(e,t,n=`path`)=>{let r=_(e);if(r&&n===`href`&&!/^file:/i.test(e.trim()))try{r.path=decodeURIComponent(r.path)}catch{}if(!r||!h(r.path))return null;let i=ee(r.path)?m(r.path):l(t,r.path);return i?{...r,resolvedPath:i}:null},Y=(e,t=``)=>{let r=m(e);if(!r)return Promise.resolve({exists:!1,isBinary:!1});let i=R(r,t),a=I.get(i);if(a)return I.delete(i),I.set(i,a),a;let o=new Promise((e,a)=>{let s=()=>{z+=1,n(`/api/fs/stat?path=${encodeURIComponent(r)}&optional=true`,{method:`GET`,cache:`no-store`,...t?{query:{directory:t}}:{}}).then(async t=>{if(!t.ok)throw Error(`File reference probe failed (${t.status})`);let n=await t.json();if(!n||typeof n.exists!=`boolean`&&n.isFile!==!0)throw Error(`Invalid file reference probe response`);let r={exists:n.exists!==!1,isBinary:n.isBinary===!0};U(i,r),e(r)}).catch(e=>{I.get(i)===o&&(I.delete(i),L.delete(i)),a(e)}).finally(()=>{z=Math.max(0,z-1),B.shift()?.()})};if(z<ne){s();return}B.push(s)});return G(i,o),o},X=(e,t)=>{if(!(r()&&o()&&!c(e,t)))return Y(e,t);let n=m(e);if(!n)return Promise.resolve({exists:!1,isBinary:!1});let i=R(n,t),s=I.get(i);if(s)return I.delete(i),I.set(i,s),s;let l=a(e).then(e=>{let t={exists:!0,isBinary:e===!0};return U(i,t),t});return G(i,l),l},Z=(e,t,n)=>!(!t.exists||n&&t.isBinary&&!d(e)&&!p(e)),se=(e,t)=>e||u(e,t),Q=async(e,t,n)=>{let r=J(e,n.effectiveDirectory,n.referenceKind);if(!r)return;if(d(r.resolvedPath)&&n.onShowPopup){let e=r.resolvedPath.split(`/`).filter(Boolean).pop()??r.resolvedPath;n.onShowPopup({open:!0,title:e,content:``,metadata:{tool:`image-preview`,filename:e,mime:f(r.resolvedPath)},image:{url:r.resolvedPath,filename:e,mimeType:f(r.resolvedPath)}});return}let i=se(n.effectiveDirectory,r.resolvedPath),a=p(r.resolvedPath);if(n.preferRuntimeEditor&&n.editor&&!a){n.editor.openFile(r.resolvedPath,Number.isFinite(r.line??NaN)?Math.max(1,Math.trunc(r.line)):void 0,Number.isFinite(r.column??NaN)?Math.max(1,Math.trunc(r.column)):void 0);return}let o=s.getState();if(a){o.openContextFile(i,r.resolvedPath,{viewerMode:`preview`});return}if(Number.isFinite(r.line??NaN)){o.openContextFileAtLine(i,r.resolvedPath,Math.max(1,Math.trunc(r.line)),Number.isFinite(r.column??NaN)?Math.max(1,Math.trunc(r.column)):1);return}o.openContextFile(i,r.resolvedPath)},$=async(e,t)=>{let n=e.matches(`a[href]`)?e:e.querySelector(`a[href]`);await Q(n?.getAttribute(`href`)||e.getAttribute(`data-yuri-file-ref`)||q(e),e.getAttribute(`data-yuri-file-binary`)===`true`,{...t,referenceKind:n?`href`:`path`})},ce=()=>{I.clear(),L.clear(),z=0,B.length=0};export{J as a,X as c,x as d,S as f,M as g,te as h,H as i,Z as l,O as m,q as n,$ as o,N as p,P as r,K as s,F as t,b as u};
1
+ import{n as e}from"./rolldown-runtime-hePW80VL.js";import{i as t}from"./runtime-switch-DEZ1K7qW.js";import{n}from"./runtime-fetch-D0YWp3FJ.js";import{S as r,T as i,b as a,x as o}from"./desktop-BAmoc_34.js";import{r as s}from"./useUIStore-BerIUSLP.js";import{i as c,o as l,t as u}from"./path-utils-jGozTg9d.js";import{c as d,i as f,s as p}from"./toolHelpers-iEHVHQ9p.js";import{a as m,i as h,n as g,o as _,r as ee,t as v}from"./fileReferenceParser-1HHDBUum.js";var y=`data-yuri-block-path-token`,b=`[${y}]`,x=`data-yuri-file-link`,S=`[${x}="true"]`,C=[x,`data-yuri-file-ref`,`data-yuri-file-path`,`data-yuri-file-binary`,`title`,`role`,`tabindex`],w=`data-yuri-block-paths-scanned`,T=`data-yuri-paragraph-paths-scanned`,E=`pre, code, a, script, style, button, [${x}], ${b}`,D=2e5,O=e=>{let t=_(e);return t?h(t.path):!1},te=e=>{let t=e.trim();return!t||t.startsWith(`#`)||t.startsWith(`?`)||t.startsWith(`//`)?!1:/^[A-Za-z]:[\\/]/.test(t)||/^file:/i.test(t)||O(t)&&/:\d+(?:-\d+|:\d+)?$/.test(t)?!0:!/^[A-Za-z][A-Za-z0-9+.-]*:/.test(t)},k=(e,t)=>{let n=0;for(let r of e){let e=n+r.data.length;if(t<=e)return{node:r,offset:Math.max(0,t-n)};n=e}let r=e.at(-1);return r?{node:r,offset:r.data.length}:null},A=e=>{let t=e.querySelectorAll(`pre code`);if(t.length===0)return;let n=e.ownerDocument;if(n)for(let e of Array.from(t)){if(e.getAttribute(w)===`true`)continue;if((e.textContent??``).length>D){e.setAttribute(w,`true`);continue}let t=n.createTreeWalker(e,NodeFilter.SHOW_TEXT),r=[],i=t.nextNode();for(;i;)r.push(i),i=t.nextNode();let a=e.textContent??``;if(!a.includes(`.`)){e.setAttribute(w,`true`);continue}v.lastIndex=0;let o=[],s=v.exec(a);for(;s;){let e=s[0];e&&O(e)&&o.push({start:s.index,end:s.index+e.length,raw:e}),s=v.exec(a)}for(let{start:e,end:t,raw:i}of o.reverse()){let a=k(r,e),o=k(r,t);if(!a||!o)continue;let s=n.createRange();s.setStart(a.node,a.offset),s.setEnd(o.node,o.offset);let c=n.createElement(`span`);c.setAttribute(y,`true`),c.textContent=i,s.deleteContents(),s.insertNode(c)}e.setAttribute(w,`true`)}},j=e=>{let t=e.ownerDocument;if(!t)return;let n=e.querySelectorAll(`p, li, blockquote, h1, h2, h3, h4, h5, h6, td, th`);if(n.length!==0)for(let e of Array.from(n)){if(e.getAttribute(T)===`true`)continue;if(e.closest(E)){e.setAttribute(T,`true`);continue}let n=t.createTreeWalker(e,NodeFilter.SHOW_TEXT,{acceptNode:e=>{let t=e.parentElement;return!t||t.closest(E)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),r=[],i=n.nextNode();for(;i;)r.push(i),i=n.nextNode();if(r.length===0){e.setAttribute(T,`true`);continue}let a=r.map(e=>e.data).join(``);if(!a.includes(`/`)||!a.includes(`.`)){e.setAttribute(T,`true`);continue}g.lastIndex=0;let o=[],s=g.exec(a);for(;s;){let e=s[0];if(!e){s=g.exec(a);continue}let t=s.index>=2?a.slice(s.index-2,s.index):``;if((s.index>=1?a.charAt(s.index-1):``)===`:`||t===`:/`){s=g.exec(a);continue}O(e)&&o.push({start:s.index,end:s.index+e.length,raw:e}),s=g.exec(a)}for(let{start:e,end:n,raw:i}of o.reverse()){let a=k(r,e),o=k(r,n);if(!a||!o)continue;let s=t.createRange();s.setStart(a.node,a.offset),s.setEnd(o.node,o.offset);let c=t.createElement(`span`);c.setAttribute(y,`true`),c.textContent=i,s.deleteContents(),s.insertNode(c)}e.setAttribute(T,`true`)}},M=e=>{A(e),j(e)},N=(e,t)=>{if(e.getAttribute(`data-yuri-file-link`)!==`true`)return;let n=(e.getAttribute(`data-yuri-file-ref`)||e.textContent||``).trim(),r=(t.textContent||``).trim();if(!(!n||n!==r))for(let n of C){let r=e.getAttribute(n);r===null?t.removeAttribute(n):t.setAttribute(n,r)}},P=e({FILE_REFERENCE_OPEN_TITLE:()=>F,extractPathCandidateFromElement:()=>q,getFileReferenceInfo:()=>Y,getFileReferenceLinkLimit:()=>H,getResolvedReference:()=>J,openFileReference:()=>Q,openFileReferenceFromElement:()=>$,peekFileReferenceInfo:()=>K,probeFileReference:()=>X,resetFileReferenceStatCacheForTests:()=>ce,shouldOfferFileReference:()=>Z}),F=`Open file`,ne=4,re=1e3,ie=200,ae=80,oe=40,I=new Map,L=new Map,R=(e,n)=>JSON.stringify([t(),n,e]),z=0,B=[],V=()=>i()?ie:re,H=()=>i()?oe:ae,U=(e,t)=>{L.set(e,t)},W=()=>{let e=I.keys().next().value;typeof e==`string`&&(I.delete(e),L.delete(e))},G=(e,t)=>{let n=V();for(;I.size>=n;)W();I.set(e,t)},K=(e,t=``)=>{let n=m(e);if(n)return L.get(R(n,t))},q=e=>{if(e.tagName.toLowerCase()===`a`){let t=e.getAttribute(`href`)?.trim();if(t&&O(t))return t}return(e.textContent||``).trim()},J=(e,t,n=`path`)=>{let r=_(e);if(r&&n===`href`&&!/^file:/i.test(e.trim()))try{r.path=decodeURIComponent(r.path)}catch{}if(!r||!h(r.path))return null;let i=ee(r.path)?m(r.path):l(t,r.path);return i?{...r,resolvedPath:i}:null},Y=(e,t=``)=>{let r=m(e);if(!r)return Promise.resolve({exists:!1,isBinary:!1});let i=R(r,t),a=I.get(i);if(a)return I.delete(i),I.set(i,a),a;let o=new Promise((e,a)=>{let s=()=>{z+=1,n(`/api/fs/stat?path=${encodeURIComponent(r)}&optional=true`,{method:`GET`,cache:`no-store`,...t?{query:{directory:t}}:{}}).then(async t=>{if(!t.ok)throw Error(`File reference probe failed (${t.status})`);let n=await t.json();if(!n||typeof n.exists!=`boolean`&&n.isFile!==!0)throw Error(`Invalid file reference probe response`);let r={exists:n.exists!==!1,isBinary:n.isBinary===!0};U(i,r),e(r)}).catch(e=>{I.get(i)===o&&(I.delete(i),L.delete(i)),a(e)}).finally(()=>{z=Math.max(0,z-1),B.shift()?.()})};if(z<ne){s();return}B.push(s)});return G(i,o),o},X=(e,t)=>{if(!(r()&&o()&&!c(e,t)))return Y(e,t);let n=m(e);if(!n)return Promise.resolve({exists:!1,isBinary:!1});let i=R(n,t),s=I.get(i);if(s)return I.delete(i),I.set(i,s),s;let l=a(e).then(e=>{let t={exists:!0,isBinary:e===!0};return U(i,t),t});return G(i,l),l},Z=(e,t,n)=>!(!t.exists||n&&t.isBinary&&!d(e)&&!p(e)),se=(e,t)=>e||u(e,t),Q=async(e,t,n)=>{let r=J(e,n.effectiveDirectory,n.referenceKind);if(!r)return;if(d(r.resolvedPath)&&n.onShowPopup){let e=r.resolvedPath.split(`/`).filter(Boolean).pop()??r.resolvedPath;n.onShowPopup({open:!0,title:e,content:``,metadata:{tool:`image-preview`,filename:e,mime:f(r.resolvedPath)},image:{url:r.resolvedPath,filename:e,mimeType:f(r.resolvedPath)}});return}let i=se(n.effectiveDirectory,r.resolvedPath),a=p(r.resolvedPath);if(n.preferRuntimeEditor&&n.editor&&!a){n.editor.openFile(r.resolvedPath,Number.isFinite(r.line??NaN)?Math.max(1,Math.trunc(r.line)):void 0,Number.isFinite(r.column??NaN)?Math.max(1,Math.trunc(r.column)):void 0);return}let o=s.getState();if(a){o.openContextFile(i,r.resolvedPath,{viewerMode:`preview`,closeFileTree:!0});return}if(Number.isFinite(r.line??NaN)){o.openContextFileAtLine(i,r.resolvedPath,Math.max(1,Math.trunc(r.line)),Number.isFinite(r.column??NaN)?Math.max(1,Math.trunc(r.column)):1,{closeFileTree:!0});return}o.openContextFile(i,r.resolvedPath,{closeFileTree:!0})},$=async(e,t)=>{let n=e.matches(`a[href]`)?e:e.querySelector(`a[href]`);await Q(n?.getAttribute(`href`)||e.getAttribute(`data-yuri-file-ref`)||q(e),e.getAttribute(`data-yuri-file-binary`)===`true`,{...t,referenceKind:n?`href`:`path`})},ce=()=>{I.clear(),L.clear(),z=0,B.length=0};export{J as a,X as c,x as d,S as f,M as g,te as h,H as i,Z as l,O as m,q as n,$ as o,N as p,P as r,K as s,F as t,b as u};
@@ -1,4 +1,4 @@
1
- import{n as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,n}from"./runtime-switch-DEZ1K7qW.js";import{n as r}from"./runtime-fetch-D0YWp3FJ.js";import{t as i}from"./runtimeAPIRegistry-C2VogTny.js";import{$ as a,A as o,At as s,D as c,F as l,G as u,H as d,I as f,J as p,K as m,M as ee,P as te,S as ne,T as re,U as ie,X as ae,Y as oe,_ as se,a as ce,b as le,c as ue,d as de,et as fe,f as pe,ft as me,gt as he,h as ge,ht as _e,k as ve,m as ye,nt as be,ot as xe,pt as Se,q as Ce,r as we,s as Te,st as Ee,tt as De,ut as Oe,v as ke,vt as Ae,x as je,y as Me}from"./gitApiHttp-CIkpp8g-.js";import{Oi as h,p as g,u as Ne}from"./useMobileNavigationStore-D-EPMP4q.js";var _=`/api/magic-prompts`,Pe=new Map([{id:`git.commit.generate.visible`,title:`Commit Generation Visible Prompt`,group:`Git`,description:`Visible user message for commit message generation.`,template:`You are generating a Conventional Commits subject line from the diffs of the selected files.`},{id:`git.commit.generate.instructions`,title:`Commit Generation Instructions`,group:`Git`,description:`Hidden instructions for commit message generation.`,placeholders:[{key:`selected_files`,description:`Bullet list of currently selected file paths.`}],template:`Return exactly one JSON object and nothing else. Do not include prose, markdown, explanations, or code fences.
1
+ import{n as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,n}from"./runtime-switch-DEZ1K7qW.js";import{n as r}from"./runtime-fetch-D0YWp3FJ.js";import{t as i}from"./runtimeAPIRegistry-C2VogTny.js";import{$ as a,A as o,At as s,D as c,F as l,G as u,H as d,I as f,J as p,K as m,M as ee,P as te,S as ne,T as re,U as ie,X as ae,Y as oe,_ as se,a as ce,b as le,c as ue,d as de,et as fe,f as pe,ft as me,gt as he,h as ge,ht as _e,k as ve,m as ye,nt as be,ot as xe,pt as Se,q as Ce,r as we,s as Te,st as Ee,tt as De,ut as Oe,v as ke,vt as Ae,x as je,y as Me}from"./gitApiHttp-MWsHNHuo.js";import{Oi as h,p as g,u as Ne}from"./useMobileNavigationStore-BWLhXqci.js";var _=`/api/magic-prompts`,Pe=new Map([{id:`git.commit.generate.visible`,title:`Commit Generation Visible Prompt`,group:`Git`,description:`Visible user message for commit message generation.`,template:`You are generating a Conventional Commits subject line from the diffs of the selected files.`},{id:`git.commit.generate.instructions`,title:`Commit Generation Instructions`,group:`Git`,description:`Hidden instructions for commit message generation.`,placeholders:[{key:`selected_files`,description:`Bullet list of currently selected file paths.`}],template:`Return exactly one JSON object and nothing else. Do not include prose, markdown, explanations, or code fences.
2
2
 
3
3
  The JSON object must have exactly this shape:
4
4
  {"subject": string, "highlights": string[]}
@@ -1,5 +1,5 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-heic2any-DgJnLT1Y.js","assets/rolldown-runtime-hePW80VL.js"])))=>i.map(i=>d[i]);
2
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{C as t,D as n,k as r}from"./runtime-auth-DBn9yahL.js";import{c as i,f as a,i as o,n as s,r as c,s as l}from"./runtime-switch-DEZ1K7qW.js";import{n as u}from"./runtime-fetch-D0YWp3FJ.js";import{T as d,u as f}from"./desktop-BAmoc_34.js";import{t as p}from"./runtimeAPIRegistry-C2VogTny.js";import{a as m,r as h}from"./vendor-zustand-vDaAPGfl.js";import{st as g}from"./vendor-base-ui-CzHs0bHY.js";import{B as ee,R as te,V as ne}from"./vendor-opencode-client-cQ47ywrT.js";import"./brand-storage-bootstrap-D4BW3w-M.js";import{S as re}from"./useUIStore-CoWJ3ROq.js";import{It as _,Rt as ie,bt as ae,ct as oe,mt as se,o as ce,rt as le,st as ue}from"./bootstrap-DGkBnhNP.js";import{n as de}from"./vendor-react-DlzBev0S.js";import{i as fe}from"./vendor-pathe-vBmvQE8f.js";import{n as pe}from"./runtime-file-resource-BP4P52ry.js";import{o as me}from"./vendor-aparajita-capacitor-secure-storage-xol_6BsB.js";var he=(e,t)=>e!==t,v=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0};function ge(e){let t=v(e.id),n=v(e.name),r=v(e.displayName),i=t??n;if(!i)return{...e,id:``,name:``,displayName:r??``};if(n===i&&r)return{...e,id:i,name:i,displayName:r};let a=r??n??i;return{...e,id:i,name:i,displayName:a}}function _e(e){return e?v(e.displayName)??v(e.name)??v(e.id)??``:``}function ve(e,t){let n=v(t);if(!n||!e?.length)return;let r=e.find(e=>v(e.name)===n);if(r)return r;let i=e.find(e=>v(e.id)===n);if(i)return i;let a=e.find(e=>v(e.displayName)===n);if(a)return a}function ye(e,t){let n=v(t);if(!n)return;let r=ve(e,n);return r?v(r.name)??v(r.id)??n:n}function be(e){return Array.from(new Set(Array.from(e.matchAll(ae()),e=>e[1])),e=>({id:e,name:e}))}function y(e){return{...e,directory:e.location?.directory}}function xe(e){let t={};for(let n of e){let e=n;!e||e.type!==`document`||!e.info||typeof e.info!=`object`||Object.assign(t,e.info)}return t}var b=e(g(),1),Se=de();function x(e,t){return e.findIndex(e=>e.id===t)}function Ce(e,t){if(!t)return e.slice();let n=x(e,t);return n<0?e.slice():e.slice(0,n)}function we(e,t,n){let r=x(e,n);return r<0?!1:x(e,t)>=r}function Te(e,t){if(!t){for(let t=e.length-1;t>=0;--t){let n=e[t];if(n?.role===`user`)return n}return}let n=x(e,t);if(!(n<0))for(let t=n-1;t>=0;--t){let n=e[t];if(n?.role===`user`)return n}}function Ee(e,t){let n=x(e,t);if(!(n<0))for(let t=n+1;t<e.length;t+=1){let n=e[t];if(n?.role===`user`)return n}}var De=`yuri:sync:debug`,Oe;function ke(){if(Oe!==void 0)return Oe;try{Oe=typeof localStorage<`u`&&localStorage.getItem(De)===`1`}catch{Oe=!1}return Oe}function S(e,...t){ke()&&(`${e}`,[...t])}var Ae={pipeline:{coalesced:(e,t)=>S(`pipeline`,`coalesced`,e,t),flush:e=>S(`pipeline`,`flush`,`${e} events`)},reducer:{messageUpdatedUnchanged:(e,t,n,r,i)=>S(`reducer`,`message.updated UNCHANGED (skipped)`,{sessionID:e,messageID:t,role:n,finish:r,completed:i}),partUpdatedNoExistingParts:(e,t,n)=>S(`reducer`,`message.part.updated NO EXISTING PARTS`,{messageID:e,partID:t,partType:n}),partDeltaNoParts:(e,t)=>S(`reducer`,`message.part.delta DROPPED (no parts array)`,{messageID:e,partID:t}),partDeltaNotFound:(e,t)=>S(`reducer`,`message.part.delta DROPPED (partID not found)`,{messageID:e,partID:t}),partSkipped:(e,t,n)=>S(`reducer`,`message.part.updated SKIPPED (type filtered)`,{messageID:e,partID:t,partType:n})},dispatch:{eventNoChange:(e,t,n)=>S(`dispatch`,`event → no change`,{eventType:e,sessionID:t,messageID:n}),eventApplied:(e,t,n)=>S(`dispatch`,`event → applied`,{eventType:e,sessionID:t,messageID:n})},recovery:{materializing:e=>S(`recovery`,`materializing session`,e)}};function je(e,t){let n=new Set(t),r=new Map,i=[],a;for(let t of e){if(!n.has(t)){i.push(t);continue}i.length>0&&r.set(t,i),i=[],a=t}let o=[],s=new Set,c=e=>{s.has(e)||(s.add(e),o.push(e))};for(let e of t){for(let t of r.get(e)??[])c(t);if(c(e),e===a)for(let e of i)c(e)}if(!a)for(let e of i)c(e);return o}var Me=`desc`;function Ne(e){return!C(e)||e.type!==`compaction`?!1:e.status===`running`||e.status===`completed`||e.status===`failed`}function Pe(e){if(e)return e.find(Ne)}var Fe=e=>e?e.toLowerCase().includes(`application/json`):!1,Ie=e=>e?e.toLowerCase().includes(`text/html`):!1;function C(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function w(e){return typeof e==`string`&&e.length>0?e:void 0}function Le(e){if(!C(e))return null;let t=w(e.id);return t?{...e,id:t}:null}function Re(e,t,n){return`${e}:${t}:${n}`}function ze(e,t,n,r,i=`text`,a){return i===`reasoning`?{id:Re(t,i,n),sessionID:e,messageID:t,type:`reasoning`,text:r}:{id:Re(t,i,n),sessionID:e,messageID:t,type:`text`,text:r,...a?.synthetic===!0?{synthetic:!0}:{}}}function Be(e){return e?e.nativeType===`synthetic`||e.type===`synthetic`:!1}function Ve(e,t){return!e?.id||Be(e)||(e.clientRole??e.role)!==`user`?!1:!Array.isArray(t)||t.length===0||!(t.some(e=>e.type===`subtask`||e.type===`compaction`)||t.every(e=>!!e.synthetic))}function He(e){if(typeof e==`string`&&e.length!==0)return e.replace(/^evt_/,`msg_`)}function Ue(e){let t=e.content;return Array.isArray(t)?t.flatMap(e=>C(e)&&e.type===`text`&&typeof e.text==`string`?[e.text]:[]).join(`
2
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{C as t,D as n,k as r}from"./runtime-auth-DBn9yahL.js";import{c as i,f as a,i as o,n as s,r as c,s as l}from"./runtime-switch-DEZ1K7qW.js";import{n as u}from"./runtime-fetch-D0YWp3FJ.js";import{T as d,u as f}from"./desktop-BAmoc_34.js";import{t as p}from"./runtimeAPIRegistry-C2VogTny.js";import{a as m,r as h}from"./vendor-zustand-vDaAPGfl.js";import{st as g}from"./vendor-base-ui-CzHs0bHY.js";import{B as ee,R as te,V as ne}from"./vendor-opencode-client-cQ47ywrT.js";import"./brand-storage-bootstrap-D4BW3w-M.js";import{S as re}from"./useUIStore-BerIUSLP.js";import{It as _,Rt as ie,bt as ae,ct as oe,mt as se,o as ce,rt as le,st as ue}from"./bootstrap-C8paoQ0j.js";import{n as de}from"./vendor-react-DlzBev0S.js";import{i as fe}from"./vendor-pathe-vBmvQE8f.js";import{n as pe}from"./runtime-file-resource-BP4P52ry.js";import{o as me}from"./vendor-aparajita-capacitor-secure-storage-xol_6BsB.js";var he=(e,t)=>e!==t,v=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0};function ge(e){let t=v(e.id),n=v(e.name),r=v(e.displayName),i=t??n;if(!i)return{...e,id:``,name:``,displayName:r??``};if(n===i&&r)return{...e,id:i,name:i,displayName:r};let a=r??n??i;return{...e,id:i,name:i,displayName:a}}function _e(e){return e?v(e.displayName)??v(e.name)??v(e.id)??``:``}function ve(e,t){let n=v(t);if(!n||!e?.length)return;let r=e.find(e=>v(e.name)===n);if(r)return r;let i=e.find(e=>v(e.id)===n);if(i)return i;let a=e.find(e=>v(e.displayName)===n);if(a)return a}function ye(e,t){let n=v(t);if(!n)return;let r=ve(e,n);return r?v(r.name)??v(r.id)??n:n}function be(e){return Array.from(new Set(Array.from(e.matchAll(ae()),e=>e[1])),e=>({id:e,name:e}))}function y(e){return{...e,directory:e.location?.directory}}function xe(e){let t={};for(let n of e){let e=n;!e||e.type!==`document`||!e.info||typeof e.info!=`object`||Object.assign(t,e.info)}return t}var b=e(g(),1),Se=de();function x(e,t){return e.findIndex(e=>e.id===t)}function Ce(e,t){if(!t)return e.slice();let n=x(e,t);return n<0?e.slice():e.slice(0,n)}function we(e,t,n){let r=x(e,n);return r<0?!1:x(e,t)>=r}function Te(e,t){if(!t){for(let t=e.length-1;t>=0;--t){let n=e[t];if(n?.role===`user`)return n}return}let n=x(e,t);if(!(n<0))for(let t=n-1;t>=0;--t){let n=e[t];if(n?.role===`user`)return n}}function Ee(e,t){let n=x(e,t);if(!(n<0))for(let t=n+1;t<e.length;t+=1){let n=e[t];if(n?.role===`user`)return n}}var De=`yuri:sync:debug`,Oe;function ke(){if(Oe!==void 0)return Oe;try{Oe=typeof localStorage<`u`&&localStorage.getItem(De)===`1`}catch{Oe=!1}return Oe}function S(e,...t){ke()&&(`${e}`,[...t])}var Ae={pipeline:{coalesced:(e,t)=>S(`pipeline`,`coalesced`,e,t),flush:e=>S(`pipeline`,`flush`,`${e} events`)},reducer:{messageUpdatedUnchanged:(e,t,n,r,i)=>S(`reducer`,`message.updated UNCHANGED (skipped)`,{sessionID:e,messageID:t,role:n,finish:r,completed:i}),partUpdatedNoExistingParts:(e,t,n)=>S(`reducer`,`message.part.updated NO EXISTING PARTS`,{messageID:e,partID:t,partType:n}),partDeltaNoParts:(e,t)=>S(`reducer`,`message.part.delta DROPPED (no parts array)`,{messageID:e,partID:t}),partDeltaNotFound:(e,t)=>S(`reducer`,`message.part.delta DROPPED (partID not found)`,{messageID:e,partID:t}),partSkipped:(e,t,n)=>S(`reducer`,`message.part.updated SKIPPED (type filtered)`,{messageID:e,partID:t,partType:n})},dispatch:{eventNoChange:(e,t,n)=>S(`dispatch`,`event → no change`,{eventType:e,sessionID:t,messageID:n}),eventApplied:(e,t,n)=>S(`dispatch`,`event → applied`,{eventType:e,sessionID:t,messageID:n})},recovery:{materializing:e=>S(`recovery`,`materializing session`,e)}};function je(e,t){let n=new Set(t),r=new Map,i=[],a;for(let t of e){if(!n.has(t)){i.push(t);continue}i.length>0&&r.set(t,i),i=[],a=t}let o=[],s=new Set,c=e=>{s.has(e)||(s.add(e),o.push(e))};for(let e of t){for(let t of r.get(e)??[])c(t);if(c(e),e===a)for(let e of i)c(e)}if(!a)for(let e of i)c(e);return o}var Me=`desc`;function Ne(e){return!C(e)||e.type!==`compaction`?!1:e.status===`running`||e.status===`completed`||e.status===`failed`}function Pe(e){if(e)return e.find(Ne)}var Fe=e=>e?e.toLowerCase().includes(`application/json`):!1,Ie=e=>e?e.toLowerCase().includes(`text/html`):!1;function C(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function w(e){return typeof e==`string`&&e.length>0?e:void 0}function Le(e){if(!C(e))return null;let t=w(e.id);return t?{...e,id:t}:null}function Re(e,t,n){return`${e}:${t}:${n}`}function ze(e,t,n,r,i=`text`,a){return i===`reasoning`?{id:Re(t,i,n),sessionID:e,messageID:t,type:`reasoning`,text:r}:{id:Re(t,i,n),sessionID:e,messageID:t,type:`text`,text:r,...a?.synthetic===!0?{synthetic:!0}:{}}}function Be(e){return e?e.nativeType===`synthetic`||e.type===`synthetic`:!1}function Ve(e,t){return!e?.id||Be(e)||(e.clientRole??e.role)!==`user`?!1:!Array.isArray(t)||t.length===0||!(t.some(e=>e.type===`subtask`||e.type===`compaction`)||t.every(e=>!!e.synthetic))}function He(e){if(typeof e==`string`&&e.length!==0)return e.replace(/^evt_/,`msg_`)}function Ue(e){let t=e.content;return Array.isArray(t)?t.flatMap(e=>C(e)&&e.type===`text`&&typeof e.text==`string`?[e.text]:[]).join(`
3
3
  `):typeof e.output==`string`?e.output:void 0}function We(e){return e===`patch`?`apply_patch`:e}function Ge(e,t,n){let r=w(n.id)??`${t}:tool`,i=We(w(n.name))??`tool`,a=C(n.state)?n.state:{},o=w(a.status)??`completed`,s=o===`streaming`?`pending`:o,c=C(n.time)?n.time:{};return{id:r,sessionID:e,messageID:t,type:`tool`,tool:i,callID:r,state:{status:s,input:a.input??{},output:Ue(a),error:C(a.error)?w(a.error.message):w(a.error),metadata:C(a.metadata)?a.metadata:{},time:{...typeof c.ran==`number`&&Number.isFinite(c.ran)?{start:c.ran}:{},...typeof c.completed==`number`&&Number.isFinite(c.completed)?{end:c.completed}:{}}}}}function Ke(e){return C(e)?{created:typeof e.created==`number`?e.created:0,...typeof e.streamed==`number`?{streamed:e.streamed}:{},...typeof e.completed==`number`?{completed:e.completed}:{},...typeof e.start==`number`?{start:e.start}:{},...typeof e.end==`number`?{end:e.end}:{}}:{created:0}}function qe(e){if(!C(e))return;let t=C(e.cache)?{...typeof e.cache.read==`number`?{read:e.cache.read}:{},...typeof e.cache.write==`number`?{write:e.cache.write}:{}}:void 0,n={...typeof e.input==`number`?{input:e.input}:{},...typeof e.output==`number`?{output:e.output}:{},...typeof e.reasoning==`number`?{reasoning:e.reasoning}:{},...t&&(t.read!==void 0||t.write!==void 0)?{cache:t}:{}};return Object.keys(n).length>0?n:void 0}function Je(e,t){let n=C(t.metadata)?t.metadata:void 0,r=n&&C(n.model)?n.model:void 0,i=C(t.model)?t.model:r,a=i?w(i.id)??w(i.modelID)??w(t.modelID):w(t.modelID),o=i?w(i.providerID)??w(t.providerID):w(t.providerID),s=(i?w(i.variant):void 0)??w(t.variant)??(n?w(n.variant):void 0);a&&(e.modelID=a),o&&(e.providerID=o),s&&(e.variant=s),(a||o||s)&&(e.model={...o?{providerID:o}:{},...a?{modelID:a}:{},...s?{variant:s}:{}});let c=w(t.agent)??w(t.mode)??(n?w(n.agent):void 0);c&&(e.agent=c)}function Ye(e,t,n){return{id:t.id,sessionID:e,role:n,time:Ke(t.time)}}function Xe(e,t){let n=Le(t);if(!n)return null;let r=n.id,i=w(n.type)??`unknown`,a=w(n.role)??w(n.clientRole);if(i===`idle`||i===`model-switched`||i===`agent-selected`||i===`agent-switched`||i===`location-switched`||a===`idle`)return null;if(i===`user`){let t=Ye(e,n,`user`);Je(t,n);let i=[],a=w(n.text);a&&i.push(ze(e,r,0,a));let o=n.files;return Array.isArray(o)&&o.forEach((t,n)=>{if(!C(t))return;let a=w(t.mime)??`application/octet-stream`,o=C(t.source)?t.source:{},s=o.type===`uri`?w(o.uri):void 0,c=w(t.data),l=s||(c?`data:${a};base64,${c}`:``),u={id:`${r}:file:${n}`,sessionID:e,messageID:r,type:`file`,mime:a,filename:w(t.name),url:l};i.push(u)}),{info:t,parts:i}}if(i===`assistant`){let t=Ye(e,n,`assistant`);if(C(n.model)){t.modelID=w(n.model.id)??w(n.model.modelID)??w(n.modelID),t.providerID=w(n.model.providerID)??w(n.providerID);let e=w(n.model.variant)??w(n.variant);(t.modelID||t.providerID||e)&&(t.model={...t.providerID?{providerID:t.providerID}:{},...t.modelID?{modelID:t.modelID}:{},...e?{variant:e}:{}})}else{let e=w(n.modelID),r=w(n.providerID),i=w(n.variant);e&&(t.modelID=e),r&&(t.providerID=r),(e||r||i)&&(t.model={...r?{providerID:r}:{},...e?{modelID:e}:{},...i?{variant:i}:{}})}let i=w(n.agent);i&&(t.agent=i);let a=w(n.finish)??w(n.rawFinish);a&&(t.finish=a),C(n.error)&&(t.error={type:w(n.error.type)??`error`,message:w(n.error.message)??``,...typeof n.error.status==`number`?{status:n.error.status}:{}}),typeof n.cost==`number`&&Number.isFinite(n.cost)&&(t.cost=n.cost);let o=qe(n.tokens);o&&(t.tokens=o);let s=[],c=Array.isArray(n.content)?n.content:[],l=0,u=0;for(let t of c){if(!C(t))continue;let n=w(t.type);if(n===`text`&&typeof t.text==`string`){s.push(ze(e,r,l++,t.text));continue}if(n===`reasoning`&&typeof t.text==`string`){s.push(ze(e,r,u++,t.text,`reasoning`));continue}n===`tool`&&s.push(Ge(e,r,t))}return{info:t,parts:s}}if(i===`shell`){let t=Ye(e,n,`user`),i=w(n.command)??``,a=C(n.output)&&typeof n.output.output==`string`?n.output.output:``,o=n.status===`running`?`running`:n.status===`exited`&&n.exit===0?`completed`:`error`;return{info:t,parts:[{id:Re(r,`text`,0),sessionID:e,messageID:r,type:`text`,text:i,shellAction:{command:i,output:a,status:o,shellID:w(n.shellID)}}]}}if(i===`synthetic`){let t={...Ye(e,n,`user`),nativeType:`synthetic`},i=w(n.description);i&&(t.description=i),C(n.metadata)&&(t.metadata=n.metadata);let a=w(n.shellID);a&&(t.shellID=a);let o=w(n.sessionID)&&n.sessionID!==e?w(n.sessionID):w(n.childSessionID)??w(n.taskSessionID);o&&(t.childSessionID=o);let s=w(n.text)??i??``;return{info:t,parts:s?[ze(e,r,0,s,`text`,{synthetic:!0})]:[{id:Re(r,`text`,0),sessionID:e,messageID:r,type:`text`,text:``,synthetic:!0}]}}if(i===`system`)return null;if(i===`compaction`){let t=n.status===`failed`?`failed`:n.status===`completed`?`completed`:`running`,i={...Ye(e,n,`assistant`),clientRole:`compaction`},a=C(n.error)?{type:w(n.error.type)??`error`,message:w(n.error.message)??``,...typeof n.error.status==`number`?{status:n.error.status}:{}}:void 0;return{info:i,parts:[{id:`${r}:compaction`,sessionID:e,messageID:r,type:`compaction`,status:t,reason:n.reason===`auto`?`auto`:`manual`,...typeof n.summary==`string`?{summary:n.summary}:{},...typeof n.recent==`string`?{recent:n.recent}:{},...a?{error:a}:{}}]}}return{info:Ye(e,n,`assistant`),parts:[ze(e,r,0,w(n.text)??`[${i}]`)]}}function Ze(e,t,n=Me,r=20){if(!C(e))throw Error(`session projection: expected JSON object`);if(!Array.isArray(e.data))throw Error(`session projection: data must be an array`);let i=[];for(let n of e.data){let e=Xe(t,n);e&&i.push(e)}n===`desc`&&i.reverse();let a=C(e.cursor)?e.cursor:void 0,o=w(a?n===`asc`?a.previous:a.next:e.cursor),s=!o||e.data.length<r,c=i.filter(e=>Ve(e.info,e.parts)).length;return{records:i,cursor:s?void 0:o,complete:s,turnCount:c}}async function Qe(e){let t=e.limit??20,n=e.order??`desc`,r=`/api/session/${encodeURIComponent(e.sessionID)}/message`,i={directory:e.directory,limit:String(t)};e.cursor?i.cursor=/^msg_[A-Za-z0-9_]+$/.test(e.cursor)?btoa(JSON.stringify({id:e.cursor,order:n,direction:n===`desc`?`next`:`previous`})).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``):e.cursor:i.order=n;let a=await u(r,{method:`GET`,query:i,signal:e.signal});if(!a.ok)throw Error(`session projection failed (${a.status})`);let o=a.headers.get(`content-type`);if(Ie(o))throw Error(`session projection: unexpected HTML response`);Fe(o);let s;try{s=await a.json()}catch{throw Error(`session projection: malformed JSON`)}return Ze(s,e.sessionID,n,t)}function $e(e){let t=e.fetched.filter(e=>!!e.info?.id),n=e.previous.filter(e=>!!e.info?.id),r=e.touched??new Set,i=new Map(t.map(e=>[e.info.id,e])),a=new Map(n.map(e=>[e.info.id,e])),o=new Set(e.coverageMessageIDs??t.map(e=>e.info.id)),s=n.findIndex(e=>o.has(e.info.id));if(!e.completeTail)for(let[e,t]of n.entries())i.has(t.info.id)||(s===-1||e<s)&&i.set(t.info.id,t);for(let e of r){let t=a.get(e);t?i.set(e,t):i.delete(e)}let c=n.map(e=>e.info.id).filter(e=>i.has(e)),l=t.map(e=>e.info.id).filter(e=>i.has(e)),u=l.some(e=>a.has(e));return(!e.completeTail&&!u?[...new Set([...c,...l])]:je(c,l)).map(e=>i.get(e))}var et=e=>e?e.toLowerCase().includes(`application/json`):!1,tt=e=>e?e.toLowerCase().includes(`text/html`):!1;function nt(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function rt(e){return typeof e==`string`&&e.length>0?e:void 0}function it(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function at(e,t,n){let r=n?`: ${n}`:``,i=Error(`${e} (${t})${r}`);throw i.status=t,i}async function ot(e){try{return(await e.text()).trim()}catch{return``}}async function st(e,t){let n=e.headers.get(`content-type`);if(tt(n))throw Error(`${t}: unexpected HTML response`);let r;try{r=await e.json()}catch{throw Error(`${t}: malformed JSON`)}if(!et(n)&&r==null)throw Error(`${t}: empty response`);return r}var ct=new Map,lt=e=>ct.get(e)??0,ut=m((e,t)=>({runningBySession:{},setRunning(t,n){ct.set(t,lt(t)+1),e(e=>{let r={...e.runningBySession};return n?r[t]=!0:delete r[t],{runningBySession:r}})},isRunning(e){return t().runningBySession[e]===!0},reset(){ct.clear(),e({runningBySession:{}})}}));function T(e,t){ut.getState().setRunning(e,t)}function dt(e){return ut.getState().isRunning(e)}function ft(e){return!dt(e.sessionID)}function pt(e){let t=nt(e)?e:null,n=t&&nt(t.data)?t.data:t;if(!n)throw Error(`session compact: expected inbox item`);let r=rt(n.id),i=rt(n.sessionID);if(!r||!i)throw Error(`session compact: inbox item missing id`);if(n.type&&n.type!==`compaction`)throw Error(`session compact: expected compaction inbox item`);return{id:r,sessionID:i,type:`compaction`,delivery:n.delivery===`queue`?`queue`:n.delivery===`steer`?`steer`:void 0,timeCreated:it(n.timeCreated)}}function mt(e){let t=nt(e)?e:null,n=t&&Array.isArray(t.data)?t.data:Array.isArray(e)?e:null;if(!n)throw Error(`session inbox: expected list`);let r=[];for(let e of n)!nt(e)||e.type!==`compaction`||r.push(pt(e));return r}function ht(e,t){t.some(e=>e.type===`compaction`)&&T(e,!0)}function gt(e,t){for(let n=t.length-1;n>=0;--n){let r=(t[n]?.parts??[]).find(Ne);if(r){T(e,r.status===`running`);return}}}async function _t(e){let t=`/api/session/${encodeURIComponent(e.sessionID)}/compact`,n={};e.messageID&&(n.id=e.messageID),e.delivery&&(n.delivery=e.delivery);let r=await u(t,{method:`POST`,headers:{"Content-Type":`application/json`},query:{directory:e.directory},body:JSON.stringify(n),signal:e.signal});r.ok||at(`session compact`,r.status,await ot(r));let i=pt(await st(r,`session compact`));return T(i.sessionID,!0),i}var vt=`compaction:`;function yt(e,t){return t&&t.length>0?t:`${vt}${e}`}function bt(e,t){let n=e.message[t]??[];for(let t=n.length-1;t>=0;--t){let r=n[t];if((e.part[r.id]??[]).some(e=>Ne(e)&&e.status===`running`))return r.id}}function xt(e,t,n,r,i=Date.now()){let a=e.message[t]?[...e.message[t]]:[];a.some(e=>e.id===n)||(a.push({id:n,sessionID:t,role:`assistant`,clientRole:`compaction`,time:{created:i}}),e.message[t]=a);let o=e.part[n]?[...e.part[n]]:[],s=o.findIndex(Ne),c=r(s>=0?o[s]:{id:`${n}:compaction`,sessionID:t,messageID:n,type:`compaction`,status:`running`,reason:`manual`});s>=0?o[s]=c:o.push(c),e.part[n]=o}function St(e,t){let n=String(t.type??``);if(!n.startsWith(`session.compaction.`))return!1;let r=nt(t.properties)?t.properties:null;if(!r)return!1;let i=rt(r.sessionID);if(!i)return!1;let a=rt(r.inputID),o=bt(e,i),s=n===`session.compaction.started`?a??He(t.id)??yt(i):a??o??He(t.id)??yt(i);if(n===`session.compaction.started`)return!e.part[s]?.some(Ne)&&(xt(e,i,s,e=>({...e,status:`running`,reason:r.reason===`auto`?`auto`:`manual`,...typeof r.recent==`string`?{recent:r.recent}:{}}),it(r.eventCreated)),T(i,!0),!0);if(n===`session.compaction.delta`){if(!o)return!1;let t=typeof r.text==`string`?r.text:``;return t?(xt(e,i,s,e=>({...e,status:`running`,summary:(e.summary??``)+t})),T(i,!0),!0):!1}if(n===`session.compaction.ended`)return T(i,!1),o?(xt(e,i,s,e=>({...e,status:`completed`,reason:r.reason===`auto`?`auto`:`manual`,summary:typeof r.text==`string`?r.text:e.summary,...typeof r.recent==`string`?{recent:r.recent}:{}}),it(r.eventCreated)),!0):!1;if(n===`session.compaction.failed`){if(T(i,!1),!o&&!a)return!1;let t=nt(r.error)?r.error:{};return xt(e,i,s,e=>({...e,status:`failed`,reason:r.reason===`auto`?`auto`:`manual`,error:{type:rt(t.type)??`error`,message:rt(t.message)??``,...typeof t.status==`number`?{status:t.status}:{}}}),it(r.eventCreated)),!0}return!1}var Ct=new Set([`patch`,`step-start`,`step-finish`]),wt=[`text`,`output`],Tt=new Set([`completed`,`error`,`aborted`,`failed`,`timeout`,`cancelled`]);function Et(e,t){if(!e||t.length===0)return(e??``)+t;if(e.endsWith(t))return e;let n=Math.min(e.length,t.length);for(let r=n;r>0;r--)if(e.endsWith(t.slice(0,r)))return e+t.slice(r);return e+t}function Dt(e,t){let n=[];for(let r of wt){let i=e[r],a=t[r];typeof i==`string`&&typeof a==`string`&&i.length!==0&&a.length!==0&&(a===i||a.startsWith(i)||i.startsWith(a))&&n.push(r)}return n}function Ot(e){let t=e.state?.time?.end;if(typeof t==`number`)return t;let n=e.time?.end;return typeof n==`number`?n:void 0}function kt(e){if(e.type!==`tool`)return;let t=e.state?.status;return typeof t==`string`?t:void 0}function At(e,t){if(e.type!==`tool`||t.type!==`tool`)return!1;let n=kt(e),r=kt(t);if(n&&Tt.has(n)&&(!r||!Tt.has(r)))return!0;let i=Ot(e),a=Ot(t);return typeof i==`number`&&typeof a!=`number`}function jt(e,t){if(e===t)return!0;if(e===void 0||t===void 0)return e===t;try{return JSON.stringify(e)===JSON.stringify(t)}catch{return!1}}var Mt=[`agent`,`mode`,`providerID`,`modelID`,`variant`],Nt=e=>typeof e==`object`&&!!e&&!Array.isArray(e),Pt=[`input`,`output`,`reasoning`];function Ft(e){if(!e||typeof e!=`object`)return!1;let t=e;return Pt.some(e=>typeof t[e]==`number`&&Number.isFinite(t[e])&&t[e]>0)}function It(e){if(!e||typeof e!=`object`)return!1;let t=e;return Pt.every(e=>typeof t[e]!=`number`||!Number.isFinite(t[e])||t[e]<=0)}function Lt(e){if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0}function Rt(e,t){let n={...e,...t},r=e,i=t,a=n;for(let e of Mt){let t=Lt(i[e]),n=Lt(r[e]);t?a[e]=t:n?a[e]=n:delete a[e]}let o=i.model,s=r.model;return Nt(o)?a.model=o:Nt(s)?a.model=s:delete a.model,(e.time||t.time)&&(n.time={...e.time,...t.time}),Ft(r.tokens)&&It(i.tokens)&&(a.tokens=r.tokens),n}function zt(e,t){if(e.time.streamed!==t.time.streamed||e.role!==t.role||e.finish!==t.finish||e.time?.completed!==t.time?.completed)return!1;for(let n of[`summary`,`error`,`cost`,`tokens`,`structured`,`model`,`tools`,`format`,`variant`,`agent`,`mode`,`providerID`,`modelID`,`system`])if(!jt(e[n],t[n]))return!1;return!0}function Bt(e,t,n){if(!t)return!1;let r=e.message[t];return r?x(r,n)>=0:!1}function Vt(e,t){switch(t.type){case`message.updated`:{let n=t.properties.info,r=n,i=typeof r.type==`string`?r.type:void 0,a=typeof r.role==`string`?r.role:void 0;if(i===`idle`||i===`model-switched`||i===`agent-selected`||i===`agent-switched`||i===`location-switched`||a===`idle`)return!1;let o=e.message[n.sessionID],s=!!o&&o.every(t=>t.role!==`assistant`||e.part[t.id]!==void 0);if(n.role===`assistant`&&s&&e.part[n.id]===void 0&&(e.part[n.id]=[]),!o)return e.message[n.sessionID]=[n],!0;let c=x(o,n.id);if(c>=0){let t=o[c],r=Rt(t,n);if(zt(t,r))return Ae.reducer.messageUpdatedUnchanged(n.sessionID,n.id,n.role,n.finish,n.time?.completed),!1;let i=[...o];i[c]=r,e.message[n.sessionID]=i}else e.message[n.sessionID]=[...o,n];return!0}case`message.removed`:{let n=t.properties,r=e.message[n.sessionID];if(r){let t=x(r,n.messageID);if(t>=0){let i=[...r];i.splice(t,1),e.message[n.sessionID]=i}}return delete e.part[n.messageID],!0}case`message.part.updated`:{let n=t.properties,r=n.part;if(Ct.has(r.type))return Ae.reducer.partSkipped(r.messageID,r.id,r.type),!1;let i=r.messageID,a=n.sessionID??r.sessionID;if(!i)return!1;let o=!Bt(e,a,i),s=e.part[i];if(!s)return Ae.reducer.partUpdatedNoExistingParts(i,r.id,r.type),e.part[i]=[r],!o||{changed:!0,materialization:{type:`incomplete-session-snapshot`,reason:`missing-owning-message`,sessionID:a,messageID:i,partID:r.id}};let c=[...s],l=c.findIndex(e=>e.id===r.id);if(l>=0){let e=c[l];if(At(e,r))return!1;let t=Dt(e,r);c[l]=t.length>0?{...r,__dedupeNextDeltaFields:t}:r}else{let e=r.type===`text`||r.type===`file`?c.findIndex(e=>e.type===r.type&&e.__yuriOptimistic===!0):-1;e>=0?c[e]=r:c.push(r)}return e.part[i]=c,!o||{changed:!0,materialization:{type:`incomplete-session-snapshot`,reason:`missing-owning-message`,sessionID:a,messageID:i,partID:r.id}}}case`message.part.removed`:{let n=t.properties,r=e.part[n.messageID];if(!r)return!1;let i=r.findIndex(e=>e.id===n.partID);if(i>=0){let t=[...r];return t.splice(i,1),t.length===0?delete e.part[n.messageID]:e.part[n.messageID]=t,!0}return!1}case`message.part.delta`:{let n=t.properties,r=e.part[n.messageID];if(!r)return Ae.reducer.partDeltaNoParts(n.messageID,n.partID),{changed:!1,materialization:{type:`incomplete-session-snapshot`,reason:`orphan-delta`,sessionID:n.sessionID,messageID:n.messageID,partID:n.partID}};let i=r.findIndex(e=>e.id===n.partID);if(i<0)return Ae.reducer.partDeltaNotFound(n.messageID,n.partID),{changed:!1,materialization:{type:`incomplete-session-snapshot`,reason:`missing-delta-part`,sessionID:n.sessionID,messageID:n.messageID,partID:n.partID}};let a=r[i],o=a[n.field],s=a.__dedupeNextDeltaFields??[],c=s.includes(n.field),l=[...r];return l[i]={...a,[n.field]:c?Et(o,n.delta):(o??``)+n.delta,__dedupeNextDeltaFields:s.filter(e=>e!==n.field)},e.part[n.messageID]=l,!0}default:return tn(e,t)}}function E(e){return!e||typeof e!=`object`||Array.isArray(e)?null:e}function D(e){return typeof e==`string`&&e.length>0?e:void 0}function Ht(e,t,n){return`${e}:${t}:${n}`}function Ut(e){return typeof e?.created==`number`&&Number.isFinite(e.created)&&e.created>0?e.created:Date.now()}function O(e){let t=e.eventCreated;return typeof t==`number`&&Number.isFinite(t)&&t>0?t:void 0}function Wt(e,t,n,r){let i=e.message[t],a=i?x(i,n):-1;if(a>=0&&i){let n=i[a],o=n.time?.created,s=!1,c={...n,time:{...n.time}};if((o===void 0||o<=0)&&typeof r?.created==`number`&&r.created>0&&(c.time={...c.time,created:r.created},s=!0),!Lt(n.agent)&&r?.agent&&(c.agent=r.agent,s=!0),!Lt(n.modelID)&&r?.modelID&&(c.modelID=r.modelID,s=!0),!Lt(n.providerID)&&r?.providerID&&(c.providerID=r.providerID,s=!0),!Lt(n.variant)&&r?.variant&&(c.variant=r.variant,s=!0),!n.model&&r?.model&&(c.model=r.model,s=!0),!s)return!1;let l=[...i];return l[a]=c,e.message[t]=l,!0}let o={id:n,sessionID:t,role:`assistant`,time:{created:Ut(r)},...r?.agent?{agent:r.agent}:{},...r?.modelID?{modelID:r.modelID}:{},...r?.providerID?{providerID:r.providerID}:{},...r?.variant?{variant:r.variant}:{},...r?.model?{model:r.model}:{}};return e.message[t]=i?[...i,o]:[o],!0}function Gt(e){let t=D(e.agent),n=E(e.model),r=n?D(n.id)??D(n.modelID):void 0,i=n?D(n.providerID):void 0,a=n?D(n.variant):void 0;return{...t?{agent:t}:{},...r?{modelID:r}:{},...i?{providerID:i}:{},...a?{variant:a}:{},...r||i||a?{model:{...i?{providerID:i}:{},...r?{modelID:r}:{},...a?{variant:a}:{}}}:{}}}function Kt(e){let t=E(e);if(!t)return;let n=E(t.cache),r={...typeof t.input==`number`?{input:t.input}:{},...typeof t.output==`number`?{output:t.output}:{},...typeof t.reasoning==`number`?{reasoning:t.reasoning}:{},...n?{cache:{...typeof n.read==`number`?{read:n.read}:{},...typeof n.write==`number`?{write:n.write}:{}}}:{}};return Object.keys(r).length>0?r:void 0}function qt(e,t,n,r){let i=e.message[t];if(!i)return e.message[t]=[r],!0;let a=x(i,n);if(a<0)return e.message[t]=[...i,r],!0;let o=i[a],s=Rt(o,r);if(zt(o,s)&&o.time?.created===s.time?.created)return!1;let c=[...i];return c[a]=s,e.message[t]=c,!0}function Jt(e,t,n){let r=e.message[t];if(!r)return;let i=x(r,n);if(i<0)return;let a=r[i]?.time?.created;return typeof a==`number`&&Number.isFinite(a)&&a>0?a:void 0}function Yt(e,t,n,r,i){let a=O(i);if(t===`session.step.started`)return Wt(e,n,r,{created:a,...Gt(i)});if(t===`session.step.streamed`)return a?(Wt(e,n,r,{created:a}),qt(e,n,r,{id:r,sessionID:n,role:`assistant`,time:{created:Jt(e,n,r)??a,streamed:a}})):!1;if(t===`session.step.ended`){Wt(e,n,r,{created:a});let t=D(i.finish),o=Kt(i.tokens),s=typeof i.cost==`number`&&Number.isFinite(i.cost)?i.cost:void 0;return qt(e,n,r,{id:r,sessionID:n,role:`assistant`,time:{created:Jt(e,n,r)??Ut({created:a}),...a?{completed:a}:{}},...t?{finish:t}:{},...o?{tokens:o}:{},...s===void 0?{}:{cost:s}})}if(t===`session.step.failed`){Wt(e,n,r,{created:a});let t=E(i.error),o=Kt(i.tokens),s=typeof i.cost==`number`&&Number.isFinite(i.cost)?i.cost:void 0;return qt(e,n,r,{id:r,sessionID:n,role:`assistant`,time:{created:Jt(e,n,r)??Ut({created:a}),...a?{completed:a}:{}},finish:`error`,...t?{error:{type:D(t.type)??`error`,message:D(t.message)??``,...typeof t.status==`number`?{status:t.status}:{}}}:D(i.error)?{error:{type:`error`,message:D(i.error)}}:{},...o?{tokens:o}:{},...s===void 0?{}:{cost:s}})}return!1}function Xt(e){if(Array.isArray(e))return e.flatMap(e=>{let t=E(e);return t&&t.type===`text`&&typeof t.text==`string`?[t.text]:[]}).join(`
4
4
  `)}function Zt(e,t,n,r){let i=Ht(n,t,r),a=e.findIndex(e=>e.id===i);return a>=0?a:e.map((e,t)=>({part:e,index:t})).filter(e=>e.part.type===t)[r]?.index??-1}function Qt(e,t,n,r,i,a,o){Wt(e,t,n,o);let s=e.part[n]?[...e.part[n]]:[],c=Zt(s,r,n,i);if(c<0){let e={id:Ht(n,r,i),sessionID:t,messageID:n,type:r,text:``};s.push(e),c=s.length-1}let l=s[c],u=typeof a==`function`?a(l.text??``):a;return s[c]={...l,text:u},e.part[n]=s,!0}function $t(e,t){return e.findIndex(e=>e.id===t||e.callID===t||e.type===`tool`&&e.id===t)}function k(e,t,n,r,i,a,o){Wt(e,t,n,o);let s=e.part[n]?[...e.part[n]]:[],c=$t(s,r);return c<0&&(s.push({id:r,sessionID:t,messageID:n,type:`tool`,tool:We(i)??`tool`,callID:r,state:{status:`pending`,input:``,output:void 0,metadata:{}}}),c=s.length-1),s[c]=a(s[c]),e.part[n]=s,!0}function en(e,t,n){return e.message[t]?.find(t=>e.part[t.id]?.some(e=>e.type===`text`&&e.shellAction?.shellID===n))?.id}function tn(e,t){let n=String(t.type);if(n.startsWith(`session.compaction.`))return St(e,t);let r=E(t.properties);if(!r)return!1;let i=D(r.sessionID);if(i&&(n===`session.shell.started`||n===`session.shell.ended`)){let a=E(r.shell),o=D(a?.id);if(!a||!o)return!1;let s=e.message[i]??[],c=en(e,i,o),l=c?s.find(e=>e.id===c):void 0,u=l?.id??(n===`session.shell.started`?He(t.id):void 0);if(!u||n===`session.shell.started`&&l)return!1;let d=Xe(i,{id:u,type:`shell`,shellID:o,command:a.command,status:a.status,exit:a.exit,output:r.output,time:{created:l?.time.created??O(r),...n===`session.shell.ended`?{completed:O(r)}:{}}});return!d||l&&jt(l,d.info)&&jt(e.part[u],d.parts)?!1:(e.message[i]=l?s.map(e=>e.id===u?d.info:e):[...s,d.info],e.part[u]=d.parts,!0)}if(i&&n===`session.synthetic`){let n=He(t.id);if(!n)return!1;let a=Xe(i,{id:n,type:`synthetic`,text:r.text,description:r.description,metadata:r.metadata,time:{created:O(r)}});if(!a)return!1;let o=e.message[i]??[],s=o.find(e=>e.id===n);return s&&jt(s,a.info)&&jt(e.part[n],a.parts)?!1:(e.message[i]=s?o.map(e=>e.id===n?a.info:e):[...o,a.info],e.part[n]=a.parts,!0)}if(n===`session.revert.committed`)return!1;let a=D(r.assistantMessageID);if(!i||!a)return!1;let o=typeof r.ordinal==`number`?r.ordinal:0,s={created:O(r)};if(n===`session.step.started`||n===`session.step.streamed`||n===`session.step.ended`||n===`session.step.failed`)return Yt(e,n,i,a,r);if(n===`session.text.started`)return Qt(e,i,a,`text`,o,``,s);if(n===`session.text.delta`){let t=typeof r.delta==`string`?r.delta:``;return t?Qt(e,i,a,`text`,o,e=>e+t,s):!1}if(n===`session.text.ended`)return Qt(e,i,a,`text`,o,typeof r.text==`string`?r.text:``,s);if(n===`session.reasoning.started`)return Qt(e,i,a,`reasoning`,o,``,s);if(n===`session.reasoning.delta`){let t=typeof r.delta==`string`?r.delta:``;return t?Qt(e,i,a,`reasoning`,o,e=>e+t,s):!1}if(n===`session.reasoning.ended`)return Qt(e,i,a,`reasoning`,o,typeof r.text==`string`?r.text:``,s);let c=D(r.id);if(!c)return!1;let l=D(r.name);if(n===`session.tool.input.started`)return k(e,i,a,c,l,e=>e,s);if(n===`session.tool.input.delta`){let t=typeof r.delta==`string`?r.delta:``;return t?k(e,i,a,c,l,e=>{let n=E(e.state)??{};if(D(n.status)&&n.status!==`pending`&&n.status!==`streaming`)return e;let r=typeof n.input==`string`?n.input+t:t;return{...e,state:{...n,status:`pending`,input:r}}},s):!1}if(n===`session.tool.input.ended`){let t=typeof r.text==`string`?r.text:``;return k(e,i,a,c,l,e=>{let n=E(e.state)??{};return{...e,state:{...n,input:t}}},s)}return n===`session.tool.called`?k(e,i,a,c,l,e=>{let t=E(e.state)??{},n=O(r);return{...e,state:{...t,status:`pending`,input:r.input??t.input??{},metadata:E(t.metadata)??{},...n===void 0?{}:{time:{...E(t.time),start:n}}}}},s):n===`session.tool.progress`?k(e,i,a,c,l,e=>{let t=E(e.state)??{};return{...e,state:{...t,metadata:E(r.metadata)??E(t.metadata)??{}}}},s):n===`session.tool.success`?k(e,i,a,c,l,e=>{let t=E(e.state)??{},n=O(r);return{...e,state:{...t,status:`completed`,input:t.input??r.input??{},output:Xt(r.content),metadata:E(r.metadata)??E(t.metadata)??{},...n===void 0?{}:{time:{...E(t.time),end:n}}}}},s):n===`session.tool.failed`&&k(e,i,a,c,l,e=>{let t=E(e.state)??{},n=O(r),i=E(r.error);return{...e,state:{...t,status:`error`,input:t.input??{},output:Xt(r.content),error:i?D(i.message)??D(r.error):D(r.error),metadata:E(r.metadata)??E(t.metadata)??{},...n===void 0?{}:{time:{...E(t.time),end:n}}}}},s)}function nn(e){if(typeof e.time?.completed==`number`)return!1;let t=e.finish;return!(typeof t==`string`&&t.length>0)}function rn(e){let t=e.id;return typeof t==`string`&&t.length>0?t:void 0}function A(e){return e.slim===!0}function an(e,t){if(!e||e.length===0||!t.some(e=>A(e)))return t;let n=new Map;for(let t of e){let e=rn(t);e&&!A(t)&&n.set(e,t)}if(n.size===0)return t;let r=!1,i=t.map(e=>{if(!A(e))return e;let t=rn(e);if(!t)return e;let i=n.get(t);return i?(r=!0,i):e});return r?i:t}function on(e,t){return e===t||e.length===t.length&&e.every((e,n)=>e===t[n])?t:e}function sn(e){let t=e.clientRole??e.role;return typeof t==`string`?t:``}function cn(e){return sn(e)!==`assistant`||!nn(e)}function ln(e,t,n){if(!e||e.length===0)return t;let r=an(e,t);if(cn(n))return on(r,e);let i=new Set;for(let e of r){let t=rn(e);t&&i.add(t)}let a=new Map,o=[],s,c=0;for(let t of e){let e=rn(t);if(e&&i.has(e)){s=e;continue}if(!e)continue;if(c+=1,!s){o.push(t);continue}let n=a.get(s);if(n){n.push(t);continue}a.set(s,[t])}if(c===0)return on(r,e);let l=[...o];for(let e of r){l.push(e);let t=rn(e);if(!t)continue;let n=a.get(t);n&&l.push(...n)}return on(l,e)}var un=e=>Object.freeze(e),dn=Object.freeze({initial:un({id:`initial`,onStale:`backfill`,messages:`insert-only`,parts:`replace`,preserveStreaming:`assistant`,protectOptimistic:`none`}),prepend:un({id:`history`,onStale:`drop`,messages:`insert-only`,parts:`skip-existing`,preserveStreaming:`assistant`,protectOptimistic:`none`}),recovery:un({id:`recovery`,onStale:`backfill`,messages:`upsert`,parts:`replace`,preserveStreaming:`assistant`,protectOptimistic:`none`}),"reconcile-page":un({id:`reconcile-page`,onStale:`backfill`,messages:`upsert`,parts:`replace`,preserveStreaming:`assistant`,protectOptimistic:`keep-unless-full`}),materialize:un({id:`materialize`,onStale:`backfill`,messages:`insert-only`,parts:`replace`,preserveStreaming:`assistant`,protectOptimistic:`none`})}),fn=un({id:`recovery-backfill`,onStale:`backfill`,messages:`insert-only`,parts:`skip-existing`,preserveStreaming:`assistant`,protectOptimistic:`none`}),pn=un({id:`send-gap-fill`,onStale:`backfill`,messages:`insert-only`,parts:`skip-existing`,preserveStreaming:`assistant`,protectOptimistic:`none`}),mn=dn.initial;function hn(e){let t=dn[e.purpose]??mn;return!e.stale||t.onStale===`drop`?t:fn}function gn(e,t){return e.preserveStreaming===`none`?!1:e.preserveStreaming===`all`||t===`assistant`}var _n=e=>structuredClone(e),vn=e=>({transport:e.transport,generation:e.generation,directory:e.directory,sessionID:e.sessionID});function yn(e){return JSON.stringify([e.transport,e.generation,e.directory,e.sessionID])}function bn(e,t){return JSON.stringify([e.transport,e.generation,e.directory,e.sessionID,t])}function xn(e){return JSON.stringify([e.transport,e.generation])}function Sn(e,t){return e.created===t.created?e.messageID<t.messageID?-1:+(e.messageID>t.messageID):e.created-t.created}function Cn(e){let t=e.time?.created;return{created:typeof t==`number`&&Number.isFinite(t)?t:0,messageID:e.id}}function wn(e){return cn(e)}function Tn(e){return A(e)?`slim`:`full`}function En(e){return e.some(e=>A(e))?`slim`:`full`}var Dn=e=>{if(typeof e!=`object`||!e)return e;if(Array.isArray(e))return e.map(Dn);let t=e,n={};for(let e of Object.keys(t).sort()){let r=t[e];r!==void 0&&(n[e]=Dn(r))}return n},On=e=>{let t=new Uint8Array(e),n=``;for(let e of t)n+=e.toString(16).padStart(2,`0`);return n};async function kn(e,t){let n=JSON.stringify(Dn({info:e,parts:t})),r=new TextEncoder().encode(n);return{hash:On(await crypto.subtle.digest(`SHA-256`,r)),byteSize:r.byteLength}}var An=e=>({scope:vn(e.scope),messageID:e.messageID,info:_n(e.info),parts:_n(e.parts),partCompleteness:e.partCompleteness.slice(),completeness:e.completeness,contentHash:e.contentHash,byteSize:e.byteSize,lastAccessedAt:e.lastAccessedAt,sortKey:{created:e.sortKey.created,messageID:e.sortKey.messageID}}),jn=e=>{let t=0;return()=>{let n=e();return t=n>t?n:t+1,t}},Mn=(e,t)=>{let n=t.slice().sort((e,t)=>Sn(e.sortKey,t.sortKey)).map(An);return{scope:vn(e),records:n,byteSize:n.reduce((e,t)=>e+t.byteSize,0)}},Nn=e=>_n(e),Pn=e=>vn(e),Fn=(e=Date.now)=>jn(e),In=e=>An(e),Ln=(e,t)=>Mn(e,t.slice());function Rn(e){return wn(e.info)?e.existing?.completeness===`full`&&e.incomingCompleteness===`slim`?{status:`skipped`,reason:`slim-downgrade`}:e.incomingHash!==void 0&&e.existing?.contentHash===e.incomingHash?{status:`skipped`,reason:`unchanged`}:{status:`written`}:{status:`skipped`,reason:`not-settled`}}var zn=[`text`,`output`],Bn={pending:1,started:2,running:3,completed:4,error:4};function Vn(e,t){return e.filter(e=>!!e?.id&&!t.has(e.type))}function Hn(e,t){if(!e||e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1){let r=e[n],i=t[n];if(!r||!i||r.id!==i.id||JSON.stringify(r)!==JSON.stringify(i))return!1}return!0}function Un(e){let t=e.state?.time?.end;if(typeof t==`number`)return t;let n=e.time?.end;return typeof n==`number`?n:void 0}function Wn(e,t){let n=e[t];return typeof n==`string`?n:void 0}function Gn(e){return Un(e)===void 0&&zn.some(t=>{let n=Wn(e,t);return typeof n==`string`&&n.length>0})}function Kn(e){let t=e.state;if(!(!t||typeof t!=`object`))return t}function qn(e){let t=Kn(e)?.status;return typeof t==`string`?t:void 0}function Jn(e){return e?Bn[e]??0:0}function Yn(e,t){if(Gn(e))return!0;if(Un(e)===void 0){if(e.type===`tool`){let n=qn(e);return n===`completed`||n===`error`?t:!0}return!0}return t}function Xn(e){let t=e.state?.time;if(!t||typeof t!=`object`)return;let n=typeof t.start==`number`?t.start:void 0,r=typeof t.end==`number`?t.end:void 0;if(n!==void 0||r!==void 0)return{start:n,end:r}}function Zn(e){return!!e&&typeof e==`object`&&!Array.isArray(e)&&Object.keys(e).length>0}function Qn(e,t,n){if(e.type!==`tool`||t.type!==`tool`)return n;let r=Kn(e);if(!r)return n;let i=Kn(n)??{},a=Kn(t)??{},o={...i},s=!1,c=qn(e),l=qn(t);Jn(c)>Jn(l)&&c&&(o={...o,status:c},s=!0);let u=r.input,d=a.input;Zn(u)&&!Zn(d)&&(o={...o,input:u},s=!0);let f=r.output,p=a.output;typeof f==`string`&&f.length>0?(typeof p!=`string`||p.length<f.length)&&(typeof p!=`string`||p.length===0||f.startsWith(p))&&(o={...o,output:f},s=!0):f!==void 0&&p===void 0&&(o={...o,output:f},s=!0);let m=r.metadata;return Zn(m)&&!Zn(a.metadata)&&(o={...o,metadata:m},s=!0),s?n===t?{...t,state:o}:{...n,state:o}:n}function $n(e,t){if(!e||Un(t)!==void 0)return t;let n=t;for(let r of zn){let i=Wn(e,r);if(!i)continue;let a=Wn(t,r);if(typeof a==`string`&&a.length>=i.length||typeof a==`string`&&a.length>0&&!i.startsWith(a))continue;n===t&&(n={...t});let o=n;o[r]=i}let r=Xn(e);if(r){let e=Xn(t),i=e?.start??r.start,a=e?.end??r.end;if(i!==e?.start||a!==e?.end){n===t&&(n={...t});let e=n;e.state={...n.state??{},time:{start:i,end:a}}}}return n=Qn(e,t,n),n}function er(e,t){if(!e||e.length===0||!t.some(e=>A(e)))return t;let n=new Map;for(let t of e)t.id&&!A(t)&&n.set(t.id,t);if(n.size===0)return t;let r=!1,i=t.map(e=>{if(!A(e)||!e.id)return e;let t=n.get(e.id);return t?(r=!0,t):e});return r?i:t}function tr(e){return e.__yuriOptimistic===!0}function nr(e){return!!(e&&e.length>0&&e.some(tr))}function rr(e){return e.length===0||e.some(e=>A(e))}function ir(e,t,n,r,i,a){if(a===`keep-unless-full`&&e&&nr(e)&&rr(t))return e;let o=er(e,t);if(!e||e.length===0||!r)return o;let s=new Map(e.map(e=>[e.id,e])),c=o,l=!1;for(let e=0;e<o.length;e+=1){let t=o[e],n=$n(s.get(t.id),t);n!==t&&(l||(c=[...o]),c[e]=n,l=!0)}let u=new Set(o.map(e=>e.id)),d=o.some(e=>A(e)),f=e.filter(e=>!!e?.id&&!u.has(e.id)&&!n.has(e.type)&&(Yn(e,i)||d&&!A(e)));if(f.length===0)return c;let p=new Set(f.map(e=>e.id)),m=new Map,h=[];for(let t of e)p.has(t.id)?h.push(t):u.has(t.id)&&h.length>0&&(m.set(t.id,h),h=[]);let g=[];for(let e of c){for(let t of m.get(e.id)??[])g.push(t);g.push(e)}for(let e of h)g.push(e);return g}var ar=e=>e,or=e=>{let t=ar(e).finish;return typeof t==`string`&&t.length>0},sr=e=>typeof ar(e).time?.completed==`number`,cr=e=>!!ar(e).error;function lr(e,t){let n=ar(t),r=n.finish,i=n.time?.completed,a=n.time?.streamed,o=n.error,s=e.tokens,c=t.tokens,l=!or(e)&&typeof r==`string`&&r.length>0,u=!sr(e)&&typeof i==`number`,d=e.time.streamed===void 0&&typeof a==`number`&&Number.isFinite(a),f=!cr(e)&&!!o,p=!Ft(s)&&Ft(c);if(!l&&!u&&!d&&!f&&!p)return e;let m={...e};return l&&(m.finish=r),(u||d)&&(m.time={...ar(e).time,...u?{completed:i}:{},...d?{streamed:a}:{}}),f&&(m.error=o),p&&(m.tokens=c),m}function ur(e,t,n,r){if(t.length===0)return e;let i=new Map(t.map(e=>[e.id,e])),a=!1,o=[];for(let t of e){let e=n(t,i.get(t.id));e!==t&&(a=!0),o.push(e)}let s=new Set(e.map(e=>e.id));if(!t.some(e=>s.has(e.id)))return r===`prepend`?[...t,...o]:r===`by-created`?dr(o,t):[...o,...t];let c=new Map(t.map(e=>[e.id,e]));for(let e of o)c.set(e.id,e);let l=je(e.map(e=>e.id),t.map(e=>e.id)).map(e=>c.get(e));return!a&&l.length===e.length&&l.every((t,n)=>t===e[n])?e:l}function dr(e,t){let n=e.slice();for(let e of t){let t=Cn(e),r=n.length;for(let e=0;e<n.length;e+=1)if(Sn(t,Cn(n[e]))<0){r=e;break}n.splice(r,0,e)}return n}function fr(e,t,n){return ur(e,t,(e,t)=>t?lr(e,t):e,n)}function pr(e,t,n){return ur(e,t,(e,t)=>!t||JSON.stringify(e)===JSON.stringify(t)?e:Rt(e,t),n)}function mr(e,t,n,r={}){let i=r.skipPartTypes??new Set,a=r.merge??mn,o=r.placeUnanchoredNewMessages??`append`,s=n.filter(e=>!!e?.info?.id),c=s.map(e=>e.info),l=e.message[t],u=l??[],d=a.messages===`upsert`?pr(u,c,o):fr(u,c,o),f=d!==u||l===void 0&&s.length===0,p=!1,m={...e.part},h=a.parts===`skip-existing`;for(let e of s){let t=e.info.id;if(h&&m[t])continue;let n=e.info.role===`assistant`,r=m[t],o=ir(r,Vn(e.parts??[],i),i,gn(a,e.info.role),nn(e.info),a.protectOptimistic);(r?Hn(r,o):o.length===0&&!n)||o.length===0&&!n||(m[t]=o,p=!0)}return{message:f?{...e.message,[t]:d}:e.message,part:p?m:e.part,messages:d,messagesChanged:f,partsChanged:p}}function hr(e){if(typeof e.time?.completed==`number`)return!1;let t=e.finish;return!(typeof t==`string`&&t.length>0)}function gr(e){let t=e.messages;if(!t)return{hasMessages:!1,renderable:!1,missingPartMessageIDs:[]};let n=t.length>0?t[t.length-1]?.id:void 0,r=[];for(let i of t)i.role===`assistant`&&(e.parts[i.id]||i.id===n&&hr(i)||r.push(i.id));return{hasMessages:!0,renderable:r.length===0,missingPartMessageIDs:r}}var _r=(e,t)=>e<t?-1:+(e>t);function vr(e){return e.filter(e=>!!e?.id)}function yr(e,t){if(t.length===0)return{...e,confirmed:[]};let n=[...e.session],r=new Map(e.part.map(e=>[e.id,vr(e.part)])),i=[];for(let e of t){if(n.findIndex(t=>t.id===e.message.id)<0){n.push(e.message),r.set(e.message.id,vr(e.parts));continue}let t=r.get(e.message.id);if(t&&t.length>0){i.push(e.message.id);continue}r.set(e.message.id,vr(e.parts))}return{cursor:e.cursor,complete:e.complete,session:n,part:[...r.entries()].sort((e,t)=>_r(e[0],t[0])).map(([e,t])=>({id:e,part:t})),confirmed:i}}var br={kind:`unknown`,loadedTurns:0},xr=3e4,Sr=12e5,Cr={project:``,projectMeta:void 0,icon:void 0,provider:{all:[],connected:[],default:{}},config:{},path:{state:``,config:``,worktree:``,directory:``,home:``},status:`loading`,agent:[],command:[],session:[],sessionTotal:0,session_status:{},session_status_observed_at:{},session_status_event_at:{},session_status_event_sequence:{},session_interrupt_acknowledged_at:{},session_execution_version:{},session_status_snapshot_at:void 0,session_error_at:{},session_execution_recovery:{},session_diff:{},todo:{},permission:{},question:{},lsp:[],vcs:void 0,limit:20},wr={ready:!1,path:{state:``,config:``,worktree:``,directory:``,home:``},projects:[],providers:{all:[],connected:[],default:{}},providerAuth:{},config:{},reload:void 0,sessionTodo:{}};function Tr(e,t){return e===void 0||t===void 0?!1:t>e}var Er=class extends Error{};function Dr(e,t,n){if(n===`reconcile-page`)return e??br;let r=0;typeof t.turnCount==`number`&&Number.isFinite(t.turnCount)?r=Math.max(0,Math.floor(t.turnCount)):typeof t.requestedTurnLimit==`number`&&Number.isFinite(t.requestedTurnLimit)?r=Math.max(0,Math.floor(t.requestedTurnLimit)):t.records.length>0&&(r=1);let i=e?.loadedTurns??0,a=n===`prepend`?i+r:r;if(t.complete)return{kind:`exhausted`,loadedTurns:a};let o=typeof t.cursor==`string`&&t.cursor.length>0?t.cursor:void 0;if(!o)throw new Er(`session message page: complete=false requires non-empty cursor`);if(n===`prepend`&&e?.kind===`has-more`&&e.cursor===o)throw new Er(`session message page: prepend returned the same cursor without progress`);if(t.records.length===0&&(n!==`prepend`||e?.kind!==`has-more`||e.cursor===o)&&n!==`initial`)throw new Er(`session message page: complete=false with zero records makes no progress`);return{kind:`has-more`,cursor:o,loadedTurns:a}}function Or(e,t){return!e||!t?e===t:e.kind!==t.kind||e.loadedTurns!==t.loadedTurns?!1:e.kind===`has-more`&&t.kind===`has-more`?e.cursor===t.cursor:!0}function kr(e,t,n,r){let i=Tr(r.capturedRevision,r.liveRevision),a=hn({purpose:r.purpose,stale:i}),o=e.session_history_boundary?.[t];if(!n.ok)return{applied:!1,merge:a,changed:!1,messagesChanged:!1,partsChanged:!1,boundaryChanged:!1,message:e.message,part:e.part,messages:e.message[t]??[],boundary:void 0,meta:void 0,confirmedOptimisticIDs:[],commands:[],error:n.error};if(i&&a.onStale===`drop`){let n=e.message[t]??[];if(n.length>0)return{applied:!1,merge:a,changed:!1,messagesChanged:!1,partsChanged:!1,boundaryChanged:!1,message:e.message,part:e.part,messages:n,boundary:void 0,meta:void 0,confirmedOptimisticIDs:[],commands:[]}}let s=r.optimistic??[],c=yr({session:n.records.map(e=>e.info),part:n.records.map(e=>({id:e.info.id,part:e.parts??[]})),cursor:n.cursor,complete:n.complete},s),l=mr(e,t,c.session.map(e=>({info:e,parts:c.part.find(t=>t.id===e.id)?.part??[]})),{skipPartTypes:r.skipPartTypes,merge:a,placeUnanchoredNewMessages:r.purpose===`prepend`?`prepend`:r.purpose===`reconcile-page`?`by-created`:`append`}),u;try{u=Dr(o,{ok:!0,records:n.records,cursor:c.cursor,complete:c.complete,turnCount:n.turnCount,requestedTurnLimit:n.requestedTurnLimit},r.purpose)}catch(n){if(!(n instanceof Er))throw n;return{applied:!1,merge:a,changed:!1,messagesChanged:!1,partsChanged:!1,boundaryChanged:!1,message:e.message,part:e.part,messages:e.message[t]??[],boundary:void 0,meta:void 0,confirmedOptimisticIDs:[],commands:[],error:n.message}}let d=!Or(o,u),f=l.messagesChanged,p=l.partsChanged,m=f||p||d,h=[];c.confirmed.length>0&&h.push({type:`clear-optimistic`,messageIDs:c.confirmed});let g=d||!o?u:o;return{applied:!0,merge:a,changed:m,messagesChanged:f,partsChanged:p,boundaryChanged:d,message:l.message,part:l.part,messages:l.messages,boundary:g,meta:{limit:g.loadedTurns,cursor:g.kind===`has-more`?g.cursor:void 0,complete:g.kind===`exhausted`},confirmedOptimisticIDs:c.confirmed,commands:h}}var Ar=new Set([`tool`,`reasoning`,`file`,`text`]),jr=new Set([`tool`,`reasoning`,`file`]);function Mr(e){return e.some(e=>A(e)&&Ar.has(e.type))}function Nr(e,t){let n=!1,r=!1;for(let t of e)jr.has(t.type)&&(n=!0,A(t)&&(r=!0));return n?r?!0:t?nn(t):!1:!1}var Pr=e=>{if(!e)return``;let t=e.clientRole??e.role;return typeof t==`string`?t:``};function Fr(e,t){return Ve(e,t)}function Ir(e){let t=0;for(let n of e.messageOrder)Fr(e.messagesByID[n],e.partsByMessageID[n])&&(t+=1);return t}var Lr=(e,t)=>{let n=e.messageOrder.lastIndexOf(t);if(n<0)return[];let r=[];for(let i=n+1;i<e.messageOrder.length;i+=1){let n=e.messageOrder[i],a=e.messagesByID[n];if(!a)continue;if(Fr(a,e.partsByMessageID[n]))break;if(Pr(a)!==`assistant`)continue;let o=a.parentID;typeof o==`string`&&o.length>0&&o!==t||r.push(a)}return r},Rr=(e,t)=>nn(e)?!0:Array.isArray(t)&&t.length>0;function zr(e){let t;for(let n=e.messageOrder.length-1;n>=0;--n){let r=e.messageOrder[n];if(Fr(e.messagesByID[r],e.partsByMessageID[r])){t=r;break}}return t?Lr(e,t).some(t=>Rr(t,e.partsByMessageID[t.id])):!1}function Br(e){return e.materializeActive?`p2`:e.prependActive||e.earlierHistoryLoaded?`p1`:e.p0Satisfied?`p0`:`idle`}var Vr=new Set([`stop`,`length`]);function Hr(e){let t=e.messageOrder[e.messageOrder.length-1];if(!t)return!1;let n=e.messagesByID[t];if(!n||Pr(n)!==`assistant`||n.error)return!1;let r=n.finish;return typeof r!=`string`||!Vr.has(r)?!1:typeof n.time?.completed!=`number`||r===`stop`&&!Ft(n.tokens)}function Ur(e,t){return t.kind===`has-more`?{sessionID:e,boundary:t,hasPreviousPage:!0,isComplete:!1,cursor:t.cursor,loadedTurns:t.loadedTurns}:t.kind===`exhausted`?{sessionID:e,boundary:t,hasPreviousPage:!1,isComplete:!0,cursor:null,loadedTurns:t.loadedTurns}:{sessionID:e,boundary:t,hasPreviousPage:!1,isComplete:!1,cursor:null,loadedTurns:t.loadedTurns}}function Wr(e){let t={},n={},r=[];for(let i of e.messages){if(!i?.id)continue;r.push(i.id),t[i.id]=i;let a=e.parts[i.id];a&&(n[i.id]=a)}return{sessionID:e.sessionID,messageOrder:r,messagesByID:t,partsByMessageID:n,boundary:e.boundary,liveRevision:e.liveRevision??0}}var Gr=`message.updated,message.removed,message.part.updated,message.part.removed,message.part.delta,session.step.started,session.step.streamed,session.shell.started,session.shell.ended,session.step.ended,session.step.failed,session.text.started,session.text.delta,session.text.ended,session.reasoning.started,session.reasoning.delta,session.reasoning.ended,session.tool.input.started,session.tool.input.delta,session.tool.input.ended,session.tool.called,session.tool.progress,session.tool.success,session.tool.failed,session.compaction.started,session.compaction.delta,session.compaction.ended,session.compaction.failed,session.synthetic,session.revert.committed`.split(`,`);function Kr(e){return Gr.includes(e)}function j(e){return e.trim()}function qr(e){return`${j(e.directory)}\n${e.sessionID}`}function Jr(e,t){return e.session_history_boundary?.[t]??br}function Yr(e){return e.filter(e=>!!e?.id)}function Xr(e,t){return e.kind!==t.kind||e.loadedTurns!==t.loadedTurns?!1:e.kind===`has-more`&&t.kind===`has-more`?e.cursor===t.cursor:!0}function Zr(e,t,n){n.applied&&e.setState(e=>{let r={};if(n.messagesChanged&&(r.message=n.message),n.partsChanged&&(r.part=n.part),n.boundary&&(n.boundaryChanged||!e.session_history_boundary?.[t]))r.session_history_boundary={...e.session_history_boundary??{},[t]:n.boundary};else if(n.boundary&&n.boundaryChanged===!1){let i=e.session_history_boundary?.[t];(!i||!Xr(i,n.boundary))&&(r.session_history_boundary={...e.session_history_boundary??{},[t]:n.boundary})}return!r.message&&!r.part&&!r.session_history_boundary&&n.boundary&&(r.session_history_boundary={...e.session_history_boundary??{},[t]:n.boundary}),!r.message&&!r.part&&!r.session_history_boundary?{}:r})}function Qr(e,t,n){let r=e.getState(),i=n.page,a=kr(r,t,{ok:!0,records:i.records.map(e=>({info:e.info,parts:e.parts?[...e.parts]:[]})),cursor:i.cursor,complete:i.complete,turnCount:i.turnCount,requestedTurnLimit:i.requestedTurnLimit},{purpose:n.purpose,skipPartTypes:n.skipPartTypes,optimistic:n.optimistic?n.optimistic.map(e=>({message:e.message,parts:[...e.parts]})):void 0,capturedRevision:n.capturedLiveRevision,liveRevision:n.liveRevision});return a.applied?(Zr(e,t,a),{applied:!0,changed:a.changed,boundary:a.boundary,meta:a.meta,confirmedOptimisticIDs:a.confirmedOptimisticIDs}):{applied:!1,changed:!1,error:a.error}}function $r(e,t){if(t.length===0)return{applied:!1,changed:!1};let n=e.getState(),r={message:{...n.message??{}},part:{...n.part??{}}},i=!1,a=!1,o;for(let e of t){if(!Kr(e.type))continue;i=!0;let t=Vt(r,e),n=typeof t==`boolean`?t:t.changed,s=typeof t==`boolean`?void 0:t.materialization;s&&!o&&(o=s),n&&(a=!0)}return i?a?(e.setState({message:r.message,part:r.part}),{applied:!0,changed:!0,...o?{materialization:o}:{}}):{applied:!0,changed:!1,...o?{materialization:o}:{}}:{applied:!1,changed:!1}}function ei(e,t){return $r(e,[t.event])}function ti(e,t){return $r(e,t.events)}function ni(e,t,n){if(n.records.length===0)return{applied:!1,changed:!1};let r=e.getState(),i=mr({message:r.message??{},part:r.part??{}},t,n.records.map(e=>({info:e.info,parts:e.parts?[...e.parts]:[]})),{skipPartTypes:n.skipPartTypes,merge:n.merge});return!i.messagesChanged&&!i.partsChanged?{applied:!0,changed:!1}:(e.setState({...i.messagesChanged?{message:i.message}:{},...i.partsChanged?{part:i.part}:{}}),{applied:!0,changed:!0})}function ri(e,t,n){let r=e.getState(),i=r.message?.[t],a=r.part?.[n]!==void 0;if(!i&&!a)return{applied:!0,changed:!1};let o={...r.message??{}},s=!1;if(i){let e=[...i],r=e.findIndex(e=>e.id===n);r>=0&&(e.splice(r,1),o[t]=e,s=!0)}let c={...r.part??{}},l=!1;return c[n]!==void 0&&(delete c[n],l=!0),!s&&!l?{applied:!0,changed:!1}:(e.setState({...s?{message:o}:{},...l?{part:c}:{}}),{applied:!0,changed:!0})}function ii(e,t,n,r,i){r.setOptimisticShadow?.({directory:i,sessionID:t,message:n.message,parts:n.parts});let a=e.getState(),o={...a.message??{}},s={...a.part??{}},c=o[t]?[...o[t]]:[];return c.some(e=>e.id===n.message.id)||c.push(n.message),o[t]=c,s[n.message.id]=Yr(n.parts),e.setState({message:o,part:s}),{applied:!0,changed:!0}}function ai(e,t,n,r,i){r.clearOptimisticShadow?.({directory:i,sessionID:t,messageID:n});let a=e.getState(),o={...a.message??{}},s={...a.part??{}},c=!1,l=o[t];if(l){let e=[...l],r=e.findIndex(e=>e.id===n);r>=0&&(e.splice(r,1),o[t]=e,c=!0)}return s[n]!==void 0&&(delete s[n],c=!0),c&&e.setState({message:o,part:s}),{applied:!0,changed:c}}function oi(e,t,n,r){return n.clearOptimisticShadow?.({directory:r,sessionID:e,messageID:t}),{applied:!0,changed:!1}}function si(e,t){let n=e.getState(),r=n.message?.[t],i=n.session_history_boundary?.[t],a=!!(r&&r.length>0),o=i!==void 0,s=new Set;if(r)for(let e of r)e?.id&&s.add(e.id);let c=!1,l={...n.part??{}};for(let e of s)l[e]!==void 0&&(delete l[e],c=!0);for(let[e,n]of Object.entries(l))s.has(e)||n?.some(e=>e.sessionID===t)&&(delete l[e],c=!0);if(!a&&!o&&!c)return!1;let u={...n.message??{}};delete u[t];let d={...n.session_history_boundary??{}};return delete d[t],e.setState({message:u,part:l,session_history_boundary:d}),!0}function ci(e,t,n){let r=si(e,t);if(!n.page)return{applied:!0,changed:r};let i=Qr(e,t,{type:`http-page`,purpose:`initial`,page:n.page,capturedLiveRevision:n.capturedLiveRevision,liveRevision:n.liveRevision,skipPartTypes:n.skipPartTypes});return{...i,changed:r||i.changed,applied:i.applied||r}}function li(e){let t=new Map,n=new Map,r=r=>{let i=qr(r);if(n.has(i))return;let a=j(r.directory),o=e.getStore(a),s=r.sessionID,c=o.getState().message?.[s],l=Jr(o.getState(),s),u=new Map;for(let e of c??[])u.set(e.id,o.getState().part?.[e.id]);let d=o.subscribe(e=>{let n=e.message?.[s],a=Jr(e,s),o=!1,d=new Map;for(let t of n??[]){let n=e.part?.[t.id];d.set(t.id,n),u.get(t.id)!==n&&(o=!0)}u.size!==d.size&&(o=!0);let f=n!==c,p=Xr(a,l);if(c=n,l=a,u=d,!f&&!o&&p)return;let m=t.get(i);if(!(!m||m.size===0))for(let e of m)e(r)});n.set(i,d)},i=e=>{let r=t.get(e);if(r&&r.size>0)return;let i=n.get(e);i&&(i(),n.delete(e)),t.delete(e)},a={getTranscript(t){let n=j(t.directory),r=e.getStore(n).getState(),i=t.sessionID,a=r.message?.[i]??[],o=e.getLiveRevision?.(n,i)??0;return Wr({sessionID:i,messages:a,parts:r.part??{},boundary:Jr(r,i),liveRevision:o})},getPagination(t){let n=j(t.directory),r=e.getStore(n).getState();return Ur(t.sessionID,Jr(r,t.sessionID))},getRequestState(t){let n=j(t.directory);return e.getRequestState?.(n,t.sessionID)??{sessionID:t.sessionID,status:`idle`}},getHydrationState(e){let t=a.getTranscript(e),n=zr(t);return{sessionID:e.sessionID,p0Satisfied:n,phase:Br({p0Satisfied:n,earlierHistoryLoaded:Ir(t)>1})}},getMessage(e,t){return a.getTranscript(e).messagesByID[t]},getParts(t,n){let r=j(t.directory);return e.getStore(r).getState().part?.[n]??[]},hasSession(t){let n=j(t.directory),r=e.getStore(n).getState().message;return r?Object.prototype.hasOwnProperty.call(r,t.sessionID):!1},apply(t,n){let r=j(t.directory),i=e.getStore(r),a=t.sessionID;switch(n.type){case`http-page`:return Qr(i,a,n);case`sse-event`:return ei(i,n);case`sse-event-batch`:return ti(i,n);case`optimistic-add`:return ii(i,a,n,e,r);case`optimistic-confirm`:return oi(a,n.messageID,e,r);case`optimistic-remove`:return ai(i,a,n.messageID,e,r);case`reset`:return ci(i,a,n);case`materialize-snapshots`:return ni(i,a,n);case`remove-message`:return ri(i,a,n.messageID);case`revert-committed`:{let e=i.getState(),t=e.message?.[a];if(!Array.isArray(t)||t.length===0)return{applied:!0,changed:!1};let r=t.findIndex(e=>e.id===n.to);if(r<0)return{applied:!0,changed:!1};let o=t.slice(r),s=t.slice(0,r),c={...e.message??{}};c[a]=s;let l={...e.part??{}};for(let e of o)delete l[e.id];return i.setState({message:c,part:l}),{applied:!0,changed:o.length>0}}default:return{applied:!1,changed:!1}}},subscribe(e,n){let a=qr(e),o=t.get(a);return o||(o=new Set,t.set(a,o)),o.add(n),r(e),()=>{let e=t.get(a);e&&(e.delete(n),i(a))}}};return a}var ui=new Set,di=new Set;function fi(e,t){return`${e}\n${t}`}function pi(){for(let e of di)e()}function mi(e,t){!e||!t||(ui.add(fi(e,t)),pi())}function hi(e,t){!e||!t||ui.delete(fi(e,t))&&pi()}function gi(e,t){if(!e)return!1;if(t)return ui.has(fi(t,e));let n=`\n${e}`;for(let e of ui)if(e.endsWith(n))return!0;return!1}function _i(e){return di.add(e),()=>{di.delete(e)}}var vi=[],yi=new Map,bi=new Map,xi=0,Si=()=>{let e=vi.findIndex(e=>e.priority===`user`);if(e>=0){let[t]=vi.splice(e,1);return t}return vi.shift()},Ci=()=>{for(;xi<4;){let e=Si();if(!e)return;yi.delete(e.key),xi+=1,Promise.resolve().then(()=>e.run()).then(t=>{e.resolve(t)},t=>{e.reject(t)}).finally(()=>{--xi,bi.delete(e.key),Ci()})}};function wi(e,t,n){let r=n?.priority??`background`,i=bi.get(e);if(i){let t=yi.get(e);return t&&r===`user`&&t.priority!==`user`&&(t.priority=`user`),i}let a,o,s=new Promise((e,t)=>{a=e,o=t}),c={key:e,priority:r,run:()=>t(),resolve:e=>{a(e)},reject:o};return vi.push(c),yi.set(e,c),bi.set(e,s),Ci(),s}var Ti=null,Ei=0,Di=new Set;function Oi(){Ei+=1;for(let e of Di)e()}function ki(e){return e}function Ai(e){return Di.add(e),()=>{Di.delete(e)}}function ji(){return Ei}function Mi(e){return Ti?.repository===e?e:(Ti={kind:`query`,repository:e},Oi(),e)}function Ni(){Ti&&(Ti=null,Oi())}function M(){return Ti?.repository??null}function Pi(){let e=M();if(!e)throw Error(`TranscriptRepository is not bound — SyncProvider must mount first`);return e}function Fi(e,t){let n=M();if(n)return n;let r=ki(t);return li({getStore:e=>r})}function N(e,t,n){return{directory:e.trim(),sessionID:t,...n?.transport===void 0?{}:{transport:n.transport},...n?.generation===void 0?{}:{generation:n.generation}}}function Ii(e){try{let t=M(),n=o(),r=s();return t?.getCacheBudget?.().listCanonicalScopesForSession(e,{transport:n,generation:r})?.map(e=>N(e.directory,e.sessionID,{transport:e.transport,generation:e.generation}))??[]}catch{return[]}}function Li(e,t){let n=M();return n?n.apply(e,t):null}async function Ri(e,t,n){let r=Pi();if(typeof r.fetchPreviousPage!=`function`)throw Error(`TranscriptRepository does not support fetchPreviousPage`);await r.fetchPreviousPage(N(e,t),n)}async function zi(e,t){let n=Pi();if(typeof n.ensureInitial!=`function`)throw Error(`TranscriptRepository does not support ensureInitial`);await n.ensureInitial(N(e,t))}async function Bi(e,t){let n=Pi(),r=N(e,t);if(typeof n.destructiveReset==`function`){await n.destructiveReset(r);return}if(typeof n.ensureInitial!=`function`)throw Error(`TranscriptRepository does not support retryInitial`);await n.ensureInitial(r)}async function Vi(e,t,n){let r=Pi();if(typeof r.refreshFromAuthority!=`function`)throw Error(`TranscriptRepository does not support refreshFromAuthority`);if(n?.background){await r.refreshFromAuthority(N(e,t));return}mi(e,t);try{await r.refreshFromAuthority(N(e,t))}finally{hi(e,t)}}async function Hi(e,t,n,r){let i=Pi();if(typeof i.materializeMessage!=`function`)throw Error(`TranscriptRepository does not support materializeMessage`);let a=N(e,t);await wi(`${e}\n${t}\n${n}`,()=>i.materializeMessage(a,n),{priority:r?.priority??`background`})}function Ui(e,t,n){let r=M();return!r||typeof r.getMessageMaterializationState!=`function`?{sessionID:t,messageID:n,status:`idle`}:r.getMessageMaterializationState(N(e,t),n)}function Wi(e,t){M()?.purgeSession?.(N(e,t))}var P=null;function Gi(e){P&&P!==e&&P.cancelAll(`reregister`),P=e}function Ki(e){P?.captureCheckpoints(e)}function qi(e){P?.onCompensation(e)}async function Ji(e){return P?P.ensureOnObserve(e):null}function Yi(e){P?.cancelAll(e)}var Xi=e=>typeof e==`number`&&Number.isFinite(e)?e:0,Zi=e=>Xi(e.input)+Xi(e.output)+Xi(e.reasoning)+Xi(e.cache?.read)+Xi(e.cache?.write),Qi=e=>e?.type===`compaction`,$i=e=>!!e&&e.some(Qi),ea=(e,t)=>e.clientRole===`compaction`||e.type===`compaction`||$i(t),ta=(e,t)=>{for(let n=e.length-1;n>=0;--n){let r=e[n],i=r.id?t(r.id):void 0;if(ea(r,i)){let e=i?.find(Qi)?.status??r.status;if(e===`running`||e===`failed`)continue;return{compacted:!0}}if(r.role!==`assistant`)continue;let a=r.tokens;if(!a)continue;let o=Zi(a);if(o>0)return{messageId:r.id??``,totalTokens:o,tokens:a}}return null},na=(e,t,n)=>{if(!e)return null;let r=`compacted`in e,i=r?0:e.totalTokens;return{...r?{pending:!0}:{},totalTokens:i,percentage:t>0?Math.round(i/t*100):0,contextLimit:t||0,outputLimit:n||void 0,normalizedOutput:!r&&n>0?Math.round(Xi(e.tokens.output)/n*100):void 0,thresholdLimit:t>0?t:2e5,lastMessageId:r?void 0:e.messageId}},ra=[],ia=[],aa={sessionID:``,messageOrder:[],messagesByID:{},partsByMessageID:{},boundary:br,liveRevision:0};Ur(``,br);var oa={sessionID:``,phase:`idle`,p0Satisfied:!1};function F(e,t){return Fi(e,t)}var sa=new Set;function ca(e,t){return`${e}\n${t}`}function la(e,t){if(!t)return;let n=ca(e,t);sa.has(n)||(sa.add(n),Ji(N(e,t)).catch(()=>{}).finally(()=>{sa.delete(n)}))}function ua(e,t){if(e&&t){sa.delete(ca(e,t));return}sa.clear()}function da(e,t,n,r,i=Object.is,a){let o=(0,b.useRef)(r);o.current=r;let s=(0,b.useRef)(i);s.current=i;let c=(0,b.useRef)(void 0),l=(0,b.useRef)(null),u=a?.enabled!==!1,d=(0,b.useMemo)(()=>()=>{let r=ji(),i=e&&u?F(t,n):null,a=i?.getTranscript(N(t,e))??aa,d=i?.hasSession?.(N(t,e)),f=o.current,p=s.current,m=l.current;if(m?.data===a&&m.select===f&&m.isEqual===p&&m.repository===i&&m.bindingRevision===r&&m.directory===t&&m.sessionID===e&&m.enabled===u&&m.resolved===d)return c.current;let h=f(a);return(c.current===void 0||!p(c.current,h))&&(c.current=h),l.current={data:a,select:f,isEqual:p,repository:i,bindingRevision:r,directory:t,sessionID:e,enabled:u,resolved:d},c.current},[t,u,e,n]),f=(0,b.useMemo)(()=>r=>{if(!e||!u)return()=>void 0;la(t,e);let i=F(t,n).subscribe(N(t,e),()=>{r()}),a=Ai(()=>{i(),c.current=void 0,l.current=null,ua(t,e),la(t,e),i=F(t,n).subscribe(N(t,e),()=>{r()}),r()});return()=>{a(),i()}},[t,u,e,n]);return b.useSyncExternalStore(f,d,d)}function fa(e,t,n,r,i,a){return da(e,t,n,r,i===void 0?Object.is:i,a)}function pa(e,t){if(e.messageOrder.length===0)return ra;if(t&&t.length>0){let n=!0,r=0;for(let i of e.messageOrder){let a=e.messagesByID[i];if(a){if(r>=t.length||t[r]!==a){n=!1;break}r+=1}}if(n&&r===t.length)return t}let n=[];for(let t of e.messageOrder){let r=e.messagesByID[t];r&&n.push(r)}return n}function ma(e,t){return e.messageOrder.length===0?t?.resolved===!0?gr({messages:ra,parts:e.partsByMessageID}):{hasMessages:!1,renderable:!1,missingPartMessageIDs:[]}:gr({messages:pa(e),parts:e.partsByMessageID})}var ha=(e,t)=>e.hasMessages===t.hasMessages&&e.renderable===t.renderable&&e.missingPartMessageIDs.length===t.missingPartMessageIDs.length&&e.missingPartMessageIDs.every((e,n)=>e===t.missingPartMessageIDs[n]);function ga(e,t,n,r){let i=(0,Se.c)(4),a;return i[0]!==t||i[1]!==e||i[2]!==n?(a=r=>{if(!e)return{hasMessages:!1,renderable:!1,missingPartMessageIDs:[]};let i=F(t,n).hasSession?.(N(t,e));return ma(r,{resolved:i===!0||void 0})},i[0]=t,i[1]=e,i[2]=n,i[3]=a):a=i[3],da(e,t,n,a,ha,r)}function _a(e,t,n,r,i){let a=(0,Se.c)(3),o;return a[0]!==r||a[1]!==i?(o=e=>na(ta(pa(e),t=>e.partsByMessageID[t]),r,i),a[0]=r,a[1]=i,a[2]=o):o=a[2],da(e,t,n,o,va)}function va(e,t){return e===t||!!(e&&t&&e.pending===t.pending&&e.totalTokens===t.totalTokens&&e.percentage===t.percentage&&e.contextLimit===t.contextLimit&&e.outputLimit===t.outputLimit&&e.normalizedOutput===t.normalizedOutput&&e.lastMessageId===t.lastMessageId)}var ya=(e,t)=>{if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(e[n]!==t[n])return!1;return!0};function ba(e,t,n,r){return da(e,t,n,pa,ya,r)}function xa(e,t){if(e===t)return!0;if(e.sessionID!==t.sessionID||e.liveRevision!==t.liveRevision||e.boundary.kind!==t.boundary.kind||e.boundary.loadedTurns!==t.boundary.loadedTurns||e.boundary.kind===`has-more`&&t.boundary.kind===`has-more`&&e.boundary.cursor!==t.boundary.cursor||e.messageOrder.length!==t.messageOrder.length)return!1;for(let n=0;n<e.messageOrder.length;n+=1){let r=e.messageOrder[n];if(r!==t.messageOrder[n]||e.messagesByID[r]!==t.messagesByID[r]||e.partsByMessageID[r]!==t.partsByMessageID[r])return!1}return!0}function Sa(e,t,n,r){return da(e,t,n,Ca,xa,r)}function Ca(e){return e}function wa(e,t,n,r){if(e.length===0)return()=>void 0;let i=[],a=()=>{for(let e of i)e();i=[]},o=()=>{let r=new Set;for(let a of e){let e=`${a.directory}\n${a.sessionID}`;if(r.has(e))continue;r.add(e);let o=M();if(o){i.push(o.subscribe(N(a.directory,a.sessionID),t));continue}let s=n?.(a.directory);if(!s)continue;let c=Fi(a.directory,s);i.push(c.subscribe(N(a.directory,a.sessionID),t))}},s=()=>{a(),o(),t()};o();let c=Ai(s),l=r?.subscribeRebuild?.(s);return()=>{l?.(),c(),a()}}function Ta(e,t){return e.length===0?``:e.map(e=>{let n=La(e.directory,e.sessionID,t?.(e.directory)),r=n[n.length-1];return`${e.sessionID}:${r?.id??``}:${r?.role??``}:${r?.time?.completed??``}`}).join(`\0`)}function Ea(e,t,n){return da(e,t,n,Da)}function Da(e){return e.messageOrder.length}function Oa(e,t,n){let r=(0,Se.c)(8),i=(0,b.useRef)(!1),a;r[0]!==t||r[1]!==e||r[2]!==n?(a=()=>{if(!e)return i.current=!1,!1;let r=F(t,n),a=r.hasSession?.(N(t,e))??r.getTranscript(N(t,e)).messageOrder.length>0;return i.current=a,i.current},r[0]=t,r[1]=e,r[2]=n,r[3]=a):a=r[3];let o=a,s;r[4]!==t||r[5]!==e||r[6]!==n?(s=r=>e?F(t,n).subscribe(N(t,e),()=>{r()}):ka,r[4]=t,r[5]=e,r[6]=n,r[7]=s):s=r[7];let c=s;return b.useSyncExternalStore(c,o,o)}function ka(){}function Aa(e,t,n,r){let i=(0,Se.c)(10),a=(0,b.useRef)(void 0),o;i[0]!==t||i[1]!==e||i[2]!==r||i[3]!==n?(o=()=>{if(!e)return a.current=ia,ia;let i=F(t,n),o=r||e,s=i.getParts(N(t,o),e),c=s.length===0?ia:s;if(a.current===void 0||a.current!==c){if(a.current&&a.current.length===c.length&&a.current.every((e,t)=>e===c[t]))return a.current;a.current=c}return a.current},i[0]=t,i[1]=e,i[2]=r,i[3]=n,i[4]=o):o=i[4];let s=o,c;i[5]!==t||i[6]!==e||i[7]!==r||i[8]!==n?(c=i=>{if(!e)return Ma;let a=F(t,n);return r?a.subscribe(N(t,r),()=>{i()}):ja},i[5]=t,i[6]=e,i[7]=r,i[8]=n,i[9]=c):c=i[9];let l=c;return b.useSyncExternalStore(l,s,s)}function ja(){}function Ma(){}function Na(e,t,n){let r=(0,Se.c)(8),i=(0,b.useRef)(oa),a;r[0]!==t||r[1]!==e||r[2]!==n?(a=()=>{if(!e)return i.current!==oa&&(i.current=oa),i.current;let r=F(t,n).getHydrationState?.(N(t,e))??{sessionID:e,phase:`idle`,p0Satisfied:!1},a=i.current;return a.sessionID===r.sessionID&&a.phase===r.phase&&a.p0Satisfied===r.p0Satisfied?a:(i.current=r,r)},r[0]=t,r[1]=e,r[2]=n,r[3]=a):a=r[3];let o=a,s;r[4]!==t||r[5]!==e||r[6]!==n?(s=r=>{if(!e)return Pa;la(t,e);let a=F(t,n).subscribe(N(t,e),()=>{r()}),o=Ai(()=>{a(),i.current=oa,ua(t,e),la(t,e),a=F(t,n).subscribe(N(t,e),()=>{r()}),r()});return()=>{o(),a()}},r[4]=t,r[5]=e,r[6]=n,r[7]=s):s=r[7];let c=s;return b.useSyncExternalStore(c,o,o)}function Pa(){}function Fa(e,t,n){let r=(0,Se.c)(2),i;return r[0]===e?i=r[1]:(i=t=>Ur(e,t.boundary),r[0]=e,r[1]=i),da(e,t,n,i,Ia)}function Ia(e,t){return e.sessionID===t.sessionID&&e.hasPreviousPage===t.hasPreviousPage&&e.isComplete===t.isComplete&&e.cursor===t.cursor&&e.loadedTurns===t.loadedTurns&&e.boundary.kind===t.boundary.kind&&e.boundary.loadedTurns===t.boundary.loadedTurns&&(e.boundary.kind!==`has-more`||t.boundary.kind!==`has-more`||e.boundary.cursor===t.boundary.cursor)}function La(e,t,n){if(!t)return[];let r=M();if(r){let n=r.getTranscript(N(e,t));return n.messageOrder.map(e=>n.messagesByID[e]).filter(e=>!!e)}if(!n)return[];let i=Fi(e,n).getTranscript(N(e,t));return i.messageOrder.map(e=>i.messagesByID[e]).filter(e=>!!e)}var I=null,Ra=``,za=null,Ba=new Set,Va=null,Ha=new Map,Ua=new Map;function Wa(e,t,n,r){I=t,Va!==t&&(Va=null,Ha=new Map,Ua=new Map),Ra=n,r&&(za=r)}function Ga(e,t){za?.(e,t)}function Ka(){if(!I)throw Error(`ChildStoreManager not initialized — is SyncProvider mounted?`);return I}function qa(e){let t=I;if(!t)return;let n=e||Ra;if(n)return t.getState(n)}function Ja(e){let t=qa(e)?.config;return t&&Object.keys(t).length>0?t:void 0}function Ya(e){return Ba.add(e),()=>{Ba.delete(e)}}function Xa(e,t){if(e)for(let n of Ba)n(e,t)}function Za(e){return qa(e)?.session??[]}function Qa(){return Array.from($a().values())}function $a(){let e=I;if(!e)return Ua;let t=Va!==e||Ha.size!==e.children.size;for(let[n,r]of e.children)if(Ha.get(n)!==r.getState().session){t=!0;break}if(!t)return Ua;let n=new Map,r=new Map;for(let[t,i]of e.children){let e=i.getState().session;n.set(t,e);for(let t of e)t?.id&&r.set(t.id,t)}return Va=e,Ha=n,Ua=r,Ua}function eo(e,t,n){if(n){let r=[];for(let[i,a]of n)if(a.session.some(t=>t.id===e)&&a.hasTranscript===!0){if(i===t)return i;r.push(i)}return r.length===1?r[0]:void 0}let r=[];try{let n=M();if(I){for(let[i,a]of I.children)if(a.getState().session.some(t=>t.id===e)&&(n??Fi(i,a)).hasSession?.(N(i,e))){if(i===t)return i;r.push(i)}}if(r.length===0&&n){let i=n.getCacheBudget?.().listCanonical();if(i){for(let n of i)if(n.scope.sessionID===e){if(n.scope.directory===t)return n.scope.directory;r.push(n.scope.directory)}}}}catch{}let i=[...new Set(r)];return i.length===1?i[0]:void 0}function to(e,t){if(!e)return[];try{let n=M(),r=t??Ra;if(n){let t=n.getTranscript(N(r,e));return t.messageOrder.map(e=>t.messagesByID[e]).filter(e=>!!e)}if(I){let t=I.getChild(r);if(t){let n=Fi(r,t).getTranscript(N(r,e));return n.messageOrder.map(e=>n.messagesByID[e]).filter(e=>!!e)}}}catch{}return[]}function no(e,t){if(!e)return[];try{let n=M(),r=t??Ra;if(n)return[...n.getParts(N(r,e),e)];if(I){let t=I.getChild(r);if(t)return[...Fi(r,t).getParts(N(r,e),e)]}}catch{}return[]}var L=e=>{if(typeof e!=`string`)return;let t=e.trim();return t.length>0?t:void 0},ro=`default`;function io(e){let t=L(e);if(t&&t!==ro)return t}function ao(e){let t=e?.model;return L(t?.id)??L(t?.modelID)}function oo(e){let t=e?.model;return L(t?.providerID)}function so(e){let t=e?.model;return io(t?.variant)}function co(e){let t=io(e.variant);return{id:e.modelID.trim(),providerID:e.providerID.trim(),...t?{variant:t}:{}}}function lo(e,t,n){let r=L(n.providerID),i=L(n.modelID);if(!r||!i)return{agent:L(n.agent)};let a=(qa(t)?.session??Qa()).find(t=>t.id===e),o=co({providerID:r,modelID:i,variant:n.variant}),s=ao(a),c=oo(a),l=so(a),u=io(o.variant),d=!a||!s||!c||c!==o.providerID||s!==o.id||l!==u,f=L(n.agent),p=L(a?.agent);return{model:d?o:void 0,agent:f&&p!==f?f:void 0}}function uo(e,t,n){if(e&&!(!n.model&&!n.agent))try{let r=Ka(),i=typeof t==`string`&&t.length>0?t:void 0;if(!i)return;let a=r.getChild?.(i)??r.ensureChild?.(i,{bootstrap:!1});if(!a?.getState||!a?.setState)return;a.setState(t=>{let r=t.session;if(!Array.isArray(r))return t;let i=r.findIndex(t=>t.id===e);if(i<0)return t;let a=r[i];if(!a)return t;let o=n.model?{id:n.model.id??n.model.modelID??``,providerID:n.model.providerID,...n.model.variant?{variant:n.model.variant}:{}}:a.model,s={...a,...n.model&&o?.id&&o.providerID?{model:o}:{},...n.agent?{agent:n.agent}:{}};if(s===a)return t;let c=r.slice();return c[i]=s,{...t,session:c}})}catch{}}var fo=new Set([`image/heic`,`image/heif`]),po=!1,mo=()=>{let e=globalThis.window?.Capacitor;return e&&typeof e==`object`?e:null},ho=e=>fo.has((e.type||``).toLowerCase()),go=async e=>{let t=new Uint8Array(await e.arrayBuffer()),n=``,r=32768;for(let e=0;e<t.byteLength;e+=r){let i=t.subarray(e,Math.min(e+r,t.byteLength));n+=String.fromCharCode(...i)}return btoa(n)},_o=(e,t)=>{let n=atob(e),r=new Uint8Array(n.length);for(let e=0;e<n.length;e++)r[e]=n.charCodeAt(e);return new Blob([r],{type:t})},vo=async e=>{if(!ho(e)||po)return null;let t=mo();if(!t||typeof t.isNativePlatform!=`function`||!t.isNativePlatform())return null;let n=t.Plugins?.YuriMedia?.transcode;if(typeof n!=`function`)return null;try{let t=await n({data:await go(e),mime:e.type.toLowerCase(),quality:.9});if(typeof t?.data!=`string`||!t.data)return null;let r=typeof t.mime==`string`&&t.mime?t.mime:`image/jpeg`;return _o(t.data,r)}catch(e){return po=!0,console.warn(`Native HEIC transcode failed`,e),null}},yo=e=>e.trim().toLowerCase(),bo=e=>e.source===`local`||e.source===`server`||e.source===`vscode`,xo=(e,t)=>{if(!e||!e.includes(`[`)||t.length===0)return[];let n=new Set(t.map(yo)),r=[],i=0;for(;i<e.length;){let t=e.indexOf(`[`,i);if(t===-1)break;let a=e.indexOf(`]`,t+1);if(a===-1)break;if(e[a+1]!==`(`){let i=se(e.slice(t+1,a)).trim();n.has(yo(i))&&r.push({start:t,end:a+1})}i=a+1}return r},So=(e,t)=>{let n=t.start,r=t.end;return r<e.length&&/\s/.test(e[r])?r+=1:n>0&&/\s/.test(e[n-1])&&--n,{start:n,end:r}},Co=(e,t,n,r)=>{let i=xo(e,t);if(i.length===0)return{text:e,mentions:[...n],composerReferences:r===void 0?void 0:[...r],changed:!1};let a=e,o=[...n],s=r===void 0?[]:[...r];for(let e=i.length-1;e>=0;--e){let{start:t,end:n}=So(a,i[e]),r=n-t;a=`${a.slice(0,t)}${a.slice(n)}`,o=o.flatMap(e=>e.range.end<=t?[e]:e.range.start>=n?[{...e,range:{start:e.range.start-r,end:e.range.end-r}}]:[]),s=s.flatMap(e=>e.end<=t?[e]:e.start>=n?[{...e,start:e.start-r,end:e.end-r}]:[])}return{text:a,mentions:o,composerReferences:r===void 0?void 0:s,changed:!0}},wo=new Set([`image`,`screenshot`,`screen-shot`,`clipboard`,`pasted-image`,`pastedimage`,`untitled`,`unknown`,`file`,`blob`]),To={"image/avif":`avif`,"image/bmp":`bmp`,"image/gif":`gif`,"image/heic":`heic`,"image/heif":`heif`,"image/jpeg":`jpg`,"image/jpg":`jpg`,"image/png":`png`,"image/svg+xml":`svg`,"image/tiff":`tiff`,"image/webp":`webp`},Eo=e=>e.trim().toLowerCase(),Do=e=>e.charCodeAt(0)<32||`<>:"/\\|?*[]`.includes(e),Oo=e=>{let t=e.replace(/\\/g,`/`).split(`/`).pop()??``;return Array.from(t).map(e=>Do(e)?`-`:e).join(``).replace(/\s+/g,` `).replace(/-+/g,`-`).trim()},ko=e=>To[e?.trim().toLowerCase()??``]??`png`,Ao=e=>{let t=Oo(e.name),n=ko(e.type),r=t.lastIndexOf(`.`);if(r>0&&r<t.length-1){let e=t.slice(r+1).toLowerCase();if(/^[a-z0-9]{1,10}$/.test(e))return{base:t.slice(0,r).trim()||`image`,ext:e}}return{base:t.trim()||`image`,ext:n}},jo=e=>{let{base:t}=Ao({name:e}),n=t.trim().toLowerCase().replace(/[\s_]+/g,`-`).replace(/-+/g,`-`).replace(/^-|-$/g,``);if(wo.has(n))return!0;let r=n.replace(/-\(\d+\)$/g,``);return r!==n&&wo.has(r)?!0:/^(image|file|unknown|untitled|blob)-\d+$/.test(n)},Mo=(e,t)=>`${e}.${t}`,No=(e,t,n)=>{let r=Mo(e,t);if(!n.has(Eo(r)))return r;for(let r=2;r<2**53-1;r+=1){let i=Mo(`${e}-${r}`,t);if(!n.has(Eo(i)))return i}return Mo(`${e}-${Date.now()}`,t)},Po=(e,t)=>{for(let n=1;n<2**53-1;n+=1){let r=Mo(`image-${n}`,e);if(!Array.from(t).some(e=>e.startsWith(`image-${n}.`))&&!t.has(Eo(r)))return r}return Mo(`image-${Date.now()}`,e)},Fo=(e,t)=>{let n=new Set(t.map(Eo));return e.map(e=>{let{base:t,ext:r}=Ao(e),i=jo(Mo(t,r))?Po(r,n):No(t,r,n);return n.add(Eo(i)),i})},Io=e=>e.map(e=>oe(e)).join(` `),Lo=(e,t,n)=>{if(t===n)return[];let r=[];for(let i of e){let e=[oe(i),`[${i}]`],a=e.some(e=>t.includes(e)),o=e.some(e=>n.includes(e));a&&!o&&r.push(i)}return r},Ro=(e,t)=>{if(t.length>=e.length)return null;let n=0,r=Math.min(e.length,t.length);for(;n<r&&e[n]===t[n];)n+=1;let i=0;for(;i<e.length-n&&i<t.length-n&&e[e.length-1-i]===t[t.length-1-i];)i+=1;let a=e.length-i;return t.length-i!==n||a<=n?null:{start:n,end:a}},zo=(e,t,n)=>{if(e===t||n.length===0)return null;let r=[...n],i=Ro(e,t);if(i){let t=Xo(e,r,{key:`Backspace`,selectionStart:i.start,selectionEnd:i.end});if(t)return t}let a=Lo(r,e,t);return a.length===0?null:{text:t,caret:t.length,removedFilenames:a}},Bo=e=>e.replaceAll(`[${ue}`,`[`),Vo=/\.(?:png|jpe?g|gif|webp|svg|avif|bmp|heic|heif|tiff?)$/i,Ho=e=>{let t=e.trim();return t.startsWith(`/`)||/^[A-Za-z]:[\\/]/.test(t)||t.startsWith(`\\\\`)},Uo=(e,t)=>{let n=e;for(let e of t){let t=e.filename.trim(),r=e.path.trim();if(!t||!r||t===r||Ho(t)||!Vo.test(t)&&!Vo.test(r))continue;let i=`[${r}]`;n=n.split(oe(t)).join(i).split(`[${t}]`).join(i)}return n},Wo=(e,t)=>{let n=e;for(let e of t??[]){if(e.source!==`vscode`||e.vscodeSource!==`selection`||!e.vscodePath)continue;let t=e.filename.match(/:(\d+(?:-\d+)?)$/)?.[1];if(!t)continue;let r=`[${e.vscodePath}:${t}]`;n=n.split(oe(e.filename)).join(r).split(`[${e.filename}]`).join(r)}return n},Go=e=>e.mime===`text/plain`&&typeof e.filename==`string`&&/:\d+(?:-\d+)?$/.test(e.filename),Ko=`application/x-directory`,qo=e=>typeof e==`string`&&e.trim().toLowerCase()===`application/x-directory`,Jo=e=>typeof e==`string`&&/[/\\]$/.test(e.trim()),Yo=(e,t,n)=>{if(t===`Backspace`){let t=n;for(;t>0&&/\s/.test(e[t-1]);)--t;for(;t>0&&!/\s/.test(e[t-1]);)--t;return{start:t,end:n}}let r=n;for(;r<e.length&&/\s/.test(e[r]);)r+=1;for(;r<e.length&&!/\s/.test(e[r]);)r+=1;return{start:n,end:r}},Xo=(e,t,n)=>{let r=Math.max(0,Math.min(n.selectionStart,e.length)),i=Math.max(r,Math.min(n.selectionEnd,e.length)),a;if(a=r===i?n.altKey?Yo(e,n.key,r):n.key===`Backspace`?{start:Math.max(0,r-1),end:r}:{start:r,end:Math.min(e.length,r+1)}:{start:r,end:i},a.start===a.end)return null;let o=xo(e,t).filter(e=>e.start<a.end&&e.end>a.start);if(o.length===0)return null;let s=Math.min(a.start,...o.map(e=>e.start)),c=Math.max(a.end,...o.map(e=>e.end));return c<e.length&&/\s/.test(e[c])&&(s===0||/\s/.test(e[s-1]))?c+=1:c===e.length&&s>0&&/\s/.test(e[s-1])&&--s,{text:`${e.slice(0,s)}${e.slice(c)}`,caret:s,removedFilenames:o.map(t=>se(e.slice(t.start+1,t.end-1)).trim())}},Zo=`<system-reminder>`,Qo=`</system-reminder>`,$o=/[ \t]*<system-reminder>[\s\S]*?<\/system-reminder>[ \t]*/g,es=/[ \t]*<system-reminder>[\s\S]*$/,ts=e=>{let t=e.trim();return t?t.startsWith(Zo)&&t.endsWith(Qo)?t:`${Zo}\n${t}\n${Qo}`:``},ns=e=>e.includes(Zo)?e.replace($o,``).replace(es,``).trim():e,rs=class extends Error{status;code;constructor(e,t,n=`Failed to upload prompt attachment`){super(n),this.name=`PromptAttachmentUploadError`,this.status=e,this.code=t}},is=`file://`,as=e=>{let t=e.trim();if(t.toLowerCase().startsWith(is))return t;let n=fe(t).split(`/`).map(e=>/^[A-Za-z]:$/.test(e)?e:encodeURIComponent(e)).join(`/`);return/^[A-Za-z]:/.test(n)?`${is}/${n}`:`${is}${n}`},os=e=>{let t=e.trim();if(!t.toLowerCase().startsWith(is))return t;let n=t.slice(7);n.toLowerCase().startsWith(`localhost/`)&&(n=n.slice(9));let r=n.split(`/`).map(e=>{if(/^[A-Za-z]:$/.test(e))return e;try{return decodeURIComponent(e)}catch{return e}}).join(`/`);return/^\/[A-Za-z]:/.test(r)?r.slice(1):r},ss=async e=>[...new Uint8Array(await crypto.subtle.digest(`SHA-256`,await e.arrayBuffer()))].map(e=>e.toString(16).padStart(2,`0`)).join(``),cs=e=>typeof e==`object`&&!!e&&!Array.isArray(e),ls=async e=>{let t;try{t=await e.json()}catch{throw new rs(e.status,`unavailable`)}if(!cs(t)||typeof t.path!=`string`||!t.path)throw new rs(e.status,`unavailable`);let n=typeof t.mime==`string`&&t.mime?t.mime:`application/octet-stream`,r=typeof t.size==`number`&&Number.isSafeInteger(t.size)?t.size:0,i=typeof t.sha256==`string`?t.sha256:``;return{path:t.path,url:as(t.path),mime:n,size:r,sha256:i}},us=e=>{let t=typeof crypto.randomUUID==`function`?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`,n=e?.replace(/[^a-z0-9._-]+/gi,`-`).replace(/^-+|-+$/g,``).slice(0,32);return n?`att-${t}-${n}`:`att-${t}`},ds=(e,t)=>{if(!e.startsWith(`data:`))return null;let n=e.indexOf(`,`);if(n===-1)return null;let r=e.slice(5,n),i=e.slice(n+1),a=r.split(`;`,1)[0]?.trim()||t||`application/octet-stream`;try{if(r.toLowerCase().includes(`;base64`)){let e=atob(i),t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n);return new Blob([t],{type:a})}return new Blob([decodeURIComponent(i)],{type:a})}catch{return null}},fs=e=>e.startsWith(`data:`)||e.startsWith(`blob:`),ps=async e=>{let t=pe(),n=e.mime||e.body.type||`application/octet-stream`,r=e.body.type===n?e.body:new Blob([e.body],{type:n});if(!Number.isSafeInteger(r.size)||r.size<0)throw new rs(413,`too-large`);let i=await ss(r),a=us(e.filename),o;try{o=await u(`/api/fs/prompt-attachments/${encodeURIComponent(a)}?storage=temporary`,{method:`PUT`,headers:{"Content-Type":n,"Content-Length":String(r.size),"X-Yuri-Content-Length":String(r.size),"X-Yuri-Sha256":i,"X-Yuri-Mime":n,...e.filename?{"X-Yuri-Filename":encodeURIComponent(e.filename)}:{}},body:r,signal:e.signal})}catch{throw new rs(0,`unavailable`)}if(o.status===413)throw new rs(413,`too-large`);if(!o.ok)throw new rs(o.status,o.status>=500||o.status===0?`unavailable`:`rejected`);let s=await ls(o);if(s.size!==r.size)throw new rs(o.status,`unavailable`);return await t(r,s.sha256),{...s,mime:n}},ms=500,hs=()=>{if(typeof window>`u`)return!1;try{return new URLSearchParams(window.location.search).get(`startupTrace`)===`1`||window.localStorage?.getItem(`YURI_STARTUP_TRACE`)===`1`}catch{return!1}},gs=()=>hs(),R=(e,t)=>{if(!hs())return;let n=typeof performance<`u`?performance.now():Date.now();window.__YURI_STARTUP_TRACE_START__??=n,window.__YURI_STARTUP_TRACE__??=[],window.__YURI_STARTUP_TRACE__.push({t:Math.round(n-window.__YURI_STARTUP_TRACE_START__),name:e,...t?{data:t}:{}}),window.__YURI_STARTUP_TRACE__.length>ms&&window.__YURI_STARTUP_TRACE__.splice(0,window.__YURI_STARTUP_TRACE__.length-ms)};typeof window<`u`&&(window.__YURI_STARTUP_TRACE_SUMMARY__=()=>{let e=typeof window<`u`?window.__YURI_STARTUP_TRACE__??[]:[],t=e.findIndex(e=>e.name===`ModelControls:ready`),n=t>=0?Math.min(e.length,t+8):e.length;return e.slice(0,n).filter(e=>e.name.includes(`checkConnection`)||e.name.includes(`checkHealth`)||e.name.includes(`initializeApp`)||e.name.includes(`initApp`)||e.name.includes(`loadProviders`)||e.name.includes(`loadAgents`)||e.name.includes(`config.defaults`)||e.name.includes(`ModelControls`)||e.name.includes(`activateDirectory`)||e.name.includes(`opencodeClient:setDirectory`))});var _s=async(e,t,n)=>{let r=typeof performance<`u`?performance.now():Date.now();R(`${e}:start`,n);try{let n=await t(),i=typeof performance<`u`?performance.now():Date.now();return R(`${e}:end`,{durationMs:Math.round(i-r)}),n}catch(t){let n=typeof performance<`u`?performance.now():Date.now();throw R(`${e}:error`,{durationMs:Math.round(n-r),error:t instanceof Error?t.message:String(t)}),t}},vs=e=>({kind:`session-inbox`,requestID:e.requestID,queueItemID:e.id,operationID:e.id,messageID:e.id,content:e.payload.text,createdAt:e.timeCreated,delivery:e.delivery,attachmentCount:Array.isArray(e.payload.files)?e.payload.files.length:0}),ys=[],bs=[],z=new Map,xs=512,Ss=0;function Cs(){return Ss}function B(){return{transportIdentity:o(),generation:s()}}function ws(e){return o()===e.transportIdentity&&s()===e.generation}function Ts(e,t,n){return`${n?.transportIdentity??o()}\0${n?.generation??s()}\0${e}\0${t}`}function Es(e=B()){if(z.size===0)return;let t=`${e.transportIdentity}\0${e.generation}\0`;for(let e of z.keys())e.startsWith(t)||z.delete(e);for(;z.size>xs;){let e=z.keys().next().value;if(e===void 0)break;z.delete(e)}}function Ds(e,t,n,r){let i=r??B();Es(i),Ss+=1,z.set(Ts(e,t,i),{kind:n,mark:Ss})}function Os(e,t,n){let r=n?.scope;Es(r??B());let i=z.get(Ts(e,t,r));if(!i)return!0;let a=n?.startedMark;return a!==void 0&&i.mark>a?!1:(z.delete(Ts(e,t,r)),!0)}function ks(e,t,n){return Es(n??B()),z.get(Ts(e,t,n))?.kind??null}var As=(e,t,n)=>{let r={...e};return n.length===0?delete r[t]:r[t]=n,r},V=m((e,t)=>({bySession:{},remember(t){return!ks(t.sessionID,t.id)&&(e(e=>{let n=e.bySession[t.sessionID]??[],r=n.findIndex(e=>e.id===t.id),i={...t,requestID:t.id};if(r>=0){let a=n.slice();return a[r]=i,{bySession:{...e.bySession,[t.sessionID]:a}}}return{bySession:{...e.bySession,[t.sessionID]:[...n,i]}}}),!0)},forget(t,n,r){r&&Ds(t,n,r),e(e=>{let r=e.bySession[t];if(!r?.length)return e;let i=r.filter(e=>e.id!==n);return i.length===r.length?e:{bySession:As(e.bySession,t,i)}})},forgetSession(t){e(e=>{if(!e.bySession[t])return e;let n={...e.bySession};return delete n[t],{bySession:n}})},forgetPromoted(t,n){let r=new Set(n);e(e=>{let n=e.bySession[t];if(!n?.length)return e;let i=new Set(n.filter(e=>r.has(e.id)).map(e=>e.id));if(i.size===0)return e;for(let e of i)Ds(t,e,`consumed`);return{bySession:As(e.bySession,t,n.filter(e=>!i.has(e.id)))}})},replaceFromAuthority(t,n,r){let i=r?.startedMark,a=[];for(let e of n)Os(t,e.id,{startedMark:i})&&a.push(e);e(e=>{let n=new Map((e.bySession[t]??[]).map(e=>[e.id,e])),i=r?.observedItems&&new Map(r.observedItems.map(e=>[e.id,e])),o=a.map(e=>({...e,requestID:e.id}));if(i){let e=new Map(o.map((e,t)=>[e.id,t]));for(let t of n.values()){if(i.get(t.id)===t)continue;let n=e.get(t.id);n===void 0?o.push(t):o[n]=t}}return{bySession:As(e.bySession,t,o)}})},updateDelivery(t,n,r){e(e=>{if(ks(t,n))return e;let i=e.bySession[t];if(!i?.length)return e;let a=i.findIndex(e=>e.id===n);if(a<0||i[a].delivery===r)return e;let o=i.slice();return o[a]={...i[a],delivery:r},{bySession:{...e.bySession,[t]:o}}})},list(e){return t().bySession[e]??ys}}));function js(e){return V.getState().remember(e)}function Ms(e,t){return Os(e.sessionID,e.id,t)?V.getState().remember(e):!1}function Ns(e,t,n){V.getState().forget(e,t,n)}function Ps(e,t){V.getState().forgetPromoted(e,t)}function Fs(e,t,n){V.getState().replaceFromAuthority(e,t,n)}function Is(e,t,n){V.getState().updateDelivery(e,t,n)}function Ls(e){return!!e&&typeof e==`object`&&e.kind===`session-inbox`}var Rs=e=>e?e.toLowerCase().includes(`application/json`):!1,zs=e=>e?e.toLowerCase().includes(`text/html`):!1;function H(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function U(e){return typeof e==`string`&&e.length>0?e:void 0}function Bs(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function Vs(e,t,n){let r=n?`: ${n}`:``,i=Error(`${e} (${t})${r}`);throw i.status=t,i}async function Hs(e){try{let t=(await e.text()).trim();if(!t)return``;try{let e=JSON.parse(t);if(typeof e.error==`string`&&e.error.trim())return e.error.trim();if(typeof e.message==`string`&&e.message.trim())return e.message.trim()}catch{}return t}catch{return``}}function Us(e){return e?{directory:e}:{}}function Ws(e,t){let n=`/api/session/${encodeURIComponent(e)}/inbox`;return t?`${n}/${encodeURIComponent(t)}`:n}async function Gs(e,t){let n=e.headers.get(`content-type`);if(zs(n))throw Error(`${t}: unexpected HTML response`);let r;try{r=await e.json()}catch{throw Error(`${t}: malformed JSON`)}if(!Rs(n)&&r==null)throw Error(`${t}: empty response`);return r}function Ks(e){let t=H(e)?e:null,n=t&&H(t.data)?t.data:t;if(!n)throw Error(`session prompt: expected inbox item`);let r=U(n.type);if(r&&r!==`user`)throw Error(`session prompt: expected user inbox item, got ${r}`);let i=U(n.id),a=U(n.sessionID);if(!i||!a)throw Error(`session prompt: inbox item missing id`);let o=H(n.payload)?n.payload:{},s=n.delivery===`queue`?`queue`:`steer`,c=H(n.time)?n.time:null;return{id:i,sessionID:a,timeCreated:Bs(n.timeCreated)??Bs(c?.created)??Date.now(),type:`user`,delivery:s,payload:{text:U(o.text)??U(n.text)??``,...o.files===void 0?{}:{files:o.files},...o.agents===void 0?{}:{agents:o.agents},...o.skills===void 0?{}:{skills:o.skills},...H(o.metadata)?{metadata:o.metadata}:{}}}}function qs(e){let t=H(e)?e:null,n=t&&Array.isArray(t.data)?t.data:Array.isArray(e)?e:null;if(!n)throw Error(`session inbox: expected list`);let r=[];for(let e of n)H(e)&&(e.type&&e.type!==`user`||r.push(Ks(e)));return r}function Js(e){return{runtimeKey:c(),generation:s(),directory:e,overlay:B()}}function W(e){return c()===e.runtimeKey&&s()===e.generation&&ws(e.overlay)}function Ys(e){let t=Error(`${e}: runtime switched`);throw t.name=`RuntimeGenerationMismatchError`,t}async function Xs(e){let t=e.commit??Js(e.directory);W(t)||Ys(`session prompt`);let n=`/api/session/${encodeURIComponent(e.sessionID)}/prompt`,r={id:e.messageID,text:e.text,delivery:e.delivery===`queue`?`queue`:`steer`};e.files?.length&&(r.files=e.files),e.agents?.length&&(r.agents=e.agents),e.skills?.length&&(r.skills=e.skills),e.metadata&&(r.metadata=e.metadata);let i=await u(n,{method:`POST`,headers:{"Content-Type":`application/json`},query:{directory:t.directory},body:JSON.stringify(r),signal:e.signal});if(W(t)||Ys(`session prompt`),!i.ok){let e=await Hs(i);Vs(`Failed to send message`,i.status,e)}let a=Ks(await Gs(i,`session prompt`));return W(t)||Ys(`session prompt`),js(a),a}function Zs(e){let t=e?.status;return typeof t!=`number`||!Number.isFinite(t)||t===408||t===429?!1:t>=400&&t<500}async function Qs(e){let t=e.inputID.trim();if(!t)return{status:`unknown`};let n=e.commit??Js(e.directory??``);if(!W(n))return{status:`unknown`};try{let r=await ec({sessionID:e.sessionID,directory:n.directory||e.directory,signal:e.signal});if(!W(n)||!r.current)return{status:`unknown`};let i=r.items.find(e=>e.id===t);if(i)return Ms(i,{startedMark:r.startedMark})?{status:`pending`,item:i}:{status:`unknown`}}catch{}if(!W(n))return{status:`unknown`};try{let r=await Qe({sessionID:e.sessionID,directory:n.directory||e.directory||``,limit:40,...e.signal?{signal:e.signal}:{}});if(!W(n))return{status:`unknown`};if(r.records.some(e=>e?.info?.id===t))return Ns(e.sessionID,t,`consumed`),{status:`promoted`,id:t}}catch{}return{status:`unknown`}}function $s(e){let t=typeof e.type==`string`?e.type:``,n=e.properties&&typeof e.properties==`object`?e.properties:null;if(!n)return!1;let r=U(n.sessionID),i=U(n.inboxID)??U(n.id);if(!r||!i)return!1;if(t===`session.inbox.enqueued`){let e=n.item,t=H(e)?U(e.type):void 0;if(t&&t!==`user`)return!1;try{return Ms(Ks(H(e)?{...e,id:i,sessionID:r,type:t??`user`}:{id:i,sessionID:r,type:`user`,delivery:`steer`,payload:{text:``}})),!0}catch{return!1}}if(t===`session.inbox.cancelled`)return Ns(r,i,`cancelled`),!0;if(t===`session.inbox.delivered`)return Ns(r,i,`consumed`),!0;if(t===`session.inbox.delivery.changed`){let e=n.delivery===`queue`?`queue`:n.delivery===`steer`?`steer`:null;return e?(Is(r,i,e),!0):!1}return!1}async function ec(e){let t=B(),n=Cs(),r=lt(e.sessionID),i={method:`GET`,query:Us(e.directory),signal:e.signal},a=await u(`/api/sessions/${encodeURIComponent(e.sessionID)}/delivery`,i);(a.status===404||a.status===501||zs(a.headers.get(`content-type`)))&&(a=await u(Ws(e.sessionID),i)),a.ok||Vs(`session inbox`,a.status,await Hs(a));let o=await Gs(a,`session inbox`),s=qs(o),c=ws(t);return c&&lt(e.sessionID)===r&&(H(o)&&typeof o.compactionRunning==`boolean`?T(e.sessionID,o.compactionRunning):ht(e.sessionID,mt(o))),{items:s,startedMark:n,scope:t,current:c}}async function tc(e){let t=B(),n=await u(Ws(e.sessionID,e.inboxID),{method:`PATCH`,headers:{"Content-Type":`application/json`},query:Us(e.directory),body:JSON.stringify({delivery:e.delivery}),signal:e.signal});n.ok||Vs(e.delivery===`steer`?`session inbox steer`:`session inbox queue`,n.status,await Hs(n)),ws(t)&&(ks(e.sessionID,e.inboxID)||Is(e.sessionID,e.inboxID,e.delivery))}async function nc(e){await tc({...e,delivery:`steer`})}async function rc(e){await tc({...e,delivery:`queue`})}async function ic(e){let t=await u(Ws(e.sessionID,e.inboxID),{method:`DELETE`,query:Us(e.directory),signal:e.signal});t.ok||Vs(`session inbox cancel`,t.status,await Hs(t))}function ac(e,t,n){Fs(e,t,n)}async function oc(e){let t=B();if(await ic(e),!ws(t))return{overlay:V.getState().list(e.sessionID),transcriptRows:[]};Ns(e.sessionID,e.inboxID,`cancelled`);try{let n=await ec({sessionID:e.sessionID,directory:e.directory,signal:e.signal});if(!ws(t)||!n.current)return{overlay:V.getState().list(e.sessionID),transcriptRows:[]};ac(e.sessionID,n.items,{startedMark:n.startedMark})}catch{}return{overlay:V.getState().list(e.sessionID),transcriptRows:[]}}async function sc(e){let t=`/api/session/${encodeURIComponent(e.sessionID)}/interrupt`,n={};e.directory&&(n.directory=e.directory),e.resume!==void 0&&(n.resume=String(e.resume));let r=await u(t,{method:`POST`,query:n,signal:e.signal});if(!r.ok)throw Error(`Session interrupt failed (${r.status})`)}async function cc(e){return e.promotedIDs.includes(e.optimisticID)?`confirmed`:(e.removeOptimistic(e.optimisticID),await e.refreshFromAuthority(),`refreshed`)}var lc=`session-revert-busy`,uc=e=>e?e.toLowerCase().includes(`text/html`):!1;function dc(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function fc(e){return typeof e==`string`&&e.length>0?e:void 0}function pc(e,t,n){if(t===409)throw mc();let r=n?`: ${n}`:``,i=Error(`${e} (${t})${r}`);if(i.status=t,t===404&&n)try{let e=JSON.parse(n);dc(e)&&e._tag===`MessageNotFoundError`&&(i.name=`MessageNotFoundError`)}catch{}throw i}function mc(){let e=Error(lc);return e.name=`SessionRevertBusyError`,e}function hc(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.name===`SessionRevertBusyError`||t.message===`session-revert-busy`}async function gc(e){try{return(await e.text()).trim()}catch{return``}}async function _c(e,t){if(uc(e.headers.get(`content-type`)))throw Error(`${t}: unexpected HTML response`);if(e.status===204)return null;let n=await e.text();if(!n.trim()){if(e.ok)return null;throw Error(`${t}: empty response`)}try{return JSON.parse(n)}catch{throw Error(`${t}: malformed JSON`)}}function vc(e){return e?{directory:e}:{}}function yc(e,t){return`/api/session/${encodeURIComponent(e)}/revert/${t}`}function bc(e){let t=dc(e)?e:null,n=t&&dc(t.data)?t.data:t;if(!n)throw Error(`session revert: expected revert payload`);let r=fc(n.messageID);if(!r)throw Error(`session revert: missing messageID`);let i=Array.isArray(n.files)?n.files.flatMap(e=>{if(!dc(e))throw Error(`session revert: invalid file diff`);let t=fc(e.file)??fc(e.path);if(!t||e.status!==`added`&&e.status!==`deleted`&&e.status!==`modified`||typeof e.additions!=`number`||typeof e.deletions!=`number`||typeof e.patch!=`string`)throw Error(`session revert: invalid file diff`);return[{file:t,status:e.status,additions:e.additions,deletions:e.deletions,patch:e.patch}]}):void 0;return{messageID:r,...fc(n.partID)?{partID:fc(n.partID)}:{},...fc(n.snapshot)?{snapshot:fc(n.snapshot)}:{},...i?{files:i}:{}}}function xc(e){return e?.files?e.files.flatMap(e=>{let t=typeof e.file==`string`&&e.file.length>0?e.file:typeof e.path==`string`&&e.path.length>0?e.path:``;return t?[t]:[]}):[]}async function Sc(e){let t=await u(yc(e.sessionID,`stage`),{method:`POST`,headers:{"Content-Type":`application/json`},query:vc(e.directory),body:JSON.stringify({messageID:e.messageID,files:e.files!==!1}),signal:e.signal});return t.ok||pc(`session revert stage`,t.status,await gc(t)),bc(await _c(t,`session revert stage`))}async function Cc(e){let t=await u(`/api/session/${encodeURIComponent(e.sessionID)}/revert`,{method:`DELETE`,query:vc(e.directory),signal:e.signal});t.ok||pc(`session revert clear`,t.status,await gc(t))}async function wc(e){let t=await u(yc(e.sessionID,`commit`),{method:`POST`,query:vc(e.directory),signal:e.signal});t.ok||pc(`session revert commit`,t.status,await gc(t))}var Tc=e=>e?e.toLowerCase().includes(`text/html`):!1;function Ec(e,t,n){let r=n?`: ${n}`:``,i=Error(`${e} (${t})${r}`);throw i.status=t,i}async function Dc(e){try{return(await e.text()).trim()}catch{return``}}function Oc(e){return e?{directory:e}:{}}function kc(e,t){return`/api/session/${encodeURIComponent(e)}/permission/${encodeURIComponent(t)}/reply`}async function Ac(e){let t=await u(kc(e.sessionID,e.requestID),{method:`POST`,headers:{"Content-Type":`application/json`},query:Oc(e.directory),body:JSON.stringify({decision:e.reply,...e.message?{message:e.message}:{}}),signal:e.signal});if(t.ok||Ec(`session permission reply`,t.status,await Dc(t)),t.status!==204&&Tc(t.headers.get(`content-type`)))throw Error(`session permission reply: unexpected HTML response`)}function jc(e){let t=Error(`${e} is not available on OpenCode v2`);return t.name=`V2CapabilityUnavailableError`,t}function Mc(e){let t=typeof e.directory==`string`?e.directory:``;return{state:``,config:``,worktree:typeof e.project?.directory==`string`?e.project.directory:t,directory:t,home:``}}function Nc(e){return e.worktree||e.canonical||``}function Pc(e,t){let n={};if(t.size===0)return n;for(let[r,i]of Object.entries(e))t.has(r)&&i?.type===`running`&&(n[r]={type:`busy`});return n}function Fc(e){return{id:e.id,sessionID:e.sessionID,permission:e.action,patterns:Array.isArray(e.resources)?e.resources:[],metadata:e.metadata??{},always:Array.isArray(e.save)?e.save:[],...e.source?.messageID?{tool:{messageID:e.source.messageID,callID:e.source.id??``}}:{}}}function Ic(e){return!!e&&typeof e==`object`&&!Array.isArray(e)&&e.kind===`question`}function Lc(e){let t=e.metadata&&typeof e.metadata.tool==`object`&&e.metadata.tool&&!Array.isArray(e.metadata.tool)?e.metadata.tool:void 0,n=typeof e.tool?.messageID==`string`&&e.tool.messageID.length>0?e.tool.messageID:typeof t?.messageID==`string`&&t.messageID.length>0?t.messageID:void 0;if(n)return{messageID:n,callID:typeof e.tool?.id==`string`?e.tool.id:typeof t?.id==`string`?t.id:``}}function Rc(e){let t=e.fields;if(!t||t.length===0){let t=typeof e.title==`string`&&e.title.length>0?e.title:`Form`;return[{question:t,header:t,options:[]}]}return t.map(t=>{let n=typeof t.title==`string`&&t.title.length>0?t.title:t.key;return{question:typeof t.description==`string`&&t.description.length>0?t.description:typeof e.title==`string`&&e.title.length>0?e.title:n,header:n,options:(t.options??[]).map(e=>({label:e.label||e.value||``,description:typeof e.description==`string`?e.description:``})).filter(e=>e.label.length>0),...t.type===`multiselect`?{multiple:!0}:{}}})}function zc(e){let t=e.questions&&e.questions.length>0?e.questions.map(e=>({question:e.question,header:e.header,options:e.options??[],...e.multiple?{multiple:!0}:{}})):Rc(e),n=Lc(e);return{id:e.id,sessionID:e.sessionID,questions:t,...n?{tool:n}:{}}}function Bc(e,t){let n={};for(let r=0;r<t.length;r+=1){let i=t[r],a=(e[r]??[]).map(e=>i.options?.find(t=>(t.label||t.value)===e)?.value??e),o=a[0]??``;if(i.type===`multiselect`)n[i.key]=a;else if(i.type===`number`||i.type===`integer`){let e=Number(o);if(!o.trim()||!Number.isFinite(e)||i.type===`integer`&&!Number.isInteger(e))throw Error(`Invalid numeric answer for ${i.key}`);n[i.key]=e}else if(i.type===`boolean`){if(o!==`true`&&o!==`false`)throw Error(`Invalid boolean answer for ${i.key}`);n[i.key]=o===`true`}else n[i.key]=o}return n}var Vc=3,Hc=3e4,Uc=32e3,Wc=36e5,Gc=6e5,Kc=new Set([429,502,503,504]),qc=new Map;function Jc(){let e=Date.now();for(let[t,n]of qc)n.consecutiveErrors===0&&e-n.lastErrorAt>Wc&&qc.delete(t)}typeof setInterval<`u`&&setInterval(Jc,Gc).unref?.();function Yc(e){let t=qc.get(e);return t||(t={consecutiveErrors:0,lastErrorAt:0,circuitOpen:!1,circuitOpenAt:0,circuitCooldownMs:Hc},qc.set(e,t)),t}function Xc(e){if(!e)return;let t=qc.get(e);t&&(t.consecutiveErrors=0,t.lastErrorAt=0)}function Zc(e,t){if(!e)return;let n=Yc(e);n.consecutiveErrors+=1,n.lastErrorAt=Date.now(),Qc(t)&&n.consecutiveErrors>=Vc&&(n.circuitOpen=!0,n.circuitOpenAt=Date.now(),console.warn(`[provider-tracker] Circuit opened for ${e} after ${n.consecutiveErrors} consecutive errors`))}function Qc(e){return e!==void 0&&Kc.has(e)}function $c(e){let t=qc.get(e);return t?.circuitOpen?Date.now()-t.circuitOpenAt>=t.circuitCooldownMs?(t.circuitOpen=!1,t.consecutiveErrors=0,t.circuitCooldownMs=Math.min(t.circuitCooldownMs*2,Uc*4),!1):!0:!1}function el(e){if(!(!e||!$c(e)))throw Error(`Provider ${e} is temporarily unavailable after repeated errors. Please retry shortly.`)}var tl=`/api`,nl=1e4,rl=4e3,il=3e3,al=1e3,ol=1500,sl=12e3;function cl(e){if(e instanceof Error)return e.message;if(typeof e==`string`)return e;if(e&&typeof e==`object`&&`message`in e&&typeof e.message==`string`)return e.message;try{return JSON.stringify(e)}catch{return String(e)}}function G(e){let t=Error(`${e} is not available on OpenCode v2`);return t.name=`V2CapabilityUnavailableError`,t}function ll(e){if(e instanceof ne&&e.reason===`UnexpectedStatus`){let t=e.cause;if(t&&typeof t==`object`&&`status`in t){let e=t.status;if(typeof e==`number`)return e}}if(e&&typeof e==`object`&&`status`in e){let t=e.status;if(typeof t==`number`)return t}}function ul(e){return e===404||e===405||e===501}function K(e){if(typeof e!=`string`)return;let t=e.trim();if(t)return{location:{directory:t}}}function dl(e){let t=e.replace(/\/+$/,``);if(t.endsWith(`/api`)){let e=t.slice(0,-4);if(e.length>0)return e}return ml(gl()||`/`)}function fl(e){return!e||typeof e.id!=`string`||e.id.length===0||typeof e.sessionID!=`string`||e.sessionID.length===0?null:{id:e.id,sessionID:e.sessionID,permission:e.action,patterns:Array.isArray(e.resources)?e.resources:[],metadata:e.metadata??{},always:Array.isArray(e.save)?e.save:[],...e.source?{tool:{messageID:e.source.messageID,callID:e.source.id}}:{}}}var pl=/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//,ml=e=>{let t=typeof e==`string`&&e.trim().length>0?e.trim():`/api`;if(pl.test(t)||typeof window>`u`)return t;let n=window.location?.href||window.location?.origin;if(!n)return t;try{return new URL(t,n).toString()}catch(e){return console.warn(`Failed to normalize OpenCode base URL:`,e),t}},hl=()=>{try{return a().api(`/api`)}catch{return null}},gl=()=>{try{return a().api(`/`)}catch{return null}},_l=e=>{let t=typeof AbortSignal<`u`?AbortSignal:void 0;if(typeof t?.timeout==`function`)return{signal:t.timeout(e),cleanup:()=>void 0};let n=new AbortController,r=setTimeout(()=>n.abort(),e);return{signal:n.signal,cleanup:()=>clearTimeout(r)}},vl=e=>{let t=e.filter(e=>e!=null);if(t.length===0)return{signal:new AbortController().signal,cleanup:()=>void 0};if(t.length===1)return{signal:t[0],cleanup:()=>void 0};let n=typeof AbortSignal<`u`?AbortSignal:void 0;if(typeof n?.any==`function`)return{signal:n.any(t),cleanup:()=>void 0};let r=new AbortController,i=()=>r.abort();for(let e of t){if(e.aborted){r.abort();break}e.addEventListener(`abort`,i)}return{signal:r.signal,cleanup:()=>{for(let e of t)e.removeEventListener(`abort`,i)}}},yl=e=>{let t=e.session?.message,n=t&&typeof t==`object`&&typeof t.get==`function`?t.get.bind(t):null;if(!n)return e;let r=Object.assign((e,t)=>n(e,t),t);return{...e,session:{...e.session,message:r}}},bl=e=>yl(te.make({baseUrl:e.baseUrl,...e.headers?{headers:e.headers}:{},fetch:(e,t)=>{let n=new URL(e instanceof Request?e.url:e.toString()),r=`${n.pathname}${n.search}`;if(e instanceof Request){let n=ml(a().api(r));return u(new Request(n,e),t)}return u(r,t)}})),xl=20971520,Sl=e=>{let{referenceOnly:t,...n}=e;return Cl(e)&&!t?n:{type:`text`,synthetic:!0,text:ts(`Attachment ${JSON.stringify(e.filename||`file`)}: ${JSON.stringify(os(e.url))}\nRead or process this file with tools as needed; its contents are not included in the message.`.replace(/</g,`\\u003c`))}},Cl=e=>typeof e.mime==`string`&&e.mime.startsWith(`image/`)?!0:typeof e.filename==`string`&&/\.(?:png|jpe?g|gif|webp|svg|avif|bmp|heic|heif|tiff?)$/i.test(e.filename),wl=e=>{let t=[];for(let n of e){if(!Cl(n))continue;let e=typeof n.filename==`string`?n.filename.trim():``,r=typeof n.url==`string`?n.url:``;if(!e||!r.toLowerCase().startsWith(`file://`))continue;let i=os(r).trim();i&&t.push({filename:e,path:i})}return t},Tl=async(e,t)=>{let n=[],r=e.files?.length?await Promise.all(e.files.map(e=>t(e))):[],i=e.additionalParts?.length?await Promise.all(e.additionalParts.map(async e=>({text:e.text,synthetic:e.synthetic,files:e.files?.length?await Promise.all(e.files.map(e=>t(e))):[]}))):[],a=e=>Uo(e,wl([...r,...i.flatMap(e=>e.files)]));if(e.prefaceText&&e.prefaceText.trim()&&n.push({type:`text`,text:a(e.prefaceText),synthetic:e.prefaceTextSynthetic!==!1}),e.text&&e.text.trim()&&n.push({type:`text`,text:a(e.text)}),n.push(...r.map(Sl)),i.length>0)for(let e of i){if(e.text&&e.text.trim()){let t={type:`text`,text:a(e.text)};e.synthetic&&(t.synthetic=!0),n.push(t)}n.push(...e.files.map(Sl))}if(e.agentMentions&&e.agentMentions.length>0)for(let t of e.agentMentions){if(!t?.name)continue;let e={type:`agent`,name:t.name};t.source&&(e.source=t.source),n.push(e)}if(n.length===0)throw Error(`Message must have at least one part (text or file)`);return n},El=e=>e.replace(/\\/g,`/`),Dl=400,Ol=()=>{let e=p();return e&&e.runtime?.isDesktop&&e.files?e.files:null},q=new class{client;baseUrl;scopedClients=new Map;currentDirectory=void 0;directoryContextQueue=Promise.resolve();listDirectoryInFlight=new Map;configProvidersInFlight=new Map;listAgentsInFlight=new Map;configInFlight=new Map;configCache=new Map;configCacheGeneration=0;listDirectoryCache=new Map;healthInFlight=new Map;healthCache=new Map;healthCacheGeneration=0;liveLocationsFlight=null;sessionBoundaryQueues=new Map;constructor(e=tl){let t=hl()||e;this.baseUrl=ml(t),this.client=bl({baseUrl:dl(this.baseUrl)})}getBaseUrl(){return ml(hl()||this.baseUrl)}reconnectToRuntimeBaseUrl(){let e=ml(hl()||tl);e!==this.baseUrl&&(this.baseUrl=e,this.client=bl({baseUrl:dl(this.baseUrl)}),this.scopedClients.clear(),this.listDirectoryInFlight.clear(),this.configProvidersInFlight.clear(),this.listAgentsInFlight.clear(),this.clearConfigCache(),this.listDirectoryCache.clear(),this.clearHealthCache(),this.liveLocationsFlight=null)}getSdkClient(){return this.client}getScopedSdkClient(e){return this.getScopedApiClient(e)}async checkLocationReleaseUse(e,t){let n=this.normalizeCandidatePath(e),r=await this.listLiveLocationDirectories();if(!r)throw Error(`Live Location inventory unavailable`);if(r&&n&&!r.has(n))return`free`;let i=this.getScopedSdkClient(e),a={location:{directory:e}},[o,s]=await Promise.all([i.shell.list(a,{signal:t}),i.form.list(a,{signal:t})]);return o.data.some(e=>e.status===`running`)||s.data.length>0?`busy`:`free`}listLiveLocationDirectories(){let e=Date.now();if(this.liveLocationsFlight&&this.liveLocationsFlight.expiresAt>e)return this.liveLocationsFlight.promise;let t=this.client.debug.location.list().then(e=>{if(!Array.isArray(e))return null;let t=new Set;for(let n of e){let e=this.normalizeCandidatePath(n?.directory??null);e&&t.add(e)}return t}).catch(()=>null);return this.liveLocationsFlight={promise:t,expiresAt:e+ol},t}async resolveBlockingRequestDirectories(e){let t=new Set;for(let n of e??[]){let e=this.normalizeCandidatePath(n??null);e&&t.add(e)}if(t.size===0)return[];let n=await this.listLiveLocationDirectories();if(!n)throw Error(`Live Location inventory unavailable`);return Array.from(t).filter(e=>n.has(e))}async releaseLocation(e,t){await this.getScopedSdkClient(e).debug.location.evict({location:{directory:e}},{signal:t})}getScopedApiClient(e){let t=(this.normalizeCandidatePath(e)??e)||``,n=this.scopedClients.get(t);if(n)return n;let r=bl({baseUrl:dl(this.baseUrl)});return this.scopedClients.set(t,r),r}normalizeCandidatePath(e){if(typeof e!=`string`)return null;let t=e.trim();if(!t)return null;let n=t.replace(/\\/g,`/`).replace(/^([a-z]):/,(e,t)=>t.toUpperCase()+`:`);return(n.length>1?n.replace(/\/+$/,``):n)||null}deriveHomeDirectory(e){let t=e.match(/^([A-Za-z]:)(?:\/|$)/);if(t){let n=t[1],r=e.slice(n.length+ +(e.charAt(n.length)===`/`)).split(`/`).filter(Boolean);return r.length>=2?{homeDirectory:`${n}/${r[0]}/${r[1]}`,username:r[1]}:r.length===1?{homeDirectory:`${n}/${r[0]}`,username:r[0]}:{homeDirectory:n,username:void 0}}let n=e.startsWith(`/`),r=e.split(`/`).filter(Boolean);return r.length>=2&&(r[0]===`Users`||r[0]===`home`)?{homeDirectory:`${n?`/`:``}${r[0]}/${r[1]}`,username:r[1]}:n?r.length===0?{homeDirectory:`/`,username:void 0}:{homeDirectory:`/${r.join(`/`)}`,username:r[r.length-1]}:r.length>0?{homeDirectory:`/${r.join(`/`)}`,username:r[r.length-1]}:{homeDirectory:`/`,username:void 0}}setDirectory(e){let t=this.normalizeCandidatePath(e)??e;this.currentDirectory!==t&&R(`opencodeClient:setDirectory`,{previous:this.currentDirectory??null,next:t??null}),this.currentDirectory=t}getDirectory(){return this.currentDirectory}runSessionBoundary(e,t){let n=e.trim();if(!n)return t();let r=this.sessionBoundaryQueues.get(n)??Promise.resolve(),i,a,o=new Promise((e,t)=>{i=e,a=t}),s=()=>t().then(i,a),c=r.then(s,s);return this.sessionBoundaryQueues.set(n,c.then(()=>void 0,()=>void 0)),o}assertCapturedRuntime(e,t,n){if(s()!==e||c()!==t){let e=Error(`${n}: runtime switched`);throw e.name=`RuntimeGenerationMismatchError`,e}}async switchSessionModel(e,t,n){let r=s(),i=c(),a=`id`in t&&typeof t.id==`string`&&t.id?t.id:t.modelID,o=t.providerID;if(!e||!a||!o)throw Error(`switchSessionModel requires sessionID, model.id, and providerID`);let l=typeof t.variant==`string`&&t.variant.trim()?t.variant.trim():void 0,u={id:a,providerID:o,...l?{variant:l}:{}},d=this.normalizeCandidatePath(n)??this.currentDirectory??``,f=this.getScopedSdkClient(d);this.assertCapturedRuntime(r,i,`session model switch`),await f.session.switchModel({sessionID:e,model:u}),this.assertCapturedRuntime(r,i,`session model switch`),uo(e,d||n,{model:u})}async switchSessionAgent(e,t,n){let r=s(),i=c(),a=typeof t==`string`?t.trim():``;if(!e||!a)throw Error(`switchSessionAgent requires sessionID and agent`);let o=this.normalizeCandidatePath(n)??this.currentDirectory??``,l=this.getScopedSdkClient(o);this.assertCapturedRuntime(r,i,`session agent switch`),await l.session.switchAgent({sessionID:e,agent:a}),this.assertCapturedRuntime(r,i,`session agent switch`),uo(e,o||n,{agent:a})}async generateSessionAside(e){let t=typeof e.sessionId==`string`?e.sessionId.trim():``;if(!t)throw Error(`generateSessionAside requires sessionId`);let n=typeof e.prompt==`string`?e.prompt:``,r=this.normalizeCandidatePath(e.directory)??this.currentDirectory??``,i=await this.getScopedSdkClient(r).session.generate({sessionID:t,prompt:n},e.signal?{signal:e.signal}:void 0);if(!i||typeof i.text!=`string`)throw Error(`session.generate returned invalid payload`);return{text:i.text}}async applySendSelection(e,t,n){t.model&&await this.switchSessionModel(e,t.model,n),t.agent&&await this.switchSessionAgent(e,t.agent,n)}async withDirectory(e,t){let n=async()=>{if(e==null)return t();let n=this.currentDirectory,r=this.normalizeCandidatePath(e)??e;this.currentDirectory=r;try{return await t()}finally{this.currentDirectory===r&&(this.currentDirectory=n)}},r=this.directoryContextQueue.then(n,n);return this.directoryContextQueue=r.then(()=>void 0,()=>void 0),r}getApiClient(){return this.client}async getSystemInfo(){let e=new Set,t=t=>{let n=this.normalizeCandidatePath(t);n&&e.add(n)};try{let e=await this.client.location.get(K(this.currentDirectory));e&&(t(e.directory),t(e.project?.directory),t(e.project?.canonical))}catch{}if(!e.size)try{let e=await this.client.location.get(K(this.currentDirectory));t(e?.project?.directory),t(e?.project?.canonical)}catch{}if(!e.size)try{(await this.listSessions()).forEach(e=>t(e.directory))}catch{}if(t(this.currentDirectory),typeof window<`u`)try{t(_(`lastDirectory`)),t(_(`homeDirectory`))}catch{}if(!e.size&&typeof process<`u`&&typeof process.cwd==`function`&&t(process.cwd()),!e.size)return{homeDirectory:`/`,username:void 0};let[n]=Array.from(e);return this.deriveHomeDirectory(n)}async probeDirectory(e){let t=this.normalizeCandidatePath(e);if(!t)return!1;try{let e=await this.client.location.get({location:{directory:t}}),n=typeof e?.directory==`string`?e.directory:null;return!!(n&&n.trim().length>0)}catch{return!1}}async listSessions(){let e=await this.client.session.list(this.currentDirectory?{directory:this.currentDirectory}:void 0);return Array.isArray(e.data)?e.data.map(y):[]}async searchSessionsByTitle(e){let t=e.search.trim(),n=await this.client.session.list({search:t||void 0,parentID:null,limit:e.limit??30,order:`desc`},e.signal?{signal:e.signal}:void 0);if(!Array.isArray(n?.data))throw Error(`session.list search returned no data`);return n.data.map(y)}async createSession(e,t){let n=this.normalizeCandidatePath(t)??this.currentDirectory;if(e?.metadata,e?.parentID){let t=await this.client.session.fork({sessionID:e.parentID});return e.title?(await this.client.session.update({sessionID:t.id,title:e.title}),y(await this.client.session.get({sessionID:t.id}))):y(t)}return y(await this.client.session.create({...n?{location:{directory:n}}:{},title:e?.title}))}async getSession(e,t){return y(await this.client.session.get({sessionID:e}))}async deleteSession(e,t){return await this.client.session.remove({sessionID:e}),!0}async deleteSessionMessage(e,t,n){throw G(`session.deleteMessage`)}async updateSession(e,t,n){let r=t.title!==void 0,i=t.metadata!==void 0,a=t.time!==void 0&&Object.prototype.hasOwnProperty.call(t.time,`archived`);if(!r&&!i&&!a)throw G(`session.update`);let o=this.normalizeCandidatePath(n)??this.currentDirectory,l=s(),d=c(),f=()=>{if(s()!==l||c()!==d){let e=Error(`session.update discarded: runtime switched`);throw e.name=`RuntimeGenerationMismatchError`,e}},p=[],m=null,h=null,g=e=>{if(p.length===0)throw e;let t=cl(e),n=Error(`session.update partial failure after ${p.join(`,`)}: ${t}`);throw n.name=`SessionUpdatePartialFailureError`,n.cause=e,n.completed=[...p],n};try{if(r&&(await this.client.session.update({sessionID:e,title:t.title}),f(),p.push(`title`),m=y(await this.client.session.get({sessionID:e})),f()),i){let n={patch:t.metadata};o&&(n.directory=o);let r=await u(`/api/yuri/sessions/${encodeURIComponent(e)}/metadata`,{method:`PUT`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify(n)});if(f(),!r.ok){let e=Error(`session.metadata update failed (${r.status})`);throw e.status=r.status,e}let i=await r.json().catch(()=>null);f(),h=typeof i==`object`&&i&&!Array.isArray(i)&&`metadata`in i&&i.metadata!==null&&typeof i.metadata==`object`&&!Array.isArray(i.metadata)?i.metadata:null,p.push(`metadata`)}if(a){let n=t.time?.archived,r;if(n==null)r=0;else if(typeof n==`number`&&Number.isFinite(n))r=n>0?Math.trunc(n):0;else throw Error(`archivedAt must be a finite number or null`);let i={archivedAt:r};o&&(i.directory=o);let a=await u(`/api/yuri/sessions/${encodeURIComponent(e)}/archive`,{method:`PUT`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify(i)});if(f(),!a.ok){let e=Error(`session.archive update failed (${a.status})`);throw e.status=a.status,e}let s=await a.json().catch(()=>null);f();let c=typeof s==`object`&&s&&!Array.isArray(s)&&`session`in s?s.session:null;if(!c||typeof c!=`object`||Array.isArray(c))throw Error(`session.archive update failed: empty response`);m=y(c),p.push(`archive`)}return m||(m=await this.getSession(e,n),f()),h&&!a?{...m,metadata:h}:m}catch(e){return g(e)}}async getSessionMessages(e,t){return(await Qe({sessionID:e,directory:this.currentDirectory??``,...typeof t==`number`?{limit:t}:{}})).records}async getSessionDiff(e,t){let n=this.normalizeCandidatePath(e.directory)??this.currentDirectory,r=typeof e.messageID==`string`&&e.messageID.trim().length>0?e.messageID.trim():void 0,i=new URLSearchParams;n&&i.set(`directory`,n),r&&i.set(`messageID`,r);let a=i.toString(),o=await u(`/api/session/${encodeURIComponent(e.sessionID)}/diff${a?`?${a}`:``}`,{method:`GET`,headers:{Accept:`application/json`},signal:t?.signal});if(!o.ok){let e=Error(`session.diff failed (${o.status})`);throw e.status=o.status,e}let s=await o.json().catch(()=>null),c=typeof s==`object`&&s&&Array.isArray(s.data)?s.data:null;if(!c)throw Error(`session.diff failed: empty response`);return c}async getSessionTodos(e){throw G(`session.todo`)}shouldNormalizeToTextPlain(e){if(!e)return!1;let t=e.toLowerCase();return t.startsWith(`text/`)&&t!==`text/plain`?!0:[`application/json`,`application/xml`,`application/javascript`,`application/typescript`,`application/x-yaml`,`application/yaml`,`application/toml`,`application/x-sh`,`application/x-shellscript`,`application/octet-stream`,`image/svg+xml`].includes(t)}isHeicMime(e){if(!e)return!1;let t=e.toLowerCase();return t===`image/heic`||t===`image/heif`}async convertHeicToJpeg(t){try{let n=ds(t.url,t.mime);if(!n)return t;let r=await vo(n)??await(await me(async()=>{let{default:t}=await import(`./vendor-heic2any-DgJnLT1Y.js`).then(t=>e(t.t(),1));return{default:t}},__vite__mapDeps([0,1]))).default({blob:n,toType:`image/jpeg`,quality:.9}),i=await new Promise((e,t)=>{let n=new FileReader;n.onload=()=>e(n.result),n.onerror=t,n.readAsDataURL(r)}),a=t.filename;return a&&=a.replace(/\.heic$/i,`.jpg`).replace(/\.heif$/i,`.jpg`),{mime:`image/jpeg`,filename:a,url:i}}catch(e){return console.warn(`Failed to convert HEIC to JPEG:`,e),t}}async normalizeFilePart(e){if(this.isHeicMime(e.mime))return this.convertHeicToJpeg(e);if(!this.shouldNormalizeToTextPlain(e.mime))return e;let t=e.url;if(e.url.startsWith(`data:`)){let n=e.url.indexOf(`,`);if(n!==-1){let r=e.url.substring(5,n),i=e.url.substring(n);t=`data:${r.replace(/^[^;,]+/,`text/plain`)}${i}`}}return{mime:`text/plain`,filename:e.filename,url:t}}async toNormalizedFilePartInput(e,t){let n=t?.generation??s(),r=t?.runtimeKey??c(),i=Cl(e)?await this.normalizeFilePart(e):e;this.assertCapturedRuntime(n,r,`prompt attachment normalize`);let a=i.url,o;if(fs(a)){let e=a.startsWith(`blob:`)?await fetch(a).then(e=>e.blob()):ds(a,i.mime);if(!e)throw Error(`Failed to materialize attachment bytes for ${i.filename??`file`}`);this.assertCapturedRuntime(n,r,`prompt attachment upload`);let t=await ps({body:e,mime:i.mime,filename:i.filename});this.assertCapturedRuntime(n,r,`prompt attachment upload`),a=t.url,o=t.size}if(Cl(i)&&o===void 0&&a.toLowerCase().startsWith(`file://`)){let e=os(a),t=p()?.files;if(t?.statFile)o=(await t.statFile(e)).size;else{let t=await u(`/api/fs/stat`,{query:{path:e}});if(!t.ok)throw Error(`Failed to inspect prompt attachment`);o=(await t.json()).size}this.assertCapturedRuntime(n,r,`prompt attachment stat`)}return{...e.id?{id:e.id}:{},type:`file`,mime:i.mime,filename:i.filename,url:a,...Cl(i)&&(o===void 0||!Number.isSafeInteger(o)||o<0||o>xl)?{referenceOnly:!0}:{}}}async buildMessageParts(e,t){let n=t?.generation??s(),r=t?.runtimeKey??c();return Tl(e,e=>this.toNormalizedFilePartInput(e,{generation:n,runtimeKey:r}))}async sendMessage(e){let t=s(),n=c(),r=()=>{this.assertCapturedRuntime(t,n,`session prompt discarded`)};r();let i=e.messageId??le(`msg`),a=this.normalizeCandidatePath(e.directory??null)??this.currentDirectory,o=Js(a??``),l=await this.buildMessageParts({text:e.text,prefaceText:e.prefaceText,prefaceTextSynthetic:e.prefaceTextSynthetic,files:e.files,additionalParts:e.additionalParts,agentMentions:e.agentMentions},{generation:t,runtimeKey:n});r(),W(o)||this.assertCapturedRuntime(t,n,`session prompt discarded`),e.format&&(e.id,e.providerID,e.modelID,e.agent,e.variant,this.baseUrl,e.format.type),el(e.providerID);let u=l.flatMap(e=>e.type===`text`&&typeof e.text==`string`?[e.text]:[]).join(`
5
5
  `)||e.text,d=l.flatMap(e=>e.type!==`file`||typeof e.url!=`string`?[]:[{uri:e.url,...e.filename?{name:e.filename}:{}}]),f=l.flatMap(e=>e.type===`agent`&&typeof e.name==`string`?[{name:e.name}]:[]),p=be(l.flatMap(e=>e.type===`text`&&!e.synthetic?[e.text]:[]).join(`
@@ -1 +1 @@
1
- import"./rolldown-runtime-hePW80VL.js";import{ot as e,st as t}from"./vendor-base-ui-CzHs0bHY.js";import{n}from"./vendor-react-DlzBev0S.js";import{r}from"./button-1hulrRFb.js";var i=n();t();var a=e();function o(e){let t=(0,i.c)(23),n,o,s,c,l,u;t[0]===e?(n=t[1],o=t[2],s=t[3],c=t[4],l=t[5],u=t[6]):({className:o,type:u,bordered:n,placeholder:c,endAdornment:s,...l}=e,t[0]=e,t[1]=n,t[2]=o,t[3]=s,t[4]=c,t[5]=l,t[6]=u);let d=c||` `,f=n!==void 0&&`border border-transparent ring-0 focus:ring-0 aria-invalid:ring-1 aria-invalid:focus:ring-1`,p=n&&`border-[var(--form-surface-border)]`,m=s&&`pe-11`,h;t[7]!==o||t[8]!==f||t[9]!==p||t[10]!==m?(h=r(`text-foreground file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground bg-[var(--surface-elevated)] appearance-none flex h-9 w-full min-w-0 rounded-lg px-3 py-1 typography-markdown outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:typography-ui-label file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:typography-ui-label`,`ring-1 ring-inset ring-border/60 transition duration-200 ease-out`,`hover:[&:not(:focus)]:bg-[var(--surface-subtle)] hover:[&:not(:focus)]:ring-transparent`,`focus:ring-2 focus:ring-[var(--interactive-focus-ring)] focus-visible:outline-none`,`aria-invalid:ring-[var(--status-error)] aria-invalid:focus:ring-[var(--status-error)]`,f,p,o,m),t[7]=o,t[8]=f,t[9]=p,t[10]=m,t[11]=h):h=t[11];let g;t[12]!==n||t[13]!==l||t[14]!==d||t[15]!==h||t[16]!==u?(g=(0,a.jsx)(`input`,{type:u,"data-slot":`input`,"data-bordered":n,placeholder:d,className:h,spellCheck:!1,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`,...l}),t[12]=n,t[13]=l,t[14]=d,t[15]=h,t[16]=u,t[17]=g):g=t[17];let _=g;if(!s)return _;let v;t[18]===s?v=t[19]:(v=(0,a.jsx)(`div`,{"data-slot":`input-end-adornment`,className:`absolute inset-y-0 end-0 flex items-center`,children:s}),t[18]=s,t[19]=v);let y;return t[20]!==_||t[21]!==v?(y=(0,a.jsxs)(`div`,{"data-slot":`input-wrapper`,className:`relative min-w-0 w-full flex-1`,children:[_,v]}),t[20]=_,t[21]=v,t[22]=y):y=t[22],y}export{o as t};
1
+ import"./rolldown-runtime-hePW80VL.js";import{ot as e,st as t}from"./vendor-base-ui-CzHs0bHY.js";import{n}from"./vendor-react-DlzBev0S.js";import{r}from"./button-CBjOhOI0.js";var i=n();t();var a=e();function o(e){let t=(0,i.c)(23),n,o,s,c,l,u;t[0]===e?(n=t[1],o=t[2],s=t[3],c=t[4],l=t[5],u=t[6]):({className:o,type:u,bordered:n,placeholder:c,endAdornment:s,...l}=e,t[0]=e,t[1]=n,t[2]=o,t[3]=s,t[4]=c,t[5]=l,t[6]=u);let d=c||` `,f=n!==void 0&&`border border-transparent ring-0 focus:ring-0 aria-invalid:ring-1 aria-invalid:focus:ring-1`,p=n&&`border-[var(--form-surface-border)]`,m=s&&`pe-11`,h;t[7]!==o||t[8]!==f||t[9]!==p||t[10]!==m?(h=r(`text-foreground file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground bg-[var(--surface-elevated)] appearance-none flex h-9 w-full min-w-0 rounded-lg px-3 py-1 typography-markdown outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:typography-ui-label file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:typography-ui-label`,`ring-1 ring-inset ring-border/60 transition duration-200 ease-out`,`hover:[&:not(:focus)]:bg-[var(--surface-subtle)] hover:[&:not(:focus)]:ring-transparent`,`focus:ring-2 focus:ring-[var(--interactive-focus-ring)] focus-visible:outline-none`,`aria-invalid:ring-[var(--status-error)] aria-invalid:focus:ring-[var(--status-error)]`,f,p,o,m),t[7]=o,t[8]=f,t[9]=p,t[10]=m,t[11]=h):h=t[11];let g;t[12]!==n||t[13]!==l||t[14]!==d||t[15]!==h||t[16]!==u?(g=(0,a.jsx)(`input`,{type:u,"data-slot":`input`,"data-bordered":n,placeholder:d,className:h,spellCheck:!1,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`,...l}),t[12]=n,t[13]=l,t[14]=d,t[15]=h,t[16]=u,t[17]=g):g=t[17];let _=g;if(!s)return _;let v;t[18]===s?v=t[19]:(v=(0,a.jsx)(`div`,{"data-slot":`input-end-adornment`,className:`absolute inset-y-0 end-0 flex items-center`,children:s}),t[18]=s,t[19]=v);let y;return t[20]!==_||t[21]!==v?(y=(0,a.jsxs)(`div`,{"data-slot":`input-wrapper`,className:`relative min-w-0 w-full flex-1`,children:[_,v]}),t[20]=_,t[21]=v,t[22]=y):y=t[22],y}export{o as t};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,i as n}from"./runtime-switch-DEZ1K7qW.js";import{T as r}from"./desktop-BAmoc_34.js";import{a as i,i as a,r as o}from"./vendor-zustand-vDaAPGfl.js";import{J as s,Y as c,ot as l,st as u}from"./vendor-base-ui-CzHs0bHY.js";import{bt as d,kt as f}from"./gitApiHttp-CIkpp8g-.js";import{r as p,x as m}from"./useUIStore-CoWJ3ROq.js";import{A as h,k as g}from"./bootstrap-DGkBnhNP.js";import{n as _}from"./vendor-react-DlzBev0S.js";import{i as v}from"./vendor-reactuses-core-DWo5Wn6R.js";import{f as y,r as b,u as x}from"./button-1hulrRFb.js";import{$i as S,Gr as C,Oi as ee,Qn as te,Qr as ne,St as w,Ui as re,V as ie,Zn as T,_a as E,ft as D,ga as O,p as k,w as A,x as j}from"./useMobileNavigationStore-D-EPMP4q.js";import{a as ae,g as M,o as oe,p as N,s as P}from"./fileMentionAutocompleteState-BZJqfgae.js";import{t as se}from"./AgentAvatar-C3ydMP90.js";import{n as F}from"./Icon-0kSL3zYJ.js";import{g as ce,v as le}from"./gitApi-CzQwUwvd.js";import{c as ue,d as de,l as fe,n as pe,r as me,t as he}from"./fileMentionTouchSelection-DC_Tjhr4.js";import{n as ge}from"./textarea-5Kh0UllD.js";import{f as _e,o as ve}from"./projectMeta-C8UBKLh9.js";var I=_(),L=e(u(),1),R=l(),z=L.memo(function(e){let t=(0,I.c)(20),{checked:n,onChange:r,disabled:i,indeterminate:a,ariaLabel:o,className:l,iconClassName:u}=e,d=i!==void 0&&i,f=n||a,p;t[0]===r?p=t[1]:(p=e=>r(!!e),t[0]=r,t[1]=p);let m=f?`border-[color:color-mix(in_srgb,var(--primary-base)_65%,var(--interactive-border))] bg-transparent shadow-none hover:bg-[var(--interactive-hover)] hover:border-[color:color-mix(in_srgb,var(--primary-base)_75%,var(--interactive-border))]`:`border-[var(--interactive-border)] bg-transparent shadow-none hover:bg-[var(--interactive-hover)] hover:border-[var(--interactive-border)]`,h;t[2]!==l||t[3]!==m?(h=b(`group/checkbox relative flex shrink-0 self-center items-center justify-center rounded-[4px] border outline-none`,`h-[14px] w-[14px] min-h-[14px] min-w-[14px]`,`transition-[background-color,border-color,box-shadow] duration-200 ease-out`,m,`focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-1 focus-visible:ring-offset-transparent`,`disabled:cursor-not-allowed disabled:opacity-50`,l),t[2]=l,t[3]=m,t[4]=h):h=t[4];let g;t[5]===u?g=t[6]:(g=b(`flex items-center justify-center text-[var(--primary-base)]`,`data-[unchecked]:hidden`,u),t[5]=u,t[6]=g);let _;t[7]===a?_=t[8]:(_=a?(0,R.jsx)(F,{name:`subtract`,className:b(`h-[10px] w-[10px] min-h-[10px] min-w-[10px]`,`text-[var(--primary-base)]`)}):(0,R.jsx)(F,{name:`check`,className:b(`h-[10px] w-[10px] min-h-[10px] min-w-[10px]`,`text-[var(--primary-base)]`)}),t[7]=a,t[8]=_);let v;t[9]!==g||t[10]!==_?(v=(0,R.jsx)(s,{keepMounted:!0,className:g,children:_}),t[9]=g,t[10]=_,t[11]=v):v=t[11];let y;return t[12]!==o||t[13]!==n||t[14]!==d||t[15]!==a||t[16]!==p||t[17]!==h||t[18]!==v?(y=(0,R.jsx)(c,{checked:n,onCheckedChange:p,disabled:d,indeterminate:a,"aria-label":o,className:h,children:v}),t[12]=o,t[13]=n,t[14]=d,t[15]=a,t[16]=p,t[17]=h,t[18]=v,t[19]=y):y=t[19],y}),B=(e,t)=>{let n=t.trim();if(!n)return[...e].sort((e,t)=>e.isBuiltIn===t.isBuiltIn?e.name.localeCompare(t.name):e.isBuiltIn?-1:1);let r=M([...e],n,e=>[e.name,e.description??``]);return r.sort((e,t)=>e.score===t.score?e.item.isBuiltIn===t.item.isBuiltIn?e.item.name.localeCompare(t.item.name):e.item.isBuiltIn?-1:1:e.score-t.score),r.map(e=>e.item)},ye=(e,t)=>e===t||e.length===t.length&&e.every((e,n)=>{let r=t[n];return r!=null&&e.id===r.id&&e.title===r.title&&(e.subtitle??``)===(r.subtitle??``)&&(e.badge??``)===(r.badge??``)&&e.iconName===r.iconName&&e.agentName===r.agentName}),be=(e,t)=>e.highlightedIndex===t.highlightedIndex&&ye(e.rows,t.rows),xe=(e,t)=>ye(e,t)?e:t.slice(),Se=(e,t,n)=>{e&&(t.current&&be(t.current,n)||(t.current=n,e(n)))},Ce=(e,t)=>{t.current=null,e?.({rows:[],highlightedIndex:0})},V=e=>{if(!e)return``;let t=e.replace(/\\/g,`/`),n=t.startsWith(`//`),r=t.replace(/\/+/g,`/`);n&&!r.startsWith(`//`)&&(r=`/${r}`);let i=r===`/`,a=/^[A-Za-z]:\/$/.test(r);return!i&&!a&&(r=r.replace(/\/+$/,``)),r},H=e=>/^[A-Za-z]:\//.test(e)?e.toLowerCase():e,U=(e,t)=>{let n=V(t),r=V(e);if(!n||!r)return!1;let i=H(n),a=H(r);return a===i||a.startsWith(`${i}/`)},we=e=>{if(!e||typeof e!=`object`)return{};let t=e,n={};for(let[e,r]of Object.entries(t)){let t=V(e);if(!t||!r||typeof r!=`object`)continue;let i=r,a=Array.isArray(i.openPaths)?Array.from(new Set(i.openPaths.filter(e=>typeof e==`string`).map(e=>V(e)).filter(e=>U(e,t)))):[],o=Array.isArray(i.expandedPaths)?Array.from(new Set(i.expandedPaths.filter(e=>typeof e==`string`).map(e=>V(e)).filter(e=>U(e,t)))):[],s=typeof i.selectedPath==`string`?V(i.selectedPath):null,c=s&&U(s,t)?s:a[0]??null,l=typeof i.touchedAt==`number`&&Number.isFinite(i.touchedAt)?i.touchedAt:Date.now(),u=n[t];if(u){let e=Array.from(new Set([...u.openPaths,...a])),r=Array.from(new Set([...u.expandedPaths,...o]));n[t]={openPaths:e,selectedPath:u.selectedPath??c??e[0]??null,expandedPaths:r,touchedAt:Math.max(u.touchedAt,l)};continue}n[t]={openPaths:a,selectedPath:c,expandedPaths:o,touchedAt:l}}return n},W=(e,t)=>{let n=Object.entries(e);if(n.length<=t)return e;n.sort((e,t)=>(t[1]?.touchedAt??0)-(e[1]?.touchedAt??0));let r={};for(let[e,i]of n.slice(0,t))r[e]=i;return r},G=e=>e?{...e,touchedAt:Date.now()}:{openPaths:[],selectedPath:null,expandedPaths:[],touchedAt:Date.now()},Te=i()(o(a((e,t)=>({byRoot:{},addOpenPath:(t,n,r)=>{let i=V((t||``).trim()),a=V((n||``).trim());!i||!a||!r?.allowOutsideRoot&&!U(a,i)||e(e=>{let t=e.byRoot[i],n=G(t),r=n.openPaths.includes(a),o=r?n.openPaths:[...n.openPaths,a],s=n.selectedPath??a;return t&&r&&t.selectedPath===s?e:{byRoot:W({...e.byRoot,[i]:{...n,openPaths:o,selectedPath:s}},20)}})},removeOpenPath:(t,n)=>{let r=V((t||``).trim()),i=V((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=H(i),a=e=>H(e)===n,o=t.selectedPath?a(t.selectedPath):!1;if(!t.openPaths.some(a)&&!o)return e;let s=t.openPaths.filter(e=>!a(e)),c=o?s[0]??null:t.selectedPath;return{byRoot:W({...e.byRoot,[r]:{...t,openPaths:s,selectedPath:c,touchedAt:Date.now()}},20)}})},removeOpenPathsByPrefix:(t,n)=>{let r=V((t||``).trim()),i=V((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=H(i),a=n.endsWith(`/`)?n:`${n}/`,o=e=>{let t=H(e);return t===n||t.startsWith(a)},s=t.openPaths.filter(e=>!o(e));if(s.length===t.openPaths.length)return e;let c=t.selectedPath&&o(t.selectedPath)?s[0]??null:t.selectedPath;return{byRoot:W({...e.byRoot,[r]:{...t,openPaths:s,selectedPath:c,touchedAt:Date.now()}},20)}})},removeExpandedPathsByPrefix:(t,n)=>{let r=V((t||``).trim()),i=V((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=H(i),a=n.endsWith(`/`)?n:`${n}/`,o=t.expandedPaths.filter(e=>{let t=H(e);return t!==n&&!t.startsWith(a)});return o.length===t.expandedPaths.length?e:{byRoot:W({...e.byRoot,[r]:{...t,expandedPaths:o,touchedAt:Date.now()}},20)}})},setSelectedPath:(t,n,r)=>{let i=V((t||``).trim()),a=n?V(n.trim()):null;!i||a&&!r?.allowOutsideRoot&&!U(a,i)||e(e=>{let t=e.byRoot[i],n=G(t),r=a&&!n.openPaths.includes(a)?[...n.openPaths,a]:n.openPaths;return t&&t.selectedPath===a&&r===t.openPaths?e:{byRoot:W({...e.byRoot,[i]:{...n,openPaths:r,selectedPath:a}},20)}})},ensureSelectedPath:e=>{let n=V((e||``).trim());if(!n)return;let r=t().byRoot[n];if(!r||r.selectedPath)return;let i=r.openPaths[0]??null;i&&t().setSelectedPath(n,i)},toggleExpandedPath:(t,n)=>{let r=V((t||``).trim()),i=V((n||``).trim());!r||!i||!U(i,r)||e(e=>{let t=e.byRoot[r],n=G(t),a=n.expandedPaths.includes(i)?n.expandedPaths.filter(e=>e!==i):[...n.expandedPaths,i];return t&&t.expandedPaths===a&&t.selectedPath===n.selectedPath&&t.openPaths===n.openPaths?e:{byRoot:W({...e.byRoot,[r]:{...n,expandedPaths:a}},20)}})},expandPath:(t,n)=>{let r=V((t||``).trim()),i=V((n||``).trim());!r||!i||!U(i,r)||e(e=>{let t=e.byRoot[r],n=G(t);return n.expandedPaths.includes(i)&&t?e:{byRoot:W({...e.byRoot,[r]:{...n,expandedPaths:[...n.expandedPaths,i]}},20)}})},expandPaths:(t,n)=>{let r=V((t||``).trim());if(!r||!n||n.length===0)return;let i=n.map(e=>V((e||``).trim())).filter(e=>e&&U(e,r));i.length!==0&&e(e=>{let t=e.byRoot[r],n=G(t),a=new Set(n.expandedPaths),o=i.filter(e=>!a.has(e));return o.length===0?e:{byRoot:W({...e.byRoot,[r]:{...n,expandedPaths:[...n.expandedPaths,...o]}},20)}})}}),{name:`files-view-tabs-store`,version:2,storage:m(),migrate:e=>{if(!e||typeof e!=`object`)return{byRoot:{}};let t=e.byRoot;return{byRoot:we(t)}},partialize:e=>({byRoot:we(e.byRoot)})}),{name:`files-view-tabs-store`})),Ee=(e,t)=>{let n=(0,I.c)(4),r=t===void 0?200:t,[i,a]=L.useState(e),o,s;return n[0]!==r||n[1]!==e?(o=()=>{let t=window.setTimeout(()=>{a(e)},r);return()=>{window.clearTimeout(t)}},s=[e,r],n[0]=r,n[1]=e,n[2]=o,n[3]=s):(o=n[2],s=n[3]),L.useEffect(o,s),i},De=()=>{let e=(0,I.c)(17),t=k(Oe),n=w(),r;e[0]===t?r=e[1]:(r=e=>t?e.getAttachment(t):void 0,e[0]=t,e[1]=r);let i=A(r),a=k(ke),o=k(Ae),s=E(K),c=E(q),l=d(J);if(t){let r;e[2]===i?r=e[3]:(r=j(i),e[2]=i,e[3]=r);let o=r;if(o)return o;let s;e[4]!==t||e[5]!==a?(s=a.get(t),e[4]=t,e[5]=a,e[6]=s):s=e[6];let c=s;if(c?.path)return c.path;let l;if(e[7]!==t||e[8]!==n){let r;e[10]===t?r=e[11]:(r=e=>e.id===t,e[10]=t,e[11]=r),l=n.find(r),e[7]=t,e[8]=n,e[9]=l}else l=e[9];let u=l;if(u?.directory)return u.directory}if(o?.open&&(o.bootstrapPendingDirectory||o.directoryOverride))return(o.bootstrapPendingDirectory||o.directoryOverride)??void 0;if(s){let t;if(e[12]!==s||e[13]!==c){let n;e[15]===s?n=e[16]:(n=e=>e.id===s,e[15]=s,e[16]=n),t=c.find(n),e[12]=s,e[13]=c,e[14]=t}else t=e[14];let n=t;if(n?.path)return n.path}return l??void 0};function Oe(e){return e.currentSessionId}function ke(e){return e.worktreeMetadata}function Ae(e){return e.newSessionDraft}function K(e){return e.activeProjectId}function q(e){return e.projects}function J(e){return e.currentDirectory}var je=`bg-transparent font-[inherit] text-[var(--primary-base)]`,Me=(e,t)=>{let n=t.trim().toLowerCase();if(!n)return e;let r=e.toLowerCase();if(!r.includes(n))return e;let i=[],a=0,o=r.indexOf(n);for(;o!==-1;)o>a&&i.push(e.slice(a,o)),i.push((0,R.jsx)(`mark`,{className:je,children:e.slice(o,o+n.length)},`${o}-${n}`)),a=o+n.length,o=r.indexOf(n,a);return a<e.length&&i.push(e.slice(a)),i},Ne=L.forwardRef(({searchQuery:e,onFileSelect:t,onAgentSelect:n,onSkillSelect:r,onSessionSelect:i,onClose:a,style:o,onRowsChange:s},c)=>{let{t:l}=y(),u=De()??``,d=k(e=>e.currentSessionId),m=ne(e=>e.activeSessions),_=ie({enabled:!!i}),te=E(e=>e.activeProjectId),w=E(e=>e.projects),T=L.useMemo(()=>w.find(e=>e.id===te)?.path??null,[te,w]),D=L.useMemo(()=>{let e=T||u;return e?e.replace(/\\/g,`/`).replace(/\/+$/,``):null},[T,u]),O=Te(e=>D?e.byRoot[D]:void 0),A=ee(e=>e.agents),j=f(e=>e.searchFiles),M=Ee(e,180),ce=h(),le=g(),[de,fe]=L.useState([]),[_e,ve]=L.useState(!1),[I,z]=L.useState(0),B=L.useRef(0),ye=L.useRef({query:e,directory:u,ids:[]}),[be,xe]=L.useState(360),[V,H]=L.useState({}),[U,we]=L.useState({}),W=L.useRef([]),G=L.useRef([]),Oe=L.useRef([]),ke=L.useRef(null),Ae=L.useRef(null),K=L.useRef(null);K.current||=he();let q=p(e=>e.isMobile),J=(e??``).trim(),je=S({directory:u||null}),Ne=L.useMemo(()=>r?je.data??[]:[],[r,je.data]),Pe=L.useMemo(()=>{if(!D||!O)return[];let e=[O.selectedPath,...O.openPaths.slice().reverse()].filter(e=>typeof e==`string`&&e.length>0),t=new Set,n=[];for(let r of e){if(t.has(r))continue;t.add(r);let e=r.replace(/\\/g,`/`),i=e.split(`/`).filter(Boolean).pop()||e,a=e.startsWith(`${D}/`)?e.slice(D.length+1):e;n.push({name:i,path:e,relativePath:a,extension:i.includes(`.`)?i.split(`.`).pop()?.toLowerCase():void 0})}return P(n,J,{limit:6})},[J,D,O]),Y=L.useMemo(()=>n?re(A).filter(e=>e.mode!==`primary`):[],[A,n]),Fe=L.useMemo(()=>i?ae({sessions:C(m,_),currentSessionId:d,searchQuery:J}):[],[m,d,_,J,i]),Ie=Pe,Le=de,X=L.useMemo(()=>ue({skills:Ne,agents:Y,sessions:Fe,recentFiles:Ie,pathHits:Le,searchQuery:J,untitledSession:l(`chat.fileMentionAutocomplete.untitledSession`),sessionBadge:l(`chat.fileMentionAutocomplete.sessionType`),skillBadge:l(`chat.commandAutocomplete.badge.skill`)}),[Ne,Y,Fe,Ie,Le,J,l]);L.useEffect(()=>{let e=e=>{let t=e.target;!t||!ke.current||ke.current.contains(t)||a()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},[a]),L.useEffect(()=>{if(!u){fe([]);return}let e=(M??``).trim(),t=N(e);if(!t){fe([]);return}let n=!1;ve(!0);let r={includeHidden:ce,respectGitignore:!le};return Promise.all([j(u,t,80,{...r,type:`file`}),j(u,t,40,{...r,type:`directory`})]).then(([t,r])=>{if(n)return;let i=new Set(Pe.map(e=>e.path));fe(oe({files:t,directories:r,query:e,excludePaths:i,limit:20}))}).catch(()=>{n||fe([])}).finally(()=>{n||ve(!1)}),()=>{n=!0}},[u,M,Pe,j,ce,le]),L.useLayoutEffect(()=>{let t=ye.current,n=t.ids[B.current],r=t.query===e&&t.directory===u?Math.max(0,X.findIndex(e=>e.id===n)):0;ye.current={query:e,directory:u,ids:X.map(e=>e.id)},B.current=r,z(r)},[X,e,u]),L.useEffect(()=>{H({}),we({})},[X]),L.useEffect(()=>{W.current[I]?.scrollIntoView({block:`nearest`})},[I]),L.useEffect(()=>{let e=null,t=()=>{e!==null&&cancelAnimationFrame(e),e=requestAnimationFrame(()=>{let e={},t={};G.current.forEach((n,r)=>{if(!n)return;let i=Oe.current[r]?.offsetWidth??n.scrollWidth,a=Math.max(0,i-n.clientWidth),o=a>8;if(e[r]=o,o){let e=Math.max(.6,a/110);t[r]=e}}),H(e),we(t)})};return t(),window.addEventListener(`resize`,t),()=>{e!==null&&cancelAnimationFrame(e),window.removeEventListener(`resize`,t)}},[X]),L.useEffect(()=>{let e=G.current[I];if(!e)return;let t=()=>{let t=e.clientWidth;t>0&&xe(t)};if(t(),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(t);return n.observe(e),()=>{n.disconnect()}},[I]);let Re=v(e=>{t(e)}),ze=v(e=>{n?.(e)}),Be=v(e=>{i?.(e)}),Ve=v(e=>{r?.(e)}),He=(e,t)=>({onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{e.pointerType===`touch`&&K.current?.pointerDown(e.clientX,e.clientY)},onPointerMove:e=>{e.pointerType===`touch`&&K.current?.pointerMove(e.clientX,e.clientY)},onPointerUp:e=>{e.pointerType===`touch`&&(K.current?.pointerUp(t)??!1)&&(e.preventDefault(),e.stopPropagation())},onPointerCancel:()=>K.current?.pointerCancel(),onClick:()=>{K.current?.click(t)},onMouseMove:()=>{B.current=e,z(e)}}),Ue=e=>{let t=X.length;if(t===0)return;let n=(e%t+t)%t,r=X[n];if(r.agentName!==void 0){ze(r.agentName);return}if(r.id.startsWith(`skill:`)){let e=Ne.find(e=>r.id===`skill:${e.name}-${e.scope}`);e&&Ve(e);return}if(r.id.startsWith(`session:`)){let e=Fe.find(e=>r.id===`session:${e.id}`);e&&Be(e);return}let i=r.id.startsWith(`recent:`)?Ie.find(e=>r.id===`recent:${e.path}`):Le.find(e=>r.id===`file:${e.path}`);i&&Re(i)};L.useEffect(()=>{Se(s,Ae,{rows:X,highlightedIndex:I})},[s,I,X]);let We=L.useRef(s);return We.current=s,L.useEffect(()=>()=>{Ce(We.current,Ae)},[]),L.useImperativeHandle(c,()=>({acceptIndex:e=>{Ue(e)},handleKeyDown:e=>{if(e===`Escape`){a();return}let t=X.length;if(t!==0){if(e===`ArrowDown`){B.current=(B.current+1)%t,z(B.current);return}if(e===`ArrowUp`){B.current=(B.current-1+t)%t,z(B.current);return}(e===`Enter`||e===`Tab`)&&Ue(B.current)}}})),(0,R.jsxs)(pe,{ref:ke,isMobile:q,className:`max-w-[640px] max-h-64`,style:o,children:[(0,R.jsx)(ge,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0`,children:(0,R.jsxs)(`div`,{className:`py-1`,children:[X.map((e,t)=>{let n=e.id.startsWith(`file:`)||e.id.startsWith(`recent:`),r=n?x(e.title,{maxLength:60}):e.title,i=I===t,a=V[t]??!1,o=U[t]??2.6;return(0,R.jsxs)(`div`,{"data-mention-id":e.id,ref:e=>{W.current[t]=e},className:b(`flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,q&&`min-h-11`,me(q,i),!q&&i&&`text-interactive-selection-foreground`),...He(t,()=>Ue(t)),children:[(0,R.jsx)(`span`,{className:`flex size-5 shrink-0 items-center justify-center`,children:e.agentName===void 0?(0,R.jsx)(F,{name:e.iconName,className:`size-3.5 text-current`}):(0,R.jsx)(se,{name:e.agentName,size:20})}),(0,R.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,R.jsxs)(`div`,{className:`flex min-w-0 items-baseline gap-2`,children:[(0,R.jsxs)(`span`,{ref:e=>{G.current[t]=e},className:b(`relative block min-w-0 overflow-hidden`,n&&a&&i&&`file-mention-marquee-container`),style:i?{"--file-mention-marquee-width":`${be}px`,"--file-mention-marquee-duration":`${o}s`}:void 0,title:e.title,children:[(0,R.jsx)(`span`,{ref:e=>{Oe.current[t]=e},className:`absolute invisible whitespace-nowrap pointer-events-none`,"aria-hidden":!0,children:e.title}),n&&a&&i?(0,R.jsx)(`span`,{className:`inline-block whitespace-nowrap file-mention-marquee`,children:Me(e.title,J)}):(0,R.jsx)(`span`,{className:`block truncate`,children:Me(r,J)})]}),e.trailingLabel?(0,R.jsx)(`span`,{className:b(`max-w-[40%] shrink-0 truncate text-muted-foreground`,q?`typography-micro`:`typography-meta`),children:e.trailingLabel}):null]}),e.subtitle?(0,R.jsx)(`div`,{className:b(`truncate text-muted-foreground`,q?`typography-micro`:`typography-meta`),children:Me(e.subtitle,J)}):null]})]},e.id)}),_e&&Le.length===0?(0,R.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,R.jsx)(F,{name:`refresh`,className:`h-4 w-4 animate-spin text-muted-foreground`})}):null,!_e&&X.length===0&&(0,R.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:l(`chat.fileMentionAutocomplete.empty`)})]})}),!q&&(0,R.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:l(`chat.autocomplete.keyboardHint`)})]})}),Pe=new Set([`new`,`fork`,`compact`,`reload`,`undo`,`redo`,`model`,`btw`]),Y=(e,t)=>{if(!t||e.isSkill)return!1;let n=e.name?.trim().toLowerCase();return!!(n&&Pe.has(n))},Fe=(e,t)=>!e||t({name:e}),Ie=` `,Le=(e,t)=>{let n=Math.max(0,Math.min(t,e.length)),r=n;for(;r>0&&!/\s/.test(e[r-1]);)--r;return r>=2&&e[r-1]===Ie&&e[r-2]===`/`&&(r-=2),e[r]===`/`?{start:r,end:n}:null},X=`text-[10px] leading-none uppercase font-bold tracking-tight px-1.5 py-1 rounded border flex-shrink-0`,Re=b(X,`bg-[color-mix(in_srgb,var(--primary-base)_12%,transparent)] text-[color-mix(in_srgb,var(--primary-base)_70%,transparent)] border-[color-mix(in_srgb,var(--primary-base)_24%,transparent)]`),ze=b(X,`bg-[color-mix(in_srgb,var(--status-success)_12%,transparent)] text-[color-mix(in_srgb,var(--status-success)_70%,transparent)] border-[color-mix(in_srgb,var(--status-success)_24%,transparent)]`),Be=b(X,`bg-[color-mix(in_srgb,var(--status-info)_12%,transparent)] text-[color-mix(in_srgb,var(--status-info)_70%,transparent)] border-[color-mix(in_srgb,var(--status-info)_24%,transparent)]`),Ve=b(X,`bg-[var(--surface-muted)] text-muted-foreground border-[var(--interactive-border)]/60`),He=(e,t)=>e.length===t.length&&e.every((e,n)=>e.id===t[n]?.id&&e.description===t[n]?.description),Ue=e=>{let t=!!e.sessionID;return{hasSession:t,canStartSessionCommand:t||e.hasNewDraft}},We=L.forwardRef(({searchQuery:e,onCommandSelect:t,onClose:n,directory:i,style:a,commandPolicy:o,commandContext:s,onRowsChange:c},l)=>{let{t:u}=y(),d=p(e=>e.isMobile),f=k(e=>e.currentSessionId),m=k(e=>!!e.newSessionDraft?.open),h=k(L.useCallback(e=>f?e.getDirectoryForSession(f):void 0,[f])),g=D(f??``,h??void 0),_=L.useMemo(()=>s??{sessionID:f??null,hasMessages:g.length>0,hasNewDraft:m},[s,f,g.length,m]),{hasSession:v,canStartSessionCommand:x}=L.useMemo(()=>Ue(_),[_]),S=_.hasMessages,[C,ee]=L.useState([]),[te,ne]=L.useState(!1),w=O({directory:i}),re=L.useMemo(()=>w.data??[],[w.data]),ie=w.isFetching,[T,E]=L.useState(0),A=L.useRef(0),j=L.useRef(!1),ae=L.useRef([]),M=L.useRef(null),oe=L.useRef(!1),N=L.useRef(null),P=L.useRef(!1),se=L.useRef(null);L.useEffect(()=>{let e=e=>{let t=e.target;!t||!M.current||M.current.contains(t)||n()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},[n]),L.useEffect(()=>{(async()=>{ne(ie);try{let t=re.flatMap((e,t)=>e.source===`skill`?[]:[{id:`opencode:${e.scope??`global`}:${e.name}:${e.agent??``}:${e.model??``}:${t}`,name:e.name,source:`opencode`,description:e.description,agent:e.agent??void 0,model:e.model??void 0,isBuiltIn:e.isBuiltIn,scope:e.scope,reference:e.reference}]),n=[{id:`yuri:new`,name:`new`,source:`yuri`,description:u(`chat.commandAutocomplete.command.newDescription`),isBuiltIn:!0},...v&&!S?[{id:`yuri:init`,name:`init`,source:`yuri`,description:u(`chat.commandAutocomplete.command.initDescription`),isBuiltIn:!0}]:[],...v?[{id:`yuri:btw`,name:`btw`,source:`yuri`,description:u(`chat.btw.description`),isBuiltIn:!0},{id:`yuri:undo`,name:`undo`,source:`yuri`,description:u(`chat.commandAutocomplete.command.undoDescription`),isBuiltIn:!0},{id:`yuri:redo`,name:`redo`,source:`yuri`,description:u(`chat.commandAutocomplete.command.redoDescription`),isBuiltIn:!0},{id:`yuri:fork`,name:`fork`,source:`yuri`,description:u(`chat.commandAutocomplete.command.forkDescription`),isBuiltIn:!0},{id:`yuri:timeline`,name:`timeline`,source:`yuri`,description:u(`chat.commandAutocomplete.command.timelineDescription`),isBuiltIn:!0}]:[],{id:`yuri:model`,name:`model`,source:`yuri`,description:u(`chat.commandAutocomplete.command.modelDescription`),isBuiltIn:!0},{id:`yuri:compact`,name:`compact`,source:`yuri`,description:u(`chat.commandAutocomplete.command.compactDescription`),isBuiltIn:!0},...r()?[{id:`yuri:reload`,name:`reload`,source:`yuri`,description:u(`chat.commandAutocomplete.command.reloadDescription`),isBuiltIn:!0}]:[],...v?[{id:`yuri:summary`,name:`summary`,source:`yuri`,description:u(`chat.commandAutocomplete.command.summaryDescription`),isYuri:!0}]:[],...x?[{id:`yuri:workspace-review`,name:`workspace-review`,source:`yuri`,description:u(`chat.commandAutocomplete.command.workspaceReviewDescription`),isYuri:!0}]:[],...x?[{id:`yuri:craft-goal`,name:`craft-goal`,source:`yuri`,description:u(`chat.commandAutocomplete.command.craftGoalDescription`),isYuri:!0}]:[],...x?[{id:`yuri:catch-up`,name:`catch-up`,source:`yuri`,description:u(`chat.commandAutocomplete.command.catchUpDescription`),isYuri:!0}]:[],...x?[{id:`yuri:debug`,name:`debug`,source:`yuri`,description:u(`chat.commandAutocomplete.command.debugDescription`),isYuri:!0}]:[],...x?[{id:`yuri:weigh`,name:`weigh`,source:`yuri`,description:u(`chat.commandAutocomplete.command.weighDescription`),isYuri:!0}]:[],...x?[{id:`yuri:explore`,name:`explore`,source:`yuri`,description:u(`chat.commandAutocomplete.command.exploreDescription`),isYuri:!0}]:[],...t],i=!S,a=B(n.filter(e=>(i||e.name!==`init`)&&(o?.(e)??!0)),e);ee(e=>He(e,a)?e:a)}catch{let t=!S,n=B([{id:`yuri:new`,name:`new`,source:`yuri`,description:u(`chat.commandAutocomplete.command.newDescription`),isBuiltIn:!0},...v&&!S?[{id:`yuri:init`,name:`init`,source:`yuri`,description:u(`chat.commandAutocomplete.command.initDescription`),isBuiltIn:!0}]:[],...v?[{id:`yuri:btw`,name:`btw`,source:`yuri`,description:u(`chat.btw.description`),isBuiltIn:!0},{id:`yuri:undo`,name:`undo`,source:`yuri`,description:u(`chat.commandAutocomplete.command.undoDescription`),isBuiltIn:!0},{id:`yuri:redo`,name:`redo`,source:`yuri`,description:u(`chat.commandAutocomplete.command.redoDescription`),isBuiltIn:!0},{id:`yuri:fork`,name:`fork`,source:`yuri`,description:u(`chat.commandAutocomplete.command.forkDescription`),isBuiltIn:!0},{id:`yuri:timeline`,name:`timeline`,source:`yuri`,description:u(`chat.commandAutocomplete.command.timelineDescription`),isBuiltIn:!0}]:[],{id:`yuri:model`,name:`model`,source:`yuri`,description:u(`chat.commandAutocomplete.command.modelDescription`),isBuiltIn:!0},{id:`yuri:compact`,name:`compact`,source:`yuri`,description:u(`chat.commandAutocomplete.command.compactDescription`),isBuiltIn:!0},...r()?[{id:`yuri:reload`,name:`reload`,source:`yuri`,description:u(`chat.commandAutocomplete.command.reloadDescription`),isBuiltIn:!0}]:[],...v?[{id:`yuri:summary`,name:`summary`,source:`yuri`,description:u(`chat.commandAutocomplete.command.summaryDescription`),isYuri:!0}]:[],...x?[{id:`yuri:workspace-review`,name:`workspace-review`,source:`yuri`,description:u(`chat.commandAutocomplete.command.workspaceReviewDescription`),isYuri:!0}]:[],...x?[{id:`yuri:craft-goal`,name:`craft-goal`,source:`yuri`,description:u(`chat.commandAutocomplete.command.craftGoalDescription`),isYuri:!0}]:[],...x?[{id:`yuri:catch-up`,name:`catch-up`,source:`yuri`,description:u(`chat.commandAutocomplete.command.catchUpDescription`),isYuri:!0}]:[],...x?[{id:`yuri:debug`,name:`debug`,source:`yuri`,description:u(`chat.commandAutocomplete.command.debugDescription`),isYuri:!0}]:[],...x?[{id:`yuri:weigh`,name:`weigh`,source:`yuri`,description:u(`chat.commandAutocomplete.command.weighDescription`),isYuri:!0}]:[],...x?[{id:`yuri:explore`,name:`explore`,source:`yuri`,description:u(`chat.commandAutocomplete.command.exploreDescription`),isYuri:!0}]:[]].filter(e=>(t||e.name!==`init`)&&(o?.(e)??!0)),e);ee(e=>He(e,n)?e:n)}finally{ne(!1)}})()},[e,S,v,x,re,ie,u,o]),L.useEffect(()=>{E(0)},[C]),L.useEffect(()=>{A.current=T},[T]),L.useEffect(()=>{ae.current[T]?.scrollIntoView({block:`nearest`})},[T]),L.useEffect(()=>{Se(c,se,{rows:fe(C,{skill:u(`chat.commandAutocomplete.badge.skill`),command:u(`chat.commandAutocomplete.badge.command`),system:u(`chat.commandAutocomplete.badge.system`)}),highlightedIndex:T})},[C,c,T,u]);let ce=L.useRef(c);ce.current=c,L.useEffect(()=>()=>{Ce(ce.current,se)},[]),L.useImperativeHandle(l,()=>({acceptIndex:(e,n=!0)=>{let r=C[e];r&&t(r,Y(r,n))},handleKeyDown:e=>{let r=C.length;if(e===`Escape`){n();return}if(r!==0){if(e===`ArrowDown`){j.current=!0,E(e=>(e+1)%r);return}if(e===`ArrowUp`){j.current=!0,E(e=>(e-1+r)%r);return}if(e===`Enter`||e===`Tab`){let n=(A.current%r+r)%r,i=C[n];i&&t(i,Y(i,e===`Enter`))}}}}),[C,n,t]);let le=e=>{let t=de(e);switch(e.name){case`new`:return(0,R.jsx)(F,{name:t,className:`h-3.5 w-3.5`});case`init`:return(0,R.jsx)(F,{name:t,className:`h-3.5 w-3.5 text-green-500`});case`undo`:return(0,R.jsx)(F,{name:t,className:`h-3.5 w-3.5 text-orange-500`});case`redo`:return(0,R.jsx)(F,{name:t,className:`h-3.5 w-3.5 text-orange-500`});case`timeline`:case`reload`:return(0,R.jsx)(F,{name:t,className:`h-3.5 w-3.5`});case`compact`:return(0,R.jsx)(F,{name:t,className:`h-3.5 w-3.5 text-purple-500`});case`goal`:return(0,R.jsx)(F,{name:t,className:`h-3.5 w-3.5`});case`review`:return(0,R.jsx)(F,{name:t,className:`h-3.5 w-3.5 text-blue-500`});case`test`:case`build`:case`run`:return(0,R.jsx)(F,{name:t,className:`h-3.5 w-3.5 text-cyan-500`});default:return e.isBuiltIn?(0,R.jsx)(F,{name:t,className:`h-3.5 w-3.5 text-yellow-500`}):(0,R.jsx)(F,{name:t,className:`h-3.5 w-3.5 text-muted-foreground`})}};return(0,R.jsxs)(pe,{ref:M,isMobile:d,className:`max-w-[450px] max-h-64`,style:a,children:[(0,R.jsx)(ge,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0 py-1.5`,children:te?(0,R.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,R.jsx)(F,{name:`refresh`,className:`h-4 w-4 animate-spin text-muted-foreground`})}):(0,R.jsxs)(`div`,{children:[C.map((n,r)=>{let i=n.isBuiltIn,a=n.isYuri;return(0,R.jsxs)(`div`,{ref:e=>{ae.current[r]=e},className:b(`flex gap-2 px-2 py-2 cursor-pointer rounded-lg`,d?`items-center`:`items-start`,me(d,r===T),!d&&r===T&&`bg-interactive-selection/35`),onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{e.pointerType===`touch`&&(N.current={x:e.clientX,y:e.clientY},P.current=!1)},onPointerMove:e=>{if(e.pointerType!==`touch`||!N.current)return;let t=e.clientX-N.current.x,n=e.clientY-N.current.y;Math.hypot(t,n)>6&&(P.current=!0)},onPointerUp:e=>{if(e.pointerType!==`touch`)return;let r=P.current;N.current=null,P.current=!1,!r&&(e.preventDefault(),e.stopPropagation(),oe.current=!0,t(n,Y(n,d)))},onPointerCancel:()=>{N.current=null,P.current=!1},onClick:()=>{if(oe.current){oe.current=!1;return}t(n,Y(n,d))},onMouseMove:()=>{j.current=!1,E(r)},children:[(0,R.jsx)(`div`,{className:b(!d&&`mt-0.5`),children:le(n)}),(0,R.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsxs)(`span`,{className:`typography-ui-label font-medium`,children:[`/`,Me(n.name,e)]}),n.isSkill?(0,R.jsx)(`span`,{className:Re,children:u(`chat.commandAutocomplete.badge.skill`)}):(0,R.jsx)(`span`,{className:Re,children:u(`chat.commandAutocomplete.badge.command`)}),a?(0,R.jsx)(`span`,{className:Ve,children:`Yuri`}):i?(0,R.jsx)(`span`,{className:Ve,children:u(`chat.commandAutocomplete.badge.system`)}):n.scope?(0,R.jsx)(`span`,{className:n.scope===`project`?Be:ze,children:n.scope}):null,n.agent&&(0,R.jsx)(`span`,{className:Ve,children:n.agent})]}),n.description&&!d&&(0,R.jsx)(`div`,{className:`typography-meta text-muted-foreground mt-0.5 truncate`,children:Me(n.description,e)})]})]},n.id)}),C.length===0&&(0,R.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:u(`chat.commandAutocomplete.empty`)})]})}),!d&&(0,R.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:u(`chat.autocomplete.keyboardHint`)})]})});We.displayName=`CommandAutocomplete`;var Ge=e=>e instanceof Error?e.name===`AbortError`||e.name===`CancelledError`||e.name===`Error`&&e.message===`CancelledError`:!1,Ke=1e4,qe=6e4,Je=5e3,Ye=3e4,Xe=6e4,Ze=25,Qe=40,$e=2,et=15e3,tt=500,nt=30,rt=20971520,it=new Map,at=new Map,ot=new Map,st=new Map,ct=new Map,lt=new Map,ut=new WeakMap,dt=e=>{let t=ut.get(e);return t||(t=new Set(e.files.map(e=>e.path)),ut.set(e,t)),t},ft=(e,t)=>`${t}:${e}`,pt=e=>at.get(e)??0,mt=e=>{let t=pt(e)+1;return at.set(e,t),t},ht=e=>{let t=(ot.get(e)??0)+1;return ot.set(e,t),t},gt=e=>{let t=it.get(e);if(t)return t;let n=new Set;return it.set(e,n),n},Z=()=>({isGitRepo:null,status:null,branches:null,branchesTransportIdentity:null,log:null,identity:null,diffCache:new Map,indexRevision:0,lastRepoCheckAt:0,lastStatusFetch:0,lastStatusChange:0,lastLogFetch:0,lastBranchesFetch:0,lastIdentityFetch:0,logMaxCount:25,isLoadingStatus:!1,isLoadingLog:!1,isLoadingBranches:!1,isLoadingIdentity:!1}),_t=(e,t=nt,n=rt)=>{let r=0;for(let t of e.values())r+=(t.original?.length??0)+(t.modified?.length??0);if(e.size<=t&&r<=n)return e;let i=Array.from(e.entries()).sort((e,t)=>e[1].fetchedAt-t[1].fetchedAt),a=new Map,o=0;for(let e=i.length-1;e>=0;e--){let[r,s]=i[e],c=(s.original?.length??0)+(s.modified?.length??0);if(a.size>=t)break;o+c>n&&a.size>0||(a.set(r,s),o+=c)}return a},vt=(e,t)=>!e&&!t?!1:!e||!t||e.remote!==t.remote||e.branch!==t.branch||e.ahead!==t.ahead||e.behind!==t.behind,yt=e=>{let t=e?.trim()??``;return t===`?`?``:t},bt=(e,t)=>{let n=new Set,r=!1,i=!e;e&&(i=e.ahead!==t.ahead||e.behind!==t.behind||e.current!==t.current||e.tracking!==t.tracking||e.isClean!==t.isClean||t.upstreamComparison!==void 0&&vt(e.upstreamComparison,t.upstreamComparison)||t.diffStats!==void 0&&e.diffStats===void 0);let a=new Map;for(let t of e?.files??[])a.set(t.path,t);for(let e of t.files??[]){let t=a.get(e.path);if(!t){n.add(e.path),yt(e.index)&&(r=!0);continue}a.delete(e.path),(t.index!==e.index||t.working_dir!==e.working_dir)&&n.add(e.path),!r&&yt(t.index)!==yt(e.index)&&(r=!0)}for(let[e,t]of a)n.add(e),yt(t.index)&&(r=!0);let o=t.diffStats,s=e?.diffStats;if(o!==void 0&&o!==s){let e=s??{};for(let t in o){let r=o[t],i=e[t];(!i||i.insertions!==r.insertions||i.deletions!==r.deletions)&&n.add(t)}for(let t in e)t in o||n.add(t)}return{changed:i||n.size>0,changedPaths:n,indexChanged:r}},xt=e=>!e||e.trim().length===0,St=e=>(e||``).trim()===`U`,Ct=e=>{let t=(e.index||``).trim(),n=(e.working_dir||``).trim();if(St(t)||St(n))return e;let r=t===`?`||n===`?`?`A`:t||n||` `;return{...e,index:r,working_dir:` `}},wt=e=>{let t=(e.index||``).trim(),n=(e.working_dir||``).trim();if(St(t)||St(n))return e;let r=n||(t===`A`||t===`?`?`?`:t)||` `;return{...e,index:` `,working_dir:r}},Tt=e=>xt(e.index)&&xt(e.working_dir),Q=i()(o((e,t)=>({directories:new Map,activeDirectory:null,setActiveDirectory:n=>{let{activeDirectory:r,directories:i}=t();if(r!==n)if(r&&mt(r),n&&mt(n),n&&!i.has(n)){let t=new Map(i);t.set(n,Z()),e({activeDirectory:n,directories:t})}else e({activeDirectory:n})},getDirectoryState:e=>t().directories.get(e)??null,fetchStatus:async(n,r,i={})=>{let a=i.mode??`full`,o=ft(n,a),s=st.get(o)??(a===`light`?st.get(ft(n,`full`)):void 0);if(s)return s;let c=(async()=>{let{silent:a=!1}=i,{directories:o}=t(),s=o.get(n);if(s||=Z(),!a){let r=new Map(t().directories),i=r.get(n)??Z();r.set(n,{...i,isLoadingStatus:!0}),e({directories:r})}let c=!1;try{let a=Date.now(),o=s.isGitRepo!==!0||a-(s.lastRepoCheckAt||0)>qe,l=s.isGitRepo===!0;if(o&&(l=await r.checkIsGitRepository(n)),!l){let r=new Map(t().directories),i=r.get(n)??s;return r.set(n,{...i,isGitRepo:!1,status:null,isLoadingStatus:!1,lastRepoCheckAt:a,lastStatusFetch:a}),e({directories:r}),!1}let u=await r.getGitStatus(n,i.mode?{mode:i.mode}:void 0),d=t().directories.get(n)??Z(),f=lt.get(n),p=f?.received===u&&f.stored===d.status?null:bt(d.status,u);if(p?.changed){c=!0;let r=new Map(t().directories),i=r.get(n)??Z(),{changedPaths:s,indexChanged:l}=p,d=new Map(i.diffCache);for(let e of s)d.delete(e);let f=s.size>0;f&&mt(n);let m={...u,diffStats:u.diffStats===void 0&&i.status?.diffStats!==void 0?i.status.diffStats:u.diffStats,upstreamComparison:u.upstreamComparison===void 0?i.status?.upstreamComparison:u.upstreamComparison};r.set(n,{...i,isGitRepo:!0,status:m,diffCache:d,indexRevision:l?i.indexRevision+1:i.indexRevision,lastRepoCheckAt:o?a:i.lastRepoCheckAt,lastStatusFetch:Date.now(),lastStatusChange:f?Date.now():i.lastStatusChange}),e({directories:r}),lt.set(n,{received:u,stored:m})}else{lt.set(n,{received:u,stored:d.status});let r=new Map(t().directories),i=r.get(n)??Z();r.set(n,{...i,isGitRepo:!0,lastRepoCheckAt:o?a:i.lastRepoCheckAt,lastStatusFetch:Date.now(),lastStatusChange:i.lastStatusChange}),e({directories:r})}}catch(e){console.error(`Failed to fetch git status:`,e)}finally{if(!a){let r=new Map(t().directories),i=r.get(n)??Z();r.set(n,{...i,isLoadingStatus:!1}),e({directories:r})}}return c})();st.set(o,c);try{return await c}finally{st.get(o)===c&&st.delete(o)}},moveStatusPathsOptimistically:(n,r,i)=>{let a=new Set(r.map(e=>e.trim()).filter(Boolean));if(a.size===0)return null;let{directories:o}=t(),s=o.get(n),c=s?.status??null;if(!s||!c)return c;let l=!1,u=[];for(let e of c.files){if(!a.has(e.path)){u.push(e);continue}let t=i===`stage`?Ct(e):wt(e);t!==e&&(l=!0),Tt(t)?l=!0:u.push(t)}if(!l)return c;let d=new Map(o);return d.set(n,{...s,status:{...c,files:u,isClean:u.length===0},indexRevision:s.indexRevision+1,lastStatusChange:Date.now()}),e({directories:d}),c},restoreStatus:(n,r)=>{let{directories:i}=t(),a=i.get(n);if(!a)return;let o=new Map(i);o.set(n,{...a,status:r,indexRevision:a.indexRevision+1,lastStatusChange:Date.now()}),e({directories:o})},bumpIndexRevision:n=>{let{directories:r}=t(),i=r.get(n);if(!i)return;let a=new Map(r);a.set(n,{...i,indexRevision:i.indexRevision+1}),e({directories:a})},fetchBranches:async(r,i,a={})=>{let o=n(),s=ht(r);{let n=new Map(t().directories),i=n.get(r)??Z();n.set(r,{...i,isLoadingBranches:!0}),e({directories:n})}try{let c=a.force?await te(r,i,void 0,o):await T(r,i,void 0,o);if(s!==ot.get(r)||o!==n())return;let l=new Map(t().directories),u=l.get(r)??Z();l.set(r,{...u,branches:c,branchesTransportIdentity:o,isLoadingBranches:!1,lastBranchesFetch:Date.now()}),e({directories:l})}catch(i){if(Ge(i)||console.error(`Failed to fetch git branches:`,i),s!==ot.get(r)||o!==n())return;let a=new Map(t().directories),c=a.get(r)??Z();a.set(r,{...c,isLoadingBranches:!1}),e({directories:a})}},fetchLog:async(n,r,i)=>{let{directories:a}=t(),o=a.get(n),s=i??o?.logMaxCount??25;{let r=new Map(t().directories),i=r.get(n)??Z();r.set(n,{...i,isLoadingLog:!0}),e({directories:r})}try{let i=await r.getGitLog(n,{maxCount:s}),a=new Map(t().directories),o=a.get(n)??Z();a.set(n,{...o,log:i,isLoadingLog:!1,lastLogFetch:Date.now(),logMaxCount:s}),e({directories:a})}catch(r){console.error(`Failed to fetch git log:`,r);let i=new Map(t().directories),a=i.get(n)??Z();i.set(n,{...a,isLoadingLog:!1}),e({directories:i})}},fetchIdentity:async(n,r)=>{{let r=new Map(t().directories),i=r.get(n)??Z();r.set(n,{...i,isLoadingIdentity:!0}),e({directories:r})}try{let i=await r.getCurrentGitIdentity(n),a=new Map(t().directories),o=a.get(n)??Z();a.set(n,{...o,identity:i,isLoadingIdentity:!1,lastIdentityFetch:Date.now()}),e({directories:a})}catch(r){console.error(`Failed to fetch git identity:`,r);let i=new Map(t().directories),a=i.get(n)??Z();i.set(n,{...a,isLoadingIdentity:!1}),e({directories:i})}},fetchAll:async(n,r,i={})=>{let{directories:a}=t(),o=a.get(n);if(!o){o=Z();let t=new Map(a);t.set(n,o),e({directories:t})}let{force:s=!1,silentIfCached:c=!1}=i,l=Date.now();await t().fetchStatus(n,r,{silent:c&&!!o?.status});let u=t().directories.get(n);if(!u?.isGitRepo)return;await t().fetchBranches(n,r,{force:s});let d=l-(u.lastLogFetch||0);(s||d>Ke||!u.log)&&await t().fetchLog(n,r),await t().fetchIdentity(n,r)},getDiff:(e,n)=>t().directories.get(e)?.diffCache.get(n)??null,setDiff:(n,r,i)=>{let a=new Map(t().directories),o=a.get(n)??Z(),s=new Map(o.diffCache);s.set(r,{...i,fetchedAt:Date.now()});let c=_t(s);a.set(n,{...o,diffCache:c}),e({directories:a})},clearDiffCache:n=>{mt(n);let r=new Map(t().directories),i=r.get(n);i&&(r.set(n,{...i,diffCache:new Map}),e({directories:r}))},fetchAllDiffs:async(e,n)=>{let r=t().directories.get(e);if(!r?.status?.files||r.status.files.length===0)return;let i=r.status.files.map(e=>e.path).slice(0,Ze);await t().prefetchDiffs(e,n,i,{maxFiles:Ze})},prefetchDiffs:async(n,r,i,a={})=>{let o=t().directories.get(n);if(!o?.status?.files||o.status.files.length===0||i.length===0)return;let{maxFiles:s=Qe}=a,c=Math.min(Math.max(1,s),nt),l=dt(o.status),u=o.status.diffStats,d=gt(n),f=[],p=new Set;for(let e of i){if(p.size>=c)break;if(!e||p.has(e)||!l.has(e))continue;let t=u?.[e];t&&t.insertions+t.deletions>tt||(p.add(e),!o.diffCache.has(e)&&(d.has(e)||f.push(e)))}let m=f;if(m.length===0)return;let h=pt(n);if(typeof document<`u`&&document.hidden)return;m.forEach(e=>d.add(e));let g=0,_=[],v=()=>{let e=g;return g+=1,e<m.length?m[e]:null},y=async e=>{let t=r.getGitFileDiff(n,{path:e}),i=new Promise((e,t)=>{setTimeout(()=>t(Error(`Timed out after ${et}ms`)),et)}),a=await Promise.race([t,i]);return{path:e,diff:{original:a.original??``,modified:a.modified??``,isBinary:a.isBinary}}},b=async()=>{for(;;){if(h!==pt(n))return;let e=v();if(!e)return;try{_.push(await y(e))}catch{}finally{d.delete(e)}}},x=Math.min($e,m.length);if(await Promise.allSettled(Array.from({length:x},()=>b())),m.forEach(e=>d.delete(e)),h!==pt(n))return;let S=new Map(t().directories),C=S.get(n);if(!C)return;let ee=new Map(C.diffCache),te=Date.now();_.forEach(e=>{!e.diff.isBinary&&e.diff.original===``&&e.diff.modified===``||ee.set(e.path,{...e.diff,fetchedAt:te})});let ne=_t(ee);S.set(n,{...C,diffCache:ne}),e({directories:S})},setLogMaxCount:(n,r)=>{let i=new Map(t().directories),a=i.get(n)??Z();i.set(n,{...a,logMaxCount:r}),e({directories:i})},ensureStatus:async(e,n)=>{let r=t().directories.get(e),i=Date.now();r?.status&&i-r.lastStatusFetch<Je||await t().fetchStatus(e,n,{silent:!!r?.status})},ensureAll:(e,n)=>{let r=ct.get(e);if(r)return r;let i=(async()=>{let r=t().directories.get(e),i=Date.now();(!r?.status||r.status.diffStats===void 0||i-(r?.lastStatusFetch??0)>=Je)&&await t().fetchStatus(e,n,{silent:!!r?.status});let a=t().directories.get(e);if(!a?.isGitRepo)return;let o=[];(!a.branches||i-a.lastBranchesFetch>=Ye)&&o.push(t().fetchBranches(e,n)),(!a.log||i-a.lastLogFetch>=Ke)&&o.push(t().fetchLog(e,n)),(!a.identity||i-a.lastIdentityFetch>=Xe)&&o.push(t().fetchIdentity(e,n)),o.length>0&&await Promise.all(o)})();return ct.set(e,i),i.finally(()=>{ct.get(e)===i&&ct.delete(e)}),i},refresh:async(e,n={})=>{let{activeDirectory:r}=t();r&&await t().fetchAll(r,e,n)}}),{name:`git-store`})),Et=e=>{let t=(0,I.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.status??null:null,t[0]=e,t[1]=n),Q(n)},Dt=e=>{let r=(0,I.c)(3),i=L.useSyncExternalStore(t,n,n),a;return r[0]!==e||r[1]!==i?(a=t=>{if(!e)return null;let n=t.directories.get(e);return n?.branchesTransportIdentity===i?n.branches:null},r[0]=e,r[1]=i,r[2]=a):a=r[2],Q(a)},Ot=e=>{let t=(0,I.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.log??null:null,t[0]=e,t[1]=n),Q(n)},kt=e=>{let t=(0,I.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.isGitRepo??null:null,t[0]=e,t[1]=n),Q(n)},At=e=>{let t=(0,I.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.status?.current?.trim()??null:null,t[0]=e,t[1]=n),Q(n)},jt=e=>{let t=(0,I.c)(3),n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=new Map,t[0]=n):n=t[0];let r=L.useRef(n),i;return t[1]===e?i=t[2]:(i=t=>{let n=r.current,i=n.size===e.length;if(i)for(let r of e){let e=t.directories.get(r),a=n.get(r);if(!a||(e?.isGitRepo??null)!==a.isGitRepo||(e?.status?.current??null)!==a.branch){i=!1;break}}if(i)return n;let a=new Map;for(let n of e){let e=t.directories.get(n);a.set(n,{isGitRepo:e?.isGitRepo??null,branch:e?.status?.current??null})}return r.current=a,a},t[1]=e,t[2]=i),Q(i)},Mt=e=>{let t=(0,I.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.isLoadingStatus??!1:!1,t[0]=e,t[1]=n),Q(n)},Nt=e=>{let t=(0,I.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.isLoadingLog??!1:!1,t[0]=e,t[1]=n),Q(n)},Pt=e=>{let t=(0,I.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.isLoadingBranches??!1:!1,t[0]=e,t[1]=n),Q(n)},Ft=e=>{let t=String(e||``).trim().replace(/^remotes\//,``);if(!t)return null;let n=t.indexOf(`/`);return n<=0||n>=t.length-1?null:{remote:t.slice(0,n),branch:t.slice(n+1)}},$=e=>String(e||``).trim().replace(/^refs\/heads\//,``).replace(/^heads\//,``).replace(/^remotes\//,``),It=e=>e.branchName?$(e.branchName):e.mode===`existing`?$(e.existingBranch||e.preferredName||``):$(e.preferredName||``),Lt=async e=>{let t=await _e(e);try{let n=Ft((await ce(e)).branches?.[t]?.tracking||null);if(n?.remote)return n.remote}catch{}try{let t=Ft((await le(e)).tracking);if(t?.remote)return t.remote}catch{}return null},Rt=async(e,t)=>{let n=await Lt(e),r=$(t);return!n||!r?null:{setUpstream:!0,upstreamRemote:n,upstreamBranch:r}},zt=async(e,t,n)=>{let r=It(t),i=n?.resolvedRootTrackingRemote,a=i===void 0?await Rt(e,r):i&&$(r)?{setUpstream:!0,upstreamRemote:i,upstreamBranch:$(r)}:null;return a?{...t,setUpstream:t.setUpstream??a.setUpstream,upstreamRemote:t.upstreamRemote||a.upstreamRemote,upstreamBranch:t.upstreamBranch||a.upstreamBranch}:t},Bt=async(e,t,n)=>{let r=await zt(e.path,t,n);return ve(e,r)},Vt=`yuri:lastWorktreeSourceBranch`,Ht=({mode:e,sourceBranch:t,linkedPr:n,selectedBranch:r})=>e===`existing-branch`?r||null:n?null:t||null,Ut=({branches:e,savedSourceBranch:t,rootBranch:n})=>t&&e.includes(t)&&t?{sourceBranch:t,shouldClearSavedSourceBranch:!1}:{sourceBranch:n&&e.includes(n)?n:e.includes(`main`)?`main`:e.includes(`master`)?`master`:e[0]??``,shouldClearSavedSourceBranch:!!t},Wt=(e,t,n)=>{if(!e)return e;let r=t.length>0&&!/\s$/.test(t)&&!/^\s/.test(e)&&!/[([{]$/.test(t),i=n.length>0&&!/\s$/.test(e)&&!/^\s/.test(n)&&!/^[\])}.,;:!?]/.test(n);return`${r?` `:``}${e}${i?` `:``}`},Gt=(e,t,n)=>{let r=Wt(e,t,n);return`${t.length===0&&!/^\s/.test(r)?` `:``}${r}${n.length===0&&!/\s$/.test(r)?` `:``}`},Kt=(e,t,n,r)=>{let i=e.slice(0,t),a=e.slice(n),o=Gt(r,i,a),s=Math.max(0,o.indexOf(r)),c=i.length+s;return{text:`${i}${o}${a}`,caret:i.length+o.length,start:c,end:c+r.length}},qt=(e,t)=>{let n=e=>`${e.kind}:${e.value}:${e.range.start}:${e.range.end}`;return new Set(e.map(n)).has(n(t))||e.some(e=>e.range.start<t.range.end&&t.range.start<e.range.end)?[...e]:[...e,t]},Jt=(e,t)=>t<e.length&&e[t]===` `?t+1:t;export{Fe as C,Te as D,Ee as E,xe as O,Le as S,De as T,jt as _,Vt as a,kt as b,Bt as c,At as d,Dt as f,Ot as g,Mt as h,Gt as i,z as k,Lt as l,Nt as m,qt as n,Ut as o,Pt as p,Kt as r,Ht as s,Jt as t,zt as u,Et as v,Ne as w,We as x,Q as y};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,i as n}from"./runtime-switch-DEZ1K7qW.js";import{T as r}from"./desktop-BAmoc_34.js";import{a as i,i as a,r as o}from"./vendor-zustand-vDaAPGfl.js";import{J as s,Y as c,ot as l,st as u}from"./vendor-base-ui-CzHs0bHY.js";import{bt as d,kt as f}from"./gitApiHttp-MWsHNHuo.js";import{r as p,x as m}from"./useUIStore-BerIUSLP.js";import{A as h,k as g}from"./bootstrap-C8paoQ0j.js";import{n as _}from"./vendor-react-DlzBev0S.js";import{i as v}from"./vendor-reactuses-core-DWo5Wn6R.js";import{f as y,r as b,u as x}from"./button-CBjOhOI0.js";import{$i as S,Gr as C,Oi as ee,Qn as te,Qr as ne,St as w,Ui as re,V as ie,Zn as T,_a as E,ft as D,ga as O,p as k,w as A,x as j}from"./useMobileNavigationStore-BWLhXqci.js";import{a as ae,g as M,o as oe,p as N,s as P}from"./fileMentionAutocompleteState-BZJqfgae.js";import{t as se}from"./AgentAvatar-DLAQkFQe.js";import{n as F}from"./Icon-Bh3TaKoN.js";import{g as ce,v as le}from"./gitApi-CNgEj6X5.js";import{c as ue,d as de,l as fe,n as pe,r as me,t as he}from"./fileMentionTouchSelection-Bizsisaj.js";import{n as ge}from"./textarea-EsaDD051.js";import{f as _e,o as ve}from"./projectMeta-rrpZdm8D.js";var I=_(),L=e(u(),1),R=l(),z=L.memo(function(e){let t=(0,I.c)(20),{checked:n,onChange:r,disabled:i,indeterminate:a,ariaLabel:o,className:l,iconClassName:u}=e,d=i!==void 0&&i,f=n||a,p;t[0]===r?p=t[1]:(p=e=>r(!!e),t[0]=r,t[1]=p);let m=f?`border-[color:color-mix(in_srgb,var(--primary-base)_65%,var(--interactive-border))] bg-transparent shadow-none hover:bg-[var(--interactive-hover)] hover:border-[color:color-mix(in_srgb,var(--primary-base)_75%,var(--interactive-border))]`:`border-[var(--interactive-border)] bg-transparent shadow-none hover:bg-[var(--interactive-hover)] hover:border-[var(--interactive-border)]`,h;t[2]!==l||t[3]!==m?(h=b(`group/checkbox relative flex shrink-0 self-center items-center justify-center rounded-[4px] border outline-none`,`h-[14px] w-[14px] min-h-[14px] min-w-[14px]`,`transition-[background-color,border-color,box-shadow] duration-200 ease-out`,m,`focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] focus-visible:ring-offset-1 focus-visible:ring-offset-transparent`,`disabled:cursor-not-allowed disabled:opacity-50`,l),t[2]=l,t[3]=m,t[4]=h):h=t[4];let g;t[5]===u?g=t[6]:(g=b(`flex items-center justify-center text-[var(--primary-base)]`,`data-[unchecked]:hidden`,u),t[5]=u,t[6]=g);let _;t[7]===a?_=t[8]:(_=a?(0,R.jsx)(F,{name:`subtract`,className:b(`h-[10px] w-[10px] min-h-[10px] min-w-[10px]`,`text-[var(--primary-base)]`)}):(0,R.jsx)(F,{name:`check`,className:b(`h-[10px] w-[10px] min-h-[10px] min-w-[10px]`,`text-[var(--primary-base)]`)}),t[7]=a,t[8]=_);let v;t[9]!==g||t[10]!==_?(v=(0,R.jsx)(s,{keepMounted:!0,className:g,children:_}),t[9]=g,t[10]=_,t[11]=v):v=t[11];let y;return t[12]!==o||t[13]!==n||t[14]!==d||t[15]!==a||t[16]!==p||t[17]!==h||t[18]!==v?(y=(0,R.jsx)(c,{checked:n,onCheckedChange:p,disabled:d,indeterminate:a,"aria-label":o,className:h,children:v}),t[12]=o,t[13]=n,t[14]=d,t[15]=a,t[16]=p,t[17]=h,t[18]=v,t[19]=y):y=t[19],y}),B=(e,t)=>{let n=t.trim();if(!n)return[...e].sort((e,t)=>e.isBuiltIn===t.isBuiltIn?e.name.localeCompare(t.name):e.isBuiltIn?-1:1);let r=M([...e],n,e=>[e.name,e.description??``]);return r.sort((e,t)=>e.score===t.score?e.item.isBuiltIn===t.item.isBuiltIn?e.item.name.localeCompare(t.item.name):e.item.isBuiltIn?-1:1:e.score-t.score),r.map(e=>e.item)},ye=(e,t)=>e===t||e.length===t.length&&e.every((e,n)=>{let r=t[n];return r!=null&&e.id===r.id&&e.title===r.title&&(e.subtitle??``)===(r.subtitle??``)&&(e.badge??``)===(r.badge??``)&&e.iconName===r.iconName&&e.agentName===r.agentName}),be=(e,t)=>e.highlightedIndex===t.highlightedIndex&&ye(e.rows,t.rows),xe=(e,t)=>ye(e,t)?e:t.slice(),Se=(e,t,n)=>{e&&(t.current&&be(t.current,n)||(t.current=n,e(n)))},Ce=(e,t)=>{t.current=null,e?.({rows:[],highlightedIndex:0})},V=e=>{if(!e)return``;let t=e.replace(/\\/g,`/`),n=t.startsWith(`//`),r=t.replace(/\/+/g,`/`);n&&!r.startsWith(`//`)&&(r=`/${r}`);let i=r===`/`,a=/^[A-Za-z]:\/$/.test(r);return!i&&!a&&(r=r.replace(/\/+$/,``)),r},H=e=>/^[A-Za-z]:\//.test(e)?e.toLowerCase():e,U=(e,t)=>{let n=V(t),r=V(e);if(!n||!r)return!1;let i=H(n),a=H(r);return a===i||a.startsWith(`${i}/`)},we=e=>{if(!e||typeof e!=`object`)return{};let t=e,n={};for(let[e,r]of Object.entries(t)){let t=V(e);if(!t||!r||typeof r!=`object`)continue;let i=r,a=Array.isArray(i.openPaths)?Array.from(new Set(i.openPaths.filter(e=>typeof e==`string`).map(e=>V(e)).filter(e=>U(e,t)))):[],o=Array.isArray(i.expandedPaths)?Array.from(new Set(i.expandedPaths.filter(e=>typeof e==`string`).map(e=>V(e)).filter(e=>U(e,t)))):[],s=typeof i.selectedPath==`string`?V(i.selectedPath):null,c=s&&U(s,t)?s:a[0]??null,l=typeof i.touchedAt==`number`&&Number.isFinite(i.touchedAt)?i.touchedAt:Date.now(),u=n[t];if(u){let e=Array.from(new Set([...u.openPaths,...a])),r=Array.from(new Set([...u.expandedPaths,...o]));n[t]={openPaths:e,selectedPath:u.selectedPath??c??e[0]??null,expandedPaths:r,touchedAt:Math.max(u.touchedAt,l)};continue}n[t]={openPaths:a,selectedPath:c,expandedPaths:o,touchedAt:l}}return n},W=(e,t)=>{let n=Object.entries(e);if(n.length<=t)return e;n.sort((e,t)=>(t[1]?.touchedAt??0)-(e[1]?.touchedAt??0));let r={};for(let[e,i]of n.slice(0,t))r[e]=i;return r},G=e=>e?{...e,touchedAt:Date.now()}:{openPaths:[],selectedPath:null,expandedPaths:[],touchedAt:Date.now()},Te=i()(o(a((e,t)=>({byRoot:{},addOpenPath:(t,n,r)=>{let i=V((t||``).trim()),a=V((n||``).trim());!i||!a||!r?.allowOutsideRoot&&!U(a,i)||e(e=>{let t=e.byRoot[i],n=G(t),r=n.openPaths.includes(a),o=r?n.openPaths:[...n.openPaths,a],s=n.selectedPath??a;return t&&r&&t.selectedPath===s?e:{byRoot:W({...e.byRoot,[i]:{...n,openPaths:o,selectedPath:s}},20)}})},removeOpenPath:(t,n)=>{let r=V((t||``).trim()),i=V((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=H(i),a=e=>H(e)===n,o=t.selectedPath?a(t.selectedPath):!1;if(!t.openPaths.some(a)&&!o)return e;let s=t.openPaths.filter(e=>!a(e)),c=o?s[0]??null:t.selectedPath;return{byRoot:W({...e.byRoot,[r]:{...t,openPaths:s,selectedPath:c,touchedAt:Date.now()}},20)}})},removeOpenPathsByPrefix:(t,n)=>{let r=V((t||``).trim()),i=V((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=H(i),a=n.endsWith(`/`)?n:`${n}/`,o=e=>{let t=H(e);return t===n||t.startsWith(a)},s=t.openPaths.filter(e=>!o(e));if(s.length===t.openPaths.length)return e;let c=t.selectedPath&&o(t.selectedPath)?s[0]??null:t.selectedPath;return{byRoot:W({...e.byRoot,[r]:{...t,openPaths:s,selectedPath:c,touchedAt:Date.now()}},20)}})},removeExpandedPathsByPrefix:(t,n)=>{let r=V((t||``).trim()),i=V((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=H(i),a=n.endsWith(`/`)?n:`${n}/`,o=t.expandedPaths.filter(e=>{let t=H(e);return t!==n&&!t.startsWith(a)});return o.length===t.expandedPaths.length?e:{byRoot:W({...e.byRoot,[r]:{...t,expandedPaths:o,touchedAt:Date.now()}},20)}})},setSelectedPath:(t,n,r)=>{let i=V((t||``).trim()),a=n?V(n.trim()):null;!i||a&&!r?.allowOutsideRoot&&!U(a,i)||e(e=>{let t=e.byRoot[i],n=G(t),r=a&&!n.openPaths.includes(a)?[...n.openPaths,a]:n.openPaths;return t&&t.selectedPath===a&&r===t.openPaths?e:{byRoot:W({...e.byRoot,[i]:{...n,openPaths:r,selectedPath:a}},20)}})},ensureSelectedPath:e=>{let n=V((e||``).trim());if(!n)return;let r=t().byRoot[n];if(!r||r.selectedPath)return;let i=r.openPaths[0]??null;i&&t().setSelectedPath(n,i)},toggleExpandedPath:(t,n)=>{let r=V((t||``).trim()),i=V((n||``).trim());!r||!i||!U(i,r)||e(e=>{let t=e.byRoot[r],n=G(t),a=n.expandedPaths.includes(i)?n.expandedPaths.filter(e=>e!==i):[...n.expandedPaths,i];return t&&t.expandedPaths===a&&t.selectedPath===n.selectedPath&&t.openPaths===n.openPaths?e:{byRoot:W({...e.byRoot,[r]:{...n,expandedPaths:a}},20)}})},expandPath:(t,n)=>{let r=V((t||``).trim()),i=V((n||``).trim());!r||!i||!U(i,r)||e(e=>{let t=e.byRoot[r],n=G(t);return n.expandedPaths.includes(i)&&t?e:{byRoot:W({...e.byRoot,[r]:{...n,expandedPaths:[...n.expandedPaths,i]}},20)}})},expandPaths:(t,n)=>{let r=V((t||``).trim());if(!r||!n||n.length===0)return;let i=n.map(e=>V((e||``).trim())).filter(e=>e&&U(e,r));i.length!==0&&e(e=>{let t=e.byRoot[r],n=G(t),a=new Set(n.expandedPaths),o=i.filter(e=>!a.has(e));return o.length===0?e:{byRoot:W({...e.byRoot,[r]:{...n,expandedPaths:[...n.expandedPaths,...o]}},20)}})}}),{name:`files-view-tabs-store`,version:2,storage:m(),migrate:e=>{if(!e||typeof e!=`object`)return{byRoot:{}};let t=e.byRoot;return{byRoot:we(t)}},partialize:e=>({byRoot:we(e.byRoot)})}),{name:`files-view-tabs-store`})),Ee=(e,t)=>{let n=(0,I.c)(4),r=t===void 0?200:t,[i,a]=L.useState(e),o,s;return n[0]!==r||n[1]!==e?(o=()=>{let t=window.setTimeout(()=>{a(e)},r);return()=>{window.clearTimeout(t)}},s=[e,r],n[0]=r,n[1]=e,n[2]=o,n[3]=s):(o=n[2],s=n[3]),L.useEffect(o,s),i},De=()=>{let e=(0,I.c)(17),t=k(Oe),n=w(),r;e[0]===t?r=e[1]:(r=e=>t?e.getAttachment(t):void 0,e[0]=t,e[1]=r);let i=A(r),a=k(ke),o=k(Ae),s=E(K),c=E(q),l=d(J);if(t){let r;e[2]===i?r=e[3]:(r=j(i),e[2]=i,e[3]=r);let o=r;if(o)return o;let s;e[4]!==t||e[5]!==a?(s=a.get(t),e[4]=t,e[5]=a,e[6]=s):s=e[6];let c=s;if(c?.path)return c.path;let l;if(e[7]!==t||e[8]!==n){let r;e[10]===t?r=e[11]:(r=e=>e.id===t,e[10]=t,e[11]=r),l=n.find(r),e[7]=t,e[8]=n,e[9]=l}else l=e[9];let u=l;if(u?.directory)return u.directory}if(o?.open&&(o.bootstrapPendingDirectory||o.directoryOverride))return(o.bootstrapPendingDirectory||o.directoryOverride)??void 0;if(s){let t;if(e[12]!==s||e[13]!==c){let n;e[15]===s?n=e[16]:(n=e=>e.id===s,e[15]=s,e[16]=n),t=c.find(n),e[12]=s,e[13]=c,e[14]=t}else t=e[14];let n=t;if(n?.path)return n.path}return l??void 0};function Oe(e){return e.currentSessionId}function ke(e){return e.worktreeMetadata}function Ae(e){return e.newSessionDraft}function K(e){return e.activeProjectId}function q(e){return e.projects}function J(e){return e.currentDirectory}var je=`bg-transparent font-[inherit] text-[var(--primary-base)]`,Me=(e,t)=>{let n=t.trim().toLowerCase();if(!n)return e;let r=e.toLowerCase();if(!r.includes(n))return e;let i=[],a=0,o=r.indexOf(n);for(;o!==-1;)o>a&&i.push(e.slice(a,o)),i.push((0,R.jsx)(`mark`,{className:je,children:e.slice(o,o+n.length)},`${o}-${n}`)),a=o+n.length,o=r.indexOf(n,a);return a<e.length&&i.push(e.slice(a)),i},Ne=L.forwardRef(({searchQuery:e,onFileSelect:t,onAgentSelect:n,onSkillSelect:r,onSessionSelect:i,onClose:a,style:o,onRowsChange:s},c)=>{let{t:l}=y(),u=De()??``,d=k(e=>e.currentSessionId),m=ne(e=>e.activeSessions),_=ie({enabled:!!i}),te=E(e=>e.activeProjectId),w=E(e=>e.projects),T=L.useMemo(()=>w.find(e=>e.id===te)?.path??null,[te,w]),D=L.useMemo(()=>{let e=T||u;return e?e.replace(/\\/g,`/`).replace(/\/+$/,``):null},[T,u]),O=Te(e=>D?e.byRoot[D]:void 0),A=ee(e=>e.agents),j=f(e=>e.searchFiles),M=Ee(e,180),ce=h(),le=g(),[de,fe]=L.useState([]),[_e,ve]=L.useState(!1),[I,z]=L.useState(0),B=L.useRef(0),ye=L.useRef({query:e,directory:u,ids:[]}),[be,xe]=L.useState(360),[V,H]=L.useState({}),[U,we]=L.useState({}),W=L.useRef([]),G=L.useRef([]),Oe=L.useRef([]),ke=L.useRef(null),Ae=L.useRef(null),K=L.useRef(null);K.current||=he();let q=p(e=>e.isMobile),J=(e??``).trim(),je=S({directory:u||null}),Ne=L.useMemo(()=>r?je.data??[]:[],[r,je.data]),Pe=L.useMemo(()=>{if(!D||!O)return[];let e=[O.selectedPath,...O.openPaths.slice().reverse()].filter(e=>typeof e==`string`&&e.length>0),t=new Set,n=[];for(let r of e){if(t.has(r))continue;t.add(r);let e=r.replace(/\\/g,`/`),i=e.split(`/`).filter(Boolean).pop()||e,a=e.startsWith(`${D}/`)?e.slice(D.length+1):e;n.push({name:i,path:e,relativePath:a,extension:i.includes(`.`)?i.split(`.`).pop()?.toLowerCase():void 0})}return P(n,J,{limit:6})},[J,D,O]),Y=L.useMemo(()=>n?re(A).filter(e=>e.mode!==`primary`):[],[A,n]),Fe=L.useMemo(()=>i?ae({sessions:C(m,_),currentSessionId:d,searchQuery:J}):[],[m,d,_,J,i]),Ie=Pe,Le=de,X=L.useMemo(()=>ue({skills:Ne,agents:Y,sessions:Fe,recentFiles:Ie,pathHits:Le,searchQuery:J,untitledSession:l(`chat.fileMentionAutocomplete.untitledSession`),sessionBadge:l(`chat.fileMentionAutocomplete.sessionType`),skillBadge:l(`chat.commandAutocomplete.badge.skill`)}),[Ne,Y,Fe,Ie,Le,J,l]);L.useEffect(()=>{let e=e=>{let t=e.target;!t||!ke.current||ke.current.contains(t)||a()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},[a]),L.useEffect(()=>{if(!u){fe([]);return}let e=(M??``).trim(),t=N(e);if(!t){fe([]);return}let n=!1;ve(!0);let r={includeHidden:ce,respectGitignore:!le};return Promise.all([j(u,t,80,{...r,type:`file`}),j(u,t,40,{...r,type:`directory`})]).then(([t,r])=>{if(n)return;let i=new Set(Pe.map(e=>e.path));fe(oe({files:t,directories:r,query:e,excludePaths:i,limit:20}))}).catch(()=>{n||fe([])}).finally(()=>{n||ve(!1)}),()=>{n=!0}},[u,M,Pe,j,ce,le]),L.useLayoutEffect(()=>{let t=ye.current,n=t.ids[B.current],r=t.query===e&&t.directory===u?Math.max(0,X.findIndex(e=>e.id===n)):0;ye.current={query:e,directory:u,ids:X.map(e=>e.id)},B.current=r,z(r)},[X,e,u]),L.useEffect(()=>{H({}),we({})},[X]),L.useEffect(()=>{W.current[I]?.scrollIntoView({block:`nearest`})},[I]),L.useEffect(()=>{let e=null,t=()=>{e!==null&&cancelAnimationFrame(e),e=requestAnimationFrame(()=>{let e={},t={};G.current.forEach((n,r)=>{if(!n)return;let i=Oe.current[r]?.offsetWidth??n.scrollWidth,a=Math.max(0,i-n.clientWidth),o=a>8;if(e[r]=o,o){let e=Math.max(.6,a/110);t[r]=e}}),H(e),we(t)})};return t(),window.addEventListener(`resize`,t),()=>{e!==null&&cancelAnimationFrame(e),window.removeEventListener(`resize`,t)}},[X]),L.useEffect(()=>{let e=G.current[I];if(!e)return;let t=()=>{let t=e.clientWidth;t>0&&xe(t)};if(t(),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(t);return n.observe(e),()=>{n.disconnect()}},[I]);let Re=v(e=>{t(e)}),ze=v(e=>{n?.(e)}),Be=v(e=>{i?.(e)}),Ve=v(e=>{r?.(e)}),He=(e,t)=>({onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{e.pointerType===`touch`&&K.current?.pointerDown(e.clientX,e.clientY)},onPointerMove:e=>{e.pointerType===`touch`&&K.current?.pointerMove(e.clientX,e.clientY)},onPointerUp:e=>{e.pointerType===`touch`&&(K.current?.pointerUp(t)??!1)&&(e.preventDefault(),e.stopPropagation())},onPointerCancel:()=>K.current?.pointerCancel(),onClick:()=>{K.current?.click(t)},onMouseMove:()=>{B.current=e,z(e)}}),Ue=e=>{let t=X.length;if(t===0)return;let n=(e%t+t)%t,r=X[n];if(r.agentName!==void 0){ze(r.agentName);return}if(r.id.startsWith(`skill:`)){let e=Ne.find(e=>r.id===`skill:${e.name}-${e.scope}`);e&&Ve(e);return}if(r.id.startsWith(`session:`)){let e=Fe.find(e=>r.id===`session:${e.id}`);e&&Be(e);return}let i=r.id.startsWith(`recent:`)?Ie.find(e=>r.id===`recent:${e.path}`):Le.find(e=>r.id===`file:${e.path}`);i&&Re(i)};L.useEffect(()=>{Se(s,Ae,{rows:X,highlightedIndex:I})},[s,I,X]);let We=L.useRef(s);return We.current=s,L.useEffect(()=>()=>{Ce(We.current,Ae)},[]),L.useImperativeHandle(c,()=>({acceptIndex:e=>{Ue(e)},handleKeyDown:e=>{if(e===`Escape`){a();return}let t=X.length;if(t!==0){if(e===`ArrowDown`){B.current=(B.current+1)%t,z(B.current);return}if(e===`ArrowUp`){B.current=(B.current-1+t)%t,z(B.current);return}(e===`Enter`||e===`Tab`)&&Ue(B.current)}}})),(0,R.jsxs)(pe,{ref:ke,isMobile:q,className:`max-w-[640px] max-h-64`,style:o,children:[(0,R.jsx)(ge,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0`,children:(0,R.jsxs)(`div`,{className:`py-1`,children:[X.map((e,t)=>{let n=e.id.startsWith(`file:`)||e.id.startsWith(`recent:`),r=n?x(e.title,{maxLength:60}):e.title,i=I===t,a=V[t]??!1,o=U[t]??2.6;return(0,R.jsxs)(`div`,{"data-mention-id":e.id,ref:e=>{W.current[t]=e},className:b(`flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,q&&`min-h-11`,me(q,i),!q&&i&&`text-interactive-selection-foreground`),...He(t,()=>Ue(t)),children:[(0,R.jsx)(`span`,{className:`flex size-5 shrink-0 items-center justify-center`,children:e.agentName===void 0?(0,R.jsx)(F,{name:e.iconName,className:`size-3.5 text-current`}):(0,R.jsx)(se,{name:e.agentName,size:20})}),(0,R.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,R.jsxs)(`div`,{className:`flex min-w-0 items-baseline gap-2`,children:[(0,R.jsxs)(`span`,{ref:e=>{G.current[t]=e},className:b(`relative block min-w-0 overflow-hidden`,n&&a&&i&&`file-mention-marquee-container`),style:i?{"--file-mention-marquee-width":`${be}px`,"--file-mention-marquee-duration":`${o}s`}:void 0,title:e.title,children:[(0,R.jsx)(`span`,{ref:e=>{Oe.current[t]=e},className:`absolute invisible whitespace-nowrap pointer-events-none`,"aria-hidden":!0,children:e.title}),n&&a&&i?(0,R.jsx)(`span`,{className:`inline-block whitespace-nowrap file-mention-marquee`,children:Me(e.title,J)}):(0,R.jsx)(`span`,{className:`block truncate`,children:Me(r,J)})]}),e.trailingLabel?(0,R.jsx)(`span`,{className:b(`max-w-[40%] shrink-0 truncate text-muted-foreground`,q?`typography-micro`:`typography-meta`),children:e.trailingLabel}):null]}),e.subtitle?(0,R.jsx)(`div`,{className:b(`truncate text-muted-foreground`,q?`typography-micro`:`typography-meta`),children:Me(e.subtitle,J)}):null]})]},e.id)}),_e&&Le.length===0?(0,R.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,R.jsx)(F,{name:`refresh`,className:`h-4 w-4 animate-spin text-muted-foreground`})}):null,!_e&&X.length===0&&(0,R.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:l(`chat.fileMentionAutocomplete.empty`)})]})}),!q&&(0,R.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:l(`chat.autocomplete.keyboardHint`)})]})}),Pe=new Set([`new`,`fork`,`compact`,`reload`,`undo`,`redo`,`model`,`btw`]),Y=(e,t)=>{if(!t||e.isSkill)return!1;let n=e.name?.trim().toLowerCase();return!!(n&&Pe.has(n))},Fe=(e,t)=>!e||t({name:e}),Ie=` `,Le=(e,t)=>{let n=Math.max(0,Math.min(t,e.length)),r=n;for(;r>0&&!/\s/.test(e[r-1]);)--r;return r>=2&&e[r-1]===Ie&&e[r-2]===`/`&&(r-=2),e[r]===`/`?{start:r,end:n}:null},X=`text-[10px] leading-none uppercase font-bold tracking-tight px-1.5 py-1 rounded border flex-shrink-0`,Re=b(X,`bg-[color-mix(in_srgb,var(--primary-base)_12%,transparent)] text-[color-mix(in_srgb,var(--primary-base)_70%,transparent)] border-[color-mix(in_srgb,var(--primary-base)_24%,transparent)]`),ze=b(X,`bg-[color-mix(in_srgb,var(--status-success)_12%,transparent)] text-[color-mix(in_srgb,var(--status-success)_70%,transparent)] border-[color-mix(in_srgb,var(--status-success)_24%,transparent)]`),Be=b(X,`bg-[color-mix(in_srgb,var(--status-info)_12%,transparent)] text-[color-mix(in_srgb,var(--status-info)_70%,transparent)] border-[color-mix(in_srgb,var(--status-info)_24%,transparent)]`),Ve=b(X,`bg-[var(--surface-muted)] text-muted-foreground border-[var(--interactive-border)]/60`),He=(e,t)=>e.length===t.length&&e.every((e,n)=>e.id===t[n]?.id&&e.description===t[n]?.description),Ue=e=>{let t=!!e.sessionID;return{hasSession:t,canStartSessionCommand:t||e.hasNewDraft}},We=L.forwardRef(({searchQuery:e,onCommandSelect:t,onClose:n,directory:i,style:a,commandPolicy:o,commandContext:s,onRowsChange:c},l)=>{let{t:u}=y(),d=p(e=>e.isMobile),f=k(e=>e.currentSessionId),m=k(e=>!!e.newSessionDraft?.open),h=k(L.useCallback(e=>f?e.getDirectoryForSession(f):void 0,[f])),g=D(f??``,h??void 0),_=L.useMemo(()=>s??{sessionID:f??null,hasMessages:g.length>0,hasNewDraft:m},[s,f,g.length,m]),{hasSession:v,canStartSessionCommand:x}=L.useMemo(()=>Ue(_),[_]),S=_.hasMessages,[C,ee]=L.useState([]),[te,ne]=L.useState(!1),w=O({directory:i}),re=L.useMemo(()=>w.data??[],[w.data]),ie=w.isFetching,[T,E]=L.useState(0),A=L.useRef(0),j=L.useRef(!1),ae=L.useRef([]),M=L.useRef(null),oe=L.useRef(!1),N=L.useRef(null),P=L.useRef(!1),se=L.useRef(null);L.useEffect(()=>{let e=e=>{let t=e.target;!t||!M.current||M.current.contains(t)||n()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},[n]),L.useEffect(()=>{(async()=>{ne(ie);try{let t=re.flatMap((e,t)=>e.source===`skill`?[]:[{id:`opencode:${e.scope??`global`}:${e.name}:${e.agent??``}:${e.model??``}:${t}`,name:e.name,source:`opencode`,description:e.description,agent:e.agent??void 0,model:e.model??void 0,isBuiltIn:e.isBuiltIn,scope:e.scope,reference:e.reference}]),n=[{id:`yuri:new`,name:`new`,source:`yuri`,description:u(`chat.commandAutocomplete.command.newDescription`),isBuiltIn:!0},...v&&!S?[{id:`yuri:init`,name:`init`,source:`yuri`,description:u(`chat.commandAutocomplete.command.initDescription`),isBuiltIn:!0}]:[],...v?[{id:`yuri:btw`,name:`btw`,source:`yuri`,description:u(`chat.btw.description`),isBuiltIn:!0},{id:`yuri:undo`,name:`undo`,source:`yuri`,description:u(`chat.commandAutocomplete.command.undoDescription`),isBuiltIn:!0},{id:`yuri:redo`,name:`redo`,source:`yuri`,description:u(`chat.commandAutocomplete.command.redoDescription`),isBuiltIn:!0},{id:`yuri:fork`,name:`fork`,source:`yuri`,description:u(`chat.commandAutocomplete.command.forkDescription`),isBuiltIn:!0},{id:`yuri:timeline`,name:`timeline`,source:`yuri`,description:u(`chat.commandAutocomplete.command.timelineDescription`),isBuiltIn:!0}]:[],{id:`yuri:model`,name:`model`,source:`yuri`,description:u(`chat.commandAutocomplete.command.modelDescription`),isBuiltIn:!0},{id:`yuri:compact`,name:`compact`,source:`yuri`,description:u(`chat.commandAutocomplete.command.compactDescription`),isBuiltIn:!0},...r()?[{id:`yuri:reload`,name:`reload`,source:`yuri`,description:u(`chat.commandAutocomplete.command.reloadDescription`),isBuiltIn:!0}]:[],...v?[{id:`yuri:summary`,name:`summary`,source:`yuri`,description:u(`chat.commandAutocomplete.command.summaryDescription`),isYuri:!0}]:[],...x?[{id:`yuri:workspace-review`,name:`workspace-review`,source:`yuri`,description:u(`chat.commandAutocomplete.command.workspaceReviewDescription`),isYuri:!0}]:[],...x?[{id:`yuri:craft-goal`,name:`craft-goal`,source:`yuri`,description:u(`chat.commandAutocomplete.command.craftGoalDescription`),isYuri:!0}]:[],...x?[{id:`yuri:catch-up`,name:`catch-up`,source:`yuri`,description:u(`chat.commandAutocomplete.command.catchUpDescription`),isYuri:!0}]:[],...x?[{id:`yuri:debug`,name:`debug`,source:`yuri`,description:u(`chat.commandAutocomplete.command.debugDescription`),isYuri:!0}]:[],...x?[{id:`yuri:weigh`,name:`weigh`,source:`yuri`,description:u(`chat.commandAutocomplete.command.weighDescription`),isYuri:!0}]:[],...x?[{id:`yuri:explore`,name:`explore`,source:`yuri`,description:u(`chat.commandAutocomplete.command.exploreDescription`),isYuri:!0}]:[],...t],i=!S,a=B(n.filter(e=>(i||e.name!==`init`)&&(o?.(e)??!0)),e);ee(e=>He(e,a)?e:a)}catch{let t=!S,n=B([{id:`yuri:new`,name:`new`,source:`yuri`,description:u(`chat.commandAutocomplete.command.newDescription`),isBuiltIn:!0},...v&&!S?[{id:`yuri:init`,name:`init`,source:`yuri`,description:u(`chat.commandAutocomplete.command.initDescription`),isBuiltIn:!0}]:[],...v?[{id:`yuri:btw`,name:`btw`,source:`yuri`,description:u(`chat.btw.description`),isBuiltIn:!0},{id:`yuri:undo`,name:`undo`,source:`yuri`,description:u(`chat.commandAutocomplete.command.undoDescription`),isBuiltIn:!0},{id:`yuri:redo`,name:`redo`,source:`yuri`,description:u(`chat.commandAutocomplete.command.redoDescription`),isBuiltIn:!0},{id:`yuri:fork`,name:`fork`,source:`yuri`,description:u(`chat.commandAutocomplete.command.forkDescription`),isBuiltIn:!0},{id:`yuri:timeline`,name:`timeline`,source:`yuri`,description:u(`chat.commandAutocomplete.command.timelineDescription`),isBuiltIn:!0}]:[],{id:`yuri:model`,name:`model`,source:`yuri`,description:u(`chat.commandAutocomplete.command.modelDescription`),isBuiltIn:!0},{id:`yuri:compact`,name:`compact`,source:`yuri`,description:u(`chat.commandAutocomplete.command.compactDescription`),isBuiltIn:!0},...r()?[{id:`yuri:reload`,name:`reload`,source:`yuri`,description:u(`chat.commandAutocomplete.command.reloadDescription`),isBuiltIn:!0}]:[],...v?[{id:`yuri:summary`,name:`summary`,source:`yuri`,description:u(`chat.commandAutocomplete.command.summaryDescription`),isYuri:!0}]:[],...x?[{id:`yuri:workspace-review`,name:`workspace-review`,source:`yuri`,description:u(`chat.commandAutocomplete.command.workspaceReviewDescription`),isYuri:!0}]:[],...x?[{id:`yuri:craft-goal`,name:`craft-goal`,source:`yuri`,description:u(`chat.commandAutocomplete.command.craftGoalDescription`),isYuri:!0}]:[],...x?[{id:`yuri:catch-up`,name:`catch-up`,source:`yuri`,description:u(`chat.commandAutocomplete.command.catchUpDescription`),isYuri:!0}]:[],...x?[{id:`yuri:debug`,name:`debug`,source:`yuri`,description:u(`chat.commandAutocomplete.command.debugDescription`),isYuri:!0}]:[],...x?[{id:`yuri:weigh`,name:`weigh`,source:`yuri`,description:u(`chat.commandAutocomplete.command.weighDescription`),isYuri:!0}]:[],...x?[{id:`yuri:explore`,name:`explore`,source:`yuri`,description:u(`chat.commandAutocomplete.command.exploreDescription`),isYuri:!0}]:[]].filter(e=>(t||e.name!==`init`)&&(o?.(e)??!0)),e);ee(e=>He(e,n)?e:n)}finally{ne(!1)}})()},[e,S,v,x,re,ie,u,o]),L.useEffect(()=>{E(0)},[C]),L.useEffect(()=>{A.current=T},[T]),L.useEffect(()=>{ae.current[T]?.scrollIntoView({block:`nearest`})},[T]),L.useEffect(()=>{Se(c,se,{rows:fe(C,{skill:u(`chat.commandAutocomplete.badge.skill`),command:u(`chat.commandAutocomplete.badge.command`),system:u(`chat.commandAutocomplete.badge.system`)}),highlightedIndex:T})},[C,c,T,u]);let ce=L.useRef(c);ce.current=c,L.useEffect(()=>()=>{Ce(ce.current,se)},[]),L.useImperativeHandle(l,()=>({acceptIndex:(e,n=!0)=>{let r=C[e];r&&t(r,Y(r,n))},handleKeyDown:e=>{let r=C.length;if(e===`Escape`){n();return}if(r!==0){if(e===`ArrowDown`){j.current=!0,E(e=>(e+1)%r);return}if(e===`ArrowUp`){j.current=!0,E(e=>(e-1+r)%r);return}if(e===`Enter`||e===`Tab`){let n=(A.current%r+r)%r,i=C[n];i&&t(i,Y(i,e===`Enter`))}}}}),[C,n,t]);let le=e=>{let t=de(e);switch(e.name){case`new`:return(0,R.jsx)(F,{name:t,className:`h-3.5 w-3.5`});case`init`:return(0,R.jsx)(F,{name:t,className:`h-3.5 w-3.5 text-green-500`});case`undo`:return(0,R.jsx)(F,{name:t,className:`h-3.5 w-3.5 text-orange-500`});case`redo`:return(0,R.jsx)(F,{name:t,className:`h-3.5 w-3.5 text-orange-500`});case`timeline`:case`reload`:return(0,R.jsx)(F,{name:t,className:`h-3.5 w-3.5`});case`compact`:return(0,R.jsx)(F,{name:t,className:`h-3.5 w-3.5 text-purple-500`});case`goal`:return(0,R.jsx)(F,{name:t,className:`h-3.5 w-3.5`});case`review`:return(0,R.jsx)(F,{name:t,className:`h-3.5 w-3.5 text-blue-500`});case`test`:case`build`:case`run`:return(0,R.jsx)(F,{name:t,className:`h-3.5 w-3.5 text-cyan-500`});default:return e.isBuiltIn?(0,R.jsx)(F,{name:t,className:`h-3.5 w-3.5 text-yellow-500`}):(0,R.jsx)(F,{name:t,className:`h-3.5 w-3.5 text-muted-foreground`})}};return(0,R.jsxs)(pe,{ref:M,isMobile:d,className:`max-w-[450px] max-h-64`,style:a,children:[(0,R.jsx)(ge,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0 py-1.5`,children:te?(0,R.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,R.jsx)(F,{name:`refresh`,className:`h-4 w-4 animate-spin text-muted-foreground`})}):(0,R.jsxs)(`div`,{children:[C.map((n,r)=>{let i=n.isBuiltIn,a=n.isYuri;return(0,R.jsxs)(`div`,{ref:e=>{ae.current[r]=e},className:b(`flex gap-2 px-2 py-2 cursor-pointer rounded-lg`,d?`items-center`:`items-start`,me(d,r===T),!d&&r===T&&`bg-interactive-selection/35`),onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{e.pointerType===`touch`&&(N.current={x:e.clientX,y:e.clientY},P.current=!1)},onPointerMove:e=>{if(e.pointerType!==`touch`||!N.current)return;let t=e.clientX-N.current.x,n=e.clientY-N.current.y;Math.hypot(t,n)>6&&(P.current=!0)},onPointerUp:e=>{if(e.pointerType!==`touch`)return;let r=P.current;N.current=null,P.current=!1,!r&&(e.preventDefault(),e.stopPropagation(),oe.current=!0,t(n,Y(n,d)))},onPointerCancel:()=>{N.current=null,P.current=!1},onClick:()=>{if(oe.current){oe.current=!1;return}t(n,Y(n,d))},onMouseMove:()=>{j.current=!1,E(r)},children:[(0,R.jsx)(`div`,{className:b(!d&&`mt-0.5`),children:le(n)}),(0,R.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsxs)(`span`,{className:`typography-ui-label font-medium`,children:[`/`,Me(n.name,e)]}),n.isSkill?(0,R.jsx)(`span`,{className:Re,children:u(`chat.commandAutocomplete.badge.skill`)}):(0,R.jsx)(`span`,{className:Re,children:u(`chat.commandAutocomplete.badge.command`)}),a?(0,R.jsx)(`span`,{className:Ve,children:`Yuri`}):i?(0,R.jsx)(`span`,{className:Ve,children:u(`chat.commandAutocomplete.badge.system`)}):n.scope?(0,R.jsx)(`span`,{className:n.scope===`project`?Be:ze,children:n.scope}):null,n.agent&&(0,R.jsx)(`span`,{className:Ve,children:n.agent})]}),n.description&&!d&&(0,R.jsx)(`div`,{className:`typography-meta text-muted-foreground mt-0.5 truncate`,children:Me(n.description,e)})]})]},n.id)}),C.length===0&&(0,R.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:u(`chat.commandAutocomplete.empty`)})]})}),!d&&(0,R.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:u(`chat.autocomplete.keyboardHint`)})]})});We.displayName=`CommandAutocomplete`;var Ge=e=>e instanceof Error?e.name===`AbortError`||e.name===`CancelledError`||e.name===`Error`&&e.message===`CancelledError`:!1,Ke=1e4,qe=6e4,Je=5e3,Ye=3e4,Xe=6e4,Ze=25,Qe=40,$e=2,et=15e3,tt=500,nt=30,rt=20971520,it=new Map,at=new Map,ot=new Map,st=new Map,ct=new Map,lt=new Map,ut=new WeakMap,dt=e=>{let t=ut.get(e);return t||(t=new Set(e.files.map(e=>e.path)),ut.set(e,t)),t},ft=(e,t)=>`${t}:${e}`,pt=e=>at.get(e)??0,mt=e=>{let t=pt(e)+1;return at.set(e,t),t},ht=e=>{let t=(ot.get(e)??0)+1;return ot.set(e,t),t},gt=e=>{let t=it.get(e);if(t)return t;let n=new Set;return it.set(e,n),n},Z=()=>({isGitRepo:null,status:null,branches:null,branchesTransportIdentity:null,log:null,identity:null,diffCache:new Map,indexRevision:0,lastRepoCheckAt:0,lastStatusFetch:0,lastStatusChange:0,lastLogFetch:0,lastBranchesFetch:0,lastIdentityFetch:0,logMaxCount:25,isLoadingStatus:!1,isLoadingLog:!1,isLoadingBranches:!1,isLoadingIdentity:!1}),_t=(e,t=nt,n=rt)=>{let r=0;for(let t of e.values())r+=(t.original?.length??0)+(t.modified?.length??0);if(e.size<=t&&r<=n)return e;let i=Array.from(e.entries()).sort((e,t)=>e[1].fetchedAt-t[1].fetchedAt),a=new Map,o=0;for(let e=i.length-1;e>=0;e--){let[r,s]=i[e],c=(s.original?.length??0)+(s.modified?.length??0);if(a.size>=t)break;o+c>n&&a.size>0||(a.set(r,s),o+=c)}return a},vt=(e,t)=>!e&&!t?!1:!e||!t||e.remote!==t.remote||e.branch!==t.branch||e.ahead!==t.ahead||e.behind!==t.behind,yt=e=>{let t=e?.trim()??``;return t===`?`?``:t},bt=(e,t)=>{let n=new Set,r=!1,i=!e;e&&(i=e.ahead!==t.ahead||e.behind!==t.behind||e.current!==t.current||e.tracking!==t.tracking||e.isClean!==t.isClean||t.upstreamComparison!==void 0&&vt(e.upstreamComparison,t.upstreamComparison)||t.diffStats!==void 0&&e.diffStats===void 0);let a=new Map;for(let t of e?.files??[])a.set(t.path,t);for(let e of t.files??[]){let t=a.get(e.path);if(!t){n.add(e.path),yt(e.index)&&(r=!0);continue}a.delete(e.path),(t.index!==e.index||t.working_dir!==e.working_dir)&&n.add(e.path),!r&&yt(t.index)!==yt(e.index)&&(r=!0)}for(let[e,t]of a)n.add(e),yt(t.index)&&(r=!0);let o=t.diffStats,s=e?.diffStats;if(o!==void 0&&o!==s){let e=s??{};for(let t in o){let r=o[t],i=e[t];(!i||i.insertions!==r.insertions||i.deletions!==r.deletions)&&n.add(t)}for(let t in e)t in o||n.add(t)}return{changed:i||n.size>0,changedPaths:n,indexChanged:r}},xt=e=>!e||e.trim().length===0,St=e=>(e||``).trim()===`U`,Ct=e=>{let t=(e.index||``).trim(),n=(e.working_dir||``).trim();if(St(t)||St(n))return e;let r=t===`?`||n===`?`?`A`:t||n||` `;return{...e,index:r,working_dir:` `}},wt=e=>{let t=(e.index||``).trim(),n=(e.working_dir||``).trim();if(St(t)||St(n))return e;let r=n||(t===`A`||t===`?`?`?`:t)||` `;return{...e,index:` `,working_dir:r}},Tt=e=>xt(e.index)&&xt(e.working_dir),Q=i()(o((e,t)=>({directories:new Map,activeDirectory:null,setActiveDirectory:n=>{let{activeDirectory:r,directories:i}=t();if(r!==n)if(r&&mt(r),n&&mt(n),n&&!i.has(n)){let t=new Map(i);t.set(n,Z()),e({activeDirectory:n,directories:t})}else e({activeDirectory:n})},getDirectoryState:e=>t().directories.get(e)??null,fetchStatus:async(n,r,i={})=>{let a=i.mode??`full`,o=ft(n,a),s=st.get(o)??(a===`light`?st.get(ft(n,`full`)):void 0);if(s)return s;let c=(async()=>{let{silent:a=!1}=i,{directories:o}=t(),s=o.get(n);if(s||=Z(),!a){let r=new Map(t().directories),i=r.get(n)??Z();r.set(n,{...i,isLoadingStatus:!0}),e({directories:r})}let c=!1;try{let a=Date.now(),o=s.isGitRepo!==!0||a-(s.lastRepoCheckAt||0)>qe,l=s.isGitRepo===!0;if(o&&(l=await r.checkIsGitRepository(n)),!l){let r=new Map(t().directories),i=r.get(n)??s;return r.set(n,{...i,isGitRepo:!1,status:null,isLoadingStatus:!1,lastRepoCheckAt:a,lastStatusFetch:a}),e({directories:r}),!1}let u=await r.getGitStatus(n,i.mode?{mode:i.mode}:void 0),d=t().directories.get(n)??Z(),f=lt.get(n),p=f?.received===u&&f.stored===d.status?null:bt(d.status,u);if(p?.changed){c=!0;let r=new Map(t().directories),i=r.get(n)??Z(),{changedPaths:s,indexChanged:l}=p,d=new Map(i.diffCache);for(let e of s)d.delete(e);let f=s.size>0;f&&mt(n);let m={...u,diffStats:u.diffStats===void 0&&i.status?.diffStats!==void 0?i.status.diffStats:u.diffStats,upstreamComparison:u.upstreamComparison===void 0?i.status?.upstreamComparison:u.upstreamComparison};r.set(n,{...i,isGitRepo:!0,status:m,diffCache:d,indexRevision:l?i.indexRevision+1:i.indexRevision,lastRepoCheckAt:o?a:i.lastRepoCheckAt,lastStatusFetch:Date.now(),lastStatusChange:f?Date.now():i.lastStatusChange}),e({directories:r}),lt.set(n,{received:u,stored:m})}else{lt.set(n,{received:u,stored:d.status});let r=new Map(t().directories),i=r.get(n)??Z();r.set(n,{...i,isGitRepo:!0,lastRepoCheckAt:o?a:i.lastRepoCheckAt,lastStatusFetch:Date.now(),lastStatusChange:i.lastStatusChange}),e({directories:r})}}catch(e){console.error(`Failed to fetch git status:`,e)}finally{if(!a){let r=new Map(t().directories),i=r.get(n)??Z();r.set(n,{...i,isLoadingStatus:!1}),e({directories:r})}}return c})();st.set(o,c);try{return await c}finally{st.get(o)===c&&st.delete(o)}},moveStatusPathsOptimistically:(n,r,i)=>{let a=new Set(r.map(e=>e.trim()).filter(Boolean));if(a.size===0)return null;let{directories:o}=t(),s=o.get(n),c=s?.status??null;if(!s||!c)return c;let l=!1,u=[];for(let e of c.files){if(!a.has(e.path)){u.push(e);continue}let t=i===`stage`?Ct(e):wt(e);t!==e&&(l=!0),Tt(t)?l=!0:u.push(t)}if(!l)return c;let d=new Map(o);return d.set(n,{...s,status:{...c,files:u,isClean:u.length===0},indexRevision:s.indexRevision+1,lastStatusChange:Date.now()}),e({directories:d}),c},restoreStatus:(n,r)=>{let{directories:i}=t(),a=i.get(n);if(!a)return;let o=new Map(i);o.set(n,{...a,status:r,indexRevision:a.indexRevision+1,lastStatusChange:Date.now()}),e({directories:o})},bumpIndexRevision:n=>{let{directories:r}=t(),i=r.get(n);if(!i)return;let a=new Map(r);a.set(n,{...i,indexRevision:i.indexRevision+1}),e({directories:a})},fetchBranches:async(r,i,a={})=>{let o=n(),s=ht(r);{let n=new Map(t().directories),i=n.get(r)??Z();n.set(r,{...i,isLoadingBranches:!0}),e({directories:n})}try{let c=a.force?await te(r,i,void 0,o):await T(r,i,void 0,o);if(s!==ot.get(r)||o!==n())return;let l=new Map(t().directories),u=l.get(r)??Z();l.set(r,{...u,branches:c,branchesTransportIdentity:o,isLoadingBranches:!1,lastBranchesFetch:Date.now()}),e({directories:l})}catch(i){if(Ge(i)||console.error(`Failed to fetch git branches:`,i),s!==ot.get(r)||o!==n())return;let a=new Map(t().directories),c=a.get(r)??Z();a.set(r,{...c,isLoadingBranches:!1}),e({directories:a})}},fetchLog:async(n,r,i)=>{let{directories:a}=t(),o=a.get(n),s=i??o?.logMaxCount??25;{let r=new Map(t().directories),i=r.get(n)??Z();r.set(n,{...i,isLoadingLog:!0}),e({directories:r})}try{let i=await r.getGitLog(n,{maxCount:s}),a=new Map(t().directories),o=a.get(n)??Z();a.set(n,{...o,log:i,isLoadingLog:!1,lastLogFetch:Date.now(),logMaxCount:s}),e({directories:a})}catch(r){console.error(`Failed to fetch git log:`,r);let i=new Map(t().directories),a=i.get(n)??Z();i.set(n,{...a,isLoadingLog:!1}),e({directories:i})}},fetchIdentity:async(n,r)=>{{let r=new Map(t().directories),i=r.get(n)??Z();r.set(n,{...i,isLoadingIdentity:!0}),e({directories:r})}try{let i=await r.getCurrentGitIdentity(n),a=new Map(t().directories),o=a.get(n)??Z();a.set(n,{...o,identity:i,isLoadingIdentity:!1,lastIdentityFetch:Date.now()}),e({directories:a})}catch(r){console.error(`Failed to fetch git identity:`,r);let i=new Map(t().directories),a=i.get(n)??Z();i.set(n,{...a,isLoadingIdentity:!1}),e({directories:i})}},fetchAll:async(n,r,i={})=>{let{directories:a}=t(),o=a.get(n);if(!o){o=Z();let t=new Map(a);t.set(n,o),e({directories:t})}let{force:s=!1,silentIfCached:c=!1}=i,l=Date.now();await t().fetchStatus(n,r,{silent:c&&!!o?.status});let u=t().directories.get(n);if(!u?.isGitRepo)return;await t().fetchBranches(n,r,{force:s});let d=l-(u.lastLogFetch||0);(s||d>Ke||!u.log)&&await t().fetchLog(n,r),await t().fetchIdentity(n,r)},getDiff:(e,n)=>t().directories.get(e)?.diffCache.get(n)??null,setDiff:(n,r,i)=>{let a=new Map(t().directories),o=a.get(n)??Z(),s=new Map(o.diffCache);s.set(r,{...i,fetchedAt:Date.now()});let c=_t(s);a.set(n,{...o,diffCache:c}),e({directories:a})},clearDiffCache:n=>{mt(n);let r=new Map(t().directories),i=r.get(n);i&&(r.set(n,{...i,diffCache:new Map}),e({directories:r}))},fetchAllDiffs:async(e,n)=>{let r=t().directories.get(e);if(!r?.status?.files||r.status.files.length===0)return;let i=r.status.files.map(e=>e.path).slice(0,Ze);await t().prefetchDiffs(e,n,i,{maxFiles:Ze})},prefetchDiffs:async(n,r,i,a={})=>{let o=t().directories.get(n);if(!o?.status?.files||o.status.files.length===0||i.length===0)return;let{maxFiles:s=Qe}=a,c=Math.min(Math.max(1,s),nt),l=dt(o.status),u=o.status.diffStats,d=gt(n),f=[],p=new Set;for(let e of i){if(p.size>=c)break;if(!e||p.has(e)||!l.has(e))continue;let t=u?.[e];t&&t.insertions+t.deletions>tt||(p.add(e),!o.diffCache.has(e)&&(d.has(e)||f.push(e)))}let m=f;if(m.length===0)return;let h=pt(n);if(typeof document<`u`&&document.hidden)return;m.forEach(e=>d.add(e));let g=0,_=[],v=()=>{let e=g;return g+=1,e<m.length?m[e]:null},y=async e=>{let t=r.getGitFileDiff(n,{path:e}),i=new Promise((e,t)=>{setTimeout(()=>t(Error(`Timed out after ${et}ms`)),et)}),a=await Promise.race([t,i]);return{path:e,diff:{original:a.original??``,modified:a.modified??``,isBinary:a.isBinary}}},b=async()=>{for(;;){if(h!==pt(n))return;let e=v();if(!e)return;try{_.push(await y(e))}catch{}finally{d.delete(e)}}},x=Math.min($e,m.length);if(await Promise.allSettled(Array.from({length:x},()=>b())),m.forEach(e=>d.delete(e)),h!==pt(n))return;let S=new Map(t().directories),C=S.get(n);if(!C)return;let ee=new Map(C.diffCache),te=Date.now();_.forEach(e=>{!e.diff.isBinary&&e.diff.original===``&&e.diff.modified===``||ee.set(e.path,{...e.diff,fetchedAt:te})});let ne=_t(ee);S.set(n,{...C,diffCache:ne}),e({directories:S})},setLogMaxCount:(n,r)=>{let i=new Map(t().directories),a=i.get(n)??Z();i.set(n,{...a,logMaxCount:r}),e({directories:i})},ensureStatus:async(e,n)=>{let r=t().directories.get(e),i=Date.now();r?.status&&i-r.lastStatusFetch<Je||await t().fetchStatus(e,n,{silent:!!r?.status})},ensureAll:(e,n)=>{let r=ct.get(e);if(r)return r;let i=(async()=>{let r=t().directories.get(e),i=Date.now();(!r?.status||r.status.diffStats===void 0||i-(r?.lastStatusFetch??0)>=Je)&&await t().fetchStatus(e,n,{silent:!!r?.status});let a=t().directories.get(e);if(!a?.isGitRepo)return;let o=[];(!a.branches||i-a.lastBranchesFetch>=Ye)&&o.push(t().fetchBranches(e,n)),(!a.log||i-a.lastLogFetch>=Ke)&&o.push(t().fetchLog(e,n)),(!a.identity||i-a.lastIdentityFetch>=Xe)&&o.push(t().fetchIdentity(e,n)),o.length>0&&await Promise.all(o)})();return ct.set(e,i),i.finally(()=>{ct.get(e)===i&&ct.delete(e)}),i},refresh:async(e,n={})=>{let{activeDirectory:r}=t();r&&await t().fetchAll(r,e,n)}}),{name:`git-store`})),Et=e=>{let t=(0,I.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.status??null:null,t[0]=e,t[1]=n),Q(n)},Dt=e=>{let r=(0,I.c)(3),i=L.useSyncExternalStore(t,n,n),a;return r[0]!==e||r[1]!==i?(a=t=>{if(!e)return null;let n=t.directories.get(e);return n?.branchesTransportIdentity===i?n.branches:null},r[0]=e,r[1]=i,r[2]=a):a=r[2],Q(a)},Ot=e=>{let t=(0,I.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.log??null:null,t[0]=e,t[1]=n),Q(n)},kt=e=>{let t=(0,I.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.isGitRepo??null:null,t[0]=e,t[1]=n),Q(n)},At=e=>{let t=(0,I.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.status?.current?.trim()??null:null,t[0]=e,t[1]=n),Q(n)},jt=e=>{let t=(0,I.c)(3),n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=new Map,t[0]=n):n=t[0];let r=L.useRef(n),i;return t[1]===e?i=t[2]:(i=t=>{let n=r.current,i=n.size===e.length;if(i)for(let r of e){let e=t.directories.get(r),a=n.get(r);if(!a||(e?.isGitRepo??null)!==a.isGitRepo||(e?.status?.current??null)!==a.branch){i=!1;break}}if(i)return n;let a=new Map;for(let n of e){let e=t.directories.get(n);a.set(n,{isGitRepo:e?.isGitRepo??null,branch:e?.status?.current??null})}return r.current=a,a},t[1]=e,t[2]=i),Q(i)},Mt=e=>{let t=(0,I.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.isLoadingStatus??!1:!1,t[0]=e,t[1]=n),Q(n)},Nt=e=>{let t=(0,I.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.isLoadingLog??!1:!1,t[0]=e,t[1]=n),Q(n)},Pt=e=>{let t=(0,I.c)(2),n;return t[0]===e?n=t[1]:(n=t=>e?t.directories.get(e)?.isLoadingBranches??!1:!1,t[0]=e,t[1]=n),Q(n)},Ft=e=>{let t=String(e||``).trim().replace(/^remotes\//,``);if(!t)return null;let n=t.indexOf(`/`);return n<=0||n>=t.length-1?null:{remote:t.slice(0,n),branch:t.slice(n+1)}},$=e=>String(e||``).trim().replace(/^refs\/heads\//,``).replace(/^heads\//,``).replace(/^remotes\//,``),It=e=>e.branchName?$(e.branchName):e.mode===`existing`?$(e.existingBranch||e.preferredName||``):$(e.preferredName||``),Lt=async e=>{let t=await _e(e);try{let n=Ft((await ce(e)).branches?.[t]?.tracking||null);if(n?.remote)return n.remote}catch{}try{let t=Ft((await le(e)).tracking);if(t?.remote)return t.remote}catch{}return null},Rt=async(e,t)=>{let n=await Lt(e),r=$(t);return!n||!r?null:{setUpstream:!0,upstreamRemote:n,upstreamBranch:r}},zt=async(e,t,n)=>{let r=It(t),i=n?.resolvedRootTrackingRemote,a=i===void 0?await Rt(e,r):i&&$(r)?{setUpstream:!0,upstreamRemote:i,upstreamBranch:$(r)}:null;return a?{...t,setUpstream:t.setUpstream??a.setUpstream,upstreamRemote:t.upstreamRemote||a.upstreamRemote,upstreamBranch:t.upstreamBranch||a.upstreamBranch}:t},Bt=async(e,t,n)=>{let r=await zt(e.path,t,n);return ve(e,r)},Vt=`yuri:lastWorktreeSourceBranch`,Ht=({mode:e,sourceBranch:t,linkedPr:n,selectedBranch:r})=>e===`existing-branch`?r||null:n?null:t||null,Ut=({branches:e,savedSourceBranch:t,rootBranch:n})=>t&&e.includes(t)&&t?{sourceBranch:t,shouldClearSavedSourceBranch:!1}:{sourceBranch:n&&e.includes(n)?n:e.includes(`main`)?`main`:e.includes(`master`)?`master`:e[0]??``,shouldClearSavedSourceBranch:!!t},Wt=(e,t,n)=>{if(!e)return e;let r=t.length>0&&!/\s$/.test(t)&&!/^\s/.test(e)&&!/[([{]$/.test(t),i=n.length>0&&!/\s$/.test(e)&&!/^\s/.test(n)&&!/^[\])}.,;:!?]/.test(n);return`${r?` `:``}${e}${i?` `:``}`},Gt=(e,t,n)=>{let r=Wt(e,t,n);return`${t.length===0&&!/^\s/.test(r)?` `:``}${r}${n.length===0&&!/\s$/.test(r)?` `:``}`},Kt=(e,t,n,r)=>{let i=e.slice(0,t),a=e.slice(n),o=Gt(r,i,a),s=Math.max(0,o.indexOf(r)),c=i.length+s;return{text:`${i}${o}${a}`,caret:i.length+o.length,start:c,end:c+r.length}},qt=(e,t)=>{let n=e=>`${e.kind}:${e.value}:${e.range.start}:${e.range.end}`;return new Set(e.map(n)).has(n(t))||e.some(e=>e.range.start<t.range.end&&t.range.start<e.range.end)?[...e]:[...e,t]},Jt=(e,t)=>t<e.length&&e[t]===` `?t+1:t;export{Fe as C,Te as D,Ee as E,xe as O,Le as S,De as T,jt as _,Vt as a,kt as b,Bt as c,At as d,Dt as f,Ot as g,Mt as h,Gt as i,z as k,Lt as l,Nt as m,qt as n,Ut as o,Pt as p,Kt as r,Ht as s,Jt as t,zt as u,Et as v,Ne as w,We as x,Q as y};