@yuriai/web 0.3.5 → 0.3.6-beta.6

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 (217) hide show
  1. package/dist/assets/{AgentAvatar-CNOu_vy0.js → AgentAvatar-Bum-xW6O.js} +1 -1
  2. package/dist/assets/{AgentSelector-K5JSbXv3.js → AgentSelector-B9Zga0u6.js} +1 -1
  3. package/dist/assets/{ArchivedSessionsDialog-CU9RXl8K.js → ArchivedSessionsDialog-DCEC4I0y.js} +1 -1
  4. package/dist/assets/{AssistantConversationSurface-u3ndSmZP.js → AssistantConversationSurface-vkVeLvop.js} +3 -3
  5. package/dist/assets/AssistantSessionCard-J2esHfj1.js +2 -0
  6. package/dist/assets/{AssistantUnreadBadge-opyLZlZd.js → AssistantUnreadBadge-BZ6L1cG6.js} +1 -1
  7. package/dist/assets/{AssistantView-CDPTtrUZ.js → AssistantView-CS5-jm7K.js} +1 -1
  8. package/dist/assets/{AssistantWorkingAvatar-Vghb8xlt.js → AssistantWorkingAvatar-CtzuYnl7.js} +1 -1
  9. package/dist/assets/{AssistantsSettingsPage-Dt4OP3J-.js → AssistantsSettingsPage-CkCY3j9O.js} +1 -1
  10. package/dist/assets/{BinaryFileFallback-CJqnlBzh.js → BinaryFileFallback-2KhGwjpa.js} +1 -1
  11. package/dist/assets/{BtwPanel-DnMW6R43.js → BtwPanel-CXY_0XsO.js} +3 -3
  12. package/dist/assets/{BusyDots-FXSlMe2F.js → BusyDots-CD4ZvJSX.js} +3 -3
  13. package/dist/assets/ChatContainer-DQXNCnON.js +65 -0
  14. package/dist/assets/{ChatView-AFUNEBdD.js → ChatView-acUOtklp.js} +3 -3
  15. package/dist/assets/{DiagramView-j7aFp44v.js → DiagramView-DYvLnWQL.js} +1 -1
  16. package/dist/assets/{DiffView-DZ_gKyTO.js → DiffView-DeWNyNgj.js} +1 -1
  17. package/dist/assets/{DiffViewToggle-DkxhEUhV.js → DiffViewToggle-Dj2DhA-4.js} +1 -1
  18. package/dist/assets/{ErrorBoundary-CCH4LiRY.js → ErrorBoundary-BX-OBb4M.js} +1 -1
  19. package/dist/assets/{FadeInOnReveal-DO9PZrJL.js → FadeInOnReveal-CVpx10UG.js} +1 -1
  20. package/dist/assets/{GuiPluginMount-BCqt2pmM.js → GuiPluginMount-ObpO9wep.js} +1 -1
  21. package/dist/assets/{GuiPluginPage-BSjWEmIu.js → GuiPluginPage-CBnSbJjH.js} +1 -1
  22. package/dist/assets/{GuiPluginSurface-B8QjacMd.js → GuiPluginSurface-C-XvgWSF.js} +1 -1
  23. package/dist/assets/{GuiPluginTitlebarItems-DfHugxsx.js → GuiPluginTitlebarItems-BlWSbCLN.js} +1 -1
  24. package/dist/assets/{GuiPluginWindow-CDycMqzT.js → GuiPluginWindow-DrPQHRml.js} +1 -1
  25. package/dist/assets/{Icon-B-w2YKpn.js → Icon-DqzPCJr3.js} +1 -1
  26. package/dist/assets/{ImageLoadingPlaceholder-DsgRtfYG.js → ImageLoadingPlaceholder-DXTOQsFT.js} +1 -1
  27. package/dist/assets/{LoadingImage-B3IL7hnv.js → LoadingImage-DKW_EFqZ.js} +1 -1
  28. package/dist/assets/MarkdownRenderer-BPkgfzGX.js +2 -0
  29. package/dist/assets/{MarkdownRendererImpl-CPgpkd9b.js → MarkdownRendererImpl-BhoZ-tH-.js} +1 -1
  30. package/dist/assets/{MarkstreamRendererImpl-BzK1BO80.js → MarkstreamRendererImpl-DjktxTE3.js} +1 -1
  31. package/dist/assets/{MobileAssistantSettingsPage-DVpE3b24.js → MobileAssistantSettingsPage-C_vs3fmd.js} +1 -1
  32. package/dist/assets/{MobileAssistantTab-BbccE67x.js → MobileAssistantTab-UYxLV4iM.js} +1 -1
  33. package/dist/assets/{MobileBtwPage-BRN1gAmR.js → MobileBtwPage-CKu_Pu-1.js} +1 -1
  34. package/dist/assets/{MobileChangesSurface-BwmSTxeh.js → MobileChangesSurface-B-VaLv5u.js} +1 -1
  35. package/dist/assets/{MobileChatScreen-Bf42GrQ8.js → MobileChatScreen-BDmUXLGP.js} +1 -1
  36. package/dist/assets/{MobileDetailNavigation-DKWnQoSh.js → MobileDetailNavigation-B9OyYPvv.js} +1 -1
  37. package/dist/assets/MobileFilesSurface-CytwXDmJ.js +2 -0
  38. package/dist/assets/{MobileHtmlNetworkBoundary-BKSYPR9N.js → MobileHtmlNetworkBoundary-CpaAGgbb.js} +2 -2
  39. package/dist/assets/{MobileOverlayPanel-DcRWQlmf.js → MobileOverlayPanel-Dl2pIYSw.js} +1 -1
  40. package/dist/assets/{MobileResizableSheet-CF3Pbot4.js → MobileResizableSheet-02xvEBic.js} +1 -1
  41. package/dist/assets/{MobileSettingsTab-of6zpTsr.js → MobileSettingsTab-CcZaL1t7.js} +1 -1
  42. package/dist/assets/{MobileShareBridge-CRq9F1rn.js → MobileShareBridge-BWtSkRu8.js} +1 -1
  43. package/dist/assets/{MobileSurface-DGNomvlu.js → MobileSurface-uhKclxNm.js} +1 -1
  44. package/dist/assets/{MobileTabPageHeader-0aJFe3_x.js → MobileTabPageHeader-CvDxMHBT.js} +1 -1
  45. package/dist/assets/{ModelLogo-D27dq-si.js → ModelLogo-Lvd4AuAS.js} +1 -1
  46. package/dist/assets/{ModelSelector-Dg__8QLh.js → ModelSelector-CHfDNevv.js} +1 -1
  47. package/dist/assets/{MultiRunWindow-COqSg1Nk.js → MultiRunWindow-DvVjYPLd.js} +1 -1
  48. package/dist/assets/{OnboardingScreen-DUNyDwc6.js → OnboardingScreen-JSz-rr84.js} +1 -1
  49. package/dist/assets/{OverlayScrollbar-DS6XJ1HA.js → OverlayScrollbar-SfQf8OZP.js} +1 -1
  50. package/dist/assets/{PierreDiffViewer-BHwj_6j8.js → PierreDiffViewer-DyLQb4PS.js} +1 -1
  51. package/dist/assets/{ProviderLogo-Cm9RNV_U.js → ProviderLogo-DZBRUtcG.js} +1 -1
  52. package/dist/assets/{RemoteAssistantSessionCard-DAjHRUrC.js → RemoteAssistantSessionCard-CizQgy_n.js} +1 -1
  53. package/dist/assets/{RemoteDesktopPanel-Bays6pHh.js → RemoteDesktopPanel-RYJmIQh3.js} +1 -1
  54. package/dist/assets/{ScheduledTasksDialog-DnwBC7cj.js → ScheduledTasksDialog-bACf76Tf.js} +1 -1
  55. package/dist/assets/{ScrollableOverlay-CkX-buJm.js → ScrollableOverlay-DSbSVZg9.js} +1 -1
  56. package/dist/assets/{SettingsGroup-kZ_faXwL.js → SettingsGroup-DgaY4U0n.js} +1 -1
  57. package/dist/assets/{SettingsView-C62JngPE.js → SettingsView-BUMS9_Hq.js} +7 -7
  58. package/dist/assets/{SettingsWindow-Cm8apHAR.js → SettingsWindow-BT1YDYdX.js} +1 -1
  59. package/dist/assets/{SetupTourDialog-W_UeWH-i.js → SetupTourDialog-bsMRlubt.js} +1 -1
  60. package/dist/assets/{SyncActions-Blnq08ks.js → SyncActions-DhnAfnaX.js} +1 -1
  61. package/dist/assets/{TerminalView-CMugifkh.js → TerminalView-CCrhbls9.js} +1 -1
  62. package/dist/assets/{TextSelectionMenu-B2fIBlD3.js → TextSelectionMenu-B7H6lDVM.js} +1 -1
  63. package/dist/assets/{ToolOutputDialog-DdSUE2kP.js → ToolOutputDialog-Cvrz8NQg.js} +1 -1
  64. package/dist/assets/{YuriLogo-Ceon25sC.js → YuriLogo-D__yuhxb.js} +1 -1
  65. package/dist/assets/{YuriWordmark-CW53XKgV.js → YuriWordmark-CFNVVLiB.js} +1 -1
  66. package/dist/assets/{assistant-attachment-cache-eNT2QtmP.js → assistant-attachment-cache-BfJmm0RR.js} +1 -1
  67. package/dist/assets/{assistantMessagePreview-C7YAFen1.js → assistantMessagePreview-BN6hGa7u.js} +1 -1
  68. package/dist/assets/{assistantQueries-DxvTFlpL.js → assistantQueries-CprcsYI6.js} +1 -1
  69. package/dist/assets/{auto-read-context-Ce0o43YI.js → auto-read-context-C-i9LK0p.js} +1 -1
  70. package/dist/assets/{capgoAdapter-DQwUA-Nt.js → capgoAdapter-DOdLoRAO.js} +1 -1
  71. package/dist/assets/{card-D44sTpdY.js → card-w5raQV1D.js} +1 -1
  72. package/dist/assets/{chatUpwardIntent-CnS7WWRL.js → chatUpwardIntent-BUGiQveD.js} +1 -1
  73. package/dist/assets/{checkbox-DaKe0Tlq.js → checkbox-_7RbogJP.js} +1 -1
  74. package/dist/assets/{client-ITylDDCS.js → client-BNBLp-TP.js} +3 -3
  75. package/dist/assets/{collapsible-CL3SPnOf.js → collapsible-g7uUkAXi.js} +1 -1
  76. package/dist/assets/{connection-hint-SMNZFDAe.js → connection-hint-D0oXnbT2.js} +1 -1
  77. package/dist/assets/{context-menu-DZunhC8o.js → context-menu-ZflmwQdh.js} +1 -1
  78. package/dist/assets/{desktopHosts-BsTrBVja.js → desktopHosts-f2baL_xR.js} +1 -1
  79. package/dist/assets/{desktopRelayRestore-BxbRKak_.js → desktopRelayRestore-v28izlUf.js} +1 -1
  80. package/dist/assets/{device-EIfSfSWk.js → device-CWomdsE7.js} +1 -1
  81. package/dist/assets/{diagram-DFXqN638.js → diagram-DWjh1vyU.js} +1 -1
  82. package/dist/assets/{dialog-CmjXOKMz.js → dialog-BN6kCa-_.js} +1 -1
  83. package/dist/assets/{dropdown-menu-BT_66BFT.js → dropdown-menu-DBarQzEj.js} +1 -1
  84. package/dist/assets/{es-DqYZgeC6.js → es-BuXtFKUW.js} +2 -2
  85. package/dist/assets/{fileMentionTouchSelection-B_62hIQI.js → fileMentionTouchSelection-CWLbylio.js} +1 -1
  86. package/dist/assets/{fileReferenceActions-TmbrIHBI.js → fileReferenceActions-Cso24xcm.js} +1 -1
  87. package/dist/assets/{fr-BHaun7Zq.js → fr-BaZeffY9.js} +2 -2
  88. package/dist/assets/{gitApi-CBfYFgtd.js → gitApi-Dv43wBP8.js} +1 -1
  89. package/dist/assets/gitApiHttp-BCUn15ro.js +3 -0
  90. package/dist/assets/{githubAuthQueries-C5RxUNL2.js → githubAuthQueries-DjHUTtMP.js} +1 -1
  91. package/dist/assets/{historyImportQueries-CZsECryv.js → historyImportQueries-DzK4Znck.js} +1 -1
  92. package/dist/assets/host-CesLGsT6.js +1 -0
  93. package/dist/assets/{i18n-Dojvs57M.js → i18n-5cDQDVOf.js} +1 -1
  94. package/dist/assets/{icons-D_vRtitD.js → icons-C-2yoZOg.js} +1 -1
  95. package/dist/assets/{imageSource-Cq_p4gAe.js → imageSource-BFZPZldy.js} +1 -1
  96. package/dist/assets/{input-BllFKOjo.js → input-BIk3HIwD.js} +1 -1
  97. package/dist/assets/{input-store-dLjM4aiu.js → input-store-CJziVczN.js} +1 -1
  98. package/dist/assets/{insertionBoundaries-Br0Bdl9R.js → insertionBoundaries-BPu6XWjZ.js} +1 -1
  99. package/dist/assets/{ja-BGNugvrx.js → ja-CGVx5A8U.js} +2 -2
  100. package/dist/assets/{kbd-CwkasrzN.js → kbd-D2YX1zHb.js} +1 -1
  101. package/dist/assets/{ko-CGbNBfDe.js → ko-C663nzbf.js} +2 -2
  102. package/dist/assets/main-DEvjKKLA.js +2 -0
  103. package/dist/assets/main-psg8ji-2.js +169 -0
  104. package/dist/assets/{markdownHeightCache-RX04MAqu.js → markdownHeightCache-B78ju12X.js} +1 -1
  105. package/dist/assets/{mcpQueries-qRW-HQMx.js → mcpQueries-ClZOzij7.js} +1 -1
  106. package/dist/assets/miniChat-DUpTKDGa.js +2 -0
  107. package/dist/assets/mobile-BWn6QkaD.js +2 -0
  108. package/dist/assets/{mobileBackNavigation-DsDUTnFY.js → mobileBackNavigation-CkPZ62-V.js} +1 -1
  109. package/dist/assets/mobileConnections-CIYG1Plg.js +2 -0
  110. package/dist/assets/{multirun-C2RRF2Q3.js → multirun-DxJV3I3M.js} +1 -1
  111. package/dist/assets/{native-config-Czc142JT.js → native-config-2pHZQeU7.js} +1 -1
  112. package/dist/assets/{nativeComposerCover-DzEGSyOO.js → nativeComposerCover-BlX7TtR8.js} +1 -1
  113. package/dist/assets/navigation-NL42ix4C.js +2 -0
  114. package/dist/assets/{openRemoteProjectSession-C5z2Juv7.js → openRemoteProjectSession-0PN8YQQV.js} +1 -1
  115. package/dist/assets/openSessionFromDeepLink-BiGSREvs.js +2 -0
  116. package/dist/assets/pathNormalization-ewtPqJWn.js +1 -0
  117. package/dist/assets/{pl-k8-4URiE.js → pl-CeBOMwg9.js} +2 -2
  118. package/dist/assets/platform-DbR5F6Vm.js +1 -0
  119. package/dist/assets/{pluginPresentation-p_0sXPMT.js → pluginPresentation-BDSmwf6B.js} +1 -1
  120. package/dist/assets/{project-preview-BcLPKzwg.js → project-preview-CYETzJZe.js} +1 -1
  121. package/dist/assets/{projectActions-BPmI9_mW.js → projectActions-Cd7WGZWC.js} +1 -1
  122. package/dist/assets/{prompt-attachment-upload-BGppTOgV.js → prompt-attachment-upload-BltVQvQ0.js} +1 -1
  123. package/dist/assets/{pt-BR-DdwCzXBH.js → pt-BR-r8268Pk6.js} +2 -2
  124. package/dist/assets/pwa-DwAXWlBC.js +2 -0
  125. package/dist/assets/queue-abort-optimistic-BAIlvaHr.js +1 -0
  126. package/dist/assets/{quota-2PwXAoIg.js → quota-DcAFX5u-.js} +1 -1
  127. package/dist/assets/{reference-history-BwtzPAmA.js → reference-history-BJE_RiI2.js} +1 -1
  128. package/dist/assets/{remote-input-store-DdjKfpxS.js → remote-input-store-BZEYXBgh.js} +1 -1
  129. package/dist/assets/remoteProjectQueries-A4mba1L1.js +1 -0
  130. package/dist/assets/remoteSessionReference-pn6xnEN8.js +1 -0
  131. package/dist/assets/{renderElectronMiniChatApp-BekZAu-s.js → renderElectronMiniChatApp-CIJo1j8s.js} +2 -2
  132. package/dist/assets/{renderMobileApp-C5U2cyeq.js → renderMobileApp-iXYVJAnU.js} +5 -5
  133. package/dist/assets/{runtime-file-download-1s2Al1t3.js → runtime-file-download-B4gjMkQj.js} +1 -1
  134. package/dist/assets/runtime-file-resource-B0yDjkk2.js +6 -0
  135. package/dist/assets/{runtimeConfig-DzYIc49M.js → runtimeConfig-DitORnV_.js} +1 -1
  136. package/dist/assets/runtimeEndpointReset-D01NK6o1.js +4 -0
  137. package/dist/assets/{scheduledTaskNavigation-VVTOq9n2.js → scheduledTaskNavigation-C-pzJzMY.js} +1 -1
  138. package/dist/assets/{select-BOtGs1FV.js → select-BmqBGFx7.js} +1 -1
  139. package/dist/assets/sessionChangeSummary-BCF9VwAA.js +1 -0
  140. package/dist/assets/sessionLookup-DcKP4fmz.js +1 -0
  141. package/dist/assets/sessionOwnership-D3zgaAKz.js +2 -0
  142. package/dist/assets/{shortcuts-Cu4ioDvH.js → shortcuts-DIaqWe1f.js} +1 -1
  143. package/dist/assets/{sortable-tabs-strip-DACGW9sB.js → sortable-tabs-strip-EetHRIX6.js} +1 -1
  144. package/dist/assets/{speechSettingsQueries-BU-4Axb5.js → speechSettingsQueries-Bm8acMUB.js} +1 -1
  145. package/dist/assets/src-DYCPWwUH.css +2 -0
  146. package/dist/assets/{store-DRUKTpV5.js → store-BRt8bo0A.js} +3 -3
  147. package/dist/assets/summaries-BQMyJaaw.js +1 -0
  148. package/dist/assets/{switch-DaUn0G3u.js → switch-DA-ralpy.js} +1 -1
  149. package/dist/assets/{terminalApi-ClNhXBA8.js → terminalApi-CjhPNDFD.js} +1 -1
  150. package/dist/assets/{textarea-IhQHekYx.js → textarea-DAq6EK4w.js} +1 -1
  151. package/dist/assets/{timeFormat-BsuUDWLs.js → timeFormat-D7_gtTO6.js} +1 -1
  152. package/dist/assets/{tooltip-Dw3DApa-.js → tooltip-BYCy1Cfz.js} +1 -1
  153. package/dist/assets/{truncated-path-KHrfQ66P.js → truncated-path-MXEmYf5S.js} +1 -1
  154. package/dist/assets/types-CilosbsN.js +2 -0
  155. package/dist/assets/ui-CWbFzUJf.js +13 -0
  156. package/dist/assets/{uk-DU-7fAP4.js → uk-CeQ1XJ99.js} +2 -2
  157. package/dist/assets/{useAppFontEffects-Dw6o6XbA.js → useAppFontEffects-BoRvZ8lz.js} +5 -5
  158. package/dist/assets/{useAssistantUIStore-CpJZ4Rqs.js → useAssistantUIStore-BJDq52fm.js} +1 -1
  159. package/dist/assets/useDesktopWindowControlsLayout-B9GYUG1c.js +1 -0
  160. package/dist/assets/{useDictation-sdgDfATy.js → useDictation-CgQ0a0Y9.js} +1 -1
  161. package/dist/assets/{useEffectiveDirectory-DZqC-2HE.js → useEffectiveDirectory-wnOwweNy.js} +1 -1
  162. package/dist/assets/{useFontPreferences-Bb-bxdL8.js → useFontPreferences-DqJCcld1.js} +1 -1
  163. package/dist/assets/{useGitStore-Bbmai549.js → useGitStore-dcwPhFO0.js} +1 -1
  164. package/dist/assets/{useInlineCommentDraftStore-DrC99u6A.js → useInlineCommentDraftStore-B0kVirb-.js} +1 -1
  165. package/dist/assets/{useMcpConfigStore-ZsZxSrCt.js → useMcpConfigStore-DeDUHkJz.js} +1 -1
  166. package/dist/assets/{useMobileSwipeActions-fUp7Bkbn.js → useMobileSwipeActions-yg95WXmV.js} +1 -1
  167. package/dist/assets/{useMobileTranscriptSyncHint-B4izCfqe.js → useMobileTranscriptSyncHint-PsaAa7gY.js} +2 -2
  168. package/dist/assets/{useModelLists-B0qSYDby.js → useModelLists-DGpesqEz.js} +1 -1
  169. package/dist/assets/{useOpenCodeReadiness-B9d-wLZB.js → useOpenCodeReadiness-DslQPffO.js} +1 -1
  170. package/dist/assets/{usePluginsStore-BLncdNj-.js → usePluginsStore-URyOiOP1.js} +1 -1
  171. package/dist/assets/{useProjectGitActions-CHMe1ku4.js → useProjectGitActions-DUW8pMoI.js} +1 -1
  172. package/dist/assets/{useProjectGitStore-Lz9AV32V.js → useProjectGitStore-Dbhq6u5W.js} +1 -1
  173. package/dist/assets/{useProjectRuntimeAPIs-D51dVo-V.js → useProjectRuntimeAPIs-ByW8LhH7.js} +1 -1
  174. package/dist/assets/{useQuotaStore-mZs9LTwx.js → useQuotaStore-BvacpO81.js} +1 -1
  175. package/dist/assets/{useSessionBtwStore-CYaTDkvT.js → useSessionBtwStore-BXfNAopW.js} +2 -2
  176. package/dist/assets/{useStreamingTextThrottle-ul6e3dUd.js → useStreamingTextThrottle-C3rgPfDZ.js} +1 -1
  177. package/dist/assets/{useUIStore-C3ewjGgP.js → useUIStore-BPe3dRMB.js} +1 -1
  178. package/dist/assets/{worktreeManager-V6hoSVxH.js → worktreeManager-Ciba_bQW.js} +1 -1
  179. package/dist/assets/{worktreeSourceBranchPreference-MQFPkOZy.js → worktreeSourceBranchPreference-CfVmY3R2.js} +1 -1
  180. package/dist/assets/{zh-CN-DOHH7nht.js → zh-CN-Bv854olO.js} +2 -2
  181. package/dist/assets/{zh-TW-t1qlXGOg.js → zh-TW-gx8cO-Cx.js} +2 -2
  182. package/dist/index.html +18 -16
  183. package/dist/mini-chat.html +18 -16
  184. package/dist/mobile.html +2 -2
  185. package/package.json +1 -1
  186. package/server/lib/assistants/builtin-skills.js +1 -1
  187. package/server/lib/gui-customization/DOCUMENTATION.md +6 -0
  188. package/server/lib/gui-customization/session-skill.js +2 -2
  189. package/server/lib/gui-customization/session-skill.test.js +3 -1
  190. package/server/lib/gui-customization/skill/SKILL.md +3 -1
  191. package/server/lib/gui-customization/skill/references/deep-links.md +39 -0
  192. package/server/lib/opencode/settings-helpers.js +4 -0
  193. package/dist/assets/AssistantSessionCard-MYBAni6A.js +0 -2
  194. package/dist/assets/ChatContainer-Dg9uDBjk.js +0 -65
  195. package/dist/assets/MarkdownRenderer-CsEylQVj.js +0 -2
  196. package/dist/assets/MobileFilesSurface-qkfC06Oh.js +0 -2
  197. package/dist/assets/gitApiHttp-Bswf6gnl.js +0 -3
  198. package/dist/assets/host-C7jHgymK.js +0 -1
  199. package/dist/assets/main-B7wAfq9F.js +0 -2
  200. package/dist/assets/main-DVmi0I-y.js +0 -169
  201. package/dist/assets/miniChat-D7-JQ1hw.js +0 -2
  202. package/dist/assets/mobile-BFQBDlo9.js +0 -2
  203. package/dist/assets/mobileConnections-PVy2SsQ_.js +0 -2
  204. package/dist/assets/navigation-C1v9hIAT.js +0 -2
  205. package/dist/assets/platform-CiUKDeXd.js +0 -1
  206. package/dist/assets/pwa-Br2HZksc.js +0 -2
  207. package/dist/assets/queue-abort-optimistic-DciJN9X1.js +0 -1
  208. package/dist/assets/remoteProjectQueries-BXrXdLjN.js +0 -1
  209. package/dist/assets/remoteSessionReference-XfJOxItc.js +0 -1
  210. package/dist/assets/runtime-file-resource-C5kmYlLv.js +0 -6
  211. package/dist/assets/runtimeEndpointReset-BKLVdNhJ.js +0 -4
  212. package/dist/assets/sessionLookup-BTQ_AtWh.js +0 -1
  213. package/dist/assets/sessionOwnership-BPfk1qCS.js +0 -2
  214. package/dist/assets/src-Dj147H4m.css +0 -2
  215. package/dist/assets/types-BBBwzIOU.js +0 -2
  216. package/dist/assets/ui-CHdferA1.js +0 -13
  217. package/dist/assets/useDesktopWindowControlsLayout-DAkTdcAP.js +0 -1
@@ -1 +1 @@
1
- import{i as e,n as t}from"./runtime-switch-DEPKHgdL.js";import{a as n}from"./vendor-zustand-CTekDqaS.js";import{t as r}from"./brand-storage-migration-Bhz6UOBJ.js";import"./brand-storage-bootstrap-D4BW3w-M.js";import{D as i,E as a,F as o,O as s,R as c,S as l,k as u,o as d,s as f,w as p,x as m}from"./prompt-attachment-upload-BGppTOgV.js";import{t as h}from"./uuid-D-SDZijH.js";var g=`yuri_input_draft_metadata_v1`,_=`yuri_input_draft_metadata_migration_v1`,v=`yuri_chat_input_draft_`,y=`yuri_chat_confirmed_mentions_`,b=()=>({ok:!1,error:{code:`unavailable`}}),x=()=>({ok:!1,error:{code:`cancelled`}}),S=e=>({ok:!1,error:{code:e instanceof DOMException&&e.name===`QuotaExceededError`?`quota`:`unavailable`}}),C=e=>typeof e==`object`&&!!e&&(Object.getPrototypeOf(e)===Object.prototype||Object.getPrototypeOf(e)===null),w=(e,t)=>Object.keys(e).every(e=>t.includes(e)),T=e=>typeof e==`number`&&Number.isSafeInteger(e)&&e>0,E=e=>typeof e==`string`&&e.length>0,D=e=>({read:async t=>{if(!e)return b();try{return{ok:!0,value:e.getItem(t)}}catch(e){return S(e)}},write:async(t,n)=>{if(!e)return b();try{return e.setItem(t,n),{ok:!0,value:void 0}}catch(e){return S(e)}},remove:async t=>{if(!e)return b();try{return e.removeItem(t),{ok:!0,value:void 0}}catch(e){return S(e)}},keys:async()=>{if(!e)return b();try{let t=[];for(let n=0;n<e.length;n+=1){let r=e.key(n);r!==null&&t.push(r)}return{ok:!0,value:t}}catch(e){return S(e)}}}),O=()=>{try{return D(typeof window>`u`?null:window.localStorage)}catch{return D(null)}},k=(e,t,n,r)=>{let i=[];try{let e=n===null?[]:JSON.parse(n);Array.isArray(e)&&(i=e.filter(e=>typeof e==`string`))}catch{}return{suffix:e,text:t??``,mentions:i,keys:r}},ee=async e=>{let t=await e.keys();if(!t.ok)return t;let n=new Set;for(let e of t.value)e.startsWith(v)&&n.add(e.slice(22)),e.startsWith(y)&&n.add(e.slice(29));let r=[];for(let i of n){let n=`${v}${i}`,a=`${y}${i}`,[o,s]=await Promise.all([e.read(n),e.read(a)]);if(!o.ok)return o;if(!s.ok)return s;r.push(k(i,o.value,s.value,[n,a].filter(e=>t.value.includes(e))))}return{ok:!0,value:r}},te=e=>{if(!(!C(e)||!w(e,[`suffix`,`text`,`mentions`,`keys`])||typeof e.suffix!=`string`||typeof e.text!=`string`||!Array.isArray(e.mentions)||!e.mentions.every(e=>typeof e==`string`)||!Array.isArray(e.keys)||!e.keys.every(e=>typeof e==`string`)))return{suffix:e.suffix,text:e.text,mentions:[...e.mentions],keys:[...e.keys]}},ne=e=>{try{let t=JSON.parse(e);return Array.isArray(t)&&t.length===3&&E(t[0])&&(t[1]===`session`||t[1]===`draft`)&&E(t[2])&&e===JSON.stringify(t)}catch{return!1}},A=e=>{if(!C(e)||!w(e,[`complete`,`claimedTransportIdentity`,`captured`,`markerCommitted`,`cleanupComplete`])||typeof e.complete!=`boolean`||typeof e.claimedTransportIdentity!=`string`||e.captured!==void 0&&typeof e.captured!=`boolean`||e.markerCommitted!==void 0&&typeof e.markerCommitted!=`boolean`||e.cleanupComplete!==void 0&&typeof e.cleanupComplete!=`boolean`)return;let t=e.cleanupComplete??e.complete,n=e.captured??e.complete,r=e.markerCommitted??e.complete;if(!((n||r||t)&&!E(e.claimedTransportIdentity))&&!(r&&!n)&&!(t&&(!n||!r)))return{complete:t,claimedTransportIdentity:e.claimedTransportIdentity,captured:n,markerCommitted:r,cleanupComplete:t}},j=e=>{if(!C(e)||!w(e,[`version`,`drafts`,`tombstones`,`migration`,`legacy`])||e.version!==1||!C(e.drafts)||!C(e.tombstones)||!C(e.legacy)||!w(e.legacy,[`new`,`entries`])||!C(e.legacy.entries))return;let t=A(e.migration);if(!t)return;let n={};for(let[t,r]of Object.entries(e.drafts)){let e=c(r);if(!e||t!==a(e.key))return;n[t]=e}let r={};for(let[t,n]of Object.entries(e.tombstones)){if(!ne(t)||!T(n))return;r[t]=n}let i={};for(let[t,n]of Object.entries(e.legacy.entries)){let e=te(n);if(!e||t!==e.suffix||t===`new`)return;i[t]=e}let o=e.legacy.new===void 0?void 0:te(e.legacy.new);if(!(e.legacy.new!==void 0&&(!o||o.suffix!==`new`)))return{version:1,drafts:n,tombstones:r,migration:t,legacy:{...o?{new:o}:{},entries:i}}},M=(e=``)=>({version:1,drafts:{},tombstones:{},migration:{complete:!1,claimedTransportIdentity:e,captured:!1,markerCommitted:!1,cleanupComplete:!1},legacy:{entries:{}}}),N=e=>{try{return{ok:!0,value:JSON.stringify(e)}}catch{return{ok:!1,error:{code:`serialization`}}}},P=async e=>{let t=await e.read(g);if(!t.ok)return t;if(t.value===null)return{ok:!0,value:null};try{let e=j(JSON.parse(t.value));return e?{ok:!0,value:e}:{ok:!1,error:{code:`corrupt`}}}catch{return{ok:!1,error:{code:`corrupt`}}}},F=async(e,t)=>{let n=j(t);if(!n)return{ok:!1,error:{code:`corrupt`}};let r=N(n);return r.ok?e.write(g,r.value):r},I=e=>C(e)&&w(e,[`version`,`claimedTransportIdentity`])&&e.version===1&&E(e.claimedTransportIdentity)?{version:1,claimedTransportIdentity:e.claimedTransportIdentity}:void 0,re=e=>N({version:1,claimedTransportIdentity:e}),ie=(e,t,n)=>{let r={},i;for(let e of t)e.suffix===`new`?i=e:r[e.suffix]=e;return{...e,migration:{complete:!1,claimedTransportIdentity:n,captured:!0,markerCommitted:!1,cleanupComplete:!1},legacy:{...i?{new:i}:{},entries:r}}},L=e=>[...new Set([e.legacy.new,...Object.values(e.legacy.entries)].flatMap(e=>e?.keys??[]))],ae=new WeakMap,R=e=>{let t=ae.get(e);if(t)return t;let n=Promise.resolve(),r,i=!0,a=e=>{let t=n.then(e,e);return n=t.then(()=>void 0,()=>void 0),t},o={persist:t=>{let n=j(t);return n?i?a(async()=>i?F(e,n):b()):Promise.resolve(b()):Promise.resolve({ok:!1,error:{code:`corrupt`}})},migrate:(t,n={})=>{if(r)return r;let o=a(async()=>{let r=await P(e);if(!r.ok)return r;let a=r.value??M(),o=i&&(n.persistenceEnabled??!0);if(!a.migration.captured){let n=await ee(e);if(!n.ok)return n;if(!o)return{ok:!0,value:ie(a,n.value,``)};if(a=ie(a,n.value,t),!i)return{ok:!0,value:a};let r=await F(e,a);if(!r.ok)return r}if(!i||!(n.persistenceEnabled??!0)){let t=await ee(e);return t.ok?{ok:!0,value:a}:t}let s=await e.read(_);if(!s.ok)return s;if(s.value!==null)try{let t=I(JSON.parse(s.value));if(!t)return{ok:!1,error:{code:`corrupt`}};if(t.claimedTransportIdentity!==a.migration.claimedTransportIdentity){let t=re(a.migration.claimedTransportIdentity);if(!t.ok)return t;if(!i)return{ok:!0,value:a};let n=await e.write(_,t.value);if(!n.ok)return n}}catch{return{ok:!1,error:{code:`corrupt`}}}else{let t=re(a.migration.claimedTransportIdentity);if(!t.ok)return t;if(!i)return{ok:!0,value:a};let n=await e.write(_,t.value);if(!n.ok)return n}if(a.migration.cleanupComplete)return{ok:!0,value:a};for(let t of L(a)){if(!i)return{ok:!0,value:a};let n=await e.remove(t);if(!n.ok)return n}if(a={...a,migration:{complete:!0,claimedTransportIdentity:a.migration.claimedTransportIdentity,captured:!0,markerCommitted:!0,cleanupComplete:!0}},!i)return{ok:!0,value:a};let c=await F(e,a);return c.ok?{ok:!0,value:a}:c}).finally(()=>{r=void 0});return r=o,o},flush:()=>n,setEnabled:async e=>{i=e,i||await n}};return ae.set(e,o),o},z=e=>{let t=R(e),n=!0,r=!1,i=[],a=[],o=()=>{if(r||i.length>0)return;let e=a;a=[],e.forEach(e=>e())},s=()=>{if(r)return;let e=i.shift();if(!e){o();return}r=!0,t.persist(e.snapshot).then(e.resolve).finally(()=>{r=!1,s()})};return{persist:e=>{let t=j(e);return t?n?new Promise(e=>{i.push({snapshot:t,resolve:e}),s()}):Promise.resolve(b()):Promise.resolve({ok:!1,error:{code:`corrupt`}})},cancelPending:()=>{let e=i;i=[],e.forEach(({resolve:e})=>e(x())),o()},flush:()=>r||i.length>0?new Promise(e=>a.push(e)):Promise.resolve(),setEnabled:async e=>{if(n=e,!n){let e=i;i=[],e.forEach(({resolve:e})=>e(x()))}await(r||i.length>0?new Promise(e=>a.push(e)):Promise.resolve()),await t.setEnabled(e),await t.flush()}}},oe=`yuri-input-drafts`,se=1,ce=`blobs`,le=`blobRefs`,B=class extends Error{code;constructor(e){super(e),this.code=e}},V=e=>({ok:!1,error:{code:e instanceof B?e.code:e instanceof DOMException&&e.name===`QuotaExceededError`?`quota-exceeded`:e instanceof DOMException&&e.name===`AbortError`?`transaction-aborted`:`transaction-failed`}}),H=e=>{if(!(e instanceof Blob)&&!u(e))throw new B(`invalid-value`)},U=e=>{if(!e)throw new B(`invalid-value`)},W=(e,t)=>({id:p(e),blobID:t,transportIdentity:e.transportIdentity,ownerKind:e.owner.kind,ownerID:e.owner.ownerID}),G=async e=>{if(typeof e==`string`)return`url:${e}`;let t=await crypto.subtle.digest(`SHA-256`,await e.arrayBuffer()),n=[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,`0`)).join(``);return`blob:${e.type}:${e.size}:${n}`},K=async(e,t)=>(e.fingerprint??await G(e.value))===t,q=async(e,t=!1)=>{let n=await e.getAllBlobRefs(),r=await e.getAllBlobs(),i=new Map;for(let t of n)await e.getBlob(t.blobID)?i.set(t.blobID,(i.get(t.blobID)??0)+1):await e.deleteBlobRef(t.id);for(let n of r){let r=i.get(n.id)??0;r||!t?await e.putBlob({...n,refCount:r}):await e.deleteBlob(n.id)}},ue=e=>{try{let t=JSON.parse(e);return!Array.isArray(t)||t.length!==4||typeof t[0]!=`string`||typeof t[2]!=`string`||t[1]!==`session`&&t[1]!==`draft`&&t[1]!==`surface`&&t[1]!==`queue`&&t[1]!==`send`?void 0:{transportIdentity:t[0],ownerKind:t[1],ownerID:t[2]}}catch{return}},J=(e,t)=>{let n=ue(e.id),r=e.ownerKind??n?.ownerKind,i=e.transportIdentity??n?.transportIdentity;return r!==void 0&&t.ownerKinds.includes(r)&&(t.transportIdentities===void 0||i!==void 0&&t.transportIdentities.includes(i))},Y=(e=de())=>{let t=async(t,n)=>{try{return{ok:!0,value:await e.transaction(async e=>{let r=await e.getBlobRef(p(t));return!r||n!==void 0&&r.blobID!==n?!1:(await e.deleteBlobRef(r.id),await q(e),(await e.getAllBlobRefs()).some(e=>e.blobID===r.blobID)||await e.deleteBlob(r.blobID),!0)})}}catch(e){return V(e)}};return{put:async(t,n)=>{try{U(t),H(n);let r=await G(n);return await e.transaction(async e=>{let i=await e.getBlob(t);if(i&&!await K(i,r))throw new B(`blob-id-conflict`);i||await e.putBlob({id:t,value:n,refCount:0,fingerprint:r})}),{ok:!0,value:void 0}}catch(e){return V(e)}},putAndRetain:async(t,n,r)=>{try{U(n),H(r);let i=await G(r);return await e.transaction(async e=>{let a=p(t),o=await e.getBlobRef(a);if(o&&o.blobID!==n)throw new B(`blob-id-conflict`);let s=await e.getBlob(n);if(s&&!await K(s,i))throw new B(`blob-id-conflict`);s||await e.putBlob({id:n,value:r,refCount:0,fingerprint:i}),o||await e.putBlobRef(W(t,n)),await q(e)}),{ok:!0,value:void 0}}catch(e){return V(e)}},read:async t=>{try{let n=await e.transaction(e=>e.getBlob(t));return n?{ok:!0,value:n.value}:{ok:!1,error:{code:`missing-blob`}}}catch(e){return V(e)}},readReference:async t=>{try{return{ok:!0,value:(await e.transaction(e=>e.getBlobRef(p(t))))?.blobID}}catch(e){return V(e)}},retain:async(t,n)=>{try{return U(n),await e.transaction(async e=>{let r=await e.getBlobRef(p(t));if(r&&r.blobID!==n)throw new B(`blob-id-conflict`);if(!await e.getBlob(n))throw new B(`missing-blob`);r||await e.putBlobRef(W(t,n)),await q(e)}),{ok:!0,value:void 0}}catch(e){return V(e)}},release:e=>t(e),releaseIfMatches:(e,n)=>t(e,n),reconcileReferences:async(t,n={ownerKinds:[`session`,`draft`]})=>{try{return{ok:!0,value:await e.transaction(async e=>{let r=[],i=[],a=[],o=new Map((await e.getAllBlobRefs()).map(e=>[e.id,e]));for(let[i,a]of o)J(a,n)&&t.get(i)!==a.blobID&&(await e.deleteBlobRef(i),r.push(i));for(let[r,s]of t){let t=ue(r);if(!t||!n.ownerKinds.includes(t.ownerKind)||n.transportIdentities!==void 0&&!n.transportIdentities.includes(t.transportIdentity)){a.push(r);continue}let c=o.get(r);if(!await e.getBlob(s)){a.push(r);continue}(!c||c.blobID!==s)&&(await e.putBlobRef({id:r,blobID:s,...t}),i.push(r))}return await q(e,!0),{released:r,repaired:i,missing:a}})}}catch(e){return V(e)}},reconcileOwnerReferences:async(t,n)=>{let r=new Map;for(let[e,i]of n)r.set(p({transportIdentity:t.transportIdentity,owner:t.owner,attachmentOccurrenceRefID:e}),i);try{return{ok:!0,value:await e.transaction(async e=>{let n=0,i=new Set;for(let a of await e.getAllBlobRefs())a.transportIdentity===t.transportIdentity&&a.ownerKind===t.owner.kind&&a.ownerID===t.owner.ownerID&&r.get(a.id)!==a.blobID&&(await e.deleteBlobRef(a.id),i.add(a.blobID),n++);await q(e);let a=await e.getAllBlobRefs();for(let t of i)a.some(e=>e.blobID===t)||await e.deleteBlob(t);return n})}}catch(e){return V(e)}},discardUnreferenced:async t=>{try{return{ok:!0,value:await e.transaction(async e=>!await e.getBlob(t)||(await e.getAllBlobRefs()).some(e=>e.blobID===t)?!1:(await e.deleteBlob(t),!0))}}catch(e){return V(e)}}}},de=(e=oe)=>({transaction:async t=>{let n=await X(e),r=n.transaction([ce,le],`readwrite`),i=r.objectStore(ce),a=r.objectStore(le),o=e=>new Promise((t,n)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>n(e.error??r.error??Error(`IndexedDB request failed`))}),s=new Promise((e,t)=>{r.oncomplete=()=>e(),r.onabort=()=>t(r.error??new DOMException(`aborted`,`AbortError`)),r.onerror=()=>{console.error(`Input draft IndexedDB transaction error`,r.error)}}),c;try{let e=await t({getBlob:e=>o(i.get(e)),getAllBlobs:()=>o(i.getAll()),putBlob:async e=>{await o(i.put(e))},deleteBlob:async e=>{await o(i.delete(e))},getBlobRef:e=>o(a.get(e)),getAllBlobRefs:()=>o(a.getAll()),putBlobRef:async e=>{await o(a.put(e))},deleteBlobRef:async e=>{await o(a.delete(e))}});return await s,e}catch(e){c=e;try{r.abort()}catch{}try{await s}catch(e){c===void 0&&(c=e)}throw c}finally{n.close()}}}),X=e=>(e===oe?r(oe):Promise.resolve()).then(()=>new Promise((t,n)=>{if(!globalThis.indexedDB){n(new B(`database-unavailable`));return}let r=indexedDB.open(e,se),i=!1,a=()=>{i||(i=!0,n(new B(`database-unavailable`)))};r.onupgradeneeded=()=>{let e=r.result;e.objectStoreNames.contains(ce)||e.createObjectStore(ce,{keyPath:`id`}),e.objectStoreNames.contains(le)||e.createObjectStore(le,{keyPath:`id`})},r.onsuccess=()=>{let e=r.result;if(e.onversionchange=()=>e.close(),i){e.close();return}i=!0,t(e)},r.onerror=a,r.onblocked=a})),fe=()=>({drafts:{},tombstones:{},migration:{complete:!1,claimedTransportIdentity:``,captured:!1,markerCommitted:!1,cleanupComplete:!1},legacy:{entries:{}}}),pe=e=>({version:1,drafts:e.drafts,tombstones:e.tombstones,migration:e.migration,legacy:e.legacy}),me=e=>{let t=pe(e),n=he(JSON.parse(JSON.stringify(t)));return{drafts:n.drafts,tombstones:n.tombstones,migration:n.migration,legacy:n.legacy}},he=e=>{let t=j(e);if(!t)throw Error(`invalid draft snapshot`);return t},ge=e=>e instanceof Map?[...e.entries()]:Object.entries(e??{}),_e=e=>typeof e==`string`?e:a(e),ve=[`session`,`draft`,`surface`],Z=e=>({transportIdentity:e.transportIdentity,owner:{kind:e.owner.kind,ownerID:e.owner.ownerID},attachmentOccurrenceRefID:e.attachmentOccurrenceRefID}),ye=e=>JSON.parse(JSON.stringify(e)),be=e=>e.phase===`metadata`?{phase:`metadata`,error:{code:e.error.code}}:{phase:`blob`,error:{...e.error},...e.reference?{reference:Z(e.reference)}:{}},xe=e=>({status:e.status,keys:[...e.keys],errors:e.errors.map(be),cleanupErrors:e.cleanupErrors.map(be)}),Se=e=>typeof e==`number`&&Number.isSafeInteger(e)&&e>0,Ce=e=>{try{let t=JSON.parse(e);return Array.isArray(t)&&t.length===3&&typeof t[0]==`string`&&ve.includes(t[1])&&typeof t[2]==`string`&&t[0].length>0&&t[2].length>0}catch{return!1}},we=e=>[...e.attachments,...e.syntheticParts.flatMap(e=>e.attachments)].flatMap(t=>t.locator.kind===`blob`?[{reference:{transportIdentity:e.key.transportIdentity,owner:{kind:e.key.owner.kind,ownerID:e.key.owner.ownerID},attachmentOccurrenceRefID:t.attachmentRefID},attachment:ye(t)}]:[]),Te=e=>{let t=new Map;for(let n of Object.values(e))for(let e of we(n))t.set(p(e.reference),e);return t},Q=(e,t)=>({phase:`blob`,error:{...e},...t?{reference:Z(t)}:{}}),$=(e,t=[])=>({status:e,keys:t,errors:[],cleanupErrors:[]}),Ee=e=>e?.attachment.locator.kind===`blob`?e.attachment.locator.blobID:``,De=(e,t,n={})=>{let r=fe(),i=n.enabled??!0,o=0,s=!1,l=Promise.resolve(),u=new Map,d=e=>{let t=l.then(e,e);return l=t.then(()=>void 0,()=>void 0),t.then(e=>e&&typeof e==`object`&&`status`in e&&`keys`in e&&`errors`in e&&`cleanupErrors`in e?xe(e):e)},f=async(t=r.drafts)=>{let n=[],i=new Map([...Te(t)].map(([e,t])=>[e,t.attachment.locator.kind===`blob`?t.attachment.locator.blobID:``]));for(let[t,r]of u){if(i.get(t)===r.expectedBlobID){u.delete(t);continue}let a=await e.releaseIfMatches(Z(r.reference),r.expectedBlobID);a.ok?u.delete(t):n.push(Q(a.error,r.reference))}return n},m=async(t,n,r,i)=>{let a=Z(t),s=await e.releaseIfMatches(a,n);s.ok||(u.set(p(a),{reference:Z(a),expectedBlobID:n,generation:o,reason:i}),r.push(Q(s.error,a)))},h=async(t,n)=>{let r=t.attachment.locator.kind===`blob`?t.attachment.locator.blobID:``,i=Z(t.reference),a=ye(t.attachment),o=await e.readReference(i);if(!o.ok)return{acquired:!1,error:Q(o.error,i)};if(o.value&&o.value!==r)return{acquired:!1,error:Q({code:`reference-conflict`},i)};if(o.value===r){let t=await e.read(r);if(t.ok)return{acquired:!1};if(t.error.code!==`missing-blob`)return{acquired:!1,error:Q(t.error,i)};let o=await n?.(Z(i),ye(a));if(o===void 0)return{acquired:!1,error:Q({code:`runtime-value-missing`},i)};let s=await e.putAndRetain(i,r,o);return s.ok?{acquired:!0}:{acquired:!1,error:Q(s.error,i)}}let s=await e.read(r);if(s.ok){let t=await e.retain(i,r);return t.ok?{acquired:!0}:{acquired:!1,error:Q(t.error,i)}}if(s.error.code!==`missing-blob`)return{acquired:!1,error:Q(s.error,i)};let c=await n?.(Z(i),ye(a));if(c===void 0)return{acquired:!1,error:Q({code:`runtime-value-missing`},i)};let l=await e.putAndRetain(i,r,c);return l.ok?{acquired:!0}:{acquired:!1,error:Q(l.error,i)}};return{seed:t=>d(async()=>{if(!i)return $(`disabled`);if(s)return{...$(`failed`),errors:[Q({code:`invalid-record`})]};let n;try{if(!t)n=fe();else{let e=he(JSON.parse(JSON.stringify(t)));n={drafts:e.drafts,tombstones:e.tombstones,migration:e.migration,legacy:e.legacy}}}catch{return{...$(`failed`),errors:[Q({code:`invalid-record`})]}}let a=Te(n.drafts),o=await e.reconcileReferences(new Map([...a].map(([e,t])=>[e,Ee(t)])),{ownerKinds:ve});return o.ok?(r=n,s=!0,{...$(`committed`),errors:o.value.missing.map(e=>Q({code:`missing-blob`},a.get(e)?.reference))}):{...$(`failed`),errors:[Q(o.error)]}}),commit:e=>{let n=[...ge(e.drafts).map(([e])=>e),...(e.delete??[]).map(_e)];return i?d(async()=>{if(!s)return $(`unseeded`,n);if(!i)return $(`disabled`,n);let l=o,u=[],d=me(r),g=ge(e.drafts),_=ge(e.tombstones),v=(e.delete??[]).map(_e);if(g.some(([e,t])=>!Ce(e)||!Se(t.revision))||_.some(([e,t])=>!Ce(e)||!Se(t))||v.some(e=>!Ce(e))||new Set(g.map(([e])=>e)).size!==g.length||_.some(([e])=>g.some(([t])=>t===e)))return{...$(`failed`,n),errors:[Q({code:`invalid-record`})]};try{for(let[e,t]of g){let n=c(t);if(!n||e!==a(n.key))throw Error(`invalid draft record`);d.drafts[e]=n,delete d.tombstones[e]}for(let e of v)delete d.drafts[e];for(let[e,t]of _)d.tombstones[e]=t;e.migration&&(d.migration=e.migration),e.legacy&&(d.legacy=e.legacy);let t=he(pe(d));d.drafts=t.drafts,d.tombstones=t.tombstones,d.migration=t.migration,d.legacy=t.legacy}catch{return{...$(`failed`,n),errors:[Q({code:`invalid-record`})],cleanupErrors:u}}if(!await e.isCurrent())return $(`stale`,n);let y=Te(r.drafts),b=Te(d.drafts);u=await f(d.drafts);let x=[];for(let[t,r]of b){let i=y.get(t);if((i?.attachment.locator.kind===`blob`?i.attachment.locator.blobID:void 0)===(r.attachment.locator.kind===`blob`?r.attachment.locator.blobID:void 0))continue;let a=await h(r,e.resolveBlobValue);if(a.error){for(let e of x.reverse())await m(e,Ee(b.get(p(e))),u,`acquire-failed`);return{...$(`failed`,n),errors:[a.error],cleanupErrors:u}}a.acquired&&x.push(r.reference)}if(!await e.isCurrent()){for(let e of x.reverse())await m(e,Ee(b.get(p(e))),u,`stale`);return{...$(`stale`,n),cleanupErrors:u}}if(!i||l!==o){for(let e of x.reverse())await m(e,Ee(b.get(p(e))),u,`disabled`);return{...$(`disabled`,n),cleanupErrors:u}}let S=await t.persist(pe(d));if(!S.ok){for(let e of x.reverse())await m(e,Ee(b.get(p(e))),u,`metadata-failed`);return{...$(`failed`,n),errors:[{phase:`metadata`,error:S.error}],cleanupErrors:u}}r=d;for(let[e,t]of y)b.has(e)||await m(t.reference,t.attachment.locator.kind===`blob`?t.attachment.locator.blobID:``,u,`metadata-committed`);return{...$(`committed`,n),cleanupErrors:u}}):Promise.resolve(xe($(`disabled`,n)))},reconcile:()=>d(async()=>{if(!s)return $(`unseeded`);if(!i)return $(`disabled`);let t=await f(),n=new Map([...Te(r.drafts)].map(([e,t])=>[e,t.attachment.locator.kind===`blob`?t.attachment.locator.blobID:``])),a=await e.reconcileReferences(n,{ownerKinds:ve}),o=a.ok?a.value.missing.map(e=>Q({code:`missing-blob`},Te(r.drafts).get(e)?.reference)):[Q(a.error)];return{status:a.ok?`committed`:`failed`,keys:[],errors:o,cleanupErrors:t}}),retryCleanup:()=>d(async()=>({...$(`committed`),cleanupErrors:await f()})),flush:()=>l,setEnabled:async e=>{if(!e){i=!1,o+=1,t.cancelPending?.(),await t.setEnabled?.(!1),await l,await t.flush?.();return}await t.setEnabled?.(!0),i=!0,o+=1}}},Oe=`yuri-composer-reference-draft`,ke=`yuri-pasted-text-draft`,Ae=e=>Array.from(e).length,je=e=>typeof e==`object`&&!!e&&(Object.getPrototypeOf(e)===Object.prototype||Object.getPrototypeOf(e)===null),Me=(e,t)=>typeof e==`string`&&e.length>0&&e.length<=t,Ne=(e,t)=>{let n=[],r=[],i=0;for(let a=0;a<Math.min(t.length,m.referenceCount);a+=1){let o=t[a];if(!(!je(o)||!Me(o.id,m.idLength)||!Me(o.token,m.displayLength)||typeof o.text!=`string`||o.text.length>m.pastePayloadLength||typeof o.characterCount!=`number`||!Number.isSafeInteger(o.characterCount)||o.characterCount!==Ae(o.text)||typeof o.index!=`number`||!Number.isSafeInteger(o.index)||o.index<1))for(let t=e.indexOf(o.token);t>=0&&n.length<m.referenceCount;t=e.indexOf(o.token,t+o.token.length)){let e=t+o.token.length;if(r.some(n=>n.start<e&&n.end>t)||i+o.text.length>m.totalPastePayloadLength)continue;let a=n.filter(e=>e.id.startsWith(`${o.id}:`)).length;n.push({id:`${o.id}:${a}`,kind:`paste`,start:t,end:e,display:o.token,text:o.text,characterCount:o.characterCount,index:o.index}),r.push({start:t,end:e}),i+=o.text.length}}return n.sort((e,t)=>e.start-t.start)},Pe=e=>{try{let t=JSON.parse(e);if(!je(t)||typeof t.text!=`string`)return{text:e,references:[]};if(t.type===Oe||t.type===`openchamber-composer-reference-draft`)return(t.version===2?o(t.text,t.references):void 0)??{text:t.text,references:[]};if(t.type===ke||t.type===`openchamber-pasted-text-draft`){let e=t.version===1&&Array.isArray(t.references)?Ne(t.text,t.references):[];return o(t.text,e)??{text:t.text,references:[]}}}catch{}return{text:e,references:[]}},Fe=`file://`,Ie=e=>{let t=e.replace(/\\/g,`/`);return/^[A-Za-z]:/.test(t)&&(t=`/${t}`),t.split(`/`).map((e,t)=>t===1&&/^[A-Za-z]:$/.test(e)?e:encodeURIComponent(e)).join(`/`)},Le=e=>{let t=e.replace(/\\/g,`/`).trim();return t.toLowerCase().startsWith(Fe)?t:`${Fe}${Ie(t)}`},Re=(e,t)=>`${e}\u0000${t}`,ze=e=>new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(r.result),r.onerror=()=>n(r.error??Error(`Failed to read file`)),r.onabort=()=>n(Error(`File read aborted`)),r.readAsDataURL(e)}),Be=e=>{if(!e.startsWith(`data:`))return 0;let t=e.indexOf(`,`);if(t<0)return 0;let n=e.slice(0,t).toLowerCase(),r=e.slice(t+1);if(!n.endsWith(`;base64`))return 0;let i=0;return r.endsWith(`==`)?i=2:r.endsWith(`=`)&&(i=1),Math.max(0,Math.floor(r.length*3/4)-i)},Ve=(e,t)=>e===t?!0:!e||!t?!1:e.filePath===t.filePath&&e.fileName===t.fileName&&e.relativePath===t.relativePath&&e.fileSize===t.fileSize&&e.selection?.startLine===t.selection?.startLine&&e.selection?.endLine===t.selection?.endLine&&e.selection?.text===t.selection?.text,He=e=>({version:1,key:e,revision:1,text:``,attachments:[],syntheticParts:[],mentions:[]}),Ue=(e,t)=>t.flatMap(t=>{let n=`@${t}`,r=[],i=e.indexOf(n);for(;i>=0;)r.push({kind:`file`,value:t,path:t,label:t,range:{start:i,end:i+n.length}}),i=e.indexOf(n,i+n.length);return r}),We=(r={})=>{let o=r.sink??O(),p=r.repository??R(o),m=r.coordinator??z(o),g=r.blobStore??Y(),_=r.durability??De(g,m,{enabled:r.persistenceEnabled??!0}),v=new Map,y=new Map,b=new Map,x=new Map,S=new Map,C=new Set,w=new Set,T,E,D=0,k=0,ee=!1,te=!1,ne,A=new Set,j=new Map,M=new Set;return n()((n,o)=>{let m=e=>v.set(e,(v.get(e)??0)+1),O=(...e)=>{for(let t of e)b.set(t,(b.get(t)??0)+1),x.delete(t)},N=e=>c(e),P=()=>r.runtimeCapture?.()??{transportIdentity:e(),generation:t()},F=e=>{let t=P();return t.transportIdentity===e.transportIdentity&&t.generation===e.generation},I=e=>[...e.attachments,...e.syntheticParts.flatMap(e=>e.attachments)],re=e=>new Set(I(e).map(e=>e.attachmentRefID)),ie=(e,t,n)=>{let r=re(n);return{draftAttachmentViews:{...e.draftAttachmentViews,[t]:Object.fromEntries(Object.entries(e.draftAttachmentViews[t]??{}).filter(([e])=>r.has(e)))},draftMissingAttachmentRefIDs:{...e.draftMissingAttachmentRefIDs,[t]:(e.draftMissingAttachmentRefIDs[t]??[]).filter(e=>r.has(e))}}},L=()=>r.createID?.()??h(),ae=async(e,t)=>{let n=t instanceof File?t:new File([t],e.filename,{type:e.mimeType});return{id:e.attachmentID,file:n,dataUrl:typeof t==`string`?t:await ze(n),mimeType:e.mimeType,filename:e.filename,size:e.size,source:e.source,...e.serverPath?{serverPath:e.serverPath}:{},...e.vscodePath?{vscodePath:e.vscodePath}:{},...e.vscodeSource?{vscodeSource:e.vscodeSource}:{}}},R=e=>{let t=e.errors[0]??e.cleanupErrors[0];return t?.phase===`metadata`||t?.phase===`blob`&&[`blob-id-conflict`,`database-unavailable`,`invalid-value`,`missing-blob`,`quota-exceeded`,`transaction-aborted`,`transaction-failed`].includes(t.error.code)?t.error.code:`unavailable`},z=(e,t)=>{let r=o(),i=D,a=t??P(),s=[...new Set(e)];if(s.forEach(e=>w.delete(e)),T&&w.size===0&&(clearTimeout(T),T=void 0,E=void 0),!r.persistenceEnabled)return s.forEach(e=>A.add(e)),Promise.resolve({status:`disabled`,keys:s,errors:[],cleanupErrors:[]});let c=new Map(s.map(e=>[e,v.get(e)??0])),l=new Map(s.map(e=>[e,r.drafts[e]?.revision??r.tombstones[e]??0])),u=s.filter(e=>r.drafts[e]),d=Object.fromEntries(u.map(e=>[e,r.draftPersistence[e]?.status===`error`?r.draftPersistence[e]:{status:`saving`,revision:l.get(e)}])),f=Object.fromEntries(u.map(e=>[e,r.draftAttachmentPersistence[e]?.status===`error`?r.draftAttachmentPersistence[e]:{status:`saving`,revision:l.get(e)}]));n(e=>({draftPersistence:{...e.draftPersistence,...d},draftAttachmentPersistence:{...e.draftAttachmentPersistence,...f}})),te||s.forEach(e=>A.add(e));let p=(async()=>{let e=o(),t=await _.commit({drafts:Object.fromEntries(s.flatMap(t=>e.drafts[t]?[[t,e.drafts[t]]]:[])),tombstones:Object.fromEntries(s.flatMap(t=>e.tombstones[t]?[[t,e.tombstones[t]]]:[])),delete:s.filter(t=>!e.drafts[t]),migration:e.migration,legacy:{...e.legacyNewDraft?{new:e.legacyNewDraft}:{},entries:e.legacyDraftEntries},resolveBlobValue:t=>{for(let[n,r]of Object.entries(e.drafts))if(r.key.transportIdentity===t.transportIdentity&&r.key.owner.kind===t.owner.kind&&r.key.owner.ownerID===t.owner.ownerID)return e.draftAttachmentViews[n]?.[t.attachmentOccurrenceRefID]?.file},isCurrent:()=>D===i&&o().persistenceEnabled&&F(a)&&s.every(e=>(v.get(e)??0)===c.get(e)&&(o().drafts[e]?.revision??o().tombstones[e]??0)===l.get(e))}),r=D===i&&o().persistenceEnabled&&F(a);return(!r||t.status===`unseeded`||t.status===`stale`||t.status===`disabled`)&&s.forEach(e=>A.add(e)),r&&n(e=>{let n={...e.draftPersistence};for(let e of u){if((v.get(e)??0)!==c.get(e))continue;let r=l.get(e);if(t.status===`committed`)n[e]={status:`saved`,revision:r};else if(t.status===`unseeded`||t.status===`stale`||t.status===`disabled`)continue;else n[e]={status:`error`,revision:r,errorCode:R(t)}}let r={...e.draftAttachmentPersistence};for(let e of u){if((v.get(e)??0)!==c.get(e))continue;let n=l.get(e);r[e]=t.status===`committed`&&t.cleanupErrors.length===0?{status:`saved`,revision:n}:t.status===`failed`||t.cleanupErrors.length>0?{status:`error`,revision:n,errorCode:R(t)}:r[e]??{status:`idle`,revision:n}}return{draftPersistence:n,draftAttachmentPersistence:r}}),t})();return C.add(p),p.then(()=>C.delete(p),()=>C.delete(p)),p},oe=e=>{let t=o(),r=Object.fromEntries(e.flatMap(e=>{let n=t.drafts[e];return n?[[e,{status:`saving`,revision:n.revision}]]:[]}));Object.keys(r).length&&n(e=>({draftPersistence:{...e.draftPersistence,...r}}))},se=()=>{T&&clearTimeout(T),T=void 0;let e=[...w];w.clear();let t=E;return E=void 0,e.length?z(e,t).then(()=>void 0):Promise.resolve()},ce=e=>{if(!o().persistenceEnabled){A.add(e);return}w.add(e),oe([e]),!T&&(E=P(),T=setTimeout(()=>{se()},40))},le=e=>{let t=[...e];return t.forEach(e=>w.delete(e)),T&&w.size===0&&(clearTimeout(T),T=void 0,E=void 0),z(t)},B=(e,t,r,i=`immediate`)=>{let s=a(e),c=o().drafts[s];if(!c||r!==void 0&&c.revision!==r)return;let l=N(t(c));if(!(!l||a(l.key)!==s))return m(s),n(e=>({drafts:{...e.drafts,[s]:l},...ie(e,s,l)})),i===`deferred`?ce(s):le([s]),l},V=e=>e?l(e):void 0,H=(e=[])=>JSON.parse(JSON.stringify(e)),U=(e,t,n,r=!1,i=!1)=>({status:e,...V(n)?{record:V(n)}:{},errors:H(t?.errors),cleanupErrors:H(t?.cleanupErrors),current:r,durable:i}),W=(e,t,n,r,i=!1,a=!1)=>({status:e,errors:H(t?.errors),cleanupErrors:H(t?.cleanupErrors),current:i,durable:a,source:V(n),destination:V(r)}),G=e=>e.status,K=e=>typeof e==`number`&&Number.isSafeInteger(e)&&e>0,q=(e,...t)=>{let n={...e};for(let e of t)delete n[e];return n},ue=async(e,t)=>{let n={},r=o().draftAttachmentViews[a(e.key)]??{};for(let i of I(e)){let e;if(i.locator.kind===`url`){let n=t?.get(i.attachmentRefID);e=n===void 0?i.locator.url:n}else e=t?.get(i.attachmentRefID)??r[i.attachmentRefID]?.file??(typeof r[i.attachmentRefID]?.dataUrl==`string`&&u(r[i.attachmentRefID].dataUrl)?r[i.attachmentRefID].dataUrl:void 0);if(i.locator.kind===`url`&&e!==void 0&&(e!==i.locator.url||!u(e))||i.locator.kind===`blob`&&e!==void 0&&!(e instanceof Blob)&&!(typeof e==`string`&&u(e)))return;e!==void 0&&(n[i.attachmentRefID]=await ae(i,e))}return n},J=e=>e?a(e):`legacy-unowned`,Y=e=>j.get(e)??0,de=e=>{j.set(e,Y(e)+1)},X=(e,t,r=!1)=>{r&&de(e),n(n=>{let r=t(n.attachmentBuckets[e]??[]);return{attachmentBuckets:{...n.attachmentBuckets,[e]:r},...J(n.activeAttachmentDraft)===e?{attachedFiles:r}:{}}})};return{drafts:{},tombstones:{},draftHydration:{},draftPersistence:{},draftAttachmentViews:{},draftMissingAttachmentRefIDs:{},draftAttachmentPersistence:{},persistenceEnabled:r.persistenceEnabled??!0,legacyDraftEntries:{},migration:{complete:!1,claimedTransportIdentity:``},captureDraftRuntime:()=>P(),commitDraftSnapshot:async e=>{let t=a(e.key),r=e.runtime;if(r.transportIdentity!==e.key.transportIdentity||!F(r))return U(`stale`,void 0);let i=o(),s=i.drafts[t],c=i.tombstones[t]??0;if(e.expectedRevision!==`absent`&&!K(e.expectedRevision)||!Number.isSafeInteger(c)||c<0)return U(`failed`,void 0);if(e.expectedRevision===`absent`?s:s?.revision!==e.expectedRevision)return U(`conflict`,void 0,s);let u=e.expectedRevision===`absent`?c+1:e.expectedRevision+1;if(!K(u))return U(`failed`,void 0);let d=N({version:1,key:e.key,revision:u,...e.snapshot});if(!d)return U(`failed`,void 0);let f=await ue(d,e.values);if(!f)return U(`failed`,void 0);let p=v.get(t)??0,h=s?.revision??c,g=await _.commit({drafts:{[t]:d},isCurrent:()=>F(r)&&(v.get(t)??0)===p&&(o().drafts[t]?.revision??o().tombstones[t]??0)===h,resolveBlobValue:t=>e.values?.get(t.attachmentOccurrenceRefID)});if(g.status!==`committed`)return U(G(g),g,s);let y=(v.get(t)??0)===p&&(o().drafts[t]?.revision??o().tombstones[t]??0)===h,b=F(r);if(!y)return b||n(e=>({draftAttachmentViews:q(e.draftAttachmentViews,t),draftMissingAttachmentRefIDs:q(e.draftMissingAttachmentRefIDs,t),draftHydration:q(e.draftHydration,t),draftPersistence:q(e.draftPersistence,t),draftAttachmentPersistence:q(e.draftAttachmentPersistence,t)})),U(`stale`,g,d,!1,!0);let x=l(d);return x?(m(t),O(t),n(e=>({drafts:{...e.drafts,[t]:x},tombstones:(()=>{let n={...e.tombstones};return delete n[t],n})(),draftAttachmentViews:b?{...e.draftAttachmentViews,[t]:f}:q(e.draftAttachmentViews,t),draftMissingAttachmentRefIDs:b?{...e.draftMissingAttachmentRefIDs,[t]:[]}:q(e.draftMissingAttachmentRefIDs,t),draftHydration:b?e.draftHydration:q(e.draftHydration,t),draftPersistence:b?{...e.draftPersistence,[t]:{status:`saved`,revision:x.revision}}:q(e.draftPersistence,t),draftAttachmentPersistence:b?{...e.draftAttachmentPersistence,[t]:g.cleanupErrors.length?{status:`error`,revision:x.revision,errorCode:R(g)}:{status:`saved`,revision:x.revision}}:q(e.draftAttachmentPersistence,t)})),U(b?`committed`:`stale`,g,x,b,!0)):U(`failed`,g)},deleteDraftSnapshot:async e=>{let t=a(e.key),r=e.runtime;if(r.transportIdentity!==e.key.transportIdentity||!F(r))return U(`stale`,void 0);let i=o(),s=i.drafts[t],c=i.tombstones[t]??0;if(!K(e.expectedRevision)||!Number.isSafeInteger(c)||c<0)return U(`failed`,void 0);if(!s||s.revision!==e.expectedRevision)return U(`conflict`,void 0);let l=e.expectedRevision+1;if(!K(l))return U(`failed`,void 0);let u=v.get(t)??0,d=s.revision,f=Math.max(c,l),p=await _.commit({tombstones:{[t]:f},delete:[t],isCurrent:()=>F(r)&&(v.get(t)??0)===u&&o().drafts[t]?.revision===d&&(o().tombstones[t]??0)===c});if(p.status!==`committed`)return U(G(p),p);let h=(v.get(t)??0)===u&&o().drafts[t]?.revision===d&&(o().tombstones[t]??0)===c,g=F(r);return h?(m(t),O(t),n(e=>{let n={...e.drafts};return delete n[t],{drafts:n,tombstones:{...e.tombstones,[t]:Math.max(e.tombstones[t]??0,f)},draftAttachmentViews:q(e.draftAttachmentViews,t),draftMissingAttachmentRefIDs:q(e.draftMissingAttachmentRefIDs,t),draftHydration:q(e.draftHydration,t),draftPersistence:q(e.draftPersistence,t),draftAttachmentPersistence:q(e.draftAttachmentPersistence,t)}}),U(g?`committed`:`stale`,p,void 0,g,!0)):(g||n(e=>({draftAttachmentViews:q(e.draftAttachmentViews,t),draftMissingAttachmentRefIDs:q(e.draftMissingAttachmentRefIDs,t),draftHydration:q(e.draftHydration,t),draftPersistence:q(e.draftPersistence,t),draftAttachmentPersistence:q(e.draftAttachmentPersistence,t)})),U(`stale`,p,void 0,!1,!0))},finalizeDraftOwnership:async e=>{let t=a(e.source),r=a(e.destination),i=e.runtime,s=o(),c=s.drafts[t],u=s.drafts[r];if(t===r||e.destination.owner.kind!==`session`||e.source.transportIdentity!==i.transportIdentity||e.destination.transportIdentity!==i.transportIdentity||!F(i))return W(`stale`,void 0,c,u);if(!K(e.expectedSourceRevision))return W(`failed`,void 0,c,u);if(!c||c.revision!==e.expectedSourceRevision||u)return W(`conflict`,void 0,c,u);let d=v.get(t)??0,f=v.get(r)??0,p=s.tombstones[t]??0,h=s.tombstones[r]??0;if(!Number.isSafeInteger(p)||p<0||!Number.isSafeInteger(h)||h<0)return W(`failed`,void 0,c,u);let g=Math.max(c.revision+1,h+1);if(!K(g))return W(`failed`,void 0,c,u);let y=N(e.disposition===`preserve`?{...c,key:e.destination,revision:g}:{...He(e.destination),revision:g});if(!y)return W(`failed`,void 0,c,u);let b=await _.commit({drafts:{[r]:y},tombstones:{[t]:Math.max(p,g)},delete:[t],isCurrent:()=>F(i)&&(v.get(t)??0)===d&&(v.get(r)??0)===f&&o().drafts[t]?.revision===c.revision&&!o().drafts[r]&&(o().tombstones[t]??0)===p&&(o().tombstones[r]??0)===h,resolveBlobValue:e=>s.draftAttachmentViews[t]?.[e.attachmentOccurrenceRefID]?.file});if(b.status!==`committed`)return W(G(b),b,c,u);let x=(v.get(t)??0)===d&&o().drafts[t]?.revision===c.revision&&(o().tombstones[t]??0)===p,S=(v.get(r)??0)===f&&!o().drafts[r]&&(o().tombstones[r]??0)===h,C=F(i),w=l(y);if(!w)return W(`failed`,b,c,u);if(C&&!x&&!S)return W(`stale`,b,c,y,!1,!0);x&&(m(t),O(t)),S&&(m(r),O(r)),n(n=>{let i=n.drafts,a=n.tombstones;(x||S)&&(i={...i}),(x||S)&&(a={...a}),x&&(delete i[t],a[t]=Math.max(a[t]??0,g)),S&&(i[r]=w,delete a[r]);let o=n.draftHydration,s=n.draftPersistence,c=n.draftAttachmentViews,l=n.draftMissingAttachmentRefIDs,u=n.draftAttachmentPersistence;return C?(x&&(o=q(o,t),s=q(s,t),c=q(c,t),l=q(l,t),u=q(u,t)),S&&(o=q(o,r),s={...q(s,r),[r]:{status:`saved`,revision:w.revision}},c=q(c,r),l=q(l,r),u={...q(u,r),[r]:b.cleanupErrors.length?{status:`error`,revision:w.revision,errorCode:R(b)}:{status:`saved`,revision:w.revision}},C&&x&&e.disposition===`preserve`&&(c={...c,[r]:n.draftAttachmentViews[t]??{}},l={...l,[r]:n.draftMissingAttachmentRefIDs[t]??[]}))):(o=q(o,t,r),s=q(s,t,r),c=q(c,t,r),l=q(l,t,r),u=q(u,t,r)),{drafts:i,tombstones:a,draftHydration:o,draftPersistence:s,draftAttachmentViews:c,draftMissingAttachmentRefIDs:l,draftAttachmentPersistence:u}});let T=x&&S&&C;return W(T?`committed`:`stale`,b,c,y,T,!0)},flushDraftPersistence:async()=>{for(await se();C.size;)await Promise.all([...C]);await _.flush()},ensureDraft:e=>{let t=a(e),r=o().drafts[t];if(r)return r;let i=N({...He(e),revision:(o().tombstones[t]??0)+1});if(!i)throw Error(`Invalid empty draft`);return m(t),n(e=>({drafts:{...e.drafts,[t]:i}})),le([t]),i},getDraft:e=>o().drafts[a(e)],setDraftText:(e,t)=>{let n=o().getDraft(e)??o().ensureDraft(e);return B(e,e=>({...e,revision:e.revision+1,text:t,mentions:e.mentions.filter(e=>e.range.end<=t.length&&t.slice(e.range.start,e.range.end)===`@${e.value}`),composerReferences:[]}),n.revision,`deferred`)??n},setDraftComposerDocument:(e,t)=>{let n=o().getDraft(e)??o().ensureDraft(e);return o().setDraftComposerState(e,{document:t,mentions:n.mentions})},setDraftComposerState:(e,t)=>{let n=o().getDraft(e)??o().ensureDraft(e);return B(e,e=>({...e,revision:e.revision+1,text:t.document.text,composerReferences:t.document.references,mentions:t.mentions}),n.revision,`deferred`)},replaceDraft:(e,t,n)=>B(e,e=>({version:1,key:e.key,revision:e.revision+1,text:n.text,attachments:n.attachments,syntheticParts:n.syntheticParts,mentions:n.mentions,...n.composerReferences===void 0?{}:{composerReferences:n.composerReferences}}),t),setDraftMentions:(e,t)=>B(e,e=>({...e,revision:e.revision+1,mentions:t})),addDraftMention:(e,t)=>B(e,e=>({...e,revision:e.revision+1,mentions:[...e.mentions,t]})),removeDraftMention:(e,t)=>B(e,e=>({...e,revision:e.revision+1,mentions:e.mentions.filter(e=>e.value!==t)})),setDraftSyntheticParts:(e,t)=>B(e,e=>({...e,revision:e.revision+1,syntheticParts:t})),consumeDraftSyntheticParts:(e,t)=>{let n=o().getDraft(e);if(!n)return null;let r=n.syntheticParts.filter(e=>!t?.(e)),i=n.syntheticParts.filter(e=>t?.(e));return B(e,e=>({...e,revision:e.revision+1,syntheticParts:i}),n.revision)?r:null},setDraftAttachments:(e,t)=>B(e,e=>({...e,revision:e.revision+1,attachments:t})),addDraftLocalAttachment:async(e,t,r={})=>{let c=o().getDraft(e);if(r.partID&&!c?.syntheticParts.some(e=>e.partID===r.partID))return;let l=a(e),u=v.get(l)??0,d=o().tombstones[l]??0,f=P(),p=t instanceof File?t:new File([t],r.filename??`attachment`,{type:t.type}),h;try{h=await ze(p)}catch{let e=o().drafts[l];if(F(f)&&(o().tombstones[l]??0)===d&&(e?a(e.key)===l:(v.get(l)??0)===u)&&(!r.partID||e?.syntheticParts.some(e=>e.partID===r.partID))){let t=e?.revision??o().tombstones[l]??0;n(e=>({draftAttachmentPersistence:{...e.draftAttachmentPersistence,[l]:{status:`error`,revision:t,errorCode:`transaction-failed`}}}))}return}if(!F(f)||(o().tombstones[l]??0)!==d)return;let g=o().drafts[l];if(!g&&(v.get(l)??0)!==u)return;let _=g??o().ensureDraft(e);if(a(_.key)!==l||r.partID&&!_.syntheticParts.some(e=>e.partID===r.partID))return;let y=r.attachmentID??L(),b=r.partID?s(r.partID,y):i(y),x=L(),S={attachmentID:y,attachmentRefID:b,filename:r.filename??(t instanceof File?t.name:`attachment`),mimeType:t.type,size:t.size,locator:{kind:`blob`,blobID:x},source:r.source??`local`,...r.vscodePath?{vscodePath:r.vscodePath}:{},...r.vscodeSource?{vscodeSource:r.vscodeSource}:{}},C=r.partID?{..._,revision:_.revision+1,syntheticParts:_.syntheticParts.map(e=>e.partID===r.partID?{...e,attachments:[...e.attachments,S]}:e)}:{..._,revision:_.revision+1,attachments:[..._.attachments,S]},w=N(C);if(!w)return;m(l);let T={id:y,file:p,dataUrl:h,mimeType:S.mimeType,filename:S.filename,size:S.size,source:S.source,...r.vscodePath?{vscodePath:r.vscodePath}:{},...r.vscodeSource?{vscodeSource:r.vscodeSource}:{}};return n(e=>({drafts:{...e.drafts,[l]:w},draftAttachmentViews:{...e.draftAttachmentViews,[l]:{...e.draftAttachmentViews[l],[b]:T}}})),await z([l]),S},addDraftDurableAttachment:(e,t)=>{let r=o().getDraft(e)??o().ensureDraft(e);if(t.partID&&!r.syntheticParts.some(e=>e.partID===t.partID))return;let c=t.attachmentID??L(),l=t.partID?s(t.partID,c):i(c),u={attachmentID:c,attachmentRefID:l,filename:t.filename,mimeType:t.mimeType,size:t.size,source:t.source,locator:{kind:`url`,url:t.url},...t.serverPath?{serverPath:t.serverPath}:{},...t.vscodePath?{vscodePath:t.vscodePath}:{},...t.vscodeSource?{vscodeSource:t.vscodeSource}:{}},d=t.partID?{...r,revision:r.revision+1,syntheticParts:r.syntheticParts.map(e=>e.partID===t.partID?{...e,attachments:[...e.attachments,u]}:e)}:{...r,revision:r.revision+1,attachments:[...r.attachments,u]},f=N(d);if(!f)return;let p=a(e);m(p);let h={id:c,file:new File([],u.filename,{type:u.mimeType}),dataUrl:t.url,mimeType:u.mimeType,filename:u.filename,size:u.size,source:u.source,...u.serverPath?{serverPath:u.serverPath}:{},...u.vscodePath?{vscodePath:u.vscodePath}:{},...u.vscodeSource?{vscodeSource:u.vscodeSource}:{}};return n(e=>({drafts:{...e.drafts,[p]:f},draftAttachmentViews:{...e.draftAttachmentViews,[p]:{...e.draftAttachmentViews[p],[l]:h}}})),z([p]),u},getDraftAttachmentViews:e=>{let t=a(e),n=o().drafts[t],r=o().draftAttachmentViews[t]??{};return n?I(n).flatMap(e=>r[e.attachmentRefID]?[r[e.attachmentRefID]]:[]):[]},retryDraftAttachmentPersistence:async e=>{let t=a(e);if(!o().persistenceEnabled||!o().drafts[t]&&!o().tombstones[t])return;let r=await _.retryCleanup();r.cleanupErrors.length&&n(e=>({draftAttachmentPersistence:{...e.draftAttachmentPersistence,[t]:{status:`error`,revision:e.drafts[t]?.revision??e.tombstones[t],errorCode:R(r)}}})),await z([t])},hydrateDraftAttachments:async e=>{let t=a(e),r=x.get(t);if(r)return r;let i=o().drafts[t];if(!i)return;let s=(b.get(t)??0)+1;b.set(t,s);let c=P(),l=D,u=(async()=>{n(e=>({draftHydration:{...e.draftHydration,[t]:`loading`}}));let e=()=>{if(b.get(t)!==s)return;let e=o(),r=e.draftAttachmentViews[t],i=e.draftMissingAttachmentRefIDs[t]??[];n(e=>({draftHydration:{...e.draftHydration,[t]:i.length?`degraded`:Object.keys(r??{}).length?`ready`:`idle`}}))},r={},a=[];for(let u of I(i)){let d=u.locator.kind===`url`?{ok:!0,value:u.locator.url}:await g.read(u.locator.blobID);if(!d.ok){if(d.error.code===`missing-blob`)a.push(u.attachmentRefID);else{b.get(t)===s&&D===l&&F(c)&&o().drafts[t]===i?n(e=>({draftHydration:{...e.draftHydration,[t]:`error`}})):e();return}continue}try{r[u.attachmentRefID]=await ae(u,d.value)}catch{b.get(t)===s&&D===l&&F(c)&&o().drafts[t]===i?n(e=>({draftHydration:{...e.draftHydration,[t]:`error`}})):e();return}}let u=o(),d=u.drafts[t],f=b.get(t);if(f===s&&D===l&&F(c)&&d===i)n(e=>({draftAttachmentViews:{...e.draftAttachmentViews,[t]:r},draftMissingAttachmentRefIDs:{...e.draftMissingAttachmentRefIDs,[t]:a},draftHydration:{...e.draftHydration,[t]:a.length?`degraded`:`ready`}}));else if(f===s){let e=u.draftAttachmentViews[t],r=u.draftMissingAttachmentRefIDs[t]??[];n(n=>({draftHydration:{...n.draftHydration,[t]:r.length?`degraded`:Object.keys(e??{}).length?`ready`:`idle`}}))}})();x.set(t,u);try{await u}finally{x.get(t)===u&&x.delete(t)}},removeDraftAttachment:async(e,t)=>{let r=a(e),i=o().drafts[r],s=i&&I(i).find(e=>e.attachmentRefID===t);if(!i||!s)return!1;let c=d(s)?f(i.text,[s.filename],i.mentions,i.composerReferences):void 0,l=N({...i,revision:i.revision+1,...c?.changed?{text:c.text,mentions:c.mentions,...c.composerReferences===void 0?{}:{composerReferences:c.composerReferences}}:{},attachments:i.attachments.filter(e=>e.attachmentRefID!==t),syntheticParts:i.syntheticParts.map(e=>({...e,attachments:e.attachments.filter(e=>e.attachmentRefID!==t)}))});return l?(m(r),n(e=>{let n={...e.draftAttachmentViews[r]};return delete n[t],{drafts:{...e.drafts,[r]:l},draftAttachmentViews:{...e.draftAttachmentViews,[r]:n},draftMissingAttachmentRefIDs:{...e.draftMissingAttachmentRefIDs,[r]:(e.draftMissingAttachmentRefIDs[r]??[]).filter(e=>e!==t)}}}),(await z([r])).status===`committed`):!1},replaceDraftAttachment:async(e,t,r,c)=>{let l=a(e),u=o().drafts[l],d=u&&I(u).find(e=>e.attachmentRefID===t);if(!u||!d)return;let f=P(),p=o().tombstones[l]??0,h=r instanceof File?r:new File([r],c?.filename??`attachment`,{type:r.type}),g;try{g=await ze(h)}catch{let e=o().drafts[l],r=e&&I(e).find(e=>e.attachmentRefID===t);F(f)&&(o().tombstones[l]??0)===p&&e&&r?.attachmentID===d.attachmentID&&r.attachmentRefID===d.attachmentRefID&&a(e.key)===l&&n(t=>({draftAttachmentPersistence:{...t.draftAttachmentPersistence,[l]:{status:`error`,revision:e.revision,errorCode:`transaction-failed`}}}));return}let _=o().drafts[l],v=_&&I(_).find(e=>e.attachmentRefID===t);if(!F(f)||(o().tombstones[l]??0)!==p||!_||v?.attachmentID!==d.attachmentID||v.attachmentRefID!==d.attachmentRefID||a(_.key)!==l)return;let y=_.syntheticParts.find(e=>e.attachments.some(e=>e.attachmentRefID===t)),b=L(),x={attachmentID:b,attachmentRefID:y?s(y.partID,b):i(b),filename:c?.filename??h.name,mimeType:h.type,size:h.size,locator:{kind:`blob`,blobID:L()},source:c?.source??`local`,...c?.vscodePath?{vscodePath:c.vscodePath}:{},...c?.vscodeSource?{vscodeSource:c.vscodeSource}:{}},S=N({..._,revision:_.revision+1,attachments:y?_.attachments:_.attachments.map(e=>e.attachmentRefID===t?x:e),syntheticParts:_.syntheticParts.map(e=>e.partID===y?.partID?{...e,attachments:e.attachments.map(e=>e.attachmentRefID===t?x:e)}:e)});if(!S)return;m(l);let C={id:b,file:h,dataUrl:g,mimeType:x.mimeType,filename:x.filename,size:x.size,source:x.source,...x.vscodePath?{vscodePath:x.vscodePath}:{},...x.vscodeSource?{vscodeSource:x.vscodeSource}:{}};return n(e=>{let n={...e.draftAttachmentViews[l]};return delete n[t],{drafts:{...e.drafts,[l]:S},draftAttachmentViews:{...e.draftAttachmentViews,[l]:{...n,[x.attachmentRefID]:C}},draftMissingAttachmentRefIDs:{...e.draftMissingAttachmentRefIDs,[l]:(e.draftMissingAttachmentRefIDs[l]??[]).filter(e=>e!==t)}}}),(await z([l])).status===`committed`?x:void 0},replaceDraftRootAttachments:async(e,t)=>{let n=a(e),r=P();if(r.transportIdentity!==e.transportIdentity||!F(r))return U(`stale`,void 0);let s=o().drafts[n],c=s?s.revision:`absent`,l=[],d=new Map;for(let e of t){let t=e.id,n=i(t);if(e.source===`server`&&e.dataUrl&&u(e.dataUrl))l.push({attachmentID:t,attachmentRefID:n,filename:e.filename,mimeType:e.mimeType,size:e.size,source:`server`,locator:{kind:`url`,url:e.dataUrl},...e.serverPath?{serverPath:e.serverPath}:{}}),d.set(n,e.dataUrl);else if(e.source===`vscode`&&e.vscodeSource===`file`&&e.dataUrl&&u(e.dataUrl))l.push({attachmentID:t,attachmentRefID:n,filename:e.filename,mimeType:e.mimeType,size:e.size,source:`vscode`,locator:{kind:`url`,url:e.dataUrl},...e.vscodePath?{vscodePath:e.vscodePath}:{},vscodeSource:`file`}),d.set(n,e.dataUrl);else{let r=e.file instanceof File?e.file:new File([e.file],e.filename,{type:e.mimeType}),i=L();l.push({attachmentID:t,attachmentRefID:n,filename:e.filename,mimeType:e.mimeType,size:e.size,source:e.source===`vscode`?`vscode`:`local`,locator:{kind:`blob`,blobID:i},...e.vscodePath?{vscodePath:e.vscodePath}:{},...e.vscodeSource===`selection`?{vscodeSource:`selection`}:{}}),d.set(n,r)}}let f=s?.syntheticParts??[];for(let e of f)for(let t of e.attachments)t.locator.kind===`url`&&!d.has(t.attachmentRefID)&&d.set(t.attachmentRefID,t.locator.url);let p={text:s?.text??``,attachments:l,syntheticParts:f,mentions:s?.mentions??[],...s?.composerReferences===void 0?{}:{composerReferences:s.composerReferences}};return o().commitDraftSnapshot({key:e,expectedRevision:c,snapshot:p,values:d,runtime:r})},restoreDraftRootAttachments:async(e,t)=>{let n=a(e),r=P();if(r.transportIdentity!==e.transportIdentity||!F(r))return U(`stale`,void 0);let s=o().drafts[n],c=s?s.revision:`absent`,l=new Set(t.map(e=>e.id)),d=[],f=new Map;for(let e of t){let t=e.id,n=i(t);if(e.source===`server`&&e.dataUrl&&u(e.dataUrl))d.push({attachmentID:t,attachmentRefID:n,filename:e.filename,mimeType:e.mimeType,size:e.size,source:`server`,locator:{kind:`url`,url:e.dataUrl},...e.serverPath?{serverPath:e.serverPath}:{}}),f.set(n,e.dataUrl);else if(e.source===`vscode`&&e.vscodeSource===`file`&&e.dataUrl&&u(e.dataUrl))d.push({attachmentID:t,attachmentRefID:n,filename:e.filename,mimeType:e.mimeType,size:e.size,source:`vscode`,locator:{kind:`url`,url:e.dataUrl},...e.vscodePath?{vscodePath:e.vscodePath}:{},vscodeSource:`file`}),f.set(n,e.dataUrl);else{let r=e.file instanceof File?e.file:new File([e.file],e.filename,{type:e.mimeType}),i=L();d.push({attachmentID:t,attachmentRefID:n,filename:e.filename,mimeType:e.mimeType,size:e.size,source:e.source===`vscode`?`vscode`:`local`,locator:{kind:`blob`,blobID:i},...e.vscodePath?{vscodePath:e.vscodePath}:{},...e.vscodeSource===`selection`?{vscodeSource:`selection`}:{}}),f.set(n,r)}}let p=o().draftAttachmentViews[n]??{};for(let e of s?.attachments??[])if(!l.has(e.attachmentID))if(d.push(JSON.parse(JSON.stringify(e))),e.locator.kind===`url`)f.set(e.attachmentRefID,e.locator.url);else{let t=p[e.attachmentRefID];t?.file instanceof Blob?f.set(e.attachmentRefID,t.file):typeof t?.dataUrl==`string`&&u(t.dataUrl)&&f.set(e.attachmentRefID,t.dataUrl)}let m=s?.syntheticParts??[];for(let e of m)for(let t of e.attachments)t.locator.kind===`url`&&!f.has(t.attachmentRefID)&&f.set(t.attachmentRefID,t.locator.url);let h={text:s?.text??``,attachments:d,syntheticParts:m,mentions:s?.mentions??[],...s?.composerReferences===void 0?{}:{composerReferences:s.composerReferences}};return o().commitDraftSnapshot({key:e,expectedRevision:c,snapshot:h,values:f,runtime:r})},deleteDraft:(e,t)=>{let r=a(e),i=o().drafts[r];if(!i||t!==void 0&&i.revision!==t)return!1;let s=i.revision+1;return K(s)?(m(r),O(r),n(e=>{let t={...e.drafts};delete t[r];let n={...e.draftHydration},i={...e.draftPersistence},a={...e.draftAttachmentViews},o={...e.draftMissingAttachmentRefIDs},c={...e.draftAttachmentPersistence};return delete n[r],delete i[r],delete a[r],delete o[r],delete c[r],{drafts:t,tombstones:{...e.tombstones,[r]:Math.max(e.tombstones[r]??0,s)},draftHydration:n,draftPersistence:i,draftAttachmentViews:a,draftMissingAttachmentRefIDs:o,draftAttachmentPersistence:c}}),z([r]),!0):!1},moveDraft:(e,t,r)=>{let i=a(e),s=a(t),c=o().drafts[i];if(!c||i===s||r!==void 0&&c.revision!==r||o().drafts[s]||(o().tombstones[s]??0)>=c.revision+1||[...c.attachments,...c.syntheticParts.flatMap(e=>e.attachments)].some(e=>e.locator.kind===`blob`))return;let l=N({...c,key:t,revision:c.revision+1});if(l)return m(i),m(s),O(i,s),n(e=>{let t={...e.drafts};delete t[i];let n={...e.tombstones,[i]:Math.max(e.tombstones[i]??0,l.revision)};(n[s]??0)<l.revision&&delete n[s];let r=e=>{let t={...e},n=t[i];return delete t[i],delete t[s],n===void 0?t:{...t,[s]:n}};return{drafts:{...t,[s]:l},tombstones:n,draftHydration:r(e.draftHydration),draftPersistence:r(e.draftPersistence),draftAttachmentViews:r(e.draftAttachmentViews),draftMissingAttachmentRefIDs:r(e.draftMissingAttachmentRefIDs),draftAttachmentPersistence:r(e.draftAttachmentPersistence)}}),z([i,s]),l},moveDraftWithAttachments:async(e,t,r)=>{let i=a(e),s=a(t),c=o().drafts[i];if(!c||i===s||r!==void 0&&c.revision!==r||o().drafts[s]||(o().tombstones[s]??0)>=c.revision+1)return;let l=N({...c,key:t,revision:c.revision+1});if(l)return m(i),m(s),O(i,s),n(e=>{let t={...e.drafts};delete t[i];let n={...e.tombstones,[i]:Math.max(e.tombstones[i]??0,l.revision)};(n[s]??0)<l.revision&&delete n[s];let r=e=>{let t={...e},n=t[i];return delete t[i],delete t[s],n===void 0?t:{...t,[s]:n}};return{drafts:{...t,[s]:l},tombstones:n,draftHydration:r(e.draftHydration),draftPersistence:r(e.draftPersistence),draftAttachmentViews:r(e.draftAttachmentViews),draftMissingAttachmentRefIDs:r(e.draftMissingAttachmentRefIDs),draftAttachmentPersistence:r(e.draftAttachmentPersistence)}}),(await z([i,s])).status===`committed`?l:void 0},setDraftPersistenceEnabled:async e=>{if(D+=1,!e){T&&clearTimeout(T),T=void 0,w.clear(),E=void 0,n({persistenceEnabled:!1,draftPersistence:{}}),await _.setEnabled(!1),await _.flush();return}n({persistenceEnabled:!0}),await _.setEnabled(!0);let t=P();te||await o().hydrateDraftMetadata(t.transportIdentity);let r=new Set([...Object.keys(o().drafts),...Object.keys(o().tombstones),...A]);A.clear(),await z(r),await _.flush()},hydrateDraftMetadata:e=>{let t=S.get(e);if(t)return t;let r=(async()=>{let t=(y.get(e)??0)+1;y.set(e,t);let r=P();if(r.transportIdentity!==e)return!1;let i=D,s=new Map(v),c=k,l=Object.entries(o().drafts).filter(([,t])=>t.key.transportIdentity===e).map(([e])=>e);n(e=>({draftHydration:{...e.draftHydration,...Object.fromEntries(l.map(e=>[e,`loading`]))}}));let u=o().persistenceEnabled,d;try{d=await p.migrate(e,{persistenceEnabled:u})}catch{return!1}if(y.get(e)!==t||D!==i||!F(r))return!1;if(!d.ok)return n(e=>({draftHydration:{...e.draftHydration,...Object.fromEntries(l.map(t=>[t,e.drafts[t]?`degraded`:`error`]))}})),!1;let f=d.value;if(!te){ne??=_.seed(f).finally(()=>{ne=void 0});let a;try{a=await ne}catch{return!1}if(y.get(e)!==t||D!==i||!F(r))return!1;if(a.status!==`committed`&&a.status!==`disabled`)return n(e=>({draftHydration:{...e.draftHydration,...Object.fromEntries(l.map(e=>[e,`degraded`]))}})),!1;a.status===`committed`&&(te=!0)}let m=o(),h={...m.drafts},g={...m.tombstones},b=new Set;for(let[e,t]of Object.entries(f.tombstones))(v.get(e)??0)===(s.get(e)??0)&&(t>=(g[e]??0)&&(g[e]=t,(h[e]?.revision??0)<=t&&delete h[e]),b.add(e));for(let[t,n]of Object.entries(f.drafts)){if(n.key.transportIdentity!==e||(v.get(t)??0)!==(s.get(t)??0))continue;let r=h[t],i=N(n);i&&(!r||r.revision<i.revision)&&(g[t]??0)<i.revision&&(h[t]=i),b.add(t)}let x=k===c?{...f.legacy.entries}:{...m.legacyDraftEntries};if(f.migration.claimedTransportIdentity===e&&k===c)for(let[t,n]of Object.entries(x)){let r={transportIdentity:e,owner:{kind:`session`,ownerID:t}},i=a(r),o=Pe(n.text),c=N({...He(r),text:o.text,composerReferences:o.references,mentions:Ue(o.text,n.mentions)});c&&!h[i]&&!g[i]&&(v.get(i)??0)===(s.get(i)??0)&&(h[i]=c),delete x[t],b.add(i)}n(e=>({drafts:h,tombstones:g,legacyNewDraft:k===c&&!ee?f.legacy.new:e.legacyNewDraft,legacyDraftEntries:x,migration:k===c?f.migration:e.migration,draftHydration:{...e.draftHydration,...Object.fromEntries([...b].map(e=>[e,`ready`]))}}));let S=[...A];for(let e of S)b.add(e);A.clear();try{await z(b),await _.flush()}catch{return!1}return y.get(e)===t&&D===i&&F(r)})();return S.set(e,r),r.finally(()=>{S.get(e)===r&&S.delete(e)}).catch(()=>void 0),r},claimLegacyNewDraft:async e=>{let t=o().legacyNewDraft;if(!t)return o().getDraft(e);let r=a(e),i=o().drafts[r];if(k+=1,ee=!0,i||o().tombstones[r])return n({legacyNewDraft:void 0}),z([r]),i;let s=Pe(t.text),c=N({...He(e),text:s.text,composerReferences:s.references,mentions:Ue(s.text,t.mentions)});if(c)return m(r),n(e=>({drafts:{...e.drafts,[r]:c},legacyNewDraft:void 0})),z([r]),c},pendingInputText:null,pendingInputMode:`replace`,pendingSyntheticParts:null,pendingPresetSubmit:null,attachedFiles:[],attachmentBuckets:{"legacy-unowned":[]},activeAttachmentDraft:null,activeEditorFile:null,setPendingInputText:(e,t=`replace`)=>n({pendingInputText:e,pendingInputMode:t}),consumePendingInputText:()=>{let{pendingInputText:e,pendingInputMode:t}=o();return e===null?null:(n({pendingInputText:null,pendingInputMode:`replace`}),{text:e,mode:t})},requestPresetSubmit:e=>n({pendingPresetSubmit:e}),consumePendingPresetSubmit:()=>{let{pendingPresetSubmit:e}=o();return e===null?null:(n({pendingPresetSubmit:null}),e)},setPendingSyntheticParts:e=>n({pendingSyntheticParts:e}),consumePendingSyntheticParts:()=>{let{pendingSyntheticParts:e}=o();return e!==null&&n({pendingSyntheticParts:null}),e},setActiveAttachmentDraft:e=>{let t=J(e);n(n=>({activeAttachmentDraft:e,attachedFiles:n.attachmentBuckets[t]??[],attachmentBuckets:n.attachmentBuckets[t]?n.attachmentBuckets:{...n.attachmentBuckets,[t]:[]}}))},addAttachedFile:async e=>{let t=o().activeAttachmentDraft;if(t){let n=J(t),r=Y(n),i=await o().addDraftLocalAttachment(t,e);r!==Y(n)&&i&&o().removeDraftAttachment(t,i.attachmentRefID);return}let n=`${Date.now()}-${Math.random().toString(36).slice(2)}`,r=J(null),i=Y(r),a;try{a=await ze(e)}catch{return}if(i!==Y(r))return;let s={id:n,file:e,dataUrl:a,mimeType:e.type,filename:e.name,size:e.size,source:`local`};X(r,e=>[...e,s])},removeAttachedFile:e=>{let t=o().activeAttachmentDraft;if(t){let n=o().getDraft(t),r=n?[...n.attachments,...n.syntheticParts.flatMap(e=>e.attachments)].find(t=>t.attachmentID===e):void 0;r&&o().removeDraftAttachment(t,r.attachmentRefID);return}X(J(null),t=>t.filter(t=>t.id!==e))},setAttachedFiles:e=>{X(J(o().activeAttachmentDraft),()=>e,!0)},clearAttachedFiles:()=>{let e=o().activeAttachmentDraft;if(e){de(J(e)),o().getDraft(e)||o().ensureDraft(e),o().setDraftAttachments(e,[]);return}X(J(null),()=>[],!0)},addDraftVSCodeFileAttachment:(e,t,n,r)=>{if(o().getDraftAttachmentViews(e).some(e=>e.source===`vscode`&&e.vscodeSource===`file`&&(e.vscodePath||``)===t)||(o().getDraft(e)?.attachments.some(e=>e.source===`vscode`&&e.vscodeSource===`file`&&(e.vscodePath||``)===t)??!1))return;let i=Le(t);o().addDraftDurableAttachment(e,{filename:n,mimeType:`text/plain`,size:r||0,source:`vscode`,vscodePath:t,vscodeSource:`file`,url:i})},addDraftVSCodeSelectionAttachment:async(e,t,n)=>{let r=a(e),i=Y(r),s=`${r}\u0000${Re(t,n.name)}`;if(!(o().getDraftAttachmentViews(e).some(e=>e.source===`vscode`&&e.vscodeSource===`selection`&&e.filename===n.name&&e.vscodePath===t)||(o().getDraft(e)?.attachments.some(e=>e.source===`vscode`&&e.vscodeSource===`selection`&&e.filename===n.name&&e.vscodePath===t)??!1)||M.has(s))){M.add(s);try{let a=await o().addDraftLocalAttachment(e,n,{source:`vscode`,vscodePath:t,vscodeSource:`selection`});i!==Y(r)&&a&&o().removeDraftAttachment(e,a.attachmentRefID)}finally{M.delete(s)}}},addVSCodeFileAttachment:(e,t,n)=>{let r=o().activeAttachmentDraft;if(r){o().addDraftVSCodeFileAttachment(r,e,t,n);return}let i=`${Date.now()}-${Math.random().toString(36).slice(2)}`,a=J(null);if((o().attachmentBuckets[a]??[]).some(t=>t.source===`vscode`&&t.vscodeSource===`file`&&(t.vscodePath||``)===e))return;let s=Le(e),c={id:i,file:new File([],t,{type:`text/plain`}),dataUrl:s,mimeType:`text/plain`,filename:t,size:n||0,source:`vscode`,vscodePath:e,vscodeSource:`file`};X(a,e=>[...e,c])},addVSCodeSelectionAttachment:async(e,t)=>{let n=o().activeAttachmentDraft;if(n){await o().addDraftVSCodeSelectionAttachment(n,e,t);return}let r=`${Date.now()}-${Math.random().toString(36).slice(2)}`,i=J(null),a=Y(i),s=`${i}\u0000${Re(e,t.name)}`;if((o().attachmentBuckets[i]??[]).some(n=>n.source===`vscode`&&n.vscodeSource===`selection`&&n.filename===t.name&&n.vscodePath===e)||M.has(s))return;M.add(s);let c;try{c=await ze(t)}catch{return}finally{M.delete(s)}if(a!==Y(i))return;let l={id:r,file:t,dataUrl:c,mimeType:t.type,filename:t.name,size:t.size,source:`vscode`,vscodePath:e,vscodeSource:`selection`};X(i,e=>[...e,l])},addCodeSelectionAttachment:async(e,t,n)=>{let r=new File([n],t,{type:`text/plain`});await o().addVSCodeSelectionAttachment(e,r)},setActiveEditorFile:e=>{Ve(o().activeEditorFile,e)||n({activeEditorFile:e})},addRestoredAttachment:({url:e,mimeType:t,filename:n})=>{let r=o().activeAttachmentDraft;if(r){if(e.startsWith(`data:`)){let i=a(r);(async()=>{try{let s=await(await fetch(e)).blob(),c=new File([s],n,{type:t||s.type||`application/octet-stream`}),l=o().activeAttachmentDraft;if(!l||a(l)!==i)return;await o().addDraftLocalAttachment(r,c)}catch{}})();return}if(!u(e))return;o().addDraftDurableAttachment(r,{filename:n,mimeType:t,size:Be(e),source:`local`,serverPath:e,url:e});return}let i={id:`restored-${Date.now()}-${Math.random().toString(36).slice(2)}`,file:new File([],n,{type:t}),dataUrl:e,mimeType:t,filename:n,size:Be(e),source:`local`,serverPath:e};X(J(null),e=>[...e,i])}}})},Ge=We();export{O as a,Y as i,Ge as n,de as r,We as t};
1
+ import{i as e,n as t}from"./runtime-switch-DEPKHgdL.js";import{a as n}from"./vendor-zustand-CTekDqaS.js";import{t as r}from"./brand-storage-migration-Bhz6UOBJ.js";import"./brand-storage-bootstrap-D4BW3w-M.js";import{D as i,E as a,F as o,O as s,R as c,S as l,k as u,o as d,s as f,w as p,x as m}from"./prompt-attachment-upload-BltVQvQ0.js";import{t as h}from"./uuid-D-SDZijH.js";var g=`yuri_input_draft_metadata_v1`,_=`yuri_input_draft_metadata_migration_v1`,v=`yuri_chat_input_draft_`,y=`yuri_chat_confirmed_mentions_`,b=()=>({ok:!1,error:{code:`unavailable`}}),x=()=>({ok:!1,error:{code:`cancelled`}}),S=e=>({ok:!1,error:{code:e instanceof DOMException&&e.name===`QuotaExceededError`?`quota`:`unavailable`}}),C=e=>typeof e==`object`&&!!e&&(Object.getPrototypeOf(e)===Object.prototype||Object.getPrototypeOf(e)===null),w=(e,t)=>Object.keys(e).every(e=>t.includes(e)),T=e=>typeof e==`number`&&Number.isSafeInteger(e)&&e>0,E=e=>typeof e==`string`&&e.length>0,D=e=>({read:async t=>{if(!e)return b();try{return{ok:!0,value:e.getItem(t)}}catch(e){return S(e)}},write:async(t,n)=>{if(!e)return b();try{return e.setItem(t,n),{ok:!0,value:void 0}}catch(e){return S(e)}},remove:async t=>{if(!e)return b();try{return e.removeItem(t),{ok:!0,value:void 0}}catch(e){return S(e)}},keys:async()=>{if(!e)return b();try{let t=[];for(let n=0;n<e.length;n+=1){let r=e.key(n);r!==null&&t.push(r)}return{ok:!0,value:t}}catch(e){return S(e)}}}),O=()=>{try{return D(typeof window>`u`?null:window.localStorage)}catch{return D(null)}},k=(e,t,n,r)=>{let i=[];try{let e=n===null?[]:JSON.parse(n);Array.isArray(e)&&(i=e.filter(e=>typeof e==`string`))}catch{}return{suffix:e,text:t??``,mentions:i,keys:r}},ee=async e=>{let t=await e.keys();if(!t.ok)return t;let n=new Set;for(let e of t.value)e.startsWith(v)&&n.add(e.slice(22)),e.startsWith(y)&&n.add(e.slice(29));let r=[];for(let i of n){let n=`${v}${i}`,a=`${y}${i}`,[o,s]=await Promise.all([e.read(n),e.read(a)]);if(!o.ok)return o;if(!s.ok)return s;r.push(k(i,o.value,s.value,[n,a].filter(e=>t.value.includes(e))))}return{ok:!0,value:r}},te=e=>{if(!(!C(e)||!w(e,[`suffix`,`text`,`mentions`,`keys`])||typeof e.suffix!=`string`||typeof e.text!=`string`||!Array.isArray(e.mentions)||!e.mentions.every(e=>typeof e==`string`)||!Array.isArray(e.keys)||!e.keys.every(e=>typeof e==`string`)))return{suffix:e.suffix,text:e.text,mentions:[...e.mentions],keys:[...e.keys]}},ne=e=>{try{let t=JSON.parse(e);return Array.isArray(t)&&t.length===3&&E(t[0])&&(t[1]===`session`||t[1]===`draft`)&&E(t[2])&&e===JSON.stringify(t)}catch{return!1}},A=e=>{if(!C(e)||!w(e,[`complete`,`claimedTransportIdentity`,`captured`,`markerCommitted`,`cleanupComplete`])||typeof e.complete!=`boolean`||typeof e.claimedTransportIdentity!=`string`||e.captured!==void 0&&typeof e.captured!=`boolean`||e.markerCommitted!==void 0&&typeof e.markerCommitted!=`boolean`||e.cleanupComplete!==void 0&&typeof e.cleanupComplete!=`boolean`)return;let t=e.cleanupComplete??e.complete,n=e.captured??e.complete,r=e.markerCommitted??e.complete;if(!((n||r||t)&&!E(e.claimedTransportIdentity))&&!(r&&!n)&&!(t&&(!n||!r)))return{complete:t,claimedTransportIdentity:e.claimedTransportIdentity,captured:n,markerCommitted:r,cleanupComplete:t}},j=e=>{if(!C(e)||!w(e,[`version`,`drafts`,`tombstones`,`migration`,`legacy`])||e.version!==1||!C(e.drafts)||!C(e.tombstones)||!C(e.legacy)||!w(e.legacy,[`new`,`entries`])||!C(e.legacy.entries))return;let t=A(e.migration);if(!t)return;let n={};for(let[t,r]of Object.entries(e.drafts)){let e=c(r);if(!e||t!==a(e.key))return;n[t]=e}let r={};for(let[t,n]of Object.entries(e.tombstones)){if(!ne(t)||!T(n))return;r[t]=n}let i={};for(let[t,n]of Object.entries(e.legacy.entries)){let e=te(n);if(!e||t!==e.suffix||t===`new`)return;i[t]=e}let o=e.legacy.new===void 0?void 0:te(e.legacy.new);if(!(e.legacy.new!==void 0&&(!o||o.suffix!==`new`)))return{version:1,drafts:n,tombstones:r,migration:t,legacy:{...o?{new:o}:{},entries:i}}},M=(e=``)=>({version:1,drafts:{},tombstones:{},migration:{complete:!1,claimedTransportIdentity:e,captured:!1,markerCommitted:!1,cleanupComplete:!1},legacy:{entries:{}}}),N=e=>{try{return{ok:!0,value:JSON.stringify(e)}}catch{return{ok:!1,error:{code:`serialization`}}}},P=async e=>{let t=await e.read(g);if(!t.ok)return t;if(t.value===null)return{ok:!0,value:null};try{let e=j(JSON.parse(t.value));return e?{ok:!0,value:e}:{ok:!1,error:{code:`corrupt`}}}catch{return{ok:!1,error:{code:`corrupt`}}}},F=async(e,t)=>{let n=j(t);if(!n)return{ok:!1,error:{code:`corrupt`}};let r=N(n);return r.ok?e.write(g,r.value):r},I=e=>C(e)&&w(e,[`version`,`claimedTransportIdentity`])&&e.version===1&&E(e.claimedTransportIdentity)?{version:1,claimedTransportIdentity:e.claimedTransportIdentity}:void 0,re=e=>N({version:1,claimedTransportIdentity:e}),ie=(e,t,n)=>{let r={},i;for(let e of t)e.suffix===`new`?i=e:r[e.suffix]=e;return{...e,migration:{complete:!1,claimedTransportIdentity:n,captured:!0,markerCommitted:!1,cleanupComplete:!1},legacy:{...i?{new:i}:{},entries:r}}},L=e=>[...new Set([e.legacy.new,...Object.values(e.legacy.entries)].flatMap(e=>e?.keys??[]))],ae=new WeakMap,R=e=>{let t=ae.get(e);if(t)return t;let n=Promise.resolve(),r,i=!0,a=e=>{let t=n.then(e,e);return n=t.then(()=>void 0,()=>void 0),t},o={persist:t=>{let n=j(t);return n?i?a(async()=>i?F(e,n):b()):Promise.resolve(b()):Promise.resolve({ok:!1,error:{code:`corrupt`}})},migrate:(t,n={})=>{if(r)return r;let o=a(async()=>{let r=await P(e);if(!r.ok)return r;let a=r.value??M(),o=i&&(n.persistenceEnabled??!0);if(!a.migration.captured){let n=await ee(e);if(!n.ok)return n;if(!o)return{ok:!0,value:ie(a,n.value,``)};if(a=ie(a,n.value,t),!i)return{ok:!0,value:a};let r=await F(e,a);if(!r.ok)return r}if(!i||!(n.persistenceEnabled??!0)){let t=await ee(e);return t.ok?{ok:!0,value:a}:t}let s=await e.read(_);if(!s.ok)return s;if(s.value!==null)try{let t=I(JSON.parse(s.value));if(!t)return{ok:!1,error:{code:`corrupt`}};if(t.claimedTransportIdentity!==a.migration.claimedTransportIdentity){let t=re(a.migration.claimedTransportIdentity);if(!t.ok)return t;if(!i)return{ok:!0,value:a};let n=await e.write(_,t.value);if(!n.ok)return n}}catch{return{ok:!1,error:{code:`corrupt`}}}else{let t=re(a.migration.claimedTransportIdentity);if(!t.ok)return t;if(!i)return{ok:!0,value:a};let n=await e.write(_,t.value);if(!n.ok)return n}if(a.migration.cleanupComplete)return{ok:!0,value:a};for(let t of L(a)){if(!i)return{ok:!0,value:a};let n=await e.remove(t);if(!n.ok)return n}if(a={...a,migration:{complete:!0,claimedTransportIdentity:a.migration.claimedTransportIdentity,captured:!0,markerCommitted:!0,cleanupComplete:!0}},!i)return{ok:!0,value:a};let c=await F(e,a);return c.ok?{ok:!0,value:a}:c}).finally(()=>{r=void 0});return r=o,o},flush:()=>n,setEnabled:async e=>{i=e,i||await n}};return ae.set(e,o),o},z=e=>{let t=R(e),n=!0,r=!1,i=[],a=[],o=()=>{if(r||i.length>0)return;let e=a;a=[],e.forEach(e=>e())},s=()=>{if(r)return;let e=i.shift();if(!e){o();return}r=!0,t.persist(e.snapshot).then(e.resolve).finally(()=>{r=!1,s()})};return{persist:e=>{let t=j(e);return t?n?new Promise(e=>{i.push({snapshot:t,resolve:e}),s()}):Promise.resolve(b()):Promise.resolve({ok:!1,error:{code:`corrupt`}})},cancelPending:()=>{let e=i;i=[],e.forEach(({resolve:e})=>e(x())),o()},flush:()=>r||i.length>0?new Promise(e=>a.push(e)):Promise.resolve(),setEnabled:async e=>{if(n=e,!n){let e=i;i=[],e.forEach(({resolve:e})=>e(x()))}await(r||i.length>0?new Promise(e=>a.push(e)):Promise.resolve()),await t.setEnabled(e),await t.flush()}}},oe=`yuri-input-drafts`,se=1,ce=`blobs`,le=`blobRefs`,B=class extends Error{code;constructor(e){super(e),this.code=e}},V=e=>({ok:!1,error:{code:e instanceof B?e.code:e instanceof DOMException&&e.name===`QuotaExceededError`?`quota-exceeded`:e instanceof DOMException&&e.name===`AbortError`?`transaction-aborted`:`transaction-failed`}}),H=e=>{if(!(e instanceof Blob)&&!u(e))throw new B(`invalid-value`)},U=e=>{if(!e)throw new B(`invalid-value`)},W=(e,t)=>({id:p(e),blobID:t,transportIdentity:e.transportIdentity,ownerKind:e.owner.kind,ownerID:e.owner.ownerID}),G=async e=>{if(typeof e==`string`)return`url:${e}`;let t=await crypto.subtle.digest(`SHA-256`,await e.arrayBuffer()),n=[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,`0`)).join(``);return`blob:${e.type}:${e.size}:${n}`},K=async(e,t)=>(e.fingerprint??await G(e.value))===t,q=async(e,t=!1)=>{let n=await e.getAllBlobRefs(),r=await e.getAllBlobs(),i=new Map;for(let t of n)await e.getBlob(t.blobID)?i.set(t.blobID,(i.get(t.blobID)??0)+1):await e.deleteBlobRef(t.id);for(let n of r){let r=i.get(n.id)??0;r||!t?await e.putBlob({...n,refCount:r}):await e.deleteBlob(n.id)}},ue=e=>{try{let t=JSON.parse(e);return!Array.isArray(t)||t.length!==4||typeof t[0]!=`string`||typeof t[2]!=`string`||t[1]!==`session`&&t[1]!==`draft`&&t[1]!==`surface`&&t[1]!==`queue`&&t[1]!==`send`?void 0:{transportIdentity:t[0],ownerKind:t[1],ownerID:t[2]}}catch{return}},J=(e,t)=>{let n=ue(e.id),r=e.ownerKind??n?.ownerKind,i=e.transportIdentity??n?.transportIdentity;return r!==void 0&&t.ownerKinds.includes(r)&&(t.transportIdentities===void 0||i!==void 0&&t.transportIdentities.includes(i))},Y=(e=de())=>{let t=async(t,n)=>{try{return{ok:!0,value:await e.transaction(async e=>{let r=await e.getBlobRef(p(t));return!r||n!==void 0&&r.blobID!==n?!1:(await e.deleteBlobRef(r.id),await q(e),(await e.getAllBlobRefs()).some(e=>e.blobID===r.blobID)||await e.deleteBlob(r.blobID),!0)})}}catch(e){return V(e)}};return{put:async(t,n)=>{try{U(t),H(n);let r=await G(n);return await e.transaction(async e=>{let i=await e.getBlob(t);if(i&&!await K(i,r))throw new B(`blob-id-conflict`);i||await e.putBlob({id:t,value:n,refCount:0,fingerprint:r})}),{ok:!0,value:void 0}}catch(e){return V(e)}},putAndRetain:async(t,n,r)=>{try{U(n),H(r);let i=await G(r);return await e.transaction(async e=>{let a=p(t),o=await e.getBlobRef(a);if(o&&o.blobID!==n)throw new B(`blob-id-conflict`);let s=await e.getBlob(n);if(s&&!await K(s,i))throw new B(`blob-id-conflict`);s||await e.putBlob({id:n,value:r,refCount:0,fingerprint:i}),o||await e.putBlobRef(W(t,n)),await q(e)}),{ok:!0,value:void 0}}catch(e){return V(e)}},read:async t=>{try{let n=await e.transaction(e=>e.getBlob(t));return n?{ok:!0,value:n.value}:{ok:!1,error:{code:`missing-blob`}}}catch(e){return V(e)}},readReference:async t=>{try{return{ok:!0,value:(await e.transaction(e=>e.getBlobRef(p(t))))?.blobID}}catch(e){return V(e)}},retain:async(t,n)=>{try{return U(n),await e.transaction(async e=>{let r=await e.getBlobRef(p(t));if(r&&r.blobID!==n)throw new B(`blob-id-conflict`);if(!await e.getBlob(n))throw new B(`missing-blob`);r||await e.putBlobRef(W(t,n)),await q(e)}),{ok:!0,value:void 0}}catch(e){return V(e)}},release:e=>t(e),releaseIfMatches:(e,n)=>t(e,n),reconcileReferences:async(t,n={ownerKinds:[`session`,`draft`]})=>{try{return{ok:!0,value:await e.transaction(async e=>{let r=[],i=[],a=[],o=new Map((await e.getAllBlobRefs()).map(e=>[e.id,e]));for(let[i,a]of o)J(a,n)&&t.get(i)!==a.blobID&&(await e.deleteBlobRef(i),r.push(i));for(let[r,s]of t){let t=ue(r);if(!t||!n.ownerKinds.includes(t.ownerKind)||n.transportIdentities!==void 0&&!n.transportIdentities.includes(t.transportIdentity)){a.push(r);continue}let c=o.get(r);if(!await e.getBlob(s)){a.push(r);continue}(!c||c.blobID!==s)&&(await e.putBlobRef({id:r,blobID:s,...t}),i.push(r))}return await q(e,!0),{released:r,repaired:i,missing:a}})}}catch(e){return V(e)}},reconcileOwnerReferences:async(t,n)=>{let r=new Map;for(let[e,i]of n)r.set(p({transportIdentity:t.transportIdentity,owner:t.owner,attachmentOccurrenceRefID:e}),i);try{return{ok:!0,value:await e.transaction(async e=>{let n=0,i=new Set;for(let a of await e.getAllBlobRefs())a.transportIdentity===t.transportIdentity&&a.ownerKind===t.owner.kind&&a.ownerID===t.owner.ownerID&&r.get(a.id)!==a.blobID&&(await e.deleteBlobRef(a.id),i.add(a.blobID),n++);await q(e);let a=await e.getAllBlobRefs();for(let t of i)a.some(e=>e.blobID===t)||await e.deleteBlob(t);return n})}}catch(e){return V(e)}},discardUnreferenced:async t=>{try{return{ok:!0,value:await e.transaction(async e=>!await e.getBlob(t)||(await e.getAllBlobRefs()).some(e=>e.blobID===t)?!1:(await e.deleteBlob(t),!0))}}catch(e){return V(e)}}}},de=(e=oe)=>({transaction:async t=>{let n=await X(e),r=n.transaction([ce,le],`readwrite`),i=r.objectStore(ce),a=r.objectStore(le),o=e=>new Promise((t,n)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>n(e.error??r.error??Error(`IndexedDB request failed`))}),s=new Promise((e,t)=>{r.oncomplete=()=>e(),r.onabort=()=>t(r.error??new DOMException(`aborted`,`AbortError`)),r.onerror=()=>{console.error(`Input draft IndexedDB transaction error`,r.error)}}),c;try{let e=await t({getBlob:e=>o(i.get(e)),getAllBlobs:()=>o(i.getAll()),putBlob:async e=>{await o(i.put(e))},deleteBlob:async e=>{await o(i.delete(e))},getBlobRef:e=>o(a.get(e)),getAllBlobRefs:()=>o(a.getAll()),putBlobRef:async e=>{await o(a.put(e))},deleteBlobRef:async e=>{await o(a.delete(e))}});return await s,e}catch(e){c=e;try{r.abort()}catch{}try{await s}catch(e){c===void 0&&(c=e)}throw c}finally{n.close()}}}),X=e=>(e===oe?r(oe):Promise.resolve()).then(()=>new Promise((t,n)=>{if(!globalThis.indexedDB){n(new B(`database-unavailable`));return}let r=indexedDB.open(e,se),i=!1,a=()=>{i||(i=!0,n(new B(`database-unavailable`)))};r.onupgradeneeded=()=>{let e=r.result;e.objectStoreNames.contains(ce)||e.createObjectStore(ce,{keyPath:`id`}),e.objectStoreNames.contains(le)||e.createObjectStore(le,{keyPath:`id`})},r.onsuccess=()=>{let e=r.result;if(e.onversionchange=()=>e.close(),i){e.close();return}i=!0,t(e)},r.onerror=a,r.onblocked=a})),fe=()=>({drafts:{},tombstones:{},migration:{complete:!1,claimedTransportIdentity:``,captured:!1,markerCommitted:!1,cleanupComplete:!1},legacy:{entries:{}}}),pe=e=>({version:1,drafts:e.drafts,tombstones:e.tombstones,migration:e.migration,legacy:e.legacy}),me=e=>{let t=pe(e),n=he(JSON.parse(JSON.stringify(t)));return{drafts:n.drafts,tombstones:n.tombstones,migration:n.migration,legacy:n.legacy}},he=e=>{let t=j(e);if(!t)throw Error(`invalid draft snapshot`);return t},ge=e=>e instanceof Map?[...e.entries()]:Object.entries(e??{}),_e=e=>typeof e==`string`?e:a(e),ve=[`session`,`draft`,`surface`],Z=e=>({transportIdentity:e.transportIdentity,owner:{kind:e.owner.kind,ownerID:e.owner.ownerID},attachmentOccurrenceRefID:e.attachmentOccurrenceRefID}),ye=e=>JSON.parse(JSON.stringify(e)),be=e=>e.phase===`metadata`?{phase:`metadata`,error:{code:e.error.code}}:{phase:`blob`,error:{...e.error},...e.reference?{reference:Z(e.reference)}:{}},xe=e=>({status:e.status,keys:[...e.keys],errors:e.errors.map(be),cleanupErrors:e.cleanupErrors.map(be)}),Se=e=>typeof e==`number`&&Number.isSafeInteger(e)&&e>0,Ce=e=>{try{let t=JSON.parse(e);return Array.isArray(t)&&t.length===3&&typeof t[0]==`string`&&ve.includes(t[1])&&typeof t[2]==`string`&&t[0].length>0&&t[2].length>0}catch{return!1}},we=e=>[...e.attachments,...e.syntheticParts.flatMap(e=>e.attachments)].flatMap(t=>t.locator.kind===`blob`?[{reference:{transportIdentity:e.key.transportIdentity,owner:{kind:e.key.owner.kind,ownerID:e.key.owner.ownerID},attachmentOccurrenceRefID:t.attachmentRefID},attachment:ye(t)}]:[]),Te=e=>{let t=new Map;for(let n of Object.values(e))for(let e of we(n))t.set(p(e.reference),e);return t},Q=(e,t)=>({phase:`blob`,error:{...e},...t?{reference:Z(t)}:{}}),$=(e,t=[])=>({status:e,keys:t,errors:[],cleanupErrors:[]}),Ee=e=>e?.attachment.locator.kind===`blob`?e.attachment.locator.blobID:``,De=(e,t,n={})=>{let r=fe(),i=n.enabled??!0,o=0,s=!1,l=Promise.resolve(),u=new Map,d=e=>{let t=l.then(e,e);return l=t.then(()=>void 0,()=>void 0),t.then(e=>e&&typeof e==`object`&&`status`in e&&`keys`in e&&`errors`in e&&`cleanupErrors`in e?xe(e):e)},f=async(t=r.drafts)=>{let n=[],i=new Map([...Te(t)].map(([e,t])=>[e,t.attachment.locator.kind===`blob`?t.attachment.locator.blobID:``]));for(let[t,r]of u){if(i.get(t)===r.expectedBlobID){u.delete(t);continue}let a=await e.releaseIfMatches(Z(r.reference),r.expectedBlobID);a.ok?u.delete(t):n.push(Q(a.error,r.reference))}return n},m=async(t,n,r,i)=>{let a=Z(t),s=await e.releaseIfMatches(a,n);s.ok||(u.set(p(a),{reference:Z(a),expectedBlobID:n,generation:o,reason:i}),r.push(Q(s.error,a)))},h=async(t,n)=>{let r=t.attachment.locator.kind===`blob`?t.attachment.locator.blobID:``,i=Z(t.reference),a=ye(t.attachment),o=await e.readReference(i);if(!o.ok)return{acquired:!1,error:Q(o.error,i)};if(o.value&&o.value!==r)return{acquired:!1,error:Q({code:`reference-conflict`},i)};if(o.value===r){let t=await e.read(r);if(t.ok)return{acquired:!1};if(t.error.code!==`missing-blob`)return{acquired:!1,error:Q(t.error,i)};let o=await n?.(Z(i),ye(a));if(o===void 0)return{acquired:!1,error:Q({code:`runtime-value-missing`},i)};let s=await e.putAndRetain(i,r,o);return s.ok?{acquired:!0}:{acquired:!1,error:Q(s.error,i)}}let s=await e.read(r);if(s.ok){let t=await e.retain(i,r);return t.ok?{acquired:!0}:{acquired:!1,error:Q(t.error,i)}}if(s.error.code!==`missing-blob`)return{acquired:!1,error:Q(s.error,i)};let c=await n?.(Z(i),ye(a));if(c===void 0)return{acquired:!1,error:Q({code:`runtime-value-missing`},i)};let l=await e.putAndRetain(i,r,c);return l.ok?{acquired:!0}:{acquired:!1,error:Q(l.error,i)}};return{seed:t=>d(async()=>{if(!i)return $(`disabled`);if(s)return{...$(`failed`),errors:[Q({code:`invalid-record`})]};let n;try{if(!t)n=fe();else{let e=he(JSON.parse(JSON.stringify(t)));n={drafts:e.drafts,tombstones:e.tombstones,migration:e.migration,legacy:e.legacy}}}catch{return{...$(`failed`),errors:[Q({code:`invalid-record`})]}}let a=Te(n.drafts),o=await e.reconcileReferences(new Map([...a].map(([e,t])=>[e,Ee(t)])),{ownerKinds:ve});return o.ok?(r=n,s=!0,{...$(`committed`),errors:o.value.missing.map(e=>Q({code:`missing-blob`},a.get(e)?.reference))}):{...$(`failed`),errors:[Q(o.error)]}}),commit:e=>{let n=[...ge(e.drafts).map(([e])=>e),...(e.delete??[]).map(_e)];return i?d(async()=>{if(!s)return $(`unseeded`,n);if(!i)return $(`disabled`,n);let l=o,u=[],d=me(r),g=ge(e.drafts),_=ge(e.tombstones),v=(e.delete??[]).map(_e);if(g.some(([e,t])=>!Ce(e)||!Se(t.revision))||_.some(([e,t])=>!Ce(e)||!Se(t))||v.some(e=>!Ce(e))||new Set(g.map(([e])=>e)).size!==g.length||_.some(([e])=>g.some(([t])=>t===e)))return{...$(`failed`,n),errors:[Q({code:`invalid-record`})]};try{for(let[e,t]of g){let n=c(t);if(!n||e!==a(n.key))throw Error(`invalid draft record`);d.drafts[e]=n,delete d.tombstones[e]}for(let e of v)delete d.drafts[e];for(let[e,t]of _)d.tombstones[e]=t;e.migration&&(d.migration=e.migration),e.legacy&&(d.legacy=e.legacy);let t=he(pe(d));d.drafts=t.drafts,d.tombstones=t.tombstones,d.migration=t.migration,d.legacy=t.legacy}catch{return{...$(`failed`,n),errors:[Q({code:`invalid-record`})],cleanupErrors:u}}if(!await e.isCurrent())return $(`stale`,n);let y=Te(r.drafts),b=Te(d.drafts);u=await f(d.drafts);let x=[];for(let[t,r]of b){let i=y.get(t);if((i?.attachment.locator.kind===`blob`?i.attachment.locator.blobID:void 0)===(r.attachment.locator.kind===`blob`?r.attachment.locator.blobID:void 0))continue;let a=await h(r,e.resolveBlobValue);if(a.error){for(let e of x.reverse())await m(e,Ee(b.get(p(e))),u,`acquire-failed`);return{...$(`failed`,n),errors:[a.error],cleanupErrors:u}}a.acquired&&x.push(r.reference)}if(!await e.isCurrent()){for(let e of x.reverse())await m(e,Ee(b.get(p(e))),u,`stale`);return{...$(`stale`,n),cleanupErrors:u}}if(!i||l!==o){for(let e of x.reverse())await m(e,Ee(b.get(p(e))),u,`disabled`);return{...$(`disabled`,n),cleanupErrors:u}}let S=await t.persist(pe(d));if(!S.ok){for(let e of x.reverse())await m(e,Ee(b.get(p(e))),u,`metadata-failed`);return{...$(`failed`,n),errors:[{phase:`metadata`,error:S.error}],cleanupErrors:u}}r=d;for(let[e,t]of y)b.has(e)||await m(t.reference,t.attachment.locator.kind===`blob`?t.attachment.locator.blobID:``,u,`metadata-committed`);return{...$(`committed`,n),cleanupErrors:u}}):Promise.resolve(xe($(`disabled`,n)))},reconcile:()=>d(async()=>{if(!s)return $(`unseeded`);if(!i)return $(`disabled`);let t=await f(),n=new Map([...Te(r.drafts)].map(([e,t])=>[e,t.attachment.locator.kind===`blob`?t.attachment.locator.blobID:``])),a=await e.reconcileReferences(n,{ownerKinds:ve}),o=a.ok?a.value.missing.map(e=>Q({code:`missing-blob`},Te(r.drafts).get(e)?.reference)):[Q(a.error)];return{status:a.ok?`committed`:`failed`,keys:[],errors:o,cleanupErrors:t}}),retryCleanup:()=>d(async()=>({...$(`committed`),cleanupErrors:await f()})),flush:()=>l,setEnabled:async e=>{if(!e){i=!1,o+=1,t.cancelPending?.(),await t.setEnabled?.(!1),await l,await t.flush?.();return}await t.setEnabled?.(!0),i=!0,o+=1}}},Oe=`yuri-composer-reference-draft`,ke=`yuri-pasted-text-draft`,Ae=e=>Array.from(e).length,je=e=>typeof e==`object`&&!!e&&(Object.getPrototypeOf(e)===Object.prototype||Object.getPrototypeOf(e)===null),Me=(e,t)=>typeof e==`string`&&e.length>0&&e.length<=t,Ne=(e,t)=>{let n=[],r=[],i=0;for(let a=0;a<Math.min(t.length,m.referenceCount);a+=1){let o=t[a];if(!(!je(o)||!Me(o.id,m.idLength)||!Me(o.token,m.displayLength)||typeof o.text!=`string`||o.text.length>m.pastePayloadLength||typeof o.characterCount!=`number`||!Number.isSafeInteger(o.characterCount)||o.characterCount!==Ae(o.text)||typeof o.index!=`number`||!Number.isSafeInteger(o.index)||o.index<1))for(let t=e.indexOf(o.token);t>=0&&n.length<m.referenceCount;t=e.indexOf(o.token,t+o.token.length)){let e=t+o.token.length;if(r.some(n=>n.start<e&&n.end>t)||i+o.text.length>m.totalPastePayloadLength)continue;let a=n.filter(e=>e.id.startsWith(`${o.id}:`)).length;n.push({id:`${o.id}:${a}`,kind:`paste`,start:t,end:e,display:o.token,text:o.text,characterCount:o.characterCount,index:o.index}),r.push({start:t,end:e}),i+=o.text.length}}return n.sort((e,t)=>e.start-t.start)},Pe=e=>{try{let t=JSON.parse(e);if(!je(t)||typeof t.text!=`string`)return{text:e,references:[]};if(t.type===Oe||t.type===`openchamber-composer-reference-draft`)return(t.version===2?o(t.text,t.references):void 0)??{text:t.text,references:[]};if(t.type===ke||t.type===`openchamber-pasted-text-draft`){let e=t.version===1&&Array.isArray(t.references)?Ne(t.text,t.references):[];return o(t.text,e)??{text:t.text,references:[]}}}catch{}return{text:e,references:[]}},Fe=`file://`,Ie=e=>{let t=e.replace(/\\/g,`/`);return/^[A-Za-z]:/.test(t)&&(t=`/${t}`),t.split(`/`).map((e,t)=>t===1&&/^[A-Za-z]:$/.test(e)?e:encodeURIComponent(e)).join(`/`)},Le=e=>{let t=e.replace(/\\/g,`/`).trim();return t.toLowerCase().startsWith(Fe)?t:`${Fe}${Ie(t)}`},Re=(e,t)=>`${e}\u0000${t}`,ze=e=>new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(r.result),r.onerror=()=>n(r.error??Error(`Failed to read file`)),r.onabort=()=>n(Error(`File read aborted`)),r.readAsDataURL(e)}),Be=e=>{if(!e.startsWith(`data:`))return 0;let t=e.indexOf(`,`);if(t<0)return 0;let n=e.slice(0,t).toLowerCase(),r=e.slice(t+1);if(!n.endsWith(`;base64`))return 0;let i=0;return r.endsWith(`==`)?i=2:r.endsWith(`=`)&&(i=1),Math.max(0,Math.floor(r.length*3/4)-i)},Ve=(e,t)=>e===t?!0:!e||!t?!1:e.filePath===t.filePath&&e.fileName===t.fileName&&e.relativePath===t.relativePath&&e.fileSize===t.fileSize&&e.selection?.startLine===t.selection?.startLine&&e.selection?.endLine===t.selection?.endLine&&e.selection?.text===t.selection?.text,He=e=>({version:1,key:e,revision:1,text:``,attachments:[],syntheticParts:[],mentions:[]}),Ue=(e,t)=>t.flatMap(t=>{let n=`@${t}`,r=[],i=e.indexOf(n);for(;i>=0;)r.push({kind:`file`,value:t,path:t,label:t,range:{start:i,end:i+n.length}}),i=e.indexOf(n,i+n.length);return r}),We=(r={})=>{let o=r.sink??O(),p=r.repository??R(o),m=r.coordinator??z(o),g=r.blobStore??Y(),_=r.durability??De(g,m,{enabled:r.persistenceEnabled??!0}),v=new Map,y=new Map,b=new Map,x=new Map,S=new Map,C=new Set,w=new Set,T,E,D=0,k=0,ee=!1,te=!1,ne,A=new Set,j=new Map,M=new Set;return n()((n,o)=>{let m=e=>v.set(e,(v.get(e)??0)+1),O=(...e)=>{for(let t of e)b.set(t,(b.get(t)??0)+1),x.delete(t)},N=e=>c(e),P=()=>r.runtimeCapture?.()??{transportIdentity:e(),generation:t()},F=e=>{let t=P();return t.transportIdentity===e.transportIdentity&&t.generation===e.generation},I=e=>[...e.attachments,...e.syntheticParts.flatMap(e=>e.attachments)],re=e=>new Set(I(e).map(e=>e.attachmentRefID)),ie=(e,t,n)=>{let r=re(n);return{draftAttachmentViews:{...e.draftAttachmentViews,[t]:Object.fromEntries(Object.entries(e.draftAttachmentViews[t]??{}).filter(([e])=>r.has(e)))},draftMissingAttachmentRefIDs:{...e.draftMissingAttachmentRefIDs,[t]:(e.draftMissingAttachmentRefIDs[t]??[]).filter(e=>r.has(e))}}},L=()=>r.createID?.()??h(),ae=async(e,t)=>{let n=t instanceof File?t:new File([t],e.filename,{type:e.mimeType});return{id:e.attachmentID,file:n,dataUrl:typeof t==`string`?t:await ze(n),mimeType:e.mimeType,filename:e.filename,size:e.size,source:e.source,...e.serverPath?{serverPath:e.serverPath}:{},...e.vscodePath?{vscodePath:e.vscodePath}:{},...e.vscodeSource?{vscodeSource:e.vscodeSource}:{}}},R=e=>{let t=e.errors[0]??e.cleanupErrors[0];return t?.phase===`metadata`||t?.phase===`blob`&&[`blob-id-conflict`,`database-unavailable`,`invalid-value`,`missing-blob`,`quota-exceeded`,`transaction-aborted`,`transaction-failed`].includes(t.error.code)?t.error.code:`unavailable`},z=(e,t)=>{let r=o(),i=D,a=t??P(),s=[...new Set(e)];if(s.forEach(e=>w.delete(e)),T&&w.size===0&&(clearTimeout(T),T=void 0,E=void 0),!r.persistenceEnabled)return s.forEach(e=>A.add(e)),Promise.resolve({status:`disabled`,keys:s,errors:[],cleanupErrors:[]});let c=new Map(s.map(e=>[e,v.get(e)??0])),l=new Map(s.map(e=>[e,r.drafts[e]?.revision??r.tombstones[e]??0])),u=s.filter(e=>r.drafts[e]),d=Object.fromEntries(u.map(e=>[e,r.draftPersistence[e]?.status===`error`?r.draftPersistence[e]:{status:`saving`,revision:l.get(e)}])),f=Object.fromEntries(u.map(e=>[e,r.draftAttachmentPersistence[e]?.status===`error`?r.draftAttachmentPersistence[e]:{status:`saving`,revision:l.get(e)}]));n(e=>({draftPersistence:{...e.draftPersistence,...d},draftAttachmentPersistence:{...e.draftAttachmentPersistence,...f}})),te||s.forEach(e=>A.add(e));let p=(async()=>{let e=o(),t=await _.commit({drafts:Object.fromEntries(s.flatMap(t=>e.drafts[t]?[[t,e.drafts[t]]]:[])),tombstones:Object.fromEntries(s.flatMap(t=>e.tombstones[t]?[[t,e.tombstones[t]]]:[])),delete:s.filter(t=>!e.drafts[t]),migration:e.migration,legacy:{...e.legacyNewDraft?{new:e.legacyNewDraft}:{},entries:e.legacyDraftEntries},resolveBlobValue:t=>{for(let[n,r]of Object.entries(e.drafts))if(r.key.transportIdentity===t.transportIdentity&&r.key.owner.kind===t.owner.kind&&r.key.owner.ownerID===t.owner.ownerID)return e.draftAttachmentViews[n]?.[t.attachmentOccurrenceRefID]?.file},isCurrent:()=>D===i&&o().persistenceEnabled&&F(a)&&s.every(e=>(v.get(e)??0)===c.get(e)&&(o().drafts[e]?.revision??o().tombstones[e]??0)===l.get(e))}),r=D===i&&o().persistenceEnabled&&F(a);return(!r||t.status===`unseeded`||t.status===`stale`||t.status===`disabled`)&&s.forEach(e=>A.add(e)),r&&n(e=>{let n={...e.draftPersistence};for(let e of u){if((v.get(e)??0)!==c.get(e))continue;let r=l.get(e);if(t.status===`committed`)n[e]={status:`saved`,revision:r};else if(t.status===`unseeded`||t.status===`stale`||t.status===`disabled`)continue;else n[e]={status:`error`,revision:r,errorCode:R(t)}}let r={...e.draftAttachmentPersistence};for(let e of u){if((v.get(e)??0)!==c.get(e))continue;let n=l.get(e);r[e]=t.status===`committed`&&t.cleanupErrors.length===0?{status:`saved`,revision:n}:t.status===`failed`||t.cleanupErrors.length>0?{status:`error`,revision:n,errorCode:R(t)}:r[e]??{status:`idle`,revision:n}}return{draftPersistence:n,draftAttachmentPersistence:r}}),t})();return C.add(p),p.then(()=>C.delete(p),()=>C.delete(p)),p},oe=e=>{let t=o(),r=Object.fromEntries(e.flatMap(e=>{let n=t.drafts[e];return n?[[e,{status:`saving`,revision:n.revision}]]:[]}));Object.keys(r).length&&n(e=>({draftPersistence:{...e.draftPersistence,...r}}))},se=()=>{T&&clearTimeout(T),T=void 0;let e=[...w];w.clear();let t=E;return E=void 0,e.length?z(e,t).then(()=>void 0):Promise.resolve()},ce=e=>{if(!o().persistenceEnabled){A.add(e);return}w.add(e),oe([e]),!T&&(E=P(),T=setTimeout(()=>{se()},40))},le=e=>{let t=[...e];return t.forEach(e=>w.delete(e)),T&&w.size===0&&(clearTimeout(T),T=void 0,E=void 0),z(t)},B=(e,t,r,i=`immediate`)=>{let s=a(e),c=o().drafts[s];if(!c||r!==void 0&&c.revision!==r)return;let l=N(t(c));if(!(!l||a(l.key)!==s))return m(s),n(e=>({drafts:{...e.drafts,[s]:l},...ie(e,s,l)})),i===`deferred`?ce(s):le([s]),l},V=e=>e?l(e):void 0,H=(e=[])=>JSON.parse(JSON.stringify(e)),U=(e,t,n,r=!1,i=!1)=>({status:e,...V(n)?{record:V(n)}:{},errors:H(t?.errors),cleanupErrors:H(t?.cleanupErrors),current:r,durable:i}),W=(e,t,n,r,i=!1,a=!1)=>({status:e,errors:H(t?.errors),cleanupErrors:H(t?.cleanupErrors),current:i,durable:a,source:V(n),destination:V(r)}),G=e=>e.status,K=e=>typeof e==`number`&&Number.isSafeInteger(e)&&e>0,q=(e,...t)=>{let n={...e};for(let e of t)delete n[e];return n},ue=async(e,t)=>{let n={},r=o().draftAttachmentViews[a(e.key)]??{};for(let i of I(e)){let e;if(i.locator.kind===`url`){let n=t?.get(i.attachmentRefID);e=n===void 0?i.locator.url:n}else e=t?.get(i.attachmentRefID)??r[i.attachmentRefID]?.file??(typeof r[i.attachmentRefID]?.dataUrl==`string`&&u(r[i.attachmentRefID].dataUrl)?r[i.attachmentRefID].dataUrl:void 0);if(i.locator.kind===`url`&&e!==void 0&&(e!==i.locator.url||!u(e))||i.locator.kind===`blob`&&e!==void 0&&!(e instanceof Blob)&&!(typeof e==`string`&&u(e)))return;e!==void 0&&(n[i.attachmentRefID]=await ae(i,e))}return n},J=e=>e?a(e):`legacy-unowned`,Y=e=>j.get(e)??0,de=e=>{j.set(e,Y(e)+1)},X=(e,t,r=!1)=>{r&&de(e),n(n=>{let r=t(n.attachmentBuckets[e]??[]);return{attachmentBuckets:{...n.attachmentBuckets,[e]:r},...J(n.activeAttachmentDraft)===e?{attachedFiles:r}:{}}})};return{drafts:{},tombstones:{},draftHydration:{},draftPersistence:{},draftAttachmentViews:{},draftMissingAttachmentRefIDs:{},draftAttachmentPersistence:{},persistenceEnabled:r.persistenceEnabled??!0,legacyDraftEntries:{},migration:{complete:!1,claimedTransportIdentity:``},captureDraftRuntime:()=>P(),commitDraftSnapshot:async e=>{let t=a(e.key),r=e.runtime;if(r.transportIdentity!==e.key.transportIdentity||!F(r))return U(`stale`,void 0);let i=o(),s=i.drafts[t],c=i.tombstones[t]??0;if(e.expectedRevision!==`absent`&&!K(e.expectedRevision)||!Number.isSafeInteger(c)||c<0)return U(`failed`,void 0);if(e.expectedRevision===`absent`?s:s?.revision!==e.expectedRevision)return U(`conflict`,void 0,s);let u=e.expectedRevision===`absent`?c+1:e.expectedRevision+1;if(!K(u))return U(`failed`,void 0);let d=N({version:1,key:e.key,revision:u,...e.snapshot});if(!d)return U(`failed`,void 0);let f=await ue(d,e.values);if(!f)return U(`failed`,void 0);let p=v.get(t)??0,h=s?.revision??c,g=await _.commit({drafts:{[t]:d},isCurrent:()=>F(r)&&(v.get(t)??0)===p&&(o().drafts[t]?.revision??o().tombstones[t]??0)===h,resolveBlobValue:t=>e.values?.get(t.attachmentOccurrenceRefID)});if(g.status!==`committed`)return U(G(g),g,s);let y=(v.get(t)??0)===p&&(o().drafts[t]?.revision??o().tombstones[t]??0)===h,b=F(r);if(!y)return b||n(e=>({draftAttachmentViews:q(e.draftAttachmentViews,t),draftMissingAttachmentRefIDs:q(e.draftMissingAttachmentRefIDs,t),draftHydration:q(e.draftHydration,t),draftPersistence:q(e.draftPersistence,t),draftAttachmentPersistence:q(e.draftAttachmentPersistence,t)})),U(`stale`,g,d,!1,!0);let x=l(d);return x?(m(t),O(t),n(e=>({drafts:{...e.drafts,[t]:x},tombstones:(()=>{let n={...e.tombstones};return delete n[t],n})(),draftAttachmentViews:b?{...e.draftAttachmentViews,[t]:f}:q(e.draftAttachmentViews,t),draftMissingAttachmentRefIDs:b?{...e.draftMissingAttachmentRefIDs,[t]:[]}:q(e.draftMissingAttachmentRefIDs,t),draftHydration:b?e.draftHydration:q(e.draftHydration,t),draftPersistence:b?{...e.draftPersistence,[t]:{status:`saved`,revision:x.revision}}:q(e.draftPersistence,t),draftAttachmentPersistence:b?{...e.draftAttachmentPersistence,[t]:g.cleanupErrors.length?{status:`error`,revision:x.revision,errorCode:R(g)}:{status:`saved`,revision:x.revision}}:q(e.draftAttachmentPersistence,t)})),U(b?`committed`:`stale`,g,x,b,!0)):U(`failed`,g)},deleteDraftSnapshot:async e=>{let t=a(e.key),r=e.runtime;if(r.transportIdentity!==e.key.transportIdentity||!F(r))return U(`stale`,void 0);let i=o(),s=i.drafts[t],c=i.tombstones[t]??0;if(!K(e.expectedRevision)||!Number.isSafeInteger(c)||c<0)return U(`failed`,void 0);if(!s||s.revision!==e.expectedRevision)return U(`conflict`,void 0);let l=e.expectedRevision+1;if(!K(l))return U(`failed`,void 0);let u=v.get(t)??0,d=s.revision,f=Math.max(c,l),p=await _.commit({tombstones:{[t]:f},delete:[t],isCurrent:()=>F(r)&&(v.get(t)??0)===u&&o().drafts[t]?.revision===d&&(o().tombstones[t]??0)===c});if(p.status!==`committed`)return U(G(p),p);let h=(v.get(t)??0)===u&&o().drafts[t]?.revision===d&&(o().tombstones[t]??0)===c,g=F(r);return h?(m(t),O(t),n(e=>{let n={...e.drafts};return delete n[t],{drafts:n,tombstones:{...e.tombstones,[t]:Math.max(e.tombstones[t]??0,f)},draftAttachmentViews:q(e.draftAttachmentViews,t),draftMissingAttachmentRefIDs:q(e.draftMissingAttachmentRefIDs,t),draftHydration:q(e.draftHydration,t),draftPersistence:q(e.draftPersistence,t),draftAttachmentPersistence:q(e.draftAttachmentPersistence,t)}}),U(g?`committed`:`stale`,p,void 0,g,!0)):(g||n(e=>({draftAttachmentViews:q(e.draftAttachmentViews,t),draftMissingAttachmentRefIDs:q(e.draftMissingAttachmentRefIDs,t),draftHydration:q(e.draftHydration,t),draftPersistence:q(e.draftPersistence,t),draftAttachmentPersistence:q(e.draftAttachmentPersistence,t)})),U(`stale`,p,void 0,!1,!0))},finalizeDraftOwnership:async e=>{let t=a(e.source),r=a(e.destination),i=e.runtime,s=o(),c=s.drafts[t],u=s.drafts[r];if(t===r||e.destination.owner.kind!==`session`||e.source.transportIdentity!==i.transportIdentity||e.destination.transportIdentity!==i.transportIdentity||!F(i))return W(`stale`,void 0,c,u);if(!K(e.expectedSourceRevision))return W(`failed`,void 0,c,u);if(!c||c.revision!==e.expectedSourceRevision||u)return W(`conflict`,void 0,c,u);let d=v.get(t)??0,f=v.get(r)??0,p=s.tombstones[t]??0,h=s.tombstones[r]??0;if(!Number.isSafeInteger(p)||p<0||!Number.isSafeInteger(h)||h<0)return W(`failed`,void 0,c,u);let g=Math.max(c.revision+1,h+1);if(!K(g))return W(`failed`,void 0,c,u);let y=N(e.disposition===`preserve`?{...c,key:e.destination,revision:g}:{...He(e.destination),revision:g});if(!y)return W(`failed`,void 0,c,u);let b=await _.commit({drafts:{[r]:y},tombstones:{[t]:Math.max(p,g)},delete:[t],isCurrent:()=>F(i)&&(v.get(t)??0)===d&&(v.get(r)??0)===f&&o().drafts[t]?.revision===c.revision&&!o().drafts[r]&&(o().tombstones[t]??0)===p&&(o().tombstones[r]??0)===h,resolveBlobValue:e=>s.draftAttachmentViews[t]?.[e.attachmentOccurrenceRefID]?.file});if(b.status!==`committed`)return W(G(b),b,c,u);let x=(v.get(t)??0)===d&&o().drafts[t]?.revision===c.revision&&(o().tombstones[t]??0)===p,S=(v.get(r)??0)===f&&!o().drafts[r]&&(o().tombstones[r]??0)===h,C=F(i),w=l(y);if(!w)return W(`failed`,b,c,u);if(C&&!x&&!S)return W(`stale`,b,c,y,!1,!0);x&&(m(t),O(t)),S&&(m(r),O(r)),n(n=>{let i=n.drafts,a=n.tombstones;(x||S)&&(i={...i}),(x||S)&&(a={...a}),x&&(delete i[t],a[t]=Math.max(a[t]??0,g)),S&&(i[r]=w,delete a[r]);let o=n.draftHydration,s=n.draftPersistence,c=n.draftAttachmentViews,l=n.draftMissingAttachmentRefIDs,u=n.draftAttachmentPersistence;return C?(x&&(o=q(o,t),s=q(s,t),c=q(c,t),l=q(l,t),u=q(u,t)),S&&(o=q(o,r),s={...q(s,r),[r]:{status:`saved`,revision:w.revision}},c=q(c,r),l=q(l,r),u={...q(u,r),[r]:b.cleanupErrors.length?{status:`error`,revision:w.revision,errorCode:R(b)}:{status:`saved`,revision:w.revision}},C&&x&&e.disposition===`preserve`&&(c={...c,[r]:n.draftAttachmentViews[t]??{}},l={...l,[r]:n.draftMissingAttachmentRefIDs[t]??[]}))):(o=q(o,t,r),s=q(s,t,r),c=q(c,t,r),l=q(l,t,r),u=q(u,t,r)),{drafts:i,tombstones:a,draftHydration:o,draftPersistence:s,draftAttachmentViews:c,draftMissingAttachmentRefIDs:l,draftAttachmentPersistence:u}});let T=x&&S&&C;return W(T?`committed`:`stale`,b,c,y,T,!0)},flushDraftPersistence:async()=>{for(await se();C.size;)await Promise.all([...C]);await _.flush()},ensureDraft:e=>{let t=a(e),r=o().drafts[t];if(r)return r;let i=N({...He(e),revision:(o().tombstones[t]??0)+1});if(!i)throw Error(`Invalid empty draft`);return m(t),n(e=>({drafts:{...e.drafts,[t]:i}})),le([t]),i},getDraft:e=>o().drafts[a(e)],setDraftText:(e,t)=>{let n=o().getDraft(e)??o().ensureDraft(e);return B(e,e=>({...e,revision:e.revision+1,text:t,mentions:e.mentions.filter(e=>e.range.end<=t.length&&t.slice(e.range.start,e.range.end)===`@${e.value}`),composerReferences:[]}),n.revision,`deferred`)??n},setDraftComposerDocument:(e,t)=>{let n=o().getDraft(e)??o().ensureDraft(e);return o().setDraftComposerState(e,{document:t,mentions:n.mentions})},setDraftComposerState:(e,t)=>{let n=o().getDraft(e)??o().ensureDraft(e);return B(e,e=>({...e,revision:e.revision+1,text:t.document.text,composerReferences:t.document.references,mentions:t.mentions}),n.revision,`deferred`)},replaceDraft:(e,t,n)=>B(e,e=>({version:1,key:e.key,revision:e.revision+1,text:n.text,attachments:n.attachments,syntheticParts:n.syntheticParts,mentions:n.mentions,...n.composerReferences===void 0?{}:{composerReferences:n.composerReferences}}),t),setDraftMentions:(e,t)=>B(e,e=>({...e,revision:e.revision+1,mentions:t})),addDraftMention:(e,t)=>B(e,e=>({...e,revision:e.revision+1,mentions:[...e.mentions,t]})),removeDraftMention:(e,t)=>B(e,e=>({...e,revision:e.revision+1,mentions:e.mentions.filter(e=>e.value!==t)})),setDraftSyntheticParts:(e,t)=>B(e,e=>({...e,revision:e.revision+1,syntheticParts:t})),consumeDraftSyntheticParts:(e,t)=>{let n=o().getDraft(e);if(!n)return null;let r=n.syntheticParts.filter(e=>!t?.(e)),i=n.syntheticParts.filter(e=>t?.(e));return B(e,e=>({...e,revision:e.revision+1,syntheticParts:i}),n.revision)?r:null},setDraftAttachments:(e,t)=>B(e,e=>({...e,revision:e.revision+1,attachments:t})),addDraftLocalAttachment:async(e,t,r={})=>{let c=o().getDraft(e);if(r.partID&&!c?.syntheticParts.some(e=>e.partID===r.partID))return;let l=a(e),u=v.get(l)??0,d=o().tombstones[l]??0,f=P(),p=t instanceof File?t:new File([t],r.filename??`attachment`,{type:t.type}),h;try{h=await ze(p)}catch{let e=o().drafts[l];if(F(f)&&(o().tombstones[l]??0)===d&&(e?a(e.key)===l:(v.get(l)??0)===u)&&(!r.partID||e?.syntheticParts.some(e=>e.partID===r.partID))){let t=e?.revision??o().tombstones[l]??0;n(e=>({draftAttachmentPersistence:{...e.draftAttachmentPersistence,[l]:{status:`error`,revision:t,errorCode:`transaction-failed`}}}))}return}if(!F(f)||(o().tombstones[l]??0)!==d)return;let g=o().drafts[l];if(!g&&(v.get(l)??0)!==u)return;let _=g??o().ensureDraft(e);if(a(_.key)!==l||r.partID&&!_.syntheticParts.some(e=>e.partID===r.partID))return;let y=r.attachmentID??L(),b=r.partID?s(r.partID,y):i(y),x=L(),S={attachmentID:y,attachmentRefID:b,filename:r.filename??(t instanceof File?t.name:`attachment`),mimeType:t.type,size:t.size,locator:{kind:`blob`,blobID:x},source:r.source??`local`,...r.vscodePath?{vscodePath:r.vscodePath}:{},...r.vscodeSource?{vscodeSource:r.vscodeSource}:{}},C=r.partID?{..._,revision:_.revision+1,syntheticParts:_.syntheticParts.map(e=>e.partID===r.partID?{...e,attachments:[...e.attachments,S]}:e)}:{..._,revision:_.revision+1,attachments:[..._.attachments,S]},w=N(C);if(!w)return;m(l);let T={id:y,file:p,dataUrl:h,mimeType:S.mimeType,filename:S.filename,size:S.size,source:S.source,...r.vscodePath?{vscodePath:r.vscodePath}:{},...r.vscodeSource?{vscodeSource:r.vscodeSource}:{}};return n(e=>({drafts:{...e.drafts,[l]:w},draftAttachmentViews:{...e.draftAttachmentViews,[l]:{...e.draftAttachmentViews[l],[b]:T}}})),await z([l]),S},addDraftDurableAttachment:(e,t)=>{let r=o().getDraft(e)??o().ensureDraft(e);if(t.partID&&!r.syntheticParts.some(e=>e.partID===t.partID))return;let c=t.attachmentID??L(),l=t.partID?s(t.partID,c):i(c),u={attachmentID:c,attachmentRefID:l,filename:t.filename,mimeType:t.mimeType,size:t.size,source:t.source,locator:{kind:`url`,url:t.url},...t.serverPath?{serverPath:t.serverPath}:{},...t.vscodePath?{vscodePath:t.vscodePath}:{},...t.vscodeSource?{vscodeSource:t.vscodeSource}:{}},d=t.partID?{...r,revision:r.revision+1,syntheticParts:r.syntheticParts.map(e=>e.partID===t.partID?{...e,attachments:[...e.attachments,u]}:e)}:{...r,revision:r.revision+1,attachments:[...r.attachments,u]},f=N(d);if(!f)return;let p=a(e);m(p);let h={id:c,file:new File([],u.filename,{type:u.mimeType}),dataUrl:t.url,mimeType:u.mimeType,filename:u.filename,size:u.size,source:u.source,...u.serverPath?{serverPath:u.serverPath}:{},...u.vscodePath?{vscodePath:u.vscodePath}:{},...u.vscodeSource?{vscodeSource:u.vscodeSource}:{}};return n(e=>({drafts:{...e.drafts,[p]:f},draftAttachmentViews:{...e.draftAttachmentViews,[p]:{...e.draftAttachmentViews[p],[l]:h}}})),z([p]),u},getDraftAttachmentViews:e=>{let t=a(e),n=o().drafts[t],r=o().draftAttachmentViews[t]??{};return n?I(n).flatMap(e=>r[e.attachmentRefID]?[r[e.attachmentRefID]]:[]):[]},retryDraftAttachmentPersistence:async e=>{let t=a(e);if(!o().persistenceEnabled||!o().drafts[t]&&!o().tombstones[t])return;let r=await _.retryCleanup();r.cleanupErrors.length&&n(e=>({draftAttachmentPersistence:{...e.draftAttachmentPersistence,[t]:{status:`error`,revision:e.drafts[t]?.revision??e.tombstones[t],errorCode:R(r)}}})),await z([t])},hydrateDraftAttachments:async e=>{let t=a(e),r=x.get(t);if(r)return r;let i=o().drafts[t];if(!i)return;let s=(b.get(t)??0)+1;b.set(t,s);let c=P(),l=D,u=(async()=>{n(e=>({draftHydration:{...e.draftHydration,[t]:`loading`}}));let e=()=>{if(b.get(t)!==s)return;let e=o(),r=e.draftAttachmentViews[t],i=e.draftMissingAttachmentRefIDs[t]??[];n(e=>({draftHydration:{...e.draftHydration,[t]:i.length?`degraded`:Object.keys(r??{}).length?`ready`:`idle`}}))},r={},a=[];for(let u of I(i)){let d=u.locator.kind===`url`?{ok:!0,value:u.locator.url}:await g.read(u.locator.blobID);if(!d.ok){if(d.error.code===`missing-blob`)a.push(u.attachmentRefID);else{b.get(t)===s&&D===l&&F(c)&&o().drafts[t]===i?n(e=>({draftHydration:{...e.draftHydration,[t]:`error`}})):e();return}continue}try{r[u.attachmentRefID]=await ae(u,d.value)}catch{b.get(t)===s&&D===l&&F(c)&&o().drafts[t]===i?n(e=>({draftHydration:{...e.draftHydration,[t]:`error`}})):e();return}}let u=o(),d=u.drafts[t],f=b.get(t);if(f===s&&D===l&&F(c)&&d===i)n(e=>({draftAttachmentViews:{...e.draftAttachmentViews,[t]:r},draftMissingAttachmentRefIDs:{...e.draftMissingAttachmentRefIDs,[t]:a},draftHydration:{...e.draftHydration,[t]:a.length?`degraded`:`ready`}}));else if(f===s){let e=u.draftAttachmentViews[t],r=u.draftMissingAttachmentRefIDs[t]??[];n(n=>({draftHydration:{...n.draftHydration,[t]:r.length?`degraded`:Object.keys(e??{}).length?`ready`:`idle`}}))}})();x.set(t,u);try{await u}finally{x.get(t)===u&&x.delete(t)}},removeDraftAttachment:async(e,t)=>{let r=a(e),i=o().drafts[r],s=i&&I(i).find(e=>e.attachmentRefID===t);if(!i||!s)return!1;let c=d(s)?f(i.text,[s.filename],i.mentions,i.composerReferences):void 0,l=N({...i,revision:i.revision+1,...c?.changed?{text:c.text,mentions:c.mentions,...c.composerReferences===void 0?{}:{composerReferences:c.composerReferences}}:{},attachments:i.attachments.filter(e=>e.attachmentRefID!==t),syntheticParts:i.syntheticParts.map(e=>({...e,attachments:e.attachments.filter(e=>e.attachmentRefID!==t)}))});return l?(m(r),n(e=>{let n={...e.draftAttachmentViews[r]};return delete n[t],{drafts:{...e.drafts,[r]:l},draftAttachmentViews:{...e.draftAttachmentViews,[r]:n},draftMissingAttachmentRefIDs:{...e.draftMissingAttachmentRefIDs,[r]:(e.draftMissingAttachmentRefIDs[r]??[]).filter(e=>e!==t)}}}),(await z([r])).status===`committed`):!1},replaceDraftAttachment:async(e,t,r,c)=>{let l=a(e),u=o().drafts[l],d=u&&I(u).find(e=>e.attachmentRefID===t);if(!u||!d)return;let f=P(),p=o().tombstones[l]??0,h=r instanceof File?r:new File([r],c?.filename??`attachment`,{type:r.type}),g;try{g=await ze(h)}catch{let e=o().drafts[l],r=e&&I(e).find(e=>e.attachmentRefID===t);F(f)&&(o().tombstones[l]??0)===p&&e&&r?.attachmentID===d.attachmentID&&r.attachmentRefID===d.attachmentRefID&&a(e.key)===l&&n(t=>({draftAttachmentPersistence:{...t.draftAttachmentPersistence,[l]:{status:`error`,revision:e.revision,errorCode:`transaction-failed`}}}));return}let _=o().drafts[l],v=_&&I(_).find(e=>e.attachmentRefID===t);if(!F(f)||(o().tombstones[l]??0)!==p||!_||v?.attachmentID!==d.attachmentID||v.attachmentRefID!==d.attachmentRefID||a(_.key)!==l)return;let y=_.syntheticParts.find(e=>e.attachments.some(e=>e.attachmentRefID===t)),b=L(),x={attachmentID:b,attachmentRefID:y?s(y.partID,b):i(b),filename:c?.filename??h.name,mimeType:h.type,size:h.size,locator:{kind:`blob`,blobID:L()},source:c?.source??`local`,...c?.vscodePath?{vscodePath:c.vscodePath}:{},...c?.vscodeSource?{vscodeSource:c.vscodeSource}:{}},S=N({..._,revision:_.revision+1,attachments:y?_.attachments:_.attachments.map(e=>e.attachmentRefID===t?x:e),syntheticParts:_.syntheticParts.map(e=>e.partID===y?.partID?{...e,attachments:e.attachments.map(e=>e.attachmentRefID===t?x:e)}:e)});if(!S)return;m(l);let C={id:b,file:h,dataUrl:g,mimeType:x.mimeType,filename:x.filename,size:x.size,source:x.source,...x.vscodePath?{vscodePath:x.vscodePath}:{},...x.vscodeSource?{vscodeSource:x.vscodeSource}:{}};return n(e=>{let n={...e.draftAttachmentViews[l]};return delete n[t],{drafts:{...e.drafts,[l]:S},draftAttachmentViews:{...e.draftAttachmentViews,[l]:{...n,[x.attachmentRefID]:C}},draftMissingAttachmentRefIDs:{...e.draftMissingAttachmentRefIDs,[l]:(e.draftMissingAttachmentRefIDs[l]??[]).filter(e=>e!==t)}}}),(await z([l])).status===`committed`?x:void 0},replaceDraftRootAttachments:async(e,t)=>{let n=a(e),r=P();if(r.transportIdentity!==e.transportIdentity||!F(r))return U(`stale`,void 0);let s=o().drafts[n],c=s?s.revision:`absent`,l=[],d=new Map;for(let e of t){let t=e.id,n=i(t);if(e.source===`server`&&e.dataUrl&&u(e.dataUrl))l.push({attachmentID:t,attachmentRefID:n,filename:e.filename,mimeType:e.mimeType,size:e.size,source:`server`,locator:{kind:`url`,url:e.dataUrl},...e.serverPath?{serverPath:e.serverPath}:{}}),d.set(n,e.dataUrl);else if(e.source===`vscode`&&e.vscodeSource===`file`&&e.dataUrl&&u(e.dataUrl))l.push({attachmentID:t,attachmentRefID:n,filename:e.filename,mimeType:e.mimeType,size:e.size,source:`vscode`,locator:{kind:`url`,url:e.dataUrl},...e.vscodePath?{vscodePath:e.vscodePath}:{},vscodeSource:`file`}),d.set(n,e.dataUrl);else{let r=e.file instanceof File?e.file:new File([e.file],e.filename,{type:e.mimeType}),i=L();l.push({attachmentID:t,attachmentRefID:n,filename:e.filename,mimeType:e.mimeType,size:e.size,source:e.source===`vscode`?`vscode`:`local`,locator:{kind:`blob`,blobID:i},...e.vscodePath?{vscodePath:e.vscodePath}:{},...e.vscodeSource===`selection`?{vscodeSource:`selection`}:{}}),d.set(n,r)}}let f=s?.syntheticParts??[];for(let e of f)for(let t of e.attachments)t.locator.kind===`url`&&!d.has(t.attachmentRefID)&&d.set(t.attachmentRefID,t.locator.url);let p={text:s?.text??``,attachments:l,syntheticParts:f,mentions:s?.mentions??[],...s?.composerReferences===void 0?{}:{composerReferences:s.composerReferences}};return o().commitDraftSnapshot({key:e,expectedRevision:c,snapshot:p,values:d,runtime:r})},restoreDraftRootAttachments:async(e,t)=>{let n=a(e),r=P();if(r.transportIdentity!==e.transportIdentity||!F(r))return U(`stale`,void 0);let s=o().drafts[n],c=s?s.revision:`absent`,l=new Set(t.map(e=>e.id)),d=[],f=new Map;for(let e of t){let t=e.id,n=i(t);if(e.source===`server`&&e.dataUrl&&u(e.dataUrl))d.push({attachmentID:t,attachmentRefID:n,filename:e.filename,mimeType:e.mimeType,size:e.size,source:`server`,locator:{kind:`url`,url:e.dataUrl},...e.serverPath?{serverPath:e.serverPath}:{}}),f.set(n,e.dataUrl);else if(e.source===`vscode`&&e.vscodeSource===`file`&&e.dataUrl&&u(e.dataUrl))d.push({attachmentID:t,attachmentRefID:n,filename:e.filename,mimeType:e.mimeType,size:e.size,source:`vscode`,locator:{kind:`url`,url:e.dataUrl},...e.vscodePath?{vscodePath:e.vscodePath}:{},vscodeSource:`file`}),f.set(n,e.dataUrl);else{let r=e.file instanceof File?e.file:new File([e.file],e.filename,{type:e.mimeType}),i=L();d.push({attachmentID:t,attachmentRefID:n,filename:e.filename,mimeType:e.mimeType,size:e.size,source:e.source===`vscode`?`vscode`:`local`,locator:{kind:`blob`,blobID:i},...e.vscodePath?{vscodePath:e.vscodePath}:{},...e.vscodeSource===`selection`?{vscodeSource:`selection`}:{}}),f.set(n,r)}}let p=o().draftAttachmentViews[n]??{};for(let e of s?.attachments??[])if(!l.has(e.attachmentID))if(d.push(JSON.parse(JSON.stringify(e))),e.locator.kind===`url`)f.set(e.attachmentRefID,e.locator.url);else{let t=p[e.attachmentRefID];t?.file instanceof Blob?f.set(e.attachmentRefID,t.file):typeof t?.dataUrl==`string`&&u(t.dataUrl)&&f.set(e.attachmentRefID,t.dataUrl)}let m=s?.syntheticParts??[];for(let e of m)for(let t of e.attachments)t.locator.kind===`url`&&!f.has(t.attachmentRefID)&&f.set(t.attachmentRefID,t.locator.url);let h={text:s?.text??``,attachments:d,syntheticParts:m,mentions:s?.mentions??[],...s?.composerReferences===void 0?{}:{composerReferences:s.composerReferences}};return o().commitDraftSnapshot({key:e,expectedRevision:c,snapshot:h,values:f,runtime:r})},deleteDraft:(e,t)=>{let r=a(e),i=o().drafts[r];if(!i||t!==void 0&&i.revision!==t)return!1;let s=i.revision+1;return K(s)?(m(r),O(r),n(e=>{let t={...e.drafts};delete t[r];let n={...e.draftHydration},i={...e.draftPersistence},a={...e.draftAttachmentViews},o={...e.draftMissingAttachmentRefIDs},c={...e.draftAttachmentPersistence};return delete n[r],delete i[r],delete a[r],delete o[r],delete c[r],{drafts:t,tombstones:{...e.tombstones,[r]:Math.max(e.tombstones[r]??0,s)},draftHydration:n,draftPersistence:i,draftAttachmentViews:a,draftMissingAttachmentRefIDs:o,draftAttachmentPersistence:c}}),z([r]),!0):!1},moveDraft:(e,t,r)=>{let i=a(e),s=a(t),c=o().drafts[i];if(!c||i===s||r!==void 0&&c.revision!==r||o().drafts[s]||(o().tombstones[s]??0)>=c.revision+1||[...c.attachments,...c.syntheticParts.flatMap(e=>e.attachments)].some(e=>e.locator.kind===`blob`))return;let l=N({...c,key:t,revision:c.revision+1});if(l)return m(i),m(s),O(i,s),n(e=>{let t={...e.drafts};delete t[i];let n={...e.tombstones,[i]:Math.max(e.tombstones[i]??0,l.revision)};(n[s]??0)<l.revision&&delete n[s];let r=e=>{let t={...e},n=t[i];return delete t[i],delete t[s],n===void 0?t:{...t,[s]:n}};return{drafts:{...t,[s]:l},tombstones:n,draftHydration:r(e.draftHydration),draftPersistence:r(e.draftPersistence),draftAttachmentViews:r(e.draftAttachmentViews),draftMissingAttachmentRefIDs:r(e.draftMissingAttachmentRefIDs),draftAttachmentPersistence:r(e.draftAttachmentPersistence)}}),z([i,s]),l},moveDraftWithAttachments:async(e,t,r)=>{let i=a(e),s=a(t),c=o().drafts[i];if(!c||i===s||r!==void 0&&c.revision!==r||o().drafts[s]||(o().tombstones[s]??0)>=c.revision+1)return;let l=N({...c,key:t,revision:c.revision+1});if(l)return m(i),m(s),O(i,s),n(e=>{let t={...e.drafts};delete t[i];let n={...e.tombstones,[i]:Math.max(e.tombstones[i]??0,l.revision)};(n[s]??0)<l.revision&&delete n[s];let r=e=>{let t={...e},n=t[i];return delete t[i],delete t[s],n===void 0?t:{...t,[s]:n}};return{drafts:{...t,[s]:l},tombstones:n,draftHydration:r(e.draftHydration),draftPersistence:r(e.draftPersistence),draftAttachmentViews:r(e.draftAttachmentViews),draftMissingAttachmentRefIDs:r(e.draftMissingAttachmentRefIDs),draftAttachmentPersistence:r(e.draftAttachmentPersistence)}}),(await z([i,s])).status===`committed`?l:void 0},setDraftPersistenceEnabled:async e=>{if(D+=1,!e){T&&clearTimeout(T),T=void 0,w.clear(),E=void 0,n({persistenceEnabled:!1,draftPersistence:{}}),await _.setEnabled(!1),await _.flush();return}n({persistenceEnabled:!0}),await _.setEnabled(!0);let t=P();te||await o().hydrateDraftMetadata(t.transportIdentity);let r=new Set([...Object.keys(o().drafts),...Object.keys(o().tombstones),...A]);A.clear(),await z(r),await _.flush()},hydrateDraftMetadata:e=>{let t=S.get(e);if(t)return t;let r=(async()=>{let t=(y.get(e)??0)+1;y.set(e,t);let r=P();if(r.transportIdentity!==e)return!1;let i=D,s=new Map(v),c=k,l=Object.entries(o().drafts).filter(([,t])=>t.key.transportIdentity===e).map(([e])=>e);n(e=>({draftHydration:{...e.draftHydration,...Object.fromEntries(l.map(e=>[e,`loading`]))}}));let u=o().persistenceEnabled,d;try{d=await p.migrate(e,{persistenceEnabled:u})}catch{return!1}if(y.get(e)!==t||D!==i||!F(r))return!1;if(!d.ok)return n(e=>({draftHydration:{...e.draftHydration,...Object.fromEntries(l.map(t=>[t,e.drafts[t]?`degraded`:`error`]))}})),!1;let f=d.value;if(!te){ne??=_.seed(f).finally(()=>{ne=void 0});let a;try{a=await ne}catch{return!1}if(y.get(e)!==t||D!==i||!F(r))return!1;if(a.status!==`committed`&&a.status!==`disabled`)return n(e=>({draftHydration:{...e.draftHydration,...Object.fromEntries(l.map(e=>[e,`degraded`]))}})),!1;a.status===`committed`&&(te=!0)}let m=o(),h={...m.drafts},g={...m.tombstones},b=new Set;for(let[e,t]of Object.entries(f.tombstones))(v.get(e)??0)===(s.get(e)??0)&&(t>=(g[e]??0)&&(g[e]=t,(h[e]?.revision??0)<=t&&delete h[e]),b.add(e));for(let[t,n]of Object.entries(f.drafts)){if(n.key.transportIdentity!==e||(v.get(t)??0)!==(s.get(t)??0))continue;let r=h[t],i=N(n);i&&(!r||r.revision<i.revision)&&(g[t]??0)<i.revision&&(h[t]=i),b.add(t)}let x=k===c?{...f.legacy.entries}:{...m.legacyDraftEntries};if(f.migration.claimedTransportIdentity===e&&k===c)for(let[t,n]of Object.entries(x)){let r={transportIdentity:e,owner:{kind:`session`,ownerID:t}},i=a(r),o=Pe(n.text),c=N({...He(r),text:o.text,composerReferences:o.references,mentions:Ue(o.text,n.mentions)});c&&!h[i]&&!g[i]&&(v.get(i)??0)===(s.get(i)??0)&&(h[i]=c),delete x[t],b.add(i)}n(e=>({drafts:h,tombstones:g,legacyNewDraft:k===c&&!ee?f.legacy.new:e.legacyNewDraft,legacyDraftEntries:x,migration:k===c?f.migration:e.migration,draftHydration:{...e.draftHydration,...Object.fromEntries([...b].map(e=>[e,`ready`]))}}));let S=[...A];for(let e of S)b.add(e);A.clear();try{await z(b),await _.flush()}catch{return!1}return y.get(e)===t&&D===i&&F(r)})();return S.set(e,r),r.finally(()=>{S.get(e)===r&&S.delete(e)}).catch(()=>void 0),r},claimLegacyNewDraft:async e=>{let t=o().legacyNewDraft;if(!t)return o().getDraft(e);let r=a(e),i=o().drafts[r];if(k+=1,ee=!0,i||o().tombstones[r])return n({legacyNewDraft:void 0}),z([r]),i;let s=Pe(t.text),c=N({...He(e),text:s.text,composerReferences:s.references,mentions:Ue(s.text,t.mentions)});if(c)return m(r),n(e=>({drafts:{...e.drafts,[r]:c},legacyNewDraft:void 0})),z([r]),c},pendingInputText:null,pendingInputMode:`replace`,pendingSyntheticParts:null,pendingPresetSubmit:null,attachedFiles:[],attachmentBuckets:{"legacy-unowned":[]},activeAttachmentDraft:null,activeEditorFile:null,setPendingInputText:(e,t=`replace`)=>n({pendingInputText:e,pendingInputMode:t}),consumePendingInputText:()=>{let{pendingInputText:e,pendingInputMode:t}=o();return e===null?null:(n({pendingInputText:null,pendingInputMode:`replace`}),{text:e,mode:t})},requestPresetSubmit:e=>n({pendingPresetSubmit:e}),consumePendingPresetSubmit:()=>{let{pendingPresetSubmit:e}=o();return e===null?null:(n({pendingPresetSubmit:null}),e)},setPendingSyntheticParts:e=>n({pendingSyntheticParts:e}),consumePendingSyntheticParts:()=>{let{pendingSyntheticParts:e}=o();return e!==null&&n({pendingSyntheticParts:null}),e},setActiveAttachmentDraft:e=>{let t=J(e);n(n=>({activeAttachmentDraft:e,attachedFiles:n.attachmentBuckets[t]??[],attachmentBuckets:n.attachmentBuckets[t]?n.attachmentBuckets:{...n.attachmentBuckets,[t]:[]}}))},addAttachedFile:async e=>{let t=o().activeAttachmentDraft;if(t){let n=J(t),r=Y(n),i=await o().addDraftLocalAttachment(t,e);r!==Y(n)&&i&&o().removeDraftAttachment(t,i.attachmentRefID);return}let n=`${Date.now()}-${Math.random().toString(36).slice(2)}`,r=J(null),i=Y(r),a;try{a=await ze(e)}catch{return}if(i!==Y(r))return;let s={id:n,file:e,dataUrl:a,mimeType:e.type,filename:e.name,size:e.size,source:`local`};X(r,e=>[...e,s])},removeAttachedFile:e=>{let t=o().activeAttachmentDraft;if(t){let n=o().getDraft(t),r=n?[...n.attachments,...n.syntheticParts.flatMap(e=>e.attachments)].find(t=>t.attachmentID===e):void 0;r&&o().removeDraftAttachment(t,r.attachmentRefID);return}X(J(null),t=>t.filter(t=>t.id!==e))},setAttachedFiles:e=>{X(J(o().activeAttachmentDraft),()=>e,!0)},clearAttachedFiles:()=>{let e=o().activeAttachmentDraft;if(e){de(J(e)),o().getDraft(e)||o().ensureDraft(e),o().setDraftAttachments(e,[]);return}X(J(null),()=>[],!0)},addDraftVSCodeFileAttachment:(e,t,n,r)=>{if(o().getDraftAttachmentViews(e).some(e=>e.source===`vscode`&&e.vscodeSource===`file`&&(e.vscodePath||``)===t)||(o().getDraft(e)?.attachments.some(e=>e.source===`vscode`&&e.vscodeSource===`file`&&(e.vscodePath||``)===t)??!1))return;let i=Le(t);o().addDraftDurableAttachment(e,{filename:n,mimeType:`text/plain`,size:r||0,source:`vscode`,vscodePath:t,vscodeSource:`file`,url:i})},addDraftVSCodeSelectionAttachment:async(e,t,n)=>{let r=a(e),i=Y(r),s=`${r}\u0000${Re(t,n.name)}`;if(!(o().getDraftAttachmentViews(e).some(e=>e.source===`vscode`&&e.vscodeSource===`selection`&&e.filename===n.name&&e.vscodePath===t)||(o().getDraft(e)?.attachments.some(e=>e.source===`vscode`&&e.vscodeSource===`selection`&&e.filename===n.name&&e.vscodePath===t)??!1)||M.has(s))){M.add(s);try{let a=await o().addDraftLocalAttachment(e,n,{source:`vscode`,vscodePath:t,vscodeSource:`selection`});i!==Y(r)&&a&&o().removeDraftAttachment(e,a.attachmentRefID)}finally{M.delete(s)}}},addVSCodeFileAttachment:(e,t,n)=>{let r=o().activeAttachmentDraft;if(r){o().addDraftVSCodeFileAttachment(r,e,t,n);return}let i=`${Date.now()}-${Math.random().toString(36).slice(2)}`,a=J(null);if((o().attachmentBuckets[a]??[]).some(t=>t.source===`vscode`&&t.vscodeSource===`file`&&(t.vscodePath||``)===e))return;let s=Le(e),c={id:i,file:new File([],t,{type:`text/plain`}),dataUrl:s,mimeType:`text/plain`,filename:t,size:n||0,source:`vscode`,vscodePath:e,vscodeSource:`file`};X(a,e=>[...e,c])},addVSCodeSelectionAttachment:async(e,t)=>{let n=o().activeAttachmentDraft;if(n){await o().addDraftVSCodeSelectionAttachment(n,e,t);return}let r=`${Date.now()}-${Math.random().toString(36).slice(2)}`,i=J(null),a=Y(i),s=`${i}\u0000${Re(e,t.name)}`;if((o().attachmentBuckets[i]??[]).some(n=>n.source===`vscode`&&n.vscodeSource===`selection`&&n.filename===t.name&&n.vscodePath===e)||M.has(s))return;M.add(s);let c;try{c=await ze(t)}catch{return}finally{M.delete(s)}if(a!==Y(i))return;let l={id:r,file:t,dataUrl:c,mimeType:t.type,filename:t.name,size:t.size,source:`vscode`,vscodePath:e,vscodeSource:`selection`};X(i,e=>[...e,l])},addCodeSelectionAttachment:async(e,t,n)=>{let r=new File([n],t,{type:`text/plain`});await o().addVSCodeSelectionAttachment(e,r)},setActiveEditorFile:e=>{Ve(o().activeEditorFile,e)||n({activeEditorFile:e})},addRestoredAttachment:({url:e,mimeType:t,filename:n})=>{let r=o().activeAttachmentDraft;if(r){if(e.startsWith(`data:`)){let i=a(r);(async()=>{try{let s=await(await fetch(e)).blob(),c=new File([s],n,{type:t||s.type||`application/octet-stream`}),l=o().activeAttachmentDraft;if(!l||a(l)!==i)return;await o().addDraftLocalAttachment(r,c)}catch{}})();return}if(!u(e))return;o().addDraftDurableAttachment(r,{filename:n,mimeType:t,size:Be(e),source:`local`,serverPath:e,url:e});return}let i={id:`restored-${Date.now()}-${Math.random().toString(36).slice(2)}`,file:new File([],n,{type:t}),dataUrl:e,mimeType:t,filename:n,size:Be(e),source:`local`,serverPath:e};X(J(null),e=>[...e,i])}}})},Ge=We();export{O as a,Y as i,Ge as n,de as r,We as t};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{R as t,l as n,u as r}from"./platform-CiUKDeXd.js";import{a as i,i as a,r as o}from"./vendor-zustand-CTekDqaS.js";import{ot as s,st as c}from"./vendor-base-ui-wXsskyKm.js";import{St as l,an as u,jt as d,on as f}from"./gitApiHttp-Bswf6gnl.js";import{t as p}from"./safeStorage-DTOhKN0V.js";import{i as m,t as h}from"./vendor-pathe-vBmvQE8f.js";import{n as g}from"./vendor-react-BkccXcWz.js";import{s as _,u as v}from"./vendor-tanstack-react-query-DIb_ItL-.js";import{E as y}from"./runtime-file-resource-C5kmYlLv.js";import{o as b}from"./path-utils-jGozTg9d.js";import{r as x}from"./vendor-reactuses-core-DjKFMfz7.js";import{r as S}from"./useUIStore-C3ewjGgP.js";import{o as C,s as w}from"./spacedFileMention-Ds4GtgiF.js";import{Ba as T,Fi as E,Oi as D,Pa as O,R as k,Yi as A,_ as j,b as M,bt as N,f as P,lo as ee,no as F,ua as I,ut as L,xa as R,za as te}from"./ui-CHdferA1.js";import{n as z}from"./Icon-B-w2YKpn.js";import{s as ne}from"./remoteProjectQueries-BXrXdLjN.js";import{t as re}from"./i18n-Dojvs57M.js";import{t as ie}from"./ScrollableOverlay-CkX-buJm.js";import{t as ae}from"./useDebouncedValue-BHlMPqY8.js";import{t as oe}from"./AgentAvatar-CNOu_vy0.js";import{c as se,d as ce,l as le,n as ue,r as de,t as fe}from"./fileMentionTouchSelection-B_62hIQI.js";import{a as pe,o as me,s as he}from"./fileMentionAutocompleteState-B9411b4o.js";var ge=(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)},_e=(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}),ve=(e,t)=>e.highlightedIndex===t.highlightedIndex&&_e(e.rows,t.rows),ye=(e,t)=>_e(e,t)?e:t.slice(),be=(e,t,n)=>{e&&(t.current&&ve(t.current,n)||(t.current=n,e(n)))},xe=(e,t)=>{t.current=null,e?.({rows:[],highlightedIndex:0})},B=e(c(),1),V=g(),Se=e=>e.directories.flatMap(e=>e.sessions),H=(e,t)=>({...ne(e,t.location.hostId),select:Se}),Ce=async(e,t,n)=>{n.sdk();let r=await e.fetchQuery(H(t,n));return n.sdk(),Se(r)},U=(e,t,n,r)=>{n.sdk();let i=e.getQueryData(H(t,n).queryKey);for(let e of i?.directories??[]){let t=e.sessions.find(e=>e.id===r);if(t)return t.title||r}return r},W=(e,t,n,r={})=>({queryKey:[...e.queryScope,`composer-files`,t,n,r],staleTime:3e4,gcTime:3e4,queryFn:async({signal:i})=>{let a=await e.sdk().file.find({query:t,location:{directory:e.location.directory},limit:n,type:r.type},{signal:i});if(e.sdk(),i.throwIfAborted(),!Array.isArray(a.data))throw Error(`File search returned no data`);return a.data.map(t=>{let n=m(t.path),r=h(n);return{name:r,path:b(e.location.directory,n),relativePath:n,extension:r.includes(`.`)?r.split(`.`).pop()?.toLowerCase():void 0,isDirectory:t.type===`directory`}})}}),G=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},K=e=>/^[A-Za-z]:\//.test(e)?e.toLowerCase():e,q=e=>e.startsWith(`yuri-remote-location:`)?n(e):G(e),J=(e,t)=>{let n=G(r(t,`local`).directory),i=G(e);if(!n||!i)return!1;let a=K(n),o=K(i);return o===a||o.startsWith(a.endsWith(`/`)?a:`${a}/`)},we=e=>{if(!e||typeof e!=`object`)return{};let t=e,n={};for(let[e,r]of Object.entries(t)){let t;try{t=q(e)}catch{continue}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=>G(e)).filter(e=>J(e,t)))):[],o=Array.isArray(i.expandedPaths)?Array.from(new Set(i.expandedPaths.filter(e=>typeof e==`string`).map(e=>G(e)).filter(e=>J(e,t)))):[],s=typeof i.selectedPath==`string`?G(i.selectedPath):null,c=s&&J(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])),i=u.selectedPath??c??e[0]??null;n[t]={openPaths:e,selectedPath:i,expandedPaths:r,touchedAt:Math.max(u.touchedAt,l)};continue}n[t]={openPaths:a,selectedPath:c,expandedPaths:o,touchedAt:l}}return n},Y=(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},X=e=>e?{...e,touchedAt:Date.now()}:{openPaths:[],selectedPath:null,expandedPaths:[],touchedAt:Date.now()},Z=i()(o(a((e,t)=>({byRoot:{},addOpenPath:(t,n,r)=>{let i=q((t||``).trim()),a=G((n||``).trim());!i||!a||!r?.allowOutsideRoot&&!J(a,i)||e(e=>{let t=e.byRoot[i],n=X(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:Y({...e.byRoot,[i]:{...n,openPaths:o,selectedPath:s}},20)}})},removeOpenPath:(t,n)=>{let r=q((t||``).trim()),i=G((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=K(i),a=e=>K(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:Y({...e.byRoot,[r]:{...t,openPaths:s,selectedPath:c,touchedAt:Date.now()}},20)}})},removeOpenPathsByPrefix:(t,n)=>{let r=q((t||``).trim()),i=G((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=K(i),a=n.endsWith(`/`)?n:`${n}/`,o=e=>{let t=K(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:Y({...e.byRoot,[r]:{...t,openPaths:s,selectedPath:c,touchedAt:Date.now()}},20)}})},removeExpandedPathsByPrefix:(t,n)=>{let r=q((t||``).trim()),i=G((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=K(i),a=n.endsWith(`/`)?n:`${n}/`,o=t.expandedPaths.filter(e=>{let t=K(e);return t!==n&&!t.startsWith(a)});return o.length===t.expandedPaths.length?e:{byRoot:Y({...e.byRoot,[r]:{...t,expandedPaths:o,touchedAt:Date.now()}},20)}})},setSelectedPath:(t,n,r)=>{let i=q((t||``).trim()),a=n?G(n.trim()):null;!i||a&&!r?.allowOutsideRoot&&!J(a,i)||e(e=>{let t=e.byRoot[i],n=X(t),r=a&&!n.openPaths.includes(a)?[...n.openPaths,a]:n.openPaths;return t&&t.selectedPath===a&&r===t.openPaths?e:{byRoot:Y({...e.byRoot,[i]:{...n,openPaths:r,selectedPath:a}},20)}})},ensureSelectedPath:e=>{let n=q((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=q((t||``).trim()),i=G((n||``).trim());!r||!i||!J(i,r)||e(e=>{let t=e.byRoot[r],n=X(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:Y({...e.byRoot,[r]:{...n,expandedPaths:a}},20)}})},expandPath:(t,n)=>{let r=q((t||``).trim()),i=G((n||``).trim());!r||!i||!J(i,r)||e(e=>{let t=e.byRoot[r],n=X(t);return n.expandedPaths.includes(i)&&t?e:{byRoot:Y({...e.byRoot,[r]:{...n,expandedPaths:[...n.expandedPaths,i]}},20)}})},expandPaths:(t,n)=>{let r=q((t||``).trim());if(!r||!n||n.length===0)return;let i=n.map(e=>G((e||``).trim())).filter(e=>e&&J(e,r));i.length!==0&&e(e=>{let t=e.byRoot[r],n=X(t),a=new Set(n.expandedPaths),o=i.filter(e=>!a.has(e));return o.length===0?e:{byRoot:Y({...e.byRoot,[r]:{...n,expandedPaths:[...n.expandedPaths,...o]}},20)}})}}),{name:`files-view-tabs-store`,version:2,storage:p(),migrate:e=>{if(!e||typeof e!=`object`)return{byRoot:{}};let t=e.byRoot;return{byRoot:we(t)}},merge:(e,t)=>({...t,byRoot:we(e&&typeof e==`object`?e.byRoot:void 0)}),partialize:e=>({byRoot:we(e.byRoot)})}),{name:`files-view-tabs-store`})),Q=()=>{let e=(0,V.c)(17),t=P(Te),n=N(),r;e[0]===t?r=e[1]:(r=e=>t?e.getAttachment(t):void 0,e[0]=t,e[1]=r);let i=M(r),a=P(Ee),o=P(De),s=T(Oe),c=T(ke),u=l(Ae);if(t){let r;e[2]===i?r=e[3]:(r=j(i),e[2]=i,e[3]=r);let o=r;if(o)return o;let s;e[4]!==t||e[5]!==a?(s=a.get(t),e[4]=t,e[5]=a,e[6]=s):s=e[6];let c=s;if(c?.path)return c.path;let l;if(e[7]!==t||e[8]!==n){let r;e[10]===t?r=e[11]:(r=e=>e.id===t,e[10]=t,e[11]=r),l=n.find(r),e[7]=t,e[8]=n,e[9]=l}else l=e[9];let u=l;if(u?.directory)return u.directory}if(o?.open&&(o.bootstrapPendingDirectory||o.directoryOverride))return(o.bootstrapPendingDirectory||o.directoryOverride)??void 0;if(s){let t;if(e[12]!==s||e[13]!==c){let n;e[15]===s?n=e[16]:(n=e=>e.id===s,e[15]=s,e[16]=n),t=c.find(n),e[12]=s,e[13]=c,e[14]=t}else t=e[14];let n=t;if(n?.path)return n.path}return u??void 0};function Te(e){return e.currentSessionId}function Ee(e){return e.worktreeMetadata}function De(e){return e.newSessionDraft}function Oe(e){return e.activeProjectId}function ke(e){return e.projects}function Ae(e){return e.currentDirectory}var $=s(),je=`bg-transparent font-[inherit] text-[var(--primary-base)]`,Me=(e,t)=>{let n=t.trim().toLowerCase();if(!n)return e;let r=e.toLowerCase();if(!r.includes(n))return e;let i=[],a=0,o=r.indexOf(n);for(;o!==-1;)o>a&&i.push(e.slice(a,o)),i.push((0,$.jsx)(`mark`,{className:je,children:e.slice(o,o+n.length)},`${o}-${n}`)),a=o+n.length,o=r.indexOf(n,a);return a<e.length&&i.push(e.slice(a)),i},Ne=B.forwardRef((e,t)=>{let n=(0,V.c)(4),r=y(),i;return n[0]!==r||n[1]!==e||n[2]!==t?(i=r?.entry.location.hostId?(0,$.jsx)(Le,{...e,ref:t,entry:r.entry,registry:r.registry},JSON.stringify(r.entry.queryScope)):(0,$.jsx)(Pe,{...e,ref:t}),n[0]=r,n[1]=e,n[2]=t,n[3]=i):i=n[3],i}),Pe=B.forwardRef((e,t)=>{let n=(0,V.c)(22),r=Q()??``,i=P(ze),a=E(Be),o=!!e.onSessionSelect,s;n[0]===o?s=n[1]:(s={enabled:o},n[0]=o,n[1]=s);let c=k(s),l=T(Ve),u=T(He),f;if(n[2]!==l||n[3]!==r||n[4]!==u){let e=u.find(e=>e.id===l)?.path||r;f=e?e.replace(/\\/g,`/`).replace(/\/+$/,``):null,n[2]=l,n[3]=r,n[4]=u,n[5]=f}else f=n[5];let p=f,m;n[6]===p?m=n[7]:(m=e=>p?e.byRoot[p]:void 0,n[6]=p,n[7]=m);let h=Z(m),g=A(Ue),_=d(We),v;n[8]!==a||n[9]!==c||n[10]!==e.onSessionSelect?(v=e.onSessionSelect?D(a,c):[],n[8]=a,n[9]=c,n[10]=e.onSessionSelect,n[11]=v):v=n[11];let y=v,b=e.currentSessionId??i,x;return n[12]!==g||n[13]!==r||n[14]!==p||n[15]!==h||n[16]!==e||n[17]!==t||n[18]!==_||n[19]!==y||n[20]!==b?(x=(0,$.jsx)(Re,{...e,ref:t,currentDirectory:r,currentSessionId:b,projectRoot:p,projectTabs:h,agentCatalog:g,sessions:y,searchFiles:_}),n[12]=g,n[13]=r,n[14]=p,n[15]=h,n[16]=e,n[17]=t,n[18]=_,n[19]=y,n[20]=b,n[21]=x):x=n[21],x}),Fe=[],Ie=[],Le=B.forwardRef((e,t)=>{let n=(0,V.c)(32),{entry:r,registry:i}=e,a=v(),o;n[0]===r?o=n[1]:(o=O(r.location.directory,void 0,r),n[0]=r,n[1]=o);let s=!!e.onAgentSelect,c;n[2]!==o||n[3]!==s?(c={...o,enabled:s},n[2]=o,n[3]=s,n[4]=c):c=n[4];let l=_(c),u;n[5]!==r||n[6]!==i?(u=H(i,r),n[5]=r,n[6]=i,n[7]=u):u=n[7];let d=!!e.onSessionSelect,f;n[8]!==u||n[9]!==d?(f={...u,enabled:d},n[8]=u,n[9]=d,n[10]=f):f=n[10];let p=_(f),m;n[11]===r.key?m=n[12]:(m=e=>e.byRoot[r.key],n[11]=r.key,n[12]=m);let h=Z(m),g;n[13]!==a||n[14]!==r?(g=(e,t,n,i)=>{let o=n===void 0?60:n;return a.fetchQuery(W(r,t,o,i))},n[13]=a,n[14]=r,n[15]=g):g=n[15];let y=x(g),b=r.location.directory,S;if(n[16]!==r.location.directory){let e;n[18]===Symbol.for(`react.memo_cache_sentinel`)?(e=/\/+$/,n[18]=e):e=n[18],S=r.location.directory.replace(/\\/g,`/`).replace(e,``),n[16]=r.location.directory,n[17]=S}else S=n[17];let C=l.data??Ie,w=p.data??Fe,T=l.error??p.error,E;n[19]===r?E=n[20]:(E=()=>{r.sdk()},n[19]=r,n[20]=E);let D;return n[21]!==r.location.directory||n[22]!==h||n[23]!==e||n[24]!==t||n[25]!==y||n[26]!==C||n[27]!==w||n[28]!==T||n[29]!==E||n[30]!==S?(D=(0,$.jsx)(Re,{...e,ref:t,currentDirectory:b,projectRoot:S,projectTabs:h,agentCatalog:C,sessions:w,searchFiles:y,catalogError:T,assertCurrent:E}),n[21]=r.location.directory,n[22]=h,n[23]=e,n[24]=t,n[25]=y,n[26]=C,n[27]=w,n[28]=T,n[29]=E,n[30]=S,n[31]=D):D=n[31],D}),Re=B.forwardRef(({searchQuery:e,onFileSelect:t,onAgentSelect:n,onSkillSelect:r,onSessionSelect:i,onClose:a,style:o,onRowsChange:s,currentDirectory:c,currentSessionId:l,projectRoot:d,projectTabs:p,agentCatalog:m,sessions:h,searchFiles:g,catalogError:_,assertCurrent:v},y)=>{let{t:b}=re(),w=ae(e,180),T=f(),E=u(),[D,O]=B.useState([]),[k,A]=B.useState(!1),[j,M]=B.useState(null),[N,P]=B.useState(0),L=B.useRef(0),te=B.useRef({query:e,directory:c,ids:[]}),[ne,ce]=B.useState(360),[le,ge]=B.useState({}),[_e,ve]=B.useState({}),ye=B.useRef([]),V=B.useRef([]),Se=B.useRef([]),H=B.useRef(null),Ce=B.useRef(null),U=B.useRef(null);U.current||=fe();let W=S(e=>e.isMobile),G=(e??``).trim(),K=R({directory:c||null}),q=B.useMemo(()=>r?K.data??[]:[],[r,K.data]),J=B.useMemo(()=>{if(!d||!p)return[];let e=[p.selectedPath,...p.openPaths.slice().reverse()].filter(e=>typeof e==`string`&&e.length>0),t=new Set,n=[];for(let r of e){if(t.has(r))continue;t.add(r);let e=r.replace(/\\/g,`/`),i=e.split(`/`).filter(Boolean).pop()||e,a=e.startsWith(`${d}/`)?e.slice(d.length+1):e;n.push({name:i,path:e,relativePath:a,extension:i.includes(`.`)?i.split(`.`).pop()?.toLowerCase():void 0})}return he(n,G,{limit:6})},[G,d,p]),we=B.useMemo(()=>n?I(m).filter(e=>e.mode!==`primary`):[],[m,n]),Y=B.useMemo(()=>i?pe({sessions:h,currentSessionId:l??null,searchQuery:G}):[],[h,l,G,i]),X=J,Z=D,Q=B.useMemo(()=>se({skills:q,agents:we,sessions:Y,recentFiles:X,pathHits:Z,searchQuery:G,untitledSession:b(`chat.fileMentionAutocomplete.untitledSession`),sessionBadge:b(`chat.fileMentionAutocomplete.sessionType`),skillBadge:b(`chat.commandAutocomplete.badge.skill`)}),[q,we,Y,X,Z,G,b]);B.useEffect(()=>{let e=e=>{let t=e.target;!t||!H.current||H.current.contains(t)||a()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},[a]),B.useEffect(()=>{if(!c){O([]),A(!1),M(null);return}let e=(w??``).trim(),t=C(e);if(!t){O([]),A(!1),M(null);return}let n=!1;A(!0),M(null);let r={includeHidden:T,respectGitignore:!E};return Promise.all([g(c,t,80,{...r,type:`file`}),g(c,t,40,{...r,type:`directory`})]).then(([t,r])=>{if(n)return;let i=new Set(J.map(e=>e.path));O(me({files:t,directories:r,query:e,excludePaths:i,limit:20}))}).catch(e=>{n||M(e instanceof Error?e:Error(String(e)))}).finally(()=>{n||A(!1)}),()=>{n=!0}},[c,w,J,g,T,E]),B.useLayoutEffect(()=>{let t=te.current,n=t.ids[L.current],r=t.query===e&&t.directory===c?Math.max(0,Q.findIndex(e=>e.id===n)):0;te.current={query:e,directory:c,ids:Q.map(e=>e.id)},L.current=r,P(r)},[Q,e,c]),B.useEffect(()=>{ge({}),ve({})},[Q]),B.useEffect(()=>{ye.current[N]?.scrollIntoView({block:`nearest`})},[N]),B.useEffect(()=>{let e=null,t=()=>{e!==null&&cancelAnimationFrame(e),e=requestAnimationFrame(()=>{let e={},t={};V.current.forEach((n,r)=>{if(!n)return;let i=Se.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}}),ge(e),ve(t)})};return t(),window.addEventListener(`resize`,t),()=>{e!==null&&cancelAnimationFrame(e),window.removeEventListener(`resize`,t)}},[Q]),B.useEffect(()=>{let e=V.current[N];if(!e)return;let t=()=>{let t=e.clientWidth;t>0&&ce(t)};if(t(),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(t);return n.observe(e),()=>{n.disconnect()}},[N]);let Te=x(e=>{t(e)}),Ee=x(e=>{n?.(e)}),De=x(e=>{i?.(e)}),Oe=x(e=>{r?.(e)}),ke=(e,t)=>({onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{e.pointerType===`touch`&&U.current?.pointerDown(e.clientX,e.clientY)},onPointerMove:e=>{e.pointerType===`touch`&&U.current?.pointerMove(e.clientX,e.clientY)},onPointerUp:e=>{e.pointerType===`touch`&&(U.current?.pointerUp(t)??!1)&&(e.preventDefault(),e.stopPropagation())},onPointerCancel:()=>U.current?.pointerCancel(),onClick:()=>{U.current?.click(t)},onMouseMove:()=>{L.current=e,P(e)}}),Ae=e=>{try{v?.()}catch(e){M(e instanceof Error?e:Error(String(e)));return}let t=Q.length;if(t===0)return;let n=(e%t+t)%t,r=Q[n];if(r.agentName!==void 0){Ee(r.agentName);return}if(r.id.startsWith(`skill:`)){let e=q.find(e=>r.id===`skill:${e.name}-${e.scope}`);e&&Oe(e);return}if(r.id.startsWith(`session:`)){let e=Y.find(e=>r.id===`session:${e.id}`);e&&De(e);return}let i=r.id.startsWith(`recent:`)?X.find(e=>r.id===`recent:${e.path}`):Z.find(e=>r.id===`file:${e.path}`);i&&Te(i)};B.useEffect(()=>{be(s,Ce,{rows:Q,highlightedIndex:N})},[s,N,Q]);let je=B.useRef(s);return je.current=s,B.useEffect(()=>()=>{xe(je.current,Ce)},[]),B.useImperativeHandle(y,()=>({acceptIndex:e=>{Ae(e)},handleKeyDown:e=>{if(e===`Escape`){a();return}let t=Q.length;if(t!==0){if(e===`ArrowDown`){L.current=(L.current+1)%t,P(L.current);return}if(e===`ArrowUp`){L.current=(L.current-1+t)%t,P(L.current);return}(e===`Enter`||e===`Tab`)&&Ae(L.current)}}})),(0,$.jsxs)(ue,{ref:H,isMobile:W,className:`max-w-[640px] max-h-64`,style:o,children:[(0,$.jsx)(ie,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0`,children:(0,$.jsxs)(`div`,{className:`py-1`,children:[_||K.error||j?(0,$.jsx)(`div`,{role:`alert`,className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:(_??K.error??j)?.message}):null,Q.map((e,t)=>{let n=e.id.startsWith(`file:`)||e.id.startsWith(`recent:`),r=n?ee(e.title,{maxLength:60}):e.title,i=N===t,a=le[t]??!1,o=_e[t]??2.6;return(0,$.jsxs)(`div`,{"data-mention-id":e.id,ref:e=>{ye.current[t]=e},className:F(`flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,W&&`min-h-11`,de(W,i),!W&&i&&`text-interactive-selection-foreground`),...ke(t,()=>Ae(t)),children:[(0,$.jsx)(`span`,{className:`flex size-5 shrink-0 items-center justify-center`,children:e.agentName===void 0?(0,$.jsx)(z,{name:e.iconName,className:`size-3.5 text-current`}):(0,$.jsx)(oe,{name:e.agentName,size:20})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-baseline gap-2`,children:[(0,$.jsxs)(`span`,{ref:e=>{V.current[t]=e},className:F(`relative block min-w-0 overflow-hidden`,n&&a&&i&&`file-mention-marquee-container`),style:i?{"--file-mention-marquee-width":`${ne}px`,"--file-mention-marquee-duration":`${o}s`}:void 0,title:e.title,children:[(0,$.jsx)(`span`,{ref:e=>{Se.current[t]=e},className:`absolute invisible whitespace-nowrap pointer-events-none`,"aria-hidden":!0,children:e.title}),n&&a&&i?(0,$.jsx)(`span`,{className:`inline-block whitespace-nowrap file-mention-marquee`,children:Me(e.title,G)}):(0,$.jsx)(`span`,{className:`block truncate`,children:Me(r,G)})]}),e.trailingLabel?(0,$.jsx)(`span`,{className:F(`max-w-[40%] shrink-0 truncate text-muted-foreground`,W?`typography-micro`:`typography-meta`),children:e.trailingLabel}):null]}),e.subtitle?(0,$.jsx)(`div`,{className:F(`truncate text-muted-foreground`,W?`typography-micro`:`typography-meta`),children:Me(e.subtitle,G)}):null]})]},e.id)}),k&&Z.length===0?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,$.jsx)(z,{name:`refresh`,className:`h-4 w-4 animate-spin text-muted-foreground`})}):null,!k&&Q.length===0&&(0,$.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:b(`chat.fileMentionAutocomplete.empty`)})]})}),!W&&(0,$.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:b(`chat.autocomplete.keyboardHint`)})]})});function ze(e){return e.currentSessionId}function Be(e){return e.activeSessions}function Ve(e){return e.activeProjectId}function He(e){return e.projects}function Ue(e){return e.agents}function We(e){return e.searchFiles}var Ge=new Set([`new`,`fork`,`compact`,`reload`,`undo`,`redo`,`model`,`btw`]),Ke=(e,t)=>{if(!t||e.isSkill)return!1;let n=e.name?.trim().toLowerCase();return!!(n&&Ge.has(n))},qe=(e,t)=>!e||t({name:e}),Je=` `,Ye=(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]===Je&&e[r-2]===`/`&&(r-=2),e[r]===`/`?{start:r,end:n}:null},Xe=`text-[10px] leading-none uppercase font-bold tracking-tight px-1.5 py-1 rounded border flex-shrink-0`,Ze=F(Xe,`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)]`),Qe=F(Xe,`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)]`),$e=F(Xe,`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)]`),et=F(Xe,`bg-[var(--surface-muted)] text-muted-foreground border-[var(--interactive-border)]/60`),tt=(e,t)=>e.length===t.length&&e.every((e,n)=>e.id===t[n]?.id&&e.description===t[n]?.description),nt=e=>{let t=!!e.sessionID;return{hasSession:t,canStartSessionCommand:t||e.hasNewDraft}},rt=B.forwardRef(({searchQuery:e,onCommandSelect:n,onClose:r,directory:i,style:a,commandPolicy:o,commandContext:s,onRowsChange:c},l)=>{let{t:u}=re(),d=S(e=>e.isMobile),f=P(e=>e.currentSessionId),p=P(e=>!!e.newSessionDraft?.open),m=P(B.useCallback(e=>f?e.getDirectoryForSession(f):void 0,[f])),h=L(f??``,m??void 0),g=B.useMemo(()=>s??{sessionID:f??null,hasMessages:h.length>0,hasNewDraft:p},[s,f,h.length,p]),{hasSession:_,canStartSessionCommand:v}=B.useMemo(()=>nt(g),[g]),y=g.hasMessages,[b,x]=B.useState([]),[C,w]=B.useState(!1),T=te({directory:i}),E=B.useMemo(()=>T.data??[],[T.data]),D=T.isFetching,[O,k]=B.useState(0),A=B.useRef(0),j=B.useRef(!1),M=B.useRef([]),N=B.useRef(null),ee=B.useRef(!1),I=B.useRef(null),R=B.useRef(!1),ne=B.useRef(null);B.useEffect(()=>{let e=e=>{let t=e.target;!t||!N.current||N.current.contains(t)||r()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},[r]),B.useEffect(()=>{(async()=>{w(D);try{let n=E.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}]),r=[{id:`yuri:new`,name:`new`,source:`yuri`,description:u(`chat.commandAutocomplete.command.newDescription`),isBuiltIn:!0},..._&&!y?[{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},...t()?[{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}]:[],...v?[{id:`yuri:craft-goal`,name:`craft-goal`,source:`yuri`,description:u(`chat.commandAutocomplete.command.craftGoalDescription`),isYuri:!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}]:[],...n],i=!y,a=ge(r.filter(e=>(i||e.name!==`init`)&&(o?.(e)??!0)),e);x(e=>tt(e,a)?e:a)}catch{let n=!y,r=ge([{id:`yuri:new`,name:`new`,source:`yuri`,description:u(`chat.commandAutocomplete.command.newDescription`),isBuiltIn:!0},..._&&!y?[{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},...t()?[{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}]:[],...v?[{id:`yuri:craft-goal`,name:`craft-goal`,source:`yuri`,description:u(`chat.commandAutocomplete.command.craftGoalDescription`),isYuri:!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=>(n||e.name!==`init`)&&(o?.(e)??!0)),e);x(e=>tt(e,r)?e:r)}finally{w(!1)}})()},[e,y,_,v,E,D,u,o]),B.useEffect(()=>{k(0)},[b]),B.useEffect(()=>{A.current=O},[O]),B.useEffect(()=>{M.current[O]?.scrollIntoView({block:`nearest`})},[O]),B.useEffect(()=>{be(c,ne,{rows:le(b,{skill:u(`chat.commandAutocomplete.badge.skill`),command:u(`chat.commandAutocomplete.badge.command`),system:u(`chat.commandAutocomplete.badge.system`)}),highlightedIndex:O})},[b,c,O,u]);let ae=B.useRef(c);ae.current=c,B.useEffect(()=>()=>{xe(ae.current,ne)},[]),B.useImperativeHandle(l,()=>({acceptIndex:(e,t=!0)=>{let r=b[e];r&&n(r,Ke(r,t))},handleKeyDown:e=>{let t=b.length;if(e===`Escape`){r();return}if(t!==0){if(e===`ArrowDown`){j.current=!0,k(e=>(e+1)%t);return}if(e===`ArrowUp`){j.current=!0,k(e=>(e-1+t)%t);return}if(e===`Enter`||e===`Tab`){let r=(A.current%t+t)%t,i=b[r];i&&n(i,Ke(i,e===`Enter`))}}}}),[b,r,n]);let oe=e=>{let t=ce(e);switch(e.name){case`new`:return(0,$.jsx)(z,{name:t,className:`h-3.5 w-3.5`});case`init`:return(0,$.jsx)(z,{name:t,className:`h-3.5 w-3.5 text-green-500`});case`undo`:return(0,$.jsx)(z,{name:t,className:`h-3.5 w-3.5 text-orange-500`});case`redo`:return(0,$.jsx)(z,{name:t,className:`h-3.5 w-3.5 text-orange-500`});case`timeline`:case`reload`:return(0,$.jsx)(z,{name:t,className:`h-3.5 w-3.5`});case`compact`:return(0,$.jsx)(z,{name:t,className:`h-3.5 w-3.5 text-purple-500`});case`goal`:return(0,$.jsx)(z,{name:t,className:`h-3.5 w-3.5`});case`review`:return(0,$.jsx)(z,{name:t,className:`h-3.5 w-3.5 text-blue-500`});case`test`:case`build`:case`run`:return(0,$.jsx)(z,{name:t,className:`h-3.5 w-3.5 text-cyan-500`});default:return e.isBuiltIn?(0,$.jsx)(z,{name:t,className:`h-3.5 w-3.5 text-yellow-500`}):(0,$.jsx)(z,{name:t,className:`h-3.5 w-3.5 text-muted-foreground`})}};return(0,$.jsxs)(ue,{ref:N,isMobile:d,className:`max-w-[450px] max-h-64`,style:a,children:[(0,$.jsx)(ie,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0 py-1.5`,children:C?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,$.jsx)(z,{name:`refresh`,className:`h-4 w-4 animate-spin text-muted-foreground`})}):(0,$.jsxs)(`div`,{children:[b.map((t,r)=>{let i=t.isBuiltIn,a=t.isYuri;return(0,$.jsxs)(`div`,{ref:e=>{M.current[r]=e},className:F(`flex gap-2 px-2 py-2 cursor-pointer rounded-lg`,d?`items-center`:`items-start`,de(d,r===O),!d&&r===O&&`bg-interactive-selection/35`),onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{e.pointerType===`touch`&&(I.current={x:e.clientX,y:e.clientY},R.current=!1)},onPointerMove:e=>{if(e.pointerType!==`touch`||!I.current)return;let t=e.clientX-I.current.x,n=e.clientY-I.current.y;Math.hypot(t,n)>6&&(R.current=!0)},onPointerUp:e=>{if(e.pointerType!==`touch`)return;let r=R.current;I.current=null,R.current=!1,!r&&(e.preventDefault(),e.stopPropagation(),ee.current=!0,n(t,Ke(t,d)))},onPointerCancel:()=>{I.current=null,R.current=!1},onClick:()=>{if(ee.current){ee.current=!1;return}n(t,Ke(t,d))},onMouseMove:()=>{j.current=!1,k(r)},children:[(0,$.jsx)(`div`,{className:F(!d&&`mt-0.5`),children:oe(t)}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(`span`,{className:`typography-ui-label font-medium`,children:[`/`,Me(t.name,e)]}),t.isSkill?(0,$.jsx)(`span`,{className:Ze,children:u(`chat.commandAutocomplete.badge.skill`)}):(0,$.jsx)(`span`,{className:Ze,children:u(`chat.commandAutocomplete.badge.command`)}),a?(0,$.jsx)(`span`,{className:et,children:`Yuri`}):i?(0,$.jsx)(`span`,{className:et,children:u(`chat.commandAutocomplete.badge.system`)}):t.scope?(0,$.jsx)(`span`,{className:t.scope===`project`?$e:Qe,children:t.scope}):null,t.agent&&(0,$.jsx)(`span`,{className:et,children:t.agent})]}),t.description&&!d&&(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground mt-0.5 truncate`,children:Me(t.description,e)})]})]},t.id)}),b.length===0&&(0,$.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:u(`chat.commandAutocomplete.empty`)})]})}),!d&&(0,$.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:u(`chat.autocomplete.keyboardHint`)})]})});rt.displayName=`CommandAutocomplete`;var it=(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?` `:``}`},at=(e,t,n)=>{let r=it(e,t,n);return`${t.length===0&&!/^\s/.test(r)?` `:``}${r}${n.length===0&&!/\s$/.test(r)?` `:``}`},ot=(e,t,n,r)=>{let i=e.slice(0,t),a=e.slice(n),o=at(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}},st=(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]},ct=(e,t)=>t<e.length&&e[t]===` `?t+1:t;export{rt as a,Ne as c,Ce as d,U as f,at as i,Q as l,st as n,Ye as o,ye as p,ot as r,qe as s,ct as t,Z as u};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{I as t,l as n,u as r}from"./platform-DbR5F6Vm.js";import{a as i,i as a,r as o}from"./vendor-zustand-CTekDqaS.js";import{ot as s,st as c}from"./vendor-base-ui-wXsskyKm.js";import{St as l,an as u,jt as d,on as f}from"./gitApiHttp-BCUn15ro.js";import{t as p}from"./safeStorage-DTOhKN0V.js";import{i as m,t as h}from"./vendor-pathe-vBmvQE8f.js";import{n as g}from"./vendor-react-BkccXcWz.js";import{s as _,u as v}from"./vendor-tanstack-react-query-DIb_ItL-.js";import{E as y}from"./runtime-file-resource-B0yDjkk2.js";import{o as b}from"./path-utils-jGozTg9d.js";import{r as x}from"./vendor-reactuses-core-DjKFMfz7.js";import{r as S}from"./useUIStore-BPe3dRMB.js";import{o as C,s as w}from"./spacedFileMention-Ds4GtgiF.js";import{Ba as T,Fi as E,Oi as D,Pa as O,R as k,Yi as A,_ as j,b as M,bt as N,f as P,lo as ee,no as F,ua as I,ut as L,xa as R,za as te}from"./ui-CWbFzUJf.js";import{n as z}from"./Icon-DqzPCJr3.js";import{s as ne}from"./remoteProjectQueries-A4mba1L1.js";import{t as re}from"./i18n-5cDQDVOf.js";import{t as ie}from"./ScrollableOverlay-DSbSVZg9.js";import{t as ae}from"./useDebouncedValue-BHlMPqY8.js";import{t as oe}from"./AgentAvatar-Bum-xW6O.js";import{c as se,d as ce,l as le,n as ue,r as de,t as fe}from"./fileMentionTouchSelection-CWLbylio.js";import{a as pe,o as me,s as he}from"./fileMentionAutocompleteState-B9411b4o.js";var ge=(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)},_e=(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}),ve=(e,t)=>e.highlightedIndex===t.highlightedIndex&&_e(e.rows,t.rows),ye=(e,t)=>_e(e,t)?e:t.slice(),be=(e,t,n)=>{e&&(t.current&&ve(t.current,n)||(t.current=n,e(n)))},xe=(e,t)=>{t.current=null,e?.({rows:[],highlightedIndex:0})},B=e(c(),1),V=g(),Se=e=>e.directories.flatMap(e=>e.sessions),H=(e,t)=>({...ne(e,t.location.hostId),select:Se}),Ce=async(e,t,n)=>{n.sdk();let r=await e.fetchQuery(H(t,n));return n.sdk(),Se(r)},U=(e,t,n,r)=>{n.sdk();let i=e.getQueryData(H(t,n).queryKey);for(let e of i?.directories??[]){let t=e.sessions.find(e=>e.id===r);if(t)return t.title||r}return r},W=(e,t,n,r={})=>({queryKey:[...e.queryScope,`composer-files`,t,n,r],staleTime:3e4,gcTime:3e4,queryFn:async({signal:i})=>{let a=await e.sdk().file.find({query:t,location:{directory:e.location.directory},limit:n,type:r.type},{signal:i});if(e.sdk(),i.throwIfAborted(),!Array.isArray(a.data))throw Error(`File search returned no data`);return a.data.map(t=>{let n=m(t.path),r=h(n);return{name:r,path:b(e.location.directory,n),relativePath:n,extension:r.includes(`.`)?r.split(`.`).pop()?.toLowerCase():void 0,isDirectory:t.type===`directory`}})}}),G=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},K=e=>/^[A-Za-z]:\//.test(e)?e.toLowerCase():e,q=e=>e.startsWith(`yuri-remote-location:`)?n(e):G(e),J=(e,t)=>{let n=G(r(t,`local`).directory),i=G(e);if(!n||!i)return!1;let a=K(n),o=K(i);return o===a||o.startsWith(a.endsWith(`/`)?a:`${a}/`)},we=e=>{if(!e||typeof e!=`object`)return{};let t=e,n={};for(let[e,r]of Object.entries(t)){let t;try{t=q(e)}catch{continue}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=>G(e)).filter(e=>J(e,t)))):[],o=Array.isArray(i.expandedPaths)?Array.from(new Set(i.expandedPaths.filter(e=>typeof e==`string`).map(e=>G(e)).filter(e=>J(e,t)))):[],s=typeof i.selectedPath==`string`?G(i.selectedPath):null,c=s&&J(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])),i=u.selectedPath??c??e[0]??null;n[t]={openPaths:e,selectedPath:i,expandedPaths:r,touchedAt:Math.max(u.touchedAt,l)};continue}n[t]={openPaths:a,selectedPath:c,expandedPaths:o,touchedAt:l}}return n},Y=(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},X=e=>e?{...e,touchedAt:Date.now()}:{openPaths:[],selectedPath:null,expandedPaths:[],touchedAt:Date.now()},Z=i()(o(a((e,t)=>({byRoot:{},addOpenPath:(t,n,r)=>{let i=q((t||``).trim()),a=G((n||``).trim());!i||!a||!r?.allowOutsideRoot&&!J(a,i)||e(e=>{let t=e.byRoot[i],n=X(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:Y({...e.byRoot,[i]:{...n,openPaths:o,selectedPath:s}},20)}})},removeOpenPath:(t,n)=>{let r=q((t||``).trim()),i=G((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=K(i),a=e=>K(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:Y({...e.byRoot,[r]:{...t,openPaths:s,selectedPath:c,touchedAt:Date.now()}},20)}})},removeOpenPathsByPrefix:(t,n)=>{let r=q((t||``).trim()),i=G((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=K(i),a=n.endsWith(`/`)?n:`${n}/`,o=e=>{let t=K(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:Y({...e.byRoot,[r]:{...t,openPaths:s,selectedPath:c,touchedAt:Date.now()}},20)}})},removeExpandedPathsByPrefix:(t,n)=>{let r=q((t||``).trim()),i=G((n||``).trim());!r||!i||e(e=>{let t=e.byRoot[r];if(!t)return e;let n=K(i),a=n.endsWith(`/`)?n:`${n}/`,o=t.expandedPaths.filter(e=>{let t=K(e);return t!==n&&!t.startsWith(a)});return o.length===t.expandedPaths.length?e:{byRoot:Y({...e.byRoot,[r]:{...t,expandedPaths:o,touchedAt:Date.now()}},20)}})},setSelectedPath:(t,n,r)=>{let i=q((t||``).trim()),a=n?G(n.trim()):null;!i||a&&!r?.allowOutsideRoot&&!J(a,i)||e(e=>{let t=e.byRoot[i],n=X(t),r=a&&!n.openPaths.includes(a)?[...n.openPaths,a]:n.openPaths;return t&&t.selectedPath===a&&r===t.openPaths?e:{byRoot:Y({...e.byRoot,[i]:{...n,openPaths:r,selectedPath:a}},20)}})},ensureSelectedPath:e=>{let n=q((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=q((t||``).trim()),i=G((n||``).trim());!r||!i||!J(i,r)||e(e=>{let t=e.byRoot[r],n=X(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:Y({...e.byRoot,[r]:{...n,expandedPaths:a}},20)}})},expandPath:(t,n)=>{let r=q((t||``).trim()),i=G((n||``).trim());!r||!i||!J(i,r)||e(e=>{let t=e.byRoot[r],n=X(t);return n.expandedPaths.includes(i)&&t?e:{byRoot:Y({...e.byRoot,[r]:{...n,expandedPaths:[...n.expandedPaths,i]}},20)}})},expandPaths:(t,n)=>{let r=q((t||``).trim());if(!r||!n||n.length===0)return;let i=n.map(e=>G((e||``).trim())).filter(e=>e&&J(e,r));i.length!==0&&e(e=>{let t=e.byRoot[r],n=X(t),a=new Set(n.expandedPaths),o=i.filter(e=>!a.has(e));return o.length===0?e:{byRoot:Y({...e.byRoot,[r]:{...n,expandedPaths:[...n.expandedPaths,...o]}},20)}})}}),{name:`files-view-tabs-store`,version:2,storage:p(),migrate:e=>{if(!e||typeof e!=`object`)return{byRoot:{}};let t=e.byRoot;return{byRoot:we(t)}},merge:(e,t)=>({...t,byRoot:we(e&&typeof e==`object`?e.byRoot:void 0)}),partialize:e=>({byRoot:we(e.byRoot)})}),{name:`files-view-tabs-store`})),Q=()=>{let e=(0,V.c)(17),t=P(Te),n=N(),r;e[0]===t?r=e[1]:(r=e=>t?e.getAttachment(t):void 0,e[0]=t,e[1]=r);let i=M(r),a=P(Ee),o=P(De),s=T(Oe),c=T(ke),u=l(Ae);if(t){let r;e[2]===i?r=e[3]:(r=j(i),e[2]=i,e[3]=r);let o=r;if(o)return o;let s;e[4]!==t||e[5]!==a?(s=a.get(t),e[4]=t,e[5]=a,e[6]=s):s=e[6];let c=s;if(c?.path)return c.path;let l;if(e[7]!==t||e[8]!==n){let r;e[10]===t?r=e[11]:(r=e=>e.id===t,e[10]=t,e[11]=r),l=n.find(r),e[7]=t,e[8]=n,e[9]=l}else l=e[9];let u=l;if(u?.directory)return u.directory}if(o?.open&&(o.bootstrapPendingDirectory||o.directoryOverride))return(o.bootstrapPendingDirectory||o.directoryOverride)??void 0;if(s){let t;if(e[12]!==s||e[13]!==c){let n;e[15]===s?n=e[16]:(n=e=>e.id===s,e[15]=s,e[16]=n),t=c.find(n),e[12]=s,e[13]=c,e[14]=t}else t=e[14];let n=t;if(n?.path)return n.path}return u??void 0};function Te(e){return e.currentSessionId}function Ee(e){return e.worktreeMetadata}function De(e){return e.newSessionDraft}function Oe(e){return e.activeProjectId}function ke(e){return e.projects}function Ae(e){return e.currentDirectory}var $=s(),je=`bg-transparent font-[inherit] text-[var(--primary-base)]`,Me=(e,t)=>{let n=t.trim().toLowerCase();if(!n)return e;let r=e.toLowerCase();if(!r.includes(n))return e;let i=[],a=0,o=r.indexOf(n);for(;o!==-1;)o>a&&i.push(e.slice(a,o)),i.push((0,$.jsx)(`mark`,{className:je,children:e.slice(o,o+n.length)},`${o}-${n}`)),a=o+n.length,o=r.indexOf(n,a);return a<e.length&&i.push(e.slice(a)),i},Ne=B.forwardRef((e,t)=>{let n=(0,V.c)(4),r=y(),i;return n[0]!==r||n[1]!==e||n[2]!==t?(i=r?.entry.location.hostId?(0,$.jsx)(Le,{...e,ref:t,entry:r.entry,registry:r.registry},JSON.stringify(r.entry.queryScope)):(0,$.jsx)(Pe,{...e,ref:t}),n[0]=r,n[1]=e,n[2]=t,n[3]=i):i=n[3],i}),Pe=B.forwardRef((e,t)=>{let n=(0,V.c)(22),r=Q()??``,i=P(ze),a=E(Be),o=!!e.onSessionSelect,s;n[0]===o?s=n[1]:(s={enabled:o},n[0]=o,n[1]=s);let c=k(s),l=T(Ve),u=T(He),f;if(n[2]!==l||n[3]!==r||n[4]!==u){let e=u.find(e=>e.id===l)?.path||r;f=e?e.replace(/\\/g,`/`).replace(/\/+$/,``):null,n[2]=l,n[3]=r,n[4]=u,n[5]=f}else f=n[5];let p=f,m;n[6]===p?m=n[7]:(m=e=>p?e.byRoot[p]:void 0,n[6]=p,n[7]=m);let h=Z(m),g=A(Ue),_=d(We),v;n[8]!==a||n[9]!==c||n[10]!==e.onSessionSelect?(v=e.onSessionSelect?D(a,c):[],n[8]=a,n[9]=c,n[10]=e.onSessionSelect,n[11]=v):v=n[11];let y=v,b=e.currentSessionId??i,x;return n[12]!==g||n[13]!==r||n[14]!==p||n[15]!==h||n[16]!==e||n[17]!==t||n[18]!==_||n[19]!==y||n[20]!==b?(x=(0,$.jsx)(Re,{...e,ref:t,currentDirectory:r,currentSessionId:b,projectRoot:p,projectTabs:h,agentCatalog:g,sessions:y,searchFiles:_}),n[12]=g,n[13]=r,n[14]=p,n[15]=h,n[16]=e,n[17]=t,n[18]=_,n[19]=y,n[20]=b,n[21]=x):x=n[21],x}),Fe=[],Ie=[],Le=B.forwardRef((e,t)=>{let n=(0,V.c)(32),{entry:r,registry:i}=e,a=v(),o;n[0]===r?o=n[1]:(o=O(r.location.directory,void 0,r),n[0]=r,n[1]=o);let s=!!e.onAgentSelect,c;n[2]!==o||n[3]!==s?(c={...o,enabled:s},n[2]=o,n[3]=s,n[4]=c):c=n[4];let l=_(c),u;n[5]!==r||n[6]!==i?(u=H(i,r),n[5]=r,n[6]=i,n[7]=u):u=n[7];let d=!!e.onSessionSelect,f;n[8]!==u||n[9]!==d?(f={...u,enabled:d},n[8]=u,n[9]=d,n[10]=f):f=n[10];let p=_(f),m;n[11]===r.key?m=n[12]:(m=e=>e.byRoot[r.key],n[11]=r.key,n[12]=m);let h=Z(m),g;n[13]!==a||n[14]!==r?(g=(e,t,n,i)=>{let o=n===void 0?60:n;return a.fetchQuery(W(r,t,o,i))},n[13]=a,n[14]=r,n[15]=g):g=n[15];let y=x(g),b=r.location.directory,S;if(n[16]!==r.location.directory){let e;n[18]===Symbol.for(`react.memo_cache_sentinel`)?(e=/\/+$/,n[18]=e):e=n[18],S=r.location.directory.replace(/\\/g,`/`).replace(e,``),n[16]=r.location.directory,n[17]=S}else S=n[17];let C=l.data??Ie,w=p.data??Fe,T=l.error??p.error,E;n[19]===r?E=n[20]:(E=()=>{r.sdk()},n[19]=r,n[20]=E);let D;return n[21]!==r.location.directory||n[22]!==h||n[23]!==e||n[24]!==t||n[25]!==y||n[26]!==C||n[27]!==w||n[28]!==T||n[29]!==E||n[30]!==S?(D=(0,$.jsx)(Re,{...e,ref:t,currentDirectory:b,projectRoot:S,projectTabs:h,agentCatalog:C,sessions:w,searchFiles:y,catalogError:T,assertCurrent:E}),n[21]=r.location.directory,n[22]=h,n[23]=e,n[24]=t,n[25]=y,n[26]=C,n[27]=w,n[28]=T,n[29]=E,n[30]=S,n[31]=D):D=n[31],D}),Re=B.forwardRef(({searchQuery:e,onFileSelect:t,onAgentSelect:n,onSkillSelect:r,onSessionSelect:i,onClose:a,style:o,onRowsChange:s,currentDirectory:c,currentSessionId:l,projectRoot:d,projectTabs:p,agentCatalog:m,sessions:h,searchFiles:g,catalogError:_,assertCurrent:v},y)=>{let{t:b}=re(),w=ae(e,180),T=f(),E=u(),[D,O]=B.useState([]),[k,A]=B.useState(!1),[j,M]=B.useState(null),[N,P]=B.useState(0),L=B.useRef(0),te=B.useRef({query:e,directory:c,ids:[]}),[ne,ce]=B.useState(360),[le,ge]=B.useState({}),[_e,ve]=B.useState({}),ye=B.useRef([]),V=B.useRef([]),Se=B.useRef([]),H=B.useRef(null),Ce=B.useRef(null),U=B.useRef(null);U.current||=fe();let W=S(e=>e.isMobile),G=(e??``).trim(),K=R({directory:c||null}),q=B.useMemo(()=>r?K.data??[]:[],[r,K.data]),J=B.useMemo(()=>{if(!d||!p)return[];let e=[p.selectedPath,...p.openPaths.slice().reverse()].filter(e=>typeof e==`string`&&e.length>0),t=new Set,n=[];for(let r of e){if(t.has(r))continue;t.add(r);let e=r.replace(/\\/g,`/`),i=e.split(`/`).filter(Boolean).pop()||e,a=e.startsWith(`${d}/`)?e.slice(d.length+1):e;n.push({name:i,path:e,relativePath:a,extension:i.includes(`.`)?i.split(`.`).pop()?.toLowerCase():void 0})}return he(n,G,{limit:6})},[G,d,p]),we=B.useMemo(()=>n?I(m).filter(e=>e.mode!==`primary`):[],[m,n]),Y=B.useMemo(()=>i?pe({sessions:h,currentSessionId:l??null,searchQuery:G}):[],[h,l,G,i]),X=J,Z=D,Q=B.useMemo(()=>se({skills:q,agents:we,sessions:Y,recentFiles:X,pathHits:Z,searchQuery:G,untitledSession:b(`chat.fileMentionAutocomplete.untitledSession`),sessionBadge:b(`chat.fileMentionAutocomplete.sessionType`),skillBadge:b(`chat.commandAutocomplete.badge.skill`)}),[q,we,Y,X,Z,G,b]);B.useEffect(()=>{let e=e=>{let t=e.target;!t||!H.current||H.current.contains(t)||a()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},[a]),B.useEffect(()=>{if(!c){O([]),A(!1),M(null);return}let e=(w??``).trim(),t=C(e);if(!t){O([]),A(!1),M(null);return}let n=!1;A(!0),M(null);let r={includeHidden:T,respectGitignore:!E};return Promise.all([g(c,t,80,{...r,type:`file`}),g(c,t,40,{...r,type:`directory`})]).then(([t,r])=>{if(n)return;let i=new Set(J.map(e=>e.path));O(me({files:t,directories:r,query:e,excludePaths:i,limit:20}))}).catch(e=>{n||M(e instanceof Error?e:Error(String(e)))}).finally(()=>{n||A(!1)}),()=>{n=!0}},[c,w,J,g,T,E]),B.useLayoutEffect(()=>{let t=te.current,n=t.ids[L.current],r=t.query===e&&t.directory===c?Math.max(0,Q.findIndex(e=>e.id===n)):0;te.current={query:e,directory:c,ids:Q.map(e=>e.id)},L.current=r,P(r)},[Q,e,c]),B.useEffect(()=>{ge({}),ve({})},[Q]),B.useEffect(()=>{ye.current[N]?.scrollIntoView({block:`nearest`})},[N]),B.useEffect(()=>{let e=null,t=()=>{e!==null&&cancelAnimationFrame(e),e=requestAnimationFrame(()=>{let e={},t={};V.current.forEach((n,r)=>{if(!n)return;let i=Se.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}}),ge(e),ve(t)})};return t(),window.addEventListener(`resize`,t),()=>{e!==null&&cancelAnimationFrame(e),window.removeEventListener(`resize`,t)}},[Q]),B.useEffect(()=>{let e=V.current[N];if(!e)return;let t=()=>{let t=e.clientWidth;t>0&&ce(t)};if(t(),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(t);return n.observe(e),()=>{n.disconnect()}},[N]);let Te=x(e=>{t(e)}),Ee=x(e=>{n?.(e)}),De=x(e=>{i?.(e)}),Oe=x(e=>{r?.(e)}),ke=(e,t)=>({onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{e.pointerType===`touch`&&U.current?.pointerDown(e.clientX,e.clientY)},onPointerMove:e=>{e.pointerType===`touch`&&U.current?.pointerMove(e.clientX,e.clientY)},onPointerUp:e=>{e.pointerType===`touch`&&(U.current?.pointerUp(t)??!1)&&(e.preventDefault(),e.stopPropagation())},onPointerCancel:()=>U.current?.pointerCancel(),onClick:()=>{U.current?.click(t)},onMouseMove:()=>{L.current=e,P(e)}}),Ae=e=>{try{v?.()}catch(e){M(e instanceof Error?e:Error(String(e)));return}let t=Q.length;if(t===0)return;let n=(e%t+t)%t,r=Q[n];if(r.agentName!==void 0){Ee(r.agentName);return}if(r.id.startsWith(`skill:`)){let e=q.find(e=>r.id===`skill:${e.name}-${e.scope}`);e&&Oe(e);return}if(r.id.startsWith(`session:`)){let e=Y.find(e=>r.id===`session:${e.id}`);e&&De(e);return}let i=r.id.startsWith(`recent:`)?X.find(e=>r.id===`recent:${e.path}`):Z.find(e=>r.id===`file:${e.path}`);i&&Te(i)};B.useEffect(()=>{be(s,Ce,{rows:Q,highlightedIndex:N})},[s,N,Q]);let je=B.useRef(s);return je.current=s,B.useEffect(()=>()=>{xe(je.current,Ce)},[]),B.useImperativeHandle(y,()=>({acceptIndex:e=>{Ae(e)},handleKeyDown:e=>{if(e===`Escape`){a();return}let t=Q.length;if(t!==0){if(e===`ArrowDown`){L.current=(L.current+1)%t,P(L.current);return}if(e===`ArrowUp`){L.current=(L.current-1+t)%t,P(L.current);return}(e===`Enter`||e===`Tab`)&&Ae(L.current)}}})),(0,$.jsxs)(ue,{ref:H,isMobile:W,className:`max-w-[640px] max-h-64`,style:o,children:[(0,$.jsx)(ie,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0`,children:(0,$.jsxs)(`div`,{className:`py-1`,children:[_||K.error||j?(0,$.jsx)(`div`,{role:`alert`,className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:(_??K.error??j)?.message}):null,Q.map((e,t)=>{let n=e.id.startsWith(`file:`)||e.id.startsWith(`recent:`),r=n?ee(e.title,{maxLength:60}):e.title,i=N===t,a=le[t]??!1,o=_e[t]??2.6;return(0,$.jsxs)(`div`,{"data-mention-id":e.id,ref:e=>{ye.current[t]=e},className:F(`flex items-center gap-2 px-3 py-1.5 cursor-pointer typography-ui-label rounded-lg`,W&&`min-h-11`,de(W,i),!W&&i&&`text-interactive-selection-foreground`),...ke(t,()=>Ae(t)),children:[(0,$.jsx)(`span`,{className:`flex size-5 shrink-0 items-center justify-center`,children:e.agentName===void 0?(0,$.jsx)(z,{name:e.iconName,className:`size-3.5 text-current`}):(0,$.jsx)(oe,{name:e.agentName,size:20})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-baseline gap-2`,children:[(0,$.jsxs)(`span`,{ref:e=>{V.current[t]=e},className:F(`relative block min-w-0 overflow-hidden`,n&&a&&i&&`file-mention-marquee-container`),style:i?{"--file-mention-marquee-width":`${ne}px`,"--file-mention-marquee-duration":`${o}s`}:void 0,title:e.title,children:[(0,$.jsx)(`span`,{ref:e=>{Se.current[t]=e},className:`absolute invisible whitespace-nowrap pointer-events-none`,"aria-hidden":!0,children:e.title}),n&&a&&i?(0,$.jsx)(`span`,{className:`inline-block whitespace-nowrap file-mention-marquee`,children:Me(e.title,G)}):(0,$.jsx)(`span`,{className:`block truncate`,children:Me(r,G)})]}),e.trailingLabel?(0,$.jsx)(`span`,{className:F(`max-w-[40%] shrink-0 truncate text-muted-foreground`,W?`typography-micro`:`typography-meta`),children:e.trailingLabel}):null]}),e.subtitle?(0,$.jsx)(`div`,{className:F(`truncate text-muted-foreground`,W?`typography-micro`:`typography-meta`),children:Me(e.subtitle,G)}):null]})]},e.id)}),k&&Z.length===0?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,$.jsx)(z,{name:`refresh`,className:`h-4 w-4 animate-spin text-muted-foreground`})}):null,!k&&Q.length===0&&(0,$.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:b(`chat.fileMentionAutocomplete.empty`)})]})}),!W&&(0,$.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:b(`chat.autocomplete.keyboardHint`)})]})});function ze(e){return e.currentSessionId}function Be(e){return e.activeSessions}function Ve(e){return e.activeProjectId}function He(e){return e.projects}function Ue(e){return e.agents}function We(e){return e.searchFiles}var Ge=new Set([`new`,`fork`,`compact`,`reload`,`undo`,`redo`,`model`,`btw`]),Ke=(e,t)=>{if(!t||e.isSkill)return!1;let n=e.name?.trim().toLowerCase();return!!(n&&Ge.has(n))},qe=(e,t)=>!e||t({name:e}),Je=` `,Ye=(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]===Je&&e[r-2]===`/`&&(r-=2),e[r]===`/`?{start:r,end:n}:null},Xe=`text-[10px] leading-none uppercase font-bold tracking-tight px-1.5 py-1 rounded border flex-shrink-0`,Ze=F(Xe,`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)]`),Qe=F(Xe,`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)]`),$e=F(Xe,`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)]`),et=F(Xe,`bg-[var(--surface-muted)] text-muted-foreground border-[var(--interactive-border)]/60`),tt=(e,t)=>e.length===t.length&&e.every((e,n)=>e.id===t[n]?.id&&e.description===t[n]?.description),nt=e=>{let t=!!e.sessionID;return{hasSession:t,canStartSessionCommand:t||e.hasNewDraft}},rt=B.forwardRef(({searchQuery:e,onCommandSelect:n,onClose:r,directory:i,style:a,commandPolicy:o,commandContext:s,onRowsChange:c},l)=>{let{t:u}=re(),d=S(e=>e.isMobile),f=P(e=>e.currentSessionId),p=P(e=>!!e.newSessionDraft?.open),m=P(B.useCallback(e=>f?e.getDirectoryForSession(f):void 0,[f])),h=L(f??``,m??void 0),g=B.useMemo(()=>s??{sessionID:f??null,hasMessages:h.length>0,hasNewDraft:p},[s,f,h.length,p]),{hasSession:_,canStartSessionCommand:v}=B.useMemo(()=>nt(g),[g]),y=g.hasMessages,[b,x]=B.useState([]),[C,w]=B.useState(!1),T=te({directory:i}),E=B.useMemo(()=>T.data??[],[T.data]),D=T.isFetching,[O,k]=B.useState(0),A=B.useRef(0),j=B.useRef(!1),M=B.useRef([]),N=B.useRef(null),ee=B.useRef(!1),I=B.useRef(null),R=B.useRef(!1),ne=B.useRef(null);B.useEffect(()=>{let e=e=>{let t=e.target;!t||!N.current||N.current.contains(t)||r()};return document.addEventListener(`pointerdown`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0)}},[r]),B.useEffect(()=>{(async()=>{w(D);try{let n=E.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}]),r=[{id:`yuri:new`,name:`new`,source:`yuri`,description:u(`chat.commandAutocomplete.command.newDescription`),isBuiltIn:!0},..._&&!y?[{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},...t()?[{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}]:[],...v?[{id:`yuri:craft-goal`,name:`craft-goal`,source:`yuri`,description:u(`chat.commandAutocomplete.command.craftGoalDescription`),isYuri:!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}]:[],...n],i=!y,a=ge(r.filter(e=>(i||e.name!==`init`)&&(o?.(e)??!0)),e);x(e=>tt(e,a)?e:a)}catch{let n=!y,r=ge([{id:`yuri:new`,name:`new`,source:`yuri`,description:u(`chat.commandAutocomplete.command.newDescription`),isBuiltIn:!0},..._&&!y?[{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},...t()?[{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}]:[],...v?[{id:`yuri:craft-goal`,name:`craft-goal`,source:`yuri`,description:u(`chat.commandAutocomplete.command.craftGoalDescription`),isYuri:!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=>(n||e.name!==`init`)&&(o?.(e)??!0)),e);x(e=>tt(e,r)?e:r)}finally{w(!1)}})()},[e,y,_,v,E,D,u,o]),B.useEffect(()=>{k(0)},[b]),B.useEffect(()=>{A.current=O},[O]),B.useEffect(()=>{M.current[O]?.scrollIntoView({block:`nearest`})},[O]),B.useEffect(()=>{be(c,ne,{rows:le(b,{skill:u(`chat.commandAutocomplete.badge.skill`),command:u(`chat.commandAutocomplete.badge.command`),system:u(`chat.commandAutocomplete.badge.system`)}),highlightedIndex:O})},[b,c,O,u]);let ae=B.useRef(c);ae.current=c,B.useEffect(()=>()=>{xe(ae.current,ne)},[]),B.useImperativeHandle(l,()=>({acceptIndex:(e,t=!0)=>{let r=b[e];r&&n(r,Ke(r,t))},handleKeyDown:e=>{let t=b.length;if(e===`Escape`){r();return}if(t!==0){if(e===`ArrowDown`){j.current=!0,k(e=>(e+1)%t);return}if(e===`ArrowUp`){j.current=!0,k(e=>(e-1+t)%t);return}if(e===`Enter`||e===`Tab`){let r=(A.current%t+t)%t,i=b[r];i&&n(i,Ke(i,e===`Enter`))}}}}),[b,r,n]);let oe=e=>{let t=ce(e);switch(e.name){case`new`:return(0,$.jsx)(z,{name:t,className:`h-3.5 w-3.5`});case`init`:return(0,$.jsx)(z,{name:t,className:`h-3.5 w-3.5 text-green-500`});case`undo`:return(0,$.jsx)(z,{name:t,className:`h-3.5 w-3.5 text-orange-500`});case`redo`:return(0,$.jsx)(z,{name:t,className:`h-3.5 w-3.5 text-orange-500`});case`timeline`:case`reload`:return(0,$.jsx)(z,{name:t,className:`h-3.5 w-3.5`});case`compact`:return(0,$.jsx)(z,{name:t,className:`h-3.5 w-3.5 text-purple-500`});case`goal`:return(0,$.jsx)(z,{name:t,className:`h-3.5 w-3.5`});case`review`:return(0,$.jsx)(z,{name:t,className:`h-3.5 w-3.5 text-blue-500`});case`test`:case`build`:case`run`:return(0,$.jsx)(z,{name:t,className:`h-3.5 w-3.5 text-cyan-500`});default:return e.isBuiltIn?(0,$.jsx)(z,{name:t,className:`h-3.5 w-3.5 text-yellow-500`}):(0,$.jsx)(z,{name:t,className:`h-3.5 w-3.5 text-muted-foreground`})}};return(0,$.jsxs)(ue,{ref:N,isMobile:d,className:`max-w-[450px] max-h-64`,style:a,children:[(0,$.jsx)(ie,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0 py-1.5`,children:C?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,$.jsx)(z,{name:`refresh`,className:`h-4 w-4 animate-spin text-muted-foreground`})}):(0,$.jsxs)(`div`,{children:[b.map((t,r)=>{let i=t.isBuiltIn,a=t.isYuri;return(0,$.jsxs)(`div`,{ref:e=>{M.current[r]=e},className:F(`flex gap-2 px-2 py-2 cursor-pointer rounded-lg`,d?`items-center`:`items-start`,de(d,r===O),!d&&r===O&&`bg-interactive-selection/35`),onMouseDown:e=>e.preventDefault(),onPointerDown:e=>{e.pointerType===`touch`&&(I.current={x:e.clientX,y:e.clientY},R.current=!1)},onPointerMove:e=>{if(e.pointerType!==`touch`||!I.current)return;let t=e.clientX-I.current.x,n=e.clientY-I.current.y;Math.hypot(t,n)>6&&(R.current=!0)},onPointerUp:e=>{if(e.pointerType!==`touch`)return;let r=R.current;I.current=null,R.current=!1,!r&&(e.preventDefault(),e.stopPropagation(),ee.current=!0,n(t,Ke(t,d)))},onPointerCancel:()=>{I.current=null,R.current=!1},onClick:()=>{if(ee.current){ee.current=!1;return}n(t,Ke(t,d))},onMouseMove:()=>{j.current=!1,k(r)},children:[(0,$.jsx)(`div`,{className:F(!d&&`mt-0.5`),children:oe(t)}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(`span`,{className:`typography-ui-label font-medium`,children:[`/`,Me(t.name,e)]}),t.isSkill?(0,$.jsx)(`span`,{className:Ze,children:u(`chat.commandAutocomplete.badge.skill`)}):(0,$.jsx)(`span`,{className:Ze,children:u(`chat.commandAutocomplete.badge.command`)}),a?(0,$.jsx)(`span`,{className:et,children:`Yuri`}):i?(0,$.jsx)(`span`,{className:et,children:u(`chat.commandAutocomplete.badge.system`)}):t.scope?(0,$.jsx)(`span`,{className:t.scope===`project`?$e:Qe,children:t.scope}):null,t.agent&&(0,$.jsx)(`span`,{className:et,children:t.agent})]}),t.description&&!d&&(0,$.jsx)(`div`,{className:`typography-meta text-muted-foreground mt-0.5 truncate`,children:Me(t.description,e)})]})]},t.id)}),b.length===0&&(0,$.jsx)(`div`,{className:`px-3 py-2 typography-ui-label text-muted-foreground`,children:u(`chat.commandAutocomplete.empty`)})]})}),!d&&(0,$.jsx)(`div`,{className:`px-3 pt-1 pb-1.5 border-t typography-meta text-muted-foreground`,children:u(`chat.autocomplete.keyboardHint`)})]})});rt.displayName=`CommandAutocomplete`;var it=(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?` `:``}`},at=(e,t,n)=>{let r=it(e,t,n);return`${t.length===0&&!/^\s/.test(r)?` `:``}${r}${n.length===0&&!/\s$/.test(r)?` `:``}`},ot=(e,t,n,r)=>{let i=e.slice(0,t),a=e.slice(n),o=at(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}},st=(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]},ct=(e,t)=>t<e.length&&e[t]===` `?t+1:t;export{rt as a,Ne as c,Ce as d,U as f,at as i,Q as l,st as n,Ye as o,ye as p,ot as r,qe as s,ct as t,Z as u};