@yuriai/web 0.1.6 → 0.1.7

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 (84) hide show
  1. package/README.md +1 -1
  2. package/dist/assets/{AgentAvatar-D6H7fWWf.js → AgentAvatar-BVnp9gE9.js} +1 -1
  3. package/dist/assets/AssistantView-BkMKCN9c.js +3 -0
  4. package/dist/assets/{DiagramView-BXVAioBW.js → DiagramView-B7_hOmVC.js} +1 -1
  5. package/dist/assets/{FadeInOnReveal-eVZbrwte.js → FadeInOnReveal-CzC5UKnq.js} +1 -1
  6. package/dist/assets/{Icon-2cKLcXGe.js → Icon-BXTZRnIO.js} +1 -1
  7. package/dist/assets/{ImageLoadingPlaceholder-DmCEIw55.js → ImageLoadingPlaceholder-Cv6IaJar.js} +1 -1
  8. package/dist/assets/{LoadingImage-B-cD_lfU.js → LoadingImage-NxtWlewi.js} +1 -1
  9. package/dist/assets/{MarkdownRenderer-BY7SOGeo.js → MarkdownRenderer-Va7Wdk98.js} +2 -2
  10. package/dist/assets/{MarkdownRendererImpl-KSaMBtRF.js → MarkdownRendererImpl-CsjvA5I5.js} +1 -1
  11. package/dist/assets/{MarkstreamRendererImpl-BvkGmuQ6.js → MarkstreamRendererImpl-Du38HKce.js} +1 -1
  12. package/dist/assets/{MobileDetailNavigation-DACAHTpS.js → MobileDetailNavigation-B_PYZ9xi.js} +1 -1
  13. package/dist/assets/MobileShareBridge-BbbQ15B3.js +4 -0
  14. package/dist/assets/MobileTabPageHeader-tiWNRKWN.js +2 -0
  15. package/dist/assets/{MultiRunWindow-4G9PetNl.js → MultiRunWindow-CFFrKEHW.js} +1 -1
  16. package/dist/assets/{OnboardingScreen-CG2xI_UT.js → OnboardingScreen-BxS5LEOm.js} +1 -1
  17. package/dist/assets/{OverlayScrollbar-piA-chKb.js → OverlayScrollbar-CbWvRXm6.js} +1 -1
  18. package/dist/assets/SettingsView-CKn54R1o.js +26 -0
  19. package/dist/assets/{SettingsWindow-DGK3Earv.js → SettingsWindow-BKatx9Q_.js} +1 -1
  20. package/dist/assets/{TerminalView-CagyLr39.js → TerminalView-h15pBKLx.js} +2 -2
  21. package/dist/assets/{ToolOutputDialog-DHukIjoH.js → ToolOutputDialog-Bj-TWElC.js} +1 -1
  22. package/dist/assets/{appThemeRegistry-U9eZywBt.js → appThemeRegistry-nntgbF9E.js} +1 -1
  23. package/dist/assets/button-D_HdP1Oy.js +1 -0
  24. package/dist/assets/{capgoAdapter-ChF9Cg3G.js → capgoAdapter-BV5kJq2r.js} +1 -1
  25. package/dist/assets/{collapsible-BRKOX_ML.js → collapsible-sUU_ORMe.js} +1 -1
  26. package/dist/assets/{diagram-C9F3kAJt.js → diagram-BE50CEiR.js} +1 -1
  27. package/dist/assets/{dialog-NsOVcGdh.js → dialog-B_87Teec.js} +1 -1
  28. package/dist/assets/{dropdown-menu.styles-CjPDePJF.js → dropdown-menu.styles-C_b80jxk.js} +1 -1
  29. package/dist/assets/{fileMentionTouchSelection-Bip-B2J9.js → fileMentionTouchSelection-Bx6vWiqF.js} +1 -1
  30. package/dist/assets/{gitApi-BN0aozGg.js → gitApi-B1arMnHR.js} +1 -1
  31. package/dist/assets/{input-BI3Ya8O_.js → input-DDfJnn8e.js} +1 -1
  32. package/dist/assets/{insertionBoundaries-gfsrexDz.js → insertionBoundaries-B8UdVMC9.js} +1 -1
  33. package/dist/assets/{main-C8xj4UeZ.js → main-BLSF9qdf.js} +2 -2
  34. package/dist/assets/{main-CjjADMt-.js → main-DJwLyPc3.js} +12 -12
  35. package/dist/assets/{markdownHeightCache-CHFSvA8u.js → markdownHeightCache-Cbd62oWw.js} +1 -1
  36. package/dist/assets/{mcpQueries-DJCrzyc3.js → mcpQueries-BxbbmYAd.js} +1 -1
  37. package/dist/assets/{miniChat-D17acnB9.js → miniChat-D_cBND3Z.js} +2 -2
  38. package/dist/assets/{mobile-DiL1n1m5.js → mobile-CZNFYieO.js} +2 -2
  39. package/dist/assets/{mobileBackNavigation-B1NT3K0K.js → mobileBackNavigation-f8AMDP0N.js} +1 -1
  40. package/dist/assets/{multirun-D2KlubbP.js → multirun-Cvl4FMPo.js} +1 -1
  41. package/dist/assets/{native-config-D9DfX51I.js → native-config-DLJCZcXh.js} +1 -1
  42. package/dist/assets/{projectMeta-B5lVMdxF.js → projectMeta-D3cfkJyk.js} +1 -1
  43. package/dist/assets/{renderElectronMiniChatApp-DQGRyvOy.js → renderElectronMiniChatApp-_n69Pa_v.js} +2 -2
  44. package/dist/assets/renderMobileApp-DUiUPyd7.js +28 -0
  45. package/dist/assets/{runtimeConfig-MKo97i27.js → runtimeConfig-DwFJL5bm.js} +1 -1
  46. package/dist/assets/runtimeEndpointReset-C_1daihM.js +149 -0
  47. package/dist/assets/{scheduledTaskNavigation-DUskP6qh.js → scheduledTaskNavigation-DvSpMLdG.js} +1 -1
  48. package/dist/assets/sessionChangeSummary-evl_LmRN.js +1 -0
  49. package/dist/assets/sessionLookup-CJ8mXxHt.js +1 -0
  50. package/dist/assets/{sortable-tabs-strip-Benojjgi.js → sortable-tabs-strip-CrjW2aQk.js} +1 -1
  51. package/dist/assets/{speechSettingsQueries-DFAUd_Aw.js → speechSettingsQueries-xWFTnUfF.js} +1 -1
  52. package/dist/assets/src-omVWmz3o.css +2 -0
  53. package/dist/assets/{textarea-C5vjnZcE.js → textarea-BkOdxUN0.js} +1 -1
  54. package/dist/assets/{tooltip-C73L9gDf.js → tooltip-BQQoK7L_.js} +1 -1
  55. package/dist/assets/{types-DZcrt4Z0.js → types-BzF7Dhzq.js} +1 -1
  56. package/dist/assets/{useAppFontEffects-DUPuwJH5.js → useAppFontEffects-lmtncXsi.js} +7 -7
  57. package/dist/assets/{useDesktopWindowControlsLayout-Co_z6hbP.js → useDesktopWindowControlsLayout-BY0_whx0.js} +1 -1
  58. package/dist/assets/{useEffectiveDirectory-DXPmcf8E.js → useEffectiveDirectory-CqkTJqRg.js} +1 -1
  59. package/dist/assets/{useMobileNavigationStore-DcG6Ukmu.js → useMobileNavigationStore-BURkCJuM.js} +4 -4
  60. package/dist/assets/{useWorkerHighlightedLines-BnmJy3ZO.js → useWorkerHighlightedLines-Bla356tF.js} +1 -1
  61. package/dist/index.html +6 -6
  62. package/dist/mini-chat.html +6 -6
  63. package/dist/mobile.html +6 -6
  64. package/package.json +1 -1
  65. package/server/lib/assistants/DOCUMENTATION.md +13 -2
  66. package/server/lib/assistants/contact-store.js +2 -1
  67. package/server/lib/assistants/contact-store.test.js +13 -3
  68. package/server/lib/assistants/routes.js +2 -1
  69. package/server/lib/assistants/service.js +54 -7
  70. package/server/lib/assistants/service.test.js +59 -10
  71. package/server/lib/opencode/feature-routes-runtime.js +1 -1
  72. package/server/lib/relay/DOCUMENTATION.md +2 -0
  73. package/server/lib/relay/service.js +1 -1
  74. package/server/lib/relay/service.test.js +3 -3
  75. package/dist/assets/AssistantView-CLk1T4Of.js +0 -3
  76. package/dist/assets/MobileShareBridge-DLPBToEM.js +0 -4
  77. package/dist/assets/MobileTabPageHeader-CvtrPaC2.js +0 -2
  78. package/dist/assets/SettingsView-pRXWe1jD.js +0 -26
  79. package/dist/assets/button-_ReBqWzC.js +0 -1
  80. package/dist/assets/renderMobileApp-BlCyG-WF.js +0 -28
  81. package/dist/assets/runtimeEndpointReset-DrO__UOn.js +0 -149
  82. package/dist/assets/sessionChangeSummary-DN7H-rqE.js +0 -1
  83. package/dist/assets/sessionLookup-DezY-ONT.js +0 -1
  84. package/dist/assets/src-CmermOKP.css +0 -2
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{p as t}from"./runtime-auth-ef9W7A43.js";import{c as n,f as r,i}from"./runtime-switch-CAZiOV2G.js";import{u as a}from"./queryRuntime-DKGLQtb9.js";import{it as o}from"./vendor-base-ui-CdzJ6My_.js";import{St as s}from"./platform-7bX6qtBV.js";import{n as c}from"./vendor-react-BP2cRVqX.js";import{n as l}from"./vendor-reactuses-core-BpfIZ1tg.js";import{f as u}from"./button-_ReBqWzC.js";var d=`yuri:close-embedded-session-chat`,f=`yuri:embedded-visibility`,p=`yuri:embedded-visibility-request`,m=e=>new URLSearchParams(e).get(`yuriPanel`)===`session-chat`,h=(e,t,n)=>JSON.stringify({sessionID:e,directory:t||``,readOnly:n===!0}),g=(e,t,n,r)=>{if(typeof window>`u`)return``;let i=new URL(window.location.pathname,window.location.origin);return i.searchParams.set(`yuriPanel`,`session-chat`),i.searchParams.set(`surface`,`desktop`),i.searchParams.set(`sessionId`,e),n?i.searchParams.set(`readOnly`,`1`):i.searchParams.delete(`readOnly`),t&&t.trim().length>0?i.searchParams.set(`directory`,t):i.searchParams.delete(`directory`),i.searchParams.set(`themeMode`,r.mode),i.searchParams.set(`lightThemeId`,r.lightThemeId),i.searchParams.set(`darkThemeId`,r.darkThemeId),i.searchParams.set(`themeVariant`,r.currentTheme.metadata.variant===`dark`?`dark`:`light`),i.searchParams.set(`currentTheme`,JSON.stringify(r.currentTheme)),i.hash=``,i.toString()},_=(e,t,n,r,i,a)=>{let o=h(n,r,i),s=e.get(t);if(s?.signature===o)return s.src;let c=g(n,r,i,a);return e.set(t,{signature:o,src:c}),c},v=null,y=()=>{if(v!==null)return v;if(typeof window>`u`)return v=!1,!1;try{return v=new URLSearchParams(window.location.search).get(`yuriPanel`)===`session-chat`,v}catch{return v=!1,!1}},b=()=>{if(!y())return null;try{let e=new URLSearchParams(window.location.search).get(`sessionId`);return e&&e.trim().length>0?e.trim():null}catch{return null}},x=e(o(),1);async function S(e,t){let n=i(),r=await a(`/api/voice/session`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({kind:e}),signal:AbortSignal.any([t,AbortSignal.timeout(2e4)])});if(t.throwIfAborted(),n!==i())throw Error(`Speech runtime changed`);if(r.status===404||r.ok&&r.headers.get(`content-type`)?.includes(`text/html`))return await r.body?.cancel(),null;if(!r.ok)throw await r.body?.cancel(),Error(`Unable to create speech session`);let o=await r.json();if(t.throwIfAborted(),n!==i())throw Error(`Speech runtime changed`);if(o?.transport===`host`)return null;if(o?.transport!==`volcengine-direct`||typeof o.token!=`string`||o.token.length>16384||!/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(o.token)||typeof o.appId!=`string`||!/^[A-Za-z0-9_-]{1,128}$/.test(o.appId)||typeof o.resourceId!=`string`||!/^[A-Za-z0-9._-]{1,128}$/.test(o.resourceId)||!Number.isFinite(o.expiresAt)||o.expiresAt<=Date.now()+5e3||o.expiresAt>Date.now()+36e4||e===`tts`&&(typeof o.voice!=`string`||!/^[A-Za-z0-9_-]{1,200}$/.test(o.voice)||!Number.isFinite(o.speed)||o.speed<.5||o.speed>2||!Number.isFinite(o.pitch)||o.pitch<.5||o.pitch>2||!Number.isFinite(o.volume)||o.volume<0||o.volume>1)||e===`asr`&&o.asrContext!==void 0&&(typeof o.asrContext!=`string`||o.asrContext.length>2e3||/\0/.test(o.asrContext)))throw Error(`Invalid speech session`);return o}function C(e,t){let n=new URL(t===`asr`?`wss://openspeech.bytedance.com/api/v3/sauc/bigmodel_async`:`wss://openspeech.bytedance.com/api/v3/tts/bidirection`);return n.search=new URLSearchParams({api_app_key:e.appId,api_access_key:`Jwt; ${e.token}`,api_resource_id:e.resourceId}).toString(),n.toString()}var w=new TextEncoder,T=new TextDecoder,E=1048576;function D(e,t=!1,n=!1){let r=new Uint8Array(8+e.length);return r.set([17,(t?2:1)<<4|(n?2:0),t?0:16,0]),new DataView(r.buffer).setUint32(4,e.length),r.set(e,8),r}function O(e,t=``,n={}){let r=w.encode(t),i=w.encode(JSON.stringify(n)),a=new Uint8Array(12+i.length+(t?4+r.length:0));a.set([17,20,16,0]);let o=new DataView(a.buffer);o.setInt32(4,e);let s=8;return t&&(o.setUint32(s,r.length),a.set(r,s+4),s+=4+r.length),o.setUint32(s,i.length),a.set(i,s+4),a}async function k(e,t){if(e.byteLength<8||e.byteLength>E)throw Error(`Invalid speech frame size`);let n=new Uint8Array(e),r=new DataView(e),i=n[1]>>4,a=n[1]&15,o=n[2]&15,s=(n[0]&15)*4;if(n[0]>>4!=1||s<4||s>n.length-4)throw Error(`Invalid speech frame`);let c=()=>{if(s+4>n.length)throw Error(`Truncated speech frame`);let e=r.getUint32(s);return s+=4,e};if(i===15)throw Error(`Speech provider failed (code ${c()})`);if(i!==9&&(t!==`tts`||i!==11))throw Error(`Unexpected speech frame`);a&1&&c();let l=0,u=``;if(a&4&&(l=c(),t===`tts`)){let e=c();if(e>256||s+e>n.length)throw Error(`Invalid speech session ID`);u=T.decode(n.subarray(s,s+e)),s+=e}let d=c();if(s+d!==n.length)throw Error(`Truncated speech payload`);let f=n.slice(s);if(o===1){let e=new Blob([f]).stream().pipeThrough(new DecompressionStream(`gzip`)).getReader(),t=[],n=0;try{for(;;){let r=await e.read();if(r.done)break;if(n+=r.value.length,n>E)throw Error(`Speech payload exceeds size limit`);t.push(r.value)}}finally{await e.cancel().catch(()=>void 0),e.releaseLock()}f=new Uint8Array(n);let r=0;for(let e of t)f.set(e,r),r+=e.length}else if(o!==0)throw Error(`Unsupported speech compression`);return{type:i,event:l,sessionId:u,final:!!(a&2),payload:f}}function A(e){let t=JSON.parse(T.decode(e));if(!t||typeof t!=`object`||Array.isArray(t))throw Error(`Invalid speech response`);return t}async function j(e,t){t.throwIfAborted();let n=new WebSocket(e);n.binaryType=`arraybuffer`;let r=[],i=0,a=null,o=null,s=null,c=(e=!0)=>{t.removeEventListener(`abort`,u),n.onmessage=null,n.onclose=null,n.onerror=null,n.onopen=null,e&&(r.length=0,i=0),n.close(),o?.()},l=(e,t=!0)=>{a??=e,s?.(a),c(t)},u=()=>l(new DOMException(`Speech cancelled`,`AbortError`));t.addEventListener(`abort`,u,{once:!0}),n.onmessage=e=>{if(!(e.data instanceof ArrayBuffer)||e.data.byteLength>E){l(Error(`Invalid speech message`));return}if(i+=e.data.byteLength,i>33554432||r.length>=4096){l(Error(`Speech receive buffer exceeded`));return}r.push(e.data),o?.()},n.onerror=()=>l(Error(`Speech connection failed`)),n.onclose=()=>l(Error(`Speech connection ended before completion`),!1);let d=setTimeout(()=>l(Error(`Speech connection timed out`)),1e4);try{await new Promise((e,t)=>{s=t,n.onopen=()=>e()})}finally{clearTimeout(d),s=null}return{send(e){if(t.throwIfAborted(),a)throw a;if(n.readyState!==WebSocket.OPEN||n.bufferedAmount+e.length>E)throw Error(`Speech send buffer exceeded`);n.send(e)},async read(){let e=setTimeout(()=>l(Error(`Speech response timed out`)),6e4);try{for(;!r.length&&!a;)await new Promise(e=>{o=e});if(t.throwIfAborted(),!r.length&&a)throw a;let e=r.shift();return i-=e.byteLength,e}finally{clearTimeout(e),o=null}},close(){a??=new DOMException(`Speech closed`,`AbortError`),c()}}}var M=class{abort;partial;disconnected;socket=null;failure=null;completion=null;text=``;final=!1;finishing=!1;sequence=0;constructor(e,t,n){this.abort=e,this.partial=t,this.disconnected=n}get connected(){return this.socket!==null&&!this.failure&&!this.abort.signal.aborted}async start(e,t){if(t!==`audio/pcm;rate=16000;bits=16`)throw Error(`Direct speech requires 16 kHz PCM16 audio`);let n=await j(C(e,`asr`),this.abort.signal);this.socket=n;try{n.send(D(new TextEncoder().encode(JSON.stringify({user:{uid:`yuri`},audio:{format:`pcm`,codec:`raw`,rate:16e3,bits:16,channel:1},request:{model_name:`bigmodel`,result_type:`full`,enable_itn:!0,enable_punc:!0,enable_nonstream:!0,show_utterances:!0,...e.asrContext?.trim()?{corpus:{context:JSON.stringify({context_type:`dialog_ctx`,context_data:[{text:e.asrContext.trim()}]})}}:{}}}))))}catch(e){throw n.close(),e}this.completion=this.receive().catch(e=>{this.failure=e instanceof Error?e:Error(`Speech recognition failed`),n.close(),!this.abort.signal.aborted&&!this.finishing&&this.disconnected()})}send(e,t){if(!this.connected||this.finishing||this.final||e!==this.sequence)return!1;try{if(t.length>128e3)throw Error(`Speech audio chunk exceeds size limit`);let e=atob(t);if(e.length%2)throw Error(`Invalid PCM audio`);let n=Uint8Array.from(e,e=>e.charCodeAt(0));return this.socket.send(D(n,!0)),this.sequence++,!0}catch{return this.failure=Error(`Unable to send speech audio`),this.socket?.close(),!1}}async finish(e){if(this.failure)throw this.failure;if(!this.socket||e!==this.sequence-1)throw Error(`Incomplete speech audio`);this.finishing=!0,this.socket.send(D(new Uint8Array,!0,!0));let t=setTimeout(()=>{this.failure=Error(`Speech finalization timed out`),this.socket?.close()},3e4);try{if(await this.completion,this.abort.signal.throwIfAborted(),this.failure)throw this.failure;if(!this.final)throw Error(`Incomplete speech recognition`);return{text:this.text}}finally{clearTimeout(t),this.socket.close()}}cancel(){this.abort.abort(),this.socket?.close()}async receive(){for(;;){let e=await k(await this.socket.read(),`asr`);this.abort.signal.throwIfAborted();let t=A(e.payload);if(t.code!==void 0&&![0,1e3,2e7].includes(Number(t.code)))throw Error(`Speech recognition failed`);let n=t.result;if(n!==void 0&&(!n||typeof n!=`object`||Array.isArray(n)))throw Error(`Invalid speech transcript`);if(n&&typeof n==`object`&&`text`in n){if(typeof n.text!=`string`)throw Error(`Invalid speech transcript`);this.text=n.text,e.final||this.partial(this.text)}if(e.final){if(!this.finishing)throw Error(`Speech recognition ended unexpectedly`);this.final=!0;return}}}},N=(e,t,n)=>{let r=Error(e);return r.name=`DictationStreamError`,r.retryable=t,n&&(r.reasonCode=n),r},P=1e4,F=15e3,I=3e4,L=3e4,R=new class{socket=null;connectPromise=null;idleCloseTimer=null;pendingStarts=new Map;pendingFinishes=new Map;connectionListeners=new Set;partialListeners=new Set;activeDictations=0;directStarts=new Map;directSessions=new Map;get isConnected(){if(this.socket?.readyState===WebSocket.OPEN)return!0;for(let e of this.directSessions.values())if(e.connected)return!0;return!1}subscribeConnectionStatus(e){return this.connectionListeners.add(e),()=>{this.connectionListeners.delete(e)}}onPartial(e){return this.partialListeners.add(e),()=>{this.partialListeners.delete(e)}}async ensureConnected(){if(this.socket?.readyState!==WebSocket.OPEN){if(this.connectPromise){await this.connectPromise;return}try{await t()}catch{}this.connectPromise=new Promise((e,t)=>{let n=!1,i;try{let e=r().websocket(`/api/dictation/ws`);i=s(e)}catch(e){this.connectPromise=null,t(e instanceof Error?e:Error(String(e)));return}let a=setTimeout(()=>{if(!n){n=!0,this.connectPromise=null;try{i.close()}catch{}t(Error(`Dictation connection timed out`))}},P);i.onopen=()=>{},i.onmessage=t=>{let r;try{r=JSON.parse(String(t.data))}catch{return}if(!n&&r.type===`ready`){n=!0,clearTimeout(a),this.socket=i,this.connectPromise=null,this.notifyConnection(!0),e();return}this.handleMessage(r)},i.onerror=()=>{window.setTimeout(()=>{n||(n=!0,clearTimeout(a),this.connectPromise=null,t(Error(`Dictation connection failed`)))},250)},i.onclose=e=>{if(!n){n=!0,clearTimeout(a),this.connectPromise=null;let r=e?.reason?`: ${e.reason}`:``;t(Error(`Dictation connection failed${r}`));return}this.socket===i&&(this.socket=null,this.rejectAllPending(Error(`Dictation connection lost`)),this.notifyConnection(!1))}}),await this.connectPromise}}async startDictationStream(e,t){let n=new AbortController;this.directStarts.set(e,n);try{let r=await S(`asr`,n.signal);if(n.signal.throwIfAborted(),r){let i=new M(n,t=>{for(let n of this.partialListeners)n(e,t)},()=>{this.directSessions.delete(e),i.cancel(),this.notifyConnection(!1)});this.directSessions.set(e,i),await i.start(r,t),n.signal.throwIfAborted(),this.notifyConnection(!0);return}await this.ensureConnected(),n.signal.throwIfAborted()}catch(t){throw this.directSessions.get(e)?.cancel(),this.directSessions.delete(e),t}finally{this.directStarts.delete(e)}return this.activeDictations+=1,this.clearIdleCloseTimer(),new Promise((n,r)=>{let i=setTimeout(()=>{this.pendingStarts.delete(e),this.releaseDictation(),r(Error(`Dictation start timed out`))},F);this.pendingStarts.set(e,{resolve:()=>{clearTimeout(i),n()},reject:e=>{clearTimeout(i),this.releaseDictation(),r(e)},timeout:i}),this.send({type:`start`,dictationId:e,format:t})||(clearTimeout(i),this.pendingStarts.delete(e),this.releaseDictation(),r(Error(`Dictation connection lost`)))})}sendDictationStreamChunk(e,t,n){let r=this.directSessions.get(e);return r?r.send(t,n):this.send({type:`chunk`,dictationId:e,seq:t,audio:n})}finishDictationStream(e,t){let n=this.directSessions.get(e);return n?n.finish(t).finally(()=>{n.cancel(),this.directSessions.delete(e)}):new Promise((n,r)=>{let i={resolve:e=>{i.timeout&&clearTimeout(i.timeout),this.releaseDictation(),n(e)},reject:e=>{i.timeout&&clearTimeout(i.timeout),this.releaseDictation(),r(e)},timeout:null};i.timeout=setTimeout(()=>{this.pendingFinishes.delete(e),this.releaseDictation(),r(Error(`Timed out waiting for transcription`))},L),this.pendingFinishes.set(e,i),this.send({type:`finish`,dictationId:e,finalSeq:t})||(this.pendingFinishes.delete(e),i.reject(Error(`Dictation connection lost`)))})}cancelDictationStream(e){this.directStarts.get(e)?.abort(),this.directStarts.delete(e);let t=this.directSessions.get(e);if(t){t.cancel(),this.directSessions.delete(e);return}this.send({type:`cancel`,dictationId:e});let n=this.pendingStarts.get(e);n&&(this.pendingStarts.delete(e),n.reject(Error(`Dictation cancelled`)));let r=this.pendingFinishes.get(e);r&&(this.pendingFinishes.delete(e),r.reject(Error(`Dictation cancelled`))),this.releaseDictation(),this.scheduleIdleCloseIfReady()}handleMessage(e){let t=e.dictationId;if(t)switch(e.type){case`ack`:{let e=this.pendingStarts.get(t);e&&(this.pendingStarts.delete(t),e.resolve());return}case`partial`:for(let n of this.partialListeners)n(t,e.text??``);return;case`finish_accepted`:{let n=this.pendingFinishes.get(t);n&&typeof e.timeoutMs==`number`&&(n.timeout&&clearTimeout(n.timeout),n.timeout=setTimeout(()=>{this.pendingFinishes.delete(t),n.reject(Error(`Timed out waiting for transcription`))},e.timeoutMs+5e3));return}case`final`:{let n=this.pendingFinishes.get(t);n&&(this.pendingFinishes.delete(t),n.resolve({text:e.text??``})),this.scheduleIdleCloseIfReady();return}case`error`:{let n=N(e.error||`Dictation failed`,e.retryable!==!1,e.reasonCode),r=this.pendingStarts.get(t);r&&(this.pendingStarts.delete(t),r.reject(n));let i=this.pendingFinishes.get(t);i&&(this.pendingFinishes.delete(t),i.reject(n)),this.scheduleIdleCloseIfReady();return}}}send(e){if(!this.isConnected||!this.socket)return!1;try{return this.socket.send(JSON.stringify(e)),!0}catch{return!1}}notifyConnection(e){for(let t of this.connectionListeners)t(e)}rejectAllPending(e){for(let[t,n]of this.pendingStarts)this.pendingStarts.delete(t),n.reject(e);for(let[t,n]of this.pendingFinishes)this.pendingFinishes.delete(t),n.reject(e);this.activeDictations=0}releaseDictation(){this.activeDictations=Math.max(0,this.activeDictations-1),this.scheduleIdleCloseIfReady()}scheduleIdleCloseIfReady(){this.activeDictations>0||this.pendingFinishes.size>0||this.pendingStarts.size>0||(this.clearIdleCloseTimer(),this.idleCloseTimer=setTimeout(()=>{if(this.activeDictations===0&&this.pendingFinishes.size===0&&this.pendingStarts.size===0){let e=this.socket;if(this.socket=null,e){try{e.close(1e3,`idle`)}catch{}this.notifyConnection(!1)}}},I))}cancelAllForRuntimeSwitch(){for(let e of this.directStarts.values())e.abort();this.directStarts.clear();for(let e of this.directSessions.values())e.cancel();this.directSessions.clear(),this.clearIdleCloseTimer();let e=this.socket;if(this.socket=null,this.connectPromise=null,this.rejectAllPending(Error(`Runtime changed`)),e){try{e.close(1e3,`runtime switch`)}catch{}this.notifyConnection(!1)}}clearIdleCloseTimer(){this.idleCloseTimer&&=(clearTimeout(this.idleCloseTimer),null)}};typeof window<`u`&&window.addEventListener(`yuri:runtime-endpoint-changed`,()=>{R.cancelAllForRuntimeSwitch()});var z=128,B=`audio/pcm;rate=16000;bits=16`,V=()=>new Promise(e=>setTimeout(e,0)),H=()=>{let e=Math.random().toString(36).slice(2,10);return`dic_${Date.now().toString(16)}${e}`},ee=class{client;format;createDictationId;dictationId=null;sendSeq=0;segments=[];streamReady=!1;flushTimer=null;drainWaiters=[];startGeneration=0;startPromise=null;constructor(e){this.client=e.client,this.format=e.format??B,this.createDictationId=e.createDictationId??H}getDictationId(){return this.dictationId}getFinalSeq(){return this.segments.length-1}hasSegments(){return this.segments.length>0}clearAll(){this.dictationId&&this.client.cancelDictationStream(this.dictationId),this.clearScheduledFlush(),this.dictationId=null,this.sendSeq=0,this.segments=[],this.streamReady=!1,this.startPromise=null,this.startGeneration+=1}resetStreamForReplay(){this.dictationId&&this.client.cancelDictationStream(this.dictationId),this.clearScheduledFlush(),this.dictationId=null,this.sendSeq=0,this.streamReady=!1,this.startPromise=null,this.startGeneration+=1}enqueueSegment(e){if(this.segments.push(e),this.client.isConnected){if(!this.dictationId){this.startPromise||this.restartStream().catch(()=>{});return}this.flush()}}flush(){let e=this.dictationId;if(!this.client.isConnected||!e||!this.streamReady)return 0;let t=0;for(;this.sendSeq<this.segments.length&&t<z;){let n=this.sendSeq,r=this.segments[n];if(!this.client.sendDictationStreamChunk(e,n,r))break;this.sendSeq=n+1,t+=1}return this.hasPendingSegments()?this.scheduleFlush():this.resolveDrainWaiters(),t}async restartStream(){this.startGeneration+=1;let e=this.startGeneration,t=this.createDictationId();this.dictationId=t,this.sendSeq=0,this.streamReady=!1;let n=(async()=>{await this.client.startDictationStream(t,this.format),this.startGeneration===e&&this.dictationId===t&&(this.streamReady=!0,this.flush())})().catch(n=>{throw this.startGeneration===e&&this.dictationId===t&&(this.dictationId=null,this.streamReady=!1),n}).finally(()=>{this.startPromise===n&&(this.startPromise=null)});this.startPromise=n,await n}async finish(e){this.dictationId||await this.restartStream(),this.startPromise&&await this.startPromise;let t=this.dictationId;if(!t||!this.streamReady)throw Error(`Failed to start dictation stream`);return this.flush(),await this.waitForFlushDrain(),{dictationId:t,text:(await this.client.finishDictationStream(t,e)).text}}cancel(){this.resetStreamForReplay()}hasPendingSegments(){return this.sendSeq<this.segments.length}scheduleFlush(){this.flushTimer||=setTimeout(()=>{this.flushTimer=null,this.flush()},0)}clearScheduledFlush(){this.resolveDrainWaiters(),this.flushTimer&&=(clearTimeout(this.flushTimer),null)}async waitForFlushDrain(){for(;this.hasPendingSegments();){if(!this.client.isConnected||!this.dictationId||!this.streamReady)throw Error(`Failed to flush dictation stream`);await new Promise(e=>{this.drainWaiters.push(e)}),await V()}}resolveDrainWaiters(){let e=this.drainWaiters;this.drainWaiters=[];for(let t of e)t()}},U=c(),W=new Set;function G(e){return W.add(e),()=>{W.delete(e)}}function K(){for(let e of W)e();if(typeof window<`u`&&window.speechSynthesis?.cancel(),typeof navigator>`u`)return;let e=navigator.audioSession;if(e)try{e.type=`play-and-record`}catch{}}function te(){if(typeof navigator>`u`)return;let e=navigator.audioSession;if(e)try{e.type!==`playback`&&(e.type=`playback`)}catch{}}var q=16e3,J=q/5,Y=()=>{if(typeof window>`u`)return null;let e=window;return e.AudioContext||e.webkitAudioContext||null},X=e=>{let t=Math.max(-1,Math.min(1,e));return Math.round(t<0?t*32768:t*32767)},ne=(e,t,n)=>{if(e.length===0)return new Int16Array;if(t===n){let t=new Int16Array(e.length);for(let n=0;n<e.length;n++)t[n]=X(e[n]);return t}let r=t/n,i=Math.max(1,Math.round(e.length/r)),a=new Int16Array(i);for(let t=0;t<i;t++){let n=t*r,i=Math.floor(n),o=Math.min(e.length-1,i+1),s=n-i;a[t]=X(e[i]*(1-s)+e[o]*s)}return a},re=(e,t)=>{if(e.length===0)return t;if(t.length===0)return e;let n=new Int16Array(e.length+t.length);return n.set(e,0),n.set(t,e.length),n},Z=e=>{let t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),n=``;for(let e=0;e<t.length;e++)n+=String.fromCharCode(t[e]);return btoa(n)},Q=()=>({stream:null,context:null,source:null,processor:null,gain:null,pending:new Int16Array,started:!1}),$=e=>{if(e)try{e.disconnect()}catch{}},ie=()=>typeof navigator>`u`||typeof window>`u`||!navigator.mediaDevices||typeof navigator.mediaDevices.getUserMedia!=`function`?!1:Y()!==null;function ae(e){let t=(0,U.c)(16),[n,r]=(0,x.useState)(0),i=(0,x.useRef)(e.onPcmSegment),a=(0,x.useRef)(e.onError),o,s;t[0]!==e.onError||t[1]!==e.onPcmSegment?(o=()=>{i.current=e.onPcmSegment,a.current=e.onError},s=[e.onPcmSegment,e.onError],t[0]=e.onError,t[1]=e.onPcmSegment,t[2]=o,t[3]=s):(o=t[2],s=t[3]),(0,x.useEffect)(o,s);let c;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(c=Q(),t[4]=c):c=t[4];let u=(0,x.useRef)(c),d=(0,x.useRef)(0),f;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(f=async()=>{if(u.current.started)return;if(typeof navigator>`u`||!navigator.mediaDevices||typeof navigator.mediaDevices.getUserMedia!=`function`)throw Error(`Microphone capture is not supported in this environment`);let e=Y();if(!e)throw Error(`AudioContext unavailable`);let t=d.current+=1;K();let n=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,noiseSuppression:!0,echoCancellation:!0,autoGainControl:!0}});if(t!==d.current){n.getTracks().forEach(ue);return}let a=new e;try{if(a.state===`suspended`&&await a.resume().catch(le),t!==d.current){n.getTracks().forEach(ce),await a.close();return}let e=a.createMediaStreamSource(n),o=a.createScriptProcessor(4096,1,1),s=a.createGain();s.gain.value=0,u.current={stream:n,context:a,source:e,processor:o,gain:s,pending:new Int16Array,started:!0},o.onaudioprocess=e=>{let t=u.current;if(!t.started)return;let n=e.inputBuffer.getChannelData(0),o=0;for(let e=0;e<n.length;e++)o+=n[e]*n[e];let s=Math.sqrt(o/Math.max(1,n.length));r(Math.min(1,Math.max(0,s*2)));let c=ne(n,a.sampleRate,q);for(t.pending=re(t.pending,c);t.pending.length>=J;){let e=t.pending.slice(0,J);t.pending=t.pending.slice(J),i.current(Z(e))}},e.connect(o),o.connect(s),s.connect(a.destination)}catch(e){let t=e;n.getTracks().forEach(se);try{await a.close()}catch{}throw u.current=Q(),t instanceof Error?t:Error(String(t))}},t[5]=f):f=t[5];let p=l(f),m;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(m=async()=>{d.current+=1;let e=u.current;if(e.started=!1,r(0),e.processor)try{e.processor.onaudioprocess=null}catch{}$(e.processor),$(e.source),$(e.gain),e.stream&&e.stream.getTracks().forEach(oe);let t=e.pending;if(e.pending=new Int16Array,t.length>0&&i.current(Z(t)),e.context)try{await e.context.close()}catch{}u.current===e&&(u.current=Q())},t[6]=m):m=t[6];let h=l(m),g,_;t[7]===h?(g=t[8],_=t[9]):(g=()=>()=>{h().catch(e=>{a.current?.(e instanceof Error?e:Error(String(e)))})},_=[h],t[7]=h,t[8]=g,t[9]=_),(0,x.useEffect)(g,_);let v;t[10]===p?v=t[11]:(v=async()=>{try{await p()}catch(e){let t=e,n=t instanceof Error?t:Error(String(t));throw a.current?.(n),n}},t[10]=p,t[11]=v);let y;return t[12]!==h||t[13]!==v||t[14]!==n?(y={start:v,stop:h,volume:n},t[12]=h,t[13]=v,t[14]=n,t[15]=y):y=t[15],y}function oe(e){try{e.stop()}catch{}}function se(e){try{e.stop()}catch{}}function ce(e){return e.stop()}function le(){}function ue(e){return e.stop()}var de=1e3,fe=e=>e instanceof Error?e:Error(String(e));function pe(e={}){let{t}=u(),{onTranscript:r,onError:i,canStart:a}=e,[o,s]=(0,x.useState)(`idle`),[c,d]=(0,x.useState)(!1),[f,p]=(0,x.useState)(``),[m,h]=(0,x.useState)(0),[g,_]=(0,x.useState)(null),[v,y]=(0,x.useState)(null),b=(0,x.useRef)(o);(0,x.useEffect)(()=>{b.current=o},[o]);let S=(0,x.useRef)(``),C=(0,x.useRef)(null),w=(0,x.useRef)({starting:!1,confirming:!1,cancelling:!1}),T=(0,x.useRef)(0),E=(0,x.useRef)(r),D=(0,x.useRef)(i);(0,x.useEffect)(()=>{E.current=r,D.current=i},[r,i]);let O=(0,x.useRef)(null);O.current||=new ee({client:R});let k=l(()=>{C.current&&=(clearInterval(C.current),null)}),A=l(()=>{C.current||=setInterval(()=>{h(e=>e+1)},de)}),j=l(e=>{let n=fe(e),r=n.name===`NotFoundError`||n.name===`DevicesNotFoundError`?Error(t(`chat.dictation.error.microphoneNotFound`),{cause:n}):n;_(r.message);let i=n.reasonCode;y(typeof i==`string`?i:null),D.current?.(r)}),M=l(()=>{_(null),y(null)}),N=l(()=>{O.current?.clearAll(),S.current=``,p(``)}),P=l(t=>e.onPartialTranscript?.(t));(0,x.useEffect)(()=>R.onPartial((e,t)=>{let n=O.current?.getDictationId();!n||e!==n||(S.current=t,p(t),P(t))}),[P]),(0,x.useEffect)(()=>R.subscribeConnectionStatus(e=>{if(!e){b.current===`recording`&&O.current?.resetStreamForReplay();return}if(b.current!==`recording`||O.current?.getDictationId())return;let t=T.current;O.current?.restartStream().catch(e=>{T.current===t&&j(e)})}),[j]);let F=ae({onPcmSegment:e=>{b.current===`recording`&&O.current?.enqueueSegment(e)},onError:e=>{D.current?.(e)}}),I=(0,x.useRef)(F.stop);(0,x.useEffect)(()=>{I.current=F.stop},[F.stop]);let L=l(e=>{h(0),s(`idle`),b.current=`idle`;let t=e.trim();return N(),t?(E.current?.(t),t):null}),z=l(e=>{O.current?.hasSegments()?(s(`failed`),b.current=`failed`):(s(`idle`),b.current=`idle`),j(e)}),B=l(async()=>{let e=w.current;if(e.starting||e.confirming||e.cancelling||b.current!==`idle`||a&&!a())return;e.starting=!0,d(!0);let t=++T.current;M(),p(``),h(0),s(`recording`),b.current=`recording`,N();try{if(await F.start(),T.current!==t||b.current!==`recording`)return;d(!1),A(),await O.current?.restartStream().catch(e=>{T.current===t&&j(e)})}catch(e){if(T.current!==t)return;await F.stop().catch(()=>void 0),k(),s(`idle`),b.current=`idle`,j(e)}finally{T.current===t&&d(!1),e.starting=!1}}),V=l(async()=>{let e=w.current;if(!e.cancelling&&(b.current===`recording`||b.current===`uploading`)){e.cancelling=!0,d(!1),T.current+=1,k(),h(0),M(),s(`idle`),b.current=`idle`;try{O.current?.cancel()}catch{}N();try{await F.stop()}catch{}finally{e.cancelling=!1}}}),H=l(async()=>{let e=w.current;if(e.confirming||b.current!==`recording`)return null;e.confirming=!0,d(!1);let t=++T.current;M(),k();try{if(await F.stop(),T.current!==t)return null;s(`uploading`),b.current=`uploading`;let e=O.current?.getFinalSeq()??-1;if(e<0)return O.current?.cancel(),L(``);let n=await O.current.finish(e);return T.current===t?L(n.text):null}catch(e){return T.current===t&&z(e),null}finally{e.confirming=!1}}),U=l(async()=>{if(b.current!==`failed`||!O.current?.hasSegments())return null;M();let e=++T.current;s(`uploading`),b.current=`uploading`;try{O.current.resetStreamForReplay();let t=O.current.getFinalSeq(),n=await O.current.finish(t);return T.current===e?L(n.text):null}catch(t){return T.current===e&&z(t),null}}),W=l(()=>{if(b.current!==`failed`)return null;let e=S.current.trim();h(0),s(`idle`),b.current=`idle`,M();try{O.current?.cancel()}catch{}return N(),e?(E.current?.(e),e):null}),G=l(()=>{h(0),s(`idle`),b.current=`idle`,M(),N()});return(0,x.useEffect)(()=>n(()=>{b.current===`failed`?(T.current+=1,G()):V()}),[V,G]),(0,x.useEffect)(()=>{if(o!==`recording`||v!==`model_download_in_progress`)return;let e=setInterval(()=>{b.current!==`recording`||O.current?.getDictationId()||O.current?.restartStream().then(()=>{M()}).catch(e=>{j(e)})},3e3);return()=>clearInterval(e)},[o,v,M,j]),(0,x.useEffect)(()=>()=>{T.current+=1,k(),I.current().catch(()=>void 0),O.current?.cancel()},[k]),{status:o,isRecording:o===`recording`,isStarting:c,isProcessing:o===`uploading`,partialTranscript:f,volume:F.volume,duration:m,error:g,errorReason:v,startDictation:B,confirmDictation:H,cancelDictation:V,retryFailedDictation:U,acceptPartialTranscript:W,discardFailedDictation:G}}var me=`app-region-no-drag transition-[opacity,transform] duration-150 ease-out data-[starting-style]:opacity-0 data-[starting-style]:scale-95 data-[ending-style]:opacity-0 data-[ending-style]:scale-95 z-50 max-h-[var(--available-height)] min-w-[8rem] origin-[var(--transform-origin)] overflow-visible rounded-xl p-1 shadow-[inset_0_1px_0_0_rgba(255,255,255,0.8),inset_0_0_0_1px_rgba(0,0,0,0.04),0_0_0_1px_rgba(0,0,0,0.10),0_1px_2px_-0.5px_rgba(0,0,0,0.08),0_4px_8px_-2px_rgba(0,0,0,0.08),0_12px_20px_-4px_rgba(0,0,0,0.08)] dark:shadow-[inset_0_1px_0_0_rgba(255,255,255,0.12),inset_0_0_0_1px_rgba(255,255,255,0.08),0_0_0_1px_rgba(0,0,0,0.36),0_1px_1px_-0.5px_rgba(0,0,0,0.22),0_3px_3px_-1.5px_rgba(0,0,0,0.20),0_6px_6px_-3px_rgba(0,0,0,0.16)]`,he=`data-[highlighted]:bg-interactive-hover hover:bg-interactive-hover active:bg-interactive-active data-[variant=destructive]:text-destructive data-[variant=destructive]:hover:bg-destructive/10 dark:data-[variant=destructive]:hover:bg-destructive/20 data-[variant=destructive]:hover:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1 typography-ui-label outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-3.5`,ge=`data-[highlighted]:bg-interactive-hover hover:bg-interactive-hover active:bg-interactive-active [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1 typography-ui-label outline-hidden select-none data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-3.5`,_e=`bg-border -mx-1 my-0.5 h-px`;export{m as S,f as _,pe as a,_ as b,te as c,j as d,A as f,d as g,C as h,ge as i,G as l,S as m,me as n,ie as o,O as p,_e as r,K as s,he as t,k as u,p as v,y as x,b as y};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{p as t}from"./runtime-auth-ef9W7A43.js";import{c as n,f as r,i}from"./runtime-switch-CAZiOV2G.js";import{u as a}from"./queryRuntime-DKGLQtb9.js";import{it as o}from"./vendor-base-ui-CdzJ6My_.js";import{St as s}from"./platform-7bX6qtBV.js";import{n as c}from"./vendor-react-BP2cRVqX.js";import{n as l}from"./vendor-reactuses-core-BpfIZ1tg.js";import{f as u}from"./button-D_HdP1Oy.js";var d=`yuri:close-embedded-session-chat`,f=`yuri:embedded-visibility`,p=`yuri:embedded-visibility-request`,m=e=>new URLSearchParams(e).get(`yuriPanel`)===`session-chat`,h=(e,t,n)=>JSON.stringify({sessionID:e,directory:t||``,readOnly:n===!0}),g=(e,t,n,r)=>{if(typeof window>`u`)return``;let i=new URL(window.location.pathname,window.location.origin);return i.searchParams.set(`yuriPanel`,`session-chat`),i.searchParams.set(`surface`,`desktop`),i.searchParams.set(`sessionId`,e),n?i.searchParams.set(`readOnly`,`1`):i.searchParams.delete(`readOnly`),t&&t.trim().length>0?i.searchParams.set(`directory`,t):i.searchParams.delete(`directory`),i.searchParams.set(`themeMode`,r.mode),i.searchParams.set(`lightThemeId`,r.lightThemeId),i.searchParams.set(`darkThemeId`,r.darkThemeId),i.searchParams.set(`themeVariant`,r.currentTheme.metadata.variant===`dark`?`dark`:`light`),i.searchParams.set(`currentTheme`,JSON.stringify(r.currentTheme)),i.hash=``,i.toString()},_=(e,t,n,r,i,a)=>{let o=h(n,r,i),s=e.get(t);if(s?.signature===o)return s.src;let c=g(n,r,i,a);return e.set(t,{signature:o,src:c}),c},v=null,y=()=>{if(v!==null)return v;if(typeof window>`u`)return v=!1,!1;try{return v=new URLSearchParams(window.location.search).get(`yuriPanel`)===`session-chat`,v}catch{return v=!1,!1}},b=()=>{if(!y())return null;try{let e=new URLSearchParams(window.location.search).get(`sessionId`);return e&&e.trim().length>0?e.trim():null}catch{return null}},x=e(o(),1);async function S(e,t){let n=i(),r=await a(`/api/voice/session`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({kind:e}),signal:AbortSignal.any([t,AbortSignal.timeout(2e4)])});if(t.throwIfAborted(),n!==i())throw Error(`Speech runtime changed`);if(r.status===404||r.ok&&r.headers.get(`content-type`)?.includes(`text/html`))return await r.body?.cancel(),null;if(!r.ok)throw await r.body?.cancel(),Error(`Unable to create speech session`);let o=await r.json();if(t.throwIfAborted(),n!==i())throw Error(`Speech runtime changed`);if(o?.transport===`host`)return null;if(o?.transport!==`volcengine-direct`||typeof o.token!=`string`||o.token.length>16384||!/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(o.token)||typeof o.appId!=`string`||!/^[A-Za-z0-9_-]{1,128}$/.test(o.appId)||typeof o.resourceId!=`string`||!/^[A-Za-z0-9._-]{1,128}$/.test(o.resourceId)||!Number.isFinite(o.expiresAt)||o.expiresAt<=Date.now()+5e3||o.expiresAt>Date.now()+36e4||e===`tts`&&(typeof o.voice!=`string`||!/^[A-Za-z0-9_-]{1,200}$/.test(o.voice)||!Number.isFinite(o.speed)||o.speed<.5||o.speed>2||!Number.isFinite(o.pitch)||o.pitch<.5||o.pitch>2||!Number.isFinite(o.volume)||o.volume<0||o.volume>1)||e===`asr`&&o.asrContext!==void 0&&(typeof o.asrContext!=`string`||o.asrContext.length>2e3||/\0/.test(o.asrContext)))throw Error(`Invalid speech session`);return o}function C(e,t){let n=new URL(t===`asr`?`wss://openspeech.bytedance.com/api/v3/sauc/bigmodel_async`:`wss://openspeech.bytedance.com/api/v3/tts/bidirection`);return n.search=new URLSearchParams({api_app_key:e.appId,api_access_key:`Jwt; ${e.token}`,api_resource_id:e.resourceId}).toString(),n.toString()}var w=new TextEncoder,T=new TextDecoder,E=1048576;function D(e,t=!1,n=!1){let r=new Uint8Array(8+e.length);return r.set([17,(t?2:1)<<4|(n?2:0),t?0:16,0]),new DataView(r.buffer).setUint32(4,e.length),r.set(e,8),r}function O(e,t=``,n={}){let r=w.encode(t),i=w.encode(JSON.stringify(n)),a=new Uint8Array(12+i.length+(t?4+r.length:0));a.set([17,20,16,0]);let o=new DataView(a.buffer);o.setInt32(4,e);let s=8;return t&&(o.setUint32(s,r.length),a.set(r,s+4),s+=4+r.length),o.setUint32(s,i.length),a.set(i,s+4),a}async function k(e,t){if(e.byteLength<8||e.byteLength>E)throw Error(`Invalid speech frame size`);let n=new Uint8Array(e),r=new DataView(e),i=n[1]>>4,a=n[1]&15,o=n[2]&15,s=(n[0]&15)*4;if(n[0]>>4!=1||s<4||s>n.length-4)throw Error(`Invalid speech frame`);let c=()=>{if(s+4>n.length)throw Error(`Truncated speech frame`);let e=r.getUint32(s);return s+=4,e};if(i===15)throw Error(`Speech provider failed (code ${c()})`);if(i!==9&&(t!==`tts`||i!==11))throw Error(`Unexpected speech frame`);a&1&&c();let l=0,u=``;if(a&4&&(l=c(),t===`tts`)){let e=c();if(e>256||s+e>n.length)throw Error(`Invalid speech session ID`);u=T.decode(n.subarray(s,s+e)),s+=e}let d=c();if(s+d!==n.length)throw Error(`Truncated speech payload`);let f=n.slice(s);if(o===1){let e=new Blob([f]).stream().pipeThrough(new DecompressionStream(`gzip`)).getReader(),t=[],n=0;try{for(;;){let r=await e.read();if(r.done)break;if(n+=r.value.length,n>E)throw Error(`Speech payload exceeds size limit`);t.push(r.value)}}finally{await e.cancel().catch(()=>void 0),e.releaseLock()}f=new Uint8Array(n);let r=0;for(let e of t)f.set(e,r),r+=e.length}else if(o!==0)throw Error(`Unsupported speech compression`);return{type:i,event:l,sessionId:u,final:!!(a&2),payload:f}}function A(e){let t=JSON.parse(T.decode(e));if(!t||typeof t!=`object`||Array.isArray(t))throw Error(`Invalid speech response`);return t}async function j(e,t){t.throwIfAborted();let n=new WebSocket(e);n.binaryType=`arraybuffer`;let r=[],i=0,a=null,o=null,s=null,c=(e=!0)=>{t.removeEventListener(`abort`,u),n.onmessage=null,n.onclose=null,n.onerror=null,n.onopen=null,e&&(r.length=0,i=0),n.close(),o?.()},l=(e,t=!0)=>{a??=e,s?.(a),c(t)},u=()=>l(new DOMException(`Speech cancelled`,`AbortError`));t.addEventListener(`abort`,u,{once:!0}),n.onmessage=e=>{if(!(e.data instanceof ArrayBuffer)||e.data.byteLength>E){l(Error(`Invalid speech message`));return}if(i+=e.data.byteLength,i>33554432||r.length>=4096){l(Error(`Speech receive buffer exceeded`));return}r.push(e.data),o?.()},n.onerror=()=>l(Error(`Speech connection failed`)),n.onclose=()=>l(Error(`Speech connection ended before completion`),!1);let d=setTimeout(()=>l(Error(`Speech connection timed out`)),1e4);try{await new Promise((e,t)=>{s=t,n.onopen=()=>e()})}finally{clearTimeout(d),s=null}return{send(e){if(t.throwIfAborted(),a)throw a;if(n.readyState!==WebSocket.OPEN||n.bufferedAmount+e.length>E)throw Error(`Speech send buffer exceeded`);n.send(e)},async read(){let e=setTimeout(()=>l(Error(`Speech response timed out`)),6e4);try{for(;!r.length&&!a;)await new Promise(e=>{o=e});if(t.throwIfAborted(),!r.length&&a)throw a;let e=r.shift();return i-=e.byteLength,e}finally{clearTimeout(e),o=null}},close(){a??=new DOMException(`Speech closed`,`AbortError`),c()}}}var M=class{abort;partial;disconnected;socket=null;failure=null;completion=null;text=``;final=!1;finishing=!1;sequence=0;constructor(e,t,n){this.abort=e,this.partial=t,this.disconnected=n}get connected(){return this.socket!==null&&!this.failure&&!this.abort.signal.aborted}async start(e,t){if(t!==`audio/pcm;rate=16000;bits=16`)throw Error(`Direct speech requires 16 kHz PCM16 audio`);let n=await j(C(e,`asr`),this.abort.signal);this.socket=n;try{n.send(D(new TextEncoder().encode(JSON.stringify({user:{uid:`yuri`},audio:{format:`pcm`,codec:`raw`,rate:16e3,bits:16,channel:1},request:{model_name:`bigmodel`,result_type:`full`,enable_itn:!0,enable_punc:!0,enable_nonstream:!0,show_utterances:!0,...e.asrContext?.trim()?{corpus:{context:JSON.stringify({context_type:`dialog_ctx`,context_data:[{text:e.asrContext.trim()}]})}}:{}}}))))}catch(e){throw n.close(),e}this.completion=this.receive().catch(e=>{this.failure=e instanceof Error?e:Error(`Speech recognition failed`),n.close(),!this.abort.signal.aborted&&!this.finishing&&this.disconnected()})}send(e,t){if(!this.connected||this.finishing||this.final||e!==this.sequence)return!1;try{if(t.length>128e3)throw Error(`Speech audio chunk exceeds size limit`);let e=atob(t);if(e.length%2)throw Error(`Invalid PCM audio`);let n=Uint8Array.from(e,e=>e.charCodeAt(0));return this.socket.send(D(n,!0)),this.sequence++,!0}catch{return this.failure=Error(`Unable to send speech audio`),this.socket?.close(),!1}}async finish(e){if(this.failure)throw this.failure;if(!this.socket||e!==this.sequence-1)throw Error(`Incomplete speech audio`);this.finishing=!0,this.socket.send(D(new Uint8Array,!0,!0));let t=setTimeout(()=>{this.failure=Error(`Speech finalization timed out`),this.socket?.close()},3e4);try{if(await this.completion,this.abort.signal.throwIfAborted(),this.failure)throw this.failure;if(!this.final)throw Error(`Incomplete speech recognition`);return{text:this.text}}finally{clearTimeout(t),this.socket.close()}}cancel(){this.abort.abort(),this.socket?.close()}async receive(){for(;;){let e=await k(await this.socket.read(),`asr`);this.abort.signal.throwIfAborted();let t=A(e.payload);if(t.code!==void 0&&![0,1e3,2e7].includes(Number(t.code)))throw Error(`Speech recognition failed`);let n=t.result;if(n!==void 0&&(!n||typeof n!=`object`||Array.isArray(n)))throw Error(`Invalid speech transcript`);if(n&&typeof n==`object`&&`text`in n){if(typeof n.text!=`string`)throw Error(`Invalid speech transcript`);this.text=n.text,e.final||this.partial(this.text)}if(e.final){if(!this.finishing)throw Error(`Speech recognition ended unexpectedly`);this.final=!0;return}}}},N=(e,t,n)=>{let r=Error(e);return r.name=`DictationStreamError`,r.retryable=t,n&&(r.reasonCode=n),r},P=1e4,F=15e3,I=3e4,L=3e4,R=new class{socket=null;connectPromise=null;idleCloseTimer=null;pendingStarts=new Map;pendingFinishes=new Map;connectionListeners=new Set;partialListeners=new Set;activeDictations=0;directStarts=new Map;directSessions=new Map;get isConnected(){if(this.socket?.readyState===WebSocket.OPEN)return!0;for(let e of this.directSessions.values())if(e.connected)return!0;return!1}subscribeConnectionStatus(e){return this.connectionListeners.add(e),()=>{this.connectionListeners.delete(e)}}onPartial(e){return this.partialListeners.add(e),()=>{this.partialListeners.delete(e)}}async ensureConnected(){if(this.socket?.readyState!==WebSocket.OPEN){if(this.connectPromise){await this.connectPromise;return}try{await t()}catch{}this.connectPromise=new Promise((e,t)=>{let n=!1,i;try{let e=r().websocket(`/api/dictation/ws`);i=s(e)}catch(e){this.connectPromise=null,t(e instanceof Error?e:Error(String(e)));return}let a=setTimeout(()=>{if(!n){n=!0,this.connectPromise=null;try{i.close()}catch{}t(Error(`Dictation connection timed out`))}},P);i.onopen=()=>{},i.onmessage=t=>{let r;try{r=JSON.parse(String(t.data))}catch{return}if(!n&&r.type===`ready`){n=!0,clearTimeout(a),this.socket=i,this.connectPromise=null,this.notifyConnection(!0),e();return}this.handleMessage(r)},i.onerror=()=>{window.setTimeout(()=>{n||(n=!0,clearTimeout(a),this.connectPromise=null,t(Error(`Dictation connection failed`)))},250)},i.onclose=e=>{if(!n){n=!0,clearTimeout(a),this.connectPromise=null;let r=e?.reason?`: ${e.reason}`:``;t(Error(`Dictation connection failed${r}`));return}this.socket===i&&(this.socket=null,this.rejectAllPending(Error(`Dictation connection lost`)),this.notifyConnection(!1))}}),await this.connectPromise}}async startDictationStream(e,t){let n=new AbortController;this.directStarts.set(e,n);try{let r=await S(`asr`,n.signal);if(n.signal.throwIfAborted(),r){let i=new M(n,t=>{for(let n of this.partialListeners)n(e,t)},()=>{this.directSessions.delete(e),i.cancel(),this.notifyConnection(!1)});this.directSessions.set(e,i),await i.start(r,t),n.signal.throwIfAborted(),this.notifyConnection(!0);return}await this.ensureConnected(),n.signal.throwIfAborted()}catch(t){throw this.directSessions.get(e)?.cancel(),this.directSessions.delete(e),t}finally{this.directStarts.delete(e)}return this.activeDictations+=1,this.clearIdleCloseTimer(),new Promise((n,r)=>{let i=setTimeout(()=>{this.pendingStarts.delete(e),this.releaseDictation(),r(Error(`Dictation start timed out`))},F);this.pendingStarts.set(e,{resolve:()=>{clearTimeout(i),n()},reject:e=>{clearTimeout(i),this.releaseDictation(),r(e)},timeout:i}),this.send({type:`start`,dictationId:e,format:t})||(clearTimeout(i),this.pendingStarts.delete(e),this.releaseDictation(),r(Error(`Dictation connection lost`)))})}sendDictationStreamChunk(e,t,n){let r=this.directSessions.get(e);return r?r.send(t,n):this.send({type:`chunk`,dictationId:e,seq:t,audio:n})}finishDictationStream(e,t){let n=this.directSessions.get(e);return n?n.finish(t).finally(()=>{n.cancel(),this.directSessions.delete(e)}):new Promise((n,r)=>{let i={resolve:e=>{i.timeout&&clearTimeout(i.timeout),this.releaseDictation(),n(e)},reject:e=>{i.timeout&&clearTimeout(i.timeout),this.releaseDictation(),r(e)},timeout:null};i.timeout=setTimeout(()=>{this.pendingFinishes.delete(e),this.releaseDictation(),r(Error(`Timed out waiting for transcription`))},L),this.pendingFinishes.set(e,i),this.send({type:`finish`,dictationId:e,finalSeq:t})||(this.pendingFinishes.delete(e),i.reject(Error(`Dictation connection lost`)))})}cancelDictationStream(e){this.directStarts.get(e)?.abort(),this.directStarts.delete(e);let t=this.directSessions.get(e);if(t){t.cancel(),this.directSessions.delete(e);return}this.send({type:`cancel`,dictationId:e});let n=this.pendingStarts.get(e);n&&(this.pendingStarts.delete(e),n.reject(Error(`Dictation cancelled`)));let r=this.pendingFinishes.get(e);r&&(this.pendingFinishes.delete(e),r.reject(Error(`Dictation cancelled`))),this.releaseDictation(),this.scheduleIdleCloseIfReady()}handleMessage(e){let t=e.dictationId;if(t)switch(e.type){case`ack`:{let e=this.pendingStarts.get(t);e&&(this.pendingStarts.delete(t),e.resolve());return}case`partial`:for(let n of this.partialListeners)n(t,e.text??``);return;case`finish_accepted`:{let n=this.pendingFinishes.get(t);n&&typeof e.timeoutMs==`number`&&(n.timeout&&clearTimeout(n.timeout),n.timeout=setTimeout(()=>{this.pendingFinishes.delete(t),n.reject(Error(`Timed out waiting for transcription`))},e.timeoutMs+5e3));return}case`final`:{let n=this.pendingFinishes.get(t);n&&(this.pendingFinishes.delete(t),n.resolve({text:e.text??``})),this.scheduleIdleCloseIfReady();return}case`error`:{let n=N(e.error||`Dictation failed`,e.retryable!==!1,e.reasonCode),r=this.pendingStarts.get(t);r&&(this.pendingStarts.delete(t),r.reject(n));let i=this.pendingFinishes.get(t);i&&(this.pendingFinishes.delete(t),i.reject(n)),this.scheduleIdleCloseIfReady();return}}}send(e){if(!this.isConnected||!this.socket)return!1;try{return this.socket.send(JSON.stringify(e)),!0}catch{return!1}}notifyConnection(e){for(let t of this.connectionListeners)t(e)}rejectAllPending(e){for(let[t,n]of this.pendingStarts)this.pendingStarts.delete(t),n.reject(e);for(let[t,n]of this.pendingFinishes)this.pendingFinishes.delete(t),n.reject(e);this.activeDictations=0}releaseDictation(){this.activeDictations=Math.max(0,this.activeDictations-1),this.scheduleIdleCloseIfReady()}scheduleIdleCloseIfReady(){this.activeDictations>0||this.pendingFinishes.size>0||this.pendingStarts.size>0||(this.clearIdleCloseTimer(),this.idleCloseTimer=setTimeout(()=>{if(this.activeDictations===0&&this.pendingFinishes.size===0&&this.pendingStarts.size===0){let e=this.socket;if(this.socket=null,e){try{e.close(1e3,`idle`)}catch{}this.notifyConnection(!1)}}},I))}cancelAllForRuntimeSwitch(){for(let e of this.directStarts.values())e.abort();this.directStarts.clear();for(let e of this.directSessions.values())e.cancel();this.directSessions.clear(),this.clearIdleCloseTimer();let e=this.socket;if(this.socket=null,this.connectPromise=null,this.rejectAllPending(Error(`Runtime changed`)),e){try{e.close(1e3,`runtime switch`)}catch{}this.notifyConnection(!1)}}clearIdleCloseTimer(){this.idleCloseTimer&&=(clearTimeout(this.idleCloseTimer),null)}};typeof window<`u`&&window.addEventListener(`yuri:runtime-endpoint-changed`,()=>{R.cancelAllForRuntimeSwitch()});var z=128,B=`audio/pcm;rate=16000;bits=16`,V=()=>new Promise(e=>setTimeout(e,0)),H=()=>{let e=Math.random().toString(36).slice(2,10);return`dic_${Date.now().toString(16)}${e}`},ee=class{client;format;createDictationId;dictationId=null;sendSeq=0;segments=[];streamReady=!1;flushTimer=null;drainWaiters=[];startGeneration=0;startPromise=null;constructor(e){this.client=e.client,this.format=e.format??B,this.createDictationId=e.createDictationId??H}getDictationId(){return this.dictationId}getFinalSeq(){return this.segments.length-1}hasSegments(){return this.segments.length>0}clearAll(){this.dictationId&&this.client.cancelDictationStream(this.dictationId),this.clearScheduledFlush(),this.dictationId=null,this.sendSeq=0,this.segments=[],this.streamReady=!1,this.startPromise=null,this.startGeneration+=1}resetStreamForReplay(){this.dictationId&&this.client.cancelDictationStream(this.dictationId),this.clearScheduledFlush(),this.dictationId=null,this.sendSeq=0,this.streamReady=!1,this.startPromise=null,this.startGeneration+=1}enqueueSegment(e){if(this.segments.push(e),this.client.isConnected){if(!this.dictationId){this.startPromise||this.restartStream().catch(()=>{});return}this.flush()}}flush(){let e=this.dictationId;if(!this.client.isConnected||!e||!this.streamReady)return 0;let t=0;for(;this.sendSeq<this.segments.length&&t<z;){let n=this.sendSeq,r=this.segments[n];if(!this.client.sendDictationStreamChunk(e,n,r))break;this.sendSeq=n+1,t+=1}return this.hasPendingSegments()?this.scheduleFlush():this.resolveDrainWaiters(),t}async restartStream(){this.startGeneration+=1;let e=this.startGeneration,t=this.createDictationId();this.dictationId=t,this.sendSeq=0,this.streamReady=!1;let n=(async()=>{await this.client.startDictationStream(t,this.format),this.startGeneration===e&&this.dictationId===t&&(this.streamReady=!0,this.flush())})().catch(n=>{throw this.startGeneration===e&&this.dictationId===t&&(this.dictationId=null,this.streamReady=!1),n}).finally(()=>{this.startPromise===n&&(this.startPromise=null)});this.startPromise=n,await n}async finish(e){this.dictationId||await this.restartStream(),this.startPromise&&await this.startPromise;let t=this.dictationId;if(!t||!this.streamReady)throw Error(`Failed to start dictation stream`);return this.flush(),await this.waitForFlushDrain(),{dictationId:t,text:(await this.client.finishDictationStream(t,e)).text}}cancel(){this.resetStreamForReplay()}hasPendingSegments(){return this.sendSeq<this.segments.length}scheduleFlush(){this.flushTimer||=setTimeout(()=>{this.flushTimer=null,this.flush()},0)}clearScheduledFlush(){this.resolveDrainWaiters(),this.flushTimer&&=(clearTimeout(this.flushTimer),null)}async waitForFlushDrain(){for(;this.hasPendingSegments();){if(!this.client.isConnected||!this.dictationId||!this.streamReady)throw Error(`Failed to flush dictation stream`);await new Promise(e=>{this.drainWaiters.push(e)}),await V()}}resolveDrainWaiters(){let e=this.drainWaiters;this.drainWaiters=[];for(let t of e)t()}},U=c(),W=new Set;function G(e){return W.add(e),()=>{W.delete(e)}}function K(){for(let e of W)e();if(typeof window<`u`&&window.speechSynthesis?.cancel(),typeof navigator>`u`)return;let e=navigator.audioSession;if(e)try{e.type=`play-and-record`}catch{}}function te(){if(typeof navigator>`u`)return;let e=navigator.audioSession;if(e)try{e.type!==`playback`&&(e.type=`playback`)}catch{}}var q=16e3,J=q/5,Y=()=>{if(typeof window>`u`)return null;let e=window;return e.AudioContext||e.webkitAudioContext||null},X=e=>{let t=Math.max(-1,Math.min(1,e));return Math.round(t<0?t*32768:t*32767)},ne=(e,t,n)=>{if(e.length===0)return new Int16Array;if(t===n){let t=new Int16Array(e.length);for(let n=0;n<e.length;n++)t[n]=X(e[n]);return t}let r=t/n,i=Math.max(1,Math.round(e.length/r)),a=new Int16Array(i);for(let t=0;t<i;t++){let n=t*r,i=Math.floor(n),o=Math.min(e.length-1,i+1),s=n-i;a[t]=X(e[i]*(1-s)+e[o]*s)}return a},re=(e,t)=>{if(e.length===0)return t;if(t.length===0)return e;let n=new Int16Array(e.length+t.length);return n.set(e,0),n.set(t,e.length),n},Z=e=>{let t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),n=``;for(let e=0;e<t.length;e++)n+=String.fromCharCode(t[e]);return btoa(n)},Q=()=>({stream:null,context:null,source:null,processor:null,gain:null,pending:new Int16Array,started:!1}),$=e=>{if(e)try{e.disconnect()}catch{}},ie=()=>typeof navigator>`u`||typeof window>`u`||!navigator.mediaDevices||typeof navigator.mediaDevices.getUserMedia!=`function`?!1:Y()!==null;function ae(e){let t=(0,U.c)(16),[n,r]=(0,x.useState)(0),i=(0,x.useRef)(e.onPcmSegment),a=(0,x.useRef)(e.onError),o,s;t[0]!==e.onError||t[1]!==e.onPcmSegment?(o=()=>{i.current=e.onPcmSegment,a.current=e.onError},s=[e.onPcmSegment,e.onError],t[0]=e.onError,t[1]=e.onPcmSegment,t[2]=o,t[3]=s):(o=t[2],s=t[3]),(0,x.useEffect)(o,s);let c;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(c=Q(),t[4]=c):c=t[4];let u=(0,x.useRef)(c),d=(0,x.useRef)(0),f;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(f=async()=>{if(u.current.started)return;if(typeof navigator>`u`||!navigator.mediaDevices||typeof navigator.mediaDevices.getUserMedia!=`function`)throw Error(`Microphone capture is not supported in this environment`);let e=Y();if(!e)throw Error(`AudioContext unavailable`);let t=d.current+=1;K();let n=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,noiseSuppression:!0,echoCancellation:!0,autoGainControl:!0}});if(t!==d.current){n.getTracks().forEach(ue);return}let a=new e;try{if(a.state===`suspended`&&await a.resume().catch(le),t!==d.current){n.getTracks().forEach(ce),await a.close();return}let e=a.createMediaStreamSource(n),o=a.createScriptProcessor(4096,1,1),s=a.createGain();s.gain.value=0,u.current={stream:n,context:a,source:e,processor:o,gain:s,pending:new Int16Array,started:!0},o.onaudioprocess=e=>{let t=u.current;if(!t.started)return;let n=e.inputBuffer.getChannelData(0),o=0;for(let e=0;e<n.length;e++)o+=n[e]*n[e];let s=Math.sqrt(o/Math.max(1,n.length));r(Math.min(1,Math.max(0,s*2)));let c=ne(n,a.sampleRate,q);for(t.pending=re(t.pending,c);t.pending.length>=J;){let e=t.pending.slice(0,J);t.pending=t.pending.slice(J),i.current(Z(e))}},e.connect(o),o.connect(s),s.connect(a.destination)}catch(e){let t=e;n.getTracks().forEach(se);try{await a.close()}catch{}throw u.current=Q(),t instanceof Error?t:Error(String(t))}},t[5]=f):f=t[5];let p=l(f),m;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(m=async()=>{d.current+=1;let e=u.current;if(e.started=!1,r(0),e.processor)try{e.processor.onaudioprocess=null}catch{}$(e.processor),$(e.source),$(e.gain),e.stream&&e.stream.getTracks().forEach(oe);let t=e.pending;if(e.pending=new Int16Array,t.length>0&&i.current(Z(t)),e.context)try{await e.context.close()}catch{}u.current===e&&(u.current=Q())},t[6]=m):m=t[6];let h=l(m),g,_;t[7]===h?(g=t[8],_=t[9]):(g=()=>()=>{h().catch(e=>{a.current?.(e instanceof Error?e:Error(String(e)))})},_=[h],t[7]=h,t[8]=g,t[9]=_),(0,x.useEffect)(g,_);let v;t[10]===p?v=t[11]:(v=async()=>{try{await p()}catch(e){let t=e,n=t instanceof Error?t:Error(String(t));throw a.current?.(n),n}},t[10]=p,t[11]=v);let y;return t[12]!==h||t[13]!==v||t[14]!==n?(y={start:v,stop:h,volume:n},t[12]=h,t[13]=v,t[14]=n,t[15]=y):y=t[15],y}function oe(e){try{e.stop()}catch{}}function se(e){try{e.stop()}catch{}}function ce(e){return e.stop()}function le(){}function ue(e){return e.stop()}var de=1e3,fe=e=>e instanceof Error?e:Error(String(e));function pe(e={}){let{t}=u(),{onTranscript:r,onError:i,canStart:a}=e,[o,s]=(0,x.useState)(`idle`),[c,d]=(0,x.useState)(!1),[f,p]=(0,x.useState)(``),[m,h]=(0,x.useState)(0),[g,_]=(0,x.useState)(null),[v,y]=(0,x.useState)(null),b=(0,x.useRef)(o);(0,x.useEffect)(()=>{b.current=o},[o]);let S=(0,x.useRef)(``),C=(0,x.useRef)(null),w=(0,x.useRef)({starting:!1,confirming:!1,cancelling:!1}),T=(0,x.useRef)(0),E=(0,x.useRef)(r),D=(0,x.useRef)(i);(0,x.useEffect)(()=>{E.current=r,D.current=i},[r,i]);let O=(0,x.useRef)(null);O.current||=new ee({client:R});let k=l(()=>{C.current&&=(clearInterval(C.current),null)}),A=l(()=>{C.current||=setInterval(()=>{h(e=>e+1)},de)}),j=l(e=>{let n=fe(e),r=n.name===`NotFoundError`||n.name===`DevicesNotFoundError`?Error(t(`chat.dictation.error.microphoneNotFound`),{cause:n}):n;_(r.message);let i=n.reasonCode;y(typeof i==`string`?i:null),D.current?.(r)}),M=l(()=>{_(null),y(null)}),N=l(()=>{O.current?.clearAll(),S.current=``,p(``)}),P=l(t=>e.onPartialTranscript?.(t));(0,x.useEffect)(()=>R.onPartial((e,t)=>{let n=O.current?.getDictationId();!n||e!==n||(S.current=t,p(t),P(t))}),[P]),(0,x.useEffect)(()=>R.subscribeConnectionStatus(e=>{if(!e){b.current===`recording`&&O.current?.resetStreamForReplay();return}if(b.current!==`recording`||O.current?.getDictationId())return;let t=T.current;O.current?.restartStream().catch(e=>{T.current===t&&j(e)})}),[j]);let F=ae({onPcmSegment:e=>{b.current===`recording`&&O.current?.enqueueSegment(e)},onError:e=>{D.current?.(e)}}),I=(0,x.useRef)(F.stop);(0,x.useEffect)(()=>{I.current=F.stop},[F.stop]);let L=l(e=>{h(0),s(`idle`),b.current=`idle`;let t=e.trim();return N(),t?(E.current?.(t),t):null}),z=l(e=>{O.current?.hasSegments()?(s(`failed`),b.current=`failed`):(s(`idle`),b.current=`idle`),j(e)}),B=l(async()=>{let e=w.current;if(e.starting||e.confirming||e.cancelling||b.current!==`idle`||a&&!a())return;e.starting=!0,d(!0);let t=++T.current;M(),p(``),h(0),s(`recording`),b.current=`recording`,N();try{if(await F.start(),T.current!==t||b.current!==`recording`)return;d(!1),A(),await O.current?.restartStream().catch(e=>{T.current===t&&j(e)})}catch(e){if(T.current!==t)return;await F.stop().catch(()=>void 0),k(),s(`idle`),b.current=`idle`,j(e)}finally{T.current===t&&d(!1),e.starting=!1}}),V=l(async()=>{let e=w.current;if(!e.cancelling&&(b.current===`recording`||b.current===`uploading`)){e.cancelling=!0,d(!1),T.current+=1,k(),h(0),M(),s(`idle`),b.current=`idle`;try{O.current?.cancel()}catch{}N();try{await F.stop()}catch{}finally{e.cancelling=!1}}}),H=l(async()=>{let e=w.current;if(e.confirming||b.current!==`recording`)return null;e.confirming=!0,d(!1);let t=++T.current;M(),k();try{if(await F.stop(),T.current!==t)return null;s(`uploading`),b.current=`uploading`;let e=O.current?.getFinalSeq()??-1;if(e<0)return O.current?.cancel(),L(``);let n=await O.current.finish(e);return T.current===t?L(n.text):null}catch(e){return T.current===t&&z(e),null}finally{e.confirming=!1}}),U=l(async()=>{if(b.current!==`failed`||!O.current?.hasSegments())return null;M();let e=++T.current;s(`uploading`),b.current=`uploading`;try{O.current.resetStreamForReplay();let t=O.current.getFinalSeq(),n=await O.current.finish(t);return T.current===e?L(n.text):null}catch(t){return T.current===e&&z(t),null}}),W=l(()=>{if(b.current!==`failed`)return null;let e=S.current.trim();h(0),s(`idle`),b.current=`idle`,M();try{O.current?.cancel()}catch{}return N(),e?(E.current?.(e),e):null}),G=l(()=>{h(0),s(`idle`),b.current=`idle`,M(),N()});return(0,x.useEffect)(()=>n(()=>{b.current===`failed`?(T.current+=1,G()):V()}),[V,G]),(0,x.useEffect)(()=>{if(o!==`recording`||v!==`model_download_in_progress`)return;let e=setInterval(()=>{b.current!==`recording`||O.current?.getDictationId()||O.current?.restartStream().then(()=>{M()}).catch(e=>{j(e)})},3e3);return()=>clearInterval(e)},[o,v,M,j]),(0,x.useEffect)(()=>()=>{T.current+=1,k(),I.current().catch(()=>void 0),O.current?.cancel()},[k]),{status:o,isRecording:o===`recording`,isStarting:c,isProcessing:o===`uploading`,partialTranscript:f,volume:F.volume,duration:m,error:g,errorReason:v,startDictation:B,confirmDictation:H,cancelDictation:V,retryFailedDictation:U,acceptPartialTranscript:W,discardFailedDictation:G}}var me=`app-region-no-drag transition-[opacity,transform] duration-150 ease-out data-[starting-style]:opacity-0 data-[starting-style]:scale-95 data-[ending-style]:opacity-0 data-[ending-style]:scale-95 z-50 max-h-[var(--available-height)] min-w-[8rem] origin-[var(--transform-origin)] overflow-visible rounded-xl p-1 shadow-[inset_0_1px_0_0_rgba(255,255,255,0.8),inset_0_0_0_1px_rgba(0,0,0,0.04),0_0_0_1px_rgba(0,0,0,0.10),0_1px_2px_-0.5px_rgba(0,0,0,0.08),0_4px_8px_-2px_rgba(0,0,0,0.08),0_12px_20px_-4px_rgba(0,0,0,0.08)] dark:shadow-[inset_0_1px_0_0_rgba(255,255,255,0.12),inset_0_0_0_1px_rgba(255,255,255,0.08),0_0_0_1px_rgba(0,0,0,0.36),0_1px_1px_-0.5px_rgba(0,0,0,0.22),0_3px_3px_-1.5px_rgba(0,0,0,0.20),0_6px_6px_-3px_rgba(0,0,0,0.16)]`,he=`data-[highlighted]:bg-interactive-hover hover:bg-interactive-hover active:bg-interactive-active data-[variant=destructive]:text-destructive data-[variant=destructive]:hover:bg-destructive/10 dark:data-[variant=destructive]:hover:bg-destructive/20 data-[variant=destructive]:hover:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1 typography-ui-label outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-3.5`,ge=`data-[highlighted]:bg-interactive-hover hover:bg-interactive-hover active:bg-interactive-active [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1 typography-ui-label outline-hidden select-none data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-3.5`,_e=`bg-border -mx-1 my-0.5 h-px`;export{m as S,f as _,pe as a,_ as b,te as c,j as d,A as f,d as g,C as h,ge as i,G as l,S as m,me as n,ie as o,O as p,_e as r,K as s,he as t,k as u,p as v,y as x,b as y};
@@ -1,2 +1,2 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{st as t}from"./persistence-Dzooc9Xg.js";import{it as n,nt as r,rt as i}from"./vendor-base-ui-CdzJ6My_.js";import{n as a}from"./vendor-react-BP2cRVqX.js";import{r as o}from"./button-_ReBqWzC.js";import{st as s}from"./useMobileNavigationStore-DcG6Ukmu.js";import{r as c,t as l}from"./Icon-2cKLcXGe.js";import{t as u}from"./vendor-fuzzysort-ukaRp9PC.js";var d=e=>{switch(e.name){case`new`:return`add`;case`init`:return`file`;case`undo`:return`arrow-go-back`;case`redo`:return`arrow-go-forward`;case`timeline`:return`time`;case`compact`:return`scissors`;case`reload`:return`refresh`;case`goal`:return`target`;case`review`:return`search-eye`;case`test`:case`build`:case`run`:return`terminal-box`;default:return e.isBuiltIn?`flashlight`:`command`}},f=()=>`book-open`,p=e=>{if(e.isDirectory)return`folder-3-fill`;switch(e.extension?.toLowerCase()){case`ts`:case`tsx`:case`js`:case`jsx`:case`json`:return`code`;case`md`:case`mdx`:return`file`;case`png`:case`jpg`:case`jpeg`:case`gif`:case`svg`:return`file-image`;default:return`file-pdf`}},m=()=>`ai-agent`,h=()=>`chat-thread`,g=32,_=(e,t)=>{let n=c[e];return typeof n!=`string`||n.length===0?null:`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="${t}" stroke-width="${l}" stroke-linecap="round" stroke-linejoin="round">${n}</svg>`},v=(e,t)=>{let n=_(e,t);return!n||typeof document>`u`?Promise.resolve(null):new Promise(e=>{let t=new Image;t.decoding=`async`,t.onload=()=>{try{let n=document.createElement(`canvas`);n.width=g,n.height=g;let r=n.getContext(`2d`);if(!r){e(null);return}r.clearRect(0,0,g,g),r.drawImage(t,0,0,g,g);let i=n.toDataURL(`image/png`),a=i.indexOf(`,`);e(a>=0?i.slice(a+1):null)}catch{e(null)}},t.onerror=()=>e(null),t.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(n)}`})},y=e(u(),1),b=(e,t)=>e.map(e=>{let n=e.isSkill?t.skill:e.isYuri?`Yuri`:e.isBuiltIn?t.system:e.scope||e.agent||t.command;return{id:e.id,title:`/${e.name}`,subtitle:e.description,badge:n,iconName:d(e)}}),x=({skills:e=[],agents:t,sessions:n,recentFiles:r,pathHits:i,untitledSession:a,sessionBadge:o,skillBadge:s,searchQuery:c=``})=>{let l=[];for(let t of e)l.push({id:`skill:${t.name}-${t.scope}`,title:`@${t.name}`,subtitle:t.description,badge:s??t.scope,iconName:f()});for(let e of t)l.push({id:`agent:${e.name}`,title:`@${e.name}`,subtitle:e.description,iconName:m(),agentName:e.name});let u=c.trim(),d=u?y.default.go(u,l,{keys:[`title`,e=>e.id.startsWith(`skill:`)?e.subtitle??``:``],threshold:.5,limit:10,scoreFn:e=>{let t=e[0],n=(t?.score??0)*(t?.target.startsWith(`@${u}`)?2:1);return n>=.5?1+n:e[1]?.score??0}}).map(e=>e.obj):l.slice();l.length=0;for(let e of r)l.push({id:`recent:${e.path}`,title:e.relativePath||e.name,iconName:p(e)});for(let e of i)l.push({id:`file:${e.path}`,title:e.relativePath||e.name,iconName:p(e)});for(let e of n)l.push({id:`session:${e.id}`,title:e.title||a,badge:o,iconName:h()});return u?[...d,...l].slice(0,10):[...d,...l]},S=(e,n)=>{if(!e.includes(`/`)||n.size===0)return[];let r=RegExp(`(^|\\s)/(${t})?([A-Za-z0-9][A-Za-z0-9_-]*)(?=$|\\s)`,`g`),i=[],a;for(;(a=r.exec(e))!==null;){let e=a[3]??``;if(!n.has(e.toLowerCase()))continue;let t=a[2]??``,r=a.index+(a[1]?.length??0);i.push({start:r,end:r+1+t.length+e.length,name:e,hasSlot:t.length>0})}return i},C=(e,n,r=e.length)=>{let i=S(e,n).filter(e=>!e.hasSlot);if(i.length===0)return null;let a=e,o=r;for(let e=i.length-1;e>=0;--e){let n=i[e].start+1;a=`${a.slice(0,n)}${t}${a.slice(n)}`,o>n&&(o+=t.length)}return a===e?null:{text:a,caret:o}},w=e=>e.startsWith(t)?e.slice(t.length):e,T=e=>{if(e.inputMode===`shell`)return null;let t=e.text,n=Math.max(0,Math.min(e.cursor,t.length));if(t.startsWith(`/`)){let e=t.indexOf(` `),r=t.indexOf(`
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{st as t}from"./persistence-Dzooc9Xg.js";import{it as n,nt as r,rt as i}from"./vendor-base-ui-CdzJ6My_.js";import{n as a}from"./vendor-react-BP2cRVqX.js";import{r as o}from"./button-D_HdP1Oy.js";import{st as s}from"./useMobileNavigationStore-BURkCJuM.js";import{r as c,t as l}from"./Icon-BXTZRnIO.js";import{t as u}from"./vendor-fuzzysort-ukaRp9PC.js";var d=e=>{switch(e.name){case`new`:return`add`;case`init`:return`file`;case`undo`:return`arrow-go-back`;case`redo`:return`arrow-go-forward`;case`timeline`:return`time`;case`compact`:return`scissors`;case`reload`:return`refresh`;case`goal`:return`target`;case`review`:return`search-eye`;case`test`:case`build`:case`run`:return`terminal-box`;default:return e.isBuiltIn?`flashlight`:`command`}},f=()=>`book-open`,p=e=>{if(e.isDirectory)return`folder-3-fill`;switch(e.extension?.toLowerCase()){case`ts`:case`tsx`:case`js`:case`jsx`:case`json`:return`code`;case`md`:case`mdx`:return`file`;case`png`:case`jpg`:case`jpeg`:case`gif`:case`svg`:return`file-image`;default:return`file-pdf`}},m=()=>`ai-agent`,h=()=>`chat-thread`,g=32,_=(e,t)=>{let n=c[e];return typeof n!=`string`||n.length===0?null:`<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="${t}" stroke-width="${l}" stroke-linecap="round" stroke-linejoin="round">${n}</svg>`},v=(e,t)=>{let n=_(e,t);return!n||typeof document>`u`?Promise.resolve(null):new Promise(e=>{let t=new Image;t.decoding=`async`,t.onload=()=>{try{let n=document.createElement(`canvas`);n.width=g,n.height=g;let r=n.getContext(`2d`);if(!r){e(null);return}r.clearRect(0,0,g,g),r.drawImage(t,0,0,g,g);let i=n.toDataURL(`image/png`),a=i.indexOf(`,`);e(a>=0?i.slice(a+1):null)}catch{e(null)}},t.onerror=()=>e(null),t.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(n)}`})},y=e(u(),1),b=(e,t)=>e.map(e=>{let n=e.isSkill?t.skill:e.isYuri?`Yuri`:e.isBuiltIn?t.system:e.scope||e.agent||t.command;return{id:e.id,title:`/${e.name}`,subtitle:e.description,badge:n,iconName:d(e)}}),x=({skills:e=[],agents:t,sessions:n,recentFiles:r,pathHits:i,untitledSession:a,sessionBadge:o,skillBadge:s,searchQuery:c=``})=>{let l=[];for(let t of e)l.push({id:`skill:${t.name}-${t.scope}`,title:`@${t.name}`,subtitle:t.description,badge:s??t.scope,iconName:f()});for(let e of t)l.push({id:`agent:${e.name}`,title:`@${e.name}`,subtitle:e.description,iconName:m(),agentName:e.name});let u=c.trim(),d=u?y.default.go(u,l,{keys:[`title`,e=>e.id.startsWith(`skill:`)?e.subtitle??``:``],threshold:.5,limit:10,scoreFn:e=>{let t=e[0],n=(t?.score??0)*(t?.target.startsWith(`@${u}`)?2:1);return n>=.5?1+n:e[1]?.score??0}}).map(e=>e.obj):l.slice();l.length=0;for(let e of r)l.push({id:`recent:${e.path}`,title:e.relativePath||e.name,iconName:p(e)});for(let e of i)l.push({id:`file:${e.path}`,title:e.relativePath||e.name,iconName:p(e)});for(let e of n)l.push({id:`session:${e.id}`,title:e.title||a,badge:o,iconName:h()});return u?[...d,...l].slice(0,10):[...d,...l]},S=(e,n)=>{if(!e.includes(`/`)||n.size===0)return[];let r=RegExp(`(^|\\s)/(${t})?([A-Za-z0-9][A-Za-z0-9_-]*)(?=$|\\s)`,`g`),i=[],a;for(;(a=r.exec(e))!==null;){let e=a[3]??``;if(!n.has(e.toLowerCase()))continue;let t=a[2]??``,r=a.index+(a[1]?.length??0);i.push({start:r,end:r+1+t.length+e.length,name:e,hasSlot:t.length>0})}return i},C=(e,n,r=e.length)=>{let i=S(e,n).filter(e=>!e.hasSlot);if(i.length===0)return null;let a=e,o=r;for(let e=i.length-1;e>=0;--e){let n=i[e].start+1;a=`${a.slice(0,n)}${t}${a.slice(n)}`,o>n&&(o+=t.length)}return a===e?null:{text:a,caret:o}},w=e=>e.startsWith(t)?e.slice(t.length):e,T=e=>{if(e.inputMode===`shell`)return null;let t=e.text,n=Math.max(0,Math.min(e.cursor,t.length));if(t.startsWith(`/`)){let e=t.indexOf(` `),r=t.indexOf(`
2
2
  `),i=Math.min(e===-1?t.length:e,r===-1?t.length:r);if(n<=i&&e===-1)return{kind:`slash-command`,query:w(t.substring(1,i)),tokenStart:0,tokenEnd:i}}let r=t.substring(0,n),i=s({value:t,cursorPosition:n,inputSource:e.mentionInputSource??`manual`,insertedText:e.insertedText});return i===null?null:{kind:`mention`,query:i,tokenStart:r.lastIndexOf(`@`),tokenEnd:n}},E=e=>e===`mention`?`@`:`/`,D=(e,t,n)=>{if(n&&n.tokenStart>=0&&n.tokenEnd>=n.tokenStart&&n.tokenEnd<=e.length&&e.startsWith(E(n.kind),n.tokenStart))return{start:n.tokenStart,end:n.tokenEnd};let r=T({text:e,cursor:t});return r?{start:r.tokenStart,end:r.tokenEnd}:null},O=e(n(),1),k=a(),A=e(r(),1),j=`absolute z-[100] min-w-0 w-full bottom-full mb-2 left-0 flex flex-col rounded-xl`,M=`pointer-events-auto absolute z-[100] min-w-0 flex flex-col rounded-xl`;function N(e,t){return o(e?M:j,`yuri-mobile-overlay-surface yuri-mobile-overlay-surface--translucent yuri-composer-autocomplete-surface`,t)}function P(e,t){return e?`yuri-composer-autocomplete-row`:o(`mx-1.5 hover:bg-[color-mix(in_srgb,var(--interactive-selection)_40%,transparent)]`,t&&`bg-[color-mix(in_srgb,var(--interactive-selection)_40%,transparent)]`)}var F=.4,I=e=>{let t=e.gap??8,n=Math.min(e.composerTop-t,e.visibleBottom-t);return{left:e.composerLeft,width:e.composerWidth,bottom:Math.max(0,e.fixedContainingBottom-n),maxHeight:L({popupBottom:n,boundaryTop:e.boundaryTop,viewportHeight:e.viewportHeight,gap:t})}},L=e=>{let t=e.gap??8,n=Math.max(0,e.popupBottom-e.boundaryTop-t),r=e.viewportHeight*F,i=Math.floor(Math.min(n,r));return n>=120?Math.min(n,Math.max(120,i)):i},R=(e,t=0)=>{let n=e.closest(`main`);if(!n)return null;let r=(e.closest(`.mobile-chat-screen__content`)?.parentElement??n.parentElement?.closest(`main`)??n).querySelector(`:scope > .yuri-mobile-detail-navigation`)?.getBoundingClientRect().bottom,i=n.getBoundingClientRect().top;return Math.max(r===void 0?i:Math.max(r,i),t)},z=(e,t)=>{let n=(0,k.c)(5),[r,i]=O.useState(void 0),a;n[0]!==t||n[1]!==e?(a=()=>{if(!t){i(void 0);return}let n=0,r=0,a=()=>{let t=e.current?.parentElement;if(!t)return;let n=t.getBoundingClientRect(),r=window.visualViewport,a=r?.offsetTop??0,o=r?.height??window.innerHeight,s=window.innerHeight,c=a+o,l=R(t,a)??a,u=I({composerTop:n.top,composerLeft:n.left,composerWidth:n.width,fixedContainingBottom:s,visibleBottom:c,boundaryTop:l,viewportHeight:o});i(e=>e&&e.left===u.left&&e.width===u.width&&e.bottom===u.bottom&&e.maxHeight===u.maxHeight?e:u)},o=()=>{a(),n&&window.cancelAnimationFrame(n),r&&window.clearTimeout(r),n=window.requestAnimationFrame(()=>{a(),r=window.setTimeout(a,220)})};return a(),window.addEventListener(`resize`,a),window.addEventListener(`yuri:keyboard-settled`,o),window.addEventListener(`yuri:keyboard-anim`,o),window.visualViewport?.addEventListener(`resize`,a),window.visualViewport?.addEventListener(`scroll`,a),()=>{n&&window.cancelAnimationFrame(n),r&&window.clearTimeout(r),window.removeEventListener(`resize`,a),window.removeEventListener(`yuri:keyboard-settled`,o),window.removeEventListener(`yuri:keyboard-anim`,o),window.visualViewport?.removeEventListener(`resize`,a),window.visualViewport?.removeEventListener(`scroll`,a)}},n[0]=t,n[1]=e,n[2]=a):a=n[2];let o;return n[3]===t?o=n[4]:(o=[t],n[3]=t,n[4]=o),O.useLayoutEffect(a,o),t?r:void 0},B=i(),V=O.forwardRef((e,t)=>{let n=(0,k.c)(24),{isMobile:r,className:i,style:a,children:o}=e,s=O.useRef(null),c=z(s,r),l=typeof document<`u`?document.body:null;if(!r){let e;n[0]===i?e=n[1]:(e=N(!1,i),n[0]=i,n[1]=e);let r;return n[2]!==o||n[3]!==t||n[4]!==a||n[5]!==e?(r=(0,B.jsx)(`div`,{ref:t,className:e,style:a,children:o}),n[2]=o,n[3]=t,n[4]=a,n[5]=e,n[6]=r):r=n[6],r}let u;n[7]===i?u=n[8]:(u=N(!0,i),n[7]=i,n[8]=u);let d;n[9]===c?d=n[10]:(d=c?{left:c.left,width:c.width,bottom:c.bottom,maxHeight:c.maxHeight,overflow:`hidden`}:{visibility:`hidden`},n[9]=c,n[10]=d);let f;n[11]!==a||n[12]!==d?(f={...a,...d},n[11]=a,n[12]=d,n[13]=f):f=n[13];let p;n[14]!==o||n[15]!==t||n[16]!==u||n[17]!==f?(p=(0,B.jsx)(`div`,{className:`pointer-events-none fixed inset-0 z-[100]`,children:(0,B.jsx)(`div`,{ref:t,className:u,style:f,children:o})}),n[14]=o,n[15]=t,n[16]=u,n[17]=f,n[18]=p):p=n[18];let m=p,h;n[19]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,B.jsx)(`span`,{ref:s,className:`hidden`,"aria-hidden":!0}),n[19]=h):h=n[19];let g;n[20]===m?g=n[21]:(g=l?(0,A.createPortal)(m,l):m,n[20]=m,n[21]=g);let _;return n[22]===g?_=n[23]:(_=(0,B.jsxs)(B.Fragment,{children:[h,g]}),n[22]=g,n[23]=_),_});V.displayName=`ComposerAutocompleteLayer`;var H=()=>{let e=null,t=!1,n=!1;return{pointerDown:(n,r)=>{e={x:n,y:r},t=!1},pointerMove:(n,r)=>{e&&Math.hypot(n-e.x,r-e.y)>6&&(t=!0)},pointerCancel:()=>{e=null,t=!1},pointerUp:r=>{if(!e)return!1;let i=!t;return e=null,t=!1,i?(n=!0,r(),!0):(n=!0,!1)},click:e=>n?(n=!1,!1):(e(),!0)}};export{T as a,x as c,d,D as i,b as l,V as n,C as o,P as r,w as s,H as t,v as u};
@@ -1,4 +1,4 @@
1
- import{n as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,n}from"./runtime-switch-CAZiOV2G.js";import{s as r,u as i}from"./queryRuntime-DKGLQtb9.js";import{$ as a,A as o,C as s,F as c,G as l,J as u,K as d,L as f,M as p,N as m,Nt as ee,O as te,Q as ne,R as re,S as ie,T as ae,X as oe,Y as h,Z as se,_ as ce,at as le,b as ue,c as de,d as fe,gt as pe,h as me,ht as he,it as ge,lt as _e,m as ve,nt as ye,o as be,pt as xe,rt as Se,u as Ce,ut as we,v as Te,vt as Ee,w as De,x as Oe,xt as ke,yt as Ae,z as je}from"./platform-7bX6qtBV.js";import{d as g,ga as _,l as Me,wa as v}from"./useMobileNavigationStore-DcG6Ukmu.js";var Ne=e({COMMIT_DIFF_FILE_LIMIT:()=>30,COMMIT_DIFF_TOTAL_CHAR_LIMIT:()=>j,SESSION_GENERATE_TIMEOUT_MS:()=>M,applyGitStash:()=>K,checkIsGitRepository:()=>x,checkoutCommit:()=>$e,cherryPick:()=>et,collectSelectedFileDiffs:()=>N,countGitStashFiles:()=>W,createBranch:()=>Y,createGitIdentity:()=>Q,createGitWorktree:()=>B,deleteGitIdentity:()=>Je,deleteGitWorktree:()=>V,deleteRemoteBranch:()=>A,discoverGitCredentials:()=>Ye,discoverGitRepositories:()=>S,dropGitStash:()=>J,generateCommitMessage:()=>F,getCommitFileDiff:()=>X,getConflictDetails:()=>$,getGitBranches:()=>k,getGitIdentities:()=>Z,getGitStatus:()=>C,getGitWorktreeBootstrapStatus:()=>R,getGlobalGitIdentity:()=>Xe,git:()=>H,listGitStashes:()=>U,listGitWorktrees:()=>I,merge:()=>Qe,popGitStash:()=>q,previewGitWorktree:()=>z,rebase:()=>Ze,resetToCommit:()=>nt,resolveGitPrimaryRoot:()=>w,resolveGitTopLevel:()=>T,revertCommit:()=>tt,stageGitFile:()=>E,stageGitFiles:()=>D,stashGitChanges:()=>G,unstageGitFile:()=>Pe,unstageGitFiles:()=>O,updateGitIdentity:()=>qe,validateGitWorktree:()=>L}),y=()=>r()?.git??null,b=e=>{let t=e.trim(),n=(t.match(/```(?:json)?\s*([\s\S]*?)```/i)?.[1]??t).trim(),r=[n.indexOf(`{`)].filter(e=>e>=0);for(let e of r)for(let t=n.length;t>e;--t)if(n[t-1]===`}`)try{let r=JSON.parse(n.slice(e,t));if(r&&typeof r==`object`&&!Array.isArray(r))return r}catch{}return null};async function x(e){let t=y();return t?t.checkIsGitRepository(e):de(e)}async function S(e){return De(e)}async function C(e,t){let n=y();return n?n.getGitStatus(e,t):f(e,t)}async function w(e){return(await Se(e)).root}async function T(e){return(await ge(e)).root}async function E(e,t){let n=y();return n?.stageGitFile?n.stageGitFile(e,t):_e(e,t)}async function D(e,t){let n=y();return n?.stageGitFiles?n.stageGitFiles(e,t):we(e,t)}async function Pe(e,t){let n=y();return n?.unstageGitFile?n.unstageGitFile(e,t):he(e,t)}async function O(e,t){let n=y();return n?.unstageGitFiles?n.unstageGitFiles(e,t):pe(e,t)}async function k(e,t){let n=y();if(t?.signal?.throwIfAborted(),n){let r=await n.getGitBranches(e,t);return t?.signal?.throwIfAborted(),r}return p(e,t)}async function A(e,t){let n=y();return n?n.deleteRemoteBranch(e,t):ie(e,t)}var j=12e4,M=9e4,Fe=[`This is an auxiliary structured generation request (git copy).`,`Use the active session context plus the materials below.`,`Answer with the required JSON only.`,`Do not call any tools and do not take any actions.`,`Model and instructions follow the session.generate session contract.`].join(` `),Ie=`Select an active session for generation. session.generate uses that session model contract and does not mutate chat history.`,Le=`No default provider or model configured. Please select a provider and model in settings first.`,Re=`Runtime changed during session.generate`,ze=`session.generate returned empty text`,Be=`session.generate returned invalid structured output`,Ve=e=>{let t=[`Diff budget: included ${e.includedFileCount} of ${e.selectedFileCount} selected files`,`fileLimit=${e.fileLimit}`,`charLimit=${e.charLimit}`,`truncatedByCharLimit=${e.truncatedByCharLimit?`yes`:`no`}`,`omittedFiles=${e.omittedFileCount}`],n=e.omittedFileCount>0||e.truncatedByCharLimit?` Materials are partial under this budget — do not invent diffs for omitted or truncated files; base the message only on provided material.`:` Materials cover the full selected set within the budget.`;return`${t.join(`; `)}.${n}`};async function N(e,t){let n=t.length,r=t.slice(0,30),i=await Promise.all(r.map(async t=>{try{let[n,r]=await Promise.all([m(e,{path:t,staged:!0}).catch(()=>null),m(e,{path:t,staged:!1}).catch(()=>null)]);return[n?.diff,r?.diff].filter(e=>typeof e==`string`&&e.trim().length>0).join(`
1
+ import{n as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,n}from"./runtime-switch-CAZiOV2G.js";import{s as r,u as i}from"./queryRuntime-DKGLQtb9.js";import{$ as a,A as o,C as s,F as c,G as l,J as u,K as d,L as f,M as p,N as m,Nt as ee,O as te,Q as ne,R as re,S as ie,T as ae,X as oe,Y as h,Z as se,_ as ce,at as le,b as ue,c as de,d as fe,gt as pe,h as me,ht as he,it as ge,lt as _e,m as ve,nt as ye,o as be,pt as xe,rt as Se,u as Ce,ut as we,v as Te,vt as Ee,w as De,x as Oe,xt as ke,yt as Ae,z as je}from"./platform-7bX6qtBV.js";import{d as g,ga as _,l as Me,wa as v}from"./useMobileNavigationStore-BURkCJuM.js";var Ne=e({COMMIT_DIFF_FILE_LIMIT:()=>30,COMMIT_DIFF_TOTAL_CHAR_LIMIT:()=>j,SESSION_GENERATE_TIMEOUT_MS:()=>M,applyGitStash:()=>K,checkIsGitRepository:()=>x,checkoutCommit:()=>$e,cherryPick:()=>et,collectSelectedFileDiffs:()=>N,countGitStashFiles:()=>W,createBranch:()=>Y,createGitIdentity:()=>Q,createGitWorktree:()=>B,deleteGitIdentity:()=>Je,deleteGitWorktree:()=>V,deleteRemoteBranch:()=>A,discoverGitCredentials:()=>Ye,discoverGitRepositories:()=>S,dropGitStash:()=>J,generateCommitMessage:()=>F,getCommitFileDiff:()=>X,getConflictDetails:()=>$,getGitBranches:()=>k,getGitIdentities:()=>Z,getGitStatus:()=>C,getGitWorktreeBootstrapStatus:()=>R,getGlobalGitIdentity:()=>Xe,git:()=>H,listGitStashes:()=>U,listGitWorktrees:()=>I,merge:()=>Qe,popGitStash:()=>q,previewGitWorktree:()=>z,rebase:()=>Ze,resetToCommit:()=>nt,resolveGitPrimaryRoot:()=>w,resolveGitTopLevel:()=>T,revertCommit:()=>tt,stageGitFile:()=>E,stageGitFiles:()=>D,stashGitChanges:()=>G,unstageGitFile:()=>Pe,unstageGitFiles:()=>O,updateGitIdentity:()=>qe,validateGitWorktree:()=>L}),y=()=>r()?.git??null,b=e=>{let t=e.trim(),n=(t.match(/```(?:json)?\s*([\s\S]*?)```/i)?.[1]??t).trim(),r=[n.indexOf(`{`)].filter(e=>e>=0);for(let e of r)for(let t=n.length;t>e;--t)if(n[t-1]===`}`)try{let r=JSON.parse(n.slice(e,t));if(r&&typeof r==`object`&&!Array.isArray(r))return r}catch{}return null};async function x(e){let t=y();return t?t.checkIsGitRepository(e):de(e)}async function S(e){return De(e)}async function C(e,t){let n=y();return n?n.getGitStatus(e,t):f(e,t)}async function w(e){return(await Se(e)).root}async function T(e){return(await ge(e)).root}async function E(e,t){let n=y();return n?.stageGitFile?n.stageGitFile(e,t):_e(e,t)}async function D(e,t){let n=y();return n?.stageGitFiles?n.stageGitFiles(e,t):we(e,t)}async function Pe(e,t){let n=y();return n?.unstageGitFile?n.unstageGitFile(e,t):he(e,t)}async function O(e,t){let n=y();return n?.unstageGitFiles?n.unstageGitFiles(e,t):pe(e,t)}async function k(e,t){let n=y();if(t?.signal?.throwIfAborted(),n){let r=await n.getGitBranches(e,t);return t?.signal?.throwIfAborted(),r}return p(e,t)}async function A(e,t){let n=y();return n?n.deleteRemoteBranch(e,t):ie(e,t)}var j=12e4,M=9e4,Fe=[`This is an auxiliary structured generation request (git copy).`,`Use the active session context plus the materials below.`,`Answer with the required JSON only.`,`Do not call any tools and do not take any actions.`,`Model and instructions follow the session.generate session contract.`].join(` `),Ie=`Select an active session for generation. session.generate uses that session model contract and does not mutate chat history.`,Le=`No default provider or model configured. Please select a provider and model in settings first.`,Re=`Runtime changed during session.generate`,ze=`session.generate returned empty text`,Be=`session.generate returned invalid structured output`,Ve=e=>{let t=[`Diff budget: included ${e.includedFileCount} of ${e.selectedFileCount} selected files`,`fileLimit=${e.fileLimit}`,`charLimit=${e.charLimit}`,`truncatedByCharLimit=${e.truncatedByCharLimit?`yes`:`no`}`,`omittedFiles=${e.omittedFileCount}`],n=e.omittedFileCount>0||e.truncatedByCharLimit?` Materials are partial under this budget — do not invent diffs for omitted or truncated files; base the message only on provided material.`:` Materials cover the full selected set within the budget.`;return`${t.join(`; `)}.${n}`};async function N(e,t){let n=t.length,r=t.slice(0,30),i=await Promise.all(r.map(async t=>{try{let[n,r]=await Promise.all([m(e,{path:t,staged:!0}).catch(()=>null),m(e,{path:t,staged:!1}).catch(()=>null)]);return[n?.diff,r?.diff].filter(e=>typeof e==`string`&&e.trim().length>0).join(`
2
2
  `)||`--- ${t} (no textual diff available)`}catch{return`--- ${t} (diff unavailable)`}})),a=``,o=0,s=!1;for(let e of i){let t=a?`
3
3
 
4
4
  `:``;if(a.length+t.length+e.length>12e4){a+=`
@@ -1 +1 @@
1
- import"./rolldown-runtime-hePW80VL.js";import{it as e,rt as t}from"./vendor-base-ui-CdzJ6My_.js";import{n}from"./vendor-react-BP2cRVqX.js";import{r}from"./button-_ReBqWzC.js";var i=n();e();var a=t();function o(e){let t=(0,i.c)(10),n,o,s;t[0]===e?(n=t[1],o=t[2],s=t[3]):({className:n,type:s,...o}=e,t[0]=e,t[1]=n,t[2]=o,t[3]=s);let c;t[4]===n?c=t[5]:(c=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)]`,n),t[4]=n,t[5]=c);let l;return t[6]!==o||t[7]!==c||t[8]!==s?(l=(0,a.jsx)(`input`,{type:s,"data-slot":`input`,className:c,spellCheck:!1,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`,...o}),t[6]=o,t[7]=c,t[8]=s,t[9]=l):l=t[9],l}export{o as t};
1
+ import"./rolldown-runtime-hePW80VL.js";import{it as e,rt as t}from"./vendor-base-ui-CdzJ6My_.js";import{n}from"./vendor-react-BP2cRVqX.js";import{r}from"./button-D_HdP1Oy.js";var i=n();e();var a=t();function o(e){let t=(0,i.c)(10),n,o,s;t[0]===e?(n=t[1],o=t[2],s=t[3]):({className:n,type:s,...o}=e,t[0]=e,t[1]=n,t[2]=o,t[3]=s);let c;t[4]===n?c=t[5]:(c=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)]`,n),t[4]=n,t[5]=c);let l;return t[6]!==o||t[7]!==c||t[8]!==s?(l=(0,a.jsx)(`input`,{type:s,"data-slot":`input`,className:c,spellCheck:!1,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`,...o}),t[6]=o,t[7]=c,t[8]=s,t[9]=l):l=t[9],l}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-CAZiOV2G.js";import{a as r,o as i,s as a}from"./queryRuntime-DKGLQtb9.js";import{D as o,O as s,rn as c}from"./persistence-Dzooc9Xg.js";import{a as l,i as u,r as d}from"./vendor-zustand-o69pgTEK.js";import{it as f,rt as p}from"./vendor-base-ui-CdzJ6My_.js";import{B as m,Ct as h,M as g,Mt as _}from"./platform-7bX6qtBV.js";import{b as v,n as ee,x as y}from"./useUIStore-NMQx_cnG.js";import{n as b}from"./vendor-react-BP2cRVqX.js";import{s as x}from"./vendor-tanstack-react-query-CdqCAt40.js";import{n as S}from"./vendor-reactuses-core-BpfIZ1tg.js";import{f as te,r as C,u as ne}from"./button-_ReBqWzC.js";import{Bt as re,Dr as ie,Pr as ae,S as oe,Un as w,Ya as T,cn as se,ct as ce,d as E,do as le,fo as D,ht as ue,lt as de,ut as fe,vn as O,wa as k,y as pe,za as me}from"./useMobileNavigationStore-DcG6Ukmu.js";import{t as he}from"./AgentAvatar-D6H7fWWf.js";import{n as A}from"./Icon-2cKLcXGe.js";import{g as ge,v as _e}from"./gitApi-BN0aozGg.js";import{f as ve,o as j}from"./projectMeta-B5lVMdxF.js";import{n as ye}from"./textarea-C5vjnZcE.js";import{c as be,d as M,l as N,n as xe,r as Se,t as Ce}from"./fileMentionTouchSelection-Bip-B2J9.js";var we=(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=w([...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)},Te=(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}),Ee=(e,t)=>e.highlightedIndex===t.highlightedIndex&&Te(e.rows,t.rows),De=(e,t)=>Te(e,t)?e:t.slice(),Oe=(e,t,n)=>{e&&(t.current&&Ee(t.current,n)||(t.current=n,e(n)))},ke=(e,t)=>{t.current=null,e?.({rows:[],highlightedIndex:0})},P=e(f(),1),F=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},I=e=>/^[A-Za-z]:\//.test(e)?e.toLowerCase():e,L=(e,t)=>{let n=F(t),r=F(e);if(!n||!r)return!1;let i=I(n),a=I(r);return a===i||a.startsWith(`${i}/`)},Ae=e=>{if(!e||typeof e!=`object`)return{};let t=e,n={};for(let[e,r]of Object.entries(t)){let t=F(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=>F(e)).filter(e=>L(e,t)))):[],o=Array.isArray(i.expandedPaths)?Array.from(new Set(i.expandedPaths.filter(e=>typeof e==`string`).map(e=>F(e)).filter(e=>L(e,t)))):[],s=typeof i.selectedPath==`string`?F(i.selectedPath):null,c=s&&L(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},R=(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},z=e=>e?{...e,touchedAt:Date.now()}:{openPaths:[],selectedPath:null,expandedPaths:[],touchedAt:Date.now()},je=l()(d(u((e,t)=>({byRoot:{},addOpenPath:(t,n,r)=>{let i=F((t||``).trim()),a=F((n||``).trim());!i||!a||!r?.allowOutsideRoot&&!L(a,i)||e(e=>{let t=e.byRoot[i],n=z(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:R({...e.byRoot,[i]:{...n,openPaths:o,selectedPath:s}},20)}})},removeOpenPath:(t,n)=>{let r=F((t||``).trim()),i=F((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=I(i),a=e=>I(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:R({...e.byRoot,[r]:{...t,openPaths:s,selectedPath:c,touchedAt:Date.now()}},20)}})},removeOpenPathsByPrefix:(t,n)=>{let r=F((t||``).trim()),i=F((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=I(i),a=n.endsWith(`/`)?n:`${n}/`,o=e=>{let t=I(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:R({...e.byRoot,[r]:{...t,openPaths:s,selectedPath:c,touchedAt:Date.now()}},20)}})},removeExpandedPathsByPrefix:(t,n)=>{let r=F((t||``).trim()),i=F((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=I(i),a=n.endsWith(`/`)?n:`${n}/`,o=t.expandedPaths.filter(e=>{let t=I(e);return t!==n&&!t.startsWith(a)});return o.length===t.expandedPaths.length?e:{byRoot:R({...e.byRoot,[r]:{...t,expandedPaths:o,touchedAt:Date.now()}},20)}})},setSelectedPath:(t,n,r)=>{let i=F((t||``).trim()),a=n?F(n.trim()):null;!i||a&&!r?.allowOutsideRoot&&!L(a,i)||e(e=>{let t=e.byRoot[i],n=z(t),r=a&&!n.openPaths.includes(a)?[...n.openPaths,a]:n.openPaths;return t&&t.selectedPath===a&&r===t.openPaths?e:{byRoot:R({...e.byRoot,[i]:{...n,openPaths:r,selectedPath:a}},20)}})},ensureSelectedPath:e=>{let n=F((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=F((t||``).trim()),i=F((n||``).trim());!r||!i||!L(i,r)||e(e=>{let t=e.byRoot[r],n=z(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:R({...e.byRoot,[r]:{...n,expandedPaths:a}},20)}})},expandPath:(t,n)=>{let r=F((t||``).trim()),i=F((n||``).trim());!r||!i||!L(i,r)||e(e=>{let t=e.byRoot[r],n=z(t);return n.expandedPaths.includes(i)&&t?e:{byRoot:R({...e.byRoot,[r]:{...n,expandedPaths:[...n.expandedPaths,i]}},20)}})},expandPaths:(t,n)=>{let r=F((t||``).trim());if(!r||!n||n.length===0)return;let i=n.map(e=>F((e||``).trim())).filter(e=>e&&L(e,r));i.length!==0&&e(e=>{let t=e.byRoot[r],n=z(t),a=new Set(n.expandedPaths),o=i.filter(e=>!a.has(e));return o.length===0?e:{byRoot:R({...e.byRoot,[r]:{...n,expandedPaths:[...n.expandedPaths,...o]}},20)}})}}),{name:`files-view-tabs-store`,version:2,storage:v(),migrate:e=>{if(!e||typeof e!=`object`)return{byRoot:{}};let t=e.byRoot;return{byRoot:Ae(t)}},partialize:e=>({byRoot:Ae(e.byRoot)})}),{name:`files-view-tabs-store`})),B=b(),Me=(e,t)=>{let n=(0,B.c)(4),r=t===void 0?200:t,[i,a]=P.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]),P.useEffect(o,s),i},Ne=()=>{let e=(0,B.c)(17),t=E(Pe),n=O(),r;e[0]===t?r=e[1]:(r=e=>t?e.getAttachment(t):void 0,e[0]=t,e[1]=r);let i=oe(r),a=E(V),o=E(H),s=D(U),c=D(Fe),l=h(Ie);if(t){let r;e[2]===i?r=e[3]:(r=pe(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 Pe(e){return e.currentSessionId}function V(e){return e.worktreeMetadata}function H(e){return e.newSessionDraft}function U(e){return e.activeProjectId}function Fe(e){return e.projects}function Ie(e){return e.currentDirectory}var W=p(),Le=`bg-transparent font-[inherit] text-[var(--primary-base)]`,G=(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,W.jsx)(`mark`,{className:Le,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},Re=P.forwardRef(({searchQuery:e,onFileSelect:t,onAgentSelect:n,onSkillSelect:r,onSessionSelect:i,onClose:a,style:c,onRowsChange:l},u)=>{let{t:d}=te(),f=Ne()??``,p=E(e=>e.currentSessionId),m=ae(e=>e.activeSessions),h=re({enabled:!!i}),g=D(e=>e.activeProjectId),v=D(e=>e.projects),y=P.useMemo(()=>v.find(e=>e.id===g)?.path??null,[g,v]),b=P.useMemo(()=>{let e=y||f;return e?e.replace(/\\/g,`/`).replace(/\/+$/,``):null},[y,f]),x=je(e=>b?e.byRoot[b]:void 0),oe=k(e=>e.agents),w=_(e=>e.searchFiles),se=Me(e,180),le=s(),O=o(),[pe,ge]=P.useState([]),[_e,ve]=P.useState(!1),[j,M]=P.useState(0),N=P.useRef(0),we=P.useRef({query:e,directory:f,ids:[]}),[Te,Ee]=P.useState(360),[De,F]=P.useState({}),[I,L]=P.useState({}),Ae=P.useRef([]),R=P.useRef([]),z=P.useRef([]),B=P.useRef(null),Pe=P.useRef(null),V=P.useRef(null);V.current||=Ce();let H=ee(e=>e.isMobile),U=(e??``).trim(),Fe=T({directory:f||null}),Ie=P.useMemo(()=>r?Fe.data??[]:[],[r,Fe.data]),Le=P.useMemo(()=>{if(!b||!x)return[];let e=[x.selectedPath,...x.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(`${b}/`)?e.slice(b.length+1):e;n.push({name:i,path:e,relativePath:a,extension:i.includes(`.`)?i.split(`.`).pop()?.toLowerCase():void 0})}return fe(n,U,{limit:6})},[U,b,x]),Re=P.useMemo(()=>n?me(oe).filter(e=>e.mode!==`primary`):[],[oe,n]),ze=P.useMemo(()=>i?ce({sessions:ie(m,h),currentSessionId:p,searchQuery:U}):[],[m,p,h,U,i]),K=Le,Be=pe,q=P.useMemo(()=>be({skills:Ie,agents:Re,sessions:ze,recentFiles:K,pathHits:Be,searchQuery:U,untitledSession:d(`chat.fileMentionAutocomplete.untitledSession`),sessionBadge:d(`chat.fileMentionAutocomplete.sessionType`),skillBadge:d(`chat.commandAutocomplete.badge.skill`)}),[Ie,Re,ze,K,Be,U,d]);P.useEffect(()=>{let e=e=>{let t=e.target;!t||!B.current||B.current.contains(t)||a()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},[a]),P.useEffect(()=>{if(!f){ge([]);return}let e=(se??``).trim(),t=ue(e);if(!t){ge([]);return}let n=!1;ve(!0);let r={includeHidden:le,respectGitignore:!O};return Promise.all([w(f,t,80,{...r,type:`file`}),w(f,t,40,{...r,type:`directory`})]).then(([t,r])=>{if(n)return;let i=new Set(Le.map(e=>e.path));ge(de({files:t,directories:r,query:e,excludePaths:i,limit:20}))}).catch(()=>{n||ge([])}).finally(()=>{n||ve(!1)}),()=>{n=!0}},[f,se,Le,w,le,O]),P.useLayoutEffect(()=>{let t=we.current,n=t.ids[N.current],r=t.query===e&&t.directory===f?Math.max(0,q.findIndex(e=>e.id===n)):0;we.current={query:e,directory:f,ids:q.map(e=>e.id)},N.current=r,M(r)},[q,e,f]),P.useEffect(()=>{F({}),L({})},[q]),P.useEffect(()=>{Ae.current[j]?.scrollIntoView({block:`nearest`})},[j]),P.useEffect(()=>{let e=null,t=()=>{e!==null&&cancelAnimationFrame(e),e=requestAnimationFrame(()=>{let e={},t={};R.current.forEach((n,r)=>{if(!n)return;let i=z.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}}),F(e),L(t)})};return t(),window.addEventListener(`resize`,t),()=>{e!==null&&cancelAnimationFrame(e),window.removeEventListener(`resize`,t)}},[q]),P.useEffect(()=>{let e=R.current[j];if(!e)return;let t=()=>{let t=e.clientWidth;t>0&&Ee(t)};if(t(),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(t);return n.observe(e),()=>{n.disconnect()}},[j]);let Ve=S(e=>{t(e)}),He=S(e=>{n?.(e)}),Ue=S(e=>{i?.(e)}),We=S(e=>{r?.(e)}),Ge=(e,t)=>({onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{e.pointerType===`touch`&&V.current?.pointerDown(e.clientX,e.clientY)},onPointerMove:e=>{e.pointerType===`touch`&&V.current?.pointerMove(e.clientX,e.clientY)},onPointerUp:e=>{e.pointerType===`touch`&&(V.current?.pointerUp(t)??!1)&&(e.preventDefault(),e.stopPropagation())},onPointerCancel:()=>V.current?.pointerCancel(),onClick:()=>{V.current?.click(t)},onMouseMove:()=>{N.current=e,M(e)}}),J=e=>{let t=q.length;if(t===0)return;let n=(e%t+t)%t,r=q[n];if(r.agentName!==void 0){He(r.agentName);return}if(r.id.startsWith(`skill:`)){let e=Ie.find(e=>r.id===`skill:${e.name}-${e.scope}`);e&&We(e);return}if(r.id.startsWith(`session:`)){let e=ze.find(e=>r.id===`session:${e.id}`);e&&Ue(e);return}let i=r.id.startsWith(`recent:`)?K.find(e=>r.id===`recent:${e.path}`):Be.find(e=>r.id===`file:${e.path}`);i&&Ve(i)};P.useEffect(()=>{Oe(l,Pe,{rows:q,highlightedIndex:j})},[l,j,q]);let Ke=P.useRef(l);return Ke.current=l,P.useEffect(()=>()=>{ke(Ke.current,Pe)},[]),P.useImperativeHandle(u,()=>({acceptIndex:e=>{J(e)},handleKeyDown:e=>{if(e===`Escape`){a();return}let t=q.length;if(t!==0){if(e===`ArrowDown`){N.current=(N.current+1)%t,M(N.current);return}if(e===`ArrowUp`){N.current=(N.current-1+t)%t,M(N.current);return}(e===`Enter`||e===`Tab`)&&J(N.current)}}})),(0,W.jsxs)(xe,{ref:B,isMobile:H,className:`max-w-[640px] max-h-64`,style:c,children:[(0,W.jsx)(ye,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0`,children:(0,W.jsxs)(`div`,{className:`py-1`,children:[q.map((e,t)=>{let n=e.id.startsWith(`file:`)||e.id.startsWith(`recent:`),r=n?ne(e.title,{maxLength:60}):e.title,i=j===t,a=De[t]??!1,o=I[t]??2.6;return(0,W.jsxs)(`div`,{"data-mention-id":e.id,ref:e=>{Ae.current[t]=e},className:C(`flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,H&&`min-h-11`,Se(H,i),!H&&i&&`text-interactive-selection-foreground`),...Ge(t,()=>J(t)),children:[(0,W.jsx)(`span`,{className:`flex size-5 shrink-0 items-center justify-center`,children:e.agentName===void 0?(0,W.jsx)(A,{name:e.iconName,className:`size-3.5 text-current`}):(0,W.jsx)(he,{name:e.agentName,size:20})}),(0,W.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,W.jsxs)(`span`,{ref:e=>{R.current[t]=e},className:`relative block min-w-0 overflow-hidden file-mention-marquee-container`,style:i?{"--file-mention-marquee-width":`${Te}px`,"--file-mention-marquee-duration":`${o}s`}:void 0,title:e.title,children:[(0,W.jsx)(`span`,{ref:e=>{z.current[t]=e},className:`absolute invisible whitespace-nowrap pointer-events-none`,"aria-hidden":!0,children:e.title}),n&&a&&i?(0,W.jsx)(`span`,{className:`inline-block whitespace-nowrap file-mention-marquee`,children:G(e.title,U)}):(0,W.jsx)(`span`,{className:`block truncate`,children:G(r,U)})]}),e.subtitle?(0,W.jsx)(`div`,{className:C(`truncate text-muted-foreground`,H?`typography-micro`:`typography-meta`),children:G(e.subtitle,U)}):null]})]},e.id)}),_e&&Be.length===0?(0,W.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,W.jsx)(A,{name:`refresh`,className:`h-4 w-4 animate-spin text-muted-foreground`})}):null,!_e&&q.length===0&&(0,W.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.empty`)})]})}),!H&&(0,W.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:d(`chat.autocomplete.keyboardHint`)})]})}),ze=new Set([`new`,`fork`,`compact`,`reload`,`undo`,`redo`,`model`,`goal`,`btw`]),K=(e,t)=>{if(!t||e.isSkill)return!1;let n=e.name?.trim().toLowerCase();return!!(n&&ze.has(n))},Be=(e,t)=>!e||t({name:e}),q=` `,Ve=(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]===q&&e[r-2]===`/`&&(r-=2),e[r]===`/`?{start:r,end:n}:null},He=`text-[10px] leading-none uppercase font-bold tracking-tight px-1.5 py-1 rounded border flex-shrink-0`,Ue=C(He,`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)]`),We=C(He,`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)]`),Ge=C(He,`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)]`),J=C(He,`bg-[var(--surface-muted)] text-muted-foreground border-[var(--interactive-border)]/60`),Ke=(e,t)=>e.length===t.length&&e.every((e,n)=>e.id===t[n]?.id&&e.description===t[n]?.description),qe=(e,t)=>{let n=!!e.sessionID;return{hasSession:n,canStartSessionCommand:n||e.hasNewDraft,canUseReviewHandoffFlow:n&&!t&&!c()}},Je=P.forwardRef(({searchQuery:e,onCommandSelect:t,onClose:n,directory:r,style:i,commandPolicy:a,commandContext:o,onRowsChange:s},l)=>{let{t:u}=te(),d=ee(e=>e.isMobile),f=E(e=>e.currentSessionId),p=E(e=>!!e.newSessionDraft?.open),m=E(P.useCallback(e=>f?e.getDirectoryForSession(f):void 0,[f])),h=se(f??``,m??void 0),g=P.useMemo(()=>o??{sessionID:f??null,hasMessages:h.length>0,hasNewDraft:p},[o,f,h.length,p]),{hasSession:_,canStartSessionCommand:v,canUseReviewHandoffFlow:y}=P.useMemo(()=>qe(g,d),[g,d]),b=g.hasMessages,[x,S]=P.useState([]),[ne,re]=P.useState(!1),ie=le({directory:r}),ae=P.useMemo(()=>ie.data??[],[ie.data]),oe=ie.isFetching,[w,T]=P.useState(0),ce=P.useRef(0),D=P.useRef(!1),ue=P.useRef([]),de=P.useRef(null),fe=P.useRef(!1),O=P.useRef(null),k=P.useRef(!1),pe=P.useRef(null);P.useEffect(()=>{let e=e=>{let t=e.target;!t||!de.current||de.current.contains(t)||n()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},[n]),P.useEffect(()=>{(async()=>{re(oe);try{let t=ae.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},..._&&!b?[{id:`yuri:init`,name:`init`,source:`yuri`,description:u(`chat.commandAutocomplete.command.initDescription`),isBuiltIn:!0}]:[],..._?[{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},...c()?[{id:`yuri:reload`,name:`reload`,source:`yuri`,description:u(`chat.commandAutocomplete.command.reloadDescription`),isBuiltIn:!0}]:[],..._?[{id:`yuri:summary`,name:`summary`,source:`yuri`,description:u(`chat.commandAutocomplete.command.summaryDescription`),isYuri:!0}]:[],...v?[{id:`yuri:workspace-review`,name:`workspace-review`,source:`yuri`,description:u(`chat.commandAutocomplete.command.workspaceReviewDescription`),isYuri:!0}]:[],...y?[{id:`yuri:handoff-review`,name:`handoff-review`,source:`yuri`,description:u(`chat.commandAutocomplete.command.handoffReviewDescription`),isYuri:!0}]:[],...v?[{id:`yuri:craft-goal`,name:`craft-goal`,source:`yuri`,description:u(`chat.commandAutocomplete.command.craftGoalDescription`),isYuri:!0}]:[],...v?[{id:`yuri:goal`,name:`goal`,source:`yuri`,description:u(`chat.goal.button.armAria`),isBuiltIn:!0}]:[],...v?[{id:`yuri:catch-up`,name:`catch-up`,source:`yuri`,description:u(`chat.commandAutocomplete.command.catchUpDescription`),isYuri:!0}]:[],...v?[{id:`yuri:debug`,name:`debug`,source:`yuri`,description:u(`chat.commandAutocomplete.command.debugDescription`),isYuri:!0}]:[],...v?[{id:`yuri:weigh`,name:`weigh`,source:`yuri`,description:u(`chat.commandAutocomplete.command.weighDescription`),isYuri:!0}]:[],...v?[{id:`yuri:explore`,name:`explore`,source:`yuri`,description:u(`chat.commandAutocomplete.command.exploreDescription`),isYuri:!0}]:[],...t],r=!b,i=we(n.filter(e=>(r||e.name!==`init`)&&(a?.(e)??!0)),e);S(e=>Ke(e,i)?e:i)}catch{let t=!b,n=we([{id:`yuri:new`,name:`new`,source:`yuri`,description:u(`chat.commandAutocomplete.command.newDescription`),isBuiltIn:!0},..._&&!b?[{id:`yuri:init`,name:`init`,source:`yuri`,description:u(`chat.commandAutocomplete.command.initDescription`),isBuiltIn:!0}]:[],..._?[{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},...c()?[{id:`yuri:reload`,name:`reload`,source:`yuri`,description:u(`chat.commandAutocomplete.command.reloadDescription`),isBuiltIn:!0}]:[],..._?[{id:`yuri:summary`,name:`summary`,source:`yuri`,description:u(`chat.commandAutocomplete.command.summaryDescription`),isYuri:!0}]:[],...v?[{id:`yuri:workspace-review`,name:`workspace-review`,source:`yuri`,description:u(`chat.commandAutocomplete.command.workspaceReviewDescription`),isYuri:!0}]:[],...y?[{id:`yuri:handoff-review`,name:`handoff-review`,source:`yuri`,description:u(`chat.commandAutocomplete.command.handoffReviewDescription`),isYuri:!0}]:[],...v?[{id:`yuri:craft-goal`,name:`craft-goal`,source:`yuri`,description:u(`chat.commandAutocomplete.command.craftGoalDescription`),isYuri:!0}]:[],...v?[{id:`yuri:goal`,name:`goal`,source:`yuri`,description:u(`chat.goal.button.armAria`),isBuiltIn:!0}]:[],...v?[{id:`yuri:catch-up`,name:`catch-up`,source:`yuri`,description:u(`chat.commandAutocomplete.command.catchUpDescription`),isYuri:!0}]:[],...v?[{id:`yuri:debug`,name:`debug`,source:`yuri`,description:u(`chat.commandAutocomplete.command.debugDescription`),isYuri:!0}]:[],...v?[{id:`yuri:weigh`,name:`weigh`,source:`yuri`,description:u(`chat.commandAutocomplete.command.weighDescription`),isYuri:!0}]:[],...v?[{id:`yuri:explore`,name:`explore`,source:`yuri`,description:u(`chat.commandAutocomplete.command.exploreDescription`),isYuri:!0}]:[]].filter(e=>(t||e.name!==`init`)&&(a?.(e)??!0)),e);S(e=>Ke(e,n)?e:n)}finally{re(!1)}})()},[e,b,_,v,y,ae,oe,u,a]),P.useEffect(()=>{T(0)},[x]),P.useEffect(()=>{ce.current=w},[w]),P.useEffect(()=>{ue.current[w]?.scrollIntoView({block:`nearest`})},[w]),P.useEffect(()=>{Oe(s,pe,{rows:N(x,{skill:u(`chat.commandAutocomplete.badge.skill`),command:u(`chat.commandAutocomplete.badge.command`),system:u(`chat.commandAutocomplete.badge.system`)}),highlightedIndex:w})},[x,s,w,u]);let me=P.useRef(s);me.current=s,P.useEffect(()=>()=>{ke(me.current,pe)},[]),P.useImperativeHandle(l,()=>({acceptIndex:(e,n=!0)=>{let r=x[e];r&&t(r,K(r,n))},handleKeyDown:e=>{let r=x.length;if(e===`Escape`){n();return}if(r!==0){if(e===`ArrowDown`){D.current=!0,T(e=>(e+1)%r);return}if(e===`ArrowUp`){D.current=!0,T(e=>(e-1+r)%r);return}if(e===`Enter`||e===`Tab`){let n=(ce.current%r+r)%r,i=x[n];i&&t(i,K(i,e===`Enter`))}}}}),[x,n,t]);let he=e=>{let t=M(e);switch(e.name){case`new`:return(0,W.jsx)(A,{name:t,className:`h-3.5 w-3.5`});case`init`:return(0,W.jsx)(A,{name:t,className:`h-3.5 w-3.5 text-green-500`});case`undo`:return(0,W.jsx)(A,{name:t,className:`h-3.5 w-3.5 text-orange-500`});case`redo`:return(0,W.jsx)(A,{name:t,className:`h-3.5 w-3.5 text-orange-500`});case`timeline`:case`reload`:return(0,W.jsx)(A,{name:t,className:`h-3.5 w-3.5`});case`compact`:return(0,W.jsx)(A,{name:t,className:`h-3.5 w-3.5 text-purple-500`});case`goal`:return(0,W.jsx)(A,{name:t,className:`h-3.5 w-3.5`});case`review`:return(0,W.jsx)(A,{name:t,className:`h-3.5 w-3.5 text-blue-500`});case`test`:case`build`:case`run`:return(0,W.jsx)(A,{name:t,className:`h-3.5 w-3.5 text-cyan-500`});default:return e.isBuiltIn?(0,W.jsx)(A,{name:t,className:`h-3.5 w-3.5 text-yellow-500`}):(0,W.jsx)(A,{name:t,className:`h-3.5 w-3.5 text-muted-foreground`})}};return(0,W.jsxs)(xe,{ref:de,isMobile:d,className:`max-w-[450px] max-h-64`,style:i,children:[(0,W.jsx)(ye,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0 py-1.5`,children:ne?(0,W.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,W.jsx)(A,{name:`refresh`,className:`h-4 w-4 animate-spin text-muted-foreground`})}):(0,W.jsxs)(`div`,{children:[x.map((n,r)=>{let i=n.isBuiltIn,a=n.isYuri;return(0,W.jsxs)(`div`,{ref:e=>{ue.current[r]=e},className:C(`flex gap-2 px-2 py-2 cursor-pointer rounded-lg`,d?`items-center`:`items-start`,Se(d,r===w),!d&&r===w&&`bg-interactive-selection/35`),onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{e.pointerType===`touch`&&(O.current={x:e.clientX,y:e.clientY},k.current=!1)},onPointerMove:e=>{if(e.pointerType!==`touch`||!O.current)return;let t=e.clientX-O.current.x,n=e.clientY-O.current.y;Math.hypot(t,n)>6&&(k.current=!0)},onPointerUp:e=>{if(e.pointerType!==`touch`)return;let r=k.current;O.current=null,k.current=!1,!r&&(e.preventDefault(),e.stopPropagation(),fe.current=!0,t(n,K(n,d)))},onPointerCancel:()=>{O.current=null,k.current=!1},onClick:()=>{if(fe.current){fe.current=!1;return}t(n,K(n,d))},onMouseMove:()=>{D.current=!1,T(r)},children:[(0,W.jsx)(`div`,{className:C(!d&&`mt-0.5`),children:he(n)}),(0,W.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsxs)(`span`,{className:`typography-ui-label font-medium`,children:[`/`,G(n.name,e)]}),n.isSkill?(0,W.jsx)(`span`,{className:Ue,children:u(`chat.commandAutocomplete.badge.skill`)}):(0,W.jsx)(`span`,{className:Ue,children:u(`chat.commandAutocomplete.badge.command`)}),a?(0,W.jsx)(`span`,{className:J,children:`Yuri`}):i?(0,W.jsx)(`span`,{className:J,children:u(`chat.commandAutocomplete.badge.system`)}):n.scope?(0,W.jsx)(`span`,{className:n.scope===`project`?Ge:We,children:n.scope}):null,n.agent&&(0,W.jsx)(`span`,{className:J,children:n.agent})]}),n.description&&!d&&(0,W.jsx)(`div`,{className:`typography-meta text-muted-foreground mt-0.5 truncate`,children:G(n.description,e)})]})]},n.id)}),x.length===0&&(0,W.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:u(`chat.commandAutocomplete.empty`)})]})}),!d&&(0,W.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:u(`chat.autocomplete.keyboardHint`)})]})});Je.displayName=`CommandAutocomplete`;var Ye=2,Xe=e=>!!e&&typeof e==`object`&&!Array.isArray(e),Ze=e=>{let t=e?.trim().replace(/\\/g,`/`);return t?t.length>1?t.replace(/\/+$/,``):t:null},Qe=e=>Xe(e)&&Array.isArray(e.all)&&e.all.every(e=>typeof e==`string`)&&typeof e.current==`string`&&Xe(e.branches),Y=(e,t)=>JSON.stringify([e,t]),$e=e=>`version`in e&&e.version===Ye&&Xe(e.entries),et=e=>{if(!e)return null;try{let t=JSON.parse(e);return Xe(t)?t.version===Ye&&Xe(t.entries)?{version:Ye,entries:t.entries}:t:null}catch{return null}},tt=(e,t)=>{try{e.setItem(`yuri.gitBranchCache`,JSON.stringify(t))}catch{}},nt=(e,t,n)=>{let r=Ze(e);if(!r||!t)return null;let i;try{i=n.getItem(`yuri.gitBranchCache`)}catch{return null}let a=et(i);if(!a)return null;if($e(a))return Qe(a.entries[Y(t,r)])?a.entries[Y(t,r)]:null;let o={};for(let[e,n]of Object.entries(a)){let r=Ze(e);r&&Qe(n)&&(o[Y(t,r)]=n)}return tt(n,{version:Ye,entries:o}),o[Y(t,r)]??null},rt=(e,t,n,r)=>{let i=Ze(e);if(!i||!t||!Qe(n))return;let a=null;try{a=r.getItem(`yuri.gitBranchCache`)}catch{return}let o=et(a);tt(r,{version:Ye,entries:{...o&&$e(o)?o.entries:{},[Y(t,i)]:n}})},it=3e4,X=Ze,at=(e,t=n())=>i.git.branches(X(e),t),ot=(e,t=n())=>i.git.remotes(X(e),t),st=async(e,t,n)=>{n.throwIfAborted();let r=a()?.git,i=t?.getGitBranches?await t.getGitBranches(e,{signal:n}):r?await r.getGitBranches(e,{signal:n}):await g(e,{signal:n});return n.throwIfAborted(),i},ct=async(e,t,n)=>{n.throwIfAborted();let r=a()?.git,i=t?.getRemotes?await t.getRemotes(e,{signal:n}):r?await r.getRemotes(e,{signal:n}):await m(e,{signal:n});return n.throwIfAborted(),i},lt=(e,t,r=n(),i=y())=>{let a=X(e),o=t;return{queryKey:at(a,r),queryFn:async({signal:e})=>{if(!a)throw Error(`Git branches require a directory`);let t=await st(a,o,e);return rt(a,r,t,i),t},staleTime:it,gcTime:1/0,initialData:()=>nt(a,r,i)??void 0,initialDataUpdatedAt:0}},ut=(e,t,r=n())=>{let i=X(e),a=t;return{queryKey:ot(i,r),queryFn:({signal:e})=>{if(!i)throw Error(`Git remotes require a directory`);return ct(i,a,e)},staleTime:it,gcTime:1/0}},dt=(e,r,i)=>{let a=(0,B.c)(9),o=i===void 0||i,s=P.useSyncExternalStore(t,n,n),c,l,u;a[0]!==e||a[1]!==r||a[2]!==s?(c=X(e),u=x,l=lt(c,r,s),a[0]=e,a[1]=r,a[2]=s,a[3]=c,a[4]=l,a[5]=u):(c=a[3],l=a[4],u=a[5]);let d=o&&!!c,f;return a[6]!==l||a[7]!==d?(f={...l,enabled:d},a[6]=l,a[7]=d,a[8]=f):f=a[8],u(f)},ft=(e,r,i)=>{let a=(0,B.c)(9),o=i===void 0||i,s=P.useSyncExternalStore(t,n,n),c,l,u;a[0]!==e||a[1]!==r||a[2]!==s?(c=X(e),u=x,l=ut(c,r,s),a[0]=e,a[1]=r,a[2]=s,a[3]=c,a[4]=l,a[5]=u):(c=a[3],l=a[4],u=a[5]);let d=o&&!!c,f;return a[6]!==l||a[7]!==d?(f={...l,enabled:d},a[6]=l,a[7]=d,a[8]=f):f=a[8],u(f)},pt=(e,t,i=r,a=n())=>i.fetchQuery(lt(e,t,a)),mt=(e,t,i=r,a=n())=>i.fetchQuery({...lt(e,t,a),staleTime:0}),ht=e=>e instanceof Error?e.name===`AbortError`||e.name===`CancelledError`||e.name===`Error`&&e.message===`CancelledError`:!1,gt=1e4,_t=6e4,vt=5e3,yt=3e4,bt=6e4,xt=25,St=40,Ct=2,wt=15e3,Tt=500,Et=30,Dt=20971520,Ot=new Map,kt=new Map,At=new Map,jt=new Map,Mt=new Map,Nt=(e,t)=>`${t}:${e}`,Pt=e=>kt.get(e)??0,Ft=e=>{let t=Pt(e)+1;return kt.set(e,t),t},It=e=>{let t=(At.get(e)??0)+1;return At.set(e,t),t},Lt=e=>{let t=Ot.get(e);if(t)return t;let n=new Set;return Ot.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}),Rt=(e,t=Et,n=Dt)=>{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},zt=(e,t)=>{if(!e&&!t)return!1;if(!e||!t)return!0;let n=new Set([...Object.keys(e),...Object.keys(t)]);for(let r of n){let n=e[r],i=t[r];if(!(!n&&!i)&&(!n||!i||n.insertions!==i.insertions||n.deletions!==i.deletions))return!0}return!1},Bt=(e,t)=>!e&&!t?!1:!e||!t||e.remote!==t.remote||e.branch!==t.branch||e.ahead!==t.ahead||e.behind!==t.behind,Vt=(e,t)=>{if(!e&&!t)return!1;if(!e||!t)return!0;let n=e.files??[],r=t.files??[];if(n.length!==r.length||e.ahead!==t.ahead||e.behind!==t.behind||e.current!==t.current||e.tracking!==t.tracking||e.isClean!==t.isClean||t.upstreamComparison!==void 0&&Bt(e.upstreamComparison,t.upstreamComparison))return!0;let i=new Set(n.map(e=>`${e.path}:${e.index}:${e.working_dir}`));for(let e of r)if(!i.has(`${e.path}:${e.index}:${e.working_dir}`))return!0;return!!(t.diffStats!==void 0&&zt(e.diffStats,t.diffStats))},Ht=(e,t)=>{let n=new Set;if(!t)return n;let r=e?.files??[],i=t.files??[],a=new Map(r.map(e=>[e.path,e])),o=new Map(i.map(e=>[e.path,e])),s=new Set([...a.keys(),...o.keys()]);for(let e of s){let t=a.get(e),r=o.get(e);if(!t||!r){n.add(e);continue}if(t.index!==r.index||t.working_dir!==r.working_dir){n.add(e);continue}}if(t.diffStats!==void 0){let r=e?.diffStats??{},i=t.diffStats??{},a=new Set([...Object.keys(r),...Object.keys(i)]);for(let e of a){let t=r[e],a=i[e];if(!t||!a){n.add(e);continue}(t.insertions!==a.insertions||t.deletions!==a.deletions)&&n.add(e)}}return n},Ut=(e,t)=>{if(!e&&!t)return!1;if(!e||!t)return!0;let n=e.files??[],r=t.files??[],i=e=>{let t=e?.trim()??``;return t===`?`?``:t},a=new Map(n.map(e=>[e.path,i(e.index)])),o=new Map(r.map(e=>[e.path,i(e.index)])),s=new Set([...a.keys(),...o.keys()]);for(let e of s)if((a.get(e)??``)!==(o.get(e)??``))return!0;return!1},Wt=e=>!e||e.trim().length===0,Gt=e=>(e||``).trim()===`U`,Kt=e=>{let t=(e.index||``).trim(),n=(e.working_dir||``).trim();if(Gt(t)||Gt(n))return e;let r=t===`?`||n===`?`?`A`:t||n||` `;return{...e,index:r,working_dir:` `}},qt=e=>{let t=(e.index||``).trim(),n=(e.working_dir||``).trim();if(Gt(t)||Gt(n))return e;let r=n||(t===`A`||t===`?`?`?`:t)||` `;return{...e,index:` `,working_dir:r}},Jt=e=>Wt(e.index)&&Wt(e.working_dir),Q=l()(d((e,t)=>({directories:new Map,activeDirectory:null,setActiveDirectory:n=>{let{activeDirectory:r,directories:i}=t();if(r!==n)if(r&&Ft(r),n&&Ft(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=Nt(n,a),s=jt.get(o)??(a===`light`?jt.get(Nt(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)>_t,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);if(Vt(s.status,u)){c=!0;let r=new Map(t().directories),i=r.get(n)??Z(),s=Ht(i.status,u),l=Ut(i.status,u),d=new Set((i.status?.files??[]).map(e=>e.path)),f=new Set((u.files??[]).map(e=>e.path)),p=new Map(i.diffCache);for(let e of d)f.has(e)||p.delete(e);for(let e of s)p.delete(e);let m=s.size>0;m&&Ft(n);let h={...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:h,diffCache:p,indexRevision:l?i.indexRevision+1:i.indexRevision,lastRepoCheckAt:o?a:i.lastRepoCheckAt,lastStatusFetch:Date.now(),lastStatusChange:m?Date.now():i.lastStatusChange}),e({directories:r})}else{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})();jt.set(o,c);try{return await c}finally{jt.get(o)===c&&jt.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`?Kt(e):qt(e);t!==e&&(l=!0),Jt(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=It(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 mt(r,i,void 0,o):await pt(r,i,void 0,o);if(s!==At.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(ht(i)||console.error(`Failed to fetch git branches:`,i),s!==At.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>gt||!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=Rt(s);a.set(n,{...o,diffCache:c}),e({directories:a})},clearDiffCache:n=>{Ft(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,xt);await t().prefetchDiffs(e,n,i,{maxFiles:xt})},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=St}=a,c=new Set(o.status.files.map(e=>e.path)),l=o.status.diffStats,u=Lt(n),d=[],f=new Set;for(let e of i){if(!e||f.has(e)||(f.add(e),!c.has(e))||o.diffCache.has(e)||u.has(e))continue;let t=l?.[e];t&&t.insertions+t.deletions>Tt||d.push(e)}let p=d.slice(0,Math.max(1,s));if(p.length===0)return;let m=Pt(n);if(typeof document<`u`&&document.hidden)return;p.forEach(e=>u.add(e));let h=0,g=[],_=()=>{let e=h;return h+=1,e<p.length?p[e]:null},v=async e=>{let t=r.getGitFileDiff(n,{path:e}),i=new Promise((e,t)=>{setTimeout(()=>t(Error(`Timed out after ${wt}ms`)),wt)}),a=await Promise.race([t,i]);return{path:e,diff:{original:a.original??``,modified:a.modified??``,isBinary:a.isBinary}}},ee=async()=>{for(;;){if(m!==Pt(n))return;let e=_();if(!e)return;try{g.push(await v(e))}catch{}finally{u.delete(e)}}},y=Math.min(Ct,p.length);if(await Promise.allSettled(Array.from({length:y},()=>ee())),p.forEach(e=>u.delete(e)),m!==Pt(n))return;let b=new Map(t().directories),x=b.get(n);if(!x)return;let S=new Map(x.diffCache),te=Date.now();g.forEach(e=>{!e.diff.isBinary&&e.diff.original===``&&e.diff.modified===``||S.set(e.path,{...e.diff,fetchedAt:te})});let C=Rt(S);b.set(n,{...x,diffCache:C}),e({directories:b})},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<vt||await t().fetchStatus(e,n,{silent:!!r?.status})},ensureAll:(e,n)=>{let r=Mt.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)>=vt)&&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>=yt)&&o.push(t().fetchBranches(e,n)),(!a.log||i-a.lastLogFetch>=gt)&&o.push(t().fetchLog(e,n)),(!a.identity||i-a.lastIdentityFetch>=bt)&&o.push(t().fetchIdentity(e,n)),o.length>0&&await Promise.all(o)})();return Mt.set(e,i),i.finally(()=>{Mt.get(e)===i&&Mt.delete(e)}),i},refresh:async(e,n={})=>{let{activeDirectory:r}=t();r&&await t().fetchAll(r,e,n)}}),{name:`git-store`})),Yt=e=>{let t=(0,B.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)},Xt=e=>{let r=(0,B.c)(3),i=P.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)},Zt=e=>{let t=(0,B.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)},Qt=e=>{let t=(0,B.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)},$t=e=>{let t=(0,B.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)},en=e=>{let t=(0,B.c)(3),n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=new Map,t[0]=n):n=t[0];let r=P.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)},tn=e=>{let t=(0,B.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)},nn=e=>{let t=(0,B.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)},rn=e=>{let t=(0,B.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)},an=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\//,``),on=e=>e.branchName?$(e.branchName):e.mode===`existing`?$(e.existingBranch||e.preferredName||``):$(e.preferredName||``),sn=async e=>{let t=await ve(e);try{let n=an((await ge(e)).branches?.[t]?.tracking||null);if(n?.remote)return n.remote}catch{}try{let t=an((await _e(e)).tracking);if(t?.remote)return t.remote}catch{}return null},cn=async(e,t)=>{let n=await sn(e),r=$(t);return!n||!r?null:{setUpstream:!0,upstreamRemote:n,upstreamBranch:r}},ln=async(e,t,n)=>{let r=on(t),i=n?.resolvedRootTrackingRemote,a=i===void 0?await cn(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},un=async(e,t,n)=>{let r=await ln(e.path,t,n);return j(e,r)},dn=`yuri:lastWorktreeSourceBranch`,fn=({mode:e,sourceBranch:t,linkedPr:n,selectedBranch:r})=>e===`existing-branch`?r||null:n?null:t||null,pn=({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},mn=(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?` `:``}`},hn=(e,t,n)=>{let r=mn(e,t,n);return`${t.length===0&&!/^\s/.test(r)?` `:``}${r}${n.length===0&&!/\s$/.test(r)?` `:``}`},gn=(e,t,n,r)=>{let i=e.slice(0,t),a=e.slice(n),o=hn(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}},_n=(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]},vn=(e,t)=>t<e.length&&e[t]===` `?t+1:t;export{je as A,ft as C,Re as D,Be as E,Ne as O,dt as S,Ve as T,en as _,dn as a,Qt as b,un as c,$t as d,Xt as f,Zt as g,tn as h,hn as i,De as j,Me as k,sn as l,nn as m,_n as n,pn as o,rn as p,gn as r,fn as s,vn as t,ln as u,Yt as v,Je as w,mt 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-CAZiOV2G.js";import{a as r,o as i,s as a}from"./queryRuntime-DKGLQtb9.js";import{D as o,O as s,rn as c}from"./persistence-Dzooc9Xg.js";import{a as l,i as u,r as d}from"./vendor-zustand-o69pgTEK.js";import{it as f,rt as p}from"./vendor-base-ui-CdzJ6My_.js";import{B as m,Ct as h,M as g,Mt as _}from"./platform-7bX6qtBV.js";import{b as v,n as ee,x as y}from"./useUIStore-NMQx_cnG.js";import{n as b}from"./vendor-react-BP2cRVqX.js";import{s as x}from"./vendor-tanstack-react-query-CdqCAt40.js";import{n as S}from"./vendor-reactuses-core-BpfIZ1tg.js";import{f as te,r as C,u as ne}from"./button-D_HdP1Oy.js";import{Bt as re,Dr as ie,Pr as ae,S as oe,Un as w,Ya as T,cn as se,ct as ce,d as E,do as le,fo as D,ht as ue,lt as de,ut as fe,vn as O,wa as k,y as pe,za as me}from"./useMobileNavigationStore-BURkCJuM.js";import{t as he}from"./AgentAvatar-BVnp9gE9.js";import{n as A}from"./Icon-BXTZRnIO.js";import{g as ge,v as _e}from"./gitApi-B1arMnHR.js";import{f as ve,o as j}from"./projectMeta-D3cfkJyk.js";import{n as ye}from"./textarea-BkOdxUN0.js";import{c as be,d as M,l as N,n as xe,r as Se,t as Ce}from"./fileMentionTouchSelection-Bx6vWiqF.js";var we=(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=w([...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)},Te=(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}),Ee=(e,t)=>e.highlightedIndex===t.highlightedIndex&&Te(e.rows,t.rows),De=(e,t)=>Te(e,t)?e:t.slice(),Oe=(e,t,n)=>{e&&(t.current&&Ee(t.current,n)||(t.current=n,e(n)))},ke=(e,t)=>{t.current=null,e?.({rows:[],highlightedIndex:0})},P=e(f(),1),F=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},I=e=>/^[A-Za-z]:\//.test(e)?e.toLowerCase():e,L=(e,t)=>{let n=F(t),r=F(e);if(!n||!r)return!1;let i=I(n),a=I(r);return a===i||a.startsWith(`${i}/`)},Ae=e=>{if(!e||typeof e!=`object`)return{};let t=e,n={};for(let[e,r]of Object.entries(t)){let t=F(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=>F(e)).filter(e=>L(e,t)))):[],o=Array.isArray(i.expandedPaths)?Array.from(new Set(i.expandedPaths.filter(e=>typeof e==`string`).map(e=>F(e)).filter(e=>L(e,t)))):[],s=typeof i.selectedPath==`string`?F(i.selectedPath):null,c=s&&L(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},R=(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},z=e=>e?{...e,touchedAt:Date.now()}:{openPaths:[],selectedPath:null,expandedPaths:[],touchedAt:Date.now()},je=l()(d(u((e,t)=>({byRoot:{},addOpenPath:(t,n,r)=>{let i=F((t||``).trim()),a=F((n||``).trim());!i||!a||!r?.allowOutsideRoot&&!L(a,i)||e(e=>{let t=e.byRoot[i],n=z(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:R({...e.byRoot,[i]:{...n,openPaths:o,selectedPath:s}},20)}})},removeOpenPath:(t,n)=>{let r=F((t||``).trim()),i=F((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=I(i),a=e=>I(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:R({...e.byRoot,[r]:{...t,openPaths:s,selectedPath:c,touchedAt:Date.now()}},20)}})},removeOpenPathsByPrefix:(t,n)=>{let r=F((t||``).trim()),i=F((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=I(i),a=n.endsWith(`/`)?n:`${n}/`,o=e=>{let t=I(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:R({...e.byRoot,[r]:{...t,openPaths:s,selectedPath:c,touchedAt:Date.now()}},20)}})},removeExpandedPathsByPrefix:(t,n)=>{let r=F((t||``).trim()),i=F((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=I(i),a=n.endsWith(`/`)?n:`${n}/`,o=t.expandedPaths.filter(e=>{let t=I(e);return t!==n&&!t.startsWith(a)});return o.length===t.expandedPaths.length?e:{byRoot:R({...e.byRoot,[r]:{...t,expandedPaths:o,touchedAt:Date.now()}},20)}})},setSelectedPath:(t,n,r)=>{let i=F((t||``).trim()),a=n?F(n.trim()):null;!i||a&&!r?.allowOutsideRoot&&!L(a,i)||e(e=>{let t=e.byRoot[i],n=z(t),r=a&&!n.openPaths.includes(a)?[...n.openPaths,a]:n.openPaths;return t&&t.selectedPath===a&&r===t.openPaths?e:{byRoot:R({...e.byRoot,[i]:{...n,openPaths:r,selectedPath:a}},20)}})},ensureSelectedPath:e=>{let n=F((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=F((t||``).trim()),i=F((n||``).trim());!r||!i||!L(i,r)||e(e=>{let t=e.byRoot[r],n=z(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:R({...e.byRoot,[r]:{...n,expandedPaths:a}},20)}})},expandPath:(t,n)=>{let r=F((t||``).trim()),i=F((n||``).trim());!r||!i||!L(i,r)||e(e=>{let t=e.byRoot[r],n=z(t);return n.expandedPaths.includes(i)&&t?e:{byRoot:R({...e.byRoot,[r]:{...n,expandedPaths:[...n.expandedPaths,i]}},20)}})},expandPaths:(t,n)=>{let r=F((t||``).trim());if(!r||!n||n.length===0)return;let i=n.map(e=>F((e||``).trim())).filter(e=>e&&L(e,r));i.length!==0&&e(e=>{let t=e.byRoot[r],n=z(t),a=new Set(n.expandedPaths),o=i.filter(e=>!a.has(e));return o.length===0?e:{byRoot:R({...e.byRoot,[r]:{...n,expandedPaths:[...n.expandedPaths,...o]}},20)}})}}),{name:`files-view-tabs-store`,version:2,storage:v(),migrate:e=>{if(!e||typeof e!=`object`)return{byRoot:{}};let t=e.byRoot;return{byRoot:Ae(t)}},partialize:e=>({byRoot:Ae(e.byRoot)})}),{name:`files-view-tabs-store`})),B=b(),Me=(e,t)=>{let n=(0,B.c)(4),r=t===void 0?200:t,[i,a]=P.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]),P.useEffect(o,s),i},Ne=()=>{let e=(0,B.c)(17),t=E(Pe),n=O(),r;e[0]===t?r=e[1]:(r=e=>t?e.getAttachment(t):void 0,e[0]=t,e[1]=r);let i=oe(r),a=E(V),o=E(H),s=D(U),c=D(Fe),l=h(Ie);if(t){let r;e[2]===i?r=e[3]:(r=pe(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 Pe(e){return e.currentSessionId}function V(e){return e.worktreeMetadata}function H(e){return e.newSessionDraft}function U(e){return e.activeProjectId}function Fe(e){return e.projects}function Ie(e){return e.currentDirectory}var W=p(),Le=`bg-transparent font-[inherit] text-[var(--primary-base)]`,G=(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,W.jsx)(`mark`,{className:Le,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},Re=P.forwardRef(({searchQuery:e,onFileSelect:t,onAgentSelect:n,onSkillSelect:r,onSessionSelect:i,onClose:a,style:c,onRowsChange:l},u)=>{let{t:d}=te(),f=Ne()??``,p=E(e=>e.currentSessionId),m=ae(e=>e.activeSessions),h=re({enabled:!!i}),g=D(e=>e.activeProjectId),v=D(e=>e.projects),y=P.useMemo(()=>v.find(e=>e.id===g)?.path??null,[g,v]),b=P.useMemo(()=>{let e=y||f;return e?e.replace(/\\/g,`/`).replace(/\/+$/,``):null},[y,f]),x=je(e=>b?e.byRoot[b]:void 0),oe=k(e=>e.agents),w=_(e=>e.searchFiles),se=Me(e,180),le=s(),O=o(),[pe,ge]=P.useState([]),[_e,ve]=P.useState(!1),[j,M]=P.useState(0),N=P.useRef(0),we=P.useRef({query:e,directory:f,ids:[]}),[Te,Ee]=P.useState(360),[De,F]=P.useState({}),[I,L]=P.useState({}),Ae=P.useRef([]),R=P.useRef([]),z=P.useRef([]),B=P.useRef(null),Pe=P.useRef(null),V=P.useRef(null);V.current||=Ce();let H=ee(e=>e.isMobile),U=(e??``).trim(),Fe=T({directory:f||null}),Ie=P.useMemo(()=>r?Fe.data??[]:[],[r,Fe.data]),Le=P.useMemo(()=>{if(!b||!x)return[];let e=[x.selectedPath,...x.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(`${b}/`)?e.slice(b.length+1):e;n.push({name:i,path:e,relativePath:a,extension:i.includes(`.`)?i.split(`.`).pop()?.toLowerCase():void 0})}return fe(n,U,{limit:6})},[U,b,x]),Re=P.useMemo(()=>n?me(oe).filter(e=>e.mode!==`primary`):[],[oe,n]),ze=P.useMemo(()=>i?ce({sessions:ie(m,h),currentSessionId:p,searchQuery:U}):[],[m,p,h,U,i]),K=Le,Be=pe,q=P.useMemo(()=>be({skills:Ie,agents:Re,sessions:ze,recentFiles:K,pathHits:Be,searchQuery:U,untitledSession:d(`chat.fileMentionAutocomplete.untitledSession`),sessionBadge:d(`chat.fileMentionAutocomplete.sessionType`),skillBadge:d(`chat.commandAutocomplete.badge.skill`)}),[Ie,Re,ze,K,Be,U,d]);P.useEffect(()=>{let e=e=>{let t=e.target;!t||!B.current||B.current.contains(t)||a()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},[a]),P.useEffect(()=>{if(!f){ge([]);return}let e=(se??``).trim(),t=ue(e);if(!t){ge([]);return}let n=!1;ve(!0);let r={includeHidden:le,respectGitignore:!O};return Promise.all([w(f,t,80,{...r,type:`file`}),w(f,t,40,{...r,type:`directory`})]).then(([t,r])=>{if(n)return;let i=new Set(Le.map(e=>e.path));ge(de({files:t,directories:r,query:e,excludePaths:i,limit:20}))}).catch(()=>{n||ge([])}).finally(()=>{n||ve(!1)}),()=>{n=!0}},[f,se,Le,w,le,O]),P.useLayoutEffect(()=>{let t=we.current,n=t.ids[N.current],r=t.query===e&&t.directory===f?Math.max(0,q.findIndex(e=>e.id===n)):0;we.current={query:e,directory:f,ids:q.map(e=>e.id)},N.current=r,M(r)},[q,e,f]),P.useEffect(()=>{F({}),L({})},[q]),P.useEffect(()=>{Ae.current[j]?.scrollIntoView({block:`nearest`})},[j]),P.useEffect(()=>{let e=null,t=()=>{e!==null&&cancelAnimationFrame(e),e=requestAnimationFrame(()=>{let e={},t={};R.current.forEach((n,r)=>{if(!n)return;let i=z.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}}),F(e),L(t)})};return t(),window.addEventListener(`resize`,t),()=>{e!==null&&cancelAnimationFrame(e),window.removeEventListener(`resize`,t)}},[q]),P.useEffect(()=>{let e=R.current[j];if(!e)return;let t=()=>{let t=e.clientWidth;t>0&&Ee(t)};if(t(),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(t);return n.observe(e),()=>{n.disconnect()}},[j]);let Ve=S(e=>{t(e)}),He=S(e=>{n?.(e)}),Ue=S(e=>{i?.(e)}),We=S(e=>{r?.(e)}),Ge=(e,t)=>({onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{e.pointerType===`touch`&&V.current?.pointerDown(e.clientX,e.clientY)},onPointerMove:e=>{e.pointerType===`touch`&&V.current?.pointerMove(e.clientX,e.clientY)},onPointerUp:e=>{e.pointerType===`touch`&&(V.current?.pointerUp(t)??!1)&&(e.preventDefault(),e.stopPropagation())},onPointerCancel:()=>V.current?.pointerCancel(),onClick:()=>{V.current?.click(t)},onMouseMove:()=>{N.current=e,M(e)}}),J=e=>{let t=q.length;if(t===0)return;let n=(e%t+t)%t,r=q[n];if(r.agentName!==void 0){He(r.agentName);return}if(r.id.startsWith(`skill:`)){let e=Ie.find(e=>r.id===`skill:${e.name}-${e.scope}`);e&&We(e);return}if(r.id.startsWith(`session:`)){let e=ze.find(e=>r.id===`session:${e.id}`);e&&Ue(e);return}let i=r.id.startsWith(`recent:`)?K.find(e=>r.id===`recent:${e.path}`):Be.find(e=>r.id===`file:${e.path}`);i&&Ve(i)};P.useEffect(()=>{Oe(l,Pe,{rows:q,highlightedIndex:j})},[l,j,q]);let Ke=P.useRef(l);return Ke.current=l,P.useEffect(()=>()=>{ke(Ke.current,Pe)},[]),P.useImperativeHandle(u,()=>({acceptIndex:e=>{J(e)},handleKeyDown:e=>{if(e===`Escape`){a();return}let t=q.length;if(t!==0){if(e===`ArrowDown`){N.current=(N.current+1)%t,M(N.current);return}if(e===`ArrowUp`){N.current=(N.current-1+t)%t,M(N.current);return}(e===`Enter`||e===`Tab`)&&J(N.current)}}})),(0,W.jsxs)(xe,{ref:B,isMobile:H,className:`max-w-[640px] max-h-64`,style:c,children:[(0,W.jsx)(ye,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0`,children:(0,W.jsxs)(`div`,{className:`py-1`,children:[q.map((e,t)=>{let n=e.id.startsWith(`file:`)||e.id.startsWith(`recent:`),r=n?ne(e.title,{maxLength:60}):e.title,i=j===t,a=De[t]??!1,o=I[t]??2.6;return(0,W.jsxs)(`div`,{"data-mention-id":e.id,ref:e=>{Ae.current[t]=e},className:C(`flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,H&&`min-h-11`,Se(H,i),!H&&i&&`text-interactive-selection-foreground`),...Ge(t,()=>J(t)),children:[(0,W.jsx)(`span`,{className:`flex size-5 shrink-0 items-center justify-center`,children:e.agentName===void 0?(0,W.jsx)(A,{name:e.iconName,className:`size-3.5 text-current`}):(0,W.jsx)(he,{name:e.agentName,size:20})}),(0,W.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,W.jsxs)(`span`,{ref:e=>{R.current[t]=e},className:`relative block min-w-0 overflow-hidden file-mention-marquee-container`,style:i?{"--file-mention-marquee-width":`${Te}px`,"--file-mention-marquee-duration":`${o}s`}:void 0,title:e.title,children:[(0,W.jsx)(`span`,{ref:e=>{z.current[t]=e},className:`absolute invisible whitespace-nowrap pointer-events-none`,"aria-hidden":!0,children:e.title}),n&&a&&i?(0,W.jsx)(`span`,{className:`inline-block whitespace-nowrap file-mention-marquee`,children:G(e.title,U)}):(0,W.jsx)(`span`,{className:`block truncate`,children:G(r,U)})]}),e.subtitle?(0,W.jsx)(`div`,{className:C(`truncate text-muted-foreground`,H?`typography-micro`:`typography-meta`),children:G(e.subtitle,U)}):null]})]},e.id)}),_e&&Be.length===0?(0,W.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,W.jsx)(A,{name:`refresh`,className:`h-4 w-4 animate-spin text-muted-foreground`})}):null,!_e&&q.length===0&&(0,W.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:d(`chat.fileMentionAutocomplete.empty`)})]})}),!H&&(0,W.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:d(`chat.autocomplete.keyboardHint`)})]})}),ze=new Set([`new`,`fork`,`compact`,`reload`,`undo`,`redo`,`model`,`goal`,`btw`]),K=(e,t)=>{if(!t||e.isSkill)return!1;let n=e.name?.trim().toLowerCase();return!!(n&&ze.has(n))},Be=(e,t)=>!e||t({name:e}),q=` `,Ve=(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]===q&&e[r-2]===`/`&&(r-=2),e[r]===`/`?{start:r,end:n}:null},He=`text-[10px] leading-none uppercase font-bold tracking-tight px-1.5 py-1 rounded border flex-shrink-0`,Ue=C(He,`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)]`),We=C(He,`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)]`),Ge=C(He,`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)]`),J=C(He,`bg-[var(--surface-muted)] text-muted-foreground border-[var(--interactive-border)]/60`),Ke=(e,t)=>e.length===t.length&&e.every((e,n)=>e.id===t[n]?.id&&e.description===t[n]?.description),qe=(e,t)=>{let n=!!e.sessionID;return{hasSession:n,canStartSessionCommand:n||e.hasNewDraft,canUseReviewHandoffFlow:n&&!t&&!c()}},Je=P.forwardRef(({searchQuery:e,onCommandSelect:t,onClose:n,directory:r,style:i,commandPolicy:a,commandContext:o,onRowsChange:s},l)=>{let{t:u}=te(),d=ee(e=>e.isMobile),f=E(e=>e.currentSessionId),p=E(e=>!!e.newSessionDraft?.open),m=E(P.useCallback(e=>f?e.getDirectoryForSession(f):void 0,[f])),h=se(f??``,m??void 0),g=P.useMemo(()=>o??{sessionID:f??null,hasMessages:h.length>0,hasNewDraft:p},[o,f,h.length,p]),{hasSession:_,canStartSessionCommand:v,canUseReviewHandoffFlow:y}=P.useMemo(()=>qe(g,d),[g,d]),b=g.hasMessages,[x,S]=P.useState([]),[ne,re]=P.useState(!1),ie=le({directory:r}),ae=P.useMemo(()=>ie.data??[],[ie.data]),oe=ie.isFetching,[w,T]=P.useState(0),ce=P.useRef(0),D=P.useRef(!1),ue=P.useRef([]),de=P.useRef(null),fe=P.useRef(!1),O=P.useRef(null),k=P.useRef(!1),pe=P.useRef(null);P.useEffect(()=>{let e=e=>{let t=e.target;!t||!de.current||de.current.contains(t)||n()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},[n]),P.useEffect(()=>{(async()=>{re(oe);try{let t=ae.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},..._&&!b?[{id:`yuri:init`,name:`init`,source:`yuri`,description:u(`chat.commandAutocomplete.command.initDescription`),isBuiltIn:!0}]:[],..._?[{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},...c()?[{id:`yuri:reload`,name:`reload`,source:`yuri`,description:u(`chat.commandAutocomplete.command.reloadDescription`),isBuiltIn:!0}]:[],..._?[{id:`yuri:summary`,name:`summary`,source:`yuri`,description:u(`chat.commandAutocomplete.command.summaryDescription`),isYuri:!0}]:[],...v?[{id:`yuri:workspace-review`,name:`workspace-review`,source:`yuri`,description:u(`chat.commandAutocomplete.command.workspaceReviewDescription`),isYuri:!0}]:[],...y?[{id:`yuri:handoff-review`,name:`handoff-review`,source:`yuri`,description:u(`chat.commandAutocomplete.command.handoffReviewDescription`),isYuri:!0}]:[],...v?[{id:`yuri:craft-goal`,name:`craft-goal`,source:`yuri`,description:u(`chat.commandAutocomplete.command.craftGoalDescription`),isYuri:!0}]:[],...v?[{id:`yuri:goal`,name:`goal`,source:`yuri`,description:u(`chat.goal.button.armAria`),isBuiltIn:!0}]:[],...v?[{id:`yuri:catch-up`,name:`catch-up`,source:`yuri`,description:u(`chat.commandAutocomplete.command.catchUpDescription`),isYuri:!0}]:[],...v?[{id:`yuri:debug`,name:`debug`,source:`yuri`,description:u(`chat.commandAutocomplete.command.debugDescription`),isYuri:!0}]:[],...v?[{id:`yuri:weigh`,name:`weigh`,source:`yuri`,description:u(`chat.commandAutocomplete.command.weighDescription`),isYuri:!0}]:[],...v?[{id:`yuri:explore`,name:`explore`,source:`yuri`,description:u(`chat.commandAutocomplete.command.exploreDescription`),isYuri:!0}]:[],...t],r=!b,i=we(n.filter(e=>(r||e.name!==`init`)&&(a?.(e)??!0)),e);S(e=>Ke(e,i)?e:i)}catch{let t=!b,n=we([{id:`yuri:new`,name:`new`,source:`yuri`,description:u(`chat.commandAutocomplete.command.newDescription`),isBuiltIn:!0},..._&&!b?[{id:`yuri:init`,name:`init`,source:`yuri`,description:u(`chat.commandAutocomplete.command.initDescription`),isBuiltIn:!0}]:[],..._?[{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},...c()?[{id:`yuri:reload`,name:`reload`,source:`yuri`,description:u(`chat.commandAutocomplete.command.reloadDescription`),isBuiltIn:!0}]:[],..._?[{id:`yuri:summary`,name:`summary`,source:`yuri`,description:u(`chat.commandAutocomplete.command.summaryDescription`),isYuri:!0}]:[],...v?[{id:`yuri:workspace-review`,name:`workspace-review`,source:`yuri`,description:u(`chat.commandAutocomplete.command.workspaceReviewDescription`),isYuri:!0}]:[],...y?[{id:`yuri:handoff-review`,name:`handoff-review`,source:`yuri`,description:u(`chat.commandAutocomplete.command.handoffReviewDescription`),isYuri:!0}]:[],...v?[{id:`yuri:craft-goal`,name:`craft-goal`,source:`yuri`,description:u(`chat.commandAutocomplete.command.craftGoalDescription`),isYuri:!0}]:[],...v?[{id:`yuri:goal`,name:`goal`,source:`yuri`,description:u(`chat.goal.button.armAria`),isBuiltIn:!0}]:[],...v?[{id:`yuri:catch-up`,name:`catch-up`,source:`yuri`,description:u(`chat.commandAutocomplete.command.catchUpDescription`),isYuri:!0}]:[],...v?[{id:`yuri:debug`,name:`debug`,source:`yuri`,description:u(`chat.commandAutocomplete.command.debugDescription`),isYuri:!0}]:[],...v?[{id:`yuri:weigh`,name:`weigh`,source:`yuri`,description:u(`chat.commandAutocomplete.command.weighDescription`),isYuri:!0}]:[],...v?[{id:`yuri:explore`,name:`explore`,source:`yuri`,description:u(`chat.commandAutocomplete.command.exploreDescription`),isYuri:!0}]:[]].filter(e=>(t||e.name!==`init`)&&(a?.(e)??!0)),e);S(e=>Ke(e,n)?e:n)}finally{re(!1)}})()},[e,b,_,v,y,ae,oe,u,a]),P.useEffect(()=>{T(0)},[x]),P.useEffect(()=>{ce.current=w},[w]),P.useEffect(()=>{ue.current[w]?.scrollIntoView({block:`nearest`})},[w]),P.useEffect(()=>{Oe(s,pe,{rows:N(x,{skill:u(`chat.commandAutocomplete.badge.skill`),command:u(`chat.commandAutocomplete.badge.command`),system:u(`chat.commandAutocomplete.badge.system`)}),highlightedIndex:w})},[x,s,w,u]);let me=P.useRef(s);me.current=s,P.useEffect(()=>()=>{ke(me.current,pe)},[]),P.useImperativeHandle(l,()=>({acceptIndex:(e,n=!0)=>{let r=x[e];r&&t(r,K(r,n))},handleKeyDown:e=>{let r=x.length;if(e===`Escape`){n();return}if(r!==0){if(e===`ArrowDown`){D.current=!0,T(e=>(e+1)%r);return}if(e===`ArrowUp`){D.current=!0,T(e=>(e-1+r)%r);return}if(e===`Enter`||e===`Tab`){let n=(ce.current%r+r)%r,i=x[n];i&&t(i,K(i,e===`Enter`))}}}}),[x,n,t]);let he=e=>{let t=M(e);switch(e.name){case`new`:return(0,W.jsx)(A,{name:t,className:`h-3.5 w-3.5`});case`init`:return(0,W.jsx)(A,{name:t,className:`h-3.5 w-3.5 text-green-500`});case`undo`:return(0,W.jsx)(A,{name:t,className:`h-3.5 w-3.5 text-orange-500`});case`redo`:return(0,W.jsx)(A,{name:t,className:`h-3.5 w-3.5 text-orange-500`});case`timeline`:case`reload`:return(0,W.jsx)(A,{name:t,className:`h-3.5 w-3.5`});case`compact`:return(0,W.jsx)(A,{name:t,className:`h-3.5 w-3.5 text-purple-500`});case`goal`:return(0,W.jsx)(A,{name:t,className:`h-3.5 w-3.5`});case`review`:return(0,W.jsx)(A,{name:t,className:`h-3.5 w-3.5 text-blue-500`});case`test`:case`build`:case`run`:return(0,W.jsx)(A,{name:t,className:`h-3.5 w-3.5 text-cyan-500`});default:return e.isBuiltIn?(0,W.jsx)(A,{name:t,className:`h-3.5 w-3.5 text-yellow-500`}):(0,W.jsx)(A,{name:t,className:`h-3.5 w-3.5 text-muted-foreground`})}};return(0,W.jsxs)(xe,{ref:de,isMobile:d,className:`max-w-[450px] max-h-64`,style:i,children:[(0,W.jsx)(ye,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0 py-1.5`,children:ne?(0,W.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,W.jsx)(A,{name:`refresh`,className:`h-4 w-4 animate-spin text-muted-foreground`})}):(0,W.jsxs)(`div`,{children:[x.map((n,r)=>{let i=n.isBuiltIn,a=n.isYuri;return(0,W.jsxs)(`div`,{ref:e=>{ue.current[r]=e},className:C(`flex gap-2 px-2 py-2 cursor-pointer rounded-lg`,d?`items-center`:`items-start`,Se(d,r===w),!d&&r===w&&`bg-interactive-selection/35`),onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{e.pointerType===`touch`&&(O.current={x:e.clientX,y:e.clientY},k.current=!1)},onPointerMove:e=>{if(e.pointerType!==`touch`||!O.current)return;let t=e.clientX-O.current.x,n=e.clientY-O.current.y;Math.hypot(t,n)>6&&(k.current=!0)},onPointerUp:e=>{if(e.pointerType!==`touch`)return;let r=k.current;O.current=null,k.current=!1,!r&&(e.preventDefault(),e.stopPropagation(),fe.current=!0,t(n,K(n,d)))},onPointerCancel:()=>{O.current=null,k.current=!1},onClick:()=>{if(fe.current){fe.current=!1;return}t(n,K(n,d))},onMouseMove:()=>{D.current=!1,T(r)},children:[(0,W.jsx)(`div`,{className:C(!d&&`mt-0.5`),children:he(n)}),(0,W.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsxs)(`span`,{className:`typography-ui-label font-medium`,children:[`/`,G(n.name,e)]}),n.isSkill?(0,W.jsx)(`span`,{className:Ue,children:u(`chat.commandAutocomplete.badge.skill`)}):(0,W.jsx)(`span`,{className:Ue,children:u(`chat.commandAutocomplete.badge.command`)}),a?(0,W.jsx)(`span`,{className:J,children:`Yuri`}):i?(0,W.jsx)(`span`,{className:J,children:u(`chat.commandAutocomplete.badge.system`)}):n.scope?(0,W.jsx)(`span`,{className:n.scope===`project`?Ge:We,children:n.scope}):null,n.agent&&(0,W.jsx)(`span`,{className:J,children:n.agent})]}),n.description&&!d&&(0,W.jsx)(`div`,{className:`typography-meta text-muted-foreground mt-0.5 truncate`,children:G(n.description,e)})]})]},n.id)}),x.length===0&&(0,W.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:u(`chat.commandAutocomplete.empty`)})]})}),!d&&(0,W.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:u(`chat.autocomplete.keyboardHint`)})]})});Je.displayName=`CommandAutocomplete`;var Ye=2,Xe=e=>!!e&&typeof e==`object`&&!Array.isArray(e),Ze=e=>{let t=e?.trim().replace(/\\/g,`/`);return t?t.length>1?t.replace(/\/+$/,``):t:null},Qe=e=>Xe(e)&&Array.isArray(e.all)&&e.all.every(e=>typeof e==`string`)&&typeof e.current==`string`&&Xe(e.branches),Y=(e,t)=>JSON.stringify([e,t]),$e=e=>`version`in e&&e.version===Ye&&Xe(e.entries),et=e=>{if(!e)return null;try{let t=JSON.parse(e);return Xe(t)?t.version===Ye&&Xe(t.entries)?{version:Ye,entries:t.entries}:t:null}catch{return null}},tt=(e,t)=>{try{e.setItem(`yuri.gitBranchCache`,JSON.stringify(t))}catch{}},nt=(e,t,n)=>{let r=Ze(e);if(!r||!t)return null;let i;try{i=n.getItem(`yuri.gitBranchCache`)}catch{return null}let a=et(i);if(!a)return null;if($e(a))return Qe(a.entries[Y(t,r)])?a.entries[Y(t,r)]:null;let o={};for(let[e,n]of Object.entries(a)){let r=Ze(e);r&&Qe(n)&&(o[Y(t,r)]=n)}return tt(n,{version:Ye,entries:o}),o[Y(t,r)]??null},rt=(e,t,n,r)=>{let i=Ze(e);if(!i||!t||!Qe(n))return;let a=null;try{a=r.getItem(`yuri.gitBranchCache`)}catch{return}let o=et(a);tt(r,{version:Ye,entries:{...o&&$e(o)?o.entries:{},[Y(t,i)]:n}})},it=3e4,X=Ze,at=(e,t=n())=>i.git.branches(X(e),t),ot=(e,t=n())=>i.git.remotes(X(e),t),st=async(e,t,n)=>{n.throwIfAborted();let r=a()?.git,i=t?.getGitBranches?await t.getGitBranches(e,{signal:n}):r?await r.getGitBranches(e,{signal:n}):await g(e,{signal:n});return n.throwIfAborted(),i},ct=async(e,t,n)=>{n.throwIfAborted();let r=a()?.git,i=t?.getRemotes?await t.getRemotes(e,{signal:n}):r?await r.getRemotes(e,{signal:n}):await m(e,{signal:n});return n.throwIfAborted(),i},lt=(e,t,r=n(),i=y())=>{let a=X(e),o=t;return{queryKey:at(a,r),queryFn:async({signal:e})=>{if(!a)throw Error(`Git branches require a directory`);let t=await st(a,o,e);return rt(a,r,t,i),t},staleTime:it,gcTime:1/0,initialData:()=>nt(a,r,i)??void 0,initialDataUpdatedAt:0}},ut=(e,t,r=n())=>{let i=X(e),a=t;return{queryKey:ot(i,r),queryFn:({signal:e})=>{if(!i)throw Error(`Git remotes require a directory`);return ct(i,a,e)},staleTime:it,gcTime:1/0}},dt=(e,r,i)=>{let a=(0,B.c)(9),o=i===void 0||i,s=P.useSyncExternalStore(t,n,n),c,l,u;a[0]!==e||a[1]!==r||a[2]!==s?(c=X(e),u=x,l=lt(c,r,s),a[0]=e,a[1]=r,a[2]=s,a[3]=c,a[4]=l,a[5]=u):(c=a[3],l=a[4],u=a[5]);let d=o&&!!c,f;return a[6]!==l||a[7]!==d?(f={...l,enabled:d},a[6]=l,a[7]=d,a[8]=f):f=a[8],u(f)},ft=(e,r,i)=>{let a=(0,B.c)(9),o=i===void 0||i,s=P.useSyncExternalStore(t,n,n),c,l,u;a[0]!==e||a[1]!==r||a[2]!==s?(c=X(e),u=x,l=ut(c,r,s),a[0]=e,a[1]=r,a[2]=s,a[3]=c,a[4]=l,a[5]=u):(c=a[3],l=a[4],u=a[5]);let d=o&&!!c,f;return a[6]!==l||a[7]!==d?(f={...l,enabled:d},a[6]=l,a[7]=d,a[8]=f):f=a[8],u(f)},pt=(e,t,i=r,a=n())=>i.fetchQuery(lt(e,t,a)),mt=(e,t,i=r,a=n())=>i.fetchQuery({...lt(e,t,a),staleTime:0}),ht=e=>e instanceof Error?e.name===`AbortError`||e.name===`CancelledError`||e.name===`Error`&&e.message===`CancelledError`:!1,gt=1e4,_t=6e4,vt=5e3,yt=3e4,bt=6e4,xt=25,St=40,Ct=2,wt=15e3,Tt=500,Et=30,Dt=20971520,Ot=new Map,kt=new Map,At=new Map,jt=new Map,Mt=new Map,Nt=(e,t)=>`${t}:${e}`,Pt=e=>kt.get(e)??0,Ft=e=>{let t=Pt(e)+1;return kt.set(e,t),t},It=e=>{let t=(At.get(e)??0)+1;return At.set(e,t),t},Lt=e=>{let t=Ot.get(e);if(t)return t;let n=new Set;return Ot.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}),Rt=(e,t=Et,n=Dt)=>{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},zt=(e,t)=>{if(!e&&!t)return!1;if(!e||!t)return!0;let n=new Set([...Object.keys(e),...Object.keys(t)]);for(let r of n){let n=e[r],i=t[r];if(!(!n&&!i)&&(!n||!i||n.insertions!==i.insertions||n.deletions!==i.deletions))return!0}return!1},Bt=(e,t)=>!e&&!t?!1:!e||!t||e.remote!==t.remote||e.branch!==t.branch||e.ahead!==t.ahead||e.behind!==t.behind,Vt=(e,t)=>{if(!e&&!t)return!1;if(!e||!t)return!0;let n=e.files??[],r=t.files??[];if(n.length!==r.length||e.ahead!==t.ahead||e.behind!==t.behind||e.current!==t.current||e.tracking!==t.tracking||e.isClean!==t.isClean||t.upstreamComparison!==void 0&&Bt(e.upstreamComparison,t.upstreamComparison))return!0;let i=new Set(n.map(e=>`${e.path}:${e.index}:${e.working_dir}`));for(let e of r)if(!i.has(`${e.path}:${e.index}:${e.working_dir}`))return!0;return!!(t.diffStats!==void 0&&zt(e.diffStats,t.diffStats))},Ht=(e,t)=>{let n=new Set;if(!t)return n;let r=e?.files??[],i=t.files??[],a=new Map(r.map(e=>[e.path,e])),o=new Map(i.map(e=>[e.path,e])),s=new Set([...a.keys(),...o.keys()]);for(let e of s){let t=a.get(e),r=o.get(e);if(!t||!r){n.add(e);continue}if(t.index!==r.index||t.working_dir!==r.working_dir){n.add(e);continue}}if(t.diffStats!==void 0){let r=e?.diffStats??{},i=t.diffStats??{},a=new Set([...Object.keys(r),...Object.keys(i)]);for(let e of a){let t=r[e],a=i[e];if(!t||!a){n.add(e);continue}(t.insertions!==a.insertions||t.deletions!==a.deletions)&&n.add(e)}}return n},Ut=(e,t)=>{if(!e&&!t)return!1;if(!e||!t)return!0;let n=e.files??[],r=t.files??[],i=e=>{let t=e?.trim()??``;return t===`?`?``:t},a=new Map(n.map(e=>[e.path,i(e.index)])),o=new Map(r.map(e=>[e.path,i(e.index)])),s=new Set([...a.keys(),...o.keys()]);for(let e of s)if((a.get(e)??``)!==(o.get(e)??``))return!0;return!1},Wt=e=>!e||e.trim().length===0,Gt=e=>(e||``).trim()===`U`,Kt=e=>{let t=(e.index||``).trim(),n=(e.working_dir||``).trim();if(Gt(t)||Gt(n))return e;let r=t===`?`||n===`?`?`A`:t||n||` `;return{...e,index:r,working_dir:` `}},qt=e=>{let t=(e.index||``).trim(),n=(e.working_dir||``).trim();if(Gt(t)||Gt(n))return e;let r=n||(t===`A`||t===`?`?`?`:t)||` `;return{...e,index:` `,working_dir:r}},Jt=e=>Wt(e.index)&&Wt(e.working_dir),Q=l()(d((e,t)=>({directories:new Map,activeDirectory:null,setActiveDirectory:n=>{let{activeDirectory:r,directories:i}=t();if(r!==n)if(r&&Ft(r),n&&Ft(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=Nt(n,a),s=jt.get(o)??(a===`light`?jt.get(Nt(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)>_t,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);if(Vt(s.status,u)){c=!0;let r=new Map(t().directories),i=r.get(n)??Z(),s=Ht(i.status,u),l=Ut(i.status,u),d=new Set((i.status?.files??[]).map(e=>e.path)),f=new Set((u.files??[]).map(e=>e.path)),p=new Map(i.diffCache);for(let e of d)f.has(e)||p.delete(e);for(let e of s)p.delete(e);let m=s.size>0;m&&Ft(n);let h={...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:h,diffCache:p,indexRevision:l?i.indexRevision+1:i.indexRevision,lastRepoCheckAt:o?a:i.lastRepoCheckAt,lastStatusFetch:Date.now(),lastStatusChange:m?Date.now():i.lastStatusChange}),e({directories:r})}else{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})();jt.set(o,c);try{return await c}finally{jt.get(o)===c&&jt.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`?Kt(e):qt(e);t!==e&&(l=!0),Jt(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=It(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 mt(r,i,void 0,o):await pt(r,i,void 0,o);if(s!==At.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(ht(i)||console.error(`Failed to fetch git branches:`,i),s!==At.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>gt||!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=Rt(s);a.set(n,{...o,diffCache:c}),e({directories:a})},clearDiffCache:n=>{Ft(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,xt);await t().prefetchDiffs(e,n,i,{maxFiles:xt})},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=St}=a,c=new Set(o.status.files.map(e=>e.path)),l=o.status.diffStats,u=Lt(n),d=[],f=new Set;for(let e of i){if(!e||f.has(e)||(f.add(e),!c.has(e))||o.diffCache.has(e)||u.has(e))continue;let t=l?.[e];t&&t.insertions+t.deletions>Tt||d.push(e)}let p=d.slice(0,Math.max(1,s));if(p.length===0)return;let m=Pt(n);if(typeof document<`u`&&document.hidden)return;p.forEach(e=>u.add(e));let h=0,g=[],_=()=>{let e=h;return h+=1,e<p.length?p[e]:null},v=async e=>{let t=r.getGitFileDiff(n,{path:e}),i=new Promise((e,t)=>{setTimeout(()=>t(Error(`Timed out after ${wt}ms`)),wt)}),a=await Promise.race([t,i]);return{path:e,diff:{original:a.original??``,modified:a.modified??``,isBinary:a.isBinary}}},ee=async()=>{for(;;){if(m!==Pt(n))return;let e=_();if(!e)return;try{g.push(await v(e))}catch{}finally{u.delete(e)}}},y=Math.min(Ct,p.length);if(await Promise.allSettled(Array.from({length:y},()=>ee())),p.forEach(e=>u.delete(e)),m!==Pt(n))return;let b=new Map(t().directories),x=b.get(n);if(!x)return;let S=new Map(x.diffCache),te=Date.now();g.forEach(e=>{!e.diff.isBinary&&e.diff.original===``&&e.diff.modified===``||S.set(e.path,{...e.diff,fetchedAt:te})});let C=Rt(S);b.set(n,{...x,diffCache:C}),e({directories:b})},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<vt||await t().fetchStatus(e,n,{silent:!!r?.status})},ensureAll:(e,n)=>{let r=Mt.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)>=vt)&&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>=yt)&&o.push(t().fetchBranches(e,n)),(!a.log||i-a.lastLogFetch>=gt)&&o.push(t().fetchLog(e,n)),(!a.identity||i-a.lastIdentityFetch>=bt)&&o.push(t().fetchIdentity(e,n)),o.length>0&&await Promise.all(o)})();return Mt.set(e,i),i.finally(()=>{Mt.get(e)===i&&Mt.delete(e)}),i},refresh:async(e,n={})=>{let{activeDirectory:r}=t();r&&await t().fetchAll(r,e,n)}}),{name:`git-store`})),Yt=e=>{let t=(0,B.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)},Xt=e=>{let r=(0,B.c)(3),i=P.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)},Zt=e=>{let t=(0,B.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)},Qt=e=>{let t=(0,B.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)},$t=e=>{let t=(0,B.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)},en=e=>{let t=(0,B.c)(3),n;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(n=new Map,t[0]=n):n=t[0];let r=P.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)},tn=e=>{let t=(0,B.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)},nn=e=>{let t=(0,B.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)},rn=e=>{let t=(0,B.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)},an=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\//,``),on=e=>e.branchName?$(e.branchName):e.mode===`existing`?$(e.existingBranch||e.preferredName||``):$(e.preferredName||``),sn=async e=>{let t=await ve(e);try{let n=an((await ge(e)).branches?.[t]?.tracking||null);if(n?.remote)return n.remote}catch{}try{let t=an((await _e(e)).tracking);if(t?.remote)return t.remote}catch{}return null},cn=async(e,t)=>{let n=await sn(e),r=$(t);return!n||!r?null:{setUpstream:!0,upstreamRemote:n,upstreamBranch:r}},ln=async(e,t,n)=>{let r=on(t),i=n?.resolvedRootTrackingRemote,a=i===void 0?await cn(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},un=async(e,t,n)=>{let r=await ln(e.path,t,n);return j(e,r)},dn=`yuri:lastWorktreeSourceBranch`,fn=({mode:e,sourceBranch:t,linkedPr:n,selectedBranch:r})=>e===`existing-branch`?r||null:n?null:t||null,pn=({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},mn=(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?` `:``}`},hn=(e,t,n)=>{let r=mn(e,t,n);return`${t.length===0&&!/^\s/.test(r)?` `:``}${r}${n.length===0&&!/\s$/.test(r)?` `:``}`},gn=(e,t,n,r)=>{let i=e.slice(0,t),a=e.slice(n),o=hn(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}},_n=(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]},vn=(e,t)=>t<e.length&&e[t]===` `?t+1:t;export{je as A,ft as C,Re as D,Be as E,Ne as O,dt as S,Ve as T,en as _,dn as a,Qt as b,un as c,$t as d,Xt as f,Zt as g,tn as h,hn as i,De as j,Me as k,sn as l,nn as m,_n as n,pn as o,rn as p,gn as r,fn as s,vn as t,ln as u,Yt as v,Je as w,mt as x,Q as y};
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-workbox-window-15MWHJyx.js","assets/rolldown-runtime-hePW80VL.js","assets/renderMobileApp-BlCyG-WF.js","assets/runtime-auth-ef9W7A43.js","assets/runtime-switch-CAZiOV2G.js","assets/queryRuntime-DKGLQtb9.js","assets/vendor-tanstack-query-core-BWz0ose6.js","assets/persistence-Dzooc9Xg.js","assets/vendor-zustand-o69pgTEK.js","assets/vendor-base-ui-CdzJ6My_.js","assets/brand-storage-bootstrap-D4BW3w-M.js","assets/brand-storage-migration-Bhz6UOBJ.js","assets/useUIStore-NMQx_cnG.js","assets/vendor-react-BP2cRVqX.js","assets/vendor-pathe-vBmvQE8f.js","assets/platform-7bX6qtBV.js","assets/vendor-opencode-client-MF2GBrFx.js","assets/runtime-file-resource-C1k5nbWb.js","assets/vendor-tanstack-react-query-CdqCAt40.js","assets/vendor-aparajita-capacitor-secure-storage-xol_6BsB.js","assets/capgoAdapter-ChF9Cg3G.js","assets/types-DZcrt4Z0.js","assets/vendor-pierre-diffs-DPBtNDJ5.js","assets/vendor-hast-util-to-html-Bw_SgZ1t.js","assets/vendor-character-entities-legacy-Wut6vMuj.js","assets/vendor-character-entities-html4-DlN_yAFd.js","assets/vendor-ccount-CyGsA0u7.js","assets/vendor-comma-separated-tokens-B9ouxNNS.js","assets/vendor-oniguruma-to-es-CrHzjjSU.js","assets/vendor-oniguruma-parser-D2DIvhSP.js","assets/vendor-diff-Dq7CZNim.js","assets/vendor-lru_map-BMOrLc9L.js","assets/vendor-sonner-ZS8XIOVl.js","assets/vendor-reactuses-core-BpfIZ1tg.js","assets/vendor-lodash-es-DfLbG5Af.js","assets/vendor-js-cookie-hSOiFTtX.js","assets/button-_ReBqWzC.js","assets/store-szlu5Wxv.js","assets/vendor-class-variance-authority-BLUaYARZ.js","assets/vendor-tailwind-merge-BicNWLTg.js","assets/MobileShareBridge-DLPBToEM.js","assets/MobileDetailNavigation-DACAHTpS.js","assets/useMobileNavigationStore-DcG6Ukmu.js","assets/useAssistantUIStore-D7JZlg_Q.js","assets/vendor-zod-Dzk5kdUU.js","assets/vendor-fuse.js-DB5wDJbI.js","assets/Icon-2cKLcXGe.js","assets/AgentAvatar-D6H7fWWf.js","assets/agentColors-DWSbQXy2.js","assets/vendor-dicebear-core-CV95S5Pg.js","assets/vendor-dicebear-styles-7lEG-JsF.js","assets/dualLimitLru-D8Sphgua.js","assets/useThemeSystem-8jhE4Zyk.js","assets/dialog-NsOVcGdh.js","assets/rasterizePng-056Poix7.js","assets/gitApi-BN0aozGg.js","assets/useAppFontEffects-DUPuwJH5.js","assets/desktopHosts-BDyl2P7W.js","assets/desktopRelayRestore-C_23nlKD.js","assets/vendor-simplewebauthn-browser-Dwhcdg_5.js","assets/projectMeta-B5lVMdxF.js","assets/input-BI3Ya8O_.js","assets/tooltip-C73L9gDf.js","assets/OverlayScrollbar-piA-chKb.js","assets/textarea-C5vjnZcE.js","assets/vendor-framer-motion-D-oiwsxL.js","assets/MobileWindowStack-DGLdgoGr.js","assets/vendor-dnd-kit-core-5pNnzVdw.js","assets/vendor-dnd-kit-accessibility-COSwgjFs.js","assets/vendor-dnd-kit-sortable-Dm50I0m7.js","assets/speechSettingsQueries-DFAUd_Aw.js","assets/dropdown-menu.styles-CjPDePJF.js","assets/image-loading-23c-W-bq.js","assets/image-loading-D9Z_BASK.css","assets/sessionChangeSummary-DN7H-rqE.js","assets/LoadingImage-B-cD_lfU.js","assets/ImageLoadingPlaceholder-DmCEIw55.js","assets/sessionChangeSummary-CRYRvpy7.css","assets/fileMentionTouchSelection-Bip-B2J9.js","assets/vendor-fuzzysort-ukaRp9PC.js","assets/insertionBoundaries-gfsrexDz.js","assets/appThemeRegistry-U9eZywBt.js","assets/MarkdownRenderer-BY7SOGeo.js","assets/useEffectiveDirectory-DXPmcf8E.js","assets/markdownHeightCache-CHFSvA8u.js","assets/url-Be8VCT8M.js","assets/markdown-worker-CkO3sT4Y.js","assets/FadeInOnReveal-eVZbrwte.js","assets/useWorkerHighlightedLines-BnmJy3ZO.js","assets/vendor-tanstack-react-virtual-B_EO--9t.js","assets/markdownTheme-DHoKvD6O.js","assets/vendor-cmdk-RDxC-9Iz.js","assets/vendor-aria-hidden-BbL3cEyI.js","assets/sortable-tabs-strip-Benojjgi.js","assets/vendor-motion-88WXBOBf.js","assets/useFontPreferences-D9PX5t6Y.js","assets/terminalApi-BHXvha-U.js","assets/MobileTabPageHeader-CvtrPaC2.js","assets/vendor-codemirror-autocomplete-7c2L_4dM.js","assets/vendor-codemirror-lang-angular-DXOgWEVj.js","assets/vendor-codemirror-lang-json-mLulNbwB.js","assets/vendor-codemirror-lang-markdown-CV1IO6Qs.js","assets/vendor-codemirror-lang-python-YM2WVLHF.js","assets/vendor-codemirror-legacy-modes-DwltVFbT.js","assets/mcpQueries-DJCrzyc3.js","assets/collapsible-BRKOX_ML.js","assets/vendor-codemirror-commands-B8KrBQ9B.js","assets/vendor-codemirror-search-ZqtrPLjU.js","assets/vendor-replit-codemirror-vim-DDj0dSVY.js","assets/vendor-codemirror-language-data-Ctd4WxgW.js","assets/projectActions-BX0cjZoq.js","assets/runtimeEndpointReset-DrO__UOn.js","assets/scheduledTaskNavigation-DUskP6qh.js","assets/mobileBackNavigation-B1NT3K0K.js","assets/sessionLookup-DezY-ONT.js","assets/vendor-cron-parser-BmO80h0C.js","assets/runtimeEndpointReset-DmY_4gYI.css","assets/SettingsView-pRXWe1jD.js","assets/native-config-D9DfX51I.js","assets/vendor-yaml-C9KlJAlj.js","assets/vendor-qrcode-D7jBCyl-.js","assets/vendor-dijkstrajs-BAzPDGZM.js","assets/AssistantView-CLk1T4Of.js","assets/assistant-attachment-cache-CLnqffXU.js","assets/renderMobileApp-1G4-5u-t.css","assets/src-CmermOKP.css","assets/main-CjjADMt-.js","assets/useDesktopWindowControlsLayout-Co_z6hbP.js","assets/diagram-C9F3kAJt.js","assets/vendor-react-drawio-Ck9ZKdNN.js","assets/multirun-D2KlubbP.js","assets/vendor-zumer-snapdom-yq9vlCKr.js","assets/vendor-html-to-image-BDMm2v6d.js","assets/main-qSeeJRW1.css"])))=>i.map(i=>d[i]);
2
- import{n as e,t}from"./runtimeConfig-MKo97i27.js";import{o as n}from"./vendor-aparajita-capacitor-secure-storage-xol_6BsB.js";/* empty css */var r=`true`,i=`false`,a=r===`true`,o=i===`true`;function s(e={}){let{immediate:t=!1,onNeedReload:r,onNeedRefresh:i,onOfflineReady:s,onRegistered:c,onRegisteredSW:l,onRegisterError:u}=e,d,f,p,m=async(e=!0)=>{await f,a||p?.()};async function h(){if(`serviceWorker`in navigator){if(d=await n(async()=>{let{Workbox:e}=await import(`./vendor-workbox-window-15MWHJyx.js`).then(e=>e.t);return{Workbox:e}},__vite__mapDeps([0,1])).then(({Workbox:e})=>new e(`/sw.js`,{scope:`/`,type:`classic`})).catch(e=>{u?.(e)}),!d)return;if(p=()=>{d?.messageSkipWaiting()},!o)if(a)d.addEventListener(`activated`,e=>{(e.isUpdate||e.isExternal)&&(r?r():window.location.reload())}),d.addEventListener(`installed`,e=>{e.isUpdate||s?.()});else{let e=!1,t=()=>{e=!0,d?.addEventListener(`controlling`,e=>{e.isUpdate&&(r?r():window.location.reload())}),i?.()};d.addEventListener(`installed`,n=>{n.isUpdate===void 0?n.isExternal===void 0?!e&&s?.():n.isExternal?t():!e&&s?.():n.isUpdate||s?.()}),d.addEventListener(`waiting`,t)}d.register({immediate:t}).then(e=>{l?l(`/sw.js`,e):c?.(e)}).catch(e=>{u?.(e)})}}return f=h(),m}window.__YURI_RUNTIME_APIS__=t();var c=()=>typeof window>`u`||typeof window.matchMedia!=`function`?!1:window.matchMedia(`(pointer: coarse)`).matches,l=(()=>{let e=new URLSearchParams(window.location.search).get(`surface`);if(e===`mobile`)return`mobile`;if(e===`desktop`)return`desktop`;let t=Math.min(window.innerWidth||0,window.screen?.width||window.innerWidth||0),n=navigator.maxTouchPoints||0;return t>0&&t<=760&&(n>0||c())?`mobile`:`desktop`})();window.__YURI_SURFACE__=l;var u=()=>!(!(`serviceWorker`in navigator)||!window.isSecureContext||window.location.protocol!==`http:`&&window.location.protocol!==`https:`||document.prerendering||String(document.visibilityState)===`prerender`),d=e=>{let t=!1,n=()=>{t||u()&&(t=!0,e())},r=()=>{setTimeout(n,0)};document.readyState===`complete`?r():window.addEventListener(`load`,r,{once:!0}),(document.prerendering||String(document.visibilityState)===`prerender`)&&document.addEventListener(`visibilitychange`,n,{once:!0})},f=()=>{d(()=>{try{s({onRegisterError(e){console.warn(`[PWA] service worker registration skipped:`,e)}})}catch(e){console.warn(`[PWA] service worker registration skipped:`,e)}})},p=`yuri.dev.module-reload`,m=(e,t)=>{console.error(`[yuri] failed to load ${t}:`,e)};l===`mobile`?n(async()=>{let{renderMobileApp:e}=await import(`./renderMobileApp-BlCyG-WF.js`);return{renderMobileApp:e}},__vite__mapDeps([2,1,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125])).then(({renderMobileApp:e})=>{try{sessionStorage.removeItem(p)}catch{}e(window.__YURI_RUNTIME_APIS__??t())}).catch(e=>m(e,`renderMobileApp`)):e().then(()=>n(()=>import(`./main-CjjADMt-.js`),__vite__mapDeps([126,1,3,4,5,6,7,8,9,10,11,12,13,14,57,15,16,17,18,19,96,21,98,22,23,24,25,26,27,28,29,30,31,33,34,35,36,37,38,39,41,42,32,43,44,45,46,52,53,55,56,58,48,51,47,49,50,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,54,82,83,84,85,86,87,88,89,90,91,92,93,94,95,97,99,100,101,102,103,104,105,106,107,108,109,110,127,111,112,113,114,115,116,128,129,130,131,132,133,125]))).then(()=>{try{sessionStorage.removeItem(p)}catch{}}).catch(e=>m(e,`desktop main`)),f();
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-workbox-window-15MWHJyx.js","assets/rolldown-runtime-hePW80VL.js","assets/renderMobileApp-DUiUPyd7.js","assets/runtime-auth-ef9W7A43.js","assets/runtime-switch-CAZiOV2G.js","assets/queryRuntime-DKGLQtb9.js","assets/vendor-tanstack-query-core-BWz0ose6.js","assets/persistence-Dzooc9Xg.js","assets/vendor-zustand-o69pgTEK.js","assets/vendor-base-ui-CdzJ6My_.js","assets/brand-storage-bootstrap-D4BW3w-M.js","assets/brand-storage-migration-Bhz6UOBJ.js","assets/useUIStore-NMQx_cnG.js","assets/vendor-react-BP2cRVqX.js","assets/vendor-pathe-vBmvQE8f.js","assets/platform-7bX6qtBV.js","assets/vendor-opencode-client-MF2GBrFx.js","assets/runtime-file-resource-C1k5nbWb.js","assets/vendor-tanstack-react-query-CdqCAt40.js","assets/vendor-aparajita-capacitor-secure-storage-xol_6BsB.js","assets/capgoAdapter-BV5kJq2r.js","assets/types-BzF7Dhzq.js","assets/vendor-pierre-diffs-DPBtNDJ5.js","assets/vendor-hast-util-to-html-Bw_SgZ1t.js","assets/vendor-character-entities-legacy-Wut6vMuj.js","assets/vendor-character-entities-html4-DlN_yAFd.js","assets/vendor-ccount-CyGsA0u7.js","assets/vendor-comma-separated-tokens-B9ouxNNS.js","assets/vendor-oniguruma-to-es-CrHzjjSU.js","assets/vendor-oniguruma-parser-D2DIvhSP.js","assets/vendor-diff-Dq7CZNim.js","assets/vendor-lru_map-BMOrLc9L.js","assets/vendor-sonner-ZS8XIOVl.js","assets/vendor-reactuses-core-BpfIZ1tg.js","assets/vendor-lodash-es-DfLbG5Af.js","assets/vendor-js-cookie-hSOiFTtX.js","assets/button-D_HdP1Oy.js","assets/store-szlu5Wxv.js","assets/vendor-class-variance-authority-BLUaYARZ.js","assets/vendor-tailwind-merge-BicNWLTg.js","assets/MobileShareBridge-BbbQ15B3.js","assets/MobileDetailNavigation-B_PYZ9xi.js","assets/useMobileNavigationStore-BURkCJuM.js","assets/useAssistantUIStore-D7JZlg_Q.js","assets/vendor-zod-Dzk5kdUU.js","assets/vendor-fuse.js-DB5wDJbI.js","assets/Icon-BXTZRnIO.js","assets/AgentAvatar-BVnp9gE9.js","assets/agentColors-DWSbQXy2.js","assets/vendor-dicebear-core-CV95S5Pg.js","assets/vendor-dicebear-styles-7lEG-JsF.js","assets/dualLimitLru-D8Sphgua.js","assets/useThemeSystem-8jhE4Zyk.js","assets/dialog-B_87Teec.js","assets/rasterizePng-056Poix7.js","assets/gitApi-B1arMnHR.js","assets/useAppFontEffects-lmtncXsi.js","assets/desktopHosts-BDyl2P7W.js","assets/desktopRelayRestore-C_23nlKD.js","assets/vendor-simplewebauthn-browser-Dwhcdg_5.js","assets/projectMeta-D3cfkJyk.js","assets/input-DDfJnn8e.js","assets/tooltip-BQQoK7L_.js","assets/OverlayScrollbar-CbWvRXm6.js","assets/textarea-BkOdxUN0.js","assets/vendor-framer-motion-D-oiwsxL.js","assets/MobileWindowStack-DGLdgoGr.js","assets/vendor-dnd-kit-core-5pNnzVdw.js","assets/vendor-dnd-kit-accessibility-COSwgjFs.js","assets/vendor-dnd-kit-sortable-Dm50I0m7.js","assets/speechSettingsQueries-xWFTnUfF.js","assets/dropdown-menu.styles-C_b80jxk.js","assets/image-loading-23c-W-bq.js","assets/image-loading-D9Z_BASK.css","assets/sessionChangeSummary-evl_LmRN.js","assets/LoadingImage-NxtWlewi.js","assets/ImageLoadingPlaceholder-Cv6IaJar.js","assets/sessionChangeSummary-CRYRvpy7.css","assets/fileMentionTouchSelection-Bx6vWiqF.js","assets/vendor-fuzzysort-ukaRp9PC.js","assets/insertionBoundaries-B8UdVMC9.js","assets/appThemeRegistry-nntgbF9E.js","assets/MarkdownRenderer-Va7Wdk98.js","assets/useEffectiveDirectory-CqkTJqRg.js","assets/markdownHeightCache-Cbd62oWw.js","assets/url-Be8VCT8M.js","assets/markdown-worker-CkO3sT4Y.js","assets/FadeInOnReveal-CzC5UKnq.js","assets/useWorkerHighlightedLines-Bla356tF.js","assets/vendor-tanstack-react-virtual-B_EO--9t.js","assets/markdownTheme-DHoKvD6O.js","assets/vendor-cmdk-RDxC-9Iz.js","assets/vendor-aria-hidden-BbL3cEyI.js","assets/sortable-tabs-strip-CrjW2aQk.js","assets/vendor-motion-88WXBOBf.js","assets/useFontPreferences-D9PX5t6Y.js","assets/terminalApi-BHXvha-U.js","assets/MobileTabPageHeader-tiWNRKWN.js","assets/vendor-codemirror-autocomplete-7c2L_4dM.js","assets/vendor-codemirror-lang-angular-DXOgWEVj.js","assets/vendor-codemirror-lang-json-mLulNbwB.js","assets/vendor-codemirror-lang-markdown-CV1IO6Qs.js","assets/vendor-codemirror-lang-python-YM2WVLHF.js","assets/vendor-codemirror-legacy-modes-DwltVFbT.js","assets/mcpQueries-BxbbmYAd.js","assets/collapsible-sUU_ORMe.js","assets/vendor-codemirror-commands-B8KrBQ9B.js","assets/vendor-codemirror-search-ZqtrPLjU.js","assets/vendor-replit-codemirror-vim-DDj0dSVY.js","assets/vendor-codemirror-language-data-Ctd4WxgW.js","assets/projectActions-BX0cjZoq.js","assets/runtimeEndpointReset-C_1daihM.js","assets/scheduledTaskNavigation-DvSpMLdG.js","assets/mobileBackNavigation-f8AMDP0N.js","assets/sessionLookup-CJ8mXxHt.js","assets/vendor-cron-parser-BmO80h0C.js","assets/runtimeEndpointReset-DmY_4gYI.css","assets/SettingsView-CKn54R1o.js","assets/native-config-DLJCZcXh.js","assets/vendor-yaml-C9KlJAlj.js","assets/vendor-qrcode-D7jBCyl-.js","assets/vendor-dijkstrajs-BAzPDGZM.js","assets/AssistantView-BkMKCN9c.js","assets/assistant-attachment-cache-CLnqffXU.js","assets/renderMobileApp-1G4-5u-t.css","assets/src-omVWmz3o.css","assets/main-DJwLyPc3.js","assets/useDesktopWindowControlsLayout-BY0_whx0.js","assets/diagram-BE50CEiR.js","assets/vendor-react-drawio-Ck9ZKdNN.js","assets/multirun-Cvl4FMPo.js","assets/vendor-zumer-snapdom-yq9vlCKr.js","assets/vendor-html-to-image-BDMm2v6d.js","assets/main-qSeeJRW1.css"])))=>i.map(i=>d[i]);
2
+ import{n as e,t}from"./runtimeConfig-DwFJL5bm.js";import{o as n}from"./vendor-aparajita-capacitor-secure-storage-xol_6BsB.js";/* empty css */var r=`true`,i=`false`,a=r===`true`,o=i===`true`;function s(e={}){let{immediate:t=!1,onNeedReload:r,onNeedRefresh:i,onOfflineReady:s,onRegistered:c,onRegisteredSW:l,onRegisterError:u}=e,d,f,p,m=async(e=!0)=>{await f,a||p?.()};async function h(){if(`serviceWorker`in navigator){if(d=await n(async()=>{let{Workbox:e}=await import(`./vendor-workbox-window-15MWHJyx.js`).then(e=>e.t);return{Workbox:e}},__vite__mapDeps([0,1])).then(({Workbox:e})=>new e(`/sw.js`,{scope:`/`,type:`classic`})).catch(e=>{u?.(e)}),!d)return;if(p=()=>{d?.messageSkipWaiting()},!o)if(a)d.addEventListener(`activated`,e=>{(e.isUpdate||e.isExternal)&&(r?r():window.location.reload())}),d.addEventListener(`installed`,e=>{e.isUpdate||s?.()});else{let e=!1,t=()=>{e=!0,d?.addEventListener(`controlling`,e=>{e.isUpdate&&(r?r():window.location.reload())}),i?.()};d.addEventListener(`installed`,n=>{n.isUpdate===void 0?n.isExternal===void 0?!e&&s?.():n.isExternal?t():!e&&s?.():n.isUpdate||s?.()}),d.addEventListener(`waiting`,t)}d.register({immediate:t}).then(e=>{l?l(`/sw.js`,e):c?.(e)}).catch(e=>{u?.(e)})}}return f=h(),m}window.__YURI_RUNTIME_APIS__=t();var c=()=>typeof window>`u`||typeof window.matchMedia!=`function`?!1:window.matchMedia(`(pointer: coarse)`).matches,l=(()=>{let e=new URLSearchParams(window.location.search).get(`surface`);if(e===`mobile`)return`mobile`;if(e===`desktop`)return`desktop`;let t=Math.min(window.innerWidth||0,window.screen?.width||window.innerWidth||0),n=navigator.maxTouchPoints||0;return t>0&&t<=760&&(n>0||c())?`mobile`:`desktop`})();window.__YURI_SURFACE__=l;var u=()=>!(!(`serviceWorker`in navigator)||!window.isSecureContext||window.location.protocol!==`http:`&&window.location.protocol!==`https:`||document.prerendering||String(document.visibilityState)===`prerender`),d=e=>{let t=!1,n=()=>{t||u()&&(t=!0,e())},r=()=>{setTimeout(n,0)};document.readyState===`complete`?r():window.addEventListener(`load`,r,{once:!0}),(document.prerendering||String(document.visibilityState)===`prerender`)&&document.addEventListener(`visibilitychange`,n,{once:!0})},f=()=>{d(()=>{try{s({onRegisterError(e){console.warn(`[PWA] service worker registration skipped:`,e)}})}catch(e){console.warn(`[PWA] service worker registration skipped:`,e)}})},p=`yuri.dev.module-reload`,m=(e,t)=>{console.error(`[yuri] failed to load ${t}:`,e)};l===`mobile`?n(async()=>{let{renderMobileApp:e}=await import(`./renderMobileApp-DUiUPyd7.js`);return{renderMobileApp:e}},__vite__mapDeps([2,1,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125])).then(({renderMobileApp:e})=>{try{sessionStorage.removeItem(p)}catch{}e(window.__YURI_RUNTIME_APIS__??t())}).catch(e=>m(e,`renderMobileApp`)):e().then(()=>n(()=>import(`./main-DJwLyPc3.js`),__vite__mapDeps([126,1,3,4,5,6,7,8,9,10,11,12,13,14,57,15,16,17,18,19,96,21,98,22,23,24,25,26,27,28,29,30,31,33,34,35,36,37,38,39,41,42,32,43,44,45,46,52,53,55,56,58,48,51,47,49,50,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,54,82,83,84,85,86,87,88,89,90,91,92,93,94,95,97,99,100,101,102,103,104,105,106,107,108,109,110,127,111,112,113,114,115,116,128,129,130,131,132,133,125]))).then(()=>{try{sessionStorage.removeItem(p)}catch{}}).catch(e=>m(e,`desktop main`)),f();